builtin.c revision dc4fa197dd1031b3c966e5ee9d69a0f49ae1d9ce
/*
* Copyright (C) 2004, 2005, 2007, 2009, 2010 Internet Systems Consortium, Inc. ("ISC")
* Copyright (C) 2001-2003 Internet Software Consortium.
*
* 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 ISC DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL ISC 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.18 2011/01/07 04:31:38 marka Exp $ */
/*! \file
* \brief
* The built-in "version", "hostname", "id", "authors" and "empty" databases.
*/
#include <config.h>
#include <string.h>
#include <stdio.h>
/*
* 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 {
char *server;
char *contact;
};
static dns_sdbimplementation_t *builtin_impl;
static const char hex[] = "0123456789abcdef";
static const char HEX[] = "0123456789ABCDEF";
static isc_result_t
const char *s;
unsigned char v[16];
unsigned int i;
char reverse[sizeof("123.123.123.123.in-addr.arpa.")];
/*
* The sum the length of the relative name and the length of the zone
* name for a IPv6 reverse lookup comes to 71.
*
* The reverse of 2001::10.0.0.1 (dns64 2001::/96) has a zone of
* "0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1.0.0.2.ip6.arpa"
* and a name of "1.0.0.0.0.0.a.0". The sum of the lengths of these
* two strings is 71.
*
* The minimum length for a ip6.arpa zone name is 8.
*
* The length of name should always be odd as we are expecting
* a series of nibbles.
*/
return (ISC_R_NOTFOUND);
/*
* We assume the zone name is well formed.
*/
/*
* XXXMPA We could check the dns64 suffix here if we need to.
*/
/*
* Check that name is a series of nibbles.
* Compute the byte values that correspond to the nibbles as we go.
*
* Shift the final result 4 bits, by setting 'i' to 1, if we if we
* have a odd number of nibbles so that "must be zero" tests below
* are byte aligned and we correctly return ISC_R_NOTFOUND or
* ISC_R_SUCCESS. We will not generate a CNAME in this case.
*/
j = nlen;
memset(v, 0, sizeof(v));
while (j >= 1) {
INSIST((i/2) < sizeof(v));
return (ISC_R_NOTFOUND);
v[i/2] >>= 4;
else
return (ISC_R_NOTFOUND);
if (j > 1)
j -= 2;
else
j -= 1;
name += 2;
i++;
}
/*
* If we get here then we know name only consisted of nibbles.
* Now we need to determine if the name exists or not and whether
* it corresponds to a empty node in the zone or there should be
* a CNAME.
*/
switch (zlen) {
case 24: /* prefix len 32 */
/*
* If the total length is not 71 then this is a empty node
* so return success.
*/
return (ISC_R_SUCCESS);
v[8], v[9], v[10], v[11]);
break;
case 28: /* prefix len 40 */
/*
* The nibbles that map to this byte must be zero for 'name'
* to exist in the zone.
*/
return (ISC_R_NOTFOUND);
/*
* If the total length is not 71 then this is a empty node
* so return success.
*/
return (ISC_R_SUCCESS);
v[6], v[8], v[9], v[10]);
break;
case 32: /* prefix len 48 */
/*
* The nibbles that map to this byte must be zero for 'name'
* to exist in the zone.
*/
return (ISC_R_NOTFOUND);
/*
* If the total length is not 71 then this is a empty node
* so return success.
*/
return (ISC_R_SUCCESS);
v[5], v[6], v[8], v[9]);
break;
case 36: /* prefix len 56 */
/*
* The nibbles that map to this byte must be zero for 'name'
* to exist in the zone.
*/
return (ISC_R_NOTFOUND);
/*
* If the total length is not 71 then this is a empty node
* so return success.
*/
return (ISC_R_SUCCESS);
v[4], v[5], v[6], v[8]);
break;
case 40: /* prefix len 64 */
/*
* The nibbles that map to this byte must be zero for 'name'
* to exist in the zone.
*/
if (v[nlen/4] != 0)
return (ISC_R_NOTFOUND);
/*
* If the total length is not 71 then this is a empty node
* so return success.
*/
return (ISC_R_SUCCESS);
v[3], v[4], v[5], v[6]);
break;
case 56: /* prefix len 96 */
/*
* If the total length is not 71 then this is a empty node
* so return success.
*/
return (ISC_R_SUCCESS);
v[0], v[1], v[2], v[3]);
break;
default:
/*
* This should never be reached unless someone adds a
* zone declaration with this internal type to named.conf.
*/
return (ISC_R_NOTFOUND);
}
}
static isc_result_t
{
else if (b->do_lookup == do_dns64_lookup)
else
return (ISC_R_NOTFOUND);
}
static isc_result_t
unsigned char buf[256];
if (len > 255)
}
static isc_result_t
if (ns_g_server->version_set) {
return (ISC_R_SUCCESS);
else
} else {
}
}
static isc_result_t
if (ns_g_server->hostname_set) {
return (ISC_R_SUCCESS);
else
} else {
char buf[256];
if (result != ISC_R_SUCCESS)
return (result);
}
}
static isc_result_t
const char **p;
static const char *authors[] = {
"Mark Andrews",
"James Brister",
"Ben Cottrell",
"Michael Graff",
"Andreas Gustafsson",
"Bob Halley",
"Evan Hunt",
"JINMEI Tatuya",
"David Lawrence",
"Danny Mayer",
"Damien Neil",
"Matt Nelson",
"Jeremy C. Reed",
"Michael Sawyer",
"Brian Wellington",
};
/*
* If a version string is specified, disable the authors.bind zone.
*/
if (ns_g_server->version_set)
return (ISC_R_SUCCESS);
if (result != ISC_R_SUCCESS)
return (result);
}
return (ISC_R_SUCCESS);
}
static isc_result_t
if (ns_g_server->server_usehostname) {
char buf[256];
if (result != ISC_R_SUCCESS)
return (result);
}
return (ISC_R_SUCCESS);
else
}
static isc_result_t
return (ISC_R_SUCCESS);
}
static isc_result_t
return (ISC_R_SUCCESS);
}
static isc_result_t
const char *contact = "hostmaster";
const char *server = "@";
if (b == &empty_builtin) {
server = ".";
contact = ".";
} else {
}
if (result != ISC_R_SUCCESS)
return (ISC_R_FAILURE);
if (result != ISC_R_SUCCESS)
return (ISC_R_FAILURE);
return (ISC_R_SUCCESS);
}
static isc_result_t
void *driverdata, void **dbdata)
{
if (argc != 3)
return (DNS_R_SYNTAX);
} else if (argc != 1)
return (DNS_R_SYNTAX);
*dbdata = &version_builtin;
*dbdata = &hostname_builtin;
*dbdata = &authors_builtin;
*dbdata = &id_builtin;
char *server;
char *contact;
/*
* We don't want built-in zones to fail. Fallback to
* the static configuration if memory allocation fails.
*/
*dbdata = &empty_builtin;
else
*dbdata = &dns64_builtin;
} else {
sizeof (empty_builtin));
else
sizeof (empty_builtin));
}
} else
return (ISC_R_NOTIMPLEMENTED);
return (ISC_R_SUCCESS);
}
static void
/*
* Don't free the static versions.
*/
return;
isc_mem_put(ns_g_mctx, b, sizeof (*b));
}
static dns_sdbmethods_t builtin_methods = {
NULL, /* allnodes */
};
ns_builtin_init(void) {
== ISC_R_SUCCESS);
return (ISC_R_SUCCESS);
}
void
ns_builtin_deinit(void) {
}