2 Unix SMB/CIFS implementation.
3 SMB torture tester - winbind struct based protocol
4 Copyright (C) Stefan Metzmacher 2007
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/>.
22 #include "torture/torture.h"
23 #include "torture/winbind/proto.h"
24 #include "nsswitch/winbind_client.h"
25 #include "libcli/security/security.h"
26 #include "param/param.h"
28 #define DO_STRUCT_REQ_REP_EXT(op,req,rep,expected,strict,warnaction,cmt) do { \
29 NSS_STATUS __got, __expected = (expected); \
30 __got = winbindd_request_response(op, req, rep); \
31 if (__got != __expected) { \
32 const char *__cmt = (cmt); \
34 torture_result(torture, TORTURE_FAIL, \
35 __location__ ": " __STRING(op) \
36 " returned %d, expected %d%s%s", \
38 (__cmt) ? ": " : "", \
39 (__cmt) ? (__cmt) : ""); \
42 torture_warning(torture, \
43 __location__ ": " __STRING(op) \
44 " returned %d, expected %d%s%s", \
46 (__cmt) ? ": " : "", \
47 (__cmt) ? (__cmt) : ""); \
53 #define DO_STRUCT_REQ_REP(op,req,rep) do { \
54 bool __noop = false; \
55 DO_STRUCT_REQ_REP_EXT(op,req,rep,NSS_STATUS_SUCCESS,true,__noop=true,NULL); \
58 static bool torture_winbind_struct_interface_version(struct torture_context *torture)
60 struct winbindd_request req;
61 struct winbindd_response rep;
66 torture_comment(torture, "Running WINBINDD_INTERFACE_VERSION (struct based)\n");
68 DO_STRUCT_REQ_REP(WINBINDD_INTERFACE_VERSION, &req, &rep);
70 torture_assert_int_equal(torture,
71 rep.data.interface_version,
72 WINBIND_INTERFACE_VERSION,
73 "winbind server and client doesn't match");
78 static bool torture_winbind_struct_ping(struct torture_context *torture)
80 struct timeval tv = timeval_current();
81 int timelimit = torture_setting_int(torture, "timelimit", 5);
84 torture_comment(torture,
85 "Running WINBINDD_PING (struct based) for %d seconds\n",
88 while (timeval_elapsed(&tv) < timelimit) {
89 DO_STRUCT_REQ_REP(WINBINDD_PING, NULL, NULL);
93 torture_comment(torture,
94 "%u (%.1f/s) WINBINDD_PING (struct based)\n",
95 total, total / timeval_elapsed(&tv));
100 static bool torture_winbind_struct_info(struct torture_context *torture)
102 struct winbindd_response rep;
103 const char *separator;
107 torture_comment(torture, "Running WINBINDD_INFO (struct based)\n");
109 DO_STRUCT_REQ_REP(WINBINDD_INFO, NULL, &rep);
111 separator = torture_setting_string(torture,
112 "winbindd separator",
113 lp_winbind_separator());
114 torture_assert_int_equal(torture,
115 rep.data.info.winbind_separator,
117 "winbind separator doesn't match");
119 torture_comment(torture, "Samba Version '%s'\n",
120 rep.data.info.samba_version);
125 static bool torture_winbind_struct_priv_pipe_dir(struct torture_context *torture)
127 struct winbindd_response rep;
128 const char *default_dir;
129 const char *expected_dir;
134 torture_comment(torture, "Running WINBINDD_PRIV_PIPE_DIR (struct based)\n");
136 DO_STRUCT_REQ_REP(WINBINDD_PRIV_PIPE_DIR, NULL, &rep);
138 got_dir = (const char *)rep.extra_data.data;
140 torture_assert(torture, got_dir, "NULL WINBINDD_PRIV_PIPE_DIR\n");
142 default_dir = lock_path(torture, WINBINDD_PRIV_SOCKET_SUBDIR);
143 expected_dir = torture_setting_string(torture,
144 "winbindd private pipe dir",
147 torture_assert_str_equal(torture, got_dir, expected_dir,
148 "WINBINDD_PRIV_PIPE_DIR doesn't match");
150 SAFE_FREE(rep.extra_data.data);
154 static bool torture_winbind_struct_netbios_name(struct torture_context *torture)
156 struct winbindd_request req;
157 struct winbindd_response rep;
158 const char *expected;
163 torture_comment(torture, "Running WINBINDD_NETBIOS_NAME (struct based)\n");
165 DO_STRUCT_REQ_REP(WINBINDD_NETBIOS_NAME, &req, &rep);
167 expected = torture_setting_string(torture,
168 "winbindd netbios name",
171 torture_assert_str_equal(torture,
172 rep.data.netbios_name, expected,
173 "winbindd's netbios name doesn't match");
178 static bool torture_winbind_struct_domain_name(struct torture_context *torture)
180 struct winbindd_request req;
181 struct winbindd_response rep;
182 const char *expected;
187 torture_comment(torture, "Running WINBINDD_DOMAIN_NAME (struct based)\n");
189 DO_STRUCT_REQ_REP(WINBINDD_DOMAIN_NAME, &req, &rep);
191 expected = torture_setting_string(torture,
192 "winbindd netbios domain",
195 torture_assert_str_equal(torture,
196 rep.data.domain_name, expected,
197 "winbindd's netbios domain doesn't match");
202 struct torture_trust_domain {
203 const char *netbios_name;
204 const char *dns_name;
208 static bool get_trusted_domains(struct torture_context *torture,
209 struct torture_trust_domain **_d)
211 struct winbindd_request req;
212 struct winbindd_response rep;
213 struct torture_trust_domain *d = NULL;
216 const char *extra_data;
221 DO_STRUCT_REQ_REP(WINBINDD_LIST_TRUSTDOM, &req, &rep);
223 extra_data = (char *)rep.extra_data.data;
224 torture_assert(torture, extra_data, "NULL trust list");
226 while (next_token(&extra_data, line, "\n", sizeof(fstring))) {
229 d = talloc_realloc(torture, d,
230 struct torture_trust_domain,
232 ZERO_STRUCT(d[dcount+1]);
235 p = strchr(lp, '\\');
236 torture_assert(torture, p, "missing 1st '\\' in line");
238 d[dcount].netbios_name = talloc_strdup(d, lp);
239 torture_assert(torture, strlen(d[dcount].netbios_name) > 0,
240 "empty netbios_name");
243 p = strchr(lp, '\\');
244 torture_assert(torture, p, "missing 2nd '\\' in line");
246 d[dcount].dns_name = talloc_strdup(d, lp);
247 /* it's ok to have an empty dns_name */
250 d[dcount].sid = dom_sid_parse_talloc(d, lp);
251 torture_assert(torture, d[dcount].sid,
252 "failed to parse sid");
256 SAFE_FREE(rep.extra_data.data);
258 torture_assert(torture, dcount >= 2,
259 "The list of trusted domain should contain 2 entries");
265 static bool torture_winbind_struct_list_trustdom(struct torture_context *torture)
267 struct winbindd_request req;
268 struct winbindd_response rep;
272 struct torture_trust_domain *listd = NULL;
275 torture_comment(torture, "Running WINBINDD_LIST_TRUSTDOM (struct based)\n");
280 req.data.list_all_domains = false;
282 DO_STRUCT_REQ_REP(WINBINDD_LIST_TRUSTDOM, &req, &rep);
284 list1 = (char *)rep.extra_data.data;
285 torture_assert(torture, list1, "NULL trust list");
287 torture_comment(torture, "%s\n", list1);
292 req.data.list_all_domains = true;
294 DO_STRUCT_REQ_REP(WINBINDD_LIST_TRUSTDOM, &req, &rep);
296 list2 = (char *)rep.extra_data.data;
297 torture_assert(torture, list2, "NULL trust list");
300 * The list_all_domains parameter should be ignored
302 torture_assert_str_equal(torture, list2, list1, "list_all_domains not ignored");
307 ok = get_trusted_domains(torture, &listd);
308 torture_assert(torture, ok, "failed to get trust list");
310 for (i=0; listd[i].netbios_name; i++) {
312 struct dom_sid *builtin_sid;
314 builtin_sid = dom_sid_parse_talloc(torture, SID_BUILTIN);
316 torture_assert_str_equal(torture,
317 listd[i].netbios_name,
319 "first domain should be 'BUILTIN'");
321 torture_assert_str_equal(torture,
324 "BUILTIN domain should not have a dns name");
326 ok = dom_sid_equal(builtin_sid,
328 torture_assert(torture, ok, "BUILTIN domain should have S-1-5-32");
334 * TODO: verify the content of the 2nd and 3rd (in member server mode)
342 static bool torture_winbind_struct_domain_info(struct torture_context *torture)
345 struct torture_trust_domain *listd = NULL;
348 torture_comment(torture, "Running WINBINDD_DOMAIN_INFO (struct based)\n");
350 ok = get_trusted_domains(torture, &listd);
351 torture_assert(torture, ok, "failed to get trust list");
353 for (i=0; listd[i].netbios_name; i++) {
354 struct winbindd_request req;
355 struct winbindd_response rep;
357 char *flagstr = talloc_strdup(torture," ");
362 fstrcpy(req.domain_name, listd[i].netbios_name);
364 DO_STRUCT_REQ_REP(WINBINDD_DOMAIN_INFO, &req, &rep);
366 torture_assert_str_equal(torture,
367 rep.data.domain_info.name,
368 listd[i].netbios_name,
369 "Netbios domain name doesn't match");
371 torture_assert_str_equal(torture,
372 rep.data.domain_info.alt_name,
374 "DNS domain name doesn't match");
376 sid = dom_sid_parse_talloc(torture, rep.data.domain_info.sid);
377 torture_assert(torture, sid, "Failed to parse SID");
379 ok = dom_sid_equal(listd[i].sid, sid);
380 torture_assert(torture, ok, "SID's doesn't match");
382 if (rep.data.domain_info.primary) {
383 flagstr = talloc_strdup_append(flagstr, "PR ");
386 if (rep.data.domain_info.active_directory) {
387 torture_assert(torture,
388 strlen(rep.data.domain_info.alt_name)>0,
389 "Active Directory without DNS name");
390 flagstr = talloc_strdup_append(flagstr, "AD ");
393 if (rep.data.domain_info.native_mode) {
394 torture_assert(torture,
395 rep.data.domain_info.active_directory,
396 "Native-Mode, but no Active Directory");
397 flagstr = talloc_strdup_append(flagstr, "NA ");
400 torture_comment(torture, "DOMAIN '%s' => '%s' [%s]\n",
401 rep.data.domain_info.name,
402 rep.data.domain_info.alt_name,
409 static bool torture_winbind_struct_getdcname(struct torture_context *torture)
412 bool strict = torture_setting_bool(torture, "strict mode", false);
413 struct torture_trust_domain *listd = NULL;
416 torture_comment(torture, "Running WINBINDD_GETDCNAME (struct based)\n");
418 ok = get_trusted_domains(torture, &listd);
419 torture_assert(torture, ok, "failed to get trust list");
421 for (i=0; listd[i].netbios_name; i++) {
422 struct winbindd_request req;
423 struct winbindd_response rep;
428 fstrcpy(req.domain_name, listd[i].netbios_name);
431 DO_STRUCT_REQ_REP_EXT(WINBINDD_GETDCNAME, &req, &rep,
433 (i <2 || strict), ok = false,
434 talloc_asprintf(torture, "DOMAIN '%s'",
438 /* TODO: check rep.data.dc_name; */
439 torture_comment(torture, "DOMAIN '%s' => DCNAME '%s'\n",
440 req.domain_name, rep.data.dc_name);
446 struct torture_suite *torture_winbind_struct_init(void)
448 struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "STRUCT");
450 torture_suite_add_simple_test(suite, "INTERFACE_VERSION", torture_winbind_struct_interface_version);
451 torture_suite_add_simple_test(suite, "PING", torture_winbind_struct_ping);
452 torture_suite_add_simple_test(suite, "INFO", torture_winbind_struct_info);
453 torture_suite_add_simple_test(suite, "PRIV_PIPE_DIR", torture_winbind_struct_priv_pipe_dir);
454 torture_suite_add_simple_test(suite, "NETBIOS_NAME", torture_winbind_struct_netbios_name);
455 torture_suite_add_simple_test(suite, "DOMAIN_NAME", torture_winbind_struct_domain_name);
456 torture_suite_add_simple_test(suite, "LIST_TRUSTDOM", torture_winbind_struct_list_trustdom);
457 torture_suite_add_simple_test(suite, "DOMAIN_INFO", torture_winbind_struct_domain_info);
458 torture_suite_add_simple_test(suite, "GETDCNAME", torture_winbind_struct_getdcname);
460 suite->description = talloc_strdup(suite, "WINBIND - struct based protocol tests");