2004-11-06 12:12:53 +03:00
/*
Unix SMB / CIFS implementation .
unlink tester
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-11-06 12:12:53 +03: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-11-06 12:12:53 +03:00
*/
# include "includes.h"
2005-02-10 08:09:35 +03:00
# include "system/filesys.h"
2006-01-03 18:40:05 +03:00
# include "libcli/libcli.h"
2006-03-17 20:59:58 +03:00
# include "torture/util.h"
2011-03-19 02:42:52 +03:00
# include "torture/basic/proto.h"
2004-11-06 12:12:53 +03:00
2004-12-31 11:44:08 +03:00
# define BASEDIR "\\unlinktest"
2004-11-06 12:12:53 +03:00
/*
This test checks that
1 ) the server does not allow an unlink on a file that is open
*/
2007-09-07 19:08:14 +04:00
bool torture_unlinktest ( struct torture_context * tctx , struct smbcli_state * cli )
2004-11-06 12:12:53 +03:00
{
2004-12-31 11:44:08 +03:00
const char * fname = BASEDIR " \\ unlink.tst " ;
2004-11-06 12:12:53 +03:00
int fnum ;
2007-10-07 02:28:14 +04:00
bool correct = true ;
2004-11-06 12:12:53 +03:00
union smb_open io ;
NTSTATUS status ;
2006-10-16 17:06:41 +04:00
torture_assert ( tctx , torture_setup_dir ( cli , BASEDIR ) ,
talloc_asprintf ( tctx , " Failed setting up %s " , BASEDIR ) ) ;
2004-11-06 12:12:53 +03:00
cli - > session - > pid = 1 ;
2006-10-16 17:06:41 +04:00
torture_comment ( tctx , " Opening a file \n " ) ;
2004-11-06 12:12:53 +03:00
fnum = smbcli_open ( cli - > tree , fname , O_RDWR | O_CREAT | O_EXCL , DENY_NONE ) ;
2006-10-16 17:06:41 +04:00
torture_assert ( tctx , fnum ! = - 1 , talloc_asprintf ( tctx , " open of %s failed (%s) " , fname , smbcli_errstr ( cli - > tree ) ) ) ;
torture_comment ( tctx , " Unlinking a open file \n " ) ;
torture_assert ( tctx , ! NT_STATUS_IS_OK ( smbcli_unlink ( cli - > tree , fname ) ) ,
" server allowed unlink on an open file " ) ;
correct = check_error ( __location__ , cli , ERRDOS , ERRbadshare ,
2004-11-06 12:12:53 +03:00
NT_STATUS_SHARING_VIOLATION ) ;
smbcli_close ( cli - > tree , fnum ) ;
smbcli_unlink ( cli - > tree , fname ) ;
2010-04-11 03:39:06 +04:00
torture_comment ( tctx , " Testing unlink after ntcreatex with DELETE access \n " ) ;
2004-11-06 12:12:53 +03:00
io . ntcreatex . level = RAW_OPEN_NTCREATEX ;
2009-10-15 11:26:19 +04:00
io . ntcreatex . in . root_fid . fnum = 0 ;
2004-11-06 12:12:53 +03:00
io . ntcreatex . in . flags = NTCREATEX_FLAGS_EXTENDED ;
io . ntcreatex . in . create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE ;
io . ntcreatex . in . file_attr = 0 ;
io . ntcreatex . in . alloc_size = 0 ;
io . ntcreatex . in . open_disposition = NTCREATEX_DISP_CREATE ;
io . ntcreatex . in . impersonation = NTCREATEX_IMPERSONATION_IMPERSONATION ;
io . ntcreatex . in . security_flags = 0 ;
io . ntcreatex . in . fname = fname ;
io . ntcreatex . in . share_access = NTCREATEX_SHARE_ACCESS_DELETE ;
2004-12-02 07:37:36 +03:00
io . ntcreatex . in . access_mask = SEC_RIGHTS_FILE_ALL ;
2004-11-06 12:12:53 +03:00
status = smb_raw_open ( cli - > tree , cli , & io ) ;
2006-10-16 17:06:41 +04:00
torture_assert_ntstatus_ok ( tctx , status , talloc_asprintf ( tctx , " failed to open %s " , fname ) ) ;
2004-11-06 12:12:53 +03:00
2006-10-16 17:06:41 +04:00
torture_assert ( tctx , ! NT_STATUS_IS_OK ( smbcli_unlink ( cli - > tree , fname ) ) ,
" server allowed unlink on an open file " ) ;
correct = check_error ( __location__ , cli , ERRDOS , ERRbadshare ,
NT_STATUS_SHARING_VIOLATION ) ;
2004-11-06 12:12:53 +03:00
return correct ;
}