From: Nathaniel McCallum Date: Wed, 27 Feb 2013 18:44:57 +0000 (-0500) Subject: ITS#7532 - Add new function ldap_connect(). X-Git-Url: https://git.sur5r.net/?p=openldap;a=commitdiff_plain;h=29f6260364df588c876d922ffcc3c429e3b4f062 ITS#7532 - Add new function ldap_connect(). This function is used to manually establish a connection after a call to ldap_initialize(). This is primarily so that a file descriptor can be obtained before any requests are sent for the purposes of polling for writability. --- diff --git a/doc/man/man3/ldap_open.3 b/doc/man/man3/ldap_open.3 index 1d5e2b5e29..66b0b98f82 100644 --- a/doc/man/man3/ldap_open.3 +++ b/doc/man/man3/ldap_open.3 @@ -30,6 +30,11 @@ LDAP **ldp; char *uri; .LP .ft B +int ldap_connect(ldp) +.ft +LDAP *ldp; +.LP +.ft B int ldap_set_urllist_proc(ld, proc, params) .ft LDAP *ld; @@ -141,6 +146,12 @@ are deprecated in favor of essentially because the latter allows to specify a schema in the URI and it explicitly returns an error code. .LP +.B ldap_connect() +causes a handle created by +.B ldap_initialize() +to connect to the server. This is useful in situations where a file +descriptor is required before a request is performed. +.LP .B ldap_init_fd() allows an LDAP structure to be initialized using an already-opened connection. The diff --git a/include/ldap.h b/include/ldap.h index 588e9066dc..e3f292dbaa 100644 --- a/include/ldap.h +++ b/include/ldap.h @@ -1548,6 +1548,9 @@ LDAP_F( LDAP * ) ldap_dup LDAP_P(( LDAP *old )); +LDAP_F( int ) +ldap_connect( LDAP *ld ); + /* * in tls.c */ diff --git a/libraries/libldap/open.c b/libraries/libldap/open.c index cd81d9c536..b513ad7d37 100644 --- a/libraries/libldap/open.c +++ b/libraries/libldap/open.c @@ -50,6 +50,29 @@ int ldap_open_defconn( LDAP *ld ) return 0; } +/* + * ldap_connect - Connect to an ldap server. + * + * Example: + * LDAP *ld; + * ldap_initialize( &ld, url ); + * ldap_connect( ld ); + */ +int +ldap_connect( LDAP *ld ) +{ + ber_socket_t sd = AC_SOCKET_INVALID; + int rc = LDAP_SUCCESS; + + LDAP_MUTEX_LOCK( &ld->ld_conn_mutex ); + if ( ber_sockbuf_ctrl( ld->ld_sb, LBER_SB_OPT_GET_FD, &sd ) == -1 ) { + rc = ldap_open_defconn( ld ); + } + LDAP_MUTEX_UNLOCK( &ld->ld_conn_mutex ); + + return rc; +} + /* * ldap_open - initialize and connect to an ldap server. A magic cookie to * be used for future communication is returned on success, NULL on failure.