summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVolker Lendecke <vlendec@samba.org>2006-12-03 16:19:15 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:16:20 -0500
commit4a272ef0a8b7a6ce5be12ffe0122ed16b03e0bf8 (patch)
tree6ff2e5945dcdebcbd2f06b74fd84a074dbc9d469
parentfe34827ffdaf4f0bbf5da739661675b0595388c7 (diff)
downloadsamba-4a272ef0a8b7a6ce5be12ffe0122ed16b03e0bf8.tar.gz
samba-4a272ef0a8b7a6ce5be12ffe0122ed16b03e0bf8.tar.bz2
samba-4a272ef0a8b7a6ce5be12ffe0122ed16b03e0bf8.zip
r20016: Add two utility functions for easy opening/creating registry keys
(This used to be commit ad22a467185e871d893e8133741b525889c2aa6f)
-rw-r--r--source3/registry/reg_frontend.c96
1 files changed, 95 insertions, 1 deletions
diff --git a/source3/registry/reg_frontend.c b/source3/registry/reg_frontend.c
index 3bbbe79a32..3bb88eaf47 100644
--- a/source3/registry/reg_frontend.c
+++ b/source3/registry/reg_frontend.c
@@ -522,8 +522,8 @@ WERROR reg_open_path(TALLOC_CTX *mem_ctx, const char *orig_path,
SAFE_FREE(path);
return err;
}
- *pkey = hive;
SAFE_FREE(path);
+ *pkey = hive;
return WERR_OK;
}
@@ -548,3 +548,97 @@ WERROR reg_open_path(TALLOC_CTX *mem_ctx, const char *orig_path,
*pkey = key;
return WERR_OK;
}
+
+/*
+ * Utility function to create a registry key without opening the hive
+ * before. Assumes the hive already exists.
+ */
+
+WERROR reg_create_path(TALLOC_CTX *mem_ctx, const char *orig_path,
+ uint32 desired_access,
+ const struct nt_user_token *token,
+ enum winreg_CreateAction *paction,
+ struct registry_key **pkey)
+{
+ struct registry_key *hive;
+ char *path, *p;
+ WERROR err;
+
+ if (!(path = SMB_STRDUP(orig_path))) {
+ return WERR_NOMEM;
+ }
+
+ p = strchr(path, '\\');
+
+ if ((p == NULL) || (p[1] == '\0')) {
+ /*
+ * No key behind the hive, just return the hive
+ */
+
+ err = reg_openhive(mem_ctx, path, desired_access, token,
+ &hive);
+ if (!W_ERROR_IS_OK(err)) {
+ SAFE_FREE(path);
+ return err;
+ }
+ SAFE_FREE(path);
+ *pkey = hive;
+ *paction = REG_OPENED_EXISTING_KEY;
+ return WERR_OK;
+ }
+
+ *p = '\0';
+
+ err = reg_openhive(mem_ctx, path,
+ (strchr(p+1, '\\') != NULL) ?
+ SEC_RIGHTS_ENUM_SUBKEYS : SEC_RIGHTS_CREATE_SUBKEY,
+ token, &hive);
+ if (!W_ERROR_IS_OK(err)) {
+ SAFE_FREE(path);
+ return err;
+ }
+
+ err = reg_createkey(mem_ctx, hive, p+1, desired_access, pkey, paction);
+ SAFE_FREE(path);
+ TALLOC_FREE(hive);
+ return err;
+}
+
+/*
+ * Utility function to create a registry key without opening the hive
+ * before. Will not delete a hive.
+ */
+
+WERROR reg_delete_path(const struct nt_user_token *token,
+ const char *orig_path)
+{
+ struct registry_key *hive;
+ char *path, *p;
+ WERROR err;
+
+ if (!(path = SMB_STRDUP(orig_path))) {
+ return WERR_NOMEM;
+ }
+
+ p = strchr(path, '\\');
+
+ if ((p == NULL) || (p[1] == '\0')) {
+ return WERR_INVALID_PARAM;
+ }
+
+ *p = '\0';
+
+ err = reg_openhive(NULL, path,
+ (strchr(p+1, '\\') != NULL) ?
+ SEC_RIGHTS_ENUM_SUBKEYS : SEC_RIGHTS_CREATE_SUBKEY,
+ token, &hive);
+ if (!W_ERROR_IS_OK(err)) {
+ SAFE_FREE(path);
+ return err;
+ }
+
+ err = reg_deletekey(hive, p+1);
+ SAFE_FREE(path);
+ TALLOC_FREE(hive);
+ return err;
+}