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"
28 #include "lib/replace/system/filesys.h"
31 #include <kadm5/kadm_err.h>
33 #include "kdc/sdb_kdb.h"
34 #include "auth/kerberos/kerberos.h"
35 #include "auth/kerberos/pac_utils.h"
36 #include "kdc/samba_kdc.h"
37 #include "kdc/pac-glue.h"
38 #include "kdc/db-glue.h"
39 #include "auth/auth.h"
40 #include "kdc/kpasswd_glue.h"
41 #include "auth/auth_sam.h"
43 #include "mit_samba.h"
46 #define DBGC_CLASS DBGC_KERBEROS
48 void mit_samba_context_free(struct mit_samba_context *ctx)
50 /* free heimdal's krb5_context */
52 krb5_free_context(ctx->context);
55 /* then free everything else */
60 * Implement a callback to log to the MIT KDC log facility
62 * http://web.mit.edu/kerberos/krb5-devel/doc/plugindev/general.html#logging-from-kdc-and-kadmind-plugin-modules
64 static void mit_samba_debug(void *private_ptr, int msg_level, const char *msg)
72 com_err("", is_error, "%s", msg);
75 int mit_samba_context_init(struct mit_samba_context **_ctx)
78 struct mit_samba_context *ctx;
79 const char *s4_conf_file;
81 struct samba_kdc_base_context base_ctx;
83 ctx = talloc_zero(NULL, struct mit_samba_context);
89 base_ctx.ev_ctx = tevent_context_init(ctx);
90 if (!base_ctx.ev_ctx) {
94 tevent_loop_allow_nesting(base_ctx.ev_ctx);
95 base_ctx.lp_ctx = loadparm_init_global(false);
96 if (!base_ctx.lp_ctx) {
101 debug_set_callback(NULL, mit_samba_debug);
103 /* init s4 configuration */
104 s4_conf_file = lpcfg_configfile(base_ctx.lp_ctx);
105 if (s4_conf_file != NULL) {
106 char *p = talloc_strdup(ctx, s4_conf_file);
111 lpcfg_load(base_ctx.lp_ctx, p);
114 lpcfg_load_default(base_ctx.lp_ctx);
117 status = samba_kdc_setup_db_ctx(ctx, &base_ctx, &ctx->db_ctx);
118 if (!NT_STATUS_IS_OK(status)) {
123 /* init heimdal's krb_context and log facilities */
124 ret = smb_krb5_init_context_basic(ctx,
135 mit_samba_context_free(ctx);
142 static krb5_error_code ks_is_tgs_principal(struct mit_samba_context *ctx,
143 krb5_const_principal principal)
148 p = smb_krb5_principal_get_comp_string(ctx, ctx->context, principal, 0);
150 eq = krb5_princ_size(ctx->context, principal) == 2 &&
151 (strcmp(p, KRB5_TGS_NAME) == 0);
158 int mit_samba_generate_salt(krb5_data *salt)
165 salt->data = malloc(salt->length);
166 if (salt->data == NULL) {
170 generate_random_buffer((uint8_t *)salt->data, salt->length);
175 int mit_samba_generate_random_password(krb5_data *pwd)
185 tmp_ctx = talloc_named(NULL,
187 "mit_samba_generate_random_password context");
188 if (tmp_ctx == NULL) {
192 password = generate_random_password(tmp_ctx, pwd->length, pwd->length);
193 if (password == NULL) {
194 talloc_free(tmp_ctx);
198 pwd->data = strdup(password);
199 talloc_free(tmp_ctx);
200 if (pwd->data == NULL) {
207 int mit_samba_get_principal(struct mit_samba_context *ctx,
208 krb5_const_principal principal,
210 krb5_db_entry **_kentry)
212 struct sdb_entry sentry = {};
213 krb5_db_entry *kentry;
216 krb5_principal referral_principal = NULL;
218 kentry = calloc(1, sizeof(krb5_db_entry));
219 if (kentry == NULL) {
223 #if KRB5_KDB_API_VERSION >= 10
225 * The MIT KDC code that wants the canonical name in all lookups, and
226 * takes care to canonicalize only when appropriate.
228 sflags |= SDB_F_FORCE_CANON;
231 #if KRB5_KDB_DAL_MAJOR_VERSION >= 9
232 if (kflags & KRB5_KDB_FLAG_REFERRAL_OK) {
233 sflags |= SDB_F_CANON;
236 if (kflags & KRB5_KDB_FLAG_CLIENT) {
237 sflags |= SDB_F_GET_CLIENT;
238 sflags |= SDB_F_FOR_AS_REQ;
240 int equal = smb_krb5_principal_is_tgs(ctx->context, principal);
246 sflags |= SDB_F_GET_KRBTGT;
248 sflags |= SDB_F_GET_SERVER;
249 sflags |= SDB_F_FOR_TGS_REQ;
252 #else /* KRB5_KDB_DAL_MAJOR_VERSION < 9 */
253 if (kflags & KRB5_KDB_FLAG_CANONICALIZE) {
254 sflags |= SDB_F_CANON;
256 if (kflags & (KRB5_KDB_FLAG_CLIENT_REFERRALS_ONLY |
257 KRB5_KDB_FLAG_INCLUDE_PAC)) {
259 * KRB5_KDB_FLAG_CLIENT_REFERRALS_ONLY is equal to
262 * We use ANY to also allow AS_REQ for service principal names
263 * This is supported by Windows.
265 sflags |= SDB_F_GET_ANY|SDB_F_FOR_AS_REQ;
267 int equal = smb_krb5_principal_is_tgs(ctx->context, principal);
273 sflags |= SDB_F_GET_KRBTGT;
275 sflags |= SDB_F_GET_SERVER|SDB_F_FOR_TGS_REQ;
278 #endif /* KRB5_KDB_DAL_MAJOR_VERSION */
280 /* always set this or the created_by data will not be populated by samba's
281 * backend and we will fail to parse the entry later */
282 sflags |= SDB_F_ADMIN_DATA;
285 fetch_referral_principal:
286 ret = samba_kdc_fetch(ctx->context, ctx->db_ctx,
287 principal, sflags, 0, &sentry);
291 case SDB_ERR_NOENTRY:
292 ret = KRB5_KDB_NOENTRY;
294 case SDB_ERR_WRONG_REALM: {
295 char *dest_realm = NULL;
296 const char *our_realm = lpcfg_realm(ctx->db_ctx->lp_ctx);
298 if (sflags & SDB_F_FOR_AS_REQ) {
300 * If this is a request for a TGT, we are done. The KDC
301 * will return the correct error to the client.
307 if (referral_principal != NULL) {
308 sdb_entry_free(&sentry);
309 ret = KRB5_KDB_NOENTRY;
314 * We get a TGS request
316 * cifs/dc7.SAMBA2008R2.EXAMPLE.COM@ADDOM.SAMBA.EXAMPLE.COM
318 * to our DC for the realm
320 * ADDOM.SAMBA.EXAMPLE.COM
322 * We look up if we have and entry in the database and get an
323 * entry with the pricipal:
325 * cifs/dc7.SAMBA2008R2.EXAMPLE.COM@SAMBA2008R2.EXAMPLE.COM
327 * and the error: SDB_ERR_WRONG_REALM.
329 * In the case of a TGS-REQ we need to return a referral ticket
330 * fo the next trust hop to the client. This ticket will have
331 * the following principal:
333 * krbtgt/SAMBA2008R2.EXAMPLE.COM@ADDOM.SAMBA.EXAMPLE.COM
335 * We just redo the lookup in the database with the referral
336 * principal and return success.
338 dest_realm = smb_krb5_principal_get_realm(
339 ctx, ctx->context, sentry.principal);
340 sdb_entry_free(&sentry);
341 if (dest_realm == NULL) {
342 ret = KRB5_KDB_NOENTRY;
346 ret = smb_krb5_make_principal(ctx->context,
352 TALLOC_FREE(dest_realm);
357 principal = referral_principal;
358 goto fetch_referral_principal;
360 case SDB_ERR_NOT_FOUND_HERE:
361 /* FIXME: RODC support */
366 ret = sdb_entry_to_krb5_db_entry(ctx->context, &sentry, kentry);
368 sdb_entry_free(&sentry);
371 krb5_free_principal(ctx->context, referral_principal);
372 referral_principal = NULL;
382 int mit_samba_get_firstkey(struct mit_samba_context *ctx,
383 krb5_db_entry **_kentry)
385 struct sdb_entry sentry = {};
386 krb5_db_entry *kentry;
389 kentry = malloc(sizeof(krb5_db_entry));
390 if (kentry == NULL) {
394 ret = samba_kdc_firstkey(ctx->context, ctx->db_ctx, &sentry);
398 case SDB_ERR_NOENTRY:
400 return KRB5_KDB_NOENTRY;
401 case SDB_ERR_NOT_FOUND_HERE:
402 /* FIXME: RODC support */
408 ret = sdb_entry_to_krb5_db_entry(ctx->context, &sentry, kentry);
410 sdb_entry_free(&sentry);
420 int mit_samba_get_nextkey(struct mit_samba_context *ctx,
421 krb5_db_entry **_kentry)
423 struct sdb_entry sentry = {};
424 krb5_db_entry *kentry;
427 kentry = malloc(sizeof(krb5_db_entry));
428 if (kentry == NULL) {
432 ret = samba_kdc_nextkey(ctx->context, ctx->db_ctx, &sentry);
436 case SDB_ERR_NOENTRY:
438 return KRB5_KDB_NOENTRY;
439 case SDB_ERR_NOT_FOUND_HERE:
440 /* FIXME: RODC support */
446 ret = sdb_entry_to_krb5_db_entry(ctx->context, &sentry, kentry);
448 sdb_entry_free(&sentry);
458 int mit_samba_get_pac(struct mit_samba_context *smb_ctx,
459 krb5_context context,
461 krb5_db_entry *client,
462 krb5_db_entry *server,
463 krb5_keyblock *replaced_reply_key,
467 DATA_BLOB *logon_info_blob = NULL;
468 DATA_BLOB *upn_dns_info_blob = NULL;
469 DATA_BLOB *cred_ndr = NULL;
470 DATA_BLOB **cred_ndr_ptr = NULL;
471 DATA_BLOB cred_blob = data_blob_null;
472 DATA_BLOB *pcred_blob = NULL;
473 DATA_BLOB *pac_attrs_blob = NULL;
474 DATA_BLOB *requester_sid_blob = NULL;
476 krb5_error_code code;
477 struct samba_kdc_entry *skdc_entry;
478 struct samba_kdc_entry *server_entry = NULL;
479 bool is_krbtgt = ks_is_tgs_principal(smb_ctx, server->princ);
480 /* Only include resource groups in a service ticket. */
481 enum auth_group_inclusion group_inclusion;
482 enum samba_asserted_identity asserted_identity =
483 (flags & KRB5_KDB_FLAG_PROTOCOL_TRANSITION) ?
484 SAMBA_ASSERTED_IDENTITY_SERVICE :
485 SAMBA_ASSERTED_IDENTITY_AUTHENTICATION_AUTHORITY;
487 skdc_entry = talloc_get_type_abort(client->e_data,
488 struct samba_kdc_entry);
490 server_entry = talloc_get_type_abort(server->e_data,
491 struct samba_kdc_entry);
493 /* Only include resource groups in a service ticket. */
495 group_inclusion = AUTH_EXCLUDE_RESOURCE_GROUPS;
496 } else if (server_entry->supported_enctypes & KERB_ENCTYPE_RESOURCE_SID_COMPRESSION_DISABLED) {
497 group_inclusion = AUTH_INCLUDE_RESOURCE_GROUPS;
499 group_inclusion = AUTH_INCLUDE_RESOURCE_GROUPS_COMPRESSED;
502 tmp_ctx = talloc_named(smb_ctx,
504 "mit_samba_get_pac context");
505 if (tmp_ctx == NULL) {
509 /* Check if we have a PREAUTH key */
510 if (replaced_reply_key != NULL) {
511 cred_ndr_ptr = &cred_ndr;
514 nt_status = samba_kdc_get_pac_blobs(tmp_ctx,
521 is_krbtgt ? &pac_attrs_blob : NULL,
522 PAC_ATTRIBUTE_FLAG_PAC_WAS_GIVEN_IMPLICITLY,
523 is_krbtgt ? &requester_sid_blob : NULL,
525 if (!NT_STATUS_IS_OK(nt_status)) {
526 talloc_free(tmp_ctx);
527 if (NT_STATUS_EQUAL(nt_status,
528 NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
534 if (replaced_reply_key != NULL && cred_ndr != NULL) {
535 code = samba_kdc_encrypt_pac_credentials(context,
541 talloc_free(tmp_ctx);
544 pcred_blob = &cred_blob;
547 code = samba_make_krb5_pac(context,
553 NULL, /* deleg_blob */
554 NULL, /* client_claims_blob */
555 NULL, /* device_info_blob */
556 NULL, /* device_claims_blob */
559 talloc_free(tmp_ctx);
563 #if KRB5_KDB_DAL_MAJOR_VERSION < 9
564 krb5_error_code mit_samba_reget_pac(struct mit_samba_context *ctx,
565 krb5_context context,
567 krb5_const_principal client_principal,
568 krb5_db_entry *client,
569 krb5_db_entry *server,
570 krb5_db_entry *krbtgt,
571 krb5_keyblock *krbtgt_keyblock,
575 krb5_error_code code;
576 struct samba_kdc_entry *client_skdc_entry = NULL;
577 struct samba_kdc_entry *krbtgt_skdc_entry = NULL;
578 struct samba_kdc_entry *server_skdc_entry = NULL;
579 krb5_principal delegated_proxy_principal = NULL;
580 krb5_pac new_pac = NULL;
581 bool is_in_db = false;
582 bool is_trusted = false;
583 uint32_t flags = SAMBA_KDC_FLAG_SKIP_PAC_BUFFER;
585 /* Create a memory context early so code can use talloc_stackframe() */
586 tmp_ctx = talloc_named(ctx, 0, "mit_samba_reget_pac context");
587 if (tmp_ctx == NULL) {
591 if (client != NULL) {
593 talloc_get_type_abort(client->e_data,
594 struct samba_kdc_entry);
597 if (server == NULL) {
603 talloc_get_type_abort(server->e_data,
604 struct samba_kdc_entry);
606 if (krbtgt == NULL) {
611 talloc_get_type_abort(krbtgt->e_data,
612 struct samba_kdc_entry);
614 code = samba_krbtgt_is_in_db(krbtgt_skdc_entry,
622 flags |= SAMBA_KDC_FLAG_KRBTGT_IS_TRUSTED;
626 flags |= SAMBA_KDC_FLAG_KRBTGT_IN_DB;
630 if (kdc_flags & KRB5_KDB_FLAG_PROTOCOL_TRANSITION) {
631 flags |= SAMBA_KDC_FLAG_PROTOCOL_TRANSITION;
634 if (kdc_flags & KRB5_KDB_FLAG_CONSTRAINED_DELEGATION) {
635 flags |= SAMBA_KDC_FLAG_CONSTRAINED_DELEGATION;
636 delegated_proxy_principal = discard_const(client_principal);
639 /* Build an updated PAC */
640 code = krb5_pac_init(context, &new_pac);
645 code = samba_kdc_update_pac(tmp_ctx,
647 krbtgt_skdc_entry->kdc_db_ctx->samdb,
653 delegated_proxy_principal,
657 krb5_pac_free(context, new_pac);
658 if (code == ENOATTR) {
659 krb5_pac_free(context, *pac);
666 /* We now replace the pac */
667 krb5_pac_free(context, *pac);
671 talloc_free(tmp_ctx);
675 krb5_error_code mit_samba_update_pac(struct mit_samba_context *ctx,
676 krb5_context context,
678 krb5_db_entry *client,
679 krb5_db_entry *server,
680 krb5_db_entry *krbtgt,
684 TALLOC_CTX *tmp_ctx = NULL;
685 krb5_error_code code;
686 struct samba_kdc_entry *client_skdc_entry = NULL;
687 struct samba_kdc_entry *server_skdc_entry = NULL;
688 struct samba_kdc_entry *krbtgt_skdc_entry = NULL;
689 bool is_in_db = false;
690 bool is_trusted = false;
691 uint32_t flags = SAMBA_KDC_FLAG_SKIP_PAC_BUFFER;
693 /* Create a memory context early so code can use talloc_stackframe() */
694 tmp_ctx = talloc_named(ctx, 0, "mit_samba_update_pac context");
695 if (tmp_ctx == NULL) {
699 if (client != NULL) {
701 talloc_get_type_abort(client->e_data,
702 struct samba_kdc_entry);
705 if (krbtgt == NULL) {
710 talloc_get_type_abort(krbtgt->e_data,
711 struct samba_kdc_entry);
714 talloc_get_type_abort(server->e_data,
715 struct samba_kdc_entry);
718 * If the krbtgt was generated by an RODC, and we are not that
719 * RODC, then we need to regenerate the PAC - we can't trust
720 * it, and confirm that the RODC was permitted to print this ticket
722 * Because of the samba_kdc_validate_pac_blob() step we can be
723 * sure that the record in 'client' or 'server' matches the SID in the
726 code = samba_krbtgt_is_in_db(krbtgt_skdc_entry,
734 flags |= SAMBA_KDC_FLAG_KRBTGT_IS_TRUSTED;
738 flags |= SAMBA_KDC_FLAG_KRBTGT_IN_DB;
742 if (kdc_flags & KRB5_KDB_FLAG_CONSTRAINED_DELEGATION) {
743 flags |= SAMBA_KDC_FLAG_CONSTRAINED_DELEGATION;
746 code = samba_kdc_update_pac(tmp_ctx,
748 krbtgt_skdc_entry->kdc_db_ctx->samdb,
754 NULL, /* delegated_proxy_principal */
758 if (code == ENOATTR) {
760 * We can't tell the KDC to not issue a PAC. It will
761 * just return the newly allocated empty PAC.
768 talloc_free(tmp_ctx);
773 /* provide header, function is exported but there are no public headers */
775 krb5_error_code encode_krb5_padata_sequence(krb5_pa_data *const *rep, krb5_data **code);
777 /* this function allocates 'data' using malloc.
778 * The caller is responsible for freeing it */
779 static void samba_kdc_build_edata_reply(NTSTATUS nt_status, DATA_BLOB *e_data)
781 krb5_error_code ret = 0;
782 krb5_pa_data pa, *ppa[2];
791 pa.magic = KV5M_PA_DATA;
792 pa.pa_type = KRB5_PADATA_PW_SALT;
794 pa.contents = malloc(pa.length);
799 SIVAL(pa.contents, 0, NT_STATUS_V(nt_status));
800 SIVAL(pa.contents, 4, 0);
801 SIVAL(pa.contents, 8, 1);
806 ret = encode_krb5_padata_sequence(ppa, &d);
812 e_data->data = (uint8_t *)d->data;
813 e_data->length = d->length;
815 /* free d, not d->data - gd */
821 int mit_samba_check_client_access(struct mit_samba_context *ctx,
822 krb5_db_entry *client,
823 const char *client_name,
824 krb5_db_entry *server,
825 const char *server_name,
826 const char *netbios_name,
827 bool password_change,
830 struct samba_kdc_entry *skdc_entry;
833 skdc_entry = talloc_get_type(client->e_data, struct samba_kdc_entry);
835 nt_status = samba_kdc_check_client_access(skdc_entry,
840 if (!NT_STATUS_IS_OK(nt_status)) {
841 if (NT_STATUS_EQUAL(nt_status, NT_STATUS_NO_MEMORY)) {
845 samba_kdc_build_edata_reply(nt_status, e_data);
847 return samba_kdc_map_policy_err(nt_status);
853 int mit_samba_check_s4u2proxy(struct mit_samba_context *ctx,
854 const krb5_db_entry *server,
855 krb5_const_principal target_principal)
857 #if KRB5_KDB_DAL_MAJOR_VERSION < 9
858 return KRB5KDC_ERR_BADOPTION;
860 struct samba_kdc_entry *server_skdc_entry =
861 talloc_get_type_abort(server->e_data, struct samba_kdc_entry);
862 krb5_error_code code;
864 code = samba_kdc_check_s4u2proxy(ctx->context,
873 krb5_error_code mit_samba_check_allowed_to_delegate_from(
874 struct mit_samba_context *ctx,
875 krb5_const_principal client_principal,
876 krb5_const_principal server_principal,
878 const krb5_db_entry *proxy)
880 #if KRB5_KDB_DAL_MAJOR_VERSION < 8
881 return KRB5KDC_ERR_POLICY;
883 struct samba_kdc_entry *proxy_skdc_entry =
884 talloc_get_type_abort(proxy->e_data, struct samba_kdc_entry);
885 krb5_error_code code;
887 code = samba_kdc_check_s4u2proxy_rbcd(ctx->context,
898 static krb5_error_code mit_samba_change_pwd_error(krb5_context context,
900 enum samPwdChangeReason reject_reason,
901 struct samr_DomInfo1 *dominfo)
903 krb5_error_code code = KADM5_PASS_Q_GENERIC;
905 if (NT_STATUS_EQUAL(result, NT_STATUS_NO_SUCH_USER)) {
906 code = KADM5_BAD_PRINCIPAL;
907 krb5_set_error_message(context,
909 "No such user when changing password");
911 if (NT_STATUS_EQUAL(result, NT_STATUS_ACCESS_DENIED)) {
912 code = KADM5_PASS_Q_GENERIC;
913 krb5_set_error_message(context,
915 "Not permitted to change password");
917 if (NT_STATUS_EQUAL(result, NT_STATUS_PASSWORD_RESTRICTION) &&
919 switch (reject_reason) {
920 case SAM_PWD_CHANGE_PASSWORD_TOO_SHORT:
921 code = KADM5_PASS_Q_TOOSHORT;
922 krb5_set_error_message(context,
924 "Password too short, password "
925 "must be at least %d characters "
927 dominfo->min_password_length);
929 case SAM_PWD_CHANGE_NOT_COMPLEX:
930 code = KADM5_PASS_Q_DICT;
931 krb5_set_error_message(context,
933 "Password does not meet "
934 "complexity requirements");
936 case SAM_PWD_CHANGE_PWD_IN_HISTORY:
937 code = KADM5_PASS_TOOSOON;
938 krb5_set_error_message(context,
940 "Password is already in password "
941 "history. New password must not "
942 "match any of your %d previous "
944 dominfo->password_history_length);
947 code = KADM5_PASS_Q_GENERIC;
948 krb5_set_error_message(context,
950 "Password change rejected, "
951 "password changes may not be "
952 "permitted on this account, or "
953 "the minimum password age may "
954 "not have elapsed.");
962 int mit_samba_kpasswd_change_password(struct mit_samba_context *ctx,
964 krb5_db_entry *db_entry)
967 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
970 enum samPwdChangeReason reject_reason;
971 struct samr_DomInfo1 *dominfo;
972 const char *error_string = NULL;
973 struct auth_user_info_dc *user_info_dc;
974 struct samba_kdc_entry *p =
975 talloc_get_type_abort(db_entry->e_data, struct samba_kdc_entry);
976 krb5_error_code code = 0;
978 #ifdef DEBUG_PASSWORD
979 DEBUG(1,("mit_samba_kpasswd_change_password called with: %s\n", pwd));
982 tmp_ctx = talloc_named(ctx, 0, "mit_samba_kpasswd_change_password");
983 if (tmp_ctx == NULL) {
987 status = samba_kdc_get_user_info_from_db(p,
990 if (!NT_STATUS_IS_OK(status)) {
991 DEBUG(1,("samba_kdc_get_user_info_from_db failed: %s\n",
993 talloc_free(tmp_ctx);
997 status = auth_generate_session_info(tmp_ctx,
1001 0, /* session_info_flags */
1002 &ctx->session_info);
1004 if (!NT_STATUS_IS_OK(status)) {
1005 DEBUG(1,("auth_generate_session_info failed: %s\n",
1006 nt_errstr(status)));
1007 talloc_free(tmp_ctx);
1011 /* password is expected as UTF16 */
1013 if (!convert_string_talloc(tmp_ctx, CH_UTF8, CH_UTF16,
1015 &password.data, &password.length)) {
1016 DEBUG(1,("convert_string_talloc failed\n"));
1017 talloc_free(tmp_ctx);
1021 status = samdb_kpasswd_change_password(tmp_ctx,
1022 ctx->db_ctx->lp_ctx,
1023 ctx->db_ctx->ev_ctx,
1030 if (!NT_STATUS_IS_OK(status)) {
1031 DEBUG(1,("samdb_kpasswd_change_password failed: %s\n",
1032 nt_errstr(status)));
1033 code = KADM5_PASS_Q_GENERIC;
1034 krb5_set_error_message(ctx->context, code, "%s", error_string);
1038 if (!NT_STATUS_IS_OK(result)) {
1039 code = mit_samba_change_pwd_error(ctx->context,
1046 talloc_free(tmp_ctx);
1051 void mit_samba_zero_bad_password_count(krb5_db_entry *db_entry)
1053 /* struct netr_SendToSamBase *send_to_sam = NULL; */
1054 struct samba_kdc_entry *p =
1055 talloc_get_type_abort(db_entry->e_data, struct samba_kdc_entry);
1056 struct ldb_dn *domain_dn;
1058 domain_dn = ldb_get_default_basedn(p->kdc_db_ctx->samdb);
1060 authsam_logon_success_accounting(p->kdc_db_ctx->samdb,
1065 /* TODO: RODC support */
1069 void mit_samba_update_bad_password_count(krb5_db_entry *db_entry)
1071 struct samba_kdc_entry *p =
1072 talloc_get_type_abort(db_entry->e_data, struct samba_kdc_entry);
1074 authsam_update_bad_pwd_count(p->kdc_db_ctx->samdb,
1076 ldb_get_default_basedn(p->kdc_db_ctx->samdb));
1079 bool mit_samba_princ_needs_pac(krb5_db_entry *db_entry)
1081 struct samba_kdc_entry *skdc_entry =
1082 talloc_get_type_abort(db_entry->e_data, struct samba_kdc_entry);
1084 return samba_princ_needs_pac(skdc_entry);