From 55d821ca8b5baaa69f88127b228bd4906e2cee68 Mon Sep 17 00:00:00 2001
From: Andrew Bartlett <abartlet@samba.org>
Date: Thu, 21 Oct 2021 13:02:42 +1300
Subject: [PATCH 072/266] CVE-2020-25722 samdb: Fill in isCriticalSystemObject
 on any account type change

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14753

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>

Conflict:remove test
Reference:https://gitlab.com/samba-team/samba/-/commit/55d821ca8b5baaa69f88127b228bd4906e2cee68
---
 source4/dsdb/samdb/ldb_modules/samldb.c         | 10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)
 delete mode 100644 selftest/knownfail.d/sam-isCriticalSystemObject

diff --git a/source4/dsdb/samdb/ldb_modules/samldb.c b/source4/dsdb/samdb/ldb_modules/samldb.c
index aeef663d2f0..5352af1099f 100644
--- a/source4/dsdb/samdb/ldb_modules/samldb.c
+++ b/source4/dsdb/samdb/ldb_modules/samldb.c
@@ -2621,8 +2621,14 @@ static int samldb_user_account_control_change(struct samldb_ctx *ac)
 		el->flags = LDB_FLAG_MOD_REPLACE;
 	}
 
-	/* "isCriticalSystemObject" might be set/changed */
-	if (old_is_critical != new_is_critical) {
+	/*
+	 * "isCriticalSystemObject" might be set/changed
+	 *
+	 * Even a change from UF_NORMAL_ACCOUNT (implicitly FALSE) to
+	 * UF_WORKSTATION_TRUST_ACCOUNT (actually FALSE) triggers
+	 * creating the attribute.
+	 */
+	if (old_is_critical != new_is_critical || old_atype != new_atype) {
 		ret = ldb_msg_add_string(ac->msg, "isCriticalSystemObject",
 					 new_is_critical ? "TRUE": "FALSE");
 		if (ret != LDB_SUCCESS) {
-- 
2.23.0

