From ab48d0295d939416845aa4794e4e0463b5447403 Mon Sep 17 00:00:00 2001 From: Luke Howard Date: Mon, 24 May 2004 05:28:43 +0000 Subject: [PATCH] slapi_ldap_init() / slapi_ldap_unbind() --- servers/slapd/slapi/proto-slapi.h | 3 +++ servers/slapd/slapi/slapi_utils.c | 40 +++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/servers/slapd/slapi/proto-slapi.h b/servers/slapd/slapi/proto-slapi.h index eca8f2152a..d524ebf519 100644 --- a/servers/slapd/slapi/proto-slapi.h +++ b/servers/slapd/slapi/proto-slapi.h @@ -149,6 +149,9 @@ extern void slapi_destroy_condvar( Slapi_CondVar *cvar ); extern int slapi_wait_condvar( Slapi_CondVar *cvar, struct timeval *timeout ); extern int slapi_notify_condvar( Slapi_CondVar *cvar, int notify_all ); +extern LDAP *slapi_ldap_init( char *ldaphost, int ldapport, int secure, int shared ); +extern void slapi_ldap_unbind( LDAP *ld ); + extern char *slapi_ch_malloc( unsigned long size ); extern void slapi_ch_free( void **ptr ); extern void slapi_ch_free_string( char **s ); diff --git a/servers/slapd/slapi/slapi_utils.c b/servers/slapd/slapi/slapi_utils.c index f2ca2846ea..b87f641947 100644 --- a/servers/slapd/slapi/slapi_utils.c +++ b/servers/slapd/slapi/slapi_utils.c @@ -4194,3 +4194,43 @@ void slapi_entry_set_uniqueid( Slapi_Entry *e, char *uniqueid ) #endif /* LDAP_SLAPI */ } +LDAP *slapi_ldap_init( char *ldaphost, int ldapport, int secure, int shared ) +{ +#ifdef LDAP_SLAPI + LDAP *ld; + char *url; + size_t size; + int rc; + + size = sizeof("ldap:///"); + if ( secure ) + size++; + size += strlen( ldaphost ); + if ( ldapport != 0 ) + size += 32; + + url = slapi_ch_malloc( size ); + + if ( ldapport != 0 ) { + sprintf( url, "ldap%s://%s:%d/", ( secure ? "s" : "" ), ldaphost, ldapport ); + } else { + sprintf( url, "ldap%s://%s/", ( secure ? "s" : "" ), ldaphost ); + } + + rc = ldap_initialize( &ld, url ); + + slapi_ch_free_string( &url ); + + return ( rc == LDAP_SUCCESS ) ? ld : NULL; +#else + return NULL; +#endif /* LDAP_SLAPI */ +} + +void slapi_ldap_unbind( LDAP *ld ) +{ +#ifdef LDAP_SLAPI + ldap_unbind( ld ); +#endif /* LDAP_SLAPI */ +} + -- 2.39.5