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 "system/time.h"
23 #include "libcli/raw/libcliraw.h"
26 /* basic testing of all RAW_CLOSE_* calls
28 BOOL torture_raw_close(void)
30 struct smbcli_state *cli;
34 struct smb_flush io_flush;
36 const char *fname = "\\torture_close.txt";
37 time_t basetime = (time(NULL) + 3*86400) & ~1;
38 union smb_fileinfo finfo, finfo2;
41 if (!torture_open_connection(&cli)) {
45 mem_ctx = talloc_init("torture_raw_close");
48 fnum = create_complex_file(cli, mem_ctx, fname); \
50 printf("(%d) Failed to create %s\n", __LINE__, fname); \
55 #define CHECK_STATUS(status, correct) do { \
56 if (!NT_STATUS_EQUAL(status, correct)) { \
57 printf("(%d) Incorrect status %s - should be %s\n", \
58 __LINE__, nt_errstr(status), nt_errstr(correct)); \
65 io.close.level = RAW_CLOSE_CLOSE;
66 io.close.in.fnum = fnum;
67 io.close.in.write_time = basetime;
68 status = smb_raw_close(cli->tree, &io);
69 CHECK_STATUS(status, NT_STATUS_OK);
71 status = smb_raw_close(cli->tree, &io);
72 CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
74 printf("testing close.in.write_time\n");
76 /* the file should have the write time set */
77 finfo.generic.in.fname = fname;
78 finfo.generic.level = RAW_FILEINFO_ALL_INFO;
79 status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo);
80 CHECK_STATUS(status, NT_STATUS_OK);
82 if (basetime != nt_time_to_unix(finfo.all_info.out.write_time)) {
83 printf("Incorrect write time on file - %s - %s\n",
84 timestring(mem_ctx, basetime),
85 nt_time_string(mem_ctx, finfo.all_info.out.write_time));
86 dump_all_info(mem_ctx, &finfo);
90 printf("testing other times\n");
92 /* none of the other times should be set to that time */
93 if (nt_time_equal(&finfo.all_info.out.write_time,
94 &finfo.all_info.out.access_time) ||
95 nt_time_equal(&finfo.all_info.out.write_time,
96 &finfo.all_info.out.create_time) ||
97 nt_time_equal(&finfo.all_info.out.write_time,
98 &finfo.all_info.out.change_time)) {
99 printf("Incorrect times after close - only write time should be set\n");
100 dump_all_info(mem_ctx, &finfo);
105 smbcli_unlink(cli->tree, fname);
108 finfo2.generic.in.fname = fname;
109 finfo2.generic.level = RAW_FILEINFO_ALL_INFO;
110 status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo2);
111 CHECK_STATUS(status, NT_STATUS_OK);
113 io.close.level = RAW_CLOSE_CLOSE;
114 io.close.in.fnum = fnum;
115 io.close.in.write_time = 0;
116 status = smb_raw_close(cli->tree, &io);
117 CHECK_STATUS(status, NT_STATUS_OK);
119 /* the file should have the write time set equal to access time */
120 finfo.generic.in.fname = fname;
121 finfo.generic.level = RAW_FILEINFO_ALL_INFO;
122 status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo);
123 CHECK_STATUS(status, NT_STATUS_OK);
125 if (!nt_time_equal(&finfo.all_info.out.write_time,
126 &finfo2.all_info.out.write_time)) {
127 printf("Incorrect write time on file - 0 time should be ignored\n");
128 dump_all_info(mem_ctx, &finfo);
132 printf("testing splclose\n");
134 /* check splclose on a file */
136 io.splclose.level = RAW_CLOSE_SPLCLOSE;
137 io.splclose.in.fnum = fnum;
138 status = smb_raw_close(cli->tree, &io);
139 CHECK_STATUS(status, NT_STATUS_DOS(ERRSRV, ERRerror));
141 printf("testing flush\n");
142 smbcli_close(cli->tree, fnum);
144 io_flush.in.fnum = fnum;
145 status = smb_raw_flush(cli->tree, &io_flush);
146 CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
148 io_flush.in.fnum = 0xffff;
149 status = smb_raw_flush(cli->tree, &io_flush);
150 CHECK_STATUS(status, NT_STATUS_OK);
154 io_flush.in.fnum = fnum;
155 status = smb_raw_flush(cli->tree, &io_flush);
156 CHECK_STATUS(status, NT_STATUS_OK);
158 printf("Testing SMBexit\n");
159 smb_raw_exit(cli->session);
161 io_flush.in.fnum = fnum;
162 status = smb_raw_flush(cli->tree, &io_flush);
163 CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
167 smbcli_close(cli->tree, fnum);
168 smbcli_unlink(cli->tree, fname);
169 torture_close_connection(cli);
170 talloc_free(mem_ctx);