s4:dsdb/samdb: add DSDB_FLAG_INTERNAL_FORCE_META_DATA
authorStefan Metzmacher <metze@samba.org>
Wed, 1 Jun 2016 21:13:21 +0000 (23:13 +0200)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 8 Jul 2016 08:01:19 +0000 (10:01 +0200)
With this it's possible to add a replPropertyMetaData entry for an empty
attribute.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source4/dsdb/samdb/ldb_modules/repl_meta_data.c
source4/dsdb/samdb/samdb.h

index 1db23927be04349d6c8b07d12f3037683a974cae..80808347e4fc683c82984fe30992455f8a5b4a4b 100644 (file)
@@ -986,12 +986,15 @@ static int replmd_add(struct ldb_module *module, struct ldb_request *req)
 
        is_schema_nc = ldb_dn_compare_base(replmd_private->schema_dn, msg->dn) == 0;
 
-       for (i=0; i < msg->num_elements; i++) {
+       for (i=0; i < msg->num_elements;) {
                struct ldb_message_element *e = &msg->elements[i];
                struct replPropertyMetaData1 *m = &nmd.ctr.ctr1.array[ni];
                const struct dsdb_attribute *sa;
 
-               if (e->name[0] == '@') continue;
+               if (e->name[0] == '@') {
+                       i++;
+                       continue;
+               }
 
                sa = dsdb_attribute_by_lDAPDisplayName(ac->schema, e->name);
                if (!sa) {
@@ -1006,6 +1009,7 @@ static int replmd_add(struct ldb_module *module, struct ldb_request *req)
                        /* if the attribute is not replicated (0x00000001)
                         * or constructed (0x00000004) it has no metadata
                         */
+                       i++;
                        continue;
                }
 
@@ -1019,6 +1023,7 @@ static int replmd_add(struct ldb_module *module, struct ldb_request *req)
                        }
                        /* linked attributes are not stored in
                           replPropertyMetaData in FL above w2k */
+                       i++;
                        continue;
                }
 
@@ -1051,6 +1056,20 @@ static int replmd_add(struct ldb_module *module, struct ldb_request *req)
                m->originating_usn              = ac->seq_num;
                m->local_usn                    = ac->seq_num;
                ni++;
+
+               if (!(e->flags & DSDB_FLAG_INTERNAL_FORCE_META_DATA)) {
+                       i++;
+                       continue;
+               }
+
+               e->flags &= ~DSDB_FLAG_INTERNAL_FORCE_META_DATA;
+
+               if (e->num_values != 0) {
+                       i++;
+                       continue;
+               }
+
+               ldb_msg_remove_element(msg, e);
        }
 
        /* fix meta data count */
@@ -1237,6 +1256,11 @@ static int replmd_update_rpmd_element(struct ldb_context *ldb,
                }
        }
 
+       if (el->flags & DSDB_FLAG_INTERNAL_FORCE_META_DATA) {
+               may_skip = false;
+               el->flags &= ~DSDB_FLAG_INTERNAL_FORCE_META_DATA;
+       }
+
        if (may_skip) {
                if (strcmp(el->name, "interSiteTopologyGenerator") != 0 &&
                    !ldb_request_get_control(req, LDB_CONTROL_PROVISION_OID)) {
@@ -1565,10 +1589,13 @@ static int replmd_update_rpmd(struct ldb_module *module,
                        return LDB_ERR_OPERATIONS_ERROR;
                }
 
-               for (i=0; i<msg->num_elements; i++) {
+               for (i=0; i<msg->num_elements;) {
+                       struct ldb_message_element *el = &msg->elements[i];
                        struct ldb_message_element *old_el;
-                       old_el = ldb_msg_find_element(res->msgs[0], msg->elements[i].name);
-                       ret = replmd_update_rpmd_element(ldb, msg, &msg->elements[i], old_el, &omd, schema, seq_num,
+
+                       old_el = ldb_msg_find_element(res->msgs[0], el->name);
+                       ret = replmd_update_rpmd_element(ldb, msg, el, old_el,
+                                                        &omd, schema, seq_num,
                                                         our_invocation_id,
                                                         now, is_schema_nc,
                                                         req);
@@ -1577,9 +1604,22 @@ static int replmd_update_rpmd(struct ldb_module *module,
                        }
 
                        if (!*is_urgent && (situation == REPL_URGENT_ON_UPDATE)) {
-                               *is_urgent = replmd_check_urgent_attribute(&msg->elements[i]);
+                               *is_urgent = replmd_check_urgent_attribute(el);
+                       }
+
+                       if (!(el->flags & DSDB_FLAG_INTERNAL_FORCE_META_DATA)) {
+                               i++;
+                               continue;
+                       }
+
+                       el->flags &= ~DSDB_FLAG_INTERNAL_FORCE_META_DATA;
+
+                       if (el->num_values != 0) {
+                               i++;
+                               continue;
                        }
 
+                       ldb_msg_remove_element(msg, el);
                }
        }
 
index 12971dd6d93570f1afbbf891006c9a3f1e200829..8c5e1779b535239dafe4171c252c5ebd4483dac3 100644 (file)
@@ -296,4 +296,11 @@ struct dsdb_extended_sec_desc_propagation_op {
 #define DSDB_SAMDB_MINIMUM_ALLOWED_RID   1000
 
 #define DSDB_METADATA_SCHEMA_SEQ_NUM   "SCHEMA_SEQ_NUM"
+
+/*
+ * must be in LDB_FLAG_INTERNAL_MASK
+ * see also the values in lib/ldb/include/ldb_module.h
+ */
+#define DSDB_FLAG_INTERNAL_FORCE_META_DATA 0x10000
+
 #endif /* __SAMDB_H__ */