425db0
From 3b8312df417b1a1fbd712b9494d5dad495e33f6d Mon Sep 17 00:00:00 2001
425db0
From: Volker Lendecke <vl@samba.org>
425db0
Date: Wed, 8 Jul 2020 15:00:49 +0200
425db0
Subject: [PATCH 1/2] winbind: Add test for lookuprids cache problem
425db0
425db0
When reading entries from gencache, wb_cache_rids_to_names() can
425db0
return STATUS_SOME_UNMAPPED, which _wbint_LookupRids() does not handle
425db0
correctly.
425db0
425db0
This test enforces this situation by filling gencache with one wbinfo
425db0
-R and then erasing the winbindd_cache.tdb. This forces winbind to
425db0
enter the domain helper process, which will then read from gencache
425db0
filled with the previous wbinfo -R.
425db0
425db0
Without having the entries cached this does not happen because
425db0
wb_cache_rids_to_names() via the do_query: path calls deep inside
425db0
calls dcerpc_lsa_lookup_sids_noalloc(), which hides the
425db0
STATUS_SOME_UNMAPPED that came in as lsa_LookupSids result value.
425db0
425db0
Bug: https://bugzilla.samba.org/show_bug.cgi?id=14435
425db0
Signed-off-by: Volker Lendecke <vl@samba.org>
425db0
Reviewed-by: Ralph Boehme <slow@samba.org>
425db0
(cherry picked from commit 04eafce653afcff517317d2b190acc4f0cbf4c61)
425db0
---
425db0
 selftest/knownfail.d/lookuprids_cache         |  1 +
425db0
 .../tests/test_wbinfo_lookuprids_cache.sh     | 21 +++++++++++++++++++
425db0
 source3/selftest/tests.py                     |  5 +++++
425db0
 3 files changed, 27 insertions(+)
425db0
 create mode 100644 selftest/knownfail.d/lookuprids_cache
425db0
 create mode 100755 source3/script/tests/test_wbinfo_lookuprids_cache.sh
425db0
425db0
diff --git a/selftest/knownfail.d/lookuprids_cache b/selftest/knownfail.d/lookuprids_cache
425db0
new file mode 100644
425db0
index 00000000000..d3c40a62b45
425db0
--- /dev/null
425db0
+++ b/selftest/knownfail.d/lookuprids_cache
425db0
@@ -0,0 +1 @@
425db0
+^samba.wbinfo_lookuprids_cache.lookuprids2\(nt4_member:local\)
425db0
\ No newline at end of file
425db0
diff --git a/source3/script/tests/test_wbinfo_lookuprids_cache.sh b/source3/script/tests/test_wbinfo_lookuprids_cache.sh
425db0
new file mode 100755
425db0
index 00000000000..0b21ffcd7c9
425db0
--- /dev/null
425db0
+++ b/source3/script/tests/test_wbinfo_lookuprids_cache.sh
425db0
@@ -0,0 +1,21 @@
425db0
+#!/bin/sh
425db0
+
425db0
+WBINFO="$VALGRIND ${WBINFO:-$BINDIR/wbinfo}"
425db0
+TDBTOOL="${TDBTOOL:-$BINDIR/tdbtool}"
425db0
+TDBDUMP="${TDBDUMP:-$BINDIR/tdbdump}"
425db0
+NET="$VALGRIND ${NET:-$BINDIR/net}"
425db0
+
425db0
+cache="$LOCK_DIR"/winbindd_cache.tdb
425db0
+
425db0
+incdir=`dirname $0`/../../../testprogs/blackbox
425db0
+. $incdir/subunit.sh
425db0
+
425db0
+testit "flush" "$NET" "cache" "flush" || failed=`expr $failed + 1`
425db0
+testit "lookuprids1" "$WBINFO" "-R" "512,12345" || failed=`expr $failed + 1`
425db0
+
425db0
+key=$("$TDBDUMP" "$cache" | grep ^key.*NDR.*/16/ | cut -d\" -f2)
425db0
+
425db0
+testit "delete" "$TDBTOOL" "$cache" delete "$key"
425db0
+testit "lookuprids2" "$WBINFO" "-R" "512,12345" || failed=`expr $failed + 1`
425db0
+
425db0
+testok $0 $failed
425db0
diff --git a/source3/selftest/tests.py b/source3/selftest/tests.py
425db0
index dc44160e50d..b01a3c1aad1 100755
425db0
--- a/source3/selftest/tests.py
425db0
+++ b/source3/selftest/tests.py
425db0
@@ -332,6 +332,11 @@ env = "nt4_member:local"
425db0
 plantestsuite("samba3.wbinfo_sids_to_xids", env,
425db0
               [os.path.join(srcdir(),
425db0
                             "nsswitch/tests/test_wbinfo_sids_to_xids.sh")])
425db0
+plantestsuite(
425db0
+    "samba.wbinfo_lookuprids_cache",
425db0
+    env,
425db0
+    [os.path.join(samba3srcdir,
425db0
+                  "script/tests/test_wbinfo_lookuprids_cache.sh")])
425db0
 
425db0
 env = "ad_member"
425db0
 t = "WBCLIENT-MULTI-PING"
425db0
-- 
425db0
2.20.1
425db0
425db0
425db0
From 7389996f5e04acb79a760cb72b9d5c5a617262b8 Mon Sep 17 00:00:00 2001
425db0
From: Volker Lendecke <vl@samba.org>
425db0
Date: Wed, 8 Jul 2020 15:09:45 +0200
425db0
Subject: [PATCH 2/2] winbind: Fix lookuprids cache problem
425db0
425db0
Bug: https://bugzilla.samba.org/show_bug.cgi?id=14435
425db0
Signed-off-by: Volker Lendecke <vl@samba.org>
425db0
Reviewed-by: Ralph Boehme <slow@samba.org>
425db0
425db0
Autobuild-User(master): Volker Lendecke <vl@samba.org>
425db0
Autobuild-Date(master): Thu Jul  9 21:40:52 UTC 2020 on sn-devel-184
425db0
425db0
(cherry picked from commit cd4122d91e942ca465c03505d5e148117f505ba4)
425db0
---
425db0
 selftest/knownfail.d/lookuprids_cache | 1 -
425db0
 source3/winbindd/winbindd_dual_srv.c  | 3 ++-
425db0
 2 files changed, 2 insertions(+), 2 deletions(-)
425db0
 delete mode 100644 selftest/knownfail.d/lookuprids_cache
425db0
425db0
diff --git a/selftest/knownfail.d/lookuprids_cache b/selftest/knownfail.d/lookuprids_cache
425db0
deleted file mode 100644
425db0
index d3c40a62b45..00000000000
425db0
--- a/selftest/knownfail.d/lookuprids_cache
425db0
+++ /dev/null
425db0
@@ -1 +0,0 @@
425db0
-^samba.wbinfo_lookuprids_cache.lookuprids2\(nt4_member:local\)
425db0
\ No newline at end of file
425db0
diff --git a/source3/winbindd/winbindd_dual_srv.c b/source3/winbindd/winbindd_dual_srv.c
425db0
index 13345caa41b..63bb614a0ca 100644
425db0
--- a/source3/winbindd/winbindd_dual_srv.c
425db0
+++ b/source3/winbindd/winbindd_dual_srv.c
425db0
@@ -672,7 +672,8 @@ NTSTATUS _wbint_LookupRids(struct pipes_struct *p, struct wbint_LookupRids *r)
425db0
 					r->in.rids->rids, r->in.rids->num_rids,
425db0
 					&domain_name, &names, &types);
425db0
 	reset_cm_connection_on_error(domain, NULL, status);
425db0
-	if (!NT_STATUS_IS_OK(status)) {
425db0
+	if (!NT_STATUS_IS_OK(status) &&
425db0
+	    !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
425db0
 		return status;
425db0
 	}
425db0
 
425db0
-- 
425db0
2.20.1
425db0