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 regdb_ops; /* these are the default */
33 /* array of REGISTRY_HOOK's which are read into a tree for easy access */
34 /* #define REG_TDB_ONLY 1 */
36 REGISTRY_HOOK reg_hooks[] = {
38 { KEY_PRINTING, &printing_ops },
39 { KEY_PRINTING_2K, &printing_ops },
40 { KEY_PRINTING_PORTS, &printing_ops },
41 { KEY_EVENTLOG, &eventlog_ops },
42 { KEY_SHARES, &shares_reg_ops },
48 /***********************************************************************
49 Open the registry database and initialize the REGISTRY_HOOK cache
50 ***********************************************************************/
52 BOOL init_registry( void )
56 if ( !init_registry_db() ) {
57 DEBUG(0,("init_registry: failed to initialize the registry tdb!\n"));
61 /* build the cache tree of registry hooks */
65 for ( i=0; reg_hooks[i].keyname; i++ ) {
66 if ( !reghook_cache_add(®_hooks[i]) )
70 if ( DEBUGLEVEL >= 20 )
71 reghook_dump_cache(20);
76 /***********************************************************************
77 High level wrapper function for storing registry subkeys
78 ***********************************************************************/
80 BOOL store_reg_keys( REGISTRY_KEY *key, REGSUBKEY_CTR *subkeys )
82 if ( key->hook && key->hook->ops && key->hook->ops->store_subkeys )
83 return key->hook->ops->store_subkeys( key->name, subkeys );
89 /***********************************************************************
90 High level wrapper function for storing registry values
91 ***********************************************************************/
93 BOOL store_reg_values( REGISTRY_KEY *key, REGVAL_CTR *val )
95 if ( check_dynamic_reg_values( key ) )
98 if ( key->hook && key->hook->ops && key->hook->ops->store_values )
99 return key->hook->ops->store_values( key->name, val );
105 /***********************************************************************
106 High level wrapper function for enumerating registry subkeys
107 Initialize the TALLOC_CTX if necessary
108 ***********************************************************************/
110 int fetch_reg_keys( REGISTRY_KEY *key, REGSUBKEY_CTR *subkey_ctr )
114 if ( key->hook && key->hook->ops && key->hook->ops->fetch_subkeys )
115 result = key->hook->ops->fetch_subkeys( key->name, subkey_ctr );
120 /***********************************************************************
121 retreive a specific subkey specified by index. Caller is
122 responsible for freeing memory
123 ***********************************************************************/
125 BOOL fetch_reg_keys_specific( REGISTRY_KEY *key, char** subkey, uint32 key_index )
127 static REGSUBKEY_CTR ctr;
128 static pstring save_path;
129 static BOOL ctr_init = False;
134 /* simple caching for performance; very basic heuristic */
136 DEBUG(8,("fetch_reg_keys_specific: Looking for key [%d] of [%s]\n", key_index, key->name));
139 DEBUG(8,("fetch_reg_keys_specific: Initializing cache of subkeys for [%s]\n", key->name));
140 regsubkey_ctr_init( &ctr );
142 pstrcpy( save_path, key->name );
144 if ( fetch_reg_keys( key, &ctr) == -1 )
149 /* clear the cache when key_index == 0 or the path has changed */
150 else if ( !key_index || StrCaseCmp( save_path, key->name) ) {
152 DEBUG(8,("fetch_reg_keys_specific: Updating cache of subkeys for [%s]\n", key->name));
154 regsubkey_ctr_destroy( &ctr );
155 regsubkey_ctr_init( &ctr );
157 pstrcpy( save_path, key->name );
159 if ( fetch_reg_keys( key, &ctr) == -1 )
163 if ( !(s = regsubkey_ctr_specific_key( &ctr, key_index )) )
166 *subkey = SMB_STRDUP( s );
171 /***********************************************************************
172 High level wrapper function for enumerating registry values
173 ***********************************************************************/
175 int fetch_reg_values( REGISTRY_KEY *key, REGVAL_CTR *val )
179 if ( key->hook && key->hook->ops && key->hook->ops->fetch_values )
180 result = key->hook->ops->fetch_values( key->name, val );
182 /* if the backend lookup returned no data, try the dynamic overlay */
185 result = fetch_dynamic_reg_values( key, val );
187 return ( result != -1 ) ? result : 0;
194 /***********************************************************************
195 retreive a specific subkey specified by index. Caller is
196 responsible for freeing memory
197 ***********************************************************************/
199 BOOL fetch_reg_values_specific( REGISTRY_KEY *key, REGISTRY_VALUE **val, uint32 val_index )
201 static REGVAL_CTR ctr;
202 static pstring save_path;
203 static BOOL ctr_init = False;
208 /* simple caching for performance; very basic heuristic */
211 DEBUG(8,("fetch_reg_values_specific: Initializing cache of values for [%s]\n", key->name));
213 regval_ctr_init( &ctr );
215 pstrcpy( save_path, key->name );
217 if ( fetch_reg_values( key, &ctr) == -1 )
222 /* clear the cache when val_index == 0 or the path has changed */
223 else if ( !val_index || !strequal(save_path, key->name) ) {
225 DEBUG(8,("fetch_reg_values_specific: Updating cache of values for [%s]\n", key->name));
227 regval_ctr_destroy( &ctr );
228 regval_ctr_init( &ctr );
230 pstrcpy( save_path, key->name );
232 if ( fetch_reg_values( key, &ctr) == -1 )
236 if ( !(v = regval_ctr_specific_value( &ctr, val_index )) )
239 *val = dup_registry_value( v );
244 /***********************************************************************
245 High level access check for passing the required access mask to the
246 underlying registry backend
247 ***********************************************************************/
249 BOOL regkey_access_check( REGISTRY_KEY *key, uint32 requested, uint32 *granted, NT_USER_TOKEN *token )
251 /* use the default security check if the backend has not defined its own */
253 if ( !(key->hook && key->hook->ops && key->hook->ops->reg_access_check) ) {
257 if ( !(sec_desc = construct_registry_sd( get_talloc_ctx() )) )
260 status = registry_access_check( sec_desc, token, requested, granted );
262 return NT_STATUS_IS_OK(status);
265 return key->hook->ops->reg_access_check( key->name, requested, granted, token );