From 400204baf2b622ad937f5f4e9f88c39360cc373e Mon Sep 17 00:00:00 2001 From: Jeff Trawick Date: Tue, 30 Jul 2002 19:38:11 +0000 Subject: [PATCH] support non-threaded configurations PR: 10920 git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@96244 13f79535-47bb-0310-9956-ffa450edef68 --- modules/experimental/mod_auth_ldap.c | 10 ++- modules/experimental/util_ldap.c | 87 ++++++++++++++------------ modules/experimental/util_ldap_cache.h | 16 +++++ 3 files changed, 73 insertions(+), 40 deletions(-) diff --git a/modules/experimental/mod_auth_ldap.c b/modules/experimental/mod_auth_ldap.c index ce025b1ebe..d1e79b78bf 100644 --- a/modules/experimental/mod_auth_ldap.c +++ b/modules/experimental/mod_auth_ldap.c @@ -85,7 +85,9 @@ /* per directory configuration */ typedef struct { apr_pool_t *pool; /* Pool that this config is allocated from */ - apr_thread_mutex_t *lock; /* Lock for this config */ +#if APR_HAS_THREADS + apr_thread_mutex_t *lock; /* Lock for this config */ +#endif int auth_authoritative; /* Is this auth method the one and only? */ int enabled; /* Is auth_ldap enabled in this directory? */ @@ -384,12 +386,16 @@ int mod_auth_ldap_auth_checker(request_rec *r) */ if (sec->groupattr->nelts == 0) { struct mod_auth_ldap_groupattr_entry_t *grp; +#if APR_HAS_THREADS apr_thread_mutex_lock(sec->lock); +#endif grp = apr_array_push(sec->groupattr); grp->name = "member"; grp = apr_array_push(sec->groupattr); grp->name = "uniquemember"; +#if APR_HAS_THREADS apr_thread_mutex_unlock(sec->lock); +#endif } if (!reqs_arr) { @@ -589,7 +595,9 @@ void *mod_auth_ldap_create_dir_config(apr_pool_t *p, char *d) (mod_auth_ldap_config_t *)apr_pcalloc(p, sizeof(mod_auth_ldap_config_t)); sec->pool = p; +#if APR_HAS_THREADS apr_thread_mutex_create(&sec->lock, APR_THREAD_MUTEX_DEFAULT, p); +#endif sec->auth_authoritative = 1; sec->enabled = 1; sec->groupattr = apr_array_make(p, GROUPATTR_MAX_ELTS, diff --git a/modules/experimental/util_ldap.c b/modules/experimental/util_ldap.c index 9bd7682b72..1743862105 100644 --- a/modules/experimental/util_ldap.c +++ b/modules/experimental/util_ldap.c @@ -193,8 +193,10 @@ void util_ldap_connection_close(util_ldap_connection_t *ldc) */ /* mark our connection as available for reuse */ - apr_thread_mutex_unlock(ldc->lock); +#if APR_HAS_THREADS + apr_thread_mutex_unlock(ldc->lock); +#endif } @@ -221,8 +223,10 @@ apr_status_t util_ldap_connection_destroy(void *param) Unlocking an unheld lock causes problems on NetWare. The other option would be to assume that close connection did its job. */ +#if APR_HAS_THREADS apr_thread_mutex_trylock(ldc->lock); apr_thread_mutex_unlock(ldc->lock); +#endif return APR_SUCCESS; } @@ -383,18 +387,24 @@ util_ldap_connection_t *util_ldap_connection_find(request_rec *r, const char *ho &ldap_module); +#if APR_HAS_THREADS /* mutex lock this function */ if (!st->mutex) { apr_thread_mutex_create(&st->mutex, APR_THREAD_MUTEX_DEFAULT, st->pool); } apr_thread_mutex_lock(st->mutex); +#endif /* Search for an exact connection match in the list that is not * being used. */ for (l=st->connections,p=NULL; l; l=l->next) { - if ( (APR_SUCCESS == apr_thread_mutex_trylock(l->lock)) - && l->port == port +#if APR_HAS_THREADS + if ( (APR_SUCCESS == apr_thread_mutex_trylock(l->lock)) && +#else + if ( +#endif + l->port == port && strcmp(l->host, host) == 0 && ( (!l->binddn && !binddn) || (l->binddn && binddn && !strcmp(l->binddn, binddn)) ) && ( (!l->bindpw && !bindpw) || (l->bindpw && bindpw && !strcmp(l->bindpw, bindpw)) ) @@ -415,8 +425,12 @@ util_ldap_connection_t *util_ldap_connection_find(request_rec *r, const char *ho */ if (!l) { for (l=st->connections,p=NULL; l; l=l->next) { - if ( (APR_SUCCESS == apr_thread_mutex_trylock(l->lock)) - && l->port == port +#if APR_HAS_THREADS + if ( (APR_SUCCESS == apr_thread_mutex_trylock(l->lock)) && +#else + if ( +#endif + l->port == port && strcmp(l->host, host) == 0 && l->deref == deref #ifdef APU_HAS_LDAP_NETSCAPE_SSL @@ -451,8 +465,10 @@ util_ldap_connection_t *util_ldap_connection_find(request_rec *r, const char *ho */ /* create the details to the pool in st */ l = apr_pcalloc(st->pool, sizeof(util_ldap_connection_t)); +#if APR_HAS_THREADS apr_thread_mutex_create(&l->lock, APR_THREAD_MUTEX_DEFAULT, st->pool); apr_thread_mutex_lock(l->lock); +#endif l->pool = st->pool; l->bound = 0; l->host = apr_pstrdup(st->pool, host); @@ -472,7 +488,9 @@ util_ldap_connection_t *util_ldap_connection_find(request_rec *r, const char *ho } } +#if APR_HAS_THREADS apr_thread_mutex_unlock(st->mutex); +#endif return l; } @@ -504,20 +522,18 @@ int util_ldap_cache_comparedn(request_rec *r, util_ldap_connection_t *ldc, (util_ldap_state_t *)ap_get_module_config(r->server->module_config, &ldap_module); - /* read lock this function */ - if (!util_ldap_cache_lock) { - apr_thread_rwlock_create(&util_ldap_cache_lock, st->pool); - } + LDAP_CACHE_LOCK_CREATE(st->pool); /* get cache entry (or create one) */ - apr_thread_rwlock_wrlock(util_ldap_cache_lock); + LDAP_CACHE_WRLOCK(); + curnode.url = url; curl = util_ald_cache_fetch(util_ldap_cache, &curnode); if (curl == NULL) { curl = util_ald_create_caches(st, url); } - apr_thread_rwlock_unlock(util_ldap_cache_lock); + LDAP_CACHE_UNLOCK(); /* a simple compare? */ if (!compare_dn_on_server) { @@ -533,7 +549,7 @@ int util_ldap_cache_comparedn(request_rec *r, util_ldap_connection_t *ldc, } /* no - it's a server side compare */ - apr_thread_rwlock_rdlock(util_ldap_cache_lock); + LDAP_CACHE_RDLOCK(); /* is it in the compare cache? */ newnode.reqdn = (char *)reqdn; @@ -541,13 +557,13 @@ int util_ldap_cache_comparedn(request_rec *r, util_ldap_connection_t *ldc, if (node != NULL) { /* If it's in the cache, it's good */ /* unlock this read lock */ - apr_thread_rwlock_unlock(util_ldap_cache_lock); + LDAP_CACHE_UNLOCK(); ldc->reason = "DN Comparison TRUE (cached)"; return LDAP_COMPARE_TRUE; } /* unlock this read lock */ - apr_thread_rwlock_unlock(util_ldap_cache_lock); + LDAP_CACHE_UNLOCK(); start_over: if (failures++ > 10) { @@ -586,11 +602,11 @@ start_over: } else { /* compare successful - add to the compare cache */ - apr_thread_rwlock_rdlock(util_ldap_cache_lock); + LDAP_CACHE_RDLOCK(); newnode.reqdn = (char *)reqdn; newnode.dn = (char *)dn; util_ald_cache_insert(curl->dn_compare_cache, &newnode); - apr_thread_rwlock_unlock(util_ldap_cache_lock); + LDAP_CACHE_UNLOCK(); ldc->reason = "DN Comparison TRUE (checked on server)"; result = LDAP_COMPARE_TRUE; } @@ -623,23 +639,20 @@ int util_ldap_cache_compare(request_rec *r, util_ldap_connection_t *ldc, (util_ldap_state_t *)ap_get_module_config(r->server->module_config, &ldap_module); - /* read lock this function */ - if (!util_ldap_cache_lock) { - apr_thread_rwlock_create(&util_ldap_cache_lock, st->pool); - } + LDAP_CACHE_LOCK_CREATE(st->pool); /* get cache entry (or create one) */ - apr_thread_rwlock_wrlock(util_ldap_cache_lock); + LDAP_CACHE_WRLOCK(); curnode.url = url; curl = util_ald_cache_fetch(util_ldap_cache, &curnode); if (curl == NULL) { curl = util_ald_create_caches(st, url); } - apr_thread_rwlock_unlock(util_ldap_cache_lock); + LDAP_CACHE_UNLOCK(); /* make a comparison to the cache */ - apr_thread_rwlock_rdlock(util_ldap_cache_lock); + LDAP_CACHE_RDLOCK(); curtime = apr_time_now(); the_compare_node.dn = (char *)dn; @@ -658,7 +671,7 @@ int util_ldap_cache_compare(request_rec *r, util_ldap_connection_t *ldc, else { /* ...and it is good */ /* unlock this read lock */ - apr_thread_rwlock_unlock(util_ldap_cache_lock); + LDAP_CACHE_UNLOCK(); if (LDAP_COMPARE_TRUE == compare_nodep->result) { ldc->reason = "Comparison true (cached)"; return compare_nodep->result; @@ -678,8 +691,7 @@ int util_ldap_cache_compare(request_rec *r, util_ldap_connection_t *ldc, } } /* unlock this read lock */ - apr_thread_rwlock_unlock(util_ldap_cache_lock); - + LDAP_CACHE_UNLOCK(); start_over: if (failures++ > 10) { @@ -705,11 +717,11 @@ start_over: (LDAP_COMPARE_FALSE == result) || (LDAP_NO_SUCH_ATTRIBUTE == result)) { /* compare completed; caching result */ - apr_thread_rwlock_wrlock(util_ldap_cache_lock); + LDAP_CACHE_WRLOCK(); the_compare_node.lastcompare = curtime; the_compare_node.result = result; util_ald_cache_insert(curl->compare_cache, &the_compare_node); - apr_thread_rwlock_unlock(util_ldap_cache_lock); + LDAP_CACHE_UNLOCK(); if (LDAP_COMPARE_TRUE == result) { ldc->reason = "Comparison true (adding to cache)"; return LDAP_COMPARE_TRUE; @@ -748,20 +760,18 @@ int util_ldap_cache_checkuserid(request_rec *r, util_ldap_connection_t *ldc, &ldap_module); /* read lock this function */ - if (!util_ldap_cache_lock) { - apr_thread_rwlock_create(&util_ldap_cache_lock, st->pool); - } + LDAP_CACHE_LOCK_CREATE(st->pool); /* Get the cache node for this url */ - apr_thread_rwlock_wrlock(util_ldap_cache_lock); + LDAP_CACHE_WRLOCK(); curnode.url = url; curl = (util_url_node_t *)util_ald_cache_fetch(util_ldap_cache, &curnode); if (curl == NULL) { curl = util_ald_create_caches(st, url); } - apr_thread_rwlock_unlock(util_ldap_cache_lock); + LDAP_CACHE_UNLOCK(); - apr_thread_rwlock_rdlock(util_ldap_cache_lock); + LDAP_CACHE_RDLOCK(); the_search_node.username = filter; search_nodep = util_ald_cache_fetch(curl->search_cache, &the_search_node); if (search_nodep != NULL && search_nodep->bindpw) { @@ -785,14 +795,13 @@ int util_ldap_cache_checkuserid(request_rec *r, util_ldap_connection_t *ldc, /* ...and entry is valid */ *binddn = search_nodep->dn; *retvals = search_nodep->vals; - apr_thread_rwlock_unlock(util_ldap_cache_lock); + LDAP_CACHE_UNLOCK(); ldc->reason = "Authentication successful (cached)"; return LDAP_SUCCESS; } } /* unlock this read lock */ - apr_thread_rwlock_unlock(util_ldap_cache_lock); - + LDAP_CACHE_UNLOCK(); /* * At this point, there is no valid cached search, so lets do the search. @@ -900,7 +909,7 @@ start_over: /* * Add the new username to the search cache. */ - apr_thread_rwlock_wrlock(util_ldap_cache_lock); + LDAP_CACHE_WRLOCK(); the_search_node.username = filter; the_search_node.dn = *binddn; the_search_node.bindpw = bindpw; @@ -908,7 +917,7 @@ start_over: the_search_node.vals = vals; util_ald_cache_insert(curl->search_cache, &the_search_node); ldap_msgfree(res); - apr_thread_rwlock_unlock(util_ldap_cache_lock); + LDAP_CACHE_UNLOCK(); ldc->reason = "Authentication successful"; return LDAP_SUCCESS; diff --git a/modules/experimental/util_ldap_cache.h b/modules/experimental/util_ldap_cache.h index f2be43d024..6adeb99181 100644 --- a/modules/experimental/util_ldap_cache.h +++ b/modules/experimental/util_ldap_cache.h @@ -107,7 +107,23 @@ apr_shm_t *util_ldap_shm; apr_rmm_t *util_ldap_rmm; #endif util_ald_cache_t *util_ldap_cache; + +#if APR_HAS_THREADS apr_thread_rwlock_t *util_ldap_cache_lock; +#define LDAP_CACHE_LOCK_CREATE(p) \ + if (!util_ldap_cache_lock) apr_thread_rwlock_create(&util_ldap_cache_lock, p) +#define LDAP_CACHE_WRLOCK() \ + apr_thread_rwlock_wrlock(util_ldap_cache_lock) +#define LDAP_CACHE_UNLOCK() \ + apr_thread_rwlock_unlock(util_ldap_cache_lock) +#define LDAP_CACHE_RDLOCK() \ + apr_thread_rwlock_rdlock(util_ldap_cache_lock) +#else +#define LDAP_CACHE_LOCK_CREATE(p) +#define LDAP_CACHE_WRLOCK() +#define LDAP_CACHE_UNLOCK() +#define LDAP_CACHE_RDLOCK() +#endif #ifndef WIN32 #define ALD_MM_FILE_MODE ( S_IRUSR|S_IWUSR ) -- 2.50.1