2003-08-13 05:53:07 +04:00
/*
Unix SMB / CIFS implementation .
test suite for various read operations
Copyright ( C ) Andrew Tridgell 2003
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
the Free Software Foundation ; either version 2 of the License , or
( 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
along with this program ; if not , write to the Free Software
Foundation , Inc . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
*/
# include "includes.h"
2004-11-01 04:03:22 +03:00
# include "libcli/raw/libcliraw.h"
2004-11-02 03:24:21 +03:00
# include "system/time.h"
2003-08-13 05:53:07 +04:00
# define CHECK_STATUS(status, correct) do { \
if ( ! NT_STATUS_EQUAL ( status , correct ) ) { \
2004-10-26 09:32:57 +04:00
printf ( " (%s) Incorrect status %s - should be %s \n " , \
__location__ , nt_errstr ( status ) , nt_errstr ( correct ) ) ; \
2003-08-13 05:53:07 +04:00
ret = False ; \
goto done ; \
} } while ( 0 )
# define CHECK_VALUE(v, correct) do { \
if ( ( v ) ! = ( correct ) ) { \
2004-10-26 09:32:57 +04:00
printf ( " (%s) Incorrect value %s=%d - should be %d \n " , \
__location__ , # v , v , correct ) ; \
2003-08-13 05:53:07 +04:00
ret = False ; \
goto done ; \
} } while ( 0 )
# define CHECK_BUFFER(buf, seed, len) do { \
if ( ! check_buffer ( buf , seed , len , __LINE__ ) ) { \
ret = False ; \
goto done ; \
} } while ( 0 )
# define BASEDIR "\\testread"
/*
setup a random buffer based on a seed
*/
2004-12-04 16:56:25 +03:00
static void setup_buffer ( uint8_t * buf , uint_t seed , int len )
2003-08-13 05:53:07 +04:00
{
int i ;
srandom ( seed ) ;
for ( i = 0 ; i < len ; i + + ) buf [ i ] = random ( ) ;
}
/*
check a random buffer based on a seed
*/
2004-12-04 16:56:25 +03:00
static BOOL check_buffer ( uint8_t * buf , uint_t seed , int len , int line )
2003-08-13 05:53:07 +04:00
{
int i ;
srandom ( seed ) ;
for ( i = 0 ; i < len ; i + + ) {
2004-12-04 16:56:25 +03:00
uint8_t v = random ( ) ;
2003-08-13 05:53:07 +04:00
if ( buf [ i ] ! = v ) {
printf ( " Buffer incorrect at line %d! ofs=%d v1=0x%x v2=0x%x \n " ,
line , i , buf [ i ] , v ) ;
return False ;
}
}
return True ;
}
/*
test read ops
*/
2004-08-04 17:23:35 +04:00
static BOOL test_read ( struct smbcli_state * cli , TALLOC_CTX * mem_ctx )
2003-08-13 05:53:07 +04:00
{
union smb_read io ;
NTSTATUS status ;
BOOL ret = True ;
int fnum ;
2004-12-04 16:56:25 +03:00
uint8_t * buf ;
2003-08-13 05:53:07 +04:00
const int maxsize = 90000 ;
const char * fname = BASEDIR " \\ test.txt " ;
const char * test_data = " TEST DATA " ;
2004-06-01 14:12:52 +04:00
uint_t seed = time ( NULL ) ;
2003-08-13 05:53:07 +04:00
2005-01-07 07:39:16 +03:00
buf = talloc_zero_size ( mem_ctx , maxsize ) ;
2003-08-13 05:53:07 +04:00
2004-11-12 12:37:59 +03:00
if ( ! torture_setup_dir ( cli , BASEDIR ) ) {
2003-08-13 05:53:07 +04:00
return False ;
}
printf ( " Testing RAW_READ_READ \n " ) ;
io . generic . level = RAW_READ_READ ;
2004-08-04 17:23:35 +04:00
fnum = smbcli_open ( cli - > tree , fname , O_RDWR | O_CREAT , DENY_NONE ) ;
2003-08-13 05:53:07 +04:00
if ( fnum = = - 1 ) {
2004-08-04 17:23:35 +04:00
printf ( " Failed to create %s - %s \n " , fname , smbcli_errstr ( cli - > tree ) ) ;
2003-08-13 05:53:07 +04:00
ret = False ;
goto done ;
}
printf ( " Trying empty file read \n " ) ;
io . read . in . fnum = fnum ;
io . read . in . count = 1 ;
io . read . in . offset = 0 ;
io . read . in . remaining = 0 ;
io . read . out . data = buf ;
status = smb_raw_read ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_VALUE ( io . read . out . nread , 0 ) ;
printf ( " Trying zero file read \n " ) ;
io . read . in . count = 0 ;
status = smb_raw_read ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_VALUE ( io . read . out . nread , 0 ) ;
printf ( " Trying bad fnum \n " ) ;
io . read . in . fnum = fnum + 1 ;
status = smb_raw_read ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_INVALID_HANDLE ) ;
io . read . in . fnum = fnum ;
2004-08-04 17:23:35 +04:00
smbcli_write ( cli - > tree , fnum , 0 , test_data , 0 , strlen ( test_data ) ) ;
2003-08-13 05:53:07 +04:00
printf ( " Trying small read \n " ) ;
io . read . in . fnum = fnum ;
io . read . in . offset = 0 ;
io . read . in . remaining = 0 ;
io . read . in . count = strlen ( test_data ) ;
status = smb_raw_read ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_VALUE ( io . read . out . nread , strlen ( test_data ) ) ;
if ( memcmp ( buf , test_data , strlen ( test_data ) ) ! = 0 ) {
ret = False ;
printf ( " incorrect data at %d!? (%s:%s) \n " , __LINE__ , test_data , buf ) ;
goto done ;
}
printf ( " Trying short read \n " ) ;
io . read . in . offset = 1 ;
io . read . in . count = strlen ( test_data ) ;
status = smb_raw_read ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_VALUE ( io . read . out . nread , strlen ( test_data ) - 1 ) ;
if ( memcmp ( buf , test_data + 1 , strlen ( test_data ) - 1 ) ! = 0 ) {
ret = False ;
printf ( " incorrect data at %d!? (%s:%s) \n " , __LINE__ , test_data + 1 , buf ) ;
goto done ;
}
printf ( " Trying max offset \n " ) ;
io . read . in . offset = ~ 0 ;
io . read . in . count = strlen ( test_data ) ;
status = smb_raw_read ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_VALUE ( io . read . out . nread , 0 ) ;
setup_buffer ( buf , seed , maxsize ) ;
2004-08-04 17:23:35 +04:00
smbcli_write ( cli - > tree , fnum , 0 , buf , 0 , maxsize ) ;
2003-08-13 05:53:07 +04:00
memset ( buf , 0 , maxsize ) ;
printf ( " Trying large read \n " ) ;
io . read . in . offset = 0 ;
io . read . in . count = ~ 0 ;
status = smb_raw_read ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_BUFFER ( buf , seed , io . read . out . nread ) ;
printf ( " Trying locked region \n " ) ;
cli - > session - > pid + + ;
2004-08-04 17:23:35 +04:00
if ( NT_STATUS_IS_ERR ( smbcli_lock ( cli - > tree , fnum , 103 , 1 , 0 , WRITE_LOCK ) ) ) {
2003-08-13 05:53:07 +04:00
printf ( " Failed to lock file at %d \n " , __LINE__ ) ;
ret = False ;
goto done ;
}
cli - > session - > pid - - ;
memset ( buf , 0 , maxsize ) ;
io . read . in . offset = 0 ;
io . read . in . count = ~ 0 ;
status = smb_raw_read ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_FILE_LOCK_CONFLICT ) ;
done :
2004-08-04 17:23:35 +04:00
smbcli_close ( cli - > tree , fnum ) ;
2003-08-13 05:53:07 +04:00
smb_raw_exit ( cli - > session ) ;
2004-08-04 17:23:35 +04:00
smbcli_deltree ( cli - > tree , BASEDIR ) ;
2003-08-13 05:53:07 +04:00
return ret ;
}
/*
test lockread ops
*/
2004-08-04 17:23:35 +04:00
static BOOL test_lockread ( struct smbcli_state * cli , TALLOC_CTX * mem_ctx )
2003-08-13 05:53:07 +04:00
{
union smb_read io ;
NTSTATUS status ;
BOOL ret = True ;
int fnum ;
2004-12-04 16:56:25 +03:00
uint8_t * buf ;
2003-08-13 05:53:07 +04:00
const int maxsize = 90000 ;
const char * fname = BASEDIR " \\ test.txt " ;
const char * test_data = " TEST DATA " ;
2004-06-01 14:12:52 +04:00
uint_t seed = time ( NULL ) ;
2003-08-13 05:53:07 +04:00
2005-01-07 07:39:16 +03:00
buf = talloc_zero_size ( mem_ctx , maxsize ) ;
2003-08-13 05:53:07 +04:00
2004-11-12 12:37:59 +03:00
if ( ! torture_setup_dir ( cli , BASEDIR ) ) {
2003-08-13 05:53:07 +04:00
return False ;
}
printf ( " Testing RAW_READ_LOCKREAD \n " ) ;
io . generic . level = RAW_READ_LOCKREAD ;
2004-08-04 17:23:35 +04:00
fnum = smbcli_open ( cli - > tree , fname , O_RDWR | O_CREAT , DENY_NONE ) ;
2003-08-13 05:53:07 +04:00
if ( fnum = = - 1 ) {
2004-08-04 17:23:35 +04:00
printf ( " Failed to create %s - %s \n " , fname , smbcli_errstr ( cli - > tree ) ) ;
2003-08-13 05:53:07 +04:00
ret = False ;
goto done ;
}
printf ( " Trying empty file read \n " ) ;
io . lockread . in . fnum = fnum ;
io . lockread . in . count = 1 ;
2004-10-26 10:18:56 +04:00
io . lockread . in . offset = 1 ;
2003-08-13 05:53:07 +04:00
io . lockread . in . remaining = 0 ;
io . lockread . out . data = buf ;
status = smb_raw_read ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_VALUE ( io . lockread . out . nread , 0 ) ;
2003-08-29 08:35:35 +04:00
status = smb_raw_read ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_LOCK_NOT_GRANTED ) ;
status = smb_raw_read ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_FILE_LOCK_CONFLICT ) ;
2003-08-13 05:53:07 +04:00
printf ( " Trying zero file read \n " ) ;
io . lockread . in . count = 0 ;
status = smb_raw_read ( cli - > tree , & io ) ;
2004-10-26 10:18:56 +04:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
smbcli_unlock ( cli - > tree , fnum , 1 , 1 ) ;
2003-08-13 05:53:07 +04:00
printf ( " Trying bad fnum \n " ) ;
io . lockread . in . fnum = fnum + 1 ;
status = smb_raw_read ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_INVALID_HANDLE ) ;
io . lockread . in . fnum = fnum ;
2004-08-04 17:23:35 +04:00
smbcli_write ( cli - > tree , fnum , 0 , test_data , 0 , strlen ( test_data ) ) ;
2003-08-13 05:53:07 +04:00
printf ( " Trying small read \n " ) ;
io . lockread . in . fnum = fnum ;
io . lockread . in . offset = 0 ;
io . lockread . in . remaining = 0 ;
io . lockread . in . count = strlen ( test_data ) ;
status = smb_raw_read ( cli - > tree , & io ) ;
2004-10-26 10:18:56 +04:00
CHECK_STATUS ( status , NT_STATUS_LOCK_NOT_GRANTED ) ;
2003-08-13 05:53:07 +04:00
2004-10-26 10:18:56 +04:00
smbcli_unlock ( cli - > tree , fnum , 1 , 0 ) ;
2003-08-13 05:53:07 +04:00
status = smb_raw_read ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_VALUE ( io . lockread . out . nread , strlen ( test_data ) ) ;
if ( memcmp ( buf , test_data , strlen ( test_data ) ) ! = 0 ) {
ret = False ;
printf ( " incorrect data at %d!? (%s:%s) \n " , __LINE__ , test_data , buf ) ;
goto done ;
}
printf ( " Trying short read \n " ) ;
io . lockread . in . offset = 1 ;
io . lockread . in . count = strlen ( test_data ) ;
status = smb_raw_read ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_LOCK_NOT_GRANTED ) ;
2004-08-04 17:23:35 +04:00
smbcli_unlock ( cli - > tree , fnum , 0 , strlen ( test_data ) ) ;
2003-08-13 05:53:07 +04:00
status = smb_raw_read ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_VALUE ( io . lockread . out . nread , strlen ( test_data ) - 1 ) ;
if ( memcmp ( buf , test_data + 1 , strlen ( test_data ) - 1 ) ! = 0 ) {
ret = False ;
printf ( " incorrect data at %d!? (%s:%s) \n " , __LINE__ , test_data + 1 , buf ) ;
goto done ;
}
printf ( " Trying max offset \n " ) ;
io . lockread . in . offset = ~ 0 ;
io . lockread . in . count = strlen ( test_data ) ;
status = smb_raw_read ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_VALUE ( io . lockread . out . nread , 0 ) ;
setup_buffer ( buf , seed , maxsize ) ;
2004-08-04 17:23:35 +04:00
smbcli_write ( cli - > tree , fnum , 0 , buf , 0 , maxsize ) ;
2003-08-13 05:53:07 +04:00
memset ( buf , 0 , maxsize ) ;
printf ( " Trying large read \n " ) ;
io . lockread . in . offset = 0 ;
io . lockread . in . count = ~ 0 ;
status = smb_raw_read ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_LOCK_NOT_GRANTED ) ;
2004-08-04 17:23:35 +04:00
smbcli_unlock ( cli - > tree , fnum , 1 , strlen ( test_data ) ) ;
2003-08-13 05:53:07 +04:00
status = smb_raw_read ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_BUFFER ( buf , seed , io . lockread . out . nread ) ;
2004-08-04 17:23:35 +04:00
smbcli_unlock ( cli - > tree , fnum , 0 , 0xFFFF ) ;
2003-08-13 05:53:07 +04:00
printf ( " Trying locked region \n " ) ;
cli - > session - > pid + + ;
2004-08-04 17:23:35 +04:00
if ( NT_STATUS_IS_ERR ( smbcli_lock ( cli - > tree , fnum , 103 , 1 , 0 , WRITE_LOCK ) ) ) {
2003-08-13 05:53:07 +04:00
printf ( " Failed to lock file at %d \n " , __LINE__ ) ;
ret = False ;
goto done ;
}
cli - > session - > pid - - ;
memset ( buf , 0 , maxsize ) ;
io . lockread . in . offset = 0 ;
io . lockread . in . count = ~ 0 ;
status = smb_raw_read ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_FILE_LOCK_CONFLICT ) ;
done :
2004-08-04 17:23:35 +04:00
smbcli_close ( cli - > tree , fnum ) ;
smbcli_deltree ( cli - > tree , BASEDIR ) ;
2003-08-13 05:53:07 +04:00
return ret ;
}
/*
test readx ops
*/
2004-08-04 17:23:35 +04:00
static BOOL test_readx ( struct smbcli_state * cli , TALLOC_CTX * mem_ctx )
2003-08-13 05:53:07 +04:00
{
union smb_read io ;
NTSTATUS status ;
BOOL ret = True ;
int fnum ;
2004-12-04 16:56:25 +03:00
uint8_t * buf ;
2003-08-13 05:53:07 +04:00
const int maxsize = 90000 ;
const char * fname = BASEDIR " \\ test.txt " ;
const char * test_data = " TEST DATA " ;
2004-06-01 14:12:52 +04:00
uint_t seed = time ( NULL ) ;
2003-08-13 05:53:07 +04:00
2005-01-07 07:39:16 +03:00
buf = talloc_zero_size ( mem_ctx , maxsize ) ;
2003-08-13 05:53:07 +04:00
2004-11-12 12:37:59 +03:00
if ( ! torture_setup_dir ( cli , BASEDIR ) ) {
2003-08-13 05:53:07 +04:00
return False ;
}
printf ( " Testing RAW_READ_READX \n " ) ;
2004-08-04 17:23:35 +04:00
fnum = smbcli_open ( cli - > tree , fname , O_RDWR | O_CREAT , DENY_NONE ) ;
2003-08-13 05:53:07 +04:00
if ( fnum = = - 1 ) {
2004-08-04 17:23:35 +04:00
printf ( " Failed to create %s - %s \n " , fname , smbcli_errstr ( cli - > tree ) ) ;
2003-08-13 05:53:07 +04:00
ret = False ;
goto done ;
}
printf ( " Trying empty file read \n " ) ;
io . generic . level = RAW_READ_READX ;
io . readx . in . fnum = fnum ;
io . readx . in . mincnt = 1 ;
io . readx . in . maxcnt = 1 ;
io . readx . in . offset = 0 ;
io . readx . in . remaining = 0 ;
io . readx . out . data = buf ;
status = smb_raw_read ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_VALUE ( io . readx . out . nread , 0 ) ;
CHECK_VALUE ( io . readx . out . remaining , 0xFFFF ) ;
CHECK_VALUE ( io . readx . out . compaction_mode , 0 ) ;
printf ( " Trying zero file read \n " ) ;
io . readx . in . mincnt = 0 ;
io . readx . in . maxcnt = 0 ;
status = smb_raw_read ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_VALUE ( io . readx . out . nread , 0 ) ;
CHECK_VALUE ( io . readx . out . remaining , 0xFFFF ) ;
CHECK_VALUE ( io . readx . out . compaction_mode , 0 ) ;
printf ( " Trying bad fnum \n " ) ;
io . readx . in . fnum = fnum + 1 ;
status = smb_raw_read ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_INVALID_HANDLE ) ;
io . readx . in . fnum = fnum ;
2004-08-04 17:23:35 +04:00
smbcli_write ( cli - > tree , fnum , 0 , test_data , 0 , strlen ( test_data ) ) ;
2003-08-13 05:53:07 +04:00
printf ( " Trying small read \n " ) ;
io . readx . in . fnum = fnum ;
io . readx . in . offset = 0 ;
io . readx . in . remaining = 0 ;
io . readx . in . mincnt = strlen ( test_data ) ;
io . readx . in . maxcnt = strlen ( test_data ) ;
status = smb_raw_read ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_VALUE ( io . readx . out . nread , strlen ( test_data ) ) ;
CHECK_VALUE ( io . readx . out . remaining , 0xFFFF ) ;
CHECK_VALUE ( io . readx . out . compaction_mode , 0 ) ;
if ( memcmp ( buf , test_data , strlen ( test_data ) ) ! = 0 ) {
ret = False ;
printf ( " incorrect data at %d!? (%s:%s) \n " , __LINE__ , test_data , buf ) ;
goto done ;
}
printf ( " Trying short read \n " ) ;
io . readx . in . offset = 1 ;
io . readx . in . mincnt = strlen ( test_data ) ;
io . readx . in . maxcnt = strlen ( test_data ) ;
status = smb_raw_read ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_VALUE ( io . readx . out . nread , strlen ( test_data ) - 1 ) ;
CHECK_VALUE ( io . readx . out . remaining , 0xFFFF ) ;
CHECK_VALUE ( io . readx . out . compaction_mode , 0 ) ;
if ( memcmp ( buf , test_data + 1 , strlen ( test_data ) - 1 ) ! = 0 ) {
ret = False ;
printf ( " incorrect data at %d!? (%s:%s) \n " , __LINE__ , test_data + 1 , buf ) ;
goto done ;
}
printf ( " Trying max offset \n " ) ;
io . readx . in . offset = 0xffffffff ;
io . readx . in . mincnt = strlen ( test_data ) ;
io . readx . in . maxcnt = strlen ( test_data ) ;
status = smb_raw_read ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_VALUE ( io . readx . out . nread , 0 ) ;
CHECK_VALUE ( io . readx . out . remaining , 0xFFFF ) ;
CHECK_VALUE ( io . readx . out . compaction_mode , 0 ) ;
setup_buffer ( buf , seed , maxsize ) ;
2004-08-04 17:23:35 +04:00
smbcli_write ( cli - > tree , fnum , 0 , buf , 0 , maxsize ) ;
2003-08-13 05:53:07 +04:00
memset ( buf , 0 , maxsize ) ;
printf ( " Trying large read \n " ) ;
io . readx . in . offset = 0 ;
2004-10-26 09:32:57 +04:00
io . readx . in . mincnt = 0xFFFF ;
io . readx . in . maxcnt = 0xFFFF ;
2003-08-13 05:53:07 +04:00
status = smb_raw_read ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_VALUE ( io . readx . out . remaining , 0xFFFF ) ;
CHECK_VALUE ( io . readx . out . compaction_mode , 0 ) ;
CHECK_VALUE ( io . readx . out . nread , io . readx . in . maxcnt ) ;
CHECK_BUFFER ( buf , seed , io . readx . out . nread ) ;
2004-10-26 09:32:57 +04:00
printf ( " Trying extra large read \n " ) ;
io . readx . in . offset = 0 ;
io . readx . in . mincnt = 100 ;
io . readx . in . maxcnt = 80000 ;
status = smb_raw_read ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_VALUE ( io . readx . out . remaining , 0xFFFF ) ;
CHECK_VALUE ( io . readx . out . compaction_mode , 0 ) ;
CHECK_VALUE ( io . readx . out . nread , 0 ) ;
CHECK_BUFFER ( buf , seed , io . readx . out . nread ) ;
2003-08-13 05:53:07 +04:00
printf ( " Trying mincnt > maxcnt \n " ) ;
memset ( buf , 0 , maxsize ) ;
io . readx . in . offset = 0 ;
io . readx . in . mincnt = 30000 ;
io . readx . in . maxcnt = 20000 ;
status = smb_raw_read ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_VALUE ( io . readx . out . remaining , 0xFFFF ) ;
CHECK_VALUE ( io . readx . out . compaction_mode , 0 ) ;
CHECK_VALUE ( io . readx . out . nread , io . readx . in . maxcnt ) ;
CHECK_BUFFER ( buf , seed , io . readx . out . nread ) ;
printf ( " Trying mincnt < maxcnt \n " ) ;
memset ( buf , 0 , maxsize ) ;
io . readx . in . offset = 0 ;
io . readx . in . mincnt = 20000 ;
io . readx . in . maxcnt = 30000 ;
status = smb_raw_read ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_VALUE ( io . readx . out . remaining , 0xFFFF ) ;
CHECK_VALUE ( io . readx . out . compaction_mode , 0 ) ;
CHECK_VALUE ( io . readx . out . nread , io . readx . in . maxcnt ) ;
CHECK_BUFFER ( buf , seed , io . readx . out . nread ) ;
printf ( " Trying locked region \n " ) ;
cli - > session - > pid + + ;
2004-08-04 17:23:35 +04:00
if ( NT_STATUS_IS_ERR ( smbcli_lock ( cli - > tree , fnum , 103 , 1 , 0 , WRITE_LOCK ) ) ) {
2003-08-13 05:53:07 +04:00
printf ( " Failed to lock file at %d \n " , __LINE__ ) ;
ret = False ;
goto done ;
}
cli - > session - > pid - - ;
memset ( buf , 0 , maxsize ) ;
io . readx . in . offset = 0 ;
io . readx . in . mincnt = 100 ;
io . readx . in . maxcnt = 200 ;
status = smb_raw_read ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_FILE_LOCK_CONFLICT ) ;
printf ( " Trying large offset read \n " ) ;
2004-05-25 17:57:39 +04:00
io . readx . in . offset = ( ( uint64_t ) 0x2 ) < < 32 ;
2003-08-13 05:53:07 +04:00
io . readx . in . mincnt = 10 ;
io . readx . in . maxcnt = 10 ;
status = smb_raw_read ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_VALUE ( io . readx . out . nread , 0 ) ;
2004-08-04 17:23:35 +04:00
if ( NT_STATUS_IS_ERR ( smbcli_lock64 ( cli - > tree , fnum , io . readx . in . offset , 1 , 0 , WRITE_LOCK ) ) ) {
2003-08-13 05:53:07 +04:00
printf ( " Failed to lock file at %d \n " , __LINE__ ) ;
ret = False ;
goto done ;
}
status = smb_raw_read ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_VALUE ( io . readx . out . nread , 0 ) ;
done :
2004-08-04 17:23:35 +04:00
smbcli_close ( cli - > tree , fnum ) ;
smbcli_deltree ( cli - > tree , BASEDIR ) ;
2003-08-13 05:53:07 +04:00
return ret ;
}
/*
test readbraw ops
*/
2004-08-04 17:23:35 +04:00
static BOOL test_readbraw ( struct smbcli_state * cli , TALLOC_CTX * mem_ctx )
2003-08-13 05:53:07 +04:00
{
union smb_read io ;
NTSTATUS status ;
BOOL ret = True ;
int fnum ;
2004-12-04 16:56:25 +03:00
uint8_t * buf ;
2003-08-13 05:53:07 +04:00
const int maxsize = 90000 ;
const char * fname = BASEDIR " \\ test.txt " ;
const char * test_data = " TEST DATA " ;
2004-06-01 14:12:52 +04:00
uint_t seed = time ( NULL ) ;
2003-08-13 05:53:07 +04:00
2005-01-07 07:39:16 +03:00
buf = talloc_zero_size ( mem_ctx , maxsize ) ;
2003-08-13 05:53:07 +04:00
2004-11-12 12:37:59 +03:00
if ( ! torture_setup_dir ( cli , BASEDIR ) ) {
2003-08-13 05:53:07 +04:00
return False ;
}
printf ( " Testing RAW_READ_READBRAW \n " ) ;
2004-08-04 17:23:35 +04:00
fnum = smbcli_open ( cli - > tree , fname , O_RDWR | O_CREAT , DENY_NONE ) ;
2003-08-13 05:53:07 +04:00
if ( fnum = = - 1 ) {
2004-08-04 17:23:35 +04:00
printf ( " Failed to create %s - %s \n " , fname , smbcli_errstr ( cli - > tree ) ) ;
2003-08-13 05:53:07 +04:00
ret = False ;
goto done ;
}
printf ( " Trying empty file read \n " ) ;
io . generic . level = RAW_READ_READBRAW ;
io . readbraw . in . fnum = fnum ;
io . readbraw . in . mincnt = 1 ;
io . readbraw . in . maxcnt = 1 ;
io . readbraw . in . offset = 0 ;
io . readbraw . in . timeout = 0 ;
io . readbraw . out . data = buf ;
status = smb_raw_read ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_VALUE ( io . readbraw . out . nread , 0 ) ;
printf ( " Trying zero file read \n " ) ;
io . readbraw . in . mincnt = 0 ;
io . readbraw . in . maxcnt = 0 ;
status = smb_raw_read ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_VALUE ( io . readbraw . out . nread , 0 ) ;
printf ( " Trying bad fnum \n " ) ;
io . readbraw . in . fnum = fnum + 1 ;
status = smb_raw_read ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_VALUE ( io . readbraw . out . nread , 0 ) ;
io . readbraw . in . fnum = fnum ;
2004-08-04 17:23:35 +04:00
smbcli_write ( cli - > tree , fnum , 0 , test_data , 0 , strlen ( test_data ) ) ;
2003-08-13 05:53:07 +04:00
printf ( " Trying small read \n " ) ;
io . readbraw . in . fnum = fnum ;
io . readbraw . in . offset = 0 ;
io . readbraw . in . mincnt = strlen ( test_data ) ;
io . readbraw . in . maxcnt = strlen ( test_data ) ;
status = smb_raw_read ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_VALUE ( io . readbraw . out . nread , strlen ( test_data ) ) ;
if ( memcmp ( buf , test_data , strlen ( test_data ) ) ! = 0 ) {
ret = False ;
printf ( " incorrect data at %d!? (%s:%s) \n " , __LINE__ , test_data , buf ) ;
goto done ;
}
printf ( " Trying short read \n " ) ;
io . readbraw . in . offset = 1 ;
io . readbraw . in . mincnt = strlen ( test_data ) ;
io . readbraw . in . maxcnt = strlen ( test_data ) ;
status = smb_raw_read ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_VALUE ( io . readbraw . out . nread , strlen ( test_data ) - 1 ) ;
if ( memcmp ( buf , test_data + 1 , strlen ( test_data ) - 1 ) ! = 0 ) {
ret = False ;
printf ( " incorrect data at %d!? (%s:%s) \n " , __LINE__ , test_data + 1 , buf ) ;
goto done ;
}
printf ( " Trying max offset \n " ) ;
io . readbraw . in . offset = ~ 0 ;
io . readbraw . in . mincnt = strlen ( test_data ) ;
io . readbraw . in . maxcnt = strlen ( test_data ) ;
status = smb_raw_read ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_VALUE ( io . readbraw . out . nread , 0 ) ;
setup_buffer ( buf , seed , maxsize ) ;
2004-08-04 17:23:35 +04:00
smbcli_write ( cli - > tree , fnum , 0 , buf , 0 , maxsize ) ;
2003-08-13 05:53:07 +04:00
memset ( buf , 0 , maxsize ) ;
printf ( " Trying large read \n " ) ;
io . readbraw . in . offset = 0 ;
io . readbraw . in . mincnt = ~ 0 ;
io . readbraw . in . maxcnt = ~ 0 ;
status = smb_raw_read ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_VALUE ( io . readbraw . out . nread , 0xFFFF ) ;
CHECK_BUFFER ( buf , seed , io . readbraw . out . nread ) ;
printf ( " Trying mincnt > maxcnt \n " ) ;
memset ( buf , 0 , maxsize ) ;
io . readbraw . in . offset = 0 ;
io . readbraw . in . mincnt = 30000 ;
io . readbraw . in . maxcnt = 20000 ;
status = smb_raw_read ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_VALUE ( io . readbraw . out . nread , io . readbraw . in . maxcnt ) ;
CHECK_BUFFER ( buf , seed , io . readbraw . out . nread ) ;
printf ( " Trying mincnt < maxcnt \n " ) ;
memset ( buf , 0 , maxsize ) ;
io . readbraw . in . offset = 0 ;
io . readbraw . in . mincnt = 20000 ;
io . readbraw . in . maxcnt = 30000 ;
status = smb_raw_read ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_VALUE ( io . readbraw . out . nread , io . readbraw . in . maxcnt ) ;
CHECK_BUFFER ( buf , seed , io . readbraw . out . nread ) ;
printf ( " Trying locked region \n " ) ;
cli - > session - > pid + + ;
2004-08-04 17:23:35 +04:00
if ( NT_STATUS_IS_ERR ( smbcli_lock ( cli - > tree , fnum , 103 , 1 , 0 , WRITE_LOCK ) ) ) {
2003-08-13 05:53:07 +04:00
printf ( " Failed to lock file at %d \n " , __LINE__ ) ;
ret = False ;
goto done ;
}
cli - > session - > pid - - ;
memset ( buf , 0 , maxsize ) ;
io . readbraw . in . offset = 0 ;
io . readbraw . in . mincnt = 100 ;
io . readbraw . in . maxcnt = 200 ;
status = smb_raw_read ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_VALUE ( io . readbraw . out . nread , 0 ) ;
printf ( " Trying locked region with timeout \n " ) ;
memset ( buf , 0 , maxsize ) ;
io . readbraw . in . offset = 0 ;
io . readbraw . in . mincnt = 100 ;
io . readbraw . in . maxcnt = 200 ;
io . readbraw . in . timeout = 10000 ;
status = smb_raw_read ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_VALUE ( io . readbraw . out . nread , 0 ) ;
printf ( " Trying large offset read \n " ) ;
2004-05-25 17:57:39 +04:00
io . readbraw . in . offset = ( ( uint64_t ) 0x2 ) < < 32 ;
2003-08-13 05:53:07 +04:00
io . readbraw . in . mincnt = 10 ;
io . readbraw . in . maxcnt = 10 ;
io . readbraw . in . timeout = 0 ;
status = smb_raw_read ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_VALUE ( io . readbraw . out . nread , 0 ) ;
done :
2004-08-04 17:23:35 +04:00
smbcli_close ( cli - > tree , fnum ) ;
smbcli_deltree ( cli - > tree , BASEDIR ) ;
2003-08-13 05:53:07 +04:00
return ret ;
}
/*
basic testing of read calls
*/
2004-10-28 17:40:50 +04:00
BOOL torture_raw_read ( void )
2003-08-13 05:53:07 +04:00
{
2004-08-04 17:23:35 +04:00
struct smbcli_state * cli ;
2003-08-13 05:53:07 +04:00
BOOL ret = True ;
TALLOC_CTX * mem_ctx ;
if ( ! torture_open_connection ( & cli ) ) {
return False ;
}
mem_ctx = talloc_init ( " torture_raw_read " ) ;
if ( ! test_read ( cli , mem_ctx ) ) {
ret = False ;
}
if ( ! test_readx ( cli , mem_ctx ) ) {
ret = False ;
}
if ( ! test_lockread ( cli , mem_ctx ) ) {
ret = False ;
}
if ( ! test_readbraw ( cli , mem_ctx ) ) {
ret = False ;
}
torture_close_connection ( cli ) ;
2005-01-27 10:08:20 +03:00
talloc_free ( mem_ctx ) ;
2003-08-13 05:53:07 +04:00
return ret ;
}