2002-07-19 03:00:24 +04:00
/*
* Unix SMB / CIFS implementation .
2005-05-23 20:25:31 +04:00
* Virtual Windows Registry Layer
2002-07-19 03:00:24 +04:00
* Copyright ( C ) Gerald Carter 2002.
2010-05-23 15:28:05 +04:00
* Copyright ( C ) Michael Adam 2008
2002-07-19 03:00:24 +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
2007-07-09 23:25:36 +04:00
* the Free Software Foundation ; either version 3 of the License , or
2002-07-19 03:00:24 +04:00
* ( 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
2007-07-10 09:23:25 +04:00
* along with this program ; if not , see < http : //www.gnu.org/licenses/>.
2002-07-19 03:00:24 +04:00
*/
/* Implementation of registry hook cache tree */
# include "includes.h"
2005-02-23 19:36:44 +03:00
# include "adt_tree.h"
2009-10-02 02:17:06 +04:00
# include "registry.h"
2010-05-23 17:25:00 +04:00
# include "reg_cachehook.h"
2002-07-19 03:00:24 +04:00
# undef DBGC_CLASS
2007-09-29 03:05:52 +04:00
# define DBGC_CLASS DBGC_REGISTRY
2002-07-19 03:00:24 +04:00
2010-02-07 17:45:42 +03:00
static struct sorted_tree * cache_tree = NULL ;
2009-03-24 01:14:45 +03:00
extern struct registry_ops regdb_ops ; /* these are the default */
2002-07-19 03:00:24 +04:00
2008-04-13 16:49:32 +04:00
static WERROR keyname_to_path ( TALLOC_CTX * mem_ctx , const char * keyname ,
char * * path )
2008-04-13 03:40:45 +04:00
{
2008-04-13 16:49:32 +04:00
char * tmp_path = NULL ;
2008-04-13 03:40:45 +04:00
2008-04-13 16:49:32 +04:00
if ( ( keyname = = NULL ) | | ( path = = NULL ) ) {
2015-12-03 17:24:24 +03:00
return WERR_INVALID_PARAMETER ;
2008-04-13 03:40:45 +04:00
}
2008-04-13 16:49:32 +04:00
tmp_path = talloc_asprintf ( mem_ctx , " \\ %s " , keyname ) ;
if ( tmp_path = = NULL ) {
2008-04-13 03:47:16 +04:00
DEBUG ( 0 , ( " talloc_asprintf failed! \n " ) ) ;
2015-12-03 17:24:14 +03:00
return WERR_NOT_ENOUGH_MEMORY ;
2008-04-13 03:40:45 +04:00
}
2008-04-13 03:47:16 +04:00
2008-04-13 16:49:32 +04:00
* path = tmp_path ;
return WERR_OK ;
2008-04-13 03:40:45 +04:00
}
2002-07-19 03:00:24 +04:00
/**********************************************************************
2008-01-03 14:07:02 +03:00
Initialize the cache tree if it has not been initialized yet .
2002-07-19 03:00:24 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-04-13 16:18:06 +04:00
WERROR reghook_cache_init ( void )
2002-07-19 03:00:24 +04:00
{
2008-04-13 16:40:51 +04:00
if ( cache_tree ! = NULL ) {
return WERR_OK ;
2008-01-03 14:07:02 +03:00
}
2002-07-19 03:00:24 +04:00
2010-02-07 17:49:13 +03:00
cache_tree = pathtree_init ( & regdb_ops ) ;
2008-04-13 16:40:51 +04:00
if ( cache_tree = = NULL ) {
2015-12-03 17:24:14 +03:00
return WERR_NOT_ENOUGH_MEMORY ;
2008-04-13 16:40:51 +04:00
}
DEBUG ( 10 , ( " reghook_cache_init: new tree with default "
" ops %p for key [%s] \n " , ( void * ) & regdb_ops ,
KEY_TREE_ROOT ) ) ;
2008-04-13 16:18:06 +04:00
return WERR_OK ;
2002-07-19 03:00:24 +04:00
}
/**********************************************************************
2008-04-13 02:54:44 +04:00
Add a new registry hook to the cache . Note that the keyname
2010-02-07 17:45:42 +03:00
is not in the exact format that a struct sorted_tree expects .
2002-07-19 03:00:24 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-03-24 01:14:45 +03:00
WERROR reghook_cache_add ( const char * keyname , struct registry_ops * ops )
2002-07-19 03:00:24 +04:00
{
2008-04-13 16:41:44 +04:00
WERROR werr ;
2007-11-27 04:24:56 +03:00
char * key = NULL ;
2008-04-13 16:49:32 +04:00
if ( ( keyname = = NULL ) | | ( ops = = NULL ) ) {
2015-12-03 17:24:24 +03:00
return WERR_INVALID_PARAMETER ;
2007-11-27 04:24:56 +03:00
}
2002-07-19 03:00:24 +04:00
2008-04-13 16:49:32 +04:00
werr = keyname_to_path ( talloc_tos ( ) , keyname , & key ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
2008-01-18 18:08:52 +03:00
DEBUG ( 10 , ( " reghook_cache_add: Adding ops %p for key [%s] \n " ,
2008-04-13 02:54:44 +04:00
( void * ) ops , key ) ) ;
2007-11-27 04:24:56 +03:00
2012-03-24 19:41:35 +04:00
if ( ! pathtree_add ( cache_tree , key , ops ) )
2015-12-03 17:24:14 +03:00
werr = WERR_NOT_ENOUGH_MEMORY ;
2012-03-24 19:41:35 +04:00
else
werr = WERR_OK ;
2008-04-13 16:49:32 +04:00
done :
2008-04-13 03:42:46 +04:00
TALLOC_FREE ( key ) ;
2008-04-13 16:55:49 +04:00
return werr ;
2002-07-19 03:00:24 +04:00
}
/**********************************************************************
2008-04-13 03:32:51 +04:00
Find a key in the cache .
2002-07-19 03:00:24 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-03-24 01:14:45 +03:00
struct registry_ops * reghook_cache_find ( const char * keyname )
2002-07-19 03:00:24 +04:00
{
2008-04-13 16:49:32 +04:00
WERROR werr ;
char * key = NULL ;
2009-03-24 01:14:45 +03:00
struct registry_ops * ops = NULL ;
2008-04-13 03:40:45 +04:00
2008-04-13 16:49:32 +04:00
if ( keyname = = NULL ) {
2002-07-19 03:00:24 +04:00
return NULL ;
}
2002-07-20 02:16:03 +04:00
2008-04-13 16:49:32 +04:00
werr = keyname_to_path ( talloc_tos ( ) , keyname , & key ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
2002-07-19 03:00:24 +04:00
DEBUG ( 10 , ( " reghook_cache_find: Searching for keyname [%s] \n " , key ) ) ;
2008-04-13 03:44:57 +04:00
2009-03-24 01:14:45 +03:00
ops = ( struct registry_ops * ) pathtree_find ( cache_tree , key ) ;
2008-01-18 18:08:52 +03:00
DEBUG ( 10 , ( " reghook_cache_find: found ops %p for key [%s] \n " ,
2008-04-13 02:54:44 +04:00
ops ? ( void * ) ops : 0 , key ) ) ;
2008-04-13 03:44:57 +04:00
2008-04-13 16:49:32 +04:00
done :
2008-04-13 03:40:45 +04:00
TALLOC_FREE ( key ) ;
2008-04-13 03:44:57 +04:00
2008-04-13 02:54:44 +04:00
return ops ;
2002-07-19 03:00:24 +04:00
}
/**********************************************************************
2008-04-13 03:32:51 +04:00
Print out the cache tree structure for debugging .
2002-07-19 03:00:24 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void reghook_dump_cache ( int debuglevel )
{
DEBUG ( debuglevel , ( " reghook_dump_cache: Starting cache dump now... \n " ) ) ;
2008-04-13 03:44:57 +04:00
2005-02-23 19:36:44 +03:00
pathtree_print_keys ( cache_tree , debuglevel ) ;
2002-07-19 03:00:24 +04:00
}