winbindd: queryuser - only get group name if needed
authorUri Simchoni <uri@samba.org>
Wed, 7 Jun 2017 17:33:57 +0000 (20:33 +0300)
committerJeremy Allison <jra@samba.org>
Fri, 21 Jul 2017 17:11:13 +0000 (19:11 +0200)
When calculating the user entry for a user, the
primary group id *name* might be needed if it is
part of a home dir / shell template (%g or %G).

Only resolve primary group SID to primary group name
if it is needed, thereby saving a round-trip to the DC
(and better handling situations where it is disconnected).

Signed-off-by: Uri Simchoni <uri@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/winbindd/wb_queryuser.c

index 69b4c8dad5aa4a65414a3f5cd47383d923df9c66..1c91949c2558bc674966ab5d91e420dd1f1065e3 100644 (file)
@@ -202,6 +202,8 @@ static void wb_queryuser_done(struct tevent_req *subreq)
                req, struct wb_queryuser_state);
        struct wbint_userinfo *info = state->info;
        NTSTATUS status, result;
+       bool need_group_name = false;
+       const char *tmpl = NULL;
 
        status = dcerpc_wbint_GetNssInfo_recv(subreq, info, &result);
        TALLOC_FREE(subreq);
@@ -236,7 +238,16 @@ static void wb_queryuser_done(struct tevent_req *subreq)
                return;
        }
 
-       if (state->info->primary_group_name == NULL) {
+       tmpl = lp_template_homedir();
+       if(strstr_m(tmpl, "%g") || strstr_m(tmpl, "%G")) {
+               need_group_name = true;
+       }
+       tmpl = lp_template_shell();
+       if(strstr_m(tmpl, "%g") || strstr_m(tmpl, "%G")) {
+               need_group_name = true;
+       }
+
+       if (need_group_name && state->info->primary_group_name == NULL) {
                subreq = wb_lookupsid_send(state, state->ev, &info->group_sid);
                if (tevent_req_nomem(subreq, req)) {
                        return;
@@ -291,6 +302,8 @@ static void wb_queryuser_got_gid(struct tevent_req *subreq)
                req, struct wb_queryuser_state);
        struct unixid xid;
        NTSTATUS status;
+       bool need_group_name = false;
+       const char *tmpl = NULL;
 
        status = wb_sids2xids_recv(subreq, &xid, 1);
        TALLOC_FREE(subreq);
@@ -305,7 +318,16 @@ static void wb_queryuser_got_gid(struct tevent_req *subreq)
 
        state->info->primary_gid = xid.id;
 
-       if (state->info->primary_group_name == NULL) {
+       tmpl = lp_template_homedir();
+       if(strstr_m(tmpl, "%g") || strstr_m(tmpl, "%G")) {
+               need_group_name = true;
+       }
+       tmpl = lp_template_shell();
+       if(strstr_m(tmpl, "%g") || strstr_m(tmpl, "%G")) {
+               need_group_name = true;
+       }
+
+       if (need_group_name && state->info->primary_group_name == NULL) {
                subreq = wb_lookupsid_send(state, state->ev,
                                           &state->info->group_sid);
                if (tevent_req_nomem(subreq, req)) {