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
},
42 { KEY_EVENTLOG
, &eventlog_ops
},
44 { KEY_SHARES
, &shares_reg_ops
},
50 /***********************************************************************
51 Open the registry database and initialize the REGISTRY_HOOK cache
52 ***********************************************************************/
54 BOOL
init_registry( void )
58 if ( !init_registry_db() ) {
59 DEBUG(0,("init_registry: failed to initialize the registry tdb!\n"));
62 /* initialize eventlog related "registry entries" */
63 init_eventlog_parameters();
64 /* inform the external eventlog machinery of the change */
65 eventlog_refresh_external_parameters();
67 /* build the cache tree of registry hooks */
71 for ( i
=0; reg_hooks
[i
].keyname
; i
++ ) {
72 if ( !reghook_cache_add(®_hooks
[i
]) )
76 if ( DEBUGLEVEL
>= 20 )
77 reghook_dump_cache(20);
82 /***********************************************************************
83 High level wrapper function for storing registry subkeys
84 ***********************************************************************/
86 BOOL
store_reg_keys( REGISTRY_KEY
*key
, REGSUBKEY_CTR
*subkeys
)
88 if ( key
->hook
&& key
->hook
->ops
&& key
->hook
->ops
->store_subkeys
)
89 return key
->hook
->ops
->store_subkeys( key
->name
, subkeys
);
95 /***********************************************************************
96 High level wrapper function for storing registry values
97 ***********************************************************************/
99 BOOL
store_reg_values( REGISTRY_KEY
*key
, REGVAL_CTR
*val
)
101 if ( check_dynamic_reg_values( key
) )
104 if ( key
->hook
&& key
->hook
->ops
&& key
->hook
->ops
->store_values
)
105 return key
->hook
->ops
->store_values( key
->name
, val
);
111 /***********************************************************************
112 High level wrapper function for enumerating registry subkeys
113 Initialize the TALLOC_CTX if necessary
114 ***********************************************************************/
116 int fetch_reg_keys( REGISTRY_KEY
*key
, REGSUBKEY_CTR
*subkey_ctr
)
120 if ( key
->hook
&& key
->hook
->ops
&& key
->hook
->ops
->fetch_subkeys
)
121 result
= key
->hook
->ops
->fetch_subkeys( key
->name
, subkey_ctr
);
126 /***********************************************************************
127 retreive a specific subkey specified by index. Caller is
128 responsible for freeing memory
129 ***********************************************************************/
131 BOOL
fetch_reg_keys_specific( REGISTRY_KEY
*key
, char** subkey
, uint32 key_index
)
133 static REGSUBKEY_CTR
*ctr
= NULL
;
134 static pstring save_path
;
139 /* simple caching for performance; very basic heuristic */
141 DEBUG(8,("fetch_reg_keys_specific: Looking for key [%d] of [%s]\n", key_index
, key
->name
));
144 DEBUG(8,("fetch_reg_keys_specific: Initializing cache of subkeys for [%s]\n", key
->name
));
146 if ( !(ctr
= TALLOC_ZERO_P( NULL
, REGSUBKEY_CTR
)) ) {
147 DEBUG(0,("fetch_reg_keys_specific: talloc() failed!\n"));
151 pstrcpy( save_path
, key
->name
);
153 if ( fetch_reg_keys( key
, ctr
) == -1 )
157 /* clear the cache when key_index == 0 or the path has changed */
158 else if ( !key_index
|| StrCaseCmp( save_path
, key
->name
) ) {
160 DEBUG(8,("fetch_reg_keys_specific: Updating cache of subkeys for [%s]\n", key
->name
));
164 if ( !(ctr
= TALLOC_ZERO_P( NULL
, REGSUBKEY_CTR
)) ) {
165 DEBUG(0,("fetch_reg_keys_specific: talloc() failed!\n"));
169 pstrcpy( save_path
, key
->name
);
171 if ( fetch_reg_keys( key
, ctr
) == -1 )
175 if ( !(s
= regsubkey_ctr_specific_key( ctr
, key_index
)) )
178 *subkey
= SMB_STRDUP( s
);
183 /***********************************************************************
184 High level wrapper function for enumerating registry values
185 ***********************************************************************/
187 int fetch_reg_values( REGISTRY_KEY
*key
, REGVAL_CTR
*val
)
191 if ( key
->hook
&& key
->hook
->ops
&& key
->hook
->ops
->fetch_values
)
192 result
= key
->hook
->ops
->fetch_values( key
->name
, val
);
194 /* if the backend lookup returned no data, try the dynamic overlay */
197 result
= fetch_dynamic_reg_values( key
, val
);
199 return ( result
!= -1 ) ? result
: 0;
206 /***********************************************************************
207 retreive a specific subkey specified by index. Caller is
208 responsible for freeing memory
209 ***********************************************************************/
211 BOOL
fetch_reg_values_specific( REGISTRY_KEY
*key
, REGISTRY_VALUE
**val
, uint32 val_index
)
213 static REGVAL_CTR
*ctr
= NULL
;
214 static pstring save_path
;
219 /* simple caching for performance; very basic heuristic */
222 DEBUG(8,("fetch_reg_values_specific: Initializing cache of values for [%s]\n", key
->name
));
224 if ( !(ctr
= TALLOC_ZERO_P( NULL
, REGVAL_CTR
)) ) {
225 DEBUG(0,("fetch_reg_values_specific: talloc() failed!\n"));
229 pstrcpy( save_path
, key
->name
);
231 if ( fetch_reg_values( key
, ctr
) == -1 )
234 /* clear the cache when val_index == 0 or the path has changed */
235 else if ( !val_index
|| !strequal(save_path
, key
->name
) ) {
237 DEBUG(8,("fetch_reg_values_specific: Updating cache of values for [%s]\n", key
->name
));
241 if ( !(ctr
= TALLOC_ZERO_P( NULL
, REGVAL_CTR
)) ) {
242 DEBUG(0,("fetch_reg_values_specific: talloc() failed!\n"));
246 pstrcpy( save_path
, key
->name
);
248 if ( fetch_reg_values( key
, ctr
) == -1 )
252 if ( !(v
= regval_ctr_specific_value( ctr
, val_index
)) )
255 *val
= dup_registry_value( v
);
260 /***********************************************************************
261 High level access check for passing the required access mask to the
262 underlying registry backend
263 ***********************************************************************/
265 BOOL
regkey_access_check( REGISTRY_KEY
*key
, uint32 requested
, uint32
*granted
, NT_USER_TOKEN
*token
)
267 /* use the default security check if the backend has not defined its own */
269 if ( !(key
->hook
&& key
->hook
->ops
&& key
->hook
->ops
->reg_access_check
) ) {
273 if ( !(sec_desc
= construct_registry_sd( get_talloc_ctx() )) )
276 status
= registry_access_check( sec_desc
, token
, requested
, granted
);
278 return NT_STATUS_IS_OK(status
);
281 return key
->hook
->ops
->reg_access_check( key
->name
, requested
, granted
, token
);