ldb: bump version due to header and internal implementation changes
[Samba.git] / source4 / lib / registry / registry.h
blob8a8271e3c9e1e0f03c726c30ff4de32e6eae9a6a
1 /*
2 Unix SMB/CIFS implementation.
3 Registry interface
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 */
22 #define _REGISTRY_H
24 struct registry_context;
25 struct loadparm_context;
27 #include <talloc.h>
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"
34 /**
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.
45 struct hive_key {
46 const struct hive_operations *ops;
49 struct hive_operations {
50 const char *name;
52 /**
53 * Open a specific subkey
55 WERROR (*enum_key) (TALLOC_CTX *mem_ctx,
56 const struct hive_key *key, uint32_t idx,
57 const char **name,
58 const char **classname,
59 NTTIME *last_mod_time);
61 /**
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);
68 /**
69 * Add a new key.
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);
76 /**
77 * Remove an existing key.
79 WERROR (*del_key) (TALLOC_CTX *mem_ctx,
80 const struct hive_key *key, const char *name);
82 /**
83 * Force write of a key to disk.
85 WERROR (*flush_key) (struct hive_key *key);
87 /**
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,
93 DATA_BLOB *data);
95 /**
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);
109 * Remove a value.
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,
177 const char **name,
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,
189 const char **name,
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,
221 int major_version,
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 {
241 uint32_t handle;
242 const char *name;
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 */
259 struct registry_key
261 struct registry_context *context;
264 struct registry_value
266 const char *name;
267 unsigned int data_type;
268 DATA_BLOB data;
271 /* FIXME */
272 typedef void (*reg_key_notification_function) (void);
273 typedef void (*reg_value_notification_function) (void);
275 struct cli_credentials;
277 struct registry_operations {
278 const char *name;
280 WERROR (*get_key_info) (TALLOC_CTX *mem_ctx,
281 const struct registry_key *key,
282 const char **classname,
283 uint32_t *numsubkeys,
284 uint32_t *numvalues,
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,
293 uint32_t key_id,
294 struct registry_key **key);
296 WERROR (*open_key) (TALLOC_CTX *mem_ctx,
297 struct registry_key *parent,
298 const char *path,
299 struct registry_key **key);
301 WERROR (*create_key) (TALLOC_CTX *mem_ctx,
302 struct registry_key *parent,
303 const char *name,
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,
316 const char **name,
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,
322 const char **name,
323 uint32_t *type,
324 DATA_BLOB *data);
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,
335 const char *path);
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,
344 const char *name,
345 uint32_t *type,
346 DATA_BLOB *data);
348 WERROR (*set_value) (struct registry_key *key,
349 const char *name,
350 uint32_t type,
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(struct registry_context **ctx,
383 struct auth_session_info *session_info,
384 struct cli_credentials *credentials,
385 struct loadparm_context *lp_ctx,
386 const char *location, struct tevent_context *ev);
388 WERROR reg_open_wine(struct registry_context **ctx, const char *path);
390 const char *reg_get_predef_name(uint32_t hkey);
391 WERROR reg_get_predefined_key_by_name(struct registry_context *ctx,
392 const char *name,
393 struct registry_key **key);
394 WERROR reg_get_predefined_key(struct registry_context *ctx,
395 uint32_t hkey,
396 struct registry_key **key);
398 WERROR reg_open_key(TALLOC_CTX *mem_ctx, struct registry_key *parent,
399 const char *name, struct registry_key **result);
401 WERROR reg_key_get_value_by_index(TALLOC_CTX *mem_ctx,
402 const struct registry_key *key, uint32_t idx,
403 const char **name,
404 uint32_t *type,
405 DATA_BLOB *data);
406 WERROR reg_key_get_info(TALLOC_CTX *mem_ctx,
407 const struct registry_key *key,
408 const char **class_name,
409 uint32_t *num_subkeys,
410 uint32_t *num_values,
411 NTTIME *last_change_time,
412 uint32_t *max_subkeynamelen,
413 uint32_t *max_valnamelen,
414 uint32_t *max_valbufsize);
415 WERROR reg_key_get_subkey_by_index(TALLOC_CTX *mem_ctx,
416 const struct registry_key *key,
417 uint32_t idx,
418 const char **name,
419 const char **classname,
420 NTTIME *last_mod_time);
421 WERROR reg_key_get_subkey_by_name(TALLOC_CTX *mem_ctx,
422 const struct registry_key *key,
423 const char *name,
424 struct registry_key **subkey);
425 WERROR reg_key_get_value_by_name(TALLOC_CTX *mem_ctx,
426 const struct registry_key *key,
427 const char *name,
428 uint32_t *type,
429 DATA_BLOB *data);
430 WERROR reg_key_del(TALLOC_CTX *mem_ctx,
431 struct registry_key *parent, const char *name);
432 WERROR reg_key_add_name(TALLOC_CTX *mem_ctx,
433 struct registry_key *parent, const char *name,
434 const char *classname,
435 struct security_descriptor *desc,
436 struct registry_key **newkey);
437 WERROR reg_val_set(struct registry_key *key, const char *value,
438 uint32_t type, DATA_BLOB data);
439 WERROR reg_get_sec_desc(TALLOC_CTX *ctx, const struct registry_key *key,
440 struct security_descriptor **secdesc);
441 WERROR reg_del_value(TALLOC_CTX *mem_ctx,
442 struct registry_key *key, const char *valname);
443 WERROR reg_key_flush(struct registry_key *key);
444 WERROR reg_create_key(TALLOC_CTX *mem_ctx,
445 struct registry_key *parent,
446 const char *name,
447 const char *key_class,
448 struct security_descriptor *security,
449 struct registry_key **key);
451 /* Utility functions */
452 const char *str_regtype(int type);
453 bool push_reg_sz(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, const char *s);
454 bool push_reg_multi_sz(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, const char **a);
455 bool pull_reg_sz(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob, const char **s);
456 bool pull_reg_multi_sz(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob, const char ***a);
457 int regtype_by_string(const char *str);
458 char *reg_val_data_string(TALLOC_CTX *mem_ctx, uint32_t type, const DATA_BLOB data);
459 char *reg_val_description(TALLOC_CTX *mem_ctx, const char *name,
460 uint32_t type, const DATA_BLOB data);
461 bool reg_string_to_val(TALLOC_CTX *mem_ctx, const char *type_str,
462 const char *data_str, uint32_t *type, DATA_BLOB *data);
463 WERROR reg_open_key_abs(TALLOC_CTX *mem_ctx, struct registry_context *handle,
464 const char *name, struct registry_key **result);
465 WERROR reg_key_del_abs(struct registry_context *ctx, const char *path);
466 WERROR reg_key_add_abs(TALLOC_CTX *mem_ctx, struct registry_context *ctx,
467 const char *path, uint32_t access_mask,
468 struct security_descriptor *sec_desc,
469 struct registry_key **result);
470 WERROR reg_load_key(struct registry_context *ctx, struct registry_key *key,
471 const char *name, const char *filename);
473 WERROR reg_mount_hive(struct registry_context *rctx,
474 struct hive_key *hive_key,
475 uint32_t key_id,
476 const char **elements);
478 struct registry_key *reg_import_hive_key(struct registry_context *ctx,
479 struct hive_key *hive,
480 uint32_t predef_key,
481 const char **elements);
482 WERROR reg_set_sec_desc(struct registry_key *key,
483 const struct security_descriptor *security);
485 struct reg_diff_callbacks {
486 WERROR (*add_key) (void *callback_data, const char *key_name);
487 WERROR (*set_value) (void *callback_data, const char *key_name,
488 const char *value_name, uint32_t value_type,
489 DATA_BLOB value);
490 WERROR (*del_value) (void *callback_data, const char *key_name,
491 const char *value_name);
492 WERROR (*del_key) (void *callback_data, const char *key_name);
493 WERROR (*del_all_values) (void *callback_data, const char *key_name);
494 WERROR (*done) (void *callback_data);
497 WERROR reg_diff_apply(struct registry_context *ctx,
498 const char *filename);
500 WERROR reg_generate_diff(struct registry_context *ctx1,
501 struct registry_context *ctx2,
502 const struct reg_diff_callbacks *callbacks,
503 void *callback_data);
504 WERROR reg_dotreg_diff_save(TALLOC_CTX *ctx, const char *filename,
505 struct reg_diff_callbacks **callbacks,
506 void **callback_data);
507 WERROR reg_preg_diff_save(TALLOC_CTX *ctx, const char *filename,
508 struct reg_diff_callbacks **callbacks,
509 void **callback_data);
510 WERROR reg_generate_diff_key(struct registry_key *oldkey,
511 struct registry_key *newkey,
512 const char *path,
513 const struct reg_diff_callbacks *callbacks,
514 void *callback_data);
515 WERROR reg_diff_load(const char *filename,
516 const struct reg_diff_callbacks *callbacks,
517 void *callback_data);
519 WERROR reg_dotreg_diff_load(int fd,
520 const struct reg_diff_callbacks *callbacks,
521 void *callback_data);
523 WERROR reg_preg_diff_load(int fd,
524 const struct reg_diff_callbacks *callbacks,
525 void *callback_data);
527 WERROR local_get_predefined_key(struct registry_context *ctx,
528 uint32_t key_id, struct registry_key **key);
531 #endif /* _REGISTRY_H */