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 /* these two functions are unused. */
89 * Utility function to create a registry key without opening the hive
90 * before. Assumes the hive already exists.
93 WERROR
reg_create_path(TALLOC_CTX
*mem_ctx
, const char *orig_path
,
94 uint32 desired_access
,
95 const struct security_token
*token
,
96 enum winreg_CreateAction
*paction
,
97 struct registry_key
**pkey
)
99 struct registry_key
*hive
;
103 if (!(path
= SMB_STRDUP(orig_path
))) {
107 p
= strchr(path
, '\\');
109 if ((p
== NULL
) || (p
[1] == '\0')) {
111 * No key behind the hive, just return the hive
114 err
= reg_openhive(mem_ctx
, path
, desired_access
, token
,
116 if (!W_ERROR_IS_OK(err
)) {
122 *paction
= REG_OPENED_EXISTING_KEY
;
128 err
= reg_openhive(mem_ctx
, path
,
129 (strchr(p
+1, '\\') != NULL
) ?
130 KEY_ENUMERATE_SUB_KEYS
: KEY_CREATE_SUB_KEY
,
132 if (!W_ERROR_IS_OK(err
)) {
137 err
= reg_createkey(mem_ctx
, hive
, p
+1, desired_access
, pkey
, paction
);
144 * Utility function to create a registry key without opening the hive
145 * before. Will not delete a hive.
148 WERROR
reg_delete_path(const struct security_token
*token
,
149 const char *orig_path
)
151 struct registry_key
*hive
;
155 if (!(path
= SMB_STRDUP(orig_path
))) {
159 p
= strchr(path
, '\\');
161 if ((p
== NULL
) || (p
[1] == '\0')) {
163 return WERR_INVALID_PARAM
;
168 err
= reg_openhive(NULL
, path
,
169 (strchr(p
+1, '\\') != NULL
) ?
170 KEY_ENUMERATE_SUB_KEYS
: KEY_CREATE_SUB_KEY
,
172 if (!W_ERROR_IS_OK(err
)) {
177 err
= reg_deletekey(hive
, p
+1);