]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s4-dsdb: Do not use a possibly-old loadparm context in schema reload
authorAndrew Bartlett <abartlet@samba.org>
Wed, 22 Aug 2012 12:08:36 +0000 (22:08 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 23 Aug 2012 13:02:25 +0000 (15:02 +0200)
The loadparm context on the schema DB might have gone away already.
Pre-cache the schema refresh interval at load time to avoid worrying
about this.

Andrew Bartlett

source4/dsdb/samdb/ldb_modules/schema_load.c
source4/dsdb/schema/schema.h
source4/dsdb/schema/schema_init.c

index be7915e03cba995b1de64c0502692a09b6755e85..f09c47a3edbe3a54887e612cb4723ede543a9abb 100644 (file)
@@ -166,10 +166,7 @@ static struct dsdb_schema *dsdb_schema_refresh(struct ldb_module *module, struct
        struct dsdb_control_current_partition *ctrl;
        struct ldb_context *ldb = ldb_module_get_ctx(module);
        struct dsdb_schema *new_schema;
-       int interval;
-       time_t ts, lastts;
-       struct loadparm_context *lp_ctx =
-               (struct loadparm_context *)ldb_get_opaque(ldb, "loadparm");
+       time_t ts, lastts;      
        
        struct schema_load_private_data *private_data = talloc_get_type(ldb_module_get_private(module), struct schema_load_private_data);
        if (!private_data) {
@@ -184,9 +181,8 @@ static struct dsdb_schema *dsdb_schema_refresh(struct ldb_module *module, struct
 
        lastts = schema->last_refresh;
        ts = time(NULL);
-       interval = lpcfg_parm_int(lp_ctx, NULL, "dsdb", "schema_reload_interval", 120);
-       if (lastts > (ts - interval)) {
-               DEBUG(11, ("Less than %d seconds since last reload, returning cached version ts = %d\n", interval, (int)lastts));
+       if (lastts > (ts - schema->refresh_interval)) {
+               DEBUG(11, ("Less than %d seconds since last reload, returning cached version ts = %d\n", (int)schema->refresh_interval, (int)lastts));
                return schema;
        }
 
index 81ac129d5e75e8dbf54d66418058957a832825ef..eb288e6bf9648c4e6a20b3d39816955b83d0c6c0 100644 (file)
@@ -247,6 +247,7 @@ struct dsdb_schema {
        bool refresh_in_progress;
        time_t ts_last_change;
        time_t last_refresh;
+       time_t refresh_interval;
        /* This 'opaque' is stored in the metadata and is used to check if the currently
         * loaded schema needs a reload because another process has signaled that it has been
         * requested to reload the schema (either due through DRS or via the schemaUpdateNow).
index 8385ac2def921b3806f703e9d2f59d7d89ce2c3d..752d4f57dd1c7dde8bb218d47c59c42e087955ea 100644 (file)
@@ -39,6 +39,7 @@ struct dsdb_schema *dsdb_new_schema(TALLOC_CTX *mem_ctx)
        if (!schema) {
                return NULL;
        }
+       schema->refresh_interval = 120;
 
        return schema;
 }
@@ -93,6 +94,8 @@ struct dsdb_schema *dsdb_schema_copy_shallow(TALLOC_CTX *mem_ctx,
        }
        schema_copy->num_attributes = schema->num_attributes;
 
+       schema_copy->refresh_interval = schema->refresh_interval;
+
        /* rebuild indexes */
        ret = dsdb_setup_sorted_accessors(ldb, schema_copy);
        if (ret != LDB_SUCCESS) {
@@ -840,7 +843,7 @@ int dsdb_schema_from_ldb_results(TALLOC_CTX *mem_ctx, struct ldb_context *ldb,
        const struct ldb_val *info_val;
        struct ldb_val info_val_default;
        struct dsdb_schema *schema;
-       struct loadparm_context *lp_ctx = NULL;
+       void *lp_opaque = ldb_get_opaque(ldb, "loadparm");
        int ret;
 
        TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
@@ -856,6 +859,16 @@ int dsdb_schema_from_ldb_results(TALLOC_CTX *mem_ctx, struct ldb_context *ldb,
                return ldb_operr(ldb);
        }
 
+       if (lp_opaque) {
+               struct loadparm_context *lp_ctx = talloc_get_type_abort(lp_opaque, struct loadparm_context);
+               schema->refresh_interval = lpcfg_parm_int(lp_ctx, NULL, "dsdb", "schema_reload_interval", schema->refresh_interval);
+               lp_ctx = talloc_get_type(ldb_get_opaque(ldb, "loadparm"),
+                                        struct loadparm_context);
+               schema->fsmo.update_allowed = lpcfg_parm_bool(lp_ctx, NULL,
+                                                             "dsdb", "schema update allowed",
+                                                             false);
+       }
+
        schema->base_dn = talloc_steal(schema, schema_res->msgs[0]->dn);
 
        prefix_val = ldb_msg_find_ldb_val(schema_res->msgs[0], "prefixMap");
@@ -903,17 +916,6 @@ int dsdb_schema_from_ldb_results(TALLOC_CTX *mem_ctx, struct ldb_context *ldb,
                schema->fsmo.we_are_master = false;
        }
 
-       lp_ctx = talloc_get_type(ldb_get_opaque(ldb, "loadparm"),
-                                               struct loadparm_context);
-       if (lp_ctx) {
-               bool allowed = lpcfg_parm_bool(lp_ctx, NULL,
-                                               "dsdb", "schema update allowed",
-                                               false);
-               schema->fsmo.update_allowed = allowed;
-       } else {
-               schema->fsmo.update_allowed = false;
-       }
-
        DEBUG(5, ("schema_fsmo_init: we are master[%s] updates allowed[%s]\n",
                  (schema->fsmo.we_are_master?"yes":"no"),
                  (schema->fsmo.update_allowed?"yes":"no")));