40 #include <libxml/xpath.h> 41 #include <libxml/relaxng.h> 42 #include <libxml/xmlreader.h> 47 static const char* parser_str =
"parser";
58 xmlDocPtr rngdoc = NULL;
59 xmlRelaxNGParserCtxtPtr rngpctx = NULL;
60 xmlRelaxNGValidCtxtPtr rngctx = NULL;
61 xmlRelaxNGPtr schema = NULL;
64 if (!cfgfile || !rngfile) {
65 return ODS_STATUS_ASSERT_ERR;
67 ods_log_debug(
"[%s] check cfgfile %s with rngfile %s", parser_str,
70 doc = xmlParseFile(cfgfile);
72 ods_log_error(
"[%s] unable to parse file: failed to load cfgfile %s",
74 return ODS_STATUS_XML_ERR;
77 rngdoc = xmlParseFile(rngfile);
79 ods_log_error(
"[%s] unable to parse file: failed to load rngfile %s",
82 return ODS_STATUS_XML_ERR;
85 rngpctx = xmlRelaxNGNewDocParserCtxt(rngdoc);
86 if (rngpctx == NULL) {
87 ods_log_error(
"[%s] unable to parse file: " 88 "xmlRelaxNGNewDocParserCtxt() failed", parser_str);
91 return ODS_STATUS_XML_ERR;
96 schema = xmlRelaxNGParse(rngpctx);
98 ods_log_error(
"[%s] unable to parse file: xmlRelaxNGParse() failed",
100 xmlRelaxNGFreeParserCtxt(rngpctx);
103 return ODS_STATUS_PARSE_ERR;
106 rngctx = xmlRelaxNGNewValidCtxt(schema);
107 if (rngctx == NULL) {
108 ods_log_error(
"[%s] unable to parse file: xmlRelaxNGNewValidCtxt() " 109 "failed", parser_str);
110 xmlRelaxNGFree(schema);
111 xmlRelaxNGFreeParserCtxt(rngpctx);
114 return ODS_STATUS_RNG_ERR;
117 status = xmlRelaxNGValidateDoc(rngctx,doc);
119 ods_log_error(
"[%s] unable to parse file: xmlRelaxNGValidateDoc() " 120 "failed", parser_str);
121 xmlRelaxNGFreeValidCtxt(rngctx);
122 xmlRelaxNGFree(schema);
123 xmlRelaxNGFreeParserCtxt(rngpctx);
126 return ODS_STATUS_RNG_ERR;
128 xmlRelaxNGFreeValidCtxt(rngctx);
129 xmlRelaxNGFree(schema);
130 xmlRelaxNGFreeParserCtxt(rngpctx);
133 return ODS_STATUS_OK;
145 xmlDocPtr doc = NULL;
146 xmlXPathContextPtr xpathCtx = NULL;
147 xmlXPathObjectPtr xpathObj = NULL;
148 xmlNode* curNode = NULL;
149 xmlChar* xexpr = NULL;
158 hsm_repository_t* rlist = NULL;
159 hsm_repository_t* repo = NULL;
162 doc = xmlParseFile(cfgfile);
164 ods_log_error(
"[%s] could not parse <RepositoryList>: " 165 "xmlParseFile() failed", parser_str);
169 xpathCtx = xmlXPathNewContext(doc);
170 if(xpathCtx == NULL) {
172 ods_log_error(
"[%s] could not parse <RepositoryList>: " 173 "xmlXPathNewContext() failed", parser_str);
177 xexpr = (xmlChar*)
"//Configuration/RepositoryList/Repository";
178 xpathObj = xmlXPathEvalExpression(xexpr, xpathCtx);
179 if(xpathObj == NULL) {
180 xmlXPathFreeContext(xpathCtx);
182 ods_log_error(
"[%s] could not parse <RepositoryList>: " 183 "xmlXPathEvalExpression failed", parser_str);
187 if (xpathObj->nodesetval && xpathObj->nodesetval->nodeNr > 0) {
188 for (i = 0; i < xpathObj->nodesetval->nodeNr; i++) {
197 curNode = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
198 name = (
char *) xmlGetProp(xpathObj->nodesetval->nodeTab[i],
199 (
const xmlChar *)
"name");
201 if (xmlStrEqual(curNode->name, (
const xmlChar *)
"RequireBackup"))
203 if (xmlStrEqual(curNode->name, (
const xmlChar *)
"Module"))
204 module = (
char *) xmlNodeGetContent(curNode);
205 if (xmlStrEqual(curNode->name, (
const xmlChar *)
"TokenLabel"))
206 tokenlabel = (
char *) xmlNodeGetContent(curNode);
207 if (xmlStrEqual(curNode->name, (
const xmlChar *)
"PIN"))
208 pin = (
char *) xmlNodeGetContent(curNode);
209 if (xmlStrEqual(curNode->name, (
const xmlChar *)
"SkipPublicKey"))
212 curNode = curNode->next;
214 if (name && module && tokenlabel) {
215 repo = hsm_repository_new(name, module, tokenlabel, pin,
216 use_pubkey, require_backup);
219 ods_log_error(
"[%s] unable to add %s repository: " 220 "hsm_repository_new() failed", parser_str, name?name:
"-");
224 ods_log_debug(
"[%s] added %s repository to repositorylist",
229 free((
void*)tokenlabel);
234 xmlXPathFreeObject(xpathObj);
235 xmlXPathFreeContext(xpathCtx);
253 char* address = NULL;
255 xmlDocPtr doc = NULL;
256 xmlXPathContextPtr xpathCtx = NULL;
257 xmlXPathObjectPtr xpathObj = NULL;
258 xmlNode* curNode = NULL;
259 xmlChar* xexpr = NULL;
261 ods_log_assert(cfgfile);
264 doc = xmlParseFile(cfgfile);
266 ods_log_error(
"[%s] could not parse <Listener>: " 267 "xmlParseFile() failed", parser_str);
271 xpathCtx = xmlXPathNewContext(doc);
272 if(xpathCtx == NULL) {
274 ods_log_error(
"[%s] could not parse <Listener>: " 275 "xmlXPathNewContext() failed", parser_str);
279 xexpr = (xmlChar*)
"//Configuration/Signer/Listener/Interface";
280 xpathObj = xmlXPathEvalExpression(xexpr, xpathCtx);
281 if(xpathObj == NULL) {
282 xmlXPathFreeContext(xpathCtx);
284 ods_log_error(
"[%s] could not parse <Listener>: " 285 "xmlXPathEvalExpression failed", parser_str);
290 ods_log_assert(listener);
291 if (xpathObj->nodesetval && xpathObj->nodesetval->nodeNr > 0) {
292 for (i = 0; i < xpathObj->nodesetval->nodeNr; i++) {
296 curNode = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
298 if (xmlStrEqual(curNode->name, (
const xmlChar *)
"Address")) {
299 address = (
char *) xmlNodeGetContent(curNode);
300 }
else if (xmlStrEqual(curNode->name, (
const xmlChar *)
"Port")) {
301 port = (
char *) xmlNodeGetContent(curNode);
303 curNode = curNode->next;
307 acl_parse_family(address), port);
309 interface =
listener_push(listener, (char *)
"", AF_INET, port);
311 interface =
listener_push(listener, (char *)
"", AF_INET6, port);
315 ods_log_error(
"[%s] unable to add %s:%s interface: " 316 "listener_push() failed", parser_str, address?address:
"",
319 ods_log_debug(
"[%s] added %s:%s interface to listener",
320 parser_str, address?address:
"", port?port:
"");
323 free((
void*)address);
326 xmlXPathFreeObject(xpathObj);
327 xmlXPathFreeContext(xpathCtx);
342 xmlDocPtr doc = NULL;
343 xmlXPathContextPtr xpathCtx = NULL;
344 xmlXPathObjectPtr xpathObj = NULL;
345 xmlChar *xexpr = NULL;
346 const char*
string = NULL;
348 ods_log_assert(expr);
349 ods_log_assert(cfgfile);
352 doc = xmlParseFile(cfgfile);
354 ods_log_error(
"[%s] unable to parse file %s: xmlParseFile() failed",
355 parser_str, cfgfile);
359 xpathCtx = xmlXPathNewContext(doc);
360 if (xpathCtx == NULL) {
361 ods_log_error(
"[%s] unable to parse file %s: xmlXPathNewContext() " 362 "failed", parser_str, cfgfile);
367 xexpr = (
unsigned char*) expr;
368 xpathObj = xmlXPathEvalExpression(xexpr, xpathCtx);
369 if (xpathObj == NULL || xpathObj->nodesetval == NULL ||
370 xpathObj->nodesetval->nodeNr <= 0) {
372 ods_log_error(
"[%s] unable to evaluate expression %s in cfgile %s",
373 parser_str, (
char*) xexpr, cfgfile);
375 xmlXPathFreeContext(xpathCtx);
377 xmlXPathFreeObject(xpathObj);
382 if (xpathObj->nodesetval != NULL &&
383 xpathObj->nodesetval->nodeNr > 0) {
384 string = (
const char*) xmlXPathCastToString(xpathObj);
385 xmlXPathFreeContext(xpathCtx);
386 xmlXPathFreeObject(xpathObj);
390 xmlXPathFreeContext(xpathCtx);
391 xmlXPathFreeObject(xpathObj);
411 "//Configuration/Enforcer/WorkingDirectory",
417 str = OPENDNSSEC_ENFORCER_WORKINGDIR;
420 lzl = strlen(OPENDNSSEC_ENFORCER_ZONELIST);
421 if (lwd>0 && strncmp(str + (lwd-1),
"/", 1) != 0) {
422 CHECKALLOC(dup = malloc(
sizeof(
char)*(lwd+lzl+2)));
423 memcpy(dup, str,
sizeof(
char)*(lwd+1));
424 strlcat(dup,
"/",
sizeof(
char)*(lwd+2));
425 strlcat(dup, OPENDNSSEC_ENFORCER_ZONELIST,
sizeof(
char)*(lwd+lzl+2));
428 CHECKALLOC(dup = malloc(
sizeof(
char)*(lwd+lzl+1)));
429 memcpy(dup, str,
sizeof(
char)*(lwd+1));
430 strlcat(dup, OPENDNSSEC_ENFORCER_ZONELIST,
sizeof(
char)*(lwd+lzl+1));
437 return (
const char*) dup;
444 const char* dup = NULL;
446 "//Configuration/Common/Logging/Syslog/Facility",
450 "//Configuration/Common/Logging/File/Filename",
464 const char* dup = NULL;
467 "//Configuration/Signer/PidFile",
474 dup = strdup(ODS_SE_PIDFILE);
483 const char* dup = NULL;
486 "//Configuration/Signer/NotifyCommand",
503 "//Configuration/Signer/SocketFile",
510 dup = strdup(ODS_SE_SOCKFILE);
512 if (strlen(dup) >=
sizeof(((
struct sockaddr_un*)0)->sun_path)) {
513 dup[
sizeof(((
struct sockaddr_un*)0)->sun_path)-1] =
'\0';
514 ods_log_warning(
"[%s] SocketFile path too long, truncated to %s", parser_str, dup);
523 const char* dup = NULL;
526 "//Configuration/Signer/WorkingDirectory",
533 dup = strdup(ODS_SE_WORKDIR);
543 const char* dup = NULL;
546 "//Configuration/Signer/Privileges/User",
560 const char* dup = NULL;
563 "//Configuration/Signer/Privileges/Group",
577 const char* dup = NULL;
580 "//Configuration/Signer/Privileges/Directory",
599 "//Configuration/Common/Logging/Syslog/Facility",
611 int verbosity = ODS_SE_VERBOSITY;
613 "//Configuration/Common/Logging/Verbosity",
616 if (strlen(str) > 0) {
617 verbosity = atoi(str);
628 int numwt = ODS_SE_WORKERTHREADS;
630 "//Configuration/Signer/WorkerThreads",
633 if (strlen(str) > 0) {
645 int numwt = ODS_SE_WORKERTHREADS;
647 "//Configuration/Signer/SignerThreads",
650 if (strlen(str) > 0) {
int parse_conf_worker_threads(const char *cfgfile)
int parse_conf_use_syslog(const char *cfgfile)
const char * parse_conf_clisock_filename(const char *cfgfile)
ods_status parse_file_check(const char *cfgfile, const char *rngfile)
const char * parse_conf_working_dir(const char *cfgfile)
const char * parse_conf_group(const char *cfgfile)
int parse_conf_signer_threads(const char *cfgfile)
const char * parse_conf_log_filename(const char *cfgfile)
const char * parse_conf_chroot(const char *cfgfile)
listener_type * listener_create()
const char * parse_conf_string(const char *cfgfile, const char *expr, int required)
listener_type * parse_conf_listener(const char *cfgfile)
const char * parse_conf_username(const char *cfgfile)
int parse_conf_verbosity(const char *cfgfile)
hsm_repository_t * parse_conf_repositories(const char *cfgfile)
const char * parse_conf_notify_command(const char *cfgfile)
const char * parse_conf_zonelist_filename(const char *cfgfile)
const char * parse_conf_pid_filename(const char *cfgfile)
interface_type * listener_push(listener_type *listener, char *address, int family, char *port)