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/>.
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)
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 struct dcerpc_binding_handle *b = p->binding_handle;
78 TALLOC_CTX *tmp_ctx = talloc_new(tctx);
79 torture_assert(tctx, tmp_ctx != NULL, "talloc_new() failed");
81 if (!test_SetupCredentials2(p, tctx, NETLOGON_NEG_AUTH2_ADS_FLAGS,
82 credentials, secure_channel_type,
87 status = gensec_client_start(tctx, &gensec_client_context, tctx->ev,
88 lpcfg_gensec_settings(tctx, tctx->lp_ctx));
89 torture_assert_ntstatus_ok(tctx, status, "gensec_client_start (client) failed");
91 status = gensec_set_target_hostname(gensec_client_context, test_machine_name);
93 status = gensec_set_credentials(gensec_client_context, cmdline_credentials);
94 torture_assert_ntstatus_ok(tctx, status, "gensec_set_credentials (client) failed");
96 status = gensec_start_mech_by_sasl_name(gensec_client_context, "GSSAPI");
97 torture_assert_ntstatus_ok(tctx, status, "gensec_start_mech_by_sasl_name (client) failed");
99 status = gensec_server_start(tctx, tctx->ev,
100 lpcfg_gensec_settings(tctx, tctx->lp_ctx),
101 NULL, &gensec_server_context);
102 torture_assert_ntstatus_ok(tctx, status, "gensec_server_start (server) failed");
104 status = gensec_set_credentials(gensec_server_context, credentials);
105 torture_assert_ntstatus_ok(tctx, status, "gensec_set_credentials (server) failed");
107 status = gensec_start_mech_by_sasl_name(gensec_server_context, "GSSAPI");
108 torture_assert_ntstatus_ok(tctx, status, "gensec_start_mech_by_sasl_name (server) failed");
110 server_to_client = data_blob(NULL, 0);
113 /* Do a client-server update dance */
114 status = gensec_update(gensec_client_context, tmp_ctx, server_to_client, &client_to_server);
115 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {;
116 torture_assert_ntstatus_ok(tctx, status, "gensec_update (client) failed");
119 status = gensec_update(gensec_server_context, tmp_ctx, client_to_server, &server_to_client);
120 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {;
121 torture_assert_ntstatus_ok(tctx, status, "gensec_update (server) failed");
124 if (NT_STATUS_IS_OK(status)) {
129 /* Extract the PAC using Samba's code */
131 status = gensec_session_info(gensec_server_context, &session_info);
132 torture_assert_ntstatus_ok(tctx, status, "gensec_session_info failed");
134 pac_wrapped_struct.ChecksumLength = session_info->server_info->pac_srv_sig.signature.length;
135 pac_wrapped_struct.SignatureType = session_info->server_info->pac_kdc_sig.type;
136 pac_wrapped_struct.SignatureLength = session_info->server_info->pac_kdc_sig.signature.length;
137 pac_wrapped_struct.ChecksumAndSignature = payload
138 = data_blob_talloc(tmp_ctx, NULL,
139 pac_wrapped_struct.ChecksumLength
140 + pac_wrapped_struct.SignatureLength);
141 memcpy(&payload.data[0],
142 session_info->server_info->pac_srv_sig.signature.data,
143 pac_wrapped_struct.ChecksumLength);
144 memcpy(&payload.data[pac_wrapped_struct.ChecksumLength],
145 session_info->server_info->pac_kdc_sig.signature.data,
146 pac_wrapped_struct.SignatureLength);
148 ndr_err = ndr_push_struct_blob(&pac_wrapped, tmp_ctx, &pac_wrapped_struct,
149 (ndr_push_flags_fn_t)ndr_push_PAC_Validate);
150 torture_assert(tctx, NDR_ERR_CODE_IS_SUCCESS(ndr_err), "ndr_push_struct_blob of PACValidate structure failed");
152 torture_assert(tctx, (creds->negotiate_flags & NETLOGON_NEG_ARCFOUR), "not willing to even try a PACValidate without RC4 encryption");
153 netlogon_creds_arcfour_crypt(creds, pac_wrapped.data, pac_wrapped.length);
155 generic.length = pac_wrapped.length;
156 generic.data = pac_wrapped.data;
158 /* Validate it over the netlogon pipe */
160 generic.identity_info.parameter_control = 0;
161 generic.identity_info.logon_id_high = 0;
162 generic.identity_info.logon_id_low = 0;
163 generic.identity_info.domain_name.string = session_info->server_info->domain_name;
164 generic.identity_info.account_name.string = session_info->server_info->account_name;
165 generic.identity_info.workstation.string = test_machine_name;
167 generic.package_name.string = "Kerberos";
169 logon.generic = &generic;
172 netlogon_creds_client_authenticator(creds, &auth);
173 r.in.credential = &auth;
174 r.in.return_authenticator = &auth2;
176 r.in.logon_level = NetlogonGenericInformation;
177 r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
178 r.in.computer_name = cli_credentials_get_workstation(credentials);
179 r.in.validation_level = NetlogonValidationGenericInfo2;
180 r.out.validation = &validation;
181 r.out.authoritative = &authoritative;
182 r.out.return_authenticator = &return_authenticator;
184 torture_assert_ntstatus_ok(tctx, dcerpc_netr_LogonSamLogon_r(b, tctx, &r),
185 "LogonSamLogon failed");
187 torture_assert_ntstatus_ok(tctx, r.out.result, "LogonSamLogon failed");
189 /* This will break the signature nicely (even in the crypto wrapping), check we get a logon failure */
190 generic.data[generic.length-1]++;
192 logon.generic = &generic;
195 netlogon_creds_client_authenticator(creds, &auth);
196 r.in.credential = &auth;
197 r.in.return_authenticator = &auth2;
198 r.in.logon_level = NetlogonGenericInformation;
200 r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
201 r.in.computer_name = cli_credentials_get_workstation(credentials);
202 r.in.validation_level = NetlogonValidationGenericInfo2;
204 torture_assert_ntstatus_ok(tctx, dcerpc_netr_LogonSamLogon_r(b, tctx, &r),
205 "LogonSamLogon failed");
207 torture_assert_ntstatus_equal(tctx, r.out.result, NT_STATUS_LOGON_FAILURE, "LogonSamLogon failed");
209 torture_assert(tctx, netlogon_creds_client_check(creds, &r.out.return_authenticator->cred),
210 "Credential chaining failed");
212 /* This will break the parsing nicely (even in the crypto wrapping), check we get INVALID_PARAMETER */
215 logon.generic = &generic;
218 netlogon_creds_client_authenticator(creds, &auth);
219 r.in.credential = &auth;
220 r.in.return_authenticator = &auth2;
221 r.in.logon_level = NetlogonGenericInformation;
223 r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
224 r.in.computer_name = cli_credentials_get_workstation(credentials);
225 r.in.validation_level = NetlogonValidationGenericInfo2;
227 torture_assert_ntstatus_ok(tctx, dcerpc_netr_LogonSamLogon_r(b, tctx, &r),
228 "LogonSamLogon failed");
230 torture_assert_ntstatus_equal(tctx, r.out.result, NT_STATUS_INVALID_PARAMETER, "LogonSamLogon failed");
232 torture_assert(tctx, netlogon_creds_client_check(creds,
233 &r.out.return_authenticator->cred),
234 "Credential chaining failed");
236 pac_wrapped_struct.ChecksumLength = session_info->server_info->pac_srv_sig.signature.length;
237 pac_wrapped_struct.SignatureType = session_info->server_info->pac_kdc_sig.type;
239 /* Break the SignatureType */
240 pac_wrapped_struct.SignatureType++;
242 pac_wrapped_struct.SignatureLength = session_info->server_info->pac_kdc_sig.signature.length;
243 pac_wrapped_struct.ChecksumAndSignature = payload
244 = data_blob_talloc(tmp_ctx, NULL,
245 pac_wrapped_struct.ChecksumLength
246 + pac_wrapped_struct.SignatureLength);
247 memcpy(&payload.data[0],
248 session_info->server_info->pac_srv_sig.signature.data,
249 pac_wrapped_struct.ChecksumLength);
250 memcpy(&payload.data[pac_wrapped_struct.ChecksumLength],
251 session_info->server_info->pac_kdc_sig.signature.data,
252 pac_wrapped_struct.SignatureLength);
254 ndr_err = ndr_push_struct_blob(&pac_wrapped, tmp_ctx, &pac_wrapped_struct,
255 (ndr_push_flags_fn_t)ndr_push_PAC_Validate);
256 torture_assert(tctx, NDR_ERR_CODE_IS_SUCCESS(ndr_err), "ndr_push_struct_blob of PACValidate structure failed");
258 torture_assert(tctx, (creds->negotiate_flags & NETLOGON_NEG_ARCFOUR), "not willing to even try a PACValidate without RC4 encryption");
259 netlogon_creds_arcfour_crypt(creds, pac_wrapped.data, pac_wrapped.length);
261 generic.length = pac_wrapped.length;
262 generic.data = pac_wrapped.data;
264 logon.generic = &generic;
267 netlogon_creds_client_authenticator(creds, &auth);
268 r.in.credential = &auth;
269 r.in.return_authenticator = &auth2;
270 r.in.logon_level = NetlogonGenericInformation;
272 r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
273 r.in.computer_name = cli_credentials_get_workstation(credentials);
274 r.in.validation_level = NetlogonValidationGenericInfo2;
276 torture_assert_ntstatus_ok(tctx, dcerpc_netr_LogonSamLogon_r(b, tctx, &r),
277 "LogonSamLogon failed");
279 torture_assert_ntstatus_equal(tctx, r.out.result, NT_STATUS_LOGON_FAILURE, "LogonSamLogon failed");
281 torture_assert(tctx, netlogon_creds_client_check(creds, &r.out.return_authenticator->cred),
282 "Credential chaining failed");
284 pac_wrapped_struct.ChecksumLength = session_info->server_info->pac_srv_sig.signature.length;
285 pac_wrapped_struct.SignatureType = session_info->server_info->pac_kdc_sig.type;
286 pac_wrapped_struct.SignatureLength = session_info->server_info->pac_kdc_sig.signature.length;
288 pac_wrapped_struct.ChecksumAndSignature = payload
289 = data_blob_talloc(tmp_ctx, NULL,
290 pac_wrapped_struct.ChecksumLength
291 + pac_wrapped_struct.SignatureLength);
292 memcpy(&payload.data[0],
293 session_info->server_info->pac_srv_sig.signature.data,
294 pac_wrapped_struct.ChecksumLength);
295 memcpy(&payload.data[pac_wrapped_struct.ChecksumLength],
296 session_info->server_info->pac_kdc_sig.signature.data,
297 pac_wrapped_struct.SignatureLength);
299 /* Break the signature length */
300 pac_wrapped_struct.SignatureLength++;
302 ndr_err = ndr_push_struct_blob(&pac_wrapped, tmp_ctx, &pac_wrapped_struct,
303 (ndr_push_flags_fn_t)ndr_push_PAC_Validate);
304 torture_assert(tctx, NDR_ERR_CODE_IS_SUCCESS(ndr_err), "ndr_push_struct_blob of PACValidate structure failed");
306 torture_assert(tctx, (creds->negotiate_flags & NETLOGON_NEG_ARCFOUR), "not willing to even try a PACValidate without RC4 encryption");
307 netlogon_creds_arcfour_crypt(creds, pac_wrapped.data, pac_wrapped.length);
309 generic.length = pac_wrapped.length;
310 generic.data = pac_wrapped.data;
312 logon.generic = &generic;
315 netlogon_creds_client_authenticator(creds, &auth);
316 r.in.credential = &auth;
317 r.in.return_authenticator = &auth2;
318 r.in.logon_level = NetlogonGenericInformation;
320 r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
321 r.in.computer_name = cli_credentials_get_workstation(credentials);
322 r.in.validation_level = NetlogonValidationGenericInfo2;
324 torture_assert_ntstatus_ok(tctx, dcerpc_netr_LogonSamLogon_r(b, tctx, &r),
325 "LogonSamLogon failed");
327 torture_assert_ntstatus_equal(tctx, r.out.result, NT_STATUS_INVALID_PARAMETER, "LogonSamLogon failed");
329 torture_assert(tctx, netlogon_creds_client_check(creds, &r.out.return_authenticator->cred),
330 "Credential chaining failed");
335 static bool test_PACVerify_bdc(struct torture_context *tctx,
336 struct dcerpc_pipe *p,
337 struct cli_credentials *credentials)
339 return test_PACVerify(tctx, p, credentials, SEC_CHAN_BDC, TEST_MACHINE_NAME_BDC);
342 static bool test_PACVerify_workstation(struct torture_context *tctx,
343 struct dcerpc_pipe *p,
344 struct cli_credentials *credentials)
346 return test_PACVerify(tctx, p, credentials, SEC_CHAN_WKSTA, TEST_MACHINE_NAME_WKSTA);
349 static bool test_PACVerify_workstation_des(struct torture_context *tctx,
350 struct dcerpc_pipe *p, struct cli_credentials *credentials, struct test_join *join_ctx)
352 struct samr_SetUserInfo r;
353 union samr_UserInfo user_info;
354 struct dcerpc_pipe *samr_pipe = torture_join_samr_pipe(join_ctx);
355 struct smb_krb5_context *smb_krb5_context;
358 ret = cli_credentials_get_krb5_context(cmdline_credentials, tctx->lp_ctx, &smb_krb5_context);
359 torture_assert_int_equal(tctx, ret, 0, "cli_credentials_get_krb5_context() failed");
361 if (krb5_config_get_bool_default(smb_krb5_context->krb5_context, NULL, FALSE,
363 "allow_weak_crypto", NULL) == FALSE) {
364 torture_skip(tctx, "Cannot test DES without [libdefaults] allow_weak_crypto = yes");
367 /* Mark this workstation with DES-only */
368 user_info.info16.acct_flags = ACB_USE_DES_KEY_ONLY | ACB_WSTRUST;
369 r.in.user_handle = torture_join_samr_user_policy(join_ctx);
371 r.in.info = &user_info;
373 torture_assert_ntstatus_ok(tctx, dcerpc_samr_SetUserInfo_r(samr_pipe->binding_handle, tctx, &r),
374 "failed to set DES info account flags");
375 torture_assert_ntstatus_ok(tctx, r.out.result,
376 "failed to set DES into account flags");
378 return test_PACVerify(tctx, p, credentials, SEC_CHAN_WKSTA, TEST_MACHINE_NAME_WKSTA_DES);
382 /* 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 */
383 static bool test_S2U4Self(struct torture_context *tctx,
384 struct dcerpc_pipe *p,
385 struct cli_credentials *credentials,
386 enum netr_SchannelType secure_channel_type,
387 const char *test_machine_name)
390 struct dcerpc_binding_handle *b = p->binding_handle;
392 struct netr_LogonSamLogon r;
394 union netr_LogonLevel logon;
395 union netr_Validation validation;
396 uint8_t authoritative;
398 struct netr_Authenticator auth, auth2;
400 DATA_BLOB client_to_server, server_to_client;
402 struct netlogon_creds_CredentialState *creds;
403 struct gensec_security *gensec_client_context;
404 struct gensec_security *gensec_server_context;
406 struct auth_session_info *kinit_session_info;
407 struct auth_session_info *s2u4self_session_info;
408 struct auth_serversupplied_info *netlogon_server_info;
410 struct netr_NetworkInfo ninfo;
411 DATA_BLOB names_blob, chal, lm_resp, nt_resp;
413 int flags = CLI_CRED_NTLMv2_AUTH;
415 struct dom_sid *builtin_domain;
417 TALLOC_CTX *tmp_ctx = talloc_new(tctx);
419 torture_assert(tctx, tmp_ctx != NULL, "talloc_new() failed");
421 /* First, do a normal Kerberos connection */
423 status = gensec_client_start(tctx, &gensec_client_context, tctx->ev,
424 lpcfg_gensec_settings(tctx, tctx->lp_ctx));
425 torture_assert_ntstatus_ok(tctx, status, "gensec_client_start (client) failed");
427 status = gensec_set_target_hostname(gensec_client_context, test_machine_name);
429 status = gensec_set_credentials(gensec_client_context, cmdline_credentials);
430 torture_assert_ntstatus_ok(tctx, status, "gensec_set_credentials (client) failed");
432 status = gensec_start_mech_by_sasl_name(gensec_client_context, "GSSAPI");
433 torture_assert_ntstatus_ok(tctx, status, "gensec_start_mech_by_sasl_name (client) failed");
435 status = gensec_server_start(tctx, tctx->ev,
436 lpcfg_gensec_settings(tctx, tctx->lp_ctx),
437 NULL, &gensec_server_context);
438 torture_assert_ntstatus_ok(tctx, status, "gensec_server_start (server) failed");
440 status = gensec_set_credentials(gensec_server_context, credentials);
441 torture_assert_ntstatus_ok(tctx, status, "gensec_set_credentials (server) failed");
443 status = gensec_start_mech_by_sasl_name(gensec_server_context, "GSSAPI");
444 torture_assert_ntstatus_ok(tctx, status, "gensec_start_mech_by_sasl_name (server) failed");
446 server_to_client = data_blob(NULL, 0);
449 /* Do a client-server update dance */
450 status = gensec_update(gensec_client_context, tmp_ctx, server_to_client, &client_to_server);
451 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {;
452 torture_assert_ntstatus_ok(tctx, status, "gensec_update (client) failed");
455 status = gensec_update(gensec_server_context, tmp_ctx, client_to_server, &server_to_client);
456 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {;
457 torture_assert_ntstatus_ok(tctx, status, "gensec_update (server) failed");
460 if (NT_STATUS_IS_OK(status)) {
465 /* Extract the PAC using Samba's code */
467 status = gensec_session_info(gensec_server_context, &kinit_session_info);
468 torture_assert_ntstatus_ok(tctx, status, "gensec_session_info failed");
471 /* Now do the dance with S2U4Self */
473 /* Wipe out any existing ccache */
474 cli_credentials_invalidate_ccache(credentials, CRED_SPECIFIED);
475 cli_credentials_set_target_service(credentials, talloc_asprintf(tmp_ctx, "host/%s", test_machine_name));
476 cli_credentials_set_impersonate_principal(credentials, cli_credentials_get_principal(cmdline_credentials, tmp_ctx));
478 status = gensec_client_start(tctx, &gensec_client_context, tctx->ev,
479 lpcfg_gensec_settings(tctx, tctx->lp_ctx));
480 torture_assert_ntstatus_ok(tctx, status, "gensec_client_start (client) failed");
482 status = gensec_set_target_hostname(gensec_client_context, test_machine_name);
484 /* We now set the same credentials on both client and server contexts */
485 status = gensec_set_credentials(gensec_client_context, credentials);
486 torture_assert_ntstatus_ok(tctx, status, "gensec_set_credentials (client) failed");
488 status = gensec_start_mech_by_sasl_name(gensec_client_context, "GSSAPI");
489 torture_assert_ntstatus_ok(tctx, status, "gensec_start_mech_by_sasl_name (client) failed");
491 status = gensec_server_start(tctx, tctx->ev,
492 lpcfg_gensec_settings(tctx, tctx->lp_ctx),
493 NULL, &gensec_server_context);
494 torture_assert_ntstatus_ok(tctx, status, "gensec_server_start (server) failed");
496 status = gensec_set_credentials(gensec_server_context, credentials);
497 torture_assert_ntstatus_ok(tctx, status, "gensec_set_credentials (server) failed");
499 status = gensec_start_mech_by_sasl_name(gensec_server_context, "GSSAPI");
500 torture_assert_ntstatus_ok(tctx, status, "gensec_start_mech_by_sasl_name (server) failed");
502 server_to_client = data_blob(NULL, 0);
505 /* Do a client-server update dance */
506 status = gensec_update(gensec_client_context, tmp_ctx, server_to_client, &client_to_server);
507 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {;
508 torture_assert_ntstatus_ok(tctx, status, "gensec_update (client) failed");
511 status = gensec_update(gensec_server_context, tmp_ctx, client_to_server, &server_to_client);
512 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {;
513 torture_assert_ntstatus_ok(tctx, status, "gensec_update (server) failed");
516 if (NT_STATUS_IS_OK(status)) {
521 /* Don't pollute the remaining tests with the changed credentials */
522 cli_credentials_invalidate_ccache(credentials, CRED_SPECIFIED);
523 cli_credentials_set_target_service(credentials, NULL);
524 cli_credentials_set_impersonate_principal(credentials, NULL);
526 /* Extract the PAC using Samba's code */
528 status = gensec_session_info(gensec_server_context, &s2u4self_session_info);
529 torture_assert_ntstatus_ok(tctx, status, "gensec_session_info failed");
531 cli_credentials_get_ntlm_username_domain(cmdline_credentials, tctx,
532 &ninfo.identity_info.account_name.string,
533 &ninfo.identity_info.domain_name.string);
535 /* Now try with SamLogon */
536 generate_random_buffer(ninfo.challenge,
537 sizeof(ninfo.challenge));
538 chal = data_blob_const(ninfo.challenge,
539 sizeof(ninfo.challenge));
541 names_blob = NTLMv2_generate_names_blob(tctx, cli_credentials_get_workstation(credentials),
542 cli_credentials_get_domain(credentials));
544 status = cli_credentials_get_ntlm_response(cmdline_credentials, tctx,
550 torture_assert_ntstatus_ok(tctx, status, "cli_credentials_get_ntlm_response failed");
552 ninfo.lm.data = lm_resp.data;
553 ninfo.lm.length = lm_resp.length;
555 ninfo.nt.data = nt_resp.data;
556 ninfo.nt.length = nt_resp.length;
558 ninfo.identity_info.parameter_control = 0;
559 ninfo.identity_info.logon_id_low = 0;
560 ninfo.identity_info.logon_id_high = 0;
561 ninfo.identity_info.workstation.string = cli_credentials_get_workstation(credentials);
563 logon.network = &ninfo;
565 r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
566 r.in.computer_name = cli_credentials_get_workstation(credentials);
567 r.in.credential = &auth;
568 r.in.return_authenticator = &auth2;
569 r.in.logon_level = 2;
571 r.out.validation = &validation;
572 r.out.authoritative = &authoritative;
574 if (!test_SetupCredentials2(p, tctx, NETLOGON_NEG_AUTH2_ADS_FLAGS,
575 credentials, secure_channel_type,
581 netlogon_creds_client_authenticator(creds, &auth);
583 r.in.validation_level = 3;
585 status = dcerpc_netr_LogonSamLogon_r(b, tctx, &r);
586 torture_assert_ntstatus_ok(tctx, status, "LogonSamLogon failed");
588 torture_assert(tctx, netlogon_creds_client_check(creds,
589 &r.out.return_authenticator->cred),
590 "Credential chaining failed");
592 status = make_server_info_netlogon_validation(tmp_ctx,
593 ninfo.identity_info.account_name.string,
594 r.in.validation_level,
596 &netlogon_server_info);
598 torture_assert_ntstatus_ok(tctx, status, "make_server_info_netlogon_validation failed");
600 torture_assert_str_equal(tctx, netlogon_server_info->account_name == NULL ? "" : netlogon_server_info->account_name,
601 kinit_session_info->server_info->account_name, "Account name differs for kinit-based PAC");
602 torture_assert_str_equal(tctx,netlogon_server_info->account_name == NULL ? "" : netlogon_server_info->account_name,
603 s2u4self_session_info->server_info->account_name, "Account name differs for S2U4Self");
604 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");
605 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");
606 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");
607 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");
608 torture_assert(tctx, dom_sid_equal(netlogon_server_info->account_sid, s2u4self_session_info->server_info->account_sid), "Account SID differs for S2U4Self");
609 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");
610 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");
611 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");
613 builtin_domain = dom_sid_parse_talloc(tmp_ctx, SID_BUILTIN);
615 for (i = 0; i < kinit_session_info->server_info->n_domain_groups; i++) {
616 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");
617 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");
618 torture_assert(tctx, !dom_sid_in_domain(builtin_domain, s2u4self_session_info->server_info->domain_groups[i]), "Returned BUILTIN domain in groups for S2U4Self");
619 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");
620 torture_assert(tctx, !dom_sid_in_domain(builtin_domain, netlogon_server_info->domain_groups[i]), "Returned BUILTIN domian in groups from NETLOGON SamLogon reply");
626 static bool test_S2U4Self_bdc(struct torture_context *tctx,
627 struct dcerpc_pipe *p,
628 struct cli_credentials *credentials)
630 return test_S2U4Self(tctx, p, credentials, SEC_CHAN_BDC, TEST_MACHINE_NAME_S2U4SELF_BDC);
633 static bool test_S2U4Self_workstation(struct torture_context *tctx,
634 struct dcerpc_pipe *p,
635 struct cli_credentials *credentials)
637 return test_S2U4Self(tctx, p, credentials, SEC_CHAN_WKSTA, TEST_MACHINE_NAME_S2U4SELF_WKSTA);
640 struct torture_suite *torture_rpc_remote_pac(TALLOC_CTX *mem_ctx)
642 struct torture_suite *suite = torture_suite_create(mem_ctx, "pac");
643 struct torture_rpc_tcase *tcase;
645 /* It is important to use different names, so that old entries in our credential cache are not used */
646 tcase = torture_suite_add_machine_bdc_rpc_iface_tcase(suite, "netlogon-bdc",
647 &ndr_table_netlogon, TEST_MACHINE_NAME_BDC);
648 torture_rpc_tcase_add_test_creds(tcase, "verify-sig", test_PACVerify_bdc);
650 tcase = torture_suite_add_machine_workstation_rpc_iface_tcase(suite, "netlogon-member",
651 &ndr_table_netlogon, TEST_MACHINE_NAME_WKSTA);
652 torture_rpc_tcase_add_test_creds(tcase, "verify-sig", test_PACVerify_workstation);
654 tcase = torture_suite_add_machine_workstation_rpc_iface_tcase(suite, "netlogon-member-des",
655 &ndr_table_netlogon, TEST_MACHINE_NAME_WKSTA_DES);
656 torture_rpc_tcase_add_test_join(tcase, "verify-sig", test_PACVerify_workstation_des);
658 tcase = torture_suite_add_machine_bdc_rpc_iface_tcase(suite, "netlogon-bdc",
659 &ndr_table_netlogon, TEST_MACHINE_NAME_S2U4SELF_BDC);
660 torture_rpc_tcase_add_test_creds(tcase, "s2u4self", test_S2U4Self_bdc);
662 tcase = torture_suite_add_machine_workstation_rpc_iface_tcase(suite, "netlogon-member",
663 &ndr_table_netlogon, TEST_MACHINE_NAME_S2U4SELF_WKSTA);
665 torture_rpc_tcase_add_test_creds(tcase, "s2u4self", test_S2U4Self_workstation);