1998-11-09 16:40:38 +00:00
/*
2002-01-30 06:08:46 +00:00
Unix SMB / CIFS implementation .
1998-11-09 16:40:38 +00:00
NT Domain Authentication SMB / MSRPC client
1999-12-13 13:27:58 +00:00
Copyright ( C ) Andrew Tridgell 1994 - 1997
Copyright ( C ) Luke Kenneth Casson Leighton 1996 - 1997
2001-08-10 09:52:10 +00:00
Copyright ( C ) Simo Sorce 2001
1998-11-09 16:40:38 +00:00
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 .
*/
# include "includes.h"
2001-10-12 05:56:23 +00:00
# include "rpcclient.h"
1998-11-09 16:40:38 +00:00
1998-11-11 14:23:55 +00:00
/*
* keys . of the form :
* - - - -
*
1999-12-13 13:27:58 +00:00
* [ HKLM ] | [ HKU ] \ [ parent_keyname_components ] \ [ subkey ] | [ value ]
1998-11-11 14:23:55 +00:00
*
* reg_getsubkey ( ) splits this down into :
1999-12-13 13:27:58 +00:00
* [ HKLM ] | [ HKU ] \ [ parent_keyname_components ] and [ subkey ] | [ value ]
1998-11-11 14:23:55 +00:00
*
1999-12-13 13:27:58 +00:00
* do_reg_connect ( ) splits the left side down further into :
* [ HKLM ] | [ HKU ] and [ parent_keyname_components ] .
1998-11-11 14:23:55 +00:00
*
* HKLM is short for HKEY_LOCAL_MACHINE
* HKU is short for HKEY_USERS
*
* oh , and HKEY stands for " Hive Key " .
*
*/
1998-11-09 16:40:38 +00:00
2006-03-10 13:14:01 +00:00
#if 0 /* This whole file need to be rewritten for the current rpcclient interface */
2001-08-10 09:52:10 +00:00
1998-11-09 16:40:38 +00:00
/****************************************************************************
nt registry enum
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-08-10 09:52:10 +00:00
static void cmd_reg_enum ( struct client_info * info )
1998-11-09 16:40:38 +00:00
{
BOOL res = True ;
BOOL res1 = True ;
BOOL res2 = True ;
int i ;
POLICY_HND key_pol ;
1999-12-13 13:27:58 +00:00
fstring full_keyname ;
1998-11-09 16:40:38 +00:00
fstring key_name ;
2005-03-23 23:26:33 +00:00
uint32 reg_type ;
1998-11-09 16:40:38 +00:00
/*
* query key info
*/
1998-11-10 19:05:00 +00:00
fstring key_class ;
uint32 max_class_len = 0 ;
1998-11-09 16:40:38 +00:00
uint32 num_subkeys ;
uint32 max_subkeylen ;
1998-11-10 19:05:00 +00:00
uint32 max_subkeysize ;
1998-11-09 16:40:38 +00:00
uint32 num_values ;
uint32 max_valnamelen ;
uint32 max_valbufsize ;
1998-11-10 19:05:00 +00:00
uint32 sec_desc ;
1998-11-09 16:40:38 +00:00
NTTIME mod_time ;
/*
* unknown 0x1a request
*/
uint32 unk_1a_response ;
1999-12-13 13:27:58 +00:00
DEBUG ( 5 , ( " cmd_reg_enum: smb_cli->fd:%d \n " , smb_cli - > fd ) ) ;
2001-06-21 09:10:42 +00:00
if ( ! next_token_nr ( NULL , full_keyname , NULL , sizeof ( full_keyname ) ) )
1999-12-13 13:27:58 +00:00
{
fprintf ( out_hnd , " regenum <key_name> \n " ) ;
return ;
}
2005-03-23 23:26:33 +00:00
if ( ! reg_split_key ( full_keyname , & reg_type , key_name ) ) {
fprintf ( out_hnd , " Unknown registry hive '%s' \n " , key_name ) ;
return ;
}
1999-12-13 13:27:58 +00:00
/* open WINREG session. */
2002-10-04 04:10:23 +00:00
res = res ? cli_nt_session_open ( smb_cli , PI_WINREG ) : False ;
1998-11-09 16:40:38 +00:00
/* open registry receive a policy handle */
1999-12-13 13:27:58 +00:00
res = res ? do_reg_connect ( smb_cli , full_keyname , key_name ,
& info - > dom . reg_pol_connect ) : False ;
1998-11-09 16:40:38 +00:00
1998-11-11 14:23:55 +00:00
if ( ( * key_name ) ! = 0 )
{
/* open an entry */
1999-12-13 13:27:58 +00:00
res1 = res ? do_reg_open_entry ( smb_cli , & info - > dom . reg_pol_connect ,
1998-11-11 14:23:55 +00:00
key_name , 0x02000000 , & key_pol ) : False ;
}
else
{
1999-12-13 13:27:58 +00:00
memcpy ( & key_pol , & info - > dom . reg_pol_connect , sizeof ( key_pol ) ) ;
1998-11-11 14:23:55 +00:00
}
1998-11-09 16:40:38 +00:00
1999-12-13 13:27:58 +00:00
res1 = res1 ? do_reg_query_key ( smb_cli ,
& key_pol ,
1998-11-10 19:05:00 +00: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 16:40:38 +00:00
1999-12-13 13:27:58 +00:00
if ( res1 & & num_subkeys > 0 )
1998-11-11 14:23:55 +00:00
{
1999-12-13 13:27:58 +00:00
fprintf ( out_hnd , " Subkeys \n " ) ;
fprintf ( out_hnd , " ------- \n " ) ;
1998-11-11 14:23:55 +00:00
}
1999-12-13 13:27:58 +00:00
for ( i = 0 ; i < num_subkeys ; i + + )
1998-11-09 16:40:38 +00:00
{
/*
* enumerate key
*/
fstring enum_name ;
uint32 enum_unk1 ;
uint32 enum_unk2 ;
time_t key_mod_time ;
/* unknown 1a it */
2005-03-23 23:26:33 +00:00
res2 = res1 ? do_reg_getversion ( smb_cli , & key_pol ,
1998-11-09 16:40:38 +00:00
& unk_1a_response ) : False ;
if ( res2 & & unk_1a_response ! = 5 )
{
1999-12-13 13:27:58 +00:00
fprintf ( out_hnd , " Unknown 1a response: %x \n " , unk_1a_response ) ;
1998-11-09 16:40:38 +00:00
}
/* enum key */
1999-12-13 13:27:58 +00:00
res2 = res2 ? do_reg_enum_key ( smb_cli , & key_pol ,
1998-11-09 16:40:38 +00:00
i , enum_name ,
& enum_unk1 , & enum_unk2 ,
& key_mod_time ) : False ;
if ( res2 )
{
1999-12-13 13:27:58 +00:00
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-09 16:40:38 +00:00
}
}
1999-12-13 13:27:58 +00:00
if ( num_values > 0 )
1999-10-29 23:15:10 +00:00
{
1999-12-13 13:27:58 +00:00
fprintf ( out_hnd , " Key Values \n " ) ;
fprintf ( out_hnd , " ---------- \n " ) ;
1999-10-29 23:15:10 +00:00
}
1998-11-11 14:23:55 +00:00
1999-12-13 13:27:58 +00:00
for ( i = 0 ; i < num_values ; i + + )
1998-11-09 16:40:38 +00:00
{
/*
* enumerate key
*/
uint32 val_type ;
2005-03-23 23:26:33 +00:00
REGVAL_BUFFER value ;
1998-11-09 16:40:38 +00:00
fstring val_name ;
/* unknown 1a it */
2005-03-23 23:26:33 +00:00
res2 = res1 ? do_reg_getversion ( smb_cli , & key_pol ,
1998-11-09 16:40:38 +00:00
& unk_1a_response ) : False ;
if ( res2 & & unk_1a_response ! = 5 )
{
1999-12-13 13:27:58 +00:00
fprintf ( out_hnd , " Unknown 1a response: %x \n " , unk_1a_response ) ;
1998-11-09 16:40:38 +00:00
}
/* enum key */
1999-12-13 13:27:58 +00:00
res2 = res2 ? do_reg_enum_val ( smb_cli , & key_pol ,
1998-11-09 16:40:38 +00:00
i , max_valnamelen , max_valbufsize ,
val_name , & val_type , & value ) : False ;
if ( res2 )
{
1999-12-13 13:27:58 +00:00
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 ) ;
1998-11-09 16:40:38 +00:00
}
}
/* close the handles */
1998-11-11 14:23:55 +00:00
if ( ( * key_name ) ! = 0 )
{
1999-12-13 13:27:58 +00:00
res1 = res1 ? do_reg_close ( smb_cli , & key_pol ) : False ;
1998-11-11 14:23:55 +00:00
}
1999-12-13 13:27:58 +00:00
res = res ? do_reg_close ( smb_cli , & info - > dom . reg_pol_connect ) : False ;
1998-11-09 16:40:38 +00:00
1999-12-13 13:27:58 +00:00
/* close the session */
cli_nt_session_close ( smb_cli ) ;
1999-10-29 21:31:19 +00:00
1999-12-13 13:27:58 +00:00
if ( res & & res1 & & res2 )
1999-11-18 00:26:11 +00:00
{
1999-12-13 13:27:58 +00:00
DEBUG ( 5 , ( " cmd_reg_enum: query succeeded \n " ) ) ;
1999-11-18 00:26:11 +00:00
}
else
{
1999-12-13 13:27:58 +00:00
DEBUG ( 5 , ( " cmd_reg_enum: query failed \n " ) ) ;
1999-11-18 00:26:11 +00:00
}
}
1998-11-10 19:05:00 +00:00
/****************************************************************************
nt registry query key
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-08-10 09:52:10 +00:00
static void cmd_reg_query_key ( struct client_info * info )
1998-11-10 19:05:00 +00:00
{
BOOL res = True ;
BOOL res1 = True ;
POLICY_HND key_pol ;
1999-12-13 13:27:58 +00:00
fstring full_keyname ;
1998-11-10 19:05:00 +00: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 ;
1999-12-13 13:27:58 +00:00
DEBUG ( 5 , ( " cmd_reg_enum: smb_cli->fd:%d \n " , smb_cli - > fd ) ) ;
1998-11-10 19:05:00 +00:00
2001-06-21 09:10:42 +00:00
if ( ! next_token_nr ( NULL , full_keyname , NULL , sizeof ( full_keyname ) ) )
1998-11-10 19:05:00 +00:00
{
1999-12-13 13:27:58 +00:00
fprintf ( out_hnd , " regquery key_name \n " ) ;
1998-11-10 19:05:00 +00:00
return ;
}
1999-12-13 13:27:58 +00:00
/* open WINREG session. */
2002-10-04 04:10:23 +00:00
res = res ? cli_nt_session_open ( smb_cli , PI_WINREG ) : False ;
1999-11-22 20:14:13 +00:00
1998-11-10 19:05:00 +00:00
/* open registry receive a policy handle */
1999-12-13 13:27:58 +00:00
res = res ? do_reg_connect ( smb_cli , full_keyname , key_name ,
& info - > dom . reg_pol_connect ) : False ;
1998-11-10 19:05:00 +00:00
1998-11-11 14:23:55 +00:00
if ( ( * key_name ) ! = 0 )
{
/* open an entry */
1999-12-13 13:27:58 +00:00
res1 = res ? do_reg_open_entry ( smb_cli , & info - > dom . reg_pol_connect ,
1998-11-11 14:23:55 +00:00
key_name , 0x02000000 , & key_pol ) : False ;
}
else
{
1999-12-13 13:27:58 +00:00
memcpy ( & key_pol , & info - > dom . reg_pol_connect , sizeof ( key_pol ) ) ;
1998-11-11 14:23:55 +00:00
}
1998-11-10 19:05:00 +00:00
1999-12-13 13:27:58 +00:00
res1 = res1 ? do_reg_query_key ( smb_cli ,
& key_pol ,
1998-11-10 19:05:00 +00:00
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 )
{
1999-12-13 13:27:58 +00:00
res1 = res1 ? do_reg_query_key ( smb_cli ,
& key_pol ,
1998-11-10 19:05:00 +00:00
key_class , & key_class_len ,
& num_subkeys , & max_subkeylen , & max_subkeysize ,
& num_values , & max_valnamelen , & max_valbufsize ,
& sec_desc , & mod_time ) : False ;
}
if ( res1 )
{
1999-12-13 13:27:58 +00:00
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 ) ) ) ;
1998-11-10 19:05:00 +00:00
}
/* close the handles */
1998-11-11 14:23:55 +00:00
if ( ( * key_name ) ! = 0 )
{
1999-12-13 13:27:58 +00:00
res1 = res1 ? do_reg_close ( smb_cli , & key_pol ) : False ;
1998-11-11 14:23:55 +00:00
}
1999-12-13 13:27:58 +00:00
res = res ? do_reg_close ( smb_cli , & info - > dom . reg_pol_connect ) : False ;
/* close the session */
cli_nt_session_close ( smb_cli ) ;
1998-11-10 19:05:00 +00: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
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2005-04-07 04:58:38 +00:00
static void cmd_reg_set_val ( struct client_info * info )
1998-11-10 19:05:00 +00:00
{
BOOL res = True ;
BOOL res3 = True ;
BOOL res4 = True ;
POLICY_HND parent_pol ;
1999-12-13 13:27:58 +00:00
fstring full_keyname ;
1998-11-11 14:23:55 +00:00
fstring keyname ;
1998-11-10 19:05:00 +00:00
fstring parent_name ;
fstring val_name ;
1999-12-13 13:27:58 +00:00
fstring tmp ;
1998-11-10 19:05:00 +00:00
uint32 val_type ;
2005-04-07 04:58:38 +00:00
RPC_DATA_BLOB value ;
1998-11-10 19:05:00 +00:00
#if 0
uint32 unk_0 ;
uint32 unk_1 ;
/* query it */
1999-12-13 13:27:58 +00:00
res1 = res1 ? do_reg_query_info ( smb_cli , & val_pol ,
2000-05-18 18:43:53 +00:00
val_name , * val_type ) : False ;
1998-11-10 19:05:00 +00:00
# endif
2005-04-07 04:58:38 +00:00
DEBUG ( 5 , ( " cmd_reg_set_val: smb_cli->fd:%d \n " , smb_cli - > fd ) ) ;
1999-11-24 23:40:20 +00:00
2001-06-21 09:10:42 +00:00
if ( ! next_token_nr ( NULL , full_keyname , NULL , sizeof ( full_keyname ) ) )
1998-11-10 19:05:00 +00:00
{
1999-12-13 13:27:58 +00:00
fprintf ( out_hnd , " regcreate <val_name> <val_type> <val> \n " ) ;
1998-11-10 19:05:00 +00:00
return ;
}
1998-11-11 14:23:55 +00:00
reg_get_subkey ( full_keyname , keyname , val_name ) ;
if ( keyname [ 0 ] = = 0 | | val_name [ 0 ] = = 0 )
1998-11-10 19:05:00 +00:00
{
1999-12-13 13:27:58 +00:00
fprintf ( out_hnd , " invalid key name \n " ) ;
1998-11-10 19:05:00 +00:00
return ;
}
1998-11-11 14:23:55 +00:00
2001-06-21 09:10:42 +00:00
if ( ! next_token_nr ( NULL , tmp , NULL , sizeof ( tmp ) ) )
1998-11-10 19:05:00 +00:00
{
1999-12-13 13:27:58 +00:00
fprintf ( out_hnd , " regcreate <val_name> <val_type (1|4)> <val> \n " ) ;
1998-11-10 19:05:00 +00:00
return ;
}
1999-12-13 13:27:58 +00:00
val_type = atoi ( tmp ) ;
1998-11-10 19:05:00 +00:00
if ( val_type ! = 1 & & val_type ! = 3 & & val_type ! = 4 )
{
1999-12-13 13:27:58 +00:00
fprintf ( out_hnd , " val_type 1=UNISTR, 3=BYTES, 4=DWORD supported \n " ) ;
1998-11-10 19:05:00 +00:00
return ;
}
2001-06-21 09:10:42 +00:00
if ( ! next_token_nr ( NULL , tmp , NULL , sizeof ( tmp ) ) )
1999-12-13 13:27:58 +00:00
{
fprintf ( out_hnd , " regcreate <val_name> <val_type (1|4)> <val> \n " ) ;
return ;
}
1998-11-10 19:05:00 +00:00
switch ( val_type )
{
case 0x01 : /* UNISTR */
{
2005-04-07 04:58:38 +00:00
init_rpc_blob_str ( & value , tmp , strlen ( tmp ) + 1 ) ;
1998-11-10 19:05:00 +00:00
break ;
}
case 0x03 : /* BYTES */
{
2005-04-07 04:58:38 +00:00
init_rpc_blob_hex ( & value , tmp ) ;
1998-11-10 19:05:00 +00:00
break ;
}
case 0x04 : /* DWORD */
{
1999-12-13 13:27:58 +00:00
uint32 tmp_val ;
if ( strnequal ( tmp , " 0x " , 2 ) )
{
tmp_val = strtol ( tmp , ( char * * ) NULL , 16 ) ;
}
else
{
tmp_val = strtol ( tmp , ( char * * ) NULL , 10 ) ;
}
2005-04-07 04:58:38 +00:00
init_rpc_blob_uint32 ( & value , tmp_val ) ;
1998-11-10 19:05:00 +00:00
break ;
}
default :
{
1999-12-13 13:27:58 +00:00
fprintf ( out_hnd , " i told you i only deal with UNISTR, DWORD and BYTES! \n " ) ;
1998-11-10 19:05:00 +00:00
return ;
}
}
DEBUG ( 10 , ( " key data: \n " ) ) ;
1998-11-10 20:51:25 +00:00
dump_data ( 10 , ( char * ) value . buffer , value . buf_len ) ;
1998-11-10 19:05:00 +00:00
1999-12-13 13:27:58 +00:00
/* open WINREG session. */
2002-10-04 04:10:23 +00:00
res = res ? cli_nt_session_open ( smb_cli , PI_WINREG ) : False ;
1999-12-13 13:27:58 +00:00
1998-11-10 19:05:00 +00:00
/* open registry receive a policy handle */
1999-12-13 13:27:58 +00:00
res = res ? do_reg_connect ( smb_cli , keyname , parent_name ,
& info - > dom . reg_pol_connect ) : False ;
1998-11-10 19:05:00 +00:00
1998-11-11 14:23:55 +00:00
if ( ( * val_name ) ! = 0 )
{
/* open an entry */
1999-12-13 13:27:58 +00:00
res3 = res ? do_reg_open_entry ( smb_cli , & info - > dom . reg_pol_connect ,
1998-11-11 14:23:55 +00:00
parent_name , 0x02000000 , & parent_pol ) : False ;
}
else
{
1999-12-13 13:27:58 +00:00
memcpy ( & parent_pol , & info - > dom . reg_pol_connect , sizeof ( parent_pol ) ) ;
1998-11-11 14:23:55 +00:00
}
1998-11-10 19:05:00 +00:00
/* create an entry */
2005-04-07 04:58:38 +00:00
res4 = res3 ? do_reg_set_val ( smb_cli , & parent_pol ,
1998-11-10 19:05:00 +00:00
val_name , val_type , & value ) : False ;
1998-11-11 00:43:41 +00:00
/* flush the modified key */
1999-12-13 13:27:58 +00:00
res4 = res4 ? do_reg_flush_key ( smb_cli , & parent_pol ) : False ;
1998-11-10 22:03:34 +00:00
1998-11-10 19:05:00 +00:00
/* close the val handle */
1998-11-11 14:23:55 +00:00
if ( ( * val_name ) ! = 0 )
{
1999-12-13 13:27:58 +00:00
res3 = res3 ? do_reg_close ( smb_cli , & parent_pol ) : False ;
1998-11-11 14:23:55 +00:00
}
1998-11-10 19:05:00 +00:00
/* close the registry handles */
1999-12-13 13:27:58 +00:00
res = res ? do_reg_close ( smb_cli , & info - > dom . reg_pol_connect ) : False ;
/* close the session */
cli_nt_session_close ( smb_cli ) ;
1998-11-10 19:05:00 +00:00
if ( res & & res3 & & res4 )
{
2005-04-07 04:58:38 +00:00
DEBUG ( 5 , ( " cmd_reg_set_val: query succeeded \n " ) ) ;
1999-12-13 13:27:58 +00:00
fprintf ( out_hnd , " OK \n " ) ;
1998-11-10 19:05:00 +00:00
}
else
{
2005-04-07 04:58:38 +00:00
DEBUG ( 5 , ( " cmd_reg_set_val: query failed \n " ) ) ;
1998-11-10 19:05:00 +00:00
}
}
1998-11-11 00:57:13 +00:00
/****************************************************************************
nt registry delete value
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-08-10 09:52:10 +00:00
static void cmd_reg_delete_val ( struct client_info * info )
1998-11-11 00:57:13 +00:00
{
BOOL res = True ;
BOOL res3 = True ;
BOOL res4 = True ;
POLICY_HND parent_pol ;
1999-12-13 13:27:58 +00:00
fstring full_keyname ;
1998-11-11 14:23:55 +00:00
fstring keyname ;
1998-11-11 00:57:13 +00:00
fstring parent_name ;
fstring val_name ;
1999-12-13 13:27:58 +00:00
DEBUG ( 5 , ( " cmd_reg_delete_val: smb_cli->fd:%d \n " , smb_cli - > fd ) ) ;
1999-11-24 23:40:20 +00:00
2001-06-21 09:10:42 +00:00
if ( ! next_token_nr ( NULL , full_keyname , NULL , sizeof ( full_keyname ) ) )
1998-11-11 00:57:13 +00:00
{
1999-12-13 13:27:58 +00:00
fprintf ( out_hnd , " regdelete <val_name> \n " ) ;
1998-11-11 00:57:13 +00:00
return ;
}
1998-11-11 14:23:55 +00:00
reg_get_subkey ( full_keyname , keyname , val_name ) ;
if ( keyname [ 0 ] = = 0 | | val_name [ 0 ] = = 0 )
1998-11-11 00:57:13 +00:00
{
1999-12-13 13:27:58 +00:00
fprintf ( out_hnd , " invalid key name \n " ) ;
1998-11-11 00:57:13 +00:00
return ;
}
1998-11-11 14:23:55 +00:00
1999-12-13 13:27:58 +00:00
/* open WINREG session. */
2002-10-04 04:10:23 +00:00
res = res ? cli_nt_session_open ( smb_cli , PI_WINREG ) : False ;
1999-12-13 13:27:58 +00:00
1998-11-11 00:57:13 +00:00
/* open registry receive a policy handle */
1999-12-13 13:27:58 +00:00
res = res ? do_reg_connect ( smb_cli , keyname , parent_name ,
& info - > dom . reg_pol_connect ) : False ;
1998-11-11 00:57:13 +00:00
1998-11-11 14:23:55 +00:00
if ( ( * val_name ) ! = 0 )
{
/* open an entry */
1999-12-13 13:27:58 +00:00
res3 = res ? do_reg_open_entry ( smb_cli , & info - > dom . reg_pol_connect ,
1998-11-11 14:23:55 +00:00
parent_name , 0x02000000 , & parent_pol ) : False ;
}
else
{
1999-12-13 13:27:58 +00:00
memcpy ( & parent_pol , & info - > dom . reg_pol_connect , sizeof ( parent_pol ) ) ;
1998-11-11 14:23:55 +00:00
}
1998-11-11 00:57:13 +00:00
1998-11-11 14:23:55 +00:00
/* delete an entry */
1999-12-13 13:27:58 +00:00
res4 = res3 ? do_reg_delete_val ( smb_cli , & parent_pol , val_name ) : False ;
1998-11-11 00:57:13 +00:00
/* flush the modified key */
1999-12-13 13:27:58 +00:00
res4 = res4 ? do_reg_flush_key ( smb_cli , & parent_pol ) : False ;
1998-11-11 00:57:13 +00:00
/* close the key handle */
1999-12-13 13:27:58 +00:00
res3 = res3 ? do_reg_close ( smb_cli , & parent_pol ) : False ;
1998-11-11 00:57:13 +00:00
/* close the registry handles */
1999-12-13 13:27:58 +00:00
res = res ? do_reg_close ( smb_cli , & info - > dom . reg_pol_connect ) : False ;
/* close the session */
cli_nt_session_close ( smb_cli ) ;
1998-11-11 00:57:13 +00:00
if ( res & & res3 & & res4 )
{
DEBUG ( 5 , ( " cmd_reg_delete_val: query succeeded \n " ) ) ;
1999-12-13 13:27:58 +00:00
fprintf ( out_hnd , " OK \n " ) ;
1998-11-11 00:57:13 +00:00
}
else
{
DEBUG ( 5 , ( " cmd_reg_delete_val: query failed \n " ) ) ;
}
}
1998-11-10 22:14:05 +00:00
/****************************************************************************
nt registry delete key
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-08-10 09:52:10 +00:00
static void cmd_reg_delete_key ( struct client_info * info )
1998-11-10 22:14:05 +00:00
{
BOOL res = True ;
BOOL res3 = True ;
BOOL res4 = True ;
POLICY_HND parent_pol ;
1999-12-13 13:27:58 +00:00
fstring full_keyname ;
1998-11-10 22:14:05 +00:00
fstring parent_name ;
fstring key_name ;
1998-11-11 14:23:55 +00:00
fstring subkey_name ;
1998-11-10 22:14:05 +00:00
1999-12-13 13:27:58 +00:00
DEBUG ( 5 , ( " cmd_reg_delete_key: smb_cli->fd:%d \n " , smb_cli - > fd ) ) ;
1998-11-10 22:14:05 +00:00
2001-06-21 09:10:42 +00:00
if ( ! next_token_nr ( NULL , full_keyname , NULL , sizeof ( full_keyname ) ) )
1998-11-10 22:14:05 +00:00
{
1999-12-13 13:27:58 +00:00
fprintf ( out_hnd , " regdeletekey <key_name> \n " ) ;
1998-11-10 22:14:05 +00:00
return ;
}
1998-11-11 14:23:55 +00:00
reg_get_subkey ( full_keyname , parent_name , subkey_name ) ;
if ( parent_name [ 0 ] = = 0 | | subkey_name [ 0 ] = = 0 )
1998-11-10 22:14:05 +00:00
{
1999-12-13 13:27:58 +00:00
fprintf ( out_hnd , " invalid key name \n " ) ;
1998-11-10 22:14:05 +00:00
return ;
}
1998-11-11 14:23:55 +00:00
1999-12-13 13:27:58 +00:00
/* open WINREG session. */
2002-10-04 04:10:23 +00:00
res = res ? cli_nt_session_open ( smb_cli , PI_WINREG ) : False ;
1999-12-13 13:27:58 +00:00
1998-11-10 22:14:05 +00:00
/* open registry receive a policy handle */
1999-12-13 13:27:58 +00:00
res = res ? do_reg_connect ( smb_cli , parent_name , key_name ,
& info - > dom . reg_pol_connect ) : False ;
1998-11-10 22:14:05 +00:00
1998-11-11 14:23:55 +00:00
if ( ( * key_name ) ! = 0 )
{
/* open an entry */
1999-12-13 13:27:58 +00:00
res3 = res ? do_reg_open_entry ( smb_cli , & info - > dom . reg_pol_connect ,
1998-11-11 14:23:55 +00:00
key_name , 0x02000000 , & parent_pol ) : False ;
}
else
{
1999-12-13 13:27:58 +00:00
memcpy ( & parent_pol , & info - > dom . reg_pol_connect , sizeof ( parent_pol ) ) ;
1998-11-11 14:23:55 +00:00
}
1998-11-10 22:14:05 +00:00
/* create an entry */
1999-12-13 13:27:58 +00:00
res4 = res3 ? do_reg_delete_key ( smb_cli , & parent_pol , subkey_name ) : False ;
1998-11-10 22:14:05 +00:00
1998-11-11 00:43:41 +00:00
/* flush the modified key */
1999-12-13 13:27:58 +00:00
res4 = res4 ? do_reg_flush_key ( smb_cli , & parent_pol ) : False ;
1998-11-10 22:14:05 +00:00
/* close the key handle */
1998-11-11 14:23:55 +00:00
if ( ( * key_name ) ! = 0 )
{
1999-12-13 13:27:58 +00:00
res3 = res3 ? do_reg_close ( smb_cli , & parent_pol ) : False ;
1998-11-11 14:23:55 +00:00
}
1998-11-10 22:14:05 +00:00
/* close the registry handles */
1999-12-13 13:27:58 +00:00
res = res ? do_reg_close ( smb_cli , & info - > dom . reg_pol_connect ) : False ;
/* close the session */
cli_nt_session_close ( smb_cli ) ;
1998-11-10 22:14:05 +00:00
if ( res & & res3 & & res4 )
{
DEBUG ( 5 , ( " cmd_reg_delete_key: query succeeded \n " ) ) ;
1999-12-13 13:27:58 +00:00
fprintf ( out_hnd , " OK \n " ) ;
1998-11-10 22:14:05 +00:00
}
else
{
DEBUG ( 5 , ( " cmd_reg_delete_key: query failed \n " ) ) ;
}
}
1998-11-10 19:05:00 +00:00
/****************************************************************************
nt registry create key
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-08-10 09:52:10 +00:00
static void cmd_reg_create_key ( struct client_info * info )
1998-11-10 19:05:00 +00:00
{
BOOL res = True ;
BOOL res3 = True ;
BOOL res4 = True ;
POLICY_HND parent_pol ;
POLICY_HND key_pol ;
1999-12-13 13:27:58 +00:00
fstring full_keyname ;
1998-11-11 14:23:55 +00:00
fstring parent_key ;
1998-11-10 19:05:00 +00:00
fstring parent_name ;
fstring key_name ;
fstring key_class ;
1998-11-12 23:35:05 +00:00
SEC_ACCESS sam_access ;
1998-11-10 19:05:00 +00:00
1999-12-13 13:27:58 +00:00
DEBUG ( 5 , ( " cmd_reg_create_key: smb_cli->fd:%d \n " , smb_cli - > fd ) ) ;
1998-11-10 19:05:00 +00:00
2001-06-21 09:10:42 +00:00
if ( ! next_token_nr ( NULL , full_keyname , NULL , sizeof ( full_keyname ) ) )
1998-11-10 19:05:00 +00:00
{
1999-12-13 13:27:58 +00:00
fprintf ( out_hnd , " regcreate <key_name> [key_class] \n " ) ;
1998-11-10 19:05:00 +00:00
return ;
}
1998-11-11 14:23:55 +00:00
reg_get_subkey ( full_keyname , parent_key , key_name ) ;
if ( parent_key [ 0 ] = = 0 | | key_name [ 0 ] = = 0 )
1998-11-10 19:05:00 +00:00
{
1999-12-13 13:27:58 +00:00
fprintf ( out_hnd , " invalid key name \n " ) ;
1998-11-10 19:05:00 +00:00
return ;
}
1998-11-11 14:23:55 +00:00
2001-06-21 09:10:42 +00:00
if ( ! next_token_nr ( NULL , key_class , NULL , sizeof ( key_class ) ) )
1998-11-10 19:05:00 +00:00
{
memset ( key_class , 0 , sizeof ( key_class ) ) ;
}
/* set access permissions */
1998-11-12 23:35:05 +00:00
sam_access . mask = SEC_RIGHTS_READ ;
1998-11-10 19:05:00 +00:00
1999-12-13 13:27:58 +00:00
/* open WINREG session. */
2002-10-04 04:10:23 +00:00
res = res ? cli_nt_session_open ( smb_cli , PI_WINREG ) : False ;
1999-12-13 13:27:58 +00:00
1998-11-10 19:05:00 +00:00
/* open registry receive a policy handle */
1999-12-13 13:27:58 +00:00
res = res ? do_reg_connect ( smb_cli , parent_key , parent_name ,
& info - > dom . reg_pol_connect ) : False ;
1998-11-10 19:05:00 +00:00
1998-11-11 14:23:55 +00:00
if ( ( * parent_name ) ! = 0 )
{
/* open an entry */
1999-12-13 13:27:58 +00:00
res3 = res ? do_reg_open_entry ( smb_cli , & info - > dom . reg_pol_connect ,
1998-11-11 14:23:55 +00:00
parent_name , 0x02000000 , & parent_pol ) : False ;
}
else
{
1999-12-13 13:27:58 +00:00
memcpy ( & parent_pol , & info - > dom . reg_pol_connect , sizeof ( parent_pol ) ) ;
1998-11-11 14:23:55 +00:00
}
1998-11-10 19:05:00 +00:00
/* create an entry */
1999-12-13 13:27:58 +00:00
res4 = res3 ? do_reg_create_key ( smb_cli , & parent_pol ,
1998-11-10 19:05:00 +00:00
key_name , key_class , & sam_access , & key_pol ) : False ;
1998-11-11 00:43:41 +00:00
/* flush the modified key */
1999-12-13 13:27:58 +00:00
res4 = res4 ? do_reg_flush_key ( smb_cli , & parent_pol ) : False ;
1998-11-10 22:03:34 +00:00
1998-11-10 19:05:00 +00:00
/* close the key handle */
1999-12-13 13:27:58 +00:00
res4 = res4 ? do_reg_close ( smb_cli , & key_pol ) : False ;
1998-11-10 19:05:00 +00:00
/* close the key handle */
1998-11-11 14:23:55 +00:00
if ( ( * parent_name ) ! = 0 )
{
1999-12-13 13:27:58 +00:00
res3 = res3 ? do_reg_close ( smb_cli , & parent_pol ) : False ;
1998-11-11 14:23:55 +00:00
}
1998-11-10 19:05:00 +00:00
/* close the registry handles */
1999-12-13 13:27:58 +00:00
res = res ? do_reg_close ( smb_cli , & info - > dom . reg_pol_connect ) : False ;
/* close the session */
cli_nt_session_close ( smb_cli ) ;
1998-11-10 19:05:00 +00:00
if ( res & & res3 & & res4 )
{
DEBUG ( 5 , ( " cmd_reg_create_key: query succeeded \n " ) ) ;
1999-12-13 13:27:58 +00:00
fprintf ( out_hnd , " OK \n " ) ;
1998-11-10 19:05:00 +00:00
}
else
{
DEBUG ( 5 , ( " cmd_reg_create_key: query failed \n " ) ) ;
}
}
1998-11-09 16:40:38 +00:00
/****************************************************************************
nt registry security info
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-08-10 09:52:10 +00:00
static void cmd_reg_test_key_sec ( struct client_info * info )
1998-11-09 16:40:38 +00:00
{
BOOL res = True ;
BOOL res3 = True ;
BOOL res4 = True ;
POLICY_HND key_pol ;
1999-12-13 13:27:58 +00:00
fstring full_keyname ;
1998-11-09 16:40:38 +00:00
fstring key_name ;
/*
* security info
*/
uint32 sec_buf_size ;
1999-12-13 13:27:58 +00:00
SEC_DESC_BUF * psdb ;
1999-11-24 23:40:20 +00:00
1999-12-13 13:27:58 +00:00
DEBUG ( 5 , ( " cmd_reg_get_key_sec: smb_cli->fd:%d \n " , smb_cli - > fd ) ) ;
1998-11-09 16:40:38 +00:00
2001-06-21 09:10:42 +00:00
if ( ! next_token_nr ( NULL , full_keyname , NULL , sizeof ( full_keyname ) ) )
1998-11-09 16:40:38 +00:00
{
1999-12-13 13:27:58 +00:00
fprintf ( out_hnd , " reggetsec <key_name> \n " ) ;
1998-11-09 16:40:38 +00:00
return ;
}
1999-12-13 13:27:58 +00:00
/* open WINREG session. */
2002-10-04 04:10:23 +00:00
res = res ? cli_nt_session_open ( smb_cli , PI_WINREG ) : False ;
1999-11-22 20:14:13 +00:00
1998-11-09 16:40:38 +00:00
/* open registry receive a policy handle */
1999-12-13 13:27:58 +00:00
res = res ? do_reg_connect ( smb_cli , full_keyname , key_name ,
& info - > dom . reg_pol_connect ) : False ;
1998-11-09 16:40:38 +00:00
1998-11-11 14:23:55 +00:00
if ( ( * key_name ) ! = 0 )
{
/* open an entry */
1999-12-13 13:27:58 +00:00
res3 = res ? do_reg_open_entry ( smb_cli , & info - > dom . reg_pol_connect ,
1998-11-11 14:23:55 +00:00
key_name , 0x02000000 , & key_pol ) : False ;
}
else
{
1999-12-13 13:27:58 +00:00
memcpy ( & key_pol , & info - > dom . reg_pol_connect , sizeof ( key_pol ) ) ;
1998-11-11 14:23:55 +00:00
}
1998-11-09 16:40:38 +00:00
/* open an entry */
1999-12-13 13:27:58 +00:00
res3 = res ? do_reg_open_entry ( smb_cli , & info - > dom . reg_pol_connect ,
1998-11-09 16:40:38 +00:00
key_name , 0x02000000 , & key_pol ) : False ;
1999-08-03 20:30:25 +00:00
/* query key sec info. first call sets sec_buf_size. */
1998-11-11 19:22:08 +00:00
1999-12-13 13:27:58 +00:00
sec_buf_size = 0 ;
res4 = res3 ? do_reg_get_key_sec ( smb_cli , & key_pol ,
& sec_buf_size , & psdb ) : False ;
1998-11-09 16:40:38 +00:00
1999-12-13 13:27:58 +00:00
free_sec_desc_buf ( & psdb ) ;
1998-11-12 23:35:05 +00:00
1999-12-13 13:27:58 +00:00
res4 = res4 ? do_reg_get_key_sec ( smb_cli , & key_pol ,
& sec_buf_size , & psdb ) : False ;
1998-11-09 16:40:38 +00:00
1999-12-13 13:27:58 +00:00
if ( res4 & & psdb - > len > 0 & & psdb - > sec ! = NULL )
1998-11-09 16:40:38 +00:00
{
1999-12-13 13:27:58 +00: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 19:21:20 +00:00
1999-12-13 13:27:58 +00:00
res4 = res4 ? do_reg_set_key_sec ( smb_cli , & key_pol , psdb ) : False ;
1998-11-09 16:40:38 +00:00
}
1999-12-13 13:27:58 +00:00
free_sec_desc_buf ( & psdb ) ;
1998-11-09 16:40:38 +00:00
/* close the key handle */
1998-11-11 14:23:55 +00:00
if ( ( * key_name ) ! = 0 )
{
1999-12-13 13:27:58 +00:00
res3 = res3 ? do_reg_close ( smb_cli , & key_pol ) : False ;
1998-11-11 14:23:55 +00:00
}
1998-11-09 16:40:38 +00:00
/* close the registry handles */
1999-12-13 13:27:58 +00:00
res = res ? do_reg_close ( smb_cli , & info - > dom . reg_pol_connect ) : False ;
/* close the session */
cli_nt_session_close ( smb_cli ) ;
1998-11-09 16:40:38 +00:00
if ( res & & res3 & & res4 )
{
DEBUG ( 5 , ( " cmd_reg_test2: query succeeded \n " ) ) ;
1999-12-13 13:27:58 +00:00
fprintf ( out_hnd , " Registry Test2 \n " ) ;
1998-11-09 16:40:38 +00:00
}
else
{
DEBUG ( 5 , ( " cmd_reg_test2: query failed \n " ) ) ;
}
}
1998-11-12 19:21:20 +00:00
/****************************************************************************
nt registry security info
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-08-10 09:52:10 +00:00
static void cmd_reg_get_key_sec ( struct client_info * info )
1998-11-12 19:21:20 +00:00
{
BOOL res = True ;
BOOL res3 = True ;
BOOL res4 = True ;
POLICY_HND key_pol ;
1999-12-13 13:27:58 +00:00
fstring full_keyname ;
1998-11-12 19:21:20 +00:00
fstring key_name ;
/*
* security info
*/
uint32 sec_buf_size ;
1999-12-13 13:27:58 +00:00
SEC_DESC_BUF * psdb ;
1999-11-24 23:40:20 +00:00
1999-12-13 13:27:58 +00:00
DEBUG ( 5 , ( " cmd_reg_get_key_sec: smb_cli->fd:%d \n " , smb_cli - > fd ) ) ;
1998-11-12 19:21:20 +00:00
2001-06-21 09:10:42 +00:00
if ( ! next_token_nr ( NULL , full_keyname , NULL , sizeof ( full_keyname ) ) )
1998-11-12 19:21:20 +00:00
{
1999-12-13 13:27:58 +00:00
fprintf ( out_hnd , " reggetsec <key_name> \n " ) ;
1998-11-12 19:21:20 +00:00
return ;
}
1999-12-13 13:27:58 +00:00
/* open WINREG session. */
2002-10-04 04:10:23 +00:00
res = res ? cli_nt_session_open ( smb_cli , PI_WINREG ) : False ;
1999-11-22 20:14:13 +00:00
1998-11-12 19:21:20 +00:00
/* open registry receive a policy handle */
1999-12-13 13:27:58 +00:00
res = res ? do_reg_connect ( smb_cli , full_keyname , key_name ,
& info - > dom . reg_pol_connect ) : False ;
1998-11-12 19:21:20 +00:00
if ( ( * key_name ) ! = 0 )
{
/* open an entry */
1999-12-13 13:27:58 +00:00
res3 = res ? do_reg_open_entry ( smb_cli , & info - > dom . reg_pol_connect ,
1998-11-12 19:21:20 +00:00
key_name , 0x02000000 , & key_pol ) : False ;
}
else
{
1999-12-13 13:27:58 +00:00
memcpy ( & key_pol , & info - > dom . reg_pol_connect , sizeof ( key_pol ) ) ;
1998-11-12 19:21:20 +00:00
}
/* open an entry */
1999-12-13 13:27:58 +00:00
res3 = res ? do_reg_open_entry ( smb_cli , & info - > dom . reg_pol_connect ,
1998-11-12 19:21:20 +00:00
key_name , 0x02000000 , & key_pol ) : False ;
1999-12-13 13:27:58 +00:00
/* Get the size. */
1998-11-12 19:21:20 +00:00
sec_buf_size = 0 ;
1999-12-13 13:27:58 +00:00
res4 = res3 ? do_reg_get_key_sec ( smb_cli , & key_pol ,
& sec_buf_size , & psdb ) : False ;
1998-11-12 19:21:20 +00:00
1999-12-13 13:27:58 +00:00
free_sec_desc_buf ( & psdb ) ;
1998-11-12 23:35:05 +00:00
1999-12-13 13:27:58 +00:00
res4 = res4 ? do_reg_get_key_sec ( smb_cli , & key_pol ,
& sec_buf_size , & psdb ) : False ;
1998-11-12 19:21:20 +00:00
1999-12-13 13:27:58 +00:00
if ( res4 & & psdb - > len > 0 & & psdb - > sec ! = NULL )
1998-11-12 19:21:20 +00:00
{
1999-12-13 13:27:58 +00: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 19:21:20 +00:00
}
1999-12-13 13:27:58 +00:00
free_sec_desc_buf ( & psdb ) ;
1998-11-12 19:21:20 +00:00
/* close the key handle */
if ( ( * key_name ) ! = 0 )
{
1999-12-13 13:27:58 +00:00
res3 = res3 ? do_reg_close ( smb_cli , & key_pol ) : False ;
1998-11-12 19:21:20 +00:00
}
/* close the registry handles */
1999-12-13 13:27:58 +00:00
res = res ? do_reg_close ( smb_cli , & info - > dom . reg_pol_connect ) : False ;
/* close the session */
cli_nt_session_close ( smb_cli ) ;
1998-11-12 19:21:20 +00: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 " ) ) ;
}
}
2001-08-10 09:52:10 +00:00
/****************************************************************************
nt registry shutdown
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-10-12 05:56:23 +00:00
static NTSTATUS cmd_reg_shutdown ( struct cli_state * cli , TALLOC_CTX * mem_ctx ,
2003-02-25 23:51:56 +00:00
int argc , const char * * argv )
2001-08-10 09:52:10 +00:00
{
2001-09-04 10:57:29 +00:00
NTSTATUS result = NT_STATUS_UNSUCCESSFUL ;
2001-08-10 09:52:10 +00:00
fstring msg ;
uint32 timeout = 20 ;
2003-01-04 07:50:04 +00:00
BOOL force = False ;
BOOL reboot = False ;
2001-08-10 09:52:10 +00:00
int opt ;
* msg = 0 ;
optind = 0 ; /* TODO: test if this hack works on other systems too --simo */
while ( ( opt = getopt ( argc , argv , " m:t:rf " ) ) ! = EOF )
{
2003-01-04 07:50:04 +00:00
/*fprintf (stderr, "[%s]\n", argv[argc-1]);*/
2001-08-10 09:52:10 +00:00
switch ( opt )
{
case ' m ' :
2003-03-18 06:30:30 +00:00
fstrcpy ( msg , optarg ) ;
2003-01-04 07:50:04 +00:00
/*fprintf (stderr, "[%s|%s]\n", optarg, msg);*/
2001-08-10 09:52:10 +00:00
break ;
2003-01-04 07:50:04 +00:00
2001-08-10 09:52:10 +00:00
case ' t ' :
timeout = atoi ( optarg ) ;
2003-01-04 07:50:04 +00:00
/*fprintf (stderr, "[%s|%d]\n", optarg, timeout);*/
break ;
2001-08-10 09:52:10 +00:00
case ' r ' :
2003-01-04 07:50:04 +00:00
reboot = True ;
break ;
2001-08-10 09:52:10 +00:00
case ' f ' :
2003-01-04 07:50:04 +00:00
force = True ;
2001-08-10 09:52:10 +00:00
break ;
2003-01-04 07:50:04 +00:00
2001-08-10 09:52:10 +00:00
}
}
/* create an entry */
2005-01-10 20:33:41 +00:00
result = werror_to_ntstatus ( cli_reg_shutdown ( cli , mem_ctx , msg , timeout , reboot , force ) ) ;
2001-08-10 09:52:10 +00:00
2001-09-04 10:57:29 +00:00
if ( NT_STATUS_IS_OK ( result ) )
2001-08-10 09:52:10 +00:00
DEBUG ( 5 , ( " cmd_reg_shutdown: query succeeded \n " ) ) ;
else
DEBUG ( 5 , ( " cmd_reg_shutdown: query failed \n " ) ) ;
return result ;
}
/****************************************************************************
abort a shutdown
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-10-12 05:56:23 +00:00
static NTSTATUS cmd_reg_abort_shutdown ( struct cli_state * cli ,
TALLOC_CTX * mem_ctx , int argc ,
2003-02-25 23:51:56 +00:00
const char * * argv )
2001-08-10 09:52:10 +00:00
{
2001-09-04 10:57:29 +00:00
NTSTATUS result = NT_STATUS_UNSUCCESSFUL ;
2001-08-10 09:52:10 +00:00
2005-01-10 20:33:41 +00:00
result = werror_to_ntstatus ( cli_reg_abort_shutdown ( cli , mem_ctx ) ) ;
2001-08-10 09:52:10 +00:00
2001-09-04 10:57:29 +00:00
if ( NT_STATUS_IS_OK ( result ) )
2001-08-10 09:52:10 +00:00
DEBUG ( 5 , ( " cmd_reg_abort_shutdown: query succeeded \n " ) ) ;
else
DEBUG ( 5 , ( " cmd_reg_abort_shutdown: query failed \n " ) ) ;
return result ;
}
2005-02-01 19:04:13 +00:00
# endif /* This whole file need to be rewritten for the cirrent rpcclient interface */
2001-08-10 09:52:10 +00:00
/* List of commands exported by this module */
struct cmd_set reg_commands [ ] = {
{ " REG " } ,
2005-02-01 19:04:13 +00:00
#if 0
2003-03-18 06:30:30 +00:00
{ " shutdown " , RPC_RTYPE_NTSTATUS , cmd_reg_shutdown , NULL , PI_WINREG , " Remote Shutdown " ,
2003-01-04 07:50:04 +00:00
" syntax: shutdown [-m message] [-t timeout] [-r] [-h] [-f] (-r == reboot, -h == halt, -f == force) " } ,
2001-08-10 09:52:10 +00:00
2003-03-18 06:30:30 +00:00
{ " abortshutdown " , RPC_RTYPE_NTSTATUS , cmd_reg_abort_shutdown , NULL , PI_WINREG , " Abort Shutdown " ,
2003-01-04 07:50:04 +00:00
" syntax: abortshutdown " } ,
2005-02-01 19:04:13 +00:00
{ " regenum " , cmd_reg_enum , " Registry Enumeration " , " <keyname> " } ,
{ " regdeletekey " , cmd_reg_delete_key , " Registry Key Delete " , " <keyname> " } ,
{ " regcreatekey " , cmd_reg_create_key , " Registry Key Create " , " <keyname> [keyclass] " } ,
{ " regqueryval " , cmd_reg_query_info , " Registry Value Query " , " <valname> " } ,
{ " regquerykey " , cmd_reg_query_key , " Registry Key Query " , " <keyname> " } ,
{ " regdeleteval " , cmd_reg_delete_val , " Registry Value Delete " , " <valname> " } ,
2005-04-07 04:58:38 +00:00
{ " regsetval " , cmd_reg_set_val , " Registry Key Create " , " <valname> <valtype> <value> " } ,
2005-02-01 19:04:13 +00:00
{ " reggetsec " , cmd_reg_get_key_sec , " Registry Key Security " , " <keyname> " } ,
{ " regtestsec " , cmd_reg_test_key_sec , " Test Registry Key Security " , " <keyname> " } ,
# endif
2001-08-10 09:52:10 +00:00
{ NULL }
} ;