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;
26 struct smb_iconv_convenience;
29 #include "libcli/util/werror.h"
30 #include "librpc/gen_ndr/security.h"
31 #include "libcli/util/ntstatus.h"
32 #include "util/time.h"
33 #include "util/data_blob.h"
36 * The hive API. This API is generally used for
37 * reading a specific file that contains just one hive.
39 * Good examples are .DAT (NTUSER.DAT) files.
41 * This API does not have any notification support (that
42 * should be provided by the registry implementation), nor
43 * does it understand what predefined keys are.
47 const struct hive_operations *ops;
50 struct hive_operations {
54 * Open a specific subkey
56 WERROR (*enum_key) (TALLOC_CTX *mem_ctx,
57 const struct hive_key *key, uint32_t idx,
59 const char **classname,
60 NTTIME *last_mod_time);
63 * Open a subkey by name
65 WERROR (*get_key_by_name) (TALLOC_CTX *mem_ctx,
66 const struct hive_key *key, const char *name,
67 struct hive_key **subkey);
72 WERROR (*add_key) (TALLOC_CTX *ctx,
73 const struct hive_key *parent_key, const char *name,
74 const char *classname,
75 struct security_descriptor *desc,
76 struct hive_key **key);
78 * Remove an existing key.
80 WERROR (*del_key) (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, int 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) (struct hive_key *key, const char *name);
113 /* Security Descriptors */
116 * Change the security descriptor on a registry key.
118 * This should return WERR_NOT_SUPPORTED if the underlying
119 * format does not have a mechanism for storing
120 * security descriptors.
122 WERROR (*set_sec_desc) (struct hive_key *key,
123 const struct security_descriptor *desc);
126 * Retrieve the security descriptor on a registry key.
128 * This should return WERR_NOT_SUPPORTED if the underlying
129 * format does not have a mechanism for storing
130 * security descriptors.
132 WERROR (*get_sec_desc) (TALLOC_CTX *ctx,
133 const struct hive_key *key,
134 struct security_descriptor **desc);
137 * Retrieve general information about a key.
139 WERROR (*get_key_info) (TALLOC_CTX *mem_ctx,
140 const struct hive_key *key,
141 const char **classname,
142 uint32_t *num_subkeys,
143 uint32_t *num_values,
144 NTTIME *last_change_time,
145 uint32_t *max_subkeynamelen,
146 uint32_t *max_valnamelen,
147 uint32_t *max_valbufsize);
150 struct cli_credentials;
151 struct auth_session_info;
152 struct event_context;
154 WERROR reg_open_hive(TALLOC_CTX *parent_ctx, const char *location,
155 struct auth_session_info *session_info,
156 struct cli_credentials *credentials,
157 struct event_context *ev_ctx,
158 struct loadparm_context *lp_ctx,
159 struct hive_key **root);
160 WERROR hive_key_get_info(TALLOC_CTX *mem_ctx, const struct hive_key *key,
161 const char **classname, uint32_t *num_subkeys,
162 uint32_t *num_values, NTTIME *last_change_time,
163 uint32_t *max_subkeynamelen,
164 uint32_t *max_valnamelen, uint32_t *max_valbufsize);
165 WERROR hive_key_add_name(TALLOC_CTX *ctx, const struct hive_key *parent_key,
166 const char *name, const char *classname,
167 struct security_descriptor *desc,
168 struct hive_key **key);
169 WERROR hive_key_del(const struct hive_key *key, const char *name);
170 WERROR hive_get_key_by_name(TALLOC_CTX *mem_ctx,
171 const struct hive_key *key, const char *name,
172 struct hive_key **subkey);
173 WERROR hive_enum_key(TALLOC_CTX *mem_ctx,
174 const struct hive_key *key, uint32_t idx,
176 const char **classname,
177 NTTIME *last_mod_time);
179 WERROR hive_key_set_value(struct hive_key *key, const char *name,
180 uint32_t type, const DATA_BLOB data);
182 WERROR hive_get_value(TALLOC_CTX *mem_ctx,
183 struct hive_key *key, const char *name,
184 uint32_t *type, DATA_BLOB *data);
185 WERROR hive_get_value_by_index(TALLOC_CTX *mem_ctx,
186 struct hive_key *key, uint32_t idx,
188 uint32_t *type, DATA_BLOB *data);
190 WERROR hive_key_del_value(struct hive_key *key, const char *name);
192 WERROR hive_key_flush(struct hive_key *key);
195 /* Individual backends */
196 WERROR reg_open_directory(TALLOC_CTX *parent_ctx,
197 const char *location, struct hive_key **key);
198 WERROR reg_open_regf_file(TALLOC_CTX *parent_ctx,
199 const char *location, struct smb_iconv_convenience *iconv_convenience,
200 struct hive_key **key);
201 WERROR reg_open_ldb_file(TALLOC_CTX *parent_ctx, const char *location,
202 struct auth_session_info *session_info,
203 struct cli_credentials *credentials,
204 struct event_context *ev_ctx,
205 struct loadparm_context *lp_ctx,
206 struct hive_key **k);
209 WERROR reg_create_directory(TALLOC_CTX *parent_ctx,
210 const char *location, struct hive_key **key);
211 WERROR reg_create_regf_file(TALLOC_CTX *parent_ctx,
212 struct smb_iconv_convenience *iconv_convenience,
213 const char *location,
215 struct hive_key **key);
219 /* Handles for the predefined keys */
220 #define HKEY_CLASSES_ROOT 0x80000000
221 #define HKEY_CURRENT_USER 0x80000001
222 #define HKEY_LOCAL_MACHINE 0x80000002
223 #define HKEY_USERS 0x80000003
224 #define HKEY_PERFORMANCE_DATA 0x80000004
225 #define HKEY_CURRENT_CONFIG 0x80000005
226 #define HKEY_DYN_DATA 0x80000006
227 #define HKEY_PERFORMANCE_TEXT 0x80000050
228 #define HKEY_PERFORMANCE_NLSTEXT 0x80000060
230 #define HKEY_FIRST HKEY_CLASSES_ROOT
231 #define HKEY_LAST HKEY_PERFORMANCE_NLSTEXT
233 struct reg_predefined_key {
238 extern const struct reg_predefined_key reg_predefined_keys[];
240 #define REG_DELETE -1
243 * The general idea here is that every backend provides a 'hive'. Combining
244 * various hives gives you a complete registry like windows has
247 #define REGISTRY_INTERFACE_VERSION 1
249 struct reg_key_operations;
251 /* structure to store the registry handles */
254 struct registry_context *context;
257 struct registry_value
260 unsigned int data_type;
265 typedef void (*reg_key_notification_function) (void);
266 typedef void (*reg_value_notification_function) (void);
268 struct cli_credentials;
270 struct registry_operations {
273 WERROR (*get_key_info) (TALLOC_CTX *mem_ctx,
274 const struct registry_key *key,
275 const char **classname,
276 uint32_t *numsubkeys,
278 NTTIME *last_change_time,
279 uint32_t *max_subkeynamelen,
280 uint32_t *max_valnamelen,
281 uint32_t *max_valbufsize);
283 WERROR (*flush_key) (struct registry_key *key);
285 WERROR (*get_predefined_key) (struct registry_context *ctx,
287 struct registry_key **key);
289 WERROR (*open_key) (TALLOC_CTX *mem_ctx,
290 struct registry_key *parent,
292 struct registry_key **key);
294 WERROR (*create_key) (TALLOC_CTX *mem_ctx,
295 struct registry_key *parent,
297 const char *key_class,
298 struct security_descriptor *security,
299 struct registry_key **key);
301 WERROR (*delete_key) (struct registry_key *key, const char *name);
303 WERROR (*delete_value) (struct registry_key *key, const char *name);
305 WERROR (*enum_key) (TALLOC_CTX *mem_ctx,
306 const struct registry_key *key, uint32_t idx,
308 const char **keyclass,
309 NTTIME *last_changed_time);
311 WERROR (*enum_value) (TALLOC_CTX *mem_ctx,
312 const struct registry_key *key, uint32_t idx,
317 WERROR (*get_security) (TALLOC_CTX *mem_ctx,
318 const struct registry_key *key,
319 struct security_descriptor **security);
321 WERROR (*set_security) (struct registry_key *key,
322 const struct security_descriptor *security);
324 WERROR (*load_key) (struct registry_key *key,
325 const char *key_name,
328 WERROR (*unload_key) (struct registry_key *key, const char *name);
330 WERROR (*notify_value_change) (struct registry_key *key,
331 reg_value_notification_function fn);
333 WERROR (*get_value) (TALLOC_CTX *mem_ctx,
334 const struct registry_key *key,
339 WERROR (*set_value) (struct registry_key *key,
342 const DATA_BLOB data);
346 * Handle to a full registry
347 * contains zero or more hives
349 struct registry_context {
350 const struct registry_operations *ops;
353 struct auth_session_info;
354 struct event_context;
355 struct loadparm_context;
358 * Open the locally defined registry.
360 WERROR reg_open_local(TALLOC_CTX *mem_ctx,
361 struct registry_context **ctx);
363 WERROR reg_open_samba(TALLOC_CTX *mem_ctx,
364 struct registry_context **ctx,
365 struct event_context *ev_ctx,
366 struct loadparm_context *lp_ctx,
367 struct auth_session_info *session_info,
368 struct cli_credentials *credentials);
371 * Open the registry on a remote machine.
373 WERROR reg_open_remote(struct registry_context **ctx,
374 struct auth_session_info *session_info,
375 struct cli_credentials *credentials,
376 struct loadparm_context *lp_ctx,
377 const char *location, struct event_context *ev);
379 WERROR reg_open_wine(struct registry_context **ctx, const char *path);
381 const char *reg_get_predef_name(uint32_t hkey);
382 WERROR reg_get_predefined_key_by_name(struct registry_context *ctx,
384 struct registry_key **key);
385 WERROR reg_get_predefined_key(struct registry_context *ctx,
387 struct registry_key **key);
389 WERROR reg_open_key(TALLOC_CTX *mem_ctx, struct registry_key *parent,
390 const char *name, struct registry_key **result);
392 WERROR reg_key_get_value_by_index(TALLOC_CTX *mem_ctx,
393 const struct registry_key *key, uint32_t idx,
397 WERROR reg_key_get_info(TALLOC_CTX *mem_ctx,
398 const struct registry_key *key,
399 const char **class_name,
400 uint32_t *num_subkeys,
401 uint32_t *num_values,
402 NTTIME *last_change_time,
403 uint32_t *max_subkeynamelen,
404 uint32_t *max_valnamelen,
405 uint32_t *max_valbufsize);
406 WERROR reg_key_get_subkey_by_index(TALLOC_CTX *mem_ctx,
407 const struct registry_key *key,
410 const char **classname,
411 NTTIME *last_mod_time);
412 WERROR reg_key_get_subkey_by_name(TALLOC_CTX *mem_ctx,
413 const struct registry_key *key,
415 struct registry_key **subkey);
416 WERROR reg_key_get_value_by_name(TALLOC_CTX *mem_ctx,
417 const struct registry_key *key,
421 WERROR reg_key_del(struct registry_key *parent, const char *name);
422 WERROR reg_key_add_name(TALLOC_CTX *mem_ctx,
423 struct registry_key *parent, const char *name,
424 const char *classname,
425 struct security_descriptor *desc,
426 struct registry_key **newkey);
427 WERROR reg_val_set(struct registry_key *key, const char *value,
428 uint32_t type, DATA_BLOB data);
429 WERROR reg_get_sec_desc(TALLOC_CTX *ctx, const struct registry_key *key,
430 struct security_descriptor **secdesc);
431 WERROR reg_del_value(struct registry_key *key, const char *valname);
432 WERROR reg_key_flush(struct registry_key *key);
433 WERROR reg_create_key(TALLOC_CTX *mem_ctx,
434 struct registry_key *parent,
436 const char *key_class,
437 struct security_descriptor *security,
438 struct registry_key **key);
440 /* Utility functions */
441 const char *str_regtype(int type);
442 char *reg_val_data_string(TALLOC_CTX *mem_ctx, struct smb_iconv_convenience *iconv_convenience, uint32_t type, const DATA_BLOB data);
443 char *reg_val_description(TALLOC_CTX *mem_ctx, struct smb_iconv_convenience *iconv_convenience, const char *name,
444 uint32_t type, const DATA_BLOB data);
445 bool reg_string_to_val(TALLOC_CTX *mem_ctx, struct smb_iconv_convenience *iconv_convenience, const char *type_str,
446 const char *data_str, uint32_t *type, DATA_BLOB *data);
447 WERROR reg_open_key_abs(TALLOC_CTX *mem_ctx, struct registry_context *handle,
448 const char *name, struct registry_key **result);
449 WERROR reg_key_del_abs(struct registry_context *ctx, const char *path);
450 WERROR reg_key_add_abs(TALLOC_CTX *mem_ctx, struct registry_context *ctx,
451 const char *path, uint32_t access_mask,
452 struct security_descriptor *sec_desc,
453 struct registry_key **result);
454 WERROR reg_load_key(struct registry_context *ctx, struct registry_key *key,
455 const char *name, const char *filename);
457 WERROR reg_mount_hive(struct registry_context *rctx,
458 struct hive_key *hive_key,
460 const char **elements);
462 struct registry_key *reg_import_hive_key(struct registry_context *ctx,
463 struct hive_key *hive,
465 const char **elements);
466 WERROR reg_get_security(TALLOC_CTX *mem_ctx,
467 const struct registry_key *key,
468 struct security_descriptor **security);
470 WERROR reg_set_security(struct registry_key *key,
471 struct security_descriptor *security);
473 struct reg_diff_callbacks {
474 WERROR (*add_key) (void *callback_data, const char *key_name);
475 WERROR (*set_value) (void *callback_data, const char *key_name,
476 const char *value_name, uint32_t value_type,
478 WERROR (*del_value) (void *callback_data, const char *key_name,
479 const char *value_name);
480 WERROR (*del_key) (void *callback_data, const char *key_name);
481 WERROR (*del_all_values) (void *callback_data, const char *key_name);
482 WERROR (*done) (void *callback_data);
485 WERROR reg_diff_apply(struct registry_context *ctx, const char *filename);
487 WERROR reg_generate_diff(struct registry_context *ctx1,
488 struct registry_context *ctx2,
489 const struct reg_diff_callbacks *callbacks,
490 void *callback_data);
491 WERROR reg_dotreg_diff_save(TALLOC_CTX *ctx, const char *filename,
492 struct smb_iconv_convenience *iconv_convenience,
493 struct reg_diff_callbacks **callbacks,
494 void **callback_data);
495 WERROR reg_generate_diff_key(struct registry_key *oldkey,
496 struct registry_key *newkey,
498 const struct reg_diff_callbacks *callbacks,
499 void *callback_data);
503 #endif /* _REGISTRY_H */