r26236: Remove more uses of global_loadparm or specify loadparm_context explicitly.
[ira/wip.git] / source4 / lib / registry / registry.h
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
24 struct registry_context;
25
26 #include <talloc.h>
27 #include "librpc/gen_ndr/security.h"
28 #include "lib/registry/hive.h"
29 #include "libcli/util/ntstatus.h"
30
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
41
42 #define HKEY_FIRST              HKEY_CLASSES_ROOT
43 #define HKEY_LAST               HKEY_PERFORMANCE_NLSTEXT
44
45 struct reg_predefined_key {
46         uint32_t handle;
47         const char *name;
48 };
49
50 extern const struct reg_predefined_key reg_predefined_keys[];
51
52 #define REG_DELETE              -1
53
54 /*
55  * The general idea here is that every backend provides a 'hive'. Combining
56  * various hives gives you a complete registry like windows has
57  */
58
59 #define REGISTRY_INTERFACE_VERSION 1
60
61 struct reg_key_operations;
62
63 /* structure to store the registry handles */
64 struct registry_key
65 {
66         struct registry_context *context;
67 };
68
69 #include "lib/registry/patchfile.h"
70
71 struct registry_value
72 {
73         const char *name;
74         unsigned int data_type;
75         DATA_BLOB data;
76 };
77
78 /* FIXME */
79 typedef void (*reg_key_notification_function) (void);
80 typedef void (*reg_value_notification_function) (void);
81
82 struct cli_credentials;
83 struct registry_context;
84
85 struct registry_operations {
86         const char *name;
87
88         WERROR (*get_key_info) (TALLOC_CTX *mem_ctx,
89                                 const struct registry_key *key,
90                                 const char **classname,
91                                 uint32_t *numsubkeys,
92                                 uint32_t *numvalues,
93                                 NTTIME *last_change_time);
94
95         WERROR (*flush_key) (struct registry_key *key);
96
97         WERROR (*get_predefined_key) (const struct registry_context *ctx,
98                                       uint32_t key_id,
99                                       struct registry_key **key);
100
101         WERROR (*open_key) (TALLOC_CTX *mem_ctx,
102                             struct registry_key *parent,
103                             const char *path,
104                             struct registry_key **key);
105
106         WERROR (*create_key) (TALLOC_CTX *mem_ctx,
107                               struct registry_key *parent,
108                               const char *name,
109                               const char *key_class,
110                               struct security_descriptor *security,
111                               struct registry_key **key);
112
113         WERROR (*delete_key) (struct registry_key *key, const char *name);
114
115         WERROR (*delete_value) (struct registry_key *key, const char *name);
116
117         WERROR (*enum_key) (TALLOC_CTX *mem_ctx,
118                             const struct registry_key *key, uint32_t idx,
119                             const char **name,
120                             const char **keyclass,
121                             NTTIME *last_changed_time);
122
123         WERROR (*enum_value) (TALLOC_CTX *mem_ctx,
124                               const struct registry_key *key, uint32_t idx,
125                               const char **name,
126                               uint32_t *type,
127                               DATA_BLOB *data);
128
129         WERROR (*get_security) (TALLOC_CTX *mem_ctx,
130                                 const struct registry_key *key,
131                                 struct security_descriptor **security);
132
133         WERROR (*set_security) (struct registry_key *key,
134                                 const struct security_descriptor *security);
135
136         WERROR (*load_key) (struct registry_key *key,
137                             const char *key_name,
138                             const char *path);
139
140         WERROR (*unload_key) (struct registry_key *key, const char *name);
141
142         WERROR (*notify_value_change) (struct registry_key *key,
143                                        reg_value_notification_function fn);
144
145         WERROR (*get_value) (TALLOC_CTX *mem_ctx,
146                              const struct registry_key *key,
147                              const char *name,
148                              uint32_t *type,
149                              DATA_BLOB *data);
150
151         WERROR (*set_value) (struct registry_key *key,
152                              const char *name,
153                              uint32_t type,
154                              const DATA_BLOB data);
155 };
156
157 /**
158  * Handle to a full registry
159  * contains zero or more hives
160  */
161 struct registry_context {
162         const struct registry_operations *ops;
163 };
164
165 struct auth_session_info;
166 struct event_context;
167 struct loadparm_context;
168
169 /**
170  * Open the locally defined registry.
171  */
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);
176
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);
182
183 /**
184  * Open the registry on a remote machine.
185  */
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);
190
191 WERROR reg_open_wine(struct registry_context **ctx, const char *path);
192
193 const char *reg_get_predef_name(uint32_t hkey);
194 WERROR reg_get_predefined_key_by_name(struct registry_context *ctx,
195                                       const char *name,
196                                       struct registry_key **key);
197 WERROR reg_get_predefined_key(const struct registry_context *ctx,
198                               uint32_t hkey,
199                               struct registry_key **key);
200
201 WERROR reg_open_key(TALLOC_CTX *mem_ctx, struct registry_key *parent,
202                     const char *name, struct registry_key **result);
203
204 WERROR reg_key_get_value_by_index(TALLOC_CTX *mem_ctx,
205                                   const struct registry_key *key, uint32_t idx,
206                                   const char **name,
207                                   uint32_t *type,
208                                   DATA_BLOB *data);
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,
217                                    int idx,
218                                    const char **name,
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,
223                                   const char *name,
224                                   struct registry_key **subkey);
225 WERROR reg_key_get_value_by_name(TALLOC_CTX *mem_ctx,
226                                  const struct registry_key *key,
227                                  const char *name,
228                                  uint32_t *type,
229                                  DATA_BLOB *data);
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,
244                       const char *name,
245                       const char *key_class,
246                       struct security_descriptor *security,
247                       struct registry_key **key);
248
249
250
251
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);
269
270 WERROR reg_mount_hive(struct registry_context *rctx,
271                       struct hive_key *hive_key,
272                       uint32_t key_id,
273                       const char **elements);
274
275 struct registry_key *reg_import_hive_key(struct registry_context *ctx,
276                                          struct hive_key *hive,
277                                          uint32_t predef_key,
278                                          const char **elements);
279 WERROR reg_get_security(TALLOC_CTX *mem_ctx,
280                         const struct registry_key *key,
281                         struct security_descriptor **security);
282
283 WERROR reg_set_security(struct registry_key *key,
284                         struct security_descriptor *security);
285
286
287 #endif /* _REGISTRY_H */