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
;
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
);
1201 netlogon_creds_arcfour_crypt(creds_state
, pinfo
.ntpassword
.hash
, 16);
1203 logon
.password
= &pinfo
;
1205 r
.in
.logon_level
= NetlogonInteractiveInformation
;
1206 r
.in
.logon
= &logon
;
1207 r
.out
.return_authenticator
= &return_authenticator
;
1209 status
= dcerpc_netr_LogonSamLogon_r(net_handle
, mem_ctx
, &r
);
1210 if (!NT_STATUS_IS_OK(status
)) {
1211 torture_comment(tctx
, "netr_LogonSamLogon failed: %s\n",
1215 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1216 torture_comment(tctx
, "netr_LogonSamLogon failed: %s\n",
1217 nt_errstr(r
.out
.result
));
1221 if ((r
.out
.return_authenticator
== NULL
) ||
1222 (!netlogon_creds_client_check(creds_state
,
1223 &r
.out
.return_authenticator
->cred
))) {
1224 torture_comment(tctx
, "Credentials check failed!\n");
1230 struct netr_ServerPasswordSet s
;
1231 char *password
= generate_random_password(wks_creds
, 8, 255);
1232 struct netlogon_creds_CredentialState
*creds_state
;
1233 struct netr_Authenticator credential
, return_authenticator
;
1234 struct samr_Password new_password
;
1236 s
.in
.server_name
= talloc_asprintf(
1237 mem_ctx
, "\\\\%s", dcerpc_server_name(net_pipe
));
1238 s
.in
.computer_name
= cli_credentials_get_workstation(wks_creds
);
1239 s
.in
.account_name
= talloc_asprintf(
1240 mem_ctx
, "%s$", s
.in
.computer_name
);
1241 s
.in
.secure_channel_type
= SEC_CHAN_WKSTA
;
1242 s
.in
.credential
= &credential
;
1243 s
.in
.new_password
= &new_password
;
1244 s
.out
.return_authenticator
= &return_authenticator
;
1246 E_md4hash(password
, new_password
.hash
);
1248 creds_state
= cli_credentials_get_netlogon_creds(wks_creds
);
1249 netlogon_creds_des_encrypt(creds_state
, &new_password
);
1250 netlogon_creds_client_authenticator(creds_state
, &credential
);
1252 status
= dcerpc_netr_ServerPasswordSet_r(net_handle
, mem_ctx
, &s
);
1253 if (!NT_STATUS_IS_OK(status
)) {
1254 torture_comment(tctx
, "ServerPasswordSet - %s\n", nt_errstr(status
));
1257 if (!NT_STATUS_IS_OK(s
.out
.result
)) {
1258 torture_comment(tctx
, "ServerPasswordSet - %s\n", nt_errstr(s
.out
.result
));
1262 if (!netlogon_creds_client_check(creds_state
,
1263 &s
.out
.return_authenticator
->cred
)) {
1264 torture_comment(tctx
, "Credential chaining failed\n");
1267 cli_credentials_set_password(wks_creds
, password
,
1273 talloc_free(mem_ctx
);
1278 * Delete the wks account again
1281 static bool leave(struct torture_context
*tctx
,
1282 struct smbcli_state
*cli
,
1283 struct cli_credentials
*admin_creds
,
1284 struct cli_credentials
*wks_creds
)
1286 char *wks_name
= talloc_asprintf(
1287 NULL
, "%s$", cli_credentials_get_workstation(wks_creds
));
1290 ret
= delete_user(tctx
, cli
, admin_creds
, wks_name
);
1291 talloc_free(wks_name
);
1296 * Test the Samba3 DC code a bit. Join, do some schan netlogon ops, leave
1299 static bool torture_netlogon_samba3(struct torture_context
*torture
)
1302 struct smbcli_state
*cli
;
1303 struct cli_credentials
*anon_creds
;
1304 struct cli_credentials
*wks_creds
;
1305 const char *wks_name
;
1307 struct smbcli_options options
;
1308 struct smbcli_session_options session_options
;
1310 wks_name
= torture_setting_string(torture
, "wksname", NULL
);
1311 if (wks_name
== NULL
) {
1312 wks_name
= get_myname(torture
);
1315 if (!(anon_creds
= cli_credentials_init_anon(torture
))) {
1316 torture_fail(torture
, "create_anon_creds failed\n");
1319 lpcfg_smbcli_options(torture
->lp_ctx
, &options
);
1320 lpcfg_smbcli_session_options(torture
->lp_ctx
, &session_options
);
1322 status
= smbcli_full_connection(torture
, &cli
,
1323 torture_setting_string(torture
, "host", NULL
),
1324 lpcfg_smb_ports(torture
->lp_ctx
),
1326 lpcfg_socket_options(torture
->lp_ctx
),
1328 lpcfg_resolve_context(torture
->lp_ctx
),
1329 torture
->ev
, &options
, &session_options
,
1330 lpcfg_gensec_settings(torture
, torture
->lp_ctx
));
1331 torture_assert_ntstatus_ok(torture
, status
, "smbcli_full_connection failed\n");
1333 wks_creds
= cli_credentials_init(torture
);
1334 if (wks_creds
== NULL
) {
1335 torture_fail(torture
, "cli_credentials_init failed\n");
1338 cli_credentials_set_conf(wks_creds
, torture
->lp_ctx
);
1339 cli_credentials_set_secure_channel_type(wks_creds
, SEC_CHAN_WKSTA
);
1340 cli_credentials_set_username(wks_creds
, wks_name
, CRED_SPECIFIED
);
1341 cli_credentials_set_workstation(wks_creds
, wks_name
, CRED_SPECIFIED
);
1342 cli_credentials_set_password(wks_creds
,
1343 generate_random_password(wks_creds
, 8, 255),
1346 torture_assert(torture
,
1347 join3(torture
, cli
, false, cmdline_credentials
, wks_creds
),
1350 cli_credentials_set_domain(
1351 cmdline_credentials
, cli_credentials_get_domain(wks_creds
),
1354 for (i
=0; i
<2; i
++) {
1356 /* Do this more than once, the routine "schan" changes
1357 * the workstation password using the netlogon
1358 * password change routine */
1362 torture_assert(torture
,
1363 auth2(torture
, cli
, wks_creds
),
1366 for (j
=0; j
<2; j
++) {
1367 torture_assert(torture
,
1368 schan(torture
, cli
, wks_creds
, cmdline_credentials
),
1373 torture_assert(torture
,
1374 leave(torture
, cli
, cmdline_credentials
, wks_creds
),
1381 * Do a simple join, testjoin and leave using specified smb and samr
1385 static bool test_join3(struct torture_context
*tctx
,
1387 struct cli_credentials
*smb_creds
,
1388 struct cli_credentials
*samr_creds
,
1389 const char *wks_name
)
1392 struct smbcli_state
*cli
;
1393 struct cli_credentials
*wks_creds
;
1394 struct smbcli_options options
;
1395 struct smbcli_session_options session_options
;
1397 lpcfg_smbcli_options(tctx
->lp_ctx
, &options
);
1398 lpcfg_smbcli_session_options(tctx
->lp_ctx
, &session_options
);
1400 status
= smbcli_full_connection(tctx
, &cli
,
1401 torture_setting_string(tctx
, "host", NULL
),
1402 lpcfg_smb_ports(tctx
->lp_ctx
),
1403 "IPC$", NULL
, lpcfg_socket_options(tctx
->lp_ctx
),
1404 smb_creds
, lpcfg_resolve_context(tctx
->lp_ctx
),
1405 tctx
->ev
, &options
, &session_options
,
1406 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
));
1407 torture_assert_ntstatus_ok(tctx
, status
,
1408 "smbcli_full_connection failed");
1410 wks_creds
= cli_credentials_init(cli
);
1411 torture_assert(tctx
, wks_creds
, "cli_credentials_init failed");
1413 cli_credentials_set_conf(wks_creds
, tctx
->lp_ctx
);
1414 cli_credentials_set_secure_channel_type(wks_creds
, SEC_CHAN_WKSTA
);
1415 cli_credentials_set_username(wks_creds
, wks_name
, CRED_SPECIFIED
);
1416 cli_credentials_set_workstation(wks_creds
, wks_name
, CRED_SPECIFIED
);
1417 cli_credentials_set_password(wks_creds
,
1418 generate_random_password(wks_creds
, 8, 255),
1421 torture_assert(tctx
,
1422 join3(tctx
, cli
, use_level25
, samr_creds
, wks_creds
),
1425 cli_credentials_set_domain(
1426 cmdline_credentials
, cli_credentials_get_domain(wks_creds
),
1429 torture_assert(tctx
,
1430 auth2(tctx
, cli
, wks_creds
),
1433 torture_assert(tctx
,
1434 leave(tctx
, cli
, samr_creds
, wks_creds
),
1443 * Test the different session key variants. Do it by joining, this uses the
1444 * session key in the setpassword routine. Test the join by doing the auth2.
1447 static bool torture_samba3_sessionkey(struct torture_context
*torture
)
1449 struct cli_credentials
*anon_creds
;
1450 const char *wks_name
;
1452 wks_name
= torture_setting_string(torture
, "wksname", get_myname(torture
));
1454 if (!(anon_creds
= cli_credentials_init_anon(torture
))) {
1455 torture_fail(torture
, "create_anon_creds failed\n");
1458 cli_credentials_set_workstation(anon_creds
, wks_name
, CRED_SPECIFIED
);
1461 if (!torture_setting_bool(torture
, "samba3", false)) {
1463 /* Samba3 in the build farm right now does this happily. Need
1466 if (test_join3(torture
, false, anon_creds
, NULL
, wks_name
)) {
1467 torture_fail(torture
, "join using anonymous bind on an anonymous smb "
1468 "connection succeeded -- HUH??\n");
1472 torture_assert(torture
,
1473 test_join3(torture
, false, anon_creds
, cmdline_credentials
, wks_name
),
1474 "join using ntlmssp bind on an anonymous smb connection failed");
1476 torture_assert(torture
,
1477 test_join3(torture
, false, cmdline_credentials
, NULL
, wks_name
),
1478 "join using anonymous bind on an authenticated smb connection failed");
1480 torture_assert(torture
,
1481 test_join3(torture
, false, cmdline_credentials
, cmdline_credentials
, wks_name
),
1482 "join using ntlmssp bind on an authenticated smb connection failed");
1485 * The following two are tests for setuserinfolevel 25
1488 torture_assert(torture
,
1489 test_join3(torture
, true, anon_creds
, cmdline_credentials
, wks_name
),
1490 "join using ntlmssp bind on an anonymous smb connection failed");
1492 torture_assert(torture
,
1493 test_join3(torture
, true, cmdline_credentials
, NULL
, wks_name
),
1494 "join using anonymous bind on an authenticated smb connection failed");
1500 * open pipe and bind, given an IPC$ context
1503 static NTSTATUS
pipe_bind_smb(struct torture_context
*tctx
,
1504 TALLOC_CTX
*mem_ctx
,
1505 struct smbcli_tree
*tree
,
1506 const char *pipe_name
,
1507 const struct ndr_interface_table
*iface
,
1508 struct dcerpc_pipe
**p
)
1510 struct dcerpc_pipe
*result
;
1513 if (!(result
= dcerpc_pipe_init(mem_ctx
, tctx
->ev
))) {
1514 return NT_STATUS_NO_MEMORY
;
1517 status
= dcerpc_pipe_open_smb(result
, tree
, pipe_name
);
1518 if (!NT_STATUS_IS_OK(status
)) {
1519 torture_comment(tctx
, "dcerpc_pipe_open_smb failed: %s\n",
1521 talloc_free(result
);
1525 status
= dcerpc_bind_auth_none(result
, iface
);
1526 if (!NT_STATUS_IS_OK(status
)) {
1527 torture_comment(tctx
, "schannel bind failed: %s\n", nt_errstr(status
));
1528 talloc_free(result
);
1533 return NT_STATUS_OK
;
1537 * Sane wrapper around lsa_LookupNames
1540 static struct dom_sid
*name2sid(struct torture_context
*tctx
,
1541 TALLOC_CTX
*mem_ctx
,
1542 struct dcerpc_pipe
*p
,
1546 struct lsa_ObjectAttribute attr
;
1547 struct lsa_QosInfo qos
;
1548 struct lsa_OpenPolicy2 r
;
1551 struct policy_handle handle
;
1552 struct lsa_LookupNames l
;
1553 struct lsa_TransSidArray sids
;
1554 struct lsa_RefDomainList
*domains
= NULL
;
1555 struct lsa_String lsa_name
;
1557 struct dom_sid
*result
;
1558 TALLOC_CTX
*tmp_ctx
;
1559 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
1561 if (!(tmp_ctx
= talloc_new(mem_ctx
))) {
1566 qos
.impersonation_level
= 2;
1567 qos
.context_mode
= 1;
1568 qos
.effective_only
= 0;
1571 attr
.root_dir
= NULL
;
1572 attr
.object_name
= NULL
;
1573 attr
.attributes
= 0;
1574 attr
.sec_desc
= NULL
;
1575 attr
.sec_qos
= &qos
;
1577 r
.in
.system_name
= "\\";
1579 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1580 r
.out
.handle
= &handle
;
1582 status
= dcerpc_lsa_OpenPolicy2_r(b
, tmp_ctx
, &r
);
1583 if (!NT_STATUS_IS_OK(status
)) {
1584 torture_comment(tctx
, "OpenPolicy2 failed - %s\n", nt_errstr(status
));
1585 talloc_free(tmp_ctx
);
1588 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1589 torture_comment(tctx
, "OpenPolicy2 failed - %s\n", nt_errstr(r
.out
.result
));
1590 talloc_free(tmp_ctx
);
1597 lsa_name
.string
= talloc_asprintf(tmp_ctx
, "%s\\%s", domain
, name
);
1599 l
.in
.handle
= &handle
;
1601 l
.in
.names
= &lsa_name
;
1604 l
.in
.count
= &count
;
1605 l
.out
.count
= &count
;
1607 l
.out
.domains
= &domains
;
1609 status
= dcerpc_lsa_LookupNames_r(b
, tmp_ctx
, &l
);
1610 if (!NT_STATUS_IS_OK(status
)) {
1611 torture_comment(tctx
, "LookupNames of %s failed - %s\n", lsa_name
.string
,
1613 talloc_free(tmp_ctx
);
1616 if (!NT_STATUS_IS_OK(l
.out
.result
)) {
1617 torture_comment(tctx
, "LookupNames of %s failed - %s\n", lsa_name
.string
,
1618 nt_errstr(l
.out
.result
));
1619 talloc_free(tmp_ctx
);
1623 result
= dom_sid_add_rid(mem_ctx
, domains
->domains
[0].sid
,
1624 l
.out
.sids
->sids
[0].rid
);
1626 c
.in
.handle
= &handle
;
1627 c
.out
.handle
= &handle
;
1629 status
= dcerpc_lsa_Close_r(b
, tmp_ctx
, &c
);
1630 if (!NT_STATUS_IS_OK(status
)) {
1631 torture_comment(tctx
, "dcerpc_lsa_Close failed - %s\n", nt_errstr(status
));
1632 talloc_free(tmp_ctx
);
1635 if (!NT_STATUS_IS_OK(c
.out
.result
)) {
1636 torture_comment(tctx
, "dcerpc_lsa_Close failed - %s\n", nt_errstr(c
.out
.result
));
1637 talloc_free(tmp_ctx
);
1641 talloc_free(tmp_ctx
);
1646 * Find out the user SID on this connection
1649 static struct dom_sid
*whoami(struct torture_context
*tctx
,
1650 TALLOC_CTX
*mem_ctx
,
1651 struct smbcli_tree
*tree
)
1653 struct dcerpc_pipe
*lsa
;
1654 struct dcerpc_binding_handle
*lsa_handle
;
1655 struct lsa_GetUserName r
;
1657 struct lsa_String
*authority_name_p
= NULL
;
1658 struct lsa_String
*account_name_p
= NULL
;
1659 struct dom_sid
*result
;
1661 status
= pipe_bind_smb(tctx
, mem_ctx
, tree
, "\\pipe\\lsarpc",
1662 &ndr_table_lsarpc
, &lsa
);
1663 if (!NT_STATUS_IS_OK(status
)) {
1664 torture_warning(tctx
, "Could not bind to LSA: %s\n",
1668 lsa_handle
= lsa
->binding_handle
;
1670 r
.in
.system_name
= "\\";
1671 r
.in
.account_name
= &account_name_p
;
1672 r
.in
.authority_name
= &authority_name_p
;
1673 r
.out
.account_name
= &account_name_p
;
1675 status
= dcerpc_lsa_GetUserName_r(lsa_handle
, mem_ctx
, &r
);
1677 authority_name_p
= *r
.out
.authority_name
;
1679 if (!NT_STATUS_IS_OK(status
)) {
1680 torture_warning(tctx
, "GetUserName failed - %s\n",
1685 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1686 torture_warning(tctx
, "GetUserName failed - %s\n",
1687 nt_errstr(r
.out
.result
));
1692 result
= name2sid(tctx
, mem_ctx
, lsa
, account_name_p
->string
,
1693 authority_name_p
->string
);
1699 static int destroy_tree(struct smbcli_tree
*tree
)
1701 smb_tree_disconnect(tree
);
1706 * Do a tcon, given a session
1709 static NTSTATUS
secondary_tcon(struct torture_context
*tctx
,
1710 TALLOC_CTX
*mem_ctx
,
1711 struct smbcli_session
*session
,
1712 const char *sharename
,
1713 struct smbcli_tree
**res
)
1715 struct smbcli_tree
*result
;
1716 TALLOC_CTX
*tmp_ctx
;
1717 union smb_tcon tcon
;
1720 if (!(tmp_ctx
= talloc_new(mem_ctx
))) {
1721 return NT_STATUS_NO_MEMORY
;
1724 if (!(result
= smbcli_tree_init(session
, mem_ctx
, false))) {
1725 talloc_free(tmp_ctx
);
1726 return NT_STATUS_NO_MEMORY
;
1729 tcon
.generic
.level
= RAW_TCON_TCONX
;
1730 tcon
.tconx
.in
.flags
= TCONX_FLAG_EXTENDED_RESPONSE
;
1731 tcon
.tconx
.in
.flags
|= TCONX_FLAG_EXTENDED_SIGNATURES
;
1732 tcon
.tconx
.in
.password
= data_blob(NULL
, 0);
1733 tcon
.tconx
.in
.path
= sharename
;
1734 tcon
.tconx
.in
.device
= "?????";
1736 status
= smb_raw_tcon(result
, tmp_ctx
, &tcon
);
1737 if (!NT_STATUS_IS_OK(status
)) {
1738 torture_warning(tctx
, "smb_raw_tcon failed: %s\n",
1740 talloc_free(tmp_ctx
);
1744 result
->tid
= tcon
.tconx
.out
.tid
;
1746 if (tcon
.tconx
.out
.options
& SMB_EXTENDED_SIGNATURES
) {
1747 smb1cli_session_protect_session_key(result
->session
->smbXcli
);
1750 result
= talloc_steal(mem_ctx
, result
);
1751 talloc_set_destructor(result
, destroy_tree
);
1752 talloc_free(tmp_ctx
);
1754 return NT_STATUS_OK
;
1758 * Test the getusername behaviour
1761 static bool torture_samba3_rpc_getusername(struct torture_context
*torture
)
1764 struct smbcli_state
*cli
;
1766 struct dom_sid
*user_sid
;
1767 struct dom_sid
*created_sid
;
1768 struct cli_credentials
*anon_creds
;
1769 struct cli_credentials
*user_creds
;
1771 struct smbcli_options options
;
1772 struct smbcli_session_options session_options
;
1774 lpcfg_smbcli_options(torture
->lp_ctx
, &options
);
1775 lpcfg_smbcli_session_options(torture
->lp_ctx
, &session_options
);
1777 status
= smbcli_full_connection(
1778 torture
, &cli
, torture_setting_string(torture
, "host", NULL
),
1779 lpcfg_smb_ports(torture
->lp_ctx
),
1780 "IPC$", NULL
, lpcfg_socket_options(torture
->lp_ctx
), cmdline_credentials
,
1781 lpcfg_resolve_context(torture
->lp_ctx
), torture
->ev
, &options
,
1782 &session_options
, lpcfg_gensec_settings(torture
, torture
->lp_ctx
));
1783 torture_assert_ntstatus_ok(torture
, status
, "smbcli_full_connection failed\n");
1785 if (!(user_sid
= whoami(torture
, torture
, cli
->tree
))) {
1786 torture_fail(torture
, "whoami on auth'ed connection failed\n");
1791 if (!(anon_creds
= cli_credentials_init_anon(torture
))) {
1792 torture_fail(torture
, "create_anon_creds failed\n");
1795 status
= smbcli_full_connection(
1796 torture
, &cli
, torture_setting_string(torture
, "host", NULL
),
1797 lpcfg_smb_ports(torture
->lp_ctx
), "IPC$", NULL
,
1798 lpcfg_socket_options(torture
->lp_ctx
), anon_creds
,
1799 lpcfg_resolve_context(torture
->lp_ctx
),
1800 torture
->ev
, &options
, &session_options
,
1801 lpcfg_gensec_settings(torture
, torture
->lp_ctx
));
1802 torture_assert_ntstatus_ok(torture
, status
, "anon smbcli_full_connection failed\n");
1804 if (!(user_sid
= whoami(torture
, torture
, cli
->tree
))) {
1805 torture_fail(torture
, "whoami on anon connection failed\n");
1808 torture_assert_sid_equal(torture
, user_sid
, dom_sid_parse_talloc(torture
, "s-1-5-7"),
1809 "Anon lsa_GetUserName returned unexpected SID");
1811 if (!(user_creds
= cli_credentials_init(torture
))) {
1812 torture_fail(torture
, "cli_credentials_init failed\n");
1815 cli_credentials_set_conf(user_creds
, torture
->lp_ctx
);
1816 cli_credentials_set_username(user_creds
, "torture_username",
1818 cli_credentials_set_password(user_creds
,
1819 generate_random_password(user_creds
, 8, 255),
1822 if (!create_user(torture
, torture
, cli
, cmdline_credentials
,
1823 cli_credentials_get_username(user_creds
),
1824 cli_credentials_get_password(user_creds
),
1825 &domain_name
, &created_sid
)) {
1826 torture_fail(torture
, "create_user failed\n");
1829 cli_credentials_set_domain(user_creds
, domain_name
,
1833 struct smbcli_session
*session2
;
1834 struct smb_composite_sesssetup setup
;
1835 struct smbcli_tree
*tree
;
1837 session2
= smbcli_session_init(cli
->transport
, torture
, false, session_options
);
1838 if (session2
== NULL
) {
1839 torture_fail(torture
, "smbcli_session_init failed\n");
1842 setup
.in
.sesskey
= cli
->transport
->negotiate
.sesskey
;
1843 setup
.in
.capabilities
= cli
->transport
->negotiate
.capabilities
;
1844 setup
.in
.workgroup
= "";
1845 setup
.in
.credentials
= user_creds
;
1846 setup
.in
.gensec_settings
= lpcfg_gensec_settings(torture
, torture
->lp_ctx
);
1848 status
= smb_composite_sesssetup(session2
, &setup
);
1849 torture_assert_ntstatus_ok(torture
, status
, "session setup with new user failed");
1851 session2
->vuid
= setup
.out
.vuid
;
1853 if (!NT_STATUS_IS_OK(secondary_tcon(torture
, torture
, session2
,
1855 torture_fail(torture
, "secondary_tcon failed\n");
1858 if (!(user_sid
= whoami(torture
, torture
, tree
))) {
1859 torture_fail_goto(torture
, del
, "whoami on user connection failed\n");
1867 torture_comment(torture
, "Created %s, found %s\n",
1868 dom_sid_string(torture
, created_sid
),
1869 dom_sid_string(torture
, user_sid
));
1871 if (!dom_sid_equal(created_sid
, user_sid
)) {
1876 if (!delete_user(torture
, cli
,
1877 cmdline_credentials
,
1878 cli_credentials_get_username(user_creds
))) {
1879 torture_fail(torture
, "delete_user failed\n");
1885 static bool test_NetShareGetInfo(struct torture_context
*tctx
,
1886 struct dcerpc_pipe
*p
,
1887 const char *sharename
)
1890 struct srvsvc_NetShareGetInfo r
;
1891 union srvsvc_NetShareInfo info
;
1892 uint32_t levels
[] = { 0, 1, 2, 501, 502, 1004, 1005, 1006, 1007, 1501 };
1895 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
1897 r
.in
.server_unc
= talloc_asprintf(tctx
, "\\\\%s",
1898 dcerpc_server_name(p
));
1899 r
.in
.share_name
= sharename
;
1902 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
1903 r
.in
.level
= levels
[i
];
1905 torture_comment(tctx
, "Testing NetShareGetInfo level %u on share '%s'\n",
1906 r
.in
.level
, r
.in
.share_name
);
1908 status
= dcerpc_srvsvc_NetShareGetInfo_r(b
, tctx
, &r
);
1909 if (!NT_STATUS_IS_OK(status
)) {
1910 torture_warning(tctx
, "NetShareGetInfo level %u on share '%s' failed"
1911 " - %s\n", r
.in
.level
, r
.in
.share_name
,
1916 if (!W_ERROR_IS_OK(r
.out
.result
)) {
1917 torture_warning(tctx
, "NetShareGetInfo level %u on share '%s' failed "
1918 "- %s\n", r
.in
.level
, r
.in
.share_name
,
1919 win_errstr(r
.out
.result
));
1928 static bool test_NetShareEnum(struct torture_context
*tctx
,
1929 struct dcerpc_pipe
*p
,
1930 const char **one_sharename
)
1933 struct srvsvc_NetShareEnum r
;
1934 struct srvsvc_NetShareInfoCtr info_ctr
;
1935 struct srvsvc_NetShareCtr0 c0
;
1936 struct srvsvc_NetShareCtr1 c1
;
1937 struct srvsvc_NetShareCtr2 c2
;
1938 struct srvsvc_NetShareCtr501 c501
;
1939 struct srvsvc_NetShareCtr502 c502
;
1940 struct srvsvc_NetShareCtr1004 c1004
;
1941 struct srvsvc_NetShareCtr1005 c1005
;
1942 struct srvsvc_NetShareCtr1006 c1006
;
1943 struct srvsvc_NetShareCtr1007 c1007
;
1944 uint32_t totalentries
= 0;
1945 uint32_t levels
[] = { 0, 1, 2, 501, 502, 1004, 1005, 1006, 1007 };
1948 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
1950 ZERO_STRUCT(info_ctr
);
1952 r
.in
.server_unc
= talloc_asprintf(tctx
,"\\\\%s",dcerpc_server_name(p
));
1953 r
.in
.info_ctr
= &info_ctr
;
1954 r
.in
.max_buffer
= (uint32_t)-1;
1955 r
.in
.resume_handle
= NULL
;
1956 r
.out
.totalentries
= &totalentries
;
1957 r
.out
.info_ctr
= &info_ctr
;
1959 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
1960 info_ctr
.level
= levels
[i
];
1962 switch (info_ctr
.level
) {
1965 info_ctr
.ctr
.ctr0
= &c0
;
1969 info_ctr
.ctr
.ctr1
= &c1
;
1973 info_ctr
.ctr
.ctr2
= &c2
;
1977 info_ctr
.ctr
.ctr501
= &c501
;
1981 info_ctr
.ctr
.ctr502
= &c502
;
1985 info_ctr
.ctr
.ctr1004
= &c1004
;
1989 info_ctr
.ctr
.ctr1005
= &c1005
;
1993 info_ctr
.ctr
.ctr1006
= &c1006
;
1997 info_ctr
.ctr
.ctr1007
= &c1007
;
2001 torture_comment(tctx
, "Testing NetShareEnum level %u\n", info_ctr
.level
);
2003 status
= dcerpc_srvsvc_NetShareEnum_r(b
, tctx
, &r
);
2004 if (!NT_STATUS_IS_OK(status
)) {
2005 torture_warning(tctx
, "NetShareEnum level %u failed - %s\n",
2006 info_ctr
.level
, nt_errstr(status
));
2010 if (!W_ERROR_IS_OK(r
.out
.result
)) {
2011 torture_warning(tctx
, "NetShareEnum level %u failed - %s\n",
2012 info_ctr
.level
, win_errstr(r
.out
.result
));
2015 if (info_ctr
.level
== 0) {
2016 struct srvsvc_NetShareCtr0
*ctr
= r
.out
.info_ctr
->ctr
.ctr0
;
2017 if (ctr
->count
> 0) {
2018 *one_sharename
= ctr
->array
[0].name
;
2026 static bool torture_samba3_rpc_srvsvc(struct torture_context
*torture
)
2028 struct dcerpc_pipe
*p
;
2029 const char *sharename
= NULL
;
2032 torture_assert_ntstatus_ok(torture
,
2033 torture_rpc_connection(torture
, &p
, &ndr_table_srvsvc
),
2034 "failed to open srvsvc");
2036 ret
&= test_NetShareEnum(torture
, p
, &sharename
);
2037 if (sharename
== NULL
) {
2038 torture_comment(torture
, "did not get sharename\n");
2040 ret
&= test_NetShareGetInfo(torture
, p
, sharename
);
2047 * Do a ReqChallenge/Auth2 with a random wks name, make sure it returns
2048 * NT_STATUS_NO_SAM_ACCOUNT
2051 static bool torture_samba3_rpc_randomauth2(struct torture_context
*torture
)
2053 TALLOC_CTX
*mem_ctx
;
2054 struct dcerpc_pipe
*net_pipe
;
2055 struct dcerpc_binding_handle
*net_handle
;
2057 bool result
= false;
2059 struct netr_ServerReqChallenge r
;
2060 struct netr_Credential netr_cli_creds
;
2061 struct netr_Credential netr_srv_creds
;
2062 uint32_t negotiate_flags
;
2063 struct netr_ServerAuthenticate2 a
;
2064 struct netlogon_creds_CredentialState
*creds_state
;
2065 struct netr_Credential netr_cred
;
2066 struct samr_Password mach_pw
;
2067 struct smbcli_state
*cli
;
2069 if (!(mem_ctx
= talloc_new(torture
))) {
2070 torture_comment(torture
, "talloc_new failed\n");
2074 if (!(wksname
= generate_random_str_list(
2075 mem_ctx
, 14, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"))) {
2076 torture_comment(torture
, "generate_random_str_list failed\n");
2080 if (!(torture_open_connection_share(
2082 torture
, torture_setting_string(torture
, "host", NULL
),
2083 "IPC$", torture
->ev
))) {
2084 torture_comment(torture
, "IPC$ connection failed\n");
2088 if (!(net_pipe
= dcerpc_pipe_init(mem_ctx
, torture
->ev
))) {
2089 torture_comment(torture
, "dcerpc_pipe_init failed\n");
2092 net_handle
= net_pipe
->binding_handle
;
2094 status
= dcerpc_pipe_open_smb(net_pipe
, cli
->tree
, "\\netlogon");
2095 if (!NT_STATUS_IS_OK(status
)) {
2096 torture_comment(torture
, "dcerpc_pipe_open_smb failed: %s\n",
2101 status
= dcerpc_bind_auth_none(net_pipe
, &ndr_table_netlogon
);
2102 if (!NT_STATUS_IS_OK(status
)) {
2103 torture_comment(torture
, "dcerpc_bind_auth_none failed: %s\n",
2108 r
.in
.computer_name
= wksname
;
2109 r
.in
.server_name
= talloc_asprintf(
2110 mem_ctx
, "\\\\%s", dcerpc_server_name(net_pipe
));
2111 if (r
.in
.server_name
== NULL
) {
2112 torture_comment(torture
, "talloc_asprintf failed\n");
2115 generate_random_buffer(netr_cli_creds
.data
,
2116 sizeof(netr_cli_creds
.data
));
2117 r
.in
.credentials
= &netr_cli_creds
;
2118 r
.out
.return_credentials
= &netr_srv_creds
;
2120 status
= dcerpc_netr_ServerReqChallenge_r(net_handle
, mem_ctx
, &r
);
2121 if (!NT_STATUS_IS_OK(status
)) {
2122 torture_comment(torture
, "netr_ServerReqChallenge failed: %s\n",
2126 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
2127 torture_comment(torture
, "netr_ServerReqChallenge failed: %s\n",
2128 nt_errstr(r
.out
.result
));
2132 negotiate_flags
= NETLOGON_NEG_AUTH2_FLAGS
;
2133 E_md4hash("foobar", mach_pw
.hash
);
2135 a
.in
.server_name
= talloc_asprintf(
2136 mem_ctx
, "\\\\%s", dcerpc_server_name(net_pipe
));
2137 a
.in
.account_name
= talloc_asprintf(
2138 mem_ctx
, "%s$", wksname
);
2139 a
.in
.computer_name
= wksname
;
2140 a
.in
.secure_channel_type
= SEC_CHAN_WKSTA
;
2141 a
.in
.negotiate_flags
= &negotiate_flags
;
2142 a
.out
.negotiate_flags
= &negotiate_flags
;
2143 a
.in
.credentials
= &netr_cred
;
2144 a
.out
.return_credentials
= &netr_cred
;
2146 creds_state
= netlogon_creds_client_init(mem_ctx
,
2150 r
.out
.return_credentials
, &mach_pw
,
2151 &netr_cred
, negotiate_flags
);
2152 torture_assert(torture
, (creds_state
!= NULL
), "memory allocation failed");
2154 status
= dcerpc_netr_ServerAuthenticate2_r(net_handle
, mem_ctx
, &a
);
2155 if (!NT_STATUS_IS_OK(status
)) {
2158 if (!NT_STATUS_EQUAL(a
.out
.result
, NT_STATUS_NO_TRUST_SAM_ACCOUNT
)) {
2159 torture_comment(torture
, "dcerpc_netr_ServerAuthenticate2 returned %s, "
2160 "expected NT_STATUS_NO_TRUST_SAM_ACCOUNT\n",
2161 nt_errstr(a
.out
.result
));
2167 talloc_free(mem_ctx
);
2171 static struct security_descriptor
*get_sharesec(struct torture_context
*tctx
,
2172 TALLOC_CTX
*mem_ctx
,
2173 struct smbcli_session
*sess
,
2174 const char *sharename
)
2176 struct smbcli_tree
*tree
;
2177 TALLOC_CTX
*tmp_ctx
;
2178 struct dcerpc_pipe
*p
;
2179 struct dcerpc_binding_handle
*b
;
2181 struct srvsvc_NetShareGetInfo r
;
2182 union srvsvc_NetShareInfo info
;
2183 struct security_descriptor
*result
;
2185 if (!(tmp_ctx
= talloc_new(mem_ctx
))) {
2186 torture_comment(tctx
, "talloc_new failed\n");
2190 if (!NT_STATUS_IS_OK(secondary_tcon(tctx
, tmp_ctx
, sess
, "IPC$", &tree
))) {
2191 torture_comment(tctx
, "secondary_tcon failed\n");
2192 talloc_free(tmp_ctx
);
2196 status
= pipe_bind_smb(tctx
, mem_ctx
, tree
, "\\pipe\\srvsvc",
2197 &ndr_table_srvsvc
, &p
);
2198 if (!NT_STATUS_IS_OK(status
)) {
2199 torture_warning(tctx
, "could not bind to srvsvc pipe: %s\n",
2201 talloc_free(tmp_ctx
);
2204 b
= p
->binding_handle
;
2207 p
->conn
->flags
|= DCERPC_DEBUG_PRINT_IN
| DCERPC_DEBUG_PRINT_OUT
;
2210 r
.in
.server_unc
= talloc_asprintf(tmp_ctx
, "\\\\%s",
2211 dcerpc_server_name(p
));
2212 r
.in
.share_name
= sharename
;
2216 status
= dcerpc_srvsvc_NetShareGetInfo_r(b
, tmp_ctx
, &r
);
2217 if (!NT_STATUS_IS_OK(status
)) {
2218 torture_comment(tctx
, "srvsvc_NetShareGetInfo failed: %s\n",
2220 talloc_free(tmp_ctx
);
2223 if (!W_ERROR_IS_OK(r
.out
.result
)) {
2224 torture_comment(tctx
, "srvsvc_NetShareGetInfo failed: %s\n",
2225 win_errstr(r
.out
.result
));
2226 talloc_free(tmp_ctx
);
2230 result
= talloc_steal(mem_ctx
, info
.info502
->sd_buf
.sd
);
2231 talloc_free(tmp_ctx
);
2235 static NTSTATUS
set_sharesec(struct torture_context
*tctx
,
2236 TALLOC_CTX
*mem_ctx
,
2237 struct smbcli_session
*sess
,
2238 const char *sharename
,
2239 struct security_descriptor
*sd
)
2241 struct smbcli_tree
*tree
;
2242 TALLOC_CTX
*tmp_ctx
;
2243 struct dcerpc_pipe
*p
;
2244 struct dcerpc_binding_handle
*b
;
2246 struct sec_desc_buf i
;
2247 struct srvsvc_NetShareSetInfo r
;
2248 union srvsvc_NetShareInfo info
;
2251 if (!(tmp_ctx
= talloc_new(mem_ctx
))) {
2252 torture_comment(tctx
, "talloc_new failed\n");
2253 return NT_STATUS_NO_MEMORY
;
2256 if (!NT_STATUS_IS_OK(secondary_tcon(tctx
, tmp_ctx
, sess
, "IPC$", &tree
))) {
2257 torture_comment(tctx
, "secondary_tcon failed\n");
2258 talloc_free(tmp_ctx
);
2259 return NT_STATUS_UNSUCCESSFUL
;
2262 status
= pipe_bind_smb(tctx
, mem_ctx
, tree
, "\\pipe\\srvsvc",
2263 &ndr_table_srvsvc
, &p
);
2264 if (!NT_STATUS_IS_OK(status
)) {
2265 torture_warning(tctx
, "could not bind to srvsvc pipe: %s\n",
2267 talloc_free(tmp_ctx
);
2268 return NT_STATUS_UNSUCCESSFUL
;
2270 b
= p
->binding_handle
;
2273 p
->conn
->flags
|= DCERPC_DEBUG_PRINT_IN
| DCERPC_DEBUG_PRINT_OUT
;
2276 r
.in
.server_unc
= talloc_asprintf(tmp_ctx
, "\\\\%s",
2277 dcerpc_server_name(p
));
2278 r
.in
.share_name
= sharename
;
2283 r
.in
.parm_error
= &error
;
2285 status
= dcerpc_srvsvc_NetShareSetInfo_r(b
, tmp_ctx
, &r
);
2286 if (!NT_STATUS_IS_OK(status
)) {
2287 torture_comment(tctx
, "srvsvc_NetShareSetInfo failed: %s\n",
2290 if (!W_ERROR_IS_OK(r
.out
.result
)) {
2291 torture_comment(tctx
, "srvsvc_NetShareSetInfo failed: %s\n",
2292 win_errstr(r
.out
.result
));
2293 status
= werror_to_ntstatus(r
.out
.result
);
2295 talloc_free(tmp_ctx
);
2299 bool try_tcon(struct torture_context
*tctx
,
2300 TALLOC_CTX
*mem_ctx
,
2301 struct security_descriptor
*orig_sd
,
2302 struct smbcli_session
*session
,
2303 const char *sharename
, const struct dom_sid
*user_sid
,
2304 unsigned int access_mask
, NTSTATUS expected_tcon
,
2305 NTSTATUS expected_mkdir
)
2307 TALLOC_CTX
*tmp_ctx
;
2308 struct smbcli_tree
*rmdir_tree
, *tree
;
2309 struct dom_sid
*domain_sid
;
2311 struct security_descriptor
*sd
;
2315 if (!(tmp_ctx
= talloc_new(mem_ctx
))) {
2316 torture_comment(tctx
, "talloc_new failed\n");
2320 status
= secondary_tcon(tctx
, tmp_ctx
, session
, sharename
, &rmdir_tree
);
2321 if (!NT_STATUS_IS_OK(status
)) {
2322 torture_comment(tctx
, "first tcon to delete dir failed\n");
2323 talloc_free(tmp_ctx
);
2327 smbcli_rmdir(rmdir_tree
, "sharesec_testdir");
2329 if (!NT_STATUS_IS_OK(dom_sid_split_rid(tmp_ctx
, user_sid
,
2330 &domain_sid
, &rid
))) {
2331 torture_comment(tctx
, "dom_sid_split_rid failed\n");
2332 talloc_free(tmp_ctx
);
2336 sd
= security_descriptor_dacl_create(
2337 tmp_ctx
, 0, "S-1-5-32-544",
2338 dom_sid_string(mem_ctx
, dom_sid_add_rid(mem_ctx
, domain_sid
,
2340 dom_sid_string(mem_ctx
, user_sid
),
2341 SEC_ACE_TYPE_ACCESS_ALLOWED
, access_mask
, 0, NULL
);
2343 torture_comment(tctx
, "security_descriptor_dacl_create failed\n");
2344 talloc_free(tmp_ctx
);
2348 status
= set_sharesec(tctx
, mem_ctx
, session
, sharename
, sd
);
2349 if (!NT_STATUS_IS_OK(status
)) {
2350 torture_comment(tctx
, "custom set_sharesec failed: %s\n",
2352 talloc_free(tmp_ctx
);
2356 status
= secondary_tcon(tctx
, tmp_ctx
, session
, sharename
, &tree
);
2357 if (!NT_STATUS_EQUAL(status
, expected_tcon
)) {
2358 torture_comment(tctx
, "Expected %s, got %s\n", nt_errstr(expected_tcon
),
2364 if (!NT_STATUS_IS_OK(status
)) {
2365 /* An expected non-access, no point in trying to write */
2369 status
= smbcli_mkdir(tree
, "sharesec_testdir");
2370 if (!NT_STATUS_EQUAL(status
, expected_mkdir
)) {
2371 torture_warning(tctx
, "Expected %s, got %s\n",
2372 nt_errstr(expected_mkdir
), nt_errstr(status
));
2377 smbcli_rmdir(rmdir_tree
, "sharesec_testdir");
2379 status
= set_sharesec(tctx
, mem_ctx
, session
, sharename
, orig_sd
);
2380 if (!NT_STATUS_IS_OK(status
)) {
2381 torture_comment(tctx
, "custom set_sharesec failed: %s\n",
2383 talloc_free(tmp_ctx
);
2387 talloc_free(tmp_ctx
);
2391 static bool torture_samba3_rpc_sharesec(struct torture_context
*torture
)
2393 struct smbcli_state
*cli
= NULL
;
2394 struct security_descriptor
*sd
= NULL
;
2395 struct dom_sid
*user_sid
= NULL
;
2396 const char *testuser_passwd
= NULL
;
2397 struct cli_credentials
*test_credentials
= NULL
;
2398 struct smbcli_options options
;
2399 struct smbcli_session_options session_options
;
2401 struct test_join
*tj
= NULL
;
2402 struct dcerpc_pipe
*lsa_pipe
= NULL
;
2403 const char *priv_array
[1];
2405 /* Create a new user. The normal user has SeBackup and SeRestore
2406 privs so we can't lock them out with a share security descriptor. */
2407 tj
= torture_create_testuser(torture
,
2409 torture_setting_string(torture
, "workgroup", NULL
),
2413 torture_fail(torture
, "Creating sharesec_user failed\n");
2416 /* Give them SeDiskOperatorPrivilege but no other privs. */
2417 status
= torture_rpc_connection(torture
, &lsa_pipe
, &ndr_table_lsarpc
);
2418 if (!NT_STATUS_IS_OK(status
)) {
2419 torture_delete_testuser(torture
, tj
, "sharesec_user");
2421 torture_fail(torture
, "Error connecting to LSA pipe");
2424 priv_array
[0] = "SeDiskOperatorPrivilege";
2425 if (!torture_setup_privs(torture
,
2429 torture_join_user_sid(tj
))) {
2430 talloc_free(lsa_pipe
);
2431 torture_delete_testuser(torture
, tj
, "sharesec_user");
2433 torture_fail(torture
, "Failed to setup privs\n");
2435 talloc_free(lsa_pipe
);
2437 test_credentials
= cli_credentials_init(torture
);
2438 cli_credentials_set_workstation(test_credentials
, "localhost", CRED_SPECIFIED
);
2439 cli_credentials_set_domain(test_credentials
, lpcfg_workgroup(torture
->lp_ctx
),
2441 cli_credentials_set_username(test_credentials
, "sharesec_user", CRED_SPECIFIED
);
2442 cli_credentials_set_password(test_credentials
, testuser_passwd
, CRED_SPECIFIED
);
2444 ZERO_STRUCT(options
);
2445 ZERO_STRUCT(session_options
);
2446 lpcfg_smbcli_options(torture
->lp_ctx
, &options
);
2447 lpcfg_smbcli_session_options(torture
->lp_ctx
, &session_options
);
2449 status
= smbcli_full_connection(torture
,
2451 torture_setting_string(torture
, "host", NULL
),
2452 lpcfg_smb_ports(torture
->lp_ctx
),
2455 lpcfg_socket_options(torture
->lp_ctx
),
2457 lpcfg_resolve_context(torture
->lp_ctx
),
2461 lpcfg_gensec_settings(torture
, torture
->lp_ctx
));
2462 if (!NT_STATUS_IS_OK(status
)) {
2464 torture_delete_testuser(torture
, tj
, "sharesec_user");
2466 torture_fail(torture
, "Failed to open connection\n");
2469 if (!(user_sid
= whoami(torture
, torture
, cli
->tree
))) {
2471 torture_delete_testuser(torture
, tj
, "sharesec_user");
2473 torture_fail(torture
, "whoami failed\n");
2476 sd
= get_sharesec(torture
, torture
, cli
->session
,
2477 torture_setting_string(torture
, "share", NULL
));
2479 if (!try_tcon(torture
, torture
, sd
, cli
->session
,
2480 torture_setting_string(torture
, "share", NULL
),
2481 user_sid
, 0, NT_STATUS_ACCESS_DENIED
, NT_STATUS_OK
)) {
2483 torture_delete_testuser(torture
, tj
, "sharesec_user");
2485 torture_fail(torture
, "failed to test tcon with 0 access_mask");
2488 if (!try_tcon(torture
, torture
, sd
, cli
->session
,
2489 torture_setting_string(torture
, "share", NULL
),
2490 user_sid
, SEC_FILE_READ_DATA
, NT_STATUS_OK
,
2491 NT_STATUS_MEDIA_WRITE_PROTECTED
)) {
2493 torture_delete_testuser(torture
, tj
, "sharesec_user");
2495 torture_fail(torture
, "failed to test tcon with SEC_FILE_READ_DATA access_mask");
2498 /* sharesec_user doesn't have any rights on the underlying file system.
2499 Go back to the normal user. */
2503 torture_delete_testuser(torture
, tj
, "sharesec_user");
2507 if (!(torture_open_connection_share(
2508 torture
, &cli
, torture
, torture_setting_string(torture
, "host", NULL
),
2509 "IPC$", torture
->ev
))) {
2510 torture_fail(torture
, "IPC$ connection failed\n");
2513 if (!(user_sid
= whoami(torture
, torture
, cli
->tree
))) {
2514 torture_fail(torture
, "whoami failed\n");
2516 torture_assert(torture
, try_tcon(
2517 torture
, torture
, sd
, cli
->session
,
2518 torture_setting_string(torture
, "share", NULL
),
2519 user_sid
, SEC_FILE_ALL
, NT_STATUS_OK
, NT_STATUS_OK
),
2520 "failed to test tcon with SEC_FILE_ALL access_mask")
2525 static bool torture_samba3_rpc_lsa(struct torture_context
*torture
)
2527 struct dcerpc_pipe
*p
;
2528 struct dcerpc_binding_handle
*b
;
2529 struct policy_handle lsa_handle
;
2531 torture_assert_ntstatus_ok(torture
,
2532 torture_rpc_connection(torture
, &p
, &ndr_table_lsarpc
),
2533 "failed to setup lsarpc");
2535 b
= p
->binding_handle
;
2538 struct lsa_ObjectAttribute attr
;
2539 struct lsa_OpenPolicy2 o
;
2540 o
.in
.system_name
= talloc_asprintf(
2541 torture
, "\\\\%s", dcerpc_server_name(p
));
2544 o
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2545 o
.out
.handle
= &lsa_handle
;
2547 torture_assert_ntstatus_ok(torture
,
2548 dcerpc_lsa_OpenPolicy2_r(b
, torture
, &o
),
2549 "dcerpc_lsa_OpenPolicy2 failed");
2550 torture_assert_ntstatus_ok(torture
, o
.out
.result
,
2551 "dcerpc_lsa_OpenPolicy2 failed");
2556 int levels
[] = { 2,3,5,6 };
2558 for (i
=0; i
<ARRAY_SIZE(levels
); i
++) {
2559 struct lsa_QueryInfoPolicy r
;
2560 union lsa_PolicyInformation
*info
= NULL
;
2561 r
.in
.handle
= &lsa_handle
;
2562 r
.in
.level
= levels
[i
];
2565 torture_assert_ntstatus_ok(torture
,
2566 dcerpc_lsa_QueryInfoPolicy_r(b
, torture
, &r
),
2567 talloc_asprintf(torture
, "dcerpc_lsa_QueryInfoPolicy level %d failed", levels
[i
]));
2568 torture_assert_ntstatus_ok(torture
, r
.out
.result
,
2569 talloc_asprintf(torture
, "dcerpc_lsa_QueryInfoPolicy level %d failed", levels
[i
]));
2576 static NTSTATUS
get_servername(TALLOC_CTX
*mem_ctx
, struct smbcli_tree
*tree
,
2579 struct rap_WserverGetInfo r
;
2581 char servername
[17];
2582 size_t converted_size
;
2585 r
.in
.bufsize
= 0xffff;
2587 status
= smbcli_rap_netservergetinfo(tree
, mem_ctx
, &r
);
2588 if (!NT_STATUS_IS_OK(status
)) {
2592 memcpy(servername
, r
.out
.info
.info0
.name
, 16);
2593 servername
[16] = '\0';
2595 if (!pull_ascii_talloc(mem_ctx
, name
, servername
, &converted_size
)) {
2596 return NT_STATUS_NO_MEMORY
;
2599 return NT_STATUS_OK
;
2602 static bool rap_get_servername(struct torture_context
*tctx
,
2605 struct smbcli_state
*cli
;
2607 torture_assert(tctx
,
2608 torture_open_connection_share(tctx
, &cli
, tctx
, torture_setting_string(tctx
, "host", NULL
),
2610 "IPC$ connection failed");
2612 torture_assert_ntstatus_ok(tctx
,
2613 get_servername(tctx
, cli
->tree
, servername
),
2614 "get_servername failed");
2621 static bool find_printers(struct torture_context
*tctx
,
2622 struct dcerpc_pipe
*p
,
2623 const char ***printers
,
2626 struct srvsvc_NetShareEnum r
;
2627 struct srvsvc_NetShareInfoCtr info_ctr
;
2628 struct srvsvc_NetShareCtr1 c1_in
;
2629 struct srvsvc_NetShareCtr1
*c1
;
2630 uint32_t totalentries
= 0;
2632 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
2636 info_ctr
.ctr
.ctr1
= &c1_in
;
2638 r
.in
.server_unc
= talloc_asprintf(
2639 tctx
, "\\\\%s", dcerpc_server_name(p
));
2640 r
.in
.info_ctr
= &info_ctr
;
2641 r
.in
.max_buffer
= (uint32_t)-1;
2642 r
.in
.resume_handle
= NULL
;
2643 r
.out
.totalentries
= &totalentries
;
2644 r
.out
.info_ctr
= &info_ctr
;
2646 torture_assert_ntstatus_ok(tctx
,
2647 dcerpc_srvsvc_NetShareEnum_r(b
, tctx
, &r
),
2648 "NetShareEnum level 1 failed");
2649 torture_assert_werr_ok(tctx
, r
.out
.result
,
2650 "NetShareEnum level 1 failed");
2654 c1
= r
.out
.info_ctr
->ctr
.ctr1
;
2655 for (i
=0; i
<c1
->count
; i
++) {
2656 if (c1
->array
[i
].type
!= STYPE_PRINTQ
) {
2659 if (!add_string_to_array(tctx
, c1
->array
[i
].name
,
2660 printers
, num_printers
)) {
2668 static bool enumprinters(struct torture_context
*tctx
,
2669 struct dcerpc_binding_handle
*b
,
2670 const char *servername
, int level
, int *num_printers
)
2672 struct spoolss_EnumPrinters r
;
2676 union spoolss_PrinterInfo
*info
;
2678 r
.in
.flags
= PRINTER_ENUM_LOCAL
;
2679 r
.in
.server
= talloc_asprintf(tctx
, "\\\\%s", servername
);
2683 r
.out
.needed
= &needed
;
2684 r
.out
.count
= &count
;
2687 torture_assert_ntstatus_ok(tctx
,
2688 dcerpc_spoolss_EnumPrinters_r(b
, tctx
, &r
),
2689 "dcerpc_spoolss_EnumPrinters failed");
2690 torture_assert_werr_equal(tctx
, r
.out
.result
, WERR_INSUFFICIENT_BUFFER
,
2691 "EnumPrinters unexpected return code should be WERR_INSUFFICIENT_BUFFER");
2693 blob
= data_blob_talloc_zero(tctx
, needed
);
2694 if (blob
.data
== NULL
) {
2698 r
.in
.buffer
= &blob
;
2699 r
.in
.offered
= needed
;
2701 torture_assert_ntstatus_ok(tctx
,
2702 dcerpc_spoolss_EnumPrinters_r(b
, tctx
, &r
),
2703 "dcerpc_spoolss_EnumPrinters failed");
2704 torture_assert_werr_ok(tctx
, r
.out
.result
,
2705 "dcerpc_spoolss_EnumPrinters failed");
2707 *num_printers
= count
;
2712 static bool getprinterinfo(struct torture_context
*tctx
,
2713 struct dcerpc_binding_handle
*b
,
2714 struct policy_handle
*handle
, int level
,
2715 union spoolss_PrinterInfo
**res
)
2717 struct spoolss_GetPrinter r
;
2721 r
.in
.handle
= handle
;
2725 r
.out
.needed
= &needed
;
2727 torture_assert_ntstatus_ok(tctx
,
2728 dcerpc_spoolss_GetPrinter_r(b
, tctx
, &r
),
2729 "dcerpc_spoolss_GetPrinter failed");
2730 torture_assert_werr_equal(tctx
, r
.out
.result
, WERR_INSUFFICIENT_BUFFER
,
2731 "GetPrinter unexpected return code should be WERR_INSUFFICIENT_BUFFER");
2733 r
.in
.handle
= handle
;
2735 blob
= data_blob_talloc_zero(tctx
, needed
);
2736 if (blob
.data
== NULL
) {
2739 r
.in
.buffer
= &blob
;
2740 r
.in
.offered
= needed
;
2742 torture_assert_ntstatus_ok(tctx
,
2743 dcerpc_spoolss_GetPrinter_r(b
, tctx
, &r
),
2744 "dcerpc_spoolss_GetPrinter failed");
2745 torture_assert_werr_ok(tctx
, r
.out
.result
,
2746 "dcerpc_spoolss_GetPrinter failed");
2749 *res
= talloc_steal(tctx
, r
.out
.info
);
2755 static bool torture_samba3_rpc_spoolss(struct torture_context
*torture
)
2757 struct dcerpc_pipe
*p
, *p2
;
2758 struct dcerpc_binding_handle
*b
;
2759 struct policy_handle server_handle
, printer_handle
;
2760 const char **printers
;
2762 struct spoolss_UserLevel1 userlevel1
;
2765 torture_assert(torture
,
2766 rap_get_servername(torture
, &servername
),
2767 "failed to rap servername");
2769 torture_assert_ntstatus_ok(torture
,
2770 torture_rpc_connection(torture
, &p2
, &ndr_table_srvsvc
),
2771 "failed to setup srvsvc");
2773 torture_assert(torture
,
2774 find_printers(torture
, p2
, &printers
, &num_printers
),
2775 "failed to find printers via srvsvc");
2779 if (num_printers
== 0) {
2780 torture_skip(torture
, "Did not find printers\n");
2784 torture_assert_ntstatus_ok(torture
,
2785 torture_rpc_connection(torture
, &p
, &ndr_table_spoolss
),
2786 "failed to setup spoolss");
2788 b
= p
->binding_handle
;
2790 ZERO_STRUCT(userlevel1
);
2791 userlevel1
.client
= talloc_asprintf(
2792 torture
, "\\\\%s", lpcfg_netbios_name(torture
->lp_ctx
));
2793 userlevel1
.user
= cli_credentials_get_username(cmdline_credentials
);
2794 userlevel1
.build
= 2600;
2795 userlevel1
.major
= 3;
2796 userlevel1
.minor
= 0;
2797 userlevel1
.processor
= 0;
2800 struct spoolss_OpenPrinterEx r
;
2803 r
.in
.printername
= talloc_asprintf(torture
, "\\\\%s",
2805 r
.in
.datatype
= NULL
;
2806 r
.in
.access_mask
= 0;
2807 r
.in
.userlevel_ctr
.level
= 1;
2808 r
.in
.userlevel_ctr
.user_info
.level1
= &userlevel1
;
2809 r
.out
.handle
= &server_handle
;
2811 torture_assert_ntstatus_ok(torture
,
2812 dcerpc_spoolss_OpenPrinterEx_r(b
, torture
, &r
),
2813 "dcerpc_spoolss_OpenPrinterEx failed");
2814 torture_assert_werr_ok(torture
, r
.out
.result
,
2815 "dcerpc_spoolss_OpenPrinterEx failed");
2819 struct spoolss_ClosePrinter r
;
2821 r
.in
.handle
= &server_handle
;
2822 r
.out
.handle
= &server_handle
;
2824 torture_assert_ntstatus_ok(torture
,
2825 dcerpc_spoolss_ClosePrinter_r(b
, torture
, &r
),
2826 "dcerpc_spoolss_ClosePrinter failed");
2827 torture_assert_werr_ok(torture
, r
.out
.result
,
2828 "dcerpc_spoolss_ClosePrinter failed");
2832 struct spoolss_OpenPrinterEx r
;
2835 r
.in
.printername
= talloc_asprintf(
2836 torture
, "\\\\%s\\%s", servername
, printers
[0]);
2837 r
.in
.datatype
= NULL
;
2838 r
.in
.access_mask
= 0;
2839 r
.in
.userlevel_ctr
.level
= 1;
2840 r
.in
.userlevel_ctr
.user_info
.level1
= &userlevel1
;
2841 r
.out
.handle
= &printer_handle
;
2843 torture_assert_ntstatus_ok(torture
,
2844 dcerpc_spoolss_OpenPrinterEx_r(b
, torture
, &r
),
2845 "dcerpc_spoolss_OpenPrinterEx failed");
2846 torture_assert_werr_ok(torture
, r
.out
.result
,
2847 "dcerpc_spoolss_OpenPrinterEx failed");
2853 for (i
=0; i
<8; i
++) {
2854 torture_assert(torture
,
2855 getprinterinfo(torture
, b
, &printer_handle
, i
, NULL
),
2856 talloc_asprintf(torture
, "getprinterinfo %d failed", i
));
2861 struct spoolss_ClosePrinter r
;
2863 r
.in
.handle
= &printer_handle
;
2864 r
.out
.handle
= &printer_handle
;
2866 torture_assert_ntstatus_ok(torture
,
2867 dcerpc_spoolss_ClosePrinter_r(b
, torture
, &r
),
2868 "dcerpc_spoolss_ClosePrinter failed");
2869 torture_assert_werr_ok(torture
, r
.out
.result
,
2870 "dcerpc_spoolss_ClosePrinter failed");
2876 torture_assert(torture
,
2877 enumprinters(torture
, b
, servername
, 1, &num_enumerated
),
2878 "enumprinters failed");
2880 torture_assert_int_equal(torture
, num_printers
, num_enumerated
,
2881 "netshareenum / enumprinters lvl 1 numprinter mismatch");
2887 torture_assert(torture
,
2888 enumprinters(torture
, b
, servername
, 2, &num_enumerated
),
2889 "enumprinters failed");
2891 torture_assert_int_equal(torture
, num_printers
, num_enumerated
,
2892 "netshareenum / enumprinters lvl 2 numprinter mismatch");
2898 static bool torture_samba3_rpc_wkssvc(struct torture_context
*torture
)
2900 struct dcerpc_pipe
*p
;
2901 struct dcerpc_binding_handle
*b
;
2904 torture_assert(torture
,
2905 rap_get_servername(torture
, &servername
),
2906 "failed to rap servername");
2908 torture_assert_ntstatus_ok(torture
,
2909 torture_rpc_connection(torture
, &p
, &ndr_table_wkssvc
),
2910 "failed to setup wkssvc");
2912 b
= p
->binding_handle
;
2915 struct wkssvc_NetWkstaInfo100 wks100
;
2916 union wkssvc_NetWkstaInfo info
;
2917 struct wkssvc_NetWkstaGetInfo r
;
2919 r
.in
.server_name
= "\\foo";
2921 info
.info100
= &wks100
;
2924 torture_assert_ntstatus_ok(torture
,
2925 dcerpc_wkssvc_NetWkstaGetInfo_r(b
, torture
, &r
),
2926 "dcerpc_wkssvc_NetWksGetInfo failed");
2927 torture_assert_werr_ok(torture
, r
.out
.result
,
2928 "dcerpc_wkssvc_NetWksGetInfo failed");
2930 torture_assert_str_equal(torture
, servername
, r
.out
.info
->info100
->server_name
,
2931 "servername RAP / DCERPC inconsistency");
2937 static bool winreg_close(struct torture_context
*tctx
,
2938 struct dcerpc_binding_handle
*b
,
2939 struct policy_handle
*handle
)
2941 struct winreg_CloseKey c
;
2943 c
.in
.handle
= c
.out
.handle
= handle
;
2945 torture_assert_ntstatus_ok(tctx
,
2946 dcerpc_winreg_CloseKey_r(b
, tctx
, &c
),
2947 "winreg_CloseKey failed");
2948 torture_assert_werr_ok(tctx
, c
.out
.result
,
2949 "winreg_CloseKey failed");
2954 static bool enumvalues(struct torture_context
*tctx
,
2955 struct dcerpc_binding_handle
*b
,
2956 struct policy_handle
*handle
)
2958 uint32_t enum_index
= 0;
2961 struct winreg_EnumValue r
;
2962 struct winreg_ValNameBuf name
;
2963 enum winreg_Type type
= 0;
2966 uint32_t size
, length
;
2968 r
.in
.handle
= handle
;
2969 r
.in
.enum_index
= enum_index
;
2972 r
.in
.name
= r
.out
.name
= &name
;
2978 r
.in
.length
= &length
;
2980 status
= dcerpc_winreg_EnumValue_r(b
, tctx
, &r
);
2981 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(r
.out
.result
)) {
2988 static bool enumkeys(struct torture_context
*tctx
,
2989 struct dcerpc_binding_handle
*b
,
2990 struct policy_handle
*handle
,
2993 struct winreg_EnumKey r
;
2994 struct winreg_StringBuf kclass
, name
;
3005 r
.in
.handle
= handle
;
3006 r
.in
.enum_index
= 0;
3008 r
.in
.keyclass
= &kclass
;
3010 r
.in
.last_changed_time
= &t
;
3013 struct winreg_OpenKey o
;
3014 struct policy_handle key_handle
;
3020 status
= dcerpc_winreg_EnumKey_r(b
, tctx
, &r
);
3021 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(r
.out
.result
)) {
3022 /* We're done enumerating */
3026 for (i
=0; i
<10-depth
; i
++) {
3027 torture_comment(tctx
, " ");
3029 torture_comment(tctx
, "%s\n", r
.out
.name
->name
);
3031 o
.in
.parent_handle
= handle
;
3032 o
.in
.keyname
.name
= r
.out
.name
->name
;
3034 o
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3035 o
.out
.handle
= &key_handle
;
3037 status
= dcerpc_winreg_OpenKey_r(b
, tctx
, &o
);
3038 if (NT_STATUS_IS_OK(status
) && W_ERROR_IS_OK(o
.out
.result
)) {
3039 enumkeys(tctx
, b
, &key_handle
, depth
-1);
3040 enumvalues(tctx
, b
, &key_handle
);
3041 torture_assert(tctx
, winreg_close(tctx
, b
, &key_handle
), "");
3044 r
.in
.enum_index
+= 1;
3050 typedef NTSTATUS (*winreg_open_fn
)(struct dcerpc_binding_handle
*, TALLOC_CTX
*, void *);
3052 static bool test_Open3(struct torture_context
*tctx
,
3053 struct dcerpc_binding_handle
*b
,
3054 const char *name
, winreg_open_fn open_fn
)
3056 struct policy_handle handle
;
3057 struct winreg_OpenHKLM r
;
3059 r
.in
.system_name
= 0;
3060 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3061 r
.out
.handle
= &handle
;
3063 torture_assert_ntstatus_ok(tctx
,
3064 open_fn(b
, tctx
, &r
),
3065 talloc_asprintf(tctx
, "%s failed", name
));
3066 torture_assert_werr_ok(tctx
, r
.out
.result
,
3067 talloc_asprintf(tctx
, "%s failed", name
));
3069 enumkeys(tctx
, b
, &handle
, 4);
3071 torture_assert(tctx
,
3072 winreg_close(tctx
, b
, &handle
),
3073 "dcerpc_CloseKey failed");
3078 static bool torture_samba3_rpc_winreg(struct torture_context
*torture
)
3080 struct dcerpc_pipe
*p
;
3081 struct dcerpc_binding_handle
*b
;
3087 {"OpenHKLM", (winreg_open_fn
)dcerpc_winreg_OpenHKLM_r
},
3088 {"OpenHKU", (winreg_open_fn
)dcerpc_winreg_OpenHKU_r
},
3089 {"OpenHKPD", (winreg_open_fn
)dcerpc_winreg_OpenHKPD_r
},
3090 {"OpenHKPT", (winreg_open_fn
)dcerpc_winreg_OpenHKPT_r
},
3091 {"OpenHKCR", (winreg_open_fn
)dcerpc_winreg_OpenHKCR_r
}};
3096 torture_assert_ntstatus_ok(torture
,
3097 torture_rpc_connection(torture
, &p
, &ndr_table_winreg
),
3098 "failed to setup winreg");
3100 b
= p
->binding_handle
;
3103 ret
= test_Open3(torture
, b
, open_fns
[0].name
, open_fns
[0].fn
);
3105 for (i
= 0; i
< ARRAY_SIZE(open_fns
); i
++) {
3106 if (!test_Open3(torture
, b
, open_fns
[i
].name
, open_fns
[i
].fn
))
3113 static bool get_shareinfo(struct torture_context
*tctx
,
3114 struct dcerpc_binding_handle
*b
,
3115 const char *servername
,
3117 struct srvsvc_NetShareInfo502
**info502
)
3119 struct srvsvc_NetShareGetInfo r
;
3120 union srvsvc_NetShareInfo info
;
3122 r
.in
.server_unc
= talloc_asprintf(tctx
, "\\\\%s", servername
);
3123 r
.in
.share_name
= share
;
3127 torture_assert_ntstatus_ok(tctx
,
3128 dcerpc_srvsvc_NetShareGetInfo_r(b
, tctx
, &r
),
3129 "srvsvc_NetShareGetInfo failed");
3130 torture_assert_werr_ok(tctx
, r
.out
.result
,
3131 "srvsvc_NetShareGetInfo failed");
3133 *info502
= talloc_move(tctx
, &info
.info502
);
3139 * Get us a handle on HKLM\
3142 static bool get_hklm_handle(struct torture_context
*tctx
,
3143 struct dcerpc_binding_handle
*b
,
3144 struct policy_handle
*handle
)
3146 struct winreg_OpenHKLM r
;
3147 struct policy_handle result
;
3149 r
.in
.system_name
= 0;
3150 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3151 r
.out
.handle
= &result
;
3153 torture_assert_ntstatus_ok(tctx
,
3154 dcerpc_winreg_OpenHKLM_r(b
, tctx
, &r
),
3156 torture_assert_werr_ok(tctx
, r
.out
.result
,
3164 static bool torture_samba3_createshare(struct torture_context
*tctx
,
3165 struct dcerpc_binding_handle
*b
,
3166 const char *sharename
)
3168 struct policy_handle hklm
;
3169 struct policy_handle new_handle
;
3170 struct winreg_CreateKey c
;
3171 struct winreg_CloseKey cl
;
3172 enum winreg_CreateAction action_taken
;
3174 c
.in
.handle
= &hklm
;
3175 c
.in
.name
.name
= talloc_asprintf(
3176 tctx
, "software\\samba\\smbconf\\%s", sharename
);
3177 torture_assert(tctx
, c
.in
.name
.name
, "talloc_asprintf failed");
3179 c
.in
.keyclass
.name
= "";
3181 c
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3182 c
.in
.secdesc
= NULL
;
3183 c
.in
.action_taken
= &action_taken
;
3184 c
.out
.new_handle
= &new_handle
;
3185 c
.out
.action_taken
= &action_taken
;
3187 torture_assert_ntstatus_ok(tctx
,
3188 dcerpc_winreg_CreateKey_r(b
, tctx
, &c
),
3190 torture_assert_werr_ok(tctx
, c
.out
.result
,
3193 cl
.in
.handle
= &new_handle
;
3194 cl
.out
.handle
= &new_handle
;
3196 torture_assert_ntstatus_ok(tctx
,
3197 dcerpc_winreg_CloseKey_r(b
, tctx
, &cl
),
3199 torture_assert_werr_ok(tctx
, cl
.out
.result
,
3205 static bool torture_samba3_deleteshare(struct torture_context
*tctx
,
3206 struct dcerpc_binding_handle
*b
,
3207 const char *sharename
)
3209 struct policy_handle hklm
;
3210 struct winreg_DeleteKey d
;
3212 torture_assert(tctx
,
3213 get_hklm_handle(tctx
, b
, &hklm
),
3214 "get_hklm_handle failed");
3216 d
.in
.handle
= &hklm
;
3217 d
.in
.key
.name
= talloc_asprintf(
3218 tctx
, "software\\samba\\smbconf\\%s", sharename
);
3219 torture_assert(tctx
, d
.in
.key
.name
, "talloc_asprintf failed");
3221 torture_assert_ntstatus_ok(tctx
,
3222 dcerpc_winreg_DeleteKey_r(b
, tctx
, &d
),
3223 "DeleteKey failed");
3224 torture_assert_werr_ok(tctx
, d
.out
.result
,
3225 "DeleteKey failed");
3230 static bool torture_samba3_setconfig(struct torture_context
*tctx
,
3231 struct dcerpc_binding_handle
*b
,
3232 const char *sharename
,
3233 const char *parameter
,
3236 struct policy_handle hklm
, key_handle
;
3237 struct winreg_OpenKey o
;
3238 struct winreg_SetValue s
;
3242 torture_assert(tctx
,
3243 get_hklm_handle(tctx
, b
, &hklm
),
3244 "get_hklm_handle failed");
3246 o
.in
.parent_handle
= &hklm
;
3247 o
.in
.keyname
.name
= talloc_asprintf(
3248 tctx
, "software\\samba\\smbconf\\%s", sharename
);
3249 torture_assert(tctx
, o
.in
.keyname
.name
, "talloc_asprintf failed");
3252 o
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3253 o
.out
.handle
= &key_handle
;
3255 torture_assert_ntstatus_ok(tctx
,
3256 dcerpc_winreg_OpenKey_r(b
, tctx
, &o
),
3258 torture_assert_werr_ok(tctx
, o
.out
.result
,
3261 torture_assert(tctx
,
3262 reg_string_to_val(tctx
, "REG_SZ", value
, &type
, &val
),
3263 "reg_string_to_val failed");
3265 s
.in
.handle
= &key_handle
;
3266 s
.in
.name
.name
= parameter
;
3268 s
.in
.data
= val
.data
;
3269 s
.in
.size
= val
.length
;
3271 torture_assert_ntstatus_ok(tctx
,
3272 dcerpc_winreg_SetValue_r(b
, tctx
, &s
),
3274 torture_assert_werr_ok(tctx
, s
.out
.result
,
3280 static bool torture_samba3_regconfig(struct torture_context
*torture
)
3282 struct srvsvc_NetShareInfo502
*i
= NULL
;
3283 const char *comment
= "Dummer Kommentar";
3284 struct dcerpc_pipe
*srvsvc_pipe
, *winreg_pipe
;
3286 torture_assert_ntstatus_ok(torture
,
3287 torture_rpc_connection(torture
, &srvsvc_pipe
, &ndr_table_srvsvc
),
3288 "failed to setup srvsvc");
3290 torture_assert_ntstatus_ok(torture
,
3291 torture_rpc_connection(torture
, &winreg_pipe
, &ndr_table_winreg
),
3292 "failed to setup winreg");
3294 torture_assert(torture
,
3295 torture_samba3_createshare(torture
, winreg_pipe
->binding_handle
, "blubber"),
3296 "torture_samba3_createshare failed");
3298 torture_assert(torture
,
3299 torture_samba3_setconfig(torture
, winreg_pipe
->binding_handle
, "blubber", "comment", comment
),
3300 "torture_samba3_setconfig failed");
3302 torture_assert(torture
,
3303 get_shareinfo(torture
, srvsvc_pipe
->binding_handle
, dcerpc_server_name(srvsvc_pipe
), "blubber", &i
),
3304 "get_shareinfo failed");
3306 torture_assert_str_equal(torture
, comment
, i
->comment
,
3307 "got unexpected comment");
3309 torture_assert(torture
,
3310 torture_samba3_deleteshare(torture
, winreg_pipe
->binding_handle
, "blubber"),
3311 "torture_samba3_deleteshare failed");
3317 * Test that even with a result of 0 rids the array is returned as a
3318 * non-NULL pointer. Yes, XP does notice.
3321 bool torture_samba3_getaliasmembership_0(struct torture_context
*torture
)
3323 struct dcerpc_pipe
*p
;
3324 struct dcerpc_binding_handle
*b
;
3325 struct samr_Connect2 c
;
3326 struct samr_OpenDomain o
;
3328 struct lsa_SidPtr ptr
;
3329 struct lsa_SidArray sids
;
3330 struct samr_GetAliasMembership g
;
3331 struct samr_Ids rids
;
3332 struct policy_handle samr
, domain
;
3334 torture_assert_ntstatus_ok(torture
,
3335 torture_rpc_connection(torture
, &p
, &ndr_table_samr
),
3336 "failed to setup samr");
3338 b
= p
->binding_handle
;
3340 c
.in
.system_name
= NULL
;
3341 c
.in
.access_mask
= SAMR_ACCESS_LOOKUP_DOMAIN
;
3342 c
.out
.connect_handle
= &samr
;
3343 torture_assert_ntstatus_ok(torture
,
3344 dcerpc_samr_Connect2_r(b
, torture
, &c
),
3346 torture_assert_ntstatus_ok(torture
, c
.out
.result
,
3348 dom_sid_parse("S-1-5-32", &sid
);
3349 o
.in
.connect_handle
= &samr
;
3350 o
.in
.access_mask
= SAMR_DOMAIN_ACCESS_LOOKUP_ALIAS
;
3352 o
.out
.domain_handle
= &domain
;
3353 torture_assert_ntstatus_ok(torture
,
3354 dcerpc_samr_OpenDomain_r(b
, torture
, &o
),
3356 torture_assert_ntstatus_ok(torture
, o
.out
.result
,
3358 dom_sid_parse("S-1-2-3-4-5", &sid
);
3362 g
.in
.domain_handle
= &domain
;
3365 torture_assert_ntstatus_ok(torture
,
3366 dcerpc_samr_GetAliasMembership_r(b
, torture
, &g
),
3368 torture_assert_ntstatus_ok(torture
, g
.out
.result
,
3370 if (rids
.ids
== NULL
) {
3371 /* This is the piece to test here */
3372 torture_fail(torture
,
3373 "torture_samba3_getaliasmembership_0: "
3374 "Server returns NULL rids array\n");
3381 * Test smb reauthentication while rpc pipe is in use.
3383 static bool torture_rpc_smb_reauth1(struct torture_context
*torture
)
3385 TALLOC_CTX
*mem_ctx
;
3388 struct smbcli_state
*cli
;
3389 struct smbcli_options options
;
3390 struct smbcli_session_options session_options
;
3392 struct dcerpc_pipe
*lsa_pipe
;
3393 struct dcerpc_binding_handle
*lsa_handle
;
3394 struct lsa_GetUserName r
;
3395 struct lsa_String
*authority_name_p
= NULL
;
3396 char *authority_name_saved
= NULL
;
3397 struct lsa_String
*account_name_p
= NULL
;
3398 char *account_name_saved
= NULL
;
3399 struct cli_credentials
*anon_creds
= NULL
;
3400 struct smb_composite_sesssetup io
;
3402 mem_ctx
= talloc_init("torture_samba3_reauth");
3403 torture_assert(torture
, (mem_ctx
!= NULL
), "talloc_init failed");
3405 lpcfg_smbcli_options(torture
->lp_ctx
, &options
);
3406 lpcfg_smbcli_session_options(torture
->lp_ctx
, &session_options
);
3408 status
= smbcli_full_connection(mem_ctx
, &cli
,
3409 torture_setting_string(torture
, "host", NULL
),
3410 lpcfg_smb_ports(torture
->lp_ctx
),
3412 lpcfg_socket_options(torture
->lp_ctx
),
3413 cmdline_credentials
,
3414 lpcfg_resolve_context(torture
->lp_ctx
),
3415 torture
->ev
, &options
, &session_options
,
3416 lpcfg_gensec_settings(torture
, torture
->lp_ctx
));
3417 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3418 "smbcli_full_connection failed");
3420 lsa_pipe
= dcerpc_pipe_init(mem_ctx
, torture
->ev
);
3421 torture_assert_goto(torture
, (lsa_pipe
!= NULL
), ret
, done
,
3422 "dcerpc_pipe_init failed");
3423 lsa_handle
= lsa_pipe
->binding_handle
;
3425 status
= dcerpc_pipe_open_smb(lsa_pipe
, cli
->tree
, "\\lsarpc");
3426 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3427 "dcerpc_pipe_open failed");
3429 status
= dcerpc_bind_auth_none(lsa_pipe
, &ndr_table_lsarpc
);
3430 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3431 "dcerpc_bind_auth_none failed");
3433 /* lsa getusername */
3436 r
.in
.system_name
= "\\";
3437 r
.in
.account_name
= &account_name_p
;
3438 r
.in
.authority_name
= &authority_name_p
;
3439 r
.out
.account_name
= &account_name_p
;
3441 status
= dcerpc_lsa_GetUserName_r(lsa_handle
, mem_ctx
, &r
);
3443 authority_name_p
= *r
.out
.authority_name
;
3445 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3446 "GetUserName failed");
3447 torture_assert_ntstatus_ok_goto(torture
, r
.out
.result
, ret
, done
,
3448 "GetUserName failed");
3450 torture_comment(torture
, "lsa_GetUserName gave '%s\\%s'\n",
3451 authority_name_p
->string
,
3452 account_name_p
->string
);
3454 account_name_saved
= talloc_strdup(mem_ctx
, account_name_p
->string
);
3455 torture_assert_goto(torture
, (account_name_saved
!= NULL
), ret
, done
,
3457 authority_name_saved
= talloc_strdup(mem_ctx
, authority_name_p
->string
);
3458 torture_assert_goto(torture
, (authority_name_saved
!= NULL
), ret
, done
,
3461 /* smb re-authenticate as anonymous */
3463 anon_creds
= cli_credentials_init_anon(mem_ctx
);
3466 io
.in
.sesskey
= cli
->transport
->negotiate
.sesskey
;
3467 io
.in
.capabilities
= cli
->transport
->negotiate
.capabilities
;
3468 io
.in
.credentials
= anon_creds
;
3469 io
.in
.workgroup
= lpcfg_workgroup(torture
->lp_ctx
);
3470 io
.in
.gensec_settings
= lpcfg_gensec_settings(torture
, torture
->lp_ctx
);
3472 status
= smb_composite_sesssetup(cli
->session
, &io
);
3473 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3474 "session reauth to anon failed");
3476 /* re-do lsa getusername after reauth */
3478 TALLOC_FREE(authority_name_p
);
3479 TALLOC_FREE(account_name_p
);
3481 r
.in
.system_name
= "\\";
3482 r
.in
.account_name
= &account_name_p
;
3483 r
.in
.authority_name
= &authority_name_p
;
3484 r
.out
.account_name
= &account_name_p
;
3486 status
= dcerpc_lsa_GetUserName_r(lsa_handle
, mem_ctx
, &r
);
3488 authority_name_p
= *r
.out
.authority_name
;
3490 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3491 "GetUserName failed");
3492 torture_assert_ntstatus_ok_goto(torture
, r
.out
.result
, ret
, done
,
3493 "GetUserName failed");
3495 torture_assert_goto(torture
, (strcmp(authority_name_p
->string
, authority_name_saved
) == 0),
3496 ret
, done
, "authority_name not equal after reauth to anon");
3497 torture_assert_goto(torture
, (strcmp(account_name_p
->string
, account_name_saved
) == 0),
3498 ret
, done
, "account_name not equal after reauth to anon");
3500 /* smb re-auth again to the original user */
3503 io
.in
.sesskey
= cli
->transport
->negotiate
.sesskey
;
3504 io
.in
.capabilities
= cli
->transport
->negotiate
.capabilities
;
3505 io
.in
.credentials
= cmdline_credentials
;
3506 io
.in
.workgroup
= lpcfg_workgroup(torture
->lp_ctx
);
3507 io
.in
.gensec_settings
= lpcfg_gensec_settings(torture
, torture
->lp_ctx
);
3509 status
= smb_composite_sesssetup(cli
->session
, &io
);
3510 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3511 "session reauth to anon failed");
3513 /* re-do lsa getusername */
3515 TALLOC_FREE(authority_name_p
);
3516 TALLOC_FREE(account_name_p
);
3518 r
.in
.system_name
= "\\";
3519 r
.in
.account_name
= &account_name_p
;
3520 r
.in
.authority_name
= &authority_name_p
;
3521 r
.out
.account_name
= &account_name_p
;
3523 status
= dcerpc_lsa_GetUserName_r(lsa_handle
, mem_ctx
, &r
);
3525 authority_name_p
= *r
.out
.authority_name
;
3527 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3528 "GetUserName failed");
3529 torture_assert_ntstatus_ok_goto(torture
, r
.out
.result
, ret
, done
,
3530 "GetUserName failed");
3532 torture_assert_goto(torture
, (strcmp(authority_name_p
->string
, authority_name_saved
) == 0),
3533 ret
, done
, "authority_name not equal after reauth to anon");
3534 torture_assert_goto(torture
, (strcmp(account_name_p
->string
, account_name_saved
) == 0),
3535 ret
, done
, "account_name not equal after reauth to anon");
3540 talloc_free(mem_ctx
);
3545 * Test smb reauthentication while rpc pipe is in use.
3546 * Open a second lsa bind after reauth to anon.
3547 * Do lsa getusername on that second bind.
3549 static bool torture_rpc_smb_reauth2(struct torture_context
*torture
)
3551 TALLOC_CTX
*mem_ctx
;
3554 struct smbcli_state
*cli
;
3555 struct smbcli_options options
;
3556 struct smbcli_session_options session_options
;
3558 struct dcerpc_pipe
*lsa_pipe
;
3559 struct dcerpc_binding_handle
*lsa_handle
;
3560 struct lsa_GetUserName r
;
3561 struct lsa_String
*authority_name_p
= NULL
;
3562 char *authority_name_saved
= NULL
;
3563 struct lsa_String
*account_name_p
= NULL
;
3564 char *account_name_saved
= NULL
;
3565 struct cli_credentials
*anon_creds
= NULL
;
3566 struct smb_composite_sesssetup io
;
3568 mem_ctx
= talloc_init("torture_samba3_reauth");
3569 torture_assert(torture
, (mem_ctx
!= NULL
), "talloc_init failed");
3571 lpcfg_smbcli_options(torture
->lp_ctx
, &options
);
3572 lpcfg_smbcli_session_options(torture
->lp_ctx
, &session_options
);
3574 status
= smbcli_full_connection(mem_ctx
, &cli
,
3575 torture_setting_string(torture
, "host", NULL
),
3576 lpcfg_smb_ports(torture
->lp_ctx
),
3578 lpcfg_socket_options(torture
->lp_ctx
),
3579 cmdline_credentials
,
3580 lpcfg_resolve_context(torture
->lp_ctx
),
3581 torture
->ev
, &options
, &session_options
,
3582 lpcfg_gensec_settings(torture
, torture
->lp_ctx
));
3583 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3584 "smbcli_full_connection failed");
3586 /* smb re-authenticate as anonymous */
3588 anon_creds
= cli_credentials_init_anon(mem_ctx
);
3591 io
.in
.sesskey
= cli
->transport
->negotiate
.sesskey
;
3592 io
.in
.capabilities
= cli
->transport
->negotiate
.capabilities
;
3593 io
.in
.credentials
= anon_creds
;
3594 io
.in
.workgroup
= lpcfg_workgroup(torture
->lp_ctx
);
3595 io
.in
.gensec_settings
= lpcfg_gensec_settings(torture
, torture
->lp_ctx
);
3597 status
= smb_composite_sesssetup(cli
->session
, &io
);
3598 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3599 "session reauth to anon failed");
3601 /* open the lsa pipe */
3603 lsa_pipe
= dcerpc_pipe_init(mem_ctx
, torture
->ev
);
3604 torture_assert_goto(torture
, (lsa_pipe
!= NULL
), ret
, done
,
3605 "dcerpc_pipe_init failed");
3606 lsa_handle
= lsa_pipe
->binding_handle
;
3608 status
= dcerpc_pipe_open_smb(lsa_pipe
, cli
->tree
, "\\lsarpc");
3609 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3610 "dcerpc_pipe_open failed");
3612 status
= dcerpc_bind_auth_none(lsa_pipe
, &ndr_table_lsarpc
);
3613 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3614 "dcerpc_bind_auth_none failed");
3616 /* lsa getusername */
3619 r
.in
.system_name
= "\\";
3620 r
.in
.account_name
= &account_name_p
;
3621 r
.in
.authority_name
= &authority_name_p
;
3622 r
.out
.account_name
= &account_name_p
;
3624 status
= dcerpc_lsa_GetUserName_r(lsa_handle
, mem_ctx
, &r
);
3626 authority_name_p
= *r
.out
.authority_name
;
3628 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3629 "GetUserName failed");
3630 torture_assert_ntstatus_ok_goto(torture
, r
.out
.result
, ret
, done
,
3631 "GetUserName failed");
3633 torture_comment(torture
, "lsa_GetUserName gave '%s\\%s'\n",
3634 authority_name_p
->string
,
3635 account_name_p
->string
);
3637 account_name_saved
= talloc_strdup(mem_ctx
, account_name_p
->string
);
3638 torture_assert_goto(torture
, (account_name_saved
!= NULL
), ret
, done
,
3640 authority_name_saved
= talloc_strdup(mem_ctx
, authority_name_p
->string
);
3641 torture_assert_goto(torture
, (authority_name_saved
!= NULL
), ret
, done
,
3644 /* smb re-auth again to the original user */
3647 io
.in
.sesskey
= cli
->transport
->negotiate
.sesskey
;
3648 io
.in
.capabilities
= cli
->transport
->negotiate
.capabilities
;
3649 io
.in
.credentials
= cmdline_credentials
;
3650 io
.in
.workgroup
= lpcfg_workgroup(torture
->lp_ctx
);
3651 io
.in
.gensec_settings
= lpcfg_gensec_settings(torture
, torture
->lp_ctx
);
3653 status
= smb_composite_sesssetup(cli
->session
, &io
);
3654 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3655 "session reauth to anon failed");
3657 /* re-do lsa getusername after reauth */
3659 TALLOC_FREE(authority_name_p
);
3660 TALLOC_FREE(account_name_p
);
3662 r
.in
.system_name
= "\\";
3663 r
.in
.account_name
= &account_name_p
;
3664 r
.in
.authority_name
= &authority_name_p
;
3665 r
.out
.account_name
= &account_name_p
;
3667 status
= dcerpc_lsa_GetUserName_r(lsa_handle
, mem_ctx
, &r
);
3669 authority_name_p
= *r
.out
.authority_name
;
3671 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3672 "GetUserName failed");
3673 torture_assert_ntstatus_ok_goto(torture
, r
.out
.result
, ret
, done
,
3674 "GetUserName failed");
3676 torture_assert_goto(torture
, (strcmp(authority_name_p
->string
, authority_name_saved
) == 0),
3677 ret
, done
, "authority_name not equal after reauth to anon");
3678 torture_assert_goto(torture
, (strcmp(account_name_p
->string
, account_name_saved
) == 0),
3679 ret
, done
, "account_name not equal after reauth to anon");
3684 talloc_free(mem_ctx
);
3689 * Test smb2 reauthentication while rpc pipe is in use.
3691 static bool torture_rpc_smb2_reauth1(struct torture_context
*torture
)
3693 TALLOC_CTX
*mem_ctx
;
3696 struct smbcli_options options
;
3698 struct dcerpc_pipe
*lsa_pipe
;
3699 struct dcerpc_binding_handle
*lsa_handle
;
3700 struct lsa_GetUserName r
;
3701 struct lsa_String
*authority_name_p
= NULL
;
3702 char *authority_name_saved
= NULL
;
3703 struct lsa_String
*account_name_p
= NULL
;
3704 char *account_name_saved
= NULL
;
3705 struct cli_credentials
*anon_creds
= NULL
;
3706 const char *host
= torture_setting_string(torture
, "host", NULL
);
3707 struct smb2_tree
*tree
;
3709 mem_ctx
= talloc_init("torture_samba3_reauth");
3710 torture_assert(torture
, (mem_ctx
!= NULL
), "talloc_init failed");
3712 lpcfg_smbcli_options(torture
->lp_ctx
, &options
);
3714 status
= smb2_connect(mem_ctx
,
3716 lpcfg_smb_ports(torture
->lp_ctx
),
3718 lpcfg_resolve_context(torture
->lp_ctx
),
3719 cmdline_credentials
,
3723 lpcfg_socket_options(torture
->lp_ctx
),
3724 lpcfg_gensec_settings(torture
, torture
->lp_ctx
)
3726 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3727 "smb2_connect failed");
3729 lsa_pipe
= dcerpc_pipe_init(mem_ctx
, torture
->ev
);
3730 torture_assert_goto(torture
, (lsa_pipe
!= NULL
), ret
, done
,
3731 "dcerpc_pipe_init failed");
3732 lsa_handle
= lsa_pipe
->binding_handle
;
3734 status
= dcerpc_pipe_open_smb2(lsa_pipe
, tree
, "lsarpc");
3735 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3736 "dcerpc_pipe_open_smb2 failed");
3738 status
= dcerpc_bind_auth_none(lsa_pipe
, &ndr_table_lsarpc
);
3739 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3740 "dcerpc_bind_auth_none failed");
3742 /* lsa getusername */
3745 r
.in
.system_name
= "\\";
3746 r
.in
.account_name
= &account_name_p
;
3747 r
.in
.authority_name
= &authority_name_p
;
3748 r
.out
.account_name
= &account_name_p
;
3750 status
= dcerpc_lsa_GetUserName_r(lsa_handle
, mem_ctx
, &r
);
3752 authority_name_p
= *r
.out
.authority_name
;
3754 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3755 "GetUserName failed");
3756 torture_assert_ntstatus_ok_goto(torture
, r
.out
.result
, ret
, done
,
3757 "GetUserName failed");
3759 torture_comment(torture
, "lsa_GetUserName gave '%s\\%s'\n",
3760 authority_name_p
->string
,
3761 account_name_p
->string
);
3763 account_name_saved
= talloc_strdup(mem_ctx
, account_name_p
->string
);
3764 torture_assert_goto(torture
, (account_name_saved
!= NULL
), ret
, done
,
3766 authority_name_saved
= talloc_strdup(mem_ctx
, authority_name_p
->string
);
3767 torture_assert_goto(torture
, (authority_name_saved
!= NULL
), ret
, done
,
3770 /* smb re-authenticate as anonymous */
3772 anon_creds
= cli_credentials_init_anon(mem_ctx
);
3774 status
= smb2_session_setup_spnego(tree
->session
,
3776 0 /* previous_session_id */);
3777 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3778 "session reauth to anon failed");
3780 /* re-do lsa getusername after reauth */
3782 TALLOC_FREE(authority_name_p
);
3783 TALLOC_FREE(account_name_p
);
3785 r
.in
.system_name
= "\\";
3786 r
.in
.account_name
= &account_name_p
;
3787 r
.in
.authority_name
= &authority_name_p
;
3788 r
.out
.account_name
= &account_name_p
;
3790 status
= dcerpc_lsa_GetUserName_r(lsa_handle
, mem_ctx
, &r
);
3792 authority_name_p
= *r
.out
.authority_name
;
3794 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3795 "GetUserName failed");
3796 torture_assert_ntstatus_ok_goto(torture
, r
.out
.result
, ret
, done
,
3797 "GetUserName failed");
3799 torture_assert_goto(torture
, (strcmp(authority_name_p
->string
, authority_name_saved
) == 0),
3800 ret
, done
, "authority_name not equal after reauth to anon");
3801 torture_assert_goto(torture
, (strcmp(account_name_p
->string
, account_name_saved
) == 0),
3802 ret
, done
, "account_name not equal after reauth to anon");
3804 /* smb re-auth again to the original user */
3806 status
= smb2_session_setup_spnego(tree
->session
,
3807 cmdline_credentials
,
3808 0 /* previous_session_id */);
3809 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3810 "session reauth to anon failed");
3812 /* re-do lsa getusername */
3814 TALLOC_FREE(authority_name_p
);
3815 TALLOC_FREE(account_name_p
);
3817 r
.in
.system_name
= "\\";
3818 r
.in
.account_name
= &account_name_p
;
3819 r
.in
.authority_name
= &authority_name_p
;
3820 r
.out
.account_name
= &account_name_p
;
3822 status
= dcerpc_lsa_GetUserName_r(lsa_handle
, mem_ctx
, &r
);
3824 authority_name_p
= *r
.out
.authority_name
;
3826 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3827 "GetUserName failed");
3828 torture_assert_ntstatus_ok_goto(torture
, r
.out
.result
, ret
, done
,
3829 "GetUserName failed");
3831 torture_assert_goto(torture
, (strcmp(authority_name_p
->string
, authority_name_saved
) == 0),
3832 ret
, done
, "authority_name not equal after reauth to anon");
3833 torture_assert_goto(torture
, (strcmp(account_name_p
->string
, account_name_saved
) == 0),
3834 ret
, done
, "account_name not equal after reauth to anon");
3839 talloc_free(mem_ctx
);
3844 * Test smb2 reauthentication while rpc pipe is in use.
3845 * Open a second lsa bind after reauth to anon.
3846 * Do lsa getusername on that second bind.
3848 static bool torture_rpc_smb2_reauth2(struct torture_context
*torture
)
3850 TALLOC_CTX
*mem_ctx
;
3853 struct smbcli_options options
;
3855 struct dcerpc_pipe
*lsa_pipe
;
3856 struct dcerpc_binding_handle
*lsa_handle
;
3857 struct lsa_GetUserName r
;
3858 struct lsa_String
*authority_name_p
= NULL
;
3859 char *authority_name_saved
= NULL
;
3860 struct lsa_String
*account_name_p
= NULL
;
3861 char *account_name_saved
= NULL
;
3862 struct cli_credentials
*anon_creds
= NULL
;
3863 const char *host
= torture_setting_string(torture
, "host", NULL
);
3864 struct smb2_tree
*tree
;
3866 mem_ctx
= talloc_init("torture_samba3_reauth");
3867 torture_assert(torture
, (mem_ctx
!= NULL
), "talloc_init failed");
3869 lpcfg_smbcli_options(torture
->lp_ctx
, &options
);
3871 status
= smb2_connect(mem_ctx
,
3873 lpcfg_smb_ports(torture
->lp_ctx
),
3875 lpcfg_resolve_context(torture
->lp_ctx
),
3876 cmdline_credentials
,
3880 lpcfg_socket_options(torture
->lp_ctx
),
3881 lpcfg_gensec_settings(torture
, torture
->lp_ctx
)
3883 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3884 "smb2_connect failed");
3886 /* smb re-authenticate as anonymous */
3888 anon_creds
= cli_credentials_init_anon(mem_ctx
);
3890 status
= smb2_session_setup_spnego(tree
->session
,
3892 0 /* previous_session_id */);
3893 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3894 "session reauth to anon failed");
3896 /* open the lsa pipe */
3898 lsa_pipe
= dcerpc_pipe_init(mem_ctx
, torture
->ev
);
3899 torture_assert_goto(torture
, (lsa_pipe
!= NULL
), ret
, done
,
3900 "dcerpc_pipe_init failed");
3901 lsa_handle
= lsa_pipe
->binding_handle
;
3903 status
= dcerpc_pipe_open_smb2(lsa_pipe
, tree
, "lsarpc");
3904 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3905 "dcerpc_pipe_open_smb2 failed");
3907 status
= dcerpc_bind_auth_none(lsa_pipe
, &ndr_table_lsarpc
);
3908 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3909 "dcerpc_bind_auth_none failed");
3911 /* lsa getusername */
3914 r
.in
.system_name
= "\\";
3915 r
.in
.account_name
= &account_name_p
;
3916 r
.in
.authority_name
= &authority_name_p
;
3917 r
.out
.account_name
= &account_name_p
;
3919 status
= dcerpc_lsa_GetUserName_r(lsa_handle
, mem_ctx
, &r
);
3921 authority_name_p
= *r
.out
.authority_name
;
3923 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3924 "GetUserName failed");
3925 torture_assert_ntstatus_ok_goto(torture
, r
.out
.result
, ret
, done
,
3926 "GetUserName failed");
3928 torture_comment(torture
, "lsa_GetUserName gave '%s\\%s'\n",
3929 authority_name_p
->string
,
3930 account_name_p
->string
);
3932 account_name_saved
= talloc_strdup(mem_ctx
, account_name_p
->string
);
3933 torture_assert_goto(torture
, (account_name_saved
!= NULL
), ret
, done
,
3935 authority_name_saved
= talloc_strdup(mem_ctx
, authority_name_p
->string
);
3936 torture_assert_goto(torture
, (authority_name_saved
!= NULL
), ret
, done
,
3939 /* smb re-auth again to the original user */
3941 status
= smb2_session_setup_spnego(tree
->session
,
3942 cmdline_credentials
,
3943 0 /* previous_session_id */);
3944 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3945 "session reauth to anon failed");
3947 /* re-do lsa getusername */
3949 TALLOC_FREE(authority_name_p
);
3950 TALLOC_FREE(account_name_p
);
3952 r
.in
.system_name
= "\\";
3953 r
.in
.account_name
= &account_name_p
;
3954 r
.in
.authority_name
= &authority_name_p
;
3955 r
.out
.account_name
= &account_name_p
;
3957 status
= dcerpc_lsa_GetUserName_r(lsa_handle
, mem_ctx
, &r
);
3959 authority_name_p
= *r
.out
.authority_name
;
3961 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3962 "GetUserName failed");
3963 torture_assert_ntstatus_ok_goto(torture
, r
.out
.result
, ret
, done
,
3964 "GetUserName failed");
3966 torture_assert_goto(torture
, (strcmp(authority_name_p
->string
, authority_name_saved
) == 0),
3967 ret
, done
, "authority_name not equal after reauth to anon");
3968 torture_assert_goto(torture
, (strcmp(account_name_p
->string
, account_name_saved
) == 0),
3969 ret
, done
, "account_name not equal after reauth to anon");
3974 talloc_free(mem_ctx
);
3978 static bool torture_rpc_smb1_pipe_name(struct torture_context
*torture
)
3980 TALLOC_CTX
*mem_ctx
;
3983 struct smbcli_state
*cli
;
3984 struct smbcli_options options
;
3985 struct smbcli_session_options session_options
;
3990 mem_ctx
= talloc_init("torture_samba3_smb1_pipe_name");
3991 torture_assert(torture
, (mem_ctx
!= NULL
), "talloc_init failed");
3993 lpcfg_smbcli_options(torture
->lp_ctx
, &options
);
3994 lpcfg_smbcli_session_options(torture
->lp_ctx
, &session_options
);
3996 status
= smbcli_full_connection(mem_ctx
, &cli
,
3997 torture_setting_string(torture
, "host", NULL
),
3998 lpcfg_smb_ports(torture
->lp_ctx
),
4000 lpcfg_socket_options(torture
->lp_ctx
),
4001 cmdline_credentials
,
4002 lpcfg_resolve_context(torture
->lp_ctx
),
4003 torture
->ev
, &options
, &session_options
,
4004 lpcfg_gensec_settings(torture
, torture
->lp_ctx
));
4005 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4006 "smbcli_full_connection failed");
4009 io
.generic
.level
= RAW_OPEN_NTCREATEX
;
4010 io
.ntcreatex
.in
.access_mask
= DESIRED_ACCESS_PIPE
;
4011 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
4012 NTCREATEX_SHARE_ACCESS_WRITE
;
4013 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_OPEN
;
4014 io
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_IMPERSONATION
;
4015 io
.ntcreatex
.in
.security_flags
= 0;
4017 io
.ntcreatex
.in
.fname
= "__none__";
4018 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4019 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
4021 "smb_raw_open for '__none__'");
4023 io
.ntcreatex
.in
.fname
= "pipe\\srvsvc";
4024 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4025 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
4027 "smb_raw_open for 'pipe\\srvsvc'");
4029 io
.ntcreatex
.in
.fname
= "\\pipe\\srvsvc";
4030 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4031 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
4033 "smb_raw_open for '\\pipe\\srvsvc'");
4035 io
.ntcreatex
.in
.fname
= "srvsvc";
4036 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4037 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4038 "smb2_create failed for 'srvsvc'");
4039 fnum
= io
.ntcreatex
.out
.file
.fnum
;
4041 cl
.generic
.level
= RAW_CLOSE_CLOSE
;
4042 cl
.close
.in
.file
.fnum
= fnum
;
4043 status
= smb_raw_close(cli
->tree
, &cl
);
4044 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4045 "smb_raw_close failed");
4047 io
.ntcreatex
.in
.fname
= "\\srvsvc";
4048 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4049 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4050 "smb2_create failed for '\\srvsvc'");
4051 fnum
= io
.ntcreatex
.out
.file
.fnum
;
4053 cl
.generic
.level
= RAW_CLOSE_CLOSE
;
4054 cl
.close
.in
.file
.fnum
= fnum
;
4055 status
= smb_raw_close(cli
->tree
, &cl
);
4056 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4057 "smb_raw_close failed");
4059 io
.ntcreatex
.in
.fname
= "\\\\\\\\\\srvsvc";
4060 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4061 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4062 "smb2_create failed for '\\\\\\\\\\srvsvc'");
4063 fnum
= io
.ntcreatex
.out
.file
.fnum
;
4065 cl
.generic
.level
= RAW_CLOSE_CLOSE
;
4066 cl
.close
.in
.file
.fnum
= fnum
;
4067 status
= smb_raw_close(cli
->tree
, &cl
);
4068 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4069 "smb_raw_close failed");
4072 io
.generic
.level
= RAW_OPEN_NTTRANS_CREATE
;
4073 io
.nttrans
.in
.access_mask
= DESIRED_ACCESS_PIPE
;
4074 io
.nttrans
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
4075 NTCREATEX_SHARE_ACCESS_WRITE
;
4076 io
.nttrans
.in
.open_disposition
= NTCREATEX_DISP_OPEN
;
4077 io
.nttrans
.in
.impersonation
= NTCREATEX_IMPERSONATION_IMPERSONATION
;
4078 io
.nttrans
.in
.security_flags
= 0;
4080 io
.nttrans
.in
.fname
= "__none__";
4081 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4082 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
4084 "smb_raw_open for '__none__'");
4086 io
.nttrans
.in
.fname
= "pipe\\srvsvc";
4087 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4088 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
4090 "smb_raw_open for 'pipe\\srvsvc'");
4092 io
.nttrans
.in
.fname
= "\\pipe\\srvsvc";
4093 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4094 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
4096 "smb_raw_open for '\\pipe\\srvsvc'");
4098 io
.nttrans
.in
.fname
= "srvsvc";
4099 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4100 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4101 "smb2_create failed for 'srvsvc'");
4102 fnum
= io
.nttrans
.out
.file
.fnum
;
4104 cl
.generic
.level
= RAW_CLOSE_CLOSE
;
4105 cl
.close
.in
.file
.fnum
= fnum
;
4106 status
= smb_raw_close(cli
->tree
, &cl
);
4107 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4108 "smb_raw_close failed");
4110 io
.nttrans
.in
.fname
= "\\srvsvc";
4111 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4112 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4113 "smb2_create failed for '\\srvsvc'");
4114 fnum
= io
.nttrans
.out
.file
.fnum
;
4116 cl
.generic
.level
= RAW_CLOSE_CLOSE
;
4117 cl
.close
.in
.file
.fnum
= fnum
;
4118 status
= smb_raw_close(cli
->tree
, &cl
);
4119 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4120 "smb_raw_close failed");
4122 io
.nttrans
.in
.fname
= "\\\\\\\\\\srvsvc";
4123 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4124 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4125 "smb2_create failed for '\\\\\\\\\\srvsvc'");
4126 fnum
= io
.nttrans
.out
.file
.fnum
;
4128 cl
.generic
.level
= RAW_CLOSE_CLOSE
;
4129 cl
.close
.in
.file
.fnum
= fnum
;
4130 status
= smb_raw_close(cli
->tree
, &cl
);
4131 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4132 "smb_raw_close failed");
4135 io
.generic
.level
= RAW_OPEN_OPENX
;
4136 io
.openx
.in
.open_mode
= OPENX_MODE_ACCESS_RDWR
;
4137 io
.openx
.in
.open_func
= OPENX_OPEN_FUNC_OPEN
;
4139 io
.openx
.in
.fname
= "__none__";
4140 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4141 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_OBJECT_PATH_SYNTAX_BAD
,
4143 "smb_raw_open for '__none__'");
4145 io
.openx
.in
.fname
= "srvsvc";
4146 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4147 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_OBJECT_PATH_SYNTAX_BAD
,
4149 "smb_raw_open for 'srvsvc'");
4151 io
.openx
.in
.fname
= "\\srvsvc";
4152 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4153 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_OBJECT_PATH_SYNTAX_BAD
,
4155 "smb_raw_open for '\\srvsvc'");
4157 io
.openx
.in
.fname
= "\\pipesrvsvc";
4158 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4159 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_OBJECT_PATH_SYNTAX_BAD
,
4161 "smb_raw_open for '\\pipesrvsvc'");
4163 io
.openx
.in
.fname
= "pipe\\__none__";
4164 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4165 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
4167 "smb_raw_open for 'pipe\\__none__'");
4169 io
.openx
.in
.fname
= "\\pipe\\__none__";
4170 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4171 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
4173 "smb_raw_open for '\\pipe\\__none__'");
4175 io
.openx
.in
.fname
= "pipe\\srvsvc";
4176 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4177 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4178 "smb2_create failed for 'pipe\\srvsvc'");
4179 fnum
= io
.openx
.out
.file
.fnum
;
4181 cl
.generic
.level
= RAW_CLOSE_CLOSE
;
4182 cl
.close
.in
.file
.fnum
= fnum
;
4183 status
= smb_raw_close(cli
->tree
, &cl
);
4184 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4185 "smb_raw_close failed");
4187 io
.openx
.in
.fname
= "\\pipe\\srvsvc";
4188 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4189 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4190 "smb2_create failed for '\\pipe\\srvsvc'");
4191 fnum
= io
.openx
.out
.file
.fnum
;
4193 cl
.generic
.level
= RAW_CLOSE_CLOSE
;
4194 cl
.close
.in
.file
.fnum
= fnum
;
4195 status
= smb_raw_close(cli
->tree
, &cl
);
4196 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4197 "smb_raw_close failed");
4199 io
.openx
.in
.fname
= "\\\\\\\\\\pipe\\srvsvc";
4200 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4201 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4202 "smb2_create failed for '\\\\\\\\\\pipe\\srvsvc'");
4203 fnum
= io
.openx
.out
.file
.fnum
;
4205 cl
.generic
.level
= RAW_CLOSE_CLOSE
;
4206 cl
.close
.in
.file
.fnum
= fnum
;
4207 status
= smb_raw_close(cli
->tree
, &cl
);
4208 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4209 "smb_raw_close failed");
4211 io
.openx
.in
.fname
= "\\\\\\\\\\pipe\\\\\\\\\\srvsvc";
4212 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4213 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4214 "smb2_create failed for '\\\\\\\\\\pipe\\\\\\\\\\srvsvc'");
4215 fnum
= io
.openx
.out
.file
.fnum
;
4217 cl
.generic
.level
= RAW_CLOSE_CLOSE
;
4218 cl
.close
.in
.file
.fnum
= fnum
;
4219 status
= smb_raw_close(cli
->tree
, &cl
);
4220 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4221 "smb_raw_close failed");
4225 talloc_free(mem_ctx
);
4229 static bool torture_rpc_smb2_pipe_name(struct torture_context
*torture
)
4231 TALLOC_CTX
*mem_ctx
;
4234 struct smbcli_options options
;
4235 const char *host
= torture_setting_string(torture
, "host", NULL
);
4236 struct smb2_tree
*tree
;
4237 struct smb2_handle h
;
4238 struct smb2_create io
;
4240 mem_ctx
= talloc_init("torture_samba3_smb2_pipe_name");
4241 torture_assert(torture
, (mem_ctx
!= NULL
), "talloc_init failed");
4243 lpcfg_smbcli_options(torture
->lp_ctx
, &options
);
4245 status
= smb2_connect(mem_ctx
,
4247 lpcfg_smb_ports(torture
->lp_ctx
),
4249 lpcfg_resolve_context(torture
->lp_ctx
),
4250 cmdline_credentials
,
4254 lpcfg_socket_options(torture
->lp_ctx
),
4255 lpcfg_gensec_settings(torture
, torture
->lp_ctx
)
4257 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4258 "smb2_connect failed");
4261 io
.in
.oplock_level
= 0;
4262 io
.in
.desired_access
= DESIRED_ACCESS_PIPE
;
4263 io
.in
.impersonation_level
= SMB2_IMPERSONATION_IMPERSONATION
;
4264 io
.in
.file_attributes
= 0;
4265 io
.in
.create_disposition
= NTCREATEX_DISP_OPEN
;
4266 io
.in
.share_access
=
4267 NTCREATEX_SHARE_ACCESS_READ
|
4268 NTCREATEX_SHARE_ACCESS_WRITE
;
4269 io
.in
.create_options
= 0;
4271 io
.in
.fname
= "__none__";
4272 status
= smb2_create(tree
, tree
, &io
);
4273 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
4275 "smb2_create for '__none__'");
4277 io
.in
.fname
= "\\srvsvc";
4278 status
= smb2_create(tree
, tree
, &io
);
4279 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
4281 "smb2_create for '\\srvsvc'");
4283 io
.in
.fname
= "\\pipe\\srvsvc";
4284 status
= smb2_create(tree
, tree
, &io
);
4285 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
4287 "smb2_create for '\\pipe\\srvsvc'");
4289 io
.in
.fname
= "pipe\\srvsvc";
4290 status
= smb2_create(tree
, tree
, &io
);
4291 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
4293 "smb2_create for 'pipe\\srvsvc'");
4295 io
.in
.fname
= "srvsvc";
4296 status
= smb2_create(tree
, tree
, &io
);
4297 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4298 "smb2_create failed for 'srvsvc'");
4300 h
= io
.out
.file
.handle
;
4302 status
= smb2_util_close(tree
, h
);
4303 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4304 "smb2_util_close failed");
4308 talloc_free(mem_ctx
);
4313 * Test behaviour of a waiting read call on a pipe when
4314 * the pipe handle is closed:
4315 * - open a pipe via smb2
4316 * - trigger a read which hangs since there is nothing to read
4317 * - close the pipe file handle
4318 * - wait for the read to return and check the status
4319 * (STATUS_PIPE_BROKEN)
4321 static bool torture_rpc_smb2_pipe_read_close(struct torture_context
*torture
)
4323 TALLOC_CTX
*mem_ctx
;
4326 struct smbcli_options options
;
4327 const char *host
= torture_setting_string(torture
, "host", NULL
);
4328 struct smb2_tree
*tree
;
4329 struct smb2_handle h
;
4330 struct smb2_request
*smb2req
;
4331 struct smb2_create io
;
4332 struct smb2_read rd
;
4334 mem_ctx
= talloc_init("torture_samba3_pipe_read_close");
4335 torture_assert(torture
, (mem_ctx
!= NULL
), "talloc_init failed");
4337 lpcfg_smbcli_options(torture
->lp_ctx
, &options
);
4339 status
= smb2_connect(mem_ctx
,
4341 lpcfg_smb_ports(torture
->lp_ctx
),
4343 lpcfg_resolve_context(torture
->lp_ctx
),
4344 cmdline_credentials
,
4348 lpcfg_socket_options(torture
->lp_ctx
),
4349 lpcfg_gensec_settings(torture
, torture
->lp_ctx
)
4351 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4352 "smb2_connect failed");
4355 io
.in
.oplock_level
= 0;
4356 io
.in
.desired_access
= DESIRED_ACCESS_PIPE
;
4357 io
.in
.impersonation_level
= SMB2_IMPERSONATION_IMPERSONATION
;
4358 io
.in
.file_attributes
= 0;
4359 io
.in
.create_disposition
= NTCREATEX_DISP_OPEN
;
4360 io
.in
.share_access
=
4361 NTCREATEX_SHARE_ACCESS_READ
|
4362 NTCREATEX_SHARE_ACCESS_WRITE
;
4363 io
.in
.create_options
= 0;
4364 io
.in
.fname
= "lsarpc";
4366 status
= smb2_create(tree
, tree
, &io
);
4367 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4368 "smb2_create failed for 'lsarpc'");
4370 h
= io
.out
.file
.handle
;
4373 rd
.in
.file
.handle
= h
;
4374 rd
.in
.length
= 1024;
4376 rd
.in
.min_count
= 0;
4378 smb2req
= smb2_read_send(tree
, &rd
);
4379 torture_assert_goto(torture
, (smb2req
!= NULL
), ret
, done
,
4380 "smb2_read_send failed");
4382 status
= smb2_util_close(tree
, h
);
4383 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4384 "smb2_util_close failed");
4386 status
= smb2_read_recv(smb2req
, mem_ctx
, &rd
);
4387 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_PIPE_BROKEN
, ret
, done
,
4388 "smb2_read_recv: unexpected return code");
4392 talloc_free(mem_ctx
);
4397 * Test behaviour of a waiting read call on a pipe when
4398 * the tree is disconnected.
4399 * - open a pipe via smb2
4400 * - trigger a read which hangs since there is nothing to read
4401 * - do a tree disconnect
4402 * - wait for the read to return and check the status
4403 * (STATUS_PIPE_BROKEN)
4405 static bool torture_rpc_smb2_pipe_read_tdis(struct torture_context
*torture
)
4407 TALLOC_CTX
*mem_ctx
;
4410 struct smbcli_options options
;
4411 const char *host
= torture_setting_string(torture
, "host", NULL
);
4412 struct smb2_tree
*tree
;
4413 struct smb2_handle h
;
4414 struct smb2_request
*smb2req
;
4415 struct smb2_create io
;
4416 struct smb2_read rd
;
4418 mem_ctx
= talloc_init("torture_samba3_pipe_read_tdis");
4419 torture_assert(torture
, (mem_ctx
!= NULL
), "talloc_init failed");
4421 lpcfg_smbcli_options(torture
->lp_ctx
, &options
);
4423 status
= smb2_connect(mem_ctx
,
4425 lpcfg_smb_ports(torture
->lp_ctx
),
4427 lpcfg_resolve_context(torture
->lp_ctx
),
4428 cmdline_credentials
,
4432 lpcfg_socket_options(torture
->lp_ctx
),
4433 lpcfg_gensec_settings(torture
, torture
->lp_ctx
)
4435 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4436 "smb2_connect failed");
4439 io
.in
.oplock_level
= 0;
4440 io
.in
.desired_access
= DESIRED_ACCESS_PIPE
;
4441 io
.in
.impersonation_level
= SMB2_IMPERSONATION_IMPERSONATION
;
4442 io
.in
.file_attributes
= 0;
4443 io
.in
.create_disposition
= NTCREATEX_DISP_OPEN
;
4444 io
.in
.share_access
=
4445 NTCREATEX_SHARE_ACCESS_READ
|
4446 NTCREATEX_SHARE_ACCESS_WRITE
;
4447 io
.in
.create_options
= 0;
4448 io
.in
.fname
= "lsarpc";
4450 status
= smb2_create(tree
, tree
, &io
);
4451 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4452 "smb2_create failed for 'lsarpc'");
4454 h
= io
.out
.file
.handle
;
4457 rd
.in
.file
.handle
= h
;
4458 rd
.in
.length
= 1024;
4460 rd
.in
.min_count
= 0;
4462 smb2req
= smb2_read_send(tree
, &rd
);
4463 torture_assert_goto(torture
, (smb2req
!= NULL
), ret
, done
,
4464 "smb2_read_send failed");
4466 status
= smb2_tdis(tree
);
4467 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4468 "smb2_tdis failed");
4470 status
= smb2_read_recv(smb2req
, mem_ctx
, &rd
);
4471 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_PIPE_BROKEN
, ret
, done
,
4472 "smb2_read_recv: unexpected return code");
4476 talloc_free(mem_ctx
);
4481 * Test behaviour of a waiting read call on a pipe when
4483 * - open a pipe via smb2
4484 * - trigger a read which hangs since there is nothing to read
4486 * - wait for the read to return and check the status
4487 * (STATUS_PIPE_BROKEN)
4489 static bool torture_rpc_smb2_pipe_read_logoff(struct torture_context
*torture
)
4491 TALLOC_CTX
*mem_ctx
;
4494 struct smbcli_options options
;
4495 const char *host
= torture_setting_string(torture
, "host", NULL
);
4496 struct smb2_tree
*tree
;
4497 struct smb2_handle h
;
4498 struct smb2_request
*smb2req
;
4499 struct smb2_create io
;
4500 struct smb2_read rd
;
4502 mem_ctx
= talloc_init("torture_samba3_pipe_read_tdis");
4503 torture_assert(torture
, (mem_ctx
!= NULL
), "talloc_init failed");
4505 lpcfg_smbcli_options(torture
->lp_ctx
, &options
);
4507 status
= smb2_connect(mem_ctx
,
4509 lpcfg_smb_ports(torture
->lp_ctx
),
4511 lpcfg_resolve_context(torture
->lp_ctx
),
4512 cmdline_credentials
,
4516 lpcfg_socket_options(torture
->lp_ctx
),
4517 lpcfg_gensec_settings(torture
, torture
->lp_ctx
)
4519 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4520 "smb2_connect failed");
4523 io
.in
.oplock_level
= 0;
4524 io
.in
.desired_access
= DESIRED_ACCESS_PIPE
;
4525 io
.in
.impersonation_level
= SMB2_IMPERSONATION_IMPERSONATION
;
4526 io
.in
.file_attributes
= 0;
4527 io
.in
.create_disposition
= NTCREATEX_DISP_OPEN
;
4528 io
.in
.share_access
=
4529 NTCREATEX_SHARE_ACCESS_READ
|
4530 NTCREATEX_SHARE_ACCESS_WRITE
;
4531 io
.in
.create_options
= 0;
4532 io
.in
.fname
= "lsarpc";
4534 status
= smb2_create(tree
, tree
, &io
);
4535 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4536 "smb2_create failed for 'lsarpc'");
4538 h
= io
.out
.file
.handle
;
4541 rd
.in
.file
.handle
= h
;
4542 rd
.in
.length
= 1024;
4544 rd
.in
.min_count
= 0;
4546 smb2req
= smb2_read_send(tree
, &rd
);
4547 torture_assert_goto(torture
, (smb2req
!= NULL
), ret
, done
,
4548 "smb2_read_send failed");
4550 status
= smb2_logoff(tree
->session
);
4551 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4552 "smb2_logoff failed");
4554 status
= smb2_read_recv(smb2req
, mem_ctx
, &rd
);
4555 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_PIPE_BROKEN
, ret
, done
,
4556 "smb2_read_recv: unexpected return code");
4560 talloc_free(mem_ctx
);
4565 struct torture_suite
*torture_rpc_samba3(TALLOC_CTX
*mem_ctx
)
4567 struct torture_suite
*suite
= torture_suite_create(mem_ctx
, "samba3");
4569 torture_suite_add_simple_test(suite
, "bind", torture_bind_samba3
);
4570 torture_suite_add_simple_test(suite
, "netlogon", torture_netlogon_samba3
);
4571 torture_suite_add_simple_test(suite
, "sessionkey", torture_samba3_sessionkey
);
4572 torture_suite_add_simple_test(suite
, "srvsvc", torture_samba3_rpc_srvsvc
);
4573 torture_suite_add_simple_test(suite
, "sharesec", torture_samba3_rpc_sharesec
);
4574 torture_suite_add_simple_test(suite
, "getusername", torture_samba3_rpc_getusername
);
4575 torture_suite_add_simple_test(suite
, "randomauth2", torture_samba3_rpc_randomauth2
);
4576 torture_suite_add_simple_test(suite
, "lsa", torture_samba3_rpc_lsa
);
4577 torture_suite_add_simple_test(suite
, "spoolss", torture_samba3_rpc_spoolss
);
4578 torture_suite_add_simple_test(suite
, "wkssvc", torture_samba3_rpc_wkssvc
);
4579 torture_suite_add_simple_test(suite
, "winreg", torture_samba3_rpc_winreg
);
4580 torture_suite_add_simple_test(suite
, "getaliasmembership-0", torture_samba3_getaliasmembership_0
);
4581 torture_suite_add_simple_test(suite
, "regconfig", torture_samba3_regconfig
);
4582 torture_suite_add_simple_test(suite
, "smb-reauth1", torture_rpc_smb_reauth1
);
4583 torture_suite_add_simple_test(suite
, "smb-reauth2", torture_rpc_smb_reauth2
);
4584 torture_suite_add_simple_test(suite
, "smb2-reauth1", torture_rpc_smb2_reauth1
);
4585 torture_suite_add_simple_test(suite
, "smb2-reauth2", torture_rpc_smb2_reauth2
);
4586 torture_suite_add_simple_test(suite
, "smb1-pipe-name", torture_rpc_smb1_pipe_name
);
4587 torture_suite_add_simple_test(suite
, "smb2-pipe-name", torture_rpc_smb2_pipe_name
);
4588 torture_suite_add_simple_test(suite
, "smb2-pipe-read-close", torture_rpc_smb2_pipe_read_close
);
4589 torture_suite_add_simple_test(suite
, "smb2-pipe-read-tdis", torture_rpc_smb2_pipe_read_tdis
);
4590 torture_suite_add_simple_test(suite
, "smb2-pipe-read-logoff", torture_rpc_smb2_pipe_read_logoff
);
4592 suite
->description
= talloc_strdup(suite
, "samba3 DCERPC interface tests");