2003-08-13 05:53:07 +04:00
/*
Unix SMB / CIFS implementation .
RAW_CLOSE_ * 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 06:07:03 +04:00
the Free Software Foundation ; either version 3 of the License , or
2003-08-13 05:53:07 +04:00
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
2007-07-10 06:07:03 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2003-08-13 05:53:07 +04:00
*/
# include "includes.h"
2006-01-03 16:41:17 +03:00
# include "torture/torture.h"
2004-11-02 03:24:21 +03:00
# include "system/time.h"
2005-12-28 18:38:36 +03:00
# include "libcli/raw/libcliraw.h"
2008-04-02 06:53:27 +04:00
# include "libcli/raw/raw_proto.h"
2006-01-03 18:40:05 +03:00
# include "libcli/libcli.h"
2006-03-17 20:59:58 +03:00
# include "torture/util.h"
2011-03-19 02:42:42 +03:00
# include "torture/raw/proto.h"
2003-08-13 05:53:07 +04:00
2007-08-28 16:54:27 +04:00
/**
* basic testing of all RAW_CLOSE_ * calls
2003-08-13 05:53:07 +04:00
*/
2007-08-28 16:54:27 +04:00
bool torture_raw_close ( struct torture_context * torture ,
2007-09-07 19:08:14 +04:00
struct smbcli_state * cli )
2003-08-13 05:53:07 +04:00
{
2007-08-28 16:54:27 +04:00
bool ret = true ;
2003-08-13 05:53:07 +04:00
union smb_close io ;
2006-03-10 23:49:20 +03:00
union smb_flush io_flush ;
2003-08-13 05:53:07 +04:00
int fnum ;
const char * fname = " \\ torture_close.txt " ;
time_t basetime = ( time ( NULL ) + 3 * 86400 ) & ~ 1 ;
union smb_fileinfo finfo , finfo2 ;
NTSTATUS status ;
# define REOPEN do { \
2007-08-28 16:54:27 +04:00
fnum = create_complex_file ( cli , torture , fname ) ; \
2003-08-13 05:53:07 +04:00
if ( fnum = = - 1 ) { \
printf ( " (%d) Failed to create %s \n " , __LINE__ , fname ) ; \
2007-08-28 16:54:27 +04:00
ret = false ; \
2003-08-13 05:53:07 +04:00
goto done ; \
} } while ( 0 )
# define CHECK_STATUS(status, correct) do { \
if ( ! NT_STATUS_EQUAL ( status , correct ) ) { \
printf ( " (%d) Incorrect status %s - should be %s \n " , \
__LINE__ , nt_errstr ( status ) , nt_errstr ( correct ) ) ; \
2007-08-28 16:54:27 +04:00
ret = false ; \
2003-08-13 05:53:07 +04:00
goto done ; \
} } while ( 0 )
REOPEN ;
io . close . level = RAW_CLOSE_CLOSE ;
2006-03-13 01:48:25 +03:00
io . close . in . file . fnum = fnum ;
2003-08-13 05:53:07 +04:00
io . close . in . write_time = basetime ;
status = smb_raw_close ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
status = smb_raw_close ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_INVALID_HANDLE ) ;
2010-04-11 03:39:06 +04:00
printf ( " Testing close.in.write_time \n " ) ;
2003-08-13 05:53:07 +04:00
/* the file should have the write time set */
finfo . generic . level = RAW_FILEINFO_ALL_INFO ;
2006-03-13 01:48:25 +03:00
finfo . generic . in . file . path = fname ;
2007-08-28 16:54:27 +04:00
status = smb_raw_pathinfo ( cli - > tree , torture , & finfo ) ;
2003-08-13 05:53:07 +04:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2004-05-25 17:57:39 +04:00
if ( basetime ! = nt_time_to_unix ( finfo . all_info . out . write_time ) ) {
2003-08-13 05:53:07 +04:00
printf ( " Incorrect write time on file - %s - %s \n " ,
2007-08-28 16:54:27 +04:00
timestring ( torture , basetime ) ,
nt_time_string ( torture , finfo . all_info . out . write_time ) ) ;
dump_all_info ( torture , & finfo ) ;
ret = false ;
2003-08-13 05:53:07 +04:00
}
2010-04-11 03:39:06 +04:00
printf ( " Testing other times \n " ) ;
2003-08-13 05:53:07 +04:00
/* none of the other times should be set to that time */
if ( nt_time_equal ( & finfo . all_info . out . write_time ,
& finfo . all_info . out . access_time ) | |
nt_time_equal ( & finfo . all_info . out . write_time ,
& finfo . all_info . out . create_time ) | |
nt_time_equal ( & finfo . all_info . out . write_time ,
& finfo . all_info . out . change_time ) ) {
printf ( " Incorrect times after close - only write time should be set \n " ) ;
2007-08-28 16:54:27 +04:00
dump_all_info ( torture , & finfo ) ;
2007-01-02 19:18:51 +03:00
2007-08-28 04:16:58 +04:00
if ( ! torture_setting_bool ( torture , " samba3 " , false ) ) {
2007-01-02 19:18:51 +03:00
/*
* In Samba3 as of 3.0 .23 d we don ' t yet support all
* file times , so don ' t mark this as a critical
* failure
*/
2007-08-28 04:16:58 +04:00
ret = false ;
2007-01-02 19:18:51 +03:00
}
2003-08-13 05:53:07 +04:00
}
2004-08-04 17:23:35 +04:00
smbcli_unlink ( cli - > tree , fname ) ;
2003-08-13 05:53:07 +04:00
REOPEN ;
finfo2 . generic . level = RAW_FILEINFO_ALL_INFO ;
2006-03-13 01:48:25 +03:00
finfo2 . generic . in . file . path = fname ;
2007-08-28 16:54:27 +04:00
status = smb_raw_pathinfo ( cli - > tree , torture , & finfo2 ) ;
2003-08-13 05:53:07 +04:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
io . close . level = RAW_CLOSE_CLOSE ;
2006-03-13 01:48:25 +03:00
io . close . in . file . fnum = fnum ;
2003-08-13 05:53:07 +04:00
io . close . in . write_time = 0 ;
status = smb_raw_close ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
/* the file should have the write time set equal to access time */
finfo . generic . level = RAW_FILEINFO_ALL_INFO ;
2006-03-13 01:48:25 +03:00
finfo . generic . in . file . path = fname ;
2007-08-28 16:54:27 +04:00
status = smb_raw_pathinfo ( cli - > tree , torture , & finfo ) ;
2003-08-13 05:53:07 +04:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
if ( ! nt_time_equal ( & finfo . all_info . out . write_time ,
& finfo2 . all_info . out . write_time ) ) {
printf ( " Incorrect write time on file - 0 time should be ignored \n " ) ;
2007-08-28 16:54:27 +04:00
dump_all_info ( torture , & finfo ) ;
ret = false ;
2003-08-13 05:53:07 +04:00
}
2010-04-11 03:39:06 +04:00
printf ( " Testing splclose \n " ) ;
2003-08-13 05:53:07 +04:00
/* check splclose on a file */
REOPEN ;
io . splclose . level = RAW_CLOSE_SPLCLOSE ;
2006-03-13 01:48:25 +03:00
io . splclose . in . file . fnum = fnum ;
2003-08-13 05:53:07 +04:00
status = smb_raw_close ( cli - > tree , & io ) ;
2005-07-04 09:24:39 +04:00
CHECK_STATUS ( status , NT_STATUS_DOS ( ERRSRV , ERRerror ) ) ;
2003-08-13 05:53:07 +04:00
2010-04-11 03:39:06 +04:00
printf ( " Testing flush \n " ) ;
2004-08-04 17:23:35 +04:00
smbcli_close ( cli - > tree , fnum ) ;
2003-08-13 05:53:07 +04:00
2006-05-19 19:10:39 +04:00
io_flush . flush . level = RAW_FLUSH_FLUSH ;
io_flush . flush . in . file . fnum = fnum ;
2003-08-13 05:53:07 +04:00
status = smb_raw_flush ( cli - > tree , & io_flush ) ;
CHECK_STATUS ( status , NT_STATUS_INVALID_HANDLE ) ;
2006-05-19 19:10:39 +04:00
io_flush . flush_all . level = RAW_FLUSH_ALL ;
2003-08-13 05:53:07 +04:00
status = smb_raw_flush ( cli - > tree , & io_flush ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
REOPEN ;
2006-05-19 19:10:39 +04:00
io_flush . flush . level = RAW_FLUSH_FLUSH ;
io_flush . flush . in . file . fnum = fnum ;
2003-08-13 05:53:07 +04:00
status = smb_raw_flush ( cli - > tree , & io_flush ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
printf ( " Testing SMBexit \n " ) ;
smb_raw_exit ( cli - > session ) ;
2006-05-19 19:10:39 +04:00
io_flush . flush . level = RAW_FLUSH_FLUSH ;
io_flush . flush . in . file . fnum = fnum ;
2003-08-13 05:53:07 +04:00
status = smb_raw_flush ( cli - > tree , & io_flush ) ;
CHECK_STATUS ( status , NT_STATUS_INVALID_HANDLE ) ;
done :
2004-08-04 17:23:35 +04:00
smbcli_close ( cli - > tree , fnum ) ;
smbcli_unlink ( cli - > tree , fname ) ;
2003-08-13 05:53:07 +04:00
return ret ;
}