2004-10-25 06:59:48 +04:00
/*
Unix SMB / CIFS implementation .
rename 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
2007-07-10 06:07:03 +04:00
the Free Software Foundation ; either version 3 of the License , or
2004-10-25 06:59:48 +04:00
( 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
2007-07-10 06:07:03 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2004-10-25 06:59:48 +04:00
*/
# 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"
2006-03-17 20:59:58 +03:00
# include "torture/util.h"
2004-10-25 06:59:48 +04:00
/*
Test rename on files open with share delete and no share delete .
*/
2006-10-16 17:06:41 +04:00
BOOL torture_test_rename ( struct torture_context * tctx ,
struct smbcli_state * cli1 )
2004-10-25 06:59:48 +04:00
{
const char * fname = " \\ test.txt " ;
const char * fname1 = " \\ test1.txt " ;
int fnum1 ;
smbcli_unlink ( cli1 - > tree , fname ) ;
smbcli_unlink ( cli1 - > tree , fname1 ) ;
2004-10-25 08:24:06 +04:00
fnum1 = smbcli_nt_create_full ( cli1 - > tree , fname , 0 ,
2004-11-30 07:33:27 +03:00
SEC_RIGHTS_FILE_READ ,
2004-10-25 08:24:06 +04:00
FILE_ATTRIBUTE_NORMAL ,
NTCREATEX_SHARE_ACCESS_READ ,
NTCREATEX_DISP_OVERWRITE_IF , 0 , 0 ) ;
2004-10-25 06:59:48 +04:00
2006-10-16 17:06:41 +04:00
torture_assert ( tctx , fnum1 ! = - 1 , talloc_asprintf ( tctx , " First open failed - %s " ,
smbcli_errstr ( cli1 - > tree ) ) ) ;
torture_assert ( tctx , NT_STATUS_IS_ERR ( smbcli_rename ( cli1 - > tree , fname , fname1 ) ) ,
" First rename succeeded - this should have failed ! " ) ;
torture_assert_ntstatus_ok ( tctx , smbcli_close ( cli1 - > tree , fnum1 ) ,
talloc_asprintf ( tctx , " close - 1 failed (%s) " , smbcli_errstr ( cli1 - > tree ) ) ) ;
2004-10-25 06:59:48 +04:00
smbcli_unlink ( cli1 - > tree , fname ) ;
smbcli_unlink ( cli1 - > tree , fname1 ) ;
fnum1 = smbcli_nt_create_full ( cli1 - > tree , fname , 0 ,
2004-11-30 07:33:27 +03:00
SEC_RIGHTS_FILE_READ ,
2004-10-25 06:59:48 +04:00
FILE_ATTRIBUTE_NORMAL ,
NTCREATEX_SHARE_ACCESS_DELETE | NTCREATEX_SHARE_ACCESS_READ ,
NTCREATEX_DISP_OVERWRITE_IF , 0 , 0 ) ;
2006-10-16 17:06:41 +04:00
torture_assert ( tctx , fnum1 ! = - 1 , talloc_asprintf ( tctx ,
" Second open failed - %s " , smbcli_errstr ( cli1 - > tree ) ) ) ;
torture_assert_ntstatus_ok ( tctx , smbcli_rename ( cli1 - > tree , fname , fname1 ) ,
talloc_asprintf ( tctx ,
" Second rename failed - this should have succeeded - %s " ,
smbcli_errstr ( cli1 - > tree ) ) ) ;
torture_assert_ntstatus_ok ( tctx , smbcli_close ( cli1 - > tree , fnum1 ) ,
talloc_asprintf ( tctx ,
" close - 2 failed (%s) " , smbcli_errstr ( cli1 - > tree ) ) ) ;
2004-10-25 06:59:48 +04:00
smbcli_unlink ( cli1 - > tree , fname ) ;
smbcli_unlink ( cli1 - > tree , fname1 ) ;
2004-10-25 08:24:06 +04:00
fnum1 = smbcli_nt_create_full ( cli1 - > tree , fname , 0 ,
2004-11-30 07:33:27 +03:00
SEC_STD_READ_CONTROL ,
2004-10-25 08:24:06 +04:00
FILE_ATTRIBUTE_NORMAL ,
NTCREATEX_SHARE_ACCESS_NONE ,
NTCREATEX_DISP_OVERWRITE_IF , 0 , 0 ) ;
2004-10-25 06:59:48 +04:00
2006-10-16 17:06:41 +04:00
torture_assert ( tctx , fnum1 ! = - 1 , talloc_asprintf ( tctx , " Third open failed - %s " ,
smbcli_errstr ( cli1 - > tree ) ) ) ;
2004-10-25 06:59:48 +04:00
2006-10-16 17:06:41 +04:00
torture_assert_ntstatus_ok ( tctx , smbcli_rename ( cli1 - > tree , fname , fname1 ) ,
talloc_asprintf ( tctx , " Third rename failed - this should have succeeded - %s " ,
smbcli_errstr ( cli1 - > tree ) ) ) ;
2004-10-25 06:59:48 +04:00
2006-10-16 17:06:41 +04:00
torture_assert_ntstatus_ok ( tctx , smbcli_close ( cli1 - > tree , fnum1 ) ,
talloc_asprintf ( tctx , " close - 3 failed (%s) " , smbcli_errstr ( cli1 - > tree ) ) ) ;
2004-10-25 06:59:48 +04:00
smbcli_unlink ( cli1 - > tree , fname ) ;
smbcli_unlink ( cli1 - > tree , fname1 ) ;
2006-10-16 17:06:41 +04:00
return true ;
2004-10-25 06:59:48 +04:00
}