summaryrefslogtreecommitdiff
path: root/source4/lib/registry/common
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2004-12-14 20:49:18 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:07:26 -0500
commit1a340869c43f9ce741e8a4bd28ea01ec63301df5 (patch)
treecd005ea4f160b42c8c38b7a9112b87c93ee0ced3 /source4/lib/registry/common
parent75f02f9d4daf4a16b408ce145f841f11d4b0ca67 (diff)
downloadsamba-1a340869c43f9ce741e8a4bd28ea01ec63301df5.tar.gz
samba-1a340869c43f9ce741e8a4bd28ea01ec63301df5.tar.bz2
samba-1a340869c43f9ce741e8a4bd28ea01ec63301df5.zip
r4204: Arguments to reg_del_key more like the RPC for more efficient usage
Fix small bug in regpatch Fix segfault in regshell cmdline completion Implement set_value and del_value in ldb backend (This used to be commit 8e2aa58abeafa78afe7dafb9723f5f365e756527)
Diffstat (limited to 'source4/lib/registry/common')
-rw-r--r--source4/lib/registry/common/reg_interface.c155
-rw-r--r--source4/lib/registry/common/reg_util.c87
2 files changed, 92 insertions, 150 deletions
diff --git a/source4/lib/registry/common/reg_interface.c b/source4/lib/registry/common/reg_interface.c
index 79bb0b765c..c729945a26 100644
--- a/source4/lib/registry/common/reg_interface.c
+++ b/source4/lib/registry/common/reg_interface.c
@@ -192,28 +192,6 @@ WERROR reg_open_hive(TALLOC_CTX *parent_ctx, const char *backend, const char *lo
return WERR_OK;
}
-/* Open a key by name (including the predefined key name!) */
-WERROR reg_open_key_abs(TALLOC_CTX *mem_ctx, struct registry_context *handle, const char *name, struct registry_key **result)
-{
- struct registry_key *predef;
- WERROR error;
- int predeflength;
- char *predefname;
-
- if(strchr(name, '\\')) predeflength = strchr(name, '\\')-name;
- else predeflength = strlen(name);
-
- predefname = strndup(name, predeflength);
- error = reg_get_predefined_key_by_name(handle, predefname, &predef);
- SAFE_FREE(predefname);
-
- if(!W_ERROR_IS_OK(error)) {
- return error;
- }
-
- return reg_open_key(mem_ctx, predef, name, result);
-}
-
/* 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
@@ -409,123 +387,21 @@ WERROR reg_key_get_value_by_name(TALLOC_CTX *mem_ctx, struct registry_key *key,
return WERR_OK;
}
-WERROR reg_key_del(struct registry_key *key)
+WERROR reg_key_del(struct registry_key *parent, const char *name)
{
WERROR error;
- if(!key) return WERR_INVALID_PARAM;
+ if(!parent) return WERR_INVALID_PARAM;
- if(!key->hive->functions->del_key)
+ if(!parent->hive->functions->del_key)
return WERR_NOT_SUPPORTED;
- error = key->hive->functions->del_key(key);
+ error = parent->hive->functions->del_key(parent, name);
if(!W_ERROR_IS_OK(error)) return error;
return WERR_OK;
}
-WERROR reg_key_del_recursive(struct registry_key *key)
-{
- WERROR error = WERR_OK;
- int i;
-
- TALLOC_CTX *mem_ctx = talloc_init("del_recursive");
-
- /* Delete all values for specified key */
- for(i = 0; W_ERROR_IS_OK(error); i++) {
- struct registry_value *val;
- error = reg_key_get_value_by_index(mem_ctx, key, i, &val);
- if(!W_ERROR_IS_OK(error) && !W_ERROR_EQUAL(error, WERR_NO_MORE_ITEMS))
- {
- talloc_destroy(mem_ctx);
- return error;
- }
-
- if(W_ERROR_IS_OK(error)) {
- error = reg_del_value(key, val->name);
- if(!W_ERROR_IS_OK(error)) {
- talloc_destroy(mem_ctx);
- return error;
- }
- }
- }
-
- error = WERR_OK;
-
- /* Delete all keys below this one */
- for(i = 0; W_ERROR_IS_OK(error); i++) {
- struct registry_key *subkey;
-
- error = reg_key_get_subkey_by_index(mem_ctx, key, i, &subkey);
- if(!W_ERROR_IS_OK(error)) { talloc_destroy(mem_ctx); return error; }
-
- error = reg_key_del_recursive(subkey);
- if(!W_ERROR_IS_OK(error)) { talloc_destroy(mem_ctx); return error; }
- }
-
- talloc_destroy(mem_ctx);
- return reg_key_del(key);
-}
-
-WERROR reg_key_add_name_recursive_abs(struct registry_context *handle, const char *name)
-{
- struct registry_key *hive;
- WERROR error;
- int hivelength;
- char *hivename;
-
- if(strchr(name, '\\')) hivelength = strchr(name, '\\')-name;
- else hivelength = strlen(name);
-
- hivename = strndup(name, hivelength);
- error = reg_get_predefined_key_by_name(handle, hivename, &hive);
- SAFE_FREE(hivename);
-
- if(!W_ERROR_IS_OK(error)) return error;
-
- return reg_key_add_name_recursive(hive, name);
-}
-
-WERROR reg_key_add_name_recursive(struct registry_key *parent, const char *path)
-{
- struct registry_key *cur, *prevcur = parent;
- WERROR error = WERR_OK;
- char *dups, *begin, *end;
- TALLOC_CTX *mem_ctx = talloc_init("add_recursive");
-
- begin = dups = strdup(path);
-
- while(1) {
- end = strchr(begin, '\\');
- if(end) *end = '\0';
-
- error = reg_key_get_subkey_by_name(mem_ctx, prevcur, begin, &cur);
-
- /* Key is not there, add it */
- if(W_ERROR_EQUAL(error, WERR_DEST_NOT_FOUND)) {
- error = reg_key_add_name(mem_ctx, prevcur, begin, 0, NULL, &cur);
- if(!W_ERROR_IS_OK(error)) break;
- }
-
- if(!W_ERROR_IS_OK(error)) {
- if(end) *end = '\\';
- break;
- }
-
- if(!end) {
- error = WERR_OK;
- break;
- }
-
- *end = '\\';
- begin = end+1;
- prevcur = cur;
- }
- SAFE_FREE(dups);
- talloc_destroy(mem_ctx);
- return error;
-}
-
WERROR reg_key_add_name(TALLOC_CTX *mem_ctx, struct registry_key *parent, const char *name, uint32_t access_mask, SEC_DESC *desc, struct registry_key **newkey)
{
WERROR error;
@@ -547,7 +423,7 @@ WERROR reg_key_add_name(TALLOC_CTX *mem_ctx, struct registry_key *parent, const
return WERR_OK;
}
-WERROR reg_val_set(struct registry_key *key, const char *value, int type, void *data, int len)
+WERROR reg_val_set(struct registry_key *key, const char *value, uint32 type, void *data, int len)
{
/* A 'real' set function has preference */
if (key->hive->functions->set_value)
@@ -577,27 +453,6 @@ WERROR reg_save (struct registry_context *ctx, const char *location)
return WERR_NOT_SUPPORTED;
}
-WERROR reg_key_get_parent(TALLOC_CTX *mem_ctx, struct registry_key *key, struct registry_key **parent)
-{
- char *parent_name;
- char *last;
- struct registry_key *root = NULL;
- WERROR error;
-
- parent_name = strdup(key->path);
- last = strrchr(parent_name, '\\');
-
- if(!last) {
- SAFE_FREE(parent_name);
- return WERR_FOOBAR;
- }
- *last = '\0';
-
- error = reg_open_key(mem_ctx, root, parent_name, parent);
- SAFE_FREE(parent_name);
- return error;
-}
-
WERROR reg_key_flush(struct registry_key *key)
{
if (!key) {
diff --git a/source4/lib/registry/common/reg_util.c b/source4/lib/registry/common/reg_util.c
index 052ccc347b..1d1f770324 100644
--- a/source4/lib/registry/common/reg_util.c
+++ b/source4/lib/registry/common/reg_util.c
@@ -150,3 +150,90 @@ char *reg_path_unix2win(char *path)
}
return path;
}
+
+/* Open a key by name (including the predefined key name!) */
+WERROR reg_open_key_abs(TALLOC_CTX *mem_ctx, struct registry_context *handle, const char *name, struct registry_key **result)
+{
+ struct registry_key *predef;
+ WERROR error;
+ int predeflength;
+ char *predefname;
+
+ if(strchr(name, '\\')) predeflength = strchr(name, '\\')-name;
+ else predeflength = strlen(name);
+
+ predefname = strndup(name, predeflength);
+ error = reg_get_predefined_key_by_name(handle, predefname, &predef);
+ SAFE_FREE(predefname);
+
+ if(!W_ERROR_IS_OK(error)) {
+ return error;
+ }
+
+ if (strchr(name, '\\')) {
+ return reg_open_key(mem_ctx, predef, strchr(name, '\\')+1, result);
+ } else {
+ *result = predef;
+ return WERR_OK;
+ }
+}
+
+static WERROR get_abs_parent(TALLOC_CTX *mem_ctx, struct registry_context *ctx, const char *path, struct registry_key **parent, const char **name)
+{
+ char *parent_name;
+ WERROR error;
+
+ if (strchr(path, '\\') == NULL) {
+ return WERR_FOOBAR;
+ }
+
+ parent_name = talloc_strndup(mem_ctx, path, strrchr(path, '\\')-1-path);
+
+ error = reg_open_key_abs(mem_ctx, ctx, parent_name, parent);
+ if (!W_ERROR_IS_OK(error)) {
+ return error;
+ }
+
+ *name = talloc_strdup(mem_ctx, strchr(path, '\\')+1);
+
+ return WERR_OK;
+}
+
+WERROR reg_key_del_abs(struct registry_context *ctx, const char *path)
+{
+ struct registry_key *parent;
+ const char *n;
+ TALLOC_CTX *mem_ctx = talloc_init("reg_key_del_abs");
+ WERROR error;
+
+ if (!strchr(path, '\\')) {
+ return WERR_FOOBAR;
+ }
+
+ error = get_abs_parent(mem_ctx, ctx, path, &parent, &n);
+ if (W_ERROR_IS_OK(error)) {
+ error = reg_key_del(parent, n);
+ }
+
+ talloc_destroy(mem_ctx);
+
+ return error;
+}
+
+WERROR reg_key_add_abs(TALLOC_CTX *mem_ctx, struct registry_context *ctx, const char *path, uint32 access_mask, SEC_DESC *sec_desc, struct registry_key **result)
+{
+ struct registry_key *parent;
+ const char *n;
+ WERROR error;
+
+ if (!strchr(path, '\\')) {
+ return WERR_FOOBAR;
+ }
+
+ error = get_abs_parent(mem_ctx, ctx, path, &parent, &n);
+ if (W_ERROR_IS_OK(error)) {
+ error = reg_key_add_name(mem_ctx, parent, n, access_mask, sec_desc, result);
+ }
+
+ return error;
+}