]> git.sur5r.net Git - openldap/commitdiff
Add char* ldap_pvt_get_fqdn(char*) which returns the FQDN of the
authorKurt Zeilenga <kurt@openldap.org>
Tue, 15 Aug 2000 01:55:43 +0000 (01:55 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Tue, 15 Aug 2000 01:55:43 +0000 (01:55 +0000)
input.  In input==NULL, returns FQDN of local host.
Fixed copy_hostent() uninitialized pointer bug.
Replaced gethostname calls with ldap_pvt_get_fqdn( NULL ) calls.

include/ldap_pvt.h
libraries/libldap/init.c
libraries/libldap/util-int.c
libraries/liblutil/authpasswd.c
libraries/liblutil/passwd.c
servers/slapd/sasl.c

index 92e287cdfd5f1b5c8322b2dea1da45007116915e..5a2fa336cd35a963bffc8213715592c7c7dc4536 100644 (file)
@@ -45,6 +45,8 @@ ldap_pvt_ctime LDAP_P((
        const time_t *tp,
        char *buf ));
 
+LDAP_F( char *) ldap_pvt_get_fqdn LDAP_P(( char * ));
+
 LDAP_F( int )
 ldap_pvt_gethostbyname_a LDAP_P((
        const char *name, 
index b8e23caaf2cb5d695b3b257b12eaae0c9a14c68c..1941a8b980ecb4c8f9b1a1106ea6a74a6afea222 100644 (file)
@@ -427,7 +427,7 @@ void ldap_int_initialize_global_options( struct ldapoptions *gopts, int *dbglvl
 
 #if defined(LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND) \
        || defined(HAVE_TLS) || defined(HAVE_CYRUS_SASL)
-char * ldap_int_hostname = "localhost";
+char * ldap_int_hostname = NULL;
 #endif
 
 void ldap_int_initialize( struct ldapoptions *gopts, int *dbglvl )
@@ -438,13 +438,7 @@ void ldap_int_initialize( struct ldapoptions *gopts, int *dbglvl )
 
 #if defined(LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND) \
        || defined(HAVE_TLS) || defined(HAVE_CYRUS_SASL)
-       {
-               static char hostbuf[MAXHOSTNAMELEN+1];
-               if( gethostname( hostbuf, MAXHOSTNAMELEN ) == 0 ) {
-                       hostbuf[MAXHOSTNAMELEN] = '\0';
-                       ldap_int_hostname = hostbuf;
-               }
-       }
+       ldap_int_hostname = ldap_pvt_get_fqdn( ldap_int_hostname );
 #endif
 
        ldap_int_utils_init();
index 126b573cb20f322d764a5be4c3d10b76c99afaa5..0cc70589d6bf6334085d86afed1fff952416b96a 100644 (file)
@@ -142,6 +142,7 @@ int ldap_pvt_gethostbyname_a(
 # define NEED_COPY_HOSTENT   
        struct hostent *he;
        int     retval;
+       *buf = NULL;
        
        ldap_pvt_thread_mutex_lock( &ldap_int_gethostby_mutex );
        
@@ -162,6 +163,7 @@ int ldap_pvt_gethostbyname_a(
        
        return retval;
 #else  
+       *buf = NULL;
        *result = gethostbyname( name );
 
        if (*result!=NULL) {
@@ -221,6 +223,7 @@ int ldap_pvt_gethostbyaddr_a(
 # define NEED_COPY_HOSTENT   
        struct hostent *he;
        int     retval;
+       *buf = NULL;   
        
        ldap_pvt_thread_mutex_lock( &ldap_int_gethostby_mutex );
        
@@ -241,6 +244,7 @@ int ldap_pvt_gethostbyaddr_a(
        
        return retval;   
 #else /* gethostbyaddr() */
+       *buf = NULL;   
        *result = gethostbyaddr( addr, len, type );
 
        if (*result!=NULL) {
@@ -377,4 +381,31 @@ static char *safe_realloc( char **buf, int len )
 }
 #endif
 
+char * ldap_pvt_get_fqdn( char *name )
+{
+       char *fqdn, *ha_buf;
+       char hostbuf[MAXHOSTNAMELEN+1];
+       struct hostent *hp, he_buf;
+       int rc, local_h_errno;
+
+       if( name == NULL ) {
+               if( gethostname( hostbuf, MAXHOSTNAMELEN ) == 0 ) {
+                       hostbuf[MAXHOSTNAMELEN] = '\0';
+                       name = hostbuf;
+               } else {
+                       name = "localhost";
+               }
+       }
+
+       rc = ldap_pvt_gethostbyname_a( name,
+               &he_buf, &ha_buf, &hp, &local_h_errno );
+
+       if( rc < 0 || hp == NULL || hp->h_name == NULL ) {
+               fqdn = LDAP_STRDUP( name );
+       } else {
+               fqdn = LDAP_STRDUP( hp->h_name );
+       }
 
+       LDAP_FREE( ha_buf );
+       return fqdn;
+}
index e179f32dbcd661ac233ad78ce62c7043123abae2..b7dab5a25d543499aaf25d6a62233c3f341db380 100644 (file)
@@ -609,18 +609,18 @@ static int chk_kerberos(
                }
 
                {
-                       char host[MAXHOSTNAMELEN+1];
+                       char *host = ldap_pvt_get_fqdn( NULL );
 
-                       if( gethostname( host, MAXHOSTNAMELEN ) != 0 ) {
+                       if( host == NULL ) {
                                krb5_free_principal( context, client );
                                krb5_free_context( context );
                                return 1;
                        }
 
-                       host[MAXHOSTNAMELEN] = '\0';
-
                        ret = krb5_sname_to_principal( context,
                                host, "ldap", KRB5_NT_SRV_HST, &server );
+
+                       ber_memfree( host );
                }
 
                if (ret) {
index 68c2709ab6053a4d96843e1bb5005a70982e6938..eca2ff12b16908981f81a2597e7b009301ade42b 100644 (file)
@@ -726,18 +726,18 @@ static int chk_kerberos(
                }
 
                {
-                       char host[MAXHOSTNAMELEN+1];
+                       char *host = ldap_pvt_get_fqdn( NULL );
 
-                       if( gethostname( host, MAXHOSTNAMELEN ) != 0 ) {
+                       if( host == NULL ) {
                                krb5_free_principal( context, client );
                                krb5_free_context( context );
                                return 1;
                        }
 
-                       host[MAXHOSTNAMELEN] = '\0';
-
                        ret = krb5_sname_to_principal( context,
                                host, "ldap", KRB5_NT_SRV_HST, &server );
+
+                       ber_memfree( host );
                }
 
                if (ret) {
index 6e46d65fe3572308064423f935ce550b87409485..2f37bb0f856a285cd7c77b21c33c4399c50b48f5 100644 (file)
@@ -196,12 +196,7 @@ int slap_sasl_init( void )
        }
 
        if( sasl_host == NULL ) {
-               static char hostname[MAXHOSTNAMELEN+1];
-
-               if( gethostname( hostname, MAXHOSTNAMELEN ) == 0 ) {
-                       hostname[MAXHOSTNAMELEN] = '\0';
-                       sasl_host = hostname;
-               }
+               sasl_host = ldap_pvt_get_fqdn( NULL );
        }
 
        Debug( LDAP_DEBUG_TRACE,