From b0501a1cb0b6503b71a2854a4abba3baae1d4f83 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 7 Jul 2016 15:44:47 +0200 Subject: [PATCH] s4:dsdb/common: add a replication metadata stamp for an empty logonHours attribute When a user object is created it gets a metadata stamp for logonHours, while the logonHours attribute has no value. Signed-off-by: Stefan Metzmacher Reviewed-by: Andrew Bartlett --- source4/dsdb/common/util.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/source4/dsdb/common/util.c b/source4/dsdb/common/util.c index ed2dde31355..2aed8042d3a 100644 --- a/source4/dsdb/common/util.c +++ b/source4/dsdb/common/util.c @@ -739,6 +739,7 @@ static int samdb_find_or_add_attribute_ex(struct ldb_context *ldb, struct ldb_message *msg, const char *name, const char *set_value, + unsigned attr_flags, bool *added) { int ret; @@ -753,11 +754,22 @@ static int samdb_find_or_add_attribute_ex(struct ldb_context *ldb, return LDB_SUCCESS; } - ret = ldb_msg_add_string(msg, name, set_value); + SMB_ASSERT(set_value != NULL || attr_flags != 0); + + ret = ldb_msg_add_empty(msg, name, + LDB_FLAG_MOD_ADD | attr_flags, + &el); if (ret != LDB_SUCCESS) { return ret; } - msg->elements[msg->num_elements - 1].flags = LDB_FLAG_MOD_ADD; + + if (set_value != NULL) { + ret = ldb_msg_add_string(msg, name, set_value); + if (ret != LDB_SUCCESS) { + return ret; + } + } + if (added != NULL) { *added = true; } @@ -766,7 +778,7 @@ static int samdb_find_or_add_attribute_ex(struct ldb_context *ldb, int samdb_find_or_add_attribute(struct ldb_context *ldb, struct ldb_message *msg, const char *name, const char *set_value) { - return samdb_find_or_add_attribute_ex(ldb, msg, name, set_value, NULL); + return samdb_find_or_add_attribute_ex(ldb, msg, name, set_value, 0, NULL); } /* @@ -5294,6 +5306,7 @@ int dsdb_user_obj_set_defaults(struct ldb_context *ldb, const char *name; const char *value; const char *add_control; + unsigned attr_flags; } map[] = { { .name = "accountExpires", @@ -5327,6 +5340,10 @@ int dsdb_user_obj_set_defaults(struct ldb_context *ldb, .name = "logonCount", .value = "0" }, + { + .name = "logonHours", + .attr_flags = DSDB_FLAG_INTERNAL_FORCE_META_DATA, + }, { .name = "pwdLastSet", .value = "0", @@ -5340,6 +5357,7 @@ int dsdb_user_obj_set_defaults(struct ldb_context *ldb, ret = samdb_find_or_add_attribute_ex(ldb, usr_obj, map[i].name, map[i].value, + map[i].attr_flags, &added); if (ret != LDB_SUCCESS) { return ret; -- 2.34.1