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 $ */
26 #include <isc/commandline.h>
30 #include <isc/result.h>
31 #include <isc/string.h>
34 #include <isccfg/cfg.h>
35 #include <isccfg/check.h>
37 #include "check-tool.h"
39 isc_log_t
*logc
= NULL
;
43 fprintf(stderr
, "usage: named-checkconf [-v] [-t directory] [named.conf]\n");
48 directory_callback(const char *clausename
, cfg_obj_t
*obj
, void *arg
) {
52 REQUIRE(strcasecmp("directory", clausename
) == 0);
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
));
69 return (ISC_R_SUCCESS
);
73 main(int argc
, char **argv
) {
75 cfg_parser_t
*parser
= NULL
;
76 cfg_obj_t
*config
= NULL
;
77 const char *conffile
= NULL
;
78 isc_mem_t
*mctx
= NULL
;
82 while ((c
= isc_commandline_parse(argc
, argv
, "t:v")) != EOF
) {
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
));
91 result
= isc_dir_chdir("/");
92 if (result
!= ISC_R_SUCCESS
) {
93 fprintf(stderr
, "isc_dir_chdir: %s\n",
94 isc_result_totext(result
));
100 printf(VERSION
"\n");
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
) !=
125 result
= cfg_check_namedconf(config
, logc
, mctx
);
126 if (result
!= ISC_R_SUCCESS
)
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
);