2 * Unix SMB/CIFS implementation.
3 * Virtual Windows Registry Layer
4 * Copyright (C) Gerald Carter 2002-2005
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.
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.
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.
21 /* Implementation of registry frontend view functions. */
26 #define DBGC_CLASS DBGC_RPC_SRV
28 extern REGISTRY_OPS printing_ops;
29 extern REGISTRY_OPS eventlog_ops;
30 extern REGISTRY_OPS shares_reg_ops;
31 extern REGISTRY_OPS smbconf_reg_ops;
32 extern REGISTRY_OPS regdb_ops; /* these are the default */
34 /* array of REGISTRY_HOOK's which are read into a tree for easy access */
35 /* #define REG_TDB_ONLY 1 */
37 REGISTRY_HOOK reg_hooks[] = {
39 { KEY_PRINTING, &printing_ops },
40 { KEY_PRINTING_2K, &printing_ops },
41 { KEY_PRINTING_PORTS, &printing_ops },
42 { KEY_SHARES, &shares_reg_ops },
43 { KEY_SMBCONF, &smbconf_reg_ops },
48 /***********************************************************************
49 Open the registry database and initialize the REGISTRY_HOOK cache
50 ***********************************************************************/
52 BOOL init_registry( void )
57 if ( !regdb_init() ) {
58 DEBUG(0,("init_registry: failed to initialize the registry tdb!\n"));
62 /* build the cache tree of registry hooks */
66 for ( i=0; reg_hooks[i].keyname; i++ ) {
67 if ( !reghook_cache_add(®_hooks[i]) )
71 if ( DEBUGLEVEL >= 20 )
72 reghook_dump_cache(20);
74 /* add any keys for other services */
78 perfcount_init_keys();
80 /* close and let each smbd open up as necessary */
87 WERROR regkey_open_internal( TALLOC_CTX *ctx, REGISTRY_KEY **regkey,
89 const struct nt_user_token *token,
90 uint32 access_desired )
92 struct registry_key *key;
95 err = reg_open_path(NULL, path, access_desired, token, &key);
96 if (!W_ERROR_IS_OK(err)) {
100 *regkey = talloc_move(ctx, &key->key);
105 WERROR regkey_set_secdesc(REGISTRY_KEY *key,
106 struct security_descriptor *psecdesc)
108 if (key->hook && key->hook->ops && key->hook->ops->set_secdesc) {
109 return key->hook->ops->set_secdesc(key->name, psecdesc);
112 return WERR_ACCESS_DENIED;
116 * Utility function to create a registry key without opening the hive
117 * before. Assumes the hive already exists.
120 WERROR reg_create_path(TALLOC_CTX *mem_ctx, const char *orig_path,
121 uint32 desired_access,
122 const struct nt_user_token *token,
123 enum winreg_CreateAction *paction,
124 struct registry_key **pkey)
126 struct registry_key *hive;
130 if (!(path = SMB_STRDUP(orig_path))) {
134 p = strchr(path, '\\');
136 if ((p == NULL) || (p[1] == '\0')) {
138 * No key behind the hive, just return the hive
141 err = reg_openhive(mem_ctx, path, desired_access, token,
143 if (!W_ERROR_IS_OK(err)) {
149 *paction = REG_OPENED_EXISTING_KEY;
155 err = reg_openhive(mem_ctx, path,
156 (strchr(p+1, '\\') != NULL) ?
157 SEC_RIGHTS_ENUM_SUBKEYS : SEC_RIGHTS_CREATE_SUBKEY,
159 if (!W_ERROR_IS_OK(err)) {
164 err = reg_createkey(mem_ctx, hive, p+1, desired_access, pkey, paction);
171 * Utility function to create a registry key without opening the hive
172 * before. Will not delete a hive.
175 WERROR reg_delete_path(const struct nt_user_token *token,
176 const char *orig_path)
178 struct registry_key *hive;
182 if (!(path = SMB_STRDUP(orig_path))) {
186 p = strchr(path, '\\');
188 if ((p == NULL) || (p[1] == '\0')) {
190 return WERR_INVALID_PARAM;
195 err = reg_openhive(NULL, path,
196 (strchr(p+1, '\\') != NULL) ?
197 SEC_RIGHTS_ENUM_SUBKEYS : SEC_RIGHTS_CREATE_SUBKEY,
199 if (!W_ERROR_IS_OK(err)) {
204 err = reg_deletekey(hive, p+1);