2005-07-02 18:38:05 +04:00
/*
Unix SMB / CIFS implementation .
Test suite for libnet calls .
Copyright ( C ) Rafal Szczesniak 2005
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 .
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 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"
2006-05-22 01:18:35 +04:00
# include "auth/credentials/credentials.h"
2005-07-02 18:38:05 +04:00
# include "libnet/libnet.h"
2006-05-04 18:54:31 +04:00
# include "libcli/security/security.h"
# include "librpc/ndr/libndr.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"
2006-03-18 18:42:57 +03:00
# include "librpc/rpc/dcerpc.h"
2006-03-25 19:01:28 +03:00
# include "torture/torture.h"
2005-07-02 18:38:05 +04:00
2006-05-22 01:18:35 +04:00
static BOOL test_connect_service ( 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 ,
BOOL badcreds , NTSTATUS expected_status )
2005-07-02 18:38:05 +04:00
{
NTSTATUS status ;
struct libnet_RpcConnect connect ;
2006-05-22 01:18:35 +04:00
connect . level = level ;
connect . in . binding = binding_string ;
connect . in . name = hostname ;
connect . in . dcerpc_iface = iface ;
/* 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
status = libnet_RpcConnect ( ctx , ctx , & connect ) ;
2006-05-22 01:18:35 +04:00
if ( ! NT_STATUS_EQUAL ( status , expected_status ) ) {
2006-05-26 08:35:37 +04:00
d_printf ( " Connecting to rpc service %s on %s. \n \t FAILED. Expected: %s. "
2006-05-22 01:18:35 +04:00
" Received: %s \n " ,
connect . in . dcerpc_iface - > name , connect . in . binding , nt_errstr ( expected_status ) ,
2005-07-02 18:38:05 +04:00
nt_errstr ( status ) ) ;
return False ;
}
2006-05-26 08:35:37 +04:00
d_printf ( " PASSED. Expected: %s, received: %s \n " , nt_errstr ( expected_status ) ,
2006-05-22 01:18:35 +04:00
nt_errstr ( status ) ) ;
if ( connect . level = = LIBNET_RPC_CONNECT_DC_INFO & & NT_STATUS_IS_OK ( status ) ) {
2006-05-26 08:35:37 +04:00
d_printf ( " Domain Controller Info: \n " ) ;
d_printf ( " \t Domain Name: \t %s \n " , connect . out . domain_name ) ;
d_printf ( " \t Domain SID: \t %s \n " , dom_sid_string ( ctx , connect . out . domain_sid ) ) ;
d_printf ( " \t Realm: \t \t %s \n " , connect . out . realm ) ;
d_printf ( " \t GUID: \t \t %s \n " , GUID_string ( ctx , connect . out . guid ) ) ;
2006-05-22 01:18:35 +04:00
} else if ( ! NT_STATUS_IS_OK ( status ) ) {
2006-05-26 08:35:37 +04:00
d_printf ( " Error string: %s \n " , connect . out . error_string ) ;
2006-05-22 01:18:35 +04:00
}
2005-07-02 18:38:05 +04:00
return True ;
}
2006-05-22 01:18:35 +04:00
static BOOL torture_rpc_connect ( struct torture_context * torture ,
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 ;
ctx = libnet_context_init ( NULL ) ;
ctx - > cred = cmdline_credentials ;
2006-05-04 18:54:31 +04:00
2006-05-26 08:35:37 +04:00
d_printf ( " Testing connection to LSA interface \n " ) ;
2007-08-20 01:23:03 +04:00
if ( ! test_connect_service ( ctx , & ndr_table_lsarpc , bindstr ,
2006-05-22 01:18:35 +04:00
hostname , level , False , NT_STATUS_OK ) ) {
2006-05-26 08:35:37 +04:00
d_printf ( " failed to connect LSA interface \n " ) ;
2006-05-22 01:18:35 +04:00
return False ;
}
2006-05-26 08:35:37 +04:00
d_printf ( " Testing connection to SAMR interface \n " ) ;
2007-08-20 01:23:03 +04:00
if ( ! test_connect_service ( ctx , & ndr_table_samr , bindstr ,
2006-05-22 01:18:35 +04:00
hostname , level , False , NT_STATUS_OK ) ) {
2006-05-26 08:35:37 +04:00
d_printf ( " failed to connect SAMR interface \n " ) ;
2006-05-22 01:18:35 +04:00
return False ;
}
2006-05-26 08:35:37 +04:00
d_printf ( " Testing connection to SRVSVC interface \n " ) ;
2007-08-20 01:23:03 +04:00
if ( ! test_connect_service ( ctx , & ndr_table_srvsvc , bindstr ,
2006-05-22 01:18:35 +04:00
hostname , level , False , NT_STATUS_OK ) ) {
2006-05-26 08:35:37 +04:00
d_printf ( " failed to connect SRVSVC interface \n " ) ;
2006-05-22 01:18:35 +04:00
return False ;
}
2006-05-04 18:54:31 +04:00
2006-05-26 08:35:37 +04:00
d_printf ( " Testing connection to LSA interface with wrong credentials \n " ) ;
2007-08-20 01:23:03 +04:00
if ( ! test_connect_service ( ctx , & ndr_table_lsarpc , bindstr ,
2006-05-22 01:18:35 +04:00
hostname , level , True , NT_STATUS_LOGON_FAILURE ) ) {
2006-05-26 08:35:37 +04:00
d_printf ( " failed to test wrong credentials on LSA interface \n " ) ;
2006-05-04 18:54:31 +04:00
return False ;
}
2006-05-26 08:35:37 +04:00
d_printf ( " Testing connection to SAMR interface with wrong credentials \n " ) ;
2007-08-20 01:23:03 +04:00
if ( ! test_connect_service ( ctx , & ndr_table_samr , bindstr ,
2006-05-22 01:18:35 +04:00
hostname , level , True , NT_STATUS_LOGON_FAILURE ) ) {
2006-05-26 08:35:37 +04:00
d_printf ( " failed to test wrong credentials on SAMR interface \n " ) ;
2006-05-22 01:18:35 +04:00
return False ;
}
talloc_free ( ctx ) ;
2006-05-04 18:54:31 +04:00
return True ;
}
2006-05-22 01:18:35 +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 ;
const char * bindstr ; ;
2005-07-02 18:38:05 +04:00
2006-10-18 18:23:19 +04:00
bindstr = torture_setting_string ( torture , " binding " , NULL ) ;
2006-05-22 01:18:35 +04:00
status = dcerpc_parse_binding ( torture , bindstr , & binding ) ;
2005-07-02 18:38:05 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2006-05-26 08:35:37 +04:00
d_printf ( " failed to parse binding string \n " ) ;
2005-07-02 18:38:05 +04:00
return False ;
}
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
2006-05-22 01:18:35 +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 ;
const char * bindstr ;
2007-05-12 01:48:29 +04:00
const char * domain_name ;
2006-05-16 01:50:53 +04:00
2006-10-18 18:23:19 +04:00
bindstr = torture_setting_string ( torture , " binding " , NULL ) ;
2006-05-22 01:18:35 +04:00
status = dcerpc_parse_binding ( torture , bindstr , & binding ) ;
2006-05-16 01:50:53 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2006-05-26 08:35:37 +04:00
d_printf ( " failed to parse binding string \n " ) ;
2006-05-16 01:50:53 +04:00
return False ;
}
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 . */
domain_name = lp_workgroup ( ) ;
return torture_rpc_connect ( torture , level , NULL , domain_name ) ;
2006-05-16 01:50:53 +04:00
}
2006-05-22 01:18:35 +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 ;
const char * bindstr ;
2007-05-12 01:48:29 +04:00
const char * domain_name ;
2005-07-02 18:38:05 +04:00
2006-10-18 18:23:19 +04:00
bindstr = torture_setting_string ( torture , " binding " , NULL ) ;
2006-05-22 01:18:35 +04:00
status = dcerpc_parse_binding ( torture , bindstr , & binding ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2006-05-26 08:35:37 +04:00
d_printf ( " failed to parse binding string \n " ) ;
2005-07-02 18:38:05 +04:00
return False ;
}
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 . */
domain_name = lp_workgroup ( ) ;
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
BOOL torture_rpc_connect_dc_info ( struct torture_context * torture )
{
const enum libnet_RpcConnect_level level = LIBNET_RPC_CONNECT_DC_INFO ;
NTSTATUS status ;
struct dcerpc_binding * binding ;
const char * bindstr ;
2007-05-12 01:48:29 +04:00
const char * domain_name ;
2006-05-22 01:18:35 +04:00
2006-10-18 18:23:19 +04:00
bindstr = torture_setting_string ( torture , " binding " , NULL ) ;
2006-05-22 01:18:35 +04:00
status = dcerpc_parse_binding ( torture , bindstr , & binding ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2006-05-26 08:35:37 +04:00
d_printf ( " failed to parse binding string \n " ) ;
2006-05-16 01:50:53 +04:00
return False ;
}
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 . */
domain_name = lp_workgroup ( ) ;
return torture_rpc_connect ( torture , level , NULL , domain_name ) ;
2006-05-22 01:18:35 +04:00
}
BOOL torture_rpc_connect_binding ( struct torture_context * torture )
{
const enum libnet_RpcConnect_level level = LIBNET_RPC_CONNECT_BINDING ;
NTSTATUS status ;
struct dcerpc_binding * binding ;
const char * bindstr ;
2006-10-18 18:23:19 +04:00
bindstr = torture_setting_string ( torture , " binding " , NULL ) ;
2006-05-22 01:18:35 +04:00
status = dcerpc_parse_binding ( torture , bindstr , & binding ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2006-05-26 08:35:37 +04:00
d_printf ( " failed to parse binding string \n " ) ;
2005-07-02 18:38:05 +04:00
return False ;
}
2006-05-22 01:18:35 +04:00
return torture_rpc_connect ( torture , level , bindstr , NULL ) ;
2005-07-02 18:38:05 +04:00
}