Commit 17453368 authored by Andreas Gustafsson's avatar Andreas Gustafsson

Reimplemented the built-in CHAOS zones using sdb.

parent d8720af3
......@@ -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.76 2001/11/06 20:05:01 bwelling Exp $
# $Id: Makefile.in,v 1.77 2001/11/20 01:14:55 gson Exp $
srcdir = @srcdir@
VPATH = @srcdir@
......@@ -63,7 +63,8 @@ SUBDIRS = unix
TARGETS = named lwresd
OBJS = aclconf.@O@ client.@O@ config.@O@ control.@O@ controlconf.@O@ interfacemgr.@O@ \
OBJS = aclconf.@O@ builtin.@O@ client.@O@ config.@O@ control.@O@ \
controlconf.@O@ interfacemgr.@O@ \
listenlist.@O@ log.@O@ logconf.@O@ main.@O@ notify.@O@ \
query.@O@ server.@O@ sortlist.@O@ \
tkeyconf.@O@ tsigconf.@O@ update.@O@ xfrout.@O@ \
......@@ -74,7 +75,8 @@ OBJS = aclconf.@O@ client.@O@ config.@O@ control.@O@ controlconf.@O@ interfacem
UOBJS = unix/os.@O@
SRCS = aclconf.c client.c config.c control.c controlconf.c interfacemgr.c \
SRCS = aclconf.c builtin.c client.c config.c control.c \
controlconf.c interfacemgr.c \
listenlist.c log.c logconf.c main.c notify.c \
query.c server.c sortlist.c \
tkeyconf.c tsigconf.c update.c xfrout.c \
......
/*
* 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: builtin.c,v 1.1 2001/11/20 01:14:56 gson Exp $ */
/*
* The built-in "version", "hostname", and "authors" databases.
*/
#include <config.h>
#include <string.h>
#include <stdio.h>
#include <isc/print.h>
#include <isc/result.h>
#include <isc/util.h>
#include <dns/sdb.h>
#include <dns/result.h>
#include <named/builtin.h>
#include <named/globals.h>
#include <named/server.h>
#include <named/os.h>
typedef struct builtin builtin_t;
static isc_result_t do_version_lookup(dns_sdblookup_t *lookup);
static isc_result_t do_hostname_lookup(dns_sdblookup_t *lookup);
static isc_result_t do_authors_lookup(dns_sdblookup_t *lookup);
/*
* We can't use function pointers as the db_data directly
* because ANSI C does not guarantee that function pointers
* can safely be cast to void pointers and back.
*/
struct builtin {
isc_result_t (*do_lookup)(dns_sdblookup_t *lookup);
};
static builtin_t version_builtin = { do_version_lookup };
static builtin_t hostname_builtin = { do_hostname_lookup };
static builtin_t authors_builtin = { do_authors_lookup };
static dns_sdbimplementation_t *builtin_impl;
static isc_result_t
builtin_lookup(const char *zone, const char *name, void *dbdata,
dns_sdblookup_t *lookup)
{
builtin_t *b = (builtin_t *) dbdata;
UNUSED(zone);
if (strcmp(name, "@") == 0)
return (b->do_lookup(lookup));
else
return (ISC_R_NOTFOUND);
}
static isc_result_t
put_txt(dns_sdblookup_t *lookup, const char *text) {
unsigned char buf[256];
unsigned int len = strlen(text);
if (len > 255)
len = 255; /* Silently truncate */
buf[0] = len;
memcpy(&buf[1], text, len);
return (dns_sdb_putrdata(lookup, dns_rdatatype_txt, 0, buf, len + 1));
}
static isc_result_t
do_version_lookup(dns_sdblookup_t *lookup) {
if (ns_g_server->version_set) {
if (ns_g_server->version == NULL)
return (ISC_R_SUCCESS);
else
return (put_txt(lookup, ns_g_server->version));
} else {
return (put_txt(lookup, ns_g_version));
}
}
static isc_result_t
do_hostname_lookup(dns_sdblookup_t *lookup) {
if (ns_g_server->hostname_set) {
if (ns_g_server->hostname == NULL)
return (ISC_R_SUCCESS);
else
return (put_txt(lookup, ns_g_server->hostname));
} else {
unsigned char buf[256];
isc_result_t result = ns_os_gethostname(buf, sizeof(buf));
if (result != ISC_R_SUCCESS)
return (result);
return (put_txt(lookup, buf));
}
}
static isc_result_t
do_authors_lookup(dns_sdblookup_t *lookup) {
isc_result_t result;
const char **p;
static const char *authors[] = {
"Mark Andrews",
"James Brister",
"Ben Cottrell",
"Michael Graff",
"Andreas Gustafsson",
"Bob Halley",
"David Lawrence",
"Danny Mayer",
"Damien Neil",
"Matt Nelson",
"Michael Sawyer",
"Brian Wellington",
NULL
};
/*
* If a version string is specified, disable the authors.bind zone.
*/
if (ns_g_server->version_set)
return (ISC_R_SUCCESS);
for (p = authors; *p != NULL; p++) {
result = put_txt(lookup, *p);
if (result != ISC_R_SUCCESS)
return (result);
}
return (ISC_R_SUCCESS);
}
static isc_result_t
builtin_authority(const char *zone, void *dbdata, dns_sdblookup_t *lookup) {
isc_result_t result;
UNUSED(zone);
UNUSED(dbdata);
result = dns_sdb_putsoa(lookup, "@", "hostmaster", 0);
if (result != ISC_R_SUCCESS)
return (ISC_R_FAILURE);
result = dns_sdb_putrr(lookup, "ns", 0, "@");
if (result != ISC_R_SUCCESS)
return (ISC_R_FAILURE);
return (ISC_R_SUCCESS);
}
static isc_result_t
builtin_create(const char *zone, int argc, char **argv,
void *driverdata, void **dbdata)
{
UNUSED(zone);
UNUSED(driverdata);
if (argc != 1)
return (DNS_R_SYNTAX);
if (strcmp(argv[0], "version") == 0)
*dbdata = &version_builtin;
else if (strcmp(argv[0], "hostname") == 0)
*dbdata = &hostname_builtin;
else if (strcmp(argv[0], "authors") == 0)
*dbdata = &authors_builtin;
else
return (ISC_R_NOTIMPLEMENTED);
return (ISC_R_SUCCESS);
}
static dns_sdbmethods_t builtin_methods = {
builtin_lookup,
builtin_authority,
NULL, /* allnodes */
builtin_create,
NULL /* destroy */
};
isc_result_t
ns_builtin_init(void) {
RUNTIME_CHECK(dns_sdb_register("_builtin", &builtin_methods, NULL,
DNS_SDBFLAG_RELATIVEOWNER |
DNS_SDBFLAG_RELATIVERDATA,
ns_g_mctx, &builtin_impl)
== ISC_R_SUCCESS);
return (ISC_R_SUCCESS);
}
void
ns_builtin_deinit(void) {
dns_sdb_unregister(&builtin_impl);
}
......@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: config.c,v 1.19 2001/11/07 04:25:11 marka Exp $ */
/* $Id: config.c,v 1.20 2001/11/20 01:14:56 gson Exp $ */
#include <config.h>
......@@ -87,7 +87,6 @@ options {\n\
treat-cr-as-space true;\n\
use-id-pool true;\n\
use-ixfr true;\n\
version \""VERSION"\";\n\
\n\
/* view */\n\
allow-notify {none;};\n\
......@@ -144,7 +143,27 @@ options {\n\
zone-statistics false;\n\
max-journal-size unlimited;\n\
ixfr-from-differences false;\n\
};";
};
view \"_bind\" chaos {
recursion no;
zone \"version.bind\" chaos {
type master;
database \"_builtin version\";
};
zone \"hostname.bind\" chaos {
type master;
database \"_builtin hostname\";
};
zone \"authors.bind\" chaos {
type master;
database \"_builtin authors\";
};
};
";
isc_result_t
ns_config_parsedefaults(cfg_parser_t *parser, cfg_obj_t **conf) {
......
/*
* 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: builtin.h,v 1.1 2001/11/20 01:18:15 gson Exp $ */
#ifndef NAMED_BUILTIN_H
#define NAMED_BUILTIN_H 1
#include <isc/types.h>
isc_result_t ns_builtin_init(void);
void ns_builtin_deinit(void);
#endif /* NAMED_BUILTIN_H */
......@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: server.h,v 1.61 2001/09/15 14:23:26 marka Exp $ */
/* $Id: server.h,v 1.62 2001/11/20 01:15:00 gson Exp $ */
#ifndef NAMED_SERVER_H
#define NAMED_SERVER_H 1
......@@ -49,6 +49,12 @@ struct ns_server {
isc_quota_t tcpquota;
isc_quota_t recursionquota;
dns_acl_t *blackholeacl;
char * statsfile; /* Statistics file name */
char * dumpfile; /* Dump file name */
isc_boolean_t version_set; /* User has set version */
char * version; /* User-specified version */
isc_boolean_t hostname_set; /* User has set hostname */
char * hostname; /* User-specified hostname */
/*
* Current ACL environment. This defines the
......@@ -76,11 +82,8 @@ struct ns_server {
isc_boolean_t flushonshutdown;
isc_boolean_t log_queries; /* For BIND 8 compatibility */
char * statsfile; /* Statistics file name */
isc_uint64_t * querystats; /* Query statistics counters */
char * dumpfile; /* Dump file name */
ns_controls_t * controls; /* Control channels */
};
......
......@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: main.c,v 1.125 2001/10/26 22:54:22 gson Exp $ */
/* $Id: main.c,v 1.126 2001/11/20 01:14:57 gson Exp $ */
#include <config.h>
......@@ -50,6 +50,7 @@
*/
#define NS_MAIN 1
#include <named/builtin.h>
#include <named/control.h>
#include <named/globals.h> /* Explicit, though named/log.h includes it. */
#include <named/interfacemgr.h>
......@@ -570,6 +571,8 @@ setup(void) {
ns_main_earlyfatal("create_managers() failed: %s",
isc_result_totext(result));
ns_builtin_init();
/*
* Add calls to register sdb drivers here.
*/
......@@ -584,6 +587,8 @@ cleanup(void) {
ns_server_destroy(&ns_g_server);
ns_builtin_deinit();
/*
* Add calls to unregister sdb drivers here.
*/
......
......@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: server.c,v 1.361 2001/11/07 23:01:41 gson Exp $ */
/* $Id: server.c,v 1.362 2001/11/20 01:14:58 gson Exp $ */
#include <config.h>
......@@ -482,7 +482,8 @@ configure_peer(cfg_obj_t *cpeer, isc_mem_t *mctx, dns_peer_t **peerp) {
*/
static isc_result_t
configure_view(dns_view_t *view, cfg_obj_t *config, cfg_obj_t *vconfig,
isc_mem_t *mctx, ns_aclconfctx_t *actx)
isc_mem_t *mctx, ns_aclconfctx_t *actx,
isc_boolean_t need_hints)
{
cfg_obj_t *maps[4];
cfg_obj_t *cfgmaps[3];
......@@ -694,15 +695,16 @@ configure_view(dns_view_t *view, cfg_obj_t *config, cfg_obj_t *vconfig,
*/
if (view->hints == NULL) {
dns_zone_t *rootzone = NULL;
dns_view_findzone(view, dns_rootname, &rootzone);
(void)dns_view_findzone(view, dns_rootname, &rootzone);
if (rootzone != NULL) {
dns_zone_detach(&rootzone);
} else {
need_hints = ISC_FALSE;
}
if (need_hints)
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
NS_LOGMODULE_SERVER, ISC_LOG_WARNING,
"no root hints for view '%s'",
view->name);
}
}
/*
......@@ -868,301 +870,6 @@ configure_view(dns_view_t *view, cfg_obj_t *config, cfg_obj_t *vconfig,
return (result);
}
/*
* Create the special view that handles queries under "bind. CH".
*/
static isc_result_t
create_bind_view(dns_view_t **viewp) {
isc_result_t result;
dns_view_t *view = NULL;
REQUIRE(viewp != NULL && *viewp == NULL);
CHECK(dns_view_create(ns_g_mctx, dns_rdataclass_ch, "_bind", &view));
/* Transfer ownership. */
*viewp = view;
view = NULL;
result = ISC_R_SUCCESS;
cleanup:
if (view != NULL)
dns_view_detach(&view);
return (result);
}
/*
* Create the zone that handles queries for "version.bind. CH". The
* version string is returned either from the "version" configuration
* option or the global defaults.
*/
static isc_result_t
create_version_zone(cfg_obj_t **maps, dns_zonemgr_t *zmgr, dns_view_t *view) {
isc_result_t result;
dns_db_t *db = NULL;
dns_zone_t *zone = NULL;
dns_dbversion_t *dbver = NULL;
dns_difftuple_t *tuple = NULL;
dns_diff_t diff;
char *versiontext;
unsigned char buf[256];
isc_region_t r;
size_t len;
dns_rdata_t rdata = DNS_RDATA_INIT;
static unsigned char origindata[] = "\007version\004bind";
dns_name_t origin;
cfg_obj_t *obj = NULL;
dns_diff_init(ns_g_mctx, &diff);
dns_name_init(&origin, NULL);
r.base = origindata;
r.length = sizeof(origindata);
dns_name_fromregion(&origin, &r);
result = ns_config_get(maps, "version", &obj);
INSIST(result == ISC_R_SUCCESS);
if (cfg_obj_isvoid(obj))
return (ISC_R_SUCCESS);
versiontext = cfg_obj_asstring(obj);
len = strlen(versiontext);
if (len > 255)
len = 255; /* Silently truncate. */
buf[0] = len;
memcpy(buf + 1, versiontext, len);
r.base = buf;
r.length = 1 + len;
dns_rdata_fromregion(&rdata, dns_rdataclass_ch, dns_rdatatype_txt, &r);
CHECK(dns_zone_create(&zone, ns_g_mctx));
CHECK(dns_zone_setorigin(zone, &origin));
dns_zone_settype(zone, dns_zone_master);
dns_zone_setclass(zone, dns_rdataclass_ch);
dns_zone_setview(zone, view);
CHECK(dns_zonemgr_managezone(zmgr, zone));
CHECK(dns_db_create(ns_g_mctx, "rbt", &origin, dns_dbtype_zone,
dns_rdataclass_ch, 0, NULL, &db));
CHECK(dns_db_newversion(db, &dbver));
CHECK(dns_difftuple_create(ns_g_mctx, DNS_DIFFOP_ADD, &origin,
0, &rdata, &tuple));
dns_diff_append(&diff, &tuple);
CHECK(dns_diff_apply(&diff, db, dbver));
dns_db_closeversion(db, &dbver, ISC_TRUE);
CHECK(dns_zone_replacedb(zone, db, ISC_FALSE));
CHECK(dns_view_addzone(view, zone));
result = ISC_R_SUCCESS;
cleanup:
if (zone != NULL)
dns_zone_detach(&zone);
if (dbver != NULL)
dns_db_closeversion(db, &dbver, ISC_FALSE);
if (db != NULL)
dns_db_detach(&db);
dns_diff_clear(&diff);
return (result);
}
/*
* Create the zone that handles queries for "hostname.bind. CH". The
* hostname string is returned either from the "hostname" configuration
* option or the the result of gethostbyname().
*/
static isc_result_t
create_hostname_zone(cfg_obj_t **maps, dns_zonemgr_t *zmgr, dns_view_t *view) {
isc_result_t result;
dns_db_t *db = NULL;
dns_zone_t *zone = NULL;
dns_dbversion_t *dbver = NULL;
dns_difftuple_t *tuple = NULL;
dns_diff_t diff;
char *hostnametext;
unsigned char buf[256];
isc_region_t r;
size_t len;
dns_rdata_t rdata = DNS_RDATA_INIT;
static unsigned char origindata[] = "\010hostname\004bind";
dns_name_t origin;
cfg_obj_t *obj = NULL;
dns_name_init(&origin, NULL);
r.base = origindata;
r.length = sizeof(origindata);
dns_name_fromregion(&origin, &r);
result = ns_config_get(maps, "hostname", &obj);
if (result == ISC_R_SUCCESS) {
if (cfg_obj_isvoid(obj))
return (ISC_R_SUCCESS);
hostnametext = cfg_obj_asstring(obj);
len = strlen(hostnametext);
if (len > 255)
len = 255; /* Silently truncate. */
buf[0] = len;
memcpy(buf + 1, hostnametext, len);
} else {
result = ns_os_gethostname((char *)buf + 1, sizeof(buf) - 1);
if (result != ISC_R_SUCCESS)
return (ISC_R_SUCCESS); /* Silent failure */
len = strlen((char *)buf + 1);
buf[0] = len;
}
r.base = buf;
r.length = 1 + len;
dns_rdata_fromregion(&rdata, dns_rdataclass_ch, dns_rdatatype_txt, &r);
dns_diff_init(ns_g_mctx, &diff);
CHECK(dns_zone_create(&zone, ns_g_mctx));
CHECK(dns_zone_setorigin(zone, &origin));
dns_zone_settype(zone, dns_zone_master);
dns_zone_setclass(zone, dns_rdataclass_ch);
dns_zone_setview(zone, view);
CHECK(dns_zonemgr_managezone(zmgr, zone));
CHECK(dns_db_create(ns_g_mctx, "rbt", &origin, dns_dbtype_zone,
dns_rdataclass_ch, 0, NULL, &db));
CHECK(dns_db_newversion(db, &dbver));
CHECK(dns_difftuple_create(ns_g_mctx, DNS_DIFFOP_ADD, &origin,
0, &rdata, &tuple));
dns_diff_append(&diff, &tuple);
CHECK(dns_diff_apply(&diff, db, dbver));
dns_db_closeversion(db, &dbver, ISC_TRUE);
CHECK(dns_zone_replacedb(zone, db, ISC_FALSE));
CHECK(dns_view_addzone(view, zone));
result = ISC_R_SUCCESS;
cleanup:
if (zone != NULL)
dns_zone_detach(&zone);
if (dbver != NULL)
dns_db_closeversion(db, &dbver, ISC_FALSE);
if (db != NULL)
dns_db_detach(&db);
dns_diff_clear(&diff);
return (result);
}
/*
* Create the special zone that handles queries for "authors.bind. CH".
* The strings returned list the BIND 9 authors.
*/
static isc_result_t
create_authors_zone(cfg_obj_t *options, dns_zonemgr_t *zmgr, dns_view_t *view)
{
isc_result_t result;
dns_db_t *db = NULL;
dns_zone_t *zone = NULL;
dns_dbversion_t *dbver = NULL;
dns_difftuple_t *tuple;
dns_diff_t diff;
isc_constregion_t r;
isc_constregion_t cr;
dns_rdata_t rdata = DNS_RDATA_INIT;
static const char origindata[] = "\007authors\004bind";
dns_name_t origin;
int i;
static const char *authors[] = {
"\014Mark Andrews",
"\015James Brister",
"\014Ben Cottrell",
"\015Michael Graff",
"\022Andreas Gustafsson",
"\012Bob Halley",
"\016David Lawrence",
"\013Danny Mayer",
"\013Damien Neil",
"\013Matt Nelson",
"\016Michael Sawyer",
"\020Brian Wellington",
NULL,
};
cfg_obj_t *obj = NULL;
/*
* If a version string is specified, disable the authors.bind zone.
*/
if (<