named-checkconf.c revision c4abb197160a74f7cd4ad23ebc63fbe0194010ab
a7038d1a0513c8e804937ebc95fc9cb3a46c04f5Mark Andrews * Copyright (C) 2004-2007, 2009-2014 Internet Systems Consortium, Inc. ("ISC")
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Copyright (C) 1999-2002 Internet Software Consortium.
bf43fdafa3bff9e84cb03f1a19aca74514d2516eBob Halley * Permission to use, copy, modify, and/or distribute this software for any
bf43fdafa3bff9e84cb03f1a19aca74514d2516eBob Halley * purpose with or without fee is hereby granted, provided that the above
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * copyright notice and this permission notice appear in all copies.
15a44745412679c30a6d022733925af70a38b715David Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
15a44745412679c30a6d022733925af70a38b715David Lawrence * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15a44745412679c30a6d022733925af70a38b715David Lawrence * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
15a44745412679c30a6d022733925af70a38b715David Lawrence * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15a44745412679c30a6d022733925af70a38b715David Lawrence * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15a44745412679c30a6d022733925af70a38b715David Lawrence * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15a44745412679c30a6d022733925af70a38b715David Lawrence * PERFORMANCE OF THIS SOFTWARE.
93d6dfaf66258337985427c86181f01fc51f0bb4Mark Andrews/* $Id: named-checkconf.c,v 1.56 2011/03/12 04:59:46 tbox Exp $ */
ed019cabc1cc75d4412010c331876e4ae5080a4dDavid Lawrence fprintf(stderr, "usage: %s [-h] [-j] [-p [-x]] [-v] [-z] [-t directory] "
23e4260821eefa5019808e18e14e2b366461aad7Brian Wellington/*% directory callback */
23e4260821eefa5019808e18e14e2b366461aad7Brian Wellingtondirectory_callback(const char *clausename, const cfg_obj_t *obj, void *arg) {
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson REQUIRE(strcasecmp("directory", clausename) == 0);
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews * Change directory.
9cd6710f91bdffef5aed68ab02533e398f6134d7Brian Wellington "change directory to '%s' failed: %s\n",
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graffget_maps(const cfg_obj_t **maps, const char *name, const cfg_obj_t **obj) {
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff for (i = 0;; i++) {
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley if (cfg_map_get(maps[i], name, obj) == ISC_R_SUCCESS)
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrewsget_checknames(const cfg_obj_t **maps, const cfg_obj_t **obj) {
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews for (i = 0;; i++) {
98d010a24a9f1b4b45ce9791845941ef90426d0cBrian Wellington result = cfg_map_get(maps[i], "check-names", &checknames);
98d010a24a9f1b4b45ce9791845941ef90426d0cBrian Wellington if (checknames != NULL && !cfg_obj_islist(checknames)) {
98d010a24a9f1b4b45ce9791845941ef90426d0cBrian Wellington if (strcasecmp(cfg_obj_asstring(type), "master") != 0)
ff30cdeb783ca7ffe69b222c56197828e882c229Mark Andrewsconfigure_hint(const char *zfile, const char *zclass, isc_mem_t *mctx) {
ff30cdeb783ca7ffe69b222c56197828e882c229Mark Andrews result = dns_rdataclass_fromtext(&rdclass, &r);
ff30cdeb783ca7ffe69b222c56197828e882c229Mark Andrews result = dns_rootns_create(mctx, rdclass, zfile, &db);
ff30cdeb783ca7ffe69b222c56197828e882c229Mark Andrews/*% configure the zone */
ff30cdeb783ca7ffe69b222c56197828e882c229Mark Andrewsconfigure_zone(const char *vclass, const char *view,
ff30cdeb783ca7ffe69b222c56197828e882c229Mark Andrews const cfg_obj_t *zconfig, const cfg_obj_t *vconfig,
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington zone_options = DNS_ZONEOPT_CHECKNS | DNS_ZONEOPT_MANYERRORS;
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington zname = cfg_obj_asstring(cfg_tuple_get(zconfig, "name"));
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington classobj = cfg_tuple_get(zconfig, "class");
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington zoptions = cfg_tuple_get(zconfig, "options");
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington maps[i++] = cfg_tuple_get(vconfig, "options");
1b1e1fda4638334b484aa38c15f53a131c0b0fdfAndreas Gustafsson * Skip checks when using an alternate data source.
8839b6acbf816fedc15b8e9e1c71fd606a9cd8eaBrian Wellington strcmp("rbt", cfg_obj_asstring(dbobj)) != 0 &&
8839b6acbf816fedc15b8e9e1c71fd606a9cd8eaBrian Wellington strcmp("rbt64", cfg_obj_asstring(dbobj)) != 0)
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews * Check hints files for hint zones.
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews * Skip loading checks for any type other than
48ed268b3378a8b729a0037bc4ae2ed73647a96aBrian Wellington * master and redirect
48ed268b3378a8b729a0037bc4ae2ed73647a96aBrian Wellington if (strcasecmp(cfg_obj_asstring(typeobj), "hint") == 0)
48ed268b3378a8b729a0037bc4ae2ed73647a96aBrian Wellington return (configure_hint(zfile, zclass, mctx));
48ed268b3378a8b729a0037bc4ae2ed73647a96aBrian Wellington else if ((strcasecmp(cfg_obj_asstring(typeobj), "master") != 0) &&
48ed268b3378a8b729a0037bc4ae2ed73647a96aBrian Wellington (strcasecmp(cfg_obj_asstring(typeobj), "redirect") != 0))
48ed268b3378a8b729a0037bc4ae2ed73647a96aBrian Wellington * Is the redirect zone configured as a slave?
9cd6710f91bdffef5aed68ab02533e398f6134d7Brian Wellington if (strcasecmp(cfg_obj_asstring(typeobj), "redirect") == 0) {
9cd6710f91bdffef5aed68ab02533e398f6134d7Brian Wellington cfg_map_get(zoptions, "masters", &mastersobj);
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews if (get_maps(maps, "check-dup-records", &obj)) {
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews if (strcasecmp(cfg_obj_asstring(obj), "warn") == 0) {
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews } else if (strcasecmp(cfg_obj_asstring(obj), "fail") == 0) {
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews } else if (strcasecmp(cfg_obj_asstring(obj), "ignore") == 0) {
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews if (strcasecmp(cfg_obj_asstring(obj), "warn") == 0) {
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington } else if (strcasecmp(cfg_obj_asstring(obj), "fail") == 0) {
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews } else if (strcasecmp(cfg_obj_asstring(obj), "ignore") == 0) {
48ed268b3378a8b729a0037bc4ae2ed73647a96aBrian Wellington if (strcasecmp(cfg_obj_asstring(obj), "warn") == 0) {
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews } else if (strcasecmp(cfg_obj_asstring(obj), "fail") == 0) {
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews } else if (strcasecmp(cfg_obj_asstring(obj), "ignore") == 0) {
ff30cdeb783ca7ffe69b222c56197828e882c229Mark Andrews if (strcasecmp(cfg_obj_asstring(obj), "warn") == 0) {
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews } else if (strcasecmp(cfg_obj_asstring(obj), "fail") == 0) {
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews } else if (strcasecmp(cfg_obj_asstring(obj), "ignore") == 0) {
3676eeb6ca95c66aae1256f37af8c990d9f25eb4Brian Wellington if (strcasecmp(cfg_obj_asstring(obj), "warn") == 0) {
3676eeb6ca95c66aae1256f37af8c990d9f25eb4Brian Wellington } else if (strcasecmp(cfg_obj_asstring(obj), "ignore") == 0) {
6f071989da905bb5ab2c6dfd01a71ee5ecea5918Brian Wellington if (strcasecmp(cfg_obj_asstring(obj), "warn") == 0) {
6f071989da905bb5ab2c6dfd01a71ee5ecea5918Brian Wellington zone_options &= ~DNS_ZONEOPT_CHECKNAMESFAIL;
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews } else if (strcasecmp(cfg_obj_asstring(obj), "fail") == 0) {
8839b6acbf816fedc15b8e9e1c71fd606a9cd8eaBrian Wellington zone_options |= DNS_ZONEOPT_CHECKNAMESFAIL;
9cd6710f91bdffef5aed68ab02533e398f6134d7Brian Wellington } else if (strcasecmp(cfg_obj_asstring(obj), "ignore") == 0) {
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington zone_options &= ~DNS_ZONEOPT_CHECKNAMESFAIL;
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington zone_options |= DNS_ZONEOPT_CHECKNAMESFAIL;
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews if (get_maps(maps, "masterfile-format", &fmtobj)) {
3676eeb6ca95c66aae1256f37af8c990d9f25eb4Brian Wellington const char *masterformatstr = cfg_obj_asstring(fmtobj);
17a3fcecd069130a5f318685493b0db5639a77c9Brian Wellington if (strcasecmp(masterformatstr, "text") == 0)
1b1e1fda4638334b484aa38c15f53a131c0b0fdfAndreas Gustafsson else if (strcasecmp(masterformatstr, "raw") == 0)
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington else if (strcasecmp(masterformatstr, "map") == 0)
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews result = load_zone(mctx, zname, zfile, masterformat,
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews fprintf(stderr, "%s/%s/%s: %s\n", view, zname, zclass,
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews/*% configure a view */
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrewsconfigure_view(const char *vclass, const char *view, const cfg_obj_t *config,
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews (void)cfg_map_get(voptions, "zone", &zonelist);
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews const cfg_obj_t *zconfig = cfg_listelt_value(element);
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington tresult = configure_zone(vclass, view, zconfig, vconfig,
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington/*% load zones from the configuration */
c99d9017ba00099bfa89e1ed53e63a5cb07d28d5Mark Andrewsload_zones_fromconfig(const cfg_obj_t *config, isc_mem_t *mctx) {
c99d9017ba00099bfa89e1ed53e63a5cb07d28d5Mark Andrews vname = cfg_obj_asstring(cfg_tuple_get(vconfig, "name"));
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington tresult = configure_view(vclass, vname, config, vconfig, mctx);
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington tresult = configure_view("IN", "_default", config, NULL, mctx);
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellingtonoutput(void *closure, const char *text, int textlen) {
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington if (fwrite(text, 1, textlen, stdout) != (size_t)textlen) {
93d6dfaf66258337985427c86181f01fc51f0bb4Mark Andrews/*% The main processing routine */
93d6dfaf66258337985427c86181f01fc51f0bb4Mark Andrews unsigned int flags = 0;
8b5de9701428e2b5eb50aba96af23dc1186124ddMark Andrews * Process memory debugging argument first.
93d6dfaf66258337985427c86181f01fc51f0bb4Mark Andrews while ((c = isc_commandline_parse(argc, argv, CMDLINE_FLAGS)) != -1) {
8b5de9701428e2b5eb50aba96af23dc1186124ddMark Andrews switch (c) {
8b5de9701428e2b5eb50aba96af23dc1186124ddMark Andrews if (strcasecmp(isc_commandline_argument, "record") == 0)
8b5de9701428e2b5eb50aba96af23dc1186124ddMark Andrews if (strcasecmp(isc_commandline_argument, "trace") == 0)
8b5de9701428e2b5eb50aba96af23dc1186124ddMark Andrews if (strcasecmp(isc_commandline_argument, "usage") == 0)
93d6dfaf66258337985427c86181f01fc51f0bb4Mark Andrews if (strcasecmp(isc_commandline_argument, "size") == 0)
93d6dfaf66258337985427c86181f01fc51f0bb4Mark Andrews if (strcasecmp(isc_commandline_argument, "mctx") == 0)
93d6dfaf66258337985427c86181f01fc51f0bb4Mark Andrews RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
c99d9017ba00099bfa89e1ed53e63a5cb07d28d5Mark Andrews while ((c = isc_commandline_parse(argc, argv, CMDLINE_FLAGS)) != EOF) {
93d6dfaf66258337985427c86181f01fc51f0bb4Mark Andrews switch (c) {
93d6dfaf66258337985427c86181f01fc51f0bb4Mark Andrews result = isc_dir_chroot(isc_commandline_argument);
34aa7909371f13b4bc0ba6d155cfc38bfa1e3c5cAndreas Gustafsson fprintf(stderr, "%s: invalid argument -%c\n",
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington /* FALLTHROUGH */
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington fprintf(stderr, "%s: unhandled option -%c\n",
94766449d6125cd5870891b70d46573e5deaceb4Brian Wellington if (((flags & CFG_PRINTER_XKEY) != 0) && !print) {
94766449d6125cd5870891b70d46573e5deaceb4Brian Wellington fprintf(stderr, "%s: -x cannot be used without -p\n", program);
6f071989da905bb5ab2c6dfd01a71ee5ecea5918Brian Wellington if (conffile == NULL || conffile[0] == '\0')
8839b6acbf816fedc15b8e9e1c71fd606a9cd8eaBrian Wellington RUNTIME_CHECK(setup_logging(mctx, stdout, &logc) == ISC_R_SUCCESS);
34aa7909371f13b4bc0ba6d155cfc38bfa1e3c5cAndreas Gustafsson RUNTIME_CHECK(isc_entropy_create(mctx, &ectx) == ISC_R_SUCCESS);
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington RUNTIME_CHECK(isc_hash_create(mctx, ectx, DNS_NAME_MAXWIRE)
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews RUNTIME_CHECK(cfg_parser_create(mctx, logc, &parser) == ISC_R_SUCCESS);
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews cfg_parser_setcallback(parser, directory_callback, NULL);
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews if (cfg_parse_file(parser, conffile, &cfg_type_namedconf, &config) !=
93d6dfaf66258337985427c86181f01fc51f0bb4Mark Andrews result = bind9_check_namedconf(config, logc, mctx);