torture: Add tests for idmap cache
authorVolker Lendecke <vl@samba.org>
Wed, 27 Feb 2019 13:54:12 +0000 (14:54 +0100)
committerKarolin Seeger <kseeger@samba.org>
Wed, 13 Mar 2019 08:34:15 +0000 (08:34 +0000)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Christof Schmitt <cs@samba.org>
Bug: https://bugzilla.samba.org/show_bug.cgi?id=13813
(cherry picked from commit e5a903bab6eda8f7ff2a7c8149d51022d9d8aede)

source3/selftest/tests.py
source3/torture/proto.h
source3/torture/test_idmap_cache.c [new file with mode: 0644]
source3/torture/torture.c
source3/wscript_build

index 5d7e4969e5945f395526410626be5de4340f1a16..e8d516573ddd73f378820d4efbe826469ea9e38c 100755 (executable)
@@ -200,6 +200,7 @@ local_tests = [
     "LOCAL-G-LOCK5",
     "LOCAL-G-LOCK6",
     "LOCAL-NAMEMAP-CACHE1",
+    "LOCAL-IDMAP-CACHE1",
     "LOCAL-hex_encode_buf",
     "LOCAL-remove_duplicate_addrs2"]
 
index 669e077051e57a662ea601f89b7c638c535d484c..b4a2007fa773edc17fec3ff97d40278e68651e23 100644 (file)
@@ -137,6 +137,7 @@ bool run_g_lock5(int dummy);
 bool run_g_lock6(int dummy);
 bool run_g_lock_ping_pong(int dummy);
 bool run_local_namemap_cache1(int dummy);
+bool run_local_idmap_cache1(int dummy);
 bool run_hidenewfiles(int dummy);
 
 #endif /* __TORTURE_H__ */
diff --git a/source3/torture/test_idmap_cache.c b/source3/torture/test_idmap_cache.c
new file mode 100644 (file)
index 0000000..b9cba3b
--- /dev/null
@@ -0,0 +1,122 @@
+/*
+ * Unix SMB/CIFS implementation.
+ * Test dbwrap_watch API
+ * Copyright (C) Volker Lendecke 2017
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "includes.h"
+#include "torture/proto.h"
+#include "lib/idmap_cache.h"
+#include "librpc/gen_ndr/idmap.h"
+#include "libcli/security/dom_sid.h"
+
+bool run_local_idmap_cache1(int dummy)
+{
+       struct dom_sid sid, found_sid;
+       struct unixid xid, found_xid;
+       bool ret = false;
+       bool expired = false;
+
+       xid = (struct unixid) { .id = 1234, .type = ID_TYPE_UID };
+       dom_sid_parse("S-1-5-21-2864185242-3846410404-2398417794-1235", &sid);
+       idmap_cache_set_sid2unixid(&sid, &xid);
+
+       ret = idmap_cache_find_sid2unixid(&sid, &found_xid, &expired);
+       if (!ret) {
+               fprintf(stderr, "idmap_cache_find_sid2unixid failed\n");
+               goto done;
+       }
+       if (expired) {
+               fprintf(stderr,
+                       "idmap_cache_find_sid2unixid returned an expired "
+                       "value\n");
+               goto done;
+       }
+       if ((xid.type != found_xid.type) || (xid.id != found_xid.id)) {
+               fprintf(stderr,
+                       "idmap_cache_find_sid2unixid returned wrong "
+                       "values\n");
+               goto done;
+       }
+
+       ret = idmap_cache_find_xid2sid(&xid, &found_sid, &expired);
+       if (!ret) {
+               fprintf(stderr, "idmap_cache_find_xid2sid failed\n");
+               goto done;
+       }
+       if (expired) {
+               fprintf(stderr,
+                       "idmap_cache_find_xid2sid returned an expired "
+                       "value\n");
+               goto done;
+       }
+       if (!dom_sid_equal(&sid, &found_sid)) {
+               fprintf(stderr,
+                       "idmap_cache_find_xid2sid returned wrong sid\n");
+               goto done;
+       }
+
+       xid.type = ID_TYPE_GID;
+
+       ret = idmap_cache_find_xid2sid(&xid, &found_sid, &expired);
+       if (ret) {
+               fprintf(stderr,
+                       "idmap_cache_find_xid2sid found a GID where it "
+                       "should not\n");
+               goto done;
+       }
+
+       idmap_cache_del_sid(&sid);
+
+       xid.type = ID_TYPE_UID;
+       ret = idmap_cache_find_xid2sid(&xid, &found_sid, &expired);
+       if (ret) {
+               fprintf(stderr,
+                       "idmap_cache_find_xid2sid found a UID where it "
+                       "should not\n");
+               goto done;
+       }
+
+       /*
+        * Test that negative mappings can also be cached
+        */
+       sid = (struct dom_sid) {0};
+       xid = (struct unixid) { .id = 1234, .type = ID_TYPE_UID };
+       idmap_cache_set_sid2unixid(&sid, &xid);
+
+       ret = idmap_cache_find_xid2sid(&xid, &found_sid, &expired);
+       if (!ret) {
+               fprintf(stderr,
+                       "idmap_cache_find_xid2sid failed to find "
+                       "negative mapping\n");
+               goto done;
+       }
+       if (expired) {
+               fprintf(stderr,
+                       "idmap_cache_find_xid2sid returned an expired "
+                       "value\n");
+               goto done;
+       }
+       if (!dom_sid_equal(&sid, &found_sid)) {
+               fprintf(stderr,
+                       "idmap_cache_find_xid2sid returned wrong sid\n");
+               goto done;
+       }
+
+       ret = true;
+done:
+       return ret;
+}
index 0d00f1f84d205d7aabd21863813f50b5ceef95d8..018ebba6c52228101d438f1663770356a5d029f6 100644 (file)
@@ -12081,6 +12081,7 @@ static struct {
        { "LOCAL-G-LOCK-PING-PONG", run_g_lock_ping_pong, 0 },
        { "LOCAL-CANONICALIZE-PATH", run_local_canonicalize_path, 0 },
        { "LOCAL-NAMEMAP-CACHE1", run_local_namemap_cache1, 0 },
+       { "LOCAL-IDMAP-CACHE1", run_local_idmap_cache1, 0 },
        { "qpathinfo-bufsize", run_qpathinfo_bufsize, 0 },
        { "hide-new-files-timeout", run_hidenewfiles, 0 },
        {NULL, NULL, 0}};
index 1ae91057f2464b99649a75e5cfc1a3823c862fea..8d29db51f7780a5925534ab3d8304e43e5281ebd 100644 (file)
@@ -1198,6 +1198,7 @@ bld.SAMBA3_BINARY('smbtorture' + bld.env.suffix3,
                         torture/wbc_async.c
                         torture/test_g_lock.c
                         torture/test_namemap_cache.c
+                        torture/test_idmap_cache.c
                         torture/test_hidenewfiles.c
                         ''',
                  deps='''