]> git.ipfire.org Git - thirdparty/openldap.git/commitdiff
Updated Winsock codes
authorKurt Zeilenga <kurt@openldap.org>
Sun, 13 Jan 2002 04:53:46 +0000 (04:53 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Sun, 13 Jan 2002 04:53:46 +0000 (04:53 +0000)
CHANGES
libraries/libldap/init.c
libraries/libldap/open.c
libraries/libldap/os-ip.c

diff --git a/CHANGES b/CHANGES
index 6b1509631eeccf27495985ef17dcae555ba40584..e77bd1edd117deff833b20d8aac95a51f436a26a 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -12,6 +12,7 @@ OpenLDAP 2.0.20 Engineering
                Fixed repl_user build error (ITS#1503)
                Updated BerkeleyDB 4 support
                Updated schema files
+               Updated Windows NT/2000 MSVC5 port
 
 OpenLDAP 2.0.19 Release
        Fixed back-ldbm not filter indexing (ITS#1405)
index c553d678d0cec5d19cad249bd97765d0a1c36098..4809fdd00c3583b275fb71b3511e6980873d9568 100644 (file)
@@ -263,11 +263,11 @@ static void openldap_ldap_init_w_userconf(const char *file)
                /* we assume UNIX path syntax is used... */
 
                /* try ~/file */
-               sprintf(path, "%s/%s", home, file);
+               sprintf(path, "%s%s%s", home, LDAP_DIRSEP, file);
                openldap_ldap_init_w_conf(path, 1);
 
                /* try ~/.file */
-               sprintf(path, "%s/.%s", home, file);
+               sprintf(path, "%s%s.%s", home, LDAP_DIRSEP, file);
                openldap_ldap_init_w_conf(path, 1);
        }
 
@@ -364,6 +364,20 @@ static void openldap_ldap_init_w_env(
        }
 }
 
+static void
+ldap_int_destroy_global_options(void)
+{
+       struct ldapoptions *gopts = LDAP_INT_GLOBAL_OPT();
+
+       if ( gopts->ldo_defludp ) {
+               ldap_free_urllist( gopts->ldo_defludp );
+               gopts->ldo_defludp = NULL;
+       }
+#if defined(HAVE_WINSOCK) || defined(HAVE_WINSOCK2)
+       WSACleanup( );
+#endif
+}
+
 /* 
  * Initialize the global options structure with default values.
  */
@@ -382,11 +396,11 @@ void ldap_int_initialize_global_options( struct ldapoptions *gopts, int *dbglvl
        gopts->ldo_tm_api = (struct timeval *)NULL;
        gopts->ldo_tm_net = (struct timeval *)NULL;
 
-       /* ldo_defludp is leaked, we should have an at_exit() handler
-        * to free this and whatever else needs to cleaned up. 
+       /* ldo_defludp wll be freed by the atexit() handler
         */
        ldap_url_parselist(&gopts->ldo_defludp, "ldap://localhost/");
        gopts->ldo_defport = LDAP_PORT;
+       atexit(ldap_int_destroy_global_options);
 
        gopts->ldo_refhoplimit = LDAP_DEFAULT_REFHOPLIMIT;
        gopts->ldo_rebindproc = NULL;
@@ -425,11 +439,44 @@ void ldap_int_initialize( struct ldapoptions *gopts, int *dbglvl )
                return;
        }
 
+#ifdef HAVE_WINSOCK2
+{      WORD wVersionRequested;
+       WSADATA wsaData;
+       wVersionRequested = MAKEWORD( 2, 0 );
+       if ( WSAStartup( wVersionRequested, &wsaData ) != 0 ) {
+               /* Tell the user that we couldn't find a usable */
+               /* WinSock DLL.                                  */
+               return;
+       }
+       /* Confirm that the WinSock DLL supports 2.0.*/
+       /* Note that if the DLL supports versions greater    */
+       /* than 2.0 in addition to 2.0, it will still return */
+       /* 2.0 in wVersion since that is the version we      */
+       /* requested.                                        */
+       if ( LOBYTE( wsaData.wVersion ) != 2 ||
+               HIBYTE( wsaData.wVersion ) != 0 )
+       {
+           /* Tell the user that we couldn't find a usable */
+           /* WinSock DLL.                                  */
+           WSACleanup( );
+           return; 
+       }
+}      /* The WinSock DLL is acceptable. Proceed. */
+#elif HAVE_WINSOCK
+{      WSADATA wsaData;
+       if ( WSAStartup( 0x0101, &wsaData ) != 0 ) {
+           return;
+       }
+}
+#endif
+
 #if defined(LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND) \
        || defined(HAVE_TLS) || defined(HAVE_CYRUS_SASL)
        ldap_int_hostname = ldap_pvt_get_fqdn( ldap_int_hostname );
 #endif
-
        ldap_int_utils_init();
 
        if ( ldap_int_tblsize == 0 )
@@ -450,8 +497,7 @@ void ldap_int_initialize( struct ldapoptions *gopts, int *dbglvl )
                if( user == NULL ) user = getenv("LOGNAME");
 
                if( user != NULL ) {
-                       /* this value is leaked, need at_exit() handler */
-                       gopts->ldo_def_sasl_authcid = LDAP_STRDUP( user );
+                       gopts->ldo_def_sasl_authcid = user;
                }
     }
 #endif
index 93b4ad3f62aebcc5b9b10a7e1af294cd91de1014..ce648ffa6c0bff10fb5472f638ac90632e4ecbd6 100644 (file)
@@ -92,47 +92,13 @@ ldap_create( LDAP **ldp )
        /* Initialize the global options, if not already done. */
        if( gopts->ldo_valid != LDAP_INITIALIZED ) {
                ldap_int_initialize(gopts, NULL);
+               if ( gopts->ldo_valid != LDAP_INITIALIZED )
+                       return LDAP_LOCAL_ERROR;
        }
 
        Debug( LDAP_DEBUG_TRACE, "ldap_create\n", 0, 0, 0 );
 
-#ifdef HAVE_WINSOCK2
-{      WORD wVersionRequested;
-       WSADATA wsaData;
-       wVersionRequested = MAKEWORD( 2, 0 );
-       if ( WSAStartup( wVersionRequested, &wsaData ) != 0 ) {
-               /* Tell the user that we couldn't find a usable */
-               /* WinSock DLL.                                  */
-               return LDAP_LOCAL_ERROR;
-       }
-       /* Confirm that the WinSock DLL supports 2.0.*/
-       /* Note that if the DLL supports versions greater    */
-       /* than 2.0 in addition to 2.0, it will still return */
-       /* 2.0 in wVersion since that is the version we      */
-       /* requested.                                        */
-       if ( LOBYTE( wsaData.wVersion ) != 2 ||
-               HIBYTE( wsaData.wVersion ) != 0 )
-       {
-           /* Tell the user that we couldn't find a usable */
-           /* WinSock DLL.                                  */
-           WSACleanup( );
-           return LDAP_LOCAL_ERROR; 
-       }
-}      /* The WinSock DLL is acceptable. Proceed. */
-
-#elif HAVE_WINSOCK
-{      WSADATA wsaData;
-       if ( WSAStartup( 0x0101, &wsaData ) != 0 ) {
-           return LDAP_LOCAL_ERROR;
-       }
-}
-#endif
-
        if ( (ld = (LDAP *) LDAP_CALLOC( 1, sizeof(LDAP) )) == NULL ) {
-           WSACleanup( );
                return( LDAP_NO_MEMORY );
        }
    
@@ -160,14 +126,12 @@ ldap_create( LDAP **ldp )
 
        if ( ld->ld_options.ldo_defludp == NULL ) {
                LDAP_FREE( (char*)ld );
-           WSACleanup( );
                return LDAP_NO_MEMORY;
        }
 
        if (( ld->ld_selectinfo = ldap_new_select_info()) == NULL ) {
                ldap_free_urllist( ld->ld_options.ldo_defludp );
                LDAP_FREE( (char*) ld );
-           WSACleanup( );
                return LDAP_NO_MEMORY;
        }
 
@@ -177,7 +141,6 @@ ldap_create( LDAP **ldp )
        if ( ld->ld_sb == NULL ) {
                ldap_free_urllist( ld->ld_options.ldo_defludp );
                LDAP_FREE( (char*) ld );
-               WSACleanup( );
                return LDAP_NO_MEMORY;
        }
 
index 5bf1064f33f027a6cdca21099bb01e1c4fae40e0..7e13ccd75cf81111f6019c27b293c868baccb078 100644 (file)
@@ -130,6 +130,8 @@ ldap_int_prepare_socket(LDAP *ld, int s, int proto )
        return 0;
 }
 
+#ifndef HAVE_WINSOCK
+
 #undef TRACE
 #define TRACE do { \
        osip_debug(ld, \
@@ -174,9 +176,6 @@ ldap_pvt_is_socket_ready(LDAP *ld, int s)
        {
                /* XXX: needs to be replace with ber_stream_read() */
                read(s, &ch, 1);
-#ifdef HAVE_WINSOCK
-               ldap_pvt_set_errno( WSAGetLastError() );
-#endif
                TRACE;
                return -1;
        }
@@ -187,6 +186,8 @@ ldap_pvt_is_socket_ready(LDAP *ld, int s)
 }
 #undef TRACE
 
+#endif /* HAVE_WINSOCK */
+
 static int
 ldap_pvt_connect(LDAP *ld, ber_socket_t s,
        struct sockaddr *sin, socklen_t addrlen,
@@ -250,15 +251,25 @@ ldap_pvt_connect(LDAP *ld, ber_socket_t s,
 #ifdef HAVE_WINSOCK
        /* This means the connection failed */
        if ( FD_ISSET(s, &efds) ) {
-           ldap_pvt_set_errno(WSAECONNREFUSED);
+           int so_errno;
+           int dummy = sizeof(so_errno);
+           if ( getsockopt( s, SOL_SOCKET, SO_ERROR,
+                       (char *) &so_errno, &dummy ) == AC_SOCKET_ERROR || !so_errno )
+           {
+               /* impossible */
+               so_errno = WSAGetLastError();
+           }
+           ldap_pvt_set_errno(so_errno);
            osip_debug(ld, "ldap_pvt_connect: error on socket %d: "
                       "errno: %d (%s)\n", s, errno, sock_errstr(errno));
            return -1;
        }
 #endif
        if ( FD_ISSET(s, &wfds) ) {
+#ifndef HAVE_WINSOCK
                if ( ldap_pvt_is_socket_ready(ld, s) == -1 )
                        return ( -1 );
+#endif
                if ( ldap_pvt_ndelay_off(ld, s) == -1 )
                        return ( -1 );
                return ( 0 );