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_netbios_name(struct torture_context *torture)
102 struct winbindd_request req;
103 struct winbindd_response rep;
104 const char *expected;
109 torture_comment(torture, "Running WINBINDD_NETBIOS_NAME (struct based)\n");
111 DO_STRUCT_REQ_REP(WINBINDD_NETBIOS_NAME, &req, &rep);
113 expected = torture_setting_string(torture,
114 "winbindd netbios name",
117 torture_assert_str_equal(torture,
118 rep.data.netbios_name, expected,
119 "winbindd's netbios name doesn't match");
124 struct torture_trust_domain {
125 const char *netbios_name;
126 const char *dns_name;
130 static bool get_trusted_domains(struct torture_context *torture,
131 struct torture_trust_domain **_d)
133 struct winbindd_request req;
134 struct winbindd_response rep;
135 struct torture_trust_domain *d = NULL;
138 const char *extra_data;
143 DO_STRUCT_REQ_REP(WINBINDD_LIST_TRUSTDOM, &req, &rep);
145 extra_data = (char *)rep.extra_data.data;
146 torture_assert(torture, extra_data, "NULL trust list");
148 while (next_token(&extra_data, line, "\n", sizeof(fstring))) {
151 d = talloc_realloc(torture, d,
152 struct torture_trust_domain,
154 ZERO_STRUCT(d[dcount+1]);
157 p = strchr(lp, '\\');
158 torture_assert(torture, p, "missing 1st '\\' in line");
160 d[dcount].netbios_name = talloc_strdup(d, lp);
161 torture_assert(torture, strlen(d[dcount].netbios_name) > 0,
162 "empty netbios_name");
165 p = strchr(lp, '\\');
166 torture_assert(torture, p, "missing 2nd '\\' in line");
168 d[dcount].dns_name = talloc_strdup(d, lp);
169 /* it's ok to have an empty dns_name */
172 d[dcount].sid = dom_sid_parse_talloc(d, lp);
173 torture_assert(torture, d[dcount].sid,
174 "failed to parse sid");
178 SAFE_FREE(rep.extra_data.data);
180 torture_assert(torture, dcount >= 2,
181 "The list of trusted domain should contain 2 entries");
187 static bool torture_winbind_struct_list_trustdom(struct torture_context *torture)
189 struct winbindd_request req;
190 struct winbindd_response rep;
194 struct torture_trust_domain *listd = NULL;
197 torture_comment(torture, "Running WINBINDD_LIST_TRUSTDOM (struct based)\n");
202 req.data.list_all_domains = false;
204 DO_STRUCT_REQ_REP(WINBINDD_LIST_TRUSTDOM, &req, &rep);
206 list1 = (char *)rep.extra_data.data;
207 torture_assert(torture, list1, "NULL trust list");
209 torture_comment(torture, "%s\n", list1);
214 req.data.list_all_domains = true;
216 DO_STRUCT_REQ_REP(WINBINDD_LIST_TRUSTDOM, &req, &rep);
218 list2 = (char *)rep.extra_data.data;
219 torture_assert(torture, list2, "NULL trust list");
222 * The list_all_domains parameter should be ignored
224 torture_assert_str_equal(torture, list2, list1, "list_all_domains not ignored");
229 ok = get_trusted_domains(torture, &listd);
230 torture_assert(torture, ok, "failed to get trust list");
232 for (i=0; listd[i].netbios_name; i++) {
234 struct dom_sid *builtin_sid;
236 builtin_sid = dom_sid_parse_talloc(torture, SID_BUILTIN);
238 torture_assert_str_equal(torture,
239 listd[i].netbios_name,
241 "first domain should be 'BUILTIN'");
243 torture_assert_str_equal(torture,
246 "BUILTIN domain should not have a dns name");
248 ok = dom_sid_equal(builtin_sid,
250 torture_assert(torture, ok, "BUILTIN domain should have S-1-5-32");
256 * TODO: verify the content of the 2nd and 3rd (in member server mode)
264 static bool torture_winbind_struct_getdcname(struct torture_context *torture)
267 bool strict = torture_setting_bool(torture, "strict mode", false);
268 struct torture_trust_domain *listd = NULL;
271 torture_comment(torture, "Running WINBINDD_GETDCNAME (struct based)\n");
273 ok = get_trusted_domains(torture, &listd);
274 torture_assert(torture, ok, "failed to get trust list");
276 for (i=0; listd[i].netbios_name; i++) {
277 struct winbindd_request req;
278 struct winbindd_response rep;
283 fstrcpy(req.domain_name, listd[i].netbios_name);
286 DO_STRUCT_REQ_REP_EXT(WINBINDD_GETDCNAME, &req, &rep,
288 (i <2 || strict), ok = false,
289 talloc_asprintf(torture, "DOMAIN '%s'",
293 /* TODO: check rep.data.dc_name; */
294 torture_comment(torture, "DOMAIN '%s' => DCNAME '%s'\n",
295 req.domain_name, rep.data.dc_name);
301 struct torture_suite *torture_winbind_struct_init(void)
303 struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "STRUCT");
305 torture_suite_add_simple_test(suite, "INTERFACE_VERSION", torture_winbind_struct_interface_version);
306 torture_suite_add_simple_test(suite, "PING", torture_winbind_struct_ping);
307 torture_suite_add_simple_test(suite, "NETBIOS_NAME", torture_winbind_struct_netbios_name);
308 torture_suite_add_simple_test(suite, "LIST_TRUSTDOM", torture_winbind_struct_list_trustdom);
309 torture_suite_add_simple_test(suite, "GETDCNAME", torture_winbind_struct_getdcname);
311 suite->description = talloc_strdup(suite, "WINBIND - struct based protocol tests");