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#ifdef HAVE_STDLIB_H
35#include <stdlib.h>
36#endif
37
38#include "kc_helper.h"
39
40#include <libxml/parser.h>
41
42const char *progname = NULL;
43
44/*
45 * Display usage
46 */
47static void usage()
48{
49 fprintf(stderr,
50 "usage: %s [options]\n\n"
51 "Options:\n"
52 " -c, --conf [PATH_TO_CONF_FILE] Path to OpenDNSSEC configuration file\n"
53 " (defaults to %s)\n"
54 " -k, --kasp [PATH_TO_KASP_FILE] Path to KASP policy file\n"
55 " (defaults to the path from the conf.xml file)\n",
56 progname, OPENDNSSEC_CONFIG_FILE);
57 fprintf(stderr,
58 " -z, --zonelist [PATH_TO_ZONELIST_FILE] Path to zonelist file\n"
59 " (defaults to the path from the conf.xml file)\n"
60 " -V, --version Display the version information\n"
61 " -v, --verbose Print extra DEBUG messages\n"
62 " -h, --help Show this message\n");
63}
64
65/*
66 * Fairly basic main.
67 */
68int main (int argc, char *argv[])
69{
70 extern int kc_helper_printto_stdout;
71 char *conffile = NULL, *kaspfile = NULL, *zonelistfile = NULL;
72 int status = 0; /* Will be non-zero on error (NOT warning) */
73 char **repo_list = NULL;
74 int repo_count = 0;
75 int ch, i, verbose = 0, option_index = 0;
76 static struct option long_options[] =
77 {
78 {"config", required_argument, 0, 'c'},
79 {"help", no_argument, 0, 'h'},
80 {"kasp", required_argument, 0, 'k'},
81 {"zonelist", required_argument, 0, 'z'},
82 {"version", no_argument, 0, 'V'},
83 {"verbose", no_argument, 0, 'v'},
84 {0,0,0,0}
85 };
86 char **policy_names = NULL;
87 int policy_count = 0;
88
89 /* The program name is the last component of the program file name */
90 if ((progname = strrchr(argv[0], '/'))) { /* EQUALS */
91 ++progname; /* Point to character after last "/" */
92 } else {
93 progname = argv[0];
94 }
95
96 while ((ch = getopt_long(argc, argv, "c:hk:Vvz:", long_options, &option_index)) != -1)
97 {
98 switch (ch)
99 {
100 case 'c':
101 conffile = StrStrdup(optarg);
102 break;
103 case 'h':
104 usage();
105 exit(0);
106 break;
107 case 'k':
108 kaspfile = StrStrdup(optarg);
109 break;
110 case 'z':
111 zonelistfile = StrStrdup(optarg);
112 break;
113 case 'V':
114 printf("%s version %s\n", PACKAGE_NAME, PACKAGE_VERSION);
115 exit(0);
116 break;
117 case 'v':
118 verbose = 1;
119 break;
120 }
121 }
122
124
125 if (!conffile)
126 conffile = StrStrdup((char *)OPENDNSSEC_CONFIG_FILE);
127
128 /* 0) Some basic setup */
130 /* 1) Check on conf.xml - set kasp.xml (if -k flag not given) */
131 status = check_conf(conffile, &kaspfile, &zonelistfile, &repo_list,
132 &repo_count, verbose);
133 /* 2) Checks on kasp.xml */
134 status += check_kasp(kaspfile, repo_list, repo_count, verbose,
135 &policy_names, &policy_count);
136 /* 3) Checks on zonelist.xml */
137 status += check_zonelist(zonelistfile, verbose, policy_names, policy_count);
138
139 for (i = 0; i < policy_count; i++) {
140 free(policy_names[i]);
141 }
142 free(policy_names);
143
144 xmlCleanupParser();
145 for (i = 0; i < repo_count; i++)
146 free(repo_list[i]);
147 free(repo_list);
148 free(conffile);
149 free(kaspfile);
150 free(zonelistfile);
151
152 if (verbose)
153 dual_log("DEBUG: finished %d", status);
154 return status;
155}
const char * progname
Definition kaspcheck.c:42
void log_init(int facility, const char *program_name)
Definition kc_helper.c:55
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:1776
char * StrStrdup(const char *string)
Definition kc_helper.c:1293
void dual_log(const char *format,...)
Definition kc_helper.c:63
int kc_helper_printto_stdout
Definition kc_helper.c:53
int check_zonelist(const char *zonelist, int verbose, char **policy_names, int policy_count)
Definition kc_helper.c:1700
int check_conf(const char *conf, char **kasp, char **zonelist, char ***repo_listout, int *repo_countout, int verbose)
Definition kc_helper.c:1422
#define DEFAULT_LOG_FACILITY
Definition kc_helper.h:33
int main(void)
Definition test.c:43