Main Page | Modules | Namespace List | Class List | Directories | File List | Class Members | File Members | Related Pages | Examples

util_ldap.h

Go to the documentation of this file.
00001 /* Licensed to the Apache Software Foundation (ASF) under one or more
00002  * contributor license agreements.  See the NOTICE file distributed with
00003  * this work for additional information regarding copyright ownership.
00004  * The ASF licenses this file to You under the Apache License, Version 2.0
00005  * (the "License"); you may not use this file except in compliance with
00006  * the License.  You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00022 #ifndef UTIL_LDAP_H
00023 #define UTIL_LDAP_H
00024 
00025 /* APR header files */
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 /* this whole thing disappears if LDAP is not enabled */
00046 #if APR_HAS_LDAP
00047 
00048 /* Apache header files */
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 /* Create a set of LDAP_DECLARE macros with appropriate export 
00059  * and import tags for the platform
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  * LDAP Connections
00085  */
00086 
00087 /* Values that the deref member can have */
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 /* Structure representing an LDAP connection */
00096 typedef struct util_ldap_connection_t {
00097     LDAP *ldap;
00098     apr_pool_t *pool;                   /* Pool from which this connection is created */
00099 #if APR_HAS_THREADS
00100     apr_thread_mutex_t *lock;           /* Lock to indicate this connection is in use */
00101 #endif
00102     int bound;                          /* Flag to indicate whether this connection is bound yet */
00103 
00104     const char *host;                   /* Name of the LDAP server (or space separated list) */
00105     int port;                           /* Port of the LDAP server */
00106     deref_options deref;                /* how to handle alias dereferening */
00107 
00108     const char *binddn;                 /* DN to bind to server (can be NULL) */
00109     const char *bindpw;                 /* Password to bind to server (can be NULL) */
00110 
00111     int secure;                         /* SSL/TLS mode of the connection */
00112     apr_array_header_t *client_certs;   /* Client certificates on this connection */
00113 
00114     const char *reason;                 /* Reason for an error failure */
00115 
00116     struct util_ldap_connection_t *next;
00117 } util_ldap_connection_t;
00118 
00119 /* LDAP cache state information */ 
00120 typedef struct util_ldap_state_t {
00121     apr_pool_t *pool;           /* pool from which this state is allocated */
00122 #if APR_HAS_THREADS
00123     apr_thread_mutex_t *mutex;          /* mutex lock for the connection list */
00124 #endif
00125     apr_global_mutex_t *util_ldap_cache_lock;
00126 
00127     apr_size_t cache_bytes;     /* Size (in bytes) of shared memory cache */
00128     char *cache_file;           /* filename for shm */
00129     long search_cache_ttl;      /* TTL for search cache */
00130     long search_cache_size;     /* Size (in entries) of search cache */
00131     long compare_cache_ttl;     /* TTL for compare cache */
00132     long compare_cache_size;    /* Size (in entries) of compare cache */
00133 
00134     struct util_ldap_connection_t *connections;
00135     int   ssl_supported;
00136     apr_array_header_t *global_certs;  /* Global CA certificates */
00137     apr_array_header_t *client_certs;  /* Client certificates */
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     /* cache ald */
00147     void *util_ldap_cache;
00148     char *lock_file;           /* filename for shm lock mutex */
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 /* from apr_ldap_cache.c */
00313 
00325 apr_status_t util_ldap_cache_init(apr_pool_t *pool, util_ldap_state_t *st);
00326 
00327 /* from apr_ldap_cache_mgr.c */
00328 
00336 char *util_ald_cache_display(request_rec *r, util_ldap_state_t *st);
00337 #ifdef __cplusplus
00338 }
00339 #endif
00340 #endif /* APR_HAS_LDAP */
00341 #endif /* UTIL_LDAP_H */

© sourcejam.com 2005-2008