s3:winbindd: use wb_sids2xids instead of wb_sid2uid in winbindd_sid_to_uid
authorMichael Adam <obnox@samba.org>
Sat, 17 Nov 2012 12:04:41 +0000 (13:04 +0100)
committerStefan Metzmacher <metze@samba.org>
Mon, 3 Dec 2012 07:48:21 +0000 (08:48 +0100)
The main purpose of the change is to hand the sid into the
idmap backend and handle responsiblity for handling the
sid-type correctly to the idmap backend instead of failing
directly when the sid is not of type user.

Hence backends like rid who are sid-type agnostic, can
return uids also for sids of other types. This is an important
fix to make sid_to_uid behave the consistently with and without
the presence of cache entries.

We need to additionally filter the result for id type UID
or more general (BOTH) to keep the behaviour.

This is a step towards using only one codepath to id_mapping.

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
source3/winbindd/winbindd_sid_to_uid.c

index 9ce564f02e8193337199b26e736405660c757e0d..67fe9527dc10213f219cff4e76e0fa929c97617e 100644 (file)
@@ -54,7 +54,7 @@ struct tevent_req *winbindd_sid_to_uid_send(TALLOC_CTX *mem_ctx,
                return tevent_req_post(req, ev);
        }
 
-       subreq = wb_sid2uid_send(state, ev, &state->sid);
+       subreq = wb_sids2xids_send(state, ev, &state->sid, 1);
        if (tevent_req_nomem(subreq, req)) {
                return tevent_req_post(req, ev);
        }
@@ -69,12 +69,26 @@ static void winbindd_sid_to_uid_done(struct tevent_req *subreq)
        struct winbindd_sid_to_uid_state *state = tevent_req_data(
                req, struct winbindd_sid_to_uid_state);
        NTSTATUS status;
+       struct unixid xid;
 
-       status = wb_sid2uid_recv(subreq, &state->uid);
+       status = wb_sids2xids_recv(subreq, &xid);
        TALLOC_FREE(subreq);
        if (tevent_req_nterror(req, status)) {
                return;
        }
+
+       /*
+        * We are filtering further down in sids2xids, but that filtering
+        * depends on the actual type of the sid handed in (as determined
+        * by lookupsids). Here we need to filter for the type of object
+        * actually requested, in this case uid.
+        */
+       if (!(xid.type == ID_TYPE_UID || xid.type == ID_TYPE_BOTH)) {
+               tevent_req_nterror(req, NT_STATUS_NONE_MAPPED);
+               return;
+       }
+
+       state->uid = (uid_t)xid.id;
        tevent_req_done(req);
 }