2009-10-16 02:33:38 +04:00
/*
Unix SMB / CIFS implementation .
SMB torture tester
2010-01-22 17:06:50 +03:00
Copyright ( C ) Guenther Deschner 2009 - 2010
2009-10-16 02:33:38 +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
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 "nsswitch/libwbclient/wbclient.h"
2010-01-29 13:22:14 +03:00
# include "nsswitch/libwbclient/wbc_async.h"
2009-10-16 02:33:38 +04:00
# include "torture/smbtorture.h"
# include "torture/winbind/proto.h"
2010-03-26 09:36:02 +03:00
# include "lib/util/util_net.h"
2009-10-16 02:33:38 +04:00
# define WBC_ERROR_EQUAL(x,y) (x == y)
# define torture_assert_wbc_equal(torture_ctx, got, expected, cmt) \
do { wbcErr __got = got , __expected = expected ; \
if ( ! WBC_ERROR_EQUAL ( __got , __expected ) ) { \
torture_result ( torture_ctx , TORTURE_FAIL , __location__ " : " # got " was %s, expected %s: %s " , wbcErrorString ( __got ) , wbcErrorString ( __expected ) , cmt ) ; \
return false ; \
} \
} while ( 0 )
# define torture_assert_wbc_ok(torture_ctx,expr,cmt) \
torture_assert_wbc_equal ( torture_ctx , expr , WBC_ERR_SUCCESS , cmt )
2010-01-29 14:09:18 +03:00
static void wbc_debug_torture ( void * private_data , enum wbcDebugLevel level ,
const char * fmt , va_list ap ) PRINTF_ATTRIBUTE ( 3 , 0 ) ;
static void wbc_debug_torture ( void * private_data , enum wbcDebugLevel level ,
const char * fmt , va_list ap )
{
struct torture_context * tctx = talloc_get_type_abort ( private_data ,
struct torture_context ) ;
torture_comment ( tctx , " %s " , talloc_vasprintf ( tctx , fmt , ap ) ) ;
}
2009-10-16 02:33:38 +04:00
static bool test_wbc_ping ( struct torture_context * tctx )
{
torture_assert_wbc_ok ( tctx , wbcPing ( ) ,
" wbcPing failed " ) ;
return true ;
}
2010-01-29 13:22:14 +03:00
static bool test_wbc_ping_async ( struct torture_context * tctx )
{
struct wb_context * wb_ctx ;
struct tevent_req * req ;
wb_ctx = wb_context_init ( tctx , NULL ) ;
req = wbcPing_send ( tctx , tctx - > ev , wb_ctx ) ;
torture_assert ( tctx , req , " wbcPing_send failed " ) ;
if ( ! tevent_req_poll ( req , tctx - > ev ) ) {
return false ;
}
torture_assert_wbc_ok ( tctx , wbcPing_recv ( req ) , " wbcPing_recv failed " ) ;
return true ;
}
2010-01-22 17:06:50 +03:00
static bool test_wbc_pingdc ( struct torture_context * tctx )
{
torture_assert_wbc_equal ( tctx , wbcPingDc ( " random_string " , NULL ) , WBC_ERR_NOT_IMPLEMENTED ,
" wbcPingDc failed " ) ;
torture_assert_wbc_ok ( tctx , wbcPingDc ( NULL , NULL ) ,
" wbcPingDc failed " ) ;
return true ;
}
2009-10-16 02:33:38 +04:00
static bool test_wbc_library_details ( struct torture_context * tctx )
{
struct wbcLibraryDetails * details ;
torture_assert_wbc_ok ( tctx , wbcLibraryDetails ( & details ) ,
" wbcLibraryDetails failed " ) ;
torture_assert ( tctx , details ,
" wbcLibraryDetails returned NULL pointer " ) ;
wbcFreeMemory ( details ) ;
return true ;
}
static bool test_wbc_interface_details ( struct torture_context * tctx )
{
struct wbcInterfaceDetails * details ;
torture_assert_wbc_ok ( tctx , wbcInterfaceDetails ( & details ) ,
" wbcInterfaceDetails failed " ) ;
torture_assert ( tctx , details ,
" wbcInterfaceDetails returned NULL pointer " ) ;
wbcFreeMemory ( details ) ;
return true ;
}
static bool test_wbc_sidtypestring ( struct torture_context * tctx )
{
torture_assert_str_equal ( tctx , wbcSidTypeString ( WBC_SID_NAME_USE_NONE ) ,
" SID_NONE " , " SID_NONE failed " ) ;
torture_assert_str_equal ( tctx , wbcSidTypeString ( WBC_SID_NAME_USER ) ,
" SID_USER " , " SID_USER failed " ) ;
torture_assert_str_equal ( tctx , wbcSidTypeString ( WBC_SID_NAME_DOM_GRP ) ,
" SID_DOM_GROUP " , " SID_DOM_GROUP failed " ) ;
torture_assert_str_equal ( tctx , wbcSidTypeString ( WBC_SID_NAME_DOMAIN ) ,
" SID_DOMAIN " , " SID_DOMAIN failed " ) ;
torture_assert_str_equal ( tctx , wbcSidTypeString ( WBC_SID_NAME_ALIAS ) ,
" SID_ALIAS " , " SID_ALIAS failed " ) ;
torture_assert_str_equal ( tctx , wbcSidTypeString ( WBC_SID_NAME_WKN_GRP ) ,
" SID_WKN_GROUP " , " SID_WKN_GROUP failed " ) ;
torture_assert_str_equal ( tctx , wbcSidTypeString ( WBC_SID_NAME_DELETED ) ,
" SID_DELETED " , " SID_DELETED failed " ) ;
torture_assert_str_equal ( tctx , wbcSidTypeString ( WBC_SID_NAME_INVALID ) ,
" SID_INVALID " , " SID_INVALID failed " ) ;
torture_assert_str_equal ( tctx , wbcSidTypeString ( WBC_SID_NAME_UNKNOWN ) ,
" SID_UNKNOWN " , " SID_UNKNOWN failed " ) ;
torture_assert_str_equal ( tctx , wbcSidTypeString ( WBC_SID_NAME_COMPUTER ) ,
" SID_COMPUTER " , " SID_COMPUTER failed " ) ;
return true ;
}
2009-10-16 15:38:57 +04:00
static bool test_wbc_sidtostring ( struct torture_context * tctx )
{
struct wbcDomainSid sid ;
const char * sid_string = " S-1-5-32 " ;
char * sid_string2 ;
torture_assert_wbc_ok ( tctx , wbcStringToSid ( sid_string , & sid ) ,
" wbcStringToSid failed " ) ;
torture_assert_wbc_ok ( tctx , wbcSidToString ( & sid , & sid_string2 ) ,
" wbcSidToString failed " ) ;
torture_assert_str_equal ( tctx , sid_string , sid_string2 ,
" sid strings differ " ) ;
2010-04-05 00:49:18 +04:00
wbcFreeMemory ( sid_string2 ) ;
2009-10-16 15:38:57 +04:00
return true ;
}
static bool test_wbc_guidtostring ( struct torture_context * tctx )
{
struct wbcGuid guid ;
const char * guid_string = " f7cf07b4-1487-45c7-824d-8b18cc580811 " ;
char * guid_string2 ;
torture_assert_wbc_ok ( tctx , wbcStringToGuid ( guid_string , & guid ) ,
" wbcStringToGuid failed " ) ;
torture_assert_wbc_ok ( tctx , wbcGuidToString ( & guid , & guid_string2 ) ,
" wbcGuidToString failed " ) ;
torture_assert_str_equal ( tctx , guid_string , guid_string2 ,
" guid strings differ " ) ;
2010-04-05 00:49:18 +04:00
wbcFreeMemory ( guid_string2 ) ;
2009-10-16 15:38:57 +04:00
return true ;
}
2009-10-16 02:33:38 +04:00
static bool test_wbc_domain_info ( struct torture_context * tctx )
{
const char * domain_name = NULL ;
struct wbcDomainInfo * info ;
struct wbcInterfaceDetails * details ;
torture_assert_wbc_ok ( tctx , wbcInterfaceDetails ( & details ) ,
" wbcInterfaceDetails failed " ) ;
domain_name = talloc_strdup ( tctx , details - > netbios_domain ) ;
wbcFreeMemory ( details ) ;
torture_assert_wbc_ok ( tctx , wbcDomainInfo ( domain_name , & info ) ,
" wbcDomainInfo failed " ) ;
torture_assert ( tctx , info ,
" wbcDomainInfo returned NULL pointer " ) ;
2010-04-05 00:49:18 +04:00
wbcFreeMemory ( info ) ;
2009-10-16 02:33:38 +04:00
return true ;
}
static bool test_wbc_users ( struct torture_context * tctx )
{
const char * domain_name = NULL ;
uint32_t num_users ;
const char * * users ;
int i ;
struct wbcInterfaceDetails * details ;
torture_assert_wbc_ok ( tctx , wbcInterfaceDetails ( & details ) ,
" wbcInterfaceDetails failed " ) ;
domain_name = talloc_strdup ( tctx , details - > netbios_domain ) ;
wbcFreeMemory ( details ) ;
torture_assert_wbc_ok ( tctx , wbcListUsers ( domain_name , & num_users , & users ) ,
" wbcListUsers failed " ) ;
torture_assert ( tctx , ! ( num_users > 0 & & ! users ) ,
" wbcListUsers returned invalid results " ) ;
for ( i = 0 ; i < MIN ( num_users , 100 ) ; i + + ) {
2009-10-16 16:51:49 +04:00
struct wbcDomainSid sid , * sids ;
2009-10-16 02:33:38 +04:00
enum wbcSidType name_type ;
char * domain ;
char * name ;
2009-10-16 16:51:49 +04:00
uint32_t num_sids ;
2009-10-16 02:33:38 +04:00
torture_assert_wbc_ok ( tctx , wbcLookupName ( domain_name , users [ i ] , & sid , & name_type ) ,
" wbcLookupName failed " ) ;
torture_assert_int_equal ( tctx , name_type , WBC_SID_NAME_USER ,
" wbcLookupName expected WBC_SID_NAME_USER " ) ;
torture_assert_wbc_ok ( tctx , wbcLookupSid ( & sid , & domain , & name , & name_type ) ,
" wbcLookupSid failed " ) ;
torture_assert_int_equal ( tctx , name_type , WBC_SID_NAME_USER ,
" wbcLookupSid expected WBC_SID_NAME_USER " ) ;
torture_assert ( tctx , name ,
" wbcLookupSid returned no name " ) ;
2010-04-05 17:11:19 +04:00
wbcFreeMemory ( domain ) ;
wbcFreeMemory ( name ) ;
2009-10-16 16:51:49 +04:00
torture_assert_wbc_ok ( tctx , wbcLookupUserSids ( & sid , true , & num_sids , & sids ) ,
" wbcLookupUserSids failed " ) ;
2010-04-05 00:49:18 +04:00
wbcFreeMemory ( sids ) ;
2009-10-16 02:33:38 +04:00
}
2010-04-05 00:49:18 +04:00
wbcFreeMemory ( users ) ;
2009-10-16 02:33:38 +04:00
return true ;
}
2010-01-29 14:09:18 +03:00
static bool test_wbc_users_async ( struct torture_context * tctx )
{
struct wb_context * wb_ctx ;
struct tevent_req * req ;
const char * domain_name = NULL ;
uint32_t num_users ;
const char * * users ;
int i ;
struct wbcInterfaceDetails * details ;
wb_ctx = wb_context_init ( tctx , NULL ) ;
wbcSetDebug ( wb_ctx , wbc_debug_torture , tctx ) ;
req = wbcInterfaceDetails_send ( tctx , tctx - > ev , wb_ctx ) ;
torture_assert ( tctx , req , " wbcInterfaceDetails_send failed " ) ;
if ( ! tevent_req_poll ( req , tctx - > ev ) ) {
return false ;
}
torture_assert_wbc_ok ( tctx ,
wbcInterfaceDetails_recv ( req , tctx , & details ) ,
" wbcInterfaceDetails_recv failed " ) ;
domain_name = talloc_strdup ( tctx , details - > netbios_domain ) ;
wbcFreeMemory ( details ) ;
/* No async implementation of this yet. */
torture_assert_wbc_ok ( tctx , wbcListUsers ( domain_name , & num_users , & users ) ,
" wbcListUsers failed " ) ;
torture_assert ( tctx , ! ( num_users > 0 & & ! users ) ,
" wbcListUsers returned invalid results " ) ;
for ( i = 0 ; i < MIN ( num_users , 100 ) ; i + + ) {
struct wbcDomainSid sid , * sids ;
enum wbcSidType name_type ;
char * domain ;
char * name ;
uint32_t num_sids ;
req = wbcLookupName_send ( tctx , tctx - > ev , wb_ctx , domain_name ,
users [ i ] ) ;
torture_assert ( tctx , req , " wbcLookupName_send failed " ) ;
if ( ! tevent_req_poll ( req , tctx - > ev ) ) {
return false ;
}
torture_assert_wbc_ok ( tctx ,
wbcLookupName_recv ( req , & sid , & name_type ) ,
" wbcLookupName_recv failed " ) ;
torture_assert_int_equal ( tctx , name_type , WBC_SID_NAME_USER ,
" wbcLookupName expected WBC_SID_NAME_USER " ) ;
torture_assert_wbc_ok ( tctx , wbcLookupSid ( & sid , & domain , & name , & name_type ) ,
" wbcLookupSid failed " ) ;
torture_assert_int_equal ( tctx , name_type , WBC_SID_NAME_USER ,
" wbcLookupSid expected WBC_SID_NAME_USER " ) ;
torture_assert ( tctx , name ,
" wbcLookupSid returned no name " ) ;
2010-04-05 17:11:19 +04:00
wbcFreeMemory ( domain ) ;
wbcFreeMemory ( name ) ;
2010-01-29 14:09:18 +03:00
torture_assert_wbc_ok ( tctx , wbcLookupUserSids ( & sid , true , & num_sids , & sids ) ,
" wbcLookupUserSids failed " ) ;
2010-04-05 00:49:18 +04:00
wbcFreeMemory ( sids ) ;
2010-01-29 14:09:18 +03:00
}
2010-04-05 00:49:18 +04:00
wbcFreeMemory ( users ) ;
2010-01-29 14:09:18 +03:00
return true ;
}
2009-10-16 02:33:38 +04:00
static bool test_wbc_groups ( struct torture_context * tctx )
{
const char * domain_name = NULL ;
uint32_t num_groups ;
const char * * groups ;
int i ;
struct wbcInterfaceDetails * details ;
torture_assert_wbc_ok ( tctx , wbcInterfaceDetails ( & details ) ,
" wbcInterfaceDetails failed " ) ;
domain_name = talloc_strdup ( tctx , details - > netbios_domain ) ;
wbcFreeMemory ( details ) ;
torture_assert_wbc_ok ( tctx , wbcListGroups ( domain_name , & num_groups , & groups ) ,
" wbcListGroups failed " ) ;
torture_assert ( tctx , ! ( num_groups > 0 & & ! groups ) ,
" wbcListGroups returned invalid results " ) ;
for ( i = 0 ; i < MIN ( num_groups , 100 ) ; i + + ) {
struct wbcDomainSid sid ;
enum wbcSidType name_type ;
char * domain ;
char * name ;
torture_assert_wbc_ok ( tctx , wbcLookupName ( domain_name , groups [ i ] , & sid , & name_type ) ,
" wbcLookupName failed " ) ;
torture_assert_wbc_ok ( tctx , wbcLookupSid ( & sid , & domain , & name , & name_type ) ,
" wbcLookupSid failed " ) ;
torture_assert ( tctx , name ,
" wbcLookupSid returned no name " ) ;
}
2010-04-05 17:11:19 +04:00
wbcFreeMemory ( groups ) ;
2009-10-16 02:33:38 +04:00
return true ;
}
static bool test_wbc_trusts ( struct torture_context * tctx )
{
struct wbcDomainInfo * domains ;
size_t num_domains ;
int i ;
torture_assert_wbc_ok ( tctx , wbcListTrusts ( & domains , & num_domains ) ,
" wbcListTrusts failed " ) ;
torture_assert ( tctx , ! ( num_domains > 0 & & ! domains ) ,
" wbcListTrusts returned invalid results " ) ;
for ( i = 0 ; i < MIN ( num_domains , 100 ) ; i + + ) {
struct wbcAuthErrorInfo * error ;
/*
struct wbcDomainSid sid ;
enum wbcSidType name_type ;
char * domain ;
char * name ;
*/
torture_assert_wbc_ok ( tctx , wbcCheckTrustCredentials ( domains [ i ] . short_name , & error ) ,
" wbcCheckTrustCredentials failed " ) ;
/*
torture_assert_wbc_ok ( tctx , wbcLookupName ( domains [ i ] . short_name , NULL , & sid , & name_type ) ,
" wbcLookupName failed " ) ;
torture_assert_int_equal ( tctx , name_type , WBC_SID_NAME_DOMAIN ,
" wbcLookupName expected WBC_SID_NAME_DOMAIN " ) ;
torture_assert_wbc_ok ( tctx , wbcLookupSid ( & sid , & domain , & name , & name_type ) ,
" wbcLookupSid failed " ) ;
torture_assert_int_equal ( tctx , name_type , WBC_SID_NAME_DOMAIN ,
" wbcLookupSid expected WBC_SID_NAME_DOMAIN " ) ;
torture_assert ( tctx , name ,
" wbcLookupSid returned no name " ) ;
*/
}
2010-04-05 00:49:18 +04:00
wbcFreeMemory ( domains ) ;
2009-10-16 02:33:38 +04:00
return true ;
}
2009-10-16 15:39:24 +04:00
static bool test_wbc_lookupdc ( struct torture_context * tctx )
{
const char * domain_name = NULL ;
struct wbcInterfaceDetails * details ;
struct wbcDomainControllerInfo * dc_info ;
torture_assert_wbc_ok ( tctx , wbcInterfaceDetails ( & details ) ,
" wbcInterfaceDetails failed " ) ;
domain_name = talloc_strdup ( tctx , details - > netbios_domain ) ;
wbcFreeMemory ( details ) ;
torture_assert_wbc_ok ( tctx , wbcLookupDomainController ( domain_name , 0 , & dc_info ) ,
" wbcLookupDomainController failed " ) ;
2010-04-05 00:49:18 +04:00
wbcFreeMemory ( dc_info ) ;
2009-10-16 15:39:24 +04:00
return true ;
}
static bool test_wbc_lookupdcex ( struct torture_context * tctx )
{
const char * domain_name = NULL ;
struct wbcInterfaceDetails * details ;
struct wbcDomainControllerInfoEx * dc_info ;
torture_assert_wbc_ok ( tctx , wbcInterfaceDetails ( & details ) ,
" wbcInterfaceDetails failed " ) ;
domain_name = talloc_strdup ( tctx , details - > netbios_domain ) ;
wbcFreeMemory ( details ) ;
torture_assert_wbc_ok ( tctx , wbcLookupDomainControllerEx ( domain_name , NULL , NULL , 0 , & dc_info ) ,
" wbcLookupDomainControllerEx failed " ) ;
2010-04-05 00:49:18 +04:00
wbcFreeMemory ( dc_info ) ;
2009-10-16 15:39:24 +04:00
return true ;
}
2009-10-16 02:33:38 +04:00
2010-01-22 18:27:39 +03:00
static bool test_wbc_resolve_winsbyname ( struct torture_context * tctx )
{
const char * name ;
char * ip ;
wbcErr ret ;
name = torture_setting_string ( tctx , " host " , NULL ) ;
ret = wbcResolveWinsByName ( name , & ip ) ;
if ( is_ipaddress ( name ) ) {
torture_assert_wbc_equal ( tctx , ret , WBC_ERR_DOMAIN_NOT_FOUND , " wbcResolveWinsByName failed " ) ;
} else {
torture_assert_wbc_ok ( tctx , ret , " wbcResolveWinsByName failed " ) ;
}
return true ;
}
static bool test_wbc_resolve_winsbyip ( struct torture_context * tctx )
{
const char * ip ;
char * name ;
wbcErr ret ;
ip = torture_setting_string ( tctx , " host " , NULL ) ;
ret = wbcResolveWinsByIP ( ip , & name ) ;
torture_assert_wbc_ok ( tctx , ret , " wbcResolveWinsByIP failed " ) ;
2010-04-05 17:11:19 +04:00
wbcFreeMemory ( name ) ;
2010-01-22 18:27:39 +03:00
return true ;
}
2009-10-16 02:33:38 +04:00
struct torture_suite * torture_wbclient ( void )
{
struct torture_suite * suite = torture_suite_create ( talloc_autofree_context ( ) , " WBCLIENT " ) ;
torture_suite_add_simple_test ( suite , " wbcPing " , test_wbc_ping ) ;
2010-01-29 13:22:14 +03:00
torture_suite_add_simple_test ( suite , " wbcPing_async " , test_wbc_ping_async ) ;
2010-01-22 17:06:50 +03:00
torture_suite_add_simple_test ( suite , " wbcPingDc " , test_wbc_pingdc ) ;
2009-10-16 02:33:38 +04:00
torture_suite_add_simple_test ( suite , " wbcLibraryDetails " , test_wbc_library_details ) ;
torture_suite_add_simple_test ( suite , " wbcInterfaceDetails " , test_wbc_interface_details ) ;
torture_suite_add_simple_test ( suite , " wbcSidTypeString " , test_wbc_sidtypestring ) ;
2009-10-16 15:38:57 +04:00
torture_suite_add_simple_test ( suite , " wbcSidToString " , test_wbc_sidtostring ) ;
torture_suite_add_simple_test ( suite , " wbcGuidToString " , test_wbc_guidtostring ) ;
2009-10-16 02:33:38 +04:00
torture_suite_add_simple_test ( suite , " wbcDomainInfo " , test_wbc_domain_info ) ;
torture_suite_add_simple_test ( suite , " wbcListUsers " , test_wbc_users ) ;
2010-01-29 14:09:18 +03:00
torture_suite_add_simple_test ( suite , " wbcListUsers_async " , test_wbc_users_async ) ;
2009-10-16 02:33:38 +04:00
torture_suite_add_simple_test ( suite , " wbcListGroups " , test_wbc_groups ) ;
torture_suite_add_simple_test ( suite , " wbcListTrusts " , test_wbc_trusts ) ;
2009-10-16 15:39:24 +04:00
torture_suite_add_simple_test ( suite , " wbcLookupDomainController " , test_wbc_lookupdc ) ;
torture_suite_add_simple_test ( suite , " wbcLookupDomainControllerEx " , test_wbc_lookupdcex ) ;
2010-01-22 18:27:39 +03:00
torture_suite_add_simple_test ( suite , " wbcResolveWinsByName " , test_wbc_resolve_winsbyname ) ;
torture_suite_add_simple_test ( suite , " wbcResolveWinsByIP " , test_wbc_resolve_winsbyip ) ;
2009-10-16 02:33:38 +04:00
return suite ;
}