src/v2l_conn.c File Reference

Handling the LDAP directory. Implementation. More...

#include <stdlib.h>
#include <jabberd.h>
#include <v2l_conn.h>

Include dependency graph for v2l_conn.c:

Go to the source code of this file.

Defines

#define V2L_CONN_LIFETIME   30
#define V2L_POLL_INTERVAL   1
#define LOG_ERROR_MEM   log_error (ZONE, "Unable to allocate memory")

Functions

static v2l_LdapConn_v2l_create_conn (char *host, int port, const char *binddn, const char *user, const char *passwd, int expire)
static int _v2l_ldap_get_credentials (v2l_Config *self, const char *user, char **passwd, char **cn)
static void _v2l_free_conn (xht h, const char *user, void *val)
static int _v2l_count_attrs (v2l_LdapRequest *req)
static int _v2l_ldap_modify (char *dn, LDAPMod **attrs, v2l_LdapEvt *evt_res)
static int _v2l_ldap_search (char *dn, char *suffix, char **attrs, int subtree, v2l_LdapEvt *evt_res)
static char * _v2l_ldap_filter (v2l_Config *self, const char *user)
static void _v2l_ldap_sync (v2l_LdapEvt *evt_res)
static v2l_LdapRequest_v2l_add_attr (v2l_LdapRequest *req, LDAPMod *attr)
static void _v2l_add_conn (v2l_LdapConn *ldap_conn)
static void _v2l_free_walker (xht h, const char *key, void *val, void *arg)
static void * _v2l_purge_conn_callback (void *arg)
static void _v2l_free_expired_walker (xht h, const char *key, void *val, void *arg)
static int _v2l_ldap_wait_callback (void *arg)
v2l_LdapConnv2l_get_conn (v2l_Config *self, const char *user)
v2l_LdapConnv2l_get_master_conn (v2l_Config *self)
void v2l_free_allconn (void)
v2l_LdapEvtv2l_ldap_get_entry (v2l_Config *self, v2l_LdapConn *curr_conn)
int v2l_request_record (v2l_Config *self, v2l_LdapConn *curr_conn, v2l_LdapRequest *req)
v2l_LdapRequestv2l_add_attr_str (v2l_LdapRequest *req, const char *attr, const char *str)
void v2l_ldap_for_all_attrs (v2l_AttrValueFunction value_func, v2l_AttrMatchFunction match_func, void *pointer, v2l_LdapEvt *evt_res)

Variables

static xht V2L_CONN_LIST = NULL


Detailed Description

Handling the LDAP directory. Implementation.

Definition in file v2l_conn.c.


Define Documentation

#define V2L_CONN_LIFETIME   30

Lifetime of an ephemeral connection, in seconds The recall connections thread period.

Definition at line 39 of file v2l_conn.c.

Referenced by _v2l_free_expired_walker(), and _v2l_purge_conn_callback().

#define V2L_POLL_INTERVAL   1

How often thread checks for LDAP results, in seconds

Definition at line 42 of file v2l_conn.c.

Referenced by _v2l_ldap_sync().


Function Documentation

static v2l_LdapRequest * _v2l_add_attr ( v2l_LdapRequest req,
LDAPMod *  attr 
) [static]

Adds LDAP attr to request. Utility function, hides OpenLDAP API to upper level.

Precondition:
Attribute is not NULL.
Parameters:
[in,out] req The SLL of LDAP requests. If NULL new list is returned.
attr The attr, LDAPMod pointer.
Returns:
The list of requests + the last added. The list of request if error.

Definition at line 746 of file v2l_conn.c.

References v2l_LdapRequest::attr, LOG_ERROR_MEM, and v2l_LdapRequest::next.

Referenced by v2l_add_attr_str().

Here is the caller graph for this function:

static void _v2l_add_conn ( v2l_LdapConn ldap_conn  )  [static]

Adds a conn to the global list. If list is empty, initializes it and starts the thread who recalls expired connections.

Parameters:
ldap_conn New connection.

Definition at line 878 of file v2l_conn.c.

References _v2l_purge_conn_callback(), v2l_LdapConn::user, and V2L_CONN_LIST.

Referenced by _v2l_create_conn().

Here is the call graph for this function:

Here is the caller graph for this function:

static int _v2l_count_attrs ( v2l_LdapRequest req  )  [static]

Gets the number or attributes in a LDAP request.

Count the number of LDAPMod in the structure

Definition at line 736 of file v2l_conn.c.

References v2l_LdapRequest::next.

Referenced by v2l_request_record().

Here is the caller graph for this function:

static v2l_LdapConn * _v2l_create_conn ( char *  host,
int  port,
const char *  binddn,
const char *  user,
const char *  passwd,
int  expire 
) [static]

Creates new LDAP connection.

Parameters:
host LDAP hostname.
port LDAP port.
binddn Bind DN.
user User name.
passwd User password.
expire Boolean, ephemeral connection?
Returns:
LDAP connectior or NULL if error.

Definition at line 463 of file v2l_conn.c.

References _v2l_add_conn(), v2l_LdapConn::binddn, v2l_LdapConn::creation_time, v2l_LdapConn::entry, v2l_LdapConn::ld, LOG_ERROR_MEM, v2l_LdapConn::poolref, and v2l_LdapConn::user.

Referenced by v2l_get_conn(), and v2l_get_master_conn().

Here is the call graph for this function:

Here is the caller graph for this function:

static void _v2l_free_conn ( xht  h,
const char *  user,
void *  val 
) [static]

Closes and frees a connection. Utility function, common code for two hash walker functions.

Parameters:
h Jabberd hash. Hash table "username"->connection.
user User name.
val deference pointer to connection.
See also:
_v2l_free_walker

_v2l_free_expired_walker

Definition at line 832 of file v2l_conn.c.

References v2l_LdapConn::ld, and v2l_LdapConn::poolref.

Referenced by _v2l_free_expired_walker(), and _v2l_free_walker().

Here is the caller graph for this function:

static void _v2l_free_expired_walker ( xht  h,
const char *  key,
void *  val,
void *  arg 
) [static]

Frees expired connections. Utility function. Hash walker function. See jabberd API for details.

Definition at line 844 of file v2l_conn.c.

References _v2l_free_conn(), v2l_LdapConn::creation_time, and V2L_CONN_LIFETIME.

Referenced by _v2l_purge_conn_callback().

Here is the call graph for this function:

Here is the caller graph for this function:

static void _v2l_free_walker ( xht  h,
const char *  key,
void *  val,
void *  arg 
) [static]

Frees connection unconditionally. Utility function. Hash walker function. See jabberd API for details.

Definition at line 826 of file v2l_conn.c.

References _v2l_free_conn().

Referenced by v2l_free_allconn().

Here is the call graph for this function:

Here is the caller graph for this function:

static char * _v2l_ldap_filter ( v2l_Config self,
const char *  user 
) [static]

Builds and returns the search filter.

Note:
Allocated memory must be freed by the caller.
Parameters:
self Module config.
user User name.
See also:
_v2l_ldap_search
Returns:
The filter or NULL if error.

Definition at line 565 of file v2l_conn.c.

References v2l_Config::filter, and LOG_ERROR_MEM.

Referenced by _v2l_ldap_get_credentials().

Here is the caller graph for this function:

static int _v2l_ldap_get_credentials ( v2l_Config self,
const char *  user,
char **  passwd,
char **  cn 
) [static]

Gets user credentials Retrieves user password and common name from LDAP directory using master connection.

Note:
Allocated memory (*passwd and *cn) must be freed by the caller.
Parameters:
self Module config.
user User name.
[out] passwd User password.
[out] cn Common Name.
Precondition:
self is valid, user is not NULL
Returns:
1 if no error, otherwise 0.

Definition at line 589 of file v2l_conn.c.

References _v2l_ldap_filter(), _v2l_ldap_search(), _v2l_ldap_sync(), v2l_LdapEvt::ld, LOG_ERROR_MEM, v2l_LdapEvt::rc, v2l_LdapEvt::result, and v2l_Config::suffix.

Referenced by v2l_get_conn().

Here is the call graph for this function:

Here is the caller graph for this function:

static int _v2l_ldap_modify ( char *  dn,
LDAPMod **  attrs,
v2l_LdapEvt evt_res 
) [static]

Modifies an entry in the LDAP directory Utility function.

Parameters:
dn Entry bind DN
attrs List of attributes changed.
[in,out] evt_res Control and info parameter.
Returns:
LDAP error code.

Definition at line 690 of file v2l_conn.c.

References v2l_LdapEvt::ld, and v2l_LdapEvt::msgid.

Referenced by v2l_request_record().

Here is the caller graph for this function:

static int _v2l_ldap_search ( char *  dn,
char *  suffix,
char **  attrs,
int  subtree,
v2l_LdapEvt evt_res 
) [static]

Searchs and retrieves an entry from the LDAP directory Utility function.

Parameters:
dn Entry bind DN.
suffix LDAP suffix
[out] attrs Entry attributes.
subtree boolean. Search in a one level or in entire subtree?
[in,out] evt_res Control and info parameter.
Returns:
LDAP error code.

Definition at line 697 of file v2l_conn.c.

References v2l_LdapEvt::ld, and v2l_LdapEvt::msgid.

Referenced by _v2l_ldap_get_credentials(), and v2l_ldap_get_entry().

Here is the caller graph for this function:

static void _v2l_ldap_sync ( v2l_LdapEvt evt_res  )  [static]

Waits for LDAP results. Operations on the directory are asynchronous. This is a sync wait function.

Parameters:
[in,out] evt_res Control and info parameter.

Definition at line 710 of file v2l_conn.c.

References _v2l_ldap_wait_callback(), and V2L_POLL_INTERVAL.

Referenced by _v2l_ldap_get_credentials(), v2l_ldap_get_entry(), and v2l_request_record().

Here is the call graph for this function:

Here is the caller graph for this function:

static int _v2l_ldap_wait_callback ( void *  arg  )  [static]

A thread for active wait for LDAP results

Definition at line 781 of file v2l_conn.c.

References v2l_LdapEvt::ld, v2l_LdapEvt::msgid, v2l_LdapEvt::rc, and v2l_LdapEvt::result.

Referenced by _v2l_ldap_sync().

Here is the caller graph for this function:

static void * _v2l_purge_conn_callback ( void *  arg  )  [static]

Frees connections when its slice time expired (periodic thread).

inline_dotgraph_2
Parameters:
arg Unused.

Definition at line 856 of file v2l_conn.c.

References _v2l_free_expired_walker(), V2L_CONN_LIFETIME, and V2L_CONN_LIST.

Referenced by _v2l_add_conn().

Here is the call graph for this function:

Here is the caller graph for this function:

v2l_LdapRequest* v2l_add_attr_str ( v2l_LdapRequest req,
const char *  attr,
const char *  str 
)

Adds a new request to the list.

Parameters:
req The list of requests.
attr attribute name.
str attribute value.
Returns:
The list of requests + the last added. The list of request if error.

Definition at line 381 of file v2l_conn.c.

References _v2l_add_attr().

Referenced by _v2l_set_sn12(), and _v2l_vcard2ldap_generic().

Here is the call graph for this function:

Here is the caller graph for this function:

void v2l_free_allconn ( void   ) 

Frees and closes all connections (ephemeral or not) If connections doesn't exist does nothing.

Postcondition:
self->master_conn closed. Connections list empty.

Definition at line 240 of file v2l_conn.c.

References _v2l_free_walker(), and V2L_CONN_LIST.

Referenced by v2l_config_shutdown().

Here is the call graph for this function:

Here is the caller graph for this function:

v2l_LdapConn* v2l_get_conn ( v2l_Config self,
const char *  user 
)

Gets a (ephemeral) connection by name. Creates one if doesn't exist.

Warning:
The name defined by V2L_ADMIN is reserved for master conn.
Precondition:
self is valid, user is not null and exists.
Postcondition:
ephermeral connection for user is open.
Parameters:
self Module config.
user the username
See also:
V2L_ADMIN

v2l_get_master_conn

Returns:
the connection if no error, otherwise NULL.

Definition at line 189 of file v2l_conn.c.

References _v2l_create_conn(), _v2l_ldap_get_credentials(), LOG_ERROR_MEM, and V2L_CONN_LIST.

Referenced by _v2l_packets_handler().

Here is the call graph for this function:

Here is the caller graph for this function:

v2l_LdapConn* v2l_get_master_conn ( v2l_Config self  ) 

Gets a connection master connection. Creates one if doesn't exist.

Precondition:
self is valid
Postcondition:
master connection is open.
Parameters:
self Module config.
Returns:
the connection if no error, otherwise NULL.

Definition at line 233 of file v2l_conn.c.

References _v2l_create_conn(), v2l_Config::binddn, v2l_Config::bindpw, v2l_Config::host, v2l_Config::port, and V2L_ADMIN.

Referenced by v2l_config_init().

Here is the call graph for this function:

Here is the caller graph for this function:

void v2l_ldap_for_all_attrs ( v2l_AttrValueFunction  value_func,
v2l_AttrMatchFunction  match_func,
void *  pointer,
v2l_LdapEvt evt_res 
)

Applies a function to all LDAP object attributes.

Precondition:
evt_res should be a valid entry (ie. result of a search in directory)
Parameters:
value_func Walker function.
match_func Match function. If returns true we'll call to value_func
pointer Generic multipurpose pointer. It will be passed to value_func
evt_res LDAP descriptor, control code and result.

Definition at line 419 of file v2l_conn.c.

References v2l_LdapEvt::ld, and v2l_LdapEvt::result.

Referenced by v2l_vcard_get().

Here is the caller graph for this function:

v2l_LdapEvt* v2l_ldap_get_entry ( v2l_Config self,
v2l_LdapConn curr_conn 
)

Retrieves an user entry from the LDAP directory.

Note:
Allocated memory must be freed by the caller.
Parameters:
self Module config
curr_conn user connection.
Returns:
evt_res LDAP descriptor, control code and result. NULL if error.

Definition at line 247 of file v2l_conn.c.

References _v2l_ldap_search(), _v2l_ldap_sync(), v2l_LdapConn::entry, v2l_LdapEvt::ld, v2l_LdapConn::ld, LOG_ERROR_MEM, v2l_LdapEvt::result, and v2l_Config::suffix.

Referenced by v2l_vcard_get().

Here is the call graph for this function:

Here is the caller graph for this function:

int v2l_request_record ( v2l_Config self,
v2l_LdapConn curr_conn,
v2l_LdapRequest req 
)

Executes a list of changes on the LDAP directory.

Precondition:
req is not NULL
Parameters:
self Module config
curr_conn The user connection.
req list of changes.
Returns:
1 if no error, otherwise 0

Definition at line 285 of file v2l_conn.c.

References _v2l_count_attrs(), _v2l_ldap_modify(), _v2l_ldap_sync(), v2l_LdapRequest::attr, v2l_LdapConn::binddn, v2l_LdapEvt::ld, v2l_LdapConn::ld, LOG_ERROR_MEM, v2l_LdapRequest::next, v2l_LdapEvt::rc, v2l_LdapEvt::result, and v2l_LdapConn::user.

Referenced by v2l_vcard_set().

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

xht V2L_CONN_LIST = NULL [static]

Global hashtable of all currently active LDAP connections

Definition at line 47 of file v2l_conn.c.

Referenced by _v2l_add_conn(), _v2l_purge_conn_callback(), v2l_free_allconn(), and v2l_get_conn().


Generated on Sun Oct 7 14:38:34 2007 for vCard2LDAP by  doxygen 1.5.1