2 Unix SMB/CIFS implementation.
4 Copyright (C) Gerald Carter 2002.
5 Copyright (C) Jelmer Vernooij 2003-2007.
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/>.
21 #ifndef _REGISTRY_H /* _REGISTRY_H */
24 struct registry_context
;
25 struct loadparm_context
;
28 #include "libcli/util/werror.h"
29 #include "librpc/gen_ndr/security.h"
30 #include "libcli/util/ntstatus.h"
31 #include "../lib/util/time.h"
32 #include "../lib/util/data_blob.h"
35 * The hive API. This API is generally used for
36 * reading a specific file that contains just one hive.
38 * Good examples are .DAT (NTUSER.DAT) files.
40 * This API does not have any notification support (that
41 * should be provided by the registry implementation), nor
42 * does it understand what predefined keys are.
46 const struct hive_operations
*ops
;
49 struct hive_operations
{
53 * Open a specific subkey
55 WERROR (*enum_key
) (TALLOC_CTX
*mem_ctx
,
56 const struct hive_key
*key
, uint32_t idx
,
58 const char **classname
,
59 NTTIME
*last_mod_time
);
62 * Open a subkey by name
64 WERROR (*get_key_by_name
) (TALLOC_CTX
*mem_ctx
,
65 const struct hive_key
*key
, const char *name
,
66 struct hive_key
**subkey
);
71 WERROR (*add_key
) (TALLOC_CTX
*ctx
,
72 const struct hive_key
*parent_key
, const char *path
,
73 const char *classname
,
74 struct security_descriptor
*desc
,
75 struct hive_key
**key
);
77 * Remove an existing key.
79 WERROR (*del_key
) (TALLOC_CTX
*mem_ctx
,
80 const struct hive_key
*key
, const char *name
);
83 * Force write of a key to disk.
85 WERROR (*flush_key
) (struct hive_key
*key
);
88 * Retrieve a registry value with a specific index.
90 WERROR (*enum_value
) (TALLOC_CTX
*mem_ctx
,
91 struct hive_key
*key
, uint32_t idx
,
92 const char **name
, uint32_t *type
,
96 * Retrieve a registry value with the specified name
98 WERROR (*get_value_by_name
) (TALLOC_CTX
*mem_ctx
,
99 struct hive_key
*key
, const char *name
,
100 uint32_t *type
, DATA_BLOB
*data
);
103 * Set a value on the specified registry key.
105 WERROR (*set_value
) (struct hive_key
*key
, const char *name
,
106 uint32_t type
, const DATA_BLOB data
);
111 WERROR (*delete_value
) (TALLOC_CTX
*mem_ctx
,
112 struct hive_key
*key
, const char *name
);
114 /* Security Descriptors */
117 * Change the security descriptor on a registry key.
119 * This should return WERR_NOT_SUPPORTED if the underlying
120 * format does not have a mechanism for storing
121 * security descriptors.
123 WERROR (*set_sec_desc
) (struct hive_key
*key
,
124 const struct security_descriptor
*desc
);
127 * Retrieve the security descriptor on a registry key.
129 * This should return WERR_NOT_SUPPORTED if the underlying
130 * format does not have a mechanism for storing
131 * security descriptors.
133 WERROR (*get_sec_desc
) (TALLOC_CTX
*ctx
,
134 const struct hive_key
*key
,
135 struct security_descriptor
**desc
);
138 * Retrieve general information about a key.
140 WERROR (*get_key_info
) (TALLOC_CTX
*mem_ctx
,
141 const struct hive_key
*key
,
142 const char **classname
,
143 uint32_t *num_subkeys
,
144 uint32_t *num_values
,
145 NTTIME
*last_change_time
,
146 uint32_t *max_subkeynamelen
,
147 uint32_t *max_valnamelen
,
148 uint32_t *max_valbufsize
);
151 struct cli_credentials
;
152 struct auth_session_info
;
153 struct tevent_context
;
155 WERROR
reg_open_hive(TALLOC_CTX
*parent_ctx
, const char *location
,
156 struct auth_session_info
*session_info
,
157 struct cli_credentials
*credentials
,
158 struct tevent_context
*ev_ctx
,
159 struct loadparm_context
*lp_ctx
,
160 struct hive_key
**root
);
161 WERROR
hive_key_get_info(TALLOC_CTX
*mem_ctx
, const struct hive_key
*key
,
162 const char **classname
, uint32_t *num_subkeys
,
163 uint32_t *num_values
, NTTIME
*last_change_time
,
164 uint32_t *max_subkeynamelen
,
165 uint32_t *max_valnamelen
, uint32_t *max_valbufsize
);
166 WERROR
hive_key_add_name(TALLOC_CTX
*ctx
, const struct hive_key
*parent_key
,
167 const char *name
, const char *classname
,
168 struct security_descriptor
*desc
,
169 struct hive_key
**key
);
170 WERROR
hive_key_del(TALLOC_CTX
*mem_ctx
,
171 const struct hive_key
*key
, const char *name
);
172 WERROR
hive_get_key_by_name(TALLOC_CTX
*mem_ctx
,
173 const struct hive_key
*key
, const char *name
,
174 struct hive_key
**subkey
);
175 WERROR
hive_enum_key(TALLOC_CTX
*mem_ctx
,
176 const struct hive_key
*key
, uint32_t idx
,
178 const char **classname
,
179 NTTIME
*last_mod_time
);
181 WERROR
hive_key_set_value(struct hive_key
*key
, const char *name
,
182 uint32_t type
, const DATA_BLOB data
);
184 WERROR
hive_get_value(TALLOC_CTX
*mem_ctx
,
185 struct hive_key
*key
, const char *name
,
186 uint32_t *type
, DATA_BLOB
*data
);
187 WERROR
hive_get_value_by_index(TALLOC_CTX
*mem_ctx
,
188 struct hive_key
*key
, uint32_t idx
,
190 uint32_t *type
, DATA_BLOB
*data
);
191 WERROR
hive_get_sec_desc(TALLOC_CTX
*mem_ctx
,
192 struct hive_key
*key
,
193 struct security_descriptor
**security
);
195 WERROR
hive_set_sec_desc(struct hive_key
*key
,
196 const struct security_descriptor
*security
);
198 WERROR
hive_key_del_value(TALLOC_CTX
*mem_ctx
,
199 struct hive_key
*key
, const char *name
);
201 WERROR
hive_key_flush(struct hive_key
*key
);
204 /* Individual backends */
205 WERROR
reg_open_directory(TALLOC_CTX
*parent_ctx
,
206 const char *location
, struct hive_key
**key
);
207 WERROR
reg_open_regf_file(TALLOC_CTX
*parent_ctx
,
208 const char *location
, struct hive_key
**key
);
209 WERROR
reg_open_ldb_file(TALLOC_CTX
*parent_ctx
, const char *location
,
210 struct auth_session_info
*session_info
,
211 struct cli_credentials
*credentials
,
212 struct tevent_context
*ev_ctx
,
213 struct loadparm_context
*lp_ctx
,
214 struct hive_key
**k
);
217 WERROR
reg_create_directory(TALLOC_CTX
*parent_ctx
,
218 const char *location
, struct hive_key
**key
);
219 WERROR
reg_create_regf_file(TALLOC_CTX
*parent_ctx
,
220 const char *location
,
222 struct hive_key
**key
);
226 /* Handles for the predefined keys */
227 #define HKEY_CLASSES_ROOT 0x80000000
228 #define HKEY_CURRENT_USER 0x80000001
229 #define HKEY_LOCAL_MACHINE 0x80000002
230 #define HKEY_USERS 0x80000003
231 #define HKEY_PERFORMANCE_DATA 0x80000004
232 #define HKEY_CURRENT_CONFIG 0x80000005
233 #define HKEY_DYN_DATA 0x80000006
234 #define HKEY_PERFORMANCE_TEXT 0x80000050
235 #define HKEY_PERFORMANCE_NLSTEXT 0x80000060
237 #define HKEY_FIRST HKEY_CLASSES_ROOT
238 #define HKEY_LAST HKEY_PERFORMANCE_NLSTEXT
240 struct reg_predefined_key
{
245 extern const struct reg_predefined_key reg_predefined_keys
[];
247 #define REG_DELETE -1
250 * The general idea here is that every backend provides a 'hive'. Combining
251 * various hives gives you a complete registry like windows has
254 #define REGISTRY_INTERFACE_VERSION 1
256 struct reg_key_operations
;
258 /* structure to store the registry handles */
261 struct registry_context
*context
;
264 struct registry_value
267 unsigned int data_type
;
272 typedef void (*reg_key_notification_function
) (void);
273 typedef void (*reg_value_notification_function
) (void);
275 struct cli_credentials
;
277 struct registry_operations
{
280 WERROR (*get_key_info
) (TALLOC_CTX
*mem_ctx
,
281 const struct registry_key
*key
,
282 const char **classname
,
283 uint32_t *numsubkeys
,
285 NTTIME
*last_change_time
,
286 uint32_t *max_subkeynamelen
,
287 uint32_t *max_valnamelen
,
288 uint32_t *max_valbufsize
);
290 WERROR (*flush_key
) (struct registry_key
*key
);
292 WERROR (*get_predefined_key
) (struct registry_context
*ctx
,
294 struct registry_key
**key
);
296 WERROR (*open_key
) (TALLOC_CTX
*mem_ctx
,
297 struct registry_key
*parent
,
299 struct registry_key
**key
);
301 WERROR (*create_key
) (TALLOC_CTX
*mem_ctx
,
302 struct registry_key
*parent
,
304 const char *key_class
,
305 struct security_descriptor
*security
,
306 struct registry_key
**key
);
308 WERROR (*delete_key
) (TALLOC_CTX
*mem_ctx
,
309 struct registry_key
*key
, const char *name
);
311 WERROR (*delete_value
) (TALLOC_CTX
*mem_ctx
,
312 struct registry_key
*key
, const char *name
);
314 WERROR (*enum_key
) (TALLOC_CTX
*mem_ctx
,
315 const struct registry_key
*key
, uint32_t idx
,
317 const char **keyclass
,
318 NTTIME
*last_changed_time
);
320 WERROR (*enum_value
) (TALLOC_CTX
*mem_ctx
,
321 const struct registry_key
*key
, uint32_t idx
,
326 WERROR (*get_sec_desc
) (TALLOC_CTX
*mem_ctx
,
327 const struct registry_key
*key
,
328 struct security_descriptor
**security
);
330 WERROR (*set_sec_desc
) (struct registry_key
*key
,
331 const struct security_descriptor
*security
);
333 WERROR (*load_key
) (struct registry_key
*key
,
334 const char *key_name
,
337 WERROR (*unload_key
) (struct registry_key
*key
, const char *name
);
339 WERROR (*notify_value_change
) (struct registry_key
*key
,
340 reg_value_notification_function fn
);
342 WERROR (*get_value
) (TALLOC_CTX
*mem_ctx
,
343 const struct registry_key
*key
,
348 WERROR (*set_value
) (struct registry_key
*key
,
351 const DATA_BLOB data
);
355 * Handle to a full registry
356 * contains zero or more hives
358 struct registry_context
{
359 const struct registry_operations
*ops
;
362 struct auth_session_info
;
363 struct tevent_context
;
364 struct loadparm_context
;
367 * Open the locally defined registry.
369 WERROR
reg_open_local(TALLOC_CTX
*mem_ctx
,
370 struct registry_context
**ctx
);
372 WERROR
reg_open_samba(TALLOC_CTX
*mem_ctx
,
373 struct registry_context
**ctx
,
374 struct tevent_context
*ev_ctx
,
375 struct loadparm_context
*lp_ctx
,
376 struct auth_session_info
*session_info
,
377 struct cli_credentials
*credentials
);
380 * Open the registry on a remote machine.
382 WERROR
reg_open_remote(TALLOC_CTX
*mem_ctx
,
383 struct registry_context
**ctx
,
384 struct auth_session_info
*session_info
,
385 struct cli_credentials
*credentials
,
386 struct loadparm_context
*lp_ctx
,
387 const char *location
, struct tevent_context
*ev
);
389 WERROR
reg_open_wine(struct registry_context
**ctx
, const char *path
);
391 const char *reg_get_predef_name(uint32_t hkey
);
392 WERROR
reg_get_predefined_key_by_name(struct registry_context
*ctx
,
394 struct registry_key
**key
);
395 WERROR
reg_get_predefined_key(struct registry_context
*ctx
,
397 struct registry_key
**key
);
399 WERROR
reg_open_key(TALLOC_CTX
*mem_ctx
, struct registry_key
*parent
,
400 const char *name
, struct registry_key
**result
);
402 WERROR
reg_key_get_value_by_index(TALLOC_CTX
*mem_ctx
,
403 const struct registry_key
*key
, uint32_t idx
,
407 WERROR
reg_key_get_info(TALLOC_CTX
*mem_ctx
,
408 const struct registry_key
*key
,
409 const char **class_name
,
410 uint32_t *num_subkeys
,
411 uint32_t *num_values
,
412 NTTIME
*last_change_time
,
413 uint32_t *max_subkeynamelen
,
414 uint32_t *max_valnamelen
,
415 uint32_t *max_valbufsize
);
416 WERROR
reg_key_get_subkey_by_index(TALLOC_CTX
*mem_ctx
,
417 const struct registry_key
*key
,
420 const char **classname
,
421 NTTIME
*last_mod_time
);
422 WERROR
reg_key_get_subkey_by_name(TALLOC_CTX
*mem_ctx
,
423 const struct registry_key
*key
,
425 struct registry_key
**subkey
);
426 WERROR
reg_key_get_value_by_name(TALLOC_CTX
*mem_ctx
,
427 const struct registry_key
*key
,
431 WERROR
reg_key_del(TALLOC_CTX
*mem_ctx
,
432 struct registry_key
*parent
, const char *name
);
433 WERROR
reg_key_add_name(TALLOC_CTX
*mem_ctx
,
434 struct registry_key
*parent
, const char *name
,
435 const char *classname
,
436 struct security_descriptor
*desc
,
437 struct registry_key
**newkey
);
438 WERROR
reg_val_set(struct registry_key
*key
, const char *value
,
439 uint32_t type
, DATA_BLOB data
);
440 WERROR
reg_get_sec_desc(TALLOC_CTX
*ctx
, const struct registry_key
*key
,
441 struct security_descriptor
**secdesc
);
442 WERROR
reg_del_value(TALLOC_CTX
*mem_ctx
,
443 struct registry_key
*key
, const char *valname
);
444 WERROR
reg_key_flush(struct registry_key
*key
);
445 WERROR
reg_create_key(TALLOC_CTX
*mem_ctx
,
446 struct registry_key
*parent
,
448 const char *key_class
,
449 struct security_descriptor
*security
,
450 struct registry_key
**key
);
452 /* Utility functions */
453 const char *str_regtype(int type
);
454 bool push_reg_sz(TALLOC_CTX
*mem_ctx
, DATA_BLOB
*blob
, const char *s
);
455 bool push_reg_multi_sz(TALLOC_CTX
*mem_ctx
, DATA_BLOB
*blob
, const char **a
);
456 bool pull_reg_sz(TALLOC_CTX
*mem_ctx
, const DATA_BLOB
*blob
, const char **s
);
457 bool pull_reg_multi_sz(TALLOC_CTX
*mem_ctx
, const DATA_BLOB
*blob
, const char ***a
);
458 int regtype_by_string(const char *str
);
459 char *reg_val_data_string(TALLOC_CTX
*mem_ctx
, uint32_t type
, const DATA_BLOB data
);
460 char *reg_val_description(TALLOC_CTX
*mem_ctx
, const char *name
,
461 uint32_t type
, const DATA_BLOB data
);
462 bool reg_string_to_val(TALLOC_CTX
*mem_ctx
, const char *type_str
,
463 const char *data_str
, uint32_t *type
, DATA_BLOB
*data
);
464 WERROR
reg_open_key_abs(TALLOC_CTX
*mem_ctx
, struct registry_context
*handle
,
465 const char *name
, struct registry_key
**result
);
466 WERROR
reg_key_del_abs(struct registry_context
*ctx
, const char *path
);
467 WERROR
reg_key_add_abs(TALLOC_CTX
*mem_ctx
, struct registry_context
*ctx
,
468 const char *path
, uint32_t access_mask
,
469 struct security_descriptor
*sec_desc
,
470 struct registry_key
**result
);
471 WERROR
reg_load_key(struct registry_context
*ctx
, struct registry_key
*key
,
472 const char *name
, const char *filename
);
474 WERROR
reg_mount_hive(struct registry_context
*rctx
,
475 struct hive_key
*hive_key
,
477 const char **elements
);
479 struct registry_key
*reg_import_hive_key(struct registry_context
*ctx
,
480 struct hive_key
*hive
,
482 const char **elements
);
483 WERROR
reg_set_sec_desc(struct registry_key
*key
,
484 const struct security_descriptor
*security
);
486 struct reg_diff_callbacks
{
487 WERROR (*add_key
) (void *callback_data
, const char *key_name
);
488 WERROR (*set_value
) (void *callback_data
, const char *key_name
,
489 const char *value_name
, uint32_t value_type
,
491 WERROR (*del_value
) (void *callback_data
, const char *key_name
,
492 const char *value_name
);
493 WERROR (*del_key
) (void *callback_data
, const char *key_name
);
494 WERROR (*del_all_values
) (void *callback_data
, const char *key_name
);
495 WERROR (*done
) (void *callback_data
);
498 WERROR
reg_diff_apply(struct registry_context
*ctx
,
499 const char *filename
);
501 WERROR
reg_generate_diff(struct registry_context
*ctx1
,
502 struct registry_context
*ctx2
,
503 const struct reg_diff_callbacks
*callbacks
,
504 void *callback_data
);
505 WERROR
reg_dotreg_diff_save(TALLOC_CTX
*ctx
, const char *filename
,
506 struct reg_diff_callbacks
**callbacks
,
507 void **callback_data
);
508 WERROR
reg_preg_diff_save(TALLOC_CTX
*ctx
, const char *filename
,
509 struct reg_diff_callbacks
**callbacks
,
510 void **callback_data
);
511 WERROR
reg_generate_diff_key(struct registry_key
*oldkey
,
512 struct registry_key
*newkey
,
514 const struct reg_diff_callbacks
*callbacks
,
515 void *callback_data
);
516 WERROR
reg_diff_load(const char *filename
,
517 const struct reg_diff_callbacks
*callbacks
,
518 void *callback_data
);
520 WERROR
reg_dotreg_diff_load(int fd
,
521 const struct reg_diff_callbacks
*callbacks
,
522 void *callback_data
);
524 WERROR
reg_preg_diff_load(int fd
,
525 const struct reg_diff_callbacks
*callbacks
,
526 void *callback_data
);
528 WERROR
local_get_predefined_key(struct registry_context
*ctx
,
529 uint32_t key_id
, struct registry_key
**key
);
532 #endif /* _REGISTRY_H */