util_ldap.h revision 3f5585f7f4a7d74f2f94ec729ea8c1879d419e35
b43f840409794ed298e8634f6284741f193b6c4ftakashi/* Licensed to the Apache Software Foundation (ASF) under one or more
b43f840409794ed298e8634f6284741f193b6c4ftakashi * contributor license agreements. See the NOTICE file distributed with
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd * this work for additional information regarding copyright ownership.
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd * The ASF licenses this file to You under the Apache License, Version 2.0
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd * (the "License"); you may not use this file except in compliance with
b43f840409794ed298e8634f6284741f193b6c4ftakashi * the License. You may obtain a copy of the License at
b43f840409794ed298e8634f6284741f193b6c4ftakashi *
b43f840409794ed298e8634f6284741f193b6c4ftakashi * http://www.apache.org/licenses/LICENSE-2.0
b43f840409794ed298e8634f6284741f193b6c4ftakashi *
96ad5d81ee4a2cc66a4ae19893efc8aa6d06fae7jailletc * Unless required by applicable law or agreed to in writing, software
b43f840409794ed298e8634f6284741f193b6c4ftakashi * distributed under the License is distributed on an "AS IS" BASIS,
b43f840409794ed298e8634f6284741f193b6c4ftakashi * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * See the License for the specific language governing permissions and
2e545ce2450a9953665f701bb05350f0d3f26275nd * limitations under the License.
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen */
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen
b43f840409794ed298e8634f6284741f193b6c4ftakashi/**
b43f840409794ed298e8634f6284741f193b6c4ftakashi * @file util_ldap.h
b43f840409794ed298e8634f6284741f193b6c4ftakashi * @brief Apache LDAP library
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen */
b43f840409794ed298e8634f6284741f193b6c4ftakashi
b43f840409794ed298e8634f6284741f193b6c4ftakashi#ifndef UTIL_LDAP_H
b43f840409794ed298e8634f6284741f193b6c4ftakashi#define UTIL_LDAP_H
b43f840409794ed298e8634f6284741f193b6c4ftakashi
b43f840409794ed298e8634f6284741f193b6c4ftakashi/* APR header files */
b43f840409794ed298e8634f6284741f193b6c4ftakashi#include "apr.h"
b43f840409794ed298e8634f6284741f193b6c4ftakashi#include "apr_thread_mutex.h"
b43f840409794ed298e8634f6284741f193b6c4ftakashi#include "apr_thread_rwlock.h"
b43f840409794ed298e8634f6284741f193b6c4ftakashi#include "apr_tables.h"
b43f840409794ed298e8634f6284741f193b6c4ftakashi#include "apr_time.h"
a99c5d4cc3cab6a62b04d52000dbc22ce1fa2d94coar#include "apr_ldap.h"
b43f840409794ed298e8634f6284741f193b6c4ftakashi
b43f840409794ed298e8634f6284741f193b6c4ftakashi#if APR_HAS_SHARED_MEMORY
b43f840409794ed298e8634f6284741f193b6c4ftakashi#include "apr_rmm.h"
b43f840409794ed298e8634f6284741f193b6c4ftakashi#include "apr_shm.h"
b43f840409794ed298e8634f6284741f193b6c4ftakashi#endif
b43f840409794ed298e8634f6284741f193b6c4ftakashi
b43f840409794ed298e8634f6284741f193b6c4ftakashi/* this whole thing disappears if LDAP is not enabled */
a99c5d4cc3cab6a62b04d52000dbc22ce1fa2d94coar#if APR_HAS_LDAP
a99c5d4cc3cab6a62b04d52000dbc22ce1fa2d94coar
a99c5d4cc3cab6a62b04d52000dbc22ce1fa2d94coar/* Apache header files */
a99c5d4cc3cab6a62b04d52000dbc22ce1fa2d94coar#include "ap_config.h"
b43f840409794ed298e8634f6284741f193b6c4ftakashi#include "httpd.h"
b43f840409794ed298e8634f6284741f193b6c4ftakashi#include "http_config.h"
b43f840409794ed298e8634f6284741f193b6c4ftakashi#include "http_core.h"
b43f840409794ed298e8634f6284741f193b6c4ftakashi#include "http_log.h"
b43f840409794ed298e8634f6284741f193b6c4ftakashi#include "http_protocol.h"
a99c5d4cc3cab6a62b04d52000dbc22ce1fa2d94coar#include "http_request.h"
a99c5d4cc3cab6a62b04d52000dbc22ce1fa2d94coar#include "apr_optional.h"
a99c5d4cc3cab6a62b04d52000dbc22ce1fa2d94coar
b43f840409794ed298e8634f6284741f193b6c4ftakashi/* Create a set of LDAP_DECLARE macros with appropriate export
b43f840409794ed298e8634f6284741f193b6c4ftakashi * and import tags for the platform
b43f840409794ed298e8634f6284741f193b6c4ftakashi */
b43f840409794ed298e8634f6284741f193b6c4ftakashi#if !defined(WIN32)
b43f840409794ed298e8634f6284741f193b6c4ftakashi#define LDAP_DECLARE(type) type
b43f840409794ed298e8634f6284741f193b6c4ftakashi#define LDAP_DECLARE_NONSTD(type) type
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh#define LDAP_DECLARE_DATA
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar#elif defined(LDAP_DECLARE_STATIC)
b43f840409794ed298e8634f6284741f193b6c4ftakashi#define LDAP_DECLARE(type) type __stdcall
b43f840409794ed298e8634f6284741f193b6c4ftakashi#define LDAP_DECLARE_NONSTD(type) type
b43f840409794ed298e8634f6284741f193b6c4ftakashi#define LDAP_DECLARE_DATA
b43f840409794ed298e8634f6284741f193b6c4ftakashi#elif defined(LDAP_DECLARE_EXPORT)
b43f840409794ed298e8634f6284741f193b6c4ftakashi#define LDAP_DECLARE(type) __declspec(dllexport) type __stdcall
b43f840409794ed298e8634f6284741f193b6c4ftakashi#define LDAP_DECLARE_NONSTD(type) __declspec(dllexport) type
b43f840409794ed298e8634f6284741f193b6c4ftakashi#define LDAP_DECLARE_DATA __declspec(dllexport)
b43f840409794ed298e8634f6284741f193b6c4ftakashi#else
b43f840409794ed298e8634f6284741f193b6c4ftakashi#define LDAP_DECLARE(type) __declspec(dllimport) type __stdcall
b43f840409794ed298e8634f6284741f193b6c4ftakashi#define LDAP_DECLARE_NONSTD(type) __declspec(dllimport) type
a99c5d4cc3cab6a62b04d52000dbc22ce1fa2d94coar#define LDAP_DECLARE_DATA __declspec(dllimport)
b43f840409794ed298e8634f6284741f193b6c4ftakashi#endif
b43f840409794ed298e8634f6284741f193b6c4ftakashi
b43f840409794ed298e8634f6284741f193b6c4ftakashi#ifdef __cplusplus
b43f840409794ed298e8634f6284741f193b6c4ftakashiextern "C" {
b43f840409794ed298e8634f6284741f193b6c4ftakashi#endif
b43f840409794ed298e8634f6284741f193b6c4ftakashi
727872d18412fc021f03969b8641810d8896820bhumbedooh/*
0d0ba3a410038e179b695446bb149cce6264e0abnd * LDAP Connections
727872d18412fc021f03969b8641810d8896820bhumbedooh */
cc7e1025de9ac63bd4db6fe7f71c158b2cf09fe4humbedooh
0d0ba3a410038e179b695446bb149cce6264e0abnd/* Values that the deref member can have */
cc7e1025de9ac63bd4db6fe7f71c158b2cf09fe4humbedoohtypedef enum {
727872d18412fc021f03969b8641810d8896820bhumbedooh never=LDAP_DEREF_NEVER,
0d0ba3a410038e179b695446bb149cce6264e0abnd searching=LDAP_DEREF_SEARCHING,
0d0ba3a410038e179b695446bb149cce6264e0abnd finding=LDAP_DEREF_FINDING,
0d0ba3a410038e179b695446bb149cce6264e0abnd always=LDAP_DEREF_ALWAYS
ac082aefa89416cbdc9a1836eaf3bed9698201c8humbedooh} deref_options;
0d0ba3a410038e179b695446bb149cce6264e0abnd
0d0ba3a410038e179b695446bb149cce6264e0abnd/* Structure representing an LDAP connection */
0d0ba3a410038e179b695446bb149cce6264e0abndtypedef struct util_ldap_connection_t {
727872d18412fc021f03969b8641810d8896820bhumbedooh LDAP *ldap;
0d0ba3a410038e179b695446bb149cce6264e0abnd apr_pool_t *pool; /* Pool from which this connection is created */
0d0ba3a410038e179b695446bb149cce6264e0abnd#if APR_HAS_THREADS
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh apr_thread_mutex_t *lock; /* Lock to indicate this connection is in use */
205f749042ed530040a4f0080dbcb47ceae8a374rjung#endif
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen int bound; /* Flag to indicate whether this connection is bound yet */
0d0ba3a410038e179b695446bb149cce6264e0abnd
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd const char *host; /* Name of the LDAP server (or space separated list) */
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd int port; /* Port of the LDAP server */
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd deref_options deref; /* how to handle alias dereferening */
b43f840409794ed298e8634f6284741f193b6c4ftakashi
const char *binddn; /* DN to bind to server (can be NULL) */
const char *bindpw; /* Password to bind to server (can be NULL) */
int secure; /* SSL/TLS mode of the connection */
apr_array_header_t *client_certs; /* Client certificates on this connection */
const char *reason; /* Reason for an error failure */
struct util_ldap_connection_t *next;
} util_ldap_connection_t;
/* LDAP cache state information */
typedef struct util_ldap_state_t {
apr_pool_t *pool; /* pool from which this state is allocated */
#if APR_HAS_THREADS
apr_thread_mutex_t *mutex; /* mutex lock for the connection list */
#endif
apr_global_mutex_t *util_ldap_cache_lock;
apr_size_t cache_bytes; /* Size (in bytes) of shared memory cache */
char *cache_file; /* filename for shm */
long search_cache_ttl; /* TTL for search cache */
long search_cache_size; /* Size (in entries) of search cache */
long compare_cache_ttl; /* TTL for compare cache */
long compare_cache_size; /* Size (in entries) of compare cache */
struct util_ldap_connection_t *connections;
int ssl_supported;
apr_array_header_t *global_certs; /* Global CA certificates */
apr_array_header_t *client_certs; /* Client certificates */
int secure;
int secure_set;
#if APR_HAS_SHARED_MEMORY
apr_shm_t *cache_shm;
apr_rmm_t *cache_rmm;
#endif
/* cache ald */
void *util_ldap_cache;
char *lock_file; /* filename for shm lock mutex */
long connectionTimeout;
int verify_svr_cert;
} util_ldap_state_t;
/* Used to store arrays of attribute labels/values. */
struct mod_auth_ldap_groupattr_entry_t {
char *name;
};
/**
* Open a connection to an LDAP server
* @param ldc A structure containing the expanded details of the server
* to connect to. The handle to the LDAP connection is returned
* as ldc->ldap.
* @tip This function connects to the LDAP server and binds. It does not
* connect if already connected (ldc->ldap != NULL). Does not bind
* if already bound.
* @return If successful LDAP_SUCCESS is returned.
* @fn int util_ldap_connection_open(request_rec *r,
* util_ldap_connection_t *ldc)
*/
APR_DECLARE_OPTIONAL_FN(int,uldap_connection_open,(request_rec *r,
util_ldap_connection_t *ldc));
/**
* Close a connection to an LDAP server
* @param ldc A structure containing the expanded details of the server
* that was connected.
* @tip This function unbinds from the LDAP server, and clears ldc->ldap.
* It is possible to rebind to this server again using the same ldc
* structure, using apr_ldap_open_connection().
* @fn util_ldap_close_connection(util_ldap_connection_t *ldc)
*/
APR_DECLARE_OPTIONAL_FN(void,uldap_connection_close,(util_ldap_connection_t *ldc));
/**
* Unbind a connection to an LDAP server
* @param ldc A structure containing the expanded details of the server
* that was connected.
* @tip This function unbinds the LDAP connection, and disconnects from
* the server. It is used during error conditions, to bring the LDAP
* connection back to a known state.
* @fn apr_status_t util_ldap_connection_unbind(util_ldap_connection_t *ldc)
*/
APR_DECLARE_OPTIONAL_FN(apr_status_t,uldap_connection_unbind,(void *param));
/**
* Cleanup a connection to an LDAP server
* @param ldc A structure containing the expanded details of the server
* that was connected.
* @tip This function is registered with the pool cleanup to close down the
* LDAP connections when the server is finished with them.
* @fn apr_status_t util_ldap_connection_cleanup(util_ldap_connection_t *ldc)
*/
APR_DECLARE_OPTIONAL_FN(apr_status_t,uldap_connection_cleanup,(void *param));
/**
* Find a connection in a list of connections
* @param r The request record
* @param host The hostname to connect to (multiple hosts space separated)
* @param port The port to connect to
* @param binddn The DN to bind with
* @param bindpw The password to bind with
* @param deref The dereferencing behavior
* @param secure use SSL on the connection
* @tip Once a connection is found and returned, a lock will be acquired to
* lock that particular connection, so that another thread does not try and
* use this connection while it is busy. Once you are finished with a connection,
* apr_ldap_connection_close() must be called to release this connection.
* @fn util_ldap_connection_t *util_ldap_connection_find(request_rec *r, const char *host, int port,
* const char *binddn, const char *bindpw, deref_options deref,
* int netscapessl, int starttls)
*/
APR_DECLARE_OPTIONAL_FN(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));
/**
* Compare two DNs for sameness
* @param r The request record
* @param ldc The LDAP connection being used.
* @param url The URL of the LDAP connection - used for deciding which cache to use.
* @param dn The first DN to compare.
* @param reqdn The DN to compare the first DN to.
* @param compare_dn_on_server Flag to determine whether the DNs should be checked using
* LDAP calls or with a direct string comparision. A direct
* string comparison is faster, but not as accurate - false
* negative comparisons are possible.
* @tip Two DNs can be equal and still fail a string comparison. Eg "dc=example,dc=com"
* and "dc=example, dc=com". Use the compare_dn_on_server unless there are serious
* performance issues.
* @fn int util_ldap_cache_comparedn(request_rec *r, util_ldap_connection_t *ldc,
* const char *url, const char *dn, const char *reqdn,
* int compare_dn_on_server)
*/
APR_DECLARE_OPTIONAL_FN(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));
/**
* A generic LDAP compare function
* @param r The request record
* @param ldc The LDAP connection being used.
* @param url The URL of the LDAP connection - used for deciding which cache to use.
* @param dn The DN of the object in which we do the compare.
* @param attrib The attribute within the object we are comparing for.
* @param value The value of the attribute we are trying to compare for.
* @tip Use this function to determine whether an attribute/value pair exists within an
* object. Typically this would be used to determine LDAP top-level group
* membership.
* @fn int util_ldap_cache_compare(request_rec *r, util_ldap_connection_t *ldc,
* const char *url, const char *dn, const char *attrib, const char *value)
*/
APR_DECLARE_OPTIONAL_FN(int,uldap_cache_compare,(request_rec *r, util_ldap_connection_t *ldc,
const char *url, const char *dn, const char *attrib, const char *value));
/**
* An LDAP function that checks if the specified user is a member of a subgroup.
* @param r The request record
* @param ldc The LDAP connection being used.
* @param url The URL of the LDAP connection - used for deciding which cache to use.
* @param dn The DN of the object in which we find subgroups to search within.
* @param attrib The attribute within group objects that identify users.
* @param value The user attribute value we are trying to compare for.
* @param subgroupAttrs The attributes within group objects that identify subgroups.
* Array of strings.
* @param subgroupclasses The objectClass values used to identify groups (and
* subgroups). apr_array_header_t *.
* @param cur_subgroup_depth Current recursive depth during subgroup processing.
* @param max_subgroup_depth Maximum depth of recursion allowed during subgroup
* processing.
* @tip Use this function to determine whether an attribute/value pair exists within a
* starting group object or one of its nested subgroups. Typically this would be
* used to determine LDAP nested group membership.
* @deffunc int util_ldap_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 )
*/
APR_DECLARE_OPTIONAL_FN(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));
/**
* Checks a username/password combination by binding to the LDAP server
* @param r The request record
* @param ldc The LDAP connection being used.
* @param url The URL of the LDAP connection - used for deciding which cache to use.
* @param basedn The Base DN to search for the user in.
* @param scope LDAP scope of the search.
* @param attrs LDAP attributes to return in search.
* @param filter The user to search for in the form of an LDAP filter. This filter must return
* exactly one user for the check to be successful.
* @param bindpw The user password to bind as.
* @param binddn The DN of the user will be returned in this variable.
* @param retvals The values corresponding to the attributes requested in the attrs array.
* @tip The filter supplied will be searched for. If a single entry is returned, an attempt
* is made to bind as that user. If this bind succeeds, the user is not validated.
* @fn int util_ldap_cache_checkuserid(request_rec *r, util_ldap_connection_t *ldc,
* char *url, const char *basedn, int scope, char **attrs,
* char *filter, char *bindpw, char **binddn, char ***retvals)
*/
APR_DECLARE_OPTIONAL_FN(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));
/**
* Searches for a specified user object in an LDAP directory
* @param r The request record
* @param ldc The LDAP connection being used.
* @param url The URL of the LDAP connection - used for deciding which cache to use.
* @param basedn The Base DN to search for the user in.
* @param scope LDAP scope of the search.
* @param attrs LDAP attributes to return in search.
* @param filter The user to search for in the form of an LDAP filter. This filter must return
* exactly one user for the check to be successful.
* @param binddn The DN of the user will be returned in this variable.
* @param retvals The values corresponding to the attributes requested in the attrs array.
* @tip The filter supplied will be searched for. If a single entry is returned, an attempt
* is made to bind as that user. If this bind succeeds, the user is not validated.
* @fn int util_ldap_cache_getuserdn(request_rec *r, util_ldap_connection_t *ldc,
* char *url, const char *basedn, int scope, char **attrs,
* char *filter, char **binddn, char ***retvals)
*/
APR_DECLARE_OPTIONAL_FN(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));
/**
* Checks if SSL support is available in mod_ldap
* @fn int util_ldap_ssl_supported(request_rec *r)
*/
APR_DECLARE_OPTIONAL_FN(int,uldap_ssl_supported,(request_rec *r));
/* from apr_ldap_cache.c */
/**
* Init the LDAP cache
* @param pool The pool to use to initialise the cache
* @param reqsize The size of the shared memory segement to request. A size
* of zero requests the max size possible from
* apr_shmem_init()
* @fn void util_ldap_cache_init(apr_pool_t *p, util_ldap_state_t *st)
* @return The status code returned is the status code of the
* apr_smmem_init() call. Regardless of the status, the cache
* will be set up at least for in-process or in-thread operation.
*/
apr_status_t util_ldap_cache_init(apr_pool_t *pool, util_ldap_state_t *st);
/* from apr_ldap_cache_mgr.c */
/**
* Display formatted stats for cache
* @param The pool to allocate the returned string from
* @tip This function returns a string allocated from the provided pool that describes
* various stats about the cache.
* @fn char *util_ald_cache_display(apr_pool_t *pool, util_ldap_state_t *st)
*/
char *util_ald_cache_display(request_rec *r, util_ldap_state_t *st);
#ifdef __cplusplus
}
#endif
#endif /* APR_HAS_LDAP */
#endif /* UTIL_LDAP_H */