Because ads->config.ldap_server_name has a short (non-FQDN) hostname,
it cannot be resolved on some situation (e.g. DNS domainname and/or
search suffix != AD domainname) and ldap_open_with_timeout() failed.

-- fumiyas, 2007-07-11

--- samba-3.0.24.osstech/source/libads/ldap.c	2007-06-08 16:10:57.056007000 +0900
+++ samba-3.0.24.osstech/source/libads/ldap.c	2007-07-12 02:42:54.551925512 +0900
@@ -271,6 +271,7 @@ ADS_STATUS ads_connect(ADS_STRUCT *ads)
 {
 	int version = LDAP_VERSION3;
 	ADS_STATUS status;
+	fstring ldap_ip;
 
 	ads->last_attempt = time(NULL);
 	ads->ld = NULL;
@@ -289,7 +290,8 @@ ADS_STATUS ads_connect(ADS_STRUCT *ads)
 	return ADS_ERROR_SYSTEM(errno?errno:ENOENT);
 
 got_connection:
-	DEBUG(3,("Connected to LDAP server %s\n", inet_ntoa(ads->ldap_ip)));
+	fstrcpy(ldap_ip, inet_ntoa(ads->ldap_ip));
+	DEBUG(3,("Connected to LDAP server %s\n", ldap_ip));
 
 	if (!ads->auth.user_name) {
 		/* Must use the userPrincipalName value here or sAMAccountName
@@ -303,7 +305,7 @@ got_connection:
 	}
 
 	if (!ads->auth.kdc_server) {
-		ads->auth.kdc_server = SMB_STRDUP(inet_ntoa(ads->ldap_ip));
+		ads->auth.kdc_server = SMB_STRDUP(ldap_ip);
 	}
 
 #if KRB5_DNS_HACK
@@ -325,8 +327,8 @@ got_connection:
 	
 	/* Otherwise setup the TCP LDAP session */
 
-	if ( (ads->ld = ldap_open_with_timeout(ads->config.ldap_server_name, 
-		LDAP_PORT, lp_ldap_timeout())) == NULL )
+	if ( (ads->ld = ldap_open_with_timeout(ldap_ip, LDAP_PORT,
+		lp_ldap_timeout())) == NULL )
 	{
 		return ADS_ERROR(LDAP_OPERATIONS_ERROR);
 	}
