From: Kurt Zeilenga Date: Thu, 23 Sep 1999 04:08:33 +0000 (+0000) Subject: experimental ITS#109 fix: make kbind open default connection if necessary. X-Git-Tag: UCDATA_2_4~395 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=deafd4e2749d56be90f1d45f641c89f7a7cd0b3b;p=openldap experimental ITS#109 fix: make kbind open default connection if necessary. implemented ldap_open_defconn() to centralize default connection opening in open.c. Used by ldap_open, kbind, and send_initial_request(). --- diff --git a/libraries/libldap/kbind.c b/libraries/libldap/kbind.c index 731a8b5fc6..0c6a07931b 100644 --- a/libraries/libldap/kbind.c +++ b/libraries/libldap/kbind.c @@ -273,6 +273,13 @@ ldap_get_kerberosv4_credentials( return( NULL ); } + if( ! ber_pvt_sb_in_use( &ld->ld_sb ) ) { + /* not connected yet */ + int rc = ldap_open_defconn( ld ); + + if( rc < 0 ) return NULL; + } + krbinstance = ld->ld_defconn->lconn_krbinstance; if ( (err = krb_mk_req( &ktxt, service, krbinstance, realm, 0 )) diff --git a/libraries/libldap/ldap-int.h b/libraries/libldap/ldap-int.h index ab446da5a9..155213471b 100644 --- a/libraries/libldap/ldap-int.h +++ b/libraries/libldap/ldap-int.h @@ -351,6 +351,7 @@ char *ldap_get_kerberosv4_credentials LDAP_P(( /* * in open.c */ +int ldap_open_defconn( LDAP *ld ); int open_ldap_connection( LDAP *ld, Sockbuf *sb, const char *host, int defport, char **krbinstancep, int async ); diff --git a/libraries/libldap/open.c b/libraries/libldap/open.c index e8785387f5..1551ec66f3 100644 --- a/libraries/libldap/open.c +++ b/libraries/libldap/open.c @@ -26,6 +26,33 @@ #include "ldap-int.h" +int ldap_open_defconn( LDAP *ld ) +{ + LDAPServer *srv; + + if (( srv = (LDAPServer *)LDAP_CALLOC( 1, sizeof( LDAPServer ))) == + NULL || ( ld->ld_defhost != NULL && ( srv->lsrv_host = + LDAP_STRDUP( ld->ld_defhost )) == NULL )) + { + if( srv != NULL ) LDAP_FREE( (char*) 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 ) LDAP_FREE( srv->lsrv_host ); + LDAP_FREE( (char *)srv ); + ld->ld_errno = LDAP_SERVER_DOWN; + return -1; + } + + ++ld->ld_defconn->lconn_refcnt; /* so it never gets closed/freed */ + + return 0; +} /* * ldap_open - initialize and connect to an ldap server. A magic cookie to @@ -40,8 +67,8 @@ LDAP * ldap_open( LDAP_CONST char *host, int port ) { + int rc; LDAP *ld; - LDAPServer *srv; Debug( LDAP_DEBUG_TRACE, "ldap_open\n", 0, 0, 0 ); @@ -49,22 +76,12 @@ ldap_open( LDAP_CONST char *host, int port ) return( NULL ); } - if (( srv = (LDAPServer *)LDAP_CALLOC( 1, sizeof( LDAPServer ))) == - NULL || ( ld->ld_defhost != NULL && ( srv->lsrv_host = - LDAP_STRDUP( ld->ld_defhost )) == NULL )) { - if(srv != NULL) LDAP_FREE( (char*) srv ); - ldap_ld_free( ld, 0, NULL, NULL ); - return( NULL ); - } - srv->lsrv_port = ld->ld_defport; + rc = ldap_open_defconn( ld ); - if (( ld->ld_defconn = ldap_new_connection( ld, &srv, 1,1,0 )) == NULL ) { - if ( ld->ld_defhost != NULL ) LDAP_FREE( srv->lsrv_host ); - LDAP_FREE( (char *)srv ); + if( rc < 0 ) { ldap_ld_free( ld, 0, NULL, NULL ); return( NULL ); } - ++ld->ld_defconn->lconn_refcnt; /* so it never gets closed/freed */ Debug( LDAP_DEBUG_TRACE, "ldap_open successful, ld_host is %s\n", ( ld->ld_host == NULL ) ? "(null)" : ld->ld_host, 0, 0 ); diff --git a/libraries/libldap/request.c b/libraries/libldap/request.c index 07da8e9bce..36bd54aff7 100644 --- a/libraries/libldap/request.c +++ b/libraries/libldap/request.c @@ -84,30 +84,13 @@ ldap_send_initial_request( if ( ! ber_pvt_sb_in_use(&ld->ld_sb ) ) { /* not connected yet */ + int rc = ldap_open_defconn( ld ); - if (( srv = (LDAPServer *)LDAP_CALLOC( 1, sizeof( LDAPServer ))) == - NULL || ( ld->ld_defhost != NULL && ( srv->lsrv_host = - LDAP_STRDUP( ld->ld_defhost )) == NULL )) - { - if (srv != NULL) LDAP_FREE( srv ); + if( rc < 0 ) { ber_free( ber, 1 ); - 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 ) LDAP_FREE( srv->lsrv_host ); - LDAP_FREE( (char *)srv ); - ber_free( ber, 1 ); - ld->ld_errno = LDAP_SERVER_DOWN; - return( -1 ); - } - ++ld->ld_defconn->lconn_refcnt; /* so it never gets closed/freed */ - Debug( LDAP_DEBUG_TRACE, "ldap_delayed_open successful, ld_host is %s\n", ( ld->ld_host == NULL ) ? "(null)" : ld->ld_host, 0, 0 );