00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00022 #ifndef UTIL_LDAP_H
00023 #define UTIL_LDAP_H
00024
00025
00026 #include "apr.h"
00027 #include "apr_thread_mutex.h"
00028 #include "apr_thread_rwlock.h"
00029 #include "apr_tables.h"
00030 #include "apr_time.h"
00031 #include "apr_ldap.h"
00032
00033 #if APR_HAS_MICROSOFT_LDAPSDK
00034 #define AP_LDAP_IS_SERVER_DOWN(s) ((s) == LDAP_SERVER_DOWN \
00035 ||(s) == LDAP_UNAVAILABLE)
00036 #else
00037 #define AP_LDAP_IS_SERVER_DOWN(s) ((s) == LDAP_SERVER_DOWN)
00038 #endif
00039
00040 #if APR_HAS_SHARED_MEMORY
00041 #include "apr_rmm.h"
00042 #include "apr_shm.h"
00043 #endif
00044
00045
00046 #if APR_HAS_LDAP
00047
00048
00049 #include "ap_config.h"
00050 #include "httpd.h"
00051 #include "http_config.h"
00052 #include "http_core.h"
00053 #include "http_log.h"
00054 #include "http_protocol.h"
00055 #include "http_request.h"
00056 #include "apr_optional.h"
00057
00058
00059
00060
00061 #if !defined(WIN32)
00062 #define LDAP_DECLARE(type) type
00063 #define LDAP_DECLARE_NONSTD(type) type
00064 #define LDAP_DECLARE_DATA
00065 #elif defined(LDAP_DECLARE_STATIC)
00066 #define LDAP_DECLARE(type) type __stdcall
00067 #define LDAP_DECLARE_NONSTD(type) type
00068 #define LDAP_DECLARE_DATA
00069 #elif defined(LDAP_DECLARE_EXPORT)
00070 #define LDAP_DECLARE(type) __declspec(dllexport) type __stdcall
00071 #define LDAP_DECLARE_NONSTD(type) __declspec(dllexport) type
00072 #define LDAP_DECLARE_DATA __declspec(dllexport)
00073 #else
00074 #define LDAP_DECLARE(type) __declspec(dllimport) type __stdcall
00075 #define LDAP_DECLARE_NONSTD(type) __declspec(dllimport) type
00076 #define LDAP_DECLARE_DATA __declspec(dllimport)
00077 #endif
00078
00079 #ifdef __cplusplus
00080 extern "C" {
00081 #endif
00082
00083
00084
00085
00086
00087
00088 typedef enum {
00089 never=LDAP_DEREF_NEVER,
00090 searching=LDAP_DEREF_SEARCHING,
00091 finding=LDAP_DEREF_FINDING,
00092 always=LDAP_DEREF_ALWAYS
00093 } deref_options;
00094
00095
00096 typedef struct util_ldap_connection_t {
00097 LDAP *ldap;
00098 apr_pool_t *pool;
00099 #if APR_HAS_THREADS
00100 apr_thread_mutex_t *lock;
00101 #endif
00102 int bound;
00103
00104 const char *host;
00105 int port;
00106 deref_options deref;
00107
00108 const char *binddn;
00109 const char *bindpw;
00110
00111 int secure;
00112 apr_array_header_t *client_certs;
00113
00114 const char *reason;
00115
00116 struct util_ldap_connection_t *next;
00117 } util_ldap_connection_t;
00118
00119
00120 typedef struct util_ldap_state_t {
00121 apr_pool_t *pool;
00122 #if APR_HAS_THREADS
00123 apr_thread_mutex_t *mutex;
00124 #endif
00125 apr_global_mutex_t *util_ldap_cache_lock;
00126
00127 apr_size_t cache_bytes;
00128 char *cache_file;
00129 long search_cache_ttl;
00130 long search_cache_size;
00131 long compare_cache_ttl;
00132 long compare_cache_size;
00133
00134 struct util_ldap_connection_t *connections;
00135 int ssl_supported;
00136 apr_array_header_t *global_certs;
00137 apr_array_header_t *client_certs;
00138 int secure;
00139 int secure_set;
00140
00141 #if APR_HAS_SHARED_MEMORY
00142 apr_shm_t *cache_shm;
00143 apr_rmm_t *cache_rmm;
00144 #endif
00145
00146
00147 void *util_ldap_cache;
00148 char *lock_file;
00149 long connectionTimeout;
00150 int verify_svr_cert;
00151
00152 } util_ldap_state_t;
00153
00154
00167 APR_DECLARE_OPTIONAL_FN(int,uldap_connection_open,(request_rec *r,
00168 util_ldap_connection_t *ldc));
00169
00179 APR_DECLARE_OPTIONAL_FN(void,uldap_connection_close,(util_ldap_connection_t *ldc));
00180
00190 APR_DECLARE_OPTIONAL_FN(apr_status_t,uldap_connection_unbind,(void *param));
00191
00200 APR_DECLARE_OPTIONAL_FN(apr_status_t,uldap_connection_cleanup,(void *param));
00201
00219 APR_DECLARE_OPTIONAL_FN(util_ldap_connection_t *,uldap_connection_find,(request_rec *r, const char *host, int port,
00220 const char *binddn, const char *bindpw, deref_options deref,
00221 int secure));
00222
00241 APR_DECLARE_OPTIONAL_FN(int,uldap_cache_comparedn,(request_rec *r, util_ldap_connection_t *ldc,
00242 const char *url, const char *dn, const char *reqdn,
00243 int compare_dn_on_server));
00244
00258 APR_DECLARE_OPTIONAL_FN(int,uldap_cache_compare,(request_rec *r, util_ldap_connection_t *ldc,
00259 const char *url, const char *dn, const char *attrib, const char *value));
00260
00280 APR_DECLARE_OPTIONAL_FN(int,uldap_cache_checkuserid,(request_rec *r, util_ldap_connection_t *ldc,
00281 const char *url, const char *basedn, int scope, char **attrs,
00282 const char *filter, const char *bindpw, const char **binddn, const char ***retvals));
00283
00302 APR_DECLARE_OPTIONAL_FN(int,uldap_cache_getuserdn,(request_rec *r, util_ldap_connection_t *ldc,
00303 const char *url, const char *basedn, int scope, char **attrs,
00304 const char *filter, const char **binddn, const char ***retvals));
00305
00310 APR_DECLARE_OPTIONAL_FN(int,uldap_ssl_supported,(request_rec *r));
00311
00312
00313
00325 apr_status_t util_ldap_cache_init(apr_pool_t *pool, util_ldap_state_t *st);
00326
00327
00328
00336 char *util_ald_cache_display(request_rec *r, util_ldap_state_t *st);
00337 #ifdef __cplusplus
00338 }
00339 #endif
00340 #endif
00341 #endif