2005-05-23 20:25:31 +04:00
/*
* Unix SMB / CIFS implementation .
* Virtual Windows Registry Layer ( utility functions )
* Copyright ( C ) Gerald Carter 2002 - 2005
*
* 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
2005-05-23 20:25:31 +04:00
* ( at your option ) any later version .
2007-11-27 04:24:56 +03:00
*
2005-05-23 20:25:31 +04:00
* 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 .
2007-11-27 04:24:56 +03:00
*
2005-05-23 20:25:31 +04:00
* 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/>.
2005-05-23 20:25:31 +04:00
*/
/* Implementation of registry frontend view functions. */
# include "includes.h"
2009-10-02 02:17:06 +04:00
# include "registry.h"
2010-05-25 02:04:13 +04:00
# include "reg_util_internal.h"
2005-05-23 20:25:31 +04:00
# undef DBGC_CLASS
2007-09-29 03:05:52 +04:00
# define DBGC_CLASS DBGC_REGISTRY
2005-05-23 20:25:31 +04:00
/***********************************************************************
Utility function for splitting the base path of a registry path off
by setting base and new_path to the apprapriate offsets withing the
path .
2007-11-27 04:24:56 +03:00
2005-05-23 20:25:31 +04:00
WARNING ! ! Does modify the original string !
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-11-27 04:24:56 +03:00
bool reg_split_path ( char * path , char * * base , char * * new_path )
2005-05-23 20:25:31 +04:00
{
char * p ;
2007-11-27 04:24:56 +03:00
2005-05-23 20:25:31 +04:00
* new_path = * base = NULL ;
2007-11-27 04:24:56 +03:00
if ( ! path ) {
return false ;
}
2005-05-23 20:25:31 +04:00
* base = path ;
2007-11-27 04:24:56 +03:00
p = strchr ( path , ' \\ ' ) ;
2005-05-23 20:25:31 +04:00
if ( p ) {
* p = ' \0 ' ;
* new_path = p + 1 ;
}
2007-11-27 04:24:56 +03:00
return true ;
}
2005-05-23 20:25:31 +04:00
/***********************************************************************
Utility function for splitting the base path of a registry path off
by setting base and new_path to the appropriate offsets withing the
path .
2007-11-27 04:24:56 +03:00
2005-05-23 20:25:31 +04:00
WARNING ! ! Does modify the original string !
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-11-27 04:24:56 +03:00
bool reg_split_key ( char * path , char * * base , char * * key )
2005-05-23 20:25:31 +04:00
{
char * p ;
2007-11-27 04:24:56 +03:00
2005-05-23 20:25:31 +04:00
* key = * base = NULL ;
2007-11-27 04:24:56 +03:00
if ( ! path ) {
return false ;
}
2005-05-23 20:25:31 +04:00
* base = path ;
2007-11-27 04:24:56 +03:00
p = strrchr ( path , ' \\ ' ) ;
if ( p ) {
2005-05-23 20:25:31 +04:00
* p = ' \0 ' ;
* key = p + 1 ;
}
2007-11-27 04:24:56 +03:00
return true ;
}
2005-05-23 20:25:31 +04:00
2008-05-07 00:20:49 +04:00
/**
2010-06-24 18:33:37 +04:00
* The full path to the registry key is used as database key .
* Leading and trailing ' \ ' characters are stripped .
2008-05-07 00:20:49 +04:00
* Key string is also normalized to UPPER case .
*/
2005-06-27 07:40:03 +04:00
2007-11-27 04:24:56 +03:00
char * normalize_reg_path ( TALLOC_CTX * ctx , const char * keyname )
2005-06-27 07:40:03 +04:00
{
2008-05-07 00:20:49 +04:00
char * p ;
char * nkeyname ;
2010-06-24 18:33:37 +04:00
/* skip leading '\' chars */
2008-05-07 00:20:49 +04:00
p = ( char * ) keyname ;
2010-06-24 18:33:37 +04:00
while ( * p = = ' \\ ' ) {
2008-05-07 00:20:49 +04:00
p + + ;
}
2010-06-24 18:33:37 +04:00
nkeyname = talloc_strdup ( ctx , p ) ;
2008-05-07 00:20:49 +04:00
if ( nkeyname = = NULL ) {
2007-11-27 04:24:56 +03:00
return NULL ;
}
2008-05-07 00:20:49 +04:00
2010-06-24 18:33:37 +04:00
/* strip trailing '\' chars */
p = strrchr ( nkeyname , ' \\ ' ) ;
2008-05-07 00:20:49 +04:00
while ( ( p ! = NULL ) & & ( p [ 1 ] = = ' \0 ' ) ) {
* p = ' \0 ' ;
2010-06-24 18:33:37 +04:00
p = strrchr ( nkeyname , ' \\ ' ) ;
2008-05-07 00:20:49 +04:00
}
2007-11-27 04:24:56 +03:00
strupper_m ( nkeyname ) ;
2008-05-07 00:20:49 +04:00
2007-11-27 04:24:56 +03:00
return nkeyname ;
2005-06-27 07:40:03 +04:00
}
2005-05-23 20:25:31 +04:00
2005-09-30 21:13:37 +04:00
/**********************************************************************
move to next non - delimter character
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-11-27 04:24:56 +03:00
char * reg_remaining_path ( TALLOC_CTX * ctx , const char * key )
2005-09-30 21:13:37 +04:00
{
2007-11-27 04:24:56 +03:00
char * new_path = NULL ;
char * p = NULL ;
if ( ! key | | ! * key ) {
2005-09-30 21:13:37 +04:00
return NULL ;
2007-11-27 04:24:56 +03:00
}
2005-09-30 21:13:37 +04:00
2007-11-27 04:24:56 +03:00
new_path = talloc_strdup ( ctx , key ) ;
if ( ! new_path ) {
return NULL ;
}
2005-09-30 21:13:37 +04:00
/* normalize_reg_path( new_path ); */
2007-11-27 04:24:56 +03:00
if ( ! ( p = strchr ( new_path , ' \\ ' ) ) ) {
2010-06-24 18:33:37 +04:00
p = new_path ;
2007-11-27 04:24:56 +03:00
} else {
2005-09-30 21:13:37 +04:00
p + + ;
2007-11-27 04:24:56 +03:00
}
return p ;
2005-09-30 21:13:37 +04:00
}