OpenDNSSEC-signer 2.1.13
cfg.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 NLNet Labs. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
19 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
21 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
22 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
23 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 *
25 */
26
32#include "config.h"
33#include "daemon/cfg.h"
34#include "parser/confparser.h"
35#include "file.h"
36#include "log.h"
37#include "status.h"
38
39#include <errno.h>
40#include <stdio.h>
41#include <string.h>
42
43static const char* conf_str = "config";
44
45
51engine_config(const char* cfgfile, int cmdline_verbosity)
52{
54 const char* rngfile = ODS_SE_RNGDIR "/conf.rng";
55 FILE* cfgfd = NULL;
56
57 if (!cfgfile) {
58 return NULL;
59 }
60 /* check syntax (slows down parsing configuration file) */
61 if (parse_file_check(cfgfile, rngfile) != ODS_STATUS_OK) {
62 ods_log_error("[%s] unable to create config: parse error in %s",
63 conf_str, cfgfile);
64 return NULL;
65 }
66 /* open cfgfile */
67 cfgfd = ods_fopen(cfgfile, NULL, "r");
68 if (cfgfd) {
69 ods_log_verbose("[%s] read cfgfile: %s", conf_str, cfgfile);
70 /* create config */
71 CHECKALLOC(ecfg = (engineconfig_type*) malloc(sizeof(engineconfig_type)));
72 /* get values */
73 ecfg->cfg_filename = strdup(cfgfile);
79 ecfg->working_dir = parse_conf_working_dir(cfgfile);
80 ecfg->username = parse_conf_username(cfgfile);
81 ecfg->group = parse_conf_group(cfgfile);
82 ecfg->chroot = parse_conf_chroot(cfgfile);
83 ecfg->use_syslog = parse_conf_use_syslog(cfgfile);
86 /* If any verbosity has been specified at cmd line we will use that */
87 if (cmdline_verbosity > 0) {
88 ecfg->verbosity = cmdline_verbosity;
89 }
90 else {
91 ecfg->verbosity = parse_conf_verbosity(cfgfile);
92 }
93 ecfg->interfaces = parse_conf_listener(cfgfile);
95 /* done */
96 ods_fclose(cfgfd);
97 return ecfg;
98 }
99 ods_log_error("[%s] unable to create config: failed to open file %s",
100 conf_str, cfgfile);
101 return NULL;
102}
103
104
109ods_status
111{
112 if (!config) {
113 ods_log_error("[%s] config-check failed: no config", conf_str);
114 return ODS_STATUS_CFG_ERR;
115 }
116 if (!config->cfg_filename) {
117 ods_log_error("[%s] config-check failed: no config filename",
118 conf_str);
119 return ODS_STATUS_CFG_ERR;
120 }
121 if (!config->zonelist_filename) {
122 ods_log_error("[%s] config-check failed: no zonelist filename",
123 conf_str);
124 return ODS_STATUS_CFG_ERR;
125 }
126 if (!config->clisock_filename) {
127 ods_log_error("[%s] config-check failed: no socket filename",
128 conf_str);
129 return ODS_STATUS_CFG_ERR;
130 }
131 if (!config->interfaces) {
132 ods_log_error("[%s] config-check failed: no listener",
133 conf_str);
134 return ODS_STATUS_CFG_ERR;
135 }
136 /* [TODO] room for more checks here */
137 return ODS_STATUS_OK;
138}
139
140
145void
147{
148 if (!out) {
149 return;
150 }
151 fprintf(out, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
152 if (config) {
153 fprintf(out, "<Configuration>\n");
154
155 /* Common */
156 fprintf(out, "\t<Common>\n");
157 if (config->use_syslog && config->log_filename) {
158 fprintf(out, "\t\t<Logging>\n");
159 fprintf(out, "\t\t\t<Syslog>\n");
160 fprintf(out, "\t\t\t\t<Facility>%s</Facility>\n",
161 config->log_filename);
162 fprintf(out, "\t\t\t</Syslog>\n");
163 fprintf(out, "\t\t</Logging>\n");
164 } else if (config->log_filename) {
165 fprintf(out, "\t\t<Logging>\n");
166 fprintf(out, "\t\t\t<File>\n");
167 fprintf(out, "\t\t\t\t<Filename>%s</Filename>\n",
168 config->log_filename);
169 fprintf(out, "\t\t\t</File>\n");
170 fprintf(out, "\t\t</Logging>\n");
171 }
172 fprintf(out, "\t</Common>\n");
173
174 /* Enforcer */
175 fprintf(out, "\t<Enforcer>\n");
176 fprintf(out, "\t\t<ZoneListFile>%s</ZoneListFile>\n",
177 config->zonelist_filename);
178 fprintf(out, "\t</Enforcer>\n");
179
180 /* Signer */
181 fprintf(out, "\t<Signer>\n");
182 if (config->username || config->group || config->chroot) {
183 fprintf(out, "\t\t<Privileges>\n");
184 if (config->username) {
185 fprintf(out, "\t\t<User>%s</User>\n", config->username);
186 }
187 if (config->group) {
188 fprintf(out, "\t\t<Group>%s</Group>\n", config->group);
189 }
190 if (config->chroot) {
191 fprintf(out, "\t\t<Directory>%s</Directory>\n",
192 config->chroot);
193 }
194 fprintf(out, "\t\t</Privileges>\n");
195 }
196 if (config->interfaces) {
197 size_t i = 0;
198 fprintf(out, "\t\t<Listener>\n");
199
200 for (i=0; i < config->interfaces->count; i++) {
201 fprintf(out, "\t\t\t<Interface>");
202 if (config->interfaces->interfaces[i].address) {
203 fprintf(out, "<Address>%s</Address>",
204 config->interfaces->interfaces[i].address);
205 }
206 if (config->interfaces->interfaces[i].port) {
207 fprintf(out, "<Port>%s</Port>",
208 config->interfaces->interfaces[i].port);
209 }
210 fprintf(out, "<Interface>\n");
211 }
212 fprintf(out, "\t\t</Listener>\n");
213
214 }
215
216 fprintf(out, "\t\t<WorkingDirectory>%s</WorkingDirectory>\n",
217 config->working_dir);
218 fprintf(out, "\t\t<WorkerThreads>%i</WorkerThreads>\n",
219 config->num_worker_threads);
220 fprintf(out, "\t\t<SignerThreads>%i</SignerThreads>\n",
221 config->num_signer_threads);
222 if (config->notify_command) {
223 fprintf(out, "\t\t<NotifyCommand>%s</NotifyCommand>\n",
224 config->notify_command);
225 }
226 fprintf(out, "\t</Signer>\n");
227
228 fprintf(out, "</Configuration>\n");
229
230 /* make configurable:
231 - pid_filename
232 - clisock_filename
233 */
234 }
235}
236
237
242void
244{
245 if (!config) {
246 return;
247 }
249 hsm_repository_free(config->repositories);
250 free((void*)config->notify_command);
251 free((void*)config->cfg_filename);
252 free((void*)config->zonelist_filename);
253 free((void*)config->log_filename);
254 free((void*)config->pid_filename);
255 free((void*)config->clisock_filename);
256 free((void*)config->working_dir);
257 free((void*)config->username);
258 free((void*)config->group);
259 free((void*)config->chroot);
260 free(config);
261}
262
void engine_config_cleanup(engineconfig_type *config)
Definition: cfg.c:243
void engine_config_print(FILE *out, engineconfig_type *config)
Definition: cfg.c:146
ods_status engine_config_check(engineconfig_type *config)
Definition: cfg.c:110
engineconfig_type * engine_config(const char *cfgfile, int cmdline_verbosity)
Definition: cfg.c:51
const char * parse_conf_clisock_filename(const char *cfgfile)
Definition: confparser.c:513
const char * parse_conf_zonelist_filename(const char *cfgfile)
Definition: confparser.c:418
hsm_repository_t * parse_conf_repositories(const char *cfgfile)
Definition: confparser.c:143
const char * parse_conf_working_dir(const char *cfgfile)
Definition: confparser.c:536
const char * parse_conf_log_filename(const char *cfgfile)
Definition: confparser.c:457
int parse_conf_worker_threads(const char *cfgfile)
Definition: confparser.c:641
const char * parse_conf_username(const char *cfgfile)
Definition: confparser.c:556
const char * parse_conf_pid_filename(const char *cfgfile)
Definition: confparser.c:477
int parse_conf_signer_threads(const char *cfgfile)
Definition: confparser.c:658
int parse_conf_use_syslog(const char *cfgfile)
Definition: confparser.c:611
const char * parse_conf_notify_command(const char *cfgfile)
Definition: confparser.c:496
const char * parse_conf_chroot(const char *cfgfile)
Definition: confparser.c:590
const char * parse_conf_group(const char *cfgfile)
Definition: confparser.c:573
int parse_conf_verbosity(const char *cfgfile)
Definition: confparser.c:624
ods_status parse_file_check(const char *cfgfile, const char *rngfile)
Definition: confparser.c:55
listener_type * parse_conf_listener(const char *cfgfile)
Definition: confparser.c:252
void listener_cleanup(listener_type *listener)
Definition: listener.c:126
const char * chroot
Definition: cfg.h:57
listener_type * interfaces
Definition: cfg.h:46
const char * cfg_filename
Definition: cfg.h:48
const char * notify_command
Definition: cfg.h:52
const char * group
Definition: cfg.h:56
const char * clisock_filename
Definition: cfg.h:53
const char * working_dir
Definition: cfg.h:54
hsm_repository_t * repositories
Definition: cfg.h:47
int num_worker_threads
Definition: cfg.h:59
int use_syslog
Definition: cfg.h:58
const char * pid_filename
Definition: cfg.h:51
const char * zonelist_filename
Definition: cfg.h:49
const char * log_filename
Definition: cfg.h:50
int num_signer_threads
Definition: cfg.h:60
const char * username
Definition: cfg.h:55
char * address
Definition: listener.h:71
size_t count
Definition: listener.h:83
interface_type * interfaces
Definition: listener.h:82