s4-smbtorture: Make test names lowercase and dot-separated.
[Samba.git] / source4 / torture / rpc / remote_pac.c
blob33034e0190ae9f71f2201f6cce9ee4e51ac97cc8
1 /*
2 Unix SMB/CIFS implementation.
4 test suite for netlogon PAC operations
6 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2008
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/>.
22 #include "includes.h"
23 #include "auth/auth.h"
24 #include "auth/auth_sam_reply.h"
25 #include "auth/gensec/gensec.h"
26 #include "system/kerberos.h"
27 #include "auth/kerberos/kerberos.h"
28 #include "auth/credentials/credentials.h"
29 #include "auth/credentials/credentials_krb5.h"
30 #include "lib/cmdline/popt_common.h"
31 #include "torture/rpc/torture_rpc.h"
32 #include "libcli/auth/libcli_auth.h"
33 #include "libcli/security/security.h"
34 #include "librpc/gen_ndr/ndr_netlogon_c.h"
35 #include "librpc/gen_ndr/ndr_samr_c.h"
36 #include "param/param.h"
38 #define TEST_MACHINE_NAME_BDC "torturepacbdc"
39 #define TEST_MACHINE_NAME_WKSTA "torturepacwksta"
40 #define TEST_MACHINE_NAME_WKSTA_DES "torturepacwkdes"
41 #define TEST_MACHINE_NAME_S2U4SELF_BDC "tests2u4selfbdc"
42 #define TEST_MACHINE_NAME_S2U4SELF_WKSTA "tests2u4selfwk"
44 /* Check to see if we can pass the PAC across to the NETLOGON server for validation */
46 /* Also happens to be a really good one-step verfication of our Kerberos stack */
48 static bool test_PACVerify(struct torture_context *tctx,
49 struct dcerpc_pipe *p,
50 struct cli_credentials *credentials,
51 enum netr_SchannelType secure_channel_type,
52 const char *test_machine_name)
54 NTSTATUS status;
56 struct netr_LogonSamLogon r;
58 union netr_LogonLevel logon;
59 union netr_Validation validation;
60 uint8_t authoritative;
61 struct netr_Authenticator return_authenticator;
63 struct netr_GenericInfo generic;
64 struct netr_Authenticator auth, auth2;
66 struct netlogon_creds_CredentialState *creds;
67 struct gensec_security *gensec_client_context;
68 struct gensec_security *gensec_server_context;
70 DATA_BLOB client_to_server, server_to_client, pac_wrapped, payload;
71 struct PAC_Validate pac_wrapped_struct;
73 enum ndr_err_code ndr_err;
75 struct auth_session_info *session_info;
77 char *tmp_dir;
78 struct dcerpc_binding_handle *b = p->binding_handle;
79 TALLOC_CTX *tmp_ctx = talloc_new(tctx);
80 torture_assert(tctx, tmp_ctx != NULL, "talloc_new() failed");
82 if (!test_SetupCredentials2(p, tctx, NETLOGON_NEG_AUTH2_ADS_FLAGS,
83 credentials, secure_channel_type,
84 &creds)) {
85 return false;
88 status = torture_temp_dir(tctx, "PACVerify", &tmp_dir);
89 torture_assert_ntstatus_ok(tctx, status, "torture_temp_dir failed");
91 status = gensec_client_start(tctx, &gensec_client_context, tctx->ev,
92 lpcfg_gensec_settings(tctx, tctx->lp_ctx));
93 torture_assert_ntstatus_ok(tctx, status, "gensec_client_start (client) failed");
95 status = gensec_set_target_hostname(gensec_client_context, test_machine_name);
97 status = gensec_set_credentials(gensec_client_context, cmdline_credentials);
98 torture_assert_ntstatus_ok(tctx, status, "gensec_set_credentials (client) failed");
100 status = gensec_start_mech_by_sasl_name(gensec_client_context, "GSSAPI");
101 torture_assert_ntstatus_ok(tctx, status, "gensec_start_mech_by_sasl_name (client) failed");
103 status = gensec_server_start(tctx, tctx->ev,
104 lpcfg_gensec_settings(tctx, tctx->lp_ctx),
105 NULL, &gensec_server_context);
106 torture_assert_ntstatus_ok(tctx, status, "gensec_server_start (server) failed");
108 status = gensec_set_credentials(gensec_server_context, credentials);
109 torture_assert_ntstatus_ok(tctx, status, "gensec_set_credentials (server) failed");
111 status = gensec_start_mech_by_sasl_name(gensec_server_context, "GSSAPI");
112 torture_assert_ntstatus_ok(tctx, status, "gensec_start_mech_by_sasl_name (server) failed");
114 server_to_client = data_blob(NULL, 0);
116 do {
117 /* Do a client-server update dance */
118 status = gensec_update(gensec_client_context, tmp_ctx, server_to_client, &client_to_server);
119 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {;
120 torture_assert_ntstatus_ok(tctx, status, "gensec_update (client) failed");
123 status = gensec_update(gensec_server_context, tmp_ctx, client_to_server, &server_to_client);
124 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {;
125 torture_assert_ntstatus_ok(tctx, status, "gensec_update (server) failed");
128 if (NT_STATUS_IS_OK(status)) {
129 break;
131 } while (1);
133 /* Extract the PAC using Samba's code */
135 status = gensec_session_info(gensec_server_context, &session_info);
136 torture_assert_ntstatus_ok(tctx, status, "gensec_session_info failed");
138 pac_wrapped_struct.ChecksumLength = session_info->server_info->pac_srv_sig.signature.length;
139 pac_wrapped_struct.SignatureType = session_info->server_info->pac_kdc_sig.type;
140 pac_wrapped_struct.SignatureLength = session_info->server_info->pac_kdc_sig.signature.length;
141 pac_wrapped_struct.ChecksumAndSignature = payload
142 = data_blob_talloc(tmp_ctx, NULL,
143 pac_wrapped_struct.ChecksumLength
144 + pac_wrapped_struct.SignatureLength);
145 memcpy(&payload.data[0],
146 session_info->server_info->pac_srv_sig.signature.data,
147 pac_wrapped_struct.ChecksumLength);
148 memcpy(&payload.data[pac_wrapped_struct.ChecksumLength],
149 session_info->server_info->pac_kdc_sig.signature.data,
150 pac_wrapped_struct.SignatureLength);
152 ndr_err = ndr_push_struct_blob(&pac_wrapped, tmp_ctx, &pac_wrapped_struct,
153 (ndr_push_flags_fn_t)ndr_push_PAC_Validate);
154 torture_assert(tctx, NDR_ERR_CODE_IS_SUCCESS(ndr_err), "ndr_push_struct_blob of PACValidate structure failed");
156 torture_assert(tctx, (creds->negotiate_flags & NETLOGON_NEG_ARCFOUR), "not willing to even try a PACValidate without RC4 encryption");
157 netlogon_creds_arcfour_crypt(creds, pac_wrapped.data, pac_wrapped.length);
159 generic.length = pac_wrapped.length;
160 generic.data = pac_wrapped.data;
162 /* Validate it over the netlogon pipe */
164 generic.identity_info.parameter_control = 0;
165 generic.identity_info.logon_id_high = 0;
166 generic.identity_info.logon_id_low = 0;
167 generic.identity_info.domain_name.string = session_info->server_info->domain_name;
168 generic.identity_info.account_name.string = session_info->server_info->account_name;
169 generic.identity_info.workstation.string = test_machine_name;
171 generic.package_name.string = "Kerberos";
173 logon.generic = &generic;
175 ZERO_STRUCT(auth2);
176 netlogon_creds_client_authenticator(creds, &auth);
177 r.in.credential = &auth;
178 r.in.return_authenticator = &auth2;
179 r.in.logon = &logon;
180 r.in.logon_level = NetlogonGenericInformation;
181 r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
182 r.in.computer_name = cli_credentials_get_workstation(credentials);
183 r.in.validation_level = NetlogonValidationGenericInfo2;
184 r.out.validation = &validation;
185 r.out.authoritative = &authoritative;
186 r.out.return_authenticator = &return_authenticator;
188 torture_assert_ntstatus_ok(tctx, dcerpc_netr_LogonSamLogon_r(b, tctx, &r),
189 "LogonSamLogon failed");
191 torture_assert_ntstatus_ok(tctx, r.out.result, "LogonSamLogon failed");
193 /* This will break the signature nicely (even in the crypto wrapping), check we get a logon failure */
194 generic.data[generic.length-1]++;
196 logon.generic = &generic;
198 ZERO_STRUCT(auth2);
199 netlogon_creds_client_authenticator(creds, &auth);
200 r.in.credential = &auth;
201 r.in.return_authenticator = &auth2;
202 r.in.logon_level = NetlogonGenericInformation;
203 r.in.logon = &logon;
204 r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
205 r.in.computer_name = cli_credentials_get_workstation(credentials);
206 r.in.validation_level = NetlogonValidationGenericInfo2;
208 torture_assert_ntstatus_ok(tctx, dcerpc_netr_LogonSamLogon_r(b, tctx, &r),
209 "LogonSamLogon failed");
211 torture_assert_ntstatus_equal(tctx, r.out.result, NT_STATUS_LOGON_FAILURE, "LogonSamLogon failed");
213 torture_assert(tctx, netlogon_creds_client_check(creds, &r.out.return_authenticator->cred),
214 "Credential chaining failed");
216 /* This will break the parsing nicely (even in the crypto wrapping), check we get INVALID_PARAMETER */
217 generic.length--;
219 logon.generic = &generic;
221 ZERO_STRUCT(auth2);
222 netlogon_creds_client_authenticator(creds, &auth);
223 r.in.credential = &auth;
224 r.in.return_authenticator = &auth2;
225 r.in.logon_level = NetlogonGenericInformation;
226 r.in.logon = &logon;
227 r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
228 r.in.computer_name = cli_credentials_get_workstation(credentials);
229 r.in.validation_level = NetlogonValidationGenericInfo2;
231 torture_assert_ntstatus_ok(tctx, dcerpc_netr_LogonSamLogon_r(b, tctx, &r),
232 "LogonSamLogon failed");
234 torture_assert_ntstatus_equal(tctx, r.out.result, NT_STATUS_INVALID_PARAMETER, "LogonSamLogon failed");
236 torture_assert(tctx, netlogon_creds_client_check(creds,
237 &r.out.return_authenticator->cred),
238 "Credential chaining failed");
240 pac_wrapped_struct.ChecksumLength = session_info->server_info->pac_srv_sig.signature.length;
241 pac_wrapped_struct.SignatureType = session_info->server_info->pac_kdc_sig.type;
243 /* Break the SignatureType */
244 pac_wrapped_struct.SignatureType++;
246 pac_wrapped_struct.SignatureLength = session_info->server_info->pac_kdc_sig.signature.length;
247 pac_wrapped_struct.ChecksumAndSignature = payload
248 = data_blob_talloc(tmp_ctx, NULL,
249 pac_wrapped_struct.ChecksumLength
250 + pac_wrapped_struct.SignatureLength);
251 memcpy(&payload.data[0],
252 session_info->server_info->pac_srv_sig.signature.data,
253 pac_wrapped_struct.ChecksumLength);
254 memcpy(&payload.data[pac_wrapped_struct.ChecksumLength],
255 session_info->server_info->pac_kdc_sig.signature.data,
256 pac_wrapped_struct.SignatureLength);
258 ndr_err = ndr_push_struct_blob(&pac_wrapped, tmp_ctx, &pac_wrapped_struct,
259 (ndr_push_flags_fn_t)ndr_push_PAC_Validate);
260 torture_assert(tctx, NDR_ERR_CODE_IS_SUCCESS(ndr_err), "ndr_push_struct_blob of PACValidate structure failed");
262 torture_assert(tctx, (creds->negotiate_flags & NETLOGON_NEG_ARCFOUR), "not willing to even try a PACValidate without RC4 encryption");
263 netlogon_creds_arcfour_crypt(creds, pac_wrapped.data, pac_wrapped.length);
265 generic.length = pac_wrapped.length;
266 generic.data = pac_wrapped.data;
268 logon.generic = &generic;
270 ZERO_STRUCT(auth2);
271 netlogon_creds_client_authenticator(creds, &auth);
272 r.in.credential = &auth;
273 r.in.return_authenticator = &auth2;
274 r.in.logon_level = NetlogonGenericInformation;
275 r.in.logon = &logon;
276 r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
277 r.in.computer_name = cli_credentials_get_workstation(credentials);
278 r.in.validation_level = NetlogonValidationGenericInfo2;
280 torture_assert_ntstatus_ok(tctx, dcerpc_netr_LogonSamLogon_r(b, tctx, &r),
281 "LogonSamLogon failed");
283 torture_assert_ntstatus_equal(tctx, r.out.result, NT_STATUS_LOGON_FAILURE, "LogonSamLogon failed");
285 torture_assert(tctx, netlogon_creds_client_check(creds, &r.out.return_authenticator->cred),
286 "Credential chaining failed");
288 pac_wrapped_struct.ChecksumLength = session_info->server_info->pac_srv_sig.signature.length;
289 pac_wrapped_struct.SignatureType = session_info->server_info->pac_kdc_sig.type;
290 pac_wrapped_struct.SignatureLength = session_info->server_info->pac_kdc_sig.signature.length;
292 pac_wrapped_struct.ChecksumAndSignature = payload
293 = data_blob_talloc(tmp_ctx, NULL,
294 pac_wrapped_struct.ChecksumLength
295 + pac_wrapped_struct.SignatureLength);
296 memcpy(&payload.data[0],
297 session_info->server_info->pac_srv_sig.signature.data,
298 pac_wrapped_struct.ChecksumLength);
299 memcpy(&payload.data[pac_wrapped_struct.ChecksumLength],
300 session_info->server_info->pac_kdc_sig.signature.data,
301 pac_wrapped_struct.SignatureLength);
303 /* Break the signature length */
304 pac_wrapped_struct.SignatureLength++;
306 ndr_err = ndr_push_struct_blob(&pac_wrapped, tmp_ctx, &pac_wrapped_struct,
307 (ndr_push_flags_fn_t)ndr_push_PAC_Validate);
308 torture_assert(tctx, NDR_ERR_CODE_IS_SUCCESS(ndr_err), "ndr_push_struct_blob of PACValidate structure failed");
310 torture_assert(tctx, (creds->negotiate_flags & NETLOGON_NEG_ARCFOUR), "not willing to even try a PACValidate without RC4 encryption");
311 netlogon_creds_arcfour_crypt(creds, pac_wrapped.data, pac_wrapped.length);
313 generic.length = pac_wrapped.length;
314 generic.data = pac_wrapped.data;
316 logon.generic = &generic;
318 ZERO_STRUCT(auth2);
319 netlogon_creds_client_authenticator(creds, &auth);
320 r.in.credential = &auth;
321 r.in.return_authenticator = &auth2;
322 r.in.logon_level = NetlogonGenericInformation;
323 r.in.logon = &logon;
324 r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
325 r.in.computer_name = cli_credentials_get_workstation(credentials);
326 r.in.validation_level = NetlogonValidationGenericInfo2;
328 torture_assert_ntstatus_ok(tctx, dcerpc_netr_LogonSamLogon_r(b, tctx, &r),
329 "LogonSamLogon failed");
331 torture_assert_ntstatus_equal(tctx, r.out.result, NT_STATUS_INVALID_PARAMETER, "LogonSamLogon failed");
333 torture_assert(tctx, netlogon_creds_client_check(creds, &r.out.return_authenticator->cred),
334 "Credential chaining failed");
336 return true;
339 static bool test_PACVerify_bdc(struct torture_context *tctx,
340 struct dcerpc_pipe *p,
341 struct cli_credentials *credentials)
343 return test_PACVerify(tctx, p, credentials, SEC_CHAN_BDC, TEST_MACHINE_NAME_BDC);
346 static bool test_PACVerify_workstation(struct torture_context *tctx,
347 struct dcerpc_pipe *p,
348 struct cli_credentials *credentials)
350 return test_PACVerify(tctx, p, credentials, SEC_CHAN_WKSTA, TEST_MACHINE_NAME_WKSTA);
353 static bool test_PACVerify_workstation_des(struct torture_context *tctx,
354 struct dcerpc_pipe *p, struct cli_credentials *credentials, struct test_join *join_ctx)
356 struct samr_SetUserInfo r;
357 union samr_UserInfo user_info;
358 struct dcerpc_pipe *samr_pipe = torture_join_samr_pipe(join_ctx);
359 struct smb_krb5_context *smb_krb5_context;
360 krb5_error_code ret;
362 ret = cli_credentials_get_krb5_context(cmdline_credentials, tctx->lp_ctx, &smb_krb5_context);
363 torture_assert_int_equal(tctx, ret, 0, "cli_credentials_get_krb5_context() failed");
365 if (krb5_config_get_bool_default(smb_krb5_context->krb5_context, NULL, FALSE,
366 "libdefaults",
367 "allow_weak_crypto", NULL) == FALSE) {
368 torture_skip(tctx, "Cannot test DES without [libdefaults] allow_weak_crypto = yes");
371 /* Mark this workstation with DES-only */
372 user_info.info16.acct_flags = ACB_USE_DES_KEY_ONLY | ACB_WSTRUST;
373 r.in.user_handle = torture_join_samr_user_policy(join_ctx);
374 r.in.level = 16;
375 r.in.info = &user_info;
377 torture_assert_ntstatus_ok(tctx, dcerpc_samr_SetUserInfo_r(samr_pipe->binding_handle, tctx, &r),
378 "failed to set DES info account flags");
379 torture_assert_ntstatus_ok(tctx, r.out.result,
380 "failed to set DES into account flags");
382 return test_PACVerify(tctx, p, credentials, SEC_CHAN_WKSTA, TEST_MACHINE_NAME_WKSTA_DES);
386 /* Check various ways to get the PAC, in particular check the group membership and other details between the PAC from a normal kinit, S2U4Self and a SamLogon */
387 static bool test_S2U4Self(struct torture_context *tctx,
388 struct dcerpc_pipe *p,
389 struct cli_credentials *credentials,
390 enum netr_SchannelType secure_channel_type,
391 const char *test_machine_name)
393 NTSTATUS status;
394 struct dcerpc_binding_handle *b = p->binding_handle;
396 struct netr_LogonSamLogon r;
398 union netr_LogonLevel logon;
399 union netr_Validation validation;
400 uint8_t authoritative;
402 struct netr_Authenticator auth, auth2;
404 DATA_BLOB client_to_server, server_to_client;
406 struct netlogon_creds_CredentialState *creds;
407 struct gensec_security *gensec_client_context;
408 struct gensec_security *gensec_server_context;
410 struct auth_session_info *kinit_session_info;
411 struct auth_session_info *s2u4self_session_info;
412 struct auth_serversupplied_info *netlogon_server_info;
414 struct netr_NetworkInfo ninfo;
415 DATA_BLOB names_blob, chal, lm_resp, nt_resp;
416 size_t i;
417 int flags = CLI_CRED_NTLMv2_AUTH;
419 struct dom_sid *builtin_domain;
421 char *tmp_dir;
423 TALLOC_CTX *tmp_ctx = talloc_new(tctx);
425 torture_assert(tctx, tmp_ctx != NULL, "talloc_new() failed");
427 /* First, do a normal Kerberos connection */
429 status = torture_temp_dir(tctx, "S2U4Self", &tmp_dir);
430 torture_assert_ntstatus_ok(tctx, status, "torture_temp_dir failed");
432 status = gensec_client_start(tctx, &gensec_client_context, tctx->ev,
433 lpcfg_gensec_settings(tctx, tctx->lp_ctx));
434 torture_assert_ntstatus_ok(tctx, status, "gensec_client_start (client) failed");
436 status = gensec_set_target_hostname(gensec_client_context, test_machine_name);
438 status = gensec_set_credentials(gensec_client_context, cmdline_credentials);
439 torture_assert_ntstatus_ok(tctx, status, "gensec_set_credentials (client) failed");
441 status = gensec_start_mech_by_sasl_name(gensec_client_context, "GSSAPI");
442 torture_assert_ntstatus_ok(tctx, status, "gensec_start_mech_by_sasl_name (client) failed");
444 status = gensec_server_start(tctx, tctx->ev,
445 lpcfg_gensec_settings(tctx, tctx->lp_ctx),
446 NULL, &gensec_server_context);
447 torture_assert_ntstatus_ok(tctx, status, "gensec_server_start (server) failed");
449 status = gensec_set_credentials(gensec_server_context, credentials);
450 torture_assert_ntstatus_ok(tctx, status, "gensec_set_credentials (server) failed");
452 status = gensec_start_mech_by_sasl_name(gensec_server_context, "GSSAPI");
453 torture_assert_ntstatus_ok(tctx, status, "gensec_start_mech_by_sasl_name (server) failed");
455 server_to_client = data_blob(NULL, 0);
457 do {
458 /* Do a client-server update dance */
459 status = gensec_update(gensec_client_context, tmp_ctx, server_to_client, &client_to_server);
460 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {;
461 torture_assert_ntstatus_ok(tctx, status, "gensec_update (client) failed");
464 status = gensec_update(gensec_server_context, tmp_ctx, client_to_server, &server_to_client);
465 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {;
466 torture_assert_ntstatus_ok(tctx, status, "gensec_update (server) failed");
469 if (NT_STATUS_IS_OK(status)) {
470 break;
472 } while (1);
474 /* Extract the PAC using Samba's code */
476 status = gensec_session_info(gensec_server_context, &kinit_session_info);
477 torture_assert_ntstatus_ok(tctx, status, "gensec_session_info failed");
480 /* Now do the dance with S2U4Self */
482 /* Wipe out any existing ccache */
483 cli_credentials_invalidate_ccache(credentials, CRED_SPECIFIED);
484 cli_credentials_set_target_service(credentials, talloc_asprintf(tmp_ctx, "host/%s", test_machine_name));
485 cli_credentials_set_impersonate_principal(credentials, cli_credentials_get_principal(cmdline_credentials, tmp_ctx));
487 status = gensec_client_start(tctx, &gensec_client_context, tctx->ev,
488 lpcfg_gensec_settings(tctx, tctx->lp_ctx));
489 torture_assert_ntstatus_ok(tctx, status, "gensec_client_start (client) failed");
491 status = gensec_set_target_hostname(gensec_client_context, test_machine_name);
493 /* We now set the same credentials on both client and server contexts */
494 status = gensec_set_credentials(gensec_client_context, credentials);
495 torture_assert_ntstatus_ok(tctx, status, "gensec_set_credentials (client) failed");
497 status = gensec_start_mech_by_sasl_name(gensec_client_context, "GSSAPI");
498 torture_assert_ntstatus_ok(tctx, status, "gensec_start_mech_by_sasl_name (client) failed");
500 status = gensec_server_start(tctx, tctx->ev,
501 lpcfg_gensec_settings(tctx, tctx->lp_ctx),
502 NULL, &gensec_server_context);
503 torture_assert_ntstatus_ok(tctx, status, "gensec_server_start (server) failed");
505 status = gensec_set_credentials(gensec_server_context, credentials);
506 torture_assert_ntstatus_ok(tctx, status, "gensec_set_credentials (server) failed");
508 status = gensec_start_mech_by_sasl_name(gensec_server_context, "GSSAPI");
509 torture_assert_ntstatus_ok(tctx, status, "gensec_start_mech_by_sasl_name (server) failed");
511 server_to_client = data_blob(NULL, 0);
513 do {
514 /* Do a client-server update dance */
515 status = gensec_update(gensec_client_context, tmp_ctx, server_to_client, &client_to_server);
516 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {;
517 torture_assert_ntstatus_ok(tctx, status, "gensec_update (client) failed");
520 status = gensec_update(gensec_server_context, tmp_ctx, client_to_server, &server_to_client);
521 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {;
522 torture_assert_ntstatus_ok(tctx, status, "gensec_update (server) failed");
525 if (NT_STATUS_IS_OK(status)) {
526 break;
528 } while (1);
530 /* Don't pollute the remaining tests with the changed credentials */
531 cli_credentials_invalidate_ccache(credentials, CRED_SPECIFIED);
532 cli_credentials_set_target_service(credentials, NULL);
533 cli_credentials_set_impersonate_principal(credentials, NULL);
535 /* Extract the PAC using Samba's code */
537 status = gensec_session_info(gensec_server_context, &s2u4self_session_info);
538 torture_assert_ntstatus_ok(tctx, status, "gensec_session_info failed");
540 cli_credentials_get_ntlm_username_domain(cmdline_credentials, tctx,
541 &ninfo.identity_info.account_name.string,
542 &ninfo.identity_info.domain_name.string);
544 /* Now try with SamLogon */
545 generate_random_buffer(ninfo.challenge,
546 sizeof(ninfo.challenge));
547 chal = data_blob_const(ninfo.challenge,
548 sizeof(ninfo.challenge));
550 names_blob = NTLMv2_generate_names_blob(tctx, cli_credentials_get_workstation(credentials),
551 cli_credentials_get_domain(credentials));
553 status = cli_credentials_get_ntlm_response(cmdline_credentials, tctx,
554 &flags,
555 chal,
556 names_blob,
557 &lm_resp, &nt_resp,
558 NULL, NULL);
559 torture_assert_ntstatus_ok(tctx, status, "cli_credentials_get_ntlm_response failed");
561 ninfo.lm.data = lm_resp.data;
562 ninfo.lm.length = lm_resp.length;
564 ninfo.nt.data = nt_resp.data;
565 ninfo.nt.length = nt_resp.length;
567 ninfo.identity_info.parameter_control = 0;
568 ninfo.identity_info.logon_id_low = 0;
569 ninfo.identity_info.logon_id_high = 0;
570 ninfo.identity_info.workstation.string = cli_credentials_get_workstation(credentials);
572 logon.network = &ninfo;
574 r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
575 r.in.computer_name = cli_credentials_get_workstation(credentials);
576 r.in.credential = &auth;
577 r.in.return_authenticator = &auth2;
578 r.in.logon_level = 2;
579 r.in.logon = &logon;
580 r.out.validation = &validation;
581 r.out.authoritative = &authoritative;
583 if (!test_SetupCredentials2(p, tctx, NETLOGON_NEG_AUTH2_ADS_FLAGS,
584 credentials, secure_channel_type,
585 &creds)) {
586 return false;
589 ZERO_STRUCT(auth2);
590 netlogon_creds_client_authenticator(creds, &auth);
592 r.in.validation_level = 3;
594 status = dcerpc_netr_LogonSamLogon_r(b, tctx, &r);
595 torture_assert_ntstatus_ok(tctx, status, "LogonSamLogon failed");
597 torture_assert(tctx, netlogon_creds_client_check(creds,
598 &r.out.return_authenticator->cred),
599 "Credential chaining failed");
601 status = make_server_info_netlogon_validation(tmp_ctx,
602 ninfo.identity_info.account_name.string,
603 r.in.validation_level,
604 r.out.validation,
605 &netlogon_server_info);
607 torture_assert_ntstatus_ok(tctx, status, "make_server_info_netlogon_validation failed");
609 torture_assert_str_equal(tctx, netlogon_server_info->account_name == NULL ? "" : netlogon_server_info->account_name,
610 kinit_session_info->server_info->account_name, "Account name differs for kinit-based PAC");
611 torture_assert_str_equal(tctx,netlogon_server_info->account_name == NULL ? "" : netlogon_server_info->account_name,
612 s2u4self_session_info->server_info->account_name, "Account name differs for S2U4Self");
613 torture_assert_str_equal(tctx, netlogon_server_info->full_name == NULL ? "" : netlogon_server_info->full_name, kinit_session_info->server_info->full_name, "Full name differs for kinit-based PAC");
614 torture_assert_str_equal(tctx, netlogon_server_info->full_name == NULL ? "" : netlogon_server_info->full_name, s2u4self_session_info->server_info->full_name, "Full name differs for S2U4Self");
615 torture_assert(tctx, dom_sid_equal(netlogon_server_info->account_sid, kinit_session_info->server_info->account_sid), "Account SID differs for kinit-based PAC");
616 torture_assert(tctx, dom_sid_equal(netlogon_server_info->primary_group_sid, kinit_session_info->server_info->primary_group_sid), "Primary Group SID differs for kinit-based PAC");
617 torture_assert(tctx, dom_sid_equal(netlogon_server_info->account_sid, s2u4self_session_info->server_info->account_sid), "Account SID differs for S2U4Self");
618 torture_assert(tctx, dom_sid_equal(netlogon_server_info->primary_group_sid, s2u4self_session_info->server_info->primary_group_sid), "Primary Group SID differs for S2U4Self");
619 torture_assert_int_equal(tctx, netlogon_server_info->n_domain_groups, kinit_session_info->server_info->n_domain_groups, "Different numbers of domain groups for kinit-based PAC");
620 torture_assert_int_equal(tctx, netlogon_server_info->n_domain_groups, s2u4self_session_info->server_info->n_domain_groups, "Different numbers of domain groups for S2U4Self");
622 builtin_domain = dom_sid_parse_talloc(tmp_ctx, SID_BUILTIN);
624 for (i = 0; i < kinit_session_info->server_info->n_domain_groups; i++) {
625 torture_assert(tctx, dom_sid_equal(netlogon_server_info->domain_groups[i], kinit_session_info->server_info->domain_groups[i]), "Different domain groups for kinit-based PAC");
626 torture_assert(tctx, dom_sid_equal(netlogon_server_info->domain_groups[i], s2u4self_session_info->server_info->domain_groups[i]), "Different domain groups for S2U4Self");
627 torture_assert(tctx, !dom_sid_in_domain(builtin_domain, s2u4self_session_info->server_info->domain_groups[i]), "Returned BUILTIN domain in groups for S2U4Self");
628 torture_assert(tctx, !dom_sid_in_domain(builtin_domain, kinit_session_info->server_info->domain_groups[i]), "Returned BUILTIN domain in groups kinit-based PAC");
629 torture_assert(tctx, !dom_sid_in_domain(builtin_domain, netlogon_server_info->domain_groups[i]), "Returned BUILTIN domian in groups from NETLOGON SamLogon reply");
632 return true;
635 static bool test_S2U4Self_bdc(struct torture_context *tctx,
636 struct dcerpc_pipe *p,
637 struct cli_credentials *credentials)
639 return test_S2U4Self(tctx, p, credentials, SEC_CHAN_BDC, TEST_MACHINE_NAME_S2U4SELF_BDC);
642 static bool test_S2U4Self_workstation(struct torture_context *tctx,
643 struct dcerpc_pipe *p,
644 struct cli_credentials *credentials)
646 return test_S2U4Self(tctx, p, credentials, SEC_CHAN_WKSTA, TEST_MACHINE_NAME_S2U4SELF_WKSTA);
649 struct torture_suite *torture_rpc_remote_pac(TALLOC_CTX *mem_ctx)
651 struct torture_suite *suite = torture_suite_create(mem_ctx, "pac");
652 struct torture_rpc_tcase *tcase;
654 /* It is important to use different names, so that old entries in our credential cache are not used */
655 tcase = torture_suite_add_machine_bdc_rpc_iface_tcase(suite, "netlogon-bdc",
656 &ndr_table_netlogon, TEST_MACHINE_NAME_BDC);
657 torture_rpc_tcase_add_test_creds(tcase, "verify-sig", test_PACVerify_bdc);
659 tcase = torture_suite_add_machine_workstation_rpc_iface_tcase(suite, "netlogon-member",
660 &ndr_table_netlogon, TEST_MACHINE_NAME_WKSTA);
661 torture_rpc_tcase_add_test_creds(tcase, "verify-sig", test_PACVerify_workstation);
663 tcase = torture_suite_add_machine_workstation_rpc_iface_tcase(suite, "netlogon-member-des",
664 &ndr_table_netlogon, TEST_MACHINE_NAME_WKSTA_DES);
665 torture_rpc_tcase_add_test_join(tcase, "verify-sig", test_PACVerify_workstation_des);
667 tcase = torture_suite_add_machine_bdc_rpc_iface_tcase(suite, "netlogon-bdc",
668 &ndr_table_netlogon, TEST_MACHINE_NAME_S2U4SELF_BDC);
669 torture_rpc_tcase_add_test_creds(tcase, "s2u4self", test_S2U4Self_bdc);
671 tcase = torture_suite_add_machine_workstation_rpc_iface_tcase(suite, "netlogon-member",
672 &ndr_table_netlogon, TEST_MACHINE_NAME_S2U4SELF_WKSTA);
674 torture_rpc_tcase_add_test_creds(tcase, "s2u4self", test_S2U4Self_workstation);
675 return suite;