mirror of
https://git.openldap.org/openldap/openldap.git
synced 2024-12-09 02:52:04 +08:00
Add char* ldap_pvt_get_fqdn(char*) which returns the FQDN of the
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.
This commit is contained in:
parent
0f5a264dc3
commit
3b03b64b77
@ -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,
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user