8b3f01
From 438284e1025a96dfa2eb0928de99226f580f356f Mon Sep 17 00:00:00 2001
8b3f01
From: =?UTF-8?q?Pavel=20Filipensk=C3=BD?= <pfilipen@redhat.com>
8b3f01
Date: Fri, 1 Apr 2022 15:56:30 +0200
8b3f01
Subject: [PATCH 1/5] selftest: Create users "jackthemapper" and "jacknomapper"
8b3f01
MIME-Version: 1.0
8b3f01
Content-Type: text/plain; charset=UTF-8
8b3f01
Content-Transfer-Encoding: 8bit
8b3f01
8b3f01
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15041
8b3f01
8b3f01
Signed-off-by: Pavel Filipenský <pfilipen@redhat.com>
8b3f01
Reviewed-by: Noel Power <npower@samba.org>
8b3f01
Reviewed-by: Jeremy Allison <jra@samba.org>
8b3f01
(cherry picked from commit 1b0146182224fe01ed70815364656a626038685a)
8b3f01
---
8b3f01
 selftest/target/Samba3.pm | 12 +++++++++++-
8b3f01
 1 file changed, 11 insertions(+), 1 deletion(-)
8b3f01
8b3f01
diff --git a/selftest/target/Samba3.pm b/selftest/target/Samba3.pm
8b3f01
index 62fb3d1e39e..b0ea9804c50 100755
8b3f01
--- a/selftest/target/Samba3.pm
8b3f01
+++ b/selftest/target/Samba3.pm
8b3f01
@@ -1466,8 +1466,10 @@ sub setup_ad_member_idmap_nss
8b3f01
 	my $extra_member_options = "
8b3f01
 	# bob:x:65521:65531:localbob gecos:/:/bin/false
8b3f01
 	# jane:x:65520:65531:localjane gecos:/:/bin/false
8b3f01
+	# jackthemapper:x:65519:65531:localjackthemaper gecos:/:/bin/false
8b3f01
+	# jacknomapper:x:65518:65531:localjacknomaper gecos:/:/bin/false
8b3f01
 	idmap config $dcvars->{DOMAIN} : backend = nss
8b3f01
-	idmap config $dcvars->{DOMAIN} : range = 65520-65521
8b3f01
+	idmap config $dcvars->{DOMAIN} : range = 65518-65521
8b3f01
 
8b3f01
 	# Support SMB1 so that we can use posix_whoami().
8b3f01
 	client min protocol = CORE
8b3f01
@@ -2532,6 +2534,8 @@ sub provision($$)
8b3f01
 	my ($uid_slashuser);
8b3f01
 	my ($uid_localbob);
8b3f01
 	my ($uid_localjane);
8b3f01
+	my ($uid_localjackthemapper);
8b3f01
+	my ($uid_localjacknomapper);
8b3f01
 
8b3f01
 	if ($unix_uid < 0xffff - 13) {
8b3f01
 		$max_uid = 0xffff;
8b3f01
@@ -2554,6 +2558,8 @@ sub provision($$)
8b3f01
 	$uid_slashuser = $max_uid - 13;
8b3f01
 	$uid_localbob = $max_uid - 14;
8b3f01
 	$uid_localjane = $max_uid - 15;
8b3f01
+	$uid_localjackthemapper = $max_uid - 16;
8b3f01
+	$uid_localjacknomapper = $max_uid - 17;
8b3f01
 
8b3f01
 	if ($unix_gids[0] < 0xffff - 8) {
8b3f01
 		$max_gid = 0xffff;
8b3f01
@@ -3298,6 +3304,8 @@ eviluser:x:$uid_eviluser:$gid_domusers:eviluser gecos::/bin/false
8b3f01
 slashuser:x:$uid_slashuser:$gid_domusers:slashuser gecos:/:/bin/false
8b3f01
 bob:x:$uid_localbob:$gid_domusers:localbob gecos:/:/bin/false
8b3f01
 jane:x:$uid_localjane:$gid_domusers:localjane gecos:/:/bin/false
8b3f01
+jackthemapper:x:$uid_localjackthemapper:$gid_domusers:localjackthemaper gecos:/:/bin/false
8b3f01
+jacknomapper:x:$uid_localjacknomapper:$gid_domusers:localjacknomaper gecos:/:/bin/false
8b3f01
 ";
8b3f01
 	if ($unix_uid != 0) {
8b3f01
 		print PASSWD "root:x:$uid_root:$gid_root:root gecos:$prefix_abs:/bin/false
8b3f01
@@ -3362,6 +3370,8 @@ force_user:x:$gid_force_user:
8b3f01
 	createuser($self, "gooduser", $password, $conffile, \%createuser_env) || die("Unable to create gooduser");
8b3f01
 	createuser($self, "eviluser", $password, $conffile, \%createuser_env) || die("Unable to create eviluser");
8b3f01
 	createuser($self, "slashuser", $password, $conffile, \%createuser_env) || die("Unable to create slashuser");
8b3f01
+	createuser($self, "jackthemapper", "mApsEcrEt", $conffile, \%createuser_env) || die("Unable to create jackthemapper");
8b3f01
+	createuser($self, "jacknomapper", "nOmApsEcrEt", $conffile, \%createuser_env) || die("Unable to create jacknomapper");
8b3f01
 
8b3f01
 	open(DNS_UPDATE_LIST, ">$prefix/dns_update_list") or die("Unable to open $$prefix/dns_update_list");
8b3f01
 	print DNS_UPDATE_LIST "A $server. $server_ip\n";
8b3f01
-- 
8b3f01
2.34.1
8b3f01
8b3f01
8b3f01
From 28bf2f4c52105fc11515c58e13b935ae046399b4 Mon Sep 17 00:00:00 2001
8b3f01
From: =?UTF-8?q?Pavel=20Filipensk=C3=BD?= <pfilipen@redhat.com>
8b3f01
Date: Tue, 5 Apr 2022 08:30:23 +0200
8b3f01
Subject: [PATCH 2/5] selftest: Create groups "jackthemappergroup" and
8b3f01
 "jacknomappergroup"
8b3f01
MIME-Version: 1.0
8b3f01
Content-Type: text/plain; charset=UTF-8
8b3f01
Content-Transfer-Encoding: 8bit
8b3f01
8b3f01
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15041
8b3f01
8b3f01
Signed-off-by: Pavel Filipenský <pfilipen@redhat.com>
8b3f01
Reviewed-by: Jeremy Allison <jra@samba.org>
8b3f01
Reviewed-by: Noel Power <npower@samba.org>
8b3f01
(cherry picked from commit 26e4268d6e3bde74520e36f3ca3cc9d979292d1d)
8b3f01
---
8b3f01
 selftest/target/Samba3.pm | 6 ++++++
8b3f01
 1 file changed, 6 insertions(+)
8b3f01
8b3f01
diff --git a/selftest/target/Samba3.pm b/selftest/target/Samba3.pm
8b3f01
index b0ea9804c50..131034a0e07 100755
8b3f01
--- a/selftest/target/Samba3.pm
8b3f01
+++ b/selftest/target/Samba3.pm
8b3f01
@@ -2527,6 +2527,8 @@ sub provision($$)
8b3f01
 	my ($gid_nobody, $gid_nogroup, $gid_root, $gid_domusers, $gid_domadmins);
8b3f01
 	my ($gid_userdup, $gid_everyone);
8b3f01
 	my ($gid_force_user);
8b3f01
+	my ($gid_jackthemapper);
8b3f01
+	my ($gid_jacknomapper);
8b3f01
 	my ($uid_user1);
8b3f01
 	my ($uid_user2);
8b3f01
 	my ($uid_gooduser);
8b3f01
@@ -2575,6 +2577,8 @@ sub provision($$)
8b3f01
 	$gid_userdup = $max_gid - 6;
8b3f01
 	$gid_everyone = $max_gid - 7;
8b3f01
 	$gid_force_user = $max_gid - 8;
8b3f01
+	$gid_jackthemapper = $max_gid - 9;
8b3f01
+	$gid_jacknomapper = $max_gid - 10;
8b3f01
 
8b3f01
 	##
8b3f01
 	## create conffile
8b3f01
@@ -3325,6 +3329,8 @@ domadmins:X:$gid_domadmins:
8b3f01
 userdup:x:$gid_userdup:$unix_name
8b3f01
 everyone:x:$gid_everyone:
8b3f01
 force_user:x:$gid_force_user:
8b3f01
+jackthemappergroup:x:$gid_jackthemapper:jackthemapper
8b3f01
+jacknomappergroup:x:$gid_jacknomapper:jacknomapper
8b3f01
 ";
8b3f01
 	if ($unix_gids[0] != 0) {
8b3f01
 		print GROUP "root:x:$gid_root:
8b3f01
-- 
8b3f01
2.34.1
8b3f01
8b3f01
8b3f01
From deadcd6a919188a75157e54b2fd772e4bf18d4fc Mon Sep 17 00:00:00 2001
8b3f01
From: =?UTF-8?q?Pavel=20Filipensk=C3=BD?= <pfilipen@redhat.com>
8b3f01
Date: Tue, 5 Apr 2022 08:31:41 +0200
8b3f01
Subject: [PATCH 3/5] selftest: Add to "username.map" mapping for
8b3f01
 jackthemappergroup
8b3f01
MIME-Version: 1.0
8b3f01
Content-Type: text/plain; charset=UTF-8
8b3f01
Content-Transfer-Encoding: 8bit
8b3f01
8b3f01
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15041
8b3f01
8b3f01
Only for environment ad_member_idmap_nss.
8b3f01
8b3f01
* !jacknompapper = \@jackthemappergroup
8b3f01
  jackthemaper from group jackthemappergroup is mapped to jacknompapper
8b3f01
8b3f01
* !root = jacknomappergroup
8b3f01
  since there is no '@' or '+' prefix, it is not an UNIX group mapping
8b3f01
8b3f01
Signed-off-by: Pavel Filipenský <pfilipen@redhat.com>
8b3f01
Reviewed-by: Jeremy Allison <jra@samba.org>
8b3f01
Reviewed-by: Noel Power <npower@samba.org>
8b3f01
(cherry picked from commit 0feeb6d58a6d6b1949faa842473053af4562c979)
8b3f01
---
8b3f01
 selftest/target/Samba3.pm | 2 ++
8b3f01
 1 file changed, 2 insertions(+)
8b3f01
8b3f01
diff --git a/selftest/target/Samba3.pm b/selftest/target/Samba3.pm
8b3f01
index 131034a0e07..8d309f9c99a 100755
8b3f01
--- a/selftest/target/Samba3.pm
8b3f01
+++ b/selftest/target/Samba3.pm
8b3f01
@@ -1490,6 +1490,8 @@ sub setup_ad_member_idmap_nss
8b3f01
 
8b3f01
 	open(USERMAP, ">$prefix/lib/username.map") or die("Unable to open $prefix/lib/username.map");
8b3f01
 	print USERMAP "
8b3f01
+!jacknomapper = \@jackthemappergroup
8b3f01
+!root = jacknomappergroup
8b3f01
 root = $dcvars->{DOMAIN}/root
8b3f01
 bob = $dcvars->{DOMAIN}/bob
8b3f01
 ";
8b3f01
-- 
8b3f01
2.34.1
8b3f01
8b3f01
8b3f01
From edf5d5641de92665c30804be6825040d7b0862af Mon Sep 17 00:00:00 2001
8b3f01
From: =?UTF-8?q?Pavel=20Filipensk=C3=BD?= <pfilipen@redhat.com>
8b3f01
Date: Tue, 5 Apr 2022 14:04:52 +0200
8b3f01
Subject: [PATCH 4/5] s3:tests Test "username map" for UNIX groups
8b3f01
MIME-Version: 1.0
8b3f01
Content-Type: text/plain; charset=UTF-8
8b3f01
Content-Transfer-Encoding: 8bit
8b3f01
8b3f01
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15041
8b3f01
8b3f01
Signed-off-by: Pavel Filipenský <pfilipen@redhat.com>
8b3f01
Reviewed-by: Jeremy Allison <jra@samba.org>
8b3f01
Reviewed-by: Noel Power <npower@samba.org>
8b3f01
(cherry picked from commit af8747a28bd62937a01fa4648f404bd0b09a44c0)
8b3f01
---
8b3f01
 selftest/knownfail.d/usernamemap         |  1 +
8b3f01
 source3/script/tests/test_usernamemap.sh | 28 ++++++++++++++++++++++++
8b3f01
 source3/selftest/tests.py                |  2 ++
8b3f01
 3 files changed, 31 insertions(+)
8b3f01
 create mode 100644 selftest/knownfail.d/usernamemap
8b3f01
 create mode 100755 source3/script/tests/test_usernamemap.sh
8b3f01
8b3f01
diff --git a/selftest/knownfail.d/usernamemap b/selftest/knownfail.d/usernamemap
8b3f01
new file mode 100644
8b3f01
index 00000000000..1c720fe892d
8b3f01
--- /dev/null
8b3f01
+++ b/selftest/knownfail.d/usernamemap
8b3f01
@@ -0,0 +1 @@
8b3f01
+samba3.blackbox.smbclient_usernamemap.jacknomapper
8b3f01
diff --git a/source3/script/tests/test_usernamemap.sh b/source3/script/tests/test_usernamemap.sh
8b3f01
new file mode 100755
8b3f01
index 00000000000..3a3344a8781
8b3f01
--- /dev/null
8b3f01
+++ b/source3/script/tests/test_usernamemap.sh
8b3f01
@@ -0,0 +1,28 @@
8b3f01
+#!/bin/sh
8b3f01
+#
8b3f01
+# Copyright (c) 2022 Pavel Filipenský <pfilipen@redhat.com>
8b3f01
+#
8b3f01
+# Tests for "username map" smb.conf parameter for UNIX groups
8b3f01
+
8b3f01
+if [ $# -lt 2 ]; then
8b3f01
+cat <
8b3f01
+Usage: test_usernamemap.sh SERVER SMBCLIENT
8b3f01
+EOF
8b3f01
+exit 1;
8b3f01
+fi
8b3f01
+
8b3f01
+SERVER="$1"
8b3f01
+SMBCLIENT="$2"
8b3f01
+SMBCLIENT="${VALGRIND} ${SMBCLIENT}"
8b3f01
+
8b3f01
+incdir=$(dirname "$0")/../../../testprogs/blackbox
8b3f01
+. "${incdir}"/subunit.sh
8b3f01
+
8b3f01
+failed=0
8b3f01
+
8b3f01
+# jackthemapper is mapped to jacknomapper, so we need jacknomapper password
8b3f01
+testit "jackthemapper" "${SMBCLIENT}" //"${SERVER}"/tmp -U"${SERVER}/jackthemapper%nOmApsEcrEt" -c ls || failed=$((failed + 1))
8b3f01
+# jacknomapper is not mapped, so we need jacknomapper password
8b3f01
+testit "jacknomapper"  "${SMBCLIENT}" //"${SERVER}"/tmp -U"${SERVER}/jacknomapper%nOmApsEcrEt"  -c ls || failed=$((failed + 1))
8b3f01
+
8b3f01
+testok "$0" "${failed}"
8b3f01
diff --git a/source3/selftest/tests.py b/source3/selftest/tests.py
8b3f01
index 06c71363d5b..390e77ad41d 100755
8b3f01
--- a/source3/selftest/tests.py
8b3f01
+++ b/source3/selftest/tests.py
8b3f01
@@ -393,6 +393,8 @@ plantestsuite("samba3.blackbox.smbclient_basic.SMB2_10", "nt4_dc_schannel", [os.
8b3f01
 plantestsuite("samba3.blackbox.smbclient_basic.SMB3_02", "nt4_dc_schannel", [os.path.join(samba3srcdir, "script/tests/test_smbclient_basic.sh"), '$SERVER', '$SERVER_IP', '$DC_USERNAME', '$DC_PASSWORD', smbclient3, configuration, "-mSMB3_02"])
8b3f01
 plantestsuite("samba3.blackbox.smbclient_basic.SMB3_11", "nt4_dc_schannel", [os.path.join(samba3srcdir, "script/tests/test_smbclient_basic.sh"), '$SERVER', '$SERVER_IP', '$DC_USERNAME', '$DC_PASSWORD', smbclient3, configuration, "-mSMB3_11"])
8b3f01
 
8b3f01
+plantestsuite("samba3.blackbox.smbclient_usernamemap", "ad_member_idmap_nss:local", [os.path.join(samba3srcdir, "script/tests/test_usernamemap.sh"), '$SERVER', smbclient3])
8b3f01
+
8b3f01
 plantestsuite("samba3.blackbox.smbclient_basic", "ad_member", [os.path.join(samba3srcdir, "script/tests/test_smbclient_basic.sh"), '$SERVER', '$SERVER_IP', '$DC_USERNAME', '$DC_PASSWORD', smbclient3, configuration])
8b3f01
 for options in ["", "--option=clientntlmv2auth=no", "--option=clientusespnego=no", "--option=clientusespnego=no --option=clientntlmv2auth=no", "--option=clientntlmv2auth=no --option=clientlanmanauth=yes --max-protocol=LANMAN2", "--option=clientntlmv2auth=no --option=clientlanmanauth=yes --option=clientmaxprotocol=NT1"]:
8b3f01
     if "NT1" in options or "LANMAN2" in options:
8b3f01
-- 
8b3f01
2.34.1
8b3f01
8b3f01
8b3f01
From e1bb74a5fe7f0b4f5f16da5c355973e94f7a07ef Mon Sep 17 00:00:00 2001
8b3f01
From: =?UTF-8?q?Pavel=20Filipensk=C3=BD?= <pfilipen@redhat.com>
8b3f01
Date: Fri, 25 Mar 2022 11:11:50 +0100
8b3f01
Subject: [PATCH 5/5] s3:auth: Fix user_in_list() for UNIX groups
8b3f01
MIME-Version: 1.0
8b3f01
Content-Type: text/plain; charset=UTF-8
8b3f01
Content-Transfer-Encoding: 8bit
8b3f01
8b3f01
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15041
8b3f01
8b3f01
Signed-off-by: Pavel Filipenský <pfilipen@redhat.com>
8b3f01
Reviewed-by: Jeremy Allison <jra@samba.org>
8b3f01
Reviewed-by: Noel Power <npower@samba.org>
8b3f01
8b3f01
Autobuild-User(master): Noel Power <npower@samba.org>
8b3f01
Autobuild-Date(master): Thu Apr  7 09:49:44 UTC 2022 on sn-devel-184
8b3f01
8b3f01
(cherry picked from commit 6dc463d3e2eb229df1c4f620cfcaf22ac71738d4)
8b3f01
---
8b3f01
 selftest/knownfail.d/usernamemap |  1 -
8b3f01
 source3/auth/user_util.c         | 12 +++++++-----
8b3f01
 2 files changed, 7 insertions(+), 6 deletions(-)
8b3f01
 delete mode 100644 selftest/knownfail.d/usernamemap
8b3f01
8b3f01
diff --git a/selftest/knownfail.d/usernamemap b/selftest/knownfail.d/usernamemap
8b3f01
deleted file mode 100644
8b3f01
index 1c720fe892d..00000000000
8b3f01
--- a/selftest/knownfail.d/usernamemap
8b3f01
+++ /dev/null
8b3f01
@@ -1 +0,0 @@
8b3f01
-samba3.blackbox.smbclient_usernamemap.jacknomapper
8b3f01
diff --git a/source3/auth/user_util.c b/source3/auth/user_util.c
8b3f01
index 70b4f320c5e..aa765c2a692 100644
8b3f01
--- a/source3/auth/user_util.c
8b3f01
+++ b/source3/auth/user_util.c
8b3f01
@@ -143,11 +143,11 @@ bool user_in_list(TALLOC_CTX *ctx, const char *user, const char * const *list)
8b3f01
 		return false;
8b3f01
 	}
8b3f01
 
8b3f01
-	DBG_DEBUG("Checking user %s in list\n", user);
8b3f01
-
8b3f01
 	while (*list) {
8b3f01
 		const char *p = *list;
8b3f01
-		bool ok;
8b3f01
+		bool check_unix_group = false;
8b3f01
+
8b3f01
+		DBG_DEBUG("Checking user '%s' in list '%s'.\n", user, *list);
8b3f01
 
8b3f01
 		/* Check raw username */
8b3f01
 		if (strequal(user, p)) {
8b3f01
@@ -155,11 +155,13 @@ bool user_in_list(TALLOC_CTX *ctx, const char *user, const char * const *list)
8b3f01
 		}
8b3f01
 
8b3f01
 		while (*p == '@' || *p == '&' || *p == '+') {
8b3f01
+			if (*p == '@' || *p == '+') {
8b3f01
+				check_unix_group = true;
8b3f01
+			}
8b3f01
 			p++;
8b3f01
 		}
8b3f01
 
8b3f01
-		ok = user_in_group(user, p);
8b3f01
-		if (ok) {
8b3f01
+		if (check_unix_group && user_in_group(user, p)) {
8b3f01
 			return true;
8b3f01
 		}
8b3f01
 
8b3f01
-- 
8b3f01
2.34.1
8b3f01