35#include <libxml/xpath.h>
36#include <libxml/xmlreader.h>
40static const char* parser_str =
"parser";
48parse_addns_remote(
const char* filename,
58 xmlXPathContextPtr xpathCtx = NULL;
59 xmlXPathObjectPtr xpathObj = NULL;
60 xmlNode* curNode = NULL;
61 xmlChar* xexpr = NULL;
63 if (!filename || !expr) {
67 doc = xmlParseFile(filename);
69 ods_log_error(
"[%s] could not parse %s: xmlParseFile() failed",
74 xpathCtx = xmlXPathNewContext(doc);
75 if(xpathCtx == NULL) {
77 ods_log_error(
"[%s] could not parse %s: xmlXPathNewContext() failed",
82 xexpr = (xmlChar*) expr;
83 xpathObj = xmlXPathEvalExpression(xexpr, xpathCtx);
84 if(xpathObj == NULL) {
85 xmlXPathFreeContext(xpathCtx);
87 ods_log_error(
"[%s] could not parse %s: xmlXPathEvalExpression() "
88 "failed", parser_str, expr);
92 if (xpathObj->nodesetval && xpathObj->nodesetval->nodeNr > 0) {
93 for (i = 0; i < xpathObj->nodesetval->nodeNr; i++) {
98 curNode = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
100 if (xmlStrEqual(curNode->name, (
const xmlChar *)
"Address")) {
101 address = (
char *) xmlNodeGetContent(curNode);
102 }
else if (xmlStrEqual(curNode->name,
103 (
const xmlChar *)
"Port")) {
104 port = (
char *) xmlNodeGetContent(curNode);
105 }
else if (xmlStrEqual(curNode->name,
106 (
const xmlChar *)
"Key")) {
107 key = (
char *) xmlNodeGetContent(curNode);
109 curNode = curNode->next;
112 new_acl =
acl_create(address, port, key, tsig);
114 ods_log_error(
"[%s] unable to add server %s:%s %s to list "
115 "%s: acl_create() failed", parser_str, address,
116 port?port:
"", key?key:
"", (char*) expr);
120 ods_log_debug(
"[%s] added server %s:%s %s to list %s",
121 parser_str, address, port?port:
"", key?key:
"",
125 free((
void*)address);
130 xmlXPathFreeObject(xpathObj);
131 xmlXPathFreeContext(xpathCtx);
144parse_addns_acl(
const char* filename,
152 xmlDocPtr doc = NULL;
153 xmlXPathContextPtr xpathCtx = NULL;
154 xmlXPathObjectPtr xpathObj = NULL;
155 xmlNode* curNode = NULL;
156 xmlChar* xexpr = NULL;
158 if (!filename || !expr) {
162 doc = xmlParseFile(filename);
164 ods_log_error(
"[%s] could not parse %s: xmlParseFile() failed",
169 xpathCtx = xmlXPathNewContext(doc);
170 if(xpathCtx == NULL) {
172 ods_log_error(
"[%s] could not parse %s: xmlXPathNewContext() failed",
177 xexpr = (xmlChar*) expr;
178 xpathObj = xmlXPathEvalExpression(xexpr, xpathCtx);
179 if(xpathObj == NULL) {
180 xmlXPathFreeContext(xpathCtx);
182 ods_log_error(
"[%s] could not parse %s: xmlXPathEvalExpression() "
183 "failed", parser_str, expr);
187 if (xpathObj->nodesetval && xpathObj->nodesetval->nodeNr > 0) {
188 for (i = 0; i < xpathObj->nodesetval->nodeNr; i++) {
192 curNode = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
194 if (xmlStrEqual(curNode->name, (
const xmlChar *)
"Prefix")) {
195 prefix = (
char *) xmlNodeGetContent(curNode);
196 }
else if (xmlStrEqual(curNode->name,
197 (
const xmlChar *)
"Key")) {
198 key = (
char *) xmlNodeGetContent(curNode);
200 curNode = curNode->next;
203 new_acl =
acl_create(prefix, NULL, key, tsig);
205 ods_log_error(
"[%s] unable to add acl for %s %s to list "
206 "%s: acl_create() failed", parser_str, prefix?prefix:
"",
207 key?key:
"", (char*) expr);
211 ods_log_debug(
"[%s] added %s %s interface to list %s",
212 parser_str, prefix?prefix:
"", key?key:
"", (char*) expr);
219 xmlXPathFreeObject(xpathObj);
220 xmlXPathFreeContext(xpathCtx);
233parse_addns_tsig_static(
const char* filename,
242 xmlDocPtr doc = NULL;
243 xmlXPathContextPtr xpathCtx = NULL;
244 xmlXPathObjectPtr xpathObj = NULL;
245 xmlNode* curNode = NULL;
246 xmlChar* xexpr = NULL;
248 if (!filename || !expr) {
252 doc = xmlParseFile(filename);
254 ods_log_error(
"[%s] could not parse %s: xmlParseFile() failed",
259 xpathCtx = xmlXPathNewContext(doc);
260 if(xpathCtx == NULL) {
262 ods_log_error(
"[%s] could not parse %s: xmlXPathNewContext() failed",
267 xexpr = (xmlChar*) expr;
268 xpathObj = xmlXPathEvalExpression(xexpr, xpathCtx);
269 if(xpathObj == NULL) {
270 xmlXPathFreeContext(xpathCtx);
272 ods_log_error(
"[%s] could not parse %s: xmlXPathEvalExpression() "
273 "failed", parser_str, expr);
277 if (xpathObj->nodesetval && xpathObj->nodesetval->nodeNr > 0) {
278 for (i = 0; i < xpathObj->nodesetval->nodeNr; i++) {
283 curNode = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
285 if (xmlStrEqual(curNode->name, (
const xmlChar *)
"Name")) {
286 name = (
char *) xmlNodeGetContent(curNode);
287 }
else if (xmlStrEqual(curNode->name,
288 (
const xmlChar *)
"Algorithm")) {
289 algo = (
char *) xmlNodeGetContent(curNode);
290 }
else if (xmlStrEqual(curNode->name,
291 (
const xmlChar *)
"Secret")) {
292 secret = (
char *) xmlNodeGetContent(curNode);
294 curNode = curNode->next;
296 if (name && algo && secret) {
299 ods_log_error(
"[%s] unable to add tsig %s: "
300 "tsig_create() failed", parser_str, name);
302 new_tsig->
next = tsig;
304 ods_log_debug(
"[%s] added %s tsig to list %s",
305 parser_str, name, (
char*) expr);
313 xmlXPathFreeObject(xpathObj);
314 xmlXPathFreeContext(xpathCtx);
330 return parse_addns_remote(filename, tsig,
331 (
char *)
"//Adapter/DNS/Inbound/RequestTransfer/Remote");
343 return parse_addns_acl(filename, tsig,
344 (
char *)
"//Adapter/DNS/Inbound/AllowNotify/Peer");
356 return parse_addns_acl(filename, tsig,
357 (
char *)
"//Adapter/DNS/Outbound/ProvideTransfer/Peer");
369 return parse_addns_remote(filename, tsig,
370 (
char *)
"//Adapter/DNS/Outbound/Notify/Remote");
381 return parse_addns_tsig_static(filename,
382 (
char *)
"//Adapter/DNS/TSIG");
acl_type * acl_create(char *address, char *port, char *tsig_name, tsig_type *tsig)
tsig_type * parse_addns_tsig(const char *filename)
acl_type * parse_addns_request_xfr(const char *filename, tsig_type *tsig)
acl_type * parse_addns_do_notify(const char *filename, tsig_type *tsig)
acl_type * parse_addns_provide_xfr(const char *filename, tsig_type *tsig)
acl_type * parse_addns_allow_notify(const char *filename, tsig_type *tsig)
tsig_type * tsig_create(char *name, char *algo, char *secret)