s4-torture: Improve samlogon test.
[Samba/gbeck.git] / source4 / torture / rpc / samba3rpc.c
blob2a905ea3c2d223ec6b78630a5970c9c39df772ed
1 /*
2 Unix SMB/CIFS implementation.
4 dcerpc torture tests, designed to walk Samba3 code paths
6 Copyright (C) Volker Lendecke 2006
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "includes.h"
23 #include "libcli/raw/libcliraw.h"
24 #include "libcli/raw/raw_proto.h"
25 #include "torture/util.h"
26 #include "libcli/rap/rap.h"
27 #include "librpc/gen_ndr/ndr_lsa_c.h"
28 #include "librpc/gen_ndr/ndr_samr_c.h"
29 #include "librpc/gen_ndr/ndr_netlogon_c.h"
30 #include "librpc/gen_ndr/ndr_srvsvc_c.h"
31 #include "librpc/gen_ndr/ndr_spoolss_c.h"
32 #include "librpc/gen_ndr/ndr_winreg_c.h"
33 #include "librpc/gen_ndr/ndr_wkssvc_c.h"
34 #include "lib/cmdline/popt_common.h"
35 #include "torture/rpc/torture_rpc.h"
36 #include "libcli/libcli.h"
37 #include "libcli/smb_composite/smb_composite.h"
38 #include "libcli/auth/libcli_auth.h"
39 #include "../lib/crypto/crypto.h"
40 #include "libcli/security/security.h"
41 #include "param/param.h"
42 #include "lib/registry/registry.h"
43 #include "libcli/resolve/resolve.h"
44 #include "torture/ndr/ndr.h"
45 #include "libcli/smb2/smb2.h"
46 #include "libcli/smb2/smb2_calls.h"
47 #include "librpc/rpc/dcerpc.h"
48 #include "librpc/rpc/dcerpc_proto.h"
49 #include "../source3/libsmb/smb2cli.h"
52 * This tests a RPC call using an invalid vuid
55 bool torture_bind_authcontext(struct torture_context *torture)
57 TALLOC_CTX *mem_ctx;
58 NTSTATUS status;
59 bool ret = false;
60 struct lsa_ObjectAttribute objectattr;
61 struct lsa_OpenPolicy2 openpolicy;
62 struct policy_handle handle;
63 struct lsa_Close close_handle;
64 struct smbcli_session *tmp;
65 struct smbcli_session *session2;
66 struct smbcli_state *cli;
67 struct dcerpc_pipe *lsa_pipe;
68 struct dcerpc_binding_handle *lsa_handle;
69 struct cli_credentials *anon_creds;
70 struct smb_composite_sesssetup setup;
71 struct smbcli_options options;
72 struct smbcli_session_options session_options;
74 mem_ctx = talloc_init("torture_bind_authcontext");
76 if (mem_ctx == NULL) {
77 torture_comment(torture, "talloc_init failed\n");
78 return false;
81 lpcfg_smbcli_options(torture->lp_ctx, &options);
82 lpcfg_smbcli_session_options(torture->lp_ctx, &session_options);
84 status = smbcli_full_connection(mem_ctx, &cli,
85 torture_setting_string(torture, "host", NULL),
86 lpcfg_smb_ports(torture->lp_ctx),
87 "IPC$", NULL,
88 lpcfg_socket_options(torture->lp_ctx),
89 cmdline_credentials,
90 lpcfg_resolve_context(torture->lp_ctx),
91 torture->ev, &options, &session_options,
92 lpcfg_gensec_settings(torture, torture->lp_ctx));
93 if (!NT_STATUS_IS_OK(status)) {
94 torture_comment(torture, "smbcli_full_connection failed: %s\n",
95 nt_errstr(status));
96 goto done;
99 lsa_pipe = dcerpc_pipe_init(mem_ctx, torture->ev);
100 if (lsa_pipe == NULL) {
101 torture_comment(torture, "dcerpc_pipe_init failed\n");
102 goto done;
104 lsa_handle = lsa_pipe->binding_handle;
106 status = dcerpc_pipe_open_smb(lsa_pipe, cli->tree, "\\lsarpc");
107 if (!NT_STATUS_IS_OK(status)) {
108 torture_comment(torture, "dcerpc_pipe_open_smb failed: %s\n",
109 nt_errstr(status));
110 goto done;
113 status = dcerpc_bind_auth_none(lsa_pipe, &ndr_table_lsarpc);
114 if (!NT_STATUS_IS_OK(status)) {
115 torture_comment(torture, "dcerpc_bind_auth_none failed: %s\n",
116 nt_errstr(status));
117 goto done;
120 openpolicy.in.system_name =talloc_asprintf(
121 mem_ctx, "\\\\%s", dcerpc_server_name(lsa_pipe));
122 ZERO_STRUCT(objectattr);
123 openpolicy.in.attr = &objectattr;
124 openpolicy.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
125 openpolicy.out.handle = &handle;
127 status = dcerpc_lsa_OpenPolicy2_r(lsa_handle, mem_ctx, &openpolicy);
129 if (!NT_STATUS_IS_OK(status)) {
130 torture_comment(torture, "dcerpc_lsa_OpenPolicy2 failed: %s\n",
131 nt_errstr(status));
132 goto done;
134 if (!NT_STATUS_IS_OK(openpolicy.out.result)) {
135 torture_comment(torture, "dcerpc_lsa_OpenPolicy2 failed: %s\n",
136 nt_errstr(openpolicy.out.result));
137 goto done;
140 close_handle.in.handle = &handle;
141 close_handle.out.handle = &handle;
143 status = dcerpc_lsa_Close_r(lsa_handle, mem_ctx, &close_handle);
144 if (!NT_STATUS_IS_OK(status)) {
145 torture_comment(torture, "dcerpc_lsa_Close failed: %s\n",
146 nt_errstr(status));
147 goto done;
149 if (!NT_STATUS_IS_OK(close_handle.out.result)) {
150 torture_comment(torture, "dcerpc_lsa_Close failed: %s\n",
151 nt_errstr(close_handle.out.result));
152 goto done;
155 session2 = smbcli_session_init(cli->transport, mem_ctx, false, session_options);
156 if (session2 == NULL) {
157 torture_comment(torture, "smbcli_session_init failed\n");
158 goto done;
161 if (!(anon_creds = cli_credentials_init_anon(mem_ctx))) {
162 torture_comment(torture, "create_anon_creds failed\n");
163 goto done;
166 setup.in.sesskey = cli->transport->negotiate.sesskey;
167 setup.in.capabilities = cli->transport->negotiate.capabilities;
168 setup.in.workgroup = "";
169 setup.in.credentials = anon_creds;
170 setup.in.gensec_settings = lpcfg_gensec_settings(torture, torture->lp_ctx);
172 status = smb_composite_sesssetup(session2, &setup);
173 if (!NT_STATUS_IS_OK(status)) {
174 torture_comment(torture, "anon session setup failed: %s\n",
175 nt_errstr(status));
176 goto done;
178 session2->vuid = setup.out.vuid;
180 tmp = cli->tree->session;
181 cli->tree->session = session2;
183 status = dcerpc_lsa_OpenPolicy2_r(lsa_handle, mem_ctx, &openpolicy);
185 cli->tree->session = tmp;
186 talloc_free(lsa_pipe);
187 lsa_pipe = NULL;
189 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
190 torture_comment(torture, "dcerpc_lsa_OpenPolicy2 with wrong vuid gave %s, "
191 "expected NT_STATUS_INVALID_HANDLE\n",
192 nt_errstr(status));
193 goto done;
196 ret = true;
197 done:
198 talloc_free(mem_ctx);
199 return ret;
203 * Bind to lsa using a specific auth method
206 static bool bindtest(struct torture_context *tctx,
207 struct smbcli_state *cli,
208 struct cli_credentials *credentials,
209 uint8_t auth_type, uint8_t auth_level)
211 TALLOC_CTX *mem_ctx;
212 bool ret = false;
213 NTSTATUS status;
215 struct dcerpc_pipe *lsa_pipe;
216 struct dcerpc_binding_handle *lsa_handle;
217 struct lsa_ObjectAttribute objectattr;
218 struct lsa_OpenPolicy2 openpolicy;
219 struct lsa_QueryInfoPolicy query;
220 union lsa_PolicyInformation *info = NULL;
221 struct policy_handle handle;
222 struct lsa_Close close_handle;
224 if ((mem_ctx = talloc_init("bindtest")) == NULL) {
225 torture_comment(tctx, "talloc_init failed\n");
226 return false;
229 lsa_pipe = dcerpc_pipe_init(mem_ctx, tctx->ev);
230 if (lsa_pipe == NULL) {
231 torture_comment(tctx, "dcerpc_pipe_init failed\n");
232 goto done;
234 lsa_handle = lsa_pipe->binding_handle;
236 status = dcerpc_pipe_open_smb(lsa_pipe, cli->tree, "\\lsarpc");
237 if (!NT_STATUS_IS_OK(status)) {
238 torture_comment(tctx, "dcerpc_pipe_open_smb failed: %s\n",
239 nt_errstr(status));
240 goto done;
243 status = dcerpc_bind_auth(lsa_pipe, &ndr_table_lsarpc,
244 credentials, lpcfg_gensec_settings(tctx->lp_ctx, tctx->lp_ctx), auth_type, auth_level,
245 NULL);
246 if (!NT_STATUS_IS_OK(status)) {
247 torture_comment(tctx, "dcerpc_bind_auth failed: %s\n", nt_errstr(status));
248 goto done;
251 openpolicy.in.system_name =talloc_asprintf(
252 mem_ctx, "\\\\%s", dcerpc_server_name(lsa_pipe));
253 ZERO_STRUCT(objectattr);
254 openpolicy.in.attr = &objectattr;
255 openpolicy.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
256 openpolicy.out.handle = &handle;
258 status = dcerpc_lsa_OpenPolicy2_r(lsa_handle, mem_ctx, &openpolicy);
260 if (!NT_STATUS_IS_OK(status)) {
261 torture_comment(tctx, "dcerpc_lsa_OpenPolicy2 failed: %s\n",
262 nt_errstr(status));
263 goto done;
265 if (!NT_STATUS_IS_OK(openpolicy.out.result)) {
266 torture_comment(tctx, "dcerpc_lsa_OpenPolicy2 failed: %s\n",
267 nt_errstr(openpolicy.out.result));
268 goto done;
271 query.in.handle = &handle;
272 query.in.level = LSA_POLICY_INFO_DOMAIN;
273 query.out.info = &info;
275 status = dcerpc_lsa_QueryInfoPolicy_r(lsa_handle, mem_ctx, &query);
276 if (!NT_STATUS_IS_OK(status)) {
277 torture_comment(tctx, "dcerpc_lsa_QueryInfoPolicy failed: %s\n",
278 nt_errstr(status));
279 goto done;
281 if (!NT_STATUS_IS_OK(query.out.result)) {
282 torture_comment(tctx, "dcerpc_lsa_QueryInfoPolicy failed: %s\n",
283 nt_errstr(query.out.result));
284 goto done;
287 close_handle.in.handle = &handle;
288 close_handle.out.handle = &handle;
290 status = dcerpc_lsa_Close_r(lsa_handle, mem_ctx, &close_handle);
291 if (!NT_STATUS_IS_OK(status)) {
292 torture_comment(tctx, "dcerpc_lsa_Close failed: %s\n",
293 nt_errstr(status));
294 goto done;
296 if (!NT_STATUS_IS_OK(close_handle.out.result)) {
297 torture_comment(tctx, "dcerpc_lsa_Close failed: %s\n",
298 nt_errstr(close_handle.out.result));
299 goto done;
303 ret = true;
304 done:
305 talloc_free(mem_ctx);
306 return ret;
310 * test authenticated RPC binds with the variants Samba3 does support
313 static bool torture_bind_samba3(struct torture_context *torture)
315 TALLOC_CTX *mem_ctx;
316 NTSTATUS status;
317 bool ret = false;
318 struct smbcli_state *cli;
319 struct smbcli_options options;
320 struct smbcli_session_options session_options;
322 mem_ctx = talloc_init("torture_bind_authcontext");
324 if (mem_ctx == NULL) {
325 torture_comment(torture, "talloc_init failed\n");
326 return false;
329 lpcfg_smbcli_options(torture->lp_ctx, &options);
330 lpcfg_smbcli_session_options(torture->lp_ctx, &session_options);
332 status = smbcli_full_connection(mem_ctx, &cli,
333 torture_setting_string(torture, "host", NULL),
334 lpcfg_smb_ports(torture->lp_ctx),
335 "IPC$", NULL,
336 lpcfg_socket_options(torture->lp_ctx),
337 cmdline_credentials,
338 lpcfg_resolve_context(torture->lp_ctx),
339 torture->ev, &options, &session_options,
340 lpcfg_gensec_settings(torture, torture->lp_ctx));
341 if (!NT_STATUS_IS_OK(status)) {
342 torture_comment(torture, "smbcli_full_connection failed: %s\n",
343 nt_errstr(status));
344 goto done;
347 ret = true;
349 ret &= bindtest(torture, cli, cmdline_credentials, DCERPC_AUTH_TYPE_NTLMSSP,
350 DCERPC_AUTH_LEVEL_INTEGRITY);
351 ret &= bindtest(torture, cli, cmdline_credentials, DCERPC_AUTH_TYPE_NTLMSSP,
352 DCERPC_AUTH_LEVEL_PRIVACY);
353 ret &= bindtest(torture, cli, cmdline_credentials, DCERPC_AUTH_TYPE_SPNEGO,
354 DCERPC_AUTH_LEVEL_INTEGRITY);
355 ret &= bindtest(torture, cli, cmdline_credentials, DCERPC_AUTH_TYPE_SPNEGO,
356 DCERPC_AUTH_LEVEL_PRIVACY);
358 done:
359 talloc_free(mem_ctx);
360 return ret;
364 * Lookup or create a user and return all necessary info
367 static bool get_usr_handle(struct torture_context *tctx,
368 struct smbcli_state *cli,
369 TALLOC_CTX *mem_ctx,
370 struct cli_credentials *admin_creds,
371 uint8_t auth_type,
372 uint8_t auth_level,
373 const char *username,
374 char **domain,
375 struct dcerpc_pipe **result_pipe,
376 struct policy_handle **result_handle,
377 struct dom_sid **sid_p)
379 struct dcerpc_pipe *samr_pipe;
380 struct dcerpc_binding_handle *samr_handle;
381 NTSTATUS status;
382 struct policy_handle conn_handle;
383 struct policy_handle domain_handle;
384 struct policy_handle *user_handle;
385 struct samr_Connect2 conn;
386 struct samr_EnumDomains enumdom;
387 uint32_t resume_handle = 0;
388 uint32_t num_entries = 0;
389 struct samr_SamArray *sam = NULL;
390 struct samr_LookupDomain l;
391 struct dom_sid2 *sid = NULL;
392 int dom_idx;
393 struct lsa_String domain_name;
394 struct lsa_String user_name;
395 struct samr_OpenDomain o;
396 struct samr_CreateUser2 c;
397 uint32_t user_rid,access_granted;
399 samr_pipe = dcerpc_pipe_init(mem_ctx, tctx->ev);
400 torture_assert(tctx, samr_pipe, "dcerpc_pipe_init failed");
402 samr_handle = samr_pipe->binding_handle;
404 torture_assert_ntstatus_ok(tctx,
405 dcerpc_pipe_open_smb(samr_pipe, cli->tree, "\\samr"),
406 "dcerpc_pipe_open_smb failed");
408 if (admin_creds != NULL) {
409 torture_assert_ntstatus_ok(tctx,
410 dcerpc_bind_auth(samr_pipe, &ndr_table_samr,
411 admin_creds, lpcfg_gensec_settings(tctx->lp_ctx, tctx->lp_ctx), auth_type, auth_level,
412 NULL),
413 "dcerpc_bind_auth failed");
414 } else {
415 /* We must have an authenticated SMB connection */
416 torture_assert_ntstatus_ok(tctx,
417 dcerpc_bind_auth_none(samr_pipe, &ndr_table_samr),
418 "dcerpc_bind_auth_none failed");
421 conn.in.system_name = talloc_asprintf(
422 mem_ctx, "\\\\%s", dcerpc_server_name(samr_pipe));
423 conn.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
424 conn.out.connect_handle = &conn_handle;
426 torture_assert_ntstatus_ok(tctx,
427 dcerpc_samr_Connect2_r(samr_handle, mem_ctx, &conn),
428 "samr_Connect2 failed");
429 torture_assert_ntstatus_ok(tctx, conn.out.result,
430 "samr_Connect2 failed");
432 enumdom.in.connect_handle = &conn_handle;
433 enumdom.in.resume_handle = &resume_handle;
434 enumdom.in.buf_size = (uint32_t)-1;
435 enumdom.out.resume_handle = &resume_handle;
436 enumdom.out.num_entries = &num_entries;
437 enumdom.out.sam = &sam;
439 torture_assert_ntstatus_ok(tctx,
440 dcerpc_samr_EnumDomains_r(samr_handle, mem_ctx, &enumdom),
441 "samr_EnumDomains failed");
442 torture_assert_ntstatus_ok(tctx, enumdom.out.result,
443 "samr_EnumDomains failed");
445 torture_assert_int_equal(tctx, *enumdom.out.num_entries, 2,
446 "samr_EnumDomains returned unexpected num_entries");
448 dom_idx = strequal(sam->entries[0].name.string,
449 "builtin") ? 1:0;
451 l.in.connect_handle = &conn_handle;
452 domain_name.string = sam->entries[dom_idx].name.string;
453 *domain = talloc_strdup(mem_ctx, domain_name.string);
454 l.in.domain_name = &domain_name;
455 l.out.sid = &sid;
457 torture_assert_ntstatus_ok(tctx,
458 dcerpc_samr_LookupDomain_r(samr_handle, mem_ctx, &l),
459 "samr_LookupDomain failed");
460 torture_assert_ntstatus_ok(tctx, l.out.result,
461 "samr_LookupDomain failed");
463 o.in.connect_handle = &conn_handle;
464 o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
465 o.in.sid = *l.out.sid;
466 o.out.domain_handle = &domain_handle;
468 torture_assert_ntstatus_ok(tctx,
469 dcerpc_samr_OpenDomain_r(samr_handle, mem_ctx, &o),
470 "samr_OpenDomain failed");
471 torture_assert_ntstatus_ok(tctx, o.out.result,
472 "samr_OpenDomain failed");
474 c.in.domain_handle = &domain_handle;
475 user_name.string = username;
476 c.in.account_name = &user_name;
477 c.in.acct_flags = ACB_NORMAL;
478 c.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
479 user_handle = talloc(mem_ctx, struct policy_handle);
480 c.out.user_handle = user_handle;
481 c.out.access_granted = &access_granted;
482 c.out.rid = &user_rid;
484 torture_assert_ntstatus_ok(tctx,
485 dcerpc_samr_CreateUser2_r(samr_handle, mem_ctx, &c),
486 "samr_CreateUser2 failed");
488 if (NT_STATUS_EQUAL(c.out.result, NT_STATUS_USER_EXISTS)) {
489 struct samr_LookupNames ln;
490 struct samr_OpenUser ou;
491 struct samr_Ids rids, types;
493 ln.in.domain_handle = &domain_handle;
494 ln.in.num_names = 1;
495 ln.in.names = &user_name;
496 ln.out.rids = &rids;
497 ln.out.types = &types;
499 torture_assert_ntstatus_ok(tctx,
500 dcerpc_samr_LookupNames_r(samr_handle, mem_ctx, &ln),
501 "samr_LookupNames failed");
502 torture_assert_ntstatus_ok(tctx, ln.out.result,
503 "samr_LookupNames failed");
505 ou.in.domain_handle = &domain_handle;
506 ou.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
507 user_rid = ou.in.rid = ln.out.rids->ids[0];
508 ou.out.user_handle = user_handle;
510 torture_assert_ntstatus_ok(tctx,
511 dcerpc_samr_OpenUser_r(samr_handle, mem_ctx, &ou),
512 "samr_OpenUser failed");
513 status = ou.out.result;
514 } else {
515 status = c.out.result;
518 torture_assert_ntstatus_ok(tctx, status,
519 "samr_CreateUser failed");
521 *result_pipe = samr_pipe;
522 *result_handle = user_handle;
523 if (sid_p != NULL) {
524 *sid_p = dom_sid_add_rid(mem_ctx, *l.out.sid, user_rid);
526 return true;
531 * Create a test user
534 static bool create_user(struct torture_context *tctx,
535 TALLOC_CTX *mem_ctx, struct smbcli_state *cli,
536 struct cli_credentials *admin_creds,
537 const char *username, const char *password,
538 char **domain_name,
539 struct dom_sid **user_sid)
541 TALLOC_CTX *tmp_ctx;
542 NTSTATUS status;
543 struct dcerpc_pipe *samr_pipe;
544 struct dcerpc_binding_handle *samr_handle;
545 struct policy_handle *wks_handle;
546 bool ret = false;
548 if (!(tmp_ctx = talloc_new(mem_ctx))) {
549 torture_comment(tctx, "talloc_init failed\n");
550 return false;
553 ret = get_usr_handle(tctx, cli, tmp_ctx, admin_creds,
554 DCERPC_AUTH_TYPE_NTLMSSP,
555 DCERPC_AUTH_LEVEL_INTEGRITY,
556 username, domain_name, &samr_pipe, &wks_handle,
557 user_sid);
558 if (ret == false) {
559 torture_comment(tctx, "get_usr_handle failed\n");
560 goto done;
562 samr_handle = samr_pipe->binding_handle;
565 struct samr_SetUserInfo2 sui2;
566 struct samr_SetUserInfo sui;
567 struct samr_QueryUserInfo qui;
568 union samr_UserInfo u_info;
569 union samr_UserInfo *info;
570 DATA_BLOB session_key;
573 ZERO_STRUCT(u_info);
574 encode_pw_buffer(u_info.info23.password.data, password,
575 STR_UNICODE);
577 status = dcerpc_fetch_session_key(samr_pipe, &session_key);
578 if (!NT_STATUS_IS_OK(status)) {
579 torture_comment(tctx, "dcerpc_fetch_session_key failed\n");
580 goto done;
582 arcfour_crypt_blob(u_info.info23.password.data, 516,
583 &session_key);
584 u_info.info23.info.password_expired = 0;
585 u_info.info23.info.fields_present = SAMR_FIELD_NT_PASSWORD_PRESENT |
586 SAMR_FIELD_LM_PASSWORD_PRESENT |
587 SAMR_FIELD_EXPIRED_FLAG;
588 sui2.in.user_handle = wks_handle;
589 sui2.in.info = &u_info;
590 sui2.in.level = 23;
592 status = dcerpc_samr_SetUserInfo2_r(samr_handle, tmp_ctx, &sui2);
593 if (!NT_STATUS_IS_OK(status)) {
594 torture_comment(tctx, "samr_SetUserInfo(23) failed: %s\n",
595 nt_errstr(status));
596 goto done;
598 if (!NT_STATUS_IS_OK(sui2.out.result)) {
599 torture_comment(tctx, "samr_SetUserInfo(23) failed: %s\n",
600 nt_errstr(sui2.out.result));
601 goto done;
604 u_info.info16.acct_flags = ACB_NORMAL;
605 sui.in.user_handle = wks_handle;
606 sui.in.info = &u_info;
607 sui.in.level = 16;
609 status = dcerpc_samr_SetUserInfo_r(samr_handle, tmp_ctx, &sui);
610 if (!NT_STATUS_IS_OK(status) || !NT_STATUS_IS_OK(sui.out.result)) {
611 torture_comment(tctx, "samr_SetUserInfo(16) failed\n");
612 goto done;
615 qui.in.user_handle = wks_handle;
616 qui.in.level = 21;
617 qui.out.info = &info;
619 status = dcerpc_samr_QueryUserInfo_r(samr_handle, tmp_ctx, &qui);
620 if (!NT_STATUS_IS_OK(status) || !NT_STATUS_IS_OK(qui.out.result)) {
621 torture_comment(tctx, "samr_QueryUserInfo(21) failed\n");
622 goto done;
625 info->info21.allow_password_change = 0;
626 info->info21.force_password_change = 0;
627 info->info21.account_name.string = NULL;
628 info->info21.rid = 0;
629 info->info21.acct_expiry = 0;
630 info->info21.fields_present = 0x81827fa; /* copy usrmgr.exe */
632 u_info.info21 = info->info21;
633 sui.in.user_handle = wks_handle;
634 sui.in.info = &u_info;
635 sui.in.level = 21;
637 status = dcerpc_samr_SetUserInfo_r(samr_handle, tmp_ctx, &sui);
638 if (!NT_STATUS_IS_OK(status) || !NT_STATUS_IS_OK(sui.out.result)) {
639 torture_comment(tctx, "samr_SetUserInfo(21) failed\n");
640 goto done;
644 *domain_name= talloc_steal(mem_ctx, *domain_name);
645 *user_sid = talloc_steal(mem_ctx, *user_sid);
646 ret = true;
647 done:
648 talloc_free(tmp_ctx);
649 return ret;
653 * Delete a test user
656 static bool delete_user(struct torture_context *tctx,
657 struct smbcli_state *cli,
658 struct cli_credentials *admin_creds,
659 const char *username)
661 TALLOC_CTX *mem_ctx;
662 NTSTATUS status;
663 char *dom_name;
664 struct dcerpc_pipe *samr_pipe;
665 struct dcerpc_binding_handle *samr_handle;
666 struct policy_handle *user_handle;
667 bool ret = false;
669 if ((mem_ctx = talloc_init("leave")) == NULL) {
670 torture_comment(tctx, "talloc_init failed\n");
671 return false;
674 ret = get_usr_handle(tctx, cli, mem_ctx, admin_creds,
675 DCERPC_AUTH_TYPE_NTLMSSP,
676 DCERPC_AUTH_LEVEL_INTEGRITY,
677 username, &dom_name, &samr_pipe,
678 &user_handle, NULL);
679 if (ret == false) {
680 torture_comment(tctx, "get_wks_handle failed\n");
681 goto done;
683 samr_handle = samr_pipe->binding_handle;
686 struct samr_DeleteUser d;
688 d.in.user_handle = user_handle;
689 d.out.user_handle = user_handle;
691 status = dcerpc_samr_DeleteUser_r(samr_handle, mem_ctx, &d);
692 if (!NT_STATUS_IS_OK(status)) {
693 torture_comment(tctx, "samr_DeleteUser failed %s\n", nt_errstr(status));
694 goto done;
696 if (!NT_STATUS_IS_OK(d.out.result)) {
697 torture_comment(tctx, "samr_DeleteUser failed %s\n", nt_errstr(d.out.result));
698 goto done;
703 ret = true;
705 done:
706 talloc_free(mem_ctx);
707 return ret;
711 * Do a Samba3-style join
714 static bool join3(struct torture_context *tctx,
715 struct smbcli_state *cli,
716 bool use_level25,
717 struct cli_credentials *admin_creds,
718 struct cli_credentials *wks_creds)
720 TALLOC_CTX *mem_ctx;
721 NTSTATUS status;
722 char *dom_name;
723 struct dcerpc_pipe *samr_pipe;
724 struct dcerpc_binding_handle *samr_handle;
725 struct policy_handle *wks_handle;
726 bool ret = false;
727 NTTIME last_password_change;
729 if ((mem_ctx = talloc_init("join3")) == NULL) {
730 torture_comment(tctx, "talloc_init failed\n");
731 return false;
734 ret = get_usr_handle(
735 tctx, cli, mem_ctx, admin_creds,
736 DCERPC_AUTH_TYPE_NTLMSSP,
737 DCERPC_AUTH_LEVEL_PRIVACY,
738 talloc_asprintf(mem_ctx, "%s$",
739 cli_credentials_get_workstation(wks_creds)),
740 &dom_name, &samr_pipe, &wks_handle, NULL);
741 if (ret == false) {
742 torture_comment(tctx, "get_wks_handle failed\n");
743 goto done;
745 samr_handle = samr_pipe->binding_handle;
748 struct samr_QueryUserInfo q;
749 union samr_UserInfo *info;
751 q.in.user_handle = wks_handle;
752 q.in.level = 21;
753 q.out.info = &info;
755 status = dcerpc_samr_QueryUserInfo_r(samr_handle, mem_ctx, &q);
756 if (!NT_STATUS_IS_OK(status)) {
757 torture_warning(tctx, "QueryUserInfo failed: %s\n",
758 nt_errstr(status));
759 goto done;
761 if (!NT_STATUS_IS_OK(q.out.result)) {
762 torture_warning(tctx, "QueryUserInfo failed: %s\n",
763 nt_errstr(q.out.result));
764 goto done;
768 last_password_change = info->info21.last_password_change;
771 cli_credentials_set_domain(wks_creds, dom_name, CRED_SPECIFIED);
773 if (use_level25) {
774 struct samr_SetUserInfo2 sui2;
775 union samr_UserInfo u_info;
776 struct samr_UserInfo21 *i21 = &u_info.info25.info;
777 DATA_BLOB session_key;
778 DATA_BLOB confounded_session_key = data_blob_talloc(
779 mem_ctx, NULL, 16);
780 struct MD5Context ctx;
781 uint8_t confounder[16];
783 ZERO_STRUCT(u_info);
785 i21->full_name.string = talloc_asprintf(
786 mem_ctx, "%s$",
787 cli_credentials_get_workstation(wks_creds));
788 i21->acct_flags = ACB_WSTRUST;
789 i21->fields_present = SAMR_FIELD_FULL_NAME |
790 SAMR_FIELD_ACCT_FLAGS | SAMR_FIELD_NT_PASSWORD_PRESENT;
791 /* this would break the test result expectations
792 i21->fields_present |= SAMR_FIELD_EXPIRED_FLAG;
793 i21->password_expired = 1;
796 encode_pw_buffer(u_info.info25.password.data,
797 cli_credentials_get_password(wks_creds),
798 STR_UNICODE);
799 status = dcerpc_fetch_session_key(samr_pipe, &session_key);
800 if (!NT_STATUS_IS_OK(status)) {
801 torture_comment(tctx, "dcerpc_fetch_session_key failed: %s\n",
802 nt_errstr(status));
803 goto done;
805 generate_random_buffer((uint8_t *)confounder, 16);
807 MD5Init(&ctx);
808 MD5Update(&ctx, confounder, 16);
809 MD5Update(&ctx, session_key.data, session_key.length);
810 MD5Final(confounded_session_key.data, &ctx);
812 arcfour_crypt_blob(u_info.info25.password.data, 516,
813 &confounded_session_key);
814 memcpy(&u_info.info25.password.data[516], confounder, 16);
816 sui2.in.user_handle = wks_handle;
817 sui2.in.level = 25;
818 sui2.in.info = &u_info;
820 status = dcerpc_samr_SetUserInfo2_r(samr_handle, mem_ctx, &sui2);
821 if (!NT_STATUS_IS_OK(status)) {
822 torture_comment(tctx, "samr_SetUserInfo2(25) failed: %s\n",
823 nt_errstr(status));
824 goto done;
826 if (!NT_STATUS_IS_OK(sui2.out.result)) {
827 torture_comment(tctx, "samr_SetUserInfo2(25) failed: %s\n",
828 nt_errstr(sui2.out.result));
829 goto done;
831 } else {
832 struct samr_SetUserInfo2 sui2;
833 struct samr_SetUserInfo sui;
834 union samr_UserInfo u_info;
835 DATA_BLOB session_key;
837 encode_pw_buffer(u_info.info24.password.data,
838 cli_credentials_get_password(wks_creds),
839 STR_UNICODE);
840 /* just to make this test pass */
841 u_info.info24.password_expired = 1;
843 status = dcerpc_fetch_session_key(samr_pipe, &session_key);
844 if (!NT_STATUS_IS_OK(status)) {
845 torture_comment(tctx, "dcerpc_fetch_session_key failed\n");
846 goto done;
848 arcfour_crypt_blob(u_info.info24.password.data, 516,
849 &session_key);
850 sui2.in.user_handle = wks_handle;
851 sui2.in.info = &u_info;
852 sui2.in.level = 24;
854 status = dcerpc_samr_SetUserInfo2_r(samr_handle, mem_ctx, &sui2);
855 if (!NT_STATUS_IS_OK(status)) {
856 torture_comment(tctx, "samr_SetUserInfo(24) failed: %s\n",
857 nt_errstr(status));
858 goto done;
860 if (!NT_STATUS_IS_OK(sui2.out.result)) {
861 torture_comment(tctx, "samr_SetUserInfo(24) failed: %s\n",
862 nt_errstr(sui2.out.result));
863 goto done;
866 u_info.info16.acct_flags = ACB_WSTRUST;
867 sui.in.user_handle = wks_handle;
868 sui.in.info = &u_info;
869 sui.in.level = 16;
871 status = dcerpc_samr_SetUserInfo_r(samr_handle, mem_ctx, &sui);
872 if (!NT_STATUS_IS_OK(status) || !NT_STATUS_IS_OK(sui.out.result)) {
873 torture_comment(tctx, "samr_SetUserInfo(16) failed\n");
874 goto done;
879 struct samr_QueryUserInfo q;
880 union samr_UserInfo *info;
882 q.in.user_handle = wks_handle;
883 q.in.level = 21;
884 q.out.info = &info;
886 status = dcerpc_samr_QueryUserInfo_r(samr_handle, mem_ctx, &q);
887 if (!NT_STATUS_IS_OK(status)) {
888 torture_warning(tctx, "QueryUserInfo failed: %s\n",
889 nt_errstr(status));
890 goto done;
892 if (!NT_STATUS_IS_OK(q.out.result)) {
893 torture_warning(tctx, "QueryUserInfo failed: %s\n",
894 nt_errstr(q.out.result));
895 goto done;
898 if (use_level25) {
899 if (last_password_change
900 == info->info21.last_password_change) {
901 torture_warning(tctx, "last_password_change unchanged "
902 "during join, level25 must change "
903 "it\n");
904 goto done;
907 else {
908 if (last_password_change
909 != info->info21.last_password_change) {
910 torture_warning(tctx, "last_password_change changed "
911 "during join, level24 doesn't "
912 "change it\n");
913 goto done;
918 ret = true;
920 done:
921 talloc_free(mem_ctx);
922 return ret;
926 * Do a ReqChallenge/Auth2 and get the wks creds
929 static bool auth2(struct torture_context *tctx,
930 struct smbcli_state *cli,
931 struct cli_credentials *wks_cred)
933 TALLOC_CTX *mem_ctx;
934 struct dcerpc_pipe *net_pipe;
935 struct dcerpc_binding_handle *net_handle;
936 bool result = false;
937 NTSTATUS status;
938 struct netr_ServerReqChallenge r;
939 struct netr_Credential netr_cli_creds;
940 struct netr_Credential netr_srv_creds;
941 uint32_t negotiate_flags;
942 struct netr_ServerAuthenticate2 a;
943 struct netlogon_creds_CredentialState *creds_state;
944 struct netr_Credential netr_cred;
945 struct samr_Password mach_pw;
947 mem_ctx = talloc_new(NULL);
948 if (mem_ctx == NULL) {
949 torture_comment(tctx, "talloc_new failed\n");
950 return false;
953 net_pipe = dcerpc_pipe_init(mem_ctx, tctx->ev);
954 if (net_pipe == NULL) {
955 torture_comment(tctx, "dcerpc_pipe_init failed\n");
956 goto done;
958 net_handle = net_pipe->binding_handle;
960 status = dcerpc_pipe_open_smb(net_pipe, cli->tree, "\\netlogon");
961 if (!NT_STATUS_IS_OK(status)) {
962 torture_comment(tctx, "dcerpc_pipe_open_smb failed: %s\n",
963 nt_errstr(status));
964 goto done;
967 status = dcerpc_bind_auth_none(net_pipe, &ndr_table_netlogon);
968 if (!NT_STATUS_IS_OK(status)) {
969 torture_comment(tctx, "dcerpc_bind_auth_none failed: %s\n",
970 nt_errstr(status));
971 goto done;
974 r.in.computer_name = cli_credentials_get_workstation(wks_cred);
975 r.in.server_name = talloc_asprintf(
976 mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
977 if (r.in.server_name == NULL) {
978 torture_comment(tctx, "talloc_asprintf failed\n");
979 goto done;
981 generate_random_buffer(netr_cli_creds.data,
982 sizeof(netr_cli_creds.data));
983 r.in.credentials = &netr_cli_creds;
984 r.out.return_credentials = &netr_srv_creds;
986 status = dcerpc_netr_ServerReqChallenge_r(net_handle, mem_ctx, &r);
987 if (!NT_STATUS_IS_OK(status)) {
988 torture_comment(tctx, "netr_ServerReqChallenge failed: %s\n",
989 nt_errstr(status));
990 goto done;
992 if (!NT_STATUS_IS_OK(r.out.result)) {
993 torture_comment(tctx, "netr_ServerReqChallenge failed: %s\n",
994 nt_errstr(r.out.result));
995 goto done;
998 negotiate_flags = NETLOGON_NEG_AUTH2_FLAGS;
999 E_md4hash(cli_credentials_get_password(wks_cred), mach_pw.hash);
1001 a.in.server_name = talloc_asprintf(
1002 mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
1003 a.in.account_name = talloc_asprintf(
1004 mem_ctx, "%s$", cli_credentials_get_workstation(wks_cred));
1005 a.in.computer_name = cli_credentials_get_workstation(wks_cred);
1006 a.in.secure_channel_type = SEC_CHAN_WKSTA;
1007 a.in.negotiate_flags = &negotiate_flags;
1008 a.out.negotiate_flags = &negotiate_flags;
1009 a.in.credentials = &netr_cred;
1010 a.out.return_credentials = &netr_cred;
1012 creds_state = netlogon_creds_client_init(mem_ctx,
1013 a.in.account_name,
1014 a.in.computer_name,
1015 r.in.credentials,
1016 r.out.return_credentials, &mach_pw,
1017 &netr_cred, negotiate_flags);
1018 torture_assert(tctx, (creds_state != NULL), "memory allocation failed");
1020 status = dcerpc_netr_ServerAuthenticate2_r(net_handle, mem_ctx, &a);
1021 if (!NT_STATUS_IS_OK(status)) {
1022 torture_comment(tctx, "netr_ServerServerAuthenticate2 failed: %s\n",
1023 nt_errstr(status));
1024 goto done;
1026 if (!NT_STATUS_IS_OK(a.out.result)) {
1027 torture_comment(tctx, "netr_ServerServerAuthenticate2 failed: %s\n",
1028 nt_errstr(a.out.result));
1029 goto done;
1032 if (!netlogon_creds_client_check(creds_state, a.out.return_credentials)) {
1033 torture_comment(tctx, "creds_client_check failed\n");
1034 goto done;
1037 cli_credentials_set_netlogon_creds(wks_cred, creds_state);
1039 result = true;
1041 done:
1042 talloc_free(mem_ctx);
1043 return result;
1047 * Do a couple of schannel protected Netlogon ops: Interactive and Network
1048 * login, and change the wks password
1051 static bool schan(struct torture_context *tctx,
1052 struct smbcli_state *cli,
1053 struct cli_credentials *wks_creds,
1054 struct cli_credentials *user_creds)
1056 TALLOC_CTX *mem_ctx;
1057 NTSTATUS status;
1058 bool ret = false;
1059 struct dcerpc_pipe *net_pipe;
1060 struct dcerpc_binding_handle *net_handle;
1061 int i;
1063 mem_ctx = talloc_new(NULL);
1064 if (mem_ctx == NULL) {
1065 torture_comment(tctx, "talloc_new failed\n");
1066 return false;
1069 net_pipe = dcerpc_pipe_init(mem_ctx, tctx->ev);
1070 if (net_pipe == NULL) {
1071 torture_comment(tctx, "dcerpc_pipe_init failed\n");
1072 goto done;
1074 net_handle = net_pipe->binding_handle;
1076 status = dcerpc_pipe_open_smb(net_pipe, cli->tree, "\\netlogon");
1077 if (!NT_STATUS_IS_OK(status)) {
1078 torture_comment(tctx, "dcerpc_pipe_open_smb failed: %s\n",
1079 nt_errstr(status));
1080 goto done;
1083 #if 0
1084 net_pipe->conn->flags |= DCERPC_DEBUG_PRINT_IN |
1085 DCERPC_DEBUG_PRINT_OUT;
1086 #endif
1087 #if 1
1088 net_pipe->conn->flags |= (DCERPC_SIGN | DCERPC_SEAL);
1089 status = dcerpc_bind_auth(net_pipe, &ndr_table_netlogon,
1090 wks_creds, lpcfg_gensec_settings(tctx->lp_ctx, tctx->lp_ctx), DCERPC_AUTH_TYPE_SCHANNEL,
1091 DCERPC_AUTH_LEVEL_PRIVACY,
1092 NULL);
1093 #else
1094 status = dcerpc_bind_auth_none(net_pipe, &ndr_table_netlogon);
1095 #endif
1096 if (!NT_STATUS_IS_OK(status)) {
1097 torture_comment(tctx, "schannel bind failed: %s\n", nt_errstr(status));
1098 goto done;
1102 for (i=2; i<4; i++) {
1103 int flags;
1104 DATA_BLOB chal, nt_resp, lm_resp, names_blob, session_key;
1105 struct netlogon_creds_CredentialState *creds_state;
1106 struct netr_Authenticator netr_auth, netr_auth2;
1107 struct netr_NetworkInfo ninfo;
1108 struct netr_PasswordInfo pinfo;
1109 struct netr_LogonSamLogon r;
1110 union netr_LogonLevel logon;
1111 union netr_Validation validation;
1112 uint8_t authoritative;
1113 struct netr_Authenticator return_authenticator;
1115 flags = CLI_CRED_LANMAN_AUTH | CLI_CRED_NTLM_AUTH |
1116 CLI_CRED_NTLMv2_AUTH;
1118 chal = data_blob_talloc(mem_ctx, NULL, 8);
1119 if (chal.data == NULL) {
1120 torture_comment(tctx, "data_blob_talloc failed\n");
1121 goto done;
1124 generate_random_buffer(chal.data, chal.length);
1125 names_blob = NTLMv2_generate_names_blob(
1126 mem_ctx,
1127 cli_credentials_get_workstation(user_creds),
1128 cli_credentials_get_domain(user_creds));
1129 status = cli_credentials_get_ntlm_response(
1130 user_creds, mem_ctx, &flags, chal, names_blob,
1131 &lm_resp, &nt_resp, NULL, NULL);
1132 if (!NT_STATUS_IS_OK(status)) {
1133 torture_comment(tctx, "cli_credentials_get_ntlm_response failed:"
1134 " %s\n", nt_errstr(status));
1135 goto done;
1138 creds_state = cli_credentials_get_netlogon_creds(wks_creds);
1139 netlogon_creds_client_authenticator(creds_state, &netr_auth);
1141 ninfo.identity_info.account_name.string =
1142 cli_credentials_get_username(user_creds);
1143 ninfo.identity_info.domain_name.string =
1144 cli_credentials_get_domain(user_creds);
1145 ninfo.identity_info.parameter_control = 0;
1146 ninfo.identity_info.logon_id_low = 0;
1147 ninfo.identity_info.logon_id_high = 0;
1148 ninfo.identity_info.workstation.string =
1149 cli_credentials_get_workstation(user_creds);
1150 memcpy(ninfo.challenge, chal.data, sizeof(ninfo.challenge));
1151 ninfo.nt.length = nt_resp.length;
1152 ninfo.nt.data = nt_resp.data;
1153 ninfo.lm.length = lm_resp.length;
1154 ninfo.lm.data = lm_resp.data;
1156 logon.network = &ninfo;
1158 r.in.server_name = talloc_asprintf(
1159 mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
1160 ZERO_STRUCT(netr_auth2);
1161 r.in.computer_name =
1162 cli_credentials_get_workstation(wks_creds);
1163 r.in.credential = &netr_auth;
1164 r.in.return_authenticator = &netr_auth2;
1165 r.in.logon_level = 2;
1166 r.in.validation_level = i;
1167 r.in.logon = &logon;
1168 r.out.validation = &validation;
1169 r.out.authoritative = &authoritative;
1170 r.out.return_authenticator = &return_authenticator;
1172 status = dcerpc_netr_LogonSamLogon_r(net_handle, mem_ctx, &r);
1173 if (!NT_STATUS_IS_OK(status)) {
1174 torture_comment(tctx, "netr_LogonSamLogon failed: %s\n",
1175 nt_errstr(status));
1176 goto done;
1178 if (!NT_STATUS_IS_OK(r.out.result)) {
1179 torture_comment(tctx, "netr_LogonSamLogon failed: %s\n",
1180 nt_errstr(r.out.result));
1181 goto done;
1184 if ((r.out.return_authenticator == NULL) ||
1185 (!netlogon_creds_client_check(creds_state,
1186 &r.out.return_authenticator->cred))) {
1187 torture_comment(tctx, "Credentials check failed!\n");
1188 goto done;
1191 netlogon_creds_client_authenticator(creds_state, &netr_auth);
1193 pinfo.identity_info = ninfo.identity_info;
1194 ZERO_STRUCT(pinfo.lmpassword.hash);
1195 E_md4hash(cli_credentials_get_password(user_creds),
1196 pinfo.ntpassword.hash);
1197 session_key = data_blob_talloc(mem_ctx,
1198 creds_state->session_key, 16);
1199 arcfour_crypt_blob(pinfo.ntpassword.hash,
1200 sizeof(pinfo.ntpassword.hash),
1201 &session_key);
1203 logon.password = &pinfo;
1205 r.in.logon_level = 1;
1206 r.in.logon = &logon;
1207 r.out.return_authenticator = &return_authenticator;
1209 status = dcerpc_netr_LogonSamLogon_r(net_handle, mem_ctx, &r);
1210 if (!NT_STATUS_IS_OK(status)) {
1211 torture_comment(tctx, "netr_LogonSamLogon failed: %s\n",
1212 nt_errstr(status));
1213 goto done;
1215 if (!NT_STATUS_IS_OK(r.out.result)) {
1216 torture_comment(tctx, "netr_LogonSamLogon failed: %s\n",
1217 nt_errstr(r.out.result));
1218 goto done;
1221 if ((r.out.return_authenticator == NULL) ||
1222 (!netlogon_creds_client_check(creds_state,
1223 &r.out.return_authenticator->cred))) {
1224 torture_comment(tctx, "Credentials check failed!\n");
1225 goto done;
1230 struct netr_ServerPasswordSet s;
1231 char *password = generate_random_password(wks_creds, 8, 255);
1232 struct netlogon_creds_CredentialState *creds_state;
1233 struct netr_Authenticator credential, return_authenticator;
1234 struct samr_Password new_password;
1236 s.in.server_name = talloc_asprintf(
1237 mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
1238 s.in.computer_name = cli_credentials_get_workstation(wks_creds);
1239 s.in.account_name = talloc_asprintf(
1240 mem_ctx, "%s$", s.in.computer_name);
1241 s.in.secure_channel_type = SEC_CHAN_WKSTA;
1242 s.in.credential = &credential;
1243 s.in.new_password = &new_password;
1244 s.out.return_authenticator = &return_authenticator;
1246 E_md4hash(password, new_password.hash);
1248 creds_state = cli_credentials_get_netlogon_creds(wks_creds);
1249 netlogon_creds_des_encrypt(creds_state, &new_password);
1250 netlogon_creds_client_authenticator(creds_state, &credential);
1252 status = dcerpc_netr_ServerPasswordSet_r(net_handle, mem_ctx, &s);
1253 if (!NT_STATUS_IS_OK(status)) {
1254 torture_comment(tctx, "ServerPasswordSet - %s\n", nt_errstr(status));
1255 goto done;
1257 if (!NT_STATUS_IS_OK(s.out.result)) {
1258 torture_comment(tctx, "ServerPasswordSet - %s\n", nt_errstr(s.out.result));
1259 goto done;
1262 if (!netlogon_creds_client_check(creds_state,
1263 &s.out.return_authenticator->cred)) {
1264 torture_comment(tctx, "Credential chaining failed\n");
1267 cli_credentials_set_password(wks_creds, password,
1268 CRED_SPECIFIED);
1271 ret = true;
1272 done:
1273 talloc_free(mem_ctx);
1274 return ret;
1278 * Delete the wks account again
1281 static bool leave(struct torture_context *tctx,
1282 struct smbcli_state *cli,
1283 struct cli_credentials *admin_creds,
1284 struct cli_credentials *wks_creds)
1286 char *wks_name = talloc_asprintf(
1287 NULL, "%s$", cli_credentials_get_workstation(wks_creds));
1288 bool ret;
1290 ret = delete_user(tctx, cli, admin_creds, wks_name);
1291 talloc_free(wks_name);
1292 return ret;
1296 * Test the Samba3 DC code a bit. Join, do some schan netlogon ops, leave
1299 static bool torture_netlogon_samba3(struct torture_context *torture)
1301 NTSTATUS status;
1302 struct smbcli_state *cli;
1303 struct cli_credentials *anon_creds;
1304 struct cli_credentials *wks_creds;
1305 const char *wks_name;
1306 int i;
1307 struct smbcli_options options;
1308 struct smbcli_session_options session_options;
1310 wks_name = torture_setting_string(torture, "wksname", NULL);
1311 if (wks_name == NULL) {
1312 wks_name = get_myname(torture);
1315 if (!(anon_creds = cli_credentials_init_anon(torture))) {
1316 torture_fail(torture, "create_anon_creds failed\n");
1319 lpcfg_smbcli_options(torture->lp_ctx, &options);
1320 lpcfg_smbcli_session_options(torture->lp_ctx, &session_options);
1322 status = smbcli_full_connection(torture, &cli,
1323 torture_setting_string(torture, "host", NULL),
1324 lpcfg_smb_ports(torture->lp_ctx),
1325 "IPC$", NULL,
1326 lpcfg_socket_options(torture->lp_ctx),
1327 anon_creds,
1328 lpcfg_resolve_context(torture->lp_ctx),
1329 torture->ev, &options, &session_options,
1330 lpcfg_gensec_settings(torture, torture->lp_ctx));
1331 torture_assert_ntstatus_ok(torture, status, "smbcli_full_connection failed\n");
1333 wks_creds = cli_credentials_init(torture);
1334 if (wks_creds == NULL) {
1335 torture_fail(torture, "cli_credentials_init failed\n");
1338 cli_credentials_set_conf(wks_creds, torture->lp_ctx);
1339 cli_credentials_set_secure_channel_type(wks_creds, SEC_CHAN_WKSTA);
1340 cli_credentials_set_username(wks_creds, wks_name, CRED_SPECIFIED);
1341 cli_credentials_set_workstation(wks_creds, wks_name, CRED_SPECIFIED);
1342 cli_credentials_set_password(wks_creds,
1343 generate_random_password(wks_creds, 8, 255),
1344 CRED_SPECIFIED);
1346 torture_assert(torture,
1347 join3(torture, cli, false, cmdline_credentials, wks_creds),
1348 "join failed");
1350 cli_credentials_set_domain(
1351 cmdline_credentials, cli_credentials_get_domain(wks_creds),
1352 CRED_SPECIFIED);
1354 for (i=0; i<2; i++) {
1356 /* Do this more than once, the routine "schan" changes
1357 * the workstation password using the netlogon
1358 * password change routine */
1360 int j;
1362 torture_assert(torture,
1363 auth2(torture, cli, wks_creds),
1364 "auth2 failed");
1366 for (j=0; j<2; j++) {
1367 torture_assert(torture,
1368 schan(torture, cli, wks_creds, cmdline_credentials),
1369 "schan failed");
1373 torture_assert(torture,
1374 leave(torture, cli, cmdline_credentials, wks_creds),
1375 "leave failed");
1377 return true;
1381 * Do a simple join, testjoin and leave using specified smb and samr
1382 * credentials
1385 static bool test_join3(struct torture_context *tctx,
1386 bool use_level25,
1387 struct cli_credentials *smb_creds,
1388 struct cli_credentials *samr_creds,
1389 const char *wks_name)
1391 NTSTATUS status;
1392 struct smbcli_state *cli;
1393 struct cli_credentials *wks_creds;
1394 struct smbcli_options options;
1395 struct smbcli_session_options session_options;
1397 lpcfg_smbcli_options(tctx->lp_ctx, &options);
1398 lpcfg_smbcli_session_options(tctx->lp_ctx, &session_options);
1400 status = smbcli_full_connection(tctx, &cli,
1401 torture_setting_string(tctx, "host", NULL),
1402 lpcfg_smb_ports(tctx->lp_ctx),
1403 "IPC$", NULL, lpcfg_socket_options(tctx->lp_ctx),
1404 smb_creds, lpcfg_resolve_context(tctx->lp_ctx),
1405 tctx->ev, &options, &session_options,
1406 lpcfg_gensec_settings(tctx, tctx->lp_ctx));
1407 torture_assert_ntstatus_ok(tctx, status,
1408 "smbcli_full_connection failed");
1410 wks_creds = cli_credentials_init(cli);
1411 torture_assert(tctx, wks_creds, "cli_credentials_init failed");
1413 cli_credentials_set_conf(wks_creds, tctx->lp_ctx);
1414 cli_credentials_set_secure_channel_type(wks_creds, SEC_CHAN_WKSTA);
1415 cli_credentials_set_username(wks_creds, wks_name, CRED_SPECIFIED);
1416 cli_credentials_set_workstation(wks_creds, wks_name, CRED_SPECIFIED);
1417 cli_credentials_set_password(wks_creds,
1418 generate_random_password(wks_creds, 8, 255),
1419 CRED_SPECIFIED);
1421 torture_assert(tctx,
1422 join3(tctx, cli, use_level25, samr_creds, wks_creds),
1423 "join failed");
1425 cli_credentials_set_domain(
1426 cmdline_credentials, cli_credentials_get_domain(wks_creds),
1427 CRED_SPECIFIED);
1429 torture_assert(tctx,
1430 auth2(tctx, cli, wks_creds),
1431 "auth2 failed");
1433 torture_assert(tctx,
1434 leave(tctx, cli, samr_creds, wks_creds),
1435 "leave failed");
1437 talloc_free(cli);
1439 return true;
1443 * Test the different session key variants. Do it by joining, this uses the
1444 * session key in the setpassword routine. Test the join by doing the auth2.
1447 static bool torture_samba3_sessionkey(struct torture_context *torture)
1449 struct cli_credentials *anon_creds;
1450 const char *wks_name;
1452 wks_name = torture_setting_string(torture, "wksname", get_myname(torture));
1454 if (!(anon_creds = cli_credentials_init_anon(torture))) {
1455 torture_fail(torture, "create_anon_creds failed\n");
1458 cli_credentials_set_workstation(anon_creds, wks_name, CRED_SPECIFIED);
1461 if (!torture_setting_bool(torture, "samba3", false)) {
1463 /* Samba3 in the build farm right now does this happily. Need
1464 * to fix :-) */
1466 if (test_join3(torture, false, anon_creds, NULL, wks_name)) {
1467 torture_fail(torture, "join using anonymous bind on an anonymous smb "
1468 "connection succeeded -- HUH??\n");
1472 torture_assert(torture,
1473 test_join3(torture, false, anon_creds, cmdline_credentials, wks_name),
1474 "join using ntlmssp bind on an anonymous smb connection failed");
1476 torture_assert(torture,
1477 test_join3(torture, false, cmdline_credentials, NULL, wks_name),
1478 "join using anonymous bind on an authenticated smb connection failed");
1480 torture_assert(torture,
1481 test_join3(torture, false, cmdline_credentials, cmdline_credentials, wks_name),
1482 "join using ntlmssp bind on an authenticated smb connection failed");
1485 * The following two are tests for setuserinfolevel 25
1488 torture_assert(torture,
1489 test_join3(torture, true, anon_creds, cmdline_credentials, wks_name),
1490 "join using ntlmssp bind on an anonymous smb connection failed");
1492 torture_assert(torture,
1493 test_join3(torture, true, cmdline_credentials, NULL, wks_name),
1494 "join using anonymous bind on an authenticated smb connection failed");
1496 return true;
1500 * open pipe and bind, given an IPC$ context
1503 static NTSTATUS pipe_bind_smb(struct torture_context *tctx,
1504 TALLOC_CTX *mem_ctx,
1505 struct smbcli_tree *tree,
1506 const char *pipe_name,
1507 const struct ndr_interface_table *iface,
1508 struct dcerpc_pipe **p)
1510 struct dcerpc_pipe *result;
1511 NTSTATUS status;
1513 if (!(result = dcerpc_pipe_init(mem_ctx, tctx->ev))) {
1514 return NT_STATUS_NO_MEMORY;
1517 status = dcerpc_pipe_open_smb(result, tree, pipe_name);
1518 if (!NT_STATUS_IS_OK(status)) {
1519 torture_comment(tctx, "dcerpc_pipe_open_smb failed: %s\n",
1520 nt_errstr(status));
1521 talloc_free(result);
1522 return status;
1525 status = dcerpc_bind_auth_none(result, iface);
1526 if (!NT_STATUS_IS_OK(status)) {
1527 torture_comment(tctx, "schannel bind failed: %s\n", nt_errstr(status));
1528 talloc_free(result);
1529 return status;
1532 *p = result;
1533 return NT_STATUS_OK;
1537 * Sane wrapper around lsa_LookupNames
1540 static struct dom_sid *name2sid(struct torture_context *tctx,
1541 TALLOC_CTX *mem_ctx,
1542 struct dcerpc_pipe *p,
1543 const char *name,
1544 const char *domain)
1546 struct lsa_ObjectAttribute attr;
1547 struct lsa_QosInfo qos;
1548 struct lsa_OpenPolicy2 r;
1549 struct lsa_Close c;
1550 NTSTATUS status;
1551 struct policy_handle handle;
1552 struct lsa_LookupNames l;
1553 struct lsa_TransSidArray sids;
1554 struct lsa_RefDomainList *domains = NULL;
1555 struct lsa_String lsa_name;
1556 uint32_t count = 0;
1557 struct dom_sid *result;
1558 TALLOC_CTX *tmp_ctx;
1559 struct dcerpc_binding_handle *b = p->binding_handle;
1561 if (!(tmp_ctx = talloc_new(mem_ctx))) {
1562 return NULL;
1565 qos.len = 0;
1566 qos.impersonation_level = 2;
1567 qos.context_mode = 1;
1568 qos.effective_only = 0;
1570 attr.len = 0;
1571 attr.root_dir = NULL;
1572 attr.object_name = NULL;
1573 attr.attributes = 0;
1574 attr.sec_desc = NULL;
1575 attr.sec_qos = &qos;
1577 r.in.system_name = "\\";
1578 r.in.attr = &attr;
1579 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1580 r.out.handle = &handle;
1582 status = dcerpc_lsa_OpenPolicy2_r(b, tmp_ctx, &r);
1583 if (!NT_STATUS_IS_OK(status)) {
1584 torture_comment(tctx, "OpenPolicy2 failed - %s\n", nt_errstr(status));
1585 talloc_free(tmp_ctx);
1586 return NULL;
1588 if (!NT_STATUS_IS_OK(r.out.result)) {
1589 torture_comment(tctx, "OpenPolicy2 failed - %s\n", nt_errstr(r.out.result));
1590 talloc_free(tmp_ctx);
1591 return NULL;
1594 sids.count = 0;
1595 sids.sids = NULL;
1597 lsa_name.string = talloc_asprintf(tmp_ctx, "%s\\%s", domain, name);
1599 l.in.handle = &handle;
1600 l.in.num_names = 1;
1601 l.in.names = &lsa_name;
1602 l.in.sids = &sids;
1603 l.in.level = 1;
1604 l.in.count = &count;
1605 l.out.count = &count;
1606 l.out.sids = &sids;
1607 l.out.domains = &domains;
1609 status = dcerpc_lsa_LookupNames_r(b, tmp_ctx, &l);
1610 if (!NT_STATUS_IS_OK(status)) {
1611 torture_comment(tctx, "LookupNames of %s failed - %s\n", lsa_name.string,
1612 nt_errstr(status));
1613 talloc_free(tmp_ctx);
1614 return NULL;
1616 if (!NT_STATUS_IS_OK(l.out.result)) {
1617 torture_comment(tctx, "LookupNames of %s failed - %s\n", lsa_name.string,
1618 nt_errstr(l.out.result));
1619 talloc_free(tmp_ctx);
1620 return NULL;
1623 result = dom_sid_add_rid(mem_ctx, domains->domains[0].sid,
1624 l.out.sids->sids[0].rid);
1626 c.in.handle = &handle;
1627 c.out.handle = &handle;
1629 status = dcerpc_lsa_Close_r(b, tmp_ctx, &c);
1630 if (!NT_STATUS_IS_OK(status)) {
1631 torture_comment(tctx, "dcerpc_lsa_Close failed - %s\n", nt_errstr(status));
1632 talloc_free(tmp_ctx);
1633 return NULL;
1635 if (!NT_STATUS_IS_OK(c.out.result)) {
1636 torture_comment(tctx, "dcerpc_lsa_Close failed - %s\n", nt_errstr(c.out.result));
1637 talloc_free(tmp_ctx);
1638 return NULL;
1641 talloc_free(tmp_ctx);
1642 return result;
1646 * Find out the user SID on this connection
1649 static struct dom_sid *whoami(struct torture_context *tctx,
1650 TALLOC_CTX *mem_ctx,
1651 struct smbcli_tree *tree)
1653 struct dcerpc_pipe *lsa;
1654 struct dcerpc_binding_handle *lsa_handle;
1655 struct lsa_GetUserName r;
1656 NTSTATUS status;
1657 struct lsa_String *authority_name_p = NULL;
1658 struct lsa_String *account_name_p = NULL;
1659 struct dom_sid *result;
1661 status = pipe_bind_smb(tctx, mem_ctx, tree, "\\pipe\\lsarpc",
1662 &ndr_table_lsarpc, &lsa);
1663 if (!NT_STATUS_IS_OK(status)) {
1664 torture_warning(tctx, "Could not bind to LSA: %s\n",
1665 nt_errstr(status));
1666 return NULL;
1668 lsa_handle = lsa->binding_handle;
1670 r.in.system_name = "\\";
1671 r.in.account_name = &account_name_p;
1672 r.in.authority_name = &authority_name_p;
1673 r.out.account_name = &account_name_p;
1675 status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r);
1677 authority_name_p = *r.out.authority_name;
1679 if (!NT_STATUS_IS_OK(status)) {
1680 torture_warning(tctx, "GetUserName failed - %s\n",
1681 nt_errstr(status));
1682 talloc_free(lsa);
1683 return NULL;
1685 if (!NT_STATUS_IS_OK(r.out.result)) {
1686 torture_warning(tctx, "GetUserName failed - %s\n",
1687 nt_errstr(r.out.result));
1688 talloc_free(lsa);
1689 return NULL;
1692 result = name2sid(tctx, mem_ctx, lsa, account_name_p->string,
1693 authority_name_p->string);
1695 talloc_free(lsa);
1696 return result;
1699 static int destroy_tree(struct smbcli_tree *tree)
1701 smb_tree_disconnect(tree);
1702 return 0;
1706 * Do a tcon, given a session
1709 static NTSTATUS secondary_tcon(struct torture_context *tctx,
1710 TALLOC_CTX *mem_ctx,
1711 struct smbcli_session *session,
1712 const char *sharename,
1713 struct smbcli_tree **res)
1715 struct smbcli_tree *result;
1716 TALLOC_CTX *tmp_ctx;
1717 union smb_tcon tcon;
1718 NTSTATUS status;
1720 if (!(tmp_ctx = talloc_new(mem_ctx))) {
1721 return NT_STATUS_NO_MEMORY;
1724 if (!(result = smbcli_tree_init(session, mem_ctx, false))) {
1725 talloc_free(tmp_ctx);
1726 return NT_STATUS_NO_MEMORY;
1729 tcon.generic.level = RAW_TCON_TCONX;
1730 tcon.tconx.in.flags = 0;
1731 tcon.tconx.in.password = data_blob(NULL, 0);
1732 tcon.tconx.in.path = sharename;
1733 tcon.tconx.in.device = "?????";
1735 status = smb_raw_tcon(result, tmp_ctx, &tcon);
1736 if (!NT_STATUS_IS_OK(status)) {
1737 torture_warning(tctx, "smb_raw_tcon failed: %s\n",
1738 nt_errstr(status));
1739 talloc_free(tmp_ctx);
1740 return status;
1743 result->tid = tcon.tconx.out.tid;
1744 result = talloc_steal(mem_ctx, result);
1745 talloc_set_destructor(result, destroy_tree);
1746 talloc_free(tmp_ctx);
1747 *res = result;
1748 return NT_STATUS_OK;
1752 * Test the getusername behaviour
1755 static bool torture_samba3_rpc_getusername(struct torture_context *torture)
1757 NTSTATUS status;
1758 struct smbcli_state *cli;
1759 bool ret = true;
1760 struct dom_sid *user_sid;
1761 struct dom_sid *created_sid;
1762 struct cli_credentials *anon_creds;
1763 struct cli_credentials *user_creds;
1764 char *domain_name;
1765 struct smbcli_options options;
1766 struct smbcli_session_options session_options;
1768 lpcfg_smbcli_options(torture->lp_ctx, &options);
1769 lpcfg_smbcli_session_options(torture->lp_ctx, &session_options);
1771 status = smbcli_full_connection(
1772 torture, &cli, torture_setting_string(torture, "host", NULL),
1773 lpcfg_smb_ports(torture->lp_ctx),
1774 "IPC$", NULL, lpcfg_socket_options(torture->lp_ctx), cmdline_credentials,
1775 lpcfg_resolve_context(torture->lp_ctx), torture->ev, &options,
1776 &session_options, lpcfg_gensec_settings(torture, torture->lp_ctx));
1777 torture_assert_ntstatus_ok(torture, status, "smbcli_full_connection failed\n");
1779 if (!(user_sid = whoami(torture, torture, cli->tree))) {
1780 torture_fail(torture, "whoami on auth'ed connection failed\n");
1783 talloc_free(cli);
1785 if (!(anon_creds = cli_credentials_init_anon(torture))) {
1786 torture_fail(torture, "create_anon_creds failed\n");
1789 status = smbcli_full_connection(
1790 torture, &cli, torture_setting_string(torture, "host", NULL),
1791 lpcfg_smb_ports(torture->lp_ctx), "IPC$", NULL,
1792 lpcfg_socket_options(torture->lp_ctx), anon_creds,
1793 lpcfg_resolve_context(torture->lp_ctx),
1794 torture->ev, &options, &session_options,
1795 lpcfg_gensec_settings(torture, torture->lp_ctx));
1796 torture_assert_ntstatus_ok(torture, status, "anon smbcli_full_connection failed\n");
1798 if (!(user_sid = whoami(torture, torture, cli->tree))) {
1799 torture_fail(torture, "whoami on anon connection failed\n");
1802 torture_assert_sid_equal(torture, user_sid, dom_sid_parse_talloc(torture, "s-1-5-7"),
1803 "Anon lsa_GetUserName returned unexpected SID");
1805 if (!(user_creds = cli_credentials_init(torture))) {
1806 torture_fail(torture, "cli_credentials_init failed\n");
1809 cli_credentials_set_conf(user_creds, torture->lp_ctx);
1810 cli_credentials_set_username(user_creds, "torture_username",
1811 CRED_SPECIFIED);
1812 cli_credentials_set_password(user_creds,
1813 generate_random_password(user_creds, 8, 255),
1814 CRED_SPECIFIED);
1816 if (!create_user(torture, torture, cli, cmdline_credentials,
1817 cli_credentials_get_username(user_creds),
1818 cli_credentials_get_password(user_creds),
1819 &domain_name, &created_sid)) {
1820 torture_fail(torture, "create_user failed\n");
1823 cli_credentials_set_domain(user_creds, domain_name,
1824 CRED_SPECIFIED);
1827 struct smbcli_session *session2;
1828 struct smb_composite_sesssetup setup;
1829 struct smbcli_tree *tree;
1831 session2 = smbcli_session_init(cli->transport, torture, false, session_options);
1832 if (session2 == NULL) {
1833 torture_fail(torture, "smbcli_session_init failed\n");
1836 setup.in.sesskey = cli->transport->negotiate.sesskey;
1837 setup.in.capabilities = cli->transport->negotiate.capabilities;
1838 setup.in.workgroup = "";
1839 setup.in.credentials = user_creds;
1840 setup.in.gensec_settings = lpcfg_gensec_settings(torture, torture->lp_ctx);
1842 status = smb_composite_sesssetup(session2, &setup);
1843 torture_assert_ntstatus_ok(torture, status, "session setup with new user failed");
1845 session2->vuid = setup.out.vuid;
1847 if (!NT_STATUS_IS_OK(secondary_tcon(torture, torture, session2,
1848 "IPC$", &tree))) {
1849 torture_fail(torture, "secondary_tcon failed\n");
1852 if (!(user_sid = whoami(torture, torture, tree))) {
1853 torture_fail_goto(torture, del, "whoami on user connection failed\n");
1854 ret = false;
1855 goto del;
1858 talloc_free(tree);
1861 torture_comment(torture, "Created %s, found %s\n",
1862 dom_sid_string(torture, created_sid),
1863 dom_sid_string(torture, user_sid));
1865 if (!dom_sid_equal(created_sid, user_sid)) {
1866 ret = false;
1869 del:
1870 if (!delete_user(torture, cli,
1871 cmdline_credentials,
1872 cli_credentials_get_username(user_creds))) {
1873 torture_fail(torture, "delete_user failed\n");
1876 return ret;
1879 static bool test_NetShareGetInfo(struct torture_context *tctx,
1880 struct dcerpc_pipe *p,
1881 const char *sharename)
1883 NTSTATUS status;
1884 struct srvsvc_NetShareGetInfo r;
1885 union srvsvc_NetShareInfo info;
1886 uint32_t levels[] = { 0, 1, 2, 501, 502, 1004, 1005, 1006, 1007, 1501 };
1887 int i;
1888 bool ret = true;
1889 struct dcerpc_binding_handle *b = p->binding_handle;
1891 r.in.server_unc = talloc_asprintf(tctx, "\\\\%s",
1892 dcerpc_server_name(p));
1893 r.in.share_name = sharename;
1894 r.out.info = &info;
1896 for (i=0;i<ARRAY_SIZE(levels);i++) {
1897 r.in.level = levels[i];
1899 torture_comment(tctx, "Testing NetShareGetInfo level %u on share '%s'\n",
1900 r.in.level, r.in.share_name);
1902 status = dcerpc_srvsvc_NetShareGetInfo_r(b, tctx, &r);
1903 if (!NT_STATUS_IS_OK(status)) {
1904 torture_warning(tctx, "NetShareGetInfo level %u on share '%s' failed"
1905 " - %s\n", r.in.level, r.in.share_name,
1906 nt_errstr(status));
1907 ret = false;
1908 continue;
1910 if (!W_ERROR_IS_OK(r.out.result)) {
1911 torture_warning(tctx, "NetShareGetInfo level %u on share '%s' failed "
1912 "- %s\n", r.in.level, r.in.share_name,
1913 win_errstr(r.out.result));
1914 ret = false;
1915 continue;
1919 return ret;
1922 static bool test_NetShareEnum(struct torture_context *tctx,
1923 struct dcerpc_pipe *p,
1924 const char **one_sharename)
1926 NTSTATUS status;
1927 struct srvsvc_NetShareEnum r;
1928 struct srvsvc_NetShareInfoCtr info_ctr;
1929 struct srvsvc_NetShareCtr0 c0;
1930 struct srvsvc_NetShareCtr1 c1;
1931 struct srvsvc_NetShareCtr2 c2;
1932 struct srvsvc_NetShareCtr501 c501;
1933 struct srvsvc_NetShareCtr502 c502;
1934 struct srvsvc_NetShareCtr1004 c1004;
1935 struct srvsvc_NetShareCtr1005 c1005;
1936 struct srvsvc_NetShareCtr1006 c1006;
1937 struct srvsvc_NetShareCtr1007 c1007;
1938 uint32_t totalentries = 0;
1939 uint32_t levels[] = { 0, 1, 2, 501, 502, 1004, 1005, 1006, 1007 };
1940 int i;
1941 bool ret = true;
1942 struct dcerpc_binding_handle *b = p->binding_handle;
1944 ZERO_STRUCT(info_ctr);
1946 r.in.server_unc = talloc_asprintf(tctx,"\\\\%s",dcerpc_server_name(p));
1947 r.in.info_ctr = &info_ctr;
1948 r.in.max_buffer = (uint32_t)-1;
1949 r.in.resume_handle = NULL;
1950 r.out.totalentries = &totalentries;
1951 r.out.info_ctr = &info_ctr;
1953 for (i=0;i<ARRAY_SIZE(levels);i++) {
1954 info_ctr.level = levels[i];
1956 switch (info_ctr.level) {
1957 case 0:
1958 ZERO_STRUCT(c0);
1959 info_ctr.ctr.ctr0 = &c0;
1960 break;
1961 case 1:
1962 ZERO_STRUCT(c1);
1963 info_ctr.ctr.ctr1 = &c1;
1964 break;
1965 case 2:
1966 ZERO_STRUCT(c2);
1967 info_ctr.ctr.ctr2 = &c2;
1968 break;
1969 case 501:
1970 ZERO_STRUCT(c501);
1971 info_ctr.ctr.ctr501 = &c501;
1972 break;
1973 case 502:
1974 ZERO_STRUCT(c502);
1975 info_ctr.ctr.ctr502 = &c502;
1976 break;
1977 case 1004:
1978 ZERO_STRUCT(c1004);
1979 info_ctr.ctr.ctr1004 = &c1004;
1980 break;
1981 case 1005:
1982 ZERO_STRUCT(c1005);
1983 info_ctr.ctr.ctr1005 = &c1005;
1984 break;
1985 case 1006:
1986 ZERO_STRUCT(c1006);
1987 info_ctr.ctr.ctr1006 = &c1006;
1988 break;
1989 case 1007:
1990 ZERO_STRUCT(c1007);
1991 info_ctr.ctr.ctr1007 = &c1007;
1992 break;
1995 torture_comment(tctx, "Testing NetShareEnum level %u\n", info_ctr.level);
1997 status = dcerpc_srvsvc_NetShareEnum_r(b, tctx, &r);
1998 if (!NT_STATUS_IS_OK(status)) {
1999 torture_warning(tctx, "NetShareEnum level %u failed - %s\n",
2000 info_ctr.level, nt_errstr(status));
2001 ret = false;
2002 continue;
2004 if (!W_ERROR_IS_OK(r.out.result)) {
2005 torture_warning(tctx, "NetShareEnum level %u failed - %s\n",
2006 info_ctr.level, win_errstr(r.out.result));
2007 continue;
2009 if (info_ctr.level == 0) {
2010 struct srvsvc_NetShareCtr0 *ctr = r.out.info_ctr->ctr.ctr0;
2011 if (ctr->count > 0) {
2012 *one_sharename = ctr->array[0].name;
2017 return ret;
2020 static bool torture_samba3_rpc_srvsvc(struct torture_context *torture)
2022 struct dcerpc_pipe *p;
2023 const char *sharename = NULL;
2024 bool ret = true;
2026 torture_assert_ntstatus_ok(torture,
2027 torture_rpc_connection(torture, &p, &ndr_table_srvsvc),
2028 "failed to open srvsvc");
2030 ret &= test_NetShareEnum(torture, p, &sharename);
2031 if (sharename == NULL) {
2032 torture_comment(torture, "did not get sharename\n");
2033 } else {
2034 ret &= test_NetShareGetInfo(torture, p, sharename);
2037 return ret;
2041 * Do a ReqChallenge/Auth2 with a random wks name, make sure it returns
2042 * NT_STATUS_NO_SAM_ACCOUNT
2045 static bool torture_samba3_rpc_randomauth2(struct torture_context *torture)
2047 TALLOC_CTX *mem_ctx;
2048 struct dcerpc_pipe *net_pipe;
2049 struct dcerpc_binding_handle *net_handle;
2050 char *wksname;
2051 bool result = false;
2052 NTSTATUS status;
2053 struct netr_ServerReqChallenge r;
2054 struct netr_Credential netr_cli_creds;
2055 struct netr_Credential netr_srv_creds;
2056 uint32_t negotiate_flags;
2057 struct netr_ServerAuthenticate2 a;
2058 struct netlogon_creds_CredentialState *creds_state;
2059 struct netr_Credential netr_cred;
2060 struct samr_Password mach_pw;
2061 struct smbcli_state *cli;
2063 if (!(mem_ctx = talloc_new(torture))) {
2064 torture_comment(torture, "talloc_new failed\n");
2065 return false;
2068 if (!(wksname = generate_random_str_list(
2069 mem_ctx, 14, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"))) {
2070 torture_comment(torture, "generate_random_str_list failed\n");
2071 goto done;
2074 if (!(torture_open_connection_share(
2075 mem_ctx, &cli,
2076 torture, torture_setting_string(torture, "host", NULL),
2077 "IPC$", torture->ev))) {
2078 torture_comment(torture, "IPC$ connection failed\n");
2079 goto done;
2082 if (!(net_pipe = dcerpc_pipe_init(mem_ctx, torture->ev))) {
2083 torture_comment(torture, "dcerpc_pipe_init failed\n");
2084 goto done;
2086 net_handle = net_pipe->binding_handle;
2088 status = dcerpc_pipe_open_smb(net_pipe, cli->tree, "\\netlogon");
2089 if (!NT_STATUS_IS_OK(status)) {
2090 torture_comment(torture, "dcerpc_pipe_open_smb failed: %s\n",
2091 nt_errstr(status));
2092 goto done;
2095 status = dcerpc_bind_auth_none(net_pipe, &ndr_table_netlogon);
2096 if (!NT_STATUS_IS_OK(status)) {
2097 torture_comment(torture, "dcerpc_bind_auth_none failed: %s\n",
2098 nt_errstr(status));
2099 goto done;
2102 r.in.computer_name = wksname;
2103 r.in.server_name = talloc_asprintf(
2104 mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
2105 if (r.in.server_name == NULL) {
2106 torture_comment(torture, "talloc_asprintf failed\n");
2107 goto done;
2109 generate_random_buffer(netr_cli_creds.data,
2110 sizeof(netr_cli_creds.data));
2111 r.in.credentials = &netr_cli_creds;
2112 r.out.return_credentials = &netr_srv_creds;
2114 status = dcerpc_netr_ServerReqChallenge_r(net_handle, mem_ctx, &r);
2115 if (!NT_STATUS_IS_OK(status)) {
2116 torture_comment(torture, "netr_ServerReqChallenge failed: %s\n",
2117 nt_errstr(status));
2118 goto done;
2120 if (!NT_STATUS_IS_OK(r.out.result)) {
2121 torture_comment(torture, "netr_ServerReqChallenge failed: %s\n",
2122 nt_errstr(r.out.result));
2123 goto done;
2126 negotiate_flags = NETLOGON_NEG_AUTH2_FLAGS;
2127 E_md4hash("foobar", mach_pw.hash);
2129 a.in.server_name = talloc_asprintf(
2130 mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
2131 a.in.account_name = talloc_asprintf(
2132 mem_ctx, "%s$", wksname);
2133 a.in.computer_name = wksname;
2134 a.in.secure_channel_type = SEC_CHAN_WKSTA;
2135 a.in.negotiate_flags = &negotiate_flags;
2136 a.out.negotiate_flags = &negotiate_flags;
2137 a.in.credentials = &netr_cred;
2138 a.out.return_credentials = &netr_cred;
2140 creds_state = netlogon_creds_client_init(mem_ctx,
2141 a.in.account_name,
2142 a.in.computer_name,
2143 r.in.credentials,
2144 r.out.return_credentials, &mach_pw,
2145 &netr_cred, negotiate_flags);
2146 torture_assert(torture, (creds_state != NULL), "memory allocation failed");
2148 status = dcerpc_netr_ServerAuthenticate2_r(net_handle, mem_ctx, &a);
2149 if (!NT_STATUS_IS_OK(status)) {
2150 goto done;
2152 if (!NT_STATUS_EQUAL(a.out.result, NT_STATUS_NO_TRUST_SAM_ACCOUNT)) {
2153 torture_comment(torture, "dcerpc_netr_ServerAuthenticate2 returned %s, "
2154 "expected NT_STATUS_NO_TRUST_SAM_ACCOUNT\n",
2155 nt_errstr(a.out.result));
2156 goto done;
2159 result = true;
2160 done:
2161 talloc_free(mem_ctx);
2162 return result;
2165 static struct security_descriptor *get_sharesec(struct torture_context *tctx,
2166 TALLOC_CTX *mem_ctx,
2167 struct smbcli_session *sess,
2168 const char *sharename)
2170 struct smbcli_tree *tree;
2171 TALLOC_CTX *tmp_ctx;
2172 struct dcerpc_pipe *p;
2173 struct dcerpc_binding_handle *b;
2174 NTSTATUS status;
2175 struct srvsvc_NetShareGetInfo r;
2176 union srvsvc_NetShareInfo info;
2177 struct security_descriptor *result;
2179 if (!(tmp_ctx = talloc_new(mem_ctx))) {
2180 torture_comment(tctx, "talloc_new failed\n");
2181 return NULL;
2184 if (!NT_STATUS_IS_OK(secondary_tcon(tctx, tmp_ctx, sess, "IPC$", &tree))) {
2185 torture_comment(tctx, "secondary_tcon failed\n");
2186 talloc_free(tmp_ctx);
2187 return NULL;
2190 status = pipe_bind_smb(tctx, mem_ctx, tree, "\\pipe\\srvsvc",
2191 &ndr_table_srvsvc, &p);
2192 if (!NT_STATUS_IS_OK(status)) {
2193 torture_warning(tctx, "could not bind to srvsvc pipe: %s\n",
2194 nt_errstr(status));
2195 talloc_free(tmp_ctx);
2196 return NULL;
2198 b = p->binding_handle;
2200 #if 0
2201 p->conn->flags |= DCERPC_DEBUG_PRINT_IN | DCERPC_DEBUG_PRINT_OUT;
2202 #endif
2204 r.in.server_unc = talloc_asprintf(tmp_ctx, "\\\\%s",
2205 dcerpc_server_name(p));
2206 r.in.share_name = sharename;
2207 r.in.level = 502;
2208 r.out.info = &info;
2210 status = dcerpc_srvsvc_NetShareGetInfo_r(b, tmp_ctx, &r);
2211 if (!NT_STATUS_IS_OK(status)) {
2212 torture_comment(tctx, "srvsvc_NetShareGetInfo failed: %s\n",
2213 nt_errstr(status));
2214 talloc_free(tmp_ctx);
2215 return NULL;
2217 if (!W_ERROR_IS_OK(r.out.result)) {
2218 torture_comment(tctx, "srvsvc_NetShareGetInfo failed: %s\n",
2219 win_errstr(r.out.result));
2220 talloc_free(tmp_ctx);
2221 return NULL;
2224 result = talloc_steal(mem_ctx, info.info502->sd_buf.sd);
2225 talloc_free(tmp_ctx);
2226 return result;
2229 static NTSTATUS set_sharesec(struct torture_context *tctx,
2230 TALLOC_CTX *mem_ctx,
2231 struct smbcli_session *sess,
2232 const char *sharename,
2233 struct security_descriptor *sd)
2235 struct smbcli_tree *tree;
2236 TALLOC_CTX *tmp_ctx;
2237 struct dcerpc_pipe *p;
2238 struct dcerpc_binding_handle *b;
2239 NTSTATUS status;
2240 struct sec_desc_buf i;
2241 struct srvsvc_NetShareSetInfo r;
2242 union srvsvc_NetShareInfo info;
2243 uint32_t error = 0;
2245 if (!(tmp_ctx = talloc_new(mem_ctx))) {
2246 torture_comment(tctx, "talloc_new failed\n");
2247 return NT_STATUS_NO_MEMORY;
2250 if (!NT_STATUS_IS_OK(secondary_tcon(tctx, tmp_ctx, sess, "IPC$", &tree))) {
2251 torture_comment(tctx, "secondary_tcon failed\n");
2252 talloc_free(tmp_ctx);
2253 return NT_STATUS_UNSUCCESSFUL;
2256 status = pipe_bind_smb(tctx, mem_ctx, tree, "\\pipe\\srvsvc",
2257 &ndr_table_srvsvc, &p);
2258 if (!NT_STATUS_IS_OK(status)) {
2259 torture_warning(tctx, "could not bind to srvsvc pipe: %s\n",
2260 nt_errstr(status));
2261 talloc_free(tmp_ctx);
2262 return NT_STATUS_UNSUCCESSFUL;
2264 b = p->binding_handle;
2266 #if 0
2267 p->conn->flags |= DCERPC_DEBUG_PRINT_IN | DCERPC_DEBUG_PRINT_OUT;
2268 #endif
2270 r.in.server_unc = talloc_asprintf(tmp_ctx, "\\\\%s",
2271 dcerpc_server_name(p));
2272 r.in.share_name = sharename;
2273 r.in.level = 1501;
2274 i.sd = sd;
2275 info.info1501 = &i;
2276 r.in.info = &info;
2277 r.in.parm_error = &error;
2279 status = dcerpc_srvsvc_NetShareSetInfo_r(b, tmp_ctx, &r);
2280 if (!NT_STATUS_IS_OK(status)) {
2281 torture_comment(tctx, "srvsvc_NetShareSetInfo failed: %s\n",
2282 nt_errstr(status));
2284 if (!W_ERROR_IS_OK(r.out.result)) {
2285 torture_comment(tctx, "srvsvc_NetShareSetInfo failed: %s\n",
2286 win_errstr(r.out.result));
2287 status = werror_to_ntstatus(r.out.result);
2289 talloc_free(tmp_ctx);
2290 return status;
2293 bool try_tcon(struct torture_context *tctx,
2294 TALLOC_CTX *mem_ctx,
2295 struct security_descriptor *orig_sd,
2296 struct smbcli_session *session,
2297 const char *sharename, const struct dom_sid *user_sid,
2298 unsigned int access_mask, NTSTATUS expected_tcon,
2299 NTSTATUS expected_mkdir)
2301 TALLOC_CTX *tmp_ctx;
2302 struct smbcli_tree *rmdir_tree, *tree;
2303 struct dom_sid *domain_sid;
2304 uint32_t rid;
2305 struct security_descriptor *sd;
2306 NTSTATUS status;
2307 bool ret = true;
2309 if (!(tmp_ctx = talloc_new(mem_ctx))) {
2310 torture_comment(tctx, "talloc_new failed\n");
2311 return false;
2314 status = secondary_tcon(tctx, tmp_ctx, session, sharename, &rmdir_tree);
2315 if (!NT_STATUS_IS_OK(status)) {
2316 torture_comment(tctx, "first tcon to delete dir failed\n");
2317 talloc_free(tmp_ctx);
2318 return false;
2321 smbcli_rmdir(rmdir_tree, "sharesec_testdir");
2323 if (!NT_STATUS_IS_OK(dom_sid_split_rid(tmp_ctx, user_sid,
2324 &domain_sid, &rid))) {
2325 torture_comment(tctx, "dom_sid_split_rid failed\n");
2326 talloc_free(tmp_ctx);
2327 return false;
2330 sd = security_descriptor_dacl_create(
2331 tmp_ctx, 0, "S-1-5-32-544",
2332 dom_sid_string(mem_ctx, dom_sid_add_rid(mem_ctx, domain_sid,
2333 DOMAIN_RID_USERS)),
2334 dom_sid_string(mem_ctx, user_sid),
2335 SEC_ACE_TYPE_ACCESS_ALLOWED, access_mask, 0, NULL);
2336 if (sd == NULL) {
2337 torture_comment(tctx, "security_descriptor_dacl_create failed\n");
2338 talloc_free(tmp_ctx);
2339 return false;
2342 status = set_sharesec(tctx, mem_ctx, session, sharename, sd);
2343 if (!NT_STATUS_IS_OK(status)) {
2344 torture_comment(tctx, "custom set_sharesec failed: %s\n",
2345 nt_errstr(status));
2346 talloc_free(tmp_ctx);
2347 return false;
2350 status = secondary_tcon(tctx, tmp_ctx, session, sharename, &tree);
2351 if (!NT_STATUS_EQUAL(status, expected_tcon)) {
2352 torture_comment(tctx, "Expected %s, got %s\n", nt_errstr(expected_tcon),
2353 nt_errstr(status));
2354 ret = false;
2355 goto done;
2358 if (!NT_STATUS_IS_OK(status)) {
2359 /* An expected non-access, no point in trying to write */
2360 goto done;
2363 status = smbcli_mkdir(tree, "sharesec_testdir");
2364 if (!NT_STATUS_EQUAL(status, expected_mkdir)) {
2365 torture_warning(tctx, "Expected %s, got %s\n",
2366 nt_errstr(expected_mkdir), nt_errstr(status));
2367 ret = false;
2370 done:
2371 smbcli_rmdir(rmdir_tree, "sharesec_testdir");
2373 status = set_sharesec(tctx, mem_ctx, session, sharename, orig_sd);
2374 if (!NT_STATUS_IS_OK(status)) {
2375 torture_comment(tctx, "custom set_sharesec failed: %s\n",
2376 nt_errstr(status));
2377 talloc_free(tmp_ctx);
2378 return false;
2381 talloc_free(tmp_ctx);
2382 return ret;
2385 static bool torture_samba3_rpc_sharesec(struct torture_context *torture)
2387 struct smbcli_state *cli;
2388 struct security_descriptor *sd;
2389 struct dom_sid *user_sid;
2391 if (!(torture_open_connection_share(
2392 torture, &cli, torture, torture_setting_string(torture, "host", NULL),
2393 "IPC$", torture->ev))) {
2394 torture_fail(torture, "IPC$ connection failed\n");
2397 if (!(user_sid = whoami(torture, torture, cli->tree))) {
2398 torture_fail(torture, "whoami failed\n");
2401 sd = get_sharesec(torture, torture, cli->session,
2402 torture_setting_string(torture, "share", NULL));
2404 torture_assert(torture, try_tcon(
2405 torture, torture, sd, cli->session,
2406 torture_setting_string(torture, "share", NULL),
2407 user_sid, 0, NT_STATUS_ACCESS_DENIED, NT_STATUS_OK),
2408 "failed to test tcon with 0 access_mask");
2410 torture_assert(torture, try_tcon(
2411 torture, torture, sd, cli->session,
2412 torture_setting_string(torture, "share", NULL),
2413 user_sid, SEC_FILE_READ_DATA, NT_STATUS_OK,
2414 NT_STATUS_MEDIA_WRITE_PROTECTED),
2415 "failed to test tcon with SEC_FILE_READ_DATA access_mask");
2417 torture_assert(torture, try_tcon(
2418 torture, torture, sd, cli->session,
2419 torture_setting_string(torture, "share", NULL),
2420 user_sid, SEC_FILE_ALL, NT_STATUS_OK, NT_STATUS_OK),
2421 "failed to test tcon with SEC_FILE_ALL access_mask")
2423 return true;
2426 static bool torture_samba3_rpc_lsa(struct torture_context *torture)
2428 struct dcerpc_pipe *p;
2429 struct dcerpc_binding_handle *b;
2430 struct policy_handle lsa_handle;
2432 torture_assert_ntstatus_ok(torture,
2433 torture_rpc_connection(torture, &p, &ndr_table_lsarpc),
2434 "failed to setup lsarpc");
2436 b = p->binding_handle;
2439 struct lsa_ObjectAttribute attr;
2440 struct lsa_OpenPolicy2 o;
2441 o.in.system_name = talloc_asprintf(
2442 torture, "\\\\%s", dcerpc_server_name(p));
2443 ZERO_STRUCT(attr);
2444 o.in.attr = &attr;
2445 o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2446 o.out.handle = &lsa_handle;
2448 torture_assert_ntstatus_ok(torture,
2449 dcerpc_lsa_OpenPolicy2_r(b, torture, &o),
2450 "dcerpc_lsa_OpenPolicy2 failed");
2451 torture_assert_ntstatus_ok(torture, o.out.result,
2452 "dcerpc_lsa_OpenPolicy2 failed");
2456 int i;
2457 int levels[] = { 2,3,5,6 };
2459 for (i=0; i<ARRAY_SIZE(levels); i++) {
2460 struct lsa_QueryInfoPolicy r;
2461 union lsa_PolicyInformation *info = NULL;
2462 r.in.handle = &lsa_handle;
2463 r.in.level = levels[i];
2464 r.out.info = &info;
2466 torture_assert_ntstatus_ok(torture,
2467 dcerpc_lsa_QueryInfoPolicy_r(b, torture, &r),
2468 talloc_asprintf(torture, "dcerpc_lsa_QueryInfoPolicy level %d failed", levels[i]));
2469 torture_assert_ntstatus_ok(torture, r.out.result,
2470 talloc_asprintf(torture, "dcerpc_lsa_QueryInfoPolicy level %d failed", levels[i]));
2474 return true;
2477 static NTSTATUS get_servername(TALLOC_CTX *mem_ctx, struct smbcli_tree *tree,
2478 char **name)
2480 struct rap_WserverGetInfo r;
2481 NTSTATUS status;
2482 char servername[17];
2483 size_t converted_size;
2485 r.in.level = 0;
2486 r.in.bufsize = 0xffff;
2488 status = smbcli_rap_netservergetinfo(tree, mem_ctx, &r);
2489 if (!NT_STATUS_IS_OK(status)) {
2490 return status;
2493 memcpy(servername, r.out.info.info0.name, 16);
2494 servername[16] = '\0';
2496 if (!pull_ascii_talloc(mem_ctx, name, servername, &converted_size)) {
2497 return NT_STATUS_NO_MEMORY;
2500 return NT_STATUS_OK;
2503 static bool rap_get_servername(struct torture_context *tctx,
2504 char **servername)
2506 struct smbcli_state *cli;
2508 torture_assert(tctx,
2509 torture_open_connection_share(tctx, &cli, tctx, torture_setting_string(tctx, "host", NULL),
2510 "IPC$", tctx->ev),
2511 "IPC$ connection failed");
2513 torture_assert_ntstatus_ok(tctx,
2514 get_servername(tctx, cli->tree, servername),
2515 "get_servername failed");
2517 talloc_free(cli);
2519 return true;
2522 static bool find_printers(struct torture_context *tctx,
2523 struct dcerpc_pipe *p,
2524 const char ***printers,
2525 int *num_printers)
2527 struct srvsvc_NetShareEnum r;
2528 struct srvsvc_NetShareInfoCtr info_ctr;
2529 struct srvsvc_NetShareCtr1 c1_in;
2530 struct srvsvc_NetShareCtr1 *c1;
2531 uint32_t totalentries = 0;
2532 int i;
2533 struct dcerpc_binding_handle *b = p->binding_handle;
2535 ZERO_STRUCT(c1_in);
2536 info_ctr.level = 1;
2537 info_ctr.ctr.ctr1 = &c1_in;
2539 r.in.server_unc = talloc_asprintf(
2540 tctx, "\\\\%s", dcerpc_server_name(p));
2541 r.in.info_ctr = &info_ctr;
2542 r.in.max_buffer = (uint32_t)-1;
2543 r.in.resume_handle = NULL;
2544 r.out.totalentries = &totalentries;
2545 r.out.info_ctr = &info_ctr;
2547 torture_assert_ntstatus_ok(tctx,
2548 dcerpc_srvsvc_NetShareEnum_r(b, tctx, &r),
2549 "NetShareEnum level 1 failed");
2550 torture_assert_werr_ok(tctx, r.out.result,
2551 "NetShareEnum level 1 failed");
2553 *printers = NULL;
2554 *num_printers = 0;
2555 c1 = r.out.info_ctr->ctr.ctr1;
2556 for (i=0; i<c1->count; i++) {
2557 if (c1->array[i].type != STYPE_PRINTQ) {
2558 continue;
2560 if (!add_string_to_array(tctx, c1->array[i].name,
2561 printers, num_printers)) {
2562 return false;
2566 return true;
2569 static bool enumprinters(struct torture_context *tctx,
2570 struct dcerpc_binding_handle *b,
2571 const char *servername, int level, int *num_printers)
2573 struct spoolss_EnumPrinters r;
2574 DATA_BLOB blob;
2575 uint32_t needed;
2576 uint32_t count;
2577 union spoolss_PrinterInfo *info;
2579 r.in.flags = PRINTER_ENUM_LOCAL;
2580 r.in.server = talloc_asprintf(tctx, "\\\\%s", servername);
2581 r.in.level = level;
2582 r.in.buffer = NULL;
2583 r.in.offered = 0;
2584 r.out.needed = &needed;
2585 r.out.count = &count;
2586 r.out.info = &info;
2588 torture_assert_ntstatus_ok(tctx,
2589 dcerpc_spoolss_EnumPrinters_r(b, tctx, &r),
2590 "dcerpc_spoolss_EnumPrinters failed");
2591 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
2592 "EnumPrinters unexpected return code should be WERR_INSUFFICIENT_BUFFER");
2594 blob = data_blob_talloc_zero(tctx, needed);
2595 if (blob.data == NULL) {
2596 return false;
2599 r.in.buffer = &blob;
2600 r.in.offered = needed;
2602 torture_assert_ntstatus_ok(tctx,
2603 dcerpc_spoolss_EnumPrinters_r(b, tctx, &r),
2604 "dcerpc_spoolss_EnumPrinters failed");
2605 torture_assert_werr_ok(tctx, r.out.result,
2606 "dcerpc_spoolss_EnumPrinters failed");
2608 *num_printers = count;
2610 return true;
2613 static bool getprinterinfo(struct torture_context *tctx,
2614 struct dcerpc_binding_handle *b,
2615 struct policy_handle *handle, int level,
2616 union spoolss_PrinterInfo **res)
2618 struct spoolss_GetPrinter r;
2619 DATA_BLOB blob;
2620 uint32_t needed;
2622 r.in.handle = handle;
2623 r.in.level = level;
2624 r.in.buffer = NULL;
2625 r.in.offered = 0;
2626 r.out.needed = &needed;
2628 torture_assert_ntstatus_ok(tctx,
2629 dcerpc_spoolss_GetPrinter_r(b, tctx, &r),
2630 "dcerpc_spoolss_GetPrinter failed");
2631 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
2632 "GetPrinter unexpected return code should be WERR_INSUFFICIENT_BUFFER");
2634 r.in.handle = handle;
2635 r.in.level = level;
2636 blob = data_blob_talloc_zero(tctx, needed);
2637 if (blob.data == NULL) {
2638 return false;
2640 r.in.buffer = &blob;
2641 r.in.offered = needed;
2643 torture_assert_ntstatus_ok(tctx,
2644 dcerpc_spoolss_GetPrinter_r(b, tctx, &r),
2645 "dcerpc_spoolss_GetPrinter failed");
2646 torture_assert_werr_ok(tctx, r.out.result,
2647 "dcerpc_spoolss_GetPrinter failed");
2649 if (res != NULL) {
2650 *res = talloc_steal(tctx, r.out.info);
2653 return true;
2656 static bool torture_samba3_rpc_spoolss(struct torture_context *torture)
2658 struct dcerpc_pipe *p, *p2;
2659 struct dcerpc_binding_handle *b;
2660 struct policy_handle server_handle, printer_handle;
2661 const char **printers;
2662 int num_printers;
2663 struct spoolss_UserLevel1 userlevel1;
2664 char *servername;
2666 torture_assert(torture,
2667 rap_get_servername(torture, &servername),
2668 "failed to rap servername");
2670 torture_assert_ntstatus_ok(torture,
2671 torture_rpc_connection(torture, &p2, &ndr_table_srvsvc),
2672 "failed to setup srvsvc");
2674 torture_assert(torture,
2675 find_printers(torture, p2, &printers, &num_printers),
2676 "failed to find printers via srvsvc");
2678 talloc_free(p2);
2680 if (num_printers == 0) {
2681 torture_skip(torture, "Did not find printers\n");
2682 return true;
2685 torture_assert_ntstatus_ok(torture,
2686 torture_rpc_connection(torture, &p, &ndr_table_spoolss),
2687 "failed to setup spoolss");
2689 b = p->binding_handle;
2691 ZERO_STRUCT(userlevel1);
2692 userlevel1.client = talloc_asprintf(
2693 torture, "\\\\%s", lpcfg_netbios_name(torture->lp_ctx));
2694 userlevel1.user = cli_credentials_get_username(cmdline_credentials);
2695 userlevel1.build = 2600;
2696 userlevel1.major = 3;
2697 userlevel1.minor = 0;
2698 userlevel1.processor = 0;
2701 struct spoolss_OpenPrinterEx r;
2703 ZERO_STRUCT(r);
2704 r.in.printername = talloc_asprintf(torture, "\\\\%s",
2705 servername);
2706 r.in.datatype = NULL;
2707 r.in.access_mask = 0;
2708 r.in.level = 1;
2709 r.in.userlevel.level1 = &userlevel1;
2710 r.out.handle = &server_handle;
2712 torture_assert_ntstatus_ok(torture,
2713 dcerpc_spoolss_OpenPrinterEx_r(b, torture, &r),
2714 "dcerpc_spoolss_OpenPrinterEx failed");
2715 torture_assert_werr_ok(torture, r.out.result,
2716 "dcerpc_spoolss_OpenPrinterEx failed");
2720 struct spoolss_ClosePrinter r;
2722 r.in.handle = &server_handle;
2723 r.out.handle = &server_handle;
2725 torture_assert_ntstatus_ok(torture,
2726 dcerpc_spoolss_ClosePrinter_r(b, torture, &r),
2727 "dcerpc_spoolss_ClosePrinter failed");
2728 torture_assert_werr_ok(torture, r.out.result,
2729 "dcerpc_spoolss_ClosePrinter failed");
2733 struct spoolss_OpenPrinterEx r;
2735 ZERO_STRUCT(r);
2736 r.in.printername = talloc_asprintf(
2737 torture, "\\\\%s\\%s", servername, printers[0]);
2738 r.in.datatype = NULL;
2739 r.in.access_mask = 0;
2740 r.in.level = 1;
2741 r.in.userlevel.level1 = &userlevel1;
2742 r.out.handle = &printer_handle;
2744 torture_assert_ntstatus_ok(torture,
2745 dcerpc_spoolss_OpenPrinterEx_r(b, torture, &r),
2746 "dcerpc_spoolss_OpenPrinterEx failed");
2747 torture_assert_werr_ok(torture, r.out.result,
2748 "dcerpc_spoolss_OpenPrinterEx failed");
2752 int i;
2754 for (i=0; i<8; i++) {
2755 torture_assert(torture,
2756 getprinterinfo(torture, b, &printer_handle, i, NULL),
2757 talloc_asprintf(torture, "getprinterinfo %d failed", i));
2762 struct spoolss_ClosePrinter r;
2764 r.in.handle = &printer_handle;
2765 r.out.handle = &printer_handle;
2767 torture_assert_ntstatus_ok(torture,
2768 dcerpc_spoolss_ClosePrinter_r(b, torture, &r),
2769 "dcerpc_spoolss_ClosePrinter failed");
2770 torture_assert_werr_ok(torture, r.out.result,
2771 "dcerpc_spoolss_ClosePrinter failed");
2775 int num_enumerated;
2777 torture_assert(torture,
2778 enumprinters(torture, b, servername, 1, &num_enumerated),
2779 "enumprinters failed");
2781 torture_assert_int_equal(torture, num_printers, num_enumerated,
2782 "netshareenum / enumprinters lvl 1 numprinter mismatch");
2786 int num_enumerated;
2788 torture_assert(torture,
2789 enumprinters(torture, b, servername, 2, &num_enumerated),
2790 "enumprinters failed");
2792 torture_assert_int_equal(torture, num_printers, num_enumerated,
2793 "netshareenum / enumprinters lvl 2 numprinter mismatch");
2796 return true;
2799 static bool torture_samba3_rpc_wkssvc(struct torture_context *torture)
2801 struct dcerpc_pipe *p;
2802 struct dcerpc_binding_handle *b;
2803 char *servername;
2805 torture_assert(torture,
2806 rap_get_servername(torture, &servername),
2807 "failed to rap servername");
2809 torture_assert_ntstatus_ok(torture,
2810 torture_rpc_connection(torture, &p, &ndr_table_wkssvc),
2811 "failed to setup wkssvc");
2813 b = p->binding_handle;
2816 struct wkssvc_NetWkstaInfo100 wks100;
2817 union wkssvc_NetWkstaInfo info;
2818 struct wkssvc_NetWkstaGetInfo r;
2820 r.in.server_name = "\\foo";
2821 r.in.level = 100;
2822 info.info100 = &wks100;
2823 r.out.info = &info;
2825 torture_assert_ntstatus_ok(torture,
2826 dcerpc_wkssvc_NetWkstaGetInfo_r(b, torture, &r),
2827 "dcerpc_wkssvc_NetWksGetInfo failed");
2828 torture_assert_werr_ok(torture, r.out.result,
2829 "dcerpc_wkssvc_NetWksGetInfo failed");
2831 torture_assert_str_equal(torture, servername, r.out.info->info100->server_name,
2832 "servername RAP / DCERPC inconsistency");
2835 return true;
2838 static bool winreg_close(struct torture_context *tctx,
2839 struct dcerpc_binding_handle *b,
2840 struct policy_handle *handle)
2842 struct winreg_CloseKey c;
2844 c.in.handle = c.out.handle = handle;
2846 torture_assert_ntstatus_ok(tctx,
2847 dcerpc_winreg_CloseKey_r(b, tctx, &c),
2848 "winreg_CloseKey failed");
2849 torture_assert_werr_ok(tctx, c.out.result,
2850 "winreg_CloseKey failed");
2852 return true;
2855 static bool enumvalues(struct torture_context *tctx,
2856 struct dcerpc_binding_handle *b,
2857 struct policy_handle *handle)
2859 uint32_t enum_index = 0;
2861 while (1) {
2862 struct winreg_EnumValue r;
2863 struct winreg_ValNameBuf name;
2864 enum winreg_Type type = 0;
2865 uint8_t buf8[1024];
2866 NTSTATUS status;
2867 uint32_t size, length;
2869 r.in.handle = handle;
2870 r.in.enum_index = enum_index;
2871 name.name = "";
2872 name.size = 1024;
2873 r.in.name = r.out.name = &name;
2874 size = 1024;
2875 length = 5;
2876 r.in.type = &type;
2877 r.in.value = buf8;
2878 r.in.size = &size;
2879 r.in.length = &length;
2881 status = dcerpc_winreg_EnumValue_r(b, tctx, &r);
2882 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
2883 return true;
2885 enum_index += 1;
2889 static bool enumkeys(struct torture_context *tctx,
2890 struct dcerpc_binding_handle *b,
2891 struct policy_handle *handle,
2892 int depth)
2894 struct winreg_EnumKey r;
2895 struct winreg_StringBuf kclass, name;
2896 NTSTATUS status;
2897 NTTIME t = 0;
2899 if (depth <= 0) {
2900 return true;
2903 kclass.name = "";
2904 kclass.size = 1024;
2906 r.in.handle = handle;
2907 r.in.enum_index = 0;
2908 r.in.name = &name;
2909 r.in.keyclass = &kclass;
2910 r.out.name = &name;
2911 r.in.last_changed_time = &t;
2913 do {
2914 struct winreg_OpenKey o;
2915 struct policy_handle key_handle;
2916 int i;
2918 name.name = NULL;
2919 name.size = 1024;
2921 status = dcerpc_winreg_EnumKey_r(b, tctx, &r);
2922 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
2923 /* We're done enumerating */
2924 return true;
2927 for (i=0; i<10-depth; i++) {
2928 torture_comment(tctx, " ");
2930 torture_comment(tctx, "%s\n", r.out.name->name);
2932 o.in.parent_handle = handle;
2933 o.in.keyname.name = r.out.name->name;
2934 o.in.options = 0;
2935 o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2936 o.out.handle = &key_handle;
2938 status = dcerpc_winreg_OpenKey_r(b, tctx, &o);
2939 if (NT_STATUS_IS_OK(status) && W_ERROR_IS_OK(o.out.result)) {
2940 enumkeys(tctx, b, &key_handle, depth-1);
2941 enumvalues(tctx, b, &key_handle);
2942 torture_assert(tctx, winreg_close(tctx, b, &key_handle), "");
2945 r.in.enum_index += 1;
2946 } while(true);
2948 return true;
2951 typedef NTSTATUS (*winreg_open_fn)(struct dcerpc_binding_handle *, TALLOC_CTX *, void *);
2953 static bool test_Open3(struct torture_context *tctx,
2954 struct dcerpc_binding_handle *b,
2955 const char *name, winreg_open_fn open_fn)
2957 struct policy_handle handle;
2958 struct winreg_OpenHKLM r;
2960 r.in.system_name = 0;
2961 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2962 r.out.handle = &handle;
2964 torture_assert_ntstatus_ok(tctx,
2965 open_fn(b, tctx, &r),
2966 talloc_asprintf(tctx, "%s failed", name));
2967 torture_assert_werr_ok(tctx, r.out.result,
2968 talloc_asprintf(tctx, "%s failed", name));
2970 enumkeys(tctx, b, &handle, 4);
2972 torture_assert(tctx,
2973 winreg_close(tctx, b, &handle),
2974 "dcerpc_CloseKey failed");
2976 return true;
2979 static bool torture_samba3_rpc_winreg(struct torture_context *torture)
2981 struct dcerpc_pipe *p;
2982 struct dcerpc_binding_handle *b;
2983 bool ret = true;
2984 struct {
2985 const char *name;
2986 winreg_open_fn fn;
2987 } open_fns[] = {
2988 {"OpenHKLM", (winreg_open_fn)dcerpc_winreg_OpenHKLM_r },
2989 {"OpenHKU", (winreg_open_fn)dcerpc_winreg_OpenHKU_r },
2990 {"OpenHKPD", (winreg_open_fn)dcerpc_winreg_OpenHKPD_r },
2991 {"OpenHKPT", (winreg_open_fn)dcerpc_winreg_OpenHKPT_r },
2992 {"OpenHKCR", (winreg_open_fn)dcerpc_winreg_OpenHKCR_r }};
2993 #if 0
2994 int i;
2995 #endif
2997 torture_assert_ntstatus_ok(torture,
2998 torture_rpc_connection(torture, &p, &ndr_table_winreg),
2999 "failed to setup winreg");
3001 b = p->binding_handle;
3003 #if 1
3004 ret = test_Open3(torture, b, open_fns[0].name, open_fns[0].fn);
3005 #else
3006 for (i = 0; i < ARRAY_SIZE(open_fns); i++) {
3007 if (!test_Open3(torture, b, open_fns[i].name, open_fns[i].fn))
3008 ret = false;
3010 #endif
3011 return ret;
3014 static bool get_shareinfo(struct torture_context *tctx,
3015 struct dcerpc_binding_handle *b,
3016 const char *servername,
3017 const char *share,
3018 struct srvsvc_NetShareInfo502 **info502)
3020 struct srvsvc_NetShareGetInfo r;
3021 union srvsvc_NetShareInfo info;
3023 r.in.server_unc = talloc_asprintf(tctx, "\\\\%s", servername);
3024 r.in.share_name = share;
3025 r.in.level = 502;
3026 r.out.info = &info;
3028 torture_assert_ntstatus_ok(tctx,
3029 dcerpc_srvsvc_NetShareGetInfo_r(b, tctx, &r),
3030 "srvsvc_NetShareGetInfo failed");
3031 torture_assert_werr_ok(tctx, r.out.result,
3032 "srvsvc_NetShareGetInfo failed");
3034 *info502 = talloc_move(tctx, &info.info502);
3036 return true;
3040 * Get us a handle on HKLM\
3043 static bool get_hklm_handle(struct torture_context *tctx,
3044 struct dcerpc_binding_handle *b,
3045 struct policy_handle *handle)
3047 struct winreg_OpenHKLM r;
3048 struct policy_handle result;
3050 r.in.system_name = 0;
3051 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3052 r.out.handle = &result;
3054 torture_assert_ntstatus_ok(tctx,
3055 dcerpc_winreg_OpenHKLM_r(b, tctx, &r),
3056 "OpenHKLM failed");
3057 torture_assert_werr_ok(tctx, r.out.result,
3058 "OpenHKLM failed");
3060 *handle = result;
3062 return true;
3065 static bool torture_samba3_createshare(struct torture_context *tctx,
3066 struct dcerpc_binding_handle *b,
3067 const char *sharename)
3069 struct policy_handle hklm;
3070 struct policy_handle new_handle;
3071 struct winreg_CreateKey c;
3072 struct winreg_CloseKey cl;
3073 enum winreg_CreateAction action_taken;
3075 c.in.handle = &hklm;
3076 c.in.name.name = talloc_asprintf(
3077 tctx, "software\\samba\\smbconf\\%s", sharename);
3078 torture_assert(tctx, c.in.name.name, "talloc_asprintf failed");
3080 c.in.keyclass.name = "";
3081 c.in.options = 0;
3082 c.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3083 c.in.secdesc = NULL;
3084 c.in.action_taken = &action_taken;
3085 c.out.new_handle = &new_handle;
3086 c.out.action_taken = &action_taken;
3088 torture_assert_ntstatus_ok(tctx,
3089 dcerpc_winreg_CreateKey_r(b, tctx, &c),
3090 "OpenKey failed");
3091 torture_assert_werr_ok(tctx, c.out.result,
3092 "OpenKey failed");
3094 cl.in.handle = &new_handle;
3095 cl.out.handle = &new_handle;
3097 torture_assert_ntstatus_ok(tctx,
3098 dcerpc_winreg_CloseKey_r(b, tctx, &cl),
3099 "CloseKey failed");
3100 torture_assert_werr_ok(tctx, cl.out.result,
3101 "CloseKey failed");
3103 return true;
3106 static bool torture_samba3_deleteshare(struct torture_context *tctx,
3107 struct dcerpc_binding_handle *b,
3108 const char *sharename)
3110 struct policy_handle hklm;
3111 struct winreg_DeleteKey d;
3113 torture_assert(tctx,
3114 get_hklm_handle(tctx, b, &hklm),
3115 "get_hklm_handle failed");
3117 d.in.handle = &hklm;
3118 d.in.key.name = talloc_asprintf(
3119 tctx, "software\\samba\\smbconf\\%s", sharename);
3120 torture_assert(tctx, d.in.key.name, "talloc_asprintf failed");
3122 torture_assert_ntstatus_ok(tctx,
3123 dcerpc_winreg_DeleteKey_r(b, tctx, &d),
3124 "DeleteKey failed");
3125 torture_assert_werr_ok(tctx, d.out.result,
3126 "DeleteKey failed");
3128 return true;
3131 static bool torture_samba3_setconfig(struct torture_context *tctx,
3132 struct dcerpc_binding_handle *b,
3133 const char *sharename,
3134 const char *parameter,
3135 const char *value)
3137 struct policy_handle hklm, key_handle;
3138 struct winreg_OpenKey o;
3139 struct winreg_SetValue s;
3140 uint32_t type;
3141 DATA_BLOB val;
3143 torture_assert(tctx,
3144 get_hklm_handle(tctx, b, &hklm),
3145 "get_hklm_handle failed");
3147 o.in.parent_handle = &hklm;
3148 o.in.keyname.name = talloc_asprintf(
3149 tctx, "software\\samba\\smbconf\\%s", sharename);
3150 torture_assert(tctx, o.in.keyname.name, "talloc_asprintf failed");
3152 o.in.options = 0;
3153 o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3154 o.out.handle = &key_handle;
3156 torture_assert_ntstatus_ok(tctx,
3157 dcerpc_winreg_OpenKey_r(b, tctx, &o),
3158 "OpenKey failed");
3159 torture_assert_werr_ok(tctx, o.out.result,
3160 "OpenKey failed");
3162 torture_assert(tctx,
3163 reg_string_to_val(tctx, "REG_SZ", value, &type, &val),
3164 "reg_string_to_val failed");
3166 s.in.handle = &key_handle;
3167 s.in.name.name = parameter;
3168 s.in.type = type;
3169 s.in.data = val.data;
3170 s.in.size = val.length;
3172 torture_assert_ntstatus_ok(tctx,
3173 dcerpc_winreg_SetValue_r(b, tctx, &s),
3174 "SetValue failed");
3175 torture_assert_werr_ok(tctx, s.out.result,
3176 "SetValue failed");
3178 return true;
3181 static bool torture_samba3_regconfig(struct torture_context *torture)
3183 struct srvsvc_NetShareInfo502 *i = NULL;
3184 const char *comment = "Dummer Kommentar";
3185 struct dcerpc_pipe *srvsvc_pipe, *winreg_pipe;
3187 torture_assert_ntstatus_ok(torture,
3188 torture_rpc_connection(torture, &srvsvc_pipe, &ndr_table_srvsvc),
3189 "failed to setup srvsvc");
3191 torture_assert_ntstatus_ok(torture,
3192 torture_rpc_connection(torture, &winreg_pipe, &ndr_table_winreg),
3193 "failed to setup winreg");
3195 torture_assert(torture,
3196 torture_samba3_createshare(torture, winreg_pipe->binding_handle, "blubber"),
3197 "torture_samba3_createshare failed");
3199 torture_assert(torture,
3200 torture_samba3_setconfig(torture, winreg_pipe->binding_handle, "blubber", "comment", comment),
3201 "torture_samba3_setconfig failed");
3203 torture_assert(torture,
3204 get_shareinfo(torture, srvsvc_pipe->binding_handle, dcerpc_server_name(srvsvc_pipe), "blubber", &i),
3205 "get_shareinfo failed");
3207 torture_assert_str_equal(torture, comment, i->comment,
3208 "got unexpected comment");
3210 torture_assert(torture,
3211 torture_samba3_deleteshare(torture, winreg_pipe->binding_handle, "blubber"),
3212 "torture_samba3_deleteshare failed");
3214 return true;
3218 * Test that even with a result of 0 rids the array is returned as a
3219 * non-NULL pointer. Yes, XP does notice.
3222 bool torture_samba3_getaliasmembership_0(struct torture_context *torture)
3224 struct dcerpc_pipe *p;
3225 struct dcerpc_binding_handle *b;
3226 struct samr_Connect2 c;
3227 struct samr_OpenDomain o;
3228 struct dom_sid sid;
3229 struct lsa_SidPtr ptr;
3230 struct lsa_SidArray sids;
3231 struct samr_GetAliasMembership g;
3232 struct samr_Ids rids;
3233 struct policy_handle samr, domain;
3235 torture_assert_ntstatus_ok(torture,
3236 torture_rpc_connection(torture, &p, &ndr_table_samr),
3237 "failed to setup samr");
3239 b = p->binding_handle;
3241 c.in.system_name = NULL;
3242 c.in.access_mask = SAMR_ACCESS_LOOKUP_DOMAIN;
3243 c.out.connect_handle = &samr;
3244 torture_assert_ntstatus_ok(torture,
3245 dcerpc_samr_Connect2_r(b, torture, &c),
3246 "");
3247 torture_assert_ntstatus_ok(torture, c.out.result,
3248 "");
3249 dom_sid_parse("S-1-5-32", &sid);
3250 o.in.connect_handle = &samr;
3251 o.in.access_mask = SAMR_DOMAIN_ACCESS_LOOKUP_ALIAS;
3252 o.in.sid = &sid;
3253 o.out.domain_handle = &domain;
3254 torture_assert_ntstatus_ok(torture,
3255 dcerpc_samr_OpenDomain_r(b, torture, &o),
3256 "");
3257 torture_assert_ntstatus_ok(torture, o.out.result,
3258 "");
3259 dom_sid_parse("S-1-2-3-4-5", &sid);
3260 ptr.sid = &sid;
3261 sids.num_sids = 1;
3262 sids.sids = &ptr;
3263 g.in.domain_handle = &domain;
3264 g.in.sids = &sids;
3265 g.out.rids = &rids;
3266 torture_assert_ntstatus_ok(torture,
3267 dcerpc_samr_GetAliasMembership_r(b, torture, &g),
3268 "");
3269 torture_assert_ntstatus_ok(torture, g.out.result,
3270 "");
3271 if (rids.ids == NULL) {
3272 /* This is the piece to test here */
3273 torture_fail(torture,
3274 "torture_samba3_getaliasmembership_0: "
3275 "Server returns NULL rids array\n");
3278 return true;
3282 * Test smb reauthentication while rpc pipe is in use.
3284 static bool torture_rpc_smb_reauth1(struct torture_context *torture)
3286 TALLOC_CTX *mem_ctx;
3287 NTSTATUS status;
3288 bool ret = false;
3289 struct smbcli_state *cli;
3290 struct smbcli_options options;
3291 struct smbcli_session_options session_options;
3293 struct dcerpc_pipe *lsa_pipe;
3294 struct dcerpc_binding_handle *lsa_handle;
3295 struct lsa_GetUserName r;
3296 struct lsa_String *authority_name_p = NULL;
3297 char *authority_name_saved = NULL;
3298 struct lsa_String *account_name_p = NULL;
3299 char *account_name_saved = NULL;
3300 struct cli_credentials *anon_creds = NULL;
3301 struct smb_composite_sesssetup io;
3303 mem_ctx = talloc_init("torture_samba3_reauth");
3304 torture_assert(torture, (mem_ctx != NULL), "talloc_init failed");
3306 lpcfg_smbcli_options(torture->lp_ctx, &options);
3307 lpcfg_smbcli_session_options(torture->lp_ctx, &session_options);
3309 status = smbcli_full_connection(mem_ctx, &cli,
3310 torture_setting_string(torture, "host", NULL),
3311 lpcfg_smb_ports(torture->lp_ctx),
3312 "IPC$", NULL,
3313 lpcfg_socket_options(torture->lp_ctx),
3314 cmdline_credentials,
3315 lpcfg_resolve_context(torture->lp_ctx),
3316 torture->ev, &options, &session_options,
3317 lpcfg_gensec_settings(torture, torture->lp_ctx));
3318 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3319 "smbcli_full_connection failed");
3321 lsa_pipe = dcerpc_pipe_init(mem_ctx, torture->ev);
3322 torture_assert_goto(torture, (lsa_pipe != NULL), ret, done,
3323 "dcerpc_pipe_init failed");
3324 lsa_handle = lsa_pipe->binding_handle;
3326 status = dcerpc_pipe_open_smb(lsa_pipe, cli->tree, "\\lsarpc");
3327 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3328 "dcerpc_pipe_open failed");
3330 status = dcerpc_bind_auth_none(lsa_pipe, &ndr_table_lsarpc);
3331 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3332 "dcerpc_bind_auth_none failed");
3334 /* lsa getusername */
3336 ZERO_STRUCT(r);
3337 r.in.system_name = "\\";
3338 r.in.account_name = &account_name_p;
3339 r.in.authority_name = &authority_name_p;
3340 r.out.account_name = &account_name_p;
3342 status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r);
3344 authority_name_p = *r.out.authority_name;
3346 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3347 "GetUserName failed");
3348 torture_assert_ntstatus_ok_goto(torture, r.out.result, ret, done,
3349 "GetUserName failed");
3351 torture_comment(torture, "lsa_GetUserName gave '%s\\%s'\n",
3352 authority_name_p->string,
3353 account_name_p->string);
3355 account_name_saved = talloc_strdup(mem_ctx, account_name_p->string);
3356 torture_assert_goto(torture, (account_name_saved != NULL), ret, done,
3357 "talloc failed");
3358 authority_name_saved = talloc_strdup(mem_ctx, authority_name_p->string);
3359 torture_assert_goto(torture, (authority_name_saved != NULL), ret, done,
3360 "talloc failed");
3362 /* smb re-authenticate as anonymous */
3364 anon_creds = cli_credentials_init_anon(mem_ctx);
3366 ZERO_STRUCT(io);
3367 io.in.sesskey = cli->transport->negotiate.sesskey;
3368 io.in.capabilities = cli->transport->negotiate.capabilities;
3369 io.in.credentials = anon_creds;
3370 io.in.workgroup = lpcfg_workgroup(torture->lp_ctx);
3371 io.in.gensec_settings = lpcfg_gensec_settings(torture, torture->lp_ctx);
3373 status = smb_composite_sesssetup(cli->session, &io);
3374 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3375 "session reauth to anon failed");
3377 /* re-do lsa getusername after reauth */
3379 TALLOC_FREE(authority_name_p);
3380 TALLOC_FREE(account_name_p);
3381 ZERO_STRUCT(r);
3382 r.in.system_name = "\\";
3383 r.in.account_name = &account_name_p;
3384 r.in.authority_name = &authority_name_p;
3385 r.out.account_name = &account_name_p;
3387 status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r);
3389 authority_name_p = *r.out.authority_name;
3391 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3392 "GetUserName failed");
3393 torture_assert_ntstatus_ok_goto(torture, r.out.result, ret, done,
3394 "GetUserName failed");
3396 torture_assert_goto(torture, (strcmp(authority_name_p->string, authority_name_saved) == 0),
3397 ret, done, "authority_name not equal after reauth to anon");
3398 torture_assert_goto(torture, (strcmp(account_name_p->string, account_name_saved) == 0),
3399 ret, done, "account_name not equal after reauth to anon");
3401 /* smb re-auth again to the original user */
3403 ZERO_STRUCT(io);
3404 io.in.sesskey = cli->transport->negotiate.sesskey;
3405 io.in.capabilities = cli->transport->negotiate.capabilities;
3406 io.in.credentials = cmdline_credentials;
3407 io.in.workgroup = lpcfg_workgroup(torture->lp_ctx);
3408 io.in.gensec_settings = lpcfg_gensec_settings(torture, torture->lp_ctx);
3410 status = smb_composite_sesssetup(cli->session, &io);
3411 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3412 "session reauth to anon failed");
3414 /* re-do lsa getusername */
3416 TALLOC_FREE(authority_name_p);
3417 TALLOC_FREE(account_name_p);
3418 ZERO_STRUCT(r);
3419 r.in.system_name = "\\";
3420 r.in.account_name = &account_name_p;
3421 r.in.authority_name = &authority_name_p;
3422 r.out.account_name = &account_name_p;
3424 status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r);
3426 authority_name_p = *r.out.authority_name;
3428 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3429 "GetUserName failed");
3430 torture_assert_ntstatus_ok_goto(torture, r.out.result, ret, done,
3431 "GetUserName failed");
3433 torture_assert_goto(torture, (strcmp(authority_name_p->string, authority_name_saved) == 0),
3434 ret, done, "authority_name not equal after reauth to anon");
3435 torture_assert_goto(torture, (strcmp(account_name_p->string, account_name_saved) == 0),
3436 ret, done, "account_name not equal after reauth to anon");
3438 ret = true;
3440 done:
3441 talloc_free(mem_ctx);
3442 return ret;
3446 * Test smb reauthentication while rpc pipe is in use.
3447 * Open a second lsa bind after reauth to anon.
3448 * Do lsa getusername on that second bind.
3450 static bool torture_rpc_smb_reauth2(struct torture_context *torture)
3452 TALLOC_CTX *mem_ctx;
3453 NTSTATUS status;
3454 bool ret = false;
3455 struct smbcli_state *cli;
3456 struct smbcli_options options;
3457 struct smbcli_session_options session_options;
3459 struct dcerpc_pipe *lsa_pipe;
3460 struct dcerpc_binding_handle *lsa_handle;
3461 struct lsa_GetUserName r;
3462 struct lsa_String *authority_name_p = NULL;
3463 char *authority_name_saved = NULL;
3464 struct lsa_String *account_name_p = NULL;
3465 char *account_name_saved = NULL;
3466 struct cli_credentials *anon_creds = NULL;
3467 struct smb_composite_sesssetup io;
3469 mem_ctx = talloc_init("torture_samba3_reauth");
3470 torture_assert(torture, (mem_ctx != NULL), "talloc_init failed");
3472 lpcfg_smbcli_options(torture->lp_ctx, &options);
3473 lpcfg_smbcli_session_options(torture->lp_ctx, &session_options);
3475 status = smbcli_full_connection(mem_ctx, &cli,
3476 torture_setting_string(torture, "host", NULL),
3477 lpcfg_smb_ports(torture->lp_ctx),
3478 "IPC$", NULL,
3479 lpcfg_socket_options(torture->lp_ctx),
3480 cmdline_credentials,
3481 lpcfg_resolve_context(torture->lp_ctx),
3482 torture->ev, &options, &session_options,
3483 lpcfg_gensec_settings(torture, torture->lp_ctx));
3484 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3485 "smbcli_full_connection failed");
3487 /* smb re-authenticate as anonymous */
3489 anon_creds = cli_credentials_init_anon(mem_ctx);
3491 ZERO_STRUCT(io);
3492 io.in.sesskey = cli->transport->negotiate.sesskey;
3493 io.in.capabilities = cli->transport->negotiate.capabilities;
3494 io.in.credentials = anon_creds;
3495 io.in.workgroup = lpcfg_workgroup(torture->lp_ctx);
3496 io.in.gensec_settings = lpcfg_gensec_settings(torture, torture->lp_ctx);
3498 status = smb_composite_sesssetup(cli->session, &io);
3499 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3500 "session reauth to anon failed");
3502 /* open the lsa pipe */
3504 lsa_pipe = dcerpc_pipe_init(mem_ctx, torture->ev);
3505 torture_assert_goto(torture, (lsa_pipe != NULL), ret, done,
3506 "dcerpc_pipe_init failed");
3507 lsa_handle = lsa_pipe->binding_handle;
3509 status = dcerpc_pipe_open_smb(lsa_pipe, cli->tree, "\\lsarpc");
3510 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3511 "dcerpc_pipe_open failed");
3513 status = dcerpc_bind_auth_none(lsa_pipe, &ndr_table_lsarpc);
3514 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3515 "dcerpc_bind_auth_none failed");
3517 /* lsa getusername */
3519 ZERO_STRUCT(r);
3520 r.in.system_name = "\\";
3521 r.in.account_name = &account_name_p;
3522 r.in.authority_name = &authority_name_p;
3523 r.out.account_name = &account_name_p;
3525 status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r);
3527 authority_name_p = *r.out.authority_name;
3529 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3530 "GetUserName failed");
3531 torture_assert_ntstatus_ok_goto(torture, r.out.result, ret, done,
3532 "GetUserName failed");
3534 torture_comment(torture, "lsa_GetUserName gave '%s\\%s'\n",
3535 authority_name_p->string,
3536 account_name_p->string);
3538 account_name_saved = talloc_strdup(mem_ctx, account_name_p->string);
3539 torture_assert_goto(torture, (account_name_saved != NULL), ret, done,
3540 "talloc failed");
3541 authority_name_saved = talloc_strdup(mem_ctx, authority_name_p->string);
3542 torture_assert_goto(torture, (authority_name_saved != NULL), ret, done,
3543 "talloc failed");
3545 /* smb re-auth again to the original user */
3547 ZERO_STRUCT(io);
3548 io.in.sesskey = cli->transport->negotiate.sesskey;
3549 io.in.capabilities = cli->transport->negotiate.capabilities;
3550 io.in.credentials = cmdline_credentials;
3551 io.in.workgroup = lpcfg_workgroup(torture->lp_ctx);
3552 io.in.gensec_settings = lpcfg_gensec_settings(torture, torture->lp_ctx);
3554 status = smb_composite_sesssetup(cli->session, &io);
3555 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3556 "session reauth to anon failed");
3558 /* re-do lsa getusername after reauth */
3560 TALLOC_FREE(authority_name_p);
3561 TALLOC_FREE(account_name_p);
3562 ZERO_STRUCT(r);
3563 r.in.system_name = "\\";
3564 r.in.account_name = &account_name_p;
3565 r.in.authority_name = &authority_name_p;
3566 r.out.account_name = &account_name_p;
3568 status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r);
3570 authority_name_p = *r.out.authority_name;
3572 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3573 "GetUserName failed");
3574 torture_assert_ntstatus_ok_goto(torture, r.out.result, ret, done,
3575 "GetUserName failed");
3577 torture_assert_goto(torture, (strcmp(authority_name_p->string, authority_name_saved) == 0),
3578 ret, done, "authority_name not equal after reauth to anon");
3579 torture_assert_goto(torture, (strcmp(account_name_p->string, account_name_saved) == 0),
3580 ret, done, "account_name not equal after reauth to anon");
3582 ret = true;
3584 done:
3585 talloc_free(mem_ctx);
3586 return ret;
3590 * Test smb2 reauthentication while rpc pipe is in use.
3592 static bool torture_rpc_smb2_reauth1(struct torture_context *torture)
3594 TALLOC_CTX *mem_ctx;
3595 NTSTATUS status;
3596 bool ret = false;
3597 struct smbcli_options options;
3599 struct dcerpc_pipe *lsa_pipe;
3600 struct dcerpc_binding_handle *lsa_handle;
3601 struct lsa_GetUserName r;
3602 struct lsa_String *authority_name_p = NULL;
3603 char *authority_name_saved = NULL;
3604 struct lsa_String *account_name_p = NULL;
3605 char *account_name_saved = NULL;
3606 struct cli_credentials *anon_creds = NULL;
3607 const char *host = torture_setting_string(torture, "host", NULL);
3608 struct smb2_tree *tree;
3610 mem_ctx = talloc_init("torture_samba3_reauth");
3611 torture_assert(torture, (mem_ctx != NULL), "talloc_init failed");
3613 lpcfg_smbcli_options(torture->lp_ctx, &options);
3615 status = smb2_connect(mem_ctx,
3616 host,
3617 lpcfg_smb_ports(torture->lp_ctx),
3618 "IPC$",
3619 lpcfg_resolve_context(torture->lp_ctx),
3620 cmdline_credentials,
3621 &tree,
3622 torture->ev,
3623 &options,
3624 lpcfg_socket_options(torture->lp_ctx),
3625 lpcfg_gensec_settings(torture, torture->lp_ctx)
3627 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3628 "smb2_connect failed");
3630 lsa_pipe = dcerpc_pipe_init(mem_ctx, torture->ev);
3631 torture_assert_goto(torture, (lsa_pipe != NULL), ret, done,
3632 "dcerpc_pipe_init failed");
3633 lsa_handle = lsa_pipe->binding_handle;
3635 status = dcerpc_pipe_open_smb2(lsa_pipe, tree, "lsarpc");
3636 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3637 "dcerpc_pipe_open_smb2 failed");
3639 status = dcerpc_bind_auth_none(lsa_pipe, &ndr_table_lsarpc);
3640 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3641 "dcerpc_bind_auth_none failed");
3643 /* lsa getusername */
3645 ZERO_STRUCT(r);
3646 r.in.system_name = "\\";
3647 r.in.account_name = &account_name_p;
3648 r.in.authority_name = &authority_name_p;
3649 r.out.account_name = &account_name_p;
3651 status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r);
3653 authority_name_p = *r.out.authority_name;
3655 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3656 "GetUserName failed");
3657 torture_assert_ntstatus_ok_goto(torture, r.out.result, ret, done,
3658 "GetUserName failed");
3660 torture_comment(torture, "lsa_GetUserName gave '%s\\%s'\n",
3661 authority_name_p->string,
3662 account_name_p->string);
3664 account_name_saved = talloc_strdup(mem_ctx, account_name_p->string);
3665 torture_assert_goto(torture, (account_name_saved != NULL), ret, done,
3666 "talloc failed");
3667 authority_name_saved = talloc_strdup(mem_ctx, authority_name_p->string);
3668 torture_assert_goto(torture, (authority_name_saved != NULL), ret, done,
3669 "talloc failed");
3671 /* smb re-authenticate as anonymous */
3673 anon_creds = cli_credentials_init_anon(mem_ctx);
3675 status = smb2_session_setup_spnego(tree->session,
3676 anon_creds,
3677 0 /* previous_session_id */);
3678 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3679 "session reauth to anon failed");
3681 /* re-do lsa getusername after reauth */
3683 TALLOC_FREE(authority_name_p);
3684 TALLOC_FREE(account_name_p);
3685 ZERO_STRUCT(r);
3686 r.in.system_name = "\\";
3687 r.in.account_name = &account_name_p;
3688 r.in.authority_name = &authority_name_p;
3689 r.out.account_name = &account_name_p;
3691 status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r);
3693 authority_name_p = *r.out.authority_name;
3695 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3696 "GetUserName failed");
3697 torture_assert_ntstatus_ok_goto(torture, r.out.result, ret, done,
3698 "GetUserName failed");
3700 torture_assert_goto(torture, (strcmp(authority_name_p->string, authority_name_saved) == 0),
3701 ret, done, "authority_name not equal after reauth to anon");
3702 torture_assert_goto(torture, (strcmp(account_name_p->string, account_name_saved) == 0),
3703 ret, done, "account_name not equal after reauth to anon");
3705 /* smb re-auth again to the original user */
3707 status = smb2_session_setup_spnego(tree->session,
3708 cmdline_credentials,
3709 0 /* previous_session_id */);
3710 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3711 "session reauth to anon failed");
3713 /* re-do lsa getusername */
3715 TALLOC_FREE(authority_name_p);
3716 TALLOC_FREE(account_name_p);
3717 ZERO_STRUCT(r);
3718 r.in.system_name = "\\";
3719 r.in.account_name = &account_name_p;
3720 r.in.authority_name = &authority_name_p;
3721 r.out.account_name = &account_name_p;
3723 status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r);
3725 authority_name_p = *r.out.authority_name;
3727 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3728 "GetUserName failed");
3729 torture_assert_ntstatus_ok_goto(torture, r.out.result, ret, done,
3730 "GetUserName failed");
3732 torture_assert_goto(torture, (strcmp(authority_name_p->string, authority_name_saved) == 0),
3733 ret, done, "authority_name not equal after reauth to anon");
3734 torture_assert_goto(torture, (strcmp(account_name_p->string, account_name_saved) == 0),
3735 ret, done, "account_name not equal after reauth to anon");
3737 ret = true;
3739 done:
3740 talloc_free(mem_ctx);
3741 return ret;
3745 * Test smb2 reauthentication while rpc pipe is in use.
3746 * Open a second lsa bind after reauth to anon.
3747 * Do lsa getusername on that second bind.
3749 static bool torture_rpc_smb2_reauth2(struct torture_context *torture)
3751 TALLOC_CTX *mem_ctx;
3752 NTSTATUS status;
3753 bool ret = false;
3754 struct smbcli_options options;
3756 struct dcerpc_pipe *lsa_pipe;
3757 struct dcerpc_binding_handle *lsa_handle;
3758 struct lsa_GetUserName r;
3759 struct lsa_String *authority_name_p = NULL;
3760 char *authority_name_saved = NULL;
3761 struct lsa_String *account_name_p = NULL;
3762 char *account_name_saved = NULL;
3763 struct cli_credentials *anon_creds = NULL;
3764 const char *host = torture_setting_string(torture, "host", NULL);
3765 struct smb2_tree *tree;
3767 mem_ctx = talloc_init("torture_samba3_reauth");
3768 torture_assert(torture, (mem_ctx != NULL), "talloc_init failed");
3770 lpcfg_smbcli_options(torture->lp_ctx, &options);
3772 status = smb2_connect(mem_ctx,
3773 host,
3774 lpcfg_smb_ports(torture->lp_ctx),
3775 "IPC$",
3776 lpcfg_resolve_context(torture->lp_ctx),
3777 cmdline_credentials,
3778 &tree,
3779 torture->ev,
3780 &options,
3781 lpcfg_socket_options(torture->lp_ctx),
3782 lpcfg_gensec_settings(torture, torture->lp_ctx)
3784 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3785 "smb2_connect failed");
3787 /* smb re-authenticate as anonymous */
3789 anon_creds = cli_credentials_init_anon(mem_ctx);
3791 status = smb2_session_setup_spnego(tree->session,
3792 anon_creds,
3793 0 /* previous_session_id */);
3794 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3795 "session reauth to anon failed");
3797 /* open the lsa pipe */
3799 lsa_pipe = dcerpc_pipe_init(mem_ctx, torture->ev);
3800 torture_assert_goto(torture, (lsa_pipe != NULL), ret, done,
3801 "dcerpc_pipe_init failed");
3802 lsa_handle = lsa_pipe->binding_handle;
3804 status = dcerpc_pipe_open_smb2(lsa_pipe, tree, "lsarpc");
3805 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3806 "dcerpc_pipe_open_smb2 failed");
3808 status = dcerpc_bind_auth_none(lsa_pipe, &ndr_table_lsarpc);
3809 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3810 "dcerpc_bind_auth_none failed");
3812 /* lsa getusername */
3814 ZERO_STRUCT(r);
3815 r.in.system_name = "\\";
3816 r.in.account_name = &account_name_p;
3817 r.in.authority_name = &authority_name_p;
3818 r.out.account_name = &account_name_p;
3820 status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r);
3822 authority_name_p = *r.out.authority_name;
3824 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3825 "GetUserName failed");
3826 torture_assert_ntstatus_ok_goto(torture, r.out.result, ret, done,
3827 "GetUserName failed");
3829 torture_comment(torture, "lsa_GetUserName gave '%s\\%s'\n",
3830 authority_name_p->string,
3831 account_name_p->string);
3833 account_name_saved = talloc_strdup(mem_ctx, account_name_p->string);
3834 torture_assert_goto(torture, (account_name_saved != NULL), ret, done,
3835 "talloc failed");
3836 authority_name_saved = talloc_strdup(mem_ctx, authority_name_p->string);
3837 torture_assert_goto(torture, (authority_name_saved != NULL), ret, done,
3838 "talloc failed");
3840 /* smb re-auth again to the original user */
3842 status = smb2_session_setup_spnego(tree->session,
3843 cmdline_credentials,
3844 0 /* previous_session_id */);
3845 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3846 "session reauth to anon failed");
3848 /* re-do lsa getusername */
3850 TALLOC_FREE(authority_name_p);
3851 TALLOC_FREE(account_name_p);
3852 ZERO_STRUCT(r);
3853 r.in.system_name = "\\";
3854 r.in.account_name = &account_name_p;
3855 r.in.authority_name = &authority_name_p;
3856 r.out.account_name = &account_name_p;
3858 status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r);
3860 authority_name_p = *r.out.authority_name;
3862 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3863 "GetUserName failed");
3864 torture_assert_ntstatus_ok_goto(torture, r.out.result, ret, done,
3865 "GetUserName failed");
3867 torture_assert_goto(torture, (strcmp(authority_name_p->string, authority_name_saved) == 0),
3868 ret, done, "authority_name not equal after reauth to anon");
3869 torture_assert_goto(torture, (strcmp(account_name_p->string, account_name_saved) == 0),
3870 ret, done, "account_name not equal after reauth to anon");
3872 ret = true;
3874 done:
3875 talloc_free(mem_ctx);
3876 return ret;
3879 static bool torture_rpc_smb1_pipe_name(struct torture_context *torture)
3881 TALLOC_CTX *mem_ctx;
3882 NTSTATUS status;
3883 bool ret = false;
3884 struct smbcli_state *cli;
3885 struct smbcli_options options;
3886 struct smbcli_session_options session_options;
3887 union smb_open io;
3888 union smb_close cl;
3889 uint16_t fnum;
3891 mem_ctx = talloc_init("torture_samba3_smb1_pipe_name");
3892 torture_assert(torture, (mem_ctx != NULL), "talloc_init failed");
3894 lpcfg_smbcli_options(torture->lp_ctx, &options);
3895 lpcfg_smbcli_session_options(torture->lp_ctx, &session_options);
3897 status = smbcli_full_connection(mem_ctx, &cli,
3898 torture_setting_string(torture, "host", NULL),
3899 lpcfg_smb_ports(torture->lp_ctx),
3900 "IPC$", NULL,
3901 lpcfg_socket_options(torture->lp_ctx),
3902 cmdline_credentials,
3903 lpcfg_resolve_context(torture->lp_ctx),
3904 torture->ev, &options, &session_options,
3905 lpcfg_gensec_settings(torture, torture->lp_ctx));
3906 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3907 "smbcli_full_connection failed");
3909 ZERO_STRUCT(io);
3910 io.generic.level = RAW_OPEN_NTCREATEX;
3911 io.ntcreatex.in.access_mask = DESIRED_ACCESS_PIPE;
3912 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ|
3913 NTCREATEX_SHARE_ACCESS_WRITE;
3914 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
3915 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_IMPERSONATION;
3916 io.ntcreatex.in.security_flags = 0;
3918 io.ntcreatex.in.fname = "__none__";
3919 status = smb_raw_open(cli->tree, torture, &io);
3920 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_NAME_NOT_FOUND,
3921 ret, done,
3922 "smb_raw_open for '__none__'");
3924 io.ntcreatex.in.fname = "pipe\\srvsvc";
3925 status = smb_raw_open(cli->tree, torture, &io);
3926 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_NAME_NOT_FOUND,
3927 ret, done,
3928 "smb_raw_open for 'pipe\\srvsvc'");
3930 io.ntcreatex.in.fname = "\\pipe\\srvsvc";
3931 status = smb_raw_open(cli->tree, torture, &io);
3932 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_NAME_NOT_FOUND,
3933 ret, done,
3934 "smb_raw_open for '\\pipe\\srvsvc'");
3936 io.ntcreatex.in.fname = "srvsvc";
3937 status = smb_raw_open(cli->tree, torture, &io);
3938 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3939 "smb2_create failed for 'srvsvc'");
3940 fnum = io.ntcreatex.out.file.fnum;
3941 ZERO_STRUCT(cl);
3942 cl.generic.level = RAW_CLOSE_CLOSE;
3943 cl.close.in.file.fnum = fnum;
3944 status = smb_raw_close(cli->tree, &cl);
3945 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3946 "smb_raw_close failed");
3948 io.ntcreatex.in.fname = "\\srvsvc";
3949 status = smb_raw_open(cli->tree, torture, &io);
3950 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3951 "smb2_create failed for '\\srvsvc'");
3952 fnum = io.ntcreatex.out.file.fnum;
3953 ZERO_STRUCT(cl);
3954 cl.generic.level = RAW_CLOSE_CLOSE;
3955 cl.close.in.file.fnum = fnum;
3956 status = smb_raw_close(cli->tree, &cl);
3957 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3958 "smb_raw_close failed");
3960 io.ntcreatex.in.fname = "\\\\\\\\\\srvsvc";
3961 status = smb_raw_open(cli->tree, torture, &io);
3962 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3963 "smb2_create failed for '\\\\\\\\\\srvsvc'");
3964 fnum = io.ntcreatex.out.file.fnum;
3965 ZERO_STRUCT(cl);
3966 cl.generic.level = RAW_CLOSE_CLOSE;
3967 cl.close.in.file.fnum = fnum;
3968 status = smb_raw_close(cli->tree, &cl);
3969 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3970 "smb_raw_close failed");
3972 ZERO_STRUCT(io);
3973 io.generic.level = RAW_OPEN_NTTRANS_CREATE;
3974 io.nttrans.in.access_mask = DESIRED_ACCESS_PIPE;
3975 io.nttrans.in.share_access = NTCREATEX_SHARE_ACCESS_READ|
3976 NTCREATEX_SHARE_ACCESS_WRITE;
3977 io.nttrans.in.open_disposition = NTCREATEX_DISP_OPEN;
3978 io.nttrans.in.impersonation = NTCREATEX_IMPERSONATION_IMPERSONATION;
3979 io.nttrans.in.security_flags = 0;
3981 io.nttrans.in.fname = "__none__";
3982 status = smb_raw_open(cli->tree, torture, &io);
3983 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_NAME_NOT_FOUND,
3984 ret, done,
3985 "smb_raw_open for '__none__'");
3987 io.nttrans.in.fname = "pipe\\srvsvc";
3988 status = smb_raw_open(cli->tree, torture, &io);
3989 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_NAME_NOT_FOUND,
3990 ret, done,
3991 "smb_raw_open for 'pipe\\srvsvc'");
3993 io.nttrans.in.fname = "\\pipe\\srvsvc";
3994 status = smb_raw_open(cli->tree, torture, &io);
3995 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_NAME_NOT_FOUND,
3996 ret, done,
3997 "smb_raw_open for '\\pipe\\srvsvc'");
3999 io.nttrans.in.fname = "srvsvc";
4000 status = smb_raw_open(cli->tree, torture, &io);
4001 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4002 "smb2_create failed for 'srvsvc'");
4003 fnum = io.nttrans.out.file.fnum;
4004 ZERO_STRUCT(cl);
4005 cl.generic.level = RAW_CLOSE_CLOSE;
4006 cl.close.in.file.fnum = fnum;
4007 status = smb_raw_close(cli->tree, &cl);
4008 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4009 "smb_raw_close failed");
4011 io.nttrans.in.fname = "\\srvsvc";
4012 status = smb_raw_open(cli->tree, torture, &io);
4013 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4014 "smb2_create failed for '\\srvsvc'");
4015 fnum = io.nttrans.out.file.fnum;
4016 ZERO_STRUCT(cl);
4017 cl.generic.level = RAW_CLOSE_CLOSE;
4018 cl.close.in.file.fnum = fnum;
4019 status = smb_raw_close(cli->tree, &cl);
4020 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4021 "smb_raw_close failed");
4023 io.nttrans.in.fname = "\\\\\\\\\\srvsvc";
4024 status = smb_raw_open(cli->tree, torture, &io);
4025 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4026 "smb2_create failed for '\\\\\\\\\\srvsvc'");
4027 fnum = io.nttrans.out.file.fnum;
4028 ZERO_STRUCT(cl);
4029 cl.generic.level = RAW_CLOSE_CLOSE;
4030 cl.close.in.file.fnum = fnum;
4031 status = smb_raw_close(cli->tree, &cl);
4032 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4033 "smb_raw_close failed");
4035 ZERO_STRUCT(io);
4036 io.generic.level = RAW_OPEN_OPENX;
4037 io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR;
4038 io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN;
4040 io.openx.in.fname = "__none__";
4041 status = smb_raw_open(cli->tree, torture, &io);
4042 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_PATH_SYNTAX_BAD,
4043 ret, done,
4044 "smb_raw_open for '__none__'");
4046 io.openx.in.fname = "srvsvc";
4047 status = smb_raw_open(cli->tree, torture, &io);
4048 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_PATH_SYNTAX_BAD,
4049 ret, done,
4050 "smb_raw_open for 'srvsvc'");
4052 io.openx.in.fname = "\\srvsvc";
4053 status = smb_raw_open(cli->tree, torture, &io);
4054 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_PATH_SYNTAX_BAD,
4055 ret, done,
4056 "smb_raw_open for '\\srvsvc'");
4058 io.openx.in.fname = "\\pipesrvsvc";
4059 status = smb_raw_open(cli->tree, torture, &io);
4060 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_PATH_SYNTAX_BAD,
4061 ret, done,
4062 "smb_raw_open for '\\pipesrvsvc'");
4064 io.openx.in.fname = "pipe\\__none__";
4065 status = smb_raw_open(cli->tree, torture, &io);
4066 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_NAME_NOT_FOUND,
4067 ret, done,
4068 "smb_raw_open for 'pipe\\__none__'");
4070 io.openx.in.fname = "\\pipe\\__none__";
4071 status = smb_raw_open(cli->tree, torture, &io);
4072 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_NAME_NOT_FOUND,
4073 ret, done,
4074 "smb_raw_open for '\\pipe\\__none__'");
4076 io.openx.in.fname = "pipe\\srvsvc";
4077 status = smb_raw_open(cli->tree, torture, &io);
4078 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4079 "smb2_create failed for 'pipe\\srvsvc'");
4080 fnum = io.openx.out.file.fnum;
4081 ZERO_STRUCT(cl);
4082 cl.generic.level = RAW_CLOSE_CLOSE;
4083 cl.close.in.file.fnum = fnum;
4084 status = smb_raw_close(cli->tree, &cl);
4085 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4086 "smb_raw_close failed");
4088 io.openx.in.fname = "\\pipe\\srvsvc";
4089 status = smb_raw_open(cli->tree, torture, &io);
4090 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4091 "smb2_create failed for '\\pipe\\srvsvc'");
4092 fnum = io.openx.out.file.fnum;
4093 ZERO_STRUCT(cl);
4094 cl.generic.level = RAW_CLOSE_CLOSE;
4095 cl.close.in.file.fnum = fnum;
4096 status = smb_raw_close(cli->tree, &cl);
4097 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4098 "smb_raw_close failed");
4100 io.openx.in.fname = "\\\\\\\\\\pipe\\srvsvc";
4101 status = smb_raw_open(cli->tree, torture, &io);
4102 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4103 "smb2_create failed for '\\\\\\\\\\pipe\\srvsvc'");
4104 fnum = io.openx.out.file.fnum;
4105 ZERO_STRUCT(cl);
4106 cl.generic.level = RAW_CLOSE_CLOSE;
4107 cl.close.in.file.fnum = fnum;
4108 status = smb_raw_close(cli->tree, &cl);
4109 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4110 "smb_raw_close failed");
4112 io.openx.in.fname = "\\\\\\\\\\pipe\\\\\\\\\\srvsvc";
4113 status = smb_raw_open(cli->tree, torture, &io);
4114 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4115 "smb2_create failed for '\\\\\\\\\\pipe\\\\\\\\\\srvsvc'");
4116 fnum = io.openx.out.file.fnum;
4117 ZERO_STRUCT(cl);
4118 cl.generic.level = RAW_CLOSE_CLOSE;
4119 cl.close.in.file.fnum = fnum;
4120 status = smb_raw_close(cli->tree, &cl);
4121 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4122 "smb_raw_close failed");
4123 ret = true;
4125 done:
4126 talloc_free(mem_ctx);
4127 return ret;
4130 static bool torture_rpc_smb2_pipe_name(struct torture_context *torture)
4132 TALLOC_CTX *mem_ctx;
4133 NTSTATUS status;
4134 bool ret = false;
4135 struct smbcli_options options;
4136 const char *host = torture_setting_string(torture, "host", NULL);
4137 struct smb2_tree *tree;
4138 struct smb2_handle h;
4139 struct smb2_create io;
4141 mem_ctx = talloc_init("torture_samba3_smb2_pipe_name");
4142 torture_assert(torture, (mem_ctx != NULL), "talloc_init failed");
4144 lpcfg_smbcli_options(torture->lp_ctx, &options);
4146 status = smb2_connect(mem_ctx,
4147 host,
4148 lpcfg_smb_ports(torture->lp_ctx),
4149 "IPC$",
4150 lpcfg_resolve_context(torture->lp_ctx),
4151 cmdline_credentials,
4152 &tree,
4153 torture->ev,
4154 &options,
4155 lpcfg_socket_options(torture->lp_ctx),
4156 lpcfg_gensec_settings(torture, torture->lp_ctx)
4158 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4159 "smb2_connect failed");
4161 ZERO_STRUCT(io);
4162 io.in.oplock_level = 0;
4163 io.in.desired_access = DESIRED_ACCESS_PIPE;
4164 io.in.impersonation_level = SMB2_IMPERSONATION_IMPERSONATION;
4165 io.in.file_attributes = 0;
4166 io.in.create_disposition = NTCREATEX_DISP_OPEN;
4167 io.in.share_access =
4168 NTCREATEX_SHARE_ACCESS_READ|
4169 NTCREATEX_SHARE_ACCESS_WRITE;
4170 io.in.create_options = 0;
4172 io.in.fname = "__none__";
4173 status = smb2_create(tree, tree, &io);
4174 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_NAME_NOT_FOUND,
4175 ret, done,
4176 "smb2_create for '__none__'");
4178 io.in.fname = "\\srvsvc";
4179 status = smb2_create(tree, tree, &io);
4180 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_NAME_NOT_FOUND,
4181 ret, done,
4182 "smb2_create for '\\srvsvc'");
4184 io.in.fname = "\\pipe\\srvsvc";
4185 status = smb2_create(tree, tree, &io);
4186 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_NAME_NOT_FOUND,
4187 ret, done,
4188 "smb2_create for '\\pipe\\srvsvc'");
4190 io.in.fname = "pipe\\srvsvc";
4191 status = smb2_create(tree, tree, &io);
4192 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_NAME_NOT_FOUND,
4193 ret, done,
4194 "smb2_create for 'pipe\\srvsvc'");
4196 io.in.fname = "srvsvc";
4197 status = smb2_create(tree, tree, &io);
4198 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4199 "smb2_create failed for 'srvsvc'");
4201 h = io.out.file.handle;
4203 status = smb2_util_close(tree, h);
4204 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4205 "smb2_util_close failed");
4207 ret = true;
4208 done:
4209 talloc_free(mem_ctx);
4210 return ret;
4214 * Test behaviour of a waiting read call on a pipe when
4215 * the pipe handle is closed:
4216 * - open a pipe via smb2
4217 * - trigger a read which hangs since there is nothing to read
4218 * - close the pipe file handle
4219 * - wait for the read to return and check the status
4220 * (STATUS_PIPE_BROKEN)
4222 static bool torture_rpc_smb2_pipe_read_close(struct torture_context *torture)
4224 TALLOC_CTX *mem_ctx;
4225 NTSTATUS status;
4226 bool ret = false;
4227 struct smbcli_options options;
4228 const char *host = torture_setting_string(torture, "host", NULL);
4229 struct smb2_tree *tree;
4230 struct smb2_handle h;
4231 struct smb2_request *smb2req;
4232 struct smb2_create io;
4233 struct smb2_read rd;
4235 mem_ctx = talloc_init("torture_samba3_pipe_read_close");
4236 torture_assert(torture, (mem_ctx != NULL), "talloc_init failed");
4238 lpcfg_smbcli_options(torture->lp_ctx, &options);
4240 status = smb2_connect(mem_ctx,
4241 host,
4242 lpcfg_smb_ports(torture->lp_ctx),
4243 "IPC$",
4244 lpcfg_resolve_context(torture->lp_ctx),
4245 cmdline_credentials,
4246 &tree,
4247 torture->ev,
4248 &options,
4249 lpcfg_socket_options(torture->lp_ctx),
4250 lpcfg_gensec_settings(torture, torture->lp_ctx)
4252 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4253 "smb2_connect failed");
4255 ZERO_STRUCT(io);
4256 io.in.oplock_level = 0;
4257 io.in.desired_access = DESIRED_ACCESS_PIPE;
4258 io.in.impersonation_level = SMB2_IMPERSONATION_IMPERSONATION;
4259 io.in.file_attributes = 0;
4260 io.in.create_disposition = NTCREATEX_DISP_OPEN;
4261 io.in.share_access =
4262 NTCREATEX_SHARE_ACCESS_READ|
4263 NTCREATEX_SHARE_ACCESS_WRITE;
4264 io.in.create_options = 0;
4265 io.in.fname = "lsarpc";
4267 status = smb2_create(tree, tree, &io);
4268 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4269 "smb2_create failed for 'lsarpc'");
4271 h = io.out.file.handle;
4273 ZERO_STRUCT(rd);
4274 rd.in.file.handle = h;
4275 rd.in.length = 1024;
4276 rd.in.offset = 0;
4277 rd.in.min_count = 0;
4279 smb2req = smb2_read_send(tree, &rd);
4280 torture_assert_goto(torture, (smb2req != NULL), ret, done,
4281 "smb2_read_send failed");
4283 status = smb2_util_close(tree, h);
4284 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4285 "smb2_util_close failed");
4287 status = smb2_read_recv(smb2req, mem_ctx, &rd);
4288 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_PIPE_BROKEN, ret, done,
4289 "smb2_read_recv: unexpected return code");
4291 ret = true;
4292 done:
4293 talloc_free(mem_ctx);
4294 return ret;
4298 * Test behaviour of a waiting read call on a pipe when
4299 * the tree is disconnected.
4300 * - open a pipe via smb2
4301 * - trigger a read which hangs since there is nothing to read
4302 * - do a tree disconnect
4303 * - wait for the read to return and check the status
4304 * (STATUS_PIPE_BROKEN)
4306 static bool torture_rpc_smb2_pipe_read_tdis(struct torture_context *torture)
4308 TALLOC_CTX *mem_ctx;
4309 NTSTATUS status;
4310 bool ret = false;
4311 struct smbcli_options options;
4312 const char *host = torture_setting_string(torture, "host", NULL);
4313 struct smb2_tree *tree;
4314 struct smb2_handle h;
4315 struct smb2_request *smb2req;
4316 struct smb2_create io;
4317 struct smb2_read rd;
4319 mem_ctx = talloc_init("torture_samba3_pipe_read_tdis");
4320 torture_assert(torture, (mem_ctx != NULL), "talloc_init failed");
4322 lpcfg_smbcli_options(torture->lp_ctx, &options);
4324 status = smb2_connect(mem_ctx,
4325 host,
4326 lpcfg_smb_ports(torture->lp_ctx),
4327 "IPC$",
4328 lpcfg_resolve_context(torture->lp_ctx),
4329 cmdline_credentials,
4330 &tree,
4331 torture->ev,
4332 &options,
4333 lpcfg_socket_options(torture->lp_ctx),
4334 lpcfg_gensec_settings(torture, torture->lp_ctx)
4336 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4337 "smb2_connect failed");
4339 ZERO_STRUCT(io);
4340 io.in.oplock_level = 0;
4341 io.in.desired_access = DESIRED_ACCESS_PIPE;
4342 io.in.impersonation_level = SMB2_IMPERSONATION_IMPERSONATION;
4343 io.in.file_attributes = 0;
4344 io.in.create_disposition = NTCREATEX_DISP_OPEN;
4345 io.in.share_access =
4346 NTCREATEX_SHARE_ACCESS_READ|
4347 NTCREATEX_SHARE_ACCESS_WRITE;
4348 io.in.create_options = 0;
4349 io.in.fname = "lsarpc";
4351 status = smb2_create(tree, tree, &io);
4352 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4353 "smb2_create failed for 'lsarpc'");
4355 h = io.out.file.handle;
4357 ZERO_STRUCT(rd);
4358 rd.in.file.handle = h;
4359 rd.in.length = 1024;
4360 rd.in.offset = 0;
4361 rd.in.min_count = 0;
4363 smb2req = smb2_read_send(tree, &rd);
4364 torture_assert_goto(torture, (smb2req != NULL), ret, done,
4365 "smb2_read_send failed");
4367 status = smb2_tdis(tree);
4368 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4369 "smb2_tdis failed");
4371 status = smb2_read_recv(smb2req, mem_ctx, &rd);
4372 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_PIPE_BROKEN, ret, done,
4373 "smb2_read_recv: unexpected return code");
4375 ret = true;
4376 done:
4377 talloc_free(mem_ctx);
4378 return ret;
4382 * Test behaviour of a waiting read call on a pipe when
4383 * the user logs off
4384 * - open a pipe via smb2
4385 * - trigger a read which hangs since there is nothing to read
4386 * - do a logoff
4387 * - wait for the read to return and check the status
4388 * (STATUS_PIPE_BROKEN)
4390 static bool torture_rpc_smb2_pipe_read_logoff(struct torture_context *torture)
4392 TALLOC_CTX *mem_ctx;
4393 NTSTATUS status;
4394 bool ret = false;
4395 struct smbcli_options options;
4396 const char *host = torture_setting_string(torture, "host", NULL);
4397 struct smb2_tree *tree;
4398 struct smb2_handle h;
4399 struct smb2_request *smb2req;
4400 struct smb2_create io;
4401 struct smb2_read rd;
4403 mem_ctx = talloc_init("torture_samba3_pipe_read_tdis");
4404 torture_assert(torture, (mem_ctx != NULL), "talloc_init failed");
4406 lpcfg_smbcli_options(torture->lp_ctx, &options);
4408 status = smb2_connect(mem_ctx,
4409 host,
4410 lpcfg_smb_ports(torture->lp_ctx),
4411 "IPC$",
4412 lpcfg_resolve_context(torture->lp_ctx),
4413 cmdline_credentials,
4414 &tree,
4415 torture->ev,
4416 &options,
4417 lpcfg_socket_options(torture->lp_ctx),
4418 lpcfg_gensec_settings(torture, torture->lp_ctx)
4420 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4421 "smb2_connect failed");
4423 ZERO_STRUCT(io);
4424 io.in.oplock_level = 0;
4425 io.in.desired_access = DESIRED_ACCESS_PIPE;
4426 io.in.impersonation_level = SMB2_IMPERSONATION_IMPERSONATION;
4427 io.in.file_attributes = 0;
4428 io.in.create_disposition = NTCREATEX_DISP_OPEN;
4429 io.in.share_access =
4430 NTCREATEX_SHARE_ACCESS_READ|
4431 NTCREATEX_SHARE_ACCESS_WRITE;
4432 io.in.create_options = 0;
4433 io.in.fname = "lsarpc";
4435 status = smb2_create(tree, tree, &io);
4436 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4437 "smb2_create failed for 'lsarpc'");
4439 h = io.out.file.handle;
4441 ZERO_STRUCT(rd);
4442 rd.in.file.handle = h;
4443 rd.in.length = 1024;
4444 rd.in.offset = 0;
4445 rd.in.min_count = 0;
4447 smb2req = smb2_read_send(tree, &rd);
4448 torture_assert_goto(torture, (smb2req != NULL), ret, done,
4449 "smb2_read_send failed");
4451 status = smb2_logoff(tree->session);
4452 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4453 "smb2_logoff failed");
4455 status = smb2_read_recv(smb2req, mem_ctx, &rd);
4456 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_PIPE_BROKEN, ret, done,
4457 "smb2_read_recv: unexpected return code");
4459 ret = true;
4460 done:
4461 talloc_free(mem_ctx);
4462 return ret;
4466 struct torture_suite *torture_rpc_samba3(TALLOC_CTX *mem_ctx)
4468 struct torture_suite *suite = torture_suite_create(mem_ctx, "samba3");
4470 torture_suite_add_simple_test(suite, "bind", torture_bind_samba3);
4471 torture_suite_add_simple_test(suite, "netlogon", torture_netlogon_samba3);
4472 torture_suite_add_simple_test(suite, "sessionkey", torture_samba3_sessionkey);
4473 torture_suite_add_simple_test(suite, "srvsvc", torture_samba3_rpc_srvsvc);
4474 torture_suite_add_simple_test(suite, "sharesec", torture_samba3_rpc_sharesec);
4475 torture_suite_add_simple_test(suite, "getusername", torture_samba3_rpc_getusername);
4476 torture_suite_add_simple_test(suite, "randomauth2", torture_samba3_rpc_randomauth2);
4477 torture_suite_add_simple_test(suite, "lsa", torture_samba3_rpc_lsa);
4478 torture_suite_add_simple_test(suite, "spoolss", torture_samba3_rpc_spoolss);
4479 torture_suite_add_simple_test(suite, "wkssvc", torture_samba3_rpc_wkssvc);
4480 torture_suite_add_simple_test(suite, "winreg", torture_samba3_rpc_winreg);
4481 torture_suite_add_simple_test(suite, "getaliasmembership-0", torture_samba3_getaliasmembership_0);
4482 torture_suite_add_simple_test(suite, "regconfig", torture_samba3_regconfig);
4483 torture_suite_add_simple_test(suite, "smb-reauth1", torture_rpc_smb_reauth1);
4484 torture_suite_add_simple_test(suite, "smb-reauth2", torture_rpc_smb_reauth2);
4485 torture_suite_add_simple_test(suite, "smb2-reauth1", torture_rpc_smb2_reauth1);
4486 torture_suite_add_simple_test(suite, "smb2-reauth2", torture_rpc_smb2_reauth2);
4487 torture_suite_add_simple_test(suite, "smb1-pipe-name", torture_rpc_smb1_pipe_name);
4488 torture_suite_add_simple_test(suite, "smb2-pipe-name", torture_rpc_smb2_pipe_name);
4489 torture_suite_add_simple_test(suite, "smb2-pipe-read-close", torture_rpc_smb2_pipe_read_close);
4490 torture_suite_add_simple_test(suite, "smb2-pipe-read-tdis", torture_rpc_smb2_pipe_read_tdis);
4491 torture_suite_add_simple_test(suite, "smb2-pipe-read-logoff", torture_rpc_smb2_pipe_read_logoff);
4493 suite->description = talloc_strdup(suite, "samba3 DCERPC interface tests");
4495 return suite;