r17881: Another microstep towards better error reporting: Make get_sorted_dc_list
authorVolker Lendecke <vlendec@samba.org>
Mon, 28 Aug 2006 09:19:30 +0000 (09:19 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 16:38:57 +0000 (11:38 -0500)
return NTSTATUS.

If we want to differentiate different name resolution problems we might want
to introduce yet another error class for Samba-internal errors. Things like no
route to host to the WINS server, a DNS server explicitly said host not found
etc might be worth passing up.

Because we can not stash everything into the existing NT_STATUS codes, what
about a Samba-specific error class like NT_STATUS_DOS and NT_STATUS_LDAP?

Volker

source/libads/ldap.c
source/libsmb/namequery.c
source/libsmb/namequery_dc.c
source/nsswitch/winbindd_rpc.c
source/utils/net_lookup.c

index 4f1f0146a7ca3ad6223cc5714a8a77703bb2b4df..402e37b3c0517eb0d048a57e912e3d72ebade6fb 100644 (file)
@@ -182,7 +182,7 @@ BOOL ads_try_connect(ADS_STRUCT *ads, const char *server )
  disabled
 **********************************************************************/
 
-static BOOL ads_find_dc(ADS_STRUCT *ads)
+static NTSTATUS ads_find_dc(ADS_STRUCT *ads)
 {
        const char *c_realm;
        int count, i=0;
@@ -190,6 +190,7 @@ static BOOL ads_find_dc(ADS_STRUCT *ads)
        pstring realm;
        BOOL got_realm = False;
        BOOL use_own_domain = False;
+       NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
 
        /* if the realm and workgroup are both empty, assume they are ours */
 
@@ -220,7 +221,7 @@ again:
                
                if ( !c_realm || !*c_realm ) {
                        DEBUG(0,("ads_find_dc: no realm or workgroup!  Don't know what to do\n"));
-                       return False;
+                       return NT_STATUS_INVALID_PARAMETER; /* rather need MISSING_PARAMETER ... */
                }
        }
        
@@ -229,14 +230,15 @@ again:
        DEBUG(6,("ads_find_dc: looking for %s '%s'\n", 
                (got_realm ? "realm" : "domain"), realm));
 
-       if ( !get_sorted_dc_list(realm, &ip_list, &count, got_realm) ) {
+       status = get_sorted_dc_list(realm, &ip_list, &count, got_realm);
+       if (!NT_STATUS_IS_OK(status)) {
                /* fall back to netbios if we can */
                if ( got_realm && !lp_disable_netbios() ) {
                        got_realm = False;
                        goto again;
                }
                
-               return False;
+               return status;
        }
                        
        /* if we fail this loop, then giveup since all the IP addresses returned were dead */
@@ -250,7 +252,7 @@ again:
                        
                if ( ads_try_connect(ads, server) ) {
                        SAFE_FREE(ip_list);
-                       return True;
+                       return NT_STATUS_OK;
                }
                
                /* keep track of failures */
@@ -259,7 +261,7 @@ again:
 
        SAFE_FREE(ip_list);
        
-       return False;
+       return NT_STATUS_NO_LOGON_SERVERS;
 }
 
 
@@ -272,6 +274,7 @@ ADS_STATUS ads_connect(ADS_STRUCT *ads)
 {
        int version = LDAP_VERSION3;
        ADS_STATUS status;
+       NTSTATUS ntstatus;
 
        ads->last_attempt = time(NULL);
        ads->ld = NULL;
@@ -283,11 +286,12 @@ ADS_STATUS ads_connect(ADS_STRUCT *ads)
                goto got_connection;
        }
 
-       if (ads_find_dc(ads)) {
+       ntstatus = ads_find_dc(ads);
+       if (NT_STATUS_IS_OK(ntstatus)) {
                goto got_connection;
        }
 
-       return ADS_ERROR_NT(NT_STATUS_NO_LOGON_SERVERS);
+       return ADS_ERROR_NT(ntstatus);
 
 got_connection:
        DEBUG(3,("Connected to LDAP server %s\n", inet_ntoa(ads->ldap_ip)));
index 14dfd5082965fb7438984b7701f90959c38359b5..62f21d94c7f30061b2c31de5b3050bf37bf66c39 100644 (file)
@@ -1360,8 +1360,8 @@ BOOL get_pdc_ip(const char *domain, struct in_addr *ip)
  a domain.
 *********************************************************/
 
-static BOOL get_dc_list(const char *domain, struct ip_service **ip_list, 
-                 int *count, BOOL ads_only, int *ordered)
+static NTSTATUS get_dc_list(const char *domain, struct ip_service **ip_list, 
+                            int *count, BOOL ads_only, int *ordered)
 {
        fstring resolve_order;
        char *saf_servername;
@@ -1419,7 +1419,14 @@ static BOOL get_dc_list(const char *domain, struct ip_service **ip_list,
 
        if ( !*pserver ) {
                DEBUG(10,("get_dc_list: no preferred domain controllers.\n"));
-               return internal_resolve_name(domain, 0x1C, ip_list, count, resolve_order);
+               /* TODO: change return type of internal_resolve_name to
+                * NTSTATUS */
+               if (internal_resolve_name(domain, 0x1C, ip_list, count,
+                                         resolve_order)) {
+                       return NT_STATUS_OK;
+               } else {
+                       return NT_STATUS_NO_LOGON_SERVERS;
+               }
        }
 
        DEBUG(3,("get_dc_list: preferred server list: \"%s\"\n", pserver ));
@@ -1434,7 +1441,8 @@ static BOOL get_dc_list(const char *domain, struct ip_service **ip_list,
        p = pserver;
        while (next_token(&p,name,LIST_SEP,sizeof(name))) {
                if (strequal(name, "*")) {
-                       if ( internal_resolve_name(domain, 0x1C, &auto_ip_list, &auto_count, resolve_order) )
+                       if (internal_resolve_name(domain, 0x1C, &auto_ip_list,
+                                                 &auto_count, resolve_order))
                                num_addresses += auto_count;
                        done_auto_lookup = True;
                        DEBUG(8,("Adding %d DC's from auto lookup\n", auto_count));
@@ -1448,16 +1456,20 @@ static BOOL get_dc_list(const char *domain, struct ip_service **ip_list,
                   
        if ( (num_addresses == 0) ) {
                if ( !done_auto_lookup ) {
-                       return internal_resolve_name(domain, 0x1C, ip_list, count, resolve_order);
+                       if (internal_resolve_name(domain, 0x1C, ip_list, count, resolve_order)) {
+                               return NT_STATUS_OK;
+                       } else {
+                               return NT_STATUS_NO_LOGON_SERVERS;
+                       }
                } else {
                        DEBUG(4,("get_dc_list: no servers found\n")); 
-                       return False;
+                       return NT_STATUS_NO_LOGON_SERVERS;
                }
        }
 
        if ( (return_iplist = SMB_MALLOC_ARRAY(struct ip_service, num_addresses)) == NULL ) {
                DEBUG(3,("get_dc_list: malloc fail !\n"));
-               return False;
+               return NT_STATUS_NO_MEMORY;
        }
 
        p = pserver;
@@ -1535,22 +1547,24 @@ static BOOL get_dc_list(const char *domain, struct ip_service **ip_list,
        *ip_list = return_iplist;
        *count = local_count;
 
-       return (*count != 0);
+       return ( *count != 0 ? NT_STATUS_OK : NT_STATUS_NO_LOGON_SERVERS );
 }
 
 /*********************************************************************
  Small wrapper function to get the DC list and sort it if neccessary.
 *********************************************************************/
 
-BOOL get_sorted_dc_list( const char *domain, struct ip_service **ip_list, int *count, BOOL ads_only )
+NTSTATUS get_sorted_dc_list( const char *domain, struct ip_service **ip_list, int *count, BOOL ads_only )
 {
        BOOL ordered;
+       NTSTATUS status;
        
        DEBUG(8,("get_sorted_dc_list: attempting lookup using [%s]\n",
                (ads_only ? "ads" : lp_name_resolve_order())));
        
-       if ( !get_dc_list(domain, ip_list, count, ads_only, &ordered) ) {
-               return False; 
+       status = get_dc_list(domain, ip_list, count, ads_only, &ordered);
+       if (!NT_STATUS_IS_OK(status)) {
+               return status; 
        }
                
        /* only sort if we don't already have an ordered list */
@@ -1558,5 +1572,5 @@ BOOL get_sorted_dc_list( const char *domain, struct ip_service **ip_list, int *c
                sort_ip_list2( *ip_list, *count );
        }
                
-       return True;
+       return NT_STATUS_OK;
 }
index b9a593bf2a73834bee0411056656ad3aeb92ab00..4afd04a98f96d8097ff6836b3ad068c51c0e6ed8 100644 (file)
@@ -81,7 +81,8 @@ static BOOL rpc_dc_name(const char *domain, fstring srv_name, struct in_addr *ip
 
        /* get a list of all domain controllers */
        
-       if ( !get_sorted_dc_list(domain, &ip_list, &count, False) ) {
+       if (!NT_STATUS_IS_OK(get_sorted_dc_list(domain, &ip_list, &count,
+                                               False))) {
                DEBUG(3, ("Could not look up dc's for domain %s\n", domain));
                return False;
        }
index d8797ee2bc6e15d6c2cec49525b6fb637c06bda4..f4676cc2fe0703df0f916e306b14c061dfef5505 100644 (file)
@@ -774,7 +774,8 @@ static int get_ldap_sequence_number( const char* domain, uint32 *seq)
        struct ip_service *ip_list = NULL;
        int count;
        
-       if ( !get_sorted_dc_list(domain, &ip_list, &count, False) ) {
+       if ( !NT_STATUS_IS_OK(get_sorted_dc_list(domain, &ip_list, &count,
+                                                False)) ) {
                DEBUG(3, ("Could not look up dc's for domain %s\n", domain));
                return False;
        }
index 68097aa9f7fe5343e3cf86db486720c74de2417a..8e1450cfa0638a9bd24cf3d8202961fbf5a15dbd 100644 (file)
@@ -165,7 +165,7 @@ static int net_lookup_dc(int argc, const char **argv)
        asprintf(&pdc_str, "%s", inet_ntoa(addr));
        d_printf("%s\n", pdc_str);
 
-       if (!get_sorted_dc_list(domain, &ip_list, &count, False)) {
+       if (!NT_STATUS_IS_OK(get_sorted_dc_list(domain, &ip_list, &count, False))) {
                SAFE_FREE(pdc_str);
                return 0;
        }