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"
54 static struct cli_credentials *create_anon_creds(TALLOC_CTX *mem_ctx)
56 struct cli_credentials *result;
58 if (!(result = cli_credentials_init(mem_ctx))) {
62 cli_credentials_set_conf(result, global_loadparm);
63 cli_credentials_set_anonymous(result);
69 * This tests a RPC call using an invalid vuid
72 bool torture_bind_authcontext(struct torture_context *torture)
77 struct lsa_ObjectAttribute objectattr;
78 struct lsa_OpenPolicy2 openpolicy;
79 struct policy_handle handle;
80 struct lsa_Close close_handle;
81 struct smbcli_session *tmp;
82 struct smbcli_session *session2;
83 struct smbcli_state *cli;
84 struct dcerpc_pipe *lsa_pipe;
85 struct cli_credentials *anon_creds;
86 struct smb_composite_sesssetup setup;
88 mem_ctx = talloc_init("torture_bind_authcontext");
90 if (mem_ctx == NULL) {
91 d_printf("talloc_init failed\n");
95 status = smbcli_full_connection(mem_ctx, &cli,
96 torture_setting_string(torture, "host", NULL),
97 "IPC$", NULL, cmdline_credentials,
99 if (!NT_STATUS_IS_OK(status)) {
100 d_printf("smbcli_full_connection failed: %s\n",
105 lsa_pipe = dcerpc_pipe_init(mem_ctx, cli->transport->socket->event.ctx);
106 if (lsa_pipe == NULL) {
107 d_printf("dcerpc_pipe_init failed\n");
111 status = dcerpc_pipe_open_smb(lsa_pipe, cli->tree, "\\lsarpc");
112 if (!NT_STATUS_IS_OK(status)) {
113 d_printf("dcerpc_pipe_open_smb failed: %s\n",
118 status = dcerpc_bind_auth_none(lsa_pipe, &ndr_table_lsarpc);
119 if (!NT_STATUS_IS_OK(status)) {
120 d_printf("dcerpc_bind_auth_none failed: %s\n",
125 openpolicy.in.system_name =talloc_asprintf(
126 mem_ctx, "\\\\%s", dcerpc_server_name(lsa_pipe));
127 ZERO_STRUCT(objectattr);
128 openpolicy.in.attr = &objectattr;
129 openpolicy.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
130 openpolicy.out.handle = &handle;
132 status = dcerpc_lsa_OpenPolicy2(lsa_pipe, mem_ctx, &openpolicy);
134 if (!NT_STATUS_IS_OK(status)) {
135 d_printf("dcerpc_lsa_OpenPolicy2 failed: %s\n",
140 close_handle.in.handle = &handle;
141 close_handle.out.handle = &handle;
143 status = dcerpc_lsa_Close(lsa_pipe, mem_ctx, &close_handle);
144 if (!NT_STATUS_IS_OK(status)) {
145 d_printf("dcerpc_lsa_Close failed: %s\n",
150 session2 = smbcli_session_init(cli->transport, mem_ctx, false);
151 if (session2 == NULL) {
152 d_printf("smbcli_session_init failed\n");
156 if (!(anon_creds = create_anon_creds(mem_ctx))) {
157 d_printf("create_anon_creds failed\n");
161 setup.in.sesskey = cli->transport->negotiate.sesskey;
162 setup.in.capabilities = cli->transport->negotiate.capabilities;
163 setup.in.workgroup = "";
164 setup.in.credentials = anon_creds;
166 status = smb_composite_sesssetup(session2, &setup);
167 if (!NT_STATUS_IS_OK(status)) {
168 d_printf("anon session setup failed: %s\n",
172 session2->vuid = setup.out.vuid;
174 tmp = cli->tree->session;
175 cli->tree->session = session2;
177 status = dcerpc_lsa_OpenPolicy2(lsa_pipe, mem_ctx, &openpolicy);
179 cli->tree->session = tmp;
180 talloc_free(lsa_pipe);
183 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
184 d_printf("dcerpc_lsa_OpenPolicy2 with wrong vuid gave %s, "
185 "expected NT_STATUS_INVALID_HANDLE\n",
192 talloc_free(mem_ctx);
197 * Bind to lsa using a specific auth method
200 static bool bindtest(struct smbcli_state *cli,
201 struct cli_credentials *credentials,
202 uint8_t auth_type, uint8_t auth_level)
208 struct dcerpc_pipe *lsa_pipe;
209 struct lsa_ObjectAttribute objectattr;
210 struct lsa_OpenPolicy2 openpolicy;
211 struct lsa_QueryInfoPolicy query;
212 struct policy_handle handle;
213 struct lsa_Close close_handle;
215 if ((mem_ctx = talloc_init("bindtest")) == NULL) {
216 d_printf("talloc_init failed\n");
220 lsa_pipe = dcerpc_pipe_init(mem_ctx,
221 cli->transport->socket->event.ctx);
222 if (lsa_pipe == NULL) {
223 d_printf("dcerpc_pipe_init failed\n");
227 status = dcerpc_pipe_open_smb(lsa_pipe, cli->tree, "\\lsarpc");
228 if (!NT_STATUS_IS_OK(status)) {
229 d_printf("dcerpc_pipe_open_smb failed: %s\n",
234 status = dcerpc_bind_auth(lsa_pipe, &ndr_table_lsarpc,
235 credentials, auth_type, auth_level,
237 if (!NT_STATUS_IS_OK(status)) {
238 d_printf("dcerpc_bind_auth failed: %s\n", nt_errstr(status));
242 openpolicy.in.system_name =talloc_asprintf(
243 mem_ctx, "\\\\%s", dcerpc_server_name(lsa_pipe));
244 ZERO_STRUCT(objectattr);
245 openpolicy.in.attr = &objectattr;
246 openpolicy.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
247 openpolicy.out.handle = &handle;
249 status = dcerpc_lsa_OpenPolicy2(lsa_pipe, mem_ctx, &openpolicy);
251 if (!NT_STATUS_IS_OK(status)) {
252 d_printf("dcerpc_lsa_OpenPolicy2 failed: %s\n",
257 query.in.handle = &handle;
258 query.in.level = LSA_POLICY_INFO_DOMAIN;
260 status = dcerpc_lsa_QueryInfoPolicy(lsa_pipe, mem_ctx, &query);
261 if (!NT_STATUS_IS_OK(status)) {
262 d_printf("dcerpc_lsa_QueryInfoPolicy failed: %s\n",
267 close_handle.in.handle = &handle;
268 close_handle.out.handle = &handle;
270 status = dcerpc_lsa_Close(lsa_pipe, mem_ctx, &close_handle);
271 if (!NT_STATUS_IS_OK(status)) {
272 d_printf("dcerpc_lsa_Close failed: %s\n",
279 talloc_free(mem_ctx);
284 * test authenticated RPC binds with the variants Samba3 does support
287 bool torture_bind_samba3(struct torture_context *torture)
292 struct smbcli_state *cli;
294 mem_ctx = talloc_init("torture_bind_authcontext");
296 if (mem_ctx == NULL) {
297 d_printf("talloc_init failed\n");
301 status = smbcli_full_connection(mem_ctx, &cli,
302 torture_setting_string(torture, "host", NULL),
303 "IPC$", NULL, cmdline_credentials,
305 if (!NT_STATUS_IS_OK(status)) {
306 d_printf("smbcli_full_connection failed: %s\n",
313 ret &= bindtest(cli, cmdline_credentials, DCERPC_AUTH_TYPE_NTLMSSP,
314 DCERPC_AUTH_LEVEL_INTEGRITY);
315 ret &= bindtest(cli, cmdline_credentials, DCERPC_AUTH_TYPE_NTLMSSP,
316 DCERPC_AUTH_LEVEL_PRIVACY);
317 ret &= bindtest(cli, cmdline_credentials, DCERPC_AUTH_TYPE_SPNEGO,
318 DCERPC_AUTH_LEVEL_INTEGRITY);
319 ret &= bindtest(cli, cmdline_credentials, DCERPC_AUTH_TYPE_SPNEGO,
320 DCERPC_AUTH_LEVEL_PRIVACY);
323 talloc_free(mem_ctx);
328 * Lookup or create a user and return all necessary info
331 static NTSTATUS get_usr_handle(struct smbcli_state *cli,
333 struct cli_credentials *admin_creds,
336 const char *username,
338 struct dcerpc_pipe **result_pipe,
339 struct policy_handle **result_handle,
340 struct dom_sid **sid)
342 struct dcerpc_pipe *samr_pipe;
344 struct policy_handle conn_handle;
345 struct policy_handle domain_handle;
346 struct policy_handle *user_handle;
347 struct samr_Connect2 conn;
348 struct samr_EnumDomains enumdom;
349 uint32_t resume_handle = 0;
350 struct samr_LookupDomain l;
352 struct lsa_String domain_name;
353 struct lsa_String user_name;
354 struct samr_OpenDomain o;
355 struct samr_CreateUser2 c;
356 uint32_t user_rid,access_granted;
358 samr_pipe = dcerpc_pipe_init(mem_ctx,
359 cli->transport->socket->event.ctx);
360 if (samr_pipe == NULL) {
361 d_printf("dcerpc_pipe_init failed\n");
362 status = NT_STATUS_NO_MEMORY;
366 status = dcerpc_pipe_open_smb(samr_pipe, cli->tree, "\\samr");
367 if (!NT_STATUS_IS_OK(status)) {
368 d_printf("dcerpc_pipe_open_smb failed: %s\n",
373 if (admin_creds != NULL) {
374 status = dcerpc_bind_auth(samr_pipe, &ndr_table_samr,
375 admin_creds, auth_type, auth_level,
377 if (!NT_STATUS_IS_OK(status)) {
378 d_printf("dcerpc_bind_auth failed: %s\n",
383 /* We must have an authenticated SMB connection */
384 status = dcerpc_bind_auth_none(samr_pipe, &ndr_table_samr);
385 if (!NT_STATUS_IS_OK(status)) {
386 d_printf("dcerpc_bind_auth_none failed: %s\n",
392 conn.in.system_name = talloc_asprintf(
393 mem_ctx, "\\\\%s", dcerpc_server_name(samr_pipe));
394 conn.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
395 conn.out.connect_handle = &conn_handle;
397 status = dcerpc_samr_Connect2(samr_pipe, mem_ctx, &conn);
398 if (!NT_STATUS_IS_OK(status)) {
399 d_printf("samr_Connect2 failed: %s\n", nt_errstr(status));
403 enumdom.in.connect_handle = &conn_handle;
404 enumdom.in.resume_handle = &resume_handle;
405 enumdom.in.buf_size = (uint32_t)-1;
406 enumdom.out.resume_handle = &resume_handle;
408 status = dcerpc_samr_EnumDomains(samr_pipe, mem_ctx, &enumdom);
409 if (!NT_STATUS_IS_OK(status)) {
410 d_printf("samr_EnumDomains failed: %s\n", nt_errstr(status));
414 if (enumdom.out.num_entries != 2) {
415 d_printf("samr_EnumDomains returned %d entries, expected 2\n",
416 enumdom.out.num_entries);
417 status = NT_STATUS_UNSUCCESSFUL;
421 dom_idx = strequal(enumdom.out.sam->entries[0].name.string,
424 l.in.connect_handle = &conn_handle;
425 domain_name.string = enumdom.out.sam->entries[0].name.string;
426 *domain = talloc_strdup(mem_ctx, domain_name.string);
427 l.in.domain_name = &domain_name;
429 status = dcerpc_samr_LookupDomain(samr_pipe, mem_ctx, &l);
430 if (!NT_STATUS_IS_OK(status)) {
431 d_printf("samr_LookupDomain failed: %s\n", nt_errstr(status));
435 o.in.connect_handle = &conn_handle;
436 o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
437 o.in.sid = l.out.sid;
438 o.out.domain_handle = &domain_handle;
440 status = dcerpc_samr_OpenDomain(samr_pipe, mem_ctx, &o);
441 if (!NT_STATUS_IS_OK(status)) {
442 d_printf("samr_OpenDomain failed: %s\n", nt_errstr(status));
446 c.in.domain_handle = &domain_handle;
447 user_name.string = username;
448 c.in.account_name = &user_name;
449 c.in.acct_flags = ACB_NORMAL;
450 c.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
451 user_handle = talloc(mem_ctx, struct policy_handle);
452 c.out.user_handle = user_handle;
453 c.out.access_granted = &access_granted;
454 c.out.rid = &user_rid;
456 status = dcerpc_samr_CreateUser2(samr_pipe, mem_ctx, &c);
458 if (NT_STATUS_EQUAL(status, NT_STATUS_USER_EXISTS)) {
459 struct samr_LookupNames ln;
460 struct samr_OpenUser ou;
462 ln.in.domain_handle = &domain_handle;
464 ln.in.names = &user_name;
466 status = dcerpc_samr_LookupNames(samr_pipe, mem_ctx, &ln);
467 if (!NT_STATUS_IS_OK(status)) {
468 d_printf("samr_LookupNames failed: %s\n",
473 ou.in.domain_handle = &domain_handle;
474 ou.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
475 user_rid = ou.in.rid = ln.out.rids.ids[0];
476 ou.out.user_handle = user_handle;
478 status = dcerpc_samr_OpenUser(samr_pipe, mem_ctx, &ou);
479 if (!NT_STATUS_IS_OK(status)) {
480 d_printf("samr_OpenUser failed: %s\n",
486 if (!NT_STATUS_IS_OK(status)) {
487 d_printf("samr_CreateUser failed: %s\n", nt_errstr(status));
491 *result_pipe = samr_pipe;
492 *result_handle = user_handle;
494 *sid = dom_sid_add_rid(mem_ctx, l.out.sid, user_rid);
506 static bool create_user(TALLOC_CTX *mem_ctx, struct smbcli_state *cli,
507 struct cli_credentials *admin_creds,
508 const char *username, const char *password,
510 struct dom_sid **user_sid)
514 struct dcerpc_pipe *samr_pipe;
515 struct policy_handle *wks_handle;
518 if (!(tmp_ctx = talloc_new(mem_ctx))) {
519 d_printf("talloc_init failed\n");
523 status = get_usr_handle(cli, tmp_ctx, admin_creds,
524 DCERPC_AUTH_TYPE_NTLMSSP,
525 DCERPC_AUTH_LEVEL_INTEGRITY,
526 username, domain_name, &samr_pipe, &wks_handle,
528 if (!NT_STATUS_IS_OK(status)) {
529 d_printf("get_wks_handle failed: %s\n", nt_errstr(status));
534 struct samr_SetUserInfo2 sui2;
535 struct samr_SetUserInfo sui;
536 struct samr_QueryUserInfo qui;
537 union samr_UserInfo u_info;
538 DATA_BLOB session_key;
542 encode_pw_buffer(u_info.info23.password.data, password,
545 status = dcerpc_fetch_session_key(samr_pipe, &session_key);
546 if (!NT_STATUS_IS_OK(status)) {
547 d_printf("dcerpc_fetch_session_key failed\n");
550 arcfour_crypt_blob(u_info.info23.password.data, 516,
552 u_info.info23.info.password_expired = 0;
553 u_info.info23.info.fields_present = SAMR_FIELD_PASSWORD |
554 SAMR_FIELD_PASSWORD2 |
555 SAMR_FIELD_EXPIRED_FLAG;
556 sui2.in.user_handle = wks_handle;
557 sui2.in.info = &u_info;
560 status = dcerpc_samr_SetUserInfo2(samr_pipe, tmp_ctx, &sui2);
561 if (!NT_STATUS_IS_OK(status)) {
562 d_printf("samr_SetUserInfo(23) failed: %s\n",
567 u_info.info16.acct_flags = ACB_NORMAL;
568 sui.in.user_handle = wks_handle;
569 sui.in.info = &u_info;
572 status = dcerpc_samr_SetUserInfo(samr_pipe, tmp_ctx, &sui);
573 if (!NT_STATUS_IS_OK(status)) {
574 d_printf("samr_SetUserInfo(16) failed\n");
578 qui.in.user_handle = wks_handle;
581 status = dcerpc_samr_QueryUserInfo(samr_pipe, tmp_ctx, &qui);
582 if (!NT_STATUS_IS_OK(status)) {
583 d_printf("samr_QueryUserInfo(21) failed\n");
587 qui.out.info->info21.allow_password_change = 0;
588 qui.out.info->info21.force_password_change = 0;
589 qui.out.info->info21.account_name.string = NULL;
590 qui.out.info->info21.rid = 0;
591 qui.out.info->info21.acct_expiry = 0;
592 qui.out.info->info21.fields_present = 0x81827fa; /* copy usrmgr.exe */
594 u_info.info21 = qui.out.info->info21;
595 sui.in.user_handle = wks_handle;
596 sui.in.info = &u_info;
599 status = dcerpc_samr_SetUserInfo(samr_pipe, tmp_ctx, &sui);
600 if (!NT_STATUS_IS_OK(status)) {
601 d_printf("samr_SetUserInfo(21) failed\n");
606 *domain_name= talloc_steal(mem_ctx, *domain_name);
607 *user_sid = talloc_steal(mem_ctx, *user_sid);
610 talloc_free(tmp_ctx);
618 static bool delete_user(struct smbcli_state *cli,
619 struct cli_credentials *admin_creds,
620 const char *username)
625 struct dcerpc_pipe *samr_pipe;
626 struct policy_handle *user_handle;
629 if ((mem_ctx = talloc_init("leave")) == NULL) {
630 d_printf("talloc_init failed\n");
634 status = get_usr_handle(cli, mem_ctx, admin_creds,
635 DCERPC_AUTH_TYPE_NTLMSSP,
636 DCERPC_AUTH_LEVEL_INTEGRITY,
637 username, &dom_name, &samr_pipe,
640 if (!NT_STATUS_IS_OK(status)) {
641 d_printf("get_wks_handle failed: %s\n", nt_errstr(status));
646 struct samr_DeleteUser d;
648 d.in.user_handle = user_handle;
649 d.out.user_handle = user_handle;
651 status = dcerpc_samr_DeleteUser(samr_pipe, mem_ctx, &d);
652 if (!NT_STATUS_IS_OK(status)) {
653 d_printf("samr_DeleteUser failed %s\n", nt_errstr(status));
661 talloc_free(mem_ctx);
666 * Do a Samba3-style join
669 static bool join3(struct smbcli_state *cli,
671 struct cli_credentials *admin_creds,
672 struct cli_credentials *wks_creds)
677 struct dcerpc_pipe *samr_pipe;
678 struct policy_handle *wks_handle;
681 if ((mem_ctx = talloc_init("join3")) == NULL) {
682 d_printf("talloc_init failed\n");
686 status = get_usr_handle(
687 cli, mem_ctx, admin_creds,
688 DCERPC_AUTH_TYPE_NTLMSSP,
689 DCERPC_AUTH_LEVEL_PRIVACY,
690 talloc_asprintf(mem_ctx, "%s$",
691 cli_credentials_get_workstation(wks_creds)),
692 &dom_name, &samr_pipe, &wks_handle, NULL);
694 if (!NT_STATUS_IS_OK(status)) {
695 d_printf("get_wks_handle failed: %s\n", nt_errstr(status));
699 cli_credentials_set_domain(wks_creds, dom_name, CRED_SPECIFIED);
702 struct samr_SetUserInfo2 sui2;
703 union samr_UserInfo u_info;
704 struct samr_UserInfo21 *i21 = &u_info.info25.info;
705 DATA_BLOB session_key;
706 DATA_BLOB confounded_session_key = data_blob_talloc(
708 struct MD5Context ctx;
709 uint8_t confounder[16];
713 i21->full_name.string = talloc_asprintf(
715 cli_credentials_get_workstation(wks_creds));
716 i21->acct_flags = ACB_WSTRUST;
717 i21->fields_present = SAMR_FIELD_FULL_NAME |
718 SAMR_FIELD_ACCT_FLAGS | SAMR_FIELD_PASSWORD;
720 encode_pw_buffer(u_info.info25.password.data,
721 cli_credentials_get_password(wks_creds),
723 status = dcerpc_fetch_session_key(samr_pipe, &session_key);
724 if (!NT_STATUS_IS_OK(status)) {
725 d_printf("dcerpc_fetch_session_key failed: %s\n",
729 generate_random_buffer((uint8_t *)confounder, 16);
732 MD5Update(&ctx, confounder, 16);
733 MD5Update(&ctx, session_key.data, session_key.length);
734 MD5Final(confounded_session_key.data, &ctx);
736 arcfour_crypt_blob(u_info.info25.password.data, 516,
737 &confounded_session_key);
738 memcpy(&u_info.info25.password.data[516], confounder, 16);
740 sui2.in.user_handle = wks_handle;
742 sui2.in.info = &u_info;
744 status = dcerpc_samr_SetUserInfo2(samr_pipe, mem_ctx, &sui2);
745 if (!NT_STATUS_IS_OK(status)) {
746 d_printf("samr_SetUserInfo2(25) failed: %s\n",
751 struct samr_SetUserInfo2 sui2;
752 struct samr_SetUserInfo sui;
753 union samr_UserInfo u_info;
754 DATA_BLOB session_key;
756 encode_pw_buffer(u_info.info24.password.data,
757 cli_credentials_get_password(wks_creds),
759 u_info.info24.pw_len =
760 strlen_m(cli_credentials_get_password(wks_creds))*2;
762 status = dcerpc_fetch_session_key(samr_pipe, &session_key);
763 if (!NT_STATUS_IS_OK(status)) {
764 d_printf("dcerpc_fetch_session_key failed\n");
767 arcfour_crypt_blob(u_info.info24.password.data, 516,
769 sui2.in.user_handle = wks_handle;
770 sui2.in.info = &u_info;
773 status = dcerpc_samr_SetUserInfo2(samr_pipe, mem_ctx, &sui2);
774 if (!NT_STATUS_IS_OK(status)) {
775 d_printf("samr_SetUserInfo(24) failed: %s\n",
780 u_info.info16.acct_flags = ACB_WSTRUST;
781 sui.in.user_handle = wks_handle;
782 sui.in.info = &u_info;
785 status = dcerpc_samr_SetUserInfo(samr_pipe, mem_ctx, &sui);
786 if (!NT_STATUS_IS_OK(status)) {
787 d_printf("samr_SetUserInfo(16) failed\n");
795 talloc_free(mem_ctx);
800 * Do a ReqChallenge/Auth2 and get the wks creds
803 static bool auth2(struct smbcli_state *cli,
804 struct cli_credentials *wks_cred)
807 struct dcerpc_pipe *net_pipe;
810 struct netr_ServerReqChallenge r;
811 struct netr_Credential netr_cli_creds;
812 struct netr_Credential netr_srv_creds;
813 uint32_t negotiate_flags;
814 struct netr_ServerAuthenticate2 a;
815 struct creds_CredentialState *creds_state;
816 struct netr_Credential netr_cred;
817 struct samr_Password mach_pw;
819 mem_ctx = talloc_new(NULL);
820 if (mem_ctx == NULL) {
821 d_printf("talloc_new failed\n");
825 net_pipe = dcerpc_pipe_init(mem_ctx,
826 cli->transport->socket->event.ctx);
827 if (net_pipe == NULL) {
828 d_printf("dcerpc_pipe_init failed\n");
832 status = dcerpc_pipe_open_smb(net_pipe, cli->tree, "\\netlogon");
833 if (!NT_STATUS_IS_OK(status)) {
834 d_printf("dcerpc_pipe_open_smb failed: %s\n",
839 status = dcerpc_bind_auth_none(net_pipe, &ndr_table_netlogon);
840 if (!NT_STATUS_IS_OK(status)) {
841 d_printf("dcerpc_bind_auth_none failed: %s\n",
846 r.in.computer_name = cli_credentials_get_workstation(wks_cred);
847 r.in.server_name = talloc_asprintf(
848 mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
849 if (r.in.server_name == NULL) {
850 d_printf("talloc_asprintf failed\n");
853 generate_random_buffer(netr_cli_creds.data,
854 sizeof(netr_cli_creds.data));
855 r.in.credentials = &netr_cli_creds;
856 r.out.credentials = &netr_srv_creds;
858 status = dcerpc_netr_ServerReqChallenge(net_pipe, mem_ctx, &r);
859 if (!NT_STATUS_IS_OK(status)) {
860 d_printf("netr_ServerReqChallenge failed: %s\n",
865 negotiate_flags = NETLOGON_NEG_AUTH2_FLAGS;
866 E_md4hash(cli_credentials_get_password(wks_cred), mach_pw.hash);
868 creds_state = talloc(mem_ctx, struct creds_CredentialState);
869 creds_client_init(creds_state, r.in.credentials,
870 r.out.credentials, &mach_pw,
871 &netr_cred, negotiate_flags);
873 a.in.server_name = talloc_asprintf(
874 mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
875 a.in.account_name = talloc_asprintf(
876 mem_ctx, "%s$", cli_credentials_get_workstation(wks_cred));
877 a.in.computer_name = cli_credentials_get_workstation(wks_cred);
878 a.in.secure_channel_type = SEC_CHAN_WKSTA;
879 a.in.negotiate_flags = &negotiate_flags;
880 a.out.negotiate_flags = &negotiate_flags;
881 a.in.credentials = &netr_cred;
882 a.out.credentials = &netr_cred;
884 status = dcerpc_netr_ServerAuthenticate2(net_pipe, mem_ctx, &a);
885 if (!NT_STATUS_IS_OK(status)) {
886 d_printf("netr_ServerServerAuthenticate2 failed: %s\n",
891 if (!creds_client_check(creds_state, a.out.credentials)) {
892 d_printf("creds_client_check failed\n");
896 cli_credentials_set_netlogon_creds(wks_cred, creds_state);
901 talloc_free(mem_ctx);
906 * Do a couple of schannel protected Netlogon ops: Interactive and Network
907 * login, and change the wks password
910 static bool schan(struct smbcli_state *cli,
911 struct cli_credentials *wks_creds,
912 struct cli_credentials *user_creds)
917 struct dcerpc_pipe *net_pipe;
920 mem_ctx = talloc_new(NULL);
921 if (mem_ctx == NULL) {
922 d_printf("talloc_new failed\n");
926 net_pipe = dcerpc_pipe_init(mem_ctx,
927 cli->transport->socket->event.ctx);
928 if (net_pipe == NULL) {
929 d_printf("dcerpc_pipe_init failed\n");
933 status = dcerpc_pipe_open_smb(net_pipe, cli->tree, "\\netlogon");
934 if (!NT_STATUS_IS_OK(status)) {
935 d_printf("dcerpc_pipe_open_smb failed: %s\n",
941 net_pipe->conn->flags |= DCERPC_DEBUG_PRINT_IN |
942 DCERPC_DEBUG_PRINT_OUT;
945 net_pipe->conn->flags |= (DCERPC_SIGN | DCERPC_SEAL);
946 status = dcerpc_bind_auth(net_pipe, &ndr_table_netlogon,
947 wks_creds, DCERPC_AUTH_TYPE_SCHANNEL,
948 DCERPC_AUTH_LEVEL_PRIVACY,
951 status = dcerpc_bind_auth_none(net_pipe, &ndr_table_netlogon);
953 if (!NT_STATUS_IS_OK(status)) {
954 d_printf("schannel bind failed: %s\n", nt_errstr(status));
959 for (i=2; i<4; i++) {
961 DATA_BLOB chal, nt_resp, lm_resp, names_blob, session_key;
962 struct creds_CredentialState *creds_state;
963 struct netr_Authenticator netr_auth, netr_auth2;
964 struct netr_NetworkInfo ninfo;
965 struct netr_PasswordInfo pinfo;
966 struct netr_LogonSamLogon r;
968 flags = CLI_CRED_LANMAN_AUTH | CLI_CRED_NTLM_AUTH |
969 CLI_CRED_NTLMv2_AUTH;
971 chal = data_blob_talloc(mem_ctx, NULL, 8);
972 if (chal.data == NULL) {
973 d_printf("data_blob_talloc failed\n");
977 generate_random_buffer(chal.data, chal.length);
978 names_blob = NTLMv2_generate_names_blob(
979 mem_ctx, cli_credentials_get_workstation(user_creds),
980 cli_credentials_get_domain(user_creds));
981 status = cli_credentials_get_ntlm_response(
982 user_creds, mem_ctx, &flags, chal, names_blob,
983 &lm_resp, &nt_resp, NULL, NULL);
984 if (!NT_STATUS_IS_OK(status)) {
985 d_printf("cli_credentials_get_ntlm_response failed:"
986 " %s\n", nt_errstr(status));
990 creds_state = cli_credentials_get_netlogon_creds(wks_creds);
991 creds_client_authenticator(creds_state, &netr_auth);
993 ninfo.identity_info.account_name.string =
994 cli_credentials_get_username(user_creds);
995 ninfo.identity_info.domain_name.string =
996 cli_credentials_get_domain(user_creds);
997 ninfo.identity_info.parameter_control = 0;
998 ninfo.identity_info.logon_id_low = 0;
999 ninfo.identity_info.logon_id_high = 0;
1000 ninfo.identity_info.workstation.string =
1001 cli_credentials_get_workstation(user_creds);
1002 memcpy(ninfo.challenge, chal.data, sizeof(ninfo.challenge));
1003 ninfo.nt.length = nt_resp.length;
1004 ninfo.nt.data = nt_resp.data;
1005 ninfo.lm.length = lm_resp.length;
1006 ninfo.lm.data = lm_resp.data;
1008 r.in.server_name = talloc_asprintf(
1009 mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
1010 ZERO_STRUCT(netr_auth2);
1011 r.in.computer_name =
1012 cli_credentials_get_workstation(wks_creds);
1013 r.in.credential = &netr_auth;
1014 r.in.return_authenticator = &netr_auth2;
1015 r.in.logon_level = 2;
1016 r.in.validation_level = i;
1017 r.in.logon.network = &ninfo;
1018 r.out.return_authenticator = NULL;
1020 status = dcerpc_netr_LogonSamLogon(net_pipe, mem_ctx, &r);
1021 if (!NT_STATUS_IS_OK(status)) {
1022 d_printf("netr_LogonSamLogon failed: %s\n",
1027 if ((r.out.return_authenticator == NULL) ||
1028 (!creds_client_check(creds_state,
1029 &r.out.return_authenticator->cred))) {
1030 d_printf("Credentials check failed!\n");
1034 creds_client_authenticator(creds_state, &netr_auth);
1036 pinfo.identity_info = ninfo.identity_info;
1037 ZERO_STRUCT(pinfo.lmpassword.hash);
1038 E_md4hash(cli_credentials_get_password(user_creds),
1039 pinfo.ntpassword.hash);
1040 session_key = data_blob_talloc(mem_ctx,
1041 creds_state->session_key, 16);
1042 arcfour_crypt_blob(pinfo.ntpassword.hash,
1043 sizeof(pinfo.ntpassword.hash),
1046 r.in.logon_level = 1;
1047 r.in.logon.password = &pinfo;
1048 r.out.return_authenticator = NULL;
1050 status = dcerpc_netr_LogonSamLogon(net_pipe, mem_ctx, &r);
1051 if (!NT_STATUS_IS_OK(status)) {
1052 d_printf("netr_LogonSamLogon failed: %s\n",
1057 if ((r.out.return_authenticator == NULL) ||
1058 (!creds_client_check(creds_state,
1059 &r.out.return_authenticator->cred))) {
1060 d_printf("Credentials check failed!\n");
1066 struct netr_ServerPasswordSet s;
1067 char *password = generate_random_str(wks_creds, 8);
1068 struct creds_CredentialState *creds_state;
1070 s.in.server_name = talloc_asprintf(
1071 mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
1072 s.in.computer_name = cli_credentials_get_workstation(wks_creds);
1073 s.in.account_name = talloc_asprintf(
1074 mem_ctx, "%s$", s.in.computer_name);
1075 s.in.secure_channel_type = SEC_CHAN_WKSTA;
1076 E_md4hash(password, s.in.new_password.hash);
1078 creds_state = cli_credentials_get_netlogon_creds(wks_creds);
1079 creds_des_encrypt(creds_state, &s.in.new_password);
1080 creds_client_authenticator(creds_state, &s.in.credential);
1082 status = dcerpc_netr_ServerPasswordSet(net_pipe, mem_ctx, &s);
1083 if (!NT_STATUS_IS_OK(status)) {
1084 printf("ServerPasswordSet - %s\n", nt_errstr(status));
1088 if (!creds_client_check(creds_state,
1089 &s.out.return_authenticator.cred)) {
1090 printf("Credential chaining failed\n");
1093 cli_credentials_set_password(wks_creds, password,
1099 talloc_free(mem_ctx);
1104 * Delete the wks account again
1107 static bool leave(struct smbcli_state *cli,
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, 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 = create_anon_creds(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 "IPC$", NULL, anon_creds, NULL);
1155 if (!NT_STATUS_IS_OK(status)) {
1156 d_printf("smbcli_full_connection failed: %s\n",
1161 wks_creds = cli_credentials_init(mem_ctx);
1162 if (wks_creds == NULL) {
1163 d_printf("cli_credentials_init failed\n");
1167 cli_credentials_set_conf(wks_creds, global_loadparm);
1168 cli_credentials_set_secure_channel_type(wks_creds, SEC_CHAN_WKSTA);
1169 cli_credentials_set_username(wks_creds, wks_name, CRED_SPECIFIED);
1170 cli_credentials_set_workstation(wks_creds, wks_name, CRED_SPECIFIED);
1171 cli_credentials_set_password(wks_creds,
1172 generate_random_str(wks_creds, 8),
1175 if (!join3(cli, false, cmdline_credentials, wks_creds)) {
1176 d_printf("join failed\n");
1180 cli_credentials_set_domain(
1181 cmdline_credentials, cli_credentials_get_domain(wks_creds),
1184 for (i=0; i<2; i++) {
1186 /* Do this more than once, the routine "schan" changes
1187 * the workstation password using the netlogon
1188 * password change routine */
1192 if (!auth2(cli, wks_creds)) {
1193 d_printf("auth2 failed\n");
1197 for (j=0; j<2; j++) {
1198 if (!schan(cli, wks_creds, cmdline_credentials)) {
1199 d_printf("schan failed\n");
1205 if (!leave(cli, cmdline_credentials, wks_creds)) {
1206 d_printf("leave failed\n");
1213 talloc_free(mem_ctx);
1218 * Do a simple join, testjoin and leave using specified smb and samr
1222 static bool test_join3(TALLOC_CTX *mem_ctx,
1224 struct cli_credentials *smb_creds,
1225 struct cli_credentials *samr_creds,
1226 const char *wks_name)
1230 struct smbcli_state *cli;
1231 struct cli_credentials *wks_creds;
1233 status = smbcli_full_connection(mem_ctx, &cli,
1234 lp_parm_string(global_loadparm, NULL, "torture", "host"),
1235 "IPC$", NULL, smb_creds, NULL);
1236 if (!NT_STATUS_IS_OK(status)) {
1237 d_printf("smbcli_full_connection failed: %s\n",
1242 wks_creds = cli_credentials_init(cli);
1243 if (wks_creds == NULL) {
1244 d_printf("cli_credentials_init failed\n");
1248 cli_credentials_set_conf(wks_creds, global_loadparm);
1249 cli_credentials_set_secure_channel_type(wks_creds, SEC_CHAN_WKSTA);
1250 cli_credentials_set_username(wks_creds, wks_name, CRED_SPECIFIED);
1251 cli_credentials_set_workstation(wks_creds, wks_name, CRED_SPECIFIED);
1252 cli_credentials_set_password(wks_creds,
1253 generate_random_str(wks_creds, 8),
1256 if (!join3(cli, use_level25, samr_creds, wks_creds)) {
1257 d_printf("join failed\n");
1261 cli_credentials_set_domain(
1262 cmdline_credentials, cli_credentials_get_domain(wks_creds),
1265 if (!auth2(cli, wks_creds)) {
1266 d_printf("auth2 failed\n");
1270 if (!leave(cli, samr_creds, wks_creds)) {
1271 d_printf("leave failed\n");
1284 * Test the different session key variants. Do it by joining, this uses the
1285 * session key in the setpassword routine. Test the join by doing the auth2.
1288 bool torture_samba3_sessionkey(struct torture_context *torture)
1290 TALLOC_CTX *mem_ctx;
1292 struct cli_credentials *anon_creds;
1293 const char *wks_name;
1295 wks_name = torture_setting_string(torture, "wksname", get_myname());
1297 mem_ctx = talloc_init("torture_samba3_sessionkey");
1299 if (mem_ctx == NULL) {
1300 d_printf("talloc_init failed\n");
1304 if (!(anon_creds = create_anon_creds(mem_ctx))) {
1305 d_printf("create_anon_creds failed\n");
1311 if (!torture_setting_bool(torture, "samba3", false)) {
1313 /* Samba3 in the build farm right now does this happily. Need
1316 if (test_join3(mem_ctx, false, anon_creds, NULL, wks_name)) {
1317 d_printf("join using anonymous bind on an anonymous smb "
1318 "connection succeeded -- HUH??\n");
1323 if (!test_join3(mem_ctx, false, anon_creds, cmdline_credentials,
1325 d_printf("join using ntlmssp bind on an anonymous smb "
1326 "connection failed\n");
1330 if (!test_join3(mem_ctx, false, cmdline_credentials, NULL, wks_name)) {
1331 d_printf("join using anonymous bind on an authenticated smb "
1332 "connection failed\n");
1336 if (!test_join3(mem_ctx, false, cmdline_credentials,
1337 cmdline_credentials,
1339 d_printf("join using ntlmssp bind on an authenticated smb "
1340 "connection failed\n");
1345 * The following two are tests for setuserinfolevel 25
1348 if (!test_join3(mem_ctx, true, anon_creds, cmdline_credentials,
1350 d_printf("join using ntlmssp bind on an anonymous smb "
1351 "connection failed\n");
1355 if (!test_join3(mem_ctx, true, cmdline_credentials, NULL, wks_name)) {
1356 d_printf("join using anonymous bind on an authenticated smb "
1357 "connection failed\n");
1367 * open pipe and bind, given an IPC$ context
1370 static NTSTATUS pipe_bind_smb(TALLOC_CTX *mem_ctx,
1371 struct smbcli_tree *tree,
1372 const char *pipe_name,
1373 const struct ndr_interface_table *iface,
1374 struct dcerpc_pipe **p)
1376 struct dcerpc_pipe *result;
1379 if (!(result = dcerpc_pipe_init(
1380 mem_ctx, tree->session->transport->socket->event.ctx))) {
1381 return NT_STATUS_NO_MEMORY;
1384 status = dcerpc_pipe_open_smb(result, tree, pipe_name);
1385 if (!NT_STATUS_IS_OK(status)) {
1386 d_printf("dcerpc_pipe_open_smb failed: %s\n",
1388 talloc_free(result);
1392 status = dcerpc_bind_auth_none(result, iface);
1393 if (!NT_STATUS_IS_OK(status)) {
1394 d_printf("schannel bind failed: %s\n", nt_errstr(status));
1395 talloc_free(result);
1400 return NT_STATUS_OK;
1404 * Sane wrapper around lsa_LookupNames
1407 static struct dom_sid *name2sid(TALLOC_CTX *mem_ctx,
1408 struct dcerpc_pipe *p,
1412 struct lsa_ObjectAttribute attr;
1413 struct lsa_QosInfo qos;
1414 struct lsa_OpenPolicy2 r;
1417 struct policy_handle handle;
1418 struct lsa_LookupNames l;
1419 struct lsa_TransSidArray sids;
1420 struct lsa_String lsa_name;
1422 struct dom_sid *result;
1423 TALLOC_CTX *tmp_ctx;
1425 if (!(tmp_ctx = talloc_new(mem_ctx))) {
1430 qos.impersonation_level = 2;
1431 qos.context_mode = 1;
1432 qos.effective_only = 0;
1435 attr.root_dir = NULL;
1436 attr.object_name = NULL;
1437 attr.attributes = 0;
1438 attr.sec_desc = NULL;
1439 attr.sec_qos = &qos;
1441 r.in.system_name = "\\";
1443 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1444 r.out.handle = &handle;
1446 status = dcerpc_lsa_OpenPolicy2(p, tmp_ctx, &r);
1447 if (!NT_STATUS_IS_OK(status)) {
1448 printf("OpenPolicy2 failed - %s\n", nt_errstr(status));
1449 talloc_free(tmp_ctx);
1456 lsa_name.string = talloc_asprintf(tmp_ctx, "%s\\%s", domain, name);
1458 l.in.handle = &handle;
1460 l.in.names = &lsa_name;
1463 l.in.count = &count;
1464 l.out.count = &count;
1467 status = dcerpc_lsa_LookupNames(p, tmp_ctx, &l);
1468 if (!NT_STATUS_IS_OK(status)) {
1469 printf("LookupNames of %s failed - %s\n", lsa_name.string,
1471 talloc_free(tmp_ctx);
1475 result = dom_sid_add_rid(mem_ctx, l.out.domains->domains[0].sid,
1476 l.out.sids->sids[0].rid);
1478 c.in.handle = &handle;
1479 c.out.handle = &handle;
1481 status = dcerpc_lsa_Close(p, tmp_ctx, &c);
1482 if (!NT_STATUS_IS_OK(status)) {
1483 printf("dcerpc_lsa_Close failed - %s\n", nt_errstr(status));
1484 talloc_free(tmp_ctx);
1488 talloc_free(tmp_ctx);
1493 * Find out the user SID on this connection
1496 static struct dom_sid *whoami(TALLOC_CTX *mem_ctx, struct smbcli_tree *tree)
1498 struct dcerpc_pipe *lsa;
1499 struct lsa_GetUserName r;
1501 struct lsa_StringPointer authority_name_p;
1502 struct dom_sid *result;
1504 status = pipe_bind_smb(mem_ctx, tree, "\\pipe\\lsarpc",
1505 &ndr_table_lsarpc, &lsa);
1506 if (!NT_STATUS_IS_OK(status)) {
1507 d_printf("(%s) Could not bind to LSA: %s\n",
1508 __location__, nt_errstr(status));
1512 r.in.system_name = "\\";
1513 r.in.account_name = NULL;
1514 authority_name_p.string = NULL;
1515 r.in.authority_name = &authority_name_p;
1517 status = dcerpc_lsa_GetUserName(lsa, mem_ctx, &r);
1519 if (!NT_STATUS_IS_OK(status)) {
1520 printf("(%s) GetUserName failed - %s\n",
1521 __location__, nt_errstr(status));
1526 result = name2sid(mem_ctx, lsa, r.out.account_name->string,
1527 r.out.authority_name->string->string);
1533 static int destroy_tree(struct smbcli_tree *tree)
1535 smb_tree_disconnect(tree);
1540 * Do a tcon, given a session
1543 NTSTATUS secondary_tcon(TALLOC_CTX *mem_ctx,
1544 struct smbcli_session *session,
1545 const char *sharename,
1546 struct smbcli_tree **res)
1548 struct smbcli_tree *result;
1549 TALLOC_CTX *tmp_ctx;
1550 union smb_tcon tcon;
1553 if (!(tmp_ctx = talloc_new(mem_ctx))) {
1554 return NT_STATUS_NO_MEMORY;
1557 if (!(result = smbcli_tree_init(session, mem_ctx, false))) {
1558 talloc_free(tmp_ctx);
1559 return NT_STATUS_NO_MEMORY;
1562 tcon.generic.level = RAW_TCON_TCONX;
1563 tcon.tconx.in.flags = 0;
1564 tcon.tconx.in.password = data_blob(NULL, 0);
1565 tcon.tconx.in.path = sharename;
1566 tcon.tconx.in.device = "?????";
1568 status = smb_raw_tcon(result, tmp_ctx, &tcon);
1569 if (!NT_STATUS_IS_OK(status)) {
1570 d_printf("(%s) smb_raw_tcon failed: %s\n", __location__,
1572 talloc_free(tmp_ctx);
1576 result->tid = tcon.tconx.out.tid;
1577 result = talloc_steal(mem_ctx, result);
1578 talloc_set_destructor(result, destroy_tree);
1579 talloc_free(tmp_ctx);
1581 return NT_STATUS_OK;
1585 * Test the getusername behaviour
1588 bool torture_samba3_rpc_getusername(struct torture_context *torture)
1591 struct smbcli_state *cli;
1592 TALLOC_CTX *mem_ctx;
1594 struct dom_sid *user_sid;
1595 struct dom_sid *created_sid;
1596 struct cli_credentials *anon_creds;
1597 struct cli_credentials *user_creds;
1600 if (!(mem_ctx = talloc_new(torture))) {
1604 status = smbcli_full_connection(
1605 mem_ctx, &cli, torture_setting_string(torture, "host", NULL),
1606 "IPC$", NULL, cmdline_credentials, NULL);
1607 if (!NT_STATUS_IS_OK(status)) {
1608 d_printf("(%s) smbcli_full_connection failed: %s\n",
1609 __location__, nt_errstr(status));
1614 if (!(user_sid = whoami(mem_ctx, cli->tree))) {
1615 d_printf("(%s) whoami on auth'ed connection failed\n",
1622 if (!(anon_creds = create_anon_creds(mem_ctx))) {
1623 d_printf("(%s) create_anon_creds failed\n", __location__);
1628 status = smbcli_full_connection(
1629 mem_ctx, &cli, torture_setting_string(torture, "host", NULL),
1630 "IPC$", NULL, anon_creds, NULL);
1631 if (!NT_STATUS_IS_OK(status)) {
1632 d_printf("(%s) anon smbcli_full_connection failed: %s\n",
1633 __location__, nt_errstr(status));
1638 if (!(user_sid = whoami(mem_ctx, cli->tree))) {
1639 d_printf("(%s) whoami on anon connection failed\n",
1645 if (!dom_sid_equal(user_sid,
1646 dom_sid_parse_talloc(mem_ctx, "s-1-5-7"))) {
1647 d_printf("(%s) Anon lsa_GetUserName returned %s, expected "
1648 "S-1-5-7", __location__,
1649 dom_sid_string(mem_ctx, user_sid));
1653 if (!(user_creds = cli_credentials_init(mem_ctx))) {
1654 d_printf("(%s) cli_credentials_init failed\n", __location__);
1659 cli_credentials_set_conf(user_creds, global_loadparm);
1660 cli_credentials_set_username(user_creds, "torture_username",
1662 cli_credentials_set_password(user_creds,
1663 generate_random_str(user_creds, 8),
1666 if (!create_user(mem_ctx, cli, cmdline_credentials,
1667 cli_credentials_get_username(user_creds),
1668 cli_credentials_get_password(user_creds),
1669 &domain_name, &created_sid)) {
1670 d_printf("(%s) create_user failed\n", __location__);
1675 cli_credentials_set_domain(user_creds, domain_name,
1679 struct smbcli_session *session2;
1680 struct smb_composite_sesssetup setup;
1681 struct smbcli_tree *tree;
1683 session2 = smbcli_session_init(cli->transport, mem_ctx, false);
1684 if (session2 == NULL) {
1685 d_printf("(%s) smbcli_session_init failed\n",
1690 setup.in.sesskey = cli->transport->negotiate.sesskey;
1691 setup.in.capabilities = cli->transport->negotiate.capabilities;
1692 setup.in.workgroup = "";
1693 setup.in.credentials = user_creds;
1695 status = smb_composite_sesssetup(session2, &setup);
1696 if (!NT_STATUS_IS_OK(status)) {
1697 d_printf("(%s) session setup with new user failed: "
1698 "%s\n", __location__, nt_errstr(status));
1702 session2->vuid = setup.out.vuid;
1704 if (!NT_STATUS_IS_OK(secondary_tcon(mem_ctx, session2,
1706 d_printf("(%s) secondary_tcon failed\n",
1712 if (!(user_sid = whoami(mem_ctx, tree))) {
1713 d_printf("(%s) whoami on user connection failed\n",
1722 d_printf("Created %s, found %s\n",
1723 dom_sid_string(mem_ctx, created_sid),
1724 dom_sid_string(mem_ctx, user_sid));
1726 if (!dom_sid_equal(created_sid, user_sid)) {
1731 if (!delete_user(cli, cmdline_credentials,
1732 cli_credentials_get_username(user_creds))) {
1733 d_printf("(%s) delete_user failed\n", __location__);
1738 talloc_free(mem_ctx);
1742 static bool test_NetShareGetInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
1743 const char *sharename)
1746 struct srvsvc_NetShareGetInfo r;
1747 uint32_t levels[] = { 0, 1, 2, 501, 502, 1004, 1005, 1006, 1007, 1501 };
1751 r.in.server_unc = talloc_asprintf(mem_ctx, "\\\\%s",
1752 dcerpc_server_name(p));
1753 r.in.share_name = sharename;
1755 for (i=0;i<ARRAY_SIZE(levels);i++) {
1756 r.in.level = levels[i];
1760 printf("testing NetShareGetInfo level %u on share '%s'\n",
1761 r.in.level, r.in.share_name);
1763 status = dcerpc_srvsvc_NetShareGetInfo(p, mem_ctx, &r);
1764 if (!NT_STATUS_IS_OK(status)) {
1765 printf("NetShareGetInfo level %u on share '%s' failed"
1766 " - %s\n", r.in.level, r.in.share_name,
1771 if (!W_ERROR_IS_OK(r.out.result)) {
1772 printf("NetShareGetInfo level %u on share '%s' failed "
1773 "- %s\n", r.in.level, r.in.share_name,
1774 win_errstr(r.out.result));
1783 static bool test_NetShareEnum(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
1784 const char **one_sharename)
1787 struct srvsvc_NetShareEnum r;
1788 struct srvsvc_NetShareCtr0 c0;
1789 uint32_t levels[] = { 0, 1, 2, 501, 502, 1004, 1005, 1006, 1007 };
1793 r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
1794 r.in.ctr.ctr0 = &c0;
1795 r.in.ctr.ctr0->count = 0;
1796 r.in.ctr.ctr0->array = NULL;
1797 r.in.max_buffer = (uint32_t)-1;
1798 r.in.resume_handle = NULL;
1800 for (i=0;i<ARRAY_SIZE(levels);i++) {
1801 r.in.level = levels[i];
1805 printf("testing NetShareEnum level %u\n", r.in.level);
1806 status = dcerpc_srvsvc_NetShareEnum(p, mem_ctx, &r);
1807 if (!NT_STATUS_IS_OK(status)) {
1808 printf("NetShareEnum level %u failed - %s\n",
1809 r.in.level, nt_errstr(status));
1813 if (!W_ERROR_IS_OK(r.out.result)) {
1814 printf("NetShareEnum level %u failed - %s\n",
1815 r.in.level, win_errstr(r.out.result));
1818 if (r.in.level == 0) {
1819 struct srvsvc_NetShareCtr0 *ctr = r.out.ctr.ctr0;
1820 if (ctr->count > 0) {
1821 *one_sharename = ctr->array[0].name;
1829 bool torture_samba3_rpc_srvsvc(struct torture_context *torture)
1831 struct dcerpc_pipe *p;
1832 TALLOC_CTX *mem_ctx;
1834 const char *sharename = NULL;
1835 struct smbcli_state *cli;
1838 if (!(mem_ctx = talloc_new(torture))) {
1842 if (!(torture_open_connection_share(
1843 mem_ctx, &cli, torture_setting_string(torture, "host", NULL),
1845 talloc_free(mem_ctx);
1849 status = pipe_bind_smb(mem_ctx, cli->tree, "\\pipe\\srvsvc",
1850 &ndr_table_srvsvc, &p);
1851 if (!NT_STATUS_IS_OK(status)) {
1852 d_printf("(%s) could not bind to srvsvc pipe: %s\n",
1853 __location__, nt_errstr(status));
1858 ret &= test_NetShareEnum(p, mem_ctx, &sharename);
1859 if (sharename == NULL) {
1860 printf("did not get sharename\n");
1862 ret &= test_NetShareGetInfo(p, mem_ctx, sharename);
1866 talloc_free(mem_ctx);
1871 * Do a ReqChallenge/Auth2 with a random wks name, make sure it returns
1872 * NT_STATUS_NO_SAM_ACCOUNT
1875 bool torture_samba3_rpc_randomauth2(struct torture_context *torture)
1877 TALLOC_CTX *mem_ctx;
1878 struct dcerpc_pipe *net_pipe;
1880 bool result = false;
1882 struct netr_ServerReqChallenge r;
1883 struct netr_Credential netr_cli_creds;
1884 struct netr_Credential netr_srv_creds;
1885 uint32_t negotiate_flags;
1886 struct netr_ServerAuthenticate2 a;
1887 struct creds_CredentialState *creds_state;
1888 struct netr_Credential netr_cred;
1889 struct samr_Password mach_pw;
1890 struct smbcli_state *cli;
1892 if (!(mem_ctx = talloc_new(torture))) {
1893 d_printf("talloc_new failed\n");
1897 if (!(wksname = generate_random_str_list(
1898 mem_ctx, 14, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"))) {
1899 d_printf("generate_random_str_list failed\n");
1903 if (!(torture_open_connection_share(
1905 torture_setting_string(torture, "host", NULL),
1907 d_printf("IPC$ connection failed\n");
1911 if (!(net_pipe = dcerpc_pipe_init(
1912 mem_ctx, cli->transport->socket->event.ctx))) {
1913 d_printf("dcerpc_pipe_init failed\n");
1917 status = dcerpc_pipe_open_smb(net_pipe, cli->tree, "\\netlogon");
1918 if (!NT_STATUS_IS_OK(status)) {
1919 d_printf("dcerpc_pipe_open_smb failed: %s\n",
1924 status = dcerpc_bind_auth_none(net_pipe, &ndr_table_netlogon);
1925 if (!NT_STATUS_IS_OK(status)) {
1926 d_printf("dcerpc_bind_auth_none failed: %s\n",
1931 r.in.computer_name = wksname;
1932 r.in.server_name = talloc_asprintf(
1933 mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
1934 if (r.in.server_name == NULL) {
1935 d_printf("talloc_asprintf failed\n");
1938 generate_random_buffer(netr_cli_creds.data,
1939 sizeof(netr_cli_creds.data));
1940 r.in.credentials = &netr_cli_creds;
1941 r.out.credentials = &netr_srv_creds;
1943 status = dcerpc_netr_ServerReqChallenge(net_pipe, mem_ctx, &r);
1944 if (!NT_STATUS_IS_OK(status)) {
1945 d_printf("netr_ServerReqChallenge failed: %s\n",
1950 negotiate_flags = NETLOGON_NEG_AUTH2_FLAGS;
1951 E_md4hash("foobar", mach_pw.hash);
1953 creds_state = talloc(mem_ctx, struct creds_CredentialState);
1954 creds_client_init(creds_state, r.in.credentials,
1955 r.out.credentials, &mach_pw,
1956 &netr_cred, negotiate_flags);
1958 a.in.server_name = talloc_asprintf(
1959 mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
1960 a.in.account_name = talloc_asprintf(
1961 mem_ctx, "%s$", wksname);
1962 a.in.computer_name = wksname;
1963 a.in.secure_channel_type = SEC_CHAN_WKSTA;
1964 a.in.negotiate_flags = &negotiate_flags;
1965 a.out.negotiate_flags = &negotiate_flags;
1966 a.in.credentials = &netr_cred;
1967 a.out.credentials = &netr_cred;
1969 status = dcerpc_netr_ServerAuthenticate2(net_pipe, mem_ctx, &a);
1971 if (!NT_STATUS_EQUAL(status, NT_STATUS_NO_TRUST_SAM_ACCOUNT)) {
1972 d_printf("dcerpc_netr_ServerAuthenticate2 returned %s, "
1973 "expected NT_STATUS_NO_TRUST_SAM_ACCOUNT\n",
1980 talloc_free(mem_ctx);
1984 static struct security_descriptor *get_sharesec(TALLOC_CTX *mem_ctx,
1985 struct smbcli_session *sess,
1986 const char *sharename)
1988 struct smbcli_tree *tree;
1989 TALLOC_CTX *tmp_ctx;
1990 struct dcerpc_pipe *p;
1992 struct srvsvc_NetShareGetInfo r;
1993 struct security_descriptor *result;
1995 if (!(tmp_ctx = talloc_new(mem_ctx))) {
1996 d_printf("talloc_new failed\n");
2000 if (!NT_STATUS_IS_OK(secondary_tcon(tmp_ctx, sess, "IPC$", &tree))) {
2001 d_printf("secondary_tcon failed\n");
2002 talloc_free(tmp_ctx);
2006 status = pipe_bind_smb(mem_ctx, tree, "\\pipe\\srvsvc",
2007 &ndr_table_srvsvc, &p);
2008 if (!NT_STATUS_IS_OK(status)) {
2009 d_printf("(%s) could not bind to srvsvc pipe: %s\n",
2010 __location__, nt_errstr(status));
2011 talloc_free(tmp_ctx);
2016 p->conn->flags |= DCERPC_DEBUG_PRINT_IN | DCERPC_DEBUG_PRINT_OUT;
2019 r.in.server_unc = talloc_asprintf(tmp_ctx, "\\\\%s",
2020 dcerpc_server_name(p));
2021 r.in.share_name = sharename;
2024 status = dcerpc_srvsvc_NetShareGetInfo(p, tmp_ctx, &r);
2025 if (!NT_STATUS_IS_OK(status)) {
2026 d_printf("srvsvc_NetShareGetInfo failed: %s\n",
2028 talloc_free(tmp_ctx);
2032 result = talloc_steal(mem_ctx, r.out.info.info502->sd);
2033 talloc_free(tmp_ctx);
2037 static NTSTATUS set_sharesec(TALLOC_CTX *mem_ctx,
2038 struct smbcli_session *sess,
2039 const char *sharename,
2040 struct security_descriptor *sd)
2042 struct smbcli_tree *tree;
2043 TALLOC_CTX *tmp_ctx;
2044 struct dcerpc_pipe *p;
2046 struct sec_desc_buf i;
2047 struct srvsvc_NetShareSetInfo r;
2050 if (!(tmp_ctx = talloc_new(mem_ctx))) {
2051 d_printf("talloc_new failed\n");
2052 return NT_STATUS_NO_MEMORY;
2055 if (!NT_STATUS_IS_OK(secondary_tcon(tmp_ctx, sess, "IPC$", &tree))) {
2056 d_printf("secondary_tcon failed\n");
2057 talloc_free(tmp_ctx);
2058 return NT_STATUS_UNSUCCESSFUL;
2061 status = pipe_bind_smb(mem_ctx, tree, "\\pipe\\srvsvc",
2062 &ndr_table_srvsvc, &p);
2063 if (!NT_STATUS_IS_OK(status)) {
2064 d_printf("(%s) could not bind to srvsvc pipe: %s\n",
2065 __location__, nt_errstr(status));
2066 talloc_free(tmp_ctx);
2067 return NT_STATUS_UNSUCCESSFUL;
2071 p->conn->flags |= DCERPC_DEBUG_PRINT_IN | DCERPC_DEBUG_PRINT_OUT;
2074 r.in.server_unc = talloc_asprintf(tmp_ctx, "\\\\%s",
2075 dcerpc_server_name(p));
2076 r.in.share_name = sharename;
2079 r.in.info.info1501 = &i;
2080 r.in.parm_error = &error;
2082 status = dcerpc_srvsvc_NetShareSetInfo(p, tmp_ctx, &r);
2083 if (!NT_STATUS_IS_OK(status)) {
2084 d_printf("srvsvc_NetShareGetInfo failed: %s\n",
2088 talloc_free(tmp_ctx);
2092 bool try_tcon(TALLOC_CTX *mem_ctx,
2093 struct security_descriptor *orig_sd,
2094 struct smbcli_session *session,
2095 const char *sharename, const struct dom_sid *user_sid,
2096 unsigned int access_mask, NTSTATUS expected_tcon,
2097 NTSTATUS expected_mkdir)
2099 TALLOC_CTX *tmp_ctx;
2100 struct smbcli_tree *rmdir_tree, *tree;
2101 struct dom_sid *domain_sid;
2103 struct security_descriptor *sd;
2107 if (!(tmp_ctx = talloc_new(mem_ctx))) {
2108 d_printf("talloc_new failed\n");
2112 status = secondary_tcon(tmp_ctx, session, sharename, &rmdir_tree);
2113 if (!NT_STATUS_IS_OK(status)) {
2114 d_printf("first tcon to delete dir failed\n");
2115 talloc_free(tmp_ctx);
2119 smbcli_rmdir(rmdir_tree, "sharesec_testdir");
2121 if (!NT_STATUS_IS_OK(dom_sid_split_rid(tmp_ctx, user_sid,
2122 &domain_sid, &rid))) {
2123 d_printf("dom_sid_split_rid failed\n");
2124 talloc_free(tmp_ctx);
2128 sd = security_descriptor_dacl_create(
2129 tmp_ctx, 0, "S-1-5-32-544",
2130 dom_sid_string(mem_ctx, dom_sid_add_rid(mem_ctx, domain_sid,
2132 dom_sid_string(mem_ctx, user_sid),
2133 SEC_ACE_TYPE_ACCESS_ALLOWED, access_mask, 0, NULL);
2135 d_printf("security_descriptor_dacl_create failed\n");
2136 talloc_free(tmp_ctx);
2140 status = set_sharesec(mem_ctx, session, sharename, sd);
2141 if (!NT_STATUS_IS_OK(status)) {
2142 d_printf("custom set_sharesec failed: %s\n",
2144 talloc_free(tmp_ctx);
2148 status = secondary_tcon(tmp_ctx, session, sharename, &tree);
2149 if (!NT_STATUS_EQUAL(status, expected_tcon)) {
2150 d_printf("Expected %s, got %s\n", nt_errstr(expected_tcon),
2156 if (!NT_STATUS_IS_OK(status)) {
2157 /* An expected non-access, no point in trying to write */
2161 status = smbcli_mkdir(tree, "sharesec_testdir");
2162 if (!NT_STATUS_EQUAL(status, expected_mkdir)) {
2163 d_printf("(%s) Expected %s, got %s\n", __location__,
2164 nt_errstr(expected_mkdir), nt_errstr(status));
2169 smbcli_rmdir(rmdir_tree, "sharesec_testdir");
2171 status = set_sharesec(mem_ctx, session, sharename, orig_sd);
2172 if (!NT_STATUS_IS_OK(status)) {
2173 d_printf("custom set_sharesec failed: %s\n",
2175 talloc_free(tmp_ctx);
2179 talloc_free(tmp_ctx);
2183 bool torture_samba3_rpc_sharesec(struct torture_context *torture)
2185 TALLOC_CTX *mem_ctx;
2187 struct smbcli_state *cli;
2188 struct security_descriptor *sd;
2189 struct dom_sid *user_sid;
2191 if (!(mem_ctx = talloc_new(torture))) {
2195 if (!(torture_open_connection_share(
2196 mem_ctx, &cli, torture_setting_string(torture, "host", NULL),
2198 d_printf("IPC$ connection failed\n");
2199 talloc_free(mem_ctx);
2203 if (!(user_sid = whoami(mem_ctx, cli->tree))) {
2204 d_printf("whoami failed\n");
2205 talloc_free(mem_ctx);
2209 sd = get_sharesec(mem_ctx, cli->session, torture_setting_string(torture,
2212 ret &= try_tcon(mem_ctx, sd, cli->session,
2213 torture_setting_string(torture, "share", NULL),
2214 user_sid, 0, NT_STATUS_ACCESS_DENIED, NT_STATUS_OK);
2216 ret &= try_tcon(mem_ctx, sd, cli->session,
2217 torture_setting_string(torture, "share", NULL),
2218 user_sid, SEC_FILE_READ_DATA, NT_STATUS_OK,
2219 NT_STATUS_MEDIA_WRITE_PROTECTED);
2221 ret &= try_tcon(mem_ctx, sd, cli->session,
2222 torture_setting_string(torture, "share", NULL),
2223 user_sid, SEC_FILE_ALL, NT_STATUS_OK, NT_STATUS_OK);
2225 talloc_free(mem_ctx);
2229 bool torture_samba3_rpc_lsa(struct torture_context *torture)
2231 TALLOC_CTX *mem_ctx;
2233 struct smbcli_state *cli;
2234 struct dcerpc_pipe *p;
2235 struct policy_handle lsa_handle;
2237 struct dom_sid *domain_sid;
2239 if (!(mem_ctx = talloc_new(torture))) {
2243 if (!(torture_open_connection_share(
2244 mem_ctx, &cli, torture_setting_string(torture, "host", NULL),
2246 d_printf("IPC$ connection failed\n");
2247 talloc_free(mem_ctx);
2251 status = pipe_bind_smb(mem_ctx, cli->tree, "\\lsarpc",
2252 &ndr_table_lsarpc, &p);
2253 if (!NT_STATUS_IS_OK(status)) {
2254 d_printf("(%s) pipe_bind_smb failed: %s\n", __location__,
2256 talloc_free(mem_ctx);
2261 struct lsa_ObjectAttribute attr;
2262 struct lsa_OpenPolicy2 o;
2263 o.in.system_name = talloc_asprintf(
2264 mem_ctx, "\\\\%s", dcerpc_server_name(p));
2267 o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2268 o.out.handle = &lsa_handle;
2269 status = dcerpc_lsa_OpenPolicy2(p, mem_ctx, &o);
2270 if (!NT_STATUS_IS_OK(status)) {
2271 d_printf("(%s) dcerpc_lsa_OpenPolicy2 failed: %s\n",
2272 __location__, nt_errstr(status));
2273 talloc_free(mem_ctx);
2279 p->conn->flags |= DCERPC_DEBUG_PRINT_IN | DCERPC_DEBUG_PRINT_OUT;
2284 int levels[] = { 2,3,5,6 };
2286 for (i=0; i<ARRAY_SIZE(levels); i++) {
2287 struct lsa_QueryInfoPolicy r;
2288 r.in.handle = &lsa_handle;
2289 r.in.level = levels[i];
2290 status = dcerpc_lsa_QueryInfoPolicy(p, mem_ctx, &r);
2291 if (!NT_STATUS_IS_OK(status)) {
2292 d_printf("(%s) dcerpc_lsa_QueryInfoPolicy %d "
2293 "failed: %s\n", __location__,
2294 levels[i], nt_errstr(status));
2295 talloc_free(mem_ctx);
2298 if (levels[i] == 5) {
2299 domain_sid = r.out.info->account_domain.sid;
2307 static NTSTATUS get_servername(TALLOC_CTX *mem_ctx, struct smbcli_tree *tree,
2310 struct rap_WserverGetInfo r;
2312 char servername[17];
2315 r.in.bufsize = 0xffff;
2317 status = smbcli_rap_netservergetinfo(tree, mem_ctx, &r);
2318 if (!NT_STATUS_IS_OK(status)) {
2322 memcpy(servername, r.out.info.info0.name, 16);
2323 servername[16] = '\0';
2325 if (pull_ascii_talloc(mem_ctx, 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_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(global_loadparm));
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_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 status = NT_STATUS_NO_MEMORY;
2987 status = secondary_tcon(p, cli->session, "IPC$", &ipc);
2988 if (!NT_STATUS_IS_OK(status)) {
2992 status = dcerpc_pipe_open_smb(p, ipc, "\\pipe\\srvsvc");
2993 if (!NT_STATUS_IS_OK(status)) {
2994 d_printf("dcerpc_pipe_open_smb failed: %s\n",
2999 status = dcerpc_bind_auth_none(p, &ndr_table_srvsvc);
3000 if (!NT_STATUS_IS_OK(status)) {
3001 d_printf("dcerpc_bind_auth_none failed: %s\n",
3006 r.in.server_unc = talloc_asprintf(mem_ctx, "\\\\%s",
3007 dcerpc_server_name(p));
3008 r.in.share_name = share;
3011 status = dcerpc_srvsvc_NetShareGetInfo(p, p, &r);
3012 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
3013 d_printf("(%s) OpenHKLM failed: %s, %s\n", __location__,
3014 nt_errstr(status), win_errstr(r.out.result));
3018 *info = talloc_move(mem_ctx, &r.out.info.info502);
3019 return NT_STATUS_OK;
3027 * Get us a handle on HKLM\
3030 static NTSTATUS get_hklm_handle(TALLOC_CTX *mem_ctx,
3031 struct smbcli_state *cli,
3032 struct dcerpc_pipe **pipe_p,
3033 struct policy_handle **handle)
3035 struct smbcli_tree *ipc;
3036 struct dcerpc_pipe *p;
3037 struct winreg_OpenHKLM r;
3039 struct policy_handle *result;
3041 result = talloc(mem_ctx, struct policy_handle);
3043 if (result == NULL) {
3044 return NT_STATUS_NO_MEMORY;
3047 if (!(p = dcerpc_pipe_init(result,
3048 cli->transport->socket->event.ctx))) {
3049 status = NT_STATUS_NO_MEMORY;
3053 status = secondary_tcon(p, cli->session, "IPC$", &ipc);
3054 if (!NT_STATUS_IS_OK(status)) {
3058 status = dcerpc_pipe_open_smb(p, ipc, "\\winreg");
3059 if (!NT_STATUS_IS_OK(status)) {
3060 d_printf("dcerpc_pipe_open_smb failed: %s\n",
3065 status = dcerpc_bind_auth_none(p, &ndr_table_winreg);
3066 if (!NT_STATUS_IS_OK(status)) {
3067 d_printf("dcerpc_bind_auth_none failed: %s\n",
3072 r.in.system_name = 0;
3073 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3074 r.out.handle = result;
3076 status = dcerpc_winreg_OpenHKLM(p, p, &r);
3077 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
3078 d_printf("(%s) OpenHKLM failed: %s, %s\n", __location__,
3079 nt_errstr(status), win_errstr(r.out.result));
3085 return NT_STATUS_OK;
3088 talloc_free(result);
3092 static NTSTATUS torture_samba3_createshare(struct smbcli_state *cli,
3093 const char *sharename)
3095 struct dcerpc_pipe *p;
3096 struct policy_handle *hklm = NULL;
3097 struct policy_handle new_handle;
3098 struct winreg_CreateKey c;
3099 struct winreg_CloseKey cl;
3100 enum winreg_CreateAction action_taken;
3102 TALLOC_CTX *mem_ctx;
3104 mem_ctx = talloc_new(cli);
3105 NT_STATUS_HAVE_NO_MEMORY(mem_ctx);
3107 status = get_hklm_handle(mem_ctx, cli, &p, &hklm);
3108 if (!NT_STATUS_IS_OK(status)) {
3109 d_printf("get_hklm_handle failed: %s\n", nt_errstr(status));
3114 c.in.name.name = talloc_asprintf(
3115 mem_ctx, "software\\samba\\smbconf\\%s", sharename);
3116 if (c.in.name.name == NULL) {
3117 d_printf("talloc_asprintf failed\n");
3118 status = NT_STATUS_NO_MEMORY;
3121 c.in.keyclass.name = "";
3123 c.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3124 c.in.secdesc = NULL;
3125 c.in.action_taken = &action_taken;
3126 c.out.new_handle = &new_handle;
3127 c.out.action_taken = &action_taken;
3129 status = dcerpc_winreg_CreateKey(p, p, &c);
3130 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(c.out.result)) {
3131 d_printf("(%s) OpenKey failed: %s, %s\n", __location__,
3132 nt_errstr(status), win_errstr(c.out.result));
3136 cl.in.handle = &new_handle;
3137 cl.out.handle = &new_handle;
3138 status = dcerpc_winreg_CloseKey(p, p, &cl);
3139 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(cl.out.result)) {
3140 d_printf("(%s) OpenKey failed: %s, %s\n", __location__,
3141 nt_errstr(status), win_errstr(cl.out.result));
3147 talloc_free(mem_ctx);
3151 static NTSTATUS torture_samba3_deleteshare(struct smbcli_state *cli,
3152 const char *sharename)
3154 struct dcerpc_pipe *p;
3155 struct policy_handle *hklm = NULL;
3156 struct winreg_DeleteKey d;
3158 TALLOC_CTX *mem_ctx;
3160 mem_ctx = talloc_new(cli);
3161 NT_STATUS_HAVE_NO_MEMORY(mem_ctx);
3163 status = get_hklm_handle(cli, cli, &p, &hklm);
3164 if (!NT_STATUS_IS_OK(status)) {
3165 d_printf("get_hklm_handle failed: %s\n", nt_errstr(status));
3170 d.in.key.name = talloc_asprintf(
3171 mem_ctx, "software\\samba\\smbconf\\%s", sharename);
3172 if (d.in.key.name == NULL) {
3173 d_printf("talloc_asprintf failed\n");
3174 status = NT_STATUS_NO_MEMORY;
3177 status = dcerpc_winreg_DeleteKey(p, p, &d);
3178 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(d.out.result)) {
3179 d_printf("(%s) OpenKey failed: %s, %s\n", __location__,
3180 nt_errstr(status), win_errstr(d.out.result));
3185 talloc_free(mem_ctx);
3189 static NTSTATUS torture_samba3_setconfig(struct smbcli_state *cli,
3190 const char *sharename,
3191 const char *parameter,
3194 struct dcerpc_pipe *p = NULL;
3195 struct policy_handle *hklm = NULL, key_handle;
3196 struct winreg_OpenKey o;
3197 struct winreg_SetValue s;
3202 status = get_hklm_handle(cli, cli, &p, &hklm);
3203 if (!NT_STATUS_IS_OK(status)) {
3204 d_printf("get_hklm_handle failed: %s\n", nt_errstr(status));
3208 o.in.parent_handle = hklm;
3209 o.in.keyname.name = talloc_asprintf(
3210 hklm, "software\\samba\\smbconf\\%s", sharename);
3211 if (o.in.keyname.name == NULL) {
3212 d_printf("talloc_asprintf failed\n");
3213 status = NT_STATUS_NO_MEMORY;
3217 o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3218 o.out.handle = &key_handle;
3220 status = dcerpc_winreg_OpenKey(p, p, &o);
3221 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(o.out.result)) {
3222 d_printf("(%s) OpenKey failed: %s, %s\n", __location__,
3223 nt_errstr(status), win_errstr(o.out.result));
3227 if (!reg_string_to_val(hklm, "REG_SZ", value, &type, &val)) {
3228 d_printf("(%s) reg_string_to_val failed\n", __location__);
3232 s.in.handle = &key_handle;
3233 s.in.name.name = parameter;
3235 s.in.data = val.data;
3236 s.in.size = val.length;
3238 status = dcerpc_winreg_SetValue(p, p, &s);
3239 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(s.out.result)) {
3240 d_printf("(%s) SetValue failed: %s, %s\n", __location__,
3241 nt_errstr(status), win_errstr(s.out.result));
3250 bool torture_samba3_regconfig(struct torture_context *torture)
3252 struct smbcli_state *cli;
3253 struct srvsvc_NetShareInfo502 *i = NULL;
3256 const char *comment = "Dummer Kommentar";
3258 if (!(torture_open_connection(&cli, 0))) {
3262 status = torture_samba3_createshare(cli, "blubber");
3263 if (!NT_STATUS_IS_OK(status)) {
3264 torture_warning(torture, "torture_samba3_createshare failed: "
3265 "%s\n", nt_errstr(status));
3269 status = torture_samba3_setconfig(cli, "blubber", "comment", comment);
3270 if (!NT_STATUS_IS_OK(status)) {
3271 torture_warning(torture, "torture_samba3_setconfig failed: "
3272 "%s\n", nt_errstr(status));
3276 status = get_shareinfo(torture, cli, "blubber", &i);
3277 if (!NT_STATUS_IS_OK(status)) {
3278 torture_warning(torture, "get_shareinfo failed: "
3279 "%s\n", nt_errstr(status));
3283 if (strcmp(comment, i->comment) != 0) {
3284 torture_warning(torture, "Expected comment [%s], got [%s]\n",
3285 comment, i->comment);
3289 status = torture_samba3_deleteshare(cli, "blubber");
3290 if (!NT_STATUS_IS_OK(status)) {
3291 torture_warning(torture, "torture_samba3_deleteshare failed: "
3292 "%s\n", nt_errstr(status));