]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
dsdb: Do not write the @INDEXLIST or @ATTRIBUTES records during schema refresh
authorAndrew Bartlett <abartlet@samba.org>
Wed, 3 May 2017 20:53:14 +0000 (22:53 +0200)
committerAndrew Bartlett <abartlet@samba.org>
Mon, 22 May 2017 23:13:25 +0000 (01:13 +0200)
Instead, write it once in the module init, if required, and after a
modify to the schema partition is detected

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
source4/dsdb/samdb/ldb_modules/schema_load.c
source4/dsdb/schema/schema_set.c
source4/dsdb/schema/tests/schema_syntax.c
source4/libnet/libnet_vampire.c
source4/torture/drs/drs_util.c

index d9814e2d83cf560f3947f6f87c2f4ae058c14b55..6ffa4650dd944d06535563d426aac1f02fc5547f 100644 (file)
@@ -246,7 +246,7 @@ static struct dsdb_schema *dsdb_schema_refresh(struct ldb_module *module, struct
                return schema;
        }
 
-       ret = dsdb_set_schema(ldb, new_schema);
+       ret = dsdb_set_schema(ldb, new_schema, false);
        if (ret != LDB_SUCCESS) {
                ldb_debug_set(ldb, LDB_DEBUG_FATAL,
                              "dsdb_set_schema() failed: %d:%s: %s",
@@ -417,7 +417,7 @@ static int schema_load_init(struct ldb_module *module)
                }
 
                /* "dsdb_set_schema()" steals schema into the ldb_context */
-               ret = dsdb_set_schema(ldb, new_schema);
+               ret = dsdb_set_schema(ldb, new_schema, false);
                if (ret != LDB_SUCCESS) {
                        ldb_debug_set(ldb, LDB_DEBUG_FATAL,
                                      "schema_load_init: dsdb_set_schema() failed: %d:%s: %s",
@@ -449,6 +449,17 @@ static int schema_load_init(struct ldb_module *module)
                return LDB_ERR_OPERATIONS_ERROR;
        }
 
+       /* Now check the @INDEXLIST is correct, or fix it up */
+       ret = dsdb_schema_set_indices_and_attributes(ldb, schema,
+                                                    true);
+       if (ret != LDB_SUCCESS) {
+               ldb_asprintf_errstring(ldb, "Failed to update "
+                                      "@INDEXLIST and @ATTRIBUTES "
+                                      "records to match database schema: %s",
+                                      ldb_errstring(ldb));
+               return ret;
+       }
+
        return ret;
 }
 
@@ -504,13 +515,27 @@ static int schema_load_del_transaction(struct ldb_module *module)
 static int schema_load_extended(struct ldb_module *module, struct ldb_request *req)
 {
        struct ldb_context *ldb = ldb_module_get_ctx(module);
-
+       struct dsdb_schema *schema;
+       int ret;
+       
        if (strcmp(req->op.extended.oid, DSDB_EXTENDED_SCHEMA_UPDATE_NOW_OID) != 0) {
                return ldb_next_request(module, req);
        }
        /* Force a refresh */
-       dsdb_get_schema(ldb, NULL);
+       schema = dsdb_get_schema(ldb, NULL);
 
+       ret = dsdb_schema_set_indices_and_attributes(ldb,
+                                                    schema,
+                                                    true);
+
+       if (ret != LDB_SUCCESS) {
+               ldb_asprintf_errstring(ldb, "Failed to write new "
+                                      "@INDEXLIST and @ATTRIBUTES "
+                                      "records for updated schema: %s",
+                                      ldb_errstring(ldb));
+               return ret;
+       }
+       
        /* Pass to next module, the partition one should finish the chain */
        return ldb_next_request(module, req);
 }
index 2e688d07546a10be2afa3669aa816378d1a18398..d3e3cc8f55b8ccce7d7e52d9355a5dcad9bcba0c 100644 (file)
@@ -56,7 +56,9 @@ const struct ldb_schema_attribute *dsdb_attribute_handler_override(struct ldb_co
  * are required so we can operate on a schema-less database (say the
  * backend during emergency fixes) and during the schema load.
  */
-static int dsdb_schema_set_indices_and_attributes(struct ldb_context *ldb, struct dsdb_schema *schema, bool write_indices_and_attributes)
+int dsdb_schema_set_indices_and_attributes(struct ldb_context *ldb,
+                                          struct dsdb_schema *schema,
+                                          bool write_indices_and_attributes)
 {
        int ret = LDB_SUCCESS;
        struct ldb_result *res;
@@ -468,7 +470,9 @@ int dsdb_set_schema_refresh_function(struct ldb_context *ldb,
  * Attach the schema to an opaque pointer on the ldb,
  * so ldb modules can find it
  */
-int dsdb_set_schema(struct ldb_context *ldb, struct dsdb_schema *schema)
+int dsdb_set_schema(struct ldb_context *ldb,
+                   struct dsdb_schema *schema,
+                   bool write_indices_and_attributes)
 {
        struct dsdb_schema *old_schema;
        int ret;
@@ -493,7 +497,8 @@ int dsdb_set_schema(struct ldb_context *ldb, struct dsdb_schema *schema)
        talloc_steal(ldb, schema);
 
        /* Set the new attributes based on the new schema */
-       ret = dsdb_schema_set_indices_and_attributes(ldb, schema, true);
+       ret = dsdb_schema_set_indices_and_attributes(ldb, schema,
+                                                    write_indices_and_attributes);
        if (ret != LDB_SUCCESS) {
                return ret;
        }
@@ -884,7 +889,7 @@ WERROR dsdb_set_schema_from_ldif(struct ldb_context *ldb,
                }
        }
 
-       ret = dsdb_set_schema(ldb, schema);
+       ret = dsdb_set_schema(ldb, schema, true);
        if (ret != LDB_SUCCESS) {
                status = WERR_FOOBAR;
                goto failed;
index 419dc3dc4c27d84e97d735fb5858a2140462b9ce..cb4d8029546eed1b6e6e4993fba76bb3f3957c3e 100644 (file)
@@ -78,7 +78,7 @@ static bool torture_syntax_add_OR_Name(struct torture_context *tctx,
        ldb_ldif_read_free(ldb, ldif);
        torture_assert_werr_ok(tctx, werr, "dsdb_set_attribute_from_ldb() failed!");
 
-       ldb_res = dsdb_set_schema(ldb, schema);
+       ldb_res = dsdb_set_schema(ldb, schema, true);
        torture_assert_int_equal(tctx, ldb_res, LDB_SUCCESS, "dsdb_set_schema() failed");
 
        return true;
index f6bcf2951a3696cc612c57744a6bba8571aa1b04..7f25a3aa07835531ddadef6d84554f6ddfc8119c 100644 (file)
@@ -365,7 +365,7 @@ static WERROR libnet_vampire_cb_apply_schema(struct libnet_vampire_cb_state *s,
         * attach the schema we just brought over DRS to the ldb,
         * so we can use it in dsdb_convert_object_ex below
         */
-       ret = dsdb_set_schema(s->ldb, s->self_made_schema);
+       ret = dsdb_set_schema(s->ldb, s->self_made_schema, true);
        if (ret != LDB_SUCCESS) {
                DEBUG(0,("Failed to attach working schema from DRS.\n"));
                return WERR_INTERNAL_ERROR;
index 7809e67103840293ce7e2b848287fc67f79b9d88..7c073c9f6e73425737ab6b477dd810e73805dbb6 100644 (file)
@@ -158,7 +158,7 @@ bool drs_util_dsdb_schema_load_ldb(struct torture_context *tctx,
 
        talloc_free(res);
 
-       ret = dsdb_set_schema(ldb, ldap_schema);
+       ret = dsdb_set_schema(ldb, ldap_schema, true);
        if (ret != LDB_SUCCESS) {
                torture_fail(tctx,
                             talloc_asprintf(tctx, "dsdb_set_schema() failed: %s", ldb_strerror(ret)));