mirror of
https://github.com/samba-team/samba.git
synced 2025-06-21 03:17:08 +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:
parent
36a7316bfc
commit
d35bda0ffd
@ -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 {
|
||||
|
@ -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))) {
|
||||
|
@ -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
|
||||
};
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
};
|
||||
|
@ -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
|
||||
};
|
||||
|
||||
|
||||
|
@ -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
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user