OpenDNSSEC-enforcer  2.0.2
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 "daemon/cmdhandler.h"
31 #include "log.h"
32 #include "str.h"
33 #include "clientpipe.h"
34 #include "utils/kc_helper.h"
35 
37 
38 #include <pthread.h>
39 
40 static const char *module_str = "update_conf_cmd";
41 
42 static void
43 usage(int sockfd)
44 {
45  client_printf(sockfd,
46  "update conf\n");
47 }
48 
49 static void
50 help(int sockfd)
51 {
52  client_printf(sockfd,
53  "Update the configuration from conf.xml and reload the Enforcer.\n\n"
54  );
55 }
56 
57 static int
58 handles(const char *cmd, ssize_t n)
59 {
60  return ods_check_command(cmd, n, update_conf_funcblock()->cmdname) ? 1 : 0;
61 }
62 
63 static int
64 run(int sockfd, engine_type* engine, const char *cmd, ssize_t n,
65  db_connection_t *dbconn)
66 {
67  char *kasp = NULL;
68  char *zonelist = NULL;
69  char **repositories = NULL;
70  int repository_count = 0;
71  int i;
72 
73  (void)cmd; (void)n; (void)dbconn;
74 
75  ods_log_debug("[%s] %s command", module_str, update_conf_funcblock()->cmdname);
76 
77  if (check_conf(engine->config->cfg_filename, &kasp, &zonelist, &repositories, &repository_count, 0)) {
78  client_printf_err(sockfd, "Unable to validate '%s' consistency.",
79  engine->config->cfg_filename);
80 
81  free(kasp);
82  free(zonelist);
83  if (repositories) {
84  for (i = 0; i < repository_count; i++) {
85  free(repositories[i]);
86  }
87  free(repositories);
88  }
89  return 1;
90  }
91 
92  free(kasp);
93  free(zonelist);
94  if (repositories) {
95  for (i = 0; i < repository_count; i++) {
96  free(repositories[i]);
97  }
98  free(repositories);
99  }
100 
101  engine->need_to_reload = 1;
102  pthread_cond_signal(&engine->signal_cond);
103 
104  return 0;
105 }
106 
107 static struct cmd_func_block funcblock = {
108  "update conf", &usage, &help, &handles, &run
109 };
110 
111 struct cmd_func_block*
113 {
114  return &funcblock;
115 }
struct cmd_func_block * update_conf_funcblock(void)
void(* help)(int sockfd)
Definition: cmdhandler.h:64
const char * cfg_filename
Definition: cfg.h:55
int check_conf(const char *conf, char **kasp, char **zonelist, char ***repo_listout, int *repo_countout, int verbose)
Definition: kc_helper.c:1395
void ods_log_debug(const char *format,...)
Definition: log.c:41
int(* run)(int sockfd, struct engine_struct *engine, const char *cmd, ssize_t n, db_connection_t *dbconn)
Definition: cmdhandler.h:79
const char * cmdname
Definition: cmdhandler.h:59
pthread_cond_t signal_cond
Definition: engine.h:69
void(* usage)(int sockfd)
Definition: cmdhandler.h:61
engineconfig_type * config
Definition: engine.h:53
int(* handles)(const char *cmd, ssize_t n)
Definition: cmdhandler.h:67
int need_to_reload
Definition: engine.h:66