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.
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,
#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 )
#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();
# define NEED_COPY_HOSTENT
struct hostent *he;
int retval;
+ *buf = NULL;
ldap_pvt_thread_mutex_lock( &ldap_int_gethostby_mutex );
return retval;
#else
+ *buf = NULL;
*result = gethostbyname( name );
if (*result!=NULL) {
# define NEED_COPY_HOSTENT
struct hostent *he;
int retval;
+ *buf = NULL;
ldap_pvt_thread_mutex_lock( &ldap_int_gethostby_mutex );
return retval;
#else /* gethostbyaddr() */
+ *buf = NULL;
*result = gethostbyaddr( addr, len, type );
if (*result!=NULL) {
}
#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;
+}
}
{
- 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) {
}
{
- 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) {
}
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,