r24667: Finally merge the registry improvements that Wilco Baan Hofman and I have
[ira/wip.git] / source / lib / registry / hive.h
1 /* 
2    Unix SMB/CIFS implementation.
3    Registry hive interface
4    Copyright (C) Jelmer Vernooij                                          2003-2007.
5    
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10    
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15    
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #ifndef __REGISTRY_HIVE_H__
22 #define __REGISTRY_HIVE_H__
23
24 #include "core.h"
25 #include "talloc.h"
26 #include "librpc/gen_ndr/security.h"
27
28 /**
29  * This file contains the hive API. This API is generally used for 
30  * reading a specific file that contains just one hive. 
31  *
32  * Good examples are .DAT (NTUSER.DAT) files.
33  *
34  * This API does not have any notification support (that 
35  * should be provided by the registry implementation), nor 
36  * does it understand what predefined keys are.
37  */
38
39 struct hive_key {
40         const struct hive_operations *ops;
41 };
42
43 struct hive_operations {
44         const char *name;       
45
46         /**
47          * Open a specific subkey
48          */
49         WERROR (*enum_key) (TALLOC_CTX *mem_ctx,
50                                                 const struct hive_key *key, uint32_t idx, 
51                                                 const char **name,
52                                                 const char **classname,
53                                                 NTTIME *last_mod_time);
54
55         /**
56          * Open a subkey by name
57          */
58         WERROR (*get_key_by_name) (TALLOC_CTX *mem_ctx,
59                                                            const struct hive_key *key, const char *name, 
60                                                            struct hive_key **subkey);
61         
62         /**
63          * Add a new key.
64          */
65         WERROR (*add_key) (TALLOC_CTX *ctx,
66                                            const struct hive_key *parent_key, const char *name, 
67                                            const char *classname, struct security_descriptor *desc, 
68                                            struct hive_key **key);
69         /**
70          * Remove an existing key.
71          */
72         WERROR (*del_key) (const struct hive_key *key, const char *name);
73
74         /**
75          * Force write of a key to disk.
76          */
77         WERROR (*flush_key) (struct hive_key *key);
78
79         /**
80          * Retrieve a registry value with a specific index.
81          */
82         WERROR (*enum_value) (TALLOC_CTX *mem_ctx,
83                                                   const struct hive_key *key, int idx, 
84                                                   const char **name, uint32_t *type, 
85                                                   DATA_BLOB *data);
86
87         /**
88          * Retrieve a registry value with the specified name
89          */
90         WERROR (*get_value_by_name) (TALLOC_CTX *mem_ctx, 
91                                                                  struct hive_key *key, const char *name, 
92                                                                  uint32_t *type, DATA_BLOB *data);
93         
94         /**
95          * Set a value on the specified registry key.
96          */
97         WERROR (*set_value) (struct hive_key *key, const char *name, 
98                                                  uint32_t type, const DATA_BLOB data);
99
100         /**
101          * Remove a value.
102          */
103         WERROR (*delete_value) (struct hive_key *key, const char *name);
104
105         /* Security Descriptors */
106
107         /**
108          * Change the security descriptor on a registry key.
109          *
110          * This should return WERR_NOT_SUPPORTED if the underlying 
111          * format does not have a mechanism for storing 
112          * security descriptors.
113          */
114         WERROR (*set_sec_desc) (struct hive_key *key, 
115                                                         const struct security_descriptor *desc);
116
117         /**
118          * Retrieve the security descriptor on a registry key.
119          *
120          * This should return WERR_NOT_SUPPORTED if the underlying 
121          * format does not have a mechanism for storing 
122          * security descriptors.
123          */
124         WERROR (*get_sec_desc) (TALLOC_CTX *ctx,
125                                                         const struct hive_key *key, 
126                                                         struct security_descriptor **desc);
127         
128         /**
129          * Retrieve general information about a key.
130          */
131         WERROR (*get_key_info) (TALLOC_CTX *mem_ctx,
132                                                         const struct hive_key *key,
133                                                         const char **classname,
134                                                         uint32_t *num_subkeys,
135                                                         uint32_t *num_values,
136                                                         NTTIME *last_change_time);
137 };
138
139 struct cli_credentials;
140 struct auth_session_info;
141
142 WERROR reg_open_hive(TALLOC_CTX *parent_ctx, const char *location, 
143                                                           struct auth_session_info *session_info, 
144                                                           struct cli_credentials *credentials, 
145                                                           struct hive_key **root);
146 WERROR hive_key_get_info(TALLOC_CTX *mem_ctx, const struct hive_key *key,
147                                                  const char **classname, uint32_t *num_subkeys, 
148                                                  uint32_t *num_values,
149                                                  NTTIME *last_change_time);
150 WERROR hive_key_add_name(TALLOC_CTX *ctx, const struct hive_key *parent_key,
151                                                  const char *name, const char *classname, struct security_descriptor *desc,
152                                                  struct hive_key **key);
153 _PUBLIC_ WERROR hive_key_del(const struct hive_key *key, const char *name);
154 _PUBLIC_ WERROR hive_get_key_by_name(TALLOC_CTX *mem_ctx,
155                                                            const struct hive_key *key, const char *name, 
156                                                            struct hive_key **subkey);
157 WERROR hive_enum_key(TALLOC_CTX *mem_ctx,
158                                         const struct hive_key *key, uint32_t idx, 
159                                         const char **name,
160                                         const char **classname,
161                                         NTTIME *last_mod_time);
162
163 WERROR hive_set_value (struct hive_key *key, const char *name, 
164                                            uint32_t type, const DATA_BLOB data);
165
166 WERROR hive_get_value (TALLOC_CTX *mem_ctx, 
167                                            struct hive_key *key, const char *name, 
168                                            uint32_t *type, DATA_BLOB *data);
169 WERROR hive_get_value_by_index (TALLOC_CTX *mem_ctx, 
170                                            struct hive_key *key, uint32_t idx, const char **name, 
171                                            uint32_t *type, DATA_BLOB *data);
172
173 WERROR hive_del_value (struct hive_key *key, const char *name);
174
175 WERROR hive_key_flush(struct hive_key *key);
176
177
178 /* Individual backends */
179 WERROR reg_open_directory(TALLOC_CTX *parent_ctx, 
180                         const char *location, struct hive_key **key);
181 WERROR reg_open_regf_file(TALLOC_CTX *parent_ctx, 
182                                                   const char *location, struct hive_key **key);
183 WERROR reg_open_ldb_file(TALLOC_CTX *parent_ctx, const char *location, 
184                                                                 struct auth_session_info *session_info,
185                                                                 struct cli_credentials *credentials,
186                                                                 struct hive_key **k);
187
188
189 WERROR reg_create_directory(TALLOC_CTX *parent_ctx, 
190                         const char *location, struct hive_key **key);
191 WERROR reg_create_regf_file(TALLOC_CTX *parent_ctx, 
192                                                          const char *location, 
193                                                          int major_version, 
194                                                          struct hive_key **key);
195
196
197 #endif /* __REGISTRY_HIVE_H__ */