4 Copyright (c) 2010, Simo Sorce <idra@samba.org>
5 Copyright (c) 2014-2015 Guenther Deschner <gd@samba.org>
6 Copyright (c) 2014-2016 Andreas Schneider <asn@samba.org>
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 #define TEVENT_DEPRECATED 1
25 #include "param/param.h"
26 #include "dsdb/samdb/samdb.h"
27 #include "system/kerberos.h"
30 #include <kadm5/kadm_err.h>
32 #include "kdc/sdb_kdb.h"
33 #include "auth/kerberos/kerberos.h"
34 #include "auth/kerberos/pac_utils.h"
35 #include "kdc/samba_kdc.h"
36 #include "kdc/pac-glue.h"
37 #include "kdc/db-glue.h"
38 #include "auth/auth.h"
39 #include "kdc/kpasswd_glue.h"
40 #include "auth/auth_sam.h"
42 #include "mit_samba.h"
45 #define DBGC_CLASS DBGC_KERBEROS
47 void mit_samba_context_free(struct mit_samba_context *ctx)
49 /* free heimdal's krb5_context */
51 krb5_free_context(ctx->context);
54 /* then free everything else */
59 * Implemant a callback to log to the MIT KDC log facility
61 * http://web.mit.edu/kerberos/krb5-devel/doc/plugindev/general.html#logging-from-kdc-and-kadmind-plugin-modules
63 static void mit_samba_debug(void *private_ptr, int msg_level, const char *msg)
71 com_err("", is_error, "%s", msg);
74 int mit_samba_context_init(struct mit_samba_context **_ctx)
77 struct mit_samba_context *ctx;
78 const char *s4_conf_file;
80 struct samba_kdc_base_context base_ctx;
82 ctx = talloc_zero(NULL, struct mit_samba_context);
88 base_ctx.ev_ctx = tevent_context_init(ctx);
89 if (!base_ctx.ev_ctx) {
93 tevent_loop_allow_nesting(base_ctx.ev_ctx);
94 base_ctx.lp_ctx = loadparm_init_global(false);
95 if (!base_ctx.lp_ctx) {
100 debug_set_callback(NULL, mit_samba_debug);
102 /* init s4 configuration */
103 s4_conf_file = lpcfg_configfile(base_ctx.lp_ctx);
104 if (s4_conf_file != NULL) {
105 char *p = talloc_strdup(ctx, s4_conf_file);
110 lpcfg_load(base_ctx.lp_ctx, p);
113 lpcfg_load_default(base_ctx.lp_ctx);
116 status = samba_kdc_setup_db_ctx(ctx, &base_ctx, &ctx->db_ctx);
117 if (!NT_STATUS_IS_OK(status)) {
122 /* init heimdal's krb_context and log facilities */
123 ret = smb_krb5_init_context_basic(ctx,
134 mit_samba_context_free(ctx);
141 static krb5_error_code ks_is_tgs_principal(struct mit_samba_context *ctx,
142 krb5_const_principal principal)
147 p = smb_krb5_principal_get_comp_string(ctx, ctx->context, principal, 0);
149 eq = krb5_princ_size(ctx->context, principal) == 2 &&
150 (strcmp(p, KRB5_TGS_NAME) == 0);
157 int mit_samba_generate_salt(krb5_data *salt)
164 salt->data = malloc(salt->length);
165 if (salt->data == NULL) {
169 generate_random_buffer((uint8_t *)salt->data, salt->length);
174 int mit_samba_generate_random_password(krb5_data *pwd)
184 tmp_ctx = talloc_named(NULL,
186 "mit_samba_create_principal_password context");
187 if (tmp_ctx == NULL) {
191 password = generate_random_password(tmp_ctx, pwd->length, pwd->length);
192 if (password == NULL) {
193 talloc_free(tmp_ctx);
197 pwd->data = strdup(password);
198 talloc_free(tmp_ctx);
199 if (pwd->data == NULL) {
206 int mit_samba_get_principal(struct mit_samba_context *ctx,
207 krb5_const_principal principal,
209 krb5_db_entry **_kentry)
211 struct sdb_entry_ex sentry = {
214 krb5_db_entry *kentry;
217 krb5_principal referral_principal = NULL;
219 kentry = calloc(1, sizeof(krb5_db_entry));
220 if (kentry == NULL) {
224 if (kflags & KRB5_KDB_FLAG_CANONICALIZE) {
225 sflags |= SDB_F_CANON;
227 if (kflags & (KRB5_KDB_FLAG_CLIENT_REFERRALS_ONLY |
228 KRB5_KDB_FLAG_INCLUDE_PAC)) {
230 * KRB5_KDB_FLAG_CLIENT_REFERRALS_ONLY is equal to
233 * We use ANY to also allow AS_REQ for service principal names
234 * This is supported by Windows.
236 sflags |= SDB_F_GET_ANY|SDB_F_FOR_AS_REQ;
237 } else if (ks_is_tgs_principal(ctx, principal)) {
238 sflags |= SDB_F_GET_KRBTGT;
240 sflags |= SDB_F_GET_SERVER|SDB_F_FOR_TGS_REQ;
243 /* always set this or the created_by data will not be populated by samba's
244 * backend and we will fail to parse the entry later */
245 sflags |= SDB_F_ADMIN_DATA;
248 fetch_referral_principal:
249 ret = samba_kdc_fetch(ctx->context, ctx->db_ctx,
250 principal, sflags, 0, &sentry);
254 case SDB_ERR_NOENTRY:
255 ret = KRB5_KDB_NOENTRY;
257 case SDB_ERR_WRONG_REALM: {
258 char *dest_realm = NULL;
259 const char *our_realm = lpcfg_realm(ctx->db_ctx->lp_ctx);
261 if (sflags & SDB_F_FOR_AS_REQ) {
263 * If this is a request for a TGT, we are done. The KDC
264 * will return the correct error to the client.
270 if (referral_principal != NULL) {
271 sdb_free_entry(&sentry);
272 ret = KRB5_KDB_NOENTRY;
277 * We get a TGS request
279 * cifs/dc7.SAMBA2008R2.EXAMPLE.COM@ADDOM.SAMBA.EXAMPLE.COM
281 * to our DC for the realm
283 * ADDOM.SAMBA.EXAMPLE.COM
285 * We look up if we have and entry in the database and get an
286 * entry with the pricipal:
288 * cifs/dc7.SAMBA2008R2.EXAMPLE.COM@SAMBA2008R2.EXAMPLE.COM
290 * and the error: SDB_ERR_WRONG_REALM.
292 * In the case of a TGS-REQ we need to return a referral ticket
293 * fo the next trust hop to the client. This ticket will have
294 * the following principal:
296 * krbtgt/SAMBA2008R2.EXAMPLE.COM@ADDOM.SAMBA.EXAMPLE.COM
298 * We just redo the lookup in the database with the referral
299 * principal and return success.
301 dest_realm = smb_krb5_principal_get_realm(
302 ctx, ctx->context, sentry.entry.principal);
303 sdb_free_entry(&sentry);
304 if (dest_realm == NULL) {
305 ret = KRB5_KDB_NOENTRY;
309 ret = smb_krb5_make_principal(ctx->context,
315 TALLOC_FREE(dest_realm);
320 principal = referral_principal;
321 goto fetch_referral_principal;
323 case SDB_ERR_NOT_FOUND_HERE:
324 /* FIXME: RODC support */
329 ret = sdb_entry_ex_to_kdb_entry_ex(ctx->context, &sentry, kentry);
331 sdb_free_entry(&sentry);
334 krb5_free_principal(ctx->context, referral_principal);
335 referral_principal = NULL;
345 int mit_samba_get_firstkey(struct mit_samba_context *ctx,
346 krb5_db_entry **_kentry)
348 struct sdb_entry_ex sentry = {
351 krb5_db_entry *kentry;
354 kentry = malloc(sizeof(krb5_db_entry));
355 if (kentry == NULL) {
359 ret = samba_kdc_firstkey(ctx->context, ctx->db_ctx, &sentry);
363 case SDB_ERR_NOENTRY:
365 return KRB5_KDB_NOENTRY;
366 case SDB_ERR_NOT_FOUND_HERE:
367 /* FIXME: RODC support */
373 ret = sdb_entry_ex_to_kdb_entry_ex(ctx->context, &sentry, kentry);
375 sdb_free_entry(&sentry);
385 int mit_samba_get_nextkey(struct mit_samba_context *ctx,
386 krb5_db_entry **_kentry)
388 struct sdb_entry_ex sentry = {
391 krb5_db_entry *kentry;
394 kentry = malloc(sizeof(krb5_db_entry));
395 if (kentry == NULL) {
399 ret = samba_kdc_nextkey(ctx->context, ctx->db_ctx, &sentry);
403 case SDB_ERR_NOENTRY:
405 return KRB5_KDB_NOENTRY;
406 case SDB_ERR_NOT_FOUND_HERE:
407 /* FIXME: RODC support */
413 ret = sdb_entry_ex_to_kdb_entry_ex(ctx->context, &sentry, kentry);
415 sdb_free_entry(&sentry);
425 int mit_samba_get_pac(struct mit_samba_context *smb_ctx,
426 krb5_context context,
427 krb5_db_entry *client,
428 krb5_keyblock *client_key,
432 DATA_BLOB *logon_info_blob = NULL;
433 DATA_BLOB *upn_dns_info_blob = NULL;
434 DATA_BLOB *cred_ndr = NULL;
435 DATA_BLOB **cred_ndr_ptr = NULL;
436 DATA_BLOB cred_blob = data_blob_null;
437 DATA_BLOB *pcred_blob = NULL;
439 krb5_error_code code;
440 struct samba_kdc_entry *skdc_entry;
442 skdc_entry = talloc_get_type_abort(client->e_data,
443 struct samba_kdc_entry);
445 tmp_ctx = talloc_named(smb_ctx,
447 "mit_samba_get_pac_data_blobs context");
448 if (tmp_ctx == NULL) {
452 #if 0 /* TODO Find out if this is a pkinit_reply key */
453 /* Check if we have a PREAUTH key */
454 if (client_key != NULL) {
455 cred_ndr_ptr = &cred_ndr;
459 nt_status = samba_kdc_get_pac_blobs(tmp_ctx,
465 if (!NT_STATUS_IS_OK(nt_status)) {
466 talloc_free(tmp_ctx);
467 if (NT_STATUS_EQUAL(nt_status,
468 NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
474 if (cred_ndr != NULL) {
475 code = samba_kdc_encrypt_pac_credentials(context,
481 talloc_free(tmp_ctx);
484 pcred_blob = &cred_blob;
487 code = samba_make_krb5_pac(context,
495 talloc_free(tmp_ctx);
499 krb5_error_code mit_samba_reget_pac(struct mit_samba_context *ctx,
500 krb5_context context,
502 krb5_const_principal client_principal,
503 krb5_db_entry *client,
504 krb5_db_entry *server,
505 krb5_db_entry *krbtgt,
506 krb5_keyblock *krbtgt_keyblock,
510 krb5_error_code code;
512 DATA_BLOB *pac_blob = NULL;
513 DATA_BLOB *upn_blob = NULL;
514 DATA_BLOB *deleg_blob = NULL;
515 struct samba_kdc_entry *client_skdc_entry = NULL;
516 struct samba_kdc_entry *krbtgt_skdc_entry = NULL;
517 struct samba_kdc_entry *server_skdc_entry = NULL;
518 bool is_in_db = false;
519 bool is_untrusted = false;
520 size_t num_types = 0;
521 uint32_t *types = NULL;
522 uint32_t forced_next_type = 0;
524 ssize_t logon_info_idx = -1;
525 ssize_t delegation_idx = -1;
526 ssize_t logon_name_idx = -1;
527 ssize_t upn_dns_info_idx = -1;
528 ssize_t srv_checksum_idx = -1;
529 ssize_t kdc_checksum_idx = -1;
530 krb5_pac new_pac = NULL;
533 /* Create a memory context early so code can use talloc_stackframe() */
534 tmp_ctx = talloc_named(ctx, 0, "mit_samba_reget_pac context");
535 if (tmp_ctx == NULL) {
539 if (client != NULL) {
541 talloc_get_type_abort(client->e_data,
542 struct samba_kdc_entry);
545 * Check the objectSID of the client and pac data are the same.
546 * Does a parse and SID check, but no crypto.
548 code = samba_kdc_validate_pac_blob(context, client_skdc_entry, *pac);
554 if (server == NULL) {
560 talloc_get_type_abort(server->e_data,
561 struct samba_kdc_entry);
563 /* The account may be set not to want the PAC */
564 ok = samba_princ_needs_pac(server_skdc_entry);
570 if (krbtgt == NULL) {
575 talloc_get_type_abort(krbtgt->e_data,
576 struct samba_kdc_entry);
578 code = samba_krbtgt_is_in_db(krbtgt_skdc_entry,
586 if (client == NULL) {
587 code = KRB5KDC_ERR_C_PRINCIPAL_UNKNOWN;
591 nt_status = samba_kdc_get_pac_blobs(tmp_ctx,
597 if (!NT_STATUS_IS_OK(nt_status)) {
602 struct PAC_SIGNATURE_DATA *pac_srv_sig;
603 struct PAC_SIGNATURE_DATA *pac_kdc_sig;
605 pac_blob = talloc_zero(tmp_ctx, DATA_BLOB);
606 if (pac_blob == NULL) {
611 pac_srv_sig = talloc_zero(tmp_ctx, struct PAC_SIGNATURE_DATA);
612 if (pac_srv_sig == NULL) {
617 pac_kdc_sig = talloc_zero(tmp_ctx, struct PAC_SIGNATURE_DATA);
618 if (pac_kdc_sig == NULL) {
623 nt_status = samba_kdc_update_pac_blob(tmp_ctx,
625 krbtgt_skdc_entry->kdc_db_ctx->samdb,
630 if (!NT_STATUS_IS_OK(nt_status)) {
631 DEBUG(0, ("Update PAC blob failed: %s\n",
632 nt_errstr(nt_status)));
639 * Now check the KDC signature, fetching the correct
640 * key based on the enc type.
642 code = check_pac_checksum(pac_srv_sig->signature,
647 DBG_INFO("PAC KDC signature failed to verify\n");
653 if (flags & KRB5_KDB_FLAG_CONSTRAINED_DELEGATION) {
654 deleg_blob = talloc_zero(tmp_ctx, DATA_BLOB);
655 if (deleg_blob == NULL) {
660 nt_status = samba_kdc_update_delegation_info_blob(tmp_ctx,
664 discard_const(client_principal),
666 if (!NT_STATUS_IS_OK(nt_status)) {
667 DEBUG(0, ("Update delegation info failed: %s\n",
668 nt_errstr(nt_status)));
674 /* Check the types of the given PAC */
675 code = krb5_pac_get_types(context, *pac, &num_types, &types);
680 for (i = 0; i < num_types; i++) {
682 case PAC_TYPE_LOGON_INFO:
683 if (logon_info_idx != -1) {
684 DBG_WARNING("logon type[%u] twice [%zd] and [%zu]: \n",
694 case PAC_TYPE_CONSTRAINED_DELEGATION:
695 if (delegation_idx != -1) {
696 DBG_WARNING("logon type[%u] twice [%zd] and [%zu]: \n",
706 case PAC_TYPE_LOGON_NAME:
707 if (logon_name_idx != -1) {
708 DBG_WARNING("logon type[%u] twice [%zd] and [%zu]: \n",
718 case PAC_TYPE_UPN_DNS_INFO:
719 if (upn_dns_info_idx != -1) {
720 DBG_WARNING("logon type[%u] twice [%zd] and [%zu]: \n",
728 upn_dns_info_idx = i;
730 case PAC_TYPE_SRV_CHECKSUM:
731 if (srv_checksum_idx != -1) {
732 DBG_WARNING("logon type[%u] twice [%zd] and [%zu]: \n",
740 srv_checksum_idx = i;
742 case PAC_TYPE_KDC_CHECKSUM:
743 if (kdc_checksum_idx != -1) {
744 DBG_WARNING("logon type[%u] twice [%zd] and [%zu]: \n",
752 kdc_checksum_idx = i;
759 if (logon_info_idx == -1) {
760 DEBUG(1, ("PAC_TYPE_LOGON_INFO missing\n"));
765 if (logon_name_idx == -1) {
766 DEBUG(1, ("PAC_TYPE_LOGON_NAME missing\n"));
771 if (srv_checksum_idx == -1) {
772 DEBUG(1, ("PAC_TYPE_SRV_CHECKSUM missing\n"));
777 if (kdc_checksum_idx == -1) {
778 DEBUG(1, ("PAC_TYPE_KDC_CHECKSUM missing\n"));
784 /* Build an updated PAC */
785 code = krb5_pac_init(context, &new_pac);
793 DATA_BLOB type_blob = data_blob_null;
796 if (forced_next_type != 0) {
798 * We need to inject possible missing types
800 type = forced_next_type;
801 forced_next_type = 0;
802 } else if (i < num_types) {
810 case PAC_TYPE_LOGON_INFO:
811 type_blob = *pac_blob;
813 if (delegation_idx == -1 && deleg_blob != NULL) {
814 /* inject CONSTRAINED_DELEGATION behind */
815 forced_next_type = PAC_TYPE_CONSTRAINED_DELEGATION;
818 case PAC_TYPE_CONSTRAINED_DELEGATION:
819 if (deleg_blob != NULL) {
820 type_blob = *deleg_blob;
823 case PAC_TYPE_CREDENTIAL_INFO:
825 * Note that we copy the credential blob,
826 * as it's only usable with the PKINIT based
827 * AS-REP reply key, it's only available on the
828 * host which did the AS-REQ/AS-REP exchange.
830 * This matches Windows 2008R2...
833 case PAC_TYPE_LOGON_NAME:
835 * This is generated in the main KDC code
838 case PAC_TYPE_UPN_DNS_INFO:
840 * Replace in the RODC case, otherwise
841 * upn_blob is NULL and we just copy.
843 if (upn_blob != NULL) {
844 type_blob = *upn_blob;
847 case PAC_TYPE_SRV_CHECKSUM:
849 * This is generated in the main KDC code
852 case PAC_TYPE_KDC_CHECKSUM:
854 * This is generated in the main KDC code
862 if (type_blob.length != 0) {
863 code = smb_krb5_copy_data_contents(&type_data,
868 krb5_pac_free(context, new_pac);
872 code = krb5_pac_get_buffer(context,
878 krb5_pac_free(context, new_pac);
883 code = krb5_pac_add_buffer(context,
887 smb_krb5_free_data_contents(context, &type_data);
890 krb5_pac_free(context, new_pac);
897 /* We now replace the pac */
898 krb5_pac_free(context, *pac);
901 talloc_free(tmp_ctx);
905 /* provide header, function is exported but there are no public headers */
907 krb5_error_code encode_krb5_padata_sequence(krb5_pa_data *const *rep, krb5_data **code);
909 /* this function allocates 'data' using malloc.
910 * The caller is responsible for freeing it */
911 static void samba_kdc_build_edata_reply(NTSTATUS nt_status, DATA_BLOB *e_data)
913 krb5_error_code ret = 0;
914 krb5_pa_data pa, *ppa[2];
923 pa.magic = KV5M_PA_DATA;
924 pa.pa_type = KRB5_PADATA_PW_SALT;
926 pa.contents = malloc(pa.length);
931 SIVAL(pa.contents, 0, NT_STATUS_V(nt_status));
932 SIVAL(pa.contents, 4, 0);
933 SIVAL(pa.contents, 8, 1);
938 ret = encode_krb5_padata_sequence(ppa, &d);
944 e_data->data = (uint8_t *)d->data;
945 e_data->length = d->length;
947 /* free d, not d->data - gd */
953 int mit_samba_check_client_access(struct mit_samba_context *ctx,
954 krb5_db_entry *client,
955 const char *client_name,
956 krb5_db_entry *server,
957 const char *server_name,
958 const char *netbios_name,
959 bool password_change,
962 struct samba_kdc_entry *skdc_entry;
965 skdc_entry = talloc_get_type(client->e_data, struct samba_kdc_entry);
967 nt_status = samba_kdc_check_client_access(skdc_entry,
972 if (!NT_STATUS_IS_OK(nt_status)) {
973 if (NT_STATUS_EQUAL(nt_status, NT_STATUS_NO_MEMORY)) {
977 samba_kdc_build_edata_reply(nt_status, e_data);
979 return samba_kdc_map_policy_err(nt_status);
985 int mit_samba_check_s4u2proxy(struct mit_samba_context *ctx,
986 krb5_db_entry *kentry,
987 const char *target_name,
988 bool is_nt_enterprise_name)
992 * This is disabled because mit_samba_update_pac_data() does not handle
993 * S4U_DELEGATION_INFO
996 return KRB5KDC_ERR_BADOPTION;
998 krb5_principal target_principal;
1002 if (is_nt_enterprise_name) {
1003 flags = KRB5_PRINCIPAL_PARSE_ENTERPRISE;
1006 ret = krb5_parse_name_flags(ctx->context, target_name,
1007 flags, &target_principal);
1012 ret = samba_kdc_check_s4u2proxy(ctx->context,
1017 krb5_free_principal(ctx->context, target_principal);
1023 static krb5_error_code mit_samba_change_pwd_error(krb5_context context,
1025 enum samPwdChangeReason reject_reason,
1026 struct samr_DomInfo1 *dominfo)
1028 krb5_error_code code = KADM5_PASS_Q_GENERIC;
1030 if (NT_STATUS_EQUAL(result, NT_STATUS_NO_SUCH_USER)) {
1031 code = KADM5_BAD_PRINCIPAL;
1032 krb5_set_error_message(context,
1034 "No such user when changing password");
1036 if (NT_STATUS_EQUAL(result, NT_STATUS_ACCESS_DENIED)) {
1037 code = KADM5_PASS_Q_GENERIC;
1038 krb5_set_error_message(context,
1040 "Not permitted to change password");
1042 if (NT_STATUS_EQUAL(result, NT_STATUS_PASSWORD_RESTRICTION) &&
1044 switch (reject_reason) {
1045 case SAM_PWD_CHANGE_PASSWORD_TOO_SHORT:
1046 code = KADM5_PASS_Q_TOOSHORT;
1047 krb5_set_error_message(context,
1049 "Password too short, password "
1050 "must be at least %d characters "
1052 dominfo->min_password_length);
1054 case SAM_PWD_CHANGE_NOT_COMPLEX:
1055 code = KADM5_PASS_Q_DICT;
1056 krb5_set_error_message(context,
1058 "Password does not meet "
1059 "complexity requirements");
1061 case SAM_PWD_CHANGE_PWD_IN_HISTORY:
1062 code = KADM5_PASS_TOOSOON;
1063 krb5_set_error_message(context,
1065 "Password is already in password "
1066 "history. New password must not "
1067 "match any of your %d previous "
1069 dominfo->password_history_length);
1072 code = KADM5_PASS_Q_GENERIC;
1073 krb5_set_error_message(context,
1075 "Password change rejected, "
1076 "password changes may not be "
1077 "permitted on this account, or "
1078 "the minimum password age may "
1079 "not have elapsed.");
1087 int mit_samba_kpasswd_change_password(struct mit_samba_context *ctx,
1089 krb5_db_entry *db_entry)
1092 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1093 TALLOC_CTX *tmp_ctx;
1095 enum samPwdChangeReason reject_reason;
1096 struct samr_DomInfo1 *dominfo;
1097 const char *error_string = NULL;
1098 struct auth_user_info_dc *user_info_dc;
1099 struct samba_kdc_entry *p =
1100 talloc_get_type_abort(db_entry->e_data, struct samba_kdc_entry);
1101 krb5_error_code code = 0;
1103 #ifdef DEBUG_PASSWORD
1104 DEBUG(1,("mit_samba_kpasswd_change_password called with: %s\n", pwd));
1107 tmp_ctx = talloc_named(ctx, 0, "mit_samba_kpasswd_change_password");
1108 if (tmp_ctx == NULL) {
1112 status = authsam_make_user_info_dc(tmp_ctx,
1114 lpcfg_netbios_name(ctx->db_ctx->lp_ctx),
1115 lpcfg_sam_name(ctx->db_ctx->lp_ctx),
1116 lpcfg_sam_dnsname(ctx->db_ctx->lp_ctx),
1122 if (!NT_STATUS_IS_OK(status)) {
1123 DEBUG(1,("authsam_make_user_info_dc failed: %s\n",
1124 nt_errstr(status)));
1125 talloc_free(tmp_ctx);
1129 status = auth_generate_session_info(tmp_ctx,
1130 ctx->db_ctx->lp_ctx,
1133 0, /* session_info_flags */
1134 &ctx->session_info);
1136 if (!NT_STATUS_IS_OK(status)) {
1137 DEBUG(1,("auth_generate_session_info failed: %s\n",
1138 nt_errstr(status)));
1139 talloc_free(tmp_ctx);
1143 /* password is expected as UTF16 */
1145 if (!convert_string_talloc(tmp_ctx, CH_UTF8, CH_UTF16,
1147 &password.data, &password.length)) {
1148 DEBUG(1,("convert_string_talloc failed\n"));
1149 talloc_free(tmp_ctx);
1153 status = samdb_kpasswd_change_password(tmp_ctx,
1154 ctx->db_ctx->lp_ctx,
1155 ctx->db_ctx->ev_ctx,
1163 if (!NT_STATUS_IS_OK(status)) {
1164 DEBUG(1,("samdb_kpasswd_change_password failed: %s\n",
1165 nt_errstr(status)));
1166 code = KADM5_PASS_Q_GENERIC;
1167 krb5_set_error_message(ctx->context, code, "%s", error_string);
1171 if (!NT_STATUS_IS_OK(result)) {
1172 code = mit_samba_change_pwd_error(ctx->context,
1179 talloc_free(tmp_ctx);
1184 void mit_samba_zero_bad_password_count(krb5_db_entry *db_entry)
1186 struct netr_SendToSamBase *send_to_sam = NULL;
1187 struct samba_kdc_entry *p =
1188 talloc_get_type_abort(db_entry->e_data, struct samba_kdc_entry);
1189 struct ldb_dn *domain_dn;
1191 domain_dn = ldb_get_default_basedn(p->kdc_db_ctx->samdb);
1193 authsam_logon_success_accounting(p->kdc_db_ctx->samdb,
1198 /* TODO: RODC support */
1202 void mit_samba_update_bad_password_count(krb5_db_entry *db_entry)
1204 struct samba_kdc_entry *p =
1205 talloc_get_type_abort(db_entry->e_data, struct samba_kdc_entry);
1207 authsam_update_bad_pwd_count(p->kdc_db_ctx->samdb,
1209 ldb_get_default_basedn(p->kdc_db_ctx->samdb));
1212 bool mit_samba_princ_needs_pac(krb5_db_entry *db_entry)
1214 struct samba_kdc_entry *skdc_entry =
1215 talloc_get_type_abort(db_entry->e_data, struct samba_kdc_entry);
1217 return samba_princ_needs_pac(skdc_entry);