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"
29 #define BASEDIR "\\unlinktest"
34 1) the server does not allow an unlink on a file that is open
36 BOOL torture_unlinktest(void)
38 struct smbcli_state *cli;
39 const char *fname = BASEDIR "\\unlink.tst";
45 if (!torture_open_connection(&cli)) {
49 printf("starting unlink test\n");
51 if (!torture_setup_dir(cli, BASEDIR)) {
55 cli->session->pid = 1;
57 printf("Opening a file\n");
59 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
61 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
65 printf("Unlinking a open file\n");
67 if (NT_STATUS_IS_OK(smbcli_unlink(cli->tree, fname))) {
68 printf("(%s) error: server allowed unlink on an open file\n", __location__);
71 correct = check_error(__location__, cli, ERRDOS, ERRbadshare,
72 NT_STATUS_SHARING_VIOLATION);
75 smbcli_close(cli->tree, fnum);
76 smbcli_unlink(cli->tree, fname);
78 printf("testing unlink after ntcreatex with DELETE access\n");
80 io.ntcreatex.level = RAW_OPEN_NTCREATEX;
81 io.ntcreatex.in.root_fid = 0;
82 io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
83 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE;
84 io.ntcreatex.in.file_attr = 0;
85 io.ntcreatex.in.alloc_size = 0;
86 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
87 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_IMPERSONATION;
88 io.ntcreatex.in.security_flags = 0;
89 io.ntcreatex.in.fname = fname;
90 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_DELETE;
91 io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
93 status = smb_raw_open(cli->tree, cli, &io);
94 if (!NT_STATUS_IS_OK(status)) {
95 printf("(%s) failed to open %s\n", __location__, fname);
97 if (NT_STATUS_IS_OK(smbcli_unlink(cli->tree, fname))) {
98 printf("(%s) error: server allowed unlink on an open file\n", __location__);
101 correct = check_error(__location__, cli, ERRDOS, ERRbadshare,
102 NT_STATUS_SHARING_VIOLATION);
105 if (!torture_close_connection(cli)) {
109 printf("unlink test finished\n");