2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-30 14:07:59 +00:00

Style cleanup in DLZ LDAP driver. No functional change, no CHANGES note.

This commit is contained in:
Evan Hunt 2011-03-07 22:01:05 +00:00
parent c85677097d
commit 5d35a7a2fb

View File

@ -15,7 +15,7 @@
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
* USE OR PERFORMANCE OF THIS SOFTWARE. * USE OR PERFORMANCE OF THIS SOFTWARE.
* *
* The development of Dynamically Loadable Zones (DLZ) for Bind 9 was * The development of Dynamically Loadable Zones (DLZ) for BIND 9 was
* conceived and contributed by Rob Butler. * conceived and contributed by Rob Butler.
* *
* Permission to use, copy, modify, and distribute this software for any * Permission to use, copy, modify, and distribute this software for any
@ -102,7 +102,6 @@ static dns_sdlzimplementation_t *dlz_ldap = NULL;
*/ */
typedef struct { typedef struct {
#ifdef ISC_PLATFORM_USETHREADS #ifdef ISC_PLATFORM_USETHREADS
db_list_t *db; /*%< handle to a list of DB */ db_list_t *db; /*%< handle to a list of DB */
#else #else
@ -113,7 +112,6 @@ typedef struct {
char *cred; /*%< password for simple authentication method */ char *cred; /*%< password for simple authentication method */
int protocol; /*%< LDAP communication protocol version */ int protocol; /*%< LDAP communication protocol version */
char *hosts; /*%< LDAP server hosts */ char *hosts; /*%< LDAP server hosts */
} ldap_instance_t; } ldap_instance_t;
/* forward references */ /* forward references */
@ -129,10 +127,8 @@ dlz_ldap_destroy(void *driverarg, void *dbdata);
*/ */
/*% checks that the LDAP URL parameters make sense */ /*% checks that the LDAP URL parameters make sense */
static isc_result_t static isc_result_t
dlz_ldap_checkURL(char *URL, int attrCnt, const char *msg) { dlz_ldap_checkURL(char *URL, int attrCnt, const char *msg) {
isc_result_t result = ISC_R_SUCCESS; isc_result_t result = ISC_R_SUCCESS;
int ldap_result; int ldap_result;
LDAPURLDesc *ldap_url = NULL; LDAPURLDesc *ldap_url = NULL;
@ -199,17 +195,15 @@ dlz_ldap_checkURL(char *URL, int attrCnt, const char *msg) {
} }
cleanup: cleanup:
if (ldap_url != NULL) if (ldap_url != NULL)
ldap_free_urldesc(ldap_url); ldap_free_urldesc(ldap_url);
return result; return (result);
} }
/*% Connects / reconnects to LDAP server */
/*% Connects / reconnects to LDAP server */
static isc_result_t static isc_result_t
dlz_ldap_connect(ldap_instance_t *dbi, dbinstance_t *dbc) { dlz_ldap_connect(ldap_instance_t *dbi, dbinstance_t *dbc) {
isc_result_t result; isc_result_t result;
int ldap_result; int ldap_result;
@ -224,7 +218,7 @@ dlz_ldap_connect(ldap_instance_t *dbi, dbinstance_t *dbc) {
/* initialize. */ /* initialize. */
dbc->dbconn = ldap_init(dbi->hosts, LDAP_PORT); dbc->dbconn = ldap_init(dbi->hosts, LDAP_PORT);
if (dbc->dbconn == NULL) if (dbc->dbconn == NULL)
return ISC_R_NOMEMORY; return (ISC_R_NOMEMORY);
/* set protocol version. */ /* set protocol version. */
ldap_result = ldap_set_option((LDAP *) dbc->dbconn, ldap_result = ldap_set_option((LDAP *) dbc->dbconn,
@ -243,7 +237,7 @@ dlz_ldap_connect(ldap_instance_t *dbi, dbinstance_t *dbc) {
goto cleanup; goto cleanup;
} }
return ISC_R_SUCCESS; return (ISC_R_SUCCESS);
cleanup: cleanup:
@ -253,7 +247,7 @@ dlz_ldap_connect(ldap_instance_t *dbi, dbinstance_t *dbc) {
dbc->dbconn = NULL; dbc->dbconn = NULL;
} }
return result; return (result);
} }
#ifdef ISC_PLATFORM_USETHREADS #ifdef ISC_PLATFORM_USETHREADS
@ -265,9 +259,7 @@ dlz_ldap_connect(ldap_instance_t *dbi, dbinstance_t *dbc) {
* multithreaded operation. * multithreaded operation.
*/ */
static void static void
ldap_destroy_dblist(db_list_t *dblist) ldap_destroy_dblist(db_list_t *dblist) {
{
dbinstance_t *ndbi = NULL; dbinstance_t *ndbi = NULL;
dbinstance_t *dbi = NULL; dbinstance_t *dbi = NULL;
@ -299,10 +291,8 @@ ldap_destroy_dblist(db_list_t *dblist)
* This function is only used when the driver is compiled for * This function is only used when the driver is compiled for
* multithreaded operation. * multithreaded operation.
*/ */
static dbinstance_t * static dbinstance_t *
ldap_find_avail_conn(db_list_t *dblist) ldap_find_avail_conn(db_list_t *dblist) {
{
dbinstance_t *dbi = NULL; dbinstance_t *dbi = NULL;
dbinstance_t *head; dbinstance_t *head;
int count = 0; int count = 0;
@ -314,7 +304,7 @@ ldap_find_avail_conn(db_list_t *dblist)
while (count < dbc_search_limit) { while (count < dbc_search_limit) {
/* try to lock on the mutex */ /* try to lock on the mutex */
if (isc_mutex_trylock(&dbi->instance_lock) == ISC_R_SUCCESS) if (isc_mutex_trylock(&dbi->instance_lock) == ISC_R_SUCCESS)
return dbi; /* success, return the DBI for use. */ return (dbi); /* success, return the DBI for use. */
/* not successful, keep trying */ /* not successful, keep trying */
dbi = ISC_LIST_NEXT(dbi, link); dbi = ISC_LIST_NEXT(dbi, link);
@ -330,9 +320,8 @@ ldap_find_avail_conn(db_list_t *dblist)
"LDAP driver unable to find available connection " "LDAP driver unable to find available connection "
"after searching %d times", "after searching %d times",
count); count);
return NULL; return (NULL);
} }
#endif /* ISC_PLATFORM_USETHREADS */ #endif /* ISC_PLATFORM_USETHREADS */
static isc_result_t static isc_result_t
@ -361,12 +350,11 @@ ldap_process_results(LDAP *dbc, LDAPMessage *msg, char ** attrs,
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_INFO, DNS_LOGMODULE_DLZ, ISC_LOG_INFO,
"LDAP no entries to process."); "LDAP no entries to process.");
return ISC_R_FAILURE; return (ISC_R_FAILURE);
} }
/* loop through all entries returned */ /* loop through all entries returned */
while (entry != NULL) { while (entry != NULL) {
/* reset for this loop */ /* reset for this loop */
ttl = 0; ttl = 0;
len = 0; len = 0;
@ -374,7 +362,7 @@ ldap_process_results(LDAP *dbc, LDAPMessage *msg, char ** attrs,
attribute = attrs[i]; attribute = attrs[i];
/* determine how much space we need for data string */ /* determine how much space we need for data string */
for (j=0; attrs[j] != NULL; j++) { for (j = 0; attrs[j] != NULL; j++) {
/* get the list of values for this attribute. */ /* get the list of values for this attribute. */
vals = ldap_get_values(dbc, entry, attrs[j]); vals = ldap_get_values(dbc, entry, attrs[j]);
/* skip empty attributes. */ /* skip empty attributes. */
@ -387,7 +375,7 @@ ldap_process_results(LDAP *dbc, LDAPMessage *msg, char ** attrs,
len = len + strlen(vals[0]) + 1; len = len + strlen(vals[0]) + 1;
/* free vals for next loop */ /* free vals for next loop */
ldap_value_free(vals); ldap_value_free(vals);
} /* end for (j=0; attrs[j] != NULL, j++) loop */ } /* end for (j = 0; attrs[j] != NULL, j++) loop */
/* allocate memory for data string */ /* allocate memory for data string */
data = isc_mem_allocate(ns_g_mctx, len + 1); data = isc_mem_allocate(ns_g_mctx, len + 1);
@ -411,7 +399,6 @@ ldap_process_results(LDAP *dbc, LDAPMessage *msg, char ** attrs,
/* loop through the attributes in the order specified. */ /* loop through the attributes in the order specified. */
while (attribute != NULL) { while (attribute != NULL) {
/* get the list of values for this attribute. */ /* get the list of values for this attribute. */
vals = ldap_get_values(dbc, entry, attribute); vals = ldap_get_values(dbc, entry, attribute);
@ -486,18 +473,20 @@ ldap_process_results(LDAP *dbc, LDAPMessage *msg, char ** attrs,
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"LDAP driver unable " "LDAP driver unable "
"to retrieve dns type"); "to retrieve DNS type");
result = ISC_R_FAILURE; result = ISC_R_FAILURE;
goto cleanup; goto cleanup;
} }
if (strlen(data) < 1) { if (strlen(data) < 1) {
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"LDAP driver unable " "LDAP driver unable "
"to retrieve dns data"); "to retrieve DNS data");
result = ISC_R_FAILURE; result = ISC_R_FAILURE;
goto cleanup; goto cleanup;
} }
if (allnodes == isc_boolean_true) { if (allnodes == isc_boolean_true) {
if (strcasecmp(host, "~") == 0) if (strcasecmp(host, "~") == 0)
result = dns_sdlz_putnamedrr( result = dns_sdlz_putnamedrr(
@ -547,7 +536,6 @@ ldap_process_results(LDAP *dbc, LDAPMessage *msg, char ** attrs,
} /* end while (entry != NULL) */ } /* end while (entry != NULL) */
cleanup: cleanup:
/* de-allocate memory */ /* de-allocate memory */
if (vals != NULL) if (vals != NULL)
ldap_value_free(vals); ldap_value_free(vals);
@ -558,7 +546,7 @@ ldap_process_results(LDAP *dbc, LDAPMessage *msg, char ** attrs,
if (data != NULL) if (data != NULL)
isc_mem_free(ns_g_mctx, data); isc_mem_free(ns_g_mctx, data);
return result; return (result);
} }
/*% /*%
@ -606,7 +594,7 @@ ldap_get_results(const char *zone, const char *record,
/* if DBI is null, can't do anything else */ /* if DBI is null, can't do anything else */
if (dbi == NULL) if (dbi == NULL)
return ISC_R_FAILURE; return (ISC_R_FAILURE);
/* set fields */ /* set fields */
if (zone != NULL) { if (zone != NULL) {
@ -735,7 +723,7 @@ ldap_get_results(const char *zone, const char *record,
goto cleanup; goto cleanup;
} }
for (i=0; i < 3; i++) { for (i = 0; i < 3; i++) {
/* /*
* dbi->dbconn may be null if trying to reconnect on a * dbi->dbconn may be null if trying to reconnect on a
@ -800,7 +788,7 @@ ldap_get_results(const char *zone, const char *record,
goto cleanup; goto cleanup;
break; break;
} /* close switch(ldap_result) */ } /* close switch(ldap_result) */
} /* end for (int i=0 i < 3; i++) */ } /* end for (int i = 0 i < 3; i++) */
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
goto cleanup; goto cleanup;
@ -846,7 +834,6 @@ ldap_get_results(const char *zone, const char *record,
result = ISC_R_UNEXPECTED; result = ISC_R_UNEXPECTED;
} }
cleanup: cleanup:
/* it's always good to cleanup after yourself */ /* it's always good to cleanup after yourself */
@ -877,13 +864,12 @@ ldap_get_results(const char *zone, const char *record,
isc_mem_free(ns_g_mctx, querystring ); isc_mem_free(ns_g_mctx, querystring );
/* return result */ /* return result */
return result; return (result);
} }
/* /*
* DLZ methods * DLZ methods
*/ */
static isc_result_t static isc_result_t
dlz_ldap_allowzonexfr(void *driverarg, void *dbdata, const char *name, dlz_ldap_allowzonexfr(void *driverarg, void *dbdata, const char *name,
const char *client) const char *client)
@ -895,11 +881,12 @@ dlz_ldap_allowzonexfr(void *driverarg, void *dbdata, const char *name,
/* check to see if we are authoritative for the zone first */ /* check to see if we are authoritative for the zone first */
result = dlz_ldap_findzone(driverarg, dbdata, name); result = dlz_ldap_findzone(driverarg, dbdata, name);
if (result != ISC_R_SUCCESS) { if (result != ISC_R_SUCCESS) {
return result; return (result);
} }
/* get all the zone data */ /* get all the zone data */
return ldap_get_results(name, NULL, client, ALLOWXFR, dbdata, NULL); result = ldap_get_results(name, NULL, client, ALLOWXFR, dbdata, NULL);
return (result);
} }
static isc_result_t static isc_result_t
@ -907,7 +894,7 @@ dlz_ldap_allnodes(const char *zone, void *driverarg, void *dbdata,
dns_sdlzallnodes_t *allnodes) dns_sdlzallnodes_t *allnodes)
{ {
UNUSED(driverarg); UNUSED(driverarg);
return ldap_get_results(zone, NULL, NULL, ALLNODES, dbdata, allnodes); return (ldap_get_results(zone, NULL, NULL, ALLNODES, dbdata, allnodes));
} }
static isc_result_t static isc_result_t
@ -915,27 +902,29 @@ dlz_ldap_authority(const char *zone, void *driverarg, void *dbdata,
dns_sdlzlookup_t *lookup) dns_sdlzlookup_t *lookup)
{ {
UNUSED(driverarg); UNUSED(driverarg);
return ldap_get_results(zone, NULL, NULL, AUTHORITY, dbdata, lookup); return (ldap_get_results(zone, NULL, NULL, AUTHORITY, dbdata, lookup));
} }
static isc_result_t static isc_result_t
dlz_ldap_findzone(void *driverarg, void *dbdata, const char *name) dlz_ldap_findzone(void *driverarg, void *dbdata, const char *name) {
{
UNUSED(driverarg); UNUSED(driverarg);
return ldap_get_results(name, NULL, NULL, FINDZONE, dbdata, NULL); return (ldap_get_results(name, NULL, NULL, FINDZONE, dbdata, NULL));
} }
static isc_result_t static isc_result_t
dlz_ldap_lookup(const char *zone, const char *name, void *driverarg, dlz_ldap_lookup(const char *zone, const char *name, void *driverarg,
void *dbdata, dns_sdlzlookup_t *lookup) void *dbdata, dns_sdlzlookup_t *lookup)
{ {
isc_result_t result;
UNUSED(driverarg); UNUSED(driverarg);
if (strcmp(name, "*") == 0) if (strcmp(name, "*") == 0)
return ldap_get_results(zone, "~", NULL, result = ldap_get_results(zone, "~", NULL, LOOKUP,
LOOKUP, dbdata, lookup); dbdata, lookup);
else else
return ldap_get_results(zone, name, NULL, result = ldap_get_results(zone, name, NULL, LOOKUP,
LOOKUP, dbdata, lookup); dbdata, lookup);
return (result);
} }
@ -943,7 +932,6 @@ static isc_result_t
dlz_ldap_create(const char *dlzname, unsigned int argc, char *argv[], dlz_ldap_create(const char *dlzname, unsigned int argc, char *argv[],
void *driverarg, void **dbdata) void *driverarg, void **dbdata)
{ {
isc_result_t result; isc_result_t result;
ldap_instance_t *ldap_inst = NULL; ldap_instance_t *ldap_inst = NULL;
dbinstance_t *dbi = NULL; dbinstance_t *dbi = NULL;
@ -1039,24 +1027,24 @@ dlz_ldap_create(const char *dlzname, unsigned int argc, char *argv[],
case 12: case 12:
result = dlz_ldap_checkURL(argv[11], 0, "allow zone transfer"); result = dlz_ldap_checkURL(argv[11], 0, "allow zone transfer");
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
return result; return (result);
case 11: case 11:
result = dlz_ldap_checkURL(argv[10], 3, "all nodes"); result = dlz_ldap_checkURL(argv[10], 3, "all nodes");
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
return result; return (result);
case 10: case 10:
if (strlen(argv[9]) > 0) { if (strlen(argv[9]) > 0) {
result = dlz_ldap_checkURL(argv[9], 3, "authority"); result = dlz_ldap_checkURL(argv[9], 3, "authority");
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
return result; return (result);
} }
case 9: case 9:
result = dlz_ldap_checkURL(argv[8], 3, "lookup"); result = dlz_ldap_checkURL(argv[8], 3, "lookup");
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
return result; return (result);
result = dlz_ldap_checkURL(argv[7], 0, "find zone"); result = dlz_ldap_checkURL(argv[7], 0, "find zone");
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
return result; return (result);
break; break;
default: default:
/* not really needed, should shut up compiler. */ /* not really needed, should shut up compiler. */
@ -1248,36 +1236,28 @@ dlz_ldap_create(const char *dlzname, unsigned int argc, char *argv[],
return(ISC_R_SUCCESS); return(ISC_R_SUCCESS);
cleanup: cleanup:
dlz_ldap_destroy(NULL, ldap_inst); dlz_ldap_destroy(NULL, ldap_inst);
return(ISC_R_FAILURE); return(ISC_R_FAILURE);
} }
void void
dlz_ldap_destroy(void *driverarg, void *dbdata) dlz_ldap_destroy(void *driverarg, void *dbdata) {
{
UNUSED(driverarg); UNUSED(driverarg);
if (dbdata != NULL) { if (dbdata != NULL) {
#ifdef ISC_PLATFORM_USETHREADS #ifdef ISC_PLATFORM_USETHREADS
/* cleanup the list of DBI's */ /* cleanup the list of DBI's */
ldap_destroy_dblist((db_list_t *) ldap_destroy_dblist((db_list_t *)
((ldap_instance_t *)dbdata)->db); ((ldap_instance_t *)dbdata)->db);
#else /* ISC_PLATFORM_USETHREADS */ #else /* ISC_PLATFORM_USETHREADS */
/* release connection */
if (((ldap_instance_t *)dbdata)->db->dbconn != NULL) if (((ldap_instance_t *)dbdata)->db->dbconn != NULL)
ldap_unbind_s((LDAP *) ldap_unbind_s((LDAP *)
((ldap_instance_t *)dbdata)->db->dbconn); ((ldap_instance_t *)dbdata)->db->dbconn);
/* destroy single DB instance */ /* destroy single DB instance */
destroy_sqldbinstance(((ldap_instance_t *)dbdata)->db); destroy_sqldbinstance(((ldap_instance_t *)dbdata)->db);
#endif /* ISC_PLATFORM_USETHREADS */ #endif /* ISC_PLATFORM_USETHREADS */
if (((ldap_instance_t *)dbdata)->hosts != NULL) if (((ldap_instance_t *)dbdata)->hosts != NULL)
@ -1338,8 +1318,7 @@ dlz_ldap_init(void) {
result = ISC_R_UNEXPECTED; result = ISC_R_UNEXPECTED;
} }
return (result);
return result;
} }
/*% /*%
@ -1347,7 +1326,6 @@ dlz_ldap_init(void) {
*/ */
void void
dlz_ldap_clear(void) { dlz_ldap_clear(void) {
/* /*
* Write debugging message to log * Write debugging message to log
*/ */