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/>.
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"
50 #include "libcli/smb/smbXcli_base.h"
53 * This tests a RPC call using an invalid vuid
56 bool torture_bind_authcontext(struct torture_context *torture)
61 struct lsa_ObjectAttribute objectattr;
62 struct lsa_OpenPolicy2 openpolicy;
63 struct policy_handle handle;
64 struct lsa_Close close_handle;
65 struct smbcli_session *tmp;
66 struct smbcli_session *session2;
67 struct smbcli_state *cli;
68 struct dcerpc_pipe *lsa_pipe;
69 struct dcerpc_binding_handle *lsa_handle;
70 struct cli_credentials *anon_creds;
71 struct smb_composite_sesssetup setup;
72 struct smbcli_options options;
73 struct smbcli_session_options session_options;
75 mem_ctx = talloc_init("torture_bind_authcontext");
77 if (mem_ctx == NULL) {
78 torture_comment(torture, "talloc_init failed\n");
82 lpcfg_smbcli_options(torture->lp_ctx, &options);
83 lpcfg_smbcli_session_options(torture->lp_ctx, &session_options);
85 status = smbcli_full_connection(mem_ctx, &cli,
86 torture_setting_string(torture, "host", NULL),
87 lpcfg_smb_ports(torture->lp_ctx),
89 lpcfg_socket_options(torture->lp_ctx),
91 lpcfg_resolve_context(torture->lp_ctx),
92 torture->ev, &options, &session_options,
93 lpcfg_gensec_settings(torture, torture->lp_ctx));
94 if (!NT_STATUS_IS_OK(status)) {
95 torture_comment(torture, "smbcli_full_connection failed: %s\n",
100 lsa_pipe = dcerpc_pipe_init(mem_ctx, torture->ev);
101 if (lsa_pipe == NULL) {
102 torture_comment(torture, "dcerpc_pipe_init failed\n");
105 lsa_handle = lsa_pipe->binding_handle;
107 status = dcerpc_pipe_open_smb(lsa_pipe, cli->tree, "\\lsarpc");
108 if (!NT_STATUS_IS_OK(status)) {
109 torture_comment(torture, "dcerpc_pipe_open_smb failed: %s\n",
114 status = dcerpc_bind_auth_none(lsa_pipe, &ndr_table_lsarpc);
115 if (!NT_STATUS_IS_OK(status)) {
116 torture_comment(torture, "dcerpc_bind_auth_none failed: %s\n",
121 openpolicy.in.system_name =talloc_asprintf(
122 mem_ctx, "\\\\%s", dcerpc_server_name(lsa_pipe));
123 ZERO_STRUCT(objectattr);
124 openpolicy.in.attr = &objectattr;
125 openpolicy.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
126 openpolicy.out.handle = &handle;
128 status = dcerpc_lsa_OpenPolicy2_r(lsa_handle, mem_ctx, &openpolicy);
130 if (!NT_STATUS_IS_OK(status)) {
131 torture_comment(torture, "dcerpc_lsa_OpenPolicy2 failed: %s\n",
135 if (!NT_STATUS_IS_OK(openpolicy.out.result)) {
136 torture_comment(torture, "dcerpc_lsa_OpenPolicy2 failed: %s\n",
137 nt_errstr(openpolicy.out.result));
141 close_handle.in.handle = &handle;
142 close_handle.out.handle = &handle;
144 status = dcerpc_lsa_Close_r(lsa_handle, mem_ctx, &close_handle);
145 if (!NT_STATUS_IS_OK(status)) {
146 torture_comment(torture, "dcerpc_lsa_Close failed: %s\n",
150 if (!NT_STATUS_IS_OK(close_handle.out.result)) {
151 torture_comment(torture, "dcerpc_lsa_Close failed: %s\n",
152 nt_errstr(close_handle.out.result));
156 session2 = smbcli_session_init(cli->transport, mem_ctx, false, session_options);
157 if (session2 == NULL) {
158 torture_comment(torture, "smbcli_session_init failed\n");
162 if (!(anon_creds = cli_credentials_init_anon(mem_ctx))) {
163 torture_comment(torture, "create_anon_creds failed\n");
167 setup.in.sesskey = cli->transport->negotiate.sesskey;
168 setup.in.capabilities = cli->transport->negotiate.capabilities;
169 setup.in.workgroup = "";
170 setup.in.credentials = anon_creds;
171 setup.in.gensec_settings = lpcfg_gensec_settings(torture, torture->lp_ctx);
173 status = smb_composite_sesssetup(session2, &setup);
174 if (!NT_STATUS_IS_OK(status)) {
175 torture_comment(torture, "anon session setup failed: %s\n",
179 session2->vuid = setup.out.vuid;
181 tmp = cli->tree->session;
182 cli->tree->session = session2;
184 status = dcerpc_lsa_OpenPolicy2_r(lsa_handle, mem_ctx, &openpolicy);
186 cli->tree->session = tmp;
187 talloc_free(lsa_pipe);
190 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
191 torture_comment(torture, "dcerpc_lsa_OpenPolicy2 with wrong vuid gave %s, "
192 "expected NT_STATUS_INVALID_HANDLE\n",
199 talloc_free(mem_ctx);
204 * Bind to lsa using a specific auth method
207 static bool bindtest(struct torture_context *tctx,
208 struct smbcli_state *cli,
209 struct cli_credentials *credentials,
210 uint8_t auth_type, uint8_t auth_level)
216 struct dcerpc_pipe *lsa_pipe;
217 struct dcerpc_binding_handle *lsa_handle;
218 struct lsa_ObjectAttribute objectattr;
219 struct lsa_OpenPolicy2 openpolicy;
220 struct lsa_QueryInfoPolicy query;
221 union lsa_PolicyInformation *info = NULL;
222 struct policy_handle handle;
223 struct lsa_Close close_handle;
225 if ((mem_ctx = talloc_init("bindtest")) == NULL) {
226 torture_comment(tctx, "talloc_init failed\n");
230 lsa_pipe = dcerpc_pipe_init(mem_ctx, tctx->ev);
231 if (lsa_pipe == NULL) {
232 torture_comment(tctx, "dcerpc_pipe_init failed\n");
235 lsa_handle = lsa_pipe->binding_handle;
237 status = dcerpc_pipe_open_smb(lsa_pipe, cli->tree, "\\lsarpc");
238 if (!NT_STATUS_IS_OK(status)) {
239 torture_comment(tctx, "dcerpc_pipe_open_smb failed: %s\n",
244 status = dcerpc_bind_auth(lsa_pipe, &ndr_table_lsarpc,
245 credentials, lpcfg_gensec_settings(tctx->lp_ctx, tctx->lp_ctx), auth_type, auth_level,
247 if (!NT_STATUS_IS_OK(status)) {
248 torture_comment(tctx, "dcerpc_bind_auth failed: %s\n", nt_errstr(status));
252 openpolicy.in.system_name =talloc_asprintf(
253 mem_ctx, "\\\\%s", dcerpc_server_name(lsa_pipe));
254 ZERO_STRUCT(objectattr);
255 openpolicy.in.attr = &objectattr;
256 openpolicy.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
257 openpolicy.out.handle = &handle;
259 status = dcerpc_lsa_OpenPolicy2_r(lsa_handle, mem_ctx, &openpolicy);
261 if (!NT_STATUS_IS_OK(status)) {
262 torture_comment(tctx, "dcerpc_lsa_OpenPolicy2 failed: %s\n",
266 if (!NT_STATUS_IS_OK(openpolicy.out.result)) {
267 torture_comment(tctx, "dcerpc_lsa_OpenPolicy2 failed: %s\n",
268 nt_errstr(openpolicy.out.result));
272 query.in.handle = &handle;
273 query.in.level = LSA_POLICY_INFO_DOMAIN;
274 query.out.info = &info;
276 status = dcerpc_lsa_QueryInfoPolicy_r(lsa_handle, mem_ctx, &query);
277 if (!NT_STATUS_IS_OK(status)) {
278 torture_comment(tctx, "dcerpc_lsa_QueryInfoPolicy failed: %s\n",
282 if (!NT_STATUS_IS_OK(query.out.result)) {
283 torture_comment(tctx, "dcerpc_lsa_QueryInfoPolicy failed: %s\n",
284 nt_errstr(query.out.result));
288 close_handle.in.handle = &handle;
289 close_handle.out.handle = &handle;
291 status = dcerpc_lsa_Close_r(lsa_handle, mem_ctx, &close_handle);
292 if (!NT_STATUS_IS_OK(status)) {
293 torture_comment(tctx, "dcerpc_lsa_Close failed: %s\n",
297 if (!NT_STATUS_IS_OK(close_handle.out.result)) {
298 torture_comment(tctx, "dcerpc_lsa_Close failed: %s\n",
299 nt_errstr(close_handle.out.result));
306 talloc_free(mem_ctx);
311 * test authenticated RPC binds with the variants Samba3 does support
314 static bool torture_bind_samba3(struct torture_context *torture)
319 struct smbcli_state *cli;
320 struct smbcli_options options;
321 struct smbcli_session_options session_options;
323 mem_ctx = talloc_init("torture_bind_authcontext");
325 if (mem_ctx == NULL) {
326 torture_comment(torture, "talloc_init failed\n");
330 lpcfg_smbcli_options(torture->lp_ctx, &options);
331 lpcfg_smbcli_session_options(torture->lp_ctx, &session_options);
333 status = smbcli_full_connection(mem_ctx, &cli,
334 torture_setting_string(torture, "host", NULL),
335 lpcfg_smb_ports(torture->lp_ctx),
337 lpcfg_socket_options(torture->lp_ctx),
339 lpcfg_resolve_context(torture->lp_ctx),
340 torture->ev, &options, &session_options,
341 lpcfg_gensec_settings(torture, torture->lp_ctx));
342 if (!NT_STATUS_IS_OK(status)) {
343 torture_comment(torture, "smbcli_full_connection failed: %s\n",
350 ret &= bindtest(torture, cli, cmdline_credentials, DCERPC_AUTH_TYPE_NTLMSSP,
351 DCERPC_AUTH_LEVEL_INTEGRITY);
352 ret &= bindtest(torture, cli, cmdline_credentials, DCERPC_AUTH_TYPE_NTLMSSP,
353 DCERPC_AUTH_LEVEL_PRIVACY);
354 ret &= bindtest(torture, cli, cmdline_credentials, DCERPC_AUTH_TYPE_SPNEGO,
355 DCERPC_AUTH_LEVEL_INTEGRITY);
356 ret &= bindtest(torture, cli, cmdline_credentials, DCERPC_AUTH_TYPE_SPNEGO,
357 DCERPC_AUTH_LEVEL_PRIVACY);
360 talloc_free(mem_ctx);
365 * Lookup or create a user and return all necessary info
368 static bool get_usr_handle(struct torture_context *tctx,
369 struct smbcli_state *cli,
371 struct cli_credentials *admin_creds,
374 const char *username,
376 struct dcerpc_pipe **result_pipe,
377 struct policy_handle **result_handle,
378 struct dom_sid **sid_p)
380 struct dcerpc_pipe *samr_pipe;
381 struct dcerpc_binding_handle *samr_handle;
383 struct policy_handle conn_handle;
384 struct policy_handle domain_handle;
385 struct policy_handle *user_handle;
386 struct samr_Connect2 conn;
387 struct samr_EnumDomains enumdom;
388 uint32_t resume_handle = 0;
389 uint32_t num_entries = 0;
390 struct samr_SamArray *sam = NULL;
391 struct samr_LookupDomain l;
392 struct dom_sid2 *sid = NULL;
394 struct lsa_String domain_name;
395 struct lsa_String user_name;
396 struct samr_OpenDomain o;
397 struct samr_CreateUser2 c;
398 uint32_t user_rid,access_granted;
400 samr_pipe = dcerpc_pipe_init(mem_ctx, tctx->ev);
401 torture_assert(tctx, samr_pipe, "dcerpc_pipe_init failed");
403 samr_handle = samr_pipe->binding_handle;
405 torture_assert_ntstatus_ok(tctx,
406 dcerpc_pipe_open_smb(samr_pipe, cli->tree, "\\samr"),
407 "dcerpc_pipe_open_smb failed");
409 if (admin_creds != NULL) {
410 torture_assert_ntstatus_ok(tctx,
411 dcerpc_bind_auth(samr_pipe, &ndr_table_samr,
412 admin_creds, lpcfg_gensec_settings(tctx->lp_ctx, tctx->lp_ctx), auth_type, auth_level,
414 "dcerpc_bind_auth failed");
416 /* We must have an authenticated SMB connection */
417 torture_assert_ntstatus_ok(tctx,
418 dcerpc_bind_auth_none(samr_pipe, &ndr_table_samr),
419 "dcerpc_bind_auth_none failed");
422 conn.in.system_name = talloc_asprintf(
423 mem_ctx, "\\\\%s", dcerpc_server_name(samr_pipe));
424 conn.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
425 conn.out.connect_handle = &conn_handle;
427 torture_assert_ntstatus_ok(tctx,
428 dcerpc_samr_Connect2_r(samr_handle, mem_ctx, &conn),
429 "samr_Connect2 failed");
430 torture_assert_ntstatus_ok(tctx, conn.out.result,
431 "samr_Connect2 failed");
433 enumdom.in.connect_handle = &conn_handle;
434 enumdom.in.resume_handle = &resume_handle;
435 enumdom.in.buf_size = (uint32_t)-1;
436 enumdom.out.resume_handle = &resume_handle;
437 enumdom.out.num_entries = &num_entries;
438 enumdom.out.sam = &sam;
440 torture_assert_ntstatus_ok(tctx,
441 dcerpc_samr_EnumDomains_r(samr_handle, mem_ctx, &enumdom),
442 "samr_EnumDomains failed");
443 torture_assert_ntstatus_ok(tctx, enumdom.out.result,
444 "samr_EnumDomains failed");
446 torture_assert_int_equal(tctx, *enumdom.out.num_entries, 2,
447 "samr_EnumDomains returned unexpected num_entries");
449 dom_idx = strequal(sam->entries[0].name.string,
452 l.in.connect_handle = &conn_handle;
453 domain_name.string = sam->entries[dom_idx].name.string;
454 *domain = talloc_strdup(mem_ctx, domain_name.string);
455 l.in.domain_name = &domain_name;
458 torture_assert_ntstatus_ok(tctx,
459 dcerpc_samr_LookupDomain_r(samr_handle, mem_ctx, &l),
460 "samr_LookupDomain failed");
461 torture_assert_ntstatus_ok(tctx, l.out.result,
462 "samr_LookupDomain failed");
464 o.in.connect_handle = &conn_handle;
465 o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
466 o.in.sid = *l.out.sid;
467 o.out.domain_handle = &domain_handle;
469 torture_assert_ntstatus_ok(tctx,
470 dcerpc_samr_OpenDomain_r(samr_handle, mem_ctx, &o),
471 "samr_OpenDomain failed");
472 torture_assert_ntstatus_ok(tctx, o.out.result,
473 "samr_OpenDomain failed");
475 c.in.domain_handle = &domain_handle;
476 user_name.string = username;
477 c.in.account_name = &user_name;
478 c.in.acct_flags = ACB_NORMAL;
479 c.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
480 user_handle = talloc(mem_ctx, struct policy_handle);
481 c.out.user_handle = user_handle;
482 c.out.access_granted = &access_granted;
483 c.out.rid = &user_rid;
485 torture_assert_ntstatus_ok(tctx,
486 dcerpc_samr_CreateUser2_r(samr_handle, mem_ctx, &c),
487 "samr_CreateUser2 failed");
489 if (NT_STATUS_EQUAL(c.out.result, NT_STATUS_USER_EXISTS)) {
490 struct samr_LookupNames ln;
491 struct samr_OpenUser ou;
492 struct samr_Ids rids, types;
494 ln.in.domain_handle = &domain_handle;
496 ln.in.names = &user_name;
498 ln.out.types = &types;
500 torture_assert_ntstatus_ok(tctx,
501 dcerpc_samr_LookupNames_r(samr_handle, mem_ctx, &ln),
502 "samr_LookupNames failed");
503 torture_assert_ntstatus_ok(tctx, ln.out.result,
504 "samr_LookupNames failed");
506 ou.in.domain_handle = &domain_handle;
507 ou.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
508 user_rid = ou.in.rid = ln.out.rids->ids[0];
509 ou.out.user_handle = user_handle;
511 torture_assert_ntstatus_ok(tctx,
512 dcerpc_samr_OpenUser_r(samr_handle, mem_ctx, &ou),
513 "samr_OpenUser failed");
514 status = ou.out.result;
516 status = c.out.result;
519 torture_assert_ntstatus_ok(tctx, status,
520 "samr_CreateUser failed");
522 *result_pipe = samr_pipe;
523 *result_handle = user_handle;
525 *sid_p = dom_sid_add_rid(mem_ctx, *l.out.sid, user_rid);
535 static bool create_user(struct torture_context *tctx,
536 TALLOC_CTX *mem_ctx, struct smbcli_state *cli,
537 struct cli_credentials *admin_creds,
538 const char *username, const char *password,
540 struct dom_sid **user_sid)
544 struct dcerpc_pipe *samr_pipe;
545 struct dcerpc_binding_handle *samr_handle;
546 struct policy_handle *wks_handle;
549 if (!(tmp_ctx = talloc_new(mem_ctx))) {
550 torture_comment(tctx, "talloc_init failed\n");
554 ret = get_usr_handle(tctx, cli, tmp_ctx, admin_creds,
555 DCERPC_AUTH_TYPE_NTLMSSP,
556 DCERPC_AUTH_LEVEL_INTEGRITY,
557 username, domain_name, &samr_pipe, &wks_handle,
560 torture_comment(tctx, "get_usr_handle failed\n");
563 samr_handle = samr_pipe->binding_handle;
566 struct samr_SetUserInfo2 sui2;
567 struct samr_SetUserInfo sui;
568 struct samr_QueryUserInfo qui;
569 union samr_UserInfo u_info;
570 union samr_UserInfo *info;
571 DATA_BLOB session_key;
575 encode_pw_buffer(u_info.info23.password.data, password,
578 status = dcerpc_fetch_session_key(samr_pipe, &session_key);
579 if (!NT_STATUS_IS_OK(status)) {
580 torture_comment(tctx, "dcerpc_fetch_session_key failed\n");
583 arcfour_crypt_blob(u_info.info23.password.data, 516,
585 u_info.info23.info.password_expired = 0;
586 u_info.info23.info.fields_present = SAMR_FIELD_NT_PASSWORD_PRESENT |
587 SAMR_FIELD_LM_PASSWORD_PRESENT |
588 SAMR_FIELD_EXPIRED_FLAG;
589 sui2.in.user_handle = wks_handle;
590 sui2.in.info = &u_info;
593 status = dcerpc_samr_SetUserInfo2_r(samr_handle, tmp_ctx, &sui2);
594 if (!NT_STATUS_IS_OK(status)) {
595 torture_comment(tctx, "samr_SetUserInfo(23) failed: %s\n",
599 if (!NT_STATUS_IS_OK(sui2.out.result)) {
600 torture_comment(tctx, "samr_SetUserInfo(23) failed: %s\n",
601 nt_errstr(sui2.out.result));
605 u_info.info16.acct_flags = ACB_NORMAL;
606 sui.in.user_handle = wks_handle;
607 sui.in.info = &u_info;
610 status = dcerpc_samr_SetUserInfo_r(samr_handle, tmp_ctx, &sui);
611 if (!NT_STATUS_IS_OK(status) || !NT_STATUS_IS_OK(sui.out.result)) {
612 torture_comment(tctx, "samr_SetUserInfo(16) failed\n");
616 qui.in.user_handle = wks_handle;
618 qui.out.info = &info;
620 status = dcerpc_samr_QueryUserInfo_r(samr_handle, tmp_ctx, &qui);
621 if (!NT_STATUS_IS_OK(status) || !NT_STATUS_IS_OK(qui.out.result)) {
622 torture_comment(tctx, "samr_QueryUserInfo(21) failed\n");
626 info->info21.allow_password_change = 0;
627 info->info21.force_password_change = 0;
628 info->info21.account_name.string = NULL;
629 info->info21.rid = 0;
630 info->info21.acct_expiry = 0;
631 info->info21.fields_present = 0x81827fa; /* copy usrmgr.exe */
633 u_info.info21 = info->info21;
634 sui.in.user_handle = wks_handle;
635 sui.in.info = &u_info;
638 status = dcerpc_samr_SetUserInfo_r(samr_handle, tmp_ctx, &sui);
639 if (!NT_STATUS_IS_OK(status) || !NT_STATUS_IS_OK(sui.out.result)) {
640 torture_comment(tctx, "samr_SetUserInfo(21) failed\n");
645 *domain_name= talloc_steal(mem_ctx, *domain_name);
646 *user_sid = talloc_steal(mem_ctx, *user_sid);
649 talloc_free(tmp_ctx);
657 static bool delete_user(struct torture_context *tctx,
658 struct smbcli_state *cli,
659 struct cli_credentials *admin_creds,
660 const char *username)
665 struct dcerpc_pipe *samr_pipe;
666 struct dcerpc_binding_handle *samr_handle;
667 struct policy_handle *user_handle;
670 if ((mem_ctx = talloc_init("leave")) == NULL) {
671 torture_comment(tctx, "talloc_init failed\n");
675 ret = get_usr_handle(tctx, cli, mem_ctx, admin_creds,
676 DCERPC_AUTH_TYPE_NTLMSSP,
677 DCERPC_AUTH_LEVEL_INTEGRITY,
678 username, &dom_name, &samr_pipe,
681 torture_comment(tctx, "get_wks_handle failed\n");
684 samr_handle = samr_pipe->binding_handle;
687 struct samr_DeleteUser d;
689 d.in.user_handle = user_handle;
690 d.out.user_handle = user_handle;
692 status = dcerpc_samr_DeleteUser_r(samr_handle, mem_ctx, &d);
693 if (!NT_STATUS_IS_OK(status)) {
694 torture_comment(tctx, "samr_DeleteUser failed %s\n", nt_errstr(status));
697 if (!NT_STATUS_IS_OK(d.out.result)) {
698 torture_comment(tctx, "samr_DeleteUser failed %s\n", nt_errstr(d.out.result));
707 talloc_free(mem_ctx);
712 * Do a Samba3-style join
715 static bool join3(struct torture_context *tctx,
716 struct smbcli_state *cli,
718 struct cli_credentials *admin_creds,
719 struct cli_credentials *wks_creds)
724 struct dcerpc_pipe *samr_pipe;
725 struct dcerpc_binding_handle *samr_handle;
726 struct policy_handle *wks_handle;
728 NTTIME last_password_change;
730 if ((mem_ctx = talloc_init("join3")) == NULL) {
731 torture_comment(tctx, "talloc_init failed\n");
735 ret = get_usr_handle(
736 tctx, cli, mem_ctx, admin_creds,
737 DCERPC_AUTH_TYPE_NTLMSSP,
738 DCERPC_AUTH_LEVEL_PRIVACY,
739 talloc_asprintf(mem_ctx, "%s$",
740 cli_credentials_get_workstation(wks_creds)),
741 &dom_name, &samr_pipe, &wks_handle, NULL);
743 torture_comment(tctx, "get_wks_handle failed\n");
746 samr_handle = samr_pipe->binding_handle;
749 struct samr_QueryUserInfo q;
750 union samr_UserInfo *info;
752 q.in.user_handle = wks_handle;
756 status = dcerpc_samr_QueryUserInfo_r(samr_handle, mem_ctx, &q);
757 if (!NT_STATUS_IS_OK(status)) {
758 torture_warning(tctx, "QueryUserInfo failed: %s\n",
762 if (!NT_STATUS_IS_OK(q.out.result)) {
763 torture_warning(tctx, "QueryUserInfo failed: %s\n",
764 nt_errstr(q.out.result));
769 last_password_change = info->info21.last_password_change;
772 cli_credentials_set_domain(wks_creds, dom_name, CRED_SPECIFIED);
775 struct samr_SetUserInfo2 sui2;
776 union samr_UserInfo u_info;
777 struct samr_UserInfo21 *i21 = &u_info.info25.info;
778 DATA_BLOB session_key;
779 DATA_BLOB confounded_session_key = data_blob_talloc(
781 struct MD5Context ctx;
782 uint8_t confounder[16];
786 i21->full_name.string = talloc_asprintf(
788 cli_credentials_get_workstation(wks_creds));
789 i21->acct_flags = ACB_WSTRUST;
790 i21->fields_present = SAMR_FIELD_FULL_NAME |
791 SAMR_FIELD_ACCT_FLAGS | SAMR_FIELD_NT_PASSWORD_PRESENT;
792 /* this would break the test result expectations
793 i21->fields_present |= SAMR_FIELD_EXPIRED_FLAG;
794 i21->password_expired = 1;
797 encode_pw_buffer(u_info.info25.password.data,
798 cli_credentials_get_password(wks_creds),
800 status = dcerpc_fetch_session_key(samr_pipe, &session_key);
801 if (!NT_STATUS_IS_OK(status)) {
802 torture_comment(tctx, "dcerpc_fetch_session_key failed: %s\n",
806 generate_random_buffer((uint8_t *)confounder, 16);
809 MD5Update(&ctx, confounder, 16);
810 MD5Update(&ctx, session_key.data, session_key.length);
811 MD5Final(confounded_session_key.data, &ctx);
813 arcfour_crypt_blob(u_info.info25.password.data, 516,
814 &confounded_session_key);
815 memcpy(&u_info.info25.password.data[516], confounder, 16);
817 sui2.in.user_handle = wks_handle;
819 sui2.in.info = &u_info;
821 status = dcerpc_samr_SetUserInfo2_r(samr_handle, mem_ctx, &sui2);
822 if (!NT_STATUS_IS_OK(status)) {
823 torture_comment(tctx, "samr_SetUserInfo2(25) failed: %s\n",
827 if (!NT_STATUS_IS_OK(sui2.out.result)) {
828 torture_comment(tctx, "samr_SetUserInfo2(25) failed: %s\n",
829 nt_errstr(sui2.out.result));
833 struct samr_SetUserInfo2 sui2;
834 struct samr_SetUserInfo sui;
835 union samr_UserInfo u_info;
836 DATA_BLOB session_key;
838 encode_pw_buffer(u_info.info24.password.data,
839 cli_credentials_get_password(wks_creds),
841 /* just to make this test pass */
842 u_info.info24.password_expired = 1;
844 status = dcerpc_fetch_session_key(samr_pipe, &session_key);
845 if (!NT_STATUS_IS_OK(status)) {
846 torture_comment(tctx, "dcerpc_fetch_session_key failed\n");
849 arcfour_crypt_blob(u_info.info24.password.data, 516,
851 sui2.in.user_handle = wks_handle;
852 sui2.in.info = &u_info;
855 status = dcerpc_samr_SetUserInfo2_r(samr_handle, mem_ctx, &sui2);
856 if (!NT_STATUS_IS_OK(status)) {
857 torture_comment(tctx, "samr_SetUserInfo(24) failed: %s\n",
861 if (!NT_STATUS_IS_OK(sui2.out.result)) {
862 torture_comment(tctx, "samr_SetUserInfo(24) failed: %s\n",
863 nt_errstr(sui2.out.result));
867 u_info.info16.acct_flags = ACB_WSTRUST;
868 sui.in.user_handle = wks_handle;
869 sui.in.info = &u_info;
872 status = dcerpc_samr_SetUserInfo_r(samr_handle, mem_ctx, &sui);
873 if (!NT_STATUS_IS_OK(status) || !NT_STATUS_IS_OK(sui.out.result)) {
874 torture_comment(tctx, "samr_SetUserInfo(16) failed\n");
880 struct samr_QueryUserInfo q;
881 union samr_UserInfo *info;
883 q.in.user_handle = wks_handle;
887 status = dcerpc_samr_QueryUserInfo_r(samr_handle, mem_ctx, &q);
888 if (!NT_STATUS_IS_OK(status)) {
889 torture_warning(tctx, "QueryUserInfo failed: %s\n",
893 if (!NT_STATUS_IS_OK(q.out.result)) {
894 torture_warning(tctx, "QueryUserInfo failed: %s\n",
895 nt_errstr(q.out.result));
900 if (last_password_change
901 == info->info21.last_password_change) {
902 torture_warning(tctx, "last_password_change unchanged "
903 "during join, level25 must change "
909 if (last_password_change
910 != info->info21.last_password_change) {
911 torture_warning(tctx, "last_password_change changed "
912 "during join, level24 doesn't "
922 talloc_free(mem_ctx);
927 * Do a ReqChallenge/Auth2 and get the wks creds
930 static bool auth2(struct torture_context *tctx,
931 struct smbcli_state *cli,
932 struct cli_credentials *wks_cred)
935 struct dcerpc_pipe *net_pipe;
936 struct dcerpc_binding_handle *net_handle;
939 struct netr_ServerReqChallenge r;
940 struct netr_Credential netr_cli_creds;
941 struct netr_Credential netr_srv_creds;
942 uint32_t negotiate_flags;
943 struct netr_ServerAuthenticate2 a;
944 struct netlogon_creds_CredentialState *creds_state;
945 struct netr_Credential netr_cred;
946 struct samr_Password mach_pw;
948 mem_ctx = talloc_new(NULL);
949 if (mem_ctx == NULL) {
950 torture_comment(tctx, "talloc_new failed\n");
954 net_pipe = dcerpc_pipe_init(mem_ctx, tctx->ev);
955 if (net_pipe == NULL) {
956 torture_comment(tctx, "dcerpc_pipe_init failed\n");
959 net_handle = net_pipe->binding_handle;
961 status = dcerpc_pipe_open_smb(net_pipe, cli->tree, "\\netlogon");
962 if (!NT_STATUS_IS_OK(status)) {
963 torture_comment(tctx, "dcerpc_pipe_open_smb failed: %s\n",
968 status = dcerpc_bind_auth_none(net_pipe, &ndr_table_netlogon);
969 if (!NT_STATUS_IS_OK(status)) {
970 torture_comment(tctx, "dcerpc_bind_auth_none failed: %s\n",
975 r.in.computer_name = cli_credentials_get_workstation(wks_cred);
976 r.in.server_name = talloc_asprintf(
977 mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
978 if (r.in.server_name == NULL) {
979 torture_comment(tctx, "talloc_asprintf failed\n");
982 generate_random_buffer(netr_cli_creds.data,
983 sizeof(netr_cli_creds.data));
984 r.in.credentials = &netr_cli_creds;
985 r.out.return_credentials = &netr_srv_creds;
987 status = dcerpc_netr_ServerReqChallenge_r(net_handle, mem_ctx, &r);
988 if (!NT_STATUS_IS_OK(status)) {
989 torture_comment(tctx, "netr_ServerReqChallenge failed: %s\n",
993 if (!NT_STATUS_IS_OK(r.out.result)) {
994 torture_comment(tctx, "netr_ServerReqChallenge failed: %s\n",
995 nt_errstr(r.out.result));
999 negotiate_flags = NETLOGON_NEG_AUTH2_FLAGS;
1000 E_md4hash(cli_credentials_get_password(wks_cred), mach_pw.hash);
1002 a.in.server_name = talloc_asprintf(
1003 mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
1004 a.in.account_name = talloc_asprintf(
1005 mem_ctx, "%s$", cli_credentials_get_workstation(wks_cred));
1006 a.in.computer_name = cli_credentials_get_workstation(wks_cred);
1007 a.in.secure_channel_type = SEC_CHAN_WKSTA;
1008 a.in.negotiate_flags = &negotiate_flags;
1009 a.out.negotiate_flags = &negotiate_flags;
1010 a.in.credentials = &netr_cred;
1011 a.out.return_credentials = &netr_cred;
1013 creds_state = netlogon_creds_client_init(mem_ctx,
1017 r.out.return_credentials, &mach_pw,
1018 &netr_cred, negotiate_flags);
1019 torture_assert(tctx, (creds_state != NULL), "memory allocation failed");
1021 status = dcerpc_netr_ServerAuthenticate2_r(net_handle, mem_ctx, &a);
1022 if (!NT_STATUS_IS_OK(status)) {
1023 torture_comment(tctx, "netr_ServerServerAuthenticate2 failed: %s\n",
1027 if (!NT_STATUS_IS_OK(a.out.result)) {
1028 torture_comment(tctx, "netr_ServerServerAuthenticate2 failed: %s\n",
1029 nt_errstr(a.out.result));
1033 if (!netlogon_creds_client_check(creds_state, a.out.return_credentials)) {
1034 torture_comment(tctx, "creds_client_check failed\n");
1038 cli_credentials_set_netlogon_creds(wks_cred, creds_state);
1043 talloc_free(mem_ctx);
1048 * Do a couple of schannel protected Netlogon ops: Interactive and Network
1049 * login, and change the wks password
1052 static bool schan(struct torture_context *tctx,
1053 struct smbcli_state *cli,
1054 struct cli_credentials *wks_creds,
1055 struct cli_credentials *user_creds)
1057 TALLOC_CTX *mem_ctx;
1060 struct dcerpc_pipe *net_pipe;
1061 struct dcerpc_binding_handle *net_handle;
1064 mem_ctx = talloc_new(NULL);
1065 if (mem_ctx == NULL) {
1066 torture_comment(tctx, "talloc_new failed\n");
1070 net_pipe = dcerpc_pipe_init(mem_ctx, tctx->ev);
1071 if (net_pipe == NULL) {
1072 torture_comment(tctx, "dcerpc_pipe_init failed\n");
1075 net_handle = net_pipe->binding_handle;
1077 status = dcerpc_pipe_open_smb(net_pipe, cli->tree, "\\netlogon");
1078 if (!NT_STATUS_IS_OK(status)) {
1079 torture_comment(tctx, "dcerpc_pipe_open_smb failed: %s\n",
1085 net_pipe->conn->flags |= DCERPC_DEBUG_PRINT_IN |
1086 DCERPC_DEBUG_PRINT_OUT;
1089 net_pipe->conn->flags |= (DCERPC_SIGN | DCERPC_SEAL);
1090 status = dcerpc_bind_auth(net_pipe, &ndr_table_netlogon,
1091 wks_creds, lpcfg_gensec_settings(tctx->lp_ctx, tctx->lp_ctx), DCERPC_AUTH_TYPE_SCHANNEL,
1092 DCERPC_AUTH_LEVEL_PRIVACY,
1095 status = dcerpc_bind_auth_none(net_pipe, &ndr_table_netlogon);
1097 if (!NT_STATUS_IS_OK(status)) {
1098 torture_comment(tctx, "schannel bind failed: %s\n", nt_errstr(status));
1103 for (i=2; i<4; i++) {
1105 DATA_BLOB chal, nt_resp, lm_resp, names_blob, session_key;
1106 struct netlogon_creds_CredentialState *creds_state;
1107 struct netr_Authenticator netr_auth, netr_auth2;
1108 struct netr_NetworkInfo ninfo;
1109 struct netr_PasswordInfo pinfo;
1110 struct netr_LogonSamLogon r;
1111 union netr_LogonLevel logon;
1112 union netr_Validation validation;
1113 uint8_t authoritative;
1114 struct netr_Authenticator return_authenticator;
1116 flags = CLI_CRED_LANMAN_AUTH | CLI_CRED_NTLM_AUTH |
1117 CLI_CRED_NTLMv2_AUTH;
1119 chal = data_blob_talloc(mem_ctx, NULL, 8);
1120 if (chal.data == NULL) {
1121 torture_comment(tctx, "data_blob_talloc failed\n");
1125 generate_random_buffer(chal.data, chal.length);
1126 names_blob = NTLMv2_generate_names_blob(
1128 cli_credentials_get_workstation(user_creds),
1129 cli_credentials_get_domain(user_creds));
1130 status = cli_credentials_get_ntlm_response(
1131 user_creds, mem_ctx, &flags, chal, names_blob,
1132 &lm_resp, &nt_resp, NULL, NULL);
1133 if (!NT_STATUS_IS_OK(status)) {
1134 torture_comment(tctx, "cli_credentials_get_ntlm_response failed:"
1135 " %s\n", nt_errstr(status));
1139 creds_state = cli_credentials_get_netlogon_creds(wks_creds);
1140 netlogon_creds_client_authenticator(creds_state, &netr_auth);
1142 ninfo.identity_info.account_name.string =
1143 cli_credentials_get_username(user_creds);
1144 ninfo.identity_info.domain_name.string =
1145 cli_credentials_get_domain(user_creds);
1146 ninfo.identity_info.parameter_control = 0;
1147 ninfo.identity_info.logon_id_low = 0;
1148 ninfo.identity_info.logon_id_high = 0;
1149 ninfo.identity_info.workstation.string =
1150 cli_credentials_get_workstation(user_creds);
1151 memcpy(ninfo.challenge, chal.data, sizeof(ninfo.challenge));
1152 ninfo.nt.length = nt_resp.length;
1153 ninfo.nt.data = nt_resp.data;
1154 ninfo.lm.length = lm_resp.length;
1155 ninfo.lm.data = lm_resp.data;
1157 logon.network = &ninfo;
1159 r.in.server_name = talloc_asprintf(
1160 mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
1161 ZERO_STRUCT(netr_auth2);
1162 r.in.computer_name =
1163 cli_credentials_get_workstation(wks_creds);
1164 r.in.credential = &netr_auth;
1165 r.in.return_authenticator = &netr_auth2;
1166 r.in.logon_level = 2;
1167 r.in.validation_level = i;
1168 r.in.logon = &logon;
1169 r.out.validation = &validation;
1170 r.out.authoritative = &authoritative;
1171 r.out.return_authenticator = &return_authenticator;
1173 status = dcerpc_netr_LogonSamLogon_r(net_handle, mem_ctx, &r);
1174 if (!NT_STATUS_IS_OK(status)) {
1175 torture_comment(tctx, "netr_LogonSamLogon failed: %s\n",
1179 if (!NT_STATUS_IS_OK(r.out.result)) {
1180 torture_comment(tctx, "netr_LogonSamLogon failed: %s\n",
1181 nt_errstr(r.out.result));
1185 if ((r.out.return_authenticator == NULL) ||
1186 (!netlogon_creds_client_check(creds_state,
1187 &r.out.return_authenticator->cred))) {
1188 torture_comment(tctx, "Credentials check failed!\n");
1192 netlogon_creds_client_authenticator(creds_state, &netr_auth);
1194 pinfo.identity_info = ninfo.identity_info;
1195 ZERO_STRUCT(pinfo.lmpassword.hash);
1196 E_md4hash(cli_credentials_get_password(user_creds),
1197 pinfo.ntpassword.hash);
1198 session_key = data_blob_talloc(mem_ctx,
1199 creds_state->session_key, 16);
1200 arcfour_crypt_blob(pinfo.ntpassword.hash,
1201 sizeof(pinfo.ntpassword.hash),
1204 logon.password = &pinfo;
1206 r.in.logon_level = 1;
1207 r.in.logon = &logon;
1208 r.out.return_authenticator = &return_authenticator;
1210 status = dcerpc_netr_LogonSamLogon_r(net_handle, mem_ctx, &r);
1211 if (!NT_STATUS_IS_OK(status)) {
1212 torture_comment(tctx, "netr_LogonSamLogon failed: %s\n",
1216 if (!NT_STATUS_IS_OK(r.out.result)) {
1217 torture_comment(tctx, "netr_LogonSamLogon failed: %s\n",
1218 nt_errstr(r.out.result));
1222 if ((r.out.return_authenticator == NULL) ||
1223 (!netlogon_creds_client_check(creds_state,
1224 &r.out.return_authenticator->cred))) {
1225 torture_comment(tctx, "Credentials check failed!\n");
1231 struct netr_ServerPasswordSet s;
1232 char *password = generate_random_password(wks_creds, 8, 255);
1233 struct netlogon_creds_CredentialState *creds_state;
1234 struct netr_Authenticator credential, return_authenticator;
1235 struct samr_Password new_password;
1237 s.in.server_name = talloc_asprintf(
1238 mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
1239 s.in.computer_name = cli_credentials_get_workstation(wks_creds);
1240 s.in.account_name = talloc_asprintf(
1241 mem_ctx, "%s$", s.in.computer_name);
1242 s.in.secure_channel_type = SEC_CHAN_WKSTA;
1243 s.in.credential = &credential;
1244 s.in.new_password = &new_password;
1245 s.out.return_authenticator = &return_authenticator;
1247 E_md4hash(password, new_password.hash);
1249 creds_state = cli_credentials_get_netlogon_creds(wks_creds);
1250 netlogon_creds_des_encrypt(creds_state, &new_password);
1251 netlogon_creds_client_authenticator(creds_state, &credential);
1253 status = dcerpc_netr_ServerPasswordSet_r(net_handle, mem_ctx, &s);
1254 if (!NT_STATUS_IS_OK(status)) {
1255 torture_comment(tctx, "ServerPasswordSet - %s\n", nt_errstr(status));
1258 if (!NT_STATUS_IS_OK(s.out.result)) {
1259 torture_comment(tctx, "ServerPasswordSet - %s\n", nt_errstr(s.out.result));
1263 if (!netlogon_creds_client_check(creds_state,
1264 &s.out.return_authenticator->cred)) {
1265 torture_comment(tctx, "Credential chaining failed\n");
1268 cli_credentials_set_password(wks_creds, password,
1274 talloc_free(mem_ctx);
1279 * Delete the wks account again
1282 static bool leave(struct torture_context *tctx,
1283 struct smbcli_state *cli,
1284 struct cli_credentials *admin_creds,
1285 struct cli_credentials *wks_creds)
1287 char *wks_name = talloc_asprintf(
1288 NULL, "%s$", cli_credentials_get_workstation(wks_creds));
1291 ret = delete_user(tctx, cli, admin_creds, wks_name);
1292 talloc_free(wks_name);
1297 * Test the Samba3 DC code a bit. Join, do some schan netlogon ops, leave
1300 static bool torture_netlogon_samba3(struct torture_context *torture)
1303 struct smbcli_state *cli;
1304 struct cli_credentials *anon_creds;
1305 struct cli_credentials *wks_creds;
1306 const char *wks_name;
1308 struct smbcli_options options;
1309 struct smbcli_session_options session_options;
1311 wks_name = torture_setting_string(torture, "wksname", NULL);
1312 if (wks_name == NULL) {
1313 wks_name = get_myname(torture);
1316 if (!(anon_creds = cli_credentials_init_anon(torture))) {
1317 torture_fail(torture, "create_anon_creds failed\n");
1320 lpcfg_smbcli_options(torture->lp_ctx, &options);
1321 lpcfg_smbcli_session_options(torture->lp_ctx, &session_options);
1323 status = smbcli_full_connection(torture, &cli,
1324 torture_setting_string(torture, "host", NULL),
1325 lpcfg_smb_ports(torture->lp_ctx),
1327 lpcfg_socket_options(torture->lp_ctx),
1329 lpcfg_resolve_context(torture->lp_ctx),
1330 torture->ev, &options, &session_options,
1331 lpcfg_gensec_settings(torture, torture->lp_ctx));
1332 torture_assert_ntstatus_ok(torture, status, "smbcli_full_connection failed\n");
1334 wks_creds = cli_credentials_init(torture);
1335 if (wks_creds == NULL) {
1336 torture_fail(torture, "cli_credentials_init failed\n");
1339 cli_credentials_set_conf(wks_creds, torture->lp_ctx);
1340 cli_credentials_set_secure_channel_type(wks_creds, SEC_CHAN_WKSTA);
1341 cli_credentials_set_username(wks_creds, wks_name, CRED_SPECIFIED);
1342 cli_credentials_set_workstation(wks_creds, wks_name, CRED_SPECIFIED);
1343 cli_credentials_set_password(wks_creds,
1344 generate_random_password(wks_creds, 8, 255),
1347 torture_assert(torture,
1348 join3(torture, cli, false, cmdline_credentials, wks_creds),
1351 cli_credentials_set_domain(
1352 cmdline_credentials, cli_credentials_get_domain(wks_creds),
1355 for (i=0; i<2; i++) {
1357 /* Do this more than once, the routine "schan" changes
1358 * the workstation password using the netlogon
1359 * password change routine */
1363 torture_assert(torture,
1364 auth2(torture, cli, wks_creds),
1367 for (j=0; j<2; j++) {
1368 torture_assert(torture,
1369 schan(torture, cli, wks_creds, cmdline_credentials),
1374 torture_assert(torture,
1375 leave(torture, cli, cmdline_credentials, wks_creds),
1382 * Do a simple join, testjoin and leave using specified smb and samr
1386 static bool test_join3(struct torture_context *tctx,
1388 struct cli_credentials *smb_creds,
1389 struct cli_credentials *samr_creds,
1390 const char *wks_name)
1393 struct smbcli_state *cli;
1394 struct cli_credentials *wks_creds;
1395 struct smbcli_options options;
1396 struct smbcli_session_options session_options;
1398 lpcfg_smbcli_options(tctx->lp_ctx, &options);
1399 lpcfg_smbcli_session_options(tctx->lp_ctx, &session_options);
1401 status = smbcli_full_connection(tctx, &cli,
1402 torture_setting_string(tctx, "host", NULL),
1403 lpcfg_smb_ports(tctx->lp_ctx),
1404 "IPC$", NULL, lpcfg_socket_options(tctx->lp_ctx),
1405 smb_creds, lpcfg_resolve_context(tctx->lp_ctx),
1406 tctx->ev, &options, &session_options,
1407 lpcfg_gensec_settings(tctx, tctx->lp_ctx));
1408 torture_assert_ntstatus_ok(tctx, status,
1409 "smbcli_full_connection failed");
1411 wks_creds = cli_credentials_init(cli);
1412 torture_assert(tctx, wks_creds, "cli_credentials_init failed");
1414 cli_credentials_set_conf(wks_creds, tctx->lp_ctx);
1415 cli_credentials_set_secure_channel_type(wks_creds, SEC_CHAN_WKSTA);
1416 cli_credentials_set_username(wks_creds, wks_name, CRED_SPECIFIED);
1417 cli_credentials_set_workstation(wks_creds, wks_name, CRED_SPECIFIED);
1418 cli_credentials_set_password(wks_creds,
1419 generate_random_password(wks_creds, 8, 255),
1422 torture_assert(tctx,
1423 join3(tctx, cli, use_level25, samr_creds, wks_creds),
1426 cli_credentials_set_domain(
1427 cmdline_credentials, cli_credentials_get_domain(wks_creds),
1430 torture_assert(tctx,
1431 auth2(tctx, cli, wks_creds),
1434 torture_assert(tctx,
1435 leave(tctx, cli, samr_creds, wks_creds),
1444 * Test the different session key variants. Do it by joining, this uses the
1445 * session key in the setpassword routine. Test the join by doing the auth2.
1448 static bool torture_samba3_sessionkey(struct torture_context *torture)
1450 struct cli_credentials *anon_creds;
1451 const char *wks_name;
1453 wks_name = torture_setting_string(torture, "wksname", get_myname(torture));
1455 if (!(anon_creds = cli_credentials_init_anon(torture))) {
1456 torture_fail(torture, "create_anon_creds failed\n");
1459 cli_credentials_set_workstation(anon_creds, wks_name, CRED_SPECIFIED);
1462 if (!torture_setting_bool(torture, "samba3", false)) {
1464 /* Samba3 in the build farm right now does this happily. Need
1467 if (test_join3(torture, false, anon_creds, NULL, wks_name)) {
1468 torture_fail(torture, "join using anonymous bind on an anonymous smb "
1469 "connection succeeded -- HUH??\n");
1473 torture_assert(torture,
1474 test_join3(torture, false, anon_creds, cmdline_credentials, wks_name),
1475 "join using ntlmssp bind on an anonymous smb connection failed");
1477 torture_assert(torture,
1478 test_join3(torture, false, cmdline_credentials, NULL, wks_name),
1479 "join using anonymous bind on an authenticated smb connection failed");
1481 torture_assert(torture,
1482 test_join3(torture, false, cmdline_credentials, cmdline_credentials, wks_name),
1483 "join using ntlmssp bind on an authenticated smb connection failed");
1486 * The following two are tests for setuserinfolevel 25
1489 torture_assert(torture,
1490 test_join3(torture, true, anon_creds, cmdline_credentials, wks_name),
1491 "join using ntlmssp bind on an anonymous smb connection failed");
1493 torture_assert(torture,
1494 test_join3(torture, true, cmdline_credentials, NULL, wks_name),
1495 "join using anonymous bind on an authenticated smb connection failed");
1501 * open pipe and bind, given an IPC$ context
1504 static NTSTATUS pipe_bind_smb(struct torture_context *tctx,
1505 TALLOC_CTX *mem_ctx,
1506 struct smbcli_tree *tree,
1507 const char *pipe_name,
1508 const struct ndr_interface_table *iface,
1509 struct dcerpc_pipe **p)
1511 struct dcerpc_pipe *result;
1514 if (!(result = dcerpc_pipe_init(mem_ctx, tctx->ev))) {
1515 return NT_STATUS_NO_MEMORY;
1518 status = dcerpc_pipe_open_smb(result, tree, pipe_name);
1519 if (!NT_STATUS_IS_OK(status)) {
1520 torture_comment(tctx, "dcerpc_pipe_open_smb failed: %s\n",
1522 talloc_free(result);
1526 status = dcerpc_bind_auth_none(result, iface);
1527 if (!NT_STATUS_IS_OK(status)) {
1528 torture_comment(tctx, "schannel bind failed: %s\n", nt_errstr(status));
1529 talloc_free(result);
1534 return NT_STATUS_OK;
1538 * Sane wrapper around lsa_LookupNames
1541 static struct dom_sid *name2sid(struct torture_context *tctx,
1542 TALLOC_CTX *mem_ctx,
1543 struct dcerpc_pipe *p,
1547 struct lsa_ObjectAttribute attr;
1548 struct lsa_QosInfo qos;
1549 struct lsa_OpenPolicy2 r;
1552 struct policy_handle handle;
1553 struct lsa_LookupNames l;
1554 struct lsa_TransSidArray sids;
1555 struct lsa_RefDomainList *domains = NULL;
1556 struct lsa_String lsa_name;
1558 struct dom_sid *result;
1559 TALLOC_CTX *tmp_ctx;
1560 struct dcerpc_binding_handle *b = p->binding_handle;
1562 if (!(tmp_ctx = talloc_new(mem_ctx))) {
1567 qos.impersonation_level = 2;
1568 qos.context_mode = 1;
1569 qos.effective_only = 0;
1572 attr.root_dir = NULL;
1573 attr.object_name = NULL;
1574 attr.attributes = 0;
1575 attr.sec_desc = NULL;
1576 attr.sec_qos = &qos;
1578 r.in.system_name = "\\";
1580 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1581 r.out.handle = &handle;
1583 status = dcerpc_lsa_OpenPolicy2_r(b, tmp_ctx, &r);
1584 if (!NT_STATUS_IS_OK(status)) {
1585 torture_comment(tctx, "OpenPolicy2 failed - %s\n", nt_errstr(status));
1586 talloc_free(tmp_ctx);
1589 if (!NT_STATUS_IS_OK(r.out.result)) {
1590 torture_comment(tctx, "OpenPolicy2 failed - %s\n", nt_errstr(r.out.result));
1591 talloc_free(tmp_ctx);
1598 lsa_name.string = talloc_asprintf(tmp_ctx, "%s\\%s", domain, name);
1600 l.in.handle = &handle;
1602 l.in.names = &lsa_name;
1605 l.in.count = &count;
1606 l.out.count = &count;
1608 l.out.domains = &domains;
1610 status = dcerpc_lsa_LookupNames_r(b, tmp_ctx, &l);
1611 if (!NT_STATUS_IS_OK(status)) {
1612 torture_comment(tctx, "LookupNames of %s failed - %s\n", lsa_name.string,
1614 talloc_free(tmp_ctx);
1617 if (!NT_STATUS_IS_OK(l.out.result)) {
1618 torture_comment(tctx, "LookupNames of %s failed - %s\n", lsa_name.string,
1619 nt_errstr(l.out.result));
1620 talloc_free(tmp_ctx);
1624 result = dom_sid_add_rid(mem_ctx, domains->domains[0].sid,
1625 l.out.sids->sids[0].rid);
1627 c.in.handle = &handle;
1628 c.out.handle = &handle;
1630 status = dcerpc_lsa_Close_r(b, tmp_ctx, &c);
1631 if (!NT_STATUS_IS_OK(status)) {
1632 torture_comment(tctx, "dcerpc_lsa_Close failed - %s\n", nt_errstr(status));
1633 talloc_free(tmp_ctx);
1636 if (!NT_STATUS_IS_OK(c.out.result)) {
1637 torture_comment(tctx, "dcerpc_lsa_Close failed - %s\n", nt_errstr(c.out.result));
1638 talloc_free(tmp_ctx);
1642 talloc_free(tmp_ctx);
1647 * Find out the user SID on this connection
1650 static struct dom_sid *whoami(struct torture_context *tctx,
1651 TALLOC_CTX *mem_ctx,
1652 struct smbcli_tree *tree)
1654 struct dcerpc_pipe *lsa;
1655 struct dcerpc_binding_handle *lsa_handle;
1656 struct lsa_GetUserName r;
1658 struct lsa_String *authority_name_p = NULL;
1659 struct lsa_String *account_name_p = NULL;
1660 struct dom_sid *result;
1662 status = pipe_bind_smb(tctx, mem_ctx, tree, "\\pipe\\lsarpc",
1663 &ndr_table_lsarpc, &lsa);
1664 if (!NT_STATUS_IS_OK(status)) {
1665 torture_warning(tctx, "Could not bind to LSA: %s\n",
1669 lsa_handle = lsa->binding_handle;
1671 r.in.system_name = "\\";
1672 r.in.account_name = &account_name_p;
1673 r.in.authority_name = &authority_name_p;
1674 r.out.account_name = &account_name_p;
1676 status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r);
1678 authority_name_p = *r.out.authority_name;
1680 if (!NT_STATUS_IS_OK(status)) {
1681 torture_warning(tctx, "GetUserName failed - %s\n",
1686 if (!NT_STATUS_IS_OK(r.out.result)) {
1687 torture_warning(tctx, "GetUserName failed - %s\n",
1688 nt_errstr(r.out.result));
1693 result = name2sid(tctx, mem_ctx, lsa, account_name_p->string,
1694 authority_name_p->string);
1700 static int destroy_tree(struct smbcli_tree *tree)
1702 smb_tree_disconnect(tree);
1707 * Do a tcon, given a session
1710 static NTSTATUS secondary_tcon(struct torture_context *tctx,
1711 TALLOC_CTX *mem_ctx,
1712 struct smbcli_session *session,
1713 const char *sharename,
1714 struct smbcli_tree **res)
1716 struct smbcli_tree *result;
1717 TALLOC_CTX *tmp_ctx;
1718 union smb_tcon tcon;
1721 if (!(tmp_ctx = talloc_new(mem_ctx))) {
1722 return NT_STATUS_NO_MEMORY;
1725 if (!(result = smbcli_tree_init(session, mem_ctx, false))) {
1726 talloc_free(tmp_ctx);
1727 return NT_STATUS_NO_MEMORY;
1730 tcon.generic.level = RAW_TCON_TCONX;
1731 tcon.tconx.in.flags = TCONX_FLAG_EXTENDED_RESPONSE;
1732 tcon.tconx.in.flags |= TCONX_FLAG_EXTENDED_SIGNATURES;
1733 tcon.tconx.in.password = data_blob(NULL, 0);
1734 tcon.tconx.in.path = sharename;
1735 tcon.tconx.in.device = "?????";
1737 status = smb_raw_tcon(result, tmp_ctx, &tcon);
1738 if (!NT_STATUS_IS_OK(status)) {
1739 torture_warning(tctx, "smb_raw_tcon failed: %s\n",
1741 talloc_free(tmp_ctx);
1745 result->tid = tcon.tconx.out.tid;
1747 if (tcon.tconx.out.options & SMB_EXTENDED_SIGNATURES) {
1748 smb1cli_session_protect_session_key(result->session->smbXcli);
1751 result = talloc_steal(mem_ctx, result);
1752 talloc_set_destructor(result, destroy_tree);
1753 talloc_free(tmp_ctx);
1755 return NT_STATUS_OK;
1759 * Test the getusername behaviour
1762 static bool torture_samba3_rpc_getusername(struct torture_context *torture)
1765 struct smbcli_state *cli;
1767 struct dom_sid *user_sid;
1768 struct dom_sid *created_sid;
1769 struct cli_credentials *anon_creds;
1770 struct cli_credentials *user_creds;
1772 struct smbcli_options options;
1773 struct smbcli_session_options session_options;
1775 lpcfg_smbcli_options(torture->lp_ctx, &options);
1776 lpcfg_smbcli_session_options(torture->lp_ctx, &session_options);
1778 status = smbcli_full_connection(
1779 torture, &cli, torture_setting_string(torture, "host", NULL),
1780 lpcfg_smb_ports(torture->lp_ctx),
1781 "IPC$", NULL, lpcfg_socket_options(torture->lp_ctx), cmdline_credentials,
1782 lpcfg_resolve_context(torture->lp_ctx), torture->ev, &options,
1783 &session_options, lpcfg_gensec_settings(torture, torture->lp_ctx));
1784 torture_assert_ntstatus_ok(torture, status, "smbcli_full_connection failed\n");
1786 if (!(user_sid = whoami(torture, torture, cli->tree))) {
1787 torture_fail(torture, "whoami on auth'ed connection failed\n");
1792 if (!(anon_creds = cli_credentials_init_anon(torture))) {
1793 torture_fail(torture, "create_anon_creds failed\n");
1796 status = smbcli_full_connection(
1797 torture, &cli, torture_setting_string(torture, "host", NULL),
1798 lpcfg_smb_ports(torture->lp_ctx), "IPC$", NULL,
1799 lpcfg_socket_options(torture->lp_ctx), anon_creds,
1800 lpcfg_resolve_context(torture->lp_ctx),
1801 torture->ev, &options, &session_options,
1802 lpcfg_gensec_settings(torture, torture->lp_ctx));
1803 torture_assert_ntstatus_ok(torture, status, "anon smbcli_full_connection failed\n");
1805 if (!(user_sid = whoami(torture, torture, cli->tree))) {
1806 torture_fail(torture, "whoami on anon connection failed\n");
1809 torture_assert_sid_equal(torture, user_sid, dom_sid_parse_talloc(torture, "s-1-5-7"),
1810 "Anon lsa_GetUserName returned unexpected SID");
1812 if (!(user_creds = cli_credentials_init(torture))) {
1813 torture_fail(torture, "cli_credentials_init failed\n");
1816 cli_credentials_set_conf(user_creds, torture->lp_ctx);
1817 cli_credentials_set_username(user_creds, "torture_username",
1819 cli_credentials_set_password(user_creds,
1820 generate_random_password(user_creds, 8, 255),
1823 if (!create_user(torture, torture, cli, cmdline_credentials,
1824 cli_credentials_get_username(user_creds),
1825 cli_credentials_get_password(user_creds),
1826 &domain_name, &created_sid)) {
1827 torture_fail(torture, "create_user failed\n");
1830 cli_credentials_set_domain(user_creds, domain_name,
1834 struct smbcli_session *session2;
1835 struct smb_composite_sesssetup setup;
1836 struct smbcli_tree *tree;
1838 session2 = smbcli_session_init(cli->transport, torture, false, session_options);
1839 if (session2 == NULL) {
1840 torture_fail(torture, "smbcli_session_init failed\n");
1843 setup.in.sesskey = cli->transport->negotiate.sesskey;
1844 setup.in.capabilities = cli->transport->negotiate.capabilities;
1845 setup.in.workgroup = "";
1846 setup.in.credentials = user_creds;
1847 setup.in.gensec_settings = lpcfg_gensec_settings(torture, torture->lp_ctx);
1849 status = smb_composite_sesssetup(session2, &setup);
1850 torture_assert_ntstatus_ok(torture, status, "session setup with new user failed");
1852 session2->vuid = setup.out.vuid;
1854 if (!NT_STATUS_IS_OK(secondary_tcon(torture, torture, session2,
1856 torture_fail(torture, "secondary_tcon failed\n");
1859 if (!(user_sid = whoami(torture, torture, tree))) {
1860 torture_fail_goto(torture, del, "whoami on user connection failed\n");
1868 torture_comment(torture, "Created %s, found %s\n",
1869 dom_sid_string(torture, created_sid),
1870 dom_sid_string(torture, user_sid));
1872 if (!dom_sid_equal(created_sid, user_sid)) {
1877 if (!delete_user(torture, cli,
1878 cmdline_credentials,
1879 cli_credentials_get_username(user_creds))) {
1880 torture_fail(torture, "delete_user failed\n");
1886 static bool test_NetShareGetInfo(struct torture_context *tctx,
1887 struct dcerpc_pipe *p,
1888 const char *sharename)
1891 struct srvsvc_NetShareGetInfo r;
1892 union srvsvc_NetShareInfo info;
1893 uint32_t levels[] = { 0, 1, 2, 501, 502, 1004, 1005, 1006, 1007, 1501 };
1896 struct dcerpc_binding_handle *b = p->binding_handle;
1898 r.in.server_unc = talloc_asprintf(tctx, "\\\\%s",
1899 dcerpc_server_name(p));
1900 r.in.share_name = sharename;
1903 for (i=0;i<ARRAY_SIZE(levels);i++) {
1904 r.in.level = levels[i];
1906 torture_comment(tctx, "Testing NetShareGetInfo level %u on share '%s'\n",
1907 r.in.level, r.in.share_name);
1909 status = dcerpc_srvsvc_NetShareGetInfo_r(b, tctx, &r);
1910 if (!NT_STATUS_IS_OK(status)) {
1911 torture_warning(tctx, "NetShareGetInfo level %u on share '%s' failed"
1912 " - %s\n", r.in.level, r.in.share_name,
1917 if (!W_ERROR_IS_OK(r.out.result)) {
1918 torture_warning(tctx, "NetShareGetInfo level %u on share '%s' failed "
1919 "- %s\n", r.in.level, r.in.share_name,
1920 win_errstr(r.out.result));
1929 static bool test_NetShareEnum(struct torture_context *tctx,
1930 struct dcerpc_pipe *p,
1931 const char **one_sharename)
1934 struct srvsvc_NetShareEnum r;
1935 struct srvsvc_NetShareInfoCtr info_ctr;
1936 struct srvsvc_NetShareCtr0 c0;
1937 struct srvsvc_NetShareCtr1 c1;
1938 struct srvsvc_NetShareCtr2 c2;
1939 struct srvsvc_NetShareCtr501 c501;
1940 struct srvsvc_NetShareCtr502 c502;
1941 struct srvsvc_NetShareCtr1004 c1004;
1942 struct srvsvc_NetShareCtr1005 c1005;
1943 struct srvsvc_NetShareCtr1006 c1006;
1944 struct srvsvc_NetShareCtr1007 c1007;
1945 uint32_t totalentries = 0;
1946 uint32_t levels[] = { 0, 1, 2, 501, 502, 1004, 1005, 1006, 1007 };
1949 struct dcerpc_binding_handle *b = p->binding_handle;
1951 ZERO_STRUCT(info_ctr);
1953 r.in.server_unc = talloc_asprintf(tctx,"\\\\%s",dcerpc_server_name(p));
1954 r.in.info_ctr = &info_ctr;
1955 r.in.max_buffer = (uint32_t)-1;
1956 r.in.resume_handle = NULL;
1957 r.out.totalentries = &totalentries;
1958 r.out.info_ctr = &info_ctr;
1960 for (i=0;i<ARRAY_SIZE(levels);i++) {
1961 info_ctr.level = levels[i];
1963 switch (info_ctr.level) {
1966 info_ctr.ctr.ctr0 = &c0;
1970 info_ctr.ctr.ctr1 = &c1;
1974 info_ctr.ctr.ctr2 = &c2;
1978 info_ctr.ctr.ctr501 = &c501;
1982 info_ctr.ctr.ctr502 = &c502;
1986 info_ctr.ctr.ctr1004 = &c1004;
1990 info_ctr.ctr.ctr1005 = &c1005;
1994 info_ctr.ctr.ctr1006 = &c1006;
1998 info_ctr.ctr.ctr1007 = &c1007;
2002 torture_comment(tctx, "Testing NetShareEnum level %u\n", info_ctr.level);
2004 status = dcerpc_srvsvc_NetShareEnum_r(b, tctx, &r);
2005 if (!NT_STATUS_IS_OK(status)) {
2006 torture_warning(tctx, "NetShareEnum level %u failed - %s\n",
2007 info_ctr.level, nt_errstr(status));
2011 if (!W_ERROR_IS_OK(r.out.result)) {
2012 torture_warning(tctx, "NetShareEnum level %u failed - %s\n",
2013 info_ctr.level, win_errstr(r.out.result));
2016 if (info_ctr.level == 0) {
2017 struct srvsvc_NetShareCtr0 *ctr = r.out.info_ctr->ctr.ctr0;
2018 if (ctr->count > 0) {
2019 *one_sharename = ctr->array[0].name;
2027 static bool torture_samba3_rpc_srvsvc(struct torture_context *torture)
2029 struct dcerpc_pipe *p;
2030 const char *sharename = NULL;
2033 torture_assert_ntstatus_ok(torture,
2034 torture_rpc_connection(torture, &p, &ndr_table_srvsvc),
2035 "failed to open srvsvc");
2037 ret &= test_NetShareEnum(torture, p, &sharename);
2038 if (sharename == NULL) {
2039 torture_comment(torture, "did not get sharename\n");
2041 ret &= test_NetShareGetInfo(torture, p, sharename);
2048 * Do a ReqChallenge/Auth2 with a random wks name, make sure it returns
2049 * NT_STATUS_NO_SAM_ACCOUNT
2052 static bool torture_samba3_rpc_randomauth2(struct torture_context *torture)
2054 TALLOC_CTX *mem_ctx;
2055 struct dcerpc_pipe *net_pipe;
2056 struct dcerpc_binding_handle *net_handle;
2058 bool result = false;
2060 struct netr_ServerReqChallenge r;
2061 struct netr_Credential netr_cli_creds;
2062 struct netr_Credential netr_srv_creds;
2063 uint32_t negotiate_flags;
2064 struct netr_ServerAuthenticate2 a;
2065 struct netlogon_creds_CredentialState *creds_state;
2066 struct netr_Credential netr_cred;
2067 struct samr_Password mach_pw;
2068 struct smbcli_state *cli;
2070 if (!(mem_ctx = talloc_new(torture))) {
2071 torture_comment(torture, "talloc_new failed\n");
2075 if (!(wksname = generate_random_str_list(
2076 mem_ctx, 14, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"))) {
2077 torture_comment(torture, "generate_random_str_list failed\n");
2081 if (!(torture_open_connection_share(
2083 torture, torture_setting_string(torture, "host", NULL),
2084 "IPC$", torture->ev))) {
2085 torture_comment(torture, "IPC$ connection failed\n");
2089 if (!(net_pipe = dcerpc_pipe_init(mem_ctx, torture->ev))) {
2090 torture_comment(torture, "dcerpc_pipe_init failed\n");
2093 net_handle = net_pipe->binding_handle;
2095 status = dcerpc_pipe_open_smb(net_pipe, cli->tree, "\\netlogon");
2096 if (!NT_STATUS_IS_OK(status)) {
2097 torture_comment(torture, "dcerpc_pipe_open_smb failed: %s\n",
2102 status = dcerpc_bind_auth_none(net_pipe, &ndr_table_netlogon);
2103 if (!NT_STATUS_IS_OK(status)) {
2104 torture_comment(torture, "dcerpc_bind_auth_none failed: %s\n",
2109 r.in.computer_name = wksname;
2110 r.in.server_name = talloc_asprintf(
2111 mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
2112 if (r.in.server_name == NULL) {
2113 torture_comment(torture, "talloc_asprintf failed\n");
2116 generate_random_buffer(netr_cli_creds.data,
2117 sizeof(netr_cli_creds.data));
2118 r.in.credentials = &netr_cli_creds;
2119 r.out.return_credentials = &netr_srv_creds;
2121 status = dcerpc_netr_ServerReqChallenge_r(net_handle, mem_ctx, &r);
2122 if (!NT_STATUS_IS_OK(status)) {
2123 torture_comment(torture, "netr_ServerReqChallenge failed: %s\n",
2127 if (!NT_STATUS_IS_OK(r.out.result)) {
2128 torture_comment(torture, "netr_ServerReqChallenge failed: %s\n",
2129 nt_errstr(r.out.result));
2133 negotiate_flags = NETLOGON_NEG_AUTH2_FLAGS;
2134 E_md4hash("foobar", mach_pw.hash);
2136 a.in.server_name = talloc_asprintf(
2137 mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
2138 a.in.account_name = talloc_asprintf(
2139 mem_ctx, "%s$", wksname);
2140 a.in.computer_name = wksname;
2141 a.in.secure_channel_type = SEC_CHAN_WKSTA;
2142 a.in.negotiate_flags = &negotiate_flags;
2143 a.out.negotiate_flags = &negotiate_flags;
2144 a.in.credentials = &netr_cred;
2145 a.out.return_credentials = &netr_cred;
2147 creds_state = netlogon_creds_client_init(mem_ctx,
2151 r.out.return_credentials, &mach_pw,
2152 &netr_cred, negotiate_flags);
2153 torture_assert(torture, (creds_state != NULL), "memory allocation failed");
2155 status = dcerpc_netr_ServerAuthenticate2_r(net_handle, mem_ctx, &a);
2156 if (!NT_STATUS_IS_OK(status)) {
2159 if (!NT_STATUS_EQUAL(a.out.result, NT_STATUS_NO_TRUST_SAM_ACCOUNT)) {
2160 torture_comment(torture, "dcerpc_netr_ServerAuthenticate2 returned %s, "
2161 "expected NT_STATUS_NO_TRUST_SAM_ACCOUNT\n",
2162 nt_errstr(a.out.result));
2168 talloc_free(mem_ctx);
2172 static struct security_descriptor *get_sharesec(struct torture_context *tctx,
2173 TALLOC_CTX *mem_ctx,
2174 struct smbcli_session *sess,
2175 const char *sharename)
2177 struct smbcli_tree *tree;
2178 TALLOC_CTX *tmp_ctx;
2179 struct dcerpc_pipe *p;
2180 struct dcerpc_binding_handle *b;
2182 struct srvsvc_NetShareGetInfo r;
2183 union srvsvc_NetShareInfo info;
2184 struct security_descriptor *result;
2186 if (!(tmp_ctx = talloc_new(mem_ctx))) {
2187 torture_comment(tctx, "talloc_new failed\n");
2191 if (!NT_STATUS_IS_OK(secondary_tcon(tctx, tmp_ctx, sess, "IPC$", &tree))) {
2192 torture_comment(tctx, "secondary_tcon failed\n");
2193 talloc_free(tmp_ctx);
2197 status = pipe_bind_smb(tctx, mem_ctx, tree, "\\pipe\\srvsvc",
2198 &ndr_table_srvsvc, &p);
2199 if (!NT_STATUS_IS_OK(status)) {
2200 torture_warning(tctx, "could not bind to srvsvc pipe: %s\n",
2202 talloc_free(tmp_ctx);
2205 b = p->binding_handle;
2208 p->conn->flags |= DCERPC_DEBUG_PRINT_IN | DCERPC_DEBUG_PRINT_OUT;
2211 r.in.server_unc = talloc_asprintf(tmp_ctx, "\\\\%s",
2212 dcerpc_server_name(p));
2213 r.in.share_name = sharename;
2217 status = dcerpc_srvsvc_NetShareGetInfo_r(b, tmp_ctx, &r);
2218 if (!NT_STATUS_IS_OK(status)) {
2219 torture_comment(tctx, "srvsvc_NetShareGetInfo failed: %s\n",
2221 talloc_free(tmp_ctx);
2224 if (!W_ERROR_IS_OK(r.out.result)) {
2225 torture_comment(tctx, "srvsvc_NetShareGetInfo failed: %s\n",
2226 win_errstr(r.out.result));
2227 talloc_free(tmp_ctx);
2231 result = talloc_steal(mem_ctx, info.info502->sd_buf.sd);
2232 talloc_free(tmp_ctx);
2236 static NTSTATUS set_sharesec(struct torture_context *tctx,
2237 TALLOC_CTX *mem_ctx,
2238 struct smbcli_session *sess,
2239 const char *sharename,
2240 struct security_descriptor *sd)
2242 struct smbcli_tree *tree;
2243 TALLOC_CTX *tmp_ctx;
2244 struct dcerpc_pipe *p;
2245 struct dcerpc_binding_handle *b;
2247 struct sec_desc_buf i;
2248 struct srvsvc_NetShareSetInfo r;
2249 union srvsvc_NetShareInfo info;
2252 if (!(tmp_ctx = talloc_new(mem_ctx))) {
2253 torture_comment(tctx, "talloc_new failed\n");
2254 return NT_STATUS_NO_MEMORY;
2257 if (!NT_STATUS_IS_OK(secondary_tcon(tctx, tmp_ctx, sess, "IPC$", &tree))) {
2258 torture_comment(tctx, "secondary_tcon failed\n");
2259 talloc_free(tmp_ctx);
2260 return NT_STATUS_UNSUCCESSFUL;
2263 status = pipe_bind_smb(tctx, mem_ctx, tree, "\\pipe\\srvsvc",
2264 &ndr_table_srvsvc, &p);
2265 if (!NT_STATUS_IS_OK(status)) {
2266 torture_warning(tctx, "could not bind to srvsvc pipe: %s\n",
2268 talloc_free(tmp_ctx);
2269 return NT_STATUS_UNSUCCESSFUL;
2271 b = p->binding_handle;
2274 p->conn->flags |= DCERPC_DEBUG_PRINT_IN | DCERPC_DEBUG_PRINT_OUT;
2277 r.in.server_unc = talloc_asprintf(tmp_ctx, "\\\\%s",
2278 dcerpc_server_name(p));
2279 r.in.share_name = sharename;
2284 r.in.parm_error = &error;
2286 status = dcerpc_srvsvc_NetShareSetInfo_r(b, tmp_ctx, &r);
2287 if (!NT_STATUS_IS_OK(status)) {
2288 torture_comment(tctx, "srvsvc_NetShareSetInfo failed: %s\n",
2291 if (!W_ERROR_IS_OK(r.out.result)) {
2292 torture_comment(tctx, "srvsvc_NetShareSetInfo failed: %s\n",
2293 win_errstr(r.out.result));
2294 status = werror_to_ntstatus(r.out.result);
2296 talloc_free(tmp_ctx);
2300 bool try_tcon(struct torture_context *tctx,
2301 TALLOC_CTX *mem_ctx,
2302 struct security_descriptor *orig_sd,
2303 struct smbcli_session *session,
2304 const char *sharename, const struct dom_sid *user_sid,
2305 unsigned int access_mask, NTSTATUS expected_tcon,
2306 NTSTATUS expected_mkdir)
2308 TALLOC_CTX *tmp_ctx;
2309 struct smbcli_tree *rmdir_tree, *tree;
2310 struct dom_sid *domain_sid;
2312 struct security_descriptor *sd;
2316 if (!(tmp_ctx = talloc_new(mem_ctx))) {
2317 torture_comment(tctx, "talloc_new failed\n");
2321 status = secondary_tcon(tctx, tmp_ctx, session, sharename, &rmdir_tree);
2322 if (!NT_STATUS_IS_OK(status)) {
2323 torture_comment(tctx, "first tcon to delete dir failed\n");
2324 talloc_free(tmp_ctx);
2328 smbcli_rmdir(rmdir_tree, "sharesec_testdir");
2330 if (!NT_STATUS_IS_OK(dom_sid_split_rid(tmp_ctx, user_sid,
2331 &domain_sid, &rid))) {
2332 torture_comment(tctx, "dom_sid_split_rid failed\n");
2333 talloc_free(tmp_ctx);
2337 sd = security_descriptor_dacl_create(
2338 tmp_ctx, 0, "S-1-5-32-544",
2339 dom_sid_string(mem_ctx, dom_sid_add_rid(mem_ctx, domain_sid,
2341 dom_sid_string(mem_ctx, user_sid),
2342 SEC_ACE_TYPE_ACCESS_ALLOWED, access_mask, 0, NULL);
2344 torture_comment(tctx, "security_descriptor_dacl_create failed\n");
2345 talloc_free(tmp_ctx);
2349 status = set_sharesec(tctx, mem_ctx, session, sharename, sd);
2350 if (!NT_STATUS_IS_OK(status)) {
2351 torture_comment(tctx, "custom set_sharesec failed: %s\n",
2353 talloc_free(tmp_ctx);
2357 status = secondary_tcon(tctx, tmp_ctx, session, sharename, &tree);
2358 if (!NT_STATUS_EQUAL(status, expected_tcon)) {
2359 torture_comment(tctx, "Expected %s, got %s\n", nt_errstr(expected_tcon),
2365 if (!NT_STATUS_IS_OK(status)) {
2366 /* An expected non-access, no point in trying to write */
2370 status = smbcli_mkdir(tree, "sharesec_testdir");
2371 if (!NT_STATUS_EQUAL(status, expected_mkdir)) {
2372 torture_warning(tctx, "Expected %s, got %s\n",
2373 nt_errstr(expected_mkdir), nt_errstr(status));
2378 smbcli_rmdir(rmdir_tree, "sharesec_testdir");
2380 status = set_sharesec(tctx, mem_ctx, session, sharename, orig_sd);
2381 if (!NT_STATUS_IS_OK(status)) {
2382 torture_comment(tctx, "custom set_sharesec failed: %s\n",
2384 talloc_free(tmp_ctx);
2388 talloc_free(tmp_ctx);
2392 static bool torture_samba3_rpc_sharesec(struct torture_context *torture)
2394 struct smbcli_state *cli;
2395 struct security_descriptor *sd;
2396 struct dom_sid *user_sid;
2398 if (!(torture_open_connection_share(
2399 torture, &cli, torture, torture_setting_string(torture, "host", NULL),
2400 "IPC$", torture->ev))) {
2401 torture_fail(torture, "IPC$ connection failed\n");
2404 if (!(user_sid = whoami(torture, torture, cli->tree))) {
2405 torture_fail(torture, "whoami failed\n");
2408 sd = get_sharesec(torture, torture, cli->session,
2409 torture_setting_string(torture, "share", NULL));
2411 torture_assert(torture, try_tcon(
2412 torture, torture, sd, cli->session,
2413 torture_setting_string(torture, "share", NULL),
2414 user_sid, 0, NT_STATUS_ACCESS_DENIED, NT_STATUS_OK),
2415 "failed to test tcon with 0 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_READ_DATA, NT_STATUS_OK,
2421 NT_STATUS_MEDIA_WRITE_PROTECTED),
2422 "failed to test tcon with SEC_FILE_READ_DATA access_mask");
2424 torture_assert(torture, try_tcon(
2425 torture, torture, sd, cli->session,
2426 torture_setting_string(torture, "share", NULL),
2427 user_sid, SEC_FILE_ALL, NT_STATUS_OK, NT_STATUS_OK),
2428 "failed to test tcon with SEC_FILE_ALL access_mask")
2433 static bool torture_samba3_rpc_lsa(struct torture_context *torture)
2435 struct dcerpc_pipe *p;
2436 struct dcerpc_binding_handle *b;
2437 struct policy_handle lsa_handle;
2439 torture_assert_ntstatus_ok(torture,
2440 torture_rpc_connection(torture, &p, &ndr_table_lsarpc),
2441 "failed to setup lsarpc");
2443 b = p->binding_handle;
2446 struct lsa_ObjectAttribute attr;
2447 struct lsa_OpenPolicy2 o;
2448 o.in.system_name = talloc_asprintf(
2449 torture, "\\\\%s", dcerpc_server_name(p));
2452 o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2453 o.out.handle = &lsa_handle;
2455 torture_assert_ntstatus_ok(torture,
2456 dcerpc_lsa_OpenPolicy2_r(b, torture, &o),
2457 "dcerpc_lsa_OpenPolicy2 failed");
2458 torture_assert_ntstatus_ok(torture, o.out.result,
2459 "dcerpc_lsa_OpenPolicy2 failed");
2464 int levels[] = { 2,3,5,6 };
2466 for (i=0; i<ARRAY_SIZE(levels); i++) {
2467 struct lsa_QueryInfoPolicy r;
2468 union lsa_PolicyInformation *info = NULL;
2469 r.in.handle = &lsa_handle;
2470 r.in.level = levels[i];
2473 torture_assert_ntstatus_ok(torture,
2474 dcerpc_lsa_QueryInfoPolicy_r(b, torture, &r),
2475 talloc_asprintf(torture, "dcerpc_lsa_QueryInfoPolicy level %d failed", levels[i]));
2476 torture_assert_ntstatus_ok(torture, r.out.result,
2477 talloc_asprintf(torture, "dcerpc_lsa_QueryInfoPolicy level %d failed", levels[i]));
2484 static NTSTATUS get_servername(TALLOC_CTX *mem_ctx, struct smbcli_tree *tree,
2487 struct rap_WserverGetInfo r;
2489 char servername[17];
2490 size_t converted_size;
2493 r.in.bufsize = 0xffff;
2495 status = smbcli_rap_netservergetinfo(tree, mem_ctx, &r);
2496 if (!NT_STATUS_IS_OK(status)) {
2500 memcpy(servername, r.out.info.info0.name, 16);
2501 servername[16] = '\0';
2503 if (!pull_ascii_talloc(mem_ctx, name, servername, &converted_size)) {
2504 return NT_STATUS_NO_MEMORY;
2507 return NT_STATUS_OK;
2510 static bool rap_get_servername(struct torture_context *tctx,
2513 struct smbcli_state *cli;
2515 torture_assert(tctx,
2516 torture_open_connection_share(tctx, &cli, tctx, torture_setting_string(tctx, "host", NULL),
2518 "IPC$ connection failed");
2520 torture_assert_ntstatus_ok(tctx,
2521 get_servername(tctx, cli->tree, servername),
2522 "get_servername failed");
2529 static bool find_printers(struct torture_context *tctx,
2530 struct dcerpc_pipe *p,
2531 const char ***printers,
2534 struct srvsvc_NetShareEnum r;
2535 struct srvsvc_NetShareInfoCtr info_ctr;
2536 struct srvsvc_NetShareCtr1 c1_in;
2537 struct srvsvc_NetShareCtr1 *c1;
2538 uint32_t totalentries = 0;
2540 struct dcerpc_binding_handle *b = p->binding_handle;
2544 info_ctr.ctr.ctr1 = &c1_in;
2546 r.in.server_unc = talloc_asprintf(
2547 tctx, "\\\\%s", dcerpc_server_name(p));
2548 r.in.info_ctr = &info_ctr;
2549 r.in.max_buffer = (uint32_t)-1;
2550 r.in.resume_handle = NULL;
2551 r.out.totalentries = &totalentries;
2552 r.out.info_ctr = &info_ctr;
2554 torture_assert_ntstatus_ok(tctx,
2555 dcerpc_srvsvc_NetShareEnum_r(b, tctx, &r),
2556 "NetShareEnum level 1 failed");
2557 torture_assert_werr_ok(tctx, r.out.result,
2558 "NetShareEnum level 1 failed");
2562 c1 = r.out.info_ctr->ctr.ctr1;
2563 for (i=0; i<c1->count; i++) {
2564 if (c1->array[i].type != STYPE_PRINTQ) {
2567 if (!add_string_to_array(tctx, c1->array[i].name,
2568 printers, num_printers)) {
2576 static bool enumprinters(struct torture_context *tctx,
2577 struct dcerpc_binding_handle *b,
2578 const char *servername, int level, int *num_printers)
2580 struct spoolss_EnumPrinters r;
2584 union spoolss_PrinterInfo *info;
2586 r.in.flags = PRINTER_ENUM_LOCAL;
2587 r.in.server = talloc_asprintf(tctx, "\\\\%s", servername);
2591 r.out.needed = &needed;
2592 r.out.count = &count;
2595 torture_assert_ntstatus_ok(tctx,
2596 dcerpc_spoolss_EnumPrinters_r(b, tctx, &r),
2597 "dcerpc_spoolss_EnumPrinters failed");
2598 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
2599 "EnumPrinters unexpected return code should be WERR_INSUFFICIENT_BUFFER");
2601 blob = data_blob_talloc_zero(tctx, needed);
2602 if (blob.data == NULL) {
2606 r.in.buffer = &blob;
2607 r.in.offered = needed;
2609 torture_assert_ntstatus_ok(tctx,
2610 dcerpc_spoolss_EnumPrinters_r(b, tctx, &r),
2611 "dcerpc_spoolss_EnumPrinters failed");
2612 torture_assert_werr_ok(tctx, r.out.result,
2613 "dcerpc_spoolss_EnumPrinters failed");
2615 *num_printers = count;
2620 static bool getprinterinfo(struct torture_context *tctx,
2621 struct dcerpc_binding_handle *b,
2622 struct policy_handle *handle, int level,
2623 union spoolss_PrinterInfo **res)
2625 struct spoolss_GetPrinter r;
2629 r.in.handle = handle;
2633 r.out.needed = &needed;
2635 torture_assert_ntstatus_ok(tctx,
2636 dcerpc_spoolss_GetPrinter_r(b, tctx, &r),
2637 "dcerpc_spoolss_GetPrinter failed");
2638 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
2639 "GetPrinter unexpected return code should be WERR_INSUFFICIENT_BUFFER");
2641 r.in.handle = handle;
2643 blob = data_blob_talloc_zero(tctx, needed);
2644 if (blob.data == NULL) {
2647 r.in.buffer = &blob;
2648 r.in.offered = needed;
2650 torture_assert_ntstatus_ok(tctx,
2651 dcerpc_spoolss_GetPrinter_r(b, tctx, &r),
2652 "dcerpc_spoolss_GetPrinter failed");
2653 torture_assert_werr_ok(tctx, r.out.result,
2654 "dcerpc_spoolss_GetPrinter failed");
2657 *res = talloc_steal(tctx, r.out.info);
2663 static bool torture_samba3_rpc_spoolss(struct torture_context *torture)
2665 struct dcerpc_pipe *p, *p2;
2666 struct dcerpc_binding_handle *b;
2667 struct policy_handle server_handle, printer_handle;
2668 const char **printers;
2670 struct spoolss_UserLevel1 userlevel1;
2673 torture_assert(torture,
2674 rap_get_servername(torture, &servername),
2675 "failed to rap servername");
2677 torture_assert_ntstatus_ok(torture,
2678 torture_rpc_connection(torture, &p2, &ndr_table_srvsvc),
2679 "failed to setup srvsvc");
2681 torture_assert(torture,
2682 find_printers(torture, p2, &printers, &num_printers),
2683 "failed to find printers via srvsvc");
2687 if (num_printers == 0) {
2688 torture_skip(torture, "Did not find printers\n");
2692 torture_assert_ntstatus_ok(torture,
2693 torture_rpc_connection(torture, &p, &ndr_table_spoolss),
2694 "failed to setup spoolss");
2696 b = p->binding_handle;
2698 ZERO_STRUCT(userlevel1);
2699 userlevel1.client = talloc_asprintf(
2700 torture, "\\\\%s", lpcfg_netbios_name(torture->lp_ctx));
2701 userlevel1.user = cli_credentials_get_username(cmdline_credentials);
2702 userlevel1.build = 2600;
2703 userlevel1.major = 3;
2704 userlevel1.minor = 0;
2705 userlevel1.processor = 0;
2708 struct spoolss_OpenPrinterEx r;
2711 r.in.printername = talloc_asprintf(torture, "\\\\%s",
2713 r.in.datatype = NULL;
2714 r.in.access_mask = 0;
2716 r.in.userlevel.level1 = &userlevel1;
2717 r.out.handle = &server_handle;
2719 torture_assert_ntstatus_ok(torture,
2720 dcerpc_spoolss_OpenPrinterEx_r(b, torture, &r),
2721 "dcerpc_spoolss_OpenPrinterEx failed");
2722 torture_assert_werr_ok(torture, r.out.result,
2723 "dcerpc_spoolss_OpenPrinterEx failed");
2727 struct spoolss_ClosePrinter r;
2729 r.in.handle = &server_handle;
2730 r.out.handle = &server_handle;
2732 torture_assert_ntstatus_ok(torture,
2733 dcerpc_spoolss_ClosePrinter_r(b, torture, &r),
2734 "dcerpc_spoolss_ClosePrinter failed");
2735 torture_assert_werr_ok(torture, r.out.result,
2736 "dcerpc_spoolss_ClosePrinter failed");
2740 struct spoolss_OpenPrinterEx r;
2743 r.in.printername = talloc_asprintf(
2744 torture, "\\\\%s\\%s", servername, printers[0]);
2745 r.in.datatype = NULL;
2746 r.in.access_mask = 0;
2748 r.in.userlevel.level1 = &userlevel1;
2749 r.out.handle = &printer_handle;
2751 torture_assert_ntstatus_ok(torture,
2752 dcerpc_spoolss_OpenPrinterEx_r(b, torture, &r),
2753 "dcerpc_spoolss_OpenPrinterEx failed");
2754 torture_assert_werr_ok(torture, r.out.result,
2755 "dcerpc_spoolss_OpenPrinterEx failed");
2761 for (i=0; i<8; i++) {
2762 torture_assert(torture,
2763 getprinterinfo(torture, b, &printer_handle, i, NULL),
2764 talloc_asprintf(torture, "getprinterinfo %d failed", i));
2769 struct spoolss_ClosePrinter r;
2771 r.in.handle = &printer_handle;
2772 r.out.handle = &printer_handle;
2774 torture_assert_ntstatus_ok(torture,
2775 dcerpc_spoolss_ClosePrinter_r(b, torture, &r),
2776 "dcerpc_spoolss_ClosePrinter failed");
2777 torture_assert_werr_ok(torture, r.out.result,
2778 "dcerpc_spoolss_ClosePrinter failed");
2784 torture_assert(torture,
2785 enumprinters(torture, b, servername, 1, &num_enumerated),
2786 "enumprinters failed");
2788 torture_assert_int_equal(torture, num_printers, num_enumerated,
2789 "netshareenum / enumprinters lvl 1 numprinter mismatch");
2795 torture_assert(torture,
2796 enumprinters(torture, b, servername, 2, &num_enumerated),
2797 "enumprinters failed");
2799 torture_assert_int_equal(torture, num_printers, num_enumerated,
2800 "netshareenum / enumprinters lvl 2 numprinter mismatch");
2806 static bool torture_samba3_rpc_wkssvc(struct torture_context *torture)
2808 struct dcerpc_pipe *p;
2809 struct dcerpc_binding_handle *b;
2812 torture_assert(torture,
2813 rap_get_servername(torture, &servername),
2814 "failed to rap servername");
2816 torture_assert_ntstatus_ok(torture,
2817 torture_rpc_connection(torture, &p, &ndr_table_wkssvc),
2818 "failed to setup wkssvc");
2820 b = p->binding_handle;
2823 struct wkssvc_NetWkstaInfo100 wks100;
2824 union wkssvc_NetWkstaInfo info;
2825 struct wkssvc_NetWkstaGetInfo r;
2827 r.in.server_name = "\\foo";
2829 info.info100 = &wks100;
2832 torture_assert_ntstatus_ok(torture,
2833 dcerpc_wkssvc_NetWkstaGetInfo_r(b, torture, &r),
2834 "dcerpc_wkssvc_NetWksGetInfo failed");
2835 torture_assert_werr_ok(torture, r.out.result,
2836 "dcerpc_wkssvc_NetWksGetInfo failed");
2838 torture_assert_str_equal(torture, servername, r.out.info->info100->server_name,
2839 "servername RAP / DCERPC inconsistency");
2845 static bool winreg_close(struct torture_context *tctx,
2846 struct dcerpc_binding_handle *b,
2847 struct policy_handle *handle)
2849 struct winreg_CloseKey c;
2851 c.in.handle = c.out.handle = handle;
2853 torture_assert_ntstatus_ok(tctx,
2854 dcerpc_winreg_CloseKey_r(b, tctx, &c),
2855 "winreg_CloseKey failed");
2856 torture_assert_werr_ok(tctx, c.out.result,
2857 "winreg_CloseKey failed");
2862 static bool enumvalues(struct torture_context *tctx,
2863 struct dcerpc_binding_handle *b,
2864 struct policy_handle *handle)
2866 uint32_t enum_index = 0;
2869 struct winreg_EnumValue r;
2870 struct winreg_ValNameBuf name;
2871 enum winreg_Type type = 0;
2874 uint32_t size, length;
2876 r.in.handle = handle;
2877 r.in.enum_index = enum_index;
2880 r.in.name = r.out.name = &name;
2886 r.in.length = &length;
2888 status = dcerpc_winreg_EnumValue_r(b, tctx, &r);
2889 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
2896 static bool enumkeys(struct torture_context *tctx,
2897 struct dcerpc_binding_handle *b,
2898 struct policy_handle *handle,
2901 struct winreg_EnumKey r;
2902 struct winreg_StringBuf kclass, name;
2913 r.in.handle = handle;
2914 r.in.enum_index = 0;
2916 r.in.keyclass = &kclass;
2918 r.in.last_changed_time = &t;
2921 struct winreg_OpenKey o;
2922 struct policy_handle key_handle;
2928 status = dcerpc_winreg_EnumKey_r(b, tctx, &r);
2929 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
2930 /* We're done enumerating */
2934 for (i=0; i<10-depth; i++) {
2935 torture_comment(tctx, " ");
2937 torture_comment(tctx, "%s\n", r.out.name->name);
2939 o.in.parent_handle = handle;
2940 o.in.keyname.name = r.out.name->name;
2942 o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2943 o.out.handle = &key_handle;
2945 status = dcerpc_winreg_OpenKey_r(b, tctx, &o);
2946 if (NT_STATUS_IS_OK(status) && W_ERROR_IS_OK(o.out.result)) {
2947 enumkeys(tctx, b, &key_handle, depth-1);
2948 enumvalues(tctx, b, &key_handle);
2949 torture_assert(tctx, winreg_close(tctx, b, &key_handle), "");
2952 r.in.enum_index += 1;
2958 typedef NTSTATUS (*winreg_open_fn)(struct dcerpc_binding_handle *, TALLOC_CTX *, void *);
2960 static bool test_Open3(struct torture_context *tctx,
2961 struct dcerpc_binding_handle *b,
2962 const char *name, winreg_open_fn open_fn)
2964 struct policy_handle handle;
2965 struct winreg_OpenHKLM r;
2967 r.in.system_name = 0;
2968 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2969 r.out.handle = &handle;
2971 torture_assert_ntstatus_ok(tctx,
2972 open_fn(b, tctx, &r),
2973 talloc_asprintf(tctx, "%s failed", name));
2974 torture_assert_werr_ok(tctx, r.out.result,
2975 talloc_asprintf(tctx, "%s failed", name));
2977 enumkeys(tctx, b, &handle, 4);
2979 torture_assert(tctx,
2980 winreg_close(tctx, b, &handle),
2981 "dcerpc_CloseKey failed");
2986 static bool torture_samba3_rpc_winreg(struct torture_context *torture)
2988 struct dcerpc_pipe *p;
2989 struct dcerpc_binding_handle *b;
2995 {"OpenHKLM", (winreg_open_fn)dcerpc_winreg_OpenHKLM_r },
2996 {"OpenHKU", (winreg_open_fn)dcerpc_winreg_OpenHKU_r },
2997 {"OpenHKPD", (winreg_open_fn)dcerpc_winreg_OpenHKPD_r },
2998 {"OpenHKPT", (winreg_open_fn)dcerpc_winreg_OpenHKPT_r },
2999 {"OpenHKCR", (winreg_open_fn)dcerpc_winreg_OpenHKCR_r }};
3004 torture_assert_ntstatus_ok(torture,
3005 torture_rpc_connection(torture, &p, &ndr_table_winreg),
3006 "failed to setup winreg");
3008 b = p->binding_handle;
3011 ret = test_Open3(torture, b, open_fns[0].name, open_fns[0].fn);
3013 for (i = 0; i < ARRAY_SIZE(open_fns); i++) {
3014 if (!test_Open3(torture, b, open_fns[i].name, open_fns[i].fn))
3021 static bool get_shareinfo(struct torture_context *tctx,
3022 struct dcerpc_binding_handle *b,
3023 const char *servername,
3025 struct srvsvc_NetShareInfo502 **info502)
3027 struct srvsvc_NetShareGetInfo r;
3028 union srvsvc_NetShareInfo info;
3030 r.in.server_unc = talloc_asprintf(tctx, "\\\\%s", servername);
3031 r.in.share_name = share;
3035 torture_assert_ntstatus_ok(tctx,
3036 dcerpc_srvsvc_NetShareGetInfo_r(b, tctx, &r),
3037 "srvsvc_NetShareGetInfo failed");
3038 torture_assert_werr_ok(tctx, r.out.result,
3039 "srvsvc_NetShareGetInfo failed");
3041 *info502 = talloc_move(tctx, &info.info502);
3047 * Get us a handle on HKLM\
3050 static bool get_hklm_handle(struct torture_context *tctx,
3051 struct dcerpc_binding_handle *b,
3052 struct policy_handle *handle)
3054 struct winreg_OpenHKLM r;
3055 struct policy_handle result;
3057 r.in.system_name = 0;
3058 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3059 r.out.handle = &result;
3061 torture_assert_ntstatus_ok(tctx,
3062 dcerpc_winreg_OpenHKLM_r(b, tctx, &r),
3064 torture_assert_werr_ok(tctx, r.out.result,
3072 static bool torture_samba3_createshare(struct torture_context *tctx,
3073 struct dcerpc_binding_handle *b,
3074 const char *sharename)
3076 struct policy_handle hklm;
3077 struct policy_handle new_handle;
3078 struct winreg_CreateKey c;
3079 struct winreg_CloseKey cl;
3080 enum winreg_CreateAction action_taken;
3082 c.in.handle = &hklm;
3083 c.in.name.name = talloc_asprintf(
3084 tctx, "software\\samba\\smbconf\\%s", sharename);
3085 torture_assert(tctx, c.in.name.name, "talloc_asprintf failed");
3087 c.in.keyclass.name = "";
3089 c.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3090 c.in.secdesc = NULL;
3091 c.in.action_taken = &action_taken;
3092 c.out.new_handle = &new_handle;
3093 c.out.action_taken = &action_taken;
3095 torture_assert_ntstatus_ok(tctx,
3096 dcerpc_winreg_CreateKey_r(b, tctx, &c),
3098 torture_assert_werr_ok(tctx, c.out.result,
3101 cl.in.handle = &new_handle;
3102 cl.out.handle = &new_handle;
3104 torture_assert_ntstatus_ok(tctx,
3105 dcerpc_winreg_CloseKey_r(b, tctx, &cl),
3107 torture_assert_werr_ok(tctx, cl.out.result,
3113 static bool torture_samba3_deleteshare(struct torture_context *tctx,
3114 struct dcerpc_binding_handle *b,
3115 const char *sharename)
3117 struct policy_handle hklm;
3118 struct winreg_DeleteKey d;
3120 torture_assert(tctx,
3121 get_hklm_handle(tctx, b, &hklm),
3122 "get_hklm_handle failed");
3124 d.in.handle = &hklm;
3125 d.in.key.name = talloc_asprintf(
3126 tctx, "software\\samba\\smbconf\\%s", sharename);
3127 torture_assert(tctx, d.in.key.name, "talloc_asprintf failed");
3129 torture_assert_ntstatus_ok(tctx,
3130 dcerpc_winreg_DeleteKey_r(b, tctx, &d),
3131 "DeleteKey failed");
3132 torture_assert_werr_ok(tctx, d.out.result,
3133 "DeleteKey failed");
3138 static bool torture_samba3_setconfig(struct torture_context *tctx,
3139 struct dcerpc_binding_handle *b,
3140 const char *sharename,
3141 const char *parameter,
3144 struct policy_handle hklm, key_handle;
3145 struct winreg_OpenKey o;
3146 struct winreg_SetValue s;
3150 torture_assert(tctx,
3151 get_hklm_handle(tctx, b, &hklm),
3152 "get_hklm_handle failed");
3154 o.in.parent_handle = &hklm;
3155 o.in.keyname.name = talloc_asprintf(
3156 tctx, "software\\samba\\smbconf\\%s", sharename);
3157 torture_assert(tctx, o.in.keyname.name, "talloc_asprintf failed");
3160 o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3161 o.out.handle = &key_handle;
3163 torture_assert_ntstatus_ok(tctx,
3164 dcerpc_winreg_OpenKey_r(b, tctx, &o),
3166 torture_assert_werr_ok(tctx, o.out.result,
3169 torture_assert(tctx,
3170 reg_string_to_val(tctx, "REG_SZ", value, &type, &val),
3171 "reg_string_to_val failed");
3173 s.in.handle = &key_handle;
3174 s.in.name.name = parameter;
3176 s.in.data = val.data;
3177 s.in.size = val.length;
3179 torture_assert_ntstatus_ok(tctx,
3180 dcerpc_winreg_SetValue_r(b, tctx, &s),
3182 torture_assert_werr_ok(tctx, s.out.result,
3188 static bool torture_samba3_regconfig(struct torture_context *torture)
3190 struct srvsvc_NetShareInfo502 *i = NULL;
3191 const char *comment = "Dummer Kommentar";
3192 struct dcerpc_pipe *srvsvc_pipe, *winreg_pipe;
3194 torture_assert_ntstatus_ok(torture,
3195 torture_rpc_connection(torture, &srvsvc_pipe, &ndr_table_srvsvc),
3196 "failed to setup srvsvc");
3198 torture_assert_ntstatus_ok(torture,
3199 torture_rpc_connection(torture, &winreg_pipe, &ndr_table_winreg),
3200 "failed to setup winreg");
3202 torture_assert(torture,
3203 torture_samba3_createshare(torture, winreg_pipe->binding_handle, "blubber"),
3204 "torture_samba3_createshare failed");
3206 torture_assert(torture,
3207 torture_samba3_setconfig(torture, winreg_pipe->binding_handle, "blubber", "comment", comment),
3208 "torture_samba3_setconfig failed");
3210 torture_assert(torture,
3211 get_shareinfo(torture, srvsvc_pipe->binding_handle, dcerpc_server_name(srvsvc_pipe), "blubber", &i),
3212 "get_shareinfo failed");
3214 torture_assert_str_equal(torture, comment, i->comment,
3215 "got unexpected comment");
3217 torture_assert(torture,
3218 torture_samba3_deleteshare(torture, winreg_pipe->binding_handle, "blubber"),
3219 "torture_samba3_deleteshare failed");
3225 * Test that even with a result of 0 rids the array is returned as a
3226 * non-NULL pointer. Yes, XP does notice.
3229 bool torture_samba3_getaliasmembership_0(struct torture_context *torture)
3231 struct dcerpc_pipe *p;
3232 struct dcerpc_binding_handle *b;
3233 struct samr_Connect2 c;
3234 struct samr_OpenDomain o;
3236 struct lsa_SidPtr ptr;
3237 struct lsa_SidArray sids;
3238 struct samr_GetAliasMembership g;
3239 struct samr_Ids rids;
3240 struct policy_handle samr, domain;
3242 torture_assert_ntstatus_ok(torture,
3243 torture_rpc_connection(torture, &p, &ndr_table_samr),
3244 "failed to setup samr");
3246 b = p->binding_handle;
3248 c.in.system_name = NULL;
3249 c.in.access_mask = SAMR_ACCESS_LOOKUP_DOMAIN;
3250 c.out.connect_handle = &samr;
3251 torture_assert_ntstatus_ok(torture,
3252 dcerpc_samr_Connect2_r(b, torture, &c),
3254 torture_assert_ntstatus_ok(torture, c.out.result,
3256 dom_sid_parse("S-1-5-32", &sid);
3257 o.in.connect_handle = &samr;
3258 o.in.access_mask = SAMR_DOMAIN_ACCESS_LOOKUP_ALIAS;
3260 o.out.domain_handle = &domain;
3261 torture_assert_ntstatus_ok(torture,
3262 dcerpc_samr_OpenDomain_r(b, torture, &o),
3264 torture_assert_ntstatus_ok(torture, o.out.result,
3266 dom_sid_parse("S-1-2-3-4-5", &sid);
3270 g.in.domain_handle = &domain;
3273 torture_assert_ntstatus_ok(torture,
3274 dcerpc_samr_GetAliasMembership_r(b, torture, &g),
3276 torture_assert_ntstatus_ok(torture, g.out.result,
3278 if (rids.ids == NULL) {
3279 /* This is the piece to test here */
3280 torture_fail(torture,
3281 "torture_samba3_getaliasmembership_0: "
3282 "Server returns NULL rids array\n");
3289 * Test smb reauthentication while rpc pipe is in use.
3291 static bool torture_rpc_smb_reauth1(struct torture_context *torture)
3293 TALLOC_CTX *mem_ctx;
3296 struct smbcli_state *cli;
3297 struct smbcli_options options;
3298 struct smbcli_session_options session_options;
3300 struct dcerpc_pipe *lsa_pipe;
3301 struct dcerpc_binding_handle *lsa_handle;
3302 struct lsa_GetUserName r;
3303 struct lsa_String *authority_name_p = NULL;
3304 char *authority_name_saved = NULL;
3305 struct lsa_String *account_name_p = NULL;
3306 char *account_name_saved = NULL;
3307 struct cli_credentials *anon_creds = NULL;
3308 struct smb_composite_sesssetup io;
3310 mem_ctx = talloc_init("torture_samba3_reauth");
3311 torture_assert(torture, (mem_ctx != NULL), "talloc_init failed");
3313 lpcfg_smbcli_options(torture->lp_ctx, &options);
3314 lpcfg_smbcli_session_options(torture->lp_ctx, &session_options);
3316 status = smbcli_full_connection(mem_ctx, &cli,
3317 torture_setting_string(torture, "host", NULL),
3318 lpcfg_smb_ports(torture->lp_ctx),
3320 lpcfg_socket_options(torture->lp_ctx),
3321 cmdline_credentials,
3322 lpcfg_resolve_context(torture->lp_ctx),
3323 torture->ev, &options, &session_options,
3324 lpcfg_gensec_settings(torture, torture->lp_ctx));
3325 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3326 "smbcli_full_connection failed");
3328 lsa_pipe = dcerpc_pipe_init(mem_ctx, torture->ev);
3329 torture_assert_goto(torture, (lsa_pipe != NULL), ret, done,
3330 "dcerpc_pipe_init failed");
3331 lsa_handle = lsa_pipe->binding_handle;
3333 status = dcerpc_pipe_open_smb(lsa_pipe, cli->tree, "\\lsarpc");
3334 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3335 "dcerpc_pipe_open failed");
3337 status = dcerpc_bind_auth_none(lsa_pipe, &ndr_table_lsarpc);
3338 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3339 "dcerpc_bind_auth_none failed");
3341 /* lsa getusername */
3344 r.in.system_name = "\\";
3345 r.in.account_name = &account_name_p;
3346 r.in.authority_name = &authority_name_p;
3347 r.out.account_name = &account_name_p;
3349 status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r);
3351 authority_name_p = *r.out.authority_name;
3353 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3354 "GetUserName failed");
3355 torture_assert_ntstatus_ok_goto(torture, r.out.result, ret, done,
3356 "GetUserName failed");
3358 torture_comment(torture, "lsa_GetUserName gave '%s\\%s'\n",
3359 authority_name_p->string,
3360 account_name_p->string);
3362 account_name_saved = talloc_strdup(mem_ctx, account_name_p->string);
3363 torture_assert_goto(torture, (account_name_saved != NULL), ret, done,
3365 authority_name_saved = talloc_strdup(mem_ctx, authority_name_p->string);
3366 torture_assert_goto(torture, (authority_name_saved != NULL), ret, done,
3369 /* smb re-authenticate as anonymous */
3371 anon_creds = cli_credentials_init_anon(mem_ctx);
3374 io.in.sesskey = cli->transport->negotiate.sesskey;
3375 io.in.capabilities = cli->transport->negotiate.capabilities;
3376 io.in.credentials = anon_creds;
3377 io.in.workgroup = lpcfg_workgroup(torture->lp_ctx);
3378 io.in.gensec_settings = lpcfg_gensec_settings(torture, torture->lp_ctx);
3380 status = smb_composite_sesssetup(cli->session, &io);
3381 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3382 "session reauth to anon failed");
3384 /* re-do lsa getusername after reauth */
3386 TALLOC_FREE(authority_name_p);
3387 TALLOC_FREE(account_name_p);
3389 r.in.system_name = "\\";
3390 r.in.account_name = &account_name_p;
3391 r.in.authority_name = &authority_name_p;
3392 r.out.account_name = &account_name_p;
3394 status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r);
3396 authority_name_p = *r.out.authority_name;
3398 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3399 "GetUserName failed");
3400 torture_assert_ntstatus_ok_goto(torture, r.out.result, ret, done,
3401 "GetUserName failed");
3403 torture_assert_goto(torture, (strcmp(authority_name_p->string, authority_name_saved) == 0),
3404 ret, done, "authority_name not equal after reauth to anon");
3405 torture_assert_goto(torture, (strcmp(account_name_p->string, account_name_saved) == 0),
3406 ret, done, "account_name not equal after reauth to anon");
3408 /* smb re-auth again to the original user */
3411 io.in.sesskey = cli->transport->negotiate.sesskey;
3412 io.in.capabilities = cli->transport->negotiate.capabilities;
3413 io.in.credentials = cmdline_credentials;
3414 io.in.workgroup = lpcfg_workgroup(torture->lp_ctx);
3415 io.in.gensec_settings = lpcfg_gensec_settings(torture, torture->lp_ctx);
3417 status = smb_composite_sesssetup(cli->session, &io);
3418 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3419 "session reauth to anon failed");
3421 /* re-do lsa getusername */
3423 TALLOC_FREE(authority_name_p);
3424 TALLOC_FREE(account_name_p);
3426 r.in.system_name = "\\";
3427 r.in.account_name = &account_name_p;
3428 r.in.authority_name = &authority_name_p;
3429 r.out.account_name = &account_name_p;
3431 status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r);
3433 authority_name_p = *r.out.authority_name;
3435 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3436 "GetUserName failed");
3437 torture_assert_ntstatus_ok_goto(torture, r.out.result, ret, done,
3438 "GetUserName failed");
3440 torture_assert_goto(torture, (strcmp(authority_name_p->string, authority_name_saved) == 0),
3441 ret, done, "authority_name not equal after reauth to anon");
3442 torture_assert_goto(torture, (strcmp(account_name_p->string, account_name_saved) == 0),
3443 ret, done, "account_name not equal after reauth to anon");
3448 talloc_free(mem_ctx);
3453 * Test smb reauthentication while rpc pipe is in use.
3454 * Open a second lsa bind after reauth to anon.
3455 * Do lsa getusername on that second bind.
3457 static bool torture_rpc_smb_reauth2(struct torture_context *torture)
3459 TALLOC_CTX *mem_ctx;
3462 struct smbcli_state *cli;
3463 struct smbcli_options options;
3464 struct smbcli_session_options session_options;
3466 struct dcerpc_pipe *lsa_pipe;
3467 struct dcerpc_binding_handle *lsa_handle;
3468 struct lsa_GetUserName r;
3469 struct lsa_String *authority_name_p = NULL;
3470 char *authority_name_saved = NULL;
3471 struct lsa_String *account_name_p = NULL;
3472 char *account_name_saved = NULL;
3473 struct cli_credentials *anon_creds = NULL;
3474 struct smb_composite_sesssetup io;
3476 mem_ctx = talloc_init("torture_samba3_reauth");
3477 torture_assert(torture, (mem_ctx != NULL), "talloc_init failed");
3479 lpcfg_smbcli_options(torture->lp_ctx, &options);
3480 lpcfg_smbcli_session_options(torture->lp_ctx, &session_options);
3482 status = smbcli_full_connection(mem_ctx, &cli,
3483 torture_setting_string(torture, "host", NULL),
3484 lpcfg_smb_ports(torture->lp_ctx),
3486 lpcfg_socket_options(torture->lp_ctx),
3487 cmdline_credentials,
3488 lpcfg_resolve_context(torture->lp_ctx),
3489 torture->ev, &options, &session_options,
3490 lpcfg_gensec_settings(torture, torture->lp_ctx));
3491 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3492 "smbcli_full_connection failed");
3494 /* smb re-authenticate as anonymous */
3496 anon_creds = cli_credentials_init_anon(mem_ctx);
3499 io.in.sesskey = cli->transport->negotiate.sesskey;
3500 io.in.capabilities = cli->transport->negotiate.capabilities;
3501 io.in.credentials = anon_creds;
3502 io.in.workgroup = lpcfg_workgroup(torture->lp_ctx);
3503 io.in.gensec_settings = lpcfg_gensec_settings(torture, torture->lp_ctx);
3505 status = smb_composite_sesssetup(cli->session, &io);
3506 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3507 "session reauth to anon failed");
3509 /* open the lsa pipe */
3511 lsa_pipe = dcerpc_pipe_init(mem_ctx, torture->ev);
3512 torture_assert_goto(torture, (lsa_pipe != NULL), ret, done,
3513 "dcerpc_pipe_init failed");
3514 lsa_handle = lsa_pipe->binding_handle;
3516 status = dcerpc_pipe_open_smb(lsa_pipe, cli->tree, "\\lsarpc");
3517 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3518 "dcerpc_pipe_open failed");
3520 status = dcerpc_bind_auth_none(lsa_pipe, &ndr_table_lsarpc);
3521 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3522 "dcerpc_bind_auth_none failed");
3524 /* lsa getusername */
3527 r.in.system_name = "\\";
3528 r.in.account_name = &account_name_p;
3529 r.in.authority_name = &authority_name_p;
3530 r.out.account_name = &account_name_p;
3532 status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r);
3534 authority_name_p = *r.out.authority_name;
3536 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3537 "GetUserName failed");
3538 torture_assert_ntstatus_ok_goto(torture, r.out.result, ret, done,
3539 "GetUserName failed");
3541 torture_comment(torture, "lsa_GetUserName gave '%s\\%s'\n",
3542 authority_name_p->string,
3543 account_name_p->string);
3545 account_name_saved = talloc_strdup(mem_ctx, account_name_p->string);
3546 torture_assert_goto(torture, (account_name_saved != NULL), ret, done,
3548 authority_name_saved = talloc_strdup(mem_ctx, authority_name_p->string);
3549 torture_assert_goto(torture, (authority_name_saved != NULL), ret, done,
3552 /* smb re-auth again to the original user */
3555 io.in.sesskey = cli->transport->negotiate.sesskey;
3556 io.in.capabilities = cli->transport->negotiate.capabilities;
3557 io.in.credentials = cmdline_credentials;
3558 io.in.workgroup = lpcfg_workgroup(torture->lp_ctx);
3559 io.in.gensec_settings = lpcfg_gensec_settings(torture, torture->lp_ctx);
3561 status = smb_composite_sesssetup(cli->session, &io);
3562 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3563 "session reauth to anon failed");
3565 /* re-do lsa getusername after reauth */
3567 TALLOC_FREE(authority_name_p);
3568 TALLOC_FREE(account_name_p);
3570 r.in.system_name = "\\";
3571 r.in.account_name = &account_name_p;
3572 r.in.authority_name = &authority_name_p;
3573 r.out.account_name = &account_name_p;
3575 status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r);
3577 authority_name_p = *r.out.authority_name;
3579 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3580 "GetUserName failed");
3581 torture_assert_ntstatus_ok_goto(torture, r.out.result, ret, done,
3582 "GetUserName failed");
3584 torture_assert_goto(torture, (strcmp(authority_name_p->string, authority_name_saved) == 0),
3585 ret, done, "authority_name not equal after reauth to anon");
3586 torture_assert_goto(torture, (strcmp(account_name_p->string, account_name_saved) == 0),
3587 ret, done, "account_name not equal after reauth to anon");
3592 talloc_free(mem_ctx);
3597 * Test smb2 reauthentication while rpc pipe is in use.
3599 static bool torture_rpc_smb2_reauth1(struct torture_context *torture)
3601 TALLOC_CTX *mem_ctx;
3604 struct smbcli_options options;
3606 struct dcerpc_pipe *lsa_pipe;
3607 struct dcerpc_binding_handle *lsa_handle;
3608 struct lsa_GetUserName r;
3609 struct lsa_String *authority_name_p = NULL;
3610 char *authority_name_saved = NULL;
3611 struct lsa_String *account_name_p = NULL;
3612 char *account_name_saved = NULL;
3613 struct cli_credentials *anon_creds = NULL;
3614 const char *host = torture_setting_string(torture, "host", NULL);
3615 struct smb2_tree *tree;
3617 mem_ctx = talloc_init("torture_samba3_reauth");
3618 torture_assert(torture, (mem_ctx != NULL), "talloc_init failed");
3620 lpcfg_smbcli_options(torture->lp_ctx, &options);
3622 status = smb2_connect(mem_ctx,
3624 lpcfg_smb_ports(torture->lp_ctx),
3626 lpcfg_resolve_context(torture->lp_ctx),
3627 cmdline_credentials,
3631 lpcfg_socket_options(torture->lp_ctx),
3632 lpcfg_gensec_settings(torture, torture->lp_ctx)
3634 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3635 "smb2_connect failed");
3637 lsa_pipe = dcerpc_pipe_init(mem_ctx, torture->ev);
3638 torture_assert_goto(torture, (lsa_pipe != NULL), ret, done,
3639 "dcerpc_pipe_init failed");
3640 lsa_handle = lsa_pipe->binding_handle;
3642 status = dcerpc_pipe_open_smb2(lsa_pipe, tree, "lsarpc");
3643 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3644 "dcerpc_pipe_open_smb2 failed");
3646 status = dcerpc_bind_auth_none(lsa_pipe, &ndr_table_lsarpc);
3647 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3648 "dcerpc_bind_auth_none failed");
3650 /* lsa getusername */
3653 r.in.system_name = "\\";
3654 r.in.account_name = &account_name_p;
3655 r.in.authority_name = &authority_name_p;
3656 r.out.account_name = &account_name_p;
3658 status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r);
3660 authority_name_p = *r.out.authority_name;
3662 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3663 "GetUserName failed");
3664 torture_assert_ntstatus_ok_goto(torture, r.out.result, ret, done,
3665 "GetUserName failed");
3667 torture_comment(torture, "lsa_GetUserName gave '%s\\%s'\n",
3668 authority_name_p->string,
3669 account_name_p->string);
3671 account_name_saved = talloc_strdup(mem_ctx, account_name_p->string);
3672 torture_assert_goto(torture, (account_name_saved != NULL), ret, done,
3674 authority_name_saved = talloc_strdup(mem_ctx, authority_name_p->string);
3675 torture_assert_goto(torture, (authority_name_saved != NULL), ret, done,
3678 /* smb re-authenticate as anonymous */
3680 anon_creds = cli_credentials_init_anon(mem_ctx);
3682 status = smb2_session_setup_spnego(tree->session,
3684 0 /* previous_session_id */);
3685 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3686 "session reauth to anon failed");
3688 /* re-do lsa getusername after reauth */
3690 TALLOC_FREE(authority_name_p);
3691 TALLOC_FREE(account_name_p);
3693 r.in.system_name = "\\";
3694 r.in.account_name = &account_name_p;
3695 r.in.authority_name = &authority_name_p;
3696 r.out.account_name = &account_name_p;
3698 status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r);
3700 authority_name_p = *r.out.authority_name;
3702 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3703 "GetUserName failed");
3704 torture_assert_ntstatus_ok_goto(torture, r.out.result, ret, done,
3705 "GetUserName failed");
3707 torture_assert_goto(torture, (strcmp(authority_name_p->string, authority_name_saved) == 0),
3708 ret, done, "authority_name not equal after reauth to anon");
3709 torture_assert_goto(torture, (strcmp(account_name_p->string, account_name_saved) == 0),
3710 ret, done, "account_name not equal after reauth to anon");
3712 /* smb re-auth again to the original user */
3714 status = smb2_session_setup_spnego(tree->session,
3715 cmdline_credentials,
3716 0 /* previous_session_id */);
3717 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3718 "session reauth to anon failed");
3720 /* re-do lsa getusername */
3722 TALLOC_FREE(authority_name_p);
3723 TALLOC_FREE(account_name_p);
3725 r.in.system_name = "\\";
3726 r.in.account_name = &account_name_p;
3727 r.in.authority_name = &authority_name_p;
3728 r.out.account_name = &account_name_p;
3730 status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r);
3732 authority_name_p = *r.out.authority_name;
3734 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3735 "GetUserName failed");
3736 torture_assert_ntstatus_ok_goto(torture, r.out.result, ret, done,
3737 "GetUserName failed");
3739 torture_assert_goto(torture, (strcmp(authority_name_p->string, authority_name_saved) == 0),
3740 ret, done, "authority_name not equal after reauth to anon");
3741 torture_assert_goto(torture, (strcmp(account_name_p->string, account_name_saved) == 0),
3742 ret, done, "account_name not equal after reauth to anon");
3747 talloc_free(mem_ctx);
3752 * Test smb2 reauthentication while rpc pipe is in use.
3753 * Open a second lsa bind after reauth to anon.
3754 * Do lsa getusername on that second bind.
3756 static bool torture_rpc_smb2_reauth2(struct torture_context *torture)
3758 TALLOC_CTX *mem_ctx;
3761 struct smbcli_options options;
3763 struct dcerpc_pipe *lsa_pipe;
3764 struct dcerpc_binding_handle *lsa_handle;
3765 struct lsa_GetUserName r;
3766 struct lsa_String *authority_name_p = NULL;
3767 char *authority_name_saved = NULL;
3768 struct lsa_String *account_name_p = NULL;
3769 char *account_name_saved = NULL;
3770 struct cli_credentials *anon_creds = NULL;
3771 const char *host = torture_setting_string(torture, "host", NULL);
3772 struct smb2_tree *tree;
3774 mem_ctx = talloc_init("torture_samba3_reauth");
3775 torture_assert(torture, (mem_ctx != NULL), "talloc_init failed");
3777 lpcfg_smbcli_options(torture->lp_ctx, &options);
3779 status = smb2_connect(mem_ctx,
3781 lpcfg_smb_ports(torture->lp_ctx),
3783 lpcfg_resolve_context(torture->lp_ctx),
3784 cmdline_credentials,
3788 lpcfg_socket_options(torture->lp_ctx),
3789 lpcfg_gensec_settings(torture, torture->lp_ctx)
3791 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3792 "smb2_connect failed");
3794 /* smb re-authenticate as anonymous */
3796 anon_creds = cli_credentials_init_anon(mem_ctx);
3798 status = smb2_session_setup_spnego(tree->session,
3800 0 /* previous_session_id */);
3801 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3802 "session reauth to anon failed");
3804 /* open the lsa pipe */
3806 lsa_pipe = dcerpc_pipe_init(mem_ctx, torture->ev);
3807 torture_assert_goto(torture, (lsa_pipe != NULL), ret, done,
3808 "dcerpc_pipe_init failed");
3809 lsa_handle = lsa_pipe->binding_handle;
3811 status = dcerpc_pipe_open_smb2(lsa_pipe, tree, "lsarpc");
3812 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3813 "dcerpc_pipe_open_smb2 failed");
3815 status = dcerpc_bind_auth_none(lsa_pipe, &ndr_table_lsarpc);
3816 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3817 "dcerpc_bind_auth_none failed");
3819 /* lsa getusername */
3822 r.in.system_name = "\\";
3823 r.in.account_name = &account_name_p;
3824 r.in.authority_name = &authority_name_p;
3825 r.out.account_name = &account_name_p;
3827 status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r);
3829 authority_name_p = *r.out.authority_name;
3831 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3832 "GetUserName failed");
3833 torture_assert_ntstatus_ok_goto(torture, r.out.result, ret, done,
3834 "GetUserName failed");
3836 torture_comment(torture, "lsa_GetUserName gave '%s\\%s'\n",
3837 authority_name_p->string,
3838 account_name_p->string);
3840 account_name_saved = talloc_strdup(mem_ctx, account_name_p->string);
3841 torture_assert_goto(torture, (account_name_saved != NULL), ret, done,
3843 authority_name_saved = talloc_strdup(mem_ctx, authority_name_p->string);
3844 torture_assert_goto(torture, (authority_name_saved != NULL), ret, done,
3847 /* smb re-auth again to the original user */
3849 status = smb2_session_setup_spnego(tree->session,
3850 cmdline_credentials,
3851 0 /* previous_session_id */);
3852 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3853 "session reauth to anon failed");
3855 /* re-do lsa getusername */
3857 TALLOC_FREE(authority_name_p);
3858 TALLOC_FREE(account_name_p);
3860 r.in.system_name = "\\";
3861 r.in.account_name = &account_name_p;
3862 r.in.authority_name = &authority_name_p;
3863 r.out.account_name = &account_name_p;
3865 status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r);
3867 authority_name_p = *r.out.authority_name;
3869 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3870 "GetUserName failed");
3871 torture_assert_ntstatus_ok_goto(torture, r.out.result, ret, done,
3872 "GetUserName failed");
3874 torture_assert_goto(torture, (strcmp(authority_name_p->string, authority_name_saved) == 0),
3875 ret, done, "authority_name not equal after reauth to anon");
3876 torture_assert_goto(torture, (strcmp(account_name_p->string, account_name_saved) == 0),
3877 ret, done, "account_name not equal after reauth to anon");
3882 talloc_free(mem_ctx);
3886 static bool torture_rpc_smb1_pipe_name(struct torture_context *torture)
3888 TALLOC_CTX *mem_ctx;
3891 struct smbcli_state *cli;
3892 struct smbcli_options options;
3893 struct smbcli_session_options session_options;
3898 mem_ctx = talloc_init("torture_samba3_smb1_pipe_name");
3899 torture_assert(torture, (mem_ctx != NULL), "talloc_init failed");
3901 lpcfg_smbcli_options(torture->lp_ctx, &options);
3902 lpcfg_smbcli_session_options(torture->lp_ctx, &session_options);
3904 status = smbcli_full_connection(mem_ctx, &cli,
3905 torture_setting_string(torture, "host", NULL),
3906 lpcfg_smb_ports(torture->lp_ctx),
3908 lpcfg_socket_options(torture->lp_ctx),
3909 cmdline_credentials,
3910 lpcfg_resolve_context(torture->lp_ctx),
3911 torture->ev, &options, &session_options,
3912 lpcfg_gensec_settings(torture, torture->lp_ctx));
3913 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3914 "smbcli_full_connection failed");
3917 io.generic.level = RAW_OPEN_NTCREATEX;
3918 io.ntcreatex.in.access_mask = DESIRED_ACCESS_PIPE;
3919 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ|
3920 NTCREATEX_SHARE_ACCESS_WRITE;
3921 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
3922 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_IMPERSONATION;
3923 io.ntcreatex.in.security_flags = 0;
3925 io.ntcreatex.in.fname = "__none__";
3926 status = smb_raw_open(cli->tree, torture, &io);
3927 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_NAME_NOT_FOUND,
3929 "smb_raw_open for '__none__'");
3931 io.ntcreatex.in.fname = "pipe\\srvsvc";
3932 status = smb_raw_open(cli->tree, torture, &io);
3933 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_NAME_NOT_FOUND,
3935 "smb_raw_open for 'pipe\\srvsvc'");
3937 io.ntcreatex.in.fname = "\\pipe\\srvsvc";
3938 status = smb_raw_open(cli->tree, torture, &io);
3939 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_NAME_NOT_FOUND,
3941 "smb_raw_open for '\\pipe\\srvsvc'");
3943 io.ntcreatex.in.fname = "srvsvc";
3944 status = smb_raw_open(cli->tree, torture, &io);
3945 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3946 "smb2_create failed for 'srvsvc'");
3947 fnum = io.ntcreatex.out.file.fnum;
3949 cl.generic.level = RAW_CLOSE_CLOSE;
3950 cl.close.in.file.fnum = fnum;
3951 status = smb_raw_close(cli->tree, &cl);
3952 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3953 "smb_raw_close failed");
3955 io.ntcreatex.in.fname = "\\srvsvc";
3956 status = smb_raw_open(cli->tree, torture, &io);
3957 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3958 "smb2_create failed for '\\srvsvc'");
3959 fnum = io.ntcreatex.out.file.fnum;
3961 cl.generic.level = RAW_CLOSE_CLOSE;
3962 cl.close.in.file.fnum = fnum;
3963 status = smb_raw_close(cli->tree, &cl);
3964 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3965 "smb_raw_close failed");
3967 io.ntcreatex.in.fname = "\\\\\\\\\\srvsvc";
3968 status = smb_raw_open(cli->tree, torture, &io);
3969 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3970 "smb2_create failed for '\\\\\\\\\\srvsvc'");
3971 fnum = io.ntcreatex.out.file.fnum;
3973 cl.generic.level = RAW_CLOSE_CLOSE;
3974 cl.close.in.file.fnum = fnum;
3975 status = smb_raw_close(cli->tree, &cl);
3976 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3977 "smb_raw_close failed");
3980 io.generic.level = RAW_OPEN_NTTRANS_CREATE;
3981 io.nttrans.in.access_mask = DESIRED_ACCESS_PIPE;
3982 io.nttrans.in.share_access = NTCREATEX_SHARE_ACCESS_READ|
3983 NTCREATEX_SHARE_ACCESS_WRITE;
3984 io.nttrans.in.open_disposition = NTCREATEX_DISP_OPEN;
3985 io.nttrans.in.impersonation = NTCREATEX_IMPERSONATION_IMPERSONATION;
3986 io.nttrans.in.security_flags = 0;
3988 io.nttrans.in.fname = "__none__";
3989 status = smb_raw_open(cli->tree, torture, &io);
3990 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_NAME_NOT_FOUND,
3992 "smb_raw_open for '__none__'");
3994 io.nttrans.in.fname = "pipe\\srvsvc";
3995 status = smb_raw_open(cli->tree, torture, &io);
3996 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_NAME_NOT_FOUND,
3998 "smb_raw_open for 'pipe\\srvsvc'");
4000 io.nttrans.in.fname = "\\pipe\\srvsvc";
4001 status = smb_raw_open(cli->tree, torture, &io);
4002 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_NAME_NOT_FOUND,
4004 "smb_raw_open for '\\pipe\\srvsvc'");
4006 io.nttrans.in.fname = "srvsvc";
4007 status = smb_raw_open(cli->tree, torture, &io);
4008 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4009 "smb2_create failed for 'srvsvc'");
4010 fnum = io.nttrans.out.file.fnum;
4012 cl.generic.level = RAW_CLOSE_CLOSE;
4013 cl.close.in.file.fnum = fnum;
4014 status = smb_raw_close(cli->tree, &cl);
4015 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4016 "smb_raw_close failed");
4018 io.nttrans.in.fname = "\\srvsvc";
4019 status = smb_raw_open(cli->tree, torture, &io);
4020 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4021 "smb2_create failed for '\\srvsvc'");
4022 fnum = io.nttrans.out.file.fnum;
4024 cl.generic.level = RAW_CLOSE_CLOSE;
4025 cl.close.in.file.fnum = fnum;
4026 status = smb_raw_close(cli->tree, &cl);
4027 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4028 "smb_raw_close failed");
4030 io.nttrans.in.fname = "\\\\\\\\\\srvsvc";
4031 status = smb_raw_open(cli->tree, torture, &io);
4032 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4033 "smb2_create failed for '\\\\\\\\\\srvsvc'");
4034 fnum = io.nttrans.out.file.fnum;
4036 cl.generic.level = RAW_CLOSE_CLOSE;
4037 cl.close.in.file.fnum = fnum;
4038 status = smb_raw_close(cli->tree, &cl);
4039 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4040 "smb_raw_close failed");
4043 io.generic.level = RAW_OPEN_OPENX;
4044 io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR;
4045 io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN;
4047 io.openx.in.fname = "__none__";
4048 status = smb_raw_open(cli->tree, torture, &io);
4049 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_PATH_SYNTAX_BAD,
4051 "smb_raw_open for '__none__'");
4053 io.openx.in.fname = "srvsvc";
4054 status = smb_raw_open(cli->tree, torture, &io);
4055 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_PATH_SYNTAX_BAD,
4057 "smb_raw_open for 'srvsvc'");
4059 io.openx.in.fname = "\\srvsvc";
4060 status = smb_raw_open(cli->tree, torture, &io);
4061 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_PATH_SYNTAX_BAD,
4063 "smb_raw_open for '\\srvsvc'");
4065 io.openx.in.fname = "\\pipesrvsvc";
4066 status = smb_raw_open(cli->tree, torture, &io);
4067 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_PATH_SYNTAX_BAD,
4069 "smb_raw_open for '\\pipesrvsvc'");
4071 io.openx.in.fname = "pipe\\__none__";
4072 status = smb_raw_open(cli->tree, torture, &io);
4073 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_NAME_NOT_FOUND,
4075 "smb_raw_open for 'pipe\\__none__'");
4077 io.openx.in.fname = "\\pipe\\__none__";
4078 status = smb_raw_open(cli->tree, torture, &io);
4079 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_NAME_NOT_FOUND,
4081 "smb_raw_open for '\\pipe\\__none__'");
4083 io.openx.in.fname = "pipe\\srvsvc";
4084 status = smb_raw_open(cli->tree, torture, &io);
4085 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4086 "smb2_create failed for 'pipe\\srvsvc'");
4087 fnum = io.openx.out.file.fnum;
4089 cl.generic.level = RAW_CLOSE_CLOSE;
4090 cl.close.in.file.fnum = fnum;
4091 status = smb_raw_close(cli->tree, &cl);
4092 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4093 "smb_raw_close failed");
4095 io.openx.in.fname = "\\pipe\\srvsvc";
4096 status = smb_raw_open(cli->tree, torture, &io);
4097 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4098 "smb2_create failed for '\\pipe\\srvsvc'");
4099 fnum = io.openx.out.file.fnum;
4101 cl.generic.level = RAW_CLOSE_CLOSE;
4102 cl.close.in.file.fnum = fnum;
4103 status = smb_raw_close(cli->tree, &cl);
4104 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4105 "smb_raw_close failed");
4107 io.openx.in.fname = "\\\\\\\\\\pipe\\srvsvc";
4108 status = smb_raw_open(cli->tree, torture, &io);
4109 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4110 "smb2_create failed for '\\\\\\\\\\pipe\\srvsvc'");
4111 fnum = io.openx.out.file.fnum;
4113 cl.generic.level = RAW_CLOSE_CLOSE;
4114 cl.close.in.file.fnum = fnum;
4115 status = smb_raw_close(cli->tree, &cl);
4116 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4117 "smb_raw_close failed");
4119 io.openx.in.fname = "\\\\\\\\\\pipe\\\\\\\\\\srvsvc";
4120 status = smb_raw_open(cli->tree, torture, &io);
4121 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4122 "smb2_create failed for '\\\\\\\\\\pipe\\\\\\\\\\srvsvc'");
4123 fnum = io.openx.out.file.fnum;
4125 cl.generic.level = RAW_CLOSE_CLOSE;
4126 cl.close.in.file.fnum = fnum;
4127 status = smb_raw_close(cli->tree, &cl);
4128 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4129 "smb_raw_close failed");
4133 talloc_free(mem_ctx);
4137 static bool torture_rpc_smb2_pipe_name(struct torture_context *torture)
4139 TALLOC_CTX *mem_ctx;
4142 struct smbcli_options options;
4143 const char *host = torture_setting_string(torture, "host", NULL);
4144 struct smb2_tree *tree;
4145 struct smb2_handle h;
4146 struct smb2_create io;
4148 mem_ctx = talloc_init("torture_samba3_smb2_pipe_name");
4149 torture_assert(torture, (mem_ctx != NULL), "talloc_init failed");
4151 lpcfg_smbcli_options(torture->lp_ctx, &options);
4153 status = smb2_connect(mem_ctx,
4155 lpcfg_smb_ports(torture->lp_ctx),
4157 lpcfg_resolve_context(torture->lp_ctx),
4158 cmdline_credentials,
4162 lpcfg_socket_options(torture->lp_ctx),
4163 lpcfg_gensec_settings(torture, torture->lp_ctx)
4165 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4166 "smb2_connect failed");
4169 io.in.oplock_level = 0;
4170 io.in.desired_access = DESIRED_ACCESS_PIPE;
4171 io.in.impersonation_level = SMB2_IMPERSONATION_IMPERSONATION;
4172 io.in.file_attributes = 0;
4173 io.in.create_disposition = NTCREATEX_DISP_OPEN;
4174 io.in.share_access =
4175 NTCREATEX_SHARE_ACCESS_READ|
4176 NTCREATEX_SHARE_ACCESS_WRITE;
4177 io.in.create_options = 0;
4179 io.in.fname = "__none__";
4180 status = smb2_create(tree, tree, &io);
4181 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_NAME_NOT_FOUND,
4183 "smb2_create for '__none__'");
4185 io.in.fname = "\\srvsvc";
4186 status = smb2_create(tree, tree, &io);
4187 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_NAME_NOT_FOUND,
4189 "smb2_create for '\\srvsvc'");
4191 io.in.fname = "\\pipe\\srvsvc";
4192 status = smb2_create(tree, tree, &io);
4193 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_NAME_NOT_FOUND,
4195 "smb2_create for '\\pipe\\srvsvc'");
4197 io.in.fname = "pipe\\srvsvc";
4198 status = smb2_create(tree, tree, &io);
4199 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_NAME_NOT_FOUND,
4201 "smb2_create for 'pipe\\srvsvc'");
4203 io.in.fname = "srvsvc";
4204 status = smb2_create(tree, tree, &io);
4205 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4206 "smb2_create failed for 'srvsvc'");
4208 h = io.out.file.handle;
4210 status = smb2_util_close(tree, h);
4211 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4212 "smb2_util_close failed");
4216 talloc_free(mem_ctx);
4221 * Test behaviour of a waiting read call on a pipe when
4222 * the pipe handle is closed:
4223 * - open a pipe via smb2
4224 * - trigger a read which hangs since there is nothing to read
4225 * - close the pipe file handle
4226 * - wait for the read to return and check the status
4227 * (STATUS_PIPE_BROKEN)
4229 static bool torture_rpc_smb2_pipe_read_close(struct torture_context *torture)
4231 TALLOC_CTX *mem_ctx;
4234 struct smbcli_options options;
4235 const char *host = torture_setting_string(torture, "host", NULL);
4236 struct smb2_tree *tree;
4237 struct smb2_handle h;
4238 struct smb2_request *smb2req;
4239 struct smb2_create io;
4240 struct smb2_read rd;
4242 mem_ctx = talloc_init("torture_samba3_pipe_read_close");
4243 torture_assert(torture, (mem_ctx != NULL), "talloc_init failed");
4245 lpcfg_smbcli_options(torture->lp_ctx, &options);
4247 status = smb2_connect(mem_ctx,
4249 lpcfg_smb_ports(torture->lp_ctx),
4251 lpcfg_resolve_context(torture->lp_ctx),
4252 cmdline_credentials,
4256 lpcfg_socket_options(torture->lp_ctx),
4257 lpcfg_gensec_settings(torture, torture->lp_ctx)
4259 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4260 "smb2_connect failed");
4263 io.in.oplock_level = 0;
4264 io.in.desired_access = DESIRED_ACCESS_PIPE;
4265 io.in.impersonation_level = SMB2_IMPERSONATION_IMPERSONATION;
4266 io.in.file_attributes = 0;
4267 io.in.create_disposition = NTCREATEX_DISP_OPEN;
4268 io.in.share_access =
4269 NTCREATEX_SHARE_ACCESS_READ|
4270 NTCREATEX_SHARE_ACCESS_WRITE;
4271 io.in.create_options = 0;
4272 io.in.fname = "lsarpc";
4274 status = smb2_create(tree, tree, &io);
4275 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4276 "smb2_create failed for 'lsarpc'");
4278 h = io.out.file.handle;
4281 rd.in.file.handle = h;
4282 rd.in.length = 1024;
4284 rd.in.min_count = 0;
4286 smb2req = smb2_read_send(tree, &rd);
4287 torture_assert_goto(torture, (smb2req != NULL), ret, done,
4288 "smb2_read_send failed");
4290 status = smb2_util_close(tree, h);
4291 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4292 "smb2_util_close failed");
4294 status = smb2_read_recv(smb2req, mem_ctx, &rd);
4295 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_PIPE_BROKEN, ret, done,
4296 "smb2_read_recv: unexpected return code");
4300 talloc_free(mem_ctx);
4305 * Test behaviour of a waiting read call on a pipe when
4306 * the tree is disconnected.
4307 * - open a pipe via smb2
4308 * - trigger a read which hangs since there is nothing to read
4309 * - do a tree disconnect
4310 * - wait for the read to return and check the status
4311 * (STATUS_PIPE_BROKEN)
4313 static bool torture_rpc_smb2_pipe_read_tdis(struct torture_context *torture)
4315 TALLOC_CTX *mem_ctx;
4318 struct smbcli_options options;
4319 const char *host = torture_setting_string(torture, "host", NULL);
4320 struct smb2_tree *tree;
4321 struct smb2_handle h;
4322 struct smb2_request *smb2req;
4323 struct smb2_create io;
4324 struct smb2_read rd;
4326 mem_ctx = talloc_init("torture_samba3_pipe_read_tdis");
4327 torture_assert(torture, (mem_ctx != NULL), "talloc_init failed");
4329 lpcfg_smbcli_options(torture->lp_ctx, &options);
4331 status = smb2_connect(mem_ctx,
4333 lpcfg_smb_ports(torture->lp_ctx),
4335 lpcfg_resolve_context(torture->lp_ctx),
4336 cmdline_credentials,
4340 lpcfg_socket_options(torture->lp_ctx),
4341 lpcfg_gensec_settings(torture, torture->lp_ctx)
4343 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4344 "smb2_connect failed");
4347 io.in.oplock_level = 0;
4348 io.in.desired_access = DESIRED_ACCESS_PIPE;
4349 io.in.impersonation_level = SMB2_IMPERSONATION_IMPERSONATION;
4350 io.in.file_attributes = 0;
4351 io.in.create_disposition = NTCREATEX_DISP_OPEN;
4352 io.in.share_access =
4353 NTCREATEX_SHARE_ACCESS_READ|
4354 NTCREATEX_SHARE_ACCESS_WRITE;
4355 io.in.create_options = 0;
4356 io.in.fname = "lsarpc";
4358 status = smb2_create(tree, tree, &io);
4359 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4360 "smb2_create failed for 'lsarpc'");
4362 h = io.out.file.handle;
4365 rd.in.file.handle = h;
4366 rd.in.length = 1024;
4368 rd.in.min_count = 0;
4370 smb2req = smb2_read_send(tree, &rd);
4371 torture_assert_goto(torture, (smb2req != NULL), ret, done,
4372 "smb2_read_send failed");
4374 status = smb2_tdis(tree);
4375 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4376 "smb2_tdis failed");
4378 status = smb2_read_recv(smb2req, mem_ctx, &rd);
4379 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_PIPE_BROKEN, ret, done,
4380 "smb2_read_recv: unexpected return code");
4384 talloc_free(mem_ctx);
4389 * Test behaviour of a waiting read call on a pipe when
4391 * - open a pipe via smb2
4392 * - trigger a read which hangs since there is nothing to read
4394 * - wait for the read to return and check the status
4395 * (STATUS_PIPE_BROKEN)
4397 static bool torture_rpc_smb2_pipe_read_logoff(struct torture_context *torture)
4399 TALLOC_CTX *mem_ctx;
4402 struct smbcli_options options;
4403 const char *host = torture_setting_string(torture, "host", NULL);
4404 struct smb2_tree *tree;
4405 struct smb2_handle h;
4406 struct smb2_request *smb2req;
4407 struct smb2_create io;
4408 struct smb2_read rd;
4410 mem_ctx = talloc_init("torture_samba3_pipe_read_tdis");
4411 torture_assert(torture, (mem_ctx != NULL), "talloc_init failed");
4413 lpcfg_smbcli_options(torture->lp_ctx, &options);
4415 status = smb2_connect(mem_ctx,
4417 lpcfg_smb_ports(torture->lp_ctx),
4419 lpcfg_resolve_context(torture->lp_ctx),
4420 cmdline_credentials,
4424 lpcfg_socket_options(torture->lp_ctx),
4425 lpcfg_gensec_settings(torture, torture->lp_ctx)
4427 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4428 "smb2_connect failed");
4431 io.in.oplock_level = 0;
4432 io.in.desired_access = DESIRED_ACCESS_PIPE;
4433 io.in.impersonation_level = SMB2_IMPERSONATION_IMPERSONATION;
4434 io.in.file_attributes = 0;
4435 io.in.create_disposition = NTCREATEX_DISP_OPEN;
4436 io.in.share_access =
4437 NTCREATEX_SHARE_ACCESS_READ|
4438 NTCREATEX_SHARE_ACCESS_WRITE;
4439 io.in.create_options = 0;
4440 io.in.fname = "lsarpc";
4442 status = smb2_create(tree, tree, &io);
4443 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4444 "smb2_create failed for 'lsarpc'");
4446 h = io.out.file.handle;
4449 rd.in.file.handle = h;
4450 rd.in.length = 1024;
4452 rd.in.min_count = 0;
4454 smb2req = smb2_read_send(tree, &rd);
4455 torture_assert_goto(torture, (smb2req != NULL), ret, done,
4456 "smb2_read_send failed");
4458 status = smb2_logoff(tree->session);
4459 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4460 "smb2_logoff failed");
4462 status = smb2_read_recv(smb2req, mem_ctx, &rd);
4463 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_PIPE_BROKEN, ret, done,
4464 "smb2_read_recv: unexpected return code");
4468 talloc_free(mem_ctx);
4473 struct torture_suite *torture_rpc_samba3(TALLOC_CTX *mem_ctx)
4475 struct torture_suite *suite = torture_suite_create(mem_ctx, "samba3");
4477 torture_suite_add_simple_test(suite, "bind", torture_bind_samba3);
4478 torture_suite_add_simple_test(suite, "netlogon", torture_netlogon_samba3);
4479 torture_suite_add_simple_test(suite, "sessionkey", torture_samba3_sessionkey);
4480 torture_suite_add_simple_test(suite, "srvsvc", torture_samba3_rpc_srvsvc);
4481 torture_suite_add_simple_test(suite, "sharesec", torture_samba3_rpc_sharesec);
4482 torture_suite_add_simple_test(suite, "getusername", torture_samba3_rpc_getusername);
4483 torture_suite_add_simple_test(suite, "randomauth2", torture_samba3_rpc_randomauth2);
4484 torture_suite_add_simple_test(suite, "lsa", torture_samba3_rpc_lsa);
4485 torture_suite_add_simple_test(suite, "spoolss", torture_samba3_rpc_spoolss);
4486 torture_suite_add_simple_test(suite, "wkssvc", torture_samba3_rpc_wkssvc);
4487 torture_suite_add_simple_test(suite, "winreg", torture_samba3_rpc_winreg);
4488 torture_suite_add_simple_test(suite, "getaliasmembership-0", torture_samba3_getaliasmembership_0);
4489 torture_suite_add_simple_test(suite, "regconfig", torture_samba3_regconfig);
4490 torture_suite_add_simple_test(suite, "smb-reauth1", torture_rpc_smb_reauth1);
4491 torture_suite_add_simple_test(suite, "smb-reauth2", torture_rpc_smb_reauth2);
4492 torture_suite_add_simple_test(suite, "smb2-reauth1", torture_rpc_smb2_reauth1);
4493 torture_suite_add_simple_test(suite, "smb2-reauth2", torture_rpc_smb2_reauth2);
4494 torture_suite_add_simple_test(suite, "smb1-pipe-name", torture_rpc_smb1_pipe_name);
4495 torture_suite_add_simple_test(suite, "smb2-pipe-name", torture_rpc_smb2_pipe_name);
4496 torture_suite_add_simple_test(suite, "smb2-pipe-read-close", torture_rpc_smb2_pipe_read_close);
4497 torture_suite_add_simple_test(suite, "smb2-pipe-read-tdis", torture_rpc_smb2_pipe_read_tdis);
4498 torture_suite_add_simple_test(suite, "smb2-pipe-read-logoff", torture_rpc_smb2_pipe_read_logoff);
4500 suite->description = talloc_strdup(suite, "samba3 DCERPC interface tests");