}
}
- if ( verbose ) {
- printf( "ldap_open( %s, %d )\n", ldaphost, ldapport );
- }
-
if ( debug ) {
lber_set_option( NULL, LBER_OPT_DEBUG_LEVEL, &debug );
ldap_set_option( NULL, LDAP_OPT_DEBUG_LEVEL, &debug );
(void) SIGNAL( SIGPIPE, SIG_IGN );
#endif
- if (( ld = ldap_open( ldaphost, ldapport )) == NULL ) {
- perror( ldaphost );
+ if ( verbose ) {
+ printf( "ldap_init( %s, %d )\n", ldaphost, ldapport );
+ }
+
+ if (( ld = ldap_init( ldaphost, ldapport )) == NULL ) {
+ perror( "ldap_init" );
exit( 1 );
}
return( NULL );
}
- /* we'll assume we're talking version 2 for now */
- ld->ld_version = LDAP_VERSION2;
-
#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
if (( srv = (LDAPServer *)calloc( 1, sizeof( LDAPServer ))) ==
NULL || ( ld->ld_defhost != NULL && ( srv->lsrv_host =
strdup( ld->ld_defhost )) == NULL )) {
+ if(srv != NULL) free( (char*) srv );
ldap_ld_free( ld, 0 );
return( NULL );
}
#endif /* LDAP_CHARSET_8859 == LDAP_DEFAULT_CHARSET */
#endif /* STR_TRANSLATION && LDAP_DEFAULT_CHARSET */
+ /* we'll assume we're talking version 2 for now */
+ ld->ld_version = LDAP_VERSION2;
+
+ ld->ld_sb.sb_sd = -1;
return( ld );
}
BerElement *ber )
{
#if defined( LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS ) || defined( LDAP_API_FEATURE_X_OPENLDAP_V2_DNS )
- LDAPServer *servers;
+ LDAPServer *servers, *srv;
#endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS || LDAP_API_FEATURE_X_OPENLDAP_V2_DNS */
Debug( LDAP_DEBUG_TRACE, "ldap_send_initial_request\n", 0, 0, 0 );
+ if ( ld->ld_sb.sb_sd == -1 ) {
+ /* not connected yet */
+
+#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
+ if (( srv = (LDAPServer *)calloc( 1, sizeof( LDAPServer ))) ==
+ NULL || ( ld->ld_defhost != NULL && ( srv->lsrv_host =
+ strdup( ld->ld_defhost )) == NULL ))
+ {
+ if (srv != NULL) free( srv );
+ ld->ld_errno = LDAP_NO_MEMORY;
+ return( -1 );
+ }
+
+ srv->lsrv_port = ld->ld_defport;
+
+ if (( ld->ld_defconn = ldap_new_connection( ld, &srv, 1,1,0 ))
+ == NULL )
+ {
+ if ( ld->ld_defhost != NULL ) free( srv->lsrv_host );
+ free( (char *)srv );
+ ld->ld_errno = LDAP_SERVER_DOWN;
+ return( -1 );
+ }
+ ++ld->ld_defconn->lconn_refcnt; /* so it never gets closed/freed */
+
+#else /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
+ if ( open_ldap_connection( ld, &ld->ld_sb, ld->ld_defhost,
+ ld->ld_defport, &ld->ld_host, 0 ) < 0 )
+ {
+ ldap_ld_free( ld, 0 );
+ ld->ld_errno = LDAP_SERVER_DOWN;
+ return( -1 );
+ }
+#endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
+
+ Debug( LDAP_DEBUG_TRACE,
+ "ldap_delayed_open successful, ld_host is %s\n",
+ ( ld->ld_host == NULL ) ? "(null)" : ld->ld_host, 0, 0 );
+ }
+
+
#if !defined( LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS ) && !defined( LDAP_API_FEATURE_X_OPENLDAP_V2_DNS )
+
if ( ber_flush( &ld->ld_sb, ber, 1 ) != 0 ) {
ld->ld_errno = LDAP_SERVER_DOWN;
return( -1 );