1998-11-09 19:40:38 +03:00
/*
Unix SMB / Netbios implementation .
Version 1.9 .
NT Domain Authentication SMB / MSRPC client
Copyright ( C ) Andrew Tridgell 1994 - 1997
Copyright ( C ) Luke Kenneth Casson Leighton 1996 - 1997
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 2 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 , write to the Free Software
Foundation , Inc . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
*/
# ifdef SYSLOG
# undef SYSLOG
# endif
# include "includes.h"
# include "nterr.h"
extern int DEBUGLEVEL ;
extern struct cli_state * smb_cli ;
extern int smb_tidx ;
extern FILE * out_hnd ;
1998-11-11 17:23:55 +03:00
/*
* keys . of the form :
* - - - -
*
* [ HKLM ] | [ HKU ] \ [ parent_keyname_components ] \ [ subkey ] | [ value ]
*
* reg_getsubkey ( ) splits this down into :
* [ HKLM ] | [ HKU ] \ [ parent_keyname_components ] and [ subkey ] | [ value ]
*
* do_reg_connect ( ) splits the left side down further into :
* [ HKLM ] | [ HKU ] and [ parent_keyname_components ] .
*
* HKLM is short for HKEY_LOCAL_MACHINE
* HKU is short for HKEY_USERS
*
* oh , and HKEY stands for " Hive Key " .
*
*/
1998-11-09 19:40:38 +03:00
/****************************************************************************
nt registry enum
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void cmd_reg_enum ( struct client_info * info )
{
1998-12-07 23:23:41 +03:00
uint16 fnum ;
1998-11-09 19:40:38 +03:00
BOOL res = True ;
BOOL res1 = True ;
BOOL res2 = True ;
int i ;
POLICY_HND key_pol ;
1998-11-11 17:23:55 +03:00
fstring full_keyname ;
1998-11-09 19:40:38 +03:00
fstring key_name ;
/*
* query key info
*/
1998-11-10 22:05:00 +03:00
fstring key_class ;
uint32 max_class_len = 0 ;
1998-11-09 19:40:38 +03:00
uint32 num_subkeys ;
uint32 max_subkeylen ;
1998-11-10 22:05:00 +03:00
uint32 max_subkeysize ;
1998-11-09 19:40:38 +03:00
uint32 num_values ;
uint32 max_valnamelen ;
uint32 max_valbufsize ;
1998-11-10 22:05:00 +03:00
uint32 sec_desc ;
1998-11-09 19:40:38 +03:00
NTTIME mod_time ;
/*
* unknown 0x1a request
*/
uint32 unk_1a_response ;
DEBUG ( 5 , ( " cmd_reg_enum: smb_cli->fd:%d \n " , smb_cli - > fd ) ) ;
1998-11-11 17:23:55 +03:00
if ( ! next_token ( NULL , full_keyname , NULL , sizeof ( full_keyname ) ) )
1998-11-09 19:40:38 +03:00
{
1998-11-11 17:23:55 +03:00
fprintf ( out_hnd , " regenum <key_name> \n " ) ;
1998-11-09 19:40:38 +03:00
return ;
}
/* open WINREG session. */
1998-12-07 23:23:41 +03:00
res = res ? cli_nt_session_open ( smb_cli , PIPE_WINREG , & fnum ) : False ;
1998-11-09 19:40:38 +03:00
/* open registry receive a policy handle */
1998-12-07 23:23:41 +03:00
res = res ? do_reg_connect ( smb_cli , fnum , full_keyname , key_name ,
1998-11-09 19:40:38 +03:00
& info - > dom . reg_pol_connect ) : False ;
1998-11-11 17:23:55 +03:00
if ( ( * key_name ) ! = 0 )
{
/* open an entry */
1998-12-07 23:23:41 +03:00
res1 = res ? do_reg_open_entry ( smb_cli , fnum , & info - > dom . reg_pol_connect ,
1998-11-11 17:23:55 +03:00
key_name , 0x02000000 , & key_pol ) : False ;
}
else
{
memcpy ( & key_pol , & info - > dom . reg_pol_connect , sizeof ( key_pol ) ) ;
}
1998-11-09 19:40:38 +03:00
1998-12-07 23:23:41 +03:00
res1 = res1 ? do_reg_query_key ( smb_cli , fnum ,
1998-11-09 19:40:38 +03:00
& key_pol ,
1998-11-10 22:05:00 +03:00
key_class , & max_class_len ,
& num_subkeys , & max_subkeylen , & max_subkeysize ,
& num_values , & max_valnamelen , & max_valbufsize ,
& sec_desc , & mod_time ) : False ;
1998-11-09 19:40:38 +03:00
1998-11-11 17:23:55 +03:00
if ( res1 & & num_subkeys > 0 )
{
fprintf ( out_hnd , " Subkeys \n " ) ;
fprintf ( out_hnd , " ------- \n " ) ;
}
1998-11-09 19:40:38 +03:00
for ( i = 0 ; i < num_subkeys ; i + + )
{
/*
* enumerate key
*/
fstring enum_name ;
uint32 enum_unk1 ;
uint32 enum_unk2 ;
time_t key_mod_time ;
/* unknown 1a it */
1998-12-07 23:23:41 +03:00
res2 = res1 ? do_reg_unknown_1a ( smb_cli , fnum , & key_pol ,
1998-11-09 19:40:38 +03:00
& unk_1a_response ) : False ;
if ( res2 & & unk_1a_response ! = 5 )
{
fprintf ( out_hnd , " Unknown 1a response: %x \n " , unk_1a_response ) ;
}
/* enum key */
1998-12-07 23:23:41 +03:00
res2 = res2 ? do_reg_enum_key ( smb_cli , fnum , & key_pol ,
1998-11-09 19:40:38 +03:00
i , enum_name ,
& enum_unk1 , & enum_unk2 ,
& key_mod_time ) : False ;
if ( res2 )
{
display_reg_key_info ( out_hnd , ACTION_HEADER , enum_name , key_mod_time ) ;
display_reg_key_info ( out_hnd , ACTION_ENUMERATE , enum_name , key_mod_time ) ;
display_reg_key_info ( out_hnd , ACTION_FOOTER , enum_name , key_mod_time ) ;
}
}
1998-11-11 17:23:55 +03:00
if ( num_values > 0 )
{
fprintf ( out_hnd , " Key Values \n " ) ;
fprintf ( out_hnd , " ---------- \n " ) ;
}
1998-11-09 19:40:38 +03:00
for ( i = 0 ; i < num_values ; i + + )
{
/*
* enumerate key
*/
uint32 val_type ;
BUFFER2 value ;
fstring val_name ;
/* unknown 1a it */
1998-12-07 23:23:41 +03:00
res2 = res1 ? do_reg_unknown_1a ( smb_cli , fnum , & key_pol ,
1998-11-09 19:40:38 +03:00
& unk_1a_response ) : False ;
if ( res2 & & unk_1a_response ! = 5 )
{
fprintf ( out_hnd , " Unknown 1a response: %x \n " , unk_1a_response ) ;
}
/* enum key */
1998-12-07 23:23:41 +03:00
res2 = res2 ? do_reg_enum_val ( smb_cli , fnum , & key_pol ,
1998-11-09 19:40:38 +03:00
i , max_valnamelen , max_valbufsize ,
val_name , & val_type , & value ) : False ;
if ( res2 )
{
display_reg_value_info ( out_hnd , ACTION_HEADER , val_name , val_type , & value ) ;
display_reg_value_info ( out_hnd , ACTION_ENUMERATE , val_name , val_type , & value ) ;
display_reg_value_info ( out_hnd , ACTION_FOOTER , val_name , val_type , & value ) ;
}
}
/* close the handles */
1998-11-11 17:23:55 +03:00
if ( ( * key_name ) ! = 0 )
{
1998-12-07 23:23:41 +03:00
res1 = res1 ? do_reg_close ( smb_cli , fnum , & key_pol ) : False ;
1998-11-11 17:23:55 +03:00
}
1998-12-07 23:23:41 +03:00
res = res ? do_reg_close ( smb_cli , fnum , & info - > dom . reg_pol_connect ) : False ;
1998-11-09 19:40:38 +03:00
/* close the session */
1998-12-07 23:23:41 +03:00
cli_nt_session_close ( smb_cli , fnum ) ;
1998-11-09 19:40:38 +03:00
if ( res & & res1 & & res2 )
{
DEBUG ( 5 , ( " cmd_reg_enum: query succeeded \n " ) ) ;
}
else
{
DEBUG ( 5 , ( " cmd_reg_enum: query failed \n " ) ) ;
}
}
1998-11-10 22:05:00 +03:00
/****************************************************************************
nt registry query key
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void cmd_reg_query_key ( struct client_info * info )
{
1998-12-07 23:23:41 +03:00
uint16 fnum ;
1998-11-10 22:05:00 +03:00
BOOL res = True ;
BOOL res1 = True ;
POLICY_HND key_pol ;
1998-11-11 17:23:55 +03:00
fstring full_keyname ;
1998-11-10 22:05:00 +03:00
fstring key_name ;
/*
* query key info
*/
fstring key_class ;
uint32 key_class_len = 0 ;
uint32 num_subkeys ;
uint32 max_subkeylen ;
uint32 max_subkeysize ;
uint32 num_values ;
uint32 max_valnamelen ;
uint32 max_valbufsize ;
uint32 sec_desc ;
NTTIME mod_time ;
DEBUG ( 5 , ( " cmd_reg_enum: smb_cli->fd:%d \n " , smb_cli - > fd ) ) ;
1998-11-11 17:23:55 +03:00
if ( ! next_token ( NULL , full_keyname , NULL , sizeof ( full_keyname ) ) )
1998-11-10 22:05:00 +03:00
{
fprintf ( out_hnd , " regquery key_name \n " ) ;
return ;
}
/* open WINREG session. */
1998-12-07 23:23:41 +03:00
res = res ? cli_nt_session_open ( smb_cli , PIPE_WINREG , & fnum ) : False ;
1998-11-10 22:05:00 +03:00
/* open registry receive a policy handle */
1998-12-07 23:23:41 +03:00
res = res ? do_reg_connect ( smb_cli , fnum , full_keyname , key_name ,
1998-11-10 22:05:00 +03:00
& info - > dom . reg_pol_connect ) : False ;
1998-11-11 17:23:55 +03:00
if ( ( * key_name ) ! = 0 )
{
/* open an entry */
1998-12-07 23:23:41 +03:00
res1 = res ? do_reg_open_entry ( smb_cli , fnum , & info - > dom . reg_pol_connect ,
1998-11-11 17:23:55 +03:00
key_name , 0x02000000 , & key_pol ) : False ;
}
else
{
memcpy ( & key_pol , & info - > dom . reg_pol_connect , sizeof ( key_pol ) ) ;
}
1998-11-10 22:05:00 +03:00
1998-12-07 23:23:41 +03:00
res1 = res1 ? do_reg_query_key ( smb_cli , fnum ,
1998-11-10 22:05:00 +03:00
& key_pol ,
key_class , & key_class_len ,
& num_subkeys , & max_subkeylen , & max_subkeysize ,
& num_values , & max_valnamelen , & max_valbufsize ,
& sec_desc , & mod_time ) : False ;
if ( res1 & & key_class_len ! = 0 )
{
1998-12-07 23:23:41 +03:00
res1 = res1 ? do_reg_query_key ( smb_cli , fnum ,
1998-11-10 22:05:00 +03:00
& key_pol ,
key_class , & key_class_len ,
& num_subkeys , & max_subkeylen , & max_subkeysize ,
& num_values , & max_valnamelen , & max_valbufsize ,
& sec_desc , & mod_time ) : False ;
}
if ( res1 )
{
fprintf ( out_hnd , " Registry Query Info Key \n " ) ;
fprintf ( out_hnd , " key class: %s \n " , key_class ) ;
fprintf ( out_hnd , " subkeys, max_len, max_size: %d %d %d \n " , num_subkeys , max_subkeylen , max_subkeysize ) ;
fprintf ( out_hnd , " vals, max_len, max_size: 0x%x 0x%x 0x%x \n " , num_values , max_valnamelen , max_valbufsize ) ;
fprintf ( out_hnd , " sec desc: 0x%x \n " , sec_desc ) ;
fprintf ( out_hnd , " mod time: %s \n " , http_timestring ( nt_time_to_unix ( & mod_time ) ) ) ;
}
/* close the handles */
1998-11-11 17:23:55 +03:00
if ( ( * key_name ) ! = 0 )
{
1998-12-07 23:23:41 +03:00
res1 = res1 ? do_reg_close ( smb_cli , fnum , & key_pol ) : False ;
1998-11-11 17:23:55 +03:00
}
1998-12-07 23:23:41 +03:00
res = res ? do_reg_close ( smb_cli , fnum , & info - > dom . reg_pol_connect ) : False ;
1998-11-10 22:05:00 +03:00
/* close the session */
1998-12-07 23:23:41 +03:00
cli_nt_session_close ( smb_cli , fnum ) ;
1998-11-10 22:05:00 +03:00
if ( res & & res1 )
{
DEBUG ( 5 , ( " cmd_reg_query: query succeeded \n " ) ) ;
}
else
{
DEBUG ( 5 , ( " cmd_reg_query: query failed \n " ) ) ;
}
}
/****************************************************************************
nt registry create value
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void cmd_reg_create_val ( struct client_info * info )
{
1998-12-07 23:23:41 +03:00
uint16 fnum ;
1998-11-10 22:05:00 +03:00
BOOL res = True ;
BOOL res3 = True ;
BOOL res4 = True ;
POLICY_HND parent_pol ;
1998-11-11 17:23:55 +03:00
fstring full_keyname ;
fstring keyname ;
1998-11-10 22:05:00 +03:00
fstring parent_name ;
fstring val_name ;
fstring tmp ;
uint32 val_type ;
BUFFER3 value ;
#if 0
uint32 unk_0 ;
uint32 unk_1 ;
/* query it */
1998-12-07 23:23:41 +03:00
res1 = res1 ? do_reg_query_info ( smb_cli , fnum , & val_pol ,
1998-11-10 22:05:00 +03:00
type , & unk_0 , & unk_1 ) : False ;
# endif
1998-11-11 17:23:55 +03:00
DEBUG ( 5 , ( " cmd_reg_create_val: smb_cli->fd:%d \n " , smb_cli - > fd ) ) ;
1998-11-10 22:05:00 +03:00
1998-11-11 17:23:55 +03:00
if ( ! next_token ( NULL , full_keyname , NULL , sizeof ( full_keyname ) ) )
1998-11-10 22:05:00 +03:00
{
1998-11-11 17:23:55 +03:00
fprintf ( out_hnd , " regcreate <val_name> <val_type> <val> \n " ) ;
1998-11-10 22:05:00 +03:00
return ;
}
1998-11-11 17:23:55 +03:00
reg_get_subkey ( full_keyname , keyname , val_name ) ;
if ( keyname [ 0 ] = = 0 | | val_name [ 0 ] = = 0 )
1998-11-10 22:05:00 +03:00
{
1998-11-11 17:23:55 +03:00
fprintf ( out_hnd , " invalid key name \n " ) ;
1998-11-10 22:05:00 +03:00
return ;
}
1998-11-11 17:23:55 +03:00
1998-11-10 22:05:00 +03:00
if ( ! next_token ( NULL , tmp , NULL , sizeof ( tmp ) ) )
{
1998-11-11 17:23:55 +03:00
fprintf ( out_hnd , " regcreate <val_name> <val_type (1|4)> <val> \n " ) ;
1998-11-10 22:05:00 +03:00
return ;
}
val_type = atoi ( tmp ) ;
if ( val_type ! = 1 & & val_type ! = 3 & & val_type ! = 4 )
{
fprintf ( out_hnd , " val_type 1=UNISTR, 3=BYTES, 4=DWORD supported \n " ) ;
return ;
}
if ( ! next_token ( NULL , tmp , NULL , sizeof ( tmp ) ) )
{
1998-11-11 17:23:55 +03:00
fprintf ( out_hnd , " regcreate <val_name> <val_type (1|4)> <val> \n " ) ;
1998-11-10 22:05:00 +03:00
return ;
}
switch ( val_type )
{
case 0x01 : /* UNISTR */
{
make_buffer3_str ( & value , tmp , strlen ( tmp ) + 1 ) ;
break ;
}
case 0x03 : /* BYTES */
{
make_buffer3_hex ( & value , tmp ) ;
break ;
}
case 0x04 : /* DWORD */
{
uint32 tmp_val ;
if ( strnequal ( tmp , " 0x " , 2 ) )
{
tmp_val = strtol ( tmp , ( char * * ) NULL , 16 ) ;
}
else
{
tmp_val = strtol ( tmp , ( char * * ) NULL , 10 ) ;
}
make_buffer3_uint32 ( & value , tmp_val ) ;
break ;
}
default :
{
fprintf ( out_hnd , " i told you i only deal with UNISTR, DWORD and BYTES! \n " ) ;
return ;
}
}
DEBUG ( 10 , ( " key data: \n " ) ) ;
1998-11-10 23:51:25 +03:00
dump_data ( 10 , ( char * ) value . buffer , value . buf_len ) ;
1998-11-10 22:05:00 +03:00
/* open WINREG session. */
1998-12-07 23:23:41 +03:00
res = res ? cli_nt_session_open ( smb_cli , PIPE_WINREG , & fnum ) : False ;
1998-11-10 22:05:00 +03:00
/* open registry receive a policy handle */
1998-12-07 23:23:41 +03:00
res = res ? do_reg_connect ( smb_cli , fnum , keyname , parent_name ,
1998-11-10 22:05:00 +03:00
& info - > dom . reg_pol_connect ) : False ;
1998-11-11 17:23:55 +03:00
if ( ( * val_name ) ! = 0 )
{
/* open an entry */
1998-12-07 23:23:41 +03:00
res3 = res ? do_reg_open_entry ( smb_cli , fnum , & info - > dom . reg_pol_connect ,
1998-11-11 17:23:55 +03:00
parent_name , 0x02000000 , & parent_pol ) : False ;
}
else
{
memcpy ( & parent_pol , & info - > dom . reg_pol_connect , sizeof ( parent_pol ) ) ;
}
1998-11-10 22:05:00 +03:00
/* create an entry */
1998-12-07 23:23:41 +03:00
res4 = res3 ? do_reg_create_val ( smb_cli , fnum , & parent_pol ,
1998-11-10 22:05:00 +03:00
val_name , val_type , & value ) : False ;
1998-11-11 03:43:41 +03:00
/* flush the modified key */
1998-12-07 23:23:41 +03:00
res4 = res4 ? do_reg_flush_key ( smb_cli , fnum , & parent_pol ) : False ;
1998-11-11 01:03:34 +03:00
1998-11-10 22:05:00 +03:00
/* close the val handle */
1998-11-11 17:23:55 +03:00
if ( ( * val_name ) ! = 0 )
{
1998-12-07 23:23:41 +03:00
res3 = res3 ? do_reg_close ( smb_cli , fnum , & parent_pol ) : False ;
1998-11-11 17:23:55 +03:00
}
1998-11-10 22:05:00 +03:00
/* close the registry handles */
1998-12-07 23:23:41 +03:00
res = res ? do_reg_close ( smb_cli , fnum , & info - > dom . reg_pol_connect ) : False ;
1998-11-10 22:05:00 +03:00
/* close the session */
1998-12-07 23:23:41 +03:00
cli_nt_session_close ( smb_cli , fnum ) ;
1998-11-10 22:05:00 +03:00
if ( res & & res3 & & res4 )
{
DEBUG ( 5 , ( " cmd_reg_create_val: query succeeded \n " ) ) ;
fprintf ( out_hnd , " OK \n " ) ;
}
else
{
DEBUG ( 5 , ( " cmd_reg_create_val: query failed \n " ) ) ;
}
}
1998-11-11 03:57:13 +03:00
/****************************************************************************
nt registry delete value
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void cmd_reg_delete_val ( struct client_info * info )
{
1998-12-07 23:23:41 +03:00
uint16 fnum ;
1998-11-11 03:57:13 +03:00
BOOL res = True ;
BOOL res3 = True ;
BOOL res4 = True ;
POLICY_HND parent_pol ;
1998-11-11 17:23:55 +03:00
fstring full_keyname ;
fstring keyname ;
1998-11-11 03:57:13 +03:00
fstring parent_name ;
fstring val_name ;
DEBUG ( 5 , ( " cmd_reg_delete_val: smb_cli->fd:%d \n " , smb_cli - > fd ) ) ;
1998-11-11 17:23:55 +03:00
if ( ! next_token ( NULL , full_keyname , NULL , sizeof ( full_keyname ) ) )
1998-11-11 03:57:13 +03:00
{
1998-11-11 17:23:55 +03:00
fprintf ( out_hnd , " regdelete <val_name> \n " ) ;
1998-11-11 03:57:13 +03:00
return ;
}
1998-11-11 17:23:55 +03:00
reg_get_subkey ( full_keyname , keyname , val_name ) ;
if ( keyname [ 0 ] = = 0 | | val_name [ 0 ] = = 0 )
1998-11-11 03:57:13 +03:00
{
1998-11-11 17:23:55 +03:00
fprintf ( out_hnd , " invalid key name \n " ) ;
1998-11-11 03:57:13 +03:00
return ;
}
1998-11-11 17:23:55 +03:00
1998-11-11 03:57:13 +03:00
/* open WINREG session. */
1998-12-07 23:23:41 +03:00
res = res ? cli_nt_session_open ( smb_cli , PIPE_WINREG , & fnum ) : False ;
1998-11-11 03:57:13 +03:00
/* open registry receive a policy handle */
1998-12-07 23:23:41 +03:00
res = res ? do_reg_connect ( smb_cli , fnum , keyname , parent_name ,
1998-11-11 03:57:13 +03:00
& info - > dom . reg_pol_connect ) : False ;
1998-11-11 17:23:55 +03:00
if ( ( * val_name ) ! = 0 )
{
/* open an entry */
1998-12-07 23:23:41 +03:00
res3 = res ? do_reg_open_entry ( smb_cli , fnum , & info - > dom . reg_pol_connect ,
1998-11-11 17:23:55 +03:00
parent_name , 0x02000000 , & parent_pol ) : False ;
}
else
{
memcpy ( & parent_pol , & info - > dom . reg_pol_connect , sizeof ( parent_pol ) ) ;
}
1998-11-11 03:57:13 +03:00
1998-11-11 17:23:55 +03:00
/* delete an entry */
1998-12-07 23:23:41 +03:00
res4 = res3 ? do_reg_delete_val ( smb_cli , fnum , & parent_pol , val_name ) : False ;
1998-11-11 03:57:13 +03:00
/* flush the modified key */
1998-12-07 23:23:41 +03:00
res4 = res4 ? do_reg_flush_key ( smb_cli , fnum , & parent_pol ) : False ;
1998-11-11 03:57:13 +03:00
/* close the key handle */
1998-12-07 23:23:41 +03:00
res3 = res3 ? do_reg_close ( smb_cli , fnum , & parent_pol ) : False ;
1998-11-11 03:57:13 +03:00
/* close the registry handles */
1998-12-07 23:23:41 +03:00
res = res ? do_reg_close ( smb_cli , fnum , & info - > dom . reg_pol_connect ) : False ;
1998-11-11 03:57:13 +03:00
/* close the session */
1998-12-07 23:23:41 +03:00
cli_nt_session_close ( smb_cli , fnum ) ;
1998-11-11 03:57:13 +03:00
if ( res & & res3 & & res4 )
{
DEBUG ( 5 , ( " cmd_reg_delete_val: query succeeded \n " ) ) ;
fprintf ( out_hnd , " OK \n " ) ;
}
else
{
DEBUG ( 5 , ( " cmd_reg_delete_val: query failed \n " ) ) ;
}
}
1998-11-11 01:14:05 +03:00
/****************************************************************************
nt registry delete key
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void cmd_reg_delete_key ( struct client_info * info )
{
1998-12-07 23:23:41 +03:00
uint16 fnum ;
1998-11-11 01:14:05 +03:00
BOOL res = True ;
BOOL res3 = True ;
BOOL res4 = True ;
POLICY_HND parent_pol ;
1998-11-11 17:23:55 +03:00
fstring full_keyname ;
1998-11-11 01:14:05 +03:00
fstring parent_name ;
fstring key_name ;
1998-11-11 17:23:55 +03:00
fstring subkey_name ;
1998-11-11 01:14:05 +03:00
DEBUG ( 5 , ( " cmd_reg_delete_key: smb_cli->fd:%d \n " , smb_cli - > fd ) ) ;
1998-11-11 17:23:55 +03:00
if ( ! next_token ( NULL , full_keyname , NULL , sizeof ( full_keyname ) ) )
1998-11-11 01:14:05 +03:00
{
1998-11-11 17:23:55 +03:00
fprintf ( out_hnd , " regdeletekey <key_name> \n " ) ;
1998-11-11 01:14:05 +03:00
return ;
}
1998-11-11 17:23:55 +03:00
reg_get_subkey ( full_keyname , parent_name , subkey_name ) ;
if ( parent_name [ 0 ] = = 0 | | subkey_name [ 0 ] = = 0 )
1998-11-11 01:14:05 +03:00
{
1998-11-11 17:23:55 +03:00
fprintf ( out_hnd , " invalid key name \n " ) ;
1998-11-11 01:14:05 +03:00
return ;
}
1998-11-11 17:23:55 +03:00
1998-11-11 01:14:05 +03:00
/* open WINREG session. */
1998-12-07 23:23:41 +03:00
res = res ? cli_nt_session_open ( smb_cli , PIPE_WINREG , & fnum ) : False ;
1998-11-11 01:14:05 +03:00
/* open registry receive a policy handle */
1998-12-07 23:23:41 +03:00
res = res ? do_reg_connect ( smb_cli , fnum , parent_name , key_name ,
1998-11-11 01:14:05 +03:00
& info - > dom . reg_pol_connect ) : False ;
1998-11-11 17:23:55 +03:00
if ( ( * key_name ) ! = 0 )
{
/* open an entry */
1998-12-07 23:23:41 +03:00
res3 = res ? do_reg_open_entry ( smb_cli , fnum , & info - > dom . reg_pol_connect ,
1998-11-11 17:23:55 +03:00
key_name , 0x02000000 , & parent_pol ) : False ;
}
else
{
memcpy ( & parent_pol , & info - > dom . reg_pol_connect , sizeof ( parent_pol ) ) ;
}
1998-11-11 01:14:05 +03:00
/* create an entry */
1998-12-07 23:23:41 +03:00
res4 = res3 ? do_reg_delete_key ( smb_cli , fnum , & parent_pol , subkey_name ) : False ;
1998-11-11 01:14:05 +03:00
1998-11-11 03:43:41 +03:00
/* flush the modified key */
1998-12-07 23:23:41 +03:00
res4 = res4 ? do_reg_flush_key ( smb_cli , fnum , & parent_pol ) : False ;
1998-11-11 01:14:05 +03:00
/* close the key handle */
1998-11-11 17:23:55 +03:00
if ( ( * key_name ) ! = 0 )
{
1998-12-07 23:23:41 +03:00
res3 = res3 ? do_reg_close ( smb_cli , fnum , & parent_pol ) : False ;
1998-11-11 17:23:55 +03:00
}
1998-11-11 01:14:05 +03:00
/* close the registry handles */
1998-12-07 23:23:41 +03:00
res = res ? do_reg_close ( smb_cli , fnum , & info - > dom . reg_pol_connect ) : False ;
1998-11-11 01:14:05 +03:00
/* close the session */
1998-12-07 23:23:41 +03:00
cli_nt_session_close ( smb_cli , fnum ) ;
1998-11-11 01:14:05 +03:00
if ( res & & res3 & & res4 )
{
DEBUG ( 5 , ( " cmd_reg_delete_key: query succeeded \n " ) ) ;
fprintf ( out_hnd , " OK \n " ) ;
}
else
{
DEBUG ( 5 , ( " cmd_reg_delete_key: query failed \n " ) ) ;
}
}
1998-11-10 22:05:00 +03:00
/****************************************************************************
nt registry create key
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void cmd_reg_create_key ( struct client_info * info )
{
1998-12-07 23:23:41 +03:00
uint16 fnum ;
1998-11-10 22:05:00 +03:00
BOOL res = True ;
BOOL res3 = True ;
BOOL res4 = True ;
POLICY_HND parent_pol ;
POLICY_HND key_pol ;
1998-11-11 17:23:55 +03:00
fstring full_keyname ;
fstring parent_key ;
1998-11-10 22:05:00 +03:00
fstring parent_name ;
fstring key_name ;
fstring key_class ;
1998-11-13 02:35:05 +03:00
SEC_ACCESS sam_access ;
1998-11-10 22:05:00 +03:00
DEBUG ( 5 , ( " cmd_reg_create_key: smb_cli->fd:%d \n " , smb_cli - > fd ) ) ;
1998-11-11 17:23:55 +03:00
if ( ! next_token ( NULL , full_keyname , NULL , sizeof ( full_keyname ) ) )
1998-11-10 22:05:00 +03:00
{
1998-11-11 17:23:55 +03:00
fprintf ( out_hnd , " regcreate <key_name> [key_class] \n " ) ;
1998-11-10 22:05:00 +03:00
return ;
}
1998-11-11 17:23:55 +03:00
reg_get_subkey ( full_keyname , parent_key , key_name ) ;
if ( parent_key [ 0 ] = = 0 | | key_name [ 0 ] = = 0 )
1998-11-10 22:05:00 +03:00
{
1998-11-11 17:23:55 +03:00
fprintf ( out_hnd , " invalid key name \n " ) ;
1998-11-10 22:05:00 +03:00
return ;
}
1998-11-11 17:23:55 +03:00
1998-11-10 22:05:00 +03:00
if ( ! next_token ( NULL , key_class , NULL , sizeof ( key_class ) ) )
{
memset ( key_class , 0 , sizeof ( key_class ) ) ;
}
/* set access permissions */
1998-11-13 02:35:05 +03:00
sam_access . mask = SEC_RIGHTS_READ ;
1998-11-10 22:05:00 +03:00
/* open WINREG session. */
1998-12-07 23:23:41 +03:00
res = res ? cli_nt_session_open ( smb_cli , PIPE_WINREG , & fnum ) : False ;
1998-11-10 22:05:00 +03:00
/* open registry receive a policy handle */
1998-12-07 23:23:41 +03:00
res = res ? do_reg_connect ( smb_cli , fnum , parent_key , parent_name ,
1998-11-10 22:05:00 +03:00
& info - > dom . reg_pol_connect ) : False ;
1998-11-11 17:23:55 +03:00
if ( ( * parent_name ) ! = 0 )
{
/* open an entry */
1998-12-07 23:23:41 +03:00
res3 = res ? do_reg_open_entry ( smb_cli , fnum , & info - > dom . reg_pol_connect ,
1998-11-11 17:23:55 +03:00
parent_name , 0x02000000 , & parent_pol ) : False ;
}
else
{
memcpy ( & parent_pol , & info - > dom . reg_pol_connect , sizeof ( parent_pol ) ) ;
}
1998-11-10 22:05:00 +03:00
/* create an entry */
1998-12-07 23:23:41 +03:00
res4 = res3 ? do_reg_create_key ( smb_cli , fnum , & parent_pol ,
1998-11-10 22:05:00 +03:00
key_name , key_class , & sam_access , & key_pol ) : False ;
1998-11-11 03:43:41 +03:00
/* flush the modified key */
1998-12-07 23:23:41 +03:00
res4 = res4 ? do_reg_flush_key ( smb_cli , fnum , & parent_pol ) : False ;
1998-11-11 01:03:34 +03:00
1998-11-10 22:05:00 +03:00
/* close the key handle */
1998-12-07 23:23:41 +03:00
res4 = res4 ? do_reg_close ( smb_cli , fnum , & key_pol ) : False ;
1998-11-10 22:05:00 +03:00
/* close the key handle */
1998-11-11 17:23:55 +03:00
if ( ( * parent_name ) ! = 0 )
{
1998-12-07 23:23:41 +03:00
res3 = res3 ? do_reg_close ( smb_cli , fnum , & parent_pol ) : False ;
1998-11-11 17:23:55 +03:00
}
1998-11-10 22:05:00 +03:00
/* close the registry handles */
1998-12-07 23:23:41 +03:00
res = res ? do_reg_close ( smb_cli , fnum , & info - > dom . reg_pol_connect ) : False ;
1998-11-10 22:05:00 +03:00
/* close the session */
1998-12-07 23:23:41 +03:00
cli_nt_session_close ( smb_cli , fnum ) ;
1998-11-10 22:05:00 +03:00
if ( res & & res3 & & res4 )
{
DEBUG ( 5 , ( " cmd_reg_create_key: query succeeded \n " ) ) ;
fprintf ( out_hnd , " OK \n " ) ;
}
else
{
DEBUG ( 5 , ( " cmd_reg_create_key: query failed \n " ) ) ;
}
}
1998-11-09 19:40:38 +03:00
/****************************************************************************
nt registry security info
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1998-11-12 22:21:20 +03:00
void cmd_reg_test_key_sec ( struct client_info * info )
1998-11-09 19:40:38 +03:00
{
1998-12-07 23:23:41 +03:00
uint16 fnum ;
1998-11-09 19:40:38 +03:00
BOOL res = True ;
BOOL res3 = True ;
BOOL res4 = True ;
POLICY_HND key_pol ;
1998-11-11 17:23:55 +03:00
fstring full_keyname ;
1998-11-09 19:40:38 +03:00
fstring key_name ;
/*
* security info
*/
uint32 sec_buf_size ;
1999-02-24 01:39:54 +03:00
SEC_DESC_BUF * psdb ;
1998-11-09 19:40:38 +03:00
DEBUG ( 5 , ( " cmd_reg_get_key_sec: smb_cli->fd:%d \n " , smb_cli - > fd ) ) ;
1998-11-11 17:23:55 +03:00
if ( ! next_token ( NULL , full_keyname , NULL , sizeof ( full_keyname ) ) )
1998-11-09 19:40:38 +03:00
{
1998-11-11 17:23:55 +03:00
fprintf ( out_hnd , " reggetsec <key_name> \n " ) ;
1998-11-09 19:40:38 +03:00
return ;
}
/* open WINREG session. */
1998-12-07 23:23:41 +03:00
res = res ? cli_nt_session_open ( smb_cli , PIPE_WINREG , & fnum ) : False ;
1998-11-09 19:40:38 +03:00
/* open registry receive a policy handle */
1998-12-07 23:23:41 +03:00
res = res ? do_reg_connect ( smb_cli , fnum , full_keyname , key_name ,
1998-11-09 19:40:38 +03:00
& info - > dom . reg_pol_connect ) : False ;
1998-11-11 17:23:55 +03:00
if ( ( * key_name ) ! = 0 )
{
/* open an entry */
1998-12-07 23:23:41 +03:00
res3 = res ? do_reg_open_entry ( smb_cli , fnum , & info - > dom . reg_pol_connect ,
1998-11-11 17:23:55 +03:00
key_name , 0x02000000 , & key_pol ) : False ;
}
else
{
memcpy ( & key_pol , & info - > dom . reg_pol_connect , sizeof ( key_pol ) ) ;
}
1998-11-09 19:40:38 +03:00
/* open an entry */
1998-12-07 23:23:41 +03:00
res3 = res ? do_reg_open_entry ( smb_cli , fnum , & info - > dom . reg_pol_connect ,
1998-11-09 19:40:38 +03:00
key_name , 0x02000000 , & key_pol ) : False ;
1999-02-24 01:39:54 +03:00
/* Get the size. */
1998-11-09 19:40:38 +03:00
sec_buf_size = 0 ;
1998-11-11 22:22:08 +03:00
1998-12-07 23:23:41 +03:00
res4 = res3 ? do_reg_get_key_sec ( smb_cli , fnum , & key_pol ,
1999-02-24 01:39:54 +03:00
& sec_buf_size , & psdb ) : False ;
1998-11-09 19:40:38 +03:00
1999-02-24 01:39:54 +03:00
free_sec_desc_buf ( & psdb ) ;
1998-11-13 02:35:05 +03:00
1998-12-07 23:23:41 +03:00
res4 = res4 ? do_reg_get_key_sec ( smb_cli , fnum , & key_pol ,
1999-02-24 01:39:54 +03:00
& sec_buf_size , & psdb ) : False ;
1998-11-09 19:40:38 +03:00
1999-02-24 01:39:54 +03:00
if ( res4 & & psdb - > len > 0 & & psdb - > sec ! = NULL )
1998-11-09 19:40:38 +03:00
{
1999-02-24 01:39:54 +03:00
display_sec_desc ( out_hnd , ACTION_HEADER , psdb - > sec ) ;
display_sec_desc ( out_hnd , ACTION_ENUMERATE , psdb - > sec ) ;
display_sec_desc ( out_hnd , ACTION_FOOTER , psdb - > sec ) ;
1998-11-12 22:21:20 +03:00
1998-12-07 23:23:41 +03:00
res4 = res4 ? do_reg_set_key_sec ( smb_cli , fnum , & key_pol ,
1999-02-24 01:39:54 +03:00
psdb ) : False ;
1998-11-12 22:21:20 +03:00
1998-11-09 19:40:38 +03:00
}
1999-02-24 01:39:54 +03:00
free_sec_desc_buf ( & psdb ) ;
1998-11-09 19:40:38 +03:00
/* close the key handle */
1998-11-11 17:23:55 +03:00
if ( ( * key_name ) ! = 0 )
{
1998-12-07 23:23:41 +03:00
res3 = res3 ? do_reg_close ( smb_cli , fnum , & key_pol ) : False ;
1998-11-11 17:23:55 +03:00
}
1998-11-09 19:40:38 +03:00
/* close the registry handles */
1998-12-07 23:23:41 +03:00
res = res ? do_reg_close ( smb_cli , fnum , & info - > dom . reg_pol_connect ) : False ;
1998-11-09 19:40:38 +03:00
/* close the session */
1998-12-07 23:23:41 +03:00
cli_nt_session_close ( smb_cli , fnum ) ;
1998-11-09 19:40:38 +03:00
if ( res & & res3 & & res4 )
{
DEBUG ( 5 , ( " cmd_reg_test2: query succeeded \n " ) ) ;
fprintf ( out_hnd , " Registry Test2 \n " ) ;
}
else
{
DEBUG ( 5 , ( " cmd_reg_test2: query failed \n " ) ) ;
}
}
1998-11-12 22:21:20 +03:00
/****************************************************************************
nt registry security info
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void cmd_reg_get_key_sec ( struct client_info * info )
{
1998-12-07 23:23:41 +03:00
uint16 fnum ;
1998-11-12 22:21:20 +03:00
BOOL res = True ;
BOOL res3 = True ;
BOOL res4 = True ;
POLICY_HND key_pol ;
fstring full_keyname ;
fstring key_name ;
/*
* security info
*/
uint32 sec_buf_size ;
1999-02-24 01:39:54 +03:00
SEC_DESC_BUF * psdb ;
1998-11-12 22:21:20 +03:00
DEBUG ( 5 , ( " cmd_reg_get_key_sec: smb_cli->fd:%d \n " , smb_cli - > fd ) ) ;
if ( ! next_token ( NULL , full_keyname , NULL , sizeof ( full_keyname ) ) )
{
fprintf ( out_hnd , " reggetsec <key_name> \n " ) ;
return ;
}
/* open WINREG session. */
1998-12-07 23:23:41 +03:00
res = res ? cli_nt_session_open ( smb_cli , PIPE_WINREG , & fnum ) : False ;
1998-11-12 22:21:20 +03:00
/* open registry receive a policy handle */
1998-12-07 23:23:41 +03:00
res = res ? do_reg_connect ( smb_cli , fnum , full_keyname , key_name ,
1998-11-12 22:21:20 +03:00
& info - > dom . reg_pol_connect ) : False ;
if ( ( * key_name ) ! = 0 )
{
/* open an entry */
1998-12-07 23:23:41 +03:00
res3 = res ? do_reg_open_entry ( smb_cli , fnum , & info - > dom . reg_pol_connect ,
1998-11-12 22:21:20 +03:00
key_name , 0x02000000 , & key_pol ) : False ;
}
else
{
memcpy ( & key_pol , & info - > dom . reg_pol_connect , sizeof ( key_pol ) ) ;
}
/* open an entry */
1998-12-07 23:23:41 +03:00
res3 = res ? do_reg_open_entry ( smb_cli , fnum , & info - > dom . reg_pol_connect ,
1998-11-12 22:21:20 +03:00
key_name , 0x02000000 , & key_pol ) : False ;
1999-02-24 01:39:54 +03:00
/* Get the size. */
1998-11-12 22:21:20 +03:00
sec_buf_size = 0 ;
1998-12-07 23:23:41 +03:00
res4 = res3 ? do_reg_get_key_sec ( smb_cli , fnum , & key_pol ,
1999-02-24 01:39:54 +03:00
& sec_buf_size , & psdb ) : False ;
1998-11-12 22:21:20 +03:00
1999-02-24 01:39:54 +03:00
free_sec_desc_buf ( & psdb ) ;
1998-11-13 02:35:05 +03:00
1998-12-07 23:23:41 +03:00
res4 = res4 ? do_reg_get_key_sec ( smb_cli , fnum , & key_pol ,
1999-02-24 01:39:54 +03:00
& sec_buf_size , & psdb ) : False ;
1998-11-12 22:21:20 +03:00
1999-02-24 01:39:54 +03:00
if ( res4 & & psdb - > len > 0 & & psdb - > sec ! = NULL )
1998-11-12 22:21:20 +03:00
{
1999-02-24 01:39:54 +03:00
display_sec_desc ( out_hnd , ACTION_HEADER , psdb - > sec ) ;
display_sec_desc ( out_hnd , ACTION_ENUMERATE , psdb - > sec ) ;
display_sec_desc ( out_hnd , ACTION_FOOTER , psdb - > sec ) ;
1998-11-13 02:35:05 +03:00
1998-11-12 22:21:20 +03:00
}
1999-02-24 01:39:54 +03:00
free_sec_desc_buf ( & psdb ) ;
1998-11-12 22:21:20 +03:00
/* close the key handle */
if ( ( * key_name ) ! = 0 )
{
1998-12-07 23:23:41 +03:00
res3 = res3 ? do_reg_close ( smb_cli , fnum , & key_pol ) : False ;
1998-11-12 22:21:20 +03:00
}
/* close the registry handles */
1998-12-07 23:23:41 +03:00
res = res ? do_reg_close ( smb_cli , fnum , & info - > dom . reg_pol_connect ) : False ;
1998-11-12 22:21:20 +03:00
/* close the session */
1998-12-07 23:23:41 +03:00
cli_nt_session_close ( smb_cli , fnum ) ;
1998-11-12 22:21:20 +03:00
if ( res & & res3 & & res4 )
{
DEBUG ( 5 , ( " cmd_reg_get_key_sec: query succeeded \n " ) ) ;
}
else
{
DEBUG ( 5 , ( " cmd_reg_get_key_sec: query failed \n " ) ) ;
}
}
1999-02-16 21:04:21 +03:00
/****************************************************************************
nt registry shutdown
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void cmd_reg_shutdown ( struct client_info * info )
{
uint16 fnum ;
BOOL res = True ;
fstring msg ;
fstring tmp ;
uint32 timeout = 20 ;
1999-03-01 19:01:45 +03:00
uint16 flgs = 0 ;
1999-02-16 21:04:21 +03:00
DEBUG ( 5 , ( " cmd_reg_shutdown: smb_cli->fd:%d \n " , smb_cli - > fd ) ) ;
1999-03-01 19:01:45 +03:00
while ( next_token ( NULL , tmp , NULL , sizeof ( tmp ) ) )
1999-02-16 21:04:21 +03:00
{
1999-03-01 19:01:45 +03:00
if ( strequal ( tmp , " -m " ) )
{
if ( next_token ( NULL , msg , NULL , sizeof ( msg ) ) )
{
continue ;
}
}
else if ( strequal ( tmp , " -t " ) )
{
if ( next_token ( NULL , tmp , NULL , sizeof ( tmp ) ) )
{
timeout = atoi ( tmp ) ;
continue ;
}
}
else if ( strequal ( tmp , " -r " ) | | strequal ( tmp , " --reboot " ) )
{
flgs = 0x100 ;
continue ;
}
fprintf ( out_hnd , " shutdown [-m msg] [-t timeout] [-r or --reboot] \n " ) ;
1999-02-16 21:04:21 +03:00
}
/* open WINREG session. */
res = res ? cli_nt_session_open ( smb_cli , PIPE_WINREG , & fnum ) : False ;
/* create an entry */
1999-03-01 19:01:45 +03:00
res = res ? do_reg_shutdown ( smb_cli , fnum , msg , timeout , flgs ) : False ;
1999-02-16 21:04:21 +03:00
/* close the session */
cli_nt_session_close ( smb_cli , fnum ) ;
if ( res )
{
DEBUG ( 5 , ( " cmd_reg_shutdown: query succeeded \n " ) ) ;
fprintf ( out_hnd , " OK \n " ) ;
}
else
{
DEBUG ( 5 , ( " cmd_reg_shutdown: query failed \n " ) ) ;
fprintf ( out_hnd , " Failed \n " ) ;
}
}