s4: popt: Global replace of cmdline_credentials -> popt_get_cmdline_credentials().
[gd/samba-autobuild/.git] / source4 / torture / rpc / schannel.c
1 /*
2    Unix SMB/CIFS implementation.
3
4    test suite for schannel operations
5
6    Copyright (C) Andrew Tridgell 2004
7
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.
12
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.
17
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/>.
20 */
21
22 #include "includes.h"
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 "auth/credentials/credentials_krb5.h"
28 #include "torture/rpc/torture_rpc.h"
29 #include "lib/cmdline/popt_common.h"
30 #include "../libcli/auth/schannel.h"
31 #include "libcli/auth/libcli_auth.h"
32 #include "libcli/security/security.h"
33 #include "system/filesys.h"
34 #include "param/param.h"
35 #include "librpc/rpc/dcerpc_proto.h"
36 #include "libcli/composite/composite.h"
37 #include "lib/events/events.h"
38
39 #define TEST_MACHINE_NAME "schannel"
40
41 /*
42   try a netlogon SamLogon
43 */
44 bool test_netlogon_ex_ops(struct dcerpc_pipe *p, struct torture_context *tctx,
45                           struct cli_credentials *credentials,
46                           struct netlogon_creds_CredentialState *creds)
47 {
48         NTSTATUS status;
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;
54         uint32_t _flags = 0;
55         DATA_BLOB names_blob, chal, lm_resp, nt_resp;
56         int i;
57         int flags = CLI_CRED_NTLM_AUTH;
58         struct dcerpc_binding_handle *b = p->binding_handle;
59
60         struct netr_UserSessionKey key;
61         struct netr_LMSessionKey LMSessKey;
62         uint32_t validation_levels[] = { 2, 3 };
63         struct netr_SamBaseInfo *base = NULL;
64         const char *crypto_alg = "";
65         bool can_do_validation_6 = true;
66         enum dcerpc_AuthLevel auth_level = DCERPC_AUTH_LEVEL_NONE;
67
68         if (lpcfg_client_lanman_auth(tctx->lp_ctx)) {
69                 flags |= CLI_CRED_LANMAN_AUTH;
70         }
71
72         if (lpcfg_client_ntlmv2_auth(tctx->lp_ctx)) {
73                 flags |= CLI_CRED_NTLMv2_AUTH;
74         }
75
76         cli_credentials_get_ntlm_username_domain(popt_get_cmdline_credentials(),
77                                 tctx,
78                                 &ninfo.identity_info.account_name.string,
79                                 &ninfo.identity_info.domain_name.string);
80
81         generate_random_buffer(ninfo.challenge,
82                                sizeof(ninfo.challenge));
83         chal = data_blob_const(ninfo.challenge,
84                                sizeof(ninfo.challenge));
85
86         names_blob = NTLMv2_generate_names_blob(tctx, cli_credentials_get_workstation(credentials),
87                                                 cli_credentials_get_domain(credentials));
88
89         status = cli_credentials_get_ntlm_response(
90                         popt_get_cmdline_credentials(),
91                         tctx,
92                         &flags,
93                         chal,
94                         NULL, /* server_timestamp */
95                         names_blob,
96                         &lm_resp, &nt_resp,
97                         NULL, NULL);
98         torture_assert_ntstatus_ok(tctx, status,
99                                    "cli_credentials_get_ntlm_response failed");
100
101         ninfo.lm.data = lm_resp.data;
102         ninfo.lm.length = lm_resp.length;
103
104         ninfo.nt.data = nt_resp.data;
105         ninfo.nt.length = nt_resp.length;
106
107         ninfo.identity_info.parameter_control = 0;
108         ninfo.identity_info.logon_id_low = 0;
109         ninfo.identity_info.logon_id_high = 0;
110         ninfo.identity_info.workstation.string = cli_credentials_get_workstation(credentials);
111
112         logon.network = &ninfo;
113
114         r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
115         r.in.computer_name = cli_credentials_get_workstation(credentials);
116         r.in.logon_level = NetlogonNetworkInformation;
117         r.in.logon= &logon;
118         r.in.flags = &_flags;
119         r.out.validation = &validation;
120         r.out.authoritative = &authoritative;
121         r.out.flags = &_flags;
122
123         /*
124         - retrieve level6
125         - save usrsession and lmsession key
126         - retrieve level 2
127         - calculate, compare
128         - retrieve level 3
129         - calculate, compare
130         */
131
132         if (creds) {
133                 if (creds->negotiate_flags & NETLOGON_NEG_SUPPORTS_AES) {
134                         crypto_alg = "AES";
135                 } else if (creds->negotiate_flags & NETLOGON_NEG_ARCFOUR) {
136                         crypto_alg = "ARCFOUR";
137                 }
138         }
139
140         dcerpc_binding_handle_auth_info(b, NULL, &auth_level);
141         if (auth_level == DCERPC_AUTH_LEVEL_PRIVACY) {
142                 r.in.validation_level = 6;
143
144                 torture_comment(tctx,
145                                 "Testing LogonSamLogonEx with name %s using %s and validation_level: %d\n",
146                                 ninfo.identity_info.account_name.string, crypto_alg,
147                                 r.in.validation_level);
148
149                 torture_assert_ntstatus_ok(tctx,
150                         dcerpc_netr_LogonSamLogonEx_r(b, tctx, &r),
151                         "LogonSamLogonEx failed");
152         } else {
153                 torture_comment(tctx,
154                                 "Skip auth_level[%u] Testing LogonSamLogonEx with name %s using %s and validation_level: %d\n",
155                                 auth_level, ninfo.identity_info.account_name.string, crypto_alg,
156                                 r.in.validation_level);
157                 r.out.result = NT_STATUS_INVALID_INFO_CLASS;
158         }
159
160         if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_INVALID_INFO_CLASS)) {
161                 can_do_validation_6 = false;
162         } else {
163                 torture_assert_ntstatus_ok(tctx, r.out.result,
164                         "LogonSamLogonEx failed");
165
166                 key = r.out.validation->sam6->base.key;
167                 LMSessKey = r.out.validation->sam6->base.LMSessKey;
168
169                 DEBUG(1,("unencrypted session keys from validation_level 6:\n"));
170                 dump_data(1, r.out.validation->sam6->base.key.key, 16);
171                 dump_data(1, r.out.validation->sam6->base.LMSessKey.key, 8);
172         }
173
174         for (i=0; i < ARRAY_SIZE(validation_levels); i++) {
175
176                 r.in.validation_level = validation_levels[i];
177
178                 torture_comment(tctx,
179                         "Testing LogonSamLogonEx with name %s using %s and validation_level: %d\n",
180                         ninfo.identity_info.account_name.string, crypto_alg,
181                         r.in.validation_level);
182
183                 torture_assert_ntstatus_ok(tctx,
184                         dcerpc_netr_LogonSamLogonEx_r(b, tctx, &r),
185                         "LogonSamLogonEx failed");
186                 torture_assert_ntstatus_ok(tctx, r.out.result,
187                         "LogonSamLogonEx failed");
188
189                 if (creds == NULL) {
190                         /* when this test is called without creds no point in
191                          * testing the session keys */
192                         continue;
193                 }
194
195                 switch (validation_levels[i]) {
196                 case 2:
197                         base = &r.out.validation->sam2->base;
198                         break;
199                 case 3:
200                         base = &r.out.validation->sam3->base;
201                         break;
202                 default:
203                         break;
204                 }
205
206                 DEBUG(1,("encrypted keys validation_level %d:\n",
207                         validation_levels[i]));
208                 dump_data(1, base->key.key, 16);
209                 dump_data(1, base->LMSessKey.key, 8);
210
211                 if (creds->negotiate_flags & NETLOGON_NEG_SUPPORTS_AES) {
212                         netlogon_creds_aes_decrypt(creds, base->key.key, 16);
213                         netlogon_creds_aes_decrypt(creds, base->LMSessKey.key, 8);
214                 } else if (creds->negotiate_flags & NETLOGON_NEG_ARCFOUR) {
215                         netlogon_creds_arcfour_crypt(creds, base->key.key, 16);
216                         netlogon_creds_arcfour_crypt(creds, base->LMSessKey.key, 8);
217                 }
218
219                 DEBUG(1,("decryped keys validation_level %d\n",
220                         validation_levels[i]));
221
222                 dump_data(1, base->key.key, 16);
223                 dump_data(1, base->LMSessKey.key, 8);
224
225                 if (!can_do_validation_6) {
226                         /* we cant compare against unencrypted keys */
227                         continue;
228                 }
229
230                 torture_assert_mem_equal(tctx,
231                                          base->key.key,
232                                          key.key,
233                                          16,
234                                          "unexpected user session key\n");
235                 torture_assert_mem_equal(tctx,
236                                          base->LMSessKey.key,
237                                          LMSessKey.key,
238                                          8,
239                                          "unexpected LM session key\n");
240         }
241
242         return true;
243 }
244
245 /*
246   do some samr ops using the schannel connection
247  */
248 static bool test_samr_ops(struct torture_context *tctx,
249                           struct dcerpc_binding_handle *b)
250 {
251         struct samr_GetDomPwInfo r;
252         struct samr_PwInfo info;
253         struct samr_Connect connect_r;
254         struct samr_OpenDomain opendom;
255         int i;
256         struct lsa_String name;
257         struct policy_handle handle;
258         struct policy_handle domain_handle;
259
260         name.string = lpcfg_workgroup(tctx->lp_ctx);
261         r.in.domain_name = &name;
262         r.out.info = &info;
263
264         connect_r.in.system_name = 0;
265         connect_r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
266         connect_r.out.connect_handle = &handle;
267
268         torture_comment(tctx, "Testing Connect and OpenDomain on BUILTIN\n");
269
270         torture_assert_ntstatus_ok(tctx, dcerpc_samr_Connect_r(b, tctx, &connect_r),
271                 "Connect failed");
272         if (!NT_STATUS_IS_OK(connect_r.out.result)) {
273                 if (NT_STATUS_EQUAL(connect_r.out.result, NT_STATUS_ACCESS_DENIED)) {
274                         torture_comment(tctx, "Connect failed (expected, schannel mapped to anonymous): %s\n",
275                                nt_errstr(connect_r.out.result));
276                 } else {
277                         torture_comment(tctx, "Connect failed - %s\n", nt_errstr(connect_r.out.result));
278                         return false;
279                 }
280         } else {
281                 opendom.in.connect_handle = &handle;
282                 opendom.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
283                 opendom.in.sid = dom_sid_parse_talloc(tctx, "S-1-5-32");
284                 opendom.out.domain_handle = &domain_handle;
285
286                 torture_assert_ntstatus_ok(tctx, dcerpc_samr_OpenDomain_r(b, tctx, &opendom),
287                         "OpenDomain failed");
288                 if (!NT_STATUS_IS_OK(opendom.out.result)) {
289                         torture_comment(tctx, "OpenDomain failed - %s\n", nt_errstr(opendom.out.result));
290                         return false;
291                 }
292         }
293
294         torture_comment(tctx, "Testing GetDomPwInfo with name %s\n", r.in.domain_name->string);
295
296         /* do several ops to test credential chaining */
297         for (i=0;i<5;i++) {
298                 torture_assert_ntstatus_ok(tctx, dcerpc_samr_GetDomPwInfo_r(b, tctx, &r),
299                         "GetDomPwInfo failed");
300                 if (!NT_STATUS_IS_OK(r.out.result)) {
301                         if (!NT_STATUS_EQUAL(r.out.result, NT_STATUS_ACCESS_DENIED)) {
302                                 torture_comment(tctx, "GetDomPwInfo op %d failed - %s\n", i, nt_errstr(r.out.result));
303                                 return false;
304                         }
305                 }
306         }
307
308         return true;
309 }
310
311
312 /*
313   do some lsa ops using the schannel connection
314  */
315 static bool test_lsa_ops(struct torture_context *tctx, struct dcerpc_pipe *p)
316 {
317         struct lsa_GetUserName r;
318         bool ret = true;
319         struct lsa_String *account_name_p = NULL;
320         struct lsa_String *authority_name_p = NULL;
321         struct dcerpc_binding_handle *b = p->binding_handle;
322
323         torture_comment(tctx, "\nTesting GetUserName\n");
324
325         r.in.system_name = "\\";
326         r.in.account_name = &account_name_p;
327         r.in.authority_name = &authority_name_p;
328         r.out.account_name = &account_name_p;
329
330         /* do several ops to test credential chaining and various operations */
331         torture_assert_ntstatus_ok(tctx, dcerpc_lsa_GetUserName_r(b, tctx, &r),
332                 "lsa_GetUserName failed");
333
334         authority_name_p = *r.out.authority_name;
335
336         if (!NT_STATUS_IS_OK(r.out.result)) {
337                 torture_comment(tctx, "GetUserName failed - %s\n", nt_errstr(r.out.result));
338                 return false;
339         } else {
340                 if (!r.out.account_name) {
341                         return false;
342                 }
343
344                 if (strcmp(account_name_p->string, "ANONYMOUS LOGON") != 0) {
345                         torture_comment(tctx, "GetUserName returned wrong user: %s, expected %s\n",
346                                account_name_p->string, "ANONYMOUS LOGON");
347                         /* FIXME: gd */
348                         if (!torture_setting_bool(tctx, "samba3", false)) {
349                                 return false;
350                         }
351                 }
352                 if (!authority_name_p || !authority_name_p->string) {
353                         return false;
354                 }
355
356                 if (strcmp(authority_name_p->string, "NT AUTHORITY") != 0) {
357                         torture_comment(tctx, "GetUserName returned wrong user: %s, expected %s\n",
358                                authority_name_p->string, "NT AUTHORITY");
359                         /* FIXME: gd */
360                         if (!torture_setting_bool(tctx, "samba3", false)) {
361                                 return false;
362                         }
363                 }
364         }
365
366         return ret;
367 }
368
369
370 /*
371   test a schannel connection with the given flags
372  */
373 static bool test_schannel(struct torture_context *tctx,
374                           uint16_t acct_flags, uint32_t dcerpc_flags,
375                           int i)
376 {
377         struct test_join *join_ctx;
378         NTSTATUS status;
379         const char *binding = torture_setting_string(tctx, "binding", NULL);
380         struct dcerpc_binding *b;
381         struct dcerpc_pipe *p = NULL;
382         struct dcerpc_pipe *p_netlogon = NULL;
383         struct dcerpc_pipe *p_netlogon2 = NULL;
384         struct dcerpc_pipe *p_netlogon3 = NULL;
385         struct dcerpc_pipe *p_samr2 = NULL;
386         struct dcerpc_pipe *p_lsa = NULL;
387         struct netlogon_creds_CredentialState *creds;
388         struct cli_credentials *credentials;
389         enum dcerpc_transport_t transport;
390
391         join_ctx = torture_join_domain(tctx,
392                                        talloc_asprintf(tctx, "%s%d", TEST_MACHINE_NAME, i),
393                                        acct_flags, &credentials);
394         torture_assert(tctx, join_ctx != NULL, "Failed to join domain");
395
396         status = dcerpc_parse_binding(tctx, binding, &b);
397         torture_assert_ntstatus_ok(tctx, status, "Bad binding string");
398
399         status = dcerpc_binding_set_flags(b, dcerpc_flags, DCERPC_AUTH_OPTIONS);
400         torture_assert_ntstatus_ok(tctx, status, "set flags");
401
402         status = dcerpc_pipe_connect_b(tctx, &p, b, &ndr_table_samr,
403                                        credentials, tctx->ev, tctx->lp_ctx);
404         torture_assert_ntstatus_ok(tctx, status,
405                 "Failed to connect to samr with schannel");
406
407         torture_assert(tctx, test_samr_ops(tctx, p->binding_handle),
408                        "Failed to process schannel secured SAMR ops");
409
410         /* Also test that when we connect to the netlogon pipe, that
411          * the credentials we setup on the first pipe are valid for
412          * the second */
413
414         /* Swap the binding details from SAMR to NETLOGON */
415         status = dcerpc_epm_map_binding(tctx, b, &ndr_table_netlogon, tctx->ev, tctx->lp_ctx);
416         torture_assert_ntstatus_ok(tctx, status, "epm map");
417
418         status = dcerpc_binding_set_flags(b, dcerpc_flags, DCERPC_AUTH_OPTIONS);
419         torture_assert_ntstatus_ok(tctx, status, "set flags");
420
421         status = dcerpc_secondary_auth_connection(p, b, &ndr_table_netlogon,
422                                                   credentials, tctx->lp_ctx,
423                                                   tctx, &p_netlogon);
424         torture_assert_ntstatus_ok(tctx, status, "Failed to create secondary connection");
425
426         creds = cli_credentials_get_netlogon_creds(credentials);
427         torture_assert(tctx, (creds != NULL), "schannel creds");
428
429         /* checks the capabilities */
430         torture_assert(tctx, test_netlogon_capabilities(p_netlogon, tctx, credentials, creds),
431                        "Failed to process schannel secured capability ops (on fresh connection)");
432
433         /* do a couple of logins */
434         torture_assert(tctx, test_netlogon_ops(p_netlogon, tctx, credentials, creds),
435                 "Failed to process schannel secured NETLOGON ops");
436
437         torture_assert(tctx, test_netlogon_ex_ops(p_netlogon, tctx, credentials, creds),
438                 "Failed to process schannel secured NETLOGON EX ops");
439
440         /* we *MUST* use ncacn_np for openpolicy etc. */
441         transport = dcerpc_binding_get_transport(b);
442         status = dcerpc_binding_set_transport(b, NCACN_NP);
443         torture_assert_ntstatus_ok(tctx, status, "set transport");
444
445         /* Swap the binding details from SAMR to LSARPC */
446         status = dcerpc_epm_map_binding(tctx, b, &ndr_table_lsarpc, tctx->ev, tctx->lp_ctx);
447         torture_assert_ntstatus_ok(tctx, status, "epm map");
448
449         torture_assert_ntstatus_ok(tctx,
450                 dcerpc_pipe_connect_b(tctx, &p_lsa, b, &ndr_table_lsarpc,
451                                       credentials, tctx->ev, tctx->lp_ctx),
452                 "failed to connect lsarpc with schannel");
453
454         torture_assert(tctx, test_lsa_ops(tctx, p_lsa),
455                 "Failed to process schannel secured LSA ops");
456
457         talloc_free(p_lsa);
458         p_lsa = NULL;
459
460         /* we *MUST* use ncacn_ip_tcp for lookupsids3/lookupnames4 */
461         status = dcerpc_binding_set_transport(b, NCACN_IP_TCP);
462         torture_assert_ntstatus_ok(tctx, status, "set transport");
463
464         torture_assert_ntstatus_ok(tctx,
465                 dcerpc_epm_map_binding(tctx, b, &ndr_table_lsarpc, tctx->ev, tctx->lp_ctx),
466                 "failed to call epm map");
467
468         torture_assert_ntstatus_ok(tctx,
469                 dcerpc_pipe_connect_b(tctx, &p_lsa, b, &ndr_table_lsarpc,
470                                       credentials, tctx->ev, tctx->lp_ctx),
471                 "failed to connect lsarpc with schannel");
472
473         torture_assert(tctx,
474                 test_many_LookupSids(p_lsa, tctx, NULL),
475                 "LsaLookupSids3 failed!\n");
476
477         status = dcerpc_binding_set_transport(b, transport);
478         torture_assert_ntstatus_ok(tctx, status, "set transport");
479
480
481         /* Drop the socket, we want to start from scratch */
482         talloc_free(p);
483         p = NULL;
484
485         /* Now see what we are still allowed to do */
486
487         status = dcerpc_parse_binding(tctx, binding, &b);
488         torture_assert_ntstatus_ok(tctx, status, "Bad binding string");
489
490         status = dcerpc_binding_set_flags(b, dcerpc_flags, DCERPC_AUTH_OPTIONS);
491         torture_assert_ntstatus_ok(tctx, status, "set flags");
492
493         status = dcerpc_pipe_connect_b(tctx, &p_samr2, b, &ndr_table_samr,
494                                        credentials, tctx->ev, tctx->lp_ctx);
495         torture_assert_ntstatus_ok(tctx, status,
496                 "Failed to connect with schannel");
497
498         /* do a some SAMR operations.  We have *not* done a new serverauthenticate */
499         torture_assert (tctx, test_samr_ops(tctx, p_samr2->binding_handle),
500                         "Failed to process schannel secured SAMR ops (on fresh connection)");
501
502         /* Swap the binding details from SAMR to NETLOGON */
503         status = dcerpc_epm_map_binding(tctx, b, &ndr_table_netlogon, tctx->ev, tctx->lp_ctx);
504         torture_assert_ntstatus_ok(tctx, status, "epm");
505
506         status = dcerpc_binding_set_flags(b, dcerpc_flags, DCERPC_AUTH_OPTIONS);
507         torture_assert_ntstatus_ok(tctx, status, "set flags");
508
509         status = dcerpc_secondary_auth_connection(p_samr2, b, &ndr_table_netlogon,
510                                                   credentials, tctx->lp_ctx,
511                                                   tctx, &p_netlogon2);
512         torture_assert_ntstatus_ok(tctx, status, "Failed to create secondary connection");
513
514         /* checks the capabilities */
515         torture_assert(tctx, test_netlogon_capabilities(p_netlogon2, tctx, credentials, creds),
516                        "Failed to process schannel secured capability ops (on fresh connection)");
517
518         /* Try the schannel-only SamLogonEx operation */
519         torture_assert(tctx, test_netlogon_ex_ops(p_netlogon2, tctx, credentials, creds),
520                        "Failed to process schannel secured NETLOGON EX ops (on fresh connection)");
521
522
523         /* And the more traditional style, proving that the
524          * credentials chaining state is fully present */
525         torture_assert(tctx, test_netlogon_ops(p_netlogon2, tctx, credentials, creds),
526                              "Failed to process schannel secured NETLOGON ops (on fresh connection)");
527
528         /* Drop the socket, we want to start from scratch (again) */
529         talloc_free(p_samr2);
530
531         /* We don't want schannel for this test */
532         status = dcerpc_binding_set_flags(b, 0, DCERPC_AUTH_OPTIONS);
533         torture_assert_ntstatus_ok(tctx, status, "set flags");
534
535         status = dcerpc_pipe_connect_b(tctx, &p_netlogon3, b, &ndr_table_netlogon,
536                                        credentials, tctx->ev, tctx->lp_ctx);
537         torture_assert_ntstatus_ok(tctx, status, "Failed to connect without schannel");
538
539         torture_assert(tctx, !test_netlogon_ex_ops(p_netlogon3, tctx, credentials, creds),
540                         "Processed NOT schannel secured NETLOGON EX ops without SCHANNEL (unsafe)");
541
542         /* Required because the previous call will mark the current context as having failed */
543         tctx->last_result = TORTURE_OK;
544         tctx->last_reason = NULL;
545
546         torture_assert(tctx, test_netlogon_ops(p_netlogon3, tctx, credentials, creds),
547                         "Failed to processed NOT schannel secured NETLOGON ops without new ServerAuth");
548
549         torture_leave_domain(tctx, join_ctx);
550         return true;
551 }
552
553 /*
554  * Purpose of this test is to demonstrate that a netlogon server carefully deals
555  * with anonymous attempts to set passwords, in particular when the server
556  * enforces the use of schannel. This test makes most sense to be run in an
557  * environment where the netlogon server enforces use of schannel.
558  */
559
560 static bool test_schannel_anonymous_setPassword(struct torture_context *tctx,
561                                                 uint32_t dcerpc_flags,
562                                                 bool use2)
563 {
564         NTSTATUS status, result;
565         const char *binding = torture_setting_string(tctx, "binding", NULL);
566         struct dcerpc_binding *b;
567         struct dcerpc_pipe *p = NULL;
568         struct cli_credentials *credentials;
569         bool ok = true;
570
571         credentials = cli_credentials_init(NULL);
572         torture_assert(tctx, credentials != NULL, "Bad credentials");
573         cli_credentials_set_anonymous(credentials);
574
575         status = dcerpc_parse_binding(tctx, binding, &b);
576         torture_assert_ntstatus_ok(tctx, status, "Bad binding string");
577
578         status = dcerpc_binding_set_flags(b, dcerpc_flags, DCERPC_AUTH_OPTIONS);
579         torture_assert_ntstatus_ok(tctx, status, "set flags");
580
581         status = dcerpc_pipe_connect_b(tctx,
582                                        &p,
583                                        b,
584                                        &ndr_table_netlogon,
585                                        credentials,
586                                        tctx->ev,
587                                        tctx->lp_ctx);
588         torture_assert_ntstatus_ok(tctx, status, "Failed to connect without schannel");
589
590         if (use2) {
591                 struct netr_ServerPasswordSet2 r = {};
592                 struct netr_Authenticator credential = {};
593                 struct netr_Authenticator return_authenticator = {};
594                 struct netr_CryptPassword new_password = {};
595
596                 r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
597                 r.in.account_name = talloc_asprintf(tctx, "%s$", TEST_MACHINE_NAME);
598                 r.in.secure_channel_type = 0;
599                 r.in.computer_name = TEST_MACHINE_NAME;
600                 r.in.credential = &credential;
601                 r.in.new_password = &new_password;
602                 r.out.return_authenticator = &return_authenticator;
603
604                 status = dcerpc_netr_ServerPasswordSet2_r(p->binding_handle, tctx, &r);
605                 result = r.out.result;
606         } else {
607                 struct netr_ServerPasswordSet r = {};
608                 struct netr_Authenticator credential = {};
609                 struct netr_Authenticator return_authenticator = {};
610                 struct samr_Password new_password = {};
611
612                 r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
613                 r.in.account_name = talloc_asprintf(tctx, "%s$", TEST_MACHINE_NAME);
614                 r.in.secure_channel_type = 0;
615                 r.in.computer_name = TEST_MACHINE_NAME;
616                 r.in.credential = &credential;
617                 r.in.new_password = &new_password;
618                 r.out.return_authenticator = &return_authenticator;
619
620                 status = dcerpc_netr_ServerPasswordSet_r(p->binding_handle, tctx, &r);
621                 result = r.out.result;
622         }
623
624         torture_assert_ntstatus_ok(tctx, status, "ServerPasswordSet failed");
625
626         if (NT_STATUS_IS_OK(result)) {
627                 torture_fail(tctx, "unexpectedly received NT_STATUS_OK");
628         }
629
630         return ok;
631 }
632
633
634 /*
635   a schannel test suite
636  */
637 bool torture_rpc_schannel(struct torture_context *torture)
638 {
639         bool ret = true;
640         struct {
641                 uint16_t acct_flags;
642                 uint32_t dcerpc_flags;
643         } tests[] = {
644                 { ACB_WSTRUST,   DCERPC_SCHANNEL | DCERPC_SIGN | DCERPC_SCHANNEL_AUTO},
645                 { ACB_WSTRUST,   DCERPC_SCHANNEL | DCERPC_SEAL | DCERPC_SCHANNEL_AUTO},
646                 { ACB_WSTRUST,   DCERPC_SCHANNEL | DCERPC_SIGN | DCERPC_SCHANNEL_128},
647                 { ACB_WSTRUST,   DCERPC_SCHANNEL | DCERPC_SEAL | DCERPC_SCHANNEL_128 },
648                 { ACB_WSTRUST,   DCERPC_SCHANNEL | DCERPC_SIGN | DCERPC_SCHANNEL_AES},
649                 { ACB_WSTRUST,   DCERPC_SCHANNEL | DCERPC_SEAL | DCERPC_SCHANNEL_AES },
650                 { ACB_SVRTRUST,  DCERPC_SCHANNEL | DCERPC_SIGN | DCERPC_SCHANNEL_AUTO},
651                 { ACB_SVRTRUST,  DCERPC_SCHANNEL | DCERPC_SEAL | DCERPC_SCHANNEL_AUTO},
652                 { ACB_SVRTRUST,  DCERPC_SCHANNEL | DCERPC_SIGN | DCERPC_SCHANNEL_128 },
653                 { ACB_SVRTRUST,  DCERPC_SCHANNEL | DCERPC_SEAL | DCERPC_SCHANNEL_128 },
654                 { ACB_SVRTRUST,  DCERPC_SCHANNEL | DCERPC_SIGN | DCERPC_SCHANNEL_AES },
655                 { ACB_SVRTRUST,  DCERPC_SCHANNEL | DCERPC_SEAL | DCERPC_SCHANNEL_AES }
656         };
657         int i;
658
659         for (i=0;i<ARRAY_SIZE(tests);i++) {
660                 torture_comment(torture, "Testing with acct_flags=0x%x dcerpc_flags=0x%x \n",
661                        tests[i].acct_flags, tests[i].dcerpc_flags);
662
663                 if (!test_schannel(torture,
664                                    tests[i].acct_flags, tests[i].dcerpc_flags,
665                                    i)) {
666                         torture_comment(torture, "Failed with acct_flags=0x%x dcerpc_flags=0x%x \n",
667                                tests[i].acct_flags, tests[i].dcerpc_flags);
668                         ret = false;
669                 }
670         }
671
672         return ret;
673 }
674
675 bool torture_rpc_schannel_anon_setpw(struct torture_context *torture)
676 {
677         bool ret = true;
678         bool ok;
679         uint32_t dcerpc_flags = DCERPC_SCHANNEL | DCERPC_SIGN | DCERPC_SCHANNEL_AUTO;
680
681         ok = test_schannel_anonymous_setPassword(torture,
682                                                  dcerpc_flags,
683                                                  true);
684         if (!ok) {
685                 torture_comment(torture,
686                                 "Failed with dcerpc_flags=0x%x\n",
687                                 dcerpc_flags);
688                 ret = false;
689         }
690
691         ok = test_schannel_anonymous_setPassword(torture,
692                                                  dcerpc_flags,
693                                                  false);
694         if (!ok) {
695                 torture_comment(torture,
696                                 "Failed with dcerpc_flags=0x%x\n",
697                                 dcerpc_flags);
698                 ret = false;
699         }
700
701         return ret;
702 }
703
704 /*
705   test two schannel connections
706  */
707 bool torture_rpc_schannel2(struct torture_context *torture)
708 {
709         struct test_join *join_ctx;
710         NTSTATUS status;
711         const char *binding = torture_setting_string(torture, "binding", NULL);
712         struct dcerpc_binding *b;
713         struct dcerpc_pipe *p1 = NULL, *p2 = NULL;
714         struct cli_credentials *credentials1, *credentials2;
715         uint32_t dcerpc_flags = DCERPC_SCHANNEL | DCERPC_SCHANNEL_AUTO | DCERPC_SIGN;
716
717         join_ctx = torture_join_domain(torture, talloc_asprintf(torture, "%s2", TEST_MACHINE_NAME),
718                                        ACB_WSTRUST, &credentials1);
719         torture_assert(torture, join_ctx != NULL,
720                        "Failed to join domain with acct_flags=ACB_WSTRUST");
721
722         credentials2 = cli_credentials_shallow_copy(torture, credentials1);
723         cli_credentials_set_netlogon_creds(credentials1, NULL);
724         cli_credentials_set_netlogon_creds(credentials2, NULL);
725
726         status = dcerpc_parse_binding(torture, binding, &b);
727         torture_assert_ntstatus_ok(torture, status, "Bad binding string");
728
729         status = dcerpc_binding_set_flags(b, dcerpc_flags, DCERPC_AUTH_OPTIONS);
730         torture_assert_ntstatus_ok(torture, status, "set flags");
731
732         torture_comment(torture, "Opening first connection\n");
733         status = dcerpc_pipe_connect_b(torture, &p1, b, &ndr_table_netlogon,
734                                        credentials1, torture->ev, torture->lp_ctx);
735         torture_assert_ntstatus_ok(torture, status, "Failed to connect with schannel");
736
737         torture_comment(torture, "Opening second connection\n");
738         status = dcerpc_pipe_connect_b(torture, &p2, b, &ndr_table_netlogon,
739                                        credentials2, torture->ev, torture->lp_ctx);
740         torture_assert_ntstatus_ok(torture, status, "Failed to connect with schannel");
741
742         cli_credentials_set_netlogon_creds(credentials1, NULL);
743         cli_credentials_set_netlogon_creds(credentials2, NULL);
744
745         torture_comment(torture, "Testing logon on pipe1\n");
746         if (!test_netlogon_ex_ops(p1, torture, credentials1, NULL))
747                 return false;
748
749         torture_comment(torture, "Testing logon on pipe2\n");
750         if (!test_netlogon_ex_ops(p2, torture, credentials2, NULL))
751                 return false;
752
753         torture_comment(torture, "Again on pipe1\n");
754         if (!test_netlogon_ex_ops(p1, torture, credentials1, NULL))
755                 return false;
756
757         torture_comment(torture, "Again on pipe2\n");
758         if (!test_netlogon_ex_ops(p2, torture, credentials2, NULL))
759                 return false;
760
761         torture_leave_domain(torture, join_ctx);
762         return true;
763 }
764
765 struct torture_schannel_bench;
766
767 struct torture_schannel_bench_conn {
768         struct torture_schannel_bench *s;
769         int index;
770         struct cli_credentials *wks_creds;
771         struct dcerpc_pipe *pipe;
772         struct netr_LogonSamLogonEx r;
773         struct netr_NetworkInfo ninfo;
774         TALLOC_CTX *tmp;
775         uint64_t total;
776         uint32_t count;
777 };
778
779 struct torture_schannel_bench {
780         struct torture_context *tctx;
781         bool progress;
782         int timelimit;
783         int nprocs;
784         int nconns;
785         struct torture_schannel_bench_conn *conns;
786         struct test_join *join_ctx1;
787         struct cli_credentials *wks_creds1;
788         struct test_join *join_ctx2;
789         struct cli_credentials *wks_creds2;
790         struct cli_credentials *user1_creds;
791         struct cli_credentials *user2_creds;
792         struct dcerpc_binding *b;
793         NTSTATUS error;
794         uint64_t total;
795         uint32_t count;
796         bool stopped;
797 };
798
799 #if 0
800 static void torture_schannel_bench_connected(struct composite_context *c)
801 {
802         struct torture_schannel_bench_conn *conn =
803                 (struct torture_schannel_bench_conn *)c->async.private_data;
804         struct torture_schannel_bench *s = talloc_get_type(conn->s,
805                                            struct torture_schannel_bench);
806
807         s->error = dcerpc_pipe_connect_b_recv(c, s->conns, &conn->pipe);
808         torture_comment(s->tctx, "conn[%u]: %s\n", conn->index, nt_errstr(s->error));
809         if (NT_STATUS_IS_OK(s->error)) {
810                 s->nconns++;
811         }
812 }
813 #endif
814
815 static void torture_schannel_bench_recv(struct tevent_req *subreq);
816
817 static bool torture_schannel_bench_start(struct torture_schannel_bench_conn *conn)
818 {
819         struct torture_schannel_bench *s = conn->s;
820         NTSTATUS status;
821         DATA_BLOB names_blob, chal, lm_resp, nt_resp;
822         int flags = CLI_CRED_NTLM_AUTH;
823         struct tevent_req *subreq;
824         struct cli_credentials *user_creds;
825
826         if (conn->total % 2) {
827                 user_creds = s->user1_creds;
828         } else {
829                 user_creds = s->user2_creds;
830         }
831
832         if (lpcfg_client_lanman_auth(s->tctx->lp_ctx)) {
833                 flags |= CLI_CRED_LANMAN_AUTH;
834         }
835
836         if (lpcfg_client_ntlmv2_auth(s->tctx->lp_ctx)) {
837                 flags |= CLI_CRED_NTLMv2_AUTH;
838         }
839
840         talloc_free(conn->tmp);
841         conn->tmp = talloc_new(s);
842         ZERO_STRUCT(conn->ninfo);
843         ZERO_STRUCT(conn->r);
844
845         cli_credentials_get_ntlm_username_domain(user_creds, conn->tmp,
846                                                  &conn->ninfo.identity_info.account_name.string,
847                                                  &conn->ninfo.identity_info.domain_name.string);
848
849         generate_random_buffer(conn->ninfo.challenge,
850                                sizeof(conn->ninfo.challenge));
851         chal = data_blob_const(conn->ninfo.challenge,
852                                sizeof(conn->ninfo.challenge));
853
854         names_blob = NTLMv2_generate_names_blob(conn->tmp,
855                                                 cli_credentials_get_workstation(conn->wks_creds),
856                                                 cli_credentials_get_domain(conn->wks_creds));
857
858         status = cli_credentials_get_ntlm_response(user_creds, conn->tmp,
859                                                    &flags,
860                                                    chal,
861                                                    NULL, /* server_timestamp */
862                                                    names_blob,
863                                                    &lm_resp, &nt_resp,
864                                                    NULL, NULL);
865         torture_assert_ntstatus_ok(s->tctx, status,
866                                    "cli_credentials_get_ntlm_response failed");
867
868         conn->ninfo.lm.data = lm_resp.data;
869         conn->ninfo.lm.length = lm_resp.length;
870
871         conn->ninfo.nt.data = nt_resp.data;
872         conn->ninfo.nt.length = nt_resp.length;
873
874         conn->ninfo.identity_info.parameter_control = 0;
875         conn->ninfo.identity_info.logon_id_low = 0;
876         conn->ninfo.identity_info.logon_id_high = 0;
877         conn->ninfo.identity_info.workstation.string = cli_credentials_get_workstation(conn->wks_creds);
878
879         conn->r.in.server_name = talloc_asprintf(conn->tmp, "\\\\%s", dcerpc_server_name(conn->pipe));
880         conn->r.in.computer_name = cli_credentials_get_workstation(conn->wks_creds);
881         conn->r.in.logon_level = NetlogonNetworkInformation;
882         conn->r.in.logon = talloc(conn->tmp, union netr_LogonLevel);
883         conn->r.in.logon->network = &conn->ninfo;
884         conn->r.in.flags = talloc(conn->tmp, uint32_t);
885         conn->r.in.validation_level = 2;
886         conn->r.out.validation = talloc(conn->tmp, union netr_Validation);
887         conn->r.out.authoritative = talloc(conn->tmp, uint8_t);
888         conn->r.out.flags = conn->r.in.flags;
889
890         subreq = dcerpc_netr_LogonSamLogonEx_r_send(s, s->tctx->ev,
891                                                     conn->pipe->binding_handle,
892                                                     &conn->r);
893         torture_assert(s->tctx, subreq, "Failed to setup LogonSamLogonEx request");
894
895         tevent_req_set_callback(subreq, torture_schannel_bench_recv, conn);
896
897         return true;
898 }
899
900 static void torture_schannel_bench_recv(struct tevent_req *subreq)
901 {
902         bool ret;
903         struct torture_schannel_bench_conn *conn =
904                 (struct torture_schannel_bench_conn *)tevent_req_callback_data_void(subreq);
905         struct torture_schannel_bench *s = talloc_get_type(conn->s,
906                                            struct torture_schannel_bench);
907
908         s->error = dcerpc_netr_LogonSamLogonEx_r_recv(subreq, subreq);
909         TALLOC_FREE(subreq);
910         if (!NT_STATUS_IS_OK(s->error)) {
911                 return;
912         }
913
914         conn->total++;
915         conn->count++;
916
917         if (s->stopped) {
918                 return;
919         }
920
921         ret = torture_schannel_bench_start(conn);
922         if (!ret) {
923                 s->error = NT_STATUS_INTERNAL_ERROR;
924         }
925 }
926
927 /*
928   test multiple schannel connection in parallel
929  */
930 bool torture_rpc_schannel_bench1(struct torture_context *torture)
931 {
932         bool ret = true;
933         NTSTATUS status;
934         const char *binding = torture_setting_string(torture, "binding", NULL);
935         struct torture_schannel_bench *s;
936         struct timeval start;
937         struct timeval end;
938         int i;
939         const char *tmp;
940
941         s = talloc_zero(torture, struct torture_schannel_bench);
942         s->tctx = torture;
943         s->progress = torture_setting_bool(torture, "progress", true);
944         s->timelimit = torture_setting_int(torture, "timelimit", 10);
945         s->nprocs = torture_setting_int(torture, "nprocs", 4);
946         s->conns = talloc_zero_array(s, struct torture_schannel_bench_conn, s->nprocs);
947
948         s->user1_creds = cli_credentials_shallow_copy(s,
949                                 popt_get_cmdline_credentials());
950         tmp = torture_setting_string(s->tctx, "extra_user1", NULL);
951         if (tmp) {
952                 cli_credentials_parse_string(s->user1_creds, tmp, CRED_SPECIFIED);
953         }
954         s->user2_creds = cli_credentials_shallow_copy(s,
955                                 popt_get_cmdline_credentials());
956         tmp = torture_setting_string(s->tctx, "extra_user2", NULL);
957         if (tmp) {
958                 cli_credentials_parse_string(s->user1_creds, tmp, CRED_SPECIFIED);
959         }
960
961         s->join_ctx1 = torture_join_domain(s->tctx, talloc_asprintf(s, "%sb", TEST_MACHINE_NAME),
962                                            ACB_WSTRUST, &s->wks_creds1);
963         torture_assert(torture, s->join_ctx1 != NULL,
964                        "Failed to join domain with acct_flags=ACB_WSTRUST");
965         s->join_ctx2 = torture_join_domain(s->tctx, talloc_asprintf(s, "%sc", TEST_MACHINE_NAME),
966                                            ACB_WSTRUST, &s->wks_creds2);
967         torture_assert(torture, s->join_ctx2 != NULL,
968                        "Failed to join domain with acct_flags=ACB_WSTRUST");
969
970         cli_credentials_set_kerberos_state(s->wks_creds1, CRED_DONT_USE_KERBEROS);
971         cli_credentials_set_kerberos_state(s->wks_creds2, CRED_DONT_USE_KERBEROS);
972
973         for (i=0; i < s->nprocs; i++) {
974                 struct cli_credentials *wks = s->wks_creds1;
975
976                 if ((i % 2) && (torture_setting_bool(torture, "multijoin", false))) {
977                         wks = s->wks_creds2;
978                 }
979
980                 s->conns[i].s = s;
981                 s->conns[i].index = i;
982                 s->conns[i].wks_creds = cli_credentials_shallow_copy(s->conns, wks);
983                 cli_credentials_set_netlogon_creds(s->conns[i].wks_creds, NULL);
984         }
985
986         status = dcerpc_parse_binding(s, binding, &s->b);
987         torture_assert_ntstatus_ok(torture, status, "Bad binding string");
988
989         status = dcerpc_binding_set_flags(s->b, DCERPC_SCHANNEL | DCERPC_SIGN,
990                                           DCERPC_AUTH_OPTIONS);
991         torture_assert_ntstatus_ok(torture, status, "set flags");
992
993         torture_comment(torture, "Opening %d connections in parallel\n", s->nprocs);
994         for (i=0; i < s->nprocs; i++) {
995 #if 1
996                 s->error = dcerpc_pipe_connect_b(s->conns, &s->conns[i].pipe, s->b,
997                                                  &ndr_table_netlogon,
998                                                  s->conns[i].wks_creds,
999                                                  torture->ev, torture->lp_ctx);
1000                 torture_assert_ntstatus_ok(torture, s->error, "Failed to connect with schannel");
1001 #else
1002                 /*
1003                  * This path doesn't work against windows,
1004                  * because of windows drops the connections
1005                  * which haven't reached a session setup yet
1006                  *
1007                  * The same as the reset on zero vc stuff.
1008                  */
1009                 struct composite_context *c;
1010                 c = dcerpc_pipe_connect_b_send(s->conns, s->b,
1011                                                &ndr_table_netlogon,
1012                                                s->conns[i].wks_creds,
1013                                                torture->ev,
1014                                                torture->lp_ctx);
1015                 torture_assert(torture, c != NULL, "Failed to setup connect");
1016                 c->async.fn = torture_schannel_bench_connected;
1017                 c->async.private_data = &s->conns[i];
1018         }
1019
1020         while (NT_STATUS_IS_OK(s->error) && s->nprocs != s->nconns) {
1021                 int ev_ret = tevent_loop_once(torture->ev);
1022                 torture_assert(torture, ev_ret == 0, "tevent_loop_once failed");
1023 #endif
1024         }
1025         torture_assert_ntstatus_ok(torture, s->error, "Failed establish a connect");
1026
1027         /*
1028          * Change the workstation password after establishing the netlogon
1029          * schannel connections to prove that existing connections are not
1030          * affected by a wks pwchange.
1031          */
1032
1033         {
1034                 struct netr_ServerPasswordSet pwset;
1035                 char *password = generate_random_password(s->join_ctx1, 8, 255);
1036                 struct netlogon_creds_CredentialState *creds_state;
1037                 struct dcerpc_pipe *net_pipe;
1038                 struct netr_Authenticator credential, return_authenticator;
1039                 struct samr_Password new_password;
1040
1041                 status = dcerpc_pipe_connect_b(s, &net_pipe, s->b,
1042                                                &ndr_table_netlogon,
1043                                                s->wks_creds1,
1044                                                torture->ev, torture->lp_ctx);
1045
1046                 torture_assert_ntstatus_ok(torture, status,
1047                                            "dcerpc_pipe_connect_b failed");
1048
1049                 pwset.in.server_name = talloc_asprintf(
1050                         net_pipe, "\\\\%s", dcerpc_server_name(net_pipe));
1051                 pwset.in.computer_name =
1052                         cli_credentials_get_workstation(s->wks_creds1);
1053                 pwset.in.account_name = talloc_asprintf(
1054                         net_pipe, "%s$", pwset.in.computer_name);
1055                 pwset.in.secure_channel_type = SEC_CHAN_WKSTA;
1056                 pwset.in.credential = &credential;
1057                 pwset.in.new_password = &new_password;
1058                 pwset.out.return_authenticator = &return_authenticator;
1059
1060                 E_md4hash(password, new_password.hash);
1061
1062                 creds_state = cli_credentials_get_netlogon_creds(
1063                         s->wks_creds1);
1064                 netlogon_creds_des_encrypt(creds_state, &new_password);
1065                 netlogon_creds_client_authenticator(creds_state, &credential);
1066
1067                 torture_assert_ntstatus_ok(torture, dcerpc_netr_ServerPasswordSet_r(net_pipe->binding_handle, torture, &pwset),
1068                         "ServerPasswordSet failed");
1069                 torture_assert_ntstatus_ok(torture, pwset.out.result,
1070                                            "ServerPasswordSet failed");
1071
1072                 if (!netlogon_creds_client_check(creds_state,
1073                                         &pwset.out.return_authenticator->cred)) {
1074                         torture_comment(torture, "Credential chaining failed\n");
1075                 }
1076
1077                 cli_credentials_set_password(s->wks_creds1, password,
1078                                              CRED_SPECIFIED);
1079
1080                 talloc_free(net_pipe);
1081
1082                 /* Just as a test, connect with the new creds */
1083
1084                 cli_credentials_set_netlogon_creds(s->wks_creds1, NULL);
1085
1086                 status = dcerpc_pipe_connect_b(s, &net_pipe, s->b,
1087                                                &ndr_table_netlogon,
1088                                                s->wks_creds1,
1089                                                torture->ev, torture->lp_ctx);
1090
1091                 torture_assert_ntstatus_ok(torture, status,
1092                                            "dcerpc_pipe_connect_b failed");
1093
1094                 talloc_free(net_pipe);
1095         }
1096
1097         torture_comment(torture, "Start looping LogonSamLogonEx on %d connections for %d secs\n",
1098                         s->nprocs, s->timelimit);
1099         for (i=0; i < s->nprocs; i++) {
1100                 ret = torture_schannel_bench_start(&s->conns[i]);
1101                 torture_assert(torture, ret, "Failed to setup LogonSamLogonEx");
1102         }
1103
1104         start = timeval_current();
1105         end = timeval_add(&start, s->timelimit, 0);
1106
1107         while (NT_STATUS_IS_OK(s->error) && !timeval_expired(&end)) {
1108                 int ev_ret = tevent_loop_once(torture->ev);
1109                 torture_assert(torture, ev_ret == 0, "tevent_loop_once failed");
1110         }
1111         torture_assert_ntstatus_ok(torture, s->error, "Failed some request");
1112         s->stopped = true;
1113         talloc_free(s->conns);
1114
1115         for (i=0; i < s->nprocs; i++) {
1116                 s->total += s->conns[i].total;
1117         }
1118
1119         torture_comment(torture,
1120                         "Total ops[%llu] (%u ops/s)\n",
1121                         (unsigned long long)s->total,
1122                         (unsigned)s->total/s->timelimit);
1123
1124         torture_leave_domain(torture, s->join_ctx1);
1125         torture_leave_domain(torture, s->join_ctx2);
1126         return true;
1127 }