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
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 .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
2007-07-10 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"
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 ;
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 ;
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 " ;
2002-03-04 03:24:24 +03:00
static BOOL use_kerberos ;
2006-07-31 13:41:25 +04:00
static fstring multishare_conn_fname ;
static BOOL use_multishare_conn = False ;
2002-02-05 04:31:47 +03:00
2001-09-06 14:37:21 +04:00
BOOL torture_showall = False ;
2001-06-19 06:02:19 +04:00
2001-07-02 07:21:17 +04:00
static double create_procs ( BOOL ( * fn ) ( int ) , BOOL * result ) ;
2001-06-19 06:02:19 +04:00
static struct timeval tp1 , tp2 ;
2006-07-31 13:41:25 +04:00
2002-02-05 04:31:47 +03:00
void start_timer ( void )
2001-06-19 06:02:19 +04:00
{
2004-07-03 15:03:58 +04:00
GetTimeOfDay ( & tp1 ) ;
2001-06-19 06:02:19 +04:00
}
2002-02-05 04:31:47 +03:00
double end_timer ( void )
2001-06-19 06:02:19 +04:00
{
2004-07-02 02:55:38 +04:00
GetTimeOfDay ( & tp2 ) ;
2001-06-19 06:02:19 +04:00
return ( ( tp2 . tv_sec - tp1 . tv_sec ) +
( tp2 . tv_usec - tp1 . tv_usec ) * 1.0e-6 ) ;
}
/* 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 ;
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 ) ;
return ret ;
}
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 ;
struct in_addr ip ;
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 ) ;
2007-10-11 05:25:16 +04:00
zero_ip_v4 ( & ip ) ;
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-06-20 21:38:42 +04:00
status = cli_connect ( c , host , & ip ) ;
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
/*
* Well , that failed , try * SMBSERVER . . .
* However , we must reconnect as well . . .
*/
2007-06-20 21:38:42 +04:00
status = cli_connect ( c , host , & ip ) ;
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 ;
}
/* No separator. */
return NULL ;
}
/*
parse a //server/share type UNC name
*/
BOOL smbcli_parse_unc ( const char * unc_name , TALLOC_CTX * mem_ctx ,
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 ;
}
static BOOL torture_open_connection_share ( struct cli_state * * c ,
const char * hostname ,
const char * sharename )
2001-06-19 06:02:19 +04:00
{
2003-04-18 07:35:39 +04:00
BOOL retry ;
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 ;
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
if ( use_oplocks ) ( * c ) - > use_oplocks = True ;
if ( use_level_II_oplocks ) ( * c ) - > use_level_II_oplocks = True ;
( * c ) - > timeout = 120000 ; /* set a really long timeout (2 minutes) */
2001-06-19 06:02:19 +04:00
2003-04-18 07:35:39 +04:00
return True ;
}
2001-06-19 06:02:19 +04:00
2006-07-31 13:41:25 +04:00
void torture_open_connection_free_unclist ( char * * unc_list )
{
if ( unc_list ! = NULL )
{
SAFE_FREE ( unc_list [ 0 ] ) ;
SAFE_FREE ( unc_list ) ;
}
}
BOOL torture_open_connection ( struct cli_state * * c , int conn_index )
{
char * * unc_list = NULL ;
int num_unc_names = 0 ;
BOOL result ;
if ( use_multishare_conn = = True ) {
char * h , * s ;
unc_list = file_lines_load ( multishare_conn_fname , & num_unc_names , 0 ) ;
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 ] ) ;
torture_open_connection_free_unclist ( unc_list ) ;
exit ( 1 ) ;
}
result = torture_open_connection_share ( c , h , s ) ;
/* h, s were copied earlier */
torture_open_connection_free_unclist ( unc_list ) ;
return result ;
}
return torture_open_connection_share ( c , host , share ) ;
}
2003-04-18 07:35:39 +04:00
BOOL torture_cli_session_setup2 ( struct cli_state * cli , uint16 * new_vuid )
{
uint16 old_vuid = cli - > vuid ;
fstring old_user_name ;
size_t passlen = strlen ( password ) ;
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 ;
fstrcpy ( cli - > user_name , old_user_name ) ;
return ret ;
2001-06-19 06:02:19 +04:00
}
2001-08-27 12:19:43 +04:00
BOOL torture_close_connection ( struct cli_state * c )
2001-06-19 06:02:19 +04:00
{
2001-07-02 07:21:17 +04:00
BOOL ret = True ;
2001-06-19 06:02:19 +04:00
if ( ! cli_tdis ( c ) ) {
printf ( " tdis failed (%s) \n " , cli_errstr ( c ) ) ;
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 */
2001-08-20 09:15:26 +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 ;
}
static BOOL wait_lock ( struct cli_state * c , int fnum , uint32 offset , uint32 len )
{
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 ;
}
static BOOL rw_torture ( struct cli_state * c )
{
2003-01-03 11:28:12 +03:00
const char * lockfname = " \\ torture.lck " ;
2001-06-19 06:02:19 +04:00
fstring fname ;
int fnum ;
int fnum2 ;
pid_t pid2 , pid = getpid ( ) ;
int i , j ;
char buf [ 1024 ] ;
2001-07-02 07:21:17 +04:00
BOOL correct = True ;
2001-06-19 06:02:19 +04:00
2007-03-23 22:12:08 +03:00
memset ( buf , ' \0 ' , sizeof ( buf ) ) ;
2001-06-19 06:02:19 +04:00
fnum2 = cli_open ( c , lockfname , O_RDWR | O_CREAT | O_EXCL ,
DENY_NONE ) ;
if ( fnum2 = = - 1 )
fnum2 = cli_open ( c , lockfname , O_RDWR , DENY_NONE ) ;
if ( fnum2 = = - 1 ) {
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 ;
}
fnum = cli_open ( c , fname , O_RDWR | O_CREAT | O_TRUNC , DENY_ALL ) ;
if ( fnum = = - 1 ) {
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
}
if ( ! cli_close ( c , fnum ) ) {
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
}
if ( ! cli_unlink ( c , fname ) ) {
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
}
if ( ! cli_unlock ( c , fnum2 , n * sizeof ( int ) , sizeof ( int ) ) ) {
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 ) ;
cli_unlink ( c , lockfname ) ;
printf ( " %d \n " , i ) ;
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
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 ;
2001-07-02 07:21:17 +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 ) ;
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
ret = False ;
}
return ret ;
2001-06-19 06:02:19 +04:00
}
static BOOL rw_torture3 ( struct cli_state * c , char * lockfname )
{
int fnum = - 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 ;
2001-07-02 07:21:17 +04:00
BOOL correct = True ;
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 )
{
fnum = cli_open ( c , lockfname , O_RDWR | O_CREAT | O_EXCL ,
DENY_NONE ) ;
if ( fnum = = - 1 ) {
printf ( " first open read/write of %s failed (%s) \n " ,
lockfname , cli_errstr ( c ) ) ;
return False ;
}
}
else
{
for ( i = 0 ; i < 500 & & fnum = = - 1 ; i + + )
{
fnum = cli_open ( c , lockfname , O_RDONLY ,
DENY_NONE ) ;
2004-02-23 05:54:03 +03:00
smb_msleep ( 10 ) ;
2001-06-19 06:02:19 +04:00
}
if ( fnum = = - 1 ) {
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 ;
}
}
}
}
if ( ! cli_close ( c , fnum ) ) {
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
}
static BOOL rw_torture2 ( struct cli_state * c1 , struct cli_state * c2 )
{
2003-01-03 11:28:12 +03:00
const char * lockfname = " \\ torture2.lck " ;
2001-06-19 06:02:19 +04:00
int fnum1 ;
int fnum2 ;
int i ;
2006-07-11 22:01:26 +04:00
char buf [ 131072 ] ;
char buf_rd [ 131072 ] ;
2001-07-02 07:21:17 +04:00
BOOL correct = True ;
ssize_t bytes_read ;
2001-06-19 06:02:19 +04:00
if ( ! cli_unlink ( c1 , lockfname ) ) {
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
}
fnum1 = cli_open ( c1 , lockfname , O_RDWR | O_CREAT | O_EXCL ,
DENY_NONE ) ;
if ( fnum1 = = - 1 ) {
printf ( " first open read/write of %s failed (%s) \n " ,
lockfname , cli_errstr ( c1 ) ) ;
return False ;
}
fnum2 = cli_open ( c2 , lockfname , O_RDONLY ,
DENY_NONE ) ;
if ( fnum2 = = - 1 ) {
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
}
}
if ( ! cli_close ( c2 , fnum2 ) ) {
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
}
if ( ! cli_close ( c1 , fnum1 ) ) {
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
}
if ( ! cli_unlink ( c1 , lockfname ) ) {
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
}
2001-07-02 07:21:17 +04:00
static BOOL run_readwritetest ( int dummy )
2001-06-19 06:02:19 +04:00
{
2003-04-18 07:35:39 +04:00
static struct cli_state * cli1 , * cli2 ;
2005-04-02 04:59:12 +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
}
2001-07-02 07:21:17 +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 ;
2001-06-19 06:02:19 +04:00
BOOL test ;
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 ;
}
return test ;
2001-06-19 06:02:19 +04:00
}
2001-07-02 07:21:17 +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 ;
2001-06-19 06:02:19 +04:00
int 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 ] ;
2001-07-02 07:21:17 +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 ) ) {
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 ) ) ;
2001-07-02 07:21:17 +04:00
2003-04-18 07:35:39 +04:00
cli1 - > max_xmit = 128 * 1024 ;
2001-07-02 07:21:17 +04:00
printf ( " starting readwritelarge \n " ) ;
2001-06-19 06:02:19 +04:00
2003-04-18 07:35:39 +04:00
cli_unlink ( cli1 , lockfname ) ;
2001-06-19 06:02:19 +04:00
2003-04-18 07:35:39 +04:00
fnum1 = cli_open ( cli1 , lockfname , O_RDWR | O_CREAT | O_EXCL , DENY_NONE ) ;
2001-06-19 06:02:19 +04:00
if ( fnum1 = = - 1 ) {
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
}
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
2003-04-18 07:35:39 +04:00
if ( ! cli_close ( cli1 , fnum1 ) ) {
printf ( " close failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2002-03-20 04:47:31 +03:00
correct = False ;
}
2003-04-18 07:35:39 +04:00
if ( ! cli_unlink ( cli1 , lockfname ) ) {
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
fnum1 = cli_open ( cli1 , lockfname , O_RDWR | O_CREAT | O_EXCL , DENY_NONE ) ;
2001-07-07 10:21:32 +04:00
if ( fnum1 = = - 1 ) {
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 ;
}
2003-04-18 07:35:39 +04:00
cli1 - > max_xmit = 4 * 1024 ;
2002-03-20 04:47:31 +03:00
2003-04-18 07:35:39 +04:00
cli_smbwrite ( cli1 , fnum1 , buf , 0 , sizeof ( buf ) ) ;
2001-07-07 10:21:32 +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
2003-04-18 07:35:39 +04:00
if ( ! cli_close ( cli1 , fnum1 ) ) {
printf ( " close failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2001-07-07 10:21:32 +04:00
correct = False ;
}
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 */
2001-07-02 07:21:17 +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 ;
pstring line ;
char cname [ 20 ] ;
FILE * f ;
2003-04-23 12:12:34 +04:00
const char * params [ 20 ] ;
2001-07-02 07:21:17 +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 ) ) {
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 ) ) ;
2001-06-19 06:02:19 +04:00
/* parse the command parameters */
params [ 0 ] = strtok ( line , " " ) ;
i = 0 ;
while ( params [ i ] ) params [ + + i ] = strtok ( NULL , " " ) ;
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 ;
}
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 */
static BOOL run_nbench ( int dummy )
2001-06-19 06:02:19 +04:00
{
double t ;
2001-07-02 07:21:17 +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
*/
2001-07-02 07:21:17 +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 " ;
2001-06-19 06:02:19 +04:00
int fnum1 , fnum2 , fnum3 ;
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 " ) ;
2003-04-18 07:35:39 +04:00
cli_unlink ( cli1 , fname ) ;
2001-06-19 06:02:19 +04:00
2003-04-18 07:35:39 +04:00
fnum1 = cli_open ( cli1 , fname , O_RDWR | O_CREAT | O_EXCL , DENY_NONE ) ;
2001-06-19 06:02:19 +04:00
if ( fnum1 = = - 1 ) {
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
fnum2 = cli_open ( cli1 , fname , O_RDWR , DENY_NONE ) ;
2001-06-19 06:02:19 +04:00
if ( fnum2 = = - 1 ) {
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
}
2003-04-18 07:35:39 +04:00
fnum3 = cli_open ( cli2 , fname , O_RDWR , DENY_NONE ) ;
2001-06-19 06:02:19 +04:00
if ( fnum3 = = - 1 ) {
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
2003-04-18 07:35:39 +04:00
if ( ! cli_close ( cli1 , fnum2 ) ) {
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
}
2003-04-18 07:35:39 +04:00
if ( ! cli_close ( cli1 , fnum1 ) ) {
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
}
2003-04-18 07:35:39 +04:00
if ( ! cli_close ( cli2 , fnum3 ) ) {
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
}
2003-04-18 07:35:39 +04:00
if ( ! cli_unlink ( cli1 , fname ) ) {
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
*/
2001-07-02 07:21:17 +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 " ;
2001-06-19 06:02:19 +04:00
int 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 ] ;
2003-04-18 07:35:39 +04:00
BOOL ret = True ;
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 " ) ;
2003-04-18 07:35:39 +04:00
cli_unlink ( cli , fname ) ;
2001-06-19 06:02:19 +04:00
2003-04-18 07:35:39 +04:00
fnum1 = cli_open ( cli , fname , O_RDWR | O_CREAT | O_EXCL , DENY_NONE ) ;
if ( fnum1 = = - 1 ) {
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
}
2003-04-18 07:35:39 +04:00
if ( ! cli_send_tconX ( cli , share , " ????? " ,
2001-06-19 06:02:19 +04:00
password , strlen ( password ) + 1 ) ) {
printf ( " %s refused 2nd tree connect (%s) \n " , host ,
2003-04-18 07:35:39 +04:00
cli_errstr ( cli ) ) ;
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 ;
if ( ! cli_close ( cli , fnum1 ) ) {
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 ;
if ( ! cli_tdis ( cli ) ) {
printf ( " secondary tdis 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 = 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
*/
static BOOL run_tcon2_test ( int dummy )
{
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 " ) ;
asprintf ( & service , " \\ \\ %s \\ %s " , host , share ) ;
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
}
2003-03-30 20:37:10 +04:00
static BOOL tcon_devtest ( struct cli_state * cli ,
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 )
{
BOOL status ;
BOOL ret ;
status = cli_send_tconX ( cli , myshare , devtype ,
password , strlen ( password ) + 1 ) ;
if ( NT_STATUS_IS_OK ( expected_error ) ) {
if ( 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 {
if ( status ) {
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
*/
static BOOL run_tcon_devtype_test ( int dummy )
{
static struct cli_state * cli1 = NULL ;
BOOL retry ;
int flags = 0 ;
NTSTATUS status ;
2003-05-03 08:30:21 +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 ;
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 ;
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
*/
2001-07-02 07:21:17 +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 " ;
2001-06-19 06:02:19 +04:00
int fnum1 , fnum2 , fnum3 ;
2001-07-02 07:21:17 +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 " ) ;
2003-04-18 07:35:39 +04:00
cli_unlink ( cli , fname ) ;
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
fnum1 = cli_open ( cli , fname , O_RDWR | O_CREAT | O_EXCL , DENY_NONE ) ;
2001-06-19 06:02:19 +04:00
if ( fnum1 = = - 1 ) {
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
fnum2 = cli_open ( cli , fname , O_RDWR , DENY_NONE ) ;
2001-06-19 06:02:19 +04:00
if ( fnum2 = = - 1 ) {
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
2003-04-18 07:35:39 +04:00
fnum3 = cli_open ( cli , fname , O_RDWR , DENY_NONE ) ;
2001-06-19 06:02:19 +04:00
if ( fnum3 = = - 1 ) {
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 ) ;
if ( 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
2003-04-18 07:35:39 +04:00
if ( 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
}
2003-04-18 07:35:39 +04:00
if ( 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
2003-04-18 07:35:39 +04:00
if ( ! cli_close ( cli , fnum1 ) ) {
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
}
2003-04-18 07:35:39 +04:00
if ( ! cli_close ( cli , fnum2 ) ) {
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
}
2003-04-18 07:35:39 +04:00
if ( ! cli_close ( cli , fnum3 ) ) {
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
*/
2001-07-02 07:21:17 +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 " ;
2001-06-19 06:02:19 +04:00
int fnum1 , fnum2 , i ;
uint32 offset ;
2001-07-02 07:21:17 +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 " ) ;
2003-04-18 07:35:39 +04:00
cli_unlink ( cli1 , fname ) ;
2001-06-19 06:02:19 +04:00
2003-04-18 07:35:39 +04:00
fnum1 = cli_open ( cli1 , fname , O_RDWR | O_CREAT | O_EXCL , DENY_NONE ) ;
2001-06-19 06:02:19 +04:00
if ( fnum1 = = - 1 ) {
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
fnum2 = cli_open ( cli2 , fname , O_RDWR , DENY_NONE ) ;
2001-06-19 06:02:19 +04:00
if ( fnum2 = = - 1 ) {
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 ;
2003-04-18 07:35:39 +04:00
if ( ! 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
}
2003-04-18 07:35:39 +04:00
if ( ! 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
}
}
2003-04-18 07:35:39 +04:00
if ( ! cli_close ( cli1 , fnum1 ) ) {
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_close ( cli2 , fnum2 ) ) {
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
}
2003-04-18 07:35:39 +04:00
if ( ! cli_unlink ( cli1 , fname ) ) {
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 ;
}
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
*/
2001-07-02 07:21:17 +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 " ;
2001-06-19 06:02:19 +04:00
int fnum1 , fnum2 , f ;
BOOL ret ;
char buf [ 1000 ] ;
2001-07-02 07:21:17 +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 " ) ;
2003-04-18 07:35:39 +04:00
cli_unlink ( cli1 , fname ) ;
2001-06-19 06:02:19 +04:00
2003-04-18 07:35:39 +04:00
fnum1 = cli_open ( cli1 , fname , O_RDWR | O_CREAT | O_EXCL , DENY_NONE ) ;
fnum2 = cli_open ( cli2 , fname , O_RDWR , DENY_NONE ) ;
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 " ) ;
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 " ) ;
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 " ) ;
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 " ) ;
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 ) & &
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 ) & &
cli_unlock ( cli1 , fnum1 , 140 , 4 ) & &
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 ) & &
cli_unlock ( cli1 , fnum1 , 150 , 4 ) & &
( cli_read ( cli2 , fnum2 , buf , 150 , 4 ) = = 4 ) & &
! ( cli_write ( cli2 , fnum2 , 0 , buf , 150 , 4 ) = = 4 ) & &
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 ) & &
cli_unlock ( cli1 , fnum1 , 160 , 4 ) & &
( 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 ) & &
cli_unlock ( cli1 , fnum1 , 170 , 4 ) & &
( 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 ) & &
cli_unlock ( cli1 , fnum1 , 190 , 4 ) & &
! ( 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 ) ;
fnum1 = cli_open ( cli1 , fname , O_RDWR , DENY_NONE ) ;
f = cli_open ( cli1 , fname , O_RDWR , DENY_NONE ) ;
ret = cli_lock ( cli1 , fnum1 , 0 , 8 , 0 , READ_LOCK ) & &
cli_lock ( cli1 , f , 0 , 1 , 0 , READ_LOCK ) & &
cli_close ( cli1 , fnum1 ) & &
( ( fnum1 = cli_open ( cli1 , fname , O_RDWR , DENY_NONE ) ) ! = - 1 ) & &
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 ) ;
cli_unlink ( cli1 , fname ) ;
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 .
*/
2001-07-02 07:21:17 +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 " ;
2001-06-19 06:02:19 +04:00
int fnum1 , fnum2 , fnum3 ;
BOOL ret ;
char buf [ 1000 ] ;
2001-07-02 07:21:17 +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 " ) ;
2003-04-18 07:35:39 +04:00
cli_unlink ( cli1 , fname ) ;
2001-06-19 06:02:19 +04:00
2003-04-18 07:35:39 +04:00
fnum1 = cli_open ( cli1 , fname , O_RDWR | O_CREAT | O_EXCL , DENY_NONE ) ;
fnum2 = cli_open ( cli2 , fname , O_RDWR , DENY_NONE ) ;
fnum3 = cli_open ( cli1 , fname , O_RDWR , DENY_NONE ) ;
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 ) ;
fnum1 = cli_open ( cli1 , fname , O_RDWR , DENY_NONE ) ;
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 ) ;
fnum1 = cli_open ( cli1 , fname , O_RDWR , DENY_NONE ) ;
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 . */
2003-04-18 07:35:39 +04:00
ret = cli_unlock ( cli1 , fnum1 , 0 , 4 ) & &
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. */
2003-04-18 07:35:39 +04:00
ret = cli_unlock ( cli1 , fnum1 , 1 , 1 ) & &
cli_unlock ( cli1 , fnum1 , 0 , 4 ) & &
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. */
2003-04-18 07:35:39 +04:00
ret = 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 ) ;
cli_unlink ( cli1 , fname ) ;
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 " ) ;
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
*/
static BOOL run_locktest6 ( int dummy )
{
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 ;
2002-03-11 04:37:08 +03:00
int fnum ;
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
2003-04-18 07:35:39 +04:00
cli_unlink ( cli , fname [ i ] ) ;
2002-03-11 04:37:08 +03:00
2003-04-18 07:35:39 +04:00
fnum = cli_open ( cli , fname [ i ] , O_RDWR | O_CREAT | O_EXCL , DENY_NONE ) ;
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
2003-04-18 07:35:39 +04:00
fnum = cli_open ( cli , fname [ i ] , O_RDWR , DENY_NONE ) ;
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
2003-04-18 07:35:39 +04:00
cli_unlink ( cli , fname [ i ] ) ;
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 ;
}
2003-04-18 07:35:39 +04:00
static BOOL run_locktest7 ( int dummy )
{
struct cli_state * cli1 ;
const char * fname = " \\ lockt7.lck " ;
int fnum1 ;
char buf [ 200 ] ;
BOOL correct = False ;
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 " ) ;
cli_unlink ( cli1 , fname ) ;
fnum1 = cli_open ( cli1 , fname , O_RDWR | O_CREAT | O_EXCL , DENY_NONE ) ;
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 ) ;
cli_unlink ( cli1 , fname ) ;
torture_close_connection ( cli1 ) ;
printf ( " finished locktest7 \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 )
*/
2001-07-02 07:21:17 +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 " ;
2001-06-19 06:02:19 +04:00
int fnum1 ;
pstring buf ;
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 " ) ;
2003-04-18 07:35:39 +04:00
cli_unlink ( cli1 , fname ) ;
2001-06-19 06:02:19 +04:00
2003-04-18 07:35:39 +04:00
fnum1 = cli_open ( cli1 , fname , O_RDWR | O_CREAT | O_EXCL , DENY_NONE ) ;
2001-06-19 06:02:19 +04:00
if ( fnum1 = = - 1 ) {
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 ) ;
cli_unlink ( cli1 , fname ) ;
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
}
2003-04-18 07:35:39 +04:00
static BOOL run_fdsesstest ( int dummy )
{
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 " ;
int fnum1 ;
int fnum2 ;
pstring buf ;
BOOL ret = True ;
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 ;
if ( ! cli_send_tconX ( cli , share , " ????? " , " " , 1 ) )
return False ;
new_cnum = cli - > cnum ;
cli - > cnum = saved_cnum ;
printf ( " starting fdsesstest \n " ) ;
cli_unlink ( cli , fname ) ;
cli_unlink ( cli , fname1 ) ;
fnum1 = cli_open ( cli , fname , O_RDWR | O_CREAT | O_EXCL , DENY_NONE ) ;
if ( fnum1 = = - 1 ) {
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. */
fnum2 = cli_open ( cli , fname1 , O_RDWR | O_CREAT | O_EXCL , DENY_NONE ) ;
if ( fnum2 ! = - 1 ) {
printf ( " create with different vuid, same cnum succeeded. \n " ) ;
cli_close ( cli , fnum2 ) ;
cli_unlink ( cli , fname1 ) ;
} 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 ) ;
cli_unlink ( cli , fname ) ;
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
*/
2001-07-02 07:21:17 +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 " ;
2001-06-19 06:02:19 +04:00
int fnum ;
2001-07-02 07:21:17 +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 " ) ;
2003-04-18 07:35:39 +04:00
cli_unlink ( cli , fname ) ;
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
fnum = cli_open ( cli , fname , O_RDWR | O_CREAT | O_EXCL , DENY_NONE ) ;
2001-06-19 06:02:19 +04:00
if ( fnum = = - 1 ) {
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
if ( cli_unlink ( cli , fname ) ) {
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 ) ;
cli_unlink ( cli , fname ) ;
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 " ) ;
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
*/
2001-07-02 07:21:17 +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 ;
2001-08-20 09:15:26 +04:00
int fnums [ 0x11000 ] , i ;
2001-06-19 06:02:19 +04:00
int retries = 4 ;
2001-07-02 07:21:17 +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 ( ) ) ;
2003-04-18 07:35:39 +04:00
if ( ( fnums [ i ] = cli_open ( cli , fname ,
2001-08-20 09:15:26 +04:00
O_RDWR | O_CREAT | O_TRUNC , DENY_NONE ) ) = =
2001-06-19 06:02:19 +04:00
- 1 ) {
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 ] ) ;
if ( ! cli_unlink ( cli , fname ) ) {
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 */
2001-07-02 07:21:17 +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 ;
2001-07-02 07:21:17 +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 + + ) {
2006-07-11 22:01:26 +04:00
cli_negprot_send ( 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 */
2001-07-02 07:21:17 +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 ;
2001-06-19 06:02:19 +04:00
pstring param ;
int api , param_len , i ;
2003-04-18 07:35:39 +04:00
struct cli_state * cli ;
2001-07-02 07:21:17 +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 ) ;
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
*/
2001-07-02 07:21:17 +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 ;
2001-07-02 07:21:17 +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
*/
2001-07-02 07:21:17 +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 ;
2001-06-19 06:02:19 +04:00
int fnum ;
time_t t , t2 ;
2003-04-18 07:35:39 +04:00
const char * fname = " \\ attrib123456789.tst " ;
2001-07-02 07:21:17 +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
}
2003-04-18 07:35:39 +04:00
cli_unlink ( cli , fname ) ;
fnum = cli_open ( cli , fname ,
2001-06-19 06:02:19 +04:00
O_RDWR | O_CREAT | O_TRUNC , DENY_NONE ) ;
2003-04-18 07:35:39 +04:00
cli_close ( cli , fnum ) ;
if ( ! cli_getatr ( cli , fname , NULL , NULL , & t ) ) {
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 */
2003-04-18 07:35:39 +04:00
if ( ! cli_setatr ( cli , fname , 0 , t2 ) ) {
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
}
2003-04-18 07:35:39 +04:00
if ( ! cli_getatr ( cli , fname , NULL , NULL , & t ) ) {
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
}
2003-04-18 07:35:39 +04:00
cli_unlink ( cli , fname ) ;
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
*/
2001-07-02 07:21:17 +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 ;
2001-06-19 06:02:19 +04:00
int 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 " ;
2002-02-21 07:27:16 +03:00
pstring pname ;
2001-07-02 07:21:17 +04:00
BOOL correct = True ;
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
}
2003-04-18 07:35:39 +04:00
cli_unlink ( cli , fname ) ;
fnum = cli_open ( cli , fname ,
2001-06-19 06:02:19 +04:00
O_RDWR | O_CREAT | O_TRUNC , DENY_NONE ) ;
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
2003-04-18 07:35:39 +04:00
if ( ! cli_qfilename ( cli , fnum , pname ) ) {
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 ) ;
2003-04-18 07:35:39 +04:00
cli_unlink ( cli , fname ) ;
fnum = cli_open ( cli , fname ,
2001-06-19 06:02:19 +04:00
O_RDWR | O_CREAT | O_TRUNC , DENY_NONE ) ;
2001-08-22 07:15:33 +04:00
if ( fnum = = - 1 ) {
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
}
}
2003-04-18 07:35:39 +04:00
cli_unlink ( cli , fname ) ;
fnum = cli_open ( cli , fname ,
2001-06-19 06:02:19 +04:00
O_RDWR | O_CREAT | O_TRUNC , DENY_NONE ) ;
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
}
}
2003-04-18 07:35:39 +04:00
cli_unlink ( cli , fname ) ;
2001-06-19 06:02:19 +04:00
/* check if the server updates the directory modification time
when creating a new file */
2003-04-18 07:35:39 +04:00
if ( ! cli_mkdir ( cli , dname ) ) {
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
}
2003-04-18 07:35:39 +04:00
fnum = cli_open ( cli , fname2 ,
2001-06-19 06:02:19 +04:00
O_RDWR | O_CREAT | O_TRUNC , DENY_NONE ) ;
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
}
2003-04-18 07:35:39 +04:00
cli_unlink ( cli , fname2 ) ;
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 .
*/
2001-07-02 07:21:17 +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 ;
2001-07-02 07:21:17 +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
}
2001-07-02 07:21:17 +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 ;
2001-06-19 06:02:19 +04:00
int 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 ;
2001-07-02 07:21:17 +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
}
2003-04-18 07:35:39 +04:00
fnum = cli_open ( cli , fname ,
2001-06-19 06:02:19 +04:00
O_RDWR | O_CREAT , DENY_NONE ) ;
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 " ) ;
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
*/
2001-07-02 07:21:17 +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 " ;
2001-06-19 06:02:19 +04:00
int fnum1 ;
2001-07-02 07:21:17 +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
}
2003-04-18 07:35:39 +04:00
cli_unlink ( cli1 , fname ) ;
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
2003-04-18 07:35:39 +04:00
fnum1 = cli_open ( cli1 , fname , O_RDWR | O_CREAT | O_EXCL , DENY_NONE ) ;
2001-06-19 06:02:19 +04:00
if ( fnum1 = = - 1 ) {
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
2003-04-18 07:35:39 +04:00
cli_unlink ( cli1 , fname ) ;
cli_unlink ( cli1 , fname ) ;
2001-06-19 06:02:19 +04:00
2003-04-18 07:35:39 +04:00
if ( ! cli_close ( cli1 , fnum1 ) ) {
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
}
2003-04-18 07:35:39 +04:00
if ( ! cli_unlink ( cli1 , fname ) ) {
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
}
2001-07-02 07:21:17 +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 " ;
2001-06-19 06:02:19 +04:00
int fnum1 , fnum2 ;
int saved_use_oplocks = use_oplocks ;
char buf [ 4 ] ;
2001-07-02 07:21:17 +04:00
BOOL correct = True ;
volatile BOOL * shared_correct ;
shared_correct = ( volatile BOOL * ) shm_setup ( sizeof ( BOOL ) ) ;
* 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
2003-04-18 07:35:39 +04:00
cli_unlink ( cli1 , fname ) ;
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
2003-04-18 07:35:39 +04:00
fnum1 = cli_open ( cli1 , fname , O_RDWR | O_CREAT | O_EXCL , DENY_NONE ) ;
2001-06-19 06:02:19 +04:00
if ( fnum1 = = - 1 ) {
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 */
2003-04-18 07:35:39 +04:00
fnum2 = cli_open ( cli2 , fname , O_RDWR , DENY_NONE ) ;
2001-06-19 06:02:19 +04:00
if ( fnum2 = = - 1 ) {
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 ) ;
2003-04-18 07:35:39 +04:00
if ( ! cli_close ( cli2 , fnum2 ) ) {
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
2003-04-18 07:35:39 +04:00
if ( ! cli_close ( cli1 , fnum1 ) ) {
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 ) ;
2003-04-18 07:35:39 +04:00
if ( ! cli_unlink ( cli1 , fname ) ) {
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 */
static BOOL oplock3_handler ( struct cli_state * cli , int fnum , unsigned char level )
{
printf ( " got oplock break fnum=%d level=%d \n " ,
fnum , level ) ;
return cli_oplock_ack ( cli , fnum , level ) ;
}
2001-07-02 07:21:17 +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 " ;
2001-06-19 06:02:19 +04:00
int fnum ;
char buf [ 4 ] = " abcd " ;
2001-07-02 07:21:17 +04:00
BOOL correct = True ;
volatile BOOL * shared_correct ;
shared_correct = ( volatile BOOL * ) shm_setup ( sizeof ( BOOL ) ) ;
* 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 */
2003-04-18 07:35:39 +04:00
fnum = cli_open ( cli , fname , O_RDWR , DENY_NONE ) ;
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 ) ;
fnum = cli_open ( cli , fname , O_RDWR | O_CREAT , DENY_NONE ) ;
cli_write ( cli , fnum , 0 , buf , 0 , 4 ) ;
cli_close ( cli , fnum ) ;
fnum = cli_open ( cli , fname , O_RDWR , DENY_NONE ) ;
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 .
*/
2001-07-02 07:21:17 +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 " ;
2002-03-07 07:15:40 +03:00
int fnum1 = - 1 ;
int fnum2 = - 1 ;
2001-07-02 07:21:17 +04:00
BOOL correct = True ;
printf ( " starting delete test \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 ;
}
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. */
2001-07-02 07:21:17 +04:00
2003-04-18 07:35:39 +04:00
cli_setatr ( cli1 , fname , 0 , 0 ) ;
cli_unlink ( cli1 , fname ) ;
2001-07-02 07:21:17 +04:00
2004-02-21 01:45:53 +03:00
fnum1 = cli_nt_create_full ( cli1 , fname , 0 , GENERIC_ALL_ACCESS | DELETE_ACCESS , FILE_ATTRIBUTE_NORMAL ,
0 , FILE_OVERWRITE_IF ,
2003-04-18 07:35:39 +04:00
FILE_DELETE_ON_CLOSE , 0 ) ;
2001-07-02 07:21:17 +04:00
2001-06-19 06:02:19 +04:00
if ( fnum1 = = - 1 ) {
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
2003-04-18 07:35:39 +04:00
if ( ! cli_close ( cli1 , fnum1 ) ) {
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
}
2003-04-18 07:35:39 +04:00
fnum1 = cli_open ( cli1 , fname , O_RDWR , DENY_NONE ) ;
if ( fnum1 ! = - 1 ) {
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
}
2001-06-19 06:02:19 +04:00
printf ( " first delete on close test succeeded. \n " ) ;
2001-07-02 07:21:17 +04:00
2001-06-19 06:02:19 +04:00
/* Test 2 - this should delete the file on close. */
2001-07-02 07:21:17 +04:00
2003-04-18 07:35:39 +04:00
cli_setatr ( cli1 , fname , 0 , 0 ) ;
cli_unlink ( cli1 , fname ) ;
2001-07-02 07:21:17 +04:00
2003-04-18 07:35:39 +04:00
fnum1 = cli_nt_create_full ( cli1 , fname , 0 , GENERIC_ALL_ACCESS ,
2001-09-06 05:21:09 +04:00
FILE_ATTRIBUTE_NORMAL , FILE_SHARE_NONE ,
2003-04-18 07:35:39 +04:00
FILE_OVERWRITE_IF , 0 , 0 ) ;
2001-07-02 07:21:17 +04:00
2001-06-19 06:02:19 +04:00
if ( fnum1 = = - 1 ) {
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
}
2001-07-02 07:21:17 +04:00
2003-04-18 07:35:39 +04:00
if ( ! cli_nt_delete_on_close ( cli1 , fnum1 , True ) ) {
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
}
2003-04-18 07:35:39 +04:00
if ( ! cli_close ( cli1 , fnum1 ) ) {
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
}
2003-04-18 07:35:39 +04:00
fnum1 = cli_open ( cli1 , fname , O_RDONLY , DENY_NONE ) ;
2001-07-02 07:21:17 +04:00
if ( fnum1 ! = - 1 ) {
2001-06-19 06:02:19 +04:00
printf ( " [2] open of %s succeeded should have been deleted on close ! \n " , fname ) ;
2003-04-18 07:35:39 +04:00
if ( ! cli_close ( cli1 , fnum1 ) ) {
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
}
2003-04-18 07:35:39 +04:00
cli_unlink ( cli1 , fname ) ;
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 " ) ;
2001-07-02 07:21:17 +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 ) ;
cli_unlink ( cli1 , fname ) ;
2001-06-19 06:02:19 +04:00
2003-04-18 07:35:39 +04:00
fnum1 = cli_nt_create_full ( cli1 , fname , 0 , GENERIC_ALL_ACCESS , FILE_ATTRIBUTE_NORMAL ,
FILE_SHARE_READ | FILE_SHARE_WRITE , FILE_OVERWRITE_IF , 0 , 0 ) ;
2001-06-19 06:02:19 +04:00
if ( fnum1 = = - 1 ) {
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 . */
2003-04-18 07:35:39 +04:00
fnum2 = cli_nt_create_full ( cli1 , fname , 0 , GENERIC_READ_ACCESS , FILE_ATTRIBUTE_NORMAL ,
FILE_SHARE_READ | FILE_SHARE_WRITE , FILE_OPEN , 0 , 0 ) ;
2001-06-19 06:02:19 +04:00
if ( fnum2 ! = - 1 ) {
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. */
2003-04-18 07:35:39 +04:00
fnum2 = cli_nt_create_full ( cli1 , fname , 0 , GENERIC_READ_ACCESS , FILE_ATTRIBUTE_NORMAL ,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE , FILE_OPEN , 0 , 0 ) ;
2001-06-19 06:02:19 +04:00
if ( fnum2 = = - 1 ) {
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
}
2003-04-18 07:35:39 +04:00
if ( ! cli_nt_delete_on_close ( cli1 , fnum1 , True ) ) {
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
}
2003-04-18 07:35:39 +04:00
if ( ! cli_close ( cli1 , fnum1 ) ) {
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
}
2003-04-18 07:35:39 +04:00
if ( ! cli_close ( cli1 , fnum2 ) ) {
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
}
2001-06-19 06:02:19 +04:00
/* This should fail - file should no longer be there. */
2003-04-18 07:35:39 +04:00
fnum1 = cli_open ( cli1 , fname , O_RDONLY , DENY_NONE ) ;
2001-07-02 07:21:17 +04:00
if ( fnum1 ! = - 1 ) {
2001-06-19 06:02:19 +04:00
printf ( " [3] open of %s succeeded should have been deleted on close ! \n " , fname ) ;
2003-04-18 07:35:39 +04:00
if ( ! cli_close ( cli1 , fnum1 ) ) {
printf ( " [3] close failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2001-06-19 06:02:19 +04:00
}
2003-04-18 07:35:39 +04:00
cli_unlink ( cli1 , fname ) ;
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 ) ;
cli_unlink ( cli1 , fname ) ;
2001-06-19 06:02:19 +04:00
2003-04-18 07:35:39 +04:00
fnum1 = cli_nt_create_full ( 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 ) ;
2001-06-19 06:02:19 +04:00
if ( fnum1 = = - 1 ) {
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. */
2003-04-18 07:35:39 +04:00
fnum2 = cli_nt_create_full ( cli1 , fname , 0 , GENERIC_READ_ACCESS ,
FILE_ATTRIBUTE_NORMAL , FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE , FILE_OPEN , 0 , 0 ) ;
2001-06-19 06:02:19 +04:00
if ( fnum2 = = - 1 ) {
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
}
2001-07-02 07:21:17 +04:00
2003-04-18 07:35:39 +04:00
if ( ! cli_close ( cli1 , fnum2 ) ) {
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
}
2003-04-18 07:35:39 +04:00
if ( ! cli_nt_delete_on_close ( cli1 , fnum1 , True ) ) {
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
}
2001-06-19 06:02:19 +04:00
/* This should fail - no more opens once delete on close set. */
2003-04-18 07:35:39 +04:00
fnum2 = cli_nt_create_full ( cli1 , fname , 0 , GENERIC_READ_ACCESS ,
FILE_ATTRIBUTE_NORMAL , FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE ,
FILE_OPEN , 0 , 0 ) ;
2001-06-19 06:02:19 +04:00
if ( fnum2 ! = - 1 ) {
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 " ) ;
2001-07-02 07:21:17 +04:00
2003-04-18 07:35:39 +04:00
if ( ! cli_close ( cli1 , fnum1 ) ) {
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
}
2001-06-19 06:02:19 +04:00
/* Test 5 ... */
2003-04-18 07:35:39 +04:00
cli_setatr ( cli1 , fname , 0 , 0 ) ;
cli_unlink ( cli1 , fname ) ;
2001-07-02 07:21:17 +04:00
2003-04-18 07:35:39 +04:00
fnum1 = cli_open ( cli1 , fname , O_RDWR | O_CREAT , DENY_NONE ) ;
2001-06-19 06:02:19 +04:00
if ( fnum1 = = - 1 ) {
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. */
2003-04-18 07:35:39 +04:00
if ( 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
2003-04-18 07:35:39 +04:00
if ( ! cli_close ( cli1 , fnum1 ) ) {
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
}
2001-06-19 06:02:19 +04:00
printf ( " fifth delete on close test succeeded. \n " ) ;
2001-07-02 07:21:17 +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 ) ;
cli_unlink ( cli1 , fname ) ;
2001-07-02 07:21:17 +04:00
2003-04-18 07:35:39 +04:00
fnum1 = cli_nt_create_full ( 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 ,
2003-04-18 07:35:39 +04:00
FILE_OVERWRITE_IF , 0 , 0 ) ;
2001-07-02 07:21:17 +04:00
2001-06-19 06:02:19 +04:00
if ( fnum1 = = - 1 ) {
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
}
2001-07-02 07:21:17 +04:00
2001-06-19 06:02:19 +04:00
/* This should fail - only allowed on NT opens with DELETE access. */
2001-07-02 07:21:17 +04:00
2003-04-18 07:35:39 +04:00
if ( 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
2003-04-18 07:35:39 +04:00
if ( ! cli_close ( cli1 , fnum1 ) ) {
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 " ) ;
2001-07-02 07:21:17 +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 ) ;
cli_unlink ( cli1 , fname ) ;
2001-07-02 07:21:17 +04:00
2003-04-18 07:35:39 +04:00
fnum1 = cli_nt_create_full ( cli1 , fname , 0 , FILE_READ_DATA | FILE_WRITE_DATA | DELETE_ACCESS ,
FILE_ATTRIBUTE_NORMAL , 0 , FILE_OVERWRITE_IF , 0 , 0 ) ;
2001-06-19 06:02:19 +04:00
if ( fnum1 = = - 1 ) {
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
}
2003-04-18 07:35:39 +04:00
if ( ! 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
}
2003-04-18 07:35:39 +04:00
if ( ! 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
2003-04-18 07:35:39 +04:00
if ( ! cli_close ( cli1 , fnum1 ) ) {
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
/* This next open should succeed - we reset the flag. */
2001-07-02 07:21:17 +04:00
2003-04-18 07:35:39 +04:00
fnum1 = cli_open ( cli1 , fname , O_RDONLY , DENY_NONE ) ;
2001-06-19 06:02:19 +04:00
if ( fnum1 = = - 1 ) {
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
}
2003-04-18 07:35:39 +04:00
if ( ! cli_close ( cli1 , fnum1 ) ) {
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 " ) ;
2001-07-02 07:21:17 +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 ) ;
cli_unlink ( cli1 , fname ) ;
2001-07-02 07:21:17 +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 ) ;
2001-07-02 07:21:17 +04:00
2003-04-18 07:35:39 +04:00
fnum1 = cli_nt_create_full ( cli1 , fname , 0 , FILE_READ_DATA | FILE_WRITE_DATA | DELETE_ACCESS ,
FILE_ATTRIBUTE_NORMAL , FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE ,
FILE_OVERWRITE_IF , 0 , 0 ) ;
2001-07-02 07:21:17 +04:00
2001-06-19 06:02:19 +04:00
if ( fnum1 = = - 1 ) {
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
}
2003-04-18 07:35:39 +04:00
fnum2 = cli_nt_create_full ( cli2 , fname , 0 , FILE_READ_DATA | FILE_WRITE_DATA | DELETE_ACCESS ,
FILE_ATTRIBUTE_NORMAL , FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE ,
FILE_OPEN , 0 , 0 ) ;
2001-07-02 07:21:17 +04:00
2001-06-19 06:02:19 +04:00
if ( fnum2 = = - 1 ) {
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
}
2003-04-18 07:35:39 +04:00
if ( ! 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
}
2003-04-18 07:35:39 +04:00
if ( ! cli_close ( cli1 , fnum1 ) ) {
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
2003-04-18 07:35:39 +04:00
if ( ! cli_close ( cli2 , fnum2 ) ) {
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.. */
2003-04-18 07:35:39 +04:00
fnum1 = cli_open ( cli1 , fname , O_RDONLY , DENY_NONE ) ;
2001-07-02 07:21:17 +04:00
if ( fnum1 ! = - 1 ) {
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. */
2003-04-18 07:35:39 +04:00
fnum1 = cli_nt_create_full ( cli1 , fname , 0 , FILE_READ_DATA | FILE_WRITE_DATA ,
FILE_ATTRIBUTE_NORMAL , FILE_SHARE_NONE , FILE_OVERWRITE_IF , FILE_DELETE_ON_CLOSE , 0 ) ;
2002-03-07 07:15:40 +03:00
if ( fnum1 ! = - 1 ) {
printf ( " [9] open of %s succeeded should have failed! \n " , fname ) ;
correct = False ;
goto fail ;
}
printf ( " ninth delete on close test succeeded. \n " ) ;
2003-04-18 07:35:39 +04:00
fnum1 = cli_nt_create_full ( 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 ) ;
2002-03-07 07:15:40 +03:00
if ( fnum1 = = - 1 ) {
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. */
2003-04-18 07:35:39 +04:00
if ( ! cli_close ( cli1 , fnum1 ) ) {
printf ( " [10] close failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2002-03-07 07:15:40 +03:00
correct = False ;
goto fail ;
}
/* This should fail.. */
2003-04-18 07:35:39 +04:00
fnum1 = cli_open ( cli1 , fname , O_RDONLY , DENY_NONE ) ;
2002-03-07 07:15:40 +03:00
if ( fnum1 ! = - 1 ) {
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 ) ;
cli_unlink ( cli1 , fname ) ;
/* What error do we get when attempting to open a read-only file with
delete access ? */
/* Create a readonly file. */
fnum1 = cli_nt_create_full ( cli1 , fname , 0 , FILE_READ_DATA | FILE_WRITE_DATA ,
FILE_ATTRIBUTE_READONLY , FILE_SHARE_NONE , FILE_OVERWRITE_IF , 0 , 0 ) ;
if ( fnum1 = = - 1 ) {
printf ( " [11] open of %s failed (%s) \n " , fname , cli_errstr ( cli1 ) ) ;
correct = False ;
goto fail ;
}
if ( ! cli_close ( cli1 , fnum1 ) ) {
printf ( " [11] close failed (%s) \n " , cli_errstr ( cli1 ) ) ;
correct = False ;
goto fail ;
}
/* Now try open for delete access. */
fnum1 = cli_nt_create_full ( cli1 , fname , 0 , FILE_READ_ATTRIBUTES | DELETE_ACCESS ,
0 , FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE ,
FILE_OVERWRITE_IF , 0 , 0 ) ;
if ( fnum1 ! = - 1 ) {
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 " ) ;
}
}
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 . */
2003-12-19 04:43:44 +03:00
if ( fnum1 ! = - 1 ) cli_close ( cli1 , fnum1 ) ;
if ( fnum2 ! = - 1 ) cli_close ( cli1 , fnum2 ) ;
2003-04-18 07:35:39 +04:00
cli_setatr ( cli1 , fname , 0 , 0 ) ;
cli_unlink ( cli1 , fname ) ;
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
*/
static BOOL run_properties ( int dummy )
{
2003-04-18 07:35:39 +04:00
static struct cli_state * cli ;
2002-03-20 02:19:00 +03:00
BOOL correct = True ;
printf ( " starting properties test \n " ) ;
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 ;
}
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
*/
static BOOL run_xcopy ( int dummy )
{
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 " ;
2002-02-24 11:38:11 +03:00
BOOL correct = True ;
int fnum1 , fnum2 ;
printf ( " starting xcopy test \n " ) ;
2006-07-31 13:41:25 +04:00
if ( ! torture_open_connection ( & cli1 , 0 ) ) {
2002-02-24 11:38:11 +03:00
return False ;
}
2003-04-18 07:35:39 +04:00
fnum1 = cli_nt_create_full ( cli1 , fname , 0 ,
2002-03-07 05:16:25 +03:00
FIRST_DESIRED_ACCESS , FILE_ATTRIBUTE_ARCHIVE ,
FILE_SHARE_NONE , FILE_OVERWRITE_IF ,
2003-04-18 07:35:39 +04:00
0x4044 , 0 ) ;
2002-02-24 11:38:11 +03:00
if ( fnum1 = = - 1 ) {
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 ;
}
2003-04-18 07:35:39 +04:00
fnum2 = cli_nt_create_full ( 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 ,
2003-04-18 07:35:39 +04:00
0x200000 , 0 ) ;
2002-02-24 11:38:11 +03:00
if ( fnum2 = = - 1 ) {
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 ;
}
2003-04-18 07:35:39 +04:00
if ( ! torture_close_connection ( cli1 ) ) {
2002-02-24 11:38:11 +03:00
correct = False ;
}
return correct ;
}
2002-03-05 22:45:16 +03:00
/*
Test rename on files open with share delete and no share delete .
*/
static BOOL run_rename ( int dummy )
{
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 " ;
2002-03-05 22:45:16 +03:00
BOOL correct = True ;
2002-03-10 04:47:12 +03:00
int fnum1 ;
2002-03-05 22:45:16 +03:00
printf ( " starting rename test \n " ) ;
2006-07-31 13:41:25 +04:00
if ( ! torture_open_connection ( & cli1 , 0 ) ) {
2002-03-05 22:45:16 +03:00
return False ;
}
2003-04-18 07:35:39 +04:00
cli_unlink ( cli1 , fname ) ;
cli_unlink ( cli1 , fname1 ) ;
fnum1 = cli_nt_create_full ( cli1 , fname , 0 , GENERIC_READ_ACCESS , FILE_ATTRIBUTE_NORMAL ,
FILE_SHARE_READ , FILE_OVERWRITE_IF , 0 , 0 ) ;
2002-03-05 22:45:16 +03:00
if ( fnum1 = = - 1 ) {
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 ;
}
2003-04-18 07:35:39 +04:00
if ( ! 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 ;
}
2003-04-18 07:35:39 +04:00
if ( ! cli_close ( cli1 , fnum1 ) ) {
printf ( " close - 1 failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2002-03-05 22:45:16 +03:00
return False ;
}
2003-04-18 07:35:39 +04:00
cli_unlink ( cli1 , fname ) ;
cli_unlink ( cli1 , fname1 ) ;
fnum1 = cli_nt_create_full ( cli1 , fname , 0 , GENERIC_READ_ACCESS , FILE_ATTRIBUTE_NORMAL ,
2002-03-23 05:57:44 +03:00
#if 0
2003-04-18 07:35:39 +04:00
FILE_SHARE_DELETE | FILE_SHARE_NONE , FILE_OVERWRITE_IF , 0 , 0 ) ;
2002-03-23 05:57:44 +03:00
# else
2003-04-18 07:35:39 +04:00
FILE_SHARE_DELETE | FILE_SHARE_READ , FILE_OVERWRITE_IF , 0 , 0 ) ;
2002-03-23 05:57:44 +03:00
# endif
2002-03-05 22:45:16 +03:00
if ( fnum1 = = - 1 ) {
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 ;
}
2003-04-18 07:35:39 +04:00
if ( ! 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
}
2003-04-18 07:35:39 +04:00
if ( ! cli_close ( cli1 , fnum1 ) ) {
printf ( " close - 2 failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2002-03-23 05:57:44 +03:00
return False ;
}
2003-04-18 07:35:39 +04:00
cli_unlink ( cli1 , fname ) ;
cli_unlink ( cli1 , fname1 ) ;
2002-03-23 05:57:44 +03:00
2003-04-18 07:35:39 +04:00
fnum1 = cli_nt_create_full ( cli1 , fname , 0 , READ_CONTROL_ACCESS , FILE_ATTRIBUTE_NORMAL ,
FILE_SHARE_NONE , FILE_OVERWRITE_IF , 0 , 0 ) ;
2002-03-23 05:57:44 +03:00
if ( fnum1 = = - 1 ) {
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
{
int fnum2 ;
2003-04-18 07:35:39 +04:00
fnum2 = cli_nt_create_full ( cli1 , fname , 0 , DELETE_ACCESS , FILE_ATTRIBUTE_NORMAL ,
FILE_SHARE_NONE , FILE_OVERWRITE_IF , 0 , 0 ) ;
2002-03-23 05:57:44 +03:00
if ( fnum2 = = - 1 ) {
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 ;
}
2003-04-18 07:35:39 +04:00
if ( ! 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 ;
}
2003-04-18 07:35:39 +04:00
if ( ! cli_close ( cli1 , fnum2 ) ) {
printf ( " close - 4 failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2002-03-23 05:57:44 +03:00
return False ;
}
}
# endif
2003-04-18 07:35:39 +04:00
if ( ! 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
}
2003-04-18 07:35:39 +04:00
if ( ! cli_close ( cli1 , fnum1 ) ) {
printf ( " close - 3 failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2002-03-05 22:45:16 +03:00
return False ;
}
2003-04-18 07:35:39 +04:00
cli_unlink ( cli1 , fname ) ;
cli_unlink ( cli1 , fname1 ) ;
2002-03-05 22:45:16 +03:00
2004-02-26 04:33:35 +03:00
/*----*/
fnum1 = cli_nt_create_full ( cli1 , fname , 0 , GENERIC_READ_ACCESS , FILE_ATTRIBUTE_NORMAL ,
FILE_SHARE_READ | FILE_SHARE_WRITE , FILE_OVERWRITE_IF , 0 , 0 ) ;
if ( fnum1 = = - 1 ) {
printf ( " Fourth open failed - %s \n " , cli_errstr ( cli1 ) ) ;
return False ;
}
if ( ! cli_rename ( cli1 , fname , fname1 ) ) {
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 ;
}
if ( ! cli_close ( cli1 , fnum1 ) ) {
printf ( " close - 4 failed (%s) \n " , cli_errstr ( cli1 ) ) ;
return False ;
}
cli_unlink ( cli1 , fname ) ;
cli_unlink ( cli1 , fname1 ) ;
/*--*/
fnum1 = cli_nt_create_full ( cli1 , fname , 0 , GENERIC_READ_ACCESS , FILE_ATTRIBUTE_NORMAL ,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE , FILE_OVERWRITE_IF , 0 , 0 ) ;
if ( fnum1 = = - 1 ) {
printf ( " Fifth open failed - %s \n " , cli_errstr ( cli1 ) ) ;
return False ;
}
if ( ! cli_rename ( cli1 , fname , fname1 ) ) {
printf ( " Fifth rename failed (SHARE_READ | SHARE_WRITE | SHARE_DELETE) - this should have failed ! \n " ) ;
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 . . .
*/
/*fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE , FILE_OVERWRITE_IF , 0 , 0 ) ;
if ( fnum2 = = - 1 ) {
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 ) ;
} */
/*--*/
if ( ! cli_close ( cli1 , fnum1 ) ) {
printf ( " close - 5 failed (%s) \n " , cli_errstr ( cli1 ) ) ;
return False ;
}
cli_unlink ( cli1 , fname ) ;
cli_unlink ( cli1 , fname1 ) ;
2003-04-18 07:35:39 +04:00
if ( ! torture_close_connection ( cli1 ) ) {
2002-03-05 22:45:16 +03:00
correct = False ;
}
return correct ;
}
2002-07-15 14:35:28 +04:00
static BOOL run_pipe_number ( int dummy )
{
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 " ;
2002-07-15 14:35:28 +04:00
int fnum ;
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 ) {
2003-04-18 07:35:39 +04:00
fnum = cli_nt_create_full ( cli1 , pipe_name , 0 , FILE_READ_DATA , FILE_ATTRIBUTE_NORMAL ,
FILE_SHARE_READ | FILE_SHARE_WRITE , FILE_OPEN_IF , 0 , 0 ) ;
2002-07-15 14:35:28 +04:00
if ( fnum = = - 1 ) {
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 .
*/
2001-07-02 07:21:17 +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 " ;
2001-07-02 07:21:17 +04:00
int 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 ;
2001-07-02 07:21:17 +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 " ) ;
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_setatr ( cli1 , fname , 0 , 0 ) ;
cli_unlink ( cli1 , fname ) ;
2001-07-02 07:21:17 +04:00
2003-04-18 07:35:39 +04:00
cli_sockopt ( cli1 , sockops ) ;
2001-07-02 07:21:17 +04:00
2003-04-18 07:35:39 +04:00
fnum1 = cli_open ( cli1 , fname , O_RDWR | O_CREAT | O_EXCL , DENY_NONE ) ;
2001-07-02 07:21:17 +04:00
if ( fnum1 = = - 1 ) {
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_close ( cli1 , fnum1 ) ) {
printf ( " close2 failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2001-07-02 07:21:17 +04:00
return False ;
}
2003-04-18 07:35:39 +04:00
if ( ! cli_setatr ( cli1 , fname , aRONLY , 0 ) ) {
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
}
2001-07-02 07:21:17 +04:00
2003-04-18 07:35:39 +04:00
fnum1 = cli_open ( cli1 , fname , O_RDONLY , DENY_WRITE ) ;
2001-07-02 07:21:17 +04:00
if ( fnum1 = = - 1 ) {
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
/* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
2003-04-18 07:35:39 +04:00
fnum2 = cli_open ( cli1 , fname , O_RDWR , DENY_ALL ) ;
2001-07-02 07:21:17 +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 " ) ;
}
2001-07-02 07:21:17 +04:00
printf ( " finished open test 1 \n " ) ;
2003-04-18 07:35:39 +04:00
cli_close ( cli1 , fnum1 ) ;
2001-07-02 07:21:17 +04:00
2001-06-19 06:02:19 +04:00
/* Now try not readonly and ensure ERRbadshare is returned. */
2001-07-02 07:21:17 +04:00
2003-04-18 07:35:39 +04:00
cli_setatr ( cli1 , fname , 0 , 0 ) ;
2001-07-02 07:21:17 +04:00
2003-04-18 07:35:39 +04:00
fnum1 = cli_open ( cli1 , fname , O_RDONLY , DENY_WRITE ) ;
2001-07-02 07:21:17 +04:00
if ( fnum1 = = - 1 ) {
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
/* This will fail - but the error should be ERRshare. */
2003-04-18 07:35:39 +04:00
fnum2 = cli_open ( cli1 , fname , O_RDWR , DENY_ALL ) ;
2001-07-02 07:21:17 +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 " ) ;
}
2001-07-02 07:21:17 +04:00
2003-04-18 07:35:39 +04:00
if ( ! cli_close ( cli1 , fnum1 ) ) {
printf ( " close2 failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2001-07-02 07:21:17 +04:00
return False ;
}
2003-04-18 07:35:39 +04:00
cli_unlink ( cli1 , fname ) ;
2001-07-02 07:21:17 +04:00
printf ( " finished open test 2 \n " ) ;
2001-06-19 06:02:19 +04:00
/* Test truncate open disposition on file opened for read. */
2001-07-02 07:21:17 +04:00
2003-04-18 07:35:39 +04:00
fnum1 = cli_open ( cli1 , fname , O_RDWR | O_CREAT | O_EXCL , DENY_NONE ) ;
2001-07-02 07:21:17 +04:00
if ( fnum1 = = - 1 ) {
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 ;
}
2001-06-19 06:02:19 +04:00
/* write 20 bytes. */
2001-07-02 07:21:17 +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
}
2003-04-18 07:35:39 +04:00
if ( ! cli_close ( cli1 , fnum1 ) ) {
printf ( " (3) 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
/* Ensure size == 20. */
2003-04-18 07:35:39 +04:00
if ( ! cli_getatr ( cli1 , fname , NULL , & fsize , NULL ) ) {
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
}
2001-07-02 07:21:17 +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. */
2001-07-02 07:21:17 +04:00
2003-04-18 07:35:39 +04:00
fnum1 = cli_open ( cli1 , fname , O_RDONLY | O_TRUNC , DENY_NONE ) ;
2001-07-02 07:21:17 +04:00
if ( fnum1 = = - 1 ) {
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 ;
}
2003-04-18 07:35:39 +04:00
if ( ! cli_close ( cli1 , fnum1 ) ) {
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. */
2003-04-18 07:35:39 +04:00
if ( ! cli_getatr ( cli1 , fname , NULL , & fsize , NULL ) ) {
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 " ) ;
2003-04-18 07:35:39 +04:00
cli_unlink ( cli1 , fname ) ;
2001-06-19 06:02:19 +04:00
printf ( " testing ctemp \n " ) ;
2003-04-18 07:35:39 +04:00
fnum1 = cli_ctemp ( cli1 , " \\ " , & tmp_path ) ;
2001-09-17 08:23:48 +04:00
if ( fnum1 = = - 1 ) {
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 ) ;
2003-04-18 07:35:39 +04:00
if ( ! cli_close ( cli1 , fnum1 ) ) {
printf ( " close of temp failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2001-09-17 08:23:48 +04:00
}
2003-04-18 07:35:39 +04:00
if ( ! cli_unlink ( cli1 , tmp_path ) ) {
printf ( " unlink of temp failed (%s) \n " , cli_errstr ( cli1 ) ) ;
2001-06-19 06:02:19 +04:00
}
2001-07-02 07:21:17 +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 ;
}
2003-04-18 07:35:39 +04:00
cli_setatr ( cli2 , fname , 0 , 0 ) ;
cli_unlink ( cli2 , fname ) ;
2002-03-26 03:07:48 +03: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 " ) ;
2003-04-18 07:35:39 +04:00
fnum1 = cli_nt_create_full ( cli1 , fname , 0 , FILE_READ_ATTRIBUTES , FILE_ATTRIBUTE_NORMAL ,
FILE_SHARE_NONE , FILE_OVERWRITE_IF , 0 , 0 ) ;
2002-03-26 03:07:48 +03:00
if ( fnum1 = = - 1 ) {
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 ;
}
2003-04-18 07:35:39 +04:00
fnum2 = cli_nt_create_full ( cli2 , fname , 0 , FILE_READ_ATTRIBUTES , FILE_ATTRIBUTE_NORMAL ,
FILE_SHARE_NONE , FILE_OPEN_IF , 0 , 0 ) ;
2002-03-26 03:07:48 +03:00
if ( fnum2 = = - 1 ) {
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 ;
}
2003-04-18 07:35:39 +04:00
if ( ! cli_close ( cli1 , fnum1 ) ) {
printf ( " test 1 close 1 of %s failed (%s) \n " , fname , cli_errstr ( cli1 ) ) ;
2002-03-26 03:07:48 +03:00
return False ;
}
2003-04-18 07:35:39 +04:00
if ( ! cli_close ( cli2 , fnum2 ) ) {
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 " ) ;
2003-04-18 07:35:39 +04:00
cli_unlink ( cli1 , fname ) ;
2002-03-26 03:07:48 +03:00
printf ( " TEST #2 testing 2 non-io opens (first with delete) \n " ) ;
2003-04-18 07:35:39 +04:00
fnum1 = cli_nt_create_full ( cli1 , fname , 0 , DELETE_ACCESS | FILE_READ_ATTRIBUTES , FILE_ATTRIBUTE_NORMAL ,
FILE_SHARE_NONE , FILE_OVERWRITE_IF , 0 , 0 ) ;
2002-03-26 03:07:48 +03:00
if ( fnum1 = = - 1 ) {
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 ;
}
2003-04-18 07:35:39 +04:00
fnum2 = cli_nt_create_full ( cli2 , fname , 0 , FILE_READ_ATTRIBUTES , FILE_ATTRIBUTE_NORMAL ,
FILE_SHARE_NONE , FILE_OPEN_IF , 0 , 0 ) ;
2002-03-26 03:07:48 +03:00
if ( fnum2 = = - 1 ) {
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 ;
}
2003-04-18 07:35:39 +04:00
if ( ! cli_close ( cli1 , fnum1 ) ) {
printf ( " test 1 close 1 of %s failed (%s) \n " , fname , cli_errstr ( cli1 ) ) ;
2002-03-26 03:07:48 +03:00
return False ;
}
2003-04-18 07:35:39 +04:00
if ( ! cli_close ( cli2 , fnum2 ) ) {
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 " ) ;
2003-04-18 07:35:39 +04:00
cli_unlink ( cli1 , fname ) ;
2002-03-26 03:07:48 +03:00
printf ( " TEST #3 testing 2 non-io opens (second with delete) \n " ) ;
2003-04-18 07:35:39 +04:00
fnum1 = cli_nt_create_full ( cli1 , fname , 0 , FILE_READ_ATTRIBUTES , FILE_ATTRIBUTE_NORMAL ,
FILE_SHARE_NONE , FILE_OVERWRITE_IF , 0 , 0 ) ;
2002-03-26 03:07:48 +03:00
if ( fnum1 = = - 1 ) {
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 ;
}
2003-04-18 07:35:39 +04:00
fnum2 = cli_nt_create_full ( cli2 , fname , 0 , DELETE_ACCESS | FILE_READ_ATTRIBUTES , FILE_ATTRIBUTE_NORMAL ,
FILE_SHARE_NONE , FILE_OPEN_IF , 0 , 0 ) ;
2002-03-26 03:07:48 +03:00
if ( fnum2 = = - 1 ) {
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 ;
}
2003-04-18 07:35:39 +04:00
if ( ! cli_close ( cli1 , fnum1 ) ) {
printf ( " test 3 close 1 of %s failed (%s) \n " , fname , cli_errstr ( cli1 ) ) ;
2002-03-26 03:07:48 +03:00
return False ;
}
2003-04-18 07:35:39 +04:00
if ( ! cli_close ( cli2 , fnum2 ) ) {
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 " ) ;
2003-04-18 07:35:39 +04:00
cli_unlink ( cli1 , fname ) ;
2002-03-26 03:07:48 +03:00
printf ( " TEST #4 testing 2 non-io opens (both with delete) \n " ) ;
2003-04-18 07:35:39 +04:00
fnum1 = cli_nt_create_full ( cli1 , fname , 0 , DELETE_ACCESS | FILE_READ_ATTRIBUTES , FILE_ATTRIBUTE_NORMAL ,
FILE_SHARE_NONE , FILE_OVERWRITE_IF , 0 , 0 ) ;
2002-03-26 03:07:48 +03:00
if ( fnum1 = = - 1 ) {
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 ;
}
2003-04-18 07:35:39 +04:00
fnum2 = cli_nt_create_full ( cli2 , fname , 0 , DELETE_ACCESS | FILE_READ_ATTRIBUTES , FILE_ATTRIBUTE_NORMAL ,
FILE_SHARE_NONE , FILE_OPEN_IF , 0 , 0 ) ;
2002-03-26 03:07:48 +03:00
if ( fnum2 ! = - 1 ) {
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
2003-04-18 07:35:39 +04:00
if ( ! cli_close ( cli1 , fnum1 ) ) {
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 " ) ;
2003-04-18 07:35:39 +04:00
cli_unlink ( cli1 , fname ) ;
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 " ) ;
2003-04-18 07:35:39 +04:00
fnum1 = cli_nt_create_full ( cli1 , fname , 0 , DELETE_ACCESS | FILE_READ_ATTRIBUTES , FILE_ATTRIBUTE_NORMAL ,
FILE_SHARE_DELETE , FILE_OVERWRITE_IF , 0 , 0 ) ;
2002-03-26 03:07:48 +03:00
if ( fnum1 = = - 1 ) {
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 ;
}
2003-04-18 07:35:39 +04:00
fnum2 = cli_nt_create_full ( cli2 , fname , 0 , DELETE_ACCESS | FILE_READ_ATTRIBUTES , FILE_ATTRIBUTE_NORMAL ,
FILE_SHARE_DELETE , FILE_OPEN_IF , 0 , 0 ) ;
2002-03-26 03:07:48 +03:00
if ( fnum2 = = - 1 ) {
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 ;
}
2003-04-18 07:35:39 +04:00
if ( ! cli_close ( cli1 , fnum1 ) ) {
printf ( " test 5 close 1 of %s failed (%s) \n " , fname , cli_errstr ( cli1 ) ) ;
2002-03-26 03:07:48 +03:00
return False ;
}
2003-04-18 07:35:39 +04:00
if ( ! cli_close ( cli2 , fnum2 ) ) {
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 " ) ;
2003-04-18 07:35:39 +04:00
cli_unlink ( cli1 , fname ) ;
2002-03-26 03:40:18 +03:00
2003-04-18 07:35:39 +04:00
fnum1 = cli_nt_create_full ( cli1 , fname , 0 , FILE_READ_DATA , FILE_ATTRIBUTE_NORMAL ,
FILE_SHARE_NONE , FILE_OVERWRITE_IF , 0 , 0 ) ;
2002-03-26 03:40:18 +03:00
if ( fnum1 = = - 1 ) {
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 ;
}
2003-04-18 07:35:39 +04:00
fnum2 = cli_nt_create_full ( cli2 , fname , 0 , FILE_READ_ATTRIBUTES , FILE_ATTRIBUTE_NORMAL ,
FILE_SHARE_READ , FILE_OPEN_IF , 0 , 0 ) ;
2002-03-26 03:40:18 +03:00
if ( fnum2 = = - 1 ) {
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 ;
}
2003-04-18 07:35:39 +04:00
if ( ! cli_close ( cli1 , fnum1 ) ) {
printf ( " test 6 close 1 of %s failed (%s) \n " , fname , cli_errstr ( cli1 ) ) ;
2002-03-26 03:40:18 +03:00
return False ;
}
2003-04-18 07:35:39 +04:00
if ( ! cli_close ( cli2 , fnum2 ) ) {
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 " ) ;
2003-04-18 07:35:39 +04:00
cli_unlink ( cli1 , fname ) ;
2002-03-26 03:40:18 +03:00
2003-04-18 07:35:39 +04:00
fnum1 = cli_nt_create_full ( cli1 , fname , 0 , FILE_READ_DATA , FILE_ATTRIBUTE_NORMAL ,
FILE_SHARE_NONE , FILE_OVERWRITE_IF , 0 , 0 ) ;
2002-03-26 03:40:18 +03:00
if ( fnum1 = = - 1 ) {
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 ;
}
2003-04-18 07:35:39 +04:00
fnum2 = cli_nt_create_full ( cli2 , fname , 0 , DELETE_ACCESS | FILE_READ_ATTRIBUTES , FILE_ATTRIBUTE_NORMAL ,
FILE_SHARE_READ | FILE_SHARE_DELETE , FILE_OPEN_IF , 0 , 0 ) ;
2002-03-26 03:40:18 +03:00
if ( fnum2 ! = - 1 ) {
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
2003-04-18 07:35:39 +04:00
if ( ! cli_close ( cli1 , fnum1 ) ) {
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 " ) ;
2003-04-18 07:35:39 +04:00
cli_unlink ( cli1 , fname ) ;
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
}
2003-04-18 07:35:39 +04:00
return correct ;
}
2002-09-25 19:19:00 +04:00
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 }
} ;
static BOOL run_openattrtest ( int dummy )
{
static struct cli_state * cli1 ;
const char * fname = " \\ openattr.file " ;
int fnum1 ;
BOOL correct = True ;
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 " ) ;
2006-07-31 13:41:25 +04:00
if ( ! torture_open_connection ( & cli1 , 0 ) ) {
2002-09-25 19:19:00 +04:00
return False ;
}
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 ) ;
cli_unlink ( cli1 , fname ) ;
fnum1 = cli_nt_create_full ( cli1 , fname , 0 , FILE_WRITE_DATA , open_attrs_table [ i ] ,
FILE_SHARE_NONE , FILE_OVERWRITE_IF , 0 , 0 ) ;
2002-09-25 19:19:00 +04:00
2003-04-18 07:35:39 +04:00
if ( fnum1 = = - 1 ) {
printf ( " open %d (1) of %s failed (%s) \n " , i , fname , cli_errstr ( cli1 ) ) ;
return False ;
2002-09-25 19:19:00 +04:00
}
2003-04-18 07:35:39 +04:00
if ( ! cli_close ( cli1 , fnum1 ) ) {
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 + + ) {
fnum1 = cli_nt_create_full ( cli1 , fname , 0 , FILE_READ_DATA | FILE_WRITE_DATA , open_attrs_table [ j ] ,
FILE_SHARE_NONE , FILE_OVERWRITE , 0 , 0 ) ;
if ( fnum1 = = - 1 ) {
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
2003-04-18 07:35:39 +04:00
if ( ! cli_close ( cli1 , fnum1 ) ) {
printf ( " close %d (2) of %s failed (%s) \n " , j , fname , cli_errstr ( cli1 ) ) ;
return False ;
}
2002-11-19 02:13:25 +03:00
2003-04-18 07:35:39 +04:00
if ( ! cli_getatr ( cli1 , fname , & attr , NULL , NULL ) ) {
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 ) ;
cli_unlink ( cli1 , fname ) ;
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
{
}
/*
test directory listing speed
*/
2001-07-02 07:21:17 +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 ;
2001-06-19 06:02:19 +04:00
int fnum ;
double t1 ;
2001-07-02 07:21:17 +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 ( ) ) ;
2003-04-18 07:35:39 +04:00
fnum = cli_open ( cli , fname , O_RDWR | O_CREAT , DENY_NONE ) ;
2001-06-19 06:02:19 +04:00
if ( fnum = = - 1 ) {
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
}
t1 = end_timer ( ) ;
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
printf ( " dirtest core %g seconds \n " , end_timer ( ) - t1 ) ;
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 ( ) ) ;
2003-04-18 07:35:39 +04:00
cli_unlink ( cli , fname ) ;
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 ) {
if ( ! cli_rmdir ( pcli , fname ) )
printf ( " del_fn: failed to rmdir %s \n , " , fname ) ;
} else {
if ( ! cli_unlink ( pcli , fname ) )
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
*/
BOOL torture_ioctl_test ( int dummy )
{
static struct cli_state * cli ;
uint16 device , function ;
int fnum ;
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 " ) ;
cli_unlink ( cli , fname ) ;
fnum = cli_open ( cli , fname , O_RDWR | O_CREAT | O_EXCL , DENY_NONE ) ;
if ( fnum = = - 1 ) {
printf ( " open of %s failed (%s) \n " , fname , cli_errstr ( cli ) ) ;
return False ;
}
status = cli_raw_ioctl ( cli , fnum , 0x2d0000 | ( 0x0420 < < 2 ) , & blob ) ;
printf ( " ioctl device info: %s \n " , cli_errstr ( cli ) ) ;
status = cli_raw_ioctl ( cli , fnum , IOCTL_QUERY_JOB_INFO , & blob ) ;
printf ( " ioctl job info: %s \n " , cli_errstr ( cli ) ) ;
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
*/
BOOL torture_chkpath_test ( int dummy )
{
static struct cli_state * cli ;
int fnum ;
BOOL ret ;
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 " ) ;
cli_unlink ( cli , " \\ chkpath.dir \\ * " ) ;
cli_rmdir ( cli , " \\ chkpath.dir " ) ;
if ( ! cli_mkdir ( cli , " \\ chkpath.dir " ) ) {
printf ( " mkdir1 failed : %s \n " , cli_errstr ( cli ) ) ;
return False ;
}
if ( ! cli_mkdir ( cli , " \\ chkpath.dir \\ dir2 " ) ) {
printf ( " mkdir2 failed : %s \n " , cli_errstr ( cli ) ) ;
return False ;
}
fnum = cli_open ( cli , " \\ chkpath.dir \\ foo.txt " , O_RDWR | O_CREAT | O_EXCL , DENY_NONE ) ;
if ( fnum = = - 1 ) {
printf ( " open1 failed (%s) \n " , cli_errstr ( cli ) ) ;
return False ;
}
cli_close ( cli , fnum ) ;
if ( ! cli_chkpath ( cli , " \\ chkpath.dir " ) ) {
printf ( " chkpath1 failed: %s \n " , cli_errstr ( cli ) ) ;
ret = False ;
}
if ( ! cli_chkpath ( cli , " \\ chkpath.dir \\ dir2 " ) ) {
printf ( " chkpath2 failed: %s \n " , cli_errstr ( cli ) ) ;
ret = False ;
}
if ( ! cli_chkpath ( cli , " \\ chkpath.dir \\ foo.txt " ) ) {
ret = check_error ( __LINE__ , cli , ERRDOS , ERRbadpath ,
NT_STATUS_NOT_A_DIRECTORY ) ;
} else {
printf ( " * chkpath on a file should fail \n " ) ;
ret = False ;
}
if ( ! cli_chkpath ( cli , " \\ chkpath.dir \\ bar.txt " ) ) {
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 ;
}
if ( ! cli_chkpath ( cli , " \\ chkpath.dir \\ dirxx \\ bar.txt " ) ) {
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 " ) ;
cli_unlink ( cli , " \\ chkpath.dir \\ * " ) ;
cli_rmdir ( cli , " \\ chkpath.dir " ) ;
if ( ! torture_close_connection ( cli ) ) {
return False ;
}
return ret ;
}
2004-03-27 05:13:58 +03:00
static BOOL run_eatest ( int dummy )
{
static struct cli_state * cli ;
const char * fname = " \\ eatest.txt " ;
BOOL correct = True ;
int fnum , 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 " ) ;
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 ;
}
cli_unlink ( cli , fname ) ;
fnum = cli_nt_create_full ( cli , fname , 0 ,
FIRST_DESIRED_ACCESS , FILE_ATTRIBUTE_ARCHIVE ,
FILE_SHARE_NONE , FILE_OVERWRITE_IF ,
0x4044 , 0 ) ;
if ( fnum = = - 1 ) {
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 ;
}
}
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 ;
}
}
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 ;
}
return correct ;
}
2003-04-18 07:35:39 +04:00
2002-09-25 19:19:00 +04:00
static BOOL run_dirtest1 ( int dummy )
{
int i ;
2003-04-18 07:35:39 +04:00
static struct cli_state * cli ;
2002-09-25 19:19:00 +04:00
int fnum , num_seen ;
BOOL correct = True ;
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 ) ;
2003-04-18 07:35:39 +04:00
fnum = cli_nt_create_full ( cli , fname , 0 , GENERIC_ALL_ACCESS , FILE_ATTRIBUTE_ARCHIVE ,
FILE_SHARE_READ | FILE_SHARE_WRITE , FILE_OVERWRITE_IF , 0 , 0 ) ;
2002-09-25 19:19:00 +04:00
if ( fnum = = - 1 ) {
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 ) ;
2003-04-18 07:35:39 +04:00
if ( ! 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 ;
}
2001-11-25 05:35:37 +03:00
static BOOL run_error_map_extract ( int dummy ) {
2006-07-11 22:01:26 +04:00
static struct cli_state * c_dos ;
static struct cli_state * c_nt ;
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
2006-07-11 22:01:26 +04:00
if ( ! cli_negprot ( c_nt ) ) {
printf ( " %s rejected the NT-error negprot (%s) \n " , host , cli_errstr ( c_nt ) ) ;
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
2006-07-11 22:01:26 +04:00
if ( ! cli_negprot ( c_dos ) ) {
printf ( " %s rejected the DOS-error negprot (%s) \n " , host , cli_errstr ( c_dos ) ) ;
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 " ) ;
}
2006-07-11 22:01:26 +04:00
flgs2 = SVAL ( c_nt - > inbuf , smb_flg2 ) ;
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 ;
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
}
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-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 ;
}
2006-07-11 22:01:26 +04:00
static BOOL run_local_substitute ( int dummy )
{
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
}
2006-09-10 01:05:51 +04:00
static BOOL run_local_gencache ( int dummy )
{
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_init ( ) ) {
d_printf ( " %s: gencache_init() failed \n " , __location__ ) ;
return False ;
}
if ( ! gencache_set ( " foo " , " bar " , time ( NULL ) + 1000 ) ) {
d_printf ( " %s: gencache_set() failed \n " , __location__ ) ;
return False ;
}
if ( ! gencache_get ( " foo " , & val , & tm ) ) {
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 ;
}
if ( gencache_get ( " foo " , & val , & tm ) ) {
d_printf ( " %s: gencache_get() on deleted entry "
" succeeded \n " , __location__ ) ;
return False ;
}
2007-08-28 16:40:01 +04:00
blob = data_blob_string_const ( " bar " ) ;
tm = time ( NULL ) ;
if ( ! gencache_set_data_blob ( " foo " , & blob , tm ) ) {
d_printf ( " %s: gencache_set_data_blob() failed \n " , __location__ ) ;
return False ;
}
data_blob_free ( & blob ) ;
if ( ! gencache_get_data_blob ( " foo " , & blob , NULL ) ) {
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 ;
}
if ( gencache_get_data_blob ( " foo " , & blob , NULL ) ) {
d_printf ( " %s: gencache_get_data_blob() on deleted entry "
" succeeded \n " , __location__ ) ;
return False ;
}
2006-09-10 01:05:51 +04:00
if ( ! gencache_shutdown ( ) ) {
d_printf ( " %s: gencache_shutdown() failed \n " , __location__ ) ;
return False ;
}
if ( gencache_shutdown ( ) ) {
d_printf ( " %s: second gencache_shutdown() succeeded \n " ,
__location__ ) ;
return False ;
}
return True ;
}
2001-07-02 07:21:17 +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 ;
volatile BOOL * child_status_out ;
2001-06-19 06:02:19 +04:00
int synccount ;
int tries = 8 ;
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 ;
}
child_status_out = ( volatile BOOL * ) shm_setup ( sizeof ( BOOL ) * nprocs ) ;
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
start_timer ( ) ;
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 ( ) ;
2004-02-23 05:54:03 +03:00
while ( child_status [ i ] & & end_timer ( ) < 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 ) ;
2001-06-19 06:02:19 +04:00
} while ( end_timer ( ) < 30 ) ;
if ( synccount ! = nprocs ) {
printf ( " FAILED TO START %d CLIENTS (started %d) \n " , nprocs , synccount ) ;
2001-07-02 07:21:17 +04:00
* result = False ;
2001-06-19 06:02:19 +04:00
return end_timer ( ) ;
}
/* start the client load */
start_timer ( ) ;
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 " ) ;
2001-07-02 07:21:17 +04:00
for ( i = 0 ; i < nprocs ; i + + ) {
if ( ! child_status_out [ i ] ) {
* result = False ;
}
}
2001-06-19 06:02:19 +04:00
return end_timer ( ) ;
}
# define FLAG_MULTIPROC 1
static struct {
2003-01-03 11:28:12 +03:00
const char * name ;
2001-07-02 07:21:17 +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 } ,
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 } ,
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 } ,
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 } ,
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 } ,
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 } ,
2001-06-19 06:02:19 +04:00
{ NULL , NULL , 0 } } ;
/****************************************************************************
run a specified test or " ALL "
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2003-01-03 11:28:12 +03:00
static BOOL run_test ( const char * name )
2001-06-19 06:02:19 +04:00
{
2001-07-02 07:21:17 +04:00
BOOL ret = True ;
BOOL result = True ;
2003-12-30 18:18:25 +03:00
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
}
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 {
2001-07-02 07:21:17 +04:00
start_timer ( ) ;
if ( ! torture_ops [ i ] . fn ( 0 ) ) {
ret = False ;
printf ( " TEST %s FAILED! \n " , name ) ;
}
t = end_timer ( ) ;
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 " ) ;
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 ;
2001-07-02 07:21:17 +04:00
BOOL correct = True ;
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 ( ) ;
2006-01-29 01:53:04 +03:00
lp_load ( 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 = ' / ' ;
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 ) ;
get_myname ( myname ) ;
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 + + ;
2002-09-25 19:19:00 +04:00
srandom ( time ( NULL ) ) ;
2001-06-19 06:02:19 +04:00
fstrcpy ( workgroup , lp_workgroup ( ) ) ;
2006-08-15 18:07:15 +04:00
while ( ( opt = getopt ( argc , argv , " p:hW:U:n:N:O:o:m:Ld:Ac:ks: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 ' :
srandom ( atoi ( optarg ) ) ;
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 ;
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 ;
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 ;
2001-06-19 06:02:19 +04:00
default :
printf ( " Unknown option %c (%d) \n " , ( char ) opt , opt ) ;
usage ( ) ;
}
}
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
}
}
2001-07-02 07:21:17 +04:00
if ( correct ) {
return ( 0 ) ;
} else {
return ( 1 ) ;
}
2001-06-19 06:02:19 +04:00
}