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"
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
,
32 enum lsa_SidType type
,
36 bool *p_ok
= private_data
;
39 ok
= strequal(domain
, "nt authority");
40 ok
&= strequal(name
, "network");
41 ok
&= (type
== SID_NAME_WKN_GRP
);
46 static void namemap_cache1_fn2(const struct dom_sid
*sid
,
47 enum lsa_SidType type
,
51 bool *p_ok
= private_data
;
54 ok
= dom_sid_equal(sid
, &global_sid_Network
);
55 ok
&= (type
== SID_NAME_WKN_GRP
);
60 static void namemap_cache1_fn3(const char *domain
,
62 enum lsa_SidType type
,
66 bool *p_ok
= private_data
;
69 ok
= strequal(domain
, "");
70 ok
&= strequal(name
, "everyone");
71 ok
&= (type
== SID_NAME_WKN_GRP
);
76 static void namemap_cache1_fn4(const struct dom_sid
*sid
,
77 enum lsa_SidType type
,
81 bool *p_ok
= private_data
;
84 ok
= dom_sid_equal(sid
, &global_sid_World
);
85 ok
&= (type
== SID_NAME_WKN_GRP
);
90 static void namemap_cache1_fn5(const char *domain
,
92 enum lsa_SidType type
,
96 bool *p_ok
= private_data
;
99 ok
= strequal(domain
, "samba-dom");
100 ok
&= strequal(name
, "");
101 ok
&= (type
== SID_NAME_DOMAIN
);
106 static void namemap_cache1_fn6(const struct dom_sid
*sid
,
107 enum lsa_SidType type
,
111 bool *p_ok
= private_data
;
114 ok
= dom_sid_equal(sid
, &domsid
);
115 ok
&= (type
== SID_NAME_DOMAIN
);
120 bool run_local_namemap_cache1(int dummy
)
125 ok
= gencache_set("SID2NAME/S-1-5-2", "invalid", time(NULL
)+60);
127 fprintf(stderr
, "gencache_set failed\n");
131 ok
= namemap_cache_find_sid(&global_sid_Network
, namemap_cache1_fn1
,
134 fprintf(stderr
, "namemap_cache_find_sid parsed valid value\n");
138 ok
= namemap_cache_set_sid2name(&global_sid_Network
,
139 "NT Authority", "Network",
143 fprintf(stderr
, "namemap_cache_set_sid2name failed\n");
147 ok
= namemap_cache_find_sid(&global_sid_Network
, namemap_cache1_fn1
,
150 fprintf(stderr
, "namecache_find_sid failed\n");
154 fprintf(stderr
, "wrong values found\n");
158 ok
= namemap_cache_set_name2sid("NT Authority", "Network",
163 fprintf(stderr
, "namemap_cache_set_name2sid failed\n");
167 ok
= namemap_cache_find_name("nt authority", "network",
168 namemap_cache1_fn2
, &found
);
170 fprintf(stderr
, "namecache_find_name failed\n");
174 fprintf(stderr
, "wrong values found\n");
178 ok
= namemap_cache_find_name("foo", "bar", namemap_cache1_fn2
, &found
);
181 "namemap_cache_find_name succeeded unexpectedly\n");
186 * Test "" domain name
189 ok
= namemap_cache_set_sid2name(&global_sid_World
, "", "Everyone",
193 fprintf(stderr
, "namemap_cache_set_sid2name failed\n");
197 ok
= namemap_cache_find_sid(&global_sid_World
, namemap_cache1_fn3
,
200 fprintf(stderr
, "namecache_find_sid failed\n");
204 fprintf(stderr
, "wrong values found\n");
208 ok
= namemap_cache_set_name2sid("", "Everyone",
209 &global_sid_World
, SID_NAME_WKN_GRP
,
212 fprintf(stderr
, "namemap_cache_set failed\n");
216 ok
= namemap_cache_find_name("", "everyone",
217 namemap_cache1_fn4
, &found
);
219 fprintf(stderr
, "namecache_find_name failed\n");
223 fprintf(stderr
, "wrong values found\n");
231 ok
= namemap_cache_set_sid2name(&domsid
, "SAMBA-DOM", "",
235 fprintf(stderr
, "namemap_cache_set failed\n");
239 ok
= namemap_cache_find_sid(&domsid
, namemap_cache1_fn5
,
242 fprintf(stderr
, "namecache_find_sid failed\n");
246 fprintf(stderr
, "wrong values found\n");
250 ok
= namemap_cache_set_name2sid("SAMBA-DOM", "",
251 &domsid
, SID_NAME_DOMAIN
,
254 fprintf(stderr
, "namemap_cache_set failed\n");
258 ok
= namemap_cache_find_name("samba-dom", "",
259 namemap_cache1_fn6
, &found
);
261 fprintf(stderr
, "namecache_find_name failed\n");
265 fprintf(stderr
, "wrong values found\n");