#include "includes.h"
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_RPC_SRV
extern REGISTRY_OPS printing_ops;
extern REGISTRY_OPS regdb_ops;
REGISTRY_HOOK reg_hooks[] = {
{ KEY_PRINTING, &printing_ops },
{ NULL, NULL }
};
BOOL init_registry( void )
{
int i;
if ( !init_registry_db() ) {
DEBUG(0,("init_registry: failed to initialize the registry tdb!\n"));
return False;
}
reghook_cache_init();
for ( i=0; reg_hooks[i].keyname; i++ ) {
if ( !reghook_cache_add(®_hooks[i]) )
return False;
}
if ( SAMBA_DEBUGLEVEL >= 20 )
reghook_dump_cache(20);
return True;
}
BOOL store_reg_keys( REGISTRY_KEY *key, REGSUBKEY_CTR *subkeys )
{
if ( key->hook && key->hook->ops && key->hook->ops->store_subkeys_fn )
return key->hook->ops->store_subkeys_fn( key->name, subkeys );
else
return False;
}
BOOL store_reg_values( REGISTRY_KEY *key, REGVAL_CTR *val )
{
if ( key->hook && key->hook->ops && key->hook->ops->store_values_fn )
return key->hook->ops->store_values_fn( key->name, val );
else
return False;
}
int fetch_reg_keys( REGISTRY_KEY *key, REGSUBKEY_CTR *subkey_ctr )
{
int result = -1;
if ( key->hook && key->hook->ops && key->hook->ops->subkey_fn )
result = key->hook->ops->subkey_fn( key->name, subkey_ctr );
return result;
}
BOOL fetch_reg_keys_specific( REGISTRY_KEY *key, char** subkey, uint32 key_index )
{
static REGSUBKEY_CTR ctr;
static pstring save_path;
static BOOL ctr_init = False;
char *s;
*subkey = NULL;
if ( !ctr_init ) {
DEBUG(8,("fetch_reg_keys_specific: Initializing cache of subkeys for [%s]\n", key->name));
ZERO_STRUCTP( &ctr );
regsubkey_ctr_init( &ctr );
pstrcpy( save_path, key->name );
if ( fetch_reg_keys( key, &ctr) == -1 )
return False;
ctr_init = True;
}
else if ( !key_index || StrCaseCmp( save_path, key->name) ) {
DEBUG(8,("fetch_reg_keys_specific: Updating cache of subkeys for [%s]\n", key->name));
regsubkey_ctr_destroy( &ctr );
regsubkey_ctr_init( &ctr );
pstrcpy( save_path, key->name );
if ( fetch_reg_keys( key, &ctr) == -1 )
return False;
}
if ( !(s = regsubkey_ctr_specific_key( &ctr, key_index )) )
return False;
*subkey = SMB_STRDUP( s );
return True;
}
int fetch_reg_values( REGISTRY_KEY *key, REGVAL_CTR *val )
{
int result = -1;
if ( key->hook && key->hook->ops && key->hook->ops->value_fn )
result = key->hook->ops->value_fn( key->name, val );
return result;
}
BOOL fetch_reg_values_specific( REGISTRY_KEY *key, REGISTRY_VALUE **val, uint32 val_index )
{
static REGVAL_CTR ctr;
static pstring save_path;
static BOOL ctr_init = False;
REGISTRY_VALUE *v;
*val = NULL;
if ( !ctr_init ) {
DEBUG(8,("fetch_reg_values_specific: Initializing cache of values for [%s]\n", key->name));
ZERO_STRUCTP( &ctr );
regval_ctr_init( &ctr );
pstrcpy( save_path, key->name );
if ( fetch_reg_values( key, &ctr) == -1 )
return False;
ctr_init = True;
}
else if ( !val_index || StrCaseCmp(save_path, key->name) ) {
DEBUG(8,("fetch_reg_values_specific: Updating cache of values for [%s]\n", key->name));
regval_ctr_destroy( &ctr );
regval_ctr_init( &ctr );
pstrcpy( save_path, key->name );
if ( fetch_reg_values( key, &ctr) == -1 )
return False;
}
if ( !(v = regval_ctr_specific_value( &ctr, val_index )) )
return False;
*val = dup_registry_value( v );
return True;
}
BOOL reg_split_path( char *path, char **base, char **new_path )
{
char *p;
*new_path = *base = NULL;
if ( !path)
return False;
*base = path;
p = strchr( path, '\\' );
if ( p ) {
*p = '\0';
*new_path = p+1;
}
return True;
}