diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2004-12-10 22:28:49 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:06:30 -0500 |
commit | a9fa37d6187eb0d0a074fec2ecffe2915b701188 (patch) | |
tree | 35f08289b3648b80c16580c1d93c0057705845e8 /source4/lib/registry | |
parent | 9f9e9b6477c4037372f871495abe7b81f15fb58c (diff) | |
download | samba-a9fa37d6187eb0d0a074fec2ecffe2915b701188.tar.gz samba-a9fa37d6187eb0d0a074fec2ecffe2915b701188.tar.bz2 samba-a9fa37d6187eb0d0a074fec2ecffe2915b701188.zip |
r4137: Make *_open_key take a registry_key instead of a hive (more efficient
in some cases)
(This used to be commit ddf7a331c58976f2c0b4a00390118f1acf60e3eb)
Diffstat (limited to 'source4/lib/registry')
-rw-r--r-- | source4/lib/registry/common/reg_interface.c | 10 | ||||
-rw-r--r-- | source4/lib/registry/reg_backend_dir.c | 17 | ||||
-rw-r--r-- | source4/lib/registry/reg_backend_gconf.c | 9 | ||||
-rw-r--r-- | source4/lib/registry/reg_backend_ldb.c | 30 | ||||
-rw-r--r-- | source4/lib/registry/reg_backend_rpc.c | 9 |
5 files changed, 41 insertions, 34 deletions
diff --git a/source4/lib/registry/common/reg_interface.c b/source4/lib/registry/common/reg_interface.c index a93fa31836..2382e4aa43 100644 --- a/source4/lib/registry/common/reg_interface.c +++ b/source4/lib/registry/common/reg_interface.c @@ -218,7 +218,6 @@ WERROR reg_open_key_abs(TALLOC_CTX *mem_ctx, struct registry_context *handle, co */ WERROR reg_open_key(TALLOC_CTX *mem_ctx, struct registry_key *parent, const char *name, struct registry_key **result) { - char *fullname; WERROR error; if(!parent) { @@ -257,15 +256,12 @@ WERROR reg_open_key(TALLOC_CTX *mem_ctx, struct registry_key *parent, const char return WERR_NOT_SUPPORTED; } - - fullname = ((parent->hive->root == parent)?talloc_strdup(mem_ctx, name):talloc_asprintf(mem_ctx, "%s\\%s", parent->path, name)); - - error = parent->hive->functions->open_key(mem_ctx, parent->hive, fullname, result); + error = parent->hive->functions->open_key(mem_ctx, parent, name, result); if(!W_ERROR_IS_OK(error)) return error; (*result)->hive = parent->hive; - (*result)->path = fullname; + (*result)->path = ((parent->hive->root == parent)?talloc_strdup(mem_ctx, name):talloc_asprintf(mem_ctx, "%s\\%s", parent->path, name)); (*result)->hive = parent->hive; return WERR_OK; @@ -369,7 +365,7 @@ WERROR reg_key_get_subkey_by_name(TALLOC_CTX *mem_ctx, struct registry_key *key, if(key->hive->functions->get_subkey_by_name) { error = key->hive->functions->get_subkey_by_name(mem_ctx, key,name,subkey); } else if(key->hive->functions->open_key) { - error = key->hive->functions->open_key(mem_ctx, key->hive, talloc_asprintf(mem_ctx, "%s\\%s", key->path, name), subkey); + error = key->hive->functions->open_key(mem_ctx, key, name, subkey); } else if(key->hive->functions->get_subkey_by_index) { for(i = 0; W_ERROR_IS_OK(error); i++) { error = reg_key_get_subkey_by_index(mem_ctx, key, i, subkey); diff --git a/source4/lib/registry/reg_backend_dir.c b/source4/lib/registry/reg_backend_dir.c index 5c3ed3c44c..c004be5a06 100644 --- a/source4/lib/registry/reg_backend_dir.c +++ b/source4/lib/registry/reg_backend_dir.c @@ -39,10 +39,10 @@ static WERROR reg_dir_del_key(struct registry_key *k) return (rmdir((char *)k->backend_data) == 0)?WERR_OK:WERR_GENERAL_FAILURE; } -static WERROR reg_dir_open_key(TALLOC_CTX *mem_ctx, struct registry_hive *h, const char *name, struct registry_key **subkey) +static WERROR reg_dir_open_key(TALLOC_CTX *mem_ctx, struct registry_key *p, const char *name, struct registry_key **subkey) { DIR *d; - char *fullpath; + char *fullpath, *unixpath; struct registry_key *ret; if(!name) { @@ -51,18 +51,19 @@ static WERROR reg_dir_open_key(TALLOC_CTX *mem_ctx, struct registry_hive *h, con } - fullpath = talloc_asprintf(mem_ctx, "%s%s", h->location, name); - fullpath = reg_path_win2unix(fullpath); + fullpath = talloc_asprintf(mem_ctx, "%s/%s", (char *)p->backend_data, name); + unixpath = reg_path_win2unix(fullpath); - d = opendir(fullpath); + d = opendir(unixpath); if(!d) { - DEBUG(3,("Unable to open '%s': %s\n", fullpath, strerror(errno))); + DEBUG(3,("Unable to open '%s': %s\n", unixpath, strerror(errno))); return WERR_BADFILE; } closedir(d); ret = talloc_p(mem_ctx, struct registry_key); - ret->hive = h; + ret->hive = p->hive; ret->path = fullpath; + ret->backend_data = unixpath; *subkey = ret; return WERR_OK; } @@ -89,7 +90,6 @@ static WERROR reg_dir_key_by_index(TALLOC_CTX *mem_ctx, struct registry_key *k, stat(thispath, &stbuf); if(S_ISDIR(stbuf.st_mode)) { - i++; if(i == idx) { (*key) = talloc_p(mem_ctx, struct registry_key); (*key)->name = e->d_name; @@ -99,6 +99,7 @@ static WERROR reg_dir_key_by_index(TALLOC_CTX *mem_ctx, struct registry_key *k, closedir(d); return WERR_OK; } + i++; } SAFE_FREE(thispath); diff --git a/source4/lib/registry/reg_backend_gconf.c b/source4/lib/registry/reg_backend_gconf.c index 2fed2417b7..b53d0fedf5 100644 --- a/source4/lib/registry/reg_backend_gconf.c +++ b/source4/lib/registry/reg_backend_gconf.c @@ -42,15 +42,18 @@ static WERROR reg_open_gconf_hive(struct registry_hive *h, struct registry_key * return WERR_OK; } -static WERROR gconf_open_key (TALLOC_CTX *mem_ctx, struct registry_hive *h, const char *name, struct registry_key **key) +static WERROR gconf_open_key (TALLOC_CTX *mem_ctx, struct registry_key *h, const char *name, struct registry_key **key) { struct registry_key *ret; char *fullpath; - fullpath = talloc_asprintf(mem_ctx, "/%s", reg_path_win2unix(talloc_strdup(mem_ctx, name))); + fullpath = talloc_asprintf(mem_ctx, "%s%s%s", + (char *)h->backend_data, + strlen((char *)h->backend_data) == 1?"":"/", + reg_path_win2unix(talloc_strdup(mem_ctx, name))); /* Check if key exists */ - if(!gconf_client_dir_exists((GConfClient *)h->backend_data, fullpath, NULL)) { + if(!gconf_client_dir_exists((GConfClient *)h->hive->backend_data, fullpath, NULL)) { return WERR_DEST_NOT_FOUND; } diff --git a/source4/lib/registry/reg_backend_ldb.c b/source4/lib/registry/reg_backend_ldb.c index e833299b7e..7804a68d3d 100644 --- a/source4/lib/registry/reg_backend_ldb.c +++ b/source4/lib/registry/reg_backend_ldb.c @@ -35,8 +35,15 @@ static int reg_close_ldb_key (void *data) struct ldb_key_data *kd = key->backend_data; struct ldb_context *c = key->hive->backend_data; - ldb_search_free(c, kd->subkeys); kd->subkeys = NULL; - ldb_search_free(c, kd->values); kd->values = NULL; + if (kd->subkeys) { + ldb_search_free(c, kd->subkeys); + kd->subkeys = NULL; + } + + if (kd->values) { + ldb_search_free(c, kd->values); + kd->values = NULL; + } return 0; } @@ -85,7 +92,7 @@ static WERROR ldb_get_subkey_by_id(TALLOC_CTX *mem_ctx, struct registry_key *k, /* Do a search if necessary */ if (kd->subkeys == NULL) { - kd->subkey_count = ldb_search(c, kd->dn, LDB_SCOPE_ONELEVEL, "(key=*)", NULL,&kd->subkeys); + kd->subkey_count = ldb_search(c, kd->dn, LDB_SCOPE_ONELEVEL, "(key=*)", NULL, &kd->subkeys); if(kd->subkey_count < 0) { DEBUG(0, ("Error getting subkeys for '%s': %s\n", kd->dn, ldb_errstring(c))); @@ -133,14 +140,17 @@ static WERROR ldb_get_value_by_id(TALLOC_CTX *mem_ctx, struct registry_key *k, i return WERR_OK; } -static WERROR ldb_open_key(TALLOC_CTX *mem_ctx, struct registry_hive *h, const char *name, struct registry_key **key) +static WERROR ldb_open_key(TALLOC_CTX *mem_ctx, struct registry_key *h, const char *name, struct registry_key **key) { - struct ldb_context *c = h->backend_data; + struct ldb_context *c = h->hive->backend_data; struct ldb_message **msg; char *ldap_path; int ret; - struct ldb_key_data *newkd; - ldap_path = reg_path_to_ldb(mem_ctx, name, NULL); + struct ldb_key_data *kd = h->backend_data, *newkd; + ldap_path = talloc_asprintf(mem_ctx, "%s%s%s", + reg_path_to_ldb(mem_ctx, name, NULL), + kd->dn?",":"", + kd->dn?kd->dn:""); ret = ldb_search(c, ldap_path, LDB_SCOPE_BASE, "(key=*)", NULL,&msg); @@ -153,7 +163,7 @@ static WERROR ldb_open_key(TALLOC_CTX *mem_ctx, struct registry_hive *h, const c *key = talloc_p(mem_ctx, struct registry_key); talloc_set_destructor(*key, reg_close_ldb_key); - (*key)->name = talloc_strdup(mem_ctx, strrchr(name, '\\')); + (*key)->name = talloc_strdup(mem_ctx, strrchr(name, '\\')?strchr(name, '\\'):name); (*key)->backend_data = newkd = talloc_zero_p(*key, struct ldb_key_data); newkd->dn = talloc_strdup(mem_ctx, msg[0]->dn); @@ -165,6 +175,7 @@ static WERROR ldb_open_key(TALLOC_CTX *mem_ctx, struct registry_hive *h, const c static WERROR ldb_open_hive(struct registry_hive *hive, struct registry_key **k) { struct ldb_context *c; + struct ldb_key_data *kd; if (!hive->location) return WERR_INVALID_PARAM; c = ldb_connect(hive->location, 0, NULL); @@ -179,7 +190,8 @@ static WERROR ldb_open_hive(struct registry_hive *hive, struct registry_key **k) hive->root = talloc_zero_p(hive, struct registry_key); talloc_set_destructor (hive->root, reg_close_ldb_key); hive->root->name = talloc_strdup(hive->root, ""); - hive->root->backend_data = talloc_zero_p(hive->root, struct ldb_key_data); + hive->root->backend_data = kd = talloc_zero_p(hive->root, struct ldb_key_data); + kd->dn = talloc_strdup(hive->root, "key=root"); return WERR_OK; diff --git a/source4/lib/registry/reg_backend_rpc.c b/source4/lib/registry/reg_backend_rpc.c index 18563b2478..927ed7fcaa 100644 --- a/source4/lib/registry/reg_backend_rpc.c +++ b/source4/lib/registry/reg_backend_rpc.c @@ -155,7 +155,7 @@ static WERROR rpc_key_put_rpc_data(TALLOC_CTX *mem_ctx, struct registry_key *k) } #endif -static WERROR rpc_open_rel_key(TALLOC_CTX *mem_ctx, struct registry_key *h, const char *name, struct registry_key **key) +static WERROR rpc_open_key(TALLOC_CTX *mem_ctx, struct registry_key *h, const char *name, struct registry_key **key) { struct rpc_key_data *mykeydata; struct winreg_OpenKey r; @@ -181,11 +181,6 @@ static WERROR rpc_open_rel_key(TALLOC_CTX *mem_ctx, struct registry_key *h, cons return r.out.result; } -static WERROR rpc_open_key(TALLOC_CTX *mem_ctx, struct registry_hive *h, const char *name, struct registry_key **key) -{ - return rpc_open_rel_key(mem_ctx, h->root, name, key); -} - static WERROR rpc_get_value_by_index(TALLOC_CTX *mem_ctx, struct registry_key *parent, int n, struct registry_value **value) { struct rpc_key_data *mykeydata = parent->backend_data; @@ -258,7 +253,7 @@ static WERROR rpc_get_subkey_by_index(TALLOC_CTX *mem_ctx, struct registry_key * r.in.key_name_len = r.out.key_name_len = 0; status = dcerpc_winreg_EnumKey((struct dcerpc_pipe *)parent->hive->backend_data, mem_ctx, &r); if(NT_STATUS_IS_OK(status) && W_ERROR_IS_OK(r.out.result)) { - return rpc_open_rel_key(mem_ctx, parent, talloc_strdup(mem_ctx, r.out.out_name->name), subkey); + return rpc_open_key(mem_ctx, parent, talloc_strdup(mem_ctx, r.out.out_name->name), subkey); } return r.out.result; |