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"
27 /* basic testing of all RAW_CLOSE_* calls
29 BOOL torture_raw_close(void)
31 struct smbcli_state *cli;
35 struct smb_flush io_flush;
37 const char *fname = "\\torture_close.txt";
38 time_t basetime = (time(NULL) + 3*86400) & ~1;
39 union smb_fileinfo finfo, finfo2;
42 if (!torture_open_connection(&cli)) {
46 mem_ctx = talloc_init("torture_raw_close");
49 fnum = create_complex_file(cli, mem_ctx, fname); \
51 printf("(%d) Failed to create %s\n", __LINE__, fname); \
56 #define CHECK_STATUS(status, correct) do { \
57 if (!NT_STATUS_EQUAL(status, correct)) { \
58 printf("(%d) Incorrect status %s - should be %s\n", \
59 __LINE__, nt_errstr(status), nt_errstr(correct)); \
66 io.close.level = RAW_CLOSE_CLOSE;
67 io.close.in.fnum = fnum;
68 io.close.in.write_time = basetime;
69 status = smb_raw_close(cli->tree, &io);
70 CHECK_STATUS(status, NT_STATUS_OK);
72 status = smb_raw_close(cli->tree, &io);
73 CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
75 printf("testing close.in.write_time\n");
77 /* the file should have the write time set */
78 finfo.generic.in.fname = fname;
79 finfo.generic.level = RAW_FILEINFO_ALL_INFO;
80 status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo);
81 CHECK_STATUS(status, NT_STATUS_OK);
83 if (basetime != nt_time_to_unix(finfo.all_info.out.write_time)) {
84 printf("Incorrect write time on file - %s - %s\n",
85 timestring(mem_ctx, basetime),
86 nt_time_string(mem_ctx, finfo.all_info.out.write_time));
87 dump_all_info(mem_ctx, &finfo);
91 printf("testing other times\n");
93 /* none of the other times should be set to that time */
94 if (nt_time_equal(&finfo.all_info.out.write_time,
95 &finfo.all_info.out.access_time) ||
96 nt_time_equal(&finfo.all_info.out.write_time,
97 &finfo.all_info.out.create_time) ||
98 nt_time_equal(&finfo.all_info.out.write_time,
99 &finfo.all_info.out.change_time)) {
100 printf("Incorrect times after close - only write time should be set\n");
101 dump_all_info(mem_ctx, &finfo);
106 smbcli_unlink(cli->tree, fname);
109 finfo2.generic.in.fname = fname;
110 finfo2.generic.level = RAW_FILEINFO_ALL_INFO;
111 status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo2);
112 CHECK_STATUS(status, NT_STATUS_OK);
114 io.close.level = RAW_CLOSE_CLOSE;
115 io.close.in.fnum = fnum;
116 io.close.in.write_time = 0;
117 status = smb_raw_close(cli->tree, &io);
118 CHECK_STATUS(status, NT_STATUS_OK);
120 /* the file should have the write time set equal to access time */
121 finfo.generic.in.fname = fname;
122 finfo.generic.level = RAW_FILEINFO_ALL_INFO;
123 status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo);
124 CHECK_STATUS(status, NT_STATUS_OK);
126 if (!nt_time_equal(&finfo.all_info.out.write_time,
127 &finfo2.all_info.out.write_time)) {
128 printf("Incorrect write time on file - 0 time should be ignored\n");
129 dump_all_info(mem_ctx, &finfo);
133 printf("testing splclose\n");
135 /* check splclose on a file */
137 io.splclose.level = RAW_CLOSE_SPLCLOSE;
138 io.splclose.in.fnum = fnum;
139 status = smb_raw_close(cli->tree, &io);
140 CHECK_STATUS(status, NT_STATUS_DOS(ERRSRV, ERRerror));
142 printf("testing flush\n");
143 smbcli_close(cli->tree, fnum);
145 io_flush.in.fnum = fnum;
146 status = smb_raw_flush(cli->tree, &io_flush);
147 CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
149 io_flush.in.fnum = 0xffff;
150 status = smb_raw_flush(cli->tree, &io_flush);
151 CHECK_STATUS(status, NT_STATUS_OK);
155 io_flush.in.fnum = fnum;
156 status = smb_raw_flush(cli->tree, &io_flush);
157 CHECK_STATUS(status, NT_STATUS_OK);
159 printf("Testing SMBexit\n");
160 smb_raw_exit(cli->session);
162 io_flush.in.fnum = fnum;
163 status = smb_raw_flush(cli->tree, &io_flush);
164 CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
168 smbcli_close(cli->tree, fnum);
169 smbcli_unlink(cli->tree, fname);
170 torture_close_connection(cli);
171 talloc_free(mem_ctx);