1
0
mirror of https://github.com/samba-team/samba.git synced 2025-06-22 07:17:05 +03:00

Add detection for need of update to the registry db.

This only detects if the tdb sequence number has changed
since the data has last been read.

Michael
(This used to be commit 3f081ebeadf30a7943723703ecae479e0412c60c)
This commit is contained in:
Michael Adam 2008-01-14 18:31:11 +01:00 committed by Günther Deschner
parent 36a7316bfc
commit d35bda0ffd
7 changed files with 72 additions and 6 deletions

View 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 {

View File

@ -27,8 +27,10 @@
static WERROR fill_value_cache(struct registry_key *key)
{
if (key->values != NULL) {
if (!reg_values_need_update(key->key, key->values)) {
return WERR_OK;
}
}
if (!(key->values = TALLOC_ZERO_P(key, REGVAL_CTR))) {
return WERR_NOMEM;
@ -44,8 +46,10 @@ static WERROR fill_value_cache(struct registry_key *key)
static WERROR fill_subkey_cache(struct registry_key *key)
{
if (key->subkeys != NULL) {
if (!reg_subkeys_need_update(key->key, key->subkeys)) {
return WERR_OK;
}
}
if (!(key->subkeys = TALLOC_ZERO_P(key, REGSUBKEY_CTR))) {
return WERR_NOMEM;

View 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
};

View 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;
}

View 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
};

View 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
};

View 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
};