2 Unix SMB/CIFS implementation.
4 dcerpc torture tests, designed to walk Samba3 code paths
6 Copyright (C) Volker Lendecke 2006
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "libcli/raw/libcliraw.h"
24 #include "libcli/raw/raw_proto.h"
25 #include "torture/util.h"
26 #include "libcli/rap/rap.h"
27 #include "librpc/gen_ndr/ndr_lsa_c.h"
28 #include "librpc/gen_ndr/ndr_samr_c.h"
29 #include "librpc/gen_ndr/ndr_netlogon_c.h"
30 #include "librpc/gen_ndr/ndr_srvsvc_c.h"
31 #include "librpc/gen_ndr/ndr_spoolss_c.h"
32 #include "librpc/gen_ndr/ndr_winreg_c.h"
33 #include "librpc/gen_ndr/ndr_wkssvc_c.h"
34 #include "lib/cmdline/popt_common.h"
35 #include "torture/rpc/torture_rpc.h"
36 #include "libcli/libcli.h"
37 #include "libcli/smb_composite/smb_composite.h"
38 #include "libcli/auth/libcli_auth.h"
39 #include "../lib/crypto/crypto.h"
40 #include "libcli/security/security.h"
41 #include "param/param.h"
42 #include "lib/registry/registry.h"
43 #include "libcli/resolve/resolve.h"
44 #include "torture/ndr/ndr.h"
45 #include "libcli/smb2/smb2.h"
46 #include "libcli/smb2/smb2_calls.h"
47 #include "librpc/rpc/dcerpc.h"
48 #include "librpc/rpc/dcerpc_proto.h"
49 #include "../source3/libsmb/smb2cli.h"
50 #include "libcli/smb/smbXcli_base.h"
53 * This tests a RPC call using an invalid vuid
56 bool torture_bind_authcontext(struct torture_context
*torture
)
61 struct lsa_ObjectAttribute objectattr
;
62 struct lsa_OpenPolicy2 openpolicy
;
63 struct policy_handle handle
;
64 struct lsa_Close close_handle
;
65 struct smbcli_session
*tmp
;
66 struct smbcli_session
*session2
;
67 struct smbcli_state
*cli
;
68 struct dcerpc_pipe
*lsa_pipe
;
69 struct dcerpc_binding_handle
*lsa_handle
;
70 struct cli_credentials
*anon_creds
;
71 struct smb_composite_sesssetup setup
;
72 struct smbcli_options options
;
73 struct smbcli_session_options session_options
;
75 mem_ctx
= talloc_init("torture_bind_authcontext");
77 if (mem_ctx
== NULL
) {
78 torture_comment(torture
, "talloc_init failed\n");
82 lpcfg_smbcli_options(torture
->lp_ctx
, &options
);
83 lpcfg_smbcli_session_options(torture
->lp_ctx
, &session_options
);
85 status
= smbcli_full_connection(mem_ctx
, &cli
,
86 torture_setting_string(torture
, "host", NULL
),
87 lpcfg_smb_ports(torture
->lp_ctx
),
89 lpcfg_socket_options(torture
->lp_ctx
),
91 lpcfg_resolve_context(torture
->lp_ctx
),
92 torture
->ev
, &options
, &session_options
,
93 lpcfg_gensec_settings(torture
, torture
->lp_ctx
));
94 if (!NT_STATUS_IS_OK(status
)) {
95 torture_comment(torture
, "smbcli_full_connection failed: %s\n",
100 lsa_pipe
= dcerpc_pipe_init(mem_ctx
, torture
->ev
);
101 if (lsa_pipe
== NULL
) {
102 torture_comment(torture
, "dcerpc_pipe_init failed\n");
105 lsa_handle
= lsa_pipe
->binding_handle
;
107 status
= dcerpc_pipe_open_smb(lsa_pipe
, cli
->tree
, "\\lsarpc");
108 if (!NT_STATUS_IS_OK(status
)) {
109 torture_comment(torture
, "dcerpc_pipe_open_smb failed: %s\n",
114 status
= dcerpc_bind_auth_none(lsa_pipe
, &ndr_table_lsarpc
);
115 if (!NT_STATUS_IS_OK(status
)) {
116 torture_comment(torture
, "dcerpc_bind_auth_none failed: %s\n",
121 openpolicy
.in
.system_name
=talloc_asprintf(
122 mem_ctx
, "\\\\%s", dcerpc_server_name(lsa_pipe
));
123 ZERO_STRUCT(objectattr
);
124 openpolicy
.in
.attr
= &objectattr
;
125 openpolicy
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
126 openpolicy
.out
.handle
= &handle
;
128 status
= dcerpc_lsa_OpenPolicy2_r(lsa_handle
, mem_ctx
, &openpolicy
);
130 if (!NT_STATUS_IS_OK(status
)) {
131 torture_comment(torture
, "dcerpc_lsa_OpenPolicy2 failed: %s\n",
135 if (!NT_STATUS_IS_OK(openpolicy
.out
.result
)) {
136 torture_comment(torture
, "dcerpc_lsa_OpenPolicy2 failed: %s\n",
137 nt_errstr(openpolicy
.out
.result
));
141 close_handle
.in
.handle
= &handle
;
142 close_handle
.out
.handle
= &handle
;
144 status
= dcerpc_lsa_Close_r(lsa_handle
, mem_ctx
, &close_handle
);
145 if (!NT_STATUS_IS_OK(status
)) {
146 torture_comment(torture
, "dcerpc_lsa_Close failed: %s\n",
150 if (!NT_STATUS_IS_OK(close_handle
.out
.result
)) {
151 torture_comment(torture
, "dcerpc_lsa_Close failed: %s\n",
152 nt_errstr(close_handle
.out
.result
));
156 session2
= smbcli_session_init(cli
->transport
, mem_ctx
, false, session_options
);
157 if (session2
== NULL
) {
158 torture_comment(torture
, "smbcli_session_init failed\n");
162 if (!(anon_creds
= cli_credentials_init_anon(mem_ctx
))) {
163 torture_comment(torture
, "create_anon_creds failed\n");
167 setup
.in
.sesskey
= cli
->transport
->negotiate
.sesskey
;
168 setup
.in
.capabilities
= cli
->transport
->negotiate
.capabilities
;
169 setup
.in
.workgroup
= "";
170 setup
.in
.credentials
= anon_creds
;
171 setup
.in
.gensec_settings
= lpcfg_gensec_settings(torture
, torture
->lp_ctx
);
173 status
= smb_composite_sesssetup(session2
, &setup
);
174 if (!NT_STATUS_IS_OK(status
)) {
175 torture_comment(torture
, "anon session setup failed: %s\n",
179 session2
->vuid
= setup
.out
.vuid
;
181 tmp
= cli
->tree
->session
;
182 cli
->tree
->session
= session2
;
184 status
= dcerpc_lsa_OpenPolicy2_r(lsa_handle
, mem_ctx
, &openpolicy
);
186 cli
->tree
->session
= tmp
;
187 talloc_free(lsa_pipe
);
190 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
191 torture_comment(torture
, "dcerpc_lsa_OpenPolicy2 with wrong vuid gave %s, "
192 "expected NT_STATUS_INVALID_HANDLE\n",
199 talloc_free(mem_ctx
);
204 * Bind to lsa using a specific auth method
207 static bool bindtest(struct torture_context
*tctx
,
208 struct smbcli_state
*cli
,
209 struct cli_credentials
*credentials
,
210 uint8_t auth_type
, uint8_t auth_level
)
216 struct dcerpc_pipe
*lsa_pipe
;
217 struct dcerpc_binding_handle
*lsa_handle
;
218 struct lsa_ObjectAttribute objectattr
;
219 struct lsa_OpenPolicy2 openpolicy
;
220 struct lsa_QueryInfoPolicy query
;
221 union lsa_PolicyInformation
*info
= NULL
;
222 struct policy_handle handle
;
223 struct lsa_Close close_handle
;
225 if ((mem_ctx
= talloc_init("bindtest")) == NULL
) {
226 torture_comment(tctx
, "talloc_init failed\n");
230 lsa_pipe
= dcerpc_pipe_init(mem_ctx
, tctx
->ev
);
231 if (lsa_pipe
== NULL
) {
232 torture_comment(tctx
, "dcerpc_pipe_init failed\n");
235 lsa_handle
= lsa_pipe
->binding_handle
;
237 status
= dcerpc_pipe_open_smb(lsa_pipe
, cli
->tree
, "\\lsarpc");
238 if (!NT_STATUS_IS_OK(status
)) {
239 torture_comment(tctx
, "dcerpc_pipe_open_smb failed: %s\n",
244 status
= dcerpc_bind_auth(lsa_pipe
, &ndr_table_lsarpc
,
245 credentials
, lpcfg_gensec_settings(tctx
->lp_ctx
, tctx
->lp_ctx
), auth_type
, auth_level
,
247 if (!NT_STATUS_IS_OK(status
)) {
248 torture_comment(tctx
, "dcerpc_bind_auth failed: %s\n", nt_errstr(status
));
252 openpolicy
.in
.system_name
=talloc_asprintf(
253 mem_ctx
, "\\\\%s", dcerpc_server_name(lsa_pipe
));
254 ZERO_STRUCT(objectattr
);
255 openpolicy
.in
.attr
= &objectattr
;
256 openpolicy
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
257 openpolicy
.out
.handle
= &handle
;
259 status
= dcerpc_lsa_OpenPolicy2_r(lsa_handle
, mem_ctx
, &openpolicy
);
261 if (!NT_STATUS_IS_OK(status
)) {
262 torture_comment(tctx
, "dcerpc_lsa_OpenPolicy2 failed: %s\n",
266 if (!NT_STATUS_IS_OK(openpolicy
.out
.result
)) {
267 torture_comment(tctx
, "dcerpc_lsa_OpenPolicy2 failed: %s\n",
268 nt_errstr(openpolicy
.out
.result
));
272 query
.in
.handle
= &handle
;
273 query
.in
.level
= LSA_POLICY_INFO_DOMAIN
;
274 query
.out
.info
= &info
;
276 status
= dcerpc_lsa_QueryInfoPolicy_r(lsa_handle
, mem_ctx
, &query
);
277 if (!NT_STATUS_IS_OK(status
)) {
278 torture_comment(tctx
, "dcerpc_lsa_QueryInfoPolicy failed: %s\n",
282 if (!NT_STATUS_IS_OK(query
.out
.result
)) {
283 torture_comment(tctx
, "dcerpc_lsa_QueryInfoPolicy failed: %s\n",
284 nt_errstr(query
.out
.result
));
288 close_handle
.in
.handle
= &handle
;
289 close_handle
.out
.handle
= &handle
;
291 status
= dcerpc_lsa_Close_r(lsa_handle
, mem_ctx
, &close_handle
);
292 if (!NT_STATUS_IS_OK(status
)) {
293 torture_comment(tctx
, "dcerpc_lsa_Close failed: %s\n",
297 if (!NT_STATUS_IS_OK(close_handle
.out
.result
)) {
298 torture_comment(tctx
, "dcerpc_lsa_Close failed: %s\n",
299 nt_errstr(close_handle
.out
.result
));
306 talloc_free(mem_ctx
);
311 * test authenticated RPC binds with the variants Samba3 does support
314 static bool torture_bind_samba3(struct torture_context
*torture
)
319 struct smbcli_state
*cli
;
320 struct smbcli_options options
;
321 struct smbcli_session_options session_options
;
323 mem_ctx
= talloc_init("torture_bind_authcontext");
325 if (mem_ctx
== NULL
) {
326 torture_comment(torture
, "talloc_init failed\n");
330 lpcfg_smbcli_options(torture
->lp_ctx
, &options
);
331 lpcfg_smbcli_session_options(torture
->lp_ctx
, &session_options
);
333 status
= smbcli_full_connection(mem_ctx
, &cli
,
334 torture_setting_string(torture
, "host", NULL
),
335 lpcfg_smb_ports(torture
->lp_ctx
),
337 lpcfg_socket_options(torture
->lp_ctx
),
339 lpcfg_resolve_context(torture
->lp_ctx
),
340 torture
->ev
, &options
, &session_options
,
341 lpcfg_gensec_settings(torture
, torture
->lp_ctx
));
342 if (!NT_STATUS_IS_OK(status
)) {
343 torture_comment(torture
, "smbcli_full_connection failed: %s\n",
350 ret
&= bindtest(torture
, cli
, cmdline_credentials
, DCERPC_AUTH_TYPE_NTLMSSP
,
351 DCERPC_AUTH_LEVEL_INTEGRITY
);
352 ret
&= bindtest(torture
, cli
, cmdline_credentials
, DCERPC_AUTH_TYPE_NTLMSSP
,
353 DCERPC_AUTH_LEVEL_PRIVACY
);
354 ret
&= bindtest(torture
, cli
, cmdline_credentials
, DCERPC_AUTH_TYPE_SPNEGO
,
355 DCERPC_AUTH_LEVEL_INTEGRITY
);
356 ret
&= bindtest(torture
, cli
, cmdline_credentials
, DCERPC_AUTH_TYPE_SPNEGO
,
357 DCERPC_AUTH_LEVEL_PRIVACY
);
360 talloc_free(mem_ctx
);
365 * Lookup or create a user and return all necessary info
368 static bool get_usr_handle(struct torture_context
*tctx
,
369 struct smbcli_state
*cli
,
371 struct cli_credentials
*admin_creds
,
374 const char *username
,
376 struct dcerpc_pipe
**result_pipe
,
377 struct policy_handle
**result_handle
,
378 struct dom_sid
**sid_p
)
380 struct dcerpc_pipe
*samr_pipe
;
381 struct dcerpc_binding_handle
*samr_handle
;
383 struct policy_handle conn_handle
;
384 struct policy_handle domain_handle
;
385 struct policy_handle
*user_handle
;
386 struct samr_Connect2 conn
;
387 struct samr_EnumDomains enumdom
;
388 uint32_t resume_handle
= 0;
389 uint32_t num_entries
= 0;
390 struct samr_SamArray
*sam
= NULL
;
391 struct samr_LookupDomain l
;
392 struct dom_sid2
*sid
= NULL
;
394 struct lsa_String domain_name
;
395 struct lsa_String user_name
;
396 struct samr_OpenDomain o
;
397 struct samr_CreateUser2 c
;
398 uint32_t user_rid
,access_granted
;
400 samr_pipe
= dcerpc_pipe_init(mem_ctx
, tctx
->ev
);
401 torture_assert(tctx
, samr_pipe
, "dcerpc_pipe_init failed");
403 samr_pipe
->conn
->flags
|= DCERPC_DEBUG_PRINT_IN
| DCERPC_DEBUG_PRINT_OUT
;
405 samr_handle
= samr_pipe
->binding_handle
;
407 torture_assert_ntstatus_ok(tctx
,
408 dcerpc_pipe_open_smb(samr_pipe
, cli
->tree
, "\\samr"),
409 "dcerpc_pipe_open_smb failed");
411 if (admin_creds
!= NULL
) {
412 torture_assert_ntstatus_ok(tctx
,
413 dcerpc_bind_auth(samr_pipe
, &ndr_table_samr
,
414 admin_creds
, lpcfg_gensec_settings(tctx
->lp_ctx
, tctx
->lp_ctx
), auth_type
, auth_level
,
416 "dcerpc_bind_auth failed");
418 /* We must have an authenticated SMB connection */
419 torture_assert_ntstatus_ok(tctx
,
420 dcerpc_bind_auth_none(samr_pipe
, &ndr_table_samr
),
421 "dcerpc_bind_auth_none failed");
424 conn
.in
.system_name
= talloc_asprintf(
425 mem_ctx
, "\\\\%s", dcerpc_server_name(samr_pipe
));
426 conn
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
427 conn
.out
.connect_handle
= &conn_handle
;
429 torture_assert_ntstatus_ok(tctx
,
430 dcerpc_samr_Connect2_r(samr_handle
, mem_ctx
, &conn
),
431 "samr_Connect2 failed");
432 torture_assert_ntstatus_ok(tctx
, conn
.out
.result
,
433 "samr_Connect2 failed");
435 enumdom
.in
.connect_handle
= &conn_handle
;
436 enumdom
.in
.resume_handle
= &resume_handle
;
437 enumdom
.in
.buf_size
= (uint32_t)-1;
438 enumdom
.out
.resume_handle
= &resume_handle
;
439 enumdom
.out
.num_entries
= &num_entries
;
440 enumdom
.out
.sam
= &sam
;
442 torture_assert_ntstatus_ok(tctx
,
443 dcerpc_samr_EnumDomains_r(samr_handle
, mem_ctx
, &enumdom
),
444 "samr_EnumDomains failed");
445 torture_assert_ntstatus_ok(tctx
, enumdom
.out
.result
,
446 "samr_EnumDomains failed");
448 torture_assert_int_equal(tctx
, *enumdom
.out
.num_entries
, 2,
449 "samr_EnumDomains returned unexpected num_entries");
451 dom_idx
= strequal(sam
->entries
[0].name
.string
,
454 l
.in
.connect_handle
= &conn_handle
;
455 domain_name
.string
= sam
->entries
[dom_idx
].name
.string
;
456 *domain
= talloc_strdup(mem_ctx
, domain_name
.string
);
457 l
.in
.domain_name
= &domain_name
;
460 torture_assert_ntstatus_ok(tctx
,
461 dcerpc_samr_LookupDomain_r(samr_handle
, mem_ctx
, &l
),
462 "samr_LookupDomain failed");
463 torture_assert_ntstatus_ok(tctx
, l
.out
.result
,
464 "samr_LookupDomain failed");
466 o
.in
.connect_handle
= &conn_handle
;
467 o
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
468 o
.in
.sid
= *l
.out
.sid
;
469 o
.out
.domain_handle
= &domain_handle
;
471 torture_assert_ntstatus_ok(tctx
,
472 dcerpc_samr_OpenDomain_r(samr_handle
, mem_ctx
, &o
),
473 "samr_OpenDomain failed");
474 torture_assert_ntstatus_ok(tctx
, o
.out
.result
,
475 "samr_OpenDomain failed");
477 c
.in
.domain_handle
= &domain_handle
;
478 user_name
.string
= username
;
479 c
.in
.account_name
= &user_name
;
480 c
.in
.acct_flags
= ACB_NORMAL
;
481 c
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
482 user_handle
= talloc(mem_ctx
, struct policy_handle
);
483 c
.out
.user_handle
= user_handle
;
484 c
.out
.access_granted
= &access_granted
;
485 c
.out
.rid
= &user_rid
;
487 torture_assert_ntstatus_ok(tctx
,
488 dcerpc_samr_CreateUser2_r(samr_handle
, mem_ctx
, &c
),
489 "samr_CreateUser2 failed");
491 if (NT_STATUS_EQUAL(c
.out
.result
, NT_STATUS_USER_EXISTS
)) {
492 struct samr_LookupNames ln
;
493 struct samr_OpenUser ou
;
494 struct samr_Ids rids
, types
;
496 ln
.in
.domain_handle
= &domain_handle
;
498 ln
.in
.names
= &user_name
;
500 ln
.out
.types
= &types
;
502 torture_assert_ntstatus_ok(tctx
,
503 dcerpc_samr_LookupNames_r(samr_handle
, mem_ctx
, &ln
),
504 "samr_LookupNames failed");
505 torture_assert_ntstatus_ok(tctx
, ln
.out
.result
,
506 "samr_LookupNames failed");
508 ou
.in
.domain_handle
= &domain_handle
;
509 ou
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
510 user_rid
= ou
.in
.rid
= ln
.out
.rids
->ids
[0];
511 ou
.out
.user_handle
= user_handle
;
513 torture_assert_ntstatus_ok(tctx
,
514 dcerpc_samr_OpenUser_r(samr_handle
, mem_ctx
, &ou
),
515 "samr_OpenUser failed");
516 status
= ou
.out
.result
;
518 status
= c
.out
.result
;
521 torture_assert_ntstatus_ok(tctx
, status
,
522 "samr_CreateUser failed");
524 *result_pipe
= samr_pipe
;
525 *result_handle
= user_handle
;
527 *sid_p
= dom_sid_add_rid(mem_ctx
, *l
.out
.sid
, user_rid
);
537 static bool create_user(struct torture_context
*tctx
,
538 TALLOC_CTX
*mem_ctx
, struct smbcli_state
*cli
,
539 struct cli_credentials
*admin_creds
,
540 const char *username
, const char *password
,
542 struct dom_sid
**user_sid
)
546 struct dcerpc_pipe
*samr_pipe
;
547 struct dcerpc_binding_handle
*samr_handle
;
548 struct policy_handle
*wks_handle
;
551 if (!(tmp_ctx
= talloc_new(mem_ctx
))) {
552 torture_comment(tctx
, "talloc_init failed\n");
556 ret
= get_usr_handle(tctx
, cli
, tmp_ctx
, admin_creds
,
557 DCERPC_AUTH_TYPE_NTLMSSP
,
558 DCERPC_AUTH_LEVEL_INTEGRITY
,
559 username
, domain_name
, &samr_pipe
, &wks_handle
,
562 torture_comment(tctx
, "get_usr_handle failed\n");
565 samr_handle
= samr_pipe
->binding_handle
;
568 struct samr_SetUserInfo2 sui2
;
569 struct samr_SetUserInfo sui
;
570 struct samr_QueryUserInfo qui
;
571 union samr_UserInfo u_info
;
572 union samr_UserInfo
*info
;
573 DATA_BLOB session_key
;
577 encode_pw_buffer(u_info
.info23
.password
.data
, password
,
580 status
= dcerpc_fetch_session_key(samr_pipe
, &session_key
);
581 if (!NT_STATUS_IS_OK(status
)) {
582 torture_comment(tctx
, "dcerpc_fetch_session_key failed\n");
585 arcfour_crypt_blob(u_info
.info23
.password
.data
, 516,
587 u_info
.info23
.info
.password_expired
= 0;
588 u_info
.info23
.info
.fields_present
= SAMR_FIELD_NT_PASSWORD_PRESENT
|
589 SAMR_FIELD_LM_PASSWORD_PRESENT
|
590 SAMR_FIELD_EXPIRED_FLAG
;
591 sui2
.in
.user_handle
= wks_handle
;
592 sui2
.in
.info
= &u_info
;
595 status
= dcerpc_samr_SetUserInfo2_r(samr_handle
, tmp_ctx
, &sui2
);
596 if (!NT_STATUS_IS_OK(status
)) {
597 torture_comment(tctx
, "samr_SetUserInfo(23) failed: %s\n",
601 if (!NT_STATUS_IS_OK(sui2
.out
.result
)) {
602 torture_comment(tctx
, "samr_SetUserInfo(23) failed: %s\n",
603 nt_errstr(sui2
.out
.result
));
607 u_info
.info16
.acct_flags
= ACB_NORMAL
;
608 sui
.in
.user_handle
= wks_handle
;
609 sui
.in
.info
= &u_info
;
612 status
= dcerpc_samr_SetUserInfo_r(samr_handle
, tmp_ctx
, &sui
);
613 if (!NT_STATUS_IS_OK(status
) || !NT_STATUS_IS_OK(sui
.out
.result
)) {
614 torture_comment(tctx
, "samr_SetUserInfo(16) failed\n");
618 qui
.in
.user_handle
= wks_handle
;
620 qui
.out
.info
= &info
;
622 status
= dcerpc_samr_QueryUserInfo_r(samr_handle
, tmp_ctx
, &qui
);
623 if (!NT_STATUS_IS_OK(status
) || !NT_STATUS_IS_OK(qui
.out
.result
)) {
624 torture_comment(tctx
, "samr_QueryUserInfo(21) failed\n");
628 info
->info21
.allow_password_change
= 0;
629 info
->info21
.force_password_change
= 0;
630 info
->info21
.account_name
.string
= NULL
;
631 info
->info21
.rid
= 0;
632 info
->info21
.acct_expiry
= 0;
633 info
->info21
.fields_present
= 0x81827fa; /* copy usrmgr.exe */
635 u_info
.info21
= info
->info21
;
636 sui
.in
.user_handle
= wks_handle
;
637 sui
.in
.info
= &u_info
;
640 status
= dcerpc_samr_SetUserInfo_r(samr_handle
, tmp_ctx
, &sui
);
641 if (!NT_STATUS_IS_OK(status
) || !NT_STATUS_IS_OK(sui
.out
.result
)) {
642 torture_comment(tctx
, "samr_SetUserInfo(21) failed\n");
647 *domain_name
= talloc_steal(mem_ctx
, *domain_name
);
648 *user_sid
= talloc_steal(mem_ctx
, *user_sid
);
651 talloc_free(tmp_ctx
);
659 static bool delete_user(struct torture_context
*tctx
,
660 struct smbcli_state
*cli
,
661 struct cli_credentials
*admin_creds
,
662 const char *username
)
667 struct dcerpc_pipe
*samr_pipe
;
668 struct dcerpc_binding_handle
*samr_handle
;
669 struct policy_handle
*user_handle
;
672 if ((mem_ctx
= talloc_init("leave")) == NULL
) {
673 torture_comment(tctx
, "talloc_init failed\n");
677 ret
= get_usr_handle(tctx
, cli
, mem_ctx
, admin_creds
,
678 DCERPC_AUTH_TYPE_NTLMSSP
,
679 DCERPC_AUTH_LEVEL_INTEGRITY
,
680 username
, &dom_name
, &samr_pipe
,
683 torture_comment(tctx
, "get_wks_handle failed\n");
686 samr_handle
= samr_pipe
->binding_handle
;
689 struct samr_DeleteUser d
;
691 d
.in
.user_handle
= user_handle
;
692 d
.out
.user_handle
= user_handle
;
694 status
= dcerpc_samr_DeleteUser_r(samr_handle
, mem_ctx
, &d
);
695 if (!NT_STATUS_IS_OK(status
)) {
696 torture_comment(tctx
, "samr_DeleteUser failed %s\n", nt_errstr(status
));
699 if (!NT_STATUS_IS_OK(d
.out
.result
)) {
700 torture_comment(tctx
, "samr_DeleteUser failed %s\n", nt_errstr(d
.out
.result
));
709 talloc_free(mem_ctx
);
714 * Do a Samba3-style join
717 static bool join3(struct torture_context
*tctx
,
718 struct smbcli_state
*cli
,
720 struct cli_credentials
*admin_creds
,
721 struct cli_credentials
*wks_creds
)
726 struct dcerpc_pipe
*samr_pipe
;
727 struct dcerpc_binding_handle
*samr_handle
;
728 struct policy_handle
*wks_handle
;
730 NTTIME last_password_change
;
732 if ((mem_ctx
= talloc_init("join3")) == NULL
) {
733 torture_comment(tctx
, "talloc_init failed\n");
737 ret
= get_usr_handle(
738 tctx
, cli
, mem_ctx
, admin_creds
,
739 DCERPC_AUTH_TYPE_NTLMSSP
,
740 DCERPC_AUTH_LEVEL_PRIVACY
,
741 talloc_asprintf(mem_ctx
, "%s$",
742 cli_credentials_get_workstation(wks_creds
)),
743 &dom_name
, &samr_pipe
, &wks_handle
, NULL
);
745 torture_comment(tctx
, "get_wks_handle failed\n");
748 samr_handle
= samr_pipe
->binding_handle
;
751 struct samr_QueryUserInfo q
;
752 union samr_UserInfo
*info
;
754 q
.in
.user_handle
= wks_handle
;
758 status
= dcerpc_samr_QueryUserInfo_r(samr_handle
, mem_ctx
, &q
);
759 if (!NT_STATUS_IS_OK(status
)) {
760 torture_warning(tctx
, "QueryUserInfo failed: %s\n",
764 if (!NT_STATUS_IS_OK(q
.out
.result
)) {
765 torture_warning(tctx
, "QueryUserInfo failed: %s\n",
766 nt_errstr(q
.out
.result
));
771 last_password_change
= info
->info21
.last_password_change
;
774 cli_credentials_set_domain(wks_creds
, dom_name
, CRED_SPECIFIED
);
777 struct samr_SetUserInfo2 sui2
;
778 union samr_UserInfo u_info
;
779 struct samr_UserInfo21
*i21
= &u_info
.info25
.info
;
780 DATA_BLOB session_key
;
781 DATA_BLOB confounded_session_key
= data_blob_talloc(
783 struct MD5Context ctx
;
784 uint8_t confounder
[16];
788 i21
->full_name
.string
= talloc_asprintf(
790 cli_credentials_get_workstation(wks_creds
));
791 i21
->acct_flags
= ACB_WSTRUST
;
792 i21
->fields_present
= SAMR_FIELD_FULL_NAME
|
793 SAMR_FIELD_ACCT_FLAGS
| SAMR_FIELD_NT_PASSWORD_PRESENT
;
794 /* this would break the test result expectations
795 i21->fields_present |= SAMR_FIELD_EXPIRED_FLAG;
796 i21->password_expired = 1;
799 encode_pw_buffer(u_info
.info25
.password
.data
,
800 cli_credentials_get_password(wks_creds
),
802 status
= dcerpc_fetch_session_key(samr_pipe
, &session_key
);
803 if (!NT_STATUS_IS_OK(status
)) {
804 torture_comment(tctx
, "dcerpc_fetch_session_key failed: %s\n",
808 generate_random_buffer((uint8_t *)confounder
, 16);
811 MD5Update(&ctx
, confounder
, 16);
812 MD5Update(&ctx
, session_key
.data
, session_key
.length
);
813 MD5Final(confounded_session_key
.data
, &ctx
);
815 arcfour_crypt_blob(u_info
.info25
.password
.data
, 516,
816 &confounded_session_key
);
817 memcpy(&u_info
.info25
.password
.data
[516], confounder
, 16);
819 sui2
.in
.user_handle
= wks_handle
;
821 sui2
.in
.info
= &u_info
;
823 status
= dcerpc_samr_SetUserInfo2_r(samr_handle
, mem_ctx
, &sui2
);
824 if (!NT_STATUS_IS_OK(status
)) {
825 torture_comment(tctx
, "samr_SetUserInfo2(25) failed: %s\n",
829 if (!NT_STATUS_IS_OK(sui2
.out
.result
)) {
830 torture_comment(tctx
, "samr_SetUserInfo2(25) failed: %s\n",
831 nt_errstr(sui2
.out
.result
));
835 struct samr_SetUserInfo2 sui2
;
836 struct samr_SetUserInfo sui
;
837 union samr_UserInfo u_info
;
838 DATA_BLOB session_key
;
840 encode_pw_buffer(u_info
.info24
.password
.data
,
841 cli_credentials_get_password(wks_creds
),
843 /* just to make this test pass */
844 u_info
.info24
.password_expired
= 1;
846 status
= dcerpc_fetch_session_key(samr_pipe
, &session_key
);
847 if (!NT_STATUS_IS_OK(status
)) {
848 torture_comment(tctx
, "dcerpc_fetch_session_key failed\n");
851 arcfour_crypt_blob(u_info
.info24
.password
.data
, 516,
853 sui2
.in
.user_handle
= wks_handle
;
854 sui2
.in
.info
= &u_info
;
857 status
= dcerpc_samr_SetUserInfo2_r(samr_handle
, mem_ctx
, &sui2
);
858 if (!NT_STATUS_IS_OK(status
)) {
859 torture_comment(tctx
, "samr_SetUserInfo(24) failed: %s\n",
863 if (!NT_STATUS_IS_OK(sui2
.out
.result
)) {
864 torture_comment(tctx
, "samr_SetUserInfo(24) failed: %s\n",
865 nt_errstr(sui2
.out
.result
));
869 u_info
.info16
.acct_flags
= ACB_WSTRUST
;
870 sui
.in
.user_handle
= wks_handle
;
871 sui
.in
.info
= &u_info
;
874 status
= dcerpc_samr_SetUserInfo_r(samr_handle
, mem_ctx
, &sui
);
875 if (!NT_STATUS_IS_OK(status
) || !NT_STATUS_IS_OK(sui
.out
.result
)) {
876 torture_comment(tctx
, "samr_SetUserInfo(16) failed\n");
882 struct samr_QueryUserInfo q
;
883 union samr_UserInfo
*info
;
885 q
.in
.user_handle
= wks_handle
;
889 status
= dcerpc_samr_QueryUserInfo_r(samr_handle
, mem_ctx
, &q
);
890 if (!NT_STATUS_IS_OK(status
)) {
891 torture_warning(tctx
, "QueryUserInfo failed: %s\n",
895 if (!NT_STATUS_IS_OK(q
.out
.result
)) {
896 torture_warning(tctx
, "QueryUserInfo failed: %s\n",
897 nt_errstr(q
.out
.result
));
902 if (last_password_change
903 == info
->info21
.last_password_change
) {
904 torture_warning(tctx
, "last_password_change unchanged "
905 "during join, level25 must change "
911 if (last_password_change
912 != info
->info21
.last_password_change
) {
913 torture_warning(tctx
, "last_password_change changed "
914 "during join, level24 doesn't "
924 talloc_free(mem_ctx
);
929 * Do a ReqChallenge/Auth2 and get the wks creds
932 static bool auth2(struct torture_context
*tctx
,
933 struct smbcli_state
*cli
,
934 struct cli_credentials
*wks_cred
)
937 struct dcerpc_pipe
*net_pipe
;
938 struct dcerpc_binding_handle
*net_handle
;
941 struct netr_ServerReqChallenge r
;
942 struct netr_Credential netr_cli_creds
;
943 struct netr_Credential netr_srv_creds
;
944 uint32_t negotiate_flags
;
945 struct netr_ServerAuthenticate2 a
;
946 struct netlogon_creds_CredentialState
*creds_state
;
947 struct netr_Credential netr_cred
;
948 struct samr_Password mach_pw
;
950 mem_ctx
= talloc_new(NULL
);
951 if (mem_ctx
== NULL
) {
952 torture_comment(tctx
, "talloc_new failed\n");
956 net_pipe
= dcerpc_pipe_init(mem_ctx
, tctx
->ev
);
957 if (net_pipe
== NULL
) {
958 torture_comment(tctx
, "dcerpc_pipe_init failed\n");
961 net_handle
= net_pipe
->binding_handle
;
963 status
= dcerpc_pipe_open_smb(net_pipe
, cli
->tree
, "\\netlogon");
964 if (!NT_STATUS_IS_OK(status
)) {
965 torture_comment(tctx
, "dcerpc_pipe_open_smb failed: %s\n",
970 status
= dcerpc_bind_auth_none(net_pipe
, &ndr_table_netlogon
);
971 if (!NT_STATUS_IS_OK(status
)) {
972 torture_comment(tctx
, "dcerpc_bind_auth_none failed: %s\n",
977 r
.in
.computer_name
= cli_credentials_get_workstation(wks_cred
);
978 r
.in
.server_name
= talloc_asprintf(
979 mem_ctx
, "\\\\%s", dcerpc_server_name(net_pipe
));
980 if (r
.in
.server_name
== NULL
) {
981 torture_comment(tctx
, "talloc_asprintf failed\n");
984 generate_random_buffer(netr_cli_creds
.data
,
985 sizeof(netr_cli_creds
.data
));
986 r
.in
.credentials
= &netr_cli_creds
;
987 r
.out
.return_credentials
= &netr_srv_creds
;
989 status
= dcerpc_netr_ServerReqChallenge_r(net_handle
, mem_ctx
, &r
);
990 if (!NT_STATUS_IS_OK(status
)) {
991 torture_comment(tctx
, "netr_ServerReqChallenge failed: %s\n",
995 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
996 torture_comment(tctx
, "netr_ServerReqChallenge failed: %s\n",
997 nt_errstr(r
.out
.result
));
1001 negotiate_flags
= NETLOGON_NEG_AUTH2_FLAGS
;
1002 E_md4hash(cli_credentials_get_password(wks_cred
), mach_pw
.hash
);
1004 a
.in
.server_name
= talloc_asprintf(
1005 mem_ctx
, "\\\\%s", dcerpc_server_name(net_pipe
));
1006 a
.in
.account_name
= talloc_asprintf(
1007 mem_ctx
, "%s$", cli_credentials_get_workstation(wks_cred
));
1008 a
.in
.computer_name
= cli_credentials_get_workstation(wks_cred
);
1009 a
.in
.secure_channel_type
= SEC_CHAN_WKSTA
;
1010 a
.in
.negotiate_flags
= &negotiate_flags
;
1011 a
.out
.negotiate_flags
= &negotiate_flags
;
1012 a
.in
.credentials
= &netr_cred
;
1013 a
.out
.return_credentials
= &netr_cred
;
1015 creds_state
= netlogon_creds_client_init(mem_ctx
,
1019 r
.out
.return_credentials
, &mach_pw
,
1020 &netr_cred
, negotiate_flags
);
1021 torture_assert(tctx
, (creds_state
!= NULL
), "memory allocation failed");
1023 status
= dcerpc_netr_ServerAuthenticate2_r(net_handle
, mem_ctx
, &a
);
1024 if (!NT_STATUS_IS_OK(status
)) {
1025 torture_comment(tctx
, "netr_ServerServerAuthenticate2 failed: %s\n",
1029 if (!NT_STATUS_IS_OK(a
.out
.result
)) {
1030 torture_comment(tctx
, "netr_ServerServerAuthenticate2 failed: %s\n",
1031 nt_errstr(a
.out
.result
));
1035 if (!netlogon_creds_client_check(creds_state
, a
.out
.return_credentials
)) {
1036 torture_comment(tctx
, "creds_client_check failed\n");
1040 cli_credentials_set_netlogon_creds(wks_cred
, creds_state
);
1045 talloc_free(mem_ctx
);
1050 * Do a couple of schannel protected Netlogon ops: Interactive and Network
1051 * login, and change the wks password
1054 static bool schan(struct torture_context
*tctx
,
1055 struct smbcli_state
*cli
,
1056 struct cli_credentials
*wks_creds
,
1057 struct cli_credentials
*user_creds
)
1059 TALLOC_CTX
*mem_ctx
;
1062 struct dcerpc_pipe
*net_pipe
;
1063 struct dcerpc_binding_handle
*net_handle
;
1066 mem_ctx
= talloc_new(NULL
);
1067 if (mem_ctx
== NULL
) {
1068 torture_comment(tctx
, "talloc_new failed\n");
1072 net_pipe
= dcerpc_pipe_init(mem_ctx
, tctx
->ev
);
1073 if (net_pipe
== NULL
) {
1074 torture_comment(tctx
, "dcerpc_pipe_init failed\n");
1077 net_handle
= net_pipe
->binding_handle
;
1079 status
= dcerpc_pipe_open_smb(net_pipe
, cli
->tree
, "\\netlogon");
1080 if (!NT_STATUS_IS_OK(status
)) {
1081 torture_comment(tctx
, "dcerpc_pipe_open_smb failed: %s\n",
1087 net_pipe
->conn
->flags
|= DCERPC_DEBUG_PRINT_IN
|
1088 DCERPC_DEBUG_PRINT_OUT
;
1091 net_pipe
->conn
->flags
|= (DCERPC_SIGN
| DCERPC_SEAL
);
1092 status
= dcerpc_bind_auth(net_pipe
, &ndr_table_netlogon
,
1093 wks_creds
, lpcfg_gensec_settings(tctx
->lp_ctx
, tctx
->lp_ctx
), DCERPC_AUTH_TYPE_SCHANNEL
,
1094 DCERPC_AUTH_LEVEL_PRIVACY
,
1097 status
= dcerpc_bind_auth_none(net_pipe
, &ndr_table_netlogon
);
1099 if (!NT_STATUS_IS_OK(status
)) {
1100 torture_comment(tctx
, "schannel bind failed: %s\n", nt_errstr(status
));
1105 for (i
=2; i
<4; i
++) {
1107 DATA_BLOB chal
, nt_resp
, lm_resp
, names_blob
, session_key
;
1108 struct netlogon_creds_CredentialState
*creds_state
;
1109 struct netr_Authenticator netr_auth
, netr_auth2
;
1110 struct netr_NetworkInfo ninfo
;
1111 struct netr_PasswordInfo pinfo
;
1112 struct netr_LogonSamLogon r
;
1113 union netr_LogonLevel logon
;
1114 union netr_Validation validation
;
1115 uint8_t authoritative
;
1116 struct netr_Authenticator return_authenticator
;
1118 flags
= CLI_CRED_LANMAN_AUTH
| CLI_CRED_NTLM_AUTH
|
1119 CLI_CRED_NTLMv2_AUTH
;
1121 chal
= data_blob_talloc(mem_ctx
, NULL
, 8);
1122 if (chal
.data
== NULL
) {
1123 torture_comment(tctx
, "data_blob_talloc failed\n");
1127 generate_random_buffer(chal
.data
, chal
.length
);
1128 names_blob
= NTLMv2_generate_names_blob(
1130 cli_credentials_get_workstation(user_creds
),
1131 cli_credentials_get_domain(user_creds
));
1132 status
= cli_credentials_get_ntlm_response(
1133 user_creds
, mem_ctx
, &flags
, chal
, names_blob
,
1134 &lm_resp
, &nt_resp
, NULL
, NULL
);
1135 if (!NT_STATUS_IS_OK(status
)) {
1136 torture_comment(tctx
, "cli_credentials_get_ntlm_response failed:"
1137 " %s\n", nt_errstr(status
));
1141 creds_state
= cli_credentials_get_netlogon_creds(wks_creds
);
1142 netlogon_creds_client_authenticator(creds_state
, &netr_auth
);
1144 ninfo
.identity_info
.account_name
.string
=
1145 cli_credentials_get_username(user_creds
);
1146 ninfo
.identity_info
.domain_name
.string
=
1147 cli_credentials_get_domain(user_creds
);
1148 ninfo
.identity_info
.parameter_control
= 0;
1149 ninfo
.identity_info
.logon_id_low
= 0;
1150 ninfo
.identity_info
.logon_id_high
= 0;
1151 ninfo
.identity_info
.workstation
.string
=
1152 cli_credentials_get_workstation(user_creds
);
1153 memcpy(ninfo
.challenge
, chal
.data
, sizeof(ninfo
.challenge
));
1154 ninfo
.nt
.length
= nt_resp
.length
;
1155 ninfo
.nt
.data
= nt_resp
.data
;
1156 ninfo
.lm
.length
= lm_resp
.length
;
1157 ninfo
.lm
.data
= lm_resp
.data
;
1159 logon
.network
= &ninfo
;
1161 r
.in
.server_name
= talloc_asprintf(
1162 mem_ctx
, "\\\\%s", dcerpc_server_name(net_pipe
));
1163 ZERO_STRUCT(netr_auth2
);
1164 r
.in
.computer_name
=
1165 cli_credentials_get_workstation(wks_creds
);
1166 r
.in
.credential
= &netr_auth
;
1167 r
.in
.return_authenticator
= &netr_auth2
;
1168 r
.in
.logon_level
= NetlogonNetworkInformation
;
1169 r
.in
.validation_level
= i
;
1170 r
.in
.logon
= &logon
;
1171 r
.out
.validation
= &validation
;
1172 r
.out
.authoritative
= &authoritative
;
1173 r
.out
.return_authenticator
= &return_authenticator
;
1175 status
= dcerpc_netr_LogonSamLogon_r(net_handle
, mem_ctx
, &r
);
1176 if (!NT_STATUS_IS_OK(status
)) {
1177 torture_comment(tctx
, "netr_LogonSamLogon failed: %s\n",
1181 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1182 torture_comment(tctx
, "netr_LogonSamLogon failed: %s\n",
1183 nt_errstr(r
.out
.result
));
1187 if ((r
.out
.return_authenticator
== NULL
) ||
1188 (!netlogon_creds_client_check(creds_state
,
1189 &r
.out
.return_authenticator
->cred
))) {
1190 torture_comment(tctx
, "Credentials check failed!\n");
1194 netlogon_creds_client_authenticator(creds_state
, &netr_auth
);
1196 pinfo
.identity_info
= ninfo
.identity_info
;
1197 ZERO_STRUCT(pinfo
.lmpassword
.hash
);
1198 E_md4hash(cli_credentials_get_password(user_creds
),
1199 pinfo
.ntpassword
.hash
);
1200 session_key
= data_blob_talloc(mem_ctx
,
1201 creds_state
->session_key
, 16);
1202 arcfour_crypt_blob(pinfo
.ntpassword
.hash
,
1203 sizeof(pinfo
.ntpassword
.hash
),
1206 logon
.password
= &pinfo
;
1208 r
.in
.logon_level
= NetlogonInteractiveInformation
;
1209 r
.in
.logon
= &logon
;
1210 r
.out
.return_authenticator
= &return_authenticator
;
1212 status
= dcerpc_netr_LogonSamLogon_r(net_handle
, mem_ctx
, &r
);
1213 if (!NT_STATUS_IS_OK(status
)) {
1214 torture_comment(tctx
, "netr_LogonSamLogon failed: %s\n",
1218 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1219 torture_comment(tctx
, "netr_LogonSamLogon failed: %s\n",
1220 nt_errstr(r
.out
.result
));
1224 if ((r
.out
.return_authenticator
== NULL
) ||
1225 (!netlogon_creds_client_check(creds_state
,
1226 &r
.out
.return_authenticator
->cred
))) {
1227 torture_comment(tctx
, "Credentials check failed!\n");
1233 struct netr_ServerPasswordSet s
;
1234 char *password
= generate_random_password(wks_creds
, 8, 255);
1235 struct netlogon_creds_CredentialState
*creds_state
;
1236 struct netr_Authenticator credential
, return_authenticator
;
1237 struct samr_Password new_password
;
1239 s
.in
.server_name
= talloc_asprintf(
1240 mem_ctx
, "\\\\%s", dcerpc_server_name(net_pipe
));
1241 s
.in
.computer_name
= cli_credentials_get_workstation(wks_creds
);
1242 s
.in
.account_name
= talloc_asprintf(
1243 mem_ctx
, "%s$", s
.in
.computer_name
);
1244 s
.in
.secure_channel_type
= SEC_CHAN_WKSTA
;
1245 s
.in
.credential
= &credential
;
1246 s
.in
.new_password
= &new_password
;
1247 s
.out
.return_authenticator
= &return_authenticator
;
1249 E_md4hash(password
, new_password
.hash
);
1251 creds_state
= cli_credentials_get_netlogon_creds(wks_creds
);
1252 netlogon_creds_des_encrypt(creds_state
, &new_password
);
1253 netlogon_creds_client_authenticator(creds_state
, &credential
);
1255 status
= dcerpc_netr_ServerPasswordSet_r(net_handle
, mem_ctx
, &s
);
1256 if (!NT_STATUS_IS_OK(status
)) {
1257 torture_comment(tctx
, "ServerPasswordSet - %s\n", nt_errstr(status
));
1260 if (!NT_STATUS_IS_OK(s
.out
.result
)) {
1261 torture_comment(tctx
, "ServerPasswordSet - %s\n", nt_errstr(s
.out
.result
));
1265 if (!netlogon_creds_client_check(creds_state
,
1266 &s
.out
.return_authenticator
->cred
)) {
1267 torture_comment(tctx
, "Credential chaining failed\n");
1270 cli_credentials_set_password(wks_creds
, password
,
1276 talloc_free(mem_ctx
);
1281 * Delete the wks account again
1284 static bool leave(struct torture_context
*tctx
,
1285 struct smbcli_state
*cli
,
1286 struct cli_credentials
*admin_creds
,
1287 struct cli_credentials
*wks_creds
)
1289 char *wks_name
= talloc_asprintf(
1290 NULL
, "%s$", cli_credentials_get_workstation(wks_creds
));
1293 ret
= delete_user(tctx
, cli
, admin_creds
, wks_name
);
1294 talloc_free(wks_name
);
1299 * Test the Samba3 DC code a bit. Join, do some schan netlogon ops, leave
1302 static bool torture_netlogon_samba3(struct torture_context
*torture
)
1305 struct smbcli_state
*cli
;
1306 struct cli_credentials
*anon_creds
;
1307 struct cli_credentials
*wks_creds
;
1308 const char *wks_name
;
1310 struct smbcli_options options
;
1311 struct smbcli_session_options session_options
;
1313 wks_name
= torture_setting_string(torture
, "wksname", NULL
);
1314 if (wks_name
== NULL
) {
1315 wks_name
= get_myname(torture
);
1318 if (!(anon_creds
= cli_credentials_init_anon(torture
))) {
1319 torture_fail(torture
, "create_anon_creds failed\n");
1322 lpcfg_smbcli_options(torture
->lp_ctx
, &options
);
1323 lpcfg_smbcli_session_options(torture
->lp_ctx
, &session_options
);
1325 status
= smbcli_full_connection(torture
, &cli
,
1326 torture_setting_string(torture
, "host", NULL
),
1327 lpcfg_smb_ports(torture
->lp_ctx
),
1329 lpcfg_socket_options(torture
->lp_ctx
),
1331 lpcfg_resolve_context(torture
->lp_ctx
),
1332 torture
->ev
, &options
, &session_options
,
1333 lpcfg_gensec_settings(torture
, torture
->lp_ctx
));
1334 torture_assert_ntstatus_ok(torture
, status
, "smbcli_full_connection failed\n");
1336 wks_creds
= cli_credentials_init(torture
);
1337 if (wks_creds
== NULL
) {
1338 torture_fail(torture
, "cli_credentials_init failed\n");
1341 cli_credentials_set_conf(wks_creds
, torture
->lp_ctx
);
1342 cli_credentials_set_secure_channel_type(wks_creds
, SEC_CHAN_WKSTA
);
1343 cli_credentials_set_username(wks_creds
, wks_name
, CRED_SPECIFIED
);
1344 cli_credentials_set_workstation(wks_creds
, wks_name
, CRED_SPECIFIED
);
1345 cli_credentials_set_password(wks_creds
,
1346 generate_random_password(wks_creds
, 8, 255),
1349 torture_assert(torture
,
1350 join3(torture
, cli
, false, cmdline_credentials
, wks_creds
),
1353 cli_credentials_set_domain(
1354 cmdline_credentials
, cli_credentials_get_domain(wks_creds
),
1357 for (i
=0; i
<2; i
++) {
1359 /* Do this more than once, the routine "schan" changes
1360 * the workstation password using the netlogon
1361 * password change routine */
1365 torture_assert(torture
,
1366 auth2(torture
, cli
, wks_creds
),
1369 for (j
=0; j
<2; j
++) {
1370 torture_assert(torture
,
1371 schan(torture
, cli
, wks_creds
, cmdline_credentials
),
1376 torture_assert(torture
,
1377 leave(torture
, cli
, cmdline_credentials
, wks_creds
),
1384 * Do a simple join, testjoin and leave using specified smb and samr
1388 static bool test_join3(struct torture_context
*tctx
,
1390 struct cli_credentials
*smb_creds
,
1391 struct cli_credentials
*samr_creds
,
1392 const char *wks_name
)
1395 struct smbcli_state
*cli
;
1396 struct cli_credentials
*wks_creds
;
1397 struct smbcli_options options
;
1398 struct smbcli_session_options session_options
;
1400 lpcfg_smbcli_options(tctx
->lp_ctx
, &options
);
1401 lpcfg_smbcli_session_options(tctx
->lp_ctx
, &session_options
);
1403 status
= smbcli_full_connection(tctx
, &cli
,
1404 torture_setting_string(tctx
, "host", NULL
),
1405 lpcfg_smb_ports(tctx
->lp_ctx
),
1406 "IPC$", NULL
, lpcfg_socket_options(tctx
->lp_ctx
),
1407 smb_creds
, lpcfg_resolve_context(tctx
->lp_ctx
),
1408 tctx
->ev
, &options
, &session_options
,
1409 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
));
1410 torture_assert_ntstatus_ok(tctx
, status
,
1411 "smbcli_full_connection failed");
1413 wks_creds
= cli_credentials_init(cli
);
1414 torture_assert(tctx
, wks_creds
, "cli_credentials_init failed");
1416 cli_credentials_set_conf(wks_creds
, tctx
->lp_ctx
);
1417 cli_credentials_set_secure_channel_type(wks_creds
, SEC_CHAN_WKSTA
);
1418 cli_credentials_set_username(wks_creds
, wks_name
, CRED_SPECIFIED
);
1419 cli_credentials_set_workstation(wks_creds
, wks_name
, CRED_SPECIFIED
);
1420 cli_credentials_set_password(wks_creds
,
1421 generate_random_password(wks_creds
, 8, 255),
1424 torture_assert(tctx
,
1425 join3(tctx
, cli
, use_level25
, samr_creds
, wks_creds
),
1428 cli_credentials_set_domain(
1429 cmdline_credentials
, cli_credentials_get_domain(wks_creds
),
1432 torture_assert(tctx
,
1433 auth2(tctx
, cli
, wks_creds
),
1436 torture_assert(tctx
,
1437 leave(tctx
, cli
, samr_creds
, wks_creds
),
1446 * Test the different session key variants. Do it by joining, this uses the
1447 * session key in the setpassword routine. Test the join by doing the auth2.
1450 static bool torture_samba3_sessionkey(struct torture_context
*torture
)
1452 struct cli_credentials
*anon_creds
;
1453 const char *wks_name
;
1455 wks_name
= torture_setting_string(torture
, "wksname", get_myname(torture
));
1457 if (!(anon_creds
= cli_credentials_init_anon(torture
))) {
1458 torture_fail(torture
, "create_anon_creds failed\n");
1461 cli_credentials_set_workstation(anon_creds
, wks_name
, CRED_SPECIFIED
);
1464 if (!torture_setting_bool(torture
, "samba3", false)) {
1466 /* Samba3 in the build farm right now does this happily. Need
1469 if (test_join3(torture
, false, anon_creds
, NULL
, wks_name
)) {
1470 torture_fail(torture
, "join using anonymous bind on an anonymous smb "
1471 "connection succeeded -- HUH??\n");
1475 torture_assert(torture
,
1476 test_join3(torture
, false, anon_creds
, cmdline_credentials
, wks_name
),
1477 "join using ntlmssp bind on an anonymous smb connection failed");
1479 torture_assert(torture
,
1480 test_join3(torture
, false, cmdline_credentials
, NULL
, wks_name
),
1481 "join using anonymous bind on an authenticated smb connection failed");
1483 torture_assert(torture
,
1484 test_join3(torture
, false, cmdline_credentials
, cmdline_credentials
, wks_name
),
1485 "join using ntlmssp bind on an authenticated smb connection failed");
1488 * The following two are tests for setuserinfolevel 25
1491 torture_assert(torture
,
1492 test_join3(torture
, true, anon_creds
, cmdline_credentials
, wks_name
),
1493 "join using ntlmssp bind on an anonymous smb connection failed");
1495 torture_assert(torture
,
1496 test_join3(torture
, true, cmdline_credentials
, NULL
, wks_name
),
1497 "join using anonymous bind on an authenticated smb connection failed");
1503 * open pipe and bind, given an IPC$ context
1506 static NTSTATUS
pipe_bind_smb(struct torture_context
*tctx
,
1507 TALLOC_CTX
*mem_ctx
,
1508 struct smbcli_tree
*tree
,
1509 const char *pipe_name
,
1510 const struct ndr_interface_table
*iface
,
1511 struct dcerpc_pipe
**p
)
1513 struct dcerpc_pipe
*result
;
1516 if (!(result
= dcerpc_pipe_init(mem_ctx
, tctx
->ev
))) {
1517 return NT_STATUS_NO_MEMORY
;
1520 status
= dcerpc_pipe_open_smb(result
, tree
, pipe_name
);
1521 if (!NT_STATUS_IS_OK(status
)) {
1522 torture_comment(tctx
, "dcerpc_pipe_open_smb failed: %s\n",
1524 talloc_free(result
);
1528 status
= dcerpc_bind_auth_none(result
, iface
);
1529 if (!NT_STATUS_IS_OK(status
)) {
1530 torture_comment(tctx
, "schannel bind failed: %s\n", nt_errstr(status
));
1531 talloc_free(result
);
1536 return NT_STATUS_OK
;
1540 * Sane wrapper around lsa_LookupNames
1543 static struct dom_sid
*name2sid(struct torture_context
*tctx
,
1544 TALLOC_CTX
*mem_ctx
,
1545 struct dcerpc_pipe
*p
,
1549 struct lsa_ObjectAttribute attr
;
1550 struct lsa_QosInfo qos
;
1551 struct lsa_OpenPolicy2 r
;
1554 struct policy_handle handle
;
1555 struct lsa_LookupNames l
;
1556 struct lsa_TransSidArray sids
;
1557 struct lsa_RefDomainList
*domains
= NULL
;
1558 struct lsa_String lsa_name
;
1560 struct dom_sid
*result
;
1561 TALLOC_CTX
*tmp_ctx
;
1562 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
1564 if (!(tmp_ctx
= talloc_new(mem_ctx
))) {
1569 qos
.impersonation_level
= 2;
1570 qos
.context_mode
= 1;
1571 qos
.effective_only
= 0;
1574 attr
.root_dir
= NULL
;
1575 attr
.object_name
= NULL
;
1576 attr
.attributes
= 0;
1577 attr
.sec_desc
= NULL
;
1578 attr
.sec_qos
= &qos
;
1580 r
.in
.system_name
= "\\";
1582 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1583 r
.out
.handle
= &handle
;
1585 status
= dcerpc_lsa_OpenPolicy2_r(b
, tmp_ctx
, &r
);
1586 if (!NT_STATUS_IS_OK(status
)) {
1587 torture_comment(tctx
, "OpenPolicy2 failed - %s\n", nt_errstr(status
));
1588 talloc_free(tmp_ctx
);
1591 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1592 torture_comment(tctx
, "OpenPolicy2 failed - %s\n", nt_errstr(r
.out
.result
));
1593 talloc_free(tmp_ctx
);
1600 lsa_name
.string
= talloc_asprintf(tmp_ctx
, "%s\\%s", domain
, name
);
1602 l
.in
.handle
= &handle
;
1604 l
.in
.names
= &lsa_name
;
1607 l
.in
.count
= &count
;
1608 l
.out
.count
= &count
;
1610 l
.out
.domains
= &domains
;
1612 status
= dcerpc_lsa_LookupNames_r(b
, tmp_ctx
, &l
);
1613 if (!NT_STATUS_IS_OK(status
)) {
1614 torture_comment(tctx
, "LookupNames of %s failed - %s\n", lsa_name
.string
,
1616 talloc_free(tmp_ctx
);
1619 if (!NT_STATUS_IS_OK(l
.out
.result
)) {
1620 torture_comment(tctx
, "LookupNames of %s failed - %s\n", lsa_name
.string
,
1621 nt_errstr(l
.out
.result
));
1622 talloc_free(tmp_ctx
);
1626 result
= dom_sid_add_rid(mem_ctx
, domains
->domains
[0].sid
,
1627 l
.out
.sids
->sids
[0].rid
);
1629 c
.in
.handle
= &handle
;
1630 c
.out
.handle
= &handle
;
1632 status
= dcerpc_lsa_Close_r(b
, tmp_ctx
, &c
);
1633 if (!NT_STATUS_IS_OK(status
)) {
1634 torture_comment(tctx
, "dcerpc_lsa_Close failed - %s\n", nt_errstr(status
));
1635 talloc_free(tmp_ctx
);
1638 if (!NT_STATUS_IS_OK(c
.out
.result
)) {
1639 torture_comment(tctx
, "dcerpc_lsa_Close failed - %s\n", nt_errstr(c
.out
.result
));
1640 talloc_free(tmp_ctx
);
1644 talloc_free(tmp_ctx
);
1649 * Find out the user SID on this connection
1652 static struct dom_sid
*whoami(struct torture_context
*tctx
,
1653 TALLOC_CTX
*mem_ctx
,
1654 struct smbcli_tree
*tree
)
1656 struct dcerpc_pipe
*lsa
;
1657 struct dcerpc_binding_handle
*lsa_handle
;
1658 struct lsa_GetUserName r
;
1660 struct lsa_String
*authority_name_p
= NULL
;
1661 struct lsa_String
*account_name_p
= NULL
;
1662 struct dom_sid
*result
;
1664 status
= pipe_bind_smb(tctx
, mem_ctx
, tree
, "\\pipe\\lsarpc",
1665 &ndr_table_lsarpc
, &lsa
);
1666 if (!NT_STATUS_IS_OK(status
)) {
1667 torture_warning(tctx
, "Could not bind to LSA: %s\n",
1671 lsa_handle
= lsa
->binding_handle
;
1673 r
.in
.system_name
= "\\";
1674 r
.in
.account_name
= &account_name_p
;
1675 r
.in
.authority_name
= &authority_name_p
;
1676 r
.out
.account_name
= &account_name_p
;
1678 status
= dcerpc_lsa_GetUserName_r(lsa_handle
, mem_ctx
, &r
);
1680 authority_name_p
= *r
.out
.authority_name
;
1682 if (!NT_STATUS_IS_OK(status
)) {
1683 torture_warning(tctx
, "GetUserName failed - %s\n",
1688 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1689 torture_warning(tctx
, "GetUserName failed - %s\n",
1690 nt_errstr(r
.out
.result
));
1695 result
= name2sid(tctx
, mem_ctx
, lsa
, account_name_p
->string
,
1696 authority_name_p
->string
);
1702 static int destroy_tree(struct smbcli_tree
*tree
)
1704 smb_tree_disconnect(tree
);
1709 * Do a tcon, given a session
1712 static NTSTATUS
secondary_tcon(struct torture_context
*tctx
,
1713 TALLOC_CTX
*mem_ctx
,
1714 struct smbcli_session
*session
,
1715 const char *sharename
,
1716 struct smbcli_tree
**res
)
1718 struct smbcli_tree
*result
;
1719 TALLOC_CTX
*tmp_ctx
;
1720 union smb_tcon tcon
;
1723 if (!(tmp_ctx
= talloc_new(mem_ctx
))) {
1724 return NT_STATUS_NO_MEMORY
;
1727 if (!(result
= smbcli_tree_init(session
, mem_ctx
, false))) {
1728 talloc_free(tmp_ctx
);
1729 return NT_STATUS_NO_MEMORY
;
1732 tcon
.generic
.level
= RAW_TCON_TCONX
;
1733 tcon
.tconx
.in
.flags
= TCONX_FLAG_EXTENDED_RESPONSE
;
1734 tcon
.tconx
.in
.flags
|= TCONX_FLAG_EXTENDED_SIGNATURES
;
1735 tcon
.tconx
.in
.password
= data_blob(NULL
, 0);
1736 tcon
.tconx
.in
.path
= sharename
;
1737 tcon
.tconx
.in
.device
= "?????";
1739 status
= smb_raw_tcon(result
, tmp_ctx
, &tcon
);
1740 if (!NT_STATUS_IS_OK(status
)) {
1741 torture_warning(tctx
, "smb_raw_tcon failed: %s\n",
1743 talloc_free(tmp_ctx
);
1747 result
->tid
= tcon
.tconx
.out
.tid
;
1749 if (tcon
.tconx
.out
.options
& SMB_EXTENDED_SIGNATURES
) {
1750 smb1cli_session_protect_session_key(result
->session
->smbXcli
);
1753 result
= talloc_steal(mem_ctx
, result
);
1754 talloc_set_destructor(result
, destroy_tree
);
1755 talloc_free(tmp_ctx
);
1757 return NT_STATUS_OK
;
1761 * Test the getusername behaviour
1764 static bool torture_samba3_rpc_getusername(struct torture_context
*torture
)
1767 struct smbcli_state
*cli
;
1769 struct dom_sid
*user_sid
;
1770 struct dom_sid
*created_sid
;
1771 struct cli_credentials
*anon_creds
;
1772 struct cli_credentials
*user_creds
;
1774 struct smbcli_options options
;
1775 struct smbcli_session_options session_options
;
1777 lpcfg_smbcli_options(torture
->lp_ctx
, &options
);
1778 lpcfg_smbcli_session_options(torture
->lp_ctx
, &session_options
);
1780 status
= smbcli_full_connection(
1781 torture
, &cli
, torture_setting_string(torture
, "host", NULL
),
1782 lpcfg_smb_ports(torture
->lp_ctx
),
1783 "IPC$", NULL
, lpcfg_socket_options(torture
->lp_ctx
), cmdline_credentials
,
1784 lpcfg_resolve_context(torture
->lp_ctx
), torture
->ev
, &options
,
1785 &session_options
, lpcfg_gensec_settings(torture
, torture
->lp_ctx
));
1786 torture_assert_ntstatus_ok(torture
, status
, "smbcli_full_connection failed\n");
1788 if (!(user_sid
= whoami(torture
, torture
, cli
->tree
))) {
1789 torture_fail(torture
, "whoami on auth'ed connection failed\n");
1794 if (!(anon_creds
= cli_credentials_init_anon(torture
))) {
1795 torture_fail(torture
, "create_anon_creds failed\n");
1798 status
= smbcli_full_connection(
1799 torture
, &cli
, torture_setting_string(torture
, "host", NULL
),
1800 lpcfg_smb_ports(torture
->lp_ctx
), "IPC$", NULL
,
1801 lpcfg_socket_options(torture
->lp_ctx
), anon_creds
,
1802 lpcfg_resolve_context(torture
->lp_ctx
),
1803 torture
->ev
, &options
, &session_options
,
1804 lpcfg_gensec_settings(torture
, torture
->lp_ctx
));
1805 torture_assert_ntstatus_ok(torture
, status
, "anon smbcli_full_connection failed\n");
1807 if (!(user_sid
= whoami(torture
, torture
, cli
->tree
))) {
1808 torture_fail(torture
, "whoami on anon connection failed\n");
1811 torture_assert_sid_equal(torture
, user_sid
, dom_sid_parse_talloc(torture
, "s-1-5-7"),
1812 "Anon lsa_GetUserName returned unexpected SID");
1814 if (!(user_creds
= cli_credentials_init(torture
))) {
1815 torture_fail(torture
, "cli_credentials_init failed\n");
1818 cli_credentials_set_conf(user_creds
, torture
->lp_ctx
);
1819 cli_credentials_set_username(user_creds
, "torture_username",
1821 cli_credentials_set_password(user_creds
,
1822 generate_random_password(user_creds
, 8, 255),
1825 if (!create_user(torture
, torture
, cli
, cmdline_credentials
,
1826 cli_credentials_get_username(user_creds
),
1827 cli_credentials_get_password(user_creds
),
1828 &domain_name
, &created_sid
)) {
1829 torture_fail(torture
, "create_user failed\n");
1832 cli_credentials_set_domain(user_creds
, domain_name
,
1836 struct smbcli_session
*session2
;
1837 struct smb_composite_sesssetup setup
;
1838 struct smbcli_tree
*tree
;
1840 session2
= smbcli_session_init(cli
->transport
, torture
, false, session_options
);
1841 if (session2
== NULL
) {
1842 torture_fail(torture
, "smbcli_session_init failed\n");
1845 setup
.in
.sesskey
= cli
->transport
->negotiate
.sesskey
;
1846 setup
.in
.capabilities
= cli
->transport
->negotiate
.capabilities
;
1847 setup
.in
.workgroup
= "";
1848 setup
.in
.credentials
= user_creds
;
1849 setup
.in
.gensec_settings
= lpcfg_gensec_settings(torture
, torture
->lp_ctx
);
1851 status
= smb_composite_sesssetup(session2
, &setup
);
1852 torture_assert_ntstatus_ok(torture
, status
, "session setup with new user failed");
1854 session2
->vuid
= setup
.out
.vuid
;
1856 if (!NT_STATUS_IS_OK(secondary_tcon(torture
, torture
, session2
,
1858 torture_fail(torture
, "secondary_tcon failed\n");
1861 if (!(user_sid
= whoami(torture
, torture
, tree
))) {
1862 torture_fail_goto(torture
, del
, "whoami on user connection failed\n");
1870 torture_comment(torture
, "Created %s, found %s\n",
1871 dom_sid_string(torture
, created_sid
),
1872 dom_sid_string(torture
, user_sid
));
1874 if (!dom_sid_equal(created_sid
, user_sid
)) {
1879 if (!delete_user(torture
, cli
,
1880 cmdline_credentials
,
1881 cli_credentials_get_username(user_creds
))) {
1882 torture_fail(torture
, "delete_user failed\n");
1888 static bool test_NetShareGetInfo(struct torture_context
*tctx
,
1889 struct dcerpc_pipe
*p
,
1890 const char *sharename
)
1893 struct srvsvc_NetShareGetInfo r
;
1894 union srvsvc_NetShareInfo info
;
1895 uint32_t levels
[] = { 0, 1, 2, 501, 502, 1004, 1005, 1006, 1007, 1501 };
1898 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
1900 r
.in
.server_unc
= talloc_asprintf(tctx
, "\\\\%s",
1901 dcerpc_server_name(p
));
1902 r
.in
.share_name
= sharename
;
1905 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
1906 r
.in
.level
= levels
[i
];
1908 torture_comment(tctx
, "Testing NetShareGetInfo level %u on share '%s'\n",
1909 r
.in
.level
, r
.in
.share_name
);
1911 status
= dcerpc_srvsvc_NetShareGetInfo_r(b
, tctx
, &r
);
1912 if (!NT_STATUS_IS_OK(status
)) {
1913 torture_warning(tctx
, "NetShareGetInfo level %u on share '%s' failed"
1914 " - %s\n", r
.in
.level
, r
.in
.share_name
,
1919 if (!W_ERROR_IS_OK(r
.out
.result
)) {
1920 torture_warning(tctx
, "NetShareGetInfo level %u on share '%s' failed "
1921 "- %s\n", r
.in
.level
, r
.in
.share_name
,
1922 win_errstr(r
.out
.result
));
1931 static bool test_NetShareEnum(struct torture_context
*tctx
,
1932 struct dcerpc_pipe
*p
,
1933 const char **one_sharename
)
1936 struct srvsvc_NetShareEnum r
;
1937 struct srvsvc_NetShareInfoCtr info_ctr
;
1938 struct srvsvc_NetShareCtr0 c0
;
1939 struct srvsvc_NetShareCtr1 c1
;
1940 struct srvsvc_NetShareCtr2 c2
;
1941 struct srvsvc_NetShareCtr501 c501
;
1942 struct srvsvc_NetShareCtr502 c502
;
1943 struct srvsvc_NetShareCtr1004 c1004
;
1944 struct srvsvc_NetShareCtr1005 c1005
;
1945 struct srvsvc_NetShareCtr1006 c1006
;
1946 struct srvsvc_NetShareCtr1007 c1007
;
1947 uint32_t totalentries
= 0;
1948 uint32_t levels
[] = { 0, 1, 2, 501, 502, 1004, 1005, 1006, 1007 };
1951 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
1953 ZERO_STRUCT(info_ctr
);
1955 r
.in
.server_unc
= talloc_asprintf(tctx
,"\\\\%s",dcerpc_server_name(p
));
1956 r
.in
.info_ctr
= &info_ctr
;
1957 r
.in
.max_buffer
= (uint32_t)-1;
1958 r
.in
.resume_handle
= NULL
;
1959 r
.out
.totalentries
= &totalentries
;
1960 r
.out
.info_ctr
= &info_ctr
;
1962 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
1963 info_ctr
.level
= levels
[i
];
1965 switch (info_ctr
.level
) {
1968 info_ctr
.ctr
.ctr0
= &c0
;
1972 info_ctr
.ctr
.ctr1
= &c1
;
1976 info_ctr
.ctr
.ctr2
= &c2
;
1980 info_ctr
.ctr
.ctr501
= &c501
;
1984 info_ctr
.ctr
.ctr502
= &c502
;
1988 info_ctr
.ctr
.ctr1004
= &c1004
;
1992 info_ctr
.ctr
.ctr1005
= &c1005
;
1996 info_ctr
.ctr
.ctr1006
= &c1006
;
2000 info_ctr
.ctr
.ctr1007
= &c1007
;
2004 torture_comment(tctx
, "Testing NetShareEnum level %u\n", info_ctr
.level
);
2006 status
= dcerpc_srvsvc_NetShareEnum_r(b
, tctx
, &r
);
2007 if (!NT_STATUS_IS_OK(status
)) {
2008 torture_warning(tctx
, "NetShareEnum level %u failed - %s\n",
2009 info_ctr
.level
, nt_errstr(status
));
2013 if (!W_ERROR_IS_OK(r
.out
.result
)) {
2014 torture_warning(tctx
, "NetShareEnum level %u failed - %s\n",
2015 info_ctr
.level
, win_errstr(r
.out
.result
));
2018 if (info_ctr
.level
== 0) {
2019 struct srvsvc_NetShareCtr0
*ctr
= r
.out
.info_ctr
->ctr
.ctr0
;
2020 if (ctr
->count
> 0) {
2021 *one_sharename
= ctr
->array
[0].name
;
2029 static bool torture_samba3_rpc_srvsvc(struct torture_context
*torture
)
2031 struct dcerpc_pipe
*p
;
2032 const char *sharename
= NULL
;
2035 torture_assert_ntstatus_ok(torture
,
2036 torture_rpc_connection(torture
, &p
, &ndr_table_srvsvc
),
2037 "failed to open srvsvc");
2039 ret
&= test_NetShareEnum(torture
, p
, &sharename
);
2040 if (sharename
== NULL
) {
2041 torture_comment(torture
, "did not get sharename\n");
2043 ret
&= test_NetShareGetInfo(torture
, p
, sharename
);
2050 * Do a ReqChallenge/Auth2 with a random wks name, make sure it returns
2051 * NT_STATUS_NO_SAM_ACCOUNT
2054 static bool torture_samba3_rpc_randomauth2(struct torture_context
*torture
)
2056 TALLOC_CTX
*mem_ctx
;
2057 struct dcerpc_pipe
*net_pipe
;
2058 struct dcerpc_binding_handle
*net_handle
;
2060 bool result
= false;
2062 struct netr_ServerReqChallenge r
;
2063 struct netr_Credential netr_cli_creds
;
2064 struct netr_Credential netr_srv_creds
;
2065 uint32_t negotiate_flags
;
2066 struct netr_ServerAuthenticate2 a
;
2067 struct netlogon_creds_CredentialState
*creds_state
;
2068 struct netr_Credential netr_cred
;
2069 struct samr_Password mach_pw
;
2070 struct smbcli_state
*cli
;
2072 if (!(mem_ctx
= talloc_new(torture
))) {
2073 torture_comment(torture
, "talloc_new failed\n");
2077 if (!(wksname
= generate_random_str_list(
2078 mem_ctx
, 14, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"))) {
2079 torture_comment(torture
, "generate_random_str_list failed\n");
2083 if (!(torture_open_connection_share(
2085 torture
, torture_setting_string(torture
, "host", NULL
),
2086 "IPC$", torture
->ev
))) {
2087 torture_comment(torture
, "IPC$ connection failed\n");
2091 if (!(net_pipe
= dcerpc_pipe_init(mem_ctx
, torture
->ev
))) {
2092 torture_comment(torture
, "dcerpc_pipe_init failed\n");
2095 net_handle
= net_pipe
->binding_handle
;
2097 status
= dcerpc_pipe_open_smb(net_pipe
, cli
->tree
, "\\netlogon");
2098 if (!NT_STATUS_IS_OK(status
)) {
2099 torture_comment(torture
, "dcerpc_pipe_open_smb failed: %s\n",
2104 status
= dcerpc_bind_auth_none(net_pipe
, &ndr_table_netlogon
);
2105 if (!NT_STATUS_IS_OK(status
)) {
2106 torture_comment(torture
, "dcerpc_bind_auth_none failed: %s\n",
2111 r
.in
.computer_name
= wksname
;
2112 r
.in
.server_name
= talloc_asprintf(
2113 mem_ctx
, "\\\\%s", dcerpc_server_name(net_pipe
));
2114 if (r
.in
.server_name
== NULL
) {
2115 torture_comment(torture
, "talloc_asprintf failed\n");
2118 generate_random_buffer(netr_cli_creds
.data
,
2119 sizeof(netr_cli_creds
.data
));
2120 r
.in
.credentials
= &netr_cli_creds
;
2121 r
.out
.return_credentials
= &netr_srv_creds
;
2123 status
= dcerpc_netr_ServerReqChallenge_r(net_handle
, mem_ctx
, &r
);
2124 if (!NT_STATUS_IS_OK(status
)) {
2125 torture_comment(torture
, "netr_ServerReqChallenge failed: %s\n",
2129 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
2130 torture_comment(torture
, "netr_ServerReqChallenge failed: %s\n",
2131 nt_errstr(r
.out
.result
));
2135 negotiate_flags
= NETLOGON_NEG_AUTH2_FLAGS
;
2136 E_md4hash("foobar", mach_pw
.hash
);
2138 a
.in
.server_name
= talloc_asprintf(
2139 mem_ctx
, "\\\\%s", dcerpc_server_name(net_pipe
));
2140 a
.in
.account_name
= talloc_asprintf(
2141 mem_ctx
, "%s$", wksname
);
2142 a
.in
.computer_name
= wksname
;
2143 a
.in
.secure_channel_type
= SEC_CHAN_WKSTA
;
2144 a
.in
.negotiate_flags
= &negotiate_flags
;
2145 a
.out
.negotiate_flags
= &negotiate_flags
;
2146 a
.in
.credentials
= &netr_cred
;
2147 a
.out
.return_credentials
= &netr_cred
;
2149 creds_state
= netlogon_creds_client_init(mem_ctx
,
2153 r
.out
.return_credentials
, &mach_pw
,
2154 &netr_cred
, negotiate_flags
);
2155 torture_assert(torture
, (creds_state
!= NULL
), "memory allocation failed");
2157 status
= dcerpc_netr_ServerAuthenticate2_r(net_handle
, mem_ctx
, &a
);
2158 if (!NT_STATUS_IS_OK(status
)) {
2161 if (!NT_STATUS_EQUAL(a
.out
.result
, NT_STATUS_NO_TRUST_SAM_ACCOUNT
)) {
2162 torture_comment(torture
, "dcerpc_netr_ServerAuthenticate2 returned %s, "
2163 "expected NT_STATUS_NO_TRUST_SAM_ACCOUNT\n",
2164 nt_errstr(a
.out
.result
));
2170 talloc_free(mem_ctx
);
2174 static struct security_descriptor
*get_sharesec(struct torture_context
*tctx
,
2175 TALLOC_CTX
*mem_ctx
,
2176 struct smbcli_session
*sess
,
2177 const char *sharename
)
2179 struct smbcli_tree
*tree
;
2180 TALLOC_CTX
*tmp_ctx
;
2181 struct dcerpc_pipe
*p
;
2182 struct dcerpc_binding_handle
*b
;
2184 struct srvsvc_NetShareGetInfo r
;
2185 union srvsvc_NetShareInfo info
;
2186 struct security_descriptor
*result
;
2188 if (!(tmp_ctx
= talloc_new(mem_ctx
))) {
2189 torture_comment(tctx
, "talloc_new failed\n");
2193 if (!NT_STATUS_IS_OK(secondary_tcon(tctx
, tmp_ctx
, sess
, "IPC$", &tree
))) {
2194 torture_comment(tctx
, "secondary_tcon failed\n");
2195 talloc_free(tmp_ctx
);
2199 status
= pipe_bind_smb(tctx
, mem_ctx
, tree
, "\\pipe\\srvsvc",
2200 &ndr_table_srvsvc
, &p
);
2201 if (!NT_STATUS_IS_OK(status
)) {
2202 torture_warning(tctx
, "could not bind to srvsvc pipe: %s\n",
2204 talloc_free(tmp_ctx
);
2207 b
= p
->binding_handle
;
2210 p
->conn
->flags
|= DCERPC_DEBUG_PRINT_IN
| DCERPC_DEBUG_PRINT_OUT
;
2213 r
.in
.server_unc
= talloc_asprintf(tmp_ctx
, "\\\\%s",
2214 dcerpc_server_name(p
));
2215 r
.in
.share_name
= sharename
;
2219 status
= dcerpc_srvsvc_NetShareGetInfo_r(b
, tmp_ctx
, &r
);
2220 if (!NT_STATUS_IS_OK(status
)) {
2221 torture_comment(tctx
, "srvsvc_NetShareGetInfo failed: %s\n",
2223 talloc_free(tmp_ctx
);
2226 if (!W_ERROR_IS_OK(r
.out
.result
)) {
2227 torture_comment(tctx
, "srvsvc_NetShareGetInfo failed: %s\n",
2228 win_errstr(r
.out
.result
));
2229 talloc_free(tmp_ctx
);
2233 result
= talloc_steal(mem_ctx
, info
.info502
->sd_buf
.sd
);
2234 talloc_free(tmp_ctx
);
2238 static NTSTATUS
set_sharesec(struct torture_context
*tctx
,
2239 TALLOC_CTX
*mem_ctx
,
2240 struct smbcli_session
*sess
,
2241 const char *sharename
,
2242 struct security_descriptor
*sd
)
2244 struct smbcli_tree
*tree
;
2245 TALLOC_CTX
*tmp_ctx
;
2246 struct dcerpc_pipe
*p
;
2247 struct dcerpc_binding_handle
*b
;
2249 struct sec_desc_buf i
;
2250 struct srvsvc_NetShareSetInfo r
;
2251 union srvsvc_NetShareInfo info
;
2254 if (!(tmp_ctx
= talloc_new(mem_ctx
))) {
2255 torture_comment(tctx
, "talloc_new failed\n");
2256 return NT_STATUS_NO_MEMORY
;
2259 if (!NT_STATUS_IS_OK(secondary_tcon(tctx
, tmp_ctx
, sess
, "IPC$", &tree
))) {
2260 torture_comment(tctx
, "secondary_tcon failed\n");
2261 talloc_free(tmp_ctx
);
2262 return NT_STATUS_UNSUCCESSFUL
;
2265 status
= pipe_bind_smb(tctx
, mem_ctx
, tree
, "\\pipe\\srvsvc",
2266 &ndr_table_srvsvc
, &p
);
2267 if (!NT_STATUS_IS_OK(status
)) {
2268 torture_warning(tctx
, "could not bind to srvsvc pipe: %s\n",
2270 talloc_free(tmp_ctx
);
2271 return NT_STATUS_UNSUCCESSFUL
;
2273 b
= p
->binding_handle
;
2276 p
->conn
->flags
|= DCERPC_DEBUG_PRINT_IN
| DCERPC_DEBUG_PRINT_OUT
;
2279 r
.in
.server_unc
= talloc_asprintf(tmp_ctx
, "\\\\%s",
2280 dcerpc_server_name(p
));
2281 r
.in
.share_name
= sharename
;
2286 r
.in
.parm_error
= &error
;
2288 status
= dcerpc_srvsvc_NetShareSetInfo_r(b
, tmp_ctx
, &r
);
2289 if (!NT_STATUS_IS_OK(status
)) {
2290 torture_comment(tctx
, "srvsvc_NetShareSetInfo failed: %s\n",
2293 if (!W_ERROR_IS_OK(r
.out
.result
)) {
2294 torture_comment(tctx
, "srvsvc_NetShareSetInfo failed: %s\n",
2295 win_errstr(r
.out
.result
));
2296 status
= werror_to_ntstatus(r
.out
.result
);
2298 talloc_free(tmp_ctx
);
2302 bool try_tcon(struct torture_context
*tctx
,
2303 TALLOC_CTX
*mem_ctx
,
2304 struct security_descriptor
*orig_sd
,
2305 struct smbcli_session
*session
,
2306 const char *sharename
, const struct dom_sid
*user_sid
,
2307 unsigned int access_mask
, NTSTATUS expected_tcon
,
2308 NTSTATUS expected_mkdir
)
2310 TALLOC_CTX
*tmp_ctx
;
2311 struct smbcli_tree
*rmdir_tree
, *tree
;
2312 struct dom_sid
*domain_sid
;
2314 struct security_descriptor
*sd
;
2318 if (!(tmp_ctx
= talloc_new(mem_ctx
))) {
2319 torture_comment(tctx
, "talloc_new failed\n");
2323 status
= secondary_tcon(tctx
, tmp_ctx
, session
, sharename
, &rmdir_tree
);
2324 if (!NT_STATUS_IS_OK(status
)) {
2325 torture_comment(tctx
, "first tcon to delete dir failed\n");
2326 talloc_free(tmp_ctx
);
2330 smbcli_rmdir(rmdir_tree
, "sharesec_testdir");
2332 if (!NT_STATUS_IS_OK(dom_sid_split_rid(tmp_ctx
, user_sid
,
2333 &domain_sid
, &rid
))) {
2334 torture_comment(tctx
, "dom_sid_split_rid failed\n");
2335 talloc_free(tmp_ctx
);
2339 sd
= security_descriptor_dacl_create(
2340 tmp_ctx
, 0, "S-1-5-32-544",
2341 dom_sid_string(mem_ctx
, dom_sid_add_rid(mem_ctx
, domain_sid
,
2343 dom_sid_string(mem_ctx
, user_sid
),
2344 SEC_ACE_TYPE_ACCESS_ALLOWED
, access_mask
, 0, NULL
);
2346 torture_comment(tctx
, "security_descriptor_dacl_create failed\n");
2347 talloc_free(tmp_ctx
);
2351 status
= set_sharesec(tctx
, mem_ctx
, session
, sharename
, sd
);
2352 if (!NT_STATUS_IS_OK(status
)) {
2353 torture_comment(tctx
, "custom set_sharesec failed: %s\n",
2355 talloc_free(tmp_ctx
);
2359 status
= secondary_tcon(tctx
, tmp_ctx
, session
, sharename
, &tree
);
2360 if (!NT_STATUS_EQUAL(status
, expected_tcon
)) {
2361 torture_comment(tctx
, "Expected %s, got %s\n", nt_errstr(expected_tcon
),
2367 if (!NT_STATUS_IS_OK(status
)) {
2368 /* An expected non-access, no point in trying to write */
2372 status
= smbcli_mkdir(tree
, "sharesec_testdir");
2373 if (!NT_STATUS_EQUAL(status
, expected_mkdir
)) {
2374 torture_warning(tctx
, "Expected %s, got %s\n",
2375 nt_errstr(expected_mkdir
), nt_errstr(status
));
2380 smbcli_rmdir(rmdir_tree
, "sharesec_testdir");
2382 status
= set_sharesec(tctx
, mem_ctx
, session
, sharename
, orig_sd
);
2383 if (!NT_STATUS_IS_OK(status
)) {
2384 torture_comment(tctx
, "custom set_sharesec failed: %s\n",
2386 talloc_free(tmp_ctx
);
2390 talloc_free(tmp_ctx
);
2394 static bool torture_samba3_rpc_sharesec(struct torture_context
*torture
)
2396 struct smbcli_state
*cli
= NULL
;
2397 struct security_descriptor
*sd
= NULL
;
2398 struct dom_sid
*user_sid
= NULL
;
2399 const char *testuser_passwd
= NULL
;
2400 struct cli_credentials
*test_credentials
= NULL
;
2401 struct smbcli_options options
;
2402 struct smbcli_session_options session_options
;
2404 struct test_join
*tj
= NULL
;
2405 struct dcerpc_pipe
*lsa_pipe
= NULL
;
2406 const char *priv_array
[1];
2408 /* Create a new user. The normal user has SeBackup and SeRestore
2409 privs so we can't lock them out with a share security descriptor. */
2410 tj
= torture_create_testuser(torture
,
2412 torture_setting_string(torture
, "workgroup", NULL
),
2416 torture_fail(torture
, "Creating sharesec_user failed\n");
2419 /* Give them SeDiskOperatorPrivilege but no other privs. */
2420 status
= torture_rpc_connection(torture
, &lsa_pipe
, &ndr_table_lsarpc
);
2421 if (!NT_STATUS_IS_OK(status
)) {
2422 torture_delete_testuser(torture
, tj
, "sharesec_user");
2424 torture_fail(torture
, "Error connecting to LSA pipe");
2427 priv_array
[0] = "SeDiskOperatorPrivilege";
2428 if (!torture_setup_privs(torture
,
2432 torture_join_user_sid(tj
))) {
2433 talloc_free(lsa_pipe
);
2434 torture_delete_testuser(torture
, tj
, "sharesec_user");
2436 torture_fail(torture
, "Failed to setup privs\n");
2438 talloc_free(lsa_pipe
);
2440 test_credentials
= cli_credentials_init(torture
);
2441 cli_credentials_set_workstation(test_credentials
, "localhost", CRED_SPECIFIED
);
2442 cli_credentials_set_domain(test_credentials
, lpcfg_workgroup(torture
->lp_ctx
),
2444 cli_credentials_set_username(test_credentials
, "sharesec_user", CRED_SPECIFIED
);
2445 cli_credentials_set_password(test_credentials
, testuser_passwd
, CRED_SPECIFIED
);
2447 ZERO_STRUCT(options
);
2448 ZERO_STRUCT(session_options
);
2449 lpcfg_smbcli_options(torture
->lp_ctx
, &options
);
2450 lpcfg_smbcli_session_options(torture
->lp_ctx
, &session_options
);
2452 status
= smbcli_full_connection(torture
,
2454 torture_setting_string(torture
, "host", NULL
),
2455 lpcfg_smb_ports(torture
->lp_ctx
),
2458 lpcfg_socket_options(torture
->lp_ctx
),
2460 lpcfg_resolve_context(torture
->lp_ctx
),
2464 lpcfg_gensec_settings(torture
, torture
->lp_ctx
));
2465 if (!NT_STATUS_IS_OK(status
)) {
2467 torture_delete_testuser(torture
, tj
, "sharesec_user");
2469 torture_fail(torture
, "Failed to open connection\n");
2472 if (!(user_sid
= whoami(torture
, torture
, cli
->tree
))) {
2474 torture_delete_testuser(torture
, tj
, "sharesec_user");
2476 torture_fail(torture
, "whoami failed\n");
2479 sd
= get_sharesec(torture
, torture
, cli
->session
,
2480 torture_setting_string(torture
, "share", NULL
));
2482 if (!try_tcon(torture
, torture
, sd
, cli
->session
,
2483 torture_setting_string(torture
, "share", NULL
),
2484 user_sid
, 0, NT_STATUS_ACCESS_DENIED
, NT_STATUS_OK
)) {
2486 torture_delete_testuser(torture
, tj
, "sharesec_user");
2488 torture_fail(torture
, "failed to test tcon with 0 access_mask");
2491 if (!try_tcon(torture
, torture
, sd
, cli
->session
,
2492 torture_setting_string(torture
, "share", NULL
),
2493 user_sid
, SEC_FILE_READ_DATA
, NT_STATUS_OK
,
2494 NT_STATUS_MEDIA_WRITE_PROTECTED
)) {
2496 torture_delete_testuser(torture
, tj
, "sharesec_user");
2498 torture_fail(torture
, "failed to test tcon with SEC_FILE_READ_DATA access_mask");
2501 /* sharesec_user doesn't have any rights on the underlying file system.
2502 Go back to the normal user. */
2506 torture_delete_testuser(torture
, tj
, "sharesec_user");
2510 if (!(torture_open_connection_share(
2511 torture
, &cli
, torture
, torture_setting_string(torture
, "host", NULL
),
2512 "IPC$", torture
->ev
))) {
2513 torture_fail(torture
, "IPC$ connection failed\n");
2516 if (!(user_sid
= whoami(torture
, torture
, cli
->tree
))) {
2517 torture_fail(torture
, "whoami failed\n");
2519 torture_assert(torture
, try_tcon(
2520 torture
, torture
, sd
, cli
->session
,
2521 torture_setting_string(torture
, "share", NULL
),
2522 user_sid
, SEC_FILE_ALL
, NT_STATUS_OK
, NT_STATUS_OK
),
2523 "failed to test tcon with SEC_FILE_ALL access_mask")
2528 static bool torture_samba3_rpc_lsa(struct torture_context
*torture
)
2530 struct dcerpc_pipe
*p
;
2531 struct dcerpc_binding_handle
*b
;
2532 struct policy_handle lsa_handle
;
2534 torture_assert_ntstatus_ok(torture
,
2535 torture_rpc_connection(torture
, &p
, &ndr_table_lsarpc
),
2536 "failed to setup lsarpc");
2538 b
= p
->binding_handle
;
2541 struct lsa_ObjectAttribute attr
;
2542 struct lsa_OpenPolicy2 o
;
2543 o
.in
.system_name
= talloc_asprintf(
2544 torture
, "\\\\%s", dcerpc_server_name(p
));
2547 o
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2548 o
.out
.handle
= &lsa_handle
;
2550 torture_assert_ntstatus_ok(torture
,
2551 dcerpc_lsa_OpenPolicy2_r(b
, torture
, &o
),
2552 "dcerpc_lsa_OpenPolicy2 failed");
2553 torture_assert_ntstatus_ok(torture
, o
.out
.result
,
2554 "dcerpc_lsa_OpenPolicy2 failed");
2559 int levels
[] = { 2,3,5,6 };
2561 for (i
=0; i
<ARRAY_SIZE(levels
); i
++) {
2562 struct lsa_QueryInfoPolicy r
;
2563 union lsa_PolicyInformation
*info
= NULL
;
2564 r
.in
.handle
= &lsa_handle
;
2565 r
.in
.level
= levels
[i
];
2568 torture_assert_ntstatus_ok(torture
,
2569 dcerpc_lsa_QueryInfoPolicy_r(b
, torture
, &r
),
2570 talloc_asprintf(torture
, "dcerpc_lsa_QueryInfoPolicy level %d failed", levels
[i
]));
2571 torture_assert_ntstatus_ok(torture
, r
.out
.result
,
2572 talloc_asprintf(torture
, "dcerpc_lsa_QueryInfoPolicy level %d failed", levels
[i
]));
2579 static NTSTATUS
get_servername(TALLOC_CTX
*mem_ctx
, struct smbcli_tree
*tree
,
2582 struct rap_WserverGetInfo r
;
2584 char servername
[17];
2585 size_t converted_size
;
2588 r
.in
.bufsize
= 0xffff;
2590 status
= smbcli_rap_netservergetinfo(tree
, mem_ctx
, &r
);
2591 if (!NT_STATUS_IS_OK(status
)) {
2595 memcpy(servername
, r
.out
.info
.info0
.name
, 16);
2596 servername
[16] = '\0';
2598 if (!pull_ascii_talloc(mem_ctx
, name
, servername
, &converted_size
)) {
2599 return NT_STATUS_NO_MEMORY
;
2602 return NT_STATUS_OK
;
2605 static bool rap_get_servername(struct torture_context
*tctx
,
2608 struct smbcli_state
*cli
;
2610 torture_assert(tctx
,
2611 torture_open_connection_share(tctx
, &cli
, tctx
, torture_setting_string(tctx
, "host", NULL
),
2613 "IPC$ connection failed");
2615 torture_assert_ntstatus_ok(tctx
,
2616 get_servername(tctx
, cli
->tree
, servername
),
2617 "get_servername failed");
2624 static bool find_printers(struct torture_context
*tctx
,
2625 struct dcerpc_pipe
*p
,
2626 const char ***printers
,
2629 struct srvsvc_NetShareEnum r
;
2630 struct srvsvc_NetShareInfoCtr info_ctr
;
2631 struct srvsvc_NetShareCtr1 c1_in
;
2632 struct srvsvc_NetShareCtr1
*c1
;
2633 uint32_t totalentries
= 0;
2635 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
2639 info_ctr
.ctr
.ctr1
= &c1_in
;
2641 r
.in
.server_unc
= talloc_asprintf(
2642 tctx
, "\\\\%s", dcerpc_server_name(p
));
2643 r
.in
.info_ctr
= &info_ctr
;
2644 r
.in
.max_buffer
= (uint32_t)-1;
2645 r
.in
.resume_handle
= NULL
;
2646 r
.out
.totalentries
= &totalentries
;
2647 r
.out
.info_ctr
= &info_ctr
;
2649 torture_assert_ntstatus_ok(tctx
,
2650 dcerpc_srvsvc_NetShareEnum_r(b
, tctx
, &r
),
2651 "NetShareEnum level 1 failed");
2652 torture_assert_werr_ok(tctx
, r
.out
.result
,
2653 "NetShareEnum level 1 failed");
2657 c1
= r
.out
.info_ctr
->ctr
.ctr1
;
2658 for (i
=0; i
<c1
->count
; i
++) {
2659 if (c1
->array
[i
].type
!= STYPE_PRINTQ
) {
2662 if (!add_string_to_array(tctx
, c1
->array
[i
].name
,
2663 printers
, num_printers
)) {
2671 static bool enumprinters(struct torture_context
*tctx
,
2672 struct dcerpc_binding_handle
*b
,
2673 const char *servername
, int level
, int *num_printers
)
2675 struct spoolss_EnumPrinters r
;
2679 union spoolss_PrinterInfo
*info
;
2681 r
.in
.flags
= PRINTER_ENUM_LOCAL
;
2682 r
.in
.server
= talloc_asprintf(tctx
, "\\\\%s", servername
);
2686 r
.out
.needed
= &needed
;
2687 r
.out
.count
= &count
;
2690 torture_assert_ntstatus_ok(tctx
,
2691 dcerpc_spoolss_EnumPrinters_r(b
, tctx
, &r
),
2692 "dcerpc_spoolss_EnumPrinters failed");
2693 torture_assert_werr_equal(tctx
, r
.out
.result
, WERR_INSUFFICIENT_BUFFER
,
2694 "EnumPrinters unexpected return code should be WERR_INSUFFICIENT_BUFFER");
2696 blob
= data_blob_talloc_zero(tctx
, needed
);
2697 if (blob
.data
== NULL
) {
2701 r
.in
.buffer
= &blob
;
2702 r
.in
.offered
= needed
;
2704 torture_assert_ntstatus_ok(tctx
,
2705 dcerpc_spoolss_EnumPrinters_r(b
, tctx
, &r
),
2706 "dcerpc_spoolss_EnumPrinters failed");
2707 torture_assert_werr_ok(tctx
, r
.out
.result
,
2708 "dcerpc_spoolss_EnumPrinters failed");
2710 *num_printers
= count
;
2715 static bool getprinterinfo(struct torture_context
*tctx
,
2716 struct dcerpc_binding_handle
*b
,
2717 struct policy_handle
*handle
, int level
,
2718 union spoolss_PrinterInfo
**res
)
2720 struct spoolss_GetPrinter r
;
2724 r
.in
.handle
= handle
;
2728 r
.out
.needed
= &needed
;
2730 torture_assert_ntstatus_ok(tctx
,
2731 dcerpc_spoolss_GetPrinter_r(b
, tctx
, &r
),
2732 "dcerpc_spoolss_GetPrinter failed");
2733 torture_assert_werr_equal(tctx
, r
.out
.result
, WERR_INSUFFICIENT_BUFFER
,
2734 "GetPrinter unexpected return code should be WERR_INSUFFICIENT_BUFFER");
2736 r
.in
.handle
= handle
;
2738 blob
= data_blob_talloc_zero(tctx
, needed
);
2739 if (blob
.data
== NULL
) {
2742 r
.in
.buffer
= &blob
;
2743 r
.in
.offered
= needed
;
2745 torture_assert_ntstatus_ok(tctx
,
2746 dcerpc_spoolss_GetPrinter_r(b
, tctx
, &r
),
2747 "dcerpc_spoolss_GetPrinter failed");
2748 torture_assert_werr_ok(tctx
, r
.out
.result
,
2749 "dcerpc_spoolss_GetPrinter failed");
2752 *res
= talloc_steal(tctx
, r
.out
.info
);
2758 static bool torture_samba3_rpc_spoolss(struct torture_context
*torture
)
2760 struct dcerpc_pipe
*p
, *p2
;
2761 struct dcerpc_binding_handle
*b
;
2762 struct policy_handle server_handle
, printer_handle
;
2763 const char **printers
;
2765 struct spoolss_UserLevel1 userlevel1
;
2768 torture_assert(torture
,
2769 rap_get_servername(torture
, &servername
),
2770 "failed to rap servername");
2772 torture_assert_ntstatus_ok(torture
,
2773 torture_rpc_connection(torture
, &p2
, &ndr_table_srvsvc
),
2774 "failed to setup srvsvc");
2776 torture_assert(torture
,
2777 find_printers(torture
, p2
, &printers
, &num_printers
),
2778 "failed to find printers via srvsvc");
2782 if (num_printers
== 0) {
2783 torture_skip(torture
, "Did not find printers\n");
2787 torture_assert_ntstatus_ok(torture
,
2788 torture_rpc_connection(torture
, &p
, &ndr_table_spoolss
),
2789 "failed to setup spoolss");
2791 b
= p
->binding_handle
;
2793 ZERO_STRUCT(userlevel1
);
2794 userlevel1
.client
= talloc_asprintf(
2795 torture
, "\\\\%s", lpcfg_netbios_name(torture
->lp_ctx
));
2796 userlevel1
.user
= cli_credentials_get_username(cmdline_credentials
);
2797 userlevel1
.build
= 2600;
2798 userlevel1
.major
= 3;
2799 userlevel1
.minor
= 0;
2800 userlevel1
.processor
= 0;
2803 struct spoolss_OpenPrinterEx r
;
2806 r
.in
.printername
= talloc_asprintf(torture
, "\\\\%s",
2808 r
.in
.datatype
= NULL
;
2809 r
.in
.access_mask
= 0;
2811 r
.in
.userlevel
.level1
= &userlevel1
;
2812 r
.out
.handle
= &server_handle
;
2814 torture_assert_ntstatus_ok(torture
,
2815 dcerpc_spoolss_OpenPrinterEx_r(b
, torture
, &r
),
2816 "dcerpc_spoolss_OpenPrinterEx failed");
2817 torture_assert_werr_ok(torture
, r
.out
.result
,
2818 "dcerpc_spoolss_OpenPrinterEx failed");
2822 struct spoolss_ClosePrinter r
;
2824 r
.in
.handle
= &server_handle
;
2825 r
.out
.handle
= &server_handle
;
2827 torture_assert_ntstatus_ok(torture
,
2828 dcerpc_spoolss_ClosePrinter_r(b
, torture
, &r
),
2829 "dcerpc_spoolss_ClosePrinter failed");
2830 torture_assert_werr_ok(torture
, r
.out
.result
,
2831 "dcerpc_spoolss_ClosePrinter failed");
2835 struct spoolss_OpenPrinterEx r
;
2838 r
.in
.printername
= talloc_asprintf(
2839 torture
, "\\\\%s\\%s", servername
, printers
[0]);
2840 r
.in
.datatype
= NULL
;
2841 r
.in
.access_mask
= 0;
2843 r
.in
.userlevel
.level1
= &userlevel1
;
2844 r
.out
.handle
= &printer_handle
;
2846 torture_assert_ntstatus_ok(torture
,
2847 dcerpc_spoolss_OpenPrinterEx_r(b
, torture
, &r
),
2848 "dcerpc_spoolss_OpenPrinterEx failed");
2849 torture_assert_werr_ok(torture
, r
.out
.result
,
2850 "dcerpc_spoolss_OpenPrinterEx failed");
2856 for (i
=0; i
<8; i
++) {
2857 torture_assert(torture
,
2858 getprinterinfo(torture
, b
, &printer_handle
, i
, NULL
),
2859 talloc_asprintf(torture
, "getprinterinfo %d failed", i
));
2864 struct spoolss_ClosePrinter r
;
2866 r
.in
.handle
= &printer_handle
;
2867 r
.out
.handle
= &printer_handle
;
2869 torture_assert_ntstatus_ok(torture
,
2870 dcerpc_spoolss_ClosePrinter_r(b
, torture
, &r
),
2871 "dcerpc_spoolss_ClosePrinter failed");
2872 torture_assert_werr_ok(torture
, r
.out
.result
,
2873 "dcerpc_spoolss_ClosePrinter failed");
2879 torture_assert(torture
,
2880 enumprinters(torture
, b
, servername
, 1, &num_enumerated
),
2881 "enumprinters failed");
2883 torture_assert_int_equal(torture
, num_printers
, num_enumerated
,
2884 "netshareenum / enumprinters lvl 1 numprinter mismatch");
2890 torture_assert(torture
,
2891 enumprinters(torture
, b
, servername
, 2, &num_enumerated
),
2892 "enumprinters failed");
2894 torture_assert_int_equal(torture
, num_printers
, num_enumerated
,
2895 "netshareenum / enumprinters lvl 2 numprinter mismatch");
2901 static bool torture_samba3_rpc_wkssvc(struct torture_context
*torture
)
2903 struct dcerpc_pipe
*p
;
2904 struct dcerpc_binding_handle
*b
;
2907 torture_assert(torture
,
2908 rap_get_servername(torture
, &servername
),
2909 "failed to rap servername");
2911 torture_assert_ntstatus_ok(torture
,
2912 torture_rpc_connection(torture
, &p
, &ndr_table_wkssvc
),
2913 "failed to setup wkssvc");
2915 b
= p
->binding_handle
;
2918 struct wkssvc_NetWkstaInfo100 wks100
;
2919 union wkssvc_NetWkstaInfo info
;
2920 struct wkssvc_NetWkstaGetInfo r
;
2922 r
.in
.server_name
= "\\foo";
2924 info
.info100
= &wks100
;
2927 torture_assert_ntstatus_ok(torture
,
2928 dcerpc_wkssvc_NetWkstaGetInfo_r(b
, torture
, &r
),
2929 "dcerpc_wkssvc_NetWksGetInfo failed");
2930 torture_assert_werr_ok(torture
, r
.out
.result
,
2931 "dcerpc_wkssvc_NetWksGetInfo failed");
2933 torture_assert_str_equal(torture
, servername
, r
.out
.info
->info100
->server_name
,
2934 "servername RAP / DCERPC inconsistency");
2940 static bool winreg_close(struct torture_context
*tctx
,
2941 struct dcerpc_binding_handle
*b
,
2942 struct policy_handle
*handle
)
2944 struct winreg_CloseKey c
;
2946 c
.in
.handle
= c
.out
.handle
= handle
;
2948 torture_assert_ntstatus_ok(tctx
,
2949 dcerpc_winreg_CloseKey_r(b
, tctx
, &c
),
2950 "winreg_CloseKey failed");
2951 torture_assert_werr_ok(tctx
, c
.out
.result
,
2952 "winreg_CloseKey failed");
2957 static bool enumvalues(struct torture_context
*tctx
,
2958 struct dcerpc_binding_handle
*b
,
2959 struct policy_handle
*handle
)
2961 uint32_t enum_index
= 0;
2964 struct winreg_EnumValue r
;
2965 struct winreg_ValNameBuf name
;
2966 enum winreg_Type type
= 0;
2969 uint32_t size
, length
;
2971 r
.in
.handle
= handle
;
2972 r
.in
.enum_index
= enum_index
;
2975 r
.in
.name
= r
.out
.name
= &name
;
2981 r
.in
.length
= &length
;
2983 status
= dcerpc_winreg_EnumValue_r(b
, tctx
, &r
);
2984 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(r
.out
.result
)) {
2991 static bool enumkeys(struct torture_context
*tctx
,
2992 struct dcerpc_binding_handle
*b
,
2993 struct policy_handle
*handle
,
2996 struct winreg_EnumKey r
;
2997 struct winreg_StringBuf kclass
, name
;
3008 r
.in
.handle
= handle
;
3009 r
.in
.enum_index
= 0;
3011 r
.in
.keyclass
= &kclass
;
3013 r
.in
.last_changed_time
= &t
;
3016 struct winreg_OpenKey o
;
3017 struct policy_handle key_handle
;
3023 status
= dcerpc_winreg_EnumKey_r(b
, tctx
, &r
);
3024 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(r
.out
.result
)) {
3025 /* We're done enumerating */
3029 for (i
=0; i
<10-depth
; i
++) {
3030 torture_comment(tctx
, " ");
3032 torture_comment(tctx
, "%s\n", r
.out
.name
->name
);
3034 o
.in
.parent_handle
= handle
;
3035 o
.in
.keyname
.name
= r
.out
.name
->name
;
3037 o
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3038 o
.out
.handle
= &key_handle
;
3040 status
= dcerpc_winreg_OpenKey_r(b
, tctx
, &o
);
3041 if (NT_STATUS_IS_OK(status
) && W_ERROR_IS_OK(o
.out
.result
)) {
3042 enumkeys(tctx
, b
, &key_handle
, depth
-1);
3043 enumvalues(tctx
, b
, &key_handle
);
3044 torture_assert(tctx
, winreg_close(tctx
, b
, &key_handle
), "");
3047 r
.in
.enum_index
+= 1;
3053 typedef NTSTATUS (*winreg_open_fn
)(struct dcerpc_binding_handle
*, TALLOC_CTX
*, void *);
3055 static bool test_Open3(struct torture_context
*tctx
,
3056 struct dcerpc_binding_handle
*b
,
3057 const char *name
, winreg_open_fn open_fn
)
3059 struct policy_handle handle
;
3060 struct winreg_OpenHKLM r
;
3062 r
.in
.system_name
= 0;
3063 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3064 r
.out
.handle
= &handle
;
3066 torture_assert_ntstatus_ok(tctx
,
3067 open_fn(b
, tctx
, &r
),
3068 talloc_asprintf(tctx
, "%s failed", name
));
3069 torture_assert_werr_ok(tctx
, r
.out
.result
,
3070 talloc_asprintf(tctx
, "%s failed", name
));
3072 enumkeys(tctx
, b
, &handle
, 4);
3074 torture_assert(tctx
,
3075 winreg_close(tctx
, b
, &handle
),
3076 "dcerpc_CloseKey failed");
3081 static bool torture_samba3_rpc_winreg(struct torture_context
*torture
)
3083 struct dcerpc_pipe
*p
;
3084 struct dcerpc_binding_handle
*b
;
3090 {"OpenHKLM", (winreg_open_fn
)dcerpc_winreg_OpenHKLM_r
},
3091 {"OpenHKU", (winreg_open_fn
)dcerpc_winreg_OpenHKU_r
},
3092 {"OpenHKPD", (winreg_open_fn
)dcerpc_winreg_OpenHKPD_r
},
3093 {"OpenHKPT", (winreg_open_fn
)dcerpc_winreg_OpenHKPT_r
},
3094 {"OpenHKCR", (winreg_open_fn
)dcerpc_winreg_OpenHKCR_r
}};
3099 torture_assert_ntstatus_ok(torture
,
3100 torture_rpc_connection(torture
, &p
, &ndr_table_winreg
),
3101 "failed to setup winreg");
3103 b
= p
->binding_handle
;
3106 ret
= test_Open3(torture
, b
, open_fns
[0].name
, open_fns
[0].fn
);
3108 for (i
= 0; i
< ARRAY_SIZE(open_fns
); i
++) {
3109 if (!test_Open3(torture
, b
, open_fns
[i
].name
, open_fns
[i
].fn
))
3116 static bool get_shareinfo(struct torture_context
*tctx
,
3117 struct dcerpc_binding_handle
*b
,
3118 const char *servername
,
3120 struct srvsvc_NetShareInfo502
**info502
)
3122 struct srvsvc_NetShareGetInfo r
;
3123 union srvsvc_NetShareInfo info
;
3125 r
.in
.server_unc
= talloc_asprintf(tctx
, "\\\\%s", servername
);
3126 r
.in
.share_name
= share
;
3130 torture_assert_ntstatus_ok(tctx
,
3131 dcerpc_srvsvc_NetShareGetInfo_r(b
, tctx
, &r
),
3132 "srvsvc_NetShareGetInfo failed");
3133 torture_assert_werr_ok(tctx
, r
.out
.result
,
3134 "srvsvc_NetShareGetInfo failed");
3136 *info502
= talloc_move(tctx
, &info
.info502
);
3142 * Get us a handle on HKLM\
3145 static bool get_hklm_handle(struct torture_context
*tctx
,
3146 struct dcerpc_binding_handle
*b
,
3147 struct policy_handle
*handle
)
3149 struct winreg_OpenHKLM r
;
3150 struct policy_handle result
;
3152 r
.in
.system_name
= 0;
3153 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3154 r
.out
.handle
= &result
;
3156 torture_assert_ntstatus_ok(tctx
,
3157 dcerpc_winreg_OpenHKLM_r(b
, tctx
, &r
),
3159 torture_assert_werr_ok(tctx
, r
.out
.result
,
3167 static bool torture_samba3_createshare(struct torture_context
*tctx
,
3168 struct dcerpc_binding_handle
*b
,
3169 const char *sharename
)
3171 struct policy_handle hklm
;
3172 struct policy_handle new_handle
;
3173 struct winreg_CreateKey c
;
3174 struct winreg_CloseKey cl
;
3175 enum winreg_CreateAction action_taken
;
3177 c
.in
.handle
= &hklm
;
3178 c
.in
.name
.name
= talloc_asprintf(
3179 tctx
, "software\\samba\\smbconf\\%s", sharename
);
3180 torture_assert(tctx
, c
.in
.name
.name
, "talloc_asprintf failed");
3182 c
.in
.keyclass
.name
= "";
3184 c
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3185 c
.in
.secdesc
= NULL
;
3186 c
.in
.action_taken
= &action_taken
;
3187 c
.out
.new_handle
= &new_handle
;
3188 c
.out
.action_taken
= &action_taken
;
3190 torture_assert_ntstatus_ok(tctx
,
3191 dcerpc_winreg_CreateKey_r(b
, tctx
, &c
),
3193 torture_assert_werr_ok(tctx
, c
.out
.result
,
3196 cl
.in
.handle
= &new_handle
;
3197 cl
.out
.handle
= &new_handle
;
3199 torture_assert_ntstatus_ok(tctx
,
3200 dcerpc_winreg_CloseKey_r(b
, tctx
, &cl
),
3202 torture_assert_werr_ok(tctx
, cl
.out
.result
,
3208 static bool torture_samba3_deleteshare(struct torture_context
*tctx
,
3209 struct dcerpc_binding_handle
*b
,
3210 const char *sharename
)
3212 struct policy_handle hklm
;
3213 struct winreg_DeleteKey d
;
3215 torture_assert(tctx
,
3216 get_hklm_handle(tctx
, b
, &hklm
),
3217 "get_hklm_handle failed");
3219 d
.in
.handle
= &hklm
;
3220 d
.in
.key
.name
= talloc_asprintf(
3221 tctx
, "software\\samba\\smbconf\\%s", sharename
);
3222 torture_assert(tctx
, d
.in
.key
.name
, "talloc_asprintf failed");
3224 torture_assert_ntstatus_ok(tctx
,
3225 dcerpc_winreg_DeleteKey_r(b
, tctx
, &d
),
3226 "DeleteKey failed");
3227 torture_assert_werr_ok(tctx
, d
.out
.result
,
3228 "DeleteKey failed");
3233 static bool torture_samba3_setconfig(struct torture_context
*tctx
,
3234 struct dcerpc_binding_handle
*b
,
3235 const char *sharename
,
3236 const char *parameter
,
3239 struct policy_handle hklm
, key_handle
;
3240 struct winreg_OpenKey o
;
3241 struct winreg_SetValue s
;
3245 torture_assert(tctx
,
3246 get_hklm_handle(tctx
, b
, &hklm
),
3247 "get_hklm_handle failed");
3249 o
.in
.parent_handle
= &hklm
;
3250 o
.in
.keyname
.name
= talloc_asprintf(
3251 tctx
, "software\\samba\\smbconf\\%s", sharename
);
3252 torture_assert(tctx
, o
.in
.keyname
.name
, "talloc_asprintf failed");
3255 o
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3256 o
.out
.handle
= &key_handle
;
3258 torture_assert_ntstatus_ok(tctx
,
3259 dcerpc_winreg_OpenKey_r(b
, tctx
, &o
),
3261 torture_assert_werr_ok(tctx
, o
.out
.result
,
3264 torture_assert(tctx
,
3265 reg_string_to_val(tctx
, "REG_SZ", value
, &type
, &val
),
3266 "reg_string_to_val failed");
3268 s
.in
.handle
= &key_handle
;
3269 s
.in
.name
.name
= parameter
;
3271 s
.in
.data
= val
.data
;
3272 s
.in
.size
= val
.length
;
3274 torture_assert_ntstatus_ok(tctx
,
3275 dcerpc_winreg_SetValue_r(b
, tctx
, &s
),
3277 torture_assert_werr_ok(tctx
, s
.out
.result
,
3283 static bool torture_samba3_regconfig(struct torture_context
*torture
)
3285 struct srvsvc_NetShareInfo502
*i
= NULL
;
3286 const char *comment
= "Dummer Kommentar";
3287 struct dcerpc_pipe
*srvsvc_pipe
, *winreg_pipe
;
3289 torture_assert_ntstatus_ok(torture
,
3290 torture_rpc_connection(torture
, &srvsvc_pipe
, &ndr_table_srvsvc
),
3291 "failed to setup srvsvc");
3293 torture_assert_ntstatus_ok(torture
,
3294 torture_rpc_connection(torture
, &winreg_pipe
, &ndr_table_winreg
),
3295 "failed to setup winreg");
3297 torture_assert(torture
,
3298 torture_samba3_createshare(torture
, winreg_pipe
->binding_handle
, "blubber"),
3299 "torture_samba3_createshare failed");
3301 torture_assert(torture
,
3302 torture_samba3_setconfig(torture
, winreg_pipe
->binding_handle
, "blubber", "comment", comment
),
3303 "torture_samba3_setconfig failed");
3305 torture_assert(torture
,
3306 get_shareinfo(torture
, srvsvc_pipe
->binding_handle
, dcerpc_server_name(srvsvc_pipe
), "blubber", &i
),
3307 "get_shareinfo failed");
3309 torture_assert_str_equal(torture
, comment
, i
->comment
,
3310 "got unexpected comment");
3312 torture_assert(torture
,
3313 torture_samba3_deleteshare(torture
, winreg_pipe
->binding_handle
, "blubber"),
3314 "torture_samba3_deleteshare failed");
3320 * Test that even with a result of 0 rids the array is returned as a
3321 * non-NULL pointer. Yes, XP does notice.
3324 bool torture_samba3_getaliasmembership_0(struct torture_context
*torture
)
3326 struct dcerpc_pipe
*p
;
3327 struct dcerpc_binding_handle
*b
;
3328 struct samr_Connect2 c
;
3329 struct samr_OpenDomain o
;
3331 struct lsa_SidPtr ptr
;
3332 struct lsa_SidArray sids
;
3333 struct samr_GetAliasMembership g
;
3334 struct samr_Ids rids
;
3335 struct policy_handle samr
, domain
;
3337 torture_assert_ntstatus_ok(torture
,
3338 torture_rpc_connection(torture
, &p
, &ndr_table_samr
),
3339 "failed to setup samr");
3341 b
= p
->binding_handle
;
3343 c
.in
.system_name
= NULL
;
3344 c
.in
.access_mask
= SAMR_ACCESS_LOOKUP_DOMAIN
;
3345 c
.out
.connect_handle
= &samr
;
3346 torture_assert_ntstatus_ok(torture
,
3347 dcerpc_samr_Connect2_r(b
, torture
, &c
),
3349 torture_assert_ntstatus_ok(torture
, c
.out
.result
,
3351 dom_sid_parse("S-1-5-32", &sid
);
3352 o
.in
.connect_handle
= &samr
;
3353 o
.in
.access_mask
= SAMR_DOMAIN_ACCESS_LOOKUP_ALIAS
;
3355 o
.out
.domain_handle
= &domain
;
3356 torture_assert_ntstatus_ok(torture
,
3357 dcerpc_samr_OpenDomain_r(b
, torture
, &o
),
3359 torture_assert_ntstatus_ok(torture
, o
.out
.result
,
3361 dom_sid_parse("S-1-2-3-4-5", &sid
);
3365 g
.in
.domain_handle
= &domain
;
3368 torture_assert_ntstatus_ok(torture
,
3369 dcerpc_samr_GetAliasMembership_r(b
, torture
, &g
),
3371 torture_assert_ntstatus_ok(torture
, g
.out
.result
,
3373 if (rids
.ids
== NULL
) {
3374 /* This is the piece to test here */
3375 torture_fail(torture
,
3376 "torture_samba3_getaliasmembership_0: "
3377 "Server returns NULL rids array\n");
3384 * Test smb reauthentication while rpc pipe is in use.
3386 static bool torture_rpc_smb_reauth1(struct torture_context
*torture
)
3388 TALLOC_CTX
*mem_ctx
;
3391 struct smbcli_state
*cli
;
3392 struct smbcli_options options
;
3393 struct smbcli_session_options session_options
;
3395 struct dcerpc_pipe
*lsa_pipe
;
3396 struct dcerpc_binding_handle
*lsa_handle
;
3397 struct lsa_GetUserName r
;
3398 struct lsa_String
*authority_name_p
= NULL
;
3399 char *authority_name_saved
= NULL
;
3400 struct lsa_String
*account_name_p
= NULL
;
3401 char *account_name_saved
= NULL
;
3402 struct cli_credentials
*anon_creds
= NULL
;
3403 struct smb_composite_sesssetup io
;
3405 mem_ctx
= talloc_init("torture_samba3_reauth");
3406 torture_assert(torture
, (mem_ctx
!= NULL
), "talloc_init failed");
3408 lpcfg_smbcli_options(torture
->lp_ctx
, &options
);
3409 lpcfg_smbcli_session_options(torture
->lp_ctx
, &session_options
);
3411 status
= smbcli_full_connection(mem_ctx
, &cli
,
3412 torture_setting_string(torture
, "host", NULL
),
3413 lpcfg_smb_ports(torture
->lp_ctx
),
3415 lpcfg_socket_options(torture
->lp_ctx
),
3416 cmdline_credentials
,
3417 lpcfg_resolve_context(torture
->lp_ctx
),
3418 torture
->ev
, &options
, &session_options
,
3419 lpcfg_gensec_settings(torture
, torture
->lp_ctx
));
3420 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3421 "smbcli_full_connection failed");
3423 lsa_pipe
= dcerpc_pipe_init(mem_ctx
, torture
->ev
);
3424 torture_assert_goto(torture
, (lsa_pipe
!= NULL
), ret
, done
,
3425 "dcerpc_pipe_init failed");
3426 lsa_handle
= lsa_pipe
->binding_handle
;
3428 status
= dcerpc_pipe_open_smb(lsa_pipe
, cli
->tree
, "\\lsarpc");
3429 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3430 "dcerpc_pipe_open failed");
3432 status
= dcerpc_bind_auth_none(lsa_pipe
, &ndr_table_lsarpc
);
3433 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3434 "dcerpc_bind_auth_none failed");
3436 /* lsa getusername */
3439 r
.in
.system_name
= "\\";
3440 r
.in
.account_name
= &account_name_p
;
3441 r
.in
.authority_name
= &authority_name_p
;
3442 r
.out
.account_name
= &account_name_p
;
3444 status
= dcerpc_lsa_GetUserName_r(lsa_handle
, mem_ctx
, &r
);
3446 authority_name_p
= *r
.out
.authority_name
;
3448 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3449 "GetUserName failed");
3450 torture_assert_ntstatus_ok_goto(torture
, r
.out
.result
, ret
, done
,
3451 "GetUserName failed");
3453 torture_comment(torture
, "lsa_GetUserName gave '%s\\%s'\n",
3454 authority_name_p
->string
,
3455 account_name_p
->string
);
3457 account_name_saved
= talloc_strdup(mem_ctx
, account_name_p
->string
);
3458 torture_assert_goto(torture
, (account_name_saved
!= NULL
), ret
, done
,
3460 authority_name_saved
= talloc_strdup(mem_ctx
, authority_name_p
->string
);
3461 torture_assert_goto(torture
, (authority_name_saved
!= NULL
), ret
, done
,
3464 /* smb re-authenticate as anonymous */
3466 anon_creds
= cli_credentials_init_anon(mem_ctx
);
3469 io
.in
.sesskey
= cli
->transport
->negotiate
.sesskey
;
3470 io
.in
.capabilities
= cli
->transport
->negotiate
.capabilities
;
3471 io
.in
.credentials
= anon_creds
;
3472 io
.in
.workgroup
= lpcfg_workgroup(torture
->lp_ctx
);
3473 io
.in
.gensec_settings
= lpcfg_gensec_settings(torture
, torture
->lp_ctx
);
3475 status
= smb_composite_sesssetup(cli
->session
, &io
);
3476 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3477 "session reauth to anon failed");
3479 /* re-do lsa getusername after reauth */
3481 TALLOC_FREE(authority_name_p
);
3482 TALLOC_FREE(account_name_p
);
3484 r
.in
.system_name
= "\\";
3485 r
.in
.account_name
= &account_name_p
;
3486 r
.in
.authority_name
= &authority_name_p
;
3487 r
.out
.account_name
= &account_name_p
;
3489 status
= dcerpc_lsa_GetUserName_r(lsa_handle
, mem_ctx
, &r
);
3491 authority_name_p
= *r
.out
.authority_name
;
3493 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3494 "GetUserName failed");
3495 torture_assert_ntstatus_ok_goto(torture
, r
.out
.result
, ret
, done
,
3496 "GetUserName failed");
3498 torture_assert_goto(torture
, (strcmp(authority_name_p
->string
, authority_name_saved
) == 0),
3499 ret
, done
, "authority_name not equal after reauth to anon");
3500 torture_assert_goto(torture
, (strcmp(account_name_p
->string
, account_name_saved
) == 0),
3501 ret
, done
, "account_name not equal after reauth to anon");
3503 /* smb re-auth again to the original user */
3506 io
.in
.sesskey
= cli
->transport
->negotiate
.sesskey
;
3507 io
.in
.capabilities
= cli
->transport
->negotiate
.capabilities
;
3508 io
.in
.credentials
= cmdline_credentials
;
3509 io
.in
.workgroup
= lpcfg_workgroup(torture
->lp_ctx
);
3510 io
.in
.gensec_settings
= lpcfg_gensec_settings(torture
, torture
->lp_ctx
);
3512 status
= smb_composite_sesssetup(cli
->session
, &io
);
3513 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3514 "session reauth to anon failed");
3516 /* re-do lsa getusername */
3518 TALLOC_FREE(authority_name_p
);
3519 TALLOC_FREE(account_name_p
);
3521 r
.in
.system_name
= "\\";
3522 r
.in
.account_name
= &account_name_p
;
3523 r
.in
.authority_name
= &authority_name_p
;
3524 r
.out
.account_name
= &account_name_p
;
3526 status
= dcerpc_lsa_GetUserName_r(lsa_handle
, mem_ctx
, &r
);
3528 authority_name_p
= *r
.out
.authority_name
;
3530 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3531 "GetUserName failed");
3532 torture_assert_ntstatus_ok_goto(torture
, r
.out
.result
, ret
, done
,
3533 "GetUserName failed");
3535 torture_assert_goto(torture
, (strcmp(authority_name_p
->string
, authority_name_saved
) == 0),
3536 ret
, done
, "authority_name not equal after reauth to anon");
3537 torture_assert_goto(torture
, (strcmp(account_name_p
->string
, account_name_saved
) == 0),
3538 ret
, done
, "account_name not equal after reauth to anon");
3543 talloc_free(mem_ctx
);
3548 * Test smb reauthentication while rpc pipe is in use.
3549 * Open a second lsa bind after reauth to anon.
3550 * Do lsa getusername on that second bind.
3552 static bool torture_rpc_smb_reauth2(struct torture_context
*torture
)
3554 TALLOC_CTX
*mem_ctx
;
3557 struct smbcli_state
*cli
;
3558 struct smbcli_options options
;
3559 struct smbcli_session_options session_options
;
3561 struct dcerpc_pipe
*lsa_pipe
;
3562 struct dcerpc_binding_handle
*lsa_handle
;
3563 struct lsa_GetUserName r
;
3564 struct lsa_String
*authority_name_p
= NULL
;
3565 char *authority_name_saved
= NULL
;
3566 struct lsa_String
*account_name_p
= NULL
;
3567 char *account_name_saved
= NULL
;
3568 struct cli_credentials
*anon_creds
= NULL
;
3569 struct smb_composite_sesssetup io
;
3571 mem_ctx
= talloc_init("torture_samba3_reauth");
3572 torture_assert(torture
, (mem_ctx
!= NULL
), "talloc_init failed");
3574 lpcfg_smbcli_options(torture
->lp_ctx
, &options
);
3575 lpcfg_smbcli_session_options(torture
->lp_ctx
, &session_options
);
3577 status
= smbcli_full_connection(mem_ctx
, &cli
,
3578 torture_setting_string(torture
, "host", NULL
),
3579 lpcfg_smb_ports(torture
->lp_ctx
),
3581 lpcfg_socket_options(torture
->lp_ctx
),
3582 cmdline_credentials
,
3583 lpcfg_resolve_context(torture
->lp_ctx
),
3584 torture
->ev
, &options
, &session_options
,
3585 lpcfg_gensec_settings(torture
, torture
->lp_ctx
));
3586 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3587 "smbcli_full_connection failed");
3589 /* smb re-authenticate as anonymous */
3591 anon_creds
= cli_credentials_init_anon(mem_ctx
);
3594 io
.in
.sesskey
= cli
->transport
->negotiate
.sesskey
;
3595 io
.in
.capabilities
= cli
->transport
->negotiate
.capabilities
;
3596 io
.in
.credentials
= anon_creds
;
3597 io
.in
.workgroup
= lpcfg_workgroup(torture
->lp_ctx
);
3598 io
.in
.gensec_settings
= lpcfg_gensec_settings(torture
, torture
->lp_ctx
);
3600 status
= smb_composite_sesssetup(cli
->session
, &io
);
3601 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3602 "session reauth to anon failed");
3604 /* open the lsa pipe */
3606 lsa_pipe
= dcerpc_pipe_init(mem_ctx
, torture
->ev
);
3607 torture_assert_goto(torture
, (lsa_pipe
!= NULL
), ret
, done
,
3608 "dcerpc_pipe_init failed");
3609 lsa_handle
= lsa_pipe
->binding_handle
;
3611 status
= dcerpc_pipe_open_smb(lsa_pipe
, cli
->tree
, "\\lsarpc");
3612 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3613 "dcerpc_pipe_open failed");
3615 status
= dcerpc_bind_auth_none(lsa_pipe
, &ndr_table_lsarpc
);
3616 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3617 "dcerpc_bind_auth_none failed");
3619 /* lsa getusername */
3622 r
.in
.system_name
= "\\";
3623 r
.in
.account_name
= &account_name_p
;
3624 r
.in
.authority_name
= &authority_name_p
;
3625 r
.out
.account_name
= &account_name_p
;
3627 status
= dcerpc_lsa_GetUserName_r(lsa_handle
, mem_ctx
, &r
);
3629 authority_name_p
= *r
.out
.authority_name
;
3631 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3632 "GetUserName failed");
3633 torture_assert_ntstatus_ok_goto(torture
, r
.out
.result
, ret
, done
,
3634 "GetUserName failed");
3636 torture_comment(torture
, "lsa_GetUserName gave '%s\\%s'\n",
3637 authority_name_p
->string
,
3638 account_name_p
->string
);
3640 account_name_saved
= talloc_strdup(mem_ctx
, account_name_p
->string
);
3641 torture_assert_goto(torture
, (account_name_saved
!= NULL
), ret
, done
,
3643 authority_name_saved
= talloc_strdup(mem_ctx
, authority_name_p
->string
);
3644 torture_assert_goto(torture
, (authority_name_saved
!= NULL
), ret
, done
,
3647 /* smb re-auth again to the original user */
3650 io
.in
.sesskey
= cli
->transport
->negotiate
.sesskey
;
3651 io
.in
.capabilities
= cli
->transport
->negotiate
.capabilities
;
3652 io
.in
.credentials
= cmdline_credentials
;
3653 io
.in
.workgroup
= lpcfg_workgroup(torture
->lp_ctx
);
3654 io
.in
.gensec_settings
= lpcfg_gensec_settings(torture
, torture
->lp_ctx
);
3656 status
= smb_composite_sesssetup(cli
->session
, &io
);
3657 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3658 "session reauth to anon failed");
3660 /* re-do lsa getusername after reauth */
3662 TALLOC_FREE(authority_name_p
);
3663 TALLOC_FREE(account_name_p
);
3665 r
.in
.system_name
= "\\";
3666 r
.in
.account_name
= &account_name_p
;
3667 r
.in
.authority_name
= &authority_name_p
;
3668 r
.out
.account_name
= &account_name_p
;
3670 status
= dcerpc_lsa_GetUserName_r(lsa_handle
, mem_ctx
, &r
);
3672 authority_name_p
= *r
.out
.authority_name
;
3674 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3675 "GetUserName failed");
3676 torture_assert_ntstatus_ok_goto(torture
, r
.out
.result
, ret
, done
,
3677 "GetUserName failed");
3679 torture_assert_goto(torture
, (strcmp(authority_name_p
->string
, authority_name_saved
) == 0),
3680 ret
, done
, "authority_name not equal after reauth to anon");
3681 torture_assert_goto(torture
, (strcmp(account_name_p
->string
, account_name_saved
) == 0),
3682 ret
, done
, "account_name not equal after reauth to anon");
3687 talloc_free(mem_ctx
);
3692 * Test smb2 reauthentication while rpc pipe is in use.
3694 static bool torture_rpc_smb2_reauth1(struct torture_context
*torture
)
3696 TALLOC_CTX
*mem_ctx
;
3699 struct smbcli_options options
;
3701 struct dcerpc_pipe
*lsa_pipe
;
3702 struct dcerpc_binding_handle
*lsa_handle
;
3703 struct lsa_GetUserName r
;
3704 struct lsa_String
*authority_name_p
= NULL
;
3705 char *authority_name_saved
= NULL
;
3706 struct lsa_String
*account_name_p
= NULL
;
3707 char *account_name_saved
= NULL
;
3708 struct cli_credentials
*anon_creds
= NULL
;
3709 const char *host
= torture_setting_string(torture
, "host", NULL
);
3710 struct smb2_tree
*tree
;
3712 mem_ctx
= talloc_init("torture_samba3_reauth");
3713 torture_assert(torture
, (mem_ctx
!= NULL
), "talloc_init failed");
3715 lpcfg_smbcli_options(torture
->lp_ctx
, &options
);
3717 status
= smb2_connect(mem_ctx
,
3719 lpcfg_smb_ports(torture
->lp_ctx
),
3721 lpcfg_resolve_context(torture
->lp_ctx
),
3722 cmdline_credentials
,
3726 lpcfg_socket_options(torture
->lp_ctx
),
3727 lpcfg_gensec_settings(torture
, torture
->lp_ctx
)
3729 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3730 "smb2_connect failed");
3732 lsa_pipe
= dcerpc_pipe_init(mem_ctx
, torture
->ev
);
3733 torture_assert_goto(torture
, (lsa_pipe
!= NULL
), ret
, done
,
3734 "dcerpc_pipe_init failed");
3735 lsa_handle
= lsa_pipe
->binding_handle
;
3737 status
= dcerpc_pipe_open_smb2(lsa_pipe
, tree
, "lsarpc");
3738 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3739 "dcerpc_pipe_open_smb2 failed");
3741 status
= dcerpc_bind_auth_none(lsa_pipe
, &ndr_table_lsarpc
);
3742 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3743 "dcerpc_bind_auth_none failed");
3745 /* lsa getusername */
3748 r
.in
.system_name
= "\\";
3749 r
.in
.account_name
= &account_name_p
;
3750 r
.in
.authority_name
= &authority_name_p
;
3751 r
.out
.account_name
= &account_name_p
;
3753 status
= dcerpc_lsa_GetUserName_r(lsa_handle
, mem_ctx
, &r
);
3755 authority_name_p
= *r
.out
.authority_name
;
3757 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3758 "GetUserName failed");
3759 torture_assert_ntstatus_ok_goto(torture
, r
.out
.result
, ret
, done
,
3760 "GetUserName failed");
3762 torture_comment(torture
, "lsa_GetUserName gave '%s\\%s'\n",
3763 authority_name_p
->string
,
3764 account_name_p
->string
);
3766 account_name_saved
= talloc_strdup(mem_ctx
, account_name_p
->string
);
3767 torture_assert_goto(torture
, (account_name_saved
!= NULL
), ret
, done
,
3769 authority_name_saved
= talloc_strdup(mem_ctx
, authority_name_p
->string
);
3770 torture_assert_goto(torture
, (authority_name_saved
!= NULL
), ret
, done
,
3773 /* smb re-authenticate as anonymous */
3775 anon_creds
= cli_credentials_init_anon(mem_ctx
);
3777 status
= smb2_session_setup_spnego(tree
->session
,
3779 0 /* previous_session_id */);
3780 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3781 "session reauth to anon failed");
3783 /* re-do lsa getusername after reauth */
3785 TALLOC_FREE(authority_name_p
);
3786 TALLOC_FREE(account_name_p
);
3788 r
.in
.system_name
= "\\";
3789 r
.in
.account_name
= &account_name_p
;
3790 r
.in
.authority_name
= &authority_name_p
;
3791 r
.out
.account_name
= &account_name_p
;
3793 status
= dcerpc_lsa_GetUserName_r(lsa_handle
, mem_ctx
, &r
);
3795 authority_name_p
= *r
.out
.authority_name
;
3797 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3798 "GetUserName failed");
3799 torture_assert_ntstatus_ok_goto(torture
, r
.out
.result
, ret
, done
,
3800 "GetUserName failed");
3802 torture_assert_goto(torture
, (strcmp(authority_name_p
->string
, authority_name_saved
) == 0),
3803 ret
, done
, "authority_name not equal after reauth to anon");
3804 torture_assert_goto(torture
, (strcmp(account_name_p
->string
, account_name_saved
) == 0),
3805 ret
, done
, "account_name not equal after reauth to anon");
3807 /* smb re-auth again to the original user */
3809 status
= smb2_session_setup_spnego(tree
->session
,
3810 cmdline_credentials
,
3811 0 /* previous_session_id */);
3812 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3813 "session reauth to anon failed");
3815 /* re-do lsa getusername */
3817 TALLOC_FREE(authority_name_p
);
3818 TALLOC_FREE(account_name_p
);
3820 r
.in
.system_name
= "\\";
3821 r
.in
.account_name
= &account_name_p
;
3822 r
.in
.authority_name
= &authority_name_p
;
3823 r
.out
.account_name
= &account_name_p
;
3825 status
= dcerpc_lsa_GetUserName_r(lsa_handle
, mem_ctx
, &r
);
3827 authority_name_p
= *r
.out
.authority_name
;
3829 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3830 "GetUserName failed");
3831 torture_assert_ntstatus_ok_goto(torture
, r
.out
.result
, ret
, done
,
3832 "GetUserName failed");
3834 torture_assert_goto(torture
, (strcmp(authority_name_p
->string
, authority_name_saved
) == 0),
3835 ret
, done
, "authority_name not equal after reauth to anon");
3836 torture_assert_goto(torture
, (strcmp(account_name_p
->string
, account_name_saved
) == 0),
3837 ret
, done
, "account_name not equal after reauth to anon");
3842 talloc_free(mem_ctx
);
3847 * Test smb2 reauthentication while rpc pipe is in use.
3848 * Open a second lsa bind after reauth to anon.
3849 * Do lsa getusername on that second bind.
3851 static bool torture_rpc_smb2_reauth2(struct torture_context
*torture
)
3853 TALLOC_CTX
*mem_ctx
;
3856 struct smbcli_options options
;
3858 struct dcerpc_pipe
*lsa_pipe
;
3859 struct dcerpc_binding_handle
*lsa_handle
;
3860 struct lsa_GetUserName r
;
3861 struct lsa_String
*authority_name_p
= NULL
;
3862 char *authority_name_saved
= NULL
;
3863 struct lsa_String
*account_name_p
= NULL
;
3864 char *account_name_saved
= NULL
;
3865 struct cli_credentials
*anon_creds
= NULL
;
3866 const char *host
= torture_setting_string(torture
, "host", NULL
);
3867 struct smb2_tree
*tree
;
3869 mem_ctx
= talloc_init("torture_samba3_reauth");
3870 torture_assert(torture
, (mem_ctx
!= NULL
), "talloc_init failed");
3872 lpcfg_smbcli_options(torture
->lp_ctx
, &options
);
3874 status
= smb2_connect(mem_ctx
,
3876 lpcfg_smb_ports(torture
->lp_ctx
),
3878 lpcfg_resolve_context(torture
->lp_ctx
),
3879 cmdline_credentials
,
3883 lpcfg_socket_options(torture
->lp_ctx
),
3884 lpcfg_gensec_settings(torture
, torture
->lp_ctx
)
3886 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3887 "smb2_connect failed");
3889 /* smb re-authenticate as anonymous */
3891 anon_creds
= cli_credentials_init_anon(mem_ctx
);
3893 status
= smb2_session_setup_spnego(tree
->session
,
3895 0 /* previous_session_id */);
3896 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3897 "session reauth to anon failed");
3899 /* open the lsa pipe */
3901 lsa_pipe
= dcerpc_pipe_init(mem_ctx
, torture
->ev
);
3902 torture_assert_goto(torture
, (lsa_pipe
!= NULL
), ret
, done
,
3903 "dcerpc_pipe_init failed");
3904 lsa_handle
= lsa_pipe
->binding_handle
;
3906 status
= dcerpc_pipe_open_smb2(lsa_pipe
, tree
, "lsarpc");
3907 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3908 "dcerpc_pipe_open_smb2 failed");
3910 status
= dcerpc_bind_auth_none(lsa_pipe
, &ndr_table_lsarpc
);
3911 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3912 "dcerpc_bind_auth_none failed");
3914 /* lsa getusername */
3917 r
.in
.system_name
= "\\";
3918 r
.in
.account_name
= &account_name_p
;
3919 r
.in
.authority_name
= &authority_name_p
;
3920 r
.out
.account_name
= &account_name_p
;
3922 status
= dcerpc_lsa_GetUserName_r(lsa_handle
, mem_ctx
, &r
);
3924 authority_name_p
= *r
.out
.authority_name
;
3926 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3927 "GetUserName failed");
3928 torture_assert_ntstatus_ok_goto(torture
, r
.out
.result
, ret
, done
,
3929 "GetUserName failed");
3931 torture_comment(torture
, "lsa_GetUserName gave '%s\\%s'\n",
3932 authority_name_p
->string
,
3933 account_name_p
->string
);
3935 account_name_saved
= talloc_strdup(mem_ctx
, account_name_p
->string
);
3936 torture_assert_goto(torture
, (account_name_saved
!= NULL
), ret
, done
,
3938 authority_name_saved
= talloc_strdup(mem_ctx
, authority_name_p
->string
);
3939 torture_assert_goto(torture
, (authority_name_saved
!= NULL
), ret
, done
,
3942 /* smb re-auth again to the original user */
3944 status
= smb2_session_setup_spnego(tree
->session
,
3945 cmdline_credentials
,
3946 0 /* previous_session_id */);
3947 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3948 "session reauth to anon failed");
3950 /* re-do lsa getusername */
3952 TALLOC_FREE(authority_name_p
);
3953 TALLOC_FREE(account_name_p
);
3955 r
.in
.system_name
= "\\";
3956 r
.in
.account_name
= &account_name_p
;
3957 r
.in
.authority_name
= &authority_name_p
;
3958 r
.out
.account_name
= &account_name_p
;
3960 status
= dcerpc_lsa_GetUserName_r(lsa_handle
, mem_ctx
, &r
);
3962 authority_name_p
= *r
.out
.authority_name
;
3964 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3965 "GetUserName failed");
3966 torture_assert_ntstatus_ok_goto(torture
, r
.out
.result
, ret
, done
,
3967 "GetUserName failed");
3969 torture_assert_goto(torture
, (strcmp(authority_name_p
->string
, authority_name_saved
) == 0),
3970 ret
, done
, "authority_name not equal after reauth to anon");
3971 torture_assert_goto(torture
, (strcmp(account_name_p
->string
, account_name_saved
) == 0),
3972 ret
, done
, "account_name not equal after reauth to anon");
3977 talloc_free(mem_ctx
);
3981 static bool torture_rpc_smb1_pipe_name(struct torture_context
*torture
)
3983 TALLOC_CTX
*mem_ctx
;
3986 struct smbcli_state
*cli
;
3987 struct smbcli_options options
;
3988 struct smbcli_session_options session_options
;
3993 mem_ctx
= talloc_init("torture_samba3_smb1_pipe_name");
3994 torture_assert(torture
, (mem_ctx
!= NULL
), "talloc_init failed");
3996 lpcfg_smbcli_options(torture
->lp_ctx
, &options
);
3997 lpcfg_smbcli_session_options(torture
->lp_ctx
, &session_options
);
3999 status
= smbcli_full_connection(mem_ctx
, &cli
,
4000 torture_setting_string(torture
, "host", NULL
),
4001 lpcfg_smb_ports(torture
->lp_ctx
),
4003 lpcfg_socket_options(torture
->lp_ctx
),
4004 cmdline_credentials
,
4005 lpcfg_resolve_context(torture
->lp_ctx
),
4006 torture
->ev
, &options
, &session_options
,
4007 lpcfg_gensec_settings(torture
, torture
->lp_ctx
));
4008 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4009 "smbcli_full_connection failed");
4012 io
.generic
.level
= RAW_OPEN_NTCREATEX
;
4013 io
.ntcreatex
.in
.access_mask
= DESIRED_ACCESS_PIPE
;
4014 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
4015 NTCREATEX_SHARE_ACCESS_WRITE
;
4016 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_OPEN
;
4017 io
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_IMPERSONATION
;
4018 io
.ntcreatex
.in
.security_flags
= 0;
4020 io
.ntcreatex
.in
.fname
= "__none__";
4021 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4022 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
4024 "smb_raw_open for '__none__'");
4026 io
.ntcreatex
.in
.fname
= "pipe\\srvsvc";
4027 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4028 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
4030 "smb_raw_open for 'pipe\\srvsvc'");
4032 io
.ntcreatex
.in
.fname
= "\\pipe\\srvsvc";
4033 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4034 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
4036 "smb_raw_open for '\\pipe\\srvsvc'");
4038 io
.ntcreatex
.in
.fname
= "srvsvc";
4039 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4040 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4041 "smb2_create failed for 'srvsvc'");
4042 fnum
= io
.ntcreatex
.out
.file
.fnum
;
4044 cl
.generic
.level
= RAW_CLOSE_CLOSE
;
4045 cl
.close
.in
.file
.fnum
= fnum
;
4046 status
= smb_raw_close(cli
->tree
, &cl
);
4047 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4048 "smb_raw_close failed");
4050 io
.ntcreatex
.in
.fname
= "\\srvsvc";
4051 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4052 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4053 "smb2_create failed for '\\srvsvc'");
4054 fnum
= io
.ntcreatex
.out
.file
.fnum
;
4056 cl
.generic
.level
= RAW_CLOSE_CLOSE
;
4057 cl
.close
.in
.file
.fnum
= fnum
;
4058 status
= smb_raw_close(cli
->tree
, &cl
);
4059 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4060 "smb_raw_close failed");
4062 io
.ntcreatex
.in
.fname
= "\\\\\\\\\\srvsvc";
4063 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4064 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4065 "smb2_create failed for '\\\\\\\\\\srvsvc'");
4066 fnum
= io
.ntcreatex
.out
.file
.fnum
;
4068 cl
.generic
.level
= RAW_CLOSE_CLOSE
;
4069 cl
.close
.in
.file
.fnum
= fnum
;
4070 status
= smb_raw_close(cli
->tree
, &cl
);
4071 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4072 "smb_raw_close failed");
4075 io
.generic
.level
= RAW_OPEN_NTTRANS_CREATE
;
4076 io
.nttrans
.in
.access_mask
= DESIRED_ACCESS_PIPE
;
4077 io
.nttrans
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
4078 NTCREATEX_SHARE_ACCESS_WRITE
;
4079 io
.nttrans
.in
.open_disposition
= NTCREATEX_DISP_OPEN
;
4080 io
.nttrans
.in
.impersonation
= NTCREATEX_IMPERSONATION_IMPERSONATION
;
4081 io
.nttrans
.in
.security_flags
= 0;
4083 io
.nttrans
.in
.fname
= "__none__";
4084 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4085 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
4087 "smb_raw_open for '__none__'");
4089 io
.nttrans
.in
.fname
= "pipe\\srvsvc";
4090 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4091 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
4093 "smb_raw_open for 'pipe\\srvsvc'");
4095 io
.nttrans
.in
.fname
= "\\pipe\\srvsvc";
4096 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4097 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
4099 "smb_raw_open for '\\pipe\\srvsvc'");
4101 io
.nttrans
.in
.fname
= "srvsvc";
4102 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4103 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4104 "smb2_create failed for 'srvsvc'");
4105 fnum
= io
.nttrans
.out
.file
.fnum
;
4107 cl
.generic
.level
= RAW_CLOSE_CLOSE
;
4108 cl
.close
.in
.file
.fnum
= fnum
;
4109 status
= smb_raw_close(cli
->tree
, &cl
);
4110 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4111 "smb_raw_close failed");
4113 io
.nttrans
.in
.fname
= "\\srvsvc";
4114 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4115 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4116 "smb2_create failed for '\\srvsvc'");
4117 fnum
= io
.nttrans
.out
.file
.fnum
;
4119 cl
.generic
.level
= RAW_CLOSE_CLOSE
;
4120 cl
.close
.in
.file
.fnum
= fnum
;
4121 status
= smb_raw_close(cli
->tree
, &cl
);
4122 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4123 "smb_raw_close failed");
4125 io
.nttrans
.in
.fname
= "\\\\\\\\\\srvsvc";
4126 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4127 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4128 "smb2_create failed for '\\\\\\\\\\srvsvc'");
4129 fnum
= io
.nttrans
.out
.file
.fnum
;
4131 cl
.generic
.level
= RAW_CLOSE_CLOSE
;
4132 cl
.close
.in
.file
.fnum
= fnum
;
4133 status
= smb_raw_close(cli
->tree
, &cl
);
4134 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4135 "smb_raw_close failed");
4138 io
.generic
.level
= RAW_OPEN_OPENX
;
4139 io
.openx
.in
.open_mode
= OPENX_MODE_ACCESS_RDWR
;
4140 io
.openx
.in
.open_func
= OPENX_OPEN_FUNC_OPEN
;
4142 io
.openx
.in
.fname
= "__none__";
4143 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4144 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_OBJECT_PATH_SYNTAX_BAD
,
4146 "smb_raw_open for '__none__'");
4148 io
.openx
.in
.fname
= "srvsvc";
4149 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4150 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_OBJECT_PATH_SYNTAX_BAD
,
4152 "smb_raw_open for 'srvsvc'");
4154 io
.openx
.in
.fname
= "\\srvsvc";
4155 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4156 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_OBJECT_PATH_SYNTAX_BAD
,
4158 "smb_raw_open for '\\srvsvc'");
4160 io
.openx
.in
.fname
= "\\pipesrvsvc";
4161 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4162 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_OBJECT_PATH_SYNTAX_BAD
,
4164 "smb_raw_open for '\\pipesrvsvc'");
4166 io
.openx
.in
.fname
= "pipe\\__none__";
4167 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4168 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
4170 "smb_raw_open for 'pipe\\__none__'");
4172 io
.openx
.in
.fname
= "\\pipe\\__none__";
4173 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4174 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
4176 "smb_raw_open for '\\pipe\\__none__'");
4178 io
.openx
.in
.fname
= "pipe\\srvsvc";
4179 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4180 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4181 "smb2_create failed for 'pipe\\srvsvc'");
4182 fnum
= io
.openx
.out
.file
.fnum
;
4184 cl
.generic
.level
= RAW_CLOSE_CLOSE
;
4185 cl
.close
.in
.file
.fnum
= fnum
;
4186 status
= smb_raw_close(cli
->tree
, &cl
);
4187 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4188 "smb_raw_close failed");
4190 io
.openx
.in
.fname
= "\\pipe\\srvsvc";
4191 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4192 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4193 "smb2_create failed for '\\pipe\\srvsvc'");
4194 fnum
= io
.openx
.out
.file
.fnum
;
4196 cl
.generic
.level
= RAW_CLOSE_CLOSE
;
4197 cl
.close
.in
.file
.fnum
= fnum
;
4198 status
= smb_raw_close(cli
->tree
, &cl
);
4199 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4200 "smb_raw_close failed");
4202 io
.openx
.in
.fname
= "\\\\\\\\\\pipe\\srvsvc";
4203 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4204 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4205 "smb2_create failed for '\\\\\\\\\\pipe\\srvsvc'");
4206 fnum
= io
.openx
.out
.file
.fnum
;
4208 cl
.generic
.level
= RAW_CLOSE_CLOSE
;
4209 cl
.close
.in
.file
.fnum
= fnum
;
4210 status
= smb_raw_close(cli
->tree
, &cl
);
4211 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4212 "smb_raw_close failed");
4214 io
.openx
.in
.fname
= "\\\\\\\\\\pipe\\\\\\\\\\srvsvc";
4215 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4216 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4217 "smb2_create failed for '\\\\\\\\\\pipe\\\\\\\\\\srvsvc'");
4218 fnum
= io
.openx
.out
.file
.fnum
;
4220 cl
.generic
.level
= RAW_CLOSE_CLOSE
;
4221 cl
.close
.in
.file
.fnum
= fnum
;
4222 status
= smb_raw_close(cli
->tree
, &cl
);
4223 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4224 "smb_raw_close failed");
4228 talloc_free(mem_ctx
);
4232 static bool torture_rpc_smb2_pipe_name(struct torture_context
*torture
)
4234 TALLOC_CTX
*mem_ctx
;
4237 struct smbcli_options options
;
4238 const char *host
= torture_setting_string(torture
, "host", NULL
);
4239 struct smb2_tree
*tree
;
4240 struct smb2_handle h
;
4241 struct smb2_create io
;
4243 mem_ctx
= talloc_init("torture_samba3_smb2_pipe_name");
4244 torture_assert(torture
, (mem_ctx
!= NULL
), "talloc_init failed");
4246 lpcfg_smbcli_options(torture
->lp_ctx
, &options
);
4248 status
= smb2_connect(mem_ctx
,
4250 lpcfg_smb_ports(torture
->lp_ctx
),
4252 lpcfg_resolve_context(torture
->lp_ctx
),
4253 cmdline_credentials
,
4257 lpcfg_socket_options(torture
->lp_ctx
),
4258 lpcfg_gensec_settings(torture
, torture
->lp_ctx
)
4260 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4261 "smb2_connect failed");
4264 io
.in
.oplock_level
= 0;
4265 io
.in
.desired_access
= DESIRED_ACCESS_PIPE
;
4266 io
.in
.impersonation_level
= SMB2_IMPERSONATION_IMPERSONATION
;
4267 io
.in
.file_attributes
= 0;
4268 io
.in
.create_disposition
= NTCREATEX_DISP_OPEN
;
4269 io
.in
.share_access
=
4270 NTCREATEX_SHARE_ACCESS_READ
|
4271 NTCREATEX_SHARE_ACCESS_WRITE
;
4272 io
.in
.create_options
= 0;
4274 io
.in
.fname
= "__none__";
4275 status
= smb2_create(tree
, tree
, &io
);
4276 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
4278 "smb2_create for '__none__'");
4280 io
.in
.fname
= "\\srvsvc";
4281 status
= smb2_create(tree
, tree
, &io
);
4282 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
4284 "smb2_create for '\\srvsvc'");
4286 io
.in
.fname
= "\\pipe\\srvsvc";
4287 status
= smb2_create(tree
, tree
, &io
);
4288 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
4290 "smb2_create for '\\pipe\\srvsvc'");
4292 io
.in
.fname
= "pipe\\srvsvc";
4293 status
= smb2_create(tree
, tree
, &io
);
4294 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
4296 "smb2_create for 'pipe\\srvsvc'");
4298 io
.in
.fname
= "srvsvc";
4299 status
= smb2_create(tree
, tree
, &io
);
4300 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4301 "smb2_create failed for 'srvsvc'");
4303 h
= io
.out
.file
.handle
;
4305 status
= smb2_util_close(tree
, h
);
4306 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4307 "smb2_util_close failed");
4311 talloc_free(mem_ctx
);
4316 * Test behaviour of a waiting read call on a pipe when
4317 * the pipe handle is closed:
4318 * - open a pipe via smb2
4319 * - trigger a read which hangs since there is nothing to read
4320 * - close the pipe file handle
4321 * - wait for the read to return and check the status
4322 * (STATUS_PIPE_BROKEN)
4324 static bool torture_rpc_smb2_pipe_read_close(struct torture_context
*torture
)
4326 TALLOC_CTX
*mem_ctx
;
4329 struct smbcli_options options
;
4330 const char *host
= torture_setting_string(torture
, "host", NULL
);
4331 struct smb2_tree
*tree
;
4332 struct smb2_handle h
;
4333 struct smb2_request
*smb2req
;
4334 struct smb2_create io
;
4335 struct smb2_read rd
;
4337 mem_ctx
= talloc_init("torture_samba3_pipe_read_close");
4338 torture_assert(torture
, (mem_ctx
!= NULL
), "talloc_init failed");
4340 lpcfg_smbcli_options(torture
->lp_ctx
, &options
);
4342 status
= smb2_connect(mem_ctx
,
4344 lpcfg_smb_ports(torture
->lp_ctx
),
4346 lpcfg_resolve_context(torture
->lp_ctx
),
4347 cmdline_credentials
,
4351 lpcfg_socket_options(torture
->lp_ctx
),
4352 lpcfg_gensec_settings(torture
, torture
->lp_ctx
)
4354 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4355 "smb2_connect failed");
4358 io
.in
.oplock_level
= 0;
4359 io
.in
.desired_access
= DESIRED_ACCESS_PIPE
;
4360 io
.in
.impersonation_level
= SMB2_IMPERSONATION_IMPERSONATION
;
4361 io
.in
.file_attributes
= 0;
4362 io
.in
.create_disposition
= NTCREATEX_DISP_OPEN
;
4363 io
.in
.share_access
=
4364 NTCREATEX_SHARE_ACCESS_READ
|
4365 NTCREATEX_SHARE_ACCESS_WRITE
;
4366 io
.in
.create_options
= 0;
4367 io
.in
.fname
= "lsarpc";
4369 status
= smb2_create(tree
, tree
, &io
);
4370 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4371 "smb2_create failed for 'lsarpc'");
4373 h
= io
.out
.file
.handle
;
4376 rd
.in
.file
.handle
= h
;
4377 rd
.in
.length
= 1024;
4379 rd
.in
.min_count
= 0;
4381 smb2req
= smb2_read_send(tree
, &rd
);
4382 torture_assert_goto(torture
, (smb2req
!= NULL
), ret
, done
,
4383 "smb2_read_send failed");
4385 status
= smb2_util_close(tree
, h
);
4386 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4387 "smb2_util_close failed");
4389 status
= smb2_read_recv(smb2req
, mem_ctx
, &rd
);
4390 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_PIPE_BROKEN
, ret
, done
,
4391 "smb2_read_recv: unexpected return code");
4395 talloc_free(mem_ctx
);
4400 * Test behaviour of a waiting read call on a pipe when
4401 * the tree is disconnected.
4402 * - open a pipe via smb2
4403 * - trigger a read which hangs since there is nothing to read
4404 * - do a tree disconnect
4405 * - wait for the read to return and check the status
4406 * (STATUS_PIPE_BROKEN)
4408 static bool torture_rpc_smb2_pipe_read_tdis(struct torture_context
*torture
)
4410 TALLOC_CTX
*mem_ctx
;
4413 struct smbcli_options options
;
4414 const char *host
= torture_setting_string(torture
, "host", NULL
);
4415 struct smb2_tree
*tree
;
4416 struct smb2_handle h
;
4417 struct smb2_request
*smb2req
;
4418 struct smb2_create io
;
4419 struct smb2_read rd
;
4421 mem_ctx
= talloc_init("torture_samba3_pipe_read_tdis");
4422 torture_assert(torture
, (mem_ctx
!= NULL
), "talloc_init failed");
4424 lpcfg_smbcli_options(torture
->lp_ctx
, &options
);
4426 status
= smb2_connect(mem_ctx
,
4428 lpcfg_smb_ports(torture
->lp_ctx
),
4430 lpcfg_resolve_context(torture
->lp_ctx
),
4431 cmdline_credentials
,
4435 lpcfg_socket_options(torture
->lp_ctx
),
4436 lpcfg_gensec_settings(torture
, torture
->lp_ctx
)
4438 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4439 "smb2_connect failed");
4442 io
.in
.oplock_level
= 0;
4443 io
.in
.desired_access
= DESIRED_ACCESS_PIPE
;
4444 io
.in
.impersonation_level
= SMB2_IMPERSONATION_IMPERSONATION
;
4445 io
.in
.file_attributes
= 0;
4446 io
.in
.create_disposition
= NTCREATEX_DISP_OPEN
;
4447 io
.in
.share_access
=
4448 NTCREATEX_SHARE_ACCESS_READ
|
4449 NTCREATEX_SHARE_ACCESS_WRITE
;
4450 io
.in
.create_options
= 0;
4451 io
.in
.fname
= "lsarpc";
4453 status
= smb2_create(tree
, tree
, &io
);
4454 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4455 "smb2_create failed for 'lsarpc'");
4457 h
= io
.out
.file
.handle
;
4460 rd
.in
.file
.handle
= h
;
4461 rd
.in
.length
= 1024;
4463 rd
.in
.min_count
= 0;
4465 smb2req
= smb2_read_send(tree
, &rd
);
4466 torture_assert_goto(torture
, (smb2req
!= NULL
), ret
, done
,
4467 "smb2_read_send failed");
4469 status
= smb2_tdis(tree
);
4470 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4471 "smb2_tdis failed");
4473 status
= smb2_read_recv(smb2req
, mem_ctx
, &rd
);
4474 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_PIPE_BROKEN
, ret
, done
,
4475 "smb2_read_recv: unexpected return code");
4479 talloc_free(mem_ctx
);
4484 * Test behaviour of a waiting read call on a pipe when
4486 * - open a pipe via smb2
4487 * - trigger a read which hangs since there is nothing to read
4489 * - wait for the read to return and check the status
4490 * (STATUS_PIPE_BROKEN)
4492 static bool torture_rpc_smb2_pipe_read_logoff(struct torture_context
*torture
)
4494 TALLOC_CTX
*mem_ctx
;
4497 struct smbcli_options options
;
4498 const char *host
= torture_setting_string(torture
, "host", NULL
);
4499 struct smb2_tree
*tree
;
4500 struct smb2_handle h
;
4501 struct smb2_request
*smb2req
;
4502 struct smb2_create io
;
4503 struct smb2_read rd
;
4505 mem_ctx
= talloc_init("torture_samba3_pipe_read_tdis");
4506 torture_assert(torture
, (mem_ctx
!= NULL
), "talloc_init failed");
4508 lpcfg_smbcli_options(torture
->lp_ctx
, &options
);
4510 status
= smb2_connect(mem_ctx
,
4512 lpcfg_smb_ports(torture
->lp_ctx
),
4514 lpcfg_resolve_context(torture
->lp_ctx
),
4515 cmdline_credentials
,
4519 lpcfg_socket_options(torture
->lp_ctx
),
4520 lpcfg_gensec_settings(torture
, torture
->lp_ctx
)
4522 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4523 "smb2_connect failed");
4526 io
.in
.oplock_level
= 0;
4527 io
.in
.desired_access
= DESIRED_ACCESS_PIPE
;
4528 io
.in
.impersonation_level
= SMB2_IMPERSONATION_IMPERSONATION
;
4529 io
.in
.file_attributes
= 0;
4530 io
.in
.create_disposition
= NTCREATEX_DISP_OPEN
;
4531 io
.in
.share_access
=
4532 NTCREATEX_SHARE_ACCESS_READ
|
4533 NTCREATEX_SHARE_ACCESS_WRITE
;
4534 io
.in
.create_options
= 0;
4535 io
.in
.fname
= "lsarpc";
4537 status
= smb2_create(tree
, tree
, &io
);
4538 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4539 "smb2_create failed for 'lsarpc'");
4541 h
= io
.out
.file
.handle
;
4544 rd
.in
.file
.handle
= h
;
4545 rd
.in
.length
= 1024;
4547 rd
.in
.min_count
= 0;
4549 smb2req
= smb2_read_send(tree
, &rd
);
4550 torture_assert_goto(torture
, (smb2req
!= NULL
), ret
, done
,
4551 "smb2_read_send failed");
4553 status
= smb2_logoff(tree
->session
);
4554 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4555 "smb2_logoff failed");
4557 status
= smb2_read_recv(smb2req
, mem_ctx
, &rd
);
4558 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_PIPE_BROKEN
, ret
, done
,
4559 "smb2_read_recv: unexpected return code");
4563 talloc_free(mem_ctx
);
4568 struct torture_suite
*torture_rpc_samba3(TALLOC_CTX
*mem_ctx
)
4570 struct torture_suite
*suite
= torture_suite_create(mem_ctx
, "samba3");
4572 torture_suite_add_simple_test(suite
, "bind", torture_bind_samba3
);
4573 torture_suite_add_simple_test(suite
, "netlogon", torture_netlogon_samba3
);
4574 torture_suite_add_simple_test(suite
, "sessionkey", torture_samba3_sessionkey
);
4575 torture_suite_add_simple_test(suite
, "srvsvc", torture_samba3_rpc_srvsvc
);
4576 torture_suite_add_simple_test(suite
, "sharesec", torture_samba3_rpc_sharesec
);
4577 torture_suite_add_simple_test(suite
, "getusername", torture_samba3_rpc_getusername
);
4578 torture_suite_add_simple_test(suite
, "randomauth2", torture_samba3_rpc_randomauth2
);
4579 torture_suite_add_simple_test(suite
, "lsa", torture_samba3_rpc_lsa
);
4580 torture_suite_add_simple_test(suite
, "spoolss", torture_samba3_rpc_spoolss
);
4581 torture_suite_add_simple_test(suite
, "wkssvc", torture_samba3_rpc_wkssvc
);
4582 torture_suite_add_simple_test(suite
, "winreg", torture_samba3_rpc_winreg
);
4583 torture_suite_add_simple_test(suite
, "getaliasmembership-0", torture_samba3_getaliasmembership_0
);
4584 torture_suite_add_simple_test(suite
, "regconfig", torture_samba3_regconfig
);
4585 torture_suite_add_simple_test(suite
, "smb-reauth1", torture_rpc_smb_reauth1
);
4586 torture_suite_add_simple_test(suite
, "smb-reauth2", torture_rpc_smb_reauth2
);
4587 torture_suite_add_simple_test(suite
, "smb2-reauth1", torture_rpc_smb2_reauth1
);
4588 torture_suite_add_simple_test(suite
, "smb2-reauth2", torture_rpc_smb2_reauth2
);
4589 torture_suite_add_simple_test(suite
, "smb1-pipe-name", torture_rpc_smb1_pipe_name
);
4590 torture_suite_add_simple_test(suite
, "smb2-pipe-name", torture_rpc_smb2_pipe_name
);
4591 torture_suite_add_simple_test(suite
, "smb2-pipe-read-close", torture_rpc_smb2_pipe_read_close
);
4592 torture_suite_add_simple_test(suite
, "smb2-pipe-read-tdis", torture_rpc_smb2_pipe_read_tdis
);
4593 torture_suite_add_simple_test(suite
, "smb2-pipe-read-logoff", torture_rpc_smb2_pipe_read_logoff
);
4595 suite
->description
= talloc_strdup(suite
, "samba3 DCERPC interface tests");