38 #include <libxml/xpath.h> 39 #include <libxml/relaxng.h> 40 #include <libxml/xmlreader.h> 45 static const char* parser_str =
"parser";
56 xmlDocPtr rngdoc = NULL;
57 xmlRelaxNGParserCtxtPtr rngpctx = NULL;
58 xmlRelaxNGValidCtxtPtr rngctx = NULL;
59 xmlRelaxNGPtr schema = NULL;
62 if (!cfgfile || !rngfile) {
64 return ODS_STATUS_ASSERT_ERR;
66 ods_log_assert(cfgfile);
67 ods_log_assert(rngfile);
68 ods_log_debug(
"[%s] check cfgfile %s with rngfile %s", parser_str,
72 doc = xmlParseFile(cfgfile);
76 return ODS_STATUS_XML_ERR;
79 rngdoc = xmlParseFile(rngfile);
84 return ODS_STATUS_XML_ERR;
87 rngpctx = xmlRelaxNGNewDocParserCtxt(rngdoc);
88 if (rngpctx == NULL) {
91 ods_log_error(
"[%s] unable to create XML RelaxNGs parser context",
93 return ODS_STATUS_XML_ERR;
98 schema = xmlRelaxNGParse(rngpctx);
100 ods_log_error(
"[%s] unable to parse a schema definition resource",
102 xmlRelaxNGFreeParserCtxt(rngpctx);
105 return ODS_STATUS_PARSE_ERR;
108 rngctx = xmlRelaxNGNewValidCtxt(schema);
109 if (rngctx == NULL) {
110 ods_log_error(
"[%s] unable to create RelaxNGs validation context",
112 xmlRelaxNGFree(schema);
113 xmlRelaxNGFreeParserCtxt(rngpctx);
116 return ODS_STATUS_RNG_ERR;
119 status = xmlRelaxNGValidateDoc(rngctx,doc);
121 ods_log_error(
"[%s] cfgfile validation failed %s", parser_str,
123 xmlRelaxNGFreeValidCtxt(rngctx);
124 xmlRelaxNGFree(schema);
125 xmlRelaxNGFreeParserCtxt(rngpctx);
128 return ODS_STATUS_RNG_ERR;
131 xmlRelaxNGFreeValidCtxt(rngctx);
132 xmlRelaxNGFree(schema);
133 xmlRelaxNGFreeParserCtxt(rngpctx);
136 return ODS_STATUS_OK;
148 xmlDocPtr doc = NULL;
149 xmlXPathContextPtr xpathCtx = NULL;
150 xmlXPathObjectPtr xpathObj = NULL;
151 xmlChar *xexpr = NULL;
152 const char*
string = NULL;
154 ods_log_assert(expr);
155 ods_log_assert(cfgfile);
158 doc = xmlParseFile(cfgfile);
163 xpathCtx = xmlXPathNewContext(doc);
164 if (xpathCtx == NULL) {
165 ods_log_error(
"[%s] unable to create new XPath context for cfgile " 166 "%s expr %s", parser_str, cfgfile, (
char*) expr);
171 xexpr = (
unsigned char*) expr;
172 xpathObj = xmlXPathEvalExpression(xexpr, xpathCtx);
173 if (xpathObj == NULL || xpathObj->nodesetval == NULL ||
174 xpathObj->nodesetval->nodeNr <= 0) {
176 ods_log_error(
"[%s] unable to evaluate required element %s in " 177 "cfgfile %s", parser_str, (
char*) xexpr, cfgfile);
179 xmlXPathFreeContext(xpathCtx);
181 xmlXPathFreeObject(xpathObj);
186 if (xpathObj->nodesetval != NULL &&
187 xpathObj->nodesetval->nodeNr > 0) {
188 string = (
const char*) xmlXPathCastToString(xpathObj);
189 xmlXPathFreeContext(xpathCtx);
190 xmlXPathFreeObject(xpathObj);
194 xmlXPathFreeContext(xpathCtx);
195 xmlXPathFreeObject(xpathObj);
207 xmlDocPtr doc = NULL;
208 xmlXPathContextPtr xpathCtx = NULL;
209 xmlXPathObjectPtr xpathObj = NULL;
210 xmlNode* curNode = NULL;
211 xmlChar* xexpr = NULL;
220 hsm_repository_t* rlist = NULL;
221 hsm_repository_t* repo = NULL;
224 doc = xmlParseFile(cfgfile);
227 "xmlParseFile() failed", parser_str);
231 xpathCtx = xmlXPathNewContext(doc);
232 if(xpathCtx == NULL) {
235 "xmlXPathNewContext() failed", parser_str);
239 xexpr = (xmlChar*)
"//Configuration/RepositoryList/Repository";
240 xpathObj = xmlXPathEvalExpression(xexpr, xpathCtx);
241 if(xpathObj == NULL) {
242 xmlXPathFreeContext(xpathCtx);
245 "xmlXPathEvalExpression failed", parser_str);
249 if (xpathObj->nodesetval && xpathObj->nodesetval->nodeNr > 0) {
250 for (i = 0; i < xpathObj->nodesetval->nodeNr; i++) {
259 curNode = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
260 name = (
char *) xmlGetProp(xpathObj->nodesetval->nodeTab[i],
261 (
const xmlChar *)
"name");
263 if (xmlStrEqual(curNode->name, (
const xmlChar *)
"RequireBackup"))
265 if (xmlStrEqual(curNode->name, (
const xmlChar *)
"Module"))
266 module = (
char *) xmlNodeGetContent(curNode);
267 if (xmlStrEqual(curNode->name, (
const xmlChar *)
"TokenLabel"))
268 tokenlabel = (
char *) xmlNodeGetContent(curNode);
269 if (xmlStrEqual(curNode->name, (
const xmlChar *)
"PIN"))
270 pin = (
char *) xmlNodeGetContent(curNode);
271 if (xmlStrEqual(curNode->name, (
const xmlChar *)
"SkipPublicKey"))
274 curNode = curNode->next;
276 if (name && module && tokenlabel) {
277 repo = hsm_repository_new(name, module, tokenlabel, pin,
278 use_pubkey, require_backup);
282 "hsm_repository_new() failed", parser_str, name?name:
"-");
291 free((
void*)tokenlabel);
295 xmlXPathFreeObject(xpathObj);
296 xmlXPathFreeContext(xpathCtx);
312 const char* dup = NULL;
315 "//Configuration/Common/PolicyFile",
328 const char* dup = NULL;
331 "//Configuration/Common/ZoneListFile",
345 const char* dup = NULL;
348 "//Configuration/Common/ZoneFetchFile",
362 const char* dup = NULL;
364 "//Configuration/Common/Logging/Syslog/Facility",
368 "//Configuration/Common/Logging/File/Filename",
382 const char* dup = NULL;
385 "//Configuration/Enforcer/PidFile",
392 dup = strdup(OPENDNSSEC_ENFORCER_PIDFILE);
401 const char* dup = NULL;
404 "//Configuration/Enforcer/DelegationSignerSubmitCommand",
417 const char* dup = NULL;
420 "//Configuration/Enforcer/DelegationSignerRetractCommand",
436 "//Configuration/Enforcer/SocketFile",
443 dup = strdup(OPENDNSSEC_ENFORCER_SOCKETFILE);
445 if (strlen(dup) >=
sizeof(((
struct sockaddr_un*)0)->sun_path)) {
446 dup[
sizeof(((
struct sockaddr_un*)0)->sun_path)-1] =
'\0';
447 ods_log_warning(
"[%s] SocketFile path too long, truncated to %s", parser_str, dup);
456 const char* dup = NULL;
459 "//Configuration/Enforcer/WorkingDirectory",
466 dup = strdup(OPENDNSSEC_ENFORCER_WORKINGDIR);
475 const char* dup = NULL;
478 "//Configuration/Enforcer/Privileges/User",
492 const char* dup = NULL;
495 "//Configuration/Enforcer/Privileges/Group",
509 const char* dup = NULL;
512 "//Configuration/Enforcer/Privileges/Directory",
525 const char* dup = NULL;
528 "//Configuration/Enforcer/Datastore/MySQL/Database",
533 "//Configuration/Enforcer/Datastore/SQLite",
541 dup = strdup(
"KASP");
550 const char* dup = NULL;
553 "//Configuration/Enforcer/Datastore/MySQL/Host",
566 const char* dup = NULL;
569 "//Configuration/Enforcer/Datastore/MySQL/Username",
582 const char* dup = NULL;
585 "//Configuration/Enforcer/Datastore/MySQL/Password",
603 "//Configuration/Common/Logging/Syslog/Facility",
617 "//Configuration/Common/Logging/Verbosity",
620 if (strlen(str) > 0) {
621 verbosity = atoi(str);
632 int numwt = ODS_SE_WORKERTHREADS;
634 "//Configuration/Enforcer/WorkerThreads",
637 if (strlen(str) > 0) {
649 "//Configuration/Enforcer/ManualKeyGeneration",
663 "//Configuration/Enforcer/Datastore/MySQL/Host/@Port",
666 if (strlen(str) > 0) {
675 const char* str = NULL;
679 "//Configuration/Enforcer/Datastore/MySQL/Host",
688 "//Configuration/Enforcer/Datastore/SQLite",
701 time_t period = 365 * 24 * 3600;
703 "//Configuration/Enforcer/AutomaticKeyGenerationPeriod",
706 if (strlen(str) > 0) {
707 duration_type* duration = duration_create_from_string(str);
709 time_t duration_period = duration2time(duration);
710 period = duration_period;
711 duration_cleanup(duration);
int parse_conf_worker_threads(const char *cfgfile)
int parse_conf_db_port(const char *cfgfile)
time_t parse_conf_automatic_keygen_period(const char *cfgfile)
void ods_log_debug(const char *format,...)
const char * parse_conf_db_host(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)
void ods_log_error(const char *format,...)
const char * parse_conf_delegation_signer_submit_command(const char *cfgfile)
const char * parse_conf_working_dir(const char *cfgfile)
int parse_conf_manual_keygen(const char *cfgfile)
const char * parse_conf_policy_filename(const char *cfgfile)
const char * parse_conf_group(const char *cfgfile)
const char * parse_conf_log_filename(const char *cfgfile)
const char * parse_conf_db_password(const char *cfgfile)
engineconfig_database_type_t
const char * parse_conf_chroot(const char *cfgfile)
const char * parse_conf_datastore(const char *cfgfile)
engineconfig_database_type_t parse_conf_db_type(const char *cfgfile)
const char * parse_conf_string(const char *cfgfile, const char *expr, int required)
const char * parse_conf_username(const char *cfgfile)
const char * parse_conf_zonefetch_filename(const char *cfgfile)
int parse_conf_verbosity(const char *cfgfile)
hsm_repository_t * parse_conf_repositories(const char *cfgfile)
const char * parse_conf_zonelist_filename(const char *cfgfile)
const char * parse_conf_pid_filename(const char *cfgfile)
const char * parse_conf_delegation_signer_retract_command(const char *cfgfile)
void ods_log_warning(const char *format,...)
const char * parse_conf_db_username(const char *cfgfile)