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.
24 /* basic testing of all RAW_CLOSE_* calls
26 BOOL torture_raw_close(void)
28 struct smbcli_state *cli;
32 struct smb_flush io_flush;
34 const char *fname = "\\torture_close.txt";
35 time_t basetime = (time(NULL) + 3*86400) & ~1;
36 union smb_fileinfo finfo, finfo2;
39 if (!torture_open_connection(&cli)) {
43 mem_ctx = talloc_init("torture_raw_close");
46 fnum = create_complex_file(cli, mem_ctx, fname); \
48 printf("(%d) Failed to create %s\n", __LINE__, fname); \
53 #define CHECK_STATUS(status, correct) do { \
54 if (!NT_STATUS_EQUAL(status, correct)) { \
55 printf("(%d) Incorrect status %s - should be %s\n", \
56 __LINE__, nt_errstr(status), nt_errstr(correct)); \
63 io.close.level = RAW_CLOSE_CLOSE;
64 io.close.in.fnum = fnum;
65 io.close.in.write_time = basetime;
66 status = smb_raw_close(cli->tree, &io);
67 CHECK_STATUS(status, NT_STATUS_OK);
69 status = smb_raw_close(cli->tree, &io);
70 CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
72 printf("testing close.in.write_time\n");
74 /* the file should have the write time set */
75 finfo.generic.in.fname = fname;
76 finfo.generic.level = RAW_FILEINFO_ALL_INFO;
77 status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo);
78 CHECK_STATUS(status, NT_STATUS_OK);
80 if (basetime != nt_time_to_unix(finfo.all_info.out.write_time)) {
81 printf("Incorrect write time on file - %s - %s\n",
82 timestring(mem_ctx, basetime),
83 nt_time_string(mem_ctx, finfo.all_info.out.write_time));
84 dump_all_info(mem_ctx, &finfo);
88 printf("testing other times\n");
90 /* none of the other times should be set to that time */
91 if (nt_time_equal(&finfo.all_info.out.write_time,
92 &finfo.all_info.out.access_time) ||
93 nt_time_equal(&finfo.all_info.out.write_time,
94 &finfo.all_info.out.create_time) ||
95 nt_time_equal(&finfo.all_info.out.write_time,
96 &finfo.all_info.out.change_time)) {
97 printf("Incorrect times after close - only write time should be set\n");
98 dump_all_info(mem_ctx, &finfo);
103 smbcli_unlink(cli->tree, fname);
106 finfo2.generic.in.fname = fname;
107 finfo2.generic.level = RAW_FILEINFO_ALL_INFO;
108 status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo2);
109 CHECK_STATUS(status, NT_STATUS_OK);
111 io.close.level = RAW_CLOSE_CLOSE;
112 io.close.in.fnum = fnum;
113 io.close.in.write_time = 0;
114 status = smb_raw_close(cli->tree, &io);
115 CHECK_STATUS(status, NT_STATUS_OK);
117 /* the file should have the write time set equal to access time */
118 finfo.generic.in.fname = fname;
119 finfo.generic.level = RAW_FILEINFO_ALL_INFO;
120 status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo);
121 CHECK_STATUS(status, NT_STATUS_OK);
123 if (!nt_time_equal(&finfo.all_info.out.write_time,
124 &finfo2.all_info.out.write_time)) {
125 printf("Incorrect write time on file - 0 time should be ignored\n");
126 dump_all_info(mem_ctx, &finfo);
130 printf("testing splclose\n");
132 /* check splclose on a file */
134 io.splclose.level = RAW_CLOSE_SPLCLOSE;
135 io.splclose.in.fnum = fnum;
136 status = smb_raw_close(cli->tree, &io);
137 CHECK_STATUS(status, NT_STATUS_UNSUCCESSFUL);
139 printf("testing flush\n");
140 smbcli_close(cli->tree, fnum);
142 io_flush.in.fnum = fnum;
143 status = smb_raw_flush(cli->tree, &io_flush);
144 CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
146 io_flush.in.fnum = 0xffff;
147 status = smb_raw_flush(cli->tree, &io_flush);
148 CHECK_STATUS(status, NT_STATUS_OK);
152 io_flush.in.fnum = fnum;
153 status = smb_raw_flush(cli->tree, &io_flush);
154 CHECK_STATUS(status, NT_STATUS_OK);
156 printf("Testing SMBexit\n");
157 smb_raw_exit(cli->session);
159 io_flush.in.fnum = fnum;
160 status = smb_raw_flush(cli->tree, &io_flush);
161 CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
165 smbcli_close(cli->tree, fnum);
166 smbcli_unlink(cli->tree, fname);
167 torture_close_connection(cli);
168 talloc_destroy(mem_ctx);