]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
replmd: Move where we update the usnChanged/whenChanged
authorTim Beale <timbeale@catalyst.net.nz>
Sun, 11 Nov 2018 22:13:28 +0000 (11:13 +1300)
committerTim Beale <timbeale@samba.org>
Wed, 21 Nov 2018 00:51:11 +0000 (01:51 +0100)
Move this closer to where the source object actually gets modified.

The main reason to do this is that adding fields can cause the
msg->elements to be reallocated, which will invalidate all the
old_el and pdn_list pointers which are derived from the msg.

Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source4/dsdb/samdb/ldb_modules/repl_meta_data.c

index b97c9db355fada37074cd9ee9243e56d61a09e7e..88c5b6c9c4fec8f390be4820a7e50cd0b1d73f1a 100644 (file)
@@ -7947,7 +7947,6 @@ static int replmd_process_linked_attribute(struct ldb_module *module,
        struct dsdb_dn *dsdb_dn = NULL;
        uint64_t seq_num = 0;
        struct ldb_message_element *old_el;
-       time_t t = time(NULL);
        struct parsed_dn *pdn_list, *pdn, *next;
        struct GUID guid = GUID_zero();
        bool active = (la->flags & DRSUAPI_DS_LINKED_ATTRIBUTE_FLAG_ACTIVE)?true:false;
@@ -8142,22 +8141,6 @@ static int replmd_process_linked_attribute(struct ldb_module *module,
                }
        }
 
-       /* we only change whenChanged and uSNChanged if the seq_num
-          has changed */
-       ldb_msg_remove_attr(msg, "whenChanged");
-       ldb_msg_remove_attr(msg, "uSNChanged");
-       ret = add_time_element(msg, "whenChanged", t);
-       if (ret != LDB_SUCCESS) {
-               ldb_operr(ldb);
-               return ret;
-       }
-
-       ret = add_uint64_element(ldb, msg, "uSNChanged", seq_num);
-       if (ret != LDB_SUCCESS) {
-               ldb_operr(ldb);
-               return ret;
-       }
-
        old_el = ldb_msg_find_element(msg, attr->lDAPDisplayName);
        if (old_el == NULL) {
                return ldb_operr(ldb);
@@ -8229,6 +8212,8 @@ static int replmd_process_la_group(struct ldb_module *module,
        const struct dsdb_attribute *attr = NULL;
        replmd_link_changed change_type;
        uint32_t num_changes = 0;
+       time_t t;
+       uint64_t seq_num = 0;
 
        /*
         * get the attribute being modified and the search result for the
@@ -8308,6 +8293,26 @@ static int replmd_process_la_group(struct ldb_module *module,
                return LDB_SUCCESS;
        }
 
+       /* update whenChanged/uSNChanged as the object has changed */
+       t = time(NULL);
+       ret = ldb_sequence_number(ldb, LDB_SEQ_HIGHEST_SEQ,
+                                 &seq_num);
+       if (ret != LDB_SUCCESS) {
+               return ret;
+       }
+
+       ret = add_time_element(msg, "whenChanged", t);
+       if (ret != LDB_SUCCESS) {
+               ldb_operr(ldb);
+               return ret;
+       }
+
+       ret = add_uint64_element(ldb, msg, "uSNChanged", seq_num);
+       if (ret != LDB_SUCCESS) {
+               ldb_operr(ldb);
+               return ret;
+       }
+
        /* apply the link changes to the source object */
        ret = linked_attr_modify(module, msg, NULL);
        if (ret != LDB_SUCCESS) {