summaryrefslogtreecommitdiff
path: root/source4/lib/registry/reg_backend_dir
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2004-09-22 12:32:31 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:59:01 -0500
commit369a5d64e462e084e6c5fe4984d56da18b2c92d9 (patch)
tree815e7a10696ef40205c1e16c4e01b660a7a8f0b7 /source4/lib/registry/reg_backend_dir
parentbc8ef3d1b6bfdf279d65783869b9a247c1da38aa (diff)
downloadsamba-369a5d64e462e084e6c5fe4984d56da18b2c92d9.tar.gz
samba-369a5d64e462e084e6c5fe4984d56da18b2c92d9.tar.bz2
samba-369a5d64e462e084e6c5fe4984d56da18b2c92d9.zip
r2518: Some long overdue changes:
- Samba4-style code in lib/registry (struct registry_key instead of REG_KEY, etc) - Use hives (like Windows has drives) instead of one root key (like a Unix FS) - usability fixes in the GTK utilities (autodetect the username, enable/disable options, etc) - fix gwsam compile - several bugfixes in the registry rpc code - do charset conversion in nt4 registry backend (This used to be commit 2762ed3b9bf1d67dd54d63e02cddbfd71ea89892)
Diffstat (limited to 'source4/lib/registry/reg_backend_dir')
-rw-r--r--source4/lib/registry/reg_backend_dir/reg_backend_dir.c77
1 files changed, 32 insertions, 45 deletions
diff --git a/source4/lib/registry/reg_backend_dir/reg_backend_dir.c b/source4/lib/registry/reg_backend_dir/reg_backend_dir.c
index b2bd34bf71..95d4c47af0 100644
--- a/source4/lib/registry/reg_backend_dir/reg_backend_dir.c
+++ b/source4/lib/registry/reg_backend_dir/reg_backend_dir.c
@@ -19,13 +19,12 @@
*/
#include "includes.h"
-#include "lib/registry/common/registry.h"
-static WERROR reg_dir_add_key(REG_KEY *parent, const char *name, uint32_t access_mask, SEC_DESC *desc, REG_KEY **result)
+static WERROR reg_dir_add_key(TALLOC_CTX *mem_ctx, struct registry_key *parent, const char *name, uint32_t access_mask, SEC_DESC *desc, struct registry_key **result)
{
char *path;
int ret;
- asprintf(&path, "%s%s\\%s", parent->handle->location, reg_key_get_path(parent), name);
+ asprintf(&path, "%s%s\\%s", parent->hive->location, parent->path, name);
path = reg_path_win2unix(path);
ret = mkdir(path, 0700);
SAFE_FREE(path);
@@ -33,19 +32,16 @@ static WERROR reg_dir_add_key(REG_KEY *parent, const char *name, uint32_t access
return WERR_INVALID_PARAM;
}
-static WERROR reg_dir_del_key(REG_KEY *k)
+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(REG_HANDLE *h, int hive, const char *name, REG_KEY **subkey)
+static WERROR reg_dir_open_key(TALLOC_CTX *mem_ctx, struct registry_hive *h, const char *name, struct registry_key **subkey)
{
DIR *d;
char *fullpath;
- REG_KEY *ret;
- TALLOC_CTX *mem_ctx;
-
- if(hive != 0) return WERR_NO_MORE_ITEMS;
+ struct registry_key *ret;
if(!name) {
DEBUG(0, ("NULL pointer passed as directory name!"));
@@ -53,33 +49,28 @@ static WERROR reg_dir_open_key(REG_HANDLE *h, int hive, const char *name, REG_KE
}
- mem_ctx = talloc_init("tmp");
fullpath = talloc_asprintf(mem_ctx, "%s%s", h->location, name);
fullpath = reg_path_win2unix(fullpath);
d = opendir(fullpath);
if(!d) {
DEBUG(3,("Unable to open '%s': %s\n", fullpath, strerror(errno)));
- talloc_destroy(mem_ctx);
return WERR_BADFILE;
}
closedir(d);
- ret = reg_key_new_abs(name, h, fullpath);
- talloc_steal(ret->mem_ctx, fullpath);
- talloc_destroy(mem_ctx);
+ ret = talloc_p(mem_ctx, struct registry_key);
+ ret->hive = h;
+ ret->path = fullpath;
*subkey = ret;
return WERR_OK;
}
-static WERROR reg_dir_fetch_subkeys(REG_KEY *k, int *count, REG_KEY ***r)
+static WERROR reg_dir_key_by_index(TALLOC_CTX *mem_ctx, struct registry_key *k, int idx, struct registry_key **key)
{
struct dirent *e;
- int max = 200;
char *fullpath = k->backend_data;
- REG_KEY **ar;
+ int i = 0;
DIR *d;
- (*count) = 0;
- ar = talloc(k->mem_ctx, sizeof(REG_KEY *) * max);
d = opendir(fullpath);
@@ -96,13 +87,15 @@ static WERROR reg_dir_fetch_subkeys(REG_KEY *k, int *count, REG_KEY ***r)
stat(thispath, &stbuf);
if(S_ISDIR(stbuf.st_mode)) {
- ar[(*count)] = reg_key_new_rel(e->d_name, k, NULL);
- ar[(*count)]->backend_data = talloc_strdup(ar[*count]->mem_ctx, thispath);
- if(ar[(*count)])(*count)++;
-
- if((*count) == max) {
- max+=200;
- ar = realloc(ar, sizeof(REG_KEY *) * max);
+ i++;
+ if(i == idx) {
+ (*key) = talloc_p(mem_ctx, struct registry_key);
+ (*key)->name = e->d_name;
+ (*key)->path = NULL;
+ (*key)->backend_data = talloc_strdup(mem_ctx, thispath);
+ SAFE_FREE(thispath);
+ closedir(d);
+ return WERR_OK;
}
}
@@ -112,44 +105,38 @@ static WERROR reg_dir_fetch_subkeys(REG_KEY *k, int *count, REG_KEY ***r)
closedir(d);
- *r = ar;
- return WERR_OK;
+ return WERR_NO_MORE_ITEMS;
}
-static WERROR reg_dir_open(REG_HANDLE *h, const char *loc, const char *credentials) {
- if(!loc) return WERR_INVALID_PARAM;
+static WERROR reg_dir_open(TALLOC_CTX *mem_ctx, struct registry_hive *h, struct registry_key **key)
+{
+ if(!h->location) return WERR_INVALID_PARAM;
+
+ *key = talloc_p(mem_ctx, struct registry_key);
+ (*key)->backend_data = talloc_strdup(mem_ctx, h->location);
return WERR_OK;
}
-static WERROR reg_dir_add_value(REG_KEY *p, const char *name, int type, void *data, int len)
+static WERROR reg_dir_set_value(struct registry_key *p, const char *name, int type, void *data, int len)
{
/* FIXME */
return WERR_NOT_SUPPORTED;
}
-static WERROR reg_dir_get_hive(REG_HANDLE *h, int hive, REG_KEY **key)
-{
- if(hive != 0) return WERR_NO_MORE_ITEMS;
- *key = reg_key_new_abs("", h, NULL);
- (*key)->backend_data = talloc_strdup((*key)->mem_ctx, h->location);
- return WERR_OK;
-}
-
-static WERROR reg_dir_del_value(REG_VAL *v)
+static WERROR reg_dir_del_value(struct registry_value *v)
{
/* FIXME*/
return WERR_NOT_SUPPORTED;
}
-static struct registry_ops reg_backend_dir = {
+static struct registry_operations reg_backend_dir = {
.name = "dir",
- .open_registry = reg_dir_open,
+ .open_hive = reg_dir_open,
.open_key = reg_dir_open_key,
- .get_hive = reg_dir_get_hive,
- .fetch_subkeys = reg_dir_fetch_subkeys,
.add_key = reg_dir_add_key,
.del_key = reg_dir_del_key,
- .add_value = reg_dir_add_value,
+ .get_subkey_by_index = reg_dir_key_by_index,
+ .set_value = reg_dir_set_value,
.del_value = reg_dir_del_value,
};