OpenDNSSEC-enforcer 2.1.10
update_conf_cmd.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2014 .SE (The Internet Infrastructure Foundation).
3 * Copyright (c) 2014 OpenDNSSEC AB (svb)
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
19 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
21 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
23 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
25 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 *
27 */
28
29#include "daemon/engine.h"
30#include "cmdhandler.h"
32#include "log.h"
33#include "str.h"
34#include "clientpipe.h"
35#include "utils/kc_helper.h"
36
38
39#include <pthread.h>
40
41static const char *module_str = "update_conf_cmd";
42
43static void
44usage(int sockfd)
45{
46 client_printf(sockfd,
47 "update conf\n");
48}
49
50static void
51help(int sockfd)
52{
53 client_printf(sockfd,
54 "Update the configuration from conf.xml and reload the Enforcer.\n\n"
55 );
56}
57
58static int
59run(int sockfd, cmdhandler_ctx_type* context, const char *cmd)
60{
61 char *kasp = NULL;
62 char *zonelist = NULL;
63 char **repositories = NULL;
64 int repository_count = 0;
65 int i;
66 db_connection_t* dbconn = getconnectioncontext(context);
67 engine_type* engine = getglobalcontext(context);
68 (void)cmd;
69
70 ods_log_debug("[%s] %s command", module_str, update_conf_funcblock.cmdname);
71
72 if (check_conf(engine->config->cfg_filename, &kasp, &zonelist, &repositories, &repository_count, (ods_log_verbosity() >= 3))) {
73 client_printf_err(sockfd, "Unable to validate '%s' consistency.",
74 engine->config->cfg_filename);
75
76 free(kasp);
77 free(zonelist);
78 if (repositories) {
79 for (i = 0; i < repository_count; i++) {
80 free(repositories[i]);
81 }
82 free(repositories);
83 }
84 return 1;
85 }
86
87 free(kasp);
88 free(zonelist);
89 if (repositories) {
90 for (i = 0; i < repository_count; i++) {
91 free(repositories[i]);
92 }
93 free(repositories);
94 }
95
96 engine->need_to_reload = 1;
97 pthread_cond_signal(&engine->signal_cond);
98
99 return 0;
100}
101
102struct cmd_func_block update_conf_funcblock = {
103 "update conf", &usage, &help, NULL, &run
104};
db_connection_t * getconnectioncontext(cmdhandler_ctx_type *context)
engine_type * getglobalcontext(cmdhandler_ctx_type *context)
int check_conf(const char *conf, char **kasp, char **zonelist, char ***repo_listout, int *repo_countout, int verbose)
Definition: kc_helper.c:1395
pthread_cond_t signal_cond
Definition: engine.h:64
int need_to_reload
Definition: engine.h:56
engineconfig_type * config
Definition: engine.h:48
const char * cfg_filename
Definition: cfg.h:55
struct cmd_func_block update_conf_funcblock