2003-11-03 10:26:30 +03:00
/*
Unix SMB / CIFS implementation .
test suite for echo rpc operations
Copyright ( C ) Andrew Tridgell 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
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"
2004-11-01 13:30:34 +03:00
# include "librpc/gen_ndr/ndr_echo.h"
2003-11-03 10:26:30 +03:00
2003-11-03 11:37:48 +03:00
/*
test the AddOne interface
*/
static BOOL test_addone ( struct dcerpc_pipe * p , TALLOC_CTX * mem_ctx )
{
int i ;
NTSTATUS status ;
printf ( " \n Testing AddOne \n " ) ;
for ( i = 0 ; i < 10 ; i + + ) {
2004-05-25 20:24:13 +04:00
uint32_t n = i ;
2003-11-09 10:24:06 +03:00
struct echo_AddOne r ;
r . in . v = & n ;
r . out . v = & n ;
status = dcerpc_echo_AddOne ( p , mem_ctx , & r ) ;
2003-11-03 11:37:48 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " AddOne(%d) failed - %s \n " , i , nt_errstr ( status ) ) ;
return False ;
}
2003-11-09 10:24:06 +03:00
printf ( " %d + 1 = %u \n " , i , n ) ;
2003-11-03 11:37:48 +03:00
}
return True ;
}
2003-11-03 12:18:38 +03:00
/*
test the EchoData interface
*/
static BOOL test_echodata ( struct dcerpc_pipe * p , TALLOC_CTX * mem_ctx )
{
int i ;
NTSTATUS status ;
2004-11-25 21:01:40 +03:00
uint8_t * data_in , * data_out ;
2003-11-04 12:10:31 +03:00
int len = 1 + ( random ( ) % 5000 ) ;
2003-11-09 10:24:06 +03:00
struct echo_EchoData r ;
2003-11-03 12:18:38 +03:00
printf ( " \n Testing EchoData \n " ) ;
2005-01-06 06:06:58 +03:00
data_in = talloc_size ( mem_ctx , len ) ;
data_out = talloc_size ( mem_ctx , len ) ;
2003-11-03 12:18:38 +03:00
for ( i = 0 ; i < len ; i + + ) {
2003-11-09 10:24:06 +03:00
data_in [ i ] = i ;
2003-11-03 12:18:38 +03:00
}
2003-11-09 10:24:06 +03:00
r . in . len = len ;
2003-11-13 12:26:53 +03:00
r . in . in_data = data_in ;
2003-11-03 12:18:38 +03:00
2003-11-09 10:24:06 +03:00
status = dcerpc_echo_EchoData ( p , mem_ctx , & r ) ;
2003-11-03 12:18:38 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2003-11-04 05:28:08 +03:00
printf ( " EchoData(%d) failed - %s \n " , len , nt_errstr ( status ) ) ;
2003-11-03 12:18:38 +03:00
return False ;
}
2003-11-13 12:26:53 +03:00
data_out = r . out . out_data ;
for ( i = 0 ; i < len ; i + + ) {
if ( data_in [ i ] ! = data_out [ i ] ) {
printf ( " Bad data returned for len %d at offset %d \n " ,
len , i ) ;
printf ( " in: \n " ) ;
2003-11-13 13:29:58 +03:00
dump_data ( 0 , data_in + i , MIN ( len - i , 16 ) ) ;
2003-11-13 12:26:53 +03:00
printf ( " out: \n " ) ;
2003-11-13 13:29:58 +03:00
dump_data ( 0 , data_out + i , MIN ( len - 1 , 16 ) ) ;
2003-11-13 12:26:53 +03:00
return False ;
}
2003-11-03 12:18:38 +03:00
}
return True ;
}
2003-11-03 13:01:20 +03:00
/*
test the SourceData interface
*/
static BOOL test_sourcedata ( struct dcerpc_pipe * p , TALLOC_CTX * mem_ctx )
{
int i ;
NTSTATUS status ;
2003-11-04 12:10:31 +03:00
int len = 200000 + ( random ( ) % 5000 ) ;
2004-11-25 21:01:40 +03:00
uint8_t * data_out ;
2003-11-09 10:24:06 +03:00
struct echo_SourceData r ;
2003-11-03 13:01:20 +03:00
printf ( " \n Testing SourceData \n " ) ;
2005-01-06 06:06:58 +03:00
data_out = talloc_size ( mem_ctx , len ) ;
2003-11-09 10:24:06 +03:00
r . in . len = len ;
r . out . data = data_out ;
status = dcerpc_echo_SourceData ( p , mem_ctx , & r ) ;
2003-11-03 13:01:20 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2003-11-04 05:28:08 +03:00
printf ( " SourceData(%d) failed - %s \n " , len , nt_errstr ( status ) ) ;
2003-11-03 13:01:20 +03:00
return False ;
}
for ( i = 0 ; i < len ; i + + ) {
2004-05-29 12:11:46 +04:00
uint8_t * v = ( uint8_t * ) data_out ;
2003-11-04 05:28:08 +03:00
if ( v [ i ] ! = ( i & 0xFF ) ) {
2004-05-29 12:11:46 +04:00
printf ( " bad data 0x%x at %d \n " , ( uint8_t ) data_out [ i ] , i ) ;
2003-11-03 13:01:20 +03:00
return False ;
}
}
return True ;
}
/*
test the SinkData interface
*/
static BOOL test_sinkdata ( struct dcerpc_pipe * p , TALLOC_CTX * mem_ctx )
{
int i ;
NTSTATUS status ;
2004-11-25 21:01:40 +03:00
uint8_t * data_in ;
2003-11-04 12:10:31 +03:00
int len = 200000 + ( random ( ) % 5000 ) ;
2003-11-09 10:24:06 +03:00
struct echo_SinkData r ;
2003-11-03 13:01:20 +03:00
printf ( " \n Testing SinkData \n " ) ;
2005-01-06 06:06:58 +03:00
data_in = talloc_size ( mem_ctx , len ) ;
2003-11-03 13:01:20 +03:00
for ( i = 0 ; i < len ; i + + ) {
data_in [ i ] = i + 1 ;
}
2003-11-09 10:24:06 +03:00
r . in . len = len ;
r . in . data = data_in ;
status = dcerpc_echo_SinkData ( p , mem_ctx , & r ) ;
2003-11-03 13:01:20 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2003-11-04 05:28:08 +03:00
printf ( " SinkData(%d) failed - %s \n " , len , nt_errstr ( status ) ) ;
2003-11-03 13:01:20 +03:00
return False ;
}
2003-11-04 12:10:31 +03:00
printf ( " sunk %d bytes \n " , len ) ;
2003-11-03 13:01:20 +03:00
return True ;
}
2003-11-13 12:26:53 +03:00
/*
test the testcall interface
*/
static BOOL test_testcall ( struct dcerpc_pipe * p , TALLOC_CTX * mem_ctx )
{
NTSTATUS status ;
2003-12-14 16:22:12 +03:00
struct echo_TestCall r ;
2003-11-17 12:34:19 +03:00
2003-11-19 15:03:11 +03:00
r . in . s1 = " input string " ;
2003-11-13 12:26:53 +03:00
printf ( " \n Testing TestCall \n " ) ;
2003-12-14 16:22:12 +03:00
status = dcerpc_echo_TestCall ( p , mem_ctx , & r ) ;
2003-11-13 12:26:53 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " TestCall failed - %s \n " , nt_errstr ( status ) ) ;
return False ;
}
return True ;
}
2003-11-19 15:03:11 +03:00
/*
test the testcall interface
*/
static BOOL test_testcall2 ( struct dcerpc_pipe * p , TALLOC_CTX * mem_ctx )
{
NTSTATUS status ;
2003-12-14 16:22:12 +03:00
struct echo_TestCall2 r ;
2003-11-19 15:03:11 +03:00
int i ;
BOOL ret = True ;
for ( i = 1 ; i < = 7 ; i + + ) {
r . in . level = i ;
printf ( " \n Testing TestCall2 level %d \n " , i ) ;
2003-12-14 16:22:12 +03:00
status = dcerpc_echo_TestCall2 ( p , mem_ctx , & r ) ;
2003-11-19 15:03:11 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " TestCall2 failed - %s \n " , nt_errstr ( status ) ) ;
ret = False ;
}
}
return ret ;
}
2004-10-28 17:40:50 +04:00
#if 0
2004-08-30 11:36:16 +04:00
/*
test the TestSleep interface
*/
static BOOL test_sleep ( struct dcerpc_pipe * p , TALLOC_CTX * mem_ctx )
{
int i ;
NTSTATUS status ;
# define ASYNC_COUNT 5
struct rpc_request * req [ ASYNC_COUNT ] ;
struct echo_TestSleep r [ ASYNC_COUNT ] ;
int done [ ASYNC_COUNT ] ;
struct event_context * ctx ;
int total_done = 0 ;
BOOL ret = True ;
printf ( " \n Testing TestSleep \n " ) ;
for ( i = 0 ; i < ASYNC_COUNT ; i + + ) {
done [ i ] = 0 ;
r [ i ] . in . seconds = ASYNC_COUNT - i ;
req [ i ] = dcerpc_echo_TestSleep_send ( p , mem_ctx , & r [ i ] ) ;
if ( ! req [ i ] ) {
printf ( " Failed to send async sleep request \n " ) ;
return False ;
}
}
ctx = dcerpc_event_context ( p ) ;
while ( total_done < ASYNC_COUNT ) {
2004-09-20 14:40:11 +04:00
if ( event_loop_once ( ctx ) ! = 0 ) {
return False ;
}
2004-08-30 11:36:16 +04:00
for ( i = 0 ; i < ASYNC_COUNT ; i + + ) {
if ( done [ i ] = = 0 & & req [ i ] - > state = = RPC_REQUEST_DONE ) {
total_done + + ;
done [ i ] = 1 ;
status = dcerpc_ndr_request_recv ( req [ i ] ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " TestSleep(%d) failed - %s \n " ,
i , nt_errstr ( status ) ) ;
ret = False ;
} else {
printf ( " Sleep for %d seconds \n " ,
r [ i ] . out . result ) ;
}
}
}
}
return ret ;
}
2004-10-28 17:40:50 +04:00
# endif
2004-08-30 11:36:16 +04:00
2005-01-05 02:27:12 +03:00
/*
test enum handling
*/
static BOOL test_enum ( struct dcerpc_pipe * p , TALLOC_CTX * mem_ctx )
{
NTSTATUS status ;
struct echo_TestEnum r ;
BOOL ret = True ;
enum echo_Enum1 v = ECHO_ENUM1 ;
struct echo_Enum2 e2 ;
union echo_Enum3 e3 ;
r . in . foo1 = & v ;
r . in . foo2 = & e2 ;
r . in . foo3 = & e3 ;
r . out . foo1 = & v ;
r . out . foo2 = & e2 ;
r . out . foo3 = & e3 ;
e2 . e1 = 76 ;
e2 . e2 = ECHO_ENUM1_32 ;
e3 . e1 = ECHO_ENUM2 ;
printf ( " \n Testing TestEnum \n " ) ;
status = dcerpc_echo_TestEnum ( p , mem_ctx , & r ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " TestEnum failed - %s \n " , nt_errstr ( status ) ) ;
ret = False ;
}
return ret ;
}
2004-10-28 17:40:50 +04:00
BOOL torture_rpc_echo ( void )
2003-11-03 10:26:30 +03:00
{
NTSTATUS status ;
struct dcerpc_pipe * p ;
TALLOC_CTX * mem_ctx ;
2003-11-03 11:37:48 +03:00
BOOL ret = True ;
2003-11-03 10:26:30 +03:00
mem_ctx = talloc_init ( " torture_rpc_echo " ) ;
2003-11-18 08:01:10 +03:00
status = torture_rpc_connection ( & p ,
DCERPC_RPCECHO_NAME ,
DCERPC_RPCECHO_UUID ,
DCERPC_RPCECHO_VERSION ) ;
2003-11-03 10:26:30 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
return False ;
}
2003-11-03 11:37:48 +03:00
if ( ! test_addone ( p , mem_ctx ) ) {
ret = False ;
2003-11-03 10:26:30 +03:00
}
2004-09-22 09:17:55 +04:00
if ( ! test_sinkdata ( p , mem_ctx ) ) {
2003-11-03 12:18:38 +03:00
ret = False ;
}
2004-09-22 09:17:55 +04:00
if ( ! test_echodata ( p , mem_ctx ) ) {
2003-11-03 13:01:20 +03:00
ret = False ;
}
2004-09-22 09:17:55 +04:00
if ( ! test_sourcedata ( p , mem_ctx ) ) {
2003-11-03 13:01:20 +03:00
ret = False ;
}
2003-11-19 15:03:11 +03:00
2003-11-13 12:26:53 +03:00
if ( ! test_testcall ( p , mem_ctx ) ) {
ret = False ;
}
2003-11-19 15:03:11 +03:00
if ( ! test_testcall2 ( p , mem_ctx ) ) {
ret = False ;
}
2005-01-05 02:27:12 +03:00
if ( ! test_enum ( p , mem_ctx ) ) {
ret = False ;
}
2004-09-22 09:17:55 +04:00
/*
2004-08-30 11:36:16 +04:00
if ( ! test_sleep ( p , mem_ctx ) ) {
ret = False ;
}
2004-09-22 09:17:55 +04:00
*/
2003-11-03 11:37:48 +03:00
printf ( " \n " ) ;
2004-09-27 12:41:39 +04:00
talloc_free ( mem_ctx ) ;
2003-11-22 11:11:32 +03:00
2003-11-03 10:26:30 +03:00
torture_rpc_close ( p ) ;
2003-11-03 11:37:48 +03:00
return ret ;
2003-11-03 10:26:30 +03:00
}