2010-03-23 18:04:30 +03:00
/*
2005-07-02 18:38:05 +04:00
Unix SMB / CIFS implementation .
Test suite for libnet calls .
Copyright ( C ) Rafal Szczesniak 2005
2010-03-23 18:04:30 +03:00
2005-07-02 18:38:05 +04:00
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 06:07:03 +04:00
the Free Software Foundation ; either version 3 of the License , or
2005-07-02 18:38:05 +04:00
( at your option ) any later version .
2010-03-23 18:04:30 +03:00
2005-07-02 18:38:05 +04:00
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 .
2010-03-23 18:04:30 +03:00
2005-07-02 18:38:05 +04:00
You should have received a copy of the GNU General Public License
2007-07-10 06:07:03 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2005-07-02 18:38:05 +04:00
*/
# include "includes.h"
# include "lib/cmdline/popt_common.h"
# include "libnet/libnet.h"
2006-05-04 18:54:31 +04:00
# include "libcli/security/security.h"
2006-03-16 03:23:11 +03:00
# include "librpc/gen_ndr/ndr_lsa.h"
# include "librpc/gen_ndr/ndr_samr.h"
2006-05-22 01:18:35 +04:00
# include "librpc/gen_ndr/ndr_srvsvc.h"
2010-04-14 00:06:51 +04:00
# include "torture/rpc/torture_rpc.h"
2007-09-08 16:42:09 +04:00
# include "param/param.h"
2005-07-02 18:38:05 +04:00
2010-03-23 17:31:27 +03:00
static bool test_connect_service ( struct torture_context * tctx ,
struct libnet_context * ctx ,
2007-08-20 00:46:45 +04:00
const struct ndr_interface_table * iface ,
2006-05-22 01:18:35 +04:00
const char * binding_string ,
const char * hostname ,
const enum libnet_RpcConnect_level level ,
2007-10-07 02:28:14 +04:00
bool badcreds , NTSTATUS expected_status )
2005-07-02 18:38:05 +04:00
{
NTSTATUS status ;
2008-12-24 01:22:57 +03:00
struct libnet_RpcConnect connect_r ;
2009-06-18 06:33:46 +04:00
ZERO_STRUCT ( connect_r ) ;
2008-12-24 01:22:57 +03:00
connect_r . level = level ;
connect_r . in . binding = binding_string ;
connect_r . in . name = hostname ;
connect_r . in . dcerpc_iface = iface ;
2006-05-22 01:18:35 +04:00
/* if bad credentials are needed, set baduser%badpassword instead
of default commandline - passed credentials */
if ( badcreds ) {
cli_credentials_set_username ( ctx - > cred , " baduser " , CRED_SPECIFIED ) ;
cli_credentials_set_password ( ctx - > cred , " badpassword " , CRED_SPECIFIED ) ;
}
2005-07-02 18:38:05 +04:00
2008-12-24 01:22:57 +03:00
status = libnet_RpcConnect ( ctx , ctx , & connect_r ) ;
2005-07-02 18:38:05 +04:00
2006-05-22 01:18:35 +04:00
if ( ! NT_STATUS_EQUAL ( status , expected_status ) ) {
2010-03-23 17:31:27 +03:00
torture_comment ( tctx , " Connecting to rpc service %s on %s. \n \t FAILED. Expected: %s. "
2006-05-22 01:18:35 +04:00
" Received: %s \n " ,
2008-12-24 01:22:57 +03:00
connect_r . in . dcerpc_iface - > name , connect_r . in . binding , nt_errstr ( expected_status ) ,
2005-07-02 18:38:05 +04:00
nt_errstr ( status ) ) ;
2007-10-07 02:28:14 +04:00
return false ;
2005-07-02 18:38:05 +04:00
}
2010-03-23 17:31:27 +03:00
torture_comment ( tctx , " PASSED. Expected: %s, received: %s \n " , nt_errstr ( expected_status ) ,
2006-05-22 01:18:35 +04:00
nt_errstr ( status ) ) ;
2008-12-24 01:22:57 +03:00
if ( connect_r . level = = LIBNET_RPC_CONNECT_DC_INFO & & NT_STATUS_IS_OK ( status ) ) {
2010-03-23 17:31:27 +03:00
torture_comment ( tctx , " Domain Controller Info: \n " ) ;
torture_comment ( tctx , " \t Domain Name: \t %s \n " , connect_r . out . domain_name ) ;
torture_comment ( tctx , " \t Domain SID: \t %s \n " , dom_sid_string ( ctx , connect_r . out . domain_sid ) ) ;
torture_comment ( tctx , " \t Realm: \t \t %s \n " , connect_r . out . realm ) ;
torture_comment ( tctx , " \t GUID: \t \t %s \n " , GUID_string ( ctx , connect_r . out . guid ) ) ;
2006-05-22 01:18:35 +04:00
} else if ( ! NT_STATUS_IS_OK ( status ) ) {
2010-03-23 17:31:27 +03:00
torture_comment ( tctx , " Error string: %s \n " , connect_r . out . error_string ) ;
2006-05-22 01:18:35 +04:00
}
2007-10-07 02:28:14 +04:00
return true ;
2005-07-02 18:38:05 +04:00
}
2007-10-07 02:28:14 +04:00
static bool torture_rpc_connect ( struct torture_context * torture ,
2006-05-22 01:18:35 +04:00
const enum libnet_RpcConnect_level level ,
const char * bindstr , const char * hostname )
2006-05-04 18:54:31 +04:00
{
2006-05-22 01:18:35 +04:00
struct libnet_context * ctx ;
2008-04-14 20:43:37 +04:00
ctx = libnet_context_init ( torture - > ev , torture - > lp_ctx ) ;
2006-05-22 01:18:35 +04:00
ctx - > cred = cmdline_credentials ;
2010-03-23 18:04:30 +03:00
2010-03-23 17:31:27 +03:00
torture_comment ( torture , " Testing connection to LSA interface \n " ) ;
if ( ! test_connect_service ( torture , ctx , & ndr_table_lsarpc , bindstr ,
2007-10-07 02:28:14 +04:00
hostname , level , false , NT_STATUS_OK ) ) {
2010-03-23 17:31:27 +03:00
torture_comment ( torture , " failed to connect LSA interface \n " ) ;
2007-10-07 02:28:14 +04:00
return false ;
2006-05-22 01:18:35 +04:00
}
2010-03-23 17:31:27 +03:00
torture_comment ( torture , " Testing connection to SAMR interface \n " ) ;
if ( ! test_connect_service ( torture , ctx , & ndr_table_samr , bindstr ,
2007-10-07 02:28:14 +04:00
hostname , level , false , NT_STATUS_OK ) ) {
2010-03-23 17:31:27 +03:00
torture_comment ( torture , " failed to connect SAMR interface \n " ) ;
2007-10-07 02:28:14 +04:00
return false ;
2006-05-22 01:18:35 +04:00
}
2010-03-23 17:31:27 +03:00
torture_comment ( torture , " Testing connection to SRVSVC interface \n " ) ;
if ( ! test_connect_service ( torture , ctx , & ndr_table_srvsvc , bindstr ,
2007-10-07 02:28:14 +04:00
hostname , level , false , NT_STATUS_OK ) ) {
2010-03-23 17:31:27 +03:00
torture_comment ( torture , " failed to connect SRVSVC interface \n " ) ;
2007-10-07 02:28:14 +04:00
return false ;
2006-05-22 01:18:35 +04:00
}
2006-05-04 18:54:31 +04:00
2010-03-23 17:31:27 +03:00
torture_comment ( torture , " Testing connection to LSA interface with wrong credentials \n " ) ;
if ( ! test_connect_service ( torture , ctx , & ndr_table_lsarpc , bindstr ,
2007-10-07 02:28:14 +04:00
hostname , level , true , NT_STATUS_LOGON_FAILURE ) ) {
2010-03-23 17:31:27 +03:00
torture_comment ( torture , " failed to test wrong credentials on LSA interface \n " ) ;
2007-10-07 02:28:14 +04:00
return false ;
2006-05-04 18:54:31 +04:00
}
2010-03-23 17:31:27 +03:00
torture_comment ( torture , " Testing connection to SAMR interface with wrong credentials \n " ) ;
if ( ! test_connect_service ( torture , ctx , & ndr_table_samr , bindstr ,
2007-10-07 02:28:14 +04:00
hostname , level , true , NT_STATUS_LOGON_FAILURE ) ) {
2010-03-23 17:31:27 +03:00
torture_comment ( torture , " failed to test wrong credentials on SAMR interface \n " ) ;
2007-10-07 02:28:14 +04:00
return false ;
2006-05-22 01:18:35 +04:00
}
talloc_free ( ctx ) ;
2006-05-04 18:54:31 +04:00
2007-10-07 02:28:14 +04:00
return true ;
2006-05-04 18:54:31 +04:00
}
2007-10-07 02:28:14 +04:00
bool torture_rpc_connect_srv ( struct torture_context * torture )
2005-07-02 18:38:05 +04:00
{
2006-05-22 01:18:35 +04:00
const enum libnet_RpcConnect_level level = LIBNET_RPC_CONNECT_SERVER ;
2005-07-02 18:38:05 +04:00
NTSTATUS status ;
2006-05-22 01:18:35 +04:00
struct dcerpc_binding * binding ;
2005-07-02 18:38:05 +04:00
2007-08-28 23:03:08 +04:00
status = torture_rpc_binding ( torture , & binding ) ;
2005-07-02 18:38:05 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2005-07-02 18:38:05 +04:00
}
2006-05-22 01:18:35 +04:00
return torture_rpc_connect ( torture , level , NULL , binding - > host ) ;
2005-07-02 18:38:05 +04:00
}
2006-05-16 01:50:53 +04:00
2007-10-07 02:28:14 +04:00
bool torture_rpc_connect_pdc ( struct torture_context * torture )
2006-05-16 01:50:53 +04:00
{
2006-05-22 01:18:35 +04:00
const enum libnet_RpcConnect_level level = LIBNET_RPC_CONNECT_PDC ;
2006-05-16 01:50:53 +04:00
NTSTATUS status ;
2006-05-22 01:18:35 +04:00
struct dcerpc_binding * binding ;
2007-05-12 01:48:29 +04:00
const char * domain_name ;
2010-03-23 18:04:30 +03:00
2007-08-28 23:03:08 +04:00
status = torture_rpc_binding ( torture , & binding ) ;
2006-05-16 01:50:53 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-05-16 01:50:53 +04:00
}
2007-05-12 01:48:29 +04:00
/* we're accessing domain controller so the domain name should be
passed ( it ' s going to be resolved to dc name and address ) instead
of specific server name . */
2007-12-03 02:28:22 +03:00
domain_name = lp_workgroup ( torture - > lp_ctx ) ;
2007-05-12 01:48:29 +04:00
return torture_rpc_connect ( torture , level , NULL , domain_name ) ;
2006-05-16 01:50:53 +04:00
}
2007-10-07 02:28:14 +04:00
bool torture_rpc_connect_dc ( struct torture_context * torture )
2005-07-02 18:38:05 +04:00
{
2006-05-22 01:18:35 +04:00
const enum libnet_RpcConnect_level level = LIBNET_RPC_CONNECT_DC ;
NTSTATUS status ;
struct dcerpc_binding * binding ;
2007-05-12 01:48:29 +04:00
const char * domain_name ;
2010-03-23 18:04:30 +03:00
2007-08-28 23:03:08 +04:00
status = torture_rpc_binding ( torture , & binding ) ;
2006-05-22 01:18:35 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2005-07-02 18:38:05 +04:00
}
2007-05-12 01:48:29 +04:00
/* we're accessing domain controller so the domain name should be
passed ( it ' s going to be resolved to dc name and address ) instead
of specific server name . */
2007-12-03 02:28:22 +03:00
domain_name = lp_workgroup ( torture - > lp_ctx ) ;
2007-05-12 01:48:29 +04:00
return torture_rpc_connect ( torture , level , NULL , domain_name ) ;
2006-05-22 01:18:35 +04:00
}
2006-05-04 18:54:31 +04:00
2006-05-22 01:18:35 +04:00
2007-10-07 02:28:14 +04:00
bool torture_rpc_connect_dc_info ( struct torture_context * torture )
2006-05-22 01:18:35 +04:00
{
const enum libnet_RpcConnect_level level = LIBNET_RPC_CONNECT_DC_INFO ;
NTSTATUS status ;
struct dcerpc_binding * binding ;
2007-05-12 01:48:29 +04:00
const char * domain_name ;
2010-03-23 18:04:30 +03:00
2007-08-28 23:03:08 +04:00
status = torture_rpc_binding ( torture , & binding ) ;
2006-05-22 01:18:35 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2006-05-16 01:50:53 +04:00
}
2007-05-12 01:48:29 +04:00
/* we're accessing domain controller so the domain name should be
passed ( it ' s going to be resolved to dc name and address ) instead
of specific server name . */
2007-12-03 02:28:22 +03:00
domain_name = lp_workgroup ( torture - > lp_ctx ) ;
2007-05-12 01:48:29 +04:00
return torture_rpc_connect ( torture , level , NULL , domain_name ) ;
2006-05-22 01:18:35 +04:00
}
2007-10-07 02:28:14 +04:00
bool torture_rpc_connect_binding ( struct torture_context * torture )
2006-05-22 01:18:35 +04:00
{
const enum libnet_RpcConnect_level level = LIBNET_RPC_CONNECT_BINDING ;
NTSTATUS status ;
struct dcerpc_binding * binding ;
const char * bindstr ;
2010-03-23 18:04:30 +03:00
2007-08-28 23:03:08 +04:00
status = torture_rpc_binding ( torture , & binding ) ;
2006-05-22 01:18:35 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2005-07-02 18:38:05 +04:00
}
2007-08-28 23:03:08 +04:00
bindstr = dcerpc_binding_string ( torture , binding ) ;
2006-05-22 01:18:35 +04:00
return torture_rpc_connect ( torture , level , bindstr , NULL ) ;
2005-07-02 18:38:05 +04:00
}