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
27 #include "reg_api_util.h"
30 * Utility function to open a complete registry path including the hive prefix.
32 WERROR
reg_open_path(TALLOC_CTX
*mem_ctx
, const char *orig_path
,
33 uint32 desired_access
, const struct security_token
*token
,
34 struct registry_key
**pkey
)
36 struct registry_key
*hive
, *key
;
40 if (!(path
= SMB_STRDUP(orig_path
))) {
44 p
= strchr(path
, '\\');
46 if ((p
== NULL
) || (p
[1] == '\0')) {
48 * No key behind the hive, just return the hive
51 err
= reg_openhive(mem_ctx
, path
, desired_access
, token
,
53 if (!W_ERROR_IS_OK(err
)) {
64 err
= reg_openhive(mem_ctx
, path
, KEY_ENUMERATE_SUB_KEYS
, token
,
66 if (!W_ERROR_IS_OK(err
)) {
71 err
= reg_openkey(mem_ctx
, hive
, p
+1, desired_access
, &key
);
76 if (!W_ERROR_IS_OK(err
)) {
85 /* these two functions are unused. */
88 * Utility function to create a registry key without opening the hive
89 * before. Assumes the hive already exists.
92 WERROR
reg_create_path(TALLOC_CTX
*mem_ctx
, const char *orig_path
,
93 uint32 desired_access
,
94 const struct security_token
*token
,
95 enum winreg_CreateAction
*paction
,
96 struct registry_key
**pkey
)
98 struct registry_key
*hive
;
102 if (!(path
= SMB_STRDUP(orig_path
))) {
106 p
= strchr(path
, '\\');
108 if ((p
== NULL
) || (p
[1] == '\0')) {
110 * No key behind the hive, just return the hive
113 err
= reg_openhive(mem_ctx
, path
, desired_access
, token
,
115 if (!W_ERROR_IS_OK(err
)) {
121 *paction
= REG_OPENED_EXISTING_KEY
;
127 err
= reg_openhive(mem_ctx
, path
,
128 (strchr(p
+1, '\\') != NULL
) ?
129 KEY_ENUMERATE_SUB_KEYS
: KEY_CREATE_SUB_KEY
,
131 if (!W_ERROR_IS_OK(err
)) {
136 err
= reg_createkey(mem_ctx
, hive
, p
+1, desired_access
, pkey
, paction
);
143 * Utility function to create a registry key without opening the hive
144 * before. Will not delete a hive.
147 WERROR
reg_delete_path(const struct security_token
*token
,
148 const char *orig_path
)
150 struct registry_key
*hive
;
154 if (!(path
= SMB_STRDUP(orig_path
))) {
158 p
= strchr(path
, '\\');
160 if ((p
== NULL
) || (p
[1] == '\0')) {
162 return WERR_INVALID_PARAM
;
167 err
= reg_openhive(NULL
, path
,
168 (strchr(p
+1, '\\') != NULL
) ?
169 KEY_ENUMERATE_SUB_KEYS
: KEY_CREATE_SUB_KEY
,
171 if (!W_ERROR_IS_OK(err
)) {
176 err
= reg_deletekey(hive
, p
+1);