s4:dsdb/repl: make sure the working_schema prefix map is populated with the remote...
authorStefan Metzmacher <metze@samba.org>
Mon, 8 Aug 2016 09:07:18 +0000 (11:07 +0200)
committerStefan Metzmacher <metze@samba.org>
Thu, 11 Aug 2016 05:10:39 +0000 (07:10 +0200)
We should create the working_schema prefix map before we try to
resolve the schema. This allows getting the same mapping (if there's not already
a conflict) and allows us to remove the implicit prefix mapping creation
in the prefix mapping lookup functions.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
(cherry picked from commit edeb577a59ea88d2a22559ffb8cbe994ea28f3f1)

source4/dsdb/repl/replicated_objects.c

index 17b68a42d2a5cd9d2abbe74ab6f37c84bde32e0b..288bcc111c2ff18677b577c3a188abf0ae9f5f3e 100644 (file)
@@ -291,6 +291,7 @@ WERROR dsdb_repl_make_working_schema(struct ldb_context *ldb,
 {
        WERROR werr;
        struct dsdb_schema_prefixmap *pfm_remote;
+       uint32_t r;
        struct dsdb_schema *working_schema;
 
        /* make a copy of the iniatial_scheam so we don't mess with it */
@@ -310,6 +311,40 @@ WERROR dsdb_repl_make_working_schema(struct ldb_context *ldb,
                return werr;
        }
 
+       for (r=0; r < pfm_remote->length; r++) {
+               const struct dsdb_schema_prefixmap_oid *rm = &pfm_remote->prefixes[r];
+               bool found_oid = false;
+               uint32_t l;
+
+               for (l=0; l < working_schema->prefixmap->length; l++) {
+                       const struct dsdb_schema_prefixmap_oid *lm = &working_schema->prefixmap->prefixes[l];
+                       int cmp;
+
+                       cmp = data_blob_cmp(&rm->bin_oid, &lm->bin_oid);
+                       if (cmp == 0) {
+                               found_oid = true;
+                               break;
+                       }
+               }
+
+               if (found_oid) {
+                       continue;
+               }
+
+               /*
+                * We prefer the same is as we got from the remote peer
+                * if there's no conflict.
+                */
+               werr = dsdb_schema_pfm_add_entry(working_schema->prefixmap,
+                                                rm->bin_oid, &rm->id, NULL);
+               if (!W_ERROR_IS_OK(werr)) {
+                       DEBUG(0,(__location__ ": Failed to merge remote prefixMap: %s",
+                                win_errstr(werr)));
+                       talloc_free(working_schema);
+                       return werr;
+               }
+       }
+
        werr = dsdb_repl_resolve_working_schema(ldb,
                                                pfm_remote,
                                                0, /* cycle_before_switching */