2 Unix SMB/CIFS implementation.
4 test suite for schannel operations
6 Copyright (C) Andrew Tridgell 2004
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 "librpc/gen_ndr/ndr_netlogon_c.h"
24 #include "librpc/gen_ndr/ndr_lsa_c.h"
25 #include "librpc/gen_ndr/ndr_samr_c.h"
26 #include "auth/credentials/credentials.h"
27 #include "torture/rpc/rpc.h"
28 #include "lib/cmdline/popt_common.h"
29 #include "auth/gensec/schannel_proto.h"
30 #include "libcli/auth/libcli_auth.h"
31 #include "libcli/security/security.h"
32 #include "system/filesys.h"
33 #include "param/param.h"
34 #include "librpc/rpc/dcerpc_proto.h"
35 #include "auth/gensec/gensec.h"
36 #include "libcli/composite/composite.h"
37 #include "lib/events/events.h"
39 #define TEST_MACHINE_NAME "schannel"
42 try a netlogon SamLogon
44 bool test_netlogon_ex_ops(struct dcerpc_pipe *p, struct torture_context *tctx,
45 struct cli_credentials *credentials,
46 struct creds_CredentialState *creds)
49 struct netr_LogonSamLogonEx r;
50 struct netr_NetworkInfo ninfo;
51 DATA_BLOB names_blob, chal, lm_resp, nt_resp;
53 int flags = CLI_CRED_NTLM_AUTH;
54 if (lp_client_lanman_auth(tctx->lp_ctx)) {
55 flags |= CLI_CRED_LANMAN_AUTH;
58 if (lp_client_ntlmv2_auth(tctx->lp_ctx)) {
59 flags |= CLI_CRED_NTLMv2_AUTH;
62 cli_credentials_get_ntlm_username_domain(cmdline_credentials, tctx,
63 &ninfo.identity_info.account_name.string,
64 &ninfo.identity_info.domain_name.string);
66 generate_random_buffer(ninfo.challenge,
67 sizeof(ninfo.challenge));
68 chal = data_blob_const(ninfo.challenge,
69 sizeof(ninfo.challenge));
71 names_blob = NTLMv2_generate_names_blob(tctx, cli_credentials_get_workstation(credentials),
72 cli_credentials_get_domain(credentials));
74 status = cli_credentials_get_ntlm_response(cmdline_credentials, tctx,
80 torture_assert_ntstatus_ok(tctx, status,
81 "cli_credentials_get_ntlm_response failed");
83 ninfo.lm.data = lm_resp.data;
84 ninfo.lm.length = lm_resp.length;
86 ninfo.nt.data = nt_resp.data;
87 ninfo.nt.length = nt_resp.length;
89 ninfo.identity_info.parameter_control = 0;
90 ninfo.identity_info.logon_id_low = 0;
91 ninfo.identity_info.logon_id_high = 0;
92 ninfo.identity_info.workstation.string = cli_credentials_get_workstation(credentials);
94 r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
95 r.in.computer_name = cli_credentials_get_workstation(credentials);
97 r.in.logon.network = &ninfo;
100 torture_comment(tctx,
101 "Testing LogonSamLogonEx with name %s\n",
102 ninfo.identity_info.account_name.string);
105 r.in.validation_level = i;
107 status = dcerpc_netr_LogonSamLogonEx(p, tctx, &r);
108 torture_assert_ntstatus_ok(tctx, status, "LogonSamLogon failed");
115 do some samr ops using the schannel connection
117 static bool test_samr_ops(struct torture_context *tctx,
118 struct dcerpc_pipe *p)
121 struct samr_GetDomPwInfo r;
122 struct samr_Connect connect;
123 struct samr_OpenDomain opendom;
125 struct lsa_String name;
126 struct policy_handle handle;
127 struct policy_handle domain_handle;
129 name.string = lp_workgroup(tctx->lp_ctx);
130 r.in.domain_name = &name;
132 connect.in.system_name = 0;
133 connect.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
134 connect.out.connect_handle = &handle;
136 printf("Testing Connect and OpenDomain on BUILTIN\n");
138 status = dcerpc_samr_Connect(p, tctx, &connect);
139 if (!NT_STATUS_IS_OK(status)) {
140 if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
141 printf("Connect failed (expected, schannel mapped to anonymous): %s\n",
144 printf("Connect failed - %s\n", nt_errstr(status));
148 opendom.in.connect_handle = &handle;
149 opendom.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
150 opendom.in.sid = dom_sid_parse_talloc(tctx, "S-1-5-32");
151 opendom.out.domain_handle = &domain_handle;
153 status = dcerpc_samr_OpenDomain(p, tctx, &opendom);
154 if (!NT_STATUS_IS_OK(status)) {
155 printf("OpenDomain failed - %s\n", nt_errstr(status));
160 printf("Testing GetDomPwInfo with name %s\n", r.in.domain_name->string);
162 /* do several ops to test credential chaining */
164 status = dcerpc_samr_GetDomPwInfo(p, tctx, &r);
165 if (!NT_STATUS_IS_OK(status)) {
166 if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
167 printf("GetDomPwInfo op %d failed - %s\n", i, nt_errstr(status));
178 do some lsa ops using the schannel connection
180 static bool test_lsa_ops(struct torture_context *tctx, struct dcerpc_pipe *p)
182 struct lsa_GetUserName r;
185 struct lsa_String *account_name_p = NULL;
186 struct lsa_String *authority_name_p = NULL;
188 printf("\nTesting GetUserName\n");
190 r.in.system_name = "\\";
191 r.in.account_name = &account_name_p;
192 r.in.authority_name = &authority_name_p;
193 r.out.account_name = &account_name_p;
195 /* do several ops to test credential chaining and various operations */
196 status = dcerpc_lsa_GetUserName(p, tctx, &r);
198 authority_name_p = *r.out.authority_name;
200 if (NT_STATUS_EQUAL(status, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED)) {
201 printf("not considering %s to be an error\n", nt_errstr(status));
202 } else if (!NT_STATUS_IS_OK(status)) {
203 printf("GetUserName failed - %s\n", nt_errstr(status));
206 if (!r.out.account_name) {
210 if (strcmp(account_name_p->string, "ANONYMOUS LOGON") != 0) {
211 printf("GetUserName returned wrong user: %s, expected %s\n",
212 account_name_p->string, "ANONYMOUS LOGON");
215 if (!authority_name_p || !authority_name_p->string) {
219 if (strcmp(authority_name_p->string, "NT AUTHORITY") != 0) {
220 printf("GetUserName returned wrong user: %s, expected %s\n",
221 authority_name_p->string, "NT AUTHORITY");
225 if (!test_many_LookupSids(p, tctx, NULL)) {
226 printf("LsaLookupSids3 failed!\n");
235 test a schannel connection with the given flags
237 static bool test_schannel(struct torture_context *tctx,
238 uint16_t acct_flags, uint32_t dcerpc_flags,
241 struct test_join *join_ctx;
243 const char *binding = torture_setting_string(tctx, "binding", NULL);
244 struct dcerpc_binding *b;
245 struct dcerpc_pipe *p = NULL;
246 struct dcerpc_pipe *p_netlogon = NULL;
247 struct dcerpc_pipe *p_netlogon2 = NULL;
248 struct dcerpc_pipe *p_netlogon3 = NULL;
249 struct dcerpc_pipe *p_samr2 = NULL;
250 struct dcerpc_pipe *p_lsa = NULL;
251 struct creds_CredentialState *creds;
252 struct cli_credentials *credentials;
254 join_ctx = torture_join_domain(tctx,
255 talloc_asprintf(tctx, "%s%d", TEST_MACHINE_NAME, i),
256 acct_flags, &credentials);
257 torture_assert(tctx, join_ctx != NULL, "Failed to join domain");
259 status = dcerpc_parse_binding(tctx, binding, &b);
260 torture_assert_ntstatus_ok(tctx, status, "Bad binding string");
262 b->flags &= ~DCERPC_AUTH_OPTIONS;
263 b->flags |= dcerpc_flags;
265 status = dcerpc_pipe_connect_b(tctx, &p, b, &ndr_table_samr,
266 credentials, tctx->ev, tctx->lp_ctx);
267 torture_assert_ntstatus_ok(tctx, status,
268 "Failed to connect with schannel");
270 torture_assert(tctx, test_samr_ops(tctx, p),
271 "Failed to process schannel secured SAMR ops");
273 /* Also test that when we connect to the netlogon pipe, that
274 * the credentials we setup on the first pipe are valid for
277 /* Swap the binding details from SAMR to NETLOGON */
278 status = dcerpc_epm_map_binding(tctx, b, &ndr_table_netlogon, tctx->ev, tctx->lp_ctx);
279 torture_assert_ntstatus_ok(tctx, status, "epm map");
281 status = dcerpc_secondary_connection(p, &p_netlogon,
283 torture_assert_ntstatus_ok(tctx, status, "seconday connection");
285 status = dcerpc_bind_auth(p_netlogon, &ndr_table_netlogon,
286 credentials, tctx->lp_ctx,
287 DCERPC_AUTH_TYPE_SCHANNEL,
288 dcerpc_auth_level(p->conn),
291 torture_assert_ntstatus_ok(tctx, status, "bind auth");
293 status = dcerpc_schannel_creds(p_netlogon->conn->security_state.generic_state, tctx, &creds);
294 torture_assert_ntstatus_ok(tctx, status, "schannel creds");
296 /* do a couple of logins */
297 torture_assert(tctx, test_netlogon_ops(p_netlogon, tctx, credentials, creds),
298 "Failed to process schannel secured NETLOGON ops");
300 torture_assert(tctx, test_netlogon_ex_ops(p_netlogon, tctx, credentials, creds),
301 "Failed to process schannel secured NETLOGON EX ops");
303 /* Swap the binding details from SAMR to LSARPC */
304 status = dcerpc_epm_map_binding(tctx, b, &ndr_table_lsarpc, tctx->ev, tctx->lp_ctx);
305 torture_assert_ntstatus_ok(tctx, status, "epm map");
307 status = dcerpc_secondary_connection(p, &p_lsa,
310 torture_assert_ntstatus_ok(tctx, status, "seconday connection");
312 status = dcerpc_bind_auth(p_lsa, &ndr_table_lsarpc,
313 credentials, tctx->lp_ctx,
314 DCERPC_AUTH_TYPE_SCHANNEL,
315 dcerpc_auth_level(p->conn),
318 torture_assert_ntstatus_ok(tctx, status, "bind auth");
320 torture_assert(tctx, test_lsa_ops(tctx, p_lsa),
321 "Failed to process schannel secured LSA ops");
323 /* Drop the socket, we want to start from scratch */
327 /* Now see what we are still allowed to do */
329 status = dcerpc_parse_binding(tctx, binding, &b);
330 torture_assert_ntstatus_ok(tctx, status, "Bad binding string");
332 b->flags &= ~DCERPC_AUTH_OPTIONS;
333 b->flags |= dcerpc_flags;
335 status = dcerpc_pipe_connect_b(tctx, &p_samr2, b, &ndr_table_samr,
336 credentials, tctx->ev, tctx->lp_ctx);
337 torture_assert_ntstatus_ok(tctx, status,
338 "Failed to connect with schannel");
340 /* do a some SAMR operations. We have *not* done a new serverauthenticate */
341 torture_assert (tctx, test_samr_ops(tctx, p_samr2),
342 "Failed to process schannel secured SAMR ops (on fresh connection)");
344 /* Swap the binding details from SAMR to NETLOGON */
345 status = dcerpc_epm_map_binding(tctx, b, &ndr_table_netlogon, tctx->ev, tctx->lp_ctx);
346 torture_assert_ntstatus_ok(tctx, status, "epm");
348 status = dcerpc_secondary_connection(p_samr2, &p_netlogon2,
350 torture_assert_ntstatus_ok(tctx, status, "seconday connection");
352 /* and now setup an SCHANNEL bind on netlogon */
353 status = dcerpc_bind_auth(p_netlogon2, &ndr_table_netlogon,
354 credentials, tctx->lp_ctx,
355 DCERPC_AUTH_TYPE_SCHANNEL,
356 dcerpc_auth_level(p_samr2->conn),
359 torture_assert_ntstatus_ok(tctx, status, "auth failed");
361 /* Try the schannel-only SamLogonEx operation */
362 torture_assert(tctx, test_netlogon_ex_ops(p_netlogon2, tctx, credentials, creds),
363 "Failed to process schannel secured NETLOGON EX ops (on fresh connection)");
366 /* And the more traditional style, proving that the
367 * credentials chaining state is fully present */
368 torture_assert(tctx, test_netlogon_ops(p_netlogon2, tctx, credentials, creds),
369 "Failed to process schannel secured NETLOGON ops (on fresh connection)");
371 /* Drop the socket, we want to start from scratch (again) */
372 talloc_free(p_samr2);
374 /* We don't want schannel for this test */
375 b->flags &= ~DCERPC_AUTH_OPTIONS;
377 status = dcerpc_pipe_connect_b(tctx, &p_netlogon3, b, &ndr_table_netlogon,
378 credentials, tctx->ev, tctx->lp_ctx);
379 torture_assert_ntstatus_ok(tctx, status, "Failed to connect without schannel");
381 torture_assert(tctx, !test_netlogon_ex_ops(p_netlogon3, tctx, credentials, creds),
382 "Processed NOT schannel secured NETLOGON EX ops without SCHANNEL (unsafe)");
384 /* Required because the previous call will mark the current context as having failed */
385 tctx->last_result = TORTURE_OK;
386 tctx->last_reason = NULL;
388 torture_assert(tctx, test_netlogon_ops(p_netlogon3, tctx, credentials, creds),
389 "Failed to processed NOT schannel secured NETLOGON ops without new ServerAuth");
391 torture_leave_domain(tctx, join_ctx);
398 a schannel test suite
400 bool torture_rpc_schannel(struct torture_context *torture)
405 uint32_t dcerpc_flags;
407 { ACB_WSTRUST, DCERPC_SCHANNEL | DCERPC_SIGN},
408 { ACB_WSTRUST, DCERPC_SCHANNEL | DCERPC_SEAL},
409 { ACB_WSTRUST, DCERPC_SCHANNEL | DCERPC_SIGN | DCERPC_SCHANNEL_128},
410 { ACB_WSTRUST, DCERPC_SCHANNEL | DCERPC_SEAL | DCERPC_SCHANNEL_128 },
411 { ACB_SVRTRUST, DCERPC_SCHANNEL | DCERPC_SIGN },
412 { ACB_SVRTRUST, DCERPC_SCHANNEL | DCERPC_SEAL },
413 { ACB_SVRTRUST, DCERPC_SCHANNEL | DCERPC_SIGN | DCERPC_SCHANNEL_128 },
414 { ACB_SVRTRUST, DCERPC_SCHANNEL | DCERPC_SEAL | DCERPC_SCHANNEL_128 }
418 for (i=0;i<ARRAY_SIZE(tests);i++) {
419 if (!test_schannel(torture,
420 tests[i].acct_flags, tests[i].dcerpc_flags,
422 torture_comment(torture, "Failed with acct_flags=0x%x dcerpc_flags=0x%x \n",
423 tests[i].acct_flags, tests[i].dcerpc_flags);
432 test two schannel connections
434 bool torture_rpc_schannel2(struct torture_context *torture)
436 struct test_join *join_ctx;
438 const char *binding = torture_setting_string(torture, "binding", NULL);
439 struct dcerpc_binding *b;
440 struct dcerpc_pipe *p1 = NULL, *p2 = NULL;
441 struct cli_credentials *credentials1, *credentials2;
442 uint32_t dcerpc_flags = DCERPC_SCHANNEL | DCERPC_SIGN;
444 join_ctx = torture_join_domain(torture, talloc_asprintf(torture, "%s2", TEST_MACHINE_NAME),
445 ACB_WSTRUST, &credentials1);
446 torture_assert(torture, join_ctx != NULL,
447 "Failed to join domain with acct_flags=ACB_WSTRUST");
449 credentials2 = (struct cli_credentials *)talloc_memdup(torture, credentials1, sizeof(*credentials1));
450 credentials1->netlogon_creds = NULL;
451 credentials2->netlogon_creds = NULL;
453 status = dcerpc_parse_binding(torture, binding, &b);
454 torture_assert_ntstatus_ok(torture, status, "Bad binding string");
456 b->flags &= ~DCERPC_AUTH_OPTIONS;
457 b->flags |= dcerpc_flags;
459 printf("Opening first connection\n");
460 status = dcerpc_pipe_connect_b(torture, &p1, b, &ndr_table_netlogon,
461 credentials1, torture->ev, torture->lp_ctx);
462 torture_assert_ntstatus_ok(torture, status, "Failed to connect with schannel");
464 torture_comment(torture, "Opening second connection\n");
465 status = dcerpc_pipe_connect_b(torture, &p2, b, &ndr_table_netlogon,
466 credentials2, torture->ev, torture->lp_ctx);
467 torture_assert_ntstatus_ok(torture, status, "Failed to connect with schannel");
469 credentials1->netlogon_creds = NULL;
470 credentials2->netlogon_creds = NULL;
472 torture_comment(torture, "Testing logon on pipe1\n");
473 if (!test_netlogon_ex_ops(p1, torture, credentials1, NULL))
476 torture_comment(torture, "Testing logon on pipe2\n");
477 if (!test_netlogon_ex_ops(p2, torture, credentials2, NULL))
480 torture_comment(torture, "Again on pipe1\n");
481 if (!test_netlogon_ex_ops(p1, torture, credentials1, NULL))
484 torture_comment(torture, "Again on pipe2\n");
485 if (!test_netlogon_ex_ops(p2, torture, credentials2, NULL))
488 torture_leave_domain(torture, join_ctx);
492 struct torture_schannel_bench;
494 struct torture_schannel_bench_conn {
495 struct torture_schannel_bench *s;
497 struct cli_credentials *wks_creds;
498 struct dcerpc_pipe *pipe;
499 struct netr_LogonSamLogonEx r;
500 struct netr_NetworkInfo ninfo;
506 struct torture_schannel_bench {
507 struct torture_context *tctx;
512 struct torture_schannel_bench_conn *conns;
513 struct test_join *join_ctx1;
514 struct cli_credentials *wks_creds1;
515 struct test_join *join_ctx2;
516 struct cli_credentials *wks_creds2;
517 struct cli_credentials *user1_creds;
518 struct cli_credentials *user2_creds;
519 struct dcerpc_binding *b;
526 static void torture_schannel_bench_connected(struct composite_context *c)
528 struct torture_schannel_bench_conn *conn =
529 (struct torture_schannel_bench_conn *)c->async.private_data;
530 struct torture_schannel_bench *s = talloc_get_type(conn->s,
531 struct torture_schannel_bench);
533 s->error = dcerpc_pipe_connect_b_recv(c, s->conns, &conn->pipe);
534 torture_comment(s->tctx, "conn[%u]: %s\n", conn->index, nt_errstr(s->error));
535 if (NT_STATUS_IS_OK(s->error)) {
540 static void torture_schannel_bench_recv(struct rpc_request *req);
542 static bool torture_schannel_bench_start(struct torture_schannel_bench_conn *conn)
544 struct torture_schannel_bench *s = conn->s;
546 DATA_BLOB names_blob, chal, lm_resp, nt_resp;
547 int flags = CLI_CRED_NTLM_AUTH;
548 struct rpc_request *req;
549 struct cli_credentials *user_creds;
551 if (conn->total % 2) {
552 user_creds = s->user1_creds;
554 user_creds = s->user2_creds;
557 if (lp_client_lanman_auth(s->tctx->lp_ctx)) {
558 flags |= CLI_CRED_LANMAN_AUTH;
561 if (lp_client_ntlmv2_auth(s->tctx->lp_ctx)) {
562 flags |= CLI_CRED_NTLMv2_AUTH;
565 talloc_free(conn->tmp);
566 conn->tmp = talloc_new(s);
567 ZERO_STRUCT(conn->ninfo);
568 ZERO_STRUCT(conn->r);
570 cli_credentials_get_ntlm_username_domain(user_creds, conn->tmp,
571 &conn->ninfo.identity_info.account_name.string,
572 &conn->ninfo.identity_info.domain_name.string);
574 generate_random_buffer(conn->ninfo.challenge,
575 sizeof(conn->ninfo.challenge));
576 chal = data_blob_const(conn->ninfo.challenge,
577 sizeof(conn->ninfo.challenge));
579 names_blob = NTLMv2_generate_names_blob(conn->tmp,
580 cli_credentials_get_workstation(conn->wks_creds),
581 cli_credentials_get_domain(conn->wks_creds));
583 status = cli_credentials_get_ntlm_response(user_creds, conn->tmp,
589 torture_assert_ntstatus_ok(s->tctx, status,
590 "cli_credentials_get_ntlm_response failed");
592 conn->ninfo.lm.data = lm_resp.data;
593 conn->ninfo.lm.length = lm_resp.length;
595 conn->ninfo.nt.data = nt_resp.data;
596 conn->ninfo.nt.length = nt_resp.length;
598 conn->ninfo.identity_info.parameter_control = 0;
599 conn->ninfo.identity_info.logon_id_low = 0;
600 conn->ninfo.identity_info.logon_id_high = 0;
601 conn->ninfo.identity_info.workstation.string = cli_credentials_get_workstation(conn->wks_creds);
603 conn->r.in.server_name = talloc_asprintf(conn->tmp, "\\\\%s", dcerpc_server_name(conn->pipe));
604 conn->r.in.computer_name = cli_credentials_get_workstation(conn->wks_creds);
605 conn->r.in.logon_level = 2;
606 conn->r.in.logon.network = &conn->ninfo;
607 conn->r.in.flags = 0;
608 conn->r.in.validation_level = 2;
610 req = dcerpc_netr_LogonSamLogonEx_send(conn->pipe, conn->tmp, &conn->r);
611 torture_assert(s->tctx, req, "Failed to setup LogonSamLogonEx request");
613 req->async.callback = torture_schannel_bench_recv;
614 req->async.private_data = conn;
619 static void torture_schannel_bench_recv(struct rpc_request *req)
622 struct torture_schannel_bench_conn *conn =
623 (struct torture_schannel_bench_conn *)req->async.private_data;
624 struct torture_schannel_bench *s = talloc_get_type(conn->s,
625 struct torture_schannel_bench);
627 s->error = dcerpc_ndr_request_recv(req);
628 if (!NT_STATUS_IS_OK(s->error)) {
639 ret = torture_schannel_bench_start(conn);
641 s->error = NT_STATUS_INTERNAL_ERROR;
646 test multiple schannel connection in parallel
648 bool torture_rpc_schannel_bench1(struct torture_context *torture)
652 const char *binding = torture_setting_string(torture, "binding", NULL);
653 struct torture_schannel_bench *s;
654 struct timeval start;
659 s = talloc_zero(torture, struct torture_schannel_bench);
661 s->progress = torture_setting_bool(torture, "progress", true);
662 s->timelimit = torture_setting_int(torture, "timelimit", 10);
663 s->nprocs = torture_setting_int(torture, "nprocs", 4);
664 s->conns = talloc_zero_array(s, struct torture_schannel_bench_conn, s->nprocs);
666 s->user1_creds = (struct cli_credentials *)talloc_memdup(s,
668 sizeof(*s->user1_creds));
669 tmp = torture_setting_string(s->tctx, "extra_user1", NULL);
671 cli_credentials_parse_string(s->user1_creds, tmp, CRED_SPECIFIED);
673 s->user2_creds = (struct cli_credentials *)talloc_memdup(s,
675 sizeof(*s->user1_creds));
676 tmp = torture_setting_string(s->tctx, "extra_user2", NULL);
678 cli_credentials_parse_string(s->user1_creds, tmp, CRED_SPECIFIED);
681 s->join_ctx1 = torture_join_domain(s->tctx, talloc_asprintf(s, "%sb", TEST_MACHINE_NAME),
682 ACB_WSTRUST, &s->wks_creds1);
683 torture_assert(torture, s->join_ctx1 != NULL,
684 "Failed to join domain with acct_flags=ACB_WSTRUST");
685 s->join_ctx2 = torture_join_domain(s->tctx, talloc_asprintf(s, "%sc", TEST_MACHINE_NAME),
686 ACB_WSTRUST, &s->wks_creds2);
687 torture_assert(torture, s->join_ctx2 != NULL,
688 "Failed to join domain with acct_flags=ACB_WSTRUST");
690 cli_credentials_set_kerberos_state(s->wks_creds1, CRED_DONT_USE_KERBEROS);
691 cli_credentials_set_kerberos_state(s->wks_creds2, CRED_DONT_USE_KERBEROS);
693 for (i=0; i < s->nprocs; i++) {
695 s->conns[i].index = i;
696 s->conns[i].wks_creds = (struct cli_credentials *)talloc_memdup(
697 s->conns, s->wks_creds1,sizeof(*s->wks_creds1));
698 if ((i % 2) && (torture_setting_bool(torture, "multijoin", false))) {
699 memcpy(s->conns[i].wks_creds, s->wks_creds2,
700 talloc_get_size(s->conns[i].wks_creds));
702 s->conns[i].wks_creds->netlogon_creds = NULL;
705 status = dcerpc_parse_binding(s, binding, &s->b);
706 torture_assert_ntstatus_ok(torture, status, "Bad binding string");
707 s->b->flags &= ~DCERPC_AUTH_OPTIONS;
708 s->b->flags |= DCERPC_SCHANNEL | DCERPC_SIGN;
710 torture_comment(torture, "Opening %d connections in parallel\n", s->nprocs);
711 for (i=0; i < s->nprocs; i++) {
713 s->error = dcerpc_pipe_connect_b(s->conns, &s->conns[i].pipe, s->b,
715 s->conns[i].wks_creds,
716 torture->ev, torture->lp_ctx);
717 torture_assert_ntstatus_ok(torture, s->error, "Failed to connect with schannel");
720 * This path doesn't work against windows,
721 * because of windows drops the connections
722 * which haven't reached a session setup yet
724 * The same as the reset on zero vc stuff.
726 struct composite_context *c;
727 c = dcerpc_pipe_connect_b_send(s->conns, s->b,
729 s->conns[i].wks_creds,
732 torture_assert(torture, c != NULL, "Failed to setup connect");
733 c->async.fn = torture_schannel_bench_connected;
734 c->async.private_data = &s->conns[i];
737 while (NT_STATUS_IS_OK(s->error) && s->nprocs != s->nconns) {
738 int ev_ret = event_loop_once(torture->ev);
739 torture_assert(torture, ev_ret == 0, "event_loop_once failed");
742 torture_assert_ntstatus_ok(torture, s->error, "Failed establish a connect");
745 * Change the workstation password after establishing the netlogon
746 * schannel connections to prove that existing connections are not
747 * affected by a wks pwchange.
751 struct netr_ServerPasswordSet pwset;
752 char *password = generate_random_str(s->join_ctx1, 8);
753 struct creds_CredentialState *creds_state;
754 struct dcerpc_pipe *net_pipe;
756 status = dcerpc_pipe_connect_b(s, &net_pipe, s->b,
759 torture->ev, torture->lp_ctx);
761 torture_assert_ntstatus_ok(torture, status,
762 "dcerpc_pipe_connect_b failed");
764 pwset.in.server_name = talloc_asprintf(
765 net_pipe, "\\\\%s", dcerpc_server_name(net_pipe));
766 pwset.in.computer_name =
767 cli_credentials_get_workstation(s->wks_creds1);
768 pwset.in.account_name = talloc_asprintf(
769 net_pipe, "%s$", pwset.in.computer_name);
770 pwset.in.secure_channel_type = SEC_CHAN_WKSTA;
771 E_md4hash(password, pwset.in.new_password.hash);
773 creds_state = cli_credentials_get_netlogon_creds(
775 creds_des_encrypt(creds_state, &pwset.in.new_password);
776 creds_client_authenticator(creds_state, &pwset.in.credential);
778 status = dcerpc_netr_ServerPasswordSet(net_pipe, torture, &pwset);
779 torture_assert_ntstatus_ok(torture, status,
780 "ServerPasswordSet failed");
782 if (!creds_client_check(creds_state,
783 &pwset.out.return_authenticator.cred)) {
784 printf("Credential chaining failed\n");
787 cli_credentials_set_password(s->wks_creds1, password,
790 talloc_free(net_pipe);
792 /* Just as a test, connect with the new creds */
794 talloc_free(s->wks_creds1->netlogon_creds);
795 s->wks_creds1->netlogon_creds = NULL;
797 status = dcerpc_pipe_connect_b(s, &net_pipe, s->b,
800 torture->ev, torture->lp_ctx);
802 torture_assert_ntstatus_ok(torture, status,
803 "dcerpc_pipe_connect_b failed");
805 talloc_free(net_pipe);
808 torture_comment(torture, "Start looping LogonSamLogonEx on %d connections for %d secs\n",
809 s->nprocs, s->timelimit);
810 for (i=0; i < s->nprocs; i++) {
811 ret = torture_schannel_bench_start(&s->conns[i]);
812 torture_assert(torture, ret, "Failed to setup LogonSamLogonEx");
815 start = timeval_current();
816 end = timeval_add(&start, s->timelimit, 0);
818 while (NT_STATUS_IS_OK(s->error) && !timeval_expired(&end)) {
819 int ev_ret = event_loop_once(torture->ev);
820 torture_assert(torture, ev_ret == 0, "event_loop_once failed");
822 torture_assert_ntstatus_ok(torture, s->error, "Failed some request");
824 talloc_free(s->conns);
826 for (i=0; i < s->nprocs; i++) {
827 s->total += s->conns[i].total;
830 torture_comment(torture,
831 "Total ops[%llu] (%u ops/s)\n",
832 (unsigned long long)s->total,
833 (unsigned)s->total/s->timelimit);
835 torture_leave_domain(torture, s->join_ctx1);
836 torture_leave_domain(torture, s->join_ctx2);