37#include <libxml/parser.h>
38#include <libxml/xpath.h>
39#include <libxml/xpathInternals.h>
40#include <libxml/xmlreader.h>
43static const char* parser_str =
"parser";
54 xmlXPathContextPtr xpathCtx = NULL;
55 xmlXPathObjectPtr xpathObj = NULL;
56 xmlNode* curNode = NULL;
57 xmlChar* xexpr = NULL;
65 int ksk, zsk, publish, i;
67 if (!cfgfile || !sc) {
71 doc = xmlParseFile(cfgfile);
73 ods_log_error(
"[%s] unable to parse <Keys>: "
74 "xmlParseFile() failed", parser_str);
78 xpathCtx = xmlXPathNewContext(doc);
79 if(xpathCtx == NULL) {
81 ods_log_error(
"[%s] unable to parse <Keys>: "
82 "xmlXPathNewContext() failed", parser_str);
86 xexpr = (xmlChar*)
"//SignerConfiguration/Zone/Keys/Key";
87 xpathObj = xmlXPathEvalExpression(xexpr, xpathCtx);
88 if(xpathObj == NULL) {
89 xmlXPathFreeContext(xpathCtx);
91 ods_log_error(
"[%s] unable to parse <Keys>: "
92 "xmlXPathEvalExpression() failed", parser_str);
98 if (xpathObj->nodesetval && xpathObj->nodesetval->nodeNr > 0) {
99 for (i = 0; i < xpathObj->nodesetval->nodeNr; i++) {
100 resourcerecord = NULL;
109 curNode = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
111 if (xmlStrEqual(curNode->name, (
const xmlChar *)
"Locator")) {
112 locator = (
char *) xmlNodeGetContent(curNode);
113 }
else if (xmlStrEqual(curNode->name, (
const xmlChar *)
"Algorithm")) {
114 algorithm = (
char *) xmlNodeGetContent(curNode);
115 }
else if (xmlStrEqual(curNode->name, (
const xmlChar *)
"Flags")) {
116 flags = (
char *) xmlNodeGetContent(curNode);
117 }
else if (xmlStrEqual(curNode->name, (
const xmlChar *)
"KSK")) {
119 }
else if (xmlStrEqual(curNode->name, (
const xmlChar *)
"ZSK")) {
121 }
else if (xmlStrEqual(curNode->name, (
const xmlChar *)
"Publish")) {
123 }
else if (xmlStrEqual(curNode->name, (
const xmlChar *)
"ResourceRecord")) {
124 resourcerecord = (
char *) xmlNodeGetContent(curNode);
126 curNode = curNode->next;
132 if (!locator && !resourcerecord)
138 new_key->
algorithm == (uint8_t) atoi(algorithm) &&
139 new_key->
flags == (uint32_t) atoi(flags) &&
141 new_key->
ksk == ksk &&
142 new_key->
zsk == zsk) {
144 ods_log_warning(
"[%s] unable to push duplicate key %s "
145 "to keylist, skipping", parser_str, locator);
148 (uint8_t) atoi(algorithm), (uint32_t) atoi(flags),
152 ods_log_error(
"[%s] unable to push key to keylist: <Key> "
153 "is missing required elements, skipping",
156 free((
void*)algorithm);
160 xmlXPathFreeObject(xpathObj);
161 xmlXPathFreeContext(xpathCtx);
176 duration_type* duration = NULL;
178 "//SignerConfiguration/Zone/Signatures/Resign",
183 duration = duration_create_from_string(str);
192 duration_type* duration = NULL;
194 "//SignerConfiguration/Zone/Signatures/Refresh",
199 duration = duration_create_from_string(str);
208 duration_type* duration = NULL;
210 "//SignerConfiguration/Zone/Signatures/Validity/Default",
215 duration = duration_create_from_string(str);
224 duration_type* duration = NULL;
226 "//SignerConfiguration/Zone/Signatures/Validity/Denial",
231 duration = duration_create_from_string(str);
240 duration_type* duration = NULL;
242 "//SignerConfiguration/Zone/Signatures/Validity/Keyset",
249 duration = duration_create_from_string(str);
258 duration_type* duration = NULL;
260 "//SignerConfiguration/Zone/Signatures/Jitter",
265 duration = duration_create_from_string(str);
274 duration_type* duration = NULL;
276 "//SignerConfiguration/Zone/Signatures/InceptionOffset",
281 duration = duration_create_from_string(str);
290 duration_type* duration = NULL;
292 "//SignerConfiguration/Zone/Keys/TTL",
297 duration = duration_create_from_string(str);
306 xmlDocPtr doc = NULL;
307 xmlXPathContextPtr xpathCtx = NULL;
308 xmlXPathObjectPtr xpathObj = NULL;
309 xmlNode* curNode = NULL;
310 xmlChar* xexpr = NULL;
311 const char **signatureresourcerecords;
318 doc = xmlParseFile(cfgfile);
320 ods_log_error(
"[%s] unable to parse <Keys>: "
321 "xmlParseFile() failed", parser_str);
325 xpathCtx = xmlXPathNewContext(doc);
326 if(xpathCtx == NULL) {
328 ods_log_error(
"[%s] unable to parse <Keys>: "
329 "xmlXPathNewContext() failed", parser_str);
333 xexpr = (xmlChar*)
"//SignerConfiguration/Zone/Keys/SignatureResourceRecord";
334 xpathObj = xmlXPathEvalExpression(xexpr, xpathCtx);
335 if(xpathObj == NULL) {
336 xmlXPathFreeContext(xpathCtx);
338 ods_log_error(
"[%s] unable to parse <Keys>: "
339 "xmlXPathEvalExpression() failed", parser_str);
343 if (xpathObj->nodesetval && xpathObj->nodesetval->nodeNr > 0) {
344 signatureresourcerecords = malloc(
sizeof(
char*) * (xpathObj->nodesetval->nodeNr + 1));
345 for (i = 0; i < xpathObj->nodesetval->nodeNr; i++) {
346 curNode = xpathObj->nodesetval->nodeTab[i];
347 signatureresourcerecords[i] = (
char *) xmlNodeGetContent(curNode);
349 signatureresourcerecords[i] = NULL;
351 signatureresourcerecords = NULL;
353 xmlXPathFreeObject(xpathObj);
354 xmlXPathFreeContext(xpathCtx);
358 return signatureresourcerecords;
366 duration_type* duration = NULL;
368 "//SignerConfiguration/Zone/Denial/NSEC3/TTL",
373 duration = duration_create_from_string(str);
382 duration_type* duration = NULL;
384 "//SignerConfiguration/Zone/SOA/TTL",
389 duration = duration_create_from_string(str);
398 duration_type* duration = NULL;
400 "//SignerConfiguration/Zone/SOA/Minimum",
405 duration = duration_create_from_string(str);
414 duration_type* duration = NULL;
416 "//SignerConfiguration/Zone/Signatures/MaxZoneTTL",
421 duration = duration_create_from_string(str);
435 "//SignerConfiguration/Zone/Denial/NSEC3",
439 return LDNS_RR_TYPE_NSEC3;
442 "//SignerConfiguration/Zone/Denial/NSEC",
446 return LDNS_RR_TYPE_NSEC;
448 return LDNS_RR_TYPE_FIRST;
461 "//SignerConfiguration/Zone/Denial/NSEC3/Hash/Algorithm",
464 if (strlen(str) > 0) {
478 "//SignerConfiguration/Zone/Denial/NSEC3/Hash/Iterations",
481 if (strlen(str) > 0) {
495 "//SignerConfiguration/Zone/Denial/NSEC3/OptOut",
509 "//SignerConfiguration/Zone/Passthrough",
525 const char* dup = NULL;
528 "//SignerConfiguration/Zone/SOA/Serial",
542 const char* dup = NULL;
545 "//SignerConfiguration/Zone/Denial/NSEC3/Hash/Salt",
const char * parse_conf_string(const char *cfgfile, const char *expr, int required)
keylist_type * keylist_create(signconf_type *signconf)
key_type * keylist_push(keylist_type *kl, const char *locator, const char *resourcerecord, uint8_t algorithm, uint32_t flags, int publish, int ksk, int zsk)
key_type * keylist_lookup_by_locator(keylist_type *kl, const char *locator)
duration_type * parse_sc_sig_validity_denial(const char *cfgfile)
const char * parse_sc_nsec3_salt(const char *cfgfile)
int parse_sc_nsec3_optout(const char *cfgfile)
duration_type * parse_sc_sig_resign_interval(const char *cfgfile)
duration_type * parse_sc_soa_min(const char *cfgfile)
const char ** parse_sc_dnskey_sigrrs(const char *cfgfile)
duration_type * parse_sc_sig_inception_offset(const char *cfgfile)
uint32_t parse_sc_nsec3_algorithm(const char *cfgfile)
duration_type * parse_sc_dnskey_ttl(const char *cfgfile)
keylist_type * parse_sc_keys(void *sc, const char *cfgfile)
uint32_t parse_sc_nsec3_iterations(const char *cfgfile)
duration_type * parse_sc_sig_validity_default(const char *cfgfile)
duration_type * parse_sc_max_zone_ttl(const char *cfgfile)
const char * parse_sc_soa_serial(const char *cfgfile)
int parse_sc_passthrough(const char *cfgfile)
duration_type * parse_sc_sig_jitter(const char *cfgfile)
duration_type * parse_sc_nsec3param_ttl(const char *cfgfile)
duration_type * parse_sc_sig_validity_keyset(const char *cfgfile)
duration_type * parse_sc_soa_ttl(const char *cfgfile)
ldns_rr_type parse_sc_nsec_type(const char *cfgfile)
duration_type * parse_sc_sig_refresh_interval(const char *cfgfile)