From: Uri Simchoni Date: Wed, 7 Jun 2017 17:33:57 +0000 (+0300) Subject: winbindd: queryuser - only get group name if needed X-Git-Tag: talloc-2.1.10~3 X-Git-Url: http://git.samba.org/?a=commitdiff_plain;h=c819c7d58f05692628eb9673dfdca5dc1d212d43;p=samba.git winbindd: queryuser - only get group name if needed 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 Reviewed-by: Jeremy Allison --- diff --git a/source3/winbindd/wb_queryuser.c b/source3/winbindd/wb_queryuser.c index 69b4c8dad5a..1c91949c255 100644 --- a/source3/winbindd/wb_queryuser.c +++ b/source3/winbindd/wb_queryuser.c @@ -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)) {