38#include <libxml/xpath.h>
39#include <libxml/relaxng.h>
40#include <libxml/xmlreader.h>
45static 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) {
63 ods_log_error(
"[%s] no cfgfile or rngfile", parser_str);
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);
74 ods_log_error(
"[%s] unable to read cfgfile %s", parser_str,
76 return ODS_STATUS_XML_ERR;
79 rngdoc = xmlParseFile(rngfile);
81 ods_log_error(
"[%s] unable to read rngfile %s", parser_str,
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;
219 uint8_t allowextract;
221 hsm_repository_t* rlist = NULL;
222 hsm_repository_t* repo = NULL;
225 doc = xmlParseFile(cfgfile);
227 ods_log_error(
"[%s] could not parse <RepositoryList>: "
228 "xmlParseFile() failed", parser_str);
232 xpathCtx = xmlXPathNewContext(doc);
233 if(xpathCtx == NULL) {
235 ods_log_error(
"[%s] could not parse <RepositoryList>: "
236 "xmlXPathNewContext() failed", parser_str);
240 xexpr = (xmlChar*)
"//Configuration/RepositoryList/Repository";
241 xpathObj = xmlXPathEvalExpression(xexpr, xpathCtx);
242 if(xpathObj == NULL) {
243 xmlXPathFreeContext(xpathCtx);
245 ods_log_error(
"[%s] could not parse <RepositoryList>: "
246 "xmlXPathEvalExpression failed", parser_str);
250 if (xpathObj->nodesetval && xpathObj->nodesetval->nodeNr > 0) {
251 for (i = 0; i < xpathObj->nodesetval->nodeNr; i++) {
261 curNode = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
262 name = (
char *) xmlGetProp(xpathObj->nodesetval->nodeTab[i],
263 (
const xmlChar *)
"name");
265 if (xmlStrEqual(curNode->name, (
const xmlChar *)
"RequireBackup"))
267 if (xmlStrEqual(curNode->name, (
const xmlChar *)
"Module"))
268 module = (
char *) xmlNodeGetContent(curNode);
269 if (xmlStrEqual(curNode->name, (
const xmlChar *)
"TokenLabel"))
270 tokenlabel = (
char *) xmlNodeGetContent(curNode);
271 if (xmlStrEqual(curNode->name, (
const xmlChar *)
"PIN"))
272 pin = (
char *) xmlNodeGetContent(curNode);
273 if (xmlStrEqual(curNode->name, (
const xmlChar *)
"SkipPublicKey"))
275 if (xmlStrEqual(curNode->name, (
const xmlChar *)
"AllowExtraction"))
278 curNode = curNode->next;
280 if (name && module && tokenlabel) {
281 repo = hsm_repository_new(name, module, tokenlabel, pin,
282 use_pubkey, allowextract, require_backup);
285 ods_log_error(
"[%s] unable to add %s repository: "
286 "hsm_repository_new() failed", parser_str, name?name:
"-");
290 ods_log_debug(
"[%s] added %s repository to repositorylist",
295 free((
void*)tokenlabel);
299 xmlXPathFreeObject(xpathObj);
300 xmlXPathFreeContext(xpathCtx);
316 const char* dup = NULL;
319 "//Configuration/Common/PolicyFile",
332 const char* dup = NULL;
335 "//Configuration/Common/ZoneListFile",
349 const char* dup = NULL;
352 "//Configuration/Common/ZoneFetchFile",
366 const char* dup = NULL;
368 "//Configuration/Common/Logging/Syslog/Facility",
372 "//Configuration/Common/Logging/File/Filename",
386 const char* dup = NULL;
389 "//Configuration/Enforcer/PidFile",
396 dup = strdup(OPENDNSSEC_ENFORCER_PIDFILE);
405 const char* dup = NULL;
408 "//Configuration/Enforcer/DelegationSignerSubmitCommand",
421 const char* dup = NULL;
424 "//Configuration/Enforcer/DelegationSignerRetractCommand",
440 "//Configuration/Enforcer/SocketFile",
447 dup = strdup(OPENDNSSEC_ENFORCER_SOCKETFILE);
449 if (strlen(dup) >=
sizeof(((
struct sockaddr_un*)0)->sun_path)) {
450 dup[
sizeof(((
struct sockaddr_un*)0)->sun_path)-1] =
'\0';
451 ods_log_warning(
"[%s] SocketFile path too long, truncated to %s", parser_str, dup);
460 const char* dup = NULL;
463 "//Configuration/Enforcer/WorkingDirectory",
470 dup = strdup(OPENDNSSEC_ENFORCER_WORKINGDIR);
479 const char* dup = NULL;
482 "//Configuration/Enforcer/Privileges/User",
496 const char* dup = NULL;
499 "//Configuration/Enforcer/Privileges/Group",
513 const char* dup = NULL;
516 "//Configuration/Enforcer/Privileges/Directory",
529 const char* dup = NULL;
532 "//Configuration/Enforcer/Datastore/MySQL/Database",
537 "//Configuration/Enforcer/Datastore/SQLite",
545 dup = strdup(
"KASP");
554 const char* dup = NULL;
557 "//Configuration/Enforcer/Datastore/MySQL/Host",
570 const char* dup = NULL;
573 "//Configuration/Enforcer/Datastore/MySQL/Username",
586 const char* dup = NULL;
589 "//Configuration/Enforcer/Datastore/MySQL/Password",
607 "//Configuration/Common/Logging/Syslog/Facility",
621 "//Configuration/Common/Logging/Verbosity",
624 if (strlen(str) > 0) {
636 int numwt = ODS_SE_WORKERTHREADS;
638 "//Configuration/Enforcer/WorkerThreads",
641 if (strlen(str) > 0) {
653 "//Configuration/Enforcer/ManualKeyGeneration",
667 "//Configuration/Enforcer/Datastore/MySQL/Host/@Port",
670 if (strlen(str) > 0) {
679 const char* str = NULL;
683 "//Configuration/Enforcer/Datastore/MySQL/Database",
692 "//Configuration/Enforcer/Datastore/SQLite",
705 time_t period = 365 * 24 * 3600;
707 "//Configuration/Enforcer/AutomaticKeyGenerationPeriod",
710 if (strlen(str) > 0) {
711 duration_type* duration = duration_create_from_string(str);
713 time_t duration_period = duration2time(duration);
714 period = duration_period;
715 duration_cleanup(duration);
728 "//Configuration/Enforcer/RolloverNotification",
731 if (strlen(str) > 0) {
732 duration_type* duration = duration_create_from_string(str);
734 period = duration2time(duration);
735 duration_cleanup(duration);
engineconfig_database_type_t
@ ENFORCER_DATABASE_TYPE_MYSQL
@ ENFORCER_DATABASE_TYPE_SQLITE
@ ENFORCER_DATABASE_TYPE_NONE
const char * parse_conf_db_username(const char *cfgfile)
engineconfig_database_type_t parse_conf_db_type(const char *cfgfile)
const char * parse_conf_clisock_filename(const char *cfgfile)
const char * parse_conf_delegation_signer_retract_command(const char *cfgfile)
const char * parse_conf_db_host(const char *cfgfile)
const char * parse_conf_policy_filename(const char *cfgfile)
const char * parse_conf_delegation_signer_submit_command(const char *cfgfile)
int parse_conf_db_port(const char *cfgfile)
const char * parse_conf_zonelist_filename(const char *cfgfile)
hsm_repository_t * parse_conf_repositories(const char *cfgfile)
const char * parse_conf_working_dir(const char *cfgfile)
const char * parse_conf_log_filename(const char *cfgfile)
int parse_conf_worker_threads(const char *cfgfile)
const char * parse_conf_username(const char *cfgfile)
time_t parse_conf_rollover_notification(const char *cfgfile)
const char * parse_conf_zonefetch_filename(const char *cfgfile)
const char * parse_conf_pid_filename(const char *cfgfile)
int parse_conf_use_syslog(const char *cfgfile)
const char * parse_conf_db_password(const char *cfgfile)
const char * parse_conf_chroot(const char *cfgfile)
const char * parse_conf_datastore(const char *cfgfile)
const char * parse_conf_group(const char *cfgfile)
time_t parse_conf_automatic_keygen_period(const char *cfgfile)
int parse_conf_manual_keygen(const char *cfgfile)
int parse_conf_verbosity(const char *cfgfile)
ods_status parse_file_check(const char *cfgfile, const char *rngfile)
const char * parse_conf_string(const char *cfgfile, const char *expr, int required)