Add BIND 9.2.4rc7.
[dragonfly.git] / contrib / bind-9.2.4rc7 / bin / check / named-checkconf.c
blob83d3cd9441807a2f233523aa4418c87150f66548
1 /*
2 * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-2001 Internet Software Consortium.
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
18 /* $Id: named-checkconf.c,v 1.12.2.1 2004/03/09 06:09:09 marka Exp $ */
20 #include <config.h>
22 #include <errno.h>
23 #include <stdlib.h>
24 #include <stdio.h>
26 #include <isc/commandline.h>
27 #include <isc/dir.h>
28 #include <isc/log.h>
29 #include <isc/mem.h>
30 #include <isc/result.h>
31 #include <isc/string.h>
32 #include <isc/util.h>
34 #include <isccfg/cfg.h>
35 #include <isccfg/check.h>
37 #include "check-tool.h"
39 isc_log_t *logc = NULL;
41 static void
42 usage(void) {
43 fprintf(stderr, "usage: named-checkconf [-v] [-t directory] [named.conf]\n");
44 exit(1);
47 static isc_result_t
48 directory_callback(const char *clausename, cfg_obj_t *obj, void *arg) {
49 isc_result_t result;
50 char *directory;
52 REQUIRE(strcasecmp("directory", clausename) == 0);
54 UNUSED(arg);
55 UNUSED(clausename);
58 * Change directory.
60 directory = cfg_obj_asstring(obj);
61 result = isc_dir_chdir(directory);
62 if (result != ISC_R_SUCCESS) {
63 cfg_obj_log(obj, logc, ISC_LOG_ERROR,
64 "change directory to '%s' failed: %s",
65 directory, isc_result_totext(result));
66 return (result);
69 return (ISC_R_SUCCESS);
72 int
73 main(int argc, char **argv) {
74 int c;
75 cfg_parser_t *parser = NULL;
76 cfg_obj_t *config = NULL;
77 const char *conffile = NULL;
78 isc_mem_t *mctx = NULL;
79 isc_result_t result;
80 int exit_status = 0;
82 while ((c = isc_commandline_parse(argc, argv, "t:v")) != EOF) {
83 switch (c) {
84 case 't':
85 result = isc_dir_chroot(isc_commandline_argument);
86 if (result != ISC_R_SUCCESS) {
87 fprintf(stderr, "isc_dir_chroot: %s\n",
88 isc_result_totext(result));
89 exit(1);
91 result = isc_dir_chdir("/");
92 if (result != ISC_R_SUCCESS) {
93 fprintf(stderr, "isc_dir_chdir: %s\n",
94 isc_result_totext(result));
95 exit(1);
97 break;
99 case 'v':
100 printf(VERSION "\n");
101 exit(0);
103 default:
104 usage();
108 if (argv[isc_commandline_index] != NULL)
109 conffile = argv[isc_commandline_index];
110 if (conffile == NULL || conffile[0] == '\0')
111 conffile = NAMED_CONFFILE;
113 RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
115 RUNTIME_CHECK(setup_logging(mctx, &logc) == ISC_R_SUCCESS);
117 RUNTIME_CHECK(cfg_parser_create(mctx, logc, &parser) == ISC_R_SUCCESS);
119 cfg_parser_setcallback(parser, directory_callback, NULL);
121 if (cfg_parse_file(parser, conffile, &cfg_type_namedconf, &config) !=
122 ISC_R_SUCCESS)
123 exit(1);
125 result = cfg_check_namedconf(config, logc, mctx);
126 if (result != ISC_R_SUCCESS)
127 exit_status = 1;
129 cfg_obj_destroy(parser, &config);
131 cfg_parser_destroy(&parser);
133 isc_log_destroy(&logc);
135 isc_mem_destroy(&mctx);
137 return (exit_status);