r23792: convert Samba4 to GPLv3
[bbaumbach/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-2004.
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 #include "core.h"
25 #include "talloc/talloc.h"
26 #include "librpc/gen_ndr/security.h"
27
28 /* Handles for the predefined keys */
29 #define HKEY_CLASSES_ROOT                0x80000000
30 #define HKEY_CURRENT_USER                0x80000001
31 #define HKEY_LOCAL_MACHINE               0x80000002
32 #define HKEY_USERS                               0x80000003
33 #define HKEY_PERFORMANCE_DATA    0x80000004
34 #define HKEY_CURRENT_CONFIG              0x80000005
35 #define HKEY_DYN_DATA                    0x80000006
36 #define HKEY_PERFORMANCE_TEXT    0x80000050
37 #define HKEY_PERFORMANCE_NLSTEXT 0x80000060
38
39 struct reg_predefined_key {
40         uint32_t handle;
41         const char *name;
42 };
43
44 extern const struct reg_predefined_key reg_predefined_keys[];
45
46 #define REG_DELETE              -1
47
48 /*
49  * The general idea here is that every backend provides a 'hive'. Combining
50  * various hives gives you a complete registry like windows has
51  */
52
53 #define REGISTRY_INTERFACE_VERSION 1
54
55 /* structure to store the registry handles */
56 struct registry_key 
57 {
58   const char *name;       
59   const char *path;     
60   const char *class_name; 
61   NTTIME last_mod; 
62   struct registry_hive *hive;
63   void *backend_data;
64 };
65
66 struct registry_value 
67 {
68   const char *name;
69   unsigned int data_type;
70   DATA_BLOB data;
71 };
72
73 /* FIXME */
74 typedef void (*reg_key_notification_function) (void);
75 typedef void (*reg_value_notification_function) (void);
76
77 /* 
78  * Container for function pointers to enumeration routines
79  * for virtual registry view 
80  *
81  * Backends can provide :
82  *  - just one hive (example: nt4, w95)
83  *  - several hives (example: rpc).
84  * 
85  * Backends should always do case-insensitive compares 
86  * (everything is case-insensitive but case-preserving, 
87  * just like the FS)
88  *
89  * There is no save function as all operations are expected to 
90  * be atomic.
91  */ 
92
93 struct hive_operations {
94         const char *name;
95
96         /* Implement this one */
97         WERROR (*open_hive) (struct registry_hive *, struct registry_key **);
98
99         /* Or this one */
100         WERROR (*open_key) (TALLOC_CTX *, const struct registry_key *, const char *name, struct registry_key **);
101
102         WERROR (*num_subkeys) (const struct registry_key *, uint32_t *count);
103         WERROR (*num_values) (const struct registry_key *, uint32_t *count);
104         WERROR (*get_subkey_by_index) (TALLOC_CTX *, const struct registry_key *, int idx, struct registry_key **);
105
106         /* Can not contain more than one level */
107         WERROR (*get_subkey_by_name) (TALLOC_CTX *, const struct registry_key *, const char *name, struct registry_key **);
108         WERROR (*get_value_by_index) (TALLOC_CTX *, const struct registry_key *, int idx, struct registry_value **);
109
110         /* Can not contain more than one level */
111         WERROR (*get_value_by_name) (TALLOC_CTX *, const struct registry_key *, const char *name, struct registry_value **);
112
113         /* Security control */
114         WERROR (*key_get_sec_desc) (TALLOC_CTX *, const struct registry_key *, struct security_descriptor **);
115         WERROR (*key_set_sec_desc) (const struct registry_key *, const struct security_descriptor *);
116
117         /* Notification */
118         WERROR (*request_key_change_notify) (const struct registry_key *, reg_key_notification_function);
119         WERROR (*request_value_change_notify) (const struct registry_value *, reg_value_notification_function);
120
121         /* Key management */
122         WERROR (*add_key)(TALLOC_CTX *, const struct registry_key *, const char *name, uint32_t access_mask, struct security_descriptor *, struct registry_key **);
123         WERROR (*del_key)(const struct registry_key *, const char *name);
124         WERROR (*flush_key) (const struct registry_key *);
125
126         /* Value management */
127         WERROR (*set_value)(const struct registry_key *, const char *name, uint32_t type, const DATA_BLOB data); 
128         WERROR (*del_value)(const struct registry_key *, const char *valname);
129 };
130
131 struct cli_credentials;
132
133 struct registry_hive
134 {
135         const struct hive_operations *functions;
136         struct registry_key *root;
137         struct auth_session_info *session_info;
138         struct cli_credentials *credentials;
139         void *backend_data;
140         const char *location;
141 };
142
143 /* Handle to a full registry
144  * contains zero or more hives */
145 struct registry_context {
146     void *backend_data;
147         struct cli_credentials *credentials;
148         struct auth_session_info *session_info;
149         WERROR (*get_predefined_key) (struct registry_context *, uint32_t hkey, struct registry_key **);
150 };
151
152 struct reg_init_function_entry {
153         const struct hive_operations *hive_functions;
154         struct reg_init_function_entry *prev, *next;
155 };
156
157 /* Representing differences between registry files */
158
159 struct reg_diff_value
160 {
161         const char *name;
162         enum { REG_DIFF_DEL_VAL, REG_DIFF_SET_VAL } changetype;
163         uint32_t type;
164         DATA_BLOB data;
165 };
166
167 struct reg_diff_key
168 {
169         const char *name;
170         enum { REG_DIFF_CHANGE_KEY, REG_DIFF_DEL_KEY } changetype;
171         uint32_t numvalues;
172         struct reg_diff_value *values;
173 };
174
175 struct reg_diff
176 {
177         const char *format;
178         uint32_t numkeys;
179         struct reg_diff_key *keys;
180 };
181
182 struct auth_session_info;
183 struct event_context;
184
185 #ifndef _PUBLIC_
186 #define _PUBLIC_
187 #endif
188
189 _PUBLIC_ WERROR reg_open_local (TALLOC_CTX *mem_ctx, 
190                                 struct registry_context **ctx, 
191                                 struct auth_session_info *session_info, 
192                                 struct cli_credentials *credentials);
193
194 _PUBLIC_ WERROR reg_open_remote(struct registry_context **ctx, 
195                                                                 struct auth_session_info *session_info, 
196                                                                 struct cli_credentials *credentials, 
197                                                                 const char *location, struct event_context *ev);
198
199 _PUBLIC_ NTSTATUS registry_register(const void *_hive_ops);
200 _PUBLIC_ NTSTATUS registry_init(void);
201 _PUBLIC_ BOOL reg_has_backend(const char *backend);
202 _PUBLIC_ int reg_list_predefs(TALLOC_CTX *mem_ctx, char ***predefs, uint32_t **hkeys);
203 _PUBLIC_ const char *reg_get_predef_name(uint32_t hkey);
204 _PUBLIC_ WERROR reg_get_predefined_key_by_name(struct registry_context *ctx, const char *name, struct registry_key **key);
205 _PUBLIC_ WERROR reg_get_predefined_key(struct registry_context *ctx, uint32_t hkey, struct registry_key **key);
206 _PUBLIC_ WERROR reg_open_hive(TALLOC_CTX *parent_ctx, const char *backend, const char *location, struct auth_session_info *session_info, struct cli_credentials *credentials, struct registry_key **root);
207 _PUBLIC_ WERROR reg_open_key(TALLOC_CTX *mem_ctx, struct registry_key *parent, const char *name, struct registry_key **result);
208 _PUBLIC_ WERROR reg_key_get_value_by_index(TALLOC_CTX *mem_ctx, const struct registry_key *key, int idx, struct registry_value **val);
209 _PUBLIC_ WERROR reg_key_num_subkeys(const struct registry_key *key, uint32_t *count);
210 _PUBLIC_ WERROR reg_key_num_values(const struct registry_key *key, uint32_t *count);
211 _PUBLIC_ WERROR reg_key_get_subkey_by_index(TALLOC_CTX *mem_ctx, const struct registry_key *key, int idx, struct registry_key **subkey);
212 WERROR reg_key_get_subkey_by_name(TALLOC_CTX *mem_ctx, const struct registry_key *key, const char *name, struct registry_key **subkey);
213 _PUBLIC_ WERROR reg_key_get_value_by_name(TALLOC_CTX *mem_ctx, const struct registry_key *key, const char *name, struct registry_value **val);
214 _PUBLIC_ WERROR reg_key_del(struct registry_key *parent, const char *name);
215 _PUBLIC_ WERROR reg_key_add_name(TALLOC_CTX *mem_ctx, const struct registry_key *parent, const char *name, uint32_t access_mask, struct security_descriptor *desc, struct registry_key **newkey);
216 _PUBLIC_ WERROR reg_val_set(struct registry_key *key, const char *value, uint32_t type, DATA_BLOB data);
217 _PUBLIC_ WERROR reg_get_sec_desc(TALLOC_CTX *ctx, const struct registry_key *key, struct security_descriptor **secdesc);
218 _PUBLIC_ WERROR reg_del_value(const struct registry_key *key, const char *valname);
219 _PUBLIC_ WERROR reg_key_flush(const struct registry_key *key);
220 _PUBLIC_ WERROR reg_key_subkeysizes(const struct registry_key *key, uint32_t *max_subkeylen, uint32_t *max_subkeysize);
221 _PUBLIC_ WERROR reg_key_valuesizes(const struct registry_key *key, uint32_t *max_valnamelen, uint32_t *max_valbufsize);
222
223 /* Utility functions */
224
225 _PUBLIC_ const char *str_regtype(int type);
226 _PUBLIC_ char *reg_val_data_string(TALLOC_CTX *mem_ctx, uint32_t type, DATA_BLOB *data);
227 _PUBLIC_ char *reg_val_description(TALLOC_CTX *mem_ctx, struct registry_value *val) ;
228 _PUBLIC_ BOOL reg_string_to_val(TALLOC_CTX *mem_ctx, const char *type_str, const char *data_str, uint32_t *type, DATA_BLOB *data);
229 char *reg_path_win2unix(char *path) ;
230 char *reg_path_unix2win(char *path) ;
231 WERROR reg_open_key_abs(TALLOC_CTX *mem_ctx, struct registry_context *handle, const char *name, struct registry_key **result);
232 WERROR reg_key_del_abs(struct registry_context *ctx, const char *path);
233 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);
234
235
236 /* Patch files */
237
238 _PUBLIC_ struct reg_diff *reg_generate_diff(TALLOC_CTX *mem_ctx, struct registry_context *ctx1, struct registry_context *ctx2);
239 _PUBLIC_ WERROR reg_diff_save(const struct reg_diff *diff, const char *filename);
240 _PUBLIC_ struct reg_diff *reg_diff_load(TALLOC_CTX *ctx, const char *fn);
241 _PUBLIC_ BOOL reg_diff_apply (const struct reg_diff *diff, struct registry_context *ctx);
242
243 NTSTATUS registry_rpc_init(void);
244
245 #endif /* _REGISTRY_H */