2 Unix SMB/CIFS implementation.
3 RAW_CLOSE_* individual test suite
4 Copyright (C) Andrew Tridgell 2003
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "torture/torture.h"
23 #include "system/time.h"
24 #include "libcli/raw/libcliraw.h"
25 #include "libcli/libcli.h"
28 /* basic testing of all RAW_CLOSE_* calls
30 BOOL torture_raw_close(void)
32 struct smbcli_state *cli;
36 union smb_flush io_flush;
38 const char *fname = "\\torture_close.txt";
39 time_t basetime = (time(NULL) + 3*86400) & ~1;
40 union smb_fileinfo finfo, finfo2;
43 if (!torture_open_connection(&cli)) {
47 mem_ctx = talloc_init("torture_raw_close");
50 fnum = create_complex_file(cli, mem_ctx, fname); \
52 printf("(%d) Failed to create %s\n", __LINE__, fname); \
57 #define CHECK_STATUS(status, correct) do { \
58 if (!NT_STATUS_EQUAL(status, correct)) { \
59 printf("(%d) Incorrect status %s - should be %s\n", \
60 __LINE__, nt_errstr(status), nt_errstr(correct)); \
67 io.close.level = RAW_CLOSE_CLOSE;
68 io.close.in.file.fnum = fnum;
69 io.close.in.write_time = basetime;
70 status = smb_raw_close(cli->tree, &io);
71 CHECK_STATUS(status, NT_STATUS_OK);
73 status = smb_raw_close(cli->tree, &io);
74 CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
76 printf("testing close.in.write_time\n");
78 /* the file should have the write time set */
79 finfo.generic.level = RAW_FILEINFO_ALL_INFO;
80 finfo.generic.in.file.path = fname;
81 status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo);
82 CHECK_STATUS(status, NT_STATUS_OK);
84 if (basetime != nt_time_to_unix(finfo.all_info.out.write_time)) {
85 printf("Incorrect write time on file - %s - %s\n",
86 timestring(mem_ctx, basetime),
87 nt_time_string(mem_ctx, finfo.all_info.out.write_time));
88 dump_all_info(mem_ctx, &finfo);
92 printf("testing other times\n");
94 /* none of the other times should be set to that time */
95 if (nt_time_equal(&finfo.all_info.out.write_time,
96 &finfo.all_info.out.access_time) ||
97 nt_time_equal(&finfo.all_info.out.write_time,
98 &finfo.all_info.out.create_time) ||
99 nt_time_equal(&finfo.all_info.out.write_time,
100 &finfo.all_info.out.change_time)) {
101 printf("Incorrect times after close - only write time should be set\n");
102 dump_all_info(mem_ctx, &finfo);
107 smbcli_unlink(cli->tree, fname);
110 finfo2.generic.level = RAW_FILEINFO_ALL_INFO;
111 finfo2.generic.in.file.path = fname;
112 status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo2);
113 CHECK_STATUS(status, NT_STATUS_OK);
115 io.close.level = RAW_CLOSE_CLOSE;
116 io.close.in.file.fnum = fnum;
117 io.close.in.write_time = 0;
118 status = smb_raw_close(cli->tree, &io);
119 CHECK_STATUS(status, NT_STATUS_OK);
121 /* the file should have the write time set equal to access time */
122 finfo.generic.level = RAW_FILEINFO_ALL_INFO;
123 finfo.generic.in.file.path = fname;
124 status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo);
125 CHECK_STATUS(status, NT_STATUS_OK);
127 if (!nt_time_equal(&finfo.all_info.out.write_time,
128 &finfo2.all_info.out.write_time)) {
129 printf("Incorrect write time on file - 0 time should be ignored\n");
130 dump_all_info(mem_ctx, &finfo);
134 printf("testing splclose\n");
136 /* check splclose on a file */
138 io.splclose.level = RAW_CLOSE_SPLCLOSE;
139 io.splclose.in.file.fnum = fnum;
140 status = smb_raw_close(cli->tree, &io);
141 CHECK_STATUS(status, NT_STATUS_DOS(ERRSRV, ERRerror));
143 printf("testing flush\n");
144 smbcli_close(cli->tree, fnum);
146 io_flush.flush.in.file.fnum = fnum;
147 status = smb_raw_flush(cli->tree, &io_flush);
148 CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
150 io_flush.flush.in.file.fnum = 0xffff;
151 status = smb_raw_flush(cli->tree, &io_flush);
152 CHECK_STATUS(status, NT_STATUS_OK);
156 io_flush.flush.in.file.fnum = fnum;
157 status = smb_raw_flush(cli->tree, &io_flush);
158 CHECK_STATUS(status, NT_STATUS_OK);
160 printf("Testing SMBexit\n");
161 smb_raw_exit(cli->session);
163 io_flush.flush.in.file.fnum = fnum;
164 status = smb_raw_flush(cli->tree, &io_flush);
165 CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
169 smbcli_close(cli->tree, fnum);
170 smbcli_unlink(cli->tree, fname);
171 torture_close_connection(cli);
172 talloc_free(mem_ctx);