2 Unix SMB/CIFS implementation.
3 Transparent registry backend handling
4 Copyright (C) Jelmer Vernooij 2003-2007.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "../lib/util/dlinklist.h"
22 #include "lib/registry/registry.h"
23 #include "system/filesys.h"
29 * @brief Main registry functions
32 const struct reg_predefined_key reg_predefined_keys
[] = {
33 {HKEY_CLASSES_ROOT
,"HKEY_CLASSES_ROOT" },
34 {HKEY_CURRENT_USER
,"HKEY_CURRENT_USER" },
35 {HKEY_LOCAL_MACHINE
, "HKEY_LOCAL_MACHINE" },
36 {HKEY_PERFORMANCE_DATA
, "HKEY_PERFORMANCE_DATA" },
37 {HKEY_USERS
, "HKEY_USERS" },
38 {HKEY_CURRENT_CONFIG
, "HKEY_CURRENT_CONFIG" },
39 {HKEY_DYN_DATA
, "HKEY_DYN_DATA" },
40 {HKEY_PERFORMANCE_TEXT
, "HKEY_PERFORMANCE_TEXT" },
41 {HKEY_PERFORMANCE_NLSTEXT
, "HKEY_PERFORMANCE_NLSTEXT" },
45 /** Obtain name of specific hkey. */
46 _PUBLIC_
const char *reg_get_predef_name(uint32_t hkey
)
49 for (i
= 0; reg_predefined_keys
[i
].name
; i
++) {
50 if (reg_predefined_keys
[i
].handle
== hkey
)
51 return reg_predefined_keys
[i
].name
;
57 /** Get predefined key by name. */
58 _PUBLIC_ WERROR
reg_get_predefined_key_by_name(struct registry_context
*ctx
,
60 struct registry_key
**key
)
64 for (i
= 0; reg_predefined_keys
[i
].name
; i
++) {
65 if (!strcasecmp(reg_predefined_keys
[i
].name
, name
))
66 return reg_get_predefined_key(ctx
,
67 reg_predefined_keys
[i
].handle
,
71 DEBUG(1, ("No predefined key with name '%s'\n", name
));
73 return WERR_FILE_NOT_FOUND
;
76 /** Get predefined key by id. */
77 _PUBLIC_ WERROR
reg_get_predefined_key(struct registry_context
*ctx
,
78 uint32_t hkey
, struct registry_key
**key
)
80 return ctx
->ops
->get_predefined_key(ctx
, hkey
, key
);
85 * First tries to use the open_key function from the backend
86 * then falls back to get_subkey_by_name and later get_subkey_by_index
88 _PUBLIC_ WERROR
reg_open_key(TALLOC_CTX
*mem_ctx
, struct registry_key
*parent
,
89 const char *name
, struct registry_key
**result
)
92 DEBUG(0, ("Invalid parent key specified for open of '%s'\n",
94 return WERR_INVALID_PARAMETER
;
97 if (parent
->context
->ops
->open_key
== NULL
) {
98 DEBUG(0, ("Registry backend doesn't have open_key!\n"));
99 return WERR_NOT_SUPPORTED
;
102 return parent
->context
->ops
->open_key(mem_ctx
, parent
, name
, result
);
108 _PUBLIC_ WERROR
reg_key_get_value_by_index(TALLOC_CTX
*mem_ctx
,
109 const struct registry_key
*key
,
110 uint32_t idx
, const char **name
,
111 uint32_t *type
, DATA_BLOB
*data
)
114 return WERR_INVALID_PARAMETER
;
116 if (key
->context
->ops
->enum_value
== NULL
)
117 return WERR_NOT_SUPPORTED
;
119 return key
->context
->ops
->enum_value(mem_ctx
, key
, idx
, name
,
124 * Get the number of subkeys.
126 _PUBLIC_ WERROR
reg_key_get_info(TALLOC_CTX
*mem_ctx
,
127 const struct registry_key
*key
,
128 const char **classname
,
129 uint32_t *num_subkeys
,
130 uint32_t *num_values
,
131 NTTIME
*last_change_time
,
132 uint32_t *max_subkeynamelen
,
133 uint32_t *max_valnamelen
,
134 uint32_t *max_valbufsize
)
137 return WERR_INVALID_PARAMETER
;
139 if (key
->context
->ops
->get_key_info
== NULL
)
140 return WERR_NOT_SUPPORTED
;
142 return key
->context
->ops
->get_key_info(mem_ctx
,
143 key
, classname
, num_subkeys
,
144 num_values
, last_change_time
,
146 max_valnamelen
, max_valbufsize
);
150 * Get subkey by index.
152 _PUBLIC_ WERROR
reg_key_get_subkey_by_index(TALLOC_CTX
*mem_ctx
,
153 const struct registry_key
*key
,
154 uint32_t idx
, const char **name
,
155 const char **keyclass
,
156 NTTIME
*last_changed_time
)
159 return WERR_INVALID_PARAMETER
;
161 if (key
->context
->ops
->enum_key
== NULL
)
162 return WERR_NOT_SUPPORTED
;
164 return key
->context
->ops
->enum_key(mem_ctx
, key
, idx
, name
,
165 keyclass
, last_changed_time
);
171 _PUBLIC_ WERROR
reg_key_get_value_by_name(TALLOC_CTX
*mem_ctx
,
172 const struct registry_key
*key
,
178 return WERR_INVALID_PARAMETER
;
180 if (key
->context
->ops
->get_value
== NULL
)
181 return WERR_NOT_SUPPORTED
;
183 return key
->context
->ops
->get_value(mem_ctx
, key
, name
, type
, data
);
189 _PUBLIC_ WERROR
reg_key_del(TALLOC_CTX
*mem_ctx
, struct registry_key
*parent
,
193 return WERR_INVALID_PARAMETER
;
195 if (parent
->context
->ops
->delete_key
== NULL
)
196 return WERR_NOT_SUPPORTED
;
198 return parent
->context
->ops
->delete_key(mem_ctx
, parent
, name
);
204 _PUBLIC_ WERROR
reg_key_add_name(TALLOC_CTX
*mem_ctx
,
205 struct registry_key
*parent
,
206 const char *path
, const char *key_class
,
207 struct security_descriptor
*desc
,
208 struct registry_key
**newkey
)
211 return WERR_INVALID_PARAMETER
;
213 if (parent
->context
->ops
->create_key
== NULL
) {
214 DEBUG(1, ("Backend '%s' doesn't support method add_key\n",
215 parent
->context
->ops
->name
));
216 return WERR_NOT_SUPPORTED
;
219 return parent
->context
->ops
->create_key(mem_ctx
, parent
, path
,
220 key_class
, desc
, newkey
);
226 _PUBLIC_ WERROR
reg_val_set(struct registry_key
*key
, const char *value
,
227 uint32_t type
, const DATA_BLOB data
)
230 return WERR_INVALID_PARAMETER
;
232 /* A 'real' set function has preference */
233 if (key
->context
->ops
->set_value
== NULL
) {
234 DEBUG(1, ("Backend '%s' doesn't support method set_value\n",
235 key
->context
->ops
->name
));
236 return WERR_NOT_SUPPORTED
;
239 return key
->context
->ops
->set_value(key
, value
, type
, data
);
243 * Get the security descriptor on a key.
245 _PUBLIC_ WERROR
reg_get_sec_desc(TALLOC_CTX
*ctx
,
246 const struct registry_key
*key
,
247 struct security_descriptor
**secdesc
)
250 return WERR_INVALID_PARAMETER
;
252 /* A 'real' set function has preference */
253 if (key
->context
->ops
->get_sec_desc
== NULL
)
254 return WERR_NOT_SUPPORTED
;
256 return key
->context
->ops
->get_sec_desc(ctx
, key
, secdesc
);
262 _PUBLIC_ WERROR
reg_del_value(TALLOC_CTX
*mem_ctx
, struct registry_key
*key
,
266 return WERR_INVALID_PARAMETER
;
268 if (key
->context
->ops
->delete_value
== NULL
)
269 return WERR_NOT_SUPPORTED
;
271 return key
->context
->ops
->delete_value(mem_ctx
, key
, valname
);
275 * Flush a key to disk.
277 _PUBLIC_ WERROR
reg_key_flush(struct registry_key
*key
)
280 return WERR_INVALID_PARAMETER
;
282 if (key
->context
->ops
->flush_key
== NULL
)
283 return WERR_NOT_SUPPORTED
;
285 return key
->context
->ops
->flush_key(key
);
288 _PUBLIC_ WERROR
reg_set_sec_desc(struct registry_key
*key
,
289 const struct security_descriptor
*security
)
292 return WERR_INVALID_PARAMETER
;
294 if (key
->context
->ops
->set_sec_desc
== NULL
)
295 return WERR_NOT_SUPPORTED
;
297 return key
->context
->ops
->set_sec_desc(key
, security
);