2003-08-13 05:53:07 +04:00
/*
Unix SMB / CIFS implementation .
randomised byte range lock tester
Copyright ( C ) Andrew Tridgell 1999
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
2007-07-10 06:07:03 +04:00
the Free Software Foundation ; either version 3 of the License , or
2003-08-13 05:53:07 +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 06:07:03 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2003-08-13 05:53:07 +04:00
*/
# include "includes.h"
2005-02-10 08:09:35 +03:00
# include "system/filesys.h"
2004-11-02 03:24:21 +03:00
# include "system/time.h"
2005-09-19 16:58:43 +04:00
# include "pstring.h"
2006-11-07 03:48:36 +03:00
# include "auth/credentials/credentials.h"
2005-12-31 01:46:16 +03:00
# include "auth/gensec/gensec.h"
2006-01-03 18:40:05 +03:00
# include "libcli/libcli.h"
2003-08-13 05:53:07 +04:00
static int numops = 1000 ;
static BOOL showall ;
static BOOL analyze ;
static BOOL hide_unlock_fails ;
static BOOL use_oplocks ;
2004-06-01 14:12:52 +04:00
static uint_t lock_range = 100 ;
static uint_t lock_base = 0 ;
static uint_t min_length = 0 ;
2003-08-13 05:53:07 +04:00
static BOOL exact_error_codes ;
static BOOL zero_zero ;
# define FILENAME "\\locktest.dat"
# define READ_PCT 50
# define LOCK_PCT 45
# define UNLOCK_PCT 70
# define RANGE_MULTIPLE 1
# define NSERVERS 2
# define NCONNECTIONS 2
# define NFILES 2
# define LOCK_TIMEOUT 0
2005-03-22 22:30:59 +03:00
static struct cli_credentials * servers [ NSERVERS ] ;
2004-08-10 00:51:16 +04:00
2003-08-13 05:53:07 +04:00
enum lock_op { OP_LOCK , OP_UNLOCK , OP_REOPEN } ;
struct record {
enum lock_op lock_op ;
enum brl_type lock_type ;
char conn , f ;
2004-05-25 17:57:39 +04:00
uint64_t start , len ;
2003-08-13 05:53:07 +04:00
char needed ;
2007-04-02 11:06:49 +04:00
uint16_t pid ;
2003-08-13 05:53:07 +04:00
} ;
# define PRESETS 0
# if PRESETS
static struct record preset [ ] = {
{ OP_LOCK , WRITE_LOCK , 0 , 0 , 2 , 0 , 1 } ,
{ OP_LOCK , WRITE_LOCK , 0 , 0 , 0 , 0 , 1 } ,
{ OP_LOCK , WRITE_LOCK , 0 , 0 , 3 , 0 , 1 } ,
{ OP_UNLOCK , 0 , 0 , 0 , 2 , 0 , 1 } ,
{ OP_REOPEN , 0 , 0 , 0 , 0 , 0 , 1 } ,
{ OP_LOCK , READ_LOCK , 0 , 0 , 2 , 0 , 1 } ,
{ OP_LOCK , READ_LOCK , 0 , 0 , 1 , 1 , 1 } ,
{ OP_LOCK , WRITE_LOCK , 0 , 0 , 0 , 0 , 1 } ,
{ OP_REOPEN , 0 , 0 , 0 , 0 , 0 , 1 } ,
{ OP_LOCK , READ_LOCK , 0 , 0 , 2 , 0 , 1 } ,
{ OP_LOCK , WRITE_LOCK , 0 , 0 , 3 , 1 , 1 } ,
{ OP_LOCK , WRITE_LOCK , 0 , 0 , 0 , 0 , 1 } ,
{ OP_REOPEN , 0 , 0 , 0 , 0 , 0 , 1 } ,
{ OP_LOCK , READ_LOCK , 0 , 0 , 2 , 0 , 1 } ,
{ OP_LOCK , WRITE_LOCK , 0 , 0 , 1 , 1 , 1 } ,
{ OP_LOCK , WRITE_LOCK , 0 , 0 , 0 , 0 , 1 } ,
{ OP_REOPEN , 0 , 0 , 0 , 0 , 0 , 1 } ,
{ OP_LOCK , WRITE_LOCK , 0 , 0 , 2 , 0 , 1 } ,
{ OP_LOCK , READ_LOCK , 0 , 0 , 1 , 1 , 1 } ,
{ OP_LOCK , WRITE_LOCK , 0 , 0 , 0 , 0 , 1 } ,
{ OP_REOPEN , 0 , 0 , 0 , 0 , 0 , 1 } ,
{ OP_LOCK , WRITE_LOCK , 0 , 0 , 2 , 0 , 1 } ,
{ OP_LOCK , READ_LOCK , 0 , 0 , 3 , 1 , 1 } ,
{ OP_LOCK , WRITE_LOCK , 0 , 0 , 0 , 0 , 1 } ,
{ OP_REOPEN , 0 , 0 , 0 , 0 , 0 , 1 } ,
} ;
# endif
static struct record * recorded ;
/*****************************************************
return a connection to a server
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2006-07-12 20:36:50 +04:00
static struct smbcli_state * connect_one ( char * share , int snum , int conn )
2003-08-13 05:53:07 +04:00
{
2004-08-04 17:23:35 +04:00
struct smbcli_state * c ;
2003-08-13 05:53:07 +04:00
fstring server , myname ;
NTSTATUS status ;
2004-06-02 12:33:29 +04:00
int retries = 10 ;
2003-08-13 05:53:07 +04:00
2006-07-12 20:36:50 +04:00
printf ( " connect_one(%s, %d, %d) \n " , share , snum , conn ) ;
2003-08-13 05:53:07 +04:00
fstrcpy ( server , share + 2 ) ;
share = strchr_m ( server , ' \\ ' ) ;
if ( ! share ) return NULL ;
* share = 0 ;
share + + ;
2006-07-12 20:36:50 +04:00
if ( snum = = 0 ) {
char * * unc_list = NULL ;
int num_unc_names ;
const char * p ;
p = lp_parm_string ( - 1 , " torture " , " unclist " ) ;
if ( p ) {
char * h , * s ;
unc_list = file_lines_load ( p , & num_unc_names , NULL ) ;
if ( ! unc_list | | num_unc_names < = 0 ) {
printf ( " Failed to load unc names list from '%s' \n " , p ) ;
exit ( 1 ) ;
}
if ( ! smbcli_parse_unc ( unc_list [ conn % num_unc_names ] ,
NULL , & h , & s ) ) {
printf ( " Failed to parse UNC name %s \n " ,
unc_list [ conn % num_unc_names ] ) ;
exit ( 1 ) ;
}
fstrcpy ( server , h ) ;
fstrcpy ( share , s ) ;
}
}
2003-08-13 05:53:07 +04:00
slprintf ( myname , sizeof ( myname ) , " lock-%u-%u " , getpid ( ) , snum ) ;
r6028: A MAJOR update to intergrate the new credentails system fully with
GENSEC, and to pull SCHANNEL into GENSEC, by making it less 'special'.
GENSEC now no longer has it's own handling of 'set username' etc,
instead it uses cli_credentials calls.
In order to link the credentails code right though Samba, a lot of
interfaces have changed to remove 'username, domain, password'
arguments, and these have been replaced with a single 'struct
cli_credentials'.
In the session setup code, a new parameter 'workgroup' contains the
client/server current workgroup, which seems unrelated to the
authentication exchange (it was being filled in from the auth info).
This allows in particular kerberos to only call back for passwords
when it actually needs to perform the kinit.
The kerberos code has been modified not to use the SPNEGO provided
'principal name' (in the mechListMIC), but to instead use the name the
host was connected to as. This better matches Microsoft behaviour,
is more secure and allows better use of standard kerberos functions.
To achieve this, I made changes to our socket code so that the
hostname (before name resolution) is now recorded on the socket.
In schannel, most of the code from librpc/rpc/dcerpc_schannel.c is now
in libcli/auth/schannel.c, and it looks much more like a standard
GENSEC module. The actual sign/seal code moved to
libcli/auth/schannel_sign.c in a previous commit.
The schannel credentails structure is now merged with the rest of the
credentails, as many of the values (username, workstation, domain)
where already present there. This makes handling this in a generic
manner much easier, as there is no longer a custom entry-point.
The auth_domain module continues to be developed, but is now just as
functional as auth_winbind. The changes here are consequential to the
schannel changes.
The only removed function at this point is the RPC-LOGIN test
(simulating the load of a WinXP login), which needs much more work to
clean it up (it contains copies of too much code from all over the
torture suite, and I havn't been able to penetrate its 'structure').
Andrew Bartlett
(This used to be commit 2301a4b38a21aa60917973451687063d83d18d66)
2005-03-24 07:14:06 +03:00
cli_credentials_set_workstation ( servers [ snum ] , myname , CRED_SPECIFIED ) ;
2003-08-13 05:53:07 +04:00
2004-06-02 12:33:29 +04:00
do {
2006-07-12 20:36:50 +04:00
printf ( " \\ \\ %s \\ %s \n " , server , share ) ;
r6028: A MAJOR update to intergrate the new credentails system fully with
GENSEC, and to pull SCHANNEL into GENSEC, by making it less 'special'.
GENSEC now no longer has it's own handling of 'set username' etc,
instead it uses cli_credentials calls.
In order to link the credentails code right though Samba, a lot of
interfaces have changed to remove 'username, domain, password'
arguments, and these have been replaced with a single 'struct
cli_credentials'.
In the session setup code, a new parameter 'workgroup' contains the
client/server current workgroup, which seems unrelated to the
authentication exchange (it was being filled in from the auth info).
This allows in particular kerberos to only call back for passwords
when it actually needs to perform the kinit.
The kerberos code has been modified not to use the SPNEGO provided
'principal name' (in the mechListMIC), but to instead use the name the
host was connected to as. This better matches Microsoft behaviour,
is more secure and allows better use of standard kerberos functions.
To achieve this, I made changes to our socket code so that the
hostname (before name resolution) is now recorded on the socket.
In schannel, most of the code from librpc/rpc/dcerpc_schannel.c is now
in libcli/auth/schannel.c, and it looks much more like a standard
GENSEC module. The actual sign/seal code moved to
libcli/auth/schannel_sign.c in a previous commit.
The schannel credentails structure is now merged with the rest of the
credentails, as many of the values (username, workstation, domain)
where already present there. This makes handling this in a generic
manner much easier, as there is no longer a custom entry-point.
The auth_domain module continues to be developed, but is now just as
functional as auth_winbind. The changes here are consequential to the
schannel changes.
The only removed function at this point is the RPC-LOGIN test
(simulating the load of a WinXP login), which needs much more work to
clean it up (it contains copies of too much code from all over the
torture suite, and I havn't been able to penetrate its 'structure').
Andrew Bartlett
(This used to be commit 2301a4b38a21aa60917973451687063d83d18d66)
2005-03-24 07:14:06 +03:00
status = smbcli_full_connection ( NULL , & c ,
2005-01-15 14:58:52 +03:00
server ,
share , NULL ,
2005-06-16 15:36:09 +04:00
servers [ snum ] , NULL ) ;
2004-06-02 12:33:29 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
sleep ( 2 ) ;
}
} while ( ! NT_STATUS_IS_OK ( status ) & & retries - - ) ;
2003-08-13 05:53:07 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
return NULL ;
}
return c ;
}
2004-08-04 17:23:35 +04:00
static void reconnect ( struct smbcli_state * cli [ NSERVERS ] [ NCONNECTIONS ] , int fnum [ NSERVERS ] [ NCONNECTIONS ] [ NFILES ] ,
2003-08-13 05:53:07 +04:00
char * share [ NSERVERS ] )
{
int server , conn , f ;
for ( server = 0 ; server < NSERVERS ; server + + )
for ( conn = 0 ; conn < NCONNECTIONS ; conn + + ) {
if ( cli [ server ] [ conn ] ) {
for ( f = 0 ; f < NFILES ; f + + ) {
if ( fnum [ server ] [ conn ] [ f ] ! = - 1 ) {
2004-08-04 17:23:35 +04:00
smbcli_close ( cli [ server ] [ conn ] - > tree , fnum [ server ] [ conn ] [ f ] ) ;
2003-08-13 05:53:07 +04:00
fnum [ server ] [ conn ] [ f ] = - 1 ;
}
}
2005-06-18 04:02:36 +04:00
talloc_free ( cli [ server ] [ conn ] ) ;
2003-08-13 05:53:07 +04:00
}
2006-07-12 20:36:50 +04:00
cli [ server ] [ conn ] = connect_one ( share [ server ] , server , conn ) ;
2003-08-13 05:53:07 +04:00
if ( ! cli [ server ] [ conn ] ) {
DEBUG ( 0 , ( " Failed to connect to %s \n " , share [ server ] ) ) ;
exit ( 1 ) ;
}
}
}
2004-08-04 17:23:35 +04:00
static BOOL test_one ( struct smbcli_state * cli [ NSERVERS ] [ NCONNECTIONS ] ,
2003-08-13 05:53:07 +04:00
int fnum [ NSERVERS ] [ NCONNECTIONS ] [ NFILES ] ,
struct record * rec )
{
2004-06-01 14:12:52 +04:00
uint_t conn = rec - > conn ;
uint_t f = rec - > f ;
2004-05-25 17:57:39 +04:00
uint64_t start = rec - > start ;
uint64_t len = rec - > len ;
2003-08-13 05:53:07 +04:00
enum brl_type op = rec - > lock_type ;
int server ;
BOOL ret [ NSERVERS ] ;
NTSTATUS status [ NSERVERS ] ;
switch ( rec - > lock_op ) {
case OP_LOCK :
/* set a lock */
for ( server = 0 ; server < NSERVERS ; server + + ) {
2007-04-02 11:06:49 +04:00
NTSTATUS res ;
struct smbcli_tree * tree = cli [ server ] [ conn ] - > tree ;
int fn = fnum [ server ] [ conn ] [ f ] ;
if ( ! ( tree - > session - > transport - > negotiate . capabilities & CAP_LARGE_FILES ) ) {
res = smbcli_lock ( tree , fn , start , len , LOCK_TIMEOUT , rec - > lock_op ) ;
} else {
union smb_lock parms ;
int ltype ;
struct smb_lock_entry lock [ 1 ] ;
parms . lockx . level = RAW_LOCK_LOCKX ;
parms . lockx . in . file . fnum = fn ;
ltype = ( rec - > lock_op = = READ_LOCK ? 1 : 0 ) ;
ltype | = LOCKING_ANDX_LARGE_FILES ;
parms . lockx . in . mode = ltype ;
parms . lockx . in . timeout = LOCK_TIMEOUT ;
parms . lockx . in . ulock_cnt = 0 ;
parms . lockx . in . lock_cnt = 1 ;
lock [ 0 ] . pid = rec - > pid ;
lock [ 0 ] . offset = start ;
lock [ 0 ] . count = len ;
parms . lockx . in . locks = & lock [ 0 ] ;
res = smb_raw_lock ( tree , & parms ) ;
}
ret [ server ] = NT_STATUS_IS_OK ( res ) ;
2004-08-04 17:23:35 +04:00
status [ server ] = smbcli_nt_error ( cli [ server ] [ conn ] - > tree ) ;
2003-08-13 05:53:07 +04:00
if ( ! exact_error_codes & &
NT_STATUS_EQUAL ( status [ server ] ,
NT_STATUS_FILE_LOCK_CONFLICT ) ) {
status [ server ] = NT_STATUS_LOCK_NOT_GRANTED ;
}
}
if ( showall | | ! NT_STATUS_EQUAL ( status [ 0 ] , status [ 1 ] ) ) {
printf ( " lock conn=%u f=%u range=%.0f(%.0f) op=%s -> %s:%s \n " ,
conn , f ,
( double ) start , ( double ) len ,
op = = READ_LOCK ? " READ_LOCK " : " WRITE_LOCK " ,
nt_errstr ( status [ 0 ] ) , nt_errstr ( status [ 1 ] ) ) ;
}
if ( ! NT_STATUS_EQUAL ( status [ 0 ] , status [ 1 ] ) ) return False ;
break ;
case OP_UNLOCK :
/* unset a lock */
for ( server = 0 ; server < NSERVERS ; server + + ) {
2007-04-02 11:06:49 +04:00
NTSTATUS res ;
struct smbcli_tree * tree = cli [ server ] [ conn ] - > tree ;
int fn = fnum [ server ] [ conn ] [ f ] ;
if ( ! ( tree - > session - > transport - > negotiate . capabilities & CAP_LARGE_FILES ) ) {
res = smbcli_unlock ( tree , fn , start , len ) ;
} else {
union smb_lock parms ;
struct smb_lock_entry lock [ 1 ] ;
parms . lockx . level = RAW_LOCK_LOCKX ;
parms . lockx . in . file . fnum = fn ;
parms . lockx . in . mode = LOCKING_ANDX_LARGE_FILES ;
parms . lockx . in . timeout = 0 ;
parms . lockx . in . ulock_cnt = 1 ;
parms . lockx . in . lock_cnt = 0 ;
lock [ 0 ] . pid = rec - > pid ;
lock [ 0 ] . count = len ;
lock [ 0 ] . offset = start ;
parms . lockx . in . locks = & lock [ 0 ] ;
res = smb_raw_lock ( tree , & parms ) ;
}
ret [ server ] = NT_STATUS_IS_OK ( res ) ;
2004-08-04 17:23:35 +04:00
status [ server ] = smbcli_nt_error ( cli [ server ] [ conn ] - > tree ) ;
2003-08-13 05:53:07 +04:00
}
if ( showall | |
( ! hide_unlock_fails & & ! NT_STATUS_EQUAL ( status [ 0 ] , status [ 1 ] ) ) ) {
printf ( " unlock conn=%u f=%u range=%.0f(%.0f) -> %s:%s \n " ,
conn , f ,
( double ) start , ( double ) len ,
nt_errstr ( status [ 0 ] ) , nt_errstr ( status [ 1 ] ) ) ;
}
if ( ! hide_unlock_fails & & ! NT_STATUS_EQUAL ( status [ 0 ] , status [ 1 ] ) )
return False ;
break ;
case OP_REOPEN :
/* reopen the file */
for ( server = 0 ; server < NSERVERS ; server + + ) {
2004-08-04 17:23:35 +04:00
smbcli_close ( cli [ server ] [ conn ] - > tree , fnum [ server ] [ conn ] [ f ] ) ;
2003-08-13 05:53:07 +04:00
fnum [ server ] [ conn ] [ f ] = - 1 ;
}
for ( server = 0 ; server < NSERVERS ; server + + ) {
2004-08-04 17:23:35 +04:00
fnum [ server ] [ conn ] [ f ] = smbcli_open ( cli [ server ] [ conn ] - > tree , FILENAME ,
2003-08-13 05:53:07 +04:00
O_RDWR | O_CREAT ,
DENY_NONE ) ;
if ( fnum [ server ] [ conn ] [ f ] = = - 1 ) {
printf ( " failed to reopen on share%d \n " , server ) ;
return False ;
}
}
if ( showall ) {
printf ( " reopen conn=%u f=%u \n " ,
conn , f ) ;
}
break ;
}
return True ;
}
2004-08-04 17:23:35 +04:00
static void close_files ( struct smbcli_state * cli [ NSERVERS ] [ NCONNECTIONS ] ,
2003-08-13 05:53:07 +04:00
int fnum [ NSERVERS ] [ NCONNECTIONS ] [ NFILES ] )
{
int server , conn , f ;
for ( server = 0 ; server < NSERVERS ; server + + )
for ( conn = 0 ; conn < NCONNECTIONS ; conn + + )
for ( f = 0 ; f < NFILES ; f + + ) {
if ( fnum [ server ] [ conn ] [ f ] ! = - 1 ) {
2004-08-04 17:23:35 +04:00
smbcli_close ( cli [ server ] [ conn ] - > tree , fnum [ server ] [ conn ] [ f ] ) ;
2003-08-13 05:53:07 +04:00
fnum [ server ] [ conn ] [ f ] = - 1 ;
}
}
for ( server = 0 ; server < NSERVERS ; server + + ) {
2004-08-04 17:23:35 +04:00
smbcli_unlink ( cli [ server ] [ 0 ] - > tree , FILENAME ) ;
2003-08-13 05:53:07 +04:00
}
}
2004-08-04 17:23:35 +04:00
static void open_files ( struct smbcli_state * cli [ NSERVERS ] [ NCONNECTIONS ] ,
2003-08-13 05:53:07 +04:00
int fnum [ NSERVERS ] [ NCONNECTIONS ] [ NFILES ] )
{
int server , conn , f ;
for ( server = 0 ; server < NSERVERS ; server + + )
for ( conn = 0 ; conn < NCONNECTIONS ; conn + + )
for ( f = 0 ; f < NFILES ; f + + ) {
2004-08-04 17:23:35 +04:00
fnum [ server ] [ conn ] [ f ] = smbcli_open ( cli [ server ] [ conn ] - > tree , FILENAME ,
2003-08-13 05:53:07 +04:00
O_RDWR | O_CREAT ,
DENY_NONE ) ;
if ( fnum [ server ] [ conn ] [ f ] = = - 1 ) {
fprintf ( stderr , " Failed to open fnum[%u][%u][%u] \n " ,
server , conn , f ) ;
exit ( 1 ) ;
}
}
}
2004-08-04 17:23:35 +04:00
static int retest ( struct smbcli_state * cli [ NSERVERS ] [ NCONNECTIONS ] ,
2003-08-13 05:53:07 +04:00
int fnum [ NSERVERS ] [ NCONNECTIONS ] [ NFILES ] ,
int n )
{
int i ;
printf ( " testing %u ... \n " , n ) ;
for ( i = 0 ; i < n ; i + + ) {
if ( i & & i % 100 = = 0 ) {
printf ( " %u \n " , i ) ;
}
if ( recorded [ i ] . needed & &
! test_one ( cli , fnum , & recorded [ i ] ) ) return i ;
}
return n ;
}
/* each server has two connections open to it. Each connection has two file
descriptors open on the file - 8 file descriptors in total
we then do random locking ops in tamdem on the 4 fnums from each
server and ensure that the results match
*/
static void test_locks ( char * share [ NSERVERS ] )
{
2004-08-04 17:23:35 +04:00
struct smbcli_state * cli [ NSERVERS ] [ NCONNECTIONS ] ;
2003-08-13 05:53:07 +04:00
int fnum [ NSERVERS ] [ NCONNECTIONS ] [ NFILES ] ;
int n , i , n1 , skip , r1 , r2 ;
ZERO_STRUCT ( fnum ) ;
ZERO_STRUCT ( cli ) ;
2004-12-03 09:24:38 +03:00
recorded = malloc_array_p ( struct record , numops ) ;
2003-08-13 05:53:07 +04:00
for ( n = 0 ; n < numops ; n + + ) {
# if PRESETS
if ( n < sizeof ( preset ) / sizeof ( preset [ 0 ] ) ) {
recorded [ n ] = preset [ n ] ;
} else {
# endif
recorded [ n ] . conn = random ( ) % NCONNECTIONS ;
recorded [ n ] . f = random ( ) % NFILES ;
2004-06-01 14:12:52 +04:00
recorded [ n ] . start = lock_base + ( ( uint_t ) random ( ) % ( lock_range - 1 ) ) ;
2003-08-13 05:53:07 +04:00
recorded [ n ] . len = min_length +
random ( ) % ( lock_range - ( recorded [ n ] . start - lock_base ) ) ;
recorded [ n ] . start * = RANGE_MULTIPLE ;
recorded [ n ] . len * = RANGE_MULTIPLE ;
2007-04-02 11:06:49 +04:00
recorded [ n ] . pid = random ( ) % 3 ;
if ( recorded [ n ] . pid = = 2 ) {
recorded [ n ] . pid = 0xFFFF ; /* see if its magic */
}
2003-08-13 05:53:07 +04:00
r1 = random ( ) % 100 ;
r2 = random ( ) % 100 ;
if ( r1 < READ_PCT ) {
recorded [ n ] . lock_type = READ_LOCK ;
} else {
recorded [ n ] . lock_type = WRITE_LOCK ;
}
if ( r2 < LOCK_PCT ) {
recorded [ n ] . lock_op = OP_LOCK ;
} else if ( r2 < UNLOCK_PCT ) {
recorded [ n ] . lock_op = OP_UNLOCK ;
} else {
recorded [ n ] . lock_op = OP_REOPEN ;
}
recorded [ n ] . needed = True ;
if ( ! zero_zero & & recorded [ n ] . start = = 0 & & recorded [ n ] . len = = 0 ) {
recorded [ n ] . len = 1 ;
}
# if PRESETS
}
# endif
}
reconnect ( cli , fnum , share ) ;
open_files ( cli , fnum ) ;
n = retest ( cli , fnum , numops ) ;
if ( n = = numops | | ! analyze ) return ;
n + + ;
skip = n / 2 ;
while ( 1 ) {
n1 = n ;
close_files ( cli , fnum ) ;
reconnect ( cli , fnum , share ) ;
open_files ( cli , fnum ) ;
for ( i = 0 ; i < n - skip ; i + = skip ) {
int m , j ;
printf ( " excluding %d-%d \n " , i , i + skip - 1 ) ;
for ( j = i ; j < i + skip ; j + + ) {
recorded [ j ] . needed = False ;
}
close_files ( cli , fnum ) ;
open_files ( cli , fnum ) ;
m = retest ( cli , fnum , n ) ;
if ( m = = n ) {
for ( j = i ; j < i + skip ; j + + ) {
recorded [ j ] . needed = True ;
}
} else {
if ( i + ( skip - 1 ) < m ) {
memmove ( & recorded [ i ] , & recorded [ i + skip ] ,
( m - ( i + skip - 1 ) ) * sizeof ( recorded [ 0 ] ) ) ;
}
n = m - ( skip - 1 ) ;
i - - ;
}
}
if ( skip > 1 ) {
skip = skip / 2 ;
printf ( " skip=%d \n " , skip ) ;
continue ;
}
if ( n1 = = n ) break ;
}
close_files ( cli , fnum ) ;
reconnect ( cli , fnum , share ) ;
open_files ( cli , fnum ) ;
showall = True ;
n1 = retest ( cli , fnum , n ) ;
if ( n1 ! = n - 1 ) {
printf ( " ERROR - inconsistent result (%u %u) \n " , n1 , n ) ;
}
close_files ( cli , fnum ) ;
for ( i = 0 ; i < n ; i + + ) {
printf ( " {%d, %d, %u, %u, %.0f, %.0f, %u}, \n " ,
recorded [ i ] . lock_op ,
recorded [ i ] . lock_type ,
recorded [ i ] . conn ,
recorded [ i ] . f ,
( double ) recorded [ i ] . start ,
( double ) recorded [ i ] . len ,
recorded [ i ] . needed ) ;
}
}
static void usage ( void )
{
printf (
" Usage: \n \
locktest / / server1 / share1 / / server2 / share2 [ options . . ] \ n \
options : \ n \
- U user % % pass ( may be specified twice ) \ n \
- s seed \ n \
- o numops \ n \
- u hide unlock fails \ n \
- a ( show all ops ) \ n \
- A analyse for minimal ops \ n \
- O use oplocks \ n \
- E enable exact error code checking \ n \
- Z enable the zero / zero lock \ n \
- R range set lock range \ n \
- B base set lock base \ n \
- M min set min lock length \ n \
2006-07-12 20:36:50 +04:00
- l filename unclist file \ n \
2003-08-13 05:53:07 +04:00
" );
}
/****************************************************************************
main program
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int main ( int argc , char * argv [ ] )
{
char * share [ NSERVERS ] ;
int opt ;
2005-04-30 13:47:32 +04:00
int seed , server ;
int username_count = 0 ;
2003-08-13 05:53:07 +04:00
setlinebuf ( stdout ) ;
setup_logging ( " locktest " , DEBUG_STDOUT ) ;
if ( argc < 3 | | argv [ 1 ] [ 0 ] = = ' - ' ) {
usage ( ) ;
exit ( 1 ) ;
}
2003-08-15 22:33:43 +04:00
setup_logging ( argv [ 0 ] , DEBUG_STDOUT ) ;
2003-08-13 05:53:07 +04:00
for ( server = 0 ; server < NSERVERS ; server + + ) {
share [ server ] = argv [ 1 + server ] ;
all_string_sub ( share [ server ] , " / " , " \\ " , 0 ) ;
}
argc - = NSERVERS ;
argv + = NSERVERS ;
2005-07-20 14:07:48 +04:00
lp_load ( ) ;
2003-08-13 05:53:07 +04:00
2005-03-22 22:30:59 +03:00
servers [ 0 ] = cli_credentials_init ( talloc_autofree_context ( ) ) ;
servers [ 1 ] = cli_credentials_init ( talloc_autofree_context ( ) ) ;
2005-04-30 13:47:32 +04:00
cli_credentials_guess ( servers [ 0 ] ) ;
cli_credentials_guess ( servers [ 1 ] ) ;
2005-03-22 22:30:59 +03:00
2003-08-13 05:53:07 +04:00
seed = time ( NULL ) ;
2006-07-12 20:36:50 +04:00
while ( ( opt = getopt ( argc , argv , " U:s:ho:aAW:OR:B:M:EZW:l: " ) ) ! = EOF ) {
2003-08-13 05:53:07 +04:00
switch ( opt ) {
case ' U ' :
2005-04-30 13:47:32 +04:00
if ( username_count = = 2 ) {
usage ( ) ;
exit ( 1 ) ;
}
cli_credentials_parse_string ( servers [ username_count ] ,
optarg , CRED_SPECIFIED ) ;
username_count + + ;
2003-08-13 05:53:07 +04:00
break ;
case ' R ' :
lock_range = strtol ( optarg , NULL , 0 ) ;
break ;
case ' B ' :
lock_base = strtol ( optarg , NULL , 0 ) ;
break ;
case ' M ' :
min_length = strtol ( optarg , NULL , 0 ) ;
break ;
case ' s ' :
seed = atoi ( optarg ) ;
break ;
case ' u ' :
hide_unlock_fails = True ;
break ;
case ' o ' :
numops = atoi ( optarg ) ;
break ;
case ' O ' :
use_oplocks = True ;
break ;
case ' a ' :
showall = True ;
break ;
case ' A ' :
analyze = True ;
break ;
case ' Z ' :
zero_zero = True ;
break ;
case ' E ' :
exact_error_codes = True ;
break ;
2006-07-12 20:36:50 +04:00
case ' l ' :
lp_set_cmdline ( " torture:unclist " , optarg ) ;
break ;
2004-06-02 12:33:29 +04:00
case ' W ' :
lp_set_cmdline ( " workgroup " , optarg ) ;
break ;
2003-08-13 05:53:07 +04:00
case ' h ' :
usage ( ) ;
exit ( 1 ) ;
default :
printf ( " Unknown option %c (%d) \n " , ( char ) opt , opt ) ;
exit ( 1 ) ;
}
}
2005-04-30 13:47:32 +04:00
if ( username_count = = 0 ) {
2004-08-10 00:51:16 +04:00
usage ( ) ;
return - 1 ;
}
2005-04-30 13:47:32 +04:00
if ( username_count = = 1 ) {
servers [ 1 ] = servers [ 0 ] ;
2004-08-10 00:51:16 +04:00
}
2003-08-13 05:53:07 +04:00
2005-12-31 01:46:16 +03:00
gensec_init ( ) ;
2004-11-09 12:26:47 +03:00
2003-08-13 05:53:07 +04:00
argc - = optind ;
argv + = optind ;
DEBUG ( 0 , ( " seed=%u base=%d range=%d min_length=%d \n " ,
seed , lock_base , lock_range , min_length ) ) ;
srandom ( seed ) ;
test_locks ( share ) ;
return ( 0 ) ;
}
2005-04-30 13:47:32 +04:00