[Date Prev][Date Next] [Chronological] [Thread] [Top]

Re: Wrapping ldap_search()

Dave Horsfall wrote:
We have a need to identify which applications are performing which searches, for diagnosis purposes. The idea is that our apps will call something like XXX_ldap_search(), which will log something then call the real ldap_search().

Is it possible to extract some sort of session ID from the LDAP handle, which can be matched up against SLAPD's log? I understand that this can (and will) change between releases, but I can wear that.

slapd will log the IP address and port number of each incoming connection. These will correspond to an address and port number on the client side as well. Normally the client library will only have one connection associated with each LDAP structure, unless automatic referral chasing is enabled (in which case additional connections will be linked to the structure for processing each referral)

As an aside, in <ldap.h> I can see where "LDAP" is typedef'd, but where is the structure itself defined? It's certainly well hidden :-)

It is opaque by design, you have to use ldap_get_option() to extract various bits from it. Getting LDAP_OPT_DESC should give you the default socket descriptor from the structure. Then you can use getsockname() to retrieve the local IP address and port number, and log that.

 -- Howard Chu
 Chief Architect, Symas Corp.  http://www.symas.com
 Director, Highland Sun        http://highlandsun.com/hyc
 OpenLDAP Core Team            http://www.openldap.org/project/