s4:dsdb: Factor out a function to remove all password related attributes
authorJo Sutton <josutton@catalyst.net.nz>
Tue, 9 Apr 2024 00:15:00 +0000 (12:15 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 16 Apr 2024 03:55:47 +0000 (15:55 +1200)
Signed-off-by: Jo Sutton <josutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source4/dsdb/samdb/ldb_modules/password_hash.c
source4/dsdb/samdb/ldb_modules/util.c

index c9f95123edf4bc9481c0c795cb773f7358115a97..c352eb9f5dcdfc37e7d5d9a612d88746606311c7 100644 (file)
@@ -4741,19 +4741,7 @@ static int password_hash_needed(struct ldb_module *module,
                return ldb_oom(ldb);
        }
 
-       /*
-        * Remove all password related attributes.
-        */
-       if (ac->userPassword) {
-               ldb_msg_remove_attr(ac->update_msg, "userPassword");
-       }
-       ldb_msg_remove_attr(ac->update_msg, "clearTextPassword");
-       ldb_msg_remove_attr(ac->update_msg, "unicodePwd");
-       ldb_msg_remove_attr(ac->update_msg, "ntPwdHistory");
-       ldb_msg_remove_attr(ac->update_msg, "dBCSPwd");
-       ldb_msg_remove_attr(ac->update_msg, "lmPwdHistory");
-       ldb_msg_remove_attr(ac->update_msg, "supplementalCredentials");
-       ldb_msg_remove_attr(ac->update_msg, "pwdLastSet");
+       dsdb_remove_password_related_attrs(ac->update_msg, ac->userPassword);
 
        *_ac = ac;
        return LDB_SUCCESS;
index 6e87531ed3843cfbbe2df24c51273be763a8e501..b343828d5084c9ec3cb7dc8643bac41b788135da 100644 (file)
@@ -1955,3 +1955,21 @@ int dsdb_make_object_category(struct ldb_context *ldb, const struct dsdb_schema
 
        return LDB_SUCCESS;
 }
+
+/*
+ * Remove all password related attributes.
+ */
+void dsdb_remove_password_related_attrs(struct ldb_message *msg,
+                                       bool userPassword)
+{
+       if (userPassword) {
+               ldb_msg_remove_attr(msg, "userPassword");
+       }
+       ldb_msg_remove_attr(msg, "clearTextPassword");
+       ldb_msg_remove_attr(msg, "unicodePwd");
+       ldb_msg_remove_attr(msg, "ntPwdHistory");
+       ldb_msg_remove_attr(msg, "dBCSPwd");
+       ldb_msg_remove_attr(msg, "lmPwdHistory");
+       ldb_msg_remove_attr(msg, "supplementalCredentials");
+       ldb_msg_remove_attr(msg, "pwdLastSet");
+}