Add detection for need of update to the registry db.
authorMichael Adam <obnox@samba.org>
Mon, 14 Jan 2008 17:31:11 +0000 (18:31 +0100)
committerGünther Deschner <gd@samba.org>
Mon, 14 Jan 2008 18:38:01 +0000 (19:38 +0100)
This only detects if the tdb sequence number has changed
since the data has last been read.

Michael
(This used to be commit 3f081ebeadf30a7943723703ecae479e0412c60c)

source3/include/reg_objects.h
source3/registry/reg_api.c
source3/registry/reg_db.c
source3/registry/reg_frontend_hilvl.c
source3/registry/reg_printing.c
source3/registry/reg_shares.c
source3/registry/reg_smbconf.c

index f6cf9cccb7150a7c9a7f45ff4defc73216c41ce3..23a14e6757a4940509d34a9060cc7dd95735895e 100644 (file)
@@ -61,6 +61,7 @@ struct registry_value {
 typedef struct {
        uint32          num_values;
        REGISTRY_VALUE  **values;
+       int seqnum;
 } REGVAL_CTR;
 
 /* container for registry subkey names */
@@ -68,6 +69,7 @@ typedef struct {
 typedef struct {
        uint32          num_subkeys;
        char            **subkeys;
+       int seqnum;
 } REGSUBKEY_CTR;
 
 /*
@@ -128,6 +130,8 @@ typedef struct {
                              struct security_descriptor **psecdesc);
        WERROR (*set_secdesc)(const char *key,
                              struct security_descriptor *sec_desc);
+       bool    (*subkeys_need_update)(REGSUBKEY_CTR *subkeys);
+       bool    (*values_need_update)(REGVAL_CTR *values);
 } REGISTRY_OPS;
 
 typedef struct {
index bb410e646b06a5ce008c11a2a5f182bcc2dcc291..8bbdb6abd3cadeb3986cfed9d1838da84ec4bac3 100644 (file)
@@ -27,7 +27,9 @@
 static WERROR fill_value_cache(struct registry_key *key)
 {
        if (key->values != NULL) {
-               return WERR_OK;
+               if (!reg_values_need_update(key->key, key->values)) {
+                       return WERR_OK;
+               }
        }
 
        if (!(key->values = TALLOC_ZERO_P(key, REGVAL_CTR))) {
@@ -44,7 +46,9 @@ static WERROR fill_value_cache(struct registry_key *key)
 static WERROR fill_subkey_cache(struct registry_key *key)
 {
        if (key->subkeys != NULL) {
-               return WERR_OK;
+               if (!reg_subkeys_need_update(key->key, key->subkeys)) {
+                       return WERR_OK;
+               }
        }
 
        if (!(key->subkeys = TALLOC_ZERO_P(key, REGSUBKEY_CTR))) {
index f50a41816c114ff57b289de9e8058ceca3ef2e16..c4bfc2b6c9c9c7c51b19ba629cab3f199d67a436 100644 (file)
@@ -622,7 +622,15 @@ int regdb_fetch_keys(const char *key, REGSUBKEY_CTR *ctr)
        }
        strupper_m(path);
 
+       if (tdb_read_lock_bystring_with_timeout(tdb_reg->tdb, path, 10) == -1) {
+               return 0;
+       }
+
        dbuf = tdb_fetch_bystring(tdb_reg->tdb, path);
+       ctr->seqnum = regdb_get_seqnum();
+
+       tdb_read_unlock_bystring(tdb_reg->tdb, path);
+
 
        buf = dbuf.dptr;
        buflen = dbuf.dsize;
@@ -750,7 +758,14 @@ int regdb_fetch_values( const char* key, REGVAL_CTR *values )
                return 0;
        }
 
+       if (tdb_read_lock_bystring_with_timeout(tdb_reg->tdb, keystr, 10) == -1) {
+               return 0;
+       }
+
        data = tdb_fetch_bystring(tdb_reg->tdb, keystr);
+       values->seqnum = regdb_get_seqnum();
+
+       tdb_read_unlock_bystring(tdb_reg->tdb, keystr);
 
        if (!data.dptr) {
                /* all keys have zero values by default */
@@ -907,6 +922,16 @@ static WERROR regdb_set_secdesc(const char *key,
        return err;
 }
 
+bool regdb_subkeys_need_update(REGSUBKEY_CTR *subkeys)
+{
+       return (regdb_get_seqnum() != subkeys->seqnum);
+}
+
+bool regdb_values_need_update(REGVAL_CTR *values)
+{
+       return (regdb_get_seqnum() != values->seqnum);
+}
+
 /* 
  * Table of function pointers for default access
  */
@@ -918,5 +943,7 @@ REGISTRY_OPS regdb_ops = {
        regdb_store_values,
        NULL,
        regdb_get_secdesc,
-       regdb_set_secdesc
+       regdb_set_secdesc,
+       regdb_subkeys_need_update,
+       regdb_values_need_update
 };
index a4b78b24c0e657a8fa62db599bf8e355ec1a2939..73fcf87e17a63f34739d565e0440950b41b3a51d 100644 (file)
@@ -214,3 +214,32 @@ WERROR regkey_set_secdesc(REGISTRY_KEY *key,
 
        return WERR_ACCESS_DENIED;
 }
+
+/**
+ * Check whether the in-memory version of the subkyes of a
+ * registry key needs update from disk.
+ */
+bool reg_subkeys_need_update(REGISTRY_KEY *key, REGSUBKEY_CTR *subkeys)
+{
+       if (key->hook && key->hook->ops && key->hook->ops->subkeys_need_update)
+       {
+               return key->hook->ops->subkeys_need_update(subkeys);
+       }
+
+       return false;
+}
+
+/**
+ * Check whether the in-memory version of the values of a
+ * registry key needs update from disk.
+ */
+bool reg_values_need_update(REGISTRY_KEY *key, REGVAL_CTR *values)
+{
+       if (key->hook && key->hook->ops && key->hook->ops->values_need_update)
+       {
+               return key->hook->ops->values_need_update(values);
+       }
+
+       return false;
+}
+
index 2ca74f7c169c39dc9cb4b43ae653b29ade19b9d8..5be07960024f83f6c7e046272ee9cbfe86b3a135 100644 (file)
@@ -1266,5 +1266,5 @@ REGISTRY_OPS printing_ops = {
        regprint_fetch_reg_values,
        regprint_store_reg_keys,
        regprint_store_reg_values,
-       NULL, NULL, NULL
+       NULL, NULL, NULL, NULL, NULL
 };
index 178f23e21cc276d21fde8affc997e6a56a4ed622..4ac6e1d1514bef7bb7126174cc8a4ab4c351825f 100644 (file)
@@ -159,7 +159,7 @@ REGISTRY_OPS shares_reg_ops = {
        shares_value_info,
        shares_store_subkey,
        shares_store_value,
-       NULL, NULL, NULL
+       NULL, NULL, NULL, NULL, NULL
 };
 
 
index 116cde936ed48c00d37f7b4c9825ae4750b88902..8dfb745a7e7f9c2c927f49e2df6ee662f6a7861f 100644 (file)
@@ -271,5 +271,7 @@ REGISTRY_OPS smbconf_reg_ops = {
        smbconf_store_values,
        smbconf_reg_access_check,
        smbconf_get_secdesc,
-       smbconf_set_secdesc
+       smbconf_set_secdesc,
+       NULL,
+       NULL
 };