diff options
author | Andrew Tridgell <tridge@samba.org> | 2002-04-18 06:56:44 +0000 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2002-04-18 06:56:44 +0000 |
commit | c0a991943044e038b78f796fb35d7625eb843d85 (patch) | |
tree | 5a837cd8ab9f1ec00c42d8a623795eb604dc8329 /source3/libads/ldap.c | |
parent | 6a9bc86d62cc9ba532392af02a5d71e50b6b0411 (diff) | |
download | samba-c0a991943044e038b78f796fb35d7625eb843d85.tar.gz samba-c0a991943044e038b78f796fb35d7625eb843d85.tar.bz2 samba-c0a991943044e038b78f796fb35d7625eb843d85.zip |
fixed the fallback to a BDC for ADS connections
(This used to be commit 3e58a1ee83ea0b4347ce24e566445cc6cb67bb3a)
Diffstat (limited to 'source3/libads/ldap.c')
-rw-r--r-- | source3/libads/ldap.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/source3/libads/ldap.c b/source3/libads/ldap.c index e2e351bd4b..3b787c6a8f 100644 --- a/source3/libads/ldap.c +++ b/source3/libads/ldap.c @@ -46,9 +46,33 @@ ADS_STATUS ads_connect(ADS_STRUCT *ads) ads->last_attempt = time(NULL); ads->ld = ldap_open(ads->ldap_server, ads->ldap_port); + + /* if that failed then try each of the BDC's in turn */ + if (!ads->ld) { + struct in_addr *ip_list; + int count; + + if (get_dc_list(False, ads->workgroup, &ip_list, &count)) { + int i; + for (i=0;i<count;i++) { + ads->ld = ldap_open(inet_ntoa(ip_list[i]), + ads->ldap_port); + if (ads->ld) break; + } + if (ads->ld) { + free(ads->ldap_server); + ads->ldap_server = strdup(inet_ntoa(ip_list[i])); + } + free(ip_list); + } + } + if (!ads->ld) { return ADS_ERROR_SYSTEM(errno); } + + DEBUG(3,("Connected to LDAP server %s\n", ads->ldap_server)); + status = ads_server_info(ads); if (!ADS_ERR_OK(status)) { DEBUG(1,("Failed to get ldap server info\n")); |