]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/open.c
Added the functions ldap_rename2() and ldap_rename2_s() to support LDAP
[openldap] / libraries / libldap / open.c
index 3aaf339144a432ee7cfb4177df96b97d131879b3..a1db516cbb49b2ca5999d1f76e073b33fb680eb3 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>
 
@@ -24,6 +24,7 @@ static char copyright[] = "@(#) Copyright (c) 1995 Regents of the University of
 
 #include "ldap-int.h"
 
+
 /*
  * ldap_open - initialize and connect to an ldap server.  A magic cookie to
  * be used for future communication is returned on success, NULL on failure.
@@ -48,13 +49,11 @@ ldap_open( char *host, int port )
                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 =
-           ldap_strdup( ld->ld_defhost )) == NULL )) {
+           strdup( ld->ld_defhost )) == NULL )) {
+               if(srv != NULL) free( (char*) srv );
                ldap_ld_free( ld, 0 );
                return( NULL );
        }
@@ -134,16 +133,18 @@ ldap_init( char *defhost, int defport )
 }      /* The WinSock DLL is acceptable. Proceed. */
 
 #elif HAVE_WINSOCK
-       if ( WSAStartup( 0x0101, &wsadata ) != 0 ) {
+{      WSADATA wsaData;
+       if ( WSAStartup( 0x0101, &wsaData ) != 0 ) {
            return( NULL );
        }
+}
 #endif
 
        if ( (ld = (LDAP *) calloc( 1, sizeof(LDAP) )) == NULL ) {
            WSACleanup( );
                return( NULL );
        }
-
+   
        /* copy the global options */
        memcpy(&ld->ld_options, &openldap_ldap_global_options,
                sizeof(ld->ld_options));
@@ -153,9 +154,9 @@ ldap_init( char *defhost, int defport )
        ld->ld_options.ldo_defhost = NULL;
 
        if ( defhost != NULL ) {
-               ld->ld_options.ldo_defhost = ldap_strdup( defhost );
+               ld->ld_options.ldo_defhost = strdup( defhost );
        } else {
-               ld->ld_options.ldo_defhost = ldap_strdup(
+               ld->ld_options.ldo_defhost = strdup(
                        openldap_ldap_global_options.ldo_defhost);
        }
 
@@ -166,7 +167,7 @@ ldap_init( char *defhost, int defport )
        }
 
        if ( openldap_ldap_global_options.ldo_defbase != NULL ) {
-               ld->ld_options.ldo_defbase = ldap_strdup(
+               ld->ld_options.ldo_defbase = strdup(
                        openldap_ldap_global_options.ldo_defbase);
        }
 
@@ -195,6 +196,11 @@ ldap_init( char *defhost, int defport )
 #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;
+
+       lber_pvt_sb_init( &(ld->ld_sb) );
+
        return( ld );
 }
 
@@ -251,6 +257,8 @@ open_ldap_connection( LDAP *ld, Sockbuf *sb, char *host, int defport,
        if ( rc == -1 ) {
                return( rc );
        }
+   
+       lber_pvt_sb_set_io( sb, &lber_pvt_sb_io_tcp, NULL );
 
        if ( krbinstancep != NULL ) {
 #ifdef HAVE_KERBEROS