2010-03-23 16:04:30 +01:00
/*
2005-08-02 18:15:23 +00:00
Unix SMB / CIFS implementation .
Test suite for libnet calls .
Copyright ( C ) Gregory LEOCADIE < gleocadie @ idealx . com > 2005
2005-08-03 03:42:43 +00:00
Copyright ( C ) Rafal Szczesniak 2005
2010-03-23 16:04:30 +01:00
2005-08-02 18:15:23 +00: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 02:07:03 +00:00
the Free Software Foundation ; either version 3 of the License , or
2005-08-02 18:15:23 +00:00
( at your option ) any later version .
2010-03-23 16:04:30 +01:00
2005-08-02 18:15:23 +00: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 16:04:30 +01:00
2005-08-02 18:15:23 +00:00
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/>.
2005-08-02 18:15:23 +00:00
*/
# include "includes.h"
2006-03-14 15:02:05 +00:00
# include "torture/rpc/rpc.h"
2005-08-02 18:15:23 +00:00
# include "libnet/libnet.h"
# include "lib/cmdline/popt_common.h"
2006-03-14 23:35:30 +00:00
# include "librpc/gen_ndr/ndr_srvsvc_c.h"
2005-08-02 18:15:23 +00:00
# define TEST_SHARENAME "libnetsharetest"
2010-03-23 15:31:27 +01:00
static void test_displayshares ( struct torture_context * tctx ,
struct libnet_ListShares s )
2005-08-02 20:35:52 +00:00
{
int i , j ;
struct share_type {
enum srvsvc_ShareType type ;
const char * desc ;
} share_types [ ] = {
{ STYPE_DISKTREE , " STYPE_DISKTREE " } ,
{ STYPE_DISKTREE_TEMPORARY , " STYPE_DISKTREE_TEMPORARY " } ,
{ STYPE_DISKTREE_HIDDEN , " STYPE_DISKTREE_HIDDEN " } ,
{ STYPE_PRINTQ , " STYPE_PRINTQ " } ,
{ STYPE_PRINTQ_TEMPORARY , " STYPE_PRINTQ_TEMPORARY " } ,
{ STYPE_PRINTQ_HIDDEN , " STYPE_PRINTQ_HIDDEN " } ,
{ STYPE_DEVICE , " STYPE_DEVICE " } ,
{ STYPE_DEVICE_TEMPORARY , " STYPE_DEVICE_TEMPORARY " } ,
{ STYPE_DEVICE_HIDDEN , " STYPE_DEVICE_HIDDEN " } ,
{ STYPE_IPC , " STYPE_IPC " } ,
{ STYPE_IPC_TEMPORARY , " STYPE_IPC_TEMPORARY " } ,
{ STYPE_IPC_HIDDEN , " STYPE_IPC_HIDDEN " }
} ;
switch ( s . in . level ) {
case 0 :
for ( i = 0 ; i < s . out . ctr . ctr0 - > count ; i + + ) {
2006-05-26 02:25:53 +00:00
struct srvsvc_NetShareInfo0 * info = & s . out . ctr . ctr0 - > array [ i ] ;
2010-03-23 15:31:27 +01:00
torture_comment ( tctx , " \t [%d] %s \n " , i , info - > name ) ;
2005-08-02 20:35:52 +00:00
}
break ;
case 1 :
for ( i = 0 ; i < s . out . ctr . ctr1 - > count ; i + + ) {
2006-05-26 02:25:53 +00:00
struct srvsvc_NetShareInfo1 * info = & s . out . ctr . ctr1 - > array [ i ] ;
2005-08-02 20:35:52 +00:00
for ( j = 0 ; j < ARRAY_SIZE ( share_types ) ; j + + ) {
2006-05-26 02:25:53 +00:00
if ( share_types [ j ] . type = = info - > type ) break ;
2005-08-02 20:35:52 +00:00
}
2010-03-23 15:31:27 +01:00
torture_comment ( tctx , " \t [%d] %s (%s) \t %s \n " , i , info - > name ,
2006-05-26 02:25:53 +00:00
info - > comment , share_types [ j ] . desc ) ;
2005-08-02 20:35:52 +00:00
}
break ;
case 2 :
for ( i = 0 ; i < s . out . ctr . ctr2 - > count ; i + + ) {
2006-05-26 02:25:53 +00:00
struct srvsvc_NetShareInfo2 * info = & s . out . ctr . ctr2 - > array [ i ] ;
2005-08-02 20:35:52 +00:00
for ( j = 0 ; j < ARRAY_SIZE ( share_types ) ; j + + ) {
2006-05-26 02:25:53 +00:00
if ( share_types [ j ] . type = = info - > type ) break ;
2005-08-02 20:35:52 +00:00
}
2010-03-23 15:31:27 +01:00
torture_comment ( tctx , " \t [%d] %s \t %s \n \t %s \n \t [perms=0x%08x, max_usr=%d, cur_usr=%d, path=%s, pass=%s] \n " ,
2006-05-26 02:25:53 +00:00
i , info - > name , share_types [ j ] . desc , info - > comment ,
info - > permissions , info - > max_users ,
info - > current_users , info - > path ,
info - > password ) ;
2005-08-02 20:35:52 +00:00
}
break ;
case 501 :
for ( i = 0 ; i < s . out . ctr . ctr501 - > count ; i + + ) {
2006-05-26 02:25:53 +00:00
struct srvsvc_NetShareInfo501 * info = & s . out . ctr . ctr501 - > array [ i ] ;
2005-08-02 20:35:52 +00:00
for ( j = 0 ; j < ARRAY_SIZE ( share_types ) ; j + + ) {
2006-05-26 02:25:53 +00:00
if ( share_types [ j ] . type = = info - > type ) break ;
2005-08-02 20:35:52 +00:00
}
2010-03-23 15:31:27 +01:00
torture_comment ( tctx , " \t [%d] %s \t %s [csc_policy=0x%08x] \n \t %s \n " , i , info - > name ,
2006-05-26 02:25:53 +00:00
share_types [ j ] . desc , info - > csc_policy ,
info - > comment ) ;
2005-08-02 20:35:52 +00:00
}
break ;
case 502 :
for ( i = 0 ; i < s . out . ctr . ctr502 - > count ; i + + ) {
2006-05-26 02:25:53 +00:00
struct srvsvc_NetShareInfo502 * info = & s . out . ctr . ctr502 - > array [ i ] ;
2005-08-02 20:35:52 +00:00
for ( j = 0 ; j < ARRAY_SIZE ( share_types ) ; j + + ) {
2006-05-26 02:25:53 +00:00
if ( share_types [ j ] . type = = info - > type ) break ;
2005-08-02 20:35:52 +00:00
}
2010-03-23 15:31:27 +01:00
torture_comment ( tctx , " \t [%d] %s \t %s \n \t %s \n \t [perms=0x%08x, max_usr=%d, cur_usr=%d, path=%s, pass=%s] \n " ,
2006-05-26 02:25:53 +00:00
i , info - > name , share_types [ j ] . desc , info - > comment ,
info - > permissions , info - > max_users ,
info - > current_users , info - > path ,
2008-10-29 21:04:31 +01:00
info - > password ) ;
2005-08-02 20:35:52 +00:00
}
break ;
}
}
2007-10-06 22:28:14 +00:00
bool torture_listshares ( struct torture_context * torture )
2005-08-02 18:15:23 +00:00
{
struct libnet_ListShares share ;
NTSTATUS status ;
uint32_t levels [ ] = { 0 , 1 , 2 , 501 , 502 } ;
int i ;
2007-10-06 22:28:14 +00:00
bool ret = true ;
2005-08-02 18:15:23 +00:00
struct libnet_context * libnetctx ;
2008-01-02 18:39:11 -06:00
struct dcerpc_binding * binding ;
2005-08-02 18:15:23 +00:00
TALLOC_CTX * mem_ctx ;
mem_ctx = talloc_init ( " test_listshares " ) ;
2008-01-02 18:39:11 -06:00
status = torture_rpc_binding ( torture , & binding ) ;
2005-08-02 22:25:42 +00:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2007-10-06 22:28:14 +00:00
ret = false ;
2005-08-02 22:25:42 +00:00
goto done ;
}
2005-08-02 18:15:23 +00:00
2008-04-14 12:43:37 -04:00
libnetctx = libnet_context_init ( torture - > ev , torture - > lp_ctx ) ;
2005-08-02 22:25:42 +00:00
if ( ! libnetctx ) {
2010-03-23 15:31:27 +01:00
torture_comment ( torture , " Couldn't allocate libnet context \n " ) ;
2007-10-06 22:28:14 +00:00
ret = false ;
2005-08-02 22:25:42 +00:00
goto done ;
}
2005-08-02 18:15:23 +00:00
libnetctx - > cred = cmdline_credentials ;
2010-03-23 16:04:30 +01:00
2010-03-23 15:31:27 +01:00
torture_comment ( torture , " Testing libnet_ListShare \n " ) ;
2010-03-23 16:04:30 +01:00
2008-01-02 18:39:11 -06:00
share . in . server_name = talloc_asprintf ( mem_ctx , " %s " , binding - > host ) ;
2005-08-02 18:15:23 +00:00
for ( i = 0 ; i < ARRAY_SIZE ( levels ) ; i + + ) {
share . in . level = levels [ i ] ;
2010-04-11 01:39:06 +02:00
torture_comment ( torture , " Testing libnet_ListShare level %u \n " , share . in . level ) ;
2005-08-02 18:15:23 +00:00
status = libnet_ListShares ( libnetctx , mem_ctx , & share ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2010-03-23 15:31:27 +01:00
torture_comment ( torture , " libnet_ListShare level %u failed - %s \n " , share . in . level , share . out . error_string ) ;
2007-10-06 22:28:14 +00:00
ret = false ;
2005-08-02 22:25:42 +00:00
goto done ;
2005-08-02 18:15:23 +00:00
}
2005-08-02 20:35:52 +00:00
2010-03-23 15:31:27 +01:00
torture_comment ( torture , " listing shares: \n " ) ;
test_displayshares ( torture , share ) ;
2005-08-02 18:15:23 +00:00
}
2005-08-02 22:25:42 +00:00
done :
talloc_free ( mem_ctx ) ;
2005-08-02 18:15:23 +00:00
return ret ;
}
2010-03-23 15:31:27 +01:00
static bool test_addshare ( struct torture_context * tctx ,
struct dcerpc_binding_handle * b , TALLOC_CTX * mem_ctx , const char * host ,
2005-08-04 01:38:53 +00:00
const char * share )
2005-08-03 03:28:10 +00:00
{
NTSTATUS status ;
struct srvsvc_NetShareAdd add ;
2008-10-29 14:52:49 +01:00
union srvsvc_NetShareInfo info ;
2005-08-03 03:28:10 +00:00
struct srvsvc_NetShareInfo2 i ;
2010-03-23 16:04:30 +01:00
2005-08-03 03:28:10 +00:00
i . name = share ;
i . type = STYPE_DISKTREE ;
i . path = " C: \\ WINDOWS \\ TEMP " ;
i . max_users = 5 ;
i . comment = " Comment to the test share " ;
i . password = NULL ;
i . permissions = 0x0 ;
2008-10-29 14:52:49 +01:00
info . info2 = & i ;
2005-08-03 03:28:10 +00:00
add . in . server_unc = host ;
add . in . level = 2 ;
2008-10-29 14:52:49 +01:00
add . in . info = & info ;
2007-12-10 06:21:29 +01:00
add . in . parm_error = NULL ;
2005-08-03 03:28:10 +00:00
2010-03-11 11:33:10 +01:00
status = dcerpc_srvsvc_NetShareAdd_r ( b , mem_ctx , & add ) ;
2005-08-03 03:28:10 +00:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2010-03-23 15:31:27 +01:00
torture_comment ( tctx , " Failed to add a new share \n " ) ;
2007-10-06 22:28:14 +00:00
return false ;
2005-08-03 03:28:10 +00:00
}
2010-03-23 15:31:27 +01:00
torture_comment ( tctx , " share added \n " ) ;
2007-10-06 22:28:14 +00:00
return true ;
2005-08-03 03:28:10 +00:00
}
2007-09-02 14:09:24 +00:00
bool torture_delshare ( struct torture_context * torture )
2005-08-02 18:15:23 +00:00
{
2005-08-03 03:28:10 +00:00
struct dcerpc_pipe * p ;
2008-01-02 18:39:11 -06:00
struct dcerpc_binding * binding ;
2005-08-02 18:15:23 +00:00
struct libnet_context * libnetctx ;
2007-08-28 19:03:08 +00:00
const char * host ;
2005-08-02 18:15:23 +00:00
NTSTATUS status ;
2007-10-06 22:28:14 +00:00
bool ret = true ;
2005-08-02 18:15:23 +00:00
struct libnet_DelShare share ;
2010-03-23 16:04:30 +01:00
2006-10-18 14:23:19 +00:00
host = torture_setting_string ( torture , " host " , NULL ) ;
2008-01-02 18:39:11 -06:00
status = torture_rpc_binding ( torture , & binding ) ;
2007-09-02 14:09:24 +00:00
torture_assert_ntstatus_ok ( torture , status , " Failed to get binding " ) ;
2005-08-02 18:15:23 +00:00
2008-04-14 12:43:37 -04:00
libnetctx = libnet_context_init ( torture - > ev , torture - > lp_ctx ) ;
2005-08-02 18:15:23 +00:00
libnetctx - > cred = cmdline_credentials ;
2007-08-28 12:54:27 +00:00
status = torture_rpc_connection ( torture ,
2005-08-03 03:28:10 +00:00
& p ,
2007-08-19 21:23:03 +00:00
& ndr_table_srvsvc ) ;
2005-08-03 03:28:10 +00:00
2007-12-10 05:45:41 +01:00
torture_assert_ntstatus_ok ( torture , status , " Failed to get rpc connection " ) ;
2010-03-23 15:31:27 +01:00
if ( ! test_addshare ( torture , p - > binding_handle , torture , host , TEST_SHARENAME ) ) {
2007-09-02 14:09:24 +00:00
return false ;
2005-08-03 03:28:10 +00:00
}
2008-01-02 18:39:11 -06:00
share . in . server_name = binding - > host ;
2005-08-02 18:15:23 +00:00
share . in . share_name = TEST_SHARENAME ;
2007-09-02 14:09:24 +00:00
status = libnet_DelShare ( libnetctx , torture , & share ) ;
torture_assert_ntstatus_ok ( torture , status , " Failed to delete share " ) ;
2005-08-02 18:15:23 +00:00
return ret ;
}