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/rap/rap.h"
25 #include "torture/torture.h"
26 #include "torture/util.h"
27 #include "torture/rap/proto.h"
28 #include "librpc/gen_ndr/ndr_lsa.h"
29 #include "librpc/gen_ndr/ndr_lsa_c.h"
30 #include "librpc/gen_ndr/ndr_samr.h"
31 #include "librpc/gen_ndr/ndr_samr_c.h"
32 #include "librpc/gen_ndr/ndr_netlogon.h"
33 #include "librpc/gen_ndr/ndr_netlogon_c.h"
34 #include "librpc/gen_ndr/ndr_srvsvc.h"
35 #include "librpc/gen_ndr/ndr_srvsvc_c.h"
36 #include "librpc/gen_ndr/ndr_spoolss.h"
37 #include "librpc/gen_ndr/ndr_spoolss_c.h"
38 #include "librpc/gen_ndr/ndr_winreg.h"
39 #include "librpc/gen_ndr/ndr_winreg_c.h"
40 #include "librpc/gen_ndr/ndr_wkssvc.h"
41 #include "librpc/gen_ndr/ndr_wkssvc_c.h"
42 #include "lib/cmdline/popt_common.h"
43 #include "librpc/rpc/dcerpc.h"
44 #include "torture/rpc/rpc.h"
45 #include "libcli/libcli.h"
46 #include "libcli/composite/composite.h"
47 #include "libcli/smb_composite/smb_composite.h"
48 #include "libcli/auth/libcli_auth.h"
49 #include "lib/crypto/crypto.h"
50 #include "libcli/security/proto.h"
51 #include "param/param.h"
52 #include "lib/registry/registry.h"
55 * This tests a RPC call using an invalid vuid
58 bool torture_bind_authcontext(struct torture_context *torture)
63 struct lsa_ObjectAttribute objectattr;
64 struct lsa_OpenPolicy2 openpolicy;
65 struct policy_handle handle;
66 struct lsa_Close close_handle;
67 struct smbcli_session *tmp;
68 struct smbcli_session *session2;
69 struct smbcli_state *cli;
70 struct dcerpc_pipe *lsa_pipe;
71 struct cli_credentials *anon_creds;
72 struct smb_composite_sesssetup setup;
74 mem_ctx = talloc_init("torture_bind_authcontext");
76 if (mem_ctx == NULL) {
77 d_printf("talloc_init failed\n");
81 status = smbcli_full_connection(mem_ctx, &cli,
82 torture_setting_string(torture, "host", NULL),
83 lp_smb_ports(torture->lp_ctx),
84 "IPC$", NULL, cmdline_credentials,
86 if (!NT_STATUS_IS_OK(status)) {
87 d_printf("smbcli_full_connection failed: %s\n",
92 lsa_pipe = dcerpc_pipe_init(mem_ctx, cli->transport->socket->event.ctx);
93 if (lsa_pipe == NULL) {
94 d_printf("dcerpc_pipe_init failed\n");
98 status = dcerpc_pipe_open_smb(lsa_pipe, cli->tree, "\\lsarpc");
99 if (!NT_STATUS_IS_OK(status)) {
100 d_printf("dcerpc_pipe_open_smb failed: %s\n",
105 status = dcerpc_bind_auth_none(lsa_pipe, &ndr_table_lsarpc);
106 if (!NT_STATUS_IS_OK(status)) {
107 d_printf("dcerpc_bind_auth_none failed: %s\n",
112 openpolicy.in.system_name =talloc_asprintf(
113 mem_ctx, "\\\\%s", dcerpc_server_name(lsa_pipe));
114 ZERO_STRUCT(objectattr);
115 openpolicy.in.attr = &objectattr;
116 openpolicy.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
117 openpolicy.out.handle = &handle;
119 status = dcerpc_lsa_OpenPolicy2(lsa_pipe, mem_ctx, &openpolicy);
121 if (!NT_STATUS_IS_OK(status)) {
122 d_printf("dcerpc_lsa_OpenPolicy2 failed: %s\n",
127 close_handle.in.handle = &handle;
128 close_handle.out.handle = &handle;
130 status = dcerpc_lsa_Close(lsa_pipe, mem_ctx, &close_handle);
131 if (!NT_STATUS_IS_OK(status)) {
132 d_printf("dcerpc_lsa_Close failed: %s\n",
137 session2 = smbcli_session_init(cli->transport, mem_ctx, false);
138 if (session2 == NULL) {
139 d_printf("smbcli_session_init failed\n");
143 if (!(anon_creds = cli_credentials_init_anon(mem_ctx))) {
144 d_printf("create_anon_creds failed\n");
148 setup.in.sesskey = cli->transport->negotiate.sesskey;
149 setup.in.capabilities = cli->transport->negotiate.capabilities;
150 setup.in.workgroup = "";
151 setup.in.credentials = anon_creds;
153 status = smb_composite_sesssetup(session2, &setup);
154 if (!NT_STATUS_IS_OK(status)) {
155 d_printf("anon session setup failed: %s\n",
159 session2->vuid = setup.out.vuid;
161 tmp = cli->tree->session;
162 cli->tree->session = session2;
164 status = dcerpc_lsa_OpenPolicy2(lsa_pipe, mem_ctx, &openpolicy);
166 cli->tree->session = tmp;
167 talloc_free(lsa_pipe);
170 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
171 d_printf("dcerpc_lsa_OpenPolicy2 with wrong vuid gave %s, "
172 "expected NT_STATUS_INVALID_HANDLE\n",
179 talloc_free(mem_ctx);
184 * Bind to lsa using a specific auth method
187 static bool bindtest(struct smbcli_state *cli,
188 struct cli_credentials *credentials,
189 struct loadparm_context *lp_ctx,
190 uint8_t auth_type, uint8_t auth_level)
196 struct dcerpc_pipe *lsa_pipe;
197 struct lsa_ObjectAttribute objectattr;
198 struct lsa_OpenPolicy2 openpolicy;
199 struct lsa_QueryInfoPolicy query;
200 struct policy_handle handle;
201 struct lsa_Close close_handle;
203 if ((mem_ctx = talloc_init("bindtest")) == NULL) {
204 d_printf("talloc_init failed\n");
208 lsa_pipe = dcerpc_pipe_init(mem_ctx,
209 cli->transport->socket->event.ctx);
210 if (lsa_pipe == NULL) {
211 d_printf("dcerpc_pipe_init failed\n");
215 status = dcerpc_pipe_open_smb(lsa_pipe, cli->tree, "\\lsarpc");
216 if (!NT_STATUS_IS_OK(status)) {
217 d_printf("dcerpc_pipe_open_smb failed: %s\n",
222 status = dcerpc_bind_auth(lsa_pipe, &ndr_table_lsarpc,
223 credentials, lp_ctx, auth_type, auth_level,
225 if (!NT_STATUS_IS_OK(status)) {
226 d_printf("dcerpc_bind_auth failed: %s\n", nt_errstr(status));
230 openpolicy.in.system_name =talloc_asprintf(
231 mem_ctx, "\\\\%s", dcerpc_server_name(lsa_pipe));
232 ZERO_STRUCT(objectattr);
233 openpolicy.in.attr = &objectattr;
234 openpolicy.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
235 openpolicy.out.handle = &handle;
237 status = dcerpc_lsa_OpenPolicy2(lsa_pipe, mem_ctx, &openpolicy);
239 if (!NT_STATUS_IS_OK(status)) {
240 d_printf("dcerpc_lsa_OpenPolicy2 failed: %s\n",
245 query.in.handle = &handle;
246 query.in.level = LSA_POLICY_INFO_DOMAIN;
248 status = dcerpc_lsa_QueryInfoPolicy(lsa_pipe, mem_ctx, &query);
249 if (!NT_STATUS_IS_OK(status)) {
250 d_printf("dcerpc_lsa_QueryInfoPolicy failed: %s\n",
255 close_handle.in.handle = &handle;
256 close_handle.out.handle = &handle;
258 status = dcerpc_lsa_Close(lsa_pipe, mem_ctx, &close_handle);
259 if (!NT_STATUS_IS_OK(status)) {
260 d_printf("dcerpc_lsa_Close failed: %s\n",
267 talloc_free(mem_ctx);
272 * test authenticated RPC binds with the variants Samba3 does support
275 bool torture_bind_samba3(struct torture_context *torture)
280 struct smbcli_state *cli;
282 mem_ctx = talloc_init("torture_bind_authcontext");
284 if (mem_ctx == NULL) {
285 d_printf("talloc_init failed\n");
289 status = smbcli_full_connection(mem_ctx, &cli,
290 torture_setting_string(torture, "host", NULL),
291 lp_smb_ports(torture->lp_ctx),
292 "IPC$", NULL, cmdline_credentials,
294 if (!NT_STATUS_IS_OK(status)) {
295 d_printf("smbcli_full_connection failed: %s\n",
302 ret &= bindtest(cli, cmdline_credentials, torture->lp_ctx, DCERPC_AUTH_TYPE_NTLMSSP,
303 DCERPC_AUTH_LEVEL_INTEGRITY);
304 ret &= bindtest(cli, cmdline_credentials, torture->lp_ctx, DCERPC_AUTH_TYPE_NTLMSSP,
305 DCERPC_AUTH_LEVEL_PRIVACY);
306 ret &= bindtest(cli, cmdline_credentials, torture->lp_ctx, DCERPC_AUTH_TYPE_SPNEGO,
307 DCERPC_AUTH_LEVEL_INTEGRITY);
308 ret &= bindtest(cli, cmdline_credentials, torture->lp_ctx, DCERPC_AUTH_TYPE_SPNEGO,
309 DCERPC_AUTH_LEVEL_PRIVACY);
312 talloc_free(mem_ctx);
317 * Lookup or create a user and return all necessary info
320 static NTSTATUS get_usr_handle(struct smbcli_state *cli,
322 struct loadparm_context *lp_ctx,
323 struct cli_credentials *admin_creds,
326 const char *username,
328 struct dcerpc_pipe **result_pipe,
329 struct policy_handle **result_handle,
330 struct dom_sid **sid)
332 struct dcerpc_pipe *samr_pipe;
334 struct policy_handle conn_handle;
335 struct policy_handle domain_handle;
336 struct policy_handle *user_handle;
337 struct samr_Connect2 conn;
338 struct samr_EnumDomains enumdom;
339 uint32_t resume_handle = 0;
340 struct samr_LookupDomain l;
342 struct lsa_String domain_name;
343 struct lsa_String user_name;
344 struct samr_OpenDomain o;
345 struct samr_CreateUser2 c;
346 uint32_t user_rid,access_granted;
348 samr_pipe = dcerpc_pipe_init(mem_ctx,
349 cli->transport->socket->event.ctx);
350 if (samr_pipe == NULL) {
351 d_printf("dcerpc_pipe_init failed\n");
352 status = NT_STATUS_NO_MEMORY;
356 status = dcerpc_pipe_open_smb(samr_pipe, cli->tree, "\\samr");
357 if (!NT_STATUS_IS_OK(status)) {
358 d_printf("dcerpc_pipe_open_smb failed: %s\n",
363 if (admin_creds != NULL) {
364 status = dcerpc_bind_auth(samr_pipe, &ndr_table_samr,
365 admin_creds, lp_ctx, auth_type, auth_level,
367 if (!NT_STATUS_IS_OK(status)) {
368 d_printf("dcerpc_bind_auth failed: %s\n",
373 /* We must have an authenticated SMB connection */
374 status = dcerpc_bind_auth_none(samr_pipe, &ndr_table_samr);
375 if (!NT_STATUS_IS_OK(status)) {
376 d_printf("dcerpc_bind_auth_none failed: %s\n",
382 conn.in.system_name = talloc_asprintf(
383 mem_ctx, "\\\\%s", dcerpc_server_name(samr_pipe));
384 conn.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
385 conn.out.connect_handle = &conn_handle;
387 status = dcerpc_samr_Connect2(samr_pipe, mem_ctx, &conn);
388 if (!NT_STATUS_IS_OK(status)) {
389 d_printf("samr_Connect2 failed: %s\n", nt_errstr(status));
393 enumdom.in.connect_handle = &conn_handle;
394 enumdom.in.resume_handle = &resume_handle;
395 enumdom.in.buf_size = (uint32_t)-1;
396 enumdom.out.resume_handle = &resume_handle;
398 status = dcerpc_samr_EnumDomains(samr_pipe, mem_ctx, &enumdom);
399 if (!NT_STATUS_IS_OK(status)) {
400 d_printf("samr_EnumDomains failed: %s\n", nt_errstr(status));
404 if (enumdom.out.num_entries != 2) {
405 d_printf("samr_EnumDomains returned %d entries, expected 2\n",
406 enumdom.out.num_entries);
407 status = NT_STATUS_UNSUCCESSFUL;
411 dom_idx = strequal(enumdom.out.sam->entries[0].name.string,
414 l.in.connect_handle = &conn_handle;
415 domain_name.string = enumdom.out.sam->entries[0].name.string;
416 *domain = talloc_strdup(mem_ctx, domain_name.string);
417 l.in.domain_name = &domain_name;
419 status = dcerpc_samr_LookupDomain(samr_pipe, mem_ctx, &l);
420 if (!NT_STATUS_IS_OK(status)) {
421 d_printf("samr_LookupDomain failed: %s\n", nt_errstr(status));
425 o.in.connect_handle = &conn_handle;
426 o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
427 o.in.sid = l.out.sid;
428 o.out.domain_handle = &domain_handle;
430 status = dcerpc_samr_OpenDomain(samr_pipe, mem_ctx, &o);
431 if (!NT_STATUS_IS_OK(status)) {
432 d_printf("samr_OpenDomain failed: %s\n", nt_errstr(status));
436 c.in.domain_handle = &domain_handle;
437 user_name.string = username;
438 c.in.account_name = &user_name;
439 c.in.acct_flags = ACB_NORMAL;
440 c.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
441 user_handle = talloc(mem_ctx, struct policy_handle);
442 c.out.user_handle = user_handle;
443 c.out.access_granted = &access_granted;
444 c.out.rid = &user_rid;
446 status = dcerpc_samr_CreateUser2(samr_pipe, mem_ctx, &c);
448 if (NT_STATUS_EQUAL(status, NT_STATUS_USER_EXISTS)) {
449 struct samr_LookupNames ln;
450 struct samr_OpenUser ou;
452 ln.in.domain_handle = &domain_handle;
454 ln.in.names = &user_name;
456 status = dcerpc_samr_LookupNames(samr_pipe, mem_ctx, &ln);
457 if (!NT_STATUS_IS_OK(status)) {
458 d_printf("samr_LookupNames failed: %s\n",
463 ou.in.domain_handle = &domain_handle;
464 ou.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
465 user_rid = ou.in.rid = ln.out.rids.ids[0];
466 ou.out.user_handle = user_handle;
468 status = dcerpc_samr_OpenUser(samr_pipe, mem_ctx, &ou);
469 if (!NT_STATUS_IS_OK(status)) {
470 d_printf("samr_OpenUser failed: %s\n",
476 if (!NT_STATUS_IS_OK(status)) {
477 d_printf("samr_CreateUser failed: %s\n", nt_errstr(status));
481 *result_pipe = samr_pipe;
482 *result_handle = user_handle;
484 *sid = dom_sid_add_rid(mem_ctx, l.out.sid, user_rid);
496 static bool create_user(TALLOC_CTX *mem_ctx, struct smbcli_state *cli,
497 struct loadparm_context *lp_ctx,
498 struct cli_credentials *admin_creds,
499 const char *username, const char *password,
501 struct dom_sid **user_sid)
505 struct dcerpc_pipe *samr_pipe;
506 struct policy_handle *wks_handle;
509 if (!(tmp_ctx = talloc_new(mem_ctx))) {
510 d_printf("talloc_init failed\n");
514 status = get_usr_handle(cli, tmp_ctx, lp_ctx, admin_creds,
515 DCERPC_AUTH_TYPE_NTLMSSP,
516 DCERPC_AUTH_LEVEL_INTEGRITY,
517 username, domain_name, &samr_pipe, &wks_handle,
519 if (!NT_STATUS_IS_OK(status)) {
520 d_printf("get_wks_handle failed: %s\n", nt_errstr(status));
525 struct samr_SetUserInfo2 sui2;
526 struct samr_SetUserInfo sui;
527 struct samr_QueryUserInfo qui;
528 union samr_UserInfo u_info;
529 DATA_BLOB session_key;
533 encode_pw_buffer(u_info.info23.password.data, password,
536 status = dcerpc_fetch_session_key(samr_pipe, &session_key);
537 if (!NT_STATUS_IS_OK(status)) {
538 d_printf("dcerpc_fetch_session_key failed\n");
541 arcfour_crypt_blob(u_info.info23.password.data, 516,
543 u_info.info23.info.password_expired = 0;
544 u_info.info23.info.fields_present = SAMR_FIELD_PASSWORD |
545 SAMR_FIELD_PASSWORD2 |
546 SAMR_FIELD_EXPIRED_FLAG;
547 sui2.in.user_handle = wks_handle;
548 sui2.in.info = &u_info;
551 status = dcerpc_samr_SetUserInfo2(samr_pipe, tmp_ctx, &sui2);
552 if (!NT_STATUS_IS_OK(status)) {
553 d_printf("samr_SetUserInfo(23) failed: %s\n",
558 u_info.info16.acct_flags = ACB_NORMAL;
559 sui.in.user_handle = wks_handle;
560 sui.in.info = &u_info;
563 status = dcerpc_samr_SetUserInfo(samr_pipe, tmp_ctx, &sui);
564 if (!NT_STATUS_IS_OK(status)) {
565 d_printf("samr_SetUserInfo(16) failed\n");
569 qui.in.user_handle = wks_handle;
572 status = dcerpc_samr_QueryUserInfo(samr_pipe, tmp_ctx, &qui);
573 if (!NT_STATUS_IS_OK(status)) {
574 d_printf("samr_QueryUserInfo(21) failed\n");
578 qui.out.info->info21.allow_password_change = 0;
579 qui.out.info->info21.force_password_change = 0;
580 qui.out.info->info21.account_name.string = NULL;
581 qui.out.info->info21.rid = 0;
582 qui.out.info->info21.acct_expiry = 0;
583 qui.out.info->info21.fields_present = 0x81827fa; /* copy usrmgr.exe */
585 u_info.info21 = qui.out.info->info21;
586 sui.in.user_handle = wks_handle;
587 sui.in.info = &u_info;
590 status = dcerpc_samr_SetUserInfo(samr_pipe, tmp_ctx, &sui);
591 if (!NT_STATUS_IS_OK(status)) {
592 d_printf("samr_SetUserInfo(21) failed\n");
597 *domain_name= talloc_steal(mem_ctx, *domain_name);
598 *user_sid = talloc_steal(mem_ctx, *user_sid);
601 talloc_free(tmp_ctx);
609 static bool delete_user(struct smbcli_state *cli,
610 struct loadparm_context *lp_ctx,
611 struct cli_credentials *admin_creds,
612 const char *username)
617 struct dcerpc_pipe *samr_pipe;
618 struct policy_handle *user_handle;
621 if ((mem_ctx = talloc_init("leave")) == NULL) {
622 d_printf("talloc_init failed\n");
626 status = get_usr_handle(cli, mem_ctx, lp_ctx, admin_creds,
627 DCERPC_AUTH_TYPE_NTLMSSP,
628 DCERPC_AUTH_LEVEL_INTEGRITY,
629 username, &dom_name, &samr_pipe,
632 if (!NT_STATUS_IS_OK(status)) {
633 d_printf("get_wks_handle failed: %s\n", nt_errstr(status));
638 struct samr_DeleteUser d;
640 d.in.user_handle = user_handle;
641 d.out.user_handle = user_handle;
643 status = dcerpc_samr_DeleteUser(samr_pipe, mem_ctx, &d);
644 if (!NT_STATUS_IS_OK(status)) {
645 d_printf("samr_DeleteUser failed %s\n", nt_errstr(status));
653 talloc_free(mem_ctx);
658 * Do a Samba3-style join
661 static bool join3(struct smbcli_state *cli,
662 struct loadparm_context *lp_ctx,
664 struct cli_credentials *admin_creds,
665 struct cli_credentials *wks_creds)
670 struct dcerpc_pipe *samr_pipe;
671 struct policy_handle *wks_handle;
674 if ((mem_ctx = talloc_init("join3")) == NULL) {
675 d_printf("talloc_init failed\n");
679 status = get_usr_handle(
680 cli, mem_ctx, lp_ctx, admin_creds,
681 DCERPC_AUTH_TYPE_NTLMSSP,
682 DCERPC_AUTH_LEVEL_PRIVACY,
683 talloc_asprintf(mem_ctx, "%s$",
684 cli_credentials_get_workstation(wks_creds)),
685 &dom_name, &samr_pipe, &wks_handle, NULL);
687 if (!NT_STATUS_IS_OK(status)) {
688 d_printf("get_wks_handle failed: %s\n", nt_errstr(status));
692 cli_credentials_set_domain(wks_creds, dom_name, CRED_SPECIFIED);
695 struct samr_SetUserInfo2 sui2;
696 union samr_UserInfo u_info;
697 struct samr_UserInfo21 *i21 = &u_info.info25.info;
698 DATA_BLOB session_key;
699 DATA_BLOB confounded_session_key = data_blob_talloc(
701 struct MD5Context ctx;
702 uint8_t confounder[16];
706 i21->full_name.string = talloc_asprintf(
708 cli_credentials_get_workstation(wks_creds));
709 i21->acct_flags = ACB_WSTRUST;
710 i21->fields_present = SAMR_FIELD_FULL_NAME |
711 SAMR_FIELD_ACCT_FLAGS | SAMR_FIELD_PASSWORD;
713 encode_pw_buffer(u_info.info25.password.data,
714 cli_credentials_get_password(wks_creds),
716 status = dcerpc_fetch_session_key(samr_pipe, &session_key);
717 if (!NT_STATUS_IS_OK(status)) {
718 d_printf("dcerpc_fetch_session_key failed: %s\n",
722 generate_random_buffer((uint8_t *)confounder, 16);
725 MD5Update(&ctx, confounder, 16);
726 MD5Update(&ctx, session_key.data, session_key.length);
727 MD5Final(confounded_session_key.data, &ctx);
729 arcfour_crypt_blob(u_info.info25.password.data, 516,
730 &confounded_session_key);
731 memcpy(&u_info.info25.password.data[516], confounder, 16);
733 sui2.in.user_handle = wks_handle;
735 sui2.in.info = &u_info;
737 status = dcerpc_samr_SetUserInfo2(samr_pipe, mem_ctx, &sui2);
738 if (!NT_STATUS_IS_OK(status)) {
739 d_printf("samr_SetUserInfo2(25) failed: %s\n",
744 struct samr_SetUserInfo2 sui2;
745 struct samr_SetUserInfo sui;
746 union samr_UserInfo u_info;
747 DATA_BLOB session_key;
749 encode_pw_buffer(u_info.info24.password.data,
750 cli_credentials_get_password(wks_creds),
752 u_info.info24.pw_len =
753 strlen_m(cli_credentials_get_password(wks_creds))*2;
755 status = dcerpc_fetch_session_key(samr_pipe, &session_key);
756 if (!NT_STATUS_IS_OK(status)) {
757 d_printf("dcerpc_fetch_session_key failed\n");
760 arcfour_crypt_blob(u_info.info24.password.data, 516,
762 sui2.in.user_handle = wks_handle;
763 sui2.in.info = &u_info;
766 status = dcerpc_samr_SetUserInfo2(samr_pipe, mem_ctx, &sui2);
767 if (!NT_STATUS_IS_OK(status)) {
768 d_printf("samr_SetUserInfo(24) failed: %s\n",
773 u_info.info16.acct_flags = ACB_WSTRUST;
774 sui.in.user_handle = wks_handle;
775 sui.in.info = &u_info;
778 status = dcerpc_samr_SetUserInfo(samr_pipe, mem_ctx, &sui);
779 if (!NT_STATUS_IS_OK(status)) {
780 d_printf("samr_SetUserInfo(16) failed\n");
788 talloc_free(mem_ctx);
793 * Do a ReqChallenge/Auth2 and get the wks creds
796 static bool auth2(struct smbcli_state *cli,
797 struct cli_credentials *wks_cred)
800 struct dcerpc_pipe *net_pipe;
803 struct netr_ServerReqChallenge r;
804 struct netr_Credential netr_cli_creds;
805 struct netr_Credential netr_srv_creds;
806 uint32_t negotiate_flags;
807 struct netr_ServerAuthenticate2 a;
808 struct creds_CredentialState *creds_state;
809 struct netr_Credential netr_cred;
810 struct samr_Password mach_pw;
812 mem_ctx = talloc_new(NULL);
813 if (mem_ctx == NULL) {
814 d_printf("talloc_new failed\n");
818 net_pipe = dcerpc_pipe_init(mem_ctx,
819 cli->transport->socket->event.ctx);
820 if (net_pipe == NULL) {
821 d_printf("dcerpc_pipe_init failed\n");
825 status = dcerpc_pipe_open_smb(net_pipe, cli->tree, "\\netlogon");
826 if (!NT_STATUS_IS_OK(status)) {
827 d_printf("dcerpc_pipe_open_smb failed: %s\n",
832 status = dcerpc_bind_auth_none(net_pipe, &ndr_table_netlogon);
833 if (!NT_STATUS_IS_OK(status)) {
834 d_printf("dcerpc_bind_auth_none failed: %s\n",
839 r.in.computer_name = cli_credentials_get_workstation(wks_cred);
840 r.in.server_name = talloc_asprintf(
841 mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
842 if (r.in.server_name == NULL) {
843 d_printf("talloc_asprintf failed\n");
846 generate_random_buffer(netr_cli_creds.data,
847 sizeof(netr_cli_creds.data));
848 r.in.credentials = &netr_cli_creds;
849 r.out.credentials = &netr_srv_creds;
851 status = dcerpc_netr_ServerReqChallenge(net_pipe, mem_ctx, &r);
852 if (!NT_STATUS_IS_OK(status)) {
853 d_printf("netr_ServerReqChallenge failed: %s\n",
858 negotiate_flags = NETLOGON_NEG_AUTH2_FLAGS;
859 E_md4hash(cli_credentials_get_password(wks_cred), mach_pw.hash);
861 creds_state = talloc(mem_ctx, struct creds_CredentialState);
862 creds_client_init(creds_state, r.in.credentials,
863 r.out.credentials, &mach_pw,
864 &netr_cred, negotiate_flags);
866 a.in.server_name = talloc_asprintf(
867 mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
868 a.in.account_name = talloc_asprintf(
869 mem_ctx, "%s$", cli_credentials_get_workstation(wks_cred));
870 a.in.computer_name = cli_credentials_get_workstation(wks_cred);
871 a.in.secure_channel_type = SEC_CHAN_WKSTA;
872 a.in.negotiate_flags = &negotiate_flags;
873 a.out.negotiate_flags = &negotiate_flags;
874 a.in.credentials = &netr_cred;
875 a.out.credentials = &netr_cred;
877 status = dcerpc_netr_ServerAuthenticate2(net_pipe, mem_ctx, &a);
878 if (!NT_STATUS_IS_OK(status)) {
879 d_printf("netr_ServerServerAuthenticate2 failed: %s\n",
884 if (!creds_client_check(creds_state, a.out.credentials)) {
885 d_printf("creds_client_check failed\n");
889 cli_credentials_set_netlogon_creds(wks_cred, creds_state);
894 talloc_free(mem_ctx);
899 * Do a couple of schannel protected Netlogon ops: Interactive and Network
900 * login, and change the wks password
903 static bool schan(struct smbcli_state *cli,
904 struct loadparm_context *lp_ctx,
905 struct cli_credentials *wks_creds,
906 struct cli_credentials *user_creds)
911 struct dcerpc_pipe *net_pipe;
914 mem_ctx = talloc_new(NULL);
915 if (mem_ctx == NULL) {
916 d_printf("talloc_new failed\n");
920 net_pipe = dcerpc_pipe_init(mem_ctx,
921 cli->transport->socket->event.ctx);
922 if (net_pipe == NULL) {
923 d_printf("dcerpc_pipe_init failed\n");
927 status = dcerpc_pipe_open_smb(net_pipe, cli->tree, "\\netlogon");
928 if (!NT_STATUS_IS_OK(status)) {
929 d_printf("dcerpc_pipe_open_smb failed: %s\n",
935 net_pipe->conn->flags |= DCERPC_DEBUG_PRINT_IN |
936 DCERPC_DEBUG_PRINT_OUT;
939 net_pipe->conn->flags |= (DCERPC_SIGN | DCERPC_SEAL);
940 status = dcerpc_bind_auth(net_pipe, &ndr_table_netlogon,
941 wks_creds, lp_ctx, DCERPC_AUTH_TYPE_SCHANNEL,
942 DCERPC_AUTH_LEVEL_PRIVACY,
945 status = dcerpc_bind_auth_none(net_pipe, &ndr_table_netlogon);
947 if (!NT_STATUS_IS_OK(status)) {
948 d_printf("schannel bind failed: %s\n", nt_errstr(status));
953 for (i=2; i<4; i++) {
955 DATA_BLOB chal, nt_resp, lm_resp, names_blob, session_key;
956 struct creds_CredentialState *creds_state;
957 struct netr_Authenticator netr_auth, netr_auth2;
958 struct netr_NetworkInfo ninfo;
959 struct netr_PasswordInfo pinfo;
960 struct netr_LogonSamLogon r;
962 flags = CLI_CRED_LANMAN_AUTH | CLI_CRED_NTLM_AUTH |
963 CLI_CRED_NTLMv2_AUTH;
965 chal = data_blob_talloc(mem_ctx, NULL, 8);
966 if (chal.data == NULL) {
967 d_printf("data_blob_talloc failed\n");
971 generate_random_buffer(chal.data, chal.length);
972 names_blob = NTLMv2_generate_names_blob(
973 mem_ctx, cli_credentials_get_workstation(user_creds),
974 cli_credentials_get_domain(user_creds));
975 status = cli_credentials_get_ntlm_response(
976 user_creds, mem_ctx, &flags, chal, names_blob,
977 &lm_resp, &nt_resp, NULL, NULL);
978 if (!NT_STATUS_IS_OK(status)) {
979 d_printf("cli_credentials_get_ntlm_response failed:"
980 " %s\n", nt_errstr(status));
984 creds_state = cli_credentials_get_netlogon_creds(wks_creds);
985 creds_client_authenticator(creds_state, &netr_auth);
987 ninfo.identity_info.account_name.string =
988 cli_credentials_get_username(user_creds);
989 ninfo.identity_info.domain_name.string =
990 cli_credentials_get_domain(user_creds);
991 ninfo.identity_info.parameter_control = 0;
992 ninfo.identity_info.logon_id_low = 0;
993 ninfo.identity_info.logon_id_high = 0;
994 ninfo.identity_info.workstation.string =
995 cli_credentials_get_workstation(user_creds);
996 memcpy(ninfo.challenge, chal.data, sizeof(ninfo.challenge));
997 ninfo.nt.length = nt_resp.length;
998 ninfo.nt.data = nt_resp.data;
999 ninfo.lm.length = lm_resp.length;
1000 ninfo.lm.data = lm_resp.data;
1002 r.in.server_name = talloc_asprintf(
1003 mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
1004 ZERO_STRUCT(netr_auth2);
1005 r.in.computer_name =
1006 cli_credentials_get_workstation(wks_creds);
1007 r.in.credential = &netr_auth;
1008 r.in.return_authenticator = &netr_auth2;
1009 r.in.logon_level = 2;
1010 r.in.validation_level = i;
1011 r.in.logon.network = &ninfo;
1012 r.out.return_authenticator = NULL;
1014 status = dcerpc_netr_LogonSamLogon(net_pipe, mem_ctx, &r);
1015 if (!NT_STATUS_IS_OK(status)) {
1016 d_printf("netr_LogonSamLogon failed: %s\n",
1021 if ((r.out.return_authenticator == NULL) ||
1022 (!creds_client_check(creds_state,
1023 &r.out.return_authenticator->cred))) {
1024 d_printf("Credentials check failed!\n");
1028 creds_client_authenticator(creds_state, &netr_auth);
1030 pinfo.identity_info = ninfo.identity_info;
1031 ZERO_STRUCT(pinfo.lmpassword.hash);
1032 E_md4hash(cli_credentials_get_password(user_creds),
1033 pinfo.ntpassword.hash);
1034 session_key = data_blob_talloc(mem_ctx,
1035 creds_state->session_key, 16);
1036 arcfour_crypt_blob(pinfo.ntpassword.hash,
1037 sizeof(pinfo.ntpassword.hash),
1040 r.in.logon_level = 1;
1041 r.in.logon.password = &pinfo;
1042 r.out.return_authenticator = NULL;
1044 status = dcerpc_netr_LogonSamLogon(net_pipe, mem_ctx, &r);
1045 if (!NT_STATUS_IS_OK(status)) {
1046 d_printf("netr_LogonSamLogon failed: %s\n",
1051 if ((r.out.return_authenticator == NULL) ||
1052 (!creds_client_check(creds_state,
1053 &r.out.return_authenticator->cred))) {
1054 d_printf("Credentials check failed!\n");
1060 struct netr_ServerPasswordSet s;
1061 char *password = generate_random_str(wks_creds, 8);
1062 struct creds_CredentialState *creds_state;
1064 s.in.server_name = talloc_asprintf(
1065 mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
1066 s.in.computer_name = cli_credentials_get_workstation(wks_creds);
1067 s.in.account_name = talloc_asprintf(
1068 mem_ctx, "%s$", s.in.computer_name);
1069 s.in.secure_channel_type = SEC_CHAN_WKSTA;
1070 E_md4hash(password, s.in.new_password.hash);
1072 creds_state = cli_credentials_get_netlogon_creds(wks_creds);
1073 creds_des_encrypt(creds_state, &s.in.new_password);
1074 creds_client_authenticator(creds_state, &s.in.credential);
1076 status = dcerpc_netr_ServerPasswordSet(net_pipe, mem_ctx, &s);
1077 if (!NT_STATUS_IS_OK(status)) {
1078 printf("ServerPasswordSet - %s\n", nt_errstr(status));
1082 if (!creds_client_check(creds_state,
1083 &s.out.return_authenticator.cred)) {
1084 printf("Credential chaining failed\n");
1087 cli_credentials_set_password(wks_creds, password,
1093 talloc_free(mem_ctx);
1098 * Delete the wks account again
1101 static bool leave(struct smbcli_state *cli,
1102 struct loadparm_context *lp_ctx,
1103 struct cli_credentials *admin_creds,
1104 struct cli_credentials *wks_creds)
1106 char *wks_name = talloc_asprintf(
1107 NULL, "%s$", cli_credentials_get_workstation(wks_creds));
1110 ret = delete_user(cli, lp_ctx, admin_creds, wks_name);
1111 talloc_free(wks_name);
1116 * Test the Samba3 DC code a bit. Join, do some schan netlogon ops, leave
1119 bool torture_netlogon_samba3(struct torture_context *torture)
1121 TALLOC_CTX *mem_ctx;
1124 struct smbcli_state *cli;
1125 struct cli_credentials *anon_creds;
1126 struct cli_credentials *wks_creds;
1127 const char *wks_name;
1130 wks_name = torture_setting_string(torture, "wksname", NULL);
1131 if (wks_name == NULL) {
1132 wks_name = get_myname();
1135 mem_ctx = talloc_init("torture_netlogon_samba3");
1137 if (mem_ctx == NULL) {
1138 d_printf("talloc_init failed\n");
1142 if (!(anon_creds = cli_credentials_init_anon(mem_ctx))) {
1143 d_printf("create_anon_creds failed\n");
1147 status = smbcli_full_connection(mem_ctx, &cli,
1148 torture_setting_string(torture, "host", NULL),
1149 lp_smb_ports(torture->lp_ctx),
1150 "IPC$", NULL, anon_creds, NULL);
1151 if (!NT_STATUS_IS_OK(status)) {
1152 d_printf("smbcli_full_connection failed: %s\n",
1157 wks_creds = cli_credentials_init(mem_ctx);
1158 if (wks_creds == NULL) {
1159 d_printf("cli_credentials_init failed\n");
1163 cli_credentials_set_conf(wks_creds, torture->lp_ctx);
1164 cli_credentials_set_secure_channel_type(wks_creds, SEC_CHAN_WKSTA);
1165 cli_credentials_set_username(wks_creds, wks_name, CRED_SPECIFIED);
1166 cli_credentials_set_workstation(wks_creds, wks_name, CRED_SPECIFIED);
1167 cli_credentials_set_password(wks_creds,
1168 generate_random_str(wks_creds, 8),
1171 if (!join3(cli, torture->lp_ctx, false, cmdline_credentials, wks_creds)) {
1172 d_printf("join failed\n");
1176 cli_credentials_set_domain(
1177 cmdline_credentials, cli_credentials_get_domain(wks_creds),
1180 for (i=0; i<2; i++) {
1182 /* Do this more than once, the routine "schan" changes
1183 * the workstation password using the netlogon
1184 * password change routine */
1188 if (!auth2(cli, wks_creds)) {
1189 d_printf("auth2 failed\n");
1193 for (j=0; j<2; j++) {
1194 if (!schan(cli, torture->lp_ctx, wks_creds, cmdline_credentials)) {
1195 d_printf("schan failed\n");
1201 if (!leave(cli, torture->lp_ctx, cmdline_credentials, wks_creds)) {
1202 d_printf("leave failed\n");
1209 talloc_free(mem_ctx);
1214 * Do a simple join, testjoin and leave using specified smb and samr
1218 static bool test_join3(struct torture_context *tctx,
1220 struct cli_credentials *smb_creds,
1221 struct cli_credentials *samr_creds,
1222 const char *wks_name)
1226 struct smbcli_state *cli;
1227 struct cli_credentials *wks_creds;
1229 status = smbcli_full_connection(tctx, &cli,
1230 torture_setting_string(tctx, "host", NULL),
1231 lp_smb_ports(tctx->lp_ctx),
1232 "IPC$", NULL, smb_creds, NULL);
1233 if (!NT_STATUS_IS_OK(status)) {
1234 d_printf("smbcli_full_connection failed: %s\n",
1239 wks_creds = cli_credentials_init(cli);
1240 if (wks_creds == NULL) {
1241 d_printf("cli_credentials_init failed\n");
1245 cli_credentials_set_conf(wks_creds, tctx->lp_ctx);
1246 cli_credentials_set_secure_channel_type(wks_creds, SEC_CHAN_WKSTA);
1247 cli_credentials_set_username(wks_creds, wks_name, CRED_SPECIFIED);
1248 cli_credentials_set_workstation(wks_creds, wks_name, CRED_SPECIFIED);
1249 cli_credentials_set_password(wks_creds,
1250 generate_random_str(wks_creds, 8),
1253 if (!join3(cli, tctx->lp_ctx, use_level25, samr_creds, wks_creds)) {
1254 d_printf("join failed\n");
1258 cli_credentials_set_domain(
1259 cmdline_credentials, cli_credentials_get_domain(wks_creds),
1262 if (!auth2(cli, wks_creds)) {
1263 d_printf("auth2 failed\n");
1267 if (!leave(cli, tctx->lp_ctx, samr_creds, wks_creds)) {
1268 d_printf("leave failed\n");
1281 * Test the different session key variants. Do it by joining, this uses the
1282 * session key in the setpassword routine. Test the join by doing the auth2.
1285 bool torture_samba3_sessionkey(struct torture_context *torture)
1288 struct cli_credentials *anon_creds;
1289 const char *wks_name;
1291 wks_name = torture_setting_string(torture, "wksname", get_myname());
1293 if (!(anon_creds = cli_credentials_init_anon(torture))) {
1294 d_printf("create_anon_creds failed\n");
1300 if (!torture_setting_bool(torture, "samba3", false)) {
1302 /* Samba3 in the build farm right now does this happily. Need
1305 if (test_join3(torture, false, anon_creds, NULL, wks_name)) {
1306 d_printf("join using anonymous bind on an anonymous smb "
1307 "connection succeeded -- HUH??\n");
1312 if (!test_join3(torture, false, anon_creds, cmdline_credentials,
1314 d_printf("join using ntlmssp bind on an anonymous smb "
1315 "connection failed\n");
1319 if (!test_join3(torture, false, cmdline_credentials, NULL, wks_name)) {
1320 d_printf("join using anonymous bind on an authenticated smb "
1321 "connection failed\n");
1325 if (!test_join3(torture, false, cmdline_credentials,
1326 cmdline_credentials,
1328 d_printf("join using ntlmssp bind on an authenticated smb "
1329 "connection failed\n");
1334 * The following two are tests for setuserinfolevel 25
1337 if (!test_join3(torture, true, anon_creds, cmdline_credentials,
1339 d_printf("join using ntlmssp bind on an anonymous smb "
1340 "connection failed\n");
1344 if (!test_join3(torture, true, cmdline_credentials, NULL, wks_name)) {
1345 d_printf("join using anonymous bind on an authenticated smb "
1346 "connection failed\n");
1356 * open pipe and bind, given an IPC$ context
1359 static NTSTATUS pipe_bind_smb(TALLOC_CTX *mem_ctx,
1360 struct smbcli_tree *tree,
1361 const char *pipe_name,
1362 const struct ndr_interface_table *iface,
1363 struct dcerpc_pipe **p)
1365 struct dcerpc_pipe *result;
1368 if (!(result = dcerpc_pipe_init(
1369 mem_ctx, tree->session->transport->socket->event.ctx))) {
1370 return NT_STATUS_NO_MEMORY;
1373 status = dcerpc_pipe_open_smb(result, tree, pipe_name);
1374 if (!NT_STATUS_IS_OK(status)) {
1375 d_printf("dcerpc_pipe_open_smb failed: %s\n",
1377 talloc_free(result);
1381 status = dcerpc_bind_auth_none(result, iface);
1382 if (!NT_STATUS_IS_OK(status)) {
1383 d_printf("schannel bind failed: %s\n", nt_errstr(status));
1384 talloc_free(result);
1389 return NT_STATUS_OK;
1393 * Sane wrapper around lsa_LookupNames
1396 static struct dom_sid *name2sid(TALLOC_CTX *mem_ctx,
1397 struct dcerpc_pipe *p,
1401 struct lsa_ObjectAttribute attr;
1402 struct lsa_QosInfo qos;
1403 struct lsa_OpenPolicy2 r;
1406 struct policy_handle handle;
1407 struct lsa_LookupNames l;
1408 struct lsa_TransSidArray sids;
1409 struct lsa_String lsa_name;
1411 struct dom_sid *result;
1412 TALLOC_CTX *tmp_ctx;
1414 if (!(tmp_ctx = talloc_new(mem_ctx))) {
1419 qos.impersonation_level = 2;
1420 qos.context_mode = 1;
1421 qos.effective_only = 0;
1424 attr.root_dir = NULL;
1425 attr.object_name = NULL;
1426 attr.attributes = 0;
1427 attr.sec_desc = NULL;
1428 attr.sec_qos = &qos;
1430 r.in.system_name = "\\";
1432 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1433 r.out.handle = &handle;
1435 status = dcerpc_lsa_OpenPolicy2(p, tmp_ctx, &r);
1436 if (!NT_STATUS_IS_OK(status)) {
1437 printf("OpenPolicy2 failed - %s\n", nt_errstr(status));
1438 talloc_free(tmp_ctx);
1445 lsa_name.string = talloc_asprintf(tmp_ctx, "%s\\%s", domain, name);
1447 l.in.handle = &handle;
1449 l.in.names = &lsa_name;
1452 l.in.count = &count;
1453 l.out.count = &count;
1456 status = dcerpc_lsa_LookupNames(p, tmp_ctx, &l);
1457 if (!NT_STATUS_IS_OK(status)) {
1458 printf("LookupNames of %s failed - %s\n", lsa_name.string,
1460 talloc_free(tmp_ctx);
1464 result = dom_sid_add_rid(mem_ctx, l.out.domains->domains[0].sid,
1465 l.out.sids->sids[0].rid);
1467 c.in.handle = &handle;
1468 c.out.handle = &handle;
1470 status = dcerpc_lsa_Close(p, tmp_ctx, &c);
1471 if (!NT_STATUS_IS_OK(status)) {
1472 printf("dcerpc_lsa_Close failed - %s\n", nt_errstr(status));
1473 talloc_free(tmp_ctx);
1477 talloc_free(tmp_ctx);
1482 * Find out the user SID on this connection
1485 static struct dom_sid *whoami(TALLOC_CTX *mem_ctx, struct smbcli_tree *tree)
1487 struct dcerpc_pipe *lsa;
1488 struct lsa_GetUserName r;
1490 struct lsa_StringPointer authority_name_p;
1491 struct dom_sid *result;
1493 status = pipe_bind_smb(mem_ctx, tree, "\\pipe\\lsarpc",
1494 &ndr_table_lsarpc, &lsa);
1495 if (!NT_STATUS_IS_OK(status)) {
1496 d_printf("(%s) Could not bind to LSA: %s\n",
1497 __location__, nt_errstr(status));
1501 r.in.system_name = "\\";
1502 r.in.account_name = NULL;
1503 authority_name_p.string = NULL;
1504 r.in.authority_name = &authority_name_p;
1506 status = dcerpc_lsa_GetUserName(lsa, mem_ctx, &r);
1508 if (!NT_STATUS_IS_OK(status)) {
1509 printf("(%s) GetUserName failed - %s\n",
1510 __location__, nt_errstr(status));
1515 result = name2sid(mem_ctx, lsa, r.out.account_name->string,
1516 r.out.authority_name->string->string);
1522 static int destroy_tree(struct smbcli_tree *tree)
1524 smb_tree_disconnect(tree);
1529 * Do a tcon, given a session
1532 NTSTATUS secondary_tcon(TALLOC_CTX *mem_ctx,
1533 struct smbcli_session *session,
1534 const char *sharename,
1535 struct smbcli_tree **res)
1537 struct smbcli_tree *result;
1538 TALLOC_CTX *tmp_ctx;
1539 union smb_tcon tcon;
1542 if (!(tmp_ctx = talloc_new(mem_ctx))) {
1543 return NT_STATUS_NO_MEMORY;
1546 if (!(result = smbcli_tree_init(session, mem_ctx, false))) {
1547 talloc_free(tmp_ctx);
1548 return NT_STATUS_NO_MEMORY;
1551 tcon.generic.level = RAW_TCON_TCONX;
1552 tcon.tconx.in.flags = 0;
1553 tcon.tconx.in.password = data_blob(NULL, 0);
1554 tcon.tconx.in.path = sharename;
1555 tcon.tconx.in.device = "?????";
1557 status = smb_raw_tcon(result, tmp_ctx, &tcon);
1558 if (!NT_STATUS_IS_OK(status)) {
1559 d_printf("(%s) smb_raw_tcon failed: %s\n", __location__,
1561 talloc_free(tmp_ctx);
1565 result->tid = tcon.tconx.out.tid;
1566 result = talloc_steal(mem_ctx, result);
1567 talloc_set_destructor(result, destroy_tree);
1568 talloc_free(tmp_ctx);
1570 return NT_STATUS_OK;
1574 * Test the getusername behaviour
1577 bool torture_samba3_rpc_getusername(struct torture_context *torture)
1580 struct smbcli_state *cli;
1581 TALLOC_CTX *mem_ctx;
1583 struct dom_sid *user_sid;
1584 struct dom_sid *created_sid;
1585 struct cli_credentials *anon_creds;
1586 struct cli_credentials *user_creds;
1589 if (!(mem_ctx = talloc_new(torture))) {
1593 status = smbcli_full_connection(
1594 mem_ctx, &cli, torture_setting_string(torture, "host", NULL),
1595 lp_smb_ports(torture->lp_ctx),
1596 "IPC$", NULL, cmdline_credentials, NULL);
1597 if (!NT_STATUS_IS_OK(status)) {
1598 d_printf("(%s) smbcli_full_connection failed: %s\n",
1599 __location__, nt_errstr(status));
1604 if (!(user_sid = whoami(mem_ctx, cli->tree))) {
1605 d_printf("(%s) whoami on auth'ed connection failed\n",
1612 if (!(anon_creds = cli_credentials_init_anon(mem_ctx))) {
1613 d_printf("(%s) create_anon_creds failed\n", __location__);
1618 status = smbcli_full_connection(
1619 mem_ctx, &cli, torture_setting_string(torture, "host", NULL),
1620 lp_smb_ports(torture->lp_ctx),
1621 "IPC$", NULL, anon_creds, NULL);
1622 if (!NT_STATUS_IS_OK(status)) {
1623 d_printf("(%s) anon smbcli_full_connection failed: %s\n",
1624 __location__, nt_errstr(status));
1629 if (!(user_sid = whoami(mem_ctx, cli->tree))) {
1630 d_printf("(%s) whoami on anon connection failed\n",
1636 if (!dom_sid_equal(user_sid,
1637 dom_sid_parse_talloc(mem_ctx, "s-1-5-7"))) {
1638 d_printf("(%s) Anon lsa_GetUserName returned %s, expected "
1639 "S-1-5-7", __location__,
1640 dom_sid_string(mem_ctx, user_sid));
1644 if (!(user_creds = cli_credentials_init(mem_ctx))) {
1645 d_printf("(%s) cli_credentials_init failed\n", __location__);
1650 cli_credentials_set_conf(user_creds, torture->lp_ctx);
1651 cli_credentials_set_username(user_creds, "torture_username",
1653 cli_credentials_set_password(user_creds,
1654 generate_random_str(user_creds, 8),
1657 if (!create_user(mem_ctx, cli, torture->lp_ctx, cmdline_credentials,
1658 cli_credentials_get_username(user_creds),
1659 cli_credentials_get_password(user_creds),
1660 &domain_name, &created_sid)) {
1661 d_printf("(%s) create_user failed\n", __location__);
1666 cli_credentials_set_domain(user_creds, domain_name,
1670 struct smbcli_session *session2;
1671 struct smb_composite_sesssetup setup;
1672 struct smbcli_tree *tree;
1674 session2 = smbcli_session_init(cli->transport, mem_ctx, false);
1675 if (session2 == NULL) {
1676 d_printf("(%s) smbcli_session_init failed\n",
1681 setup.in.sesskey = cli->transport->negotiate.sesskey;
1682 setup.in.capabilities = cli->transport->negotiate.capabilities;
1683 setup.in.workgroup = "";
1684 setup.in.credentials = user_creds;
1686 status = smb_composite_sesssetup(session2, &setup);
1687 if (!NT_STATUS_IS_OK(status)) {
1688 d_printf("(%s) session setup with new user failed: "
1689 "%s\n", __location__, nt_errstr(status));
1693 session2->vuid = setup.out.vuid;
1695 if (!NT_STATUS_IS_OK(secondary_tcon(mem_ctx, session2,
1697 d_printf("(%s) secondary_tcon failed\n",
1703 if (!(user_sid = whoami(mem_ctx, tree))) {
1704 d_printf("(%s) whoami on user connection failed\n",
1713 d_printf("Created %s, found %s\n",
1714 dom_sid_string(mem_ctx, created_sid),
1715 dom_sid_string(mem_ctx, user_sid));
1717 if (!dom_sid_equal(created_sid, user_sid)) {
1722 if (!delete_user(cli, torture->lp_ctx,
1723 cmdline_credentials,
1724 cli_credentials_get_username(user_creds))) {
1725 d_printf("(%s) delete_user failed\n", __location__);
1730 talloc_free(mem_ctx);
1734 static bool test_NetShareGetInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
1735 const char *sharename)
1738 struct srvsvc_NetShareGetInfo r;
1739 uint32_t levels[] = { 0, 1, 2, 501, 502, 1004, 1005, 1006, 1007, 1501 };
1743 r.in.server_unc = talloc_asprintf(mem_ctx, "\\\\%s",
1744 dcerpc_server_name(p));
1745 r.in.share_name = sharename;
1747 for (i=0;i<ARRAY_SIZE(levels);i++) {
1748 r.in.level = levels[i];
1752 printf("testing NetShareGetInfo level %u on share '%s'\n",
1753 r.in.level, r.in.share_name);
1755 status = dcerpc_srvsvc_NetShareGetInfo(p, mem_ctx, &r);
1756 if (!NT_STATUS_IS_OK(status)) {
1757 printf("NetShareGetInfo level %u on share '%s' failed"
1758 " - %s\n", r.in.level, r.in.share_name,
1763 if (!W_ERROR_IS_OK(r.out.result)) {
1764 printf("NetShareGetInfo level %u on share '%s' failed "
1765 "- %s\n", r.in.level, r.in.share_name,
1766 win_errstr(r.out.result));
1775 static bool test_NetShareEnum(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
1776 const char **one_sharename)
1779 struct srvsvc_NetShareEnum r;
1780 struct srvsvc_NetShareCtr0 c0;
1781 uint32_t levels[] = { 0, 1, 2, 501, 502, 1004, 1005, 1006, 1007 };
1785 r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
1786 r.in.ctr.ctr0 = &c0;
1787 r.in.ctr.ctr0->count = 0;
1788 r.in.ctr.ctr0->array = NULL;
1789 r.in.max_buffer = (uint32_t)-1;
1790 r.in.resume_handle = NULL;
1792 for (i=0;i<ARRAY_SIZE(levels);i++) {
1793 r.in.level = levels[i];
1797 printf("testing NetShareEnum level %u\n", r.in.level);
1798 status = dcerpc_srvsvc_NetShareEnum(p, mem_ctx, &r);
1799 if (!NT_STATUS_IS_OK(status)) {
1800 printf("NetShareEnum level %u failed - %s\n",
1801 r.in.level, nt_errstr(status));
1805 if (!W_ERROR_IS_OK(r.out.result)) {
1806 printf("NetShareEnum level %u failed - %s\n",
1807 r.in.level, win_errstr(r.out.result));
1810 if (r.in.level == 0) {
1811 struct srvsvc_NetShareCtr0 *ctr = r.out.ctr.ctr0;
1812 if (ctr->count > 0) {
1813 *one_sharename = ctr->array[0].name;
1821 bool torture_samba3_rpc_srvsvc(struct torture_context *torture)
1823 struct dcerpc_pipe *p;
1824 TALLOC_CTX *mem_ctx;
1826 const char *sharename = NULL;
1827 struct smbcli_state *cli;
1830 if (!(mem_ctx = talloc_new(torture))) {
1834 if (!(torture_open_connection_share(
1835 mem_ctx, &cli, torture, torture_setting_string(torture, "host", NULL),
1837 talloc_free(mem_ctx);
1841 status = pipe_bind_smb(mem_ctx, cli->tree, "\\pipe\\srvsvc",
1842 &ndr_table_srvsvc, &p);
1843 if (!NT_STATUS_IS_OK(status)) {
1844 d_printf("(%s) could not bind to srvsvc pipe: %s\n",
1845 __location__, nt_errstr(status));
1850 ret &= test_NetShareEnum(p, mem_ctx, &sharename);
1851 if (sharename == NULL) {
1852 printf("did not get sharename\n");
1854 ret &= test_NetShareGetInfo(p, mem_ctx, sharename);
1858 talloc_free(mem_ctx);
1863 * Do a ReqChallenge/Auth2 with a random wks name, make sure it returns
1864 * NT_STATUS_NO_SAM_ACCOUNT
1867 bool torture_samba3_rpc_randomauth2(struct torture_context *torture)
1869 TALLOC_CTX *mem_ctx;
1870 struct dcerpc_pipe *net_pipe;
1872 bool result = false;
1874 struct netr_ServerReqChallenge r;
1875 struct netr_Credential netr_cli_creds;
1876 struct netr_Credential netr_srv_creds;
1877 uint32_t negotiate_flags;
1878 struct netr_ServerAuthenticate2 a;
1879 struct creds_CredentialState *creds_state;
1880 struct netr_Credential netr_cred;
1881 struct samr_Password mach_pw;
1882 struct smbcli_state *cli;
1884 if (!(mem_ctx = talloc_new(torture))) {
1885 d_printf("talloc_new failed\n");
1889 if (!(wksname = generate_random_str_list(
1890 mem_ctx, 14, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"))) {
1891 d_printf("generate_random_str_list failed\n");
1895 if (!(torture_open_connection_share(
1897 torture, torture_setting_string(torture, "host", NULL),
1899 d_printf("IPC$ connection failed\n");
1903 if (!(net_pipe = dcerpc_pipe_init(
1904 mem_ctx, cli->transport->socket->event.ctx))) {
1905 d_printf("dcerpc_pipe_init failed\n");
1909 status = dcerpc_pipe_open_smb(net_pipe, cli->tree, "\\netlogon");
1910 if (!NT_STATUS_IS_OK(status)) {
1911 d_printf("dcerpc_pipe_open_smb failed: %s\n",
1916 status = dcerpc_bind_auth_none(net_pipe, &ndr_table_netlogon);
1917 if (!NT_STATUS_IS_OK(status)) {
1918 d_printf("dcerpc_bind_auth_none failed: %s\n",
1923 r.in.computer_name = wksname;
1924 r.in.server_name = talloc_asprintf(
1925 mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
1926 if (r.in.server_name == NULL) {
1927 d_printf("talloc_asprintf failed\n");
1930 generate_random_buffer(netr_cli_creds.data,
1931 sizeof(netr_cli_creds.data));
1932 r.in.credentials = &netr_cli_creds;
1933 r.out.credentials = &netr_srv_creds;
1935 status = dcerpc_netr_ServerReqChallenge(net_pipe, mem_ctx, &r);
1936 if (!NT_STATUS_IS_OK(status)) {
1937 d_printf("netr_ServerReqChallenge failed: %s\n",
1942 negotiate_flags = NETLOGON_NEG_AUTH2_FLAGS;
1943 E_md4hash("foobar", mach_pw.hash);
1945 creds_state = talloc(mem_ctx, struct creds_CredentialState);
1946 creds_client_init(creds_state, r.in.credentials,
1947 r.out.credentials, &mach_pw,
1948 &netr_cred, negotiate_flags);
1950 a.in.server_name = talloc_asprintf(
1951 mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
1952 a.in.account_name = talloc_asprintf(
1953 mem_ctx, "%s$", wksname);
1954 a.in.computer_name = wksname;
1955 a.in.secure_channel_type = SEC_CHAN_WKSTA;
1956 a.in.negotiate_flags = &negotiate_flags;
1957 a.out.negotiate_flags = &negotiate_flags;
1958 a.in.credentials = &netr_cred;
1959 a.out.credentials = &netr_cred;
1961 status = dcerpc_netr_ServerAuthenticate2(net_pipe, mem_ctx, &a);
1963 if (!NT_STATUS_EQUAL(status, NT_STATUS_NO_TRUST_SAM_ACCOUNT)) {
1964 d_printf("dcerpc_netr_ServerAuthenticate2 returned %s, "
1965 "expected NT_STATUS_NO_TRUST_SAM_ACCOUNT\n",
1972 talloc_free(mem_ctx);
1976 static struct security_descriptor *get_sharesec(TALLOC_CTX *mem_ctx,
1977 struct smbcli_session *sess,
1978 const char *sharename)
1980 struct smbcli_tree *tree;
1981 TALLOC_CTX *tmp_ctx;
1982 struct dcerpc_pipe *p;
1984 struct srvsvc_NetShareGetInfo r;
1985 struct security_descriptor *result;
1987 if (!(tmp_ctx = talloc_new(mem_ctx))) {
1988 d_printf("talloc_new failed\n");
1992 if (!NT_STATUS_IS_OK(secondary_tcon(tmp_ctx, sess, "IPC$", &tree))) {
1993 d_printf("secondary_tcon failed\n");
1994 talloc_free(tmp_ctx);
1998 status = pipe_bind_smb(mem_ctx, tree, "\\pipe\\srvsvc",
1999 &ndr_table_srvsvc, &p);
2000 if (!NT_STATUS_IS_OK(status)) {
2001 d_printf("(%s) could not bind to srvsvc pipe: %s\n",
2002 __location__, nt_errstr(status));
2003 talloc_free(tmp_ctx);
2008 p->conn->flags |= DCERPC_DEBUG_PRINT_IN | DCERPC_DEBUG_PRINT_OUT;
2011 r.in.server_unc = talloc_asprintf(tmp_ctx, "\\\\%s",
2012 dcerpc_server_name(p));
2013 r.in.share_name = sharename;
2016 status = dcerpc_srvsvc_NetShareGetInfo(p, tmp_ctx, &r);
2017 if (!NT_STATUS_IS_OK(status)) {
2018 d_printf("srvsvc_NetShareGetInfo failed: %s\n",
2020 talloc_free(tmp_ctx);
2024 result = talloc_steal(mem_ctx, r.out.info.info502->sd);
2025 talloc_free(tmp_ctx);
2029 static NTSTATUS set_sharesec(TALLOC_CTX *mem_ctx,
2030 struct smbcli_session *sess,
2031 const char *sharename,
2032 struct security_descriptor *sd)
2034 struct smbcli_tree *tree;
2035 TALLOC_CTX *tmp_ctx;
2036 struct dcerpc_pipe *p;
2038 struct sec_desc_buf i;
2039 struct srvsvc_NetShareSetInfo r;
2042 if (!(tmp_ctx = talloc_new(mem_ctx))) {
2043 d_printf("talloc_new failed\n");
2044 return NT_STATUS_NO_MEMORY;
2047 if (!NT_STATUS_IS_OK(secondary_tcon(tmp_ctx, sess, "IPC$", &tree))) {
2048 d_printf("secondary_tcon failed\n");
2049 talloc_free(tmp_ctx);
2050 return NT_STATUS_UNSUCCESSFUL;
2053 status = pipe_bind_smb(mem_ctx, tree, "\\pipe\\srvsvc",
2054 &ndr_table_srvsvc, &p);
2055 if (!NT_STATUS_IS_OK(status)) {
2056 d_printf("(%s) could not bind to srvsvc pipe: %s\n",
2057 __location__, nt_errstr(status));
2058 talloc_free(tmp_ctx);
2059 return NT_STATUS_UNSUCCESSFUL;
2063 p->conn->flags |= DCERPC_DEBUG_PRINT_IN | DCERPC_DEBUG_PRINT_OUT;
2066 r.in.server_unc = talloc_asprintf(tmp_ctx, "\\\\%s",
2067 dcerpc_server_name(p));
2068 r.in.share_name = sharename;
2071 r.in.info.info1501 = &i;
2072 r.in.parm_error = &error;
2074 status = dcerpc_srvsvc_NetShareSetInfo(p, tmp_ctx, &r);
2075 if (!NT_STATUS_IS_OK(status)) {
2076 d_printf("srvsvc_NetShareGetInfo failed: %s\n",
2080 talloc_free(tmp_ctx);
2084 bool try_tcon(TALLOC_CTX *mem_ctx,
2085 struct security_descriptor *orig_sd,
2086 struct smbcli_session *session,
2087 const char *sharename, const struct dom_sid *user_sid,
2088 unsigned int access_mask, NTSTATUS expected_tcon,
2089 NTSTATUS expected_mkdir)
2091 TALLOC_CTX *tmp_ctx;
2092 struct smbcli_tree *rmdir_tree, *tree;
2093 struct dom_sid *domain_sid;
2095 struct security_descriptor *sd;
2099 if (!(tmp_ctx = talloc_new(mem_ctx))) {
2100 d_printf("talloc_new failed\n");
2104 status = secondary_tcon(tmp_ctx, session, sharename, &rmdir_tree);
2105 if (!NT_STATUS_IS_OK(status)) {
2106 d_printf("first tcon to delete dir failed\n");
2107 talloc_free(tmp_ctx);
2111 smbcli_rmdir(rmdir_tree, "sharesec_testdir");
2113 if (!NT_STATUS_IS_OK(dom_sid_split_rid(tmp_ctx, user_sid,
2114 &domain_sid, &rid))) {
2115 d_printf("dom_sid_split_rid failed\n");
2116 talloc_free(tmp_ctx);
2120 sd = security_descriptor_dacl_create(
2121 tmp_ctx, 0, "S-1-5-32-544",
2122 dom_sid_string(mem_ctx, dom_sid_add_rid(mem_ctx, domain_sid,
2124 dom_sid_string(mem_ctx, user_sid),
2125 SEC_ACE_TYPE_ACCESS_ALLOWED, access_mask, 0, NULL);
2127 d_printf("security_descriptor_dacl_create failed\n");
2128 talloc_free(tmp_ctx);
2132 status = set_sharesec(mem_ctx, session, sharename, sd);
2133 if (!NT_STATUS_IS_OK(status)) {
2134 d_printf("custom set_sharesec failed: %s\n",
2136 talloc_free(tmp_ctx);
2140 status = secondary_tcon(tmp_ctx, session, sharename, &tree);
2141 if (!NT_STATUS_EQUAL(status, expected_tcon)) {
2142 d_printf("Expected %s, got %s\n", nt_errstr(expected_tcon),
2148 if (!NT_STATUS_IS_OK(status)) {
2149 /* An expected non-access, no point in trying to write */
2153 status = smbcli_mkdir(tree, "sharesec_testdir");
2154 if (!NT_STATUS_EQUAL(status, expected_mkdir)) {
2155 d_printf("(%s) Expected %s, got %s\n", __location__,
2156 nt_errstr(expected_mkdir), nt_errstr(status));
2161 smbcli_rmdir(rmdir_tree, "sharesec_testdir");
2163 status = set_sharesec(mem_ctx, session, sharename, orig_sd);
2164 if (!NT_STATUS_IS_OK(status)) {
2165 d_printf("custom set_sharesec failed: %s\n",
2167 talloc_free(tmp_ctx);
2171 talloc_free(tmp_ctx);
2175 bool torture_samba3_rpc_sharesec(struct torture_context *torture)
2177 TALLOC_CTX *mem_ctx;
2179 struct smbcli_state *cli;
2180 struct security_descriptor *sd;
2181 struct dom_sid *user_sid;
2183 if (!(mem_ctx = talloc_new(torture))) {
2187 if (!(torture_open_connection_share(
2188 mem_ctx, &cli, torture, torture_setting_string(torture, "host", NULL),
2190 d_printf("IPC$ connection failed\n");
2191 talloc_free(mem_ctx);
2195 if (!(user_sid = whoami(mem_ctx, cli->tree))) {
2196 d_printf("whoami failed\n");
2197 talloc_free(mem_ctx);
2201 sd = get_sharesec(mem_ctx, cli->session, torture_setting_string(torture,
2204 ret &= try_tcon(mem_ctx, sd, cli->session,
2205 torture_setting_string(torture, "share", NULL),
2206 user_sid, 0, NT_STATUS_ACCESS_DENIED, NT_STATUS_OK);
2208 ret &= try_tcon(mem_ctx, sd, cli->session,
2209 torture_setting_string(torture, "share", NULL),
2210 user_sid, SEC_FILE_READ_DATA, NT_STATUS_OK,
2211 NT_STATUS_MEDIA_WRITE_PROTECTED);
2213 ret &= try_tcon(mem_ctx, sd, cli->session,
2214 torture_setting_string(torture, "share", NULL),
2215 user_sid, SEC_FILE_ALL, NT_STATUS_OK, NT_STATUS_OK);
2217 talloc_free(mem_ctx);
2221 bool torture_samba3_rpc_lsa(struct torture_context *torture)
2223 TALLOC_CTX *mem_ctx;
2225 struct smbcli_state *cli;
2226 struct dcerpc_pipe *p;
2227 struct policy_handle lsa_handle;
2229 struct dom_sid *domain_sid;
2231 if (!(mem_ctx = talloc_new(torture))) {
2235 if (!(torture_open_connection_share(
2236 mem_ctx, &cli, torture, torture_setting_string(torture, "host", NULL),
2238 d_printf("IPC$ connection failed\n");
2239 talloc_free(mem_ctx);
2243 status = pipe_bind_smb(mem_ctx, cli->tree, "\\lsarpc",
2244 &ndr_table_lsarpc, &p);
2245 if (!NT_STATUS_IS_OK(status)) {
2246 d_printf("(%s) pipe_bind_smb failed: %s\n", __location__,
2248 talloc_free(mem_ctx);
2253 struct lsa_ObjectAttribute attr;
2254 struct lsa_OpenPolicy2 o;
2255 o.in.system_name = talloc_asprintf(
2256 mem_ctx, "\\\\%s", dcerpc_server_name(p));
2259 o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2260 o.out.handle = &lsa_handle;
2261 status = dcerpc_lsa_OpenPolicy2(p, mem_ctx, &o);
2262 if (!NT_STATUS_IS_OK(status)) {
2263 d_printf("(%s) dcerpc_lsa_OpenPolicy2 failed: %s\n",
2264 __location__, nt_errstr(status));
2265 talloc_free(mem_ctx);
2271 p->conn->flags |= DCERPC_DEBUG_PRINT_IN | DCERPC_DEBUG_PRINT_OUT;
2276 int levels[] = { 2,3,5,6 };
2278 for (i=0; i<ARRAY_SIZE(levels); i++) {
2279 struct lsa_QueryInfoPolicy r;
2280 r.in.handle = &lsa_handle;
2281 r.in.level = levels[i];
2282 status = dcerpc_lsa_QueryInfoPolicy(p, mem_ctx, &r);
2283 if (!NT_STATUS_IS_OK(status)) {
2284 d_printf("(%s) dcerpc_lsa_QueryInfoPolicy %d "
2285 "failed: %s\n", __location__,
2286 levels[i], nt_errstr(status));
2287 talloc_free(mem_ctx);
2290 if (levels[i] == 5) {
2291 domain_sid = r.out.info->account_domain.sid;
2299 static NTSTATUS get_servername(TALLOC_CTX *mem_ctx, struct smbcli_tree *tree,
2302 struct rap_WserverGetInfo r;
2304 char servername[17];
2307 r.in.bufsize = 0xffff;
2309 status = smbcli_rap_netservergetinfo(tree, mem_ctx, &r);
2310 if (!NT_STATUS_IS_OK(status)) {
2314 memcpy(servername, r.out.info.info0.name, 16);
2315 servername[16] = '\0';
2317 if (pull_ascii_talloc(mem_ctx, global_smb_iconv_convenience,
2318 name, servername) < 0) {
2319 return NT_STATUS_NO_MEMORY;
2322 return NT_STATUS_OK;
2326 static NTSTATUS find_printers(TALLOC_CTX *ctx, struct smbcli_tree *tree,
2327 const char ***printers, int *num_printers)
2329 TALLOC_CTX *mem_ctx;
2331 struct dcerpc_pipe *p;
2332 struct srvsvc_NetShareEnum r;
2333 struct srvsvc_NetShareCtr1 c1_in;
2334 struct srvsvc_NetShareCtr1 *c1;
2337 mem_ctx = talloc_new(ctx);
2338 if (mem_ctx == NULL) {
2339 return NT_STATUS_NO_MEMORY;
2342 status = pipe_bind_smb(mem_ctx, tree, "\\srvsvc", &ndr_table_srvsvc,
2344 if (!NT_STATUS_IS_OK(status)) {
2345 d_printf("could not bind to srvsvc pipe\n");
2346 talloc_free(mem_ctx);
2350 r.in.server_unc = talloc_asprintf(
2351 mem_ctx, "\\\\%s", dcerpc_server_name(p));
2354 r.in.ctr.ctr1 = &c1_in;
2355 r.in.max_buffer = (uint32_t)-1;
2356 r.in.resume_handle = NULL;
2358 status = dcerpc_srvsvc_NetShareEnum(p, mem_ctx, &r);
2359 if (!NT_STATUS_IS_OK(status)) {
2360 d_printf("NetShareEnum level %u failed - %s\n",
2361 r.in.level, nt_errstr(status));
2362 talloc_free(mem_ctx);
2368 c1 = r.out.ctr.ctr1;
2369 for (i=0; i<c1->count; i++) {
2370 if (c1->array[i].type != STYPE_PRINTQ) {
2373 if (!add_string_to_array(ctx, c1->array[i].name,
2374 printers, num_printers)) {
2376 return NT_STATUS_NO_MEMORY;
2380 talloc_free(mem_ctx);
2381 return NT_STATUS_OK;
2384 static bool enumprinters(TALLOC_CTX *mem_ctx, struct dcerpc_pipe *pipe,
2385 const char *servername, int level, int *num_printers)
2387 struct spoolss_EnumPrinters r;
2391 r.in.flags = PRINTER_ENUM_LOCAL;
2392 r.in.server = talloc_asprintf(mem_ctx, "\\\\%s", servername);
2397 status = dcerpc_spoolss_EnumPrinters(pipe, mem_ctx, &r);
2398 if (!NT_STATUS_IS_OK(status)) {
2399 d_printf("(%s) dcerpc_spoolss_EnumPrinters failed: %s\n",
2400 __location__, nt_errstr(status));
2404 if (!W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
2405 d_printf("(%s) EnumPrinters unexpected return code %s, should "
2406 "be WERR_INSUFFICIENT_BUFFER\n", __location__,
2407 win_errstr(r.out.result));
2411 blob = data_blob_talloc_zero(mem_ctx, r.out.needed);
2412 if (blob.data == NULL) {
2413 d_printf("(%s) data_blob_talloc failed\n", __location__);
2417 r.in.buffer = &blob;
2418 r.in.offered = r.out.needed;
2420 status = dcerpc_spoolss_EnumPrinters(pipe, mem_ctx, &r);
2421 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
2422 d_printf("(%s) dcerpc_spoolss_EnumPrinters failed: %s, "
2423 "%s\n", __location__, nt_errstr(status),
2424 win_errstr(r.out.result));
2428 *num_printers = r.out.count;
2433 static NTSTATUS getprinterinfo(TALLOC_CTX *ctx, struct dcerpc_pipe *pipe,
2434 struct policy_handle *handle, int level,
2435 union spoolss_PrinterInfo **res)
2437 TALLOC_CTX *mem_ctx;
2438 struct spoolss_GetPrinter r;
2442 mem_ctx = talloc_new(ctx);
2443 if (mem_ctx == NULL) {
2444 return NT_STATUS_NO_MEMORY;
2447 r.in.handle = handle;
2452 status = dcerpc_spoolss_GetPrinter(pipe, mem_ctx, &r);
2453 if (!NT_STATUS_IS_OK(status)) {
2454 d_printf("(%s) dcerpc_spoolss_GetPrinter failed: %s\n",
2455 __location__, nt_errstr(status));
2456 talloc_free(mem_ctx);
2460 if (!W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
2461 printf("GetPrinter unexpected return code %s, should "
2462 "be WERR_INSUFFICIENT_BUFFER\n",
2463 win_errstr(r.out.result));
2464 talloc_free(mem_ctx);
2465 return NT_STATUS_UNSUCCESSFUL;
2468 r.in.handle = handle;
2470 blob = data_blob_talloc(mem_ctx, NULL, r.out.needed);
2471 if (blob.data == NULL) {
2472 talloc_free(mem_ctx);
2473 return NT_STATUS_NO_MEMORY;
2475 memset(blob.data, 0, blob.length);
2476 r.in.buffer = &blob;
2477 r.in.offered = r.out.needed;
2479 status = dcerpc_spoolss_GetPrinter(pipe, mem_ctx, &r);
2480 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
2481 d_printf("(%s) dcerpc_spoolss_GetPrinter failed: %s, "
2482 "%s\n", __location__, nt_errstr(status),
2483 win_errstr(r.out.result));
2484 talloc_free(mem_ctx);
2485 return NT_STATUS_IS_OK(status) ?
2486 NT_STATUS_UNSUCCESSFUL : status;
2490 *res = talloc_steal(ctx, r.out.info);
2493 talloc_free(mem_ctx);
2494 return NT_STATUS_OK;
2497 bool torture_samba3_rpc_spoolss(struct torture_context *torture)
2499 TALLOC_CTX *mem_ctx;
2501 struct smbcli_state *cli;
2502 struct dcerpc_pipe *p;
2504 struct policy_handle server_handle, printer_handle;
2505 const char **printers;
2507 struct spoolss_UserLevel1 userlevel1;
2510 if (!(mem_ctx = talloc_new(torture))) {
2514 if (!(torture_open_connection_share(
2515 mem_ctx, &cli, torture, torture_setting_string(torture, "host", NULL),
2517 d_printf("IPC$ connection failed\n");
2518 talloc_free(mem_ctx);
2522 status = get_servername(mem_ctx, cli->tree, &servername);
2523 if (!NT_STATUS_IS_OK(status)) {
2524 d_fprintf(stderr, "(%s) get_servername returned %s\n",
2525 __location__, nt_errstr(status));
2526 talloc_free(mem_ctx);
2530 if (!NT_STATUS_IS_OK(find_printers(mem_ctx, cli->tree,
2531 &printers, &num_printers))) {
2532 talloc_free(mem_ctx);
2536 if (num_printers == 0) {
2537 d_printf("Did not find printers\n");
2538 talloc_free(mem_ctx);
2542 status = pipe_bind_smb(mem_ctx, cli->tree, "\\spoolss",
2543 &ndr_table_spoolss, &p);
2544 if (!NT_STATUS_IS_OK(status)) {
2545 d_printf("(%s) pipe_bind_smb failed: %s\n", __location__,
2547 talloc_free(mem_ctx);
2551 ZERO_STRUCT(userlevel1);
2552 userlevel1.client = talloc_asprintf(
2553 mem_ctx, "\\\\%s", lp_netbios_name(torture->lp_ctx));
2554 userlevel1.user = cli_credentials_get_username(cmdline_credentials);
2555 userlevel1.build = 2600;
2556 userlevel1.major = 3;
2557 userlevel1.minor = 0;
2558 userlevel1.processor = 0;
2561 struct spoolss_OpenPrinterEx r;
2564 r.in.printername = talloc_asprintf(mem_ctx, "\\\\%s",
2566 r.in.datatype = NULL;
2567 r.in.access_mask = 0;
2569 r.in.userlevel.level1 = &userlevel1;
2570 r.out.handle = &server_handle;
2572 status = dcerpc_spoolss_OpenPrinterEx(p, mem_ctx, &r);
2573 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
2574 d_printf("(%s) dcerpc_spoolss_OpenPrinterEx failed: "
2575 "%s, %s\n", __location__, nt_errstr(status),
2576 win_errstr(r.out.result));
2577 talloc_free(mem_ctx);
2583 struct spoolss_ClosePrinter r;
2585 r.in.handle = &server_handle;
2586 r.out.handle = &server_handle;
2588 status = dcerpc_spoolss_ClosePrinter(p, mem_ctx, &r);
2589 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
2590 d_printf("(%s) dcerpc_spoolss_ClosePrinter failed: "
2591 "%s, %s\n", __location__, nt_errstr(status),
2592 win_errstr(r.out.result));
2593 talloc_free(mem_ctx);
2599 struct spoolss_OpenPrinterEx r;
2602 r.in.printername = talloc_asprintf(
2603 mem_ctx, "\\\\%s\\%s", servername, printers[0]);
2604 r.in.datatype = NULL;
2605 r.in.access_mask = 0;
2607 r.in.userlevel.level1 = &userlevel1;
2608 r.out.handle = &printer_handle;
2610 status = dcerpc_spoolss_OpenPrinterEx(p, mem_ctx, &r);
2611 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
2612 d_printf("(%s) dcerpc_spoolss_OpenPrinterEx failed: "
2613 "%s, %s\n", __location__, nt_errstr(status),
2614 win_errstr(r.out.result));
2615 talloc_free(mem_ctx);
2623 for (i=0; i<8; i++) {
2624 status = getprinterinfo(mem_ctx, p, &printer_handle,
2626 if (!NT_STATUS_IS_OK(status)) {
2627 d_printf("(%s) getprinterinfo %d failed: %s\n",
2628 __location__, i, nt_errstr(status));
2635 struct spoolss_ClosePrinter r;
2637 r.in.handle = &printer_handle;
2638 r.out.handle = &printer_handle;
2640 status = dcerpc_spoolss_ClosePrinter(p, mem_ctx, &r);
2641 if (!NT_STATUS_IS_OK(status)) {
2642 d_printf("(%s) dcerpc_spoolss_ClosePrinter failed: "
2643 "%s\n", __location__, nt_errstr(status));
2644 talloc_free(mem_ctx);
2651 if (!enumprinters(mem_ctx, p, servername, 1,
2653 d_printf("(%s) enumprinters failed\n", __location__);
2654 talloc_free(mem_ctx);
2657 if (num_printers != num_enumerated) {
2658 d_printf("(%s) netshareenum gave %d printers, "
2659 "enumprinters lvl 1 gave %d\n", __location__,
2660 num_printers, num_enumerated);
2661 talloc_free(mem_ctx);
2668 if (!enumprinters(mem_ctx, p, servername, 2,
2670 d_printf("(%s) enumprinters failed\n", __location__);
2671 talloc_free(mem_ctx);
2674 if (num_printers != num_enumerated) {
2675 d_printf("(%s) netshareenum gave %d printers, "
2676 "enumprinters lvl 2 gave %d\n", __location__,
2677 num_printers, num_enumerated);
2678 talloc_free(mem_ctx);
2683 talloc_free(mem_ctx);
2688 bool torture_samba3_rpc_wkssvc(struct torture_context *torture)
2690 TALLOC_CTX *mem_ctx;
2691 struct smbcli_state *cli;
2692 struct dcerpc_pipe *p;
2696 if (!(mem_ctx = talloc_new(torture))) {
2700 if (!(torture_open_connection_share(
2701 mem_ctx, &cli, torture, torture_setting_string(torture, "host", NULL),
2703 d_printf("IPC$ connection failed\n");
2704 talloc_free(mem_ctx);
2708 status = get_servername(mem_ctx, cli->tree, &servername);
2709 if (!NT_STATUS_IS_OK(status)) {
2710 d_fprintf(stderr, "(%s) get_servername returned %s\n",
2711 __location__, nt_errstr(status));
2712 talloc_free(mem_ctx);
2716 status = pipe_bind_smb(mem_ctx, cli->tree, "\\wkssvc",
2717 &ndr_table_wkssvc, &p);
2718 if (!NT_STATUS_IS_OK(status)) {
2719 d_printf("(%s) pipe_bind_smb failed: %s\n", __location__,
2721 talloc_free(mem_ctx);
2726 struct wkssvc_NetWkstaInfo100 wks100;
2727 union wkssvc_NetWkstaInfo info;
2728 struct wkssvc_NetWkstaGetInfo r;
2730 r.in.server_name = "\\foo";
2732 info.info100 = &wks100;
2735 status = dcerpc_wkssvc_NetWkstaGetInfo(p, mem_ctx, &r);
2736 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
2737 d_printf("(%s) dcerpc_wkssvc_NetWksGetInfo failed: "
2738 "%s, %s\n", __location__, nt_errstr(status),
2739 win_errstr(r.out.result));
2740 talloc_free(mem_ctx);
2744 if (strcmp(servername,
2745 r.out.info->info100->server_name) != 0) {
2746 d_printf("(%s) servername inconsistency: RAP=%s, "
2747 "dcerpc_wkssvc_NetWksGetInfo=%s",
2748 __location__, servername,
2749 r.out.info->info100->server_name);
2750 talloc_free(mem_ctx);
2755 talloc_free(mem_ctx);
2759 static NTSTATUS winreg_close(struct dcerpc_pipe *p,
2760 struct policy_handle *handle)
2762 struct winreg_CloseKey c;
2764 TALLOC_CTX *mem_ctx;
2766 c.in.handle = c.out.handle = handle;
2768 if (!(mem_ctx = talloc_new(p))) {
2769 return NT_STATUS_NO_MEMORY;
2772 status = dcerpc_winreg_CloseKey(p, mem_ctx, &c);
2773 talloc_free(mem_ctx);
2775 if (!NT_STATUS_IS_OK(status)) {
2779 if (!W_ERROR_IS_OK(c.out.result)) {
2780 return werror_to_ntstatus(c.out.result);
2783 return NT_STATUS_OK;
2786 static NTSTATUS enumvalues(struct dcerpc_pipe *p, struct policy_handle *handle,
2787 TALLOC_CTX *mem_ctx)
2789 uint32_t enum_index = 0;
2792 struct winreg_EnumValue r;
2793 struct winreg_StringBuf name;
2794 enum winreg_Type type = 0;
2797 uint32_t size, length;
2799 r.in.handle = handle;
2800 r.in.enum_index = enum_index;
2803 r.in.name = r.out.name = &name;
2809 r.in.length = &length;
2811 status = dcerpc_winreg_EnumValue(p, mem_ctx, &r);
2812 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
2813 return NT_STATUS_OK;
2819 static NTSTATUS enumkeys(struct dcerpc_pipe *p, struct policy_handle *handle,
2820 TALLOC_CTX *mem_ctx, int depth)
2822 struct winreg_EnumKey r;
2823 struct winreg_StringBuf class, name;
2828 return NT_STATUS_OK;
2834 r.in.handle = handle;
2835 r.in.enum_index = 0;
2837 r.in.keyclass = &class;
2839 r.in.last_changed_time = &t;
2842 TALLOC_CTX *tmp_ctx;
2843 struct winreg_OpenKey o;
2844 struct policy_handle key_handle;
2847 if (!(tmp_ctx = talloc_new(mem_ctx))) {
2848 return NT_STATUS_NO_MEMORY;
2854 status = dcerpc_winreg_EnumKey(p, tmp_ctx, &r);
2855 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
2856 /* We're done enumerating */
2857 talloc_free(tmp_ctx);
2858 return NT_STATUS_OK;
2861 for (i=0; i<10-depth; i++)
2863 printf("%s\n", r.out.name->name);
2866 o.in.parent_handle = handle;
2867 o.in.keyname.name = r.out.name->name;
2869 o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2870 o.out.handle = &key_handle;
2872 status = dcerpc_winreg_OpenKey(p, tmp_ctx, &o);
2873 if (NT_STATUS_IS_OK(status) && W_ERROR_IS_OK(o.out.result)) {
2874 enumkeys(p, &key_handle, tmp_ctx, depth-1);
2875 enumvalues(p, &key_handle, tmp_ctx);
2876 status = winreg_close(p, &key_handle);
2877 if (!NT_STATUS_IS_OK(status)) {
2882 talloc_free(tmp_ctx);
2884 r.in.enum_index += 1;
2887 return NT_STATUS_OK;
2890 typedef NTSTATUS (*winreg_open_fn)(struct dcerpc_pipe *, TALLOC_CTX *, void *);
2892 static bool test_Open3(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
2893 const char *name, winreg_open_fn open_fn)
2895 struct policy_handle handle;
2896 struct winreg_OpenHKLM r;
2899 r.in.system_name = 0;
2900 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2901 r.out.handle = &handle;
2903 status = open_fn(p, mem_ctx, &r);
2904 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
2905 d_printf("(%s) %s failed: %s, %s\n", __location__, name,
2906 nt_errstr(status), win_errstr(r.out.result));
2910 enumkeys(p, &handle, mem_ctx, 4);
2912 status = winreg_close(p, &handle);
2913 if (!NT_STATUS_IS_OK(status)) {
2914 d_printf("(%s) dcerpc_CloseKey failed: %s\n",
2915 __location__, nt_errstr(status));
2922 bool torture_samba3_rpc_winreg(struct torture_context *torture)
2925 struct dcerpc_pipe *p;
2926 TALLOC_CTX *mem_ctx;
2932 {"OpenHKLM", (winreg_open_fn)dcerpc_winreg_OpenHKLM },
2933 {"OpenHKU", (winreg_open_fn)dcerpc_winreg_OpenHKU },
2934 {"OpenHKPD", (winreg_open_fn)dcerpc_winreg_OpenHKPD },
2935 {"OpenHKPT", (winreg_open_fn)dcerpc_winreg_OpenHKPT },
2936 {"OpenHKCR", (winreg_open_fn)dcerpc_winreg_OpenHKCR }};
2941 mem_ctx = talloc_init("torture_rpc_winreg");
2943 status = torture_rpc_connection(torture, &p, &ndr_table_winreg);
2945 if (!NT_STATUS_IS_OK(status)) {
2946 talloc_free(mem_ctx);
2951 ret = test_Open3(p, mem_ctx, open_fns[0].name, open_fns[0].fn);
2953 for (i = 0; i < ARRAY_SIZE(open_fns); i++) {
2954 if (!test_Open3(p, mem_ctx, open_fns[i].name, open_fns[i].fn))
2959 talloc_free(mem_ctx);
2964 static NTSTATUS get_shareinfo(TALLOC_CTX *mem_ctx,
2965 struct smbcli_state *cli,
2967 struct srvsvc_NetShareInfo502 **info)
2969 struct smbcli_tree *ipc;
2970 struct dcerpc_pipe *p;
2971 struct srvsvc_NetShareGetInfo r;
2974 if (!(p = dcerpc_pipe_init(cli,
2975 cli->transport->socket->event.ctx))) {
2976 status = NT_STATUS_NO_MEMORY;
2980 status = secondary_tcon(p, cli->session, "IPC$", &ipc);
2981 if (!NT_STATUS_IS_OK(status)) {
2985 status = dcerpc_pipe_open_smb(p, ipc, "\\pipe\\srvsvc");
2986 if (!NT_STATUS_IS_OK(status)) {
2987 d_printf("dcerpc_pipe_open_smb failed: %s\n",
2992 status = dcerpc_bind_auth_none(p, &ndr_table_srvsvc);
2993 if (!NT_STATUS_IS_OK(status)) {
2994 d_printf("dcerpc_bind_auth_none failed: %s\n",
2999 r.in.server_unc = talloc_asprintf(mem_ctx, "\\\\%s",
3000 dcerpc_server_name(p));
3001 r.in.share_name = share;
3004 status = dcerpc_srvsvc_NetShareGetInfo(p, p, &r);
3005 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
3006 d_printf("(%s) OpenHKLM failed: %s, %s\n", __location__,
3007 nt_errstr(status), win_errstr(r.out.result));
3011 *info = talloc_move(mem_ctx, &r.out.info.info502);
3012 return NT_STATUS_OK;
3020 * Get us a handle on HKLM\
3023 static NTSTATUS get_hklm_handle(TALLOC_CTX *mem_ctx,
3024 struct smbcli_state *cli,
3025 struct dcerpc_pipe **pipe_p,
3026 struct policy_handle **handle)
3028 struct smbcli_tree *ipc;
3029 struct dcerpc_pipe *p;
3030 struct winreg_OpenHKLM r;
3032 struct policy_handle *result;
3034 result = talloc(mem_ctx, struct policy_handle);
3036 if (result == NULL) {
3037 return NT_STATUS_NO_MEMORY;
3040 if (!(p = dcerpc_pipe_init(result,
3041 cli->transport->socket->event.ctx))) {
3042 status = NT_STATUS_NO_MEMORY;
3046 status = secondary_tcon(p, cli->session, "IPC$", &ipc);
3047 if (!NT_STATUS_IS_OK(status)) {
3051 status = dcerpc_pipe_open_smb(p, ipc, "\\winreg");
3052 if (!NT_STATUS_IS_OK(status)) {
3053 d_printf("dcerpc_pipe_open_smb failed: %s\n",
3058 status = dcerpc_bind_auth_none(p, &ndr_table_winreg);
3059 if (!NT_STATUS_IS_OK(status)) {
3060 d_printf("dcerpc_bind_auth_none failed: %s\n",
3065 r.in.system_name = 0;
3066 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3067 r.out.handle = result;
3069 status = dcerpc_winreg_OpenHKLM(p, p, &r);
3070 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
3071 d_printf("(%s) OpenHKLM failed: %s, %s\n", __location__,
3072 nt_errstr(status), win_errstr(r.out.result));
3078 return NT_STATUS_OK;
3081 talloc_free(result);
3085 static NTSTATUS torture_samba3_createshare(struct smbcli_state *cli,
3086 const char *sharename)
3088 struct dcerpc_pipe *p;
3089 struct policy_handle *hklm = NULL;
3090 struct policy_handle new_handle;
3091 struct winreg_CreateKey c;
3092 struct winreg_CloseKey cl;
3093 enum winreg_CreateAction action_taken;
3095 TALLOC_CTX *mem_ctx;
3097 mem_ctx = talloc_new(cli);
3098 NT_STATUS_HAVE_NO_MEMORY(mem_ctx);
3100 status = get_hklm_handle(mem_ctx, cli, &p, &hklm);
3101 if (!NT_STATUS_IS_OK(status)) {
3102 d_printf("get_hklm_handle failed: %s\n", nt_errstr(status));
3107 c.in.name.name = talloc_asprintf(
3108 mem_ctx, "software\\samba\\smbconf\\%s", sharename);
3109 if (c.in.name.name == NULL) {
3110 d_printf("talloc_asprintf failed\n");
3111 status = NT_STATUS_NO_MEMORY;
3114 c.in.keyclass.name = "";
3116 c.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3117 c.in.secdesc = NULL;
3118 c.in.action_taken = &action_taken;
3119 c.out.new_handle = &new_handle;
3120 c.out.action_taken = &action_taken;
3122 status = dcerpc_winreg_CreateKey(p, p, &c);
3123 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(c.out.result)) {
3124 d_printf("(%s) OpenKey failed: %s, %s\n", __location__,
3125 nt_errstr(status), win_errstr(c.out.result));
3129 cl.in.handle = &new_handle;
3130 cl.out.handle = &new_handle;
3131 status = dcerpc_winreg_CloseKey(p, p, &cl);
3132 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(cl.out.result)) {
3133 d_printf("(%s) OpenKey failed: %s, %s\n", __location__,
3134 nt_errstr(status), win_errstr(cl.out.result));
3140 talloc_free(mem_ctx);
3144 static NTSTATUS torture_samba3_deleteshare(struct smbcli_state *cli,
3145 const char *sharename)
3147 struct dcerpc_pipe *p;
3148 struct policy_handle *hklm = NULL;
3149 struct winreg_DeleteKey d;
3151 TALLOC_CTX *mem_ctx;
3153 mem_ctx = talloc_new(cli);
3154 NT_STATUS_HAVE_NO_MEMORY(mem_ctx);
3156 status = get_hklm_handle(cli, cli, &p, &hklm);
3157 if (!NT_STATUS_IS_OK(status)) {
3158 d_printf("get_hklm_handle failed: %s\n", nt_errstr(status));
3163 d.in.key.name = talloc_asprintf(
3164 mem_ctx, "software\\samba\\smbconf\\%s", sharename);
3165 if (d.in.key.name == NULL) {
3166 d_printf("talloc_asprintf failed\n");
3167 status = NT_STATUS_NO_MEMORY;
3170 status = dcerpc_winreg_DeleteKey(p, p, &d);
3171 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(d.out.result)) {
3172 d_printf("(%s) OpenKey failed: %s, %s\n", __location__,
3173 nt_errstr(status), win_errstr(d.out.result));
3178 talloc_free(mem_ctx);
3182 static NTSTATUS torture_samba3_setconfig(struct smbcli_state *cli,
3183 const char *sharename,
3184 const char *parameter,
3187 struct dcerpc_pipe *p = NULL;
3188 struct policy_handle *hklm = NULL, key_handle;
3189 struct winreg_OpenKey o;
3190 struct winreg_SetValue s;
3195 status = get_hklm_handle(cli, cli, &p, &hklm);
3196 if (!NT_STATUS_IS_OK(status)) {
3197 d_printf("get_hklm_handle failed: %s\n", nt_errstr(status));
3201 o.in.parent_handle = hklm;
3202 o.in.keyname.name = talloc_asprintf(
3203 hklm, "software\\samba\\smbconf\\%s", sharename);
3204 if (o.in.keyname.name == NULL) {
3205 d_printf("talloc_asprintf failed\n");
3206 status = NT_STATUS_NO_MEMORY;
3210 o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3211 o.out.handle = &key_handle;
3213 status = dcerpc_winreg_OpenKey(p, p, &o);
3214 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(o.out.result)) {
3215 d_printf("(%s) OpenKey failed: %s, %s\n", __location__,
3216 nt_errstr(status), win_errstr(o.out.result));
3220 if (!reg_string_to_val(hklm, "REG_SZ", value, &type, &val)) {
3221 d_printf("(%s) reg_string_to_val failed\n", __location__);
3225 s.in.handle = &key_handle;
3226 s.in.name.name = parameter;
3228 s.in.data = val.data;
3229 s.in.size = val.length;
3231 status = dcerpc_winreg_SetValue(p, p, &s);
3232 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(s.out.result)) {
3233 d_printf("(%s) SetValue failed: %s, %s\n", __location__,
3234 nt_errstr(status), win_errstr(s.out.result));
3243 bool torture_samba3_regconfig(struct torture_context *torture)
3245 struct smbcli_state *cli;
3246 struct srvsvc_NetShareInfo502 *i = NULL;
3249 const char *comment = "Dummer Kommentar";
3251 if (!(torture_open_connection(&cli, torture, 0))) {
3255 status = torture_samba3_createshare(cli, "blubber");
3256 if (!NT_STATUS_IS_OK(status)) {
3257 torture_warning(torture, "torture_samba3_createshare failed: "
3258 "%s\n", nt_errstr(status));
3262 status = torture_samba3_setconfig(cli, "blubber", "comment", comment);
3263 if (!NT_STATUS_IS_OK(status)) {
3264 torture_warning(torture, "torture_samba3_setconfig failed: "
3265 "%s\n", nt_errstr(status));
3269 status = get_shareinfo(torture, cli, "blubber", &i);
3270 if (!NT_STATUS_IS_OK(status)) {
3271 torture_warning(torture, "get_shareinfo failed: "
3272 "%s\n", nt_errstr(status));
3276 if (strcmp(comment, i->comment) != 0) {
3277 torture_warning(torture, "Expected comment [%s], got [%s]\n",
3278 comment, i->comment);
3282 status = torture_samba3_deleteshare(cli, "blubber");
3283 if (!NT_STATUS_IS_OK(status)) {
3284 torture_warning(torture, "torture_samba3_deleteshare failed: "
3285 "%s\n", nt_errstr(status));