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 "librpc/gen_ndr/ndr_svcctl_c.h"
35 #include "lib/cmdline/cmdline.h"
36 #include "torture/rpc/torture_rpc.h"
37 #include "libcli/libcli.h"
38 #include "libcli/smb_composite/smb_composite.h"
39 #include "libcli/auth/libcli_auth.h"
40 #include "libcli/security/security.h"
41 #include "param/param.h"
42 #include "lib/registry/registry.h"
43 #include "libcli/resolve/resolve.h"
44 #include "torture/ndr/ndr.h"
45 #include "libcli/smb2/smb2.h"
46 #include "libcli/smb2/smb2_calls.h"
47 #include "librpc/rpc/dcerpc.h"
48 #include "librpc/rpc/dcerpc_proto.h"
49 #include "libcli/smb/smbXcli_base.h"
50 #include "source3/rpc_client/init_samr.h"
53 * open pipe and bind, given an IPC$ context
56 static NTSTATUS
pipe_bind_smb(struct torture_context
*tctx
,
58 struct smbcli_tree
*tree
,
59 const char *pipe_name
,
60 const struct ndr_interface_table
*iface
,
61 struct dcerpc_pipe
**p
)
63 struct dcerpc_pipe
*result
;
66 if (!(result
= dcerpc_pipe_init(mem_ctx
, tctx
->ev
))) {
67 return NT_STATUS_NO_MEMORY
;
70 status
= dcerpc_pipe_open_smb(result
, tree
, pipe_name
);
71 if (!NT_STATUS_IS_OK(status
)) {
72 torture_comment(tctx
, "dcerpc_pipe_open_smb failed: %s\n",
78 status
= dcerpc_bind_auth_none(result
, iface
);
79 if (!NT_STATUS_IS_OK(status
)) {
80 torture_comment(tctx
, "dcerpc_bind_auth_none failed: %s\n", nt_errstr(status
));
89 static NTSTATUS
pipe_bind_smb2(struct torture_context
*tctx
,
91 struct smb2_tree
*tree
,
92 const char *pipe_name
,
93 const struct ndr_interface_table
*iface
,
94 struct dcerpc_pipe
**p
)
96 struct dcerpc_pipe
*result
;
99 if (!(result
= dcerpc_pipe_init(mem_ctx
, tctx
->ev
))) {
100 return NT_STATUS_NO_MEMORY
;
103 status
= dcerpc_pipe_open_smb2(result
, tree
, pipe_name
);
104 if (!NT_STATUS_IS_OK(status
)) {
105 torture_comment(tctx
, "dcerpc_pipe_open_smb2 failed: %s\n",
111 status
= dcerpc_bind_auth_none(result
, iface
);
112 if (!NT_STATUS_IS_OK(status
)) {
113 torture_comment(tctx
, "dcerpc_bind_auth_none failed: %s\n", nt_errstr(status
));
122 static NTSTATUS
pipe_bind_smb_auth(struct torture_context
*tctx
,
124 struct smbcli_tree
*tree
,
125 struct cli_credentials
*creds
,
128 const char *pipe_name
,
129 const struct ndr_interface_table
*iface
,
130 struct dcerpc_pipe
**p
)
132 struct dcerpc_pipe
*result
;
135 if (!(result
= dcerpc_pipe_init(mem_ctx
, tctx
->ev
))) {
136 return NT_STATUS_NO_MEMORY
;
139 status
= dcerpc_pipe_open_smb(result
, tree
, pipe_name
);
140 if (!NT_STATUS_IS_OK(status
)) {
141 torture_comment(tctx
, "dcerpc_pipe_open_smb failed: %s\n",
147 status
= dcerpc_bind_auth(result
, iface
, creds
,
148 lpcfg_gensec_settings(tctx
->lp_ctx
, tctx
->lp_ctx
),
149 auth_type
, auth_level
, NULL
);
150 if (!NT_STATUS_IS_OK(status
)) {
151 torture_comment(tctx
, "dcerpc_bind_auth failed: %s\n", nt_errstr(status
));
161 * This tests a RPC call using an invalid vuid
164 bool torture_bind_authcontext(struct torture_context
*torture
)
169 struct lsa_ObjectAttribute objectattr
;
170 struct lsa_OpenPolicy2 openpolicy
;
171 struct policy_handle handle
;
172 struct lsa_Close close_handle
;
173 struct smbcli_session
*tmp
;
175 struct smbcli_session
*session2
;
176 struct smbcli_state
*cli
;
177 struct dcerpc_pipe
*lsa_pipe
;
178 struct dcerpc_binding_handle
*lsa_handle
;
179 struct cli_credentials
*anon_creds
;
180 struct smb_composite_sesssetup setup
;
181 struct smbcli_options options
;
182 struct smbcli_session_options session_options
;
184 mem_ctx
= talloc_init("torture_bind_authcontext");
186 if (mem_ctx
== NULL
) {
187 torture_comment(torture
, "talloc_init failed\n");
191 lpcfg_smbcli_options(torture
->lp_ctx
, &options
);
192 lpcfg_smbcli_session_options(torture
->lp_ctx
, &session_options
);
194 status
= smbcli_full_connection(mem_ctx
, &cli
,
195 torture_setting_string(torture
, "host", NULL
),
196 lpcfg_smb_ports(torture
->lp_ctx
),
198 lpcfg_socket_options(torture
->lp_ctx
),
199 samba_cmdline_get_creds(),
200 lpcfg_resolve_context(torture
->lp_ctx
),
201 torture
->ev
, &options
, &session_options
,
202 lpcfg_gensec_settings(torture
, torture
->lp_ctx
));
203 if (!NT_STATUS_IS_OK(status
)) {
204 torture_comment(torture
, "smbcli_full_connection failed: %s\n",
209 status
= pipe_bind_smb(torture
, mem_ctx
, cli
->tree
, "\\lsarpc",
210 &ndr_table_lsarpc
, &lsa_pipe
);
211 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
212 "pipe_bind_smb failed");
213 lsa_handle
= lsa_pipe
->binding_handle
;
215 openpolicy
.in
.system_name
=talloc_asprintf(
216 mem_ctx
, "\\\\%s", dcerpc_server_name(lsa_pipe
));
217 ZERO_STRUCT(objectattr
);
218 openpolicy
.in
.attr
= &objectattr
;
219 openpolicy
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
220 openpolicy
.out
.handle
= &handle
;
222 status
= dcerpc_lsa_OpenPolicy2_r(lsa_handle
, mem_ctx
, &openpolicy
);
224 if (!NT_STATUS_IS_OK(status
)) {
225 torture_comment(torture
, "dcerpc_lsa_OpenPolicy2 failed: %s\n",
229 if (!NT_STATUS_IS_OK(openpolicy
.out
.result
)) {
230 torture_comment(torture
, "dcerpc_lsa_OpenPolicy2 failed: %s\n",
231 nt_errstr(openpolicy
.out
.result
));
235 close_handle
.in
.handle
= &handle
;
236 close_handle
.out
.handle
= &handle
;
238 status
= dcerpc_lsa_Close_r(lsa_handle
, mem_ctx
, &close_handle
);
239 if (!NT_STATUS_IS_OK(status
)) {
240 torture_comment(torture
, "dcerpc_lsa_Close failed: %s\n",
244 if (!NT_STATUS_IS_OK(close_handle
.out
.result
)) {
245 torture_comment(torture
, "dcerpc_lsa_Close failed: %s\n",
246 nt_errstr(close_handle
.out
.result
));
250 session2
= smbcli_session_init(cli
->transport
, mem_ctx
, false, session_options
);
251 if (session2
== NULL
) {
252 torture_comment(torture
, "smbcli_session_init failed\n");
256 if (!(anon_creds
= cli_credentials_init_anon(mem_ctx
))) {
257 torture_comment(torture
, "create_anon_creds failed\n");
261 setup
.in
.sesskey
= cli
->transport
->negotiate
.sesskey
;
262 setup
.in
.capabilities
= cli
->transport
->negotiate
.capabilities
;
263 setup
.in
.workgroup
= "";
264 setup
.in
.credentials
= anon_creds
;
265 setup
.in
.gensec_settings
= lpcfg_gensec_settings(torture
, torture
->lp_ctx
);
267 status
= smb_composite_sesssetup(session2
, &setup
);
268 if (!NT_STATUS_IS_OK(status
)) {
269 torture_comment(torture
, "anon session setup failed: %s\n",
273 session2
->vuid
= setup
.out
.vuid
;
275 tmp
= cli
->tree
->session
;
276 tmp_vuid
= smb1cli_session_current_id(tmp
->smbXcli
);
277 smb1cli_session_set_id(tmp
->smbXcli
, session2
->vuid
);
278 cli
->tree
->session
= session2
;
280 status
= dcerpc_lsa_OpenPolicy2_r(lsa_handle
, mem_ctx
, &openpolicy
);
282 torture_assert(torture
, smbXcli_conn_is_connected(cli
->transport
->conn
),
283 "smb still connected");
284 torture_assert(torture
, !dcerpc_binding_handle_is_connected(lsa_handle
),
285 "dcerpc disconnected");
287 if (NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
288 torture_comment(torture
, "dcerpc_lsa_OpenPolicy2 with wrong vuid gave %s, "
289 "expected NT_STATUS_CONNECTION_DISCONNECTED\n",
291 status
= NT_STATUS_CONNECTION_DISCONNECTED
;
293 if (NT_STATUS_EQUAL(status
, NT_STATUS_IO_DEVICE_ERROR
)) {
294 torture_comment(torture
, "dcerpc_lsa_OpenPolicy2 with wrong vuid gave %s, "
295 "expected NT_STATUS_CONNECTION_DISCONNECTED\n",
297 status
= NT_STATUS_CONNECTION_DISCONNECTED
;
300 torture_assert_ntstatus_equal(torture
, status
, NT_STATUS_CONNECTION_DISCONNECTED
,
301 "lsa connection disconnected");
303 smb1cli_session_set_id(tmp
->smbXcli
, tmp_vuid
);
304 cli
->tree
->session
= tmp
;
305 talloc_free(lsa_pipe
);
310 talloc_free(mem_ctx
);
315 * Bind to lsa using a specific auth method
318 static bool bindtest(struct torture_context
*tctx
,
319 struct smbcli_state
*cli
,
320 struct cli_credentials
*credentials
,
321 uint8_t auth_type
, uint8_t auth_level
)
327 struct dcerpc_pipe
*lsa_pipe
;
328 struct dcerpc_binding_handle
*lsa_handle
;
329 struct lsa_ObjectAttribute objectattr
;
330 struct lsa_OpenPolicy2 openpolicy
;
331 struct lsa_QueryInfoPolicy query
;
332 union lsa_PolicyInformation
*info
= NULL
;
333 struct policy_handle handle
;
334 struct lsa_Close close_handle
;
336 if ((mem_ctx
= talloc_init("bindtest")) == NULL
) {
337 torture_comment(tctx
, "talloc_init failed\n");
341 status
= pipe_bind_smb_auth(tctx
, mem_ctx
, cli
->tree
,
342 credentials
, auth_type
, auth_level
,
343 "\\lsarpc", &ndr_table_lsarpc
, &lsa_pipe
);
344 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
345 "pipe_bind_smb_auth failed");
346 lsa_handle
= lsa_pipe
->binding_handle
;
348 openpolicy
.in
.system_name
=talloc_asprintf(
349 mem_ctx
, "\\\\%s", dcerpc_server_name(lsa_pipe
));
350 ZERO_STRUCT(objectattr
);
351 openpolicy
.in
.attr
= &objectattr
;
352 openpolicy
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
353 openpolicy
.out
.handle
= &handle
;
355 status
= dcerpc_lsa_OpenPolicy2_r(lsa_handle
, mem_ctx
, &openpolicy
);
357 if (!NT_STATUS_IS_OK(status
)) {
358 torture_comment(tctx
, "dcerpc_lsa_OpenPolicy2 failed: %s\n",
362 if (!NT_STATUS_IS_OK(openpolicy
.out
.result
)) {
363 torture_comment(tctx
, "dcerpc_lsa_OpenPolicy2 failed: %s\n",
364 nt_errstr(openpolicy
.out
.result
));
368 query
.in
.handle
= &handle
;
369 query
.in
.level
= LSA_POLICY_INFO_DOMAIN
;
370 query
.out
.info
= &info
;
372 status
= dcerpc_lsa_QueryInfoPolicy_r(lsa_handle
, mem_ctx
, &query
);
373 if (!NT_STATUS_IS_OK(status
)) {
374 torture_comment(tctx
, "dcerpc_lsa_QueryInfoPolicy failed: %s\n",
378 if (!NT_STATUS_IS_OK(query
.out
.result
)) {
379 torture_comment(tctx
, "dcerpc_lsa_QueryInfoPolicy failed: %s\n",
380 nt_errstr(query
.out
.result
));
384 close_handle
.in
.handle
= &handle
;
385 close_handle
.out
.handle
= &handle
;
387 status
= dcerpc_lsa_Close_r(lsa_handle
, mem_ctx
, &close_handle
);
388 if (!NT_STATUS_IS_OK(status
)) {
389 torture_comment(tctx
, "dcerpc_lsa_Close failed: %s\n",
393 if (!NT_STATUS_IS_OK(close_handle
.out
.result
)) {
394 torture_comment(tctx
, "dcerpc_lsa_Close failed: %s\n",
395 nt_errstr(close_handle
.out
.result
));
402 talloc_free(mem_ctx
);
407 * test authenticated RPC binds with the variants Samba3 does support
410 static bool torture_bind_samba3(struct torture_context
*torture
)
415 struct smbcli_state
*cli
;
416 struct smbcli_options options
;
417 struct smbcli_session_options session_options
;
419 mem_ctx
= talloc_init("torture_bind_authcontext");
421 if (mem_ctx
== NULL
) {
422 torture_comment(torture
, "talloc_init failed\n");
426 lpcfg_smbcli_options(torture
->lp_ctx
, &options
);
427 lpcfg_smbcli_session_options(torture
->lp_ctx
, &session_options
);
429 status
= smbcli_full_connection(mem_ctx
, &cli
,
430 torture_setting_string(torture
, "host", NULL
),
431 lpcfg_smb_ports(torture
->lp_ctx
),
433 lpcfg_socket_options(torture
->lp_ctx
),
434 samba_cmdline_get_creds(),
435 lpcfg_resolve_context(torture
->lp_ctx
),
436 torture
->ev
, &options
, &session_options
,
437 lpcfg_gensec_settings(torture
, torture
->lp_ctx
));
438 if (!NT_STATUS_IS_OK(status
)) {
439 torture_comment(torture
, "smbcli_full_connection failed: %s\n",
446 ret
&= bindtest(torture
, cli
, samba_cmdline_get_creds(),
447 DCERPC_AUTH_TYPE_NTLMSSP
,
448 DCERPC_AUTH_LEVEL_INTEGRITY
);
449 ret
&= bindtest(torture
, cli
, samba_cmdline_get_creds(),
450 DCERPC_AUTH_TYPE_NTLMSSP
,
451 DCERPC_AUTH_LEVEL_PRIVACY
);
452 ret
&= bindtest(torture
, cli
, samba_cmdline_get_creds(),
453 DCERPC_AUTH_TYPE_SPNEGO
,
454 DCERPC_AUTH_LEVEL_INTEGRITY
);
455 ret
&= bindtest(torture
, cli
, samba_cmdline_get_creds(),
456 DCERPC_AUTH_TYPE_SPNEGO
,
457 DCERPC_AUTH_LEVEL_PRIVACY
);
460 talloc_free(mem_ctx
);
465 * Lookup or create a user and return all necessary info
468 static bool get_usr_handle(struct torture_context
*tctx
,
469 struct smbcli_state
*cli
,
471 struct cli_credentials
*admin_creds
,
474 const char *username
,
476 struct dcerpc_pipe
**result_pipe
,
477 struct policy_handle
**result_handle
,
478 struct dom_sid
**sid_p
)
480 struct dcerpc_pipe
*samr_pipe
;
481 struct dcerpc_binding_handle
*samr_handle
;
483 struct policy_handle conn_handle
;
484 struct policy_handle domain_handle
;
485 struct policy_handle
*user_handle
;
486 struct samr_Connect2 conn
;
487 struct samr_EnumDomains enumdom
;
488 uint32_t resume_handle
= 0;
489 uint32_t num_entries
= 0;
490 struct samr_SamArray
*sam
= NULL
;
491 struct samr_LookupDomain l
;
492 struct dom_sid2
*sid
= NULL
;
494 struct lsa_String domain_name
;
495 struct lsa_String user_name
;
496 struct samr_OpenDomain o
;
497 struct samr_CreateUser2 c
;
498 uint32_t user_rid
,access_granted
;
500 if (admin_creds
!= NULL
) {
501 status
= pipe_bind_smb_auth(tctx
, mem_ctx
, cli
->tree
,
502 admin_creds
, auth_type
, auth_level
,
503 "\\samr", &ndr_table_samr
, &samr_pipe
);
504 torture_assert_ntstatus_ok(tctx
, status
, "pipe_bind_smb_auth failed");
506 /* We must have an authenticated SMB connection */
507 status
= pipe_bind_smb(tctx
, mem_ctx
, cli
->tree
,
508 "\\samr", &ndr_table_samr
, &samr_pipe
);
509 torture_assert_ntstatus_ok(tctx
, status
, "pipe_bind_smb_auth failed");
512 samr_pipe
->conn
->flags
|= DCERPC_DEBUG_PRINT_IN
| DCERPC_DEBUG_PRINT_OUT
;
514 samr_handle
= samr_pipe
->binding_handle
;
516 conn
.in
.system_name
= talloc_asprintf(
517 mem_ctx
, "\\\\%s", dcerpc_server_name(samr_pipe
));
518 conn
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
519 conn
.out
.connect_handle
= &conn_handle
;
521 torture_assert_ntstatus_ok(tctx
,
522 dcerpc_samr_Connect2_r(samr_handle
, mem_ctx
, &conn
),
523 "samr_Connect2 failed");
524 torture_assert_ntstatus_ok(tctx
, conn
.out
.result
,
525 "samr_Connect2 failed");
527 enumdom
.in
.connect_handle
= &conn_handle
;
528 enumdom
.in
.resume_handle
= &resume_handle
;
529 enumdom
.in
.buf_size
= (uint32_t)-1;
530 enumdom
.out
.resume_handle
= &resume_handle
;
531 enumdom
.out
.num_entries
= &num_entries
;
532 enumdom
.out
.sam
= &sam
;
534 torture_assert_ntstatus_ok(tctx
,
535 dcerpc_samr_EnumDomains_r(samr_handle
, mem_ctx
, &enumdom
),
536 "samr_EnumDomains failed");
537 torture_assert_ntstatus_ok(tctx
, enumdom
.out
.result
,
538 "samr_EnumDomains failed");
540 torture_assert_int_equal(tctx
, *enumdom
.out
.num_entries
, 2,
541 "samr_EnumDomains returned unexpected num_entries");
543 dom_idx
= strequal(sam
->entries
[0].name
.string
,
546 l
.in
.connect_handle
= &conn_handle
;
547 domain_name
.string
= sam
->entries
[dom_idx
].name
.string
;
548 *domain
= talloc_strdup(mem_ctx
, domain_name
.string
);
549 l
.in
.domain_name
= &domain_name
;
552 torture_assert_ntstatus_ok(tctx
,
553 dcerpc_samr_LookupDomain_r(samr_handle
, mem_ctx
, &l
),
554 "samr_LookupDomain failed");
555 torture_assert_ntstatus_ok(tctx
, l
.out
.result
,
556 "samr_LookupDomain failed");
558 o
.in
.connect_handle
= &conn_handle
;
559 o
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
560 o
.in
.sid
= *l
.out
.sid
;
561 o
.out
.domain_handle
= &domain_handle
;
563 torture_assert_ntstatus_ok(tctx
,
564 dcerpc_samr_OpenDomain_r(samr_handle
, mem_ctx
, &o
),
565 "samr_OpenDomain failed");
566 torture_assert_ntstatus_ok(tctx
, o
.out
.result
,
567 "samr_OpenDomain failed");
569 c
.in
.domain_handle
= &domain_handle
;
570 user_name
.string
= username
;
571 c
.in
.account_name
= &user_name
;
572 c
.in
.acct_flags
= ACB_NORMAL
;
573 c
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
574 user_handle
= talloc(mem_ctx
, struct policy_handle
);
575 c
.out
.user_handle
= user_handle
;
576 c
.out
.access_granted
= &access_granted
;
577 c
.out
.rid
= &user_rid
;
579 torture_assert_ntstatus_ok(tctx
,
580 dcerpc_samr_CreateUser2_r(samr_handle
, mem_ctx
, &c
),
581 "samr_CreateUser2 failed");
583 if (NT_STATUS_EQUAL(c
.out
.result
, NT_STATUS_USER_EXISTS
)) {
584 struct samr_LookupNames ln
;
585 struct samr_OpenUser ou
;
586 struct samr_Ids rids
, types
;
588 ln
.in
.domain_handle
= &domain_handle
;
590 ln
.in
.names
= &user_name
;
592 ln
.out
.types
= &types
;
594 torture_assert_ntstatus_ok(tctx
,
595 dcerpc_samr_LookupNames_r(samr_handle
, mem_ctx
, &ln
),
596 "samr_LookupNames failed");
597 torture_assert_ntstatus_ok(tctx
, ln
.out
.result
,
598 "samr_LookupNames failed");
600 ou
.in
.domain_handle
= &domain_handle
;
601 ou
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
602 user_rid
= ou
.in
.rid
= ln
.out
.rids
->ids
[0];
603 ou
.out
.user_handle
= user_handle
;
605 torture_assert_ntstatus_ok(tctx
,
606 dcerpc_samr_OpenUser_r(samr_handle
, mem_ctx
, &ou
),
607 "samr_OpenUser failed");
608 status
= ou
.out
.result
;
610 status
= c
.out
.result
;
613 torture_assert_ntstatus_ok(tctx
, status
,
614 "samr_CreateUser failed");
616 *result_pipe
= samr_pipe
;
617 *result_handle
= user_handle
;
619 *sid_p
= dom_sid_add_rid(mem_ctx
, *l
.out
.sid
, user_rid
);
629 static bool create_user(struct torture_context
*tctx
,
630 TALLOC_CTX
*mem_ctx
, struct smbcli_state
*cli
,
631 struct cli_credentials
*admin_creds
,
632 const char *username
, const char *password
,
634 struct dom_sid
**user_sid
)
638 struct dcerpc_pipe
*samr_pipe
;
639 struct dcerpc_binding_handle
*samr_handle
;
640 struct policy_handle
*wks_handle
;
643 if (!(tmp_ctx
= talloc_new(mem_ctx
))) {
644 torture_comment(tctx
, "talloc_init failed\n");
648 ret
= get_usr_handle(tctx
, cli
, tmp_ctx
, admin_creds
,
649 DCERPC_AUTH_TYPE_NTLMSSP
,
650 DCERPC_AUTH_LEVEL_INTEGRITY
,
651 username
, domain_name
, &samr_pipe
, &wks_handle
,
654 torture_comment(tctx
, "get_usr_handle failed\n");
657 samr_handle
= samr_pipe
->binding_handle
;
660 struct samr_SetUserInfo2 sui2
;
661 struct samr_SetUserInfo sui
;
662 struct samr_QueryUserInfo qui
;
663 union samr_UserInfo u_info
;
664 union samr_UserInfo
*info
;
665 DATA_BLOB session_key
;
668 encode_pw_buffer(u_info
.info23
.password
.data
, password
,
671 status
= dcerpc_binding_handle_transport_session_key(samr_handle
,
674 if (!NT_STATUS_IS_OK(status
)) {
675 torture_comment(tctx
, "transport_session_key failed\n");
679 status
= init_samr_CryptPassword(password
,
681 &u_info
.info23
.password
);
682 if (!NT_STATUS_IS_OK(status
)) {
683 torture_comment(tctx
, "init_samr_CryptPassword failed\n");
687 u_info
.info23
.info
.password_expired
= 0;
688 u_info
.info23
.info
.fields_present
= SAMR_FIELD_NT_PASSWORD_PRESENT
|
689 SAMR_FIELD_LM_PASSWORD_PRESENT
|
690 SAMR_FIELD_EXPIRED_FLAG
;
691 sui2
.in
.user_handle
= wks_handle
;
692 sui2
.in
.info
= &u_info
;
695 status
= dcerpc_samr_SetUserInfo2_r(samr_handle
, tmp_ctx
, &sui2
);
696 if (!NT_STATUS_IS_OK(status
)) {
697 torture_comment(tctx
, "samr_SetUserInfo(23) failed: %s\n",
701 if (!NT_STATUS_IS_OK(sui2
.out
.result
)) {
702 torture_comment(tctx
, "samr_SetUserInfo(23) failed: %s\n",
703 nt_errstr(sui2
.out
.result
));
707 u_info
.info16
.acct_flags
= ACB_NORMAL
;
708 sui
.in
.user_handle
= wks_handle
;
709 sui
.in
.info
= &u_info
;
712 status
= dcerpc_samr_SetUserInfo_r(samr_handle
, tmp_ctx
, &sui
);
713 if (!NT_STATUS_IS_OK(status
) || !NT_STATUS_IS_OK(sui
.out
.result
)) {
714 torture_comment(tctx
, "samr_SetUserInfo(16) failed\n");
718 qui
.in
.user_handle
= wks_handle
;
720 qui
.out
.info
= &info
;
722 status
= dcerpc_samr_QueryUserInfo_r(samr_handle
, tmp_ctx
, &qui
);
723 if (!NT_STATUS_IS_OK(status
) || !NT_STATUS_IS_OK(qui
.out
.result
)) {
724 torture_comment(tctx
, "samr_QueryUserInfo(21) failed\n");
728 info
->info21
.allow_password_change
= 0;
729 info
->info21
.force_password_change
= 0;
730 info
->info21
.account_name
.string
= NULL
;
731 info
->info21
.rid
= 0;
732 info
->info21
.acct_expiry
= 0;
733 info
->info21
.fields_present
= 0x81827fa; /* copy usrmgr.exe */
735 u_info
.info21
= info
->info21
;
736 sui
.in
.user_handle
= wks_handle
;
737 sui
.in
.info
= &u_info
;
740 status
= dcerpc_samr_SetUserInfo_r(samr_handle
, tmp_ctx
, &sui
);
741 if (!NT_STATUS_IS_OK(status
) || !NT_STATUS_IS_OK(sui
.out
.result
)) {
742 torture_comment(tctx
, "samr_SetUserInfo(21) failed\n");
747 *domain_name
= talloc_steal(mem_ctx
, *domain_name
);
748 *user_sid
= talloc_steal(mem_ctx
, *user_sid
);
751 talloc_free(tmp_ctx
);
759 static bool delete_user(struct torture_context
*tctx
,
760 struct smbcli_state
*cli
,
761 struct cli_credentials
*admin_creds
,
762 const char *username
)
767 struct dcerpc_pipe
*samr_pipe
;
768 struct dcerpc_binding_handle
*samr_handle
;
769 struct policy_handle
*user_handle
;
772 if ((mem_ctx
= talloc_init("leave")) == NULL
) {
773 torture_comment(tctx
, "talloc_init failed\n");
777 ret
= get_usr_handle(tctx
, cli
, mem_ctx
, admin_creds
,
778 DCERPC_AUTH_TYPE_NTLMSSP
,
779 DCERPC_AUTH_LEVEL_INTEGRITY
,
780 username
, &dom_name
, &samr_pipe
,
783 torture_comment(tctx
, "get_wks_handle failed\n");
786 samr_handle
= samr_pipe
->binding_handle
;
789 struct samr_DeleteUser d
;
791 d
.in
.user_handle
= user_handle
;
792 d
.out
.user_handle
= user_handle
;
794 status
= dcerpc_samr_DeleteUser_r(samr_handle
, mem_ctx
, &d
);
795 if (!NT_STATUS_IS_OK(status
)) {
796 torture_comment(tctx
, "samr_DeleteUser failed %s\n", nt_errstr(status
));
799 if (!NT_STATUS_IS_OK(d
.out
.result
)) {
800 torture_comment(tctx
, "samr_DeleteUser failed %s\n", nt_errstr(d
.out
.result
));
809 talloc_free(mem_ctx
);
814 * Do a Samba3-style join
817 static bool join3(struct torture_context
*tctx
,
818 struct smbcli_state
*cli
,
820 struct cli_credentials
*admin_creds
,
821 struct cli_credentials
*wks_creds
)
826 struct dcerpc_pipe
*samr_pipe
;
827 struct dcerpc_binding_handle
*samr_handle
;
828 struct policy_handle
*wks_handle
;
830 NTTIME last_password_change
;
832 if ((mem_ctx
= talloc_init("join3")) == NULL
) {
833 torture_comment(tctx
, "talloc_init failed\n");
837 ret
= get_usr_handle(
838 tctx
, cli
, mem_ctx
, admin_creds
,
839 DCERPC_AUTH_TYPE_NTLMSSP
,
840 DCERPC_AUTH_LEVEL_PRIVACY
,
841 talloc_asprintf(mem_ctx
, "%s$",
842 cli_credentials_get_workstation(wks_creds
)),
843 &dom_name
, &samr_pipe
, &wks_handle
, NULL
);
845 torture_comment(tctx
, "get_wks_handle failed\n");
848 samr_handle
= samr_pipe
->binding_handle
;
851 struct samr_QueryUserInfo q
;
852 union samr_UserInfo
*info
;
854 q
.in
.user_handle
= wks_handle
;
858 status
= dcerpc_samr_QueryUserInfo_r(samr_handle
, mem_ctx
, &q
);
859 if (!NT_STATUS_IS_OK(status
)) {
860 torture_warning(tctx
, "QueryUserInfo failed: %s\n",
864 if (!NT_STATUS_IS_OK(q
.out
.result
)) {
865 torture_warning(tctx
, "QueryUserInfo failed: %s\n",
866 nt_errstr(q
.out
.result
));
871 last_password_change
= info
->info21
.last_password_change
;
874 cli_credentials_set_domain(wks_creds
, dom_name
, CRED_SPECIFIED
);
877 struct samr_SetUserInfo2 sui2
;
878 union samr_UserInfo u_info
;
879 struct samr_UserInfo21
*i21
= &u_info
.info25
.info
;
880 DATA_BLOB session_key
;
884 i21
->full_name
.string
= talloc_asprintf(
886 cli_credentials_get_workstation(wks_creds
));
887 i21
->acct_flags
= ACB_WSTRUST
;
888 i21
->fields_present
= SAMR_FIELD_FULL_NAME
|
889 SAMR_FIELD_ACCT_FLAGS
| SAMR_FIELD_NT_PASSWORD_PRESENT
;
890 /* this would break the test result expectations
891 i21->fields_present |= SAMR_FIELD_EXPIRED_FLAG;
892 i21->password_expired = 1;
895 status
= dcerpc_binding_handle_transport_session_key(samr_handle
,
898 if (!NT_STATUS_IS_OK(status
)) {
899 torture_comment(tctx
, "transport_session_key failed: %s\n",
904 status
= init_samr_CryptPasswordEx(cli_credentials_get_password(wks_creds
),
906 &u_info
.info25
.password
);
908 sui2
.in
.user_handle
= wks_handle
;
910 sui2
.in
.info
= &u_info
;
912 status
= dcerpc_samr_SetUserInfo2_r(samr_handle
, mem_ctx
, &sui2
);
913 if (!NT_STATUS_IS_OK(status
)) {
914 torture_comment(tctx
, "samr_SetUserInfo2(25) failed: %s\n",
918 if (!NT_STATUS_IS_OK(sui2
.out
.result
)) {
919 torture_comment(tctx
, "samr_SetUserInfo2(25) failed: %s\n",
920 nt_errstr(sui2
.out
.result
));
924 struct samr_SetUserInfo2 sui2
;
925 struct samr_SetUserInfo sui
;
926 union samr_UserInfo u_info
;
927 DATA_BLOB session_key
;
929 encode_pw_buffer(u_info
.info24
.password
.data
,
930 cli_credentials_get_password(wks_creds
),
932 /* just to make this test pass */
933 u_info
.info24
.password_expired
= 1;
935 status
= dcerpc_binding_handle_transport_session_key(samr_handle
,
938 if (!NT_STATUS_IS_OK(status
)) {
939 torture_comment(tctx
, "transport_session_key failed\n");
943 status
= init_samr_CryptPassword(cli_credentials_get_password(wks_creds
),
945 &u_info
.info24
.password
);
947 sui2
.in
.user_handle
= wks_handle
;
948 sui2
.in
.info
= &u_info
;
951 status
= dcerpc_samr_SetUserInfo2_r(samr_handle
, mem_ctx
, &sui2
);
952 if (!NT_STATUS_IS_OK(status
)) {
953 torture_comment(tctx
, "samr_SetUserInfo(24) failed: %s\n",
957 if (!NT_STATUS_IS_OK(sui2
.out
.result
)) {
958 torture_comment(tctx
, "samr_SetUserInfo(24) failed: %s\n",
959 nt_errstr(sui2
.out
.result
));
963 u_info
.info16
.acct_flags
= ACB_WSTRUST
;
964 sui
.in
.user_handle
= wks_handle
;
965 sui
.in
.info
= &u_info
;
968 status
= dcerpc_samr_SetUserInfo_r(samr_handle
, mem_ctx
, &sui
);
969 if (!NT_STATUS_IS_OK(status
) || !NT_STATUS_IS_OK(sui
.out
.result
)) {
970 torture_comment(tctx
, "samr_SetUserInfo(16) failed\n");
976 struct samr_QueryUserInfo q
;
977 union samr_UserInfo
*info
;
979 q
.in
.user_handle
= wks_handle
;
983 status
= dcerpc_samr_QueryUserInfo_r(samr_handle
, mem_ctx
, &q
);
984 if (!NT_STATUS_IS_OK(status
)) {
985 torture_warning(tctx
, "QueryUserInfo failed: %s\n",
989 if (!NT_STATUS_IS_OK(q
.out
.result
)) {
990 torture_warning(tctx
, "QueryUserInfo failed: %s\n",
991 nt_errstr(q
.out
.result
));
996 if (last_password_change
997 == info
->info21
.last_password_change
) {
998 torture_warning(tctx
, "last_password_change unchanged "
999 "during join, level25 must change "
1005 if (last_password_change
1006 != info
->info21
.last_password_change
) {
1007 torture_warning(tctx
, "last_password_change changed "
1008 "during join, level24 doesn't "
1018 talloc_free(mem_ctx
);
1023 * Do a ReqChallenge/Auth2 and get the wks creds
1026 static bool auth2(struct torture_context
*tctx
,
1027 struct smbcli_state
*cli
,
1028 struct cli_credentials
*wks_cred
)
1030 TALLOC_CTX
*mem_ctx
;
1031 struct dcerpc_pipe
*net_pipe
;
1032 struct dcerpc_binding_handle
*net_handle
;
1033 bool result
= false;
1035 struct netr_ServerReqChallenge r
;
1036 struct netr_Credential netr_cli_creds
;
1037 struct netr_Credential netr_srv_creds
;
1038 uint32_t negotiate_flags
;
1039 struct netr_ServerAuthenticate2 a
;
1040 struct netlogon_creds_CredentialState
*creds_state
;
1041 struct netr_Credential netr_cred
;
1042 struct samr_Password mach_pw
;
1044 mem_ctx
= talloc_new(NULL
);
1045 if (mem_ctx
== NULL
) {
1046 torture_comment(tctx
, "talloc_new failed\n");
1050 status
= pipe_bind_smb(tctx
, mem_ctx
, cli
->tree
, "\\netlogon",
1051 &ndr_table_netlogon
, &net_pipe
);
1052 torture_assert_ntstatus_ok_goto(tctx
, status
, result
, done
,
1053 "pipe_bind_smb failed");
1054 net_handle
= net_pipe
->binding_handle
;
1056 r
.in
.computer_name
= cli_credentials_get_workstation(wks_cred
);
1057 r
.in
.server_name
= talloc_asprintf(
1058 mem_ctx
, "\\\\%s", dcerpc_server_name(net_pipe
));
1059 if (r
.in
.server_name
== NULL
) {
1060 torture_comment(tctx
, "talloc_asprintf failed\n");
1063 generate_random_buffer(netr_cli_creds
.data
,
1064 sizeof(netr_cli_creds
.data
));
1065 r
.in
.credentials
= &netr_cli_creds
;
1066 r
.out
.return_credentials
= &netr_srv_creds
;
1068 status
= dcerpc_netr_ServerReqChallenge_r(net_handle
, mem_ctx
, &r
);
1069 if (!NT_STATUS_IS_OK(status
)) {
1070 torture_comment(tctx
, "netr_ServerReqChallenge failed: %s\n",
1074 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1075 torture_comment(tctx
, "netr_ServerReqChallenge failed: %s\n",
1076 nt_errstr(r
.out
.result
));
1080 negotiate_flags
= NETLOGON_NEG_AUTH2_ADS_FLAGS
| NETLOGON_NEG_SUPPORTS_AES
;
1081 E_md4hash(cli_credentials_get_password(wks_cred
), mach_pw
.hash
);
1083 a
.in
.server_name
= talloc_asprintf(
1084 mem_ctx
, "\\\\%s", dcerpc_server_name(net_pipe
));
1085 a
.in
.account_name
= talloc_asprintf(
1086 mem_ctx
, "%s$", cli_credentials_get_workstation(wks_cred
));
1087 a
.in
.computer_name
= cli_credentials_get_workstation(wks_cred
);
1088 a
.in
.secure_channel_type
= SEC_CHAN_WKSTA
;
1089 a
.in
.negotiate_flags
= &negotiate_flags
;
1090 a
.out
.negotiate_flags
= &negotiate_flags
;
1091 a
.in
.credentials
= &netr_cred
;
1092 a
.out
.return_credentials
= &netr_cred
;
1094 creds_state
= netlogon_creds_client_init(mem_ctx
,
1097 a
.in
.secure_channel_type
,
1099 r
.out
.return_credentials
, &mach_pw
,
1103 torture_assert(tctx
, (creds_state
!= NULL
), "memory allocation failed");
1105 status
= dcerpc_netr_ServerAuthenticate2_r(net_handle
, mem_ctx
, &a
);
1106 if (!NT_STATUS_IS_OK(status
)) {
1107 torture_comment(tctx
, "netr_ServerServerAuthenticate2 failed: %s\n",
1111 if (!NT_STATUS_IS_OK(a
.out
.result
)) {
1112 torture_comment(tctx
, "netr_ServerServerAuthenticate2 failed: %s\n",
1113 nt_errstr(a
.out
.result
));
1117 if (!netlogon_creds_client_check(creds_state
, a
.out
.return_credentials
)) {
1118 torture_comment(tctx
, "creds_client_check failed\n");
1122 cli_credentials_set_netlogon_creds(wks_cred
, creds_state
);
1127 talloc_free(mem_ctx
);
1132 * Do a couple of schannel protected Netlogon ops: Interactive and Network
1133 * login, and change the wks password
1136 static bool schan(struct torture_context
*tctx
,
1137 struct smbcli_state
*cli
,
1138 struct cli_credentials
*wks_creds
,
1139 struct cli_credentials
*user_creds
)
1141 TALLOC_CTX
*mem_ctx
;
1144 struct dcerpc_pipe
*net_pipe
;
1145 struct dcerpc_binding_handle
*net_handle
;
1148 mem_ctx
= talloc_new(NULL
);
1149 if (mem_ctx
== NULL
) {
1150 torture_comment(tctx
, "talloc_new failed\n");
1155 status
= pipe_bind_smb_auth(tctx
, mem_ctx
, cli
->tree
,
1157 DCERPC_AUTH_TYPE_SCHANNEL
,
1158 DCERPC_AUTH_LEVEL_PRIVACY
,
1159 "\\netlogon", &ndr_table_netlogon
, &net_pipe
);
1160 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
1161 "pipe_bind_smb_auth failed");
1163 status
= pipe_bind_smb(tctx
, mem_ctx
, cli
->tree
,
1164 "\\netlogon", &ndr_table_netlogon
, &net_pipe
);
1165 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
1166 "pipe_bind_smb failed");
1169 net_pipe
->conn
->flags
|= DCERPC_DEBUG_PRINT_IN
|
1170 DCERPC_DEBUG_PRINT_OUT
;
1172 net_handle
= net_pipe
->binding_handle
;
1175 for (i
=2; i
<4; i
++) {
1177 DATA_BLOB chal
, nt_resp
, lm_resp
, names_blob
;
1178 struct netlogon_creds_CredentialState
*creds_state
;
1179 struct netr_Authenticator netr_auth
, netr_auth2
;
1180 struct netr_NetworkInfo ninfo
;
1181 struct netr_PasswordInfo pinfo
;
1182 struct netr_LogonSamLogon r
;
1183 union netr_LogonLevel logon
;
1184 union netr_Validation validation
;
1185 uint8_t authoritative
;
1186 struct netr_Authenticator return_authenticator
;
1188 flags
= CLI_CRED_LANMAN_AUTH
| CLI_CRED_NTLM_AUTH
|
1189 CLI_CRED_NTLMv2_AUTH
;
1191 chal
= data_blob_talloc(mem_ctx
, NULL
, 8);
1192 if (chal
.data
== NULL
) {
1193 torture_comment(tctx
, "data_blob_talloc failed\n");
1197 generate_random_buffer(chal
.data
, chal
.length
);
1198 names_blob
= NTLMv2_generate_names_blob(
1200 cli_credentials_get_workstation(wks_creds
),
1201 cli_credentials_get_domain(wks_creds
));
1202 status
= cli_credentials_get_ntlm_response(
1203 user_creds
, mem_ctx
, &flags
, chal
, NULL
, names_blob
,
1204 &lm_resp
, &nt_resp
, NULL
, NULL
);
1205 if (!NT_STATUS_IS_OK(status
)) {
1206 torture_comment(tctx
, "cli_credentials_get_ntlm_response failed:"
1207 " %s\n", nt_errstr(status
));
1211 creds_state
= cli_credentials_get_netlogon_creds(wks_creds
);
1212 netlogon_creds_client_authenticator(creds_state
, &netr_auth
);
1214 ninfo
.identity_info
.account_name
.string
=
1215 cli_credentials_get_username(user_creds
);
1216 ninfo
.identity_info
.domain_name
.string
=
1217 cli_credentials_get_domain(user_creds
);
1218 ninfo
.identity_info
.parameter_control
= 0;
1219 ninfo
.identity_info
.logon_id
= 0;
1220 ninfo
.identity_info
.workstation
.string
=
1221 cli_credentials_get_workstation(user_creds
);
1222 memcpy(ninfo
.challenge
, chal
.data
, sizeof(ninfo
.challenge
));
1223 ninfo
.nt
.length
= nt_resp
.length
;
1224 ninfo
.nt
.data
= nt_resp
.data
;
1225 ninfo
.lm
.length
= lm_resp
.length
;
1226 ninfo
.lm
.data
= lm_resp
.data
;
1228 logon
.network
= &ninfo
;
1230 r
.in
.server_name
= talloc_asprintf(
1231 mem_ctx
, "\\\\%s", dcerpc_server_name(net_pipe
));
1232 ZERO_STRUCT(netr_auth2
);
1233 r
.in
.computer_name
=
1234 cli_credentials_get_workstation(wks_creds
);
1235 r
.in
.credential
= &netr_auth
;
1236 r
.in
.return_authenticator
= &netr_auth2
;
1237 r
.in
.logon_level
= NetlogonNetworkInformation
;
1238 r
.in
.validation_level
= i
;
1239 r
.in
.logon
= &logon
;
1240 r
.out
.validation
= &validation
;
1241 r
.out
.authoritative
= &authoritative
;
1242 r
.out
.return_authenticator
= &return_authenticator
;
1244 status
= dcerpc_netr_LogonSamLogon_r(net_handle
, mem_ctx
, &r
);
1245 if (!NT_STATUS_IS_OK(status
)) {
1246 torture_comment(tctx
, "netr_LogonSamLogon failed: %s\n",
1250 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1251 torture_comment(tctx
, "netr_LogonSamLogon failed: %s\n",
1252 nt_errstr(r
.out
.result
));
1256 if ((r
.out
.return_authenticator
== NULL
) ||
1257 (!netlogon_creds_client_check(creds_state
,
1258 &r
.out
.return_authenticator
->cred
))) {
1259 torture_comment(tctx
, "Credentials check failed!\n");
1263 netlogon_creds_client_authenticator(creds_state
, &netr_auth
);
1265 pinfo
.identity_info
= ninfo
.identity_info
;
1266 ZERO_STRUCT(pinfo
.lmpassword
.hash
);
1267 E_md4hash(cli_credentials_get_password(user_creds
),
1268 pinfo
.ntpassword
.hash
);
1270 logon
.password
= &pinfo
;
1273 * We don't use this here:
1275 * netlogon_creds_encrypt_samlogon_logon(creds_state,
1276 * NetlogonInteractiveInformation,
1279 * in order to detect bugs
1281 #undef netlogon_creds_aes_encrypt
1282 netlogon_creds_aes_encrypt(creds_state
, pinfo
.ntpassword
.hash
, 16);
1283 #define netlogon_creds_aes_encrypt __DO_NOT_USE_netlogon_creds_aes_encrypt
1285 r
.in
.logon_level
= NetlogonInteractiveInformation
;
1286 r
.in
.logon
= &logon
;
1287 r
.out
.return_authenticator
= &return_authenticator
;
1289 status
= dcerpc_netr_LogonSamLogon_r(net_handle
, mem_ctx
, &r
);
1290 if (!NT_STATUS_IS_OK(status
)) {
1291 torture_comment(tctx
, "netr_LogonSamLogon failed: %s\n",
1295 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1296 torture_comment(tctx
, "netr_LogonSamLogon failed: %s\n",
1297 nt_errstr(r
.out
.result
));
1301 if ((r
.out
.return_authenticator
== NULL
) ||
1302 (!netlogon_creds_client_check(creds_state
,
1303 &r
.out
.return_authenticator
->cred
))) {
1304 torture_comment(tctx
, "Credentials check failed!\n");
1310 struct netr_ServerPasswordSet s
;
1311 char *password
= generate_random_password(wks_creds
, 8, 255);
1312 struct netlogon_creds_CredentialState
*creds_state
;
1313 struct netr_Authenticator credential
, return_authenticator
;
1314 struct samr_Password new_password
;
1315 enum dcerpc_AuthType auth_type
;
1316 enum dcerpc_AuthLevel auth_level
;
1318 s
.in
.server_name
= talloc_asprintf(
1319 mem_ctx
, "\\\\%s", dcerpc_server_name(net_pipe
));
1320 s
.in
.computer_name
= cli_credentials_get_workstation(wks_creds
);
1321 s
.in
.account_name
= talloc_asprintf(
1322 mem_ctx
, "%s$", s
.in
.computer_name
);
1323 s
.in
.secure_channel_type
= SEC_CHAN_WKSTA
;
1324 s
.in
.credential
= &credential
;
1325 s
.in
.new_password
= &new_password
;
1326 s
.out
.return_authenticator
= &return_authenticator
;
1328 E_md4hash(password
, new_password
.hash
);
1330 creds_state
= cli_credentials_get_netlogon_creds(wks_creds
);
1331 dcerpc_binding_handle_auth_info(net_handle
,
1334 status
= netlogon_creds_encrypt_samr_Password(creds_state
,
1338 torture_assert_ntstatus_ok(tctx
, status
, "encrypt_samr_Password");
1339 netlogon_creds_client_authenticator(creds_state
, &credential
);
1341 status
= dcerpc_netr_ServerPasswordSet_r(net_handle
, mem_ctx
, &s
);
1342 if (!NT_STATUS_IS_OK(status
)) {
1343 torture_comment(tctx
, "ServerPasswordSet - %s\n", nt_errstr(status
));
1346 if (!NT_STATUS_IS_OK(s
.out
.result
)) {
1347 torture_comment(tctx
, "ServerPasswordSet - %s\n", nt_errstr(s
.out
.result
));
1351 if (!netlogon_creds_client_check(creds_state
,
1352 &s
.out
.return_authenticator
->cred
)) {
1353 torture_comment(tctx
, "Credential chaining failed\n");
1356 cli_credentials_set_password(wks_creds
, password
,
1362 talloc_free(mem_ctx
);
1367 * Delete the wks account again
1370 static bool leave(struct torture_context
*tctx
,
1371 struct smbcli_state
*cli
,
1372 struct cli_credentials
*admin_creds
,
1373 struct cli_credentials
*wks_creds
)
1375 char *wks_name
= talloc_asprintf(
1376 NULL
, "%s$", cli_credentials_get_workstation(wks_creds
));
1379 ret
= delete_user(tctx
, cli
, admin_creds
, wks_name
);
1380 talloc_free(wks_name
);
1385 * Test the Samba3 DC code a bit. Join, do some schan netlogon ops, leave
1388 static bool torture_netlogon_samba3(struct torture_context
*torture
)
1391 struct smbcli_state
*cli
;
1392 struct cli_credentials
*wks_creds
;
1393 const char *wks_name
;
1395 struct smbcli_options options
;
1396 struct smbcli_session_options session_options
;
1398 wks_name
= torture_setting_string(torture
, "wksname", NULL
);
1399 torture_assert(torture
, wks_name
!= NULL
, "wksname not set");
1401 lpcfg_smbcli_options(torture
->lp_ctx
, &options
);
1402 lpcfg_smbcli_session_options(torture
->lp_ctx
, &session_options
);
1404 status
= smbcli_full_connection(torture
, &cli
,
1405 torture_setting_string(torture
, "host", NULL
),
1406 lpcfg_smb_ports(torture
->lp_ctx
),
1408 lpcfg_socket_options(torture
->lp_ctx
),
1409 samba_cmdline_get_creds(),
1410 lpcfg_resolve_context(torture
->lp_ctx
),
1411 torture
->ev
, &options
, &session_options
,
1412 lpcfg_gensec_settings(torture
, torture
->lp_ctx
));
1413 torture_assert_ntstatus_ok(torture
, status
, "smbcli_full_connection failed\n");
1415 wks_creds
= cli_credentials_init(torture
);
1416 if (wks_creds
== NULL
) {
1417 torture_fail(torture
, "cli_credentials_init failed\n");
1420 cli_credentials_set_conf(wks_creds
, torture
->lp_ctx
);
1421 cli_credentials_set_secure_channel_type(wks_creds
, SEC_CHAN_WKSTA
);
1422 cli_credentials_set_username(wks_creds
, wks_name
, CRED_SPECIFIED
);
1423 cli_credentials_set_workstation(wks_creds
, wks_name
, CRED_SPECIFIED
);
1424 cli_credentials_set_password(wks_creds
,
1425 generate_random_password(wks_creds
, 8, 255),
1428 torture_assert(torture
,
1429 join3(torture
, cli
, false, NULL
, wks_creds
),
1432 cli_credentials_set_domain(
1433 samba_cmdline_get_creds(),
1434 cli_credentials_get_domain(wks_creds
),
1437 for (i
=0; i
<2; i
++) {
1439 /* Do this more than once, the routine "schan" changes
1440 * the workstation password using the netlogon
1441 * password change routine */
1445 torture_assert(torture
,
1446 auth2(torture
, cli
, wks_creds
),
1449 for (j
=0; j
<2; j
++) {
1450 torture_assert(torture
,
1451 schan(torture
, cli
, wks_creds
,
1452 samba_cmdline_get_creds()),
1457 torture_assert(torture
,
1458 leave(torture
, cli
, NULL
, wks_creds
),
1465 * Do a simple join, testjoin and leave using specified smb and samr
1469 static bool test_join3(struct torture_context
*tctx
,
1471 struct cli_credentials
*smb_creds
,
1472 struct cli_credentials
*samr_creds
,
1473 const char *wks_name
)
1476 struct smbcli_state
*cli
;
1477 struct cli_credentials
*wks_creds
;
1478 struct smbcli_options options
;
1479 struct smbcli_session_options session_options
;
1481 lpcfg_smbcli_options(tctx
->lp_ctx
, &options
);
1482 lpcfg_smbcli_session_options(tctx
->lp_ctx
, &session_options
);
1484 status
= smbcli_full_connection(tctx
, &cli
,
1485 torture_setting_string(tctx
, "host", NULL
),
1486 lpcfg_smb_ports(tctx
->lp_ctx
),
1487 "IPC$", NULL
, lpcfg_socket_options(tctx
->lp_ctx
),
1488 smb_creds
, lpcfg_resolve_context(tctx
->lp_ctx
),
1489 tctx
->ev
, &options
, &session_options
,
1490 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
));
1491 torture_assert_ntstatus_ok(tctx
, status
,
1492 "smbcli_full_connection failed");
1494 wks_creds
= cli_credentials_init(cli
);
1495 torture_assert(tctx
, wks_creds
, "cli_credentials_init failed");
1497 cli_credentials_set_conf(wks_creds
, tctx
->lp_ctx
);
1498 cli_credentials_set_secure_channel_type(wks_creds
, SEC_CHAN_WKSTA
);
1499 cli_credentials_set_username(wks_creds
, wks_name
, CRED_SPECIFIED
);
1500 cli_credentials_set_workstation(wks_creds
, wks_name
, CRED_SPECIFIED
);
1501 cli_credentials_set_password(wks_creds
,
1502 generate_random_password(wks_creds
, 8, 255),
1505 torture_assert(tctx
,
1506 join3(tctx
, cli
, use_level25
, samr_creds
, wks_creds
),
1509 cli_credentials_set_domain(
1510 samba_cmdline_get_creds(),
1511 cli_credentials_get_domain(wks_creds
),
1514 torture_assert(tctx
,
1515 auth2(tctx
, cli
, wks_creds
),
1518 torture_assert(tctx
,
1519 leave(tctx
, cli
, samr_creds
, wks_creds
),
1528 * Test the different session key variants. Do it by joining, this uses the
1529 * session key in the setpassword routine. Test the join by doing the auth2.
1532 static bool torture_samba3_sessionkey(struct torture_context
*torture
)
1534 struct cli_credentials
*anon_creds
;
1535 const char *wks_name
;
1538 wks_name
= torture_setting_string(torture
, "wksname", NULL
);
1539 torture_assert(torture
, wks_name
!= NULL
, "wksname not set");
1541 if (!(anon_creds
= cli_credentials_init_anon(torture
))) {
1542 torture_fail(torture
, "create_anon_creds failed\n");
1545 cli_credentials_set_workstation(anon_creds
, wks_name
, CRED_SPECIFIED
);
1548 if (!torture_setting_bool(torture
, "samba3", false)) {
1550 /* Samba3 in the build farm right now does this happily. Need
1553 if (test_join3(torture
, false, anon_creds
, NULL
, wks_name
)) {
1554 torture_fail(torture
, "join using anonymous bind on an anonymous smb "
1555 "connection succeeded -- HUH??\n");
1559 torture_assert(torture
,
1560 test_join3(torture
, false, samba_cmdline_get_creds(),
1562 "join using anonymous bind on an authenticated smb connection failed");
1565 * The following two are tests for setuserinfolevel 25
1568 torture_assert(torture
,
1569 test_join3(torture
, true, samba_cmdline_get_creds(),
1571 "join using anonymous bind on an authenticated smb connection failed");
1577 * Sane wrapper around lsa_LookupNames
1580 static struct dom_sid
*name2sid(struct torture_context
*tctx
,
1581 TALLOC_CTX
*mem_ctx
,
1582 struct dcerpc_pipe
*p
,
1586 struct lsa_ObjectAttribute attr
;
1587 struct lsa_QosInfo qos
;
1588 struct lsa_OpenPolicy2 r
;
1591 struct policy_handle handle
;
1592 struct lsa_LookupNames l
;
1593 struct lsa_TransSidArray sids
;
1594 struct lsa_RefDomainList
*domains
= NULL
;
1595 struct lsa_String lsa_name
;
1597 struct dom_sid
*result
;
1598 TALLOC_CTX
*tmp_ctx
;
1599 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
1601 if (!(tmp_ctx
= talloc_new(mem_ctx
))) {
1606 qos
.impersonation_level
= 2;
1607 qos
.context_mode
= 1;
1608 qos
.effective_only
= 0;
1611 attr
.root_dir
= NULL
;
1612 attr
.object_name
= NULL
;
1613 attr
.attributes
= 0;
1614 attr
.sec_desc
= NULL
;
1615 attr
.sec_qos
= &qos
;
1617 r
.in
.system_name
= "\\";
1619 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1620 r
.out
.handle
= &handle
;
1622 status
= dcerpc_lsa_OpenPolicy2_r(b
, tmp_ctx
, &r
);
1623 if (!NT_STATUS_IS_OK(status
)) {
1624 torture_comment(tctx
, "OpenPolicy2 failed - %s\n", nt_errstr(status
));
1625 talloc_free(tmp_ctx
);
1628 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1629 torture_comment(tctx
, "OpenPolicy2 failed - %s\n", nt_errstr(r
.out
.result
));
1630 talloc_free(tmp_ctx
);
1637 lsa_name
.string
= talloc_asprintf(tmp_ctx
, "%s\\%s", domain
, name
);
1639 l
.in
.handle
= &handle
;
1641 l
.in
.names
= &lsa_name
;
1644 l
.in
.count
= &count
;
1645 l
.out
.count
= &count
;
1647 l
.out
.domains
= &domains
;
1649 status
= dcerpc_lsa_LookupNames_r(b
, tmp_ctx
, &l
);
1650 if (!NT_STATUS_IS_OK(status
)) {
1651 torture_comment(tctx
, "LookupNames of %s failed - %s\n", lsa_name
.string
,
1653 talloc_free(tmp_ctx
);
1656 if (!NT_STATUS_IS_OK(l
.out
.result
)) {
1657 torture_comment(tctx
, "LookupNames of %s failed - %s\n", lsa_name
.string
,
1658 nt_errstr(l
.out
.result
));
1659 talloc_free(tmp_ctx
);
1663 result
= dom_sid_add_rid(mem_ctx
, domains
->domains
[0].sid
,
1664 l
.out
.sids
->sids
[0].rid
);
1666 c
.in
.handle
= &handle
;
1667 c
.out
.handle
= &handle
;
1669 status
= dcerpc_lsa_Close_r(b
, tmp_ctx
, &c
);
1670 if (!NT_STATUS_IS_OK(status
)) {
1671 torture_comment(tctx
, "dcerpc_lsa_Close failed - %s\n", nt_errstr(status
));
1672 talloc_free(tmp_ctx
);
1675 if (!NT_STATUS_IS_OK(c
.out
.result
)) {
1676 torture_comment(tctx
, "dcerpc_lsa_Close failed - %s\n", nt_errstr(c
.out
.result
));
1677 talloc_free(tmp_ctx
);
1681 talloc_free(tmp_ctx
);
1686 * Find out the user SID on this connection
1689 static struct dom_sid
*whoami(struct torture_context
*tctx
,
1690 TALLOC_CTX
*mem_ctx
,
1691 struct smbcli_tree
*tree
)
1693 struct dcerpc_pipe
*lsa
;
1694 struct dcerpc_binding_handle
*lsa_handle
;
1695 struct lsa_GetUserName r
;
1697 struct lsa_String
*authority_name_p
= NULL
;
1698 struct lsa_String
*account_name_p
= NULL
;
1699 struct dom_sid
*result
;
1701 status
= pipe_bind_smb(tctx
, mem_ctx
, tree
, "\\pipe\\lsarpc",
1702 &ndr_table_lsarpc
, &lsa
);
1703 if (!NT_STATUS_IS_OK(status
)) {
1704 torture_warning(tctx
, "Could not bind to LSA: %s\n",
1708 lsa_handle
= lsa
->binding_handle
;
1710 r
.in
.system_name
= "\\";
1711 r
.in
.account_name
= &account_name_p
;
1712 r
.in
.authority_name
= &authority_name_p
;
1713 r
.out
.account_name
= &account_name_p
;
1715 status
= dcerpc_lsa_GetUserName_r(lsa_handle
, mem_ctx
, &r
);
1717 authority_name_p
= *r
.out
.authority_name
;
1719 if (!NT_STATUS_IS_OK(status
)) {
1720 torture_warning(tctx
, "GetUserName failed - %s\n",
1725 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1726 torture_warning(tctx
, "GetUserName failed - %s\n",
1727 nt_errstr(r
.out
.result
));
1732 result
= name2sid(tctx
, mem_ctx
, lsa
, account_name_p
->string
,
1733 authority_name_p
->string
);
1739 static int destroy_tree(struct smbcli_tree
*tree
)
1741 smb_tree_disconnect(tree
);
1746 * Do a tcon, given a session
1749 static NTSTATUS
secondary_tcon(struct torture_context
*tctx
,
1750 TALLOC_CTX
*mem_ctx
,
1751 struct smbcli_session
*session
,
1752 const char *sharename
,
1753 struct smbcli_tree
**res
)
1755 struct smbcli_tree
*result
;
1756 TALLOC_CTX
*tmp_ctx
;
1757 union smb_tcon tcon
;
1760 if (!(tmp_ctx
= talloc_new(mem_ctx
))) {
1761 return NT_STATUS_NO_MEMORY
;
1764 if (!(result
= smbcli_tree_init(session
, mem_ctx
, false))) {
1765 talloc_free(tmp_ctx
);
1766 return NT_STATUS_NO_MEMORY
;
1769 tcon
.generic
.level
= RAW_TCON_TCONX
;
1770 tcon
.tconx
.in
.flags
= TCONX_FLAG_EXTENDED_RESPONSE
;
1771 tcon
.tconx
.in
.flags
|= TCONX_FLAG_EXTENDED_SIGNATURES
;
1772 tcon
.tconx
.in
.password
= data_blob(NULL
, 0);
1773 tcon
.tconx
.in
.path
= sharename
;
1774 tcon
.tconx
.in
.device
= "?????";
1776 status
= smb_raw_tcon(result
, tmp_ctx
, &tcon
);
1777 if (!NT_STATUS_IS_OK(status
)) {
1778 torture_warning(tctx
, "smb_raw_tcon failed: %s\n",
1780 talloc_free(tmp_ctx
);
1784 result
->tid
= tcon
.tconx
.out
.tid
;
1786 if (tcon
.tconx
.out
.options
& SMB_EXTENDED_SIGNATURES
) {
1787 smb1cli_session_protect_session_key(result
->session
->smbXcli
);
1790 result
= talloc_steal(mem_ctx
, result
);
1791 talloc_set_destructor(result
, destroy_tree
);
1792 talloc_free(tmp_ctx
);
1794 return NT_STATUS_OK
;
1798 * Test the getusername behaviour
1801 static bool torture_samba3_rpc_getusername(struct torture_context
*torture
)
1804 struct smbcli_state
*cli
;
1806 struct dom_sid
*user_sid
;
1807 struct dom_sid
*created_sid
;
1808 struct cli_credentials
*anon_creds
;
1809 struct cli_credentials
*user_creds
;
1811 struct smbcli_options options
;
1812 struct smbcli_session_options session_options
;
1814 lpcfg_smbcli_options(torture
->lp_ctx
, &options
);
1815 lpcfg_smbcli_session_options(torture
->lp_ctx
, &session_options
);
1817 if (!(anon_creds
= cli_credentials_init_anon(torture
))) {
1818 torture_fail(torture
, "create_anon_creds failed\n");
1821 status
= smbcli_full_connection(
1822 torture
, &cli
, torture_setting_string(torture
, "host", NULL
),
1823 lpcfg_smb_ports(torture
->lp_ctx
), "IPC$", NULL
,
1824 lpcfg_socket_options(torture
->lp_ctx
), anon_creds
,
1825 lpcfg_resolve_context(torture
->lp_ctx
),
1826 torture
->ev
, &options
, &session_options
,
1827 lpcfg_gensec_settings(torture
, torture
->lp_ctx
));
1828 torture_assert_ntstatus_ok(torture
, status
, "anon smbcli_full_connection failed\n");
1830 if (!(user_sid
= whoami(torture
, torture
, cli
->tree
))) {
1831 torture_fail(torture
, "whoami on anon connection failed\n");
1834 torture_assert_sid_equal(torture
, user_sid
, dom_sid_parse_talloc(torture
, "s-1-5-7"),
1835 "Anon lsa_GetUserName returned unexpected SID");
1839 status
= smbcli_full_connection(
1840 torture
, &cli
, torture_setting_string(torture
, "host", NULL
),
1841 lpcfg_smb_ports(torture
->lp_ctx
),
1842 "IPC$", NULL
, lpcfg_socket_options(torture
->lp_ctx
),
1843 samba_cmdline_get_creds(),
1844 lpcfg_resolve_context(torture
->lp_ctx
), torture
->ev
, &options
,
1845 &session_options
, lpcfg_gensec_settings(torture
, torture
->lp_ctx
));
1846 torture_assert_ntstatus_ok(torture
, status
, "smbcli_full_connection failed\n");
1848 if (!(user_sid
= whoami(torture
, torture
, cli
->tree
))) {
1849 torture_fail(torture
, "whoami on auth'ed connection failed\n");
1852 if (!(user_creds
= cli_credentials_init(torture
))) {
1853 torture_fail(torture
, "cli_credentials_init failed\n");
1856 cli_credentials_set_conf(user_creds
, torture
->lp_ctx
);
1857 cli_credentials_set_username(user_creds
, "torture_username",
1859 cli_credentials_set_password(user_creds
,
1860 generate_random_password(user_creds
, 8, 255),
1863 if (!create_user(torture
, torture
, cli
, NULL
,
1864 cli_credentials_get_username(user_creds
),
1865 cli_credentials_get_password(user_creds
),
1866 &domain_name
, &created_sid
)) {
1867 torture_fail(torture
, "create_user failed\n");
1870 cli_credentials_set_domain(user_creds
, domain_name
,
1874 struct smbcli_session
*session2
;
1875 struct smb_composite_sesssetup setup
;
1876 struct smbcli_tree
*tree
;
1878 session2
= smbcli_session_init(cli
->transport
, torture
, false, session_options
);
1879 if (session2
== NULL
) {
1880 torture_fail(torture
, "smbcli_session_init failed\n");
1883 setup
.in
.sesskey
= cli
->transport
->negotiate
.sesskey
;
1884 setup
.in
.capabilities
= cli
->transport
->negotiate
.capabilities
;
1885 setup
.in
.workgroup
= "";
1886 setup
.in
.credentials
= user_creds
;
1887 setup
.in
.gensec_settings
= lpcfg_gensec_settings(torture
, torture
->lp_ctx
);
1889 status
= smb_composite_sesssetup(session2
, &setup
);
1890 torture_assert_ntstatus_ok(torture
, status
, "session setup with new user failed");
1892 session2
->vuid
= setup
.out
.vuid
;
1894 if (!NT_STATUS_IS_OK(secondary_tcon(torture
, torture
, session2
,
1896 torture_fail(torture
, "secondary_tcon failed\n");
1899 if (!(user_sid
= whoami(torture
, torture
, tree
))) {
1900 torture_fail_goto(torture
, del
, "whoami on user connection failed\n");
1908 torture_comment(torture
, "Created %s, found %s\n",
1909 dom_sid_string(torture
, created_sid
),
1910 dom_sid_string(torture
, user_sid
));
1912 if (!dom_sid_equal(created_sid
, user_sid
)) {
1917 if (!delete_user(torture
, cli
,
1919 cli_credentials_get_username(user_creds
))) {
1920 torture_fail(torture
, "delete_user failed\n");
1926 static bool test_NetShareGetInfo(struct torture_context
*tctx
,
1927 struct dcerpc_pipe
*p
,
1928 const char *sharename
)
1931 struct srvsvc_NetShareGetInfo r
;
1932 union srvsvc_NetShareInfo info
;
1933 uint32_t levels
[] = { 0, 1, 2, 501, 502, 1004, 1005, 1006, 1007, 1501 };
1936 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
1938 r
.in
.server_unc
= talloc_asprintf(tctx
, "\\\\%s",
1939 dcerpc_server_name(p
));
1940 r
.in
.share_name
= sharename
;
1943 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
1944 r
.in
.level
= levels
[i
];
1946 torture_comment(tctx
, "Testing NetShareGetInfo level %u on share '%s'\n",
1947 r
.in
.level
, r
.in
.share_name
);
1949 status
= dcerpc_srvsvc_NetShareGetInfo_r(b
, tctx
, &r
);
1950 if (!NT_STATUS_IS_OK(status
)) {
1951 torture_warning(tctx
, "NetShareGetInfo level %u on share '%s' failed"
1952 " - %s\n", r
.in
.level
, r
.in
.share_name
,
1957 if (!W_ERROR_IS_OK(r
.out
.result
)) {
1958 torture_warning(tctx
, "NetShareGetInfo level %u on share '%s' failed "
1959 "- %s\n", r
.in
.level
, r
.in
.share_name
,
1960 win_errstr(r
.out
.result
));
1969 static bool test_NetShareEnum(struct torture_context
*tctx
,
1970 struct dcerpc_pipe
*p
,
1971 const char **one_sharename
)
1974 struct srvsvc_NetShareEnum r
;
1975 struct srvsvc_NetShareInfoCtr info_ctr
;
1976 struct srvsvc_NetShareCtr0 c0
;
1977 struct srvsvc_NetShareCtr1 c1
;
1978 struct srvsvc_NetShareCtr2 c2
;
1979 struct srvsvc_NetShareCtr501 c501
;
1980 struct srvsvc_NetShareCtr502 c502
;
1981 struct srvsvc_NetShareCtr1004 c1004
;
1982 struct srvsvc_NetShareCtr1005 c1005
;
1983 struct srvsvc_NetShareCtr1006 c1006
;
1984 struct srvsvc_NetShareCtr1007 c1007
;
1985 uint32_t totalentries
= 0;
1986 uint32_t levels
[] = { 0, 1, 2, 501, 502, 1004, 1005, 1006, 1007 };
1989 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
1991 ZERO_STRUCT(info_ctr
);
1993 r
.in
.server_unc
= talloc_asprintf(tctx
,"\\\\%s",dcerpc_server_name(p
));
1994 r
.in
.info_ctr
= &info_ctr
;
1995 r
.in
.max_buffer
= (uint32_t)-1;
1996 r
.in
.resume_handle
= NULL
;
1997 r
.out
.totalentries
= &totalentries
;
1998 r
.out
.info_ctr
= &info_ctr
;
2000 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
2001 info_ctr
.level
= levels
[i
];
2003 switch (info_ctr
.level
) {
2006 info_ctr
.ctr
.ctr0
= &c0
;
2010 info_ctr
.ctr
.ctr1
= &c1
;
2014 info_ctr
.ctr
.ctr2
= &c2
;
2018 info_ctr
.ctr
.ctr501
= &c501
;
2022 info_ctr
.ctr
.ctr502
= &c502
;
2026 info_ctr
.ctr
.ctr1004
= &c1004
;
2030 info_ctr
.ctr
.ctr1005
= &c1005
;
2034 info_ctr
.ctr
.ctr1006
= &c1006
;
2038 info_ctr
.ctr
.ctr1007
= &c1007
;
2042 torture_comment(tctx
, "Testing NetShareEnum level %u\n", info_ctr
.level
);
2044 status
= dcerpc_srvsvc_NetShareEnum_r(b
, tctx
, &r
);
2045 if (!NT_STATUS_IS_OK(status
)) {
2046 torture_warning(tctx
, "NetShareEnum level %u failed - %s\n",
2047 info_ctr
.level
, nt_errstr(status
));
2051 if (!W_ERROR_IS_OK(r
.out
.result
)) {
2052 torture_warning(tctx
, "NetShareEnum level %u failed - %s\n",
2053 info_ctr
.level
, win_errstr(r
.out
.result
));
2056 if (info_ctr
.level
== 0) {
2057 struct srvsvc_NetShareCtr0
*ctr
= r
.out
.info_ctr
->ctr
.ctr0
;
2058 if (ctr
->count
> 0) {
2059 *one_sharename
= ctr
->array
[0].name
;
2067 static bool torture_samba3_rpc_srvsvc(struct torture_context
*torture
)
2069 struct dcerpc_pipe
*p
;
2070 const char *sharename
= NULL
;
2073 torture_assert_ntstatus_ok(torture
,
2074 torture_rpc_connection(torture
, &p
, &ndr_table_srvsvc
),
2075 "failed to open srvsvc");
2077 ret
&= test_NetShareEnum(torture
, p
, &sharename
);
2078 if (sharename
== NULL
) {
2079 torture_comment(torture
, "did not get sharename\n");
2081 ret
&= test_NetShareGetInfo(torture
, p
, sharename
);
2088 * Do a ReqChallenge/Auth2 with a random wks name, make sure it returns
2089 * NT_STATUS_NO_SAM_ACCOUNT
2092 static bool torture_samba3_rpc_randomauth2(struct torture_context
*torture
)
2094 TALLOC_CTX
*mem_ctx
;
2095 struct dcerpc_pipe
*net_pipe
;
2096 struct dcerpc_binding_handle
*net_handle
;
2098 bool result
= false;
2100 struct netr_ServerReqChallenge r
;
2101 struct netr_Credential netr_cli_creds
;
2102 struct netr_Credential netr_srv_creds
;
2103 uint32_t negotiate_flags
;
2104 struct netr_ServerAuthenticate2 a
;
2105 struct netlogon_creds_CredentialState
*creds_state
;
2106 struct netr_Credential netr_cred
;
2107 struct samr_Password mach_pw
;
2108 struct smbcli_state
*cli
;
2110 if (!(mem_ctx
= talloc_new(torture
))) {
2111 torture_comment(torture
, "talloc_new failed\n");
2115 if (!(wksname
= generate_random_str_list(
2116 mem_ctx
, 14, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"))) {
2117 torture_comment(torture
, "generate_random_str_list failed\n");
2121 if (!(torture_open_connection_share(
2123 torture
, torture_setting_string(torture
, "host", NULL
),
2124 "IPC$", torture
->ev
))) {
2125 torture_comment(torture
, "IPC$ connection failed\n");
2129 status
= pipe_bind_smb(torture
, mem_ctx
, cli
->tree
, "\\netlogon",
2130 &ndr_table_netlogon
, &net_pipe
);
2131 torture_assert_ntstatus_ok_goto(torture
, status
, result
, done
,
2132 "pipe_bind_smb failed");
2133 net_handle
= net_pipe
->binding_handle
;
2135 r
.in
.computer_name
= wksname
;
2136 r
.in
.server_name
= talloc_asprintf(
2137 mem_ctx
, "\\\\%s", dcerpc_server_name(net_pipe
));
2138 if (r
.in
.server_name
== NULL
) {
2139 torture_comment(torture
, "talloc_asprintf failed\n");
2142 generate_random_buffer(netr_cli_creds
.data
,
2143 sizeof(netr_cli_creds
.data
));
2144 r
.in
.credentials
= &netr_cli_creds
;
2145 r
.out
.return_credentials
= &netr_srv_creds
;
2147 status
= dcerpc_netr_ServerReqChallenge_r(net_handle
, mem_ctx
, &r
);
2148 if (!NT_STATUS_IS_OK(status
)) {
2149 torture_comment(torture
, "netr_ServerReqChallenge failed: %s\n",
2153 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
2154 torture_comment(torture
, "netr_ServerReqChallenge failed: %s\n",
2155 nt_errstr(r
.out
.result
));
2159 negotiate_flags
= NETLOGON_NEG_AUTH2_FLAGS
;
2160 E_md4hash("foobar", mach_pw
.hash
);
2162 a
.in
.server_name
= talloc_asprintf(
2163 mem_ctx
, "\\\\%s", dcerpc_server_name(net_pipe
));
2164 a
.in
.account_name
= talloc_asprintf(
2165 mem_ctx
, "%s$", wksname
);
2166 a
.in
.computer_name
= wksname
;
2167 a
.in
.secure_channel_type
= SEC_CHAN_WKSTA
;
2168 a
.in
.negotiate_flags
= &negotiate_flags
;
2169 a
.out
.negotiate_flags
= &negotiate_flags
;
2170 a
.in
.credentials
= &netr_cred
;
2171 a
.out
.return_credentials
= &netr_cred
;
2173 creds_state
= netlogon_creds_client_init(mem_ctx
,
2176 a
.in
.secure_channel_type
,
2178 r
.out
.return_credentials
, &mach_pw
,
2182 torture_assert(torture
, (creds_state
!= NULL
), "memory allocation failed");
2184 status
= dcerpc_netr_ServerAuthenticate2_r(net_handle
, mem_ctx
, &a
);
2185 if (!NT_STATUS_IS_OK(status
)) {
2188 if (!NT_STATUS_EQUAL(a
.out
.result
, NT_STATUS_NO_TRUST_SAM_ACCOUNT
)) {
2189 torture_comment(torture
, "dcerpc_netr_ServerAuthenticate2 returned %s, "
2190 "expected NT_STATUS_NO_TRUST_SAM_ACCOUNT\n",
2191 nt_errstr(a
.out
.result
));
2197 talloc_free(mem_ctx
);
2201 static struct security_descriptor
*get_sharesec(struct torture_context
*tctx
,
2202 TALLOC_CTX
*mem_ctx
,
2203 struct smbcli_session
*sess
,
2204 const char *sharename
)
2206 struct smbcli_tree
*tree
;
2207 TALLOC_CTX
*tmp_ctx
;
2208 struct dcerpc_pipe
*p
;
2209 struct dcerpc_binding_handle
*b
;
2211 struct srvsvc_NetShareGetInfo r
;
2212 union srvsvc_NetShareInfo info
;
2213 struct security_descriptor
*result
;
2215 if (!(tmp_ctx
= talloc_new(mem_ctx
))) {
2216 torture_comment(tctx
, "talloc_new failed\n");
2220 if (!NT_STATUS_IS_OK(secondary_tcon(tctx
, tmp_ctx
, sess
, "IPC$", &tree
))) {
2221 torture_comment(tctx
, "secondary_tcon failed\n");
2222 talloc_free(tmp_ctx
);
2226 status
= pipe_bind_smb(tctx
, mem_ctx
, tree
, "\\pipe\\srvsvc",
2227 &ndr_table_srvsvc
, &p
);
2228 if (!NT_STATUS_IS_OK(status
)) {
2229 torture_warning(tctx
, "could not bind to srvsvc pipe: %s\n",
2231 talloc_free(tmp_ctx
);
2234 b
= p
->binding_handle
;
2237 p
->conn
->flags
|= DCERPC_DEBUG_PRINT_IN
| DCERPC_DEBUG_PRINT_OUT
;
2240 r
.in
.server_unc
= talloc_asprintf(tmp_ctx
, "\\\\%s",
2241 dcerpc_server_name(p
));
2242 r
.in
.share_name
= sharename
;
2246 status
= dcerpc_srvsvc_NetShareGetInfo_r(b
, tmp_ctx
, &r
);
2247 if (!NT_STATUS_IS_OK(status
)) {
2248 torture_comment(tctx
, "srvsvc_NetShareGetInfo failed: %s\n",
2250 talloc_free(tmp_ctx
);
2253 if (!W_ERROR_IS_OK(r
.out
.result
)) {
2254 torture_comment(tctx
, "srvsvc_NetShareGetInfo failed: %s\n",
2255 win_errstr(r
.out
.result
));
2256 talloc_free(tmp_ctx
);
2260 result
= talloc_steal(mem_ctx
, info
.info502
->sd_buf
.sd
);
2261 talloc_free(tmp_ctx
);
2265 static NTSTATUS
set_sharesec(struct torture_context
*tctx
,
2266 TALLOC_CTX
*mem_ctx
,
2267 struct smbcli_session
*sess
,
2268 const char *sharename
,
2269 struct security_descriptor
*sd
)
2271 struct smbcli_tree
*tree
;
2272 TALLOC_CTX
*tmp_ctx
;
2273 struct dcerpc_pipe
*p
;
2274 struct dcerpc_binding_handle
*b
;
2276 struct sec_desc_buf i
;
2277 struct srvsvc_NetShareSetInfo r
;
2278 union srvsvc_NetShareInfo info
;
2281 if (!(tmp_ctx
= talloc_new(mem_ctx
))) {
2282 torture_comment(tctx
, "talloc_new failed\n");
2283 return NT_STATUS_NO_MEMORY
;
2286 if (!NT_STATUS_IS_OK(secondary_tcon(tctx
, tmp_ctx
, sess
, "IPC$", &tree
))) {
2287 torture_comment(tctx
, "secondary_tcon failed\n");
2288 talloc_free(tmp_ctx
);
2289 return NT_STATUS_UNSUCCESSFUL
;
2292 status
= pipe_bind_smb(tctx
, mem_ctx
, tree
, "\\pipe\\srvsvc",
2293 &ndr_table_srvsvc
, &p
);
2294 if (!NT_STATUS_IS_OK(status
)) {
2295 torture_warning(tctx
, "could not bind to srvsvc pipe: %s\n",
2297 talloc_free(tmp_ctx
);
2298 return NT_STATUS_UNSUCCESSFUL
;
2300 b
= p
->binding_handle
;
2303 p
->conn
->flags
|= DCERPC_DEBUG_PRINT_IN
| DCERPC_DEBUG_PRINT_OUT
;
2306 r
.in
.server_unc
= talloc_asprintf(tmp_ctx
, "\\\\%s",
2307 dcerpc_server_name(p
));
2308 r
.in
.share_name
= sharename
;
2313 r
.in
.parm_error
= &error
;
2315 status
= dcerpc_srvsvc_NetShareSetInfo_r(b
, tmp_ctx
, &r
);
2316 if (!NT_STATUS_IS_OK(status
)) {
2317 torture_comment(tctx
, "srvsvc_NetShareSetInfo failed: %s\n",
2320 if (!W_ERROR_IS_OK(r
.out
.result
)) {
2321 torture_comment(tctx
, "srvsvc_NetShareSetInfo failed: %s\n",
2322 win_errstr(r
.out
.result
));
2323 status
= werror_to_ntstatus(r
.out
.result
);
2325 talloc_free(tmp_ctx
);
2329 bool try_tcon(struct torture_context
*tctx
,
2330 TALLOC_CTX
*mem_ctx
,
2331 struct security_descriptor
*orig_sd
,
2332 struct smbcli_session
*session
,
2333 const char *sharename
, const struct dom_sid
*user_sid
,
2334 unsigned int access_mask
, NTSTATUS expected_tcon
,
2335 NTSTATUS expected_mkdir
)
2337 TALLOC_CTX
*tmp_ctx
;
2338 struct smbcli_tree
*rmdir_tree
, *tree
;
2339 struct dom_sid
*domain_sid
;
2341 struct security_descriptor
*sd
;
2345 if (!(tmp_ctx
= talloc_new(mem_ctx
))) {
2346 torture_comment(tctx
, "talloc_new failed\n");
2350 status
= secondary_tcon(tctx
, tmp_ctx
, session
, sharename
, &rmdir_tree
);
2351 if (!NT_STATUS_IS_OK(status
)) {
2352 torture_comment(tctx
, "first tcon to delete dir failed\n");
2353 talloc_free(tmp_ctx
);
2357 smbcli_rmdir(rmdir_tree
, "sharesec_testdir");
2359 if (!NT_STATUS_IS_OK(dom_sid_split_rid(tmp_ctx
, user_sid
,
2360 &domain_sid
, &rid
))) {
2361 torture_comment(tctx
, "dom_sid_split_rid failed\n");
2362 talloc_free(tmp_ctx
);
2366 sd
= security_descriptor_dacl_create(
2367 tmp_ctx
, 0, "S-1-5-32-544",
2368 dom_sid_string(mem_ctx
, dom_sid_add_rid(mem_ctx
, domain_sid
,
2370 dom_sid_string(mem_ctx
, user_sid
),
2371 SEC_ACE_TYPE_ACCESS_ALLOWED
, access_mask
, 0, NULL
);
2373 torture_comment(tctx
, "security_descriptor_dacl_create failed\n");
2374 talloc_free(tmp_ctx
);
2378 status
= set_sharesec(tctx
, mem_ctx
, session
, sharename
, sd
);
2379 if (!NT_STATUS_IS_OK(status
)) {
2380 torture_comment(tctx
, "custom set_sharesec failed: %s\n",
2382 talloc_free(tmp_ctx
);
2386 status
= secondary_tcon(tctx
, tmp_ctx
, session
, sharename
, &tree
);
2387 if (!NT_STATUS_EQUAL(status
, expected_tcon
)) {
2388 torture_comment(tctx
, "Expected %s, got %s\n", nt_errstr(expected_tcon
),
2394 if (!NT_STATUS_IS_OK(status
)) {
2395 /* An expected non-access, no point in trying to write */
2399 status
= smbcli_mkdir(tree
, "sharesec_testdir");
2400 if (!NT_STATUS_EQUAL(status
, expected_mkdir
)) {
2401 torture_warning(tctx
, "Expected %s, got %s\n",
2402 nt_errstr(expected_mkdir
), nt_errstr(status
));
2407 smbcli_rmdir(rmdir_tree
, "sharesec_testdir");
2409 status
= set_sharesec(tctx
, mem_ctx
, session
, sharename
, orig_sd
);
2410 if (!NT_STATUS_IS_OK(status
)) {
2411 torture_comment(tctx
, "custom set_sharesec failed: %s\n",
2413 talloc_free(tmp_ctx
);
2417 talloc_free(tmp_ctx
);
2421 static bool torture_samba3_rpc_sharesec(struct torture_context
*torture
)
2423 struct smbcli_state
*cli
= NULL
;
2424 struct security_descriptor
*sd
= NULL
;
2425 struct dom_sid
*user_sid
= NULL
;
2426 const char *testuser_passwd
= NULL
;
2427 struct cli_credentials
*test_credentials
= NULL
;
2428 struct smbcli_options options
;
2429 struct smbcli_session_options session_options
;
2431 struct test_join
*tj
= NULL
;
2432 struct dcerpc_pipe
*lsa_pipe
= NULL
;
2433 const char *priv_array
[1];
2435 /* Create a new user. The normal user has SeBackup and SeRestore
2436 privs so we can't lock them out with a share security descriptor. */
2437 tj
= torture_create_testuser(torture
,
2439 torture_setting_string(torture
, "workgroup", NULL
),
2443 torture_fail(torture
, "Creating sharesec_user failed\n");
2446 /* Give them SeDiskOperatorPrivilege but no other privs. */
2447 status
= torture_rpc_connection(torture
, &lsa_pipe
, &ndr_table_lsarpc
);
2448 if (!NT_STATUS_IS_OK(status
)) {
2449 torture_delete_testuser(torture
, tj
, "sharesec_user");
2451 torture_fail(torture
, "Error connecting to LSA pipe");
2454 priv_array
[0] = "SeDiskOperatorPrivilege";
2455 if (!torture_setup_privs(torture
,
2459 torture_join_user_sid(tj
))) {
2460 talloc_free(lsa_pipe
);
2461 torture_delete_testuser(torture
, tj
, "sharesec_user");
2463 torture_fail(torture
, "Failed to setup privs\n");
2465 talloc_free(lsa_pipe
);
2467 test_credentials
= cli_credentials_init(torture
);
2468 cli_credentials_set_workstation(test_credentials
, "localhost", CRED_SPECIFIED
);
2469 cli_credentials_set_domain(test_credentials
, lpcfg_workgroup(torture
->lp_ctx
),
2471 cli_credentials_set_username(test_credentials
, "sharesec_user", CRED_SPECIFIED
);
2472 cli_credentials_set_password(test_credentials
, testuser_passwd
, CRED_SPECIFIED
);
2474 ZERO_STRUCT(options
);
2475 ZERO_STRUCT(session_options
);
2476 lpcfg_smbcli_options(torture
->lp_ctx
, &options
);
2477 lpcfg_smbcli_session_options(torture
->lp_ctx
, &session_options
);
2479 status
= smbcli_full_connection(torture
,
2481 torture_setting_string(torture
, "host", NULL
),
2482 lpcfg_smb_ports(torture
->lp_ctx
),
2485 lpcfg_socket_options(torture
->lp_ctx
),
2487 lpcfg_resolve_context(torture
->lp_ctx
),
2491 lpcfg_gensec_settings(torture
, torture
->lp_ctx
));
2492 if (!NT_STATUS_IS_OK(status
)) {
2494 torture_delete_testuser(torture
, tj
, "sharesec_user");
2496 torture_fail(torture
, "Failed to open connection\n");
2499 if (!(user_sid
= whoami(torture
, torture
, cli
->tree
))) {
2501 torture_delete_testuser(torture
, tj
, "sharesec_user");
2503 torture_fail(torture
, "whoami failed\n");
2506 sd
= get_sharesec(torture
, torture
, cli
->session
,
2507 torture_setting_string(torture
, "share", NULL
));
2509 if (!try_tcon(torture
, torture
, sd
, cli
->session
,
2510 torture_setting_string(torture
, "share", NULL
),
2511 user_sid
, 0, NT_STATUS_ACCESS_DENIED
, NT_STATUS_OK
)) {
2513 torture_delete_testuser(torture
, tj
, "sharesec_user");
2515 torture_fail(torture
, "failed to test tcon with 0 access_mask");
2518 if (!try_tcon(torture
, torture
, sd
, cli
->session
,
2519 torture_setting_string(torture
, "share", NULL
),
2520 user_sid
, SEC_FILE_READ_DATA
, NT_STATUS_OK
,
2521 NT_STATUS_MEDIA_WRITE_PROTECTED
)) {
2523 torture_delete_testuser(torture
, tj
, "sharesec_user");
2525 torture_fail(torture
, "failed to test tcon with SEC_FILE_READ_DATA access_mask");
2528 /* sharesec_user doesn't have any rights on the underlying file system.
2529 Go back to the normal user. */
2533 torture_delete_testuser(torture
, tj
, "sharesec_user");
2537 if (!(torture_open_connection_share(
2538 torture
, &cli
, torture
, torture_setting_string(torture
, "host", NULL
),
2539 "IPC$", torture
->ev
))) {
2540 torture_fail(torture
, "IPC$ connection failed\n");
2543 if (!(user_sid
= whoami(torture
, torture
, cli
->tree
))) {
2544 torture_fail(torture
, "whoami failed\n");
2546 torture_assert(torture
, try_tcon(
2547 torture
, torture
, sd
, cli
->session
,
2548 torture_setting_string(torture
, "share", NULL
),
2549 user_sid
, SEC_FILE_ALL
, NT_STATUS_OK
, NT_STATUS_OK
),
2550 "failed to test tcon with SEC_FILE_ALL access_mask");
2555 static bool torture_samba3_rpc_lsa(struct torture_context
*torture
)
2557 struct dcerpc_pipe
*p
;
2558 struct dcerpc_binding_handle
*b
;
2559 struct policy_handle lsa_handle
;
2561 torture_assert_ntstatus_ok(torture
,
2562 torture_rpc_connection(torture
, &p
, &ndr_table_lsarpc
),
2563 "failed to setup lsarpc");
2565 b
= p
->binding_handle
;
2568 struct lsa_ObjectAttribute attr
;
2569 struct lsa_OpenPolicy2 o
;
2570 o
.in
.system_name
= talloc_asprintf(
2571 torture
, "\\\\%s", dcerpc_server_name(p
));
2574 o
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2575 o
.out
.handle
= &lsa_handle
;
2577 torture_assert_ntstatus_ok(torture
,
2578 dcerpc_lsa_OpenPolicy2_r(b
, torture
, &o
),
2579 "dcerpc_lsa_OpenPolicy2 failed");
2580 torture_assert_ntstatus_ok(torture
, o
.out
.result
,
2581 "dcerpc_lsa_OpenPolicy2 failed");
2586 int levels
[] = { 2,3,5,6 };
2588 for (i
=0; i
<ARRAY_SIZE(levels
); i
++) {
2589 struct lsa_QueryInfoPolicy r
;
2590 union lsa_PolicyInformation
*info
= NULL
;
2591 r
.in
.handle
= &lsa_handle
;
2592 r
.in
.level
= levels
[i
];
2595 torture_assert_ntstatus_ok(torture
,
2596 dcerpc_lsa_QueryInfoPolicy_r(b
, torture
, &r
),
2597 talloc_asprintf(torture
, "dcerpc_lsa_QueryInfoPolicy level %d failed", levels
[i
]));
2598 torture_assert_ntstatus_ok(torture
, r
.out
.result
,
2599 talloc_asprintf(torture
, "dcerpc_lsa_QueryInfoPolicy level %d failed", levels
[i
]));
2606 static NTSTATUS
get_servername(TALLOC_CTX
*mem_ctx
, struct smbcli_tree
*tree
,
2609 struct rap_WserverGetInfo r
;
2611 char servername
[17];
2612 size_t converted_size
;
2615 r
.in
.bufsize
= 0xffff;
2617 status
= smbcli_rap_netservergetinfo(tree
, mem_ctx
, &r
);
2618 if (!NT_STATUS_IS_OK(status
)) {
2622 memcpy(servername
, r
.out
.info
.info0
.name
, 16);
2623 servername
[16] = '\0';
2625 if (!pull_ascii_talloc(mem_ctx
, name
, servername
, &converted_size
)) {
2626 return NT_STATUS_NO_MEMORY
;
2629 return NT_STATUS_OK
;
2632 static bool rap_get_servername(struct torture_context
*tctx
,
2635 struct smbcli_state
*cli
;
2637 torture_assert(tctx
,
2638 torture_open_connection_share(tctx
, &cli
, tctx
, torture_setting_string(tctx
, "host", NULL
),
2640 "IPC$ connection failed");
2642 torture_assert_ntstatus_ok(tctx
,
2643 get_servername(tctx
, cli
->tree
, servername
),
2644 "get_servername failed");
2651 static bool find_printers(struct torture_context
*tctx
,
2652 struct dcerpc_pipe
*p
,
2653 const char ***printers
,
2654 size_t *num_printers
)
2656 struct srvsvc_NetShareEnum r
;
2657 struct srvsvc_NetShareInfoCtr info_ctr
;
2658 struct srvsvc_NetShareCtr1 c1_in
;
2659 struct srvsvc_NetShareCtr1
*c1
;
2660 uint32_t totalentries
= 0;
2662 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
2666 info_ctr
.ctr
.ctr1
= &c1_in
;
2668 r
.in
.server_unc
= talloc_asprintf(
2669 tctx
, "\\\\%s", dcerpc_server_name(p
));
2670 r
.in
.info_ctr
= &info_ctr
;
2671 r
.in
.max_buffer
= (uint32_t)-1;
2672 r
.in
.resume_handle
= NULL
;
2673 r
.out
.totalentries
= &totalentries
;
2674 r
.out
.info_ctr
= &info_ctr
;
2676 torture_assert_ntstatus_ok(tctx
,
2677 dcerpc_srvsvc_NetShareEnum_r(b
, tctx
, &r
),
2678 "NetShareEnum level 1 failed");
2679 torture_assert_werr_ok(tctx
, r
.out
.result
,
2680 "NetShareEnum level 1 failed");
2684 c1
= r
.out
.info_ctr
->ctr
.ctr1
;
2685 for (i
=0; i
<c1
->count
; i
++) {
2686 if (c1
->array
[i
].type
!= STYPE_PRINTQ
) {
2689 if (!add_string_to_array(tctx
, c1
->array
[i
].name
,
2690 printers
, num_printers
)) {
2698 static bool enumprinters(struct torture_context
*tctx
,
2699 struct dcerpc_binding_handle
*b
,
2700 const char *servername
, int level
, int *num_printers
)
2702 struct spoolss_EnumPrinters r
;
2706 union spoolss_PrinterInfo
*info
;
2708 r
.in
.flags
= PRINTER_ENUM_LOCAL
;
2709 r
.in
.server
= talloc_asprintf(tctx
, "\\\\%s", servername
);
2713 r
.out
.needed
= &needed
;
2714 r
.out
.count
= &count
;
2717 torture_assert_ntstatus_ok(tctx
,
2718 dcerpc_spoolss_EnumPrinters_r(b
, tctx
, &r
),
2719 "dcerpc_spoolss_EnumPrinters failed");
2720 torture_assert_werr_equal(tctx
, r
.out
.result
, WERR_INSUFFICIENT_BUFFER
,
2721 "EnumPrinters unexpected return code should be WERR_INSUFFICIENT_BUFFER");
2723 blob
= data_blob_talloc_zero(tctx
, needed
);
2724 if (blob
.data
== NULL
) {
2728 r
.in
.buffer
= &blob
;
2729 r
.in
.offered
= needed
;
2731 torture_assert_ntstatus_ok(tctx
,
2732 dcerpc_spoolss_EnumPrinters_r(b
, tctx
, &r
),
2733 "dcerpc_spoolss_EnumPrinters failed");
2734 torture_assert_werr_ok(tctx
, r
.out
.result
,
2735 "dcerpc_spoolss_EnumPrinters failed");
2737 *num_printers
= count
;
2742 static bool getprinterinfo(struct torture_context
*tctx
,
2743 struct dcerpc_binding_handle
*b
,
2744 struct policy_handle
*handle
, int level
,
2745 union spoolss_PrinterInfo
**res
)
2747 struct spoolss_GetPrinter r
;
2751 r
.in
.handle
= handle
;
2755 r
.out
.needed
= &needed
;
2757 torture_assert_ntstatus_ok(tctx
,
2758 dcerpc_spoolss_GetPrinter_r(b
, tctx
, &r
),
2759 "dcerpc_spoolss_GetPrinter failed");
2760 torture_assert_werr_equal(tctx
, r
.out
.result
, WERR_INSUFFICIENT_BUFFER
,
2761 "GetPrinter unexpected return code should be WERR_INSUFFICIENT_BUFFER");
2763 r
.in
.handle
= handle
;
2765 blob
= data_blob_talloc_zero(tctx
, needed
);
2766 if (blob
.data
== NULL
) {
2769 r
.in
.buffer
= &blob
;
2770 r
.in
.offered
= needed
;
2772 torture_assert_ntstatus_ok(tctx
,
2773 dcerpc_spoolss_GetPrinter_r(b
, tctx
, &r
),
2774 "dcerpc_spoolss_GetPrinter failed");
2775 torture_assert_werr_ok(tctx
, r
.out
.result
,
2776 "dcerpc_spoolss_GetPrinter failed");
2779 *res
= talloc_steal(tctx
, r
.out
.info
);
2785 static bool torture_samba3_rpc_spoolss(struct torture_context
*torture
)
2787 struct dcerpc_pipe
*p
, *p2
;
2788 struct dcerpc_binding_handle
*b
;
2789 struct policy_handle server_handle
, printer_handle
;
2790 const char **printers
;
2791 size_t num_printers
;
2792 struct spoolss_UserLevel1 userlevel1
;
2795 torture_assert(torture
,
2796 rap_get_servername(torture
, &servername
),
2797 "failed to rap servername");
2799 torture_assert_ntstatus_ok(torture
,
2800 torture_rpc_connection(torture
, &p2
, &ndr_table_srvsvc
),
2801 "failed to setup srvsvc");
2803 torture_assert(torture
,
2804 find_printers(torture
, p2
, &printers
, &num_printers
),
2805 "failed to find printers via srvsvc");
2809 if (num_printers
== 0) {
2810 torture_skip(torture
, "Did not find printers\n");
2814 torture_assert_ntstatus_ok(torture
,
2815 torture_rpc_connection(torture
, &p
, &ndr_table_spoolss
),
2816 "failed to setup spoolss");
2818 b
= p
->binding_handle
;
2820 ZERO_STRUCT(userlevel1
);
2821 userlevel1
.client
= talloc_asprintf(
2822 torture
, "\\\\%s", lpcfg_netbios_name(torture
->lp_ctx
));
2823 userlevel1
.user
= cli_credentials_get_username(
2824 samba_cmdline_get_creds());
2825 userlevel1
.build
= 2600;
2826 userlevel1
.major
= 3;
2827 userlevel1
.minor
= 0;
2828 userlevel1
.processor
= 0;
2831 struct spoolss_OpenPrinterEx r
;
2834 r
.in
.printername
= talloc_asprintf(torture
, "\\\\%s",
2836 r
.in
.datatype
= NULL
;
2837 r
.in
.access_mask
= 0;
2838 r
.in
.userlevel_ctr
.level
= 1;
2839 r
.in
.userlevel_ctr
.user_info
.level1
= &userlevel1
;
2840 r
.out
.handle
= &server_handle
;
2842 torture_assert_ntstatus_ok(torture
,
2843 dcerpc_spoolss_OpenPrinterEx_r(b
, torture
, &r
),
2844 "dcerpc_spoolss_OpenPrinterEx failed");
2845 torture_assert_werr_ok(torture
, r
.out
.result
,
2846 "dcerpc_spoolss_OpenPrinterEx failed");
2850 struct spoolss_ClosePrinter r
;
2852 r
.in
.handle
= &server_handle
;
2853 r
.out
.handle
= &server_handle
;
2855 torture_assert_ntstatus_ok(torture
,
2856 dcerpc_spoolss_ClosePrinter_r(b
, torture
, &r
),
2857 "dcerpc_spoolss_ClosePrinter failed");
2858 torture_assert_werr_ok(torture
, r
.out
.result
,
2859 "dcerpc_spoolss_ClosePrinter failed");
2863 struct spoolss_OpenPrinterEx r
;
2866 r
.in
.printername
= talloc_asprintf(
2867 torture
, "\\\\%s\\%s", servername
, printers
[0]);
2868 r
.in
.datatype
= NULL
;
2869 r
.in
.access_mask
= 0;
2870 r
.in
.userlevel_ctr
.level
= 1;
2871 r
.in
.userlevel_ctr
.user_info
.level1
= &userlevel1
;
2872 r
.out
.handle
= &printer_handle
;
2874 torture_assert_ntstatus_ok(torture
,
2875 dcerpc_spoolss_OpenPrinterEx_r(b
, torture
, &r
),
2876 "dcerpc_spoolss_OpenPrinterEx failed");
2877 torture_assert_werr_ok(torture
, r
.out
.result
,
2878 "dcerpc_spoolss_OpenPrinterEx failed");
2884 for (i
=0; i
<8; i
++) {
2885 torture_assert(torture
,
2886 getprinterinfo(torture
, b
, &printer_handle
, i
, NULL
),
2887 talloc_asprintf(torture
, "getprinterinfo %d failed", i
));
2892 struct spoolss_ClosePrinter r
;
2894 r
.in
.handle
= &printer_handle
;
2895 r
.out
.handle
= &printer_handle
;
2897 torture_assert_ntstatus_ok(torture
,
2898 dcerpc_spoolss_ClosePrinter_r(b
, torture
, &r
),
2899 "dcerpc_spoolss_ClosePrinter failed");
2900 torture_assert_werr_ok(torture
, r
.out
.result
,
2901 "dcerpc_spoolss_ClosePrinter failed");
2907 torture_assert(torture
,
2908 enumprinters(torture
, b
, servername
, 1, &num_enumerated
),
2909 "enumprinters failed");
2911 torture_assert_int_equal(torture
, num_printers
, num_enumerated
,
2912 "netshareenum / enumprinters lvl 1 numprinter mismatch");
2918 torture_assert(torture
,
2919 enumprinters(torture
, b
, servername
, 2, &num_enumerated
),
2920 "enumprinters failed");
2922 torture_assert_int_equal(torture
, num_printers
, num_enumerated
,
2923 "netshareenum / enumprinters lvl 2 numprinter mismatch");
2929 static bool torture_samba3_rpc_wkssvc(struct torture_context
*torture
)
2931 struct dcerpc_pipe
*p
;
2932 struct dcerpc_binding_handle
*b
;
2935 torture_assert(torture
,
2936 rap_get_servername(torture
, &servername
),
2937 "failed to rap servername");
2939 torture_assert_ntstatus_ok(torture
,
2940 torture_rpc_connection(torture
, &p
, &ndr_table_wkssvc
),
2941 "failed to setup wkssvc");
2943 b
= p
->binding_handle
;
2946 struct wkssvc_NetWkstaInfo100 wks100
;
2947 union wkssvc_NetWkstaInfo info
;
2948 struct wkssvc_NetWkstaGetInfo r
;
2950 r
.in
.server_name
= "\\foo";
2952 info
.info100
= &wks100
;
2955 torture_assert_ntstatus_ok(torture
,
2956 dcerpc_wkssvc_NetWkstaGetInfo_r(b
, torture
, &r
),
2957 "dcerpc_wkssvc_NetWksGetInfo failed");
2958 torture_assert_werr_ok(torture
, r
.out
.result
,
2959 "dcerpc_wkssvc_NetWksGetInfo failed");
2961 torture_assert_str_equal(torture
, servername
, r
.out
.info
->info100
->server_name
,
2962 "servername RAP / DCERPC inconsistency");
2968 static bool winreg_close(struct torture_context
*tctx
,
2969 struct dcerpc_binding_handle
*b
,
2970 struct policy_handle
*handle
)
2972 struct winreg_CloseKey c
;
2974 c
.in
.handle
= c
.out
.handle
= handle
;
2976 torture_assert_ntstatus_ok(tctx
,
2977 dcerpc_winreg_CloseKey_r(b
, tctx
, &c
),
2978 "winreg_CloseKey failed");
2979 torture_assert_werr_ok(tctx
, c
.out
.result
,
2980 "winreg_CloseKey failed");
2985 static bool enumvalues(struct torture_context
*tctx
,
2986 struct dcerpc_binding_handle
*b
,
2987 struct policy_handle
*handle
)
2989 uint32_t enum_index
= 0;
2992 struct winreg_EnumValue r
;
2993 struct winreg_ValNameBuf name
;
2994 enum winreg_Type type
= 0;
2997 uint32_t size
, length
;
3000 r
.in
.handle
= handle
;
3001 r
.in
.enum_index
= enum_index
;
3004 r
.in
.name
= r
.out
.name
= &name
;
3010 r
.in
.length
= &length
;
3012 status
= dcerpc_winreg_EnumValue_r(b
, tctx
, &r
);
3013 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(r
.out
.result
)) {
3020 static bool enumkeys(struct torture_context
*tctx
,
3021 struct dcerpc_binding_handle
*b
,
3022 struct policy_handle
*handle
,
3025 struct winreg_EnumKey r
;
3026 struct winreg_StringBuf kclass
, name
;
3037 r
.in
.handle
= handle
;
3038 r
.in
.enum_index
= 0;
3040 r
.in
.keyclass
= &kclass
;
3042 r
.in
.last_changed_time
= &t
;
3045 struct winreg_OpenKey o
;
3046 struct policy_handle key_handle
;
3052 status
= dcerpc_winreg_EnumKey_r(b
, tctx
, &r
);
3053 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(r
.out
.result
)) {
3054 /* We're done enumerating */
3058 for (i
=0; i
<10-depth
; i
++) {
3059 torture_comment(tctx
, " ");
3061 torture_comment(tctx
, "%s\n", r
.out
.name
->name
);
3063 o
.in
.parent_handle
= handle
;
3064 o
.in
.keyname
.name
= r
.out
.name
->name
;
3066 o
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3067 o
.out
.handle
= &key_handle
;
3069 status
= dcerpc_winreg_OpenKey_r(b
, tctx
, &o
);
3070 if (NT_STATUS_IS_OK(status
) && W_ERROR_IS_OK(o
.out
.result
)) {
3071 enumkeys(tctx
, b
, &key_handle
, depth
-1);
3072 enumvalues(tctx
, b
, &key_handle
);
3073 torture_assert(tctx
, winreg_close(tctx
, b
, &key_handle
), "");
3076 r
.in
.enum_index
+= 1;
3082 typedef NTSTATUS (*winreg_open_fn
)(struct dcerpc_binding_handle
*, TALLOC_CTX
*, void *);
3084 static bool test_Open3(struct torture_context
*tctx
,
3085 struct dcerpc_binding_handle
*b
,
3086 const char *name
, winreg_open_fn open_fn
)
3088 struct policy_handle handle
;
3089 struct winreg_OpenHKLM r
;
3091 r
.in
.system_name
= 0;
3092 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3093 r
.out
.handle
= &handle
;
3095 torture_assert_ntstatus_ok(tctx
,
3096 open_fn(b
, tctx
, &r
),
3097 talloc_asprintf(tctx
, "%s failed", name
));
3098 torture_assert_werr_ok(tctx
, r
.out
.result
,
3099 talloc_asprintf(tctx
, "%s failed", name
));
3101 enumkeys(tctx
, b
, &handle
, 4);
3103 torture_assert(tctx
,
3104 winreg_close(tctx
, b
, &handle
),
3105 "dcerpc_CloseKey failed");
3110 static bool torture_samba3_rpc_winreg(struct torture_context
*torture
)
3112 struct dcerpc_pipe
*p
;
3113 struct dcerpc_binding_handle
*b
;
3119 {"OpenHKLM", (winreg_open_fn
)dcerpc_winreg_OpenHKLM_r
},
3120 {"OpenHKU", (winreg_open_fn
)dcerpc_winreg_OpenHKU_r
},
3121 {"OpenHKPD", (winreg_open_fn
)dcerpc_winreg_OpenHKPD_r
},
3122 {"OpenHKPT", (winreg_open_fn
)dcerpc_winreg_OpenHKPT_r
},
3123 {"OpenHKCR", (winreg_open_fn
)dcerpc_winreg_OpenHKCR_r
}};
3128 torture_assert_ntstatus_ok(torture
,
3129 torture_rpc_connection(torture
, &p
, &ndr_table_winreg
),
3130 "failed to setup winreg");
3132 b
= p
->binding_handle
;
3135 ret
= test_Open3(torture
, b
, open_fns
[0].name
, open_fns
[0].fn
);
3137 for (i
= 0; i
< ARRAY_SIZE(open_fns
); i
++) {
3138 if (!test_Open3(torture
, b
, open_fns
[i
].name
, open_fns
[i
].fn
))
3145 static bool get_shareinfo(struct torture_context
*tctx
,
3146 struct dcerpc_binding_handle
*b
,
3147 const char *servername
,
3149 struct srvsvc_NetShareInfo502
**info502
)
3151 struct srvsvc_NetShareGetInfo r
;
3152 union srvsvc_NetShareInfo info
;
3154 r
.in
.server_unc
= talloc_asprintf(tctx
, "\\\\%s", servername
);
3155 r
.in
.share_name
= share
;
3159 torture_assert_ntstatus_ok(tctx
,
3160 dcerpc_srvsvc_NetShareGetInfo_r(b
, tctx
, &r
),
3161 "srvsvc_NetShareGetInfo failed");
3162 torture_assert_werr_ok(tctx
, r
.out
.result
,
3163 "srvsvc_NetShareGetInfo failed");
3165 *info502
= talloc_move(tctx
, &info
.info502
);
3171 * Get us a handle on HKLM\
3174 static bool get_hklm_handle(struct torture_context
*tctx
,
3175 struct dcerpc_binding_handle
*b
,
3176 struct policy_handle
*handle
)
3178 struct winreg_OpenHKLM r
;
3179 struct policy_handle result
;
3181 r
.in
.system_name
= 0;
3182 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3183 r
.out
.handle
= &result
;
3185 torture_assert_ntstatus_ok(tctx
,
3186 dcerpc_winreg_OpenHKLM_r(b
, tctx
, &r
),
3188 torture_assert_werr_ok(tctx
, r
.out
.result
,
3196 static bool torture_samba3_createshare(struct torture_context
*tctx
,
3197 struct dcerpc_binding_handle
*b
,
3198 const char *sharename
)
3200 struct policy_handle hklm
;
3201 struct policy_handle new_handle
;
3202 struct winreg_CreateKey c
;
3203 struct winreg_CloseKey cl
;
3204 enum winreg_CreateAction action_taken
= REG_ACTION_NONE
;
3209 ZERO_STRUCT(new_handle
);
3211 c
.in
.handle
= &hklm
;
3212 c
.in
.name
.name
= talloc_asprintf(
3213 tctx
, "software\\samba\\smbconf\\%s", sharename
);
3214 torture_assert(tctx
, c
.in
.name
.name
, "talloc_asprintf failed");
3216 c
.in
.keyclass
.name
= "";
3218 c
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3219 c
.in
.secdesc
= NULL
;
3220 c
.in
.action_taken
= &action_taken
;
3221 c
.out
.new_handle
= &new_handle
;
3222 c
.out
.action_taken
= &action_taken
;
3224 torture_assert_ntstatus_ok(tctx
,
3225 dcerpc_winreg_CreateKey_r(b
, tctx
, &c
),
3227 torture_assert_werr_ok(tctx
, c
.out
.result
,
3230 cl
.in
.handle
= &new_handle
;
3231 cl
.out
.handle
= &new_handle
;
3233 torture_assert_ntstatus_ok(tctx
,
3234 dcerpc_winreg_CloseKey_r(b
, tctx
, &cl
),
3236 torture_assert_werr_ok(tctx
, cl
.out
.result
,
3242 static bool torture_samba3_deleteshare(struct torture_context
*tctx
,
3243 struct dcerpc_binding_handle
*b
,
3244 const char *sharename
)
3246 struct policy_handle hklm
;
3247 struct winreg_DeleteKey d
;
3249 torture_assert(tctx
,
3250 get_hklm_handle(tctx
, b
, &hklm
),
3251 "get_hklm_handle failed");
3253 d
.in
.handle
= &hklm
;
3254 d
.in
.key
.name
= talloc_asprintf(
3255 tctx
, "software\\samba\\smbconf\\%s", sharename
);
3256 torture_assert(tctx
, d
.in
.key
.name
, "talloc_asprintf failed");
3258 torture_assert_ntstatus_ok(tctx
,
3259 dcerpc_winreg_DeleteKey_r(b
, tctx
, &d
),
3260 "DeleteKey failed");
3261 torture_assert_werr_ok(tctx
, d
.out
.result
,
3262 "DeleteKey failed");
3267 static bool torture_samba3_setconfig(struct torture_context
*tctx
,
3268 struct dcerpc_binding_handle
*b
,
3269 const char *sharename
,
3270 const char *parameter
,
3273 struct policy_handle hklm
, key_handle
;
3274 struct winreg_OpenKey o
;
3275 struct winreg_SetValue s
;
3279 torture_assert(tctx
,
3280 get_hklm_handle(tctx
, b
, &hklm
),
3281 "get_hklm_handle failed");
3283 o
.in
.parent_handle
= &hklm
;
3284 o
.in
.keyname
.name
= talloc_asprintf(
3285 tctx
, "software\\samba\\smbconf\\%s", sharename
);
3286 torture_assert(tctx
, o
.in
.keyname
.name
, "talloc_asprintf failed");
3289 o
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3290 o
.out
.handle
= &key_handle
;
3292 torture_assert_ntstatus_ok(tctx
,
3293 dcerpc_winreg_OpenKey_r(b
, tctx
, &o
),
3295 torture_assert_werr_ok(tctx
, o
.out
.result
,
3298 torture_assert(tctx
,
3299 reg_string_to_val(tctx
, "REG_SZ", value
, &type
, &val
),
3300 "reg_string_to_val failed");
3302 s
.in
.handle
= &key_handle
;
3303 s
.in
.name
.name
= parameter
;
3305 s
.in
.data
= val
.data
;
3306 s
.in
.size
= val
.length
;
3308 torture_assert_ntstatus_ok(tctx
,
3309 dcerpc_winreg_SetValue_r(b
, tctx
, &s
),
3311 torture_assert_werr_ok(tctx
, s
.out
.result
,
3317 static bool torture_samba3_regconfig(struct torture_context
*torture
)
3319 struct srvsvc_NetShareInfo502
*i
= NULL
;
3320 const char *comment
= "Dummer Kommentar";
3321 struct dcerpc_pipe
*srvsvc_pipe
, *winreg_pipe
;
3323 torture_assert_ntstatus_ok(torture
,
3324 torture_rpc_connection(torture
, &srvsvc_pipe
, &ndr_table_srvsvc
),
3325 "failed to setup srvsvc");
3327 torture_assert_ntstatus_ok(torture
,
3328 torture_rpc_connection(torture
, &winreg_pipe
, &ndr_table_winreg
),
3329 "failed to setup winreg");
3331 torture_assert(torture
,
3332 torture_samba3_createshare(torture
, winreg_pipe
->binding_handle
, "blubber"),
3333 "torture_samba3_createshare failed");
3335 torture_assert(torture
,
3336 torture_samba3_setconfig(torture
, winreg_pipe
->binding_handle
, "blubber", "comment", comment
),
3337 "torture_samba3_setconfig failed");
3339 torture_assert(torture
,
3340 get_shareinfo(torture
, srvsvc_pipe
->binding_handle
, dcerpc_server_name(srvsvc_pipe
), "blubber", &i
),
3341 "get_shareinfo failed");
3343 torture_assert_str_equal(torture
, comment
, i
->comment
,
3344 "got unexpected comment");
3346 torture_assert(torture
,
3347 torture_samba3_deleteshare(torture
, winreg_pipe
->binding_handle
, "blubber"),
3348 "torture_samba3_deleteshare failed");
3354 * Test that even with a result of 0 rids the array is returned as a
3355 * non-NULL pointer. Yes, XP does notice.
3358 bool torture_samba3_getaliasmembership_0(struct torture_context
*torture
)
3360 struct dcerpc_pipe
*p
;
3361 struct dcerpc_binding_handle
*b
;
3362 struct samr_Connect2 c
;
3363 struct samr_OpenDomain o
;
3365 struct lsa_SidPtr ptr
;
3366 struct lsa_SidArray sids
;
3367 struct samr_GetAliasMembership g
;
3368 struct samr_Ids rids
;
3369 struct policy_handle samr
, domain
;
3371 torture_assert_ntstatus_ok(torture
,
3372 torture_rpc_connection(torture
, &p
, &ndr_table_samr
),
3373 "failed to setup samr");
3375 b
= p
->binding_handle
;
3377 c
.in
.system_name
= NULL
;
3378 c
.in
.access_mask
= SAMR_ACCESS_LOOKUP_DOMAIN
;
3379 c
.out
.connect_handle
= &samr
;
3380 torture_assert_ntstatus_ok(torture
,
3381 dcerpc_samr_Connect2_r(b
, torture
, &c
),
3383 torture_assert_ntstatus_ok(torture
, c
.out
.result
,
3385 dom_sid_parse("S-1-5-32", &sid
);
3386 o
.in
.connect_handle
= &samr
;
3387 o
.in
.access_mask
= SAMR_DOMAIN_ACCESS_LOOKUP_ALIAS
;
3389 o
.out
.domain_handle
= &domain
;
3390 torture_assert_ntstatus_ok(torture
,
3391 dcerpc_samr_OpenDomain_r(b
, torture
, &o
),
3393 torture_assert_ntstatus_ok(torture
, o
.out
.result
,
3395 dom_sid_parse("S-1-2-3-4-5", &sid
);
3399 g
.in
.domain_handle
= &domain
;
3402 torture_assert_ntstatus_ok(torture
,
3403 dcerpc_samr_GetAliasMembership_r(b
, torture
, &g
),
3405 torture_assert_ntstatus_ok(torture
, g
.out
.result
,
3407 if (rids
.ids
== NULL
) {
3408 /* This is the piece to test here */
3409 torture_fail(torture
,
3410 "torture_samba3_getaliasmembership_0: "
3411 "Server returns NULL rids array\n");
3418 * Test smb reauthentication while rpc pipe is in use.
3420 static bool torture_rpc_smb_reauth1(struct torture_context
*torture
)
3422 TALLOC_CTX
*mem_ctx
;
3425 struct smbcli_state
*cli
;
3426 struct smbcli_options options
;
3427 struct smbcli_session_options session_options
;
3429 struct dcerpc_pipe
*lsa_pipe
;
3430 struct dcerpc_binding_handle
*lsa_handle
;
3431 struct lsa_GetUserName r
;
3432 struct lsa_String
*authority_name_p
= NULL
;
3433 char *authority_name_saved
= NULL
;
3434 struct lsa_String
*account_name_p
= NULL
;
3435 char *account_name_saved
= NULL
;
3436 struct cli_credentials
*anon_creds
= NULL
;
3437 struct smb_composite_sesssetup io
;
3439 mem_ctx
= talloc_init("torture_samba3_reauth");
3440 torture_assert(torture
, (mem_ctx
!= NULL
), "talloc_init failed");
3442 lpcfg_smbcli_options(torture
->lp_ctx
, &options
);
3443 lpcfg_smbcli_session_options(torture
->lp_ctx
, &session_options
);
3445 status
= smbcli_full_connection(mem_ctx
, &cli
,
3446 torture_setting_string(torture
, "host", NULL
),
3447 lpcfg_smb_ports(torture
->lp_ctx
),
3449 lpcfg_socket_options(torture
->lp_ctx
),
3450 samba_cmdline_get_creds(),
3451 lpcfg_resolve_context(torture
->lp_ctx
),
3452 torture
->ev
, &options
, &session_options
,
3453 lpcfg_gensec_settings(torture
, torture
->lp_ctx
));
3454 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3455 "smbcli_full_connection failed");
3457 status
= pipe_bind_smb(torture
, mem_ctx
, cli
->tree
, "\\lsarpc",
3458 &ndr_table_lsarpc
, &lsa_pipe
);
3459 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3460 "pipe_bind_smb failed");
3461 lsa_handle
= lsa_pipe
->binding_handle
;
3463 /* lsa getusername */
3466 r
.in
.system_name
= "\\";
3467 r
.in
.account_name
= &account_name_p
;
3468 r
.in
.authority_name
= &authority_name_p
;
3469 r
.out
.account_name
= &account_name_p
;
3471 status
= dcerpc_lsa_GetUserName_r(lsa_handle
, mem_ctx
, &r
);
3473 authority_name_p
= *r
.out
.authority_name
;
3475 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3476 "GetUserName failed");
3477 torture_assert_ntstatus_ok_goto(torture
, r
.out
.result
, ret
, done
,
3478 "GetUserName failed");
3480 torture_comment(torture
, "lsa_GetUserName gave '%s\\%s'\n",
3481 authority_name_p
->string
,
3482 account_name_p
->string
);
3484 account_name_saved
= talloc_strdup(mem_ctx
, account_name_p
->string
);
3485 torture_assert_goto(torture
, (account_name_saved
!= NULL
), ret
, done
,
3487 authority_name_saved
= talloc_strdup(mem_ctx
, authority_name_p
->string
);
3488 torture_assert_goto(torture
, (authority_name_saved
!= NULL
), ret
, done
,
3491 /* smb re-authenticate as anonymous */
3493 anon_creds
= cli_credentials_init_anon(mem_ctx
);
3496 io
.in
.sesskey
= cli
->transport
->negotiate
.sesskey
;
3497 io
.in
.capabilities
= cli
->transport
->negotiate
.capabilities
;
3498 io
.in
.credentials
= anon_creds
;
3499 io
.in
.workgroup
= lpcfg_workgroup(torture
->lp_ctx
);
3500 io
.in
.gensec_settings
= lpcfg_gensec_settings(torture
, torture
->lp_ctx
);
3502 status
= smb_composite_sesssetup(cli
->session
, &io
);
3503 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3504 "session reauth to anon failed");
3506 /* re-do lsa getusername after reauth */
3508 TALLOC_FREE(authority_name_p
);
3509 TALLOC_FREE(account_name_p
);
3511 r
.in
.system_name
= "\\";
3512 r
.in
.account_name
= &account_name_p
;
3513 r
.in
.authority_name
= &authority_name_p
;
3514 r
.out
.account_name
= &account_name_p
;
3516 status
= dcerpc_lsa_GetUserName_r(lsa_handle
, mem_ctx
, &r
);
3518 authority_name_p
= *r
.out
.authority_name
;
3520 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3521 "GetUserName failed");
3522 torture_assert_ntstatus_ok_goto(torture
, r
.out
.result
, ret
, done
,
3523 "GetUserName failed");
3525 torture_assert_goto(torture
, (strcmp(authority_name_p
->string
, authority_name_saved
) == 0),
3526 ret
, done
, "authority_name not equal after reauth to anon");
3527 torture_assert_goto(torture
, (strcmp(account_name_p
->string
, account_name_saved
) == 0),
3528 ret
, done
, "account_name not equal after reauth to anon");
3530 /* smb re-auth again to the original user */
3533 io
.in
.sesskey
= cli
->transport
->negotiate
.sesskey
;
3534 io
.in
.capabilities
= cli
->transport
->negotiate
.capabilities
;
3535 io
.in
.credentials
= samba_cmdline_get_creds();
3536 io
.in
.workgroup
= lpcfg_workgroup(torture
->lp_ctx
);
3537 io
.in
.gensec_settings
= lpcfg_gensec_settings(torture
, torture
->lp_ctx
);
3539 status
= smb_composite_sesssetup(cli
->session
, &io
);
3540 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3541 "session reauth to anon failed");
3543 /* re-do lsa getusername */
3545 TALLOC_FREE(authority_name_p
);
3546 TALLOC_FREE(account_name_p
);
3548 r
.in
.system_name
= "\\";
3549 r
.in
.account_name
= &account_name_p
;
3550 r
.in
.authority_name
= &authority_name_p
;
3551 r
.out
.account_name
= &account_name_p
;
3553 status
= dcerpc_lsa_GetUserName_r(lsa_handle
, mem_ctx
, &r
);
3555 authority_name_p
= *r
.out
.authority_name
;
3557 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3558 "GetUserName failed");
3559 torture_assert_ntstatus_ok_goto(torture
, r
.out
.result
, ret
, done
,
3560 "GetUserName failed");
3562 torture_assert_goto(torture
, (strcmp(authority_name_p
->string
, authority_name_saved
) == 0),
3563 ret
, done
, "authority_name not equal after reauth to anon");
3564 torture_assert_goto(torture
, (strcmp(account_name_p
->string
, account_name_saved
) == 0),
3565 ret
, done
, "account_name not equal after reauth to anon");
3570 talloc_free(mem_ctx
);
3575 * Test smb reauthentication while rpc pipe is in use.
3576 * Open a second lsa bind after reauth to anon.
3577 * Do lsa getusername on that second bind.
3579 static bool torture_rpc_smb_reauth2(struct torture_context
*torture
)
3581 TALLOC_CTX
*mem_ctx
;
3584 struct smbcli_state
*cli
;
3585 struct smbcli_options options
;
3586 struct smbcli_session_options session_options
;
3588 struct dcerpc_pipe
*lsa_pipe
;
3589 struct dcerpc_binding_handle
*lsa_handle
;
3590 struct lsa_GetUserName r
;
3591 struct lsa_String
*authority_name_p
= NULL
;
3592 char *authority_name_saved
= NULL
;
3593 struct lsa_String
*account_name_p
= NULL
;
3594 char *account_name_saved
= NULL
;
3595 struct cli_credentials
*anon_creds
= NULL
;
3596 struct smb_composite_sesssetup io
;
3598 mem_ctx
= talloc_init("torture_samba3_reauth");
3599 torture_assert(torture
, (mem_ctx
!= NULL
), "talloc_init failed");
3601 lpcfg_smbcli_options(torture
->lp_ctx
, &options
);
3602 lpcfg_smbcli_session_options(torture
->lp_ctx
, &session_options
);
3604 status
= smbcli_full_connection(mem_ctx
, &cli
,
3605 torture_setting_string(torture
, "host", NULL
),
3606 lpcfg_smb_ports(torture
->lp_ctx
),
3608 lpcfg_socket_options(torture
->lp_ctx
),
3609 samba_cmdline_get_creds(),
3610 lpcfg_resolve_context(torture
->lp_ctx
),
3611 torture
->ev
, &options
, &session_options
,
3612 lpcfg_gensec_settings(torture
, torture
->lp_ctx
));
3613 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3614 "smbcli_full_connection failed");
3616 /* smb re-authenticate as anonymous */
3618 anon_creds
= cli_credentials_init_anon(mem_ctx
);
3621 io
.in
.sesskey
= cli
->transport
->negotiate
.sesskey
;
3622 io
.in
.capabilities
= cli
->transport
->negotiate
.capabilities
;
3623 io
.in
.credentials
= anon_creds
;
3624 io
.in
.workgroup
= lpcfg_workgroup(torture
->lp_ctx
);
3625 io
.in
.gensec_settings
= lpcfg_gensec_settings(torture
, torture
->lp_ctx
);
3627 status
= smb_composite_sesssetup(cli
->session
, &io
);
3628 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3629 "session reauth to anon failed");
3631 /* open the lsa pipe */
3633 status
= pipe_bind_smb(torture
, mem_ctx
, cli
->tree
, "\\lsarpc",
3634 &ndr_table_lsarpc
, &lsa_pipe
);
3635 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3636 "pipe_bind_smb failed");
3637 lsa_handle
= lsa_pipe
->binding_handle
;
3639 /* lsa getusername */
3642 r
.in
.system_name
= "\\";
3643 r
.in
.account_name
= &account_name_p
;
3644 r
.in
.authority_name
= &authority_name_p
;
3645 r
.out
.account_name
= &account_name_p
;
3647 status
= dcerpc_lsa_GetUserName_r(lsa_handle
, mem_ctx
, &r
);
3649 authority_name_p
= *r
.out
.authority_name
;
3651 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3652 "GetUserName failed");
3653 torture_assert_ntstatus_ok_goto(torture
, r
.out
.result
, ret
, done
,
3654 "GetUserName failed");
3656 torture_comment(torture
, "lsa_GetUserName gave '%s\\%s'\n",
3657 authority_name_p
->string
,
3658 account_name_p
->string
);
3660 account_name_saved
= talloc_strdup(mem_ctx
, account_name_p
->string
);
3661 torture_assert_goto(torture
, (account_name_saved
!= NULL
), ret
, done
,
3663 authority_name_saved
= talloc_strdup(mem_ctx
, authority_name_p
->string
);
3664 torture_assert_goto(torture
, (authority_name_saved
!= NULL
), ret
, done
,
3667 /* smb re-auth again to the original user */
3670 io
.in
.sesskey
= cli
->transport
->negotiate
.sesskey
;
3671 io
.in
.capabilities
= cli
->transport
->negotiate
.capabilities
;
3672 io
.in
.credentials
= samba_cmdline_get_creds();
3673 io
.in
.workgroup
= lpcfg_workgroup(torture
->lp_ctx
);
3674 io
.in
.gensec_settings
= lpcfg_gensec_settings(torture
, torture
->lp_ctx
);
3676 status
= smb_composite_sesssetup(cli
->session
, &io
);
3677 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3678 "session reauth to anon failed");
3680 /* re-do lsa getusername after reauth */
3682 TALLOC_FREE(authority_name_p
);
3683 TALLOC_FREE(account_name_p
);
3685 r
.in
.system_name
= "\\";
3686 r
.in
.account_name
= &account_name_p
;
3687 r
.in
.authority_name
= &authority_name_p
;
3688 r
.out
.account_name
= &account_name_p
;
3690 status
= dcerpc_lsa_GetUserName_r(lsa_handle
, mem_ctx
, &r
);
3692 authority_name_p
= *r
.out
.authority_name
;
3694 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3695 "GetUserName failed");
3696 torture_assert_ntstatus_ok_goto(torture
, r
.out
.result
, ret
, done
,
3697 "GetUserName failed");
3699 torture_assert_goto(torture
, (strcmp(authority_name_p
->string
, authority_name_saved
) == 0),
3700 ret
, done
, "authority_name not equal after reauth to anon");
3701 torture_assert_goto(torture
, (strcmp(account_name_p
->string
, account_name_saved
) == 0),
3702 ret
, done
, "account_name not equal after reauth to anon");
3707 talloc_free(mem_ctx
);
3712 * Test smb2 reauthentication while rpc pipe is in use.
3714 static bool torture_rpc_smb2_reauth1(struct torture_context
*torture
)
3716 TALLOC_CTX
*mem_ctx
;
3719 struct smbcli_options options
;
3721 struct dcerpc_pipe
*lsa_pipe
;
3722 struct dcerpc_binding_handle
*lsa_handle
;
3723 struct lsa_GetUserName r
;
3724 struct lsa_String
*authority_name_p
= NULL
;
3725 char *authority_name_saved
= NULL
;
3726 struct lsa_String
*account_name_p
= NULL
;
3727 char *account_name_saved
= NULL
;
3728 struct cli_credentials
*anon_creds
= NULL
;
3729 const char *host
= torture_setting_string(torture
, "host", NULL
);
3730 struct smb2_tree
*tree
;
3732 mem_ctx
= talloc_init("torture_samba3_reauth");
3733 torture_assert(torture
, (mem_ctx
!= NULL
), "talloc_init failed");
3735 lpcfg_smbcli_options(torture
->lp_ctx
, &options
);
3737 status
= smb2_connect(mem_ctx
,
3739 lpcfg_smb_ports(torture
->lp_ctx
),
3741 lpcfg_resolve_context(torture
->lp_ctx
),
3742 samba_cmdline_get_creds(),
3746 lpcfg_socket_options(torture
->lp_ctx
),
3747 lpcfg_gensec_settings(torture
, torture
->lp_ctx
)
3749 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3750 "smb2_connect failed");
3752 status
= pipe_bind_smb2(torture
, mem_ctx
, tree
, "lsarpc",
3753 &ndr_table_lsarpc
, &lsa_pipe
);
3754 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3755 "pipe_bind_smb2 failed");
3756 lsa_handle
= lsa_pipe
->binding_handle
;
3758 /* lsa getusername */
3761 r
.in
.system_name
= "\\";
3762 r
.in
.account_name
= &account_name_p
;
3763 r
.in
.authority_name
= &authority_name_p
;
3764 r
.out
.account_name
= &account_name_p
;
3766 status
= dcerpc_lsa_GetUserName_r(lsa_handle
, mem_ctx
, &r
);
3768 authority_name_p
= *r
.out
.authority_name
;
3770 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3771 "GetUserName failed");
3772 torture_assert_ntstatus_ok_goto(torture
, r
.out
.result
, ret
, done
,
3773 "GetUserName failed");
3775 torture_comment(torture
, "lsa_GetUserName gave '%s\\%s'\n",
3776 authority_name_p
->string
,
3777 account_name_p
->string
);
3779 account_name_saved
= talloc_strdup(mem_ctx
, account_name_p
->string
);
3780 torture_assert_goto(torture
, (account_name_saved
!= NULL
), ret
, done
,
3782 authority_name_saved
= talloc_strdup(mem_ctx
, authority_name_p
->string
);
3783 torture_assert_goto(torture
, (authority_name_saved
!= NULL
), ret
, done
,
3786 /* smb re-authenticate as anonymous */
3788 anon_creds
= cli_credentials_init_anon(mem_ctx
);
3790 status
= smb2_session_setup_spnego(tree
->session
,
3792 0 /* previous_session_id */);
3793 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3794 "session reauth to anon failed");
3796 /* re-do lsa getusername after reauth */
3798 TALLOC_FREE(authority_name_p
);
3799 TALLOC_FREE(account_name_p
);
3801 r
.in
.system_name
= "\\";
3802 r
.in
.account_name
= &account_name_p
;
3803 r
.in
.authority_name
= &authority_name_p
;
3804 r
.out
.account_name
= &account_name_p
;
3806 status
= dcerpc_lsa_GetUserName_r(lsa_handle
, mem_ctx
, &r
);
3808 authority_name_p
= *r
.out
.authority_name
;
3810 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3811 "GetUserName failed");
3812 torture_assert_ntstatus_ok_goto(torture
, r
.out
.result
, ret
, done
,
3813 "GetUserName failed");
3815 torture_assert_goto(torture
, (strcmp(authority_name_p
->string
, authority_name_saved
) == 0),
3816 ret
, done
, "authority_name not equal after reauth to anon");
3817 torture_assert_goto(torture
, (strcmp(account_name_p
->string
, account_name_saved
) == 0),
3818 ret
, done
, "account_name not equal after reauth to anon");
3820 /* smb re-auth again to the original user */
3822 status
= smb2_session_setup_spnego(tree
->session
,
3823 samba_cmdline_get_creds(),
3824 0 /* previous_session_id */);
3825 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3826 "session reauth to anon failed");
3828 /* re-do lsa getusername */
3830 TALLOC_FREE(authority_name_p
);
3831 TALLOC_FREE(account_name_p
);
3833 r
.in
.system_name
= "\\";
3834 r
.in
.account_name
= &account_name_p
;
3835 r
.in
.authority_name
= &authority_name_p
;
3836 r
.out
.account_name
= &account_name_p
;
3838 status
= dcerpc_lsa_GetUserName_r(lsa_handle
, mem_ctx
, &r
);
3840 authority_name_p
= *r
.out
.authority_name
;
3842 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3843 "GetUserName failed");
3844 torture_assert_ntstatus_ok_goto(torture
, r
.out
.result
, ret
, done
,
3845 "GetUserName failed");
3847 torture_assert_goto(torture
, (strcmp(authority_name_p
->string
, authority_name_saved
) == 0),
3848 ret
, done
, "authority_name not equal after reauth to anon");
3849 torture_assert_goto(torture
, (strcmp(account_name_p
->string
, account_name_saved
) == 0),
3850 ret
, done
, "account_name not equal after reauth to anon");
3855 talloc_free(mem_ctx
);
3860 * Test smb2 reauthentication while rpc pipe is in use.
3861 * Open a second lsa bind after reauth to anon.
3862 * Do lsa getusername on that second bind.
3864 static bool torture_rpc_smb2_reauth2(struct torture_context
*torture
)
3866 TALLOC_CTX
*mem_ctx
;
3869 struct smbcli_options options
;
3871 struct dcerpc_pipe
*lsa_pipe
;
3872 struct dcerpc_binding_handle
*lsa_handle
;
3873 struct lsa_GetUserName r
;
3874 struct lsa_String
*authority_name_p
= NULL
;
3875 char *authority_name_saved
= NULL
;
3876 struct lsa_String
*account_name_p
= NULL
;
3877 char *account_name_saved
= NULL
;
3878 struct cli_credentials
*anon_creds
= NULL
;
3879 const char *host
= torture_setting_string(torture
, "host", NULL
);
3880 struct smb2_tree
*tree
;
3882 mem_ctx
= talloc_init("torture_samba3_reauth");
3883 torture_assert(torture
, (mem_ctx
!= NULL
), "talloc_init failed");
3885 lpcfg_smbcli_options(torture
->lp_ctx
, &options
);
3887 status
= smb2_connect(mem_ctx
,
3889 lpcfg_smb_ports(torture
->lp_ctx
),
3891 lpcfg_resolve_context(torture
->lp_ctx
),
3892 samba_cmdline_get_creds(),
3896 lpcfg_socket_options(torture
->lp_ctx
),
3897 lpcfg_gensec_settings(torture
, torture
->lp_ctx
)
3899 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3900 "smb2_connect failed");
3902 /* smb re-authenticate as anonymous */
3904 anon_creds
= cli_credentials_init_anon(mem_ctx
);
3906 status
= smb2_session_setup_spnego(tree
->session
,
3908 0 /* previous_session_id */);
3909 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3910 "session reauth to anon failed");
3912 /* open the lsa pipe */
3914 status
= pipe_bind_smb2(torture
, mem_ctx
, tree
, "lsarpc",
3915 &ndr_table_lsarpc
, &lsa_pipe
);
3916 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3917 "pipe_bind_smb2 failed");
3918 lsa_handle
= lsa_pipe
->binding_handle
;
3920 /* lsa getusername */
3923 r
.in
.system_name
= "\\";
3924 r
.in
.account_name
= &account_name_p
;
3925 r
.in
.authority_name
= &authority_name_p
;
3926 r
.out
.account_name
= &account_name_p
;
3928 status
= dcerpc_lsa_GetUserName_r(lsa_handle
, mem_ctx
, &r
);
3930 authority_name_p
= *r
.out
.authority_name
;
3932 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3933 "GetUserName failed");
3934 torture_assert_ntstatus_ok_goto(torture
, r
.out
.result
, ret
, done
,
3935 "GetUserName failed");
3937 torture_comment(torture
, "lsa_GetUserName gave '%s\\%s'\n",
3938 authority_name_p
->string
,
3939 account_name_p
->string
);
3941 account_name_saved
= talloc_strdup(mem_ctx
, account_name_p
->string
);
3942 torture_assert_goto(torture
, (account_name_saved
!= NULL
), ret
, done
,
3944 authority_name_saved
= talloc_strdup(mem_ctx
, authority_name_p
->string
);
3945 torture_assert_goto(torture
, (authority_name_saved
!= NULL
), ret
, done
,
3948 /* smb re-auth again to the original user */
3950 status
= smb2_session_setup_spnego(tree
->session
,
3951 samba_cmdline_get_creds(),
3952 0 /* previous_session_id */);
3953 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3954 "session reauth to anon failed");
3956 /* re-do lsa getusername */
3958 TALLOC_FREE(authority_name_p
);
3959 TALLOC_FREE(account_name_p
);
3961 r
.in
.system_name
= "\\";
3962 r
.in
.account_name
= &account_name_p
;
3963 r
.in
.authority_name
= &authority_name_p
;
3964 r
.out
.account_name
= &account_name_p
;
3966 status
= dcerpc_lsa_GetUserName_r(lsa_handle
, mem_ctx
, &r
);
3968 authority_name_p
= *r
.out
.authority_name
;
3970 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
3971 "GetUserName failed");
3972 torture_assert_ntstatus_ok_goto(torture
, r
.out
.result
, ret
, done
,
3973 "GetUserName failed");
3975 torture_assert_goto(torture
, (strcmp(authority_name_p
->string
, authority_name_saved
) == 0),
3976 ret
, done
, "authority_name not equal after reauth to anon");
3977 torture_assert_goto(torture
, (strcmp(account_name_p
->string
, account_name_saved
) == 0),
3978 ret
, done
, "account_name not equal after reauth to anon");
3983 talloc_free(mem_ctx
);
3987 static bool torture_rpc_smb1_pipe_name(struct torture_context
*torture
)
3989 TALLOC_CTX
*mem_ctx
;
3992 struct smbcli_state
*cli
;
3993 struct smbcli_options options
;
3994 struct smbcli_session_options session_options
;
3999 mem_ctx
= talloc_init("torture_samba3_smb1_pipe_name");
4000 torture_assert(torture
, (mem_ctx
!= NULL
), "talloc_init failed");
4002 lpcfg_smbcli_options(torture
->lp_ctx
, &options
);
4003 lpcfg_smbcli_session_options(torture
->lp_ctx
, &session_options
);
4005 status
= smbcli_full_connection(mem_ctx
, &cli
,
4006 torture_setting_string(torture
, "host", NULL
),
4007 lpcfg_smb_ports(torture
->lp_ctx
),
4009 lpcfg_socket_options(torture
->lp_ctx
),
4010 samba_cmdline_get_creds(),
4011 lpcfg_resolve_context(torture
->lp_ctx
),
4012 torture
->ev
, &options
, &session_options
,
4013 lpcfg_gensec_settings(torture
, torture
->lp_ctx
));
4014 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4015 "smbcli_full_connection failed");
4018 io
.generic
.level
= RAW_OPEN_NTCREATEX
;
4019 io
.ntcreatex
.in
.access_mask
= DESIRED_ACCESS_PIPE
;
4020 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
4021 NTCREATEX_SHARE_ACCESS_WRITE
;
4022 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_OPEN
;
4023 io
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_IMPERSONATION
;
4024 io
.ntcreatex
.in
.security_flags
= 0;
4026 io
.ntcreatex
.in
.fname
= "__none__";
4027 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4028 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
4030 "smb_raw_open for '__none__'");
4032 io
.ntcreatex
.in
.fname
= "pipe\\srvsvc";
4033 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4034 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
4036 "smb_raw_open for 'pipe\\srvsvc'");
4038 io
.ntcreatex
.in
.fname
= "\\pipe\\srvsvc";
4039 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4040 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
4042 "smb_raw_open for '\\pipe\\srvsvc'");
4044 io
.ntcreatex
.in
.fname
= "srvsvc";
4045 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4046 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4047 "smb2_create failed for 'srvsvc'");
4048 fnum
= io
.ntcreatex
.out
.file
.fnum
;
4050 cl
.generic
.level
= RAW_CLOSE_CLOSE
;
4051 cl
.close
.in
.file
.fnum
= fnum
;
4052 status
= smb_raw_close(cli
->tree
, &cl
);
4053 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4054 "smb_raw_close failed");
4056 io
.ntcreatex
.in
.fname
= "\\srvsvc";
4057 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4058 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4059 "smb2_create failed for '\\srvsvc'");
4060 fnum
= io
.ntcreatex
.out
.file
.fnum
;
4062 cl
.generic
.level
= RAW_CLOSE_CLOSE
;
4063 cl
.close
.in
.file
.fnum
= fnum
;
4064 status
= smb_raw_close(cli
->tree
, &cl
);
4065 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4066 "smb_raw_close failed");
4068 io
.ntcreatex
.in
.fname
= "\\\\\\\\\\srvsvc";
4069 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4070 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4071 "smb2_create failed for '\\\\\\\\\\srvsvc'");
4072 fnum
= io
.ntcreatex
.out
.file
.fnum
;
4074 cl
.generic
.level
= RAW_CLOSE_CLOSE
;
4075 cl
.close
.in
.file
.fnum
= fnum
;
4076 status
= smb_raw_close(cli
->tree
, &cl
);
4077 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4078 "smb_raw_close failed");
4081 io
.generic
.level
= RAW_OPEN_NTTRANS_CREATE
;
4082 io
.nttrans
.in
.access_mask
= DESIRED_ACCESS_PIPE
;
4083 io
.nttrans
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
4084 NTCREATEX_SHARE_ACCESS_WRITE
;
4085 io
.nttrans
.in
.open_disposition
= NTCREATEX_DISP_OPEN
;
4086 io
.nttrans
.in
.impersonation
= NTCREATEX_IMPERSONATION_IMPERSONATION
;
4087 io
.nttrans
.in
.security_flags
= 0;
4089 io
.nttrans
.in
.fname
= "__none__";
4090 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4091 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
4093 "smb_raw_open for '__none__'");
4095 io
.nttrans
.in
.fname
= "pipe\\srvsvc";
4096 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4097 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
4099 "smb_raw_open for 'pipe\\srvsvc'");
4101 io
.nttrans
.in
.fname
= "\\pipe\\srvsvc";
4102 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4103 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
4105 "smb_raw_open for '\\pipe\\srvsvc'");
4107 io
.nttrans
.in
.fname
= "srvsvc";
4108 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4109 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4110 "smb2_create failed for 'srvsvc'");
4111 fnum
= io
.nttrans
.out
.file
.fnum
;
4113 cl
.generic
.level
= RAW_CLOSE_CLOSE
;
4114 cl
.close
.in
.file
.fnum
= fnum
;
4115 status
= smb_raw_close(cli
->tree
, &cl
);
4116 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4117 "smb_raw_close failed");
4119 io
.nttrans
.in
.fname
= "\\srvsvc";
4120 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4121 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4122 "smb2_create failed for '\\srvsvc'");
4123 fnum
= io
.nttrans
.out
.file
.fnum
;
4125 cl
.generic
.level
= RAW_CLOSE_CLOSE
;
4126 cl
.close
.in
.file
.fnum
= fnum
;
4127 status
= smb_raw_close(cli
->tree
, &cl
);
4128 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4129 "smb_raw_close failed");
4131 io
.nttrans
.in
.fname
= "\\\\\\\\\\srvsvc";
4132 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4133 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4134 "smb2_create failed for '\\\\\\\\\\srvsvc'");
4135 fnum
= io
.nttrans
.out
.file
.fnum
;
4137 cl
.generic
.level
= RAW_CLOSE_CLOSE
;
4138 cl
.close
.in
.file
.fnum
= fnum
;
4139 status
= smb_raw_close(cli
->tree
, &cl
);
4140 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4141 "smb_raw_close failed");
4144 io
.generic
.level
= RAW_OPEN_OPENX
;
4145 io
.openx
.in
.open_mode
= OPENX_MODE_ACCESS_RDWR
;
4146 io
.openx
.in
.open_func
= OPENX_OPEN_FUNC_OPEN
;
4148 io
.openx
.in
.fname
= "__none__";
4149 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4150 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_OBJECT_PATH_SYNTAX_BAD
,
4152 "smb_raw_open for '__none__'");
4154 io
.openx
.in
.fname
= "srvsvc";
4155 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4156 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_OBJECT_PATH_SYNTAX_BAD
,
4158 "smb_raw_open for 'srvsvc'");
4160 io
.openx
.in
.fname
= "\\srvsvc";
4161 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4162 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_OBJECT_PATH_SYNTAX_BAD
,
4164 "smb_raw_open for '\\srvsvc'");
4166 io
.openx
.in
.fname
= "\\pipesrvsvc";
4167 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4168 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_OBJECT_PATH_SYNTAX_BAD
,
4170 "smb_raw_open for '\\pipesrvsvc'");
4172 io
.openx
.in
.fname
= "pipe\\__none__";
4173 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4174 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
4176 "smb_raw_open for 'pipe\\__none__'");
4178 io
.openx
.in
.fname
= "\\pipe\\__none__";
4179 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4180 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
4182 "smb_raw_open for '\\pipe\\__none__'");
4184 io
.openx
.in
.fname
= "pipe\\srvsvc";
4185 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4186 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4187 "smb2_create failed for 'pipe\\srvsvc'");
4188 fnum
= io
.openx
.out
.file
.fnum
;
4190 cl
.generic
.level
= RAW_CLOSE_CLOSE
;
4191 cl
.close
.in
.file
.fnum
= fnum
;
4192 status
= smb_raw_close(cli
->tree
, &cl
);
4193 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4194 "smb_raw_close failed");
4196 io
.openx
.in
.fname
= "\\pipe\\srvsvc";
4197 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4198 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4199 "smb2_create failed for '\\pipe\\srvsvc'");
4200 fnum
= io
.openx
.out
.file
.fnum
;
4202 cl
.generic
.level
= RAW_CLOSE_CLOSE
;
4203 cl
.close
.in
.file
.fnum
= fnum
;
4204 status
= smb_raw_close(cli
->tree
, &cl
);
4205 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4206 "smb_raw_close failed");
4208 io
.openx
.in
.fname
= "\\\\\\\\\\pipe\\srvsvc";
4209 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4210 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4211 "smb2_create failed for '\\\\\\\\\\pipe\\srvsvc'");
4212 fnum
= io
.openx
.out
.file
.fnum
;
4214 cl
.generic
.level
= RAW_CLOSE_CLOSE
;
4215 cl
.close
.in
.file
.fnum
= fnum
;
4216 status
= smb_raw_close(cli
->tree
, &cl
);
4217 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4218 "smb_raw_close failed");
4220 io
.openx
.in
.fname
= "\\\\\\\\\\pipe\\\\\\\\\\srvsvc";
4221 status
= smb_raw_open(cli
->tree
, torture
, &io
);
4222 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4223 "smb2_create failed for '\\\\\\\\\\pipe\\\\\\\\\\srvsvc'");
4224 fnum
= io
.openx
.out
.file
.fnum
;
4226 cl
.generic
.level
= RAW_CLOSE_CLOSE
;
4227 cl
.close
.in
.file
.fnum
= fnum
;
4228 status
= smb_raw_close(cli
->tree
, &cl
);
4229 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4230 "smb_raw_close failed");
4234 talloc_free(mem_ctx
);
4238 static bool torture_rpc_smb2_pipe_name(struct torture_context
*torture
)
4240 TALLOC_CTX
*mem_ctx
;
4243 struct smbcli_options options
;
4244 const char *host
= torture_setting_string(torture
, "host", NULL
);
4245 struct smb2_tree
*tree
;
4246 struct smb2_handle h
;
4247 struct smb2_create io
;
4249 mem_ctx
= talloc_init("torture_samba3_smb2_pipe_name");
4250 torture_assert(torture
, (mem_ctx
!= NULL
), "talloc_init failed");
4252 lpcfg_smbcli_options(torture
->lp_ctx
, &options
);
4254 status
= smb2_connect(mem_ctx
,
4256 lpcfg_smb_ports(torture
->lp_ctx
),
4258 lpcfg_resolve_context(torture
->lp_ctx
),
4259 samba_cmdline_get_creds(),
4263 lpcfg_socket_options(torture
->lp_ctx
),
4264 lpcfg_gensec_settings(torture
, torture
->lp_ctx
)
4266 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4267 "smb2_connect failed");
4270 io
.in
.oplock_level
= 0;
4271 io
.in
.desired_access
= DESIRED_ACCESS_PIPE
;
4272 io
.in
.impersonation_level
= SMB2_IMPERSONATION_IMPERSONATION
;
4273 io
.in
.file_attributes
= 0;
4274 io
.in
.create_disposition
= NTCREATEX_DISP_OPEN
;
4275 io
.in
.share_access
=
4276 NTCREATEX_SHARE_ACCESS_READ
|
4277 NTCREATEX_SHARE_ACCESS_WRITE
;
4278 io
.in
.create_options
= 0;
4280 io
.in
.fname
= "__none__";
4281 status
= smb2_create(tree
, tree
, &io
);
4282 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
4284 "smb2_create for '__none__'");
4286 io
.in
.fname
= "\\srvsvc";
4287 status
= smb2_create(tree
, tree
, &io
);
4288 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
4290 "smb2_create for '\\srvsvc'");
4292 io
.in
.fname
= "\\pipe\\srvsvc";
4293 status
= smb2_create(tree
, tree
, &io
);
4294 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
4296 "smb2_create for '\\pipe\\srvsvc'");
4298 io
.in
.fname
= "pipe\\srvsvc";
4299 status
= smb2_create(tree
, tree
, &io
);
4300 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
4302 "smb2_create for 'pipe\\srvsvc'");
4304 io
.in
.fname
= "srvsvc";
4305 status
= smb2_create(tree
, tree
, &io
);
4306 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4307 "smb2_create failed for 'srvsvc'");
4309 h
= io
.out
.file
.handle
;
4311 status
= smb2_util_close(tree
, h
);
4312 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4313 "smb2_util_close failed");
4317 talloc_free(mem_ctx
);
4322 * Test behaviour of a waiting read call on a pipe when
4323 * the pipe handle is closed:
4324 * - open a pipe via smb2
4325 * - trigger a read which hangs since there is nothing to read
4326 * - close the pipe file handle
4327 * - wait for the read to return and check the status
4328 * (STATUS_PIPE_BROKEN)
4330 static bool torture_rpc_smb2_pipe_read_close(struct torture_context
*torture
)
4332 TALLOC_CTX
*mem_ctx
;
4335 struct smbcli_options options
;
4336 const char *host
= torture_setting_string(torture
, "host", NULL
);
4337 struct smb2_tree
*tree
;
4338 struct smb2_handle h
;
4339 struct smb2_request
*smb2req
;
4340 struct smb2_create io
;
4341 struct smb2_read rd
;
4343 mem_ctx
= talloc_init("torture_samba3_pipe_read_close");
4344 torture_assert(torture
, (mem_ctx
!= NULL
), "talloc_init failed");
4346 lpcfg_smbcli_options(torture
->lp_ctx
, &options
);
4348 status
= smb2_connect(mem_ctx
,
4350 lpcfg_smb_ports(torture
->lp_ctx
),
4352 lpcfg_resolve_context(torture
->lp_ctx
),
4353 samba_cmdline_get_creds(),
4357 lpcfg_socket_options(torture
->lp_ctx
),
4358 lpcfg_gensec_settings(torture
, torture
->lp_ctx
)
4360 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4361 "smb2_connect failed");
4364 io
.in
.oplock_level
= 0;
4365 io
.in
.desired_access
= DESIRED_ACCESS_PIPE
;
4366 io
.in
.impersonation_level
= SMB2_IMPERSONATION_IMPERSONATION
;
4367 io
.in
.file_attributes
= 0;
4368 io
.in
.create_disposition
= NTCREATEX_DISP_OPEN
;
4369 io
.in
.share_access
=
4370 NTCREATEX_SHARE_ACCESS_READ
|
4371 NTCREATEX_SHARE_ACCESS_WRITE
;
4372 io
.in
.create_options
= 0;
4373 io
.in
.fname
= "lsarpc";
4375 status
= smb2_create(tree
, tree
, &io
);
4376 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4377 "smb2_create failed for 'lsarpc'");
4379 h
= io
.out
.file
.handle
;
4382 rd
.in
.file
.handle
= h
;
4383 rd
.in
.length
= 1024;
4385 rd
.in
.min_count
= 0;
4387 smb2req
= smb2_read_send(tree
, &rd
);
4388 torture_assert_goto(torture
, (smb2req
!= NULL
), ret
, done
,
4389 "smb2_read_send failed");
4391 status
= smb2_util_close(tree
, h
);
4392 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4393 "smb2_util_close failed");
4395 status
= smb2_read_recv(smb2req
, mem_ctx
, &rd
);
4396 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_PIPE_BROKEN
, ret
, done
,
4397 "smb2_read_recv: unexpected return code");
4401 talloc_free(mem_ctx
);
4406 * Test behaviour of a waiting read call on a pipe when
4407 * the tree is disconnected.
4408 * - open a pipe via smb2
4409 * - trigger a read which hangs since there is nothing to read
4410 * - do a tree disconnect
4411 * - wait for the read to return and check the status
4412 * (STATUS_PIPE_BROKEN)
4414 static bool torture_rpc_smb2_pipe_read_tdis(struct torture_context
*torture
)
4416 TALLOC_CTX
*mem_ctx
;
4419 struct smbcli_options options
;
4420 const char *host
= torture_setting_string(torture
, "host", NULL
);
4421 struct smb2_tree
*tree
;
4422 struct smb2_handle h
;
4423 struct smb2_request
*smb2req
;
4424 struct smb2_create io
;
4425 struct smb2_read rd
;
4427 mem_ctx
= talloc_init("torture_samba3_pipe_read_tdis");
4428 torture_assert(torture
, (mem_ctx
!= NULL
), "talloc_init failed");
4430 lpcfg_smbcli_options(torture
->lp_ctx
, &options
);
4432 status
= smb2_connect(mem_ctx
,
4434 lpcfg_smb_ports(torture
->lp_ctx
),
4436 lpcfg_resolve_context(torture
->lp_ctx
),
4437 samba_cmdline_get_creds(),
4441 lpcfg_socket_options(torture
->lp_ctx
),
4442 lpcfg_gensec_settings(torture
, torture
->lp_ctx
)
4444 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4445 "smb2_connect failed");
4448 io
.in
.oplock_level
= 0;
4449 io
.in
.desired_access
= DESIRED_ACCESS_PIPE
;
4450 io
.in
.impersonation_level
= SMB2_IMPERSONATION_IMPERSONATION
;
4451 io
.in
.file_attributes
= 0;
4452 io
.in
.create_disposition
= NTCREATEX_DISP_OPEN
;
4453 io
.in
.share_access
=
4454 NTCREATEX_SHARE_ACCESS_READ
|
4455 NTCREATEX_SHARE_ACCESS_WRITE
;
4456 io
.in
.create_options
= 0;
4457 io
.in
.fname
= "lsarpc";
4459 status
= smb2_create(tree
, tree
, &io
);
4460 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4461 "smb2_create failed for 'lsarpc'");
4463 h
= io
.out
.file
.handle
;
4466 rd
.in
.file
.handle
= h
;
4467 rd
.in
.length
= 1024;
4469 rd
.in
.min_count
= 0;
4471 smb2req
= smb2_read_send(tree
, &rd
);
4472 torture_assert_goto(torture
, (smb2req
!= NULL
), ret
, done
,
4473 "smb2_read_send failed");
4475 status
= smb2_tdis(tree
);
4476 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4477 "smb2_tdis failed");
4479 status
= smb2_read_recv(smb2req
, mem_ctx
, &rd
);
4480 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_PIPE_BROKEN
, ret
, done
,
4481 "smb2_read_recv: unexpected return code");
4485 talloc_free(mem_ctx
);
4490 * Test behaviour of a waiting read call on a pipe when
4492 * - open a pipe via smb2
4493 * - trigger a read which hangs since there is nothing to read
4495 * - wait for the read to return and check the status
4496 * (STATUS_PIPE_BROKEN)
4498 static bool torture_rpc_smb2_pipe_read_logoff(struct torture_context
*torture
)
4500 TALLOC_CTX
*mem_ctx
;
4503 struct smbcli_options options
;
4504 const char *host
= torture_setting_string(torture
, "host", NULL
);
4505 struct smb2_tree
*tree
;
4506 struct smb2_handle h
;
4507 struct smb2_request
*smb2req
;
4508 struct smb2_create io
;
4509 struct smb2_read rd
;
4511 mem_ctx
= talloc_init("torture_samba3_pipe_read_tdis");
4512 torture_assert(torture
, (mem_ctx
!= NULL
), "talloc_init failed");
4514 lpcfg_smbcli_options(torture
->lp_ctx
, &options
);
4516 status
= smb2_connect(mem_ctx
,
4518 lpcfg_smb_ports(torture
->lp_ctx
),
4520 lpcfg_resolve_context(torture
->lp_ctx
),
4521 samba_cmdline_get_creds(),
4525 lpcfg_socket_options(torture
->lp_ctx
),
4526 lpcfg_gensec_settings(torture
, torture
->lp_ctx
)
4528 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4529 "smb2_connect failed");
4532 io
.in
.oplock_level
= 0;
4533 io
.in
.desired_access
= DESIRED_ACCESS_PIPE
;
4534 io
.in
.impersonation_level
= SMB2_IMPERSONATION_IMPERSONATION
;
4535 io
.in
.file_attributes
= 0;
4536 io
.in
.create_disposition
= NTCREATEX_DISP_OPEN
;
4537 io
.in
.share_access
=
4538 NTCREATEX_SHARE_ACCESS_READ
|
4539 NTCREATEX_SHARE_ACCESS_WRITE
;
4540 io
.in
.create_options
= 0;
4541 io
.in
.fname
= "lsarpc";
4543 status
= smb2_create(tree
, tree
, &io
);
4544 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4545 "smb2_create failed for 'lsarpc'");
4547 h
= io
.out
.file
.handle
;
4550 rd
.in
.file
.handle
= h
;
4551 rd
.in
.length
= 1024;
4553 rd
.in
.min_count
= 0;
4555 smb2req
= smb2_read_send(tree
, &rd
);
4556 torture_assert_goto(torture
, (smb2req
!= NULL
), ret
, done
,
4557 "smb2_read_send failed");
4559 status
= smb2_logoff(tree
->session
);
4560 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4561 "smb2_logoff failed");
4563 status
= smb2_read_recv(smb2req
, mem_ctx
, &rd
);
4564 torture_assert_ntstatus_equal_goto(torture
, status
, NT_STATUS_PIPE_BROKEN
, ret
, done
,
4565 "smb2_read_recv: unexpected return code");
4569 talloc_free(mem_ctx
);
4573 static bool torture_rpc_lsa_over_netlogon(struct torture_context
*torture
)
4575 TALLOC_CTX
*mem_ctx
;
4578 struct smbcli_options options
;
4579 struct smb2_tree
*tree
;
4580 struct dcerpc_pipe
*netlogon_pipe
;
4581 struct dcerpc_binding_handle
*lsa_handle
;
4582 struct lsa_ObjectAttribute attr
;
4583 struct lsa_QosInfo qos
;
4584 struct lsa_OpenPolicy2 o
;
4585 struct policy_handle handle
;
4587 torture_comment(torture
, "Testing if we can access LSA server over "
4588 "\\\\pipe\\netlogon rather than \\\\pipe\\lsarpc\n");
4590 mem_ctx
= talloc_init("torture_samba3_rpc_lsa_over_netlogon");
4591 torture_assert(torture
, (mem_ctx
!= NULL
), "talloc_init failed");
4593 lpcfg_smbcli_options(torture
->lp_ctx
, &options
);
4595 status
= smb2_connect(mem_ctx
,
4596 torture_setting_string(torture
, "host", NULL
),
4597 lpcfg_smb_ports(torture
->lp_ctx
),
4599 lpcfg_resolve_context(torture
->lp_ctx
),
4600 samba_cmdline_get_creds(),
4604 lpcfg_socket_options(torture
->lp_ctx
),
4605 lpcfg_gensec_settings(torture
, torture
->lp_ctx
)
4607 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4608 "smb2_connect failed");
4610 status
= pipe_bind_smb2(torture
, mem_ctx
, tree
, "netlogon",
4611 &ndr_table_lsarpc
, &netlogon_pipe
);
4612 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4613 "pipe_bind_smb2 failed");
4614 lsa_handle
= netlogon_pipe
->binding_handle
;
4617 qos
.impersonation_level
= 2;
4618 qos
.context_mode
= 1;
4619 qos
.effective_only
= 0;
4622 attr
.root_dir
= NULL
;
4623 attr
.object_name
= NULL
;
4624 attr
.attributes
= 0;
4625 attr
.sec_desc
= NULL
;
4626 attr
.sec_qos
= &qos
;
4628 o
.in
.system_name
= "\\";
4630 o
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
4631 o
.out
.handle
= &handle
;
4633 torture_assert_ntstatus_ok(torture
,
4634 dcerpc_lsa_OpenPolicy2_r(lsa_handle
, torture
, &o
),
4635 "OpenPolicy2 failed");
4636 torture_assert_ntstatus_ok(torture
,
4638 "OpenPolicy2 failed");
4642 talloc_free(mem_ctx
);
4646 static bool torture_rpc_pipes_supported_interfaces(
4647 struct torture_context
*torture
)
4649 TALLOC_CTX
*mem_ctx
;
4652 struct smbcli_options options
;
4653 struct smb2_tree
*tree
;
4654 struct dcerpc_pipe
*pipe1
;
4655 struct dcerpc_pipe
*pipe2
;
4656 struct dcerpc_pipe
*pipe3
;
4658 torture_comment(torture
, "Testing only appropriate interfaces are "
4659 "available in smb pipes\n");
4661 mem_ctx
= talloc_init("torture_samba3_rpc_pipes_supported_interfaces");
4662 torture_assert(torture
, (mem_ctx
!= NULL
), "talloc_init failed");
4664 lpcfg_smbcli_options(torture
->lp_ctx
, &options
);
4666 status
= smb2_connect(mem_ctx
,
4667 torture_setting_string(torture
, "host", NULL
),
4668 lpcfg_smb_ports(torture
->lp_ctx
),
4670 lpcfg_resolve_context(torture
->lp_ctx
),
4671 samba_cmdline_get_creds(),
4675 lpcfg_socket_options(torture
->lp_ctx
),
4676 lpcfg_gensec_settings(torture
, torture
->lp_ctx
)
4678 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
4679 "smb2_connect failed");
4681 /* Test embedded services pipes. The svcctl interface is
4682 * not available if we open the winreg pipe. */
4683 status
= pipe_bind_smb2(torture
, mem_ctx
, tree
, "winreg",
4684 &ndr_table_svcctl
, &pipe1
);
4685 torture_assert_ntstatus_equal(torture
,
4687 NT_STATUS_RPC_UNSUPPORTED_NAME_SYNTAX
,
4688 "svcctl interface not supported in winreg pipe");
4690 /* Test it is not possible to bind to S4 server provided services */
4691 status
= pipe_bind_smb2(torture
, mem_ctx
, tree
, "srvsvc",
4692 &ndr_table_samr
, &pipe2
);
4693 torture_assert_ntstatus_equal(torture
,
4695 NT_STATUS_RPC_UNSUPPORTED_NAME_SYNTAX
,
4696 "samr interface not supported in srvsvc pipe");
4698 /* Test pipes in forked daemons like lsassd. The lsarpc interface is
4699 * not available if we open the SAMR pipe. */
4700 status
= pipe_bind_smb2(torture
, mem_ctx
, tree
, "samr",
4701 &ndr_table_lsarpc
, &pipe3
);
4702 torture_assert_ntstatus_equal(torture
,
4704 NT_STATUS_RPC_UNSUPPORTED_NAME_SYNTAX
,
4705 "lsarpc interface not supported in samr pipe");
4709 talloc_free(mem_ctx
);
4713 struct torture_suite
*torture_rpc_samba3(TALLOC_CTX
*mem_ctx
)
4715 struct torture_suite
*suite
= torture_suite_create(mem_ctx
, "samba3");
4717 torture_suite_add_simple_test(suite
, "bind", torture_bind_samba3
);
4718 torture_suite_add_simple_test(suite
, "netlogon", torture_netlogon_samba3
);
4719 torture_suite_add_simple_test(suite
, "sessionkey", torture_samba3_sessionkey
);
4720 torture_suite_add_simple_test(suite
, "srvsvc", torture_samba3_rpc_srvsvc
);
4721 torture_suite_add_simple_test(suite
, "sharesec", torture_samba3_rpc_sharesec
);
4722 torture_suite_add_simple_test(suite
, "getusername", torture_samba3_rpc_getusername
);
4723 torture_suite_add_simple_test(suite
, "randomauth2", torture_samba3_rpc_randomauth2
);
4724 torture_suite_add_simple_test(suite
, "lsa", torture_samba3_rpc_lsa
);
4725 torture_suite_add_simple_test(suite
, "spoolss", torture_samba3_rpc_spoolss
);
4726 torture_suite_add_simple_test(suite
, "wkssvc", torture_samba3_rpc_wkssvc
);
4727 torture_suite_add_simple_test(suite
, "winreg", torture_samba3_rpc_winreg
);
4728 torture_suite_add_simple_test(suite
, "getaliasmembership-0", torture_samba3_getaliasmembership_0
);
4729 torture_suite_add_simple_test(suite
, "regconfig", torture_samba3_regconfig
);
4730 torture_suite_add_simple_test(suite
, "smb-reauth1", torture_rpc_smb_reauth1
);
4731 torture_suite_add_simple_test(suite
, "smb-reauth2", torture_rpc_smb_reauth2
);
4732 torture_suite_add_simple_test(suite
, "smb2-reauth1", torture_rpc_smb2_reauth1
);
4733 torture_suite_add_simple_test(suite
, "smb2-reauth2", torture_rpc_smb2_reauth2
);
4734 torture_suite_add_simple_test(suite
, "smb1-pipe-name", torture_rpc_smb1_pipe_name
);
4735 torture_suite_add_simple_test(suite
, "smb2-pipe-name", torture_rpc_smb2_pipe_name
);
4736 torture_suite_add_simple_test(suite
, "smb2-pipe-read-close", torture_rpc_smb2_pipe_read_close
);
4737 torture_suite_add_simple_test(suite
, "smb2-pipe-read-tdis", torture_rpc_smb2_pipe_read_tdis
);
4738 torture_suite_add_simple_test(suite
, "smb2-pipe-read-logoff", torture_rpc_smb2_pipe_read_logoff
);
4739 torture_suite_add_simple_test(suite
,
4740 "lsa_over_netlogon",
4741 torture_rpc_lsa_over_netlogon
);
4742 torture_suite_add_simple_test(suite
,
4743 "pipes_supported_interfaces",
4744 torture_rpc_pipes_supported_interfaces
);
4746 suite
->description
= talloc_strdup(suite
, "samba3 DCERPC interface tests");