2006-03-14 15:02:05 +00:00
/*
Unix SMB / CIFS implementation .
SMB torture tester
Copyright ( C ) Andrew Tridgell 1997 - 2003
Copyright ( C ) Jelmer Vernooij 2006
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-10 02:07:03 +00:00
the Free Software Foundation ; either version 3 of the License , or
2006-03-14 15:02:05 +00: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 02:07:03 +00:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2006-03-14 15:02:05 +00:00
*/
# include "includes.h"
# include "auth/credentials/credentials.h"
# include "lib/cmdline/popt_common.h"
2006-03-18 15:42:57 +00:00
# include "librpc/rpc/dcerpc.h"
2006-03-14 15:02:05 +00:00
# include "torture/rpc/rpc.h"
# include "torture/torture.h"
2007-08-21 19:35:43 +00:00
# include "librpc/ndr/ndr_table.h"
2006-10-16 13:06:41 +00:00
# include "lib/util/dlinklist.h"
2006-03-14 15:02:05 +00:00
2007-08-31 16:43:05 +00:00
static bool torture_rpc_teardown ( struct torture_context * tcase ,
void * data )
{
struct torture_rpc_tcase_data * tcase_data =
( struct torture_rpc_tcase_data * ) data ;
if ( tcase_data - > join_ctx ! = NULL )
torture_leave_domain ( tcase_data - > join_ctx ) ;
talloc_free ( tcase_data ) ;
return true ;
}
/**
* Obtain the DCE / RPC binding context associated with a torture context .
*
* @ param tctx Torture context
* @ param binding Pointer to store DCE / RPC binding
*/
2007-08-28 19:03:08 +00:00
NTSTATUS torture_rpc_binding ( struct torture_context * tctx ,
2007-08-31 16:43:05 +00:00
struct dcerpc_binding * * binding )
2007-08-28 19:03:08 +00:00
{
NTSTATUS status ;
2007-08-31 16:43:05 +00:00
const char * binding_string = torture_setting_string ( tctx , " binding " ,
NULL ) ;
2007-08-28 19:03:08 +00:00
if ( binding_string = = NULL ) {
2007-08-31 16:43:05 +00:00
torture_comment ( tctx ,
" You must specify a DCE/RPC binding string \n " ) ;
2007-08-28 19:03:08 +00:00
return NT_STATUS_INVALID_PARAMETER ;
}
status = dcerpc_parse_binding ( tctx , binding_string , binding ) ;
if ( NT_STATUS_IS_ERR ( status ) ) {
2007-08-31 16:43:05 +00:00
DEBUG ( 0 , ( " Failed to parse dcerpc binding '%s' \n " ,
binding_string ) ) ;
2007-08-28 19:03:08 +00:00
return status ;
}
return NT_STATUS_OK ;
}
2007-08-31 16:43:05 +00:00
/**
* open a rpc connection to the chosen binding string
*/
2007-08-28 12:54:27 +00:00
_PUBLIC_ NTSTATUS torture_rpc_connection ( struct torture_context * tctx ,
2006-03-14 15:02:05 +00:00
struct dcerpc_pipe * * p ,
2007-08-19 20:46:45 +00:00
const struct ndr_interface_table * table )
2006-03-14 15:02:05 +00:00
{
2007-08-28 12:54:27 +00:00
NTSTATUS status ;
2007-08-28 19:03:08 +00:00
struct dcerpc_binding * binding ;
2006-03-14 15:02:05 +00:00
2007-08-28 19:03:08 +00:00
status = torture_rpc_binding ( tctx , & binding ) ;
if ( NT_STATUS_IS_ERR ( status ) )
return status ;
2006-03-14 15:02:05 +00:00
2007-08-28 19:03:08 +00:00
status = dcerpc_pipe_connect_b ( tctx ,
2006-03-14 15:02:05 +00:00
p , binding , table ,
cmdline_credentials , NULL ) ;
2007-08-28 19:03:08 +00:00
if ( NT_STATUS_IS_ERR ( status ) ) {
printf ( " Failed to connect to remote server: %s %s \n " ,
dcerpc_binding_string ( tctx , binding ) , nt_errstr ( status ) ) ;
2006-03-22 10:18:31 +00:00
}
2006-04-02 12:02:01 +00:00
return status ;
2006-03-14 15:02:05 +00:00
}
2007-08-31 16:43:05 +00:00
/**
* open a rpc connection to a specific transport
*/
2007-08-28 12:54:27 +00:00
NTSTATUS torture_rpc_connection_transport ( struct torture_context * tctx ,
2006-03-14 15:02:05 +00:00
struct dcerpc_pipe * * p ,
2007-08-19 20:46:45 +00:00
const struct ndr_interface_table * table ,
2007-02-28 15:57:52 +00:00
enum dcerpc_transport_t transport ,
uint32_t assoc_group_id )
2006-03-14 15:02:05 +00:00
{
2007-08-31 16:43:05 +00:00
NTSTATUS status ;
2007-08-28 19:03:08 +00:00
struct dcerpc_binding * binding ;
2006-03-14 15:02:05 +00:00
2007-08-28 19:03:08 +00:00
status = torture_rpc_binding ( tctx , & binding ) ;
if ( NT_STATUS_IS_ERR ( status ) )
2006-03-14 15:02:05 +00:00
return status ;
2007-08-28 19:03:08 +00:00
binding - > transport = transport ;
binding - > assoc_group_id = assoc_group_id ;
2006-03-14 15:02:05 +00:00
2007-08-31 22:34:52 +00:00
status = dcerpc_pipe_connect_b ( tctx , p , binding , table ,
2006-03-14 15:02:05 +00:00
cmdline_credentials , NULL ) ;
2007-08-31 22:34:52 +00:00
if ( NT_STATUS_IS_ERR ( status ) ) {
2006-03-14 15:02:05 +00:00
* p = NULL ;
}
2007-08-31 22:34:52 +00:00
2006-03-14 15:02:05 +00:00
return status ;
}
2007-08-31 16:43:05 +00:00
static bool torture_rpc_setup_machine ( struct torture_context * tctx ,
void * * data )
{
NTSTATUS status ;
struct dcerpc_binding * binding ;
struct torture_rpc_tcase * tcase = talloc_get_type ( tctx - > active_tcase ,
struct torture_rpc_tcase ) ;
struct torture_rpc_tcase_data * tcase_data ;
status = torture_rpc_binding ( tctx , & binding ) ;
if ( NT_STATUS_IS_ERR ( status ) )
return false ;
* data = tcase_data = talloc_zero ( tctx , struct torture_rpc_tcase_data ) ;
tcase_data - > credentials = cmdline_credentials ;
tcase_data - > join_ctx = torture_join_domain ( tcase - > machine_name ,
ACB_SVRTRUST ,
& tcase_data - > credentials ) ;
if ( tcase_data - > join_ctx = = NULL )
torture_fail ( tctx , " Failed to join as BDC " ) ;
status = dcerpc_pipe_connect_b ( tctx ,
& ( tcase_data - > pipe ) ,
binding ,
tcase - > table ,
tcase_data - > credentials , NULL ) ;
torture_assert_ntstatus_ok ( tctx , status , " Error connecting to server " ) ;
return true ;
}
_PUBLIC_ struct torture_rpc_tcase * torture_suite_add_machine_rpc_iface_tcase (
struct torture_suite * suite ,
const char * name ,
const struct ndr_interface_table * table ,
const char * machine_name )
{
struct torture_rpc_tcase * tcase = talloc ( suite ,
struct torture_rpc_tcase ) ;
2007-08-31 22:34:52 +00:00
torture_suite_init_rpc_tcase ( suite , tcase , name , table ) ;
2007-08-31 16:43:05 +00:00
tcase - > machine_name = talloc_strdup ( tcase , machine_name ) ;
tcase - > tcase . setup = torture_rpc_setup_machine ;
tcase - > tcase . teardown = torture_rpc_teardown ;
return tcase ;
}
2007-08-31 22:34:52 +00:00
_PUBLIC_ bool torture_suite_init_rpc_tcase ( struct torture_suite * suite ,
struct torture_rpc_tcase * tcase ,
const char * name ,
const struct ndr_interface_table * table )
{
if ( ! torture_suite_init_tcase ( suite , ( struct torture_tcase * ) tcase , name ) )
return false ;
tcase - > table = table ;
return true ;
}
2007-08-28 13:49:34 +00:00
static bool torture_rpc_setup_anonymous ( struct torture_context * tctx ,
2007-08-31 16:43:05 +00:00
void * * data )
2007-08-28 13:49:34 +00:00
{
NTSTATUS status ;
2007-08-28 19:03:08 +00:00
struct dcerpc_binding * binding ;
2007-08-31 16:43:05 +00:00
struct torture_rpc_tcase_data * tcase_data ;
struct torture_rpc_tcase * tcase = talloc_get_type ( tctx - > active_tcase ,
struct torture_rpc_tcase ) ;
2007-08-28 13:49:34 +00:00
2007-08-28 19:03:08 +00:00
status = torture_rpc_binding ( tctx , & binding ) ;
if ( NT_STATUS_IS_ERR ( status ) )
return false ;
2007-08-31 16:43:05 +00:00
* data = tcase_data = talloc_zero ( tctx , struct torture_rpc_tcase_data ) ;
tcase_data - > credentials = cli_credentials_init_anon ( tctx ) ;
2007-08-28 13:49:34 +00:00
2007-08-28 19:03:08 +00:00
status = dcerpc_pipe_connect_b ( tctx ,
2007-08-31 16:43:05 +00:00
& ( tcase_data - > pipe ) ,
2007-08-28 13:49:34 +00:00
binding ,
2007-08-28 14:42:37 +00:00
tcase - > table ,
2007-08-31 16:43:05 +00:00
tcase_data - > credentials , NULL ) ;
2007-08-28 13:49:34 +00:00
torture_assert_ntstatus_ok ( tctx , status , " Error connecting to server " ) ;
return true ;
}
2006-10-16 13:06:41 +00:00
static bool torture_rpc_setup ( struct torture_context * tctx , void * * data )
{
NTSTATUS status ;
2007-08-28 14:42:37 +00:00
struct torture_rpc_tcase * tcase = talloc_get_type (
tctx - > active_tcase , struct torture_rpc_tcase ) ;
2007-08-31 16:43:05 +00:00
struct torture_rpc_tcase_data * tcase_data ;
* data = tcase_data = talloc_zero ( tctx , struct torture_rpc_tcase_data ) ;
tcase_data - > credentials = cmdline_credentials ;
2006-10-16 13:06:41 +00:00
status = torture_rpc_connection ( tctx ,
2007-08-31 16:43:05 +00:00
& ( tcase_data - > pipe ) ,
2007-08-31 22:34:52 +00:00
tcase - > table ) ;
2006-10-16 13:06:41 +00:00
torture_assert_ntstatus_ok ( tctx , status , " Error connecting to server " ) ;
return true ;
}
2007-08-31 16:43:05 +00:00
2006-10-16 13:06:41 +00:00
2007-08-28 14:42:37 +00:00
_PUBLIC_ struct torture_rpc_tcase * torture_suite_add_anon_rpc_iface_tcase ( struct torture_suite * suite ,
2007-08-28 13:49:34 +00:00
const char * name ,
const struct ndr_interface_table * table )
{
2007-08-28 14:42:37 +00:00
struct torture_rpc_tcase * tcase = talloc ( suite , struct torture_rpc_tcase ) ;
2007-08-31 22:34:52 +00:00
torture_suite_init_rpc_tcase ( suite , tcase , name , table ) ;
2007-08-28 13:49:34 +00:00
2007-08-28 14:42:37 +00:00
tcase - > tcase . setup = torture_rpc_setup_anonymous ;
tcase - > tcase . teardown = torture_rpc_teardown ;
2007-08-28 13:49:34 +00:00
return tcase ;
}
2007-08-28 14:42:37 +00:00
_PUBLIC_ struct torture_rpc_tcase * torture_suite_add_rpc_iface_tcase ( struct torture_suite * suite ,
2006-11-04 04:48:46 +00:00
const char * name ,
2007-08-19 20:46:45 +00:00
const struct ndr_interface_table * table )
2006-10-16 13:06:41 +00:00
{
2007-08-28 14:42:37 +00:00
struct torture_rpc_tcase * tcase = talloc ( suite , struct torture_rpc_tcase ) ;
2007-08-31 22:34:52 +00:00
torture_suite_init_rpc_tcase ( suite , tcase , name , table ) ;
2006-10-16 13:06:41 +00:00
2007-08-28 14:42:37 +00:00
tcase - > tcase . setup = torture_rpc_setup ;
tcase - > tcase . teardown = torture_rpc_teardown ;
2006-10-16 13:06:41 +00:00
return tcase ;
}
static bool torture_rpc_wrap_test ( struct torture_context * tctx ,
struct torture_tcase * tcase ,
struct torture_test * test )
{
bool ( * fn ) ( struct torture_context * , struct dcerpc_pipe * ) ;
2007-08-31 16:43:05 +00:00
struct torture_rpc_tcase_data * tcase_data =
( struct torture_rpc_tcase_data * ) tcase - > data ;
2006-10-16 13:06:41 +00:00
fn = test - > fn ;
2007-08-31 16:43:05 +00:00
return fn ( tctx , tcase_data - > pipe ) ;
2006-10-16 13:06:41 +00:00
}
2007-08-26 15:16:40 +00:00
static bool torture_rpc_wrap_test_ex ( struct torture_context * tctx ,
struct torture_tcase * tcase ,
struct torture_test * test )
{
bool ( * fn ) ( struct torture_context * , struct dcerpc_pipe * , const void * ) ;
2007-08-31 16:43:05 +00:00
struct torture_rpc_tcase_data * tcase_data =
( struct torture_rpc_tcase_data * ) tcase - > data ;
2007-08-26 15:16:40 +00:00
fn = test - > fn ;
2007-08-31 16:43:05 +00:00
return fn ( tctx , tcase_data - > pipe , test - > data ) ;
}
static bool torture_rpc_wrap_test_creds ( struct torture_context * tctx ,
struct torture_tcase * tcase ,
struct torture_test * test )
{
bool ( * fn ) ( struct torture_context * , struct dcerpc_pipe * , struct cli_credentials * ) ;
struct torture_rpc_tcase_data * tcase_data =
( struct torture_rpc_tcase_data * ) tcase - > data ;
fn = test - > fn ;
return fn ( tctx , tcase_data - > pipe , tcase_data - > credentials ) ;
2007-08-26 15:16:40 +00:00
}
2006-10-16 13:06:41 +00:00
_PUBLIC_ struct torture_test * torture_rpc_tcase_add_test (
2007-08-28 14:42:37 +00:00
struct torture_rpc_tcase * tcase ,
2006-10-16 13:06:41 +00:00
const char * name ,
bool ( * fn ) ( struct torture_context * , struct dcerpc_pipe * ) )
{
struct torture_test * test ;
test = talloc ( tcase , struct torture_test ) ;
test - > name = talloc_strdup ( test , name ) ;
test - > description = NULL ;
test - > run = torture_rpc_wrap_test ;
test - > dangerous = false ;
test - > data = NULL ;
test - > fn = fn ;
2007-08-28 14:42:37 +00:00
DLIST_ADD ( tcase - > tcase . tests , test ) ;
2006-10-16 13:06:41 +00:00
return test ;
}
2007-08-31 16:43:05 +00:00
_PUBLIC_ struct torture_test * torture_rpc_tcase_add_test_creds (
struct torture_rpc_tcase * tcase ,
const char * name ,
bool ( * fn ) ( struct torture_context * , struct dcerpc_pipe * , struct cli_credentials * ) )
{
struct torture_test * test ;
test = talloc ( tcase , struct torture_test ) ;
test - > name = talloc_strdup ( test , name ) ;
test - > description = NULL ;
test - > run = torture_rpc_wrap_test_creds ;
test - > dangerous = false ;
test - > data = NULL ;
test - > fn = fn ;
DLIST_ADD ( tcase - > tcase . tests , test ) ;
return test ;
}
2007-08-26 15:16:40 +00:00
_PUBLIC_ struct torture_test * torture_rpc_tcase_add_test_ex (
2007-08-28 14:42:37 +00:00
struct torture_rpc_tcase * tcase ,
2007-08-26 15:16:40 +00:00
const char * name ,
bool ( * fn ) ( struct torture_context * , struct dcerpc_pipe * ,
void * ) ,
void * userdata )
{
struct torture_test * test ;
test = talloc ( tcase , struct torture_test ) ;
test - > name = talloc_strdup ( test , name ) ;
test - > description = NULL ;
test - > run = torture_rpc_wrap_test_ex ;
test - > dangerous = false ;
test - > data = userdata ;
test - > fn = fn ;
2007-08-28 14:42:37 +00:00
DLIST_ADD ( tcase - > tcase . tests , test ) ;
2007-08-26 15:16:40 +00:00
return test ;
}
2006-03-14 15:02:05 +00:00
NTSTATUS torture_rpc_init ( void )
{
2006-12-12 23:48:28 +00:00
struct torture_suite * suite = torture_suite_create ( talloc_autofree_context ( ) , " RPC " ) ;
2006-03-17 00:45:52 +00:00
dcerpc_init ( ) ;
2007-08-19 21:23:03 +00:00
ndr_table_init ( ) ;
2006-03-17 00:45:52 +00:00
2006-10-16 13:06:41 +00:00
torture_suite_add_simple_test ( suite , " LSA " , torture_rpc_lsa ) ;
torture_suite_add_simple_test ( suite , " LSALOOKUP " , torture_rpc_lsa_lookup ) ;
torture_suite_add_simple_test ( suite , " LSA-GETUSER " , torture_rpc_lsa_get_user ) ;
2007-09-02 12:26:06 +00:00
torture_suite_add_suite ( suite , torture_rpc_lsa_secrets ( suite ) ) ;
2007-08-31 22:34:52 +00:00
torture_suite_add_suite ( suite , torture_rpc_echo ( suite ) ) ;
2007-08-28 16:24:18 +00:00
torture_suite_add_simple_test ( suite , " DFS " , torture_rpc_dfs ) ;
2007-08-31 22:34:52 +00:00
torture_suite_add_suite ( suite , torture_rpc_unixinfo ( suite ) ) ;
torture_suite_add_suite ( suite , torture_rpc_eventlog ( suite ) ) ;
torture_suite_add_suite ( suite , torture_rpc_atsvc ( suite ) ) ;
2007-08-28 19:03:08 +00:00
torture_suite_add_suite ( suite , torture_rpc_wkssvc ( suite ) ) ;
2007-08-26 15:16:40 +00:00
torture_suite_add_suite ( suite , torture_rpc_handles ( suite ) ) ;
torture_suite_add_suite ( suite , torture_rpc_winreg ( suite ) ) ;
2006-10-16 13:06:41 +00:00
torture_suite_add_simple_test ( suite , " SPOOLSS " , torture_rpc_spoolss ) ;
torture_suite_add_simple_test ( suite , " SAMR " , torture_rpc_samr ) ;
torture_suite_add_simple_test ( suite , " SAMR-USERS " , torture_rpc_samr_users ) ;
torture_suite_add_simple_test ( suite , " SAMR-PASSWORDS " , torture_rpc_samr_passwords ) ;
2007-08-31 17:38:37 +00:00
torture_suite_add_suite ( suite , torture_rpc_netlogon ( suite ) ) ;
2006-10-16 13:06:41 +00:00
torture_suite_add_simple_test ( suite , " SAMLOGON " , torture_rpc_samlogon ) ;
torture_suite_add_simple_test ( suite , " SAMSYNC " , torture_rpc_samsync ) ;
torture_suite_add_simple_test ( suite , " SCHANNEL " , torture_rpc_schannel ) ;
2007-05-23 07:44:51 +00:00
torture_suite_add_simple_test ( suite , " SCHANNEL2 " , torture_rpc_schannel2 ) ;
2007-08-28 13:49:34 +00:00
torture_suite_add_suite ( suite , torture_rpc_srvsvc ( suite ) ) ;
2007-08-28 12:54:27 +00:00
torture_suite_add_suite ( suite , torture_rpc_svcctl ( suite ) ) ;
2007-08-28 16:24:18 +00:00
torture_suite_add_suite ( suite , torture_rpc_epmapper ( suite ) ) ;
torture_suite_add_suite ( suite , torture_rpc_initshutdown ( suite ) ) ;
torture_suite_add_suite ( suite , torture_rpc_oxidresolve ( suite ) ) ;
torture_suite_add_suite ( suite , torture_rpc_remact ( suite ) ) ;
2006-10-16 13:06:41 +00:00
torture_suite_add_simple_test ( suite , " MGMT " , torture_rpc_mgmt ) ;
torture_suite_add_simple_test ( suite , " SCANNER " , torture_rpc_scanner ) ;
torture_suite_add_simple_test ( suite , " AUTOIDL " , torture_rpc_autoidl ) ;
torture_suite_add_simple_test ( suite , " COUNTCALLS " , torture_rpc_countcalls ) ;
torture_suite_add_simple_test ( suite , " MULTIBIND " , torture_multi_bind ) ;
torture_suite_add_simple_test ( suite , " AUTHCONTEXT " , torture_bind_authcontext ) ;
torture_suite_add_simple_test ( suite , " BINDSAMBA3 " , torture_bind_samba3 ) ;
torture_suite_add_simple_test ( suite , " NETLOGSAMBA3 " , torture_netlogon_samba3 ) ;
torture_suite_add_simple_test ( suite , " SAMBA3SESSIONKEY " , torture_samba3_sessionkey ) ;
torture_suite_add_simple_test ( suite , " SAMBA3-SRVSVC " , torture_samba3_rpc_srvsvc ) ;
torture_suite_add_simple_test ( suite , " SAMBA3-SHARESEC " ,
2006-07-17 08:05:02 +00:00
torture_samba3_rpc_sharesec ) ;
2006-10-16 13:06:41 +00:00
torture_suite_add_simple_test ( suite , " SAMBA3-GETUSERNAME " ,
2006-07-15 17:55:01 +00:00
torture_samba3_rpc_getusername ) ;
2006-10-16 13:06:41 +00:00
torture_suite_add_simple_test ( suite , " SAMBA3-LSA " , torture_samba3_rpc_lsa ) ;
torture_suite_add_simple_test ( suite , " SAMBA3-SPOOLSS " , torture_samba3_rpc_spoolss ) ;
torture_suite_add_simple_test ( suite , " SAMBA3-WKSSVC " , torture_samba3_rpc_wkssvc ) ;
2007-08-31 13:30:47 +00:00
torture_suite_add_simple_test ( suite , " SAMBA3-WINREG " , torture_samba3_rpc_winreg ) ;
2007-08-31 22:34:52 +00:00
torture_suite_add_suite ( suite , torture_rpc_drsuapi ( suite ) ) ;
torture_suite_add_suite ( suite , torture_rpc_drsuapi_cracknames ( suite ) ) ;
2007-09-02 03:14:32 +00:00
torture_suite_add_suite ( suite , torture_rpc_dssetup ( suite ) ) ;
2006-10-16 13:06:41 +00:00
torture_suite_add_simple_test ( suite , " ALTERCONTEXT " , torture_rpc_alter_context ) ;
torture_suite_add_simple_test ( suite , " JOIN " , torture_rpc_join ) ;
torture_suite_add_simple_test ( suite , " DSSYNC " , torture_rpc_dssync ) ;
torture_suite_add_simple_test ( suite , " BENCH-RPC " , torture_bench_rpc ) ;
torture_suite_add_simple_test ( suite , " ASYNCBIND " , torture_async_bind ) ;
2006-12-12 23:48:28 +00:00
suite - > description = talloc_strdup ( suite , " DCE/RPC protocol and interface tests " ) ;
2006-10-16 13:06:41 +00:00
torture_register_suite ( suite ) ;
2006-03-14 15:02:05 +00:00
return NT_STATUS_OK ;
}