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