dlz_ldap_driver.c revision 5d35a7a2fbcf6bd060b0ce7deb349e427cb59fc1
a134177ed9f82189504191d90f3ed9e97c2b47cbTinderbox User * Copyright (C) 2002 Stichting NLnet, Netherlands, stichting@nlnet.nl.
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Permission to use, copy, modify, and distribute this software for any
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * purpose with or without fee is hereby granted, provided that the
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * above copyright notice and this permission notice appear in all
28a8f5b0de57d269cf2845c69cb6abe18cbd3b3aMark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND STICHTING NLNET
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
00b872e4f76587584a2359e9001e9cf08b195ccfMark Andrews * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews * STICHTING NLNET BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews * USE OR PERFORMANCE OF THIS SOFTWARE.
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews * The development of Dynamically Loadable Zones (DLZ) for BIND 9 was
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews * conceived and contributed by Rob Butler.
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews * Permission to use, copy, modify, and distribute this software for any
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman * purpose with or without fee is hereby granted, provided that the
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews * above copyright notice and this permission notice appear in all
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND ROB BUTLER
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews * ROB BUTLER BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews * USE OR PERFORMANCE OF THIS SOFTWARE.
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews * Copyright (C) 1999-2001 Internet Software Consortium.
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews * Permission to use, copy, modify, and distribute this software for any
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews * purpose with or without fee is hereby granted, provided that the above
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews * copyright notice and this permission notice appear in all copies.
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews * Need older API functions from ldap.h.
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews * Structure to hold everthing needed by this "instance" of the LDAP
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews * driver remember, the driver code is only loaded once, but may have
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews * many separate instances.
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrewstypedef struct {
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews int method; /*%< security authentication method */
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews char *cred; /*%< password for simple authentication method */
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews int protocol; /*%< LDAP communication protocol version */
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews/* forward references */
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrewsdlz_ldap_findzone(void *driverarg, void *dbdata, const char *name);
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrewsdlz_ldap_destroy(void *driverarg, void *dbdata);
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews * Private methods
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews/*% checks that the LDAP URL parameters make sense */
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrewsdlz_ldap_checkURL(char *URL, int attrCnt, const char *msg) {
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews if (ldap_result != LDAP_SUCCESS || ldap_url == NULL) {
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews if (ldap_count_values(ldap_url->lud_attrs) < attrCnt) {
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews "%s query must specify at least "
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews "%d attributes to return",
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews if (ldap_url->lud_dn == NULL || strlen (ldap_url->lud_dn) < 1) {
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews if (ldap_url->lud_exts != NULL || ldap_url->lud_crit_exts != 0) {
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews "%s uses extensions. "
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews "The driver does not support LDAP extensions.",
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews/*% Connects / reconnects to LDAP server */
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrewsdlz_ldap_connect(ldap_instance_t *dbi, dbinstance_t *dbc) {
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews /* if we have a connection, get ride of it. */
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews /* now connect / reconnect. */
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews /* initialize. */
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews dbc->dbconn = ldap_init(dbi->hosts, LDAP_PORT);
89639a5e13cace9166bf14931b9e1ce9dc8c47a3Mark Andrews /* set protocol version. */
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman ldap_result = ldap_set_option((LDAP *) dbc->dbconn,
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews /* "bind" to server. i.e. send username / pass */
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews ldap_result = ldap_bind_s((LDAP *) dbc->dbconn, dbi->user,
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews /* cleanup if failure. */
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews * Properly cleans up a list of database instances.
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews * This function is only used when the driver is compiled for
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews * multithreaded operation.
static dbinstance_t *
int count = 0;
count++;
count);
return (NULL);
static isc_result_t
int len;
int ttl;
return (ISC_R_FAILURE);
ttl = 0;
len = 0;
goto cleanup;
goto cleanup;
vals[0]);
goto cleanup;
goto cleanup;
goto cleanup;
return (result);
static isc_result_t
int ldap_result = 0;
int entries;
#ifdef ISC_PLATFORM_USETHREADS
return (ISC_R_FAILURE);
goto cleanup;
goto cleanup;
goto cleanup;
switch(query) {
case ALLNODES:
goto cleanup;
case ALLOWXFR:
goto cleanup;
case AUTHORITY:
goto cleanup;
case FINDZONE:
goto cleanup;
case LOOKUP:
goto cleanup;
goto cleanup;
goto cleanup;
goto cleanup;
dbi);
switch(ldap_result) {
case LDAP_NO_SUCH_OBJECT:
goto cleanup;
case LDAP_SERVER_DOWN:
dbi);
goto cleanup;
goto cleanup;
switch(query) {
case ALLNODES:
case AUTHORITY:
case LOOKUP:
case ALLOWXFR:
if (entries == 0)
else if (entries > 0)
case FINDZONE:
if (entries == 0)
else if (entries > 0)
#ifdef ISC_PLATFORM_USETHREADS
return (result);
static isc_result_t
const char *client)
return (result);
return (result);
static isc_result_t
static isc_result_t
static isc_result_t
static isc_result_t
return (result);
static isc_result_t
int protocol;
int method;
#ifdef ISC_PLATFORM_USETHREADS
int dbcount;
char *endp;
#ifdef ISC_PLATFORM_USETHREADS
return (ISC_R_FAILURE);
return (ISC_R_FAILURE);
return (ISC_R_FAILURE);
return (ISC_R_FAILURE);
#ifdef ISC_PLATFORM_USETHREADS
return (ISC_R_FAILURE);
switch(argc) {
return (result);
return (result);
return (result);
return (result);
return (result);
return (ISC_R_NOMEMORY);
goto cleanup;
goto cleanup;
goto cleanup;
#ifdef ISC_PLATFORM_USETHREADS
goto cleanup;
for (i = 0; i < dbcount; i++) {
switch(argc) {
goto cleanup;
#ifdef ISC_PLATFORM_USETHREADS
switch(result) {
case ISC_R_SUCCESS:
case ISC_R_NOMEMORY:
#ifdef ISC_PLATFORM_USETHREADS
goto cleanup;
case ISC_R_NOPERM:
goto cleanup;
case ISC_R_FAILURE:
#ifdef ISC_PLATFORM_USETHREADS
goto cleanup;
goto cleanup;
#ifdef ISC_PLATFORM_USETHREADS
return(ISC_R_SUCCESS);
return(ISC_R_FAILURE);
#ifdef ISC_PLATFORM_USETHREADS
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
dlz_ldap_init(void) {
return (result);
dlz_ldap_clear(void) {