wafsamba: add MODE_{744,_777}
[Samba.git] / source3 / torture / test_namemap_cache.c
blobb30fe8743d4b4640586241102697cf58e1a189a3
1 /*
2 * Unix SMB/CIFS implementation.
3 * namemap_cache.c
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/>.
20 #include "includes.h"
21 #include "torture/proto.h"
22 #include "lib/namemap_cache.h"
23 #include "libcli/security/dom_sid.h"
24 #include "lib/gencache.h"
26 static const struct dom_sid domsid = {
27 1, 4, {0,0,0,0,0,5}, {21, 123, 456, 789}
30 static void namemap_cache1_fn1(const char *domain,
31 const char *name,
32 enum lsa_SidType type,
33 bool expired,
34 void *private_data)
36 bool *p_ok = private_data;
37 bool ok;
39 ok = strequal(domain, "nt authority");
40 ok &= strequal(name, "network");
41 ok &= (type == SID_NAME_WKN_GRP);
43 *p_ok = ok;
46 static void namemap_cache1_fn2(const struct dom_sid *sid,
47 enum lsa_SidType type,
48 bool expired,
49 void *private_data)
51 bool *p_ok = private_data;
52 bool ok;
54 ok = dom_sid_equal(sid, &global_sid_Network);
55 ok &= (type == SID_NAME_WKN_GRP);
57 *p_ok = ok;
60 static void namemap_cache1_fn3(const char *domain,
61 const char *name,
62 enum lsa_SidType type,
63 bool expired,
64 void *private_data)
66 bool *p_ok = private_data;
67 bool ok;
69 ok = strequal(domain, "");
70 ok &= strequal(name, "everyone");
71 ok &= (type == SID_NAME_WKN_GRP);
73 *p_ok = ok;
76 static void namemap_cache1_fn4(const struct dom_sid *sid,
77 enum lsa_SidType type,
78 bool expired,
79 void *private_data)
81 bool *p_ok = private_data;
82 bool ok;
84 ok = dom_sid_equal(sid, &global_sid_World);
85 ok &= (type == SID_NAME_WKN_GRP);
87 *p_ok = ok;
90 static void namemap_cache1_fn5(const char *domain,
91 const char *name,
92 enum lsa_SidType type,
93 bool expired,
94 void *private_data)
96 bool *p_ok = private_data;
97 bool ok;
99 ok = strequal(domain, "samba-dom");
100 ok &= strequal(name, "");
101 ok &= (type == SID_NAME_DOMAIN);
103 *p_ok = ok;
106 static void namemap_cache1_fn6(const struct dom_sid *sid,
107 enum lsa_SidType type,
108 bool expired,
109 void *private_data)
111 bool *p_ok = private_data;
112 bool ok;
114 ok = dom_sid_equal(sid, &domsid);
115 ok &= (type == SID_NAME_DOMAIN);
117 *p_ok = ok;
120 bool run_local_namemap_cache1(int dummy)
122 bool found;
123 bool ok;
125 ok = gencache_set("SID2NAME/S-1-5-2", "invalid", time(NULL)+60);
126 if (!ok) {
127 fprintf(stderr, "gencache_set failed\n");
128 return false;
131 ok = namemap_cache_find_sid(&global_sid_Network, namemap_cache1_fn1,
132 &found);
133 if (ok) {
134 fprintf(stderr, "namemap_cache_find_sid parsed valid value\n");
135 return false;
138 ok = namemap_cache_set_sid2name(&global_sid_Network,
139 "NT Authority", "Network",
140 SID_NAME_WKN_GRP,
141 time(NULL) + 60);
142 if (!ok) {
143 fprintf(stderr, "namemap_cache_set_sid2name failed\n");
144 return false;
147 ok = namemap_cache_find_sid(&global_sid_Network, namemap_cache1_fn1,
148 &found);
149 if (!ok) {
150 fprintf(stderr, "namecache_find_sid failed\n");
151 return false;
153 if (!found) {
154 fprintf(stderr, "wrong values found\n");
155 return false;
158 ok = namemap_cache_set_name2sid("NT Authority", "Network",
159 &global_sid_Network,
160 SID_NAME_WKN_GRP,
161 time(NULL) + 60);
162 if (!ok) {
163 fprintf(stderr, "namemap_cache_set_name2sid failed\n");
164 return false;
167 ok = namemap_cache_find_name("nt authority", "network",
168 namemap_cache1_fn2, &found);
169 if (!ok) {
170 fprintf(stderr, "namecache_find_name failed\n");
171 return false;
173 if (!found) {
174 fprintf(stderr, "wrong values found\n");
175 return false;
178 ok = namemap_cache_find_name("foo", "bar", namemap_cache1_fn2, &found);
179 if (ok) {
180 fprintf(stderr,
181 "namemap_cache_find_name succeeded unexpectedly\n");
182 return false;
186 * Test "" domain name
189 ok = namemap_cache_set_sid2name(&global_sid_World, "", "Everyone",
190 SID_NAME_WKN_GRP,
191 time(NULL) + 60);
192 if (!ok) {
193 fprintf(stderr, "namemap_cache_set_sid2name failed\n");
194 return false;
197 ok = namemap_cache_find_sid(&global_sid_World, namemap_cache1_fn3,
198 &found);
199 if (!ok) {
200 fprintf(stderr, "namecache_find_sid failed\n");
201 return false;
203 if (!found) {
204 fprintf(stderr, "wrong values found\n");
205 return false;
208 ok = namemap_cache_set_name2sid("", "Everyone",
209 &global_sid_World, SID_NAME_WKN_GRP,
210 time(NULL) + 60);
211 if (!ok) {
212 fprintf(stderr, "namemap_cache_set failed\n");
213 return false;
216 ok = namemap_cache_find_name("", "everyone",
217 namemap_cache1_fn4, &found);
218 if (!ok) {
219 fprintf(stderr, "namecache_find_name failed\n");
220 return false;
222 if (!found) {
223 fprintf(stderr, "wrong values found\n");
224 return false;
228 * Test domain only
231 ok = namemap_cache_set_sid2name(&domsid, "SAMBA-DOM", "",
232 SID_NAME_DOMAIN,
233 time(NULL) + 60);
234 if (!ok) {
235 fprintf(stderr, "namemap_cache_set failed\n");
236 return false;
239 ok = namemap_cache_find_sid(&domsid, namemap_cache1_fn5,
240 &found);
241 if (!ok) {
242 fprintf(stderr, "namecache_find_sid failed\n");
243 return false;
245 if (!found) {
246 fprintf(stderr, "wrong values found\n");
247 return false;
250 ok = namemap_cache_set_name2sid("SAMBA-DOM", "",
251 &domsid, SID_NAME_DOMAIN,
252 time(NULL) + 60);
253 if (!ok) {
254 fprintf(stderr, "namemap_cache_set failed\n");
255 return false;
258 ok = namemap_cache_find_name("samba-dom", "",
259 namemap_cache1_fn6, &found);
260 if (!ok) {
261 fprintf(stderr, "namecache_find_name failed\n");
262 return false;
264 if (!found) {
265 fprintf(stderr, "wrong values found\n");
266 return false;
269 return true;