]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
more checks by checkconf.
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Fri, 11 Jan 2008 11:24:30 +0000 (11:24 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Fri, 11 Jan 2008 11:24:30 +0000 (11:24 +0000)
git-svn-id: file:///svn/unbound/trunk@842 be551aaa-1e26-0410-a405-d3ace91eadb9

doc/Changelog
iterator/iter_hints.c
smallapp/unbound-checkconf.c
testdata/04-checkconf.tpkg
util/net_help.c

index 6fef02baa3ac637a4ad2fb9dab508599aa5ca046..52c4465fd6e1826a141bd5b2cb3c910c95d497c1 100644 (file)
@@ -1,6 +1,8 @@
 11 January 2008: Wouter
        - man page, warning removed.
        - added text describing the use of stub zones for private zones.
+       - checkconf tests for bad hostnames (IP address), and for doubled
+         interface lines.
 
 10 January 2008: Wouter
        - typo in example.conf.
index 024ad96c94b5dd1653a9d45e3cecbb7536ea56a3..b7b99f906ca81667f8f501cb90d2c6d2669fe747 100644 (file)
@@ -434,7 +434,6 @@ hints_apply_cfg(struct iter_hints* hints, struct config_file* cfg)
                        return 0;
                if(!hints_insert(hints, LDNS_RR_CLASS_IN, dp))
                        return 0;
-               delegpt_log(VERB_DETAIL, dp);
        }
 
        init_parents(hints);
index 074b6a67db9cdd777e653f3e0fab053c8aa0d905..f605380c378bd79fba9ca2a35f699a23c3cd20db 100644 (file)
@@ -86,20 +86,58 @@ check_mod(struct config_file* cfg, struct module_func_block* fb)
        regional_destroy(env.scratch);
 }
 
-/** check configuration for errors */
+/** check localzones */
 static void
-morechecks(struct config_file* cfg)
+localzonechecks(struct config_file* cfg)
+{
+       struct local_zones* zs;
+       if(!(zs = local_zones_create()))
+               fatal_exit("out of memory");
+       if(!local_zones_apply_cfg(zs, cfg))
+               fatal_exit("failed local-zone, local-data configuration");
+       local_zones_delete(zs);
+}
+
+/** emit warnings for IP in hosts */
+static void
+warn_hosts(const char* typ, struct config_stub* list)
 {
-       int i;
        struct sockaddr_storage a;
        socklen_t alen;
-       struct config_str2list* acl;
-       struct local_zones* zs;
+       struct config_stub* s;
+       struct config_strlist* h;
+       for(s=list; s; s=s->next) {
+               for(h=s->hosts; h; h=h->next) {
+                       if(extstrtoaddr(h->str, &a, &alen)) {
+                               fprintf(stderr, "unbound-checkconf: warning:"
+                                 " %s %s: \"%s\" is an IP%s address, "
+                                 "and when looked up as a host name "
+                                 "during use may not resolve.\n", 
+                                 s->name, typ, h->str,
+                                 addr_is_ip6(&a, alen)?"6":"4");
+                       }
+               }
+       }
+}
+
+/** check interface strings */
+static void
+interfacechecks(struct config_file* cfg)
+{
+       struct sockaddr_storage a;
+       socklen_t alen;
+       int i, j;
        for(i=0; i<cfg->num_ifs; i++) {
                if(!ipstrtoaddr(cfg->ifs[i], UNBOUND_DNS_PORT, &a, &alen)) {
                        fatal_exit("cannot parse interface specified as '%s'",
                                cfg->ifs[i]);
                }
+               for(j=0; j<cfg->num_ifs; j++) {
+                       if(i!=j && strcmp(cfg->ifs[i], cfg->ifs[j])==0)
+                               fatal_exit("interface: %s present twice, "
+                                       "cannot bind same ports twice.",
+                                       cfg->ifs[i]);
+               }
        }
        for(i=0; i<cfg->num_out_ifs; i++) {
                if(!ipstrtoaddr(cfg->out_ifs[i], UNBOUND_DNS_PORT, 
@@ -107,14 +145,40 @@ morechecks(struct config_file* cfg)
                        fatal_exit("cannot parse outgoing-interface "
                                "specified as '%s'", cfg->out_ifs[i]);
                }
+               for(j=0; j<cfg->num_out_ifs; j++) {
+                       if(i!=j && strcmp(cfg->out_ifs[i], cfg->out_ifs[j])==0)
+                               fatal_exit("outgoing-interface: %s present "
+                                       "twice, cannot bind same ports twice.",
+                                       cfg->out_ifs[i]);
+               }
        }
+}
+
+/** check acl ips */
+static void
+aclchecks(struct config_file* cfg)
+{
+       int d;
+       struct sockaddr_storage a;
+       socklen_t alen;
+       struct config_str2list* acl;
        for(acl=cfg->acls; acl; acl = acl->next) {
                if(!netblockstrtoaddr(acl->str, UNBOUND_DNS_PORT, &a, &alen, 
-                       &i)) {
+                       &d)) {
                        fatal_exit("cannot parse access control address %s %s",
                                acl->str, acl->str2);
                }
        }
+}
+
+/** check configuration for errors */
+static void
+morechecks(struct config_file* cfg)
+{
+       warn_hosts("stub-host", cfg->stubs);
+       warn_hosts("forward-host", cfg->forwards);
+       interfacechecks(cfg);
+       aclchecks(cfg);
 
        if(cfg->verbosity < 0)
                fatal_exit("verbosity value < 0");
@@ -152,12 +216,7 @@ morechecks(struct config_file* cfg)
                endpwent();
        }
 
-       if(!(zs = local_zones_create()))
-               fatal_exit("out of memory");
-       if(!local_zones_apply_cfg(zs, cfg))
-               fatal_exit("failed local-zone, local-data configuration");
-       local_zones_print(zs); /* @@@ DEBUG */
-       local_zones_delete(zs);
+       localzonechecks(cfg);
 }
 
 /** check config file */
index d01b6410c5a967745b01cc2c46e7b4c165cf4bb9..ab98b86f4d056ce954ec4cccb3acba5dbe2d3afe 100644 (file)
Binary files a/testdata/04-checkconf.tpkg and b/testdata/04-checkconf.tpkg differ
index b2200721da79d778439728d4d194abd558ec2f0c..712e8c9066384e3b5bf345c4232b49f080484668 100644 (file)
@@ -182,14 +182,12 @@ extstrtoaddr(const char* str, struct sockaddr_storage* addr,
        if((s=strchr(str, '@'))) {
                char buf[MAX_ADDR_STRLEN];
                if(s-str >= MAX_ADDR_STRLEN) {
-                       log_err("address too long: '%s'", str);
                        return 0;
                }
                strncpy(buf, str, MAX_ADDR_STRLEN);
                buf[s-str] = 0;
                port = atoi(s+1);
                if(port == 0 && strcmp(s+1,"0")!=0) {
-                       log_err("bad port spec in address: '%s", str);
                        return 0;
                }
                return ipstrtoaddr(buf, port, addr, addrlen);
@@ -212,7 +210,6 @@ ipstrtoaddr(const char* ip, int port, struct sockaddr_storage* addr,
                sa->sin6_family = AF_INET6;
                sa->sin6_port = (in_port_t)htons(p);
                if(inet_pton((int)sa->sin6_family, ip, &sa->sin6_addr) <= 0) {
-                       log_err("Bad ip6 address %s", ip);
                        return 0;
                }
        } else { /* ip4 */
@@ -222,7 +219,6 @@ ipstrtoaddr(const char* ip, int port, struct sockaddr_storage* addr,
                sa->sin_family = AF_INET;
                sa->sin_port = (in_port_t)htons(p);
                if(inet_pton((int)sa->sin_family, ip, &sa->sin_addr) <= 0) {
-                       log_err("Bad ip4 address %s", ip);
                        return 0;
                }
        }