2 Unix SMB/CIFS implementation.
6 Copyright (C) Andrew Tridgell 2003
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "torture/torture.h"
25 #include "system/filesys.h"
26 #include "libcli/raw/libcliraw.h"
27 #include "libcli/libcli.h"
28 #include "torture/util.h"
30 #define BASEDIR "\\unlinktest"
35 1) the server does not allow an unlink on a file that is open
37 BOOL
torture_unlinktest(struct torture_context
*tctx
, struct smbcli_state
*cli
)
39 const char *fname
= BASEDIR
"\\unlink.tst";
45 torture_assert(tctx
, torture_setup_dir(cli
, BASEDIR
),
46 talloc_asprintf(tctx
, "Failed setting up %s", BASEDIR
));
48 cli
->session
->pid
= 1;
50 torture_comment(tctx
, "Opening a file\n");
52 fnum
= smbcli_open(cli
->tree
, fname
, O_RDWR
|O_CREAT
|O_EXCL
, DENY_NONE
);
53 torture_assert(tctx
, fnum
!= -1, talloc_asprintf(tctx
, "open of %s failed (%s)", fname
, smbcli_errstr(cli
->tree
)));
55 torture_comment(tctx
, "Unlinking a open file\n");
57 torture_assert(tctx
, !NT_STATUS_IS_OK(smbcli_unlink(cli
->tree
, fname
)),
58 "server allowed unlink on an open file");
60 correct
= check_error(__location__
, cli
, ERRDOS
, ERRbadshare
,
61 NT_STATUS_SHARING_VIOLATION
);
63 smbcli_close(cli
->tree
, fnum
);
64 smbcli_unlink(cli
->tree
, fname
);
66 torture_comment(tctx
, "testing unlink after ntcreatex with DELETE access\n");
68 io
.ntcreatex
.level
= RAW_OPEN_NTCREATEX
;
69 io
.ntcreatex
.in
.root_fid
= 0;
70 io
.ntcreatex
.in
.flags
= NTCREATEX_FLAGS_EXTENDED
;
71 io
.ntcreatex
.in
.create_options
= NTCREATEX_OPTIONS_NON_DIRECTORY_FILE
;
72 io
.ntcreatex
.in
.file_attr
= 0;
73 io
.ntcreatex
.in
.alloc_size
= 0;
74 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_CREATE
;
75 io
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_IMPERSONATION
;
76 io
.ntcreatex
.in
.security_flags
= 0;
77 io
.ntcreatex
.in
.fname
= fname
;
78 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_DELETE
;
79 io
.ntcreatex
.in
.access_mask
= SEC_RIGHTS_FILE_ALL
;
81 status
= smb_raw_open(cli
->tree
, cli
, &io
);
82 torture_assert_ntstatus_ok(tctx
, status
, talloc_asprintf(tctx
, "failed to open %s", fname
));
84 torture_assert(tctx
, !NT_STATUS_IS_OK(smbcli_unlink(cli
->tree
, fname
)),
85 "server allowed unlink on an open file");
87 correct
= check_error(__location__
, cli
, ERRDOS
, ERRbadshare
,
88 NT_STATUS_SHARING_VIOLATION
);