0001-01-01 02:30:17 +02:30
/*
0001-01-01 02:30:17 +02:30
* Unix SMB / CIFS implementation .
0001-01-01 02:30:17 +02:30
* RPC Pipe client / server routines
0001-01-01 02:30:17 +02:30
* Copyright ( C ) Andrew Tridgell 1992 - 1998 ,
* Copyright ( C ) Luke Kenneth Casson Leighton 1996 - 1998 ,
* Copyright ( C ) Paul Ashton 1997 - 1998.
0001-01-01 02:30:17 +02:30
* Copyright ( C ) Jeremy Allison 1999.
0001-01-01 02:30:17 +02:30
*
* 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"
0001-01-01 02:30:17 +02:30
# undef DBGC_CLASS
# define DBGC_CLASS DBGC_RPC_CLI
0001-01-01 02:30:17 +02:30
/****************************************************************************
do a REG Open Policy
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
0001-01-01 02:30:17 +02:30
BOOL do_reg_connect ( struct cli_state * cli , char * full_keyname , char * key_name ,
0001-01-01 02:30:17 +02:30
POLICY_HND * reg_hnd )
0001-01-01 02:30:17 +02:30
{
0001-01-01 02:30:17 +02:30
BOOL res = True ;
uint32 reg_type = 0 ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( full_keyname = = NULL )
0001-01-01 02:30:17 +02:30
return False ;
0001-01-01 02:30:17 +02:30
ZERO_STRUCTP ( reg_hnd ) ;
/*
* open registry receive a policy handle
*/
0001-01-01 02:30:17 +02:30
if ( ! reg_split_key ( full_keyname , & reg_type , key_name ) ) {
DEBUG ( 0 , ( " do_reg_connect: unrecognised key name %s \n " , full_keyname ) ) ;
0001-01-01 02:30:17 +02:30
return False ;
}
0001-01-01 02:30:17 +02:30
switch ( reg_type ) {
case HKEY_LOCAL_MACHINE :
res = res ? do_reg_open_hklm ( cli , 0x84E0 , 0x02000000 , reg_hnd ) : False ;
break ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
case HKEY_USERS :
res = res ? do_reg_open_hku ( cli , 0x84E0 , 0x02000000 , reg_hnd ) : False ;
break ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
default :
DEBUG ( 0 , ( " do_reg_connect: unrecognised hive key \n " ) ) ;
return False ;
0001-01-01 02:30:17 +02:30
}
0001-01-01 02:30:17 +02:30
return res ;
0001-01-01 02:30:17 +02:30
}
0001-01-01 02:30:17 +02:30
/****************************************************************************
do a REG Open Policy
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
0001-01-01 02:30:17 +02:30
BOOL do_reg_open_hklm ( struct cli_state * cli , uint16 unknown_0 , uint32 level ,
0001-01-01 02:30:17 +02:30
POLICY_HND * hnd )
{
prs_struct rbuf ;
prs_struct buf ;
0001-01-01 02:30:17 +02:30
REG_Q_OPEN_HKLM q_o ;
0001-01-01 02:30:17 +02:30
REG_R_OPEN_HKLM r_o ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( hnd = = NULL )
return False ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
prs_init ( & buf , MAX_PDU_FRAG_LEN , cli - > mem_ctx , MARSHALL ) ;
prs_init ( & rbuf , 0 , cli - > mem_ctx , UNMARSHALL ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
/* create and send a MSRPC command with api REG_OPEN_HKLM */
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
DEBUG ( 4 , ( " REG Open HKLM \n " ) ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
init_reg_q_open_hklm ( & q_o , unknown_0 , level ) ;
0001-01-01 02:30:17 +02:30
/* turn parameters into data stream */
0001-01-01 02:30:17 +02:30
if ( ! reg_io_q_open_hklm ( " " , & q_o , & buf , 0 ) ) {
prs_mem_free ( & buf ) ;
prs_mem_free ( & rbuf ) ;
return False ;
}
0001-01-01 02:30:17 +02:30
/* send the data on \PIPE\ */
0001-01-01 02:30:17 +02:30
if ( ! rpc_api_pipe_req ( cli , REG_OPEN_HKLM , & buf , & rbuf ) ) {
prs_mem_free ( & buf ) ;
prs_mem_free ( & rbuf ) ;
return False ;
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
prs_mem_free ( & buf ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
ZERO_STRUCT ( r_o ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( ! reg_io_r_open_hklm ( " " , & r_o , & rbuf , 0 ) ) {
prs_mem_free ( & rbuf ) ;
return False ;
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( r_o . status ! = 0 ) {
/* report error code */
0001-01-01 02:30:17 +02:30
DEBUG ( 0 , ( " REG_OPEN_HKLM: %s \n " , nt_errstr ( r_o . status ) ) ) ;
0001-01-01 02:30:17 +02:30
prs_mem_free ( & rbuf ) ;
return False ;
0001-01-01 02:30:17 +02:30
}
0001-01-01 02:30:17 +02:30
/* ok, at last: we're happy. return the policy handle */
0001-01-01 02:30:17 +02:30
* hnd = r_o . pol ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
prs_mem_free ( & rbuf ) ;
0001-01-01 02:30:17 +02:30
return True ;
0001-01-01 02:30:17 +02:30
}
/****************************************************************************
0001-01-01 02:30:17 +02:30
do a REG Open HKU
0001-01-01 02:30:17 +02:30
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
0001-01-01 02:30:17 +02:30
BOOL do_reg_open_hku ( struct cli_state * cli , uint16 unknown_0 , uint32 level ,
0001-01-01 02:30:17 +02:30
POLICY_HND * hnd )
{
prs_struct rbuf ;
prs_struct buf ;
0001-01-01 02:30:17 +02:30
REG_Q_OPEN_HKU q_o ;
0001-01-01 02:30:17 +02:30
REG_R_OPEN_HKU r_o ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( hnd = = NULL )
return False ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
prs_init ( & buf , MAX_PDU_FRAG_LEN , cli - > mem_ctx , MARSHALL ) ;
prs_init ( & rbuf , 0 , cli - > mem_ctx , UNMARSHALL ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
/* create and send a MSRPC command with api REG_OPEN_HKU */
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
DEBUG ( 4 , ( " REG Open HKU \n " ) ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
init_reg_q_open_hku ( & q_o , unknown_0 , level ) ;
0001-01-01 02:30:17 +02:30
/* turn parameters into data stream */
0001-01-01 02:30:17 +02:30
if ( ! reg_io_q_open_hku ( " " , & q_o , & buf , 0 ) ) {
prs_mem_free ( & buf ) ;
prs_mem_free ( & rbuf ) ;
return False ;
}
0001-01-01 02:30:17 +02:30
/* send the data on \PIPE\ */
0001-01-01 02:30:17 +02:30
if ( rpc_api_pipe_req ( cli , REG_OPEN_HKU , & buf , & rbuf ) ) {
prs_mem_free ( & buf ) ;
prs_mem_free ( & rbuf ) ;
return False ;
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
prs_mem_free ( & buf ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
ZERO_STRUCT ( r_o ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( ! reg_io_r_open_hku ( " " , & r_o , & rbuf , 0 ) ) {
prs_mem_free ( & rbuf ) ;
return False ;
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( r_o . status ! = 0 ) {
/* report error code */
0001-01-01 02:30:17 +02:30
DEBUG ( 0 , ( " REG_OPEN_HKU: %s \n " , nt_errstr ( r_o . status ) ) ) ;
0001-01-01 02:30:17 +02:30
prs_mem_free ( & rbuf ) ;
return False ;
0001-01-01 02:30:17 +02:30
}
0001-01-01 02:30:17 +02:30
/* ok, at last: we're happy. return the policy handle */
0001-01-01 02:30:17 +02:30
* hnd = r_o . pol ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
prs_mem_free ( & rbuf ) ;
0001-01-01 02:30:17 +02:30
return True ;
0001-01-01 02:30:17 +02:30
}
0001-01-01 02:30:17 +02:30
/****************************************************************************
do a REG Unknown 0xB command . sent after a create key or create value .
this might be some sort of " sync " or " refresh " command , sent after
modification of the registry . . .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
0001-01-01 02:30:17 +02:30
BOOL do_reg_flush_key ( struct cli_state * cli , POLICY_HND * hnd )
0001-01-01 02:30:17 +02:30
{
prs_struct rbuf ;
prs_struct buf ;
0001-01-01 02:30:17 +02:30
REG_Q_FLUSH_KEY q_o ;
0001-01-01 02:30:17 +02:30
REG_R_FLUSH_KEY r_o ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( hnd = = NULL )
return False ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
prs_init ( & buf , MAX_PDU_FRAG_LEN , cli - > mem_ctx , MARSHALL ) ;
prs_init ( & rbuf , 0 , cli - > mem_ctx , UNMARSHALL ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
/* create and send a MSRPC command with api REG_FLUSH_KEY */
0001-01-01 02:30:17 +02:30
DEBUG ( 4 , ( " REG Unknown 0xB \n " ) ) ;
0001-01-01 02:30:17 +02:30
init_reg_q_flush_key ( & q_o , hnd ) ;
0001-01-01 02:30:17 +02:30
/* turn parameters into data stream */
0001-01-01 02:30:17 +02:30
if ( ! reg_io_q_flush_key ( " " , & q_o , & buf , 0 ) ) {
prs_mem_free ( & buf ) ;
prs_mem_free ( & rbuf ) ;
return False ;
}
0001-01-01 02:30:17 +02:30
/* send the data on \PIPE\ */
0001-01-01 02:30:17 +02:30
if ( ! rpc_api_pipe_req ( cli , REG_FLUSH_KEY , & buf , & rbuf ) ) {
prs_mem_free ( & buf ) ;
prs_mem_free ( & rbuf ) ;
return False ;
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
prs_mem_free ( & buf ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
ZERO_STRUCT ( r_o ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( ! reg_io_r_flush_key ( " " , & r_o , & rbuf , 0 ) ) {
prs_mem_free ( & rbuf ) ;
return False ;
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( r_o . status ! = 0 ) {
/* report error code */
0001-01-01 02:30:17 +02:30
DEBUG ( 0 , ( " REG_FLUSH_KEY: %s \n " , nt_errstr ( r_o . status ) ) ) ;
0001-01-01 02:30:17 +02:30
prs_mem_free ( & rbuf ) ;
return False ;
0001-01-01 02:30:17 +02:30
}
prs_mem_free ( & rbuf ) ;
0001-01-01 02:30:17 +02:30
return True ;
0001-01-01 02:30:17 +02:30
}
0001-01-01 02:30:17 +02:30
/****************************************************************************
0001-01-01 02:30:17 +02:30
do a REG Query Key
0001-01-01 02:30:17 +02:30
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
0001-01-01 02:30:17 +02:30
BOOL do_reg_query_key ( struct cli_state * cli , POLICY_HND * hnd ,
char * class , uint32 * class_len ,
0001-01-01 02:30:17 +02:30
uint32 * num_subkeys , uint32 * max_subkeylen ,
0001-01-01 02:30:17 +02:30
uint32 * max_subkeysize , uint32 * num_values ,
0001-01-01 02:30:17 +02:30
uint32 * max_valnamelen , uint32 * max_valbufsize ,
0001-01-01 02:30:17 +02:30
uint32 * sec_desc , NTTIME * mod_time )
0001-01-01 02:30:17 +02:30
{
prs_struct rbuf ;
prs_struct buf ;
0001-01-01 02:30:17 +02:30
REG_Q_QUERY_KEY q_o ;
0001-01-01 02:30:17 +02:30
REG_R_QUERY_KEY r_o ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( hnd = = NULL )
return False ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
prs_init ( & buf , MAX_PDU_FRAG_LEN , cli - > mem_ctx , MARSHALL ) ;
prs_init ( & rbuf , 0 , cli - > mem_ctx , UNMARSHALL ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
/* create and send a MSRPC command with api REG_QUERY_KEY */
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
DEBUG ( 4 , ( " REG Query Key \n " ) ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
init_reg_q_query_key ( & q_o , hnd , * class_len ) ;
0001-01-01 02:30:17 +02:30
/* turn parameters into data stream */
0001-01-01 02:30:17 +02:30
if ( ! reg_io_q_query_key ( " " , & q_o , & buf , 0 ) ) {
prs_mem_free ( & buf ) ;
prs_mem_free ( & rbuf ) ;
return False ;
}
0001-01-01 02:30:17 +02:30
/* send the data on \PIPE\ */
0001-01-01 02:30:17 +02:30
if ( ! rpc_api_pipe_req ( cli , REG_QUERY_KEY , & buf , & rbuf ) ) {
prs_mem_free ( & buf ) ;
prs_mem_free ( & rbuf ) ;
return False ;
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
prs_mem_free ( & buf ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
ZERO_STRUCT ( r_o ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( ! reg_io_r_query_key ( " " , & r_o , & rbuf , 0 ) ) {
prs_mem_free ( & rbuf ) ;
return False ;
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( r_o . status ! = 0 ) {
/* report error code */
0001-01-01 02:30:17 +02:30
DEBUG ( 0 , ( " REG_QUERY_KEY: %s \n " , nt_errstr ( r_o . status ) ) ) ;
0001-01-01 02:30:17 +02:30
prs_mem_free ( & rbuf ) ;
return False ;
0001-01-01 02:30:17 +02:30
}
0001-01-01 02:30:17 +02:30
* class_len = r_o . hdr_class . uni_max_len ;
0001-01-01 02:30:17 +02:30
rpcstr_pull ( class , & r_o . uni_class , - 1 , - 1 , 0 ) ;
0001-01-01 02:30:17 +02:30
* num_subkeys = r_o . num_subkeys ;
* max_subkeylen = r_o . max_subkeylen ;
* max_subkeysize = r_o . max_subkeysize ;
* num_values = r_o . num_values ;
* max_valnamelen = r_o . max_valnamelen ;
* max_valbufsize = r_o . max_valbufsize ;
* sec_desc = r_o . sec_desc ;
* mod_time = r_o . mod_time ;
0001-01-01 02:30:17 +02:30
prs_mem_free ( & rbuf ) ;
0001-01-01 02:30:17 +02:30
return True ;
0001-01-01 02:30:17 +02:30
}
/****************************************************************************
do a REG Unknown 1 A
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
0001-01-01 02:30:17 +02:30
BOOL do_reg_unknown_1a ( struct cli_state * cli , POLICY_HND * hnd , uint32 * unk )
0001-01-01 02:30:17 +02:30
{
prs_struct rbuf ;
prs_struct buf ;
REG_Q_UNK_1A q_o ;
0001-01-01 02:30:17 +02:30
REG_R_UNK_1A r_o ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( hnd = = NULL )
return False ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
prs_init ( & buf , MAX_PDU_FRAG_LEN , cli - > mem_ctx , MARSHALL ) ;
prs_init ( & rbuf , 0 , cli - > mem_ctx , UNMARSHALL ) ;
0001-01-01 02:30:17 +02:30
/* create and send a MSRPC command with api REG_UNKNOWN_1A */
DEBUG ( 4 , ( " REG Unknown 1a \n " ) ) ;
0001-01-01 02:30:17 +02:30
init_reg_q_unk_1a ( & q_o , hnd ) ;
0001-01-01 02:30:17 +02:30
/* turn parameters into data stream */
0001-01-01 02:30:17 +02:30
if ( ! reg_io_q_unk_1a ( " " , & q_o , & buf , 0 ) ) {
prs_mem_free ( & buf ) ;
prs_mem_free ( & rbuf ) ;
return False ;
}
0001-01-01 02:30:17 +02:30
/* send the data on \PIPE\ */
0001-01-01 02:30:17 +02:30
if ( rpc_api_pipe_req ( cli , REG_UNK_1A , & buf , & rbuf ) ) {
prs_mem_free ( & buf ) ;
prs_mem_free ( & rbuf ) ;
return False ;
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
prs_mem_free ( & buf ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
ZERO_STRUCT ( r_o ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( ! reg_io_r_unk_1a ( " " , & r_o , & rbuf , 0 ) ) {
prs_mem_free ( & rbuf ) ;
return False ;
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( r_o . status ! = 0 ) {
/* report error code */
0001-01-01 02:30:17 +02:30
DEBUG ( 0 , ( " REG_UNK_1A: %s \n " , nt_errstr ( r_o . status ) ) ) ;
0001-01-01 02:30:17 +02:30
prs_mem_free ( & rbuf ) ;
return False ;
0001-01-01 02:30:17 +02:30
}
0001-01-01 02:30:17 +02:30
( * unk ) = r_o . unknown ;
0001-01-01 02:30:17 +02:30
prs_mem_free ( & rbuf ) ;
0001-01-01 02:30:17 +02:30
return True ;
0001-01-01 02:30:17 +02:30
}
/****************************************************************************
do a REG Query Info
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
0001-01-01 02:30:17 +02:30
BOOL do_reg_query_info ( struct cli_state * cli , POLICY_HND * hnd ,
0001-01-01 02:30:17 +02:30
char * key_value , uint32 * key_type )
0001-01-01 02:30:17 +02:30
{
prs_struct rbuf ;
prs_struct buf ;
REG_Q_INFO q_o ;
0001-01-01 02:30:17 +02:30
REG_R_INFO r_o ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( hnd = = NULL )
return False ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
prs_init ( & buf , MAX_PDU_FRAG_LEN , cli - > mem_ctx , MARSHALL ) ;
prs_init ( & rbuf , 0 , cli - > mem_ctx , UNMARSHALL ) ;
0001-01-01 02:30:17 +02:30
/* create and send a MSRPC command with api REG_INFO */
DEBUG ( 4 , ( " REG Query Info \n " ) ) ;
0001-01-01 02:30:17 +02:30
init_reg_q_info ( & q_o , hnd , " ProductType " ) ;
0001-01-01 02:30:17 +02:30
/* turn parameters into data stream */
0001-01-01 02:30:17 +02:30
if ( ! reg_io_q_info ( " " , & q_o , & buf , 0 ) ) {
prs_mem_free ( & buf ) ;
prs_mem_free ( & rbuf ) ;
return False ;
}
0001-01-01 02:30:17 +02:30
/* send the data on \PIPE\ */
0001-01-01 02:30:17 +02:30
if ( ! rpc_api_pipe_req ( cli , REG_INFO , & buf , & rbuf ) ) {
prs_mem_free ( & buf ) ;
prs_mem_free ( & rbuf ) ;
return False ;
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
prs_mem_free ( & buf ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
ZERO_STRUCT ( r_o ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( ! reg_io_r_info ( " " , & r_o , & rbuf , 0 ) ) {
prs_mem_free ( & rbuf ) ;
return False ;
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( r_o . status ! = 0 ) {
/* report error code */
0001-01-01 02:30:17 +02:30
DEBUG ( 0 , ( " REG_INFO: %s \n " , nt_errstr ( r_o . status ) ) ) ;
0001-01-01 02:30:17 +02:30
prs_mem_free ( & rbuf ) ;
return False ;
0001-01-01 02:30:17 +02:30
}
0001-01-01 02:30:17 +02:30
/*fstrcpy(key_value, dos_buffer2_to_str(r_o.uni_val));*/
rpcstr_pull ( key_value , r_o . uni_val - > buffer , sizeof ( fstring ) , r_o . uni_val - > buf_len , 0 ) ;
0001-01-01 02:30:17 +02:30
* key_type = r_o . type ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
prs_mem_free ( & rbuf ) ;
0001-01-01 02:30:17 +02:30
return True ;
0001-01-01 02:30:17 +02:30
}
0001-01-01 02:30:17 +02:30
/****************************************************************************
do a REG Set Key Security
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
0001-01-01 02:30:17 +02:30
BOOL do_reg_set_key_sec ( struct cli_state * cli , POLICY_HND * hnd , SEC_DESC_BUF * sec_desc_buf )
0001-01-01 02:30:17 +02:30
{
prs_struct rbuf ;
prs_struct buf ;
REG_Q_SET_KEY_SEC q_o ;
0001-01-01 02:30:17 +02:30
REG_R_SET_KEY_SEC r_o ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( hnd = = NULL )
return False ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
prs_init ( & buf , MAX_PDU_FRAG_LEN , cli - > mem_ctx , MARSHALL ) ;
prs_init ( & rbuf , 0 , cli - > mem_ctx , UNMARSHALL ) ;
0001-01-01 02:30:17 +02:30
/* create and send a MSRPC command with api REG_SET_KEY_SEC */
DEBUG ( 4 , ( " REG Set Key security. \n " ) ) ;
0001-01-01 02:30:17 +02:30
init_reg_q_set_key_sec ( & q_o , hnd , sec_desc_buf ) ;
0001-01-01 02:30:17 +02:30
/* turn parameters into data stream */
0001-01-01 02:30:17 +02:30
if ( ! reg_io_q_set_key_sec ( " " , & q_o , & buf , 0 ) ) {
prs_mem_free ( & buf ) ;
prs_mem_free ( & rbuf ) ;
return False ;
}
0001-01-01 02:30:17 +02:30
/* send the data on \PIPE\ */
0001-01-01 02:30:17 +02:30
if ( ! rpc_api_pipe_req ( cli , REG_SET_KEY_SEC , & buf , & rbuf ) ) {
prs_mem_free ( & buf ) ;
prs_mem_free ( & rbuf ) ;
return False ;
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
prs_mem_free ( & buf ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
ZERO_STRUCT ( r_o ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( ! reg_io_r_set_key_sec ( " " , & r_o , & rbuf , 0 ) ) {
prs_mem_free ( & rbuf ) ;
return False ;
}
if ( r_o . status ! = 0 ) {
prs_mem_free ( & rbuf ) ;
return False ;
0001-01-01 02:30:17 +02:30
}
prs_mem_free ( & rbuf ) ;
0001-01-01 02:30:17 +02:30
return True ;
0001-01-01 02:30:17 +02:30
}
0001-01-01 02:30:17 +02:30
/****************************************************************************
do a REG Query Key Security
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
0001-01-01 02:30:17 +02:30
BOOL do_reg_get_key_sec ( struct cli_state * cli , POLICY_HND * hnd , uint32 * sec_buf_size , SEC_DESC_BUF * * ppsec_desc_buf )
0001-01-01 02:30:17 +02:30
{
prs_struct rbuf ;
prs_struct buf ;
REG_Q_GET_KEY_SEC q_o ;
0001-01-01 02:30:17 +02:30
REG_R_GET_KEY_SEC r_o ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( hnd = = NULL )
return False ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
prs_init ( & buf , MAX_PDU_FRAG_LEN , cli - > mem_ctx , MARSHALL ) ;
prs_init ( & rbuf , 0 , cli - > mem_ctx , UNMARSHALL ) ;
0001-01-01 02:30:17 +02:30
/* create and send a MSRPC command with api REG_GET_KEY_SEC */
DEBUG ( 4 , ( " REG query key security. buf_size: %d \n " , * sec_buf_size ) ) ;
0001-01-01 02:30:17 +02:30
init_reg_q_get_key_sec ( & q_o , hnd , * sec_buf_size , NULL ) ;
0001-01-01 02:30:17 +02:30
/* turn parameters into data stream */
0001-01-01 02:30:17 +02:30
if ( ! reg_io_q_get_key_sec ( " " , & q_o , & buf , 0 ) ) {
prs_mem_free ( & buf ) ;
prs_mem_free ( & rbuf ) ;
return False ;
}
0001-01-01 02:30:17 +02:30
/* send the data on \PIPE\ */
0001-01-01 02:30:17 +02:30
if ( ! rpc_api_pipe_req ( cli , REG_GET_KEY_SEC , & buf , & rbuf ) ) {
prs_mem_free ( & buf ) ;
prs_mem_free ( & rbuf ) ;
return False ;
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
prs_mem_free ( & buf ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
ZERO_STRUCT ( r_o ) ;
if ( ! reg_io_r_get_key_sec ( " " , & r_o , & rbuf , 0 ) ) {
prs_mem_free ( & rbuf ) ;
return False ;
}
if ( r_o . status = = 0x0000007a ) {
/*
* get the maximum buffer size : it was too small
*/
( * sec_buf_size ) = r_o . hdr_sec . buf_max_len ;
DEBUG ( 5 , ( " sec_buf_size too small. use %d \n " , * sec_buf_size ) ) ;
} else if ( r_o . status ! = 0 ) {
/* report error code */
0001-01-01 02:30:17 +02:30
DEBUG ( 0 , ( " REG_GET_KEY_SEC: %s \n " , nt_errstr ( r_o . status ) ) ) ;
0001-01-01 02:30:17 +02:30
prs_mem_free ( & rbuf ) ;
return False ;
} else {
( * sec_buf_size ) = r_o . data - > len ;
* ppsec_desc_buf = r_o . data ;
0001-01-01 02:30:17 +02:30
}
prs_mem_free ( & rbuf ) ;
0001-01-01 02:30:17 +02:30
return True ;
0001-01-01 02:30:17 +02:30
}
0001-01-01 02:30:17 +02:30
/****************************************************************************
do a REG Delete Value
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
0001-01-01 02:30:17 +02:30
BOOL do_reg_delete_val ( struct cli_state * cli , POLICY_HND * hnd , char * val_name )
0001-01-01 02:30:17 +02:30
{
prs_struct rbuf ;
prs_struct buf ;
REG_Q_DELETE_VALUE q_o ;
0001-01-01 02:30:17 +02:30
REG_R_DELETE_VALUE r_o ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( hnd = = NULL )
return False ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
prs_init ( & buf , MAX_PDU_FRAG_LEN , cli - > mem_ctx , MARSHALL ) ;
prs_init ( & rbuf , 0 , cli - > mem_ctx , UNMARSHALL ) ;
0001-01-01 02:30:17 +02:30
/* create and send a MSRPC command with api REG_DELETE_VALUE */
DEBUG ( 4 , ( " REG Delete Value: %s \n " , val_name ) ) ;
0001-01-01 02:30:17 +02:30
init_reg_q_delete_val ( & q_o , hnd , val_name ) ;
0001-01-01 02:30:17 +02:30
/* turn parameters into data stream */
0001-01-01 02:30:17 +02:30
if ( ! reg_io_q_delete_val ( " " , & q_o , & buf , 0 ) ) {
prs_mem_free ( & buf ) ;
prs_mem_free ( & rbuf ) ;
return False ;
}
0001-01-01 02:30:17 +02:30
/* send the data on \PIPE\ */
0001-01-01 02:30:17 +02:30
if ( rpc_api_pipe_req ( cli , REG_DELETE_VALUE , & buf , & rbuf ) ) {
prs_mem_free ( & buf ) ;
prs_mem_free ( & rbuf ) ;
return False ;
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
prs_mem_free ( & buf ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
ZERO_STRUCT ( r_o ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( ! reg_io_r_delete_val ( " " , & r_o , & rbuf , 0 ) ) {
prs_mem_free ( & rbuf ) ;
return False ;
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( r_o . status ! = 0 ) {
/* report error code */
0001-01-01 02:30:17 +02:30
DEBUG ( 0 , ( " REG_DELETE_VALUE: %s \n " , nt_errstr ( r_o . status ) ) ) ;
0001-01-01 02:30:17 +02:30
prs_mem_free ( & rbuf ) ;
return False ;
0001-01-01 02:30:17 +02:30
}
prs_mem_free ( & rbuf ) ;
0001-01-01 02:30:17 +02:30
return True ;
0001-01-01 02:30:17 +02:30
}
0001-01-01 02:30:17 +02:30
/****************************************************************************
do a REG Delete Key
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
0001-01-01 02:30:17 +02:30
BOOL do_reg_delete_key ( struct cli_state * cli , POLICY_HND * hnd , char * key_name )
0001-01-01 02:30:17 +02:30
{
prs_struct rbuf ;
prs_struct buf ;
REG_Q_DELETE_KEY q_o ;
0001-01-01 02:30:17 +02:30
REG_R_DELETE_KEY r_o ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( hnd = = NULL )
return False ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
prs_init ( & buf , MAX_PDU_FRAG_LEN , cli - > mem_ctx , MARSHALL ) ;
prs_init ( & rbuf , 0 , cli - > mem_ctx , UNMARSHALL ) ;
0001-01-01 02:30:17 +02:30
/* create and send a MSRPC command with api REG_DELETE_KEY */
DEBUG ( 4 , ( " REG Delete Key: %s \n " , key_name ) ) ;
0001-01-01 02:30:17 +02:30
init_reg_q_delete_key ( & q_o , hnd , key_name ) ;
0001-01-01 02:30:17 +02:30
/* turn parameters into data stream */
0001-01-01 02:30:17 +02:30
if ( ! reg_io_q_delete_key ( " " , & q_o , & buf , 0 ) ) {
prs_mem_free ( & buf ) ;
prs_mem_free ( & rbuf ) ;
return False ;
}
0001-01-01 02:30:17 +02:30
/* send the data on \PIPE\ */
0001-01-01 02:30:17 +02:30
if ( ! rpc_api_pipe_req ( cli , REG_DELETE_KEY , & buf , & rbuf ) ) {
prs_mem_free ( & buf ) ;
prs_mem_free ( & rbuf ) ;
return False ;
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
prs_mem_free ( & buf ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
ZERO_STRUCT ( r_o ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( ! reg_io_r_delete_key ( " " , & r_o , & rbuf , 0 ) ) {
prs_mem_free ( & rbuf ) ;
return False ;
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( r_o . status ! = 0 ) {
/* report error code */
0001-01-01 02:30:17 +02:30
DEBUG ( 0 , ( " REG_DELETE_KEY: %s \n " , nt_errstr ( r_o . status ) ) ) ;
0001-01-01 02:30:17 +02:30
prs_mem_free ( & rbuf ) ;
return False ;
0001-01-01 02:30:17 +02:30
}
prs_mem_free ( & rbuf ) ;
0001-01-01 02:30:17 +02:30
return True ;
0001-01-01 02:30:17 +02:30
}
0001-01-01 02:30:17 +02:30
/****************************************************************************
do a REG Create Key
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
0001-01-01 02:30:17 +02:30
BOOL do_reg_create_key ( struct cli_state * cli , POLICY_HND * hnd ,
0001-01-01 02:30:17 +02:30
char * key_name , char * key_class ,
0001-01-01 02:30:17 +02:30
SEC_ACCESS * sam_access ,
0001-01-01 02:30:17 +02:30
POLICY_HND * key )
{
prs_struct rbuf ;
prs_struct buf ;
REG_Q_CREATE_KEY q_o ;
0001-01-01 02:30:17 +02:30
REG_R_CREATE_KEY r_o ;
SEC_DESC * sec = NULL ;
SEC_DESC_BUF * sec_buf = NULL ;
size_t sec_len ;
0001-01-01 02:30:17 +02:30
ZERO_STRUCT ( q_o ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( hnd = = NULL )
return False ;
0001-01-01 02:30:17 +02:30
/* create and send a MSRPC command with api REG_CREATE_KEY */
DEBUG ( 4 , ( " REG Create Key: %s %s 0x%08x \n " , key_name , key_class ,
0001-01-01 02:30:17 +02:30
sam_access ! = NULL ? sam_access - > mask : 0 ) ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( ( sec = make_sec_desc ( cli - > mem_ctx , 1 , NULL , NULL , NULL , NULL , & sec_len ) ) = = NULL ) {
0001-01-01 02:30:17 +02:30
DEBUG ( 0 , ( " make_sec_desc : malloc fail. \n " ) ) ;
return False ;
}
DEBUG ( 10 , ( " make_sec_desc: len = %d \n " , ( int ) sec_len ) ) ;
0001-01-01 02:30:17 +02:30
if ( ( sec_buf = make_sec_desc_buf ( cli - > mem_ctx , ( int ) sec_len , sec ) ) = = NULL ) {
0001-01-01 02:30:17 +02:30
DEBUG ( 0 , ( " make_sec_desc : malloc fail (1) \n " ) ) ;
return False ;
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
prs_init ( & buf , MAX_PDU_FRAG_LEN , cli - > mem_ctx , MARSHALL ) ;
prs_init ( & rbuf , 0 , cli - > mem_ctx , UNMARSHALL ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
init_reg_q_create_key ( & q_o , hnd , key_name , key_class , sam_access , sec_buf ) ;
0001-01-01 02:30:17 +02:30
/* turn parameters into data stream */
0001-01-01 02:30:17 +02:30
if ( ! reg_io_q_create_key ( " " , & q_o , & buf , 0 ) ) {
prs_mem_free ( & buf ) ;
prs_mem_free ( & rbuf ) ;
return False ;
}
0001-01-01 02:30:17 +02:30
/* send the data on \PIPE\ */
0001-01-01 02:30:17 +02:30
if ( rpc_api_pipe_req ( cli , REG_CREATE_KEY , & buf , & rbuf ) ) {
prs_mem_free ( & buf ) ;
prs_mem_free ( & rbuf ) ;
return False ;
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
prs_mem_free ( & buf ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
ZERO_STRUCT ( r_o ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( ! reg_io_r_create_key ( " " , & r_o , & rbuf , 0 ) ) {
prs_mem_free ( & rbuf ) ;
return False ;
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( r_o . status ! = 0 ) {
/* report error code */
0001-01-01 02:30:17 +02:30
DEBUG ( 0 , ( " REG_CREATE_KEY: %s \n " , nt_errstr ( r_o . status ) ) ) ;
0001-01-01 02:30:17 +02:30
prs_mem_free ( & rbuf ) ;
return False ;
0001-01-01 02:30:17 +02:30
}
0001-01-01 02:30:17 +02:30
* key = r_o . key_pol ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
prs_mem_free ( & rbuf ) ;
0001-01-01 02:30:17 +02:30
return True ;
0001-01-01 02:30:17 +02:30
}
0001-01-01 02:30:17 +02:30
/****************************************************************************
do a REG Enum Key
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
0001-01-01 02:30:17 +02:30
BOOL do_reg_enum_key ( struct cli_state * cli , POLICY_HND * hnd ,
0001-01-01 02:30:17 +02:30
int key_index , char * key_name ,
uint32 * unk_1 , uint32 * unk_2 ,
time_t * mod_time )
{
prs_struct rbuf ;
prs_struct buf ;
REG_Q_ENUM_KEY q_o ;
0001-01-01 02:30:17 +02:30
REG_R_ENUM_KEY r_o ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( hnd = = NULL )
return False ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
prs_init ( & buf , MAX_PDU_FRAG_LEN , cli - > mem_ctx , MARSHALL ) ;
prs_init ( & rbuf , 0 , cli - > mem_ctx , UNMARSHALL ) ;
0001-01-01 02:30:17 +02:30
/* create and send a MSRPC command with api REG_ENUM_KEY */
DEBUG ( 4 , ( " REG Enum Key \n " ) ) ;
0001-01-01 02:30:17 +02:30
init_reg_q_enum_key ( & q_o , hnd , key_index ) ;
0001-01-01 02:30:17 +02:30
/* turn parameters into data stream */
0001-01-01 02:30:17 +02:30
if ( ! reg_io_q_enum_key ( " " , & q_o , & buf , 0 ) ) {
prs_mem_free ( & buf ) ;
prs_mem_free ( & rbuf ) ;
return False ;
}
0001-01-01 02:30:17 +02:30
/* send the data on \PIPE\ */
0001-01-01 02:30:17 +02:30
if ( ! rpc_api_pipe_req ( cli , REG_ENUM_KEY , & buf , & rbuf ) ) {
prs_mem_free ( & buf ) ;
prs_mem_free ( & rbuf ) ;
return False ;
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
prs_mem_free ( & buf ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
ZERO_STRUCT ( r_o ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( ! reg_io_r_enum_key ( " " , & r_o , & rbuf , 0 ) ) {
prs_mem_free ( & rbuf ) ;
return False ;
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( r_o . status ! = 0 ) {
/* report error code */
0001-01-01 02:30:17 +02:30
DEBUG ( 0 , ( " REG_ENUM_KEY: %s \n " , nt_errstr ( r_o . status ) ) ) ;
0001-01-01 02:30:17 +02:30
prs_mem_free ( & rbuf ) ;
return False ;
0001-01-01 02:30:17 +02:30
}
0001-01-01 02:30:17 +02:30
( * unk_1 ) = r_o . unknown_1 ;
( * unk_2 ) = r_o . unknown_2 ;
0001-01-01 02:30:17 +02:30
rpcstr_pull ( key_name , r_o . key_name . str . buffer , - 1 , - 1 , 0 ) ;
0001-01-01 02:30:17 +02:30
( * mod_time ) = nt_time_to_unix ( & r_o . time ) ;
0001-01-01 02:30:17 +02:30
prs_mem_free ( & rbuf ) ;
0001-01-01 02:30:17 +02:30
return True ;
0001-01-01 02:30:17 +02:30
}
/****************************************************************************
0001-01-01 02:30:17 +02:30
do a REG Create Value
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
0001-01-01 02:30:17 +02:30
BOOL do_reg_create_val ( struct cli_state * cli , POLICY_HND * hnd ,
0001-01-01 02:30:17 +02:30
char * val_name , uint32 type , BUFFER3 * data )
{
prs_struct rbuf ;
prs_struct buf ;
REG_Q_CREATE_VALUE q_o ;
0001-01-01 02:30:17 +02:30
REG_R_CREATE_VALUE r_o ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( hnd = = NULL )
return False ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
prs_init ( & buf , MAX_PDU_FRAG_LEN , cli - > mem_ctx , MARSHALL ) ;
prs_init ( & rbuf , 0 , cli - > mem_ctx , UNMARSHALL ) ;
0001-01-01 02:30:17 +02:30
/* create and send a MSRPC command with api REG_CREATE_VALUE */
DEBUG ( 4 , ( " REG Create Value: %s \n " , val_name ) ) ;
0001-01-01 02:30:17 +02:30
init_reg_q_create_val ( & q_o , hnd , val_name , type , data ) ;
0001-01-01 02:30:17 +02:30
/* turn parameters into data stream */
0001-01-01 02:30:17 +02:30
if ( ! reg_io_q_create_val ( " " , & q_o , & buf , 0 ) ) {
prs_mem_free ( & buf ) ;
prs_mem_free ( & rbuf ) ;
return False ;
}
0001-01-01 02:30:17 +02:30
/* send the data on \PIPE\ */
0001-01-01 02:30:17 +02:30
if ( ! rpc_api_pipe_req ( cli , REG_CREATE_VALUE , & buf , & rbuf ) ) {
prs_mem_free ( & buf ) ;
prs_mem_free ( & rbuf ) ;
return False ;
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
prs_mem_free ( & buf ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
ZERO_STRUCT ( r_o ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( ! reg_io_r_create_val ( " " , & r_o , & rbuf , 0 ) ) {
prs_mem_free ( & rbuf ) ;
return False ;
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( r_o . status ! = 0 ) {
/* report error code */
0001-01-01 02:30:17 +02:30
DEBUG ( 0 , ( " REG_CREATE_VALUE: %s \n " , nt_errstr ( r_o . status ) ) ) ;
0001-01-01 02:30:17 +02:30
prs_mem_free ( & rbuf ) ;
return False ;
0001-01-01 02:30:17 +02:30
}
prs_mem_free ( & rbuf ) ;
0001-01-01 02:30:17 +02:30
return True ;
0001-01-01 02:30:17 +02:30
}
/****************************************************************************
0001-01-01 02:30:17 +02:30
do a REG Enum Value
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
0001-01-01 02:30:17 +02:30
BOOL do_reg_enum_val ( struct cli_state * cli , POLICY_HND * hnd ,
0001-01-01 02:30:17 +02:30
int val_index , int max_valnamelen , int max_valbufsize ,
fstring val_name ,
uint32 * val_type , BUFFER2 * value )
{
prs_struct rbuf ;
prs_struct buf ;
REG_Q_ENUM_VALUE q_o ;
0001-01-01 02:30:17 +02:30
REG_R_ENUM_VALUE r_o ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( hnd = = NULL )
return False ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
prs_init ( & buf , MAX_PDU_FRAG_LEN , cli - > mem_ctx , MARSHALL ) ;
prs_init ( & rbuf , 0 , cli - > mem_ctx , UNMARSHALL ) ;
0001-01-01 02:30:17 +02:30
/* create and send a MSRPC command with api REG_ENUM_VALUE */
DEBUG ( 4 , ( " REG Enum Value \n " ) ) ;
0001-01-01 02:30:17 +02:30
init_reg_q_enum_val ( & q_o , hnd , val_index , max_valnamelen , max_valbufsize ) ;
0001-01-01 02:30:17 +02:30
/* turn parameters into data stream */
0001-01-01 02:30:17 +02:30
if ( ! reg_io_q_enum_val ( " " , & q_o , & buf , 0 ) ) {
prs_mem_free ( & buf ) ;
prs_mem_free ( & rbuf ) ;
return False ;
}
0001-01-01 02:30:17 +02:30
/* send the data on \PIPE\ */
0001-01-01 02:30:17 +02:30
if ( ! rpc_api_pipe_req ( cli , REG_ENUM_VALUE , & buf , & rbuf ) ) {
prs_mem_free ( & buf ) ;
prs_mem_free ( & rbuf ) ;
return False ;
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
prs_mem_free ( & buf ) ;
ZERO_STRUCT ( r_o ) ;
r_o . buf_value = value ;
if ( ! reg_io_r_enum_val ( " " , & r_o , & rbuf , 0 ) ) {
prs_mem_free ( & rbuf ) ;
return False ;
}
if ( r_o . status ! = 0 ) {
/* report error code */
0001-01-01 02:30:17 +02:30
DEBUG ( 0 , ( " REG_ENUM_VALUE: %s \n " , nt_errstr ( r_o . status ) ) ) ;
0001-01-01 02:30:17 +02:30
prs_mem_free ( & rbuf ) ;
return False ;
0001-01-01 02:30:17 +02:30
}
0001-01-01 02:30:17 +02:30
( * val_type ) = r_o . type ;
0001-01-01 02:30:17 +02:30
rpcstr_pull ( val_name , & r_o . uni_name , - 1 , - 1 , 0 ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
prs_mem_free ( & rbuf ) ;
0001-01-01 02:30:17 +02:30
return True ;
0001-01-01 02:30:17 +02:30
}
/****************************************************************************
do a REG Open Key
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
0001-01-01 02:30:17 +02:30
BOOL do_reg_open_entry ( struct cli_state * cli , POLICY_HND * hnd ,
0001-01-01 02:30:17 +02:30
char * key_name , uint32 unk_0 ,
POLICY_HND * key_hnd )
{
prs_struct rbuf ;
prs_struct buf ;
REG_Q_OPEN_ENTRY q_o ;
0001-01-01 02:30:17 +02:30
REG_R_OPEN_ENTRY r_o ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( hnd = = NULL )
return False ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
prs_init ( & buf , MAX_PDU_FRAG_LEN , cli - > mem_ctx , MARSHALL ) ;
prs_init ( & rbuf , 0 , cli - > mem_ctx , UNMARSHALL ) ;
0001-01-01 02:30:17 +02:30
/* create and send a MSRPC command with api REG_OPEN_ENTRY */
DEBUG ( 4 , ( " REG Open Entry \n " ) ) ;
0001-01-01 02:30:17 +02:30
init_reg_q_open_entry ( & q_o , hnd , key_name , unk_0 ) ;
0001-01-01 02:30:17 +02:30
/* turn parameters into data stream */
0001-01-01 02:30:17 +02:30
if ( ! reg_io_q_open_entry ( " " , & q_o , & buf , 0 ) ) {
prs_mem_free ( & buf ) ;
prs_mem_free ( & rbuf ) ;
return False ;
}
0001-01-01 02:30:17 +02:30
/* send the data on \PIPE\ */
0001-01-01 02:30:17 +02:30
if ( ! rpc_api_pipe_req ( cli , REG_OPEN_ENTRY , & buf , & rbuf ) ) {
prs_mem_free ( & buf ) ;
prs_mem_free ( & rbuf ) ;
return False ;
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
prs_mem_free ( & buf ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
ZERO_STRUCT ( r_o ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( ! reg_io_r_open_entry ( " " , & r_o , & rbuf , 0 ) ) {
prs_mem_free ( & rbuf ) ;
return False ;
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( r_o . status ! = 0 ) {
/* report error code */
0001-01-01 02:30:17 +02:30
DEBUG ( 0 , ( " REG_OPEN_ENTRY: %s \n " , nt_errstr ( r_o . status ) ) ) ;
0001-01-01 02:30:17 +02:30
prs_mem_free ( & rbuf ) ;
return False ;
0001-01-01 02:30:17 +02:30
}
0001-01-01 02:30:17 +02:30
* key_hnd = r_o . pol ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
prs_mem_free ( & rbuf ) ;
0001-01-01 02:30:17 +02:30
return True ;
0001-01-01 02:30:17 +02:30
}
/****************************************************************************
do a REG Close
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
0001-01-01 02:30:17 +02:30
BOOL do_reg_close ( struct cli_state * cli , POLICY_HND * hnd )
0001-01-01 02:30:17 +02:30
{
prs_struct rbuf ;
prs_struct buf ;
REG_Q_CLOSE q_c ;
0001-01-01 02:30:17 +02:30
REG_R_CLOSE r_c ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( hnd = = NULL )
return False ;
0001-01-01 02:30:17 +02:30
/* create and send a MSRPC command with api REG_CLOSE */
0001-01-01 02:30:17 +02:30
prs_init ( & buf , MAX_PDU_FRAG_LEN , cli - > mem_ctx , MARSHALL ) ;
prs_init ( & rbuf , 0 , cli - > mem_ctx , UNMARSHALL ) ;
0001-01-01 02:30:17 +02:30
DEBUG ( 4 , ( " REG Close \n " ) ) ;
/* store the parameters */
0001-01-01 02:30:17 +02:30
init_reg_q_close ( & q_c , hnd ) ;
0001-01-01 02:30:17 +02:30
/* turn parameters into data stream */
0001-01-01 02:30:17 +02:30
if ( ! reg_io_q_close ( " " , & q_c , & buf , 0 ) ) {
prs_mem_free ( & buf ) ;
prs_mem_free ( & rbuf ) ;
return False ;
}
0001-01-01 02:30:17 +02:30
/* send the data on \PIPE\ */
0001-01-01 02:30:17 +02:30
if ( ! rpc_api_pipe_req ( cli , REG_CLOSE , & buf , & rbuf ) ) {
prs_mem_free ( & buf ) ;
prs_mem_free ( & rbuf ) ;
return False ;
0001-01-01 02:30:17 +02:30
}
0001-01-01 02:30:17 +02:30
prs_mem_free ( & buf ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
ZERO_STRUCT ( r_c ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( ! reg_io_r_close ( " " , & r_c , & rbuf , 0 ) ) {
prs_mem_free ( & rbuf ) ;
0001-01-01 02:30:17 +02:30
return False ;
}
0001-01-01 02:30:17 +02:30
if ( r_c . status ! = 0 ) {
/* report error code */
0001-01-01 02:30:17 +02:30
DEBUG ( 0 , ( " REG_CLOSE: %s \n " , nt_errstr ( r_c . status ) ) ) ;
0001-01-01 02:30:17 +02:30
prs_mem_free ( & rbuf ) ;
return False ;
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
/* check that the returned policy handle is all zeros */
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( IVAL ( & r_c . pol . data1 , 0 ) | | IVAL ( & r_c . pol . data2 , 0 ) | | SVAL ( & r_c . pol . data3 , 0 ) | |
SVAL ( & r_c . pol . data4 , 0 ) | | IVAL ( r_c . pol . data5 , 0 ) | | IVAL ( r_c . pol . data5 , 4 ) ) {
0001-01-01 02:30:17 +02:30
prs_mem_free ( & rbuf ) ;
DEBUG ( 0 , ( " REG_CLOSE: non-zero handle returned \n " ) ) ;
return False ;
}
0001-01-01 02:30:17 +02:30
prs_mem_free ( & rbuf ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
return True ;
0001-01-01 02:30:17 +02:30
}