2000-12-14 21:33:11 +00:00
|
|
|
/*
|
2001-01-09 22:01:04 +00:00
|
|
|
* Copyright (C) 1999-2001 Internet Software Consortium.
|
2000-12-14 21:33:11 +00:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
|
|
|
|
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
|
|
|
* INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
|
|
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
|
|
|
|
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
|
|
|
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2001-09-17 02:59:01 +00:00
|
|
|
/* $Id: named-checkconf.c,v 1.15 2001/09/17 02:59:01 marka Exp $ */
|
2000-12-14 21:33:11 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdlib.h>
|
2001-01-29 03:23:13 +00:00
|
|
|
#include <stdio.h>
|
2000-12-14 21:33:11 +00:00
|
|
|
|
2001-01-29 03:23:13 +00:00
|
|
|
#include <isc/commandline.h>
|
|
|
|
#include <isc/dir.h>
|
2001-03-03 23:11:36 +00:00
|
|
|
#include <isc/log.h>
|
2000-12-14 21:33:11 +00:00
|
|
|
#include <isc/mem.h>
|
2001-01-29 03:23:13 +00:00
|
|
|
#include <isc/result.h>
|
2000-12-14 21:33:11 +00:00
|
|
|
#include <isc/string.h>
|
|
|
|
#include <isc/util.h>
|
|
|
|
|
2001-03-03 23:11:36 +00:00
|
|
|
#include <isccfg/cfg.h>
|
|
|
|
#include <isccfg/check.h>
|
2000-12-14 21:33:11 +00:00
|
|
|
|
2001-09-04 00:32:32 +00:00
|
|
|
#include <dns/log.h>
|
2001-09-17 00:23:10 +00:00
|
|
|
#include <dns/result.h>
|
2001-09-04 00:32:32 +00:00
|
|
|
|
2000-12-14 21:33:11 +00:00
|
|
|
#include "check-tool.h"
|
|
|
|
|
2001-07-27 04:59:01 +00:00
|
|
|
isc_log_t *logc = NULL;
|
2001-03-03 23:11:36 +00:00
|
|
|
|
2001-09-04 00:32:32 +00:00
|
|
|
#define CHECK(r)\
|
|
|
|
do { \
|
|
|
|
result = (r); \
|
|
|
|
if (result != ISC_R_SUCCESS) \
|
|
|
|
goto cleanup; \
|
|
|
|
} while (0)
|
|
|
|
|
2001-01-29 03:23:13 +00:00
|
|
|
static void
|
|
|
|
usage(void) {
|
2001-09-17 00:23:10 +00:00
|
|
|
fprintf(stderr, "usage: named-checkconf [-v] [-z] [-t directory] [named.conf]\n");
|
2001-01-29 03:23:13 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2000-12-14 21:33:11 +00:00
|
|
|
static isc_result_t
|
2001-03-03 23:11:36 +00:00
|
|
|
directory_callback(const char *clausename, cfg_obj_t *obj, void *arg) {
|
|
|
|
isc_result_t result;
|
|
|
|
char *directory;
|
|
|
|
|
|
|
|
REQUIRE(strcasecmp("directory", clausename) == 0);
|
|
|
|
|
|
|
|
UNUSED(arg);
|
2001-03-16 23:00:00 +00:00
|
|
|
UNUSED(clausename);
|
2001-03-03 23:11:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Change directory.
|
|
|
|
*/
|
|
|
|
directory = cfg_obj_asstring(obj);
|
|
|
|
result = isc_dir_chdir(directory);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2001-07-27 04:59:01 +00:00
|
|
|
cfg_obj_log(obj, logc, ISC_LOG_ERROR,
|
2001-09-17 00:23:10 +00:00
|
|
|
"change directory to '%s' failed: %s\n",
|
2001-03-03 23:11:36 +00:00
|
|
|
directory, isc_result_totext(result));
|
|
|
|
return (result);
|
|
|
|
}
|
2000-12-14 21:33:11 +00:00
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2001-09-04 00:32:32 +00:00
|
|
|
static isc_result_t
|
2001-09-17 00:23:10 +00:00
|
|
|
configure_zone(const char *vclass, const char *view, cfg_obj_t *zconfig,
|
|
|
|
isc_mem_t *mctx)
|
|
|
|
{
|
|
|
|
isc_result_t result;
|
2001-09-04 00:32:32 +00:00
|
|
|
const char *zclass;
|
|
|
|
const char *zname;
|
|
|
|
const char *zfile;
|
|
|
|
cfg_obj_t *zoptions = NULL;
|
|
|
|
cfg_obj_t *classobj = NULL;
|
|
|
|
cfg_obj_t *typeobj = NULL;
|
|
|
|
cfg_obj_t *fileobj = NULL;
|
|
|
|
cfg_obj_t *dbobj = NULL;
|
|
|
|
|
|
|
|
zname = cfg_obj_asstring(cfg_tuple_get(zconfig, "name"));
|
|
|
|
classobj = cfg_tuple_get(zconfig, "class");
|
|
|
|
if (!cfg_obj_isstring(classobj))
|
|
|
|
zclass = vclass;
|
|
|
|
else
|
|
|
|
zclass = cfg_obj_asstring(classobj);
|
|
|
|
zoptions = cfg_tuple_get(zconfig, "options");
|
|
|
|
cfg_map_get(zoptions, "type", &typeobj);
|
|
|
|
if (typeobj == NULL)
|
|
|
|
return (ISC_R_FAILURE);
|
|
|
|
if (strcasecmp(cfg_obj_asstring(typeobj), "master") != 0)
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
cfg_map_get(zoptions, "database", &dbobj);
|
|
|
|
if (dbobj != NULL)
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
cfg_map_get(zoptions, "file", &fileobj);
|
|
|
|
if (fileobj == NULL)
|
|
|
|
return (ISC_R_FAILURE);
|
|
|
|
zfile = cfg_obj_asstring(fileobj);
|
2001-09-17 00:23:10 +00:00
|
|
|
result = load_zone(mctx, zname, zfile, zclass, NULL);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
fprintf(stderr, "%s/%s/%s: %s\n", view, zname, zclass,
|
|
|
|
dns_result_totext(result));
|
|
|
|
return(result);
|
2001-09-04 00:32:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
2001-09-17 00:23:10 +00:00
|
|
|
configure_view(const char *vclass, const char *view, cfg_obj_t *config,
|
|
|
|
cfg_obj_t *vconfig, isc_mem_t *mctx)
|
2001-09-04 00:32:32 +00:00
|
|
|
{
|
|
|
|
cfg_listelt_t *element;
|
|
|
|
cfg_obj_t *voptions;
|
|
|
|
cfg_obj_t *zonelist;
|
|
|
|
isc_result_t result = ISC_R_SUCCESS;
|
|
|
|
|
|
|
|
voptions = NULL;
|
|
|
|
if (vconfig != NULL)
|
|
|
|
voptions = cfg_tuple_get(vconfig, "options");
|
|
|
|
|
|
|
|
zonelist = NULL;
|
|
|
|
if (voptions != NULL)
|
|
|
|
(void)cfg_map_get(voptions, "zone", &zonelist);
|
|
|
|
else
|
|
|
|
(void)cfg_map_get(config, "zone", &zonelist);
|
|
|
|
|
|
|
|
for (element = cfg_list_first(zonelist);
|
|
|
|
element != NULL;
|
|
|
|
element = cfg_list_next(element))
|
|
|
|
{
|
|
|
|
cfg_obj_t *zconfig = cfg_listelt_value(element);
|
2001-09-17 00:23:10 +00:00
|
|
|
CHECK(configure_zone(vclass, view, zconfig, mctx));
|
2001-09-04 00:32:32 +00:00
|
|
|
}
|
|
|
|
cleanup:
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static isc_result_t
|
|
|
|
load_zones_fromconfig(cfg_obj_t *config, isc_mem_t *mctx) {
|
|
|
|
cfg_listelt_t *element;
|
|
|
|
cfg_obj_t *classobj;
|
|
|
|
cfg_obj_t *views;
|
|
|
|
cfg_obj_t *vconfig;
|
|
|
|
const char *vclass;
|
|
|
|
isc_result_t result = ISC_R_SUCCESS;
|
|
|
|
|
|
|
|
views = NULL;
|
|
|
|
|
|
|
|
(void)cfg_map_get(config, "view", &views);
|
|
|
|
for (element = cfg_list_first(views);
|
|
|
|
element != NULL;
|
|
|
|
element = cfg_list_next(element))
|
|
|
|
{
|
2001-09-17 00:23:10 +00:00
|
|
|
const char *vname;
|
2001-09-04 00:32:32 +00:00
|
|
|
|
|
|
|
vclass = "IN";
|
|
|
|
vconfig = cfg_listelt_value(element);
|
|
|
|
if (vconfig != NULL) {
|
|
|
|
classobj = cfg_tuple_get(vconfig, "class");
|
|
|
|
if (cfg_obj_isstring(classobj))
|
|
|
|
vclass = cfg_obj_asstring(classobj);
|
|
|
|
}
|
2001-09-17 00:23:10 +00:00
|
|
|
vname = cfg_obj_asstring(cfg_tuple_get(vconfig, "name"));
|
|
|
|
CHECK(configure_view(vclass, vname, config, vconfig, mctx));
|
2001-09-04 00:32:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (views == NULL)
|
2001-09-17 00:23:10 +00:00
|
|
|
CHECK(configure_view("IN", "_default", config, NULL, mctx));
|
2001-09-04 00:32:32 +00:00
|
|
|
cleanup:
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
2000-12-14 21:33:11 +00:00
|
|
|
int
|
2000-12-19 19:53:58 +00:00
|
|
|
main(int argc, char **argv) {
|
2001-01-29 03:23:13 +00:00
|
|
|
int c;
|
2001-03-03 23:11:36 +00:00
|
|
|
cfg_parser_t *parser = NULL;
|
|
|
|
cfg_obj_t *config = NULL;
|
2000-12-14 21:33:11 +00:00
|
|
|
const char *conffile = NULL;
|
|
|
|
isc_mem_t *mctx = NULL;
|
2001-01-29 03:23:13 +00:00
|
|
|
isc_result_t result;
|
2001-07-16 17:53:22 +00:00
|
|
|
int exit_status = 0;
|
2001-09-04 00:32:32 +00:00
|
|
|
isc_boolean_t load_zones = ISC_FALSE;
|
2000-12-14 21:33:11 +00:00
|
|
|
|
2001-09-04 00:32:32 +00:00
|
|
|
while ((c = isc_commandline_parse(argc, argv, "dt:vz")) != EOF) {
|
2001-01-29 03:23:13 +00:00
|
|
|
switch (c) {
|
2001-09-04 00:32:32 +00:00
|
|
|
case 'd':
|
|
|
|
debug++;
|
|
|
|
break;
|
|
|
|
|
2001-01-29 03:23:13 +00:00
|
|
|
case 't':
|
|
|
|
result = isc_dir_chroot(isc_commandline_argument);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
fprintf(stderr, "isc_dir_chroot: %s\n",
|
|
|
|
isc_result_totext(result));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
result = isc_dir_chdir("/");
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
fprintf(stderr, "isc_dir_chdir: %s\n",
|
|
|
|
isc_result_totext(result));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2001-06-29 01:05:11 +00:00
|
|
|
case 'v':
|
|
|
|
printf(VERSION "\n");
|
|
|
|
exit(0);
|
|
|
|
|
2001-09-04 00:32:32 +00:00
|
|
|
case 'z':
|
|
|
|
load_zones = ISC_TRUE;
|
|
|
|
break;
|
|
|
|
|
2001-01-29 03:23:13 +00:00
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argv[isc_commandline_index] != NULL)
|
|
|
|
conffile = argv[isc_commandline_index];
|
2000-12-14 21:33:11 +00:00
|
|
|
if (conffile == NULL || conffile[0] == '\0')
|
2001-07-27 17:45:29 +00:00
|
|
|
conffile = NAMED_CONFFILE;
|
2000-12-14 21:33:11 +00:00
|
|
|
|
|
|
|
RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
|
|
|
|
|
2001-07-27 04:59:01 +00:00
|
|
|
RUNTIME_CHECK(setup_logging(mctx, &logc) == ISC_R_SUCCESS);
|
2000-12-14 21:33:11 +00:00
|
|
|
|
2001-07-27 04:59:01 +00:00
|
|
|
RUNTIME_CHECK(cfg_parser_create(mctx, logc, &parser) == ISC_R_SUCCESS);
|
2001-03-03 23:11:36 +00:00
|
|
|
|
|
|
|
cfg_parser_setcallback(parser, directory_callback, NULL);
|
|
|
|
|
|
|
|
if (cfg_parse_file(parser, conffile, &cfg_type_namedconf, &config) !=
|
|
|
|
ISC_R_SUCCESS)
|
2000-12-14 21:33:11 +00:00
|
|
|
exit(1);
|
|
|
|
|
2001-07-27 04:59:01 +00:00
|
|
|
result = cfg_check_namedconf(config, logc, mctx);
|
2001-07-16 17:53:22 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
exit_status = 1;
|
2001-03-03 23:11:36 +00:00
|
|
|
|
2001-09-17 00:23:10 +00:00
|
|
|
if (result == ISC_R_SUCCESS && load_zones) {
|
2001-09-04 00:32:32 +00:00
|
|
|
dns_log_init(logc);
|
|
|
|
dns_log_setcontext(logc);
|
|
|
|
result = load_zones_fromconfig(config, mctx);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
exit_status = 1;
|
|
|
|
}
|
|
|
|
|
2001-03-03 23:11:36 +00:00
|
|
|
cfg_obj_destroy(parser, &config);
|
|
|
|
|
|
|
|
cfg_parser_destroy(&parser);
|
2000-12-14 21:33:11 +00:00
|
|
|
|
2001-07-27 04:59:01 +00:00
|
|
|
isc_log_destroy(&logc);
|
2000-12-14 21:33:11 +00:00
|
|
|
|
|
|
|
isc_mem_destroy(&mctx);
|
|
|
|
|
2001-07-16 17:53:22 +00:00
|
|
|
return (exit_status);
|
2000-12-14 21:33:11 +00:00
|
|
|
}
|