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;
27 #include "librpc/gen_ndr/security.h"
28 #include "lib/registry/hive.h"
29 #include "libcli/util/ntstatus.h"
31 /* Handles for the predefined keys */
32 #define HKEY_CLASSES_ROOT 0x80000000
33 #define HKEY_CURRENT_USER 0x80000001
34 #define HKEY_LOCAL_MACHINE 0x80000002
35 #define HKEY_USERS 0x80000003
36 #define HKEY_PERFORMANCE_DATA 0x80000004
37 #define HKEY_CURRENT_CONFIG 0x80000005
38 #define HKEY_DYN_DATA 0x80000006
39 #define HKEY_PERFORMANCE_TEXT 0x80000050
40 #define HKEY_PERFORMANCE_NLSTEXT 0x80000060
42 #define HKEY_FIRST HKEY_CLASSES_ROOT
43 #define HKEY_LAST HKEY_PERFORMANCE_NLSTEXT
45 struct reg_predefined_key {
50 extern const struct reg_predefined_key reg_predefined_keys[];
55 * The general idea here is that every backend provides a 'hive'. Combining
56 * various hives gives you a complete registry like windows has
59 #define REGISTRY_INTERFACE_VERSION 1
61 struct reg_key_operations;
63 /* structure to store the registry handles */
66 struct registry_context *context;
69 #include "lib/registry/patchfile.h"
74 unsigned int data_type;
79 typedef void (*reg_key_notification_function) (void);
80 typedef void (*reg_value_notification_function) (void);
82 struct cli_credentials;
83 struct registry_context;
85 struct registry_operations {
88 WERROR (*get_key_info) (TALLOC_CTX *mem_ctx,
89 const struct registry_key *key,
90 const char **classname,
93 NTTIME *last_change_time);
95 WERROR (*flush_key) (struct registry_key *key);
97 WERROR (*get_predefined_key) (const struct registry_context *ctx,
99 struct registry_key **key);
101 WERROR (*open_key) (TALLOC_CTX *mem_ctx,
102 struct registry_key *parent,
104 struct registry_key **key);
106 WERROR (*create_key) (TALLOC_CTX *mem_ctx,
107 struct registry_key *parent,
109 const char *key_class,
110 struct security_descriptor *security,
111 struct registry_key **key);
113 WERROR (*delete_key) (struct registry_key *key, const char *name);
115 WERROR (*delete_value) (struct registry_key *key, const char *name);
117 WERROR (*enum_key) (TALLOC_CTX *mem_ctx,
118 const struct registry_key *key, uint32_t idx,
120 const char **keyclass,
121 NTTIME *last_changed_time);
123 WERROR (*enum_value) (TALLOC_CTX *mem_ctx,
124 const struct registry_key *key, uint32_t idx,
129 WERROR (*get_security) (TALLOC_CTX *mem_ctx,
130 const struct registry_key *key,
131 struct security_descriptor **security);
133 WERROR (*set_security) (struct registry_key *key,
134 const struct security_descriptor *security);
136 WERROR (*load_key) (struct registry_key *key,
137 const char *key_name,
140 WERROR (*unload_key) (struct registry_key *key, const char *name);
142 WERROR (*notify_value_change) (struct registry_key *key,
143 reg_value_notification_function fn);
145 WERROR (*get_value) (TALLOC_CTX *mem_ctx,
146 const struct registry_key *key,
151 WERROR (*set_value) (struct registry_key *key,
154 const DATA_BLOB data);
158 * Handle to a full registry
159 * contains zero or more hives
161 struct registry_context {
162 const struct registry_operations *ops;
165 struct auth_session_info;
166 struct event_context;
167 struct loadparm_context;
170 * Open the locally defined registry.
172 WERROR reg_open_local(TALLOC_CTX *mem_ctx,
173 struct registry_context **ctx,
174 struct auth_session_info *session_info,
175 struct cli_credentials *credentials);
177 WERROR reg_open_samba(TALLOC_CTX *mem_ctx,
178 struct registry_context **ctx,
179 struct loadparm_context *lp_ctx,
180 struct auth_session_info *session_info,
181 struct cli_credentials *credentials);
184 * Open the registry on a remote machine.
186 WERROR reg_open_remote(struct registry_context **ctx,
187 struct auth_session_info *session_info,
188 struct cli_credentials *credentials,
189 const char *location, struct event_context *ev);
191 WERROR reg_open_wine(struct registry_context **ctx, const char *path);
193 const char *reg_get_predef_name(uint32_t hkey);
194 WERROR reg_get_predefined_key_by_name(struct registry_context *ctx,
196 struct registry_key **key);
197 WERROR reg_get_predefined_key(const struct registry_context *ctx,
199 struct registry_key **key);
201 WERROR reg_open_key(TALLOC_CTX *mem_ctx, struct registry_key *parent,
202 const char *name, struct registry_key **result);
204 WERROR reg_key_get_value_by_index(TALLOC_CTX *mem_ctx,
205 const struct registry_key *key, uint32_t idx,
209 WERROR reg_key_get_info(TALLOC_CTX *mem_ctx,
210 const struct registry_key *key,
211 const char **class_name,
212 uint32_t *num_subkeys,
213 uint32_t *num_values,
214 NTTIME *last_change_time);
215 WERROR reg_key_get_subkey_by_index(TALLOC_CTX *mem_ctx,
216 const struct registry_key *key,
219 const char **classname,
220 NTTIME *last_mod_time);
221 WERROR reg_key_get_subkey_by_name(TALLOC_CTX *mem_ctx,
222 const struct registry_key *key,
224 struct registry_key **subkey);
225 WERROR reg_key_get_value_by_name(TALLOC_CTX *mem_ctx,
226 const struct registry_key *key,
230 WERROR reg_key_del(struct registry_key *parent, const char *name);
231 WERROR reg_key_add_name(TALLOC_CTX *mem_ctx,
232 struct registry_key *parent, const char *name,
233 const char *classname,
234 struct security_descriptor *desc,
235 struct registry_key **newkey);
236 WERROR reg_val_set(struct registry_key *key, const char *value,
237 uint32_t type, DATA_BLOB data);
238 WERROR reg_get_sec_desc(TALLOC_CTX *ctx, const struct registry_key *key,
239 struct security_descriptor **secdesc);
240 WERROR reg_del_value(struct registry_key *key, const char *valname);
241 WERROR reg_key_flush(struct registry_key *key);
242 WERROR reg_create_key(TALLOC_CTX *mem_ctx,
243 struct registry_key *parent,
245 const char *key_class,
246 struct security_descriptor *security,
247 struct registry_key **key);
252 /* Utility functions */
253 const char *str_regtype(int type);
254 char *reg_val_data_string(TALLOC_CTX *mem_ctx, uint32_t type,
255 const DATA_BLOB data);
256 char *reg_val_description(TALLOC_CTX *mem_ctx, const char *name,
257 uint32_t type, const DATA_BLOB data);
258 bool reg_string_to_val(TALLOC_CTX *mem_ctx, const char *type_str,
259 const char *data_str, uint32_t *type, DATA_BLOB *data);
260 WERROR reg_open_key_abs(TALLOC_CTX *mem_ctx, struct registry_context *handle,
261 const char *name, struct registry_key **result);
262 WERROR reg_key_del_abs(struct registry_context *ctx, const char *path);
263 WERROR reg_key_add_abs(TALLOC_CTX *mem_ctx, struct registry_context *ctx,
264 const char *path, uint32_t access_mask,
265 struct security_descriptor *sec_desc,
266 struct registry_key **result);
267 WERROR reg_load_key(struct registry_context *ctx, struct registry_key *key,
268 const char *name, const char *filename);
270 WERROR reg_mount_hive(struct registry_context *rctx,
271 struct hive_key *hive_key,
273 const char **elements);
275 struct registry_key *reg_import_hive_key(struct registry_context *ctx,
276 struct hive_key *hive,
278 const char **elements);
279 WERROR reg_get_security(TALLOC_CTX *mem_ctx,
280 const struct registry_key *key,
281 struct security_descriptor **security);
283 WERROR reg_set_security(struct registry_key *key,
284 struct security_descriptor *security);
287 #endif /* _REGISTRY_H */