diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2004-05-22 18:49:25 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 12:53:53 -0500 |
commit | bf52e242f53aeaac33eea69fbdfb3477634b90fb (patch) | |
tree | 76b04dc95e3e7befd45180a661cd7f55d085701e /source4/lib/registry/common | |
parent | 4e9d01c2a7cd044ac4b466a1039c9a7e3978d6ef (diff) | |
download | samba-bf52e242f53aeaac33eea69fbdfb3477634b90fb.tar.gz samba-bf52e242f53aeaac33eea69fbdfb3477634b90fb.tar.bz2 samba-bf52e242f53aeaac33eea69fbdfb3477634b90fb.zip |
r825: - Introduce support for multiple roots (or 'hives')
- Clean up rpc backend (possible now that multiple hives are supported)
(This used to be commit 8cd1b6bc70510fe576135a66351e9e3ea895c9ff)
Diffstat (limited to 'source4/lib/registry/common')
-rw-r--r-- | source4/lib/registry/common/reg_interface.c | 62 | ||||
-rw-r--r-- | source4/lib/registry/common/reg_objects.c | 7 | ||||
-rw-r--r-- | source4/lib/registry/common/registry.h | 24 |
3 files changed, 75 insertions, 18 deletions
diff --git a/source4/lib/registry/common/reg_interface.c b/source4/lib/registry/common/reg_interface.c index 4d1726c542..3e5a545f9a 100644 --- a/source4/lib/registry/common/reg_interface.c +++ b/source4/lib/registry/common/reg_interface.c @@ -117,6 +117,25 @@ WERROR reg_open(const char *backend, const char *location, const char *credentia return werr; } +WERROR reg_open_key_abs(REG_HANDLE *handle, const char *name, REG_KEY **result) +{ + REG_KEY *hive; + WERROR error; + int i, hivelength; + + if(strchr(name, '\\')) hivelength = strchr(name, '\\')-name; + else hivelength = strlen(name); + + for(i = 0; W_ERROR_IS_OK(error); i++) { + error = reg_get_hive(handle, i, &hive); + if(W_ERROR_IS_OK(error) && !strncmp(reg_key_name(hive), name, hivelength)) { + return reg_open_key(hive, name, result); + } + } + + return error; +} + /* Open a key * First tries to use the open_key function from the backend * then falls back to get_subkey_by_name and later get_subkey_by_index @@ -166,7 +185,7 @@ WERROR reg_open_key(REG_KEY *parent, const char *name, REG_KEY **result) return WERR_NOT_SUPPORTED; } - error = parent->handle->functions->open_key(parent->handle, fullname, result); + error = parent->handle->functions->open_key(parent->handle, parent->hive, fullname, result); if(!W_ERROR_IS_OK(error)) { talloc_destroy(mem_ctx); @@ -175,6 +194,7 @@ WERROR reg_open_key(REG_KEY *parent, const char *name, REG_KEY **result) (*result)->handle = parent->handle; (*result)->path = fullname; + (*result)->hive = parent->hive; talloc_steal(mem_ctx, (*result)->mem_ctx, fullname); talloc_destroy(mem_ctx); @@ -285,6 +305,7 @@ WERROR reg_key_get_subkey_by_index(REG_KEY *key, int idx, REG_KEY **subkey) (*subkey)->path = talloc_asprintf((*subkey)->mem_ctx, "%s%s%s", key->path, key->path[strlen(key->path)-1] == '\\'?"":"\\", (*subkey)->name); (*subkey)->handle = key->handle; + (*subkey)->hive = key->hive; return WERR_OK;; @@ -315,6 +336,7 @@ WERROR reg_key_get_subkey_by_name(REG_KEY *key, const char *name, REG_KEY **subk (*subkey)->path = talloc_asprintf((*subkey)->mem_ctx, "%s%s%s", key->path, key->path[strlen(key->path)-1] == '\\'?"":"\\", (*subkey)->name); (*subkey)->handle = key->handle; + (*subkey)->hive = key->hive; return WERR_OK; } @@ -427,6 +449,25 @@ WERROR reg_val_del(REG_VAL *val) return WERR_OK; } +WERROR reg_key_add_name_recursive_abs(REG_HANDLE *handle, const char *name) +{ + REG_KEY *hive; + WERROR error; + int i, hivelength; + + if(strchr(name, '\\')) hivelength = strchr(name, '\\')-name; + else hivelength = strlen(name); + + for(i = 0; W_ERROR_IS_OK(error); i++) { + error = reg_get_hive(handle, i, &hive); + if(W_ERROR_IS_OK(error) && !strncmp(reg_key_name(hive), name, hivelength)) { + return reg_key_add_name_recursive(hive, name); + } + } + + return error; +} + WERROR reg_key_add_name_recursive(REG_KEY *parent, const char *path) { REG_KEY *cur, *prevcur = parent; @@ -516,21 +557,26 @@ void reg_free(REG_HANDLE *h) h->functions->close_registry(h); } -WERROR reg_get_root(REG_HANDLE *h, REG_KEY **key) +WERROR reg_get_hive(REG_HANDLE *h, int hivenum, REG_KEY **key) { WERROR ret; - if(h->functions->open_root_key) { - ret = h->functions->open_root_key(h, key); + + if(h->functions->get_hive) { + ret = h->functions->get_hive(h, hivenum, key); } else if(h->functions->open_key) { - ret = h->functions->open_key(h, "\\", key); + if(hivenum == 0) ret = h->functions->open_key(h, hivenum, "", key); + else ret = WERR_NO_MORE_ITEMS; } else { - DEBUG(0, ("Backend '%s' has neither open_root_key nor open_key method implemented\n", h->functions->name)); + DEBUG(0, ("Backend '%s' has neither open_root_key nor open_key or get_hive method implemented\n", h->functions->name)); ret = WERR_NOT_SUPPORTED; } if(W_ERROR_IS_OK(ret)) { (*key)->handle = h; - (*key)->path = talloc_strdup((*key)->mem_ctx, "\\"); + if(!(*key)->path) { + (*key)->path = talloc_strdup((*key)->mem_ctx, (*key)->name); + } + (*key)->hive = hivenum; } return ret; @@ -565,7 +611,7 @@ WERROR reg_key_get_parent(REG_KEY *key, REG_KEY **parent) REG_KEY *root; WERROR error; - error = reg_get_root(key->handle, &root); + error = reg_get_hive(key->handle, key->hive, &root); if(!W_ERROR_IS_OK(error)) return error; parent_name = strdup(reg_key_get_path(key)); diff --git a/source4/lib/registry/common/reg_objects.c b/source4/lib/registry/common/reg_objects.c index 787ec52127..7a92f413ff 100644 --- a/source4/lib/registry/common/reg_objects.c +++ b/source4/lib/registry/common/reg_objects.c @@ -141,6 +141,12 @@ char *reg_val_get_path(REG_VAL *v) const char *reg_key_get_path(REG_KEY *k) { SMB_REG_ASSERT(k); + return strchr(k->path, '\\')?strchr(k->path, '\\')+1:k->path; +} + +const char *reg_key_get_path_abs(REG_KEY *k) +{ + SMB_REG_ASSERT(k); return k->path; } @@ -168,6 +174,7 @@ REG_KEY *reg_key_new_rel(const char *name, REG_KEY *k, void *data) r = talloc(mem_ctx, sizeof(REG_KEY)); ZERO_STRUCTP(r); r->handle = k->handle; + r->hive = k->hive; r->name = talloc_strdup(mem_ctx, name); r->path = talloc_asprintf(mem_ctx, "%s%s%s", parent_path, *parent_path && parent_path[strlen(parent_path)-1] != '\\'?"\\":"", name); diff --git a/source4/lib/registry/common/registry.h b/source4/lib/registry/common/registry.h index 208bcae1e1..d4e8cccade 100644 --- a/source4/lib/registry/common/registry.h +++ b/source4/lib/registry/common/registry.h @@ -40,6 +40,7 @@ struct reg_key_s { int cache_values_count; REG_KEY **cache_subkeys; int cache_subkeys_count; + int hive; TALLOC_CTX *mem_ctx; int ref; }; @@ -61,10 +62,14 @@ struct reg_val_s { typedef void (*key_notification_function) (void); typedef void (*value_notification_function) (void); - /* * Container for function pointers to enumeration routines * for virtual registry view + * + * Backends can provide : + * - just one hive (example: nt4, w95) + * - several hives (example: rpc) + * */ struct registry_ops { @@ -73,17 +78,23 @@ struct registry_ops { WERROR (*sync_key)(REG_KEY *, const char *location); WERROR (*close_registry) (REG_HANDLE *); + /* Implement this one */ + WERROR (*get_hive) (REG_HANDLE *, int , REG_KEY **); + + /* Or this one */ + WERROR (*open_key) (REG_HANDLE *, int hive, const char *name, REG_KEY **); + /* Either implement these */ - WERROR (*open_root_key) (REG_HANDLE *, REG_KEY **); WERROR (*num_subkeys) (REG_KEY *, int *count); WERROR (*num_values) (REG_KEY *, int *count); WERROR (*get_subkey_by_index) (REG_KEY *, int idx, REG_KEY **); + /* Can not contain more then one level */ WERROR (*get_subkey_by_name) (REG_KEY *, const char *name, REG_KEY **); WERROR (*get_value_by_index) (REG_KEY *, int idx, REG_VAL **); + /* Can not contain more then one level */ WERROR (*get_value_by_name) (REG_KEY *, const char *name, REG_VAL **); /* Or these */ - WERROR (*open_key) (REG_HANDLE *, const char *name, REG_KEY **); WERROR (*fetch_subkeys) (REG_KEY *, int *count, REG_KEY ***); WERROR (*fetch_values) (REG_KEY *, int *count, REG_VAL ***); @@ -111,15 +122,8 @@ struct registry_ops { void (*free_val_backend_data) (REG_VAL *); }; -typedef struct reg_sub_tree_s { - char *path; - REG_HANDLE *handle; - struct reg_sub_tree_s *prev, *next; -} REG_SUBTREE; - struct reg_handle_s { struct registry_ops *functions; - REG_SUBTREE *subtrees; char *location; char *credentials; void *backend_data; |