5e0b971a1d717db02640643f8091d995c3727f0b
[gd/samba-autobuild/.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
84 struct registry_operations {
85         const char *name;
86
87         WERROR (*get_key_info) (TALLOC_CTX *mem_ctx,
88                                 const struct registry_key *key,
89                                 const char **classname,
90                                 uint32_t *numsubkeys,
91                                 uint32_t *numvalues,
92                                 NTTIME *last_change_time,
93                                 uint32_t *max_subkeynamelen,
94                                 uint32_t *max_valnamelen,
95                                 uint32_t *max_valbufsize);
96
97         WERROR (*flush_key) (struct registry_key *key);
98
99         WERROR (*get_predefined_key) (struct registry_context *ctx,
100                                       uint32_t key_id,
101                                       struct registry_key **key);
102
103         WERROR (*open_key) (TALLOC_CTX *mem_ctx,
104                             struct registry_key *parent,
105                             const char *path,
106                             struct registry_key **key);
107
108         WERROR (*create_key) (TALLOC_CTX *mem_ctx,
109                               struct registry_key *parent,
110                               const char *name,
111                               const char *key_class,
112                               struct security_descriptor *security,
113                               struct registry_key **key);
114
115         WERROR (*delete_key) (struct registry_key *key, const char *name);
116
117         WERROR (*delete_value) (struct registry_key *key, const char *name);
118
119         WERROR (*enum_key) (TALLOC_CTX *mem_ctx,
120                             const struct registry_key *key, uint32_t idx,
121                             const char **name,
122                             const char **keyclass,
123                             NTTIME *last_changed_time);
124
125         WERROR (*enum_value) (TALLOC_CTX *mem_ctx,
126                               const struct registry_key *key, uint32_t idx,
127                               const char **name,
128                               uint32_t *type,
129                               DATA_BLOB *data);
130
131         WERROR (*get_security) (TALLOC_CTX *mem_ctx,
132                                 const struct registry_key *key,
133                                 struct security_descriptor **security);
134
135         WERROR (*set_security) (struct registry_key *key,
136                                 const struct security_descriptor *security);
137
138         WERROR (*load_key) (struct registry_key *key,
139                             const char *key_name,
140                             const char *path);
141
142         WERROR (*unload_key) (struct registry_key *key, const char *name);
143
144         WERROR (*notify_value_change) (struct registry_key *key,
145                                        reg_value_notification_function fn);
146
147         WERROR (*get_value) (TALLOC_CTX *mem_ctx,
148                              const struct registry_key *key,
149                              const char *name,
150                              uint32_t *type,
151                              DATA_BLOB *data);
152
153         WERROR (*set_value) (struct registry_key *key,
154                              const char *name,
155                              uint32_t type,
156                              const DATA_BLOB data);
157 };
158
159 /**
160  * Handle to a full registry
161  * contains zero or more hives
162  */
163 struct registry_context {
164         const struct registry_operations *ops;
165 };
166
167 struct auth_session_info;
168 struct event_context;
169 struct loadparm_context;
170
171 /**
172  * Open the locally defined registry.
173  */
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);
178
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);
184
185 /**
186  * Open the registry on a remote machine.
187  */
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);
193
194 WERROR reg_open_wine(struct registry_context **ctx, const char *path);
195
196 const char *reg_get_predef_name(uint32_t hkey);
197 WERROR reg_get_predefined_key_by_name(struct registry_context *ctx,
198                                       const char *name,
199                                       struct registry_key **key);
200 WERROR reg_get_predefined_key(struct registry_context *ctx,
201                               uint32_t hkey,
202                               struct registry_key **key);
203
204 WERROR reg_open_key(TALLOC_CTX *mem_ctx, struct registry_key *parent,
205                     const char *name, struct registry_key **result);
206
207 WERROR reg_key_get_value_by_index(TALLOC_CTX *mem_ctx,
208                                   const struct registry_key *key, uint32_t idx,
209                                   const char **name,
210                                   uint32_t *type,
211                                   DATA_BLOB *data);
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,
223                                    int idx,
224                                    const char **name,
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,
229                                   const char *name,
230                                   struct registry_key **subkey);
231 WERROR reg_key_get_value_by_name(TALLOC_CTX *mem_ctx,
232                                  const struct registry_key *key,
233                                  const char *name,
234                                  uint32_t *type,
235                                  DATA_BLOB *data);
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,
250                       const char *name,
251                       const char *key_class,
252                       struct security_descriptor *security,
253                       struct registry_key **key);
254
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);
271
272 WERROR reg_mount_hive(struct registry_context *rctx,
273                       struct hive_key *hive_key,
274                       uint32_t key_id,
275                       const char **elements);
276
277 struct registry_key *reg_import_hive_key(struct registry_context *ctx,
278                                          struct hive_key *hive,
279                                          uint32_t predef_key,
280                                          const char **elements);
281 WERROR reg_get_security(TALLOC_CTX *mem_ctx,
282                         const struct registry_key *key,
283                         struct security_descriptor **security);
284
285 WERROR reg_set_security(struct registry_key *key,
286                         struct security_descriptor *security);
287
288
289 #endif /* _REGISTRY_H */