util_ldap.h revision 094c6e3951ccdbb0a63ae4f0e3a696b0dce83291
842ae4bd224140319ae7feec1872b93dfd491143fielding/* Licensed to the Apache Software Foundation (ASF) under one or more
842ae4bd224140319ae7feec1872b93dfd491143fielding * contributor license agreements. See the NOTICE file distributed with
842ae4bd224140319ae7feec1872b93dfd491143fielding * this work for additional information regarding copyright ownership.
842ae4bd224140319ae7feec1872b93dfd491143fielding * The ASF licenses this file to You under the Apache License, Version 2.0
842ae4bd224140319ae7feec1872b93dfd491143fielding * (the "License"); you may not use this file except in compliance with
842ae4bd224140319ae7feec1872b93dfd491143fielding * the License. You may obtain a copy of the License at
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes *
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * http://www.apache.org/licenses/LICENSE-2.0
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes *
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * Unless required by applicable law or agreed to in writing, software
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * distributed under the License is distributed on an "AS IS" BASIS,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * See the License for the specific language governing permissions and
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * limitations under the License.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/**
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * @file util_ldap.h
e8f95a682820a599fe41b22977010636be5c2717jim * @brief Apache LDAP library
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes */
e8f95a682820a599fe41b22977010636be5c2717jim
1747d30b98aa1bdbc43994c02cd46ab4cb9319e4fielding#ifndef UTIL_LDAP_H
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#define UTIL_LDAP_H
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/* APR header files */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#include "apr.h"
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#include "apr_thread_mutex.h"
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#include "apr_thread_rwlock.h"
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#include "apr_tables.h"
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#include "apr_time.h"
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#if APR_HAS_SHARED_MEMORY
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#include "apr_rmm.h"
5c0419d51818eb02045cf923a9fe456127a44c60wrowe#include "apr_shm.h"
5c0419d51818eb02045cf923a9fe456127a44c60wrowe#endif
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/* Apache header files */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#include "ap_config.h"
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#include "httpd.h"
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#include "http_config.h"
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#include "http_core.h"
d266c3777146d36a4c23c17aad6f153aebea1bf4jorton#include "http_log.h"
d266c3777146d36a4c23c17aad6f153aebea1bf4jorton#include "http_protocol.h"
d266c3777146d36a4c23c17aad6f153aebea1bf4jorton#include "http_request.h"
d266c3777146d36a4c23c17aad6f153aebea1bf4jorton#include "apr_optional.h"
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/* this whole thing disappears if LDAP is not enabled */
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholes#if AP_HAS_LDAP
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholes
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholes#include "ap_ldap.h"
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholes#include "ap_ldap_rebind.h"
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholes
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholes#ifdef __cplusplus
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholesextern "C" {
cd3bbd6d2df78d6c75e5d159a81ef8bdd5f70df9trawick#endif
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/*
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * LDAP Connections
0568280364eb026393be492ebc732795c4934643jorton */
0568280364eb026393be492ebc732795c4934643jorton
0568280364eb026393be492ebc732795c4934643jorton/* Values that the deref member can have */
0568280364eb026393be492ebc732795c4934643jortontypedef enum {
0568280364eb026393be492ebc732795c4934643jorton never=LDAP_DEREF_NEVER,
0568280364eb026393be492ebc732795c4934643jorton searching=LDAP_DEREF_SEARCHING,
0568280364eb026393be492ebc732795c4934643jorton finding=LDAP_DEREF_FINDING,
0568280364eb026393be492ebc732795c4934643jorton always=LDAP_DEREF_ALWAYS
0568280364eb026393be492ebc732795c4934643jorton} deref_options;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener/* Structure representing an LDAP connection */
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovenertypedef struct util_ldap_connection_t {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes LDAP *ldap;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes apr_pool_t *pool; /* Pool from which this connection is created */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#if APR_HAS_THREADS
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes apr_thread_mutex_t *lock; /* Lock to indicate this connection is in use */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#endif
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes const char *host; /* Name of the LDAP server (or space separated list) */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes int port; /* Port of the LDAP server */
796e4a7141265d8ed7036e4628161c6eafb2a789jorton deref_options deref; /* how to handle alias dereferening */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes const char *binddn; /* DN to bind to server (can be NULL) */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes const char *bindpw; /* Password to bind to server (can be NULL) */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes int bound; /* Flag to indicate whether this connection is bound yet */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes int secure; /* SSL/TLS mode of the connection */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes apr_array_header_t *client_certs; /* Client certificates on this connection */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes const char *reason; /* Reason for an error failure */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes struct util_ldap_connection_t *next;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes struct util_ldap_state_t *st; /* The LDAP vhost config this connection belongs to */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes int keep; /* Will this connection be kept when it's unlocked */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe int ChaseReferrals; /* [on|off] (default = AP_LDAP_CHASEREFERRALS_ON)*/
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes int ReferralHopLimit; /* # of referral hops to follow (default = AP_LDAP_DEFAULT_HOPLIMIT) */
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe apr_time_t freed; /* the time this conn was placed back in the pool */
e8f95a682820a599fe41b22977010636be5c2717jim apr_pool_t *rebind_pool; /* frequently cleared pool for rebind data */
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe} util_ldap_connection_t;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholestypedef struct util_ldap_config_t {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes int ChaseReferrals;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes int ReferralHopLimit;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes apr_array_header_t *client_certs; /* Client certificates */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes} util_ldap_config_t;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/* LDAP cache state information */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholestypedef struct util_ldap_state_t {
713a2b68bac4aeb1e9c48785006c0732451039depquerna apr_pool_t *pool; /* pool from which this state is allocated */
713a2b68bac4aeb1e9c48785006c0732451039depquerna#if APR_HAS_THREADS
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes apr_thread_mutex_t *mutex; /* mutex lock for the connection list */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#endif
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes apr_global_mutex_t *util_ldap_cache_lock;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes apr_size_t cache_bytes; /* Size (in bytes) of shared memory cache */
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe char *cache_file; /* filename for shm */
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe long search_cache_ttl; /* TTL for search cache */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes long search_cache_size; /* Size (in entries) of search cache */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes long compare_cache_ttl; /* TTL for compare cache */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes long compare_cache_size; /* Size (in entries) of compare cache */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes struct util_ldap_connection_t *connections;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes apr_array_header_t *global_certs; /* Global CA certificates */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes int ssl_supported;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes int secure;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener int secure_set;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes int verify_svr_cert;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
f43b67c5a9d29b572eac916f8335cedc80c908bebnicholes#if APR_HAS_SHARED_MEMORY
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes apr_shm_t *cache_shm;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes apr_rmm_t *cache_rmm;
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe#endif
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* cache ald */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes void *util_ldap_cache;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes long connectionTimeout;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes struct timeval *opTimeout;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes int debug_level; /* SDK debug level */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes apr_interval_time_t connection_pool_ttl;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes} util_ldap_state_t;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/* Used to store arrays of attribute labels/values. */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstruct mod_auth_ldap_groupattr_entry_t {
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener char *name;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener};
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener/**
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * Open a connection to an LDAP server
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * @param ldc A structure containing the expanded details of the server
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * to connect to. The handle to the LDAP connection is returned
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * as ldc->ldap.
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * @tip This function connects to the LDAP server and binds. It does not
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * connect if already connected (ldc->ldap != NULL). Does not bind
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * if already bound.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * @return If successful LDAP_SUCCESS is returned.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * @fn int util_ldap_connection_open(request_rec *r,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * util_ldap_connection_t *ldc)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes */
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovenerAPR_DECLARE_OPTIONAL_FN(int,uldap_connection_open,(request_rec *r,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes util_ldap_connection_t *ldc));
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/**
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * Close a connection to an LDAP server
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * @param ldc A structure containing the expanded details of the server
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * that was connected.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * @tip This function unbinds from the LDAP server, and clears ldc->ldap.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * It is possible to rebind to this server again using the same ldc
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * structure, using ap_ldap_open_connection().
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * @fn util_ldap_close_connection(util_ldap_connection_t *ldc)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesAPR_DECLARE_OPTIONAL_FN(void,uldap_connection_close,(util_ldap_connection_t *ldc));
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/**
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * Unbind a connection to an LDAP server
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * @param ldc A structure containing the expanded details of the server
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * that was connected.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * @tip This function unbinds the LDAP connection, and disconnects from
1f299703465bd9975d94e9f229f76af807442de2covener * the server. It is used during error conditions, to bring the LDAP
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * connection back to a known state.
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * @fn apr_status_t util_ldap_connection_unbind(util_ldap_connection_t *ldc)
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesAPR_DECLARE_OPTIONAL_FN(apr_status_t,uldap_connection_unbind,(void *param));
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/**
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * Find a connection in a list of connections
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * @param r The request record
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * @param host The hostname to connect to (multiple hosts space separated)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * @param port The port to connect to
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * @param binddn The DN to bind with
f43b67c5a9d29b572eac916f8335cedc80c908bebnicholes * @param bindpw The password to bind with
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * @param deref The dereferencing behavior
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * @param secure use SSL on the connection
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * @tip Once a connection is found and returned, a lock will be acquired to
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * lock that particular connection, so that another thread does not try and
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * use this connection while it is busy. Once you are finished with a connection,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * ap_ldap_connection_close() must be called to release this connection.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * @fn util_ldap_connection_t *util_ldap_connection_find(request_rec *r, const char *host, int port,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * const char *binddn, const char *bindpw, deref_options deref,
3e6d7277b90d3011db832139afc20efb5f17e203rederpj * int netscapessl, int starttls)
3e6d7277b90d3011db832139afc20efb5f17e203rederpj */
3e6d7277b90d3011db832139afc20efb5f17e203rederpjAPR_DECLARE_OPTIONAL_FN(util_ldap_connection_t *,uldap_connection_find,(request_rec *r, const char *host, int port,
3e6d7277b90d3011db832139afc20efb5f17e203rederpj const char *binddn, const char *bindpw, deref_options deref,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes int secure));
f43b67c5a9d29b572eac916f8335cedc80c908bebnicholes
e8f95a682820a599fe41b22977010636be5c2717jim/**
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * Compare two DNs for sameness
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * @param r The request record
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * @param ldc The LDAP connection being used.
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * @param url The URL of the LDAP connection - used for deciding which cache to use.
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * @param dn The first DN to compare.
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * @param reqdn The DN to compare the first DN to.
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * @param compare_dn_on_server Flag to determine whether the DNs should be checked using
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * LDAP calls or with a direct string comparision. A direct
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * string comparison is faster, but not as accurate - false
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * negative comparisons are possible.
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * @tip Two DNs can be equal and still fail a string comparison. Eg "dc=example,dc=com"
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * and "dc=example, dc=com". Use the compare_dn_on_server unless there are serious
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * performance issues.
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * @fn int util_ldap_cache_comparedn(request_rec *r, util_ldap_connection_t *ldc,
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * const char *url, const char *dn, const char *reqdn,
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * int compare_dn_on_server)
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener */
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovenerAPR_DECLARE_OPTIONAL_FN(int,uldap_cache_comparedn,(request_rec *r, util_ldap_connection_t *ldc,
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener const char *url, const char *dn, const char *reqdn,
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener int compare_dn_on_server));
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener/**
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * A generic LDAP compare function
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * @param r The request record
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * @param ldc The LDAP connection being used.
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * @param url The URL of the LDAP connection - used for deciding which cache to use.
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * @param dn The DN of the object in which we do the compare.
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * @param attrib The attribute within the object we are comparing for.
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * @param value The value of the attribute we are trying to compare for.
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * @tip Use this function to determine whether an attribute/value pair exists within an
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * object. Typically this would be used to determine LDAP top-level group
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * membership.
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * @fn int util_ldap_cache_compare(request_rec *r, util_ldap_connection_t *ldc,
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * const char *url, const char *dn, const char *attrib, const char *value)
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener */
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovenerAPR_DECLARE_OPTIONAL_FN(int,uldap_cache_compare,(request_rec *r, util_ldap_connection_t *ldc,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes const char *url, const char *dn, const char *attrib, const char *value));
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener/**
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * An LDAP function that checks if the specified user is a member of a subgroup.
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * @param r The request record
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * @param ldc The LDAP connection being used.
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * @param url The URL of the LDAP connection - used for deciding which cache to use.
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * @param dn The DN of the object in which we find subgroups to search within.
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * @param attrib The attribute within group objects that identify users.
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * @param value The user attribute value we are trying to compare for.
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * @param subgroupAttrs The attributes within group objects that identify subgroups.
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * Array of strings.
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * @param subgroupclasses The objectClass values used to identify groups (and
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * subgroups). apr_array_header_t *.
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * @param cur_subgroup_depth Current recursive depth during subgroup processing.
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * @param max_subgroup_depth Maximum depth of recursion allowed during subgroup
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * processing.
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * @tip Use this function to determine whether an attribute/value pair exists within a
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * starting group object or one of its nested subgroups. Typically this would be
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * used to determine LDAP nested group membership.
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * @deffunc int util_ldap_cache_check_subgroups(request_rec *r, util_ldap_connection_t
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * *ldc, const char *url, const char *dn,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * const char *attrib, const char value,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * char **subgroupAttrs, apr_array_header_t
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * *subgroupclasses, int cur_subgroup_depth, int
0e05808dc59a321566303084c84b9826a4353cefrederpj * max_subgroup_depth )
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes */
b08925593f214f621161742925dcf074a8047e0acovenerAPR_DECLARE_OPTIONAL_FN(int,uldap_cache_check_subgroups,(request_rec *r, util_ldap_connection_t *ldc,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes const char *url, const char *dn, const char *attrib, const char *value,
54d22ed1c429b903b029bbd62621f11a9e286137minfrin char **subgroupAttrs, apr_array_header_t *subgroupclasses,
465bb68501690d7a47bfd2a6129580047d76d8f1rederpj int cur_subgroup_depth, int max_subgroup_depth));
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholes
465bb68501690d7a47bfd2a6129580047d76d8f1rederpj/**
e8f95a682820a599fe41b22977010636be5c2717jim * Checks a username/password combination by binding to the LDAP server
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholes * @param r The request record
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholes * @param ldc The LDAP connection being used.
54d22ed1c429b903b029bbd62621f11a9e286137minfrin * @param url The URL of the LDAP connection - used for deciding which cache to use.
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * @param basedn The Base DN to search for the user in.
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * @param scope LDAP scope of the search.
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * @param attrs LDAP attributes to return in search.
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * @param filter The user to search for in the form of an LDAP filter. This filter must return
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * exactly one user for the check to be successful.
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * @param bindpw The user password to bind as.
ebe5305f8b22507374358f32b74d12fb50c05a25covener * @param binddn The DN of the user will be returned in this variable.
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * @param retvals The values corresponding to the attributes requested in the attrs array.
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * @tip The filter supplied will be searched for. If a single entry is returned, an attempt
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * is made to bind as that user. If this bind succeeds, the user is not validated.
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * @fn int util_ldap_cache_checkuserid(request_rec *r, util_ldap_connection_t *ldc,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * char *url, const char *basedn, int scope, char **attrs,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * char *filter, char *bindpw, char **binddn, char ***retvals)
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholesAPR_DECLARE_OPTIONAL_FN(int,uldap_cache_checkuserid,(request_rec *r, util_ldap_connection_t *ldc,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes const char *url, const char *basedn, int scope, char **attrs,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes const char *filter, const char *bindpw, const char **binddn, const char ***retvals));
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/**
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * Searches for a specified user object in an LDAP directory
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * @param r The request record
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * @param ldc The LDAP connection being used.
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * @param url The URL of the LDAP connection - used for deciding which cache to use.
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * @param basedn The Base DN to search for the user in.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * @param scope LDAP scope of the search.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * @param attrs LDAP attributes to return in search.
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * @param filter The user to search for in the form of an LDAP filter. This filter must return
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * exactly one user for the check to be successful.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * @param binddn The DN of the user will be returned in this variable.
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * @param retvals The values corresponding to the attributes requested in the attrs array.
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * @tip The filter supplied will be searched for. If a single entry is returned, an attempt
54d22ed1c429b903b029bbd62621f11a9e286137minfrin * is made to bind as that user. If this bind succeeds, the user is not validated.
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * @fn int util_ldap_cache_getuserdn(request_rec *r, util_ldap_connection_t *ldc,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * char *url, const char *basedn, int scope, char **attrs,
ebe5305f8b22507374358f32b74d12fb50c05a25covener * char *filter, char **binddn, char ***retvals)
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholesAPR_DECLARE_OPTIONAL_FN(int,uldap_cache_getuserdn,(request_rec *r, util_ldap_connection_t *ldc,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes const char *url, const char *basedn, int scope, char **attrs,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes const char *filter, const char **binddn, const char ***retvals));
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
54d22ed1c429b903b029bbd62621f11a9e286137minfrin/**
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * Checks if SSL support is available in mod_ldap
54d22ed1c429b903b029bbd62621f11a9e286137minfrin * @fn int util_ldap_ssl_supported(request_rec *r)
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholesAPR_DECLARE_OPTIONAL_FN(int,uldap_ssl_supported,(request_rec *r));
ebe5305f8b22507374358f32b74d12fb50c05a25covener
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes/* from ap_ldap_cache.c */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes/**
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * Init the LDAP cache
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * @param pool The pool to use to initialise the cache
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * @param reqsize The size of the shared memory segment to request. A size
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * of zero requests the max size possible from
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * apr_shmem_init()
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * @fn void util_ldap_cache_init(apr_pool_t *p, util_ldap_state_t *st)
b08925593f214f621161742925dcf074a8047e0acovener * @return The status code returned is the status code of the
b08925593f214f621161742925dcf074a8047e0acovener * apr_smmem_init() call. Regardless of the status, the cache
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * will be set up at least for in-process or in-thread operation.
7add8f7fb048534390571801b7794f71cd9e127abnicholes */
7add8f7fb048534390571801b7794f71cd9e127abnicholesapr_status_t util_ldap_cache_init(apr_pool_t *pool, util_ldap_state_t *st);
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem/* from ap_ldap_cache_mgr.c */
7add8f7fb048534390571801b7794f71cd9e127abnicholes
7add8f7fb048534390571801b7794f71cd9e127abnicholes/**
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * Display formatted stats for cache
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * @param The pool to allocate the returned string from
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * @tip This function returns a string allocated from the provided pool that describes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * various stats about the cache.
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * @fn char *util_ald_cache_display(apr_pool_t *pool, util_ldap_state_t *st)
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes */
7add8f7fb048534390571801b7794f71cd9e127abnicholeschar *util_ald_cache_display(request_rec *r, util_ldap_state_t *st);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes#ifdef __cplusplus
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes}
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes#endif
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes#endif /* AP_HAS_LDAP */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes#endif /* UTIL_LDAP_H */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes