2004-10-24 13:08:52 +04: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 18:40:05 +03:00
# include "libcli/libcli.h"
2006-01-03 16:41:17 +03:00
# include "torture/torture.h"
2005-02-10 08:09:35 +03:00
# include "system/filesys.h"
2005-08-21 01:28:30 +04:00
# include "libcli/raw/libcliraw.h"
2004-10-24 13:08:52 +04:00
2006-02-04 17:08:24 +03:00
# include "torture/raw/proto.h"
2005-07-06 17:24:38 +04:00
static BOOL check_delete_on_close ( struct smbcli_state * cli , int fnum ,
2006-02-27 06:23:28 +03:00
const char * fname , BOOL expect_it ,
const char * where )
2005-07-06 13:50:31 +04:00
{
TALLOC_CTX * mem_ctx = talloc_init ( " single_search " ) ;
union smb_search_data data ;
NTSTATUS status ;
time_t c_time , a_time , m_time ;
size_t size ;
uint16_t mode ;
2005-07-06 17:24:38 +04:00
BOOL res = True ;
2005-07-06 13:50:31 +04:00
status = torture_single_search ( cli , mem_ctx ,
fname , RAW_SEARCH_FULL_DIRECTORY_INFO ,
2005-07-06 18:56:45 +04:00
FILE_ATTRIBUTE_DIRECTORY ,
2005-07-06 13:50:31 +04:00
& data ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " (%s) single_search failed (%s) \n " ,
2006-02-27 06:23:28 +03:00
where , nt_errstr ( status ) ) ;
2005-07-06 17:24:38 +04:00
res = False ;
goto done ;
}
if ( fnum ! = - 1 ) {
union smb_fileinfo io ;
int nlink = expect_it ? 0 : 1 ;
io . all_info . level = RAW_FILEINFO_ALL_INFO ;
2006-03-13 01:48:25 +03:00
io . all_info . in . file . fnum = fnum ;
2005-07-06 17:24:38 +04:00
status = smb_raw_fileinfo ( cli - > tree , mem_ctx , & io ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2006-02-27 06:23:28 +03:00
printf ( " (%s) qfileinfo failed (%s) \n " , where ,
2005-07-06 17:24:38 +04:00
nt_errstr ( status ) ) ;
res = False ;
goto done ;
}
if ( expect_it ! = io . all_info . out . delete_pending ) {
2006-02-27 06:23:28 +03:00
printf ( " %s - Expected del_on_close flag %d, qfileinfo/all_info gave %d \n " ,
where , expect_it , io . all_info . out . delete_pending ) ;
2005-07-06 17:24:38 +04:00
res = False ;
goto done ;
}
if ( nlink ! = io . all_info . out . nlink ) {
2006-02-27 06:23:28 +03:00
printf ( " %s - Expected nlink %d, qfileinfo/all_info gave %d \n " ,
where , nlink , io . all_info . out . nlink ) ;
2005-07-06 17:24:38 +04:00
res = False ;
goto done ;
}
io . standard_info . level = RAW_FILEINFO_STANDARD_INFO ;
2006-03-13 01:48:25 +03:00
io . standard_info . in . file . fnum = fnum ;
2005-07-06 17:24:38 +04:00
status = smb_raw_fileinfo ( cli - > tree , mem_ctx , & io ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2006-02-27 06:23:28 +03:00
printf ( " (%s) qpathinfo failed (%s) \n " , where ,
2005-07-06 17:24:38 +04:00
nt_errstr ( status ) ) ;
res = False ;
goto done ;
}
if ( expect_it ! = io . standard_info . out . delete_pending ) {
2006-02-27 06:23:28 +03:00
printf ( " %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 17:24:38 +04:00
res = False ;
goto done ;
}
if ( nlink ! = io . standard_info . out . nlink ) {
2006-02-27 06:23:28 +03:00
printf ( " %s - Expected nlink %d, qfileinfo/standard_info gave %d \n " ,
where , nlink , io . all_info . out . nlink ) ;
2005-07-06 17:24:38 +04:00
res = False ;
goto done ;
}
2005-07-06 13:50:31 +04:00
}
status = smbcli_qpathinfo ( cli - > tree , fname ,
& c_time , & a_time , & m_time ,
& size , & mode ) ;
if ( expect_it ) {
if ( ! NT_STATUS_EQUAL ( status , NT_STATUS_DELETE_PENDING ) ) {
printf ( " (%s) qpathinfo did not give correct error "
" code (%s) -- NT_STATUS_DELETE_PENDING "
2006-02-27 06:23:28 +03:00
" expected \n " , where ,
2005-07-06 13:50:31 +04:00
nt_errstr ( status ) ) ;
2005-07-06 17:24:38 +04:00
res = False ;
goto done ;
2005-07-06 13:50:31 +04:00
}
} else {
if ( ! NT_STATUS_IS_OK ( status ) ) {
2006-02-27 06:23:28 +03:00
printf ( " (%s) qpathinfo failed (%s) \n " , where ,
2005-07-06 13:50:31 +04:00
nt_errstr ( status ) ) ;
2005-07-06 17:24:38 +04:00
res = False ;
goto done ;
2005-07-06 13:50:31 +04:00
}
}
2005-07-06 17:24:38 +04:00
done :
talloc_free ( mem_ctx ) ;
return res ;
2005-07-06 13:50:31 +04:00
}
2004-10-24 13:08:52 +04:00
2005-08-21 01:28:30 +04:00
# define CHECK_STATUS(_cli, _expected) do { \
if ( ! NT_STATUS_EQUAL ( _cli - > tree - > session - > transport - > error . e . nt_status , _expected ) ) { \
printf ( " (%d) Incorrect status %s - should be %s \n " , \
__LINE__ , nt_errstr ( _cli - > tree - > session - > transport - > error . e . nt_status ) , nt_errstr ( _expected ) ) ; \
correct = False ; \
goto fail ; \
} } while ( 0 )
2006-02-03 05:07:22 +03:00
const char * fname = " \\ delete.file " ;
const char * fname_new = " \\ delete.new " ;
const char * dirname = " \\ delete.dir " ;
2006-02-01 07:41:54 +03:00
2006-02-03 05:07:22 +03:00
static void del_clean_area ( struct smbcli_state * cli1 , struct smbcli_state * cli2 )
{
2005-07-06 18:56:45 +04:00
smbcli_deltree ( cli1 - > tree , dirname ) ;
2004-10-24 13:08:52 +04:00
smbcli_setatr ( cli1 - > tree , fname , 0 , 0 ) ;
smbcli_unlink ( cli1 - > tree , fname ) ;
2006-02-03 05:07:22 +03:00
smbcli_setatr ( cli1 - > tree , fname_new , 0 , 0 ) ;
smbcli_unlink ( cli1 - > tree , fname_new ) ;
smb_raw_exit ( cli1 - > session ) ;
smb_raw_exit ( cli2 - > session ) ;
}
/* Test 1 - this should delete the file on close. */
static BOOL deltest1 ( struct smbcli_state * cli1 , struct smbcli_state * cli2 )
{
int fnum1 = - 1 ;
del_clean_area ( cli1 , cli2 ) ;
2004-11-30 07:33:27 +03:00
fnum1 = smbcli_nt_create_full ( cli1 - > tree , fname , 0 ,
2004-12-02 07:37:36 +03:00
SEC_RIGHTS_FILE_ALL ,
2004-11-30 07:33:27 +03:00
FILE_ATTRIBUTE_NORMAL ,
NTCREATEX_SHARE_ACCESS_DELETE , NTCREATEX_DISP_OVERWRITE_IF ,
NTCREATEX_OPTIONS_DELETE_ON_CLOSE , 0 ) ;
2004-10-24 13:08:52 +04:00
if ( fnum1 = = - 1 ) {
2004-10-24 14:27:38 +04:00
printf ( " (%s) open of %s failed (%s) \n " ,
__location__ , fname , smbcli_errstr ( cli1 - > tree ) ) ;
2006-02-03 05:07:22 +03:00
return False ;
2004-10-24 13:08:52 +04:00
}
if ( NT_STATUS_IS_ERR ( smbcli_close ( cli1 - > tree , fnum1 ) ) ) {
2004-10-24 14:27:38 +04:00
printf ( " (%s) close failed (%s) \n " ,
__location__ , smbcli_errstr ( cli1 - > tree ) ) ;
2006-02-03 05:07:22 +03:00
return False ;
2004-10-24 13:08:52 +04:00
}
fnum1 = smbcli_open ( cli1 - > tree , fname , O_RDWR , DENY_NONE ) ;
if ( fnum1 ! = - 1 ) {
2004-10-24 14:27:38 +04:00
printf ( " (%s) open of %s succeeded (should fail) \n " ,
__location__ , fname ) ;
2006-02-03 05:07:22 +03:00
return False ;
2004-10-24 13:08:52 +04:00
}
2006-02-27 06:23:28 +03:00
2004-10-24 13:08:52 +04:00
printf ( " first delete on close test succeeded. \n " ) ;
2006-02-03 05:07:22 +03:00
return True ;
}
/* Test 2 - this should delete the file on close. */
static BOOL deltest2 ( struct smbcli_state * cli1 , struct smbcli_state * cli2 )
{
int fnum1 = - 1 ;
del_clean_area ( cli1 , cli2 ) ;
2004-11-30 07:33:27 +03:00
fnum1 = smbcli_nt_create_full ( cli1 - > tree , fname , 0 ,
2004-12-02 07:37:36 +03:00
SEC_RIGHTS_FILE_ALL ,
2004-11-30 07:33:27 +03:00
FILE_ATTRIBUTE_NORMAL , NTCREATEX_SHARE_ACCESS_NONE ,
NTCREATEX_DISP_OVERWRITE_IF , 0 , 0 ) ;
2004-10-24 13:08:52 +04:00
if ( fnum1 = = - 1 ) {
2004-10-24 14:27:38 +04:00
printf ( " (%s) open of %s failed (%s) \n " ,
__location__ , fname , smbcli_errstr ( cli1 - > tree ) ) ;
2006-02-03 05:07:22 +03:00
return False ;
2004-10-24 13:08:52 +04:00
}
if ( NT_STATUS_IS_ERR ( smbcli_nt_delete_on_close ( cli1 - > tree , fnum1 , True ) ) ) {
2004-10-24 14:27:38 +04:00
printf ( " (%s) setting delete_on_close failed (%s) \n " ,
__location__ , smbcli_errstr ( cli1 - > tree ) ) ;
2006-02-03 05:07:22 +03:00
return False ;
2004-10-24 13:08:52 +04:00
}
if ( NT_STATUS_IS_ERR ( smbcli_close ( cli1 - > tree , fnum1 ) ) ) {
2004-10-24 14:27:38 +04:00
printf ( " (%s) close failed (%s) \n " ,
__location__ , smbcli_errstr ( cli1 - > tree ) ) ;
2006-02-03 05:07:22 +03:00
return False ;
2004-10-24 13:08:52 +04:00
}
fnum1 = smbcli_open ( cli1 - > tree , fname , O_RDONLY , DENY_NONE ) ;
if ( fnum1 ! = - 1 ) {
2004-10-24 14:27:38 +04:00
printf ( " (%s) open of %s succeeded should have been deleted on close ! \n " ,
__location__ , fname ) ;
2004-10-24 13:08:52 +04:00
if ( NT_STATUS_IS_ERR ( smbcli_close ( cli1 - > tree , fnum1 ) ) ) {
2004-10-24 14:27:38 +04:00
printf ( " (%s) close failed (%s) \n " ,
__location__ , smbcli_errstr ( cli1 - > tree ) ) ;
2006-02-03 05:07:22 +03:00
return False ;
2004-10-24 13:08:52 +04:00
}
smbcli_unlink ( cli1 - > tree , fname ) ;
2006-02-03 05:07:22 +03:00
} else {
2004-10-24 13:08:52 +04:00
printf ( " second delete on close test succeeded. \n " ) ;
2006-02-03 05:07:22 +03:00
}
return True ;
}
2006-02-01 07:41:54 +03:00
2006-02-03 05:07:22 +03:00
/* Test 3 - ... */
static BOOL deltest3 ( struct smbcli_state * cli1 , struct smbcli_state * cli2 )
{
int fnum1 = - 1 ;
int fnum2 = - 1 ;
del_clean_area ( cli1 , cli2 ) ;
2004-10-24 13:08:52 +04:00
2004-10-24 14:27:38 +04:00
fnum1 = smbcli_nt_create_full ( cli1 - > tree , fname , 0 ,
2004-12-02 07:37:36 +03:00
SEC_RIGHTS_FILE_ALL ,
2004-10-24 14:27:38 +04:00
FILE_ATTRIBUTE_NORMAL ,
NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE ,
NTCREATEX_DISP_OVERWRITE_IF , 0 , 0 ) ;
2004-10-24 13:08:52 +04:00
if ( fnum1 = = - 1 ) {
2004-10-24 14:27:38 +04:00
printf ( " (%s) open - 1 of %s failed (%s) \n " ,
__location__ , fname , smbcli_errstr ( cli1 - > tree ) ) ;
2006-02-03 05:07:22 +03:00
return False ;
2004-10-24 13:08:52 +04:00
}
/* This should fail with a sharing violation - open for delete is only compatible
with SHARE_DELETE . */
2004-10-24 14:27:38 +04:00
fnum2 = smbcli_nt_create_full ( cli1 - > tree , fname , 0 ,
2004-11-30 07:33:27 +03:00
SEC_RIGHTS_FILE_READ ,
2004-10-24 14:27:38 +04:00
FILE_ATTRIBUTE_NORMAL ,
NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE ,
NTCREATEX_DISP_OPEN , 0 , 0 ) ;
2004-10-24 13:08:52 +04:00
if ( fnum2 ! = - 1 ) {
2004-10-24 14:27:38 +04:00
printf ( " (%s) open - 2 of %s succeeded - should have failed. \n " ,
__location__ , fname ) ;
2006-02-03 05:07:22 +03:00
return False ;
2004-10-24 13:08:52 +04:00
}
/* This should succeed. */
2004-11-30 07:33:27 +03: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 13:08:52 +04:00
if ( fnum2 = = - 1 ) {
2004-10-24 14:27:38 +04:00
printf ( " (%s) open - 2 of %s failed (%s) \n " ,
__location__ , fname , smbcli_errstr ( cli1 - > tree ) ) ;
2006-02-03 05:07:22 +03:00
return False ;
2004-10-24 13:08:52 +04:00
}
if ( NT_STATUS_IS_ERR ( smbcli_nt_delete_on_close ( cli1 - > tree , fnum1 , True ) ) ) {
2004-10-24 14:27:38 +04:00
printf ( " (%s) setting delete_on_close failed (%s) \n " ,
__location__ , smbcli_errstr ( cli1 - > tree ) ) ;
2006-02-03 05:07:22 +03:00
return False ;
2004-10-24 13:08:52 +04:00
}
if ( NT_STATUS_IS_ERR ( smbcli_close ( cli1 - > tree , fnum1 ) ) ) {
2004-10-24 14:27:38 +04:00
printf ( " (%s) close 1 failed (%s) \n " ,
__location__ , smbcli_errstr ( cli1 - > tree ) ) ;
2006-02-03 05:07:22 +03:00
return False ;
2004-10-24 13:08:52 +04:00
}
if ( NT_STATUS_IS_ERR ( smbcli_close ( cli1 - > tree , fnum2 ) ) ) {
2004-10-24 14:27:38 +04:00
printf ( " (%s) close 2 failed (%s) \n " ,
__location__ , smbcli_errstr ( cli1 - > tree ) ) ;
2006-02-03 05:07:22 +03:00
return False ;
2004-10-24 13:08:52 +04: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 14:27:38 +04:00
printf ( " (%s) open of %s succeeded should have been deleted on close ! \n " ,
__location__ , fname ) ;
2004-10-24 13:08:52 +04:00
if ( NT_STATUS_IS_ERR ( smbcli_close ( cli1 - > tree , fnum1 ) ) ) {
2004-10-24 14:27:38 +04:00
printf ( " (%s) close failed (%s) \n " ,
__location__ , smbcli_errstr ( cli1 - > tree ) ) ;
2004-10-24 13:08:52 +04:00
}
smbcli_unlink ( cli1 - > tree , fname ) ;
2006-02-03 05:07:22 +03:00
return False ;
} else {
2004-10-24 13:08:52 +04:00
printf ( " third delete on close test succeeded. \n " ) ;
2006-02-03 05:07:22 +03:00
}
return True ;
}
2004-10-24 13:08:52 +04:00
2006-02-03 05:07:22 +03:00
/* Test 4 ... */
static BOOL deltest4 ( struct smbcli_state * cli1 , struct smbcli_state * cli2 )
{
int fnum1 = - 1 ;
int fnum2 = - 1 ;
BOOL correct = True ;
2006-02-01 07:41:54 +03:00
2006-02-03 05:07:22 +03:00
del_clean_area ( cli1 , cli2 ) ;
2004-10-24 13:08:52 +04:00
fnum1 = smbcli_nt_create_full ( cli1 - > tree , fname , 0 ,
2004-11-30 07:33:27 +03: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 13:08:52 +04:00
if ( fnum1 = = - 1 ) {
2004-10-24 14:27:38 +04:00
printf ( " (%s) open of %s failed (%s) \n " ,
__location__ , fname , smbcli_errstr ( cli1 - > tree ) ) ;
2006-02-03 05:07:22 +03:00
return False ;
2004-10-24 13:08:52 +04:00
}
/* This should succeed. */
2004-11-30 07:33:27 +03:00
fnum2 = smbcli_nt_create_full ( cli1 - > tree , fname , 0 ,
SEC_RIGHTS_FILE_READ ,
2004-10-24 16:38:32 +04:00
FILE_ATTRIBUTE_NORMAL ,
NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE |
NTCREATEX_SHARE_ACCESS_DELETE ,
NTCREATEX_DISP_OPEN , 0 , 0 ) ;
2004-10-24 13:08:52 +04:00
if ( fnum2 = = - 1 ) {
2004-10-24 14:27:38 +04:00
printf ( " (%s) open - 2 of %s failed (%s) \n " ,
__location__ , fname , smbcli_errstr ( cli1 - > tree ) ) ;
2006-02-03 05:07:22 +03:00
return False ;
2004-10-24 13:08:52 +04:00
}
if ( NT_STATUS_IS_ERR ( smbcli_close ( cli1 - > tree , fnum2 ) ) ) {
2004-10-24 14:27:38 +04:00
printf ( " (%s) close - 1 failed (%s) \n " ,
__location__ , smbcli_errstr ( cli1 - > tree ) ) ;
2006-02-03 05:07:22 +03:00
return False ;
2004-10-24 13:08:52 +04:00
}
if ( NT_STATUS_IS_ERR ( smbcli_nt_delete_on_close ( cli1 - > tree , fnum1 , True ) ) ) {
2004-10-24 14:27:38 +04:00
printf ( " (%s) setting delete_on_close failed (%s) \n " ,
__location__ , smbcli_errstr ( cli1 - > tree ) ) ;
2006-02-03 05:07:22 +03:00
return False ;
2004-10-24 13:08:52 +04:00
}
/* This should fail - no more opens once delete on close set. */
2004-10-24 16:38:32 +04:00
fnum2 = smbcli_nt_create_full ( cli1 - > tree , fname , 0 ,
2004-11-30 07:33:27 +03:00
SEC_RIGHTS_FILE_READ ,
2004-10-24 16:38:32 +04:00
FILE_ATTRIBUTE_NORMAL ,
NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE | NTCREATEX_SHARE_ACCESS_DELETE ,
NTCREATEX_DISP_OPEN , 0 , 0 ) ;
2004-10-24 13:08:52 +04:00
if ( fnum2 ! = - 1 ) {
2004-10-24 14:27:38 +04:00
printf ( " (%s) open - 3 of %s succeeded ! Should have failed. \n " ,
__location__ , fname ) ;
2006-02-03 05:07:22 +03:00
return False ;
2005-08-21 01:28:30 +04:00
}
CHECK_STATUS ( cli1 , NT_STATUS_DELETE_PENDING ) ;
2004-10-24 13:08:52 +04:00
if ( NT_STATUS_IS_ERR ( smbcli_close ( cli1 - > tree , fnum1 ) ) ) {
2004-10-24 14:27:38 +04:00
printf ( " (%s) close - 2 failed (%s) \n " ,
__location__ , smbcli_errstr ( cli1 - > tree ) ) ;
2006-02-03 05:07:22 +03:00
return False ;
2004-10-24 13:08:52 +04:00
}
2006-02-01 07:41:54 +03:00
printf ( " fourth delete on close test succeeded. \n " ) ;
2006-02-03 05:07:22 +03:00
fail :
return correct ;
}
/* Test 5 ... */
static BOOL deltest5 ( struct smbcli_state * cli1 , struct smbcli_state * cli2 )
{
int fnum1 = - 1 ;
del_clean_area ( cli1 , cli2 ) ;
2004-10-24 13:08:52 +04:00
fnum1 = smbcli_open ( cli1 - > tree , fname , O_RDWR | O_CREAT , DENY_NONE ) ;
if ( fnum1 = = - 1 ) {
2004-10-24 14:27:38 +04:00
printf ( " (%s) open of %s failed (%s) \n " ,
__location__ , fname , smbcli_errstr ( cli1 - > tree ) ) ;
2006-02-03 05:07:22 +03:00
return False ;
2004-10-24 13:08:52 +04:00
}
/* This should fail - only allowed on NT opens with DELETE access. */
if ( NT_STATUS_IS_OK ( smbcli_nt_delete_on_close ( cli1 - > tree , fnum1 , True ) ) ) {
2004-10-24 14:27:38 +04:00
printf ( " (%s) setting delete_on_close on OpenX file succeeded - should fail ! \n " ,
__location__ ) ;
2006-02-03 05:07:22 +03:00
return False ;
2004-10-24 13:08:52 +04:00
}
if ( NT_STATUS_IS_ERR ( smbcli_close ( cli1 - > tree , fnum1 ) ) ) {
2004-10-24 14:27:38 +04:00
printf ( " (%s) close - 2 failed (%s) \n " ,
__location__ , smbcli_errstr ( cli1 - > tree ) ) ;
2006-02-03 05:07:22 +03:00
return False ;
2004-10-24 13:08:52 +04:00
}
2006-02-01 07:41:54 +03:00
2004-10-24 13:08:52 +04:00
printf ( " fifth delete on close test succeeded. \n " ) ;
2006-02-03 05:07:22 +03:00
return True ;
}
/* Test 6 ... */
static BOOL deltest6 ( struct smbcli_state * cli1 , struct smbcli_state * cli2 )
{
int fnum1 = - 1 ;
del_clean_area ( cli1 , cli2 ) ;
2004-10-24 13:08:52 +04:00
fnum1 = smbcli_nt_create_full ( cli1 - > tree , fname , 0 ,
2004-11-30 07:33:27 +03:00
SEC_FILE_READ_DATA | SEC_FILE_WRITE_DATA ,
2004-10-24 13:08:52 +04:00
FILE_ATTRIBUTE_NORMAL ,
NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE |
NTCREATEX_SHARE_ACCESS_DELETE ,
NTCREATEX_DISP_OVERWRITE_IF , 0 , 0 ) ;
if ( fnum1 = = - 1 ) {
2004-10-24 14:27:38 +04:00
printf ( " (%s) open of %s failed (%s) \n " ,
__location__ , fname , smbcli_errstr ( cli1 - > tree ) ) ;
2006-02-03 05:07:22 +03:00
return False ;
2004-10-24 13:08:52 +04:00
}
/* This should fail - only allowed on NT opens with DELETE access. */
if ( NT_STATUS_IS_OK ( smbcli_nt_delete_on_close ( cli1 - > tree , fnum1 , True ) ) ) {
2004-10-24 14:27:38 +04:00
printf ( " (%s) setting delete_on_close on file with no delete access succeeded - should fail ! \n " ,
__location__ ) ;
2006-02-03 05:07:22 +03:00
return False ;
2004-10-24 13:08:52 +04:00
}
if ( NT_STATUS_IS_ERR ( smbcli_close ( cli1 - > tree , fnum1 ) ) ) {
2004-10-24 14:27:38 +04:00
printf ( " (%s) close - 2 failed (%s) \n " ,
__location__ , smbcli_errstr ( cli1 - > tree ) ) ;
2006-02-03 05:07:22 +03:00
return False ;
2004-10-24 13:08:52 +04:00
}
printf ( " sixth delete on close test succeeded. \n " ) ;
2006-02-03 05:07:22 +03:00
return True ;
}
/* Test 7 ... */
static BOOL deltest7 ( struct smbcli_state * cli1 , struct smbcli_state * cli2 )
{
int fnum1 = - 1 ;
BOOL correct = True ;
del_clean_area ( cli1 , cli2 ) ;
2004-10-24 13:08:52 +04:00
fnum1 = smbcli_nt_create_full ( cli1 - > tree , fname , 0 ,
2004-11-30 07:33:27 +03: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 13:08:52 +04:00
if ( fnum1 = = - 1 ) {
2004-10-24 14:27:38 +04:00
printf ( " (%s) open of %s failed (%s) \n " ,
__location__ , fname , smbcli_errstr ( cli1 - > tree ) ) ;
2004-10-24 13:08:52 +04:00
correct = False ;
goto fail ;
}
if ( NT_STATUS_IS_ERR ( smbcli_nt_delete_on_close ( cli1 - > tree , fnum1 , True ) ) ) {
2004-10-24 14:27:38 +04:00
printf ( " (%s) setting delete_on_close on file failed ! \n " ,
__location__ ) ;
2004-10-24 13:08:52 +04:00
correct = False ;
goto fail ;
}
2005-07-06 13:50:31 +04:00
2006-02-27 06:23:28 +03:00
correct & = check_delete_on_close ( cli1 , fnum1 , fname , True , __location__ ) ;
2004-10-24 13:08:52 +04:00
if ( NT_STATUS_IS_ERR ( smbcli_nt_delete_on_close ( cli1 - > tree , fnum1 , False ) ) ) {
2004-10-24 14:27:38 +04:00
printf ( " (%s) unsetting delete_on_close on file failed ! \n " ,
__location__ ) ;
2004-10-24 13:08:52 +04:00
correct = False ;
goto fail ;
}
2006-02-27 06:23:28 +03:00
correct & = check_delete_on_close ( cli1 , fnum1 , fname , False , __location__ ) ;
2005-07-06 13:50:31 +04:00
2004-10-24 13:08:52 +04:00
if ( NT_STATUS_IS_ERR ( smbcli_close ( cli1 - > tree , fnum1 ) ) ) {
2004-10-24 14:27:38 +04:00
printf ( " (%s) close - 2 failed (%s) \n " ,
__location__ , smbcli_errstr ( cli1 - > tree ) ) ;
2004-10-24 13:08:52 +04:00
correct = False ;
goto fail ;
}
/* This next open should succeed - we reset the flag. */
fnum1 = smbcli_open ( cli1 - > tree , fname , O_RDONLY , DENY_NONE ) ;
if ( fnum1 = = - 1 ) {
2004-10-24 14:27:38 +04:00
printf ( " (%s) open of %s failed (%s) \n " ,
__location__ , fname , smbcli_errstr ( cli1 - > tree ) ) ;
2004-10-24 13:08:52 +04:00
correct = False ;
goto fail ;
}
if ( NT_STATUS_IS_ERR ( smbcli_close ( cli1 - > tree , fnum1 ) ) ) {
2004-10-24 14:27:38 +04:00
printf ( " (%s) close - 2 failed (%s) \n " ,
__location__ , smbcli_errstr ( cli1 - > tree ) ) ;
2004-10-24 13:08:52 +04:00
correct = False ;
goto fail ;
}
printf ( " seventh delete on close test succeeded. \n " ) ;
2006-02-03 05:07:22 +03:00
fail :
return correct ;
}
/* Test 8 ... */
static BOOL deltest8 ( struct smbcli_state * cli1 , struct smbcli_state * cli2 )
{
int fnum1 = - 1 ;
int fnum2 = - 1 ;
BOOL correct = True ;
del_clean_area ( cli1 , cli2 ) ;
2004-11-30 07:33:27 +03: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 13:08:52 +04:00
if ( fnum1 = = - 1 ) {
2004-10-24 14:27:38 +04:00
printf ( " (%s) open of %s failed (%s) \n " ,
__location__ , fname , smbcli_errstr ( cli1 - > tree ) ) ;
2004-10-24 13:08:52 +04:00
correct = False ;
goto fail ;
}
2004-11-30 07:33:27 +03: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 13:08:52 +04:00
if ( fnum2 = = - 1 ) {
2004-10-24 14:27:38 +04:00
printf ( " (%s) open of %s failed (%s) \n " ,
__location__ , fname , smbcli_errstr ( cli1 - > tree ) ) ;
2004-10-24 13:08:52 +04:00
correct = False ;
goto fail ;
}
if ( NT_STATUS_IS_ERR ( smbcli_nt_delete_on_close ( cli1 - > tree , fnum1 , True ) ) ) {
2004-10-24 14:27:38 +04:00
printf ( " (%s) setting delete_on_close on file failed ! \n " ,
__location__ ) ;
2004-10-24 13:08:52 +04:00
correct = False ;
goto fail ;
}
2005-07-06 13:50:31 +04:00
2006-02-27 06:23:28 +03:00
correct & = check_delete_on_close ( cli1 , fnum1 , fname , True , __location__ ) ;
correct & = check_delete_on_close ( cli2 , fnum2 , fname , True , __location__ ) ;
2005-07-06 12:13:11 +04:00
2004-10-24 13:08:52 +04:00
if ( NT_STATUS_IS_ERR ( smbcli_close ( cli1 - > tree , fnum1 ) ) ) {
2004-10-24 14:27:38 +04:00
printf ( " (%s) close - 1 failed (%s) \n " ,
__location__ , smbcli_errstr ( cli1 - > tree ) ) ;
2004-10-24 13:08:52 +04:00
correct = False ;
goto fail ;
}
2006-02-27 06:23:28 +03:00
correct & = check_delete_on_close ( cli1 , - 1 , fname , True , __location__ ) ;
correct & = check_delete_on_close ( cli2 , fnum2 , fname , True , __location__ ) ;
2005-07-06 13:50:31 +04:00
2004-10-24 13:08:52 +04:00
if ( NT_STATUS_IS_ERR ( smbcli_close ( cli2 - > tree , fnum2 ) ) ) {
2004-10-24 14:27:38 +04:00
printf ( " (%s) close - 2 failed (%s) \n " ,
__location__ , smbcli_errstr ( cli2 - > tree ) ) ;
2004-10-24 13:08:52 +04:00
correct = False ;
goto fail ;
}
/* This should fail.. */
fnum1 = smbcli_open ( cli1 - > tree , fname , O_RDONLY , DENY_NONE ) ;
if ( fnum1 ! = - 1 ) {
2004-10-24 14:27:38 +04:00
printf ( " (%s) open of %s succeeded should have been deleted on close ! \n " ,
__location__ , fname ) ;
2004-10-24 13:08:52 +04:00
correct = False ;
2006-02-03 05:07:22 +03:00
} else {
2004-10-24 13:08:52 +04:00
printf ( " eighth delete on close test succeeded. \n " ) ;
2006-02-03 05:07:22 +03:00
}
2004-10-24 13:08:52 +04:00
2006-02-03 05:07:22 +03:00
fail :
return correct ;
}
/* Test 9 ... */
static BOOL deltest9 ( struct smbcli_state * cli1 , struct smbcli_state * cli2 )
{
int fnum1 = - 1 ;
del_clean_area ( cli1 , cli2 ) ;
2006-02-01 07:41:54 +03:00
2004-10-24 13:08:52 +04:00
/* This should fail - we need to set DELETE_ACCESS. */
2004-10-24 16:38:32 +04:00
fnum1 = smbcli_nt_create_full ( cli1 - > tree , fname , 0 ,
2004-11-30 07:33:27 +03:00
SEC_FILE_READ_DATA | SEC_FILE_WRITE_DATA ,
2004-10-24 16:38:32 +04:00
FILE_ATTRIBUTE_NORMAL ,
NTCREATEX_SHARE_ACCESS_NONE ,
NTCREATEX_DISP_OVERWRITE_IF ,
NTCREATEX_OPTIONS_DELETE_ON_CLOSE , 0 ) ;
2004-10-24 13:08:52 +04:00
if ( fnum1 ! = - 1 ) {
2004-10-24 14:27:38 +04:00
printf ( " (%s) open of %s succeeded should have failed! \n " ,
__location__ , fname ) ;
2006-02-03 05:07:22 +03:00
return False ;
2004-10-24 13:08:52 +04:00
}
printf ( " ninth delete on close test succeeded. \n " ) ;
2006-02-03 05:07:22 +03:00
return True ;
}
/* Test 10 ... */
static BOOL deltest10 ( struct smbcli_state * cli1 , struct smbcli_state * cli2 )
{
int fnum1 = - 1 ;
BOOL correct = True ;
del_clean_area ( cli1 , cli2 ) ;
2004-10-24 13:08:52 +04:00
2004-10-24 16:38:32 +04:00
fnum1 = smbcli_nt_create_full ( cli1 - > tree , fname , 0 ,
2004-11-30 07:33:27 +03:00
SEC_FILE_READ_DATA |
SEC_FILE_WRITE_DATA |
SEC_STD_DELETE ,
2004-10-24 16:38:32 +04:00
FILE_ATTRIBUTE_NORMAL ,
NTCREATEX_SHARE_ACCESS_NONE ,
NTCREATEX_DISP_OVERWRITE_IF ,
NTCREATEX_OPTIONS_DELETE_ON_CLOSE , 0 ) ;
2004-10-24 13:08:52 +04:00
if ( fnum1 = = - 1 ) {
2004-10-24 14:27:38 +04:00
printf ( " (%s) open of %s failed (%s) \n " ,
__location__ , fname , smbcli_errstr ( cli1 - > tree ) ) ;
2004-10-24 13:08:52 +04:00
correct = False ;
goto fail ;
}
/* This should delete the file. */
if ( NT_STATUS_IS_ERR ( smbcli_close ( cli1 - > tree , fnum1 ) ) ) {
2004-10-24 14:27:38 +04:00
printf ( " (%s) close failed (%s) \n " ,
__location__ , smbcli_errstr ( cli1 - > tree ) ) ;
2004-10-24 13:08:52 +04:00
correct = False ;
goto fail ;
}
/* This should fail.. */
fnum1 = smbcli_open ( cli1 - > tree , fname , O_RDONLY , DENY_NONE ) ;
if ( fnum1 ! = - 1 ) {
2004-10-24 14:27:38 +04:00
printf ( " (%s) open of %s succeeded should have been deleted on close ! \n " ,
__location__ , fname ) ;
2004-10-24 13:08:52 +04:00
correct = False ;
2006-02-03 05:07:22 +03:00
goto fail ;
} else {
2004-10-24 13:08:52 +04:00
printf ( " tenth delete on close test succeeded. \n " ) ;
2006-02-03 05:07:22 +03:00
}
2004-10-24 13:08:52 +04:00
2006-02-03 05:07:22 +03:00
fail :
2006-02-01 07:41:54 +03:00
2006-02-03 05:07:22 +03:00
return correct ;
}
2004-10-24 13:08:52 +04:00
2006-02-03 05:07:22 +03:00
/* Test 11 ... */
static BOOL deltest11 ( struct smbcli_state * cli1 , struct smbcli_state * cli2 )
{
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 07:33:27 +03:00
2004-10-24 16:55:12 +04:00
fnum1 = smbcli_nt_create_full ( cli1 - > tree , fname , 0 ,
2004-12-02 07:37:36 +03:00
SEC_RIGHTS_FILE_ALL ,
2004-10-24 16:55:12 +04:00
FILE_ATTRIBUTE_READONLY ,
NTCREATEX_SHARE_ACCESS_NONE ,
NTCREATEX_DISP_OVERWRITE_IF , 0 , 0 ) ;
2004-10-24 13:08:52 +04:00
if ( fnum1 = = - 1 ) {
2004-10-24 14:27:38 +04:00
printf ( " (%s) open of %s failed (%s) \n " ,
__location__ , fname , smbcli_errstr ( cli1 - > tree ) ) ;
2006-02-03 05:07:22 +03:00
return False ;
2004-10-24 13:08:52 +04:00
}
status = smbcli_nt_delete_on_close ( cli1 - > tree , fnum1 , True ) ;
2005-07-04 09:05:28 +04:00
if ( ! NT_STATUS_EQUAL ( status , NT_STATUS_CANNOT_DELETE ) ) {
2004-10-24 14:27:38 +04:00
printf ( " (%s) setting delete_on_close should fail with NT_STATUS_CANNOT_DELETE. Got %s instead) \n " ,
__location__ , smbcli_errstr ( cli1 - > tree ) ) ;
2006-02-03 05:07:22 +03:00
return False ;
2004-10-24 13:08:52 +04:00
}
if ( NT_STATUS_IS_ERR ( smbcli_close ( cli1 - > tree , fnum1 ) ) ) {
2004-10-24 14:27:38 +04:00
printf ( " (%s) close failed (%s) \n " ,
__location__ , smbcli_errstr ( cli1 - > tree ) ) ;
2006-02-03 05:07:22 +03:00
return False ;
2004-10-24 13:08:52 +04:00
}
2006-02-03 05:07:22 +03:00
printf ( " eleventh delete on close test succeeded. \n " ) ;
return True ;
}
2006-02-01 07:41:54 +03:00
2006-02-03 05:07:22 +03:00
/* Test 12 ... */
static BOOL deltest12 ( struct smbcli_state * cli1 , struct smbcli_state * cli2 )
{
int fnum1 = - 1 ;
NTSTATUS status ;
2006-02-01 07:41:54 +03:00
2006-02-03 05:07:22 +03:00
del_clean_area ( cli1 , cli2 ) ;
2004-10-24 13:08:52 +04:00
2005-12-09 22:36:40 +03:00
/* test 12 - does having read only attribute still allow delete on
* close at time of open . */
2004-10-24 13:08:52 +04:00
2004-11-30 07:33:27 +03:00
fnum1 = smbcli_nt_create_full ( cli1 - > tree , fname , 0 ,
2004-12-02 07:37:36 +03:00
SEC_RIGHTS_FILE_ALL ,
2004-11-30 07:33:27 +03:00
FILE_ATTRIBUTE_READONLY ,
2005-12-09 22:36:40 +03:00
NTCREATEX_SHARE_ACCESS_DELETE ,
NTCREATEX_DISP_OVERWRITE_IF ,
2004-11-30 07:33:27 +03:00
NTCREATEX_OPTIONS_DELETE_ON_CLOSE , 0 ) ;
2004-10-24 13:08:52 +04:00
if ( fnum1 ! = - 1 ) {
2005-12-09 22:36:40 +03:00
printf ( " (%s) open of %s succeeded. Should fail with "
" NT_STATUS_CANNOT_DELETE. \n " , __location__ , fname ) ;
2004-10-24 13:08:52 +04:00
smbcli_close ( cli1 - > tree , fnum1 ) ;
2006-02-03 05:07:22 +03:00
return False ;
2004-10-24 13:08:52 +04:00
} else {
status = smbcli_nt_error ( cli1 - > tree ) ;
2005-07-04 09:05:28 +04:00
if ( ! NT_STATUS_EQUAL ( status , NT_STATUS_CANNOT_DELETE ) ) {
2005-12-09 22:36:40 +03:00
printf ( " (%s) setting delete_on_close on open should "
" fail with NT_STATUS_CANNOT_DELETE. Got %s "
" instead) \n " ,
2004-10-24 14:27:38 +04:00
__location__ , smbcli_errstr ( cli1 - > tree ) ) ;
2006-02-03 05:07:22 +03:00
return False ;
2004-10-24 13:08:52 +04:00
}
}
printf ( " twelvth delete on close test succeeded. \n " ) ;
2006-02-03 05:07:22 +03:00
return True ;
}
/* Test 13 ... */
static BOOL deltest13 ( struct smbcli_state * cli1 , struct smbcli_state * cli2 )
{
int fnum1 = - 1 ;
int fnum2 = - 1 ;
BOOL correct = True ;
del_clean_area ( cli1 , cli2 ) ;
2004-10-24 13:08:52 +04:00
2005-07-06 13:50:31 +04: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 22:36:40 +03:00
NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE |
NTCREATEX_SHARE_ACCESS_DELETE ,
2005-07-06 13:50:31 +04:00
NTCREATEX_DISP_OVERWRITE_IF ,
0 , 0 ) ;
if ( fnum1 = = - 1 ) {
printf ( " (%s) open of %s failed (%s) \n " ,
__location__ , fname , smbcli_errstr ( cli1 - > tree ) ) ;
correct = False ;
goto fail ;
}
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 22:36:40 +03:00
NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE |
NTCREATEX_SHARE_ACCESS_DELETE ,
2005-07-06 13:50:31 +04:00
NTCREATEX_DISP_OPEN , 0 , 0 ) ;
if ( fnum2 = = - 1 ) {
printf ( " (%s) open of %s failed (%s) \n " ,
__location__ , fname , smbcli_errstr ( cli2 - > tree ) ) ;
correct = False ;
goto fail ;
}
if ( NT_STATUS_IS_ERR ( smbcli_nt_delete_on_close ( cli1 - > tree , fnum1 ,
True ) ) ) {
printf ( " (%s) setting delete_on_close on file failed ! \n " ,
__location__ ) ;
correct = False ;
goto fail ;
}
2006-02-27 06:23:28 +03:00
correct & = check_delete_on_close ( cli1 , fnum1 , fname , True , __location__ ) ;
correct & = check_delete_on_close ( cli2 , fnum2 , fname , True , __location__ ) ;
2005-07-06 13:50:31 +04:00
if ( NT_STATUS_IS_ERR ( smbcli_nt_delete_on_close ( cli2 - > tree , fnum2 ,
False ) ) ) {
printf ( " (%s) setting delete_on_close on file failed ! \n " ,
__location__ ) ;
correct = False ;
goto fail ;
}
2006-02-27 06:23:28 +03:00
correct & = check_delete_on_close ( cli1 , fnum1 , fname , False , __location__ ) ;
correct & = check_delete_on_close ( cli2 , fnum2 , fname , False , __location__ ) ;
2005-07-06 13:50:31 +04:00
if ( NT_STATUS_IS_ERR ( smbcli_close ( cli1 - > tree , fnum1 ) ) ) {
printf ( " (%s) close - 1 failed (%s) \n " ,
__location__ , smbcli_errstr ( cli1 - > tree ) ) ;
correct = False ;
goto fail ;
}
if ( NT_STATUS_IS_ERR ( smbcli_close ( cli2 - > tree , fnum2 ) ) ) {
printf ( " (%s) close - 2 failed (%s) \n " ,
__location__ , smbcli_errstr ( cli2 - > tree ) ) ;
correct = False ;
goto fail ;
}
fnum1 = smbcli_open ( cli1 - > tree , fname , O_RDONLY , DENY_NONE ) ;
if ( fnum1 = = - 1 ) {
printf ( " (%s) open of %s failed! \n " ,
__location__ , fname ) ;
correct = False ;
goto fail ;
}
2006-02-03 05:07:22 +03:00
printf ( " thirteenth delete on close test succeeded. \n " ) ;
2005-07-06 13:50:31 +04:00
2006-02-03 05:07:22 +03:00
fail :
2006-02-01 07:41:54 +03:00
2006-02-03 05:07:22 +03:00
return correct ;
}
/* Test 14 ... */
static BOOL deltest14 ( struct smbcli_state * cli1 , struct smbcli_state * cli2 )
{
int dnum1 = - 1 ;
BOOL correct = True ;
del_clean_area ( cli1 , cli2 ) ;
2005-07-06 13:50:31 +04:00
2005-07-06 18:56:45 +04:00
/* Test 14 -- directory */
dnum1 = smbcli_nt_create_full ( cli1 - > tree , dirname , 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_CREATE , 0 , 0 ) ;
if ( dnum1 = = - 1 ) {
printf ( " (%s) open of %s failed: %s! \n " ,
__location__ , dirname , smbcli_errstr ( cli1 - > tree ) ) ;
correct = False ;
goto fail ;
}
2006-02-27 06:23:28 +03:00
correct & = check_delete_on_close ( cli1 , dnum1 , dirname , False , __location__ ) ;
2005-07-06 18:56:45 +04:00
if ( NT_STATUS_IS_ERR ( smbcli_nt_delete_on_close ( cli1 - > tree , dnum1 , True ) ) ) {
printf ( " (%s) setting delete_on_close on file failed ! \n " ,
__location__ ) ;
correct = False ;
goto fail ;
}
2006-02-27 06:23:28 +03:00
correct & = check_delete_on_close ( cli1 , dnum1 , dirname , True , __location__ ) ;
2005-07-06 18:56:45 +04:00
smbcli_close ( cli1 - > tree , dnum1 ) ;
/* Now it should be gone... */
dnum1 = smbcli_nt_create_full ( cli1 - > tree , dirname , 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 , 0 , 0 ) ;
if ( dnum1 ! = - 1 ) {
printf ( " (%s) setting delete_on_close on file succeeded ! \n " ,
__location__ ) ;
correct = False ;
goto fail ;
}
printf ( " fourteenth delete on close test succeeded. \n " ) ;
2006-02-03 05:07:22 +03:00
fail :
return correct ;
}
/* Test 15 ... */
static BOOL deltest15 ( struct smbcli_state * cli1 , struct smbcli_state * cli2 )
{
int fnum1 = - 1 ;
int fnum2 = - 1 ;
BOOL correct = True ;
NTSTATUS status ;
del_clean_area ( cli1 , cli2 ) ;
2006-02-01 07:09:02 +03:00
/* Test 15: delete on close under rename */
2005-12-10 00:49:11 +03: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 ) ;
if ( fnum1 = = - 1 ) {
printf ( " (%s) open - 1 of %s failed (%s) \n " ,
__location__ , fname , smbcli_errstr ( cli1 - > tree ) ) ;
correct = False ;
goto fail ;
}
status = smbcli_rename ( cli2 - > tree , fname , fname_new ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " (%s) renaming failed: %s ! \n " ,
__location__ , nt_errstr ( status ) ) ;
correct = False ;
goto fail ;
}
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 ) ;
if ( fnum2 = = - 1 ) {
printf ( " (%s) open - 1 of %s failed (%s) \n " ,
__location__ , fname_new , smbcli_errstr ( cli1 - > tree ) ) ;
correct = False ;
goto fail ;
}
status = smbcli_nt_delete_on_close ( cli2 - > tree , fnum2 , True ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " (%s) setting delete_on_close on file failed ! \n " ,
__location__ ) ;
correct = False ;
goto fail ;
}
smbcli_close ( cli2 - > tree , fnum2 ) ;
/* The file should be around under the new name, there's a second
* handle open */
2006-02-27 06:23:28 +03:00
correct & = check_delete_on_close ( cli1 , fnum1 , fname_new , True , __location__ ) ;
2005-12-10 00:49:11 +03: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 ) ;
if ( fnum2 = = - 1 ) {
printf ( " (%s) open - 1 of %s failed (%s) \n " ,
__location__ , fname , smbcli_errstr ( cli1 - > tree ) ) ;
correct = False ;
goto fail ;
}
2006-02-27 06:23:28 +03:00
correct & = check_delete_on_close ( cli2 , fnum2 , fname , False , __location__ ) ;
2005-12-10 00:49:11 +03: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 ) ;
if ( fnum1 = = - 1 ) {
printf ( " (%s) open - 1 of %s failed (%s) \n " ,
__location__ , fname , smbcli_errstr ( cli1 - > tree ) ) ;
correct = False ;
goto fail ;
}
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 ) ;
if ( fnum1 ! = - 1 ) {
printf ( " (%s) smbcli_open succeeded, should have "
" failed \n " , __location__ ) ;
smbcli_close ( cli1 - > tree , fnum1 ) ;
correct = False ;
goto fail ;
}
2006-02-01 07:09:02 +03:00
printf ( " fifteenth delete on close test succeeded. \n " ) ;
2005-12-10 00:49:11 +03:00
2006-02-03 05:07:22 +03:00
fail :
return correct ;
}
/* Test 16 ... */
static BOOL deltest16 ( struct smbcli_state * cli1 , struct smbcli_state * cli2 )
{
int fnum1 = - 1 ;
int fnum2 = - 1 ;
BOOL correct = True ;
del_clean_area ( cli1 , cli2 ) ;
2006-02-01 07:09:02 +03:00
/* Test 16. */
2006-02-01 05:30:57 +03: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 ) ;
if ( fnum1 = = - 1 ) {
printf ( " (%s) open - 1 of %s failed (%s) \n " ,
__location__ , fname , smbcli_errstr ( cli1 - > tree ) ) ;
correct = False ;
goto fail ;
}
/* The delete on close bit is *not* reported as being set. */
2006-02-27 06:23:28 +03:00
correct & = check_delete_on_close ( cli1 , fnum1 , fname , False , __location__ ) ;
/* The delete on close bit is *not* reported as being set. */
correct & = check_delete_on_close ( cli1 , - 1 , fname , False , __location__ ) ;
correct & = check_delete_on_close ( cli2 , - 1 , fname , False , __location__ ) ;
2006-02-01 05:30:57 +03:00
/* Now try opening again for read-only. */
2006-02-27 06:23:28 +03:00
fnum2 = smbcli_nt_create_full ( cli2 - > tree , fname , 0 ,
2006-02-01 05:30:57 +03: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. */
if ( fnum2 = = - 1 ) {
printf ( " (%s) open - 1 of %s failed (%s) \n " ,
__location__ , fname , smbcli_errstr ( cli1 - > tree ) ) ;
correct = False ;
goto fail ;
}
2006-02-27 06:23:28 +03:00
correct & = check_delete_on_close ( cli1 , fnum1 , fname , False , __location__ ) ;
correct & = check_delete_on_close ( cli1 , - 1 , fname , False , __location__ ) ;
correct & = check_delete_on_close ( cli2 , fnum2 , fname , False , __location__ ) ;
correct & = check_delete_on_close ( cli2 , - 1 , fname , False , __location__ ) ;
2006-02-01 05:30:57 +03:00
smbcli_close ( cli1 - > tree , fnum1 ) ;
2006-02-27 06:23:28 +03:00
correct & = check_delete_on_close ( cli2 , fnum2 , fname , True , __location__ ) ;
correct & = check_delete_on_close ( cli2 , - 1 , fname , True , __location__ ) ;
smbcli_close ( cli2 - > tree , fnum2 ) ;
2006-02-01 05:30:57 +03:00
/* And the file should be deleted ! */
fnum1 = smbcli_open ( cli1 - > tree , fname , O_RDWR , DENY_NONE ) ;
if ( fnum1 ! = - 1 ) {
printf ( " (%s) open of %s succeeded (should fail) \n " ,
__location__ , fname ) ;
correct = False ;
goto fail ;
}
2006-02-01 07:09:02 +03:00
printf ( " sixteenth delete on close test succeeded. \n " ) ;
2006-02-01 05:30:57 +03:00
2006-02-03 05:07:22 +03:00
fail :
return correct ;
}
/* Test 17 ... */
static BOOL deltest17 ( struct smbcli_state * cli1 , struct smbcli_state * cli2 )
{
int fnum1 = - 1 ;
int fnum2 = - 1 ;
BOOL correct = True ;
del_clean_area ( cli1 , cli2 ) ;
2006-02-01 07:09:02 +03:00
/* Test 17. */
2006-02-01 05:30:57 +03: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 ) ;
if ( fnum1 = = - 1 ) {
printf ( " (%s) open - 1 of %s failed (%s) \n " ,
__location__ , fname , smbcli_errstr ( cli1 - > tree ) ) ;
correct = False ;
goto fail ;
}
/* 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 ) ;
if ( fnum1 = = - 1 ) {
printf ( " (%s) open - 1 of %s failed (%s) \n " ,
__location__ , fname , smbcli_errstr ( cli1 - > tree ) ) ;
correct = False ;
goto fail ;
}
/* The delete on close bit is *not* reported as being set. */
2006-02-27 06:23:28 +03:00
correct & = check_delete_on_close ( cli1 , fnum1 , fname , False , __location__ ) ;
2006-02-01 05:30:57 +03:00
/* Now try opening again for read-only. */
fnum2 = smbcli_nt_create_full ( cli1 - > tree , fname , 0 ,
2006-02-06 22:43:24 +03:00
SEC_RIGHTS_FILE_READ |
SEC_STD_DELETE ,
2006-02-01 05:30:57 +03:00
FILE_ATTRIBUTE_NORMAL ,
NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE |
NTCREATEX_SHARE_ACCESS_DELETE ,
NTCREATEX_DISP_OPEN ,
0 , 0 ) ;
/* Should work. */
if ( fnum2 = = - 1 ) {
printf ( " (%s) open - 1 of %s failed (%s) \n " ,
__location__ , fname , smbcli_errstr ( cli1 - > tree ) ) ;
correct = False ;
goto fail ;
}
2006-02-27 06:23:28 +03:00
/* still not reported as being set on either */
correct & = check_delete_on_close ( cli1 , fnum1 , fname , False , __location__ ) ;
correct & = check_delete_on_close ( cli1 , fnum2 , fname , False , __location__ ) ;
2006-02-01 05:30:57 +03:00
smbcli_close ( cli1 - > tree , fnum1 ) ;
2006-02-27 06:23:28 +03:00
correct & = check_delete_on_close ( cli1 , fnum2 , fname , False , __location__ ) ;
2006-02-01 05:30:57 +03: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 ) ;
if ( fnum1 = = - 1 ) {
2006-02-01 08:22:44 +03:00
printf ( " (%s) open of %s failed (should succeed) - %s \n " ,
__location__ , fname , smbcli_errstr ( cli1 - > tree ) ) ;
2006-02-01 05:30:57 +03:00
correct = False ;
goto fail ;
}
2006-02-01 07:09:02 +03:00
printf ( " seventeenth delete on close test succeeded. \n " ) ;
2006-02-01 05:30:57 +03:00
2006-02-03 05:07:22 +03:00
fail :
return correct ;
}
/* Test 18 ... */
static BOOL deltest18 ( struct smbcli_state * cli1 , struct smbcli_state * cli2 )
{
int fnum1 = - 1 ;
int fnum2 = - 1 ;
BOOL correct = True ;
del_clean_area ( cli1 , cli2 ) ;
2006-02-01 07:09:02 +03:00
/* Test 18. With directories. */
2006-02-01 06:36:04 +03:00
/* Ensure the file doesn't already exist. */
smbcli_close ( cli1 - > tree , fnum1 ) ;
smbcli_close ( cli1 - > tree , fnum2 ) ;
smbcli_deltree ( cli1 - > tree , dirname ) ;
/* Firstly create with all access, but delete on close. */
fnum1 = smbcli_nt_create_full ( cli1 - > tree , dirname , 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_CREATE ,
NTCREATEX_OPTIONS_DIRECTORY | NTCREATEX_OPTIONS_DELETE_ON_CLOSE , 0 ) ;
if ( fnum1 = = - 1 ) {
printf ( " (%s) open - 1 of %s failed (%s) \n " ,
__location__ , dirname , smbcli_errstr ( cli1 - > tree ) ) ;
correct = False ;
goto fail ;
}
/* The delete on close bit is *not* reported as being set. */
2006-02-27 06:23:28 +03:00
correct & = check_delete_on_close ( cli1 , fnum1 , dirname , False , __location__ ) ;
2006-02-01 06:36:04 +03:00
/* Now try opening again for read-only. */
fnum2 = smbcli_nt_create_full ( cli1 - > tree , dirname , 0 ,
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. */
if ( fnum2 = = - 1 ) {
printf ( " (%s) open - 1 of %s failed (%s) \n " ,
__location__ , dirname , smbcli_errstr ( cli1 - > tree ) ) ;
correct = False ;
goto fail ;
}
2006-02-27 06:23:28 +03:00
correct & = check_delete_on_close ( cli1 , fnum1 , dirname , False , __location__ ) ;
correct & = check_delete_on_close ( cli1 , fnum2 , dirname , False , __location__ ) ;
2006-02-01 06:36:04 +03:00
smbcli_close ( cli1 - > tree , fnum1 ) ;
2006-02-27 06:23:28 +03:00
correct & = check_delete_on_close ( cli1 , fnum2 , dirname , True , __location__ ) ;
2006-02-01 06:36:04 +03:00
smbcli_close ( cli1 - > tree , fnum2 ) ;
/* And the directory should be deleted ! */
fnum1 = smbcli_nt_create_full ( cli1 - > tree , dirname , 0 ,
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 ) ;
if ( fnum1 ! = - 1 ) {
printf ( " (%s) open of %s succeeded (should fail) \n " ,
__location__ , dirname ) ;
correct = False ;
goto fail ;
}
2006-02-01 07:09:02 +03:00
printf ( " eighteenth delete on close test succeeded. \n " ) ;
2006-02-01 06:36:04 +03:00
2006-02-03 05:07:22 +03:00
fail :
return correct ;
}
/* Test 19 ... */
static BOOL deltest19 ( struct smbcli_state * cli1 , struct smbcli_state * cli2 )
{
int fnum1 = - 1 ;
int fnum2 = - 1 ;
BOOL correct = True ;
del_clean_area ( cli1 , cli2 ) ;
2006-02-01 07:09:02 +03:00
/* Test 19. */
2006-02-01 06:36:04 +03:00
smbcli_deltree ( cli1 - > tree , dirname ) ;
/* Firstly open and create with all access */
fnum1 = smbcli_nt_create_full ( cli1 - > tree , dirname , 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_CREATE ,
NTCREATEX_OPTIONS_DIRECTORY , 0 ) ;
if ( fnum1 = = - 1 ) {
printf ( " (%s) open - 1 of %s failed (%s) \n " ,
__location__ , dirname , smbcli_errstr ( cli1 - > tree ) ) ;
correct = False ;
goto fail ;
}
/* And close - just to create the directory. */
smbcli_close ( cli1 - > tree , fnum1 ) ;
/* Next open with all access, but add delete on close. */
fnum1 = smbcli_nt_create_full ( cli1 - > tree , dirname , 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 | NTCREATEX_OPTIONS_DELETE_ON_CLOSE , 0 ) ;
if ( fnum1 = = - 1 ) {
printf ( " (%s) open - 1 of %s failed (%s) \n " ,
__location__ , fname , smbcli_errstr ( cli1 - > tree ) ) ;
correct = False ;
goto fail ;
}
/* The delete on close bit is *not* reported as being set. */
2006-02-27 06:23:28 +03:00
correct & = check_delete_on_close ( cli1 , fnum1 , dirname , False , __location__ ) ;
2006-02-01 06:36:04 +03:00
/* Now try opening again for read-only. */
2006-02-03 05:07:22 +03:00
fnum2 = smbcli_nt_create_full ( cli1 - > tree , dirname , 0 ,
2006-02-01 06:36:04 +03: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. */
if ( fnum2 = = - 1 ) {
printf ( " (%s) open - 1 of %s failed (%s) \n " ,
__location__ , dirname , smbcli_errstr ( cli1 - > tree ) ) ;
correct = False ;
goto fail ;
}
smbcli_close ( cli1 - > tree , fnum1 ) ;
2006-02-27 06:23:28 +03:00
correct & = check_delete_on_close ( cli1 , fnum2 , dirname , True , __location__ ) ;
2006-02-01 06:36:04 +03:00
smbcli_close ( cli1 - > tree , fnum2 ) ;
2006-02-03 05:07:22 +03:00
/* See if the file is deleted - for a directory this seems to be true ! */
2006-02-01 06:36:04 +03:00
fnum1 = smbcli_nt_create_full ( cli1 - > tree , dirname , 0 ,
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 05:07:22 +03:00
CHECK_STATUS ( cli1 , NT_STATUS_OBJECT_NAME_NOT_FOUND ) ;
if ( fnum1 ! = - 1 ) {
printf ( " (%s) open of %s succeeded (should fail) \n " ,
2006-02-01 06:36:04 +03:00
__location__ , dirname ) ;
correct = False ;
goto fail ;
}
2006-02-01 07:41:54 +03:00
2006-02-01 07:09:02 +03:00
printf ( " nineteenth delete on close test succeeded. \n " ) ;
2006-02-03 05:07:22 +03:00
fail :
return correct ;
}
/* Test 20 ... */
static BOOL deltest20 ( struct smbcli_state * cli1 , struct smbcli_state * cli2 )
{
int fnum1 = - 1 ;
int dnum1 = - 1 ;
BOOL correct = True ;
NTSTATUS status ;
del_clean_area ( cli1 , cli2 ) ;
2006-02-01 07:09:02 +03:00
/* Test 20 -- non-empty directory hardest to get right... */
smbcli_deltree ( cli1 - > tree , dirname ) ;
dnum1 = smbcli_nt_create_full ( cli1 - > tree , dirname , 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_CREATE ,
NTCREATEX_OPTIONS_DIRECTORY , 0 ) ;
if ( dnum1 = = - 1 ) {
printf ( " (%s) open of %s failed: %s! \n " ,
__location__ , dirname , smbcli_errstr ( cli1 - > tree ) ) ;
correct = False ;
goto fail ;
}
2006-02-27 06:23:28 +03:00
correct & = check_delete_on_close ( cli1 , dnum1 , dirname , False , __location__ ) ;
2006-02-01 07:09:02 +03:00
status = smbcli_nt_delete_on_close ( cli1 - > tree , dnum1 , True ) ;
{
char * fullname ;
asprintf ( & fullname , " \\ %s%s " , dirname , fname ) ;
fnum1 = smbcli_open ( cli1 - > tree , fullname , O_CREAT | O_RDWR ,
DENY_NONE ) ;
if ( fnum1 ! = - 1 ) {
printf ( " (%s) smbcli_open succeeded, should have "
2006-02-27 06:23:28 +03:00
" failed with NT_STATUS_DELETE_PENDING \n " ,
__location__ ) ;
2006-02-01 07:09:02 +03:00
correct = False ;
goto fail ;
}
if ( ! NT_STATUS_EQUAL ( smbcli_nt_error ( cli1 - > tree ) ,
NT_STATUS_DELETE_PENDING ) ) {
printf ( " (%s) smbcli_open returned %s, expected "
" NT_STATUS_DELETE_PENDING \n " ,
__location__ , smbcli_errstr ( cli1 - > tree ) ) ;
correct = False ;
goto fail ;
}
}
status = smbcli_nt_delete_on_close ( cli1 - > tree , dnum1 , False ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " (%s) setting delete_on_close on file failed ! \n " ,
__location__ ) ;
correct = False ;
goto fail ;
}
{
char * fullname ;
asprintf ( & fullname , " \\ %s%s " , dirname , fname ) ;
fnum1 = smbcli_open ( cli1 - > tree , fullname , O_CREAT | O_RDWR ,
DENY_NONE ) ;
if ( fnum1 = = - 1 ) {
printf ( " (%s) smbcli_open failed: %s \n " ,
__location__ , smbcli_errstr ( cli1 - > tree ) ) ;
correct = False ;
goto fail ;
}
smbcli_close ( cli1 - > tree , fnum1 ) ;
}
status = smbcli_nt_delete_on_close ( cli1 - > tree , dnum1 , True ) ;
if ( ! NT_STATUS_EQUAL ( status , NT_STATUS_DIRECTORY_NOT_EMPTY ) ) {
printf ( " (%s) setting delete_on_close returned %s, expected "
" NT_STATUS_DIRECTORY_NOT_EMPTY \n " , __location__ ,
smbcli_errstr ( cli1 - > tree ) ) ;
correct = False ;
goto fail ;
}
smbcli_close ( cli1 - > tree , dnum1 ) ;
2006-02-01 06:36:04 +03:00
printf ( " twentieth delete on close test succeeded. \n " ) ;
2006-02-03 05:07:22 +03:00
fail :
return correct ;
}
2006-02-06 22:43:24 +03:00
/* Test 21 ... */
static BOOL deltest21 ( struct smbcli_state * * ppcli1 , struct smbcli_state * * ppcli2 )
{
int fnum1 = - 1 ;
struct smbcli_state * cli1 = * ppcli1 ;
struct smbcli_state * cli2 = * ppcli2 ;
BOOL correct = True ;
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 ) ;
if ( fnum1 = = - 1 ) {
printf ( " (%s) open of %s failed (%s) \n " ,
__location__ , fname , smbcli_errstr ( cli1 - > tree ) ) ;
return False ;
}
if ( NT_STATUS_IS_ERR ( smbcli_nt_delete_on_close ( cli1 - > tree , fnum1 , True ) ) ) {
printf ( " (%s) setting delete_on_close failed (%s) \n " ,
__location__ , smbcli_errstr ( cli1 - > tree ) ) ;
return False ;
}
/* Ensure delete on close is set. */
2006-02-27 06:23:28 +03:00
correct & = check_delete_on_close ( cli1 , fnum1 , fname , True , __location__ ) ;
2006-02-06 22:43:24 +03:00
/* Now yank the rug from under cli1. */
smbcli_transport_dead ( cli1 - > transport ) ;
fnum1 = - 1 ;
if ( ! torture_open_connection ( ppcli1 ) ) {
return False ;
}
cli1 = * ppcli1 ;
/* 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 ) ;
printf ( " twenty-first delete on close test succeeded. \n " ) ;
fail :
return correct ;
}
2006-02-03 05:07:22 +03:00
/*
Test delete on close semantics .
*/
BOOL torture_test_delete ( void )
{
struct smbcli_state * cli1 = NULL ;
struct smbcli_state * cli2 = NULL ;
BOOL correct = True ;
printf ( " starting delete test \n " ) ;
if ( ! torture_open_connection ( & cli1 ) ) {
return False ;
}
if ( ! torture_open_connection ( & cli2 ) ) {
printf ( " (%s) failed to open second connection. \n " ,
__location__ ) ;
correct = False ;
goto fail ;
}
2006-02-06 22:43:24 +03:00
correct & = deltest1 ( cli1 , cli2 ) ;
correct & = deltest2 ( cli1 , cli2 ) ;
correct & = deltest3 ( cli1 , cli2 ) ;
correct & = deltest4 ( cli1 , cli2 ) ;
correct & = deltest5 ( cli1 , cli2 ) ;
correct & = deltest6 ( cli1 , cli2 ) ;
correct & = deltest7 ( cli1 , cli2 ) ;
correct & = deltest8 ( cli1 , cli2 ) ;
correct & = deltest9 ( cli1 , cli2 ) ;
correct & = deltest10 ( cli1 , cli2 ) ;
correct & = deltest11 ( cli1 , cli2 ) ;
correct & = deltest12 ( cli1 , cli2 ) ;
correct & = deltest13 ( cli1 , cli2 ) ;
correct & = deltest14 ( cli1 , cli2 ) ;
correct & = deltest15 ( cli1 , cli2 ) ;
correct & = deltest16 ( cli1 , cli2 ) ;
correct & = deltest17 ( cli1 , cli2 ) ;
correct & = deltest18 ( cli1 , cli2 ) ;
correct & = deltest19 ( cli1 , cli2 ) ;
correct & = deltest20 ( cli1 , cli2 ) ;
correct & = deltest21 ( & cli1 , & cli2 ) ;
if ( ! correct ) {
printf ( " Failed delete test \n " ) ;
} else {
printf ( " delete test ok ! \n " ) ;
2006-02-03 05:07:22 +03:00
}
2004-10-24 13:08:52 +04:00
fail :
2006-02-03 05:07:22 +03:00
del_clean_area ( cli1 , cli2 ) ;
2006-02-01 06:36:04 +03:00
2004-10-24 13:08:52 +04:00
if ( ! torture_close_connection ( cli1 ) ) {
correct = False ;
}
if ( ! torture_close_connection ( cli2 ) ) {
correct = False ;
}
return correct ;
}