Ensure that winbindd and smbd both use identical logic to find dc's.
authorJeremy Allison <jra@samba.org>
Thu, 28 Feb 2002 01:05:15 +0000 (01:05 +0000)
committerJeremy Allison <jra@samba.org>
Thu, 28 Feb 2002 01:05:15 +0000 (01:05 +0000)
Fix bug where zeroip addresses were being checked.
Jeremy.

source/auth/auth_domain.c
source/libsmb/namequery.c
source/nsswitch/winbindd_cm.c

index 947cd41a26594e06259b8826aebcd3dadfde0749..c7bfea4f6a8015b7c37878919cd25844184a653e 100644 (file)
@@ -197,9 +197,8 @@ static NTSTATUS find_connect_pdc(struct cli_state **cli,
                if(!is_local_net(ip_list[i]))
                        continue;
 
-               if(NT_STATUS_IS_OK(nt_status = 
-                                  attempt_connect_to_dc(cli, domain, 
-                                                        &ip_list[i], trust_passwd))) 
+               if(NT_STATUS_IS_OK(nt_status = attempt_connect_to_dc(cli, domain, 
+                                               &ip_list[i], trust_passwd))) 
                        break;
                
                zero_ip(&ip_list[i]); /* Tried and failed. */
@@ -211,10 +210,11 @@ static NTSTATUS find_connect_pdc(struct cli_state **cli,
        if(!NT_STATUS_IS_OK(nt_status)) {
                i = (sys_random() % count);
 
-               if (!NT_STATUS_IS_OK(nt_status = 
-                                    attempt_connect_to_dc(cli, domain, 
-                                                          &ip_list[i], trust_passwd)))
-                        zero_ip(&ip_list[i]); /* Tried and failed. */
+               if (!is_zero_ip(ip_list[i])) {
+                       if (!NT_STATUS_IS_OK(nt_status = attempt_connect_to_dc(cli, domain, 
+                                               &ip_list[i], trust_passwd)))
+                       zero_ip(&ip_list[i]); /* Tried and failed. */
+               }
        }
 
        /*
@@ -227,15 +227,16 @@ static NTSTATUS find_connect_pdc(struct cli_state **cli,
                 * Note that from a WINS server the #1 IP address is the PDC.
                 */
                for(i = 0; i < count; i++) {
-                       if (NT_STATUS_IS_OK(nt_status = 
-                                           attempt_connect_to_dc(cli, domain, 
-                                                                 &ip_list[i], trust_passwd)))
+                       if (is_zero_ip(ip_list[i]))
+                               continue;
+
+                       if (NT_STATUS_IS_OK(nt_status = attempt_connect_to_dc(cli, domain, 
+                                                 &ip_list[i], trust_passwd)))
                                break;
                }
        }
 
        SAFE_FREE(ip_list);
-
        return nt_status;
 }
 
index f03ede10cd6d1556cb362a2515a20fa1e0789982..0370365953d67508db18afed17f5be0a8a7e326c 100644 (file)
@@ -1269,6 +1269,14 @@ NT GETDC call, UNICODE, NT domain SID and uncle tom cobbley and all...
 #endif /* defined(I_HATE_WINDOWS_REPLY_CODE) */
 }
 
+/********************************************************
+  Get the IP address list of the Local Master Browsers
+ ********************************************************/ 
+
+BOOL get_lmb_list(struct in_addr **ip_list, int *count)
+{
+    return internal_resolve_name( MSBROWSE, 0x1, ip_list, count);
+}
 
 /********************************************************
  Get the IP address list of the PDC/BDC's of a Domain.
@@ -1320,11 +1328,3 @@ BOOL get_dc_list(BOOL pdc_only, const char *group, struct in_addr **ip_list, int
        } else
                return internal_resolve_name(group, name_type, ip_list, count);
 }
-
-/********************************************************
-  Get the IP address list of the Local Master Browsers
- ********************************************************/ 
-BOOL get_lmb_list(struct in_addr **ip_list, int *count)
-{
-    return internal_resolve_name( MSBROWSE, 0x1, ip_list, count);
-}
index 3aaaf6b67096f8e88b09255303f39b6bfcd60571..dcbd47303f3bae8f3374a33e0a92e8942ef8aa94 100644 (file)
@@ -148,47 +148,46 @@ static BOOL cm_get_dc_name(const char *domain, fstring srv_name, struct in_addr
        }
 
        /* Pick a nice close server */
-          
-       if (strequal(lp_passwordserver(), "*")) {
+       /* Look for DC on local net */
+
+       for (i = 0; i < count; i++) {
+               if (!is_local_net(ip_list[i]))
+                       continue;
                
-               /* Look for DC on local net */
-
-               for (i = 0; i < count; i++) {
-                       if (is_local_net(ip_list[i]) &&
-                           name_status_find(domain, 0x1c, 0x20,
-                                            ip_list[i], srv_name)) {
-                               dc_ip = ip_list[i];
-                               goto done;
-                       }
-                       zero_ip(&ip_list[i]);
+               if (name_status_find(domain, 0x1c, 0x20, ip_list[i], srv_name)) {
+                       dc_ip = ip_list[i];
+                       goto done;
                }
+               zero_ip(&ip_list[i]);
+       }
 
-               /* Look for other DCs */
-
-               for (i = 0; i < count; i++) {
-                       if (!is_zero_ip(ip_list[i]) &&
-                           name_status_find(domain, 0x1c, 0x20,
-                                            ip_list[i], srv_name)) {
-                               dc_ip = ip_list[i];
-                               goto done;
-                       }
-               }
+       /*
+        * Secondly try and contact a random PDC/BDC.
+        */
 
-               /* No-one to talk to )-: */
+       i = (sys_random() % count);
 
-               return False;
+       if (!is_zero_ip(ip_list[i]) &&
+           name_status_find(domain, 0x1c, 0x20,
+                            ip_list[i], srv_name)) {
+               dc_ip = ip_list[i];
+               goto done;
        }
+       zero_ip(&ip_list[i]); /* Tried and failed. */
 
-       /* Return first DC that we can contact */
+       /* Finally return first DC that we can contact */
 
        for (i = 0; i < count; i++) {
-               if (name_status_find(domain, 0x1c, 0x20, ip_list[i],
-                                    srv_name)) {
+               if (is_zero_ip(ip_list[i]))
+                       continue;
+
+               if (name_status_find(domain, 0x1c, 0x20, ip_list[i], srv_name)) {
                        dc_ip = ip_list[i];
                        goto done;
                }
        }
 
+       /* No-one to talk to )-: */
        return False;           /* Boo-hoo */
        
  done:
@@ -201,7 +200,7 @@ static BOOL cm_get_dc_name(const char *domain, fstring srv_name, struct in_addr
 
        fstrcpy(dcc->srv_name, srv_name);
 
-       DEBUG(3, ("Returning DC %s (%s) for domain %s\n", srv_name,
+       DEBUG(3, ("cm_get_dc_name: Returning DC %s (%s) for domain %s\n", srv_name,
                  inet_ntoa(dc_ip), domain));
 
        *ip_out = dc_ip;