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;
84 struct registry_operations {
87 WERROR (*get_key_info) (TALLOC_CTX *mem_ctx,
88 const struct registry_key *key,
89 const char **classname,
92 NTTIME *last_change_time,
93 uint32_t *max_subkeynamelen,
94 uint32_t *max_valnamelen,
95 uint32_t *max_valbufsize);
97 WERROR (*flush_key) (struct registry_key *key);
99 WERROR (*get_predefined_key) (struct registry_context *ctx,
101 struct registry_key **key);
103 WERROR (*open_key) (TALLOC_CTX *mem_ctx,
104 struct registry_key *parent,
106 struct registry_key **key);
108 WERROR (*create_key) (TALLOC_CTX *mem_ctx,
109 struct registry_key *parent,
111 const char *key_class,
112 struct security_descriptor *security,
113 struct registry_key **key);
115 WERROR (*delete_key) (struct registry_key *key, const char *name);
117 WERROR (*delete_value) (struct registry_key *key, const char *name);
119 WERROR (*enum_key) (TALLOC_CTX *mem_ctx,
120 const struct registry_key *key, uint32_t idx,
122 const char **keyclass,
123 NTTIME *last_changed_time);
125 WERROR (*enum_value) (TALLOC_CTX *mem_ctx,
126 const struct registry_key *key, uint32_t idx,
131 WERROR (*get_security) (TALLOC_CTX *mem_ctx,
132 const struct registry_key *key,
133 struct security_descriptor **security);
135 WERROR (*set_security) (struct registry_key *key,
136 const struct security_descriptor *security);
138 WERROR (*load_key) (struct registry_key *key,
139 const char *key_name,
142 WERROR (*unload_key) (struct registry_key *key, const char *name);
144 WERROR (*notify_value_change) (struct registry_key *key,
145 reg_value_notification_function fn);
147 WERROR (*get_value) (TALLOC_CTX *mem_ctx,
148 const struct registry_key *key,
153 WERROR (*set_value) (struct registry_key *key,
156 const DATA_BLOB data);
160 * Handle to a full registry
161 * contains zero or more hives
163 struct registry_context {
164 const struct registry_operations *ops;
167 struct auth_session_info;
168 struct event_context;
169 struct loadparm_context;
172 * Open the locally defined registry.
174 WERROR reg_open_local(TALLOC_CTX *mem_ctx,
175 struct registry_context **ctx,
176 struct auth_session_info *session_info,
177 struct cli_credentials *credentials);
179 WERROR reg_open_samba(TALLOC_CTX *mem_ctx,
180 struct registry_context **ctx,
181 struct loadparm_context *lp_ctx,
182 struct auth_session_info *session_info,
183 struct cli_credentials *credentials);
186 * Open the registry on a remote machine.
188 WERROR reg_open_remote(struct registry_context **ctx,
189 struct auth_session_info *session_info,
190 struct cli_credentials *credentials,
191 struct loadparm_context *lp_ctx,
192 const char *location, struct event_context *ev);
194 WERROR reg_open_wine(struct registry_context **ctx, const char *path);
196 const char *reg_get_predef_name(uint32_t hkey);
197 WERROR reg_get_predefined_key_by_name(struct registry_context *ctx,
199 struct registry_key **key);
200 WERROR reg_get_predefined_key(struct registry_context *ctx,
202 struct registry_key **key);
204 WERROR reg_open_key(TALLOC_CTX *mem_ctx, struct registry_key *parent,
205 const char *name, struct registry_key **result);
207 WERROR reg_key_get_value_by_index(TALLOC_CTX *mem_ctx,
208 const struct registry_key *key, uint32_t idx,
212 WERROR reg_key_get_info(TALLOC_CTX *mem_ctx,
213 const struct registry_key *key,
214 const char **class_name,
215 uint32_t *num_subkeys,
216 uint32_t *num_values,
217 NTTIME *last_change_time,
218 uint32_t *max_subkeynamelen,
219 uint32_t *max_valnamelen,
220 uint32_t *max_valbufsize);
221 WERROR reg_key_get_subkey_by_index(TALLOC_CTX *mem_ctx,
222 const struct registry_key *key,
225 const char **classname,
226 NTTIME *last_mod_time);
227 WERROR reg_key_get_subkey_by_name(TALLOC_CTX *mem_ctx,
228 const struct registry_key *key,
230 struct registry_key **subkey);
231 WERROR reg_key_get_value_by_name(TALLOC_CTX *mem_ctx,
232 const struct registry_key *key,
236 WERROR reg_key_del(struct registry_key *parent, const char *name);
237 WERROR reg_key_add_name(TALLOC_CTX *mem_ctx,
238 struct registry_key *parent, const char *name,
239 const char *classname,
240 struct security_descriptor *desc,
241 struct registry_key **newkey);
242 WERROR reg_val_set(struct registry_key *key, const char *value,
243 uint32_t type, DATA_BLOB data);
244 WERROR reg_get_sec_desc(TALLOC_CTX *ctx, const struct registry_key *key,
245 struct security_descriptor **secdesc);
246 WERROR reg_del_value(struct registry_key *key, const char *valname);
247 WERROR reg_key_flush(struct registry_key *key);
248 WERROR reg_create_key(TALLOC_CTX *mem_ctx,
249 struct registry_key *parent,
251 const char *key_class,
252 struct security_descriptor *security,
253 struct registry_key **key);
255 /* Utility functions */
256 const char *str_regtype(int type);
257 char *reg_val_data_string(TALLOC_CTX *mem_ctx, struct smb_iconv_convenience *iconv_convenience, uint32_t type, const DATA_BLOB data);
258 char *reg_val_description(TALLOC_CTX *mem_ctx, struct smb_iconv_convenience *iconv_convenience, const char *name,
259 uint32_t type, const DATA_BLOB data);
260 bool reg_string_to_val(TALLOC_CTX *mem_ctx, struct smb_iconv_convenience *iconv_convenience, const char *type_str,
261 const char *data_str, uint32_t *type, DATA_BLOB *data);
262 WERROR reg_open_key_abs(TALLOC_CTX *mem_ctx, struct registry_context *handle,
263 const char *name, struct registry_key **result);
264 WERROR reg_key_del_abs(struct registry_context *ctx, const char *path);
265 WERROR reg_key_add_abs(TALLOC_CTX *mem_ctx, struct registry_context *ctx,
266 const char *path, uint32_t access_mask,
267 struct security_descriptor *sec_desc,
268 struct registry_key **result);
269 WERROR reg_load_key(struct registry_context *ctx, struct registry_key *key,
270 const char *name, const char *filename);
272 WERROR reg_mount_hive(struct registry_context *rctx,
273 struct hive_key *hive_key,
275 const char **elements);
277 struct registry_key *reg_import_hive_key(struct registry_context *ctx,
278 struct hive_key *hive,
280 const char **elements);
281 WERROR reg_get_security(TALLOC_CTX *mem_ctx,
282 const struct registry_key *key,
283 struct security_descriptor **security);
285 WERROR reg_set_security(struct registry_key *key,
286 struct security_descriptor *security);
289 #endif /* _REGISTRY_H */