2003-08-13 01:53:07 +00:00
/*
Unix SMB / CIFS implementation .
unlink 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"
# define CHECK_STATUS(status, correct) do { \
if ( ! NT_STATUS_EQUAL ( status , correct ) ) { \
2004-10-25 05:26:23 +00:00
printf ( " (%s) Incorrect status %s - should be %s \n " , \
__location__ , nt_errstr ( status ) , nt_errstr ( correct ) ) ; \
2003-08-13 01:53:07 +00:00
ret = False ; \
goto done ; \
} } while ( 0 )
# define BASEDIR "\\testunlink"
/*
test unlink ops
*/
2004-08-04 13:23:35 +00:00
static BOOL test_unlink ( struct smbcli_state * cli , TALLOC_CTX * mem_ctx )
2003-08-13 01:53:07 +00:00
{
struct smb_unlink io ;
NTSTATUS status ;
BOOL ret = True ;
const char * fname = BASEDIR " \\ test.txt " ;
2004-08-04 13:23:35 +00:00
if ( smbcli_deltree ( cli - > tree , BASEDIR ) = = - 1 | |
NT_STATUS_IS_ERR ( smbcli_mkdir ( cli - > tree , BASEDIR ) ) ) {
printf ( " Unable to setup %s - %s \n " , BASEDIR , smbcli_errstr ( cli - > tree ) ) ;
2003-08-13 01:53:07 +00:00
return False ;
}
printf ( " Trying non-existant file \n " ) ;
io . in . pattern = fname ;
io . in . attrib = 0 ;
status = smb_raw_unlink ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OBJECT_NAME_NOT_FOUND ) ;
2004-08-04 13:23:35 +00:00
smbcli_close ( cli - > tree , smbcli_open ( cli - > tree , fname , O_RDWR | O_CREAT , DENY_NONE ) ) ;
2003-08-13 01:53:07 +00:00
io . in . pattern = fname ;
io . in . attrib = 0 ;
status = smb_raw_unlink ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
printf ( " Trying a hidden file \n " ) ;
2004-08-04 13:23:35 +00:00
smbcli_close ( cli - > tree , smbcli_open ( cli - > tree , fname , O_RDWR | O_CREAT , DENY_NONE ) ) ;
2003-08-13 01:53:07 +00:00
torture_set_file_attribute ( cli - > tree , fname , FILE_ATTRIBUTE_HIDDEN ) ;
io . in . pattern = fname ;
io . in . attrib = 0 ;
status = smb_raw_unlink ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_NO_SUCH_FILE ) ;
io . in . pattern = fname ;
io . in . attrib = FILE_ATTRIBUTE_HIDDEN ;
status = smb_raw_unlink ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2004-10-26 22:44:28 +00:00
io . in . pattern = fname ;
io . in . attrib = FILE_ATTRIBUTE_HIDDEN ;
status = smb_raw_unlink ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OBJECT_NAME_NOT_FOUND ) ;
2003-08-13 01:53:07 +00:00
printf ( " Trying a directory \n " ) ;
io . in . pattern = BASEDIR ;
io . in . attrib = 0 ;
status = smb_raw_unlink ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_FILE_IS_A_DIRECTORY ) ;
io . in . pattern = BASEDIR ;
io . in . attrib = FILE_ATTRIBUTE_DIRECTORY ;
status = smb_raw_unlink ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_FILE_IS_A_DIRECTORY ) ;
printf ( " Trying a bad path \n " ) ;
io . in . pattern = " .. " ;
io . in . attrib = 0 ;
status = smb_raw_unlink ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OBJECT_PATH_SYNTAX_BAD ) ;
2003-08-13 02:04:44 +00:00
io . in . pattern = " \\ .. " ;
io . in . attrib = 0 ;
status = smb_raw_unlink ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OBJECT_PATH_SYNTAX_BAD ) ;
2004-10-26 05:33:23 +00:00
io . in . pattern = BASEDIR " \\ .. \\ .. " ;
io . in . attrib = 0 ;
status = smb_raw_unlink ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OBJECT_PATH_SYNTAX_BAD ) ;
2003-08-13 02:04:44 +00:00
io . in . pattern = BASEDIR " \\ .. " ;
io . in . attrib = 0 ;
status = smb_raw_unlink ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_FILE_IS_A_DIRECTORY ) ;
2003-08-13 01:53:07 +00:00
printf ( " Trying wildcards \n " ) ;
2004-08-04 13:23:35 +00:00
smbcli_close ( cli - > tree , smbcli_open ( cli - > tree , fname , O_RDWR | O_CREAT , DENY_NONE ) ) ;
2003-08-13 01:53:07 +00:00
io . in . pattern = BASEDIR " \\ t*.t " ;
io . in . attrib = 0 ;
status = smb_raw_unlink ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_NO_SUCH_FILE ) ;
2004-10-26 05:33:23 +00:00
io . in . pattern = BASEDIR " \\ z* " ;
io . in . attrib = 0 ;
status = smb_raw_unlink ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_NO_SUCH_FILE ) ;
io . in . pattern = BASEDIR " \\ z* " ;
io . in . attrib = FILE_ATTRIBUTE_DIRECTORY ;
status = smb_raw_unlink ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_NO_SUCH_FILE ) ;
2003-08-13 01:53:07 +00:00
io . in . pattern = BASEDIR " \\ * " ;
io . in . attrib = FILE_ATTRIBUTE_DIRECTORY ;
status = smb_raw_unlink ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OBJECT_NAME_INVALID ) ;
2004-10-26 05:33:23 +00:00
io . in . pattern = BASEDIR " \\ ? " ;
io . in . attrib = FILE_ATTRIBUTE_DIRECTORY ;
status = smb_raw_unlink ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OBJECT_NAME_INVALID ) ;
io . in . pattern = BASEDIR " \\ t* " ;
io . in . attrib = FILE_ATTRIBUTE_DIRECTORY ;
status = smb_raw_unlink ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
smbcli_close ( cli - > tree , smbcli_open ( cli - > tree , fname , O_RDWR | O_CREAT , DENY_NONE ) ) ;
2003-08-13 01:53:07 +00:00
io . in . pattern = BASEDIR " \\ *.dat " ;
io . in . attrib = FILE_ATTRIBUTE_DIRECTORY ;
status = smb_raw_unlink ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_NO_SUCH_FILE ) ;
io . in . pattern = BASEDIR " \\ *.tx? " ;
io . in . attrib = 0 ;
status = smb_raw_unlink ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
status = smb_raw_unlink ( cli - > tree , & io ) ;
CHECK_STATUS ( status , NT_STATUS_NO_SUCH_FILE ) ;
done :
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 ;
}
/*
basic testing of unlink calls
*/
BOOL torture_raw_unlink ( int dummy )
{
2004-08-04 13:23:35 +00:00
struct smbcli_state * cli ;
2003-08-13 01:53:07 +00:00
BOOL ret = True ;
TALLOC_CTX * mem_ctx ;
if ( ! torture_open_connection ( & cli ) ) {
return False ;
}
mem_ctx = talloc_init ( " torture_raw_unlink " ) ;
if ( ! test_unlink ( cli , mem_ctx ) ) {
ret = False ;
}
torture_close_connection ( cli ) ;
talloc_destroy ( mem_ctx ) ;
return ret ;
}