2 * Unix SMB/CIFS implementation.
4 * Copyright (C) Volker Lendecke 2017
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "torture/proto.h"
22 #include "lib/namemap_cache.h"
23 #include "libcli/security/dom_sid.h"
25 static const struct dom_sid domsid = {
26 1, 4, {0,0,0,0,0,5}, {21, 123, 456, 789}
29 static void namemap_cache1_fn1(const char *domain,
31 enum lsa_SidType type,
35 bool *p_ok = private_data;
38 ok = strequal(domain, "nt authority");
39 ok &= strequal(name, "network");
40 ok &= (type == SID_NAME_WKN_GRP);
45 static void namemap_cache1_fn2(const struct dom_sid *sid,
46 enum lsa_SidType type,
50 bool *p_ok = private_data;
53 ok = dom_sid_equal(sid, &global_sid_Network);
54 ok &= (type == SID_NAME_WKN_GRP);
59 static void namemap_cache1_fn3(const char *domain,
61 enum lsa_SidType type,
65 bool *p_ok = private_data;
68 ok = strequal(domain, "");
69 ok &= strequal(name, "everyone");
70 ok &= (type == SID_NAME_WKN_GRP);
75 static void namemap_cache1_fn4(const struct dom_sid *sid,
76 enum lsa_SidType type,
80 bool *p_ok = private_data;
83 ok = dom_sid_equal(sid, &global_sid_World);
84 ok &= (type == SID_NAME_WKN_GRP);
89 static void namemap_cache1_fn5(const char *domain,
91 enum lsa_SidType type,
95 bool *p_ok = private_data;
98 ok = strequal(domain, "samba-dom");
99 ok &= strequal(name, "");
100 ok &= (type == SID_NAME_DOMAIN);
105 static void namemap_cache1_fn6(const struct dom_sid *sid,
106 enum lsa_SidType type,
110 bool *p_ok = private_data;
113 ok = dom_sid_equal(sid, &domsid);
114 ok &= (type == SID_NAME_DOMAIN);
119 bool run_local_namemap_cache1(int dummy)
124 ok = gencache_set("SID2NAME/S-1-5-2", "invalid", time(NULL)+60);
126 fprintf(stderr, "gencache_set failed\n");
130 ok = namemap_cache_find_sid(&global_sid_Network, namemap_cache1_fn1,
133 fprintf(stderr, "namemap_cache_find_sid parsed valid value\n");
137 ok = namemap_cache_set_sid2name(&global_sid_Network,
138 "NT Authority", "Network",
142 fprintf(stderr, "namemap_cache_set_sid2name failed\n");
146 ok = namemap_cache_find_sid(&global_sid_Network, namemap_cache1_fn1,
149 fprintf(stderr, "namecache_find_sid failed\n");
153 fprintf(stderr, "wrong values found\n");
157 ok = namemap_cache_set_name2sid("NT Authority", "Network",
162 fprintf(stderr, "namemap_cache_set_name2sid failed\n");
166 ok = namemap_cache_find_name("nt authority", "network",
167 namemap_cache1_fn2, &found);
169 fprintf(stderr, "namecache_find_name failed\n");
173 fprintf(stderr, "wrong values found\n");
177 ok = namemap_cache_find_name("foo", "bar", namemap_cache1_fn2, &found);
180 "namemap_cache_find_name succeeded unexpectedly\n");
185 * Test "" domain name
188 ok = namemap_cache_set_sid2name(&global_sid_World, "", "Everyone",
192 fprintf(stderr, "namemap_cache_set_sid2name failed\n");
196 ok = namemap_cache_find_sid(&global_sid_World, namemap_cache1_fn3,
199 fprintf(stderr, "namecache_find_sid failed\n");
203 fprintf(stderr, "wrong values found\n");
207 ok = namemap_cache_set_name2sid("", "Everyone",
208 &global_sid_World, SID_NAME_WKN_GRP,
211 fprintf(stderr, "namemap_cache_set failed\n");
215 ok = namemap_cache_find_name("", "everyone",
216 namemap_cache1_fn4, &found);
218 fprintf(stderr, "namecache_find_name failed\n");
222 fprintf(stderr, "wrong values found\n");
230 ok = namemap_cache_set_sid2name(&domsid, "SAMBA-DOM", "",
234 fprintf(stderr, "namemap_cache_set failed\n");
238 ok = namemap_cache_find_sid(&domsid, namemap_cache1_fn5,
241 fprintf(stderr, "namecache_find_sid failed\n");
245 fprintf(stderr, "wrong values found\n");
249 ok = namemap_cache_set_name2sid("SAMBA-DOM", "",
250 &domsid, SID_NAME_DOMAIN,
253 fprintf(stderr, "namemap_cache_set failed\n");
257 ok = namemap_cache_find_name("samba-dom", "",
258 namemap_cache1_fn6, &found);
260 fprintf(stderr, "namecache_find_name failed\n");
264 fprintf(stderr, "wrong values found\n");
268 gencache_stabilize();