41 #include <libxml/tree.h>
42 #include <libxml/parser.h>
43 #include <libxml/xpath.h>
44 #include <libxml/xpathInternals.h>
45 #include <libxml/relaxng.h>
49 char *
config = (
char *) OPENDNSSEC_CONFIG_FILE;
55 #define StrFree(ptr) {if(ptr != NULL) {free(ptr); (ptr) = NULL;}}
63 "usage: %s [options]\n\n"
65 " -c, --conf [PATH_TO_CONF_FILE] Path to OpenDNSSEC configuration file\n"
67 " -k, --kasp [PATH_TO_KASP_FILE] Path to KASP policy file\n"
68 " (defaults to the path from the conf.xml file)\n"
69 " -V, --version Display the version information\n"
70 " -v, --verbose Print extra DEBUG messages\n"
71 " -h, --help Show this message\n",
progname, OPENDNSSEC_CONFIG_FILE);
77 int main (
int argc,
char *argv[])
84 static struct option long_options[] =
86 {
"config", required_argument, 0,
'c'},
87 {
"help", no_argument, 0,
'h'},
88 {
"kasp", required_argument, 0,
'k'},
89 {
"version", no_argument, 0,
'V'},
90 {
"verbose", no_argument, 0,
'v'},
95 if ((
progname = strrchr(argv[0],
'/'))) {
102 while ((ch = getopt_long(argc, argv,
"c:hk:Vv", long_options, &option_index)) != -1) {
116 printf(
"%s version %s\n", PACKAGE_NAME, PACKAGE_VERSION);
135 dual_log(
"DEBUG: finished %d\n", status);
165 xmlXPathContextPtr xpath_ctx;
166 xmlXPathObjectPtr xpath_obj;
169 char* temp_char = NULL;
172 int* repo_mods = NULL;
174 const char* rngfilename = OPENDNSSEC_SCHEMA_DIR
"/conf.rng";
175 const char* zonerngfilename = OPENDNSSEC_SCHEMA_DIR
"/zonelist.rng";
187 doc = xmlParseFile(
config);
193 xpath_ctx = xmlXPathNewContext(doc);
194 if(xpath_ctx == NULL) {
200 xexpr = (xmlChar *)
"//Configuration/RepositoryList/Repository";
201 xpath_obj = xmlXPathEvalExpression(xexpr, xpath_ctx);
202 if(xpath_obj == NULL) {
203 xmlXPathFreeContext(xpath_ctx);
208 if (xpath_obj->nodesetval) {
212 repo_mods = (
int*)malloc(
sizeof(
int) *
repo_count);
215 if (repo == NULL || repo_mods == NULL ||
repo_list == NULL) {
216 dual_log(
"ERROR: malloc for repo information failed\n");
223 curNode = xpath_obj->nodesetval->nodeTab[i]->xmlChildrenNode;
226 repo[i].
name = (
char *) xmlGetProp(xpath_obj->nodesetval->nodeTab[i],
227 (
const xmlChar *)
"name");
231 if (xmlStrEqual(curNode->name, (
const xmlChar *)
"TokenLabel"))
232 repo[i].
TokenLabel = (
char *) xmlNodeGetContent(curNode);
233 if (xmlStrEqual(curNode->name, (
const xmlChar *)
"Module"))
234 repo[i].module = (
char *) xmlNodeGetContent(curNode);
235 curNode = curNode->next;
239 xmlXPathFreeObject(xpath_obj);
244 if (repo_mods[i] == 0) {
247 status +=
check_file(repo[i].module,
"Module");
253 if ( repo_mods[j] == 0 &&
254 (strcmp(repo[i].module, repo[j].module) == 0) ) {
257 if (strcmp(repo[i].TokenLabel, repo[j].TokenLabel) == 0) {
258 dual_log(
"ERROR: Multiple Repositories (%s and %s) in %s have the same Module (%s) and TokenLabel (%s)\n", repo[i].name, repo[j].name,
config, repo[i].module, repo[i].TokenLabel);
267 if (strcmp(repo[i].name, repo[j].name) == 0) {
268 dual_log(
"ERROR: Two repositories exist with the same name (%s)\n", repo[i].name);
277 xexpr = (xmlChar *)
"//Configuration/Common/PolicyFile";
278 xpath_obj = xmlXPathEvalExpression(xexpr, xpath_ctx);
279 if(xpath_obj == NULL) {
280 xmlXPathFreeContext(xpath_ctx);
285 free(repo[i].module);
286 free(repo[i].TokenLabel);
293 temp_char = (
char*) xmlXPathCastToString(xpath_obj);
296 xmlXPathFreeObject(xpath_obj);
301 xexpr = (xmlChar *)
"//Configuration/Common/ZoneListFile";
302 xpath_obj = xmlXPathEvalExpression(xexpr, xpath_ctx);
303 if(xpath_obj == NULL) {
304 xmlXPathFreeContext(xpath_ctx);
309 free(repo[i].module);
310 free(repo[i].TokenLabel);
317 temp_char = (
char*) xmlXPathCastToString(xpath_obj);
319 if (
check_rng(temp_char, zonerngfilename) == 0) {
320 dual_log(
"INFO: The XML in %s is valid\n", temp_char);
325 xmlXPathFreeObject(xpath_obj);
332 (xmlChar *)
"//Configuration/Enforcer/Privileges/User",
333 (xmlChar *)
"//Configuration/Enforcer/Privileges/Group");
338 (xmlChar *)
"//Configuration/Enforcer/Datastore/SQLite");
339 if (temp_status == -1) {
345 status += temp_status;
356 status +=
check_time_def_from_xpath(xpath_ctx, (xmlChar *)
"//Configuration/Enforcer/RolloverNotification",
"Configuration",
"Enforcer/RolloverNotification",
config);
360 (xmlChar *)
"//Configuration/Enforcer/DelegationSignerSubmitCommand");
361 if (temp_status > 0) {
362 status += temp_status;
368 (xmlChar *)
"//Configuration/Signer/Privileges/User",
369 (xmlChar *)
"//Configuration/Signer/Privileges/Group");
373 (xmlChar *)
"//Configuration/Signer/WorkingDirectory");
374 if (temp_status == -1) {
376 check_path(OPENDNSSEC_STATE_DIR
"/tmp",
"default WorkingDirectory");
378 status += temp_status;
381 xmlXPathFreeContext(xpath_ctx);
386 free(repo[i].module);
387 free(repo[i].TokenLabel);
404 const char* rngfilename = OPENDNSSEC_SCHEMA_DIR
"/kasp.rng";
406 xmlXPathContextPtr xpath_ctx;
407 xmlXPathObjectPtr xpath_obj;
411 int policy_count = 0;
412 char **policy_names = NULL;
413 int default_found = 0;
416 dual_log(
"ERROR: No location for kasp.xml set\n");
430 doc = xmlParseFile(
kasp);
436 xpath_ctx = xmlXPathNewContext(doc);
437 if(xpath_ctx == NULL) {
444 xexpr = (xmlChar *)
"//KASP/Policy";
445 xpath_obj = xmlXPathEvalExpression(xexpr, xpath_ctx);
446 if(xpath_obj == NULL) {
447 xmlXPathFreeContext(xpath_ctx);
452 if (xpath_obj->nodesetval) {
453 policy_count = xpath_obj->nodesetval->nodeNr;
455 policy_names = (
char**)malloc(
sizeof(
char*) * policy_count);
456 if (policy_names == NULL) {
457 dual_log(
"ERROR: Malloc for policy names failed\n");
461 for (i = 0; i < policy_count; i++) {
463 policy_names[i] = (
char *) xmlGetProp(xpath_obj->nodesetval->nodeTab[i],
464 (
const xmlChar *)
"name");
469 for (i = 0; i < policy_count; i++) {
470 if (strcmp(policy_names[i],
"default") == 0) {
473 for (j = i+1; j < policy_count; j++) {
474 if ( (strcmp(policy_names[i], policy_names[j]) == 0) ) {
475 dual_log(
"ERROR: Two policies exist with the same name (%s)\n", policy_names[i]);
480 if (default_found == 0) {
481 dual_log(
"WARNING: No policy named 'default' in %s. This means you will need to refer explicitly to the policy for each zone\n",
kasp);
485 for (i = 0; i < policy_count; i++) {
486 curNode = xpath_obj->nodesetval->nodeTab[i]->xmlChildrenNode;
491 for (i = 0; i < policy_count; i++) {
492 free(policy_names[i]);
496 xmlXPathFreeObject(xpath_obj);
497 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)