330097
From 25465d0bc77dd712b3d94e488f2cf0583fd7ac04 Mon Sep 17 00:00:00 2001
330097
From: Andreas Schneider <asn@cryptomilk.org>
330097
Date: Tue, 26 Apr 2022 07:10:56 +0200
330097
Subject: [PATCH 1/5] s3:passdb: Remove trailing spaces in lookup_sid.c
330097
330097
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15054
330097
330097
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
330097
Reviewed-by: Jeremy Allison <jra@samba.org>
330097
(cherry picked from commit 756cd0eed30322ae6dbd5402ec11441387475884)
330097
---
330097
 source3/passdb/lookup_sid.c | 18 +++++++++---------
330097
 1 file changed, 9 insertions(+), 9 deletions(-)
330097
330097
diff --git a/source3/passdb/lookup_sid.c b/source3/passdb/lookup_sid.c
330097
index a551bcfd24a..3a28cdc68a6 100644
330097
--- a/source3/passdb/lookup_sid.c
330097
+++ b/source3/passdb/lookup_sid.c
330097
@@ -1,4 +1,4 @@
330097
-/* 
330097
+/*
330097
    Unix SMB/CIFS implementation.
330097
    uid/user handling
330097
    Copyright (C) Andrew Tridgell         1992-1998
330097
@@ -72,7 +72,7 @@ static bool lookup_unix_group_name(const char *name, struct dom_sid *sid)
330097
  If an explicit domain name was given in the form domain\user, it
330097
  has to try that. If no explicit domain name was given, we have
330097
  to do guesswork.
330097
-*****************************************************************/  
330097
+*****************************************************************/
330097
 
330097
 bool lookup_name(TALLOC_CTX *mem_ctx,
330097
 		 const char *full_name, int flags,
330097
@@ -300,7 +300,7 @@ bool lookup_name(TALLOC_CTX *mem_ctx,
330097
 		goto ok;
330097
 	}
330097
 
330097
-	/* 6. Builtin aliases */	
330097
+	/* 6. Builtin aliases */
330097
 
330097
 	if ((flags & LOOKUP_NAME_BUILTIN) &&
330097
 	    lookup_builtin_name(name, &rid))
330097
@@ -882,7 +882,7 @@ NTSTATUS lookup_sids(TALLOC_CTX *mem_ctx, int num_sids,
330097
 	}
330097
 
330097
 	/* First build up the data structures:
330097
-	 * 
330097
+	 *
330097
 	 * dom_infos is a list of domains referenced in the list of
330097
 	 * SIDs. Later we will walk the list of domains and look up the RIDs
330097
 	 * in bulk.
330097
@@ -1070,7 +1070,7 @@ NTSTATUS lookup_sids(TALLOC_CTX *mem_ctx, int num_sids,
330097
 
330097
 /*****************************************************************
330097
  *THE CANONICAL* convert SID to name function.
330097
-*****************************************************************/  
330097
+*****************************************************************/
330097
 
330097
 bool lookup_sid(TALLOC_CTX *mem_ctx, const struct dom_sid *sid,
330097
 		const char **ret_domain, const char **ret_name,
330097
@@ -1104,7 +1104,7 @@ bool lookup_sid(TALLOC_CTX *mem_ctx, const struct dom_sid *sid,
330097
 		goto done;
330097
 	}
330097
 
330097
-	if ((ret_name != NULL) && 
330097
+	if ((ret_name != NULL) &&
330097
 	    !(*ret_name = talloc_strdup(mem_ctx, name->name))) {
330097
 		goto done;
330097
 	}
330097
@@ -1130,7 +1130,7 @@ bool lookup_sid(TALLOC_CTX *mem_ctx, const struct dom_sid *sid,
330097
 
330097
 /*****************************************************************
330097
  *THE LEGACY* convert SID to id function.
330097
-*****************************************************************/  
330097
+*****************************************************************/
330097
 
330097
 static bool legacy_sid_to_unixid(const struct dom_sid *psid, struct unixid *id)
330097
 {
330097
@@ -1465,7 +1465,7 @@ fail:
330097
 
330097
 /*****************************************************************
330097
  *THE CANONICAL* convert SID to uid function.
330097
-*****************************************************************/  
330097
+*****************************************************************/
330097
 
330097
 bool sid_to_uid(const struct dom_sid *psid, uid_t *puid)
330097
 {
330097
@@ -1527,7 +1527,7 @@ bool sid_to_uid(const struct dom_sid *psid, uid_t *puid)
330097
 /*****************************************************************
330097
  *THE CANONICAL* convert SID to gid function.
330097
  Group mapping is used for gids that maps to Wellknown SIDs
330097
-*****************************************************************/  
330097
+*****************************************************************/
330097
 
330097
 bool sid_to_gid(const struct dom_sid *psid, gid_t *pgid)
330097
 {
330097
-- 
330097
2.36.0
330097
330097
330097
From e884efce61290ad6f4125ab4e3adb08bcc1a800d Mon Sep 17 00:00:00 2001
330097
From: Andreas Schneider <asn@cryptomilk.org>
330097
Date: Tue, 26 Apr 2022 07:12:02 +0200
330097
Subject: [PATCH 2/5] s3:passdb: Add support to handle UPNs in lookup_name()
330097
330097
This address an issue if sssd is running and handling nsswitch. If we look up
330097
a user with getpwnam("DOMAIN\user") it will return user@REALM in the passwd
330097
structure. We need to be able to deal with that.
330097
330097
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15054
330097
330097
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
330097
Reviewed-by: Jeremy Allison <jra@samba.org>
330097
(cherry picked from commit 2a03fb91c1120718ada9d4b8421044cb7eae7b83)
330097
---
330097
 source3/passdb/lookup_sid.c | 14 ++++++++++++--
330097
 1 file changed, 12 insertions(+), 2 deletions(-)
330097
330097
diff --git a/source3/passdb/lookup_sid.c b/source3/passdb/lookup_sid.c
330097
index 3a28cdc68a6..c14d7a7b123 100644
330097
--- a/source3/passdb/lookup_sid.c
330097
+++ b/source3/passdb/lookup_sid.c
330097
@@ -100,8 +100,18 @@ bool lookup_name(TALLOC_CTX *mem_ctx,
330097
 					PTR_DIFF(p, full_name));
330097
 		name = talloc_strdup(tmp_ctx, p+1);
330097
 	} else {
330097
-		domain = talloc_strdup(tmp_ctx, "");
330097
-		name = talloc_strdup(tmp_ctx, full_name);
330097
+		char *q = strchr_m(full_name, '@');
330097
+
330097
+		/* Set the domain for UPNs */
330097
+		if (q != NULL) {
330097
+			name = talloc_strndup(tmp_ctx,
330097
+					      full_name,
330097
+					      PTR_DIFF(q, full_name));
330097
+			domain = talloc_strdup(tmp_ctx, q + 1);
330097
+		} else {
330097
+			domain = talloc_strdup(tmp_ctx, "");
330097
+			name = talloc_strdup(tmp_ctx, full_name);
330097
+		}
330097
 	}
330097
 
330097
 	if ((domain == NULL) || (name == NULL)) {
330097
-- 
330097
2.36.0
330097
330097
330097
From cc548efd5fa1783e8412e7ac695c8d6be3323d67 Mon Sep 17 00:00:00 2001
330097
From: Andreas Schneider <asn@cryptomilk.org>
330097
Date: Tue, 26 Apr 2022 12:26:25 +0200
330097
Subject: [PATCH 3/5] s3:passdb: Use already defined pointer in
330097
 lookup_name_smbconf()
330097
330097
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
330097
Reviewed-by: Jeremy Allison <jra@samba.org>
330097
(cherry picked from commit ed8e466854d6d8d6120388716a7b604df7a4db27)
330097
---
330097
 source3/passdb/lookup_sid.c | 12 +++++-------
330097
 1 file changed, 5 insertions(+), 7 deletions(-)
330097
330097
diff --git a/source3/passdb/lookup_sid.c b/source3/passdb/lookup_sid.c
330097
index c14d7a7b123..dbea5578f92 100644
330097
--- a/source3/passdb/lookup_sid.c
330097
+++ b/source3/passdb/lookup_sid.c
330097
@@ -464,7 +464,7 @@ bool lookup_name_smbconf(TALLOC_CTX *mem_ctx,
330097
 		 const char **ret_domain, const char **ret_name,
330097
 		 struct dom_sid *ret_sid, enum lsa_SidType *ret_type)
330097
 {
330097
-	char *qualified_name;
330097
+	char *qualified_name = NULL;
330097
 	const char *p;
330097
 
330097
 	if ((p = strchr_m(full_name, *lp_winbind_separator())) != NULL) {
330097
@@ -472,16 +472,14 @@ bool lookup_name_smbconf(TALLOC_CTX *mem_ctx,
330097
 		/* The name is already qualified with a domain. */
330097
 
330097
 		if (*lp_winbind_separator() != '\\') {
330097
-			char *tmp;
330097
-
330097
 			/* lookup_name() needs '\\' as a separator */
330097
 
330097
-			tmp = talloc_strdup(mem_ctx, full_name);
330097
-			if (!tmp) {
330097
+			qualified_name = talloc_strdup(mem_ctx, full_name);
330097
+			if (qualified_name == NULL) {
330097
 				return false;
330097
 			}
330097
-			tmp[p - full_name] = '\\';
330097
-			full_name = tmp;
330097
+			qualified_name[p - full_name] = '\\';
330097
+			full_name = qualified_name;
330097
 		}
330097
 
330097
 		return lookup_name(mem_ctx, full_name, flags,
330097
-- 
330097
2.36.0
330097
330097
330097
From 3ee3336f4a3fbb80ccabe6c1494a68286af55437 Mon Sep 17 00:00:00 2001
330097
From: Andreas Schneider <asn@cryptomilk.org>
330097
Date: Tue, 26 Apr 2022 07:24:10 +0200
330097
Subject: [PATCH 4/5] s3:passdb: Refactor lookup_name_smbconf()
330097
330097
This will be changed to support UPNs too in the next patch.
330097
330097
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15054
330097
330097
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
330097
Reviewed-by: Jeremy Allison <jra@samba.org>
330097
(cherry picked from commit 2690310743920dfe20ac235c1e3617e0f421eddc)
330097
---
330097
 source3/passdb/lookup_sid.c | 7 ++++---
330097
 1 file changed, 4 insertions(+), 3 deletions(-)
330097
330097
diff --git a/source3/passdb/lookup_sid.c b/source3/passdb/lookup_sid.c
330097
index dbea5578f92..de9dd123239 100644
330097
--- a/source3/passdb/lookup_sid.c
330097
+++ b/source3/passdb/lookup_sid.c
330097
@@ -465,13 +465,14 @@ bool lookup_name_smbconf(TALLOC_CTX *mem_ctx,
330097
 		 struct dom_sid *ret_sid, enum lsa_SidType *ret_type)
330097
 {
330097
 	char *qualified_name = NULL;
330097
-	const char *p;
330097
+	const char *p = strchr_m(full_name, *lp_winbind_separator());
330097
+	bool is_qualified = p != NULL;
330097
 
330097
-	if ((p = strchr_m(full_name, *lp_winbind_separator())) != NULL) {
330097
+	if (is_qualified) {
330097
 
330097
 		/* The name is already qualified with a domain. */
330097
 
330097
-		if (*lp_winbind_separator() != '\\') {
330097
+		if (p != NULL && *lp_winbind_separator() != '\\') {
330097
 			/* lookup_name() needs '\\' as a separator */
330097
 
330097
 			qualified_name = talloc_strdup(mem_ctx, full_name);
330097
-- 
330097
2.36.0
330097
330097
330097
From 1baa5b170c36854eaa0a5f2c9aba29d50194f750 Mon Sep 17 00:00:00 2001
330097
From: Andreas Schneider <asn@cryptomilk.org>
330097
Date: Tue, 26 Apr 2022 07:39:12 +0200
330097
Subject: [PATCH 5/5] s3:passdb: Also allow to handle UPNs in
330097
 lookup_name_smbconf()
330097
330097
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15054
330097
330097
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
330097
Reviewed-by: Jeremy Allison <jra@samba.org>
330097
(cherry picked from commit 28fc44f2852046d03cada161ed1001d04d9e1554)
330097
---
330097
 source3/passdb/lookup_sid.c | 3 ++-
330097
 1 file changed, 2 insertions(+), 1 deletion(-)
330097
330097
diff --git a/source3/passdb/lookup_sid.c b/source3/passdb/lookup_sid.c
330097
index de9dd123239..426ea3f81bd 100644
330097
--- a/source3/passdb/lookup_sid.c
330097
+++ b/source3/passdb/lookup_sid.c
330097
@@ -466,8 +466,9 @@ bool lookup_name_smbconf(TALLOC_CTX *mem_ctx,
330097
 {
330097
 	char *qualified_name = NULL;
330097
 	const char *p = strchr_m(full_name, *lp_winbind_separator());
330097
-	bool is_qualified = p != NULL;
330097
+	bool is_qualified = p != NULL || strchr_m(full_name, '@') != NULL;
330097
 
330097
+	/* For DOMAIN\user or user@REALM directly call lookup_name(). */
330097
 	if (is_qualified) {
330097
 
330097
 		/* The name is already qualified with a domain. */
330097
-- 
330097
2.36.0
330097