s3:wb_lookupsids: don't ignore 'result' and check if we got useable values
authorStefan Metzmacher <metze@samba.org>
Thu, 16 Jun 2011 16:16:15 +0000 (18:16 +0200)
committerStefan Metzmacher <metze@samba.org>
Thu, 16 Jun 2011 16:41:01 +0000 (18:41 +0200)
The wrong fix for bug #8215 discovered this bug, as it caused
sam_rids_to_names() to always return NT_STATUS_NONE_MAPPED.

metze

source3/winbindd/wb_lookupsids.c

index f3fac6c6305e808794b75160e3ead01cb68e3597..8f431ab4fc6d5992ac3e6a72a709dabeee13fb81 100644 (file)
@@ -428,6 +428,7 @@ static void wb_lookupsids_done(struct tevent_req *subreq)
                req, struct wb_lookupsids_state);
        struct wb_lookupsids_domain *d;
        uint32_t i;
+       bool fallback = false;
 
        NTSTATUS status, result;
 
@@ -437,13 +438,31 @@ static void wb_lookupsids_done(struct tevent_req *subreq)
                return;
        }
 
+       d = &state->domains[state->domains_done];
+
+       if (NT_STATUS_IS_ERR(result)) {
+               fallback = true;
+       } else if (state->tmp_names.count != d->sids.num_sids) {
+               fallback = true;
+       }
+
+       if (fallback) {
+               for (i=0; i < d->sids.num_sids; i++) {
+                       uint32_t res_sid_index = d->sid_indexes[i];
+
+                       state->single_sids[state->num_single_sids] =
+                               res_sid_index;
+                       state->num_single_sids += 1;
+               }
+               state->domains_done += 1;
+               wb_lookupsids_next(req, state);
+               return;
+       }
+
        /*
-        * Ignore "result" here. We depend on the individual states in
-        * the translated names.
+        * Look at the individual states in the translated names.
         */
 
-       d = &state->domains[state->domains_done];
-
        for (i=0; i<state->tmp_names.count; i++) {
 
                uint32_t res_sid_index = d->sid_indexes[i];
@@ -544,6 +563,7 @@ static void wb_lookupsids_lookuprids_done(struct tevent_req *subreq)
        NTSTATUS status, result;
        struct wb_lookupsids_domain *d;
        uint32_t i;
+       bool fallback = false;
 
        status = dcerpc_wbint_LookupRids_recv(subreq, state, &result);
        TALLOC_FREE(subreq);
@@ -552,6 +572,30 @@ static void wb_lookupsids_lookuprids_done(struct tevent_req *subreq)
        }
 
        d = &state->domains[state->domains_done];
+
+       if (NT_STATUS_IS_ERR(result)) {
+               fallback = true;
+       } else if (state->rid_names.num_principals != d->sids.num_sids) {
+               fallback = true;
+       }
+
+       if (fallback) {
+               for (i=0; i < d->sids.num_sids; i++) {
+                       uint32_t res_sid_index = d->sid_indexes[i];
+
+                       state->single_sids[state->num_single_sids] =
+                               res_sid_index;
+                       state->num_single_sids += 1;
+               }
+               state->domains_done += 1;
+               wb_lookupsids_next(req, state);
+               return;
+       }
+
+       /*
+        * Look at the individual states in the translated names.
+        */
+
        sid_copy(&src_domain_sid, get_global_sam_sid());
        src_domain.name.string = get_global_sam_name();
        src_domain.sid = &src_domain_sid;