s3:winbindd: change getpwsid() to return a passwd struct for a group sid id-mapped...
authorMichael Adam <obnox@samba.org>
Tue, 22 Jan 2013 17:08:25 +0000 (18:08 +0100)
committerStefan Metzmacher <metze@samba.org>
Tue, 29 Jan 2013 21:01:27 +0000 (22:01 +0100)
Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
source3/winbindd/wb_getpwsid.c

index ef54ee5f48e9a0ef28c9e09eb85b2469369edd7c..df8b0f2dcc744de563cdb2385b807a6c7fe338cb 100644 (file)
@@ -67,12 +67,10 @@ static void wb_getpwsid_queryuser_done(struct tevent_req *subreq)
 
        status = wb_queryuser_recv(subreq, state, &state->userinfo);
        TALLOC_FREE(subreq);
-       if (tevent_req_nterror(req, status)) {
-               return;
-       }
-
-       if ((state->userinfo->acct_name != NULL)
-           && (state->userinfo->acct_name[0] != '\0')) {
+       if (NT_STATUS_IS_OK(status)
+           && (state->userinfo->acct_name != NULL)
+           && (state->userinfo->acct_name[0] != '\0'))
+       {
                /*
                 * QueryUser got us a name, let's got directly to the
                 * fill_pwent step
@@ -87,10 +85,25 @@ static void wb_getpwsid_queryuser_done(struct tevent_req *subreq)
        }
 
        /*
-        * QueryUser didn't get us a name, do it via LSA.
+        * Either query_user did not succeed, or it
+        * succeeded but did not return an acct_name.
+        * (TODO: Can this happen at all???)
+        * ==> Try lsa_lookupsids.
         */
-       subreq = wb_lookupsid_send(state, state->ev,
-                                  &state->userinfo->user_sid);
+       if (state->userinfo == NULL) {
+               state->userinfo = talloc_zero(state, struct wbint_userinfo);
+               if (tevent_req_nomem(state->userinfo, req)) {
+                       return;
+               }
+
+               /* a successful query_user call would have filled these */
+               sid_copy(&state->userinfo->user_sid, &state->sid);
+               state->userinfo->homedir = NULL;
+               state->userinfo->shell = NULL;
+               state->userinfo->primary_gid = (gid_t)-1;
+       }
+
+       subreq = wb_lookupsid_send(state, state->ev, &state->sid);
        if (tevent_req_nomem(subreq, req)) {
                return;
        }
@@ -113,6 +126,27 @@ static void wb_getpwsid_lookupsid_done(struct tevent_req *subreq)
        if (tevent_req_nterror(req, status)) {
                return;
        }
+
+       switch (type) {
+       case SID_NAME_USER:
+       case SID_NAME_COMPUTER:
+               /*
+                * user case: we only need the account name from lookup_sids
+                */
+               break;
+       case SID_NAME_DOM_GRP:
+       case SID_NAME_ALIAS:
+       case SID_NAME_WKN_GRP:
+               /*
+                * also treat group-type SIDs (they might map to ID_TYPE_BOTH)
+                */
+               sid_copy(&state->userinfo->group_sid, &state->sid);
+               break;
+       default:
+               tevent_req_nterror(req, NT_STATUS_NO_SUCH_USER);
+               return;
+       }
+
        subreq = wb_fill_pwent_send(state, state->ev, state->userinfo,
                                    state->pw);
        if (tevent_req_nomem(subreq, req)) {