Line data Source code
1 : /*
2 : * Unix SMB/CIFS implementation.
3 : * namemap_cache.c
4 : * Copyright (C) Volker Lendecke 2017
5 : *
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.
10 : *
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.
15 : *
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/>.
18 : */
19 :
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"
25 :
26 : static const struct dom_sid domsid = {
27 : 1, 4, {0,0,0,0,0,5}, {21, 123, 456, 789}
28 : };
29 :
30 0 : static void namemap_cache1_fn1(const char *domain,
31 : const char *name,
32 : enum lsa_SidType type,
33 : bool expired,
34 : void *private_data)
35 : {
36 0 : bool *p_ok = private_data;
37 : bool ok;
38 :
39 0 : ok = strequal(domain, "nt authority");
40 0 : ok &= strequal(name, "network");
41 0 : ok &= (type == SID_NAME_WKN_GRP);
42 :
43 0 : *p_ok = ok;
44 0 : }
45 :
46 0 : static void namemap_cache1_fn2(const struct dom_sid *sid,
47 : enum lsa_SidType type,
48 : bool expired,
49 : void *private_data)
50 : {
51 0 : bool *p_ok = private_data;
52 : bool ok;
53 :
54 0 : ok = dom_sid_equal(sid, &global_sid_Network);
55 0 : ok &= (type == SID_NAME_WKN_GRP);
56 :
57 0 : *p_ok = ok;
58 0 : }
59 :
60 0 : static void namemap_cache1_fn3(const char *domain,
61 : const char *name,
62 : enum lsa_SidType type,
63 : bool expired,
64 : void *private_data)
65 : {
66 0 : bool *p_ok = private_data;
67 : bool ok;
68 :
69 0 : ok = strequal(domain, "");
70 0 : ok &= strequal(name, "everyone");
71 0 : ok &= (type == SID_NAME_WKN_GRP);
72 :
73 0 : *p_ok = ok;
74 0 : }
75 :
76 0 : static void namemap_cache1_fn4(const struct dom_sid *sid,
77 : enum lsa_SidType type,
78 : bool expired,
79 : void *private_data)
80 : {
81 0 : bool *p_ok = private_data;
82 : bool ok;
83 :
84 0 : ok = dom_sid_equal(sid, &global_sid_World);
85 0 : ok &= (type == SID_NAME_WKN_GRP);
86 :
87 0 : *p_ok = ok;
88 0 : }
89 :
90 0 : static void namemap_cache1_fn5(const char *domain,
91 : const char *name,
92 : enum lsa_SidType type,
93 : bool expired,
94 : void *private_data)
95 : {
96 0 : bool *p_ok = private_data;
97 : bool ok;
98 :
99 0 : ok = strequal(domain, "samba-dom");
100 0 : ok &= strequal(name, "");
101 0 : ok &= (type == SID_NAME_DOMAIN);
102 :
103 0 : *p_ok = ok;
104 0 : }
105 :
106 0 : static void namemap_cache1_fn6(const struct dom_sid *sid,
107 : enum lsa_SidType type,
108 : bool expired,
109 : void *private_data)
110 : {
111 0 : bool *p_ok = private_data;
112 : bool ok;
113 :
114 0 : ok = dom_sid_equal(sid, &domsid);
115 0 : ok &= (type == SID_NAME_DOMAIN);
116 :
117 0 : *p_ok = ok;
118 0 : }
119 :
120 0 : bool run_local_namemap_cache1(int dummy)
121 : {
122 : bool found;
123 : bool ok;
124 :
125 0 : ok = gencache_set("SID2NAME/S-1-5-2", "invalid", time(NULL)+60);
126 0 : if (!ok) {
127 0 : fprintf(stderr, "gencache_set failed\n");
128 0 : return false;
129 : }
130 :
131 0 : ok = namemap_cache_find_sid(&global_sid_Network, namemap_cache1_fn1,
132 : &found);
133 0 : if (ok) {
134 0 : fprintf(stderr, "namemap_cache_find_sid parsed valid value\n");
135 0 : return false;
136 : }
137 :
138 0 : ok = namemap_cache_set_sid2name(&global_sid_Network,
139 : "NT Authority", "Network",
140 : SID_NAME_WKN_GRP,
141 0 : time(NULL) + 60);
142 0 : if (!ok) {
143 0 : fprintf(stderr, "namemap_cache_set_sid2name failed\n");
144 0 : return false;
145 : }
146 :
147 0 : ok = namemap_cache_find_sid(&global_sid_Network, namemap_cache1_fn1,
148 : &found);
149 0 : if (!ok) {
150 0 : fprintf(stderr, "namecache_find_sid failed\n");
151 0 : return false;
152 : }
153 0 : if (!found) {
154 0 : fprintf(stderr, "wrong values found\n");
155 0 : return false;
156 : }
157 :
158 0 : ok = namemap_cache_set_name2sid("NT Authority", "Network",
159 : &global_sid_Network,
160 : SID_NAME_WKN_GRP,
161 0 : time(NULL) + 60);
162 0 : if (!ok) {
163 0 : fprintf(stderr, "namemap_cache_set_name2sid failed\n");
164 0 : return false;
165 : }
166 :
167 0 : ok = namemap_cache_find_name("nt authority", "network",
168 : namemap_cache1_fn2, &found);
169 0 : if (!ok) {
170 0 : fprintf(stderr, "namecache_find_name failed\n");
171 0 : return false;
172 : }
173 0 : if (!found) {
174 0 : fprintf(stderr, "wrong values found\n");
175 0 : return false;
176 : }
177 :
178 0 : ok = namemap_cache_find_name("foo", "bar", namemap_cache1_fn2, &found);
179 0 : if (ok) {
180 0 : fprintf(stderr,
181 : "namemap_cache_find_name succeeded unexpectedly\n");
182 0 : return false;
183 : }
184 :
185 : /*
186 : * Test "" domain name
187 : */
188 :
189 0 : ok = namemap_cache_set_sid2name(&global_sid_World, "", "Everyone",
190 : SID_NAME_WKN_GRP,
191 0 : time(NULL) + 60);
192 0 : if (!ok) {
193 0 : fprintf(stderr, "namemap_cache_set_sid2name failed\n");
194 0 : return false;
195 : }
196 :
197 0 : ok = namemap_cache_find_sid(&global_sid_World, namemap_cache1_fn3,
198 : &found);
199 0 : if (!ok) {
200 0 : fprintf(stderr, "namecache_find_sid failed\n");
201 0 : return false;
202 : }
203 0 : if (!found) {
204 0 : fprintf(stderr, "wrong values found\n");
205 0 : return false;
206 : }
207 :
208 0 : ok = namemap_cache_set_name2sid("", "Everyone",
209 : &global_sid_World, SID_NAME_WKN_GRP,
210 0 : time(NULL) + 60);
211 0 : if (!ok) {
212 0 : fprintf(stderr, "namemap_cache_set failed\n");
213 0 : return false;
214 : }
215 :
216 0 : ok = namemap_cache_find_name("", "everyone",
217 : namemap_cache1_fn4, &found);
218 0 : if (!ok) {
219 0 : fprintf(stderr, "namecache_find_name failed\n");
220 0 : return false;
221 : }
222 0 : if (!found) {
223 0 : fprintf(stderr, "wrong values found\n");
224 0 : return false;
225 : }
226 :
227 : /*
228 : * Test domain only
229 : */
230 :
231 0 : ok = namemap_cache_set_sid2name(&domsid, "SAMBA-DOM", "",
232 : SID_NAME_DOMAIN,
233 0 : time(NULL) + 60);
234 0 : if (!ok) {
235 0 : fprintf(stderr, "namemap_cache_set failed\n");
236 0 : return false;
237 : }
238 :
239 0 : ok = namemap_cache_find_sid(&domsid, namemap_cache1_fn5,
240 : &found);
241 0 : if (!ok) {
242 0 : fprintf(stderr, "namecache_find_sid failed\n");
243 0 : return false;
244 : }
245 0 : if (!found) {
246 0 : fprintf(stderr, "wrong values found\n");
247 0 : return false;
248 : }
249 :
250 0 : ok = namemap_cache_set_name2sid("SAMBA-DOM", "",
251 : &domsid, SID_NAME_DOMAIN,
252 0 : time(NULL) + 60);
253 0 : if (!ok) {
254 0 : fprintf(stderr, "namemap_cache_set failed\n");
255 0 : return false;
256 : }
257 :
258 0 : ok = namemap_cache_find_name("samba-dom", "",
259 : namemap_cache1_fn6, &found);
260 0 : if (!ok) {
261 0 : fprintf(stderr, "namecache_find_name failed\n");
262 0 : return false;
263 : }
264 0 : if (!found) {
265 0 : fprintf(stderr, "wrong values found\n");
266 0 : return false;
267 : }
268 :
269 0 : return true;
270 : }
|