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 );
#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 */
+}
+