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
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"
/* basic testing of all RAW_CLOSE_* calls
*/
2004-10-28 17:40:50 +04:00
BOOL torture_raw_close ( 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 ;
union smb_close io ;
struct smb_flush io_flush ;
int fnum ;
const char * fname = " \\ torture_close.txt " ;
time_t basetime = ( time ( NULL ) + 3 * 86400 ) & ~ 1 ;
union smb_fileinfo finfo , finfo2 ;
NTSTATUS status ;
if ( ! torture_open_connection ( & cli ) ) {
return False ;
}
mem_ctx = talloc_init ( " torture_raw_close " ) ;
# define REOPEN do { \
fnum = create_complex_file ( cli , mem_ctx , fname ) ; \
if ( fnum = = - 1 ) { \
printf ( " (%d) Failed to create %s \n " , __LINE__ , fname ) ; \
ret = False ; \
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 ) ) ; \
ret = False ; \
goto done ; \
} } while ( 0 )
REOPEN ;
io . close . level = RAW_CLOSE_CLOSE ;
io . close . in . fnum = fnum ;
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 ) ;
printf ( " testing close.in.write_time \n " ) ;
/* the file should have the write time set */
finfo . generic . in . fname = fname ;
finfo . generic . level = RAW_FILEINFO_ALL_INFO ;
status = smb_raw_pathinfo ( cli - > tree , mem_ctx , & finfo ) ;
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 " ,
2004-04-11 00:18:22 +04:00
timestring ( mem_ctx , basetime ) ,
2004-05-25 17:57:39 +04:00
nt_time_string ( mem_ctx , finfo . all_info . out . write_time ) ) ;
2003-08-13 05:53:07 +04:00
dump_all_info ( mem_ctx , & finfo ) ;
ret = False ;
}
printf ( " testing other times \n " ) ;
/* 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 " ) ;
dump_all_info ( mem_ctx , & finfo ) ;
ret = False ;
}
2004-08-04 17:23:35 +04:00
smbcli_unlink ( cli - > tree , fname ) ;
2003-08-13 05:53:07 +04:00
REOPEN ;
finfo2 . generic . in . fname = fname ;
finfo2 . generic . level = RAW_FILEINFO_ALL_INFO ;
status = smb_raw_pathinfo ( cli - > tree , mem_ctx , & finfo2 ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
io . close . level = RAW_CLOSE_CLOSE ;
io . close . in . fnum = fnum ;
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 . in . fname = fname ;
finfo . generic . level = RAW_FILEINFO_ALL_INFO ;
status = smb_raw_pathinfo ( cli - > tree , mem_ctx , & finfo ) ;
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 " ) ;
dump_all_info ( mem_ctx , & finfo ) ;
ret = False ;
}
printf ( " testing splclose \n " ) ;
/* check splclose on a file */
REOPEN ;
io . splclose . level = RAW_CLOSE_SPLCLOSE ;
io . splclose . in . fnum = fnum ;
status = smb_raw_close ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_UNSUCCESSFUL ) ;
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
io_flush . in . fnum = fnum ;
status = smb_raw_flush ( cli - > tree , & io_flush ) ;
CHECK_STATUS ( status , NT_STATUS_INVALID_HANDLE ) ;
io_flush . in . fnum = 0xffff ;
status = smb_raw_flush ( cli - > tree , & io_flush ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
REOPEN ;
io_flush . in . fnum = fnum ;
status = smb_raw_flush ( cli - > tree , & io_flush ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
printf ( " Testing SMBexit \n " ) ;
smb_raw_exit ( cli - > session ) ;
io_flush . in . fnum = fnum ;
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
torture_close_connection ( cli ) ;
talloc_destroy ( mem_ctx ) ;
return ret ;
}