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