OpenDNSSEC-signer
1.3.9
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 6065 2012-01-16 09:45:47Z jerry $
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) {
62
ods_log_error
(
"[%s] failed to read: no allocator available"
,
63
conf_str);
64
return
NULL;
65
}
66
ods_log_assert
(allocator);
67
if
(!cfgfile) {
68
ods_log_error
(
"[%s] failed to read: no filename given"
, conf_str);
69
return
NULL;
70
}
71
ods_log_assert
(cfgfile);
72
ods_log_verbose
(
"[%s] read cfgfile: %s"
, conf_str, cfgfile);
73
74
ecfg = (
engineconfig_type
*)
allocator_alloc
(allocator,
75
sizeof
(
engineconfig_type
));
76
if
(!ecfg) {
77
ods_log_error
(
"[%s] failed to read: allocator failed"
, conf_str);
78
return
NULL;
79
}
80
81
ecfg->
allocator
=
allocator
;
82
83
/* check syntax (slows down parsing configuration file) */
84
if
(
parse_file_check
(cfgfile, rngfile) !=
ODS_STATUS_OK
) {
85
ods_log_error
(
"[%s] failed to read: unable to parse file %s"
,
86
conf_str, cfgfile);
87
return
NULL;
88
}
89
90
/* open cfgfile */
91
cfgfd =
ods_fopen
(cfgfile, NULL,
"r"
);
92
if
(cfgfd) {
93
/* get values */
94
ecfg->
cfg_filename
=
allocator_strdup
(allocator, cfgfile);
95
ecfg->
zonelist_filename
=
parse_conf_zonelist_filename
(allocator,
96
cfgfile);
97
ecfg->
zonefetch_filename
=
parse_conf_zonefetch_filename
(allocator,
98
cfgfile);
99
ecfg->
log_filename
=
parse_conf_log_filename
(allocator, cfgfile);
100
ecfg->
pid_filename
=
parse_conf_pid_filename
(allocator, cfgfile);
101
ecfg->
notify_command
=
parse_conf_notify_command
(allocator, cfgfile);
102
ecfg->
clisock_filename
=
parse_conf_clisock_filename
(allocator,
103
cfgfile);
104
ecfg->
working_dir
=
parse_conf_working_dir
(allocator, cfgfile);
105
ecfg->
username
=
parse_conf_username
(allocator, cfgfile);
106
ecfg->
group
=
parse_conf_group
(allocator, cfgfile);
107
ecfg->
chroot
=
parse_conf_chroot
(allocator, cfgfile);
108
ecfg->
use_syslog
=
parse_conf_use_syslog
(cfgfile);
109
ecfg->
num_worker_threads
=
parse_conf_worker_threads
(cfgfile);
110
ecfg->
num_signer_threads
=
parse_conf_signer_threads
(cfgfile);
111
/* If any verbosity has been specified at cmd line we will use that */
112
if
(cmdline_verbosity > 0) {
113
ecfg->
verbosity
= cmdline_verbosity;
114
}
115
else
{
116
ecfg->
verbosity
=
parse_conf_verbosity
(cfgfile);
117
}
118
ecfg->
num_adapters
= 0;
119
120
/* done */
121
ods_fclose
(cfgfd);
122
return
ecfg;
123
}
124
125
ods_log_error
(
"[%s] failed to read: unable to open file %s"
, conf_str,
126
cfgfile);
127
return
NULL;
128
}
129
130
135
ods_status
136
engine_config_check
(
engineconfig_type
* config)
137
{
138
if
(!config) {
139
ods_log_error
(
"[%s] check failed: config does not exist"
, conf_str);
140
return
ODS_STATUS_CFG_ERR
;
141
}
142
if
(!config->
zonelist_filename
) {
143
ods_log_error
(
"[%s] check failed: no zonelist filename"
, conf_str);
144
return
ODS_STATUS_CFG_ERR
;
145
}
146
if
(!config->
clisock_filename
) {
147
ods_log_error
(
"[%s] check failed: no socket filename"
, conf_str);
148
return
ODS_STATUS_CFG_ERR
;
149
}
150
151
/* [TODO] room for more checks here */
152
153
return
ODS_STATUS_OK
;
154
}
155
156
161
void
162
engine_config_print
(FILE* out,
engineconfig_type
* config)
163
{
164
if
(!out) {
165
return
;
166
}
167
168
fprintf(out,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
);
169
if
(config) {
170
fprintf(out,
"<Configuration>\n"
);
171
172
/* Common */
173
fprintf(out,
"\t<Common>\n"
);
174
if
(config->
use_syslog
&& config->
log_filename
) {
175
fprintf(out,
"\t\t<Logging>\n"
);
176
fprintf(out,
"\t\t\t<Syslog>\n"
);
177
fprintf(out,
"\t\t\t\t<Facility>%s</Facility>\n"
,
178
config->
log_filename
);
179
fprintf(out,
"\t\t\t</Syslog>\n"
);
180
fprintf(out,
"\t\t</Logging>\n"
);
181
}
else
if
(config->
log_filename
) {
182
fprintf(out,
"\t\t<Logging>\n"
);
183
fprintf(out,
"\t\t\t<File>\n"
);
184
fprintf(out,
"\t\t\t\t<Filename>%s</Filename>\n"
,
185
config->
log_filename
);
186
fprintf(out,
"\t\t\t</File>\n"
);
187
fprintf(out,
"\t\t</Logging>\n"
);
188
}
189
190
fprintf(out,
"\t\t<ZoneListFile>%s</ZoneListFile>\n"
,
191
config->
zonelist_filename
);
192
if
(config->
zonefetch_filename
) {
193
fprintf(out,
"\t\t<ZoneFetchFile>%s</ZoneFetchFile>\n"
,
194
config->
zonefetch_filename
);
195
}
196
197
fprintf(out,
"\t</Common>\n"
);
198
199
/* Signer */
200
fprintf(out,
"\t<Signer>\n"
);
201
if
(config->
username
|| config->
group
|| config->
chroot
) {
202
fprintf(out,
"\t\t<Privileges>\n"
);
203
if
(config->
username
) {
204
fprintf(out,
"\t\t<User>%s</User>\n"
, config->
username
);
205
}
206
if
(config->
group
) {
207
fprintf(out,
"\t\t<Group>%s</Group>\n"
, config->
group
);
208
}
209
if
(config->
chroot
) {
210
fprintf(out,
"\t\t<Directory>%s</Directory>\n"
,
211
config->
chroot
);
212
}
213
fprintf(out,
"\t\t</Privileges>\n"
);
214
}
215
fprintf(out,
"\t\t<WorkingDirectory>%s</WorkingDirectory>\n"
,
216
config->
working_dir
);
217
fprintf(out,
"\t\t<WorkerThreads>%i</WorkerThreads>\n"
,
218
config->
num_worker_threads
);
219
fprintf(out,
"\t\t<SignerThreads>%i</SignerThreads>\n"
,
220
config->
num_signer_threads
);
221
if
(config->
notify_command
) {
222
fprintf(out,
"\t\t<NotifyCommand>%s</NotifyCommand>\n"
,
223
config->
notify_command
);
224
}
225
fprintf(out,
"\t</Signer>\n"
);
226
227
fprintf(out,
"</Configuration>\n"
);
228
229
/* make configurable:
230
- pid_filename
231
- clisock_filename
232
*/
233
}
234
return
;
235
}
236
237
242
void
243
engine_config_cleanup
(
engineconfig_type
* config)
244
{
245
allocator_type
*
allocator
;
246
if
(!config) {
247
return
;
248
}
249
allocator = config->
allocator
;
250
allocator_deallocate
(allocator, (
void
*) config->
cfg_filename
);
251
allocator_deallocate
(allocator, (
void
*) config->
zonelist_filename
);
252
allocator_deallocate
(allocator, (
void
*) config->
zonefetch_filename
);
253
allocator_deallocate
(allocator, (
void
*) config->
log_filename
);
254
allocator_deallocate
(allocator, (
void
*) config->
pid_filename
);
255
allocator_deallocate
(allocator, (
void
*) config->
notify_command
);
256
allocator_deallocate
(allocator, (
void
*) config->
clisock_filename
);
257
allocator_deallocate
(allocator, (
void
*) config->
working_dir
);
258
allocator_deallocate
(allocator, (
void
*) config->
username
);
259
allocator_deallocate
(allocator, (
void
*) config->
group
);
260
allocator_deallocate
(allocator, (
void
*) config->
chroot
);
261
allocator_deallocate
(allocator, (
void
*) config);
262
return
;
263
}
264
Generated on Fri Jun 29 2012 10:31:12 for OpenDNSSEC-signer by
1.8.1.1