s4:libregistry - change counters to be "unsigned"
[Samba/nascimento.git] / source4 / lib / registry / registry.h
blobeeabaefb92ac0f279bb9b3e888fb8cdddfd6c8db
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 "../lib/util/time.h"
33 #include "../lib/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, 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) (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 tevent_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 tevent_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,
175 const char **name,
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,
187 const char **name,
188 uint32_t *type, DATA_BLOB *data);
189 WERROR hive_get_sec_desc(TALLOC_CTX *mem_ctx,
190 struct hive_key *key,
191 struct security_descriptor **security);
193 WERROR hive_set_sec_desc(struct hive_key *key,
194 const struct security_descriptor *security);
196 WERROR hive_key_del_value(struct hive_key *key, const char *name);
198 WERROR hive_key_flush(struct hive_key *key);
201 /* Individual backends */
202 WERROR reg_open_directory(TALLOC_CTX *parent_ctx,
203 const char *location, struct hive_key **key);
204 WERROR reg_open_regf_file(TALLOC_CTX *parent_ctx,
205 const char *location, struct smb_iconv_convenience *iconv_convenience,
206 struct hive_key **key);
207 WERROR reg_open_ldb_file(TALLOC_CTX *parent_ctx, const char *location,
208 struct auth_session_info *session_info,
209 struct cli_credentials *credentials,
210 struct tevent_context *ev_ctx,
211 struct loadparm_context *lp_ctx,
212 struct hive_key **k);
215 WERROR reg_create_directory(TALLOC_CTX *parent_ctx,
216 const char *location, struct hive_key **key);
217 WERROR reg_create_regf_file(TALLOC_CTX *parent_ctx,
218 struct smb_iconv_convenience *iconv_convenience,
219 const char *location,
220 int major_version,
221 struct hive_key **key);
225 /* Handles for the predefined keys */
226 #define HKEY_CLASSES_ROOT 0x80000000
227 #define HKEY_CURRENT_USER 0x80000001
228 #define HKEY_LOCAL_MACHINE 0x80000002
229 #define HKEY_USERS 0x80000003
230 #define HKEY_PERFORMANCE_DATA 0x80000004
231 #define HKEY_CURRENT_CONFIG 0x80000005
232 #define HKEY_DYN_DATA 0x80000006
233 #define HKEY_PERFORMANCE_TEXT 0x80000050
234 #define HKEY_PERFORMANCE_NLSTEXT 0x80000060
236 #define HKEY_FIRST HKEY_CLASSES_ROOT
237 #define HKEY_LAST HKEY_PERFORMANCE_NLSTEXT
239 struct reg_predefined_key {
240 uint32_t handle;
241 const char *name;
244 extern const struct reg_predefined_key reg_predefined_keys[];
246 #define REG_DELETE -1
249 * The general idea here is that every backend provides a 'hive'. Combining
250 * various hives gives you a complete registry like windows has
253 #define REGISTRY_INTERFACE_VERSION 1
255 struct reg_key_operations;
257 /* structure to store the registry handles */
258 struct registry_key
260 struct registry_context *context;
263 struct registry_value
265 const char *name;
266 unsigned int data_type;
267 DATA_BLOB data;
270 /* FIXME */
271 typedef void (*reg_key_notification_function) (void);
272 typedef void (*reg_value_notification_function) (void);
274 struct cli_credentials;
276 struct registry_operations {
277 const char *name;
279 WERROR (*get_key_info) (TALLOC_CTX *mem_ctx,
280 const struct registry_key *key,
281 const char **classname,
282 uint32_t *numsubkeys,
283 uint32_t *numvalues,
284 NTTIME *last_change_time,
285 uint32_t *max_subkeynamelen,
286 uint32_t *max_valnamelen,
287 uint32_t *max_valbufsize);
289 WERROR (*flush_key) (struct registry_key *key);
291 WERROR (*get_predefined_key) (struct registry_context *ctx,
292 uint32_t key_id,
293 struct registry_key **key);
295 WERROR (*open_key) (TALLOC_CTX *mem_ctx,
296 struct registry_key *parent,
297 const char *path,
298 struct registry_key **key);
300 WERROR (*create_key) (TALLOC_CTX *mem_ctx,
301 struct registry_key *parent,
302 const char *name,
303 const char *key_class,
304 struct security_descriptor *security,
305 struct registry_key **key);
307 WERROR (*delete_key) (struct registry_key *key, const char *name);
309 WERROR (*delete_value) (struct registry_key *key, const char *name);
311 WERROR (*enum_key) (TALLOC_CTX *mem_ctx,
312 const struct registry_key *key, uint32_t idx,
313 const char **name,
314 const char **keyclass,
315 NTTIME *last_changed_time);
317 WERROR (*enum_value) (TALLOC_CTX *mem_ctx,
318 const struct registry_key *key, uint32_t idx,
319 const char **name,
320 uint32_t *type,
321 DATA_BLOB *data);
323 WERROR (*get_sec_desc) (TALLOC_CTX *mem_ctx,
324 const struct registry_key *key,
325 struct security_descriptor **security);
327 WERROR (*set_sec_desc) (struct registry_key *key,
328 const struct security_descriptor *security);
330 WERROR (*load_key) (struct registry_key *key,
331 const char *key_name,
332 const char *path);
334 WERROR (*unload_key) (struct registry_key *key, const char *name);
336 WERROR (*notify_value_change) (struct registry_key *key,
337 reg_value_notification_function fn);
339 WERROR (*get_value) (TALLOC_CTX *mem_ctx,
340 const struct registry_key *key,
341 const char *name,
342 uint32_t *type,
343 DATA_BLOB *data);
345 WERROR (*set_value) (struct registry_key *key,
346 const char *name,
347 uint32_t type,
348 const DATA_BLOB data);
352 * Handle to a full registry
353 * contains zero or more hives
355 struct registry_context {
356 const struct registry_operations *ops;
359 struct auth_session_info;
360 struct tevent_context;
361 struct loadparm_context;
364 * Open the locally defined registry.
366 WERROR reg_open_local(TALLOC_CTX *mem_ctx,
367 struct registry_context **ctx);
369 WERROR reg_open_samba(TALLOC_CTX *mem_ctx,
370 struct registry_context **ctx,
371 struct tevent_context *ev_ctx,
372 struct loadparm_context *lp_ctx,
373 struct auth_session_info *session_info,
374 struct cli_credentials *credentials);
377 * Open the registry on a remote machine.
379 WERROR reg_open_remote(struct registry_context **ctx,
380 struct auth_session_info *session_info,
381 struct cli_credentials *credentials,
382 struct loadparm_context *lp_ctx,
383 const char *location, struct tevent_context *ev);
385 WERROR reg_open_wine(struct registry_context **ctx, const char *path);
387 const char *reg_get_predef_name(uint32_t hkey);
388 WERROR reg_get_predefined_key_by_name(struct registry_context *ctx,
389 const char *name,
390 struct registry_key **key);
391 WERROR reg_get_predefined_key(struct registry_context *ctx,
392 uint32_t hkey,
393 struct registry_key **key);
395 WERROR reg_open_key(TALLOC_CTX *mem_ctx, struct registry_key *parent,
396 const char *name, struct registry_key **result);
398 WERROR reg_key_get_value_by_index(TALLOC_CTX *mem_ctx,
399 const struct registry_key *key, uint32_t idx,
400 const char **name,
401 uint32_t *type,
402 DATA_BLOB *data);
403 WERROR reg_key_get_info(TALLOC_CTX *mem_ctx,
404 const struct registry_key *key,
405 const char **class_name,
406 uint32_t *num_subkeys,
407 uint32_t *num_values,
408 NTTIME *last_change_time,
409 uint32_t *max_subkeynamelen,
410 uint32_t *max_valnamelen,
411 uint32_t *max_valbufsize);
412 WERROR reg_key_get_subkey_by_index(TALLOC_CTX *mem_ctx,
413 const struct registry_key *key,
414 uint32_t idx,
415 const char **name,
416 const char **classname,
417 NTTIME *last_mod_time);
418 WERROR reg_key_get_subkey_by_name(TALLOC_CTX *mem_ctx,
419 const struct registry_key *key,
420 const char *name,
421 struct registry_key **subkey);
422 WERROR reg_key_get_value_by_name(TALLOC_CTX *mem_ctx,
423 const struct registry_key *key,
424 const char *name,
425 uint32_t *type,
426 DATA_BLOB *data);
427 WERROR reg_key_del(struct registry_key *parent, const char *name);
428 WERROR reg_key_add_name(TALLOC_CTX *mem_ctx,
429 struct registry_key *parent, const char *name,
430 const char *classname,
431 struct security_descriptor *desc,
432 struct registry_key **newkey);
433 WERROR reg_val_set(struct registry_key *key, const char *value,
434 uint32_t type, DATA_BLOB data);
435 WERROR reg_get_sec_desc(TALLOC_CTX *ctx, const struct registry_key *key,
436 struct security_descriptor **secdesc);
437 WERROR reg_del_value(struct registry_key *key, const char *valname);
438 WERROR reg_key_flush(struct registry_key *key);
439 WERROR reg_create_key(TALLOC_CTX *mem_ctx,
440 struct registry_key *parent,
441 const char *name,
442 const char *key_class,
443 struct security_descriptor *security,
444 struct registry_key **key);
446 /* Utility functions */
447 const char *str_regtype(int type);
448 char *reg_val_data_string(TALLOC_CTX *mem_ctx, struct smb_iconv_convenience *iconv_convenience, uint32_t type, const DATA_BLOB data);
449 char *reg_val_description(TALLOC_CTX *mem_ctx, struct smb_iconv_convenience *iconv_convenience, const char *name,
450 uint32_t type, const DATA_BLOB data);
451 bool reg_string_to_val(TALLOC_CTX *mem_ctx, struct smb_iconv_convenience *iconv_convenience, const char *type_str,
452 const char *data_str, uint32_t *type, DATA_BLOB *data);
453 WERROR reg_open_key_abs(TALLOC_CTX *mem_ctx, struct registry_context *handle,
454 const char *name, struct registry_key **result);
455 WERROR reg_key_del_abs(struct registry_context *ctx, const char *path);
456 WERROR reg_key_add_abs(TALLOC_CTX *mem_ctx, struct registry_context *ctx,
457 const char *path, uint32_t access_mask,
458 struct security_descriptor *sec_desc,
459 struct registry_key **result);
460 WERROR reg_load_key(struct registry_context *ctx, struct registry_key *key,
461 const char *name, const char *filename);
463 WERROR reg_mount_hive(struct registry_context *rctx,
464 struct hive_key *hive_key,
465 uint32_t key_id,
466 const char **elements);
468 struct registry_key *reg_import_hive_key(struct registry_context *ctx,
469 struct hive_key *hive,
470 uint32_t predef_key,
471 const char **elements);
472 WERROR reg_set_sec_desc(struct registry_key *key,
473 const struct security_descriptor *security);
475 struct reg_diff_callbacks {
476 WERROR (*add_key) (void *callback_data, const char *key_name);
477 WERROR (*set_value) (void *callback_data, const char *key_name,
478 const char *value_name, uint32_t value_type,
479 DATA_BLOB value);
480 WERROR (*del_value) (void *callback_data, const char *key_name,
481 const char *value_name);
482 WERROR (*del_key) (void *callback_data, const char *key_name);
483 WERROR (*del_all_values) (void *callback_data, const char *key_name);
484 WERROR (*done) (void *callback_data);
487 WERROR reg_diff_apply(struct registry_context *ctx,
488 struct smb_iconv_convenience *ic, const char *filename);
490 WERROR reg_generate_diff(struct registry_context *ctx1,
491 struct registry_context *ctx2,
492 const struct reg_diff_callbacks *callbacks,
493 void *callback_data);
494 WERROR reg_dotreg_diff_save(TALLOC_CTX *ctx, const char *filename,
495 struct smb_iconv_convenience *iconv_convenience,
496 struct reg_diff_callbacks **callbacks,
497 void **callback_data);
498 WERROR reg_preg_diff_save(TALLOC_CTX *ctx, const char *filename,
499 struct smb_iconv_convenience *ic,
500 struct reg_diff_callbacks **callbacks,
501 void **callback_data);
502 WERROR reg_generate_diff_key(struct registry_key *oldkey,
503 struct registry_key *newkey,
504 const char *path,
505 const struct reg_diff_callbacks *callbacks,
506 void *callback_data);
507 WERROR reg_diff_load(const char *filename,
508 struct smb_iconv_convenience *iconv_convenience,
509 const struct reg_diff_callbacks *callbacks,
510 void *callback_data);
512 WERROR reg_dotreg_diff_load(int fd,
513 struct smb_iconv_convenience *iconv_convenience,
514 const struct reg_diff_callbacks *callbacks,
515 void *callback_data);
517 WERROR reg_preg_diff_load(int fd,
518 struct smb_iconv_convenience *iconv_convenience,
519 const struct reg_diff_callbacks *callbacks,
520 void *callback_data);
522 WERROR local_get_predefined_key(struct registry_context *ctx,
523 uint32_t key_id, struct registry_key **key);
526 #endif /* _REGISTRY_H */