a3a04f
From 0eb6274aacc95601cb9a94922a8176935f336f92 Mon Sep 17 00:00:00 2001
a3a04f
From: Andreas Schneider <asn@samba.org>
a3a04f
Date: Tue, 20 Jun 2017 10:27:07 +0200
a3a04f
Subject: [PATCH] s3:winbind: Fix 'winbind normalize names' in wb_getpwsid()
a3a04f
a3a04f
BUG: https://bugzilla.samba.org/show_bug.cgi?id=12851
a3a04f
a3a04f
Signed-off-by: Andreas Schneider <asn@samba.org>
a3a04f
Reviewed-by: Volker Lendecke <vl@samba.org>
a3a04f
---
a3a04f
 source3/winbindd/wb_getpwsid.c | 34 +++++++++++++++++++++++++++++++---
a3a04f
 1 file changed, 31 insertions(+), 3 deletions(-)
a3a04f
a3a04f
diff --git a/source3/winbindd/wb_getpwsid.c b/source3/winbindd/wb_getpwsid.c
a3a04f
index 8c764f77b08..b0bf6784ba6 100644
a3a04f
--- a/source3/winbindd/wb_getpwsid.c
a3a04f
+++ b/source3/winbindd/wb_getpwsid.c
a3a04f
@@ -63,7 +63,9 @@ static void wb_getpwsid_queryuser_done(struct tevent_req *subreq)
a3a04f
 		req, struct wb_getpwsid_state);
a3a04f
 	struct winbindd_pw *pw = state->pw;
a3a04f
 	struct wbint_userinfo *info;
a3a04f
+	struct winbindd_domain *domain = NULL;
a3a04f
 	fstring acct_name, output_username;
a3a04f
+	char *mapped_name = NULL;
a3a04f
 	char *tmp;
a3a04f
 	NTSTATUS status;
a3a04f
 
a3a04f
@@ -83,8 +85,34 @@ static void wb_getpwsid_queryuser_done(struct tevent_req *subreq)
a3a04f
 		return;
a3a04f
 	}
a3a04f
 
a3a04f
-	fill_domain_username(output_username, info->domain_name,
a3a04f
-			     acct_name, true);
a3a04f
+	domain = find_domain_from_name_noinit(info->domain_name);
a3a04f
+	if (tevent_req_nomem(domain, req)) {
a3a04f
+		return;
a3a04f
+	}
a3a04f
+
a3a04f
+	/*
a3a04f
+	 * TODO:
a3a04f
+	 * This function should be called in 'idmap winbind child'. It shouldn't
a3a04f
+	 * be a blocking call, but for this we need to add a new function for
a3a04f
+	 * winbind.idl. This is a fix which can be backported for now.
a3a04f
+	 */
a3a04f
+	status = normalize_name_map(state,
a3a04f
+				    domain,
a3a04f
+				    acct_name,
a3a04f
+				    &mapped_name);
a3a04f
+	if (NT_STATUS_IS_OK(status)) {
a3a04f
+		fill_domain_username(output_username,
a3a04f
+				     info->domain_name,
a3a04f
+				     mapped_name, true);
a3a04f
+		fstrcpy(acct_name, mapped_name);
a3a04f
+	} else if (NT_STATUS_EQUAL(status, NT_STATUS_FILE_RENAMED)) {
a3a04f
+		fstrcpy(acct_name, mapped_name);
a3a04f
+	} else {
a3a04f
+		fill_domain_username(output_username,
a3a04f
+				     info->domain_name,
a3a04f
+				     acct_name, true);
a3a04f
+	}
a3a04f
+
a3a04f
 	strlcpy(pw->pw_name, output_username, sizeof(pw->pw_name));
a3a04f
 
a3a04f
 	strlcpy(pw->pw_gecos, info->full_name ? info->full_name : "",
a3a04f
@@ -101,7 +129,7 @@ static void wb_getpwsid_queryuser_done(struct tevent_req *subreq)
a3a04f
 	TALLOC_FREE(tmp);
a3a04f
 
a3a04f
 	tmp = talloc_sub_specified(
a3a04f
-		state, info->shell, info->acct_name,
a3a04f
+		state, info->shell, acct_name,
a3a04f
 		info->primary_group_name, info->domain_name,
a3a04f
 		pw->pw_uid, pw->pw_gid);
a3a04f
 	if (tevent_req_nomem(tmp, req)) {
a3a04f
-- 
a3a04f
2.13.1
a3a04f