]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/request.c
Fix typo in previous commit.
[openldap] / libraries / libldap / request.c
index 821a29aa7498e1d4626ef8f608b4283d416f9366..6dfa9d1718cc9a7c70e168675e4ce0e097aa2e57 100644 (file)
@@ -1,4 +1,8 @@
 /*
+ * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
+ * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+ */
+/*  Portions
  *  Copyright (c) 1995 Regents of the University of Michigan.
  *  All rights reserved.
  *
@@ -7,10 +11,6 @@
 
 #include "portable.h"
 
-#ifndef lint 
-static char copyright[] = "@(#) Copyright (c) 1995 Regents of the University of Michigan.\nAll rights reserved.\n";
-#endif
-
 #include <stdio.h>
 #include <stdlib.h>
 
@@ -75,12 +75,54 @@ ldap_send_initial_request( LDAP *ld, unsigned long msgtype, char *dn,
        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 );
@@ -442,6 +484,7 @@ void
 ldap_dump_connection( LDAP *ld, LDAPConn *lconns, int all )
 {
        LDAPConn        *lc;
+       char            timebuf[32];
 
        fprintf( stderr, "** Connection%s:\n", all ? "s" : "" );
        for ( lc = lconns; lc != NULL; lc = lc->lconn_next ) {
@@ -457,7 +500,7 @@ ldap_dump_connection( LDAP *ld, LDAPConn *lconns, int all )
                    "NeedSocket" : ( lc->lconn_status ==
                    LDAP_CONNST_CONNECTING ) ? "Connecting" : "Connected" );
                fprintf( stderr, "  last used: %s\n",
-                   ctime( &lc->lconn_lastused ));
+                   ldap_pvt_ctime( &lc->lconn_lastused, timebuf ));
                if ( !all ) {
                        break;
                }
@@ -685,7 +728,7 @@ ldap_chase_referrals( LDAP *ld, LDAPRequest *lr, char **errstrp, int *hadrefp )
                                return( -1 );
                        }
 
-                       if (( srv->lsrv_host = ldap_strdup( tmpref )) == NULL ) {
+                       if (( srv->lsrv_host = strdup( tmpref )) == NULL ) {
                                free( (char *)srv );
                                ber_free( ber, 1 );
                                ld->ld_errno = LDAP_NO_MEMORY;
@@ -696,7 +739,7 @@ ldap_chase_referrals( LDAP *ld, LDAPRequest *lr, char **errstrp, int *hadrefp )
                                *ports++ = '\0';
                                srv->lsrv_port = atoi( ports );
                        } else {
-                               srv->lsrv_port = LDAP_PORT;
+                               srv->lsrv_port = openldap_ldap_global_options.ldo_defport;
                        }
 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_DNS
                } else {
@@ -833,7 +876,7 @@ re_encode_request( LDAP *ld, BerElement *origber, int msgid, char **dnp )
        if ( ldap_debug & LDAP_DEBUG_PACKETS ) {
                Debug( LDAP_DEBUG_ANY, "re_encode_request new request is:\n",
                    0, 0, 0 );
-               ber_dump( ber, 0 );
+               lber_log_dump( LDAP_DEBUG_BER, ldap_debug, ber, 0 );
        }
 #endif /* LDAP_DEBUG */
 
@@ -879,7 +922,7 @@ dn2servers( LDAP *ld, char *dn )    /* dn can also be a domain.... */
        srvlist = NULL;
 
        for ( i = 0; dxs[ i ] != NULL; ++i ) {
-               port = LDAP_PORT;
+               port = openldap_ldap_global_options.ldo_defport;
                server_dn = NULL;
                if ( strchr( dxs[ i ], ':' ) == NULL ) {
                        host = dxs[ i ];
@@ -919,9 +962,9 @@ dn2servers( LDAP *ld, char *dn )    /* dn can also be a domain.... */
                        prevsrv = srv;
                        
                        /* copy in info. */
-                       if (( srv->lsrv_host = ldap_strdup( host )) == NULL ||
+                       if (( srv->lsrv_host = strdup( host )) == NULL ||
                            ( server_dn != NULL && ( srv->lsrv_dn =
-                           ldap_strdup( server_dn )) == NULL )) {
+                           strdup( server_dn )) == NULL )) {
                                free_servers( srvlist );
                                srvlist = NULL;
                                break;          /* exit loop & return */