cf659d
From 091731ca7cc89c10f698a8d52e0ade1a07bde0d3 Mon Sep 17 00:00:00 2001
cf659d
From: Andreas Schneider <asn@samba.org>
cf659d
Date: Mon, 2 Jul 2018 16:18:52 +0200
cf659d
Subject: [PATCH 1/2] nsswitch: Add tests to lookup user via getpwnam
cf659d
cf659d
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13503
cf659d
cf659d
Signed-off-by: Andreas Schneider <asn@samba.org>
cf659d
Reviewed-by: Ralph Boehme <slow@samba.org>
cf659d
(cherry picked from commit 8e96e9ea46351de34ad5cac9a9a9ece4226b462c)
cf659d
---
cf659d
 nsswitch/tests/test_wbinfo_user_info.sh | 71 ++++++++++++++++++++++++++++-----
cf659d
 selftest/knownfail.d/upn_handling       |  2 +
cf659d
 source3/selftest/tests.py               |  4 +-
cf659d
 3 files changed, 66 insertions(+), 11 deletions(-)
cf659d
cf659d
diff --git a/nsswitch/tests/test_wbinfo_user_info.sh b/nsswitch/tests/test_wbinfo_user_info.sh
cf659d
index 2803ac1408b..da30f97be74 100755
cf659d
--- a/nsswitch/tests/test_wbinfo_user_info.sh
cf659d
+++ b/nsswitch/tests/test_wbinfo_user_info.sh
cf659d
@@ -2,19 +2,20 @@
cf659d
 # Blackbox test for wbinfo lookup for account name and upn
cf659d
 # Copyright (c) 2018 Andreas Schneider <asn@samba.org>
cf659d
 
cf659d
-if [ $# -lt 5 ]; then
cf659d
+if [ $# -lt 6 ]; then
cf659d
 cat <
cf659d
-Usage: $(basename $0) DOMAIN REALM USERNAME1 UPN_NAME1 USERNAME2 UPN_NAME2
cf659d
+Usage: $(basename $0) DOMAIN REALM OWN_DOMAIN USERNAME1 UPN_NAME1 USERNAME2 UPN_NAME2
cf659d
 EOF
cf659d
 exit 1;
cf659d
 fi
cf659d
 
cf659d
 DOMAIN=$1
cf659d
 REALM=$2
cf659d
-USERNAME1=$3
cf659d
-UPN_NAME1=$4
cf659d
-USERNAME2=$5
cf659d
-UPN_NAME2=$6
cf659d
+OWN_DOMAIN=$3
cf659d
+USERNAME1=$4
cf659d
+UPN_NAME1=$5
cf659d
+USERNAME2=$6
cf659d
+UPN_NAME2=$7
cf659d
 shift 6
cf659d
 
cf659d
 failed=0
cf659d
@@ -31,9 +32,9 @@ test_user_info()
cf659d
 {
cf659d
 	local cmd out ret user domain upn userinfo
cf659d
 
cf659d
-	domain="$1"
cf659d
-	user="$2"
cf659d
-	upn="$3"
cf659d
+	local domain="$1"
cf659d
+	local user="$2"
cf659d
+	local upn="$3"
cf659d
 
cf659d
 	if [ $# -lt 3 ]; then
cf659d
 		userinfo="$domain/$user"
cf659d
@@ -62,6 +63,39 @@ test_user_info()
cf659d
 	return 0
cf659d
 }
cf659d
 
cf659d
+test_getpwnam()
cf659d
+{
cf659d
+	local cmd out ret
cf659d
+
cf659d
+	local lookup_username=$1
cf659d
+	local expected_return=$2
cf659d
+	local expected_output=$3
cf659d
+
cf659d
+	cmd='getent passwd $lookup_username'
cf659d
+	eval echo "$cmd"
cf659d
+	out=$(eval $cmd)
cf659d
+	ret=$?
cf659d
+
cf659d
+	if [ $ret -ne $expected_return ]; then
cf659d
+		echo "return code: $ret, expected return code is: $expected_return"
cf659d
+		echo "$out"
cf659d
+		return 1
cf659d
+	fi
cf659d
+
cf659d
+	if [ -n "$expected_output" ]; then
cf659d
+		echo "$out" | grep "$expected_output"
cf659d
+		ret=$?
cf659d
+
cf659d
+		if [ $ret -ne 0 ]; then
cf659d
+			echo "Unable to find $expected_output in:"
cf659d
+			echo "$out"
cf659d
+			return 1
cf659d
+		fi
cf659d
+	fi
cf659d
+
cf659d
+	return 0
cf659d
+}
cf659d
+
cf659d
 testit "name_to_sid.domain.$USERNAME1" $wbinfo_tool --name-to-sid $DOMAIN/$USERNAME1 || failed=$(expr $failed + 1)
cf659d
 testit "name_to_sid.upn.$UPN_NAME1" $wbinfo_tool --name-to-sid $UPN1 || failed=$(expr $failed + 1)
cf659d
 
cf659d
@@ -80,4 +114,23 @@ UPN3="$UPN_NAME3@${REALM}.upn"
cf659d
 testit "name_to_sid.upn.$UPN_NAME3" $wbinfo_tool --name-to-sid $UPN3 || failed=$(expr $failed + 1)
cf659d
 testit "user_info.upn.$UPN_NAME3" test_user_info $DOMAIN $USERNAME3 $UPN3 || failed=$(expr $failed + 1)
cf659d
 
cf659d
+testit "getpwnam.domain.$DOMAIN.$USERNAME1" test_getpwnam "$DOMAIN/$USERNAME1" 0 "$DOMAIN/$USERNAME1" || failed=$(expr $failed + 1)
cf659d
+
cf659d
+testit "getpwnam.upn.$UPN_NAME1" test_getpwnam "$UPN1" 0 "$DOMAIN/$USERNAME1" || failed=$(expr $failed + 1)
cf659d
+
cf659d
+# We should not be able to lookup the user just by the name
cf659d
+test_ret=0
cf659d
+test_output="$DOMAIN/$USERNAME1"
cf659d
+
cf659d
+if [ "$ENVNAME" = "ad_member" ]; then
cf659d
+	test_ret=2
cf659d
+	test_output=""
cf659d
+fi
cf659d
+if [ "$ENVNAME" = "fl2008r2dc" ]; then
cf659d
+	test_ret=0
cf659d
+	test_output="$OWN_DOMAIN/$USERNAME1"
cf659d
+fi
cf659d
+
cf659d
+testit "getpwnam.local.$USERNAME1" test_getpwnam "$USERNAME1" $test_ret $test_output || failed=$(expr $failed + 1)
cf659d
+
cf659d
 exit $failed
cf659d
diff --git a/selftest/knownfail.d/upn_handling b/selftest/knownfail.d/upn_handling
cf659d
index bcbedb4f903..7dc9b71dc5e 100644
cf659d
--- a/selftest/knownfail.d/upn_handling
cf659d
+++ b/selftest/knownfail.d/upn_handling
cf659d
@@ -1,8 +1,10 @@
cf659d
 ^samba3\.wbinfo_user_info\.name_to_sid\.upn\.testdenied_upn.ad_member
cf659d
 ^samba3\.wbinfo_user_info\.user_info\.upn\.testdenied_upn.ad_member
cf659d
+^samba3\.wbinfo_user_info\.getpwnam\.local\.alice.ad_member
cf659d
 ^samba3\.wbinfo_user_info\.user_info\.domain\.alice.fl2008r2dc
cf659d
 ^samba3\.wbinfo_user_info\.user_info\.upn\.alice.fl2008r2dc
cf659d
 ^samba3\.wbinfo_user_info\.user_info\.domain\.jane.fl2008r2dc
cf659d
 ^samba3\.wbinfo_user_info\.user_info\.upn\.jane\.doe.fl2008r2dc
cf659d
 ^samba3\.wbinfo_user_info\.name_to_sid\.upn\.testdenied_upn.fl2008r2dc
cf659d
 ^samba3\.wbinfo_user_info\.user_info\.upn\.testdenied_upn.fl2008r2dc
cf659d
+^samba3\.wbinfo_user_info\.getpwnam\.local\.alice.fl2008r2dc
cf659d
diff --git a/source3/selftest/tests.py b/source3/selftest/tests.py
cf659d
index f43d2b14d3a..a9cb2dad792 100755
cf659d
--- a/source3/selftest/tests.py
cf659d
+++ b/source3/selftest/tests.py
cf659d
@@ -216,13 +216,13 @@ env = "ad_member:local"
cf659d
 plantestsuite("samba3.wbinfo_user_info", env,
cf659d
               [ os.path.join(srcdir(),
cf659d
                             "nsswitch/tests/test_wbinfo_user_info.sh"),
cf659d
-                '$DOMAIN', '$REALM', 'alice', 'alice', 'jane', 'jane.doe' ])
cf659d
+                '$DOMAIN', '$REALM', '$DOMAIN', 'alice', 'alice', 'jane', 'jane.doe' ])
cf659d
 
cf659d
 env = "fl2008r2dc:local"
cf659d
 plantestsuite("samba3.wbinfo_user_info", env,
cf659d
               [ os.path.join(srcdir(),
cf659d
                             "nsswitch/tests/test_wbinfo_user_info.sh"),
cf659d
-                '$TRUST_DOMAIN', '$TRUST_REALM', 'alice', 'alice', 'jane', 'jane.doe' ])
cf659d
+                '$TRUST_DOMAIN', '$TRUST_REALM', '$DOMAIN', 'alice', 'alice', 'jane', 'jane.doe' ])
cf659d
 
cf659d
 env = "ad_member"
cf659d
 t = "WBCLIENT-MULTI-PING"
cf659d
-- 
cf659d
2.13.6
cf659d
cf659d
cf659d
From 495f43f5fa972076de996f9c639657672e378c7d Mon Sep 17 00:00:00 2001
cf659d
From: Andreas Schneider <asn@samba.org>
cf659d
Date: Mon, 2 Jul 2018 16:38:01 +0200
cf659d
Subject: [PATCH 2/2] s3:winbind: Do not lookup local system accounts in AD
cf659d
MIME-Version: 1.0
cf659d
Content-Type: text/plain; charset=UTF-8
cf659d
Content-Transfer-Encoding: 8bit
cf659d
cf659d
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13503
cf659d
cf659d
Signed-off-by: Andreas Schneider <asn@samba.org>
cf659d
Reviewed-by: Ralph Boehme <slow@samba.org>
cf659d
cf659d
Autobuild-User(master): Ralph Böhme <slow@samba.org>
cf659d
Autobuild-Date(master): Wed Jul  4 23:55:56 CEST 2018 on sn-devel-144
cf659d
cf659d
(cherry picked from commit 9f28d30633af721efec02d8816a9fa48f795a01c)
cf659d
---
cf659d
 selftest/knownfail.d/upn_handling | 2 --
cf659d
 source3/winbindd/winbindd_util.c  | 2 ++
cf659d
 2 files changed, 2 insertions(+), 2 deletions(-)
cf659d
cf659d
diff --git a/selftest/knownfail.d/upn_handling b/selftest/knownfail.d/upn_handling
cf659d
index 7dc9b71dc5e..bcbedb4f903 100644
cf659d
--- a/selftest/knownfail.d/upn_handling
cf659d
+++ b/selftest/knownfail.d/upn_handling
cf659d
@@ -1,10 +1,8 @@
cf659d
 ^samba3\.wbinfo_user_info\.name_to_sid\.upn\.testdenied_upn.ad_member
cf659d
 ^samba3\.wbinfo_user_info\.user_info\.upn\.testdenied_upn.ad_member
cf659d
-^samba3\.wbinfo_user_info\.getpwnam\.local\.alice.ad_member
cf659d
 ^samba3\.wbinfo_user_info\.user_info\.domain\.alice.fl2008r2dc
cf659d
 ^samba3\.wbinfo_user_info\.user_info\.upn\.alice.fl2008r2dc
cf659d
 ^samba3\.wbinfo_user_info\.user_info\.domain\.jane.fl2008r2dc
cf659d
 ^samba3\.wbinfo_user_info\.user_info\.upn\.jane\.doe.fl2008r2dc
cf659d
 ^samba3\.wbinfo_user_info\.name_to_sid\.upn\.testdenied_upn.fl2008r2dc
cf659d
 ^samba3\.wbinfo_user_info\.user_info\.upn\.testdenied_upn.fl2008r2dc
cf659d
-^samba3\.wbinfo_user_info\.getpwnam\.local\.alice.fl2008r2dc
cf659d
diff --git a/source3/winbindd/winbindd_util.c b/source3/winbindd/winbindd_util.c
cf659d
index aa633419c9a..7a5fb73cdef 100644
cf659d
--- a/source3/winbindd/winbindd_util.c
cf659d
+++ b/source3/winbindd/winbindd_util.c
cf659d
@@ -1605,6 +1605,8 @@ bool parse_domain_user(const char *domuser,
cf659d
 		} else if (assume_domain(lp_workgroup())) {
cf659d
 			fstrcpy(domain, lp_workgroup());
cf659d
 			fstrcpy(namespace, domain);
cf659d
+		} else {
cf659d
+			fstrcpy(namespace, lp_netbios_name());
cf659d
 		}
cf659d
 	}
cf659d
 
cf659d
-- 
cf659d
2.13.6
cf659d