2004-11-09 09:26:47 +00:00
/*
Unix SMB / CIFS implementation .
test server handling of unexpected client disconnects
Copyright ( C ) Andrew Tridgell 2004
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
2004-11-09 09:26:47 +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/>.
2004-11-09 09:26:47 +00:00
*/
# include "includes.h"
2005-02-10 05:09:35 +00:00
# include "system/filesys.h"
2004-11-09 09:26:47 +00:00
# include "libcli/raw/libcliraw.h"
2008-04-02 04:53:27 +02:00
# include "libcli/raw/raw_proto.h"
2006-01-03 15:40:05 +00:00
# include "libcli/libcli.h"
2006-03-17 17:59:58 +00:00
# include "torture/util.h"
2011-03-19 00:42:52 +01:00
# include "torture/basic/proto.h"
2004-11-09 09:26:47 +00:00
# define BASEDIR "\\test_disconnect"
# define CHECK_STATUS(status, correct) do { \
if ( ! NT_STATUS_EQUAL ( status , correct ) ) { \
printf ( " (%s) Incorrect status %s - should be %s \n " , \
__location__ , nt_errstr ( status ) , nt_errstr ( correct ) ) ; \
talloc_free ( cli ) ; \
2007-10-06 22:28:14 +00:00
return false ; \
2004-11-09 09:26:47 +00:00
} } while ( 0 )
/*
test disconnect after async open
*/
2007-10-06 22:28:14 +00:00
static bool test_disconnect_open ( struct smbcli_state * cli , TALLOC_CTX * mem_ctx )
2004-11-09 09:26:47 +00:00
{
union smb_open io ;
struct smbcli_request * req1 , * req2 ;
2011-11-21 13:06:00 -08:00
NTSTATUS status ;
2004-11-09 09:26:47 +00:00
printf ( " trying open/disconnect \n " ) ;
io . generic . level = RAW_OPEN_NTCREATEX ;
2009-10-15 18:26:19 +11:00
io . ntcreatex . in . root_fid . fnum = 0 ;
2004-11-09 09:26:47 +00:00
io . ntcreatex . in . flags = 0 ;
2004-11-30 04:33:27 +00:00
io . ntcreatex . in . access_mask = SEC_FILE_READ_DATA ;
2004-11-09 09:26:47 +00:00
io . ntcreatex . in . create_options = 0 ;
io . ntcreatex . in . file_attr = FILE_ATTRIBUTE_NORMAL ;
io . ntcreatex . in . share_access = NTCREATEX_SHARE_ACCESS_READ ;
io . ntcreatex . in . alloc_size = 0 ;
io . ntcreatex . in . open_disposition = NTCREATEX_DISP_OPEN_IF ;
io . ntcreatex . in . impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS ;
io . ntcreatex . in . security_flags = 0 ;
io . ntcreatex . in . fname = BASEDIR " \\ open.dat " ;
status = smb_raw_open ( cli - > tree , mem_ctx , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2004-11-09 09:35:45 +00:00
io . ntcreatex . in . share_access = 0 ;
2004-11-09 09:26:47 +00:00
req1 = smb_raw_open_send ( cli - > tree , & io ) ;
req2 = smb_raw_open_send ( cli - > tree , & io ) ;
2011-11-21 13:06:00 -08:00
if ( ! req1 | | ! req2 ) {
printf ( " test_disconnect_open: smb_raw_open_send() "
" returned NULL \n " ) ;
return false ;
}
2004-11-09 09:35:45 +00:00
status = smbcli_chkpath ( cli - > tree , " \\ " ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2004-11-09 09:26:47 +00:00
talloc_free ( cli ) ;
2007-10-06 22:28:14 +00:00
return true ;
2004-11-09 09:26:47 +00:00
}
/*
test disconnect with timed lock
*/
2007-10-06 22:28:14 +00:00
static bool test_disconnect_lock ( struct smbcli_state * cli , TALLOC_CTX * mem_ctx )
2004-11-09 09:26:47 +00:00
{
union smb_lock io ;
NTSTATUS status ;
int fnum ;
struct smbcli_request * req ;
struct smb_lock_entry lock [ 1 ] ;
printf ( " trying disconnect with async lock \n " ) ;
fnum = smbcli_open ( cli - > tree , BASEDIR " \\ write.dat " ,
O_RDWR | O_CREAT , DENY_NONE ) ;
if ( fnum = = - 1 ) {
printf ( " open failed in mux_write - %s \n " , smbcli_errstr ( cli - > tree ) ) ;
2007-10-06 22:28:14 +00:00
return false ;
2004-11-09 09:26:47 +00:00
}
io . lockx . level = RAW_LOCK_LOCKX ;
2006-03-12 22:48:25 +00:00
io . lockx . in . file . fnum = fnum ;
2004-11-09 09:26:47 +00:00
io . lockx . in . mode = 0 ;
io . lockx . in . timeout = 0 ;
io . lockx . in . lock_cnt = 1 ;
io . lockx . in . ulock_cnt = 0 ;
lock [ 0 ] . pid = 1 ;
lock [ 0 ] . offset = 0 ;
lock [ 0 ] . count = 4 ;
io . lockx . in . locks = & lock [ 0 ] ;
status = smb_raw_lock ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
lock [ 0 ] . pid = 2 ;
io . lockx . in . timeout = 3000 ;
req = smb_raw_lock_send ( cli - > tree , & io ) ;
2011-11-21 13:06:00 -08:00
if ( ! req ) {
printf ( " test_disconnect_lock: smb_raw_lock_send() "
" returned NULL \n " ) ;
return false ;
}
2004-11-09 09:26:47 +00:00
2004-11-09 09:35:45 +00:00
status = smbcli_chkpath ( cli - > tree , " \\ " ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2004-11-09 09:26:47 +00:00
talloc_free ( cli ) ;
2007-10-06 22:28:14 +00:00
return true ;
2004-11-09 09:26:47 +00:00
}
/*
basic testing of disconnects
*/
2007-09-07 15:08:14 +00:00
bool torture_disconnect ( struct torture_context * torture )
2004-11-09 09:26:47 +00:00
{
2007-10-06 22:28:14 +00:00
bool ret = true ;
2004-11-09 09:26:47 +00:00
TALLOC_CTX * mem_ctx ;
int i ;
2005-07-26 12:40:26 +00:00
extern int torture_numops ;
2006-10-16 13:06:41 +00:00
struct smbcli_state * cli ;
2004-11-09 09:26:47 +00:00
mem_ctx = talloc_init ( " torture_raw_mux " ) ;
2007-12-03 15:53:07 +01:00
if ( ! torture_open_connection ( & cli , torture , 0 ) ) {
2007-10-06 22:28:14 +00:00
return false ;
2004-11-09 09:26:47 +00:00
}
2012-05-18 15:43:31 +10:00
torture_assert ( torture , torture_setup_dir ( cli , BASEDIR ) , " Failed to setup up test directory: " BASEDIR ) ;
2004-11-09 09:26:47 +00:00
2005-07-26 12:40:26 +00:00
for ( i = 0 ; i < torture_numops ; i + + ) {
2004-11-09 09:26:47 +00:00
ret & = test_disconnect_lock ( cli , mem_ctx ) ;
2007-12-03 15:53:07 +01:00
if ( ! torture_open_connection ( & cli , torture , 0 ) ) {
2007-10-06 22:28:14 +00:00
return false ;
2004-11-09 09:26:47 +00:00
}
ret & = test_disconnect_open ( cli , mem_ctx ) ;
2007-12-03 15:53:07 +01:00
if ( ! torture_open_connection ( & cli , torture , 0 ) ) {
2007-10-06 22:28:14 +00:00
return false ;
2004-11-09 09:26:47 +00:00
}
2006-08-05 08:21:31 +00:00
2007-10-06 22:28:14 +00:00
if ( torture_setting_bool ( torture , " samba3 " , false ) ) {
2006-08-05 08:21:31 +00:00
/*
* In Samba3 it might happen that the old smbd from
* test_disconnect_lock is not scheduled before the
* new process comes in . Try to get rid of the random
* failures in the build farm .
*/
2010-09-16 21:36:37 +02:00
smb_msleep ( 200 ) ;
2006-08-05 08:21:31 +00:00
}
2004-11-09 09:26:47 +00:00
}
smb_raw_exit ( cli - > session ) ;
smbcli_deltree ( cli - > tree , BASEDIR ) ;
2005-01-27 07:08:20 +00:00
talloc_free ( mem_ctx ) ;
2004-11-09 09:26:47 +00:00
return ret ;
}