39 #include <libxml/tree.h> 40 #include <libxml/parser.h> 41 #include <libxml/xpath.h> 42 #include <libxml/xpathInternals.h> 43 #include <libxml/relaxng.h> 47 char *
config = (
char *) OPENDNSSEC_CONFIG_FILE;
53 #define StrFree(ptr) {if(ptr != NULL) {free(ptr); (ptr) = NULL;}} 61 "usage: %s [options]\n\n" 63 " -c, --conf [PATH_TO_CONF_FILE] Path to OpenDNSSEC configuration file\n" 65 " -k, --kasp [PATH_TO_KASP_FILE] Path to KASP policy file\n" 66 " (defaults to the path from the conf.xml file)\n" 67 " -V, --version Display the version information\n" 68 " -v, --verbose Print extra DEBUG messages\n" 69 " -h, --help Show this message\n",
progname, OPENDNSSEC_CONFIG_FILE);
75 int main (
int argc,
char *argv[])
82 static struct option long_options[] =
84 {
"config", required_argument, 0,
'c'},
85 {
"help", no_argument, 0,
'h'},
86 {
"kasp", required_argument, 0,
'k'},
87 {
"version", no_argument, 0,
'V'},
88 {
"verbose", no_argument, 0,
'v'},
93 if ((
progname = strrchr(argv[0],
'/'))) {
100 while ((ch = getopt_long(argc, argv,
"c:hk:Vv", long_options, &option_index)) != -1) {
114 printf(
"%s version %s\n", PACKAGE_NAME, PACKAGE_VERSION);
133 dual_log(
"DEBUG: finished %d", status);
163 xmlXPathContextPtr xpath_ctx;
164 xmlXPathObjectPtr xpath_obj;
167 char* temp_char = NULL;
170 int* repo_mods = NULL;
172 const char* rngfilename = OPENDNSSEC_SCHEMA_DIR
"/conf.rng";
173 const char* zonerngfilename = OPENDNSSEC_SCHEMA_DIR
"/zonelist.rng";
185 doc = xmlParseFile(
config);
191 xpath_ctx = xmlXPathNewContext(doc);
192 if(xpath_ctx == NULL) {
198 xexpr = (xmlChar *)
"//Configuration/RepositoryList/Repository";
199 xpath_obj = xmlXPathEvalExpression(xexpr, xpath_ctx);
200 if(xpath_obj == NULL) {
201 xmlXPathFreeContext(xpath_ctx);
206 if (xpath_obj->nodesetval) {
210 repo_mods = (
int*)malloc(
sizeof(
int) *
repo_count);
213 if (repo == NULL || repo_mods == NULL ||
repo_list == NULL) {
214 dual_log(
"ERROR: malloc for repo information failed");
221 curNode = xpath_obj->nodesetval->nodeTab[i]->xmlChildrenNode;
224 repo[i].
name = (
char *) xmlGetProp(xpath_obj->nodesetval->nodeTab[i],
225 (
const xmlChar *)
"name");
229 if (xmlStrEqual(curNode->name, (
const xmlChar *)
"TokenLabel"))
230 repo[i].
TokenLabel = (
char *) xmlNodeGetContent(curNode);
231 if (xmlStrEqual(curNode->name, (
const xmlChar *)
"Module"))
232 repo[i].module = (
char *) xmlNodeGetContent(curNode);
233 curNode = curNode->next;
237 xmlXPathFreeObject(xpath_obj);
242 if (repo_mods[i] == 0) {
245 status +=
check_file(repo[i].module,
"Module");
251 if ( repo_mods[j] == 0 &&
252 (strcmp(repo[i].module, repo[j].module) == 0) ) {
255 if (strcmp(repo[i].TokenLabel, repo[j].TokenLabel) == 0) {
256 dual_log(
"ERROR: Multiple Repositories (%s and %s) in %s have the same Module (%s) and TokenLabel (%s)", repo[i].name, repo[j].name,
config, repo[i].module, repo[i].TokenLabel);
265 if (strcmp(repo[i].name, repo[j].name) == 0) {
266 dual_log(
"ERROR: Two repositories exist with the same name (%s)", repo[i].name);
275 xexpr = (xmlChar *)
"//Configuration/Common/PolicyFile";
276 xpath_obj = xmlXPathEvalExpression(xexpr, xpath_ctx);
277 if(xpath_obj == NULL) {
278 xmlXPathFreeContext(xpath_ctx);
283 free(repo[i].module);
284 free(repo[i].TokenLabel);
291 temp_char = (
char*) xmlXPathCastToString(xpath_obj);
294 xmlXPathFreeObject(xpath_obj);
299 xexpr = (xmlChar *)
"//Configuration/Common/ZoneListFile";
300 xpath_obj = xmlXPathEvalExpression(xexpr, xpath_ctx);
301 if(xpath_obj == NULL) {
302 xmlXPathFreeContext(xpath_ctx);
307 free(repo[i].module);
308 free(repo[i].TokenLabel);
315 temp_char = (
char*) xmlXPathCastToString(xpath_obj);
317 if (
check_rng(temp_char, zonerngfilename) == 0) {
318 dual_log(
"INFO: The XML in %s is valid", temp_char);
323 xmlXPathFreeObject(xpath_obj);
330 (xmlChar *)
"//Configuration/Enforcer/Privileges/User",
331 (xmlChar *)
"//Configuration/Enforcer/Privileges/Group");
336 (xmlChar *)
"//Configuration/Enforcer/Datastore/SQLite");
337 if (temp_status == -1) {
343 status += temp_status;
354 status +=
check_time_def_from_xpath(xpath_ctx, (xmlChar *)
"//Configuration/Enforcer/RolloverNotification",
"Configuration",
"Enforcer/RolloverNotification",
config);
358 (xmlChar *)
"//Configuration/Enforcer/DelegationSignerSubmitCommand");
359 if (temp_status > 0) {
360 status += temp_status;
366 (xmlChar *)
"//Configuration/Signer/Privileges/User",
367 (xmlChar *)
"//Configuration/Signer/Privileges/Group");
371 (xmlChar *)
"//Configuration/Signer/WorkingDirectory");
372 if (temp_status == -1) {
374 status +=
check_path(OPENDNSSEC_STATE_DIR
"/tmp",
"default WorkingDirectory");
376 status += temp_status;
379 xmlXPathFreeContext(xpath_ctx);
384 free(repo[i].module);
385 free(repo[i].TokenLabel);
402 const char* rngfilename = OPENDNSSEC_SCHEMA_DIR
"/kasp.rng";
404 xmlXPathContextPtr xpath_ctx;
405 xmlXPathObjectPtr xpath_obj;
409 int policy_count = 0;
410 char **policy_names = NULL;
411 int default_found = 0;
414 dual_log(
"ERROR: No location for kasp.xml set");
428 doc = xmlParseFile(
kasp);
434 xpath_ctx = xmlXPathNewContext(doc);
435 if(xpath_ctx == NULL) {
442 xexpr = (xmlChar *)
"//KASP/Policy";
443 xpath_obj = xmlXPathEvalExpression(xexpr, xpath_ctx);
444 if(xpath_obj == NULL) {
445 xmlXPathFreeContext(xpath_ctx);
450 if (xpath_obj->nodesetval) {
451 policy_count = xpath_obj->nodesetval->nodeNr;
453 policy_names = (
char**)malloc(
sizeof(
char*) * policy_count);
454 if (policy_names == NULL) {
455 dual_log(
"ERROR: Malloc for policy names failed");
459 for (i = 0; i < policy_count; i++) {
461 policy_names[i] = (
char *) xmlGetProp(xpath_obj->nodesetval->nodeTab[i],
462 (
const xmlChar *)
"name");
467 for (i = 0; i < policy_count; i++) {
468 if (strcmp(policy_names[i],
"default") == 0) {
471 for (j = i+1; j < policy_count; j++) {
472 if ( (strcmp(policy_names[i], policy_names[j]) == 0) ) {
473 dual_log(
"ERROR: Two policies exist with the same name (%s)", policy_names[i]);
478 if (default_found == 0) {
479 dual_log(
"WARNING: No policy named 'default' in %s. This means you will need to refer explicitly to the policy for each zone",
kasp);
483 for (i = 0; i < policy_count; i++) {
484 curNode = xpath_obj->nodesetval->nodeTab[i]->xmlChildrenNode;
489 for (i = 0; i < policy_count; i++) {
490 free(policy_names[i]);
494 xmlXPathFreeObject(xpath_obj);
495 xmlXPathFreeContext(xpath_ctx);
#define DEFAULT_LOG_FACILITY
int check_path(const char *pathname, const char *log_string)
int check_policy(xmlNode *curNode, const char *policy_name, char **repo_list, int repo_count, const char *kasp)
int check_conf(char **kasp)
void log_init(int facility, const char *program_name)
int check_rng(const char *filename, const char *rngfilename)
char * StrStrdup(const char *string)
int main(int argc, char *argv[])
int check_path_from_xpath(xmlXPathContextPtr xpath_ctx, const char *log_string, const xmlChar *path_xexpr)
int check_file(const char *filename, const char *log_string)
void StrAppend(char **str1, const char *str2)
void dual_log(const char *format,...)
int check_time_def_from_xpath(xmlXPathContextPtr xpath_ctx, const xmlChar *time_xexpr, const char *location, const char *field, const char *filename)
int check_user_group(xmlXPathContextPtr xpath_ctx, const xmlChar *user_xexpr, const xmlChar *group_xexpr)
int check_file_from_xpath(xmlXPathContextPtr xpath_ctx, const char *log_string, const xmlChar *file_xexpr)