dlz_ldap_driver.c revision f02b5d87a561ba669bd368a8a6422f364f7702ec
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff/*
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff * Copyright (C) 2002 Stichting NLnet, Netherlands, stichting@nlnet.nl.
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff *
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff * Permission to use, copy, modify, and distribute this software for any
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff * purpose with or without fee is hereby granted, provided that the
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff * above copyright notice and this permission notice appear in all
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff * copies.
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff *
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff * THE SOFTWARE IS PROVIDED "AS IS" AND STICHTING NLNET
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff * STICHTING NLNET BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff * USE OR PERFORMANCE OF THIS SOFTWARE.
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff *
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff * The development of Dynamically Loadable Zones (DLZ) for Bind 9 was
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff * conceived and contributed by Rob Butler.
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff *
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff * Permission to use, copy, modify, and distribute this software for any
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff * purpose with or without fee is hereby granted, provided that the
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff * above copyright notice and this permission notice appear in all
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff * copies.
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff *
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff * THE SOFTWARE IS PROVIDED "AS IS" AND ROB BUTLER
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff * ROB BUTLER BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
0b14ebe3132846e91bea02992493e3d506233e76Michael Graff * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff * USE OR PERFORMANCE OF THIS SOFTWARE.
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff */
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff/*
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff * Copyright (C) 1999-2001 Internet Software Consortium.
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff *
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff * Permission to use, copy, modify, and distribute this software for any
7f1bd55920715d872389194c4201ea95b71378efMichael Graff * purpose with or without fee is hereby granted, provided that the above
7f1bd55920715d872389194c4201ea95b71378efMichael Graff * copyright notice and this permission notice appear in all copies.
7f1bd55920715d872389194c4201ea95b71378efMichael Graff *
7f1bd55920715d872389194c4201ea95b71378efMichael Graff * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
7f1bd55920715d872389194c4201ea95b71378efMichael Graff * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graff * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graff * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff */
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff#ifdef DLZ_LDAP
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graff#include <config.h>
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff#include <stdio.h>
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff#include <string.h>
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graff#include <stdlib.h>
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graff
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff#include <dns/log.h>
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff#include <dns/sdlz.h>
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff#include <dns/result.h>
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff#include <isc/mem.h>
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff#include <isc/platform.h>
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff#include <isc/print.h>
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff#include <isc/result.h>
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff#include <isc/string.h>
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff#include <isc/util.h>
6fe411037dafd168a9f65e6b254c50f3db616688Michael Graff
6fe411037dafd168a9f65e6b254c50f3db616688Michael Graff#include <named/globals.h>
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff#include <dlz/sdlz_helper.h>
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff#include <dlz/dlz_ldap_driver.h>
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff/*
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff * Need older API functions from ldap.h.
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graff */
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff#define LDAP_DEPRECATED 1
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff#include <ldap.h>
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff#define SIMPLE "simple"
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff#define KRB41 "krb41"
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff#define KRB42 "krb42"
6fe411037dafd168a9f65e6b254c50f3db616688Michael Graff#define V2 "v2"
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graff#define V3 "v3"
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graff
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graffstatic dns_sdlzimplementation_t *dlz_ldap = NULL;
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff#define dbc_search_limit 30
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff#define ALLNODES 1
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff#define ALLOWXFR 2
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff#define AUTHORITY 3
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff#define FINDZONE 4
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff#define LOOKUP 5
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff/*%
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff * Structure to hold everthing needed by this "instance" of the LDAP
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff * driver remember, the driver code is only loaded once, but may have
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff * many separate instances.
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff */
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Grafftypedef struct {
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff#ifdef ISC_PLATFORM_USETHREADS
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff db_list_t *db; /*%< handle to a list of DB */
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff#else
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff dbinstance_t *db; /*%< handle to db */
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff#endif
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff int method; /*%< security authentication method */
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff char *user; /*%< who is authenticating */
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff char *cred; /*%< password for simple authentication method */
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff int protocol; /*%< LDAP communication protocol version */
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff char *hosts; /*%< LDAP server hosts */
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff} ldap_instance_t;
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff/* forward references */
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graffstatic isc_result_t
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graffdlz_ldap_findzone(void *driverarg, void *dbdata, const char *name);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graffstatic void
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graffdlz_ldap_destroy(void *driverarg, void *dbdata);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff/*
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff * Private methods
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff */
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff/*% checks that the LDAP URL parameters make sense */
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graffstatic isc_result_t
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graffdlz_ldap_checkURL(char *URL, int attrCnt, const char *msg) {
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff isc_result_t result = ISC_R_SUCCESS;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff int ldap_result;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff LDAPURLDesc *ldap_url = NULL;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff if (!ldap_is_ldap_url(URL)) {
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff "%s query is not a valid LDAP URL", msg);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff result = ISC_R_FAILURE;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff goto cleanup;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff }
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff ldap_result = ldap_url_parse(URL, &ldap_url);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff if (ldap_result != LDAP_SUCCESS || ldap_url == NULL) {
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff "parsing %s query failed", msg);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff result = ISC_R_FAILURE;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff goto cleanup;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff }
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff if (ldap_count_values(ldap_url->lud_attrs) < attrCnt) {
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff "%s query must specify at least "
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff "%d attributes to return",
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff msg, attrCnt);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff result = ISC_R_FAILURE;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff goto cleanup;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff }
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff if (ldap_url->lud_host != NULL) {
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff "%s query must not specify a host", msg);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff result = ISC_R_FAILURE;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff goto cleanup;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff }
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff if (ldap_url->lud_port != 389) {
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff "%s query must not specify a port", msg);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff result = ISC_R_FAILURE;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff goto cleanup;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff }
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff if (ldap_url->lud_dn == NULL || strlen (ldap_url->lud_dn) < 1) {
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff "%s query must specify a search base", msg);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff result = ISC_R_FAILURE;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff goto cleanup;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff }
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff if (ldap_url->lud_exts != NULL || ldap_url->lud_crit_exts != 0) {
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff "%s uses extensions. "
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff "The driver does not support LDAP extensions.",
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff msg);
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff result = ISC_R_FAILURE;
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff goto cleanup;
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff }
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff cleanup:
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff if (ldap_url != NULL)
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff ldap_free_urldesc(ldap_url);
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff return result;
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff}
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff/*% Connects / reconnects to LDAP server */
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff
c16cc434ef385a870bea53eb7ecfea7da8eb562dMichael Graffstatic isc_result_t
c16cc434ef385a870bea53eb7ecfea7da8eb562dMichael Graffdlz_ldap_connect(ldap_instance_t *dbi, dbinstance_t *dbc) {
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff isc_result_t result;
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff int ldap_result;
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff /* if we have a connection, get ride of it. */
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff if (dbc->dbconn != NULL) {
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff ldap_unbind_s((LDAP *) dbc->dbconn);
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff dbc->dbconn = NULL;
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff }
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff
c16cc434ef385a870bea53eb7ecfea7da8eb562dMichael Graff /* now connect / reconnect. */
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff /* initialize. */
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff dbc->dbconn = ldap_init(dbi->hosts, LDAP_PORT);
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff if (dbc->dbconn == NULL)
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff return ISC_R_NOMEMORY;
c16cc434ef385a870bea53eb7ecfea7da8eb562dMichael Graff
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff /* set protocol version. */
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff ldap_result = ldap_set_option((LDAP *) dbc->dbconn,
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff LDAP_OPT_PROTOCOL_VERSION,
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff &(dbi->protocol));
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff if (ldap_result != LDAP_SUCCESS) {
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff result = ISC_R_NOPERM;
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff goto cleanup;
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff }
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff /* "bind" to server. i.e. send username / pass */
11e2a221f173f6bebb1cb4bc634efd40054ed7deMichael Graff ldap_result = ldap_bind_s((LDAP *) dbc->dbconn, dbi->user,
11e2a221f173f6bebb1cb4bc634efd40054ed7deMichael Graff dbi->cred, dbi->method);
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff if (ldap_result != LDAP_SUCCESS) {
58efc48a9623797187726360efb57cbabd916f0dMichael Graff result = ISC_R_FAILURE;
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff goto cleanup;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff }
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff return ISC_R_SUCCESS;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff cleanup:
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff /* cleanup if failure. */
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff if (dbc->dbconn != NULL) {
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff ldap_unbind_s((LDAP *) dbc->dbconn);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff dbc->dbconn = NULL;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff }
6fe411037dafd168a9f65e6b254c50f3db616688Michael Graff
6fe411037dafd168a9f65e6b254c50f3db616688Michael Graff return result;
6fe411037dafd168a9f65e6b254c50f3db616688Michael Graff}
6fe411037dafd168a9f65e6b254c50f3db616688Michael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff#ifdef ISC_PLATFORM_USETHREADS
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff/*%
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff * Properly cleans up a list of database instances.
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff * This function is only used when the driver is compiled for
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff * multithreaded operation.
c16cc434ef385a870bea53eb7ecfea7da8eb562dMichael Graff */
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graffstatic void
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graffldap_destroy_dblist(db_list_t *dblist)
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff{
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff dbinstance_t *ndbi = NULL;
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graff dbinstance_t *dbi = NULL;
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff /* get the first DBI in the list */
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff ndbi = ISC_LIST_HEAD(*dblist);
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graff
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff /* loop through the list */
7f1bd55920715d872389194c4201ea95b71378efMichael Graff while (ndbi != NULL) {
bd7237e653e15bfb7f202a1c0914271912597ef4Michael Graff dbi = ndbi;
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff /* get the next DBI in the list */
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff ndbi = ISC_LIST_NEXT(dbi, link);
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff /* release DB connection */
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graff if (dbi->dbconn != NULL)
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff ldap_unbind_s((LDAP *) dbi->dbconn);
7f1bd55920715d872389194c4201ea95b71378efMichael Graff /* release all memory that comprised a DBI */
7f1bd55920715d872389194c4201ea95b71378efMichael Graff destroy_sqldbinstance(dbi);
7f1bd55920715d872389194c4201ea95b71378efMichael Graff }
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff /* release memory for the list structure */
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff isc_mem_put(ns_g_mctx, dblist, sizeof(db_list_t));
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff}
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff/*%
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff * Loops through the list of DB instances, attempting to lock
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff * on the mutex. If successful, the DBI is reserved for use
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff * and the thread can perform queries against the database.
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff * If the lock fails, the next one in the list is tried.
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff * looping continues until a lock is obtained, or until
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff * the list has been searched dbc_search_limit times.
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff * This function is only used when the driver is compiled for
6fe411037dafd168a9f65e6b254c50f3db616688Michael Graff * multithreaded operation.
6fe411037dafd168a9f65e6b254c50f3db616688Michael Graff */
6fe411037dafd168a9f65e6b254c50f3db616688Michael Graff
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graffstatic dbinstance_t *
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graffldap_find_avail_conn(db_list_t *dblist)
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff{
ef4b66d3557505af25fec8ce461f07ddd671ea1eBob Halley dbinstance_t *dbi = NULL;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff dbinstance_t *head;
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff int count = 0;
ef4b66d3557505af25fec8ce461f07ddd671ea1eBob Halley
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff /* get top of list */
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff head = dbi = ISC_LIST_HEAD(*dblist);
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff /* loop through list */
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff while (count < dbc_search_limit) {
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff /* try to lock on the mutex */
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff if (isc_mutex_trylock(&dbi->instance_lock) == ISC_R_SUCCESS)
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff return dbi; /* success, return the DBI for use. */
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff /* not successful, keep trying */
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff dbi = ISC_LIST_NEXT(dbi, link);
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff /* check to see if we have gone to the top of the list. */
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff if (dbi == NULL) {
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff count++;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff dbi = head;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff }
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff }
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff DNS_LOGMODULE_DLZ, ISC_LOG_INFO,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff "LDAP driver unable to find available connection "
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff "after searching %d times",
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff count);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff return NULL;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff}
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff#endif /* ISC_PLATFORM_USETHREADS */
6fe411037dafd168a9f65e6b254c50f3db616688Michael Graff
6fe411037dafd168a9f65e6b254c50f3db616688Michael Graffstatic isc_result_t
6fe411037dafd168a9f65e6b254c50f3db616688Michael Graffldap_process_results(LDAP *dbc, LDAPMessage *msg, char ** attrs,
7f1bd55920715d872389194c4201ea95b71378efMichael Graff void *ptr, isc_boolean_t allnodes)
7f1bd55920715d872389194c4201ea95b71378efMichael Graff{
7f1bd55920715d872389194c4201ea95b71378efMichael Graff isc_result_t result = ISC_R_SUCCESS;
7f1bd55920715d872389194c4201ea95b71378efMichael Graff int i = 0;
6fe411037dafd168a9f65e6b254c50f3db616688Michael Graff int j;
6fe411037dafd168a9f65e6b254c50f3db616688Michael Graff int len;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff char *attribute = NULL;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff LDAPMessage *entry;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff char *endp = NULL;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff char *host = NULL;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff char *type = NULL;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff char *data = NULL;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff char **vals = NULL;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff int ttl;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff /* make sure there are at least some attributes to process. */
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff REQUIRE(attrs != NULL || attrs[0] != NULL);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff /* get the first entry to process */
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff entry = ldap_first_entry(dbc, msg);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff if (entry == NULL) {
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff DNS_LOGMODULE_DLZ, ISC_LOG_INFO,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff "LDAP no entries to process.");
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff return ISC_R_FAILURE;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff }
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff /* loop through all entries returned */
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff while (entry != NULL) {
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff /* reset for this loop */
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff ttl = 0;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff len = 0;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff i = 0;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff attribute = attrs[i];
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff /* determine how much space we need for data string */
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff for (j=0; attrs[j] != NULL; j++) {
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff /* get the list of values for this attribute. */
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff vals = ldap_get_values(dbc, entry, attrs[j]);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff /* skip empty attributes. */
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff if (vals == NULL || ldap_count_values(vals) < 1)
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff continue;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff /*
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff * we only use the first value. this driver
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff * does not support multi-valued attributes.
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff */
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff len = len + strlen(vals[0]) + 1;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff /* free vals for next loop */
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff ldap_value_free(vals);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff } /* end for (j=0; attrs[j] != NULL, j++) loop */
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff /* allocate memory for data string */
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff data = isc_mem_allocate(ns_g_mctx, len + 1);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff if (data == NULL) {
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff "LDAP driver unable to allocate memory "
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff "while processing results");
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff result = ISC_R_FAILURE;
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff goto cleanup;
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff }
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff /*
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff * Make sure data is null termed at the beginning so
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff * we can check if any data was stored to it later.
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff */
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff data[0] = '\0';
58efc48a9623797187726360efb57cbabd916f0dMichael Graff
58efc48a9623797187726360efb57cbabd916f0dMichael Graff /* reset j to re-use below */
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff j = 0;
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff /* loop through the attributes in the order specified. */
7f1bd55920715d872389194c4201ea95b71378efMichael Graff while (attribute != NULL) {
0b14ebe3132846e91bea02992493e3d506233e76Michael Graff
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff /* get the list of values for this attribute. */
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff vals = ldap_get_values(dbc, entry, attribute);
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff /* skip empty attributes. */
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff if (vals == NULL || vals[0] == NULL) {
0b14ebe3132846e91bea02992493e3d506233e76Michael Graff /* increment attibute pointer */
0b14ebe3132846e91bea02992493e3d506233e76Michael Graff attribute = attrs[++i];
0b14ebe3132846e91bea02992493e3d506233e76Michael Graff /* start loop over */
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff continue;
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff }
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff /*
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff * j initially = 0. Increment j each time we
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff * set a field that way next loop will set
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff * next field.
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff */
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff switch(j) {
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff case 0:
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff j++;
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff /*
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff * convert text to int, make sure it
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff * worked right
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff */
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff ttl = strtol(vals[0], &endp, 10);
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff if (*endp != '\0' || ttl < 0) {
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff isc_log_write(dns_lctx,
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff DNS_LOGCATEGORY_DATABASE,
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff DNS_LOGMODULE_DLZ,
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff ISC_LOG_ERROR,
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff "LDAP driver ttl must "
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graff "be a postive number");
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff goto cleanup;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff }
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff break;
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff case 1:
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff j++;
7f1bd55920715d872389194c4201ea95b71378efMichael Graff type = isc_mem_strdup(ns_g_mctx, vals[0]);
7f1bd55920715d872389194c4201ea95b71378efMichael Graff break;
0b14ebe3132846e91bea02992493e3d506233e76Michael Graff case 2:
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff j++;
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff if (allnodes == isc_boolean_true) {
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff host = isc_mem_strdup(ns_g_mctx,
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff vals[0]);
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff } else {
0b14ebe3132846e91bea02992493e3d506233e76Michael Graff strcpy(data, vals[0]);
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff }
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff break;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff case 3:
7f1bd55920715d872389194c4201ea95b71378efMichael Graff j++;
7f1bd55920715d872389194c4201ea95b71378efMichael Graff if (allnodes == isc_boolean_true) {
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff strcpy(data, vals[0]);
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff } else {
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff strcat(data, " ");
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff strcat(data, vals[0]);
7f1bd55920715d872389194c4201ea95b71378efMichael Graff }
7f1bd55920715d872389194c4201ea95b71378efMichael Graff break;
0b14ebe3132846e91bea02992493e3d506233e76Michael Graff default:
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff strcat(data, " ");
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff strcat(data, vals[0]);
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff break;
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff } /* end switch(j) */
58efc48a9623797187726360efb57cbabd916f0dMichael Graff
58efc48a9623797187726360efb57cbabd916f0dMichael Graff /* free values */
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graff ldap_value_free(vals);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff vals = NULL;
58efc48a9623797187726360efb57cbabd916f0dMichael Graff
58efc48a9623797187726360efb57cbabd916f0dMichael Graff /* increment attibute pointer */
58efc48a9623797187726360efb57cbabd916f0dMichael Graff attribute = attrs[++i];
58efc48a9623797187726360efb57cbabd916f0dMichael Graff } /* end while (attribute != NULL) */
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
58efc48a9623797187726360efb57cbabd916f0dMichael Graff if (type == NULL) {
58efc48a9623797187726360efb57cbabd916f0dMichael Graff isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff "LDAP driver unable "
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff "to retrieve dns type");
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff result = ISC_R_FAILURE;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff goto cleanup;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff }
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graff if (strlen(data) < 1) {
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff "LDAP driver unable "
7f1bd55920715d872389194c4201ea95b71378efMichael Graff "to retrieve dns data");
7f1bd55920715d872389194c4201ea95b71378efMichael Graff result = ISC_R_FAILURE;
c16cc434ef385a870bea53eb7ecfea7da8eb562dMichael Graff goto cleanup;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff }
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff if (allnodes == isc_boolean_true) {
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff if (strcasecmp(host, "~") == 0)
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff result = dns_sdlz_putnamedrr(
58efc48a9623797187726360efb57cbabd916f0dMichael Graff (dns_sdlzallnodes_t *) ptr,
0b14ebe3132846e91bea02992493e3d506233e76Michael Graff "*", type, ttl, data);
0b14ebe3132846e91bea02992493e3d506233e76Michael Graff else
0b14ebe3132846e91bea02992493e3d506233e76Michael Graff result = dns_sdlz_putnamedrr(
0b14ebe3132846e91bea02992493e3d506233e76Michael Graff (dns_sdlzallnodes_t *) ptr,
0b14ebe3132846e91bea02992493e3d506233e76Michael Graff host, type, ttl, data);
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graff if (result != ISC_R_SUCCESS)
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff isc_log_write(dns_lctx,
0b14ebe3132846e91bea02992493e3d506233e76Michael Graff DNS_LOGCATEGORY_DATABASE,
0b14ebe3132846e91bea02992493e3d506233e76Michael Graff DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
0b14ebe3132846e91bea02992493e3d506233e76Michael Graff "dlz-ldap: putnamedrr failed "
0b14ebe3132846e91bea02992493e3d506233e76Michael Graff "for \"%s %s %u %s\", %s",
0b14ebe3132846e91bea02992493e3d506233e76Michael Graff host, type, ttl, data,
0b14ebe3132846e91bea02992493e3d506233e76Michael Graff isc_result_totext(result));
0b14ebe3132846e91bea02992493e3d506233e76Michael Graff } else {
0b14ebe3132846e91bea02992493e3d506233e76Michael Graff result = dns_sdlz_putrr((dns_sdlzlookup_t *) ptr,
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff type, ttl, data);
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff if (result != ISC_R_SUCCESS)
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff isc_log_write(dns_lctx,
58efc48a9623797187726360efb57cbabd916f0dMichael Graff DNS_LOGCATEGORY_DATABASE,
58efc48a9623797187726360efb57cbabd916f0dMichael Graff DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
58efc48a9623797187726360efb57cbabd916f0dMichael Graff "dlz-ldap: putrr failed "
58efc48a9623797187726360efb57cbabd916f0dMichael Graff "for \"%s %u %s\", %s",
58efc48a9623797187726360efb57cbabd916f0dMichael Graff type, ttl, data,
9db3eaed9573b0fdd2109b38261806bde12ff9c3Bob Halley isc_result_totext(result));
58efc48a9623797187726360efb57cbabd916f0dMichael Graff }
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff if (result != ISC_R_SUCCESS) {
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
58efc48a9623797187726360efb57cbabd916f0dMichael Graff DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley "LDAP driver failed "
58efc48a9623797187726360efb57cbabd916f0dMichael Graff "while sending data to BIND.");
0b14ebe3132846e91bea02992493e3d506233e76Michael Graff goto cleanup;
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff }
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graff
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff /* free memory for type, data and host for next loop */
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff isc_mem_free(ns_g_mctx, type);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff isc_mem_free(ns_g_mctx, data);
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff if (host != NULL)
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff isc_mem_free(ns_g_mctx, host);
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff /* get the next entry to process */
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff entry = ldap_next_entry(dbc, entry);
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff } /* end while (entry != NULL) */
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff cleanup:
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff /* de-allocate memory */
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff if (vals != NULL)
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff ldap_value_free(vals);
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff if (host != NULL)
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff isc_mem_free(ns_g_mctx, host);
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff if (type != NULL)
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff isc_mem_free(ns_g_mctx, type);
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff if (data != NULL)
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff isc_mem_free(ns_g_mctx, data);
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff return result;
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff}
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff/*%
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff * This function is the real core of the driver. Zone, record
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff * and client strings are passed in (or NULL is passed if the
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff * string is not available). The type of query we want to run
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff * is indicated by the query flag, and the dbdata object is passed
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff * passed in to. dbdata really holds either:
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff * 1) a list of database instances (in multithreaded mode) OR
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff * 2) a single database instance (in single threaded mode)
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff * The function will construct the query and obtain an available
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff * database instance (DBI). It will then run the query and hopefully
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff * obtain a result set.
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff */
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graffstatic isc_result_t
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graffldap_get_results(const char *zone, const char *record,
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff const char *client, unsigned int query,
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff void *dbdata, void *ptr)
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff{
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff isc_result_t result;
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff dbinstance_t *dbi = NULL;
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff char *querystring = NULL;
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff LDAPURLDesc *ldap_url = NULL;
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff int ldap_result = 0;
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff LDAPMessage *ldap_msg = NULL;
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff int i;
3cd4668988c5bccd59cca899459df4cfa985be67Bob Halley int entries;
3cd4668988c5bccd59cca899459df4cfa985be67Bob Halley
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff /* get db instance / connection */
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff#ifdef ISC_PLATFORM_USETHREADS
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff /* find an available DBI from the list */
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff dbi = ldap_find_avail_conn((db_list_t *)
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff ((ldap_instance_t *)dbdata)->db);
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff#else /* ISC_PLATFORM_USETHREADS */
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff /*
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff * only 1 DBI - no need to lock instance lock either
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff * only 1 thread in the whole process, no possible contention.
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff */
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff dbi = (dbinstance_t *) ((ldap_instance_t *)dbdata)->db;
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff#endif /* ISC_PLATFORM_USETHREADS */
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff /* if DBI is null, can't do anything else */
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff if (dbi == NULL)
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff return ISC_R_FAILURE;
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff /* set fields */
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff if (zone != NULL) {
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff dbi->zone = isc_mem_strdup(ns_g_mctx, zone);
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff if (dbi->zone == NULL) {
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff result = ISC_R_NOMEMORY;
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff goto cleanup;
3cd4668988c5bccd59cca899459df4cfa985be67Bob Halley }
3cd4668988c5bccd59cca899459df4cfa985be67Bob Halley } else {
3cd4668988c5bccd59cca899459df4cfa985be67Bob Halley dbi->zone = NULL;
3cd4668988c5bccd59cca899459df4cfa985be67Bob Halley }
3cd4668988c5bccd59cca899459df4cfa985be67Bob Halley if (record != NULL) {
3cd4668988c5bccd59cca899459df4cfa985be67Bob Halley dbi->record = isc_mem_strdup(ns_g_mctx, record);
3cd4668988c5bccd59cca899459df4cfa985be67Bob Halley if (dbi->record == NULL) {
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff result = ISC_R_NOMEMORY;
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff goto cleanup;
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff }
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff } else {
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff dbi->record = NULL;
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff }
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff if (client != NULL) {
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff dbi->client = isc_mem_strdup(ns_g_mctx, client);
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff if (dbi->client == NULL) {
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff result = ISC_R_NOMEMORY;
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff goto cleanup;
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff }
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff } else {
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff dbi->client = NULL;
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff }
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff /* what type of query are we going to run? */
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff switch(query) {
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff case ALLNODES:
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff /*
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff * if the query was not passed in from the config file
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff * then we can't run it. return not_implemented, so
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff * it's like the code for that operation was never
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff * built into the driver.... AHHH flexibility!!!
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff */
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff if (dbi->allnodes_q == NULL) {
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff result = ISC_R_NOTIMPLEMENTED;
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff goto cleanup;
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff } else {
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff querystring = build_querystring(ns_g_mctx,
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff dbi->allnodes_q);
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff }
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff break;
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff case ALLOWXFR:
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff /* same as comments as ALLNODES */
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff if (dbi->allowxfr_q == NULL) {
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff result = ISC_R_NOTIMPLEMENTED;
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff goto cleanup;
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff } else {
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff querystring = build_querystring(ns_g_mctx,
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff dbi->allowxfr_q);
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff }
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff break;
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff case AUTHORITY:
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff /* same as comments as ALLNODES */
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff if (dbi->authority_q == NULL) {
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff result = ISC_R_NOTIMPLEMENTED;
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff goto cleanup;
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff } else {
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff querystring = build_querystring(ns_g_mctx,
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff dbi->authority_q);
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff }
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff break;
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff case FINDZONE:
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff /* this is required. It's the whole point of DLZ! */
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff if (dbi->findzone_q == NULL) {
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(2),
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff "No query specified for findzone. "
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff "Findzone requires a query");
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff result = ISC_R_FAILURE;
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff goto cleanup;
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff } else {
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff querystring = build_querystring(ns_g_mctx,
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff dbi->findzone_q);
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff }
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff break;
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff case LOOKUP:
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff /* this is required. It's also a major point of DLZ! */
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff if (dbi->lookup_q == NULL) {
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(2),
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff "No query specified for lookup. "
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff "Lookup requires a query");
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff result = ISC_R_FAILURE;
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff goto cleanup;
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff } else {
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff querystring = build_querystring(ns_g_mctx,
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff dbi->lookup_q);
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff }
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff break;
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff default:
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff /*
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff * this should never happen. If it does, the code is
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff * screwed up!
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff */
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff UNEXPECTED_ERROR(__FILE__, __LINE__,
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff "Incorrect query flag passed to "
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff "ldap_get_results");
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff result = ISC_R_UNEXPECTED;
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff goto cleanup;
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley }
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff /* if the querystring is null, Bummer, outta RAM. UPGRADE TIME!!! */
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff if (querystring == NULL) {
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff result = ISC_R_NOMEMORY;
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff goto cleanup;
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff }
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff /*
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff * output the full query string during debug so we can see
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff * what lame error the query has.
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff */
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(1),
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff "\nQuery String: %s\n", querystring);
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff /* break URL down into it's component parts, if error cleanup */
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff ldap_result = ldap_url_parse(querystring, &ldap_url);
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff if (ldap_result != LDAP_SUCCESS || ldap_url == NULL) {
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff result = ISC_R_FAILURE;
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff goto cleanup;
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff }
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff for (i=0; i < 3; i++) {
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff /*
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff * dbi->dbconn may be null if trying to reconnect on a
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff * previous query failed.
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff */
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff if (dbi->dbconn == NULL) {
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff DNS_LOGMODULE_DLZ, ISC_LOG_INFO,
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff "LDAP driver attempting to re-connect");
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff result = dlz_ldap_connect((ldap_instance_t *) dbdata,
6fe411037dafd168a9f65e6b254c50f3db616688Michael Graff dbi);
6fe411037dafd168a9f65e6b254c50f3db616688Michael Graff if (result != ISC_R_SUCCESS) {
0b14ebe3132846e91bea02992493e3d506233e76Michael Graff result = ISC_R_FAILURE;
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff continue;
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff }
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff }
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff /* perform ldap search syncronously */
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff ldap_result = ldap_search_s((LDAP *) dbi->dbconn,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff ldap_url->lud_dn,
ef4b66d3557505af25fec8ce461f07ddd671ea1eBob Halley ldap_url->lud_scope,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff ldap_url->lud_filter,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff ldap_url->lud_attrs, 0, &ldap_msg);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff /*
7f1bd55920715d872389194c4201ea95b71378efMichael Graff * check return code. No such object is ok, just
7f1bd55920715d872389194c4201ea95b71378efMichael Graff * didn't find what we wanted
d524cd03ece72a4db67ec414992c486838732114Michael Graff */
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff switch(ldap_result) {
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff case LDAP_NO_SUCH_OBJECT:
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(1),
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff "No object found matching "
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff "query requirements");
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff result = ISC_R_NOTFOUND;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff goto cleanup;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff break;
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff case LDAP_SUCCESS: /* on success do nothing */
ef4b66d3557505af25fec8ce461f07ddd671ea1eBob Halley result = ISC_R_SUCCESS;
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff i = 3;
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff break;
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff case LDAP_SERVER_DOWN:
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff DNS_LOGMODULE_DLZ, ISC_LOG_INFO,
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff "LDAP driver attempting to re-connect");
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff result = dlz_ldap_connect((ldap_instance_t *) dbdata,
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff dbi);
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff if (result != ISC_R_SUCCESS)
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff result = ISC_R_FAILURE;
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff break;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff default:
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff /*
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff * other errors not ok. Log error message and
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff * get out
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff */
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff "LDAP error: %s",
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff ldap_err2string(ldap_result));
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff result = ISC_R_FAILURE;
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff goto cleanup;
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff break;
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff } /* close switch(ldap_result) */
04135883be6700d7c9f489e4db9cb6c147b064caMichael Graff } /* end for (int i=0 i < 3; i++) */
04135883be6700d7c9f489e4db9cb6c147b064caMichael Graff
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff if (result != ISC_R_SUCCESS)
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff goto cleanup;
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff switch(query) {
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff case ALLNODES:
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff result = ldap_process_results((LDAP *) dbi->dbconn, ldap_msg,
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff ldap_url->lud_attrs,
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff ptr, isc_boolean_true);
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff break;
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff case AUTHORITY:
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff case LOOKUP:
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graff result = ldap_process_results((LDAP *) dbi->dbconn, ldap_msg,
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff ldap_url->lud_attrs,
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff ptr, isc_boolean_false);
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff break;
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff case ALLOWXFR:
ef4b66d3557505af25fec8ce461f07ddd671ea1eBob Halley entries = ldap_count_entries((LDAP *) dbi->dbconn, ldap_msg);
ef4b66d3557505af25fec8ce461f07ddd671ea1eBob Halley if (entries == 0)
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff result = ISC_R_NOPERM;
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff else if (entries > 0)
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff result = ISC_R_SUCCESS;
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff else
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff result = ISC_R_FAILURE;
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff break;
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff case FINDZONE:
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff entries = ldap_count_entries((LDAP *) dbi->dbconn, ldap_msg);
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff if (entries == 0)
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff result = ISC_R_NOTFOUND;
6fe411037dafd168a9f65e6b254c50f3db616688Michael Graff else if (entries > 0)
6fe411037dafd168a9f65e6b254c50f3db616688Michael Graff result = ISC_R_SUCCESS;
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff else
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff result = ISC_R_FAILURE;
ef4b66d3557505af25fec8ce461f07ddd671ea1eBob Halley break;
6fe411037dafd168a9f65e6b254c50f3db616688Michael Graff default:
04135883be6700d7c9f489e4db9cb6c147b064caMichael Graff /*
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff * this should never happen. If it does, the code is
04135883be6700d7c9f489e4db9cb6c147b064caMichael Graff * screwed up!
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff */
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff UNEXPECTED_ERROR(__FILE__, __LINE__,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff "Incorrect query flag passed to "
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff "ldap_get_results");
6fe411037dafd168a9f65e6b254c50f3db616688Michael Graff result = ISC_R_UNEXPECTED;
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graff }
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graff
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff cleanup:
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff /* it's always good to cleanup after yourself */
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff /* if we retrieved results, free them */
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff if (ldap_msg != NULL)
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff ldap_msgfree(ldap_msg);
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff if (ldap_url != NULL)
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff ldap_free_urldesc(ldap_url);
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff /* cleanup */
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff if (dbi->zone != NULL)
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff isc_mem_free(ns_g_mctx, dbi->zone);
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff if (dbi->record != NULL)
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff isc_mem_free(ns_g_mctx, dbi->record);
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff if (dbi->client != NULL)
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff isc_mem_free(ns_g_mctx, dbi->client);
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff#ifdef ISC_PLATFORM_USETHREADS
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff /* release the lock so another thread can use this dbi */
0b14ebe3132846e91bea02992493e3d506233e76Michael Graff isc_mutex_unlock(&dbi->instance_lock);
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff#endif /* ISC_PLATFORM_USETHREADS */
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff /* release query string */
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff if (querystring != NULL)
233f59d93351311880dd40e5a24e19085e5d4002Michael Graff isc_mem_free(ns_g_mctx, querystring );
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff
0b14ebe3132846e91bea02992493e3d506233e76Michael Graff /* return result */
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff return result;
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff}
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff/*
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff * DLZ methods
6fe411037dafd168a9f65e6b254c50f3db616688Michael Graff */
233f59d93351311880dd40e5a24e19085e5d4002Michael Graff
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graffstatic isc_result_t
0b14ebe3132846e91bea02992493e3d506233e76Michael Graffdlz_ldap_allowzonexfr(void *driverarg, void *dbdata, const char *name,
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graff const char *client)
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff{
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff isc_result_t result;
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff UNUSED(driverarg);
233f59d93351311880dd40e5a24e19085e5d4002Michael Graff
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff /* check to see if we are authoritative for the zone first */
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff result = dlz_ldap_findzone(driverarg, dbdata, name);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff if (result != ISC_R_SUCCESS) {
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff return result;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff }
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff /* get all the zone data */
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff return ldap_get_results(name, NULL, client, ALLOWXFR, dbdata, NULL);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff}
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graffstatic isc_result_t
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graffdlz_ldap_allnodes(const char *zone, void *driverarg, void *dbdata,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff dns_sdlzallnodes_t *allnodes)
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff{
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff UNUSED(driverarg);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff return ldap_get_results(zone, NULL, NULL, ALLNODES, dbdata, allnodes);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff}
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graffstatic isc_result_t
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graffdlz_ldap_authority(const char *zone, void *driverarg, void *dbdata,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff dns_sdlzlookup_t *lookup)
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff{
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff UNUSED(driverarg);
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff return ldap_get_results(zone, NULL, NULL, AUTHORITY, dbdata, lookup);
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff}
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graffstatic isc_result_t
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graffdlz_ldap_findzone(void *driverarg, void *dbdata, const char *name)
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff{
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff UNUSED(driverarg);
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff return ldap_get_results(name, NULL, NULL, FINDZONE, dbdata, NULL);
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff}
11e2a221f173f6bebb1cb4bc634efd40054ed7deMichael Graff
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graffstatic isc_result_t
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graffdlz_ldap_lookup(const char *zone, const char *name, void *driverarg,
11e2a221f173f6bebb1cb4bc634efd40054ed7deMichael Graff void *dbdata, dns_sdlzlookup_t *lookup)
11e2a221f173f6bebb1cb4bc634efd40054ed7deMichael Graff{
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff UNUSED(driverarg);
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff if (strcmp(name, "*") == 0)
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff return ldap_get_results(zone, "~", NULL,
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff LOOKUP, dbdata, lookup);
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff else
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff return ldap_get_results(zone, name, NULL,
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff LOOKUP, dbdata, lookup);
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff}
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graffstatic isc_result_t
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graffdlz_ldap_create(const char *dlzname, unsigned int argc, char *argv[],
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff void *driverarg, void **dbdata)
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff{
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graff
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff isc_result_t result;
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graff ldap_instance_t *ldap_inst = NULL;
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graff dbinstance_t *dbi = NULL;
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff int protocol;
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff int method;
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff#ifdef ISC_PLATFORM_USETHREADS
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff /* if multi-threaded, we need a few extra variables. */
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff int dbcount;
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff char *endp;
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff/* db_list_t *dblist = NULL; */
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff int i;
2743e0ce08d1decc963908f024007078d4a553acMichael Graff
2743e0ce08d1decc963908f024007078d4a553acMichael Graff#endif /* ISC_PLATFORM_USETHREADS */
2743e0ce08d1decc963908f024007078d4a553acMichael Graff
2743e0ce08d1decc963908f024007078d4a553acMichael Graff UNUSED(dlzname);
2743e0ce08d1decc963908f024007078d4a553acMichael Graff UNUSED(driverarg);
2743e0ce08d1decc963908f024007078d4a553acMichael Graff
2743e0ce08d1decc963908f024007078d4a553acMichael Graff#ifdef ISC_PLATFORM_USETHREADS
2743e0ce08d1decc963908f024007078d4a553acMichael Graff /* if debugging, let user know we are multithreaded. */
2743e0ce08d1decc963908f024007078d4a553acMichael Graff isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
2743e0ce08d1decc963908f024007078d4a553acMichael Graff DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(1),
2743e0ce08d1decc963908f024007078d4a553acMichael Graff "LDAP driver running multithreaded");
2743e0ce08d1decc963908f024007078d4a553acMichael Graff#else /* ISC_PLATFORM_USETHREADS */
2743e0ce08d1decc963908f024007078d4a553acMichael Graff /* if debugging, let user know we are single threaded. */
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(1),
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff "LDAP driver running single threaded");
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff#endif /* ISC_PLATFORM_USETHREADS */
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff if (argc < 9) {
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff "LDAP driver requires at least "
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff "8 command line args.");
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff return (ISC_R_FAILURE);
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff }
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff /* no more than 13 arg's should be passed to the driver */
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff if (argc > 12) {
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff "LDAP driver cannot accept more than "
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff "11 command line args.");
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff return (ISC_R_FAILURE);
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff }
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff
3cd4668988c5bccd59cca899459df4cfa985be67Bob Halley /* determine protocol version. */
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff if (strncasecmp(argv[2], V2, strlen(V2)) == 0) {
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff protocol = 2;
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff } else if (strncasecmp(argv[2], V3, strlen(V3)) == 0) {
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff protocol = 3;
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff } else {
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff "LDAP driver protocol must be either %s or %s",
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff V2, V3);
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff return (ISC_R_FAILURE);
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graff }
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graff /* determine connection method. */
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff if (strncasecmp(argv[3], SIMPLE, strlen(SIMPLE)) == 0) {
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff method = LDAP_AUTH_SIMPLE;
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff } else if (strncasecmp(argv[3], KRB41, strlen(KRB41)) == 0) {
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff method = LDAP_AUTH_KRBV41;
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff } else if (strncasecmp(argv[3], KRB42, strlen(KRB42)) == 0) {
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff method = LDAP_AUTH_KRBV42;
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff } else {
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff "LDAP driver authentication method must be "
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff "one of %s, %s or %s",
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff SIMPLE, KRB41, KRB42);
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff return (ISC_R_FAILURE);
3446e5e9327ed3595f7a9403f9944666f4820f2aMichael Graff }
3446e5e9327ed3595f7a9403f9944666f4820f2aMichael Graff
3446e5e9327ed3595f7a9403f9944666f4820f2aMichael Graff /* multithreaded build can have multiple DB connections */
3446e5e9327ed3595f7a9403f9944666f4820f2aMichael Graff#ifdef ISC_PLATFORM_USETHREADS
3446e5e9327ed3595f7a9403f9944666f4820f2aMichael Graff
6fe411037dafd168a9f65e6b254c50f3db616688Michael Graff /* check how many db connections we should create */
6fe411037dafd168a9f65e6b254c50f3db616688Michael Graff dbcount = strtol(argv[1], &endp, 10);
04135883be6700d7c9f489e4db9cb6c147b064caMichael Graff if (*endp != '\0' || dbcount < 0) {
6fe411037dafd168a9f65e6b254c50f3db616688Michael Graff isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
6fe411037dafd168a9f65e6b254c50f3db616688Michael Graff DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff "LDAP driver database connection count "
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff "must be positive.");
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff return (ISC_R_FAILURE);
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff }
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff#endif
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff /* check that LDAP URL parameters make sense */
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff switch(argc) {
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff case 12:
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff result = dlz_ldap_checkURL(argv[11], 0, "allow zone transfer");
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff if (result != ISC_R_SUCCESS)
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff return result;
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff case 11:
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff result = dlz_ldap_checkURL(argv[10], 3, "all nodes");
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff if (result != ISC_R_SUCCESS)
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff return result;
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff case 10:
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff if (strlen(argv[9]) > 0) {
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff result = dlz_ldap_checkURL(argv[9], 3, "authority");
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff if (result != ISC_R_SUCCESS)
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff return result;
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff }
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff case 9:
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff result = dlz_ldap_checkURL(argv[8], 3, "lookup");
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff if (result != ISC_R_SUCCESS)
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff return result;
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff result = dlz_ldap_checkURL(argv[7], 0, "find zone");
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff if (result != ISC_R_SUCCESS)
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff return result;
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff break;
11e2a221f173f6bebb1cb4bc634efd40054ed7deMichael Graff default:
11e2a221f173f6bebb1cb4bc634efd40054ed7deMichael Graff /* not really needed, should shut up compiler. */
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff result = ISC_R_FAILURE;
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff }
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff /* allocate memory for LDAP instance */
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graff ldap_inst = isc_mem_get(ns_g_mctx, sizeof(ldap_instance_t));
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff if (ldap_inst == NULL)
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff return (ISC_R_NOMEMORY);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff memset(ldap_inst, 0, sizeof(ldap_instance_t));
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graff
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff /* store info needed to automatically re-connect. */
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff ldap_inst->protocol = protocol;
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff ldap_inst->method = method;
7f1bd55920715d872389194c4201ea95b71378efMichael Graff ldap_inst->hosts = isc_mem_strdup(ns_g_mctx, argv[6]);
c16cc434ef385a870bea53eb7ecfea7da8eb562dMichael Graff if (ldap_inst->hosts == NULL) {
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff result = ISC_R_NOMEMORY;
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff goto cleanup;
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff }
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff ldap_inst->user = isc_mem_strdup(ns_g_mctx, argv[4]);
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff if (ldap_inst->user == NULL) {
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff result = ISC_R_NOMEMORY;
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff goto cleanup;
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff }
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff ldap_inst->cred = isc_mem_strdup(ns_g_mctx, argv[5]);
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff if (ldap_inst->cred == NULL) {
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff result = ISC_R_NOMEMORY;
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graff goto cleanup;
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff }
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graff#ifdef ISC_PLATFORM_USETHREADS
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff /* allocate memory for database connection list */
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff ldap_inst->db = isc_mem_get(ns_g_mctx, sizeof(db_list_t));
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff if (ldap_inst->db == NULL) {
6d58c9b95ec40eb38533061eefab6cb256e870e6Bob Halley result = ISC_R_NOMEMORY;
6d58c9b95ec40eb38533061eefab6cb256e870e6Bob Halley goto cleanup;
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff }
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff /* initialize DB connection list */
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff ISC_LIST_INIT(*(ldap_inst->db));
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff /*
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff * create the appropriate number of database instances (DBI)
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff * append each new DBI to the end of the list
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff */
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff for (i = 0; i < dbcount; i++) {
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff#endif /* ISC_PLATFORM_USETHREADS */
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff /* how many queries were passed in from config file? */
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff switch(argc) {
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff case 9:
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff result = build_sqldbinstance(ns_g_mctx, NULL, NULL,
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff NULL, argv[7], argv[8],
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff NULL, &dbi);
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff break;
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff case 10:
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff result = build_sqldbinstance(ns_g_mctx, NULL, NULL,
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff argv[9], argv[7], argv[8],
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff NULL, &dbi);
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff break;
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff case 11:
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff result = build_sqldbinstance(ns_g_mctx, argv[10], NULL,
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff argv[9], argv[7], argv[8],
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff NULL, &dbi);
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff break;
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff case 12:
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff result = build_sqldbinstance(ns_g_mctx, argv[10],
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff argv[11], argv[9],
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff argv[7], argv[8],
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff NULL, &dbi);
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff break;
6d58c9b95ec40eb38533061eefab6cb256e870e6Bob Halley default:
6d58c9b95ec40eb38533061eefab6cb256e870e6Bob Halley /* not really needed, should shut up compiler. */
6d58c9b95ec40eb38533061eefab6cb256e870e6Bob Halley result = ISC_R_FAILURE;
6d58c9b95ec40eb38533061eefab6cb256e870e6Bob Halley }
6d58c9b95ec40eb38533061eefab6cb256e870e6Bob Halley
6d58c9b95ec40eb38533061eefab6cb256e870e6Bob Halley if (result == ISC_R_SUCCESS) {
6d58c9b95ec40eb38533061eefab6cb256e870e6Bob Halley isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
6d58c9b95ec40eb38533061eefab6cb256e870e6Bob Halley DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(2),
6d58c9b95ec40eb38533061eefab6cb256e870e6Bob Halley "LDAP driver created "
6d58c9b95ec40eb38533061eefab6cb256e870e6Bob Halley "database instance object.");
6d58c9b95ec40eb38533061eefab6cb256e870e6Bob Halley } else { /* unsuccessful?, log err msg and cleanup. */
6d58c9b95ec40eb38533061eefab6cb256e870e6Bob Halley isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
6d58c9b95ec40eb38533061eefab6cb256e870e6Bob Halley DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
6d58c9b95ec40eb38533061eefab6cb256e870e6Bob Halley "LDAP driver could not create "
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff "database instance object.");
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff goto cleanup;
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff }
58efc48a9623797187726360efb57cbabd916f0dMichael Graff
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff#ifdef ISC_PLATFORM_USETHREADS
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff /* when multithreaded, build a list of DBI's */
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff ISC_LINK_INIT(dbi, link);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff ISC_LIST_APPEND(*(ldap_inst->db), dbi, link);
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff#else
6d58c9b95ec40eb38533061eefab6cb256e870e6Bob Halley /*
6d58c9b95ec40eb38533061eefab6cb256e870e6Bob Halley * when single threaded, hold onto the one connection
6d58c9b95ec40eb38533061eefab6cb256e870e6Bob Halley * instance.
6d58c9b95ec40eb38533061eefab6cb256e870e6Bob Halley */
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff ldap_inst->db = dbi;
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff#endif
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff /* attempt to connect */
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff result = dlz_ldap_connect(ldap_inst, dbi);
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff /*
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff * if db connection cannot be created, log err msg and
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff * cleanup.
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff */
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff switch(result) {
6fe411037dafd168a9f65e6b254c50f3db616688Michael Graff /* success, do nothing */
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff case ISC_R_SUCCESS:
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff break;
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff /*
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff * no memory means ldap_init could not
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff * allocate memory
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff */
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff case ISC_R_NOMEMORY:
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff#ifdef ISC_PLATFORM_USETHREADS
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff "LDAP driver could not allocate memory "
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff "for connection number %u",
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff i+1);
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff#else
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graff isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graff "LDAP driver could not allocate memory "
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff "for connection");
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff#endif
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff goto cleanup;
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff break;
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff /*
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff * no perm means ldap_set_option could not set
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff * protocol version
3446e5e9327ed3595f7a9403f9944666f4820f2aMichael Graff */
3446e5e9327ed3595f7a9403f9944666f4820f2aMichael Graff case ISC_R_NOPERM:
3446e5e9327ed3595f7a9403f9944666f4820f2aMichael Graff isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
3446e5e9327ed3595f7a9403f9944666f4820f2aMichael Graff DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
3446e5e9327ed3595f7a9403f9944666f4820f2aMichael Graff "LDAP driver could not "
6fe411037dafd168a9f65e6b254c50f3db616688Michael Graff "set protocol version.");
6fe411037dafd168a9f65e6b254c50f3db616688Michael Graff result = ISC_R_FAILURE;
04135883be6700d7c9f489e4db9cb6c147b064caMichael Graff goto cleanup;
6fe411037dafd168a9f65e6b254c50f3db616688Michael Graff break;
6fe411037dafd168a9f65e6b254c50f3db616688Michael Graff /* failure means couldn't connect to ldap server */
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff case ISC_R_FAILURE:
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff#ifdef ISC_PLATFORM_USETHREADS
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff "LDAP driver could not "
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff "bind connection number %u to server.",
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff i+1);
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff#else
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
11e2a221f173f6bebb1cb4bc634efd40054ed7deMichael Graff "LDAP driver could not "
11e2a221f173f6bebb1cb4bc634efd40054ed7deMichael Graff "bind connection to server.");
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff#endif
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff goto cleanup;
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff break;
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff /*
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff * default should never happen. If it does,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff * major errors.
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graff */
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff default:
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff UNEXPECTED_ERROR(__FILE__, __LINE__,
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff "dlz_ldap_create() failed: %s",
58efc48a9623797187726360efb57cbabd916f0dMichael Graff isc_result_totext(result));
58efc48a9623797187726360efb57cbabd916f0dMichael Graff result = ISC_R_UNEXPECTED;
58efc48a9623797187726360efb57cbabd916f0dMichael Graff goto cleanup;
58efc48a9623797187726360efb57cbabd916f0dMichael Graff break;
58efc48a9623797187726360efb57cbabd916f0dMichael Graff } /* end switch(result) */
58efc48a9623797187726360efb57cbabd916f0dMichael Graff
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff#ifdef ISC_PLATFORM_USETHREADS
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff /* set DBI = null for next loop through. */
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff dbi = NULL;
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff } /* end for loop */
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff#endif /* ISC_PLATFORM_USETHREADS */
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graff /* set dbdata to the ldap_instance we created. */
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff *dbdata = ldap_inst;
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graff /* hey, we got through all of that ok, return success. */
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff return(ISC_R_SUCCESS);
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff
6d58c9b95ec40eb38533061eefab6cb256e870e6Bob Halley cleanup:
6d58c9b95ec40eb38533061eefab6cb256e870e6Bob Halley
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff dlz_ldap_destroy(NULL, ldap_inst);
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff return(ISC_R_FAILURE);
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff}
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graffvoid
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graffdlz_ldap_destroy(void *driverarg, void *dbdata)
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff{
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff UNUSED(driverarg);
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff if (dbdata != NULL) {
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff#ifdef ISC_PLATFORM_USETHREADS
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff /* cleanup the list of DBI's */
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff ldap_destroy_dblist((db_list_t *)
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff ((ldap_instance_t *)dbdata)->db);
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff#else /* ISC_PLATFORM_USETHREADS */
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff /* release connection */
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff if (((ldap_instance_t *)dbdata)->db->dbconn != NULL)
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff ldap_unbind_s((LDAP *)
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff ((ldap_instance_t *)dbdata)->db->dbconn);
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff /* destroy single DB instance */
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff destroy_sqldbinstance(((ldap_instance_t *)dbdata)->db);
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff#endif /* ISC_PLATFORM_USETHREADS */
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff if (((ldap_instance_t *)dbdata)->hosts != NULL)
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff isc_mem_free(ns_g_mctx,
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff ((ldap_instance_t *)dbdata)->hosts);
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff
6d58c9b95ec40eb38533061eefab6cb256e870e6Bob Halley if (((ldap_instance_t *)dbdata)->user != NULL)
6d58c9b95ec40eb38533061eefab6cb256e870e6Bob Halley isc_mem_free(ns_g_mctx,
6d58c9b95ec40eb38533061eefab6cb256e870e6Bob Halley ((ldap_instance_t *)dbdata)->user);
6d58c9b95ec40eb38533061eefab6cb256e870e6Bob Halley
6d58c9b95ec40eb38533061eefab6cb256e870e6Bob Halley if (((ldap_instance_t *)dbdata)->cred != NULL)
6d58c9b95ec40eb38533061eefab6cb256e870e6Bob Halley isc_mem_free(ns_g_mctx,
6d58c9b95ec40eb38533061eefab6cb256e870e6Bob Halley ((ldap_instance_t *)dbdata)->cred);
6d58c9b95ec40eb38533061eefab6cb256e870e6Bob Halley
6d58c9b95ec40eb38533061eefab6cb256e870e6Bob Halley isc_mem_put(ns_g_mctx, dbdata, sizeof(ldap_instance_t));
6d58c9b95ec40eb38533061eefab6cb256e870e6Bob Halley }
6d58c9b95ec40eb38533061eefab6cb256e870e6Bob Halley}
6d58c9b95ec40eb38533061eefab6cb256e870e6Bob Halley
6d58c9b95ec40eb38533061eefab6cb256e870e6Bob Halleystatic dns_sdlzmethods_t dlz_ldap_methods = {
6d58c9b95ec40eb38533061eefab6cb256e870e6Bob Halley dlz_ldap_create,
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff dlz_ldap_destroy,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff dlz_ldap_findzone,
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff dlz_ldap_lookup,
58efc48a9623797187726360efb57cbabd916f0dMichael Graff dlz_ldap_authority,
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff dlz_ldap_allnodes,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff dlz_ldap_allowzonexfr,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff NULL,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff NULL,
6d58c9b95ec40eb38533061eefab6cb256e870e6Bob Halley NULL,
6d58c9b95ec40eb38533061eefab6cb256e870e6Bob Halley NULL,
6d58c9b95ec40eb38533061eefab6cb256e870e6Bob Halley NULL,
6d58c9b95ec40eb38533061eefab6cb256e870e6Bob Halley NULL,
6d58c9b95ec40eb38533061eefab6cb256e870e6Bob Halley NULL,
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff};
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff/*%
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff * Wrapper around dns_sdlzregister().
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff */
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graffisc_result_t
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graffdlz_ldap_init(void) {
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff isc_result_t result;
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff
54a64ec428cb9f783d62a044cbec3a72724a937cMichael Graff /*
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff * Write debugging message to log
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff */
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(2),
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff "Registering DLZ ldap driver.");
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff result = dns_sdlzregister("ldap", &dlz_ldap_methods, NULL,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff DNS_SDLZFLAG_RELATIVEOWNER |
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff DNS_SDLZFLAG_RELATIVERDATA,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff ns_g_mctx, &dlz_ldap);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff if (result != ISC_R_SUCCESS) {
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff UNEXPECTED_ERROR(__FILE__, __LINE__,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff "dns_sdlzregister() failed: %s",
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff isc_result_totext(result));
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff result = ISC_R_UNEXPECTED;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff }
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff return result;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff}
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff/*%
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff * Wrapper around dns_sdlzunregister().
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff */
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graffvoid
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graffdlz_ldap_clear(void) {
58efc48a9623797187726360efb57cbabd916f0dMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff /*
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff * Write debugging message to log
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff */
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(2),
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff "Unregistering DLZ ldap driver.");
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff if (dlz_ldap != NULL)
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff dns_sdlzunregister(&dlz_ldap);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff}
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff#endif
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff