OpenDNSSEC-enforcer 2.1.13
enforce_cmd.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011 Surfnet
3 * Copyright (c) 2011 .SE (The Internet Infrastructure Foundation).
4 * Copyright (c) 2011 OpenDNSSEC AB (svb)
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
22 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 */
29
30#include <getopt.h>
31#include "config.h"
32
33#include "cmdhandler.h"
35#include "daemon/engine.h"
37#include "file.h"
38#include "log.h"
39#include "str.h"
40#include "clientpipe.h"
41#include "longgetopt.h"
42
44
45static const char *module_str = "enforce_cmd";
46
51static void
52usage(int sockfd)
53{
54 client_printf(sockfd,
55 "enforce\n"
56 " --zone <zone> aka -z\n");
57}
58
59static void
60help(int sockfd)
61{
62 client_printf(sockfd,
63 "Force enforce task to run for a zone."
64 " Without arguments run enforce task for every zone.\n"
65 "\nOptions:\n"
66 "zone Schedule enforce task for this zone for *now*\n"
67 "\n"
68 );
69}
70
75static int
76run(cmdhandler_ctx_type* context, int argc, char* argv[])
77{
78 int sockfd = context->sockfd;
79 struct longgetopt optctx;
80 int long_index = 0, opt = 0;
81 char const *zone_name = NULL;
82 db_connection_t* dbconn = getconnectioncontext(context);
83 engine_type* engine = getglobalcontext(context);
84
85 static struct option long_options[] = {
86 {"zone", required_argument, 0, 'z'},
87 {0, 0, 0, 0}
88 };
89
90 for(opt = longgetopt(argc, argv, "z:", long_options, &long_index, &optctx); opt != -1;
91 opt = longgetopt(argc, argv, NULL, long_options, &long_index, &optctx)) {
92 switch (opt) {
93 case 'z':
94 zone_name = optctx.optarg;
95 break;
96 default:
97 client_printf_err(sockfd, "unknown arguments\n");
98 ods_log_error("[%s] unknown arguments for enforce command", module_str);
99 return -1;
100
101 }
102 }
103
104 if (zone_name) {
105 enforce_task_flush_zone(engine, zone_name);
106 } else {
107 enforce_task_flush_all(engine, dbconn);
108 }
109 return 0;
110}
111
112struct cmd_func_block enforce_funcblock = {
113 "enforce", &usage, &help, NULL, NULL, &run, NULL
114};
struct cmd_func_block enforce_funcblock
void enforce_task_flush_all(engine_type *engine, db_connection_t *dbconn)
void enforce_task_flush_zone(engine_type *engine, char const *zonename)
db_connection_t * getconnectioncontext(cmdhandler_ctx_type *context)
engine_type * getglobalcontext(cmdhandler_ctx_type *context)