9839786e012a21bf57b039ba1489a8ab9ddce207
[jelmer/samba4-debian.git] / source / 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 "core.h"
27 #include "talloc/talloc.h"
28 #include "librpc/gen_ndr/security.h"
29 #include "lib/registry/hive.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
168 /**
169  * Open the locally defined registry.
170  */
171 WERROR reg_open_local (TALLOC_CTX *mem_ctx, 
172                                 struct registry_context **ctx, 
173                                 struct auth_session_info *session_info, 
174                                 struct cli_credentials *credentials);
175
176 WERROR reg_open_samba (TALLOC_CTX *mem_ctx,
177                                                                 struct registry_context **ctx,
178                                                                 struct auth_session_info *session_info,
179                                                                 struct cli_credentials *credentials);
180
181 /**
182  * Open the registry on a remote machine.
183  */
184 WERROR reg_open_remote(struct registry_context **ctx, 
185                                                                 struct auth_session_info *session_info, 
186                                                                 struct cli_credentials *credentials, 
187                                                                 const char *location, struct event_context *ev);
188
189 WERROR reg_open_wine(struct registry_context **ctx, const char *path);
190
191 const char *reg_get_predef_name(uint32_t hkey);
192 WERROR reg_get_predefined_key_by_name(struct registry_context *ctx, 
193                                                                                            const char *name, 
194                                                                                            struct registry_key **key);
195 WERROR reg_get_predefined_key(const struct registry_context *ctx, 
196                                                                            uint32_t hkey, 
197                                                                            struct registry_key **key);
198
199 WERROR reg_open_key(TALLOC_CTX *mem_ctx, struct registry_key *parent, 
200                                                          const char *name, struct registry_key **result);
201
202 WERROR reg_key_get_value_by_index(TALLOC_CTX *mem_ctx, 
203                                    const struct registry_key *key, uint32_t idx, 
204                                    const char **name,
205                                    uint32_t *type,
206                                    DATA_BLOB *data);
207 WERROR reg_key_get_info(TALLOC_CTX *mem_ctx,
208                                                                  const struct registry_key *key, 
209                                                                         const char **class_name,
210                                                                         uint32_t *num_subkeys,
211                                                                         uint32_t *num_values,
212                                                                         NTTIME *last_change_time);
213 WERROR reg_key_get_subkey_by_index(TALLOC_CTX *mem_ctx, 
214                                                                                         const struct registry_key *key, 
215                                                                                         int idx, 
216                                                                                         const char **name,
217                                                                                         const char **classname,
218                                                                                         NTTIME *last_mod_time);
219 WERROR reg_key_get_subkey_by_name(TALLOC_CTX *mem_ctx, 
220                                                                   const struct registry_key *key, 
221                                                                   const char *name, 
222                                                                   struct registry_key **subkey);
223 WERROR reg_key_get_value_by_name(TALLOC_CTX *mem_ctx, 
224                                                                                   const struct registry_key *key, 
225                                                                                   const char *name, 
226                                                                                   uint32_t *type,
227                                                                                   DATA_BLOB *data);
228 WERROR reg_key_del(struct registry_key *parent, const char *name);
229 WERROR reg_key_add_name(TALLOC_CTX *mem_ctx, 
230                                                                  struct registry_key *parent, const char *name, 
231                                                                  const char *classname, 
232                                                                  struct security_descriptor *desc, 
233                                                                  struct registry_key **newkey);
234 WERROR reg_val_set(struct registry_key *key, const char *value, 
235                                                         uint32_t type, DATA_BLOB data);
236 WERROR reg_get_sec_desc(TALLOC_CTX *ctx, const struct registry_key *key, struct security_descriptor **secdesc);
237 WERROR reg_del_value(struct registry_key *key, const char *valname);
238 WERROR reg_key_flush(struct registry_key *key);
239 WERROR reg_create_key (TALLOC_CTX *mem_ctx, 
240                                                 struct registry_key *parent,
241
242                                                   const char *name,
243                                                   const char *key_class,
244                                                   struct security_descriptor *security,
245                                                   struct registry_key **key);
246
247
248
249
250 /* Utility functions */
251 const char *str_regtype(int type);
252 char *reg_val_data_string(TALLOC_CTX *mem_ctx, uint32_t type, 
253                                                                    const DATA_BLOB data);
254 char *reg_val_description(TALLOC_CTX *mem_ctx, const char *name,
255                                                                    uint32_t type, const DATA_BLOB data);
256 bool reg_string_to_val(TALLOC_CTX *mem_ctx, const char *type_str, const char *data_str, uint32_t *type, DATA_BLOB *data);
257 WERROR reg_open_key_abs(TALLOC_CTX *mem_ctx, struct registry_context *handle, const char *name, struct registry_key **result);
258 WERROR reg_key_del_abs(struct registry_context *ctx, const char *path);
259 WERROR reg_key_add_abs(TALLOC_CTX *mem_ctx, struct registry_context *ctx, const char *path, uint32_t access_mask, struct security_descriptor *sec_desc, struct registry_key **result);
260 WERROR reg_load_key(struct registry_context *ctx, struct registry_key *key, 
261                                         const char *name, const char *filename);
262
263 WERROR reg_mount_hive(struct registry_context *rctx, 
264                                           struct hive_key *hive_key,
265                                           uint32_t key_id,
266                                           const char **elements);
267
268 struct registry_key *reg_import_hive_key(struct registry_context *ctx,
269                                                                              struct hive_key *hive, 
270                                                                              uint32_t predef_key,
271                                                                                  const char **elements);
272
273
274 #endif /* _REGISTRY_H */