torture3: Test namemap_cache
authorVolker Lendecke <vl@samba.org>
Thu, 3 Aug 2017 14:26:25 +0000 (16:26 +0200)
committerRalph Boehme <slow@samba.org>
Wed, 29 Nov 2017 15:59:16 +0000 (16:59 +0100)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/selftest/tests.py
source3/torture/proto.h
source3/torture/test_namemap_cache.c [new file with mode: 0644]
source3/torture/torture.c
source3/wscript_build

index b16416cab05361b5553f2fd8dddf8e933103077f..8360cea274ca53b695b9da3ee7a8c8f213c60856 100755 (executable)
@@ -154,6 +154,7 @@ local_tests = [
     "LOCAL-G-LOCK3",
     "LOCAL-G-LOCK4",
     "LOCAL-G-LOCK5",
+    "LOCAL-NAMEMAP-CACHE1",
     "LOCAL-hex_encode_buf",
     "LOCAL-remove_duplicate_addrs2"]
 
index 8a032da892d75552efe8b57a983e3e3496a6bbb9..83e0c7494d87ffd213284e2e6bbc81d33deb4280 100644 (file)
@@ -132,5 +132,6 @@ bool run_g_lock3(int dummy);
 bool run_g_lock4(int dummy);
 bool run_g_lock5(int dummy);
 bool run_g_lock_ping_pong(int dummy);
+bool run_local_namemap_cache1(int dummy);
 
 #endif /* __TORTURE_H__ */
diff --git a/source3/torture/test_namemap_cache.c b/source3/torture/test_namemap_cache.c
new file mode 100644 (file)
index 0000000..07c6bf4
--- /dev/null
@@ -0,0 +1,262 @@
+/*
+ * Unix SMB/CIFS implementation.
+ * namemap_cache.c
+ * 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/namemap_cache.h"
+#include "libcli/security/dom_sid.h"
+
+static const struct dom_sid domsid = {
+       1, 4, {0,0,0,0,0,5}, {21, 123, 456, 789}
+};
+
+static void namemap_cache1_fn1(const char *domain, const char *name,
+                              enum lsa_SidType type, time_t timeout,
+                              void *private_data)
+{
+       bool *p_ok = private_data;
+       bool ok;
+
+       ok = strequal(domain, "nt authority");
+       ok &= strequal(name, "network");
+       ok &= (type == SID_NAME_WKN_GRP);
+
+       *p_ok = ok;
+}
+
+static void namemap_cache1_fn2(const struct dom_sid *sid,
+                              enum lsa_SidType type, time_t timeout,
+                              void *private_data)
+{
+       bool *p_ok = private_data;
+       bool ok;
+
+       ok = dom_sid_equal(sid, &global_sid_Network);
+       ok &= (type == SID_NAME_WKN_GRP);
+
+       *p_ok = ok;
+}
+
+static void namemap_cache1_fn3(const char *domain, const char *name,
+                              enum lsa_SidType type, time_t timeout,
+                              void *private_data)
+{
+       bool *p_ok = private_data;
+       bool ok;
+
+       ok = strequal(domain, "");
+       ok &= strequal(name, "everyone");
+       ok &= (type == SID_NAME_WKN_GRP);
+
+       *p_ok = ok;
+}
+
+static void namemap_cache1_fn4(const struct dom_sid *sid,
+                              enum lsa_SidType type, time_t timeout,
+                              void *private_data)
+{
+       bool *p_ok = private_data;
+       bool ok;
+
+       ok = dom_sid_equal(sid, &global_sid_World);
+       ok &= (type == SID_NAME_WKN_GRP);
+
+       *p_ok = ok;
+}
+
+static void namemap_cache1_fn5(const char *domain, const char *name,
+                              enum lsa_SidType type, time_t timeout,
+                              void *private_data)
+{
+       bool *p_ok = private_data;
+       bool ok;
+
+       ok = strequal(domain, "samba-dom");
+       ok &= strequal(name, "");
+       ok &= (type == SID_NAME_DOMAIN);
+
+       *p_ok = ok;
+}
+
+static void namemap_cache1_fn6(const struct dom_sid *sid,
+                              enum lsa_SidType type, time_t timeout,
+                              void *private_data)
+{
+       bool *p_ok = private_data;
+       bool ok;
+
+       ok = dom_sid_equal(sid, &domsid);
+       ok &= (type == SID_NAME_DOMAIN);
+
+       *p_ok = ok;
+}
+
+bool run_local_namemap_cache1(int dummy)
+{
+       bool found;
+       bool ok;
+
+       ok = gencache_set("SID2NAME/S-1-5-2", "invalid", time(NULL)+60);
+       if (!ok) {
+               fprintf(stderr, "gencache_set failed\n");
+               return false;
+       }
+
+       ok = namemap_cache_find_sid(&global_sid_Network, namemap_cache1_fn1,
+                                   &found);
+       if (ok) {
+               fprintf(stderr, "namemap_cache_find_sid parsed valid value\n");
+               return false;
+       }
+
+       ok = namemap_cache_set_sid2name(&global_sid_Network,
+                                       "NT Authority", "Network",
+                                       SID_NAME_WKN_GRP,
+                                       time(NULL) + 60);
+       if (!ok) {
+               fprintf(stderr, "namemap_cache_set_sid2name failed\n");
+               return false;
+       }
+
+       ok = namemap_cache_find_sid(&global_sid_Network, namemap_cache1_fn1,
+                                   &found);
+       if (!ok) {
+               fprintf(stderr, "namecache_find_sid failed\n");
+               return false;
+       }
+       if (!found) {
+               fprintf(stderr, "wrong values found\n");
+               return false;
+       }
+
+       ok = namemap_cache_set_name2sid("NT Authority", "Network",
+                                       &global_sid_Network,
+                                       SID_NAME_WKN_GRP,
+                                       time(NULL) + 60);
+       if (!ok) {
+               fprintf(stderr, "namemap_cache_set_name2sid failed\n");
+               return false;
+       }
+
+       ok = namemap_cache_find_name("nt authority", "network",
+                                    namemap_cache1_fn2, &found);
+       if (!ok) {
+               fprintf(stderr, "namecache_find_name failed\n");
+               return false;
+       }
+       if (!found) {
+               fprintf(stderr, "wrong values found\n");
+               return false;
+       }
+
+       ok = namemap_cache_find_name("foo", "bar", namemap_cache1_fn2, &found);
+       if (ok) {
+               fprintf(stderr,
+                       "namemap_cache_find_name succeeded unexpectedly\n");
+               return false;
+       }
+
+       /*
+        * Test "" domain name
+        */
+
+       ok = namemap_cache_set_sid2name(&global_sid_World, "", "Everyone",
+                                       SID_NAME_WKN_GRP,
+                                       time(NULL) + 60);
+       if (!ok) {
+               fprintf(stderr, "namemap_cache_set_sid2name failed\n");
+               return false;
+       }
+
+       ok = namemap_cache_find_sid(&global_sid_World, namemap_cache1_fn3,
+                                   &found);
+       if (!ok) {
+               fprintf(stderr, "namecache_find_sid failed\n");
+               return false;
+       }
+       if (!found) {
+               fprintf(stderr, "wrong values found\n");
+               return false;
+       }
+
+       ok = namemap_cache_set_name2sid("", "Everyone",
+                                       &global_sid_World, SID_NAME_WKN_GRP,
+                                       time(NULL) + 60);
+       if (!ok) {
+               fprintf(stderr, "namemap_cache_set failed\n");
+               return false;
+       }
+
+       ok = namemap_cache_find_name("", "everyone",
+                                    namemap_cache1_fn4, &found);
+       if (!ok) {
+               fprintf(stderr, "namecache_find_name failed\n");
+               return false;
+       }
+       if (!found) {
+               fprintf(stderr, "wrong values found\n");
+               return false;
+       }
+
+       /*
+        * Test domain only
+        */
+
+       ok = namemap_cache_set_sid2name(&domsid, "SAMBA-DOM", "",
+                                       SID_NAME_DOMAIN,
+                                       time(NULL) + 60);
+       if (!ok) {
+               fprintf(stderr, "namemap_cache_set failed\n");
+               return false;
+       }
+
+       ok = namemap_cache_find_sid(&domsid, namemap_cache1_fn5,
+                                   &found);
+       if (!ok) {
+               fprintf(stderr, "namecache_find_sid failed\n");
+               return false;
+       }
+       if (!found) {
+               fprintf(stderr, "wrong values found\n");
+               return false;
+       }
+
+       ok = namemap_cache_set_name2sid("SAMBA-DOM", "",
+                                       &domsid, SID_NAME_DOMAIN,
+                                       time(NULL) + 60);
+       if (!ok) {
+               fprintf(stderr, "namemap_cache_set failed\n");
+               return false;
+       }
+
+       ok = namemap_cache_find_name("samba-dom", "",
+                                    namemap_cache1_fn6, &found);
+       if (!ok) {
+               fprintf(stderr, "namecache_find_name failed\n");
+               return false;
+       }
+       if (!found) {
+               fprintf(stderr, "wrong values found\n");
+               return false;
+       }
+
+       gencache_stabilize();
+
+       return true;
+}
index f2363900b26061f50c64177993a3becdcfcf05f4..cf8b03ca111d5ac2a0d1be23bec701d12a1e04ea 100644 (file)
@@ -11586,6 +11586,7 @@ static struct {
        { "LOCAL-G-LOCK5", run_g_lock5, 0 },
        { "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 },
        { "qpathinfo-bufsize", run_qpathinfo_bufsize, 0 },
        {NULL, NULL, 0}};
 
index 83b99cc065c66daa92bab75c6b27e34e5a4b0902..8b46caee02c05ba940be69f67302d93bb9edce0d 100644 (file)
@@ -1174,6 +1174,7 @@ bld.SAMBA3_BINARY('smbtorture' + bld.env.suffix3,
                         torture/bench_pthreadpool.c
                         torture/wbc_async.c
                         torture/test_g_lock.c
+                        torture/test_namemap_cache.c
                         ''',
                  deps='''
                       talloc