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 union netr_LogonLevel logon;
52 union netr_Validation validation;
53 uint8_t authoritative = 0;
55 DATA_BLOB names_blob, chal, lm_resp, nt_resp;
57 int flags = CLI_CRED_NTLM_AUTH;
58 if (lp_client_lanman_auth(tctx->lp_ctx)) {
59 flags |= CLI_CRED_LANMAN_AUTH;
62 if (lp_client_ntlmv2_auth(tctx->lp_ctx)) {
63 flags |= CLI_CRED_NTLMv2_AUTH;
66 cli_credentials_get_ntlm_username_domain(cmdline_credentials, tctx,
67 &ninfo.identity_info.account_name.string,
68 &ninfo.identity_info.domain_name.string);
70 generate_random_buffer(ninfo.challenge,
71 sizeof(ninfo.challenge));
72 chal = data_blob_const(ninfo.challenge,
73 sizeof(ninfo.challenge));
75 names_blob = NTLMv2_generate_names_blob(tctx, cli_credentials_get_workstation(credentials),
76 cli_credentials_get_domain(credentials));
78 status = cli_credentials_get_ntlm_response(cmdline_credentials, tctx,
84 torture_assert_ntstatus_ok(tctx, status,
85 "cli_credentials_get_ntlm_response failed");
87 ninfo.lm.data = lm_resp.data;
88 ninfo.lm.length = lm_resp.length;
90 ninfo.nt.data = nt_resp.data;
91 ninfo.nt.length = nt_resp.length;
93 ninfo.identity_info.parameter_control = 0;
94 ninfo.identity_info.logon_id_low = 0;
95 ninfo.identity_info.logon_id_high = 0;
96 ninfo.identity_info.workstation.string = cli_credentials_get_workstation(credentials);
98 logon.network = &ninfo;
100 r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
101 r.in.computer_name = cli_credentials_get_workstation(credentials);
102 r.in.logon_level = 2;
104 r.in.flags = &_flags;
105 r.out.validation = &validation;
106 r.out.authoritative = &authoritative;
107 r.out.flags = &_flags;
109 torture_comment(tctx,
110 "Testing LogonSamLogonEx with name %s\n",
111 ninfo.identity_info.account_name.string);
114 r.in.validation_level = i;
116 status = dcerpc_netr_LogonSamLogonEx(p, tctx, &r);
117 torture_assert_ntstatus_ok(tctx, status, "LogonSamLogon failed");
124 do some samr ops using the schannel connection
126 static bool test_samr_ops(struct torture_context *tctx,
127 struct dcerpc_pipe *p)
130 struct samr_GetDomPwInfo r;
131 struct samr_Connect connect;
132 struct samr_OpenDomain opendom;
134 struct lsa_String name;
135 struct policy_handle handle;
136 struct policy_handle domain_handle;
138 name.string = lp_workgroup(tctx->lp_ctx);
139 r.in.domain_name = &name;
141 connect.in.system_name = 0;
142 connect.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
143 connect.out.connect_handle = &handle;
145 printf("Testing Connect and OpenDomain on BUILTIN\n");
147 status = dcerpc_samr_Connect(p, tctx, &connect);
148 if (!NT_STATUS_IS_OK(status)) {
149 if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
150 printf("Connect failed (expected, schannel mapped to anonymous): %s\n",
153 printf("Connect failed - %s\n", nt_errstr(status));
157 opendom.in.connect_handle = &handle;
158 opendom.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
159 opendom.in.sid = dom_sid_parse_talloc(tctx, "S-1-5-32");
160 opendom.out.domain_handle = &domain_handle;
162 status = dcerpc_samr_OpenDomain(p, tctx, &opendom);
163 if (!NT_STATUS_IS_OK(status)) {
164 printf("OpenDomain failed - %s\n", nt_errstr(status));
169 printf("Testing GetDomPwInfo with name %s\n", r.in.domain_name->string);
171 /* do several ops to test credential chaining */
173 status = dcerpc_samr_GetDomPwInfo(p, tctx, &r);
174 if (!NT_STATUS_IS_OK(status)) {
175 if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
176 printf("GetDomPwInfo op %d failed - %s\n", i, nt_errstr(status));
187 do some lsa ops using the schannel connection
189 static bool test_lsa_ops(struct torture_context *tctx, struct dcerpc_pipe *p)
191 struct lsa_GetUserName r;
194 struct lsa_String *account_name_p = NULL;
195 struct lsa_String *authority_name_p = NULL;
197 printf("\nTesting GetUserName\n");
199 r.in.system_name = "\\";
200 r.in.account_name = &account_name_p;
201 r.in.authority_name = &authority_name_p;
202 r.out.account_name = &account_name_p;
204 /* do several ops to test credential chaining and various operations */
205 status = dcerpc_lsa_GetUserName(p, tctx, &r);
207 authority_name_p = *r.out.authority_name;
209 if (NT_STATUS_EQUAL(status, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED)) {
210 printf("not considering %s to be an error\n", nt_errstr(status));
211 } else if (!NT_STATUS_IS_OK(status)) {
212 printf("GetUserName failed - %s\n", nt_errstr(status));
215 if (!r.out.account_name) {
219 if (strcmp(account_name_p->string, "ANONYMOUS LOGON") != 0) {
220 printf("GetUserName returned wrong user: %s, expected %s\n",
221 account_name_p->string, "ANONYMOUS LOGON");
224 if (!authority_name_p || !authority_name_p->string) {
228 if (strcmp(authority_name_p->string, "NT AUTHORITY") != 0) {
229 printf("GetUserName returned wrong user: %s, expected %s\n",
230 authority_name_p->string, "NT AUTHORITY");
234 if (!test_many_LookupSids(p, tctx, NULL)) {
235 printf("LsaLookupSids3 failed!\n");
244 test a schannel connection with the given flags
246 static bool test_schannel(struct torture_context *tctx,
247 uint16_t acct_flags, uint32_t dcerpc_flags,
250 struct test_join *join_ctx;
252 const char *binding = torture_setting_string(tctx, "binding", NULL);
253 struct dcerpc_binding *b;
254 struct dcerpc_pipe *p = NULL;
255 struct dcerpc_pipe *p_netlogon = NULL;
256 struct dcerpc_pipe *p_netlogon2 = NULL;
257 struct dcerpc_pipe *p_netlogon3 = NULL;
258 struct dcerpc_pipe *p_samr2 = NULL;
259 struct dcerpc_pipe *p_lsa = NULL;
260 struct creds_CredentialState *creds;
261 struct cli_credentials *credentials;
263 join_ctx = torture_join_domain(tctx,
264 talloc_asprintf(tctx, "%s%d", TEST_MACHINE_NAME, i),
265 acct_flags, &credentials);
266 torture_assert(tctx, join_ctx != NULL, "Failed to join domain");
268 status = dcerpc_parse_binding(tctx, binding, &b);
269 torture_assert_ntstatus_ok(tctx, status, "Bad binding string");
271 b->flags &= ~DCERPC_AUTH_OPTIONS;
272 b->flags |= dcerpc_flags;
274 status = dcerpc_pipe_connect_b(tctx, &p, b, &ndr_table_samr,
275 credentials, tctx->ev, tctx->lp_ctx);
276 torture_assert_ntstatus_ok(tctx, status,
277 "Failed to connect with schannel");
279 torture_assert(tctx, test_samr_ops(tctx, p),
280 "Failed to process schannel secured SAMR ops");
282 /* Also test that when we connect to the netlogon pipe, that
283 * the credentials we setup on the first pipe are valid for
286 /* Swap the binding details from SAMR to NETLOGON */
287 status = dcerpc_epm_map_binding(tctx, b, &ndr_table_netlogon, tctx->ev, tctx->lp_ctx);
288 torture_assert_ntstatus_ok(tctx, status, "epm map");
290 status = dcerpc_secondary_connection(p, &p_netlogon,
292 torture_assert_ntstatus_ok(tctx, status, "seconday connection");
294 status = dcerpc_bind_auth(p_netlogon, &ndr_table_netlogon,
295 credentials, lp_gensec_settings(tctx, tctx->lp_ctx),
296 DCERPC_AUTH_TYPE_SCHANNEL,
297 dcerpc_auth_level(p->conn),
300 torture_assert_ntstatus_ok(tctx, status, "bind auth");
302 status = dcerpc_schannel_creds(p_netlogon->conn->security_state.generic_state, tctx, &creds);
303 torture_assert_ntstatus_ok(tctx, status, "schannel creds");
305 /* do a couple of logins */
306 torture_assert(tctx, test_netlogon_ops(p_netlogon, tctx, credentials, creds),
307 "Failed to process schannel secured NETLOGON ops");
309 torture_assert(tctx, test_netlogon_ex_ops(p_netlogon, tctx, credentials, creds),
310 "Failed to process schannel secured NETLOGON EX ops");
312 /* Swap the binding details from SAMR to LSARPC */
313 status = dcerpc_epm_map_binding(tctx, b, &ndr_table_lsarpc, tctx->ev, tctx->lp_ctx);
314 torture_assert_ntstatus_ok(tctx, status, "epm map");
316 status = dcerpc_secondary_connection(p, &p_lsa,
319 torture_assert_ntstatus_ok(tctx, status, "seconday connection");
321 status = dcerpc_bind_auth(p_lsa, &ndr_table_lsarpc,
322 credentials, lp_gensec_settings(tctx, tctx->lp_ctx),
323 DCERPC_AUTH_TYPE_SCHANNEL,
324 dcerpc_auth_level(p->conn),
327 torture_assert_ntstatus_ok(tctx, status, "bind auth");
329 torture_assert(tctx, test_lsa_ops(tctx, p_lsa),
330 "Failed to process schannel secured LSA ops");
332 /* Drop the socket, we want to start from scratch */
336 /* Now see what we are still allowed to do */
338 status = dcerpc_parse_binding(tctx, binding, &b);
339 torture_assert_ntstatus_ok(tctx, status, "Bad binding string");
341 b->flags &= ~DCERPC_AUTH_OPTIONS;
342 b->flags |= dcerpc_flags;
344 status = dcerpc_pipe_connect_b(tctx, &p_samr2, b, &ndr_table_samr,
345 credentials, tctx->ev, tctx->lp_ctx);
346 torture_assert_ntstatus_ok(tctx, status,
347 "Failed to connect with schannel");
349 /* do a some SAMR operations. We have *not* done a new serverauthenticate */
350 torture_assert (tctx, test_samr_ops(tctx, p_samr2),
351 "Failed to process schannel secured SAMR ops (on fresh connection)");
353 /* Swap the binding details from SAMR to NETLOGON */
354 status = dcerpc_epm_map_binding(tctx, b, &ndr_table_netlogon, tctx->ev, tctx->lp_ctx);
355 torture_assert_ntstatus_ok(tctx, status, "epm");
357 status = dcerpc_secondary_connection(p_samr2, &p_netlogon2,
359 torture_assert_ntstatus_ok(tctx, status, "seconday connection");
361 /* and now setup an SCHANNEL bind on netlogon */
362 status = dcerpc_bind_auth(p_netlogon2, &ndr_table_netlogon,
363 credentials, lp_gensec_settings(tctx, tctx->lp_ctx),
364 DCERPC_AUTH_TYPE_SCHANNEL,
365 dcerpc_auth_level(p_samr2->conn),
368 torture_assert_ntstatus_ok(tctx, status, "auth failed");
370 /* Try the schannel-only SamLogonEx operation */
371 torture_assert(tctx, test_netlogon_ex_ops(p_netlogon2, tctx, credentials, creds),
372 "Failed to process schannel secured NETLOGON EX ops (on fresh connection)");
375 /* And the more traditional style, proving that the
376 * credentials chaining state is fully present */
377 torture_assert(tctx, test_netlogon_ops(p_netlogon2, tctx, credentials, creds),
378 "Failed to process schannel secured NETLOGON ops (on fresh connection)");
380 /* Drop the socket, we want to start from scratch (again) */
381 talloc_free(p_samr2);
383 /* We don't want schannel for this test */
384 b->flags &= ~DCERPC_AUTH_OPTIONS;
386 status = dcerpc_pipe_connect_b(tctx, &p_netlogon3, b, &ndr_table_netlogon,
387 credentials, tctx->ev, tctx->lp_ctx);
388 torture_assert_ntstatus_ok(tctx, status, "Failed to connect without schannel");
390 torture_assert(tctx, !test_netlogon_ex_ops(p_netlogon3, tctx, credentials, creds),
391 "Processed NOT schannel secured NETLOGON EX ops without SCHANNEL (unsafe)");
393 /* Required because the previous call will mark the current context as having failed */
394 tctx->last_result = TORTURE_OK;
395 tctx->last_reason = NULL;
397 torture_assert(tctx, test_netlogon_ops(p_netlogon3, tctx, credentials, creds),
398 "Failed to processed NOT schannel secured NETLOGON ops without new ServerAuth");
400 torture_leave_domain(tctx, join_ctx);
407 a schannel test suite
409 bool torture_rpc_schannel(struct torture_context *torture)
414 uint32_t dcerpc_flags;
416 { ACB_WSTRUST, DCERPC_SCHANNEL | DCERPC_SIGN},
417 { ACB_WSTRUST, DCERPC_SCHANNEL | DCERPC_SEAL},
418 { ACB_WSTRUST, DCERPC_SCHANNEL | DCERPC_SIGN | DCERPC_SCHANNEL_128},
419 { ACB_WSTRUST, DCERPC_SCHANNEL | DCERPC_SEAL | DCERPC_SCHANNEL_128 },
420 { ACB_SVRTRUST, DCERPC_SCHANNEL | DCERPC_SIGN },
421 { ACB_SVRTRUST, DCERPC_SCHANNEL | DCERPC_SEAL },
422 { ACB_SVRTRUST, DCERPC_SCHANNEL | DCERPC_SIGN | DCERPC_SCHANNEL_128 },
423 { ACB_SVRTRUST, DCERPC_SCHANNEL | DCERPC_SEAL | DCERPC_SCHANNEL_128 }
427 for (i=0;i<ARRAY_SIZE(tests);i++) {
428 if (!test_schannel(torture,
429 tests[i].acct_flags, tests[i].dcerpc_flags,
431 torture_comment(torture, "Failed with acct_flags=0x%x dcerpc_flags=0x%x \n",
432 tests[i].acct_flags, tests[i].dcerpc_flags);
441 test two schannel connections
443 bool torture_rpc_schannel2(struct torture_context *torture)
445 struct test_join *join_ctx;
447 const char *binding = torture_setting_string(torture, "binding", NULL);
448 struct dcerpc_binding *b;
449 struct dcerpc_pipe *p1 = NULL, *p2 = NULL;
450 struct cli_credentials *credentials1, *credentials2;
451 uint32_t dcerpc_flags = DCERPC_SCHANNEL | DCERPC_SIGN;
453 join_ctx = torture_join_domain(torture, talloc_asprintf(torture, "%s2", TEST_MACHINE_NAME),
454 ACB_WSTRUST, &credentials1);
455 torture_assert(torture, join_ctx != NULL,
456 "Failed to join domain with acct_flags=ACB_WSTRUST");
458 credentials2 = (struct cli_credentials *)talloc_memdup(torture, credentials1, sizeof(*credentials1));
459 credentials1->netlogon_creds = NULL;
460 credentials2->netlogon_creds = NULL;
462 status = dcerpc_parse_binding(torture, binding, &b);
463 torture_assert_ntstatus_ok(torture, status, "Bad binding string");
465 b->flags &= ~DCERPC_AUTH_OPTIONS;
466 b->flags |= dcerpc_flags;
468 printf("Opening first connection\n");
469 status = dcerpc_pipe_connect_b(torture, &p1, b, &ndr_table_netlogon,
470 credentials1, torture->ev, torture->lp_ctx);
471 torture_assert_ntstatus_ok(torture, status, "Failed to connect with schannel");
473 torture_comment(torture, "Opening second connection\n");
474 status = dcerpc_pipe_connect_b(torture, &p2, b, &ndr_table_netlogon,
475 credentials2, torture->ev, torture->lp_ctx);
476 torture_assert_ntstatus_ok(torture, status, "Failed to connect with schannel");
478 credentials1->netlogon_creds = NULL;
479 credentials2->netlogon_creds = NULL;
481 torture_comment(torture, "Testing logon on pipe1\n");
482 if (!test_netlogon_ex_ops(p1, torture, credentials1, NULL))
485 torture_comment(torture, "Testing logon on pipe2\n");
486 if (!test_netlogon_ex_ops(p2, torture, credentials2, NULL))
489 torture_comment(torture, "Again on pipe1\n");
490 if (!test_netlogon_ex_ops(p1, torture, credentials1, NULL))
493 torture_comment(torture, "Again on pipe2\n");
494 if (!test_netlogon_ex_ops(p2, torture, credentials2, NULL))
497 torture_leave_domain(torture, join_ctx);
501 struct torture_schannel_bench;
503 struct torture_schannel_bench_conn {
504 struct torture_schannel_bench *s;
506 struct cli_credentials *wks_creds;
507 struct dcerpc_pipe *pipe;
508 struct netr_LogonSamLogonEx r;
509 struct netr_NetworkInfo ninfo;
515 struct torture_schannel_bench {
516 struct torture_context *tctx;
521 struct torture_schannel_bench_conn *conns;
522 struct test_join *join_ctx1;
523 struct cli_credentials *wks_creds1;
524 struct test_join *join_ctx2;
525 struct cli_credentials *wks_creds2;
526 struct cli_credentials *user1_creds;
527 struct cli_credentials *user2_creds;
528 struct dcerpc_binding *b;
535 static void torture_schannel_bench_connected(struct composite_context *c)
537 struct torture_schannel_bench_conn *conn =
538 (struct torture_schannel_bench_conn *)c->async.private_data;
539 struct torture_schannel_bench *s = talloc_get_type(conn->s,
540 struct torture_schannel_bench);
542 s->error = dcerpc_pipe_connect_b_recv(c, s->conns, &conn->pipe);
543 torture_comment(s->tctx, "conn[%u]: %s\n", conn->index, nt_errstr(s->error));
544 if (NT_STATUS_IS_OK(s->error)) {
549 static void torture_schannel_bench_recv(struct rpc_request *req);
551 static bool torture_schannel_bench_start(struct torture_schannel_bench_conn *conn)
553 struct torture_schannel_bench *s = conn->s;
555 DATA_BLOB names_blob, chal, lm_resp, nt_resp;
556 int flags = CLI_CRED_NTLM_AUTH;
557 struct rpc_request *req;
558 struct cli_credentials *user_creds;
560 if (conn->total % 2) {
561 user_creds = s->user1_creds;
563 user_creds = s->user2_creds;
566 if (lp_client_lanman_auth(s->tctx->lp_ctx)) {
567 flags |= CLI_CRED_LANMAN_AUTH;
570 if (lp_client_ntlmv2_auth(s->tctx->lp_ctx)) {
571 flags |= CLI_CRED_NTLMv2_AUTH;
574 talloc_free(conn->tmp);
575 conn->tmp = talloc_new(s);
576 ZERO_STRUCT(conn->ninfo);
577 ZERO_STRUCT(conn->r);
579 cli_credentials_get_ntlm_username_domain(user_creds, conn->tmp,
580 &conn->ninfo.identity_info.account_name.string,
581 &conn->ninfo.identity_info.domain_name.string);
583 generate_random_buffer(conn->ninfo.challenge,
584 sizeof(conn->ninfo.challenge));
585 chal = data_blob_const(conn->ninfo.challenge,
586 sizeof(conn->ninfo.challenge));
588 names_blob = NTLMv2_generate_names_blob(conn->tmp,
589 cli_credentials_get_workstation(conn->wks_creds),
590 cli_credentials_get_domain(conn->wks_creds));
592 status = cli_credentials_get_ntlm_response(user_creds, conn->tmp,
598 torture_assert_ntstatus_ok(s->tctx, status,
599 "cli_credentials_get_ntlm_response failed");
601 conn->ninfo.lm.data = lm_resp.data;
602 conn->ninfo.lm.length = lm_resp.length;
604 conn->ninfo.nt.data = nt_resp.data;
605 conn->ninfo.nt.length = nt_resp.length;
607 conn->ninfo.identity_info.parameter_control = 0;
608 conn->ninfo.identity_info.logon_id_low = 0;
609 conn->ninfo.identity_info.logon_id_high = 0;
610 conn->ninfo.identity_info.workstation.string = cli_credentials_get_workstation(conn->wks_creds);
612 conn->r.in.server_name = talloc_asprintf(conn->tmp, "\\\\%s", dcerpc_server_name(conn->pipe));
613 conn->r.in.computer_name = cli_credentials_get_workstation(conn->wks_creds);
614 conn->r.in.logon_level = 2;
615 conn->r.in.logon = talloc(conn->tmp, union netr_LogonLevel);
616 conn->r.in.logon->network = &conn->ninfo;
617 conn->r.in.flags = talloc(conn->tmp, uint32_t);
618 conn->r.in.validation_level = 2;
619 conn->r.out.validation = talloc(conn->tmp, union netr_Validation);
620 conn->r.out.authoritative = talloc(conn->tmp, uint8_t);
621 conn->r.out.flags = conn->r.in.flags;
623 req = dcerpc_netr_LogonSamLogonEx_send(conn->pipe, conn->tmp, &conn->r);
624 torture_assert(s->tctx, req, "Failed to setup LogonSamLogonEx request");
626 req->async.callback = torture_schannel_bench_recv;
627 req->async.private_data = conn;
632 static void torture_schannel_bench_recv(struct rpc_request *req)
635 struct torture_schannel_bench_conn *conn =
636 (struct torture_schannel_bench_conn *)req->async.private_data;
637 struct torture_schannel_bench *s = talloc_get_type(conn->s,
638 struct torture_schannel_bench);
640 s->error = dcerpc_ndr_request_recv(req);
641 if (!NT_STATUS_IS_OK(s->error)) {
652 ret = torture_schannel_bench_start(conn);
654 s->error = NT_STATUS_INTERNAL_ERROR;
659 test multiple schannel connection in parallel
661 bool torture_rpc_schannel_bench1(struct torture_context *torture)
665 const char *binding = torture_setting_string(torture, "binding", NULL);
666 struct torture_schannel_bench *s;
667 struct timeval start;
672 s = talloc_zero(torture, struct torture_schannel_bench);
674 s->progress = torture_setting_bool(torture, "progress", true);
675 s->timelimit = torture_setting_int(torture, "timelimit", 10);
676 s->nprocs = torture_setting_int(torture, "nprocs", 4);
677 s->conns = talloc_zero_array(s, struct torture_schannel_bench_conn, s->nprocs);
679 s->user1_creds = (struct cli_credentials *)talloc_memdup(s,
681 sizeof(*s->user1_creds));
682 tmp = torture_setting_string(s->tctx, "extra_user1", NULL);
684 cli_credentials_parse_string(s->user1_creds, tmp, CRED_SPECIFIED);
686 s->user2_creds = (struct cli_credentials *)talloc_memdup(s,
688 sizeof(*s->user1_creds));
689 tmp = torture_setting_string(s->tctx, "extra_user2", NULL);
691 cli_credentials_parse_string(s->user1_creds, tmp, CRED_SPECIFIED);
694 s->join_ctx1 = torture_join_domain(s->tctx, talloc_asprintf(s, "%sb", TEST_MACHINE_NAME),
695 ACB_WSTRUST, &s->wks_creds1);
696 torture_assert(torture, s->join_ctx1 != NULL,
697 "Failed to join domain with acct_flags=ACB_WSTRUST");
698 s->join_ctx2 = torture_join_domain(s->tctx, talloc_asprintf(s, "%sc", TEST_MACHINE_NAME),
699 ACB_WSTRUST, &s->wks_creds2);
700 torture_assert(torture, s->join_ctx2 != NULL,
701 "Failed to join domain with acct_flags=ACB_WSTRUST");
703 cli_credentials_set_kerberos_state(s->wks_creds1, CRED_DONT_USE_KERBEROS);
704 cli_credentials_set_kerberos_state(s->wks_creds2, CRED_DONT_USE_KERBEROS);
706 for (i=0; i < s->nprocs; i++) {
708 s->conns[i].index = i;
709 s->conns[i].wks_creds = (struct cli_credentials *)talloc_memdup(
710 s->conns, s->wks_creds1,sizeof(*s->wks_creds1));
711 if ((i % 2) && (torture_setting_bool(torture, "multijoin", false))) {
712 memcpy(s->conns[i].wks_creds, s->wks_creds2,
713 talloc_get_size(s->conns[i].wks_creds));
715 s->conns[i].wks_creds->netlogon_creds = NULL;
718 status = dcerpc_parse_binding(s, binding, &s->b);
719 torture_assert_ntstatus_ok(torture, status, "Bad binding string");
720 s->b->flags &= ~DCERPC_AUTH_OPTIONS;
721 s->b->flags |= DCERPC_SCHANNEL | DCERPC_SIGN;
723 torture_comment(torture, "Opening %d connections in parallel\n", s->nprocs);
724 for (i=0; i < s->nprocs; i++) {
726 s->error = dcerpc_pipe_connect_b(s->conns, &s->conns[i].pipe, s->b,
728 s->conns[i].wks_creds,
729 torture->ev, torture->lp_ctx);
730 torture_assert_ntstatus_ok(torture, s->error, "Failed to connect with schannel");
733 * This path doesn't work against windows,
734 * because of windows drops the connections
735 * which haven't reached a session setup yet
737 * The same as the reset on zero vc stuff.
739 struct composite_context *c;
740 c = dcerpc_pipe_connect_b_send(s->conns, s->b,
742 s->conns[i].wks_creds,
745 torture_assert(torture, c != NULL, "Failed to setup connect");
746 c->async.fn = torture_schannel_bench_connected;
747 c->async.private_data = &s->conns[i];
750 while (NT_STATUS_IS_OK(s->error) && s->nprocs != s->nconns) {
751 int ev_ret = event_loop_once(torture->ev);
752 torture_assert(torture, ev_ret == 0, "event_loop_once failed");
755 torture_assert_ntstatus_ok(torture, s->error, "Failed establish a connect");
758 * Change the workstation password after establishing the netlogon
759 * schannel connections to prove that existing connections are not
760 * affected by a wks pwchange.
764 struct netr_ServerPasswordSet pwset;
765 char *password = generate_random_str(s->join_ctx1, 8);
766 struct creds_CredentialState *creds_state;
767 struct dcerpc_pipe *net_pipe;
768 struct netr_Authenticator credential, return_authenticator;
769 struct samr_Password new_password;
771 status = dcerpc_pipe_connect_b(s, &net_pipe, s->b,
774 torture->ev, torture->lp_ctx);
776 torture_assert_ntstatus_ok(torture, status,
777 "dcerpc_pipe_connect_b failed");
779 pwset.in.server_name = talloc_asprintf(
780 net_pipe, "\\\\%s", dcerpc_server_name(net_pipe));
781 pwset.in.computer_name =
782 cli_credentials_get_workstation(s->wks_creds1);
783 pwset.in.account_name = talloc_asprintf(
784 net_pipe, "%s$", pwset.in.computer_name);
785 pwset.in.secure_channel_type = SEC_CHAN_WKSTA;
786 pwset.in.credential = &credential;
787 pwset.in.new_password = &new_password;
788 pwset.out.return_authenticator = &return_authenticator;
790 E_md4hash(password, new_password.hash);
792 creds_state = cli_credentials_get_netlogon_creds(
794 creds_des_encrypt(creds_state, &new_password);
795 creds_client_authenticator(creds_state, &credential);
797 status = dcerpc_netr_ServerPasswordSet(net_pipe, torture, &pwset);
798 torture_assert_ntstatus_ok(torture, status,
799 "ServerPasswordSet failed");
801 if (!creds_client_check(creds_state,
802 &pwset.out.return_authenticator->cred)) {
803 printf("Credential chaining failed\n");
806 cli_credentials_set_password(s->wks_creds1, password,
809 talloc_free(net_pipe);
811 /* Just as a test, connect with the new creds */
813 talloc_free(s->wks_creds1->netlogon_creds);
814 s->wks_creds1->netlogon_creds = NULL;
816 status = dcerpc_pipe_connect_b(s, &net_pipe, s->b,
819 torture->ev, torture->lp_ctx);
821 torture_assert_ntstatus_ok(torture, status,
822 "dcerpc_pipe_connect_b failed");
824 talloc_free(net_pipe);
827 torture_comment(torture, "Start looping LogonSamLogonEx on %d connections for %d secs\n",
828 s->nprocs, s->timelimit);
829 for (i=0; i < s->nprocs; i++) {
830 ret = torture_schannel_bench_start(&s->conns[i]);
831 torture_assert(torture, ret, "Failed to setup LogonSamLogonEx");
834 start = timeval_current();
835 end = timeval_add(&start, s->timelimit, 0);
837 while (NT_STATUS_IS_OK(s->error) && !timeval_expired(&end)) {
838 int ev_ret = event_loop_once(torture->ev);
839 torture_assert(torture, ev_ret == 0, "event_loop_once failed");
841 torture_assert_ntstatus_ok(torture, s->error, "Failed some request");
843 talloc_free(s->conns);
845 for (i=0; i < s->nprocs; i++) {
846 s->total += s->conns[i].total;
849 torture_comment(torture,
850 "Total ops[%llu] (%u ops/s)\n",
851 (unsigned long long)s->total,
852 (unsigned)s->total/s->timelimit);
854 torture_leave_domain(torture, s->join_ctx1);
855 torture_leave_domain(torture, s->join_ctx2);