diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2004-10-11 00:29:55 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 12:59:45 -0500 |
commit | e2a47719097291dac9e2ff33fbb1d1b26f26517c (patch) | |
tree | feaf896f3c92d3a45b66e4ce6a9380c5cf06a49a /source4 | |
parent | ffa0cf3af05c82df558bb2484e04a8f2220f6ea0 (diff) | |
download | samba-e2a47719097291dac9e2ff33fbb1d1b26f26517c.tar.gz samba-e2a47719097291dac9e2ff33fbb1d1b26f26517c.tar.bz2 samba-e2a47719097291dac9e2ff33fbb1d1b26f26517c.zip |
r2898: - Support enumerating remote registry values
- Some LDB updates
(This used to be commit 4b5bf739f5a8f39ff3633d738f6de42681a6b30f)
Diffstat (limited to 'source4')
-rw-r--r-- | source4/lib/registry/reg_backend_ldb/reg_backend_ldb.c | 80 | ||||
-rw-r--r-- | source4/lib/registry/reg_backend_rpc/reg_backend_rpc.c | 63 |
2 files changed, 67 insertions, 76 deletions
diff --git a/source4/lib/registry/reg_backend_ldb/reg_backend_ldb.c b/source4/lib/registry/reg_backend_ldb/reg_backend_ldb.c index e0f65f2c37..cc0432d9ea 100644 --- a/source4/lib/registry/reg_backend_ldb/reg_backend_ldb.c +++ b/source4/lib/registry/reg_backend_ldb/reg_backend_ldb.c @@ -40,7 +40,7 @@ static char *reg_path_to_ldb(TALLOC_CTX *mem_ctx, const char *path, const char * ret = talloc_asprintf_append(ret, "key=%s,", keyname); if(begin) { - begin[0] = '\0'; + *begin = '\0'; end = begin-1; } else { end = NULL; @@ -50,6 +50,10 @@ static char *reg_path_to_ldb(TALLOC_CTX *mem_ctx, const char *path, const char * SAFE_FREE(mypath); ret[strlen(ret)-1] = '\0'; + + printf("RETURNING: %s\n", ret); + + if(strlen(ret) == 0) return NULL; return ret; } @@ -62,40 +66,19 @@ static int ldb_close_registry(void *data) } -/* - * Saves the dn as private_data for every key/val - */ - -static WERROR ldb_open_hive(TALLOC_CTX *mem_ctx, struct registry_hive *hive, struct registry_key **k) -{ - struct ldb_context *c; - - if (!hive->location) return WERR_INVALID_PARAM; - c = ldb_connect(hive->location, 0, NULL); - - ldb_set_debug_stderr(c); - - - if(!c) return WERR_FOOBAR; - hive->backend_data = c; - talloc_set_destructor(c, ldb_close_registry); - - return WERR_OK; -} static WERROR ldb_add_key(TALLOC_CTX *mem_ctx, struct registry_key *p, const char *name, uint32_t access_mask, SEC_DESC *sec, struct registry_key **new) { return WERR_NOT_SUPPORTED; } -#if 0 -FIXME -static WERROR ldb_fetch_subkeys(struct registry_key *k, int *count, struct registry_key ***subkeys) +static WERROR ldb_get_subkey_by_id(TALLOC_CTX *mem_ctx, struct registry_key *k, int idx, struct registry_key **subkey) { struct ldb_context *c = k->hive->backend_data; - int ret, i, j; + int ret; struct ldb_message **msg; + struct ldb_message_element *el; ret = ldb_search(c, (char *)k->backend_data, LDB_SCOPE_ONELEVEL, "(key=*)", NULL,&msg); @@ -104,27 +87,19 @@ static WERROR ldb_fetch_subkeys(struct registry_key *k, int *count, struct regis return WERR_FOOBAR; } - *subkeys = talloc_array_p(k->mem_ctx, struct registry_key *, ret); - j = 0; - for(i = 0; i < ret; i++) { - struct ldb_message_element *el; - char *name; - el = ldb_msg_find_element(msg[i], "key"); - - name = el->values[0].data; - - /* Dirty hack to circumvent ldb_tdb bug */ - if(k->backend_data && !strcmp(msg[i]->dn, (char *)k->backend_data)) continue; - - (*subkeys)[j] = reg_key_new_rel(name, k, NULL); - (*subkeys)[j]->backend_data = talloc_strdup((*subkeys)[j]->mem_ctx, msg[i]->dn); - j++; - } - *count = j; + if(idx >= ret) return WERR_NO_MORE_ITEMS; + + el = ldb_msg_find_element(msg[idx], "key"); + + *subkey = talloc_p(mem_ctx, struct registry_key); + (*subkey)->name = talloc_strdup(mem_ctx, el->values[0].data); + (*subkey)->backend_data = talloc_strdup(mem_ctx, msg[idx]->dn); + printf("Retrieved: %s\n", (*subkey)->backend_data); ldb_search_free(c, msg); return WERR_OK; } +#if 0 static WERROR ldb_fetch_values(struct registry_key *k, int *count, REG_VAL ***values) { @@ -171,7 +146,7 @@ static WERROR ldb_open_key(TALLOC_CTX *mem_ctx, struct registry_hive *h, const c int ret; ldap_path = reg_path_to_ldb(mem_ctx, name, NULL); - ret = ldb_search(c, ldap_path, LDB_SCOPE_BASE, "*", NULL,&msg); + ret = ldb_search(c, ldap_path, LDB_SCOPE_BASE, "(key=*)", NULL,&msg); if(ret == 0) { return WERR_NO_MORE_ITEMS; @@ -181,19 +156,36 @@ static WERROR ldb_open_key(TALLOC_CTX *mem_ctx, struct registry_hive *h, const c } *key = talloc_p(mem_ctx, struct registry_key); - /* FIXME */ + (*key)->name = talloc_strdup(mem_ctx, strrchr(name, '\\')); + (*key)->backend_data = talloc_strdup(mem_ctx, msg[0]->dn); + printf("Retrieved: %s\n", (*key)->backend_data); ldb_search_free(c, msg); return WERR_OK; } +static WERROR ldb_open_hive(TALLOC_CTX *mem_ctx, struct registry_hive *hive, struct registry_key **k) +{ + struct ldb_context *c; + + if (!hive->location) return WERR_INVALID_PARAM; + c = ldb_connect(hive->location, 0, NULL); + + if(!c) return WERR_FOOBAR; + ldb_set_debug_stderr(c); + hive->backend_data = c; + + return ldb_open_key(mem_ctx, hive, "", k); +} + static struct registry_operations reg_backend_ldb = { .name = "ldb", .open_hive = ldb_open_hive, .open_key = ldb_open_key, /* .fetch_subkeys = ldb_fetch_subkeys, .fetch_values = ldb_fetch_values,*/ + .get_subkey_by_index = ldb_get_subkey_by_id, .add_key = ldb_add_key, }; diff --git a/source4/lib/registry/reg_backend_rpc/reg_backend_rpc.c b/source4/lib/registry/reg_backend_rpc/reg_backend_rpc.c index 3dd73162be..db1ab9364e 100644 --- a/source4/lib/registry/reg_backend_rpc/reg_backend_rpc.c +++ b/source4/lib/registry/reg_backend_rpc/reg_backend_rpc.c @@ -198,55 +198,54 @@ static WERROR rpc_open_key(TALLOC_CTX *mem_ctx, struct registry_hive *h, const c 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; - uint32_t requested_len = 0; WERROR error; - + struct winreg_EnumValue r; + uint32 type, len1, len2 = 0; + struct EnumValueIn buf_name, buf_val; + NTSTATUS status; + if(mykeydata->num_values == -1) { error = rpc_query_key(parent); if(!W_ERROR_IS_OK(error)) return error; } - requested_len = mykeydata->max_valdatalen; - -#if 0 /* EnumValue is not working yet ... */ + len1 = mykeydata->max_valdatalen; + r.in.handle = &mykeydata->pol; r.in.enum_index = n; - r.in.type = r.out.type = &type; - r.in.requested_len = r.out.requested_len = &requested_len; - r.in.returned_len = r.out.returned_len = &returned_len; - vn.max_len = mykeydata->max_valnamelen * 2; - vn.len = 0; - vn.buf = NULL; - if(vn.max_len > 0) { - vn.len = 0; - vn.max_len = mykeydata->max_valnamelen*2; - /* FIXME: we should not point a 'char *' to a const buffer!!! --metze*/ - vn.buf = ""; - } - r.in.name = r.out.name = &vn; - vb.max_len = mykeydata->max_valdatalen; - vb.offset = 0x0; - vb.len = 0x0; - vb.buffer = talloc_array_p(mem_ctx, uint8, mykeydata->max_valdatalen); - r.in.value = r.out.value = &vb; - - status = dcerpc_winreg_EnumValue((struct dcerpc_pipe *)parent->handle->backend_data, parent->mem_ctx, &r); + r.in.name_in.len = 0; + r.in.name_in.max_len = mykeydata->max_valnamelen * 2; + buf_name.max_len = mykeydata->max_valnamelen; + buf_name.offset = 0; + buf_name.len = 0; + r.in.name_in.buffer = &buf_name; + r.in.type = &type; + buf_val.max_len = mykeydata->max_valdatalen; + buf_val.offset = 0; + buf_val.len = 0; + r.in.value_in = &buf_val; + r.in.value_len1 = &len1; + r.in.value_len2 = &len2; + + + status = dcerpc_winreg_EnumValue((struct dcerpc_pipe *)parent->hive->backend_data, mem_ctx, &r); if(NT_STATUS_IS_ERR(status)) { DEBUG(0, ("Error in EnumValue: %s\n", nt_errstr(status))); + return WERR_GENERAL_FAILURE; } if(NT_STATUS_IS_OK(status) && W_ERROR_IS_OK(r.out.result)) { - *value = reg_val_new(parent, NULL); - (*value)->name = r.out.name->buf; + *value = talloc_p(mem_ctx, struct registry_value); + (*value)->parent = parent; + (*value)->name = talloc_strdup(mem_ctx, r.out.name_out.name); + printf("Type: %d\n", type); (*value)->data_type = type; - (*value)->data_len = r.out.value->len; - (*value)->data_blk = r.out.value->buffer; - exit(1); + (*value)->data_len = r.out.value_out->buffer.length; + (*value)->data_blk = talloc_memdup(mem_ctx, r.out.value_out->buffer.data, r.out.value_out->buffer.length); return WERR_OK; } -#endif - return WERR_NOT_SUPPORTED; + return r.out.result; } static WERROR rpc_get_subkey_by_index(TALLOC_CTX *mem_ctx, struct registry_key *parent, int n, struct registry_key **subkey) |