Fix PReg write support.
[Samba.git] / source4 / lib / registry / registry.h
blob6a98a6063362fdb9cad801ed0c485f59333e9bfb
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;
26 struct smb_iconv_convenience;
28 #include <talloc.h>
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"
35 /**
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.
46 struct hive_key {
47 const struct hive_operations *ops;
50 struct hive_operations {
51 const char *name;
53 /**
54 * Open a specific subkey
56 WERROR (*enum_key) (TALLOC_CTX *mem_ctx,
57 const struct hive_key *key, uint32_t idx,
58 const char **name,
59 const char **classname,
60 NTTIME *last_mod_time);
62 /**
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);
69 /**
70 * Add a new key.
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);
77 /**
78 * Remove an existing key.
80 WERROR (*del_key) (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, int 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) (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;
153 WERROR reg_open_hive(TALLOC_CTX *parent_ctx, const char *location,
154 struct auth_session_info *session_info,
155 struct cli_credentials *credentials,
156 struct loadparm_context *lp_ctx,
157 struct hive_key **root);
158 WERROR hive_key_get_info(TALLOC_CTX *mem_ctx, const struct hive_key *key,
159 const char **classname, uint32_t *num_subkeys,
160 uint32_t *num_values, NTTIME *last_change_time,
161 uint32_t *max_subkeynamelen,
162 uint32_t *max_valnamelen, uint32_t *max_valbufsize);
163 WERROR hive_key_add_name(TALLOC_CTX *ctx, const struct hive_key *parent_key,
164 const char *name, const char *classname,
165 struct security_descriptor *desc,
166 struct hive_key **key);
167 WERROR hive_key_del(const struct hive_key *key, const char *name);
168 WERROR hive_get_key_by_name(TALLOC_CTX *mem_ctx,
169 const struct hive_key *key, const char *name,
170 struct hive_key **subkey);
171 WERROR hive_enum_key(TALLOC_CTX *mem_ctx,
172 const struct hive_key *key, uint32_t idx,
173 const char **name,
174 const char **classname,
175 NTTIME *last_mod_time);
177 WERROR hive_key_set_value(struct hive_key *key, const char *name,
178 uint32_t type, const DATA_BLOB data);
180 WERROR hive_get_value(TALLOC_CTX *mem_ctx,
181 struct hive_key *key, const char *name,
182 uint32_t *type, DATA_BLOB *data);
183 WERROR hive_get_value_by_index(TALLOC_CTX *mem_ctx,
184 struct hive_key *key, uint32_t idx,
185 const char **name,
186 uint32_t *type, DATA_BLOB *data);
187 WERROR hive_get_sec_desc(TALLOC_CTX *mem_ctx,
188 struct hive_key *key,
189 struct security_descriptor **security);
191 WERROR hive_set_sec_desc(struct hive_key *key,
192 const struct security_descriptor *security);
194 WERROR hive_key_del_value(struct hive_key *key, const char *name);
196 WERROR hive_key_flush(struct hive_key *key);
199 /* Individual backends */
200 WERROR reg_open_directory(TALLOC_CTX *parent_ctx,
201 const char *location, struct hive_key **key);
202 WERROR reg_open_regf_file(TALLOC_CTX *parent_ctx,
203 const char *location, struct smb_iconv_convenience *iconv_convenience,
204 struct hive_key **key);
205 WERROR reg_open_ldb_file(TALLOC_CTX *parent_ctx, const char *location,
206 struct auth_session_info *session_info,
207 struct cli_credentials *credentials,
208 struct loadparm_context *lp_ctx,
209 struct hive_key **k);
212 WERROR reg_create_directory(TALLOC_CTX *parent_ctx,
213 const char *location, struct hive_key **key);
214 WERROR reg_create_regf_file(TALLOC_CTX *parent_ctx,
215 struct smb_iconv_convenience *iconv_convenience,
216 const char *location,
217 int major_version,
218 struct hive_key **key);
222 /* Handles for the predefined keys */
223 #define HKEY_CLASSES_ROOT 0x80000000
224 #define HKEY_CURRENT_USER 0x80000001
225 #define HKEY_LOCAL_MACHINE 0x80000002
226 #define HKEY_USERS 0x80000003
227 #define HKEY_PERFORMANCE_DATA 0x80000004
228 #define HKEY_CURRENT_CONFIG 0x80000005
229 #define HKEY_DYN_DATA 0x80000006
230 #define HKEY_PERFORMANCE_TEXT 0x80000050
231 #define HKEY_PERFORMANCE_NLSTEXT 0x80000060
233 #define HKEY_FIRST HKEY_CLASSES_ROOT
234 #define HKEY_LAST HKEY_PERFORMANCE_NLSTEXT
236 struct reg_predefined_key {
237 uint32_t handle;
238 const char *name;
241 extern const struct reg_predefined_key reg_predefined_keys[];
243 #define REG_DELETE -1
246 * The general idea here is that every backend provides a 'hive'. Combining
247 * various hives gives you a complete registry like windows has
250 #define REGISTRY_INTERFACE_VERSION 1
252 struct reg_key_operations;
254 /* structure to store the registry handles */
255 struct registry_key
257 struct registry_context *context;
260 struct registry_value
262 const char *name;
263 unsigned int data_type;
264 DATA_BLOB data;
267 /* FIXME */
268 typedef void (*reg_key_notification_function) (void);
269 typedef void (*reg_value_notification_function) (void);
271 struct cli_credentials;
273 struct registry_operations {
274 const char *name;
276 WERROR (*get_key_info) (TALLOC_CTX *mem_ctx,
277 const struct registry_key *key,
278 const char **classname,
279 uint32_t *numsubkeys,
280 uint32_t *numvalues,
281 NTTIME *last_change_time,
282 uint32_t *max_subkeynamelen,
283 uint32_t *max_valnamelen,
284 uint32_t *max_valbufsize);
286 WERROR (*flush_key) (struct registry_key *key);
288 WERROR (*get_predefined_key) (struct registry_context *ctx,
289 uint32_t key_id,
290 struct registry_key **key);
292 WERROR (*open_key) (TALLOC_CTX *mem_ctx,
293 struct registry_key *parent,
294 const char *path,
295 struct registry_key **key);
297 WERROR (*create_key) (TALLOC_CTX *mem_ctx,
298 struct registry_key *parent,
299 const char *name,
300 const char *key_class,
301 struct security_descriptor *security,
302 struct registry_key **key);
304 WERROR (*delete_key) (struct registry_key *key, const char *name);
306 WERROR (*delete_value) (struct registry_key *key, const char *name);
308 WERROR (*enum_key) (TALLOC_CTX *mem_ctx,
309 const struct registry_key *key, uint32_t idx,
310 const char **name,
311 const char **keyclass,
312 NTTIME *last_changed_time);
314 WERROR (*enum_value) (TALLOC_CTX *mem_ctx,
315 const struct registry_key *key, uint32_t idx,
316 const char **name,
317 uint32_t *type,
318 DATA_BLOB *data);
320 WERROR (*get_sec_desc) (TALLOC_CTX *mem_ctx,
321 const struct registry_key *key,
322 struct security_descriptor **security);
324 WERROR (*set_sec_desc) (struct registry_key *key,
325 const struct security_descriptor *security);
327 WERROR (*load_key) (struct registry_key *key,
328 const char *key_name,
329 const char *path);
331 WERROR (*unload_key) (struct registry_key *key, const char *name);
333 WERROR (*notify_value_change) (struct registry_key *key,
334 reg_value_notification_function fn);
336 WERROR (*get_value) (TALLOC_CTX *mem_ctx,
337 const struct registry_key *key,
338 const char *name,
339 uint32_t *type,
340 DATA_BLOB *data);
342 WERROR (*set_value) (struct registry_key *key,
343 const char *name,
344 uint32_t type,
345 const DATA_BLOB data);
349 * Handle to a full registry
350 * contains zero or more hives
352 struct registry_context {
353 const struct registry_operations *ops;
356 struct auth_session_info;
357 struct event_context;
358 struct loadparm_context;
361 * Open the locally defined registry.
363 WERROR reg_open_local(TALLOC_CTX *mem_ctx,
364 struct registry_context **ctx,
365 struct auth_session_info *session_info,
366 struct cli_credentials *credentials);
368 WERROR reg_open_samba(TALLOC_CTX *mem_ctx,
369 struct registry_context **ctx,
370 struct loadparm_context *lp_ctx,
371 struct auth_session_info *session_info,
372 struct cli_credentials *credentials);
375 * Open the registry on a remote machine.
377 WERROR reg_open_remote(struct registry_context **ctx,
378 struct auth_session_info *session_info,
379 struct cli_credentials *credentials,
380 struct loadparm_context *lp_ctx,
381 const char *location, struct event_context *ev);
383 WERROR reg_open_wine(struct registry_context **ctx, const char *path);
385 const char *reg_get_predef_name(uint32_t hkey);
386 WERROR reg_get_predefined_key_by_name(struct registry_context *ctx,
387 const char *name,
388 struct registry_key **key);
389 WERROR reg_get_predefined_key(struct registry_context *ctx,
390 uint32_t hkey,
391 struct registry_key **key);
393 WERROR reg_open_key(TALLOC_CTX *mem_ctx, struct registry_key *parent,
394 const char *name, struct registry_key **result);
396 WERROR reg_key_get_value_by_index(TALLOC_CTX *mem_ctx,
397 const struct registry_key *key, uint32_t idx,
398 const char **name,
399 uint32_t *type,
400 DATA_BLOB *data);
401 WERROR reg_key_get_info(TALLOC_CTX *mem_ctx,
402 const struct registry_key *key,
403 const char **class_name,
404 uint32_t *num_subkeys,
405 uint32_t *num_values,
406 NTTIME *last_change_time,
407 uint32_t *max_subkeynamelen,
408 uint32_t *max_valnamelen,
409 uint32_t *max_valbufsize);
410 WERROR reg_key_get_subkey_by_index(TALLOC_CTX *mem_ctx,
411 const struct registry_key *key,
412 int idx,
413 const char **name,
414 const char **classname,
415 NTTIME *last_mod_time);
416 WERROR reg_key_get_subkey_by_name(TALLOC_CTX *mem_ctx,
417 const struct registry_key *key,
418 const char *name,
419 struct registry_key **subkey);
420 WERROR reg_key_get_value_by_name(TALLOC_CTX *mem_ctx,
421 const struct registry_key *key,
422 const char *name,
423 uint32_t *type,
424 DATA_BLOB *data);
425 WERROR reg_key_del(struct registry_key *parent, const char *name);
426 WERROR reg_key_add_name(TALLOC_CTX *mem_ctx,
427 struct registry_key *parent, const char *name,
428 const char *classname,
429 struct security_descriptor *desc,
430 struct registry_key **newkey);
431 WERROR reg_val_set(struct registry_key *key, const char *value,
432 uint32_t type, DATA_BLOB data);
433 WERROR reg_get_sec_desc(TALLOC_CTX *ctx, const struct registry_key *key,
434 struct security_descriptor **secdesc);
435 WERROR reg_del_value(struct registry_key *key, const char *valname);
436 WERROR reg_key_flush(struct registry_key *key);
437 WERROR reg_create_key(TALLOC_CTX *mem_ctx,
438 struct registry_key *parent,
439 const char *name,
440 const char *key_class,
441 struct security_descriptor *security,
442 struct registry_key **key);
444 /* Utility functions */
445 const char *str_regtype(int type);
446 char *reg_val_data_string(TALLOC_CTX *mem_ctx, struct smb_iconv_convenience *iconv_convenience, uint32_t type, const DATA_BLOB data);
447 char *reg_val_description(TALLOC_CTX *mem_ctx, struct smb_iconv_convenience *iconv_convenience, const char *name,
448 uint32_t type, const DATA_BLOB data);
449 bool reg_string_to_val(TALLOC_CTX *mem_ctx, struct smb_iconv_convenience *iconv_convenience, const char *type_str,
450 const char *data_str, uint32_t *type, DATA_BLOB *data);
451 WERROR reg_open_key_abs(TALLOC_CTX *mem_ctx, struct registry_context *handle,
452 const char *name, struct registry_key **result);
453 WERROR reg_key_del_abs(struct registry_context *ctx, const char *path);
454 WERROR reg_key_add_abs(TALLOC_CTX *mem_ctx, struct registry_context *ctx,
455 const char *path, uint32_t access_mask,
456 struct security_descriptor *sec_desc,
457 struct registry_key **result);
458 WERROR reg_load_key(struct registry_context *ctx, struct registry_key *key,
459 const char *name, const char *filename);
461 WERROR reg_mount_hive(struct registry_context *rctx,
462 struct hive_key *hive_key,
463 uint32_t key_id,
464 const char **elements);
466 struct registry_key *reg_import_hive_key(struct registry_context *ctx,
467 struct hive_key *hive,
468 uint32_t predef_key,
469 const char **elements);
470 WERROR reg_set_sec_desc(struct registry_key *key,
471 const 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,
477 DATA_BLOB value);
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_preg_diff_save(TALLOC_CTX *ctx, const char *filename,
496 struct smb_iconv_convenience *ic,
497 struct reg_diff_callbacks **callbacks,
498 void **callback_data);
499 WERROR reg_generate_diff_key(struct registry_key *oldkey,
500 struct registry_key *newkey,
501 const char *path,
502 const struct reg_diff_callbacks *callbacks,
503 void *callback_data);
504 WERROR reg_diff_load(const char *filename,
505 struct smb_iconv_convenience *iconv_convenience,
506 const struct reg_diff_callbacks *callbacks,
507 void *callback_data);
511 #endif /* _REGISTRY_H */