/*
* Copyright (C) 2002 Stichting NLnet, Netherlands, stichting@nlnet.nl.
*
* 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 STICHTING NLNET
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
* STICHTING NLNET 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.
*
* The development of Dynamically Loadable Zones (DLZ) for Bind 9 was
* conceived and contributed by Rob Butler.
*
* 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 ROB BUTLER
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
* ROB BUTLER 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.
*/
/*
* Copyright (C) 1999-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.
*/
#ifdef DLZ_BDB
#include <config.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <dlz/dlz_bdb_driver.h>
#include <db.h>
/* should the bdb driver use threads. */
#ifdef ISC_PLATFORM_USETHREADS
#else
#define bdb_threads 0
#endif
/* BDB database names */
/*%
* This structure contains all the Berkeley DB handles
* for this instance of the BDB driver.
*/
typedef struct bdb_instance {
typedef struct parsed_data {
char *zone;
char *host;
char *type;
int ttl;
char *data;
/* forward reference */
static isc_result_t
/*%
* Parses the DBT from the Berkeley DB into a parsed_data record
* The parsed_data record should be allocated before and passed into the
* bdb_parse_data function. The char (type & data) fields should not
* be "free"d as that memory is part of the DBT data field. It will be
* "free"d when the DBT is freed.
*/
static isc_result_t
/*%
* String should be formated as:
* zone(a space)host(a space)ttl(a space)type(a space)remaining data
* examples:
* example.com www 10 A 127.0.0.1
* example.com mail 10 A 127.0.0.2
* example.com @ 10 MX 20 mail.example.com
*/
/* save pointer to zone */
/* find space after zone and change it to a '\0' */
/* verify we found a space */
return ISC_R_FAILURE;
/* change the space to a null (string terminator) */
tmp[0] = '\0';
/* make sure it is safe to increment pointer */
return ISC_R_FAILURE;
/* save pointer to host */
/* find space after type and change it to a '\0' */
/* verify we found a space */
return ISC_R_FAILURE;
/* change the space to a null (string terminator) */
tmp[0] = '\0';
/* make sure it is safe to increment pointer */
return ISC_R_FAILURE;
/* save pointer to dns type */
/* find space after type and change it to a '\0' */
/* verify we found a space */
return ISC_R_FAILURE;
/* change the space to a null (string terminator) */
tmp[0] = '\0';
/* make sure it is safe to increment pointer */
return ISC_R_FAILURE;
/* save pointer to dns ttl */
/* find space after ttl and change it to a '\0' */
/* verify we found a space */
return ISC_R_FAILURE;
/* change the space to a null (string terminator) */
tmp[0] = '\0';
/* make sure it is safe to increment pointer */
return ISC_R_FAILURE;
/* save pointer to remainder of DNS data */
/* convert ttl string to integer */
"BDB driver ttl must be a postive number");
return ISC_R_FAILURE;
}
/* if we get this far everything should have worked. */
return ISC_R_SUCCESS;
}
/*
* DLZ methods
*/
static isc_result_t
const char *client)
{
/* check to see if we are authoritative for the zone first. */
if (result != ISC_R_SUCCESS)
return (ISC_R_NOTFOUND);
goto xfr_cleanup;
}
goto xfr_cleanup;
}
/* get a cursor to loop through zone data */
goto xfr_cleanup;
}
case DB_NOTFOUND:
case DB_SECONDARY_BAD:
break;
case 0:
break;
default:
}
/* free any memory duplicate string in the key field */
/* free any memory allocated to the data field. */
/* get rid of zone_cursor */
if (client_cursor != NULL)
return result;
}
static isc_result_t
{
int flags;
int bdbres;
return (ISC_R_NOMEMORY);
/* get a cursor to loop through zone data */
goto allnodes_cleanup;
}
flags)) == 0) {
flags = DB_NEXT_DUP;
goto allnodes_cleanup;
goto allnodes_cleanup;
if (result != ISC_R_SUCCESS)
goto allnodes_cleanup;
} /* end while loop */
/* free any memory duplicate string in the key field */
/* get rid of zone_cursor */
if (zone_cursor != NULL)
return result;
}
/*%
* Performs BDB cleanup.
* Used by bdb_create if there is an error starting up.
* Used by bdb_destroy when the driver is shutting down.
*/
static void
/* close databases */
/* close environment */
/* cleanup memory */
/* save mctx for later */
/* return, and detach the memory */
}
}
static isc_result_t
{
return (ISC_R_NOMEMORY);
/* get a cursor to loop through zone data */
goto findzone_cleanup;
}
case DB_NOTFOUND:
case DB_SECONDARY_BAD:
break;
case 0:
break;
default:
}
/* free any memory duplicate string in the key field */
/* free any memory allocated to the data field. */
/* get rid of zone_cursor */
if (zone_cursor != NULL)
return result;
}
static isc_result_t
{
int bdbres;
/* set zone key */
goto lookup_cleanup;
}
/* get a cursor to loop through zone data */
goto lookup_cleanup;
}
/* initialize zone_cursor with zone_key */
goto lookup_cleanup;
}
/* set host key */
goto lookup_cleanup;
}
/* get a cursor to loop through host data */
goto lookup_cleanup;
}
/* initialize host_cursor with host_key */
goto lookup_cleanup;
}
cur_arr[0] = zone_cursor;
&data, 0)) == 0) {
goto lookup_cleanup;
goto lookup_cleanup;
if (result != ISC_R_SUCCESS)
goto lookup_cleanup;
} /* end while loop */
/* get rid of the joined cusor */
if (join_cursor != NULL)
/* get rid of zone_cursor */
if (zone_cursor != NULL)
/* get rid of host_cursor */
if (host_cursor != NULL)
return result;
return ISC_R_NOTFOUND;
}
/*% Initializes, sets flags and then opens Berkeley databases. */
static isc_result_t
int result;
/* Initialize the database. */
"BDB could not initialize %s database. "
"BDB error: %s",
return ISC_R_FAILURE;
}
/* set database flags. */
"BDB could not set flags for %s database. "
"BDB error: %s",
return ISC_R_FAILURE;
}
/* open the database. */
DB_RDONLY | bdb_threads, 0)) != 0) {
"BDB could not open %s database in %s. "
"BDB error: %s",
return ISC_R_FAILURE;
}
return ISC_R_SUCCESS;
}
static isc_result_t
{
int bdbres;
/* verify we have 3 arg's passed to the driver */
if (argc != 3) {
"Berkeley DB driver requires at least "
"2 command line args.");
return (ISC_R_FAILURE);
}
/* allocate and zero memory for driver structure */
"Could not allocate memory for "
"database instance object.");
return (ISC_R_NOMEMORY);
}
/* attach to the memory context */
/* create BDB environment
* Basically BDB allocates and assigns memory to db->dbenv
*/
if (bdbres != 0) {
"BDB environment could not be created. "
"BDB error: %s",
goto init_cleanup;
}
/* open BDB environment */
0);
if (bdbres != 0) {
"BDB environment at '%s' could not be opened. "
"BDB error: %s",
goto init_cleanup;
}
/* open dlz_data database. */
if (result != ISC_R_SUCCESS)
goto init_cleanup;
/* open dlz_host database. */
DB_DUP | DB_DUPSORT);
if (result != ISC_R_SUCCESS)
goto init_cleanup;
/* open dlz_zone database. */
DB_DUP | DB_DUPSORT);
if (result != ISC_R_SUCCESS)
goto init_cleanup;
/* open dlz_client database. */
if (result != ISC_R_SUCCESS)
goto init_cleanup;
/* associate the host secondary database with the primary database */
if (bdbres != 0) {
"BDB could not associate %s database with %s. "
"BDB error: %s",
goto init_cleanup;
}
/* associate the zone secondary database with the primary database */
if (bdbres != 0) {
"BDB could not associate %s database with %s. "
"BDB error: %s",
goto init_cleanup;
}
return(ISC_R_SUCCESS);
return result;
}
static void
{
}
/* bdb_authority not needed as authority data is returned by lookup */
NULL,
};
/*%
* Wrapper around dns_sdlzregister().
*/
dlz_bdb_init(void) {
/*
* Write debugging message to log
*/
"Registering DLZ bdb driver.");
if (result != ISC_R_SUCCESS) {
"dns_sdlzregister() failed: %s",
}
return result;
}
/*%
* Wrapper around dns_sdlzunregister().
*/
void
dlz_bdb_clear(void) {
/*
* Write debugging message to log
*/
"Unregistering DLZ bdb driver.");
}
#endif