diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2004-09-22 12:32:31 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 12:59:01 -0500 |
commit | 369a5d64e462e084e6c5fe4984d56da18b2c92d9 (patch) | |
tree | 815e7a10696ef40205c1e16c4e01b660a7a8f0b7 /source4/lib/registry/reg_backend_gconf | |
parent | bc8ef3d1b6bfdf279d65783869b9a247c1da38aa (diff) | |
download | samba-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_gconf')
-rw-r--r-- | source4/lib/registry/reg_backend_gconf/reg_backend_gconf.c | 201 |
1 files changed, 91 insertions, 110 deletions
diff --git a/source4/lib/registry/reg_backend_gconf/reg_backend_gconf.c b/source4/lib/registry/reg_backend_gconf/reg_backend_gconf.c index 15a8319711..d8c8d951c1 100644 --- a/source4/lib/registry/reg_backend_gconf/reg_backend_gconf.c +++ b/source4/lib/registry/reg_backend_gconf/reg_backend_gconf.c @@ -19,7 +19,6 @@ */ #include "includes.h" -#include "lib/registry/common/registry.h" #include <gconf/gconf-client.h> static WERROR gerror_to_werror(GError *error) @@ -29,33 +28,24 @@ static WERROR gerror_to_werror(GError *error) return WERR_FOOBAR; } -static WERROR reg_open_gconf(REG_HANDLE *h, const char *location, const char *credentials) +static WERROR reg_open_gconf_hive(TALLOC_CTX *mem_ctx, struct registry_hive *h, struct registry_key **k) { + g_type_init(); h->backend_data = (void *)gconf_client_get_default(); if(!h->backend_data) return WERR_FOOBAR; + + *k = talloc_p(mem_ctx, struct registry_key); + (*k)->name = ""; + (*k)->path = ""; + (*k)->backend_data = talloc_strdup(mem_ctx, "/"); return WERR_OK; } -static WERROR reg_close_gconf(REG_HANDLE *h) -{ - return WERR_OK; -} - -static WERROR gconf_get_hive (REG_HANDLE *h, int hivenum, REG_KEY **key) -{ - if(hivenum != 0) return WERR_NO_MORE_ITEMS; - *key = reg_key_new_abs("", h, NULL); - (*key)->backend_data = talloc_strdup((*key)->mem_ctx, "/"); - return WERR_OK; -} - -static WERROR gconf_open_key (REG_HANDLE *h, int hivenum, const char *name, REG_KEY **key) +static WERROR gconf_open_key (TALLOC_CTX *mem_ctx, struct registry_hive *h, const char *name, struct registry_key **key) { - REG_KEY *ret; + struct registry_key *ret; char *fullpath; - if(hivenum != 0) return WERR_NO_MORE_ITEMS; - fullpath = reg_path_win2unix(strdup(name)); /* Check if key exists */ @@ -63,143 +53,134 @@ static WERROR gconf_open_key (REG_HANDLE *h, int hivenum, const char *name, REG_ SAFE_FREE(fullpath); return WERR_DEST_NOT_FOUND; } - ret = reg_key_new_abs(name, h, NULL); - ret->backend_data = talloc_strdup(ret->mem_ctx, fullpath); + + ret = talloc_p(mem_ctx, struct registry_key); + ret->backend_data = talloc_strdup(mem_ctx, fullpath); SAFE_FREE(fullpath); *key = ret; return WERR_OK; } -static WERROR gconf_fetch_values(REG_KEY *p, int *count, REG_VAL ***vals) +static WERROR gconf_get_value_by_id(TALLOC_CTX *mem_ctx, struct registry_key *p, int idx, struct registry_value **val) { GSList *entries; GSList *cur; - REG_VAL **ar = talloc(p->mem_ctx, sizeof(REG_VAL *)); + GConfEntry *entry; + GConfValue *value; + struct registry_value *newval; char *fullpath = p->backend_data; - cur = entries = gconf_client_all_entries((GConfClient*)p->handle->backend_data, fullpath, NULL); - - (*count) = 0; - while(cur) { - GConfEntry *entry = cur->data; - GConfValue *value = gconf_entry_get_value(entry); - REG_VAL *newval = reg_val_new(p, NULL); - newval->name = talloc_strdup(newval->mem_ctx, strrchr(gconf_entry_get_key(entry), '/')+1); - if(value) { - switch(value->type) { - case GCONF_VALUE_INVALID: - newval->data_type = REG_NONE; - break; - - case GCONF_VALUE_STRING: - newval->data_type = REG_SZ; - newval->data_blk = talloc_strdup(newval->mem_ctx, gconf_value_get_string(value)); - newval->data_len = strlen(newval->data_blk); - break; - - case GCONF_VALUE_INT: - newval->data_type = REG_DWORD; - newval->data_blk = talloc(newval->mem_ctx, sizeof(long)); - *((long *)newval->data_blk) = gconf_value_get_int(value); - newval->data_len = sizeof(long); - break; - - case GCONF_VALUE_FLOAT: - newval->data_blk = talloc(newval->mem_ctx, sizeof(double)); - newval->data_type = REG_BINARY; - *((double *)newval->data_blk) = gconf_value_get_float(value); - newval->data_len = sizeof(double); - break; - - case GCONF_VALUE_BOOL: - newval->data_blk = talloc(newval->mem_ctx, sizeof(BOOL)); - newval->data_type = REG_BINARY; - *((BOOL *)newval->data_blk) = gconf_value_get_bool(value); - newval->data_len = sizeof(BOOL); - break; - - default: - newval->data_type = REG_NONE; - DEBUG(0, ("Not implemented..\n")); - break; - } - } else newval->data_type = REG_NONE; - - ar[(*count)] = newval; - ar = talloc_realloc(ar, sizeof(REG_VAL *) * ((*count)+2)); - (*count)++; - g_free(cur->data); - cur = cur->next; - } + int i; + cur = entries = gconf_client_all_entries((GConfClient*)p->hive->backend_data, fullpath, NULL); + + for(i = 0; i < idx && cur; i++) cur = cur->next; + + if(!cur) return WERR_NO_MORE_ITEMS; + + entry = cur->data; + value = gconf_entry_get_value(entry); + + newval = talloc_p(mem_ctx, struct registry_value); + newval->name = talloc_strdup(mem_ctx, strrchr(gconf_entry_get_key(entry), '/')+1); + if(value) { + switch(value->type) { + case GCONF_VALUE_INVALID: + newval->data_type = REG_NONE; + break; + + case GCONF_VALUE_STRING: + newval->data_type = REG_SZ; + newval->data_blk = talloc_strdup(mem_ctx, gconf_value_get_string(value)); + newval->data_len = strlen(newval->data_blk); + break; + + case GCONF_VALUE_INT: + newval->data_type = REG_DWORD; + newval->data_blk = talloc_p(mem_ctx, long); + *((long *)newval->data_blk) = gconf_value_get_int(value); + newval->data_len = sizeof(long); + break; + + case GCONF_VALUE_FLOAT: + newval->data_blk = talloc_p(mem_ctx, double); + newval->data_type = REG_BINARY; + *((double *)newval->data_blk) = gconf_value_get_float(value); + newval->data_len = sizeof(double); + break; + + case GCONF_VALUE_BOOL: + newval->data_blk = talloc_p(mem_ctx, BOOL); + newval->data_type = REG_BINARY; + *((BOOL *)newval->data_blk) = gconf_value_get_bool(value); + newval->data_len = sizeof(BOOL); + break; + + default: + newval->data_type = REG_NONE; + DEBUG(0, ("Not implemented..\n")); + break; + } + } else newval->data_type = REG_NONE; g_slist_free(entries); - *vals = ar; + *val = newval; return WERR_OK; } -static WERROR gconf_fetch_subkeys(REG_KEY *p, int *count, REG_KEY ***subs) +static WERROR gconf_get_subkey_by_id(TALLOC_CTX *mem_ctx, struct registry_key *p, int idx, struct registry_key **sub) { GSList *dirs; GSList *cur; - REG_KEY **ar = talloc_array_p(p->mem_ctx, REG_KEY *, 1); + int i; char *fullpath = p->backend_data; - cur = dirs = gconf_client_all_dirs((GConfClient*)p->handle->backend_data, fullpath,NULL); - - (*count) = 0; - while(cur) { - char *winpath = reg_path_unix2win(strdup((char *)cur->data)); - ar[(*count)] = reg_key_new_abs(winpath, p->handle,NULL); - free(winpath); - ar[(*count)]->backend_data = reg_path_win2unix(talloc_strdup(ar[*count]->mem_ctx, cur->data)); - ar = talloc_realloc_p(ar, REG_KEY *, (*count)+2); - (*count)++; - g_free(cur->data); - cur = cur->next; - } + cur = dirs = gconf_client_all_dirs((GConfClient*)p->hive->backend_data, fullpath,NULL); + + for(i = 0; i < idx && cur; i++) cur = cur->next; + + if(!cur) return WERR_NO_MORE_ITEMS; + + *sub = talloc_p(mem_ctx, struct registry_key); + (*sub)->name = talloc_strdup(mem_ctx, strrchr((char *)cur->data, '/')+1); + (*sub)->backend_data = talloc_strdup(mem_ctx, cur->data); g_slist_free(dirs); - *subs = ar; return WERR_OK; } -static WERROR gconf_update_value(REG_VAL *val, int type, void *data, int len) +static WERROR gconf_set_value(struct registry_key *key, const char *valname, int type, void *data, int len) { GError *error = NULL; - char *keypath = val->backend_data; char *valpath; - if(val->name)asprintf(&valpath, "%s/%s", keypath, val->name); - else valpath = strdup(keypath); + asprintf(&valpath, "%s/%s", key->path, valname); switch(type) { case REG_SZ: case REG_EXPAND_SZ: - gconf_client_set_string((GConfClient *)val->handle->backend_data, valpath, data, &error); - free(valpath); + gconf_client_set_string((GConfClient *)key->hive->backend_data, valpath, data, &error); + SAFE_FREE(valpath); return gerror_to_werror(error); case REG_DWORD: - gconf_client_set_int((GConfClient *)val->handle->backend_data, valpath, + gconf_client_set_int((GConfClient *)key->hive->backend_data, valpath, *((int *)data), &error); - free(valpath); + SAFE_FREE(valpath); return gerror_to_werror(error); default: DEBUG(0, ("Unsupported type: %d\n", type)); - free(valpath); + SAFE_FREE(valpath); return WERR_NOT_SUPPORTED; } return WERR_NOT_SUPPORTED; } -static struct registry_ops reg_backend_gconf = { +static struct registry_operations reg_backend_gconf = { .name = "gconf", - .open_registry = reg_open_gconf, - .close_registry = reg_close_gconf, - .get_hive = gconf_get_hive, + .open_hive = reg_open_gconf_hive, .open_key = gconf_open_key, - .fetch_subkeys = gconf_fetch_subkeys, - .fetch_values = gconf_fetch_values, - .update_value = gconf_update_value, + .get_subkey_by_index = gconf_get_subkey_by_id, + .get_value_by_index = gconf_get_value_by_id, + .set_value = gconf_set_value, /* Note: * since GConf uses schemas for what keys and values are allowed, there |