Apache HTTPD
util_ldap.h
Go to the documentation of this file.
1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
22#ifndef UTIL_LDAP_H
23#define UTIL_LDAP_H
24
25/* APR header files */
26#include "apr.h"
27#include "apr_thread_mutex.h"
28#include "apr_thread_rwlock.h"
29#include "apr_tables.h"
30#include "apr_time.h"
31#include "apr_version.h"
32#if APR_MAJOR_VERSION < 2
33/* The LDAP API is currently only present in APR 1.x */
34#include "apr_ldap.h"
35#else
36#define APR_HAS_LDAP 0
37#endif
38
39#if APR_HAS_SHARED_MEMORY
40#include "apr_rmm.h"
41#include "apr_shm.h"
42#endif
43
44/* this whole thing disappears if LDAP is not enabled */
45#if APR_HAS_LDAP
46
47#if defined(LDAP_UNAVAILABLE) || APR_HAS_MICROSOFT_LDAPSDK
48#define AP_LDAP_IS_SERVER_DOWN(s) ((s) == LDAP_SERVER_DOWN \
49 ||(s) == LDAP_UNAVAILABLE)
50#else
51#define AP_LDAP_IS_SERVER_DOWN(s) ((s) == LDAP_SERVER_DOWN)
52#endif
53
54/* Apache header files */
55#include "ap_config.h"
56#include "httpd.h"
57#include "http_config.h"
58#include "http_core.h"
59#include "http_log.h"
60#include "http_protocol.h"
61#include "http_request.h"
62#include "apr_optional.h"
63
64/* Create a set of LDAP_DECLARE macros with appropriate export
65 * and import tags for the platform
66 */
67#if !defined(WIN32)
68#define LDAP_DECLARE(type) type
69#define LDAP_DECLARE_NONSTD(type) type
70#define LDAP_DECLARE_DATA
71#elif defined(LDAP_DECLARE_STATIC)
72#define LDAP_DECLARE(type) type __stdcall
73#define LDAP_DECLARE_NONSTD(type) type
74#define LDAP_DECLARE_DATA
75#elif defined(LDAP_DECLARE_EXPORT)
76#define LDAP_DECLARE(type) __declspec(dllexport) type __stdcall
77#define LDAP_DECLARE_NONSTD(type) __declspec(dllexport) type
78#define LDAP_DECLARE_DATA __declspec(dllexport)
79#else
80#define LDAP_DECLARE(type) __declspec(dllimport) type __stdcall
81#define LDAP_DECLARE_NONSTD(type) __declspec(dllimport) type
82#define LDAP_DECLARE_DATA __declspec(dllimport)
83#endif
84
85#if APR_HAS_MICROSOFT_LDAPSDK
86#define timeval l_timeval
87#endif
88
89#ifdef __cplusplus
90extern "C" {
91#endif
92
93/*
94 * LDAP Connections
95 */
96
97/* Values that the deref member can have */
98typedef enum {
99 never=LDAP_DEREF_NEVER,
100 searching=LDAP_DEREF_SEARCHING,
101 finding=LDAP_DEREF_FINDING,
102 always=LDAP_DEREF_ALWAYS
103} deref_options;
104
105/* Structure representing an LDAP connection */
106typedef struct util_ldap_connection_t {
107 LDAP *ldap;
108 apr_pool_t *pool; /* Pool from which this connection is created */
109#if APR_HAS_THREADS
110 apr_thread_mutex_t *lock; /* Lock to indicate this connection is in use */
111#endif
112
113 const char *host; /* Name of the LDAP server (or space separated list) */
114 int port; /* Port of the LDAP server */
115 deref_options deref; /* how to handle alias dereferening */
116
117 const char *binddn; /* DN to bind to server (can be NULL) */
118 const char *bindpw; /* Password to bind to server (can be NULL) */
119
120 int bound; /* Flag to indicate whether this connection is bound yet */
121
122 int secure; /* SSL/TLS mode of the connection */
123 apr_array_header_t *client_certs; /* Client certificates on this connection */
124
125 const char *reason; /* Reason for an error failure */
126
127 struct util_ldap_connection_t *next;
128 struct util_ldap_state_t *st; /* The LDAP vhost config this connection belongs to */
129 int keep; /* Will this connection be kept when it's unlocked */
130
131 int ChaseReferrals; /* [on|off] (default = AP_LDAP_CHASEREFERRALS_ON)*/
132 int ReferralHopLimit; /* # of referral hops to follow (default = AP_LDAP_DEFAULT_HOPLIMIT) */
133 apr_time_t freed; /* the time this conn was placed back in the pool */
134 apr_pool_t *rebind_pool; /* frequently cleared pool for rebind data */
135 int must_rebind; /* The connection was last bound with other then binddn/bindpw */
136 request_rec *r; /* request_rec used to find this util_ldap_connection_t */
137 apr_time_t last_backend_conn; /* the approximate time of the last backend LDAP request */
138} util_ldap_connection_t;
139
140typedef struct util_ldap_config_t {
141 int ChaseReferrals;
142 int ReferralHopLimit;
143 apr_array_header_t *client_certs; /* Client certificates */
144} util_ldap_config_t;
145
146/* LDAP cache state information */
147typedef struct util_ldap_state_t {
148 apr_pool_t *pool; /* pool from which this state is allocated */
149#if APR_HAS_THREADS
150 apr_thread_mutex_t *mutex; /* mutex lock for the connection list */
151#endif
152 apr_global_mutex_t *util_ldap_cache_lock;
153
154 apr_size_t cache_bytes; /* Size (in bytes) of shared memory cache */
155 char *cache_file; /* filename for shm */
156 long search_cache_ttl; /* TTL for search cache */
157 long search_cache_size; /* Size (in entries) of search cache */
158 long compare_cache_ttl; /* TTL for compare cache */
159 long compare_cache_size; /* Size (in entries) of compare cache */
160
161 struct util_ldap_connection_t *connections;
162 apr_array_header_t *global_certs; /* Global CA certificates */
163 int ssl_supported;
164 int secure;
165 int secure_set;
166 int verify_svr_cert;
167
168#if APR_HAS_SHARED_MEMORY
169 apr_shm_t *cache_shm;
170 apr_rmm_t *cache_rmm;
171#endif
172
173 /* cache ald */
174 void *util_ldap_cache;
175
176 long connectionTimeout;
177 struct timeval *opTimeout;
178
179 int debug_level; /* SDK debug level */
180 apr_interval_time_t connection_pool_ttl;
181 int retries; /* number of retries for failed bind/search/compare */
182 apr_interval_time_t retry_delay; /* delay between retries of failed bind/search/compare */
183} util_ldap_state_t;
184
185/* Used to store arrays of attribute labels/values. */
186struct mod_auth_ldap_groupattr_entry_t {
187 char *name;
188};
189
203 util_ldap_connection_t *ldc));
204
214APR_DECLARE_OPTIONAL_FN(void,uldap_connection_close,(util_ldap_connection_t *ldc));
215
226
244APR_DECLARE_OPTIONAL_FN(util_ldap_connection_t *,uldap_connection_find,(request_rec *r, const char *host, int port,
245 const char *binddn, const char *bindpw, deref_options deref,
246 int secure));
247
266APR_DECLARE_OPTIONAL_FN(int,uldap_cache_comparedn,(request_rec *r, util_ldap_connection_t *ldc,
267 const char *url, const char *dn, const char *reqdn,
268 int compare_dn_on_server));
269
284APR_DECLARE_OPTIONAL_FN(int,uldap_cache_compare,(request_rec *r, util_ldap_connection_t *ldc,
285 const char *url, const char *dn, const char *attrib, const char *value));
286
312APR_DECLARE_OPTIONAL_FN(int,uldap_cache_check_subgroups,(request_rec *r, util_ldap_connection_t *ldc,
313 const char *url, const char *dn, const char *attrib, const char *value,
314 char **subgroupAttrs, apr_array_header_t *subgroupclasses,
315 int cur_subgroup_depth, int max_subgroup_depth));
316
336APR_DECLARE_OPTIONAL_FN(int,uldap_cache_checkuserid,(request_rec *r, util_ldap_connection_t *ldc,
337 const char *url, const char *basedn, int scope, char **attrs,
338 const char *filter, const char *bindpw, const char **binddn, const char ***retvals));
339
358APR_DECLARE_OPTIONAL_FN(int,uldap_cache_getuserdn,(request_rec *r, util_ldap_connection_t *ldc,
359 const char *url, const char *basedn, int scope, char **attrs,
360 const char *filter, const char **binddn, const char ***retvals));
361
367
368/* from apr_ldap_cache.c */
369
381apr_status_t util_ldap_cache_init(apr_pool_t *pool, util_ldap_state_t *st);
382
383/* from apr_ldap_cache_mgr.c */
384
392char *util_ald_cache_display(request_rec *r, util_ldap_state_t *st);
393#ifdef __cplusplus
394}
395#endif
396#endif /* APR_HAS_LDAP */
397#endif /* UTIL_LDAP_H */
Symbol export macros and hook functions.
APR-UTIL registration of functions exported by modules.
APR-UTIL Relocatable Memory Management Routines.
APR Shared Memory Routines.
APR Table library.
APR Thread Mutex Routines.
APR Reader/Writer Lock Routines.
APR Time Library.
APR Versioning Interface.
static sem_id lock
Definition threadpriv.c:21
request_rec * r
const char apr_port_t port
Definition http_vhost.h:125
const char * host
Definition http_vhost.h:124
const char * url
Definition apr_escape.h:120
#define APR_DECLARE_OPTIONAL_FN(ret, name, args)
const char int apr_pool_t * pool
Definition apr_cstr.h:84
const char * value
Definition apr_env.h:51
int apr_status_t
Definition apr_errno.h:44
int reason
apr_int64_t apr_interval_time_t
Definition apr_time.h:55
apr_int64_t apr_time_t
Definition apr_time.h:45
Apache Configuration.
CORE HTTP Daemon.
Apache Logging library.
HTTP protocol handling.
Apache Request library.
HTTP Daemon routines.
char * name
A structure that represents the current request.
Definition httpd.h:845
static int uldap_cache_check_subgroups(request_rec *r, util_ldap_connection_t *ldc, const char *url, const char *dn, const char *attrib, const char *value, char **subgroupAttrs, apr_array_header_t *subgroupclasses, int cur_subgroup_depth, int max_subgroup_depth)
Definition util_ldap.c:1453
static apr_status_t uldap_connection_unbind(void *param)
Definition util_ldap.c:225
static int uldap_cache_comparedn(request_rec *r, util_ldap_connection_t *ldc, const char *url, const char *dn, const char *reqdn, int compare_dn_on_server)
Definition util_ldap.c:946
static int uldap_cache_compare(request_rec *r, util_ldap_connection_t *ldc, const char *url, const char *dn, const char *attrib, const char *value)
Definition util_ldap.c:1093
static void uldap_connection_close(util_ldap_connection_t *ldc)
Definition util_ldap.c:197
static int uldap_ssl_supported(request_rec *r)
Definition util_ldap.c:2180
static util_ldap_connection_t * uldap_connection_find(request_rec *r, const char *host, int port, const char *binddn, const char *bindpw, deref_options deref, int secure)
Definition util_ldap.c:742
static int uldap_connection_open(request_rec *r, util_ldap_connection_t *ldc)
Definition util_ldap.c:588
static int uldap_cache_checkuserid(request_rec *r, util_ldap_connection_t *ldc, const char *url, const char *basedn, int scope, char **attrs, const char *filter, const char *bindpw, const char **binddn, const char ***retvals)
Definition util_ldap.c:1697
static int uldap_cache_getuserdn(request_rec *r, util_ldap_connection_t *ldc, const char *url, const char *basedn, int scope, char **attrs, const char *filter, const char **binddn, const char ***retvals)
Definition util_ldap.c:1974