docs: ldbdel.1.xml: Correct meta data.
[Samba/gebeck_regimport.git] / source4 / lib / registry / hive.c
blobdc38fc82152f17fe93c4d75e8c9d13a8e16f08db
2 /*
3 Unix SMB/CIFS implementation.
4 Registry hive interface
5 Copyright (C) Jelmer Vernooij 2003-2007.
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.
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.
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.
22 #include "includes.h"
23 #include "registry.h"
24 #include "system/filesys.h"
25 #include "param/param.h"
27 /** Open a registry file/host/etc */
28 _PUBLIC_ WERROR reg_open_hive(TALLOC_CTX *parent_ctx, const char *location,
29 struct auth_session_info *session_info,
30 struct cli_credentials *credentials,
31 struct tevent_context *ev_ctx,
32 struct loadparm_context *lp_ctx,
33 struct hive_key **root)
35 int fd, num;
36 char peek[20];
38 fd = open(location, O_RDWR);
39 if (fd == -1) {
40 if (errno == ENOENT)
41 return WERR_BADFILE;
42 return WERR_BADFILE;
45 num = read(fd, peek, 20);
46 if (num == -1) {
47 return WERR_BADFILE;
50 if (!strncmp(peek, "regf", 4)) {
51 close(fd);
52 return reg_open_regf_file(parent_ctx, location, root);
53 } else if (!strncmp(peek, "TDB file", 8)) {
54 close(fd);
55 return reg_open_ldb_file(parent_ctx, location, session_info,
56 credentials, ev_ctx, lp_ctx, root);
59 return WERR_BADFILE;
62 _PUBLIC_ WERROR hive_key_get_info(TALLOC_CTX *mem_ctx,
63 const struct hive_key *key,
64 const char **classname, uint32_t *num_subkeys,
65 uint32_t *num_values,
66 NTTIME *last_change_time,
67 uint32_t *max_subkeynamelen,
68 uint32_t *max_valnamelen,
69 uint32_t *max_valbufsize)
71 return key->ops->get_key_info(mem_ctx, key, classname, num_subkeys,
72 num_values, last_change_time,
73 max_subkeynamelen,
74 max_valnamelen, max_valbufsize);
77 _PUBLIC_ WERROR hive_key_add_name(TALLOC_CTX *ctx,
78 const struct hive_key *parent_key,
79 const char *name, const char *classname,
80 struct security_descriptor *desc,
81 struct hive_key **key)
83 SMB_ASSERT(strchr(name, '\\') == NULL);
85 return parent_key->ops->add_key(ctx, parent_key, name, classname,
86 desc, key);
89 _PUBLIC_ WERROR hive_key_del(TALLOC_CTX *mem_ctx, const struct hive_key *key,
90 const char *name)
92 return key->ops->del_key(mem_ctx, key, name);
95 _PUBLIC_ WERROR hive_get_key_by_name(TALLOC_CTX *mem_ctx,
96 const struct hive_key *key,
97 const char *name,
98 struct hive_key **subkey)
100 return key->ops->get_key_by_name(mem_ctx, key, name, subkey);
103 WERROR hive_enum_key(TALLOC_CTX *mem_ctx,
104 const struct hive_key *key, uint32_t idx,
105 const char **name,
106 const char **classname,
107 NTTIME *last_mod_time)
109 return key->ops->enum_key(mem_ctx, key, idx, name, classname,
110 last_mod_time);
113 WERROR hive_key_set_value(struct hive_key *key, const char *name, uint32_t type,
114 const DATA_BLOB data)
116 if (key->ops->set_value == NULL)
117 return WERR_NOT_SUPPORTED;
119 return key->ops->set_value(key, name, type, data);
122 WERROR hive_get_value(TALLOC_CTX *mem_ctx,
123 struct hive_key *key, const char *name,
124 uint32_t *type, DATA_BLOB *data)
126 if (key->ops->get_value_by_name == NULL)
127 return WERR_NOT_SUPPORTED;
129 return key->ops->get_value_by_name(mem_ctx, key, name, type, data);
132 WERROR hive_get_value_by_index(TALLOC_CTX *mem_ctx,
133 struct hive_key *key, uint32_t idx,
134 const char **name,
135 uint32_t *type, DATA_BLOB *data)
137 if (key->ops->enum_value == NULL)
138 return WERR_NOT_SUPPORTED;
140 return key->ops->enum_value(mem_ctx, key, idx, name, type, data);
143 WERROR hive_get_sec_desc(TALLOC_CTX *mem_ctx,
144 struct hive_key *key,
145 struct security_descriptor **security)
147 if (key->ops->get_sec_desc == NULL)
148 return WERR_NOT_SUPPORTED;
150 return key->ops->get_sec_desc(mem_ctx, key, security);
153 WERROR hive_set_sec_desc(struct hive_key *key,
154 const struct security_descriptor *security)
156 if (key->ops->set_sec_desc == NULL)
157 return WERR_NOT_SUPPORTED;
159 return key->ops->set_sec_desc(key, security);
162 WERROR hive_key_del_value(TALLOC_CTX *mem_ctx, struct hive_key *key,
163 const char *name)
165 if (key->ops->delete_value == NULL)
166 return WERR_NOT_SUPPORTED;
168 return key->ops->delete_value(mem_ctx, key, name);
171 WERROR hive_key_flush(struct hive_key *key)
173 if (key->ops->flush_key == NULL)
174 return WERR_OK;
176 return key->ops->flush_key(key);