88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews * Copyright (C) 2002 Nuno M. Rodrigues.
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews * Permission to use, copy, modify, and distribute this software for any
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews * purpose with or without fee is hereby granted, provided that the above
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews * copyright notice and this permission notice appear in all copies.
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND NUNO M. RODRIGUES
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt/* $Id: bdb.c,v 1.2 2011/10/11 00:09:02 each Exp $ */
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews * BIND 9.1.x simple database driver
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews * implementation, using Berkeley DB.
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrewsbdb_create(const char *zone, int argc, char **argv,
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews return ISC_R_FAILURE; /* database path must be given */
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews * XXX Should use dns_msgcat et al
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews * but seems to be unavailable.
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews isc_log_iwrite(dns_lctx, DNS_LOGCATEGORY_DATABASE,
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews DNS_LOGMODULE_SDB, ISC_LOG_CRITICAL, isc_msgcat,
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews "db_create");
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews isc_log_iwrite(dns_lctx, DNS_LOGCATEGORY_DATABASE,
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews DNS_LOGMODULE_SDB, ISC_LOG_CRITICAL, isc_msgcat,
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews if ((ret = (*(DB **)dbdata)->open(*(DB **)dbdata, *argv, NULL, DB_HASH,
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews isc_log_iwrite(dns_lctx, DNS_LOGCATEGORY_DATABASE,
793814f80703afdd69b59ade91e63efa81ae4178Evan Huntbdb_lookup(const char *zone, const char *name, void *dbdata,
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt dns_sdblookup_t *l, dns_clientinfomethods_t *methods,
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrewsbdb_lookup(const char *zone, const char *name, void *dbdata,
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt#endif /* DNS_CLIENTINFO_VERSION */
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt#endif /* DNS_CLIENTINFO_VERSION */
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews if ((ret = ((DB *)dbdata)->cursor((DB *)dbdata, NULL, &c, 0)) != 0) {
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews isc_log_iwrite(dns_lctx, DNS_LOGCATEGORY_DATABASE,
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews while (ret == 0) {
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews dns_ttl_fromtext((isc_textregion_t *)&ttltext, &ttl);
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews if (dns_sdb_putrr(l, type, ttl, rdata) != ISC_R_SUCCESS) {
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrewsbdb_allnodes(const char *zone, void *dbdata, dns_sdballnodes_t *n)
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews if ((ret = ((DB *)dbdata)->cursor((DB *)dbdata, NULL, &c, 0)) != 0) {
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews isc_log_iwrite(dns_lctx, DNS_LOGCATEGORY_DATABASE,
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews while (c->c_get(c, &key, &data, DB_NEXT) == 0) {
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews dns_ttl_fromtext((isc_textregion_t *)&ttltext, &ttl);
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews if (dns_sdb_putnamedrr(n, key.data, type, ttl, rdata) !=
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrewsbdb_destroy(const char *zone, void *unused, void **dbdata)