s4-dsdb/syntax: Map remote ATTIDs for Class OID syntax
[Samba.git] / source3 / registry / reg_dispatcher.c
bloba96047817d9a033f5704a285d5daf93edfd0c43a
1 /*
2 * Unix SMB/CIFS implementation.
3 * Virtual Windows Registry Layer
4 * Copyright (C) Gerald Carter 2002-2005
5 * Copyright (C) Michael Adam 2006-2008
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, see <http://www.gnu.org/licenses/>.
22 * Implementation of registry frontend view functions.
23 * Functions moved from reg_frontend.c to minimize linker deps.
26 #include "includes.h"
27 #include "registry.h"
28 #include "reg_dispatcher.h"
29 #include "../libcli/security/security.h"
31 #undef DBGC_CLASS
32 #define DBGC_CLASS DBGC_REGISTRY
34 static const struct generic_mapping reg_generic_map =
35 { REG_KEY_READ, REG_KEY_WRITE, REG_KEY_EXECUTE, REG_KEY_ALL };
37 /********************************************************************
38 ********************************************************************/
40 static WERROR construct_registry_sd(TALLOC_CTX *ctx, struct security_descriptor **psd)
42 struct security_ace ace[3];
43 size_t i = 0;
44 struct security_descriptor *sd;
45 struct security_acl *theacl;
46 size_t sd_size;
48 /* basic access for Everyone */
50 init_sec_ace(&ace[i++], &global_sid_World, SEC_ACE_TYPE_ACCESS_ALLOWED,
51 REG_KEY_READ, 0);
53 /* Full Access 'BUILTIN\Administrators' */
55 init_sec_ace(&ace[i++], &global_sid_Builtin_Administrators,
56 SEC_ACE_TYPE_ACCESS_ALLOWED, REG_KEY_ALL, 0);
58 /* Full Access 'NT Authority\System' */
60 init_sec_ace(&ace[i++], &global_sid_System, SEC_ACE_TYPE_ACCESS_ALLOWED,
61 REG_KEY_ALL, 0);
63 /* create the security descriptor */
65 theacl = make_sec_acl(ctx, NT4_ACL_REVISION, i, ace);
66 if (theacl == NULL) {
67 return WERR_NOMEM;
70 sd = make_sec_desc(ctx, SD_REVISION, SEC_DESC_SELF_RELATIVE,
71 &global_sid_Builtin_Administrators,
72 &global_sid_System, NULL, theacl,
73 &sd_size);
74 if (sd == NULL) {
75 return WERR_NOMEM;
78 *psd = sd;
79 return WERR_OK;
82 /***********************************************************************
83 High level wrapper function for storing registry subkeys
84 ***********************************************************************/
86 bool store_reg_keys(struct registry_key_handle *key,
87 struct regsubkey_ctr *subkeys)
89 if (key->ops && key->ops->store_subkeys)
90 return key->ops->store_subkeys(key->name, subkeys);
92 return false;
95 /***********************************************************************
96 High level wrapper function for storing registry values
97 ***********************************************************************/
99 bool store_reg_values(struct registry_key_handle *key, struct regval_ctr *val)
101 if (key->ops && key->ops->store_values)
102 return key->ops->store_values(key->name, val);
104 return false;
107 WERROR create_reg_subkey(struct registry_key_handle *key, const char *subkey)
109 if (key->ops && key->ops->create_subkey) {
110 return key->ops->create_subkey(key->name, subkey);
113 return WERR_NOT_SUPPORTED;
116 WERROR delete_reg_subkey(struct registry_key_handle *key, const char *subkey)
118 if (key->ops && key->ops->delete_subkey) {
119 return key->ops->delete_subkey(key->name, subkey);
122 return WERR_NOT_SUPPORTED;
125 /***********************************************************************
126 High level wrapper function for enumerating registry subkeys
127 Initialize the TALLOC_CTX if necessary
128 ***********************************************************************/
130 int fetch_reg_keys(struct registry_key_handle *key,
131 struct regsubkey_ctr *subkey_ctr)
133 int result = -1;
135 if (key->ops && key->ops->fetch_subkeys)
136 result = key->ops->fetch_subkeys(key->name, subkey_ctr);
138 return result;
141 /***********************************************************************
142 High level wrapper function for enumerating registry values
143 ***********************************************************************/
145 int fetch_reg_values(struct registry_key_handle *key, struct regval_ctr *val)
147 int result = -1;
149 DEBUG(10, ("fetch_reg_values called for key '%s' (ops %p)\n", key->name,
150 (key->ops) ? (void *)key->ops : NULL));
152 if (key->ops && key->ops->fetch_values)
153 result = key->ops->fetch_values(key->name, val);
155 return result;
158 /***********************************************************************
159 High level access check for passing the required access mask to the
160 underlying registry backend
161 ***********************************************************************/
163 bool regkey_access_check(struct registry_key_handle *key, uint32 requested,
164 uint32 *granted,
165 const struct security_token *token )
167 struct security_descriptor *sec_desc;
168 NTSTATUS status;
169 WERROR err;
171 /* root free-pass, like we have on all other pipes like samr, lsa, etc. */
172 if (geteuid() == sec_initial_uid()) {
173 *granted = REG_KEY_ALL;
174 return true;
177 /* use the default security check if the backend has not defined its
178 * own */
180 if (key->ops && key->ops->reg_access_check) {
181 return key->ops->reg_access_check(key->name, requested,
182 granted, token);
185 err = regkey_get_secdesc(talloc_tos(), key, &sec_desc);
187 if (!W_ERROR_IS_OK(err)) {
188 return false;
191 se_map_generic( &requested, &reg_generic_map );
193 status =se_access_check(sec_desc, token, requested, granted);
194 TALLOC_FREE(sec_desc);
195 if (!NT_STATUS_IS_OK(status)) {
196 return false;
199 return NT_STATUS_IS_OK(status);
202 WERROR regkey_get_secdesc(TALLOC_CTX *mem_ctx, struct registry_key_handle *key,
203 struct security_descriptor **psecdesc)
205 struct security_descriptor *secdesc;
206 WERROR werr;
208 if (key->ops && key->ops->get_secdesc) {
209 werr = key->ops->get_secdesc(mem_ctx, key->name, psecdesc);
210 if (W_ERROR_IS_OK(werr)) {
211 return WERR_OK;
215 werr = construct_registry_sd(mem_ctx, &secdesc);
216 if (!W_ERROR_IS_OK(werr)) {
217 return werr;
220 *psecdesc = secdesc;
221 return WERR_OK;
224 WERROR regkey_set_secdesc(struct registry_key_handle *key,
225 struct security_descriptor *psecdesc)
227 if (key->ops && key->ops->set_secdesc) {
228 return key->ops->set_secdesc(key->name, psecdesc);
231 return WERR_ACCESS_DENIED;
235 * Check whether the in-memory version of the subkyes of a
236 * registry key needs update from disk.
238 bool reg_subkeys_need_update(struct registry_key_handle *key,
239 struct regsubkey_ctr *subkeys)
241 if (key->ops && key->ops->subkeys_need_update)
243 return key->ops->subkeys_need_update(subkeys);
246 return false;
250 * Check whether the in-memory version of the values of a
251 * registry key needs update from disk.
253 bool reg_values_need_update(struct registry_key_handle *key,
254 struct regval_ctr *values)
256 if (key->ops && key->ops->values_need_update)
258 return key->ops->values_need_update(values);
261 return false;