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;
157 uint8_t allowextract;
159 hsm_repository_t* rlist = NULL;
160 hsm_repository_t* repo = NULL;
163 doc = xmlParseFile(cfgfile);
165 ods_log_error(
"[%s] could not parse <RepositoryList>: "
166 "xmlParseFile() failed", parser_str);
170 xpathCtx = xmlXPathNewContext(doc);
171 if(xpathCtx == NULL) {
173 ods_log_error(
"[%s] could not parse <RepositoryList>: "
174 "xmlXPathNewContext() failed", parser_str);
178 xexpr = (xmlChar*)
"//Configuration/RepositoryList/Repository";
179 xpathObj = xmlXPathEvalExpression(xexpr, xpathCtx);
180 if(xpathObj == NULL) {
181 xmlXPathFreeContext(xpathCtx);
183 ods_log_error(
"[%s] could not parse <RepositoryList>: "
184 "xmlXPathEvalExpression failed", parser_str);
188 if (xpathObj->nodesetval && xpathObj->nodesetval->nodeNr > 0) {
189 for (i = 0; i < xpathObj->nodesetval->nodeNr; i++) {
199 curNode = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
200 name = (
char *) xmlGetProp(xpathObj->nodesetval->nodeTab[i],
201 (
const xmlChar *)
"name");
203 if (xmlStrEqual(curNode->name, (
const xmlChar *)
"RequireBackup"))
205 if (xmlStrEqual(curNode->name, (
const xmlChar *)
"Module"))
206 module = (
char *) xmlNodeGetContent(curNode);
207 if (xmlStrEqual(curNode->name, (
const xmlChar *)
"TokenLabel"))
208 tokenlabel = (
char *) xmlNodeGetContent(curNode);
209 if (xmlStrEqual(curNode->name, (
const xmlChar *)
"PIN"))
210 pin = (
char *) xmlNodeGetContent(curNode);
211 if (xmlStrEqual(curNode->name, (
const xmlChar *)
"SkipPublicKey"))
213 if (xmlStrEqual(curNode->name, (
const xmlChar *)
"AllowExtraction"))
216 curNode = curNode->next;
218 if (name && module && tokenlabel) {
219 repo = hsm_repository_new(name, module, tokenlabel, pin,
220 use_pubkey, allowextract, require_backup);
223 ods_log_error(
"[%s] unable to add %s repository: "
224 "hsm_repository_new() failed", parser_str, name?name:
"-");
228 ods_log_debug(
"[%s] added %s repository to repositorylist",
233 free((
void*)tokenlabel);
238 xmlXPathFreeObject(xpathObj);
239 xmlXPathFreeContext(xpathCtx);
257 char* address = NULL;
258 const char* port = NULL;
259 xmlDocPtr doc = NULL;
260 xmlXPathContextPtr xpathCtx = NULL;
261 xmlXPathObjectPtr xpathObj = NULL;
262 xmlNode* curNode = NULL;
263 xmlChar* xexpr = NULL;
265 ods_log_assert(cfgfile);
268 doc = xmlParseFile(cfgfile);
270 ods_log_error(
"[%s] could not parse <Listener>: "
271 "xmlParseFile() failed", parser_str);
275 xpathCtx = xmlXPathNewContext(doc);
276 if(xpathCtx == NULL) {
278 ods_log_error(
"[%s] could not parse <Listener>: "
279 "xmlXPathNewContext() failed", parser_str);
283 xexpr = (xmlChar*)
"//Configuration/Signer/Listener/Interface";
284 xpathObj = xmlXPathEvalExpression(xexpr, xpathCtx);
285 if(xpathObj == NULL) {
286 xmlXPathFreeContext(xpathCtx);
288 ods_log_error(
"[%s] could not parse <Listener>: "
289 "xmlXPathEvalExpression failed", parser_str);
294 ods_log_assert(listener);
299 if (xpathObj->nodesetval && xpathObj->nodesetval->nodeNr > 0) {
300 for (i = 0; i < xpathObj->nodesetval->nodeNr; i++) {
302 port = strdup(
"15354");
304 curNode = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
306 if (xmlStrEqual(curNode->name, (
const xmlChar *)
"Address")) {
307 address = (
char *) xmlNodeGetContent(curNode);
308 }
else if (xmlStrEqual(curNode->name, (
const xmlChar *)
"Port")) {
310 port = (
char *) xmlNodeGetContent(curNode);
312 curNode = curNode->next;
318 interface =
listener_push(listener, (char *)
"", AF_INET, port);
320 interface =
listener_push(listener, (char *)
"", AF_INET6, port);
324 ods_log_error(
"[%s] unable to add %s:%s interface: "
325 "listener_push() failed", parser_str, address?address:
"",
328 ods_log_debug(
"[%s] added %s:%s interface to listener",
329 parser_str, address?address:
"", port);
332 free((
void*)address);
336 interface =
listener_push(listener, (char *)
"", AF_INET,
"15354");
338 interface =
listener_push(listener, (char *)
"", AF_INET6,
"15354");
341 xmlXPathFreeObject(xpathObj);
342 xmlXPathFreeContext(xpathCtx);
357 xmlDocPtr doc = NULL;
358 xmlXPathContextPtr xpathCtx = NULL;
359 xmlXPathObjectPtr xpathObj = NULL;
360 xmlChar *xexpr = NULL;
361 const char*
string = NULL;
363 ods_log_assert(expr);
364 ods_log_assert(cfgfile);
367 doc = xmlParseFile(cfgfile);
369 ods_log_error(
"[%s] unable to parse file %s: xmlParseFile() failed",
370 parser_str, cfgfile);
374 xpathCtx = xmlXPathNewContext(doc);
375 if (xpathCtx == NULL) {
376 ods_log_error(
"[%s] unable to parse file %s: xmlXPathNewContext() "
377 "failed", parser_str, cfgfile);
382 xexpr = (
unsigned char*) expr;
383 xpathObj = xmlXPathEvalExpression(xexpr, xpathCtx);
384 if (xpathObj == NULL || xpathObj->nodesetval == NULL ||
385 xpathObj->nodesetval->nodeNr <= 0) {
387 ods_log_error(
"[%s] unable to evaluate expression %s in cfgile %s",
388 parser_str, (
char*) xexpr, cfgfile);
390 xmlXPathFreeContext(xpathCtx);
392 xmlXPathFreeObject(xpathObj);
397 if (xpathObj->nodesetval != NULL &&
398 xpathObj->nodesetval->nodeNr > 0) {
399 string = (
const char*) xmlXPathCastToString(xpathObj);
400 xmlXPathFreeContext(xpathCtx);
401 xmlXPathFreeObject(xpathObj);
405 xmlXPathFreeContext(xpathCtx);
406 xmlXPathFreeObject(xpathObj);
426 "//Configuration/Enforcer/WorkingDirectory",
432 str = OPENDNSSEC_ENFORCER_WORKINGDIR;
435 lzl = strlen(OPENDNSSEC_ENFORCER_ZONELIST);
436 if (lwd>0 && strncmp(str + (lwd-1),
"/", 1) != 0) {
437 CHECKALLOC(dup = malloc(
sizeof(
char)*(lwd+lzl+2)));
438 memcpy(dup, str,
sizeof(
char)*(lwd+1));
439 strlcat(dup,
"/",
sizeof(
char)*(lwd+2));
440 strlcat(dup, OPENDNSSEC_ENFORCER_ZONELIST,
sizeof(
char)*(lwd+lzl+2));
443 CHECKALLOC(dup = malloc(
sizeof(
char)*(lwd+lzl+1)));
444 memcpy(dup, str,
sizeof(
char)*(lwd+1));
445 strlcat(dup, OPENDNSSEC_ENFORCER_ZONELIST,
sizeof(
char)*(lwd+lzl+1));
452 return (
const char*) dup;
459 const char* dup = NULL;
461 "//Configuration/Common/Logging/Syslog/Facility",
465 "//Configuration/Common/Logging/File/Filename",
479 const char* dup = NULL;
482 "//Configuration/Signer/PidFile",
489 dup = strdup(ODS_SE_PIDFILE);
498 const char* dup = NULL;
501 "//Configuration/Signer/NotifyCommand",
518 "//Configuration/Signer/SocketFile",
525 dup = strdup(ODS_SE_SOCKFILE);
527 if (strlen(dup) >=
sizeof(((
struct sockaddr_un*)0)->sun_path)) {
528 dup[
sizeof(((
struct sockaddr_un*)0)->sun_path)-1] =
'\0';
529 ods_log_warning(
"[%s] SocketFile path too long, truncated to %s", parser_str, dup);
538 const char* dup = NULL;
541 "//Configuration/Signer/WorkingDirectory",
548 dup = strdup(ODS_SE_WORKDIR);
558 const char* dup = NULL;
561 "//Configuration/Signer/Privileges/User",
575 const char* dup = NULL;
578 "//Configuration/Signer/Privileges/Group",
592 const char* dup = NULL;
595 "//Configuration/Signer/Privileges/Directory",
614 "//Configuration/Common/Logging/Syslog/Facility",
626 int verbosity = ODS_SE_VERBOSITY;
628 "//Configuration/Common/Logging/Verbosity",
631 if (strlen(str) > 0) {
632 verbosity = atoi(str);
643 int numwt = ODS_SE_WORKERTHREADS;
645 "//Configuration/Signer/WorkerThreads",
648 if (strlen(str) > 0) {
660 int numwt = ODS_SE_WORKERTHREADS;
662 "//Configuration/Signer/SignerThreads",
665 if (strlen(str) > 0) {
int acl_parse_family(const char *a)
const char * parse_conf_pid_filename(const char *cfgfile)
const char * parse_conf_log_filename(const char *cfgfile)
const char * parse_conf_notify_command(const char *cfgfile)
const char * parse_conf_chroot(const char *cfgfile)
const char * parse_conf_working_dir(const char *cfgfile)
const char * parse_conf_string(const char *cfgfile, const char *expr, int required)
int parse_conf_worker_threads(const char *cfgfile)
int parse_conf_signer_threads(const char *cfgfile)
int parse_conf_use_syslog(const char *cfgfile)
const char * parse_conf_clisock_filename(const char *cfgfile)
const char * parse_conf_zonelist_filename(const char *cfgfile)
listener_type * parse_conf_listener(const char *cfgfile)
const char * parse_conf_group(const char *cfgfile)
hsm_repository_t * parse_conf_repositories(const char *cfgfile)
const char * parse_conf_username(const char *cfgfile)
int parse_conf_verbosity(const char *cfgfile)
ods_status parse_file_check(const char *cfgfile, const char *rngfile)
interface_type * listener_push(listener_type *listener, char *address, int family, const char *port)
listener_type * listener_create()