]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/os-ip.c
Don't provide ldap.OpenLDAP.org and dc=OpenLDAP, dc=Org as the defaults.
[openldap] / libraries / libldap / os-ip.c
index b56809cda4bbfc70db365dc80da78e12f291879e..6d501565a9ef759a4b3496509bc0cd0e50683fc1 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.
  *
@@ -48,7 +52,13 @@ ldap_connect_to_host( Sockbuf *sb, char *host, unsigned long address,
        int                     status; /* for ioctl call */
 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
 #endif /* notyet */
-
+   
+       /* buffers for ldap_pvt_gethostbyname_a */
+       struct hostent          he_buf;
+       int                     local_h_errno;
+       char                    *ha_buf=NULL;
+#define DO_RETURN(x) if (ha_buf) free(ha_buf); return (x);
+   
        Debug( LDAP_DEBUG_TRACE, "ldap_connect_to_host: %s:%d\n",
            ( host == NULL ) ? "(by address)" : host, (int) ntohs( (short) port ), 0 );
 
@@ -59,13 +69,15 @@ ldap_connect_to_host( Sockbuf *sb, char *host, unsigned long address,
            /* This was just a test for -1 until OSF1 let inet_addr return
               unsigned int, which is narrower than 'unsigned long address' */
            if ( address == 0xffffffff || address == (unsigned long) -1 ) {
-               if ( (hp = gethostbyname( host )) == NULL ) {
+               if ( ( ldap_pvt_gethostbyname_a( host, &he_buf, &ha_buf,
+                       &hp, &local_h_errno) < 0) || (hp==NULL))
+               {
 #ifdef HAVE_WINSOCK
                        errno = WSAGetLastError();
 #else
                        errno = EHOSTUNREACH;   /* not exactly right, but... */
 #endif
-                       return( -1 );
+                       DO_RETURN( -1 );
                }
                use_hp = 1;
            }
@@ -74,7 +86,7 @@ ldap_connect_to_host( Sockbuf *sb, char *host, unsigned long address,
        rc = -1;
        for ( i = 0; !use_hp || ( hp->h_addr_list[ i ] != 0 ); i++ ) {
                if (( s = socket( AF_INET, SOCK_STREAM, 0 )) < 0 ) {
-                       return( -1 );
+                       DO_RETURN( -1 );
                }
 #ifdef notyet
 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
@@ -99,7 +111,7 @@ ldap_connect_to_host( Sockbuf *sb, char *host, unsigned long address,
                        break;
                } else {
 #ifdef HAVE_WINSOCK
-                       errno = WSAGetLastError();
+                       errno = WSAGetLastError();
 #endif
 #ifdef notyet
 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
@@ -145,8 +157,12 @@ ldap_connect_to_host( Sockbuf *sb, char *host, unsigned long address,
                    s, (char *) inet_ntoa( sin.sin_addr ), 0 );
        }
 
-       return( rc );
+       DO_RETURN( rc );
+       
+       
 }
+   
+#undef DO_RETURN
 
 
 void
@@ -165,6 +181,12 @@ ldap_host_connected_to( Sockbuf *sb )
        int                     len;
        struct sockaddr_in      sin;
 
+       /* buffers for gethostbyaddr_r */
+       struct hostent          he_buf;
+        int                    local_h_errno;
+       char                    *ha_buf=NULL;
+#define DO_RETURN(x) if (ha_buf) free(ha_buf); return (x);
+   
        (void)memset( (char *)&sin, 0, sizeof( struct sockaddr_in ));
        len = sizeof( sin );
        if ( getpeername( sb->sb_sd, (struct sockaddr *)&sin, &len ) == -1 ) {
@@ -176,15 +198,20 @@ ldap_host_connected_to( Sockbuf *sb )
         * this is necessary for kerberos to work right, since the official
         * hostname is used as the kerberos instance.
         */
-       if (( hp = gethostbyaddr( (char *) &sin.sin_addr,
-           sizeof( sin.sin_addr ), AF_INET )) != NULL ) {
+       if ((ldap_pvt_gethostbyaddr_a( (char *) &sin.sin_addr,
+               sizeof( sin.sin_addr ), 
+               AF_INET, &he_buf, &ha_buf,
+               &hp,&local_h_errno ) ==0 ) && (hp != NULL) )
+       {
                if ( hp->h_name != NULL ) {
-                       return( strdup( hp->h_name ));
+                       DO_RETURN( strdup( hp->h_name ));
                }
        }
 
-       return( NULL );
+       DO_RETURN( NULL );
 }
+#undef DO_RETURN   
+   
 #endif /* HAVE_KERBEROS */