util_ldap.c revision 9c63a05713cb83a44a1590b4af33edeebf39f118
f90884915ff10ae83f59e709c68824de834e64f5Dominik Luecke/* Licensed to the Apache Software Foundation (ASF) under one or more
f90884915ff10ae83f59e709c68824de834e64f5Dominik Luecke * contributor license agreements. See the NOTICE file distributed with
f90884915ff10ae83f59e709c68824de834e64f5Dominik Luecke * this work for additional information regarding copyright ownership.
f90884915ff10ae83f59e709c68824de834e64f5Dominik Luecke * The ASF licenses this file to You under the Apache License, Version 2.0
f90884915ff10ae83f59e709c68824de834e64f5Dominik Luecke * (the "License"); you may not use this file except in compliance with
f90884915ff10ae83f59e709c68824de834e64f5Dominik Luecke * the License. You may obtain a copy of the License at
b72a390042c19e630cf221494b60c9df2a60d187Dominik Luecke * Unless required by applicable law or agreed to in writing, software
f90884915ff10ae83f59e709c68824de834e64f5Dominik Luecke * distributed under the License is distributed on an "AS IS" BASIS,
f90884915ff10ae83f59e709c68824de834e64f5Dominik Luecke * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2af38fde95f93562f2124ec615fba0e509c8202eDominik Luecke * See the License for the specific language governing permissions and
2af38fde95f93562f2124ec615fba0e509c8202eDominik Luecke * limitations under the License.
2af38fde95f93562f2124ec615fba0e509c8202eDominik Luecke * Original code from auth_ldap module for Apache v1.3:
f90884915ff10ae83f59e709c68824de834e64f5Dominik Luecke * Copyright 1998, 1999 Enbridge Pipelines Inc.
f90884915ff10ae83f59e709c68824de834e64f5Dominik Luecke * Copyright 1999-2001 Dave Carrigan
cf04ba46b9eb495d334466e24e082e391055ca7bDominik Luecke#error mod_ldap requires APR-util to have LDAP support built in
4df63f7187b1ba16cbe5c781db187a42f2f49579Dominik Luecke/* Default define for ldap functions that need a SIZELIMIT but
08056875f5f633ef432598d5245ea41c112d2178Dominik Luecke * do not have the define
08056875f5f633ef432598d5245ea41c112d2178Dominik Luecke * XXX This should be removed once a supporting #define is
08056875f5f633ef432598d5245ea41c112d2178Dominik Luecke * released through APR-Util.
f90884915ff10ae83f59e709c68824de834e64f5Dominik Luecke#define AP_LDAP_OPT_DEBUG LDAP_OPT_DEBUG_LEVEL
b72a390042c19e630cf221494b60c9df2a60d187Dominik Lueckestatic const char *ldap_cache_mutex_type = "ldap-cache";
08056875f5f633ef432598d5245ea41c112d2178Dominik Luecke apr_global_mutex_lock(st->util_ldap_cache_lock); \
548f3850942936a8c6021185c8391dfcd3b03018Dominik Luecke apr_global_mutex_unlock(st->util_ldap_cache_lock); \
548f3850942936a8c6021185c8391dfcd3b03018Dominik Lueckestatic apr_status_t util_ldap_connection_remove (void *param);
548f3850942936a8c6021185c8391dfcd3b03018Dominik Lueckestatic void util_ldap_strdup (char **str, const char *newstr)
08056875f5f633ef432598d5245ea41c112d2178Dominik Luecke * Status Handler
08056875f5f633ef432598d5245ea41c112d2178Dominik Luecke * --------------
548f3850942936a8c6021185c8391dfcd3b03018Dominik Luecke * This handler generates a status page about the current performance of
08056875f5f633ef432598d5245ea41c112d2178Dominik Luecke * the LDAP cache. It is enabled as follows:
548f3850942936a8c6021185c8391dfcd3b03018Dominik Luecke * <Location /ldap-status>
548f3850942936a8c6021185c8391dfcd3b03018Dominik Luecke * SetHandler ldap-status
548f3850942936a8c6021185c8391dfcd3b03018Dominik Luecke * </Location>
08056875f5f633ef432598d5245ea41c112d2178Dominik Luecke util_ldap_state_t *st = (util_ldap_state_t *)
08056875f5f633ef432598d5245ea41c112d2178Dominik Luecke ap_get_module_config(r->server->module_config,
5b9f5c1b3592b99fc74d3438740ebcf9eb4c94beDominik Luecke ap_set_content_type(r, "text/html; charset=ISO-8859-1");
5b9f5c1b3592b99fc74d3438740ebcf9eb4c94beDominik Luecke "<html><head><title>LDAP Cache Information</title></head>\n", r);
5b9f5c1b3592b99fc74d3438740ebcf9eb4c94beDominik Luecke ap_rputs("<body bgcolor='#ffffff'><h1 align=center>LDAP Cache Information"
5b9f5c1b3592b99fc74d3438740ebcf9eb4c94beDominik Luecke "</h1>\n", r);
5b9f5c1b3592b99fc74d3438740ebcf9eb4c94beDominik Luecke/* ------------------------------------------------------------------ */
5b9f5c1b3592b99fc74d3438740ebcf9eb4c94beDominik Luecke * Closes an LDAP connection by unlocking it. The next time
5b9f5c1b3592b99fc74d3438740ebcf9eb4c94beDominik Luecke * uldap_connection_find() is called this connection will be
5b9f5c1b3592b99fc74d3438740ebcf9eb4c94beDominik Luecke * available for reuse.
5b9f5c1b3592b99fc74d3438740ebcf9eb4c94beDominik Lueckestatic void uldap_connection_close(util_ldap_connection_t *ldc)
5b9f5c1b3592b99fc74d3438740ebcf9eb4c94beDominik Luecke * Is it safe leaving bound connections floating around between the
5b9f5c1b3592b99fc74d3438740ebcf9eb4c94beDominik Luecke * different modules? Keeping the user bound is a performance boost,
5b9f5c1b3592b99fc74d3438740ebcf9eb4c94beDominik Luecke * but it is also a potential security problem - maybe.
#if APR_HAS_THREADS
if (ldc) {
return APR_SUCCESS;
if (ldc) {
return APR_SUCCESS;
#if APR_HAS_THREADS
if (l == ldc) {
if (prev) {
prev = l;
#if APR_HAS_THREADS
return APR_SUCCESS;
#ifdef LDAP_OPT_NETWORK_TIMEOUT
&ldap_module);
&(result));
return(APR_EGENERAL);
return(rc);
&(result));
if ((ldc->ReferralHopLimit != AP_LDAP_HOPLIMIT_UNSET) && ldc->ChaseReferrals == AP_LDAP_CHASEREFERRALS_ON) {
&(result));
#ifdef APR_LDAP_OPT_VERIFY_CERT
#if defined(LDAPSSL_VERIFY_SERVER)
int i = LDAP_OPT_X_TLS_DEMAND;
int i = LDAP_OPT_X_TLS_NEVER;
#ifdef LDAP_OPT_NETWORK_TIMEOUT
#ifdef LDAP_OPT_TIMEOUT
return(rc);
int rc;
return LDAP_OTHER;
else if (rc == 0) {
return rc;
int rc = 0;
int failures = 0;
int new_connection = 0;
if (!ldc) {
return LDAP_SUCCESS;
return rc;
&ldap_module);
return(rc);
static util_ldap_connection_t *
&ldap_module);
#if APR_HAS_THREADS
#if APR_HAS_THREADS
#if APR_HAS_THREADS
#if APR_HAS_THREADS
l->bound = 0;
#if APR_HAS_THREADS
#if APR_HAS_THREADS
return NULL;
#if APR_HAS_THREADS
l->bound = 0;
p->next = l;
#if APR_HAS_THREADS
int result = 0;
int failures = 0;
char *searchdn;
&ldap_module);
if (!compare_dn_on_server) {
return LDAP_COMPARE_FALSE;
return LDAP_COMPARE_TRUE;
if (curl) {
return LDAP_COMPARE_TRUE;
return result;
return result;
goto start_over;
goto start_over;
return result;
if (curl) {
return result;
int result = 0;
int failures = 0;
&ldap_module);
if (curl) {
return result;
return result;
return result;
(char *)dn,
(char *)attrib,
(char *)value);
goto start_over;
goto start_over;
if (curl) {
void *junk;
return LDAP_COMPARE_TRUE;
return LDAP_COMPARE_FALSE;
return LDAP_NO_SUCH_ATTRIBUTE;
return result;
const char *url,
const char *dn,
char **subgroupAttrs,
int failures = 0;
if (!subgroupAttrs) {
return res;
return res;
return res;
goto start_over;
goto start_over;
return res;
if (subgroupAttrs) {
char **values;
int val_index = 0;
if (values) {
val_index = 0;
tmp_sgcIndex = 0;
tmp_sgcIndex++;
val_index++;
indx++;
int sgindex;
char **group;
return res;
char **subgroupAttrs,
int cur_subgroup_depth,
int max_subgroup_depth)
&ldap_module);
return LDAP_COMPARE_FALSE;
return result;
sizeof(util_compare_subgroup_t));
if (!tmp_local_sgl) {
dn);
dn);
if (!tmp_local_sgl) {
if (sgl_copy) {
if (!tmp_local_sgl) {
return result;
sgindex++;
return result;
const char ***retvals)
int numvals = 0;
int result = 0;
char *dn;
int count;
int failures = 0;
&ldap_module);
&curnode);
if (curl) {
if (attrs) {
return LDAP_SUCCESS;
return result;
return result;
goto start_over;
return result;
if (count == 0 )
return LDAP_NO_SUCH_OBJECT;
return LDAP_INVALID_CREDENTIALS;
goto start_over;
return result;
if (attrs) {
while (attrs[k++]);
numvals = k;
while (attrs[i]) {
char **values;
if (curl) {
return LDAP_SUCCESS;
int numvals = 0;
int result = 0;
char *dn;
int count;
int failures = 0;
&ldap_module);
&curnode);
if (curl) {
if (attrs) {
return LDAP_SUCCESS;
return result;
return result;
goto start_over;
return result;
if (count == 0 )
return LDAP_NO_SUCH_OBJECT;
if (attrs) {
while (attrs[k++]);
numvals = k;
while (attrs[i]) {
char **values;
if (curl) {
return LDAP_SUCCESS;
const char *bytes)
&ldap_module);
return err;
return NULL;
const char *file)
&ldap_module);
return err;
if (file) {
return NULL;
const char *ttl)
&ldap_module);
return err;
return NULL;
const char *size)
&ldap_module);
return err;
return NULL;
const char *ttl)
&ldap_module);
return err;
return NULL;
const char *size)
&ldap_module);
return err;
return NULL;
return APR_LDAP_CA_TYPE_DER;
return APR_LDAP_CA_TYPE_BASE64;
return APR_LDAP_CA_TYPE_CERT7_DB;
return APR_LDAP_CA_TYPE_SECMOD;
return APR_LDAP_CERT_TYPE_DER;
return APR_LDAP_CERT_TYPE_BASE64;
return APR_LDAP_CERT_TYPE_PFX;
return APR_LDAP_CERT_TYPE_KEY3_DB;
return APR_LDAP_CERT_TYPE_NICKNAME;
return APR_LDAP_KEY_TYPE_DER;
return APR_LDAP_KEY_TYPE_BASE64;
return APR_LDAP_KEY_TYPE_PFX;
return APR_LDAP_CA_TYPE_UNKNOWN;
void *dummy,
const char *type,
const char *file,
const char *password)
&ldap_module);
int cert_type = 0;
return err;
if (type) {
!= APR_SUCCESS))
return(NULL);
void *config,
const char *type,
const char *file,
const char *password)
int cert_type = 0;
if (type) {
type);
!= APR_SUCCESS))
return(NULL);
const char *mode)
&ldap_module);
mode);
return(NULL);
void *dummy,
int mode)
&ldap_module);
return err;
return(NULL);
void *dummy,
const char *ttl)
#ifdef LDAP_OPT_NETWORK_TIMEOUT
&ldap_module);
return err;
#ifdef LDAP_OPT_NETWORK_TIMEOUT
return NULL;
void *config,
int mode)
return(NULL);
void *config,
const char *arg) {
&ldap_module);
return err;
#ifndef AP_LDAP_OPT_DEBUG
return NULL;
void *config,
const char *hop_limit)
return "LDAPReferralHopLimit must be greater than zero (Use 'LDAPReferrals Off' to disable referral chasing)";
return NULL;
return dc;
void *dummy,
const char *val)
long timeout;
char *endptr;
&ldap_module);
return err;
if (timeout < 0) {
if (timeout) {
timeout);
#ifndef LDAP_OPT_TIMEOUT
return NULL;
#if APR_HAS_THREADS
return st;
void *overridesv)
#if APR_HAS_THREADS
return st;
return APR_SUCCESS;
APR_LOCK_DEFAULT, 0);
return result;
return OK;
&ldap_module);
void *data;
int rc;
if (!data) {
NULL);
return OK;
return DONE;
return result;
while (s_vhost) {
&ldap_module);
NULL,
&(result_err));
apr_ldap_rebind_init (p);
#ifdef AP_LDAP_OPT_DEBUG
return(OK);
&ldap_module);
{NULL}