2003-08-13 01:53:07 +00:00
/*
Unix SMB / CIFS implementation .
RAW_OPEN_ * individual test suite
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
2007-07-10 02:07:03 +00:00
the Free Software Foundation ; either version 3 of the License , or
2003-08-13 01:53:07 +00:00
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
2007-07-10 02:07:03 +00:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2003-08-13 01:53:07 +00:00
*/
# include "includes.h"
2006-01-03 13:41:17 +00:00
# include "torture/torture.h"
2004-11-01 01:03:22 +00:00
# include "libcli/raw/libcliraw.h"
2008-04-02 04:53:27 +02:00
# include "libcli/raw/raw_proto.h"
2004-11-02 00:24:21 +00:00
# include "system/time.h"
2005-02-10 05:09:35 +00:00
# include "system/filesys.h"
2006-03-16 00:23:11 +00:00
# include "librpc/gen_ndr/security.h"
2005-08-24 13:15:01 +00:00
# include "lib/events/events.h"
2006-01-03 15:40:05 +00:00
# include "libcli/libcli.h"
2006-03-17 17:59:58 +00:00
# include "torture/util.h"
2007-05-17 08:47:04 +00:00
# include "auth/credentials/credentials.h"
# include "lib/cmdline/popt_common.h"
2007-09-08 12:42:09 +00:00
# include "param/param.h"
2003-08-13 01:53:07 +00:00
/* enum for whether reads/writes are possible on a file */
enum rdwr_mode { RDWR_NONE , RDWR_RDONLY , RDWR_WRONLY , RDWR_RDWR } ;
# define BASEDIR "\\rawopen"
/*
check if a open file can be read / written
*/
2004-08-04 13:23:35 +00:00
static enum rdwr_mode check_rdwr ( struct smbcli_tree * tree , int fnum )
2003-08-13 01:53:07 +00:00
{
2004-12-04 13:56:25 +00:00
uint8_t c = 1 ;
2007-10-06 22:28:14 +00:00
bool can_read = ( smbcli_read ( tree , fnum , & c , 0 , 1 ) = = 1 ) ;
bool can_write = ( smbcli_write ( tree , fnum , 0 , & c , 0 , 1 ) = = 1 ) ;
2003-08-13 01:53:07 +00:00
if ( can_read & & can_write ) return RDWR_RDWR ;
if ( can_read & & ! can_write ) return RDWR_RDONLY ;
if ( ! can_read & & can_write ) return RDWR_WRONLY ;
return RDWR_NONE ;
}
/*
describe a RDWR mode as a string
*/
static const char * rdwr_string ( enum rdwr_mode m )
{
switch ( m ) {
case RDWR_NONE : return " NONE " ;
case RDWR_RDONLY : return " RDONLY " ;
case RDWR_WRONLY : return " WRONLY " ;
case RDWR_RDWR : return " RDWR " ;
}
return " - " ;
}
# define CHECK_STATUS(status, correct) do { \
if ( ! NT_STATUS_EQUAL ( status , correct ) ) { \
2004-10-21 03:49:17 +00:00
printf ( " (%s) Incorrect status %s - should be %s \n " , \
__location__ , nt_errstr ( status ) , nt_errstr ( correct ) ) ; \
2007-10-06 22:28:14 +00:00
ret = false ; \
2003-08-13 01:53:07 +00:00
goto done ; \
} } while ( 0 )
# define CREATE_FILE do { \
2007-12-03 00:28:22 +01:00
fnum = create_complex_file ( cli , tctx , fname ) ; \
2003-08-13 01:53:07 +00:00
if ( fnum = = - 1 ) { \
2004-10-21 03:49:17 +00:00
printf ( " (%s) Failed to create %s - %s \n " , __location__ , fname , smbcli_errstr ( cli - > tree ) ) ; \
2007-10-06 22:28:14 +00:00
ret = false ; \
2003-08-13 01:53:07 +00:00
goto done ; \
} } while ( 0 )
# define CHECK_RDWR(fnum, correct) do { \
2004-02-08 00:51:07 +00:00
enum rdwr_mode m = check_rdwr ( cli - > tree , fnum ) ; \
2003-08-13 01:53:07 +00:00
if ( m ! = correct ) { \
2004-10-21 03:49:17 +00:00
printf ( " (%s) Incorrect readwrite mode %s - expected %s \n " , \
__location__ , rdwr_string ( m ) , rdwr_string ( correct ) ) ; \
2007-10-06 22:28:14 +00:00
ret = false ; \
2003-08-13 01:53:07 +00:00
} } while ( 0 )
# define CHECK_TIME(t, field) do { \
time_t t1 , t2 ; \
finfo . all_info . level = RAW_FILEINFO_ALL_INFO ; \
2006-03-12 22:48:25 +00:00
finfo . all_info . in . file . path = fname ; \
2007-12-03 00:28:22 +01:00
status = smb_raw_pathinfo ( cli - > tree , tctx , & finfo ) ; \
2003-08-13 01:53:07 +00:00
CHECK_STATUS ( status , NT_STATUS_OK ) ; \
t1 = t & ~ 1 ; \
2004-05-25 13:57:39 +00:00
t2 = nt_time_to_unix ( finfo . all_info . out . field ) & ~ 1 ; \
2006-04-24 14:20:44 +00:00
if ( abs ( t1 - t2 ) > 2 ) { \
2004-10-21 03:49:17 +00:00
printf ( " (%s) wrong time for field %s %s - %s \n " , \
__location__ , # field , \
2007-12-03 00:28:22 +01:00
timestring ( tctx , t1 ) , \
timestring ( tctx , t2 ) ) ; \
dump_all_info ( tctx , & finfo ) ; \
2007-10-06 22:28:14 +00:00
ret = false ; \
2003-08-13 01:53:07 +00:00
} } while ( 0 )
# define CHECK_NTTIME(t, field) do { \
NTTIME t2 ; \
finfo . all_info . level = RAW_FILEINFO_ALL_INFO ; \
2006-03-12 22:48:25 +00:00
finfo . all_info . in . file . path = fname ; \
2007-12-03 00:28:22 +01:00
status = smb_raw_pathinfo ( cli - > tree , tctx , & finfo ) ; \
2003-08-13 01:53:07 +00:00
CHECK_STATUS ( status , NT_STATUS_OK ) ; \
t2 = finfo . all_info . out . field ; \
2004-05-25 13:57:39 +00:00
if ( t ! = t2 ) { \
2004-10-21 03:49:17 +00:00
printf ( " (%s) wrong time for field %s %s - %s \n " , \
__location__ , # field , \
2007-12-03 00:28:22 +01:00
nt_time_string ( tctx , t ) , \
nt_time_string ( tctx , t2 ) ) ; \
dump_all_info ( tctx , & finfo ) ; \
2007-10-06 22:28:14 +00:00
ret = false ; \
2003-08-13 01:53:07 +00:00
} } while ( 0 )
# define CHECK_ALL_INFO(v, field) do { \
finfo . all_info . level = RAW_FILEINFO_ALL_INFO ; \
2006-03-12 22:48:25 +00:00
finfo . all_info . in . file . path = fname ; \
2007-12-03 00:28:22 +01:00
status = smb_raw_pathinfo ( cli - > tree , tctx , & finfo ) ; \
2003-08-13 01:53:07 +00:00
CHECK_STATUS ( status , NT_STATUS_OK ) ; \
2004-10-21 06:37:15 +00:00
if ( ( v ) ! = ( finfo . all_info . out . field ) ) { \
2004-10-21 03:49:17 +00:00
printf ( " (%s) wrong value for field %s 0x%x - 0x%x \n " , \
2004-10-21 06:37:15 +00:00
__location__ , # field , ( int ) v , ( int ) ( finfo . all_info . out . field ) ) ; \
2007-12-03 00:28:22 +01:00
dump_all_info ( tctx , & finfo ) ; \
2007-10-06 22:28:14 +00:00
ret = false ; \
2003-08-13 01:53:07 +00:00
} } while ( 0 )
# define CHECK_VAL(v, correct) do { \
if ( ( v ) ! = ( correct ) ) { \
2004-11-06 07:58:45 +00:00
printf ( " (%s) wrong value for %s 0x%x - should be 0x%x \n " , \
2004-10-21 06:37:15 +00:00
__location__ , # v , ( int ) ( v ) , ( int ) correct ) ; \
2007-10-06 22:28:14 +00:00
ret = false ; \
2003-08-13 01:53:07 +00:00
} } while ( 0 )
# define SET_ATTRIB(sattrib) do { \
union smb_setfileinfo sfinfo ; \
ZERO_STRUCT ( sfinfo . basic_info . in ) ; \
2006-03-13 12:43:59 +00:00
sfinfo . basic_info . level = RAW_SFILEINFO_BASIC_INFORMATION ; \
sfinfo . basic_info . in . file . path = fname ; \
2003-08-13 01:53:07 +00:00
sfinfo . basic_info . in . attrib = sattrib ; \
status = smb_raw_setpathinfo ( cli - > tree , & sfinfo ) ; \
if ( ! NT_STATUS_IS_OK ( status ) ) { \
2004-10-21 03:49:17 +00:00
printf ( " (%s) Failed to set attrib 0x%x on %s \n " , \
__location__ , sattrib , fname ) ; \
2003-08-13 01:53:07 +00:00
} } while ( 0 )
/*
test RAW_OPEN_OPEN
*/
2007-12-03 00:28:22 +01:00
static bool test_open ( struct smbcli_state * cli , struct torture_context * tctx )
2003-08-13 01:53:07 +00:00
{
union smb_open io ;
union smb_fileinfo finfo ;
const char * fname = BASEDIR " \\ torture_open.txt " ;
NTSTATUS status ;
2004-08-21 01:54:46 +00:00
int fnum = - 1 , fnum2 ;
2007-10-06 22:28:14 +00:00
bool ret = true ;
2003-08-13 01:53:07 +00:00
printf ( " Checking RAW_OPEN_OPEN \n " ) ;
2004-11-02 04:17:30 +00:00
io . openold . level = RAW_OPEN_OPEN ;
io . openold . in . fname = fname ;
2004-12-13 10:48:21 +00:00
io . openold . in . open_mode = OPEN_FLAGS_FCB ;
2004-11-02 04:17:30 +00:00
io . openold . in . search_attrs = 0 ;
2007-12-03 00:28:22 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2003-08-13 01:53:07 +00:00
CHECK_STATUS ( status , NT_STATUS_OBJECT_NAME_NOT_FOUND ) ;
2006-03-12 22:48:25 +00:00
fnum = io . openold . out . file . fnum ;
2003-08-13 01:53:07 +00:00
2004-08-04 13:23:35 +00:00
smbcli_unlink ( cli - > tree , fname ) ;
2003-08-13 01:53:07 +00:00
CREATE_FILE ;
2004-08-04 13:23:35 +00:00
smbcli_close ( cli - > tree , fnum ) ;
2003-08-13 01:53:07 +00:00
2007-12-03 00:28:22 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2003-08-13 01:53:07 +00:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2006-03-12 22:48:25 +00:00
fnum = io . openold . out . file . fnum ;
2003-08-13 01:53:07 +00:00
CHECK_RDWR ( fnum , RDWR_RDWR ) ;
2007-12-03 00:28:22 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2003-08-13 01:53:07 +00:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2006-03-12 22:48:25 +00:00
fnum2 = io . openold . out . file . fnum ;
2003-08-13 01:53:07 +00:00
CHECK_RDWR ( fnum2 , RDWR_RDWR ) ;
2004-08-04 13:23:35 +00:00
smbcli_close ( cli - > tree , fnum2 ) ;
smbcli_close ( cli - > tree , fnum ) ;
2003-08-13 01:53:07 +00:00
/* check the read/write modes */
2004-11-02 04:17:30 +00:00
io . openold . level = RAW_OPEN_OPEN ;
io . openold . in . fname = fname ;
io . openold . in . search_attrs = 0 ;
2003-08-13 01:53:07 +00:00
2004-12-13 10:48:21 +00:00
io . openold . in . open_mode = OPEN_FLAGS_OPEN_READ ;
2007-12-03 00:28:22 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2003-08-13 01:53:07 +00:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2006-03-12 22:48:25 +00:00
fnum = io . openold . out . file . fnum ;
2003-08-13 01:53:07 +00:00
CHECK_RDWR ( fnum , RDWR_RDONLY ) ;
2004-08-04 13:23:35 +00:00
smbcli_close ( cli - > tree , fnum ) ;
2003-08-13 01:53:07 +00:00
2004-12-13 10:48:21 +00:00
io . openold . in . open_mode = OPEN_FLAGS_OPEN_WRITE ;
2007-12-03 00:28:22 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2003-08-13 01:53:07 +00:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2006-03-12 22:48:25 +00:00
fnum = io . openold . out . file . fnum ;
2003-08-13 01:53:07 +00:00
CHECK_RDWR ( fnum , RDWR_WRONLY ) ;
2004-08-04 13:23:35 +00:00
smbcli_close ( cli - > tree , fnum ) ;
2003-08-13 01:53:07 +00:00
2004-12-13 10:48:21 +00:00
io . openold . in . open_mode = OPEN_FLAGS_OPEN_RDWR ;
2007-12-03 00:28:22 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2003-08-13 01:53:07 +00:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2006-03-12 22:48:25 +00:00
fnum = io . openold . out . file . fnum ;
2003-08-13 01:53:07 +00:00
CHECK_RDWR ( fnum , RDWR_RDWR ) ;
2004-08-04 13:23:35 +00:00
smbcli_close ( cli - > tree , fnum ) ;
2003-08-13 01:53:07 +00:00
/* check the share modes roughly - not a complete matrix */
2004-12-13 10:48:21 +00:00
io . openold . in . open_mode = OPEN_FLAGS_OPEN_RDWR | OPEN_FLAGS_DENY_WRITE ;
2007-12-03 00:28:22 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2003-08-13 01:53:07 +00:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2006-03-12 22:48:25 +00:00
fnum = io . openold . out . file . fnum ;
2003-08-13 01:53:07 +00:00
CHECK_RDWR ( fnum , RDWR_RDWR ) ;
2004-12-13 10:48:21 +00:00
if ( io . openold . in . open_mode ! = io . openold . out . rmode ) {
printf ( " (%s) rmode should equal open_mode - 0x%x 0x%x \n " ,
__location__ , io . openold . out . rmode , io . openold . in . open_mode ) ;
2003-08-13 01:53:07 +00:00
}
2004-12-13 10:48:21 +00:00
io . openold . in . open_mode = OPEN_FLAGS_OPEN_RDWR | OPEN_FLAGS_DENY_NONE ;
2007-12-03 00:28:22 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2003-08-13 01:53:07 +00:00
CHECK_STATUS ( status , NT_STATUS_SHARING_VIOLATION ) ;
2004-12-13 10:48:21 +00:00
io . openold . in . open_mode = OPEN_FLAGS_OPEN_READ | OPEN_FLAGS_DENY_NONE ;
2007-12-03 00:28:22 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2003-08-13 01:53:07 +00:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2006-03-12 22:48:25 +00:00
fnum2 = io . openold . out . file . fnum ;
2003-08-13 01:53:07 +00:00
CHECK_RDWR ( fnum2 , RDWR_RDONLY ) ;
2004-08-04 13:23:35 +00:00
smbcli_close ( cli - > tree , fnum ) ;
smbcli_close ( cli - > tree , fnum2 ) ;
2003-08-13 01:53:07 +00:00
/* check the returned write time */
2004-11-02 04:17:30 +00:00
io . openold . level = RAW_OPEN_OPEN ;
io . openold . in . fname = fname ;
io . openold . in . search_attrs = 0 ;
2004-12-13 10:48:21 +00:00
io . openold . in . open_mode = OPEN_FLAGS_OPEN_READ ;
2007-12-03 00:28:22 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2003-08-13 01:53:07 +00:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2006-03-12 22:48:25 +00:00
fnum = io . openold . out . file . fnum ;
2003-08-13 01:53:07 +00:00
/* check other reply fields */
2004-11-02 04:17:30 +00:00
CHECK_TIME ( io . openold . out . write_time , write_time ) ;
CHECK_ALL_INFO ( io . openold . out . size , size ) ;
CHECK_ALL_INFO ( io . openold . out . attrib , attrib & ~ FILE_ATTRIBUTE_NONINDEXED ) ;
2003-08-13 01:53:07 +00:00
done :
2004-08-04 13:23:35 +00:00
smbcli_close ( cli - > tree , fnum ) ;
smbcli_unlink ( cli - > tree , fname ) ;
2003-08-13 01:53:07 +00:00
return ret ;
}
/*
test RAW_OPEN_OPENX
*/
2007-12-03 00:28:22 +01:00
static bool test_openx ( struct smbcli_state * cli , struct torture_context * tctx )
2003-08-13 01:53:07 +00:00
{
union smb_open io ;
union smb_fileinfo finfo ;
const char * fname = BASEDIR " \\ torture_openx.txt " ;
2005-09-09 21:45:36 +00:00
const char * fname_exe = BASEDIR " \\ torture_openx.exe " ;
2003-08-13 01:53:07 +00:00
NTSTATUS status ;
2004-08-21 01:54:46 +00:00
int fnum = - 1 , fnum2 ;
2007-10-06 22:28:14 +00:00
bool ret = true ;
2003-08-13 01:53:07 +00:00
int i ;
2004-11-03 10:09:48 +00:00
struct timeval tv ;
2003-08-13 01:53:07 +00:00
struct {
2004-05-25 17:24:24 +00:00
uint16_t open_func ;
2007-10-06 22:28:14 +00:00
bool with_file ;
2003-08-13 01:53:07 +00:00
NTSTATUS correct_status ;
} open_funcs [ ] = {
2007-10-06 22:28:14 +00:00
{ OPENX_OPEN_FUNC_OPEN , true , NT_STATUS_OK } ,
{ OPENX_OPEN_FUNC_OPEN , false , NT_STATUS_OBJECT_NAME_NOT_FOUND } ,
{ OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE , true , NT_STATUS_OK } ,
{ OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE , false , NT_STATUS_OK } ,
{ OPENX_OPEN_FUNC_FAIL , true , NT_STATUS_DOS ( ERRDOS , ERRbadaccess ) } ,
{ OPENX_OPEN_FUNC_FAIL , false , NT_STATUS_DOS ( ERRDOS , ERRbadaccess ) } ,
{ OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE , true , NT_STATUS_OBJECT_NAME_COLLISION } ,
{ OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE , false , NT_STATUS_OK } ,
{ OPENX_OPEN_FUNC_TRUNC , true , NT_STATUS_OK } ,
{ OPENX_OPEN_FUNC_TRUNC , false , NT_STATUS_OBJECT_NAME_NOT_FOUND } ,
{ OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE , true , NT_STATUS_OK } ,
{ OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE , false , NT_STATUS_OK } ,
2003-08-13 01:53:07 +00:00
} ;
printf ( " Checking RAW_OPEN_OPENX \n " ) ;
2004-08-04 13:23:35 +00:00
smbcli_unlink ( cli - > tree , fname ) ;
2003-08-13 01:53:07 +00:00
io . openx . level = RAW_OPEN_OPENX ;
io . openx . in . fname = fname ;
io . openx . in . flags = OPENX_FLAGS_ADDITIONAL_INFO ;
io . openx . in . open_mode = OPENX_MODE_ACCESS_RDWR ;
io . openx . in . search_attrs = 0 ;
io . openx . in . file_attrs = 0 ;
io . openx . in . write_time = 0 ;
io . openx . in . size = 1024 * 1024 ;
io . openx . in . timeout = 0 ;
/* check all combinations of open_func */
for ( i = 0 ; i < ARRAY_SIZE ( open_funcs ) ; i + + ) {
if ( open_funcs [ i ] . with_file ) {
2007-12-03 00:28:22 +01:00
fnum = create_complex_file ( cli , tctx , fname ) ;
2003-08-13 01:53:07 +00:00
if ( fnum = = - 1 ) {
2004-08-04 13:23:35 +00:00
d_printf ( " Failed to create file %s - %s \n " , fname , smbcli_errstr ( cli - > tree ) ) ;
2007-10-06 22:28:14 +00:00
ret = false ;
2003-08-13 01:53:07 +00:00
goto done ;
}
2004-08-04 13:23:35 +00:00
smbcli_close ( cli - > tree , fnum ) ;
2003-08-13 01:53:07 +00:00
}
io . openx . in . open_func = open_funcs [ i ] . open_func ;
2007-12-03 00:28:22 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2003-08-13 01:53:07 +00:00
if ( ! NT_STATUS_EQUAL ( status , open_funcs [ i ] . correct_status ) ) {
2004-10-21 03:49:17 +00:00
printf ( " (%s) incorrect status %s should be %s (i=%d with_file=%d open_func=0x%x) \n " ,
__location__ , nt_errstr ( status ) , nt_errstr ( open_funcs [ i ] . correct_status ) ,
2003-08-13 01:53:07 +00:00
i , ( int ) open_funcs [ i ] . with_file , ( int ) open_funcs [ i ] . open_func ) ;
2007-10-06 22:28:14 +00:00
ret = false ;
2003-08-13 01:53:07 +00:00
}
2004-12-13 10:48:21 +00:00
if ( NT_STATUS_IS_OK ( status ) ) {
2006-03-12 22:48:25 +00:00
smbcli_close ( cli - > tree , io . openx . out . file . fnum ) ;
2004-12-13 10:48:21 +00:00
}
if ( open_funcs [ i ] . with_file ) {
2004-08-04 13:23:35 +00:00
smbcli_unlink ( cli - > tree , fname ) ;
2003-08-13 01:53:07 +00:00
}
}
2004-12-13 10:48:21 +00:00
smbcli_unlink ( cli - > tree , fname ) ;
2003-08-13 01:53:07 +00:00
/* check the basic return fields */
io . openx . in . open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE ;
2007-12-03 00:28:22 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2003-08-13 01:53:07 +00:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2006-03-12 22:48:25 +00:00
fnum = io . openx . out . file . fnum ;
2003-08-13 01:53:07 +00:00
CHECK_ALL_INFO ( io . openx . out . size , size ) ;
CHECK_TIME ( io . openx . out . write_time , write_time ) ;
2004-10-21 06:37:15 +00:00
CHECK_ALL_INFO ( io . openx . out . attrib , attrib & ~ FILE_ATTRIBUTE_NONINDEXED ) ;
2003-08-13 01:53:07 +00:00
CHECK_VAL ( io . openx . out . access , OPENX_MODE_ACCESS_RDWR ) ;
CHECK_VAL ( io . openx . out . ftype , 0 ) ;
CHECK_VAL ( io . openx . out . devstate , 0 ) ;
CHECK_VAL ( io . openx . out . action , OPENX_ACTION_CREATED ) ;
2004-11-06 07:58:45 +00:00
CHECK_VAL ( io . openx . out . size , 1024 * 1024 ) ;
CHECK_ALL_INFO ( io . openx . in . size , size ) ;
2004-08-04 13:23:35 +00:00
smbcli_close ( cli - > tree , fnum ) ;
smbcli_unlink ( cli - > tree , fname ) ;
2003-08-13 01:53:07 +00:00
/* check the fields when the file already existed */
2007-12-03 00:28:22 +01:00
fnum2 = create_complex_file ( cli , tctx , fname ) ;
2003-08-13 01:53:07 +00:00
if ( fnum2 = = - 1 ) {
2007-10-06 22:28:14 +00:00
ret = false ;
2003-08-13 01:53:07 +00:00
goto done ;
}
2004-08-04 13:23:35 +00:00
smbcli_close ( cli - > tree , fnum2 ) ;
2003-08-13 01:53:07 +00:00
io . openx . in . open_func = OPENX_OPEN_FUNC_OPEN ;
2007-12-03 00:28:22 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2003-08-13 01:53:07 +00:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2006-03-12 22:48:25 +00:00
fnum = io . openx . out . file . fnum ;
2003-08-13 01:53:07 +00:00
CHECK_ALL_INFO ( io . openx . out . size , size ) ;
CHECK_TIME ( io . openx . out . write_time , write_time ) ;
CHECK_VAL ( io . openx . out . action , OPENX_ACTION_EXISTED ) ;
CHECK_VAL ( io . openx . out . unknown , 0 ) ;
2004-10-21 06:37:15 +00:00
CHECK_ALL_INFO ( io . openx . out . attrib , attrib & ~ FILE_ATTRIBUTE_NONINDEXED ) ;
2004-08-04 13:23:35 +00:00
smbcli_close ( cli - > tree , fnum ) ;
2003-08-13 01:53:07 +00:00
/* now check the search attrib for hidden files - win2003 ignores this? */
SET_ATTRIB ( FILE_ATTRIBUTE_HIDDEN ) ;
CHECK_ALL_INFO ( FILE_ATTRIBUTE_HIDDEN , attrib ) ;
io . openx . in . search_attrs = FILE_ATTRIBUTE_HIDDEN ;
2007-12-03 00:28:22 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2003-08-13 01:53:07 +00:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2006-03-12 22:48:25 +00:00
smbcli_close ( cli - > tree , io . openx . out . file . fnum ) ;
2003-08-13 01:53:07 +00:00
io . openx . in . search_attrs = 0 ;
2007-12-03 00:28:22 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2003-08-13 01:53:07 +00:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2006-03-12 22:48:25 +00:00
smbcli_close ( cli - > tree , io . openx . out . file . fnum ) ;
2003-08-13 01:53:07 +00:00
SET_ATTRIB ( FILE_ATTRIBUTE_NORMAL ) ;
2004-08-04 13:23:35 +00:00
smbcli_unlink ( cli - > tree , fname ) ;
2003-08-13 01:53:07 +00:00
/* and check attrib on create */
io . openx . in . open_func = OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE ;
io . openx . in . search_attrs = 0 ;
io . openx . in . file_attrs = FILE_ATTRIBUTE_SYSTEM ;
2007-12-03 00:28:22 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2003-08-13 01:53:07 +00:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2007-12-03 00:28:22 +01:00
if ( torture_setting_bool ( tctx , " samba3 " , false ) ) {
2007-01-03 06:29:22 +00:00
CHECK_ALL_INFO ( FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_ARCHIVE ,
attrib & ~ ( FILE_ATTRIBUTE_NONINDEXED |
FILE_ATTRIBUTE_SPARSE ) ) ;
}
else {
CHECK_ALL_INFO ( FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_ARCHIVE ,
attrib & ~ ( FILE_ATTRIBUTE_NONINDEXED ) ) ;
}
2006-03-12 22:48:25 +00:00
smbcli_close ( cli - > tree , io . openx . out . file . fnum ) ;
2004-08-04 13:23:35 +00:00
smbcli_unlink ( cli - > tree , fname ) ;
2003-08-13 01:53:07 +00:00
/* check timeout on create - win2003 ignores the timeout! */
io . openx . in . open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE ;
io . openx . in . file_attrs = 0 ;
io . openx . in . open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_ALL ;
2007-12-03 00:28:22 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2003-08-13 01:53:07 +00:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2006-03-12 22:48:25 +00:00
fnum = io . openx . out . file . fnum ;
2003-08-13 01:53:07 +00:00
io . openx . in . timeout = 20000 ;
2004-11-03 10:09:48 +00:00
tv = timeval_current ( ) ;
2003-08-13 01:53:07 +00:00
io . openx . in . open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_NONE ;
2007-12-03 00:28:22 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2003-08-13 01:53:07 +00:00
CHECK_STATUS ( status , NT_STATUS_SHARING_VIOLATION ) ;
2004-11-03 10:09:48 +00:00
if ( timeval_elapsed ( & tv ) > 3.0 ) {
printf ( " (%s) Incorrect timing in openx with timeout - waited %.2f seconds \n " ,
__location__ , timeval_elapsed ( & tv ) ) ;
2007-10-06 22:28:14 +00:00
ret = false ;
2003-08-13 01:53:07 +00:00
}
2004-08-04 13:23:35 +00:00
smbcli_close ( cli - > tree , fnum ) ;
smbcli_unlink ( cli - > tree , fname ) ;
2003-08-13 01:53:07 +00:00
/* now this is a really weird one - open for execute implies create?! */
io . openx . in . fname = fname ;
io . openx . in . flags = OPENX_FLAGS_ADDITIONAL_INFO ;
io . openx . in . open_mode = OPENX_MODE_ACCESS_EXEC | OPENX_MODE_DENY_NONE ;
io . openx . in . search_attrs = 0 ;
io . openx . in . open_func = OPENX_OPEN_FUNC_FAIL ;
io . openx . in . file_attrs = 0 ;
io . openx . in . write_time = 0 ;
io . openx . in . size = 0 ;
io . openx . in . timeout = 0 ;
2007-12-03 00:28:22 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2003-08-13 01:53:07 +00:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2006-03-12 22:48:25 +00:00
smbcli_close ( cli - > tree , io . openx . out . file . fnum ) ;
2003-08-13 01:53:07 +00:00
/* check the extended return flag */
io . openx . in . flags = OPENX_FLAGS_ADDITIONAL_INFO | OPENX_FLAGS_EXTENDED_RETURN ;
io . openx . in . open_func = OPENX_OPEN_FUNC_OPEN ;
2007-12-03 00:28:22 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2003-08-13 01:53:07 +00:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2004-11-30 04:33:27 +00:00
CHECK_VAL ( io . openx . out . access_mask , SEC_STD_ALL ) ;
2006-03-12 22:48:25 +00:00
smbcli_close ( cli - > tree , io . openx . out . file . fnum ) ;
2003-08-13 01:53:07 +00:00
2004-12-13 10:48:21 +00:00
io . openx . in . fname = " \\ A.+,;=[].B " ;
2007-12-03 00:28:22 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2004-12-13 10:48:21 +00:00
CHECK_STATUS ( status , NT_STATUS_OBJECT_NAME_NOT_FOUND ) ;
2005-09-09 21:45:36 +00:00
/* Check the mapping for open exec. */
/* First create an .exe file. */
smbcli_unlink ( cli - > tree , fname_exe ) ;
2007-12-03 00:28:22 +01:00
fnum = create_complex_file ( cli , tctx , fname_exe ) ;
2005-09-09 21:45:36 +00:00
smbcli_close ( cli - > tree , fnum ) ;
io . openx . level = RAW_OPEN_OPENX ;
io . openx . in . fname = fname_exe ;
io . openx . in . flags = OPENX_FLAGS_ADDITIONAL_INFO ;
io . openx . in . open_mode = OPENX_MODE_ACCESS_EXEC | OPENX_MODE_DENY_NONE ;
io . openx . in . search_attrs = 0 ;
io . openx . in . file_attrs = 0 ;
io . openx . in . write_time = 0 ;
io . openx . in . size = 0 ;
io . openx . in . timeout = 0 ;
2007-12-03 00:28:22 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2005-09-09 21:45:36 +00:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
/* Can we read and write ? */
2006-03-12 22:48:25 +00:00
CHECK_RDWR ( io . openx . out . file . fnum , RDWR_RDONLY ) ;
smbcli_close ( cli - > tree , io . openx . out . file . fnum ) ;
2005-09-09 21:45:36 +00:00
smbcli_unlink ( cli - > tree , fname ) ;
2003-08-13 01:53:07 +00:00
done :
2004-08-04 13:23:35 +00:00
smbcli_close ( cli - > tree , fnum ) ;
2005-09-09 21:45:36 +00:00
smbcli_unlink ( cli - > tree , fname_exe ) ;
2004-08-04 13:23:35 +00:00
smbcli_unlink ( cli - > tree , fname ) ;
2003-08-13 01:53:07 +00:00
return ret ;
}
/*
test RAW_OPEN_T2OPEN
2004-12-13 10:48:21 +00:00
many thanks to kukks for a sniff showing how this works with os2 - > w2k
2003-08-13 01:53:07 +00:00
*/
2007-12-03 00:28:22 +01:00
static bool test_t2open ( struct smbcli_state * cli , struct torture_context * tctx )
2003-08-13 01:53:07 +00:00
{
union smb_open io ;
union smb_fileinfo finfo ;
2004-11-06 07:58:45 +00:00
const char * fname1 = BASEDIR " \\ torture_t2open_yes.txt " ;
const char * fname2 = BASEDIR " \\ torture_t2open_no.txt " ;
const char * fname = BASEDIR " \\ torture_t2open_3.txt " ;
2003-08-13 01:53:07 +00:00
NTSTATUS status ;
int fnum ;
2007-10-06 22:28:14 +00:00
bool ret = true ;
2003-08-13 01:53:07 +00:00
int i ;
struct {
2004-05-25 17:24:24 +00:00
uint16_t open_func ;
2007-10-06 22:28:14 +00:00
bool with_file ;
2003-08-13 01:53:07 +00:00
NTSTATUS correct_status ;
} open_funcs [ ] = {
2007-10-06 22:28:14 +00:00
{ OPENX_OPEN_FUNC_OPEN , true , NT_STATUS_OK } ,
{ OPENX_OPEN_FUNC_OPEN , false , NT_STATUS_OBJECT_NAME_NOT_FOUND } ,
{ OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE , true , NT_STATUS_OK } ,
{ OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE , false , NT_STATUS_OK } ,
{ OPENX_OPEN_FUNC_FAIL , true , NT_STATUS_OBJECT_NAME_COLLISION } ,
{ OPENX_OPEN_FUNC_FAIL , false , NT_STATUS_OBJECT_NAME_COLLISION } ,
{ OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE , true , NT_STATUS_OBJECT_NAME_COLLISION } ,
{ OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE , false , NT_STATUS_OBJECT_NAME_COLLISION } ,
{ OPENX_OPEN_FUNC_TRUNC , true , NT_STATUS_OK } ,
{ OPENX_OPEN_FUNC_TRUNC , false , NT_STATUS_OK } ,
{ OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE , true , NT_STATUS_OK } ,
{ OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE , false , NT_STATUS_OK } ,
2003-08-13 01:53:07 +00:00
} ;
2007-12-03 00:28:22 +01:00
fnum = create_complex_file ( cli , tctx , fname1 ) ;
2004-11-06 07:58:45 +00:00
if ( fnum = = - 1 ) {
d_printf ( " Failed to create file %s - %s \n " , fname1 , smbcli_errstr ( cli - > tree ) ) ;
2007-10-06 22:28:14 +00:00
ret = false ;
2004-11-06 07:58:45 +00:00
goto done ;
}
smbcli_close ( cli - > tree , fnum ) ;
2003-08-13 01:53:07 +00:00
printf ( " Checking RAW_OPEN_T2OPEN \n " ) ;
io . t2open . level = RAW_OPEN_T2OPEN ;
2004-12-13 10:48:21 +00:00
io . t2open . in . flags = OPENX_FLAGS_ADDITIONAL_INFO ;
2003-08-13 01:53:07 +00:00
io . t2open . in . open_mode = OPENX_MODE_DENY_NONE | OPENX_MODE_ACCESS_RDWR ;
io . t2open . in . open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE ;
2004-12-13 10:48:21 +00:00
io . t2open . in . search_attrs = 0 ;
2003-08-13 01:53:07 +00:00
io . t2open . in . file_attrs = 0 ;
io . t2open . in . write_time = 0 ;
io . t2open . in . size = 0 ;
io . t2open . in . timeout = 0 ;
2004-12-13 10:48:21 +00:00
io . t2open . in . num_eas = 3 ;
2007-12-03 00:28:22 +01:00
io . t2open . in . eas = talloc_array ( tctx , struct ea_struct , io . t2open . in . num_eas ) ;
2003-08-13 01:53:07 +00:00
io . t2open . in . eas [ 0 ] . flags = 0 ;
2004-12-13 10:48:21 +00:00
io . t2open . in . eas [ 0 ] . name . s = " .CLASSINFO " ;
2007-12-03 00:28:22 +01:00
io . t2open . in . eas [ 0 ] . value = data_blob_talloc ( tctx , " first value " , 11 ) ;
2004-12-13 10:48:21 +00:00
io . t2open . in . eas [ 1 ] . flags = 0 ;
io . t2open . in . eas [ 1 ] . name . s = " EA TWO " ;
2007-12-03 00:28:22 +01:00
io . t2open . in . eas [ 1 ] . value = data_blob_talloc ( tctx , " foo " , 3 ) ;
2004-12-13 10:48:21 +00:00
io . t2open . in . eas [ 2 ] . flags = 0 ;
io . t2open . in . eas [ 2 ] . name . s = " X THIRD " ;
2007-12-03 00:28:22 +01:00
io . t2open . in . eas [ 2 ] . value = data_blob_talloc ( tctx , " xy " , 2 ) ;
2003-08-13 01:53:07 +00:00
/* check all combinations of open_func */
for ( i = 0 ; i < ARRAY_SIZE ( open_funcs ) ; i + + ) {
2007-01-03 06:29:22 +00:00
again :
2003-08-13 01:53:07 +00:00
if ( open_funcs [ i ] . with_file ) {
2004-11-06 07:58:45 +00:00
io . t2open . in . fname = fname1 ;
} else {
io . t2open . in . fname = fname2 ;
2003-08-13 01:53:07 +00:00
}
io . t2open . in . open_func = open_funcs [ i ] . open_func ;
2007-12-03 00:28:22 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2007-01-03 06:29:22 +00:00
if ( ( io . t2open . in . num_eas ! = 0 )
& & NT_STATUS_EQUAL ( status , NT_STATUS_EAS_NOT_SUPPORTED )
2007-12-03 00:28:22 +01:00
& & torture_setting_bool ( tctx , " samba3 " , false ) ) {
2007-01-03 06:29:22 +00:00
printf ( " (%s) EAs not supported, not treating as fatal "
" in Samba3 test \n " , __location__ ) ;
io . t2open . in . num_eas = 0 ;
goto again ;
}
2003-08-13 01:53:07 +00:00
if ( ! NT_STATUS_EQUAL ( status , open_funcs [ i ] . correct_status ) ) {
2004-10-21 03:49:17 +00:00
printf ( " (%s) incorrect status %s should be %s (i=%d with_file=%d open_func=0x%x) \n " ,
__location__ , nt_errstr ( status ) , nt_errstr ( open_funcs [ i ] . correct_status ) ,
2003-08-13 01:53:07 +00:00
i , ( int ) open_funcs [ i ] . with_file , ( int ) open_funcs [ i ] . open_func ) ;
2007-10-06 22:28:14 +00:00
ret = false ;
2003-08-13 01:53:07 +00:00
}
2004-11-06 07:58:45 +00:00
if ( NT_STATUS_IS_OK ( status ) ) {
2006-03-12 22:48:25 +00:00
smbcli_close ( cli - > tree , io . t2open . out . file . fnum ) ;
2003-08-13 01:53:07 +00:00
}
}
2004-11-06 07:58:45 +00:00
smbcli_unlink ( cli - > tree , fname1 ) ;
2004-12-13 10:48:21 +00:00
smbcli_unlink ( cli - > tree , fname2 ) ;
2004-11-06 07:58:45 +00:00
2003-08-13 01:53:07 +00:00
/* check the basic return fields */
io . t2open . in . open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE ;
2004-12-13 10:48:21 +00:00
io . t2open . in . write_time = 0 ;
2004-11-06 07:58:45 +00:00
io . t2open . in . fname = fname ;
2007-12-03 00:28:22 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2003-08-13 01:53:07 +00:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2006-03-12 22:48:25 +00:00
fnum = io . t2open . out . file . fnum ;
2003-08-13 01:53:07 +00:00
CHECK_ALL_INFO ( io . t2open . out . size , size ) ;
2004-12-13 10:48:21 +00:00
#if 0
/* windows appears to leak uninitialised memory here */
2003-08-13 01:53:07 +00:00
CHECK_VAL ( io . t2open . out . write_time , 0 ) ;
2004-12-13 10:48:21 +00:00
# endif
2004-10-21 06:37:15 +00:00
CHECK_ALL_INFO ( io . t2open . out . attrib , attrib & ~ FILE_ATTRIBUTE_NONINDEXED ) ;
2003-08-13 01:53:07 +00:00
CHECK_VAL ( io . t2open . out . access , OPENX_MODE_DENY_NONE | OPENX_MODE_ACCESS_RDWR ) ;
CHECK_VAL ( io . t2open . out . ftype , 0 ) ;
CHECK_VAL ( io . t2open . out . devstate , 0 ) ;
2004-12-13 10:48:21 +00:00
CHECK_VAL ( io . t2open . out . action , OPENX_ACTION_CREATED ) ;
2004-08-04 13:23:35 +00:00
smbcli_close ( cli - > tree , fnum ) ;
2003-08-13 01:53:07 +00:00
2004-12-13 10:48:21 +00:00
status = torture_check_ea ( cli , fname , " .CLASSINFO " , " first value " ) ;
2007-01-03 06:29:22 +00:00
CHECK_STATUS ( status , io . t2open . in . num_eas
? NT_STATUS_OK : NT_STATUS_EAS_NOT_SUPPORTED ) ;
2004-12-13 10:48:21 +00:00
status = torture_check_ea ( cli , fname , " EA TWO " , " foo " ) ;
2007-01-03 06:29:22 +00:00
CHECK_STATUS ( status , io . t2open . in . num_eas
? NT_STATUS_OK : NT_STATUS_EAS_NOT_SUPPORTED ) ;
2004-12-13 10:48:21 +00:00
status = torture_check_ea ( cli , fname , " X THIRD " , " xy " ) ;
2007-01-03 06:29:22 +00:00
CHECK_STATUS ( status , io . t2open . in . num_eas
? NT_STATUS_OK : NT_STATUS_EAS_NOT_SUPPORTED ) ;
2004-12-13 10:48:21 +00:00
2003-08-13 01:53:07 +00:00
/* now check the search attrib for hidden files - win2003 ignores this? */
SET_ATTRIB ( FILE_ATTRIBUTE_HIDDEN ) ;
CHECK_ALL_INFO ( FILE_ATTRIBUTE_HIDDEN , attrib ) ;
2007-12-03 00:28:22 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2003-08-13 01:53:07 +00:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2006-03-12 22:48:25 +00:00
smbcli_close ( cli - > tree , io . t2open . out . file . fnum ) ;
2003-08-13 01:53:07 +00:00
2007-12-03 00:28:22 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2003-08-13 01:53:07 +00:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2006-03-12 22:48:25 +00:00
smbcli_close ( cli - > tree , io . t2open . out . file . fnum ) ;
2003-08-13 01:53:07 +00:00
SET_ATTRIB ( FILE_ATTRIBUTE_NORMAL ) ;
2004-08-04 13:23:35 +00:00
smbcli_unlink ( cli - > tree , fname ) ;
2003-08-13 01:53:07 +00:00
/* and check attrib on create */
io . t2open . in . open_func = OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE ;
io . t2open . in . file_attrs = FILE_ATTRIBUTE_SYSTEM ;
2007-12-03 00:28:22 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2004-12-13 10:48:21 +00:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2003-08-13 01:53:07 +00:00
/* check timeout on create - win2003 ignores the timeout! */
io . t2open . in . open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE ;
io . t2open . in . file_attrs = 0 ;
2004-12-13 10:48:21 +00:00
io . t2open . in . timeout = 20000 ;
2003-08-13 01:53:07 +00:00
io . t2open . in . open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_ALL ;
2007-12-03 00:28:22 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2004-12-13 10:48:21 +00:00
CHECK_STATUS ( status , NT_STATUS_SHARING_VIOLATION ) ;
2003-08-13 01:53:07 +00:00
done :
2004-08-04 13:23:35 +00:00
smbcli_close ( cli - > tree , fnum ) ;
smbcli_unlink ( cli - > tree , fname ) ;
2003-08-13 01:53:07 +00:00
return ret ;
}
/*
test RAW_OPEN_NTCREATEX
*/
2007-12-03 00:28:22 +01:00
static bool test_ntcreatex ( struct smbcli_state * cli , struct torture_context * tctx )
2003-08-13 01:53:07 +00:00
{
union smb_open io ;
union smb_fileinfo finfo ;
const char * fname = BASEDIR " \\ torture_ntcreatex.txt " ;
const char * dname = BASEDIR " \\ torture_ntcreatex.dir " ;
NTSTATUS status ;
2004-08-21 01:54:46 +00:00
int fnum = - 1 ;
2007-10-06 22:28:14 +00:00
bool ret = true ;
2003-08-13 01:53:07 +00:00
int i ;
struct {
2004-05-25 16:24:13 +00:00
uint32_t open_disp ;
2007-10-06 22:28:14 +00:00
bool with_file ;
2003-08-13 01:53:07 +00:00
NTSTATUS correct_status ;
} open_funcs [ ] = {
2007-10-06 22:28:14 +00:00
{ NTCREATEX_DISP_SUPERSEDE , true , NT_STATUS_OK } ,
{ NTCREATEX_DISP_SUPERSEDE , false , NT_STATUS_OK } ,
{ NTCREATEX_DISP_OPEN , true , NT_STATUS_OK } ,
{ NTCREATEX_DISP_OPEN , false , NT_STATUS_OBJECT_NAME_NOT_FOUND } ,
{ NTCREATEX_DISP_CREATE , true , NT_STATUS_OBJECT_NAME_COLLISION } ,
{ NTCREATEX_DISP_CREATE , false , NT_STATUS_OK } ,
{ NTCREATEX_DISP_OPEN_IF , true , NT_STATUS_OK } ,
{ NTCREATEX_DISP_OPEN_IF , false , NT_STATUS_OK } ,
{ NTCREATEX_DISP_OVERWRITE , true , NT_STATUS_OK } ,
{ NTCREATEX_DISP_OVERWRITE , false , NT_STATUS_OBJECT_NAME_NOT_FOUND } ,
{ NTCREATEX_DISP_OVERWRITE_IF , true , NT_STATUS_OK } ,
{ NTCREATEX_DISP_OVERWRITE_IF , false , NT_STATUS_OK } ,
{ 6 , true , NT_STATUS_INVALID_PARAMETER } ,
{ 6 , false , NT_STATUS_INVALID_PARAMETER } ,
2003-08-13 01:53:07 +00:00
} ;
printf ( " Checking RAW_OPEN_NTCREATEX \n " ) ;
/* reasonable default parameters */
io . generic . level = RAW_OPEN_NTCREATEX ;
io . ntcreatex . in . flags = NTCREATEX_FLAGS_EXTENDED ;
io . ntcreatex . in . root_fid = 0 ;
2004-12-02 04:37:36 +00:00
io . ntcreatex . in . access_mask = SEC_RIGHTS_FILE_ALL ;
2003-08-13 01:53:07 +00:00
io . ntcreatex . in . alloc_size = 1024 * 1024 ;
io . ntcreatex . in . file_attr = FILE_ATTRIBUTE_NORMAL ;
io . ntcreatex . in . share_access = NTCREATEX_SHARE_ACCESS_NONE ;
io . ntcreatex . in . open_disposition = NTCREATEX_DISP_CREATE ;
io . ntcreatex . in . create_options = 0 ;
io . ntcreatex . in . impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS ;
io . ntcreatex . in . security_flags = 0 ;
io . ntcreatex . in . fname = fname ;
/* test the open disposition */
for ( i = 0 ; i < ARRAY_SIZE ( open_funcs ) ; i + + ) {
if ( open_funcs [ i ] . with_file ) {
2004-08-04 13:23:35 +00:00
fnum = smbcli_open ( cli - > tree , fname , O_CREAT | O_RDWR | O_TRUNC , DENY_NONE ) ;
2003-08-13 01:53:07 +00:00
if ( fnum = = - 1 ) {
2004-08-04 13:23:35 +00:00
d_printf ( " Failed to create file %s - %s \n " , fname , smbcli_errstr ( cli - > tree ) ) ;
2007-10-06 22:28:14 +00:00
ret = false ;
2003-08-13 01:53:07 +00:00
goto done ;
}
2004-08-04 13:23:35 +00:00
smbcli_close ( cli - > tree , fnum ) ;
2003-08-13 01:53:07 +00:00
}
io . ntcreatex . in . open_disposition = open_funcs [ i ] . open_disp ;
2007-12-03 00:28:22 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2003-08-13 01:53:07 +00:00
if ( ! NT_STATUS_EQUAL ( status , open_funcs [ i ] . correct_status ) ) {
2004-10-21 03:49:17 +00:00
printf ( " (%s) incorrect status %s should be %s (i=%d with_file=%d open_disp=%d) \n " ,
__location__ , nt_errstr ( status ) , nt_errstr ( open_funcs [ i ] . correct_status ) ,
2003-08-13 01:53:07 +00:00
i , ( int ) open_funcs [ i ] . with_file , ( int ) open_funcs [ i ] . open_disp ) ;
2007-10-06 22:28:14 +00:00
ret = false ;
2003-08-13 01:53:07 +00:00
}
if ( NT_STATUS_IS_OK ( status ) | | open_funcs [ i ] . with_file ) {
2006-03-12 22:48:25 +00:00
smbcli_close ( cli - > tree , io . ntcreatex . out . file . fnum ) ;
2004-08-04 13:23:35 +00:00
smbcli_unlink ( cli - > tree , fname ) ;
2003-08-13 01:53:07 +00:00
}
}
/* basic field testing */
io . ntcreatex . in . open_disposition = NTCREATEX_DISP_CREATE ;
2007-12-03 00:28:22 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2003-08-13 01:53:07 +00:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2006-03-12 22:48:25 +00:00
fnum = io . ntcreatex . out . file . fnum ;
2003-08-13 01:53:07 +00:00
CHECK_VAL ( io . ntcreatex . out . oplock_level , 0 ) ;
CHECK_VAL ( io . ntcreatex . out . create_action , NTCREATEX_ACTION_CREATED ) ;
CHECK_NTTIME ( io . ntcreatex . out . create_time , create_time ) ;
CHECK_NTTIME ( io . ntcreatex . out . access_time , access_time ) ;
CHECK_NTTIME ( io . ntcreatex . out . write_time , write_time ) ;
CHECK_NTTIME ( io . ntcreatex . out . change_time , change_time ) ;
CHECK_ALL_INFO ( io . ntcreatex . out . attrib , attrib ) ;
CHECK_ALL_INFO ( io . ntcreatex . out . alloc_size , alloc_size ) ;
CHECK_ALL_INFO ( io . ntcreatex . out . size , size ) ;
CHECK_ALL_INFO ( io . ntcreatex . out . is_directory , directory ) ;
CHECK_VAL ( io . ntcreatex . out . file_type , FILE_TYPE_DISK ) ;
/* check fields when the file already existed */
2004-08-04 13:23:35 +00:00
smbcli_close ( cli - > tree , fnum ) ;
smbcli_unlink ( cli - > tree , fname ) ;
2007-12-03 00:28:22 +01:00
fnum = create_complex_file ( cli , tctx , fname ) ;
2003-08-13 01:53:07 +00:00
if ( fnum = = - 1 ) {
2007-10-06 22:28:14 +00:00
ret = false ;
2003-08-13 01:53:07 +00:00
goto done ;
}
2004-08-04 13:23:35 +00:00
smbcli_close ( cli - > tree , fnum ) ;
2003-08-13 01:53:07 +00:00
io . ntcreatex . in . open_disposition = NTCREATEX_DISP_OPEN ;
2007-12-03 00:28:22 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2003-08-13 01:53:07 +00:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2006-03-12 22:48:25 +00:00
fnum = io . ntcreatex . out . file . fnum ;
2003-08-13 01:53:07 +00:00
CHECK_VAL ( io . ntcreatex . out . oplock_level , 0 ) ;
CHECK_VAL ( io . ntcreatex . out . create_action , NTCREATEX_ACTION_EXISTED ) ;
CHECK_NTTIME ( io . ntcreatex . out . create_time , create_time ) ;
CHECK_NTTIME ( io . ntcreatex . out . access_time , access_time ) ;
CHECK_NTTIME ( io . ntcreatex . out . write_time , write_time ) ;
CHECK_NTTIME ( io . ntcreatex . out . change_time , change_time ) ;
CHECK_ALL_INFO ( io . ntcreatex . out . attrib , attrib ) ;
CHECK_ALL_INFO ( io . ntcreatex . out . alloc_size , alloc_size ) ;
CHECK_ALL_INFO ( io . ntcreatex . out . size , size ) ;
CHECK_ALL_INFO ( io . ntcreatex . out . is_directory , directory ) ;
CHECK_VAL ( io . ntcreatex . out . file_type , FILE_TYPE_DISK ) ;
2004-08-04 13:23:35 +00:00
smbcli_close ( cli - > tree , fnum ) ;
smbcli_unlink ( cli - > tree , fname ) ;
2003-08-13 01:53:07 +00:00
/* create a directory */
io . ntcreatex . in . open_disposition = NTCREATEX_DISP_CREATE ;
2004-12-02 04:37:36 +00:00
io . ntcreatex . in . access_mask = SEC_RIGHTS_FILE_ALL ;
2003-08-13 01:53:07 +00:00
io . ntcreatex . in . alloc_size = 0 ;
io . ntcreatex . in . file_attr = FILE_ATTRIBUTE_DIRECTORY ;
io . ntcreatex . in . share_access = NTCREATEX_SHARE_ACCESS_NONE ;
io . ntcreatex . in . open_disposition = NTCREATEX_DISP_CREATE ;
io . ntcreatex . in . create_options = 0 ;
io . ntcreatex . in . fname = dname ;
fname = dname ;
2004-08-04 13:23:35 +00:00
smbcli_rmdir ( cli - > tree , fname ) ;
smbcli_unlink ( cli - > tree , fname ) ;
2003-08-13 01:53:07 +00:00
2004-12-02 04:37:36 +00:00
io . ntcreatex . in . access_mask = SEC_FLAG_MAXIMUM_ALLOWED ;
2003-08-13 01:53:07 +00:00
io . ntcreatex . in . create_options = NTCREATEX_OPTIONS_DIRECTORY ;
io . ntcreatex . in . file_attr = FILE_ATTRIBUTE_NORMAL ;
io . ntcreatex . in . share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE ;
2007-12-03 00:28:22 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2003-08-13 01:53:07 +00:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2006-03-12 22:48:25 +00:00
fnum = io . ntcreatex . out . file . fnum ;
2003-08-13 01:53:07 +00:00
CHECK_VAL ( io . ntcreatex . out . oplock_level , 0 ) ;
CHECK_VAL ( io . ntcreatex . out . create_action , NTCREATEX_ACTION_CREATED ) ;
CHECK_NTTIME ( io . ntcreatex . out . create_time , create_time ) ;
CHECK_NTTIME ( io . ntcreatex . out . access_time , access_time ) ;
CHECK_NTTIME ( io . ntcreatex . out . write_time , write_time ) ;
CHECK_NTTIME ( io . ntcreatex . out . change_time , change_time ) ;
CHECK_ALL_INFO ( io . ntcreatex . out . attrib , attrib ) ;
2004-10-21 06:37:15 +00:00
CHECK_VAL ( io . ntcreatex . out . attrib & ~ FILE_ATTRIBUTE_NONINDEXED ,
FILE_ATTRIBUTE_DIRECTORY ) ;
2003-08-13 01:53:07 +00:00
CHECK_ALL_INFO ( io . ntcreatex . out . alloc_size , alloc_size ) ;
CHECK_ALL_INFO ( io . ntcreatex . out . size , size ) ;
CHECK_ALL_INFO ( io . ntcreatex . out . is_directory , directory ) ;
CHECK_VAL ( io . ntcreatex . out . is_directory , 1 ) ;
CHECK_VAL ( io . ntcreatex . out . size , 0 ) ;
CHECK_VAL ( io . ntcreatex . out . alloc_size , 0 ) ;
CHECK_VAL ( io . ntcreatex . out . file_type , FILE_TYPE_DISK ) ;
2004-08-04 13:23:35 +00:00
smbcli_unlink ( cli - > tree , fname ) ;
2003-08-13 01:53:07 +00:00
2004-11-17 20:56:26 +00:00
done :
smbcli_close ( cli - > tree , fnum ) ;
smbcli_unlink ( cli - > tree , fname ) ;
return ret ;
}
/*
test RAW_OPEN_NTTRANS_CREATE
*/
2007-12-03 00:28:22 +01:00
static bool test_nttrans_create ( struct smbcli_state * cli , struct torture_context * tctx )
2004-11-17 20:56:26 +00:00
{
union smb_open io ;
union smb_fileinfo finfo ;
const char * fname = BASEDIR " \\ torture_ntcreatex.txt " ;
const char * dname = BASEDIR " \\ torture_ntcreatex.dir " ;
NTSTATUS status ;
int fnum = - 1 ;
2007-10-06 22:28:14 +00:00
bool ret = true ;
2004-11-17 20:56:26 +00:00
int i ;
struct {
uint32_t open_disp ;
2007-10-06 22:28:14 +00:00
bool with_file ;
2004-11-17 20:56:26 +00:00
NTSTATUS correct_status ;
} open_funcs [ ] = {
2007-10-06 22:28:14 +00:00
{ NTCREATEX_DISP_SUPERSEDE , true , NT_STATUS_OK } ,
{ NTCREATEX_DISP_SUPERSEDE , false , NT_STATUS_OK } ,
{ NTCREATEX_DISP_OPEN , true , NT_STATUS_OK } ,
{ NTCREATEX_DISP_OPEN , false , NT_STATUS_OBJECT_NAME_NOT_FOUND } ,
{ NTCREATEX_DISP_CREATE , true , NT_STATUS_OBJECT_NAME_COLLISION } ,
{ NTCREATEX_DISP_CREATE , false , NT_STATUS_OK } ,
{ NTCREATEX_DISP_OPEN_IF , true , NT_STATUS_OK } ,
{ NTCREATEX_DISP_OPEN_IF , false , NT_STATUS_OK } ,
{ NTCREATEX_DISP_OVERWRITE , true , NT_STATUS_OK } ,
{ NTCREATEX_DISP_OVERWRITE , false , NT_STATUS_OBJECT_NAME_NOT_FOUND } ,
{ NTCREATEX_DISP_OVERWRITE_IF , true , NT_STATUS_OK } ,
{ NTCREATEX_DISP_OVERWRITE_IF , false , NT_STATUS_OK } ,
{ 6 , true , NT_STATUS_INVALID_PARAMETER } ,
{ 6 , false , NT_STATUS_INVALID_PARAMETER } ,
2004-11-17 20:56:26 +00:00
} ;
printf ( " Checking RAW_OPEN_NTTRANS_CREATE \n " ) ;
/* reasonable default parameters */
io . generic . level = RAW_OPEN_NTTRANS_CREATE ;
io . ntcreatex . in . flags = NTCREATEX_FLAGS_EXTENDED ;
io . ntcreatex . in . root_fid = 0 ;
2004-12-02 04:37:36 +00:00
io . ntcreatex . in . access_mask = SEC_RIGHTS_FILE_ALL ;
2004-11-17 20:56:26 +00:00
io . ntcreatex . in . alloc_size = 1024 * 1024 ;
io . ntcreatex . in . file_attr = FILE_ATTRIBUTE_NORMAL ;
io . ntcreatex . in . share_access = NTCREATEX_SHARE_ACCESS_NONE ;
io . ntcreatex . in . open_disposition = NTCREATEX_DISP_CREATE ;
io . ntcreatex . in . create_options = 0 ;
io . ntcreatex . in . impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS ;
io . ntcreatex . in . security_flags = 0 ;
io . ntcreatex . in . fname = fname ;
io . ntcreatex . in . sec_desc = NULL ;
io . ntcreatex . in . ea_list = NULL ;
/* test the open disposition */
for ( i = 0 ; i < ARRAY_SIZE ( open_funcs ) ; i + + ) {
if ( open_funcs [ i ] . with_file ) {
fnum = smbcli_open ( cli - > tree , fname , O_CREAT | O_RDWR | O_TRUNC , DENY_NONE ) ;
if ( fnum = = - 1 ) {
d_printf ( " Failed to create file %s - %s \n " , fname , smbcli_errstr ( cli - > tree ) ) ;
2007-10-06 22:28:14 +00:00
ret = false ;
2004-11-17 20:56:26 +00:00
goto done ;
}
smbcli_close ( cli - > tree , fnum ) ;
}
io . ntcreatex . in . open_disposition = open_funcs [ i ] . open_disp ;
2007-12-03 00:28:22 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2004-11-17 20:56:26 +00:00
if ( ! NT_STATUS_EQUAL ( status , open_funcs [ i ] . correct_status ) ) {
printf ( " (%s) incorrect status %s should be %s (i=%d with_file=%d open_disp=%d) \n " ,
__location__ , nt_errstr ( status ) , nt_errstr ( open_funcs [ i ] . correct_status ) ,
i , ( int ) open_funcs [ i ] . with_file , ( int ) open_funcs [ i ] . open_disp ) ;
2007-10-06 22:28:14 +00:00
ret = false ;
2004-11-17 20:56:26 +00:00
}
if ( NT_STATUS_IS_OK ( status ) | | open_funcs [ i ] . with_file ) {
2006-03-12 22:48:25 +00:00
smbcli_close ( cli - > tree , io . ntcreatex . out . file . fnum ) ;
2004-11-17 20:56:26 +00:00
smbcli_unlink ( cli - > tree , fname ) ;
}
}
/* basic field testing */
io . ntcreatex . in . open_disposition = NTCREATEX_DISP_CREATE ;
2007-12-03 00:28:22 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2004-11-17 20:56:26 +00:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2006-03-12 22:48:25 +00:00
fnum = io . ntcreatex . out . file . fnum ;
2004-11-17 20:56:26 +00:00
CHECK_VAL ( io . ntcreatex . out . oplock_level , 0 ) ;
CHECK_VAL ( io . ntcreatex . out . create_action , NTCREATEX_ACTION_CREATED ) ;
CHECK_NTTIME ( io . ntcreatex . out . create_time , create_time ) ;
CHECK_NTTIME ( io . ntcreatex . out . access_time , access_time ) ;
CHECK_NTTIME ( io . ntcreatex . out . write_time , write_time ) ;
CHECK_NTTIME ( io . ntcreatex . out . change_time , change_time ) ;
CHECK_ALL_INFO ( io . ntcreatex . out . attrib , attrib ) ;
CHECK_ALL_INFO ( io . ntcreatex . out . alloc_size , alloc_size ) ;
CHECK_ALL_INFO ( io . ntcreatex . out . size , size ) ;
CHECK_ALL_INFO ( io . ntcreatex . out . is_directory , directory ) ;
CHECK_VAL ( io . ntcreatex . out . file_type , FILE_TYPE_DISK ) ;
/* check fields when the file already existed */
smbcli_close ( cli - > tree , fnum ) ;
smbcli_unlink ( cli - > tree , fname ) ;
2007-12-03 00:28:22 +01:00
fnum = create_complex_file ( cli , tctx , fname ) ;
2004-11-17 20:56:26 +00:00
if ( fnum = = - 1 ) {
2007-10-06 22:28:14 +00:00
ret = false ;
2004-11-17 20:56:26 +00:00
goto done ;
}
smbcli_close ( cli - > tree , fnum ) ;
io . ntcreatex . in . open_disposition = NTCREATEX_DISP_OPEN ;
2007-12-03 00:28:22 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2004-11-17 20:56:26 +00:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2006-03-12 22:48:25 +00:00
fnum = io . ntcreatex . out . file . fnum ;
2004-11-17 20:56:26 +00:00
CHECK_VAL ( io . ntcreatex . out . oplock_level , 0 ) ;
CHECK_VAL ( io . ntcreatex . out . create_action , NTCREATEX_ACTION_EXISTED ) ;
CHECK_NTTIME ( io . ntcreatex . out . create_time , create_time ) ;
CHECK_NTTIME ( io . ntcreatex . out . access_time , access_time ) ;
CHECK_NTTIME ( io . ntcreatex . out . write_time , write_time ) ;
CHECK_NTTIME ( io . ntcreatex . out . change_time , change_time ) ;
CHECK_ALL_INFO ( io . ntcreatex . out . attrib , attrib ) ;
CHECK_ALL_INFO ( io . ntcreatex . out . alloc_size , alloc_size ) ;
CHECK_ALL_INFO ( io . ntcreatex . out . size , size ) ;
CHECK_ALL_INFO ( io . ntcreatex . out . is_directory , directory ) ;
CHECK_VAL ( io . ntcreatex . out . file_type , FILE_TYPE_DISK ) ;
smbcli_close ( cli - > tree , fnum ) ;
smbcli_unlink ( cli - > tree , fname ) ;
/* create a directory */
io . ntcreatex . in . open_disposition = NTCREATEX_DISP_CREATE ;
2004-12-02 04:37:36 +00:00
io . ntcreatex . in . access_mask = SEC_RIGHTS_FILE_ALL ;
2004-11-17 20:56:26 +00:00
io . ntcreatex . in . alloc_size = 0 ;
io . ntcreatex . in . file_attr = FILE_ATTRIBUTE_DIRECTORY ;
io . ntcreatex . in . share_access = NTCREATEX_SHARE_ACCESS_NONE ;
io . ntcreatex . in . open_disposition = NTCREATEX_DISP_CREATE ;
io . ntcreatex . in . create_options = 0 ;
io . ntcreatex . in . fname = dname ;
fname = dname ;
smbcli_rmdir ( cli - > tree , fname ) ;
smbcli_unlink ( cli - > tree , fname ) ;
2004-12-02 04:37:36 +00:00
io . ntcreatex . in . access_mask = SEC_FLAG_MAXIMUM_ALLOWED ;
2004-11-17 20:56:26 +00:00
io . ntcreatex . in . create_options = NTCREATEX_OPTIONS_DIRECTORY ;
io . ntcreatex . in . file_attr = FILE_ATTRIBUTE_NORMAL ;
io . ntcreatex . in . share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE ;
2007-12-03 00:28:22 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2004-11-17 20:56:26 +00:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2006-03-12 22:48:25 +00:00
fnum = io . ntcreatex . out . file . fnum ;
2004-11-17 20:56:26 +00:00
CHECK_VAL ( io . ntcreatex . out . oplock_level , 0 ) ;
CHECK_VAL ( io . ntcreatex . out . create_action , NTCREATEX_ACTION_CREATED ) ;
CHECK_NTTIME ( io . ntcreatex . out . create_time , create_time ) ;
CHECK_NTTIME ( io . ntcreatex . out . access_time , access_time ) ;
CHECK_NTTIME ( io . ntcreatex . out . write_time , write_time ) ;
CHECK_NTTIME ( io . ntcreatex . out . change_time , change_time ) ;
CHECK_ALL_INFO ( io . ntcreatex . out . attrib , attrib ) ;
CHECK_VAL ( io . ntcreatex . out . attrib & ~ FILE_ATTRIBUTE_NONINDEXED ,
FILE_ATTRIBUTE_DIRECTORY ) ;
CHECK_ALL_INFO ( io . ntcreatex . out . alloc_size , alloc_size ) ;
CHECK_ALL_INFO ( io . ntcreatex . out . size , size ) ;
CHECK_ALL_INFO ( io . ntcreatex . out . is_directory , directory ) ;
CHECK_VAL ( io . ntcreatex . out . is_directory , 1 ) ;
CHECK_VAL ( io . ntcreatex . out . size , 0 ) ;
CHECK_VAL ( io . ntcreatex . out . alloc_size , 0 ) ;
CHECK_VAL ( io . ntcreatex . out . file_type , FILE_TYPE_DISK ) ;
smbcli_unlink ( cli - > tree , fname ) ;
2003-08-13 01:53:07 +00:00
done :
2004-08-04 13:23:35 +00:00
smbcli_close ( cli - > tree , fnum ) ;
smbcli_unlink ( cli - > tree , fname ) ;
2003-08-13 01:53:07 +00:00
return ret ;
}
2004-05-14 22:07:43 +00:00
/*
test RAW_OPEN_NTCREATEX with an already opened and byte range locked file
I ' ve got an application that does a similar sequence of ntcreate & x ,
locking & x and another ntcreate & x with
open_disposition = = NTCREATEX_DISP_OVERWRITE_IF . Windows 2003 allows the
second open .
*/
2007-12-03 00:28:22 +01:00
static bool test_ntcreatex_brlocked ( struct smbcli_state * cli , struct torture_context * tctx )
2004-05-14 22:07:43 +00:00
{
union smb_open io , io1 ;
union smb_lock io2 ;
struct smb_lock_entry lock [ 1 ] ;
const char * fname = BASEDIR " \\ torture_ntcreatex.txt " ;
NTSTATUS status ;
2007-10-06 22:28:14 +00:00
bool ret = true ;
2004-05-14 22:07:43 +00:00
2005-08-04 04:21:03 +00:00
printf ( " Testing ntcreatex with a byte range locked file \n " ) ;
2004-05-14 22:07:43 +00:00
io . generic . level = RAW_OPEN_NTCREATEX ;
io . ntcreatex . in . flags = NTCREATEX_FLAGS_EXTENDED ;
io . ntcreatex . in . root_fid = 0 ;
io . ntcreatex . in . access_mask = 0x2019f ;
io . ntcreatex . in . alloc_size = 0 ;
io . ntcreatex . in . file_attr = FILE_ATTRIBUTE_NORMAL ;
io . ntcreatex . in . share_access = NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE ;
io . ntcreatex . in . open_disposition = NTCREATEX_DISP_CREATE ;
io . ntcreatex . in . create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE ;
io . ntcreatex . in . impersonation = NTCREATEX_IMPERSONATION_IMPERSONATION ;
io . ntcreatex . in . security_flags = NTCREATEX_SECURITY_DYNAMIC |
NTCREATEX_SECURITY_ALL ;
io . ntcreatex . in . fname = fname ;
2007-12-03 00:28:22 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2004-05-14 22:07:43 +00:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
io2 . lockx . level = RAW_LOCK_LOCKX ;
2006-03-12 22:48:25 +00:00
io2 . lockx . in . file . fnum = io . ntcreatex . out . file . fnum ;
2004-05-14 22:07:43 +00:00
io2 . lockx . in . mode = LOCKING_ANDX_LARGE_FILES ;
io2 . lockx . in . timeout = 0 ;
io2 . lockx . in . ulock_cnt = 0 ;
io2 . lockx . in . lock_cnt = 1 ;
lock [ 0 ] . pid = cli - > session - > pid ;
lock [ 0 ] . offset = 0 ;
lock [ 0 ] . count = 0x1 ;
io2 . lockx . in . locks = & lock [ 0 ] ;
status = smb_raw_lock ( cli - > tree , & io2 ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
io1 . generic . level = RAW_OPEN_NTCREATEX ;
io1 . ntcreatex . in . flags = NTCREATEX_FLAGS_EXTENDED ;
io1 . ntcreatex . in . root_fid = 0 ;
io1 . ntcreatex . in . access_mask = 0x20196 ;
io1 . ntcreatex . in . alloc_size = 0 ;
io1 . ntcreatex . in . file_attr = FILE_ATTRIBUTE_NORMAL ;
io1 . ntcreatex . in . share_access = NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE ;
io1 . ntcreatex . in . open_disposition = NTCREATEX_DISP_OVERWRITE_IF ;
io1 . ntcreatex . in . create_options = 0 ;
io1 . ntcreatex . in . impersonation = NTCREATEX_IMPERSONATION_IMPERSONATION ;
io1 . ntcreatex . in . security_flags = NTCREATEX_SECURITY_DYNAMIC |
NTCREATEX_SECURITY_ALL ;
io1 . ntcreatex . in . fname = fname ;
2007-12-03 00:28:22 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io1 ) ;
2004-05-14 22:07:43 +00:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
done :
2006-03-12 22:48:25 +00:00
smbcli_close ( cli - > tree , io . ntcreatex . out . file . fnum ) ;
smbcli_close ( cli - > tree , io1 . ntcreatex . out . file . fnum ) ;
2004-08-04 13:23:35 +00:00
smbcli_unlink ( cli - > tree , fname ) ;
2004-05-14 22:07:43 +00:00
return ret ;
}
2003-08-13 01:53:07 +00:00
/*
test RAW_OPEN_MKNEW
*/
2007-12-03 00:28:22 +01:00
static bool test_mknew ( struct smbcli_state * cli , struct torture_context * tctx )
2003-08-13 01:53:07 +00:00
{
union smb_open io ;
const char * fname = BASEDIR " \\ torture_mknew.txt " ;
NTSTATUS status ;
2004-08-21 01:54:46 +00:00
int fnum = - 1 ;
2007-10-06 22:28:14 +00:00
bool ret = true ;
2003-08-13 01:53:07 +00:00
time_t basetime = ( time ( NULL ) + 3600 * 24 * 3 ) & ~ 1 ;
union smb_fileinfo finfo ;
printf ( " Checking RAW_OPEN_MKNEW \n " ) ;
io . mknew . level = RAW_OPEN_MKNEW ;
io . mknew . in . attrib = 0 ;
io . mknew . in . write_time = 0 ;
io . mknew . in . fname = fname ;
2007-12-03 00:28:22 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2003-08-13 01:53:07 +00:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2006-03-12 22:48:25 +00:00
fnum = io . mknew . out . file . fnum ;
2003-08-13 01:53:07 +00:00
2007-12-03 00:28:22 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2003-08-13 01:53:07 +00:00
CHECK_STATUS ( status , NT_STATUS_OBJECT_NAME_COLLISION ) ;
2004-08-04 13:23:35 +00:00
smbcli_close ( cli - > tree , fnum ) ;
smbcli_unlink ( cli - > tree , fname ) ;
2003-08-13 01:53:07 +00:00
/* make sure write_time works */
io . mknew . in . write_time = basetime ;
2007-12-03 00:28:22 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2003-08-13 01:53:07 +00:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2006-03-12 22:48:25 +00:00
fnum = io . mknew . out . file . fnum ;
2003-08-13 01:53:07 +00:00
CHECK_TIME ( basetime , write_time ) ;
2004-08-04 13:23:35 +00:00
smbcli_close ( cli - > tree , fnum ) ;
smbcli_unlink ( cli - > tree , fname ) ;
2003-08-13 01:53:07 +00:00
/* make sure file_attrs works */
io . mknew . in . attrib = FILE_ATTRIBUTE_HIDDEN ;
2007-12-03 00:28:22 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2003-08-13 01:53:07 +00:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2006-03-12 22:48:25 +00:00
fnum = io . mknew . out . file . fnum ;
2004-10-21 06:37:15 +00:00
CHECK_ALL_INFO ( FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_ARCHIVE ,
attrib & ~ FILE_ATTRIBUTE_NONINDEXED ) ;
2003-08-13 01:53:07 +00:00
done :
2004-08-04 13:23:35 +00:00
smbcli_close ( cli - > tree , fnum ) ;
smbcli_unlink ( cli - > tree , fname ) ;
2003-08-13 01:53:07 +00:00
return ret ;
}
2003-08-14 01:31:31 +00:00
/*
test RAW_OPEN_CREATE
*/
2007-12-03 00:28:22 +01:00
static bool test_create ( struct smbcli_state * cli , struct torture_context * tctx )
2003-08-14 01:31:31 +00:00
{
union smb_open io ;
const char * fname = BASEDIR " \\ torture_create.txt " ;
NTSTATUS status ;
2004-08-21 01:54:46 +00:00
int fnum = - 1 ;
2007-10-06 22:28:14 +00:00
bool ret = true ;
2003-08-14 01:31:31 +00:00
time_t basetime = ( time ( NULL ) + 3600 * 24 * 3 ) & ~ 1 ;
union smb_fileinfo finfo ;
printf ( " Checking RAW_OPEN_CREATE \n " ) ;
io . create . level = RAW_OPEN_CREATE ;
io . create . in . attrib = 0 ;
io . create . in . write_time = 0 ;
io . create . in . fname = fname ;
2007-12-03 00:28:22 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2003-08-14 01:31:31 +00:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2006-03-12 22:48:25 +00:00
fnum = io . create . out . file . fnum ;
2003-08-14 01:31:31 +00:00
2007-12-03 00:28:22 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2003-08-14 01:31:31 +00:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2006-03-12 22:48:25 +00:00
smbcli_close ( cli - > tree , io . create . out . file . fnum ) ;
2004-08-04 13:23:35 +00:00
smbcli_close ( cli - > tree , fnum ) ;
smbcli_unlink ( cli - > tree , fname ) ;
2003-08-14 01:31:31 +00:00
/* make sure write_time works */
io . create . in . write_time = basetime ;
2007-12-03 00:28:22 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2003-08-14 01:31:31 +00:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2006-03-12 22:48:25 +00:00
fnum = io . create . out . file . fnum ;
2003-08-14 01:31:31 +00:00
CHECK_TIME ( basetime , write_time ) ;
2004-08-04 13:23:35 +00:00
smbcli_close ( cli - > tree , fnum ) ;
smbcli_unlink ( cli - > tree , fname ) ;
2003-08-14 01:31:31 +00:00
/* make sure file_attrs works */
io . create . in . attrib = FILE_ATTRIBUTE_HIDDEN ;
2007-12-03 00:28:22 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2003-08-14 01:31:31 +00:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2006-03-12 22:48:25 +00:00
fnum = io . create . out . file . fnum ;
2004-10-21 06:37:15 +00:00
CHECK_ALL_INFO ( FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_ARCHIVE ,
attrib & ~ FILE_ATTRIBUTE_NONINDEXED ) ;
2003-08-14 01:31:31 +00:00
done :
2004-08-04 13:23:35 +00:00
smbcli_close ( cli - > tree , fnum ) ;
smbcli_unlink ( cli - > tree , fname ) ;
2003-08-14 01:31:31 +00:00
return ret ;
}
2003-08-13 01:53:07 +00:00
/*
test RAW_OPEN_CTEMP
*/
2007-12-03 00:28:22 +01:00
static bool test_ctemp ( struct smbcli_state * cli , TALLOC_CTX * tctx )
2003-08-13 01:53:07 +00:00
{
union smb_open io ;
NTSTATUS status ;
2004-08-21 01:54:46 +00:00
int fnum = - 1 ;
2007-10-06 22:28:14 +00:00
bool ret = true ;
2003-08-13 01:53:07 +00:00
time_t basetime = ( time ( NULL ) + 3600 * 24 * 3 ) & ~ 1 ;
union smb_fileinfo finfo ;
const char * name , * fname = NULL ;
printf ( " Checking RAW_OPEN_CTEMP \n " ) ;
io . ctemp . level = RAW_OPEN_CTEMP ;
io . ctemp . in . attrib = FILE_ATTRIBUTE_HIDDEN ;
io . ctemp . in . write_time = basetime ;
io . ctemp . in . directory = BASEDIR ;
2007-12-03 00:28:22 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2003-08-13 01:53:07 +00:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2006-03-12 22:48:25 +00:00
fnum = io . ctemp . out . file . fnum ;
2003-08-13 01:53:07 +00:00
name = io . ctemp . out . name ;
finfo . generic . level = RAW_FILEINFO_NAME_INFO ;
2006-03-12 22:48:25 +00:00
finfo . generic . in . file . fnum = fnum ;
2007-12-03 00:28:22 +01:00
status = smb_raw_fileinfo ( cli - > tree , tctx , & finfo ) ;
2003-08-13 01:53:07 +00:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
fname = finfo . name_info . out . fname . s ;
d_printf ( " ctemp name=%s real name=%s \n " , name , fname ) ;
done :
2004-08-04 13:23:35 +00:00
smbcli_close ( cli - > tree , fnum ) ;
2003-08-13 01:53:07 +00:00
if ( fname ) {
2004-08-04 13:23:35 +00:00
smbcli_unlink ( cli - > tree , fname ) ;
2003-08-13 01:53:07 +00:00
}
return ret ;
}
2004-12-26 08:13:01 +00:00
/*
test chained RAW_OPEN_OPENX_READX
*/
2007-12-03 00:28:22 +01:00
static bool test_chained ( struct smbcli_state * cli , TALLOC_CTX * tctx )
2004-12-26 08:13:01 +00:00
{
union smb_open io ;
const char * fname = BASEDIR " \\ torture_chained.txt " ;
NTSTATUS status ;
int fnum = - 1 ;
2007-10-06 22:28:14 +00:00
bool ret = true ;
2004-12-26 08:13:01 +00:00
const char * buf = " test " ;
char buf2 [ 4 ] ;
printf ( " Checking RAW_OPEN_OPENX chained with READX \n " ) ;
smbcli_unlink ( cli - > tree , fname ) ;
2007-12-03 00:28:22 +01:00
fnum = create_complex_file ( cli , tctx , fname ) ;
2004-12-26 08:13:01 +00:00
smbcli_write ( cli - > tree , fnum , 0 , buf , 0 , sizeof ( buf ) ) ;
smbcli_close ( cli - > tree , fnum ) ;
io . openxreadx . level = RAW_OPEN_OPENX_READX ;
io . openxreadx . in . fname = fname ;
io . openxreadx . in . flags = OPENX_FLAGS_ADDITIONAL_INFO ;
io . openxreadx . in . open_mode = OPENX_MODE_ACCESS_RDWR ;
io . openxreadx . in . open_func = OPENX_OPEN_FUNC_OPEN ;
io . openxreadx . in . search_attrs = 0 ;
io . openxreadx . in . file_attrs = 0 ;
io . openxreadx . in . write_time = 0 ;
io . openxreadx . in . size = 1024 * 1024 ;
io . openxreadx . in . timeout = 0 ;
io . openxreadx . in . offset = 0 ;
io . openxreadx . in . mincnt = sizeof ( buf ) ;
io . openxreadx . in . maxcnt = sizeof ( buf ) ;
io . openxreadx . in . remaining = 0 ;
2006-01-18 16:20:33 +00:00
io . openxreadx . out . data = ( uint8_t * ) buf2 ;
2004-12-26 08:13:01 +00:00
2007-12-03 00:28:22 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2004-12-26 08:13:01 +00:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2006-03-12 22:48:25 +00:00
fnum = io . openxreadx . out . file . fnum ;
2004-12-26 08:13:01 +00:00
if ( memcmp ( buf , buf2 , sizeof ( buf ) ) ! = 0 ) {
d_printf ( " wrong data in reply buffer \n " ) ;
2007-10-06 22:28:14 +00:00
ret = false ;
2004-12-26 08:13:01 +00:00
}
done :
smbcli_close ( cli - > tree , fnum ) ;
smbcli_unlink ( cli - > tree , fname ) ;
return ret ;
}
2006-09-05 18:39:48 +00:00
/*
test RAW_OPEN_OPENX without a leading slash on the path .
NetApp filers are known to fail on this .
*/
2007-12-03 00:28:22 +01:00
static bool test_no_leading_slash ( struct smbcli_state * cli , TALLOC_CTX * tctx )
2006-09-05 18:39:48 +00:00
{
union smb_open io ;
const char * fname = BASEDIR " \\ torture_no_leading_slash.txt " ;
NTSTATUS status ;
int fnum = - 1 ;
2007-10-06 22:28:14 +00:00
bool ret = true ;
2006-09-05 18:39:48 +00:00
const char * buf = " test " ;
printf ( " Checking RAW_OPEN_OPENX without leading slash on path \n " ) ;
smbcli_unlink ( cli - > tree , fname ) ;
/* Create the file */
2007-12-03 00:28:22 +01:00
fnum = create_complex_file ( cli , tctx , fname ) ;
2006-09-05 18:39:48 +00:00
smbcli_write ( cli - > tree , fnum , 0 , buf , 0 , sizeof ( buf ) ) ;
smbcli_close ( cli - > tree , fnum ) ;
/* Prepare to open the file using path without leading slash */
io . openx . level = RAW_OPEN_OPENX ;
io . openx . in . fname = fname + 1 ;
io . openx . in . flags = OPENX_FLAGS_ADDITIONAL_INFO ;
io . openx . in . open_mode = OPENX_MODE_ACCESS_RDWR ;
io . openx . in . open_func = OPENX_OPEN_FUNC_OPEN ;
io . openx . in . search_attrs = 0 ;
io . openx . in . file_attrs = 0 ;
io . openx . in . write_time = 0 ;
io . openx . in . size = 1024 * 1024 ;
io . openx . in . timeout = 0 ;
2007-12-03 00:28:22 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2006-09-05 18:39:48 +00:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
fnum = io . openx . out . file . fnum ;
done :
smbcli_close ( cli - > tree , fnum ) ;
smbcli_unlink ( cli - > tree , fname ) ;
return ret ;
}
2005-08-24 13:15:01 +00:00
/* A little torture test to expose a race condition in Samba 3.0.20 ... :-) */
2007-12-03 00:28:22 +01:00
static bool test_raw_open_multi ( struct torture_context * tctx )
2005-08-24 13:15:01 +00:00
{
struct smbcli_state * cli ;
TALLOC_CTX * mem_ctx = talloc_init ( " torture_test_oplock_multi " ) ;
const char * fname = " \\ test_oplock.dat " ;
NTSTATUS status ;
2007-10-06 22:28:14 +00:00
bool ret = true ;
2005-08-24 13:15:01 +00:00
union smb_open io ;
struct smbcli_state * * clients ;
struct smbcli_request * * requests ;
union smb_open * ios ;
2007-12-03 00:28:22 +01:00
const char * host = torture_setting_string ( tctx , " host " , NULL ) ;
const char * share = torture_setting_string ( tctx , " share " , NULL ) ;
2005-08-24 13:15:01 +00:00
int i , num_files = 3 ;
struct event_context * ev ;
int num_ok = 0 ;
int num_collision = 0 ;
2007-05-17 08:47:04 +00:00
ev = cli_credentials_get_event_context ( cmdline_credentials ) ;
2005-08-24 13:15:01 +00:00
clients = talloc_array ( mem_ctx , struct smbcli_state * , num_files ) ;
requests = talloc_array ( mem_ctx , struct smbcli_request * , num_files ) ;
ios = talloc_array ( mem_ctx , union smb_open , num_files ) ;
if ( ( ev = = NULL ) | | ( clients = = NULL ) | | ( requests = = NULL ) | |
( ios = = NULL ) ) {
DEBUG ( 0 , ( " talloc failed \n " ) ) ;
2007-10-06 22:28:14 +00:00
return false ;
2005-08-24 13:15:01 +00:00
}
2007-12-03 15:53:07 +01:00
if ( ! torture_open_connection_share ( mem_ctx , & cli , tctx , host , share , ev ) ) {
2007-10-06 22:28:14 +00:00
return false ;
2005-08-24 13:15:01 +00:00
}
2008-01-25 17:27:17 +11:00
cli - > tree - > session - > transport - > options . request_timeout = 60 ;
2005-08-24 13:15:01 +00:00
for ( i = 0 ; i < num_files ; i + + ) {
if ( ! torture_open_connection_share ( mem_ctx , & ( clients [ i ] ) ,
2007-12-03 15:53:07 +01:00
tctx , host , share , ev ) ) {
2005-08-24 13:15:01 +00:00
DEBUG ( 0 , ( " Could not open %d'th connection \n " , i ) ) ;
2007-10-06 22:28:14 +00:00
return false ;
2005-08-24 13:15:01 +00:00
}
2008-01-25 17:27:17 +11:00
clients [ i ] - > tree - > session - > transport - > options . request_timeout = 60 ;
2005-08-24 13:15:01 +00:00
}
/* cleanup */
smbcli_unlink ( cli - > tree , fname ) ;
/*
base ntcreatex parms
*/
io . generic . level = RAW_OPEN_NTCREATEX ;
io . ntcreatex . in . root_fid = 0 ;
io . ntcreatex . in . access_mask = SEC_RIGHTS_FILE_ALL ;
io . ntcreatex . in . alloc_size = 0 ;
io . ntcreatex . in . file_attr = FILE_ATTRIBUTE_NORMAL ;
io . ntcreatex . in . share_access = NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE |
NTCREATEX_SHARE_ACCESS_DELETE ;
io . ntcreatex . in . open_disposition = NTCREATEX_DISP_CREATE ;
io . ntcreatex . in . create_options = 0 ;
io . ntcreatex . in . impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS ;
io . ntcreatex . in . security_flags = 0 ;
io . ntcreatex . in . fname = fname ;
io . ntcreatex . in . flags = 0 ;
for ( i = 0 ; i < num_files ; i + + ) {
ios [ i ] = io ;
requests [ i ] = smb_raw_open_send ( clients [ i ] - > tree , & ios [ i ] ) ;
if ( requests [ i ] = = NULL ) {
DEBUG ( 0 , ( " could not send %d'th request \n " , i ) ) ;
2007-10-06 22:28:14 +00:00
return false ;
2005-08-24 13:15:01 +00:00
}
}
DEBUG ( 10 , ( " waiting for replies \n " ) ) ;
while ( 1 ) {
2007-10-06 22:28:14 +00:00
bool unreplied = false ;
2005-08-24 13:15:01 +00:00
for ( i = 0 ; i < num_files ; i + + ) {
if ( requests [ i ] = = NULL ) {
continue ;
}
if ( requests [ i ] - > state < SMBCLI_REQUEST_DONE ) {
2007-10-06 22:28:14 +00:00
unreplied = true ;
2005-08-24 13:15:01 +00:00
break ;
}
status = smb_raw_open_recv ( requests [ i ] , mem_ctx ,
& ios [ i ] ) ;
DEBUG ( 0 , ( " File %d returned status %s \n " , i ,
nt_errstr ( status ) ) ) ;
if ( NT_STATUS_IS_OK ( status ) ) {
num_ok + = 1 ;
}
if ( NT_STATUS_EQUAL ( status ,
NT_STATUS_OBJECT_NAME_COLLISION ) ) {
num_collision + = 1 ;
}
requests [ i ] = NULL ;
}
if ( ! unreplied ) {
break ;
}
if ( event_loop_once ( ev ) ! = 0 ) {
DEBUG ( 0 , ( " event_loop_once failed \n " ) ) ;
2007-10-06 22:28:14 +00:00
return false ;
2005-08-24 13:15:01 +00:00
}
}
if ( ( num_ok ! = 1 ) | | ( num_ok + num_collision ! = num_files ) ) {
2007-10-06 22:28:14 +00:00
ret = false ;
2005-08-24 13:15:01 +00:00
}
for ( i = 0 ; i < num_files ; i + + ) {
torture_close_connection ( clients [ i ] ) ;
}
talloc_free ( mem_ctx ) ;
return ret ;
}
2004-12-26 08:13:01 +00:00
2003-08-13 01:53:07 +00:00
/* basic testing of all RAW_OPEN_* calls
*/
2007-08-28 12:54:27 +00:00
bool torture_raw_open ( struct torture_context * torture , struct smbcli_state * cli )
2003-08-13 01:53:07 +00:00
{
2007-08-28 12:54:27 +00:00
bool ret = true ;
2003-08-13 01:53:07 +00:00
2004-11-12 09:37:59 +00:00
if ( ! torture_setup_dir ( cli , BASEDIR ) ) {
2007-08-28 12:54:27 +00:00
return false ;
2003-08-13 01:53:07 +00:00
}
2007-08-28 12:54:27 +00:00
ret & = test_ntcreatex_brlocked ( cli , torture ) ;
ret & = test_open ( cli , torture ) ;
2007-12-03 00:28:22 +01:00
ret & = test_raw_open_multi ( torture ) ;
2007-08-28 12:54:27 +00:00
ret & = test_openx ( cli , torture ) ;
ret & = test_ntcreatex ( cli , torture ) ;
ret & = test_nttrans_create ( cli , torture ) ;
ret & = test_t2open ( cli , torture ) ;
ret & = test_mknew ( cli , torture ) ;
ret & = test_create ( cli , torture ) ;
ret & = test_ctemp ( cli , torture ) ;
ret & = test_chained ( cli , torture ) ;
ret & = test_no_leading_slash ( cli , torture ) ;
2003-08-13 01:53:07 +00:00
smb_raw_exit ( cli - > session ) ;
2004-08-04 13:23:35 +00:00
smbcli_deltree ( cli - > tree , BASEDIR ) ;
2003-08-13 01:53:07 +00:00
return ret ;
}