2004-10-24 09:08:52 +00:00
/*
Unix SMB / CIFS implementation .
delete on close testing
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"
2006-01-03 15:40:05 +00:00
# include "libcli/libcli.h"
2006-01-03 13:41:17 +00:00
# include "torture/torture.h"
2006-03-17 17:59:58 +00:00
# include "torture/util.h"
2005-02-10 05:09:35 +00:00
# include "system/filesys.h"
2005-08-20 21:28:30 +00:00
# include "libcli/raw/libcliraw.h"
2004-10-24 09:08:52 +00:00
2006-02-04 14:08:24 +00:00
# include "torture/raw/proto.h"
2006-10-16 13:06:41 +00:00
static bool check_delete_on_close ( struct torture_context * tctx ,
struct smbcli_state * cli , int fnum ,
const char * fname , bool expect_it ,
const char * where )
2005-07-06 09:50:31 +00:00
{
union smb_search_data data ;
NTSTATUS status ;
time_t c_time , a_time , m_time ;
size_t size ;
uint16_t mode ;
2006-10-16 13:06:41 +00:00
status = torture_single_search ( cli , tctx ,
2006-07-06 08:00:24 +00:00
fname ,
RAW_SEARCH_TRANS2 ,
RAW_SEARCH_DATA_FULL_DIRECTORY_INFO ,
2005-07-06 14:56:45 +00:00
FILE_ATTRIBUTE_DIRECTORY ,
2005-07-06 09:50:31 +00:00
& data ) ;
2006-10-16 13:06:41 +00:00
torture_assert_ntstatus_ok ( tctx , status ,
talloc_asprintf ( tctx , " single_search failed (%s) " , where ) ) ;
2005-07-06 13:24:38 +00:00
if ( fnum ! = - 1 ) {
union smb_fileinfo io ;
int nlink = expect_it ? 0 : 1 ;
io . all_info . level = RAW_FILEINFO_ALL_INFO ;
2006-03-12 22:48:25 +00:00
io . all_info . in . file . fnum = fnum ;
2005-07-06 13:24:38 +00:00
2006-10-16 13:06:41 +00:00
status = smb_raw_fileinfo ( cli - > tree , tctx , & io ) ;
torture_assert_ntstatus_ok ( tctx , status , talloc_asprintf ( tctx ,
" qfileinfo failed (%s) " , where ) ) ;
2005-07-06 13:24:38 +00:00
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , expect_it = = io . all_info . out . delete_pending ,
talloc_asprintf ( tctx ,
" %s - Expected del_on_close flag %d, qfileinfo/all_info gave %d " ,
where , expect_it , io . all_info . out . delete_pending ) ) ;
2005-07-06 13:24:38 +00:00
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , nlink = = io . all_info . out . nlink ,
talloc_asprintf ( tctx ,
" %s - Expected nlink %d, qfileinfo/all_info gave %d " ,
where , nlink , io . all_info . out . nlink ) ) ;
2005-07-06 13:24:38 +00:00
io . standard_info . level = RAW_FILEINFO_STANDARD_INFO ;
2006-03-12 22:48:25 +00:00
io . standard_info . in . file . fnum = fnum ;
2005-07-06 13:24:38 +00:00
2006-10-16 13:06:41 +00:00
status = smb_raw_fileinfo ( cli - > tree , tctx , & io ) ;
torture_assert_ntstatus_ok ( tctx , status , talloc_asprintf ( tctx , " qpathinfo failed (%s) " , where ) ) ;
2005-07-06 13:24:38 +00:00
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , expect_it = = io . standard_info . out . delete_pending ,
talloc_asprintf ( tctx , " %s - Expected del_on_close flag %d, qfileinfo/standard_info gave %d \n " ,
where , expect_it , io . standard_info . out . delete_pending ) ) ;
2005-07-06 13:24:38 +00:00
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , nlink = = io . standard_info . out . nlink ,
talloc_asprintf ( tctx , " %s - Expected nlink %d, qfileinfo/standard_info gave %d " ,
where , nlink , io . all_info . out . nlink ) ) ;
2005-07-06 09:50:31 +00:00
}
status = smbcli_qpathinfo ( cli - > tree , fname ,
& c_time , & a_time , & m_time ,
& size , & mode ) ;
if ( expect_it ) {
2006-10-16 13:06:41 +00:00
torture_assert_ntstatus_equal ( tctx , status , NT_STATUS_DELETE_PENDING ,
" qpathinfo did not give correct error code " ) ;
2005-07-06 09:50:31 +00:00
} else {
2006-10-16 13:06:41 +00:00
torture_assert_ntstatus_ok ( tctx , status ,
talloc_asprintf ( tctx , " qpathinfo failed (%s) " , where ) ) ;
2005-07-06 09:50:31 +00:00
}
2006-10-16 13:06:41 +00:00
return true ;
2005-07-06 09:50:31 +00:00
}
2004-10-24 09:08:52 +00:00
2006-10-16 13:06:41 +00:00
# define CHECK_STATUS(_cli, _expected) \
torture_assert_ntstatus_equal ( tctx , _cli - > tree - > session - > transport - > error . e . nt_status , _expected , \
" Incorrect status " )
2005-08-20 21:28:30 +00:00
2006-05-24 14:45:07 +00:00
static const char * fname = " \\ delete.file " ;
static const char * fname_new = " \\ delete.new " ;
static const char * dname = " \\ delete.dir " ;
2006-02-01 04:41:54 +00:00
2006-02-03 02:07:22 +00:00
static void del_clean_area ( struct smbcli_state * cli1 , struct smbcli_state * cli2 )
{
2006-10-16 13:06:41 +00:00
smb_raw_exit ( cli1 - > session ) ;
smb_raw_exit ( cli2 - > session ) ;
2006-05-24 14:45:07 +00:00
smbcli_deltree ( cli1 - > tree , dname ) ;
2004-10-24 09:08:52 +00:00
smbcli_setatr ( cli1 - > tree , fname , 0 , 0 ) ;
smbcli_unlink ( cli1 - > tree , fname ) ;
2006-02-03 02:07:22 +00:00
smbcli_setatr ( cli1 - > tree , fname_new , 0 , 0 ) ;
smbcli_unlink ( cli1 - > tree , fname_new ) ;
}
/* Test 1 - this should delete the file on close. */
2006-10-16 13:06:41 +00:00
static bool deltest1 ( struct torture_context * tctx , struct smbcli_state * cli1 , struct smbcli_state * cli2 )
2006-02-03 02:07:22 +00:00
{
int fnum1 = - 1 ;
del_clean_area ( cli1 , cli2 ) ;
2004-11-30 04:33:27 +00:00
fnum1 = smbcli_nt_create_full ( cli1 - > tree , fname , 0 ,
2004-12-02 04:37:36 +00:00
SEC_RIGHTS_FILE_ALL ,
2004-11-30 04:33:27 +00:00
FILE_ATTRIBUTE_NORMAL ,
NTCREATEX_SHARE_ACCESS_DELETE , NTCREATEX_DISP_OVERWRITE_IF ,
NTCREATEX_OPTIONS_DELETE_ON_CLOSE , 0 ) ;
2004-10-24 09:08:52 +00:00
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , fnum1 ! = - 1 , talloc_asprintf ( tctx , " open of %s failed (%s) " ,
fname , smbcli_errstr ( cli1 - > tree ) ) ) ;
2004-10-24 09:08:52 +00:00
2006-10-16 13:06:41 +00:00
torture_assert_ntstatus_ok ( tctx , smbcli_close ( cli1 - > tree , fnum1 ) ,
talloc_asprintf ( tctx , " close failed (%s) " , smbcli_errstr ( cli1 - > tree ) ) ) ;
2004-10-24 09:08:52 +00:00
fnum1 = smbcli_open ( cli1 - > tree , fname , O_RDWR , DENY_NONE ) ;
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , fnum1 = = - 1 , talloc_asprintf ( tctx , " open of %s succeeded (should fail) " ,
fname ) ) ;
2006-02-27 03:23:28 +00:00
2006-02-03 02:07:22 +00:00
return True ;
}
/* Test 2 - this should delete the file on close. */
2006-10-16 13:06:41 +00:00
static bool deltest2 ( struct torture_context * tctx , struct smbcli_state * cli1 , struct smbcli_state * cli2 )
2006-02-03 02:07:22 +00:00
{
int fnum1 = - 1 ;
del_clean_area ( cli1 , cli2 ) ;
2004-11-30 04:33:27 +00:00
fnum1 = smbcli_nt_create_full ( cli1 - > tree , fname , 0 ,
2004-12-02 04:37:36 +00:00
SEC_RIGHTS_FILE_ALL ,
2004-11-30 04:33:27 +00:00
FILE_ATTRIBUTE_NORMAL , NTCREATEX_SHARE_ACCESS_NONE ,
NTCREATEX_DISP_OVERWRITE_IF , 0 , 0 ) ;
2004-10-24 09:08:52 +00:00
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , fnum1 ! = - 1 ,
talloc_asprintf ( tctx , " open of %s failed (%s) " ,
fname , smbcli_errstr ( cli1 - > tree ) ) ) ;
2004-10-24 09:08:52 +00:00
2006-10-16 13:06:41 +00:00
torture_assert_ntstatus_ok ( tctx , smbcli_nt_delete_on_close ( cli1 - > tree , fnum1 , True ) ,
talloc_asprintf ( tctx , " setting delete_on_close failed (%s) " ,
smbcli_errstr ( cli1 - > tree ) ) ) ;
2004-10-24 09:08:52 +00:00
2006-10-16 13:06:41 +00:00
torture_assert_ntstatus_ok ( tctx , smbcli_close ( cli1 - > tree , fnum1 ) ,
talloc_asprintf ( tctx , " close failed (%s) " ,
smbcli_errstr ( cli1 - > tree ) ) ) ;
2004-10-24 09:08:52 +00:00
fnum1 = smbcli_open ( cli1 - > tree , fname , O_RDONLY , DENY_NONE ) ;
if ( fnum1 ! = - 1 ) {
2004-10-24 10:27:38 +00:00
printf ( " (%s) open of %s succeeded should have been deleted on close ! \n " ,
__location__ , fname ) ;
2004-10-24 09:08:52 +00:00
if ( NT_STATUS_IS_ERR ( smbcli_close ( cli1 - > tree , fnum1 ) ) ) {
2004-10-24 10:27:38 +00:00
printf ( " (%s) close failed (%s) \n " ,
__location__ , smbcli_errstr ( cli1 - > tree ) ) ;
2006-02-03 02:07:22 +00:00
return False ;
2004-10-24 09:08:52 +00:00
}
smbcli_unlink ( cli1 - > tree , fname ) ;
2006-02-03 02:07:22 +00:00
}
2006-10-16 13:06:41 +00:00
return true ;
2006-02-03 02:07:22 +00:00
}
2006-02-01 04:41:54 +00:00
2006-02-03 02:07:22 +00:00
/* Test 3 - ... */
2006-10-16 13:06:41 +00:00
static bool deltest3 ( struct torture_context * tctx , struct smbcli_state * cli1 , struct smbcli_state * cli2 )
2006-02-03 02:07:22 +00:00
{
int fnum1 = - 1 ;
int fnum2 = - 1 ;
del_clean_area ( cli1 , cli2 ) ;
2004-10-24 09:08:52 +00:00
2004-10-24 10:27:38 +00:00
fnum1 = smbcli_nt_create_full ( cli1 - > tree , fname , 0 ,
2004-12-02 04:37:36 +00:00
SEC_RIGHTS_FILE_ALL ,
2004-10-24 10:27:38 +00:00
FILE_ATTRIBUTE_NORMAL ,
NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE ,
NTCREATEX_DISP_OVERWRITE_IF , 0 , 0 ) ;
2004-10-24 09:08:52 +00:00
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , fnum1 ! = - 1 , talloc_asprintf ( tctx , " open - 1 of %s failed (%s) " ,
fname , smbcli_errstr ( cli1 - > tree ) ) ) ;
2004-10-24 09:08:52 +00:00
/* This should fail with a sharing violation - open for delete is only compatible
with SHARE_DELETE . */
2004-10-24 10:27:38 +00:00
fnum2 = smbcli_nt_create_full ( cli1 - > tree , fname , 0 ,
2004-11-30 04:33:27 +00:00
SEC_RIGHTS_FILE_READ ,
2004-10-24 10:27:38 +00:00
FILE_ATTRIBUTE_NORMAL ,
NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE ,
NTCREATEX_DISP_OPEN , 0 , 0 ) ;
2004-10-24 09:08:52 +00:00
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , fnum2 = = - 1 ,
talloc_asprintf ( tctx , " open - 2 of %s succeeded - should have failed. " ,
fname ) ) ;
2004-10-24 09:08:52 +00:00
/* This should succeed. */
2004-11-30 04:33:27 +00:00
fnum2 = smbcli_nt_create_full ( cli1 - > tree , fname , 0 ,
SEC_RIGHTS_FILE_READ ,
FILE_ATTRIBUTE_NORMAL ,
NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE | NTCREATEX_SHARE_ACCESS_DELETE ,
NTCREATEX_DISP_OPEN , 0 , 0 ) ;
2004-10-24 09:08:52 +00:00
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , fnum2 ! = - 1 , talloc_asprintf ( tctx , " open - 2 of %s failed (%s) " ,
fname , smbcli_errstr ( cli1 - > tree ) ) ) ;
2004-10-24 09:08:52 +00:00
2006-10-16 13:06:41 +00:00
torture_assert_ntstatus_ok ( tctx ,
smbcli_nt_delete_on_close ( cli1 - > tree , fnum1 , True ) ,
talloc_asprintf ( tctx , " setting delete_on_close failed (%s) " ,
smbcli_errstr ( cli1 - > tree ) ) ) ;
2004-10-24 09:08:52 +00:00
2006-10-16 13:06:41 +00:00
torture_assert_ntstatus_ok ( tctx , smbcli_close ( cli1 - > tree , fnum1 ) ,
talloc_asprintf ( tctx , " close 1 failed (%s) " ,
smbcli_errstr ( cli1 - > tree ) ) ) ;
2004-10-24 09:08:52 +00:00
2006-10-16 13:06:41 +00:00
torture_assert_ntstatus_ok ( tctx , smbcli_close ( cli1 - > tree , fnum2 ) ,
talloc_asprintf ( tctx , " close 2 failed (%s) " ,
smbcli_errstr ( cli1 - > tree ) ) ) ;
2004-10-24 09:08:52 +00:00
/* This should fail - file should no longer be there. */
fnum1 = smbcli_open ( cli1 - > tree , fname , O_RDONLY , DENY_NONE ) ;
if ( fnum1 ! = - 1 ) {
2004-10-24 10:27:38 +00:00
printf ( " (%s) open of %s succeeded should have been deleted on close ! \n " ,
__location__ , fname ) ;
2004-10-24 09:08:52 +00:00
if ( NT_STATUS_IS_ERR ( smbcli_close ( cli1 - > tree , fnum1 ) ) ) {
2004-10-24 10:27:38 +00:00
printf ( " (%s) close failed (%s) \n " ,
__location__ , smbcli_errstr ( cli1 - > tree ) ) ;
2004-10-24 09:08:52 +00:00
}
smbcli_unlink ( cli1 - > tree , fname ) ;
2006-02-03 02:07:22 +00:00
return False ;
}
return True ;
}
2004-10-24 09:08:52 +00:00
2006-02-03 02:07:22 +00:00
/* Test 4 ... */
2006-10-16 13:06:41 +00:00
static bool deltest4 ( struct torture_context * tctx , struct smbcli_state * cli1 , struct smbcli_state * cli2 )
2006-02-03 02:07:22 +00:00
{
int fnum1 = - 1 ;
int fnum2 = - 1 ;
2006-10-16 13:06:41 +00:00
bool correct = True ;
2006-02-01 04:41:54 +00:00
2006-02-03 02:07:22 +00:00
del_clean_area ( cli1 , cli2 ) ;
2004-10-24 09:08:52 +00:00
fnum1 = smbcli_nt_create_full ( cli1 - > tree , fname , 0 ,
2004-11-30 04:33:27 +00:00
SEC_FILE_READ_DATA |
SEC_FILE_WRITE_DATA |
SEC_STD_DELETE ,
FILE_ATTRIBUTE_NORMAL ,
NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE ,
NTCREATEX_DISP_OVERWRITE_IF , 0 , 0 ) ;
2004-10-24 09:08:52 +00:00
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , fnum1 ! = - 1 , talloc_asprintf ( tctx , " open of %s failed (%s) " ,
fname , smbcli_errstr ( cli1 - > tree ) ) ) ;
2004-10-24 09:08:52 +00:00
/* This should succeed. */
2004-11-30 04:33:27 +00:00
fnum2 = smbcli_nt_create_full ( cli1 - > tree , fname , 0 ,
SEC_RIGHTS_FILE_READ ,
2004-10-24 12:38:32 +00:00
FILE_ATTRIBUTE_NORMAL ,
NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE |
NTCREATEX_SHARE_ACCESS_DELETE ,
NTCREATEX_DISP_OPEN , 0 , 0 ) ;
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , fnum2 ! = - 1 , talloc_asprintf ( tctx , " open - 2 of %s failed (%s) " ,
fname , smbcli_errstr ( cli1 - > tree ) ) ) ;
2004-10-24 09:08:52 +00:00
2006-10-16 13:06:41 +00:00
torture_assert_ntstatus_ok ( tctx ,
smbcli_close ( cli1 - > tree , fnum2 ) ,
talloc_asprintf ( tctx , " close - 1 failed (%s) " ,
smbcli_errstr ( cli1 - > tree ) ) ) ;
2004-10-24 09:08:52 +00:00
2006-10-16 13:06:41 +00:00
torture_assert_ntstatus_ok ( tctx ,
smbcli_nt_delete_on_close ( cli1 - > tree , fnum1 , True ) ,
talloc_asprintf ( tctx , " setting delete_on_close failed (%s) " ,
smbcli_errstr ( cli1 - > tree ) ) ) ;
2007-05-21 05:40:04 +00:00
2004-10-24 09:08:52 +00:00
/* This should fail - no more opens once delete on close set. */
2004-10-24 12:38:32 +00:00
fnum2 = smbcli_nt_create_full ( cli1 - > tree , fname , 0 ,
2004-11-30 04:33:27 +00:00
SEC_RIGHTS_FILE_READ ,
2004-10-24 12:38:32 +00:00
FILE_ATTRIBUTE_NORMAL ,
NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE | NTCREATEX_SHARE_ACCESS_DELETE ,
NTCREATEX_DISP_OPEN , 0 , 0 ) ;
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , fnum2 = = - 1 ,
talloc_asprintf ( tctx , " open - 3 of %s succeeded ! Should have failed. " ,
fname ) ) ;
2005-08-20 21:28:30 +00:00
CHECK_STATUS ( cli1 , NT_STATUS_DELETE_PENDING ) ;
2006-10-16 13:06:41 +00:00
torture_assert_ntstatus_ok ( tctx , smbcli_close ( cli1 - > tree , fnum1 ) ,
talloc_asprintf ( tctx , " close - 2 failed (%s) " ,
smbcli_errstr ( cli1 - > tree ) ) ) ;
2004-10-24 09:08:52 +00:00
2006-02-03 02:07:22 +00:00
return correct ;
}
/* Test 5 ... */
2006-10-16 13:06:41 +00:00
static bool deltest5 ( struct torture_context * tctx , struct smbcli_state * cli1 , struct smbcli_state * cli2 )
2006-02-03 02:07:22 +00:00
{
int fnum1 = - 1 ;
del_clean_area ( cli1 , cli2 ) ;
2004-10-24 09:08:52 +00:00
fnum1 = smbcli_open ( cli1 - > tree , fname , O_RDWR | O_CREAT , DENY_NONE ) ;
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , fnum1 ! = - 1 , talloc_asprintf ( tctx , " open of %s failed (%s) " ,
fname , smbcli_errstr ( cli1 - > tree ) ) ) ;
2004-10-24 09:08:52 +00:00
/* This should fail - only allowed on NT opens with DELETE access. */
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , ! NT_STATUS_IS_OK ( smbcli_nt_delete_on_close ( cli1 - > tree , fnum1 , True ) ) ,
" setting delete_on_close on OpenX file succeeded - should fail ! " ) ;
2004-10-24 09:08:52 +00:00
2006-10-16 13:06:41 +00:00
torture_assert_ntstatus_ok ( tctx , smbcli_close ( cli1 - > tree , fnum1 ) ,
talloc_asprintf ( tctx , " close - 2 failed (%s) " , smbcli_errstr ( cli1 - > tree ) ) ) ;
2006-02-01 04:41:54 +00:00
2006-02-03 02:07:22 +00:00
return True ;
}
/* Test 6 ... */
2006-10-16 13:06:41 +00:00
static bool deltest6 ( struct torture_context * tctx , struct smbcli_state * cli1 , struct smbcli_state * cli2 )
2006-02-03 02:07:22 +00:00
{
int fnum1 = - 1 ;
del_clean_area ( cli1 , cli2 ) ;
2004-10-24 09:08:52 +00:00
fnum1 = smbcli_nt_create_full ( cli1 - > tree , fname , 0 ,
2004-11-30 04:33:27 +00:00
SEC_FILE_READ_DATA | SEC_FILE_WRITE_DATA ,
2004-10-24 09:08:52 +00:00
FILE_ATTRIBUTE_NORMAL ,
NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE |
NTCREATEX_SHARE_ACCESS_DELETE ,
NTCREATEX_DISP_OVERWRITE_IF , 0 , 0 ) ;
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , fnum1 ! = - 1 , talloc_asprintf ( tctx , " open of %s failed (%s) " ,
fname , smbcli_errstr ( cli1 - > tree ) ) ) ;
2004-10-24 09:08:52 +00:00
/* This should fail - only allowed on NT opens with DELETE access. */
2006-10-16 13:06:41 +00:00
torture_assert ( tctx ,
! NT_STATUS_IS_OK ( smbcli_nt_delete_on_close ( cli1 - > tree , fnum1 , True ) ) ,
" setting delete_on_close on file with no delete access succeeded - should fail ! " ) ;
2004-10-24 09:08:52 +00:00
2006-10-16 13:06:41 +00:00
torture_assert_ntstatus_ok ( tctx ,
smbcli_close ( cli1 - > tree , fnum1 ) ,
talloc_asprintf ( tctx , " close - 2 failed (%s) " ,
smbcli_errstr ( cli1 - > tree ) ) ) ;
2004-10-24 09:08:52 +00:00
2006-02-03 02:07:22 +00:00
return True ;
}
/* Test 7 ... */
2006-10-16 13:06:41 +00:00
static bool deltest7 ( struct torture_context * tctx , struct smbcli_state * cli1 , struct smbcli_state * cli2 )
2006-02-03 02:07:22 +00:00
{
int fnum1 = - 1 ;
2006-10-16 13:06:41 +00:00
bool correct = True ;
2006-02-03 02:07:22 +00:00
del_clean_area ( cli1 , cli2 ) ;
2004-10-24 09:08:52 +00:00
fnum1 = smbcli_nt_create_full ( cli1 - > tree , fname , 0 ,
2004-11-30 04:33:27 +00:00
SEC_FILE_READ_DATA |
SEC_FILE_WRITE_DATA |
SEC_STD_DELETE ,
FILE_ATTRIBUTE_NORMAL , 0 ,
NTCREATEX_DISP_OVERWRITE_IF , 0 , 0 ) ;
2004-10-24 09:08:52 +00:00
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , fnum1 ! = - 1 , talloc_asprintf ( tctx , " open of %s failed (%s) " ,
fname , smbcli_errstr ( cli1 - > tree ) ) ) ;
2004-10-24 09:08:52 +00:00
2006-10-16 13:06:41 +00:00
torture_assert_ntstatus_ok ( tctx , smbcli_nt_delete_on_close ( cli1 - > tree , fnum1 , True ) ,
" setting delete_on_close on file failed ! " ) ;
2005-07-06 09:50:31 +00:00
2006-10-16 13:06:41 +00:00
correct & = check_delete_on_close ( tctx , cli1 , fnum1 , fname , True , __location__ ) ;
2004-10-24 09:08:52 +00:00
2006-10-16 13:06:41 +00:00
torture_assert_ntstatus_ok ( tctx ,
smbcli_nt_delete_on_close ( cli1 - > tree , fnum1 , False ) ,
" unsetting delete_on_close on file failed ! " ) ;
2004-10-24 09:08:52 +00:00
2006-10-16 13:06:41 +00:00
correct & = check_delete_on_close ( tctx , cli1 , fnum1 , fname , False , __location__ ) ;
2005-07-06 09:50:31 +00:00
2006-10-16 13:06:41 +00:00
torture_assert_ntstatus_ok ( tctx , smbcli_close ( cli1 - > tree , fnum1 ) ,
talloc_asprintf ( tctx , " close - 2 failed (%s) " , smbcli_errstr ( cli1 - > tree ) ) ) ;
2004-10-24 09:08:52 +00:00
/* This next open should succeed - we reset the flag. */
fnum1 = smbcli_open ( cli1 - > tree , fname , O_RDONLY , DENY_NONE ) ;
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , fnum1 ! = - 1 , talloc_asprintf ( tctx , " open of %s failed (%s) " ,
fname , smbcli_errstr ( cli1 - > tree ) ) ) ;
2004-10-24 09:08:52 +00:00
2006-10-16 13:06:41 +00:00
torture_assert_ntstatus_ok ( tctx , smbcli_close ( cli1 - > tree , fnum1 ) ,
talloc_asprintf ( tctx , " close - 2 failed (%s) " ,
smbcli_errstr ( cli1 - > tree ) ) ) ;
2006-02-03 02:07:22 +00:00
return correct ;
}
/* Test 8 ... */
2006-10-16 13:06:41 +00:00
static bool deltest8 ( struct torture_context * tctx , struct smbcli_state * cli1 , struct smbcli_state * cli2 )
2006-02-03 02:07:22 +00:00
{
int fnum1 = - 1 ;
int fnum2 = - 1 ;
2006-10-16 13:06:41 +00:00
bool correct = True ;
2006-02-03 02:07:22 +00:00
del_clean_area ( cli1 , cli2 ) ;
2004-11-30 04:33:27 +00:00
fnum1 = smbcli_nt_create_full ( cli1 - > tree , fname , 0 ,
SEC_FILE_READ_DATA |
SEC_FILE_WRITE_DATA |
SEC_STD_DELETE ,
FILE_ATTRIBUTE_NORMAL ,
NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE | NTCREATEX_SHARE_ACCESS_DELETE ,
NTCREATEX_DISP_OVERWRITE_IF , 0 , 0 ) ;
2004-10-24 09:08:52 +00:00
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , fnum1 ! = - 1 ,
talloc_asprintf ( tctx , " open of %s failed (%s) " ,
fname , smbcli_errstr ( cli1 - > tree ) ) ) ;
2004-10-24 09:08:52 +00:00
2004-11-30 04:33:27 +00:00
fnum2 = smbcli_nt_create_full ( cli2 - > tree , fname , 0 ,
SEC_FILE_READ_DATA |
SEC_FILE_WRITE_DATA |
SEC_STD_DELETE ,
FILE_ATTRIBUTE_NORMAL ,
NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE | NTCREATEX_SHARE_ACCESS_DELETE ,
NTCREATEX_DISP_OPEN , 0 , 0 ) ;
2004-10-24 09:08:52 +00:00
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , fnum2 ! = - 1 , talloc_asprintf ( tctx , " open of %s failed (%s) " ,
fname , smbcli_errstr ( cli1 - > tree ) ) ) ;
2004-10-24 09:08:52 +00:00
2006-10-16 13:06:41 +00:00
torture_assert_ntstatus_ok ( tctx ,
smbcli_nt_delete_on_close ( cli1 - > tree , fnum1 , True ) ,
" setting delete_on_close on file failed ! " ) ;
2005-07-06 09:50:31 +00:00
2006-10-16 13:06:41 +00:00
correct & = check_delete_on_close ( tctx , cli1 , fnum1 , fname , True , __location__ ) ;
correct & = check_delete_on_close ( tctx , cli2 , fnum2 , fname , True , __location__ ) ;
2005-07-06 08:13:11 +00:00
2006-10-16 13:06:41 +00:00
torture_assert_ntstatus_ok ( tctx , smbcli_close ( cli1 - > tree , fnum1 ) ,
talloc_asprintf ( tctx , " close - 1 failed (%s) " ,
smbcli_errstr ( cli1 - > tree ) ) ) ;
2004-10-24 09:08:52 +00:00
2006-10-16 13:06:41 +00:00
correct & = check_delete_on_close ( tctx , cli1 , - 1 , fname , True , __location__ ) ;
correct & = check_delete_on_close ( tctx , cli2 , fnum2 , fname , True , __location__ ) ;
2005-07-06 09:50:31 +00:00
2006-10-16 13:06:41 +00:00
torture_assert_ntstatus_ok ( tctx , smbcli_close ( cli2 - > tree , fnum2 ) ,
talloc_asprintf ( tctx , " close - 2 failed (%s) " , smbcli_errstr ( cli2 - > tree ) ) ) ;
2004-10-24 09:08:52 +00:00
/* This should fail.. */
fnum1 = smbcli_open ( cli1 - > tree , fname , O_RDONLY , DENY_NONE ) ;
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , fnum1 = = - 1 ,
talloc_asprintf ( tctx , " open of %s succeeded should have been deleted on close ! \n " , fname ) ) ;
2006-02-03 02:07:22 +00:00
return correct ;
}
/* Test 9 ... */
2006-10-16 13:06:41 +00:00
static bool deltest9 ( struct torture_context * tctx , struct smbcli_state * cli1 , struct smbcli_state * cli2 )
2006-02-03 02:07:22 +00:00
{
int fnum1 = - 1 ;
del_clean_area ( cli1 , cli2 ) ;
2006-02-01 04:41:54 +00:00
2004-10-24 09:08:52 +00:00
/* This should fail - we need to set DELETE_ACCESS. */
2004-10-24 12:38:32 +00:00
fnum1 = smbcli_nt_create_full ( cli1 - > tree , fname , 0 ,
2004-11-30 04:33:27 +00:00
SEC_FILE_READ_DATA | SEC_FILE_WRITE_DATA ,
2004-10-24 12:38:32 +00:00
FILE_ATTRIBUTE_NORMAL ,
NTCREATEX_SHARE_ACCESS_NONE ,
NTCREATEX_DISP_OVERWRITE_IF ,
NTCREATEX_OPTIONS_DELETE_ON_CLOSE , 0 ) ;
2004-10-24 09:08:52 +00:00
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , fnum1 = = - 1 ,
talloc_asprintf ( tctx , " open of %s succeeded should have failed! " ,
fname ) ) ;
2004-10-24 09:08:52 +00:00
2006-02-03 02:07:22 +00:00
return True ;
}
/* Test 10 ... */
2006-10-16 13:06:41 +00:00
static bool deltest10 ( struct torture_context * tctx , struct smbcli_state * cli1 , struct smbcli_state * cli2 )
2006-02-03 02:07:22 +00:00
{
int fnum1 = - 1 ;
del_clean_area ( cli1 , cli2 ) ;
2004-10-24 09:08:52 +00:00
2004-10-24 12:38:32 +00:00
fnum1 = smbcli_nt_create_full ( cli1 - > tree , fname , 0 ,
2004-11-30 04:33:27 +00:00
SEC_FILE_READ_DATA |
SEC_FILE_WRITE_DATA |
SEC_STD_DELETE ,
2004-10-24 12:38:32 +00:00
FILE_ATTRIBUTE_NORMAL ,
NTCREATEX_SHARE_ACCESS_NONE ,
NTCREATEX_DISP_OVERWRITE_IF ,
NTCREATEX_OPTIONS_DELETE_ON_CLOSE , 0 ) ;
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , fnum1 ! = - 1 ,
talloc_asprintf ( tctx , " open of %s failed (%s) " ,
fname , smbcli_errstr ( cli1 - > tree ) ) ) ;
2004-10-24 09:08:52 +00:00
/* This should delete the file. */
2006-10-16 13:06:41 +00:00
torture_assert_ntstatus_ok ( tctx , smbcli_close ( cli1 - > tree , fnum1 ) ,
talloc_asprintf ( tctx , " close failed (%s) " ,
smbcli_errstr ( cli1 - > tree ) ) ) ;
2004-10-24 09:08:52 +00:00
/* This should fail.. */
fnum1 = smbcli_open ( cli1 - > tree , fname , O_RDONLY , DENY_NONE ) ;
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , fnum1 = = - 1 ,
talloc_asprintf ( tctx , " open of %s succeeded should have been deleted on close ! " ,
fname ) ) ;
return true ;
2006-02-03 02:07:22 +00:00
}
2004-10-24 09:08:52 +00:00
2006-02-03 02:07:22 +00:00
/* Test 11 ... */
2006-10-16 13:06:41 +00:00
static bool deltest11 ( struct torture_context * tctx , struct smbcli_state * cli1 , struct smbcli_state * cli2 )
2006-02-03 02:07:22 +00:00
{
int fnum1 = - 1 ;
NTSTATUS status ;
del_clean_area ( cli1 , cli2 ) ;
/* test 11 - does having read only attribute still allow delete on close. */
2004-11-30 04:33:27 +00:00
2004-10-24 12:55:12 +00:00
fnum1 = smbcli_nt_create_full ( cli1 - > tree , fname , 0 ,
2004-12-02 04:37:36 +00:00
SEC_RIGHTS_FILE_ALL ,
2004-10-24 12:55:12 +00:00
FILE_ATTRIBUTE_READONLY ,
NTCREATEX_SHARE_ACCESS_NONE ,
NTCREATEX_DISP_OVERWRITE_IF , 0 , 0 ) ;
2004-10-24 09:08:52 +00:00
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , fnum1 ! = - 1 , talloc_asprintf ( tctx , " open of %s failed (%s) " ,
fname , smbcli_errstr ( cli1 - > tree ) ) ) ;
2004-10-24 09:08:52 +00:00
status = smbcli_nt_delete_on_close ( cli1 - > tree , fnum1 , True ) ;
2006-10-16 13:06:41 +00:00
torture_assert_ntstatus_equal ( tctx , status , NT_STATUS_CANNOT_DELETE ,
talloc_asprintf ( tctx , " setting delete_on_close should fail with NT_STATUS_CANNOT_DELETE. Got %s instead) " , smbcli_errstr ( cli1 - > tree ) ) ) ;
2004-10-24 09:08:52 +00:00
2006-10-16 13:06:41 +00:00
torture_assert_ntstatus_ok ( tctx , smbcli_close ( cli1 - > tree , fnum1 ) ,
talloc_asprintf ( tctx , " close failed (%s) " ,
smbcli_errstr ( cli1 - > tree ) ) ) ;
2004-10-24 09:08:52 +00:00
2006-02-03 02:07:22 +00:00
return True ;
}
2006-02-01 04:41:54 +00:00
2006-02-03 02:07:22 +00:00
/* Test 12 ... */
2006-10-16 13:06:41 +00:00
static bool deltest12 ( struct torture_context * tctx , struct smbcli_state * cli1 , struct smbcli_state * cli2 )
2006-02-03 02:07:22 +00:00
{
int fnum1 = - 1 ;
NTSTATUS status ;
2006-02-01 04:41:54 +00:00
2006-02-03 02:07:22 +00:00
del_clean_area ( cli1 , cli2 ) ;
2004-10-24 09:08:52 +00:00
2005-12-09 19:36:40 +00:00
/* test 12 - does having read only attribute still allow delete on
* close at time of open . */
2004-10-24 09:08:52 +00:00
2004-11-30 04:33:27 +00:00
fnum1 = smbcli_nt_create_full ( cli1 - > tree , fname , 0 ,
2004-12-02 04:37:36 +00:00
SEC_RIGHTS_FILE_ALL ,
2004-11-30 04:33:27 +00:00
FILE_ATTRIBUTE_READONLY ,
2005-12-09 19:36:40 +00:00
NTCREATEX_SHARE_ACCESS_DELETE ,
NTCREATEX_DISP_OVERWRITE_IF ,
2004-11-30 04:33:27 +00:00
NTCREATEX_OPTIONS_DELETE_ON_CLOSE , 0 ) ;
2004-10-24 09:08:52 +00:00
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , fnum1 = = - 1 ,
talloc_asprintf ( tctx , " open of %s succeeded. Should fail with "
" NT_STATUS_CANNOT_DELETE. \n " , fname ) ) ;
status = smbcli_nt_error ( cli1 - > tree ) ;
torture_assert_ntstatus_equal ( tctx , status , NT_STATUS_CANNOT_DELETE ,
talloc_asprintf ( tctx , " setting delete_on_close on open should "
2005-12-09 19:36:40 +00:00
" fail with NT_STATUS_CANNOT_DELETE. Got %s "
2006-10-16 13:06:41 +00:00
" instead) " ,
smbcli_errstr ( cli1 - > tree ) ) ) ;
2004-10-24 09:08:52 +00:00
2006-10-16 13:06:41 +00:00
return true ;
2006-02-03 02:07:22 +00:00
}
/* Test 13 ... */
2006-10-16 13:06:41 +00:00
static bool deltest13 ( struct torture_context * tctx , struct smbcli_state * cli1 , struct smbcli_state * cli2 )
2006-02-03 02:07:22 +00:00
{
int fnum1 = - 1 ;
int fnum2 = - 1 ;
2006-10-16 13:06:41 +00:00
bool correct = True ;
2006-02-03 02:07:22 +00:00
del_clean_area ( cli1 , cli2 ) ;
2004-10-24 09:08:52 +00:00
2005-07-06 09:50:31 +00:00
/* Test 13: Does resetting the delete on close flag affect a second
* fd ? */
fnum1 = smbcli_nt_create_full ( cli1 - > tree , fname , 0 ,
SEC_FILE_READ_DATA |
SEC_FILE_WRITE_DATA |
SEC_STD_DELETE ,
FILE_ATTRIBUTE_NORMAL ,
2005-12-09 19:36:40 +00:00
NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE |
NTCREATEX_SHARE_ACCESS_DELETE ,
2005-07-06 09:50:31 +00:00
NTCREATEX_DISP_OVERWRITE_IF ,
0 , 0 ) ;
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , fnum1 ! = - 1 ,
talloc_asprintf ( tctx , " open of %s failed (%s) " ,
fname , smbcli_errstr ( cli1 - > tree ) ) ) ;
2005-07-06 09:50:31 +00:00
fnum2 = smbcli_nt_create_full ( cli2 - > tree , fname , 0 ,
SEC_FILE_READ_DATA |
SEC_FILE_WRITE_DATA |
SEC_STD_DELETE ,
FILE_ATTRIBUTE_NORMAL ,
2005-12-09 19:36:40 +00:00
NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE |
NTCREATEX_SHARE_ACCESS_DELETE ,
2005-07-06 09:50:31 +00:00
NTCREATEX_DISP_OPEN , 0 , 0 ) ;
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , fnum2 ! = - 1 , talloc_asprintf ( tctx ,
" open of %s failed (%s) " ,
fname , smbcli_errstr ( cli2 - > tree ) ) ) ;
2005-07-06 09:50:31 +00:00
2006-10-16 13:06:41 +00:00
torture_assert_ntstatus_ok ( tctx ,
smbcli_nt_delete_on_close ( cli1 - > tree , fnum1 ,
True ) ,
" setting delete_on_close on file failed ! " ) ;
2005-07-06 09:50:31 +00:00
2006-10-16 13:06:41 +00:00
correct & = check_delete_on_close ( tctx , cli1 , fnum1 , fname , True , __location__ ) ;
correct & = check_delete_on_close ( tctx , cli2 , fnum2 , fname , True , __location__ ) ;
2005-07-06 09:50:31 +00:00
2006-10-16 13:06:41 +00:00
torture_assert_ntstatus_ok ( tctx , smbcli_nt_delete_on_close ( cli2 - > tree , fnum2 ,
False ) ,
" setting delete_on_close on file failed ! " ) ;
2005-07-06 09:50:31 +00:00
2006-10-16 13:06:41 +00:00
correct & = check_delete_on_close ( tctx , cli1 , fnum1 , fname , False , __location__ ) ;
correct & = check_delete_on_close ( tctx , cli2 , fnum2 , fname , False , __location__ ) ;
2005-07-06 09:50:31 +00:00
2006-10-16 13:06:41 +00:00
torture_assert_ntstatus_ok ( tctx , smbcli_close ( cli1 - > tree , fnum1 ) ,
talloc_asprintf ( tctx , " close - 1 failed (%s) " ,
smbcli_errstr ( cli1 - > tree ) ) ) ;
2005-07-06 09:50:31 +00:00
2006-10-16 13:06:41 +00:00
torture_assert_ntstatus_ok ( tctx , smbcli_close ( cli2 - > tree , fnum2 ) ,
talloc_asprintf ( tctx , " close - 2 failed (%s) " ,
smbcli_errstr ( cli2 - > tree ) ) ) ;
2005-07-06 09:50:31 +00:00
fnum1 = smbcli_open ( cli1 - > tree , fname , O_RDONLY , DENY_NONE ) ;
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , fnum1 ! = - 1 , talloc_asprintf ( tctx , " open of %s failed! " ,
fname ) ) ;
2005-07-06 09:50:31 +00:00
2006-10-16 13:06:41 +00:00
smbcli_close ( cli1 - > tree , fnum1 ) ;
2006-02-01 04:41:54 +00:00
2006-02-03 02:07:22 +00:00
return correct ;
}
/* Test 14 ... */
2006-10-16 13:06:41 +00:00
static bool deltest14 ( struct torture_context * tctx , struct smbcli_state * cli1 , struct smbcli_state * cli2 )
2006-02-03 02:07:22 +00:00
{
int dnum1 = - 1 ;
2006-10-16 13:06:41 +00:00
bool correct = true ;
2006-02-03 02:07:22 +00:00
del_clean_area ( cli1 , cli2 ) ;
2005-07-06 09:50:31 +00:00
2005-07-06 14:56:45 +00:00
/* Test 14 -- directory */
2006-05-24 14:45:07 +00:00
dnum1 = smbcli_nt_create_full ( cli1 - > tree , dname , 0 ,
2005-07-06 14:56:45 +00:00
SEC_FILE_READ_DATA |
SEC_FILE_WRITE_DATA |
SEC_STD_DELETE ,
FILE_ATTRIBUTE_DIRECTORY ,
NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE |
NTCREATEX_SHARE_ACCESS_DELETE ,
NTCREATEX_DISP_CREATE , 0 , 0 ) ;
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , dnum1 ! = - 1 , talloc_asprintf ( tctx , " open of %s failed: %s! " ,
dname , smbcli_errstr ( cli1 - > tree ) ) ) ;
2005-07-06 14:56:45 +00:00
2006-10-16 13:06:41 +00:00
correct & = check_delete_on_close ( tctx , cli1 , dnum1 , dname , False , __location__ ) ;
torture_assert_ntstatus_ok ( tctx , smbcli_nt_delete_on_close ( cli1 - > tree , dnum1 , True ) ,
" setting delete_on_close on file failed ! " ) ;
correct & = check_delete_on_close ( tctx , cli1 , dnum1 , dname , True , __location__ ) ;
2005-07-06 14:56:45 +00:00
smbcli_close ( cli1 - > tree , dnum1 ) ;
/* Now it should be gone... */
2006-05-24 14:45:07 +00:00
dnum1 = smbcli_nt_create_full ( cli1 - > tree , dname , 0 ,
2005-07-06 14:56:45 +00:00
SEC_FILE_READ_DATA |
SEC_FILE_WRITE_DATA |
SEC_STD_DELETE ,
FILE_ATTRIBUTE_DIRECTORY ,
NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE |
NTCREATEX_SHARE_ACCESS_DELETE ,
NTCREATEX_DISP_OPEN , 0 , 0 ) ;
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , dnum1 = = - 1 , " setting delete_on_close on file succeeded ! " ) ;
2006-02-03 02:07:22 +00:00
return correct ;
}
/* Test 15 ... */
2006-10-16 13:06:41 +00:00
static bool deltest15 ( struct torture_context * tctx , struct smbcli_state * cli1 , struct smbcli_state * cli2 )
2006-02-03 02:07:22 +00:00
{
int fnum1 = - 1 ;
2006-10-16 13:06:41 +00:00
bool correct = true ;
2006-02-03 02:07:22 +00:00
int fnum2 = - 1 ;
NTSTATUS status ;
del_clean_area ( cli1 , cli2 ) ;
2006-02-01 04:09:02 +00:00
/* Test 15: delete on close under rename */
2005-12-09 21:49:11 +00:00
smbcli_setatr ( cli1 - > tree , fname , 0 , 0 ) ;
smbcli_unlink ( cli1 - > tree , fname ) ;
smbcli_unlink ( cli1 - > tree , fname_new ) ;
fnum1 = smbcli_nt_create_full ( cli1 - > tree , fname , 0 ,
SEC_FILE_READ_DATA ,
FILE_ATTRIBUTE_NORMAL ,
NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE |
NTCREATEX_SHARE_ACCESS_DELETE ,
NTCREATEX_DISP_OVERWRITE_IF ,
0 , 0 ) ;
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , fnum1 ! = - 1 ,
talloc_asprintf ( tctx , " open - 1 of %s failed (%s) " , fname , smbcli_errstr ( cli1 - > tree ) ) ) ;
2005-12-09 21:49:11 +00:00
status = smbcli_rename ( cli2 - > tree , fname , fname_new ) ;
2006-10-16 13:06:41 +00:00
torture_assert_ntstatus_ok ( tctx , status , " renaming failed! " ) ;
2005-12-09 21:49:11 +00:00
fnum2 = smbcli_nt_create_full ( cli2 - > tree , fname_new , 0 ,
SEC_GENERIC_ALL ,
FILE_ATTRIBUTE_NORMAL ,
NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE |
NTCREATEX_SHARE_ACCESS_DELETE ,
NTCREATEX_DISP_OVERWRITE_IF ,
0 , 0 ) ;
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , fnum2 ! = - 1 ,
talloc_asprintf ( tctx , " open - 1 of %s failed (%s) " ,
fname_new , smbcli_errstr ( cli1 - > tree ) ) ) ;
2005-12-09 21:49:11 +00:00
status = smbcli_nt_delete_on_close ( cli2 - > tree , fnum2 , True ) ;
2006-10-16 13:06:41 +00:00
torture_assert_ntstatus_ok ( tctx , status ,
" setting delete_on_close on file failed ! " ) ;
2005-12-09 21:49:11 +00:00
smbcli_close ( cli2 - > tree , fnum2 ) ;
/* The file should be around under the new name, there's a second
* handle open */
2006-10-16 13:06:41 +00:00
correct & = check_delete_on_close ( tctx , cli1 , fnum1 , fname_new , True , __location__ ) ;
2005-12-09 21:49:11 +00:00
fnum2 = smbcli_nt_create_full ( cli2 - > tree , fname , 0 ,
SEC_GENERIC_ALL ,
FILE_ATTRIBUTE_NORMAL ,
NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE |
NTCREATEX_SHARE_ACCESS_DELETE ,
NTCREATEX_DISP_OVERWRITE_IF ,
0 , 0 ) ;
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , fnum2 ! = - 1 , talloc_asprintf ( tctx , " open - 1 of %s failed (%s) " ,
fname , smbcli_errstr ( cli1 - > tree ) ) ) ;
2005-12-09 21:49:11 +00:00
2006-10-16 13:06:41 +00:00
correct & = check_delete_on_close ( tctx , cli2 , fnum2 , fname , False , __location__ ) ;
2006-02-27 03:23:28 +00:00
2005-12-09 21:49:11 +00:00
smbcli_close ( cli2 - > tree , fnum2 ) ;
smbcli_close ( cli1 - > tree , fnum1 ) ;
fnum1 = smbcli_nt_create_full ( cli1 - > tree , fname , 0 ,
SEC_FILE_READ_EA ,
FILE_ATTRIBUTE_NORMAL ,
NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE |
NTCREATEX_SHARE_ACCESS_DELETE ,
NTCREATEX_DISP_OPEN ,
0 , 0 ) ;
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , fnum1 ! = - 1 , talloc_asprintf ( tctx , " open - 1 of %s failed (%s) " ,
fname , smbcli_errstr ( cli1 - > tree ) ) ) ;
2005-12-09 21:49:11 +00:00
smbcli_close ( cli1 - > tree , fnum1 ) ;
fnum1 = smbcli_nt_create_full ( cli1 - > tree , fname_new , 0 ,
SEC_FILE_READ_EA ,
FILE_ATTRIBUTE_NORMAL ,
NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE |
NTCREATEX_SHARE_ACCESS_DELETE ,
NTCREATEX_DISP_OPEN ,
0 , 0 ) ;
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , fnum1 = = - 1 ,
" smbcli_open succeeded, should have "
" failed " ) ;
2006-02-03 02:07:22 +00:00
return correct ;
}
/* Test 16 ... */
2006-10-16 13:06:41 +00:00
static bool deltest16 ( struct torture_context * tctx , struct smbcli_state * cli1 , struct smbcli_state * cli2 )
2006-02-03 02:07:22 +00:00
{
int fnum1 = - 1 ;
int fnum2 = - 1 ;
2006-10-16 13:06:41 +00:00
bool correct = true ;
2006-02-03 02:07:22 +00:00
del_clean_area ( cli1 , cli2 ) ;
2006-02-01 04:09:02 +00:00
/* Test 16. */
2006-02-01 02:30:57 +00:00
/* Ensure the file doesn't already exist. */
smbcli_close ( cli1 - > tree , fnum1 ) ;
smbcli_close ( cli1 - > tree , fnum2 ) ;
smbcli_setatr ( cli1 - > tree , fname , 0 , 0 ) ;
smbcli_unlink ( cli1 - > tree , fname ) ;
/* Firstly create with all access, but delete on close. */
fnum1 = smbcli_nt_create_full ( cli1 - > tree , fname , 0 ,
SEC_RIGHTS_FILE_ALL ,
FILE_ATTRIBUTE_NORMAL ,
NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE |
NTCREATEX_SHARE_ACCESS_DELETE ,
NTCREATEX_DISP_CREATE ,
NTCREATEX_OPTIONS_DELETE_ON_CLOSE , 0 ) ;
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , fnum1 ! = - 1 , talloc_asprintf ( tctx , " open - 1 of %s failed (%s) " , fname , smbcli_errstr ( cli1 - > tree ) ) ) ;
2006-02-01 02:30:57 +00:00
/* The delete on close bit is *not* reported as being set. */
2006-10-16 13:06:41 +00:00
correct & = check_delete_on_close ( tctx , cli1 , fnum1 , fname , False , __location__ ) ;
2006-02-27 03:23:28 +00:00
/* The delete on close bit is *not* reported as being set. */
2006-10-16 13:06:41 +00:00
correct & = check_delete_on_close ( tctx , cli1 , - 1 , fname , False , __location__ ) ;
correct & = check_delete_on_close ( tctx , cli2 , - 1 , fname , False , __location__ ) ;
2006-02-01 02:30:57 +00:00
/* Now try opening again for read-only. */
2006-02-27 03:23:28 +00:00
fnum2 = smbcli_nt_create_full ( cli2 - > tree , fname , 0 ,
2006-02-01 02:30:57 +00:00
SEC_RIGHTS_FILE_READ ,
FILE_ATTRIBUTE_NORMAL ,
NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE |
NTCREATEX_SHARE_ACCESS_DELETE ,
NTCREATEX_DISP_OPEN ,
0 , 0 ) ;
/* Should work. */
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , fnum2 ! = - 1 , talloc_asprintf ( tctx , " open - 1 of %s failed (%s) " ,
fname , smbcli_errstr ( cli1 - > tree ) ) ) ;
2006-02-01 02:30:57 +00:00
2006-10-16 13:06:41 +00:00
correct & = check_delete_on_close ( tctx , cli1 , fnum1 , fname , False , __location__ ) ;
correct & = check_delete_on_close ( tctx , cli1 , - 1 , fname , False , __location__ ) ;
correct & = check_delete_on_close ( tctx , cli2 , fnum2 , fname , False , __location__ ) ;
correct & = check_delete_on_close ( tctx , cli2 , - 1 , fname , False , __location__ ) ;
2006-02-27 03:23:28 +00:00
2006-02-01 02:30:57 +00:00
smbcli_close ( cli1 - > tree , fnum1 ) ;
2006-02-27 03:23:28 +00:00
2006-10-16 13:06:41 +00:00
correct & = check_delete_on_close ( tctx , cli2 , fnum2 , fname , True , __location__ ) ;
correct & = check_delete_on_close ( tctx , cli2 , - 1 , fname , True , __location__ ) ;
2006-02-27 03:23:28 +00:00
smbcli_close ( cli2 - > tree , fnum2 ) ;
2006-02-01 02:30:57 +00:00
/* And the file should be deleted ! */
fnum1 = smbcli_open ( cli1 - > tree , fname , O_RDWR , DENY_NONE ) ;
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , fnum1 = = - 1 , talloc_asprintf ( tctx , " open of %s succeeded (should fail) " ,
fname ) ) ;
2006-02-03 02:07:22 +00:00
return correct ;
}
/* Test 17 ... */
2006-10-16 13:06:41 +00:00
static bool deltest17 ( struct torture_context * tctx , struct smbcli_state * cli1 , struct smbcli_state * cli2 )
2006-02-03 02:07:22 +00:00
{
int fnum1 = - 1 ;
int fnum2 = - 1 ;
2006-10-16 13:06:41 +00:00
bool correct = True ;
2006-02-03 02:07:22 +00:00
del_clean_area ( cli1 , cli2 ) ;
2006-02-01 04:09:02 +00:00
/* Test 17. */
2006-02-01 02:30:57 +00:00
/* Ensure the file doesn't already exist. */
smbcli_close ( cli1 - > tree , fnum1 ) ;
smbcli_close ( cli1 - > tree , fnum2 ) ;
smbcli_setatr ( cli1 - > tree , fname , 0 , 0 ) ;
smbcli_unlink ( cli1 - > tree , fname ) ;
/* Firstly open and create with all access */
fnum1 = smbcli_nt_create_full ( cli1 - > tree , fname , 0 ,
SEC_RIGHTS_FILE_ALL ,
FILE_ATTRIBUTE_NORMAL ,
NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE |
NTCREATEX_SHARE_ACCESS_DELETE ,
NTCREATEX_DISP_CREATE ,
0 , 0 ) ;
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , fnum1 ! = - 1 , talloc_asprintf ( tctx , " open - 1 of %s failed (%s) " ,
fname , smbcli_errstr ( cli1 - > tree ) ) ) ;
2006-02-01 02:30:57 +00:00
/* And close - just to create the file. */
smbcli_close ( cli1 - > tree , fnum1 ) ;
/* Next open with all access, but add delete on close. */
fnum1 = smbcli_nt_create_full ( cli1 - > tree , fname , 0 ,
SEC_RIGHTS_FILE_ALL ,
FILE_ATTRIBUTE_NORMAL ,
NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE |
NTCREATEX_SHARE_ACCESS_DELETE ,
NTCREATEX_DISP_OPEN ,
NTCREATEX_OPTIONS_DELETE_ON_CLOSE , 0 ) ;
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , fnum1 ! = - 1 , talloc_asprintf ( tctx , " open - 1 of %s failed (%s) " ,
fname , smbcli_errstr ( cli1 - > tree ) ) ) ;
2006-02-01 02:30:57 +00:00
/* The delete on close bit is *not* reported as being set. */
2006-10-16 13:06:41 +00:00
correct & = check_delete_on_close ( tctx , cli1 , fnum1 , fname , False , __location__ ) ;
2006-02-01 02:30:57 +00:00
/* Now try opening again for read-only. */
fnum2 = smbcli_nt_create_full ( cli1 - > tree , fname , 0 ,
2006-02-06 19:43:24 +00:00
SEC_RIGHTS_FILE_READ |
SEC_STD_DELETE ,
2006-02-01 02:30:57 +00:00
FILE_ATTRIBUTE_NORMAL ,
NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE |
NTCREATEX_SHARE_ACCESS_DELETE ,
NTCREATEX_DISP_OPEN ,
0 , 0 ) ;
/* Should work. */
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , fnum2 ! = - 1 , talloc_asprintf ( tctx , " open - 1 of %s failed (%s) " ,
fname , smbcli_errstr ( cli1 - > tree ) ) ) ;
2006-02-01 02:30:57 +00:00
2006-02-27 03:23:28 +00:00
/* still not reported as being set on either */
2006-10-16 13:06:41 +00:00
correct & = check_delete_on_close ( tctx , cli1 , fnum1 , fname , False , __location__ ) ;
correct & = check_delete_on_close ( tctx , cli1 , fnum2 , fname , False , __location__ ) ;
2006-02-27 03:23:28 +00:00
2006-02-01 02:30:57 +00:00
smbcli_close ( cli1 - > tree , fnum1 ) ;
2006-02-27 03:23:28 +00:00
2006-10-16 13:06:41 +00:00
correct & = check_delete_on_close ( tctx , cli1 , fnum2 , fname , False , __location__ ) ;
2006-02-27 03:23:28 +00:00
2006-02-01 02:30:57 +00:00
smbcli_close ( cli1 - > tree , fnum2 ) ;
/* See if the file is deleted - shouldn't be.... */
fnum1 = smbcli_open ( cli1 - > tree , fname , O_RDWR , DENY_NONE ) ;
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , fnum1 ! = - 1 , talloc_asprintf ( tctx , " open of %s failed (should succeed) - %s " ,
fname , smbcli_errstr ( cli1 - > tree ) ) ) ;
2006-02-03 02:07:22 +00:00
return correct ;
}
/* Test 18 ... */
2006-10-16 13:06:41 +00:00
static bool deltest18 ( struct torture_context * tctx , struct smbcli_state * cli1 , struct smbcli_state * cli2 )
2006-02-03 02:07:22 +00:00
{
int fnum1 = - 1 ;
int fnum2 = - 1 ;
2006-10-16 13:06:41 +00:00
bool correct = True ;
2006-02-03 02:07:22 +00:00
del_clean_area ( cli1 , cli2 ) ;
2006-02-01 04:09:02 +00:00
/* Test 18. With directories. */
2006-02-01 03:36:04 +00:00
/* Ensure the file doesn't already exist. */
smbcli_close ( cli1 - > tree , fnum1 ) ;
smbcli_close ( cli1 - > tree , fnum2 ) ;
2006-05-24 14:45:07 +00:00
smbcli_deltree ( cli1 - > tree , dname ) ;
2006-02-01 03:36:04 +00:00
/* Firstly create with all access, but delete on close. */
2006-05-24 14:45:07 +00:00
fnum1 = smbcli_nt_create_full ( cli1 - > tree , dname , 0 ,
2006-02-01 03:36:04 +00:00
SEC_FILE_READ_DATA |
SEC_FILE_WRITE_DATA |
SEC_STD_DELETE ,
FILE_ATTRIBUTE_DIRECTORY ,
NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE |
NTCREATEX_SHARE_ACCESS_DELETE ,
NTCREATEX_DISP_CREATE ,
NTCREATEX_OPTIONS_DIRECTORY | NTCREATEX_OPTIONS_DELETE_ON_CLOSE , 0 ) ;
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , fnum1 ! = - 1 , talloc_asprintf ( tctx , " open - 1 of %s failed (%s) " ,
dname , smbcli_errstr ( cli1 - > tree ) ) ) ;
2006-02-01 03:36:04 +00:00
/* The delete on close bit is *not* reported as being set. */
2006-10-16 13:06:41 +00:00
correct & = check_delete_on_close ( tctx , cli1 , fnum1 , dname , False , __location__ ) ;
2006-02-01 03:36:04 +00:00
/* Now try opening again for read-only. */
2006-05-24 14:45:07 +00:00
fnum2 = smbcli_nt_create_full ( cli1 - > tree , dname , 0 ,
2006-02-01 03:36:04 +00:00
SEC_RIGHTS_FILE_READ ,
FILE_ATTRIBUTE_DIRECTORY ,
NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE |
NTCREATEX_SHARE_ACCESS_DELETE ,
NTCREATEX_DISP_OPEN ,
NTCREATEX_OPTIONS_DIRECTORY , 0 ) ;
/* Should work. */
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , fnum2 ! = - 1 , talloc_asprintf ( tctx , " open - 1 of %s failed (%s) " ,
dname , smbcli_errstr ( cli1 - > tree ) ) ) ;
2006-02-01 03:36:04 +00:00
2006-10-16 13:06:41 +00:00
correct & = check_delete_on_close ( tctx , cli1 , fnum1 , dname , False , __location__ ) ;
correct & = check_delete_on_close ( tctx , cli1 , fnum2 , dname , False , __location__ ) ;
2006-02-27 03:23:28 +00:00
2006-02-01 03:36:04 +00:00
smbcli_close ( cli1 - > tree , fnum1 ) ;
2006-02-27 03:23:28 +00:00
2006-10-16 13:06:41 +00:00
correct & = check_delete_on_close ( tctx , cli1 , fnum2 , dname , True , __location__ ) ;
2006-02-27 03:23:28 +00:00
2006-02-01 03:36:04 +00:00
smbcli_close ( cli1 - > tree , fnum2 ) ;
/* And the directory should be deleted ! */
2006-05-24 14:45:07 +00:00
fnum1 = smbcli_nt_create_full ( cli1 - > tree , dname , 0 ,
2006-02-01 03:36:04 +00:00
SEC_RIGHTS_FILE_READ ,
FILE_ATTRIBUTE_DIRECTORY ,
NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE |
NTCREATEX_SHARE_ACCESS_DELETE ,
NTCREATEX_DISP_OPEN ,
NTCREATEX_OPTIONS_DIRECTORY , 0 ) ;
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , fnum1 = = - 1 , talloc_asprintf ( tctx , " open of %s succeeded (should fail) " ,
dname ) ) ;
2006-02-03 02:07:22 +00:00
return correct ;
}
/* Test 19 ... */
2006-10-16 13:06:41 +00:00
static bool deltest19 ( struct torture_context * tctx , struct smbcli_state * cli1 , struct smbcli_state * cli2 )
2006-02-03 02:07:22 +00:00
{
int fnum1 = - 1 ;
int fnum2 = - 1 ;
2006-10-16 13:06:41 +00:00
bool correct = True ;
2006-02-03 02:07:22 +00:00
del_clean_area ( cli1 , cli2 ) ;
2006-02-01 04:09:02 +00:00
/* Test 19. */
2006-02-01 03:36:04 +00:00
2006-05-24 14:45:07 +00:00
smbcli_deltree ( cli1 - > tree , dname ) ;
2006-02-01 03:36:04 +00:00
/* Firstly open and create with all access */
2006-05-24 14:45:07 +00:00
fnum1 = smbcli_nt_create_full ( cli1 - > tree , dname , 0 ,
2006-02-01 03:36:04 +00:00
SEC_FILE_READ_DATA |
SEC_FILE_WRITE_DATA |
SEC_STD_DELETE ,
FILE_ATTRIBUTE_DIRECTORY ,
NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE |
NTCREATEX_SHARE_ACCESS_DELETE ,
NTCREATEX_DISP_CREATE ,
NTCREATEX_OPTIONS_DIRECTORY , 0 ) ;
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , fnum1 ! = - 1 , talloc_asprintf ( tctx , " open - 1 of %s failed (%s) " ,
dname , smbcli_errstr ( cli1 - > tree ) ) ) ;
2006-02-01 03:36:04 +00:00
/* And close - just to create the directory. */
smbcli_close ( cli1 - > tree , fnum1 ) ;
/* Next open with all access, but add delete on close. */
2006-05-24 14:45:07 +00:00
fnum1 = smbcli_nt_create_full ( cli1 - > tree , dname , 0 ,
2006-02-01 03:36:04 +00:00
SEC_FILE_READ_DATA |
SEC_FILE_WRITE_DATA |
SEC_STD_DELETE ,
FILE_ATTRIBUTE_DIRECTORY ,
NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE |
NTCREATEX_SHARE_ACCESS_DELETE ,
NTCREATEX_DISP_OPEN ,
NTCREATEX_OPTIONS_DIRECTORY | NTCREATEX_OPTIONS_DELETE_ON_CLOSE , 0 ) ;
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , fnum1 ! = - 1 ,
talloc_asprintf ( tctx , " open - 1 of %s failed (%s) " , fname , smbcli_errstr ( cli1 - > tree ) ) ) ;
2006-02-01 03:36:04 +00:00
/* The delete on close bit is *not* reported as being set. */
2006-10-16 13:06:41 +00:00
correct & = check_delete_on_close ( tctx , cli1 , fnum1 , dname , False , __location__ ) ;
2006-02-01 03:36:04 +00:00
/* Now try opening again for read-only. */
2006-05-24 14:45:07 +00:00
fnum2 = smbcli_nt_create_full ( cli1 - > tree , dname , 0 ,
2006-02-01 03:36:04 +00:00
SEC_RIGHTS_FILE_READ ,
FILE_ATTRIBUTE_DIRECTORY ,
NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE |
NTCREATEX_SHARE_ACCESS_DELETE ,
NTCREATEX_DISP_OPEN ,
NTCREATEX_OPTIONS_DIRECTORY , 0 ) ;
/* Should work. */
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , fnum2 ! = - 1 , talloc_asprintf ( tctx , " open - 1 of %s failed (%s) " ,
dname , smbcli_errstr ( cli1 - > tree ) ) ) ;
2006-02-01 03:36:04 +00:00
smbcli_close ( cli1 - > tree , fnum1 ) ;
2006-02-27 03:23:28 +00:00
2006-10-16 13:06:41 +00:00
correct & = check_delete_on_close ( tctx , cli1 , fnum2 , dname , True , __location__ ) ;
2006-02-27 03:23:28 +00:00
2006-02-01 03:36:04 +00:00
smbcli_close ( cli1 - > tree , fnum2 ) ;
2006-02-03 02:07:22 +00:00
/* See if the file is deleted - for a directory this seems to be true ! */
2006-05-24 14:45:07 +00:00
fnum1 = smbcli_nt_create_full ( cli1 - > tree , dname , 0 ,
2006-02-01 03:36:04 +00:00
SEC_RIGHTS_FILE_READ ,
FILE_ATTRIBUTE_DIRECTORY ,
NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE |
NTCREATEX_SHARE_ACCESS_DELETE ,
NTCREATEX_DISP_OPEN ,
NTCREATEX_OPTIONS_DIRECTORY , 0 ) ;
2006-02-03 02:07:22 +00:00
CHECK_STATUS ( cli1 , NT_STATUS_OBJECT_NAME_NOT_FOUND ) ;
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , fnum1 = = - 1 ,
talloc_asprintf ( tctx , " open of %s succeeded (should fail) " , dname ) ) ;
2006-02-03 02:07:22 +00:00
return correct ;
}
/* Test 20 ... */
2006-10-16 13:06:41 +00:00
static bool deltest20 ( struct torture_context * tctx , struct smbcli_state * cli1 , struct smbcli_state * cli2 )
2006-02-03 02:07:22 +00:00
{
int fnum1 = - 1 ;
int dnum1 = - 1 ;
2006-10-16 13:06:41 +00:00
bool correct = True ;
2006-02-03 02:07:22 +00:00
NTSTATUS status ;
del_clean_area ( cli1 , cli2 ) ;
2006-02-01 04:09:02 +00:00
/* Test 20 -- non-empty directory hardest to get right... */
2007-02-03 17:46:32 +00:00
if ( torture_setting_bool ( tctx , " samba3 " , False ) ) {
return True ;
}
2006-05-24 14:45:07 +00:00
smbcli_deltree ( cli1 - > tree , dname ) ;
2006-02-01 04:09:02 +00:00
2006-05-24 14:45:07 +00:00
dnum1 = smbcli_nt_create_full ( cli1 - > tree , dname , 0 ,
2006-02-01 04:09:02 +00:00
SEC_FILE_READ_DATA |
SEC_FILE_WRITE_DATA |
SEC_STD_DELETE ,
FILE_ATTRIBUTE_DIRECTORY ,
NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE |
NTCREATEX_SHARE_ACCESS_DELETE ,
NTCREATEX_DISP_CREATE ,
NTCREATEX_OPTIONS_DIRECTORY , 0 ) ;
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , dnum1 ! = - 1 , talloc_asprintf ( tctx , " open of %s failed: %s! " ,
dname , smbcli_errstr ( cli1 - > tree ) ) ) ;
2006-02-01 04:09:02 +00:00
2006-10-16 13:06:41 +00:00
correct & = check_delete_on_close ( tctx , cli1 , dnum1 , dname , False , __location__ ) ;
2006-02-01 04:09:02 +00:00
status = smbcli_nt_delete_on_close ( cli1 - > tree , dnum1 , True ) ;
{
char * fullname ;
2006-05-24 14:45:07 +00:00
asprintf ( & fullname , " \\ %s%s " , dname , fname ) ;
2006-02-01 04:09:02 +00:00
fnum1 = smbcli_open ( cli1 - > tree , fullname , O_CREAT | O_RDWR ,
DENY_NONE ) ;
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , fnum1 = = - 1 ,
" smbcli_open succeeded, should have "
" failed with NT_STATUS_DELETE_PENDING "
) ;
2006-02-01 04:09:02 +00:00
2006-10-16 13:06:41 +00:00
torture_assert_ntstatus_equal ( tctx ,
smbcli_nt_error ( cli1 - > tree ) ,
NT_STATUS_DELETE_PENDING ,
" smbcli_open failed " ) ;
2006-02-01 04:09:02 +00:00
}
status = smbcli_nt_delete_on_close ( cli1 - > tree , dnum1 , False ) ;
2006-10-16 13:06:41 +00:00
torture_assert_ntstatus_ok ( tctx , status ,
" setting delete_on_close on file failed ! " ) ;
2006-02-01 04:09:02 +00:00
{
char * fullname ;
2006-05-24 14:45:07 +00:00
asprintf ( & fullname , " \\ %s%s " , dname , fname ) ;
2006-02-01 04:09:02 +00:00
fnum1 = smbcli_open ( cli1 - > tree , fullname , O_CREAT | O_RDWR ,
DENY_NONE ) ;
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , fnum1 ! = - 1 ,
talloc_asprintf ( tctx , " smbcli_open failed: %s \n " ,
smbcli_errstr ( cli1 - > tree ) ) ) ;
2006-02-01 04:09:02 +00:00
smbcli_close ( cli1 - > tree , fnum1 ) ;
}
status = smbcli_nt_delete_on_close ( cli1 - > tree , dnum1 , True ) ;
2006-10-16 13:06:41 +00:00
torture_assert_ntstatus_equal ( tctx , status , NT_STATUS_DIRECTORY_NOT_EMPTY ,
" setting delete_on_close failed " ) ;
2006-02-01 04:09:02 +00:00
smbcli_close ( cli1 - > tree , dnum1 ) ;
2006-02-03 02:07:22 +00:00
return correct ;
}
2007-05-23 21:14:05 +00:00
/* Test 20a ... */
static bool deltest20a ( struct torture_context * tctx , struct smbcli_state * cli1 , struct smbcli_state * cli2 )
{
int fnum1 = - 1 ;
int fnum2 = - 1 ;
bool correct = True ;
del_clean_area ( cli1 , cli2 ) ;
/* Test 20a. */
/* Ensure the file doesn't already exist. */
smbcli_close ( cli1 - > tree , fnum1 ) ;
smbcli_close ( cli1 - > tree , fnum2 ) ;
smbcli_setatr ( cli1 - > tree , fname , 0 , 0 ) ;
smbcli_unlink ( cli1 - > tree , fname ) ;
/* Firstly open and create with all access */
fnum1 = smbcli_nt_create_full ( cli1 - > tree , fname , 0 ,
SEC_RIGHTS_FILE_ALL ,
FILE_ATTRIBUTE_NORMAL ,
NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE |
NTCREATEX_SHARE_ACCESS_DELETE ,
NTCREATEX_DISP_CREATE ,
0 , 0 ) ;
torture_assert ( tctx , fnum1 ! = - 1 , talloc_asprintf ( tctx , " open - 1 of %s failed (%s) " ,
fname , smbcli_errstr ( cli1 - > tree ) ) ) ;
/* Next open with all access, but add delete on close. */
fnum2 = smbcli_nt_create_full ( cli2 - > tree , fname , 0 ,
SEC_RIGHTS_FILE_ALL ,
FILE_ATTRIBUTE_NORMAL ,
NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE |
NTCREATEX_SHARE_ACCESS_DELETE ,
NTCREATEX_DISP_OPEN ,
NTCREATEX_OPTIONS_DELETE_ON_CLOSE , 0 ) ;
torture_assert ( tctx , fnum2 ! = - 1 , talloc_asprintf ( tctx , " open - 2 of %s failed (%s) " ,
fname , smbcli_errstr ( cli2 - > tree ) ) ) ;
/* The delete on close bit is *not* reported as being set. */
correct & = check_delete_on_close ( tctx , cli1 , fnum1 , fname , False , __location__ ) ;
correct & = check_delete_on_close ( tctx , cli2 , fnum2 , fname , False , __location__ ) ;
smbcli_close ( cli1 - > tree , fnum1 ) ;
correct & = check_delete_on_close ( tctx , cli2 , fnum2 , fname , False , __location__ ) ;
smbcli_close ( cli2 - > tree , fnum2 ) ;
/* See if the file is deleted - should be.... */
fnum1 = smbcli_open ( cli1 - > tree , fname , O_RDWR , DENY_NONE ) ;
torture_assert ( tctx , fnum1 = = - 1 , talloc_asprintf ( tctx , " open of %s succeeded (should fail) - %s " ,
fname , smbcli_errstr ( cli1 - > tree ) ) ) ;
return correct ;
}
2007-05-23 23:11:16 +00:00
/* Test 20b ... */
2007-05-23 23:14:48 +00:00
/* This is the delete semantics that the cifsfs client depends on when
* trying to delete an open file on a Windows server . It
* opens a file with initial delete on close set , renames it then closes
* all open handles . The file goes away on Windows .
*/
2007-05-23 23:11:16 +00:00
static bool deltest20b ( struct torture_context * tctx , struct smbcli_state * cli1 , struct smbcli_state * cli2 )
{
int fnum1 = - 1 ;
int fnum2 = - 1 ;
bool correct = True ;
del_clean_area ( cli1 , cli2 ) ;
2007-05-23 23:14:48 +00:00
/* Test 20b. */
2007-05-23 23:11:16 +00:00
/* Ensure the file doesn't already exist. */
smbcli_close ( cli1 - > tree , fnum1 ) ;
smbcli_close ( cli1 - > tree , fnum2 ) ;
smbcli_setatr ( cli1 - > tree , fname , 0 , 0 ) ;
smbcli_unlink ( cli1 - > tree , fname ) ;
smbcli_setatr ( cli1 - > tree , fname_new , 0 , 0 ) ;
smbcli_unlink ( cli1 - > tree , fname_new ) ;
/* Firstly open and create with all access */
fnum1 = smbcli_nt_create_full ( cli1 - > tree , fname , 0 ,
SEC_RIGHTS_FILE_ALL ,
FILE_ATTRIBUTE_NORMAL ,
NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE |
NTCREATEX_SHARE_ACCESS_DELETE ,
NTCREATEX_DISP_CREATE ,
0 , 0 ) ;
torture_assert ( tctx , fnum1 ! = - 1 , talloc_asprintf ( tctx , " open - 1 of %s failed (%s) " ,
fname , smbcli_errstr ( cli1 - > tree ) ) ) ;
/* And close - just to create the file. */
smbcli_close ( cli1 - > tree , fnum1 ) ;
/* Firstly open and create with all access */
fnum1 = smbcli_nt_create_full ( cli1 - > tree , fname , 0 ,
SEC_RIGHTS_FILE_ALL ,
FILE_ATTRIBUTE_NORMAL ,
NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE |
NTCREATEX_SHARE_ACCESS_DELETE ,
NTCREATEX_DISP_OPEN ,
0 , 0 ) ;
torture_assert ( tctx , fnum1 ! = - 1 , talloc_asprintf ( tctx , " open - 1 of %s failed (%s) " ,
fname , smbcli_errstr ( cli1 - > tree ) ) ) ;
/* Next open with all access, but add delete on close. */
fnum2 = smbcli_nt_create_full ( cli2 - > tree , fname , 0 ,
SEC_RIGHTS_FILE_ALL ,
FILE_ATTRIBUTE_NORMAL ,
NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE |
NTCREATEX_SHARE_ACCESS_DELETE ,
NTCREATEX_DISP_OPEN ,
NTCREATEX_OPTIONS_DELETE_ON_CLOSE , 0 ) ;
torture_assert ( tctx , fnum2 ! = - 1 , talloc_asprintf ( tctx , " open - 2 of %s failed (%s) " ,
fname , smbcli_errstr ( cli2 - > tree ) ) ) ;
/* The delete on close bit is *not* reported as being set. */
correct & = check_delete_on_close ( tctx , cli1 , fnum1 , fname , False , __location__ ) ;
correct & = check_delete_on_close ( tctx , cli2 , fnum2 , fname , False , __location__ ) ;
smbcli_close ( cli1 - > tree , fnum1 ) ;
correct & = check_delete_on_close ( tctx , cli2 , fnum2 , fname , False , __location__ ) ;
/* Rename the file by handle. */
{
union smb_setfileinfo sfinfo ;
NTSTATUS status ;
memset ( & sfinfo , ' \0 ' , sizeof ( sfinfo ) ) ;
sfinfo . generic . level = RAW_SFILEINFO_RENAME_INFORMATION ;
sfinfo . generic . in . file . fnum = fnum2 ;
sfinfo . rename_information . in . root_fid = 0 ;
/* Don't start the filename with '\\', we get NT_STATUS_NOT_SUPPORTED if so. */
sfinfo . rename_information . in . new_name = fname_new + 1 ;
sfinfo . rename_information . in . overwrite = 1 ;
status = smb_raw_setfileinfo ( cli2 - > tree , & sfinfo ) ;
torture_assert_ntstatus_equal ( tctx , status , NT_STATUS_OK , talloc_asprintf ( tctx , " rename of %s to %s failed (%s) " ,
fname , fname_new , smbcli_errstr ( cli2 - > tree ) ) ) ;
}
correct & = check_delete_on_close ( tctx , cli2 , fnum2 , fname_new , False , __location__ ) ;
smbcli_close ( cli2 - > tree , fnum2 ) ;
/* See if the file is deleted - should be.... */
fnum1 = smbcli_open ( cli1 - > tree , fname , O_RDWR , DENY_NONE ) ;
torture_assert ( tctx , fnum1 = = - 1 , talloc_asprintf ( tctx , " open of %s succeeded (should fail) - %s " ,
fname , smbcli_errstr ( cli1 - > tree ) ) ) ;
fnum1 = smbcli_open ( cli1 - > tree , fname_new , O_RDWR , DENY_NONE ) ;
torture_assert ( tctx , fnum1 = = - 1 , talloc_asprintf ( tctx , " open of %s succeeded (should fail) - %s " ,
fname_new , smbcli_errstr ( cli1 - > tree ) ) ) ;
return correct ;
}
2006-02-06 19:43:24 +00:00
/* Test 21 ... */
2006-10-16 13:06:41 +00:00
static bool deltest21 ( struct torture_context * tctx )
2006-02-06 19:43:24 +00:00
{
int fnum1 = - 1 ;
2006-10-16 13:06:41 +00:00
struct smbcli_state * cli1 ;
struct smbcli_state * cli2 ;
bool correct = True ;
if ( ! torture_open_connection ( & cli1 , 0 ) )
return False ;
if ( ! torture_open_connection ( & cli2 , 1 ) )
return False ;
2006-02-06 19:43:24 +00:00
del_clean_area ( cli1 , cli2 ) ;
/* Test 21 -- Test removal of file after socket close. */
fnum1 = smbcli_nt_create_full ( cli1 - > tree , fname , 0 ,
SEC_RIGHTS_FILE_ALL ,
FILE_ATTRIBUTE_NORMAL , NTCREATEX_SHARE_ACCESS_NONE ,
NTCREATEX_DISP_OVERWRITE_IF , 0 , 0 ) ;
2006-10-16 13:06:41 +00:00
torture_assert ( tctx , fnum1 ! = - 1 , talloc_asprintf ( tctx , " open of %s failed (%s) " ,
fname , smbcli_errstr ( cli1 - > tree ) ) ) ;
2006-02-06 19:43:24 +00:00
2006-10-16 13:06:41 +00:00
torture_assert_ntstatus_ok ( tctx ,
smbcli_nt_delete_on_close ( cli1 - > tree , fnum1 , True ) ,
talloc_asprintf ( tctx , " setting delete_on_close failed (%s) " ,
smbcli_errstr ( cli1 - > tree ) ) ) ;
2006-02-06 19:43:24 +00:00
/* Ensure delete on close is set. */
2006-10-16 13:06:41 +00:00
correct & = check_delete_on_close ( tctx , cli1 , fnum1 , fname , True , __location__ ) ;
2006-02-06 19:43:24 +00:00
/* Now yank the rug from under cli1. */
2006-07-13 17:37:45 +00:00
smbcli_transport_dead ( cli1 - > transport , NT_STATUS_LOCAL_DISCONNECT ) ;
2006-02-06 19:43:24 +00:00
fnum1 = - 1 ;
2006-10-16 13:06:41 +00:00
if ( ! torture_open_connection ( & cli1 , 0 ) ) {
2006-02-06 19:43:24 +00:00
return False ;
}
2006-07-02 08:53:49 +00:00
/* On slow build farm machines it might happen that they are not fast
* enogh to delete the file for this test */
msleep ( 200 ) ;
2006-02-06 19:43:24 +00:00
/* File should not be there. */
fnum1 = smbcli_nt_create_full ( cli1 - > tree , fname , 0 ,
SEC_RIGHTS_FILE_READ ,
FILE_ATTRIBUTE_NORMAL ,
NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE |
NTCREATEX_SHARE_ACCESS_DELETE ,
NTCREATEX_DISP_OPEN ,
0 , 0 ) ;
CHECK_STATUS ( cli1 , NT_STATUS_OBJECT_NAME_NOT_FOUND ) ;
return correct ;
}
2007-01-04 16:26:15 +00:00
/* Test 22 ... */
/*
* Test whether a second * directory * handle inhibits delete if the first has
* del - on - close set and is closed
*/
static bool deltest22 ( struct torture_context * tctx )
{
int dnum1 = - 1 ;
int dnum2 = - 1 ;
struct smbcli_state * cli1 ;
bool correct = True ;
if ( ! torture_open_connection ( & cli1 , 0 ) )
return False ;
smbcli_deltree ( cli1 - > tree , dname ) ;
torture_assert_ntstatus_ok (
tctx , smbcli_mkdir ( cli1 - > tree , dname ) ,
talloc_asprintf ( tctx , " smbcli_mdir failed: (%s) \n " ,
smbcli_errstr ( cli1 - > tree ) ) ) ;
dnum1 = smbcli_nt_create_full ( cli1 - > tree , dname , 0 ,
SEC_FILE_READ_DATA |
SEC_FILE_WRITE_DATA |
SEC_STD_DELETE ,
FILE_ATTRIBUTE_DIRECTORY ,
NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE |
NTCREATEX_SHARE_ACCESS_DELETE ,
NTCREATEX_DISP_OPEN ,
NTCREATEX_OPTIONS_DIRECTORY , 0 ) ;
torture_assert ( tctx , dnum1 ! = - 1 ,
talloc_asprintf ( tctx , " open of %s failed: %s! " ,
dname , smbcli_errstr ( cli1 - > tree ) ) ) ;
dnum2 = smbcli_nt_create_full ( cli1 - > tree , dname , 0 ,
SEC_FILE_READ_DATA |
SEC_FILE_WRITE_DATA ,
FILE_ATTRIBUTE_DIRECTORY ,
NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE |
NTCREATEX_SHARE_ACCESS_DELETE ,
NTCREATEX_DISP_OPEN ,
NTCREATEX_OPTIONS_DIRECTORY , 0 ) ;
torture_assert ( tctx , dnum2 ! = - 1 ,
talloc_asprintf ( tctx , " open of %s failed: %s! " ,
dname , smbcli_errstr ( cli1 - > tree ) ) ) ;
torture_assert_ntstatus_ok (
tctx , smbcli_nt_delete_on_close ( cli1 - > tree , dnum1 , True ) ,
talloc_asprintf ( tctx , " setting delete_on_close failed (%s) " ,
smbcli_errstr ( cli1 - > tree ) ) ) ;
smbcli_close ( cli1 - > tree , dnum1 ) ;
dnum1 = smbcli_nt_create_full ( cli1 - > tree , dname , 0 ,
SEC_FILE_READ_DATA |
SEC_FILE_WRITE_DATA |
SEC_STD_DELETE ,
FILE_ATTRIBUTE_DIRECTORY ,
NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE |
NTCREATEX_SHARE_ACCESS_DELETE ,
NTCREATEX_DISP_OPEN ,
NTCREATEX_OPTIONS_DIRECTORY , 0 ) ;
torture_assert ( tctx , dnum1 = = - 1 ,
talloc_asprintf ( tctx , " open of %s succeeded! \n " ,
dname ) ) ;
CHECK_STATUS ( cli1 , NT_STATUS_DELETE_PENDING ) ;
return correct ;
}
2007-05-23 21:14:05 +00:00
2006-02-03 02:07:22 +00:00
/*
Test delete on close semantics .
*/
2006-10-16 13:06:41 +00:00
struct torture_suite * torture_test_delete ( void )
2006-02-03 02:07:22 +00:00
{
2006-10-16 13:06:41 +00:00
struct torture_suite * suite = torture_suite_create (
2007-05-21 05:40:04 +00:00
talloc_autofree_context ( ) ,
" DELETE " ) ;
2006-10-16 13:06:41 +00:00
torture_suite_add_2smb_test ( suite , " deltest1 " , deltest1 ) ;
torture_suite_add_2smb_test ( suite , " deltest2 " , deltest2 ) ;
torture_suite_add_2smb_test ( suite , " deltest3 " , deltest3 ) ;
torture_suite_add_2smb_test ( suite , " deltest4 " , deltest4 ) ;
torture_suite_add_2smb_test ( suite , " deltest5 " , deltest5 ) ;
torture_suite_add_2smb_test ( suite , " deltest6 " , deltest6 ) ;
torture_suite_add_2smb_test ( suite , " deltest7 " , deltest7 ) ;
torture_suite_add_2smb_test ( suite , " deltest8 " , deltest8 ) ;
torture_suite_add_2smb_test ( suite , " deltest9 " , deltest9 ) ;
torture_suite_add_2smb_test ( suite , " deltest10 " , deltest10 ) ;
torture_suite_add_2smb_test ( suite , " deltest11 " , deltest11 ) ;
torture_suite_add_2smb_test ( suite , " deltest12 " , deltest12 ) ;
torture_suite_add_2smb_test ( suite , " deltest13 " , deltest13 ) ;
torture_suite_add_2smb_test ( suite , " deltest14 " , deltest14 ) ;
torture_suite_add_2smb_test ( suite , " deltest15 " , deltest15 ) ;
2006-10-18 12:23:35 +00:00
torture_suite_add_2smb_test ( suite , " deltest16 " , deltest16 ) ;
torture_suite_add_2smb_test ( suite , " deltest17 " , deltest17 ) ;
torture_suite_add_2smb_test ( suite , " deltest18 " , deltest18 ) ;
torture_suite_add_2smb_test ( suite , " deltest19 " , deltest19 ) ;
torture_suite_add_2smb_test ( suite , " deltest20 " , deltest20 ) ;
2007-05-23 21:14:05 +00:00
torture_suite_add_2smb_test ( suite , " deltest20a " , deltest20a ) ;
2007-05-23 23:11:16 +00:00
torture_suite_add_2smb_test ( suite , " deltest20b " , deltest20b ) ;
2006-10-16 13:06:41 +00:00
torture_suite_add_simple_test ( suite , " deltest21 " , deltest21 ) ;
2007-01-04 16:26:15 +00:00
torture_suite_add_simple_test ( suite , " deltest22 " , deltest22 ) ;
2006-02-06 19:43:24 +00:00
2006-10-16 13:06:41 +00:00
return suite ;
2004-10-24 09:08:52 +00:00
}