2008-04-04 15:21:03 +04:00
/*
* Samba Unix / Linux SMB client library
* Distributed SMB / CIFS Server Management Utility
* registry utility functions
*
* Copyright ( C ) Michael Adam 2008
*
* 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
* the Free Software Foundation ; either version 3 of the License , or
* ( 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
* along with this program . If not , see < http : //www.gnu.org/licenses/>.
*/
# include "includes.h"
2009-10-02 02:17:06 +04:00
# include "registry.h"
2008-04-04 15:21:03 +04:00
# include "utils/net_registry_util.h"
2009-08-02 12:26:48 +04:00
# include "utils/net.h"
2011-02-26 02:28:15 +03:00
# include "../libcli/registry/util_reg.h"
2008-04-04 15:21:03 +04:00
void print_registry_key ( const char * keyname , NTTIME * modtime )
{
2011-07-15 10:20:12 +04:00
const char * ts = _ ( " None " ) ;
char * freeme = NULL ;
if ( modtime ! = 0 ) {
freeme = http_timestring ( talloc_tos ( ) ,
nt_time_to_unix ( * modtime ) ) ;
ts = freeme ;
}
2009-08-02 12:26:48 +04:00
d_printf ( _ ( " Keyname = %s \n " ) , keyname ) ;
2011-07-15 10:20:12 +04:00
d_printf ( _ ( " Modtime = %s \n " ) , ts ) ;
2008-04-04 15:21:03 +04:00
d_printf ( " \n " ) ;
2011-07-15 10:20:12 +04:00
TALLOC_FREE ( freeme ) ;
2008-04-04 15:21:03 +04:00
}
2008-05-15 14:55:54 +04:00
void print_registry_value ( const struct registry_value * valvalue , bool raw )
2008-04-04 15:21:03 +04:00
{
2008-05-15 14:55:54 +04:00
if ( ! raw ) {
2009-08-02 12:26:48 +04:00
d_printf ( _ ( " Type = %s \n " ) ,
2010-04-27 18:38:40 +04:00
str_regtype ( valvalue - > type ) ) ;
2008-05-15 14:55:54 +04:00
}
2008-04-04 15:21:03 +04:00
switch ( valvalue - > type ) {
2010-06-29 18:13:15 +04:00
case REG_DWORD : {
uint32_t v = 0 ;
if ( valvalue - > data . length > = 4 ) {
v = IVAL ( valvalue - > data . data , 0 ) ;
}
2008-05-15 14:55:54 +04:00
if ( ! raw ) {
2009-08-02 12:26:48 +04:00
d_printf ( _ ( " Value = " ) ) ;
2008-05-15 14:55:54 +04:00
}
2012-05-07 17:48:16 +04:00
d_printf ( " %u \n " , v ) ;
2008-04-04 15:21:03 +04:00
break ;
2010-06-29 18:13:15 +04:00
}
2008-04-04 15:21:03 +04:00
case REG_SZ :
2010-06-29 18:13:15 +04:00
case REG_EXPAND_SZ : {
const char * s ;
if ( ! pull_reg_sz ( talloc_tos ( ) , & valvalue - > data , & s ) ) {
break ;
}
2008-05-15 14:55:54 +04:00
if ( ! raw ) {
2009-08-02 12:26:48 +04:00
d_printf ( _ ( " Value = \" " ) ) ;
2008-05-15 14:55:54 +04:00
}
2010-06-29 18:13:15 +04:00
d_printf ( " %s " , s ) ;
2008-05-15 14:55:54 +04:00
if ( ! raw ) {
d_printf ( " \" " ) ;
}
d_printf ( " \n " ) ;
2008-04-04 15:21:03 +04:00
break ;
2010-06-29 18:13:15 +04:00
}
2008-04-04 15:21:03 +04:00
case REG_MULTI_SZ : {
2015-05-07 03:00:06 +03:00
uint32_t j ;
2010-06-29 18:13:15 +04:00
const char * * a ;
if ( ! pull_reg_multi_sz ( talloc_tos ( ) , & valvalue - > data , & a ) ) {
break ;
}
for ( j = 0 ; a [ j ] ! = NULL ; j + + ) {
2008-05-15 14:55:54 +04:00
if ( ! raw ) {
2009-08-02 12:26:48 +04:00
d_printf ( _ ( " Value[%3.3d] = \" " ) , j ) ;
2008-05-15 14:55:54 +04:00
}
2010-06-29 18:13:15 +04:00
d_printf ( " %s " , a [ j ] ) ;
2008-05-15 14:55:54 +04:00
if ( ! raw ) {
d_printf ( " \" " ) ;
}
d_printf ( " \n " ) ;
2008-04-04 15:21:03 +04:00
}
break ;
}
case REG_BINARY :
2008-05-15 14:55:54 +04:00
if ( ! raw ) {
2009-08-02 12:26:48 +04:00
d_printf ( _ ( " Value = " ) ) ;
2008-05-15 14:55:54 +04:00
}
2010-06-29 18:13:15 +04:00
d_printf ( _ ( " %d bytes \n " ) , ( int ) valvalue - > data . length ) ;
2008-04-04 15:21:03 +04:00
break ;
default :
2008-05-15 14:55:54 +04:00
if ( ! raw ) {
2009-08-02 12:26:48 +04:00
d_printf ( _ ( " Value = " ) ) ;
2008-05-15 14:55:54 +04:00
}
2009-08-02 12:26:48 +04:00
d_printf ( _ ( " <unprintable> \n " ) ) ;
2008-04-04 15:21:03 +04:00
break ;
}
2008-04-09 14:29:34 +04:00
}
void print_registry_value_with_name ( const char * valname ,
const struct registry_value * valvalue )
{
2009-08-02 12:26:48 +04:00
d_printf ( _ ( " Valuename = %s \n " ) , valname ) ;
2008-05-15 14:55:54 +04:00
print_registry_value ( valvalue , false ) ;
2008-04-04 15:21:03 +04:00
d_printf ( " \n " ) ;
}
/**
* Split path into hive name and subkeyname
* normalizations performed :
2010-06-25 19:26:34 +04:00
* - if the path contains no ' \\ ' characters ,
* assume that the legacy format of using ' / '
* as a separator is used and convert ' / ' to ' \\ '
2008-04-04 15:21:03 +04:00
* - strip trailing ' \\ ' chars
*/
WERROR split_hive_key ( TALLOC_CTX * ctx , const char * path , char * * hivename ,
2008-04-04 19:24:53 +04:00
char * * subkeyname )
2008-04-04 15:21:03 +04:00
{
char * p ;
2008-04-04 19:24:53 +04:00
const char * tmp_subkeyname ;
2008-04-04 15:21:03 +04:00
if ( ( path = = NULL ) | | ( hivename = = NULL ) | | ( subkeyname = = NULL ) ) {
2015-12-03 17:24:26 +03:00
return WERR_INVALID_PARAMETER ;
2008-04-04 15:21:03 +04:00
}
if ( strlen ( path ) = = 0 ) {
2015-12-03 17:24:26 +03:00
return WERR_INVALID_PARAMETER ;
2008-04-04 15:21:03 +04:00
}
2010-06-25 19:26:34 +04:00
if ( strchr ( path , ' \\ ' ) = = NULL ) {
* hivename = talloc_string_sub ( ctx , path , " / " , " \\ " ) ;
} else {
* hivename = talloc_strdup ( ctx , path ) ;
}
2008-04-04 15:21:03 +04:00
if ( * hivename = = NULL ) {
2015-12-03 17:24:17 +03:00
return WERR_NOT_ENOUGH_MEMORY ;
2008-04-04 15:21:03 +04:00
}
/* strip trailing '\\' chars */
p = strrchr ( * hivename , ' \\ ' ) ;
while ( ( p ! = NULL ) & & ( p [ 1 ] = = ' \0 ' ) ) {
* p = ' \0 ' ;
p = strrchr ( * hivename , ' \\ ' ) ;
}
p = strchr ( * hivename , ' \\ ' ) ;
if ( ( p = = NULL ) | | ( * p = = ' \0 ' ) ) {
/* just the hive - no subkey given */
2008-04-04 19:24:53 +04:00
tmp_subkeyname = " " ;
2008-04-04 15:21:03 +04:00
} else {
* p = ' \0 ' ;
2008-04-04 19:24:53 +04:00
tmp_subkeyname = p + 1 ;
}
* subkeyname = talloc_strdup ( ctx , tmp_subkeyname ) ;
if ( * subkeyname = = NULL ) {
2015-12-03 17:24:17 +03:00
return WERR_NOT_ENOUGH_MEMORY ;
2008-04-04 15:21:03 +04:00
}
return WERR_OK ;
}