diff -Nur bind-9.1.3.orig/bin/named/Makefile.in bind-9.1.3/bin/named/Makefile.in --- bind-9.1.3.orig/bin/named/Makefile.in Tue Jul 3 20:38:58 2001 +++ bind-9.1.3/bin/named/Makefile.in Mon Mar 4 01:19:24 2002 @@ -26,10 +26,10 @@ # # Add database drivers here. # -DBDRIVER_OBJS = -DBDRIVER_SRCS = -DBDRIVER_INCLUDES = -DBDRIVER_LIBS = +DBDRIVER_OBJS = hashdb.o +DBDRIVER_SRCS = hashdb.c +DBDRIVER_INCLUDES = hashdb.h +DBDRIVER_LIBS = -lcrypto CINCLUDES = -I${srcdir}/include -I${srcdir}/unix/include \ ${LWRES_INCLUDES} ${DNS_INCLUDES} ${ISC_INCLUDES} \ diff -Nur bind-9.1.3.orig/bin/named/hashdb.c bind-9.1.3/bin/named/hashdb.c --- bind-9.1.3.orig/bin/named/hashdb.c Thu Jan 1 01:00:00 1970 +++ bind-9.1.3/bin/named/hashdb.c Sat Mar 9 14:22:36 2002 @@ -0,0 +1,213 @@ +/* + * Copyright (C) 2000, 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. + */ + + + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +#include + +#include + +#include "hashdb.h" + +void sha1hex (const char* in, char* out); + +static isc_result_t hashdb_create(const char *zone, int argc, char **argv, void *driverdata, void **dbdata); + +typedef struct { + char* suffix; + int suffix_len; + char* secret; + int secret_len; +} dr_t; + +static dr_t *dr; +static dns_sdbimplementation_t *hashdb = NULL; + +void sha1hex (const char* in, char* out) +{ + unsigned char hash[20]; + unsigned int i; + char a[3]; + + SHA1(in, strlen(in), hash); + for (i = 0; i<20; i++) { + sprintf (a, "%02x", (unsigned int) hash[i]); + strcat (out, a); + } +} + + +/* + * This database operates on relative names. + */ +static isc_result_t +hashdb_lookup(const char *zone, const char *name, void *dbdata, + dns_sdblookup_t *lookup) +{ + isc_result_t result; + char *hname; + dr_t *blah; + int hlen; + char b[41]; + UNUSED(zone); + + bzero (b, 41); + blah = (dr_t*) dbdata; + isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL, + DNS_LOGMODULE_SDB, ISC_LOG_INFO, + "hashdb_lookup: blah->suffix is %s\n", blah->suffix); + + hlen = (40 + blah->suffix_len + 1); + hname = isc_mem_get(ns_g_mctx, hlen); + if (hname == NULL) + return (ISC_R_NOMEMORY); + bzero (hname, hlen); + isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL, + DNS_LOGMODULE_SDB, ISC_LOG_INFO, + "hashdb_lookup: asked for %s\n", name); + if (blah->secret != NULL) { + strncat(name, blah->secret, blah->secret_len); + isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL, + DNS_LOGMODULE_SDB, ISC_LOG_INFO, + "hashdb_lookup: secret is %s\n", blah->secret); + } + sha1hex(name, b); + strncat(hname, b, 41); + strncat(hname, blah->suffix, blah->suffix_len); + isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL, + DNS_LOGMODULE_SDB, ISC_LOG_INFO, + "hashdb_lookup: created answer %s\n", hname); + result = dns_sdb_putrr(lookup, "cname", 120, hname ); + if (result != ISC_R_SUCCESS) { + isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL, + DNS_LOGMODULE_SDB, ISC_LOG_ERROR, + "hashdb_lookup: unable to putrr cname %s", hname); + return (ISC_R_FAILURE); + } + return (ISC_R_SUCCESS); +} + +/* + * lookup() does not return SOA or NS records, so authority() must be defined. + */ +static isc_result_t +hashdb_authority(const char *zone, void *dbdata, dns_sdblookup_t *lookup) { + isc_result_t result; + + UNUSED(zone); + UNUSED(dbdata); + + result = dns_sdb_putsoa(lookup, "localhost.", "root.localhost.", 0); + if (result != ISC_R_SUCCESS) + return (ISC_R_FAILURE); + + result = dns_sdb_putrr(lookup, "ns", 86400, "ns1.localdomain."); + if (result != ISC_R_SUCCESS) + return (ISC_R_FAILURE); + result = dns_sdb_putrr(lookup, "ns", 86400, "ns2.localdomain."); + if (result != ISC_R_SUCCESS) + return (ISC_R_FAILURE); + + return (ISC_R_SUCCESS); +} + +/* + * This zone does not support zone transfer, so allnodes() is NULL. There + * is no database specific data, so create() and destroy() are NULL. + */ +static dns_sdbmethods_t hashdb_methods = { + hashdb_lookup, + hashdb_authority, + NULL, /* allnodes */ + hashdb_create, /* create */ + NULL /* destroy */ +}; + +/* + * Wrapper around dns_sdb_register(). + */ +isc_result_t +hashdb_init(void) { + unsigned int flags; + flags = 0; + isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL, + DNS_LOGMODULE_SDB, ISC_LOG_INFO, + "hashdb_init called\n"); + return (dns_sdb_register("hash", &hashdb_methods, NULL, flags, + ns_g_mctx, &hashdb)); +} + +/* + * hasdb_create gets passed its arguments from the config file + */ + +static isc_result_t +hashdb_create(const char *zone, int argc, char **argv, + void *driverdata, void **dbdata) +{ + dr_t *blah; + UNUSED(driverdata); + UNUSED(zone); + blah = (dr_t*) malloc (sizeof(dr_t)); + isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL, + DNS_LOGMODULE_SDB, ISC_LOG_INFO, + "hashdb_create: called with argc=%d\n argv[0]=%s\n", argc, argv[0]); + if (argc < 1) + return (ISC_R_FAILURE); + blah->suffix = isc_mem_strdup(ns_g_mctx, argv[0]); + blah->suffix_len = strlen(argv[0]); + isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL, + DNS_LOGMODULE_SDB, ISC_LOG_INFO, + "hashdb_create: suffix is %s\n", blah->suffix); + if (argc == 2) { + isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL, + DNS_LOGMODULE_SDB, ISC_LOG_INFO, + "hashdb_create: secret is %s\n", argv[1]); + blah->secret = argv[1]; + blah->secret_len = strlen(argv[1]); + } else { + blah->secret = NULL; + } + *dbdata = blah; + return (ISC_R_SUCCESS); +} + +/* + * Wrapper around dns_sdb_unregister(). + */ +void +hashdb_clear(void) { + isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL, + DNS_LOGMODULE_SDB, ISC_LOG_INFO, + "hashdb_clear called\n"); + if (hashdb != NULL) + dns_sdb_unregister(&hashdb); +} diff -Nur bind-9.1.3.orig/bin/named/hashdb.h bind-9.1.3/bin/named/hashdb.h --- bind-9.1.3.orig/bin/named/hashdb.h Thu Jan 1 01:00:00 1970 +++ bind-9.1.3/bin/named/hashdb.h Sat Mar 9 14:05:51 2002 @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2000, 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: hashdb.h,v 1.1 2002/03/05 11:45:15 bauerm Exp $ */ + +#include + +isc_result_t hashdb_init(void); + +void hashdb_clear(void); + diff -Nur bind-9.1.3.orig/bin/named/include/hashdb.h bind-9.1.3/bin/named/include/hashdb.h --- bind-9.1.3.orig/bin/named/include/hashdb.h Thu Jan 1 01:00:00 1970 +++ bind-9.1.3/bin/named/include/hashdb.h Sat Mar 9 14:05:33 2002 @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2000, 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: hashdb.h,v 1.1 2002/03/05 11:45:15 bauerm Exp $ */ + +#include + +isc_result_t hashdb_init(void); + +void hashdb_clear(void); + diff -Nur bind-9.1.3.orig/bin/named/main.c bind-9.1.3/bin/named/main.c --- bind-9.1.3.orig/bin/named/main.c Tue Jul 3 20:39:04 2001 +++ bind-9.1.3/bin/named/main.c Mon Mar 18 16:37:54 2002 @@ -54,7 +54,7 @@ /* * Include header files for database drivers here. */ -/* #include "xxdb.h" */ +#include "hashdb.h" static isc_boolean_t want_stats = ISC_FALSE; static const char * program_name = "named"; @@ -495,6 +495,10 @@ * Add calls to register sdb drivers here. */ /* xxdb_init(); */ + result = hashdb_init(); + if (result != ISC_R_SUCCESS) + ns_main_earlyfatal("hashdb_init() failed: %s", + isc_result_totext(result)); ns_server_create(ns_g_mctx, &ns_g_server); @@ -515,7 +519,7 @@ /* * Add calls to unregister sdb drivers here. */ - /* xxdb_clear(); */ + hashdb_clear(); isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, ISC_LOG_NOTICE, "exiting");