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"
2004-11-30 04:33:27 +00:00
# include "librpc/gen_ndr/ndr_security.h"
2004-10-24 09:08:52 +00:00
/*
Test delete on close semantics .
*/
2004-10-28 13:40:50 +00:00
BOOL torture_test_delete ( void )
2004-10-24 09:08:52 +00:00
{
struct smbcli_state * cli1 ;
struct smbcli_state * cli2 = NULL ;
const char * fname = " \\ delete.file " ;
int fnum1 = - 1 ;
int fnum2 = - 1 ;
BOOL correct = True ;
NTSTATUS status ;
printf ( " starting delete test \n " ) ;
if ( ! torture_open_connection ( & cli1 ) ) {
return False ;
}
2004-10-24 10:27:38 +00:00
2004-10-24 09:08:52 +00:00
/* Test 1 - this should delete the file on close. */
smbcli_setatr ( cli1 - > tree , fname , 0 , 0 ) ;
smbcli_unlink ( cli1 - > tree , fname ) ;
2004-11-30 04:33:27 +00:00
fnum1 = smbcli_nt_create_full ( cli1 - > tree , fname , 0 ,
SEC_RIGHTS_FULL_CONTROL ,
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
if ( fnum1 = = - 1 ) {
2004-10-24 10:27:38 +00:00
printf ( " (%s) open of %s failed (%s) \n " ,
__location__ , fname , smbcli_errstr ( cli1 - > tree ) ) ;
2004-10-24 09:08:52 +00:00
correct = False ;
goto fail ;
}
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
correct = False ;
goto fail ;
}
fnum1 = smbcli_open ( cli1 - > tree , fname , O_RDWR , DENY_NONE ) ;
if ( fnum1 ! = - 1 ) {
2004-10-24 10:27:38 +00:00
printf ( " (%s) open of %s succeeded (should fail) \n " ,
__location__ , fname ) ;
2004-10-24 09:08:52 +00:00
correct = False ;
goto fail ;
}
printf ( " first delete on close test succeeded. \n " ) ;
/* Test 2 - this should delete the file on close. */
smbcli_setatr ( cli1 - > tree , fname , 0 , 0 ) ;
smbcli_unlink ( cli1 - > tree , fname ) ;
2004-11-30 04:33:27 +00:00
fnum1 = smbcli_nt_create_full ( cli1 - > tree , fname , 0 ,
SEC_RIGHTS_FULL_CONTROL ,
FILE_ATTRIBUTE_NORMAL , NTCREATEX_SHARE_ACCESS_NONE ,
NTCREATEX_DISP_OVERWRITE_IF , 0 , 0 ) ;
2004-10-24 09:08:52 +00:00
if ( fnum1 = = - 1 ) {
2004-10-24 10:27:38 +00:00
printf ( " (%s) open of %s failed (%s) \n " ,
__location__ , fname , smbcli_errstr ( cli1 - > tree ) ) ;
2004-10-24 09:08:52 +00:00
correct = False ;
goto fail ;
}
if ( NT_STATUS_IS_ERR ( smbcli_nt_delete_on_close ( cli1 - > tree , fnum1 , True ) ) ) {
2004-10-24 10:27:38 +00:00
printf ( " (%s) setting delete_on_close failed (%s) \n " ,
__location__ , smbcli_errstr ( cli1 - > tree ) ) ;
2004-10-24 09:08:52 +00:00
correct = False ;
goto fail ;
}
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
correct = False ;
goto fail ;
}
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
correct = False ;
goto fail ;
}
smbcli_unlink ( cli1 - > tree , fname ) ;
} else
printf ( " second delete on close test succeeded. \n " ) ;
/* Test 3 - ... */
smbcli_setatr ( cli1 - > tree , fname , 0 , 0 ) ;
smbcli_unlink ( cli1 - > tree , fname ) ;
2004-10-24 10:27:38 +00:00
fnum1 = smbcli_nt_create_full ( cli1 - > tree , fname , 0 ,
2004-11-30 04:33:27 +00:00
SEC_RIGHTS_FULL_CONTROL ,
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
if ( fnum1 = = - 1 ) {
2004-10-24 10:27:38 +00:00
printf ( " (%s) open - 1 of %s failed (%s) \n " ,
__location__ , fname , smbcli_errstr ( cli1 - > tree ) ) ;
2004-10-24 09:08:52 +00:00
correct = False ;
goto fail ;
}
/* 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
if ( fnum2 ! = - 1 ) {
2004-10-24 10:27:38 +00:00
printf ( " (%s) open - 2 of %s succeeded - should have failed. \n " ,
__location__ , fname ) ;
2004-10-24 09:08:52 +00:00
correct = False ;
goto fail ;
}
/* 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
if ( fnum2 = = - 1 ) {
2004-10-24 10:27:38 +00:00
printf ( " (%s) open - 2 of %s failed (%s) \n " ,
__location__ , fname , smbcli_errstr ( cli1 - > tree ) ) ;
2004-10-24 09:08:52 +00:00
correct = False ;
goto fail ;
}
if ( NT_STATUS_IS_ERR ( smbcli_nt_delete_on_close ( cli1 - > tree , fnum1 , True ) ) ) {
2004-10-24 10:27:38 +00:00
printf ( " (%s) setting delete_on_close failed (%s) \n " ,
__location__ , smbcli_errstr ( cli1 - > tree ) ) ;
2004-10-24 09:08:52 +00:00
correct = False ;
goto fail ;
}
if ( NT_STATUS_IS_ERR ( smbcli_close ( cli1 - > tree , fnum1 ) ) ) {
2004-10-24 10:27:38 +00:00
printf ( " (%s) close 1 failed (%s) \n " ,
__location__ , smbcli_errstr ( cli1 - > tree ) ) ;
2004-10-24 09:08:52 +00:00
correct = False ;
goto fail ;
}
if ( NT_STATUS_IS_ERR ( smbcli_close ( cli1 - > tree , fnum2 ) ) ) {
2004-10-24 10:27:38 +00:00
printf ( " (%s) close 2 failed (%s) \n " ,
__location__ , smbcli_errstr ( cli1 - > tree ) ) ;
2004-10-24 09:08:52 +00:00
correct = False ;
goto fail ;
}
/* 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 ) ;
correct = False ;
goto fail ;
} else
printf ( " third delete on close test succeeded. \n " ) ;
/* Test 4 ... */
smbcli_setatr ( cli1 - > tree , fname , 0 , 0 ) ;
2004-10-24 10:27:38 +00:00
status = smbcli_unlink ( cli1 - > tree , fname ) ;
if ( NT_STATUS_IS_OK ( status ) ) {
printf ( " (%s) succeeded unlink of %s \n " , __location__ , fname ) ;
correct = False ;
goto fail ;
}
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
if ( fnum1 = = - 1 ) {
2004-10-24 10:27:38 +00:00
printf ( " (%s) open of %s failed (%s) \n " ,
__location__ , fname , smbcli_errstr ( cli1 - > tree ) ) ;
2004-10-24 09:08:52 +00:00
correct = False ;
goto fail ;
}
/* 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 ) ;
2004-10-24 09:08:52 +00:00
if ( fnum2 = = - 1 ) {
2004-10-24 10:27:38 +00:00
printf ( " (%s) open - 2 of %s failed (%s) \n " ,
__location__ , fname , smbcli_errstr ( cli1 - > tree ) ) ;
2004-10-24 09:08:52 +00:00
correct = False ;
goto fail ;
}
if ( NT_STATUS_IS_ERR ( smbcli_close ( cli1 - > tree , fnum2 ) ) ) {
2004-10-24 10:27:38 +00:00
printf ( " (%s) close - 1 failed (%s) \n " ,
__location__ , smbcli_errstr ( cli1 - > tree ) ) ;
2004-10-24 09:08:52 +00:00
correct = False ;
goto fail ;
}
if ( NT_STATUS_IS_ERR ( smbcli_nt_delete_on_close ( cli1 - > tree , fnum1 , True ) ) ) {
2004-10-24 10:27:38 +00:00
printf ( " (%s) setting delete_on_close failed (%s) \n " ,
__location__ , smbcli_errstr ( cli1 - > tree ) ) ;
2004-10-24 09:08:52 +00:00
correct = False ;
goto fail ;
}
/* 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 ) ;
2004-10-24 09:08:52 +00:00
if ( fnum2 ! = - 1 ) {
2004-10-24 10:27:38 +00:00
printf ( " (%s) open - 3 of %s succeeded ! Should have failed. \n " ,
__location__ , fname ) ;
2004-10-24 09:08:52 +00:00
correct = False ;
goto fail ;
} else
printf ( " fourth delete on close test succeeded. \n " ) ;
if ( NT_STATUS_IS_ERR ( smbcli_close ( cli1 - > tree , fnum1 ) ) ) {
2004-10-24 10:27:38 +00:00
printf ( " (%s) close - 2 failed (%s) \n " ,
__location__ , smbcli_errstr ( cli1 - > tree ) ) ;
2004-10-24 09:08:52 +00:00
correct = False ;
goto fail ;
}
/* Test 5 ... */
smbcli_setatr ( cli1 - > tree , fname , 0 , 0 ) ;
smbcli_unlink ( cli1 - > tree , fname ) ;
fnum1 = smbcli_open ( cli1 - > tree , fname , O_RDWR | O_CREAT , DENY_NONE ) ;
if ( fnum1 = = - 1 ) {
2004-10-24 10:27:38 +00:00
printf ( " (%s) open of %s failed (%s) \n " ,
__location__ , fname , smbcli_errstr ( cli1 - > tree ) ) ;
2004-10-24 09:08:52 +00:00
correct = False ;
goto fail ;
}
/* 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 10:27:38 +00:00
printf ( " (%s) setting delete_on_close on OpenX file succeeded - should fail ! \n " ,
__location__ ) ;
2004-10-24 09:08:52 +00:00
correct = False ;
goto fail ;
}
if ( NT_STATUS_IS_ERR ( smbcli_close ( cli1 - > tree , fnum1 ) ) ) {
2004-10-24 10:27:38 +00:00
printf ( " (%s) close - 2 failed (%s) \n " ,
__location__ , smbcli_errstr ( cli1 - > tree ) ) ;
2004-10-24 09:08:52 +00:00
correct = False ;
goto fail ;
}
printf ( " fifth delete on close test succeeded. \n " ) ;
/* Test 6 ... */
smbcli_setatr ( cli1 - > tree , fname , 0 , 0 ) ;
smbcli_unlink ( cli1 - > tree , fname ) ;
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 ) ;
if ( fnum1 = = - 1 ) {
2004-10-24 10:27:38 +00:00
printf ( " (%s) open of %s failed (%s) \n " ,
__location__ , fname , smbcli_errstr ( cli1 - > tree ) ) ;
2004-10-24 09:08:52 +00:00
correct = False ;
goto fail ;
}
/* 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 10:27:38 +00:00
printf ( " (%s) setting delete_on_close on file with no delete access succeeded - should fail ! \n " ,
__location__ ) ;
2004-10-24 09:08:52 +00:00
correct = False ;
goto fail ;
}
if ( NT_STATUS_IS_ERR ( smbcli_close ( cli1 - > tree , fnum1 ) ) ) {
2004-10-24 10:27:38 +00:00
printf ( " (%s) close - 2 failed (%s) \n " ,
__location__ , smbcli_errstr ( cli1 - > tree ) ) ;
2004-10-24 09:08:52 +00:00
correct = False ;
goto fail ;
}
printf ( " sixth delete on close test succeeded. \n " ) ;
/* Test 7 ... */
smbcli_setatr ( cli1 - > tree , fname , 0 , 0 ) ;
smbcli_unlink ( cli1 - > tree , fname ) ;
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
if ( fnum1 = = - 1 ) {
2004-10-24 10:27:38 +00:00
printf ( " (%s) open of %s failed (%s) \n " ,
__location__ , fname , smbcli_errstr ( cli1 - > tree ) ) ;
2004-10-24 09:08:52 +00:00
correct = False ;
goto fail ;
}
if ( NT_STATUS_IS_ERR ( smbcli_nt_delete_on_close ( cli1 - > tree , fnum1 , True ) ) ) {
2004-10-24 10:27:38 +00:00
printf ( " (%s) setting delete_on_close on file failed ! \n " ,
__location__ ) ;
2004-10-24 09:08:52 +00:00
correct = False ;
goto fail ;
}
if ( NT_STATUS_IS_ERR ( smbcli_nt_delete_on_close ( cli1 - > tree , fnum1 , False ) ) ) {
2004-10-24 10:27:38 +00:00
printf ( " (%s) unsetting delete_on_close on file failed ! \n " ,
__location__ ) ;
2004-10-24 09:08:52 +00:00
correct = False ;
goto fail ;
}
if ( NT_STATUS_IS_ERR ( smbcli_close ( cli1 - > tree , fnum1 ) ) ) {
2004-10-24 10:27:38 +00:00
printf ( " (%s) close - 2 failed (%s) \n " ,
__location__ , smbcli_errstr ( cli1 - > tree ) ) ;
2004-10-24 09:08:52 +00: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 10:27:38 +00:00
printf ( " (%s) open of %s failed (%s) \n " ,
__location__ , fname , smbcli_errstr ( cli1 - > tree ) ) ;
2004-10-24 09:08:52 +00:00
correct = False ;
goto fail ;
}
if ( NT_STATUS_IS_ERR ( smbcli_close ( cli1 - > tree , fnum1 ) ) ) {
2004-10-24 10:27:38 +00:00
printf ( " (%s) close - 2 failed (%s) \n " ,
__location__ , smbcli_errstr ( cli1 - > tree ) ) ;
2004-10-24 09:08:52 +00:00
correct = False ;
goto fail ;
}
printf ( " seventh delete on close test succeeded. \n " ) ;
/* Test 7 ... */
smbcli_setatr ( cli1 - > tree , fname , 0 , 0 ) ;
smbcli_unlink ( cli1 - > tree , fname ) ;
if ( ! torture_open_connection ( & cli2 ) ) {
2004-10-24 10:27:38 +00:00
printf ( " (%s) failed to open second connection. \n " ,
__location__ ) ;
2004-10-24 09:08:52 +00:00
correct = False ;
goto fail ;
}
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
if ( fnum1 = = - 1 ) {
2004-10-24 10:27:38 +00:00
printf ( " (%s) open of %s failed (%s) \n " ,
__location__ , fname , smbcli_errstr ( cli1 - > tree ) ) ;
2004-10-24 09:08:52 +00:00
correct = False ;
goto fail ;
}
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
if ( fnum2 = = - 1 ) {
2004-10-24 10:27:38 +00:00
printf ( " (%s) open of %s failed (%s) \n " ,
__location__ , fname , smbcli_errstr ( cli1 - > tree ) ) ;
2004-10-24 09:08:52 +00:00
correct = False ;
goto fail ;
}
if ( NT_STATUS_IS_ERR ( smbcli_nt_delete_on_close ( cli1 - > tree , fnum1 , True ) ) ) {
2004-10-24 10:27:38 +00:00
printf ( " (%s) setting delete_on_close on file failed ! \n " ,
__location__ ) ;
2004-10-24 09:08:52 +00:00
correct = False ;
goto fail ;
}
if ( NT_STATUS_IS_ERR ( smbcli_close ( cli1 - > tree , fnum1 ) ) ) {
2004-10-24 10:27:38 +00:00
printf ( " (%s) close - 1 failed (%s) \n " ,
__location__ , smbcli_errstr ( cli1 - > tree ) ) ;
2004-10-24 09:08:52 +00:00
correct = False ;
goto fail ;
}
if ( NT_STATUS_IS_ERR ( smbcli_close ( cli2 - > tree , fnum2 ) ) ) {
2004-10-24 10:27:38 +00:00
printf ( " (%s) close - 2 failed (%s) \n " ,
__location__ , smbcli_errstr ( cli2 - > tree ) ) ;
2004-10-24 09:08:52 +00:00
correct = False ;
goto fail ;
}
/* This should fail.. */
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
goto fail ;
correct = False ;
} else
printf ( " eighth delete on close test succeeded. \n " ) ;
/* 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
if ( fnum1 ! = - 1 ) {
2004-10-24 10:27:38 +00:00
printf ( " (%s) open of %s succeeded should have failed! \n " ,
__location__ , fname ) ;
2004-10-24 09:08:52 +00:00
correct = False ;
goto fail ;
}
printf ( " ninth delete on close test succeeded. \n " ) ;
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 ) ;
2004-10-24 09:08:52 +00:00
if ( fnum1 = = - 1 ) {
2004-10-24 10:27:38 +00:00
printf ( " (%s) open of %s failed (%s) \n " ,
__location__ , fname , smbcli_errstr ( cli1 - > tree ) ) ;
2004-10-24 09:08:52 +00:00
correct = False ;
goto fail ;
}
/* This should delete the file. */
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
correct = False ;
goto fail ;
}
/* This should fail.. */
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
goto fail ;
correct = False ;
} else
printf ( " tenth delete on close test succeeded. \n " ) ;
/* test 11 - does having read only attribute still allow delete on close. */
smbcli_setatr ( cli1 - > tree , fname , 0 , 0 ) ;
smbcli_unlink ( cli1 - > tree , fname ) ;
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-11-30 04:33:27 +00:00
SEC_RIGHTS_FULL_CONTROL ,
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
if ( fnum1 = = - 1 ) {
2004-10-24 10:27:38 +00:00
printf ( " (%s) open of %s failed (%s) \n " ,
__location__ , fname , smbcli_errstr ( cli1 - > tree ) ) ;
2004-10-24 09:08:52 +00:00
correct = False ;
goto fail ;
}
status = smbcli_nt_delete_on_close ( cli1 - > tree , fnum1 , True ) ;
if ( NT_STATUS_V ( status ) ! = NT_STATUS_V ( NT_STATUS_CANNOT_DELETE ) ) {
2004-10-24 10:27:38 +00:00
printf ( " (%s) setting delete_on_close should fail with NT_STATUS_CANNOT_DELETE. Got %s instead) \n " ,
__location__ , smbcli_errstr ( cli1 - > tree ) ) ;
2004-10-24 09:08:52 +00:00
correct = False ;
goto fail ;
}
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
correct = False ;
goto fail ;
}
smbcli_setatr ( cli1 - > tree , fname , 0 , 0 ) ;
smbcli_unlink ( cli1 - > tree , fname ) ;
printf ( " eleventh delete on close test succeeded. \n " ) ;
/* test 12 - does having read only attribute still allow delete on close at time of open. */
2004-11-30 04:33:27 +00:00
fnum1 = smbcli_nt_create_full ( cli1 - > tree , fname , 0 ,
SEC_RIGHTS_FULL_CONTROL ,
FILE_ATTRIBUTE_READONLY ,
NTCREATEX_SHARE_ACCESS_DELETE , NTCREATEX_DISP_OVERWRITE_IF ,
NTCREATEX_OPTIONS_DELETE_ON_CLOSE , 0 ) ;
2004-10-24 09:08:52 +00:00
if ( fnum1 ! = - 1 ) {
2004-10-24 10:27:38 +00:00
printf ( " (%s) open of %s succeeded. Should fail with NT_STATUS_CANNOT_DELETE. \n " ,
__location__ , fname ) ;
2004-10-24 09:08:52 +00:00
smbcli_close ( cli1 - > tree , fnum1 ) ;
correct = False ;
goto fail ;
} else {
status = smbcli_nt_error ( cli1 - > tree ) ;
if ( NT_STATUS_V ( status ) ! = NT_STATUS_V ( NT_STATUS_CANNOT_DELETE ) ) {
2004-10-24 10:27:38 +00:00
printf ( " (%s) setting delete_on_close on open should fail with NT_STATUS_CANNOT_DELETE. Got %s instead) \n " ,
__location__ , smbcli_errstr ( cli1 - > tree ) ) ;
2004-10-24 09:08:52 +00:00
correct = False ;
goto fail ;
}
}
printf ( " twelvth delete on close test succeeded. \n " ) ;
printf ( " finished delete test \n " ) ;
fail :
/* FIXME: This will crash if we aborted before cli2 got
* intialized , because these functions don ' t handle
* uninitialized connections . */
smbcli_close ( cli1 - > tree , fnum1 ) ;
smbcli_close ( cli1 - > tree , fnum2 ) ;
smbcli_setatr ( cli1 - > tree , fname , 0 , 0 ) ;
smbcli_unlink ( cli1 - > tree , fname ) ;
if ( ! torture_close_connection ( cli1 ) ) {
correct = False ;
}
if ( ! torture_close_connection ( cli2 ) ) {
correct = False ;
}
return correct ;
}