util_ldap.h revision 820e91baab4f9a45001d668698d2fae3501cb4b0
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"
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick#include "apr_ldap.h"
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#include "apr_ldap_rebind.h"
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#if APR_HAS_MICROSOFT_LDAPSDK
5c0419d51818eb02045cf923a9fe456127a44c60wrowe#define AP_LDAP_IS_SERVER_DOWN(s) ((s) == LDAP_SERVER_DOWN \
5c0419d51818eb02045cf923a9fe456127a44c60wrowe ||(s) == LDAP_UNAVAILABLE)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#else
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#define AP_LDAP_IS_SERVER_DOWN(s) ((s) == LDAP_SERVER_DOWN)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#endif
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#if APR_HAS_SHARED_MEMORY
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#include "apr_rmm.h"
d266c3777146d36a4c23c17aad6f153aebea1bf4jorton#include "apr_shm.h"
d266c3777146d36a4c23c17aad6f153aebea1bf4jorton#endif
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholes
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholes/* this whole thing disappears if LDAP is not enabled */
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholes#if APR_HAS_LDAP
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholes
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholes/* Apache header files */
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholes#include "ap_config.h"
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholes#include "httpd.h"
cd3bbd6d2df78d6c75e5d159a81ef8bdd5f70df9trawick#include "http_config.h"
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#include "http_core.h"
0f60998368b493f90120180a93fc2e1e74490872covener#include "http_log.h"
0f60998368b493f90120180a93fc2e1e74490872covener#include "http_protocol.h"
0f60998368b493f90120180a93fc2e1e74490872covener#include "http_request.h"
0f60998368b493f90120180a93fc2e1e74490872covener#include "apr_optional.h"
0f60998368b493f90120180a93fc2e1e74490872covener
0f60998368b493f90120180a93fc2e1e74490872covener/* Create a set of LDAP_DECLARE macros with appropriate export
0f60998368b493f90120180a93fc2e1e74490872covener * and import tags for the platform
0f60998368b493f90120180a93fc2e1e74490872covener */
87587593f1a53030e840acc0dec6cc881022ea40covener#if !defined(WIN32)
87587593f1a53030e840acc0dec6cc881022ea40covener#define LDAP_DECLARE(type) type
87587593f1a53030e840acc0dec6cc881022ea40covener#define LDAP_DECLARE_NONSTD(type) type
87587593f1a53030e840acc0dec6cc881022ea40covener#define LDAP_DECLARE_DATA
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#elif defined(LDAP_DECLARE_STATIC)
43997561b2302d13dee973998e77743a3ddd2374trawick#define LDAP_DECLARE(type) type __stdcall
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#define LDAP_DECLARE_NONSTD(type) type
0568280364eb026393be492ebc732795c4934643jorton#define LDAP_DECLARE_DATA
0568280364eb026393be492ebc732795c4934643jorton#elif defined(LDAP_DECLARE_EXPORT)
0568280364eb026393be492ebc732795c4934643jorton#define LDAP_DECLARE(type) __declspec(dllexport) type __stdcall
0568280364eb026393be492ebc732795c4934643jorton#define LDAP_DECLARE_NONSTD(type) __declspec(dllexport) type
0568280364eb026393be492ebc732795c4934643jorton#define LDAP_DECLARE_DATA __declspec(dllexport)
0568280364eb026393be492ebc732795c4934643jorton#else
0568280364eb026393be492ebc732795c4934643jorton#define LDAP_DECLARE(type) __declspec(dllimport) type __stdcall
0568280364eb026393be492ebc732795c4934643jorton#define LDAP_DECLARE_NONSTD(type) __declspec(dllimport) type
0568280364eb026393be492ebc732795c4934643jorton#define LDAP_DECLARE_DATA __declspec(dllimport)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#endif
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener#ifdef __cplusplus
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesextern "C" {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#endif
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/*
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * LDAP Connections
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/* Values that the deref member can have */
796e4a7141265d8ed7036e4628161c6eafb2a789jortontypedef enum {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes never=LDAP_DEREF_NEVER,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes searching=LDAP_DEREF_SEARCHING,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes finding=LDAP_DEREF_FINDING,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes always=LDAP_DEREF_ALWAYS
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes} deref_options;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/* Structure representing an LDAP connection */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholestypedef 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 int bound; /* Flag to indicate whether this connection is bound yet */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe const char *host; /* Name of the LDAP server (or space separated list) */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes int port; /* Port of the LDAP server */
95b6fe1346805e1731e6e97c15d569c73be22cf7minfrin deref_options deref; /* how to handle alias dereferening */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes const char *binddn; /* DN to bind to server (can be NULL) */
95b6fe1346805e1731e6e97c15d569c73be22cf7minfrin const char *bindpw; /* Password to bind to server (can be NULL) */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
95b6fe1346805e1731e6e97c15d569c73be22cf7minfrin 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;
95b6fe1346805e1731e6e97c15d569c73be22cf7minfrin struct util_ldap_state_t *st; /* The LDAP vhost config this connection belongs to */
95b6fe1346805e1731e6e97c15d569c73be22cf7minfrin int keep; /* Will this connection be kept when it's unlocked */
95b6fe1346805e1731e6e97c15d569c73be22cf7minfrin
a1790fb35c4b352dab721370985c623a9f8f5062rpluem int ChaseReferrals; /* [on|off] (default = AP_LDAP_CHASEREFERRALS_ON)*/
713a2b68bac4aeb1e9c48785006c0732451039depquerna int ReferralHopLimit; /* # of referral hops to follow (default = AP_LDAP_DEFAULT_HOPLIMIT) */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes} util_ldap_connection_t;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholestypedef struct util_ldap_config_t {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes int ChaseReferrals;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes int ReferralHopLimit;
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe apr_array_header_t *client_certs; /* Client certificates */
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe} util_ldap_config_t;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/* LDAP cache state information */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholestypedef struct util_ldap_state_t {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes apr_pool_t *pool; /* pool from which this state is allocated */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#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;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes apr_size_t cache_bytes; /* Size (in bytes) of shared memory cache */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes char *cache_file; /* filename for shm */
f43b67c5a9d29b572eac916f8335cedc80c908bebnicholes 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 */
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe long compare_cache_size; /* Size (in entries) of compare cache */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes struct util_ldap_connection_t *connections;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes int ssl_supported;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes apr_array_header_t *global_certs; /* Global CA certificates */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes int secure;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes int secure_set;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#if APR_HAS_SHARED_MEMORY
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes apr_shm_t *cache_shm;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes apr_rmm_t *cache_rmm;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#endif
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* cache ald */
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener void *util_ldap_cache;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener long connectionTimeout;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener int verify_svr_cert;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener int debug_level; /* SDK debug level */
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener struct timeval *opTimeout;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener} util_ldap_state_t;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener/* Used to store arrays of attribute labels/values. */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstruct mod_auth_ldap_groupattr_entry_t {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes char *name;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes};
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/**
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * Open a connection to an LDAP server
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * @param ldc A structure containing the expanded details of the server
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * to connect to. The handle to the LDAP connection is returned
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe * as ldc->ldap.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * @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 */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesAPR_DECLARE_OPTIONAL_FN(int,uldap_connection_open,(request_rec *r,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes util_ldap_connection_t *ldc));
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
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
1f299703465bd9975d94e9f229f76af807442de2covener * structure, using apr_ldap_open_connection().
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * @fn util_ldap_close_connection(util_ldap_connection_t *ldc)
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener */
7af19efc4667363f74d332a8d010b49e88d56fd5trawickAPR_DECLARE_OPTIONAL_FN(void,uldap_connection_close,(util_ldap_connection_t *ldc));
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe/**
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
9ad7b260be233be7d7b5576979825cac72e15498rederpj * the server. It is used during error conditions, to bring the LDAP
cceddc0b6c0fdaed0c73abda39975bb1d388243acovener * connection back to a known state.
cceddc0b6c0fdaed0c73abda39975bb1d388243acovener * @fn apr_status_t util_ldap_connection_unbind(util_ldap_connection_t *ldc)
cceddc0b6c0fdaed0c73abda39975bb1d388243acovener */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesAPR_DECLARE_OPTIONAL_FN(apr_status_t,uldap_connection_unbind,(void *param));
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
f43b67c5a9d29b572eac916f8335cedc80c908bebnicholes/**
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * Cleanup 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 functions unbinds and closes the connection to the LDAP server
f2be127030aa4190033084f0a6add531c9bc41desf * @fn apr_status_t util_ldap_connection_cleanup(util_ldap_connection_t *ldc)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesAPR_DECLARE_OPTIONAL_FN(apr_status_t,uldap_connection_cleanup,(void *param));
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
f2be127030aa4190033084f0a6add531c9bc41desf/**
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * Find a connection in a list of connections
3e6d7277b90d3011db832139afc20efb5f17e203rederpj * @param r The request record
3e6d7277b90d3011db832139afc20efb5f17e203rederpj * @param host The hostname to connect to (multiple hosts space separated)
3e6d7277b90d3011db832139afc20efb5f17e203rederpj * @param port The port to connect to
3e6d7277b90d3011db832139afc20efb5f17e203rederpj * @param binddn The DN to bind with
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * @param bindpw The password to bind with
f43b67c5a9d29b572eac916f8335cedc80c908bebnicholes * @param deref The dereferencing behavior
e8f95a682820a599fe41b22977010636be5c2717jim * @param secure use SSL on the connection
f2be127030aa4190033084f0a6add531c9bc41desf * @tip Once a connection is found and returned, a lock will be acquired to
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * lock that particular connection, so that another thread does not try and
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * use this connection while it is busy. Once you are finished with a connection,
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * apr_ldap_connection_close() must be called to release this connection.
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * @fn util_ldap_connection_t *util_ldap_connection_find(request_rec *r, const char *host, int port,
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * const char *binddn, const char *bindpw, deref_options deref,
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * int netscapessl, int starttls)
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener */
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovenerAPR_DECLARE_OPTIONAL_FN(util_ldap_connection_t *,uldap_connection_find,(request_rec *r, const char *host, int port,
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener const char *binddn, const char *bindpw, deref_options deref,
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener int secure));
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener/**
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * Compare two DNs for sameness
6683642c1e0032eeeed5f99e8c14880692ef84c5sf * @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.
6683642c1e0032eeeed5f99e8c14880692ef84c5sf * @param reqdn The DN to compare the first DN to.
6683642c1e0032eeeed5f99e8c14880692ef84c5sf * @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.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * @param url The URL of the LDAP connection - used for deciding which cache to use.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * @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,
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener const char *url, const char *dn, const char *attrib, const char *value));
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
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.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * @param subgroupAttrs The attributes within group objects that identify subgroups.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * Array of strings.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * @param subgroupclasses The objectClass values used to identify groups (and
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * subgroups). apr_array_header_t *.
0e05808dc59a321566303084c84b9826a4353cefrederpj * @param cur_subgroup_depth Current recursive depth during subgroup processing.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * @param max_subgroup_depth Maximum depth of recursion allowed during subgroup
b08925593f214f621161742925dcf074a8047e0acovener * processing.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * @tip Use this function to determine whether an attribute/value pair exists within a
54d22ed1c429b903b029bbd62621f11a9e286137minfrin * starting group object or one of its nested subgroups. Typically this would be
465bb68501690d7a47bfd2a6129580047d76d8f1rederpj * used to determine LDAP nested group membership.
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf * @deffunc int util_ldap_cache_check_subgroups(request_rec *r, util_ldap_connection_t
465bb68501690d7a47bfd2a6129580047d76d8f1rederpj * *ldc, const char *url, const char *dn,
e8f95a682820a599fe41b22977010636be5c2717jim * const char *attrib, const char value,
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholes * char **subgroupAttrs, apr_array_header_t
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholes * *subgroupclasses, int cur_subgroup_depth, int
54d22ed1c429b903b029bbd62621f11a9e286137minfrin * max_subgroup_depth )
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholesAPR_DECLARE_OPTIONAL_FN(int,uldap_cache_check_subgroups,(request_rec *r, util_ldap_connection_t *ldc,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes const char *url, const char *dn, const char *attrib, const char *value,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes char **subgroupAttrs, apr_array_header_t *subgroupclasses,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes int cur_subgroup_depth, int max_subgroup_depth));
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
ebe5305f8b22507374358f32b74d12fb50c05a25covener/**
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * Checks a username/password combination by binding to the LDAP server
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.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * @param basedn The Base DN to search for the user in.
513b324e774c559b579896df131fd7c8471ed529rederpj * @param scope LDAP scope of the search.
513b324e774c559b579896df131fd7c8471ed529rederpj * @param attrs LDAP attributes to return in search.
513b324e774c559b579896df131fd7c8471ed529rederpj * @param filter The user to search for in the form of an LDAP filter. This filter must return
513b324e774c559b579896df131fd7c8471ed529rederpj * exactly one user for the check to be successful.
513b324e774c559b579896df131fd7c8471ed529rederpj * @param bindpw The user password to bind as.
513b324e774c559b579896df131fd7c8471ed529rederpj * @param binddn The DN of the user will be returned in this variable.
513b324e774c559b579896df131fd7c8471ed529rederpj * @param retvals The values corresponding to the attributes requested in the attrs array.
513b324e774c559b579896df131fd7c8471ed529rederpj * @tip The filter supplied will be searched for. If a single entry is returned, an attempt
513b324e774c559b579896df131fd7c8471ed529rederpj * is made to bind as that user. If this bind succeeds, the user is not validated.
513b324e774c559b579896df131fd7c8471ed529rederpj * @fn int util_ldap_cache_checkuserid(request_rec *r, util_ldap_connection_t *ldc,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * char *url, const char *basedn, int scope, char **attrs,
02fd88c85a9850109753b87612955ad372de1575sf * char *filter, char *bindpw, char **binddn, char ***retvals)
02fd88c85a9850109753b87612955ad372de1575sf */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesAPR_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
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes/**
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.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * @param basedn The Base DN to search for the user in.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * @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
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * exactly one user for the check to be successful.
707f6d077f73cc948deead8df5b40ea42c1eaa78covener * @param binddn The DN of the user will be returned in this variable.
707f6d077f73cc948deead8df5b40ea42c1eaa78covener * @param retvals The values corresponding to the attributes requested in the attrs array.
707f6d077f73cc948deead8df5b40ea42c1eaa78covener * @tip The filter supplied will be searched for. If a single entry is returned, an attempt
707f6d077f73cc948deead8df5b40ea42c1eaa78covener * is made to bind as that user. If this bind succeeds, the user is not validated.
707f6d077f73cc948deead8df5b40ea42c1eaa78covener * @fn int util_ldap_cache_getuserdn(request_rec *r, util_ldap_connection_t *ldc,
707f6d077f73cc948deead8df5b40ea42c1eaa78covener * char *url, const char *basedn, int scope, char **attrs,
707f6d077f73cc948deead8df5b40ea42c1eaa78covener * char *filter, char **binddn, char ***retvals)
707f6d077f73cc948deead8df5b40ea42c1eaa78covener */
707f6d077f73cc948deead8df5b40ea42c1eaa78covenerAPR_DECLARE_OPTIONAL_FN(int,uldap_cache_getuserdn,(request_rec *r, util_ldap_connection_t *ldc,
707f6d077f73cc948deead8df5b40ea42c1eaa78covener const char *url, const char *basedn, int scope, char **attrs,
9ad7b260be233be7d7b5576979825cac72e15498rederpj const char *filter, const char **binddn, const char ***retvals));
9ad7b260be233be7d7b5576979825cac72e15498rederpj
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes/**
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 apr_ldap_cache.c */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes/**
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * Init the LDAP cache
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * @param pool The pool to use to initialise the cache
54d22ed1c429b903b029bbd62621f11a9e286137minfrin * @param reqsize The size of the shared memory segment to request. A size
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * of zero requests the max size possible from
54d22ed1c429b903b029bbd62621f11a9e286137minfrin * apr_shmem_init()
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * @fn void util_ldap_cache_init(apr_pool_t *p, util_ldap_state_t *st)
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * @return The status code returned is the status code of the
ebe5305f8b22507374358f32b74d12fb50c05a25covener * apr_smmem_init() call. Regardless of the status, the cache
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * will be set up at least for in-process or in-thread operation.
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholesapr_status_t util_ldap_cache_init(apr_pool_t *pool, util_ldap_state_t *st);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes/* from apr_ldap_cache_mgr.c */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes/**
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * Display formatted stats for cache
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * @param The pool to allocate the returned string from
b08925593f214f621161742925dcf074a8047e0acovener * @tip This function returns a string allocated from the provided pool that describes
b08925593f214f621161742925dcf074a8047e0acovener * various stats about the cache.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * @fn char *util_ald_cache_display(apr_pool_t *pool, util_ldap_state_t *st)
707f6d077f73cc948deead8df5b40ea42c1eaa78covener */
707f6d077f73cc948deead8df5b40ea42c1eaa78covenerchar *util_ald_cache_display(request_rec *r, util_ldap_state_t *st);
9ad7b260be233be7d7b5576979825cac72e15498rederpj#ifdef __cplusplus
707f6d077f73cc948deead8df5b40ea42c1eaa78covener}
707f6d077f73cc948deead8df5b40ea42c1eaa78covener#endif
9ad7b260be233be7d7b5576979825cac72e15498rederpj#endif /* APR_HAS_LDAP */
707f6d077f73cc948deead8df5b40ea42c1eaa78covener#endif /* UTIL_LDAP_H */
707f6d077f73cc948deead8df5b40ea42c1eaa78covener