OpenDNSSEC-signer
1.4.1
Main Page
Data Structures
Files
File List
Globals
signer
src
daemon
cfg.c
Go to the documentation of this file.
1
/*
2
* $Id: cfg.c 7083 2013-04-03 13:27:51Z matthijs $
3
*
4
* Copyright (c) 2009 NLNet Labs. 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
34
#include "config.h"
35
#include "
daemon/cfg.h
"
36
#include "
parser/confparser.h
"
37
#include "
shared/allocator.h
"
38
#include "
shared/file.h
"
39
#include "
shared/log.h
"
40
#include "
shared/status.h
"
41
42
#include <errno.h>
43
#include <stdio.h>
44
#include <string.h>
45
46
static
const
char
* conf_str =
"config"
;
47
48
53
engineconfig_type
*
54
engine_config
(
allocator_type
* allocator,
const
char
* cfgfile,
55
int
cmdline_verbosity)
56
{
57
engineconfig_type
* ecfg;
58
const
char
* rngfile = ODS_SE_RNGDIR
"/conf.rng"
;
59
FILE* cfgfd = NULL;
60
61
if
(!allocator || !cfgfile) {
62
return
NULL;
63
}
64
/* check syntax (slows down parsing configuration file) */
65
if
(
parse_file_check
(cfgfile, rngfile) !=
ODS_STATUS_OK
) {
66
ods_log_error
(
"[%s] unable to create config: parse error in %s"
,
67
conf_str, cfgfile);
68
return
NULL;
69
}
70
/* open cfgfile */
71
cfgfd =
ods_fopen
(cfgfile, NULL,
"r"
);
72
if
(cfgfd) {
73
ods_log_verbose
(
"[%s] read cfgfile: %s"
, conf_str, cfgfile);
74
/* create config */
75
ecfg = (
engineconfig_type
*)
allocator_alloc
(allocator,
76
sizeof
(
engineconfig_type
));
77
if
(!ecfg) {
78
ods_log_error
(
"[%s] unable to create config: allocator_alloc() "
79
"failed"
, conf_str);
80
ods_fclose
(cfgfd);
81
return
NULL;
82
}
83
ecfg->
allocator
= allocator;
84
/* get values */
85
ecfg->
cfg_filename
=
allocator_strdup
(allocator, cfgfile);
86
ecfg->
zonelist_filename
=
parse_conf_zonelist_filename
(allocator,
87
cfgfile);
88
ecfg->
log_filename
=
parse_conf_log_filename
(allocator, cfgfile);
89
ecfg->
pid_filename
=
parse_conf_pid_filename
(allocator, cfgfile);
90
ecfg->
notify_command
=
parse_conf_notify_command
(allocator, cfgfile);
91
ecfg->
clisock_filename
=
parse_conf_clisock_filename
(allocator,
92
cfgfile);
93
ecfg->
working_dir
=
parse_conf_working_dir
(allocator, cfgfile);
94
ecfg->
username
=
parse_conf_username
(allocator, cfgfile);
95
ecfg->
group
=
parse_conf_group
(allocator, cfgfile);
96
ecfg->
chroot
=
parse_conf_chroot
(allocator, cfgfile);
97
ecfg->
use_syslog
=
parse_conf_use_syslog
(cfgfile);
98
ecfg->
num_worker_threads
=
parse_conf_worker_threads
(cfgfile);
99
ecfg->
num_signer_threads
=
parse_conf_signer_threads
(cfgfile);
100
/* If any verbosity has been specified at cmd line we will use that */
101
if
(cmdline_verbosity > 0) {
102
ecfg->
verbosity
= cmdline_verbosity;
103
}
104
else
{
105
ecfg->
verbosity
=
parse_conf_verbosity
(cfgfile);
106
}
107
ecfg->
interfaces
=
parse_conf_listener
(allocator, cfgfile);
108
/* done */
109
ods_fclose
(cfgfd);
110
return
ecfg;
111
}
112
ods_log_error
(
"[%s] unable to create config: failed to open file %s"
,
113
conf_str, cfgfile);
114
return
NULL;
115
}
116
117
122
ods_status
123
engine_config_check
(
engineconfig_type
* config)
124
{
125
if
(!config) {
126
ods_log_error
(
"[%s] config-check failed: no config"
, conf_str);
127
return
ODS_STATUS_CFG_ERR
;
128
}
129
if
(!config->
cfg_filename
) {
130
ods_log_error
(
"[%s] config-check failed: no config filename"
,
131
conf_str);
132
return
ODS_STATUS_CFG_ERR
;
133
}
134
if
(!config->
zonelist_filename
) {
135
ods_log_error
(
"[%s] config-check failed: no zonelist filename"
,
136
conf_str);
137
return
ODS_STATUS_CFG_ERR
;
138
}
139
if
(!config->
clisock_filename
) {
140
ods_log_error
(
"[%s] config-check failed: no socket filename"
,
141
conf_str);
142
return
ODS_STATUS_CFG_ERR
;
143
}
144
if
(!config->
interfaces
) {
145
ods_log_error
(
"[%s] config-check failed: no listener"
,
146
conf_str);
147
return
ODS_STATUS_CFG_ERR
;
148
}
149
/* [TODO] room for more checks here */
150
return
ODS_STATUS_OK
;
151
}
152
153
158
void
159
engine_config_print
(FILE* out,
engineconfig_type
* config)
160
{
161
if
(!out) {
162
return
;
163
}
164
fprintf(out,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
);
165
if
(config) {
166
fprintf(out,
"<Configuration>\n"
);
167
168
/* Common */
169
fprintf(out,
"\t<Common>\n"
);
170
if
(config->
use_syslog
&& config->
log_filename
) {
171
fprintf(out,
"\t\t<Logging>\n"
);
172
fprintf(out,
"\t\t\t<Syslog>\n"
);
173
fprintf(out,
"\t\t\t\t<Facility>%s</Facility>\n"
,
174
config->
log_filename
);
175
fprintf(out,
"\t\t\t</Syslog>\n"
);
176
fprintf(out,
"\t\t</Logging>\n"
);
177
}
else
if
(config->
log_filename
) {
178
fprintf(out,
"\t\t<Logging>\n"
);
179
fprintf(out,
"\t\t\t<File>\n"
);
180
fprintf(out,
"\t\t\t\t<Filename>%s</Filename>\n"
,
181
config->
log_filename
);
182
fprintf(out,
"\t\t\t</File>\n"
);
183
fprintf(out,
"\t\t</Logging>\n"
);
184
}
185
fprintf(out,
"\t\t<ZoneListFile>%s</ZoneListFile>\n"
,
186
config->
zonelist_filename
);
187
fprintf(out,
"\t</Common>\n"
);
188
189
/* Signer */
190
fprintf(out,
"\t<Signer>\n"
);
191
if
(config->
username
|| config->
group
|| config->
chroot
) {
192
fprintf(out,
"\t\t<Privileges>\n"
);
193
if
(config->
username
) {
194
fprintf(out,
"\t\t<User>%s</User>\n"
, config->
username
);
195
}
196
if
(config->
group
) {
197
fprintf(out,
"\t\t<Group>%s</Group>\n"
, config->
group
);
198
}
199
if
(config->
chroot
) {
200
fprintf(out,
"\t\t<Directory>%s</Directory>\n"
,
201
config->
chroot
);
202
}
203
fprintf(out,
"\t\t</Privileges>\n"
);
204
}
205
if
(config->
interfaces
) {
206
size_t
i = 0;
207
fprintf(out,
"\t\t<Listener>\n"
);
208
209
for
(i=0; i < config->
interfaces
->
count
; i++) {
210
fprintf(out,
"\t\t\t<Interface>"
);
211
if
(config->
interfaces
->
interfaces
[i].
address
) {
212
fprintf(out,
"<Address>%s</Address>"
,
213
config->
interfaces
->
interfaces
[i].
address
);
214
}
215
if
(config->
interfaces
->
interfaces
[i].
port
) {
216
fprintf(out,
"<Port>%s</Port>"
,
217
config->
interfaces
->
interfaces
[i].
port
);
218
}
219
fprintf(out,
"<Interface>\n"
);
220
}
221
fprintf(out,
"\t\t</Listener>\n"
);
222
223
}
224
225
fprintf(out,
"\t\t<WorkingDirectory>%s</WorkingDirectory>\n"
,
226
config->
working_dir
);
227
fprintf(out,
"\t\t<WorkerThreads>%i</WorkerThreads>\n"
,
228
config->
num_worker_threads
);
229
fprintf(out,
"\t\t<SignerThreads>%i</SignerThreads>\n"
,
230
config->
num_signer_threads
);
231
if
(config->
notify_command
) {
232
fprintf(out,
"\t\t<NotifyCommand>%s</NotifyCommand>\n"
,
233
config->
notify_command
);
234
}
235
fprintf(out,
"\t</Signer>\n"
);
236
237
fprintf(out,
"</Configuration>\n"
);
238
239
/* make configurable:
240
- pid_filename
241
- clisock_filename
242
*/
243
}
244
return
;
245
}
246
247
252
void
253
engine_config_cleanup
(
engineconfig_type
* config)
254
{
255
allocator_type
* allocator = NULL;
256
if
(!config) {
257
return
;
258
}
259
allocator = config->
allocator
;
260
listener_cleanup
(config->
interfaces
);
261
allocator_deallocate
(allocator, (
void
*) config->
notify_command
);
262
allocator_deallocate
(allocator, (
void
*) config->
cfg_filename
);
263
allocator_deallocate
(allocator, (
void
*) config->
zonelist_filename
);
264
allocator_deallocate
(allocator, (
void
*) config->
log_filename
);
265
allocator_deallocate
(allocator, (
void
*) config->
pid_filename
);
266
allocator_deallocate
(allocator, (
void
*) config->
clisock_filename
);
267
allocator_deallocate
(allocator, (
void
*) config->
working_dir
);
268
allocator_deallocate
(allocator, (
void
*) config->
username
);
269
allocator_deallocate
(allocator, (
void
*) config->
group
);
270
allocator_deallocate
(allocator, (
void
*) config->
chroot
);
271
allocator_deallocate
(allocator, (
void
*) config);
272
return
;
273
}
274
Generated on Wed Jul 17 2013 07:14:23 for OpenDNSSEC-signer by
1.8.4