Commit 90c099e8 authored by Brian Wellington's avatar Brian Wellington

762. [feature] named now uses the new configuration parser.

parent 6893a1ee
762. [feature] named now uses the new configuration parser.
761. [bug] _REENTRANT was still defined when building with
--disable-threads.
......
......@@ -13,7 +13,7 @@
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
# $Id: Makefile.in,v 1.67 2001/02/04 15:52:39 bwelling Exp $
# $Id: Makefile.in,v 1.68 2001/03/04 21:21:19 bwelling Exp $
srcdir = @srcdir@
VPATH = @srcdir@
......@@ -32,34 +32,37 @@ DBDRIVER_INCLUDES =
DBDRIVER_LIBS =
CINCLUDES = -I${srcdir}/include -I${srcdir}/unix/include \
${LWRES_INCLUDES} ${DNS_INCLUDES} ${ISC_INCLUDES} \
${OMAPI_INCLUDES} ${DBDRIVER_INCLUDES}
${LWRES_INCLUDES} ${OMAPI_INCLUDES} ${DNS_INCLUDES} \
${ISCCFG_INCLUDES} ${ISC_INCLUDES} ${DBDRIVER_INCLUDES}
CDEFINES =
CWARNINGS =
OMAPILIBS = ../../lib/omapi/libomapi.@A@
DNSLIBS = ../../lib/dns/libdns.@A@ @DNS_OPENSSL_LIBS@ @DNS_GSSAPI_LIBS@
ISCCFGLIBS = ../../lib/isccfg/libisccfg.@A@
ISCLIBS = ../../lib/isc/libisc.@A@
LWRESLIBS = ../../lib/lwres/liblwres.@A@
OMAPIDEPLIBS = ../../lib/omapi/libomapi.@A@
DNSDEPLIBS = ../../lib/dns/libdns.@A@
ISCCFGDEPLIBS = ../../lib/isccfg/libisccfg.@A@
ISCDEPLIBS = ../../lib/isc/libisc.@A@
LWRESDEPLIBS = ../../lib/lwres/liblwres.@A@
DEPLIBS = ${LWRESDEPLIBS} ${OMAPIDEPLIBS} ${DNSDEPLIBS} ${ISCDEPLIBS}
DEPLIBS = ${LWRESDEPLIBS} ${OMAPIDEPLIBS} ${DNSDEPLIBS} \
${ISCCFGDEPLIBS} ${ISCDEPLIBS}
LIBS = ${LWRESLIBS} ${OMAPILIBS} ${DNSLIBS} ${ISCLIBS} \
${DBDRIVER_LIBS} @LIBS@
LIBS = ${LWRESLIBS} ${OMAPILIBS} ${DNSLIBS} \
${ISCCFGLIBS} ${ISCLIBS} ${DBDRIVER_LIBS} @LIBS@
SUBDIRS = unix
TARGETS = named lwresd
OBJS = aclconf.@O@ client.@O@ interfacemgr.@O@ listenlist.@O@ \
log.@O@ logconf.@O@ main.@O@ notify.@O@ omapi.@O@ \
omapiconf.@O@ query.@O@ server.@O@ sortlist.@O@ \
OBJS = aclconf.@O@ client.@O@ config.@O@ interfacemgr.@O@ \
listenlist.@O@ log.@O@ logconf.@O@ main.@O@ notify.@O@ \
omapi.@O@ omapiconf.@O@ query.@O@ server.@O@ sortlist.@O@ \
tkeyconf.@O@ tsigconf.@O@ update.@O@ xfrout.@O@ \
zoneconf.@O@ \
lwaddr.@O@ lwresd.@O@ lwdclient.@O@ lwderror.@O@ lwdgabn.@O@ \
......@@ -68,9 +71,9 @@ OBJS = aclconf.@O@ client.@O@ interfacemgr.@O@ listenlist.@O@ \
UOBJS = unix/os.@O@
SRCS = aclconf.c client.c interfacemgr.c listenlist.c \
log.c logconf.c main.c notify.c omapi.c \
omapiconf.c query.c server.c sortlist.c \
SRCS = aclconf.c client.c config.c interfacemgr.c \
listenlist.c log.c logconf.c main.c notify.c \
omapi.c omapiconf.c query.c server.c sortlist.c \
tkeyconf.c tsigconf.c update.c xfrout.c \
zoneconf.c \
lwaddr.c lwresd.c lwdclient.c lwderror.c lwdgabn.c \
......@@ -86,6 +89,11 @@ main.@O@: main.c
-DNS_LOCALSTATEDIR=\"${localstatedir}\" \
-DNS_SYSCONFDIR=\"${sysconfdir}\" -c ${srcdir}/main.c
config.@O@: config.c
${LIBTOOL} ${CC} ${ALL_CFLAGS} -DVERSION=\"${VERSION}\" \
-DNS_LOCALSTATEDIR=\"${localstatedir}\" \
-c ${srcdir}/config.c
named: ${OBJS} ${UOBJS} ${DEPLIBS}
${LIBTOOL} ${PURIFY} ${CC} ${CFLAGS} -o $@ ${OBJS} ${UOBJS} ${LIBS}
......
......@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: aclconf.c,v 1.25 2001/01/09 21:39:39 bwelling Exp $ */
/* $Id: aclconf.c,v 1.26 2001/03/04 21:21:20 bwelling Exp $ */
#include <config.h>
......@@ -46,34 +46,59 @@ ns_aclconfctx_destroy(ns_aclconfctx_t *ctx) {
}
}
/*
* Find the definition of the named acl whose name is "name".
*/
static isc_result_t
get_acl_def(cfg_obj_t *cctx, char *name, cfg_obj_t **ret) {
isc_result_t result;
cfg_obj_t *acls = NULL;
cfg_listelt_t *elt;
result = cfg_map_get(cctx, "acl", &acls);
if (result != ISC_R_SUCCESS)
return (result);
for (elt = cfg_list_first(acls);
elt != NULL;
elt = cfg_list_next(elt)) {
cfg_obj_t *acl = cfg_listelt_value(elt);
const char *aclname = cfg_obj_asstring(cfg_tuple_get(acl, "name"));
if (strcasecmp(aclname, name) == 0) {
*ret = cfg_tuple_get(acl, "value");
return (ISC_R_SUCCESS);
}
}
return (ISC_R_NOTFOUND);
}
static isc_result_t
convert_named_acl(char *aclname, dns_c_ctx_t *cctx,
convert_named_acl(cfg_obj_t *nameobj, cfg_obj_t *cctx,
ns_aclconfctx_t *ctx, isc_mem_t *mctx,
dns_acl_t **target)
{
isc_result_t result;
dns_c_acl_t *cacl;
cfg_obj_t *cacl = NULL;
dns_acl_t *dacl;
char *aclname = cfg_obj_asstring(nameobj);
/* Look for an already-converted version. */
for (dacl = ISC_LIST_HEAD(ctx->named_acl_cache);
dacl != NULL;
dacl = ISC_LIST_NEXT(dacl, nextincache))
{
if (strcmp(aclname, dacl->name) == 0) {
if (strcasecmp(aclname, dacl->name) == 0) {
dns_acl_attach(dacl, target);
return (ISC_R_SUCCESS);
}
}
/* Not yet converted. Convert now. */
result = dns_c_acltable_getacl(cctx->acls, aclname, &cacl);
result = get_acl_def(cctx, aclname, &cacl);
if (result != ISC_R_SUCCESS) {
isc_log_write(dns_lctx, DNS_LOGCATEGORY_SECURITY,
DNS_LOGMODULE_ACL, ISC_LOG_WARNING,
"undefined ACL '%s'", aclname);
cfg_obj_log(nameobj, dns_lctx, ISC_LOG_WARNING,
"undefined ACL '%s'", aclname);
return (result);
}
result = ns_acl_fromconfig(cacl->ipml, cctx, ctx, mctx, &dacl);
result = ns_acl_fromconfig(cacl, cctx, ctx, mctx, &dacl);
if (result != ISC_R_SUCCESS)
return (result);
dacl->name = isc_mem_strdup(dacl->mctx, aclname);
......@@ -85,11 +110,12 @@ convert_named_acl(char *aclname, dns_c_ctx_t *cctx,
}
static isc_result_t
convert_keyname(char *txtname, isc_mem_t *mctx, dns_name_t *dnsname) {
convert_keyname(cfg_obj_t *keyobj, isc_mem_t *mctx, dns_name_t *dnsname) {
isc_result_t result;
isc_buffer_t buf;
dns_fixedname_t fixname;
unsigned int keylen;
const char *txtname = cfg_obj_asstring(keyobj);
keylen = strlen(txtname);
isc_buffer_init(&buf, txtname, keylen);
......@@ -98,34 +124,33 @@ convert_keyname(char *txtname, isc_mem_t *mctx, dns_name_t *dnsname) {
result = dns_name_fromtext(dns_fixedname_name(&fixname), &buf,
dns_rootname, ISC_FALSE, NULL);
if (result != ISC_R_SUCCESS) {
isc_log_write(dns_lctx, DNS_LOGCATEGORY_SECURITY,
DNS_LOGMODULE_ACL, ISC_LOG_WARNING,
"key name \"%s\" is not a valid domain name",
txtname);
cfg_obj_log(keyobj, dns_lctx, ISC_LOG_WARNING,
"key name '%s' is not a valid domain name",
txtname);
return (result);
}
return (dns_name_dup(dns_fixedname_name(&fixname), mctx, dnsname));
}
isc_result_t
ns_acl_fromconfig(dns_c_ipmatchlist_t *caml,
dns_c_ctx_t *cctx,
ns_aclconfctx_t *ctx,
isc_mem_t *mctx,
dns_acl_t **target)
ns_acl_fromconfig(cfg_obj_t *caml,
cfg_obj_t *cctx,
ns_aclconfctx_t *ctx,
isc_mem_t *mctx,
dns_acl_t **target)
{
isc_result_t result;
unsigned int count;
dns_acl_t *dacl = NULL;
dns_aclelement_t *de;
dns_c_ipmatchelement_t *ce;
cfg_listelt_t *elt;
REQUIRE(target != NULL && *target == NULL);
count = 0;
for (ce = ISC_LIST_HEAD(caml->elements);
ce != NULL;
ce = ISC_LIST_NEXT(ce, next))
for (elt = cfg_list_first(caml);
elt != NULL;
elt = cfg_list_next(elt))
count++;
result = dns_acl_create(mctx, count, &dacl);
......@@ -133,59 +158,63 @@ ns_acl_fromconfig(dns_c_ipmatchlist_t *caml,
return (result);
de = dacl->elements;
for (ce = ISC_LIST_HEAD(caml->elements);
ce != NULL;
ce = ISC_LIST_NEXT(ce, next))
for (elt = cfg_list_first(caml);
elt != NULL;
elt = cfg_list_next(elt))
{
de->negative = dns_c_ipmatchelement_isneg(ce);
switch (ce->type) {
case dns_c_ipmatch_pattern:
cfg_obj_t *ce = cfg_listelt_value(elt);
if (cfg_obj_istuple(ce)) {
/* This must be a negated element. */
ce = cfg_tuple_get(ce, "value");
de->negative = ISC_TRUE;
} else {
de->negative = ISC_FALSE;
}
if (cfg_obj_isnetprefix(ce)) {
/* Network prefix */
de->type = dns_aclelementtype_ipprefix;
isc_netaddr_fromsockaddr(&de->u.ip_prefix.address,
&ce->u.direct.address);
/* XXX "mask" is a misnomer */
de->u.ip_prefix.prefixlen = ce->u.direct.mask;
break;
case dns_c_ipmatch_key:
cfg_obj_asnetprefix(ce,
&de->u.ip_prefix.address,
&de->u.ip_prefix.prefixlen);
} else if (cfg_obj_istype(ce, &cfg_type_keyref)) {
/* Key name */
de->type = dns_aclelementtype_keyname;
dns_name_init(&de->u.keyname, NULL);
result = convert_keyname(ce->u.key, mctx,
&de->u.keyname);
if (result != ISC_R_SUCCESS)
goto cleanup;
break;
case dns_c_ipmatch_indirect:
de->type = dns_aclelementtype_nestedacl;
result = ns_acl_fromconfig(ce->u.indirect.list,
cctx, ctx, mctx,
&de->u.nestedacl);
result = convert_keyname(ce, mctx, &de->u.keyname);
if (result != ISC_R_SUCCESS)
goto cleanup;
break;
case dns_c_ipmatch_localhost:
de->type = dns_aclelementtype_localhost;
break;
case dns_c_ipmatch_any:
de->type = dns_aclelementtype_any;
break;
case dns_c_ipmatch_localnets:
de->type = dns_aclelementtype_localnets;
break;
case dns_c_ipmatch_acl:
} else if (cfg_obj_islist(ce)) {
/* Nested ACL */
de->type = dns_aclelementtype_nestedacl;
result = convert_named_acl(ce->u.aclname,
cctx, ctx, mctx,
result = ns_acl_fromconfig(ce, cctx, ctx, mctx,
&de->u.nestedacl);
if (result != ISC_R_SUCCESS)
goto cleanup;
break;
default:
isc_log_write(dns_lctx, DNS_LOGCATEGORY_SECURITY,
DNS_LOGMODULE_ACL, ISC_LOG_WARNING,
"address match list contains "
"unsupported element type");
} else if (cfg_obj_isstring(ce)) {
/* ACL name */
char *name = cfg_obj_asstring(ce);
if (strcasecmp(name, "localhost") == 0) {
de->type = dns_aclelementtype_localhost;
} else if (strcasecmp(name, "localnets") == 0) {
de->type = dns_aclelementtype_localnets;
} else if (strcasecmp(name, "any") == 0) {
de->type = dns_aclelementtype_any;
} else if (strcasecmp(name, "none") == 0) {
de->type = dns_aclelementtype_any;
de->negative = ! de->negative;
} else {
de->type = dns_aclelementtype_nestedacl;
result = convert_named_acl(ce, cctx, ctx, mctx,
&de->u.nestedacl);
if (result != ISC_R_SUCCESS)
goto cleanup;
}
} else {
cfg_obj_log(ce, dns_lctx, ISC_LOG_WARNING,
"address match list contains "
"unsupported element type");
result = ISC_R_FAILURE;
goto cleanup;
}
......
/*
* Copyright (C) 2001 Internet Software Consortium.
*
* 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.
*/
/* $Id: config.c,v 1.1 2001/03/04 21:21:21 bwelling Exp $ */
#include <stdlib.h>
#include <string.h>
#include <isc/buffer.h>
#include <isc/log.h>
#include <isc/mem.h>
#include <isc/region.h>
#include <isc/result.h>
#include <isc/sockaddr.h>
#include <isc/util.h>
#include <isccfg/cfg.h>
#include <dns/fixedname.h>
#include <dns/name.h>
#include <dns/rdataclass.h>
#include <dns/zone.h>
#include <named/config.h>
#include <named/globals.h>
static char defaultconf[] = "
options {
# blackhole {none;};
coresize default;
datasize default;
deallocate-on-exit true;
# directory <none>
dump-file \"named_dump.db\";
fake-iquery no;
files default;
has-old-clients false;
heartbeat-interval 3600;
host-statistics no;
interface-interval 3600;
listen-on {any;};
listen-on-v6 {none;};
memstatistics-file \"named.memstats\";
multiple-cnames no;
# named-xfer <obsolete>
# pid-file \"" NS_LOCALSTATEDIR "/named.pid\"; /* or /lwresd.pid */
port 53;
"
#ifdef PATH_RANDOMDEV
"
random-device \"" PATH_RANDOMDEV "\";
"
#endif
"
recursive-clients 1000;
rrset-order {order cyclic;};
serial-queries 20;
stacksize default;
statistics-file \"named.stats\";
statistics-interval 3600;
tcp-clients 100;
# tkey-dhkey <none>
# tkey-gssapi-credential <none>
# tkey-domain <none>
transfers-per-ns 2;
transfers-in 10;
transfers-out 10;
treat-cr-as-space true;
use-id-pool true;
use-ixfr true;
version \""VERSION"\";
/* view */
allow-notify {none;};
allow-update-forwarding {none;};
allow-recursion {any;};
allow-v6-synthesis {none;};
# sortlist <none>
# topology <none>
auth-nxdomain false;
recursion true;
provide-ixfr true;
request-ixfr true;
fetch-glue no;
rfc2308-type1 no;
additional-from-auth true;
additional-from-cache true;
query-source address *;
query-source-v6 address *;
notify-source *;
notify-source-v6 *;
cleaning-interval 3600;
min-roots 2;
lame-ttl 600;
max-ncache-ttl 10800; /* 3 hours */
max-cache-ttl 604800; /* 1 week */
transfer-format many-answers;
max-cache-size 0;
check-names master ignore;
check-names slave ignore;
check-names response ignore;
/* zone */
allow-query {any;};
allow-transfer {any;};
notify yes;
# also-notify <none>
dialup no;
# forward <none>
# forwarders <none>
maintain-ixfr-base no;
# max-ixfr-log-size <obsolete>
transfer-source *;
transfer-source-v6 *;
max-transfer-time-in 7200;
max-transfer-time-out 7200;
max-transfer-idle-in 3600;
max-transfer-idle-out 3600;
max-retry-time 1209600; /* 2 weeks */
min-retry-time 500;
max-refresh-time 2419200; /* 4 weeks */
min-refresh-time 300;
sig-validity-interval 30; /* days */
zone-statistics false;
};";
isc_result_t
ns_config_parsedefaults(cfg_parser_t *parser, cfg_obj_t **conf) {
isc_buffer_t b;
isc_buffer_init(&b, defaultconf, sizeof(defaultconf) - 1);
isc_buffer_add(&b, sizeof(defaultconf) - 1);
return (cfg_parse_buffer(parser, &b, &cfg_type_namedconf, conf));
}
isc_result_t
ns_config_get(cfg_obj_t **maps, const char* name, cfg_obj_t **obj) {
int i;
for (i = 0; ; i++) {
if (maps[i] == NULL)
return (ISC_R_NOTFOUND);
if (cfg_map_get(maps[i], name, obj) == ISC_R_SUCCESS)
return (ISC_R_SUCCESS);
}
}
int
ns_config_listcount(cfg_obj_t *list) {
cfg_listelt_t *e;
int i = 0;
for (e = cfg_list_first(list); e != NULL; e = cfg_list_next(e))
i++;
return (i);
}
isc_result_t
ns_config_getclass(cfg_obj_t *classobj, dns_rdataclass_t *classp) {
char *str;
isc_textregion_t r;
if (!cfg_obj_isstring(classobj)) {
*classp = dns_rdataclass_in;
return (ISC_R_SUCCESS);
}
str = cfg_obj_asstring(classobj);
r.base = str;
r.length = strlen(str);
return (dns_rdataclass_fromtext(classp, &r));
}
isc_result_t
ns_config_getzonetype(cfg_obj_t *zonetypeobj) {
dns_zonetype_t ztype;
char *str;
str = cfg_obj_asstring(zonetypeobj);
if (strcmp(str, "master") == 0)
ztype = dns_zone_master;
else if (strcmp(str, "slave") == 0)
ztype = dns_zone_slave;
else if (strcmp(str, "stub") == 0)
ztype = dns_zone_stub;
else
INSIST(0);
return (ztype);
}
isc_result_t
ns_config_getiplist(cfg_obj_t *config, cfg_obj_t *list,
in_port_t defport, isc_mem_t *mctx,
isc_sockaddr_t **addrsp, isc_uint32_t *countp)
{
int count, i = 0;
cfg_obj_t *addrlist;
cfg_obj_t *portobj;
cfg_listelt_t *element;
isc_sockaddr_t *addrs;
in_port_t port;
isc_result_t result;
INSIST(addrsp != NULL && *addrsp == NULL);
addrlist = cfg_tuple_get(list, "addresses");
count = ns_config_listcount(addrlist);
portobj = cfg_tuple_get(list, "port");
if (cfg_obj_isuint32(portobj)) {
isc_uint32_t val = cfg_obj_asuint32(portobj);
if (val > ISC_UINT16_MAX) {
cfg_obj_log(portobj, ns_g_lctx, ISC_LOG_ERROR,
"port '%u' out of range", val);
return (ISC_R_RANGE);
}
port = (in_port_t) val;
} else if (defport != 0)
port = defport;
else {
result = ns_config_getport(config, &port);
if (result != ISC_R_SUCCESS)
return (result);
}
addrs = isc_mem_get(mctx, count * sizeof(isc_sockaddr_t));
if (addrs == NULL)
return (ISC_R_NOMEMORY);
for (element = cfg_list_first(addrlist);
element != NULL;
element = cfg_list_next(element), i++)
{
INSIST(i < count);
addrs[i] = *cfg_obj_assockaddr(cfg_listelt_value(element));
if (isc_sockaddr_getport(&addrs[i]) == 0)
isc_sockaddr_setport(&addrs[i], port);
}
INSIST(i == count);
*addrsp = addrs;
*countp = count;
return (ISC_R_SUCCESS);
}
void
ns_config_putiplist(isc_mem_t *mctx, isc_sockaddr_t **addrsp,
isc_uint32_t count)
{
INSIST(addrsp != NULL && *addrsp != NULL);
isc_mem_put(mctx, *addrsp, count * sizeof(isc_sockaddr_t));
*addrsp = NULL;
}
isc_result_t
ns_config_getipandkeylist(cfg_obj_t *config, cfg_obj_t *list, isc_mem_t *mctx,
isc_sockaddr_t **addrsp, dns_name_t ***keysp,
isc_uint32_t *countp)
{
isc_uint32_t count, i = 0;
isc_result_t result;
cfg_listelt_t *element;
cfg_obj_t *addrlist;
cfg_obj_t *portobj;
in_port_t port;
dns_fixedname_t fname;
isc_sockaddr_t *addrs = NULL;
dns_name_t **keys = NULL;
INSIST(addrsp != NULL && *addrsp == NULL);
addrlist = cfg_tuple_get(list, "addresses");
count = ns_config_listcount(addrlist);
portobj = cfg_tuple_get(list, "port");
if (cfg_obj_isuint32(portobj)) {
isc_uint32_t val = cfg_obj_asuint32(portobj);
if (val > ISC_UINT16_MAX) {
cfg_obj_log(portobj, ns_g_lctx, ISC_LOG_ERROR,
"port '%u' out of range", val);
return (ISC_R_RANGE);
}
port = (in_port_t) val;
} else {
result = ns_config_getport(config, &port);
if (result != ISC_R_SUCCESS)
return (result);
}
result = ISC_R_NOMEMORY;
addrs = isc_mem_get(mctx, count * sizeof(isc_sockaddr_t));
if (addrs == NULL)
goto cleanup;
keys = isc_mem_get(mctx, count * sizeof(dns_name_t *));
if (keys == NULL)
goto cleanup;
for (element = cfg_list_first(addrlist);