2010-10-06 20:46:43 +04:00
/*
Unix SMB / CIFS implementation .
Run the async echo responder
Copyright ( C ) Volker Lendecke 2010
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 3 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 , see < http : //www.gnu.org/licenses/>.
*/
# include "includes.h"
# include "torture/proto.h"
2011-05-06 13:47:43 +04:00
# include "libsmb/libsmb.h"
2011-02-28 12:19:44 +03:00
# include "rpc_client/cli_pipe.h"
2011-01-15 11:15:34 +03:00
# include "librpc/gen_ndr/ndr_echo_c.h"
2010-10-06 20:46:43 +04:00
static void rpccli_sleep_done ( struct tevent_req * req )
{
int * done = ( int * ) tevent_req_callback_data_void ( req ) ;
NTSTATUS status ;
2011-01-15 11:15:34 +03:00
uint32_t result = UINT32_MAX ;
2010-10-06 20:46:43 +04:00
2011-01-15 11:15:34 +03:00
status = dcerpc_echo_TestSleep_recv ( req , talloc_tos ( ) , & result ) ;
2010-10-06 20:46:43 +04:00
TALLOC_FREE ( req ) ;
printf ( " sleep returned %s, %d \n " , nt_errstr ( status ) , ( int ) result ) ;
* done - = 1 ;
}
static void cli_echo_done ( struct tevent_req * req )
{
int * done = ( int * ) tevent_req_callback_data_void ( req ) ;
NTSTATUS status ;
status = cli_echo_recv ( req ) ;
TALLOC_FREE ( req ) ;
printf ( " echo returned %s \n " , nt_errstr ( status ) ) ;
* done - = 1 ;
}
2011-07-26 23:07:08 +04:00
static void write_andx_done ( struct tevent_req * req )
2010-10-06 20:46:43 +04:00
{
int * done = ( int * ) tevent_req_callback_data_void ( req ) ;
NTSTATUS status ;
size_t written ;
status = cli_write_andx_recv ( req , & written ) ;
TALLOC_FREE ( req ) ;
2011-07-26 23:06:41 +04:00
printf ( " cli_write_andx returned %s \n " , nt_errstr ( status ) ) ;
2010-10-06 20:46:43 +04:00
* done - = 1 ;
}
bool run_async_echo ( int dummy )
{
struct cli_state * cli = NULL ;
struct rpc_pipe_client * p ;
2011-01-15 11:15:34 +03:00
struct dcerpc_binding_handle * b ;
2010-10-06 20:46:43 +04:00
struct tevent_context * ev ;
struct tevent_req * req ;
NTSTATUS status ;
bool ret = false ;
int i , num_reqs ;
2011-07-28 15:41:18 +04:00
uint8_t buf [ 65536 ] ;
2010-10-06 20:46:43 +04:00
printf ( " Starting ASYNC_ECHO \n " ) ;
ev = tevent_context_init ( talloc_tos ( ) ) ;
if ( ev = = NULL ) {
printf ( " tevent_context_init failed \n " ) ;
goto fail ;
}
if ( ! torture_open_connection ( & cli , 0 ) ) {
printf ( " torture_open_connection failed \n " ) ;
goto fail ;
}
status = cli_rpc_pipe_open_noauth ( cli , & ndr_table_rpcecho . syntax_id ,
& p ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " Could not open echo pipe: %s \n " , nt_errstr ( status ) ) ;
goto fail ;
}
2011-01-15 11:15:34 +03:00
b = p - > binding_handle ;
2010-10-06 20:46:43 +04:00
num_reqs = 0 ;
2011-01-15 11:15:34 +03:00
req = dcerpc_echo_TestSleep_send ( ev , ev , b , 15 ) ;
2010-10-06 20:46:43 +04:00
if ( req = = NULL ) {
printf ( " rpccli_echo_TestSleep_send failed \n " ) ;
goto fail ;
}
tevent_req_set_callback ( req , rpccli_sleep_done , & num_reqs ) ;
num_reqs + = 1 ;
req = cli_echo_send ( ev , ev , cli , 1 , data_blob_const ( " hello " , 5 ) ) ;
if ( req = = NULL ) {
printf ( " cli_echo_send failed \n " ) ;
goto fail ;
}
tevent_req_set_callback ( req , cli_echo_done , & num_reqs ) ;
num_reqs + = 1 ;
memset ( buf , 0 , sizeof ( buf ) ) ;
for ( i = 0 ; i < 10 ; i + + ) {
2011-07-26 22:49:32 +04:00
req = cli_write_andx_send ( ev , ev , cli , 4711 , 0 , buf , 0 ,
sizeof ( buf ) ) ;
2010-10-06 20:46:43 +04:00
if ( req = = NULL ) {
2011-07-26 22:48:59 +04:00
printf ( " cli_write_andx_send failed \n " ) ;
2010-10-06 20:46:43 +04:00
goto fail ;
}
2011-07-26 23:07:08 +04:00
tevent_req_set_callback ( req , write_andx_done , & num_reqs ) ;
2010-10-06 20:46:43 +04:00
num_reqs + = 1 ;
2011-07-26 22:49:32 +04:00
req = cli_echo_send ( ev , ev , cli , 1 ,
data_blob_const ( " hello " , 5 ) ) ;
2010-10-06 20:46:43 +04:00
if ( req = = NULL ) {
printf ( " cli_echo_send failed \n " ) ;
goto fail ;
}
tevent_req_set_callback ( req , cli_echo_done , & num_reqs ) ;
num_reqs + = 1 ;
}
while ( num_reqs > 0 ) {
if ( tevent_loop_once ( ev ) ! = 0 ) {
printf ( " tevent_loop_once failed \n " ) ;
goto fail ;
}
}
TALLOC_FREE ( p ) ;
ret = true ;
fail :
if ( cli ! = NULL ) {
torture_close_connection ( cli ) ;
}
return ret ;
}