]> git.sur5r.net Git - openldap/commitdiff
experimental ITS#109 fix: make kbind open default connection if necessary.
authorKurt Zeilenga <kurt@openldap.org>
Thu, 23 Sep 1999 04:08:33 +0000 (04:08 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Thu, 23 Sep 1999 04:08:33 +0000 (04:08 +0000)
implemented ldap_open_defconn() to centralize default connection
opening in open.c.  Used by ldap_open, kbind, and send_initial_request().

libraries/libldap/kbind.c
libraries/libldap/ldap-int.h
libraries/libldap/open.c
libraries/libldap/request.c

index 731a8b5fc6c25c5b43df0c5efc47a78bf71e3f10..0c6a07931b0719355daa60c18e09b2c28d7f0e88 100644 (file)
@@ -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 ))
index ab446da5a979dacc96cdb5281d0c52201a55f3d5..155213471bcbbe0971ecf1a38c6dd1ba53a46152 100644 (file)
@@ -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 );
 
index e8785387f5507c4cb7b6f3328e1953b70d51ef4e..1551ec66f35102f278ac1d47d99e5b20c1510a9a 100644 (file)
 
 #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 );
index 07da8e9bcec79d63a8c3a8c9dc862afc6082c72f..36bd54aff7a10715fb96ce81e77fecc675107222 100644 (file)
@@ -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 );