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.
*
* 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"
2002-07-19 03:00:24 +04:00
# undef DBGC_CLASS
# define DBGC_CLASS DBGC_RPC_SRV
static SORTED_TREE * cache_tree ;
2002-07-19 22:49:44 +04:00
extern REGISTRY_OPS regdb_ops ; /* these are the default */
static REGISTRY_HOOK default_hook = { KEY_TREE_ROOT , & regdb_ops } ;
2002-07-19 03:00:24 +04:00
/**********************************************************************
Initialize the cache tree
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
BOOL reghook_cache_init ( void )
{
2005-09-04 01:53:20 +04:00
cache_tree = pathtree_init ( & default_hook , NULL ) ;
2002-07-19 03:00:24 +04:00
return ( cache_tree = = NULL ) ;
}
/**********************************************************************
Add a new REGISTRY_HOOK to the cache . Note that the keyname
is not in the exact format that a SORTED_TREE expects .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
BOOL reghook_cache_add ( REGISTRY_HOOK * hook )
{
pstring key ;
if ( ! hook )
return False ;
pstrcpy ( key , " \\ " ) ;
pstrcat ( key , hook - > keyname ) ;
pstring_sub ( key , " \\ " , " / " ) ;
DEBUG ( 10 , ( " reghook_cache_add: Adding key [%s] \n " , key ) ) ;
2005-02-23 19:36:44 +03:00
return pathtree_add ( cache_tree , key , hook ) ;
2002-07-19 03:00:24 +04:00
}
/**********************************************************************
Initialize the cache tree
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2005-06-09 19:20:11 +04:00
REGISTRY_HOOK * reghook_cache_find ( const char * keyname )
2002-07-19 03:00:24 +04:00
{
char * key ;
2002-07-20 02:16:03 +04:00
int len ;
2002-07-20 08:27:30 +04:00
REGISTRY_HOOK * hook ;
2002-07-19 03:00:24 +04:00
if ( ! keyname )
return NULL ;
2002-07-20 02:16:03 +04:00
2002-07-20 06:42:04 +04:00
/* prepend the string with a '\' character */
2002-07-20 02:16:03 +04:00
len = strlen ( keyname ) ;
2006-07-31 07:53:39 +04:00
if ( ! ( key = ( char * ) SMB_MALLOC ( len + 2 ) ) ) {
2002-07-20 02:16:03 +04:00
DEBUG ( 0 , ( " reghook_cache_find: malloc failed for string [%s] !?!?! \n " ,
2002-07-19 03:00:24 +04:00
keyname ) ) ;
return NULL ;
}
2002-07-20 02:16:03 +04:00
* key = ' \\ ' ;
strncpy ( key + 1 , keyname , len + 1 ) ;
2002-07-19 03:00:24 +04:00
2002-07-20 06:42:04 +04:00
/* swap to a form understood by the SORTED_TREE */
2002-07-19 03:00:24 +04:00
string_sub ( key , " \\ " , " / " , 0 ) ;
DEBUG ( 10 , ( " reghook_cache_find: Searching for keyname [%s] \n " , key ) ) ;
2006-07-31 07:53:39 +04:00
hook = ( REGISTRY_HOOK * ) pathtree_find ( cache_tree , key ) ;
2002-07-20 08:27:30 +04:00
SAFE_FREE ( key ) ;
return hook ;
2002-07-19 03:00:24 +04:00
}
/**********************************************************************
Initialize the cache tree
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void reghook_dump_cache ( int debuglevel )
{
DEBUG ( debuglevel , ( " reghook_dump_cache: Starting cache dump now... \n " ) ) ;
2005-02-23 19:36:44 +03:00
pathtree_print_keys ( cache_tree , debuglevel ) ;
2002-07-19 03:00:24 +04:00
}