s4:kdc: provide a PAC_CREDENTIAL_INFO element for PKINIT logons
[Samba.git] / source4 / kdc / pac-glue.c
blob0b9fd12b764f03381c38a617a57694d379da48d4
1 /*
2 Unix SMB/CIFS implementation.
4 PAC Glue between Samba and the KDC
6 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2005-2009
7 Copyright (C) Simo Sorce <idra@samba.org> 2010
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "includes.h"
25 #include "../libds/common/flags.h"
26 #include <ldb.h>
27 #include "auth/auth.h"
28 #include "auth/auth_sam_reply.h"
29 #include "system/kerberos.h"
30 #include "auth/kerberos/kerberos.h"
31 #include "kdc/samba_kdc.h"
32 #include "kdc/pac-glue.h"
33 #include "param/param.h"
34 #include "librpc/gen_ndr/ndr_krb5pac.h"
35 #include "libcli/security/security.h"
36 #include "dsdb/samdb/samdb.h"
37 #include "auth/kerberos/pac_utils.h"
39 static
40 NTSTATUS samba_get_logon_info_pac_blob(TALLOC_CTX *mem_ctx,
41 const struct auth_user_info_dc *info,
42 DATA_BLOB *pac_data)
44 struct netr_SamInfo3 *info3;
45 union PAC_INFO pac_info;
46 enum ndr_err_code ndr_err;
47 NTSTATUS nt_status;
49 ZERO_STRUCT(pac_info);
51 *pac_data = data_blob_null;
53 nt_status = auth_convert_user_info_dc_saminfo3(mem_ctx, info, &info3);
54 if (!NT_STATUS_IS_OK(nt_status)) {
55 DEBUG(1, ("Getting Samba info failed: %s\n",
56 nt_errstr(nt_status)));
57 return nt_status;
60 pac_info.logon_info.info = talloc_zero(mem_ctx, struct PAC_LOGON_INFO);
61 if (!pac_info.logon_info.info) {
62 return NT_STATUS_NO_MEMORY;
65 pac_info.logon_info.info->info3 = *info3;
67 ndr_err = ndr_push_union_blob(pac_data, mem_ctx, &pac_info,
68 PAC_TYPE_LOGON_INFO,
69 (ndr_push_flags_fn_t)ndr_push_PAC_INFO);
70 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
71 nt_status = ndr_map_error2ntstatus(ndr_err);
72 DEBUG(1, ("PAC_LOGON_INFO (presig) push failed: %s\n",
73 nt_errstr(nt_status)));
74 return nt_status;
77 return NT_STATUS_OK;
80 static
81 NTSTATUS samba_get_cred_info_ndr_blob(TALLOC_CTX *mem_ctx,
82 const struct ldb_message *msg,
83 DATA_BLOB *cred_blob)
85 enum ndr_err_code ndr_err;
86 NTSTATUS nt_status;
87 int ret;
88 static const struct samr_Password zero_hash;
89 struct samr_Password *lm_hash = NULL;
90 struct samr_Password *nt_hash = NULL;
91 struct PAC_CREDENTIAL_NTLM_SECPKG ntlm_secpkg = {
92 .version = 0,
94 DATA_BLOB ntlm_blob = data_blob_null;
95 struct PAC_CREDENTIAL_SUPPLEMENTAL_SECPKG secpkgs[1] = {{
96 .credential_size = 0,
97 }};
98 struct PAC_CREDENTIAL_DATA cred_data = {
99 .credential_count = 0,
101 struct PAC_CREDENTIAL_DATA_NDR cred_ndr;
103 ZERO_STRUCT(cred_ndr);
105 *cred_blob = data_blob_null;
107 lm_hash = samdb_result_hash(mem_ctx, msg, "dBCSPwd");
108 if (lm_hash != NULL) {
109 ret = memcmp(lm_hash->hash, zero_hash.hash, 16);
110 if (ret == 0) {
111 lm_hash = NULL;
114 if (lm_hash != NULL) {
115 DEBUG(5, ("Passing LM password hash through credentials set\n"));
116 ntlm_secpkg.flags |= PAC_CREDENTIAL_NTLM_HAS_LM_HASH;
117 ntlm_secpkg.lm_password = *lm_hash;
118 ZERO_STRUCTP(lm_hash);
119 TALLOC_FREE(lm_hash);
122 nt_hash = samdb_result_hash(mem_ctx, msg, "unicodePwd");
123 if (nt_hash != NULL) {
124 ret = memcmp(nt_hash->hash, zero_hash.hash, 16);
125 if (ret == 0) {
126 nt_hash = NULL;
129 if (nt_hash != NULL) {
130 DEBUG(5, ("Passing LM password hash through credentials set\n"));
131 ntlm_secpkg.flags |= PAC_CREDENTIAL_NTLM_HAS_NT_HASH;
132 ntlm_secpkg.nt_password = *nt_hash;
133 ZERO_STRUCTP(nt_hash);
134 TALLOC_FREE(nt_hash);
137 if (ntlm_secpkg.flags == 0) {
138 return NT_STATUS_OK;
141 #ifdef DEBUG_PASSWORD
142 if (DEBUGLVL(11)) {
143 NDR_PRINT_DEBUG(PAC_CREDENTIAL_NTLM_SECPKG, &ntlm_secpkg);
145 #endif
147 ndr_err = ndr_push_struct_blob(&ntlm_blob, mem_ctx, &ntlm_secpkg,
148 (ndr_push_flags_fn_t)ndr_push_PAC_CREDENTIAL_NTLM_SECPKG);
149 ZERO_STRUCT(ntlm_secpkg);
150 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
151 nt_status = ndr_map_error2ntstatus(ndr_err);
152 DEBUG(1, ("PAC_CREDENTIAL_NTLM_SECPKG (presig) push failed: %s\n",
153 nt_errstr(nt_status)));
154 return nt_status;
157 DEBUG(10, ("NTLM credential BLOB (len %zu) for user\n",
158 ntlm_blob.length));
159 dump_data_pw("PAC_CREDENTIAL_NTLM_SECPKG",
160 ntlm_blob.data, ntlm_blob.length);
162 secpkgs[0].package_name.string = discard_const_p(char, "NTLM");
163 secpkgs[0].credential_size = ntlm_blob.length;
164 secpkgs[0].credential = ntlm_blob.data;
166 cred_data.credential_count = ARRAY_SIZE(secpkgs);
167 cred_data.credentials = secpkgs;
169 #ifdef DEBUG_PASSWORD
170 if (DEBUGLVL(11)) {
171 NDR_PRINT_DEBUG(PAC_CREDENTIAL_DATA, &cred_data);
173 #endif
175 cred_ndr.ctr.data = &cred_data;
177 #ifdef DEBUG_PASSWORD
178 if (DEBUGLVL(11)) {
179 NDR_PRINT_DEBUG(PAC_CREDENTIAL_DATA_NDR, &cred_ndr);
181 #endif
183 ndr_err = ndr_push_struct_blob(cred_blob, mem_ctx, &cred_ndr,
184 (ndr_push_flags_fn_t)ndr_push_PAC_CREDENTIAL_DATA_NDR);
185 data_blob_clear(&ntlm_blob);
186 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
187 nt_status = ndr_map_error2ntstatus(ndr_err);
188 DEBUG(1, ("PAC_CREDENTIAL_DATA_NDR (presig) push failed: %s\n",
189 nt_errstr(nt_status)));
190 return nt_status;
193 DEBUG(10, ("Created credential BLOB (len %zu) for user\n",
194 cred_blob->length));
195 dump_data_pw("PAC_CREDENTIAL_DATA_NDR",
196 cred_blob->data, cred_blob->length);
198 return NT_STATUS_OK;
201 krb5_error_code samba_kdc_encrypt_pac_credentials(krb5_context context,
202 const krb5_keyblock *pkreplykey,
203 const DATA_BLOB *cred_ndr_blob,
204 TALLOC_CTX *mem_ctx,
205 DATA_BLOB *cred_info_blob)
207 krb5_crypto cred_crypto;
208 krb5_enctype cred_enctype;
209 krb5_data cred_ndr_crypt;
210 struct PAC_CREDENTIAL_INFO pac_cred_info = { .version = 0, };
211 krb5_error_code ret;
212 const char *krb5err;
213 enum ndr_err_code ndr_err;
214 NTSTATUS nt_status;
216 *cred_info_blob = data_blob_null;
218 ret = krb5_crypto_init(context, pkreplykey, ETYPE_NULL,
219 &cred_crypto);
220 if (ret != 0) {
221 krb5err = krb5_get_error_message(context, ret);
222 DEBUG(1, ("Failed initializing cred data crypto: %s\n", krb5err));
223 krb5_free_error_message(context, krb5err);
224 return ret;
227 ret = krb5_crypto_getenctype(context, cred_crypto, &cred_enctype);
228 if (ret != 0) {
229 DEBUG(1, ("Failed getting crypto type for key\n"));
230 krb5_crypto_destroy(context, cred_crypto);
231 return ret;
234 DEBUG(10, ("Plain cred_ndr_blob (len %zu)\n",
235 cred_ndr_blob->length));
236 dump_data_pw("PAC_CREDENTIAL_DATA_NDR",
237 cred_ndr_blob->data, cred_ndr_blob->length);
239 ret = krb5_encrypt(context, cred_crypto,
240 KRB5_KU_OTHER_ENCRYPTED,
241 cred_ndr_blob->data, cred_ndr_blob->length,
242 &cred_ndr_crypt);
243 krb5_crypto_destroy(context, cred_crypto);
244 if (ret != 0) {
245 krb5err = krb5_get_error_message(context, ret);
246 DEBUG(1, ("Failed crypt of cred data: %s\n", krb5err));
247 krb5_free_error_message(context, krb5err);
248 return ret;
251 pac_cred_info.encryption_type = cred_enctype;
252 pac_cred_info.encrypted_data.length = cred_ndr_crypt.length;
253 pac_cred_info.encrypted_data.data = (uint8_t *)cred_ndr_crypt.data;
255 if (DEBUGLVL(10)) {
256 NDR_PRINT_DEBUG(PAC_CREDENTIAL_INFO, &pac_cred_info);
259 ndr_err = ndr_push_struct_blob(cred_info_blob, mem_ctx, &pac_cred_info,
260 (ndr_push_flags_fn_t)ndr_push_PAC_CREDENTIAL_INFO);
261 krb5_data_free(&cred_ndr_crypt);
262 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
263 nt_status = ndr_map_error2ntstatus(ndr_err);
264 DEBUG(1, ("PAC_CREDENTIAL_INFO (presig) push failed: %s\n",
265 nt_errstr(nt_status)));
266 return KRB5KDC_ERR_SVC_UNAVAILABLE;
269 DEBUG(10, ("Encrypted credential BLOB (len %zu) with alg %d\n",
270 cred_info_blob->length, (int)pac_cred_info.encryption_type));
271 dump_data_pw("PAC_CREDENTIAL_INFO",
272 cred_info_blob->data, cred_info_blob->length);
274 return 0;
277 krb5_error_code samba_make_krb5_pac(krb5_context context,
278 const DATA_BLOB *logon_blob,
279 const DATA_BLOB *cred_blob,
280 const DATA_BLOB *deleg_blob,
281 krb5_pac *pac)
283 krb5_data logon_data;
284 krb5_data cred_data;
285 krb5_data deleg_data;
286 krb5_data null_data;
287 krb5_error_code ret;
289 ZERO_STRUCT(null_data);
291 /* The user account may be set not to want the PAC */
292 if (logon_blob == NULL) {
293 return 0;
296 ret = krb5_copy_data_contents(&logon_data,
297 logon_blob->data,
298 logon_blob->length);
299 if (ret != 0) {
300 return ret;
303 ZERO_STRUCT(cred_data);
304 if (cred_blob != NULL) {
305 ret = krb5_copy_data_contents(&cred_data,
306 cred_blob->data,
307 cred_blob->length);
308 if (ret != 0) {
309 kerberos_free_data_contents(context, &logon_data);
310 return ret;
314 ZERO_STRUCT(deleg_data);
315 if (deleg_blob != NULL) {
316 ret = krb5_copy_data_contents(&deleg_data,
317 deleg_blob->data,
318 deleg_blob->length);
319 if (ret != 0) {
320 kerberos_free_data_contents(context, &logon_data);
321 kerberos_free_data_contents(context, &cred_data);
322 return ret;
326 ret = krb5_pac_init(context, pac);
327 if (ret != 0) {
328 kerberos_free_data_contents(context, &logon_data);
329 kerberos_free_data_contents(context, &cred_data);
330 kerberos_free_data_contents(context, &deleg_data);
331 return ret;
334 ret = krb5_pac_add_buffer(context, *pac, PAC_TYPE_LOGON_INFO, &logon_data);
335 kerberos_free_data_contents(context, &logon_data);
336 if (ret != 0) {
337 kerberos_free_data_contents(context, &cred_data);
338 kerberos_free_data_contents(context, &deleg_data);
339 return ret;
342 if (cred_blob != NULL) {
343 ret = krb5_pac_add_buffer(context, *pac,
344 PAC_TYPE_CREDENTIAL_INFO,
345 &cred_data);
346 kerberos_free_data_contents(context, &cred_data);
347 if (ret != 0) {
348 kerberos_free_data_contents(context, &deleg_data);
349 return ret;
353 if (deleg_blob != NULL) {
354 ret = krb5_pac_add_buffer(context, *pac,
355 PAC_TYPE_CONSTRAINED_DELEGATION,
356 &deleg_data);
357 kerberos_free_data_contents(context, &deleg_data);
358 if (ret != 0) {
359 return ret;
363 return ret;
366 bool samba_princ_needs_pac(struct samba_kdc_entry *skdc_entry)
369 uint32_t userAccountControl;
371 /* The service account may be set not to want the PAC */
372 userAccountControl = ldb_msg_find_attr_as_uint(skdc_entry->msg, "userAccountControl", 0);
373 if (userAccountControl & UF_NO_AUTH_DATA_REQUIRED) {
374 return false;
377 return true;
380 /* Was the krbtgt in this DB (ie, should we check the incoming signature) and was it an RODC */
381 int samba_krbtgt_is_in_db(struct samba_kdc_entry *p,
382 bool *is_in_db,
383 bool *is_untrusted)
385 NTSTATUS status;
386 int rodc_krbtgt_number, trust_direction;
387 uint32_t rid;
389 TALLOC_CTX *mem_ctx = talloc_new(NULL);
390 if (!mem_ctx) {
391 return ENOMEM;
394 trust_direction = ldb_msg_find_attr_as_int(p->msg, "trustDirection", 0);
396 if (trust_direction != 0) {
397 /* Domain trust - we cannot check the sig, but we trust it for a correct PAC
399 This is exactly where we should flag for SID
400 validation when we do inter-foreest trusts
402 talloc_free(mem_ctx);
403 *is_untrusted = false;
404 *is_in_db = false;
405 return 0;
408 /* The lack of password controls etc applies to krbtgt by
409 * virtue of being that particular RID */
410 status = dom_sid_split_rid(NULL, samdb_result_dom_sid(mem_ctx, p->msg, "objectSid"), NULL, &rid);
412 if (!NT_STATUS_IS_OK(status)) {
413 talloc_free(mem_ctx);
414 return EINVAL;
417 rodc_krbtgt_number = ldb_msg_find_attr_as_int(p->msg, "msDS-SecondaryKrbTgtNumber", -1);
419 if (p->kdc_db_ctx->my_krbtgt_number == 0) {
420 if (rid == DOMAIN_RID_KRBTGT) {
421 *is_untrusted = false;
422 *is_in_db = true;
423 talloc_free(mem_ctx);
424 return 0;
425 } else if (rodc_krbtgt_number != -1) {
426 *is_in_db = true;
427 *is_untrusted = true;
428 talloc_free(mem_ctx);
429 return 0;
431 } else if ((rid != DOMAIN_RID_KRBTGT) && (rodc_krbtgt_number == p->kdc_db_ctx->my_krbtgt_number)) {
432 talloc_free(mem_ctx);
433 *is_untrusted = false;
434 *is_in_db = true;
435 return 0;
436 } else if (rid == DOMAIN_RID_KRBTGT) {
437 /* krbtgt viewed from an RODC */
438 talloc_free(mem_ctx);
439 *is_untrusted = false;
440 *is_in_db = false;
441 return 0;
444 /* Another RODC */
445 talloc_free(mem_ctx);
446 *is_untrusted = true;
447 *is_in_db = false;
448 return 0;
451 NTSTATUS samba_kdc_get_pac_blobs(TALLOC_CTX *mem_ctx,
452 struct samba_kdc_entry *p,
453 DATA_BLOB **_logon_info_blob,
454 DATA_BLOB **_cred_ndr_blob)
456 struct auth_user_info_dc *user_info_dc;
457 DATA_BLOB *logon_blob = NULL;
458 DATA_BLOB *cred_blob = NULL;
459 NTSTATUS nt_status;
461 *_logon_info_blob = NULL;
462 if (_cred_ndr_blob != NULL) {
463 *_cred_ndr_blob = NULL;
466 /* The user account may be set not to want the PAC */
467 if ( ! samba_princ_needs_pac(p)) {
468 return NT_STATUS_OK;
471 logon_blob = talloc_zero(mem_ctx, DATA_BLOB);
472 if (logon_blob == NULL) {
473 return NT_STATUS_NO_MEMORY;
476 if (_cred_ndr_blob != NULL) {
477 cred_blob = talloc_zero(mem_ctx, DATA_BLOB);
478 if (cred_blob == NULL) {
479 return NT_STATUS_NO_MEMORY;
483 nt_status = authsam_make_user_info_dc(mem_ctx, p->kdc_db_ctx->samdb,
484 lpcfg_netbios_name(p->kdc_db_ctx->lp_ctx),
485 lpcfg_sam_name(p->kdc_db_ctx->lp_ctx),
486 lpcfg_sam_dnsname(p->kdc_db_ctx->lp_ctx),
487 p->realm_dn,
488 p->msg,
489 data_blob(NULL, 0),
490 data_blob(NULL, 0),
491 &user_info_dc);
492 if (!NT_STATUS_IS_OK(nt_status)) {
493 DEBUG(0, ("Getting user info for PAC failed: %s\n",
494 nt_errstr(nt_status)));
495 return nt_status;
498 nt_status = samba_get_logon_info_pac_blob(logon_blob,
499 user_info_dc,
500 logon_blob);
501 if (!NT_STATUS_IS_OK(nt_status)) {
502 DEBUG(0, ("Building PAC LOGON INFO failed: %s\n",
503 nt_errstr(nt_status)));
504 return nt_status;
507 if (cred_blob != NULL) {
508 nt_status = samba_get_cred_info_ndr_blob(cred_blob,
509 p->msg,
510 cred_blob);
511 if (!NT_STATUS_IS_OK(nt_status)) {
512 DEBUG(0, ("Building PAC CRED INFO failed: %s\n",
513 nt_errstr(nt_status)));
514 return nt_status;
518 TALLOC_FREE(user_info_dc);
519 *_logon_info_blob = logon_blob;
520 if (_cred_ndr_blob != NULL) {
521 *_cred_ndr_blob = cred_blob;
523 return NT_STATUS_OK;
526 NTSTATUS samba_kdc_get_pac_blob(TALLOC_CTX *mem_ctx,
527 struct samba_kdc_entry *p,
528 DATA_BLOB **_logon_info_blob)
530 NTSTATUS nt_status;
532 nt_status = samba_kdc_get_pac_blobs(mem_ctx, p,
533 _logon_info_blob,
534 NULL);
535 if (!NT_STATUS_IS_OK(nt_status)) {
536 return nt_status;
539 return NT_STATUS_OK;
542 NTSTATUS samba_kdc_update_pac_blob(TALLOC_CTX *mem_ctx,
543 krb5_context context,
544 const krb5_pac pac, DATA_BLOB *pac_blob,
545 struct PAC_SIGNATURE_DATA *pac_srv_sig,
546 struct PAC_SIGNATURE_DATA *pac_kdc_sig)
548 struct auth_user_info_dc *user_info_dc;
549 krb5_error_code ret;
550 NTSTATUS nt_status;
552 ret = kerberos_pac_to_user_info_dc(mem_ctx, pac,
553 context, &user_info_dc, pac_srv_sig, pac_kdc_sig);
554 if (ret) {
555 return NT_STATUS_UNSUCCESSFUL;
558 nt_status = samba_get_logon_info_pac_blob(mem_ctx,
559 user_info_dc, pac_blob);
561 return nt_status;
564 NTSTATUS samba_kdc_update_delegation_info_blob(TALLOC_CTX *mem_ctx,
565 krb5_context context,
566 const krb5_pac pac,
567 const krb5_principal server_principal,
568 const krb5_principal proxy_principal,
569 DATA_BLOB *new_blob)
571 krb5_data old_data;
572 DATA_BLOB old_blob;
573 krb5_error_code ret;
574 NTSTATUS nt_status;
575 enum ndr_err_code ndr_err;
576 union PAC_INFO info;
577 struct PAC_CONSTRAINED_DELEGATION _d;
578 struct PAC_CONSTRAINED_DELEGATION *d = NULL;
579 char *server = NULL;
580 char *proxy = NULL;
581 uint32_t i;
582 TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
584 if (tmp_ctx == NULL) {
585 return NT_STATUS_NO_MEMORY;
588 ret = krb5_pac_get_buffer(context, pac, PAC_TYPE_CONSTRAINED_DELEGATION, &old_data);
589 if (ret == ENOENT) {
590 ZERO_STRUCT(old_data);
591 } else if (ret) {
592 talloc_free(tmp_ctx);
593 return NT_STATUS_UNSUCCESSFUL;
596 old_blob.length = old_data.length;
597 old_blob.data = (uint8_t *)old_data.data;
599 ZERO_STRUCT(info);
600 if (old_blob.length > 0) {
601 ndr_err = ndr_pull_union_blob(&old_blob, mem_ctx,
602 &info, PAC_TYPE_CONSTRAINED_DELEGATION,
603 (ndr_pull_flags_fn_t)ndr_pull_PAC_INFO);
604 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
605 kerberos_free_data_contents(context, &old_data);
606 nt_status = ndr_map_error2ntstatus(ndr_err);
607 DEBUG(0,("can't parse the PAC LOGON_INFO: %s\n", nt_errstr(nt_status)));
608 talloc_free(tmp_ctx);
609 return nt_status;
611 } else {
612 ZERO_STRUCT(_d);
613 info.constrained_delegation.info = &_d;
615 kerberos_free_data_contents(context, &old_data);
617 ret = krb5_unparse_name(context, server_principal, &server);
618 if (ret) {
619 talloc_free(tmp_ctx);
620 return NT_STATUS_INTERNAL_ERROR;
623 ret = krb5_unparse_name_flags(context, proxy_principal,
624 KRB5_PRINCIPAL_UNPARSE_NO_REALM, &proxy);
625 if (ret) {
626 SAFE_FREE(server);
627 talloc_free(tmp_ctx);
628 return NT_STATUS_INTERNAL_ERROR;
631 d = info.constrained_delegation.info;
632 i = d->num_transited_services;
633 d->proxy_target.string = server;
634 d->transited_services = talloc_realloc(mem_ctx, d->transited_services,
635 struct lsa_String, i + 1);
636 d->transited_services[i].string = proxy;
637 d->num_transited_services = i + 1;
639 ndr_err = ndr_push_union_blob(new_blob, mem_ctx,
640 &info, PAC_TYPE_CONSTRAINED_DELEGATION,
641 (ndr_push_flags_fn_t)ndr_push_PAC_INFO);
642 SAFE_FREE(server);
643 SAFE_FREE(proxy);
644 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
645 kerberos_free_data_contents(context, &old_data);
646 nt_status = ndr_map_error2ntstatus(ndr_err);
647 DEBUG(0,("can't parse the PAC LOGON_INFO: %s\n", nt_errstr(nt_status)));
648 talloc_free(tmp_ctx);
649 return nt_status;
652 talloc_free(tmp_ctx);
653 return NT_STATUS_OK;
656 /* function to map policy errors */
657 krb5_error_code samba_kdc_map_policy_err(NTSTATUS nt_status)
659 krb5_error_code ret;
661 if (NT_STATUS_EQUAL(nt_status, NT_STATUS_PASSWORD_MUST_CHANGE))
662 ret = KRB5KDC_ERR_KEY_EXP;
663 else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_PASSWORD_EXPIRED))
664 ret = KRB5KDC_ERR_KEY_EXP;
665 else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_ACCOUNT_EXPIRED))
666 ret = KRB5KDC_ERR_CLIENT_REVOKED;
667 else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_ACCOUNT_DISABLED))
668 ret = KRB5KDC_ERR_CLIENT_REVOKED;
669 else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_INVALID_LOGON_HOURS))
670 ret = KRB5KDC_ERR_CLIENT_REVOKED;
671 else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_ACCOUNT_LOCKED_OUT))
672 ret = KRB5KDC_ERR_CLIENT_REVOKED;
673 else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_INVALID_WORKSTATION))
674 ret = KRB5KDC_ERR_POLICY;
675 else
676 ret = KRB5KDC_ERR_POLICY;
678 return ret;
681 /* Given a kdc entry, consult the account_ok routine in auth/auth_sam.c
682 * for consistency */
683 NTSTATUS samba_kdc_check_client_access(struct samba_kdc_entry *kdc_entry,
684 const char *client_name,
685 const char *workstation,
686 bool password_change)
688 TALLOC_CTX *tmp_ctx;
689 NTSTATUS nt_status;
691 tmp_ctx = talloc_named(NULL, 0, "samba_kdc_check_client_access");
692 if (!tmp_ctx) {
693 return NT_STATUS_NO_MEMORY;
696 /* we allow all kinds of trusts here */
697 nt_status = authsam_account_ok(tmp_ctx,
698 kdc_entry->kdc_db_ctx->samdb,
699 MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT |
700 MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT,
701 kdc_entry->realm_dn, kdc_entry->msg,
702 workstation, client_name,
703 true, password_change);
705 talloc_free(tmp_ctx);
706 return nt_status;