OpenDNSSEC-enforcer 2.1.13
kaspcheck.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2012 Nominet UK. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
19 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
21 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
22 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
23 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#define _GNU_SOURCE
27#include <stdio.h>
28#include <getopt.h>
29#include <string.h>
30#include <syslog.h>
31
32#include "config.h"
33
34#include "kc_helper.h"
35
36#include <libxml/parser.h>
37
38const char *progname = NULL;
39
40/*
41 * Display usage
42 */
43static void usage()
44{
45 fprintf(stderr,
46 "usage: %s [options]\n\n"
47 "Options:\n"
48 " -c, --conf [PATH_TO_CONF_FILE] Path to OpenDNSSEC configuration file\n"
49 " (defaults to %s)\n"
50 " -k, --kasp [PATH_TO_KASP_FILE] Path to KASP policy file\n"
51 " (defaults to the path from the conf.xml file)\n",
52 progname, OPENDNSSEC_CONFIG_FILE);
53 fprintf(stderr,
54 " -z, --zonelist [PATH_TO_ZONELIST_FILE] Path to zonelist file\n"
55 " (defaults to the path from the conf.xml file)\n"
56 " -V, --version Display the version information\n"
57 " -v, --verbose Print extra DEBUG messages\n"
58 " -h, --help Show this message\n");
59}
60
61/*
62 * Fairly basic main.
63 */
64int main (int argc, char *argv[])
65{
66 extern int kc_helper_printto_stdout;
67 char *conffile = NULL, *kaspfile = NULL, *zonelistfile = NULL;
68 int status = 0; /* Will be non-zero on error (NOT warning) */
69 char **repo_list = NULL;
70 int repo_count = 0;
71 int ch, i, verbose = 0, option_index = 0;
72 static struct option long_options[] =
73 {
74 {"config", required_argument, 0, 'c'},
75 {"help", no_argument, 0, 'h'},
76 {"kasp", required_argument, 0, 'k'},
77 {"zonelist", required_argument, 0, 'z'},
78 {"version", no_argument, 0, 'V'},
79 {"verbose", no_argument, 0, 'v'},
80 {0,0,0,0}
81 };
82 char **policy_names = NULL;
83 int policy_count = 0;
84
85 /* The program name is the last component of the program file name */
86 if ((progname = strrchr(argv[0], '/'))) { /* EQUALS */
87 ++progname; /* Point to character after last "/" */
88 } else {
89 progname = argv[0];
90 }
91
92 while ((ch = getopt_long(argc, argv, "c:hk:Vvz:", long_options, &option_index)) != -1)
93 {
94 switch (ch)
95 {
96 case 'c':
97 conffile = StrStrdup(optarg);
98 break;
99 case 'h':
100 usage();
101 exit(0);
102 break;
103 case 'k':
104 kaspfile = StrStrdup(optarg);
105 break;
106 case 'z':
107 zonelistfile = StrStrdup(optarg);
108 break;
109 case 'V':
110 printf("%s version %s\n", PACKAGE_NAME, PACKAGE_VERSION);
111 exit(0);
112 break;
113 case 'v':
114 verbose = 1;
115 break;
116 }
117 }
118
120
121 if (!conffile)
122 conffile = StrStrdup((char *)OPENDNSSEC_CONFIG_FILE);
123
124 /* 0) Some basic setup */
126 /* 1) Check on conf.xml - set kasp.xml (if -k flag not given) */
127 status = check_conf(conffile, &kaspfile, &zonelistfile, &repo_list,
128 &repo_count, verbose);
129 /* 2) Checks on kasp.xml */
130 status += check_kasp(kaspfile, repo_list, repo_count, verbose,
131 &policy_names, &policy_count);
132 /* 3) Checks on zonelist.xml */
133 status += check_zonelist(zonelistfile, verbose, policy_names, policy_count);
134
135 for (i = 0; i < policy_count; i++) {
136 free(policy_names[i]);
137 }
138 free(policy_names);
139
140 xmlCleanupParser();
141 for (i = 0; i < repo_count; i++)
142 free(repo_list[i]);
143 free(repo_list);
144 free(conffile);
145 free(kaspfile);
146 free(zonelistfile);
147
148 if (verbose)
149 dual_log("DEBUG: finished %d", status);
150 return status;
151}
const char * progname
Definition kaspcheck.c:38
void log_init(int facility, const char *program_name)
Definition kc_helper.c:51
int check_kasp(const char *kasp, char **repo_list, int repo_count, int verbose, char ***policy_names_out, int *policy_count_out)
Definition kc_helper.c:1772
char * StrStrdup(const char *string)
Definition kc_helper.c:1289
void dual_log(const char *format,...)
Definition kc_helper.c:59
int kc_helper_printto_stdout
Definition kc_helper.c:49
int check_zonelist(const char *zonelist, int verbose, char **policy_names, int policy_count)
Definition kc_helper.c:1696
int check_conf(const char *conf, char **kasp, char **zonelist, char ***repo_listout, int *repo_countout, int verbose)
Definition kc_helper.c:1418
#define DEFAULT_LOG_FACILITY
Definition kc_helper.h:33
int main(void)
Definition test.c:43