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