2003-04-11 08:09:14 +04:00
/*
Unix SMB / CIFS implementation .
RPC pipe client
Copyright ( C ) Tim Potter 2003
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
2007-07-09 23:25:36 +04:00
the Free Software Foundation ; either version 3 of the License , or
2003-04-11 08:09:14 +04:00
( 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
2007-07-10 04:52:41 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2003-04-11 08:09:14 +04:00
*/
# include "includes.h"
# include "rpcclient.h"
2011-01-15 11:14:56 +03:00
# include "../librpc/gen_ndr/ndr_echo_c.h"
2003-04-11 08:09:14 +04:00
2005-09-30 21:13:37 +04:00
static NTSTATUS cmd_echo_add_one ( struct rpc_pipe_client * cli , TALLOC_CTX * mem_ctx ,
2003-04-11 08:09:14 +04:00
int argc , const char * * argv )
{
2011-01-15 11:14:56 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2015-05-09 17:33:08 +03:00
uint32_t request = 1 , response ;
2011-01-15 11:14:56 +03:00
NTSTATUS status ;
2003-04-11 08:09:14 +04:00
if ( argc > 2 ) {
printf ( " Usage: %s [num] \n " , argv [ 0 ] ) ;
return NT_STATUS_OK ;
}
2011-01-15 11:14:56 +03:00
if ( argc = = 2 ) {
2003-04-11 08:09:14 +04:00
request = atoi ( argv [ 1 ] ) ;
2011-01-15 11:14:56 +03:00
}
2003-04-11 08:09:14 +04:00
2011-01-15 11:14:56 +03:00
status = dcerpc_echo_AddOne ( b , mem_ctx , request , & response ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2003-04-11 08:09:14 +04:00
goto done ;
2011-01-15 11:14:56 +03:00
}
2003-04-11 08:09:14 +04:00
printf ( " %d + 1 = %d \n " , request , response ) ;
done :
2011-01-15 11:14:56 +03:00
return status ;
2003-04-11 08:09:14 +04:00
}
2005-09-30 21:13:37 +04:00
static NTSTATUS cmd_echo_data ( struct rpc_pipe_client * cli , TALLOC_CTX * mem_ctx ,
2003-04-11 08:09:14 +04:00
int argc , const char * * argv )
{
2011-01-15 11:14:56 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2015-05-09 17:33:08 +03:00
uint32_t size , i ;
2011-01-15 11:14:56 +03:00
NTSTATUS status ;
2007-05-31 01:46:03 +04:00
uint8_t * in_data = NULL , * out_data = NULL ;
2003-04-11 08:09:14 +04:00
if ( argc ! = 2 ) {
printf ( " Usage: %s num \n " , argv [ 0 ] ) ;
return NT_STATUS_OK ;
}
size = atoi ( argv [ 1 ] ) ;
2007-05-31 01:46:03 +04:00
if ( ( in_data = ( uint8_t * ) SMB_MALLOC ( size ) ) = = NULL ) {
printf ( " Failure to allocate buff of %d bytes \n " ,
size ) ;
2011-01-15 11:14:56 +03:00
status = NT_STATUS_NO_MEMORY ;
2007-06-20 22:05:48 +04:00
goto done ;
2007-05-31 01:46:03 +04:00
}
if ( ( out_data = ( uint8_t * ) SMB_MALLOC ( size ) ) = = NULL ) {
printf ( " Failure to allocate buff of %d bytes \n " ,
size ) ;
2011-01-15 11:14:56 +03:00
status = NT_STATUS_NO_MEMORY ;
2007-06-20 22:05:48 +04:00
goto done ;
2007-05-31 01:46:03 +04:00
}
2003-04-11 08:09:14 +04:00
2011-01-15 11:14:56 +03:00
for ( i = 0 ; i < size ; i + + ) {
2003-04-11 08:09:14 +04:00
in_data [ i ] = i & 0xff ;
2011-01-15 11:14:56 +03:00
}
2003-04-11 08:09:14 +04:00
2011-01-15 11:14:56 +03:00
status = dcerpc_echo_EchoData ( b , mem_ctx , size , in_data , out_data ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2003-04-11 08:09:14 +04:00
goto done ;
2011-01-15 11:14:56 +03:00
}
2003-04-11 08:09:14 +04:00
for ( i = 0 ; i < size ; i + + ) {
if ( in_data [ i ] ! = out_data [ i ] ) {
printf ( " mismatch at offset %d, %d != %d \n " ,
i , in_data [ i ] , out_data [ i ] ) ;
2011-01-15 11:14:56 +03:00
status = NT_STATUS_UNSUCCESSFUL ;
2003-04-11 08:09:14 +04:00
}
}
done :
SAFE_FREE ( in_data ) ;
2007-05-31 01:46:03 +04:00
SAFE_FREE ( out_data ) ;
2003-04-11 08:09:14 +04:00
2011-01-15 11:14:56 +03:00
return status ;
2003-04-11 08:09:14 +04:00
}
2005-09-30 21:13:37 +04:00
static NTSTATUS cmd_echo_source_data ( struct rpc_pipe_client * cli ,
2003-04-11 08:09:14 +04:00
TALLOC_CTX * mem_ctx , int argc ,
const char * * argv )
{
2011-01-15 11:14:56 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2015-05-09 17:33:08 +03:00
uint32_t size , i ;
2011-01-15 11:14:56 +03:00
NTSTATUS status ;
2007-05-31 01:46:03 +04:00
uint8_t * out_data = NULL ;
2003-04-11 08:09:14 +04:00
if ( argc ! = 2 ) {
printf ( " Usage: %s num \n " , argv [ 0 ] ) ;
return NT_STATUS_OK ;
}
size = atoi ( argv [ 1 ] ) ;
2007-05-31 01:46:03 +04:00
if ( ( out_data = ( uint8_t * ) SMB_MALLOC ( size ) ) = = NULL ) {
printf ( " Failure to allocate buff of %d bytes \n " ,
size ) ;
2011-01-15 11:14:56 +03:00
status = NT_STATUS_NO_MEMORY ;
2007-05-31 01:46:03 +04:00
goto done ;
}
2003-04-11 08:09:14 +04:00
2011-01-15 11:14:56 +03:00
status = dcerpc_echo_SourceData ( b , mem_ctx , size , out_data ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2003-04-11 08:09:14 +04:00
goto done ;
2011-01-15 11:14:56 +03:00
}
2003-04-11 08:09:14 +04:00
for ( i = 0 ; i < size ; i + + ) {
2007-05-31 01:46:03 +04:00
if ( out_data & & out_data [ i ] ! = ( i & 0xff ) ) {
2003-04-11 08:09:14 +04:00
printf ( " mismatch at offset %d, %d != %d \n " ,
i , out_data [ i ] , i & 0xff ) ;
2011-01-15 11:14:56 +03:00
status = NT_STATUS_UNSUCCESSFUL ;
2003-04-11 08:09:14 +04:00
}
}
done :
2007-07-16 11:44:23 +04:00
SAFE_FREE ( out_data ) ;
2011-01-15 11:14:56 +03:00
return status ;
2003-04-11 08:09:14 +04:00
}
2005-09-30 21:13:37 +04:00
static NTSTATUS cmd_echo_sink_data ( struct rpc_pipe_client * cli , TALLOC_CTX * mem_ctx ,
2003-04-11 08:09:14 +04:00
int argc , const char * * argv )
{
2011-01-15 11:14:56 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2015-05-09 17:33:08 +03:00
uint32_t size , i ;
2011-01-15 11:14:56 +03:00
NTSTATUS status ;
2007-05-31 01:46:03 +04:00
uint8_t * in_data = NULL ;
2003-04-11 08:09:14 +04:00
if ( argc ! = 2 ) {
printf ( " Usage: %s num \n " , argv [ 0 ] ) ;
return NT_STATUS_OK ;
}
size = atoi ( argv [ 1 ] ) ;
2007-05-31 01:46:03 +04:00
if ( ( in_data = ( uint8_t * ) SMB_MALLOC ( size ) ) = = NULL ) {
printf ( " Failure to allocate buff of %d bytes \n " ,
size ) ;
2011-01-15 11:14:56 +03:00
status = NT_STATUS_NO_MEMORY ;
2007-05-31 01:46:03 +04:00
goto done ;
}
2003-04-11 08:09:14 +04:00
2011-01-15 11:14:56 +03:00
for ( i = 0 ; i < size ; i + + ) {
2003-04-11 08:09:14 +04:00
in_data [ i ] = i & 0xff ;
2011-01-15 11:14:56 +03:00
}
2003-04-11 08:09:14 +04:00
2011-01-15 11:14:56 +03:00
status = dcerpc_echo_SinkData ( b , mem_ctx , size , in_data ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2003-04-11 08:09:14 +04:00
goto done ;
2011-01-15 11:14:56 +03:00
}
2003-04-11 08:09:14 +04:00
done :
SAFE_FREE ( in_data ) ;
2011-01-15 11:14:56 +03:00
return status ;
2003-04-11 08:09:14 +04:00
}
/* List of commands exported by this module */
struct cmd_set echo_commands [ ] = {
2019-01-09 15:27:03 +03:00
{
. name = " ECHO " ,
} ,
{
. name = " echoaddone " ,
. returntype = RPC_RTYPE_NTSTATUS ,
. ntfn = cmd_echo_add_one ,
. wfn = NULL ,
. table = & ndr_table_rpcecho ,
. rpc_pipe = NULL ,
. description = " Add one to a number " ,
. usage = " " ,
} ,
{
. name = " echodata " ,
. returntype = RPC_RTYPE_NTSTATUS ,
. ntfn = cmd_echo_data ,
. wfn = NULL ,
. table = & ndr_table_rpcecho ,
. rpc_pipe = NULL ,
. description = " Echo data " ,
. usage = " " ,
} ,
{
. name = " sinkdata " ,
. returntype = RPC_RTYPE_NTSTATUS ,
. ntfn = cmd_echo_sink_data ,
. wfn = NULL ,
. table = & ndr_table_rpcecho ,
. rpc_pipe = NULL ,
. description = " Sink data " ,
. usage = " " ,
} ,
{
. name = " sourcedata " ,
. returntype = RPC_RTYPE_NTSTATUS ,
. ntfn = cmd_echo_source_data ,
. wfn = NULL ,
. table = & ndr_table_rpcecho ,
. rpc_pipe = NULL ,
. description = " Source data " ,
. usage = " " ,
} ,
{
. name = NULL
} ,
2003-04-11 08:09:14 +04:00
} ;