source: trunk/server/source4/lib/registry/registry.h

Last change on this file was 745, checked in by Silvan Scherrer, 13 years ago

Samba Server: updated trunk to 3.6.0

File size: 17.0 KB
Line 
1/*
2 Unix SMB/CIFS implementation.
3 Registry interface
4 Copyright (C) Gerald Carter 2002.
5 Copyright (C) Jelmer Vernooij 2003-2007.
6
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.
11
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.
16
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/>.
19*/
20
21#ifndef _REGISTRY_H /* _REGISTRY_H */
22#define _REGISTRY_H
23
24struct registry_context;
25struct loadparm_context;
26
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"
33
34/**
35 * The hive API. This API is generally used for
36 * reading a specific file that contains just one hive.
37 *
38 * Good examples are .DAT (NTUSER.DAT) files.
39 *
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.
43 */
44
45struct hive_key {
46 const struct hive_operations *ops;
47};
48
49struct hive_operations {
50 const char *name;
51
52 /**
53 * Open a specific subkey
54 */
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);
60
61 /**
62 * Open a subkey by name
63 */
64 WERROR (*get_key_by_name) (TALLOC_CTX *mem_ctx,
65 const struct hive_key *key, const char *name,
66 struct hive_key **subkey);
67
68 /**
69 * Add a new key.
70 */
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.
78 */
79 WERROR (*del_key) (TALLOC_CTX *mem_ctx,
80 const struct hive_key *key, const char *name);
81
82 /**
83 * Force write of a key to disk.
84 */
85 WERROR (*flush_key) (struct hive_key *key);
86
87 /**
88 * Retrieve a registry value with a specific index.
89 */
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);
94
95 /**
96 * Retrieve a registry value with the specified name
97 */
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);
101
102 /**
103 * Set a value on the specified registry key.
104 */
105 WERROR (*set_value) (struct hive_key *key, const char *name,
106 uint32_t type, const DATA_BLOB data);
107
108 /**
109 * Remove a value.
110 */
111 WERROR (*delete_value) (TALLOC_CTX *mem_ctx,
112 struct hive_key *key, const char *name);
113
114 /* Security Descriptors */
115
116 /**
117 * Change the security descriptor on a registry key.
118 *
119 * This should return WERR_NOT_SUPPORTED if the underlying
120 * format does not have a mechanism for storing
121 * security descriptors.
122 */
123 WERROR (*set_sec_desc) (struct hive_key *key,
124 const struct security_descriptor *desc);
125
126 /**
127 * Retrieve the security descriptor on a registry key.
128 *
129 * This should return WERR_NOT_SUPPORTED if the underlying
130 * format does not have a mechanism for storing
131 * security descriptors.
132 */
133 WERROR (*get_sec_desc) (TALLOC_CTX *ctx,
134 const struct hive_key *key,
135 struct security_descriptor **desc);
136
137 /**
138 * Retrieve general information about a key.
139 */
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);
149};
150
151struct cli_credentials;
152struct auth_session_info;
153struct tevent_context;
154
155WERROR 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);
161WERROR 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);
166WERROR 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);
170WERROR hive_key_del(TALLOC_CTX *mem_ctx,
171 const struct hive_key *key, const char *name);
172WERROR hive_get_key_by_name(TALLOC_CTX *mem_ctx,
173 const struct hive_key *key, const char *name,
174 struct hive_key **subkey);
175WERROR 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);
180
181WERROR hive_key_set_value(struct hive_key *key, const char *name,
182 uint32_t type, const DATA_BLOB data);
183
184WERROR hive_get_value(TALLOC_CTX *mem_ctx,
185 struct hive_key *key, const char *name,
186 uint32_t *type, DATA_BLOB *data);
187WERROR 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);
191WERROR hive_get_sec_desc(TALLOC_CTX *mem_ctx,
192 struct hive_key *key,
193 struct security_descriptor **security);
194
195WERROR hive_set_sec_desc(struct hive_key *key,
196 const struct security_descriptor *security);
197
198WERROR hive_key_del_value(TALLOC_CTX *mem_ctx,
199 struct hive_key *key, const char *name);
200
201WERROR hive_key_flush(struct hive_key *key);
202
203
204/* Individual backends */
205WERROR reg_open_directory(TALLOC_CTX *parent_ctx,
206 const char *location, struct hive_key **key);
207WERROR reg_open_regf_file(TALLOC_CTX *parent_ctx,
208 const char *location, struct hive_key **key);
209WERROR 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);
215
216
217WERROR reg_create_directory(TALLOC_CTX *parent_ctx,
218 const char *location, struct hive_key **key);
219WERROR reg_create_regf_file(TALLOC_CTX *parent_ctx,
220 const char *location,
221 int major_version,
222 struct hive_key **key);
223
224
225
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
236
237#define HKEY_FIRST HKEY_CLASSES_ROOT
238#define HKEY_LAST HKEY_PERFORMANCE_NLSTEXT
239
240struct reg_predefined_key {
241 uint32_t handle;
242 const char *name;
243};
244
245extern const struct reg_predefined_key reg_predefined_keys[];
246
247#define REG_DELETE -1
248
249/*
250 * The general idea here is that every backend provides a 'hive'. Combining
251 * various hives gives you a complete registry like windows has
252 */
253
254#define REGISTRY_INTERFACE_VERSION 1
255
256struct reg_key_operations;
257
258/* structure to store the registry handles */
259struct registry_key
260{
261 struct registry_context *context;
262};
263
264struct registry_value
265{
266 const char *name;
267 unsigned int data_type;
268 DATA_BLOB data;
269};
270
271/* FIXME */
272typedef void (*reg_key_notification_function) (void);
273typedef void (*reg_value_notification_function) (void);
274
275struct cli_credentials;
276
277struct registry_operations {
278 const char *name;
279
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);
289
290 WERROR (*flush_key) (struct registry_key *key);
291
292 WERROR (*get_predefined_key) (struct registry_context *ctx,
293 uint32_t key_id,
294 struct registry_key **key);
295
296 WERROR (*open_key) (TALLOC_CTX *mem_ctx,
297 struct registry_key *parent,
298 const char *path,
299 struct registry_key **key);
300
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);
307
308 WERROR (*delete_key) (TALLOC_CTX *mem_ctx,
309 struct registry_key *key, const char *name);
310
311 WERROR (*delete_value) (TALLOC_CTX *mem_ctx,
312 struct registry_key *key, const char *name);
313
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);
319
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);
325
326 WERROR (*get_sec_desc) (TALLOC_CTX *mem_ctx,
327 const struct registry_key *key,
328 struct security_descriptor **security);
329
330 WERROR (*set_sec_desc) (struct registry_key *key,
331 const struct security_descriptor *security);
332
333 WERROR (*load_key) (struct registry_key *key,
334 const char *key_name,
335 const char *path);
336
337 WERROR (*unload_key) (struct registry_key *key, const char *name);
338
339 WERROR (*notify_value_change) (struct registry_key *key,
340 reg_value_notification_function fn);
341
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);
347
348 WERROR (*set_value) (struct registry_key *key,
349 const char *name,
350 uint32_t type,
351 const DATA_BLOB data);
352};
353
354/**
355 * Handle to a full registry
356 * contains zero or more hives
357 */
358struct registry_context {
359 const struct registry_operations *ops;
360};
361
362struct auth_session_info;
363struct tevent_context;
364struct loadparm_context;
365
366/**
367 * Open the locally defined registry.
368 */
369WERROR reg_open_local(TALLOC_CTX *mem_ctx,
370 struct registry_context **ctx);
371
372WERROR 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);
378
379/**
380 * Open the registry on a remote machine.
381 */
382WERROR 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);
387
388WERROR reg_open_wine(struct registry_context **ctx, const char *path);
389
390const char *reg_get_predef_name(uint32_t hkey);
391WERROR reg_get_predefined_key_by_name(struct registry_context *ctx,
392 const char *name,
393 struct registry_key **key);
394WERROR reg_get_predefined_key(struct registry_context *ctx,
395 uint32_t hkey,
396 struct registry_key **key);
397
398WERROR reg_open_key(TALLOC_CTX *mem_ctx, struct registry_key *parent,
399 const char *name, struct registry_key **result);
400
401WERROR 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);
406WERROR 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);
415WERROR 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);
421WERROR 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);
425WERROR 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);
430WERROR reg_key_del(TALLOC_CTX *mem_ctx,
431 struct registry_key *parent, const char *name);
432WERROR 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);
437WERROR reg_val_set(struct registry_key *key, const char *value,
438 uint32_t type, DATA_BLOB data);
439WERROR reg_get_sec_desc(TALLOC_CTX *ctx, const struct registry_key *key,
440 struct security_descriptor **secdesc);
441WERROR reg_del_value(TALLOC_CTX *mem_ctx,
442 struct registry_key *key, const char *valname);
443WERROR reg_key_flush(struct registry_key *key);
444WERROR 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);
450
451/* Utility functions */
452const char *str_regtype(int type);
453bool push_reg_sz(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, const char *s);
454bool push_reg_multi_sz(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, const char **a);
455bool pull_reg_sz(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob, const char **s);
456bool pull_reg_multi_sz(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob, const char ***a);
457int regtype_by_string(const char *str);
458char *reg_val_data_string(TALLOC_CTX *mem_ctx, uint32_t type, const DATA_BLOB data);
459char *reg_val_description(TALLOC_CTX *mem_ctx, const char *name,
460 uint32_t type, const DATA_BLOB data);
461bool reg_string_to_val(TALLOC_CTX *mem_ctx, const char *type_str,
462 const char *data_str, uint32_t *type, DATA_BLOB *data);
463WERROR reg_open_key_abs(TALLOC_CTX *mem_ctx, struct registry_context *handle,
464 const char *name, struct registry_key **result);
465WERROR reg_key_del_abs(struct registry_context *ctx, const char *path);
466WERROR 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);
470WERROR reg_load_key(struct registry_context *ctx, struct registry_key *key,
471 const char *name, const char *filename);
472
473WERROR reg_mount_hive(struct registry_context *rctx,
474 struct hive_key *hive_key,
475 uint32_t key_id,
476 const char **elements);
477
478struct registry_key *reg_import_hive_key(struct registry_context *ctx,
479 struct hive_key *hive,
480 uint32_t predef_key,
481 const char **elements);
482WERROR reg_set_sec_desc(struct registry_key *key,
483 const struct security_descriptor *security);
484
485struct 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);
495};
496
497WERROR reg_diff_apply(struct registry_context *ctx,
498 const char *filename);
499
500WERROR reg_generate_diff(struct registry_context *ctx1,
501 struct registry_context *ctx2,
502 const struct reg_diff_callbacks *callbacks,
503 void *callback_data);
504WERROR reg_dotreg_diff_save(TALLOC_CTX *ctx, const char *filename,
505 struct reg_diff_callbacks **callbacks,
506 void **callback_data);
507WERROR reg_preg_diff_save(TALLOC_CTX *ctx, const char *filename,
508 struct reg_diff_callbacks **callbacks,
509 void **callback_data);
510WERROR 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);
515WERROR reg_diff_load(const char *filename,
516 const struct reg_diff_callbacks *callbacks,
517 void *callback_data);
518
519WERROR reg_dotreg_diff_load(int fd,
520 const struct reg_diff_callbacks *callbacks,
521 void *callback_data);
522
523WERROR reg_preg_diff_load(int fd,
524 const struct reg_diff_callbacks *callbacks,
525 void *callback_data);
526
527WERROR local_get_predefined_key(struct registry_context *ctx,
528 uint32_t key_id, struct registry_key **key);
529
530
531#endif /* _REGISTRY_H */
Note: See TracBrowser for help on using the repository browser.