r26689: registry: Return max_subkeynamelen, max_valnamelen and max_valbufsize in...
[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 <talloc.h>
25 #include "libcli/util/werror.h"
26 #include "librpc/gen_ndr/security.h"
27 #include "libcli/util/ntstatus.h"
28
29 /**
30  * This file contains the hive API. This API is generally used for
31  * reading a specific file that contains just one hive.
32  *
33  * Good examples are .DAT (NTUSER.DAT) files.
34  *
35  * This API does not have any notification support (that
36  * should be provided by the registry implementation), nor
37  * does it understand what predefined keys are.
38  */
39
40 struct hive_key {
41         const struct hive_operations *ops;
42 };
43
44 struct hive_operations {
45         const char *name;
46
47         /**
48          * Open a specific subkey
49          */
50         WERROR (*enum_key) (TALLOC_CTX *mem_ctx,
51                             const struct hive_key *key, uint32_t idx,
52                             const char **name,
53                             const char **classname,
54                             NTTIME *last_mod_time);
55
56         /**
57          * Open a subkey by name
58          */
59         WERROR (*get_key_by_name) (TALLOC_CTX *mem_ctx,
60                                    const struct hive_key *key, const char *name,
61                                    struct hive_key **subkey);
62
63         /**
64          * Add a new key.
65          */
66         WERROR (*add_key) (TALLOC_CTX *ctx,
67                            const struct hive_key *parent_key, const char *name,
68                            const char *classname,
69                            struct security_descriptor *desc,
70                            struct hive_key **key);
71         /**
72          * Remove an existing key.
73          */
74         WERROR (*del_key) (const struct hive_key *key, const char *name);
75
76         /**
77          * Force write of a key to disk.
78          */
79         WERROR (*flush_key) (struct hive_key *key);
80
81         /**
82          * Retrieve a registry value with a specific index.
83          */
84         WERROR (*enum_value) (TALLOC_CTX *mem_ctx,
85                               struct hive_key *key, int idx,
86                               const char **name, uint32_t *type,
87                               DATA_BLOB *data);
88
89         /**
90          * Retrieve a registry value with the specified name
91          */
92         WERROR (*get_value_by_name) (TALLOC_CTX *mem_ctx,
93                                      struct hive_key *key, const char *name,
94                                      uint32_t *type, DATA_BLOB *data);
95
96         /**
97          * Set a value on the specified registry key.
98          */
99         WERROR (*set_value) (struct hive_key *key, const char *name,
100                              uint32_t type, const DATA_BLOB data);
101
102         /**
103          * Remove a value.
104          */
105         WERROR (*delete_value) (struct hive_key *key, const char *name);
106
107         /* Security Descriptors */
108
109         /**
110          * Change the security descriptor on a registry key.
111          *
112          * This should return WERR_NOT_SUPPORTED if the underlying
113          * format does not have a mechanism for storing
114          * security descriptors.
115          */
116         WERROR (*set_sec_desc) (struct hive_key *key,
117                                 const struct security_descriptor *desc);
118
119         /**
120          * Retrieve the security descriptor on a registry key.
121          *
122          * This should return WERR_NOT_SUPPORTED if the underlying
123          * format does not have a mechanism for storing
124          * security descriptors.
125          */
126         WERROR (*get_sec_desc) (TALLOC_CTX *ctx,
127                                 const struct hive_key *key,
128                                 struct security_descriptor **desc);
129
130         /**
131          * Retrieve general information about a key.
132          */
133         WERROR (*get_key_info) (TALLOC_CTX *mem_ctx,
134                                 const struct hive_key *key,
135                                 const char **classname,
136                                 uint32_t *num_subkeys,
137                                 uint32_t *num_values,
138                                 NTTIME *last_change_time,
139                                 uint32_t *max_subkeynamelen,
140                                 uint32_t *max_valnamelen,
141                                 uint32_t *max_valbufsize);
142 };
143
144 struct cli_credentials;
145 struct auth_session_info;
146
147 WERROR reg_open_hive(TALLOC_CTX *parent_ctx, const char *location,
148                      struct auth_session_info *session_info,
149                      struct cli_credentials *credentials,
150                      struct loadparm_context *lp_ctx,
151                      struct hive_key **root);
152 WERROR hive_key_get_info(TALLOC_CTX *mem_ctx, const struct hive_key *key,
153                          const char **classname, uint32_t *num_subkeys,
154                          uint32_t *num_values, NTTIME *last_change_time,
155                          uint32_t *max_subkeynamelen,
156                          uint32_t *max_valnamelen, uint32_t *max_valbufsize);
157 WERROR hive_key_add_name(TALLOC_CTX *ctx, const struct hive_key *parent_key,
158                          const char *name, const char *classname,
159                          struct security_descriptor *desc,
160                          struct hive_key **key);
161 WERROR hive_key_del(const struct hive_key *key, const char *name);
162 WERROR hive_get_key_by_name(TALLOC_CTX *mem_ctx,
163                             const struct hive_key *key, const char *name,
164                             struct hive_key **subkey);
165 WERROR hive_enum_key(TALLOC_CTX *mem_ctx,
166                      const struct hive_key *key, uint32_t idx,
167                      const char **name,
168                      const char **classname,
169                      NTTIME *last_mod_time);
170
171 WERROR hive_key_set_value(struct hive_key *key, const char *name,
172                       uint32_t type, const DATA_BLOB data);
173
174 WERROR hive_get_value(TALLOC_CTX *mem_ctx,
175                       struct hive_key *key, const char *name,
176                       uint32_t *type, DATA_BLOB *data);
177 WERROR hive_get_value_by_index(TALLOC_CTX *mem_ctx,
178                                struct hive_key *key, uint32_t idx,
179                                const char **name,
180                                uint32_t *type, DATA_BLOB *data);
181
182 WERROR hive_key_del_value(struct hive_key *key, const char *name);
183
184 WERROR hive_key_flush(struct hive_key *key);
185
186
187 /* Individual backends */
188 WERROR reg_open_directory(TALLOC_CTX *parent_ctx,
189                           const char *location, struct hive_key **key);
190 WERROR reg_open_regf_file(TALLOC_CTX *parent_ctx,
191                           const char *location, struct loadparm_context *lp_ctx,
192                           struct hive_key **key);
193 WERROR reg_open_ldb_file(TALLOC_CTX *parent_ctx, const char *location,
194                          struct auth_session_info *session_info,
195                          struct cli_credentials *credentials,
196                          struct loadparm_context *lp_ctx,
197                          struct hive_key **k);
198
199
200 WERROR reg_create_directory(TALLOC_CTX *parent_ctx,
201                             const char *location, struct hive_key **key);
202 WERROR reg_create_regf_file(TALLOC_CTX *parent_ctx,
203                             const char *location,
204                             int major_version,
205                             struct hive_key **key);
206
207
208 #endif /* __REGISTRY_HIVE_H__ */