From 3042a1d544b479ee0372f8d8ebcccce0b4a1ba3e Mon Sep 17 00:00:00 2001 From: Alexander Bokovoy Date: Fri, 29 Oct 2021 22:30:53 +0300 Subject: [PATCH] ipa-kdb: Use proper account flags for Kerberos principal in PAC As part of CVE-2020-25717 mitigations, Samba expects correct user account flags in the PAC. This means for services and host principals we should be using ACB_WSTRUST or ACB_SVRTRUST depending on whether they run on IPA clients ("workstation" or "domain member") or IPA servers ("domain controller"). Fixes: https://pagure.io/freeipa/issue/9031 Signed-off-by: Alexander Bokovoy Reviewed-By: Rob Crittenden --- daemons/ipa-kdb/ipa_kdb_mspac.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/daemons/ipa-kdb/ipa_kdb_mspac.c b/daemons/ipa-kdb/ipa_kdb_mspac.c index 8a77a3538..0e0ee3616 100644 --- a/daemons/ipa-kdb/ipa_kdb_mspac.c +++ b/daemons/ipa-kdb/ipa_kdb_mspac.c @@ -648,6 +648,11 @@ static krb5_error_code ipadb_fill_info3(struct ipadb_context *ipactx, info3->base.logon_count = 0; /* we do not have this info yet */ info3->base.bad_password_count = 0; /* we do not have this info yet */ + /* Use AES keys by default to detect changes. + * This bit is not used by Windows clients and servers so we can + * clear it after detecting the changes */ + info3->base.acct_flags = ACB_USE_AES_KEYS; + if ((is_host || is_service)) { /* it is either host or service, so get the hostname first */ char *sep = strchr(info3->base.account_name.string, '/'); @@ -655,11 +660,13 @@ static krb5_error_code ipadb_fill_info3(struct ipadb_context *ipactx, ipactx, sep ? sep + 1 : info3->base.account_name.string); if (is_master) { - /* Well know RID of domain controllers group */ + /* Well known RID of domain controllers group */ info3->base.rid = 516; + info3->base.acct_flags |= ACB_SVRTRUST; } else { - /* Well know RID of domain computers group */ + /* Well known RID of domain computers group */ info3->base.rid = 515; + info3->base.acct_flags |= ACB_WSTRUST; } } else { ret = ipadb_ldap_attr_to_str(ipactx->lcontext, lentry, @@ -799,9 +806,13 @@ static krb5_error_code ipadb_fill_info3(struct ipadb_context *ipactx, /* always zero out, not used for Krb, only NTLM */ memset(&info3->base.LMSessKey, '\0', sizeof(info3->base.LMSessKey)); - /* TODO: fill based on objectclass, user vs computer, etc... */ - info3->base.acct_flags = ACB_NORMAL; /* samr_AcctFlags */ + /* If account type was not set before, default to ACB_NORMAL */ + if (!(info3->base.acct_flags & ~ACB_USE_AES_KEYS)) { + info3->base.acct_flags |= ACB_NORMAL; /* samr_AcctFlags */ + } + /* Clear ACB_USE_AES_KEYS as it is not used by Windows */ + info3->base.acct_flags &= ~ACB_USE_AES_KEYS; info3->base.sub_auth_status = 0; info3->base.last_successful_logon = 0; info3->base.last_failed_logon = 0;