summaryrefslogtreecommitdiff
path: root/source3/nsswitch/winbindd_cm.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2002-10-23 03:37:51 +0000
committerAndrew Tridgell <tridge@samba.org>2002-10-23 03:37:51 +0000
commite53b7d6496957ed4d80c82120df81c13abb8e298 (patch)
treebd7d6129db900580aa3e448045772f9dc409a013 /source3/nsswitch/winbindd_cm.c
parentb064077145e61ed4bdf2ccb9b91c94b8c2acb27a (diff)
downloadsamba-e53b7d6496957ed4d80c82120df81c13abb8e298.tar.gz
samba-e53b7d6496957ed4d80c82120df81c13abb8e298.tar.bz2
samba-e53b7d6496957ed4d80c82120df81c13abb8e298.zip
much simpler code to choose a DC to contact in winbindd. We now always
choose the server that has the most bits in common in its IP with one of our interfaces. (This used to be commit 31774dce67844b67cb405e65f307a20354f2cedb)
Diffstat (limited to 'source3/nsswitch/winbindd_cm.c')
-rw-r--r--source3/nsswitch/winbindd_cm.c61
1 files changed, 6 insertions, 55 deletions
diff --git a/source3/nsswitch/winbindd_cm.c b/source3/nsswitch/winbindd_cm.c
index 5f477c78f7..3b83fde95b 100644
--- a/source3/nsswitch/winbindd_cm.c
+++ b/source3/nsswitch/winbindd_cm.c
@@ -140,70 +140,20 @@ static BOOL cm_ads_find_dc(const char *domain, struct in_addr *dc_ip, fstring sr
*/
static BOOL cm_rpc_find_dc(const char *domain, struct in_addr *dc_ip, fstring srv_name)
{
- struct in_addr *ip_list = NULL, exclude_ip;
+ struct in_addr *ip_list = NULL;
int count, i;
- zero_ip(&exclude_ip);
-
- /* Lookup domain controller name. Try the real PDC first to avoid
- SAM sync delays */
-
- if (get_dc_list(True, domain, &ip_list, &count)) {
- if (name_status_find(domain, 0x1c, 0x20, ip_list[0], srv_name)) {
- *dc_ip = ip_list[0];
- SAFE_FREE(ip_list);
- return True;
- }
- /* Didn't get name, remember not to talk to this DC. */
- exclude_ip = ip_list[0];
- SAFE_FREE(ip_list);
- }
-
- if (!get_dc_list(False, domain, &ip_list, &count)) {
+ if (!get_dc_list(False, domain, &ip_list, &count) &&
+ !get_dc_list(True, domain, &ip_list, &count)) {
DEBUG(3, ("Could not look up dc's for domain %s\n", domain));
return False;
}
- /* Remove the entry we've already failed with (should be the PDC). */
- for (i = 0; i < count; i++) {
- if (ip_equal( exclude_ip, ip_list[i]))
- zero_ip(&ip_list[i]);
- }
-
/* Pick a nice close server */
- /* Look for DC on local net */
- for (i = 0; i < count; i++) {
- if (is_zero_ip(ip_list[i]))
- continue;
-
- if (!is_local_net(ip_list[i]))
- continue;
-
- if (name_status_find(domain, 0x1c, 0x20, ip_list[i], srv_name)) {
- *dc_ip = ip_list[i];
- SAFE_FREE(ip_list);
- return True;
- }
- zero_ip(&ip_list[i]);
- }
-
- /*
- * Secondly try and contact a random PDC/BDC.
- */
-
- i = (sys_random() % count);
-
- if (!is_zero_ip(ip_list[i]) &&
- name_status_find(domain, 0x1c, 0x20,
- ip_list[i], srv_name)) {
- *dc_ip = ip_list[i];
- SAFE_FREE(ip_list);
- return True;
+ if (count > 1) {
+ qsort(ip_list, count, sizeof(struct in_addr), QSORT_CAST ip_compare);
}
- zero_ip(&ip_list[i]); /* Tried and failed. */
- /* Finally return first DC that we can contact using a node
- status */
for (i = 0; i < count; i++) {
if (is_zero_ip(ip_list[i]))
continue;
@@ -215,6 +165,7 @@ static BOOL cm_rpc_find_dc(const char *domain, struct in_addr *dc_ip, fstring sr
}
}
+
SAFE_FREE(ip_list);
return False;