2001-06-19 06:02:19 +04:00
/*
2002-01-30 09:08:46 +03:00
Unix SMB / CIFS implementation .
2001-06-19 06:02:19 +04:00
SMB torture tester
Copyright ( C ) Andrew Tridgell 1997 - 1998
2009-10-21 04:41:27 +04:00
Copyright ( C ) Jeremy Allison 2009
2009-04-22 13:51:03 +04:00
2001-06-19 06:02:19 +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-09 23:25:36 +04:00
the Free Software Foundation ; either version 3 of the License , or
2001-06-19 06:02:19 +04:00
( at your option ) any later version .
2009-04-22 13:51:03 +04:00
2001-06-19 06:02:19 +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 .
2009-04-22 13:51:03 +04:00
2001-06-19 06:02:19 +04:00
You should have received a copy of the GNU General Public License
2007-07-10 04:52:41 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2001-06-19 06:02:19 +04:00
*/
# include "includes.h"
2009-04-16 16:53:36 +04:00
# include "nsswitch/libwbclient/wbc_async.h"
2009-11-24 13:43:56 +03:00
# include "torture/proto.h"
2010-01-23 16:55:11 +03:00
# include "libcli/security/dom_sid.h"
2010-05-18 04:17:44 +04:00
# include "tldap.h"
# include "tldap_util.h"
2001-06-19 06:02:19 +04:00
2005-05-02 21:49:43 +04:00
extern char * optarg ;
extern int optind ;
2001-06-19 06:02:19 +04:00
static fstring host , workgroup , share , password , username , myname ;
static int max_protocol = PROTOCOL_NT1 ;
2003-01-03 11:28:12 +03:00
static const char * sockops = " TCP_NODELAY " ;
2002-04-12 14:18:46 +04:00
static int nprocs = 1 ;
2003-04-01 20:48:18 +04:00
static int port_to_use = 0 ;
2002-04-12 14:18:46 +04:00
int torture_numops = 100 ;
2008-12-20 01:41:19 +03:00
int torture_blocksize = 1024 * 1024 ;
2001-06-19 06:02:19 +04:00
static int procnum ; /* records process count number when forking */
2003-04-18 07:35:39 +04:00
static struct cli_state * current_cli ;
2001-06-19 06:02:19 +04:00
static fstring randomfname ;
2007-10-19 04:40:25 +04:00
static bool use_oplocks ;
static bool use_level_II_oplocks ;
2003-01-03 11:28:12 +03:00
static const char * client_txt = " client_oplocks.txt " ;
2007-10-19 04:40:25 +04:00
static bool use_kerberos ;
2006-07-31 13:41:25 +04:00
static fstring multishare_conn_fname ;
2007-10-19 04:40:25 +04:00
static bool use_multishare_conn = False ;
2008-01-05 03:09:24 +03:00
static bool do_encrypt ;
2009-10-21 04:37:43 +04:00
static const char * local_path = NULL ;
2002-02-05 04:31:47 +03:00
2007-10-19 04:40:25 +04:00
bool torture_showall = False ;
2001-06-19 06:02:19 +04:00
2007-10-19 04:40:25 +04:00
static double create_procs ( bool ( * fn ) ( int ) , bool * result ) ;
2001-06-19 06:02:19 +04:00
/* return a pointer to a anonymous shared memory segment of size "size"
which will persist across fork ( ) but will disappear when all processes
exit
The memory is not zeroed
This function uses system5 shared memory . It takes advantage of a property
that the memory is not destroyed if it is attached when the id is removed
*/
2002-02-05 04:31:47 +03:00
void * shm_setup ( int size )
2001-06-19 06:02:19 +04:00
{
int shmid ;
void * ret ;
2009-09-17 01:23:16 +04:00
# ifdef __QNXNTO__
shmid = shm_open ( " private " , O_RDWR | O_CREAT | O_EXCL , S_IRUSR | S_IWUSR ) ;
if ( shmid = = - 1 ) {
printf ( " can't get shared memory \n " ) ;
exit ( 1 ) ;
}
shm_unlink ( " private " ) ;
if ( ftruncate ( shmid , size ) = = - 1 ) {
printf ( " can't set shared memory size \n " ) ;
exit ( 1 ) ;
}
ret = mmap ( 0 , size , PROT_READ | PROT_WRITE , MAP_SHARED , shmid , 0 ) ;
if ( ret = = MAP_FAILED ) {
printf ( " can't map shared memory \n " ) ;
exit ( 1 ) ;
}
# else
2004-12-19 03:31:31 +03:00
shmid = shmget ( IPC_PRIVATE , size , S_IRUSR | S_IWUSR ) ;
2001-06-19 06:02:19 +04:00
if ( shmid = = - 1 ) {
printf ( " can't get shared memory \n " ) ;
exit ( 1 ) ;
}
ret = ( void * ) shmat ( shmid , 0 , 0 ) ;
if ( ! ret | | ret = = ( void * ) - 1 ) {
printf ( " can't attach to shared memory \n " ) ;
return NULL ;
}
/* the following releases the ipc, but note that this process
and all its children will still have access to the memory , its
just that the shmid is no longer valid for other shm calls . This
means we don ' t leave behind lots of shm segments after we exit
See Stevens " advanced programming in unix env " for details
*/
shmctl ( shmid , IPC_RMID , 0 ) ;
2009-09-17 01:23:16 +04:00
# endif
2009-04-22 13:51:03 +04:00
2001-06-19 06:02:19 +04:00
return ret ;
}
2008-01-05 03:09:24 +03:00
/********************************************************************
Ensure a connection is encrypted .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static bool force_cli_encryption ( struct cli_state * c ,
const char * sharename )
{
uint16 major , minor ;
uint32 caplow , caphigh ;
NTSTATUS status ;
if ( ! SERVER_HAS_UNIX_CIFS ( c ) ) {
d_printf ( " Encryption required and "
" server that doesn't support "
" UNIX extensions - failing connect \n " ) ;
return false ;
}
2009-11-13 01:07:21 +03:00
status = cli_unix_extensions_version ( c , & major , & minor , & caplow ,
& caphigh ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2008-01-05 03:09:24 +03:00
d_printf ( " Encryption required and "
" can't get UNIX CIFS extensions "
2009-11-13 01:07:21 +03:00
" version from server: %s \n " , nt_errstr ( status ) ) ;
2008-01-05 03:09:24 +03:00
return false ;
}
if ( ! ( caplow & CIFS_UNIX_TRANSPORT_ENCRYPTION_CAP ) ) {
d_printf ( " Encryption required and "
" share %s doesn't support "
" encryption. \n " , sharename ) ;
return false ;
}
if ( c - > use_kerberos ) {
status = cli_gss_smb_encryption_start ( c ) ;
} else {
status = cli_raw_ntlm_smb_encryption_start ( c ,
username ,
password ,
workgroup ) ;
}
if ( ! NT_STATUS_IS_OK ( status ) ) {
d_printf ( " Encryption required and "
" setup failed with error %s. \n " ,
nt_errstr ( status ) ) ;
return false ;
}
return true ;
}
2001-06-19 06:02:19 +04:00
2006-07-11 22:01:26 +04:00
static struct cli_state * open_nbt_connection ( void )
2001-06-19 06:02:19 +04:00
{
struct nmb_name called , calling ;
2007-10-25 01:16:54 +04:00
struct sockaddr_storage ss ;
2006-07-11 22:01:26 +04:00
struct cli_state * c ;
2007-06-20 21:38:42 +04:00
NTSTATUS status ;
2001-06-19 06:02:19 +04:00
make_nmb_name ( & calling , myname , 0x0 ) ;
make_nmb_name ( & called , host , 0x20 ) ;
2008-12-03 10:29:57 +03:00
zero_sockaddr ( & ss ) ;
2001-06-19 06:02:19 +04:00
2006-07-11 22:01:26 +04:00
if ( ! ( c = cli_initialise ( ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " Failed initialize cli_struct to connect with %s \n " , host ) ;
2006-07-11 22:01:26 +04:00
return NULL ;
2003-04-18 07:35:39 +04:00
}
c - > port = port_to_use ;
2007-10-25 01:16:54 +04:00
status = cli_connect ( c , host , & ss ) ;
2007-06-20 21:38:42 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " Failed to connect with %s. Error %s \n " , host , nt_errstr ( status ) ) ;
2006-07-11 22:01:26 +04:00
return NULL ;
2001-06-19 06:02:19 +04:00
}
2002-03-04 03:24:24 +03:00
c - > use_kerberos = use_kerberos ;
2001-06-19 06:02:19 +04:00
c - > timeout = 120000 ; /* set a really long timeout (2 minutes) */
if ( use_oplocks ) c - > use_oplocks = True ;
if ( use_level_II_oplocks ) c - > use_level_II_oplocks = True ;
if ( ! cli_session_request ( c , & calling , & called ) ) {
2003-04-18 07:35:39 +04:00
/*
2007-10-25 01:16:54 +04:00
* Well , that failed , try * SMBSERVER . . .
2003-04-18 07:35:39 +04:00
* However , we must reconnect as well . . .
*/
2007-10-25 01:16:54 +04:00
status = cli_connect ( c , host , & ss ) ;
2007-06-20 21:38:42 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " Failed to connect with %s. Error %s \n " , host , nt_errstr ( status ) ) ;
2006-07-11 22:01:26 +04:00
return NULL ;
2003-04-18 07:35:39 +04:00
}
make_nmb_name ( & called , " *SMBSERVER " , 0x20 ) ;
if ( ! cli_session_request ( c , & calling , & called ) ) {
printf ( " %s rejected the session \n " , host ) ;
printf ( " We tried with a called name of %s & %s \n " ,
host , " *SMBSERVER " ) ;
cli_shutdown ( c ) ;
2006-07-11 22:01:26 +04:00
return NULL ;
2003-04-18 07:35:39 +04:00
}
2001-06-19 06:02:19 +04:00
}
2006-07-11 22:01:26 +04:00
return c ;
2001-06-19 06:02:19 +04:00
}
2006-07-31 13:41:25 +04:00
/* Insert a NULL at the first separator of the given path and return a pointer
* to the remainder of the string .
*/
static char *
terminate_path_at_separator ( char * path )
{
char * p ;
if ( ! path ) {
return NULL ;
}
if ( ( p = strchr_m ( path , ' / ' ) ) ) {
* p = ' \0 ' ;
return p + 1 ;
}
if ( ( p = strchr_m ( path , ' \\ ' ) ) ) {
* p = ' \0 ' ;
return p + 1 ;
}
2009-04-22 13:51:03 +04:00
2006-07-31 13:41:25 +04:00
/* No separator. */
return NULL ;
}
/*
parse a //server/share type UNC name
*/
2007-10-19 04:40:25 +04:00
bool smbcli_parse_unc ( const char * unc_name , TALLOC_CTX * mem_ctx ,
2006-07-31 13:41:25 +04:00
char * * hostname , char * * sharename )
{
char * p ;
* hostname = * sharename = NULL ;
if ( strncmp ( unc_name , " \\ \\ " , 2 ) & &
strncmp ( unc_name , " // " , 2 ) ) {
return False ;
}
* hostname = talloc_strdup ( mem_ctx , & unc_name [ 2 ] ) ;
p = terminate_path_at_separator ( * hostname ) ;
if ( p & & * p ) {
* sharename = talloc_strdup ( mem_ctx , p ) ;
terminate_path_at_separator ( * sharename ) ;
}
if ( * hostname & & * sharename ) {
return True ;
}
TALLOC_FREE ( * hostname ) ;
TALLOC_FREE ( * sharename ) ;
return False ;
}
2007-10-19 04:40:25 +04:00
static bool torture_open_connection_share ( struct cli_state * * c ,
2006-07-31 13:41:25 +04:00
const char * hostname ,
const char * sharename )
2001-06-19 06:02:19 +04:00
{
2007-10-19 04:40:25 +04:00
bool retry ;
2003-04-18 07:35:39 +04:00
int flags = 0 ;
NTSTATUS status ;
2001-06-19 06:02:19 +04:00
2003-04-18 07:35:39 +04:00
if ( use_kerberos )
flags | = CLI_FULL_CONNECTION_USE_KERBEROS ;
2009-04-06 22:45:08 +04:00
if ( use_oplocks )
flags | = CLI_FULL_CONNECTION_OPLOCKS ;
if ( use_level_II_oplocks )
flags | = CLI_FULL_CONNECTION_LEVEL_II_OPLOCKS ;
2006-07-31 13:41:25 +04:00
2003-04-18 07:35:39 +04:00
status = cli_full_connection ( c , myname ,
2006-07-31 13:41:25 +04:00
hostname , NULL , port_to_use ,
sharename , " ????? " ,
2003-04-18 07:35:39 +04:00
username , workgroup ,
2003-07-31 03:49:29 +04:00
password , flags , Undefined , & retry ) ;
2003-04-18 07:35:39 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2006-09-05 14:37:18 +04:00
printf ( " failed to open share connection: //%s/%s port:%d - %s \n " ,
hostname , sharename , port_to_use , nt_errstr ( status ) ) ;
2001-06-19 06:02:19 +04:00
return False ;
}
2003-04-18 07:35:39 +04:00
( * c ) - > timeout = 120000 ; /* set a really long timeout (2 minutes) */
2001-06-19 06:02:19 +04:00
2008-01-05 03:09:24 +03:00
if ( do_encrypt ) {
return force_cli_encryption ( * c ,
sharename ) ;
}
2003-04-18 07:35:39 +04:00
return True ;
}
2001-06-19 06:02:19 +04:00
2007-10-19 04:40:25 +04:00
bool torture_open_connection ( struct cli_state * * c , int conn_index )
2006-07-31 13:41:25 +04:00
{
char * * unc_list = NULL ;
int num_unc_names = 0 ;
2007-10-19 04:40:25 +04:00
bool result ;
2006-07-31 13:41:25 +04:00
if ( use_multishare_conn = = True ) {
char * h , * s ;
2008-10-12 20:29:36 +04:00
unc_list = file_lines_load ( multishare_conn_fname , & num_unc_names , 0 , NULL ) ;
2006-07-31 13:41:25 +04:00
if ( ! unc_list | | num_unc_names < = 0 ) {
printf ( " Failed to load unc names list from '%s' \n " , multishare_conn_fname ) ;
exit ( 1 ) ;
}
if ( ! smbcli_parse_unc ( unc_list [ conn_index % num_unc_names ] ,
NULL , & h , & s ) ) {
printf ( " Failed to parse UNC name %s \n " ,
unc_list [ conn_index % num_unc_names ] ) ;
2008-10-12 20:29:36 +04:00
TALLOC_FREE ( unc_list ) ;
2006-07-31 13:41:25 +04:00
exit ( 1 ) ;
}
result = torture_open_connection_share ( c , h , s ) ;
/* h, s were copied earlier */
2008-10-12 20:29:36 +04:00
TALLOC_FREE ( unc_list ) ;
2006-07-31 13:41:25 +04:00
return result ;
}
return torture_open_connection_share ( c , host , share ) ;
}
2007-10-19 04:40:25 +04:00
bool torture_cli_session_setup2 ( struct cli_state * cli , uint16 * new_vuid )
2003-04-18 07:35:39 +04:00
{
uint16 old_vuid = cli - > vuid ;
fstring old_user_name ;
size_t passlen = strlen ( password ) ;
2009-03-14 03:49:24 +03:00
NTSTATUS status ;
2007-10-19 04:40:25 +04:00
bool ret ;
2001-06-19 06:02:19 +04:00
2003-04-18 07:35:39 +04:00
fstrcpy ( old_user_name , cli - > user_name ) ;
cli - > vuid = 0 ;
2006-08-16 21:14:16 +04:00
ret = NT_STATUS_IS_OK ( cli_session_setup ( cli , username ,
password , passlen ,
password , passlen ,
workgroup ) ) ;
2003-04-18 07:35:39 +04:00
* new_vuid = cli - > vuid ;
cli - > vuid = old_vuid ;
2009-03-14 03:49:24 +03:00
status = cli_set_username ( cli , old_user_name ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return false ;
}
2003-04-18 07:35:39 +04:00
return ret ;
2001-06-19 06:02:19 +04:00
}
2007-10-19 04:40:25 +04:00
bool torture_close_connection ( struct cli_state * c )
2001-06-19 06:02:19 +04:00
{
2007-10-19 04:40:25 +04:00
bool ret = True ;
2010-01-03 20:46:57 +03:00
NTSTATUS status ;
status = cli_tdis ( c ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " tdis failed (%s) \n " , nt_errstr ( status ) ) ;
2001-07-02 07:21:17 +04:00
ret = False ;
2001-06-19 06:02:19 +04:00
}
2001-07-02 07:21:17 +04:00
cli_shutdown ( c ) ;
return ret ;
2001-06-19 06:02:19 +04:00
}
/* check if the server produced the expected error code */
2007-10-19 04:40:25 +04:00
static bool check_error ( int line , struct cli_state * c ,
2001-09-04 15:52:42 +04:00
uint8 eclass , uint32 ecode , NTSTATUS nterr )
2001-06-19 06:02:19 +04:00
{
2001-08-13 08:08:42 +04:00
if ( cli_is_dos_error ( c ) ) {
2005-06-25 13:07:42 +04:00
uint8 cclass ;
2001-08-13 08:08:42 +04:00
uint32 num ;
/* Check DOS error */
2005-06-25 13:07:42 +04:00
cli_dos_error ( c , & cclass , & num ) ;
2001-08-13 08:08:42 +04:00
2005-06-25 13:07:42 +04:00
if ( eclass ! = cclass | | ecode ! = num ) {
2001-08-13 08:08:42 +04:00
printf ( " unexpected error code class=%d code=%d \n " ,
2005-06-25 13:07:42 +04:00
( int ) cclass , ( int ) num ) ;
2001-09-04 15:52:42 +04:00
printf ( " expected %d/%d %s (line=%d) \n " ,
2002-03-17 07:36:35 +03:00
( int ) eclass , ( int ) ecode , nt_errstr ( nterr ) , line ) ;
2001-08-13 08:08:42 +04:00
return False ;
}
} else {
2001-08-27 23:46:22 +04:00
NTSTATUS status ;
2001-08-13 08:08:42 +04:00
/* Check NT error */
status = cli_nt_error ( c ) ;
2001-09-04 15:52:42 +04:00
if ( NT_STATUS_V ( nterr ) ! = NT_STATUS_V ( status ) ) {
2002-03-17 07:36:35 +03:00
printf ( " unexpected error code %s \n " , nt_errstr ( status ) ) ;
printf ( " expected %s (line=%d) \n " , nt_errstr ( nterr ) , line ) ;
2001-08-13 08:08:42 +04:00
return False ;
}
}
2001-06-19 06:02:19 +04:00
return True ;
}
2007-10-19 04:40:25 +04:00
static bool wait_lock ( struct cli_state * c , int fnum , uint32 offset , uint32 len )
2001-06-19 06:02:19 +04:00
{
while ( ! cli_lock ( c , fnum , offset , len , - 1 , WRITE_LOCK ) ) {
2001-08-20 09:15:26 +04:00
if ( ! check_error ( __LINE__ , c , ERRDOS , ERRlock , NT_STATUS_LOCK_NOT_GRANTED ) ) return False ;
2001-06-19 06:02:19 +04:00
}
return True ;
}
2007-10-19 04:40:25 +04:00
static bool rw_torture ( struct cli_state * c )
2001-06-19 06:02:19 +04:00
{
2003-01-03 11:28:12 +03:00
const char * lockfname = " \\ torture.lck " ;
2001-06-19 06:02:19 +04:00
fstring fname ;
2009-05-01 02:26:43 +04:00
uint16_t fnum ;
uint16_t fnum2 ;
2001-06-19 06:02:19 +04:00
pid_t pid2 , pid = getpid ( ) ;
int i , j ;
char buf [ 1024 ] ;
2007-10-19 04:40:25 +04:00
bool correct = True ;
2009-05-01 02:26:43 +04:00
NTSTATUS status ;
2001-06-19 06:02:19 +04:00
2007-03-23 22:12:08 +03:00
memset ( buf , ' \0 ' , sizeof ( buf ) ) ;
2009-05-01 02:26:43 +04:00
status = cli_open ( c , lockfname , O_RDWR | O_CREAT | O_EXCL ,
DENY_NONE , & fnum2 ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
status = cli_open ( c , lockfname , O_RDWR , DENY_NONE , & fnum2 ) ;
}
if ( ! NT_STATUS_IS_OK ( status ) ) {
2001-06-19 06:02:19 +04:00
printf ( " open of %s failed (%s) \n " , lockfname , cli_errstr ( c ) ) ;
return False ;
}
2002-04-12 14:18:46 +04:00
for ( i = 0 ; i < torture_numops ; i + + ) {
2001-06-19 06:02:19 +04:00
unsigned n = ( unsigned ) sys_random ( ) % 10 ;
if ( i % 10 = = 0 ) {
printf ( " %d \r " , i ) ; fflush ( stdout ) ;
}
slprintf ( fname , sizeof ( fstring ) - 1 , " \\ torture.%u " , n ) ;
if ( ! wait_lock ( c , fnum2 , n * sizeof ( int ) , sizeof ( int ) ) ) {
return False ;
}
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_open ( c , fname , O_RDWR | O_CREAT | O_TRUNC , DENY_ALL , & fnum ) ) ) {
2001-06-19 06:02:19 +04:00
printf ( " open failed (%s) \n " , cli_errstr ( c ) ) ;
2001-07-02 07:21:17 +04:00
correct = False ;
2001-06-19 06:02:19 +04:00
break ;
}
if ( cli_write ( c , fnum , 0 , ( char * ) & pid , 0 , sizeof ( pid ) ) ! = sizeof ( pid ) ) {
printf ( " write failed (%s) \n " , cli_errstr ( c ) ) ;
2001-07-02 07:21:17 +04:00
correct = False ;
2001-06-19 06:02:19 +04:00
}
for ( j = 0 ; j < 50 ; j + + ) {
if ( cli_write ( c , fnum , 0 , ( char * ) buf ,
sizeof ( pid ) + ( j * sizeof ( buf ) ) ,
sizeof ( buf ) ) ! = sizeof ( buf ) ) {
printf ( " write failed (%s) \n " , cli_errstr ( c ) ) ;
2001-07-02 07:21:17 +04:00
correct = False ;
2001-06-19 06:02:19 +04:00
}
}
pid2 = 0 ;
if ( cli_read ( c , fnum , ( char * ) & pid2 , 0 , sizeof ( pid ) ) ! = sizeof ( pid ) ) {
printf ( " read failed (%s) \n " , cli_errstr ( c ) ) ;
2001-07-02 07:21:17 +04:00
correct = False ;
2001-06-19 06:02:19 +04:00
}
if ( pid2 ! = pid ) {
printf ( " data corruption! \n " ) ;
2001-07-02 07:21:17 +04:00
correct = False ;
2001-06-19 06:02:19 +04:00
}
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( c , fnum ) ) ) {
2001-06-19 06:02:19 +04:00
printf ( " close failed (%s) \n " , cli_errstr ( c ) ) ;
2001-07-02 07:21:17 +04:00
correct = False ;
2001-06-19 06:02:19 +04:00
}
2009-04-30 05:26:02 +04:00
if ( ! NT_STATUS_IS_OK ( cli_unlink ( c , fname , aSYSTEM | aHIDDEN ) ) ) {
2001-06-19 06:02:19 +04:00
printf ( " unlink failed (%s) \n " , cli_errstr ( c ) ) ;
2001-07-02 07:21:17 +04:00
correct = False ;
2001-06-19 06:02:19 +04:00
}
2009-07-15 22:49:33 +04:00
if ( ! NT_STATUS_IS_OK ( cli_unlock ( c , fnum2 , n * sizeof ( int ) , sizeof ( int ) ) ) ) {
2001-06-19 06:02:19 +04:00
printf ( " unlock failed (%s) \n " , cli_errstr ( c ) ) ;
2001-07-02 07:21:17 +04:00
correct = False ;
2001-06-19 06:02:19 +04:00
}
}
cli_close ( c , fnum2 ) ;
2009-04-30 05:26:02 +04:00
cli_unlink ( c , lockfname , aSYSTEM | aHIDDEN ) ;
2001-06-19 06:02:19 +04:00
printf ( " %d \n " , i ) ;
2001-07-02 07:21:17 +04:00
return correct ;
2001-06-19 06:02:19 +04:00
}
2007-10-19 04:40:25 +04:00
static bool run_torture ( int dummy )
2001-06-19 06:02:19 +04:00
{
2003-04-18 07:35:39 +04:00
struct cli_state * cli ;
2007-10-19 04:40:25 +04:00
bool ret ;
2001-06-19 06:02:19 +04:00
cli = current_cli ;
2003-04-18 07:35:39 +04:00
cli_sockopt ( cli , sockops ) ;
2001-06-19 06:02:19 +04:00
2003-04-18 07:35:39 +04:00
ret = rw_torture ( cli ) ;
2009-04-22 13:51:03 +04:00
2003-04-18 07:35:39 +04:00
if ( ! torture_close_connection ( cli ) ) {
2001-07-02 07:21:17 +04:00
ret = False ;
}
return ret ;
2001-06-19 06:02:19 +04:00
}
2007-10-19 04:40:25 +04:00
static bool rw_torture3 ( struct cli_state * c , char * lockfname )
2001-06-19 06:02:19 +04:00
{
2009-05-01 02:26:43 +04:00
uint16_t fnum = ( uint16_t ) - 1 ;
2003-04-18 07:35:39 +04:00
unsigned int i = 0 ;
2001-06-19 06:02:19 +04:00
char buf [ 131072 ] ;
char buf_rd [ 131072 ] ;
unsigned count ;
unsigned countprev = 0 ;
2001-09-16 12:24:44 +04:00
ssize_t sent = 0 ;
2007-10-19 04:40:25 +04:00
bool correct = True ;
2009-05-01 02:26:43 +04:00
NTSTATUS status ;
2001-06-19 06:02:19 +04:00
srandom ( 1 ) ;
for ( i = 0 ; i < sizeof ( buf ) ; i + = sizeof ( uint32 ) )
{
SIVAL ( buf , i , sys_random ( ) ) ;
}
if ( procnum = = 0 )
{
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_open ( c , lockfname , O_RDWR | O_CREAT | O_EXCL ,
DENY_NONE , & fnum ) ) ) {
2001-06-19 06:02:19 +04:00
printf ( " first open read/write of %s failed (%s) \n " ,
lockfname , cli_errstr ( c ) ) ;
return False ;
}
}
else
{
2009-05-04 00:45:42 +04:00
for ( i = 0 ; i < 500 & & fnum = = ( uint16_t ) - 1 ; i + + )
2001-06-19 06:02:19 +04:00
{
2009-05-01 02:26:43 +04:00
status = cli_open ( c , lockfname , O_RDONLY ,
DENY_NONE , & fnum ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
break ;
}
2004-02-23 05:54:03 +03:00
smb_msleep ( 10 ) ;
2001-06-19 06:02:19 +04:00
}
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2001-06-19 06:02:19 +04:00
printf ( " second open read-only of %s failed (%s) \n " ,
lockfname , cli_errstr ( c ) ) ;
return False ;
}
}
i = 0 ;
for ( count = 0 ; count < sizeof ( buf ) ; count + = sent )
{
if ( count > = countprev ) {
printf ( " %d %8d \r " , i , count ) ;
fflush ( stdout ) ;
i + + ;
countprev + = ( sizeof ( buf ) / 20 ) ;
}
if ( procnum = = 0 )
{
sent = ( ( unsigned ) sys_random ( ) % ( 20 ) ) + 1 ;
if ( sent > sizeof ( buf ) - count )
{
sent = sizeof ( buf ) - count ;
}
2001-09-16 12:24:44 +04:00
if ( cli_write ( c , fnum , 0 , buf + count , count , ( size_t ) sent ) ! = sent ) {
2001-06-19 06:02:19 +04:00
printf ( " write failed (%s) \n " , cli_errstr ( c ) ) ;
2001-07-02 07:21:17 +04:00
correct = False ;
2001-06-19 06:02:19 +04:00
}
}
else
{
sent = cli_read ( c , fnum , buf_rd + count , count ,
sizeof ( buf ) - count ) ;
if ( sent < 0 )
{
2003-11-07 01:11:08 +03:00
printf ( " read failed offset:%d size:%ld (%s) \n " ,
count , ( unsigned long ) sizeof ( buf ) - count ,
cli_errstr ( c ) ) ;
2001-07-02 07:21:17 +04:00
correct = False ;
2001-06-19 06:02:19 +04:00
sent = 0 ;
}
if ( sent > 0 )
{
if ( memcmp ( buf_rd + count , buf + count , sent ) ! = 0 )
{
printf ( " read/write compare failed \n " ) ;
2003-11-07 01:11:08 +03:00
printf ( " offset: %d req %ld recvd %ld \n " , count , ( unsigned long ) sizeof ( buf ) - count , ( unsigned long ) sent ) ;
2001-07-02 07:21:17 +04:00
correct = False ;
2001-06-19 06:02:19 +04:00
break ;
}
}
}
}
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( c , fnum ) ) ) {
2001-06-19 06:02:19 +04:00
printf ( " close failed (%s) \n " , cli_errstr ( c ) ) ;
2001-07-02 07:21:17 +04:00
correct = False ;
2001-06-19 06:02:19 +04:00
}
2001-07-02 07:21:17 +04:00
return correct ;
2001-06-19 06:02:19 +04:00
}
2007-10-19 04:40:25 +04:00
static bool rw_torture2 ( struct cli_state * c1 , struct cli_state * c2 )
2001-06-19 06:02:19 +04:00
{
2003-01-03 11:28:12 +03:00
const char * lockfname = " \\ torture2.lck " ;
2009-05-01 02:26:43 +04:00
uint16_t fnum1 ;
uint16_t fnum2 ;
2001-06-19 06:02:19 +04:00
int i ;
2006-07-11 22:01:26 +04:00
char buf [ 131072 ] ;
char buf_rd [ 131072 ] ;
2007-10-19 04:40:25 +04:00
bool correct = True ;
2001-07-02 07:21:17 +04:00
ssize_t bytes_read ;
2001-06-19 06:02:19 +04:00
2009-04-30 05:26:02 +04:00
if ( ! NT_STATUS_IS_OK ( cli_unlink ( c1 , lockfname , aSYSTEM | aHIDDEN ) ) ) {
2001-07-02 07:21:17 +04:00
printf ( " unlink failed (%s) (normal, this file should not exist) \n " , cli_errstr ( c1 ) ) ;
2001-06-19 06:02:19 +04:00
}
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_open ( c1 , lockfname , O_RDWR | O_CREAT | O_EXCL ,
DENY_NONE , & fnum1 ) ) ) {
2001-06-19 06:02:19 +04:00
printf ( " first open read/write of %s failed (%s) \n " ,
lockfname , cli_errstr ( c1 ) ) ;
return False ;
}
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_open ( c2 , lockfname , O_RDONLY ,
DENY_NONE , & fnum2 ) ) ) {
2001-06-19 06:02:19 +04:00
printf ( " second open read-only of %s failed (%s) \n " ,
lockfname , cli_errstr ( c2 ) ) ;
cli_close ( c1 , fnum1 ) ;
return False ;
}
2002-04-12 14:18:46 +04:00
for ( i = 0 ; i < torture_numops ; i + + )
2001-06-19 06:02:19 +04:00
{
2001-07-02 07:21:17 +04:00
size_t buf_size = ( ( unsigned ) sys_random ( ) % ( sizeof ( buf ) - 1 ) ) + 1 ;
2001-06-19 06:02:19 +04:00
if ( i % 10 = = 0 ) {
printf ( " %d \r " , i ) ; fflush ( stdout ) ;
}
2006-07-11 22:01:26 +04:00
generate_random_buffer ( ( unsigned char * ) buf , buf_size ) ;
2001-06-19 06:02:19 +04:00
if ( cli_write ( c1 , fnum1 , 0 , buf , 0 , buf_size ) ! = buf_size ) {
printf ( " write failed (%s) \n " , cli_errstr ( c1 ) ) ;
2001-07-02 07:21:17 +04:00
correct = False ;
2003-04-23 12:12:34 +04:00
break ;
2001-06-19 06:02:19 +04:00
}
2001-07-02 07:21:17 +04:00
if ( ( bytes_read = cli_read ( c2 , fnum2 , buf_rd , 0 , buf_size ) ) ! = buf_size ) {
2001-06-19 06:02:19 +04:00
printf ( " read failed (%s) \n " , cli_errstr ( c2 ) ) ;
2006-07-12 01:23:44 +04:00
printf ( " read %d, expected %ld \n " , ( int ) bytes_read ,
2003-11-07 01:11:08 +03:00
( unsigned long ) buf_size ) ;
2001-07-02 07:21:17 +04:00
correct = False ;
2003-04-23 12:12:34 +04:00
break ;
2001-06-19 06:02:19 +04:00
}
if ( memcmp ( buf_rd , buf , buf_size ) ! = 0 )
{
printf ( " read/write compare failed \n " ) ;
2001-07-02 07:21:17 +04:00
correct = False ;
2003-04-23 12:12:34 +04:00
break ;
2001-06-19 06:02:19 +04:00
}
}
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( c2 , fnum2 ) ) ) {
2001-06-19 06:02:19 +04:00
printf ( " close failed (%s) \n " , cli_errstr ( c2 ) ) ;
2001-07-02 07:21:17 +04:00
correct = False ;
2001-06-19 06:02:19 +04:00
}
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( c1 , fnum1 ) ) ) {
2001-06-19 06:02:19 +04:00
printf ( " close failed (%s) \n " , cli_errstr ( c1 ) ) ;
2001-07-02 07:21:17 +04:00
correct = False ;
2001-06-19 06:02:19 +04:00
}
2009-04-30 05:26:02 +04:00
if ( ! NT_STATUS_IS_OK ( cli_unlink ( c1 , lockfname , aSYSTEM | aHIDDEN ) ) ) {
2001-06-19 06:02:19 +04:00
printf ( " unlink failed (%s) \n " , cli_errstr ( c1 ) ) ;
2001-07-02 07:21:17 +04:00
correct = False ;
2001-06-19 06:02:19 +04:00
}
2001-07-02 07:21:17 +04:00
return correct ;
2001-06-19 06:02:19 +04:00
}
2007-10-19 04:40:25 +04:00
static bool run_readwritetest ( int dummy )
2001-06-19 06:02:19 +04:00
{
2009-07-02 13:06:21 +04:00
struct cli_state * cli1 , * cli2 ;
2007-10-19 04:40:25 +04:00
bool test1 , test2 = False ;
2001-06-19 06:02:19 +04:00
2006-07-31 13:41:25 +04:00
if ( ! torture_open_connection ( & cli1 , 0 ) | | ! torture_open_connection ( & cli2 , 1 ) ) {
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2003-04-18 07:35:39 +04:00
cli_sockopt ( cli1 , sockops ) ;
cli_sockopt ( cli2 , sockops ) ;
2001-06-19 06:02:19 +04:00
printf ( " starting readwritetest \n " ) ;
2003-04-18 07:35:39 +04:00
test1 = rw_torture2 ( cli1 , cli2 ) ;
2001-07-02 07:21:17 +04:00
printf ( " Passed readwritetest v1: %s \n " , BOOLSTR ( test1 ) ) ;
2001-06-19 06:02:19 +04:00
2003-04-23 12:12:34 +04:00
if ( test1 ) {
test2 = rw_torture2 ( cli1 , cli1 ) ;
printf ( " Passed readwritetest v2: %s \n " , BOOLSTR ( test2 ) ) ;
}
2001-06-19 06:02:19 +04:00
2003-04-18 07:35:39 +04:00
if ( ! torture_close_connection ( cli1 ) ) {
2001-07-02 07:21:17 +04:00
test1 = False ;
}
2003-04-18 07:35:39 +04:00
if ( ! torture_close_connection ( cli2 ) ) {
2001-07-02 07:21:17 +04:00
test2 = False ;
}
return ( test1 & & test2 ) ;
2001-06-19 06:02:19 +04:00
}
2007-10-19 04:40:25 +04:00
static bool run_readwritemulti ( int dummy )
2001-06-19 06:02:19 +04:00
{
2003-04-18 07:35:39 +04:00
struct cli_state * cli ;
2007-10-19 04:40:25 +04:00
bool test ;
2001-06-19 06:02:19 +04:00
cli = current_cli ;
2003-04-23 12:12:34 +04:00
cli_sockopt ( cli , sockops ) ;
2001-06-19 06:02:19 +04:00
printf ( " run_readwritemulti: fname %s \n " , randomfname ) ;
2003-04-23 12:12:34 +04:00
test = rw_torture3 ( cli , randomfname ) ;
2001-06-19 06:02:19 +04:00
2003-04-23 12:12:34 +04:00
if ( ! torture_close_connection ( cli ) ) {
2001-07-02 07:21:17 +04:00
test = False ;
}
2009-04-22 13:51:03 +04:00
2001-07-02 07:21:17 +04:00
return test ;
2001-06-19 06:02:19 +04:00
}
2007-10-19 04:40:25 +04:00
static bool run_readwritelarge ( int dummy )
2001-06-19 06:02:19 +04:00
{
2003-04-18 07:35:39 +04:00
static struct cli_state * cli1 ;
2009-05-01 02:26:43 +04:00
uint16_t fnum1 ;
2003-01-03 11:28:12 +03:00
const char * lockfname = " \\ large.dat " ;
2005-03-23 00:17:01 +03:00
SMB_OFF_T fsize ;
2002-03-20 04:47:31 +03:00
char buf [ 126 * 1024 ] ;
2007-10-19 04:40:25 +04:00
bool correct = True ;
2009-04-22 13:51:03 +04:00
2006-07-31 13:41:25 +04:00
if ( ! torture_open_connection ( & cli1 , 0 ) ) {
2001-07-02 07:21:17 +04:00
return False ;
}
2003-04-18 07:35:39 +04:00
cli_sockopt ( cli1 , sockops ) ;
2001-06-19 06:02:19 +04:00
memset ( buf , ' \0 ' , sizeof ( buf ) ) ;
2009-04-22 13:51:03 +04:00
2003-04-18 07:35:39 +04:00
cli1 - > max_xmit = 128 * 1024 ;
2009-04-22 13:51:03 +04:00
2001-07-02 07:21:17 +04:00
printf ( " starting readwritelarge \n " ) ;
2009-04-22 13:51:03 +04:00
2009-04-30 05:26:02 +04:00
cli_unlink ( cli1 , lockfname , aSYSTEM | aHIDDEN ) ;
2001-06-19 06:02:19 +04:00
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_open ( cli1 , lockfname , O_RDWR | O_CREAT | O_EXCL , DENY_NONE , & fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " open read/write of %s failed (%s) \n " , lockfname , cli_errstr ( cli1 ) ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2009-04-22 13:51:03 +04:00
2003-04-18 07:35:39 +04:00
cli_write ( cli1 , fnum1 , 0 , buf , 0 , sizeof ( buf ) ) ;
2001-06-19 06:02:19 +04:00
2003-04-18 07:35:39 +04:00
if ( ! cli_qfileinfo ( cli1 , fnum1 , NULL , & fsize , NULL , NULL , NULL , NULL , NULL ) ) {
printf ( " qfileinfo failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2001-07-02 07:21:17 +04:00
correct = False ;
2001-06-19 06:02:19 +04:00
}
if ( fsize = = sizeof ( buf ) )
2003-11-07 01:11:08 +03:00
printf ( " readwritelarge test 1 succeeded (size = %lx) \n " ,
( unsigned long ) fsize ) ;
2001-07-02 07:21:17 +04:00
else {
2003-11-07 01:11:08 +03:00
printf ( " readwritelarge test 1 failed (size = %lx) \n " ,
( unsigned long ) fsize ) ;
2001-07-07 10:21:32 +04:00
correct = False ;
2001-07-02 07:21:17 +04:00
}
2001-06-19 06:02:19 +04:00
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli1 , fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " close failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2002-03-20 04:47:31 +03:00
correct = False ;
}
2009-04-30 05:26:02 +04:00
if ( ! NT_STATUS_IS_OK ( cli_unlink ( cli1 , lockfname , aSYSTEM | aHIDDEN ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " unlink failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2001-07-02 07:21:17 +04:00
correct = False ;
2001-06-19 06:02:19 +04:00
}
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_open ( cli1 , lockfname , O_RDWR | O_CREAT | O_EXCL , DENY_NONE , & fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " open read/write of %s failed (%s) \n " , lockfname , cli_errstr ( cli1 ) ) ;
2001-07-07 10:21:32 +04:00
return False ;
}
2009-04-22 13:51:03 +04:00
2003-04-18 07:35:39 +04:00
cli1 - > max_xmit = 4 * 1024 ;
2009-04-22 13:51:03 +04:00
2003-04-18 07:35:39 +04:00
cli_smbwrite ( cli1 , fnum1 , buf , 0 , sizeof ( buf ) ) ;
2009-04-22 13:51:03 +04:00
2003-04-18 07:35:39 +04:00
if ( ! cli_qfileinfo ( cli1 , fnum1 , NULL , & fsize , NULL , NULL , NULL , NULL , NULL ) ) {
printf ( " qfileinfo failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2002-03-20 04:47:31 +03:00
correct = False ;
}
if ( fsize = = sizeof ( buf ) )
2003-11-07 01:11:08 +03:00
printf ( " readwritelarge test 2 succeeded (size = %lx) \n " ,
( unsigned long ) fsize ) ;
2002-03-20 04:47:31 +03:00
else {
2003-11-07 01:11:08 +03:00
printf ( " readwritelarge test 2 failed (size = %lx) \n " ,
( unsigned long ) fsize ) ;
2002-03-20 04:47:31 +03:00
correct = False ;
}
2002-03-23 05:57:44 +03:00
#if 0
/* ToDo - set allocation. JRA */
2003-04-18 07:35:39 +04:00
if ( ! cli_set_allocation_size ( cli1 , fnum1 , 0 ) ) {
2002-03-23 05:57:44 +03:00
printf ( " set allocation size to zero failed (%s) \n " , cli_errstr ( & cli1 ) ) ;
return False ;
}
2003-04-18 07:35:39 +04:00
if ( ! cli_qfileinfo ( cli1 , fnum1 , NULL , & fsize , NULL , NULL , NULL , NULL , NULL ) ) {
printf ( " qfileinfo failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2002-03-23 05:57:44 +03:00
correct = False ;
}
if ( fsize ! = 0 )
printf ( " readwritelarge test 3 (truncate test) succeeded (size = %x) \n " , fsize ) ;
# endif
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli1 , fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " close failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2001-07-07 10:21:32 +04:00
correct = False ;
}
2009-04-22 13:51:03 +04:00
2003-04-18 07:35:39 +04:00
if ( ! torture_close_connection ( cli1 ) ) {
2001-07-02 07:21:17 +04:00
correct = False ;
}
return correct ;
2003-04-18 07:35:39 +04:00
}
2001-06-19 06:02:19 +04:00
int line_count = 0 ;
2002-02-05 04:31:47 +03:00
int nbio_id ;
# define ival(s) strtol(s, NULL, 0)
2001-06-19 06:02:19 +04:00
/* run a test that simulates an approximate netbench client load */
2007-10-19 04:40:25 +04:00
static bool run_netbench ( int client )
2001-06-19 06:02:19 +04:00
{
2003-04-18 07:35:39 +04:00
struct cli_state * cli ;
2001-06-19 06:02:19 +04:00
int i ;
2007-12-05 04:05:33 +03:00
char line [ 1024 ] ;
2001-06-19 06:02:19 +04:00
char cname [ 20 ] ;
FILE * f ;
2003-04-23 12:12:34 +04:00
const char * params [ 20 ] ;
2007-10-19 04:40:25 +04:00
bool correct = True ;
2001-06-19 06:02:19 +04:00
cli = current_cli ;
2002-02-05 04:31:47 +03:00
nbio_id = client ;
2003-04-18 07:35:39 +04:00
cli_sockopt ( cli , sockops ) ;
2001-06-19 06:02:19 +04:00
2003-04-18 07:35:39 +04:00
nb_setup ( cli ) ;
2001-06-19 06:02:19 +04:00
2005-07-20 17:43:38 +04:00
slprintf ( cname , sizeof ( cname ) - 1 , " client%d " , client ) ;
2001-06-19 06:02:19 +04:00
2002-02-05 04:31:47 +03:00
f = fopen ( client_txt , " r " ) ;
2001-06-19 06:02:19 +04:00
if ( ! f ) {
2002-02-05 04:31:47 +03:00
perror ( client_txt ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
while ( fgets ( line , sizeof ( line ) - 1 , f ) ) {
2008-01-23 13:04:10 +03:00
char * saveptr ;
2001-06-19 06:02:19 +04:00
line_count + + ;
line [ strlen ( line ) - 1 ] = 0 ;
/* printf("[%d] %s\n", line_count, line); */
2002-02-05 04:31:47 +03:00
all_string_sub ( line , " client1 " , cname , sizeof ( line ) ) ;
2007-12-05 04:05:33 +03:00
2001-06-19 06:02:19 +04:00
/* parse the command parameters */
2008-01-23 13:04:10 +03:00
params [ 0 ] = strtok_r ( line , " " , & saveptr ) ;
2001-06-19 06:02:19 +04:00
i = 0 ;
2008-01-23 13:04:10 +03:00
while ( params [ i ] ) params [ + + i ] = strtok_r ( NULL , " " , & saveptr ) ;
2001-06-19 06:02:19 +04:00
params [ i ] = " " ;
if ( i < 2 ) continue ;
2002-02-05 04:31:47 +03:00
if ( ! strncmp ( params [ 0 ] , " SMB " , 3 ) ) {
printf ( " ERROR: You are using a dbench 1 load file \n " ) ;
exit ( 1 ) ;
}
if ( ! strcmp ( params [ 0 ] , " NTCreateX " ) ) {
nb_createx ( params [ 1 ] , ival ( params [ 2 ] ) , ival ( params [ 3 ] ) ,
ival ( params [ 4 ] ) ) ;
} else if ( ! strcmp ( params [ 0 ] , " Close " ) ) {
nb_close ( ival ( params [ 1 ] ) ) ;
} else if ( ! strcmp ( params [ 0 ] , " Rename " ) ) {
nb_rename ( params [ 1 ] , params [ 2 ] ) ;
} else if ( ! strcmp ( params [ 0 ] , " Unlink " ) ) {
nb_unlink ( params [ 1 ] ) ;
} else if ( ! strcmp ( params [ 0 ] , " Deltree " ) ) {
nb_deltree ( params [ 1 ] ) ;
} else if ( ! strcmp ( params [ 0 ] , " Rmdir " ) ) {
nb_rmdir ( params [ 1 ] ) ;
} else if ( ! strcmp ( params [ 0 ] , " QUERY_PATH_INFORMATION " ) ) {
nb_qpathinfo ( params [ 1 ] ) ;
} else if ( ! strcmp ( params [ 0 ] , " QUERY_FILE_INFORMATION " ) ) {
nb_qfileinfo ( ival ( params [ 1 ] ) ) ;
} else if ( ! strcmp ( params [ 0 ] , " QUERY_FS_INFORMATION " ) ) {
nb_qfsinfo ( ival ( params [ 1 ] ) ) ;
} else if ( ! strcmp ( params [ 0 ] , " FIND_FIRST " ) ) {
nb_findfirst ( params [ 1 ] ) ;
} else if ( ! strcmp ( params [ 0 ] , " WriteX " ) ) {
nb_writex ( ival ( params [ 1 ] ) ,
ival ( params [ 2 ] ) , ival ( params [ 3 ] ) , ival ( params [ 4 ] ) ) ;
} else if ( ! strcmp ( params [ 0 ] , " ReadX " ) ) {
nb_readx ( ival ( params [ 1 ] ) ,
ival ( params [ 2 ] ) , ival ( params [ 3 ] ) , ival ( params [ 4 ] ) ) ;
} else if ( ! strcmp ( params [ 0 ] , " Flush " ) ) {
nb_flush ( ival ( params [ 1 ] ) ) ;
2001-06-19 06:02:19 +04:00
} else {
2002-02-05 04:31:47 +03:00
printf ( " Unknown operation %s \n " , params [ 0 ] ) ;
exit ( 1 ) ;
2001-06-19 06:02:19 +04:00
}
}
fclose ( f ) ;
2002-02-05 06:55:20 +03:00
nb_cleanup ( ) ;
2001-06-19 06:02:19 +04:00
2003-04-18 07:35:39 +04:00
if ( ! torture_close_connection ( cli ) ) {
2001-07-02 07:21:17 +04:00
correct = False ;
}
2009-04-22 13:51:03 +04:00
2001-07-02 07:21:17 +04:00
return correct ;
2001-06-19 06:02:19 +04:00
}
2002-02-05 04:31:47 +03:00
/* run a test that simulates an approximate netbench client load */
2007-10-19 04:40:25 +04:00
static bool run_nbench ( int dummy )
2001-06-19 06:02:19 +04:00
{
double t ;
2007-10-19 04:40:25 +04:00
bool correct = True ;
2001-06-19 06:02:19 +04:00
2002-02-05 04:31:47 +03:00
nbio_shmem ( nprocs ) ;
nbio_id = - 1 ;
signal ( SIGALRM , nb_alarm ) ;
alarm ( 1 ) ;
2001-07-02 07:21:17 +04:00
t = create_procs ( run_netbench , & correct ) ;
2002-02-05 04:31:47 +03:00
alarm ( 0 ) ;
printf ( " \n Throughput %g MB/sec \n " ,
1.0e-6 * nbio_total ( ) / t ) ;
2001-07-02 07:21:17 +04:00
return correct ;
2001-06-19 06:02:19 +04:00
}
/*
This test checks for two things :
1 ) correct support for retaining locks over a close ( ie . the server
must not use posix semantics )
2 ) support for lock timeouts
*/
2007-10-19 04:40:25 +04:00
static bool run_locktest1 ( int dummy )
2001-06-19 06:02:19 +04:00
{
2003-04-18 07:35:39 +04:00
struct cli_state * cli1 , * cli2 ;
2003-01-03 11:28:12 +03:00
const char * fname = " \\ lockt1.lck " ;
2009-05-01 02:26:43 +04:00
uint16_t fnum1 , fnum2 , fnum3 ;
2001-06-19 06:02:19 +04:00
time_t t1 , t2 ;
2002-09-25 19:19:00 +04:00
unsigned lock_timeout ;
2001-06-19 06:02:19 +04:00
2006-07-31 13:41:25 +04:00
if ( ! torture_open_connection ( & cli1 , 0 ) | | ! torture_open_connection ( & cli2 , 1 ) ) {
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2003-04-18 07:35:39 +04:00
cli_sockopt ( cli1 , sockops ) ;
cli_sockopt ( cli2 , sockops ) ;
2001-06-19 06:02:19 +04:00
printf ( " starting locktest1 \n " ) ;
2009-04-30 05:26:02 +04:00
cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ;
2001-06-19 06:02:19 +04:00
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_open ( cli1 , fname , O_RDWR | O_CREAT | O_EXCL , DENY_NONE , & fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " open of %s failed (%s) \n " , fname , cli_errstr ( cli1 ) ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_open ( cli1 , fname , O_RDWR , DENY_NONE , & fnum2 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " open2 of %s failed (%s) \n " , fname , cli_errstr ( cli1 ) ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_open ( cli2 , fname , O_RDWR , DENY_NONE , & fnum3 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " open3 of %s failed (%s) \n " , fname , cli_errstr ( cli2 ) ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2003-04-18 07:35:39 +04:00
if ( ! cli_lock ( cli1 , fnum1 , 0 , 4 , 0 , WRITE_LOCK ) ) {
printf ( " lock1 failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2003-04-18 07:35:39 +04:00
if ( cli_lock ( cli2 , fnum3 , 0 , 4 , 0 , WRITE_LOCK ) ) {
2001-06-19 06:02:19 +04:00
printf ( " lock2 succeeded! This is a locking bug \n " ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
} else {
2003-04-18 07:35:39 +04:00
if ( ! check_error ( __LINE__ , cli2 , ERRDOS , ERRlock ,
2001-08-20 09:15:26 +04:00
NT_STATUS_LOCK_NOT_GRANTED ) ) return False ;
2001-06-19 06:02:19 +04:00
}
2002-09-25 19:19:00 +04:00
lock_timeout = ( 1 + ( random ( ) % 20 ) ) ;
printf ( " Testing lock timeout with timeout=%u \n " , lock_timeout ) ;
2001-06-19 06:02:19 +04:00
t1 = time ( NULL ) ;
2004-12-08 20:30:50 +03:00
if ( cli_lock ( cli2 , fnum3 , 0 , 4 , lock_timeout * 1000 , WRITE_LOCK ) ) {
2001-06-19 06:02:19 +04:00
printf ( " lock3 succeeded! This is a locking bug \n " ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
} else {
2003-04-18 07:35:39 +04:00
if ( ! check_error ( __LINE__ , cli2 , ERRDOS , ERRlock ,
2002-03-06 21:55:01 +03:00
NT_STATUS_FILE_LOCK_CONFLICT ) ) return False ;
2001-06-19 06:02:19 +04:00
}
t2 = time ( NULL ) ;
2003-06-10 18:01:57 +04:00
if ( ABS ( t2 - t1 ) < lock_timeout - 1 ) {
2001-06-19 06:02:19 +04:00
printf ( " error: This server appears not to support timed lock requests \n " ) ;
}
2003-06-10 18:01:57 +04:00
2002-09-25 19:19:00 +04:00
printf ( " server slept for %u seconds for a %u second timeout \n " ,
( unsigned int ) ( t2 - t1 ) , lock_timeout ) ;
2001-06-19 06:02:19 +04:00
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli1 , fnum2 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " close1 failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2003-04-18 07:35:39 +04:00
if ( cli_lock ( cli2 , fnum3 , 0 , 4 , 0 , WRITE_LOCK ) ) {
2001-06-19 06:02:19 +04:00
printf ( " lock4 succeeded! This is a locking bug \n " ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
} else {
2003-04-18 07:35:39 +04:00
if ( ! check_error ( __LINE__ , cli2 , ERRDOS , ERRlock ,
2002-03-06 21:55:01 +03:00
NT_STATUS_FILE_LOCK_CONFLICT ) ) return False ;
2001-06-19 06:02:19 +04:00
}
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli1 , fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " close2 failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli2 , fnum3 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " close3 failed (%s) \n " , cli_errstr ( cli2 ) ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2009-04-30 05:26:02 +04:00
if ( ! NT_STATUS_IS_OK ( cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " unlink failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2003-04-18 07:35:39 +04:00
if ( ! torture_close_connection ( cli1 ) ) {
2001-07-02 07:21:17 +04:00
return False ;
}
2003-04-18 07:35:39 +04:00
if ( ! torture_close_connection ( cli2 ) ) {
2001-07-02 07:21:17 +04:00
return False ;
}
2001-06-19 06:02:19 +04:00
printf ( " Passed locktest1 \n " ) ;
2001-07-02 07:21:17 +04:00
return True ;
2001-06-19 06:02:19 +04:00
}
/*
2003-04-18 07:35:39 +04:00
this checks to see if a secondary tconx can use open files from an
earlier tconx
2001-06-19 06:02:19 +04:00
*/
2007-10-19 04:40:25 +04:00
static bool run_tcon_test ( int dummy )
2001-06-19 06:02:19 +04:00
{
2003-04-18 07:35:39 +04:00
static struct cli_state * cli ;
2003-01-03 11:28:12 +03:00
const char * fname = " \\ tcontest.tmp " ;
2009-05-01 02:26:43 +04:00
uint16 fnum1 ;
2003-04-18 07:35:39 +04:00
uint16 cnum1 , cnum2 , cnum3 ;
uint16 vuid1 , vuid2 ;
2001-06-19 06:02:19 +04:00
char buf [ 4 ] ;
2007-10-19 04:40:25 +04:00
bool ret = True ;
2009-01-26 10:37:13 +03:00
NTSTATUS status ;
2001-06-19 06:02:19 +04:00
2007-03-25 06:17:05 +04:00
memset ( buf , ' \0 ' , sizeof ( buf ) ) ;
2006-07-31 13:41:25 +04:00
if ( ! torture_open_connection ( & cli , 0 ) ) {
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2003-04-18 07:35:39 +04:00
cli_sockopt ( cli , sockops ) ;
2001-06-19 06:02:19 +04:00
printf ( " starting tcontest \n " ) ;
2009-04-30 05:26:02 +04:00
cli_unlink ( cli , fname , aSYSTEM | aHIDDEN ) ;
2001-06-19 06:02:19 +04:00
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_open ( cli , fname , O_RDWR | O_CREAT | O_EXCL , DENY_NONE , & fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " open of %s failed (%s) \n " , fname , cli_errstr ( cli ) ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2003-04-18 07:35:39 +04:00
cnum1 = cli - > cnum ;
vuid1 = cli - > vuid ;
2001-06-19 06:02:19 +04:00
2003-04-18 07:35:39 +04:00
if ( cli_write ( cli , fnum1 , 0 , buf , 130 , 4 ) ! = 4 ) {
printf ( " initial write failed (%s) " , cli_errstr ( cli ) ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2009-01-26 10:37:13 +03:00
status = cli_tcon_andx ( cli , share , " ????? " ,
password , strlen ( password ) + 1 ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2001-06-19 06:02:19 +04:00
printf ( " %s refused 2nd tree connect (%s) \n " , host ,
2009-01-26 10:37:13 +03:00
nt_errstr ( status ) ) ;
2003-04-18 07:35:39 +04:00
cli_shutdown ( cli ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2003-04-18 07:35:39 +04:00
cnum2 = cli - > cnum ;
cnum3 = MAX ( cnum1 , cnum2 ) + 1 ; /* any invalid number */
vuid2 = cli - > vuid + 1 ;
/* try a write with the wrong tid */
cli - > cnum = cnum2 ;
if ( cli_write ( cli , fnum1 , 0 , buf , 130 , 4 ) = = 4 ) {
printf ( " * server allows write with wrong TID \n " ) ;
ret = False ;
} else {
printf ( " server fails write with wrong TID : %s \n " , cli_errstr ( cli ) ) ;
}
/* try a write with an invalid tid */
cli - > cnum = cnum3 ;
if ( cli_write ( cli , fnum1 , 0 , buf , 130 , 4 ) = = 4 ) {
printf ( " * server allows write with invalid TID \n " ) ;
ret = False ;
} else {
printf ( " server fails write with invalid TID : %s \n " , cli_errstr ( cli ) ) ;
}
/* try a write with an invalid vuid */
cli - > vuid = vuid2 ;
cli - > cnum = cnum1 ;
if ( cli_write ( cli , fnum1 , 0 , buf , 130 , 4 ) = = 4 ) {
printf ( " * server allows write with invalid VUID \n " ) ;
ret = False ;
} else {
printf ( " server fails write with invalid VUID : %s \n " , cli_errstr ( cli ) ) ;
}
cli - > cnum = cnum1 ;
cli - > vuid = vuid1 ;
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli , fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " close failed (%s) \n " , cli_errstr ( cli ) ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2003-04-18 07:35:39 +04:00
cli - > cnum = cnum2 ;
2010-01-03 20:46:57 +03:00
status = cli_tdis ( cli ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " secondary tdis failed (%s) \n " , nt_errstr ( status ) ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2003-04-18 07:35:39 +04:00
cli - > cnum = cnum1 ;
if ( ! torture_close_connection ( cli ) ) {
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2003-04-18 07:35:39 +04:00
return ret ;
}
2001-06-19 06:02:19 +04:00
2003-04-18 07:35:39 +04:00
/*
checks for old style tcon support
*/
2007-10-19 04:40:25 +04:00
static bool run_tcon2_test ( int dummy )
2003-04-18 07:35:39 +04:00
{
static struct cli_state * cli ;
uint16 cnum , max_xmit ;
char * service ;
NTSTATUS status ;
2006-07-31 13:41:25 +04:00
if ( ! torture_open_connection ( & cli , 0 ) ) {
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2003-04-18 07:35:39 +04:00
cli_sockopt ( cli , sockops ) ;
printf ( " starting tcon2 test \n " ) ;
2009-01-02 22:38:24 +03:00
if ( asprintf ( & service , " \\ \\ %s \\ %s " , host , share ) = = - 1 ) {
return false ;
}
2003-04-18 07:35:39 +04:00
status = cli_raw_tcon ( cli , service , password , " ????? " , & max_xmit , & cnum ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " tcon2 failed : %s \n " , cli_errstr ( cli ) ) ;
} else {
printf ( " tcon OK : max_xmit=%d cnum=%d tid=%d \n " ,
( int ) max_xmit , ( int ) cnum , SVAL ( cli - > inbuf , smb_tid ) ) ;
}
2001-06-19 06:02:19 +04:00
2003-04-18 07:35:39 +04:00
if ( ! torture_close_connection ( cli ) ) {
2001-07-02 07:21:17 +04:00
return False ;
}
2001-06-19 06:02:19 +04:00
2003-04-18 07:35:39 +04:00
printf ( " Passed tcon2 test \n " ) ;
2001-07-02 07:21:17 +04:00
return True ;
2001-06-19 06:02:19 +04:00
}
2007-10-19 04:40:25 +04:00
static bool tcon_devtest ( struct cli_state * cli ,
2003-03-30 20:37:10 +04:00
const char * myshare , const char * devtype ,
2003-04-23 13:26:07 +04:00
const char * return_devtype ,
2003-03-30 20:37:10 +04:00
NTSTATUS expected_error )
{
2009-01-26 10:37:13 +03:00
NTSTATUS status ;
2007-10-19 04:40:25 +04:00
bool ret ;
2003-03-30 20:37:10 +04:00
2009-01-26 10:37:13 +03:00
status = cli_tcon_andx ( cli , myshare , devtype ,
password , strlen ( password ) + 1 ) ;
2003-03-30 20:37:10 +04:00
if ( NT_STATUS_IS_OK ( expected_error ) ) {
2009-01-26 10:37:13 +03:00
if ( NT_STATUS_IS_OK ( status ) ) {
2003-04-23 13:26:07 +04:00
if ( strcmp ( cli - > dev , return_devtype ) = = 0 ) {
ret = True ;
} else {
printf ( " tconX to share %s with type %s "
" succeeded but returned the wrong "
" device type (got [%s] but should have got [%s]) \n " ,
myshare , devtype , cli - > dev , return_devtype ) ;
ret = False ;
}
2003-03-30 20:37:10 +04:00
} else {
printf ( " tconX to share %s with type %s "
" should have succeeded but failed \n " ,
myshare , devtype ) ;
ret = False ;
}
cli_tdis ( cli ) ;
} else {
2009-01-26 10:37:13 +03:00
if ( NT_STATUS_IS_OK ( status ) ) {
2003-03-30 20:37:10 +04:00
printf ( " tconx to share %s with type %s "
" should have failed but succeeded \n " ,
myshare , devtype ) ;
ret = False ;
} else {
if ( NT_STATUS_EQUAL ( cli_nt_error ( cli ) ,
expected_error ) ) {
ret = True ;
} else {
printf ( " Returned unexpected error \n " ) ;
ret = False ;
}
}
}
return ret ;
}
/*
checks for correct tconX support
*/
2007-10-19 04:40:25 +04:00
static bool run_tcon_devtype_test ( int dummy )
2003-03-30 20:37:10 +04:00
{
static struct cli_state * cli1 = NULL ;
2007-10-19 04:40:25 +04:00
bool retry ;
2003-03-30 20:37:10 +04:00
int flags = 0 ;
NTSTATUS status ;
2007-10-19 04:40:25 +04:00
bool ret = True ;
2003-03-30 20:37:10 +04:00
status = cli_full_connection ( & cli1 , myname ,
host , NULL , port_to_use ,
NULL , NULL ,
username , workgroup ,
2003-07-31 03:49:29 +04:00
password , flags , Undefined , & retry ) ;
2003-03-30 20:37:10 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " could not open connection \n " ) ;
return False ;
}
2003-04-23 13:26:07 +04:00
if ( ! tcon_devtest ( cli1 , " IPC$ " , " A: " , NULL , NT_STATUS_BAD_DEVICE_TYPE ) )
2003-03-30 20:37:10 +04:00
ret = False ;
2003-04-23 13:26:07 +04:00
if ( ! tcon_devtest ( cli1 , " IPC$ " , " ????? " , " IPC " , NT_STATUS_OK ) )
2003-03-30 20:37:10 +04:00
ret = False ;
2003-04-23 13:26:07 +04:00
if ( ! tcon_devtest ( cli1 , " IPC$ " , " LPT: " , NULL , NT_STATUS_BAD_DEVICE_TYPE ) )
2003-03-30 20:37:10 +04:00
ret = False ;
2003-04-23 13:26:07 +04:00
if ( ! tcon_devtest ( cli1 , " IPC$ " , " IPC " , " IPC " , NT_STATUS_OK ) )
2003-03-30 20:37:10 +04:00
ret = False ;
2009-04-22 13:51:03 +04:00
2003-04-23 13:26:07 +04:00
if ( ! tcon_devtest ( cli1 , " IPC$ " , " FOOBA " , NULL , NT_STATUS_BAD_DEVICE_TYPE ) )
2003-03-30 20:37:10 +04:00
ret = False ;
2003-04-23 13:26:07 +04:00
if ( ! tcon_devtest ( cli1 , share , " A: " , " A: " , NT_STATUS_OK ) )
2003-03-30 20:37:10 +04:00
ret = False ;
2003-04-23 13:26:07 +04:00
if ( ! tcon_devtest ( cli1 , share , " ????? " , " A: " , NT_STATUS_OK ) )
2003-03-30 20:37:10 +04:00
ret = False ;
2003-04-23 13:26:07 +04:00
if ( ! tcon_devtest ( cli1 , share , " LPT: " , NULL , NT_STATUS_BAD_DEVICE_TYPE ) )
2003-03-30 20:37:10 +04:00
ret = False ;
2003-04-23 13:26:07 +04:00
if ( ! tcon_devtest ( cli1 , share , " IPC " , NULL , NT_STATUS_BAD_DEVICE_TYPE ) )
2003-03-30 20:37:10 +04:00
ret = False ;
2009-04-22 13:51:03 +04:00
2003-04-23 13:26:07 +04:00
if ( ! tcon_devtest ( cli1 , share , " FOOBA " , NULL , NT_STATUS_BAD_DEVICE_TYPE ) )
2003-03-30 20:37:10 +04:00
ret = False ;
cli_shutdown ( cli1 ) ;
if ( ret )
printf ( " Passed tcondevtest \n " ) ;
return ret ;
}
2001-06-19 06:02:19 +04:00
/*
This test checks that
1 ) the server supports multiple locking contexts on the one SMB
connection , distinguished by PID .
2 ) the server correctly fails overlapping locks made by the same PID ( this
goes against POSIX behaviour , which is why it is tricky to implement )
3 ) the server denies unlock requests by an incorrect client PID
*/
2007-10-19 04:40:25 +04:00
static bool run_locktest2 ( int dummy )
2001-06-19 06:02:19 +04:00
{
2003-04-18 07:35:39 +04:00
static struct cli_state * cli ;
2003-01-03 11:28:12 +03:00
const char * fname = " \\ lockt2.lck " ;
2009-05-01 02:26:43 +04:00
uint16_t fnum1 , fnum2 , fnum3 ;
2007-10-19 04:40:25 +04:00
bool correct = True ;
2001-06-19 06:02:19 +04:00
2006-07-31 13:41:25 +04:00
if ( ! torture_open_connection ( & cli , 0 ) ) {
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2003-04-18 07:35:39 +04:00
cli_sockopt ( cli , sockops ) ;
2001-06-19 06:02:19 +04:00
printf ( " starting locktest2 \n " ) ;
2009-04-30 05:26:02 +04:00
cli_unlink ( cli , fname , aSYSTEM | aHIDDEN ) ;
2001-06-19 06:02:19 +04:00
2003-04-18 07:35:39 +04:00
cli_setpid ( cli , 1 ) ;
2001-06-19 06:02:19 +04:00
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_open ( cli , fname , O_RDWR | O_CREAT | O_EXCL , DENY_NONE , & fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " open of %s failed (%s) \n " , fname , cli_errstr ( cli ) ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_open ( cli , fname , O_RDWR , DENY_NONE , & fnum2 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " open2 of %s failed (%s) \n " , fname , cli_errstr ( cli ) ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2003-04-18 07:35:39 +04:00
cli_setpid ( cli , 2 ) ;
2001-06-19 06:02:19 +04:00
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_open ( cli , fname , O_RDWR , DENY_NONE , & fnum3 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " open3 of %s failed (%s) \n " , fname , cli_errstr ( cli ) ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2003-04-18 07:35:39 +04:00
cli_setpid ( cli , 1 ) ;
2001-06-19 06:02:19 +04:00
2003-04-18 07:35:39 +04:00
if ( ! cli_lock ( cli , fnum1 , 0 , 4 , 0 , WRITE_LOCK ) ) {
printf ( " lock1 failed (%s) \n " , cli_errstr ( cli ) ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2003-04-18 07:35:39 +04:00
if ( cli_lock ( cli , fnum1 , 0 , 4 , 0 , WRITE_LOCK ) ) {
2001-06-19 06:02:19 +04:00
printf ( " WRITE lock1 succeeded! This is a locking bug \n " ) ;
2001-07-02 07:21:17 +04:00
correct = False ;
2001-06-19 06:02:19 +04:00
} else {
2003-04-18 07:35:39 +04:00
if ( ! check_error ( __LINE__ , cli , ERRDOS , ERRlock ,
2001-08-20 09:15:26 +04:00
NT_STATUS_LOCK_NOT_GRANTED ) ) return False ;
2001-06-19 06:02:19 +04:00
}
2003-04-18 07:35:39 +04:00
if ( cli_lock ( cli , fnum2 , 0 , 4 , 0 , WRITE_LOCK ) ) {
2001-06-19 06:02:19 +04:00
printf ( " WRITE lock2 succeeded! This is a locking bug \n " ) ;
2001-07-02 07:21:17 +04:00
correct = False ;
2001-06-19 06:02:19 +04:00
} else {
2003-04-18 07:35:39 +04:00
if ( ! check_error ( __LINE__ , cli , ERRDOS , ERRlock ,
2001-08-20 09:15:26 +04:00
NT_STATUS_LOCK_NOT_GRANTED ) ) return False ;
2001-06-19 06:02:19 +04:00
}
2003-04-18 07:35:39 +04:00
if ( cli_lock ( cli , fnum2 , 0 , 4 , 0 , READ_LOCK ) ) {
2001-06-19 06:02:19 +04:00
printf ( " READ lock2 succeeded! This is a locking bug \n " ) ;
2001-07-02 07:21:17 +04:00
correct = False ;
2001-06-19 06:02:19 +04:00
} else {
2003-04-18 07:35:39 +04:00
if ( ! check_error ( __LINE__ , cli , ERRDOS , ERRlock ,
2002-03-06 21:55:01 +03:00
NT_STATUS_FILE_LOCK_CONFLICT ) ) return False ;
2001-06-19 06:02:19 +04:00
}
2003-04-18 07:35:39 +04:00
if ( ! cli_lock ( cli , fnum1 , 100 , 4 , 0 , WRITE_LOCK ) ) {
printf ( " lock at 100 failed (%s) \n " , cli_errstr ( cli ) ) ;
2001-07-07 10:21:32 +04:00
}
2003-04-18 07:35:39 +04:00
cli_setpid ( cli , 2 ) ;
2009-07-15 22:49:33 +04:00
if ( NT_STATUS_IS_OK ( cli_unlock ( cli , fnum1 , 100 , 4 ) ) ) {
2001-07-07 10:21:32 +04:00
printf ( " unlock at 100 succeeded! This is a locking bug \n " ) ;
correct = False ;
}
2001-06-19 06:02:19 +04:00
2009-07-15 22:49:33 +04:00
if ( NT_STATUS_IS_OK ( cli_unlock ( cli , fnum1 , 0 , 4 ) ) ) {
2001-07-02 07:21:17 +04:00
printf ( " unlock1 succeeded! This is a locking bug \n " ) ;
correct = False ;
2001-07-07 10:21:32 +04:00
} else {
2003-04-18 07:35:39 +04:00
if ( ! check_error ( __LINE__ , cli ,
2001-09-06 05:21:09 +04:00
ERRDOS , ERRlock ,
2002-03-06 21:55:01 +03:00
NT_STATUS_RANGE_NOT_LOCKED ) ) return False ;
2001-07-07 10:21:32 +04:00
}
2009-07-15 22:49:33 +04:00
if ( NT_STATUS_IS_OK ( cli_unlock ( cli , fnum1 , 0 , 8 ) ) ) {
2001-07-07 10:21:32 +04:00
printf ( " unlock2 succeeded! This is a locking bug \n " ) ;
correct = False ;
} else {
2003-04-18 07:35:39 +04:00
if ( ! check_error ( __LINE__ , cli ,
2001-09-06 05:21:09 +04:00
ERRDOS , ERRlock ,
2002-03-06 21:55:01 +03:00
NT_STATUS_RANGE_NOT_LOCKED ) ) return False ;
2001-06-19 06:02:19 +04:00
}
2003-04-18 07:35:39 +04:00
if ( cli_lock ( cli , fnum3 , 0 , 4 , 0 , WRITE_LOCK ) ) {
2001-06-19 06:02:19 +04:00
printf ( " lock3 succeeded! This is a locking bug \n " ) ;
2001-07-02 07:21:17 +04:00
correct = False ;
2001-06-19 06:02:19 +04:00
} else {
2003-04-18 07:35:39 +04:00
if ( ! check_error ( __LINE__ , cli , ERRDOS , ERRlock , NT_STATUS_LOCK_NOT_GRANTED ) ) return False ;
2001-06-19 06:02:19 +04:00
}
2003-04-18 07:35:39 +04:00
cli_setpid ( cli , 1 ) ;
2001-06-19 06:02:19 +04:00
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli , fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " close1 failed (%s) \n " , cli_errstr ( cli ) ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli , fnum2 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " close2 failed (%s) \n " , cli_errstr ( cli ) ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli , fnum3 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " close3 failed (%s) \n " , cli_errstr ( cli ) ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2003-04-18 07:35:39 +04:00
if ( ! torture_close_connection ( cli ) ) {
2001-07-02 07:21:17 +04:00
correct = False ;
}
2001-06-19 06:02:19 +04:00
printf ( " locktest2 finished \n " ) ;
2001-07-02 07:21:17 +04:00
return correct ;
2001-06-19 06:02:19 +04:00
}
/*
This test checks that
1 ) the server supports the full offset range in lock requests
*/
2007-10-19 04:40:25 +04:00
static bool run_locktest3 ( int dummy )
2001-06-19 06:02:19 +04:00
{
2003-04-18 07:35:39 +04:00
static struct cli_state * cli1 , * cli2 ;
2003-01-03 11:28:12 +03:00
const char * fname = " \\ lockt3.lck " ;
2009-05-01 02:26:43 +04:00
uint16_t fnum1 , fnum2 ;
int i ;
2001-06-19 06:02:19 +04:00
uint32 offset ;
2007-10-19 04:40:25 +04:00
bool correct = True ;
2001-06-19 06:02:19 +04:00
2002-04-12 14:18:46 +04:00
# define NEXT_OFFSET offset += (~(uint32)0) / torture_numops
2001-06-19 06:02:19 +04:00
2006-07-31 13:41:25 +04:00
if ( ! torture_open_connection ( & cli1 , 0 ) | | ! torture_open_connection ( & cli2 , 1 ) ) {
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2003-04-18 07:35:39 +04:00
cli_sockopt ( cli1 , sockops ) ;
cli_sockopt ( cli2 , sockops ) ;
2001-06-19 06:02:19 +04:00
printf ( " starting locktest3 \n " ) ;
2009-04-30 05:26:02 +04:00
cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ;
2001-06-19 06:02:19 +04:00
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_open ( cli1 , fname , O_RDWR | O_CREAT | O_EXCL , DENY_NONE , & fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " open of %s failed (%s) \n " , fname , cli_errstr ( cli1 ) ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_open ( cli2 , fname , O_RDWR , DENY_NONE , & fnum2 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " open2 of %s failed (%s) \n " , fname , cli_errstr ( cli2 ) ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2002-04-12 14:18:46 +04:00
for ( offset = i = 0 ; i < torture_numops ; i + + ) {
2001-06-19 06:02:19 +04:00
NEXT_OFFSET ;
2003-04-18 07:35:39 +04:00
if ( ! cli_lock ( cli1 , fnum1 , offset - 1 , 1 , 0 , WRITE_LOCK ) ) {
2001-06-19 06:02:19 +04:00
printf ( " lock1 %d failed (%s) \n " ,
i ,
2003-04-18 07:35:39 +04:00
cli_errstr ( cli1 ) ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2003-04-18 07:35:39 +04:00
if ( ! cli_lock ( cli2 , fnum2 , offset - 2 , 1 , 0 , WRITE_LOCK ) ) {
2001-06-19 06:02:19 +04:00
printf ( " lock2 %d failed (%s) \n " ,
i ,
2003-04-18 07:35:39 +04:00
cli_errstr ( cli1 ) ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
}
2002-04-12 14:18:46 +04:00
for ( offset = i = 0 ; i < torture_numops ; i + + ) {
2001-06-19 06:02:19 +04:00
NEXT_OFFSET ;
2003-04-18 07:35:39 +04:00
if ( cli_lock ( cli1 , fnum1 , offset - 2 , 1 , 0 , WRITE_LOCK ) ) {
2001-06-19 06:02:19 +04:00
printf ( " error: lock1 %d succeeded! \n " , i ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2003-04-18 07:35:39 +04:00
if ( cli_lock ( cli2 , fnum2 , offset - 1 , 1 , 0 , WRITE_LOCK ) ) {
2001-06-19 06:02:19 +04:00
printf ( " error: lock2 %d succeeded! \n " , i ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2003-04-18 07:35:39 +04:00
if ( cli_lock ( cli1 , fnum1 , offset - 1 , 1 , 0 , WRITE_LOCK ) ) {
2001-06-19 06:02:19 +04:00
printf ( " error: lock3 %d succeeded! \n " , i ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2003-04-18 07:35:39 +04:00
if ( cli_lock ( cli2 , fnum2 , offset - 2 , 1 , 0 , WRITE_LOCK ) ) {
2001-06-19 06:02:19 +04:00
printf ( " error: lock4 %d succeeded! \n " , i ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
}
2002-04-12 14:18:46 +04:00
for ( offset = i = 0 ; i < torture_numops ; i + + ) {
2001-06-19 06:02:19 +04:00
NEXT_OFFSET ;
2009-07-15 22:49:33 +04:00
if ( ! NT_STATUS_IS_OK ( cli_unlock ( cli1 , fnum1 , offset - 1 , 1 ) ) ) {
2001-06-19 06:02:19 +04:00
printf ( " unlock1 %d failed (%s) \n " ,
i ,
2003-04-18 07:35:39 +04:00
cli_errstr ( cli1 ) ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2009-07-15 22:49:33 +04:00
if ( ! NT_STATUS_IS_OK ( cli_unlock ( cli2 , fnum2 , offset - 2 , 1 ) ) ) {
2001-06-19 06:02:19 +04:00
printf ( " unlock2 %d failed (%s) \n " ,
i ,
2003-04-18 07:35:39 +04:00
cli_errstr ( cli1 ) ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
}
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli1 , fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " close1 failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli2 , fnum2 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " close2 failed (%s) \n " , cli_errstr ( cli2 ) ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2009-04-30 05:26:02 +04:00
if ( ! NT_STATUS_IS_OK ( cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " unlink failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2003-04-18 07:35:39 +04:00
if ( ! torture_close_connection ( cli1 ) ) {
2001-07-02 07:21:17 +04:00
correct = False ;
}
2009-04-22 13:51:03 +04:00
2003-04-18 07:35:39 +04:00
if ( ! torture_close_connection ( cli2 ) ) {
2001-07-02 07:21:17 +04:00
correct = False ;
}
2001-06-19 06:02:19 +04:00
printf ( " finished locktest3 \n " ) ;
2001-07-02 07:21:17 +04:00
return correct ;
2001-06-19 06:02:19 +04:00
}
2001-07-02 07:21:17 +04:00
# define EXPECTED(ret, v) if ((ret) != (v)) { \
printf ( " ** " ) ; correct = False ; \
}
2001-06-19 06:02:19 +04:00
/*
looks at overlapping locks
*/
2007-10-19 04:40:25 +04:00
static bool run_locktest4 ( int dummy )
2001-06-19 06:02:19 +04:00
{
2003-04-18 07:35:39 +04:00
static struct cli_state * cli1 , * cli2 ;
2003-01-03 11:28:12 +03:00
const char * fname = " \\ lockt4.lck " ;
2009-05-01 02:26:43 +04:00
uint16_t fnum1 , fnum2 , f ;
2007-10-19 04:40:25 +04:00
bool ret ;
2001-06-19 06:02:19 +04:00
char buf [ 1000 ] ;
2007-10-19 04:40:25 +04:00
bool correct = True ;
2001-06-19 06:02:19 +04:00
2006-07-31 13:41:25 +04:00
if ( ! torture_open_connection ( & cli1 , 0 ) | | ! torture_open_connection ( & cli2 , 1 ) ) {
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2003-04-18 07:35:39 +04:00
cli_sockopt ( cli1 , sockops ) ;
cli_sockopt ( cli2 , sockops ) ;
2001-06-19 06:02:19 +04:00
printf ( " starting locktest4 \n " ) ;
2009-04-30 05:26:02 +04:00
cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ;
2001-06-19 06:02:19 +04:00
2009-05-01 02:26:43 +04:00
cli_open ( cli1 , fname , O_RDWR | O_CREAT | O_EXCL , DENY_NONE , & fnum1 ) ;
cli_open ( cli2 , fname , O_RDWR , DENY_NONE , & fnum2 ) ;
2001-06-19 06:02:19 +04:00
memset ( buf , 0 , sizeof ( buf ) ) ;
2003-04-18 07:35:39 +04:00
if ( cli_write ( cli1 , fnum1 , 0 , buf , 0 , sizeof ( buf ) ) ! = sizeof ( buf ) ) {
2001-06-19 06:02:19 +04:00
printf ( " Failed to create file \n " ) ;
2001-07-02 07:21:17 +04:00
correct = False ;
2001-06-19 06:02:19 +04:00
goto fail ;
}
2003-04-18 07:35:39 +04:00
ret = cli_lock ( cli1 , fnum1 , 0 , 4 , 0 , WRITE_LOCK ) & &
cli_lock ( cli1 , fnum1 , 2 , 4 , 0 , WRITE_LOCK ) ;
2001-06-19 06:02:19 +04:00
EXPECTED ( ret , False ) ;
printf ( " the same process %s set overlapping write locks \n " , ret ? " can " : " cannot " ) ;
2009-04-22 13:51:03 +04:00
2003-04-18 07:35:39 +04:00
ret = cli_lock ( cli1 , fnum1 , 10 , 4 , 0 , READ_LOCK ) & &
cli_lock ( cli1 , fnum1 , 12 , 4 , 0 , READ_LOCK ) ;
2001-06-19 06:02:19 +04:00
EXPECTED ( ret , True ) ;
printf ( " the same process %s set overlapping read locks \n " , ret ? " can " : " cannot " ) ;
2003-04-18 07:35:39 +04:00
ret = cli_lock ( cli1 , fnum1 , 20 , 4 , 0 , WRITE_LOCK ) & &
cli_lock ( cli2 , fnum2 , 22 , 4 , 0 , WRITE_LOCK ) ;
2001-06-19 06:02:19 +04:00
EXPECTED ( ret , False ) ;
printf ( " a different connection %s set overlapping write locks \n " , ret ? " can " : " cannot " ) ;
2009-04-22 13:51:03 +04:00
2003-04-18 07:35:39 +04:00
ret = cli_lock ( cli1 , fnum1 , 30 , 4 , 0 , READ_LOCK ) & &
cli_lock ( cli2 , fnum2 , 32 , 4 , 0 , READ_LOCK ) ;
2001-06-19 06:02:19 +04:00
EXPECTED ( ret , True ) ;
printf ( " a different connection %s set overlapping read locks \n " , ret ? " can " : " cannot " ) ;
2009-04-22 13:51:03 +04:00
2003-04-18 07:35:39 +04:00
ret = ( cli_setpid ( cli1 , 1 ) , cli_lock ( cli1 , fnum1 , 40 , 4 , 0 , WRITE_LOCK ) ) & &
( cli_setpid ( cli1 , 2 ) , cli_lock ( cli1 , fnum1 , 42 , 4 , 0 , WRITE_LOCK ) ) ;
2001-06-19 06:02:19 +04:00
EXPECTED ( ret , False ) ;
printf ( " a different pid %s set overlapping write locks \n " , ret ? " can " : " cannot " ) ;
2009-04-22 13:51:03 +04:00
2003-04-18 07:35:39 +04:00
ret = ( cli_setpid ( cli1 , 1 ) , cli_lock ( cli1 , fnum1 , 50 , 4 , 0 , READ_LOCK ) ) & &
( cli_setpid ( cli1 , 2 ) , cli_lock ( cli1 , fnum1 , 52 , 4 , 0 , READ_LOCK ) ) ;
2001-06-19 06:02:19 +04:00
EXPECTED ( ret , True ) ;
printf ( " a different pid %s set overlapping read locks \n " , ret ? " can " : " cannot " ) ;
2003-04-18 07:35:39 +04:00
ret = cli_lock ( cli1 , fnum1 , 60 , 4 , 0 , READ_LOCK ) & &
cli_lock ( cli1 , fnum1 , 60 , 4 , 0 , READ_LOCK ) ;
2001-06-19 06:02:19 +04:00
EXPECTED ( ret , True ) ;
printf ( " the same process %s set the same read lock twice \n " , ret ? " can " : " cannot " ) ;
2003-04-18 07:35:39 +04:00
ret = cli_lock ( cli1 , fnum1 , 70 , 4 , 0 , WRITE_LOCK ) & &
cli_lock ( cli1 , fnum1 , 70 , 4 , 0 , WRITE_LOCK ) ;
2001-06-19 06:02:19 +04:00
EXPECTED ( ret , False ) ;
printf ( " the same process %s set the same write lock twice \n " , ret ? " can " : " cannot " ) ;
2003-04-18 07:35:39 +04:00
ret = cli_lock ( cli1 , fnum1 , 80 , 4 , 0 , READ_LOCK ) & &
cli_lock ( cli1 , fnum1 , 80 , 4 , 0 , WRITE_LOCK ) ;
2001-06-19 06:02:19 +04:00
EXPECTED ( ret , False ) ;
printf ( " the same process %s overlay a read lock with a write lock \n " , ret ? " can " : " cannot " ) ;
2003-04-18 07:35:39 +04:00
ret = cli_lock ( cli1 , fnum1 , 90 , 4 , 0 , WRITE_LOCK ) & &
cli_lock ( cli1 , fnum1 , 90 , 4 , 0 , READ_LOCK ) ;
2001-06-19 06:02:19 +04:00
EXPECTED ( ret , True ) ;
printf ( " the same process %s overlay a write lock with a read lock \n " , ret ? " can " : " cannot " ) ;
2003-04-18 07:35:39 +04:00
ret = ( cli_setpid ( cli1 , 1 ) , cli_lock ( cli1 , fnum1 , 100 , 4 , 0 , WRITE_LOCK ) ) & &
( cli_setpid ( cli1 , 2 ) , cli_lock ( cli1 , fnum1 , 100 , 4 , 0 , READ_LOCK ) ) ;
2001-06-19 06:02:19 +04:00
EXPECTED ( ret , False ) ;
printf ( " a different pid %s overlay a write lock with a read lock \n " , ret ? " can " : " cannot " ) ;
2003-04-18 07:35:39 +04:00
ret = cli_lock ( cli1 , fnum1 , 110 , 4 , 0 , READ_LOCK ) & &
cli_lock ( cli1 , fnum1 , 112 , 4 , 0 , READ_LOCK ) & &
2009-07-15 22:49:33 +04:00
NT_STATUS_IS_OK ( cli_unlock ( cli1 , fnum1 , 110 , 6 ) ) ;
2001-06-19 06:02:19 +04:00
EXPECTED ( ret , False ) ;
printf ( " the same process %s coalesce read locks \n " , ret ? " can " : " cannot " ) ;
2003-04-18 07:35:39 +04:00
ret = cli_lock ( cli1 , fnum1 , 120 , 4 , 0 , WRITE_LOCK ) & &
( cli_read ( cli2 , fnum2 , buf , 120 , 4 ) = = 4 ) ;
2001-06-19 06:02:19 +04:00
EXPECTED ( ret , False ) ;
printf ( " this server %s strict write locking \n " , ret ? " doesn't do " : " does " ) ;
2003-04-18 07:35:39 +04:00
ret = cli_lock ( cli1 , fnum1 , 130 , 4 , 0 , READ_LOCK ) & &
( cli_write ( cli2 , fnum2 , 0 , buf , 130 , 4 ) = = 4 ) ;
2001-06-19 06:02:19 +04:00
EXPECTED ( ret , False ) ;
printf ( " this server %s strict read locking \n " , ret ? " doesn't do " : " does " ) ;
2003-04-18 07:35:39 +04:00
ret = cli_lock ( cli1 , fnum1 , 140 , 4 , 0 , READ_LOCK ) & &
cli_lock ( cli1 , fnum1 , 140 , 4 , 0 , READ_LOCK ) & &
2009-07-15 22:49:33 +04:00
NT_STATUS_IS_OK ( cli_unlock ( cli1 , fnum1 , 140 , 4 ) ) & &
NT_STATUS_IS_OK ( cli_unlock ( cli1 , fnum1 , 140 , 4 ) ) ;
2001-06-19 06:02:19 +04:00
EXPECTED ( ret , True ) ;
printf ( " this server %s do recursive read locking \n " , ret ? " does " : " doesn't " ) ;
2003-04-18 07:35:39 +04:00
ret = cli_lock ( cli1 , fnum1 , 150 , 4 , 0 , WRITE_LOCK ) & &
cli_lock ( cli1 , fnum1 , 150 , 4 , 0 , READ_LOCK ) & &
2009-07-15 22:49:33 +04:00
NT_STATUS_IS_OK ( cli_unlock ( cli1 , fnum1 , 150 , 4 ) ) & &
2003-04-18 07:35:39 +04:00
( cli_read ( cli2 , fnum2 , buf , 150 , 4 ) = = 4 ) & &
! ( cli_write ( cli2 , fnum2 , 0 , buf , 150 , 4 ) = = 4 ) & &
2009-07-15 22:49:33 +04:00
NT_STATUS_IS_OK ( cli_unlock ( cli1 , fnum1 , 150 , 4 ) ) ;
2001-06-19 06:02:19 +04:00
EXPECTED ( ret , True ) ;
printf ( " this server %s do recursive lock overlays \n " , ret ? " does " : " doesn't " ) ;
2003-04-18 07:35:39 +04:00
ret = cli_lock ( cli1 , fnum1 , 160 , 4 , 0 , READ_LOCK ) & &
2009-07-15 22:49:33 +04:00
NT_STATUS_IS_OK ( cli_unlock ( cli1 , fnum1 , 160 , 4 ) ) & &
2003-04-18 07:35:39 +04:00
( cli_write ( cli2 , fnum2 , 0 , buf , 160 , 4 ) = = 4 ) & &
( cli_read ( cli2 , fnum2 , buf , 160 , 4 ) = = 4 ) ;
2001-06-19 06:02:19 +04:00
EXPECTED ( ret , True ) ;
printf ( " the same process %s remove a read lock using write locking \n " , ret ? " can " : " cannot " ) ;
2003-04-18 07:35:39 +04:00
ret = cli_lock ( cli1 , fnum1 , 170 , 4 , 0 , WRITE_LOCK ) & &
2009-07-15 22:49:33 +04:00
NT_STATUS_IS_OK ( cli_unlock ( cli1 , fnum1 , 170 , 4 ) ) & &
2003-04-18 07:35:39 +04:00
( cli_write ( cli2 , fnum2 , 0 , buf , 170 , 4 ) = = 4 ) & &
( cli_read ( cli2 , fnum2 , buf , 170 , 4 ) = = 4 ) ;
2001-06-19 06:02:19 +04:00
EXPECTED ( ret , True ) ;
printf ( " the same process %s remove a write lock using read locking \n " , ret ? " can " : " cannot " ) ;
2003-04-18 07:35:39 +04:00
ret = cli_lock ( cli1 , fnum1 , 190 , 4 , 0 , WRITE_LOCK ) & &
cli_lock ( cli1 , fnum1 , 190 , 4 , 0 , READ_LOCK ) & &
2009-07-15 22:49:33 +04:00
NT_STATUS_IS_OK ( cli_unlock ( cli1 , fnum1 , 190 , 4 ) ) & &
2003-04-18 07:35:39 +04:00
! ( cli_write ( cli2 , fnum2 , 0 , buf , 190 , 4 ) = = 4 ) & &
( cli_read ( cli2 , fnum2 , buf , 190 , 4 ) = = 4 ) ;
2001-06-19 06:02:19 +04:00
EXPECTED ( ret , True ) ;
printf ( " the same process %s remove the first lock first \n " , ret ? " does " : " doesn't " ) ;
2003-04-18 07:35:39 +04:00
cli_close ( cli1 , fnum1 ) ;
cli_close ( cli2 , fnum2 ) ;
2009-05-01 02:26:43 +04:00
cli_open ( cli1 , fname , O_RDWR , DENY_NONE , & fnum1 ) ;
cli_open ( cli1 , fname , O_RDWR , DENY_NONE , & f ) ;
2003-04-18 07:35:39 +04:00
ret = cli_lock ( cli1 , fnum1 , 0 , 8 , 0 , READ_LOCK ) & &
cli_lock ( cli1 , f , 0 , 1 , 0 , READ_LOCK ) & &
2009-05-01 03:57:42 +04:00
NT_STATUS_IS_OK ( cli_close ( cli1 , fnum1 ) ) & &
NT_STATUS_IS_OK ( cli_open ( cli1 , fname , O_RDWR , DENY_NONE , & fnum1 ) ) & &
2003-04-18 07:35:39 +04:00
cli_lock ( cli1 , fnum1 , 7 , 1 , 0 , WRITE_LOCK ) ;
cli_close ( cli1 , f ) ;
cli_close ( cli1 , fnum1 ) ;
2001-06-19 06:02:19 +04:00
EXPECTED ( ret , True ) ;
printf ( " the server %s have the NT byte range lock bug \n " , ! ret ? " does " : " doesn't " ) ;
2002-03-11 04:37:08 +03:00
2001-06-19 06:02:19 +04:00
fail :
2003-04-18 07:35:39 +04:00
cli_close ( cli1 , fnum1 ) ;
cli_close ( cli2 , fnum2 ) ;
2009-04-30 05:26:02 +04:00
cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ;
2003-04-18 07:35:39 +04:00
torture_close_connection ( cli1 ) ;
torture_close_connection ( cli2 ) ;
2001-06-19 06:02:19 +04:00
printf ( " finished locktest4 \n " ) ;
2001-07-02 07:21:17 +04:00
return correct ;
2001-06-19 06:02:19 +04:00
}
/*
looks at lock upgrade / downgrade .
*/
2007-10-19 04:40:25 +04:00
static bool run_locktest5 ( int dummy )
2001-06-19 06:02:19 +04:00
{
2003-04-18 07:35:39 +04:00
static struct cli_state * cli1 , * cli2 ;
2003-01-03 11:28:12 +03:00
const char * fname = " \\ lockt5.lck " ;
2009-05-01 02:26:43 +04:00
uint16_t fnum1 , fnum2 , fnum3 ;
2007-10-19 04:40:25 +04:00
bool ret ;
2001-06-19 06:02:19 +04:00
char buf [ 1000 ] ;
2007-10-19 04:40:25 +04:00
bool correct = True ;
2001-06-19 06:02:19 +04:00
2006-07-31 13:41:25 +04:00
if ( ! torture_open_connection ( & cli1 , 0 ) | | ! torture_open_connection ( & cli2 , 1 ) ) {
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2003-04-18 07:35:39 +04:00
cli_sockopt ( cli1 , sockops ) ;
cli_sockopt ( cli2 , sockops ) ;
2001-06-19 06:02:19 +04:00
printf ( " starting locktest5 \n " ) ;
2009-04-30 05:26:02 +04:00
cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ;
2001-06-19 06:02:19 +04:00
2009-05-01 02:26:43 +04:00
cli_open ( cli1 , fname , O_RDWR | O_CREAT | O_EXCL , DENY_NONE , & fnum1 ) ;
cli_open ( cli2 , fname , O_RDWR , DENY_NONE , & fnum2 ) ;
cli_open ( cli1 , fname , O_RDWR , DENY_NONE , & fnum3 ) ;
2001-06-19 06:02:19 +04:00
memset ( buf , 0 , sizeof ( buf ) ) ;
2003-04-18 07:35:39 +04:00
if ( cli_write ( cli1 , fnum1 , 0 , buf , 0 , sizeof ( buf ) ) ! = sizeof ( buf ) ) {
2001-06-19 06:02:19 +04:00
printf ( " Failed to create file \n " ) ;
2001-07-02 07:21:17 +04:00
correct = False ;
2001-06-19 06:02:19 +04:00
goto fail ;
}
/* Check for NT bug... */
2003-04-18 07:35:39 +04:00
ret = cli_lock ( cli1 , fnum1 , 0 , 8 , 0 , READ_LOCK ) & &
cli_lock ( cli1 , fnum3 , 0 , 1 , 0 , READ_LOCK ) ;
cli_close ( cli1 , fnum1 ) ;
2009-05-01 02:26:43 +04:00
cli_open ( cli1 , fname , O_RDWR , DENY_NONE , & fnum1 ) ;
2003-04-18 07:35:39 +04:00
ret = cli_lock ( cli1 , fnum1 , 7 , 1 , 0 , WRITE_LOCK ) ;
2001-06-19 06:02:19 +04:00
EXPECTED ( ret , True ) ;
printf ( " this server %s the NT locking bug \n " , ret ? " doesn't have " : " has " ) ;
2003-04-18 07:35:39 +04:00
cli_close ( cli1 , fnum1 ) ;
2009-05-01 02:26:43 +04:00
cli_open ( cli1 , fname , O_RDWR , DENY_NONE , & fnum1 ) ;
2003-04-18 07:35:39 +04:00
cli_unlock ( cli1 , fnum3 , 0 , 1 ) ;
2001-06-19 06:02:19 +04:00
2003-04-18 07:35:39 +04:00
ret = cli_lock ( cli1 , fnum1 , 0 , 4 , 0 , WRITE_LOCK ) & &
cli_lock ( cli1 , fnum1 , 1 , 1 , 0 , READ_LOCK ) ;
2001-06-19 06:02:19 +04:00
EXPECTED ( ret , True ) ;
printf ( " the same process %s overlay a write with a read lock \n " , ret ? " can " : " cannot " ) ;
2003-04-18 07:35:39 +04:00
ret = cli_lock ( cli2 , fnum2 , 0 , 4 , 0 , READ_LOCK ) ;
2001-06-19 06:02:19 +04:00
EXPECTED ( ret , False ) ;
printf ( " a different processs %s get a read lock on the first process lock stack \n " , ret ? " can " : " cannot " ) ;
/* Unlock the process 2 lock. */
2003-04-18 07:35:39 +04:00
cli_unlock ( cli2 , fnum2 , 0 , 4 ) ;
2001-06-19 06:02:19 +04:00
2003-04-18 07:35:39 +04:00
ret = cli_lock ( cli1 , fnum3 , 0 , 4 , 0 , READ_LOCK ) ;
2001-06-19 06:02:19 +04:00
EXPECTED ( ret , False ) ;
printf ( " the same processs on a different fnum %s get a read lock \n " , ret ? " can " : " cannot " ) ;
/* Unlock the process 1 fnum3 lock. */
2003-04-18 07:35:39 +04:00
cli_unlock ( cli1 , fnum3 , 0 , 4 ) ;
2001-06-19 06:02:19 +04:00
/* Stack 2 more locks here. */
2003-04-18 07:35:39 +04:00
ret = cli_lock ( cli1 , fnum1 , 0 , 4 , 0 , READ_LOCK ) & &
cli_lock ( cli1 , fnum1 , 0 , 4 , 0 , READ_LOCK ) ;
2001-06-19 06:02:19 +04:00
EXPECTED ( ret , True ) ;
printf ( " the same process %s stack read locks \n " , ret ? " can " : " cannot " ) ;
/* Unlock the first process lock, then check this was the WRITE lock that was
removed . */
2009-07-15 22:49:33 +04:00
ret = NT_STATUS_IS_OK ( cli_unlock ( cli1 , fnum1 , 0 , 4 ) ) & &
2003-04-18 07:35:39 +04:00
cli_lock ( cli2 , fnum2 , 0 , 4 , 0 , READ_LOCK ) ;
2001-06-19 06:02:19 +04:00
EXPECTED ( ret , True ) ;
printf ( " the first unlock removes the %s lock \n " , ret ? " WRITE " : " READ " ) ;
/* Unlock the process 2 lock. */
2003-04-18 07:35:39 +04:00
cli_unlock ( cli2 , fnum2 , 0 , 4 ) ;
2001-06-19 06:02:19 +04:00
/* We should have 3 stacked locks here. Ensure we need to do 3 unlocks. */
2009-07-15 22:49:33 +04:00
ret = NT_STATUS_IS_OK ( cli_unlock ( cli1 , fnum1 , 1 , 1 ) ) & &
NT_STATUS_IS_OK ( cli_unlock ( cli1 , fnum1 , 0 , 4 ) ) & &
NT_STATUS_IS_OK ( cli_unlock ( cli1 , fnum1 , 0 , 4 ) ) ;
2001-06-19 06:02:19 +04:00
EXPECTED ( ret , True ) ;
printf ( " the same process %s unlock the stack of 4 locks \n " , ret ? " can " : " cannot " ) ;
/* Ensure the next unlock fails. */
2009-07-15 22:49:33 +04:00
ret = NT_STATUS_IS_OK ( cli_unlock ( cli1 , fnum1 , 0 , 4 ) ) ;
2001-06-19 06:02:19 +04:00
EXPECTED ( ret , False ) ;
printf ( " the same process %s count the lock stack \n " , ! ret ? " can " : " cannot " ) ;
/* Ensure connection 2 can get a write lock. */
2003-04-18 07:35:39 +04:00
ret = cli_lock ( cli2 , fnum2 , 0 , 4 , 0 , WRITE_LOCK ) ;
2001-06-19 06:02:19 +04:00
EXPECTED ( ret , True ) ;
printf ( " a different processs %s get a write lock on the unlocked stack \n " , ret ? " can " : " cannot " ) ;
2001-07-02 07:21:17 +04:00
2001-06-19 06:02:19 +04:00
fail :
2003-04-18 07:35:39 +04:00
cli_close ( cli1 , fnum1 ) ;
cli_close ( cli2 , fnum2 ) ;
2009-04-30 05:26:02 +04:00
cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ;
2003-04-18 07:35:39 +04:00
if ( ! torture_close_connection ( cli1 ) ) {
2001-07-02 07:21:17 +04:00
correct = False ;
}
2003-04-18 07:35:39 +04:00
if ( ! torture_close_connection ( cli2 ) ) {
2001-07-02 07:21:17 +04:00
correct = False ;
}
2001-06-19 06:02:19 +04:00
printf ( " finished locktest5 \n " ) ;
2009-04-22 13:51:03 +04:00
2001-07-02 07:21:17 +04:00
return correct ;
2001-06-19 06:02:19 +04:00
}
2002-03-11 04:37:08 +03:00
/*
tries the unusual lockingX locktype bits
*/
2007-10-19 04:40:25 +04:00
static bool run_locktest6 ( int dummy )
2002-03-11 04:37:08 +03:00
{
2003-04-18 07:35:39 +04:00
static struct cli_state * cli ;
2003-01-03 11:28:12 +03:00
const char * fname [ 1 ] = { " \\ lock6.txt " } ;
2002-03-11 04:57:39 +03:00
int i ;
2009-05-01 02:26:43 +04:00
uint16_t fnum ;
2002-03-11 04:37:08 +03:00
NTSTATUS status ;
2006-07-31 13:41:25 +04:00
if ( ! torture_open_connection ( & cli , 0 ) ) {
2002-03-11 04:37:08 +03:00
return False ;
}
2003-04-18 07:35:39 +04:00
cli_sockopt ( cli , sockops ) ;
2002-03-11 04:37:08 +03:00
printf ( " starting locktest6 \n " ) ;
2002-03-11 18:56:59 +03:00
for ( i = 0 ; i < 1 ; i + + ) {
2002-03-11 04:57:39 +03:00
printf ( " Testing %s \n " , fname [ i ] ) ;
2002-03-11 04:37:08 +03:00
2009-04-30 05:26:02 +04:00
cli_unlink ( cli , fname [ i ] , aSYSTEM | aHIDDEN ) ;
2002-03-11 04:37:08 +03:00
2009-05-01 02:26:43 +04:00
cli_open ( cli , fname [ i ] , O_RDWR | O_CREAT | O_EXCL , DENY_NONE , & fnum ) ;
2003-04-18 07:35:39 +04:00
status = cli_locktype ( cli , fnum , 0 , 8 , 0 , LOCKING_ANDX_CHANGE_LOCKTYPE ) ;
cli_close ( cli , fnum ) ;
2002-03-17 07:36:35 +03:00
printf ( " CHANGE_LOCKTYPE gave %s \n " , nt_errstr ( status ) ) ;
2002-03-11 04:57:39 +03:00
2009-05-01 02:26:43 +04:00
cli_open ( cli , fname [ i ] , O_RDWR , DENY_NONE , & fnum ) ;
2003-04-18 07:35:39 +04:00
status = cli_locktype ( cli , fnum , 0 , 8 , 0 , LOCKING_ANDX_CANCEL_LOCK ) ;
cli_close ( cli , fnum ) ;
2002-03-17 07:36:35 +03:00
printf ( " CANCEL_LOCK gave %s \n " , nt_errstr ( status ) ) ;
2002-03-11 04:57:39 +03:00
2009-04-30 05:26:02 +04:00
cli_unlink ( cli , fname [ i ] , aSYSTEM | aHIDDEN ) ;
2002-03-11 04:57:39 +03:00
}
2002-03-11 04:37:08 +03:00
2003-04-18 07:35:39 +04:00
torture_close_connection ( cli ) ;
2002-03-11 04:37:08 +03:00
printf ( " finished locktest6 \n " ) ;
return True ;
}
2007-10-19 04:40:25 +04:00
static bool run_locktest7 ( int dummy )
2003-04-18 07:35:39 +04:00
{
struct cli_state * cli1 ;
const char * fname = " \\ lockt7.lck " ;
2009-05-01 02:26:43 +04:00
uint16_t fnum1 ;
2003-04-18 07:35:39 +04:00
char buf [ 200 ] ;
2007-10-19 04:40:25 +04:00
bool correct = False ;
2003-04-18 07:35:39 +04:00
2006-07-31 13:41:25 +04:00
if ( ! torture_open_connection ( & cli1 , 0 ) ) {
2003-04-18 07:35:39 +04:00
return False ;
}
cli_sockopt ( cli1 , sockops ) ;
printf ( " starting locktest7 \n " ) ;
2009-04-30 05:26:02 +04:00
cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ;
2003-04-18 07:35:39 +04:00
2009-05-01 02:26:43 +04:00
cli_open ( cli1 , fname , O_RDWR | O_CREAT | O_EXCL , DENY_NONE , & fnum1 ) ;
2003-04-18 07:35:39 +04:00
memset ( buf , 0 , sizeof ( buf ) ) ;
if ( cli_write ( cli1 , fnum1 , 0 , buf , 0 , sizeof ( buf ) ) ! = sizeof ( buf ) ) {
printf ( " Failed to create file \n " ) ;
goto fail ;
}
cli_setpid ( cli1 , 1 ) ;
if ( ! cli_lock ( cli1 , fnum1 , 130 , 4 , 0 , READ_LOCK ) ) {
printf ( " Unable to apply read lock on range 130:4, error was %s \n " , cli_errstr ( cli1 ) ) ;
goto fail ;
} else {
printf ( " pid1 successfully locked range 130:4 for READ \n " ) ;
}
if ( cli_read ( cli1 , fnum1 , buf , 130 , 4 ) ! = 4 ) {
printf ( " pid1 unable to read the range 130:4, error was %s \n " , cli_errstr ( cli1 ) ) ;
goto fail ;
} else {
printf ( " pid1 successfully read the range 130:4 \n " ) ;
}
if ( cli_write ( cli1 , fnum1 , 0 , buf , 130 , 4 ) ! = 4 ) {
printf ( " pid1 unable to write to the range 130:4, error was %s \n " , cli_errstr ( cli1 ) ) ;
if ( NT_STATUS_V ( cli_nt_error ( cli1 ) ) ! = NT_STATUS_V ( NT_STATUS_FILE_LOCK_CONFLICT ) ) {
printf ( " Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT) \n " ) ;
goto fail ;
}
} else {
printf ( " pid1 successfully wrote to the range 130:4 (should be denied) \n " ) ;
goto fail ;
}
cli_setpid ( cli1 , 2 ) ;
if ( cli_read ( cli1 , fnum1 , buf , 130 , 4 ) ! = 4 ) {
printf ( " pid2 unable to read the range 130:4, error was %s \n " , cli_errstr ( cli1 ) ) ;
} else {
printf ( " pid2 successfully read the range 130:4 \n " ) ;
}
if ( cli_write ( cli1 , fnum1 , 0 , buf , 130 , 4 ) ! = 4 ) {
printf ( " pid2 unable to write to the range 130:4, error was %s \n " , cli_errstr ( cli1 ) ) ;
if ( NT_STATUS_V ( cli_nt_error ( cli1 ) ) ! = NT_STATUS_V ( NT_STATUS_FILE_LOCK_CONFLICT ) ) {
printf ( " Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT) \n " ) ;
goto fail ;
}
} else {
printf ( " pid2 successfully wrote to the range 130:4 (should be denied) \n " ) ;
goto fail ;
}
cli_setpid ( cli1 , 1 ) ;
cli_unlock ( cli1 , fnum1 , 130 , 4 ) ;
if ( ! cli_lock ( cli1 , fnum1 , 130 , 4 , 0 , WRITE_LOCK ) ) {
printf ( " Unable to apply write lock on range 130:4, error was %s \n " , cli_errstr ( cli1 ) ) ;
goto fail ;
} else {
printf ( " pid1 successfully locked range 130:4 for WRITE \n " ) ;
}
if ( cli_read ( cli1 , fnum1 , buf , 130 , 4 ) ! = 4 ) {
printf ( " pid1 unable to read the range 130:4, error was %s \n " , cli_errstr ( cli1 ) ) ;
goto fail ;
} else {
printf ( " pid1 successfully read the range 130:4 \n " ) ;
}
if ( cli_write ( cli1 , fnum1 , 0 , buf , 130 , 4 ) ! = 4 ) {
printf ( " pid1 unable to write to the range 130:4, error was %s \n " , cli_errstr ( cli1 ) ) ;
goto fail ;
} else {
printf ( " pid1 successfully wrote to the range 130:4 \n " ) ;
}
cli_setpid ( cli1 , 2 ) ;
if ( cli_read ( cli1 , fnum1 , buf , 130 , 4 ) ! = 4 ) {
printf ( " pid2 unable to read the range 130:4, error was %s \n " , cli_errstr ( cli1 ) ) ;
if ( NT_STATUS_V ( cli_nt_error ( cli1 ) ) ! = NT_STATUS_V ( NT_STATUS_FILE_LOCK_CONFLICT ) ) {
printf ( " Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT) \n " ) ;
goto fail ;
}
} else {
printf ( " pid2 successfully read the range 130:4 (should be denied) \n " ) ;
goto fail ;
}
if ( cli_write ( cli1 , fnum1 , 0 , buf , 130 , 4 ) ! = 4 ) {
printf ( " pid2 unable to write to the range 130:4, error was %s \n " , cli_errstr ( cli1 ) ) ;
if ( NT_STATUS_V ( cli_nt_error ( cli1 ) ) ! = NT_STATUS_V ( NT_STATUS_FILE_LOCK_CONFLICT ) ) {
printf ( " Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT) \n " ) ;
goto fail ;
}
} else {
printf ( " pid2 successfully wrote to the range 130:4 (should be denied) \n " ) ;
goto fail ;
}
cli_unlock ( cli1 , fnum1 , 130 , 0 ) ;
correct = True ;
fail :
cli_close ( cli1 , fnum1 ) ;
2009-04-30 05:26:02 +04:00
cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ;
2003-04-18 07:35:39 +04:00
torture_close_connection ( cli1 ) ;
printf ( " finished locktest7 \n " ) ;
return correct ;
}
2009-05-20 16:56:04 +04:00
/*
* This demonstrates a problem with our use of GPFS share modes : A file
* descriptor sitting in the pending close queue holding a GPFS share mode
* blocks opening a file another time . Happens with Word 2007 temp files .
* With " posix locking = yes " and " gpfs:sharemodes = yes " enabled , the third
* open is denied with NT_STATUS_SHARING_VIOLATION .
*/
static bool run_locktest8 ( int dummy )
{
struct cli_state * cli1 ;
const char * fname = " \\ lockt8.lck " ;
uint16_t fnum1 , fnum2 ;
char buf [ 200 ] ;
bool correct = False ;
NTSTATUS status ;
if ( ! torture_open_connection ( & cli1 , 0 ) ) {
return False ;
}
cli_sockopt ( cli1 , sockops ) ;
printf ( " starting locktest8 \n " ) ;
cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ;
status = cli_open ( cli1 , fname , O_RDWR | O_CREAT | O_EXCL , DENY_WRITE ,
& fnum1 ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
d_fprintf ( stderr , " cli_open returned %s \n " , cli_errstr ( cli1 ) ) ;
return false ;
}
memset ( buf , 0 , sizeof ( buf ) ) ;
status = cli_open ( cli1 , fname , O_RDONLY , DENY_NONE , & fnum2 ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
d_fprintf ( stderr , " cli_open second time returned %s \n " ,
cli_errstr ( cli1 ) ) ;
goto fail ;
}
if ( ! cli_lock ( cli1 , fnum2 , 1 , 1 , 0 , READ_LOCK ) ) {
printf ( " Unable to apply read lock on range 1:1, error was "
" %s \n " , cli_errstr ( cli1 ) ) ;
goto fail ;
}
status = cli_close ( cli1 , fnum1 ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
d_fprintf ( stderr , " cli_close(fnum1) %s \n " , cli_errstr ( cli1 ) ) ;
goto fail ;
}
status = cli_open ( cli1 , fname , O_RDWR , DENY_NONE , & fnum1 ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
d_fprintf ( stderr , " cli_open third time returned %s \n " ,
cli_errstr ( cli1 ) ) ;
goto fail ;
}
correct = true ;
fail :
cli_close ( cli1 , fnum1 ) ;
cli_close ( cli1 , fnum2 ) ;
cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ;
torture_close_connection ( cli1 ) ;
printf ( " finished locktest8 \n " ) ;
return correct ;
}
2009-10-21 04:37:43 +04:00
/*
* This test is designed to be run in conjunction with
* external NFS or POSIX locks taken in the filesystem .
2009-10-21 04:41:27 +04:00
* It checks that the smbd server will block until the
* lock is released and then acquire it . JRA .
2009-10-21 04:37:43 +04:00
*/
static bool got_alarm ;
static int alarm_fd ;
static void alarm_handler ( int dummy )
{
got_alarm = True ;
}
static void alarm_handler_parent ( int dummy )
{
close ( alarm_fd ) ;
}
static void do_local_lock ( int read_fd , int write_fd )
{
int fd ;
char c = ' \0 ' ;
struct flock lock ;
const char * local_pathname = NULL ;
int ret ;
local_pathname = talloc_asprintf ( talloc_tos ( ) ,
" %s/lockt9.lck " , local_path ) ;
if ( ! local_pathname ) {
printf ( " child: alloc fail \n " ) ;
exit ( 1 ) ;
}
unlink ( local_pathname ) ;
fd = open ( local_pathname , O_RDWR | O_CREAT , 0666 ) ;
if ( fd = = - 1 ) {
printf ( " child: open of %s failed %s. \n " ,
local_pathname , strerror ( errno ) ) ;
exit ( 1 ) ;
}
/* Now take a fcntl lock. */
lock . l_type = F_WRLCK ;
lock . l_whence = SEEK_SET ;
lock . l_start = 0 ;
lock . l_len = 4 ;
lock . l_pid = getpid ( ) ;
ret = fcntl ( fd , F_SETLK , & lock ) ;
if ( ret = = - 1 ) {
printf ( " child: failed to get lock 0:4 on file %s. Error %s \n " ,
local_pathname , strerror ( errno ) ) ;
exit ( 1 ) ;
} else {
printf ( " child: got lock 0:4 on file %s. \n " ,
local_pathname ) ;
fflush ( stdout ) ;
}
CatchSignal ( SIGALRM , alarm_handler ) ;
alarm ( 5 ) ;
/* Signal the parent. */
if ( write ( write_fd , & c , 1 ) ! = 1 ) {
printf ( " child: start signal fail %s. \n " ,
strerror ( errno ) ) ;
exit ( 1 ) ;
}
alarm ( 0 ) ;
alarm ( 10 ) ;
/* Wait for the parent to be ready. */
if ( read ( read_fd , & c , 1 ) ! = 1 ) {
printf ( " child: reply signal fail %s. \n " ,
strerror ( errno ) ) ;
exit ( 1 ) ;
}
alarm ( 0 ) ;
sleep ( 5 ) ;
close ( fd ) ;
printf ( " child: released lock 0:4 on file %s. \n " ,
local_pathname ) ;
fflush ( stdout ) ;
exit ( 0 ) ;
}
static bool run_locktest9 ( int dummy )
{
struct cli_state * cli1 ;
const char * fname = " \\ lockt9.lck " ;
uint16_t fnum ;
bool correct = False ;
int pipe_in [ 2 ] , pipe_out [ 2 ] ;
pid_t child_pid ;
char c = ' \0 ' ;
int ret ;
2009-11-24 12:59:09 +03:00
struct timeval start ;
2009-10-21 04:37:43 +04:00
double seconds ;
NTSTATUS status ;
printf ( " starting locktest9 \n " ) ;
if ( local_path = = NULL ) {
d_fprintf ( stderr , " locktest9 must be given a local path via -l <localpath> \n " ) ;
return false ;
}
if ( pipe ( pipe_in ) = = - 1 | | pipe ( pipe_out ) = = - 1 ) {
return false ;
}
child_pid = fork ( ) ;
if ( child_pid = = - 1 ) {
return false ;
}
if ( child_pid = = 0 ) {
/* Child. */
do_local_lock ( pipe_out [ 0 ] , pipe_in [ 1 ] ) ;
exit ( 0 ) ;
}
close ( pipe_out [ 0 ] ) ;
close ( pipe_in [ 1 ] ) ;
pipe_out [ 0 ] = - 1 ;
pipe_in [ 1 ] = - 1 ;
/* Parent. */
ret = read ( pipe_in [ 0 ] , & c , 1 ) ;
if ( ret ! = 1 ) {
d_fprintf ( stderr , " failed to read start signal from child. %s \n " ,
strerror ( errno ) ) ;
return false ;
}
if ( ! torture_open_connection ( & cli1 , 0 ) ) {
return false ;
}
cli_sockopt ( cli1 , sockops ) ;
status = cli_open ( cli1 , fname , O_RDWR , DENY_NONE ,
& fnum ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
d_fprintf ( stderr , " cli_open returned %s \n " , cli_errstr ( cli1 ) ) ;
return false ;
}
/* Ensure the child has the lock. */
if ( cli_lock ( cli1 , fnum , 0 , 4 , 0 , WRITE_LOCK ) ) {
d_fprintf ( stderr , " Got the lock on range 0:4 - this should not happen ! \n " ) ;
goto fail ;
} else {
d_printf ( " Child has the lock. \n " ) ;
}
/* Tell the child to wait 5 seconds then exit. */
ret = write ( pipe_out [ 1 ] , & c , 1 ) ;
if ( ret ! = 1 ) {
d_fprintf ( stderr , " failed to send exit signal to child. %s \n " ,
strerror ( errno ) ) ;
goto fail ;
}
/* Wait 20 seconds for the lock. */
alarm_fd = cli1 - > fd ;
CatchSignal ( SIGALRM , alarm_handler_parent ) ;
alarm ( 20 ) ;
2009-11-24 12:59:09 +03:00
start = timeval_current ( ) ;
2009-10-21 04:37:43 +04:00
if ( ! cli_lock ( cli1 , fnum , 0 , 4 , - 1 , WRITE_LOCK ) ) {
d_fprintf ( stderr , " Unable to apply write lock on range 0:4, error was "
" %s \n " , cli_errstr ( cli1 ) ) ;
goto fail_nofd ;
}
alarm ( 0 ) ;
2009-11-24 12:59:09 +03:00
seconds = timeval_elapsed ( & start ) ;
2009-10-21 04:37:43 +04:00
printf ( " Parent got the lock after %.2f seconds. \n " ,
seconds ) ;
status = cli_close ( cli1 , fnum ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
d_fprintf ( stderr , " cli_close(fnum1) %s \n " , cli_errstr ( cli1 ) ) ;
goto fail ;
}
correct = true ;
fail :
cli_close ( cli1 , fnum ) ;
torture_close_connection ( cli1 ) ;
fail_nofd :
printf ( " finished locktest9 \n " ) ;
return correct ;
}
2001-06-19 06:02:19 +04:00
/*
test whether fnums and tids open on one VC are available on another ( a major
security hole )
*/
2007-10-19 04:40:25 +04:00
static bool run_fdpasstest ( int dummy )
2001-06-19 06:02:19 +04:00
{
2003-04-18 07:35:39 +04:00
struct cli_state * cli1 , * cli2 ;
2003-01-03 11:28:12 +03:00
const char * fname = " \\ fdpass.tst " ;
2009-05-01 02:26:43 +04:00
uint16_t fnum1 ;
2007-12-05 04:05:33 +03:00
char buf [ 1024 ] ;
2001-06-19 06:02:19 +04:00
2006-07-31 13:41:25 +04:00
if ( ! torture_open_connection ( & cli1 , 0 ) | | ! torture_open_connection ( & cli2 , 1 ) ) {
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2003-04-18 07:35:39 +04:00
cli_sockopt ( cli1 , sockops ) ;
cli_sockopt ( cli2 , sockops ) ;
2001-06-19 06:02:19 +04:00
printf ( " starting fdpasstest \n " ) ;
2009-04-30 05:26:02 +04:00
cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ;
2001-06-19 06:02:19 +04:00
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_open ( cli1 , fname , O_RDWR | O_CREAT | O_EXCL , DENY_NONE , & fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " open of %s failed (%s) \n " , fname , cli_errstr ( cli1 ) ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2003-04-18 07:35:39 +04:00
if ( cli_write ( cli1 , fnum1 , 0 , " hello world \n " , 0 , 13 ) ! = 13 ) {
printf ( " write failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2003-04-18 07:35:39 +04:00
cli2 - > vuid = cli1 - > vuid ;
cli2 - > cnum = cli1 - > cnum ;
cli2 - > pid = cli1 - > pid ;
2001-06-19 06:02:19 +04:00
2003-04-18 07:35:39 +04:00
if ( cli_read ( cli2 , fnum1 , buf , 0 , 13 ) = = 13 ) {
2001-06-19 06:02:19 +04:00
printf ( " read succeeded! nasty security hole [%s] \n " ,
buf ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2003-04-18 07:35:39 +04:00
cli_close ( cli1 , fnum1 ) ;
2009-04-30 05:26:02 +04:00
cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ;
2001-06-19 06:02:19 +04:00
2003-04-18 07:35:39 +04:00
torture_close_connection ( cli1 ) ;
torture_close_connection ( cli2 ) ;
2001-06-19 06:02:19 +04:00
printf ( " finished fdpasstest \n " ) ;
2001-07-02 07:21:17 +04:00
return True ;
2001-06-19 06:02:19 +04:00
}
2007-10-19 04:40:25 +04:00
static bool run_fdsesstest ( int dummy )
2003-04-18 07:35:39 +04:00
{
struct cli_state * cli ;
uint16 new_vuid ;
uint16 saved_vuid ;
uint16 new_cnum ;
uint16 saved_cnum ;
const char * fname = " \\ fdsess.tst " ;
const char * fname1 = " \\ fdsess1.tst " ;
2009-05-01 02:26:43 +04:00
uint16_t fnum1 ;
uint16_t fnum2 ;
2007-12-05 04:05:33 +03:00
char buf [ 1024 ] ;
2007-10-19 04:40:25 +04:00
bool ret = True ;
2003-04-18 07:35:39 +04:00
2006-07-31 13:41:25 +04:00
if ( ! torture_open_connection ( & cli , 0 ) )
2003-04-18 07:35:39 +04:00
return False ;
cli_sockopt ( cli , sockops ) ;
if ( ! torture_cli_session_setup2 ( cli , & new_vuid ) )
return False ;
saved_cnum = cli - > cnum ;
2009-01-26 10:37:13 +03:00
if ( ! NT_STATUS_IS_OK ( cli_tcon_andx ( cli , share , " ????? " , " " , 1 ) ) )
2003-04-18 07:35:39 +04:00
return False ;
new_cnum = cli - > cnum ;
cli - > cnum = saved_cnum ;
printf ( " starting fdsesstest \n " ) ;
2009-04-30 05:26:02 +04:00
cli_unlink ( cli , fname , aSYSTEM | aHIDDEN ) ;
cli_unlink ( cli , fname1 , aSYSTEM | aHIDDEN ) ;
2003-04-18 07:35:39 +04:00
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_open ( cli , fname , O_RDWR | O_CREAT | O_EXCL , DENY_NONE , & fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " open of %s failed (%s) \n " , fname , cli_errstr ( cli ) ) ;
return False ;
}
if ( cli_write ( cli , fnum1 , 0 , " hello world \n " , 0 , 13 ) ! = 13 ) {
printf ( " write failed (%s) \n " , cli_errstr ( cli ) ) ;
return False ;
}
saved_vuid = cli - > vuid ;
cli - > vuid = new_vuid ;
if ( cli_read ( cli , fnum1 , buf , 0 , 13 ) = = 13 ) {
printf ( " read succeeded with different vuid! nasty security hole [%s] \n " ,
buf ) ;
ret = False ;
}
/* Try to open a file with different vuid, samba cnum. */
2009-05-01 02:26:43 +04:00
if ( NT_STATUS_IS_OK ( cli_open ( cli , fname1 , O_RDWR | O_CREAT | O_EXCL , DENY_NONE , & fnum2 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " create with different vuid, same cnum succeeded. \n " ) ;
cli_close ( cli , fnum2 ) ;
2009-04-30 05:26:02 +04:00
cli_unlink ( cli , fname1 , aSYSTEM | aHIDDEN ) ;
2003-04-18 07:35:39 +04:00
} else {
printf ( " create with different vuid, same cnum failed. \n " ) ;
printf ( " This will cause problems with service clients. \n " ) ;
ret = False ;
}
cli - > vuid = saved_vuid ;
/* Try with same vuid, different cnum. */
cli - > cnum = new_cnum ;
if ( cli_read ( cli , fnum1 , buf , 0 , 13 ) = = 13 ) {
printf ( " read succeeded with different cnum![%s] \n " ,
buf ) ;
ret = False ;
}
cli - > cnum = saved_cnum ;
cli_close ( cli , fnum1 ) ;
2009-04-30 05:26:02 +04:00
cli_unlink ( cli , fname , aSYSTEM | aHIDDEN ) ;
2003-04-18 07:35:39 +04:00
torture_close_connection ( cli ) ;
printf ( " finished fdsesstest \n " ) ;
return ret ;
}
2001-06-19 06:02:19 +04:00
/*
This test checks that
1 ) the server does not allow an unlink on a file that is open
*/
2007-10-19 04:40:25 +04:00
static bool run_unlinktest ( int dummy )
2001-06-19 06:02:19 +04:00
{
2003-04-18 07:35:39 +04:00
struct cli_state * cli ;
2003-01-03 11:28:12 +03:00
const char * fname = " \\ unlink.tst " ;
2009-05-01 02:26:43 +04:00
uint16_t fnum ;
2007-10-19 04:40:25 +04:00
bool correct = True ;
2001-06-19 06:02:19 +04:00
2006-07-31 13:41:25 +04:00
if ( ! torture_open_connection ( & cli , 0 ) ) {
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2003-04-18 07:35:39 +04:00
cli_sockopt ( cli , sockops ) ;
2001-06-19 06:02:19 +04:00
printf ( " starting unlink test \n " ) ;
2009-04-30 05:26:02 +04:00
cli_unlink ( cli , fname , aSYSTEM | aHIDDEN ) ;
2001-06-19 06:02:19 +04:00
2003-04-18 07:35:39 +04:00
cli_setpid ( cli , 1 ) ;
2001-06-19 06:02:19 +04:00
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_open ( cli , fname , O_RDWR | O_CREAT | O_EXCL , DENY_NONE , & fnum ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " open of %s failed (%s) \n " , fname , cli_errstr ( cli ) ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2009-04-30 05:26:02 +04:00
if ( NT_STATUS_IS_OK ( cli_unlink ( cli , fname , aSYSTEM | aHIDDEN ) ) ) {
2001-06-19 06:02:19 +04:00
printf ( " error: server allowed unlink on an open file \n " ) ;
2001-07-02 07:21:17 +04:00
correct = False ;
2001-08-24 03:16:42 +04:00
} else {
2003-04-18 07:35:39 +04:00
correct = check_error ( __LINE__ , cli , ERRDOS , ERRbadshare ,
2001-08-24 03:16:42 +04:00
NT_STATUS_SHARING_VIOLATION ) ;
2001-06-19 06:02:19 +04:00
}
2003-04-18 07:35:39 +04:00
cli_close ( cli , fnum ) ;
2009-04-30 05:26:02 +04:00
cli_unlink ( cli , fname , aSYSTEM | aHIDDEN ) ;
2001-06-19 06:02:19 +04:00
2003-04-18 07:35:39 +04:00
if ( ! torture_close_connection ( cli ) ) {
2001-07-02 07:21:17 +04:00
correct = False ;
}
2001-06-19 06:02:19 +04:00
printf ( " unlink test finished \n " ) ;
2009-04-22 13:51:03 +04:00
2001-07-02 07:21:17 +04:00
return correct ;
2001-06-19 06:02:19 +04:00
}
/*
test how many open files this server supports on the one socket
*/
2007-10-19 04:40:25 +04:00
static bool run_maxfidtest ( int dummy )
2001-06-19 06:02:19 +04:00
{
2003-04-18 07:35:39 +04:00
struct cli_state * cli ;
2005-06-25 13:07:42 +04:00
const char * ftemplate = " \\ maxfid.%d.%d " ;
2001-06-19 06:02:19 +04:00
fstring fname ;
2009-05-01 02:26:43 +04:00
uint16_t fnums [ 0x11000 ] ;
int i ;
2001-06-19 06:02:19 +04:00
int retries = 4 ;
2007-10-19 04:40:25 +04:00
bool correct = True ;
2001-06-19 06:02:19 +04:00
cli = current_cli ;
if ( retries < = 0 ) {
printf ( " failed to connect \n " ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2003-04-18 07:35:39 +04:00
cli_sockopt ( cli , sockops ) ;
2001-06-19 06:02:19 +04:00
2001-08-20 09:15:26 +04:00
for ( i = 0 ; i < 0x11000 ; i + + ) {
2005-06-25 13:07:42 +04:00
slprintf ( fname , sizeof ( fname ) - 1 , ftemplate , i , ( int ) getpid ( ) ) ;
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_open ( cli , fname ,
O_RDWR | O_CREAT | O_TRUNC , DENY_NONE , & fnums [ i ] ) ) ) {
2001-06-19 06:02:19 +04:00
printf ( " open of %s failed (%s) \n " ,
2003-04-18 07:35:39 +04:00
fname , cli_errstr ( cli ) ) ;
2001-08-20 09:15:26 +04:00
printf ( " maximum fnum is %d \n " , i ) ;
2001-06-19 06:02:19 +04:00
break ;
}
2001-08-24 03:16:42 +04:00
printf ( " %6d \r " , i ) ;
2001-06-19 06:02:19 +04:00
}
2001-08-24 03:16:42 +04:00
printf ( " %6d \n " , i ) ;
2001-11-20 11:49:16 +03:00
i - - ;
2001-06-19 06:02:19 +04:00
printf ( " cleaning up \n " ) ;
2001-08-20 09:15:26 +04:00
for ( ; i > = 0 ; i - - ) {
2005-06-25 13:07:42 +04:00
slprintf ( fname , sizeof ( fname ) - 1 , ftemplate , i , ( int ) getpid ( ) ) ;
2003-04-18 07:35:39 +04:00
cli_close ( cli , fnums [ i ] ) ;
2009-04-30 05:26:02 +04:00
if ( ! NT_STATUS_IS_OK ( cli_unlink ( cli , fname , aSYSTEM | aHIDDEN ) ) ) {
2001-06-19 06:02:19 +04:00
printf ( " unlink of %s failed (%s) \n " ,
2003-04-18 07:35:39 +04:00
fname , cli_errstr ( cli ) ) ;
2001-07-02 07:21:17 +04:00
correct = False ;
2001-06-19 06:02:19 +04:00
}
2001-08-24 03:16:42 +04:00
printf ( " %6d \r " , i ) ;
2001-06-19 06:02:19 +04:00
}
2001-08-24 03:16:42 +04:00
printf ( " %6d \n " , 0 ) ;
2001-06-19 06:02:19 +04:00
printf ( " maxfid test finished \n " ) ;
2003-04-18 07:35:39 +04:00
if ( ! torture_close_connection ( cli ) ) {
2001-07-02 07:21:17 +04:00
correct = False ;
}
return correct ;
2001-06-19 06:02:19 +04:00
}
/* generate a random buffer */
static void rand_buf ( char * buf , int len )
{
while ( len - - ) {
* buf = ( char ) sys_random ( ) ;
buf + + ;
}
}
/* send smb negprot commands, not reading the response */
2007-10-19 04:40:25 +04:00
static bool run_negprot_nowait ( int dummy )
2001-06-19 06:02:19 +04:00
{
int i ;
2006-07-11 22:01:26 +04:00
static struct cli_state * cli ;
2007-10-19 04:40:25 +04:00
bool correct = True ;
2001-06-19 06:02:19 +04:00
printf ( " starting negprot nowait test \n " ) ;
2006-07-11 22:01:26 +04:00
if ( ! ( cli = open_nbt_connection ( ) ) ) {
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
for ( i = 0 ; i < 50000 ; i + + ) {
2008-09-11 09:31:34 +04:00
cli_negprot_sendsync ( cli ) ;
2001-06-19 06:02:19 +04:00
}
2006-07-11 22:01:26 +04:00
if ( ! torture_close_connection ( cli ) ) {
2001-07-02 07:21:17 +04:00
correct = False ;
}
2001-06-19 06:02:19 +04:00
printf ( " finished negprot nowait test \n " ) ;
2001-07-02 07:21:17 +04:00
return correct ;
2001-06-19 06:02:19 +04:00
}
/* send random IPC commands */
2007-10-19 04:40:25 +04:00
static bool run_randomipc ( int dummy )
2001-06-19 06:02:19 +04:00
{
char * rparam = NULL ;
char * rdata = NULL ;
2006-07-11 22:01:26 +04:00
unsigned int rdrcnt , rprcnt ;
2007-12-05 04:05:33 +03:00
char param [ 1024 ] ;
2001-06-19 06:02:19 +04:00
int api , param_len , i ;
2003-04-18 07:35:39 +04:00
struct cli_state * cli ;
2007-10-19 04:40:25 +04:00
bool correct = True ;
2001-08-24 03:16:42 +04:00
int count = 50000 ;
2001-06-19 06:02:19 +04:00
printf ( " starting random ipc test \n " ) ;
2006-07-31 13:41:25 +04:00
if ( ! torture_open_connection ( & cli , 0 ) ) {
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2001-08-24 03:16:42 +04:00
for ( i = 0 ; i < count ; i + + ) {
2001-06-19 06:02:19 +04:00
api = sys_random ( ) % 500 ;
param_len = ( sys_random ( ) % 64 ) ;
rand_buf ( param , param_len ) ;
2009-04-22 13:51:03 +04:00
2001-06-19 06:02:19 +04:00
SSVAL ( param , 0 , api ) ;
2003-04-18 07:35:39 +04:00
cli_api ( cli ,
2001-06-19 06:02:19 +04:00
param , param_len , 8 ,
NULL , 0 , BUFFER_SIZE ,
& rparam , & rprcnt ,
& rdata , & rdrcnt ) ;
2001-08-24 03:16:42 +04:00
if ( i % 100 = = 0 ) {
printf ( " %d/%d \r " , i , count ) ;
}
2001-06-19 06:02:19 +04:00
}
2001-08-24 03:16:42 +04:00
printf ( " %d/%d \n " , i , count ) ;
2001-06-19 06:02:19 +04:00
2003-04-18 07:35:39 +04:00
if ( ! torture_close_connection ( cli ) ) {
2001-07-02 07:21:17 +04:00
correct = False ;
}
2001-06-19 06:02:19 +04:00
printf ( " finished random ipc test \n " ) ;
2001-07-02 07:21:17 +04:00
return correct ;
2001-06-19 06:02:19 +04:00
}
static void browse_callback ( const char * sname , uint32 stype ,
const char * comment , void * state )
{
printf ( " \t %20.20s %08x %s \n " , sname , stype , comment ) ;
}
/*
This test checks the browse list code
*/
2007-10-19 04:40:25 +04:00
static bool run_browsetest ( int dummy )
2001-06-19 06:02:19 +04:00
{
2003-04-18 07:35:39 +04:00
static struct cli_state * cli ;
2007-10-19 04:40:25 +04:00
bool correct = True ;
2001-06-19 06:02:19 +04:00
printf ( " starting browse test \n " ) ;
2006-07-31 13:41:25 +04:00
if ( ! torture_open_connection ( & cli , 0 ) ) {
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
printf ( " domain list: \n " ) ;
2003-04-18 07:35:39 +04:00
cli_NetServerEnum ( cli , cli - > server_domain ,
2001-06-19 06:02:19 +04:00
SV_TYPE_DOMAIN_ENUM ,
browse_callback , NULL ) ;
printf ( " machine list: \n " ) ;
2003-04-18 07:35:39 +04:00
cli_NetServerEnum ( cli , cli - > server_domain ,
2001-06-19 06:02:19 +04:00
SV_TYPE_ALL ,
browse_callback , NULL ) ;
2003-04-18 07:35:39 +04:00
if ( ! torture_close_connection ( cli ) ) {
2001-07-02 07:21:17 +04:00
correct = False ;
}
2001-06-19 06:02:19 +04:00
printf ( " browse test finished \n " ) ;
2001-07-02 07:21:17 +04:00
return correct ;
2001-06-19 06:02:19 +04:00
}
/*
This checks how the getatr calls works
*/
2007-10-19 04:40:25 +04:00
static bool run_attrtest ( int dummy )
2001-06-19 06:02:19 +04:00
{
2003-04-18 07:35:39 +04:00
struct cli_state * cli ;
2009-05-01 02:26:43 +04:00
uint16_t fnum ;
2001-06-19 06:02:19 +04:00
time_t t , t2 ;
2003-04-18 07:35:39 +04:00
const char * fname = " \\ attrib123456789.tst " ;
2007-10-19 04:40:25 +04:00
bool correct = True ;
2001-06-19 06:02:19 +04:00
printf ( " starting attrib test \n " ) ;
2006-07-31 13:41:25 +04:00
if ( ! torture_open_connection ( & cli , 0 ) ) {
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2009-04-30 05:26:02 +04:00
cli_unlink ( cli , fname , aSYSTEM | aHIDDEN ) ;
2009-05-01 02:26:43 +04:00
cli_open ( cli , fname ,
O_RDWR | O_CREAT | O_TRUNC , DENY_NONE , & fnum ) ;
2003-04-18 07:35:39 +04:00
cli_close ( cli , fnum ) ;
2009-05-06 07:59:22 +04:00
if ( ! NT_STATUS_IS_OK ( cli_getatr ( cli , fname , NULL , NULL , & t ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " getatr failed (%s) \n " , cli_errstr ( cli ) ) ;
2001-07-02 07:21:17 +04:00
correct = False ;
2001-06-19 06:02:19 +04:00
}
2002-03-03 23:47:44 +03:00
if ( abs ( t - time ( NULL ) ) > 60 * 60 * 24 * 10 ) {
2001-06-19 06:02:19 +04:00
printf ( " ERROR: SMBgetatr bug. time is %s " ,
ctime ( & t ) ) ;
t = time ( NULL ) ;
2001-07-02 07:21:17 +04:00
correct = True ;
2001-06-19 06:02:19 +04:00
}
t2 = t - 60 * 60 * 24 ; /* 1 day ago */
2009-05-07 03:13:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_setatr ( cli , fname , 0 , t2 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " setatr failed (%s) \n " , cli_errstr ( cli ) ) ;
2001-07-02 07:21:17 +04:00
correct = True ;
2001-06-19 06:02:19 +04:00
}
2009-05-06 07:59:22 +04:00
if ( ! NT_STATUS_IS_OK ( cli_getatr ( cli , fname , NULL , NULL , & t ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " getatr failed (%s) \n " , cli_errstr ( cli ) ) ;
2001-07-02 07:21:17 +04:00
correct = True ;
2001-06-19 06:02:19 +04:00
}
if ( t ! = t2 ) {
printf ( " ERROR: getatr/setatr bug. times are \n %s " ,
ctime ( & t ) ) ;
printf ( " %s " , ctime ( & t2 ) ) ;
2001-07-02 07:21:17 +04:00
correct = True ;
2001-06-19 06:02:19 +04:00
}
2009-04-30 05:26:02 +04:00
cli_unlink ( cli , fname , aSYSTEM | aHIDDEN ) ;
2001-06-19 06:02:19 +04:00
2003-04-18 07:35:39 +04:00
if ( ! torture_close_connection ( cli ) ) {
2001-07-02 07:21:17 +04:00
correct = False ;
}
2001-06-19 06:02:19 +04:00
printf ( " attrib test finished \n " ) ;
2001-07-02 07:21:17 +04:00
return correct ;
2001-06-19 06:02:19 +04:00
}
/*
This checks a couple of trans2 calls
*/
2007-10-19 04:40:25 +04:00
static bool run_trans2test ( int dummy )
2001-06-19 06:02:19 +04:00
{
2003-04-18 07:35:39 +04:00
struct cli_state * cli ;
2009-05-01 02:26:43 +04:00
uint16_t fnum ;
2005-03-23 00:17:01 +03:00
SMB_OFF_T size ;
2006-08-27 20:50:10 +04:00
time_t c_time , a_time , m_time ;
2006-08-24 20:44:00 +04:00
struct timespec c_time_ts , a_time_ts , m_time_ts , w_time_ts , m_time2_ts ;
2003-01-03 11:28:12 +03:00
const char * fname = " \\ trans2.tst " ;
const char * dname = " \\ trans2 " ;
const char * fname2 = " \\ trans2 \\ trans2.tst " ;
2007-12-05 04:05:33 +03:00
char pname [ 1024 ] ;
2007-10-19 04:40:25 +04:00
bool correct = True ;
2009-11-21 15:46:52 +03:00
NTSTATUS status ;
uint32_t fs_attr ;
2001-06-19 06:02:19 +04:00
printf ( " starting trans2 test \n " ) ;
2006-07-31 13:41:25 +04:00
if ( ! torture_open_connection ( & cli , 0 ) ) {
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2009-11-21 15:46:52 +03:00
status = cli_get_fs_attr_info ( cli , & fs_attr ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " ERROR: cli_get_fs_attr_info returned %s \n " ,
nt_errstr ( status ) ) ;
correct = false ;
}
2009-04-30 05:26:02 +04:00
cli_unlink ( cli , fname , aSYSTEM | aHIDDEN ) ;
2009-05-01 02:26:43 +04:00
cli_open ( cli , fname ,
O_RDWR | O_CREAT | O_TRUNC , DENY_NONE , & fnum ) ;
2006-08-24 20:44:00 +04:00
if ( ! cli_qfileinfo ( cli , fnum , NULL , & size , & c_time_ts , & a_time_ts , & w_time_ts ,
& m_time_ts , NULL ) ) {
2003-04-18 07:35:39 +04:00
printf ( " ERROR: qfileinfo failed (%s) \n " , cli_errstr ( cli ) ) ;
2001-07-02 07:21:17 +04:00
correct = False ;
2001-06-19 06:02:19 +04:00
}
2002-02-21 07:27:16 +03:00
2007-12-01 03:13:35 +03:00
if ( ! cli_qfilename ( cli , fnum , pname , sizeof ( pname ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " ERROR: qfilename failed (%s) \n " , cli_errstr ( cli ) ) ;
2002-02-21 07:27:16 +03:00
correct = False ;
}
if ( strcmp ( pname , fname ) ) {
printf ( " qfilename gave different name? [%s] [%s] \n " ,
fname , pname ) ;
correct = False ;
}
2003-04-18 07:35:39 +04:00
cli_close ( cli , fnum ) ;
2001-06-19 06:02:19 +04:00
sleep ( 2 ) ;
2009-04-30 05:26:02 +04:00
cli_unlink ( cli , fname , aSYSTEM | aHIDDEN ) ;
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_open ( cli , fname ,
O_RDWR | O_CREAT | O_TRUNC , DENY_NONE , & fnum ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " open of %s failed (%s) \n " , fname , cli_errstr ( cli ) ) ;
2001-08-22 07:15:33 +04:00
return False ;
}
2003-04-18 07:35:39 +04:00
cli_close ( cli , fnum ) ;
2001-06-19 06:02:19 +04:00
2003-04-18 07:35:39 +04:00
if ( ! cli_qpathinfo ( cli , fname , & c_time , & a_time , & m_time , & size , NULL ) ) {
printf ( " ERROR: qpathinfo failed (%s) \n " , cli_errstr ( cli ) ) ;
2001-07-02 07:21:17 +04:00
correct = False ;
2001-06-19 06:02:19 +04:00
} else {
if ( c_time ! = m_time ) {
printf ( " create time=%s " , ctime ( & c_time ) ) ;
printf ( " modify time=%s " , ctime ( & m_time ) ) ;
printf ( " This system appears to have sticky create times \n " ) ;
}
if ( a_time % ( 60 * 60 ) = = 0 ) {
printf ( " access time=%s " , ctime ( & a_time ) ) ;
printf ( " This system appears to set a midnight access time \n " ) ;
2001-07-02 07:21:17 +04:00
correct = False ;
2001-06-19 06:02:19 +04:00
}
if ( abs ( m_time - time ( NULL ) ) > 60 * 60 * 24 * 7 ) {
2001-08-24 03:16:42 +04:00
printf ( " ERROR: totally incorrect times - maybe word reversed? mtime=%s " , ctime ( & m_time ) ) ;
2001-07-02 07:21:17 +04:00
correct = False ;
2001-06-19 06:02:19 +04:00
}
}
2009-04-30 05:26:02 +04:00
cli_unlink ( cli , fname , aSYSTEM | aHIDDEN ) ;
2009-05-01 02:26:43 +04:00
cli_open ( cli , fname ,
O_RDWR | O_CREAT | O_TRUNC , DENY_NONE , & fnum ) ;
2003-04-18 07:35:39 +04:00
cli_close ( cli , fnum ) ;
2006-08-24 20:44:00 +04:00
if ( ! cli_qpathinfo2 ( cli , fname , & c_time_ts , & a_time_ts , & w_time_ts ,
& m_time_ts , & size , NULL , NULL ) ) {
2003-04-18 07:35:39 +04:00
printf ( " ERROR: qpathinfo2 failed (%s) \n " , cli_errstr ( cli ) ) ;
2001-07-02 07:21:17 +04:00
correct = False ;
2001-06-19 06:02:19 +04:00
} else {
2006-08-24 20:44:00 +04:00
if ( w_time_ts . tv_sec < 60 * 60 * 24 * 2 ) {
printf ( " write time=%s " , ctime ( & w_time_ts . tv_sec ) ) ;
2001-06-19 06:02:19 +04:00
printf ( " This system appears to set a initial 0 write time \n " ) ;
2001-07-02 07:21:17 +04:00
correct = False ;
2001-06-19 06:02:19 +04:00
}
}
2009-04-30 05:26:02 +04:00
cli_unlink ( cli , fname , aSYSTEM | aHIDDEN ) ;
2001-06-19 06:02:19 +04:00
/* check if the server updates the directory modification time
when creating a new file */
2009-04-21 16:52:34 +04:00
if ( ! NT_STATUS_IS_OK ( cli_mkdir ( cli , dname ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " ERROR: mkdir failed (%s) \n " , cli_errstr ( cli ) ) ;
2001-07-02 07:21:17 +04:00
correct = False ;
2001-06-19 06:02:19 +04:00
}
sleep ( 3 ) ;
2006-08-24 20:44:00 +04:00
if ( ! cli_qpathinfo2 ( cli , " \\ trans2 \\ " , & c_time_ts , & a_time_ts , & w_time_ts ,
& m_time_ts , & size , NULL , NULL ) ) {
2003-04-18 07:35:39 +04:00
printf ( " ERROR: qpathinfo2 failed (%s) \n " , cli_errstr ( cli ) ) ;
2001-07-02 07:21:17 +04:00
correct = False ;
2001-06-19 06:02:19 +04:00
}
2009-05-01 02:26:43 +04:00
cli_open ( cli , fname2 ,
O_RDWR | O_CREAT | O_TRUNC , DENY_NONE , & fnum ) ;
2003-04-18 07:35:39 +04:00
cli_write ( cli , fnum , 0 , ( char * ) & fnum , 0 , sizeof ( fnum ) ) ;
cli_close ( cli , fnum ) ;
2006-08-24 20:44:00 +04:00
if ( ! cli_qpathinfo2 ( cli , " \\ trans2 \\ " , & c_time_ts , & a_time_ts , & w_time_ts ,
& m_time2_ts , & size , NULL , NULL ) ) {
2003-04-18 07:35:39 +04:00
printf ( " ERROR: qpathinfo2 failed (%s) \n " , cli_errstr ( cli ) ) ;
2001-07-02 07:21:17 +04:00
correct = False ;
2001-06-19 06:02:19 +04:00
} else {
2006-08-27 20:50:10 +04:00
if ( memcmp ( & m_time_ts , & m_time2_ts , sizeof ( struct timespec ) )
= = 0 ) {
2001-06-19 06:02:19 +04:00
printf ( " This system does not update directory modification times \n " ) ;
2001-07-02 07:21:17 +04:00
correct = False ;
}
2001-06-19 06:02:19 +04:00
}
2009-04-30 05:26:02 +04:00
cli_unlink ( cli , fname2 , aSYSTEM | aHIDDEN ) ;
2003-04-18 07:35:39 +04:00
cli_rmdir ( cli , dname ) ;
2001-06-19 06:02:19 +04:00
2003-04-18 07:35:39 +04:00
if ( ! torture_close_connection ( cli ) ) {
2001-07-02 07:21:17 +04:00
correct = False ;
}
2001-06-19 06:02:19 +04:00
printf ( " trans2 test finished \n " ) ;
2001-07-02 07:21:17 +04:00
return correct ;
2001-06-19 06:02:19 +04:00
}
/*
This checks new W2K calls .
*/
2007-10-19 04:40:25 +04:00
static bool new_trans ( struct cli_state * pcli , int fnum , int level )
2001-06-19 06:02:19 +04:00
{
2004-02-21 01:45:53 +03:00
char * buf = NULL ;
uint32 len ;
2007-10-19 04:40:25 +04:00
bool correct = True ;
2001-06-19 06:02:19 +04:00
2004-02-21 01:45:53 +03:00
if ( ! cli_qfileinfo_test ( pcli , fnum , level , & buf , & len ) ) {
2001-06-19 06:02:19 +04:00
printf ( " ERROR: qfileinfo (%d) failed (%s) \n " , level , cli_errstr ( pcli ) ) ;
2001-07-02 07:21:17 +04:00
correct = False ;
2001-06-19 06:02:19 +04:00
} else {
2004-02-21 01:45:53 +03:00
printf ( " qfileinfo: level %d, len = %u \n " , level , len ) ;
2007-03-28 17:34:59 +04:00
dump_data ( 0 , ( uint8 * ) buf , len ) ;
2001-06-19 06:02:19 +04:00
printf ( " \n " ) ;
}
2004-02-21 01:45:53 +03:00
SAFE_FREE ( buf ) ;
2001-07-02 07:21:17 +04:00
return correct ;
2001-06-19 06:02:19 +04:00
}
2007-10-19 04:40:25 +04:00
static bool run_w2ktest ( int dummy )
2001-06-19 06:02:19 +04:00
{
2003-04-18 07:35:39 +04:00
struct cli_state * cli ;
2009-05-01 02:26:43 +04:00
uint16_t fnum ;
2003-01-03 11:28:12 +03:00
const char * fname = " \\ w2ktest \\ w2k.tst " ;
2001-06-19 06:02:19 +04:00
int level ;
2007-10-19 04:40:25 +04:00
bool correct = True ;
2001-06-19 06:02:19 +04:00
printf ( " starting w2k test \n " ) ;
2006-07-31 13:41:25 +04:00
if ( ! torture_open_connection ( & cli , 0 ) ) {
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2009-05-01 02:26:43 +04:00
cli_open ( cli , fname ,
O_RDWR | O_CREAT , DENY_NONE , & fnum ) ;
2001-06-19 06:02:19 +04:00
2001-07-02 07:21:17 +04:00
for ( level = 1004 ; level < 1040 ; level + + ) {
2003-04-18 07:35:39 +04:00
new_trans ( cli , fnum , level ) ;
2001-07-02 07:21:17 +04:00
}
2001-06-19 06:02:19 +04:00
2003-04-18 07:35:39 +04:00
cli_close ( cli , fnum ) ;
2001-06-19 06:02:19 +04:00
2003-04-18 07:35:39 +04:00
if ( ! torture_close_connection ( cli ) ) {
2001-07-02 07:21:17 +04:00
correct = False ;
}
2001-06-19 06:02:19 +04:00
printf ( " w2k test finished \n " ) ;
2009-04-22 13:51:03 +04:00
2001-07-02 07:21:17 +04:00
return correct ;
2001-06-19 06:02:19 +04:00
}
/*
this is a harness for some oplock tests
*/
2007-10-19 04:40:25 +04:00
static bool run_oplock1 ( int dummy )
2001-06-19 06:02:19 +04:00
{
2003-04-18 07:35:39 +04:00
struct cli_state * cli1 ;
2003-01-03 11:28:12 +03:00
const char * fname = " \\ lockt1.lck " ;
2009-05-01 02:26:43 +04:00
uint16_t fnum1 ;
2007-10-19 04:40:25 +04:00
bool correct = True ;
2001-06-19 06:02:19 +04:00
printf ( " starting oplock test 1 \n " ) ;
2006-07-31 13:41:25 +04:00
if ( ! torture_open_connection ( & cli1 , 0 ) ) {
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2009-04-30 05:26:02 +04:00
cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ;
2001-06-19 06:02:19 +04:00
2003-04-18 07:35:39 +04:00
cli_sockopt ( cli1 , sockops ) ;
2001-06-19 06:02:19 +04:00
2003-04-18 07:35:39 +04:00
cli1 - > use_oplocks = True ;
2001-06-19 06:02:19 +04:00
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_open ( cli1 , fname , O_RDWR | O_CREAT | O_EXCL , DENY_NONE , & fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " open of %s failed (%s) \n " , fname , cli_errstr ( cli1 ) ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2003-04-18 07:35:39 +04:00
cli1 - > use_oplocks = False ;
2001-06-19 06:02:19 +04:00
2009-04-30 05:26:02 +04:00
cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ;
cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ;
2001-06-19 06:02:19 +04:00
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli1 , fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " close2 failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2009-04-30 05:26:02 +04:00
if ( ! NT_STATUS_IS_OK ( cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " unlink failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2003-04-18 07:35:39 +04:00
if ( ! torture_close_connection ( cli1 ) ) {
2001-07-02 07:21:17 +04:00
correct = False ;
}
2001-06-19 06:02:19 +04:00
printf ( " finished oplock test 1 \n " ) ;
2001-07-02 07:21:17 +04:00
return correct ;
2001-06-19 06:02:19 +04:00
}
2007-10-19 04:40:25 +04:00
static bool run_oplock2 ( int dummy )
2001-06-19 06:02:19 +04:00
{
2003-04-18 07:35:39 +04:00
struct cli_state * cli1 , * cli2 ;
2003-01-03 11:28:12 +03:00
const char * fname = " \\ lockt2.lck " ;
2009-05-01 02:26:43 +04:00
uint16_t fnum1 , fnum2 ;
2001-06-19 06:02:19 +04:00
int saved_use_oplocks = use_oplocks ;
char buf [ 4 ] ;
2007-10-19 04:40:25 +04:00
bool correct = True ;
volatile bool * shared_correct ;
2001-07-02 07:21:17 +04:00
2007-10-19 04:40:25 +04:00
shared_correct = ( volatile bool * ) shm_setup ( sizeof ( bool ) ) ;
2001-07-02 07:21:17 +04:00
* shared_correct = True ;
2001-06-19 06:02:19 +04:00
use_level_II_oplocks = True ;
use_oplocks = True ;
printf ( " starting oplock test 2 \n " ) ;
2006-07-31 13:41:25 +04:00
if ( ! torture_open_connection ( & cli1 , 0 ) ) {
2001-06-19 06:02:19 +04:00
use_level_II_oplocks = False ;
use_oplocks = saved_use_oplocks ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2003-04-18 07:35:39 +04:00
cli1 - > use_oplocks = True ;
cli1 - > use_level_II_oplocks = True ;
2001-06-19 06:02:19 +04:00
2006-07-31 13:41:25 +04:00
if ( ! torture_open_connection ( & cli2 , 1 ) ) {
2001-06-19 06:02:19 +04:00
use_level_II_oplocks = False ;
use_oplocks = saved_use_oplocks ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2003-04-18 07:35:39 +04:00
cli2 - > use_oplocks = True ;
cli2 - > use_level_II_oplocks = True ;
2001-06-19 06:02:19 +04:00
2009-04-30 05:26:02 +04:00
cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ;
2001-06-19 06:02:19 +04:00
2003-04-18 07:35:39 +04:00
cli_sockopt ( cli1 , sockops ) ;
cli_sockopt ( cli2 , sockops ) ;
2001-06-19 06:02:19 +04:00
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_open ( cli1 , fname , O_RDWR | O_CREAT | O_EXCL , DENY_NONE , & fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " open of %s failed (%s) \n " , fname , cli_errstr ( cli1 ) ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
/* Don't need the globals any more. */
use_level_II_oplocks = False ;
use_oplocks = saved_use_oplocks ;
if ( fork ( ) = = 0 ) {
/* Child code */
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_open ( cli2 , fname , O_RDWR , DENY_NONE , & fnum2 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " second open of %s failed (%s) \n " , fname , cli_errstr ( cli1 ) ) ;
2001-07-02 07:21:17 +04:00
* shared_correct = False ;
2001-06-19 06:02:19 +04:00
exit ( 0 ) ;
}
sleep ( 2 ) ;
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli2 , fnum2 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " close2 failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2001-07-02 07:21:17 +04:00
* shared_correct = False ;
2001-06-19 06:02:19 +04:00
}
exit ( 0 ) ;
}
sleep ( 2 ) ;
2005-03-03 07:08:13 +03:00
/* Ensure cli1 processes the break. Empty file should always return 0
* bytes . */
2001-06-19 06:02:19 +04:00
2005-03-03 07:08:13 +03:00
if ( cli_read ( cli1 , fnum1 , buf , 0 , 4 ) ! = 0 ) {
2003-04-18 07:35:39 +04:00
printf ( " read on fnum1 failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2001-07-02 07:21:17 +04:00
correct = False ;
2001-06-19 06:02:19 +04:00
}
/* Should now be at level II. */
/* Test if sending a write locks causes a break to none. */
2003-04-18 07:35:39 +04:00
if ( ! cli_lock ( cli1 , fnum1 , 0 , 4 , 0 , READ_LOCK ) ) {
printf ( " lock failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2001-07-02 07:21:17 +04:00
correct = False ;
2001-06-19 06:02:19 +04:00
}
2003-04-18 07:35:39 +04:00
cli_unlock ( cli1 , fnum1 , 0 , 4 ) ;
2001-06-19 06:02:19 +04:00
sleep ( 2 ) ;
2003-04-18 07:35:39 +04:00
if ( ! cli_lock ( cli1 , fnum1 , 0 , 4 , 0 , WRITE_LOCK ) ) {
printf ( " lock failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2001-07-02 07:21:17 +04:00
correct = False ;
2001-06-19 06:02:19 +04:00
}
2003-04-18 07:35:39 +04:00
cli_unlock ( cli1 , fnum1 , 0 , 4 ) ;
2001-06-19 06:02:19 +04:00
sleep ( 2 ) ;
2003-04-18 07:35:39 +04:00
cli_read ( cli1 , fnum1 , buf , 0 , 4 ) ;
2001-06-19 06:02:19 +04:00
#if 0
2003-04-18 07:35:39 +04:00
if ( cli_write ( cli1 , fnum1 , 0 , buf , 0 , 4 ) ! = 4 ) {
printf ( " write on fnum1 failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2001-07-02 07:21:17 +04:00
correct = False ;
2001-06-19 06:02:19 +04:00
}
# endif
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli1 , fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " close1 failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2001-07-02 07:21:17 +04:00
correct = False ;
2001-06-19 06:02:19 +04:00
}
sleep ( 4 ) ;
2009-04-30 05:26:02 +04:00
if ( ! NT_STATUS_IS_OK ( cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " unlink failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2001-07-02 07:21:17 +04:00
correct = False ;
2001-06-19 06:02:19 +04:00
}
2003-04-18 07:35:39 +04:00
if ( ! torture_close_connection ( cli1 ) ) {
2001-07-02 07:21:17 +04:00
correct = False ;
}
if ( ! * shared_correct ) {
correct = False ;
}
2001-06-19 06:02:19 +04:00
printf ( " finished oplock test 2 \n " ) ;
2001-07-02 07:21:17 +04:00
return correct ;
2001-06-19 06:02:19 +04:00
}
/* handler for oplock 3 tests */
2009-05-01 02:26:43 +04:00
static NTSTATUS oplock3_handler ( struct cli_state * cli , uint16_t fnum , unsigned char level )
2001-06-19 06:02:19 +04:00
{
printf ( " got oplock break fnum=%d level=%d \n " ,
fnum , level ) ;
return cli_oplock_ack ( cli , fnum , level ) ;
}
2007-10-19 04:40:25 +04:00
static bool run_oplock3 ( int dummy )
2001-06-19 06:02:19 +04:00
{
2003-04-18 07:35:39 +04:00
struct cli_state * cli ;
2003-01-03 11:28:12 +03:00
const char * fname = " \\ oplockt3.dat " ;
2009-05-01 02:26:43 +04:00
uint16_t fnum ;
2001-06-19 06:02:19 +04:00
char buf [ 4 ] = " abcd " ;
2007-10-19 04:40:25 +04:00
bool correct = True ;
volatile bool * shared_correct ;
2001-07-02 07:21:17 +04:00
2007-10-19 04:40:25 +04:00
shared_correct = ( volatile bool * ) shm_setup ( sizeof ( bool ) ) ;
2001-07-02 07:21:17 +04:00
* shared_correct = True ;
2001-06-19 06:02:19 +04:00
printf ( " starting oplock test 3 \n " ) ;
if ( fork ( ) = = 0 ) {
/* Child code */
2001-06-19 11:31:55 +04:00
use_oplocks = True ;
use_level_II_oplocks = True ;
2006-07-31 13:41:25 +04:00
if ( ! torture_open_connection ( & cli , 0 ) ) {
2001-07-02 07:21:17 +04:00
* shared_correct = False ;
exit ( 0 ) ;
}
2001-06-19 06:02:19 +04:00
sleep ( 2 ) ;
/* try to trigger a oplock break in parent */
2009-05-01 02:26:43 +04:00
cli_open ( cli , fname , O_RDWR , DENY_NONE , & fnum ) ;
2003-04-18 07:35:39 +04:00
cli_write ( cli , fnum , 0 , buf , 0 , 4 ) ;
2001-06-19 06:02:19 +04:00
exit ( 0 ) ;
}
/* parent code */
use_oplocks = True ;
use_level_II_oplocks = True ;
2006-07-31 13:41:25 +04:00
if ( ! torture_open_connection ( & cli , 1 ) ) { /* other is forked */
2001-07-02 07:21:17 +04:00
return False ;
}
2003-04-18 07:35:39 +04:00
cli_oplock_handler ( cli , oplock3_handler ) ;
2009-05-01 02:26:43 +04:00
cli_open ( cli , fname , O_RDWR | O_CREAT , DENY_NONE , & fnum ) ;
2003-04-18 07:35:39 +04:00
cli_write ( cli , fnum , 0 , buf , 0 , 4 ) ;
cli_close ( cli , fnum ) ;
2009-05-01 02:26:43 +04:00
cli_open ( cli , fname , O_RDWR , DENY_NONE , & fnum ) ;
2003-04-18 07:35:39 +04:00
cli - > timeout = 20000 ;
cli_receive_smb ( cli ) ;
2001-06-19 06:02:19 +04:00
printf ( " finished oplock test 3 \n " ) ;
2001-07-02 07:21:17 +04:00
return ( correct & & * shared_correct ) ;
/* What are we looking for here? What's sucess and what's FAILURE? */
2001-06-19 06:02:19 +04:00
}
/*
Test delete on close semantics .
*/
2007-10-19 04:40:25 +04:00
static bool run_deletetest ( int dummy )
2001-06-19 06:02:19 +04:00
{
2003-12-19 04:43:44 +03:00
struct cli_state * cli1 = NULL ;
struct cli_state * cli2 = NULL ;
2003-01-03 11:28:12 +03:00
const char * fname = " \\ delete.file " ;
2009-05-01 02:26:43 +04:00
uint16_t fnum1 = ( uint16_t ) - 1 ;
uint16_t fnum2 = ( uint16_t ) - 1 ;
2007-10-19 04:40:25 +04:00
bool correct = True ;
2009-04-22 13:51:03 +04:00
2001-07-02 07:21:17 +04:00
printf ( " starting delete test \n " ) ;
2009-04-22 13:51:03 +04:00
2006-07-31 13:41:25 +04:00
if ( ! torture_open_connection ( & cli1 , 0 ) ) {
2001-07-02 07:21:17 +04:00
return False ;
}
2009-04-22 13:51:03 +04:00
2003-04-18 07:35:39 +04:00
cli_sockopt ( cli1 , sockops ) ;
2001-09-06 05:21:09 +04:00
2003-04-18 07:35:39 +04:00
/* Test 1 - this should delete the file on close. */
2009-04-22 13:51:03 +04:00
2003-04-18 07:35:39 +04:00
cli_setatr ( cli1 , fname , 0 , 0 ) ;
2009-04-30 05:26:02 +04:00
cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ;
2009-04-22 13:51:03 +04:00
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_ntcreate ( cli1 , fname , 0 , GENERIC_ALL_ACCESS | DELETE_ACCESS , FILE_ATTRIBUTE_NORMAL ,
2004-02-21 01:45:53 +03:00
0 , FILE_OVERWRITE_IF ,
2009-05-01 02:26:43 +04:00
FILE_DELETE_ON_CLOSE , 0 , & fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " [1] open of %s failed (%s) \n " , fname , cli_errstr ( cli1 ) ) ;
2002-03-07 07:15:40 +03:00
correct = False ;
goto fail ;
2001-07-02 07:21:17 +04:00
}
2004-02-21 01:45:53 +03:00
2004-02-21 02:19:39 +03:00
#if 0 /* JRATEST */
{
uint32 * accinfo = NULL ;
uint32 len ;
cli_qfileinfo_test ( cli1 , fnum1 , SMB_FILE_ACCESS_INFORMATION , ( char * * ) & accinfo , & len ) ;
if ( accinfo )
printf ( " access mode = 0x%lx \n " , * accinfo ) ;
SAFE_FREE ( accinfo ) ;
}
2004-02-21 01:45:53 +03:00
# endif
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli1 , fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " [1] close failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2002-03-07 07:15:40 +03:00
correct = False ;
goto fail ;
2001-06-19 06:02:19 +04:00
}
2009-05-01 02:26:43 +04:00
if ( NT_STATUS_IS_OK ( cli_open ( cli1 , fname , O_RDWR , DENY_NONE , & fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " [1] open of %s succeeded (should fail) \n " , fname ) ;
2002-03-07 07:15:40 +03:00
correct = False ;
goto fail ;
2001-07-02 07:21:17 +04:00
}
2009-04-22 13:51:03 +04:00
2001-06-19 06:02:19 +04:00
printf ( " first delete on close test succeeded. \n " ) ;
2009-04-22 13:51:03 +04:00
2001-06-19 06:02:19 +04:00
/* Test 2 - this should delete the file on close. */
2009-04-22 13:51:03 +04:00
2003-04-18 07:35:39 +04:00
cli_setatr ( cli1 , fname , 0 , 0 ) ;
2009-04-30 05:26:02 +04:00
cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ;
2009-04-22 13:51:03 +04:00
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_ntcreate ( cli1 , fname , 0 , GENERIC_ALL_ACCESS ,
2001-09-06 05:21:09 +04:00
FILE_ATTRIBUTE_NORMAL , FILE_SHARE_NONE ,
2009-05-01 02:26:43 +04:00
FILE_OVERWRITE_IF , 0 , 0 , & fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " [2] open of %s failed (%s) \n " , fname , cli_errstr ( cli1 ) ) ;
2002-03-07 07:15:40 +03:00
correct = False ;
goto fail ;
2001-06-19 06:02:19 +04:00
}
2009-04-22 13:51:03 +04:00
2009-05-30 01:58:34 +04:00
if ( ! NT_STATUS_IS_OK ( cli_nt_delete_on_close ( cli1 , fnum1 , true ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " [2] setting delete_on_close failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2002-03-07 07:15:40 +03:00
correct = False ;
goto fail ;
2001-07-02 07:21:17 +04:00
}
2009-04-22 13:51:03 +04:00
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli1 , fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " [2] close failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2002-03-07 07:15:40 +03:00
correct = False ;
goto fail ;
2001-07-02 07:21:17 +04:00
}
2009-04-22 13:51:03 +04:00
2009-05-01 02:26:43 +04:00
if ( NT_STATUS_IS_OK ( cli_open ( cli1 , fname , O_RDONLY , DENY_NONE , & fnum1 ) ) ) {
2001-06-19 06:02:19 +04:00
printf ( " [2] open of %s succeeded should have been deleted on close ! \n " , fname ) ;
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli1 , fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " [2] close failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2001-07-02 07:21:17 +04:00
correct = False ;
2002-03-07 07:15:40 +03:00
goto fail ;
2001-06-19 06:02:19 +04:00
}
2009-04-30 05:26:02 +04:00
cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ;
2001-07-02 07:21:17 +04:00
} else
2001-06-19 06:02:19 +04:00
printf ( " second delete on close test succeeded. \n " ) ;
2009-04-22 13:51:03 +04:00
2001-06-19 06:02:19 +04:00
/* Test 3 - ... */
2003-04-18 07:35:39 +04:00
cli_setatr ( cli1 , fname , 0 , 0 ) ;
2009-04-30 05:26:02 +04:00
cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ;
2001-06-19 06:02:19 +04:00
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_ntcreate ( cli1 , fname , 0 , GENERIC_ALL_ACCESS , FILE_ATTRIBUTE_NORMAL ,
FILE_SHARE_READ | FILE_SHARE_WRITE , FILE_OVERWRITE_IF , 0 , 0 , & fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " [3] open - 1 of %s failed (%s) \n " , fname , cli_errstr ( cli1 ) ) ;
2002-03-07 07:15:40 +03:00
correct = False ;
goto fail ;
2001-06-19 06:02:19 +04:00
}
/* This should fail with a sharing violation - open for delete is only compatible
with SHARE_DELETE . */
2009-05-01 02:26:43 +04:00
if ( NT_STATUS_IS_OK ( cli_ntcreate ( cli1 , fname , 0 , GENERIC_READ_ACCESS , FILE_ATTRIBUTE_NORMAL ,
FILE_SHARE_READ | FILE_SHARE_WRITE , FILE_OPEN , 0 , 0 , & fnum2 ) ) ) {
2001-06-19 06:02:19 +04:00
printf ( " [3] open - 2 of %s succeeded - should have failed. \n " , fname ) ;
2002-03-07 07:15:40 +03:00
correct = False ;
goto fail ;
2001-06-19 06:02:19 +04:00
}
/* This should succeed. */
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_ntcreate ( cli1 , fname , 0 , GENERIC_READ_ACCESS , FILE_ATTRIBUTE_NORMAL ,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE , FILE_OPEN , 0 , 0 , & fnum2 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " [3] open - 2 of %s failed (%s) \n " , fname , cli_errstr ( cli1 ) ) ;
2002-03-07 07:15:40 +03:00
correct = False ;
goto fail ;
2001-06-19 06:02:19 +04:00
}
2009-05-30 01:58:34 +04:00
if ( ! NT_STATUS_IS_OK ( cli_nt_delete_on_close ( cli1 , fnum1 , true ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " [3] setting delete_on_close failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2002-03-07 07:15:40 +03:00
correct = False ;
goto fail ;
2001-07-02 07:21:17 +04:00
}
2009-04-22 13:51:03 +04:00
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli1 , fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " [3] close 1 failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2002-03-07 07:15:40 +03:00
correct = False ;
goto fail ;
2001-07-02 07:21:17 +04:00
}
2009-04-22 13:51:03 +04:00
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli1 , fnum2 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " [3] close 2 failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2002-03-07 07:15:40 +03:00
correct = False ;
goto fail ;
2001-07-02 07:21:17 +04:00
}
2009-04-22 13:51:03 +04:00
2001-06-19 06:02:19 +04:00
/* This should fail - file should no longer be there. */
2009-05-01 02:26:43 +04:00
if ( NT_STATUS_IS_OK ( cli_open ( cli1 , fname , O_RDONLY , DENY_NONE , & fnum1 ) ) ) {
2001-06-19 06:02:19 +04:00
printf ( " [3] open of %s succeeded should have been deleted on close ! \n " , fname ) ;
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli1 , fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " [3] close failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2001-06-19 06:02:19 +04:00
}
2009-04-30 05:26:02 +04:00
cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ;
2001-07-02 07:21:17 +04:00
correct = False ;
2002-03-07 07:15:40 +03:00
goto fail ;
2001-07-02 07:21:17 +04:00
} else
2001-06-19 06:02:19 +04:00
printf ( " third delete on close test succeeded. \n " ) ;
/* Test 4 ... */
2003-04-18 07:35:39 +04:00
cli_setatr ( cli1 , fname , 0 , 0 ) ;
2009-04-30 05:26:02 +04:00
cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ;
2001-06-19 06:02:19 +04:00
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_ntcreate ( cli1 , fname , 0 , FILE_READ_DATA | FILE_WRITE_DATA | DELETE_ACCESS ,
FILE_ATTRIBUTE_NORMAL , FILE_SHARE_READ | FILE_SHARE_WRITE , FILE_OVERWRITE_IF , 0 , 0 , & fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " [4] open of %s failed (%s) \n " , fname , cli_errstr ( cli1 ) ) ;
2002-03-07 07:15:40 +03:00
correct = False ;
goto fail ;
2001-06-19 06:02:19 +04:00
}
/* This should succeed. */
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_ntcreate ( cli1 , fname , 0 , GENERIC_READ_ACCESS ,
FILE_ATTRIBUTE_NORMAL , FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE , FILE_OPEN , 0 , 0 , & fnum2 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " [4] open - 2 of %s failed (%s) \n " , fname , cli_errstr ( cli1 ) ) ;
2002-03-07 07:15:40 +03:00
correct = False ;
goto fail ;
2001-06-19 06:02:19 +04:00
}
2009-04-22 13:51:03 +04:00
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli1 , fnum2 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " [4] close - 1 failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2002-03-07 07:15:40 +03:00
correct = False ;
goto fail ;
2001-07-02 07:21:17 +04:00
}
2009-04-22 13:51:03 +04:00
2009-05-30 01:58:34 +04:00
if ( ! NT_STATUS_IS_OK ( cli_nt_delete_on_close ( cli1 , fnum1 , true ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " [4] setting delete_on_close failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2002-03-07 07:15:40 +03:00
correct = False ;
goto fail ;
2001-07-02 07:21:17 +04:00
}
2009-04-22 13:51:03 +04:00
2001-06-19 06:02:19 +04:00
/* This should fail - no more opens once delete on close set. */
2009-05-01 02:26:43 +04:00
if ( NT_STATUS_IS_OK ( cli_ntcreate ( cli1 , fname , 0 , GENERIC_READ_ACCESS ,
2003-04-18 07:35:39 +04:00
FILE_ATTRIBUTE_NORMAL , FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE ,
2009-05-01 02:26:43 +04:00
FILE_OPEN , 0 , 0 , & fnum2 ) ) ) {
2001-06-19 06:02:19 +04:00
printf ( " [4] open - 3 of %s succeeded ! Should have failed. \n " , fname ) ;
2002-03-07 07:15:40 +03:00
correct = False ;
goto fail ;
2001-07-02 07:21:17 +04:00
} else
2001-06-19 06:02:19 +04:00
printf ( " fourth delete on close test succeeded. \n " ) ;
2009-04-22 13:51:03 +04:00
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli1 , fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " [4] close - 2 failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2002-03-07 07:15:40 +03:00
correct = False ;
goto fail ;
2001-07-02 07:21:17 +04:00
}
2009-04-22 13:51:03 +04:00
2001-06-19 06:02:19 +04:00
/* Test 5 ... */
2003-04-18 07:35:39 +04:00
cli_setatr ( cli1 , fname , 0 , 0 ) ;
2009-04-30 05:26:02 +04:00
cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ;
2009-04-22 13:51:03 +04:00
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_open ( cli1 , fname , O_RDWR | O_CREAT , DENY_NONE , & fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " [5] open of %s failed (%s) \n " , fname , cli_errstr ( cli1 ) ) ;
2002-03-07 07:15:40 +03:00
correct = False ;
goto fail ;
2001-06-19 06:02:19 +04:00
}
/* This should fail - only allowed on NT opens with DELETE access. */
2009-05-30 01:58:34 +04:00
if ( NT_STATUS_IS_OK ( cli_nt_delete_on_close ( cli1 , fnum1 , true ) ) ) {
2001-07-02 07:21:17 +04:00
printf ( " [5] setting delete_on_close on OpenX file succeeded - should fail ! \n " ) ;
2002-03-07 07:15:40 +03:00
correct = False ;
goto fail ;
2001-07-02 07:21:17 +04:00
}
2001-06-19 06:02:19 +04:00
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli1 , fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " [5] close - 2 failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2002-03-07 07:15:40 +03:00
correct = False ;
goto fail ;
2001-07-02 07:21:17 +04:00
}
2009-04-22 13:51:03 +04:00
2001-06-19 06:02:19 +04:00
printf ( " fifth delete on close test succeeded. \n " ) ;
2009-04-22 13:51:03 +04:00
2001-06-19 06:02:19 +04:00
/* Test 6 ... */
2003-04-18 07:35:39 +04:00
cli_setatr ( cli1 , fname , 0 , 0 ) ;
2009-04-30 05:26:02 +04:00
cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ;
2009-04-22 13:51:03 +04:00
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_ntcreate ( cli1 , fname , 0 , FILE_READ_DATA | FILE_WRITE_DATA ,
2001-07-02 07:21:17 +04:00
FILE_ATTRIBUTE_NORMAL , FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE ,
2009-05-01 02:26:43 +04:00
FILE_OVERWRITE_IF , 0 , 0 , & fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " [6] open of %s failed (%s) \n " , fname , cli_errstr ( cli1 ) ) ;
2002-03-07 07:15:40 +03:00
correct = False ;
goto fail ;
2001-06-19 06:02:19 +04:00
}
2009-04-22 13:51:03 +04:00
2001-06-19 06:02:19 +04:00
/* This should fail - only allowed on NT opens with DELETE access. */
2009-04-22 13:51:03 +04:00
2009-05-30 01:58:34 +04:00
if ( NT_STATUS_IS_OK ( cli_nt_delete_on_close ( cli1 , fnum1 , true ) ) ) {
2001-07-02 07:21:17 +04:00
printf ( " [6] setting delete_on_close on file with no delete access succeeded - should fail ! \n " ) ;
2002-03-07 07:15:40 +03:00
correct = False ;
goto fail ;
2001-07-02 07:21:17 +04:00
}
2001-06-19 06:02:19 +04:00
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli1 , fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " [6] close - 2 failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2002-03-07 07:15:40 +03:00
correct = False ;
goto fail ;
2001-07-02 07:21:17 +04:00
}
2001-06-19 06:02:19 +04:00
printf ( " sixth delete on close test succeeded. \n " ) ;
2009-04-22 13:51:03 +04:00
2001-06-19 06:02:19 +04:00
/* Test 7 ... */
2003-04-18 07:35:39 +04:00
cli_setatr ( cli1 , fname , 0 , 0 ) ;
2009-04-30 05:26:02 +04:00
cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ;
2009-04-22 13:51:03 +04:00
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_ntcreate ( cli1 , fname , 0 , FILE_READ_DATA | FILE_WRITE_DATA | DELETE_ACCESS ,
FILE_ATTRIBUTE_NORMAL , 0 , FILE_OVERWRITE_IF , 0 , 0 , & fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " [7] open of %s failed (%s) \n " , fname , cli_errstr ( cli1 ) ) ;
2002-03-07 07:15:40 +03:00
correct = False ;
goto fail ;
2001-06-19 06:02:19 +04:00
}
2009-05-30 01:58:34 +04:00
if ( ! NT_STATUS_IS_OK ( cli_nt_delete_on_close ( cli1 , fnum1 , true ) ) ) {
2001-07-02 07:21:17 +04:00
printf ( " [7] setting delete_on_close on file failed ! \n " ) ;
2002-03-07 07:15:40 +03:00
correct = False ;
goto fail ;
2001-07-02 07:21:17 +04:00
}
2009-04-22 13:51:03 +04:00
2009-05-30 01:58:34 +04:00
if ( ! NT_STATUS_IS_OK ( cli_nt_delete_on_close ( cli1 , fnum1 , false ) ) ) {
2001-07-02 07:21:17 +04:00
printf ( " [7] unsetting delete_on_close on file failed ! \n " ) ;
2002-03-07 07:15:40 +03:00
correct = False ;
goto fail ;
2001-07-02 07:21:17 +04:00
}
2001-06-19 06:02:19 +04:00
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli1 , fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " [7] close - 2 failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2002-03-07 07:15:40 +03:00
correct = False ;
goto fail ;
2001-07-02 07:21:17 +04:00
}
2009-04-22 13:51:03 +04:00
2001-06-19 06:02:19 +04:00
/* This next open should succeed - we reset the flag. */
2009-04-22 13:51:03 +04:00
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_open ( cli1 , fname , O_RDONLY , DENY_NONE , & fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " [5] open of %s failed (%s) \n " , fname , cli_errstr ( cli1 ) ) ;
2002-03-07 07:15:40 +03:00
correct = False ;
goto fail ;
2001-06-19 06:02:19 +04:00
}
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli1 , fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " [7] close - 2 failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2002-03-07 07:15:40 +03:00
correct = False ;
goto fail ;
2001-07-02 07:21:17 +04:00
}
2001-06-19 06:02:19 +04:00
printf ( " seventh delete on close test succeeded. \n " ) ;
2009-04-22 13:51:03 +04:00
2001-06-19 06:02:19 +04:00
/* Test 7 ... */
2003-04-18 07:35:39 +04:00
cli_setatr ( cli1 , fname , 0 , 0 ) ;
2009-04-30 05:26:02 +04:00
cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ;
2009-04-22 13:51:03 +04:00
2006-07-31 13:41:25 +04:00
if ( ! torture_open_connection ( & cli2 , 1 ) ) {
2001-06-19 06:02:19 +04:00
printf ( " [8] failed to open second connection. \n " ) ;
2002-03-07 07:15:40 +03:00
correct = False ;
goto fail ;
2001-07-02 07:21:17 +04:00
}
2001-06-19 06:02:19 +04:00
2003-04-18 07:35:39 +04:00
cli_sockopt ( cli1 , sockops ) ;
2009-04-22 13:51:03 +04:00
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_ntcreate ( cli1 , fname , 0 , FILE_READ_DATA | FILE_WRITE_DATA | DELETE_ACCESS ,
2003-04-18 07:35:39 +04:00
FILE_ATTRIBUTE_NORMAL , FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE ,
2009-05-01 02:26:43 +04:00
FILE_OVERWRITE_IF , 0 , 0 , & fnum1 ) ) ) {
2005-02-24 02:41:15 +03:00
printf ( " [8] open 1 of %s failed (%s) \n " , fname , cli_errstr ( cli1 ) ) ;
2002-03-07 07:15:40 +03:00
correct = False ;
goto fail ;
2001-06-19 06:02:19 +04:00
}
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_ntcreate ( cli2 , fname , 0 , FILE_READ_DATA | FILE_WRITE_DATA | DELETE_ACCESS ,
2003-04-18 07:35:39 +04:00
FILE_ATTRIBUTE_NORMAL , FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE ,
2009-05-01 02:26:43 +04:00
FILE_OPEN , 0 , 0 , & fnum2 ) ) ) {
2005-02-24 02:41:15 +03:00
printf ( " [8] open 2 of %s failed (%s) \n " , fname , cli_errstr ( cli2 ) ) ;
2002-03-07 07:15:40 +03:00
correct = False ;
goto fail ;
2001-06-19 06:02:19 +04:00
}
2009-05-30 01:58:34 +04:00
if ( ! NT_STATUS_IS_OK ( cli_nt_delete_on_close ( cli1 , fnum1 , true ) ) ) {
2001-07-02 07:21:17 +04:00
printf ( " [8] setting delete_on_close on file failed ! \n " ) ;
2002-03-07 07:15:40 +03:00
correct = False ;
goto fail ;
2001-07-02 07:21:17 +04:00
}
2009-04-22 13:51:03 +04:00
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli1 , fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " [8] close - 1 failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2002-03-07 07:15:40 +03:00
correct = False ;
goto fail ;
2001-07-02 07:21:17 +04:00
}
2001-06-19 06:02:19 +04:00
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli2 , fnum2 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " [8] close - 2 failed (%s) \n " , cli_errstr ( cli2 ) ) ;
2002-03-07 07:15:40 +03:00
correct = False ;
goto fail ;
2001-07-02 07:21:17 +04:00
}
2001-06-19 06:02:19 +04:00
/* This should fail.. */
2009-05-01 02:26:43 +04:00
if ( NT_STATUS_IS_OK ( cli_open ( cli1 , fname , O_RDONLY , DENY_NONE , & fnum1 ) ) ) {
2001-06-19 06:02:19 +04:00
printf ( " [8] open of %s succeeded should have been deleted on close ! \n " , fname ) ;
2002-03-07 07:15:40 +03:00
goto fail ;
2001-07-02 07:21:17 +04:00
correct = False ;
} else
2001-06-19 06:02:19 +04:00
printf ( " eighth delete on close test succeeded. \n " ) ;
2002-03-07 07:15:40 +03:00
/* This should fail - we need to set DELETE_ACCESS. */
2009-05-01 02:26:43 +04:00
if ( NT_STATUS_IS_OK ( cli_ntcreate ( cli1 , fname , 0 , FILE_READ_DATA | FILE_WRITE_DATA ,
FILE_ATTRIBUTE_NORMAL , FILE_SHARE_NONE , FILE_OVERWRITE_IF , FILE_DELETE_ON_CLOSE , 0 , & fnum1 ) ) ) {
2002-03-07 07:15:40 +03:00
printf ( " [9] open of %s succeeded should have failed! \n " , fname ) ;
correct = False ;
goto fail ;
}
printf ( " ninth delete on close test succeeded. \n " ) ;
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_ntcreate ( cli1 , fname , 0 , FILE_READ_DATA | FILE_WRITE_DATA | DELETE_ACCESS ,
FILE_ATTRIBUTE_NORMAL , FILE_SHARE_NONE , FILE_OVERWRITE_IF , FILE_DELETE_ON_CLOSE , 0 , & fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " [10] open of %s failed (%s) \n " , fname , cli_errstr ( cli1 ) ) ;
2002-03-07 07:15:40 +03:00
correct = False ;
goto fail ;
}
/* This should delete the file. */
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli1 , fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " [10] close failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2002-03-07 07:15:40 +03:00
correct = False ;
goto fail ;
}
/* This should fail.. */
2009-05-01 02:26:43 +04:00
if ( NT_STATUS_IS_OK ( cli_open ( cli1 , fname , O_RDONLY , DENY_NONE , & fnum1 ) ) ) {
2002-03-07 07:15:40 +03:00
printf ( " [10] open of %s succeeded should have been deleted on close ! \n " , fname ) ;
goto fail ;
correct = False ;
} else
printf ( " tenth delete on close test succeeded. \n " ) ;
2005-02-24 02:41:15 +03:00
cli_setatr ( cli1 , fname , 0 , 0 ) ;
2009-04-30 05:26:02 +04:00
cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ;
2005-02-24 02:41:15 +03:00
/* What error do we get when attempting to open a read-only file with
delete access ? */
/* Create a readonly file. */
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_ntcreate ( cli1 , fname , 0 , FILE_READ_DATA | FILE_WRITE_DATA ,
FILE_ATTRIBUTE_READONLY , FILE_SHARE_NONE , FILE_OVERWRITE_IF , 0 , 0 , & fnum1 ) ) ) {
2005-02-24 02:41:15 +03:00
printf ( " [11] open of %s failed (%s) \n " , fname , cli_errstr ( cli1 ) ) ;
correct = False ;
goto fail ;
}
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli1 , fnum1 ) ) ) {
2005-02-24 02:41:15 +03:00
printf ( " [11] close failed (%s) \n " , cli_errstr ( cli1 ) ) ;
correct = False ;
goto fail ;
}
/* Now try open for delete access. */
2009-05-01 02:26:43 +04:00
if ( NT_STATUS_IS_OK ( cli_ntcreate ( cli1 , fname , 0 , FILE_READ_ATTRIBUTES | DELETE_ACCESS ,
2005-02-24 02:41:15 +03:00
0 , FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE ,
2009-05-01 02:26:43 +04:00
FILE_OVERWRITE_IF , 0 , 0 , & fnum1 ) ) ) {
2005-02-24 02:41:15 +03:00
printf ( " [11] open of %s succeeded should have been denied with ACCESS_DENIED! \n " , fname ) ;
cli_close ( cli1 , fnum1 ) ;
goto fail ;
correct = False ;
} else {
NTSTATUS nterr = cli_nt_error ( cli1 ) ;
if ( ! NT_STATUS_EQUAL ( nterr , NT_STATUS_ACCESS_DENIED ) ) {
printf ( " [11] open of %s should have been denied with ACCESS_DENIED! Got error %s \n " , fname , nt_errstr ( nterr ) ) ;
goto fail ;
correct = False ;
} else {
printf ( " eleventh delete on close test succeeded. \n " ) ;
}
}
2009-04-22 13:51:03 +04:00
2001-07-02 07:21:17 +04:00
printf ( " finished delete test \n " ) ;
2002-03-07 07:15:40 +03:00
fail :
2003-04-18 07:35:39 +04:00
/* FIXME: This will crash if we aborted before cli2 got
* intialized , because these functions don ' t handle
* uninitialized connections . */
2009-04-22 13:51:03 +04:00
2009-05-04 00:45:42 +04:00
if ( fnum1 ! = ( uint16_t ) - 1 ) cli_close ( cli1 , fnum1 ) ;
if ( fnum2 ! = ( uint16_t ) - 1 ) cli_close ( cli1 , fnum2 ) ;
2003-04-18 07:35:39 +04:00
cli_setatr ( cli1 , fname , 0 , 0 ) ;
2009-04-30 05:26:02 +04:00
cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ;
2003-04-18 07:35:39 +04:00
2003-12-19 04:43:44 +03:00
if ( cli1 & & ! torture_close_connection ( cli1 ) ) {
2001-07-02 07:21:17 +04:00
correct = False ;
}
2003-12-19 04:43:44 +03:00
if ( cli2 & & ! torture_close_connection ( cli2 ) ) {
2001-07-02 07:21:17 +04:00
correct = False ;
}
return correct ;
2001-06-19 06:02:19 +04:00
}
2002-03-20 02:19:00 +03:00
/*
print out server properties
*/
2007-10-19 04:40:25 +04:00
static bool run_properties ( int dummy )
2002-03-20 02:19:00 +03:00
{
2009-04-22 13:54:13 +04:00
struct cli_state * cli ;
2007-10-19 04:40:25 +04:00
bool correct = True ;
2009-04-22 13:51:03 +04:00
2002-03-20 02:19:00 +03:00
printf ( " starting properties test \n " ) ;
2009-04-22 13:51:03 +04:00
2002-03-20 02:19:00 +03:00
ZERO_STRUCT ( cli ) ;
2006-07-31 13:41:25 +04:00
if ( ! torture_open_connection ( & cli , 0 ) ) {
2002-03-20 02:19:00 +03:00
return False ;
}
2009-04-22 13:51:03 +04:00
2003-04-18 07:35:39 +04:00
cli_sockopt ( cli , sockops ) ;
2002-03-20 02:19:00 +03:00
2003-04-18 07:35:39 +04:00
d_printf ( " Capabilities 0x%08x \n " , cli - > capabilities ) ;
2002-03-20 02:19:00 +03:00
2003-04-18 07:35:39 +04:00
if ( ! torture_close_connection ( cli ) ) {
2002-03-20 02:19:00 +03:00
correct = False ;
}
return correct ;
}
2002-03-07 05:16:25 +03:00
/* FIRST_DESIRED_ACCESS 0xf019f */
# define FIRST_DESIRED_ACCESS FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA|\
FILE_READ_EA | /* 0xf */ \
FILE_WRITE_EA | FILE_READ_ATTRIBUTES | /* 0x90 */ \
FILE_WRITE_ATTRIBUTES | /* 0x100 */ \
DELETE_ACCESS | READ_CONTROL_ACCESS | \
WRITE_DAC_ACCESS | WRITE_OWNER_ACCESS /* 0xf0000 */
/* SECOND_DESIRED_ACCESS 0xe0080 */
# define SECOND_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
READ_CONTROL_ACCESS | WRITE_DAC_ACCESS | \
WRITE_OWNER_ACCESS /* 0xe0000 */
#if 0
# define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTES| /* 0x80 */ \
READ_CONTROL_ACCESS | WRITE_DAC_ACCESS | \
FILE_READ_DATA | \
WRITE_OWNER_ACCESS /* */
# endif
2002-02-24 11:38:11 +03:00
/*
Test ntcreate calls made by xcopy
*/
2007-10-19 04:40:25 +04:00
static bool run_xcopy ( int dummy )
2002-02-24 11:38:11 +03:00
{
2003-04-18 07:35:39 +04:00
static struct cli_state * cli1 ;
2003-01-03 11:28:12 +03:00
const char * fname = " \\ test.txt " ;
2007-10-19 04:40:25 +04:00
bool correct = True ;
2009-05-01 02:26:43 +04:00
uint16_t fnum1 , fnum2 ;
2002-02-24 11:38:11 +03:00
printf ( " starting xcopy test \n " ) ;
2009-04-22 13:51:03 +04:00
2006-07-31 13:41:25 +04:00
if ( ! torture_open_connection ( & cli1 , 0 ) ) {
2002-02-24 11:38:11 +03:00
return False ;
}
2009-04-22 13:51:03 +04:00
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_ntcreate ( cli1 , fname , 0 ,
2002-03-07 05:16:25 +03:00
FIRST_DESIRED_ACCESS , FILE_ATTRIBUTE_ARCHIVE ,
FILE_SHARE_NONE , FILE_OVERWRITE_IF ,
2009-05-01 02:26:43 +04:00
0x4044 , 0 , & fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " First open failed - %s \n " , cli_errstr ( cli1 ) ) ;
2002-02-24 11:38:11 +03:00
return False ;
}
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_ntcreate ( cli1 , fname , 0 ,
2002-03-07 05:16:25 +03:00
SECOND_DESIRED_ACCESS , 0 ,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE , FILE_OPEN ,
2009-05-01 02:26:43 +04:00
0x200000 , 0 , & fnum2 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " second open failed - %s \n " , cli_errstr ( cli1 ) ) ;
2002-02-24 11:38:11 +03:00
return False ;
}
2009-04-22 13:51:03 +04:00
2003-04-18 07:35:39 +04:00
if ( ! torture_close_connection ( cli1 ) ) {
2002-02-24 11:38:11 +03:00
correct = False ;
}
2009-04-22 13:51:03 +04:00
2002-02-24 11:38:11 +03:00
return correct ;
}
2002-03-05 22:45:16 +03:00
/*
Test rename on files open with share delete and no share delete .
*/
2007-10-19 04:40:25 +04:00
static bool run_rename ( int dummy )
2002-03-05 22:45:16 +03:00
{
2003-04-18 07:35:39 +04:00
static struct cli_state * cli1 ;
2003-01-03 11:28:12 +03:00
const char * fname = " \\ test.txt " ;
const char * fname1 = " \\ test1.txt " ;
2007-10-19 04:40:25 +04:00
bool correct = True ;
2009-05-01 02:26:43 +04:00
uint16_t fnum1 ;
2010-04-02 02:01:43 +04:00
uint16_t attr ;
2009-05-02 21:11:52 +04:00
NTSTATUS status ;
2002-03-05 22:45:16 +03:00
printf ( " starting rename test \n " ) ;
2009-04-22 13:51:03 +04:00
2006-07-31 13:41:25 +04:00
if ( ! torture_open_connection ( & cli1 , 0 ) ) {
2002-03-05 22:45:16 +03:00
return False ;
}
2009-04-22 13:51:03 +04:00
2009-04-30 05:26:02 +04:00
cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ;
cli_unlink ( cli1 , fname1 , aSYSTEM | aHIDDEN ) ;
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_ntcreate ( cli1 , fname , 0 , GENERIC_READ_ACCESS , FILE_ATTRIBUTE_NORMAL ,
FILE_SHARE_READ , FILE_OVERWRITE_IF , 0 , 0 , & fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " First open failed - %s \n " , cli_errstr ( cli1 ) ) ;
2002-03-05 22:45:16 +03:00
return False ;
}
2009-04-29 03:43:16 +04:00
if ( ! NT_STATUS_IS_OK ( cli_rename ( cli1 , fname , fname1 ) ) ) {
2004-02-26 04:33:35 +03:00
printf ( " First rename failed (SHARE_READ) (this is correct) - %s \n " , cli_errstr ( cli1 ) ) ;
2002-03-05 22:45:16 +03:00
} else {
2004-02-26 04:33:35 +03:00
printf ( " First rename succeeded (SHARE_READ) - this should have failed ! \n " ) ;
2002-03-05 22:45:16 +03:00
correct = False ;
}
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli1 , fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " close - 1 failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2002-03-05 22:45:16 +03:00
return False ;
}
2009-04-30 05:26:02 +04:00
cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ;
cli_unlink ( cli1 , fname1 , aSYSTEM | aHIDDEN ) ;
2009-05-02 21:11:52 +04:00
status = cli_ntcreate ( cli1 , fname , 0 , GENERIC_READ_ACCESS , FILE_ATTRIBUTE_NORMAL ,
2002-03-23 05:57:44 +03:00
#if 0
2009-05-02 21:11:52 +04:00
FILE_SHARE_DELETE | FILE_SHARE_NONE ,
2002-03-23 05:57:44 +03:00
# else
2009-05-02 21:11:52 +04:00
FILE_SHARE_DELETE | FILE_SHARE_READ ,
2002-03-23 05:57:44 +03:00
# endif
2009-05-02 21:11:52 +04:00
FILE_OVERWRITE_IF , 0 , 0 , & fnum1 ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2003-04-18 07:35:39 +04:00
printf ( " Second open failed - %s \n " , cli_errstr ( cli1 ) ) ;
2002-03-05 22:45:16 +03:00
return False ;
}
2009-04-29 03:43:16 +04:00
if ( ! NT_STATUS_IS_OK ( cli_rename ( cli1 , fname , fname1 ) ) ) {
2004-02-26 04:33:35 +03:00
printf ( " Second rename failed (SHARE_DELETE | SHARE_READ) - this should have succeeded - %s \n " , cli_errstr ( cli1 ) ) ;
2002-03-05 22:45:16 +03:00
correct = False ;
} else {
2004-02-26 04:33:35 +03:00
printf ( " Second rename succeeded (SHARE_DELETE | SHARE_READ) \n " ) ;
2002-03-05 22:45:16 +03:00
}
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli1 , fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " close - 2 failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2002-03-23 05:57:44 +03:00
return False ;
}
2009-04-30 05:26:02 +04:00
cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ;
cli_unlink ( cli1 , fname1 , aSYSTEM | aHIDDEN ) ;
2002-03-23 05:57:44 +03:00
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_ntcreate ( cli1 , fname , 0 , READ_CONTROL_ACCESS , FILE_ATTRIBUTE_NORMAL ,
FILE_SHARE_NONE , FILE_OVERWRITE_IF , 0 , 0 , & fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " Third open failed - %s \n " , cli_errstr ( cli1 ) ) ;
2002-03-23 05:57:44 +03:00
return False ;
}
2002-03-23 05:59:20 +03:00
#if 0
2002-03-23 05:57:44 +03:00
{
2009-05-01 02:26:43 +04:00
uint16_t fnum2 ;
2002-03-23 05:57:44 +03:00
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_ntcreate ( cli1 , fname , 0 , DELETE_ACCESS , FILE_ATTRIBUTE_NORMAL ,
FILE_SHARE_NONE , FILE_OVERWRITE_IF , 0 , 0 , & fnum2 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " Fourth open failed - %s \n " , cli_errstr ( cli1 ) ) ;
2002-03-23 05:57:44 +03:00
return False ;
}
2009-05-30 01:58:34 +04:00
if ( ! NT_STATUS_IS_OK ( cli_nt_delete_on_close ( cli1 , fnum2 , true ) ) ) {
2002-03-23 05:57:44 +03:00
printf ( " [8] setting delete_on_close on file failed ! \n " ) ;
return False ;
}
2009-04-22 13:51:03 +04:00
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli1 , fnum2 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " close - 4 failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2002-03-23 05:57:44 +03:00
return False ;
}
}
# endif
2009-04-29 03:43:16 +04:00
if ( ! NT_STATUS_IS_OK ( cli_rename ( cli1 , fname , fname1 ) ) ) {
2004-02-26 04:33:35 +03:00
printf ( " Third rename failed (SHARE_NONE) - this should have succeeded - %s \n " , cli_errstr ( cli1 ) ) ;
2002-03-23 05:57:44 +03:00
correct = False ;
} else {
2004-02-26 04:33:35 +03:00
printf ( " Third rename succeeded (SHARE_NONE) \n " ) ;
2002-03-23 05:57:44 +03:00
}
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli1 , fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " close - 3 failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2002-03-05 22:45:16 +03:00
return False ;
}
2009-04-30 05:26:02 +04:00
cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ;
cli_unlink ( cli1 , fname1 , aSYSTEM | aHIDDEN ) ;
2002-03-05 22:45:16 +03:00
2004-02-26 04:33:35 +03:00
/*----*/
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_ntcreate ( cli1 , fname , 0 , GENERIC_READ_ACCESS , FILE_ATTRIBUTE_NORMAL ,
FILE_SHARE_READ | FILE_SHARE_WRITE , FILE_OVERWRITE_IF , 0 , 0 , & fnum1 ) ) ) {
2004-02-26 04:33:35 +03:00
printf ( " Fourth open failed - %s \n " , cli_errstr ( cli1 ) ) ;
return False ;
}
2009-04-29 03:43:16 +04:00
if ( ! NT_STATUS_IS_OK ( cli_rename ( cli1 , fname , fname1 ) ) ) {
2004-02-26 04:33:35 +03:00
printf ( " Fourth rename failed (SHARE_READ | SHARE_WRITE) (this is correct) - %s \n " , cli_errstr ( cli1 ) ) ;
} else {
printf ( " Fourth rename succeeded (SHARE_READ | SHARE_WRITE) - this should have failed ! \n " ) ;
correct = False ;
}
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli1 , fnum1 ) ) ) {
2004-02-26 04:33:35 +03:00
printf ( " close - 4 failed (%s) \n " , cli_errstr ( cli1 ) ) ;
return False ;
}
2009-04-30 05:26:02 +04:00
cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ;
cli_unlink ( cli1 , fname1 , aSYSTEM | aHIDDEN ) ;
2004-02-26 04:33:35 +03:00
/*--*/
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_ntcreate ( cli1 , fname , 0 , GENERIC_READ_ACCESS , FILE_ATTRIBUTE_NORMAL ,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE , FILE_OVERWRITE_IF , 0 , 0 , & fnum1 ) ) ) {
2004-02-26 04:33:35 +03:00
printf ( " Fifth open failed - %s \n " , cli_errstr ( cli1 ) ) ;
return False ;
}
2009-04-29 03:43:16 +04:00
if ( ! NT_STATUS_IS_OK ( cli_rename ( cli1 , fname , fname1 ) ) ) {
2008-08-13 01:40:01 +04:00
printf ( " Fifth rename failed (SHARE_READ | SHARE_WRITE | SHARE_DELETE) - this should have succeeded - %s ! \n " ,
cli_errstr ( cli1 ) ) ;
2004-02-26 04:33:35 +03:00
correct = False ;
} else {
printf ( " Fifth rename succeeded (SHARE_READ | SHARE_WRITE | SHARE_DELETE) (this is correct) - %s \n " , cli_errstr ( cli1 ) ) ;
}
/*
* Now check if the first name still exists . . .
*/
2009-05-01 02:26:43 +04:00
/* if (!NT_STATUS_OP(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE , FILE_OVERWRITE_IF , 0 , 0 , & fnum2 ) ) ) {
2004-02-26 04:33:35 +03:00
printf ( " Opening original file after rename of open file fails: %s \n " ,
cli_errstr ( cli1 ) ) ;
}
else {
printf ( " Opening original file after rename of open file works ... \n " ) ;
( void ) cli_close ( cli1 , fnum2 ) ;
} */
/*--*/
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli1 , fnum1 ) ) ) {
2004-02-26 04:33:35 +03:00
printf ( " close - 5 failed (%s) \n " , cli_errstr ( cli1 ) ) ;
return False ;
}
2010-04-02 02:01:43 +04:00
/* Check that the renamed file has FILE_ATTRIBUTE_ARCHIVE. */
if ( ! NT_STATUS_IS_OK ( cli_getatr ( cli1 , fname1 , & attr , NULL , NULL ) ) ) {
printf ( " getatr on file %s failed - %s ! \n " ,
fname1 ,
cli_errstr ( cli1 ) ) ;
correct = False ;
} else {
if ( attr ! = FILE_ATTRIBUTE_ARCHIVE ) {
printf ( " Renamed file %s has wrong attr 0x%x "
" (should be 0x%x) \n " ,
fname1 ,
attr ,
( unsigned int ) FILE_ATTRIBUTE_ARCHIVE ) ;
correct = False ;
} else {
printf ( " Renamed file %s has archive bit set \n " , fname1 ) ;
}
}
2009-04-30 05:26:02 +04:00
cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ;
cli_unlink ( cli1 , fname1 , aSYSTEM | aHIDDEN ) ;
2009-04-22 13:51:03 +04:00
2003-04-18 07:35:39 +04:00
if ( ! torture_close_connection ( cli1 ) ) {
2002-03-05 22:45:16 +03:00
correct = False ;
}
2009-04-22 13:51:03 +04:00
2002-03-05 22:45:16 +03:00
return correct ;
}
2007-10-19 04:40:25 +04:00
static bool run_pipe_number ( int dummy )
2002-07-15 14:35:28 +04:00
{
2003-04-18 07:35:39 +04:00
struct cli_state * cli1 ;
2003-01-03 11:28:12 +03:00
const char * pipe_name = " \\ SPOOLSS " ;
2009-05-01 02:26:43 +04:00
uint16_t fnum ;
2002-07-15 14:35:28 +04:00
int num_pipes = 0 ;
printf ( " starting pipenumber test \n " ) ;
2006-07-31 13:41:25 +04:00
if ( ! torture_open_connection ( & cli1 , 0 ) ) {
2002-07-15 14:35:28 +04:00
return False ;
}
2003-04-18 07:35:39 +04:00
cli_sockopt ( cli1 , sockops ) ;
2002-07-15 14:35:28 +04:00
while ( 1 ) {
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_ntcreate ( cli1 , pipe_name , 0 , FILE_READ_DATA , FILE_ATTRIBUTE_NORMAL ,
FILE_SHARE_READ | FILE_SHARE_WRITE , FILE_OPEN_IF , 0 , 0 , & fnum ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " Open of pipe %s failed with error (%s) \n " , pipe_name , cli_errstr ( cli1 ) ) ;
2002-07-15 14:35:28 +04:00
break ;
}
num_pipes + + ;
2006-09-05 14:37:18 +04:00
printf ( " \r %6d " , num_pipes ) ;
2002-07-15 14:35:28 +04:00
}
printf ( " pipe_number test - we can open %d %s pipes. \n " , num_pipes , pipe_name ) ;
2003-04-18 07:35:39 +04:00
torture_close_connection ( cli1 ) ;
2002-07-15 14:35:28 +04:00
return True ;
}
2002-02-24 11:38:11 +03:00
2001-06-19 06:02:19 +04:00
/*
Test open mode returns on read - only files .
*/
2007-10-19 04:40:25 +04:00
static bool run_opentest ( int dummy )
2001-06-19 06:02:19 +04:00
{
2003-04-18 07:35:39 +04:00
static struct cli_state * cli1 ;
static struct cli_state * cli2 ;
2003-01-03 11:28:12 +03:00
const char * fname = " \\ readonly.file " ;
2009-05-01 02:26:43 +04:00
uint16_t fnum1 , fnum2 ;
2001-06-19 06:02:19 +04:00
char buf [ 20 ] ;
2005-03-23 00:17:01 +03:00
SMB_OFF_T fsize ;
2007-10-19 04:40:25 +04:00
bool correct = True ;
2001-09-17 08:23:48 +04:00
char * tmp_path ;
2001-06-19 06:02:19 +04:00
2001-07-02 07:21:17 +04:00
printf ( " starting open test \n " ) ;
2009-04-22 13:51:03 +04:00
2006-07-31 13:41:25 +04:00
if ( ! torture_open_connection ( & cli1 , 0 ) ) {
2001-07-02 07:21:17 +04:00
return False ;
}
2009-04-22 13:51:03 +04:00
2003-04-18 07:35:39 +04:00
cli_setatr ( cli1 , fname , 0 , 0 ) ;
2009-04-30 05:26:02 +04:00
cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ;
2009-04-22 13:51:03 +04:00
2003-04-18 07:35:39 +04:00
cli_sockopt ( cli1 , sockops ) ;
2009-04-22 13:51:03 +04:00
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_open ( cli1 , fname , O_RDWR | O_CREAT | O_EXCL , DENY_NONE , & fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " open of %s failed (%s) \n " , fname , cli_errstr ( cli1 ) ) ;
2001-07-02 07:21:17 +04:00
return False ;
}
2001-06-19 06:02:19 +04:00
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli1 , fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " close2 failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2001-07-02 07:21:17 +04:00
return False ;
}
2009-04-22 13:51:03 +04:00
2009-05-07 03:13:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_setatr ( cli1 , fname , aRONLY , 0 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " cli_setatr failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2009-04-22 13:51:03 +04:00
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_open ( cli1 , fname , O_RDONLY , DENY_WRITE , & fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " open of %s failed (%s) \n " , fname , cli_errstr ( cli1 ) ) ;
2001-07-02 07:21:17 +04:00
return False ;
}
2009-04-22 13:51:03 +04:00
2001-06-19 06:02:19 +04:00
/* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
2009-05-01 02:26:43 +04:00
cli_open ( cli1 , fname , O_RDWR , DENY_ALL , & fnum2 ) ;
2009-04-22 13:51:03 +04:00
2003-04-18 07:35:39 +04:00
if ( check_error ( __LINE__ , cli1 , ERRDOS , ERRnoaccess ,
2001-08-20 09:15:26 +04:00
NT_STATUS_ACCESS_DENIED ) ) {
2001-06-19 06:02:19 +04:00
printf ( " correct error code ERRDOS/ERRnoaccess returned \n " ) ;
}
2009-04-22 13:51:03 +04:00
2001-07-02 07:21:17 +04:00
printf ( " finished open test 1 \n " ) ;
2009-04-22 13:51:03 +04:00
2003-04-18 07:35:39 +04:00
cli_close ( cli1 , fnum1 ) ;
2009-04-22 13:51:03 +04:00
2001-06-19 06:02:19 +04:00
/* Now try not readonly and ensure ERRbadshare is returned. */
2009-04-22 13:51:03 +04:00
2003-04-18 07:35:39 +04:00
cli_setatr ( cli1 , fname , 0 , 0 ) ;
2009-04-22 13:51:03 +04:00
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_open ( cli1 , fname , O_RDONLY , DENY_WRITE , & fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " open of %s failed (%s) \n " , fname , cli_errstr ( cli1 ) ) ;
2001-07-02 07:21:17 +04:00
return False ;
}
2009-04-22 13:51:03 +04:00
2001-06-19 06:02:19 +04:00
/* This will fail - but the error should be ERRshare. */
2009-05-01 02:26:43 +04:00
cli_open ( cli1 , fname , O_RDWR , DENY_ALL , & fnum2 ) ;
2009-04-22 13:51:03 +04:00
2003-04-18 07:35:39 +04:00
if ( check_error ( __LINE__ , cli1 , ERRDOS , ERRbadshare ,
2001-08-20 09:15:26 +04:00
NT_STATUS_SHARING_VIOLATION ) ) {
2001-06-19 06:02:19 +04:00
printf ( " correct error code ERRDOS/ERRbadshare returned \n " ) ;
}
2009-04-22 13:51:03 +04:00
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli1 , fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " close2 failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2001-07-02 07:21:17 +04:00
return False ;
}
2009-04-22 13:51:03 +04:00
2009-04-30 05:26:02 +04:00
cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ;
2009-04-22 13:51:03 +04:00
2001-07-02 07:21:17 +04:00
printf ( " finished open test 2 \n " ) ;
2009-04-22 13:51:03 +04:00
2001-06-19 06:02:19 +04:00
/* Test truncate open disposition on file opened for read. */
2009-04-22 13:51:03 +04:00
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_open ( cli1 , fname , O_RDWR | O_CREAT | O_EXCL , DENY_NONE , & fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " (3) open (1) of %s failed (%s) \n " , fname , cli_errstr ( cli1 ) ) ;
2001-07-02 07:21:17 +04:00
return False ;
}
2009-04-22 13:51:03 +04:00
2001-06-19 06:02:19 +04:00
/* write 20 bytes. */
2009-04-22 13:51:03 +04:00
2001-06-19 06:02:19 +04:00
memset ( buf , ' \0 ' , 20 ) ;
2003-04-18 07:35:39 +04:00
if ( cli_write ( cli1 , fnum1 , 0 , buf , 0 , 20 ) ! = 20 ) {
printf ( " write failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2001-07-02 07:21:17 +04:00
correct = False ;
2001-06-19 06:02:19 +04:00
}
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli1 , fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " (3) close1 failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2001-07-02 07:21:17 +04:00
return False ;
}
2009-04-22 13:51:03 +04:00
2001-06-19 06:02:19 +04:00
/* Ensure size == 20. */
2009-05-06 07:59:22 +04:00
if ( ! NT_STATUS_IS_OK ( cli_getatr ( cli1 , fname , NULL , & fsize , NULL ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " (3) getatr failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2009-04-22 13:51:03 +04:00
2001-06-19 06:02:19 +04:00
if ( fsize ! = 20 ) {
printf ( " (3) file size != 20 \n " ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
/* Now test if we can truncate a file opened for readonly. */
2009-04-22 13:51:03 +04:00
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_open ( cli1 , fname , O_RDONLY | O_TRUNC , DENY_NONE , & fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " (3) open (2) of %s failed (%s) \n " , fname , cli_errstr ( cli1 ) ) ;
2001-07-02 07:21:17 +04:00
return False ;
}
2009-04-22 13:51:03 +04:00
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli1 , fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " close2 failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2001-07-02 07:21:17 +04:00
return False ;
}
2001-06-19 06:02:19 +04:00
/* Ensure size == 0. */
2009-05-06 07:59:22 +04:00
if ( ! NT_STATUS_IS_OK ( cli_getatr ( cli1 , fname , NULL , & fsize , NULL ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " (3) getatr failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
if ( fsize ! = 0 ) {
printf ( " (3) file size != 0 \n " ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2001-07-02 07:21:17 +04:00
printf ( " finished open test 3 \n " ) ;
2009-04-22 13:51:03 +04:00
2009-04-30 05:26:02 +04:00
cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ;
2001-06-19 06:02:19 +04:00
printf ( " testing ctemp \n " ) ;
2009-06-10 22:58:00 +04:00
if ( ! NT_STATUS_IS_OK ( cli_ctemp ( cli1 , talloc_tos ( ) , " \\ " , & fnum1 , & tmp_path ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " ctemp failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2001-09-17 08:23:48 +04:00
return False ;
}
printf ( " ctemp gave path %s \n " , tmp_path ) ;
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli1 , fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " close of temp failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2001-09-17 08:23:48 +04:00
}
2009-04-30 05:26:02 +04:00
if ( ! NT_STATUS_IS_OK ( cli_unlink ( cli1 , tmp_path , aSYSTEM | aHIDDEN ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " unlink of temp failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2001-06-19 06:02:19 +04:00
}
2009-04-22 13:51:03 +04:00
2002-03-26 03:07:48 +03:00
/* Test the non-io opens... */
2006-07-31 13:41:25 +04:00
if ( ! torture_open_connection ( & cli2 , 1 ) ) {
2002-03-26 03:07:48 +03:00
return False ;
}
2009-04-22 13:51:03 +04:00
2003-04-18 07:35:39 +04:00
cli_setatr ( cli2 , fname , 0 , 0 ) ;
2009-04-30 05:26:02 +04:00
cli_unlink ( cli2 , fname , aSYSTEM | aHIDDEN ) ;
2009-04-22 13:51:03 +04:00
2003-04-18 07:35:39 +04:00
cli_sockopt ( cli2 , sockops ) ;
2002-03-26 03:07:48 +03:00
printf ( " TEST #1 testing 2 non-io opens (no delete) \n " ) ;
2009-04-22 13:51:03 +04:00
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_ntcreate ( cli1 , fname , 0 , FILE_READ_ATTRIBUTES , FILE_ATTRIBUTE_NORMAL ,
FILE_SHARE_NONE , FILE_OVERWRITE_IF , 0 , 0 , & fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " test 1 open 1 of %s failed (%s) \n " , fname , cli_errstr ( cli1 ) ) ;
2002-03-26 03:07:48 +03:00
return False ;
}
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_ntcreate ( cli2 , fname , 0 , FILE_READ_ATTRIBUTES , FILE_ATTRIBUTE_NORMAL ,
FILE_SHARE_NONE , FILE_OPEN_IF , 0 , 0 , & fnum2 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " test 1 open 2 of %s failed (%s) \n " , fname , cli_errstr ( cli2 ) ) ;
2002-03-26 03:07:48 +03:00
return False ;
}
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli1 , fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " test 1 close 1 of %s failed (%s) \n " , fname , cli_errstr ( cli1 ) ) ;
2002-03-26 03:07:48 +03:00
return False ;
}
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli2 , fnum2 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " test 1 close 2 of %s failed (%s) \n " , fname , cli_errstr ( cli2 ) ) ;
2002-03-26 03:07:48 +03:00
return False ;
}
printf ( " non-io open test #1 passed. \n " ) ;
2009-04-30 05:26:02 +04:00
cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ;
2002-03-26 03:07:48 +03:00
printf ( " TEST #2 testing 2 non-io opens (first with delete) \n " ) ;
2009-04-22 13:51:03 +04:00
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_ntcreate ( cli1 , fname , 0 , DELETE_ACCESS | FILE_READ_ATTRIBUTES , FILE_ATTRIBUTE_NORMAL ,
FILE_SHARE_NONE , FILE_OVERWRITE_IF , 0 , 0 , & fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " test 2 open 1 of %s failed (%s) \n " , fname , cli_errstr ( cli1 ) ) ;
2002-03-26 03:07:48 +03:00
return False ;
}
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_ntcreate ( cli2 , fname , 0 , FILE_READ_ATTRIBUTES , FILE_ATTRIBUTE_NORMAL ,
FILE_SHARE_NONE , FILE_OPEN_IF , 0 , 0 , & fnum2 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " test 2 open 2 of %s failed (%s) \n " , fname , cli_errstr ( cli2 ) ) ;
2002-03-26 03:07:48 +03:00
return False ;
}
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli1 , fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " test 1 close 1 of %s failed (%s) \n " , fname , cli_errstr ( cli1 ) ) ;
2002-03-26 03:07:48 +03:00
return False ;
}
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli2 , fnum2 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " test 1 close 2 of %s failed (%s) \n " , fname , cli_errstr ( cli1 ) ) ;
2002-03-26 03:07:48 +03:00
return False ;
}
printf ( " non-io open test #2 passed. \n " ) ;
2009-04-30 05:26:02 +04:00
cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ;
2002-03-26 03:07:48 +03:00
printf ( " TEST #3 testing 2 non-io opens (second with delete) \n " ) ;
2009-04-22 13:51:03 +04:00
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_ntcreate ( cli1 , fname , 0 , FILE_READ_ATTRIBUTES , FILE_ATTRIBUTE_NORMAL ,
FILE_SHARE_NONE , FILE_OVERWRITE_IF , 0 , 0 , & fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " test 3 open 1 of %s failed (%s) \n " , fname , cli_errstr ( cli1 ) ) ;
2002-03-26 03:07:48 +03:00
return False ;
}
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_ntcreate ( cli2 , fname , 0 , DELETE_ACCESS | FILE_READ_ATTRIBUTES , FILE_ATTRIBUTE_NORMAL ,
FILE_SHARE_NONE , FILE_OPEN_IF , 0 , 0 , & fnum2 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " test 3 open 2 of %s failed (%s) \n " , fname , cli_errstr ( cli2 ) ) ;
2002-03-26 03:07:48 +03:00
return False ;
}
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli1 , fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " test 3 close 1 of %s failed (%s) \n " , fname , cli_errstr ( cli1 ) ) ;
2002-03-26 03:07:48 +03:00
return False ;
}
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli2 , fnum2 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " test 3 close 2 of %s failed (%s) \n " , fname , cli_errstr ( cli2 ) ) ;
2002-03-26 03:07:48 +03:00
return False ;
}
printf ( " non-io open test #3 passed. \n " ) ;
2009-04-30 05:26:02 +04:00
cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ;
2002-03-26 03:07:48 +03:00
printf ( " TEST #4 testing 2 non-io opens (both with delete) \n " ) ;
2009-04-22 13:51:03 +04:00
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_ntcreate ( cli1 , fname , 0 , DELETE_ACCESS | FILE_READ_ATTRIBUTES , FILE_ATTRIBUTE_NORMAL ,
FILE_SHARE_NONE , FILE_OVERWRITE_IF , 0 , 0 , & fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " test 4 open 1 of %s failed (%s) \n " , fname , cli_errstr ( cli1 ) ) ;
2002-03-26 03:07:48 +03:00
return False ;
}
2009-05-01 02:26:43 +04:00
if ( NT_STATUS_IS_OK ( cli_ntcreate ( cli2 , fname , 0 , DELETE_ACCESS | FILE_READ_ATTRIBUTES , FILE_ATTRIBUTE_NORMAL ,
FILE_SHARE_NONE , FILE_OPEN_IF , 0 , 0 , & fnum2 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " test 4 open 2 of %s SUCCEEDED - should have failed (%s) \n " , fname , cli_errstr ( cli2 ) ) ;
2002-03-26 03:07:48 +03:00
return False ;
}
2003-04-18 07:35:39 +04:00
printf ( " test 3 open 2 of %s gave %s (correct error should be %s) \n " , fname , cli_errstr ( cli2 ) , " sharing violation " ) ;
2002-03-26 03:07:48 +03:00
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli1 , fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " test 4 close 1 of %s failed (%s) \n " , fname , cli_errstr ( cli1 ) ) ;
2002-03-26 03:07:48 +03:00
return False ;
}
printf ( " non-io open test #4 passed. \n " ) ;
2009-04-30 05:26:02 +04:00
cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ;
2002-03-26 03:07:48 +03:00
printf ( " TEST #5 testing 2 non-io opens (both with delete - both with file share delete) \n " ) ;
2009-04-22 13:51:03 +04:00
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_ntcreate ( cli1 , fname , 0 , DELETE_ACCESS | FILE_READ_ATTRIBUTES , FILE_ATTRIBUTE_NORMAL ,
FILE_SHARE_DELETE , FILE_OVERWRITE_IF , 0 , 0 , & fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " test 5 open 1 of %s failed (%s) \n " , fname , cli_errstr ( cli1 ) ) ;
2002-03-26 03:07:48 +03:00
return False ;
}
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_ntcreate ( cli2 , fname , 0 , DELETE_ACCESS | FILE_READ_ATTRIBUTES , FILE_ATTRIBUTE_NORMAL ,
FILE_SHARE_DELETE , FILE_OPEN_IF , 0 , 0 , & fnum2 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " test 5 open 2 of %s failed (%s) \n " , fname , cli_errstr ( cli2 ) ) ;
2002-03-26 03:07:48 +03:00
return False ;
}
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli1 , fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " test 5 close 1 of %s failed (%s) \n " , fname , cli_errstr ( cli1 ) ) ;
2002-03-26 03:07:48 +03:00
return False ;
}
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli2 , fnum2 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " test 5 close 2 of %s failed (%s) \n " , fname , cli_errstr ( cli2 ) ) ;
2002-03-26 03:07:48 +03:00
return False ;
}
printf ( " non-io open test #5 passed. \n " ) ;
2002-03-26 03:40:18 +03:00
printf ( " TEST #6 testing 1 non-io open, one io open \n " ) ;
2009-04-22 13:51:03 +04:00
2009-04-30 05:26:02 +04:00
cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ;
2002-03-26 03:40:18 +03:00
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_ntcreate ( cli1 , fname , 0 , FILE_READ_DATA , FILE_ATTRIBUTE_NORMAL ,
FILE_SHARE_NONE , FILE_OVERWRITE_IF , 0 , 0 , & fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " test 6 open 1 of %s failed (%s) \n " , fname , cli_errstr ( cli1 ) ) ;
2002-03-26 03:40:18 +03:00
return False ;
}
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_ntcreate ( cli2 , fname , 0 , FILE_READ_ATTRIBUTES , FILE_ATTRIBUTE_NORMAL ,
FILE_SHARE_READ , FILE_OPEN_IF , 0 , 0 , & fnum2 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " test 6 open 2 of %s failed (%s) \n " , fname , cli_errstr ( cli2 ) ) ;
2002-03-26 03:40:18 +03:00
return False ;
}
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli1 , fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " test 6 close 1 of %s failed (%s) \n " , fname , cli_errstr ( cli1 ) ) ;
2002-03-26 03:40:18 +03:00
return False ;
}
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli2 , fnum2 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " test 6 close 2 of %s failed (%s) \n " , fname , cli_errstr ( cli2 ) ) ;
2002-03-26 03:40:18 +03:00
return False ;
}
printf ( " non-io open test #6 passed. \n " ) ;
printf ( " TEST #7 testing 1 non-io open, one io open with delete \n " ) ;
2009-04-30 05:26:02 +04:00
cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ;
2002-03-26 03:40:18 +03:00
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_ntcreate ( cli1 , fname , 0 , FILE_READ_DATA , FILE_ATTRIBUTE_NORMAL ,
FILE_SHARE_NONE , FILE_OVERWRITE_IF , 0 , 0 , & fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " test 7 open 1 of %s failed (%s) \n " , fname , cli_errstr ( cli1 ) ) ;
2002-03-26 03:40:18 +03:00
return False ;
}
2009-05-01 02:26:43 +04:00
if ( NT_STATUS_IS_OK ( cli_ntcreate ( cli2 , fname , 0 , DELETE_ACCESS | FILE_READ_ATTRIBUTES , FILE_ATTRIBUTE_NORMAL ,
FILE_SHARE_READ | FILE_SHARE_DELETE , FILE_OPEN_IF , 0 , 0 , & fnum2 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " test 7 open 2 of %s SUCCEEDED - should have failed (%s) \n " , fname , cli_errstr ( cli2 ) ) ;
2002-03-26 03:40:18 +03:00
return False ;
}
2003-04-18 07:35:39 +04:00
printf ( " test 7 open 2 of %s gave %s (correct error should be %s) \n " , fname , cli_errstr ( cli2 ) , " sharing violation " ) ;
2002-03-26 03:40:18 +03:00
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli1 , fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " test 7 close 1 of %s failed (%s) \n " , fname , cli_errstr ( cli1 ) ) ;
2002-03-26 03:40:18 +03:00
return False ;
}
printf ( " non-io open test #7 passed. \n " ) ;
2009-04-30 05:26:02 +04:00
cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ;
2002-09-25 19:19:00 +04:00
2003-04-18 07:35:39 +04:00
if ( ! torture_close_connection ( cli1 ) ) {
correct = False ;
2002-09-25 19:19:00 +04:00
}
2003-04-18 07:35:39 +04:00
if ( ! torture_close_connection ( cli2 ) ) {
correct = False ;
2002-09-25 19:19:00 +04:00
}
2009-04-22 13:51:03 +04:00
2003-04-18 07:35:39 +04:00
return correct ;
}
2002-09-25 19:19:00 +04:00
2009-11-29 18:04:21 +03:00
NTSTATUS torture_setup_unix_extensions ( struct cli_state * cli )
{
uint16 major , minor ;
uint32 caplow , caphigh ;
NTSTATUS status ;
if ( ! SERVER_HAS_UNIX_CIFS ( cli ) ) {
printf ( " Server doesn't support UNIX CIFS extensions. \n " ) ;
return NT_STATUS_NOT_SUPPORTED ;
}
status = cli_unix_extensions_version ( cli , & major , & minor , & caplow ,
& caphigh ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " Server didn't return UNIX CIFS extensions: %s \n " ,
nt_errstr ( status ) ) ;
return status ;
}
status = cli_set_unix_extensions_capabilities ( cli , major , minor ,
caplow , caphigh ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " Server doesn't support setting UNIX CIFS extensions: "
" %s. \n " , nt_errstr ( status ) ) ;
return status ;
}
return NT_STATUS_OK ;
}
2009-03-12 00:28:47 +03:00
/*
Test POSIX open / mkdir calls .
*/
static bool run_simple_posix_open_test ( int dummy )
{
static struct cli_state * cli1 ;
2009-05-28 04:28:23 +04:00
const char * fname = " posix:file " ;
const char * hname = " posix:hlink " ;
const char * sname = " posix:symlink " ;
const char * dname = " posix:dir " ;
char buf [ 10 ] ;
2009-05-28 08:51:15 +04:00
char namebuf [ 11 ] ;
2009-05-21 05:31:36 +04:00
uint16_t fnum1 = ( uint16_t ) - 1 ;
2009-06-06 03:06:05 +04:00
SMB_STRUCT_STAT sbuf ;
2009-03-12 00:28:47 +03:00
bool correct = false ;
2009-11-13 01:07:21 +03:00
NTSTATUS status ;
2009-03-12 00:28:47 +03:00
printf ( " Starting simple POSIX open test \n " ) ;
if ( ! torture_open_connection ( & cli1 , 0 ) ) {
return false ;
}
cli_sockopt ( cli1 , sockops ) ;
2009-11-29 18:04:21 +03:00
status = torture_setup_unix_extensions ( cli1 ) ;
2009-11-13 01:07:21 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2009-03-12 00:28:47 +03:00
return false ;
}
cli_setatr ( cli1 , fname , 0 , 0 ) ;
cli_posix_unlink ( cli1 , fname ) ;
cli_setatr ( cli1 , dname , 0 , 0 ) ;
cli_posix_rmdir ( cli1 , dname ) ;
2009-05-28 04:28:23 +04:00
cli_setatr ( cli1 , hname , 0 , 0 ) ;
cli_posix_unlink ( cli1 , hname ) ;
cli_setatr ( cli1 , sname , 0 , 0 ) ;
cli_posix_unlink ( cli1 , sname ) ;
2009-03-12 00:28:47 +03:00
/* Create a directory. */
2009-05-21 05:31:36 +04:00
if ( ! NT_STATUS_IS_OK ( cli_posix_mkdir ( cli1 , dname , 0777 ) ) ) {
2009-05-05 02:50:35 +04:00
printf ( " POSIX mkdir of %s failed (%s) \n " , dname , cli_errstr ( cli1 ) ) ;
2009-03-12 00:28:47 +03:00
goto out ;
}
2009-05-21 05:31:36 +04:00
if ( ! NT_STATUS_IS_OK ( cli_posix_open ( cli1 , fname , O_RDWR | O_CREAT | O_EXCL , 0600 , & fnum1 ) ) ) {
2009-03-12 00:28:47 +03:00
printf ( " POSIX create of %s failed (%s) \n " , fname , cli_errstr ( cli1 ) ) ;
goto out ;
}
2009-06-06 03:06:05 +04:00
/* Test ftruncate - set file size. */
if ( ! NT_STATUS_IS_OK ( cli_ftruncate ( cli1 , fnum1 , 1000 ) ) ) {
printf ( " ftruncate failed (%s) \n " , cli_errstr ( cli1 ) ) ;
goto out ;
}
/* Ensure st_size == 1000 */
if ( ! NT_STATUS_IS_OK ( cli_posix_stat ( cli1 , fname , & sbuf ) ) ) {
printf ( " stat failed (%s) \n " , cli_errstr ( cli1 ) ) ;
goto out ;
}
if ( sbuf . st_ex_size ! = 1000 ) {
printf ( " ftruncate - stat size (%u) != 1000 \n " , ( unsigned int ) sbuf . st_ex_size ) ;
goto out ;
}
/* Test ftruncate - set file size back to zero. */
if ( ! NT_STATUS_IS_OK ( cli_ftruncate ( cli1 , fnum1 , 0 ) ) ) {
printf ( " ftruncate failed (%s) \n " , cli_errstr ( cli1 ) ) ;
goto out ;
}
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli1 , fnum1 ) ) ) {
2009-03-12 00:28:47 +03:00
printf ( " close failed (%s) \n " , cli_errstr ( cli1 ) ) ;
goto out ;
}
/* Now open the file again for read only. */
2009-05-21 05:31:36 +04:00
if ( ! NT_STATUS_IS_OK ( cli_posix_open ( cli1 , fname , O_RDONLY , 0 , & fnum1 ) ) ) {
2009-03-12 00:28:47 +03:00
printf ( " POSIX open of %s failed (%s) \n " , fname , cli_errstr ( cli1 ) ) ;
goto out ;
}
/* Now unlink while open. */
2009-04-29 00:18:51 +04:00
if ( ! NT_STATUS_IS_OK ( cli_posix_unlink ( cli1 , fname ) ) ) {
2009-03-12 00:28:47 +03:00
printf ( " POSIX unlink of %s failed (%s) \n " , fname , cli_errstr ( cli1 ) ) ;
goto out ;
}
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli1 , fnum1 ) ) ) {
2009-03-12 00:28:47 +03:00
printf ( " close(2) failed (%s) \n " , cli_errstr ( cli1 ) ) ;
goto out ;
}
/* Ensure the file has gone. */
2009-05-21 05:31:36 +04:00
if ( NT_STATUS_IS_OK ( cli_posix_open ( cli1 , fname , O_RDONLY , 0 , & fnum1 ) ) ) {
2009-03-12 00:28:47 +03:00
printf ( " POSIX open of %s succeeded, should have been deleted. \n " , fname ) ;
goto out ;
}
2009-05-23 02:21:55 +04:00
/* What happens when we try and POSIX open a directory ? */
if ( NT_STATUS_IS_OK ( cli_posix_open ( cli1 , dname , O_RDONLY , 0 , & fnum1 ) ) ) {
printf ( " POSIX open of directory %s succeeded, should have failed. \n " , fname ) ;
goto out ;
} else {
if ( ! check_error ( __LINE__ , cli1 , ERRDOS , EISDIR ,
NT_STATUS_FILE_IS_A_DIRECTORY ) ) {
goto out ;
}
}
2009-05-28 04:28:23 +04:00
/* Create the file. */
if ( ! NT_STATUS_IS_OK ( cli_posix_open ( cli1 , fname , O_RDWR | O_CREAT | O_EXCL , 0600 , & fnum1 ) ) ) {
printf ( " POSIX create of %s failed (%s) \n " , fname , cli_errstr ( cli1 ) ) ;
goto out ;
}
/* Write some data into it. */
if ( cli_write ( cli1 , fnum1 , 0 , " TEST DATA \n " , 0 , 10 ) ! = 10 ) {
printf ( " cli_write failed: %s \n " , cli_errstr ( cli1 ) ) ;
goto out ;
}
cli_close ( cli1 , fnum1 ) ;
/* Now create a hardlink. */
if ( ! NT_STATUS_IS_OK ( cli_posix_hardlink ( cli1 , fname , hname ) ) ) {
printf ( " POSIX hardlink of %s failed (%s) \n " , hname , cli_errstr ( cli1 ) ) ;
goto out ;
}
/* Now create a symlink. */
if ( ! NT_STATUS_IS_OK ( cli_posix_symlink ( cli1 , fname , sname ) ) ) {
printf ( " POSIX symlink of %s failed (%s) \n " , sname , cli_errstr ( cli1 ) ) ;
goto out ;
}
/* Open the hardlink for read. */
if ( ! NT_STATUS_IS_OK ( cli_posix_open ( cli1 , hname , O_RDONLY , 0 , & fnum1 ) ) ) {
printf ( " POSIX open of %s failed (%s) \n " , hname , cli_errstr ( cli1 ) ) ;
goto out ;
}
if ( cli_read ( cli1 , fnum1 , buf , 0 , 10 ) ! = 10 ) {
printf ( " POSIX read of %s failed (%s) \n " , hname , cli_errstr ( cli1 ) ) ;
goto out ;
}
if ( memcmp ( buf , " TEST DATA \n " , 10 ) ) {
printf ( " invalid data read from hardlink \n " ) ;
goto out ;
}
2009-07-14 05:43:10 +04:00
/* Do a POSIX lock/unlock. */
2009-07-15 22:49:33 +04:00
if ( ! NT_STATUS_IS_OK ( cli_posix_lock ( cli1 , fnum1 , 0 , 100 , true , READ_LOCK ) ) ) {
printf ( " POSIX lock failed %s \n " , cli_errstr ( cli1 ) ) ;
2009-07-14 05:43:10 +04:00
goto out ;
}
/* Punch a hole in the locked area. */
if ( ! NT_STATUS_IS_OK ( cli_posix_unlock ( cli1 , fnum1 , 10 , 80 ) ) ) {
2009-07-15 22:49:33 +04:00
printf ( " POSIX unlock failed %s \n " , cli_errstr ( cli1 ) ) ;
2009-07-14 05:43:10 +04:00
goto out ;
}
2009-05-28 04:28:23 +04:00
cli_close ( cli1 , fnum1 ) ;
/* Open the symlink for read - this should fail. A POSIX
client should not be doing opens on a symlink . */
if ( NT_STATUS_IS_OK ( cli_posix_open ( cli1 , sname , O_RDONLY , 0 , & fnum1 ) ) ) {
printf ( " POSIX open of %s succeeded (should have failed) \n " , sname ) ;
goto out ;
} else {
if ( ! check_error ( __LINE__ , cli1 , ERRDOS , ERRbadpath ,
NT_STATUS_OBJECT_PATH_NOT_FOUND ) ) {
2009-05-28 08:51:15 +04:00
printf ( " POSIX open of %s should have failed "
" with NT_STATUS_OBJECT_PATH_NOT_FOUND, "
" failed with %s instead. \n " ,
sname , cli_errstr ( cli1 ) ) ;
2009-05-28 04:28:23 +04:00
goto out ;
}
}
2009-05-28 08:51:15 +04:00
if ( ! NT_STATUS_IS_OK ( cli_posix_readlink ( cli1 , sname , namebuf , sizeof ( namebuf ) ) ) ) {
printf ( " POSIX readlink on %s failed (%s) \n " , sname , cli_errstr ( cli1 ) ) ;
goto out ;
}
if ( strcmp ( namebuf , fname ) ! = 0 ) {
printf ( " POSIX readlink on %s failed to match name %s (read %s) \n " ,
sname , fname , namebuf ) ;
goto out ;
}
2009-05-28 04:28:23 +04:00
2009-04-29 00:18:51 +04:00
if ( ! NT_STATUS_IS_OK ( cli_posix_rmdir ( cli1 , dname ) ) ) {
2009-03-12 00:28:47 +03:00
printf ( " POSIX rmdir failed (%s) \n " , cli_errstr ( cli1 ) ) ;
goto out ;
}
printf ( " Simple POSIX open test passed \n " ) ;
correct = true ;
out :
2009-05-21 23:17:53 +04:00
if ( fnum1 ! = ( uint16_t ) - 1 ) {
2009-03-12 00:28:47 +03:00
cli_close ( cli1 , fnum1 ) ;
2009-05-23 02:21:55 +04:00
fnum1 = ( uint16_t ) - 1 ;
2009-03-12 00:28:47 +03:00
}
2009-05-28 04:28:23 +04:00
cli_setatr ( cli1 , sname , 0 , 0 ) ;
cli_posix_unlink ( cli1 , sname ) ;
cli_setatr ( cli1 , hname , 0 , 0 ) ;
cli_posix_unlink ( cli1 , hname ) ;
2009-03-12 00:28:47 +03:00
cli_setatr ( cli1 , fname , 0 , 0 ) ;
cli_posix_unlink ( cli1 , fname ) ;
cli_setatr ( cli1 , dname , 0 , 0 ) ;
cli_posix_rmdir ( cli1 , dname ) ;
if ( ! torture_close_connection ( cli1 ) ) {
correct = false ;
}
return correct ;
}
2003-04-18 07:35:39 +04:00
static uint32 open_attrs_table [ ] = {
FILE_ATTRIBUTE_NORMAL ,
FILE_ATTRIBUTE_ARCHIVE ,
FILE_ATTRIBUTE_READONLY ,
FILE_ATTRIBUTE_HIDDEN ,
FILE_ATTRIBUTE_SYSTEM ,
FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_READONLY ,
FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_HIDDEN ,
FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_SYSTEM ,
FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN ,
FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM ,
FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM ,
FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN ,
FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM ,
FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM ,
FILE_ATTRIBUTE_HIDDEN , FILE_ATTRIBUTE_SYSTEM ,
} ;
struct trunc_open_results {
unsigned int num ;
uint32 init_attr ;
uint32 trunc_attr ;
uint32 result_attr ;
} ;
static struct trunc_open_results attr_results [ ] = {
{ 0 , FILE_ATTRIBUTE_NORMAL , FILE_ATTRIBUTE_NORMAL , FILE_ATTRIBUTE_ARCHIVE } ,
{ 1 , FILE_ATTRIBUTE_NORMAL , FILE_ATTRIBUTE_ARCHIVE , FILE_ATTRIBUTE_ARCHIVE } ,
{ 2 , FILE_ATTRIBUTE_NORMAL , FILE_ATTRIBUTE_READONLY , FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_READONLY } ,
{ 16 , FILE_ATTRIBUTE_ARCHIVE , FILE_ATTRIBUTE_NORMAL , FILE_ATTRIBUTE_ARCHIVE } ,
{ 17 , FILE_ATTRIBUTE_ARCHIVE , FILE_ATTRIBUTE_ARCHIVE , FILE_ATTRIBUTE_ARCHIVE } ,
{ 18 , FILE_ATTRIBUTE_ARCHIVE , FILE_ATTRIBUTE_READONLY , FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_READONLY } ,
{ 51 , FILE_ATTRIBUTE_HIDDEN , FILE_ATTRIBUTE_HIDDEN , FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_HIDDEN } ,
{ 54 , FILE_ATTRIBUTE_HIDDEN , FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_HIDDEN , FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_HIDDEN } ,
{ 56 , FILE_ATTRIBUTE_HIDDEN , FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN , FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN } ,
{ 68 , FILE_ATTRIBUTE_SYSTEM , FILE_ATTRIBUTE_SYSTEM , FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_SYSTEM } ,
{ 71 , FILE_ATTRIBUTE_SYSTEM , FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_SYSTEM , FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_SYSTEM } ,
{ 73 , FILE_ATTRIBUTE_SYSTEM , FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM , FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM } ,
{ 99 , FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_HIDDEN , FILE_ATTRIBUTE_HIDDEN , FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_HIDDEN } ,
{ 102 , FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_HIDDEN , FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_HIDDEN , FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_HIDDEN } ,
{ 104 , FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_HIDDEN , FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN , FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN } ,
{ 116 , FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_SYSTEM , FILE_ATTRIBUTE_SYSTEM , FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_SYSTEM } ,
{ 119 , FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_SYSTEM , FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_SYSTEM , FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_SYSTEM } ,
{ 121 , FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_SYSTEM , FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM , FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM } ,
{ 170 , FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN , FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN , FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN } ,
{ 173 , FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN , FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM , FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM } ,
{ 227 , FILE_ATTRIBUTE_HIDDEN , FILE_ATTRIBUTE_HIDDEN , FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_HIDDEN } ,
{ 230 , FILE_ATTRIBUTE_HIDDEN , FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_HIDDEN , FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_HIDDEN } ,
{ 232 , FILE_ATTRIBUTE_HIDDEN , FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN , FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN } ,
{ 244 , FILE_ATTRIBUTE_SYSTEM , FILE_ATTRIBUTE_SYSTEM , FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_SYSTEM } ,
{ 247 , FILE_ATTRIBUTE_SYSTEM , FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_SYSTEM , FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_SYSTEM } ,
{ 249 , FILE_ATTRIBUTE_SYSTEM , FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM , FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM }
} ;
2007-10-19 04:40:25 +04:00
static bool run_openattrtest ( int dummy )
2003-04-18 07:35:39 +04:00
{
static struct cli_state * cli1 ;
const char * fname = " \\ openattr.file " ;
2009-05-01 02:26:43 +04:00
uint16_t fnum1 ;
2007-10-19 04:40:25 +04:00
bool correct = True ;
2003-04-18 07:35:39 +04:00
uint16 attr ;
unsigned int i , j , k , l ;
2002-09-25 19:19:00 +04:00
2003-04-18 07:35:39 +04:00
printf ( " starting open attr test \n " ) ;
2009-04-22 13:51:03 +04:00
2006-07-31 13:41:25 +04:00
if ( ! torture_open_connection ( & cli1 , 0 ) ) {
2002-09-25 19:19:00 +04:00
return False ;
}
2009-04-22 13:51:03 +04:00
2003-04-18 07:35:39 +04:00
cli_sockopt ( cli1 , sockops ) ;
2002-09-25 19:19:00 +04:00
2003-04-18 07:35:39 +04:00
for ( k = 0 , i = 0 ; i < sizeof ( open_attrs_table ) / sizeof ( uint32 ) ; i + + ) {
cli_setatr ( cli1 , fname , 0 , 0 ) ;
2009-04-30 05:26:02 +04:00
cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ;
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_ntcreate ( cli1 , fname , 0 , FILE_WRITE_DATA , open_attrs_table [ i ] ,
FILE_SHARE_NONE , FILE_OVERWRITE_IF , 0 , 0 , & fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " open %d (1) of %s failed (%s) \n " , i , fname , cli_errstr ( cli1 ) ) ;
return False ;
2002-09-25 19:19:00 +04:00
}
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli1 , fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " close %d (1) of %s failed (%s) \n " , i , fname , cli_errstr ( cli1 ) ) ;
return False ;
}
2002-11-19 02:13:25 +03:00
2003-04-18 07:35:39 +04:00
for ( j = 0 ; j < sizeof ( open_attrs_table ) / sizeof ( uint32 ) ; j + + ) {
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_ntcreate ( cli1 , fname , 0 , FILE_READ_DATA | FILE_WRITE_DATA , open_attrs_table [ j ] ,
FILE_SHARE_NONE , FILE_OVERWRITE , 0 , 0 , & fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
for ( l = 0 ; l < sizeof ( attr_results ) / sizeof ( struct trunc_open_results ) ; l + + ) {
if ( attr_results [ l ] . num = = k ) {
printf ( " [%d] trunc open 0x%x -> 0x%x of %s failed - should have succeeded !(0x%x:%s) \n " ,
k , open_attrs_table [ i ] ,
open_attrs_table [ j ] ,
fname , NT_STATUS_V ( cli_nt_error ( cli1 ) ) , cli_errstr ( cli1 ) ) ;
correct = False ;
}
}
if ( NT_STATUS_V ( cli_nt_error ( cli1 ) ) ! = NT_STATUS_V ( NT_STATUS_ACCESS_DENIED ) ) {
printf ( " [%d] trunc open 0x%x -> 0x%x failed with wrong error code %s \n " ,
k , open_attrs_table [ i ] , open_attrs_table [ j ] ,
cli_errstr ( cli1 ) ) ;
correct = False ;
}
#if 0
printf ( " [%d] trunc open 0x%x -> 0x%x failed \n " , k , open_attrs_table [ i ] , open_attrs_table [ j ] ) ;
# endif
k + + ;
continue ;
}
2002-11-19 02:13:25 +03:00
2009-05-01 03:57:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_close ( cli1 , fnum1 ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " close %d (2) of %s failed (%s) \n " , j , fname , cli_errstr ( cli1 ) ) ;
return False ;
}
2002-11-19 02:13:25 +03:00
2009-05-06 07:59:22 +04:00
if ( ! NT_STATUS_IS_OK ( cli_getatr ( cli1 , fname , & attr , NULL , NULL ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " getatr(2) failed (%s) \n " , cli_errstr ( cli1 ) ) ;
return False ;
}
2002-11-19 02:13:25 +03:00
2003-04-18 07:35:39 +04:00
#if 0
printf ( " [%d] getatr check [0x%x] trunc [0x%x] got attr 0x%x \n " ,
k , open_attrs_table [ i ] , open_attrs_table [ j ] , attr ) ;
# endif
2002-11-19 02:13:25 +03:00
2003-04-18 07:35:39 +04:00
for ( l = 0 ; l < sizeof ( attr_results ) / sizeof ( struct trunc_open_results ) ; l + + ) {
if ( attr_results [ l ] . num = = k ) {
if ( attr ! = attr_results [ l ] . result_attr | |
open_attrs_table [ i ] ! = attr_results [ l ] . init_attr | |
open_attrs_table [ j ] ! = attr_results [ l ] . trunc_attr ) {
printf ( " getatr check failed. [0x%x] trunc [0x%x] got attr 0x%x, should be 0x%x \n " ,
open_attrs_table [ i ] ,
open_attrs_table [ j ] ,
( unsigned int ) attr ,
attr_results [ l ] . result_attr ) ;
correct = False ;
}
break ;
}
}
k + + ;
}
2002-11-19 02:13:25 +03:00
}
2003-04-18 07:35:39 +04:00
cli_setatr ( cli1 , fname , 0 , 0 ) ;
2009-04-30 05:26:02 +04:00
cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ;
2002-11-19 02:13:25 +03:00
2003-04-18 07:35:39 +04:00
printf ( " open attr test %s. \n " , correct ? " passed " : " failed " ) ;
2002-09-25 19:19:00 +04:00
2003-04-18 07:35:39 +04:00
if ( ! torture_close_connection ( cli1 ) ) {
2002-03-26 03:07:48 +03:00
correct = False ;
}
2001-07-02 07:21:17 +04:00
return correct ;
2001-06-19 06:02:19 +04:00
}
2005-02-28 10:01:52 +03:00
static void list_fn ( const char * mnt , file_info * finfo , const char * name , void * state )
2001-06-19 06:02:19 +04:00
{
2009-04-22 13:51:03 +04:00
2001-06-19 06:02:19 +04:00
}
/*
test directory listing speed
*/
2007-10-19 04:40:25 +04:00
static bool run_dirtest ( int dummy )
2001-06-19 06:02:19 +04:00
{
int i ;
2003-04-18 07:35:39 +04:00
static struct cli_state * cli ;
2009-05-01 02:26:43 +04:00
uint16_t fnum ;
2009-11-24 12:59:09 +03:00
struct timeval core_start ;
2007-10-19 04:40:25 +04:00
bool correct = True ;
2001-06-19 06:02:19 +04:00
printf ( " starting directory test \n " ) ;
2006-07-31 13:41:25 +04:00
if ( ! torture_open_connection ( & cli , 0 ) ) {
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2003-04-18 07:35:39 +04:00
cli_sockopt ( cli , sockops ) ;
2001-06-19 06:02:19 +04:00
srandom ( 0 ) ;
2002-04-12 14:18:46 +04:00
for ( i = 0 ; i < torture_numops ; i + + ) {
2001-06-19 06:02:19 +04:00
fstring fname ;
2002-03-03 23:47:44 +03:00
slprintf ( fname , sizeof ( fname ) , " \\ %x " , ( int ) random ( ) ) ;
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_open ( cli , fname , O_RDWR | O_CREAT , DENY_NONE , & fnum ) ) ) {
2001-06-19 06:02:19 +04:00
fprintf ( stderr , " Failed to open %s \n " , fname ) ;
2001-07-02 07:21:17 +04:00
return False ;
2001-06-19 06:02:19 +04:00
}
2003-04-18 07:35:39 +04:00
cli_close ( cli , fnum ) ;
2001-06-19 06:02:19 +04:00
}
2009-11-24 12:59:09 +03:00
core_start = timeval_current ( ) ;
2001-06-19 06:02:19 +04:00
2003-04-18 07:35:39 +04:00
printf ( " Matched %d \n " , cli_list ( cli , " a*.* " , 0 , list_fn , NULL ) ) ;
printf ( " Matched %d \n " , cli_list ( cli , " b*.* " , 0 , list_fn , NULL ) ) ;
printf ( " Matched %d \n " , cli_list ( cli , " xyzabc " , 0 , list_fn , NULL ) ) ;
2001-06-19 06:02:19 +04:00
2009-11-24 12:59:09 +03:00
printf ( " dirtest core %g seconds \n " , timeval_elapsed ( & core_start ) ) ;
2001-06-19 06:02:19 +04:00
srandom ( 0 ) ;
2002-04-12 14:18:46 +04:00
for ( i = 0 ; i < torture_numops ; i + + ) {
2001-06-19 06:02:19 +04:00
fstring fname ;
2002-03-03 23:47:44 +03:00
slprintf ( fname , sizeof ( fname ) , " \\ %x " , ( int ) random ( ) ) ;
2009-04-30 05:26:02 +04:00
cli_unlink ( cli , fname , aSYSTEM | aHIDDEN ) ;
2001-06-19 06:02:19 +04:00
}
2003-04-18 07:35:39 +04:00
if ( ! torture_close_connection ( cli ) ) {
2001-07-02 07:21:17 +04:00
correct = False ;
}
2001-06-19 06:02:19 +04:00
printf ( " finished dirtest \n " ) ;
2001-07-02 07:21:17 +04:00
return correct ;
2001-06-19 06:02:19 +04:00
}
2005-02-28 10:01:52 +03:00
static void del_fn ( const char * mnt , file_info * finfo , const char * mask , void * state )
2002-09-25 19:19:00 +04:00
{
struct cli_state * pcli = ( struct cli_state * ) state ;
fstring fname ;
slprintf ( fname , sizeof ( fname ) , " \\ LISTDIR \\ %s " , finfo - > name ) ;
if ( strcmp ( finfo - > name , " . " ) = = 0 | | strcmp ( finfo - > name , " .. " ) = = 0 )
return ;
if ( finfo - > mode & aDIR ) {
2009-04-21 17:52:54 +04:00
if ( ! NT_STATUS_IS_OK ( cli_rmdir ( pcli , fname ) ) )
2002-09-25 19:19:00 +04:00
printf ( " del_fn: failed to rmdir %s \n , " , fname ) ;
} else {
2009-04-30 05:26:02 +04:00
if ( ! NT_STATUS_IS_OK ( cli_unlink ( pcli , fname , aSYSTEM | aHIDDEN ) ) )
2002-09-25 19:19:00 +04:00
printf ( " del_fn: failed to unlink %s \n , " , fname ) ;
}
}
2003-04-18 07:35:39 +04:00
2003-04-23 12:12:34 +04:00
/*
sees what IOCTLs are supported
*/
2007-10-19 04:40:25 +04:00
bool torture_ioctl_test ( int dummy )
2003-04-23 12:12:34 +04:00
{
static struct cli_state * cli ;
2009-05-01 02:26:43 +04:00
uint16_t device , function ;
uint16_t fnum ;
2003-04-23 12:12:34 +04:00
const char * fname = " \\ ioctl.dat " ;
DATA_BLOB blob ;
NTSTATUS status ;
2006-07-31 13:41:25 +04:00
if ( ! torture_open_connection ( & cli , 0 ) ) {
2003-04-23 12:12:34 +04:00
return False ;
}
printf ( " starting ioctl test \n " ) ;
2009-04-30 05:26:02 +04:00
cli_unlink ( cli , fname , aSYSTEM | aHIDDEN ) ;
2003-04-23 12:12:34 +04:00
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_open ( cli , fname , O_RDWR | O_CREAT | O_EXCL , DENY_NONE , & fnum ) ) ) {
2003-04-23 12:12:34 +04:00
printf ( " open of %s failed (%s) \n " , fname , cli_errstr ( cli ) ) ;
return False ;
}
status = cli_raw_ioctl ( cli , fnum , 0x2d0000 | ( 0x0420 < < 2 ) , & blob ) ;
2010-02-21 13:41:54 +03:00
printf ( " ioctl device info: %s \n " , nt_errstr ( status ) ) ;
2003-04-23 12:12:34 +04:00
status = cli_raw_ioctl ( cli , fnum , IOCTL_QUERY_JOB_INFO , & blob ) ;
2010-02-21 13:41:54 +03:00
printf ( " ioctl job info: %s \n " , nt_errstr ( status ) ) ;
2003-04-23 12:12:34 +04:00
for ( device = 0 ; device < 0x100 ; device + + ) {
printf ( " testing device=0x%x \n " , device ) ;
for ( function = 0 ; function < 0x100 ; function + + ) {
uint32 code = ( device < < 16 ) | function ;
status = cli_raw_ioctl ( cli , fnum , code , & blob ) ;
if ( NT_STATUS_IS_OK ( status ) ) {
2006-07-12 01:23:44 +04:00
printf ( " ioctl 0x%x OK : %d bytes \n " , ( int ) code ,
2006-07-22 23:29:02 +04:00
( int ) blob . length ) ;
2003-04-23 12:12:34 +04:00
data_blob_free ( & blob ) ;
}
}
}
if ( ! torture_close_connection ( cli ) ) {
return False ;
}
return True ;
}
2003-04-18 07:35:39 +04:00
/*
tries varients of chkpath
*/
2007-10-19 04:40:25 +04:00
bool torture_chkpath_test ( int dummy )
2003-04-18 07:35:39 +04:00
{
static struct cli_state * cli ;
2009-05-01 02:26:43 +04:00
uint16_t fnum ;
2007-10-19 04:40:25 +04:00
bool ret ;
2003-04-18 07:35:39 +04:00
2006-07-31 13:41:25 +04:00
if ( ! torture_open_connection ( & cli , 0 ) ) {
2003-04-18 07:35:39 +04:00
return False ;
}
printf ( " starting chkpath test \n " ) ;
/* cleanup from an old run */
cli_rmdir ( cli , " \\ chkpath.dir \\ dir2 " ) ;
2009-04-30 05:26:02 +04:00
cli_unlink ( cli , " \\ chkpath.dir \\ * " , aSYSTEM | aHIDDEN ) ;
2003-04-18 07:35:39 +04:00
cli_rmdir ( cli , " \\ chkpath.dir " ) ;
2009-04-21 16:52:34 +04:00
if ( ! NT_STATUS_IS_OK ( cli_mkdir ( cli , " \\ chkpath.dir " ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " mkdir1 failed : %s \n " , cli_errstr ( cli ) ) ;
return False ;
}
2009-04-21 16:52:34 +04:00
if ( ! NT_STATUS_IS_OK ( cli_mkdir ( cli , " \\ chkpath.dir \\ dir2 " ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " mkdir2 failed : %s \n " , cli_errstr ( cli ) ) ;
return False ;
}
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_open ( cli , " \\ chkpath.dir \\ foo.txt " , O_RDWR | O_CREAT | O_EXCL , DENY_NONE , & fnum ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " open1 failed (%s) \n " , cli_errstr ( cli ) ) ;
return False ;
}
cli_close ( cli , fnum ) ;
2009-04-22 17:46:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_chkpath ( cli , " \\ chkpath.dir " ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " chkpath1 failed: %s \n " , cli_errstr ( cli ) ) ;
ret = False ;
}
2009-04-22 17:46:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_chkpath ( cli , " \\ chkpath.dir \\ dir2 " ) ) ) {
2003-04-18 07:35:39 +04:00
printf ( " chkpath2 failed: %s \n " , cli_errstr ( cli ) ) ;
ret = False ;
}
2009-04-22 17:46:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_chkpath ( cli , " \\ chkpath.dir \\ foo.txt " ) ) ) {
2003-04-18 07:35:39 +04:00
ret = check_error ( __LINE__ , cli , ERRDOS , ERRbadpath ,
NT_STATUS_NOT_A_DIRECTORY ) ;
} else {
printf ( " * chkpath on a file should fail \n " ) ;
ret = False ;
}
2009-04-22 17:46:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_chkpath ( cli , " \\ chkpath.dir \\ bar.txt " ) ) ) {
2003-04-18 07:35:39 +04:00
ret = check_error ( __LINE__ , cli , ERRDOS , ERRbadfile ,
NT_STATUS_OBJECT_NAME_NOT_FOUND ) ;
} else {
printf ( " * chkpath on a non existant file should fail \n " ) ;
ret = False ;
}
2009-04-22 17:46:42 +04:00
if ( ! NT_STATUS_IS_OK ( cli_chkpath ( cli , " \\ chkpath.dir \\ dirxx \\ bar.txt " ) ) ) {
2003-04-18 07:35:39 +04:00
ret = check_error ( __LINE__ , cli , ERRDOS , ERRbadpath ,
NT_STATUS_OBJECT_PATH_NOT_FOUND ) ;
} else {
printf ( " * chkpath on a non existent component should fail \n " ) ;
ret = False ;
}
cli_rmdir ( cli , " \\ chkpath.dir \\ dir2 " ) ;
2009-04-30 05:26:02 +04:00
cli_unlink ( cli , " \\ chkpath.dir \\ * " , aSYSTEM | aHIDDEN ) ;
2003-04-18 07:35:39 +04:00
cli_rmdir ( cli , " \\ chkpath.dir " ) ;
if ( ! torture_close_connection ( cli ) ) {
return False ;
}
return ret ;
}
2007-10-19 04:40:25 +04:00
static bool run_eatest ( int dummy )
2004-03-27 05:13:58 +03:00
{
static struct cli_state * cli ;
const char * fname = " \\ eatest.txt " ;
2007-10-19 04:40:25 +04:00
bool correct = True ;
2009-05-01 02:26:43 +04:00
uint16_t fnum ;
int i ;
2004-03-30 02:21:47 +04:00
size_t num_eas ;
struct ea_struct * ea_list = NULL ;
TALLOC_CTX * mem_ctx = talloc_init ( " eatest " ) ;
2004-03-27 05:13:58 +03:00
printf ( " starting eatest \n " ) ;
2009-04-22 13:51:03 +04:00
2006-07-31 13:41:25 +04:00
if ( ! torture_open_connection ( & cli , 0 ) ) {
2007-03-01 05:43:33 +03:00
talloc_destroy ( mem_ctx ) ;
2004-03-27 05:13:58 +03:00
return False ;
}
2009-04-22 13:51:03 +04:00
2009-04-30 05:26:02 +04:00
cli_unlink ( cli , fname , aSYSTEM | aHIDDEN ) ;
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_ntcreate ( cli , fname , 0 ,
2004-03-27 05:13:58 +03:00
FIRST_DESIRED_ACCESS , FILE_ATTRIBUTE_ARCHIVE ,
FILE_SHARE_NONE , FILE_OVERWRITE_IF ,
2009-05-01 02:26:43 +04:00
0x4044 , 0 , & fnum ) ) ) {
2004-03-27 05:13:58 +03:00
printf ( " open failed - %s \n " , cli_errstr ( cli ) ) ;
2007-03-01 05:43:33 +03:00
talloc_destroy ( mem_ctx ) ;
2004-03-27 05:13:58 +03:00
return False ;
}
2003-04-18 07:35:39 +04:00
2004-03-27 05:13:58 +03:00
for ( i = 0 ; i < 10 ; i + + ) {
fstring ea_name , ea_val ;
2003-04-18 07:35:39 +04:00
2004-03-27 05:13:58 +03:00
slprintf ( ea_name , sizeof ( ea_name ) , " EA_%d " , i ) ;
memset ( ea_val , ( char ) i + 1 , i + 1 ) ;
2004-03-30 02:21:47 +04:00
if ( ! cli_set_ea_fnum ( cli , fnum , ea_name , ea_val , i + 1 ) ) {
2004-03-27 05:13:58 +03:00
printf ( " ea_set of name %s failed - %s \n " , ea_name , cli_errstr ( cli ) ) ;
2007-03-01 05:43:33 +03:00
talloc_destroy ( mem_ctx ) ;
2004-03-27 05:13:58 +03:00
return False ;
}
}
2009-04-22 13:51:03 +04:00
2004-03-27 05:13:58 +03:00
cli_close ( cli , fnum ) ;
for ( i = 0 ; i < 10 ; i + + ) {
fstring ea_name , ea_val ;
2004-03-30 02:21:47 +04:00
slprintf ( ea_name , sizeof ( ea_name ) , " EA_%d " , i + 10 ) ;
2004-03-27 05:13:58 +03:00
memset ( ea_val , ( char ) i + 1 , i + 1 ) ;
2004-03-30 02:21:47 +04:00
if ( ! cli_set_ea_path ( cli , fname , ea_name , ea_val , i + 1 ) ) {
2004-03-27 05:13:58 +03:00
printf ( " ea_set of name %s failed - %s \n " , ea_name , cli_errstr ( cli ) ) ;
2007-03-01 05:43:33 +03:00
talloc_destroy ( mem_ctx ) ;
2004-03-27 05:13:58 +03:00
return False ;
}
}
2009-04-22 13:51:03 +04:00
2004-03-30 02:21:47 +04:00
if ( ! cli_get_ea_list_path ( cli , fname , mem_ctx , & num_eas , & ea_list ) ) {
printf ( " ea_get list failed - %s \n " , cli_errstr ( cli ) ) ;
correct = False ;
}
2006-07-12 01:23:44 +04:00
printf ( " num_eas = %d \n " , ( int ) num_eas ) ;
2004-03-30 22:38:21 +04:00
if ( num_eas ! = 20 ) {
printf ( " Should be 20 EA's stored... failing. \n " ) ;
correct = False ;
}
2004-03-30 02:21:47 +04:00
for ( i = 0 ; i < num_eas ; i + + ) {
printf ( " %d: ea_name = %s. Val = " , i , ea_list [ i ] . name ) ;
2007-03-28 17:34:59 +04:00
dump_data ( 0 , ea_list [ i ] . value . data ,
2006-07-11 22:01:26 +04:00
ea_list [ i ] . value . length ) ;
2004-03-30 02:21:47 +04:00
}
2004-03-27 05:13:58 +03:00
2004-03-30 03:39:13 +04:00
/* Setting EA's to zero length deletes them. Test this */
2004-04-06 18:24:13 +04:00
printf ( " Now deleting all EA's - case indepenent.... \n " ) ;
2004-03-30 03:39:13 +04:00
2005-10-31 23:11:58 +03:00
# if 1
cli_set_ea_path ( cli , fname , " " , " " , 0 ) ;
# else
2004-03-30 03:39:13 +04:00
for ( i = 0 ; i < 20 ; i + + ) {
fstring ea_name ;
2004-04-06 18:24:13 +04:00
slprintf ( ea_name , sizeof ( ea_name ) , " ea_%d " , i ) ;
2004-03-30 03:39:13 +04:00
if ( ! cli_set_ea_path ( cli , fname , ea_name , " " , 0 ) ) {
printf ( " ea_set of name %s failed - %s \n " , ea_name , cli_errstr ( cli ) ) ;
2007-03-01 05:43:33 +03:00
talloc_destroy ( mem_ctx ) ;
2004-03-30 03:39:13 +04:00
return False ;
}
}
2005-10-31 23:11:58 +03:00
# endif
2004-03-30 03:39:13 +04:00
if ( ! cli_get_ea_list_path ( cli , fname , mem_ctx , & num_eas , & ea_list ) ) {
printf ( " ea_get list failed - %s \n " , cli_errstr ( cli ) ) ;
correct = False ;
}
2006-07-12 01:23:44 +04:00
printf ( " num_eas = %d \n " , ( int ) num_eas ) ;
2004-03-30 03:39:13 +04:00
for ( i = 0 ; i < num_eas ; i + + ) {
printf ( " %d: ea_name = %s. Val = " , i , ea_list [ i ] . name ) ;
2007-03-28 17:34:59 +04:00
dump_data ( 0 , ea_list [ i ] . value . data ,
2006-07-11 22:01:26 +04:00
ea_list [ i ] . value . length ) ;
2004-03-30 03:39:13 +04:00
}
if ( num_eas ! = 0 ) {
printf ( " deleting EA's failed. \n " ) ;
correct = False ;
}
2004-03-30 22:38:21 +04:00
/* Try and delete a non existant EA. */
if ( ! cli_set_ea_path ( cli , fname , " foo " , " " , 0 ) ) {
printf ( " deleting non-existant EA 'foo' should succeed. %s \n " , cli_errstr ( cli ) ) ;
correct = False ;
}
2004-03-30 02:21:47 +04:00
talloc_destroy ( mem_ctx ) ;
2004-03-27 05:13:58 +03:00
if ( ! torture_close_connection ( cli ) ) {
correct = False ;
}
2009-04-22 13:51:03 +04:00
2004-03-27 05:13:58 +03:00
return correct ;
}
2003-04-18 07:35:39 +04:00
2007-10-19 04:40:25 +04:00
static bool run_dirtest1 ( int dummy )
2002-09-25 19:19:00 +04:00
{
int i ;
2003-04-18 07:35:39 +04:00
static struct cli_state * cli ;
2009-05-01 02:26:43 +04:00
uint16_t fnum ;
int num_seen ;
2007-10-19 04:40:25 +04:00
bool correct = True ;
2002-09-25 19:19:00 +04:00
printf ( " starting directory test \n " ) ;
2006-07-31 13:41:25 +04:00
if ( ! torture_open_connection ( & cli , 0 ) ) {
2002-09-25 19:19:00 +04:00
return False ;
}
2003-04-18 07:35:39 +04:00
cli_sockopt ( cli , sockops ) ;
2002-09-25 19:19:00 +04:00
2003-04-18 07:35:39 +04:00
cli_list ( cli , " \\ LISTDIR \\ * " , 0 , del_fn , cli ) ;
cli_list ( cli , " \\ LISTDIR \\ * " , aDIR , del_fn , cli ) ;
cli_rmdir ( cli , " \\ LISTDIR " ) ;
cli_mkdir ( cli , " \\ LISTDIR " ) ;
2002-09-25 19:19:00 +04:00
/* Create 1000 files and 1000 directories. */
for ( i = 0 ; i < 1000 ; i + + ) {
fstring fname ;
slprintf ( fname , sizeof ( fname ) , " \\ LISTDIR \\ f%d " , i ) ;
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_ntcreate ( cli , fname , 0 , GENERIC_ALL_ACCESS , FILE_ATTRIBUTE_ARCHIVE ,
FILE_SHARE_READ | FILE_SHARE_WRITE , FILE_OVERWRITE_IF , 0 , 0 , & fnum ) ) ) {
2002-09-25 19:19:00 +04:00
fprintf ( stderr , " Failed to open %s \n " , fname ) ;
return False ;
}
2003-04-18 07:35:39 +04:00
cli_close ( cli , fnum ) ;
2002-09-25 19:19:00 +04:00
}
for ( i = 0 ; i < 1000 ; i + + ) {
fstring fname ;
slprintf ( fname , sizeof ( fname ) , " \\ LISTDIR \\ d%d " , i ) ;
2009-04-21 16:52:34 +04:00
if ( ! NT_STATUS_IS_OK ( cli_mkdir ( cli , fname ) ) ) {
2002-09-25 19:19:00 +04:00
fprintf ( stderr , " Failed to open %s \n " , fname ) ;
return False ;
}
}
/* Now ensure that doing an old list sees both files and directories. */
2003-04-18 07:35:39 +04:00
num_seen = cli_list_old ( cli , " \\ LISTDIR \\ * " , aDIR , list_fn , NULL ) ;
2002-09-25 19:19:00 +04:00
printf ( " num_seen = %d \n " , num_seen ) ;
/* We should see 100 files + 1000 directories + . and .. */
if ( num_seen ! = 2002 )
correct = False ;
/* Ensure if we have the "must have" bits we only see the
* relevent entries .
*/
2003-04-18 07:35:39 +04:00
num_seen = cli_list_old ( cli , " \\ LISTDIR \\ * " , ( aDIR < < 8 ) | aDIR , list_fn , NULL ) ;
2002-09-25 19:19:00 +04:00
printf ( " num_seen = %d \n " , num_seen ) ;
if ( num_seen ! = 1002 )
correct = False ;
2003-04-18 07:35:39 +04:00
num_seen = cli_list_old ( cli , " \\ LISTDIR \\ * " , ( aARCH < < 8 ) | aDIR , list_fn , NULL ) ;
2002-09-25 19:19:00 +04:00
printf ( " num_seen = %d \n " , num_seen ) ;
if ( num_seen ! = 1000 )
correct = False ;
/* Delete everything. */
2003-04-18 07:35:39 +04:00
cli_list ( cli , " \\ LISTDIR \\ * " , 0 , del_fn , cli ) ;
cli_list ( cli , " \\ LISTDIR \\ * " , aDIR , del_fn , cli ) ;
cli_rmdir ( cli , " \\ LISTDIR " ) ;
2002-09-25 19:19:00 +04:00
#if 0
2003-04-18 07:35:39 +04:00
printf ( " Matched %d \n " , cli_list ( cli , " a*.* " , 0 , list_fn , NULL ) ) ;
printf ( " Matched %d \n " , cli_list ( cli , " b*.* " , 0 , list_fn , NULL ) ) ;
printf ( " Matched %d \n " , cli_list ( cli , " xyzabc " , 0 , list_fn , NULL ) ) ;
2002-09-25 19:19:00 +04:00
# endif
2003-04-18 07:35:39 +04:00
if ( ! torture_close_connection ( cli ) ) {
2002-09-25 19:19:00 +04:00
correct = False ;
}
printf ( " finished dirtest1 \n " ) ;
return correct ;
}
2007-10-19 04:40:25 +04:00
static bool run_error_map_extract ( int dummy ) {
2009-04-22 13:51:03 +04:00
2006-07-11 22:01:26 +04:00
static struct cli_state * c_dos ;
static struct cli_state * c_nt ;
2008-09-11 20:57:49 +04:00
NTSTATUS status ;
2001-11-25 05:35:37 +03:00
uint32 error ;
uint32 flgs2 , errnum ;
uint8 errclass ;
NTSTATUS nt_status ;
fstring user ;
2002-01-03 10:00:18 +03:00
/* NT-Error connection */
2006-07-11 22:01:26 +04:00
if ( ! ( c_nt = open_nbt_connection ( ) ) ) {
2002-01-03 09:10:25 +03:00
return False ;
}
2006-07-11 22:01:26 +04:00
c_nt - > use_spnego = False ;
2002-01-03 10:00:18 +03:00
2008-09-11 20:57:49 +04:00
status = cli_negprot ( c_nt ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " %s rejected the NT-error negprot (%s) \n " , host ,
nt_errstr ( status ) ) ;
2006-07-11 22:01:26 +04:00
cli_shutdown ( c_nt ) ;
2002-01-02 06:54:40 +03:00
return False ;
}
2001-11-25 05:35:37 +03:00
2006-08-16 21:14:16 +04:00
if ( ! NT_STATUS_IS_OK ( cli_session_setup ( c_nt , " " , " " , 0 , " " , 0 ,
workgroup ) ) ) {
2006-07-11 22:01:26 +04:00
printf ( " %s rejected the NT-error initial session setup (%s) \n " , host , cli_errstr ( c_nt ) ) ;
2002-01-03 10:00:18 +03:00
return False ;
}
/* DOS-Error connection */
2006-07-11 22:01:26 +04:00
if ( ! ( c_dos = open_nbt_connection ( ) ) ) {
2002-01-03 09:10:25 +03:00
return False ;
}
2006-07-11 22:01:26 +04:00
c_dos - > use_spnego = False ;
c_dos - > force_dos_errors = True ;
2002-01-03 10:00:18 +03:00
2008-09-11 20:57:49 +04:00
status = cli_negprot ( c_dos ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " %s rejected the DOS-error negprot (%s) \n " , host ,
nt_errstr ( status ) ) ;
2006-07-11 22:01:26 +04:00
cli_shutdown ( c_dos ) ;
2001-11-25 05:35:37 +03:00
return False ;
}
2006-08-16 21:14:16 +04:00
if ( ! NT_STATUS_IS_OK ( cli_session_setup ( c_dos , " " , " " , 0 , " " , 0 ,
workgroup ) ) ) {
2006-07-11 22:01:26 +04:00
printf ( " %s rejected the DOS-error initial session setup (%s) \n " , host , cli_errstr ( c_dos ) ) ;
2002-01-03 10:00:18 +03:00
return False ;
}
2001-11-25 05:35:37 +03:00
for ( error = ( 0xc0000000 | 0x1 ) ; error < ( 0xc0000000 | 0xFFF ) ; error + + ) {
2003-07-23 16:33:59 +04:00
fstr_sprintf ( user , " %X " , error ) ;
2001-06-19 06:02:19 +04:00
2006-08-16 21:14:16 +04:00
if ( NT_STATUS_IS_OK ( cli_session_setup ( c_nt , user ,
password , strlen ( password ) ,
password , strlen ( password ) ,
workgroup ) ) ) {
2002-01-03 10:36:26 +03:00
printf ( " /** Session setup succeeded. This shouldn't happen...*/ \n " ) ;
}
2009-04-22 13:51:03 +04:00
2006-07-11 22:01:26 +04:00
flgs2 = SVAL ( c_nt - > inbuf , smb_flg2 ) ;
2009-04-22 13:51:03 +04:00
2002-01-03 10:36:26 +03:00
/* Case #1: 32-bit NT errors */
if ( flgs2 & FLAGS2_32_BIT_ERROR_CODES ) {
2006-07-11 22:01:26 +04:00
nt_status = NT_STATUS ( IVAL ( c_nt - > inbuf , smb_rcls ) ) ;
2001-11-25 05:35:37 +03:00
} else {
2002-01-03 11:36:47 +03:00
printf ( " /** Dos error on NT connection! (%s) */ \n " ,
2006-07-11 22:01:26 +04:00
cli_errstr ( c_nt ) ) ;
2002-01-03 10:36:26 +03:00
nt_status = NT_STATUS ( 0xc0000000 ) ;
2001-11-25 05:35:37 +03:00
}
2006-08-16 21:14:16 +04:00
if ( NT_STATUS_IS_OK ( cli_session_setup ( c_dos , user ,
password , strlen ( password ) ,
password , strlen ( password ) ,
workgroup ) ) ) {
2002-01-03 10:36:26 +03:00
printf ( " /** Session setup succeeded. This shouldn't happen...*/ \n " ) ;
2001-11-25 05:35:37 +03:00
}
2006-07-11 22:01:26 +04:00
flgs2 = SVAL ( c_dos - > inbuf , smb_flg2 ) , errnum ;
2009-04-22 13:51:03 +04:00
2002-01-03 10:36:26 +03:00
/* Case #1: 32-bit NT errors */
if ( flgs2 & FLAGS2_32_BIT_ERROR_CODES ) {
2002-01-03 11:36:47 +03:00
printf ( " /** NT error on DOS connection! (%s) */ \n " ,
2006-07-11 22:01:26 +04:00
cli_errstr ( c_nt ) ) ;
2002-01-03 10:36:26 +03:00
errnum = errclass = 0 ;
2001-11-25 05:35:37 +03:00
} else {
2006-07-11 22:01:26 +04:00
cli_dos_error ( c_dos , & errclass , & errnum ) ;
2001-11-25 05:35:37 +03:00
}
2002-01-03 10:36:26 +03:00
if ( NT_STATUS_V ( nt_status ) ! = error ) {
printf ( " /* \t { This NT error code was 'sqashed' \n \t from %s to %s \n \t during the session setup } \n */ \n " ,
2007-10-06 02:06:24 +04:00
get_nt_error_c_code ( NT_STATUS ( error ) ) ,
get_nt_error_c_code ( nt_status ) ) ;
2002-01-03 10:36:26 +03:00
}
2009-04-22 13:51:03 +04:00
2002-01-03 10:36:26 +03:00
printf ( " \t {%s, \t %s, \t %s}, \n " ,
smb_dos_err_class ( errclass ) ,
smb_dos_err_name ( errclass , errnum ) ,
2007-10-06 02:06:24 +04:00
get_nt_error_c_code ( NT_STATUS ( error ) ) ) ;
2001-11-25 05:35:37 +03:00
}
return True ;
}
2001-06-19 06:02:19 +04:00
2007-12-04 13:38:57 +03:00
static bool run_sesssetup_bench ( int dummy )
{
static struct cli_state * c ;
2008-12-29 19:08:38 +03:00
const char * fname = " \\ file.dat " ;
2009-05-01 02:26:43 +04:00
uint16_t fnum ;
2007-12-04 13:38:57 +03:00
NTSTATUS status ;
int i ;
2008-12-29 19:08:38 +03:00
if ( ! torture_open_connection ( & c , 0 ) ) {
2007-12-04 13:38:57 +03:00
return false ;
}
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_ntcreate (
c , fname , 0 , GENERIC_ALL_ACCESS | DELETE_ACCESS ,
FILE_ATTRIBUTE_NORMAL , 0 , FILE_OVERWRITE_IF ,
FILE_DELETE_ON_CLOSE , 0 , & fnum ) ) ) {
2008-12-29 19:08:38 +03:00
d_printf ( " open %s failed: %s \n " , fname , cli_errstr ( c ) ) ;
2007-12-04 13:38:57 +03:00
return false ;
}
for ( i = 0 ; i < torture_numops ; i + + ) {
status = cli_session_setup (
c , username ,
password , strlen ( password ) ,
password , strlen ( password ) ,
workgroup ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
d_printf ( " (%s) cli_session_setup failed: %s \n " ,
__location__ , nt_errstr ( status ) ) ;
return false ;
}
2008-12-30 00:07:56 +03:00
d_printf ( " \r %d " , ( int ) c - > vuid ) ;
2010-01-03 15:03:42 +03:00
status = cli_ulogoff ( c ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2007-12-04 13:38:57 +03:00
d_printf ( " (%s) cli_ulogoff failed: %s \n " ,
2010-01-03 15:03:42 +03:00
__location__ , nt_errstr ( status ) ) ;
2007-12-04 13:38:57 +03:00
return false ;
}
c - > vuid = 0 ;
}
return true ;
}
2007-10-07 17:36:56 +04:00
static bool subst_test ( const char * str , const char * user , const char * domain ,
uid_t uid , gid_t gid , const char * expected )
{
char * subst ;
bool result = true ;
subst = talloc_sub_specified ( talloc_tos ( ) , str , user , domain , uid , gid ) ;
if ( strcmp ( subst , expected ) ! = 0 ) {
printf ( " sub_specified(%s, %s, %s, %d, %d) returned [%s], expected "
" [%s] \n " , str , user , domain , ( int ) uid , ( int ) gid , subst ,
expected ) ;
result = false ;
}
TALLOC_FREE ( subst ) ;
return result ;
}
2009-04-06 01:20:45 +04:00
static void chain1_open_completion ( struct tevent_req * req )
{
2009-05-01 02:26:43 +04:00
uint16_t fnum ;
2009-04-06 01:20:45 +04:00
NTSTATUS status ;
status = cli_open_recv ( req , & fnum ) ;
TALLOC_FREE ( req ) ;
d_printf ( " cli_open_recv returned %s: %d \n " ,
nt_errstr ( status ) ,
NT_STATUS_IS_OK ( status ) ? fnum : - 1 ) ;
}
static void chain1_write_completion ( struct tevent_req * req )
{
size_t written ;
NTSTATUS status ;
status = cli_write_andx_recv ( req , & written ) ;
TALLOC_FREE ( req ) ;
d_printf ( " cli_write_andx_recv returned %s: %d \n " ,
nt_errstr ( status ) ,
NT_STATUS_IS_OK ( status ) ? ( int ) written : - 1 ) ;
}
static void chain1_close_completion ( struct tevent_req * req )
{
NTSTATUS status ;
bool * done = ( bool * ) tevent_req_callback_data_void ( req ) ;
status = cli_close_recv ( req ) ;
* done = true ;
TALLOC_FREE ( req ) ;
d_printf ( " cli_close returned %s \n " , nt_errstr ( status ) ) ;
}
static bool run_chain1 ( int dummy )
{
struct cli_state * cli1 ;
struct event_context * evt = event_context_init ( NULL ) ;
struct tevent_req * reqs [ 3 ] , * smbreqs [ 3 ] ;
bool done = false ;
const char * str = " foobar " ;
2009-05-12 16:47:02 +04:00
NTSTATUS status ;
2009-04-06 01:20:45 +04:00
printf ( " starting chain1 test \n " ) ;
if ( ! torture_open_connection ( & cli1 , 0 ) ) {
return False ;
}
cli_sockopt ( cli1 , sockops ) ;
reqs [ 0 ] = cli_open_create ( talloc_tos ( ) , evt , cli1 , " \\ test " ,
O_CREAT | O_RDWR , 0 , & smbreqs [ 0 ] ) ;
if ( reqs [ 0 ] = = NULL ) return false ;
tevent_req_set_callback ( reqs [ 0 ] , chain1_open_completion , NULL ) ;
reqs [ 1 ] = cli_write_andx_create ( talloc_tos ( ) , evt , cli1 , 0 , 0 ,
( uint8_t * ) str , 0 , strlen ( str ) + 1 ,
smbreqs , 1 , & smbreqs [ 1 ] ) ;
if ( reqs [ 1 ] = = NULL ) return false ;
tevent_req_set_callback ( reqs [ 1 ] , chain1_write_completion , NULL ) ;
reqs [ 2 ] = cli_close_create ( talloc_tos ( ) , evt , cli1 , 0 , & smbreqs [ 2 ] ) ;
if ( reqs [ 2 ] = = NULL ) return false ;
tevent_req_set_callback ( reqs [ 2 ] , chain1_close_completion , & done ) ;
2009-05-12 16:47:02 +04:00
status = cli_smb_chain_send ( smbreqs , ARRAY_SIZE ( smbreqs ) ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2009-04-06 01:20:45 +04:00
return false ;
}
while ( ! done ) {
event_loop_once ( evt ) ;
}
torture_close_connection ( cli1 ) ;
return True ;
}
2009-05-07 18:24:46 +04:00
static void chain2_sesssetup_completion ( struct tevent_req * req )
{
NTSTATUS status ;
status = cli_session_setup_guest_recv ( req ) ;
d_printf ( " sesssetup returned %s \n " , nt_errstr ( status ) ) ;
}
static void chain2_tcon_completion ( struct tevent_req * req )
{
bool * done = ( bool * ) tevent_req_callback_data_void ( req ) ;
NTSTATUS status ;
status = cli_tcon_andx_recv ( req ) ;
d_printf ( " tcon_and_x returned %s \n " , nt_errstr ( status ) ) ;
* done = true ;
}
static bool run_chain2 ( int dummy )
{
struct cli_state * cli1 ;
struct event_context * evt = event_context_init ( NULL ) ;
struct tevent_req * reqs [ 2 ] , * smbreqs [ 2 ] ;
bool done = false ;
2009-05-12 16:47:02 +04:00
NTSTATUS status ;
2009-05-07 18:24:46 +04:00
printf ( " starting chain2 test \n " ) ;
2009-07-19 22:53:11 +04:00
status = cli_start_connection ( & cli1 , global_myname ( ) , host , NULL ,
port_to_use , Undefined , 0 , NULL ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2009-05-07 18:24:46 +04:00
return False ;
}
cli_sockopt ( cli1 , sockops ) ;
reqs [ 0 ] = cli_session_setup_guest_create ( talloc_tos ( ) , evt , cli1 ,
& smbreqs [ 0 ] ) ;
if ( reqs [ 0 ] = = NULL ) return false ;
tevent_req_set_callback ( reqs [ 0 ] , chain2_sesssetup_completion , NULL ) ;
reqs [ 1 ] = cli_tcon_andx_create ( talloc_tos ( ) , evt , cli1 , " IPC$ " ,
" ????? " , NULL , 0 , & smbreqs [ 1 ] ) ;
if ( reqs [ 1 ] = = NULL ) return false ;
tevent_req_set_callback ( reqs [ 1 ] , chain2_tcon_completion , & done ) ;
2009-05-12 16:47:02 +04:00
status = cli_smb_chain_send ( smbreqs , ARRAY_SIZE ( smbreqs ) ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2009-05-07 18:24:46 +04:00
return false ;
}
while ( ! done ) {
event_loop_once ( evt ) ;
}
torture_close_connection ( cli1 ) ;
return True ;
}
2009-10-12 19:29:45 +04:00
struct torture_createdel_state {
struct tevent_context * ev ;
struct cli_state * cli ;
} ;
static void torture_createdel_created ( struct tevent_req * subreq ) ;
static void torture_createdel_closed ( struct tevent_req * subreq ) ;
static struct tevent_req * torture_createdel_send ( TALLOC_CTX * mem_ctx ,
struct tevent_context * ev ,
struct cli_state * cli ,
const char * name )
{
struct tevent_req * req , * subreq ;
struct torture_createdel_state * state ;
req = tevent_req_create ( mem_ctx , & state ,
struct torture_createdel_state ) ;
if ( req = = NULL ) {
return NULL ;
}
state - > ev = ev ;
state - > cli = cli ;
subreq = cli_ntcreate_send (
state , ev , cli , name , 0 ,
FILE_READ_DATA | FILE_WRITE_DATA | DELETE_ACCESS ,
FILE_ATTRIBUTE_NORMAL ,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE ,
FILE_OPEN_IF , FILE_DELETE_ON_CLOSE , 0 ) ;
if ( tevent_req_nomem ( subreq , req ) ) {
return tevent_req_post ( req , ev ) ;
}
tevent_req_set_callback ( subreq , torture_createdel_created , req ) ;
return req ;
}
static void torture_createdel_created ( struct tevent_req * subreq )
{
struct tevent_req * req = tevent_req_callback_data (
subreq , struct tevent_req ) ;
struct torture_createdel_state * state = tevent_req_data (
req , struct torture_createdel_state ) ;
NTSTATUS status ;
uint16_t fnum ;
status = cli_ntcreate_recv ( subreq , & fnum ) ;
TALLOC_FREE ( subreq ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 10 , ( " cli_ntcreate_recv returned %s \n " ,
nt_errstr ( status ) ) ) ;
tevent_req_nterror ( req , status ) ;
return ;
}
subreq = cli_close_send ( state , state - > ev , state - > cli , fnum ) ;
if ( tevent_req_nomem ( subreq , req ) ) {
return ;
}
tevent_req_set_callback ( subreq , torture_createdel_closed , req ) ;
}
static void torture_createdel_closed ( struct tevent_req * subreq )
{
struct tevent_req * req = tevent_req_callback_data (
subreq , struct tevent_req ) ;
NTSTATUS status ;
status = cli_close_recv ( subreq ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 10 , ( " cli_close_recv returned %s \n " , nt_errstr ( status ) ) ) ;
tevent_req_nterror ( req , status ) ;
return ;
}
tevent_req_done ( req ) ;
}
static NTSTATUS torture_createdel_recv ( struct tevent_req * req )
{
return tevent_req_simple_recv_ntstatus ( req ) ;
}
struct torture_createdels_state {
struct tevent_context * ev ;
struct cli_state * cli ;
const char * base_name ;
int sent ;
int received ;
int num_files ;
struct tevent_req * * reqs ;
} ;
static void torture_createdels_done ( struct tevent_req * subreq ) ;
static struct tevent_req * torture_createdels_send ( TALLOC_CTX * mem_ctx ,
struct tevent_context * ev ,
struct cli_state * cli ,
const char * base_name ,
int num_parallel ,
int num_files )
{
struct tevent_req * req ;
struct torture_createdels_state * state ;
int i ;
req = tevent_req_create ( mem_ctx , & state ,
struct torture_createdels_state ) ;
if ( req = = NULL ) {
return NULL ;
}
state - > ev = ev ;
state - > cli = cli ;
state - > base_name = talloc_strdup ( state , base_name ) ;
if ( tevent_req_nomem ( state - > base_name , req ) ) {
return tevent_req_post ( req , ev ) ;
}
state - > num_files = MAX ( num_parallel , num_files ) ;
state - > sent = 0 ;
state - > received = 0 ;
state - > reqs = talloc_array ( state , struct tevent_req * , num_parallel ) ;
if ( tevent_req_nomem ( state - > reqs , req ) ) {
return tevent_req_post ( req , ev ) ;
}
for ( i = 0 ; i < num_parallel ; i + + ) {
char * name ;
name = talloc_asprintf ( state , " %s%8.8d " , state - > base_name ,
state - > sent ) ;
if ( tevent_req_nomem ( name , req ) ) {
return tevent_req_post ( req , ev ) ;
}
state - > reqs [ i ] = torture_createdel_send (
state - > reqs , state - > ev , state - > cli , name ) ;
if ( tevent_req_nomem ( state - > reqs [ i ] , req ) ) {
return tevent_req_post ( req , ev ) ;
}
name = talloc_move ( state - > reqs [ i ] , & name ) ;
tevent_req_set_callback ( state - > reqs [ i ] ,
torture_createdels_done , req ) ;
state - > sent + = 1 ;
}
return req ;
}
static void torture_createdels_done ( struct tevent_req * subreq )
{
struct tevent_req * req = tevent_req_callback_data (
subreq , struct tevent_req ) ;
struct torture_createdels_state * state = tevent_req_data (
req , struct torture_createdels_state ) ;
size_t num_parallel = talloc_array_length ( state - > reqs ) ;
NTSTATUS status ;
char * name ;
int i ;
status = torture_createdel_recv ( subreq ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 10 , ( " torture_createdel_recv returned %s \n " ,
nt_errstr ( status ) ) ) ;
TALLOC_FREE ( subreq ) ;
tevent_req_nterror ( req , status ) ;
return ;
}
for ( i = 0 ; i < num_parallel ; i + + ) {
if ( subreq = = state - > reqs [ i ] ) {
break ;
}
}
if ( i = = num_parallel ) {
DEBUG ( 10 , ( " received something we did not send \n " ) ) ;
tevent_req_nterror ( req , NT_STATUS_INTERNAL_ERROR ) ;
return ;
}
TALLOC_FREE ( state - > reqs [ i ] ) ;
if ( state - > sent > = state - > num_files ) {
tevent_req_done ( req ) ;
return ;
}
name = talloc_asprintf ( state , " %s%8.8d " , state - > base_name ,
state - > sent ) ;
if ( tevent_req_nomem ( name , req ) ) {
return ;
}
state - > reqs [ i ] = torture_createdel_send ( state - > reqs , state - > ev ,
state - > cli , name ) ;
if ( tevent_req_nomem ( state - > reqs [ i ] , req ) ) {
return ;
}
name = talloc_move ( state - > reqs [ i ] , & name ) ;
tevent_req_set_callback ( state - > reqs [ i ] , torture_createdels_done , req ) ;
state - > sent + = 1 ;
}
static NTSTATUS torture_createdels_recv ( struct tevent_req * req )
{
return tevent_req_simple_recv_ntstatus ( req ) ;
}
struct swallow_notify_state {
struct tevent_context * ev ;
struct cli_state * cli ;
uint16_t fnum ;
uint32_t completion_filter ;
bool recursive ;
bool ( * fn ) ( uint32_t action , const char * name , void * priv ) ;
void * priv ;
} ;
static void swallow_notify_done ( struct tevent_req * subreq ) ;
static struct tevent_req * swallow_notify_send ( TALLOC_CTX * mem_ctx ,
struct tevent_context * ev ,
struct cli_state * cli ,
uint16_t fnum ,
uint32_t completion_filter ,
bool recursive ,
bool ( * fn ) ( uint32_t action ,
const char * name ,
void * priv ) ,
void * priv )
{
struct tevent_req * req , * subreq ;
struct swallow_notify_state * state ;
req = tevent_req_create ( mem_ctx , & state ,
struct swallow_notify_state ) ;
if ( req = = NULL ) {
return NULL ;
}
state - > ev = ev ;
state - > cli = cli ;
state - > fnum = fnum ;
state - > completion_filter = completion_filter ;
state - > recursive = recursive ;
state - > fn = fn ;
state - > priv = priv ;
subreq = cli_notify_send ( state , state - > ev , state - > cli , state - > fnum ,
0xffff , state - > completion_filter ,
state - > recursive ) ;
if ( tevent_req_nomem ( subreq , req ) ) {
return tevent_req_post ( req , ev ) ;
}
tevent_req_set_callback ( subreq , swallow_notify_done , req ) ;
return req ;
}
static void swallow_notify_done ( struct tevent_req * subreq )
{
struct tevent_req * req = tevent_req_callback_data (
subreq , struct tevent_req ) ;
struct swallow_notify_state * state = tevent_req_data (
req , struct swallow_notify_state ) ;
NTSTATUS status ;
uint32_t i , num_changes ;
struct notify_change * changes ;
status = cli_notify_recv ( subreq , state , & num_changes , & changes ) ;
TALLOC_FREE ( subreq ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 10 , ( " cli_notify_recv returned %s \n " ,
nt_errstr ( status ) ) ) ;
tevent_req_nterror ( req , status ) ;
return ;
}
for ( i = 0 ; i < num_changes ; i + + ) {
state - > fn ( changes [ i ] . action , changes [ i ] . name , state - > priv ) ;
}
TALLOC_FREE ( changes ) ;
subreq = cli_notify_send ( state , state - > ev , state - > cli , state - > fnum ,
0xffff , state - > completion_filter ,
state - > recursive ) ;
if ( tevent_req_nomem ( subreq , req ) ) {
return ;
}
tevent_req_set_callback ( subreq , swallow_notify_done , req ) ;
}
static bool print_notifies ( uint32_t action , const char * name , void * priv )
{
if ( DEBUGLEVEL > 5 ) {
d_printf ( " %d %s \n " , ( int ) action , name ) ;
}
return true ;
}
static void notify_bench_done ( struct tevent_req * req )
{
int * num_finished = ( int * ) tevent_req_callback_data_void ( req ) ;
* num_finished + = 1 ;
}
static bool run_notify_bench ( int dummy )
{
const char * dname = " \\ notify-bench " ;
struct tevent_context * ev ;
NTSTATUS status ;
uint16_t dnum ;
2010-01-03 14:58:01 +03:00
struct tevent_req * req1 ;
struct tevent_req * req2 = NULL ;
2009-10-12 19:29:45 +04:00
int i , num_unc_names ;
int num_finished = 0 ;
printf ( " starting notify-bench test \n " ) ;
if ( use_multishare_conn ) {
char * * unc_list ;
unc_list = file_lines_load ( multishare_conn_fname ,
& num_unc_names , 0 , NULL ) ;
if ( ! unc_list | | num_unc_names < = 0 ) {
d_printf ( " Failed to load unc names list from '%s' \n " ,
multishare_conn_fname ) ;
return false ;
}
TALLOC_FREE ( unc_list ) ;
} else {
num_unc_names = 1 ;
}
ev = tevent_context_init ( talloc_tos ( ) ) ;
if ( ev = = NULL ) {
d_printf ( " tevent_context_init failed \n " ) ;
return false ;
}
for ( i = 0 ; i < num_unc_names ; i + + ) {
struct cli_state * cli ;
char * base_fname ;
base_fname = talloc_asprintf ( talloc_tos ( ) , " %s \\ file%3.3d. " ,
dname , i ) ;
if ( base_fname = = NULL ) {
return false ;
}
if ( ! torture_open_connection ( & cli , i ) ) {
return false ;
}
status = cli_ntcreate ( cli , dname , 0 ,
MAXIMUM_ALLOWED_ACCESS ,
0 , FILE_SHARE_READ | FILE_SHARE_WRITE |
FILE_SHARE_DELETE ,
FILE_OPEN_IF , FILE_DIRECTORY_FILE , 0 ,
& dnum ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
d_printf ( " Could not create %s: %s \n " , dname ,
nt_errstr ( status ) ) ;
return false ;
}
req1 = swallow_notify_send ( talloc_tos ( ) , ev , cli , dnum ,
FILE_NOTIFY_CHANGE_FILE_NAME |
FILE_NOTIFY_CHANGE_DIR_NAME |
FILE_NOTIFY_CHANGE_ATTRIBUTES |
FILE_NOTIFY_CHANGE_LAST_WRITE ,
false , print_notifies , NULL ) ;
if ( req1 = = NULL ) {
d_printf ( " Could not create notify request \n " ) ;
return false ;
}
req2 = torture_createdels_send ( talloc_tos ( ) , ev , cli ,
base_fname , 10 , torture_numops ) ;
if ( req2 = = NULL ) {
d_printf ( " Could not create createdels request \n " ) ;
return false ;
}
TALLOC_FREE ( base_fname ) ;
tevent_req_set_callback ( req2 , notify_bench_done ,
& num_finished ) ;
}
while ( num_finished < num_unc_names ) {
int ret ;
ret = tevent_loop_once ( ev ) ;
if ( ret ! = 0 ) {
d_printf ( " tevent_loop_once failed \n " ) ;
return false ;
}
}
if ( ! tevent_req_poll ( req2 , ev ) ) {
d_printf ( " tevent_req_poll failed \n " ) ;
}
status = torture_createdels_recv ( req2 ) ;
d_printf ( " torture_createdels_recv returned %s \n " , nt_errstr ( status ) ) ;
return true ;
}
2009-04-17 17:08:40 +04:00
static bool run_mangle1 ( int dummy )
{
struct cli_state * cli ;
const char * fname = " this_is_a_long_fname_to_be_mangled.txt " ;
2009-05-01 02:26:43 +04:00
uint16_t fnum ;
2009-04-17 17:08:40 +04:00
fstring alt_name ;
NTSTATUS status ;
2009-04-22 13:17:38 +04:00
time_t change_time , access_time , write_time ;
2009-04-17 17:08:40 +04:00
SMB_OFF_T size ;
uint16_t mode ;
2009-05-07 18:24:54 +04:00
printf ( " starting mangle1 test \n " ) ;
2009-04-17 17:08:40 +04:00
if ( ! torture_open_connection ( & cli , 0 ) ) {
return False ;
}
cli_sockopt ( cli , sockops ) ;
2009-05-09 15:46:08 +04:00
if ( ! NT_STATUS_IS_OK ( cli_ntcreate (
2009-05-01 02:26:43 +04:00
cli , fname , 0 , GENERIC_ALL_ACCESS | DELETE_ACCESS ,
FILE_ATTRIBUTE_NORMAL , 0 , FILE_OVERWRITE_IF , 0 , 0 , & fnum ) ) ) {
2009-04-17 17:08:40 +04:00
d_printf ( " open %s failed: %s \n " , fname , cli_errstr ( cli ) ) ;
return false ;
}
cli_close ( cli , fnum ) ;
status = cli_qpathinfo_alt_name ( cli , fname , alt_name ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
d_printf ( " cli_qpathinfo_alt_name failed: %s \n " ,
nt_errstr ( status ) ) ;
return false ;
}
d_printf ( " alt_name: %s \n " , alt_name ) ;
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_open ( cli , alt_name , O_RDONLY , DENY_NONE , & fnum ) ) ) {
2009-04-17 17:08:40 +04:00
d_printf ( " cli_open(%s) failed: %s \n " , alt_name ,
cli_errstr ( cli ) ) ;
return false ;
}
cli_close ( cli , fnum ) ;
2009-04-22 13:17:38 +04:00
if ( ! cli_qpathinfo ( cli , alt_name , & change_time , & access_time ,
& write_time , & size , & mode ) ) {
2009-04-17 17:08:40 +04:00
d_printf ( " cli_qpathinfo(%s) failed: %s \n " , alt_name ,
cli_errstr ( cli ) ) ;
return false ;
}
return true ;
}
2009-03-12 11:02:02 +03:00
static size_t null_source ( uint8_t * buf , size_t n , void * priv )
2008-12-20 01:41:19 +03:00
{
size_t * to_pull = ( size_t * ) priv ;
size_t thistime = * to_pull ;
thistime = MIN ( thistime , n ) ;
if ( thistime = = 0 ) {
return 0 ;
}
2009-03-12 11:02:02 +03:00
memset ( buf , 0 , thistime ) ;
2008-12-20 01:41:19 +03:00
* to_pull - = thistime ;
return thistime ;
}
static bool run_windows_write ( int dummy )
{
struct cli_state * cli1 ;
2009-05-01 02:26:43 +04:00
uint16_t fnum ;
2008-12-20 01:41:19 +03:00
int i ;
bool ret = false ;
const char * fname = " \\ writetest.txt " ;
2010-01-03 14:58:31 +03:00
struct timeval start_time ;
2008-12-20 01:41:19 +03:00
double seconds ;
double kbytes ;
printf ( " starting windows_write test \n " ) ;
if ( ! torture_open_connection ( & cli1 , 0 ) ) {
return False ;
}
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_open ( cli1 , fname , O_RDWR | O_CREAT | O_EXCL , DENY_NONE , & fnum ) ) ) {
2008-12-20 01:41:19 +03:00
printf ( " open failed (%s) \n " , cli_errstr ( cli1 ) ) ;
return False ;
}
cli_sockopt ( cli1 , sockops ) ;
2010-01-03 14:58:31 +03:00
start_time = timeval_current ( ) ;
2008-12-20 01:41:19 +03:00
for ( i = 0 ; i < torture_numops ; i + + ) {
char c = 0 ;
off_t start = i * torture_blocksize ;
NTSTATUS status ;
size_t to_pull = torture_blocksize - 1 ;
if ( cli_write ( cli1 , fnum , 0 , & c ,
start + torture_blocksize - 1 , 1 ) ! = 1 ) {
printf ( " cli_write failed: %s \n " , cli_errstr ( cli1 ) ) ;
goto fail ;
}
status = cli_push ( cli1 , fnum , 0 , i * torture_blocksize , torture_blocksize ,
2009-03-12 11:02:02 +03:00
null_source , & to_pull ) ;
2008-12-20 01:41:19 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " cli_push returned: %s \n " , nt_errstr ( status ) ) ;
goto fail ;
}
}
2010-01-03 14:58:31 +03:00
seconds = timeval_elapsed ( & start_time ) ;
2008-12-20 01:41:19 +03:00
kbytes = ( double ) torture_blocksize * torture_numops ;
kbytes / = 1024 ;
printf ( " Wrote %d kbytes in %.2f seconds: %d kb/sec \n " , ( int ) kbytes ,
( double ) seconds , ( int ) ( kbytes / seconds ) ) ;
ret = true ;
fail :
cli_close ( cli1 , fnum ) ;
2009-04-30 05:26:02 +04:00
cli_unlink ( cli1 , fname , aSYSTEM | aHIDDEN ) ;
2008-12-20 01:41:19 +03:00
torture_close_connection ( cli1 ) ;
return ret ;
}
2008-08-27 21:30:57 +04:00
static bool run_cli_echo ( int dummy )
{
struct cli_state * cli ;
NTSTATUS status ;
2009-03-29 03:52:22 +04:00
printf ( " starting cli_echo test \n " ) ;
2008-08-27 21:30:57 +04:00
if ( ! torture_open_connection ( & cli , 0 ) ) {
return false ;
}
cli_sockopt ( cli , sockops ) ;
2009-04-05 22:48:16 +04:00
status = cli_echo ( cli , 5 , data_blob_const ( " hello " , 5 ) ) ;
2008-08-27 21:30:57 +04:00
d_printf ( " cli_echo returned %s \n " , nt_errstr ( status ) ) ;
torture_close_connection ( cli ) ;
return NT_STATUS_IS_OK ( status ) ;
}
2009-04-17 03:21:31 +04:00
static bool run_uid_regression_test ( int dummy )
{
static struct cli_state * cli ;
int16_t old_vuid ;
2009-05-04 21:40:57 +04:00
int16_t old_cnum ;
2009-04-17 03:21:31 +04:00
bool correct = True ;
2010-01-03 15:03:42 +03:00
NTSTATUS status ;
2009-04-17 03:21:31 +04:00
printf ( " starting uid regression test \n " ) ;
if ( ! torture_open_connection ( & cli , 0 ) ) {
return False ;
}
cli_sockopt ( cli , sockops ) ;
/* Ok - now save then logoff our current user. */
old_vuid = cli - > vuid ;
2010-01-03 15:03:42 +03:00
status = cli_ulogoff ( cli ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2009-04-17 03:21:31 +04:00
d_printf ( " (%s) cli_ulogoff failed: %s \n " ,
2010-01-03 15:03:42 +03:00
__location__ , nt_errstr ( status ) ) ;
2009-04-17 03:21:31 +04:00
correct = false ;
goto out ;
}
cli - > vuid = old_vuid ;
/* Try an operation. */
2009-04-21 16:52:34 +04:00
if ( ! NT_STATUS_IS_OK ( cli_mkdir ( cli , " \\ uid_reg_test " ) ) ) {
2009-04-17 03:21:31 +04:00
/* We expect bad uid. */
if ( ! check_error ( __LINE__ , cli , ERRSRV , ERRbaduid ,
NT_STATUS_NO_SUCH_USER ) ) {
return False ;
}
2009-05-04 21:40:57 +04:00
}
old_cnum = cli - > cnum ;
/* Now try a SMBtdis with the invald vuid set to zero. */
cli - > vuid = 0 ;
/* This should succeed. */
2010-01-03 20:46:57 +03:00
status = cli_tdis ( cli ) ;
if ( NT_STATUS_IS_OK ( status ) ) {
2009-05-04 21:40:57 +04:00
printf ( " First tdis with invalid vuid should succeed. \n " ) ;
} else {
2010-01-03 20:46:57 +03:00
printf ( " First tdis failed (%s) \n " , nt_errstr ( status ) ) ;
2009-05-04 21:40:57 +04:00
}
cli - > vuid = old_vuid ;
cli - > cnum = old_cnum ;
/* This should fail. */
2010-01-03 20:46:57 +03:00
status = cli_tdis ( cli ) ;
if ( NT_STATUS_IS_OK ( status ) ) {
2009-05-04 21:40:57 +04:00
printf ( " Second tdis with invalid vuid should fail - succeeded instead !. \n " ) ;
} else {
/* Should be bad tid. */
if ( ! check_error ( __LINE__ , cli , ERRSRV , ERRinvnid ,
NT_STATUS_NETWORK_NAME_DELETED ) ) {
return False ;
}
2009-04-17 03:21:31 +04:00
}
cli_rmdir ( cli , " \\ uid_reg_test " ) ;
out :
2009-05-04 21:40:57 +04:00
cli_shutdown ( cli ) ;
2009-04-17 03:21:31 +04:00
return correct ;
}
2009-05-15 03:03:31 +04:00
static const char * illegal_chars = " * \\ /?<>| \" : " ;
static char force_shortname_chars [ ] = " +,.[];= \177 " ;
static void shortname_del_fn ( const char * mnt , file_info * finfo , const char * mask , void * state )
{
struct cli_state * pcli = ( struct cli_state * ) state ;
fstring fname ;
slprintf ( fname , sizeof ( fname ) , " \\ shortname \\ %s " , finfo - > name ) ;
if ( strcmp ( finfo - > name , " . " ) = = 0 | | strcmp ( finfo - > name , " .. " ) = = 0 )
return ;
if ( finfo - > mode & aDIR ) {
if ( ! NT_STATUS_IS_OK ( cli_rmdir ( pcli , fname ) ) )
printf ( " del_fn: failed to rmdir %s \n , " , fname ) ;
} else {
if ( ! NT_STATUS_IS_OK ( cli_unlink ( pcli , fname , aSYSTEM | aHIDDEN ) ) )
printf ( " del_fn: failed to unlink %s \n , " , fname ) ;
}
}
struct sn_state {
int i ;
bool val ;
} ;
static void shortname_list_fn ( const char * mnt , file_info * finfo , const char * name , void * state )
{
struct sn_state * s = ( struct sn_state * ) state ;
int i = s - > i ;
#if 0
printf ( " shortname list: i = %d, name = |%s|, shortname = |%s| \n " ,
i , finfo - > name , finfo - > short_name ) ;
# endif
if ( strchr ( force_shortname_chars , i ) ) {
if ( ! finfo - > short_name [ 0 ] ) {
/* Shortname not created when it should be. */
2009-05-15 03:30:11 +04:00
d_printf ( " (%s) ERROR: Shortname was not created for file %s containing %d \n " ,
__location__ , finfo - > name , i ) ;
2009-05-15 03:03:31 +04:00
s - > val = true ;
}
} else if ( finfo - > short_name [ 0 ] ) {
/* Shortname created when it should not be. */
d_printf ( " (%s) ERROR: Shortname %s was created for file %s \n " ,
__location__ , finfo - > short_name , finfo - > name ) ;
s - > val = true ;
}
}
static bool run_shortname_test ( int dummy )
{
static struct cli_state * cli ;
bool correct = True ;
int i ;
struct sn_state s ;
char fname [ 20 ] ;
printf ( " starting shortname test \n " ) ;
if ( ! torture_open_connection ( & cli , 0 ) ) {
return False ;
}
cli_sockopt ( cli , sockops ) ;
cli_list ( cli , " \\ shortname \\ * " , 0 , shortname_del_fn , cli ) ;
cli_list ( cli , " \\ shortname \\ * " , aDIR , shortname_del_fn , cli ) ;
cli_rmdir ( cli , " \\ shortname " ) ;
if ( ! NT_STATUS_IS_OK ( cli_mkdir ( cli , " \\ shortname " ) ) ) {
d_printf ( " (%s) cli_mkdir of \\ shortname failed: %s \n " ,
__location__ , cli_errstr ( cli ) ) ;
correct = false ;
goto out ;
}
strlcpy ( fname , " \\ shortname \\ " , sizeof ( fname ) ) ;
strlcat ( fname , " test .txt " , sizeof ( fname ) ) ;
s . val = false ;
for ( i = 32 ; i < 128 ; i + + ) {
NTSTATUS status ;
uint16_t fnum = ( uint16_t ) - 1 ;
s . i = i ;
if ( strchr ( illegal_chars , i ) ) {
continue ;
}
fname [ 15 ] = i ;
status = cli_ntcreate ( cli , fname , 0 , GENERIC_ALL_ACCESS , FILE_ATTRIBUTE_NORMAL ,
FILE_SHARE_READ | FILE_SHARE_WRITE , FILE_OVERWRITE_IF , 0 , 0 , & fnum ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
d_printf ( " (%s) cli_nt_create of %s failed: %s \n " ,
__location__ , fname , cli_errstr ( cli ) ) ;
correct = false ;
goto out ;
}
cli_close ( cli , fnum ) ;
if ( cli_list ( cli , " \\ shortname \\ test*.* " , 0 , shortname_list_fn , & s ) ! = 1 ) {
d_printf ( " (%s) failed to list %s: %s \n " ,
__location__ , fname , cli_errstr ( cli ) ) ;
correct = false ;
goto out ;
}
if ( ! NT_STATUS_IS_OK ( cli_unlink ( cli , fname , aSYSTEM | aHIDDEN ) ) ) {
d_printf ( " (%s) failed to delete %s: %s \n " ,
__location__ , fname , cli_errstr ( cli ) ) ;
correct = false ;
goto out ;
}
if ( s . val ) {
correct = false ;
goto out ;
}
}
out :
cli_list ( cli , " \\ shortname \\ * " , 0 , shortname_del_fn , cli ) ;
cli_list ( cli , " \\ shortname \\ * " , aDIR , shortname_del_fn , cli ) ;
cli_rmdir ( cli , " \\ shortname " ) ;
torture_close_connection ( cli ) ;
return correct ;
}
2009-06-20 20:43:58 +04:00
static void pagedsearch_cb ( struct tevent_req * req )
{
int rc ;
struct tldap_message * msg ;
char * dn ;
rc = tldap_search_paged_recv ( req , talloc_tos ( ) , & msg ) ;
if ( rc ! = TLDAP_SUCCESS ) {
d_printf ( " tldap_search_paged_recv failed: %s \n " ,
tldap_err2string ( rc ) ) ;
return ;
}
if ( tldap_msg_type ( msg ) ! = TLDAP_RES_SEARCH_ENTRY ) {
TALLOC_FREE ( msg ) ;
return ;
}
if ( ! tldap_entry_dn ( msg , & dn ) ) {
d_printf ( " tldap_entry_dn failed \n " ) ;
return ;
}
d_printf ( " %s \n " , dn ) ;
TALLOC_FREE ( msg ) ;
}
2009-06-19 15:06:02 +04:00
static bool run_tldap ( int dummy )
{
struct tldap_context * ld ;
int fd , rc ;
NTSTATUS status ;
struct sockaddr_storage addr ;
2009-06-20 20:43:58 +04:00
struct tevent_context * ev ;
struct tevent_req * req ;
char * basedn ;
2010-03-08 04:20:02 +03:00
const char * filter ;
2009-06-19 15:06:02 +04:00
2009-07-28 22:51:58 +04:00
if ( ! resolve_name ( host , & addr , 0 , false ) ) {
2009-06-19 15:06:02 +04:00
d_printf ( " could not find host %s \n " , host ) ;
return false ;
}
status = open_socket_out ( & addr , 389 , 9999 , & fd ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
d_printf ( " open_socket_out failed: %s \n " , nt_errstr ( status ) ) ;
return false ;
}
ld = tldap_context_create ( talloc_tos ( ) , fd ) ;
if ( ld = = NULL ) {
close ( fd ) ;
d_printf ( " tldap_context_create failed \n " ) ;
return false ;
}
rc = tldap_fetch_rootdse ( ld ) ;
if ( rc ! = TLDAP_SUCCESS ) {
d_printf ( " tldap_fetch_rootdse failed: %s \n " ,
tldap_errstr ( talloc_tos ( ) , ld , rc ) ) ;
return false ;
}
2009-06-20 20:43:58 +04:00
basedn = tldap_talloc_single_attribute (
tldap_rootdse ( ld ) , " defaultNamingContext " , talloc_tos ( ) ) ;
if ( basedn = = NULL ) {
d_printf ( " no defaultNamingContext \n " ) ;
return false ;
}
d_printf ( " defaultNamingContext: %s \n " , basedn ) ;
ev = tevent_context_init ( talloc_tos ( ) ) ;
if ( ev = = NULL ) {
d_printf ( " tevent_context_init failed \n " ) ;
return false ;
}
req = tldap_search_paged_send ( talloc_tos ( ) , ev , ld , basedn ,
TLDAP_SCOPE_SUB , " (objectclass=*) " ,
NULL , 0 , 0 ,
NULL , 0 , NULL , 0 , 0 , 0 , 0 , 5 ) ;
if ( req = = NULL ) {
d_printf ( " tldap_search_paged_send failed \n " ) ;
return false ;
}
tevent_req_set_callback ( req , pagedsearch_cb , NULL ) ;
tevent_req_poll ( req , ev ) ;
TALLOC_FREE ( req ) ;
2010-03-08 04:20:02 +03:00
/* test search filters against rootDSE */
filter = " (&(|(name=samba)(nextRid<=10000000)(usnChanged>=10)(samba~=ambas)(!(name=s*m*a))) "
" (|(name:=samba)(name:dn:2.5.13.5:=samba)(:dn:2.5.13.5:=samba)(!(name=*samba)))) " ;
rc = tldap_search ( ld , " " , TLDAP_SCOPE_BASE , filter ,
NULL , 0 , 0 , NULL , 0 , NULL , 0 , 0 , 0 , 0 ,
talloc_tos ( ) , NULL , NULL ) ;
if ( rc ! = TLDAP_SUCCESS ) {
d_printf ( " tldap_search with complex filter failed: %s \n " ,
tldap_errstr ( talloc_tos ( ) , ld , rc ) ) ;
return false ;
}
2009-06-19 15:06:02 +04:00
TALLOC_FREE ( ld ) ;
return true ;
}
2010-02-02 05:49:50 +03:00
/* Torture test to ensure no regression of :
https : //bugzilla.samba.org/show_bug.cgi?id=7084
*/
static bool run_dir_createtime ( int dummy )
{
struct cli_state * cli ;
const char * dname = " \\ testdir " ;
const char * fname = " \\ testdir \\ testfile " ;
NTSTATUS status ;
struct timespec create_time ;
struct timespec create_time1 ;
uint16_t fnum ;
bool ret = false ;
if ( ! torture_open_connection ( & cli , 0 ) ) {
return false ;
}
cli_unlink ( cli , fname , aSYSTEM | aHIDDEN ) ;
cli_rmdir ( cli , dname ) ;
status = cli_mkdir ( cli , dname ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " mkdir failed: %s \n " , nt_errstr ( status ) ) ;
goto out ;
}
if ( ! cli_qpathinfo2 ( cli ,
dname ,
& create_time ,
NULL ,
NULL ,
NULL ,
NULL ,
NULL ,
NULL ) ) {
status = cli_nt_error ( cli ) ;
printf ( " cli_qpathinfo2 returned %s \n " ,
nt_errstr ( status ) ) ;
goto out ;
}
/* Sleep 3 seconds, then create a file. */
sleep ( 3 ) ;
status = cli_open ( cli , fname , O_RDWR | O_CREAT | O_EXCL ,
DENY_NONE , & fnum ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " cli_open failed: %s \n " , nt_errstr ( status ) ) ;
goto out ;
}
if ( ! cli_qpathinfo2 ( cli ,
dname ,
& create_time1 ,
NULL ,
NULL ,
NULL ,
NULL ,
NULL ,
NULL ) ) {
status = cli_nt_error ( cli ) ;
printf ( " cli_qpathinfo2 (2) returned %s \n " ,
nt_errstr ( status ) ) ;
goto out ;
}
if ( timespec_compare ( & create_time1 , & create_time ) ) {
printf ( " run_dir_createtime: create time was updated (error) \n " ) ;
} else {
printf ( " run_dir_createtime: create time was not updated (correct) \n " ) ;
ret = true ;
}
out :
cli_unlink ( cli , fname , aSYSTEM | aHIDDEN ) ;
cli_rmdir ( cli , dname ) ;
if ( ! torture_close_connection ( cli ) ) {
ret = false ;
}
return ret ;
}
2009-07-02 13:56:33 +04:00
static bool run_streamerror ( int dummy )
{
struct cli_state * cli ;
const char * dname = " \\ testdir " ;
const char * streamname =
" testdir:{4c8cc155-6c1e-11d1-8e41-00c04fb9386d}:$DATA " ;
NTSTATUS status ;
time_t change_time , access_time , write_time ;
SMB_OFF_T size ;
uint16_t mode , fnum ;
bool ret = true ;
if ( ! torture_open_connection ( & cli , 0 ) ) {
return false ;
}
2010-02-23 02:04:10 +03:00
cli_unlink ( cli , " \\ testdir \\ * " , aSYSTEM | aHIDDEN ) ;
2009-07-02 13:56:33 +04:00
cli_rmdir ( cli , dname ) ;
status = cli_mkdir ( cli , dname ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " mkdir failed: %s \n " , nt_errstr ( status ) ) ;
return false ;
}
cli_qpathinfo ( cli , streamname , & change_time , & access_time , & write_time ,
& size , & mode ) ;
status = cli_nt_error ( cli ) ;
if ( ! NT_STATUS_EQUAL ( status , NT_STATUS_OBJECT_NAME_NOT_FOUND ) ) {
printf ( " pathinfo returned %s, expected "
" NT_STATUS_OBJECT_NAME_NOT_FOUND \n " ,
nt_errstr ( status ) ) ;
ret = false ;
}
status = cli_ntcreate ( cli , streamname , 0x16 ,
FILE_READ_DATA | FILE_READ_EA |
FILE_READ_ATTRIBUTES | READ_CONTROL_ACCESS ,
FILE_ATTRIBUTE_NORMAL , FILE_SHARE_READ ,
FILE_OPEN , 0 , 0 , & fnum ) ;
if ( ! NT_STATUS_EQUAL ( status , NT_STATUS_OBJECT_NAME_NOT_FOUND ) ) {
printf ( " ntcreate returned %s, expected "
" NT_STATUS_OBJECT_NAME_NOT_FOUND \n " ,
nt_errstr ( status ) ) ;
ret = false ;
}
cli_rmdir ( cli , dname ) ;
return ret ;
}
2007-10-19 04:40:25 +04:00
static bool run_local_substitute ( int dummy )
2006-07-11 22:01:26 +04:00
{
2007-10-07 17:36:56 +04:00
bool ok = true ;
ok & = subst_test ( " %U " , " bla " , " " , - 1 , - 1 , " bla " ) ;
ok & = subst_test ( " %u%U " , " bla " , " " , - 1 , - 1 , " blabla " ) ;
ok & = subst_test ( " %g " , " " , " " , - 1 , - 1 , " NO_GROUP " ) ;
ok & = subst_test ( " %G " , " " , " " , - 1 , - 1 , " NO_GROUP " ) ;
ok & = subst_test ( " %g " , " " , " " , - 1 , 0 , gidtoname ( 0 ) ) ;
ok & = subst_test ( " %G " , " " , " " , - 1 , 0 , gidtoname ( 0 ) ) ;
ok & = subst_test ( " %D%u " , " u " , " dom " , - 1 , 0 , " domu " ) ;
ok & = subst_test ( " %i %I " , " " , " " , - 1 , - 1 , " 0.0.0.0 0.0.0.0 " ) ;
2006-07-11 22:01:26 +04:00
/* Different captialization rules in sub_basic... */
2007-10-07 17:36:56 +04:00
ok & = ( strcmp ( talloc_sub_basic ( talloc_tos ( ) , " BLA " , " dom " , " %U%D " ) ,
" blaDOM " ) = = 0 ) ;
2006-07-11 22:01:26 +04:00
2007-10-07 17:36:56 +04:00
return ok ;
2006-07-11 22:01:26 +04:00
}
2009-07-10 19:29:22 +04:00
static bool run_local_base64 ( int dummy )
{
int i ;
bool ret = true ;
for ( i = 1 ; i < 2000 ; i + + ) {
DATA_BLOB blob1 , blob2 ;
char * b64 ;
blob1 . data = talloc_array ( talloc_tos ( ) , uint8_t , i ) ;
blob1 . length = i ;
generate_random_buffer ( blob1 . data , blob1 . length ) ;
b64 = base64_encode_data_blob ( talloc_tos ( ) , blob1 ) ;
if ( b64 = = NULL ) {
d_fprintf ( stderr , " base64_encode_data_blob failed "
" for %d bytes \n " , i ) ;
ret = false ;
}
blob2 = base64_decode_data_blob ( b64 ) ;
TALLOC_FREE ( b64 ) ;
if ( data_blob_cmp ( & blob1 , & blob2 ) ) {
d_fprintf ( stderr , " data_blob_cmp failed for %d "
" bytes \n " , i ) ;
ret = false ;
}
TALLOC_FREE ( blob1 . data ) ;
data_blob_free ( & blob2 ) ;
}
return ret ;
}
2007-10-19 04:40:25 +04:00
static bool run_local_gencache ( int dummy )
2006-09-10 01:05:51 +04:00
{
char * val ;
time_t tm ;
2007-08-28 16:40:01 +04:00
DATA_BLOB blob ;
2006-09-10 01:05:51 +04:00
if ( ! gencache_set ( " foo " , " bar " , time ( NULL ) + 1000 ) ) {
d_printf ( " %s: gencache_set() failed \n " , __location__ ) ;
return False ;
}
2009-11-02 15:01:58 +03:00
if ( ! gencache_get ( " foo " , NULL , NULL ) ) {
d_printf ( " %s: gencache_get() failed \n " , __location__ ) ;
return False ;
}
2008-07-11 19:44:25 +04:00
if ( ! gencache_get ( " foo " , & val , & tm ) ) {
2006-09-10 01:05:51 +04:00
d_printf ( " %s: gencache_get() failed \n " , __location__ ) ;
return False ;
}
if ( strcmp ( val , " bar " ) ! = 0 ) {
d_printf ( " %s: gencache_get() returned %s, expected %s \n " ,
__location__ , val , " bar " ) ;
SAFE_FREE ( val ) ;
return False ;
}
SAFE_FREE ( val ) ;
if ( ! gencache_del ( " foo " ) ) {
d_printf ( " %s: gencache_del() failed \n " , __location__ ) ;
return False ;
}
if ( gencache_del ( " foo " ) ) {
d_printf ( " %s: second gencache_del() succeeded \n " ,
__location__ ) ;
return False ;
}
2009-04-22 13:51:03 +04:00
2008-07-11 19:44:25 +04:00
if ( gencache_get ( " foo " , & val , & tm ) ) {
2006-09-10 01:05:51 +04:00
d_printf ( " %s: gencache_get() on deleted entry "
" succeeded \n " , __location__ ) ;
return False ;
}
2008-10-13 07:20:26 +04:00
blob = data_blob_string_const_null ( " bar " ) ;
2009-07-10 19:36:18 +04:00
tm = time ( NULL ) + 60 ;
2007-08-28 16:40:01 +04:00
if ( ! gencache_set_data_blob ( " foo " , & blob , tm ) ) {
d_printf ( " %s: gencache_set_data_blob() failed \n " , __location__ ) ;
return False ;
}
2009-09-23 17:21:40 +04:00
if ( ! gencache_get_data_blob ( " foo " , & blob , NULL , NULL ) ) {
2007-08-28 16:40:01 +04:00
d_printf ( " %s: gencache_get_data_blob() failed \n " , __location__ ) ;
return False ;
}
if ( strcmp ( ( const char * ) blob . data , " bar " ) ! = 0 ) {
d_printf ( " %s: gencache_get_data_blob() returned %s, expected %s \n " ,
__location__ , ( const char * ) blob . data , " bar " ) ;
data_blob_free ( & blob ) ;
return False ;
}
data_blob_free ( & blob ) ;
if ( ! gencache_del ( " foo " ) ) {
d_printf ( " %s: gencache_del() failed \n " , __location__ ) ;
return False ;
}
if ( gencache_del ( " foo " ) ) {
d_printf ( " %s: second gencache_del() succeeded \n " ,
__location__ ) ;
return False ;
}
2009-09-23 17:21:40 +04:00
if ( gencache_get_data_blob ( " foo " , & blob , NULL , NULL ) ) {
2007-08-28 16:40:01 +04:00
d_printf ( " %s: gencache_get_data_blob() on deleted entry "
" succeeded \n " , __location__ ) ;
return False ;
}
2006-09-10 01:05:51 +04:00
return True ;
}
2007-11-10 01:43:24 +03:00
static bool rbt_testval ( struct db_context * db , const char * key ,
const char * value )
{
struct db_record * rec ;
TDB_DATA data = string_tdb_data ( value ) ;
bool ret = false ;
NTSTATUS status ;
rec = db - > fetch_locked ( db , db , string_tdb_data ( key ) ) ;
if ( rec = = NULL ) {
d_fprintf ( stderr , " fetch_locked failed \n " ) ;
goto done ;
}
status = rec - > store ( rec , data , 0 ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
d_fprintf ( stderr , " store failed: %s \n " , nt_errstr ( status ) ) ;
goto done ;
}
TALLOC_FREE ( rec ) ;
rec = db - > fetch_locked ( db , db , string_tdb_data ( key ) ) ;
if ( rec = = NULL ) {
d_fprintf ( stderr , " second fetch_locked failed \n " ) ;
goto done ;
}
if ( ( rec - > value . dsize ! = data . dsize )
| | ( memcmp ( rec - > value . dptr , data . dptr , data . dsize ) ! = 0 ) ) {
d_fprintf ( stderr , " Got wrong data back \n " ) ;
goto done ;
}
ret = true ;
done :
TALLOC_FREE ( rec ) ;
return ret ;
}
static bool run_local_rbtree ( int dummy )
{
struct db_context * db ;
bool ret = false ;
int i ;
db = db_open_rbt ( NULL ) ;
if ( db = = NULL ) {
d_fprintf ( stderr , " db_open_rbt failed \n " ) ;
return false ;
}
for ( i = 0 ; i < 1000 ; i + + ) {
char * key , * value ;
2009-01-02 22:38:24 +03:00
if ( asprintf ( & key , " key%ld " , random ( ) ) = = - 1 ) {
goto done ;
}
if ( asprintf ( & value , " value%ld " , random ( ) ) = = - 1 ) {
SAFE_FREE ( key ) ;
goto done ;
}
2007-11-10 01:43:24 +03:00
if ( ! rbt_testval ( db , key , value ) ) {
SAFE_FREE ( key ) ;
SAFE_FREE ( value ) ;
goto done ;
}
SAFE_FREE ( value ) ;
2009-01-02 22:38:24 +03:00
if ( asprintf ( & value , " value%ld " , random ( ) ) = = - 1 ) {
SAFE_FREE ( key ) ;
goto done ;
}
2007-11-10 01:43:24 +03:00
if ( ! rbt_testval ( db , key , value ) ) {
SAFE_FREE ( key ) ;
SAFE_FREE ( value ) ;
goto done ;
}
SAFE_FREE ( key ) ;
SAFE_FREE ( value ) ;
}
ret = true ;
done :
TALLOC_FREE ( db ) ;
return ret ;
}
2009-08-16 12:44:06 +04:00
struct talloc_dict_test {
int content ;
} ;
static int talloc_dict_traverse_fn ( DATA_BLOB key , void * data , void * priv )
{
int * count = ( int * ) priv ;
* count + = 1 ;
return 0 ;
}
static bool run_local_talloc_dict ( int dummy )
{
struct talloc_dict * dict ;
struct talloc_dict_test * t ;
int key , count ;
dict = talloc_dict_init ( talloc_tos ( ) ) ;
if ( dict = = NULL ) {
return false ;
}
t = talloc ( talloc_tos ( ) , struct talloc_dict_test ) ;
if ( t = = NULL ) {
return false ;
}
key = 1 ;
t - > content = 1 ;
if ( ! talloc_dict_set ( dict , data_blob_const ( & key , sizeof ( key ) ) , t ) ) {
return false ;
}
count = 0 ;
if ( talloc_dict_traverse ( dict , talloc_dict_traverse_fn , & count ) ! = 0 ) {
return false ;
}
if ( count ! = 1 ) {
return false ;
}
TALLOC_FREE ( dict ) ;
return true ;
}
2010-02-20 23:31:16 +03:00
static bool run_local_string_to_sid ( int dummy ) {
2010-01-23 16:55:11 +03:00
struct dom_sid sid ;
2010-02-20 23:31:16 +03:00
if ( string_to_sid ( & sid , " S--1-5-32-545 " ) ) {
2010-02-20 23:07:08 +03:00
printf ( " allowing S--1-5-32-545 \n " ) ;
2010-01-23 16:55:11 +03:00
return false ;
}
2010-02-20 23:31:16 +03:00
if ( string_to_sid ( & sid , " S-1-5-32-+545 " ) ) {
2010-02-20 23:07:08 +03:00
printf ( " allowing S-1-5-32-+545 \n " ) ;
2010-01-23 16:55:11 +03:00
return false ;
}
2010-02-20 23:31:16 +03:00
if ( string_to_sid ( & sid , " S-1-2-3-4-5-6-7-8-9-0-1-2-3-4-5-6-7-8-9-0 " ) ) {
2010-02-20 23:07:08 +03:00
printf ( " allowing S-1-2-3-4-5-6-7-8-9-0-1-2-3-4-5-6-7-8-9-0 \n " ) ;
2010-01-23 16:55:11 +03:00
return false ;
}
2010-02-20 23:31:16 +03:00
if ( string_to_sid ( & sid , " S-1-5-32-545-abc " ) ) {
printf ( " allowing S-1-5-32-545-abc \n " ) ;
return false ;
}
if ( ! string_to_sid ( & sid , " S-1-5-32-545 " ) ) {
printf ( " could not parse S-1-5-32-545 \n " ) ;
return false ;
}
if ( ! sid_equal ( & sid , & global_sid_Builtin_Users ) ) {
printf ( " mis-parsed S-1-5-32-545 as %s \n " ,
sid_string_tos ( & sid ) ) ;
return false ;
}
2010-01-23 16:55:11 +03:00
return true ;
}
2009-07-09 01:08:04 +04:00
/* Split a path name into filename and stream name components. Canonicalise
* such that an implicit $ DATA token is always explicit .
*
* The " specification " of this function can be found in the
* run_local_stream_name ( ) function in torture . c , I ' ve tried those
* combinations against a W2k3 server .
*/
static NTSTATUS split_ntfs_stream_name ( TALLOC_CTX * mem_ctx , const char * fname ,
char * * pbase , char * * pstream )
{
char * base = NULL ;
char * stream = NULL ;
char * sname ; /* stream name */
const char * stype ; /* stream type */
DEBUG ( 10 , ( " split_ntfs_stream_name called for [%s] \n " , fname ) ) ;
sname = strchr_m ( fname , ' : ' ) ;
if ( lp_posix_pathnames ( ) | | ( sname = = NULL ) ) {
if ( pbase ! = NULL ) {
base = talloc_strdup ( mem_ctx , fname ) ;
NT_STATUS_HAVE_NO_MEMORY ( base ) ;
}
goto done ;
}
if ( pbase ! = NULL ) {
base = talloc_strndup ( mem_ctx , fname , PTR_DIFF ( sname , fname ) ) ;
NT_STATUS_HAVE_NO_MEMORY ( base ) ;
}
sname + = 1 ;
stype = strchr_m ( sname , ' : ' ) ;
if ( stype = = NULL ) {
sname = talloc_strdup ( mem_ctx , sname ) ;
stype = " $DATA " ;
}
else {
if ( StrCaseCmp ( stype , " :$DATA " ) ! = 0 ) {
/*
* If there is an explicit stream type , so far we only
* allow $ DATA . Is there anything else allowed ? - - vl
*/
DEBUG ( 10 , ( " [%s] is an invalid stream type \n " , stype ) ) ;
TALLOC_FREE ( base ) ;
return NT_STATUS_OBJECT_NAME_INVALID ;
}
sname = talloc_strndup ( mem_ctx , sname , PTR_DIFF ( stype , sname ) ) ;
stype + = 1 ;
}
if ( sname = = NULL ) {
TALLOC_FREE ( base ) ;
return NT_STATUS_NO_MEMORY ;
}
if ( sname [ 0 ] = = ' \0 ' ) {
/*
* no stream name , so no stream
*/
goto done ;
}
if ( pstream ! = NULL ) {
stream = talloc_asprintf ( mem_ctx , " %s:%s " , sname , stype ) ;
if ( stream = = NULL ) {
TALLOC_FREE ( sname ) ;
TALLOC_FREE ( base ) ;
return NT_STATUS_NO_MEMORY ;
}
/*
* upper - case the type field
*/
strupper_m ( strchr_m ( stream , ' : ' ) + 1 ) ;
}
done :
if ( pbase ! = NULL ) {
* pbase = base ;
}
if ( pstream ! = NULL ) {
* pstream = stream ;
}
return NT_STATUS_OK ;
}
2008-01-20 01:10:09 +03:00
static bool test_stream_name ( const char * fname , const char * expected_base ,
const char * expected_stream ,
NTSTATUS expected_status )
{
NTSTATUS status ;
char * base = NULL ;
char * stream = NULL ;
status = split_ntfs_stream_name ( talloc_tos ( ) , fname , & base , & stream ) ;
if ( ! NT_STATUS_EQUAL ( status , expected_status ) ) {
goto error ;
}
if ( ! NT_STATUS_IS_OK ( status ) ) {
return true ;
}
if ( base = = NULL ) goto error ;
if ( strcmp ( expected_base , base ) ! = 0 ) goto error ;
if ( ( expected_stream ! = NULL ) & & ( stream = = NULL ) ) goto error ;
if ( ( expected_stream = = NULL ) & & ( stream ! = NULL ) ) goto error ;
if ( ( stream ! = NULL ) & & ( strcmp ( expected_stream , stream ) ! = 0 ) )
goto error ;
TALLOC_FREE ( base ) ;
TALLOC_FREE ( stream ) ;
return true ;
error :
d_fprintf ( stderr , " test_stream(%s, %s, %s, %s) \n " ,
fname , expected_base ? expected_base : " <NULL> " ,
expected_stream ? expected_stream : " <NULL> " ,
nt_errstr ( expected_status ) ) ;
d_fprintf ( stderr , " -> base=%s, stream=%s, status=%s \n " ,
base ? base : " <NULL> " , stream ? stream : " <NULL> " ,
nt_errstr ( status ) ) ;
TALLOC_FREE ( base ) ;
TALLOC_FREE ( stream ) ;
return false ;
}
static bool run_local_stream_name ( int dummy )
{
bool ret = true ;
ret & = test_stream_name (
" bla " , " bla " , NULL , NT_STATUS_OK ) ;
ret & = test_stream_name (
" bla::$DATA " , " bla " , NULL , NT_STATUS_OK ) ;
ret & = test_stream_name (
" bla:blub: " , " bla " , NULL , NT_STATUS_OBJECT_NAME_INVALID ) ;
ret & = test_stream_name (
" bla:: " , NULL , NULL , NT_STATUS_OBJECT_NAME_INVALID ) ;
ret & = test_stream_name (
" bla::123 " , " bla " , NULL , NT_STATUS_OBJECT_NAME_INVALID ) ;
ret & = test_stream_name (
" bla:$DATA " , " bla " , " $DATA:$DATA " , NT_STATUS_OK ) ;
ret & = test_stream_name (
" bla:x:$DATA " , " bla " , " x:$DATA " , NT_STATUS_OK ) ;
ret & = test_stream_name (
" bla:x " , " bla " , " x:$DATA " , NT_STATUS_OK ) ;
return ret ;
}
2007-12-18 11:41:03 +03:00
static bool data_blob_equal ( DATA_BLOB a , DATA_BLOB b )
{
if ( a . length ! = b . length ) {
printf ( " a.length=%d != b.length=%d \n " ,
( int ) a . length , ( int ) b . length ) ;
return false ;
}
if ( memcmp ( a . data , b . data , a . length ) ! = 0 ) {
printf ( " a.data and b.data differ \n " ) ;
return false ;
}
return true ;
}
static bool run_local_memcache ( int dummy )
{
struct memcache * cache ;
DATA_BLOB k1 , k2 ;
DATA_BLOB d1 , d2 , d3 ;
DATA_BLOB v1 , v2 , v3 ;
2008-11-14 01:50:19 +03:00
TALLOC_CTX * mem_ctx ;
char * str1 , * str2 ;
size_t size1 , size2 ;
bool ret = false ;
2007-12-18 11:41:03 +03:00
cache = memcache_init ( NULL , 100 ) ;
if ( cache = = NULL ) {
printf ( " memcache_init failed \n " ) ;
return false ;
}
d1 = data_blob_const ( " d1 " , 2 ) ;
d2 = data_blob_const ( " d2 " , 2 ) ;
d3 = data_blob_const ( " d3 " , 2 ) ;
k1 = data_blob_const ( " d1 " , 2 ) ;
k2 = data_blob_const ( " d2 " , 2 ) ;
memcache_add ( cache , STAT_CACHE , k1 , d1 ) ;
memcache_add ( cache , GETWD_CACHE , k2 , d2 ) ;
if ( ! memcache_lookup ( cache , STAT_CACHE , k1 , & v1 ) ) {
printf ( " could not find k1 \n " ) ;
return false ;
}
if ( ! data_blob_equal ( d1 , v1 ) ) {
return false ;
}
if ( ! memcache_lookup ( cache , GETWD_CACHE , k2 , & v2 ) ) {
printf ( " could not find k2 \n " ) ;
return false ;
}
if ( ! data_blob_equal ( d2 , v2 ) ) {
return false ;
}
memcache_add ( cache , STAT_CACHE , k1 , d3 ) ;
if ( ! memcache_lookup ( cache , STAT_CACHE , k1 , & v3 ) ) {
printf ( " could not find replaced k1 \n " ) ;
return false ;
}
if ( ! data_blob_equal ( d3 , v3 ) ) {
return false ;
}
memcache_add ( cache , GETWD_CACHE , k1 , d1 ) ;
if ( memcache_lookup ( cache , GETWD_CACHE , k2 , & v2 ) ) {
printf ( " Did find k2, should have been purged \n " ) ;
return false ;
}
TALLOC_FREE ( cache ) ;
2008-11-14 01:50:19 +03:00
cache = memcache_init ( NULL , 0 ) ;
mem_ctx = talloc_init ( " foo " ) ;
str1 = talloc_strdup ( mem_ctx , " string1 " ) ;
str2 = talloc_strdup ( mem_ctx , " string2 " ) ;
memcache_add_talloc ( cache , SINGLETON_CACHE_TALLOC ,
2008-11-14 15:42:54 +03:00
data_blob_string_const ( " torture " ) , & str1 ) ;
2008-11-14 01:50:19 +03:00
size1 = talloc_total_size ( cache ) ;
memcache_add_talloc ( cache , SINGLETON_CACHE_TALLOC ,
2008-11-14 15:42:54 +03:00
data_blob_string_const ( " torture " ) , & str2 ) ;
2008-11-14 01:50:19 +03:00
size2 = talloc_total_size ( cache ) ;
printf ( " size1=%d, size2=%d \n " , ( int ) size1 , ( int ) size2 ) ;
if ( size2 > size1 ) {
printf ( " memcache leaks memory! \n " ) ;
goto fail ;
}
ret = true ;
fail :
TALLOC_FREE ( cache ) ;
return ret ;
2007-12-18 11:41:03 +03:00
}
2009-03-16 22:38:11 +03:00
static void wbclient_done ( struct tevent_req * req )
2008-12-28 19:43:18 +03:00
{
2009-02-04 11:07:36 +03:00
wbcErr wbc_err ;
2008-12-28 19:43:18 +03:00
struct winbindd_response * wb_resp ;
2009-03-16 22:38:11 +03:00
int * i = ( int * ) tevent_req_callback_data_void ( req ) ;
2008-12-28 19:43:18 +03:00
2009-02-04 11:07:36 +03:00
wbc_err = wb_trans_recv ( req , req , & wb_resp ) ;
2008-12-28 19:43:18 +03:00
TALLOC_FREE ( req ) ;
* i + = 1 ;
2009-02-04 11:07:36 +03:00
d_printf ( " wb_trans_recv %d returned %s \n " , * i , wbcErrorString ( wbc_err ) ) ;
2008-12-28 19:43:18 +03:00
}
static bool run_local_wbclient ( int dummy )
{
struct event_context * ev ;
struct wb_context * * wb_ctx ;
struct winbindd_request wb_req ;
bool result = false ;
int i , j ;
BlockSignals ( True , SIGPIPE ) ;
2009-05-20 16:18:23 +04:00
ev = tevent_context_init_byname ( talloc_tos ( ) , " epoll " ) ;
2008-12-28 19:43:18 +03:00
if ( ev = = NULL ) {
goto fail ;
}
2009-05-20 01:07:36 +04:00
wb_ctx = TALLOC_ARRAY ( ev , struct wb_context * , nprocs ) ;
2008-12-28 19:43:18 +03:00
if ( wb_ctx = = NULL ) {
goto fail ;
}
ZERO_STRUCT ( wb_req ) ;
wb_req . cmd = WINBINDD_PING ;
2009-05-20 01:07:36 +04:00
d_printf ( " nprocs=%d, numops=%d \n " , ( int ) nprocs , ( int ) torture_numops ) ;
for ( i = 0 ; i < nprocs ; i + + ) {
2009-04-21 11:58:42 +04:00
wb_ctx [ i ] = wb_context_init ( ev , NULL ) ;
2008-12-28 19:43:18 +03:00
if ( wb_ctx [ i ] = = NULL ) {
goto fail ;
}
2009-05-20 01:07:36 +04:00
for ( j = 0 ; j < torture_numops ; j + + ) {
2009-03-16 22:38:11 +03:00
struct tevent_req * req ;
2008-12-28 19:43:18 +03:00
req = wb_trans_send ( ev , ev , wb_ctx [ i ] ,
( j % 2 ) = = 0 , & wb_req ) ;
if ( req = = NULL ) {
goto fail ;
}
2009-03-16 22:38:11 +03:00
tevent_req_set_callback ( req , wbclient_done , & i ) ;
2008-12-28 19:43:18 +03:00
}
}
i = 0 ;
2009-05-20 01:07:36 +04:00
while ( i < nprocs * torture_numops ) {
2008-12-28 19:43:18 +03:00
event_loop_once ( ev ) ;
}
result = true ;
fail :
TALLOC_FREE ( ev ) ;
return result ;
}
2009-04-26 02:01:43 +04:00
static void getaddrinfo_finished ( struct tevent_req * req )
{
char * name = ( char * ) tevent_req_callback_data_void ( req ) ;
struct addrinfo * ainfo ;
int res ;
res = getaddrinfo_recv ( req , & ainfo ) ;
if ( res ! = 0 ) {
d_printf ( " gai(%s) returned %s \n " , name , gai_strerror ( res ) ) ;
return ;
}
d_printf ( " gai(%s) succeeded \n " , name ) ;
freeaddrinfo ( ainfo ) ;
}
static bool run_getaddrinfo_send ( int dummy )
{
TALLOC_CTX * frame = talloc_stackframe ( ) ;
struct fncall_context * ctx ;
struct tevent_context * ev ;
bool result = false ;
const char * names [ 4 ] = { " www.samba.org " , " notfound.samba.org " ,
" www.slashdot.org " , " heise.de " } ;
struct tevent_req * reqs [ 4 ] ;
int i ;
ev = event_context_init ( frame ) ;
if ( ev = = NULL ) {
goto fail ;
}
ctx = fncall_context_init ( frame , 4 ) ;
for ( i = 0 ; i < ARRAY_SIZE ( names ) ; i + + ) {
reqs [ i ] = getaddrinfo_send ( frame , ev , ctx , names [ i ] , NULL ,
NULL ) ;
if ( reqs [ i ] = = NULL ) {
goto fail ;
}
tevent_req_set_callback ( reqs [ i ] , getaddrinfo_finished ,
2009-05-04 00:46:05 +04:00
( void * ) names [ i ] ) ;
2009-04-26 02:01:43 +04:00
}
for ( i = 0 ; i < ARRAY_SIZE ( reqs ) ; i + + ) {
tevent_loop_once ( ev ) ;
}
result = true ;
fail :
TALLOC_FREE ( frame ) ;
return result ;
}
2009-12-11 17:37:52 +03:00
static bool dbtrans_inc ( struct db_context * db )
{
struct db_record * rec ;
uint32_t * val ;
bool ret = false ;
NTSTATUS status ;
rec = db - > fetch_locked ( db , db , string_term_tdb_data ( " transtest " ) ) ;
if ( rec = = NULL ) {
printf ( __location__ " fetch_lock failed \n " ) ;
return false ;
}
if ( rec - > value . dsize ! = sizeof ( uint32_t ) ) {
printf ( __location__ " value.dsize = %d \n " ,
( int ) rec - > value . dsize ) ;
goto fail ;
}
val = ( uint32_t * ) rec - > value . dptr ;
* val + = 1 ;
status = rec - > store ( rec , make_tdb_data ( ( uint8_t * ) val ,
sizeof ( uint32_t ) ) ,
0 ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( __location__ " store failed: %s \n " ,
nt_errstr ( status ) ) ;
goto fail ;
}
ret = true ;
fail :
TALLOC_FREE ( rec ) ;
return ret ;
}
static bool run_local_dbtrans ( int dummy )
{
struct db_context * db ;
struct db_record * rec ;
NTSTATUS status ;
uint32_t initial ;
int res ;
db = db_open ( talloc_tos ( ) , " transtest.tdb " , 0 , TDB_DEFAULT ,
O_RDWR | O_CREAT , 0600 ) ;
if ( db = = NULL ) {
printf ( " Could not open transtest.db \n " ) ;
return false ;
}
res = db - > transaction_start ( db ) ;
if ( res = = - 1 ) {
printf ( __location__ " transaction_start failed \n " ) ;
return false ;
}
rec = db - > fetch_locked ( db , db , string_term_tdb_data ( " transtest " ) ) ;
if ( rec = = NULL ) {
printf ( __location__ " fetch_lock failed \n " ) ;
return false ;
}
if ( rec - > value . dptr = = NULL ) {
initial = 0 ;
status = rec - > store (
rec , make_tdb_data ( ( uint8_t * ) & initial ,
sizeof ( initial ) ) ,
0 ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( __location__ " store returned %s \n " ,
nt_errstr ( status ) ) ;
return false ;
}
}
TALLOC_FREE ( rec ) ;
res = db - > transaction_commit ( db ) ;
if ( res = = - 1 ) {
printf ( __location__ " transaction_commit failed \n " ) ;
return false ;
}
while ( true ) {
uint32_t val , val2 ;
int i ;
res = db - > transaction_start ( db ) ;
if ( res = = - 1 ) {
printf ( __location__ " transaction_start failed \n " ) ;
break ;
}
if ( ! dbwrap_fetch_uint32 ( db , " transtest " , & val ) ) {
printf ( __location__ " dbwrap_fetch_uint32 failed \n " ) ;
break ;
}
for ( i = 0 ; i < 10 ; i + + ) {
if ( ! dbtrans_inc ( db ) ) {
return false ;
}
}
if ( ! dbwrap_fetch_uint32 ( db , " transtest " , & val2 ) ) {
printf ( __location__ " dbwrap_fetch_uint32 failed \n " ) ;
break ;
}
if ( val2 ! = val + 10 ) {
printf ( __location__ " val=%d, val2=%d \n " ,
( int ) val , ( int ) val2 ) ;
break ;
}
printf ( " val2=%d \r " , val2 ) ;
res = db - > transaction_commit ( db ) ;
if ( res = = - 1 ) {
printf ( __location__ " transaction_commit failed \n " ) ;
break ;
}
}
TALLOC_FREE ( db ) ;
return true ;
}
2009-04-26 02:01:43 +04:00
2007-10-19 04:40:25 +04:00
static double create_procs ( bool ( * fn ) ( int ) , bool * result )
2001-06-19 06:02:19 +04:00
{
int i , status ;
2001-07-02 07:21:17 +04:00
volatile pid_t * child_status ;
2007-10-19 04:40:25 +04:00
volatile bool * child_status_out ;
2001-06-19 06:02:19 +04:00
int synccount ;
int tries = 8 ;
2009-11-24 12:59:09 +03:00
struct timeval start ;
2001-06-19 06:02:19 +04:00
synccount = 0 ;
2001-07-02 07:21:17 +04:00
child_status = ( volatile pid_t * ) shm_setup ( sizeof ( pid_t ) * nprocs ) ;
2001-06-19 06:02:19 +04:00
if ( ! child_status ) {
printf ( " Failed to setup shared memory \n " ) ;
2001-07-02 07:21:17 +04:00
return - 1 ;
}
2007-10-19 04:40:25 +04:00
child_status_out = ( volatile bool * ) shm_setup ( sizeof ( bool ) * nprocs ) ;
2001-07-02 07:21:17 +04:00
if ( ! child_status_out ) {
printf ( " Failed to setup result status shared memory \n " ) ;
return - 1 ;
2001-06-19 06:02:19 +04:00
}
2002-01-16 05:31:53 +03:00
for ( i = 0 ; i < nprocs ; i + + ) {
child_status [ i ] = 0 ;
child_status_out [ i ] = True ;
}
2001-07-02 07:21:17 +04:00
2009-11-24 12:59:09 +03:00
start = timeval_current ( ) ;
2001-06-19 06:02:19 +04:00
for ( i = 0 ; i < nprocs ; i + + ) {
procnum = i ;
if ( fork ( ) = = 0 ) {
pid_t mypid = getpid ( ) ;
sys_srandom ( ( ( int ) mypid ) ^ ( ( int ) time ( NULL ) ) ) ;
slprintf ( myname , sizeof ( myname ) , " CLIENT%d " , i ) ;
while ( 1 ) {
2006-07-31 13:41:25 +04:00
if ( torture_open_connection ( & current_cli , i ) ) break ;
2001-06-19 06:02:19 +04:00
if ( tries - - = = 0 ) {
printf ( " pid %d failed to start \n " , ( int ) getpid ( ) ) ;
_exit ( 1 ) ;
}
2004-02-23 05:54:03 +03:00
smb_msleep ( 10 ) ;
2001-06-19 06:02:19 +04:00
}
child_status [ i ] = getpid ( ) ;
2009-11-24 12:59:09 +03:00
while ( child_status [ i ] & & timeval_elapsed ( & start ) < 5 ) smb_msleep ( 2 ) ;
2001-06-19 06:02:19 +04:00
2001-07-02 07:21:17 +04:00
child_status_out [ i ] = fn ( i ) ;
2001-06-19 06:02:19 +04:00
_exit ( 0 ) ;
}
}
do {
synccount = 0 ;
for ( i = 0 ; i < nprocs ; i + + ) {
if ( child_status [ i ] ) synccount + + ;
}
if ( synccount = = nprocs ) break ;
2004-02-23 05:54:03 +03:00
smb_msleep ( 10 ) ;
2009-11-24 12:59:09 +03:00
} while ( timeval_elapsed ( & start ) < 30 ) ;
2001-06-19 06:02:19 +04:00
if ( synccount ! = nprocs ) {
printf ( " FAILED TO START %d CLIENTS (started %d) \n " , nprocs , synccount ) ;
2001-07-02 07:21:17 +04:00
* result = False ;
2009-11-24 12:59:09 +03:00
return timeval_elapsed ( & start ) ;
2001-06-19 06:02:19 +04:00
}
/* start the client load */
2009-11-24 12:59:09 +03:00
start = timeval_current ( ) ;
2001-06-19 06:02:19 +04:00
for ( i = 0 ; i < nprocs ; i + + ) {
child_status [ i ] = 0 ;
}
printf ( " %d clients started \n " , nprocs ) ;
for ( i = 0 ; i < nprocs ; i + + ) {
2002-03-07 00:05:26 +03:00
while ( waitpid ( 0 , & status , 0 ) = = - 1 & & errno = = EINTR ) /* noop */ ;
2001-06-19 06:02:19 +04:00
}
2001-07-02 07:21:17 +04:00
2001-06-19 06:02:19 +04:00
printf ( " \n " ) ;
2009-04-22 13:51:03 +04:00
2001-07-02 07:21:17 +04:00
for ( i = 0 ; i < nprocs ; i + + ) {
if ( ! child_status_out [ i ] ) {
* result = False ;
}
}
2009-11-24 12:59:09 +03:00
return timeval_elapsed ( & start ) ;
2001-06-19 06:02:19 +04:00
}
# define FLAG_MULTIPROC 1
static struct {
2003-01-03 11:28:12 +03:00
const char * name ;
2007-10-19 04:40:25 +04:00
bool ( * fn ) ( int ) ;
2001-06-19 06:02:19 +04:00
unsigned flags ;
} torture_ops [ ] = {
{ " FDPASS " , run_fdpasstest , 0 } ,
{ " LOCK1 " , run_locktest1 , 0 } ,
{ " LOCK2 " , run_locktest2 , 0 } ,
{ " LOCK3 " , run_locktest3 , 0 } ,
{ " LOCK4 " , run_locktest4 , 0 } ,
{ " LOCK5 " , run_locktest5 , 0 } ,
2002-03-11 04:37:08 +03:00
{ " LOCK6 " , run_locktest6 , 0 } ,
2003-04-18 07:35:39 +04:00
{ " LOCK7 " , run_locktest7 , 0 } ,
2009-05-20 16:56:04 +04:00
{ " LOCK8 " , run_locktest8 , 0 } ,
2009-10-21 04:37:43 +04:00
{ " LOCK9 " , run_locktest9 , 0 } ,
2001-06-19 06:02:19 +04:00
{ " UNLINK " , run_unlinktest , 0 } ,
{ " BROWSE " , run_browsetest , 0 } ,
{ " ATTR " , run_attrtest , 0 } ,
{ " TRANS2 " , run_trans2test , 0 } ,
{ " MAXFID " , run_maxfidtest , FLAG_MULTIPROC } ,
{ " TORTURE " , run_torture , FLAG_MULTIPROC } ,
{ " RANDOMIPC " , run_randomipc , 0 } ,
{ " NEGNOWAIT " , run_negprot_nowait , 0 } ,
2002-02-05 04:31:47 +03:00
{ " NBENCH " , run_nbench , 0 } ,
2001-06-19 06:02:19 +04:00
{ " OPLOCK1 " , run_oplock1 , 0 } ,
{ " OPLOCK2 " , run_oplock2 , 0 } ,
{ " OPLOCK3 " , run_oplock3 , 0 } ,
{ " DIR " , run_dirtest , 0 } ,
2002-09-25 19:19:00 +04:00
{ " DIR1 " , run_dirtest1 , 0 } ,
2010-02-02 05:49:50 +03:00
{ " DIR-CREATETIME " , run_dir_createtime , 0 } ,
2001-09-06 14:37:21 +04:00
{ " DENY1 " , torture_denytest1 , 0 } ,
{ " DENY2 " , torture_denytest2 , 0 } ,
2001-06-19 06:02:19 +04:00
{ " TCON " , run_tcon_test , 0 } ,
2003-03-30 20:37:10 +04:00
{ " TCONDEV " , run_tcon_devtype_test , 0 } ,
2001-06-19 06:02:19 +04:00
{ " RW1 " , run_readwritetest , 0 } ,
{ " RW2 " , run_readwritemulti , FLAG_MULTIPROC } ,
{ " RW3 " , run_readwritelarge , 0 } ,
{ " OPEN " , run_opentest , 0 } ,
2009-03-12 00:28:47 +03:00
{ " POSIX " , run_simple_posix_open_test , 0 } ,
2009-11-29 18:05:36 +03:00
{ " POSIX-APPEND " , run_posix_append , 0 } ,
2009-04-17 03:21:31 +04:00
{ " UID-REGRESSION-TEST " , run_uid_regression_test , 0 } ,
2009-05-15 03:03:31 +04:00
{ " SHORTNAME-TEST " , run_shortname_test , 0 } ,
2003-04-18 07:35:39 +04:00
# if 1
{ " OPENATTR " , run_openattrtest , 0 } ,
# endif
2002-02-24 11:38:11 +03:00
{ " XCOPY " , run_xcopy , 0 } ,
2002-03-05 22:45:16 +03:00
{ " RENAME " , run_rename , 0 } ,
2001-06-19 06:02:19 +04:00
{ " DELETE " , run_deletetest , 0 } ,
2002-03-20 02:19:00 +03:00
{ " PROPERTIES " , run_properties , 0 } ,
2002-04-12 14:18:46 +04:00
{ " MANGLE " , torture_mangle , 0 } ,
2009-04-17 17:08:40 +04:00
{ " MANGLE1 " , run_mangle1 , 0 } ,
2001-06-19 06:02:19 +04:00
{ " W2K " , run_w2ktest , 0 } ,
2001-08-27 12:19:43 +04:00
{ " TRANS2SCAN " , torture_trans2_scan , 0 } ,
{ " NTTRANSSCAN " , torture_nttrans_scan , 0 } ,
2001-09-25 09:20:43 +04:00
{ " UTABLE " , torture_utable , 0 } ,
2001-10-02 09:52:11 +04:00
{ " CASETABLE " , torture_casetable , 0 } ,
2001-11-25 05:35:37 +03:00
{ " ERRMAPEXTRACT " , run_error_map_extract , 0 } ,
2002-07-15 14:35:28 +04:00
{ " PIPE_NUMBER " , run_pipe_number , 0 } ,
2003-04-18 07:35:39 +04:00
{ " TCON2 " , run_tcon2_test , 0 } ,
2003-04-23 12:12:34 +04:00
{ " IOCTL " , torture_ioctl_test , 0 } ,
2003-04-18 07:35:39 +04:00
{ " CHKPATH " , torture_chkpath_test , 0 } ,
{ " FDSESS " , run_fdsesstest , 0 } ,
2004-03-27 05:13:58 +03:00
{ " EATEST " , run_eatest , 0 } ,
2007-12-04 13:38:57 +03:00
{ " SESSSETUP_BENCH " , run_sesssetup_bench , 0 } ,
2009-04-06 01:20:45 +04:00
{ " CHAIN1 " , run_chain1 , 0 } ,
2009-05-07 18:24:46 +04:00
{ " CHAIN2 " , run_chain2 , 0 } ,
2008-12-20 01:41:19 +03:00
{ " WINDOWS-WRITE " , run_windows_write , 0 } ,
2008-08-27 21:30:57 +04:00
{ " CLI_ECHO " , run_cli_echo , 0 } ,
2009-04-26 02:01:43 +04:00
{ " GETADDRINFO " , run_getaddrinfo_send , 0 } ,
2009-06-19 15:06:02 +04:00
{ " TLDAP " , run_tldap } ,
2009-07-02 13:56:33 +04:00
{ " STREAMERROR " , run_streamerror } ,
2009-10-12 19:29:45 +04:00
{ " NOTIFY-BENCH " , run_notify_bench } ,
2006-07-11 22:01:26 +04:00
{ " LOCAL-SUBSTITUTE " , run_local_substitute , 0 } ,
2006-09-10 01:05:51 +04:00
{ " LOCAL-GENCACHE " , run_local_gencache , 0 } ,
2009-08-16 12:44:06 +04:00
{ " LOCAL-TALLOC-DICT " , run_local_talloc_dict , 0 } ,
2009-07-10 19:29:22 +04:00
{ " LOCAL-BASE64 " , run_local_base64 , 0 } ,
2007-11-10 01:43:24 +03:00
{ " LOCAL-RBTREE " , run_local_rbtree , 0 } ,
2007-12-18 11:41:03 +03:00
{ " LOCAL-MEMCACHE " , run_local_memcache , 0 } ,
2008-01-20 01:10:09 +03:00
{ " LOCAL-STREAM-NAME " , run_local_stream_name , 0 } ,
2008-12-28 19:43:18 +03:00
{ " LOCAL-WBCLIENT " , run_local_wbclient , 0 } ,
2010-02-20 23:31:16 +03:00
{ " LOCAL-string_to_sid " , run_local_string_to_sid , 0 } ,
2009-12-11 17:37:52 +03:00
{ " LOCAL-DBTRANS " , run_local_dbtrans , 0 } ,
2001-06-19 06:02:19 +04:00
{ NULL , NULL , 0 } } ;
/****************************************************************************
run a specified test or " ALL "
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
static bool run_test ( const char * name )
2001-06-19 06:02:19 +04:00
{
2007-10-19 04:40:25 +04:00
bool ret = True ;
bool result = True ;
bool found = False ;
2001-06-19 06:02:19 +04:00
int i ;
2001-07-02 07:21:17 +04:00
double t ;
2001-06-19 06:02:19 +04:00
if ( strequal ( name , " ALL " ) ) {
for ( i = 0 ; torture_ops [ i ] . name ; i + + ) {
run_test ( torture_ops [ i ] . name ) ;
}
2003-12-30 18:18:25 +03:00
found = True ;
2001-06-19 06:02:19 +04:00
}
2009-04-22 13:51:03 +04:00
2001-06-19 06:02:19 +04:00
for ( i = 0 ; torture_ops [ i ] . name ; i + + ) {
2003-07-23 16:33:59 +04:00
fstr_sprintf ( randomfname , " \\ XX%x " ,
2001-06-19 06:02:19 +04:00
( unsigned ) random ( ) ) ;
if ( strequal ( name , torture_ops [ i ] . name ) ) {
2003-12-30 18:18:25 +03:00
found = True ;
2001-06-19 06:02:19 +04:00
printf ( " Running %s \n " , name ) ;
if ( torture_ops [ i ] . flags & FLAG_MULTIPROC ) {
2001-07-02 07:21:17 +04:00
t = create_procs ( torture_ops [ i ] . fn , & result ) ;
if ( ! result ) {
ret = False ;
printf ( " TEST %s FAILED! \n " , name ) ;
}
2001-06-19 06:02:19 +04:00
} else {
2009-11-24 12:59:09 +03:00
struct timeval start ;
start = timeval_current ( ) ;
2001-07-02 07:21:17 +04:00
if ( ! torture_ops [ i ] . fn ( 0 ) ) {
ret = False ;
printf ( " TEST %s FAILED! \n " , name ) ;
}
2009-11-24 12:59:09 +03:00
t = timeval_elapsed ( & start ) ;
2001-06-19 06:02:19 +04:00
}
2001-07-02 07:21:17 +04:00
printf ( " %s took %g secs \n \n " , name , t ) ;
2001-06-19 06:02:19 +04:00
}
}
2003-12-30 18:18:25 +03:00
if ( ! found ) {
printf ( " Did not find a test named %s \n " , name ) ;
ret = False ;
}
2001-07-02 07:21:17 +04:00
return ret ;
2001-06-19 06:02:19 +04:00
}
static void usage ( void )
{
int i ;
2005-05-02 19:00:51 +04:00
printf ( " WARNING samba4 test suite is much more complete nowadays. \n " ) ;
printf ( " Please use samba4 torture. \n \n " ) ;
2001-06-19 06:02:19 +04:00
printf ( " Usage: smbtorture //server/share <options> TEST1 TEST2 ... \n " ) ;
printf ( " \t -d debuglevel \n " ) ;
printf ( " \t -U user%%pass \n " ) ;
2002-03-04 03:24:24 +03:00
printf ( " \t -k use kerberos \n " ) ;
2001-06-19 06:02:19 +04:00
printf ( " \t -N numprocs \n " ) ;
printf ( " \t -n my_netbios_name \n " ) ;
printf ( " \t -W workgroup \n " ) ;
printf ( " \t -o num_operations \n " ) ;
printf ( " \t -O socket_options \n " ) ;
printf ( " \t -m maximum protocol \n " ) ;
printf ( " \t -L use oplocks \n " ) ;
2002-02-05 04:31:47 +03:00
printf ( " \t -c CLIENT.TXT specify client load file for NBENCH \n " ) ;
2001-09-06 14:37:21 +04:00
printf ( " \t -A showall \n " ) ;
2003-04-18 07:35:39 +04:00
printf ( " \t -p port \n " ) ;
2002-04-12 14:18:46 +04:00
printf ( " \t -s seed \n " ) ;
2006-07-31 13:41:25 +04:00
printf ( " \t -b unclist_filename specify multiple shares for multiple connections \n " ) ;
2001-06-19 06:02:19 +04:00
printf ( " \n \n " ) ;
printf ( " tests are: " ) ;
for ( i = 0 ; torture_ops [ i ] . name ; i + + ) {
printf ( " %s " , torture_ops [ i ] . name ) ;
}
printf ( " \n " ) ;
printf ( " default test is ALL \n " ) ;
2009-04-22 13:51:03 +04:00
2001-06-19 06:02:19 +04:00
exit ( 1 ) ;
}
/****************************************************************************
main program
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int main ( int argc , char * argv [ ] )
{
int opt , i ;
char * p ;
2003-02-24 06:28:37 +03:00
int gotuser = 0 ;
2001-06-19 06:02:19 +04:00
int gotpass = 0 ;
2007-10-19 04:40:25 +04:00
bool correct = True ;
2007-11-09 05:50:07 +03:00
TALLOC_CTX * frame = talloc_stackframe ( ) ;
2008-03-09 00:29:35 +03:00
int seed = time ( NULL ) ;
2001-06-19 06:02:19 +04:00
2001-09-10 15:08:57 +04:00
dbf = x_stdout ;
2001-06-19 06:02:19 +04:00
2001-07-02 08:47:55 +04:00
# ifdef HAVE_SETBUFFER
2001-06-19 06:02:19 +04:00
setbuffer ( stdout , NULL , 0 ) ;
2001-07-02 08:47:55 +04:00
# endif
2001-06-19 06:02:19 +04:00
2006-01-23 03:19:45 +03:00
load_case_tables ( ) ;
2009-12-07 02:36:51 +03:00
setup_logging ( " smbtorture " , true ) ;
2009-01-28 12:50:55 +03:00
if ( is_default_dyn_CONFIGFILE ( ) ) {
if ( getenv ( " SMB_CONF_PATH " ) ) {
set_dyn_CONFIGFILE ( getenv ( " SMB_CONF_PATH " ) ) ;
}
}
2007-12-10 22:30:37 +03:00
lp_load ( get_dyn_CONFIGFILE ( ) , True , False , False , True ) ;
2001-06-19 06:02:19 +04:00
load_interfaces ( ) ;
if ( argc < 2 ) {
usage ( ) ;
}
for ( p = argv [ 1 ] ; * p ; p + + )
if ( * p = = ' \\ ' )
* p = ' / ' ;
2009-04-22 13:51:03 +04:00
2001-06-19 06:02:19 +04:00
if ( strncmp ( argv [ 1 ] , " // " , 2 ) ) {
usage ( ) ;
}
fstrcpy ( host , & argv [ 1 ] [ 2 ] ) ;
2001-07-04 11:36:09 +04:00
p = strchr_m ( & host [ 2 ] , ' / ' ) ;
2001-06-19 06:02:19 +04:00
if ( ! p ) {
usage ( ) ;
}
* p = 0 ;
fstrcpy ( share , p + 1 ) ;
2009-02-13 12:56:34 +03:00
fstrcpy ( myname , get_myname ( talloc_tos ( ) ) ) ;
2007-11-09 05:50:07 +03:00
if ( ! * myname ) {
fprintf ( stderr , " Failed to get my hostname. \n " ) ;
return 1 ;
}
2001-06-19 06:02:19 +04:00
if ( * username = = 0 & & getenv ( " LOGNAME " ) ) {
2003-01-14 11:53:59 +03:00
fstrcpy ( username , getenv ( " LOGNAME " ) ) ;
2001-06-19 06:02:19 +04:00
}
argc - - ;
argv + + ;
fstrcpy ( workgroup , lp_workgroup ( ) ) ;
2009-10-21 04:37:43 +04:00
while ( ( opt = getopt ( argc , argv , " p:hW:U:n:N:O:o:m:Ll:d:Aec:ks:b:B: " ) ) ! = EOF ) {
2001-06-19 06:02:19 +04:00
switch ( opt ) {
2003-04-18 07:35:39 +04:00
case ' p ' :
port_to_use = atoi ( optarg ) ;
break ;
2002-04-12 14:18:46 +04:00
case ' s ' :
2008-03-09 00:29:35 +03:00
seed = atoi ( optarg ) ;
2002-04-12 14:18:46 +04:00
break ;
2001-06-19 06:02:19 +04:00
case ' W ' :
fstrcpy ( workgroup , optarg ) ;
break ;
case ' m ' :
max_protocol = interpret_protocol ( optarg , max_protocol ) ;
break ;
case ' N ' :
nprocs = atoi ( optarg ) ;
break ;
case ' o ' :
2002-04-12 14:18:46 +04:00
torture_numops = atoi ( optarg ) ;
2001-06-19 06:02:19 +04:00
break ;
case ' d ' :
DEBUGLEVEL = atoi ( optarg ) ;
break ;
case ' O ' :
sockops = optarg ;
break ;
case ' L ' :
use_oplocks = True ;
break ;
2009-10-21 04:37:43 +04:00
case ' l ' :
local_path = optarg ;
break ;
2001-09-06 14:37:21 +04:00
case ' A ' :
torture_showall = True ;
break ;
2001-06-19 06:02:19 +04:00
case ' n ' :
fstrcpy ( myname , optarg ) ;
break ;
2002-02-05 04:31:47 +03:00
case ' c ' :
client_txt = optarg ;
break ;
2008-01-05 03:09:24 +03:00
case ' e ' :
do_encrypt = true ;
break ;
2002-03-04 03:24:24 +03:00
case ' k ' :
# ifdef HAVE_KRB5
use_kerberos = True ;
# else
d_printf ( " No kerberos support compiled in \n " ) ;
exit ( 1 ) ;
# endif
break ;
2001-06-19 06:02:19 +04:00
case ' U ' :
2003-02-24 06:28:37 +03:00
gotuser = 1 ;
2003-01-14 11:53:59 +03:00
fstrcpy ( username , optarg ) ;
2001-07-04 11:36:09 +04:00
p = strchr_m ( username , ' % ' ) ;
2001-06-19 06:02:19 +04:00
if ( p ) {
* p = 0 ;
2003-01-14 11:53:59 +03:00
fstrcpy ( password , p + 1 ) ;
2001-06-19 06:02:19 +04:00
gotpass = 1 ;
}
break ;
2006-07-31 13:41:25 +04:00
case ' b ' :
fstrcpy ( multishare_conn_fname , optarg ) ;
use_multishare_conn = True ;
break ;
2008-12-20 01:41:19 +03:00
case ' B ' :
torture_blocksize = atoi ( optarg ) ;
break ;
2001-06-19 06:02:19 +04:00
default :
printf ( " Unknown option %c (%d) \n " , ( char ) opt , opt ) ;
usage ( ) ;
}
}
2008-03-09 00:29:35 +03:00
d_printf ( " using seed %d \n " , seed ) ;
srandom ( seed ) ;
2003-02-24 06:28:37 +03:00
if ( use_kerberos & & ! gotuser ) gotpass = True ;
2001-06-19 06:02:19 +04:00
while ( ! gotpass ) {
p = getpass ( " Password: " ) ;
if ( p ) {
2003-01-14 11:53:59 +03:00
fstrcpy ( password , p ) ;
2001-06-19 06:02:19 +04:00
gotpass = 1 ;
}
}
printf ( " host=%s share=%s user=%s myname=%s \n " ,
host , share , username , myname ) ;
2003-12-30 18:18:25 +03:00
if ( argc = = optind ) {
2001-07-02 07:21:17 +04:00
correct = run_test ( " ALL " ) ;
2001-06-19 06:02:19 +04:00
} else {
2003-12-30 18:18:25 +03:00
for ( i = optind ; i < argc ; i + + ) {
2001-07-02 07:21:17 +04:00
if ( ! run_test ( argv [ i ] ) ) {
correct = False ;
}
2001-06-19 06:02:19 +04:00
}
}
2007-11-09 05:50:07 +03:00
TALLOC_FREE ( frame ) ;
2001-07-02 07:21:17 +04:00
if ( correct ) {
return ( 0 ) ;
} else {
return ( 1 ) ;
}
2001-06-19 06:02:19 +04:00
}