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_krb5pac.h"
36 #include "librpc/gen_ndr/ndr_samr_c.h"
37 #include "param/param.h"
39 #define TEST_MACHINE_NAME_BDC "torturepacbdc"
40 #define TEST_MACHINE_NAME_WKSTA "torturepacwksta"
41 #define TEST_MACHINE_NAME_WKSTA_DES "torturepacwkdes"
42 #define TEST_MACHINE_NAME_S2U4SELF_BDC "tests2u4selfbdc"
43 #define TEST_MACHINE_NAME_S2U4SELF_WKSTA "tests2u4selfwk"
46 struct PAC_SIGNATURE_DATA
*pac_srv_sig
;
47 struct PAC_SIGNATURE_DATA
*pac_kdc_sig
;
50 /* A helper function which avoids touching the local databases to
51 * generate the session info, as we just want to verify the PAC
52 * details, not the full local token */
53 static NTSTATUS
test_generate_session_info_pac(struct auth4_context
*auth_ctx
,
55 struct smb_krb5_context
*smb_krb5_context
,
57 const char *principal_name
,
58 const struct tsocket_address
*remote_address
,
59 uint32_t session_info_flags
,
60 struct auth_session_info
**session_info
)
63 struct auth_user_info_dc
*user_info_dc
;
65 struct pac_data
*pac_data
;
67 tmp_ctx
= talloc_named(mem_ctx
, 0, "gensec_gssapi_session_info context");
68 NT_STATUS_HAVE_NO_MEMORY(tmp_ctx
);
70 auth_ctx
->private_data
= pac_data
= talloc_zero(auth_ctx
, struct pac_data
);
72 pac_data
->pac_srv_sig
= talloc(tmp_ctx
, struct PAC_SIGNATURE_DATA
);
73 if (!pac_data
->pac_srv_sig
) {
75 return NT_STATUS_NO_MEMORY
;
77 pac_data
->pac_kdc_sig
= talloc(tmp_ctx
, struct PAC_SIGNATURE_DATA
);
78 if (!pac_data
->pac_kdc_sig
) {
80 return NT_STATUS_NO_MEMORY
;
83 nt_status
= kerberos_pac_blob_to_user_info_dc(tmp_ctx
,
85 smb_krb5_context
->krb5_context
,
87 pac_data
->pac_srv_sig
,
88 pac_data
->pac_kdc_sig
);
89 if (!NT_STATUS_IS_OK(nt_status
)) {
94 talloc_steal(pac_data
, pac_data
->pac_srv_sig
);
95 talloc_steal(pac_data
, pac_data
->pac_kdc_sig
);
97 if (user_info_dc
->info
->authenticated
) {
98 session_info_flags
|= AUTH_SESSION_INFO_AUTHENTICATED
;
101 session_info_flags
|= AUTH_SESSION_INFO_SIMPLE_PRIVILEGES
;
102 nt_status
= auth_generate_session_info(mem_ctx
,
105 user_info_dc
, session_info_flags
,
107 if (!NT_STATUS_IS_OK(nt_status
)) {
108 talloc_free(tmp_ctx
);
112 talloc_free(tmp_ctx
);
116 /* Check to see if we can pass the PAC across to the NETLOGON server for validation */
118 /* Also happens to be a really good one-step verfication of our Kerberos stack */
120 static bool test_PACVerify(struct torture_context
*tctx
,
121 struct dcerpc_pipe
*p
,
122 struct cli_credentials
*credentials
,
123 enum netr_SchannelType secure_channel_type
,
124 const char *test_machine_name
)
128 struct netr_LogonSamLogon r
;
130 union netr_LogonLevel logon
;
131 union netr_Validation validation
;
132 uint8_t authoritative
;
133 struct netr_Authenticator return_authenticator
;
135 struct netr_GenericInfo generic
;
136 struct netr_Authenticator auth
, auth2
;
138 struct netlogon_creds_CredentialState
*creds
;
139 struct gensec_security
*gensec_client_context
;
140 struct gensec_security
*gensec_server_context
;
142 DATA_BLOB client_to_server
, server_to_client
, pac_wrapped
, payload
;
143 struct PAC_Validate pac_wrapped_struct
;
145 enum ndr_err_code ndr_err
;
147 struct auth4_context
*auth_context
;
148 struct auth_session_info
*session_info
;
149 struct pac_data
*pac_data
;
151 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
152 TALLOC_CTX
*tmp_ctx
= talloc_new(tctx
);
153 torture_assert(tctx
, tmp_ctx
!= NULL
, "talloc_new() failed");
155 if (!test_SetupCredentials2(p
, tctx
, NETLOGON_NEG_AUTH2_ADS_FLAGS
,
156 credentials
, secure_channel_type
,
161 auth_context
= talloc_zero(tmp_ctx
, struct auth4_context
);
162 torture_assert(tctx
, auth_context
!= NULL
, "talloc_new() failed");
164 auth_context
->generate_session_info_pac
= test_generate_session_info_pac
;
166 status
= gensec_client_start(tctx
, &gensec_client_context
,
167 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
));
168 torture_assert_ntstatus_ok(tctx
, status
, "gensec_client_start (client) failed");
170 status
= gensec_set_target_hostname(gensec_client_context
, test_machine_name
);
172 status
= gensec_set_credentials(gensec_client_context
, cmdline_credentials
);
173 torture_assert_ntstatus_ok(tctx
, status
, "gensec_set_credentials (client) failed");
175 status
= gensec_start_mech_by_sasl_name(gensec_client_context
, "GSSAPI");
176 torture_assert_ntstatus_ok(tctx
, status
, "gensec_start_mech_by_sasl_name (client) failed");
178 status
= gensec_server_start(tctx
,
179 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
),
180 auth_context
, &gensec_server_context
);
181 torture_assert_ntstatus_ok(tctx
, status
, "gensec_server_start (server) failed");
183 status
= gensec_set_credentials(gensec_server_context
, credentials
);
184 torture_assert_ntstatus_ok(tctx
, status
, "gensec_set_credentials (server) failed");
186 status
= gensec_start_mech_by_sasl_name(gensec_server_context
, "GSSAPI");
187 torture_assert_ntstatus_ok(tctx
, status
, "gensec_start_mech_by_sasl_name (server) failed");
189 server_to_client
= data_blob(NULL
, 0);
192 /* Do a client-server update dance */
193 status
= gensec_update(gensec_client_context
, tmp_ctx
, tctx
->ev
, server_to_client
, &client_to_server
);
194 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {;
195 torture_assert_ntstatus_ok(tctx
, status
, "gensec_update (client) failed");
198 status
= gensec_update(gensec_server_context
, tmp_ctx
, tctx
->ev
, client_to_server
, &server_to_client
);
199 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {;
200 torture_assert_ntstatus_ok(tctx
, status
, "gensec_update (server) failed");
203 if (NT_STATUS_IS_OK(status
)) {
208 /* Extract the PAC using Samba's code */
210 status
= gensec_session_info(gensec_server_context
, gensec_server_context
, &session_info
);
211 torture_assert_ntstatus_ok(tctx
, status
, "gensec_session_info failed");
213 pac_data
= talloc_get_type(auth_context
->private_data
, struct pac_data
);
215 torture_assert(tctx
, pac_data
!= NULL
, "gensec_update failed to fill in pac_data in auth_context");
216 torture_assert(tctx
, pac_data
->pac_srv_sig
!= NULL
, "pac_srv_sig not present");
217 torture_assert(tctx
, pac_data
->pac_kdc_sig
!= NULL
, "pac_kdc_sig not present");
219 pac_wrapped_struct
.ChecksumLength
= pac_data
->pac_srv_sig
->signature
.length
;
220 pac_wrapped_struct
.SignatureType
= pac_data
->pac_kdc_sig
->type
;
221 pac_wrapped_struct
.SignatureLength
= pac_data
->pac_kdc_sig
->signature
.length
;
222 pac_wrapped_struct
.ChecksumAndSignature
= payload
223 = data_blob_talloc(tmp_ctx
, NULL
,
224 pac_wrapped_struct
.ChecksumLength
225 + pac_wrapped_struct
.SignatureLength
);
226 memcpy(&payload
.data
[0],
227 pac_data
->pac_srv_sig
->signature
.data
,
228 pac_wrapped_struct
.ChecksumLength
);
229 memcpy(&payload
.data
[pac_wrapped_struct
.ChecksumLength
],
230 pac_data
->pac_kdc_sig
->signature
.data
,
231 pac_wrapped_struct
.SignatureLength
);
233 ndr_err
= ndr_push_struct_blob(&pac_wrapped
, tmp_ctx
, &pac_wrapped_struct
,
234 (ndr_push_flags_fn_t
)ndr_push_PAC_Validate
);
235 torture_assert(tctx
, NDR_ERR_CODE_IS_SUCCESS(ndr_err
), "ndr_push_struct_blob of PACValidate structure failed");
237 torture_assert(tctx
, (creds
->negotiate_flags
& NETLOGON_NEG_ARCFOUR
), "not willing to even try a PACValidate without RC4 encryption");
238 netlogon_creds_arcfour_crypt(creds
, pac_wrapped
.data
, pac_wrapped
.length
);
240 generic
.length
= pac_wrapped
.length
;
241 generic
.data
= pac_wrapped
.data
;
243 /* Validate it over the netlogon pipe */
245 generic
.identity_info
.parameter_control
= 0;
246 generic
.identity_info
.logon_id_high
= 0;
247 generic
.identity_info
.logon_id_low
= 0;
248 generic
.identity_info
.domain_name
.string
= session_info
->info
->domain_name
;
249 generic
.identity_info
.account_name
.string
= session_info
->info
->account_name
;
250 generic
.identity_info
.workstation
.string
= test_machine_name
;
252 generic
.package_name
.string
= "Kerberos";
254 logon
.generic
= &generic
;
257 netlogon_creds_client_authenticator(creds
, &auth
);
258 r
.in
.credential
= &auth
;
259 r
.in
.return_authenticator
= &auth2
;
261 r
.in
.logon_level
= NetlogonGenericInformation
;
262 r
.in
.server_name
= talloc_asprintf(tctx
, "\\\\%s", dcerpc_server_name(p
));
263 r
.in
.computer_name
= cli_credentials_get_workstation(credentials
);
264 r
.in
.validation_level
= NetlogonValidationGenericInfo2
;
265 r
.out
.validation
= &validation
;
266 r
.out
.authoritative
= &authoritative
;
267 r
.out
.return_authenticator
= &return_authenticator
;
269 torture_assert_ntstatus_ok(tctx
, dcerpc_netr_LogonSamLogon_r(b
, tctx
, &r
),
270 "LogonSamLogon failed");
272 torture_assert_ntstatus_ok(tctx
, r
.out
.result
, "LogonSamLogon failed");
274 /* This will break the signature nicely (even in the crypto wrapping), check we get a logon failure */
275 generic
.data
[generic
.length
-1]++;
277 logon
.generic
= &generic
;
280 netlogon_creds_client_authenticator(creds
, &auth
);
281 r
.in
.credential
= &auth
;
282 r
.in
.return_authenticator
= &auth2
;
283 r
.in
.logon_level
= NetlogonGenericInformation
;
285 r
.in
.server_name
= talloc_asprintf(tctx
, "\\\\%s", dcerpc_server_name(p
));
286 r
.in
.computer_name
= cli_credentials_get_workstation(credentials
);
287 r
.in
.validation_level
= NetlogonValidationGenericInfo2
;
289 torture_assert_ntstatus_ok(tctx
, dcerpc_netr_LogonSamLogon_r(b
, tctx
, &r
),
290 "LogonSamLogon failed");
292 torture_assert_ntstatus_equal(tctx
, r
.out
.result
, NT_STATUS_LOGON_FAILURE
, "LogonSamLogon failed");
294 torture_assert(tctx
, netlogon_creds_client_check(creds
, &r
.out
.return_authenticator
->cred
),
295 "Credential chaining failed");
297 /* This will break the parsing nicely (even in the crypto wrapping), check we get INVALID_PARAMETER */
300 logon
.generic
= &generic
;
303 netlogon_creds_client_authenticator(creds
, &auth
);
304 r
.in
.credential
= &auth
;
305 r
.in
.return_authenticator
= &auth2
;
306 r
.in
.logon_level
= NetlogonGenericInformation
;
308 r
.in
.server_name
= talloc_asprintf(tctx
, "\\\\%s", dcerpc_server_name(p
));
309 r
.in
.computer_name
= cli_credentials_get_workstation(credentials
);
310 r
.in
.validation_level
= NetlogonValidationGenericInfo2
;
312 torture_assert_ntstatus_ok(tctx
, dcerpc_netr_LogonSamLogon_r(b
, tctx
, &r
),
313 "LogonSamLogon failed");
315 torture_assert_ntstatus_equal(tctx
, r
.out
.result
, NT_STATUS_INVALID_PARAMETER
, "LogonSamLogon failed");
317 torture_assert(tctx
, netlogon_creds_client_check(creds
,
318 &r
.out
.return_authenticator
->cred
),
319 "Credential chaining failed");
321 pac_wrapped_struct
.ChecksumLength
= pac_data
->pac_srv_sig
->signature
.length
;
322 pac_wrapped_struct
.SignatureType
= pac_data
->pac_kdc_sig
->type
;
324 /* Break the SignatureType */
325 pac_wrapped_struct
.SignatureType
++;
327 pac_wrapped_struct
.SignatureLength
= pac_data
->pac_kdc_sig
->signature
.length
;
328 pac_wrapped_struct
.ChecksumAndSignature
= payload
329 = data_blob_talloc(tmp_ctx
, NULL
,
330 pac_wrapped_struct
.ChecksumLength
331 + pac_wrapped_struct
.SignatureLength
);
332 memcpy(&payload
.data
[0],
333 pac_data
->pac_srv_sig
->signature
.data
,
334 pac_wrapped_struct
.ChecksumLength
);
335 memcpy(&payload
.data
[pac_wrapped_struct
.ChecksumLength
],
336 pac_data
->pac_kdc_sig
->signature
.data
,
337 pac_wrapped_struct
.SignatureLength
);
339 ndr_err
= ndr_push_struct_blob(&pac_wrapped
, tmp_ctx
, &pac_wrapped_struct
,
340 (ndr_push_flags_fn_t
)ndr_push_PAC_Validate
);
341 torture_assert(tctx
, NDR_ERR_CODE_IS_SUCCESS(ndr_err
), "ndr_push_struct_blob of PACValidate structure failed");
343 torture_assert(tctx
, (creds
->negotiate_flags
& NETLOGON_NEG_ARCFOUR
), "not willing to even try a PACValidate without RC4 encryption");
344 netlogon_creds_arcfour_crypt(creds
, pac_wrapped
.data
, pac_wrapped
.length
);
346 generic
.length
= pac_wrapped
.length
;
347 generic
.data
= pac_wrapped
.data
;
349 logon
.generic
= &generic
;
352 netlogon_creds_client_authenticator(creds
, &auth
);
353 r
.in
.credential
= &auth
;
354 r
.in
.return_authenticator
= &auth2
;
355 r
.in
.logon_level
= NetlogonGenericInformation
;
357 r
.in
.server_name
= talloc_asprintf(tctx
, "\\\\%s", dcerpc_server_name(p
));
358 r
.in
.computer_name
= cli_credentials_get_workstation(credentials
);
359 r
.in
.validation_level
= NetlogonValidationGenericInfo2
;
361 torture_assert_ntstatus_ok(tctx
, dcerpc_netr_LogonSamLogon_r(b
, tctx
, &r
),
362 "LogonSamLogon failed");
364 torture_assert_ntstatus_equal(tctx
, r
.out
.result
, NT_STATUS_LOGON_FAILURE
, "LogonSamLogon failed");
366 torture_assert(tctx
, netlogon_creds_client_check(creds
, &r
.out
.return_authenticator
->cred
),
367 "Credential chaining failed");
369 pac_wrapped_struct
.ChecksumLength
= pac_data
->pac_srv_sig
->signature
.length
;
370 pac_wrapped_struct
.SignatureType
= pac_data
->pac_kdc_sig
->type
;
371 pac_wrapped_struct
.SignatureLength
= pac_data
->pac_kdc_sig
->signature
.length
;
373 pac_wrapped_struct
.ChecksumAndSignature
= payload
374 = data_blob_talloc(tmp_ctx
, NULL
,
375 pac_wrapped_struct
.ChecksumLength
376 + pac_wrapped_struct
.SignatureLength
);
377 memcpy(&payload
.data
[0],
378 pac_data
->pac_srv_sig
->signature
.data
,
379 pac_wrapped_struct
.ChecksumLength
);
380 memcpy(&payload
.data
[pac_wrapped_struct
.ChecksumLength
],
381 pac_data
->pac_kdc_sig
->signature
.data
,
382 pac_wrapped_struct
.SignatureLength
);
384 /* Break the signature length */
385 pac_wrapped_struct
.SignatureLength
++;
387 ndr_err
= ndr_push_struct_blob(&pac_wrapped
, tmp_ctx
, &pac_wrapped_struct
,
388 (ndr_push_flags_fn_t
)ndr_push_PAC_Validate
);
389 torture_assert(tctx
, NDR_ERR_CODE_IS_SUCCESS(ndr_err
), "ndr_push_struct_blob of PACValidate structure failed");
391 torture_assert(tctx
, (creds
->negotiate_flags
& NETLOGON_NEG_ARCFOUR
), "not willing to even try a PACValidate without RC4 encryption");
392 netlogon_creds_arcfour_crypt(creds
, pac_wrapped
.data
, pac_wrapped
.length
);
394 generic
.length
= pac_wrapped
.length
;
395 generic
.data
= pac_wrapped
.data
;
397 logon
.generic
= &generic
;
400 netlogon_creds_client_authenticator(creds
, &auth
);
401 r
.in
.credential
= &auth
;
402 r
.in
.return_authenticator
= &auth2
;
403 r
.in
.logon_level
= NetlogonGenericInformation
;
405 r
.in
.server_name
= talloc_asprintf(tctx
, "\\\\%s", dcerpc_server_name(p
));
406 r
.in
.computer_name
= cli_credentials_get_workstation(credentials
);
407 r
.in
.validation_level
= NetlogonValidationGenericInfo2
;
409 torture_assert_ntstatus_ok(tctx
, dcerpc_netr_LogonSamLogon_r(b
, tctx
, &r
),
410 "LogonSamLogon failed");
412 torture_assert_ntstatus_equal(tctx
, r
.out
.result
, NT_STATUS_INVALID_PARAMETER
, "LogonSamLogon failed");
414 torture_assert(tctx
, netlogon_creds_client_check(creds
, &r
.out
.return_authenticator
->cred
),
415 "Credential chaining failed");
420 static bool test_PACVerify_bdc(struct torture_context
*tctx
,
421 struct dcerpc_pipe
*p
,
422 struct cli_credentials
*credentials
)
424 return test_PACVerify(tctx
, p
, credentials
, SEC_CHAN_BDC
, TEST_MACHINE_NAME_BDC
);
427 static bool test_PACVerify_workstation(struct torture_context
*tctx
,
428 struct dcerpc_pipe
*p
,
429 struct cli_credentials
*credentials
)
431 return test_PACVerify(tctx
, p
, credentials
, SEC_CHAN_WKSTA
, TEST_MACHINE_NAME_WKSTA
);
434 static bool test_PACVerify_workstation_des(struct torture_context
*tctx
,
435 struct dcerpc_pipe
*p
, struct cli_credentials
*credentials
, struct test_join
*join_ctx
)
437 struct samr_SetUserInfo r
;
438 union samr_UserInfo user_info
;
439 struct dcerpc_pipe
*samr_pipe
= torture_join_samr_pipe(join_ctx
);
440 struct smb_krb5_context
*smb_krb5_context
;
443 ret
= cli_credentials_get_krb5_context(cmdline_credentials
, tctx
->lp_ctx
, &smb_krb5_context
);
444 torture_assert_int_equal(tctx
, ret
, 0, "cli_credentials_get_krb5_context() failed");
446 if (krb5_config_get_bool_default(smb_krb5_context
->krb5_context
, NULL
, FALSE
,
448 "allow_weak_crypto", NULL
) == FALSE
) {
449 torture_skip(tctx
, "Cannot test DES without [libdefaults] allow_weak_crypto = yes");
452 /* Mark this workstation with DES-only */
453 user_info
.info16
.acct_flags
= ACB_USE_DES_KEY_ONLY
| ACB_WSTRUST
;
454 r
.in
.user_handle
= torture_join_samr_user_policy(join_ctx
);
456 r
.in
.info
= &user_info
;
458 torture_assert_ntstatus_ok(tctx
, dcerpc_samr_SetUserInfo_r(samr_pipe
->binding_handle
, tctx
, &r
),
459 "failed to set DES info account flags");
460 torture_assert_ntstatus_ok(tctx
, r
.out
.result
,
461 "failed to set DES into account flags");
463 return test_PACVerify(tctx
, p
, credentials
, SEC_CHAN_WKSTA
, TEST_MACHINE_NAME_WKSTA_DES
);
467 /* 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 */
468 static bool test_S2U4Self(struct torture_context
*tctx
,
469 struct dcerpc_pipe
*p
,
470 struct cli_credentials
*credentials
,
471 enum netr_SchannelType secure_channel_type
,
472 const char *test_machine_name
)
475 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
477 struct netr_LogonSamLogon r
;
479 union netr_LogonLevel logon
;
480 union netr_Validation validation
;
481 uint8_t authoritative
;
483 struct netr_Authenticator auth
, auth2
;
485 DATA_BLOB client_to_server
, server_to_client
;
487 struct netlogon_creds_CredentialState
*creds
;
488 struct gensec_security
*gensec_client_context
;
489 struct gensec_security
*gensec_server_context
;
491 struct auth4_context
*auth_context
;
492 struct auth_session_info
*kinit_session_info
;
493 struct auth_session_info
*s2u4self_session_info
;
494 struct auth_user_info_dc
*netlogon_user_info_dc
;
496 struct netr_NetworkInfo ninfo
;
497 DATA_BLOB names_blob
, chal
, lm_resp
, nt_resp
;
499 int flags
= CLI_CRED_NTLMv2_AUTH
;
501 struct dom_sid
*builtin_domain
;
503 TALLOC_CTX
*tmp_ctx
= talloc_new(tctx
);
505 torture_assert(tctx
, tmp_ctx
!= NULL
, "talloc_new() failed");
507 auth_context
= talloc_zero(tmp_ctx
, struct auth4_context
);
508 torture_assert(tctx
, auth_context
!= NULL
, "talloc_new() failed");
510 auth_context
->generate_session_info_pac
= test_generate_session_info_pac
;
512 /* First, do a normal Kerberos connection */
514 status
= gensec_client_start(tctx
, &gensec_client_context
,
515 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
));
516 torture_assert_ntstatus_ok(tctx
, status
, "gensec_client_start (client) failed");
518 status
= gensec_set_target_hostname(gensec_client_context
, test_machine_name
);
520 status
= gensec_set_credentials(gensec_client_context
, cmdline_credentials
);
521 torture_assert_ntstatus_ok(tctx
, status
, "gensec_set_credentials (client) failed");
523 status
= gensec_start_mech_by_sasl_name(gensec_client_context
, "GSSAPI");
524 torture_assert_ntstatus_ok(tctx
, status
, "gensec_start_mech_by_sasl_name (client) failed");
526 status
= gensec_server_start(tctx
,
527 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
),
528 auth_context
, &gensec_server_context
);
529 torture_assert_ntstatus_ok(tctx
, status
, "gensec_server_start (server) failed");
531 status
= gensec_set_credentials(gensec_server_context
, credentials
);
532 torture_assert_ntstatus_ok(tctx
, status
, "gensec_set_credentials (server) failed");
534 status
= gensec_start_mech_by_sasl_name(gensec_server_context
, "GSSAPI");
535 torture_assert_ntstatus_ok(tctx
, status
, "gensec_start_mech_by_sasl_name (server) failed");
537 server_to_client
= data_blob(NULL
, 0);
540 /* Do a client-server update dance */
541 status
= gensec_update(gensec_client_context
, tmp_ctx
, tctx
->ev
, server_to_client
, &client_to_server
);
542 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {;
543 torture_assert_ntstatus_ok(tctx
, status
, "gensec_update (client) failed");
546 status
= gensec_update(gensec_server_context
, tmp_ctx
, tctx
->ev
, client_to_server
, &server_to_client
);
547 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {;
548 torture_assert_ntstatus_ok(tctx
, status
, "gensec_update (server) failed");
551 if (NT_STATUS_IS_OK(status
)) {
556 /* Extract the PAC using Samba's code */
558 status
= gensec_session_info(gensec_server_context
, gensec_server_context
, &kinit_session_info
);
559 torture_assert_ntstatus_ok(tctx
, status
, "gensec_session_info failed");
562 /* Now do the dance with S2U4Self */
564 /* Wipe out any existing ccache */
565 cli_credentials_invalidate_ccache(credentials
, CRED_SPECIFIED
);
566 cli_credentials_set_impersonate_principal(credentials
,
567 cli_credentials_get_principal(cmdline_credentials
, tmp_ctx
),
568 talloc_asprintf(tmp_ctx
, "host/%s", test_machine_name
));
570 status
= gensec_client_start(tctx
, &gensec_client_context
,
571 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
));
572 torture_assert_ntstatus_ok(tctx
, status
, "gensec_client_start (client) failed");
574 status
= gensec_set_target_hostname(gensec_client_context
, test_machine_name
);
576 /* We now set the same credentials on both client and server contexts */
577 status
= gensec_set_credentials(gensec_client_context
, credentials
);
578 torture_assert_ntstatus_ok(tctx
, status
, "gensec_set_credentials (client) failed");
580 status
= gensec_start_mech_by_sasl_name(gensec_client_context
, "GSSAPI");
581 torture_assert_ntstatus_ok(tctx
, status
, "gensec_start_mech_by_sasl_name (client) failed");
583 status
= gensec_server_start(tctx
,
584 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
),
585 auth_context
, &gensec_server_context
);
586 torture_assert_ntstatus_ok(tctx
, status
, "gensec_server_start (server) failed");
588 status
= gensec_set_credentials(gensec_server_context
, credentials
);
589 torture_assert_ntstatus_ok(tctx
, status
, "gensec_set_credentials (server) failed");
591 status
= gensec_start_mech_by_sasl_name(gensec_server_context
, "GSSAPI");
592 torture_assert_ntstatus_ok(tctx
, status
, "gensec_start_mech_by_sasl_name (server) failed");
594 server_to_client
= data_blob(NULL
, 0);
597 /* Do a client-server update dance */
598 status
= gensec_update(gensec_client_context
, tmp_ctx
, tctx
->ev
, server_to_client
, &client_to_server
);
599 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {;
600 torture_assert_ntstatus_ok(tctx
, status
, "gensec_update (client) failed");
603 status
= gensec_update(gensec_server_context
, tmp_ctx
, tctx
->ev
, client_to_server
, &server_to_client
);
604 if (!NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {;
605 torture_assert_ntstatus_ok(tctx
, status
, "gensec_update (server) failed");
608 if (NT_STATUS_IS_OK(status
)) {
613 /* Don't pollute the remaining tests with the changed credentials */
614 cli_credentials_invalidate_ccache(credentials
, CRED_SPECIFIED
);
615 cli_credentials_set_target_service(credentials
, NULL
);
616 cli_credentials_set_impersonate_principal(credentials
, NULL
, NULL
);
618 /* Extract the PAC using Samba's code */
620 status
= gensec_session_info(gensec_server_context
, gensec_server_context
, &s2u4self_session_info
);
621 torture_assert_ntstatus_ok(tctx
, status
, "gensec_session_info failed");
623 cli_credentials_get_ntlm_username_domain(cmdline_credentials
, tctx
,
624 &ninfo
.identity_info
.account_name
.string
,
625 &ninfo
.identity_info
.domain_name
.string
);
627 /* Now try with SamLogon */
628 generate_random_buffer(ninfo
.challenge
,
629 sizeof(ninfo
.challenge
));
630 chal
= data_blob_const(ninfo
.challenge
,
631 sizeof(ninfo
.challenge
));
633 names_blob
= NTLMv2_generate_names_blob(tctx
, cli_credentials_get_workstation(credentials
),
634 cli_credentials_get_domain(credentials
));
636 status
= cli_credentials_get_ntlm_response(cmdline_credentials
, tctx
,
642 torture_assert_ntstatus_ok(tctx
, status
, "cli_credentials_get_ntlm_response failed");
644 ninfo
.lm
.data
= lm_resp
.data
;
645 ninfo
.lm
.length
= lm_resp
.length
;
647 ninfo
.nt
.data
= nt_resp
.data
;
648 ninfo
.nt
.length
= nt_resp
.length
;
650 ninfo
.identity_info
.parameter_control
= 0;
651 ninfo
.identity_info
.logon_id_low
= 0;
652 ninfo
.identity_info
.logon_id_high
= 0;
653 ninfo
.identity_info
.workstation
.string
= cli_credentials_get_workstation(credentials
);
655 logon
.network
= &ninfo
;
657 r
.in
.server_name
= talloc_asprintf(tctx
, "\\\\%s", dcerpc_server_name(p
));
658 r
.in
.computer_name
= cli_credentials_get_workstation(credentials
);
659 r
.in
.credential
= &auth
;
660 r
.in
.return_authenticator
= &auth2
;
661 r
.in
.logon_level
= 2;
663 r
.out
.validation
= &validation
;
664 r
.out
.authoritative
= &authoritative
;
666 if (!test_SetupCredentials2(p
, tctx
, NETLOGON_NEG_AUTH2_ADS_FLAGS
,
667 credentials
, secure_channel_type
,
673 netlogon_creds_client_authenticator(creds
, &auth
);
675 r
.in
.validation_level
= 3;
677 status
= dcerpc_netr_LogonSamLogon_r(b
, tctx
, &r
);
678 torture_assert_ntstatus_ok(tctx
, status
, "LogonSamLogon failed");
680 torture_assert(tctx
, netlogon_creds_client_check(creds
,
681 &r
.out
.return_authenticator
->cred
),
682 "Credential chaining failed");
684 status
= make_user_info_dc_netlogon_validation(tmp_ctx
,
685 ninfo
.identity_info
.account_name
.string
,
686 r
.in
.validation_level
,
688 true, /* This user was authenticated */
689 &netlogon_user_info_dc
);
691 torture_assert_ntstatus_ok(tctx
, status
, "make_user_info_dc_netlogon_validation failed");
693 torture_assert_str_equal(tctx
, netlogon_user_info_dc
->info
->account_name
== NULL
? "" : netlogon_user_info_dc
->info
->account_name
,
694 kinit_session_info
->info
->account_name
, "Account name differs for kinit-based PAC");
695 torture_assert_str_equal(tctx
,netlogon_user_info_dc
->info
->account_name
== NULL
? "" : netlogon_user_info_dc
->info
->account_name
,
696 s2u4self_session_info
->info
->account_name
, "Account name differs for S2U4Self");
697 torture_assert_str_equal(tctx
, netlogon_user_info_dc
->info
->full_name
== NULL
? "" : netlogon_user_info_dc
->info
->full_name
, kinit_session_info
->info
->full_name
, "Full name differs for kinit-based PAC");
698 torture_assert_str_equal(tctx
, netlogon_user_info_dc
->info
->full_name
== NULL
? "" : netlogon_user_info_dc
->info
->full_name
, s2u4self_session_info
->info
->full_name
, "Full name differs for S2U4Self");
699 torture_assert_int_equal(tctx
, netlogon_user_info_dc
->num_sids
, kinit_session_info
->torture
->num_dc_sids
, "Different numbers of domain groups for kinit-based PAC");
700 torture_assert_int_equal(tctx
, netlogon_user_info_dc
->num_sids
, s2u4self_session_info
->torture
->num_dc_sids
, "Different numbers of domain groups for S2U4Self");
702 builtin_domain
= dom_sid_parse_talloc(tmp_ctx
, SID_BUILTIN
);
704 for (i
= 0; i
< kinit_session_info
->torture
->num_dc_sids
; i
++) {
705 torture_assert(tctx
, dom_sid_equal(&netlogon_user_info_dc
->sids
[i
], &kinit_session_info
->torture
->dc_sids
[i
]), "Different domain groups for kinit-based PAC");
706 torture_assert(tctx
, dom_sid_equal(&netlogon_user_info_dc
->sids
[i
], &s2u4self_session_info
->torture
->dc_sids
[i
]), "Different domain groups for S2U4Self");
707 torture_assert(tctx
, !dom_sid_in_domain(builtin_domain
, &s2u4self_session_info
->torture
->dc_sids
[i
]), "Returned BUILTIN domain in groups for S2U4Self");
708 torture_assert(tctx
, !dom_sid_in_domain(builtin_domain
, &kinit_session_info
->torture
->dc_sids
[i
]), "Returned BUILTIN domain in groups kinit-based PAC");
709 torture_assert(tctx
, !dom_sid_in_domain(builtin_domain
, &netlogon_user_info_dc
->sids
[i
]), "Returned BUILTIN domian in groups from NETLOGON SamLogon reply");
715 static bool test_S2U4Self_bdc(struct torture_context
*tctx
,
716 struct dcerpc_pipe
*p
,
717 struct cli_credentials
*credentials
)
719 return test_S2U4Self(tctx
, p
, credentials
, SEC_CHAN_BDC
, TEST_MACHINE_NAME_S2U4SELF_BDC
);
722 static bool test_S2U4Self_workstation(struct torture_context
*tctx
,
723 struct dcerpc_pipe
*p
,
724 struct cli_credentials
*credentials
)
726 return test_S2U4Self(tctx
, p
, credentials
, SEC_CHAN_WKSTA
, TEST_MACHINE_NAME_S2U4SELF_WKSTA
);
729 struct torture_suite
*torture_rpc_remote_pac(TALLOC_CTX
*mem_ctx
)
731 struct torture_suite
*suite
= torture_suite_create(mem_ctx
, "pac");
732 struct torture_rpc_tcase
*tcase
;
734 /* It is important to use different names, so that old entries in our credential cache are not used */
735 tcase
= torture_suite_add_machine_bdc_rpc_iface_tcase(suite
, "netlogon-bdc",
736 &ndr_table_netlogon
, TEST_MACHINE_NAME_BDC
);
737 torture_rpc_tcase_add_test_creds(tcase
, "verify-sig", test_PACVerify_bdc
);
739 tcase
= torture_suite_add_machine_workstation_rpc_iface_tcase(suite
, "netlogon-member",
740 &ndr_table_netlogon
, TEST_MACHINE_NAME_WKSTA
);
741 torture_rpc_tcase_add_test_creds(tcase
, "verify-sig", test_PACVerify_workstation
);
743 tcase
= torture_suite_add_machine_workstation_rpc_iface_tcase(suite
, "netlogon-member-des",
744 &ndr_table_netlogon
, TEST_MACHINE_NAME_WKSTA_DES
);
745 torture_rpc_tcase_add_test_join(tcase
, "verify-sig", test_PACVerify_workstation_des
);
747 tcase
= torture_suite_add_machine_bdc_rpc_iface_tcase(suite
, "netlogon-bdc",
748 &ndr_table_netlogon
, TEST_MACHINE_NAME_S2U4SELF_BDC
);
749 torture_rpc_tcase_add_test_creds(tcase
, "s2u4self", test_S2U4Self_bdc
);
751 tcase
= torture_suite_add_machine_workstation_rpc_iface_tcase(suite
, "netlogon-member",
752 &ndr_table_netlogon
, TEST_MACHINE_NAME_S2U4SELF_WKSTA
);
754 torture_rpc_tcase_add_test_creds(tcase
, "s2u4self", test_S2U4Self_workstation
);