2 * Unix SMB/CIFS implementation.
3 * Virtual Windows Registry Layer
4 * Copyright (C) Volker Lendecke 2006
5 * Copyright (C) Michael Adam 2007-2010
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, see <http://www.gnu.org/licenses/>.
22 * Higher level utility functions on top of reg_api.c
28 #include "reg_api_util.h"
31 * Utility function to open a complete registry path including the hive prefix.
33 WERROR reg_open_path(TALLOC_CTX *mem_ctx, const char *orig_path,
34 uint32 desired_access, const struct security_token *token,
35 struct registry_key **pkey)
37 struct registry_key *hive, *key;
41 if (!(path = SMB_STRDUP(orig_path))) {
45 p = strchr(path, '\\');
47 if ((p == NULL) || (p[1] == '\0')) {
49 * No key behind the hive, just return the hive
52 err = reg_openhive(mem_ctx, path, desired_access, token,
54 if (!W_ERROR_IS_OK(err)) {
65 err = reg_openhive(mem_ctx, path, KEY_ENUMERATE_SUB_KEYS, token,
67 if (!W_ERROR_IS_OK(err)) {
72 err = reg_openkey(mem_ctx, hive, p+1, desired_access, &key);
77 if (!W_ERROR_IS_OK(err)) {
86 * Utility function to create a registry key without opening the hive
87 * before. Assumes the hive already exists.
90 WERROR reg_create_path(TALLOC_CTX *mem_ctx, const char *orig_path,
91 uint32 desired_access,
92 const struct security_token *token,
93 enum winreg_CreateAction *paction,
94 struct registry_key **pkey)
96 struct registry_key *hive;
100 if (!(path = SMB_STRDUP(orig_path))) {
104 p = strchr(path, '\\');
106 if ((p == NULL) || (p[1] == '\0')) {
108 * No key behind the hive, just return the hive
111 err = reg_openhive(mem_ctx, path, desired_access, token,
113 if (!W_ERROR_IS_OK(err)) {
119 *paction = REG_OPENED_EXISTING_KEY;
125 err = reg_openhive(mem_ctx, path,
126 (strchr(p+1, '\\') != NULL) ?
127 KEY_ENUMERATE_SUB_KEYS : KEY_CREATE_SUB_KEY,
129 if (!W_ERROR_IS_OK(err)) {
134 err = reg_createkey(mem_ctx, hive, p+1, desired_access, pkey, paction);
141 * Utility function to create a registry key without opening the hive
142 * before. Will not delete a hive.
145 WERROR reg_delete_path(const struct security_token *token,
146 const char *orig_path)
148 struct registry_key *hive;
152 if (!(path = SMB_STRDUP(orig_path))) {
156 p = strchr(path, '\\');
158 if ((p == NULL) || (p[1] == '\0')) {
160 return WERR_INVALID_PARAM;
165 err = reg_openhive(NULL, path,
166 (strchr(p+1, '\\') != NULL) ?
167 KEY_ENUMERATE_SUB_KEYS : KEY_CREATE_SUB_KEY,
169 if (!W_ERROR_IS_OK(err)) {
174 err = reg_deletekey(hive, p+1);