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 lp_iconv_convenience(torture->lp_ctx));
94 if (lsa_pipe == NULL) {
95 d_printf("dcerpc_pipe_init failed\n");
99 status = dcerpc_pipe_open_smb(lsa_pipe, cli->tree, "\\lsarpc");
100 if (!NT_STATUS_IS_OK(status)) {
101 d_printf("dcerpc_pipe_open_smb failed: %s\n",
106 status = dcerpc_bind_auth_none(lsa_pipe, &ndr_table_lsarpc);
107 if (!NT_STATUS_IS_OK(status)) {
108 d_printf("dcerpc_bind_auth_none failed: %s\n",
113 openpolicy.in.system_name =talloc_asprintf(
114 mem_ctx, "\\\\%s", dcerpc_server_name(lsa_pipe));
115 ZERO_STRUCT(objectattr);
116 openpolicy.in.attr = &objectattr;
117 openpolicy.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
118 openpolicy.out.handle = &handle;
120 status = dcerpc_lsa_OpenPolicy2(lsa_pipe, mem_ctx, &openpolicy);
122 if (!NT_STATUS_IS_OK(status)) {
123 d_printf("dcerpc_lsa_OpenPolicy2 failed: %s\n",
128 close_handle.in.handle = &handle;
129 close_handle.out.handle = &handle;
131 status = dcerpc_lsa_Close(lsa_pipe, mem_ctx, &close_handle);
132 if (!NT_STATUS_IS_OK(status)) {
133 d_printf("dcerpc_lsa_Close failed: %s\n",
138 session2 = smbcli_session_init(cli->transport, mem_ctx, false);
139 if (session2 == NULL) {
140 d_printf("smbcli_session_init failed\n");
144 if (!(anon_creds = cli_credentials_init_anon(mem_ctx))) {
145 d_printf("create_anon_creds failed\n");
149 setup.in.sesskey = cli->transport->negotiate.sesskey;
150 setup.in.capabilities = cli->transport->negotiate.capabilities;
151 setup.in.workgroup = "";
152 setup.in.credentials = anon_creds;
154 status = smb_composite_sesssetup(session2, &setup);
155 if (!NT_STATUS_IS_OK(status)) {
156 d_printf("anon session setup failed: %s\n",
160 session2->vuid = setup.out.vuid;
162 tmp = cli->tree->session;
163 cli->tree->session = session2;
165 status = dcerpc_lsa_OpenPolicy2(lsa_pipe, mem_ctx, &openpolicy);
167 cli->tree->session = tmp;
168 talloc_free(lsa_pipe);
171 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
172 d_printf("dcerpc_lsa_OpenPolicy2 with wrong vuid gave %s, "
173 "expected NT_STATUS_INVALID_HANDLE\n",
180 talloc_free(mem_ctx);
185 * Bind to lsa using a specific auth method
188 static bool bindtest(struct smbcli_state *cli,
189 struct cli_credentials *credentials,
190 struct loadparm_context *lp_ctx,
191 uint8_t auth_type, uint8_t auth_level)
197 struct dcerpc_pipe *lsa_pipe;
198 struct lsa_ObjectAttribute objectattr;
199 struct lsa_OpenPolicy2 openpolicy;
200 struct lsa_QueryInfoPolicy query;
201 struct policy_handle handle;
202 struct lsa_Close close_handle;
204 if ((mem_ctx = talloc_init("bindtest")) == NULL) {
205 d_printf("talloc_init failed\n");
209 lsa_pipe = dcerpc_pipe_init(mem_ctx,
210 cli->transport->socket->event.ctx,
211 lp_iconv_convenience(lp_ctx));
212 if (lsa_pipe == NULL) {
213 d_printf("dcerpc_pipe_init failed\n");
217 status = dcerpc_pipe_open_smb(lsa_pipe, cli->tree, "\\lsarpc");
218 if (!NT_STATUS_IS_OK(status)) {
219 d_printf("dcerpc_pipe_open_smb failed: %s\n",
224 status = dcerpc_bind_auth(lsa_pipe, &ndr_table_lsarpc,
225 credentials, lp_ctx, auth_type, auth_level,
227 if (!NT_STATUS_IS_OK(status)) {
228 d_printf("dcerpc_bind_auth failed: %s\n", nt_errstr(status));
232 openpolicy.in.system_name =talloc_asprintf(
233 mem_ctx, "\\\\%s", dcerpc_server_name(lsa_pipe));
234 ZERO_STRUCT(objectattr);
235 openpolicy.in.attr = &objectattr;
236 openpolicy.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
237 openpolicy.out.handle = &handle;
239 status = dcerpc_lsa_OpenPolicy2(lsa_pipe, mem_ctx, &openpolicy);
241 if (!NT_STATUS_IS_OK(status)) {
242 d_printf("dcerpc_lsa_OpenPolicy2 failed: %s\n",
247 query.in.handle = &handle;
248 query.in.level = LSA_POLICY_INFO_DOMAIN;
250 status = dcerpc_lsa_QueryInfoPolicy(lsa_pipe, mem_ctx, &query);
251 if (!NT_STATUS_IS_OK(status)) {
252 d_printf("dcerpc_lsa_QueryInfoPolicy failed: %s\n",
257 close_handle.in.handle = &handle;
258 close_handle.out.handle = &handle;
260 status = dcerpc_lsa_Close(lsa_pipe, mem_ctx, &close_handle);
261 if (!NT_STATUS_IS_OK(status)) {
262 d_printf("dcerpc_lsa_Close failed: %s\n",
269 talloc_free(mem_ctx);
274 * test authenticated RPC binds with the variants Samba3 does support
277 bool torture_bind_samba3(struct torture_context *torture)
282 struct smbcli_state *cli;
284 mem_ctx = talloc_init("torture_bind_authcontext");
286 if (mem_ctx == NULL) {
287 d_printf("talloc_init failed\n");
291 status = smbcli_full_connection(mem_ctx, &cli,
292 torture_setting_string(torture, "host", NULL),
293 lp_smb_ports(torture->lp_ctx),
294 "IPC$", NULL, cmdline_credentials,
296 if (!NT_STATUS_IS_OK(status)) {
297 d_printf("smbcli_full_connection failed: %s\n",
304 ret &= bindtest(cli, cmdline_credentials, torture->lp_ctx, DCERPC_AUTH_TYPE_NTLMSSP,
305 DCERPC_AUTH_LEVEL_INTEGRITY);
306 ret &= bindtest(cli, cmdline_credentials, torture->lp_ctx, DCERPC_AUTH_TYPE_NTLMSSP,
307 DCERPC_AUTH_LEVEL_PRIVACY);
308 ret &= bindtest(cli, cmdline_credentials, torture->lp_ctx, DCERPC_AUTH_TYPE_SPNEGO,
309 DCERPC_AUTH_LEVEL_INTEGRITY);
310 ret &= bindtest(cli, cmdline_credentials, torture->lp_ctx, DCERPC_AUTH_TYPE_SPNEGO,
311 DCERPC_AUTH_LEVEL_PRIVACY);
314 talloc_free(mem_ctx);
319 * Lookup or create a user and return all necessary info
322 static NTSTATUS get_usr_handle(struct smbcli_state *cli,
324 struct loadparm_context *lp_ctx,
325 struct cli_credentials *admin_creds,
328 const char *username,
330 struct dcerpc_pipe **result_pipe,
331 struct policy_handle **result_handle,
332 struct dom_sid **sid)
334 struct dcerpc_pipe *samr_pipe;
336 struct policy_handle conn_handle;
337 struct policy_handle domain_handle;
338 struct policy_handle *user_handle;
339 struct samr_Connect2 conn;
340 struct samr_EnumDomains enumdom;
341 uint32_t resume_handle = 0;
342 struct samr_LookupDomain l;
344 struct lsa_String domain_name;
345 struct lsa_String user_name;
346 struct samr_OpenDomain o;
347 struct samr_CreateUser2 c;
348 uint32_t user_rid,access_granted;
350 samr_pipe = dcerpc_pipe_init(mem_ctx,
351 cli->transport->socket->event.ctx,
352 lp_iconv_convenience(lp_ctx));
353 if (samr_pipe == NULL) {
354 d_printf("dcerpc_pipe_init failed\n");
355 status = NT_STATUS_NO_MEMORY;
359 status = dcerpc_pipe_open_smb(samr_pipe, cli->tree, "\\samr");
360 if (!NT_STATUS_IS_OK(status)) {
361 d_printf("dcerpc_pipe_open_smb failed: %s\n",
366 if (admin_creds != NULL) {
367 status = dcerpc_bind_auth(samr_pipe, &ndr_table_samr,
368 admin_creds, lp_ctx, auth_type, auth_level,
370 if (!NT_STATUS_IS_OK(status)) {
371 d_printf("dcerpc_bind_auth failed: %s\n",
376 /* We must have an authenticated SMB connection */
377 status = dcerpc_bind_auth_none(samr_pipe, &ndr_table_samr);
378 if (!NT_STATUS_IS_OK(status)) {
379 d_printf("dcerpc_bind_auth_none failed: %s\n",
385 conn.in.system_name = talloc_asprintf(
386 mem_ctx, "\\\\%s", dcerpc_server_name(samr_pipe));
387 conn.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
388 conn.out.connect_handle = &conn_handle;
390 status = dcerpc_samr_Connect2(samr_pipe, mem_ctx, &conn);
391 if (!NT_STATUS_IS_OK(status)) {
392 d_printf("samr_Connect2 failed: %s\n", nt_errstr(status));
396 enumdom.in.connect_handle = &conn_handle;
397 enumdom.in.resume_handle = &resume_handle;
398 enumdom.in.buf_size = (uint32_t)-1;
399 enumdom.out.resume_handle = &resume_handle;
401 status = dcerpc_samr_EnumDomains(samr_pipe, mem_ctx, &enumdom);
402 if (!NT_STATUS_IS_OK(status)) {
403 d_printf("samr_EnumDomains failed: %s\n", nt_errstr(status));
407 if (enumdom.out.num_entries != 2) {
408 d_printf("samr_EnumDomains returned %d entries, expected 2\n",
409 enumdom.out.num_entries);
410 status = NT_STATUS_UNSUCCESSFUL;
414 dom_idx = strequal(enumdom.out.sam->entries[0].name.string,
417 l.in.connect_handle = &conn_handle;
418 domain_name.string = enumdom.out.sam->entries[0].name.string;
419 *domain = talloc_strdup(mem_ctx, domain_name.string);
420 l.in.domain_name = &domain_name;
422 status = dcerpc_samr_LookupDomain(samr_pipe, mem_ctx, &l);
423 if (!NT_STATUS_IS_OK(status)) {
424 d_printf("samr_LookupDomain failed: %s\n", nt_errstr(status));
428 o.in.connect_handle = &conn_handle;
429 o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
430 o.in.sid = l.out.sid;
431 o.out.domain_handle = &domain_handle;
433 status = dcerpc_samr_OpenDomain(samr_pipe, mem_ctx, &o);
434 if (!NT_STATUS_IS_OK(status)) {
435 d_printf("samr_OpenDomain failed: %s\n", nt_errstr(status));
439 c.in.domain_handle = &domain_handle;
440 user_name.string = username;
441 c.in.account_name = &user_name;
442 c.in.acct_flags = ACB_NORMAL;
443 c.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
444 user_handle = talloc(mem_ctx, struct policy_handle);
445 c.out.user_handle = user_handle;
446 c.out.access_granted = &access_granted;
447 c.out.rid = &user_rid;
449 status = dcerpc_samr_CreateUser2(samr_pipe, mem_ctx, &c);
451 if (NT_STATUS_EQUAL(status, NT_STATUS_USER_EXISTS)) {
452 struct samr_LookupNames ln;
453 struct samr_OpenUser ou;
455 ln.in.domain_handle = &domain_handle;
457 ln.in.names = &user_name;
459 status = dcerpc_samr_LookupNames(samr_pipe, mem_ctx, &ln);
460 if (!NT_STATUS_IS_OK(status)) {
461 d_printf("samr_LookupNames failed: %s\n",
466 ou.in.domain_handle = &domain_handle;
467 ou.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
468 user_rid = ou.in.rid = ln.out.rids.ids[0];
469 ou.out.user_handle = user_handle;
471 status = dcerpc_samr_OpenUser(samr_pipe, mem_ctx, &ou);
472 if (!NT_STATUS_IS_OK(status)) {
473 d_printf("samr_OpenUser failed: %s\n",
479 if (!NT_STATUS_IS_OK(status)) {
480 d_printf("samr_CreateUser failed: %s\n", nt_errstr(status));
484 *result_pipe = samr_pipe;
485 *result_handle = user_handle;
487 *sid = dom_sid_add_rid(mem_ctx, l.out.sid, user_rid);
499 static bool create_user(TALLOC_CTX *mem_ctx, struct smbcli_state *cli,
500 struct loadparm_context *lp_ctx,
501 struct cli_credentials *admin_creds,
502 const char *username, const char *password,
504 struct dom_sid **user_sid)
508 struct dcerpc_pipe *samr_pipe;
509 struct policy_handle *wks_handle;
512 if (!(tmp_ctx = talloc_new(mem_ctx))) {
513 d_printf("talloc_init failed\n");
517 status = get_usr_handle(cli, tmp_ctx, lp_ctx, admin_creds,
518 DCERPC_AUTH_TYPE_NTLMSSP,
519 DCERPC_AUTH_LEVEL_INTEGRITY,
520 username, domain_name, &samr_pipe, &wks_handle,
522 if (!NT_STATUS_IS_OK(status)) {
523 d_printf("get_wks_handle failed: %s\n", nt_errstr(status));
528 struct samr_SetUserInfo2 sui2;
529 struct samr_SetUserInfo sui;
530 struct samr_QueryUserInfo qui;
531 union samr_UserInfo u_info;
532 DATA_BLOB session_key;
536 encode_pw_buffer(u_info.info23.password.data, password,
539 status = dcerpc_fetch_session_key(samr_pipe, &session_key);
540 if (!NT_STATUS_IS_OK(status)) {
541 d_printf("dcerpc_fetch_session_key failed\n");
544 arcfour_crypt_blob(u_info.info23.password.data, 516,
546 u_info.info23.info.password_expired = 0;
547 u_info.info23.info.fields_present = SAMR_FIELD_PASSWORD |
548 SAMR_FIELD_PASSWORD2 |
549 SAMR_FIELD_EXPIRED_FLAG;
550 sui2.in.user_handle = wks_handle;
551 sui2.in.info = &u_info;
554 status = dcerpc_samr_SetUserInfo2(samr_pipe, tmp_ctx, &sui2);
555 if (!NT_STATUS_IS_OK(status)) {
556 d_printf("samr_SetUserInfo(23) failed: %s\n",
561 u_info.info16.acct_flags = ACB_NORMAL;
562 sui.in.user_handle = wks_handle;
563 sui.in.info = &u_info;
566 status = dcerpc_samr_SetUserInfo(samr_pipe, tmp_ctx, &sui);
567 if (!NT_STATUS_IS_OK(status)) {
568 d_printf("samr_SetUserInfo(16) failed\n");
572 qui.in.user_handle = wks_handle;
575 status = dcerpc_samr_QueryUserInfo(samr_pipe, tmp_ctx, &qui);
576 if (!NT_STATUS_IS_OK(status)) {
577 d_printf("samr_QueryUserInfo(21) failed\n");
581 qui.out.info->info21.allow_password_change = 0;
582 qui.out.info->info21.force_password_change = 0;
583 qui.out.info->info21.account_name.string = NULL;
584 qui.out.info->info21.rid = 0;
585 qui.out.info->info21.acct_expiry = 0;
586 qui.out.info->info21.fields_present = 0x81827fa; /* copy usrmgr.exe */
588 u_info.info21 = qui.out.info->info21;
589 sui.in.user_handle = wks_handle;
590 sui.in.info = &u_info;
593 status = dcerpc_samr_SetUserInfo(samr_pipe, tmp_ctx, &sui);
594 if (!NT_STATUS_IS_OK(status)) {
595 d_printf("samr_SetUserInfo(21) failed\n");
600 *domain_name= talloc_steal(mem_ctx, *domain_name);
601 *user_sid = talloc_steal(mem_ctx, *user_sid);
604 talloc_free(tmp_ctx);
612 static bool delete_user(struct smbcli_state *cli,
613 struct loadparm_context *lp_ctx,
614 struct cli_credentials *admin_creds,
615 const char *username)
620 struct dcerpc_pipe *samr_pipe;
621 struct policy_handle *user_handle;
624 if ((mem_ctx = talloc_init("leave")) == NULL) {
625 d_printf("talloc_init failed\n");
629 status = get_usr_handle(cli, mem_ctx, lp_ctx, admin_creds,
630 DCERPC_AUTH_TYPE_NTLMSSP,
631 DCERPC_AUTH_LEVEL_INTEGRITY,
632 username, &dom_name, &samr_pipe,
635 if (!NT_STATUS_IS_OK(status)) {
636 d_printf("get_wks_handle failed: %s\n", nt_errstr(status));
641 struct samr_DeleteUser d;
643 d.in.user_handle = user_handle;
644 d.out.user_handle = user_handle;
646 status = dcerpc_samr_DeleteUser(samr_pipe, mem_ctx, &d);
647 if (!NT_STATUS_IS_OK(status)) {
648 d_printf("samr_DeleteUser failed %s\n", nt_errstr(status));
656 talloc_free(mem_ctx);
661 * Do a Samba3-style join
664 static bool join3(struct smbcli_state *cli,
665 struct loadparm_context *lp_ctx,
667 struct cli_credentials *admin_creds,
668 struct cli_credentials *wks_creds)
673 struct dcerpc_pipe *samr_pipe;
674 struct policy_handle *wks_handle;
677 if ((mem_ctx = talloc_init("join3")) == NULL) {
678 d_printf("talloc_init failed\n");
682 status = get_usr_handle(
683 cli, mem_ctx, lp_ctx, admin_creds,
684 DCERPC_AUTH_TYPE_NTLMSSP,
685 DCERPC_AUTH_LEVEL_PRIVACY,
686 talloc_asprintf(mem_ctx, "%s$",
687 cli_credentials_get_workstation(wks_creds)),
688 &dom_name, &samr_pipe, &wks_handle, NULL);
690 if (!NT_STATUS_IS_OK(status)) {
691 d_printf("get_wks_handle failed: %s\n", nt_errstr(status));
695 cli_credentials_set_domain(wks_creds, dom_name, CRED_SPECIFIED);
698 struct samr_SetUserInfo2 sui2;
699 union samr_UserInfo u_info;
700 struct samr_UserInfo21 *i21 = &u_info.info25.info;
701 DATA_BLOB session_key;
702 DATA_BLOB confounded_session_key = data_blob_talloc(
704 struct MD5Context ctx;
705 uint8_t confounder[16];
709 i21->full_name.string = talloc_asprintf(
711 cli_credentials_get_workstation(wks_creds));
712 i21->acct_flags = ACB_WSTRUST;
713 i21->fields_present = SAMR_FIELD_FULL_NAME |
714 SAMR_FIELD_ACCT_FLAGS | SAMR_FIELD_PASSWORD;
716 encode_pw_buffer(u_info.info25.password.data,
717 cli_credentials_get_password(wks_creds),
719 status = dcerpc_fetch_session_key(samr_pipe, &session_key);
720 if (!NT_STATUS_IS_OK(status)) {
721 d_printf("dcerpc_fetch_session_key failed: %s\n",
725 generate_random_buffer((uint8_t *)confounder, 16);
728 MD5Update(&ctx, confounder, 16);
729 MD5Update(&ctx, session_key.data, session_key.length);
730 MD5Final(confounded_session_key.data, &ctx);
732 arcfour_crypt_blob(u_info.info25.password.data, 516,
733 &confounded_session_key);
734 memcpy(&u_info.info25.password.data[516], confounder, 16);
736 sui2.in.user_handle = wks_handle;
738 sui2.in.info = &u_info;
740 status = dcerpc_samr_SetUserInfo2(samr_pipe, mem_ctx, &sui2);
741 if (!NT_STATUS_IS_OK(status)) {
742 d_printf("samr_SetUserInfo2(25) failed: %s\n",
747 struct samr_SetUserInfo2 sui2;
748 struct samr_SetUserInfo sui;
749 union samr_UserInfo u_info;
750 DATA_BLOB session_key;
752 encode_pw_buffer(u_info.info24.password.data,
753 cli_credentials_get_password(wks_creds),
755 u_info.info24.pw_len =
756 strlen_m(cli_credentials_get_password(wks_creds))*2;
758 status = dcerpc_fetch_session_key(samr_pipe, &session_key);
759 if (!NT_STATUS_IS_OK(status)) {
760 d_printf("dcerpc_fetch_session_key failed\n");
763 arcfour_crypt_blob(u_info.info24.password.data, 516,
765 sui2.in.user_handle = wks_handle;
766 sui2.in.info = &u_info;
769 status = dcerpc_samr_SetUserInfo2(samr_pipe, mem_ctx, &sui2);
770 if (!NT_STATUS_IS_OK(status)) {
771 d_printf("samr_SetUserInfo(24) failed: %s\n",
776 u_info.info16.acct_flags = ACB_WSTRUST;
777 sui.in.user_handle = wks_handle;
778 sui.in.info = &u_info;
781 status = dcerpc_samr_SetUserInfo(samr_pipe, mem_ctx, &sui);
782 if (!NT_STATUS_IS_OK(status)) {
783 d_printf("samr_SetUserInfo(16) failed\n");
791 talloc_free(mem_ctx);
796 * Do a ReqChallenge/Auth2 and get the wks creds
799 static bool auth2(struct smbcli_state *cli,
800 struct cli_credentials *wks_cred)
803 struct dcerpc_pipe *net_pipe;
806 struct netr_ServerReqChallenge r;
807 struct netr_Credential netr_cli_creds;
808 struct netr_Credential netr_srv_creds;
809 uint32_t negotiate_flags;
810 struct netr_ServerAuthenticate2 a;
811 struct creds_CredentialState *creds_state;
812 struct netr_Credential netr_cred;
813 struct samr_Password mach_pw;
815 mem_ctx = talloc_new(NULL);
816 if (mem_ctx == NULL) {
817 d_printf("talloc_new failed\n");
821 net_pipe = dcerpc_pipe_init(mem_ctx,
822 cli->transport->socket->event.ctx,
823 lp_iconv_convenience(global_loadparm));
824 if (net_pipe == NULL) {
825 d_printf("dcerpc_pipe_init failed\n");
829 status = dcerpc_pipe_open_smb(net_pipe, cli->tree, "\\netlogon");
830 if (!NT_STATUS_IS_OK(status)) {
831 d_printf("dcerpc_pipe_open_smb failed: %s\n",
836 status = dcerpc_bind_auth_none(net_pipe, &ndr_table_netlogon);
837 if (!NT_STATUS_IS_OK(status)) {
838 d_printf("dcerpc_bind_auth_none failed: %s\n",
843 r.in.computer_name = cli_credentials_get_workstation(wks_cred);
844 r.in.server_name = talloc_asprintf(
845 mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
846 if (r.in.server_name == NULL) {
847 d_printf("talloc_asprintf failed\n");
850 generate_random_buffer(netr_cli_creds.data,
851 sizeof(netr_cli_creds.data));
852 r.in.credentials = &netr_cli_creds;
853 r.out.credentials = &netr_srv_creds;
855 status = dcerpc_netr_ServerReqChallenge(net_pipe, mem_ctx, &r);
856 if (!NT_STATUS_IS_OK(status)) {
857 d_printf("netr_ServerReqChallenge failed: %s\n",
862 negotiate_flags = NETLOGON_NEG_AUTH2_FLAGS;
863 E_md4hash(cli_credentials_get_password(wks_cred), mach_pw.hash);
865 creds_state = talloc(mem_ctx, struct creds_CredentialState);
866 creds_client_init(creds_state, r.in.credentials,
867 r.out.credentials, &mach_pw,
868 &netr_cred, negotiate_flags);
870 a.in.server_name = talloc_asprintf(
871 mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
872 a.in.account_name = talloc_asprintf(
873 mem_ctx, "%s$", cli_credentials_get_workstation(wks_cred));
874 a.in.computer_name = cli_credentials_get_workstation(wks_cred);
875 a.in.secure_channel_type = SEC_CHAN_WKSTA;
876 a.in.negotiate_flags = &negotiate_flags;
877 a.out.negotiate_flags = &negotiate_flags;
878 a.in.credentials = &netr_cred;
879 a.out.credentials = &netr_cred;
881 status = dcerpc_netr_ServerAuthenticate2(net_pipe, mem_ctx, &a);
882 if (!NT_STATUS_IS_OK(status)) {
883 d_printf("netr_ServerServerAuthenticate2 failed: %s\n",
888 if (!creds_client_check(creds_state, a.out.credentials)) {
889 d_printf("creds_client_check failed\n");
893 cli_credentials_set_netlogon_creds(wks_cred, creds_state);
898 talloc_free(mem_ctx);
903 * Do a couple of schannel protected Netlogon ops: Interactive and Network
904 * login, and change the wks password
907 static bool schan(struct smbcli_state *cli,
908 struct loadparm_context *lp_ctx,
909 struct cli_credentials *wks_creds,
910 struct cli_credentials *user_creds)
915 struct dcerpc_pipe *net_pipe;
918 mem_ctx = talloc_new(NULL);
919 if (mem_ctx == NULL) {
920 d_printf("talloc_new failed\n");
924 net_pipe = dcerpc_pipe_init(mem_ctx,
925 cli->transport->socket->event.ctx,
926 lp_iconv_convenience(lp_ctx));
927 if (net_pipe == NULL) {
928 d_printf("dcerpc_pipe_init failed\n");
932 status = dcerpc_pipe_open_smb(net_pipe, cli->tree, "\\netlogon");
933 if (!NT_STATUS_IS_OK(status)) {
934 d_printf("dcerpc_pipe_open_smb failed: %s\n",
940 net_pipe->conn->flags |= DCERPC_DEBUG_PRINT_IN |
941 DCERPC_DEBUG_PRINT_OUT;
944 net_pipe->conn->flags |= (DCERPC_SIGN | DCERPC_SEAL);
945 status = dcerpc_bind_auth(net_pipe, &ndr_table_netlogon,
946 wks_creds, lp_ctx, DCERPC_AUTH_TYPE_SCHANNEL,
947 DCERPC_AUTH_LEVEL_PRIVACY,
950 status = dcerpc_bind_auth_none(net_pipe, &ndr_table_netlogon);
952 if (!NT_STATUS_IS_OK(status)) {
953 d_printf("schannel bind failed: %s\n", nt_errstr(status));
958 for (i=2; i<4; i++) {
960 DATA_BLOB chal, nt_resp, lm_resp, names_blob, session_key;
961 struct creds_CredentialState *creds_state;
962 struct netr_Authenticator netr_auth, netr_auth2;
963 struct netr_NetworkInfo ninfo;
964 struct netr_PasswordInfo pinfo;
965 struct netr_LogonSamLogon r;
967 flags = CLI_CRED_LANMAN_AUTH | CLI_CRED_NTLM_AUTH |
968 CLI_CRED_NTLMv2_AUTH;
970 chal = data_blob_talloc(mem_ctx, NULL, 8);
971 if (chal.data == NULL) {
972 d_printf("data_blob_talloc failed\n");
976 generate_random_buffer(chal.data, chal.length);
977 names_blob = NTLMv2_generate_names_blob(
978 mem_ctx, cli_credentials_get_workstation(user_creds),
979 cli_credentials_get_domain(user_creds));
980 status = cli_credentials_get_ntlm_response(
981 user_creds, mem_ctx, &flags, chal, names_blob,
982 &lm_resp, &nt_resp, NULL, NULL);
983 if (!NT_STATUS_IS_OK(status)) {
984 d_printf("cli_credentials_get_ntlm_response failed:"
985 " %s\n", nt_errstr(status));
989 creds_state = cli_credentials_get_netlogon_creds(wks_creds);
990 creds_client_authenticator(creds_state, &netr_auth);
992 ninfo.identity_info.account_name.string =
993 cli_credentials_get_username(user_creds);
994 ninfo.identity_info.domain_name.string =
995 cli_credentials_get_domain(user_creds);
996 ninfo.identity_info.parameter_control = 0;
997 ninfo.identity_info.logon_id_low = 0;
998 ninfo.identity_info.logon_id_high = 0;
999 ninfo.identity_info.workstation.string =
1000 cli_credentials_get_workstation(user_creds);
1001 memcpy(ninfo.challenge, chal.data, sizeof(ninfo.challenge));
1002 ninfo.nt.length = nt_resp.length;
1003 ninfo.nt.data = nt_resp.data;
1004 ninfo.lm.length = lm_resp.length;
1005 ninfo.lm.data = lm_resp.data;
1007 r.in.server_name = talloc_asprintf(
1008 mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
1009 ZERO_STRUCT(netr_auth2);
1010 r.in.computer_name =
1011 cli_credentials_get_workstation(wks_creds);
1012 r.in.credential = &netr_auth;
1013 r.in.return_authenticator = &netr_auth2;
1014 r.in.logon_level = 2;
1015 r.in.validation_level = i;
1016 r.in.logon.network = &ninfo;
1017 r.out.return_authenticator = NULL;
1019 status = dcerpc_netr_LogonSamLogon(net_pipe, mem_ctx, &r);
1020 if (!NT_STATUS_IS_OK(status)) {
1021 d_printf("netr_LogonSamLogon failed: %s\n",
1026 if ((r.out.return_authenticator == NULL) ||
1027 (!creds_client_check(creds_state,
1028 &r.out.return_authenticator->cred))) {
1029 d_printf("Credentials check failed!\n");
1033 creds_client_authenticator(creds_state, &netr_auth);
1035 pinfo.identity_info = ninfo.identity_info;
1036 ZERO_STRUCT(pinfo.lmpassword.hash);
1037 E_md4hash(cli_credentials_get_password(user_creds),
1038 pinfo.ntpassword.hash);
1039 session_key = data_blob_talloc(mem_ctx,
1040 creds_state->session_key, 16);
1041 arcfour_crypt_blob(pinfo.ntpassword.hash,
1042 sizeof(pinfo.ntpassword.hash),
1045 r.in.logon_level = 1;
1046 r.in.logon.password = &pinfo;
1047 r.out.return_authenticator = NULL;
1049 status = dcerpc_netr_LogonSamLogon(net_pipe, mem_ctx, &r);
1050 if (!NT_STATUS_IS_OK(status)) {
1051 d_printf("netr_LogonSamLogon failed: %s\n",
1056 if ((r.out.return_authenticator == NULL) ||
1057 (!creds_client_check(creds_state,
1058 &r.out.return_authenticator->cred))) {
1059 d_printf("Credentials check failed!\n");
1065 struct netr_ServerPasswordSet s;
1066 char *password = generate_random_str(wks_creds, 8);
1067 struct creds_CredentialState *creds_state;
1069 s.in.server_name = talloc_asprintf(
1070 mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
1071 s.in.computer_name = cli_credentials_get_workstation(wks_creds);
1072 s.in.account_name = talloc_asprintf(
1073 mem_ctx, "%s$", s.in.computer_name);
1074 s.in.secure_channel_type = SEC_CHAN_WKSTA;
1075 E_md4hash(password, s.in.new_password.hash);
1077 creds_state = cli_credentials_get_netlogon_creds(wks_creds);
1078 creds_des_encrypt(creds_state, &s.in.new_password);
1079 creds_client_authenticator(creds_state, &s.in.credential);
1081 status = dcerpc_netr_ServerPasswordSet(net_pipe, mem_ctx, &s);
1082 if (!NT_STATUS_IS_OK(status)) {
1083 printf("ServerPasswordSet - %s\n", nt_errstr(status));
1087 if (!creds_client_check(creds_state,
1088 &s.out.return_authenticator.cred)) {
1089 printf("Credential chaining failed\n");
1092 cli_credentials_set_password(wks_creds, password,
1098 talloc_free(mem_ctx);
1103 * Delete the wks account again
1106 static bool leave(struct smbcli_state *cli,
1107 struct loadparm_context *lp_ctx,
1108 struct cli_credentials *admin_creds,
1109 struct cli_credentials *wks_creds)
1111 char *wks_name = talloc_asprintf(
1112 NULL, "%s$", cli_credentials_get_workstation(wks_creds));
1115 ret = delete_user(cli, lp_ctx, admin_creds, wks_name);
1116 talloc_free(wks_name);
1121 * Test the Samba3 DC code a bit. Join, do some schan netlogon ops, leave
1124 bool torture_netlogon_samba3(struct torture_context *torture)
1126 TALLOC_CTX *mem_ctx;
1129 struct smbcli_state *cli;
1130 struct cli_credentials *anon_creds;
1131 struct cli_credentials *wks_creds;
1132 const char *wks_name;
1135 wks_name = torture_setting_string(torture, "wksname", NULL);
1136 if (wks_name == NULL) {
1137 wks_name = get_myname();
1140 mem_ctx = talloc_init("torture_netlogon_samba3");
1142 if (mem_ctx == NULL) {
1143 d_printf("talloc_init failed\n");
1147 if (!(anon_creds = cli_credentials_init_anon(mem_ctx))) {
1148 d_printf("create_anon_creds failed\n");
1152 status = smbcli_full_connection(mem_ctx, &cli,
1153 torture_setting_string(torture, "host", NULL),
1154 lp_smb_ports(torture->lp_ctx),
1155 "IPC$", NULL, anon_creds, NULL);
1156 if (!NT_STATUS_IS_OK(status)) {
1157 d_printf("smbcli_full_connection failed: %s\n",
1162 wks_creds = cli_credentials_init(mem_ctx);
1163 if (wks_creds == NULL) {
1164 d_printf("cli_credentials_init failed\n");
1168 cli_credentials_set_conf(wks_creds, torture->lp_ctx);
1169 cli_credentials_set_secure_channel_type(wks_creds, SEC_CHAN_WKSTA);
1170 cli_credentials_set_username(wks_creds, wks_name, CRED_SPECIFIED);
1171 cli_credentials_set_workstation(wks_creds, wks_name, CRED_SPECIFIED);
1172 cli_credentials_set_password(wks_creds,
1173 generate_random_str(wks_creds, 8),
1176 if (!join3(cli, torture->lp_ctx, false, cmdline_credentials, wks_creds)) {
1177 d_printf("join failed\n");
1181 cli_credentials_set_domain(
1182 cmdline_credentials, cli_credentials_get_domain(wks_creds),
1185 for (i=0; i<2; i++) {
1187 /* Do this more than once, the routine "schan" changes
1188 * the workstation password using the netlogon
1189 * password change routine */
1193 if (!auth2(cli, wks_creds)) {
1194 d_printf("auth2 failed\n");
1198 for (j=0; j<2; j++) {
1199 if (!schan(cli, torture->lp_ctx, wks_creds, cmdline_credentials)) {
1200 d_printf("schan failed\n");
1206 if (!leave(cli, torture->lp_ctx, cmdline_credentials, wks_creds)) {
1207 d_printf("leave failed\n");
1214 talloc_free(mem_ctx);
1219 * Do a simple join, testjoin and leave using specified smb and samr
1223 static bool test_join3(struct torture_context *tctx,
1225 struct cli_credentials *smb_creds,
1226 struct cli_credentials *samr_creds,
1227 const char *wks_name)
1231 struct smbcli_state *cli;
1232 struct cli_credentials *wks_creds;
1234 status = smbcli_full_connection(tctx, &cli,
1235 torture_setting_string(tctx, "host", NULL),
1236 lp_smb_ports(tctx->lp_ctx),
1237 "IPC$", NULL, smb_creds, NULL);
1238 if (!NT_STATUS_IS_OK(status)) {
1239 d_printf("smbcli_full_connection failed: %s\n",
1244 wks_creds = cli_credentials_init(cli);
1245 if (wks_creds == NULL) {
1246 d_printf("cli_credentials_init failed\n");
1250 cli_credentials_set_conf(wks_creds, tctx->lp_ctx);
1251 cli_credentials_set_secure_channel_type(wks_creds, SEC_CHAN_WKSTA);
1252 cli_credentials_set_username(wks_creds, wks_name, CRED_SPECIFIED);
1253 cli_credentials_set_workstation(wks_creds, wks_name, CRED_SPECIFIED);
1254 cli_credentials_set_password(wks_creds,
1255 generate_random_str(wks_creds, 8),
1258 if (!join3(cli, tctx->lp_ctx, use_level25, samr_creds, wks_creds)) {
1259 d_printf("join failed\n");
1263 cli_credentials_set_domain(
1264 cmdline_credentials, cli_credentials_get_domain(wks_creds),
1267 if (!auth2(cli, wks_creds)) {
1268 d_printf("auth2 failed\n");
1272 if (!leave(cli, tctx->lp_ctx, samr_creds, wks_creds)) {
1273 d_printf("leave failed\n");
1286 * Test the different session key variants. Do it by joining, this uses the
1287 * session key in the setpassword routine. Test the join by doing the auth2.
1290 bool torture_samba3_sessionkey(struct torture_context *torture)
1293 struct cli_credentials *anon_creds;
1294 const char *wks_name;
1296 wks_name = torture_setting_string(torture, "wksname", get_myname());
1298 if (!(anon_creds = cli_credentials_init_anon(torture))) {
1299 d_printf("create_anon_creds failed\n");
1305 if (!torture_setting_bool(torture, "samba3", false)) {
1307 /* Samba3 in the build farm right now does this happily. Need
1310 if (test_join3(torture, false, anon_creds, NULL, wks_name)) {
1311 d_printf("join using anonymous bind on an anonymous smb "
1312 "connection succeeded -- HUH??\n");
1317 if (!test_join3(torture, false, anon_creds, cmdline_credentials,
1319 d_printf("join using ntlmssp bind on an anonymous smb "
1320 "connection failed\n");
1324 if (!test_join3(torture, false, cmdline_credentials, NULL, wks_name)) {
1325 d_printf("join using anonymous bind on an authenticated smb "
1326 "connection failed\n");
1330 if (!test_join3(torture, false, cmdline_credentials,
1331 cmdline_credentials,
1333 d_printf("join using ntlmssp bind on an authenticated smb "
1334 "connection failed\n");
1339 * The following two are tests for setuserinfolevel 25
1342 if (!test_join3(torture, true, anon_creds, cmdline_credentials,
1344 d_printf("join using ntlmssp bind on an anonymous smb "
1345 "connection failed\n");
1349 if (!test_join3(torture, true, cmdline_credentials, NULL, wks_name)) {
1350 d_printf("join using anonymous bind on an authenticated smb "
1351 "connection failed\n");
1361 * open pipe and bind, given an IPC$ context
1364 static NTSTATUS pipe_bind_smb(TALLOC_CTX *mem_ctx,
1365 struct smbcli_tree *tree,
1366 const char *pipe_name,
1367 const struct ndr_interface_table *iface,
1368 struct dcerpc_pipe **p)
1370 struct dcerpc_pipe *result;
1373 if (!(result = dcerpc_pipe_init(
1374 mem_ctx, tree->session->transport->socket->event.ctx,
1375 lp_iconv_convenience(global_loadparm)))) {
1376 return NT_STATUS_NO_MEMORY;
1379 status = dcerpc_pipe_open_smb(result, tree, pipe_name);
1380 if (!NT_STATUS_IS_OK(status)) {
1381 d_printf("dcerpc_pipe_open_smb failed: %s\n",
1383 talloc_free(result);
1387 status = dcerpc_bind_auth_none(result, iface);
1388 if (!NT_STATUS_IS_OK(status)) {
1389 d_printf("schannel bind failed: %s\n", nt_errstr(status));
1390 talloc_free(result);
1395 return NT_STATUS_OK;
1399 * Sane wrapper around lsa_LookupNames
1402 static struct dom_sid *name2sid(TALLOC_CTX *mem_ctx,
1403 struct dcerpc_pipe *p,
1407 struct lsa_ObjectAttribute attr;
1408 struct lsa_QosInfo qos;
1409 struct lsa_OpenPolicy2 r;
1412 struct policy_handle handle;
1413 struct lsa_LookupNames l;
1414 struct lsa_TransSidArray sids;
1415 struct lsa_String lsa_name;
1417 struct dom_sid *result;
1418 TALLOC_CTX *tmp_ctx;
1420 if (!(tmp_ctx = talloc_new(mem_ctx))) {
1425 qos.impersonation_level = 2;
1426 qos.context_mode = 1;
1427 qos.effective_only = 0;
1430 attr.root_dir = NULL;
1431 attr.object_name = NULL;
1432 attr.attributes = 0;
1433 attr.sec_desc = NULL;
1434 attr.sec_qos = &qos;
1436 r.in.system_name = "\\";
1438 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1439 r.out.handle = &handle;
1441 status = dcerpc_lsa_OpenPolicy2(p, tmp_ctx, &r);
1442 if (!NT_STATUS_IS_OK(status)) {
1443 printf("OpenPolicy2 failed - %s\n", nt_errstr(status));
1444 talloc_free(tmp_ctx);
1451 lsa_name.string = talloc_asprintf(tmp_ctx, "%s\\%s", domain, name);
1453 l.in.handle = &handle;
1455 l.in.names = &lsa_name;
1458 l.in.count = &count;
1459 l.out.count = &count;
1462 status = dcerpc_lsa_LookupNames(p, tmp_ctx, &l);
1463 if (!NT_STATUS_IS_OK(status)) {
1464 printf("LookupNames of %s failed - %s\n", lsa_name.string,
1466 talloc_free(tmp_ctx);
1470 result = dom_sid_add_rid(mem_ctx, l.out.domains->domains[0].sid,
1471 l.out.sids->sids[0].rid);
1473 c.in.handle = &handle;
1474 c.out.handle = &handle;
1476 status = dcerpc_lsa_Close(p, tmp_ctx, &c);
1477 if (!NT_STATUS_IS_OK(status)) {
1478 printf("dcerpc_lsa_Close failed - %s\n", nt_errstr(status));
1479 talloc_free(tmp_ctx);
1483 talloc_free(tmp_ctx);
1488 * Find out the user SID on this connection
1491 static struct dom_sid *whoami(TALLOC_CTX *mem_ctx, struct smbcli_tree *tree)
1493 struct dcerpc_pipe *lsa;
1494 struct lsa_GetUserName r;
1496 struct lsa_StringPointer authority_name_p;
1497 struct dom_sid *result;
1499 status = pipe_bind_smb(mem_ctx, tree, "\\pipe\\lsarpc",
1500 &ndr_table_lsarpc, &lsa);
1501 if (!NT_STATUS_IS_OK(status)) {
1502 d_printf("(%s) Could not bind to LSA: %s\n",
1503 __location__, nt_errstr(status));
1507 r.in.system_name = "\\";
1508 r.in.account_name = NULL;
1509 authority_name_p.string = NULL;
1510 r.in.authority_name = &authority_name_p;
1512 status = dcerpc_lsa_GetUserName(lsa, mem_ctx, &r);
1514 if (!NT_STATUS_IS_OK(status)) {
1515 printf("(%s) GetUserName failed - %s\n",
1516 __location__, nt_errstr(status));
1521 result = name2sid(mem_ctx, lsa, r.out.account_name->string,
1522 r.out.authority_name->string->string);
1528 static int destroy_tree(struct smbcli_tree *tree)
1530 smb_tree_disconnect(tree);
1535 * Do a tcon, given a session
1538 NTSTATUS secondary_tcon(TALLOC_CTX *mem_ctx,
1539 struct smbcli_session *session,
1540 const char *sharename,
1541 struct smbcli_tree **res)
1543 struct smbcli_tree *result;
1544 TALLOC_CTX *tmp_ctx;
1545 union smb_tcon tcon;
1548 if (!(tmp_ctx = talloc_new(mem_ctx))) {
1549 return NT_STATUS_NO_MEMORY;
1552 if (!(result = smbcli_tree_init(session, mem_ctx, false))) {
1553 talloc_free(tmp_ctx);
1554 return NT_STATUS_NO_MEMORY;
1557 tcon.generic.level = RAW_TCON_TCONX;
1558 tcon.tconx.in.flags = 0;
1559 tcon.tconx.in.password = data_blob(NULL, 0);
1560 tcon.tconx.in.path = sharename;
1561 tcon.tconx.in.device = "?????";
1563 status = smb_raw_tcon(result, tmp_ctx, &tcon);
1564 if (!NT_STATUS_IS_OK(status)) {
1565 d_printf("(%s) smb_raw_tcon failed: %s\n", __location__,
1567 talloc_free(tmp_ctx);
1571 result->tid = tcon.tconx.out.tid;
1572 result = talloc_steal(mem_ctx, result);
1573 talloc_set_destructor(result, destroy_tree);
1574 talloc_free(tmp_ctx);
1576 return NT_STATUS_OK;
1580 * Test the getusername behaviour
1583 bool torture_samba3_rpc_getusername(struct torture_context *torture)
1586 struct smbcli_state *cli;
1587 TALLOC_CTX *mem_ctx;
1589 struct dom_sid *user_sid;
1590 struct dom_sid *created_sid;
1591 struct cli_credentials *anon_creds;
1592 struct cli_credentials *user_creds;
1595 if (!(mem_ctx = talloc_new(torture))) {
1599 status = smbcli_full_connection(
1600 mem_ctx, &cli, torture_setting_string(torture, "host", NULL),
1601 lp_smb_ports(torture->lp_ctx),
1602 "IPC$", NULL, cmdline_credentials, NULL);
1603 if (!NT_STATUS_IS_OK(status)) {
1604 d_printf("(%s) smbcli_full_connection failed: %s\n",
1605 __location__, nt_errstr(status));
1610 if (!(user_sid = whoami(mem_ctx, cli->tree))) {
1611 d_printf("(%s) whoami on auth'ed connection failed\n",
1618 if (!(anon_creds = cli_credentials_init_anon(mem_ctx))) {
1619 d_printf("(%s) create_anon_creds failed\n", __location__);
1624 status = smbcli_full_connection(
1625 mem_ctx, &cli, torture_setting_string(torture, "host", NULL),
1626 lp_smb_ports(torture->lp_ctx),
1627 "IPC$", NULL, anon_creds, NULL);
1628 if (!NT_STATUS_IS_OK(status)) {
1629 d_printf("(%s) anon smbcli_full_connection failed: %s\n",
1630 __location__, nt_errstr(status));
1635 if (!(user_sid = whoami(mem_ctx, cli->tree))) {
1636 d_printf("(%s) whoami on anon connection failed\n",
1642 if (!dom_sid_equal(user_sid,
1643 dom_sid_parse_talloc(mem_ctx, "s-1-5-7"))) {
1644 d_printf("(%s) Anon lsa_GetUserName returned %s, expected "
1645 "S-1-5-7", __location__,
1646 dom_sid_string(mem_ctx, user_sid));
1650 if (!(user_creds = cli_credentials_init(mem_ctx))) {
1651 d_printf("(%s) cli_credentials_init failed\n", __location__);
1656 cli_credentials_set_conf(user_creds, torture->lp_ctx);
1657 cli_credentials_set_username(user_creds, "torture_username",
1659 cli_credentials_set_password(user_creds,
1660 generate_random_str(user_creds, 8),
1663 if (!create_user(mem_ctx, cli, torture->lp_ctx, cmdline_credentials,
1664 cli_credentials_get_username(user_creds),
1665 cli_credentials_get_password(user_creds),
1666 &domain_name, &created_sid)) {
1667 d_printf("(%s) create_user failed\n", __location__);
1672 cli_credentials_set_domain(user_creds, domain_name,
1676 struct smbcli_session *session2;
1677 struct smb_composite_sesssetup setup;
1678 struct smbcli_tree *tree;
1680 session2 = smbcli_session_init(cli->transport, mem_ctx, false);
1681 if (session2 == NULL) {
1682 d_printf("(%s) smbcli_session_init failed\n",
1687 setup.in.sesskey = cli->transport->negotiate.sesskey;
1688 setup.in.capabilities = cli->transport->negotiate.capabilities;
1689 setup.in.workgroup = "";
1690 setup.in.credentials = user_creds;
1692 status = smb_composite_sesssetup(session2, &setup);
1693 if (!NT_STATUS_IS_OK(status)) {
1694 d_printf("(%s) session setup with new user failed: "
1695 "%s\n", __location__, nt_errstr(status));
1699 session2->vuid = setup.out.vuid;
1701 if (!NT_STATUS_IS_OK(secondary_tcon(mem_ctx, session2,
1703 d_printf("(%s) secondary_tcon failed\n",
1709 if (!(user_sid = whoami(mem_ctx, tree))) {
1710 d_printf("(%s) whoami on user connection failed\n",
1719 d_printf("Created %s, found %s\n",
1720 dom_sid_string(mem_ctx, created_sid),
1721 dom_sid_string(mem_ctx, user_sid));
1723 if (!dom_sid_equal(created_sid, user_sid)) {
1728 if (!delete_user(cli, torture->lp_ctx,
1729 cmdline_credentials,
1730 cli_credentials_get_username(user_creds))) {
1731 d_printf("(%s) delete_user failed\n", __location__);
1736 talloc_free(mem_ctx);
1740 static bool test_NetShareGetInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
1741 const char *sharename)
1744 struct srvsvc_NetShareGetInfo r;
1745 uint32_t levels[] = { 0, 1, 2, 501, 502, 1004, 1005, 1006, 1007, 1501 };
1749 r.in.server_unc = talloc_asprintf(mem_ctx, "\\\\%s",
1750 dcerpc_server_name(p));
1751 r.in.share_name = sharename;
1753 for (i=0;i<ARRAY_SIZE(levels);i++) {
1754 r.in.level = levels[i];
1758 printf("testing NetShareGetInfo level %u on share '%s'\n",
1759 r.in.level, r.in.share_name);
1761 status = dcerpc_srvsvc_NetShareGetInfo(p, mem_ctx, &r);
1762 if (!NT_STATUS_IS_OK(status)) {
1763 printf("NetShareGetInfo level %u on share '%s' failed"
1764 " - %s\n", r.in.level, r.in.share_name,
1769 if (!W_ERROR_IS_OK(r.out.result)) {
1770 printf("NetShareGetInfo level %u on share '%s' failed "
1771 "- %s\n", r.in.level, r.in.share_name,
1772 win_errstr(r.out.result));
1781 static bool test_NetShareEnum(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
1782 const char **one_sharename)
1785 struct srvsvc_NetShareEnum r;
1786 struct srvsvc_NetShareCtr0 c0;
1787 uint32_t levels[] = { 0, 1, 2, 501, 502, 1004, 1005, 1006, 1007 };
1791 r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
1792 r.in.ctr.ctr0 = &c0;
1793 r.in.ctr.ctr0->count = 0;
1794 r.in.ctr.ctr0->array = NULL;
1795 r.in.max_buffer = (uint32_t)-1;
1796 r.in.resume_handle = NULL;
1798 for (i=0;i<ARRAY_SIZE(levels);i++) {
1799 r.in.level = levels[i];
1803 printf("testing NetShareEnum level %u\n", r.in.level);
1804 status = dcerpc_srvsvc_NetShareEnum(p, mem_ctx, &r);
1805 if (!NT_STATUS_IS_OK(status)) {
1806 printf("NetShareEnum level %u failed - %s\n",
1807 r.in.level, nt_errstr(status));
1811 if (!W_ERROR_IS_OK(r.out.result)) {
1812 printf("NetShareEnum level %u failed - %s\n",
1813 r.in.level, win_errstr(r.out.result));
1816 if (r.in.level == 0) {
1817 struct srvsvc_NetShareCtr0 *ctr = r.out.ctr.ctr0;
1818 if (ctr->count > 0) {
1819 *one_sharename = ctr->array[0].name;
1827 bool torture_samba3_rpc_srvsvc(struct torture_context *torture)
1829 struct dcerpc_pipe *p;
1830 TALLOC_CTX *mem_ctx;
1832 const char *sharename = NULL;
1833 struct smbcli_state *cli;
1836 if (!(mem_ctx = talloc_new(torture))) {
1840 if (!(torture_open_connection_share(
1841 mem_ctx, &cli, torture, torture_setting_string(torture, "host", NULL),
1843 talloc_free(mem_ctx);
1847 status = pipe_bind_smb(mem_ctx, cli->tree, "\\pipe\\srvsvc",
1848 &ndr_table_srvsvc, &p);
1849 if (!NT_STATUS_IS_OK(status)) {
1850 d_printf("(%s) could not bind to srvsvc pipe: %s\n",
1851 __location__, nt_errstr(status));
1856 ret &= test_NetShareEnum(p, mem_ctx, &sharename);
1857 if (sharename == NULL) {
1858 printf("did not get sharename\n");
1860 ret &= test_NetShareGetInfo(p, mem_ctx, sharename);
1864 talloc_free(mem_ctx);
1869 * Do a ReqChallenge/Auth2 with a random wks name, make sure it returns
1870 * NT_STATUS_NO_SAM_ACCOUNT
1873 bool torture_samba3_rpc_randomauth2(struct torture_context *torture)
1875 TALLOC_CTX *mem_ctx;
1876 struct dcerpc_pipe *net_pipe;
1878 bool result = false;
1880 struct netr_ServerReqChallenge r;
1881 struct netr_Credential netr_cli_creds;
1882 struct netr_Credential netr_srv_creds;
1883 uint32_t negotiate_flags;
1884 struct netr_ServerAuthenticate2 a;
1885 struct creds_CredentialState *creds_state;
1886 struct netr_Credential netr_cred;
1887 struct samr_Password mach_pw;
1888 struct smbcli_state *cli;
1890 if (!(mem_ctx = talloc_new(torture))) {
1891 d_printf("talloc_new failed\n");
1895 if (!(wksname = generate_random_str_list(
1896 mem_ctx, 14, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"))) {
1897 d_printf("generate_random_str_list failed\n");
1901 if (!(torture_open_connection_share(
1903 torture, torture_setting_string(torture, "host", NULL),
1905 d_printf("IPC$ connection failed\n");
1909 if (!(net_pipe = dcerpc_pipe_init(
1910 mem_ctx, cli->transport->socket->event.ctx,
1911 lp_iconv_convenience(torture->lp_ctx)))) {
1912 d_printf("dcerpc_pipe_init failed\n");
1916 status = dcerpc_pipe_open_smb(net_pipe, cli->tree, "\\netlogon");
1917 if (!NT_STATUS_IS_OK(status)) {
1918 d_printf("dcerpc_pipe_open_smb failed: %s\n",
1923 status = dcerpc_bind_auth_none(net_pipe, &ndr_table_netlogon);
1924 if (!NT_STATUS_IS_OK(status)) {
1925 d_printf("dcerpc_bind_auth_none failed: %s\n",
1930 r.in.computer_name = wksname;
1931 r.in.server_name = talloc_asprintf(
1932 mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
1933 if (r.in.server_name == NULL) {
1934 d_printf("talloc_asprintf failed\n");
1937 generate_random_buffer(netr_cli_creds.data,
1938 sizeof(netr_cli_creds.data));
1939 r.in.credentials = &netr_cli_creds;
1940 r.out.credentials = &netr_srv_creds;
1942 status = dcerpc_netr_ServerReqChallenge(net_pipe, mem_ctx, &r);
1943 if (!NT_STATUS_IS_OK(status)) {
1944 d_printf("netr_ServerReqChallenge failed: %s\n",
1949 negotiate_flags = NETLOGON_NEG_AUTH2_FLAGS;
1950 E_md4hash("foobar", mach_pw.hash);
1952 creds_state = talloc(mem_ctx, struct creds_CredentialState);
1953 creds_client_init(creds_state, r.in.credentials,
1954 r.out.credentials, &mach_pw,
1955 &netr_cred, negotiate_flags);
1957 a.in.server_name = talloc_asprintf(
1958 mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
1959 a.in.account_name = talloc_asprintf(
1960 mem_ctx, "%s$", wksname);
1961 a.in.computer_name = wksname;
1962 a.in.secure_channel_type = SEC_CHAN_WKSTA;
1963 a.in.negotiate_flags = &negotiate_flags;
1964 a.out.negotiate_flags = &negotiate_flags;
1965 a.in.credentials = &netr_cred;
1966 a.out.credentials = &netr_cred;
1968 status = dcerpc_netr_ServerAuthenticate2(net_pipe, mem_ctx, &a);
1970 if (!NT_STATUS_EQUAL(status, NT_STATUS_NO_TRUST_SAM_ACCOUNT)) {
1971 d_printf("dcerpc_netr_ServerAuthenticate2 returned %s, "
1972 "expected NT_STATUS_NO_TRUST_SAM_ACCOUNT\n",
1979 talloc_free(mem_ctx);
1983 static struct security_descriptor *get_sharesec(TALLOC_CTX *mem_ctx,
1984 struct smbcli_session *sess,
1985 const char *sharename)
1987 struct smbcli_tree *tree;
1988 TALLOC_CTX *tmp_ctx;
1989 struct dcerpc_pipe *p;
1991 struct srvsvc_NetShareGetInfo r;
1992 struct security_descriptor *result;
1994 if (!(tmp_ctx = talloc_new(mem_ctx))) {
1995 d_printf("talloc_new failed\n");
1999 if (!NT_STATUS_IS_OK(secondary_tcon(tmp_ctx, sess, "IPC$", &tree))) {
2000 d_printf("secondary_tcon failed\n");
2001 talloc_free(tmp_ctx);
2005 status = pipe_bind_smb(mem_ctx, tree, "\\pipe\\srvsvc",
2006 &ndr_table_srvsvc, &p);
2007 if (!NT_STATUS_IS_OK(status)) {
2008 d_printf("(%s) could not bind to srvsvc pipe: %s\n",
2009 __location__, nt_errstr(status));
2010 talloc_free(tmp_ctx);
2015 p->conn->flags |= DCERPC_DEBUG_PRINT_IN | DCERPC_DEBUG_PRINT_OUT;
2018 r.in.server_unc = talloc_asprintf(tmp_ctx, "\\\\%s",
2019 dcerpc_server_name(p));
2020 r.in.share_name = sharename;
2023 status = dcerpc_srvsvc_NetShareGetInfo(p, tmp_ctx, &r);
2024 if (!NT_STATUS_IS_OK(status)) {
2025 d_printf("srvsvc_NetShareGetInfo failed: %s\n",
2027 talloc_free(tmp_ctx);
2031 result = talloc_steal(mem_ctx, r.out.info.info502->sd);
2032 talloc_free(tmp_ctx);
2036 static NTSTATUS set_sharesec(TALLOC_CTX *mem_ctx,
2037 struct smbcli_session *sess,
2038 const char *sharename,
2039 struct security_descriptor *sd)
2041 struct smbcli_tree *tree;
2042 TALLOC_CTX *tmp_ctx;
2043 struct dcerpc_pipe *p;
2045 struct sec_desc_buf i;
2046 struct srvsvc_NetShareSetInfo r;
2049 if (!(tmp_ctx = talloc_new(mem_ctx))) {
2050 d_printf("talloc_new failed\n");
2051 return NT_STATUS_NO_MEMORY;
2054 if (!NT_STATUS_IS_OK(secondary_tcon(tmp_ctx, sess, "IPC$", &tree))) {
2055 d_printf("secondary_tcon failed\n");
2056 talloc_free(tmp_ctx);
2057 return NT_STATUS_UNSUCCESSFUL;
2060 status = pipe_bind_smb(mem_ctx, tree, "\\pipe\\srvsvc",
2061 &ndr_table_srvsvc, &p);
2062 if (!NT_STATUS_IS_OK(status)) {
2063 d_printf("(%s) could not bind to srvsvc pipe: %s\n",
2064 __location__, nt_errstr(status));
2065 talloc_free(tmp_ctx);
2066 return NT_STATUS_UNSUCCESSFUL;
2070 p->conn->flags |= DCERPC_DEBUG_PRINT_IN | DCERPC_DEBUG_PRINT_OUT;
2073 r.in.server_unc = talloc_asprintf(tmp_ctx, "\\\\%s",
2074 dcerpc_server_name(p));
2075 r.in.share_name = sharename;
2078 r.in.info.info1501 = &i;
2079 r.in.parm_error = &error;
2081 status = dcerpc_srvsvc_NetShareSetInfo(p, tmp_ctx, &r);
2082 if (!NT_STATUS_IS_OK(status)) {
2083 d_printf("srvsvc_NetShareGetInfo failed: %s\n",
2087 talloc_free(tmp_ctx);
2091 bool try_tcon(TALLOC_CTX *mem_ctx,
2092 struct security_descriptor *orig_sd,
2093 struct smbcli_session *session,
2094 const char *sharename, const struct dom_sid *user_sid,
2095 unsigned int access_mask, NTSTATUS expected_tcon,
2096 NTSTATUS expected_mkdir)
2098 TALLOC_CTX *tmp_ctx;
2099 struct smbcli_tree *rmdir_tree, *tree;
2100 struct dom_sid *domain_sid;
2102 struct security_descriptor *sd;
2106 if (!(tmp_ctx = talloc_new(mem_ctx))) {
2107 d_printf("talloc_new failed\n");
2111 status = secondary_tcon(tmp_ctx, session, sharename, &rmdir_tree);
2112 if (!NT_STATUS_IS_OK(status)) {
2113 d_printf("first tcon to delete dir failed\n");
2114 talloc_free(tmp_ctx);
2118 smbcli_rmdir(rmdir_tree, "sharesec_testdir");
2120 if (!NT_STATUS_IS_OK(dom_sid_split_rid(tmp_ctx, user_sid,
2121 &domain_sid, &rid))) {
2122 d_printf("dom_sid_split_rid failed\n");
2123 talloc_free(tmp_ctx);
2127 sd = security_descriptor_dacl_create(
2128 tmp_ctx, 0, "S-1-5-32-544",
2129 dom_sid_string(mem_ctx, dom_sid_add_rid(mem_ctx, domain_sid,
2131 dom_sid_string(mem_ctx, user_sid),
2132 SEC_ACE_TYPE_ACCESS_ALLOWED, access_mask, 0, NULL);
2134 d_printf("security_descriptor_dacl_create failed\n");
2135 talloc_free(tmp_ctx);
2139 status = set_sharesec(mem_ctx, session, sharename, sd);
2140 if (!NT_STATUS_IS_OK(status)) {
2141 d_printf("custom set_sharesec failed: %s\n",
2143 talloc_free(tmp_ctx);
2147 status = secondary_tcon(tmp_ctx, session, sharename, &tree);
2148 if (!NT_STATUS_EQUAL(status, expected_tcon)) {
2149 d_printf("Expected %s, got %s\n", nt_errstr(expected_tcon),
2155 if (!NT_STATUS_IS_OK(status)) {
2156 /* An expected non-access, no point in trying to write */
2160 status = smbcli_mkdir(tree, "sharesec_testdir");
2161 if (!NT_STATUS_EQUAL(status, expected_mkdir)) {
2162 d_printf("(%s) Expected %s, got %s\n", __location__,
2163 nt_errstr(expected_mkdir), nt_errstr(status));
2168 smbcli_rmdir(rmdir_tree, "sharesec_testdir");
2170 status = set_sharesec(mem_ctx, session, sharename, orig_sd);
2171 if (!NT_STATUS_IS_OK(status)) {
2172 d_printf("custom set_sharesec failed: %s\n",
2174 talloc_free(tmp_ctx);
2178 talloc_free(tmp_ctx);
2182 bool torture_samba3_rpc_sharesec(struct torture_context *torture)
2184 TALLOC_CTX *mem_ctx;
2186 struct smbcli_state *cli;
2187 struct security_descriptor *sd;
2188 struct dom_sid *user_sid;
2190 if (!(mem_ctx = talloc_new(torture))) {
2194 if (!(torture_open_connection_share(
2195 mem_ctx, &cli, torture, torture_setting_string(torture, "host", NULL),
2197 d_printf("IPC$ connection failed\n");
2198 talloc_free(mem_ctx);
2202 if (!(user_sid = whoami(mem_ctx, cli->tree))) {
2203 d_printf("whoami failed\n");
2204 talloc_free(mem_ctx);
2208 sd = get_sharesec(mem_ctx, cli->session, torture_setting_string(torture,
2211 ret &= try_tcon(mem_ctx, sd, cli->session,
2212 torture_setting_string(torture, "share", NULL),
2213 user_sid, 0, NT_STATUS_ACCESS_DENIED, NT_STATUS_OK);
2215 ret &= try_tcon(mem_ctx, sd, cli->session,
2216 torture_setting_string(torture, "share", NULL),
2217 user_sid, SEC_FILE_READ_DATA, NT_STATUS_OK,
2218 NT_STATUS_MEDIA_WRITE_PROTECTED);
2220 ret &= try_tcon(mem_ctx, sd, cli->session,
2221 torture_setting_string(torture, "share", NULL),
2222 user_sid, SEC_FILE_ALL, NT_STATUS_OK, NT_STATUS_OK);
2224 talloc_free(mem_ctx);
2228 bool torture_samba3_rpc_lsa(struct torture_context *torture)
2230 TALLOC_CTX *mem_ctx;
2232 struct smbcli_state *cli;
2233 struct dcerpc_pipe *p;
2234 struct policy_handle lsa_handle;
2236 struct dom_sid *domain_sid;
2238 if (!(mem_ctx = talloc_new(torture))) {
2242 if (!(torture_open_connection_share(
2243 mem_ctx, &cli, torture, torture_setting_string(torture, "host", NULL),
2245 d_printf("IPC$ connection failed\n");
2246 talloc_free(mem_ctx);
2250 status = pipe_bind_smb(mem_ctx, cli->tree, "\\lsarpc",
2251 &ndr_table_lsarpc, &p);
2252 if (!NT_STATUS_IS_OK(status)) {
2253 d_printf("(%s) pipe_bind_smb failed: %s\n", __location__,
2255 talloc_free(mem_ctx);
2260 struct lsa_ObjectAttribute attr;
2261 struct lsa_OpenPolicy2 o;
2262 o.in.system_name = talloc_asprintf(
2263 mem_ctx, "\\\\%s", dcerpc_server_name(p));
2266 o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2267 o.out.handle = &lsa_handle;
2268 status = dcerpc_lsa_OpenPolicy2(p, mem_ctx, &o);
2269 if (!NT_STATUS_IS_OK(status)) {
2270 d_printf("(%s) dcerpc_lsa_OpenPolicy2 failed: %s\n",
2271 __location__, nt_errstr(status));
2272 talloc_free(mem_ctx);
2278 p->conn->flags |= DCERPC_DEBUG_PRINT_IN | DCERPC_DEBUG_PRINT_OUT;
2283 int levels[] = { 2,3,5,6 };
2285 for (i=0; i<ARRAY_SIZE(levels); i++) {
2286 struct lsa_QueryInfoPolicy r;
2287 r.in.handle = &lsa_handle;
2288 r.in.level = levels[i];
2289 status = dcerpc_lsa_QueryInfoPolicy(p, mem_ctx, &r);
2290 if (!NT_STATUS_IS_OK(status)) {
2291 d_printf("(%s) dcerpc_lsa_QueryInfoPolicy %d "
2292 "failed: %s\n", __location__,
2293 levels[i], nt_errstr(status));
2294 talloc_free(mem_ctx);
2297 if (levels[i] == 5) {
2298 domain_sid = r.out.info->account_domain.sid;
2306 static NTSTATUS get_servername(TALLOC_CTX *mem_ctx, struct smbcli_tree *tree,
2309 struct rap_WserverGetInfo r;
2311 char servername[17];
2314 r.in.bufsize = 0xffff;
2316 status = smbcli_rap_netservergetinfo(tree, mem_ctx, &r);
2317 if (!NT_STATUS_IS_OK(status)) {
2321 memcpy(servername, r.out.info.info0.name, 16);
2322 servername[16] = '\0';
2324 if (pull_ascii_talloc(mem_ctx, lp_iconv_convenience(global_loadparm),
2325 name, servername) < 0) {
2326 return NT_STATUS_NO_MEMORY;
2329 return NT_STATUS_OK;
2333 static NTSTATUS find_printers(TALLOC_CTX *ctx, struct smbcli_tree *tree,
2334 const char ***printers, int *num_printers)
2336 TALLOC_CTX *mem_ctx;
2338 struct dcerpc_pipe *p;
2339 struct srvsvc_NetShareEnum r;
2340 struct srvsvc_NetShareCtr1 c1_in;
2341 struct srvsvc_NetShareCtr1 *c1;
2344 mem_ctx = talloc_new(ctx);
2345 if (mem_ctx == NULL) {
2346 return NT_STATUS_NO_MEMORY;
2349 status = pipe_bind_smb(mem_ctx, tree, "\\srvsvc", &ndr_table_srvsvc,
2351 if (!NT_STATUS_IS_OK(status)) {
2352 d_printf("could not bind to srvsvc pipe\n");
2353 talloc_free(mem_ctx);
2357 r.in.server_unc = talloc_asprintf(
2358 mem_ctx, "\\\\%s", dcerpc_server_name(p));
2361 r.in.ctr.ctr1 = &c1_in;
2362 r.in.max_buffer = (uint32_t)-1;
2363 r.in.resume_handle = NULL;
2365 status = dcerpc_srvsvc_NetShareEnum(p, mem_ctx, &r);
2366 if (!NT_STATUS_IS_OK(status)) {
2367 d_printf("NetShareEnum level %u failed - %s\n",
2368 r.in.level, nt_errstr(status));
2369 talloc_free(mem_ctx);
2375 c1 = r.out.ctr.ctr1;
2376 for (i=0; i<c1->count; i++) {
2377 if (c1->array[i].type != STYPE_PRINTQ) {
2380 if (!add_string_to_array(ctx, c1->array[i].name,
2381 printers, num_printers)) {
2383 return NT_STATUS_NO_MEMORY;
2387 talloc_free(mem_ctx);
2388 return NT_STATUS_OK;
2391 static bool enumprinters(TALLOC_CTX *mem_ctx, struct dcerpc_pipe *pipe,
2392 const char *servername, int level, int *num_printers)
2394 struct spoolss_EnumPrinters r;
2398 r.in.flags = PRINTER_ENUM_LOCAL;
2399 r.in.server = talloc_asprintf(mem_ctx, "\\\\%s", servername);
2404 status = dcerpc_spoolss_EnumPrinters(pipe, mem_ctx, &r);
2405 if (!NT_STATUS_IS_OK(status)) {
2406 d_printf("(%s) dcerpc_spoolss_EnumPrinters failed: %s\n",
2407 __location__, nt_errstr(status));
2411 if (!W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
2412 d_printf("(%s) EnumPrinters unexpected return code %s, should "
2413 "be WERR_INSUFFICIENT_BUFFER\n", __location__,
2414 win_errstr(r.out.result));
2418 blob = data_blob_talloc_zero(mem_ctx, r.out.needed);
2419 if (blob.data == NULL) {
2420 d_printf("(%s) data_blob_talloc failed\n", __location__);
2424 r.in.buffer = &blob;
2425 r.in.offered = r.out.needed;
2427 status = dcerpc_spoolss_EnumPrinters(pipe, mem_ctx, &r);
2428 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
2429 d_printf("(%s) dcerpc_spoolss_EnumPrinters failed: %s, "
2430 "%s\n", __location__, nt_errstr(status),
2431 win_errstr(r.out.result));
2435 *num_printers = r.out.count;
2440 static NTSTATUS getprinterinfo(TALLOC_CTX *ctx, struct dcerpc_pipe *pipe,
2441 struct policy_handle *handle, int level,
2442 union spoolss_PrinterInfo **res)
2444 TALLOC_CTX *mem_ctx;
2445 struct spoolss_GetPrinter r;
2449 mem_ctx = talloc_new(ctx);
2450 if (mem_ctx == NULL) {
2451 return NT_STATUS_NO_MEMORY;
2454 r.in.handle = handle;
2459 status = dcerpc_spoolss_GetPrinter(pipe, mem_ctx, &r);
2460 if (!NT_STATUS_IS_OK(status)) {
2461 d_printf("(%s) dcerpc_spoolss_GetPrinter failed: %s\n",
2462 __location__, nt_errstr(status));
2463 talloc_free(mem_ctx);
2467 if (!W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
2468 printf("GetPrinter unexpected return code %s, should "
2469 "be WERR_INSUFFICIENT_BUFFER\n",
2470 win_errstr(r.out.result));
2471 talloc_free(mem_ctx);
2472 return NT_STATUS_UNSUCCESSFUL;
2475 r.in.handle = handle;
2477 blob = data_blob_talloc(mem_ctx, NULL, r.out.needed);
2478 if (blob.data == NULL) {
2479 talloc_free(mem_ctx);
2480 return NT_STATUS_NO_MEMORY;
2482 memset(blob.data, 0, blob.length);
2483 r.in.buffer = &blob;
2484 r.in.offered = r.out.needed;
2486 status = dcerpc_spoolss_GetPrinter(pipe, mem_ctx, &r);
2487 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
2488 d_printf("(%s) dcerpc_spoolss_GetPrinter failed: %s, "
2489 "%s\n", __location__, nt_errstr(status),
2490 win_errstr(r.out.result));
2491 talloc_free(mem_ctx);
2492 return NT_STATUS_IS_OK(status) ?
2493 NT_STATUS_UNSUCCESSFUL : status;
2497 *res = talloc_steal(ctx, r.out.info);
2500 talloc_free(mem_ctx);
2501 return NT_STATUS_OK;
2504 bool torture_samba3_rpc_spoolss(struct torture_context *torture)
2506 TALLOC_CTX *mem_ctx;
2508 struct smbcli_state *cli;
2509 struct dcerpc_pipe *p;
2511 struct policy_handle server_handle, printer_handle;
2512 const char **printers;
2514 struct spoolss_UserLevel1 userlevel1;
2517 if (!(mem_ctx = talloc_new(torture))) {
2521 if (!(torture_open_connection_share(
2522 mem_ctx, &cli, torture, torture_setting_string(torture, "host", NULL),
2524 d_printf("IPC$ connection failed\n");
2525 talloc_free(mem_ctx);
2529 status = get_servername(mem_ctx, cli->tree, &servername);
2530 if (!NT_STATUS_IS_OK(status)) {
2531 d_fprintf(stderr, "(%s) get_servername returned %s\n",
2532 __location__, nt_errstr(status));
2533 talloc_free(mem_ctx);
2537 if (!NT_STATUS_IS_OK(find_printers(mem_ctx, cli->tree,
2538 &printers, &num_printers))) {
2539 talloc_free(mem_ctx);
2543 if (num_printers == 0) {
2544 d_printf("Did not find printers\n");
2545 talloc_free(mem_ctx);
2549 status = pipe_bind_smb(mem_ctx, cli->tree, "\\spoolss",
2550 &ndr_table_spoolss, &p);
2551 if (!NT_STATUS_IS_OK(status)) {
2552 d_printf("(%s) pipe_bind_smb failed: %s\n", __location__,
2554 talloc_free(mem_ctx);
2558 ZERO_STRUCT(userlevel1);
2559 userlevel1.client = talloc_asprintf(
2560 mem_ctx, "\\\\%s", lp_netbios_name(torture->lp_ctx));
2561 userlevel1.user = cli_credentials_get_username(cmdline_credentials);
2562 userlevel1.build = 2600;
2563 userlevel1.major = 3;
2564 userlevel1.minor = 0;
2565 userlevel1.processor = 0;
2568 struct spoolss_OpenPrinterEx r;
2571 r.in.printername = talloc_asprintf(mem_ctx, "\\\\%s",
2573 r.in.datatype = NULL;
2574 r.in.access_mask = 0;
2576 r.in.userlevel.level1 = &userlevel1;
2577 r.out.handle = &server_handle;
2579 status = dcerpc_spoolss_OpenPrinterEx(p, mem_ctx, &r);
2580 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
2581 d_printf("(%s) dcerpc_spoolss_OpenPrinterEx failed: "
2582 "%s, %s\n", __location__, nt_errstr(status),
2583 win_errstr(r.out.result));
2584 talloc_free(mem_ctx);
2590 struct spoolss_ClosePrinter r;
2592 r.in.handle = &server_handle;
2593 r.out.handle = &server_handle;
2595 status = dcerpc_spoolss_ClosePrinter(p, mem_ctx, &r);
2596 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
2597 d_printf("(%s) dcerpc_spoolss_ClosePrinter failed: "
2598 "%s, %s\n", __location__, nt_errstr(status),
2599 win_errstr(r.out.result));
2600 talloc_free(mem_ctx);
2606 struct spoolss_OpenPrinterEx r;
2609 r.in.printername = talloc_asprintf(
2610 mem_ctx, "\\\\%s\\%s", servername, printers[0]);
2611 r.in.datatype = NULL;
2612 r.in.access_mask = 0;
2614 r.in.userlevel.level1 = &userlevel1;
2615 r.out.handle = &printer_handle;
2617 status = dcerpc_spoolss_OpenPrinterEx(p, mem_ctx, &r);
2618 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
2619 d_printf("(%s) dcerpc_spoolss_OpenPrinterEx failed: "
2620 "%s, %s\n", __location__, nt_errstr(status),
2621 win_errstr(r.out.result));
2622 talloc_free(mem_ctx);
2630 for (i=0; i<8; i++) {
2631 status = getprinterinfo(mem_ctx, p, &printer_handle,
2633 if (!NT_STATUS_IS_OK(status)) {
2634 d_printf("(%s) getprinterinfo %d failed: %s\n",
2635 __location__, i, nt_errstr(status));
2642 struct spoolss_ClosePrinter r;
2644 r.in.handle = &printer_handle;
2645 r.out.handle = &printer_handle;
2647 status = dcerpc_spoolss_ClosePrinter(p, mem_ctx, &r);
2648 if (!NT_STATUS_IS_OK(status)) {
2649 d_printf("(%s) dcerpc_spoolss_ClosePrinter failed: "
2650 "%s\n", __location__, nt_errstr(status));
2651 talloc_free(mem_ctx);
2658 if (!enumprinters(mem_ctx, p, servername, 1,
2660 d_printf("(%s) enumprinters failed\n", __location__);
2661 talloc_free(mem_ctx);
2664 if (num_printers != num_enumerated) {
2665 d_printf("(%s) netshareenum gave %d printers, "
2666 "enumprinters lvl 1 gave %d\n", __location__,
2667 num_printers, num_enumerated);
2668 talloc_free(mem_ctx);
2675 if (!enumprinters(mem_ctx, p, servername, 2,
2677 d_printf("(%s) enumprinters failed\n", __location__);
2678 talloc_free(mem_ctx);
2681 if (num_printers != num_enumerated) {
2682 d_printf("(%s) netshareenum gave %d printers, "
2683 "enumprinters lvl 2 gave %d\n", __location__,
2684 num_printers, num_enumerated);
2685 talloc_free(mem_ctx);
2690 talloc_free(mem_ctx);
2695 bool torture_samba3_rpc_wkssvc(struct torture_context *torture)
2697 TALLOC_CTX *mem_ctx;
2698 struct smbcli_state *cli;
2699 struct dcerpc_pipe *p;
2703 if (!(mem_ctx = talloc_new(torture))) {
2707 if (!(torture_open_connection_share(
2708 mem_ctx, &cli, torture, torture_setting_string(torture, "host", NULL),
2710 d_printf("IPC$ connection failed\n");
2711 talloc_free(mem_ctx);
2715 status = get_servername(mem_ctx, cli->tree, &servername);
2716 if (!NT_STATUS_IS_OK(status)) {
2717 d_fprintf(stderr, "(%s) get_servername returned %s\n",
2718 __location__, nt_errstr(status));
2719 talloc_free(mem_ctx);
2723 status = pipe_bind_smb(mem_ctx, cli->tree, "\\wkssvc",
2724 &ndr_table_wkssvc, &p);
2725 if (!NT_STATUS_IS_OK(status)) {
2726 d_printf("(%s) pipe_bind_smb failed: %s\n", __location__,
2728 talloc_free(mem_ctx);
2733 struct wkssvc_NetWkstaInfo100 wks100;
2734 union wkssvc_NetWkstaInfo info;
2735 struct wkssvc_NetWkstaGetInfo r;
2737 r.in.server_name = "\\foo";
2739 info.info100 = &wks100;
2742 status = dcerpc_wkssvc_NetWkstaGetInfo(p, mem_ctx, &r);
2743 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
2744 d_printf("(%s) dcerpc_wkssvc_NetWksGetInfo failed: "
2745 "%s, %s\n", __location__, nt_errstr(status),
2746 win_errstr(r.out.result));
2747 talloc_free(mem_ctx);
2751 if (strcmp(servername,
2752 r.out.info->info100->server_name) != 0) {
2753 d_printf("(%s) servername inconsistency: RAP=%s, "
2754 "dcerpc_wkssvc_NetWksGetInfo=%s",
2755 __location__, servername,
2756 r.out.info->info100->server_name);
2757 talloc_free(mem_ctx);
2762 talloc_free(mem_ctx);
2766 static NTSTATUS winreg_close(struct dcerpc_pipe *p,
2767 struct policy_handle *handle)
2769 struct winreg_CloseKey c;
2771 TALLOC_CTX *mem_ctx;
2773 c.in.handle = c.out.handle = handle;
2775 if (!(mem_ctx = talloc_new(p))) {
2776 return NT_STATUS_NO_MEMORY;
2779 status = dcerpc_winreg_CloseKey(p, mem_ctx, &c);
2780 talloc_free(mem_ctx);
2782 if (!NT_STATUS_IS_OK(status)) {
2786 if (!W_ERROR_IS_OK(c.out.result)) {
2787 return werror_to_ntstatus(c.out.result);
2790 return NT_STATUS_OK;
2793 static NTSTATUS enumvalues(struct dcerpc_pipe *p, struct policy_handle *handle,
2794 TALLOC_CTX *mem_ctx)
2796 uint32_t enum_index = 0;
2799 struct winreg_EnumValue r;
2800 struct winreg_StringBuf name;
2801 enum winreg_Type type = 0;
2804 uint32_t size, length;
2806 r.in.handle = handle;
2807 r.in.enum_index = enum_index;
2810 r.in.name = r.out.name = &name;
2816 r.in.length = &length;
2818 status = dcerpc_winreg_EnumValue(p, mem_ctx, &r);
2819 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
2820 return NT_STATUS_OK;
2826 static NTSTATUS enumkeys(struct dcerpc_pipe *p, struct policy_handle *handle,
2827 TALLOC_CTX *mem_ctx, int depth)
2829 struct winreg_EnumKey r;
2830 struct winreg_StringBuf class, name;
2835 return NT_STATUS_OK;
2841 r.in.handle = handle;
2842 r.in.enum_index = 0;
2844 r.in.keyclass = &class;
2846 r.in.last_changed_time = &t;
2849 TALLOC_CTX *tmp_ctx;
2850 struct winreg_OpenKey o;
2851 struct policy_handle key_handle;
2854 if (!(tmp_ctx = talloc_new(mem_ctx))) {
2855 return NT_STATUS_NO_MEMORY;
2861 status = dcerpc_winreg_EnumKey(p, tmp_ctx, &r);
2862 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
2863 /* We're done enumerating */
2864 talloc_free(tmp_ctx);
2865 return NT_STATUS_OK;
2868 for (i=0; i<10-depth; i++)
2870 printf("%s\n", r.out.name->name);
2873 o.in.parent_handle = handle;
2874 o.in.keyname.name = r.out.name->name;
2876 o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2877 o.out.handle = &key_handle;
2879 status = dcerpc_winreg_OpenKey(p, tmp_ctx, &o);
2880 if (NT_STATUS_IS_OK(status) && W_ERROR_IS_OK(o.out.result)) {
2881 enumkeys(p, &key_handle, tmp_ctx, depth-1);
2882 enumvalues(p, &key_handle, tmp_ctx);
2883 status = winreg_close(p, &key_handle);
2884 if (!NT_STATUS_IS_OK(status)) {
2889 talloc_free(tmp_ctx);
2891 r.in.enum_index += 1;
2894 return NT_STATUS_OK;
2897 typedef NTSTATUS (*winreg_open_fn)(struct dcerpc_pipe *, TALLOC_CTX *, void *);
2899 static bool test_Open3(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
2900 const char *name, winreg_open_fn open_fn)
2902 struct policy_handle handle;
2903 struct winreg_OpenHKLM r;
2906 r.in.system_name = 0;
2907 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2908 r.out.handle = &handle;
2910 status = open_fn(p, mem_ctx, &r);
2911 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
2912 d_printf("(%s) %s failed: %s, %s\n", __location__, name,
2913 nt_errstr(status), win_errstr(r.out.result));
2917 enumkeys(p, &handle, mem_ctx, 4);
2919 status = winreg_close(p, &handle);
2920 if (!NT_STATUS_IS_OK(status)) {
2921 d_printf("(%s) dcerpc_CloseKey failed: %s\n",
2922 __location__, nt_errstr(status));
2929 bool torture_samba3_rpc_winreg(struct torture_context *torture)
2932 struct dcerpc_pipe *p;
2933 TALLOC_CTX *mem_ctx;
2939 {"OpenHKLM", (winreg_open_fn)dcerpc_winreg_OpenHKLM },
2940 {"OpenHKU", (winreg_open_fn)dcerpc_winreg_OpenHKU },
2941 {"OpenHKPD", (winreg_open_fn)dcerpc_winreg_OpenHKPD },
2942 {"OpenHKPT", (winreg_open_fn)dcerpc_winreg_OpenHKPT },
2943 {"OpenHKCR", (winreg_open_fn)dcerpc_winreg_OpenHKCR }};
2948 mem_ctx = talloc_init("torture_rpc_winreg");
2950 status = torture_rpc_connection(torture, &p, &ndr_table_winreg);
2952 if (!NT_STATUS_IS_OK(status)) {
2953 talloc_free(mem_ctx);
2958 ret = test_Open3(p, mem_ctx, open_fns[0].name, open_fns[0].fn);
2960 for (i = 0; i < ARRAY_SIZE(open_fns); i++) {
2961 if (!test_Open3(p, mem_ctx, open_fns[i].name, open_fns[i].fn))
2966 talloc_free(mem_ctx);
2971 static NTSTATUS get_shareinfo(TALLOC_CTX *mem_ctx,
2972 struct smbcli_state *cli,
2974 struct srvsvc_NetShareInfo502 **info)
2976 struct smbcli_tree *ipc;
2977 struct dcerpc_pipe *p;
2978 struct srvsvc_NetShareGetInfo r;
2981 if (!(p = dcerpc_pipe_init(cli,
2982 cli->transport->socket->event.ctx,
2983 lp_iconv_convenience(global_loadparm)))) {
2984 status = NT_STATUS_NO_MEMORY;
2988 status = secondary_tcon(p, cli->session, "IPC$", &ipc);
2989 if (!NT_STATUS_IS_OK(status)) {
2993 status = dcerpc_pipe_open_smb(p, ipc, "\\pipe\\srvsvc");
2994 if (!NT_STATUS_IS_OK(status)) {
2995 d_printf("dcerpc_pipe_open_smb failed: %s\n",
3000 status = dcerpc_bind_auth_none(p, &ndr_table_srvsvc);
3001 if (!NT_STATUS_IS_OK(status)) {
3002 d_printf("dcerpc_bind_auth_none failed: %s\n",
3007 r.in.server_unc = talloc_asprintf(mem_ctx, "\\\\%s",
3008 dcerpc_server_name(p));
3009 r.in.share_name = share;
3012 status = dcerpc_srvsvc_NetShareGetInfo(p, p, &r);
3013 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
3014 d_printf("(%s) OpenHKLM failed: %s, %s\n", __location__,
3015 nt_errstr(status), win_errstr(r.out.result));
3019 *info = talloc_move(mem_ctx, &r.out.info.info502);
3020 return NT_STATUS_OK;
3028 * Get us a handle on HKLM\
3031 static NTSTATUS get_hklm_handle(TALLOC_CTX *mem_ctx,
3032 struct smbcli_state *cli,
3033 struct dcerpc_pipe **pipe_p,
3034 struct policy_handle **handle)
3036 struct smbcli_tree *ipc;
3037 struct dcerpc_pipe *p;
3038 struct winreg_OpenHKLM r;
3040 struct policy_handle *result;
3042 result = talloc(mem_ctx, struct policy_handle);
3044 if (result == NULL) {
3045 return NT_STATUS_NO_MEMORY;
3048 if (!(p = dcerpc_pipe_init(result,
3049 cli->transport->socket->event.ctx,
3050 lp_iconv_convenience(global_loadparm)))) {
3051 status = NT_STATUS_NO_MEMORY;
3055 status = secondary_tcon(p, cli->session, "IPC$", &ipc);
3056 if (!NT_STATUS_IS_OK(status)) {
3060 status = dcerpc_pipe_open_smb(p, ipc, "\\winreg");
3061 if (!NT_STATUS_IS_OK(status)) {
3062 d_printf("dcerpc_pipe_open_smb failed: %s\n",
3067 status = dcerpc_bind_auth_none(p, &ndr_table_winreg);
3068 if (!NT_STATUS_IS_OK(status)) {
3069 d_printf("dcerpc_bind_auth_none failed: %s\n",
3074 r.in.system_name = 0;
3075 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3076 r.out.handle = result;
3078 status = dcerpc_winreg_OpenHKLM(p, p, &r);
3079 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
3080 d_printf("(%s) OpenHKLM failed: %s, %s\n", __location__,
3081 nt_errstr(status), win_errstr(r.out.result));
3087 return NT_STATUS_OK;
3090 talloc_free(result);
3094 static NTSTATUS torture_samba3_createshare(struct smbcli_state *cli,
3095 const char *sharename)
3097 struct dcerpc_pipe *p;
3098 struct policy_handle *hklm = NULL;
3099 struct policy_handle new_handle;
3100 struct winreg_CreateKey c;
3101 struct winreg_CloseKey cl;
3102 enum winreg_CreateAction action_taken;
3104 TALLOC_CTX *mem_ctx;
3106 mem_ctx = talloc_new(cli);
3107 NT_STATUS_HAVE_NO_MEMORY(mem_ctx);
3109 status = get_hklm_handle(mem_ctx, cli, &p, &hklm);
3110 if (!NT_STATUS_IS_OK(status)) {
3111 d_printf("get_hklm_handle failed: %s\n", nt_errstr(status));
3116 c.in.name.name = talloc_asprintf(
3117 mem_ctx, "software\\samba\\smbconf\\%s", sharename);
3118 if (c.in.name.name == NULL) {
3119 d_printf("talloc_asprintf failed\n");
3120 status = NT_STATUS_NO_MEMORY;
3123 c.in.keyclass.name = "";
3125 c.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3126 c.in.secdesc = NULL;
3127 c.in.action_taken = &action_taken;
3128 c.out.new_handle = &new_handle;
3129 c.out.action_taken = &action_taken;
3131 status = dcerpc_winreg_CreateKey(p, p, &c);
3132 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(c.out.result)) {
3133 d_printf("(%s) OpenKey failed: %s, %s\n", __location__,
3134 nt_errstr(status), win_errstr(c.out.result));
3138 cl.in.handle = &new_handle;
3139 cl.out.handle = &new_handle;
3140 status = dcerpc_winreg_CloseKey(p, p, &cl);
3141 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(cl.out.result)) {
3142 d_printf("(%s) OpenKey failed: %s, %s\n", __location__,
3143 nt_errstr(status), win_errstr(cl.out.result));
3149 talloc_free(mem_ctx);
3153 static NTSTATUS torture_samba3_deleteshare(struct smbcli_state *cli,
3154 const char *sharename)
3156 struct dcerpc_pipe *p;
3157 struct policy_handle *hklm = NULL;
3158 struct winreg_DeleteKey d;
3160 TALLOC_CTX *mem_ctx;
3162 mem_ctx = talloc_new(cli);
3163 NT_STATUS_HAVE_NO_MEMORY(mem_ctx);
3165 status = get_hklm_handle(cli, cli, &p, &hklm);
3166 if (!NT_STATUS_IS_OK(status)) {
3167 d_printf("get_hklm_handle failed: %s\n", nt_errstr(status));
3172 d.in.key.name = talloc_asprintf(
3173 mem_ctx, "software\\samba\\smbconf\\%s", sharename);
3174 if (d.in.key.name == NULL) {
3175 d_printf("talloc_asprintf failed\n");
3176 status = NT_STATUS_NO_MEMORY;
3179 status = dcerpc_winreg_DeleteKey(p, p, &d);
3180 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(d.out.result)) {
3181 d_printf("(%s) OpenKey failed: %s, %s\n", __location__,
3182 nt_errstr(status), win_errstr(d.out.result));
3187 talloc_free(mem_ctx);
3191 static NTSTATUS torture_samba3_setconfig(struct smbcli_state *cli,
3192 const char *sharename,
3193 const char *parameter,
3196 struct dcerpc_pipe *p = NULL;
3197 struct policy_handle *hklm = NULL, key_handle;
3198 struct winreg_OpenKey o;
3199 struct winreg_SetValue s;
3204 status = get_hklm_handle(cli, cli, &p, &hklm);
3205 if (!NT_STATUS_IS_OK(status)) {
3206 d_printf("get_hklm_handle failed: %s\n", nt_errstr(status));
3210 o.in.parent_handle = hklm;
3211 o.in.keyname.name = talloc_asprintf(
3212 hklm, "software\\samba\\smbconf\\%s", sharename);
3213 if (o.in.keyname.name == NULL) {
3214 d_printf("talloc_asprintf failed\n");
3215 status = NT_STATUS_NO_MEMORY;
3219 o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3220 o.out.handle = &key_handle;
3222 status = dcerpc_winreg_OpenKey(p, p, &o);
3223 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(o.out.result)) {
3224 d_printf("(%s) OpenKey failed: %s, %s\n", __location__,
3225 nt_errstr(status), win_errstr(o.out.result));
3229 if (!reg_string_to_val(hklm, "REG_SZ", value, &type, &val)) {
3230 d_printf("(%s) reg_string_to_val failed\n", __location__);
3234 s.in.handle = &key_handle;
3235 s.in.name.name = parameter;
3237 s.in.data = val.data;
3238 s.in.size = val.length;
3240 status = dcerpc_winreg_SetValue(p, p, &s);
3241 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(s.out.result)) {
3242 d_printf("(%s) SetValue failed: %s, %s\n", __location__,
3243 nt_errstr(status), win_errstr(s.out.result));
3252 bool torture_samba3_regconfig(struct torture_context *torture)
3254 struct smbcli_state *cli;
3255 struct srvsvc_NetShareInfo502 *i = NULL;
3258 const char *comment = "Dummer Kommentar";
3260 if (!(torture_open_connection(&cli, torture, 0))) {
3264 status = torture_samba3_createshare(cli, "blubber");
3265 if (!NT_STATUS_IS_OK(status)) {
3266 torture_warning(torture, "torture_samba3_createshare failed: "
3267 "%s\n", nt_errstr(status));
3271 status = torture_samba3_setconfig(cli, "blubber", "comment", comment);
3272 if (!NT_STATUS_IS_OK(status)) {
3273 torture_warning(torture, "torture_samba3_setconfig failed: "
3274 "%s\n", nt_errstr(status));
3278 status = get_shareinfo(torture, cli, "blubber", &i);
3279 if (!NT_STATUS_IS_OK(status)) {
3280 torture_warning(torture, "get_shareinfo failed: "
3281 "%s\n", nt_errstr(status));
3285 if (strcmp(comment, i->comment) != 0) {
3286 torture_warning(torture, "Expected comment [%s], got [%s]\n",
3287 comment, i->comment);
3291 status = torture_samba3_deleteshare(cli, "blubber");
3292 if (!NT_STATUS_IS_OK(status)) {
3293 torture_warning(torture, "torture_samba3_deleteshare failed: "
3294 "%s\n", nt_errstr(status));