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 "libcli/smb/smbXcli_base.h"
52 * open pipe and bind, given an IPC$ context
55 static NTSTATUS pipe_bind_smb(struct torture_context *tctx,
57 struct smbcli_tree *tree,
58 const char *pipe_name,
59 const struct ndr_interface_table *iface,
60 struct dcerpc_pipe **p)
62 struct dcerpc_pipe *result;
65 if (!(result = dcerpc_pipe_init(mem_ctx, tctx->ev))) {
66 return NT_STATUS_NO_MEMORY;
69 status = dcerpc_pipe_open_smb(result, tree, pipe_name);
70 if (!NT_STATUS_IS_OK(status)) {
71 torture_comment(tctx, "dcerpc_pipe_open_smb failed: %s\n",
77 status = dcerpc_bind_auth_none(result, iface);
78 if (!NT_STATUS_IS_OK(status)) {
79 torture_comment(tctx, "dcerpc_bind_auth_none failed: %s\n", nt_errstr(status));
88 static NTSTATUS pipe_bind_smb2(struct torture_context *tctx,
90 struct smb2_tree *tree,
91 const char *pipe_name,
92 const struct ndr_interface_table *iface,
93 struct dcerpc_pipe **p)
95 struct dcerpc_pipe *result;
98 if (!(result = dcerpc_pipe_init(mem_ctx, tctx->ev))) {
99 return NT_STATUS_NO_MEMORY;
102 status = dcerpc_pipe_open_smb2(result, tree, pipe_name);
103 if (!NT_STATUS_IS_OK(status)) {
104 torture_comment(tctx, "dcerpc_pipe_open_smb2 failed: %s\n",
110 status = dcerpc_bind_auth_none(result, iface);
111 if (!NT_STATUS_IS_OK(status)) {
112 torture_comment(tctx, "dcerpc_bind_auth_none failed: %s\n", nt_errstr(status));
121 static NTSTATUS pipe_bind_smb_auth(struct torture_context *tctx,
123 struct smbcli_tree *tree,
124 struct cli_credentials *creds,
127 const char *pipe_name,
128 const struct ndr_interface_table *iface,
129 struct dcerpc_pipe **p)
131 struct dcerpc_pipe *result;
134 if (!(result = dcerpc_pipe_init(mem_ctx, tctx->ev))) {
135 return NT_STATUS_NO_MEMORY;
138 status = dcerpc_pipe_open_smb(result, tree, pipe_name);
139 if (!NT_STATUS_IS_OK(status)) {
140 torture_comment(tctx, "dcerpc_pipe_open_smb failed: %s\n",
146 status = dcerpc_bind_auth(result, iface, creds,
147 lpcfg_gensec_settings(tctx->lp_ctx, tctx->lp_ctx),
148 auth_type, auth_level, NULL);
149 if (!NT_STATUS_IS_OK(status)) {
150 torture_comment(tctx, "dcerpc_bind_auth failed: %s\n", nt_errstr(status));
160 * This tests a RPC call using an invalid vuid
163 bool torture_bind_authcontext(struct torture_context *torture)
168 struct lsa_ObjectAttribute objectattr;
169 struct lsa_OpenPolicy2 openpolicy;
170 struct policy_handle handle;
171 struct lsa_Close close_handle;
172 struct smbcli_session *tmp;
174 struct smbcli_session *session2;
175 struct smbcli_state *cli;
176 struct dcerpc_pipe *lsa_pipe;
177 struct dcerpc_binding_handle *lsa_handle;
178 struct cli_credentials *anon_creds;
179 struct smb_composite_sesssetup setup;
180 struct smbcli_options options;
181 struct smbcli_session_options session_options;
183 mem_ctx = talloc_init("torture_bind_authcontext");
185 if (mem_ctx == NULL) {
186 torture_comment(torture, "talloc_init failed\n");
190 lpcfg_smbcli_options(torture->lp_ctx, &options);
191 lpcfg_smbcli_session_options(torture->lp_ctx, &session_options);
193 status = smbcli_full_connection(mem_ctx, &cli,
194 torture_setting_string(torture, "host", NULL),
195 lpcfg_smb_ports(torture->lp_ctx),
197 lpcfg_socket_options(torture->lp_ctx),
199 lpcfg_resolve_context(torture->lp_ctx),
200 torture->ev, &options, &session_options,
201 lpcfg_gensec_settings(torture, torture->lp_ctx));
202 if (!NT_STATUS_IS_OK(status)) {
203 torture_comment(torture, "smbcli_full_connection failed: %s\n",
208 status = pipe_bind_smb(torture, mem_ctx, cli->tree, "\\lsarpc",
209 &ndr_table_lsarpc, &lsa_pipe);
210 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
211 "pipe_bind_smb failed");
212 lsa_handle = lsa_pipe->binding_handle;
214 openpolicy.in.system_name =talloc_asprintf(
215 mem_ctx, "\\\\%s", dcerpc_server_name(lsa_pipe));
216 ZERO_STRUCT(objectattr);
217 openpolicy.in.attr = &objectattr;
218 openpolicy.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
219 openpolicy.out.handle = &handle;
221 status = dcerpc_lsa_OpenPolicy2_r(lsa_handle, mem_ctx, &openpolicy);
223 if (!NT_STATUS_IS_OK(status)) {
224 torture_comment(torture, "dcerpc_lsa_OpenPolicy2 failed: %s\n",
228 if (!NT_STATUS_IS_OK(openpolicy.out.result)) {
229 torture_comment(torture, "dcerpc_lsa_OpenPolicy2 failed: %s\n",
230 nt_errstr(openpolicy.out.result));
234 close_handle.in.handle = &handle;
235 close_handle.out.handle = &handle;
237 status = dcerpc_lsa_Close_r(lsa_handle, mem_ctx, &close_handle);
238 if (!NT_STATUS_IS_OK(status)) {
239 torture_comment(torture, "dcerpc_lsa_Close failed: %s\n",
243 if (!NT_STATUS_IS_OK(close_handle.out.result)) {
244 torture_comment(torture, "dcerpc_lsa_Close failed: %s\n",
245 nt_errstr(close_handle.out.result));
249 session2 = smbcli_session_init(cli->transport, mem_ctx, false, session_options);
250 if (session2 == NULL) {
251 torture_comment(torture, "smbcli_session_init failed\n");
255 if (!(anon_creds = cli_credentials_init_anon(mem_ctx))) {
256 torture_comment(torture, "create_anon_creds failed\n");
260 setup.in.sesskey = cli->transport->negotiate.sesskey;
261 setup.in.capabilities = cli->transport->negotiate.capabilities;
262 setup.in.workgroup = "";
263 setup.in.credentials = anon_creds;
264 setup.in.gensec_settings = lpcfg_gensec_settings(torture, torture->lp_ctx);
266 status = smb_composite_sesssetup(session2, &setup);
267 if (!NT_STATUS_IS_OK(status)) {
268 torture_comment(torture, "anon session setup failed: %s\n",
272 session2->vuid = setup.out.vuid;
274 tmp = cli->tree->session;
275 tmp_vuid = smb1cli_session_current_id(tmp->smbXcli);
276 smb1cli_session_set_id(tmp->smbXcli, session2->vuid);
277 cli->tree->session = session2;
279 status = dcerpc_lsa_OpenPolicy2_r(lsa_handle, mem_ctx, &openpolicy);
281 torture_assert(torture, smbXcli_conn_is_connected(cli->transport->conn),
282 "smb still connected");
283 torture_assert(torture, !dcerpc_binding_handle_is_connected(lsa_handle),
284 "dcerpc disonnected");
286 if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
287 torture_comment(torture, "dcerpc_lsa_OpenPolicy2 with wrong vuid gave %s, "
288 "expected NT_STATUS_CONNECTION_DISCONNECTED\n",
290 status = NT_STATUS_CONNECTION_DISCONNECTED;
292 if (NT_STATUS_EQUAL(status, NT_STATUS_IO_DEVICE_ERROR)) {
293 torture_comment(torture, "dcerpc_lsa_OpenPolicy2 with wrong vuid gave %s, "
294 "expected NT_STATUS_CONNECTION_DISCONNECTED\n",
296 status = NT_STATUS_CONNECTION_DISCONNECTED;
299 torture_assert_ntstatus_equal(torture, status, NT_STATUS_CONNECTION_DISCONNECTED,
300 "lsa connection disconnected");
302 smb1cli_session_set_id(tmp->smbXcli, tmp_vuid);
303 cli->tree->session = tmp;
304 talloc_free(lsa_pipe);
309 talloc_free(mem_ctx);
314 * Bind to lsa using a specific auth method
317 static bool bindtest(struct torture_context *tctx,
318 struct smbcli_state *cli,
319 struct cli_credentials *credentials,
320 uint8_t auth_type, uint8_t auth_level)
326 struct dcerpc_pipe *lsa_pipe;
327 struct dcerpc_binding_handle *lsa_handle;
328 struct lsa_ObjectAttribute objectattr;
329 struct lsa_OpenPolicy2 openpolicy;
330 struct lsa_QueryInfoPolicy query;
331 union lsa_PolicyInformation *info = NULL;
332 struct policy_handle handle;
333 struct lsa_Close close_handle;
335 if ((mem_ctx = talloc_init("bindtest")) == NULL) {
336 torture_comment(tctx, "talloc_init failed\n");
340 status = pipe_bind_smb_auth(tctx, mem_ctx, cli->tree,
341 credentials, auth_type, auth_level,
342 "\\lsarpc", &ndr_table_lsarpc, &lsa_pipe);
343 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
344 "pipe_bind_smb_auth failed");
345 lsa_handle = lsa_pipe->binding_handle;
347 openpolicy.in.system_name =talloc_asprintf(
348 mem_ctx, "\\\\%s", dcerpc_server_name(lsa_pipe));
349 ZERO_STRUCT(objectattr);
350 openpolicy.in.attr = &objectattr;
351 openpolicy.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
352 openpolicy.out.handle = &handle;
354 status = dcerpc_lsa_OpenPolicy2_r(lsa_handle, mem_ctx, &openpolicy);
356 if (!NT_STATUS_IS_OK(status)) {
357 torture_comment(tctx, "dcerpc_lsa_OpenPolicy2 failed: %s\n",
361 if (!NT_STATUS_IS_OK(openpolicy.out.result)) {
362 torture_comment(tctx, "dcerpc_lsa_OpenPolicy2 failed: %s\n",
363 nt_errstr(openpolicy.out.result));
367 query.in.handle = &handle;
368 query.in.level = LSA_POLICY_INFO_DOMAIN;
369 query.out.info = &info;
371 status = dcerpc_lsa_QueryInfoPolicy_r(lsa_handle, mem_ctx, &query);
372 if (!NT_STATUS_IS_OK(status)) {
373 torture_comment(tctx, "dcerpc_lsa_QueryInfoPolicy failed: %s\n",
377 if (!NT_STATUS_IS_OK(query.out.result)) {
378 torture_comment(tctx, "dcerpc_lsa_QueryInfoPolicy failed: %s\n",
379 nt_errstr(query.out.result));
383 close_handle.in.handle = &handle;
384 close_handle.out.handle = &handle;
386 status = dcerpc_lsa_Close_r(lsa_handle, mem_ctx, &close_handle);
387 if (!NT_STATUS_IS_OK(status)) {
388 torture_comment(tctx, "dcerpc_lsa_Close failed: %s\n",
392 if (!NT_STATUS_IS_OK(close_handle.out.result)) {
393 torture_comment(tctx, "dcerpc_lsa_Close failed: %s\n",
394 nt_errstr(close_handle.out.result));
401 talloc_free(mem_ctx);
406 * test authenticated RPC binds with the variants Samba3 does support
409 static bool torture_bind_samba3(struct torture_context *torture)
414 struct smbcli_state *cli;
415 struct smbcli_options options;
416 struct smbcli_session_options session_options;
418 mem_ctx = talloc_init("torture_bind_authcontext");
420 if (mem_ctx == NULL) {
421 torture_comment(torture, "talloc_init failed\n");
425 lpcfg_smbcli_options(torture->lp_ctx, &options);
426 lpcfg_smbcli_session_options(torture->lp_ctx, &session_options);
428 status = smbcli_full_connection(mem_ctx, &cli,
429 torture_setting_string(torture, "host", NULL),
430 lpcfg_smb_ports(torture->lp_ctx),
432 lpcfg_socket_options(torture->lp_ctx),
434 lpcfg_resolve_context(torture->lp_ctx),
435 torture->ev, &options, &session_options,
436 lpcfg_gensec_settings(torture, torture->lp_ctx));
437 if (!NT_STATUS_IS_OK(status)) {
438 torture_comment(torture, "smbcli_full_connection failed: %s\n",
445 ret &= bindtest(torture, cli, cmdline_credentials, DCERPC_AUTH_TYPE_NTLMSSP,
446 DCERPC_AUTH_LEVEL_INTEGRITY);
447 ret &= bindtest(torture, cli, cmdline_credentials, DCERPC_AUTH_TYPE_NTLMSSP,
448 DCERPC_AUTH_LEVEL_PRIVACY);
449 ret &= bindtest(torture, cli, cmdline_credentials, DCERPC_AUTH_TYPE_SPNEGO,
450 DCERPC_AUTH_LEVEL_INTEGRITY);
451 ret &= bindtest(torture, cli, cmdline_credentials, DCERPC_AUTH_TYPE_SPNEGO,
452 DCERPC_AUTH_LEVEL_PRIVACY);
455 talloc_free(mem_ctx);
460 * Lookup or create a user and return all necessary info
463 static bool get_usr_handle(struct torture_context *tctx,
464 struct smbcli_state *cli,
466 struct cli_credentials *admin_creds,
469 const char *username,
471 struct dcerpc_pipe **result_pipe,
472 struct policy_handle **result_handle,
473 struct dom_sid **sid_p)
475 struct dcerpc_pipe *samr_pipe;
476 struct dcerpc_binding_handle *samr_handle;
478 struct policy_handle conn_handle;
479 struct policy_handle domain_handle;
480 struct policy_handle *user_handle;
481 struct samr_Connect2 conn;
482 struct samr_EnumDomains enumdom;
483 uint32_t resume_handle = 0;
484 uint32_t num_entries = 0;
485 struct samr_SamArray *sam = NULL;
486 struct samr_LookupDomain l;
487 struct dom_sid2 *sid = NULL;
489 struct lsa_String domain_name;
490 struct lsa_String user_name;
491 struct samr_OpenDomain o;
492 struct samr_CreateUser2 c;
493 uint32_t user_rid,access_granted;
495 if (admin_creds != NULL) {
496 status = pipe_bind_smb_auth(tctx, mem_ctx, cli->tree,
497 admin_creds, auth_type, auth_level,
498 "\\samr", &ndr_table_samr, &samr_pipe);
499 torture_assert_ntstatus_ok(tctx, status, "pipe_bind_smb_auth failed");
501 /* We must have an authenticated SMB connection */
502 status = pipe_bind_smb(tctx, mem_ctx, cli->tree,
503 "\\samr", &ndr_table_samr, &samr_pipe);
504 torture_assert_ntstatus_ok(tctx, status, "pipe_bind_smb_auth failed");
507 samr_pipe->conn->flags |= DCERPC_DEBUG_PRINT_IN | DCERPC_DEBUG_PRINT_OUT;
509 samr_handle = samr_pipe->binding_handle;
511 conn.in.system_name = talloc_asprintf(
512 mem_ctx, "\\\\%s", dcerpc_server_name(samr_pipe));
513 conn.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
514 conn.out.connect_handle = &conn_handle;
516 torture_assert_ntstatus_ok(tctx,
517 dcerpc_samr_Connect2_r(samr_handle, mem_ctx, &conn),
518 "samr_Connect2 failed");
519 torture_assert_ntstatus_ok(tctx, conn.out.result,
520 "samr_Connect2 failed");
522 enumdom.in.connect_handle = &conn_handle;
523 enumdom.in.resume_handle = &resume_handle;
524 enumdom.in.buf_size = (uint32_t)-1;
525 enumdom.out.resume_handle = &resume_handle;
526 enumdom.out.num_entries = &num_entries;
527 enumdom.out.sam = &sam;
529 torture_assert_ntstatus_ok(tctx,
530 dcerpc_samr_EnumDomains_r(samr_handle, mem_ctx, &enumdom),
531 "samr_EnumDomains failed");
532 torture_assert_ntstatus_ok(tctx, enumdom.out.result,
533 "samr_EnumDomains failed");
535 torture_assert_int_equal(tctx, *enumdom.out.num_entries, 2,
536 "samr_EnumDomains returned unexpected num_entries");
538 dom_idx = strequal(sam->entries[0].name.string,
541 l.in.connect_handle = &conn_handle;
542 domain_name.string = sam->entries[dom_idx].name.string;
543 *domain = talloc_strdup(mem_ctx, domain_name.string);
544 l.in.domain_name = &domain_name;
547 torture_assert_ntstatus_ok(tctx,
548 dcerpc_samr_LookupDomain_r(samr_handle, mem_ctx, &l),
549 "samr_LookupDomain failed");
550 torture_assert_ntstatus_ok(tctx, l.out.result,
551 "samr_LookupDomain failed");
553 o.in.connect_handle = &conn_handle;
554 o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
555 o.in.sid = *l.out.sid;
556 o.out.domain_handle = &domain_handle;
558 torture_assert_ntstatus_ok(tctx,
559 dcerpc_samr_OpenDomain_r(samr_handle, mem_ctx, &o),
560 "samr_OpenDomain failed");
561 torture_assert_ntstatus_ok(tctx, o.out.result,
562 "samr_OpenDomain failed");
564 c.in.domain_handle = &domain_handle;
565 user_name.string = username;
566 c.in.account_name = &user_name;
567 c.in.acct_flags = ACB_NORMAL;
568 c.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
569 user_handle = talloc(mem_ctx, struct policy_handle);
570 c.out.user_handle = user_handle;
571 c.out.access_granted = &access_granted;
572 c.out.rid = &user_rid;
574 torture_assert_ntstatus_ok(tctx,
575 dcerpc_samr_CreateUser2_r(samr_handle, mem_ctx, &c),
576 "samr_CreateUser2 failed");
578 if (NT_STATUS_EQUAL(c.out.result, NT_STATUS_USER_EXISTS)) {
579 struct samr_LookupNames ln;
580 struct samr_OpenUser ou;
581 struct samr_Ids rids, types;
583 ln.in.domain_handle = &domain_handle;
585 ln.in.names = &user_name;
587 ln.out.types = &types;
589 torture_assert_ntstatus_ok(tctx,
590 dcerpc_samr_LookupNames_r(samr_handle, mem_ctx, &ln),
591 "samr_LookupNames failed");
592 torture_assert_ntstatus_ok(tctx, ln.out.result,
593 "samr_LookupNames failed");
595 ou.in.domain_handle = &domain_handle;
596 ou.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
597 user_rid = ou.in.rid = ln.out.rids->ids[0];
598 ou.out.user_handle = user_handle;
600 torture_assert_ntstatus_ok(tctx,
601 dcerpc_samr_OpenUser_r(samr_handle, mem_ctx, &ou),
602 "samr_OpenUser failed");
603 status = ou.out.result;
605 status = c.out.result;
608 torture_assert_ntstatus_ok(tctx, status,
609 "samr_CreateUser failed");
611 *result_pipe = samr_pipe;
612 *result_handle = user_handle;
614 *sid_p = dom_sid_add_rid(mem_ctx, *l.out.sid, user_rid);
624 static bool create_user(struct torture_context *tctx,
625 TALLOC_CTX *mem_ctx, struct smbcli_state *cli,
626 struct cli_credentials *admin_creds,
627 const char *username, const char *password,
629 struct dom_sid **user_sid)
633 struct dcerpc_pipe *samr_pipe;
634 struct dcerpc_binding_handle *samr_handle;
635 struct policy_handle *wks_handle;
638 if (!(tmp_ctx = talloc_new(mem_ctx))) {
639 torture_comment(tctx, "talloc_init failed\n");
643 ret = get_usr_handle(tctx, cli, tmp_ctx, admin_creds,
644 DCERPC_AUTH_TYPE_NTLMSSP,
645 DCERPC_AUTH_LEVEL_INTEGRITY,
646 username, domain_name, &samr_pipe, &wks_handle,
649 torture_comment(tctx, "get_usr_handle failed\n");
652 samr_handle = samr_pipe->binding_handle;
655 struct samr_SetUserInfo2 sui2;
656 struct samr_SetUserInfo sui;
657 struct samr_QueryUserInfo qui;
658 union samr_UserInfo u_info;
659 union samr_UserInfo *info;
660 DATA_BLOB session_key;
664 encode_pw_buffer(u_info.info23.password.data, password,
667 status = dcerpc_fetch_session_key(samr_pipe, &session_key);
668 if (!NT_STATUS_IS_OK(status)) {
669 torture_comment(tctx, "dcerpc_fetch_session_key failed\n");
672 arcfour_crypt_blob(u_info.info23.password.data, 516,
674 u_info.info23.info.password_expired = 0;
675 u_info.info23.info.fields_present = SAMR_FIELD_NT_PASSWORD_PRESENT |
676 SAMR_FIELD_LM_PASSWORD_PRESENT |
677 SAMR_FIELD_EXPIRED_FLAG;
678 sui2.in.user_handle = wks_handle;
679 sui2.in.info = &u_info;
682 status = dcerpc_samr_SetUserInfo2_r(samr_handle, tmp_ctx, &sui2);
683 if (!NT_STATUS_IS_OK(status)) {
684 torture_comment(tctx, "samr_SetUserInfo(23) failed: %s\n",
688 if (!NT_STATUS_IS_OK(sui2.out.result)) {
689 torture_comment(tctx, "samr_SetUserInfo(23) failed: %s\n",
690 nt_errstr(sui2.out.result));
694 u_info.info16.acct_flags = ACB_NORMAL;
695 sui.in.user_handle = wks_handle;
696 sui.in.info = &u_info;
699 status = dcerpc_samr_SetUserInfo_r(samr_handle, tmp_ctx, &sui);
700 if (!NT_STATUS_IS_OK(status) || !NT_STATUS_IS_OK(sui.out.result)) {
701 torture_comment(tctx, "samr_SetUserInfo(16) failed\n");
705 qui.in.user_handle = wks_handle;
707 qui.out.info = &info;
709 status = dcerpc_samr_QueryUserInfo_r(samr_handle, tmp_ctx, &qui);
710 if (!NT_STATUS_IS_OK(status) || !NT_STATUS_IS_OK(qui.out.result)) {
711 torture_comment(tctx, "samr_QueryUserInfo(21) failed\n");
715 info->info21.allow_password_change = 0;
716 info->info21.force_password_change = 0;
717 info->info21.account_name.string = NULL;
718 info->info21.rid = 0;
719 info->info21.acct_expiry = 0;
720 info->info21.fields_present = 0x81827fa; /* copy usrmgr.exe */
722 u_info.info21 = info->info21;
723 sui.in.user_handle = wks_handle;
724 sui.in.info = &u_info;
727 status = dcerpc_samr_SetUserInfo_r(samr_handle, tmp_ctx, &sui);
728 if (!NT_STATUS_IS_OK(status) || !NT_STATUS_IS_OK(sui.out.result)) {
729 torture_comment(tctx, "samr_SetUserInfo(21) failed\n");
734 *domain_name= talloc_steal(mem_ctx, *domain_name);
735 *user_sid = talloc_steal(mem_ctx, *user_sid);
738 talloc_free(tmp_ctx);
746 static bool delete_user(struct torture_context *tctx,
747 struct smbcli_state *cli,
748 struct cli_credentials *admin_creds,
749 const char *username)
754 struct dcerpc_pipe *samr_pipe;
755 struct dcerpc_binding_handle *samr_handle;
756 struct policy_handle *user_handle;
759 if ((mem_ctx = talloc_init("leave")) == NULL) {
760 torture_comment(tctx, "talloc_init failed\n");
764 ret = get_usr_handle(tctx, cli, mem_ctx, admin_creds,
765 DCERPC_AUTH_TYPE_NTLMSSP,
766 DCERPC_AUTH_LEVEL_INTEGRITY,
767 username, &dom_name, &samr_pipe,
770 torture_comment(tctx, "get_wks_handle failed\n");
773 samr_handle = samr_pipe->binding_handle;
776 struct samr_DeleteUser d;
778 d.in.user_handle = user_handle;
779 d.out.user_handle = user_handle;
781 status = dcerpc_samr_DeleteUser_r(samr_handle, mem_ctx, &d);
782 if (!NT_STATUS_IS_OK(status)) {
783 torture_comment(tctx, "samr_DeleteUser failed %s\n", nt_errstr(status));
786 if (!NT_STATUS_IS_OK(d.out.result)) {
787 torture_comment(tctx, "samr_DeleteUser failed %s\n", nt_errstr(d.out.result));
796 talloc_free(mem_ctx);
801 * Do a Samba3-style join
804 static bool join3(struct torture_context *tctx,
805 struct smbcli_state *cli,
807 struct cli_credentials *admin_creds,
808 struct cli_credentials *wks_creds)
813 struct dcerpc_pipe *samr_pipe;
814 struct dcerpc_binding_handle *samr_handle;
815 struct policy_handle *wks_handle;
817 NTTIME last_password_change;
819 if ((mem_ctx = talloc_init("join3")) == NULL) {
820 torture_comment(tctx, "talloc_init failed\n");
824 ret = get_usr_handle(
825 tctx, cli, mem_ctx, admin_creds,
826 DCERPC_AUTH_TYPE_NTLMSSP,
827 DCERPC_AUTH_LEVEL_PRIVACY,
828 talloc_asprintf(mem_ctx, "%s$",
829 cli_credentials_get_workstation(wks_creds)),
830 &dom_name, &samr_pipe, &wks_handle, NULL);
832 torture_comment(tctx, "get_wks_handle failed\n");
835 samr_handle = samr_pipe->binding_handle;
838 struct samr_QueryUserInfo q;
839 union samr_UserInfo *info;
841 q.in.user_handle = wks_handle;
845 status = dcerpc_samr_QueryUserInfo_r(samr_handle, mem_ctx, &q);
846 if (!NT_STATUS_IS_OK(status)) {
847 torture_warning(tctx, "QueryUserInfo failed: %s\n",
851 if (!NT_STATUS_IS_OK(q.out.result)) {
852 torture_warning(tctx, "QueryUserInfo failed: %s\n",
853 nt_errstr(q.out.result));
858 last_password_change = info->info21.last_password_change;
861 cli_credentials_set_domain(wks_creds, dom_name, CRED_SPECIFIED);
864 struct samr_SetUserInfo2 sui2;
865 union samr_UserInfo u_info;
866 struct samr_UserInfo21 *i21 = &u_info.info25.info;
867 DATA_BLOB session_key;
868 DATA_BLOB confounded_session_key = data_blob_talloc(
871 uint8_t confounder[16];
875 i21->full_name.string = talloc_asprintf(
877 cli_credentials_get_workstation(wks_creds));
878 i21->acct_flags = ACB_WSTRUST;
879 i21->fields_present = SAMR_FIELD_FULL_NAME |
880 SAMR_FIELD_ACCT_FLAGS | SAMR_FIELD_NT_PASSWORD_PRESENT;
881 /* this would break the test result expectations
882 i21->fields_present |= SAMR_FIELD_EXPIRED_FLAG;
883 i21->password_expired = 1;
886 encode_pw_buffer(u_info.info25.password.data,
887 cli_credentials_get_password(wks_creds),
889 status = dcerpc_fetch_session_key(samr_pipe, &session_key);
890 if (!NT_STATUS_IS_OK(status)) {
891 torture_comment(tctx, "dcerpc_fetch_session_key failed: %s\n",
895 generate_random_buffer((uint8_t *)confounder, 16);
898 MD5Update(&ctx, confounder, 16);
899 MD5Update(&ctx, session_key.data, session_key.length);
900 MD5Final(confounded_session_key.data, &ctx);
902 arcfour_crypt_blob(u_info.info25.password.data, 516,
903 &confounded_session_key);
904 memcpy(&u_info.info25.password.data[516], confounder, 16);
906 sui2.in.user_handle = wks_handle;
908 sui2.in.info = &u_info;
910 status = dcerpc_samr_SetUserInfo2_r(samr_handle, mem_ctx, &sui2);
911 if (!NT_STATUS_IS_OK(status)) {
912 torture_comment(tctx, "samr_SetUserInfo2(25) failed: %s\n",
916 if (!NT_STATUS_IS_OK(sui2.out.result)) {
917 torture_comment(tctx, "samr_SetUserInfo2(25) failed: %s\n",
918 nt_errstr(sui2.out.result));
922 struct samr_SetUserInfo2 sui2;
923 struct samr_SetUserInfo sui;
924 union samr_UserInfo u_info;
925 DATA_BLOB session_key;
927 encode_pw_buffer(u_info.info24.password.data,
928 cli_credentials_get_password(wks_creds),
930 /* just to make this test pass */
931 u_info.info24.password_expired = 1;
933 status = dcerpc_fetch_session_key(samr_pipe, &session_key);
934 if (!NT_STATUS_IS_OK(status)) {
935 torture_comment(tctx, "dcerpc_fetch_session_key failed\n");
938 arcfour_crypt_blob(u_info.info24.password.data, 516,
940 sui2.in.user_handle = wks_handle;
941 sui2.in.info = &u_info;
944 status = dcerpc_samr_SetUserInfo2_r(samr_handle, mem_ctx, &sui2);
945 if (!NT_STATUS_IS_OK(status)) {
946 torture_comment(tctx, "samr_SetUserInfo(24) failed: %s\n",
950 if (!NT_STATUS_IS_OK(sui2.out.result)) {
951 torture_comment(tctx, "samr_SetUserInfo(24) failed: %s\n",
952 nt_errstr(sui2.out.result));
956 u_info.info16.acct_flags = ACB_WSTRUST;
957 sui.in.user_handle = wks_handle;
958 sui.in.info = &u_info;
961 status = dcerpc_samr_SetUserInfo_r(samr_handle, mem_ctx, &sui);
962 if (!NT_STATUS_IS_OK(status) || !NT_STATUS_IS_OK(sui.out.result)) {
963 torture_comment(tctx, "samr_SetUserInfo(16) failed\n");
969 struct samr_QueryUserInfo q;
970 union samr_UserInfo *info;
972 q.in.user_handle = wks_handle;
976 status = dcerpc_samr_QueryUserInfo_r(samr_handle, mem_ctx, &q);
977 if (!NT_STATUS_IS_OK(status)) {
978 torture_warning(tctx, "QueryUserInfo failed: %s\n",
982 if (!NT_STATUS_IS_OK(q.out.result)) {
983 torture_warning(tctx, "QueryUserInfo failed: %s\n",
984 nt_errstr(q.out.result));
989 if (last_password_change
990 == info->info21.last_password_change) {
991 torture_warning(tctx, "last_password_change unchanged "
992 "during join, level25 must change "
998 if (last_password_change
999 != info->info21.last_password_change) {
1000 torture_warning(tctx, "last_password_change changed "
1001 "during join, level24 doesn't "
1011 talloc_free(mem_ctx);
1016 * Do a ReqChallenge/Auth2 and get the wks creds
1019 static bool auth2(struct torture_context *tctx,
1020 struct smbcli_state *cli,
1021 struct cli_credentials *wks_cred)
1023 TALLOC_CTX *mem_ctx;
1024 struct dcerpc_pipe *net_pipe;
1025 struct dcerpc_binding_handle *net_handle;
1026 bool result = false;
1028 struct netr_ServerReqChallenge r;
1029 struct netr_Credential netr_cli_creds;
1030 struct netr_Credential netr_srv_creds;
1031 uint32_t negotiate_flags;
1032 struct netr_ServerAuthenticate2 a;
1033 struct netlogon_creds_CredentialState *creds_state;
1034 struct netr_Credential netr_cred;
1035 struct samr_Password mach_pw;
1037 mem_ctx = talloc_new(NULL);
1038 if (mem_ctx == NULL) {
1039 torture_comment(tctx, "talloc_new failed\n");
1043 status = pipe_bind_smb(tctx, mem_ctx, cli->tree, "\\netlogon",
1044 &ndr_table_netlogon, &net_pipe);
1045 torture_assert_ntstatus_ok_goto(tctx, status, result, done,
1046 "pipe_bind_smb failed");
1047 net_handle = net_pipe->binding_handle;
1049 r.in.computer_name = cli_credentials_get_workstation(wks_cred);
1050 r.in.server_name = talloc_asprintf(
1051 mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
1052 if (r.in.server_name == NULL) {
1053 torture_comment(tctx, "talloc_asprintf failed\n");
1056 generate_random_buffer(netr_cli_creds.data,
1057 sizeof(netr_cli_creds.data));
1058 r.in.credentials = &netr_cli_creds;
1059 r.out.return_credentials = &netr_srv_creds;
1061 status = dcerpc_netr_ServerReqChallenge_r(net_handle, mem_ctx, &r);
1062 if (!NT_STATUS_IS_OK(status)) {
1063 torture_comment(tctx, "netr_ServerReqChallenge failed: %s\n",
1067 if (!NT_STATUS_IS_OK(r.out.result)) {
1068 torture_comment(tctx, "netr_ServerReqChallenge failed: %s\n",
1069 nt_errstr(r.out.result));
1073 negotiate_flags = NETLOGON_NEG_AUTH2_ADS_FLAGS;
1074 E_md4hash(cli_credentials_get_password(wks_cred), mach_pw.hash);
1076 a.in.server_name = talloc_asprintf(
1077 mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
1078 a.in.account_name = talloc_asprintf(
1079 mem_ctx, "%s$", cli_credentials_get_workstation(wks_cred));
1080 a.in.computer_name = cli_credentials_get_workstation(wks_cred);
1081 a.in.secure_channel_type = SEC_CHAN_WKSTA;
1082 a.in.negotiate_flags = &negotiate_flags;
1083 a.out.negotiate_flags = &negotiate_flags;
1084 a.in.credentials = &netr_cred;
1085 a.out.return_credentials = &netr_cred;
1087 creds_state = netlogon_creds_client_init(mem_ctx,
1090 a.in.secure_channel_type,
1092 r.out.return_credentials, &mach_pw,
1093 &netr_cred, negotiate_flags);
1094 torture_assert(tctx, (creds_state != NULL), "memory allocation failed");
1096 status = dcerpc_netr_ServerAuthenticate2_r(net_handle, mem_ctx, &a);
1097 if (!NT_STATUS_IS_OK(status)) {
1098 torture_comment(tctx, "netr_ServerServerAuthenticate2 failed: %s\n",
1102 if (!NT_STATUS_IS_OK(a.out.result)) {
1103 torture_comment(tctx, "netr_ServerServerAuthenticate2 failed: %s\n",
1104 nt_errstr(a.out.result));
1108 if (!netlogon_creds_client_check(creds_state, a.out.return_credentials)) {
1109 torture_comment(tctx, "creds_client_check failed\n");
1113 cli_credentials_set_netlogon_creds(wks_cred, creds_state);
1118 talloc_free(mem_ctx);
1123 * Do a couple of schannel protected Netlogon ops: Interactive and Network
1124 * login, and change the wks password
1127 static bool schan(struct torture_context *tctx,
1128 struct smbcli_state *cli,
1129 struct cli_credentials *wks_creds,
1130 struct cli_credentials *user_creds)
1132 TALLOC_CTX *mem_ctx;
1135 struct dcerpc_pipe *net_pipe;
1136 struct dcerpc_binding_handle *net_handle;
1139 mem_ctx = talloc_new(NULL);
1140 if (mem_ctx == NULL) {
1141 torture_comment(tctx, "talloc_new failed\n");
1146 status = pipe_bind_smb_auth(tctx, mem_ctx, cli->tree,
1148 DCERPC_AUTH_TYPE_SCHANNEL,
1149 DCERPC_AUTH_LEVEL_PRIVACY,
1150 "\\netlogon", &ndr_table_netlogon, &net_pipe);
1151 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
1152 "pipe_bind_smb_auth failed");
1153 net_pipe->conn->flags |= (DCERPC_SIGN | DCERPC_SEAL);
1155 status = pipe_bind_smb(tctx, mem_ctx, cli->tree,
1156 "\\netlogon", &ndr_table_netlogon, &net_pipe);
1157 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
1158 "pipe_bind_smb failed");
1161 net_pipe->conn->flags |= DCERPC_DEBUG_PRINT_IN |
1162 DCERPC_DEBUG_PRINT_OUT;
1164 net_handle = net_pipe->binding_handle;
1167 for (i=2; i<4; i++) {
1169 DATA_BLOB chal, nt_resp, lm_resp, names_blob;
1170 struct netlogon_creds_CredentialState *creds_state;
1171 struct netr_Authenticator netr_auth, netr_auth2;
1172 struct netr_NetworkInfo ninfo;
1173 struct netr_PasswordInfo pinfo;
1174 struct netr_LogonSamLogon r;
1175 union netr_LogonLevel logon;
1176 union netr_Validation validation;
1177 uint8_t authoritative;
1178 struct netr_Authenticator return_authenticator;
1180 flags = CLI_CRED_LANMAN_AUTH | CLI_CRED_NTLM_AUTH |
1181 CLI_CRED_NTLMv2_AUTH;
1183 chal = data_blob_talloc(mem_ctx, NULL, 8);
1184 if (chal.data == NULL) {
1185 torture_comment(tctx, "data_blob_talloc failed\n");
1189 generate_random_buffer(chal.data, chal.length);
1190 names_blob = NTLMv2_generate_names_blob(
1192 cli_credentials_get_workstation(wks_creds),
1193 cli_credentials_get_domain(wks_creds));
1194 status = cli_credentials_get_ntlm_response(
1195 user_creds, mem_ctx, &flags, chal, NULL, names_blob,
1196 &lm_resp, &nt_resp, NULL, NULL);
1197 if (!NT_STATUS_IS_OK(status)) {
1198 torture_comment(tctx, "cli_credentials_get_ntlm_response failed:"
1199 " %s\n", nt_errstr(status));
1203 creds_state = cli_credentials_get_netlogon_creds(wks_creds);
1204 netlogon_creds_client_authenticator(creds_state, &netr_auth);
1206 ninfo.identity_info.account_name.string =
1207 cli_credentials_get_username(user_creds);
1208 ninfo.identity_info.domain_name.string =
1209 cli_credentials_get_domain(user_creds);
1210 ninfo.identity_info.parameter_control = 0;
1211 ninfo.identity_info.logon_id_low = 0;
1212 ninfo.identity_info.logon_id_high = 0;
1213 ninfo.identity_info.workstation.string =
1214 cli_credentials_get_workstation(user_creds);
1215 memcpy(ninfo.challenge, chal.data, sizeof(ninfo.challenge));
1216 ninfo.nt.length = nt_resp.length;
1217 ninfo.nt.data = nt_resp.data;
1218 ninfo.lm.length = lm_resp.length;
1219 ninfo.lm.data = lm_resp.data;
1221 logon.network = &ninfo;
1223 r.in.server_name = talloc_asprintf(
1224 mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
1225 ZERO_STRUCT(netr_auth2);
1226 r.in.computer_name =
1227 cli_credentials_get_workstation(wks_creds);
1228 r.in.credential = &netr_auth;
1229 r.in.return_authenticator = &netr_auth2;
1230 r.in.logon_level = NetlogonNetworkInformation;
1231 r.in.validation_level = i;
1232 r.in.logon = &logon;
1233 r.out.validation = &validation;
1234 r.out.authoritative = &authoritative;
1235 r.out.return_authenticator = &return_authenticator;
1237 status = dcerpc_netr_LogonSamLogon_r(net_handle, mem_ctx, &r);
1238 if (!NT_STATUS_IS_OK(status)) {
1239 torture_comment(tctx, "netr_LogonSamLogon failed: %s\n",
1243 if (!NT_STATUS_IS_OK(r.out.result)) {
1244 torture_comment(tctx, "netr_LogonSamLogon failed: %s\n",
1245 nt_errstr(r.out.result));
1249 if ((r.out.return_authenticator == NULL) ||
1250 (!netlogon_creds_client_check(creds_state,
1251 &r.out.return_authenticator->cred))) {
1252 torture_comment(tctx, "Credentials check failed!\n");
1256 netlogon_creds_client_authenticator(creds_state, &netr_auth);
1258 pinfo.identity_info = ninfo.identity_info;
1259 ZERO_STRUCT(pinfo.lmpassword.hash);
1260 E_md4hash(cli_credentials_get_password(user_creds),
1261 pinfo.ntpassword.hash);
1263 netlogon_creds_arcfour_crypt(creds_state, pinfo.ntpassword.hash, 16);
1265 logon.password = &pinfo;
1267 r.in.logon_level = NetlogonInteractiveInformation;
1268 r.in.logon = &logon;
1269 r.out.return_authenticator = &return_authenticator;
1271 status = dcerpc_netr_LogonSamLogon_r(net_handle, mem_ctx, &r);
1272 if (!NT_STATUS_IS_OK(status)) {
1273 torture_comment(tctx, "netr_LogonSamLogon failed: %s\n",
1277 if (!NT_STATUS_IS_OK(r.out.result)) {
1278 torture_comment(tctx, "netr_LogonSamLogon failed: %s\n",
1279 nt_errstr(r.out.result));
1283 if ((r.out.return_authenticator == NULL) ||
1284 (!netlogon_creds_client_check(creds_state,
1285 &r.out.return_authenticator->cred))) {
1286 torture_comment(tctx, "Credentials check failed!\n");
1292 struct netr_ServerPasswordSet s;
1293 char *password = generate_random_password(wks_creds, 8, 255);
1294 struct netlogon_creds_CredentialState *creds_state;
1295 struct netr_Authenticator credential, return_authenticator;
1296 struct samr_Password new_password;
1298 s.in.server_name = talloc_asprintf(
1299 mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
1300 s.in.computer_name = cli_credentials_get_workstation(wks_creds);
1301 s.in.account_name = talloc_asprintf(
1302 mem_ctx, "%s$", s.in.computer_name);
1303 s.in.secure_channel_type = SEC_CHAN_WKSTA;
1304 s.in.credential = &credential;
1305 s.in.new_password = &new_password;
1306 s.out.return_authenticator = &return_authenticator;
1308 E_md4hash(password, new_password.hash);
1310 creds_state = cli_credentials_get_netlogon_creds(wks_creds);
1311 netlogon_creds_des_encrypt(creds_state, &new_password);
1312 netlogon_creds_client_authenticator(creds_state, &credential);
1314 status = dcerpc_netr_ServerPasswordSet_r(net_handle, mem_ctx, &s);
1315 if (!NT_STATUS_IS_OK(status)) {
1316 torture_comment(tctx, "ServerPasswordSet - %s\n", nt_errstr(status));
1319 if (!NT_STATUS_IS_OK(s.out.result)) {
1320 torture_comment(tctx, "ServerPasswordSet - %s\n", nt_errstr(s.out.result));
1324 if (!netlogon_creds_client_check(creds_state,
1325 &s.out.return_authenticator->cred)) {
1326 torture_comment(tctx, "Credential chaining failed\n");
1329 cli_credentials_set_password(wks_creds, password,
1335 talloc_free(mem_ctx);
1340 * Delete the wks account again
1343 static bool leave(struct torture_context *tctx,
1344 struct smbcli_state *cli,
1345 struct cli_credentials *admin_creds,
1346 struct cli_credentials *wks_creds)
1348 char *wks_name = talloc_asprintf(
1349 NULL, "%s$", cli_credentials_get_workstation(wks_creds));
1352 ret = delete_user(tctx, cli, admin_creds, wks_name);
1353 talloc_free(wks_name);
1358 * Test the Samba3 DC code a bit. Join, do some schan netlogon ops, leave
1361 static bool torture_netlogon_samba3(struct torture_context *torture)
1364 struct smbcli_state *cli;
1365 struct cli_credentials *wks_creds;
1366 const char *wks_name;
1368 struct smbcli_options options;
1369 struct smbcli_session_options session_options;
1371 wks_name = torture_setting_string(torture, "wksname", NULL);
1372 if (wks_name == NULL) {
1373 wks_name = get_myname(torture);
1376 lpcfg_smbcli_options(torture->lp_ctx, &options);
1377 lpcfg_smbcli_session_options(torture->lp_ctx, &session_options);
1379 status = smbcli_full_connection(torture, &cli,
1380 torture_setting_string(torture, "host", NULL),
1381 lpcfg_smb_ports(torture->lp_ctx),
1383 lpcfg_socket_options(torture->lp_ctx),
1384 cmdline_credentials,
1385 lpcfg_resolve_context(torture->lp_ctx),
1386 torture->ev, &options, &session_options,
1387 lpcfg_gensec_settings(torture, torture->lp_ctx));
1388 torture_assert_ntstatus_ok(torture, status, "smbcli_full_connection failed\n");
1390 wks_creds = cli_credentials_init(torture);
1391 if (wks_creds == NULL) {
1392 torture_fail(torture, "cli_credentials_init failed\n");
1395 cli_credentials_set_conf(wks_creds, torture->lp_ctx);
1396 cli_credentials_set_secure_channel_type(wks_creds, SEC_CHAN_WKSTA);
1397 cli_credentials_set_username(wks_creds, wks_name, CRED_SPECIFIED);
1398 cli_credentials_set_workstation(wks_creds, wks_name, CRED_SPECIFIED);
1399 cli_credentials_set_password(wks_creds,
1400 generate_random_password(wks_creds, 8, 255),
1403 torture_assert(torture,
1404 join3(torture, cli, false, NULL, wks_creds),
1407 cli_credentials_set_domain(
1408 cmdline_credentials, cli_credentials_get_domain(wks_creds),
1411 for (i=0; i<2; i++) {
1413 /* Do this more than once, the routine "schan" changes
1414 * the workstation password using the netlogon
1415 * password change routine */
1419 torture_assert(torture,
1420 auth2(torture, cli, wks_creds),
1423 for (j=0; j<2; j++) {
1424 torture_assert(torture,
1425 schan(torture, cli, wks_creds, cmdline_credentials),
1430 torture_assert(torture,
1431 leave(torture, cli, NULL, wks_creds),
1438 * Do a simple join, testjoin and leave using specified smb and samr
1442 static bool test_join3(struct torture_context *tctx,
1444 struct cli_credentials *smb_creds,
1445 struct cli_credentials *samr_creds,
1446 const char *wks_name)
1449 struct smbcli_state *cli;
1450 struct cli_credentials *wks_creds;
1451 struct smbcli_options options;
1452 struct smbcli_session_options session_options;
1454 lpcfg_smbcli_options(tctx->lp_ctx, &options);
1455 lpcfg_smbcli_session_options(tctx->lp_ctx, &session_options);
1457 status = smbcli_full_connection(tctx, &cli,
1458 torture_setting_string(tctx, "host", NULL),
1459 lpcfg_smb_ports(tctx->lp_ctx),
1460 "IPC$", NULL, lpcfg_socket_options(tctx->lp_ctx),
1461 smb_creds, lpcfg_resolve_context(tctx->lp_ctx),
1462 tctx->ev, &options, &session_options,
1463 lpcfg_gensec_settings(tctx, tctx->lp_ctx));
1464 torture_assert_ntstatus_ok(tctx, status,
1465 "smbcli_full_connection failed");
1467 wks_creds = cli_credentials_init(cli);
1468 torture_assert(tctx, wks_creds, "cli_credentials_init failed");
1470 cli_credentials_set_conf(wks_creds, tctx->lp_ctx);
1471 cli_credentials_set_secure_channel_type(wks_creds, SEC_CHAN_WKSTA);
1472 cli_credentials_set_username(wks_creds, wks_name, CRED_SPECIFIED);
1473 cli_credentials_set_workstation(wks_creds, wks_name, CRED_SPECIFIED);
1474 cli_credentials_set_password(wks_creds,
1475 generate_random_password(wks_creds, 8, 255),
1478 torture_assert(tctx,
1479 join3(tctx, cli, use_level25, samr_creds, wks_creds),
1482 cli_credentials_set_domain(
1483 cmdline_credentials, cli_credentials_get_domain(wks_creds),
1486 torture_assert(tctx,
1487 auth2(tctx, cli, wks_creds),
1490 torture_assert(tctx,
1491 leave(tctx, cli, samr_creds, wks_creds),
1500 * Test the different session key variants. Do it by joining, this uses the
1501 * session key in the setpassword routine. Test the join by doing the auth2.
1504 static bool torture_samba3_sessionkey(struct torture_context *torture)
1506 struct cli_credentials *anon_creds;
1507 const char *wks_name;
1509 wks_name = torture_setting_string(torture, "wksname", get_myname(torture));
1511 if (!(anon_creds = cli_credentials_init_anon(torture))) {
1512 torture_fail(torture, "create_anon_creds failed\n");
1515 cli_credentials_set_workstation(anon_creds, wks_name, CRED_SPECIFIED);
1518 if (!torture_setting_bool(torture, "samba3", false)) {
1520 /* Samba3 in the build farm right now does this happily. Need
1523 if (test_join3(torture, false, anon_creds, NULL, wks_name)) {
1524 torture_fail(torture, "join using anonymous bind on an anonymous smb "
1525 "connection succeeded -- HUH??\n");
1529 torture_assert(torture,
1530 test_join3(torture, false, cmdline_credentials, NULL, wks_name),
1531 "join using anonymous bind on an authenticated smb connection failed");
1534 * The following two are tests for setuserinfolevel 25
1537 torture_assert(torture,
1538 test_join3(torture, true, cmdline_credentials, NULL, wks_name),
1539 "join using anonymous bind on an authenticated smb connection failed");
1545 * Sane wrapper around lsa_LookupNames
1548 static struct dom_sid *name2sid(struct torture_context *tctx,
1549 TALLOC_CTX *mem_ctx,
1550 struct dcerpc_pipe *p,
1554 struct lsa_ObjectAttribute attr;
1555 struct lsa_QosInfo qos;
1556 struct lsa_OpenPolicy2 r;
1559 struct policy_handle handle;
1560 struct lsa_LookupNames l;
1561 struct lsa_TransSidArray sids;
1562 struct lsa_RefDomainList *domains = NULL;
1563 struct lsa_String lsa_name;
1565 struct dom_sid *result;
1566 TALLOC_CTX *tmp_ctx;
1567 struct dcerpc_binding_handle *b = p->binding_handle;
1569 if (!(tmp_ctx = talloc_new(mem_ctx))) {
1574 qos.impersonation_level = 2;
1575 qos.context_mode = 1;
1576 qos.effective_only = 0;
1579 attr.root_dir = NULL;
1580 attr.object_name = NULL;
1581 attr.attributes = 0;
1582 attr.sec_desc = NULL;
1583 attr.sec_qos = &qos;
1585 r.in.system_name = "\\";
1587 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1588 r.out.handle = &handle;
1590 status = dcerpc_lsa_OpenPolicy2_r(b, tmp_ctx, &r);
1591 if (!NT_STATUS_IS_OK(status)) {
1592 torture_comment(tctx, "OpenPolicy2 failed - %s\n", nt_errstr(status));
1593 talloc_free(tmp_ctx);
1596 if (!NT_STATUS_IS_OK(r.out.result)) {
1597 torture_comment(tctx, "OpenPolicy2 failed - %s\n", nt_errstr(r.out.result));
1598 talloc_free(tmp_ctx);
1605 lsa_name.string = talloc_asprintf(tmp_ctx, "%s\\%s", domain, name);
1607 l.in.handle = &handle;
1609 l.in.names = &lsa_name;
1612 l.in.count = &count;
1613 l.out.count = &count;
1615 l.out.domains = &domains;
1617 status = dcerpc_lsa_LookupNames_r(b, tmp_ctx, &l);
1618 if (!NT_STATUS_IS_OK(status)) {
1619 torture_comment(tctx, "LookupNames of %s failed - %s\n", lsa_name.string,
1621 talloc_free(tmp_ctx);
1624 if (!NT_STATUS_IS_OK(l.out.result)) {
1625 torture_comment(tctx, "LookupNames of %s failed - %s\n", lsa_name.string,
1626 nt_errstr(l.out.result));
1627 talloc_free(tmp_ctx);
1631 result = dom_sid_add_rid(mem_ctx, domains->domains[0].sid,
1632 l.out.sids->sids[0].rid);
1634 c.in.handle = &handle;
1635 c.out.handle = &handle;
1637 status = dcerpc_lsa_Close_r(b, tmp_ctx, &c);
1638 if (!NT_STATUS_IS_OK(status)) {
1639 torture_comment(tctx, "dcerpc_lsa_Close failed - %s\n", nt_errstr(status));
1640 talloc_free(tmp_ctx);
1643 if (!NT_STATUS_IS_OK(c.out.result)) {
1644 torture_comment(tctx, "dcerpc_lsa_Close failed - %s\n", nt_errstr(c.out.result));
1645 talloc_free(tmp_ctx);
1649 talloc_free(tmp_ctx);
1654 * Find out the user SID on this connection
1657 static struct dom_sid *whoami(struct torture_context *tctx,
1658 TALLOC_CTX *mem_ctx,
1659 struct smbcli_tree *tree)
1661 struct dcerpc_pipe *lsa;
1662 struct dcerpc_binding_handle *lsa_handle;
1663 struct lsa_GetUserName r;
1665 struct lsa_String *authority_name_p = NULL;
1666 struct lsa_String *account_name_p = NULL;
1667 struct dom_sid *result;
1669 status = pipe_bind_smb(tctx, mem_ctx, tree, "\\pipe\\lsarpc",
1670 &ndr_table_lsarpc, &lsa);
1671 if (!NT_STATUS_IS_OK(status)) {
1672 torture_warning(tctx, "Could not bind to LSA: %s\n",
1676 lsa_handle = lsa->binding_handle;
1678 r.in.system_name = "\\";
1679 r.in.account_name = &account_name_p;
1680 r.in.authority_name = &authority_name_p;
1681 r.out.account_name = &account_name_p;
1683 status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r);
1685 authority_name_p = *r.out.authority_name;
1687 if (!NT_STATUS_IS_OK(status)) {
1688 torture_warning(tctx, "GetUserName failed - %s\n",
1693 if (!NT_STATUS_IS_OK(r.out.result)) {
1694 torture_warning(tctx, "GetUserName failed - %s\n",
1695 nt_errstr(r.out.result));
1700 result = name2sid(tctx, mem_ctx, lsa, account_name_p->string,
1701 authority_name_p->string);
1707 static int destroy_tree(struct smbcli_tree *tree)
1709 smb_tree_disconnect(tree);
1714 * Do a tcon, given a session
1717 static NTSTATUS secondary_tcon(struct torture_context *tctx,
1718 TALLOC_CTX *mem_ctx,
1719 struct smbcli_session *session,
1720 const char *sharename,
1721 struct smbcli_tree **res)
1723 struct smbcli_tree *result;
1724 TALLOC_CTX *tmp_ctx;
1725 union smb_tcon tcon;
1728 if (!(tmp_ctx = talloc_new(mem_ctx))) {
1729 return NT_STATUS_NO_MEMORY;
1732 if (!(result = smbcli_tree_init(session, mem_ctx, false))) {
1733 talloc_free(tmp_ctx);
1734 return NT_STATUS_NO_MEMORY;
1737 tcon.generic.level = RAW_TCON_TCONX;
1738 tcon.tconx.in.flags = TCONX_FLAG_EXTENDED_RESPONSE;
1739 tcon.tconx.in.flags |= TCONX_FLAG_EXTENDED_SIGNATURES;
1740 tcon.tconx.in.password = data_blob(NULL, 0);
1741 tcon.tconx.in.path = sharename;
1742 tcon.tconx.in.device = "?????";
1744 status = smb_raw_tcon(result, tmp_ctx, &tcon);
1745 if (!NT_STATUS_IS_OK(status)) {
1746 torture_warning(tctx, "smb_raw_tcon failed: %s\n",
1748 talloc_free(tmp_ctx);
1752 result->tid = tcon.tconx.out.tid;
1754 if (tcon.tconx.out.options & SMB_EXTENDED_SIGNATURES) {
1755 smb1cli_session_protect_session_key(result->session->smbXcli);
1758 result = talloc_steal(mem_ctx, result);
1759 talloc_set_destructor(result, destroy_tree);
1760 talloc_free(tmp_ctx);
1762 return NT_STATUS_OK;
1766 * Test the getusername behaviour
1769 static bool torture_samba3_rpc_getusername(struct torture_context *torture)
1772 struct smbcli_state *cli;
1774 struct dom_sid *user_sid;
1775 struct dom_sid *created_sid;
1776 struct cli_credentials *anon_creds;
1777 struct cli_credentials *user_creds;
1779 struct smbcli_options options;
1780 struct smbcli_session_options session_options;
1782 lpcfg_smbcli_options(torture->lp_ctx, &options);
1783 lpcfg_smbcli_session_options(torture->lp_ctx, &session_options);
1785 if (!(anon_creds = cli_credentials_init_anon(torture))) {
1786 torture_fail(torture, "create_anon_creds failed\n");
1789 status = smbcli_full_connection(
1790 torture, &cli, torture_setting_string(torture, "host", NULL),
1791 lpcfg_smb_ports(torture->lp_ctx), "IPC$", NULL,
1792 lpcfg_socket_options(torture->lp_ctx), anon_creds,
1793 lpcfg_resolve_context(torture->lp_ctx),
1794 torture->ev, &options, &session_options,
1795 lpcfg_gensec_settings(torture, torture->lp_ctx));
1796 torture_assert_ntstatus_ok(torture, status, "anon smbcli_full_connection failed\n");
1798 if (!(user_sid = whoami(torture, torture, cli->tree))) {
1799 torture_fail(torture, "whoami on anon connection failed\n");
1802 torture_assert_sid_equal(torture, user_sid, dom_sid_parse_talloc(torture, "s-1-5-7"),
1803 "Anon lsa_GetUserName returned unexpected SID");
1807 status = smbcli_full_connection(
1808 torture, &cli, torture_setting_string(torture, "host", NULL),
1809 lpcfg_smb_ports(torture->lp_ctx),
1810 "IPC$", NULL, lpcfg_socket_options(torture->lp_ctx), cmdline_credentials,
1811 lpcfg_resolve_context(torture->lp_ctx), torture->ev, &options,
1812 &session_options, lpcfg_gensec_settings(torture, torture->lp_ctx));
1813 torture_assert_ntstatus_ok(torture, status, "smbcli_full_connection failed\n");
1815 if (!(user_sid = whoami(torture, torture, cli->tree))) {
1816 torture_fail(torture, "whoami on auth'ed connection failed\n");
1819 if (!(user_creds = cli_credentials_init(torture))) {
1820 torture_fail(torture, "cli_credentials_init failed\n");
1823 cli_credentials_set_conf(user_creds, torture->lp_ctx);
1824 cli_credentials_set_username(user_creds, "torture_username",
1826 cli_credentials_set_password(user_creds,
1827 generate_random_password(user_creds, 8, 255),
1830 if (!create_user(torture, torture, cli, NULL,
1831 cli_credentials_get_username(user_creds),
1832 cli_credentials_get_password(user_creds),
1833 &domain_name, &created_sid)) {
1834 torture_fail(torture, "create_user failed\n");
1837 cli_credentials_set_domain(user_creds, domain_name,
1841 struct smbcli_session *session2;
1842 struct smb_composite_sesssetup setup;
1843 struct smbcli_tree *tree;
1845 session2 = smbcli_session_init(cli->transport, torture, false, session_options);
1846 if (session2 == NULL) {
1847 torture_fail(torture, "smbcli_session_init failed\n");
1850 setup.in.sesskey = cli->transport->negotiate.sesskey;
1851 setup.in.capabilities = cli->transport->negotiate.capabilities;
1852 setup.in.workgroup = "";
1853 setup.in.credentials = user_creds;
1854 setup.in.gensec_settings = lpcfg_gensec_settings(torture, torture->lp_ctx);
1856 status = smb_composite_sesssetup(session2, &setup);
1857 torture_assert_ntstatus_ok(torture, status, "session setup with new user failed");
1859 session2->vuid = setup.out.vuid;
1861 if (!NT_STATUS_IS_OK(secondary_tcon(torture, torture, session2,
1863 torture_fail(torture, "secondary_tcon failed\n");
1866 if (!(user_sid = whoami(torture, torture, tree))) {
1867 torture_fail_goto(torture, del, "whoami on user connection failed\n");
1875 torture_comment(torture, "Created %s, found %s\n",
1876 dom_sid_string(torture, created_sid),
1877 dom_sid_string(torture, user_sid));
1879 if (!dom_sid_equal(created_sid, user_sid)) {
1884 if (!delete_user(torture, cli,
1886 cli_credentials_get_username(user_creds))) {
1887 torture_fail(torture, "delete_user failed\n");
1893 static bool test_NetShareGetInfo(struct torture_context *tctx,
1894 struct dcerpc_pipe *p,
1895 const char *sharename)
1898 struct srvsvc_NetShareGetInfo r;
1899 union srvsvc_NetShareInfo info;
1900 uint32_t levels[] = { 0, 1, 2, 501, 502, 1004, 1005, 1006, 1007, 1501 };
1903 struct dcerpc_binding_handle *b = p->binding_handle;
1905 r.in.server_unc = talloc_asprintf(tctx, "\\\\%s",
1906 dcerpc_server_name(p));
1907 r.in.share_name = sharename;
1910 for (i=0;i<ARRAY_SIZE(levels);i++) {
1911 r.in.level = levels[i];
1913 torture_comment(tctx, "Testing NetShareGetInfo level %u on share '%s'\n",
1914 r.in.level, r.in.share_name);
1916 status = dcerpc_srvsvc_NetShareGetInfo_r(b, tctx, &r);
1917 if (!NT_STATUS_IS_OK(status)) {
1918 torture_warning(tctx, "NetShareGetInfo level %u on share '%s' failed"
1919 " - %s\n", r.in.level, r.in.share_name,
1924 if (!W_ERROR_IS_OK(r.out.result)) {
1925 torture_warning(tctx, "NetShareGetInfo level %u on share '%s' failed "
1926 "- %s\n", r.in.level, r.in.share_name,
1927 win_errstr(r.out.result));
1936 static bool test_NetShareEnum(struct torture_context *tctx,
1937 struct dcerpc_pipe *p,
1938 const char **one_sharename)
1941 struct srvsvc_NetShareEnum r;
1942 struct srvsvc_NetShareInfoCtr info_ctr;
1943 struct srvsvc_NetShareCtr0 c0;
1944 struct srvsvc_NetShareCtr1 c1;
1945 struct srvsvc_NetShareCtr2 c2;
1946 struct srvsvc_NetShareCtr501 c501;
1947 struct srvsvc_NetShareCtr502 c502;
1948 struct srvsvc_NetShareCtr1004 c1004;
1949 struct srvsvc_NetShareCtr1005 c1005;
1950 struct srvsvc_NetShareCtr1006 c1006;
1951 struct srvsvc_NetShareCtr1007 c1007;
1952 uint32_t totalentries = 0;
1953 uint32_t levels[] = { 0, 1, 2, 501, 502, 1004, 1005, 1006, 1007 };
1956 struct dcerpc_binding_handle *b = p->binding_handle;
1958 ZERO_STRUCT(info_ctr);
1960 r.in.server_unc = talloc_asprintf(tctx,"\\\\%s",dcerpc_server_name(p));
1961 r.in.info_ctr = &info_ctr;
1962 r.in.max_buffer = (uint32_t)-1;
1963 r.in.resume_handle = NULL;
1964 r.out.totalentries = &totalentries;
1965 r.out.info_ctr = &info_ctr;
1967 for (i=0;i<ARRAY_SIZE(levels);i++) {
1968 info_ctr.level = levels[i];
1970 switch (info_ctr.level) {
1973 info_ctr.ctr.ctr0 = &c0;
1977 info_ctr.ctr.ctr1 = &c1;
1981 info_ctr.ctr.ctr2 = &c2;
1985 info_ctr.ctr.ctr501 = &c501;
1989 info_ctr.ctr.ctr502 = &c502;
1993 info_ctr.ctr.ctr1004 = &c1004;
1997 info_ctr.ctr.ctr1005 = &c1005;
2001 info_ctr.ctr.ctr1006 = &c1006;
2005 info_ctr.ctr.ctr1007 = &c1007;
2009 torture_comment(tctx, "Testing NetShareEnum level %u\n", info_ctr.level);
2011 status = dcerpc_srvsvc_NetShareEnum_r(b, tctx, &r);
2012 if (!NT_STATUS_IS_OK(status)) {
2013 torture_warning(tctx, "NetShareEnum level %u failed - %s\n",
2014 info_ctr.level, nt_errstr(status));
2018 if (!W_ERROR_IS_OK(r.out.result)) {
2019 torture_warning(tctx, "NetShareEnum level %u failed - %s\n",
2020 info_ctr.level, win_errstr(r.out.result));
2023 if (info_ctr.level == 0) {
2024 struct srvsvc_NetShareCtr0 *ctr = r.out.info_ctr->ctr.ctr0;
2025 if (ctr->count > 0) {
2026 *one_sharename = ctr->array[0].name;
2034 static bool torture_samba3_rpc_srvsvc(struct torture_context *torture)
2036 struct dcerpc_pipe *p;
2037 const char *sharename = NULL;
2040 torture_assert_ntstatus_ok(torture,
2041 torture_rpc_connection(torture, &p, &ndr_table_srvsvc),
2042 "failed to open srvsvc");
2044 ret &= test_NetShareEnum(torture, p, &sharename);
2045 if (sharename == NULL) {
2046 torture_comment(torture, "did not get sharename\n");
2048 ret &= test_NetShareGetInfo(torture, p, sharename);
2055 * Do a ReqChallenge/Auth2 with a random wks name, make sure it returns
2056 * NT_STATUS_NO_SAM_ACCOUNT
2059 static bool torture_samba3_rpc_randomauth2(struct torture_context *torture)
2061 TALLOC_CTX *mem_ctx;
2062 struct dcerpc_pipe *net_pipe;
2063 struct dcerpc_binding_handle *net_handle;
2065 bool result = false;
2067 struct netr_ServerReqChallenge r;
2068 struct netr_Credential netr_cli_creds;
2069 struct netr_Credential netr_srv_creds;
2070 uint32_t negotiate_flags;
2071 struct netr_ServerAuthenticate2 a;
2072 struct netlogon_creds_CredentialState *creds_state;
2073 struct netr_Credential netr_cred;
2074 struct samr_Password mach_pw;
2075 struct smbcli_state *cli;
2077 if (!(mem_ctx = talloc_new(torture))) {
2078 torture_comment(torture, "talloc_new failed\n");
2082 if (!(wksname = generate_random_str_list(
2083 mem_ctx, 14, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"))) {
2084 torture_comment(torture, "generate_random_str_list failed\n");
2088 if (!(torture_open_connection_share(
2090 torture, torture_setting_string(torture, "host", NULL),
2091 "IPC$", torture->ev))) {
2092 torture_comment(torture, "IPC$ connection failed\n");
2096 status = pipe_bind_smb(torture, mem_ctx, cli->tree, "\\netlogon",
2097 &ndr_table_netlogon, &net_pipe);
2098 torture_assert_ntstatus_ok_goto(torture, status, result, done,
2099 "pipe_bind_smb failed");
2100 net_handle = net_pipe->binding_handle;
2102 r.in.computer_name = wksname;
2103 r.in.server_name = talloc_asprintf(
2104 mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
2105 if (r.in.server_name == NULL) {
2106 torture_comment(torture, "talloc_asprintf failed\n");
2109 generate_random_buffer(netr_cli_creds.data,
2110 sizeof(netr_cli_creds.data));
2111 r.in.credentials = &netr_cli_creds;
2112 r.out.return_credentials = &netr_srv_creds;
2114 status = dcerpc_netr_ServerReqChallenge_r(net_handle, mem_ctx, &r);
2115 if (!NT_STATUS_IS_OK(status)) {
2116 torture_comment(torture, "netr_ServerReqChallenge failed: %s\n",
2120 if (!NT_STATUS_IS_OK(r.out.result)) {
2121 torture_comment(torture, "netr_ServerReqChallenge failed: %s\n",
2122 nt_errstr(r.out.result));
2126 negotiate_flags = NETLOGON_NEG_AUTH2_FLAGS;
2127 E_md4hash("foobar", mach_pw.hash);
2129 a.in.server_name = talloc_asprintf(
2130 mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
2131 a.in.account_name = talloc_asprintf(
2132 mem_ctx, "%s$", wksname);
2133 a.in.computer_name = wksname;
2134 a.in.secure_channel_type = SEC_CHAN_WKSTA;
2135 a.in.negotiate_flags = &negotiate_flags;
2136 a.out.negotiate_flags = &negotiate_flags;
2137 a.in.credentials = &netr_cred;
2138 a.out.return_credentials = &netr_cred;
2140 creds_state = netlogon_creds_client_init(mem_ctx,
2143 a.in.secure_channel_type,
2145 r.out.return_credentials, &mach_pw,
2146 &netr_cred, negotiate_flags);
2147 torture_assert(torture, (creds_state != NULL), "memory allocation failed");
2149 status = dcerpc_netr_ServerAuthenticate2_r(net_handle, mem_ctx, &a);
2150 if (!NT_STATUS_IS_OK(status)) {
2153 if (!NT_STATUS_EQUAL(a.out.result, NT_STATUS_NO_TRUST_SAM_ACCOUNT)) {
2154 torture_comment(torture, "dcerpc_netr_ServerAuthenticate2 returned %s, "
2155 "expected NT_STATUS_NO_TRUST_SAM_ACCOUNT\n",
2156 nt_errstr(a.out.result));
2162 talloc_free(mem_ctx);
2166 static struct security_descriptor *get_sharesec(struct torture_context *tctx,
2167 TALLOC_CTX *mem_ctx,
2168 struct smbcli_session *sess,
2169 const char *sharename)
2171 struct smbcli_tree *tree;
2172 TALLOC_CTX *tmp_ctx;
2173 struct dcerpc_pipe *p;
2174 struct dcerpc_binding_handle *b;
2176 struct srvsvc_NetShareGetInfo r;
2177 union srvsvc_NetShareInfo info;
2178 struct security_descriptor *result;
2180 if (!(tmp_ctx = talloc_new(mem_ctx))) {
2181 torture_comment(tctx, "talloc_new failed\n");
2185 if (!NT_STATUS_IS_OK(secondary_tcon(tctx, tmp_ctx, sess, "IPC$", &tree))) {
2186 torture_comment(tctx, "secondary_tcon failed\n");
2187 talloc_free(tmp_ctx);
2191 status = pipe_bind_smb(tctx, mem_ctx, tree, "\\pipe\\srvsvc",
2192 &ndr_table_srvsvc, &p);
2193 if (!NT_STATUS_IS_OK(status)) {
2194 torture_warning(tctx, "could not bind to srvsvc pipe: %s\n",
2196 talloc_free(tmp_ctx);
2199 b = p->binding_handle;
2202 p->conn->flags |= DCERPC_DEBUG_PRINT_IN | DCERPC_DEBUG_PRINT_OUT;
2205 r.in.server_unc = talloc_asprintf(tmp_ctx, "\\\\%s",
2206 dcerpc_server_name(p));
2207 r.in.share_name = sharename;
2211 status = dcerpc_srvsvc_NetShareGetInfo_r(b, tmp_ctx, &r);
2212 if (!NT_STATUS_IS_OK(status)) {
2213 torture_comment(tctx, "srvsvc_NetShareGetInfo failed: %s\n",
2215 talloc_free(tmp_ctx);
2218 if (!W_ERROR_IS_OK(r.out.result)) {
2219 torture_comment(tctx, "srvsvc_NetShareGetInfo failed: %s\n",
2220 win_errstr(r.out.result));
2221 talloc_free(tmp_ctx);
2225 result = talloc_steal(mem_ctx, info.info502->sd_buf.sd);
2226 talloc_free(tmp_ctx);
2230 static NTSTATUS set_sharesec(struct torture_context *tctx,
2231 TALLOC_CTX *mem_ctx,
2232 struct smbcli_session *sess,
2233 const char *sharename,
2234 struct security_descriptor *sd)
2236 struct smbcli_tree *tree;
2237 TALLOC_CTX *tmp_ctx;
2238 struct dcerpc_pipe *p;
2239 struct dcerpc_binding_handle *b;
2241 struct sec_desc_buf i;
2242 struct srvsvc_NetShareSetInfo r;
2243 union srvsvc_NetShareInfo info;
2246 if (!(tmp_ctx = talloc_new(mem_ctx))) {
2247 torture_comment(tctx, "talloc_new failed\n");
2248 return NT_STATUS_NO_MEMORY;
2251 if (!NT_STATUS_IS_OK(secondary_tcon(tctx, tmp_ctx, sess, "IPC$", &tree))) {
2252 torture_comment(tctx, "secondary_tcon failed\n");
2253 talloc_free(tmp_ctx);
2254 return NT_STATUS_UNSUCCESSFUL;
2257 status = pipe_bind_smb(tctx, mem_ctx, tree, "\\pipe\\srvsvc",
2258 &ndr_table_srvsvc, &p);
2259 if (!NT_STATUS_IS_OK(status)) {
2260 torture_warning(tctx, "could not bind to srvsvc pipe: %s\n",
2262 talloc_free(tmp_ctx);
2263 return NT_STATUS_UNSUCCESSFUL;
2265 b = p->binding_handle;
2268 p->conn->flags |= DCERPC_DEBUG_PRINT_IN | DCERPC_DEBUG_PRINT_OUT;
2271 r.in.server_unc = talloc_asprintf(tmp_ctx, "\\\\%s",
2272 dcerpc_server_name(p));
2273 r.in.share_name = sharename;
2278 r.in.parm_error = &error;
2280 status = dcerpc_srvsvc_NetShareSetInfo_r(b, tmp_ctx, &r);
2281 if (!NT_STATUS_IS_OK(status)) {
2282 torture_comment(tctx, "srvsvc_NetShareSetInfo failed: %s\n",
2285 if (!W_ERROR_IS_OK(r.out.result)) {
2286 torture_comment(tctx, "srvsvc_NetShareSetInfo failed: %s\n",
2287 win_errstr(r.out.result));
2288 status = werror_to_ntstatus(r.out.result);
2290 talloc_free(tmp_ctx);
2294 bool try_tcon(struct torture_context *tctx,
2295 TALLOC_CTX *mem_ctx,
2296 struct security_descriptor *orig_sd,
2297 struct smbcli_session *session,
2298 const char *sharename, const struct dom_sid *user_sid,
2299 unsigned int access_mask, NTSTATUS expected_tcon,
2300 NTSTATUS expected_mkdir)
2302 TALLOC_CTX *tmp_ctx;
2303 struct smbcli_tree *rmdir_tree, *tree;
2304 struct dom_sid *domain_sid;
2306 struct security_descriptor *sd;
2310 if (!(tmp_ctx = talloc_new(mem_ctx))) {
2311 torture_comment(tctx, "talloc_new failed\n");
2315 status = secondary_tcon(tctx, tmp_ctx, session, sharename, &rmdir_tree);
2316 if (!NT_STATUS_IS_OK(status)) {
2317 torture_comment(tctx, "first tcon to delete dir failed\n");
2318 talloc_free(tmp_ctx);
2322 smbcli_rmdir(rmdir_tree, "sharesec_testdir");
2324 if (!NT_STATUS_IS_OK(dom_sid_split_rid(tmp_ctx, user_sid,
2325 &domain_sid, &rid))) {
2326 torture_comment(tctx, "dom_sid_split_rid failed\n");
2327 talloc_free(tmp_ctx);
2331 sd = security_descriptor_dacl_create(
2332 tmp_ctx, 0, "S-1-5-32-544",
2333 dom_sid_string(mem_ctx, dom_sid_add_rid(mem_ctx, domain_sid,
2335 dom_sid_string(mem_ctx, user_sid),
2336 SEC_ACE_TYPE_ACCESS_ALLOWED, access_mask, 0, NULL);
2338 torture_comment(tctx, "security_descriptor_dacl_create failed\n");
2339 talloc_free(tmp_ctx);
2343 status = set_sharesec(tctx, mem_ctx, session, sharename, sd);
2344 if (!NT_STATUS_IS_OK(status)) {
2345 torture_comment(tctx, "custom set_sharesec failed: %s\n",
2347 talloc_free(tmp_ctx);
2351 status = secondary_tcon(tctx, tmp_ctx, session, sharename, &tree);
2352 if (!NT_STATUS_EQUAL(status, expected_tcon)) {
2353 torture_comment(tctx, "Expected %s, got %s\n", nt_errstr(expected_tcon),
2359 if (!NT_STATUS_IS_OK(status)) {
2360 /* An expected non-access, no point in trying to write */
2364 status = smbcli_mkdir(tree, "sharesec_testdir");
2365 if (!NT_STATUS_EQUAL(status, expected_mkdir)) {
2366 torture_warning(tctx, "Expected %s, got %s\n",
2367 nt_errstr(expected_mkdir), nt_errstr(status));
2372 smbcli_rmdir(rmdir_tree, "sharesec_testdir");
2374 status = set_sharesec(tctx, mem_ctx, session, sharename, orig_sd);
2375 if (!NT_STATUS_IS_OK(status)) {
2376 torture_comment(tctx, "custom set_sharesec failed: %s\n",
2378 talloc_free(tmp_ctx);
2382 talloc_free(tmp_ctx);
2386 static bool torture_samba3_rpc_sharesec(struct torture_context *torture)
2388 struct smbcli_state *cli = NULL;
2389 struct security_descriptor *sd = NULL;
2390 struct dom_sid *user_sid = NULL;
2391 const char *testuser_passwd = NULL;
2392 struct cli_credentials *test_credentials = NULL;
2393 struct smbcli_options options;
2394 struct smbcli_session_options session_options;
2396 struct test_join *tj = NULL;
2397 struct dcerpc_pipe *lsa_pipe = NULL;
2398 const char *priv_array[1];
2400 /* Create a new user. The normal user has SeBackup and SeRestore
2401 privs so we can't lock them out with a share security descriptor. */
2402 tj = torture_create_testuser(torture,
2404 torture_setting_string(torture, "workgroup", NULL),
2408 torture_fail(torture, "Creating sharesec_user failed\n");
2411 /* Give them SeDiskOperatorPrivilege but no other privs. */
2412 status = torture_rpc_connection(torture, &lsa_pipe, &ndr_table_lsarpc);
2413 if (!NT_STATUS_IS_OK(status)) {
2414 torture_delete_testuser(torture, tj, "sharesec_user");
2416 torture_fail(torture, "Error connecting to LSA pipe");
2419 priv_array[0] = "SeDiskOperatorPrivilege";
2420 if (!torture_setup_privs(torture,
2424 torture_join_user_sid(tj))) {
2425 talloc_free(lsa_pipe);
2426 torture_delete_testuser(torture, tj, "sharesec_user");
2428 torture_fail(torture, "Failed to setup privs\n");
2430 talloc_free(lsa_pipe);
2432 test_credentials = cli_credentials_init(torture);
2433 cli_credentials_set_workstation(test_credentials, "localhost", CRED_SPECIFIED);
2434 cli_credentials_set_domain(test_credentials, lpcfg_workgroup(torture->lp_ctx),
2436 cli_credentials_set_username(test_credentials, "sharesec_user", CRED_SPECIFIED);
2437 cli_credentials_set_password(test_credentials, testuser_passwd, CRED_SPECIFIED);
2439 ZERO_STRUCT(options);
2440 ZERO_STRUCT(session_options);
2441 lpcfg_smbcli_options(torture->lp_ctx, &options);
2442 lpcfg_smbcli_session_options(torture->lp_ctx, &session_options);
2444 status = smbcli_full_connection(torture,
2446 torture_setting_string(torture, "host", NULL),
2447 lpcfg_smb_ports(torture->lp_ctx),
2450 lpcfg_socket_options(torture->lp_ctx),
2452 lpcfg_resolve_context(torture->lp_ctx),
2456 lpcfg_gensec_settings(torture, torture->lp_ctx));
2457 if (!NT_STATUS_IS_OK(status)) {
2459 torture_delete_testuser(torture, tj, "sharesec_user");
2461 torture_fail(torture, "Failed to open connection\n");
2464 if (!(user_sid = whoami(torture, torture, cli->tree))) {
2466 torture_delete_testuser(torture, tj, "sharesec_user");
2468 torture_fail(torture, "whoami failed\n");
2471 sd = get_sharesec(torture, torture, cli->session,
2472 torture_setting_string(torture, "share", NULL));
2474 if (!try_tcon(torture, torture, sd, cli->session,
2475 torture_setting_string(torture, "share", NULL),
2476 user_sid, 0, NT_STATUS_ACCESS_DENIED, NT_STATUS_OK)) {
2478 torture_delete_testuser(torture, tj, "sharesec_user");
2480 torture_fail(torture, "failed to test tcon with 0 access_mask");
2483 if (!try_tcon(torture, torture, sd, cli->session,
2484 torture_setting_string(torture, "share", NULL),
2485 user_sid, SEC_FILE_READ_DATA, NT_STATUS_OK,
2486 NT_STATUS_MEDIA_WRITE_PROTECTED)) {
2488 torture_delete_testuser(torture, tj, "sharesec_user");
2490 torture_fail(torture, "failed to test tcon with SEC_FILE_READ_DATA access_mask");
2493 /* sharesec_user doesn't have any rights on the underlying file system.
2494 Go back to the normal user. */
2498 torture_delete_testuser(torture, tj, "sharesec_user");
2502 if (!(torture_open_connection_share(
2503 torture, &cli, torture, torture_setting_string(torture, "host", NULL),
2504 "IPC$", torture->ev))) {
2505 torture_fail(torture, "IPC$ connection failed\n");
2508 if (!(user_sid = whoami(torture, torture, cli->tree))) {
2509 torture_fail(torture, "whoami failed\n");
2511 torture_assert(torture, try_tcon(
2512 torture, torture, sd, cli->session,
2513 torture_setting_string(torture, "share", NULL),
2514 user_sid, SEC_FILE_ALL, NT_STATUS_OK, NT_STATUS_OK),
2515 "failed to test tcon with SEC_FILE_ALL access_mask")
2520 static bool torture_samba3_rpc_lsa(struct torture_context *torture)
2522 struct dcerpc_pipe *p;
2523 struct dcerpc_binding_handle *b;
2524 struct policy_handle lsa_handle;
2526 torture_assert_ntstatus_ok(torture,
2527 torture_rpc_connection(torture, &p, &ndr_table_lsarpc),
2528 "failed to setup lsarpc");
2530 b = p->binding_handle;
2533 struct lsa_ObjectAttribute attr;
2534 struct lsa_OpenPolicy2 o;
2535 o.in.system_name = talloc_asprintf(
2536 torture, "\\\\%s", dcerpc_server_name(p));
2539 o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2540 o.out.handle = &lsa_handle;
2542 torture_assert_ntstatus_ok(torture,
2543 dcerpc_lsa_OpenPolicy2_r(b, torture, &o),
2544 "dcerpc_lsa_OpenPolicy2 failed");
2545 torture_assert_ntstatus_ok(torture, o.out.result,
2546 "dcerpc_lsa_OpenPolicy2 failed");
2551 int levels[] = { 2,3,5,6 };
2553 for (i=0; i<ARRAY_SIZE(levels); i++) {
2554 struct lsa_QueryInfoPolicy r;
2555 union lsa_PolicyInformation *info = NULL;
2556 r.in.handle = &lsa_handle;
2557 r.in.level = levels[i];
2560 torture_assert_ntstatus_ok(torture,
2561 dcerpc_lsa_QueryInfoPolicy_r(b, torture, &r),
2562 talloc_asprintf(torture, "dcerpc_lsa_QueryInfoPolicy level %d failed", levels[i]));
2563 torture_assert_ntstatus_ok(torture, r.out.result,
2564 talloc_asprintf(torture, "dcerpc_lsa_QueryInfoPolicy level %d failed", levels[i]));
2571 static NTSTATUS get_servername(TALLOC_CTX *mem_ctx, struct smbcli_tree *tree,
2574 struct rap_WserverGetInfo r;
2576 char servername[17];
2577 size_t converted_size;
2580 r.in.bufsize = 0xffff;
2582 status = smbcli_rap_netservergetinfo(tree, mem_ctx, &r);
2583 if (!NT_STATUS_IS_OK(status)) {
2587 memcpy(servername, r.out.info.info0.name, 16);
2588 servername[16] = '\0';
2590 if (!pull_ascii_talloc(mem_ctx, name, servername, &converted_size)) {
2591 return NT_STATUS_NO_MEMORY;
2594 return NT_STATUS_OK;
2597 static bool rap_get_servername(struct torture_context *tctx,
2600 struct smbcli_state *cli;
2602 torture_assert(tctx,
2603 torture_open_connection_share(tctx, &cli, tctx, torture_setting_string(tctx, "host", NULL),
2605 "IPC$ connection failed");
2607 torture_assert_ntstatus_ok(tctx,
2608 get_servername(tctx, cli->tree, servername),
2609 "get_servername failed");
2616 static bool find_printers(struct torture_context *tctx,
2617 struct dcerpc_pipe *p,
2618 const char ***printers,
2619 size_t *num_printers)
2621 struct srvsvc_NetShareEnum r;
2622 struct srvsvc_NetShareInfoCtr info_ctr;
2623 struct srvsvc_NetShareCtr1 c1_in;
2624 struct srvsvc_NetShareCtr1 *c1;
2625 uint32_t totalentries = 0;
2627 struct dcerpc_binding_handle *b = p->binding_handle;
2631 info_ctr.ctr.ctr1 = &c1_in;
2633 r.in.server_unc = talloc_asprintf(
2634 tctx, "\\\\%s", dcerpc_server_name(p));
2635 r.in.info_ctr = &info_ctr;
2636 r.in.max_buffer = (uint32_t)-1;
2637 r.in.resume_handle = NULL;
2638 r.out.totalentries = &totalentries;
2639 r.out.info_ctr = &info_ctr;
2641 torture_assert_ntstatus_ok(tctx,
2642 dcerpc_srvsvc_NetShareEnum_r(b, tctx, &r),
2643 "NetShareEnum level 1 failed");
2644 torture_assert_werr_ok(tctx, r.out.result,
2645 "NetShareEnum level 1 failed");
2649 c1 = r.out.info_ctr->ctr.ctr1;
2650 for (i=0; i<c1->count; i++) {
2651 if (c1->array[i].type != STYPE_PRINTQ) {
2654 if (!add_string_to_array(tctx, c1->array[i].name,
2655 printers, num_printers)) {
2663 static bool enumprinters(struct torture_context *tctx,
2664 struct dcerpc_binding_handle *b,
2665 const char *servername, int level, int *num_printers)
2667 struct spoolss_EnumPrinters r;
2671 union spoolss_PrinterInfo *info;
2673 r.in.flags = PRINTER_ENUM_LOCAL;
2674 r.in.server = talloc_asprintf(tctx, "\\\\%s", servername);
2678 r.out.needed = &needed;
2679 r.out.count = &count;
2682 torture_assert_ntstatus_ok(tctx,
2683 dcerpc_spoolss_EnumPrinters_r(b, tctx, &r),
2684 "dcerpc_spoolss_EnumPrinters failed");
2685 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
2686 "EnumPrinters unexpected return code should be WERR_INSUFFICIENT_BUFFER");
2688 blob = data_blob_talloc_zero(tctx, needed);
2689 if (blob.data == NULL) {
2693 r.in.buffer = &blob;
2694 r.in.offered = needed;
2696 torture_assert_ntstatus_ok(tctx,
2697 dcerpc_spoolss_EnumPrinters_r(b, tctx, &r),
2698 "dcerpc_spoolss_EnumPrinters failed");
2699 torture_assert_werr_ok(tctx, r.out.result,
2700 "dcerpc_spoolss_EnumPrinters failed");
2702 *num_printers = count;
2707 static bool getprinterinfo(struct torture_context *tctx,
2708 struct dcerpc_binding_handle *b,
2709 struct policy_handle *handle, int level,
2710 union spoolss_PrinterInfo **res)
2712 struct spoolss_GetPrinter r;
2716 r.in.handle = handle;
2720 r.out.needed = &needed;
2722 torture_assert_ntstatus_ok(tctx,
2723 dcerpc_spoolss_GetPrinter_r(b, tctx, &r),
2724 "dcerpc_spoolss_GetPrinter failed");
2725 torture_assert_werr_equal(tctx, r.out.result, WERR_INSUFFICIENT_BUFFER,
2726 "GetPrinter unexpected return code should be WERR_INSUFFICIENT_BUFFER");
2728 r.in.handle = handle;
2730 blob = data_blob_talloc_zero(tctx, needed);
2731 if (blob.data == NULL) {
2734 r.in.buffer = &blob;
2735 r.in.offered = needed;
2737 torture_assert_ntstatus_ok(tctx,
2738 dcerpc_spoolss_GetPrinter_r(b, tctx, &r),
2739 "dcerpc_spoolss_GetPrinter failed");
2740 torture_assert_werr_ok(tctx, r.out.result,
2741 "dcerpc_spoolss_GetPrinter failed");
2744 *res = talloc_steal(tctx, r.out.info);
2750 static bool torture_samba3_rpc_spoolss(struct torture_context *torture)
2752 struct dcerpc_pipe *p, *p2;
2753 struct dcerpc_binding_handle *b;
2754 struct policy_handle server_handle, printer_handle;
2755 const char **printers;
2756 size_t num_printers;
2757 struct spoolss_UserLevel1 userlevel1;
2760 torture_assert(torture,
2761 rap_get_servername(torture, &servername),
2762 "failed to rap servername");
2764 torture_assert_ntstatus_ok(torture,
2765 torture_rpc_connection(torture, &p2, &ndr_table_srvsvc),
2766 "failed to setup srvsvc");
2768 torture_assert(torture,
2769 find_printers(torture, p2, &printers, &num_printers),
2770 "failed to find printers via srvsvc");
2774 if (num_printers == 0) {
2775 torture_skip(torture, "Did not find printers\n");
2779 torture_assert_ntstatus_ok(torture,
2780 torture_rpc_connection(torture, &p, &ndr_table_spoolss),
2781 "failed to setup spoolss");
2783 b = p->binding_handle;
2785 ZERO_STRUCT(userlevel1);
2786 userlevel1.client = talloc_asprintf(
2787 torture, "\\\\%s", lpcfg_netbios_name(torture->lp_ctx));
2788 userlevel1.user = cli_credentials_get_username(cmdline_credentials);
2789 userlevel1.build = 2600;
2790 userlevel1.major = 3;
2791 userlevel1.minor = 0;
2792 userlevel1.processor = 0;
2795 struct spoolss_OpenPrinterEx r;
2798 r.in.printername = talloc_asprintf(torture, "\\\\%s",
2800 r.in.datatype = NULL;
2801 r.in.access_mask = 0;
2802 r.in.userlevel_ctr.level = 1;
2803 r.in.userlevel_ctr.user_info.level1 = &userlevel1;
2804 r.out.handle = &server_handle;
2806 torture_assert_ntstatus_ok(torture,
2807 dcerpc_spoolss_OpenPrinterEx_r(b, torture, &r),
2808 "dcerpc_spoolss_OpenPrinterEx failed");
2809 torture_assert_werr_ok(torture, r.out.result,
2810 "dcerpc_spoolss_OpenPrinterEx failed");
2814 struct spoolss_ClosePrinter r;
2816 r.in.handle = &server_handle;
2817 r.out.handle = &server_handle;
2819 torture_assert_ntstatus_ok(torture,
2820 dcerpc_spoolss_ClosePrinter_r(b, torture, &r),
2821 "dcerpc_spoolss_ClosePrinter failed");
2822 torture_assert_werr_ok(torture, r.out.result,
2823 "dcerpc_spoolss_ClosePrinter failed");
2827 struct spoolss_OpenPrinterEx r;
2830 r.in.printername = talloc_asprintf(
2831 torture, "\\\\%s\\%s", servername, printers[0]);
2832 r.in.datatype = NULL;
2833 r.in.access_mask = 0;
2834 r.in.userlevel_ctr.level = 1;
2835 r.in.userlevel_ctr.user_info.level1 = &userlevel1;
2836 r.out.handle = &printer_handle;
2838 torture_assert_ntstatus_ok(torture,
2839 dcerpc_spoolss_OpenPrinterEx_r(b, torture, &r),
2840 "dcerpc_spoolss_OpenPrinterEx failed");
2841 torture_assert_werr_ok(torture, r.out.result,
2842 "dcerpc_spoolss_OpenPrinterEx failed");
2848 for (i=0; i<8; i++) {
2849 torture_assert(torture,
2850 getprinterinfo(torture, b, &printer_handle, i, NULL),
2851 talloc_asprintf(torture, "getprinterinfo %d failed", i));
2856 struct spoolss_ClosePrinter r;
2858 r.in.handle = &printer_handle;
2859 r.out.handle = &printer_handle;
2861 torture_assert_ntstatus_ok(torture,
2862 dcerpc_spoolss_ClosePrinter_r(b, torture, &r),
2863 "dcerpc_spoolss_ClosePrinter failed");
2864 torture_assert_werr_ok(torture, r.out.result,
2865 "dcerpc_spoolss_ClosePrinter failed");
2871 torture_assert(torture,
2872 enumprinters(torture, b, servername, 1, &num_enumerated),
2873 "enumprinters failed");
2875 torture_assert_int_equal(torture, num_printers, num_enumerated,
2876 "netshareenum / enumprinters lvl 1 numprinter mismatch");
2882 torture_assert(torture,
2883 enumprinters(torture, b, servername, 2, &num_enumerated),
2884 "enumprinters failed");
2886 torture_assert_int_equal(torture, num_printers, num_enumerated,
2887 "netshareenum / enumprinters lvl 2 numprinter mismatch");
2893 static bool torture_samba3_rpc_wkssvc(struct torture_context *torture)
2895 struct dcerpc_pipe *p;
2896 struct dcerpc_binding_handle *b;
2899 torture_assert(torture,
2900 rap_get_servername(torture, &servername),
2901 "failed to rap servername");
2903 torture_assert_ntstatus_ok(torture,
2904 torture_rpc_connection(torture, &p, &ndr_table_wkssvc),
2905 "failed to setup wkssvc");
2907 b = p->binding_handle;
2910 struct wkssvc_NetWkstaInfo100 wks100;
2911 union wkssvc_NetWkstaInfo info;
2912 struct wkssvc_NetWkstaGetInfo r;
2914 r.in.server_name = "\\foo";
2916 info.info100 = &wks100;
2919 torture_assert_ntstatus_ok(torture,
2920 dcerpc_wkssvc_NetWkstaGetInfo_r(b, torture, &r),
2921 "dcerpc_wkssvc_NetWksGetInfo failed");
2922 torture_assert_werr_ok(torture, r.out.result,
2923 "dcerpc_wkssvc_NetWksGetInfo failed");
2925 torture_assert_str_equal(torture, servername, r.out.info->info100->server_name,
2926 "servername RAP / DCERPC inconsistency");
2932 static bool winreg_close(struct torture_context *tctx,
2933 struct dcerpc_binding_handle *b,
2934 struct policy_handle *handle)
2936 struct winreg_CloseKey c;
2938 c.in.handle = c.out.handle = handle;
2940 torture_assert_ntstatus_ok(tctx,
2941 dcerpc_winreg_CloseKey_r(b, tctx, &c),
2942 "winreg_CloseKey failed");
2943 torture_assert_werr_ok(tctx, c.out.result,
2944 "winreg_CloseKey failed");
2949 static bool enumvalues(struct torture_context *tctx,
2950 struct dcerpc_binding_handle *b,
2951 struct policy_handle *handle)
2953 uint32_t enum_index = 0;
2956 struct winreg_EnumValue r;
2957 struct winreg_ValNameBuf name;
2958 enum winreg_Type type = 0;
2961 uint32_t size, length;
2964 r.in.handle = handle;
2965 r.in.enum_index = enum_index;
2968 r.in.name = r.out.name = &name;
2974 r.in.length = &length;
2976 status = dcerpc_winreg_EnumValue_r(b, tctx, &r);
2977 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
2984 static bool enumkeys(struct torture_context *tctx,
2985 struct dcerpc_binding_handle *b,
2986 struct policy_handle *handle,
2989 struct winreg_EnumKey r;
2990 struct winreg_StringBuf kclass, name;
3001 r.in.handle = handle;
3002 r.in.enum_index = 0;
3004 r.in.keyclass = &kclass;
3006 r.in.last_changed_time = &t;
3009 struct winreg_OpenKey o;
3010 struct policy_handle key_handle;
3016 status = dcerpc_winreg_EnumKey_r(b, tctx, &r);
3017 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
3018 /* We're done enumerating */
3022 for (i=0; i<10-depth; i++) {
3023 torture_comment(tctx, " ");
3025 torture_comment(tctx, "%s\n", r.out.name->name);
3027 o.in.parent_handle = handle;
3028 o.in.keyname.name = r.out.name->name;
3030 o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3031 o.out.handle = &key_handle;
3033 status = dcerpc_winreg_OpenKey_r(b, tctx, &o);
3034 if (NT_STATUS_IS_OK(status) && W_ERROR_IS_OK(o.out.result)) {
3035 enumkeys(tctx, b, &key_handle, depth-1);
3036 enumvalues(tctx, b, &key_handle);
3037 torture_assert(tctx, winreg_close(tctx, b, &key_handle), "");
3040 r.in.enum_index += 1;
3046 typedef NTSTATUS (*winreg_open_fn)(struct dcerpc_binding_handle *, TALLOC_CTX *, void *);
3048 static bool test_Open3(struct torture_context *tctx,
3049 struct dcerpc_binding_handle *b,
3050 const char *name, winreg_open_fn open_fn)
3052 struct policy_handle handle;
3053 struct winreg_OpenHKLM r;
3055 r.in.system_name = 0;
3056 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3057 r.out.handle = &handle;
3059 torture_assert_ntstatus_ok(tctx,
3060 open_fn(b, tctx, &r),
3061 talloc_asprintf(tctx, "%s failed", name));
3062 torture_assert_werr_ok(tctx, r.out.result,
3063 talloc_asprintf(tctx, "%s failed", name));
3065 enumkeys(tctx, b, &handle, 4);
3067 torture_assert(tctx,
3068 winreg_close(tctx, b, &handle),
3069 "dcerpc_CloseKey failed");
3074 static bool torture_samba3_rpc_winreg(struct torture_context *torture)
3076 struct dcerpc_pipe *p;
3077 struct dcerpc_binding_handle *b;
3083 {"OpenHKLM", (winreg_open_fn)dcerpc_winreg_OpenHKLM_r },
3084 {"OpenHKU", (winreg_open_fn)dcerpc_winreg_OpenHKU_r },
3085 {"OpenHKPD", (winreg_open_fn)dcerpc_winreg_OpenHKPD_r },
3086 {"OpenHKPT", (winreg_open_fn)dcerpc_winreg_OpenHKPT_r },
3087 {"OpenHKCR", (winreg_open_fn)dcerpc_winreg_OpenHKCR_r }};
3092 torture_assert_ntstatus_ok(torture,
3093 torture_rpc_connection(torture, &p, &ndr_table_winreg),
3094 "failed to setup winreg");
3096 b = p->binding_handle;
3099 ret = test_Open3(torture, b, open_fns[0].name, open_fns[0].fn);
3101 for (i = 0; i < ARRAY_SIZE(open_fns); i++) {
3102 if (!test_Open3(torture, b, open_fns[i].name, open_fns[i].fn))
3109 static bool get_shareinfo(struct torture_context *tctx,
3110 struct dcerpc_binding_handle *b,
3111 const char *servername,
3113 struct srvsvc_NetShareInfo502 **info502)
3115 struct srvsvc_NetShareGetInfo r;
3116 union srvsvc_NetShareInfo info;
3118 r.in.server_unc = talloc_asprintf(tctx, "\\\\%s", servername);
3119 r.in.share_name = share;
3123 torture_assert_ntstatus_ok(tctx,
3124 dcerpc_srvsvc_NetShareGetInfo_r(b, tctx, &r),
3125 "srvsvc_NetShareGetInfo failed");
3126 torture_assert_werr_ok(tctx, r.out.result,
3127 "srvsvc_NetShareGetInfo failed");
3129 *info502 = talloc_move(tctx, &info.info502);
3135 * Get us a handle on HKLM\
3138 static bool get_hklm_handle(struct torture_context *tctx,
3139 struct dcerpc_binding_handle *b,
3140 struct policy_handle *handle)
3142 struct winreg_OpenHKLM r;
3143 struct policy_handle result;
3145 r.in.system_name = 0;
3146 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3147 r.out.handle = &result;
3149 torture_assert_ntstatus_ok(tctx,
3150 dcerpc_winreg_OpenHKLM_r(b, tctx, &r),
3152 torture_assert_werr_ok(tctx, r.out.result,
3160 static bool torture_samba3_createshare(struct torture_context *tctx,
3161 struct dcerpc_binding_handle *b,
3162 const char *sharename)
3164 struct policy_handle hklm;
3165 struct policy_handle new_handle;
3166 struct winreg_CreateKey c;
3167 struct winreg_CloseKey cl;
3168 enum winreg_CreateAction action_taken = REG_ACTION_NONE;
3173 ZERO_STRUCT(new_handle);
3175 c.in.handle = &hklm;
3176 c.in.name.name = talloc_asprintf(
3177 tctx, "software\\samba\\smbconf\\%s", sharename);
3178 torture_assert(tctx, c.in.name.name, "talloc_asprintf failed");
3180 c.in.keyclass.name = "";
3182 c.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3183 c.in.secdesc = NULL;
3184 c.in.action_taken = &action_taken;
3185 c.out.new_handle = &new_handle;
3186 c.out.action_taken = &action_taken;
3188 torture_assert_ntstatus_ok(tctx,
3189 dcerpc_winreg_CreateKey_r(b, tctx, &c),
3191 torture_assert_werr_ok(tctx, c.out.result,
3194 cl.in.handle = &new_handle;
3195 cl.out.handle = &new_handle;
3197 torture_assert_ntstatus_ok(tctx,
3198 dcerpc_winreg_CloseKey_r(b, tctx, &cl),
3200 torture_assert_werr_ok(tctx, cl.out.result,
3206 static bool torture_samba3_deleteshare(struct torture_context *tctx,
3207 struct dcerpc_binding_handle *b,
3208 const char *sharename)
3210 struct policy_handle hklm;
3211 struct winreg_DeleteKey d;
3213 torture_assert(tctx,
3214 get_hklm_handle(tctx, b, &hklm),
3215 "get_hklm_handle failed");
3217 d.in.handle = &hklm;
3218 d.in.key.name = talloc_asprintf(
3219 tctx, "software\\samba\\smbconf\\%s", sharename);
3220 torture_assert(tctx, d.in.key.name, "talloc_asprintf failed");
3222 torture_assert_ntstatus_ok(tctx,
3223 dcerpc_winreg_DeleteKey_r(b, tctx, &d),
3224 "DeleteKey failed");
3225 torture_assert_werr_ok(tctx, d.out.result,
3226 "DeleteKey failed");
3231 static bool torture_samba3_setconfig(struct torture_context *tctx,
3232 struct dcerpc_binding_handle *b,
3233 const char *sharename,
3234 const char *parameter,
3237 struct policy_handle hklm, key_handle;
3238 struct winreg_OpenKey o;
3239 struct winreg_SetValue s;
3243 torture_assert(tctx,
3244 get_hklm_handle(tctx, b, &hklm),
3245 "get_hklm_handle failed");
3247 o.in.parent_handle = &hklm;
3248 o.in.keyname.name = talloc_asprintf(
3249 tctx, "software\\samba\\smbconf\\%s", sharename);
3250 torture_assert(tctx, o.in.keyname.name, "talloc_asprintf failed");
3253 o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3254 o.out.handle = &key_handle;
3256 torture_assert_ntstatus_ok(tctx,
3257 dcerpc_winreg_OpenKey_r(b, tctx, &o),
3259 torture_assert_werr_ok(tctx, o.out.result,
3262 torture_assert(tctx,
3263 reg_string_to_val(tctx, "REG_SZ", value, &type, &val),
3264 "reg_string_to_val failed");
3266 s.in.handle = &key_handle;
3267 s.in.name.name = parameter;
3269 s.in.data = val.data;
3270 s.in.size = val.length;
3272 torture_assert_ntstatus_ok(tctx,
3273 dcerpc_winreg_SetValue_r(b, tctx, &s),
3275 torture_assert_werr_ok(tctx, s.out.result,
3281 static bool torture_samba3_regconfig(struct torture_context *torture)
3283 struct srvsvc_NetShareInfo502 *i = NULL;
3284 const char *comment = "Dummer Kommentar";
3285 struct dcerpc_pipe *srvsvc_pipe, *winreg_pipe;
3287 torture_assert_ntstatus_ok(torture,
3288 torture_rpc_connection(torture, &srvsvc_pipe, &ndr_table_srvsvc),
3289 "failed to setup srvsvc");
3291 torture_assert_ntstatus_ok(torture,
3292 torture_rpc_connection(torture, &winreg_pipe, &ndr_table_winreg),
3293 "failed to setup winreg");
3295 torture_assert(torture,
3296 torture_samba3_createshare(torture, winreg_pipe->binding_handle, "blubber"),
3297 "torture_samba3_createshare failed");
3299 torture_assert(torture,
3300 torture_samba3_setconfig(torture, winreg_pipe->binding_handle, "blubber", "comment", comment),
3301 "torture_samba3_setconfig failed");
3303 torture_assert(torture,
3304 get_shareinfo(torture, srvsvc_pipe->binding_handle, dcerpc_server_name(srvsvc_pipe), "blubber", &i),
3305 "get_shareinfo failed");
3307 torture_assert_str_equal(torture, comment, i->comment,
3308 "got unexpected comment");
3310 torture_assert(torture,
3311 torture_samba3_deleteshare(torture, winreg_pipe->binding_handle, "blubber"),
3312 "torture_samba3_deleteshare failed");
3318 * Test that even with a result of 0 rids the array is returned as a
3319 * non-NULL pointer. Yes, XP does notice.
3322 bool torture_samba3_getaliasmembership_0(struct torture_context *torture)
3324 struct dcerpc_pipe *p;
3325 struct dcerpc_binding_handle *b;
3326 struct samr_Connect2 c;
3327 struct samr_OpenDomain o;
3329 struct lsa_SidPtr ptr;
3330 struct lsa_SidArray sids;
3331 struct samr_GetAliasMembership g;
3332 struct samr_Ids rids;
3333 struct policy_handle samr, domain;
3335 torture_assert_ntstatus_ok(torture,
3336 torture_rpc_connection(torture, &p, &ndr_table_samr),
3337 "failed to setup samr");
3339 b = p->binding_handle;
3341 c.in.system_name = NULL;
3342 c.in.access_mask = SAMR_ACCESS_LOOKUP_DOMAIN;
3343 c.out.connect_handle = &samr;
3344 torture_assert_ntstatus_ok(torture,
3345 dcerpc_samr_Connect2_r(b, torture, &c),
3347 torture_assert_ntstatus_ok(torture, c.out.result,
3349 dom_sid_parse("S-1-5-32", &sid);
3350 o.in.connect_handle = &samr;
3351 o.in.access_mask = SAMR_DOMAIN_ACCESS_LOOKUP_ALIAS;
3353 o.out.domain_handle = &domain;
3354 torture_assert_ntstatus_ok(torture,
3355 dcerpc_samr_OpenDomain_r(b, torture, &o),
3357 torture_assert_ntstatus_ok(torture, o.out.result,
3359 dom_sid_parse("S-1-2-3-4-5", &sid);
3363 g.in.domain_handle = &domain;
3366 torture_assert_ntstatus_ok(torture,
3367 dcerpc_samr_GetAliasMembership_r(b, torture, &g),
3369 torture_assert_ntstatus_ok(torture, g.out.result,
3371 if (rids.ids == NULL) {
3372 /* This is the piece to test here */
3373 torture_fail(torture,
3374 "torture_samba3_getaliasmembership_0: "
3375 "Server returns NULL rids array\n");
3382 * Test smb reauthentication while rpc pipe is in use.
3384 static bool torture_rpc_smb_reauth1(struct torture_context *torture)
3386 TALLOC_CTX *mem_ctx;
3389 struct smbcli_state *cli;
3390 struct smbcli_options options;
3391 struct smbcli_session_options session_options;
3393 struct dcerpc_pipe *lsa_pipe;
3394 struct dcerpc_binding_handle *lsa_handle;
3395 struct lsa_GetUserName r;
3396 struct lsa_String *authority_name_p = NULL;
3397 char *authority_name_saved = NULL;
3398 struct lsa_String *account_name_p = NULL;
3399 char *account_name_saved = NULL;
3400 struct cli_credentials *anon_creds = NULL;
3401 struct smb_composite_sesssetup io;
3403 mem_ctx = talloc_init("torture_samba3_reauth");
3404 torture_assert(torture, (mem_ctx != NULL), "talloc_init failed");
3406 lpcfg_smbcli_options(torture->lp_ctx, &options);
3407 lpcfg_smbcli_session_options(torture->lp_ctx, &session_options);
3409 status = smbcli_full_connection(mem_ctx, &cli,
3410 torture_setting_string(torture, "host", NULL),
3411 lpcfg_smb_ports(torture->lp_ctx),
3413 lpcfg_socket_options(torture->lp_ctx),
3414 cmdline_credentials,
3415 lpcfg_resolve_context(torture->lp_ctx),
3416 torture->ev, &options, &session_options,
3417 lpcfg_gensec_settings(torture, torture->lp_ctx));
3418 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3419 "smbcli_full_connection failed");
3421 status = pipe_bind_smb(torture, mem_ctx, cli->tree, "\\lsarpc",
3422 &ndr_table_lsarpc, &lsa_pipe);
3423 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3424 "pipe_bind_smb failed");
3425 lsa_handle = lsa_pipe->binding_handle;
3427 /* lsa getusername */
3430 r.in.system_name = "\\";
3431 r.in.account_name = &account_name_p;
3432 r.in.authority_name = &authority_name_p;
3433 r.out.account_name = &account_name_p;
3435 status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r);
3437 authority_name_p = *r.out.authority_name;
3439 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3440 "GetUserName failed");
3441 torture_assert_ntstatus_ok_goto(torture, r.out.result, ret, done,
3442 "GetUserName failed");
3444 torture_comment(torture, "lsa_GetUserName gave '%s\\%s'\n",
3445 authority_name_p->string,
3446 account_name_p->string);
3448 account_name_saved = talloc_strdup(mem_ctx, account_name_p->string);
3449 torture_assert_goto(torture, (account_name_saved != NULL), ret, done,
3451 authority_name_saved = talloc_strdup(mem_ctx, authority_name_p->string);
3452 torture_assert_goto(torture, (authority_name_saved != NULL), ret, done,
3455 /* smb re-authenticate as anonymous */
3457 anon_creds = cli_credentials_init_anon(mem_ctx);
3460 io.in.sesskey = cli->transport->negotiate.sesskey;
3461 io.in.capabilities = cli->transport->negotiate.capabilities;
3462 io.in.credentials = anon_creds;
3463 io.in.workgroup = lpcfg_workgroup(torture->lp_ctx);
3464 io.in.gensec_settings = lpcfg_gensec_settings(torture, torture->lp_ctx);
3466 status = smb_composite_sesssetup(cli->session, &io);
3467 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3468 "session reauth to anon failed");
3470 /* re-do lsa getusername after reauth */
3472 TALLOC_FREE(authority_name_p);
3473 TALLOC_FREE(account_name_p);
3475 r.in.system_name = "\\";
3476 r.in.account_name = &account_name_p;
3477 r.in.authority_name = &authority_name_p;
3478 r.out.account_name = &account_name_p;
3480 status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r);
3482 authority_name_p = *r.out.authority_name;
3484 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3485 "GetUserName failed");
3486 torture_assert_ntstatus_ok_goto(torture, r.out.result, ret, done,
3487 "GetUserName failed");
3489 torture_assert_goto(torture, (strcmp(authority_name_p->string, authority_name_saved) == 0),
3490 ret, done, "authority_name not equal after reauth to anon");
3491 torture_assert_goto(torture, (strcmp(account_name_p->string, account_name_saved) == 0),
3492 ret, done, "account_name not equal after reauth to anon");
3494 /* smb re-auth again to the original user */
3497 io.in.sesskey = cli->transport->negotiate.sesskey;
3498 io.in.capabilities = cli->transport->negotiate.capabilities;
3499 io.in.credentials = cmdline_credentials;
3500 io.in.workgroup = lpcfg_workgroup(torture->lp_ctx);
3501 io.in.gensec_settings = lpcfg_gensec_settings(torture, torture->lp_ctx);
3503 status = smb_composite_sesssetup(cli->session, &io);
3504 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3505 "session reauth to anon failed");
3507 /* re-do lsa getusername */
3509 TALLOC_FREE(authority_name_p);
3510 TALLOC_FREE(account_name_p);
3512 r.in.system_name = "\\";
3513 r.in.account_name = &account_name_p;
3514 r.in.authority_name = &authority_name_p;
3515 r.out.account_name = &account_name_p;
3517 status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r);
3519 authority_name_p = *r.out.authority_name;
3521 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3522 "GetUserName failed");
3523 torture_assert_ntstatus_ok_goto(torture, r.out.result, ret, done,
3524 "GetUserName failed");
3526 torture_assert_goto(torture, (strcmp(authority_name_p->string, authority_name_saved) == 0),
3527 ret, done, "authority_name not equal after reauth to anon");
3528 torture_assert_goto(torture, (strcmp(account_name_p->string, account_name_saved) == 0),
3529 ret, done, "account_name not equal after reauth to anon");
3534 talloc_free(mem_ctx);
3539 * Test smb reauthentication while rpc pipe is in use.
3540 * Open a second lsa bind after reauth to anon.
3541 * Do lsa getusername on that second bind.
3543 static bool torture_rpc_smb_reauth2(struct torture_context *torture)
3545 TALLOC_CTX *mem_ctx;
3548 struct smbcli_state *cli;
3549 struct smbcli_options options;
3550 struct smbcli_session_options session_options;
3552 struct dcerpc_pipe *lsa_pipe;
3553 struct dcerpc_binding_handle *lsa_handle;
3554 struct lsa_GetUserName r;
3555 struct lsa_String *authority_name_p = NULL;
3556 char *authority_name_saved = NULL;
3557 struct lsa_String *account_name_p = NULL;
3558 char *account_name_saved = NULL;
3559 struct cli_credentials *anon_creds = NULL;
3560 struct smb_composite_sesssetup io;
3562 mem_ctx = talloc_init("torture_samba3_reauth");
3563 torture_assert(torture, (mem_ctx != NULL), "talloc_init failed");
3565 lpcfg_smbcli_options(torture->lp_ctx, &options);
3566 lpcfg_smbcli_session_options(torture->lp_ctx, &session_options);
3568 status = smbcli_full_connection(mem_ctx, &cli,
3569 torture_setting_string(torture, "host", NULL),
3570 lpcfg_smb_ports(torture->lp_ctx),
3572 lpcfg_socket_options(torture->lp_ctx),
3573 cmdline_credentials,
3574 lpcfg_resolve_context(torture->lp_ctx),
3575 torture->ev, &options, &session_options,
3576 lpcfg_gensec_settings(torture, torture->lp_ctx));
3577 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3578 "smbcli_full_connection failed");
3580 /* smb re-authenticate as anonymous */
3582 anon_creds = cli_credentials_init_anon(mem_ctx);
3585 io.in.sesskey = cli->transport->negotiate.sesskey;
3586 io.in.capabilities = cli->transport->negotiate.capabilities;
3587 io.in.credentials = anon_creds;
3588 io.in.workgroup = lpcfg_workgroup(torture->lp_ctx);
3589 io.in.gensec_settings = lpcfg_gensec_settings(torture, torture->lp_ctx);
3591 status = smb_composite_sesssetup(cli->session, &io);
3592 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3593 "session reauth to anon failed");
3595 /* open the lsa pipe */
3597 status = pipe_bind_smb(torture, mem_ctx, cli->tree, "\\lsarpc",
3598 &ndr_table_lsarpc, &lsa_pipe);
3599 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3600 "pipe_bind_smb failed");
3601 lsa_handle = lsa_pipe->binding_handle;
3603 /* lsa getusername */
3606 r.in.system_name = "\\";
3607 r.in.account_name = &account_name_p;
3608 r.in.authority_name = &authority_name_p;
3609 r.out.account_name = &account_name_p;
3611 status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r);
3613 authority_name_p = *r.out.authority_name;
3615 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3616 "GetUserName failed");
3617 torture_assert_ntstatus_ok_goto(torture, r.out.result, ret, done,
3618 "GetUserName failed");
3620 torture_comment(torture, "lsa_GetUserName gave '%s\\%s'\n",
3621 authority_name_p->string,
3622 account_name_p->string);
3624 account_name_saved = talloc_strdup(mem_ctx, account_name_p->string);
3625 torture_assert_goto(torture, (account_name_saved != NULL), ret, done,
3627 authority_name_saved = talloc_strdup(mem_ctx, authority_name_p->string);
3628 torture_assert_goto(torture, (authority_name_saved != NULL), ret, done,
3631 /* smb re-auth again to the original user */
3634 io.in.sesskey = cli->transport->negotiate.sesskey;
3635 io.in.capabilities = cli->transport->negotiate.capabilities;
3636 io.in.credentials = cmdline_credentials;
3637 io.in.workgroup = lpcfg_workgroup(torture->lp_ctx);
3638 io.in.gensec_settings = lpcfg_gensec_settings(torture, torture->lp_ctx);
3640 status = smb_composite_sesssetup(cli->session, &io);
3641 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3642 "session reauth to anon failed");
3644 /* re-do lsa getusername after reauth */
3646 TALLOC_FREE(authority_name_p);
3647 TALLOC_FREE(account_name_p);
3649 r.in.system_name = "\\";
3650 r.in.account_name = &account_name_p;
3651 r.in.authority_name = &authority_name_p;
3652 r.out.account_name = &account_name_p;
3654 status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r);
3656 authority_name_p = *r.out.authority_name;
3658 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3659 "GetUserName failed");
3660 torture_assert_ntstatus_ok_goto(torture, r.out.result, ret, done,
3661 "GetUserName failed");
3663 torture_assert_goto(torture, (strcmp(authority_name_p->string, authority_name_saved) == 0),
3664 ret, done, "authority_name not equal after reauth to anon");
3665 torture_assert_goto(torture, (strcmp(account_name_p->string, account_name_saved) == 0),
3666 ret, done, "account_name not equal after reauth to anon");
3671 talloc_free(mem_ctx);
3676 * Test smb2 reauthentication while rpc pipe is in use.
3678 static bool torture_rpc_smb2_reauth1(struct torture_context *torture)
3680 TALLOC_CTX *mem_ctx;
3683 struct smbcli_options options;
3685 struct dcerpc_pipe *lsa_pipe;
3686 struct dcerpc_binding_handle *lsa_handle;
3687 struct lsa_GetUserName r;
3688 struct lsa_String *authority_name_p = NULL;
3689 char *authority_name_saved = NULL;
3690 struct lsa_String *account_name_p = NULL;
3691 char *account_name_saved = NULL;
3692 struct cli_credentials *anon_creds = NULL;
3693 const char *host = torture_setting_string(torture, "host", NULL);
3694 struct smb2_tree *tree;
3696 mem_ctx = talloc_init("torture_samba3_reauth");
3697 torture_assert(torture, (mem_ctx != NULL), "talloc_init failed");
3699 lpcfg_smbcli_options(torture->lp_ctx, &options);
3701 status = smb2_connect(mem_ctx,
3703 lpcfg_smb_ports(torture->lp_ctx),
3705 lpcfg_resolve_context(torture->lp_ctx),
3706 cmdline_credentials,
3710 lpcfg_socket_options(torture->lp_ctx),
3711 lpcfg_gensec_settings(torture, torture->lp_ctx)
3713 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3714 "smb2_connect failed");
3716 status = pipe_bind_smb2(torture, mem_ctx, tree, "lsarpc",
3717 &ndr_table_lsarpc, &lsa_pipe);
3718 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3719 "pipe_bind_smb2 failed");
3720 lsa_handle = lsa_pipe->binding_handle;
3722 /* lsa getusername */
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_comment(torture, "lsa_GetUserName gave '%s\\%s'\n",
3740 authority_name_p->string,
3741 account_name_p->string);
3743 account_name_saved = talloc_strdup(mem_ctx, account_name_p->string);
3744 torture_assert_goto(torture, (account_name_saved != NULL), ret, done,
3746 authority_name_saved = talloc_strdup(mem_ctx, authority_name_p->string);
3747 torture_assert_goto(torture, (authority_name_saved != NULL), ret, done,
3750 /* smb re-authenticate as anonymous */
3752 anon_creds = cli_credentials_init_anon(mem_ctx);
3754 status = smb2_session_setup_spnego(tree->session,
3756 0 /* previous_session_id */);
3757 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3758 "session reauth to anon failed");
3760 /* re-do lsa getusername after reauth */
3762 TALLOC_FREE(authority_name_p);
3763 TALLOC_FREE(account_name_p);
3765 r.in.system_name = "\\";
3766 r.in.account_name = &account_name_p;
3767 r.in.authority_name = &authority_name_p;
3768 r.out.account_name = &account_name_p;
3770 status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r);
3772 authority_name_p = *r.out.authority_name;
3774 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3775 "GetUserName failed");
3776 torture_assert_ntstatus_ok_goto(torture, r.out.result, ret, done,
3777 "GetUserName failed");
3779 torture_assert_goto(torture, (strcmp(authority_name_p->string, authority_name_saved) == 0),
3780 ret, done, "authority_name not equal after reauth to anon");
3781 torture_assert_goto(torture, (strcmp(account_name_p->string, account_name_saved) == 0),
3782 ret, done, "account_name not equal after reauth to anon");
3784 /* smb re-auth again to the original user */
3786 status = smb2_session_setup_spnego(tree->session,
3787 cmdline_credentials,
3788 0 /* previous_session_id */);
3789 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3790 "session reauth to anon failed");
3792 /* re-do lsa getusername */
3794 TALLOC_FREE(authority_name_p);
3795 TALLOC_FREE(account_name_p);
3797 r.in.system_name = "\\";
3798 r.in.account_name = &account_name_p;
3799 r.in.authority_name = &authority_name_p;
3800 r.out.account_name = &account_name_p;
3802 status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r);
3804 authority_name_p = *r.out.authority_name;
3806 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3807 "GetUserName failed");
3808 torture_assert_ntstatus_ok_goto(torture, r.out.result, ret, done,
3809 "GetUserName failed");
3811 torture_assert_goto(torture, (strcmp(authority_name_p->string, authority_name_saved) == 0),
3812 ret, done, "authority_name not equal after reauth to anon");
3813 torture_assert_goto(torture, (strcmp(account_name_p->string, account_name_saved) == 0),
3814 ret, done, "account_name not equal after reauth to anon");
3819 talloc_free(mem_ctx);
3824 * Test smb2 reauthentication while rpc pipe is in use.
3825 * Open a second lsa bind after reauth to anon.
3826 * Do lsa getusername on that second bind.
3828 static bool torture_rpc_smb2_reauth2(struct torture_context *torture)
3830 TALLOC_CTX *mem_ctx;
3833 struct smbcli_options options;
3835 struct dcerpc_pipe *lsa_pipe;
3836 struct dcerpc_binding_handle *lsa_handle;
3837 struct lsa_GetUserName r;
3838 struct lsa_String *authority_name_p = NULL;
3839 char *authority_name_saved = NULL;
3840 struct lsa_String *account_name_p = NULL;
3841 char *account_name_saved = NULL;
3842 struct cli_credentials *anon_creds = NULL;
3843 const char *host = torture_setting_string(torture, "host", NULL);
3844 struct smb2_tree *tree;
3846 mem_ctx = talloc_init("torture_samba3_reauth");
3847 torture_assert(torture, (mem_ctx != NULL), "talloc_init failed");
3849 lpcfg_smbcli_options(torture->lp_ctx, &options);
3851 status = smb2_connect(mem_ctx,
3853 lpcfg_smb_ports(torture->lp_ctx),
3855 lpcfg_resolve_context(torture->lp_ctx),
3856 cmdline_credentials,
3860 lpcfg_socket_options(torture->lp_ctx),
3861 lpcfg_gensec_settings(torture, torture->lp_ctx)
3863 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3864 "smb2_connect failed");
3866 /* smb re-authenticate as anonymous */
3868 anon_creds = cli_credentials_init_anon(mem_ctx);
3870 status = smb2_session_setup_spnego(tree->session,
3872 0 /* previous_session_id */);
3873 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3874 "session reauth to anon failed");
3876 /* open the lsa pipe */
3878 status = pipe_bind_smb2(torture, mem_ctx, tree, "lsarpc",
3879 &ndr_table_lsarpc, &lsa_pipe);
3880 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3881 "pipe_bind_smb2 failed");
3882 lsa_handle = lsa_pipe->binding_handle;
3884 /* lsa getusername */
3887 r.in.system_name = "\\";
3888 r.in.account_name = &account_name_p;
3889 r.in.authority_name = &authority_name_p;
3890 r.out.account_name = &account_name_p;
3892 status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r);
3894 authority_name_p = *r.out.authority_name;
3896 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3897 "GetUserName failed");
3898 torture_assert_ntstatus_ok_goto(torture, r.out.result, ret, done,
3899 "GetUserName failed");
3901 torture_comment(torture, "lsa_GetUserName gave '%s\\%s'\n",
3902 authority_name_p->string,
3903 account_name_p->string);
3905 account_name_saved = talloc_strdup(mem_ctx, account_name_p->string);
3906 torture_assert_goto(torture, (account_name_saved != NULL), ret, done,
3908 authority_name_saved = talloc_strdup(mem_ctx, authority_name_p->string);
3909 torture_assert_goto(torture, (authority_name_saved != NULL), ret, done,
3912 /* smb re-auth again to the original user */
3914 status = smb2_session_setup_spnego(tree->session,
3915 cmdline_credentials,
3916 0 /* previous_session_id */);
3917 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3918 "session reauth to anon failed");
3920 /* re-do lsa getusername */
3922 TALLOC_FREE(authority_name_p);
3923 TALLOC_FREE(account_name_p);
3925 r.in.system_name = "\\";
3926 r.in.account_name = &account_name_p;
3927 r.in.authority_name = &authority_name_p;
3928 r.out.account_name = &account_name_p;
3930 status = dcerpc_lsa_GetUserName_r(lsa_handle, mem_ctx, &r);
3932 authority_name_p = *r.out.authority_name;
3934 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3935 "GetUserName failed");
3936 torture_assert_ntstatus_ok_goto(torture, r.out.result, ret, done,
3937 "GetUserName failed");
3939 torture_assert_goto(torture, (strcmp(authority_name_p->string, authority_name_saved) == 0),
3940 ret, done, "authority_name not equal after reauth to anon");
3941 torture_assert_goto(torture, (strcmp(account_name_p->string, account_name_saved) == 0),
3942 ret, done, "account_name not equal after reauth to anon");
3947 talloc_free(mem_ctx);
3951 static bool torture_rpc_smb1_pipe_name(struct torture_context *torture)
3953 TALLOC_CTX *mem_ctx;
3956 struct smbcli_state *cli;
3957 struct smbcli_options options;
3958 struct smbcli_session_options session_options;
3963 mem_ctx = talloc_init("torture_samba3_smb1_pipe_name");
3964 torture_assert(torture, (mem_ctx != NULL), "talloc_init failed");
3966 lpcfg_smbcli_options(torture->lp_ctx, &options);
3967 lpcfg_smbcli_session_options(torture->lp_ctx, &session_options);
3969 status = smbcli_full_connection(mem_ctx, &cli,
3970 torture_setting_string(torture, "host", NULL),
3971 lpcfg_smb_ports(torture->lp_ctx),
3973 lpcfg_socket_options(torture->lp_ctx),
3974 cmdline_credentials,
3975 lpcfg_resolve_context(torture->lp_ctx),
3976 torture->ev, &options, &session_options,
3977 lpcfg_gensec_settings(torture, torture->lp_ctx));
3978 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
3979 "smbcli_full_connection failed");
3982 io.generic.level = RAW_OPEN_NTCREATEX;
3983 io.ntcreatex.in.access_mask = DESIRED_ACCESS_PIPE;
3984 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ|
3985 NTCREATEX_SHARE_ACCESS_WRITE;
3986 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
3987 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_IMPERSONATION;
3988 io.ntcreatex.in.security_flags = 0;
3990 io.ntcreatex.in.fname = "__none__";
3991 status = smb_raw_open(cli->tree, torture, &io);
3992 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_NAME_NOT_FOUND,
3994 "smb_raw_open for '__none__'");
3996 io.ntcreatex.in.fname = "pipe\\srvsvc";
3997 status = smb_raw_open(cli->tree, torture, &io);
3998 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_NAME_NOT_FOUND,
4000 "smb_raw_open for 'pipe\\srvsvc'");
4002 io.ntcreatex.in.fname = "\\pipe\\srvsvc";
4003 status = smb_raw_open(cli->tree, torture, &io);
4004 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_NAME_NOT_FOUND,
4006 "smb_raw_open for '\\pipe\\srvsvc'");
4008 io.ntcreatex.in.fname = "srvsvc";
4009 status = smb_raw_open(cli->tree, torture, &io);
4010 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4011 "smb2_create failed for 'srvsvc'");
4012 fnum = io.ntcreatex.out.file.fnum;
4014 cl.generic.level = RAW_CLOSE_CLOSE;
4015 cl.close.in.file.fnum = fnum;
4016 status = smb_raw_close(cli->tree, &cl);
4017 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4018 "smb_raw_close failed");
4020 io.ntcreatex.in.fname = "\\srvsvc";
4021 status = smb_raw_open(cli->tree, torture, &io);
4022 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4023 "smb2_create failed for '\\srvsvc'");
4024 fnum = io.ntcreatex.out.file.fnum;
4026 cl.generic.level = RAW_CLOSE_CLOSE;
4027 cl.close.in.file.fnum = fnum;
4028 status = smb_raw_close(cli->tree, &cl);
4029 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4030 "smb_raw_close failed");
4032 io.ntcreatex.in.fname = "\\\\\\\\\\srvsvc";
4033 status = smb_raw_open(cli->tree, torture, &io);
4034 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4035 "smb2_create failed for '\\\\\\\\\\srvsvc'");
4036 fnum = io.ntcreatex.out.file.fnum;
4038 cl.generic.level = RAW_CLOSE_CLOSE;
4039 cl.close.in.file.fnum = fnum;
4040 status = smb_raw_close(cli->tree, &cl);
4041 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4042 "smb_raw_close failed");
4045 io.generic.level = RAW_OPEN_NTTRANS_CREATE;
4046 io.nttrans.in.access_mask = DESIRED_ACCESS_PIPE;
4047 io.nttrans.in.share_access = NTCREATEX_SHARE_ACCESS_READ|
4048 NTCREATEX_SHARE_ACCESS_WRITE;
4049 io.nttrans.in.open_disposition = NTCREATEX_DISP_OPEN;
4050 io.nttrans.in.impersonation = NTCREATEX_IMPERSONATION_IMPERSONATION;
4051 io.nttrans.in.security_flags = 0;
4053 io.nttrans.in.fname = "__none__";
4054 status = smb_raw_open(cli->tree, torture, &io);
4055 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_NAME_NOT_FOUND,
4057 "smb_raw_open for '__none__'");
4059 io.nttrans.in.fname = "pipe\\srvsvc";
4060 status = smb_raw_open(cli->tree, torture, &io);
4061 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_NAME_NOT_FOUND,
4063 "smb_raw_open for 'pipe\\srvsvc'");
4065 io.nttrans.in.fname = "\\pipe\\srvsvc";
4066 status = smb_raw_open(cli->tree, torture, &io);
4067 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_NAME_NOT_FOUND,
4069 "smb_raw_open for '\\pipe\\srvsvc'");
4071 io.nttrans.in.fname = "srvsvc";
4072 status = smb_raw_open(cli->tree, torture, &io);
4073 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4074 "smb2_create failed for 'srvsvc'");
4075 fnum = io.nttrans.out.file.fnum;
4077 cl.generic.level = RAW_CLOSE_CLOSE;
4078 cl.close.in.file.fnum = fnum;
4079 status = smb_raw_close(cli->tree, &cl);
4080 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4081 "smb_raw_close failed");
4083 io.nttrans.in.fname = "\\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 '\\srvsvc'");
4087 fnum = io.nttrans.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.nttrans.in.fname = "\\\\\\\\\\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 '\\\\\\\\\\srvsvc'");
4099 fnum = io.nttrans.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");
4108 io.generic.level = RAW_OPEN_OPENX;
4109 io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR;
4110 io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN;
4112 io.openx.in.fname = "__none__";
4113 status = smb_raw_open(cli->tree, torture, &io);
4114 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_PATH_SYNTAX_BAD,
4116 "smb_raw_open for '__none__'");
4118 io.openx.in.fname = "srvsvc";
4119 status = smb_raw_open(cli->tree, torture, &io);
4120 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_PATH_SYNTAX_BAD,
4122 "smb_raw_open for 'srvsvc'");
4124 io.openx.in.fname = "\\srvsvc";
4125 status = smb_raw_open(cli->tree, torture, &io);
4126 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_PATH_SYNTAX_BAD,
4128 "smb_raw_open for '\\srvsvc'");
4130 io.openx.in.fname = "\\pipesrvsvc";
4131 status = smb_raw_open(cli->tree, torture, &io);
4132 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_PATH_SYNTAX_BAD,
4134 "smb_raw_open for '\\pipesrvsvc'");
4136 io.openx.in.fname = "pipe\\__none__";
4137 status = smb_raw_open(cli->tree, torture, &io);
4138 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_NAME_NOT_FOUND,
4140 "smb_raw_open for 'pipe\\__none__'");
4142 io.openx.in.fname = "\\pipe\\__none__";
4143 status = smb_raw_open(cli->tree, torture, &io);
4144 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_NAME_NOT_FOUND,
4146 "smb_raw_open for '\\pipe\\__none__'");
4148 io.openx.in.fname = "pipe\\srvsvc";
4149 status = smb_raw_open(cli->tree, torture, &io);
4150 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4151 "smb2_create failed for 'pipe\\srvsvc'");
4152 fnum = io.openx.out.file.fnum;
4154 cl.generic.level = RAW_CLOSE_CLOSE;
4155 cl.close.in.file.fnum = fnum;
4156 status = smb_raw_close(cli->tree, &cl);
4157 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4158 "smb_raw_close failed");
4160 io.openx.in.fname = "\\pipe\\srvsvc";
4161 status = smb_raw_open(cli->tree, torture, &io);
4162 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4163 "smb2_create failed for '\\pipe\\srvsvc'");
4164 fnum = io.openx.out.file.fnum;
4166 cl.generic.level = RAW_CLOSE_CLOSE;
4167 cl.close.in.file.fnum = fnum;
4168 status = smb_raw_close(cli->tree, &cl);
4169 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4170 "smb_raw_close failed");
4172 io.openx.in.fname = "\\\\\\\\\\pipe\\srvsvc";
4173 status = smb_raw_open(cli->tree, torture, &io);
4174 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4175 "smb2_create failed for '\\\\\\\\\\pipe\\srvsvc'");
4176 fnum = io.openx.out.file.fnum;
4178 cl.generic.level = RAW_CLOSE_CLOSE;
4179 cl.close.in.file.fnum = fnum;
4180 status = smb_raw_close(cli->tree, &cl);
4181 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4182 "smb_raw_close failed");
4184 io.openx.in.fname = "\\\\\\\\\\pipe\\\\\\\\\\srvsvc";
4185 status = smb_raw_open(cli->tree, torture, &io);
4186 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4187 "smb2_create failed for '\\\\\\\\\\pipe\\\\\\\\\\srvsvc'");
4188 fnum = io.openx.out.file.fnum;
4190 cl.generic.level = RAW_CLOSE_CLOSE;
4191 cl.close.in.file.fnum = fnum;
4192 status = smb_raw_close(cli->tree, &cl);
4193 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4194 "smb_raw_close failed");
4198 talloc_free(mem_ctx);
4202 static bool torture_rpc_smb2_pipe_name(struct torture_context *torture)
4204 TALLOC_CTX *mem_ctx;
4207 struct smbcli_options options;
4208 const char *host = torture_setting_string(torture, "host", NULL);
4209 struct smb2_tree *tree;
4210 struct smb2_handle h;
4211 struct smb2_create io;
4213 mem_ctx = talloc_init("torture_samba3_smb2_pipe_name");
4214 torture_assert(torture, (mem_ctx != NULL), "talloc_init failed");
4216 lpcfg_smbcli_options(torture->lp_ctx, &options);
4218 status = smb2_connect(mem_ctx,
4220 lpcfg_smb_ports(torture->lp_ctx),
4222 lpcfg_resolve_context(torture->lp_ctx),
4223 cmdline_credentials,
4227 lpcfg_socket_options(torture->lp_ctx),
4228 lpcfg_gensec_settings(torture, torture->lp_ctx)
4230 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4231 "smb2_connect failed");
4234 io.in.oplock_level = 0;
4235 io.in.desired_access = DESIRED_ACCESS_PIPE;
4236 io.in.impersonation_level = SMB2_IMPERSONATION_IMPERSONATION;
4237 io.in.file_attributes = 0;
4238 io.in.create_disposition = NTCREATEX_DISP_OPEN;
4239 io.in.share_access =
4240 NTCREATEX_SHARE_ACCESS_READ|
4241 NTCREATEX_SHARE_ACCESS_WRITE;
4242 io.in.create_options = 0;
4244 io.in.fname = "__none__";
4245 status = smb2_create(tree, tree, &io);
4246 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_NAME_NOT_FOUND,
4248 "smb2_create for '__none__'");
4250 io.in.fname = "\\srvsvc";
4251 status = smb2_create(tree, tree, &io);
4252 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_NAME_NOT_FOUND,
4254 "smb2_create for '\\srvsvc'");
4256 io.in.fname = "\\pipe\\srvsvc";
4257 status = smb2_create(tree, tree, &io);
4258 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_NAME_NOT_FOUND,
4260 "smb2_create for '\\pipe\\srvsvc'");
4262 io.in.fname = "pipe\\srvsvc";
4263 status = smb2_create(tree, tree, &io);
4264 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_OBJECT_NAME_NOT_FOUND,
4266 "smb2_create for 'pipe\\srvsvc'");
4268 io.in.fname = "srvsvc";
4269 status = smb2_create(tree, tree, &io);
4270 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4271 "smb2_create failed for 'srvsvc'");
4273 h = io.out.file.handle;
4275 status = smb2_util_close(tree, h);
4276 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4277 "smb2_util_close failed");
4281 talloc_free(mem_ctx);
4286 * Test behaviour of a waiting read call on a pipe when
4287 * the pipe handle is closed:
4288 * - open a pipe via smb2
4289 * - trigger a read which hangs since there is nothing to read
4290 * - close the pipe file handle
4291 * - wait for the read to return and check the status
4292 * (STATUS_PIPE_BROKEN)
4294 static bool torture_rpc_smb2_pipe_read_close(struct torture_context *torture)
4296 TALLOC_CTX *mem_ctx;
4299 struct smbcli_options options;
4300 const char *host = torture_setting_string(torture, "host", NULL);
4301 struct smb2_tree *tree;
4302 struct smb2_handle h;
4303 struct smb2_request *smb2req;
4304 struct smb2_create io;
4305 struct smb2_read rd;
4307 mem_ctx = talloc_init("torture_samba3_pipe_read_close");
4308 torture_assert(torture, (mem_ctx != NULL), "talloc_init failed");
4310 lpcfg_smbcli_options(torture->lp_ctx, &options);
4312 status = smb2_connect(mem_ctx,
4314 lpcfg_smb_ports(torture->lp_ctx),
4316 lpcfg_resolve_context(torture->lp_ctx),
4317 cmdline_credentials,
4321 lpcfg_socket_options(torture->lp_ctx),
4322 lpcfg_gensec_settings(torture, torture->lp_ctx)
4324 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4325 "smb2_connect failed");
4328 io.in.oplock_level = 0;
4329 io.in.desired_access = DESIRED_ACCESS_PIPE;
4330 io.in.impersonation_level = SMB2_IMPERSONATION_IMPERSONATION;
4331 io.in.file_attributes = 0;
4332 io.in.create_disposition = NTCREATEX_DISP_OPEN;
4333 io.in.share_access =
4334 NTCREATEX_SHARE_ACCESS_READ|
4335 NTCREATEX_SHARE_ACCESS_WRITE;
4336 io.in.create_options = 0;
4337 io.in.fname = "lsarpc";
4339 status = smb2_create(tree, tree, &io);
4340 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4341 "smb2_create failed for 'lsarpc'");
4343 h = io.out.file.handle;
4346 rd.in.file.handle = h;
4347 rd.in.length = 1024;
4349 rd.in.min_count = 0;
4351 smb2req = smb2_read_send(tree, &rd);
4352 torture_assert_goto(torture, (smb2req != NULL), ret, done,
4353 "smb2_read_send failed");
4355 status = smb2_util_close(tree, h);
4356 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4357 "smb2_util_close failed");
4359 status = smb2_read_recv(smb2req, mem_ctx, &rd);
4360 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_PIPE_BROKEN, ret, done,
4361 "smb2_read_recv: unexpected return code");
4365 talloc_free(mem_ctx);
4370 * Test behaviour of a waiting read call on a pipe when
4371 * the tree is disconnected.
4372 * - open a pipe via smb2
4373 * - trigger a read which hangs since there is nothing to read
4374 * - do a tree disconnect
4375 * - wait for the read to return and check the status
4376 * (STATUS_PIPE_BROKEN)
4378 static bool torture_rpc_smb2_pipe_read_tdis(struct torture_context *torture)
4380 TALLOC_CTX *mem_ctx;
4383 struct smbcli_options options;
4384 const char *host = torture_setting_string(torture, "host", NULL);
4385 struct smb2_tree *tree;
4386 struct smb2_handle h;
4387 struct smb2_request *smb2req;
4388 struct smb2_create io;
4389 struct smb2_read rd;
4391 mem_ctx = talloc_init("torture_samba3_pipe_read_tdis");
4392 torture_assert(torture, (mem_ctx != NULL), "talloc_init failed");
4394 lpcfg_smbcli_options(torture->lp_ctx, &options);
4396 status = smb2_connect(mem_ctx,
4398 lpcfg_smb_ports(torture->lp_ctx),
4400 lpcfg_resolve_context(torture->lp_ctx),
4401 cmdline_credentials,
4405 lpcfg_socket_options(torture->lp_ctx),
4406 lpcfg_gensec_settings(torture, torture->lp_ctx)
4408 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4409 "smb2_connect failed");
4412 io.in.oplock_level = 0;
4413 io.in.desired_access = DESIRED_ACCESS_PIPE;
4414 io.in.impersonation_level = SMB2_IMPERSONATION_IMPERSONATION;
4415 io.in.file_attributes = 0;
4416 io.in.create_disposition = NTCREATEX_DISP_OPEN;
4417 io.in.share_access =
4418 NTCREATEX_SHARE_ACCESS_READ|
4419 NTCREATEX_SHARE_ACCESS_WRITE;
4420 io.in.create_options = 0;
4421 io.in.fname = "lsarpc";
4423 status = smb2_create(tree, tree, &io);
4424 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4425 "smb2_create failed for 'lsarpc'");
4427 h = io.out.file.handle;
4430 rd.in.file.handle = h;
4431 rd.in.length = 1024;
4433 rd.in.min_count = 0;
4435 smb2req = smb2_read_send(tree, &rd);
4436 torture_assert_goto(torture, (smb2req != NULL), ret, done,
4437 "smb2_read_send failed");
4439 status = smb2_tdis(tree);
4440 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4441 "smb2_tdis failed");
4443 status = smb2_read_recv(smb2req, mem_ctx, &rd);
4444 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_PIPE_BROKEN, ret, done,
4445 "smb2_read_recv: unexpected return code");
4449 talloc_free(mem_ctx);
4454 * Test behaviour of a waiting read call on a pipe when
4456 * - open a pipe via smb2
4457 * - trigger a read which hangs since there is nothing to read
4459 * - wait for the read to return and check the status
4460 * (STATUS_PIPE_BROKEN)
4462 static bool torture_rpc_smb2_pipe_read_logoff(struct torture_context *torture)
4464 TALLOC_CTX *mem_ctx;
4467 struct smbcli_options options;
4468 const char *host = torture_setting_string(torture, "host", NULL);
4469 struct smb2_tree *tree;
4470 struct smb2_handle h;
4471 struct smb2_request *smb2req;
4472 struct smb2_create io;
4473 struct smb2_read rd;
4475 mem_ctx = talloc_init("torture_samba3_pipe_read_tdis");
4476 torture_assert(torture, (mem_ctx != NULL), "talloc_init failed");
4478 lpcfg_smbcli_options(torture->lp_ctx, &options);
4480 status = smb2_connect(mem_ctx,
4482 lpcfg_smb_ports(torture->lp_ctx),
4484 lpcfg_resolve_context(torture->lp_ctx),
4485 cmdline_credentials,
4489 lpcfg_socket_options(torture->lp_ctx),
4490 lpcfg_gensec_settings(torture, torture->lp_ctx)
4492 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4493 "smb2_connect failed");
4496 io.in.oplock_level = 0;
4497 io.in.desired_access = DESIRED_ACCESS_PIPE;
4498 io.in.impersonation_level = SMB2_IMPERSONATION_IMPERSONATION;
4499 io.in.file_attributes = 0;
4500 io.in.create_disposition = NTCREATEX_DISP_OPEN;
4501 io.in.share_access =
4502 NTCREATEX_SHARE_ACCESS_READ|
4503 NTCREATEX_SHARE_ACCESS_WRITE;
4504 io.in.create_options = 0;
4505 io.in.fname = "lsarpc";
4507 status = smb2_create(tree, tree, &io);
4508 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4509 "smb2_create failed for 'lsarpc'");
4511 h = io.out.file.handle;
4514 rd.in.file.handle = h;
4515 rd.in.length = 1024;
4517 rd.in.min_count = 0;
4519 smb2req = smb2_read_send(tree, &rd);
4520 torture_assert_goto(torture, (smb2req != NULL), ret, done,
4521 "smb2_read_send failed");
4523 status = smb2_logoff(tree->session);
4524 torture_assert_ntstatus_ok_goto(torture, status, ret, done,
4525 "smb2_logoff failed");
4527 status = smb2_read_recv(smb2req, mem_ctx, &rd);
4528 torture_assert_ntstatus_equal_goto(torture, status, NT_STATUS_PIPE_BROKEN, ret, done,
4529 "smb2_read_recv: unexpected return code");
4533 talloc_free(mem_ctx);
4538 struct torture_suite *torture_rpc_samba3(TALLOC_CTX *mem_ctx)
4540 struct torture_suite *suite = torture_suite_create(mem_ctx, "samba3");
4542 torture_suite_add_simple_test(suite, "bind", torture_bind_samba3);
4543 torture_suite_add_simple_test(suite, "netlogon", torture_netlogon_samba3);
4544 torture_suite_add_simple_test(suite, "sessionkey", torture_samba3_sessionkey);
4545 torture_suite_add_simple_test(suite, "srvsvc", torture_samba3_rpc_srvsvc);
4546 torture_suite_add_simple_test(suite, "sharesec", torture_samba3_rpc_sharesec);
4547 torture_suite_add_simple_test(suite, "getusername", torture_samba3_rpc_getusername);
4548 torture_suite_add_simple_test(suite, "randomauth2", torture_samba3_rpc_randomauth2);
4549 torture_suite_add_simple_test(suite, "lsa", torture_samba3_rpc_lsa);
4550 torture_suite_add_simple_test(suite, "spoolss", torture_samba3_rpc_spoolss);
4551 torture_suite_add_simple_test(suite, "wkssvc", torture_samba3_rpc_wkssvc);
4552 torture_suite_add_simple_test(suite, "winreg", torture_samba3_rpc_winreg);
4553 torture_suite_add_simple_test(suite, "getaliasmembership-0", torture_samba3_getaliasmembership_0);
4554 torture_suite_add_simple_test(suite, "regconfig", torture_samba3_regconfig);
4555 torture_suite_add_simple_test(suite, "smb-reauth1", torture_rpc_smb_reauth1);
4556 torture_suite_add_simple_test(suite, "smb-reauth2", torture_rpc_smb_reauth2);
4557 torture_suite_add_simple_test(suite, "smb2-reauth1", torture_rpc_smb2_reauth1);
4558 torture_suite_add_simple_test(suite, "smb2-reauth2", torture_rpc_smb2_reauth2);
4559 torture_suite_add_simple_test(suite, "smb1-pipe-name", torture_rpc_smb1_pipe_name);
4560 torture_suite_add_simple_test(suite, "smb2-pipe-name", torture_rpc_smb2_pipe_name);
4561 torture_suite_add_simple_test(suite, "smb2-pipe-read-close", torture_rpc_smb2_pipe_read_close);
4562 torture_suite_add_simple_test(suite, "smb2-pipe-read-tdis", torture_rpc_smb2_pipe_read_tdis);
4563 torture_suite_add_simple_test(suite, "smb2-pipe-read-logoff", torture_rpc_smb2_pipe_read_logoff);
4565 suite->description = talloc_strdup(suite, "samba3 DCERPC interface tests");