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 2 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, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "torture/torture.h"
25 #include "librpc/gen_ndr/ndr_lsa.h"
26 #include "librpc/gen_ndr/ndr_lsa_c.h"
27 #include "librpc/gen_ndr/ndr_samr.h"
28 #include "librpc/gen_ndr/ndr_samr_c.h"
29 #include "librpc/gen_ndr/ndr_netlogon.h"
30 #include "librpc/gen_ndr/ndr_netlogon_c.h"
31 #include "lib/cmdline/popt_common.h"
32 #include "librpc/rpc/dcerpc.h"
33 #include "torture/rpc/rpc.h"
34 #include "libcli/libcli.h"
35 #include "libcli/composite/composite.h"
36 #include "libcli/smb_composite/smb_composite.h"
37 #include "libcli/auth/libcli_auth.h"
38 #include "libcli/auth/credentials.h"
39 #include "lib/crypto/crypto.h"
42 * This tests a RPC call using an invalid vuid
45 BOOL torture_bind_authcontext(struct torture_context *torture)
50 struct lsa_ObjectAttribute objectattr;
51 struct lsa_OpenPolicy2 openpolicy;
52 struct policy_handle handle;
53 struct lsa_Close close;
54 struct smbcli_session *tmp;
55 struct smbcli_session *session2;
56 struct smbcli_state *cli;
57 struct dcerpc_pipe *lsa_pipe;
58 struct cli_credentials *anon_creds;
59 struct smb_composite_sesssetup setup;
61 mem_ctx = talloc_init("torture_bind_authcontext");
63 if (mem_ctx == NULL) {
64 d_printf("talloc_init failed\n");
68 status = smbcli_full_connection(mem_ctx, &cli,
69 lp_parm_string(-1, "torture", "host"),
70 "IPC$", NULL, cmdline_credentials,
72 if (!NT_STATUS_IS_OK(status)) {
73 d_printf("smbcli_full_connection failed: %s\n",
78 lsa_pipe = dcerpc_pipe_init(mem_ctx, cli->transport->socket->event.ctx);
79 if (lsa_pipe == NULL) {
80 d_printf("dcerpc_pipe_init failed\n");
84 status = dcerpc_pipe_open_smb(lsa_pipe->conn, cli->tree, "\\lsarpc");
85 if (!NT_STATUS_IS_OK(status)) {
86 d_printf("dcerpc_pipe_open_smb failed: %s\n",
91 status = dcerpc_bind_auth_none(lsa_pipe, &dcerpc_table_lsarpc);
92 if (!NT_STATUS_IS_OK(status)) {
93 d_printf("dcerpc_bind_auth_none failed: %s\n",
98 openpolicy.in.system_name =talloc_asprintf(
99 mem_ctx, "\\\\%s", dcerpc_server_name(lsa_pipe));
100 ZERO_STRUCT(objectattr);
101 openpolicy.in.attr = &objectattr;
102 openpolicy.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
103 openpolicy.out.handle = &handle;
105 status = dcerpc_lsa_OpenPolicy2(lsa_pipe, mem_ctx, &openpolicy);
107 if (!NT_STATUS_IS_OK(status)) {
108 d_printf("dcerpc_lsa_OpenPolicy2 failed: %s\n",
113 close.in.handle = &handle;
114 close.out.handle = &handle;
116 status = dcerpc_lsa_Close(lsa_pipe, mem_ctx, &close);
117 if (!NT_STATUS_IS_OK(status)) {
118 d_printf("dcerpc_lsa_Close failed: %s\n",
123 session2 = smbcli_session_init(cli->transport, mem_ctx, False);
124 if (session2 == NULL) {
125 d_printf("smbcli_session_init failed\n");
129 anon_creds = cli_credentials_init(mem_ctx);
130 if (anon_creds == NULL) {
131 d_printf("cli_credentials_init failed\n");
135 cli_credentials_set_conf(anon_creds);
136 cli_credentials_set_anonymous(anon_creds);
138 setup.in.sesskey = cli->transport->negotiate.sesskey;
139 setup.in.capabilities = cli->transport->negotiate.capabilities;
140 setup.in.workgroup = "";
141 setup.in.credentials = anon_creds;
143 status = smb_composite_sesssetup(session2, &setup);
144 if (!NT_STATUS_IS_OK(status)) {
145 d_printf("anon session setup failed: %s\n",
150 tmp = cli->tree->session;
151 cli->tree->session = session2;
153 status = dcerpc_lsa_OpenPolicy2(lsa_pipe, mem_ctx, &openpolicy);
155 cli->tree->session = tmp;
156 talloc_free(lsa_pipe);
159 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
160 d_printf("dcerpc_lsa_OpenPolicy2 with wrong vuid gave %s, "
161 "expected NT_STATUS_INVALID_HANDLE\n",
168 talloc_free(mem_ctx);
173 * Bind to lsa using a specific auth method
176 static BOOL bindtest(struct smbcli_state *cli,
177 struct cli_credentials *credentials,
178 uint8_t auth_type, uint8_t auth_level)
184 struct dcerpc_pipe *lsa_pipe;
185 struct lsa_ObjectAttribute objectattr;
186 struct lsa_OpenPolicy2 openpolicy;
187 struct lsa_QueryInfoPolicy query;
188 struct policy_handle handle;
189 struct lsa_Close close;
191 if ((mem_ctx = talloc_init("bindtest")) == NULL) {
192 d_printf("talloc_init failed\n");
196 lsa_pipe = dcerpc_pipe_init(mem_ctx,
197 cli->transport->socket->event.ctx);
198 if (lsa_pipe == NULL) {
199 d_printf("dcerpc_pipe_init failed\n");
203 status = dcerpc_pipe_open_smb(lsa_pipe->conn, cli->tree, "\\lsarpc");
204 if (!NT_STATUS_IS_OK(status)) {
205 d_printf("dcerpc_pipe_open_smb failed: %s\n",
210 status = dcerpc_bind_auth(lsa_pipe, &dcerpc_table_lsarpc,
211 credentials, auth_type, auth_level,
213 if (!NT_STATUS_IS_OK(status)) {
214 d_printf("dcerpc_bind_auth failed: %s\n", nt_errstr(status));
218 openpolicy.in.system_name =talloc_asprintf(
219 mem_ctx, "\\\\%s", dcerpc_server_name(lsa_pipe));
220 ZERO_STRUCT(objectattr);
221 openpolicy.in.attr = &objectattr;
222 openpolicy.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
223 openpolicy.out.handle = &handle;
225 status = dcerpc_lsa_OpenPolicy2(lsa_pipe, mem_ctx, &openpolicy);
227 if (!NT_STATUS_IS_OK(status)) {
228 d_printf("dcerpc_lsa_OpenPolicy2 failed: %s\n",
233 query.in.handle = &handle;
234 query.in.level = LSA_POLICY_INFO_DOMAIN;
236 status = dcerpc_lsa_QueryInfoPolicy(lsa_pipe, mem_ctx, &query);
237 if (!NT_STATUS_IS_OK(status)) {
238 d_printf("dcerpc_lsa_QueryInfoPolicy failed: %s\n",
243 close.in.handle = &handle;
244 close.out.handle = &handle;
246 status = dcerpc_lsa_Close(lsa_pipe, mem_ctx, &close);
247 if (!NT_STATUS_IS_OK(status)) {
248 d_printf("dcerpc_lsa_Close failed: %s\n",
255 talloc_free(mem_ctx);
260 * test authenticated RPC binds with the variants Samba3 does support
263 BOOL torture_bind_samba3(struct torture_context *torture)
268 struct smbcli_state *cli;
270 mem_ctx = talloc_init("torture_bind_authcontext");
272 if (mem_ctx == NULL) {
273 d_printf("talloc_init failed\n");
277 status = smbcli_full_connection(mem_ctx, &cli,
278 lp_parm_string(-1, "torture", "host"),
279 "IPC$", NULL, cmdline_credentials,
281 if (!NT_STATUS_IS_OK(status)) {
282 d_printf("smbcli_full_connection failed: %s\n",
289 ret &= bindtest(cli, cmdline_credentials, DCERPC_AUTH_TYPE_NTLMSSP,
290 DCERPC_AUTH_LEVEL_INTEGRITY);
291 ret &= bindtest(cli, cmdline_credentials, DCERPC_AUTH_TYPE_NTLMSSP,
292 DCERPC_AUTH_LEVEL_PRIVACY);
293 ret &= bindtest(cli, cmdline_credentials, DCERPC_AUTH_TYPE_SPNEGO,
294 DCERPC_AUTH_LEVEL_INTEGRITY);
295 ret &= bindtest(cli, cmdline_credentials, DCERPC_AUTH_TYPE_SPNEGO,
296 DCERPC_AUTH_LEVEL_PRIVACY);
299 talloc_free(mem_ctx);
304 * Lookup or create a user and return all necessary info
307 static NTSTATUS get_usr_handle(struct smbcli_state *cli,
309 struct cli_credentials *admin_creds,
310 const char *wks_name,
312 struct dcerpc_pipe **result_pipe,
313 struct policy_handle **result_handle)
315 struct dcerpc_pipe *samr_pipe;
317 struct policy_handle conn_handle;
318 struct policy_handle domain_handle;
319 struct policy_handle *user_handle;
320 struct samr_Connect2 conn;
321 struct samr_EnumDomains enumdom;
322 uint32_t resume_handle = 0;
323 struct samr_LookupDomain l;
325 struct lsa_String domain_name;
326 struct lsa_String user_name;
327 struct samr_OpenDomain o;
328 struct samr_CreateUser2 c;
329 uint32_t user_rid,access_granted;
331 samr_pipe = dcerpc_pipe_init(mem_ctx,
332 cli->transport->socket->event.ctx);
333 if (samr_pipe == NULL) {
334 d_printf("dcerpc_pipe_init failed\n");
335 status = NT_STATUS_NO_MEMORY;
339 status = dcerpc_pipe_open_smb(samr_pipe->conn, cli->tree, "\\samr");
340 if (!NT_STATUS_IS_OK(status)) {
341 d_printf("dcerpc_pipe_open_smb failed: %s\n",
346 status = dcerpc_bind_auth(samr_pipe, &dcerpc_table_samr,
347 admin_creds, DCERPC_AUTH_TYPE_NTLMSSP,
348 DCERPC_AUTH_LEVEL_INTEGRITY, NULL);
349 if (!NT_STATUS_IS_OK(status)) {
350 d_printf("dcerpc_bind_auth failed: %s\n", nt_errstr(status));
354 conn.in.system_name = talloc_asprintf(
355 mem_ctx, "\\\\%s", dcerpc_server_name(samr_pipe));
356 conn.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
357 conn.out.connect_handle = &conn_handle;
359 status = dcerpc_samr_Connect2(samr_pipe, mem_ctx, &conn);
360 if (!NT_STATUS_IS_OK(status)) {
361 d_printf("samr_Connect2 failed: %s\n", nt_errstr(status));
365 enumdom.in.connect_handle = &conn_handle;
366 enumdom.in.resume_handle = &resume_handle;
367 enumdom.in.buf_size = (uint32_t)-1;
368 enumdom.out.resume_handle = &resume_handle;
370 status = dcerpc_samr_EnumDomains(samr_pipe, mem_ctx, &enumdom);
371 if (!NT_STATUS_IS_OK(status)) {
372 d_printf("samr_EnumDomains failed: %s\n", nt_errstr(status));
376 if (enumdom.out.num_entries != 2) {
377 d_printf("samr_EnumDomains returned %d entries, expected 2\n",
378 enumdom.out.num_entries);
379 status = NT_STATUS_UNSUCCESSFUL;
383 dom_idx = strequal(enumdom.out.sam->entries[0].name.string,
386 l.in.connect_handle = &conn_handle;
387 domain_name.string = enumdom.out.sam->entries[0].name.string;
388 *domain = talloc_strdup(mem_ctx, domain_name.string);
389 l.in.domain_name = &domain_name;
391 status = dcerpc_samr_LookupDomain(samr_pipe, mem_ctx, &l);
392 if (!NT_STATUS_IS_OK(status)) {
393 d_printf("samr_LookupDomain failed: %s\n", nt_errstr(status));
397 o.in.connect_handle = &conn_handle;
398 o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
399 o.in.sid = l.out.sid;
400 o.out.domain_handle = &domain_handle;
402 status = dcerpc_samr_OpenDomain(samr_pipe, mem_ctx, &o);
403 if (!NT_STATUS_IS_OK(status)) {
404 d_printf("samr_OpenDomain failed: %s\n", nt_errstr(status));
408 c.in.domain_handle = &domain_handle;
409 user_name.string = talloc_asprintf(mem_ctx, "%s$", wks_name);
410 c.in.account_name = &user_name;
411 c.in.acct_flags = ACB_WSTRUST;
412 c.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
413 user_handle = talloc(mem_ctx, struct policy_handle);
414 c.out.user_handle = user_handle;
415 c.out.access_granted = &access_granted;
416 c.out.rid = &user_rid;
418 status = dcerpc_samr_CreateUser2(samr_pipe, mem_ctx, &c);
420 if (NT_STATUS_EQUAL(status, NT_STATUS_USER_EXISTS)) {
421 struct samr_LookupNames ln;
422 struct samr_OpenUser ou;
424 ln.in.domain_handle = &domain_handle;
426 ln.in.names = &user_name;
428 status = dcerpc_samr_LookupNames(samr_pipe, mem_ctx, &ln);
429 if (!NT_STATUS_IS_OK(status)) {
430 d_printf("samr_LookupNames failed: %s\n",
435 ou.in.domain_handle = &domain_handle;
436 ou.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
437 ou.in.rid = ln.out.rids.ids[0];
438 ou.out.user_handle = user_handle;
440 status = dcerpc_samr_OpenUser(samr_pipe, mem_ctx, &ou);
441 if (!NT_STATUS_IS_OK(status)) {
442 d_printf("samr_OpenUser failed: %s\n",
448 if (!NT_STATUS_IS_OK(status)) {
449 d_printf("samr_CreateUser failed: %s\n", nt_errstr(status));
453 *result_pipe = samr_pipe;
454 *result_handle = user_handle;
462 * Do a Samba3-style join
465 static BOOL join3(struct smbcli_state *cli,
466 struct cli_credentials *admin_creds,
467 struct cli_credentials *wks_creds)
472 struct dcerpc_pipe *samr_pipe;
473 struct policy_handle *wks_handle;
476 if ((mem_ctx = talloc_init("join3")) == NULL) {
477 d_printf("talloc_init failed\n");
481 status = get_usr_handle(cli, mem_ctx, admin_creds,
482 cli_credentials_get_workstation(wks_creds),
483 &dom_name, &samr_pipe, &wks_handle);
485 if (!NT_STATUS_IS_OK(status)) {
486 d_printf("get_wks_handle failed: %s\n", nt_errstr(status));
490 cli_credentials_set_domain(wks_creds, dom_name, CRED_SPECIFIED);
493 struct samr_SetUserInfo2 sui2;
494 struct samr_SetUserInfo sui;
495 union samr_UserInfo u_info;
496 DATA_BLOB session_key;
498 encode_pw_buffer(u_info.info24.password.data,
499 cli_credentials_get_password(wks_creds),
501 u_info.info24.pw_len =
502 strlen_m(cli_credentials_get_password(wks_creds))*2;
504 status = dcerpc_fetch_session_key(samr_pipe, &session_key);
505 if (!NT_STATUS_IS_OK(status)) {
506 d_printf("dcerpc_fetch_session_key failed\n");
509 arcfour_crypt_blob(u_info.info24.password.data, 516,
511 sui2.in.user_handle = wks_handle;
512 sui2.in.info = &u_info;
515 status = dcerpc_samr_SetUserInfo2(samr_pipe, mem_ctx, &sui2);
516 if (!NT_STATUS_IS_OK(status)) {
517 d_printf("samr_SetUserInfo(24) failed\n");
521 u_info.info16.acct_flags = ACB_WSTRUST;
522 sui.in.user_handle = wks_handle;
523 sui.in.info = &u_info;
526 status = dcerpc_samr_SetUserInfo(samr_pipe, mem_ctx, &sui);
527 if (!NT_STATUS_IS_OK(status)) {
528 d_printf("samr_SetUserInfo(16) failed\n");
536 talloc_free(mem_ctx);
541 * Do a ReqChallenge/Auth2 and get the wks creds
544 static BOOL auth2(struct smbcli_state *cli,
545 struct cli_credentials *wks_cred)
548 struct dcerpc_pipe *net_pipe;
551 struct netr_ServerReqChallenge r;
552 struct netr_Credential netr_cli_creds;
553 struct netr_Credential netr_srv_creds;
554 uint32_t negotiate_flags;
555 struct netr_ServerAuthenticate2 a;
556 struct creds_CredentialState *creds_state;
557 struct netr_Credential netr_cred;
558 struct samr_Password mach_pw;
560 mem_ctx = talloc_new(NULL);
561 if (mem_ctx == NULL) {
562 d_printf("talloc_new failed\n");
566 net_pipe = dcerpc_pipe_init(mem_ctx,
567 cli->transport->socket->event.ctx);
568 if (net_pipe == NULL) {
569 d_printf("dcerpc_pipe_init failed\n");
573 status = dcerpc_pipe_open_smb(net_pipe->conn, cli->tree, "\\netlogon");
574 if (!NT_STATUS_IS_OK(status)) {
575 d_printf("dcerpc_pipe_open_smb failed: %s\n",
580 d_printf("Got the netlogon pipe\n");
582 status = dcerpc_bind_auth_none(net_pipe, &dcerpc_table_netlogon);
583 if (!NT_STATUS_IS_OK(status)) {
584 d_printf("dcerpc_bind_auth_none failed: %s\n",
589 r.in.computer_name = cli_credentials_get_workstation(wks_cred);
590 r.in.server_name = talloc_asprintf(
591 mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
592 if (r.in.server_name == NULL) {
593 d_printf("talloc_asprintf failed\n");
596 generate_random_buffer(netr_cli_creds.data,
597 sizeof(netr_cli_creds.data));
598 r.in.credentials = &netr_cli_creds;
599 r.out.credentials = &netr_srv_creds;
601 status = dcerpc_netr_ServerReqChallenge(net_pipe, mem_ctx, &r);
602 if (!NT_STATUS_IS_OK(status)) {
603 d_printf("netr_ServerReqChallenge failed: %s\n",
608 negotiate_flags = NETLOGON_NEG_AUTH2_FLAGS;
609 E_md4hash(cli_credentials_get_password(wks_cred), mach_pw.hash);
611 creds_state = talloc(mem_ctx, struct creds_CredentialState);
612 creds_client_init(creds_state, r.in.credentials,
613 r.out.credentials, &mach_pw,
614 &netr_cred, negotiate_flags);
616 a.in.server_name = talloc_asprintf(
617 mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
618 a.in.account_name = talloc_asprintf(
619 mem_ctx, "%s$", cli_credentials_get_workstation(wks_cred));
620 a.in.computer_name = cli_credentials_get_workstation(wks_cred);
621 a.in.secure_channel_type = SEC_CHAN_WKSTA;
622 a.in.negotiate_flags = &negotiate_flags;
623 a.out.negotiate_flags = &negotiate_flags;
624 a.in.credentials = &netr_cred;
625 a.out.credentials = &netr_cred;
627 status = dcerpc_netr_ServerAuthenticate2(net_pipe, mem_ctx, &a);
628 if (!NT_STATUS_IS_OK(status)) {
629 d_printf("netr_ServerServerAuthenticate2 failed: %s\n",
634 if (!creds_client_check(creds_state, a.out.credentials)) {
635 d_printf("creds_client_check failed\n");
639 cli_credentials_set_netlogon_creds(wks_cred, creds_state);
644 talloc_free(mem_ctx);
649 * Do a couple of channel protected Netlogon ops: Interactive and Network
650 * login, and change the wks password
653 static BOOL schan(struct smbcli_state *cli,
654 struct cli_credentials *wks_creds,
655 struct cli_credentials *user_creds)
660 struct dcerpc_pipe *net_pipe;
663 mem_ctx = talloc_new(NULL);
664 if (mem_ctx == NULL) {
665 d_printf("talloc_new failed\n");
669 net_pipe = dcerpc_pipe_init(mem_ctx,
670 cli->transport->socket->event.ctx);
671 if (net_pipe == NULL) {
672 d_printf("dcerpc_pipe_init failed\n");
676 status = dcerpc_pipe_open_smb(net_pipe->conn, cli->tree, "\\netlogon");
677 if (!NT_STATUS_IS_OK(status)) {
678 d_printf("dcerpc_pipe_open_smb failed: %s\n",
684 net_pipe->conn->flags |= DCERPC_DEBUG_PRINT_IN |
685 DCERPC_DEBUG_PRINT_OUT;
688 net_pipe->conn->flags |= (DCERPC_SIGN | DCERPC_SEAL);
689 status = dcerpc_bind_auth(net_pipe, &dcerpc_table_netlogon,
690 wks_creds, DCERPC_AUTH_TYPE_SCHANNEL,
691 DCERPC_AUTH_LEVEL_PRIVACY,
694 status = dcerpc_bind_auth_none(net_pipe, &dcerpc_table_netlogon);
696 if (!NT_STATUS_IS_OK(status)) {
697 d_printf("schannel bind failed: %s\n", nt_errstr(status));
702 for (i=2; i<4; i++) {
704 DATA_BLOB chal, nt_resp, lm_resp, names_blob, session_key;
705 struct creds_CredentialState *creds_state;
706 struct netr_Authenticator netr_auth, netr_auth2;
707 struct netr_NetworkInfo ninfo;
708 struct netr_PasswordInfo pinfo;
709 struct netr_LogonSamLogon r;
711 flags = CLI_CRED_LANMAN_AUTH | CLI_CRED_NTLM_AUTH |
712 CLI_CRED_NTLMv2_AUTH;
714 chal = data_blob_talloc(mem_ctx, NULL, 8);
715 if (chal.data == NULL) {
716 d_printf("data_blob_talloc failed\n");
720 generate_random_buffer(chal.data, chal.length);
721 names_blob = NTLMv2_generate_names_blob(
722 mem_ctx, cli_credentials_get_workstation(user_creds),
723 cli_credentials_get_domain(user_creds));
724 status = cli_credentials_get_ntlm_response(
725 user_creds, mem_ctx, &flags, chal, names_blob,
726 &lm_resp, &nt_resp, NULL, NULL);
727 if (!NT_STATUS_IS_OK(status)) {
728 d_printf("cli_credentials_get_ntlm_response failed:"
729 " %s\n", nt_errstr(status));
733 creds_state = cli_credentials_get_netlogon_creds(wks_creds);
734 creds_client_authenticator(creds_state, &netr_auth);
736 ninfo.identity_info.account_name.string =
737 cli_credentials_get_username(user_creds);
738 ninfo.identity_info.domain_name.string =
739 cli_credentials_get_domain(user_creds);
740 ninfo.identity_info.parameter_control = 0;
741 ninfo.identity_info.logon_id_low = 0;
742 ninfo.identity_info.logon_id_high = 0;
743 ninfo.identity_info.workstation.string =
744 cli_credentials_get_workstation(user_creds);
745 memcpy(ninfo.challenge, chal.data, sizeof(ninfo.challenge));
746 ninfo.nt.length = nt_resp.length;
747 ninfo.nt.data = nt_resp.data;
748 ninfo.lm.length = lm_resp.length;
749 ninfo.lm.data = lm_resp.data;
751 r.in.server_name = talloc_asprintf(
752 mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
753 ZERO_STRUCT(netr_auth2);
755 cli_credentials_get_workstation(wks_creds);
756 r.in.credential = &netr_auth;
757 r.in.return_authenticator = &netr_auth2;
758 r.in.logon_level = 2;
759 r.in.validation_level = i;
760 r.in.logon.network = &ninfo;
761 r.out.return_authenticator = NULL;
763 status = dcerpc_netr_LogonSamLogon(net_pipe, mem_ctx, &r);
764 if (!NT_STATUS_IS_OK(status)) {
765 d_printf("netr_LogonSamLogon failed: %s\n",
770 if ((r.out.return_authenticator == NULL) ||
771 (!creds_client_check(creds_state,
772 &r.out.return_authenticator->cred))) {
773 d_printf("Credentials check failed!\n");
777 creds_client_authenticator(creds_state, &netr_auth);
779 pinfo.identity_info = ninfo.identity_info;
780 ZERO_STRUCT(pinfo.lmpassword.hash);
781 E_md4hash(cli_credentials_get_password(user_creds),
782 pinfo.ntpassword.hash);
783 session_key = data_blob_talloc(mem_ctx,
784 creds_state->session_key, 16);
785 arcfour_crypt_blob(pinfo.ntpassword.hash,
786 sizeof(pinfo.ntpassword.hash),
789 r.in.logon_level = 1;
790 r.in.logon.password = &pinfo;
791 r.out.return_authenticator = NULL;
793 status = dcerpc_netr_LogonSamLogon(net_pipe, mem_ctx, &r);
794 if (!NT_STATUS_IS_OK(status)) {
795 d_printf("netr_LogonSamLogon failed: %s\n",
800 if ((r.out.return_authenticator == NULL) ||
801 (!creds_client_check(creds_state,
802 &r.out.return_authenticator->cred))) {
803 d_printf("Credentials check failed!\n");
809 struct netr_ServerPasswordSet s;
810 char *password = generate_random_str(wks_creds, 8);
811 struct creds_CredentialState *creds_state;
813 s.in.server_name = talloc_asprintf(
814 mem_ctx, "\\\\%s", dcerpc_server_name(net_pipe));
815 s.in.computer_name = cli_credentials_get_workstation(wks_creds);
816 s.in.account_name = talloc_asprintf(
817 mem_ctx, "%s$", s.in.computer_name);
818 s.in.secure_channel_type = SEC_CHAN_WKSTA;
819 E_md4hash(password, s.in.new_password.hash);
820 creds_des_encrypt(creds_state, &s.in.new_password);
822 creds_state = cli_credentials_get_netlogon_creds(wks_creds);
823 creds_client_authenticator(creds_state, &s.in.credential);
825 status = dcerpc_netr_ServerPasswordSet(net_pipe, mem_ctx, &s);
826 if (!NT_STATUS_IS_OK(status)) {
827 printf("ServerPasswordSet - %s\n", nt_errstr(status));
831 if (!creds_client_check(creds_state,
832 &s.out.return_authenticator.cred)) {
833 printf("Credential chaining failed\n");
836 cli_credentials_set_password(wks_creds, password,
842 talloc_free(mem_ctx);
847 * Delete the wks account again
850 static BOOL leave(struct smbcli_state *cli,
851 struct cli_credentials *admin_creds,
852 struct cli_credentials *wks_creds)
857 struct dcerpc_pipe *samr_pipe;
858 struct policy_handle *wks_handle;
861 if ((mem_ctx = talloc_init("join3")) == NULL) {
862 d_printf("talloc_init failed\n");
866 status = get_usr_handle(cli, mem_ctx, admin_creds,
867 cli_credentials_get_workstation(wks_creds),
868 &dom_name, &samr_pipe, &wks_handle);
870 if (!NT_STATUS_IS_OK(status)) {
871 d_printf("get_wks_handle failed: %s\n", nt_errstr(status));
876 struct samr_DeleteUser d;
878 d.in.user_handle = wks_handle;
879 d.out.user_handle = wks_handle;
881 status = dcerpc_samr_DeleteUser(samr_pipe, mem_ctx, &d);
882 if (!NT_STATUS_IS_OK(status)) {
883 d_printf("samr_DeleteUser failed\n");
891 talloc_free(mem_ctx);
896 * Test the Samba3 DC code a bit. Join, do some schan netlogon ops, leave
899 BOOL torture_netlogon_samba3(struct torture_context *torture)
904 struct smbcli_state *cli;
905 struct cli_credentials *anon_creds;
906 struct cli_credentials *wks_creds;
907 const char *wks_name;
910 wks_name = lp_parm_string(-1, "torture", "wksname");
911 if (wks_name == NULL) {
912 wks_name = get_myname();
915 mem_ctx = talloc_init("torture_bind_authcontext");
917 if (mem_ctx == NULL) {
918 d_printf("talloc_init failed\n");
922 anon_creds = cli_credentials_init(mem_ctx);
923 if (anon_creds == NULL) {
924 d_printf("cli_credentials_init failed\n");
928 cli_credentials_set_conf(anon_creds);
929 cli_credentials_set_anonymous(anon_creds);
931 status = smbcli_full_connection(mem_ctx, &cli,
932 lp_parm_string(-1, "torture", "host"),
933 "IPC$", NULL, anon_creds, NULL);
934 if (!NT_STATUS_IS_OK(status)) {
935 d_printf("smbcli_full_connection failed: %s\n",
940 wks_creds = cli_credentials_init(mem_ctx);
941 if (wks_creds == NULL) {
942 d_printf("cli_credentials_init failed\n");
946 cli_credentials_set_conf(wks_creds);
947 cli_credentials_set_secure_channel_type(wks_creds, SEC_CHAN_WKSTA);
948 cli_credentials_set_username(wks_creds, wks_name, CRED_SPECIFIED);
949 cli_credentials_set_workstation(wks_creds, wks_name, CRED_SPECIFIED);
950 cli_credentials_set_password(wks_creds, "blub", CRED_SPECIFIED);
952 if (!join3(cli, cmdline_credentials, wks_creds)) {
953 d_printf("join failed\n");
957 cli_credentials_set_domain(
958 cmdline_credentials, cli_credentials_get_domain(wks_creds),
961 for (i=0; i<2; i++) {
963 /* Do this more than once, the routine "schan" changes
964 * the workstation password using the netlogon
965 * password change routine */
969 if (!auth2(cli, wks_creds)) {
970 d_printf("auth2 failed\n");
974 for (j=0; j<2; j++) {
975 if (!schan(cli, wks_creds, cmdline_credentials)) {
976 d_printf("schan failed\n");
982 if (!leave(cli, cmdline_credentials, wks_creds)) {
983 d_printf("leave failed\n");
990 talloc_free(mem_ctx);