2002-07-16 02:27:07 +04:00
/*
* Unix SMB / CIFS implementation .
2005-05-23 20:25:31 +04:00
* Virtual Windows Registry Layer
* Copyright ( C ) Gerald Carter 2002 - 2005
2002-07-16 02:27:07 +04:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 2 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
*/
2002-07-19 03:00:24 +04:00
/* Implementation of registry frontend view functions. */
2002-07-16 02:27:07 +04:00
# include "includes.h"
# undef DBGC_CLASS
# define DBGC_CLASS DBGC_RPC_SRV
2002-07-19 03:00:24 +04:00
extern REGISTRY_OPS printing_ops ;
2005-03-24 02:26:33 +03:00
extern REGISTRY_OPS eventlog_ops ;
2005-05-23 20:25:31 +04:00
extern REGISTRY_OPS shares_reg_ops ;
2006-11-30 10:38:40 +03:00
extern REGISTRY_OPS smbconf_reg_ops ;
2002-07-19 22:49:44 +04:00
extern REGISTRY_OPS regdb_ops ; /* these are the default */
2002-07-16 02:27:07 +04:00
2002-07-19 03:00:24 +04:00
/* array of REGISTRY_HOOK's which are read into a tree for easy access */
2005-06-29 20:35:32 +04:00
/* #define REG_TDB_ONLY 1 */
2002-07-16 02:27:07 +04:00
2002-07-19 03:00:24 +04:00
REGISTRY_HOOK reg_hooks [ ] = {
2005-06-29 20:35:32 +04:00
# ifndef REG_TDB_ONLY
2005-05-23 20:25:31 +04:00
{ KEY_PRINTING , & printing_ops } ,
{ KEY_PRINTING_2K , & printing_ops } ,
{ KEY_PRINTING_PORTS , & printing_ops } ,
{ KEY_SHARES , & shares_reg_ops } ,
2006-11-30 10:38:40 +03:00
{ KEY_SMBCONF , & smbconf_reg_ops } ,
2005-06-29 20:35:32 +04:00
# endif
2002-07-19 03:00:24 +04:00
{ NULL , NULL }
} ;
2002-07-16 02:27:07 +04:00
2002-07-23 08:55:06 +04:00
/***********************************************************************
Open the registry database and initialize the REGISTRY_HOOK cache
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
BOOL init_registry ( void )
{
int i ;
2005-09-30 21:13:37 +04:00
2006-12-03 20:16:45 +03:00
if ( ! regdb_init ( ) ) {
2006-12-03 20:34:11 +03:00
DEBUG ( 0 , ( " init_registry: failed to initialize the registry tdb! \n " ) ) ;
2006-12-03 20:16:45 +03:00
return False ;
}
2006-12-03 20:34:11 +03:00
/* build the cache tree of registry hooks */
reghook_cache_init ( ) ;
2002-07-23 08:55:06 +04:00
for ( i = 0 ; reg_hooks [ i ] . keyname ; i + + ) {
if ( ! reghook_cache_add ( & reg_hooks [ i ] ) )
return False ;
}
if ( DEBUGLEVEL > = 20 )
reghook_dump_cache ( 20 ) ;
2005-10-06 21:48:03 +04:00
/* add any keys for other services */
2005-09-30 21:13:37 +04:00
svcctl_init_keys ( ) ;
2005-10-06 21:48:03 +04:00
eventlog_init_keys ( ) ;
2005-11-08 19:33:45 +03:00
perfcount_init_keys ( ) ;
2005-09-30 21:13:37 +04:00
2005-10-07 16:14:25 +04:00
/* close and let each smbd open up as necessary */
regdb_close ( ) ;
2002-07-23 08:55:06 +04:00
return True ;
}
2006-12-01 23:01:09 +03:00
WERROR regkey_open_internal ( TALLOC_CTX * ctx , REGISTRY_KEY * * regkey ,
const char * path ,
const struct nt_user_token * token ,
uint32 access_desired )
2006-11-30 10:38:40 +03:00
{
2006-12-05 10:36:14 +03:00
struct registry_key * key ;
2006-11-30 10:38:40 +03:00
WERROR err ;
2006-12-05 10:36:14 +03:00
err = reg_open_path ( NULL , path , access_desired , token , & key ) ;
if ( ! W_ERROR_IS_OK ( err ) ) {
return err ;
2006-11-30 10:38:40 +03:00
}
2006-12-05 10:36:14 +03:00
* regkey = talloc_move ( ctx , & key - > key ) ;
TALLOC_FREE ( key ) ;
return WERR_OK ;
2006-11-30 10:38:40 +03:00
}
WERROR regkey_set_secdesc ( REGISTRY_KEY * key ,
struct security_descriptor * psecdesc )
{
if ( key - > hook & & key - > hook - > ops & & key - > hook - > ops - > set_secdesc ) {
return key - > hook - > ops - > set_secdesc ( key - > name , psecdesc ) ;
}
return WERR_ACCESS_DENIED ;
}
2006-12-03 19:19:15 +03:00
/*
* Utility function to create a registry key without opening the hive
* before . Assumes the hive already exists .
*/
WERROR reg_create_path ( TALLOC_CTX * mem_ctx , const char * orig_path ,
uint32 desired_access ,
const struct nt_user_token * token ,
enum winreg_CreateAction * paction ,
struct registry_key * * pkey )
{
struct registry_key * hive ;
char * path , * p ;
WERROR err ;
if ( ! ( path = SMB_STRDUP ( orig_path ) ) ) {
return WERR_NOMEM ;
}
p = strchr ( path , ' \\ ' ) ;
if ( ( p = = NULL ) | | ( p [ 1 ] = = ' \0 ' ) ) {
/*
* No key behind the hive , just return the hive
*/
err = reg_openhive ( mem_ctx , path , desired_access , token ,
& hive ) ;
if ( ! W_ERROR_IS_OK ( err ) ) {
SAFE_FREE ( path ) ;
return err ;
}
SAFE_FREE ( path ) ;
* pkey = hive ;
* paction = REG_OPENED_EXISTING_KEY ;
return WERR_OK ;
}
* p = ' \0 ' ;
err = reg_openhive ( mem_ctx , path ,
( strchr ( p + 1 , ' \\ ' ) ! = NULL ) ?
SEC_RIGHTS_ENUM_SUBKEYS : SEC_RIGHTS_CREATE_SUBKEY ,
token , & hive ) ;
if ( ! W_ERROR_IS_OK ( err ) ) {
SAFE_FREE ( path ) ;
return err ;
}
err = reg_createkey ( mem_ctx , hive , p + 1 , desired_access , pkey , paction ) ;
SAFE_FREE ( path ) ;
TALLOC_FREE ( hive ) ;
return err ;
}
/*
* Utility function to create a registry key without opening the hive
* before . Will not delete a hive .
*/
WERROR reg_delete_path ( const struct nt_user_token * token ,
const char * orig_path )
{
struct registry_key * hive ;
char * path , * p ;
WERROR err ;
if ( ! ( path = SMB_STRDUP ( orig_path ) ) ) {
return WERR_NOMEM ;
}
p = strchr ( path , ' \\ ' ) ;
if ( ( p = = NULL ) | | ( p [ 1 ] = = ' \0 ' ) ) {
2007-01-09 11:19:05 +03:00
SAFE_FREE ( path ) ;
2006-12-03 19:19:15 +03:00
return WERR_INVALID_PARAM ;
}
* p = ' \0 ' ;
err = reg_openhive ( NULL , path ,
( strchr ( p + 1 , ' \\ ' ) ! = NULL ) ?
SEC_RIGHTS_ENUM_SUBKEYS : SEC_RIGHTS_CREATE_SUBKEY ,
token , & hive ) ;
if ( ! W_ERROR_IS_OK ( err ) ) {
SAFE_FREE ( path ) ;
return err ;
}
err = reg_deletekey ( hive , p + 1 ) ;
SAFE_FREE ( path ) ;
TALLOC_FREE ( hive ) ;
return err ;
}