Debian Codegraph @

source4/torture/basic/delaywrite.c

raw
1 /*
2 Unix SMB/CIFS implementation.
3
4 test suite for delayed write update
5
6 Copyright (C) Volker Lendecke 2004
7 Copyright (C) Andrew Tridgell 2004
8 Copyright (C) Jeremy Allison 2004
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24 #include "includes.h"
25 #include "torture/torture.h"
26 #include "libcli/raw/libcliraw.h"
27 #include "libcli/raw/raw_proto.h"
28 #include "system/time.h"
29 #include "system/filesys.h"
30 #include "libcli/libcli.h"
31 #include "torture/util.h"
32 #include "torture/basic/proto.h"
33
34 #define BASEDIR "\\delaywrite"
35
36 static bool test_delayed_write_update(struct torture_context *tctx, struct smbcli_state *cli)
37 {
38 union smb_fileinfo finfo1, finfo2;
39 const char *fname = BASEDIR "\\torture_file.txt";
40 NTSTATUS status;
41 int fnum1 = -1;
42 bool ret = true;
43 ssize_t written;
44
45 torture_comment(tctx, "\nRunning test_delayed_write_update\n");
46
47 torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
48
49 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
50 torture_assert_int_not_equal(tctx, fnum1, -1, talloc_asprintf(tctx,
51 "Failed to open %s", fname));
52
53 finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO;
54 finfo1.basic_info.in.file.fnum = fnum1;
55 finfo2 = finfo1;
56
57 status = smb_raw_fileinfo(cli->tree, tctx, &finfo1);
58 torture_assert_ntstatus_ok(tctx, status, "fileinfo failed");
59
60 torture_comment(tctx, "Initial write time %s\n",
61 nt_time_string(tctx, finfo1.basic_info.out.write_time));
62
63 /* Bypass coarse timesources resolution */
64 smb_msleep(10);
65
66 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
67 torture_assert_int_equal(tctx, written, 1,
68 "unexpected number of bytes written");
69
70 status = smb_raw_fileinfo(cli->tree, tctx, &finfo2);
71 torture_assert_ntstatus_ok(tctx, status, "fileinfo failed");
72
73 torture_comment(tctx, "write time %s\n",
74 nt_time_string(tctx, finfo2.basic_info.out.write_time));
75
76 torture_assert_u64_not_equal(tctx,
77 finfo2.basic_info.out.write_time,
78 finfo1.basic_info.out.write_time,
79 "Server did not update write time");
80
81 if (fnum1 != -1)
82 smbcli_close(cli->tree, fnum1);
83 smbcli_unlink(cli->tree, fname);
84 smbcli_deltree(cli->tree, BASEDIR);
85
86 return ret;
87 }
88
89 static bool test_delayed_write_update1(struct torture_context *tctx, struct smbcli_state *cli)
90 {
91 union smb_fileinfo finfo1, finfo2, finfo3, pinfo4;
92 const char *fname = BASEDIR "\\torture_file1.txt";
93 NTSTATUS status;
94 int fnum1 = -1;
95 bool ret = true;
96 ssize_t written;
97 struct timeval start;
98 struct timeval end;
99 double used_delay = torture_setting_int(tctx, "writetimeupdatedelay", 2000000);
100 int normal_delay = 2000000;
101 double sec = ((double)used_delay) / ((double)normal_delay);
102 int msec = 1000 * sec;
103 char buf[2048];
104 bool first;
105 bool updated;
106
107 torture_comment(tctx, "\nRunning test_delayed_write_update1\n");
108
109 torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
110
111 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
112 torture_assert_int_not_equal(tctx, fnum1, -1, talloc_asprintf(tctx,
113 "Failed to open %s", fname));
114
115 memset(buf, 'x', 2048);
116 written = smbcli_write(cli->tree, fnum1, 0, buf, 0, 2048);
117
118 /* 3 second delay to ensure we get past any 2 second time
119 granularity (older systems may have that) */
120 smb_msleep(3 * msec);
121
122 finfo1.all_info.level = RAW_FILEINFO_ALL_INFO;
123 finfo1.all_info.in.file.fnum = fnum1;
124 finfo2 = finfo1;
125 finfo3 = finfo1;
126 pinfo4.all_info.level = RAW_FILEINFO_ALL_INFO;
127 pinfo4.all_info.in.file.path = fname;
128
129 status = smb_raw_fileinfo(cli->tree, tctx, &finfo1);
130
131 torture_assert_ntstatus_ok(tctx, status, "fileinfo failed");
132
133 torture_assert_u64_equal(tctx, finfo1.all_info.out.size, 2048,
134 "file size not as expected after write(2048)");
135
136 torture_comment(tctx, "Initial write time %s\n",
137 nt_time_string(tctx, finfo1.all_info.out.write_time));
138
139 /* 3 second delay to ensure we get past any 2 second time
140 granularity (older systems may have that) */
141 smb_msleep(3 * msec);
142
143 /* Do a zero length SMBwrite call to truncate. */
144 written = smbcli_smbwrite(cli->tree, fnum1, "x", 1024, 0);
145 torture_assert_int_equal(tctx, written, 0,
146 "unexpected number of bytes written");
147
148 start = timeval_current();
149 end = timeval_add(&start, (120 * sec), 0);
150 first = true;
151 updated = false;
152 while (!timeval_expired(&end)) {
153 status = smb_raw_fileinfo(cli->tree, tctx, &finfo2);
154
155 torture_assert_ntstatus_ok(tctx, status, "fileinfo failed");
156
157 torture_assert_u64_equal(tctx, finfo2.all_info.out.size, 1024,
158 "file not truncated to expected size "
159 "(1024)");
160
161 torture_comment(tctx, "write time %s\n",
162 nt_time_string(tctx, finfo2.all_info.out.write_time));
163
164 if (finfo1.all_info.out.write_time !=
165 finfo2.all_info.out.write_time)
166 {
167 updated = true;
168 break;
169 }
170
171 fflush(stdout);
172 smb_msleep(1 * msec);
173 first = false;
174 }
175
176 torture_assert(tctx, updated,
177 "Server did not update write time within 120 seconds");
178
179 torture_assert(tctx, first, talloc_asprintf(tctx,
180 "Server did not update write time immediately but only "
181 "after %.2f seconds!", timeval_elapsed(&start)));
182
183 torture_comment(tctx, "Server updated write time immediately. Good!\n");
184
185 fflush(stdout);
186 smb_msleep(2 * msec);
187
188 /* Do a non-zero length SMBwrite and make sure it updates the write time. */
189 written = smbcli_smbwrite(cli->tree, fnum1, "x", 0, 1);
190 torture_assert_int_equal(tctx, written, 1,
191 "unexpected number of bytes written");
192
193 updated = false;
194 start = timeval_current();
195 end = timeval_add(&start, (10*sec), 0);
196 while (!timeval_expired(&end)) {
197 status = smb_raw_fileinfo(cli->tree, tctx, &finfo3);
198
199 torture_assert_ntstatus_ok(tctx, status, "fileinfo failed");
200
201 torture_assert_u64_equal(tctx, finfo3.all_info.out.size, 1024,
202 "file not truncated to expected size "
203 "(1024)");
204
205 torture_comment(tctx, "write time %s\n",
206 nt_time_string(tctx, finfo3.all_info.out.write_time));
207
208 if (finfo3.all_info.out.write_time !=
209 finfo2.all_info.out.write_time)
210 {
211 updated = true;
212 break;
213 }
214 fflush(stdout);
215 smb_msleep(1 * msec);
216 }
217
218 torture_assert(tctx, updated,
219 "Server did not update write time within 10 seconds");
220
221 fflush(stdout);
222 smb_msleep(2 * msec);
223
224 /* the close should not trigger an write time update */
225 smbcli_close(cli->tree, fnum1);
226 fnum1 = -1;
227
228 status = smb_raw_pathinfo(cli->tree, tctx, &pinfo4);
229 torture_assert_ntstatus_ok(tctx, status, "pathinfo failed");
230
231 torture_assert_u64_equal(tctx,
232 pinfo4.all_info.out.write_time,
233 finfo3.all_info.out.write_time,
234 "Server did update write time on "
235 "close (wrong!)");
236
237 if (fnum1 != -1)
238 smbcli_close(cli->tree, fnum1);
239 smbcli_unlink(cli->tree, fname);
240 smbcli_deltree(cli->tree, BASEDIR);
241
242 return ret;
243 }
244
245 /* Updating with a SMBwrite of zero length
246 * changes the write time immediately - even on expand. */
247
248 static bool test_delayed_write_update1a(struct torture_context *tctx, struct smbcli_state *cli)
249 {
250 union smb_fileinfo finfo1, finfo2, finfo3, pinfo4;
251 const char *fname = BASEDIR "\\torture_file1a.txt";
252 NTSTATUS status;
253 int fnum1 = -1;
254 bool ret = true;
255 ssize_t written;
256 char buf[2048];
257
258 torture_comment(tctx, "\nRunning test_delayed_write_update1a\n");
259
260 torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
261
262 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
263 torture_assert_int_not_equal(tctx, fnum1, -1, talloc_asprintf(tctx,
264 "Failed to open %s", fname));
265
266 memset(buf, 'x', 2048);
267 written = smbcli_write(cli->tree, fnum1, 0, buf, 0, 2048);
268
269 /* Bypass possible filesystem granularity */
270 smb_msleep(20);
271
272 finfo1.all_info.level = RAW_FILEINFO_ALL_INFO;
273 finfo1.all_info.in.file.fnum = fnum1;
274 finfo2 = finfo1;
275 finfo3 = finfo1;
276 pinfo4.all_info.level = RAW_FILEINFO_ALL_INFO;
277 pinfo4.all_info.in.file.path = fname;
278
279 status = smb_raw_fileinfo(cli->tree, tctx, &finfo1);
280
281 torture_assert_ntstatus_ok(tctx, status, "fileinfo failed");
282
283 torture_assert_u64_equal(tctx, finfo1.all_info.out.size, 2048,
284 "file size not as expected after write(2048)");
285
286 torture_comment(tctx, "Initial write time %s\n",
287 nt_time_string(tctx, finfo1.all_info.out.write_time));
288
289 /* Do a zero length SMBwrite call to truncate. */
290 written = smbcli_smbwrite(cli->tree, fnum1, "x", 10240, 0);
291
292 torture_assert_int_equal(tctx, written, 0,
293 "unexpected number of bytes written");
294
295 status = smb_raw_fileinfo(cli->tree, tctx, &finfo2);
296 torture_assert_ntstatus_ok(tctx, status, "fileinfo failed");
297
298 torture_assert_u64_equal(tctx, finfo2.all_info.out.size, 10240,
299 "file not truncated to expected size "
300 "(10240)");
301
302 torture_assert_u64_not_equal(tctx,
303 finfo1.all_info.out.write_time,
304 finfo2.all_info.out.write_time,
305 "Server did not update write time immediately");
306
307 torture_comment(tctx, "Server updated write time immediately. Good!\n");
308
309 fflush(stdout);
310 smb_msleep(20);
311
312 /* Do a non-zero length SMBwrite and make sure it doesn't update the write time. */
313 written = smbcli_smbwrite(cli->tree, fnum1, "x", 0, 1);
314
315 torture_assert_int_equal(tctx, written, 1,
316 "unexpected number of bytes written");
317
318 status = smb_raw_fileinfo(cli->tree, tctx, &finfo3);
319 torture_assert_ntstatus_ok(tctx, status, "fileinfo failed");
320
321 torture_assert_u64_equal(tctx, finfo3.all_info.out.size, 10240,
322 "file not truncated to expected size "
323 "(10240)");
324
325 torture_comment(tctx, "write time %s\n",
326 nt_time_string(tctx, finfo3.all_info.out.write_time));
327
328 torture_assert_u64_not_equal(tctx,
329 finfo3.all_info.out.write_time,
330 finfo2.all_info.out.write_time,
331 "Server did not update write time immediately");
332
333 /* the close should not trigger a write time update */
334 smbcli_close(cli->tree, fnum1);
335 fnum1 = -1;
336
337 status = smb_raw_pathinfo(cli->tree, tctx, &pinfo4);
338 torture_assert_ntstatus_ok(tctx, status, "pathinfo failed");
339
340 torture_assert_u64_equal(tctx,
341 pinfo4.all_info.out.write_time,
342 finfo3.all_info.out.write_time,
343 "Server updated write time on "
344 "close (wrong!)");
345
346 smbcli_unlink(cli->tree, fname);
347 smbcli_deltree(cli->tree, BASEDIR);
348
349 return ret;
350 }
351
352 /* Updating with a SET_FILE_END_OF_FILE_INFO
353 * changes the write time immediately - even on expand. */
354
355 static bool test_delayed_write_update1b(struct torture_context *tctx, struct smbcli_state *cli)
356 {
357 union smb_fileinfo finfo1, finfo2, finfo3, pinfo4;
358 const char *fname = BASEDIR "\\torture_file1b.txt";
359 NTSTATUS status;
360 int fnum1 = -1;
361 bool ret = true;
362 ssize_t written;
363 char buf[2048];
364
365 torture_comment(tctx, "\nRunning test_delayed_write_update1b\n");
366
367 torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
368
369 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
370 torture_assert_int_not_equal(tctx, fnum1, -1, talloc_asprintf(tctx,
371 "Failed to open %s", fname));
372
373 memset(buf, 'x', 2048);
374 written = smbcli_write(cli->tree, fnum1, 0, buf, 0, 2048);
375
376 /* Bypass possible filesystem granularity */
377 smb_msleep(20);
378
379 finfo1.all_info.level = RAW_FILEINFO_ALL_INFO;
380 finfo1.all_info.in.file.fnum = fnum1;
381 finfo2 = finfo1;
382 finfo3 = finfo1;
383 pinfo4.all_info.level = RAW_FILEINFO_ALL_INFO;
384 pinfo4.all_info.in.file.path = fname;
385
386 status = smb_raw_fileinfo(cli->tree, tctx, &finfo1);
387
388 torture_assert_ntstatus_ok(tctx, status, "fileinfo failed");
389
390 torture_assert_u64_equal(tctx, finfo1.all_info.out.size, 2048,
391 "file size not as expected after write(2048)");
392
393 torture_comment(tctx, "Initial write time %s\n",
394 nt_time_string(tctx, finfo1.all_info.out.write_time));
395
396 /* Bypass possible filesystem granularity */
397 smb_msleep(20);
398
399 /* Do a SET_END_OF_FILE_INFO call to truncate. */
400 status = smbcli_ftruncate(cli->tree, fnum1, (uint64_t)10240);
401
402 torture_assert_ntstatus_ok(tctx, status, "SET_END_OF_FILE failed");
403
404 status = smb_raw_fileinfo(cli->tree, tctx, &finfo2);
405 torture_assert_ntstatus_ok(tctx, status, "fileinfo failed");
406
407 torture_assert_u64_equal(tctx, finfo2.all_info.out.size, 10240,
408 "file not truncated to expected size "
409 "(10240)");
410
411 torture_comment(tctx, "write time %s\n",
412 nt_time_string(tctx, finfo2.all_info.out.write_time));
413
414 torture_assert_u64_not_equal(tctx,
415 finfo2.all_info.out.write_time,
416 finfo1.all_info.out.write_time,
417 "Server did not update write time "
418 "immediately");
419
420 fflush(stdout);
421 /* Bypass possible filesystem granularity */
422 smb_msleep(20);
423
424 /* Do a non-zero length SMBwrite and make sure it doesn't update the write time. */
425 written = smbcli_smbwrite(cli->tree, fnum1, "x", 0, 1);
426
427 torture_assert_int_equal(tctx, written, 1,
428 "unexpected number of bytes written");
429
430 status = smb_raw_fileinfo(cli->tree, tctx, &finfo3);
431 torture_assert_ntstatus_ok(tctx, status, "fileinfo failed");
432
433 torture_assert_u64_equal(tctx, finfo3.all_info.out.size, 10240,
434 "file not truncated to expected size "
435 "(10240)");
436
437 torture_comment(tctx, "write time %s\n",
438 nt_time_string(tctx, finfo3.all_info.out.write_time));
439
440 torture_assert_u64_not_equal(tctx,
441 finfo3.all_info.out.write_time,
442 finfo2.all_info.out.write_time,
443 "Server did not update write time "
444 "immediately");
445
446 /* the close should not trigger an write time update */
447 smbcli_close(cli->tree, fnum1);
448 fnum1 = -1;
449
450 status = smb_raw_pathinfo(cli->tree, tctx, &pinfo4);
451 torture_assert_ntstatus_ok(tctx, status, "pathinfo failed");
452
453 torture_assert_u64_equal(tctx,
454 pinfo4.all_info.out.write_time,
455 finfo3.all_info.out.write_time,
456 "Server updated write time on "
457 "close (wrong!)");
458
459 if (fnum1 != -1)
460 smbcli_close(cli->tree, fnum1);
461 smbcli_unlink(cli->tree, fname);
462 smbcli_deltree(cli->tree, BASEDIR);
463
464 return ret;
465 }
466
467 /* Updating with a SET_ALLOCATION_INFO (truncate) does so immediately. */
468
469 static bool test_delayed_write_update1c(struct torture_context *tctx, struct smbcli_state *cli)
470 {
471 union smb_setfileinfo parms;
472 union smb_fileinfo finfo1, finfo2, finfo3, pinfo4;
473 const char *fname = BASEDIR "\\torture_file1c.txt";
474 NTSTATUS status;
475 int fnum1 = -1;
476 bool ret = true;
477 ssize_t written;
478 char buf[2048];
479
480 torture_comment(tctx, "\nRunning test_delayed_write_update1c\n");
481
482 torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
483
484 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
485 torture_assert_int_not_equal(tctx, fnum1, -1, talloc_asprintf(tctx,
486 "Failed to open %s", fname));
487
488 memset(buf, 'x', 2048);
489 written = smbcli_write(cli->tree, fnum1, 0, buf, 0, 2048);
490
491 /* Bypass possible filesystem granularity */
492 smb_msleep(20);
493
494 finfo1.all_info.level = RAW_FILEINFO_ALL_INFO;
495 finfo1.all_info.in.file.fnum = fnum1;
496 finfo2 = finfo1;
497 finfo3 = finfo1;
498 pinfo4.all_info.level = RAW_FILEINFO_ALL_INFO;
499 pinfo4.all_info.in.file.path = fname;
500
501 status = smb_raw_fileinfo(cli->tree, tctx, &finfo1);
502
503 torture_assert_ntstatus_ok(tctx, status, "fileinfo failed");
504
505 torture_assert_u64_equal(tctx, finfo1.all_info.out.size, 2048,
506 "file size not as expected after write(2048)");
507
508 torture_comment(tctx, "Initial write time %s\n",
509 nt_time_string(tctx, finfo1.all_info.out.write_time));
510
511 /* Do a SET_ALLOCATION_SIZE call to truncate. */
512 parms.allocation_info.level = RAW_SFILEINFO_ALLOCATION_INFO;
513 parms.allocation_info.in.file.fnum = fnum1;
514 parms.allocation_info.in.alloc_size = 0;
515
516 status = smb_raw_setfileinfo(cli->tree, &parms);
517
518 torture_assert_ntstatus_ok(tctx, status,
519 "RAW_SFILEINFO_ALLOCATION_INFO failed");
520
521 status = smb_raw_fileinfo(cli->tree, tctx, &finfo2);
522 torture_assert_ntstatus_ok(tctx, status, "fileinfo failed");
523
524 torture_assert_u64_equal(tctx, finfo2.all_info.out.size, 0,
525 "file not truncated to expected size "
526 "(0)");
527
528 torture_comment(tctx, "write time %s\n",
529 nt_time_string(tctx, finfo2.all_info.out.write_time));
530
531 torture_assert_u64_not_equal(tctx,
532 finfo2.all_info.out.write_time,
533 finfo1.all_info.out.write_time,
534 "Server did not update write time "
535 "immediately");
536
537 /* Bypass possible filesystem granularity */
538 smb_msleep(20);
539
540 /* Do a non-zero length SMBwrite and make sure it doesn't update the write time. */
541 written = smbcli_smbwrite(cli->tree, fnum1, "x", 0, 1);
542 torture_assert_int_equal(tctx, written, 1,
543 "Unexpected number of bytes written");
544
545 status = smb_raw_fileinfo(cli->tree, tctx, &finfo3);
546 torture_assert_ntstatus_ok(tctx, status, "fileinfo failed");
547
548 torture_assert_u64_equal(tctx, finfo3.all_info.out.size, 1,
549 "file not expaneded");
550
551 torture_comment(tctx, "write time %s\n",
552 nt_time_string(tctx, finfo3.all_info.out.write_time));
553
554 torture_assert_u64_not_equal(tctx,
555 finfo3.all_info.out.write_time,
556 finfo2.all_info.out.write_time,
557 "Server did not update write time "
558 "immediately");
559
560 /* the close should trigger an write time update */
561 smbcli_close(cli->tree, fnum1);
562 fnum1 = -1;
563
564 status = smb_raw_pathinfo(cli->tree, tctx, &pinfo4);
565 torture_assert_ntstatus_ok(tctx, status, "pathinfo failed");
566
567 torture_assert_u64_equal(tctx,
568 pinfo4.all_info.out.write_time,
569 finfo3.all_info.out.write_time,
570 "Server updated write time on "
571 "close (wrong!)");
572 if (fnum1 != -1)
573 smbcli_close(cli->tree, fnum1);
574 smbcli_unlink(cli->tree, fname);
575 smbcli_deltree(cli->tree, BASEDIR);
576
577 return ret;
578 }
579
580 /*
581 * Do as above, but using 2 connections.
582 */
583
584 static bool test_delayed_write_update2(struct torture_context *tctx, struct smbcli_state *cli,
585 struct smbcli_state *cli2)
586 {
587 union smb_fileinfo finfo1, finfo2;
588 const char *fname = BASEDIR "\\torture_file.txt";
589 NTSTATUS status;
590 int fnum1 = -1;
591 int fnum2 = -1;
592 bool ret = true;
593 ssize_t written;
594 struct timeval start;
595 struct timeval end;
596 double used_delay = torture_setting_int(tctx, "writetimeupdatedelay", 2000000);
597 int normal_delay = 2000000;
598 double sec = ((double)used_delay) / ((double)normal_delay);
599 int msec = 1000 * sec;
600 union smb_flush flsh;
601
602 torture_comment(tctx, "\nRunning test_delayed_write_update2\n");
603
604 torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
605
606 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
607 if (fnum1 == -1) {
608 torture_comment(tctx, "Failed to open %s\n", fname);
609 return false;
610 }
611
612 finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO;
613 finfo1.basic_info.in.file.fnum = fnum1;
614 finfo2 = finfo1;
615
616 status = smb_raw_fileinfo(cli->tree, tctx, &finfo1);
617
618 torture_assert_ntstatus_ok(tctx, status, "fileinfo failed");
619
620 torture_comment(tctx, "Initial write time %s\n",
621 nt_time_string(tctx, finfo1.basic_info.out.write_time));
622
623 /* Bypass possible filesystem granularity */
624 smb_msleep(20);
625
626 {
627 /* Try using setfileinfo instead of write to update write time. */
628 union smb_setfileinfo sfinfo;
629 time_t t_set = time(NULL);
630 sfinfo.basic_info.level = RAW_SFILEINFO_BASIC_INFO;
631 sfinfo.basic_info.in.file.fnum = fnum1;
632 sfinfo.basic_info.in.create_time = finfo1.basic_info.out.create_time;
633 sfinfo.basic_info.in.access_time = finfo1.basic_info.out.access_time;
634
635 /* I tried this with both + and - ve to see if it makes a different.
636 It doesn't - once the filetime is set via setfileinfo it stays that way. */
637 #if 1
638 unix_to_nt_time(&sfinfo.basic_info.in.write_time, t_set - 30000);
639 #else
640 unix_to_nt_time(&sfinfo.basic_info.in.write_time, t_set + 30000);
641 #endif
642 sfinfo.basic_info.in.change_time = finfo1.basic_info.out.change_time;
643 sfinfo.basic_info.in.attrib = finfo1.basic_info.out.attrib;
644
645 status = smb_raw_setfileinfo(cli->tree, &sfinfo);
646
647 torture_assert_ntstatus_ok(tctx, status, "sfileinfo failed");
648 }
649
650 finfo2.basic_info.in.file.path = fname;
651
652 status = smb_raw_pathinfo(cli2->tree, tctx, &finfo2);
653
654 if (!NT_STATUS_IS_OK(status)) {
655 DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
656 return false;
657 }
658 torture_comment(tctx, "write time %s\n",
659 nt_time_string(tctx, finfo2.basic_info.out.write_time));
660
661 torture_assert_u64_not_equal(tctx,
662 finfo2.all_info.out.write_time,
663 finfo1.all_info.out.write_time,
664 "Server did not update write time "
665 "immediately");
666
667 /* Now try a write to see if the write time gets reset. */
668
669 finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO;
670 finfo1.basic_info.in.file.fnum = fnum1;
671 finfo2 = finfo1;
672
673 status = smb_raw_fileinfo(cli->tree, tctx, &finfo1);
674
675 if (!NT_STATUS_IS_OK(status)) {
676 DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
677 return false;
678 }
679
680 torture_comment(tctx, "Modified write time %s\n",
681 nt_time_string(tctx, finfo1.basic_info.out.write_time));
682
683
684 torture_comment(tctx, "Doing a 10 byte write to extend the file and see if this changes the last write time.\n");
685
686 written = smbcli_write(cli->tree, fnum1, 0, "0123456789", 1, 10);
687
688 if (written != 10) {
689 torture_result(tctx, TORTURE_FAIL, "write failed - wrote %d bytes (%s)\n",
690 (int)written, __location__);
691 return false;
692 }
693
694 /* Just to prove to tridge that the an smbflush has no effect on
695 the write time :-). The setfileinfo IS STICKY. JRA. */
696
697 torture_comment(tctx, "Doing flush after write\n");
698
699 flsh.flush.level = RAW_FLUSH_FLUSH;
700 flsh.flush.in.file.fnum = fnum1;
701 status = smb_raw_flush(cli->tree, &flsh);
702 if (!NT_STATUS_IS_OK(status)) {
703 DEBUG(0, ("smbflush failed: %s\n", nt_errstr(status)));
704 return false;
705 }
706
707 /* Once the time was set using setfileinfo then it stays set - writes
708 don't have any effect. But make sure. */
709 start = timeval_current();
710 end = timeval_add(&start, (4*sec), 0);
711 while (!timeval_expired(&end)) {
712 status = smb_raw_fileinfo(cli->tree, tctx, &finfo2);
713
714 if (!NT_STATUS_IS_OK(status)) {
715 DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
716 ret = false;
717 break;
718 }
719 torture_comment(tctx, "write time %s\n",
720 nt_time_string(tctx, finfo2.basic_info.out.write_time));
721
722 torture_assert_u64_equal(tctx,
723 finfo2.all_info.out.write_time,
724 finfo1.all_info.out.write_time,
725 "Server updated write time");
726
727 fflush(stdout);
728 smb_msleep(1 * msec);
729 }
730
731 fflush(stdout);
732 smb_msleep(2 * msec);
733
734 fnum2 = smbcli_open(cli->tree, fname, O_RDWR, DENY_NONE);
735 if (fnum2 == -1) {
736 torture_result(tctx, TORTURE_FAIL, "Failed to open %s\n", fname);
737 return false;
738 }
739
740 torture_comment(tctx, "Doing a 10 byte write to extend the file via second fd and see if this changes the last write time.\n");
741
742 written = smbcli_write(cli->tree, fnum2, 0, "0123456789", 11, 10);
743
744 if (written != 10) {
745 torture_result(tctx, TORTURE_FAIL, "write failed - wrote %d bytes (%s)\n",
746 (int)written, __location__);
747 return false;
748 }
749
750 status = smb_raw_fileinfo(cli->tree, tctx, &finfo2);
751
752 if (!NT_STATUS_IS_OK(status)) {
753 DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
754 return false;
755 }
756 torture_comment(tctx, "write time %s\n",
757 nt_time_string(tctx, finfo2.basic_info.out.write_time));
758
759 torture_assert_u64_not_equal(tctx,
760 finfo2.all_info.out.write_time,
761 finfo1.all_info.out.write_time,
762 "Server did not update write time");
763
764 torture_comment(tctx, "Closing the first fd to see if write time updated.\n");
765 smbcli_close(cli->tree, fnum1);
766 fnum1 = -1;
767
768 torture_comment(tctx, "Doing a 10 byte write to extend the file via second fd and see if this changes the last write time.\n");
769
770 written = smbcli_write(cli->tree, fnum2, 0, "0123456789", 21, 10);
771
772 if (written != 10) {
773 torture_result(tctx, TORTURE_FAIL, "write failed - wrote %d bytes (%s)\n",
774 (int)written, __location__);
775 return false;
776 }
777
778 finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO;
779 finfo1.basic_info.in.file.fnum = fnum2;
780 finfo2 = finfo1;
781 status = smb_raw_fileinfo(cli->tree, tctx, &finfo2);
782
783 if (!NT_STATUS_IS_OK(status)) {
784 DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
785 return false;
786 }
787 torture_comment(tctx, "write time %s\n",
788 nt_time_string(tctx, finfo2.basic_info.out.write_time));
789
790 torture_assert_u64_not_equal(tctx,
791 finfo2.all_info.out.write_time,
792 finfo1.all_info.out.write_time,
793 "Server did not update write time "
794 "immediately");
795
796 /*
797 * Sticky write time only applied to the handle
798 * that was used to set the write time.
799 */
800 start = timeval_current();
801 end = timeval_add(&start, (4*sec), 0);
802 while (!timeval_expired(&end)) {
803 status = smb_raw_fileinfo(cli->tree, tctx, &finfo2);
804
805 if (!NT_STATUS_IS_OK(status)) {
806 DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
807 ret = false;
808 break;
809 }
810 torture_comment(tctx, "write time %s\n",
811 nt_time_string(tctx, finfo2.basic_info.out.write_time));
812 if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) {
813 break;
814 }
815 fflush(stdout);
816 smb_msleep(1 * msec);
817 }
818
819 torture_assert_u64_not_equal(tctx,
820 finfo2.all_info.out.write_time,
821 finfo1.all_info.out.write_time,
822 "Server did not update write time "
823 "immediately");
824
825 torture_comment(tctx, "Closing second fd to see if write time updated.\n");
826
827 smbcli_close(cli->tree, fnum2);
828 fnum2 = -1;
829
830 fnum1 = smbcli_open(cli->tree, fname, O_RDWR, DENY_NONE);
831 if (fnum1 == -1) {
832 torture_comment(tctx, "Failed to open %s\n", fname);
833 return false;
834 }
835
836 finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO;
837 finfo1.basic_info.in.file.fnum = fnum1;
838 finfo2 = finfo1;
839
840 status = smb_raw_fileinfo(cli->tree, tctx, &finfo1);
841
842 if (!NT_STATUS_IS_OK(status)) {
843 DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
844 return false;
845 }
846
847 torture_comment(tctx, "Second open initial write time %s\n",
848 nt_time_string(tctx, finfo1.basic_info.out.write_time));
849
850 smb_msleep(10 * msec);
851 torture_comment(tctx, "Doing a 10 byte write to extend the file to see if this changes the last write time.\n");
852
853 written = smbcli_write(cli->tree, fnum1, 0, "0123456789", 31, 10);
854
855 if (written != 10) {
856 torture_result(tctx, TORTURE_FAIL, "write failed - wrote %d bytes (%s)\n",
857 (int)written, __location__);
858 return false;
859 }
860
861 finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO;
862 finfo1.basic_info.in.file.fnum = fnum1;
863 finfo2 = finfo1;
864 status = smb_raw_fileinfo(cli->tree, tctx, &finfo2);
865
866 if (!NT_STATUS_IS_OK(status)) {
867 DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
868 return false;
869 }
870 torture_comment(tctx, "write time %s\n",
871 nt_time_string(tctx, finfo2.basic_info.out.write_time));
872
873 torture_assert_u64_not_equal(tctx,
874 finfo2.all_info.out.write_time,
875 finfo1.all_info.out.write_time,
876 "Server did not update write time "
877 "immediately");
878
879 /* One more test to do. We should read the filetime via findfirst on the
880 second connection to ensure it's the same. This is very easy for a Windows
881 server but a bastard to get right on a POSIX server. JRA. */
882
883 if (fnum1 != -1)
884 smbcli_close(cli->tree, fnum1);
885 smbcli_unlink(cli->tree, fname);
886 smbcli_deltree(cli->tree, BASEDIR);
887
888 return ret;
889 }
890
891
892 /* Windows does obviously not update the stat info during a write call. I
893 * *think* this is the problem causing a spurious Excel 2003 on XP error
894 * message when saving a file. Excel does a setfileinfo, writes, and then does
895 * a getpath(!)info. Or so... For Samba sometimes it displays an error message
896 * that the file might have been changed in between. What i've been able to
897 * trace down is that this happens if the getpathinfo after the write shows a
898 * different last write time than the setfileinfo showed. This is really
899 * nasty....
900 */
901
902 static bool test_finfo_after_write(struct torture_context *tctx, struct smbcli_state *cli,
903 struct smbcli_state *cli2)
904 {
905 union smb_fileinfo finfo1, finfo2;
906 const char *fname = BASEDIR "\\torture_file.txt";
907 NTSTATUS status;
908 int fnum1 = -1;
909 int fnum2;
910 bool ret = true;
911 ssize_t written;
912 double used_delay = torture_setting_int(tctx, "writetimeupdatedelay", 2000000);
913 int normal_delay = 2000000;
914 double sec = ((double)used_delay) / ((double)normal_delay);
915 int msec = 1000 * sec;
916
917 torture_comment(tctx, "\nRunning test_finfo_after_write\n");
918
919 torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
920
921 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
922 if (fnum1 == -1) {
923 ret = false;
924 torture_result(tctx, TORTURE_FAIL, __location__": unable to open %s", fname);
925 goto done;
926 }
927
928 finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO;
929 finfo1.basic_info.in.file.fnum = fnum1;
930
931 status = smb_raw_fileinfo(cli->tree, tctx, &finfo1);
932
933 if (!NT_STATUS_IS_OK(status)) {
934 ret = false;
935 torture_result(tctx, TORTURE_FAIL, __location__": fileinfo failed: %s", nt_errstr(status));
936 goto done;
937 }
938
939 smb_msleep(1 * msec);
940
941 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
942
943 if (written != 1) {
944 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
945 ret = false;
946 goto done;
947 }
948
949 fnum2 = smbcli_open(cli2->tree, fname, O_RDWR, DENY_NONE);
950 if (fnum2 == -1) {
951 torture_result(tctx, TORTURE_FAIL, __location__": failed to open 2nd time - %s",
952 smbcli_errstr(cli2->tree));
953 ret = false;
954 goto done;
955 }
956
957 written = smbcli_write(cli2->tree, fnum2, 0, "x", 0, 1);
958
959 if (written != 1) {
960 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1",
961 (int)written);
962 ret = false;
963 goto done;
964 }
965
966 finfo2.basic_info.level = RAW_FILEINFO_BASIC_INFO;
967 finfo2.basic_info.in.file.path = fname;
968
969 status = smb_raw_pathinfo(cli2->tree, tctx, &finfo2);
970
971 if (!NT_STATUS_IS_OK(status)) {
972 torture_result(tctx, TORTURE_FAIL, __location__": fileinfo failed: %s",
973 nt_errstr(status));
974 ret = false;
975 goto done;
976 }
977
978 if (finfo1.basic_info.out.create_time !=
979 finfo2.basic_info.out.create_time) {
980 torture_result(tctx, TORTURE_FAIL, __location__": create_time changed");
981 ret = false;
982 goto done;
983 }
984
985 if (finfo1.basic_info.out.write_time ==
986 finfo2.basic_info.out.write_time) {
987 torture_result(tctx, TORTURE_FAIL, __location__": write_time unchanged:\n"
988 "write time conn 1 = %s, conn 2 = %s",
989 nt_time_string(tctx, finfo1.basic_info.out.write_time),
990 nt_time_string(tctx, finfo2.basic_info.out.write_time));
991 ret = false;
992 goto done;
993 }
994
995 if (finfo1.basic_info.out.change_time ==
996 finfo2.basic_info.out.change_time) {
997 torture_result(tctx, TORTURE_FAIL, __location__": change_time unchanged");
998 ret = false;
999 goto done;
1000 }
1001
1002 /* One of the two following calls updates the qpathinfo. */
1003
1004 /* If you had skipped the smbcli_write on fnum2, it would
1005 * *not* have updated the stat on disk */
1006
1007 smbcli_close(cli2->tree, fnum2);
1008 cli2 = NULL;
1009
1010 /* This call is only for the people looking at ethereal :-) */
1011 finfo2.basic_info.level = RAW_FILEINFO_BASIC_INFO;
1012 finfo2.basic_info.in.file.path = fname;
1013
1014 status = smb_raw_pathinfo(cli->tree, tctx, &finfo2);
1015
1016 if (!NT_STATUS_IS_OK(status)) {
1017 torture_result(tctx, TORTURE_FAIL, __location__": fileinfo failed: %s", nt_errstr(status));
1018 ret = false;
1019 goto done;
1020 }
1021
1022 done:
1023 if (fnum1 != -1)
1024 smbcli_close(cli->tree, fnum1);
1025 smbcli_unlink(cli->tree, fname);
1026 smbcli_deltree(cli->tree, BASEDIR);
1027
1028 return ret;
1029 }
1030
1031 #define COMPARE_WRITE_TIME_CMP(given, correct, cmp) do { \
1032 uint64_t r = 10*1000*1000; \
1033 NTTIME g = (given).basic_info.out.write_time; \
1034 NTTIME gr = (g / r) * r; \
1035 NTTIME c = (correct).basic_info.out.write_time; \
1036 NTTIME cr = (c / r) * r; \
1037 bool strict = torture_setting_bool(tctx, "strict mode", false); \
1038 bool err = false; \
1039 if (strict && (g cmp c)) { \
1040 err = true; \
1041 } else if ((g cmp c) && (gr cmp cr)) { \
1042 /* handle filesystem without high resolution timestamps */ \
1043 err = true; \
1044 } \
1045 if (err) { \
1046 torture_result(tctx, TORTURE_FAIL, __location__": wrong write_time (%s)%s(%llu) %s (%s)%s(%llu)", \
1047 #given, nt_time_string(tctx, g), (unsigned long long)g, \
1048 #cmp, #correct, nt_time_string(tctx, c), (unsigned long long)c); \
1049 ret = false; \
1050 goto done; \
1051 } \
1052 } while (0)
1053 #define COMPARE_WRITE_TIME_EQUAL(given,correct) \
1054 COMPARE_WRITE_TIME_CMP(given,correct,!=)
1055 #define COMPARE_WRITE_TIME_GREATER(given,correct) \
1056 COMPARE_WRITE_TIME_CMP(given,correct,<=)
1057 #define COMPARE_WRITE_TIME_LESS(given,correct) \
1058 COMPARE_WRITE_TIME_CMP(given,correct,>=)
1059
1060 #define COMPARE_ACCESS_TIME_CMP(given, correct, cmp) do { \
1061 NTTIME g = (given).basic_info.out.access_time; \
1062 NTTIME c = (correct).basic_info.out.access_time; \
1063 if (g cmp c) { \
1064 torture_result(tctx, TORTURE_FAIL, __location__": wrong access_time (%s)%s %s (%s)%s", \
1065 #given, nt_time_string(tctx, g), \
1066 #cmp, #correct, nt_time_string(tctx, c)); \
1067 ret = false; \
1068 goto done; \
1069 } \
1070 } while (0)
1071 #define COMPARE_ACCESS_TIME_EQUAL(given,correct) \
1072 COMPARE_ACCESS_TIME_CMP(given,correct,!=)
1073
1074 #define COMPARE_BOTH_TIMES_EQUAL(given,correct) do { \
1075 COMPARE_ACCESS_TIME_EQUAL(given,correct); \
1076 COMPARE_WRITE_TIME_EQUAL(given,correct); \
1077 } while (0)
1078
1079 #define GET_INFO_FILE(finfo) do { \
1080 NTSTATUS _status; \
1081 _status = smb_raw_fileinfo(cli->tree, tctx, &finfo); \
1082 if (!NT_STATUS_IS_OK(_status)) { \
1083 ret = false; \
1084 torture_result(tctx, TORTURE_FAIL, __location__": fileinfo failed: %s", \
1085 nt_errstr(_status)); \
1086 goto done; \
1087 } \
1088 torture_comment(tctx, "fileinfo: Access(%s) Write(%s)\n", \
1089 nt_time_string(tctx, finfo.basic_info.out.access_time), \
1090 nt_time_string(tctx, finfo.basic_info.out.write_time)); \
1091 } while (0)
1092 #define GET_INFO_FILE2(finfo) do { \
1093 NTSTATUS _status; \
1094 _status = smb_raw_fileinfo(cli2->tree, tctx, &finfo); \
1095 if (!NT_STATUS_IS_OK(_status)) { \
1096 ret = false; \
1097 torture_result(tctx, TORTURE_FAIL, __location__": fileinfo failed: %s", \
1098 nt_errstr(_status)); \
1099 goto done; \
1100 } \
1101 torture_comment(tctx, "fileinfo: Access(%s) Write(%s)\n", \
1102 nt_time_string(tctx, finfo.basic_info.out.access_time), \
1103 nt_time_string(tctx, finfo.basic_info.out.write_time)); \
1104 } while (0)
1105 #define GET_INFO_FILE_EX(cli,_fnum,finfo) do { \
1106 NTSTATUS _status; \
1107 finfo.basic_info.in.file.fnum = (_fnum); \
1108 _status = smb_raw_fileinfo((cli)->tree, tctx, &(finfo)); \
1109 torture_assert_ntstatus_ok_goto(tctx, _status, ret, done,\
1110 "smb_raw_fileinfo failed"); \
1111 torture_comment(tctx, "fileinfo: Access(%s) Write(%s)\n", \
1112 nt_time_string(tctx, (finfo).basic_info.out.access_time), \
1113 nt_time_string(tctx, (finfo).basic_info.out.write_time)); \
1114 } while (0)
1115 #define GET_INFO_PATH(pinfo) do { \
1116 NTSTATUS _status; \
1117 _status = smb_raw_pathinfo(cli2->tree, tctx, &pinfo); \
1118 if (!NT_STATUS_IS_OK(_status)) { \
1119 torture_result(tctx, TORTURE_FAIL, __location__": pathinfo failed: %s", \
1120 nt_errstr(_status)); \
1121 ret = false; \
1122 goto done; \
1123 } \
1124 torture_comment(tctx, "pathinfo: Access(%s) Write(%s)\n", \
1125 nt_time_string(tctx, pinfo.basic_info.out.access_time), \
1126 nt_time_string(tctx, pinfo.basic_info.out.write_time)); \
1127 } while (0)
1128 #define GET_INFO_PATH_EX(cli, pinfo) do { \
1129 NTSTATUS _status; \
1130 _status = smb_raw_pathinfo((cli)->tree, tctx, &pinfo); \
1131 if (!NT_STATUS_IS_OK(_status)) { \
1132 torture_result(tctx, TORTURE_FAIL, __location__": pathinfo failed: %s", \
1133 nt_errstr(_status)); \
1134 ret = false; \
1135 goto done; \
1136 } \
1137 torture_comment(tctx, "pathinfo: Access(%s) Write(%s)\n", \
1138 nt_time_string(tctx, pinfo.basic_info.out.access_time), \
1139 nt_time_string(tctx, pinfo.basic_info.out.write_time)); \
1140 } while (0)
1141 #define GET_INFO_BOTH(finfo,pinfo) do { \
1142 GET_INFO_FILE(finfo); \
1143 GET_INFO_PATH(pinfo); \
1144 COMPARE_BOTH_TIMES_EQUAL(finfo,pinfo); \
1145 } while (0)
1146
1147 #define GET_INFO_BOTH_EX(cli, fnum, finfo, pinfo) do { \
1148 GET_INFO_FILE_EX(cli, fnum, finfo); \
1149 GET_INFO_PATH_EX(cli, pinfo); \
1150 COMPARE_BOTH_TIMES_EQUAL(finfo, pinfo); \
1151 } while (0)
1152
1153 #define SET_INFO_FILE_EX(finfo, wrtime, tree, tfnum) do { \
1154 NTSTATUS _status; \
1155 union smb_setfileinfo _sfinfo; \
1156 _sfinfo.basic_info.level = RAW_SFILEINFO_BASIC_INFO; \
1157 _sfinfo.basic_info.in.file.fnum = tfnum; \
1158 _sfinfo.basic_info.in.create_time = 0; \
1159 _sfinfo.basic_info.in.access_time = 0; \
1160 unix_to_nt_time(&_sfinfo.basic_info.in.write_time, (wrtime)); \
1161 _sfinfo.basic_info.in.change_time = 0; \
1162 _sfinfo.basic_info.in.attrib = finfo.basic_info.out.attrib; \
1163 _status = smb_raw_setfileinfo(tree, &_sfinfo); \
1164 if (!NT_STATUS_IS_OK(_status)) { \
1165 torture_result(tctx, TORTURE_FAIL, __location__": setfileinfo failed: %s", \
1166 nt_errstr(_status)); \
1167 ret = false; \
1168 goto done; \
1169 } \
1170 } while (0)
1171 #define SET_INFO_FILE(finfo, wrtime) \
1172 SET_INFO_FILE_EX(finfo, wrtime, cli->tree, fnum1)
1173
1174 #define SET_INFO_FILE_NS(finfo, wrtime, ns, tree, tfnum) do { \
1175 NTSTATUS _status; \
1176 union smb_setfileinfo sfinfo; \
1177 sfinfo.basic_info.level = RAW_SFILEINFO_BASIC_INFO; \
1178 sfinfo.basic_info.in.file.fnum = tfnum; \
1179 sfinfo.basic_info.in.create_time = 0; \
1180 sfinfo.basic_info.in.access_time = 0; \
1181 unix_to_nt_time(&sfinfo.basic_info.in.write_time, (wrtime)); \
1182 sfinfo.basic_info.in.write_time += (ns); \
1183 sfinfo.basic_info.in.change_time = 0; \
1184 sfinfo.basic_info.in.attrib = finfo.basic_info.out.attrib; \
1185 _status = smb_raw_setfileinfo(tree, &sfinfo); \
1186 if (!NT_STATUS_IS_OK(_status)) { \
1187 torture_result(tctx, TORTURE_FAIL, __location__": setfileinfo failed: %s", \
1188 nt_errstr(_status)); \
1189 ret = false; \
1190 goto done; \
1191 } \
1192 } while (0)
1193
1194 static bool test_delayed_write_update3(struct torture_context *tctx,
1195 struct smbcli_state *cli,
1196 struct smbcli_state *cli2)
1197 {
1198 union smb_fileinfo finfo0, finfo1, finfo2, finfo3;
1199 union smb_fileinfo pinfo0, pinfo1, pinfo2, pinfo3, pinfo4;
1200 const char *fname = BASEDIR "\\torture_file3.txt";
1201 int fnum1 = -1;
1202 bool ret = true;
1203 ssize_t written;
1204 struct timeval start;
1205 struct timeval end;
1206 double used_delay = torture_setting_int(tctx, "writetimeupdatedelay", 2000000);
1207 int normal_delay = 2000000;
1208 double sec = ((double)used_delay) / ((double)normal_delay);
1209
1210 torture_comment(tctx, "\nRunning test_delayed_write_update3\n");
1211
1212 torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
1213
1214 torture_comment(tctx, "Open the file handle\n");
1215 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
1216 if (fnum1 == -1) {
1217 ret = false;
1218 torture_result(tctx, TORTURE_FAIL, __location__": unable to open %s", fname);
1219 goto done;
1220 }
1221
1222 finfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
1223 finfo0.basic_info.in.file.fnum = fnum1;
1224 finfo1 = finfo0;
1225 finfo2 = finfo0;
1226 finfo3 = finfo0;
1227 pinfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
1228 pinfo0.basic_info.in.file.path = fname;
1229 pinfo1 = pinfo0;
1230 pinfo2 = pinfo0;
1231 pinfo3 = pinfo0;
1232 pinfo4 = pinfo0;
1233
1234 /* get the initial times */
1235 GET_INFO_BOTH(finfo0,pinfo0);
1236
1237 /* Bypass possible filesystem granularity */
1238 smb_msleep(20);
1239
1240 /*
1241 * make sure the write time is updated immediately
1242 */
1243 start = timeval_current();
1244 end = timeval_add(&start, 4 * sec, 0);
1245 while (!timeval_expired(&end)) {
1246 /* do a write */
1247 torture_comment(tctx, "Do a write on the file handle\n");
1248 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
1249 if (written != 1) {
1250 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
1251 ret = false;
1252 goto done;
1253 }
1254 /* get the times after the write */
1255 GET_INFO_FILE(finfo1);
1256
1257 torture_assert_u64_not_equal(tctx,
1258 finfo1.all_info.out.write_time,
1259 finfo0.all_info.out.write_time,
1260 "Server did not update write time "
1261 "immediately");
1262 finfo0 = finfo1;
1263 /* Bypass possible filesystem granularity */
1264 smb_msleep(20);
1265 }
1266
1267 GET_INFO_BOTH(finfo1,pinfo1);
1268 COMPARE_WRITE_TIME_GREATER(pinfo1, pinfo0);
1269
1270 /* Bypass possible filesystem granularity */
1271 smb_msleep(20);
1272
1273 /* any further write also updates the write time */
1274 start = timeval_current();
1275 end = timeval_add(&start, 4 * sec, 0);
1276 while (!timeval_expired(&end)) {
1277 /* do a write */
1278 torture_comment(tctx, "Do a write on the file handle\n");
1279 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
1280 if (written != 1) {
1281 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
1282 ret = false;
1283 goto done;
1284 }
1285 /* get the times after the write */
1286 GET_INFO_BOTH(finfo2,pinfo2);
1287
1288 torture_assert_u64_not_equal(tctx,
1289 finfo2.all_info.out.write_time,
1290 finfo1.all_info.out.write_time,
1291 "Server did not update write time "
1292 "immediately");
1293 finfo1 = finfo2;
1294 /* Bypass possible filesystem granularity */
1295 smb_msleep(20);
1296 }
1297
1298 GET_INFO_BOTH(finfo3,pinfo3);
1299
1300 torture_assert_u64_equal(tctx,
1301 finfo3.all_info.out.write_time,
1302 finfo2.all_info.out.write_time,
1303 "Server unexpectedly updated write time");
1304
1305 /*
1306 * the close doesn't update the write time
1307 */
1308 torture_comment(tctx, "Close the file handle\n");
1309 smbcli_close(cli->tree, fnum1);
1310 fnum1 = -1;
1311
1312 GET_INFO_PATH(pinfo4);
1313
1314 torture_assert_u64_equal(tctx,
1315 pinfo4.all_info.out.write_time,
1316 pinfo3.all_info.out.write_time,
1317 "Server updated write time "
1318 "on close");
1319
1320 done:
1321 if (fnum1 != -1)
1322 smbcli_close(cli->tree, fnum1);
1323 smbcli_unlink(cli->tree, fname);
1324 smbcli_deltree(cli->tree, BASEDIR);
1325
1326 return ret;
1327 }
1328
1329 /*
1330 * Show that a truncate write always updates the write time even
1331 * if an initial write has already updated the write time.
1332 */
1333
1334 static bool test_delayed_write_update3a(struct torture_context *tctx,
1335 struct smbcli_state *cli,
1336 struct smbcli_state *cli2)
1337 {
1338 union smb_fileinfo finfo0, finfo1, finfo2, finfo3;
1339 union smb_fileinfo pinfo0, pinfo1, pinfo2, pinfo3, pinfo4;
1340 const char *fname = BASEDIR "\\torture_file3a.txt";
1341 int fnum1 = -1;
1342 bool ret = true;
1343 ssize_t written;
1344 int i;
1345 double used_delay = torture_setting_int(tctx, "writetimeupdatedelay", 2000000);
1346 int normal_delay = 2000000;
1347 double sec = ((double)used_delay) / ((double)normal_delay);
1348 int msec = 1000 * sec;
1349
1350 torture_comment(tctx, "\nRunning test_delayed_write_update3a\n");
1351
1352 torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
1353
1354 torture_comment(tctx, "Open the file handle\n");
1355 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
1356 if (fnum1 == -1) {
1357 ret = false;
1358 torture_result(tctx, TORTURE_FAIL, __location__": unable to open %s", fname);
1359 goto done;
1360 }
1361
1362 finfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
1363 finfo0.basic_info.in.file.fnum = fnum1;
1364 finfo1 = finfo0;
1365 finfo2 = finfo0;
1366 finfo3 = finfo0;
1367 pinfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
1368 pinfo0.basic_info.in.file.path = fname;
1369 pinfo1 = pinfo0;
1370 pinfo2 = pinfo0;
1371 pinfo3 = pinfo0;
1372 pinfo4 = pinfo0;
1373
1374 /* get the initial times */
1375 GET_INFO_BOTH(finfo0,pinfo0);
1376
1377 /*
1378 * sleep some time, to demonstrate the handling of write times
1379 * doesn't depend on the time since the open
1380 */
1381 smb_msleep(5 * msec);
1382
1383 /* get the initial times */
1384 GET_INFO_BOTH(finfo1,pinfo1);
1385 COMPARE_WRITE_TIME_EQUAL(finfo1, finfo0);
1386
1387 /*
1388 * make sure the write time is updated immediately
1389 */
1390
1391 /* do a write */
1392 torture_comment(tctx, "Do a write on the file handle\n");
1393 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
1394 if (written != 1) {
1395 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
1396 ret = false;
1397 goto done;
1398 }
1399 /* get the times after the write */
1400 GET_INFO_FILE(finfo1);
1401
1402 torture_assert_u64_not_equal(tctx,
1403 finfo1.all_info.out.write_time,
1404 finfo0.all_info.out.write_time,
1405 "Server did not update write time "
1406 "immediately");
1407
1408 GET_INFO_BOTH(finfo1,pinfo1);
1409 COMPARE_WRITE_TIME_GREATER(pinfo1, pinfo0);
1410
1411 /* Bypass possible filesystem granularity */
1412 smb_msleep(20);
1413
1414 /*
1415 * demonstrate that a truncate write always
1416 * updates the write time immediately
1417 */
1418 for (i=0; i < 3; i++) {
1419 smb_msleep(2 * msec);
1420 /* do a write */
1421 torture_comment(tctx, "Do a truncate SMBwrite [%d] on the file handle\n", i);
1422 written = smbcli_smbwrite(cli->tree, fnum1, "x", 10240, 0);
1423 if (written != 0) {
1424 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 0", (int)written);
1425 ret = false;
1426 goto done;
1427 }
1428 /* get the times after the write */
1429 GET_INFO_BOTH(finfo2,pinfo2);
1430 COMPARE_WRITE_TIME_GREATER(finfo2, finfo1);
1431 finfo1 = finfo2;
1432 }
1433
1434 smb_msleep(3 * msec);
1435
1436 /* Check a further write updates the write time */
1437 torture_comment(tctx, "Do a write on the file handle\n");
1438 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
1439 if (written != 1) {
1440 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
1441 ret = false;
1442 goto done;
1443 }
1444 /* get the times after the write */
1445 GET_INFO_BOTH(finfo2,pinfo2);
1446
1447 torture_assert_u64_not_equal(tctx,
1448 finfo2.all_info.out.write_time,
1449 finfo1.all_info.out.write_time,
1450 "Server did not update write time "
1451 "immediately");
1452
1453 GET_INFO_BOTH(finfo2,pinfo2);
1454
1455 /* sleep */
1456 smb_msleep(3 * msec);
1457
1458 /* get the initial times */
1459 GET_INFO_BOTH(finfo1,pinfo1);
1460 COMPARE_WRITE_TIME_EQUAL(finfo1, finfo2);
1461
1462 /*
1463 * demonstrate that a truncate write always
1464 * updates the write time immediately
1465 */
1466 for (i=0; i < 3; i++) {
1467 smb_msleep(2 * msec);
1468 /* do a write */
1469 torture_comment(tctx, "Do a truncate SMBwrite [%d] on the file handle\n", i);
1470 written = smbcli_smbwrite(cli->tree, fnum1, "x", 512, 0);
1471 if (written != 0) {
1472 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 0", (int)written);
1473 ret = false;
1474 goto done;
1475 }
1476 /* get the times after the write */
1477 GET_INFO_BOTH(finfo2,pinfo2);
1478 COMPARE_WRITE_TIME_GREATER(finfo2, finfo1);
1479 finfo1 = finfo2;
1480 }
1481
1482 /* sleep */
1483 smb_msleep(3 * msec);
1484
1485 GET_INFO_BOTH(finfo3,pinfo3);
1486 COMPARE_WRITE_TIME_EQUAL(finfo3, finfo2);
1487
1488 /*
1489 * the close doesn't update the write time
1490 */
1491 torture_comment(tctx, "Close the file handle\n");
1492 smbcli_close(cli->tree, fnum1);
1493 fnum1 = -1;
1494
1495 GET_INFO_PATH(pinfo4);
1496 COMPARE_WRITE_TIME_EQUAL(pinfo4, pinfo3);
1497
1498 if (pinfo4.basic_info.out.write_time == pinfo3.basic_info.out.write_time) {
1499 torture_comment(tctx, "Server did not update the write_time on close (correct)\n");
1500 }
1501
1502 done:
1503 if (fnum1 != -1)
1504 smbcli_close(cli->tree, fnum1);
1505 smbcli_unlink(cli->tree, fname);
1506 smbcli_deltree(cli->tree, BASEDIR);
1507
1508 return ret;
1509 }
1510
1511 /*
1512 * Show a close after write does not update the write timestamp to
1513 * the close time.
1514 */
1515
1516 static bool test_delayed_write_update3b(struct torture_context *tctx,
1517 struct smbcli_state *cli,
1518 struct smbcli_state *cli2)
1519 {
1520 union smb_fileinfo finfo0, finfo1, finfo2, finfo3;
1521 union smb_fileinfo pinfo0, pinfo1, pinfo2, pinfo3, pinfo4;
1522 const char *fname = BASEDIR "\\torture_file3b.txt";
1523 int fnum1 = -1;
1524 bool ret = true;
1525 ssize_t written;
1526 struct timeval start;
1527 struct timeval end;
1528 double used_delay = torture_setting_int(tctx, "writetimeupdatedelay", 2000000);
1529 int normal_delay = 2000000;
1530 double sec = ((double)used_delay) / ((double)normal_delay);
1531 int msec = 1000 * sec;
1532
1533 torture_comment(tctx, "\nRunning test_delayed_write_update3b\n");
1534
1535 torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
1536
1537 torture_comment(tctx, "Open the file handle\n");
1538 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
1539 if (fnum1 == -1) {
1540 ret = false;
1541 torture_result(tctx, TORTURE_FAIL, __location__": unable to open %s", fname);
1542 goto done;
1543 }
1544
1545 finfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
1546 finfo0.basic_info.in.file.fnum = fnum1;
1547 finfo1 = finfo0;
1548 finfo2 = finfo0;
1549 finfo3 = finfo0;
1550 pinfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
1551 pinfo0.basic_info.in.file.path = fname;
1552 pinfo1 = pinfo0;
1553 pinfo2 = pinfo0;
1554 pinfo3 = pinfo0;
1555 pinfo4 = pinfo0;
1556
1557 /* get the initial times */
1558 GET_INFO_BOTH(finfo0,pinfo0);
1559
1560 /*
1561 * sleep some time, to demonstrate the handling of write times
1562 * doesn't depend on the time since the open
1563 */
1564 smb_msleep(2 * msec);
1565
1566 /* get the initial times */
1567 GET_INFO_BOTH(finfo1,pinfo1);
1568 COMPARE_WRITE_TIME_EQUAL(finfo1, finfo0);
1569
1570 /* do a write */
1571 torture_comment(tctx, "Do a write on the file handle\n");
1572 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
1573 if (written != 1) {
1574 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
1575 ret = false;
1576 goto done;
1577 }
1578 /* get the times after the write */
1579 GET_INFO_BOTH(finfo1,pinfo1);
1580
1581 torture_assert_u64_not_equal(tctx,
1582 finfo1.all_info.out.write_time,
1583 finfo0.all_info.out.write_time,
1584 "Server did not update write time "
1585 "immediately");
1586
1587 torture_assert_u64_not_equal(tctx,
1588 pinfo1.all_info.out.write_time,
1589 finfo0.all_info.out.write_time,
1590 "Server did not update write time "
1591 "immediately");
1592
1593 /* Bypass possible filesystem granularity */
1594 smb_msleep(20);
1595
1596 /* Check further writes also update the write time */
1597 start = timeval_current();
1598 end = timeval_add(&start, 4 * sec, 0);
1599 while (!timeval_expired(&end)) {
1600 /* do a write */
1601 torture_comment(tctx, "Do a write on the file handle\n");
1602 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
1603 if (written != 1) {
1604 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
1605 ret = false;
1606 goto done;
1607 }
1608 /* get the times after the write */
1609 GET_INFO_BOTH(finfo2,pinfo2);
1610
1611 torture_assert_u64_not_equal(tctx,
1612 finfo2.all_info.out.write_time,
1613 finfo1.all_info.out.write_time,
1614 "Server did not update write time "
1615 "immediately");
1616
1617 torture_assert_u64_not_equal(tctx,
1618 pinfo2.all_info.out.write_time,
1619 finfo1.all_info.out.write_time,
1620 "Server did not update write time "
1621 "immediately");
1622
1623 /* Bypass possible filesystem granularity */
1624 smb_msleep(20);
1625 }
1626
1627 /* Bypass possible filesystem granularity */
1628 smb_msleep(20);
1629
1630 GET_INFO_BOTH(finfo3,pinfo3);
1631 COMPARE_WRITE_TIME_EQUAL(finfo3, finfo2);
1632
1633 /*
1634 * the close does not update the write time
1635 */
1636 torture_comment(tctx, "Close the file handle\n");
1637 smbcli_close(cli->tree, fnum1);
1638 fnum1 = -1;
1639
1640 GET_INFO_PATH(pinfo4);
1641
1642 torture_assert_u64_equal(tctx,
1643 pinfo4.all_info.out.write_time,
1644 finfo3.all_info.out.write_time,
1645 "Server updated write time");
1646
1647 done:
1648 if (fnum1 != -1)
1649 smbcli_close(cli->tree, fnum1);
1650 smbcli_unlink(cli->tree, fname);
1651 smbcli_deltree(cli->tree, BASEDIR);
1652
1653 return ret;
1654 }
1655
1656 /*
1657 * Check that a write after a truncate write updates
1658 * the timestamp and a truncate write after a write does.
1659 * Also prove that a close after a truncate write does not update the
1660 * timestamp.
1661 */
1662
1663 static bool test_delayed_write_update3c(struct torture_context *tctx,
1664 struct smbcli_state *cli,
1665 struct smbcli_state *cli2)
1666 {
1667 union smb_fileinfo finfo0, finfo1, finfo2, finfo3;
1668 union smb_fileinfo pinfo0, pinfo1, pinfo2, pinfo3, pinfo4;
1669 const char *fname = BASEDIR "\\torture_file3c.txt";
1670 int fnum1 = -1;
1671 bool ret = true;
1672 ssize_t written;
1673 int i;
1674 struct timeval start;
1675 struct timeval end;
1676 double used_delay = torture_setting_int(tctx, "writetimeupdatedelay", 2000000);
1677 int normal_delay = 2000000;
1678 double sec = ((double)used_delay) / ((double)normal_delay);
1679 int msec = 1000 * sec;
1680
1681 torture_comment(tctx, "\nRunning test_delayed_write_update3c\n");
1682
1683 torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
1684
1685 torture_comment(tctx, "Open the file handle\n");
1686 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
1687 if (fnum1 == -1) {
1688 ret = false;
1689 torture_result(tctx, TORTURE_FAIL, __location__": unable to open %s", fname);
1690 goto done;
1691 }
1692
1693 finfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
1694 finfo0.basic_info.in.file.fnum = fnum1;
1695 finfo1 = finfo0;
1696 finfo2 = finfo0;
1697 finfo3 = finfo0;
1698 pinfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
1699 pinfo0.basic_info.in.file.path = fname;
1700 pinfo1 = pinfo0;
1701 pinfo2 = pinfo0;
1702 pinfo3 = pinfo0;
1703 pinfo4 = pinfo0;
1704
1705 /* get the initial times */
1706 GET_INFO_BOTH(finfo0,pinfo0);
1707
1708 /*
1709 * sleep some time, to demonstrate the handling of write times
1710 * doesn't depend on the time since the open
1711 */
1712 smb_msleep(2 * msec);
1713
1714 /* get the initial times */
1715 GET_INFO_BOTH(finfo1,pinfo1);
1716 COMPARE_WRITE_TIME_EQUAL(finfo1, finfo0);
1717
1718 /*
1719 * demonstrate that a truncate write always
1720 * updates the write time immediately
1721 */
1722 for (i=0; i < 3; i++) {
1723 /* Bypass possible filesystem granularity */
1724 smb_msleep(20);
1725 /* do a write */
1726 torture_comment(tctx, "Do a truncate SMBwrite [%d] on the file handle\n", i);
1727 written = smbcli_smbwrite(cli->tree, fnum1, "x", 512, 0);
1728 if (written != 0) {
1729 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 0", (int)written);
1730 ret = false;
1731 goto done;
1732 }
1733 /* get the times after the write */
1734 GET_INFO_BOTH(finfo2,pinfo2);
1735 COMPARE_WRITE_TIME_GREATER(finfo2, finfo1);
1736 finfo1 = finfo2;
1737 }
1738
1739 /* Bypass possible filesystem granularity */
1740 smb_msleep(20);
1741
1742 start = timeval_current();
1743 end = timeval_add(&start, 7 * sec, 0);
1744 while (!timeval_expired(&end)) {
1745 /* do a write */
1746 torture_comment(tctx, "Do a write on the file handle\n");
1747 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
1748 if (written != 1) {
1749 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
1750 ret = false;
1751 goto done;
1752 }
1753 /* get the times after the write */
1754 GET_INFO_FILE(finfo2);
1755
1756 torture_assert_u64_not_equal(tctx,
1757 finfo2.all_info.out.write_time,
1758 finfo1.all_info.out.write_time,
1759 "Server did not update write time "
1760 "immediately");
1761 /* Bypass possible filesystem granularity */
1762 smb_msleep(20);
1763 }
1764
1765 /* sleep */
1766 smb_msleep(20);
1767
1768 /* get the initial times */
1769 GET_INFO_BOTH(finfo1,pinfo1);
1770 COMPARE_WRITE_TIME_EQUAL(finfo1, finfo2);
1771
1772 /*
1773 * demonstrate that a truncate write always
1774 * updates the write time immediately
1775 */
1776 for (i=0; i < 3; i++) {
1777 smb_msleep(2 * msec);
1778 /* do a write */
1779 torture_comment(tctx, "Do a truncate write [%d] on the file handle\n", i);
1780 written = smbcli_smbwrite(cli->tree, fnum1, "x", 512, 0);
1781 if (written != 0) {
1782 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 0", (int)written);
1783 ret = false;
1784 goto done;
1785 }
1786 /* get the times after the write */
1787 GET_INFO_BOTH(finfo2,pinfo2);
1788 COMPARE_WRITE_TIME_GREATER(finfo2, finfo1);
1789 finfo1 = finfo2;
1790 }
1791
1792 /* Bypass possible filesystem granularity */
1793 smb_msleep(20);
1794
1795 GET_INFO_BOTH(finfo2,pinfo2);
1796 COMPARE_WRITE_TIME_EQUAL(finfo2, finfo1);
1797
1798 /* check further writes also update the write time */
1799 start = timeval_current();
1800 end = timeval_add(&start, 4 * sec, 0);
1801 while (!timeval_expired(&end)) {
1802 /* do a write */
1803 torture_comment(tctx, "Do a write on the file handle\n");
1804 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
1805 if (written != 1) {
1806 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
1807 ret = false;
1808 goto done;
1809 }
1810 /* get the times after the write */
1811 GET_INFO_BOTH(finfo2,pinfo2);
1812
1813 torture_assert_u64_not_equal(tctx,
1814 finfo2.all_info.out.write_time,
1815 finfo1.all_info.out.write_time,
1816 "Server did not update write time "
1817 "immediately");
1818 smb_msleep(20);
1819 }
1820
1821 /* Bypass possible filesystem granularity */
1822 smb_msleep(20);
1823
1824 GET_INFO_BOTH(finfo3,pinfo3);
1825 COMPARE_WRITE_TIME_EQUAL(finfo3, finfo2);
1826
1827 /*
1828 * the close must not update the write time
1829 */
1830 torture_comment(tctx, "Close the file handle\n");
1831 smbcli_close(cli->tree, fnum1);
1832 fnum1 = -1;
1833
1834 GET_INFO_PATH(pinfo4);
1835
1836 torture_assert_u64_equal(tctx,
1837 pinfo4.all_info.out.write_time,
1838 finfo3.all_info.out.write_time,
1839 "Server did not update write time "
1840 "immediately");
1841
1842 done:
1843 if (fnum1 != -1)
1844 smbcli_close(cli->tree, fnum1);
1845 smbcli_unlink(cli->tree, fname);
1846 smbcli_deltree(cli->tree, BASEDIR);
1847
1848 return ret;
1849 }
1850
1851 /*
1852 * Show only the first write updates the timestamp, and a close
1853 * after writes updates to current (I think this is the same
1854 * as test 3b. JRA).
1855 */
1856
1857 static bool test_delayed_write_update4(struct torture_context *tctx,
1858 struct smbcli_state *cli,
1859 struct smbcli_state *cli2)
1860 {
1861 union smb_fileinfo finfo0, finfo1, finfo2, finfo3;
1862 union smb_fileinfo pinfo0, pinfo1, pinfo2, pinfo3, pinfo4;
1863 const char *fname = BASEDIR "\\torture_file4.txt";
1864 int fnum1 = -1;
1865 bool ret = true;
1866 ssize_t written;
1867 struct timeval start;
1868 struct timeval end;
1869 double used_delay = torture_setting_int(tctx, "writetimeupdatedelay", 2000000);
1870 int normal_delay = 2000000;
1871 double sec = ((double)used_delay) / ((double)normal_delay);
1872
1873 torture_comment(tctx, "\nRunning test_delayed_write_update4\n");
1874
1875 torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
1876
1877 torture_comment(tctx, "Open the file handle\n");
1878 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
1879 if (fnum1 == -1) {
1880 ret = false;
1881 torture_result(tctx, TORTURE_FAIL, __location__": unable to open %s", fname);
1882 goto done;
1883 }
1884
1885 finfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
1886 finfo0.basic_info.in.file.fnum = fnum1;
1887 finfo1 = finfo0;
1888 finfo2 = finfo0;
1889 finfo3 = finfo0;
1890 pinfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
1891 pinfo0.basic_info.in.file.path = fname;
1892 pinfo1 = pinfo0;
1893 pinfo2 = pinfo0;
1894 pinfo3 = pinfo0;
1895 pinfo4 = pinfo0;
1896
1897 /* get the initial times */
1898 GET_INFO_BOTH(finfo0,pinfo0);
1899
1900 /* Bypass possible filesystem granularity */
1901 smb_msleep(20);
1902
1903 /* do a write */
1904 torture_comment(tctx, "Do a write on the file handle\n");
1905 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
1906 if (written != 1) {
1907 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
1908 ret = false;
1909 goto done;
1910 }
1911
1912 GET_INFO_BOTH(finfo1,pinfo1);
1913
1914 torture_assert_u64_not_equal(tctx,
1915 finfo1.all_info.out.write_time,
1916 finfo0.all_info.out.write_time,
1917 "Server did not update write time "
1918 "immediately");
1919
1920
1921 /* Bypass possible filesystem granularity */
1922 smb_msleep(20);
1923
1924 /* Check further writes also update the write time */
1925 start = timeval_current();
1926 end = timeval_add(&start, 4 * sec, 0);
1927 while (!timeval_expired(&end)) {
1928 /* do a write */
1929 torture_comment(tctx, "Do a write on the file handle\n");
1930 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
1931 if (written != 1) {
1932 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
1933 ret = false;
1934 goto done;
1935 }
1936 /* get the times after the write */
1937 GET_INFO_BOTH(finfo2,pinfo2);
1938
1939 torture_assert_u64_not_equal(tctx,
1940 finfo2.all_info.out.write_time,
1941 finfo1.all_info.out.write_time,
1942 "Server did not update write time "
1943 "immediately");
1944
1945 /* Bypass possible filesystem granularity */
1946 smb_msleep(20);
1947 }
1948
1949 /* Bypass possible filesystem granularity */
1950 smb_msleep(20);
1951
1952 GET_INFO_BOTH(finfo3,pinfo3);
1953 COMPARE_WRITE_TIME_EQUAL(finfo3, finfo2);
1954
1955 /*
1956 * check the close does not update the write time
1957 */
1958 torture_comment(tctx, "Close the file handle\n");
1959 smbcli_close(cli->tree, fnum1);
1960 fnum1 = -1;
1961
1962 GET_INFO_PATH(pinfo4);
1963
1964 torture_assert_u64_equal(tctx,
1965 pinfo4.all_info.out.write_time,
1966 finfo3.all_info.out.write_time,
1967 "Server did not update write time "
1968 "immediately");
1969
1970 done:
1971 if (fnum1 != -1)
1972 smbcli_close(cli->tree, fnum1);
1973 smbcli_unlink(cli->tree, fname);
1974 smbcli_deltree(cli->tree, BASEDIR);
1975
1976 return ret;
1977 }
1978
1979 /*
1980 * Show writes and closes have no effect on updating times once a SETWRITETIME is done.
1981 */
1982
1983 static bool test_delayed_write_update5(struct torture_context *tctx,
1984 struct smbcli_state *cli,
1985 struct smbcli_state *cli2)
1986 {
1987 union smb_fileinfo finfo0, finfo1, finfo2, finfo3, finfo4, finfo5;
1988 union smb_fileinfo pinfo0, pinfo1, pinfo2, pinfo3, pinfo4, pinfo5, pinfo6;
1989 const char *fname = BASEDIR "\\torture_file5.txt";
1990 int fnum1 = -1;
1991 bool ret = true;
1992 ssize_t written;
1993 struct timeval start;
1994 struct timeval end;
1995 double used_delay = torture_setting_int(tctx, "writetimeupdatedelay", 2000000);
1996 int normal_delay = 2000000;
1997 double sec = ((double)used_delay) / ((double)normal_delay);
1998 int msec = 1000 * sec;
1999
2000 torture_comment(tctx, "\nRunning test_delayed_write_update5\n");
2001
2002 torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
2003
2004 torture_comment(tctx, "Open the file handle\n");
2005 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
2006 if (fnum1 == -1) {
2007 ret = false;
2008 torture_result(tctx, TORTURE_FAIL, __location__": unable to open %s", fname);
2009 goto done;
2010 }
2011
2012 finfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
2013 finfo0.basic_info.in.file.fnum = fnum1;
2014 finfo1 = finfo0;
2015 finfo2 = finfo0;
2016 finfo3 = finfo0;
2017 finfo4 = finfo0;
2018 finfo5 = finfo0;
2019 pinfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
2020 pinfo0.basic_info.in.file.path = fname;
2021 pinfo1 = pinfo0;
2022 pinfo2 = pinfo0;
2023 pinfo3 = pinfo0;
2024 pinfo4 = pinfo0;
2025 pinfo5 = pinfo0;
2026 pinfo6 = pinfo0;
2027
2028 /* get the initial times */
2029 GET_INFO_BOTH(finfo0,pinfo0);
2030
2031 /* do a write */
2032 torture_comment(tctx, "Do a write on the file handle\n");
2033 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
2034 if (written != 1) {
2035 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
2036 ret = false;
2037 goto done;
2038 }
2039
2040 GET_INFO_BOTH(finfo1,pinfo1);
2041
2042 torture_assert_u64_not_equal(tctx,
2043 finfo1.all_info.out.write_time,
2044 finfo0.all_info.out.write_time,
2045 "Server did not update write time "
2046 "immediately");
2047
2048 torture_comment(tctx, "Set write time in the future on the file handle\n");
2049 SET_INFO_FILE(finfo0, time(NULL) + 86400);
2050 GET_INFO_BOTH(finfo2,pinfo2);
2051 COMPARE_WRITE_TIME_GREATER(finfo2, finfo1);
2052
2053 torture_comment(tctx, "Set write time in the past on the file handle\n");
2054 SET_INFO_FILE(finfo0, time(NULL) - 86400);
2055 GET_INFO_BOTH(finfo2,pinfo2);
2056 COMPARE_WRITE_TIME_LESS(finfo2, finfo1);
2057
2058 /* make sure there's no delayed update happening */
2059 start = timeval_current();
2060 end = timeval_add(&start, 4 * sec, 0);
2061 while (!timeval_expired(&end)) {
2062
2063 /* get the times after the first write */
2064 GET_INFO_BOTH(finfo3,pinfo3);
2065
2066 if (finfo3.basic_info.out.write_time > finfo2.basic_info.out.write_time) {
2067 double diff = timeval_elapsed(&start);
2068 torture_result(tctx, TORTURE_FAIL, "Server updated write_time after %.2f seconds "
2069 "(wrong!)\n",
2070 diff);
2071 return false;
2072 }
2073 smb_msleep(1 * msec);
2074 }
2075
2076 /* sure any further write doesn't update the write time */
2077 start = timeval_current();
2078 end = timeval_add(&start, 4 * sec, 0);
2079 while (!timeval_expired(&end)) {
2080 /* do a write */
2081 torture_comment(tctx, "Do a write on the file handle\n");
2082 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
2083 if (written != 1) {
2084 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
2085 ret = false;
2086 goto done;
2087 }
2088 /* get the times after the write */
2089 GET_INFO_BOTH(finfo4,pinfo4);
2090
2091 torture_assert_u64_equal(tctx,
2092 finfo4.all_info.out.write_time,
2093 finfo3.all_info.out.write_time,
2094 "Server did not honor sticky write time");
2095 smb_msleep(1 * msec);
2096 }
2097
2098 /* Bypass possible filesystem granularity */
2099 smb_msleep(20);
2100
2101 GET_INFO_BOTH(finfo5,pinfo5);
2102 COMPARE_WRITE_TIME_EQUAL(finfo5, finfo4);
2103
2104 /*
2105 * the close doesn't update the write time
2106 */
2107 torture_comment(tctx, "Close the file handle\n");
2108 smbcli_close(cli->tree, fnum1);
2109 fnum1 = -1;
2110
2111 GET_INFO_PATH(pinfo6);
2112
2113 torture_assert_u64_equal(tctx,
2114 pinfo6.all_info.out.write_time,
2115 finfo5.all_info.out.write_time,
2116 "Server update writed time when closing");
2117
2118 done:
2119 if (fnum1 != -1)
2120 smbcli_close(cli->tree, fnum1);
2121 smbcli_unlink(cli->tree, fname);
2122 smbcli_deltree(cli->tree, BASEDIR);
2123
2124 return ret;
2125 }
2126
2127 /*
2128 * Show truncate writes and closes have no effect on updating times once a SETWRITETIME is done.
2129 */
2130
2131 static bool test_delayed_write_update5b(struct torture_context *tctx,
2132 struct smbcli_state *cli,
2133 struct smbcli_state *cli2)
2134 {
2135 union smb_fileinfo finfo0, finfo1, finfo2, finfo3, finfo4, finfo5;
2136 union smb_fileinfo pinfo0, pinfo1, pinfo2, pinfo3, pinfo4, pinfo5, pinfo6;
2137 const char *fname = BASEDIR "\\torture_fileb.txt";
2138 int fnum1 = -1;
2139 bool ret = true;
2140 ssize_t written;
2141 struct timeval start;
2142 struct timeval end;
2143 double used_delay = torture_setting_int(tctx, "writetimeupdatedelay", 2000000);
2144 int normal_delay = 2000000;
2145 double sec = ((double)used_delay) / ((double)normal_delay);
2146 int msec = 1000 * sec;
2147
2148 torture_comment(tctx, "\nRunning test_delayed_write_update5b\n");
2149
2150 torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
2151
2152 torture_comment(tctx, "Open the file handle\n");
2153 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
2154 if (fnum1 == -1) {
2155 ret = false;
2156 torture_result(tctx, TORTURE_FAIL, __location__": unable to open %s", fname);
2157 goto done;
2158 }
2159
2160 finfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
2161 finfo0.basic_info.in.file.fnum = fnum1;
2162 finfo1 = finfo0;
2163 finfo2 = finfo0;
2164 finfo3 = finfo0;
2165 finfo4 = finfo0;
2166 finfo5 = finfo0;
2167 pinfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
2168 pinfo0.basic_info.in.file.path = fname;
2169 pinfo1 = pinfo0;
2170 pinfo2 = pinfo0;
2171 pinfo3 = pinfo0;
2172 pinfo4 = pinfo0;
2173 pinfo5 = pinfo0;
2174 pinfo6 = pinfo0;
2175
2176 /* get the initial times */
2177 GET_INFO_BOTH(finfo0,pinfo0);
2178
2179 /* do a write */
2180 torture_comment(tctx, "Do a write on the file handle\n");
2181 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
2182 if (written != 1) {
2183 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
2184 ret = false;
2185 goto done;
2186 }
2187
2188 GET_INFO_BOTH(finfo1,pinfo1);
2189 COMPARE_WRITE_TIME_EQUAL(finfo1, finfo0);
2190
2191 torture_comment(tctx, "Set write time in the future on the file handle\n");
2192 SET_INFO_FILE(finfo0, time(NULL) + 86400);
2193 GET_INFO_BOTH(finfo2,pinfo2);
2194 COMPARE_WRITE_TIME_GREATER(finfo2, finfo1);
2195
2196 torture_comment(tctx, "Set write time in the past on the file handle\n");
2197 SET_INFO_FILE(finfo0, time(NULL) - 86400);
2198 GET_INFO_BOTH(finfo2,pinfo2);
2199 COMPARE_WRITE_TIME_LESS(finfo2, finfo1);
2200
2201 /* make sure there's no delayed update pending */
2202 start = timeval_current();
2203 end = timeval_add(&start, 4 * sec, 0);
2204 while (!timeval_expired(&end)) {
2205
2206 /* get the times after the first write */
2207 GET_INFO_BOTH(finfo3,pinfo3);
2208
2209 if (finfo3.basic_info.out.write_time > finfo2.basic_info.out.write_time) {
2210 double diff = timeval_elapsed(&start);
2211 torture_result(tctx, TORTURE_FAIL, "Server updated write_time after %.2f seconds "
2212 "(wrong!)\n",
2213 diff);
2214 ret = false;
2215 break;
2216 }
2217 smb_msleep(1 * msec);
2218 }
2219
2220 GET_INFO_BOTH(finfo3,pinfo3);
2221 COMPARE_WRITE_TIME_EQUAL(finfo3, finfo2);
2222 if (finfo3.basic_info.out.write_time == finfo2.basic_info.out.write_time) {
2223 torture_comment(tctx, "Server did not update write_time (correct)\n");
2224 }
2225
2226 /* Do any further write (truncates) update the write time ? */
2227 start = timeval_current();
2228 end = timeval_add(&start, 4 * sec, 0);
2229 while (!timeval_expired(&end)) {
2230 /* do a write */
2231 torture_comment(tctx, "Do a truncate write on the file handle\n");
2232 written = smbcli_smbwrite(cli->tree, fnum1, "x", 1024, 0);
2233 if (written != 0) {
2234 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
2235 ret = false;
2236 goto done;
2237 }
2238 /* get the times after the write */
2239 GET_INFO_BOTH(finfo4,pinfo4);
2240
2241 if (finfo4.basic_info.out.write_time > finfo3.basic_info.out.write_time) {
2242 double diff = timeval_elapsed(&start);
2243 torture_result(tctx, TORTURE_FAIL, "Server updated write_time after %.2f seconds "
2244 "(wrong!)\n",
2245 diff);
2246 ret = false;
2247 break;
2248 }
2249 smb_msleep(1 * msec);
2250 }
2251
2252 GET_INFO_BOTH(finfo4,pinfo4);
2253 COMPARE_WRITE_TIME_EQUAL(finfo4, finfo3);
2254 if (finfo4.basic_info.out.write_time == finfo3.basic_info.out.write_time) {
2255 torture_comment(tctx, "Server did not update write_time (correct)\n");
2256 }
2257
2258 /* sleep */
2259 smb_msleep(5 * msec);
2260
2261 GET_INFO_BOTH(finfo5,pinfo5);
2262 COMPARE_WRITE_TIME_EQUAL(finfo5, finfo4);
2263
2264 /*
2265 * the close doesn't update the write time
2266 */
2267 torture_comment(tctx, "Close the file handle\n");
2268 smbcli_close(cli->tree, fnum1);
2269 fnum1 = -1;
2270
2271 GET_INFO_PATH(pinfo6);
2272 COMPARE_WRITE_TIME_EQUAL(pinfo6, pinfo5);
2273
2274 if (pinfo6.basic_info.out.write_time == pinfo5.basic_info.out.write_time) {
2275 torture_comment(tctx, "Server did not update the write_time on close (correct)\n");
2276 }
2277
2278 done:
2279 if (fnum1 != -1)
2280 smbcli_close(cli->tree, fnum1);
2281 smbcli_unlink(cli->tree, fname);
2282 smbcli_deltree(cli->tree, BASEDIR);
2283
2284 return ret;
2285 }
2286
2287 /*
2288 * Open 2 handles on a file. Write one one and then set the
2289 * WRITE TIME explicitly on the other. Ensure there's no delayed write time
2290 * update. Ensure the write time is not updated to
2291 * the close time when the non-explicit set handle is closed.
2292 *
2293 */
2294
2295 static bool test_delayed_write_update6(struct torture_context *tctx,
2296 struct smbcli_state *cli,
2297 struct smbcli_state *cli2)
2298 {
2299 union smb_fileinfo finfo0, finfo1, finfo2, finfo3, finfo4, finfo5;
2300 union smb_fileinfo pinfo0, pinfo1, pinfo2, pinfo3, pinfo4, pinfo5, pinfo6, pinfo7;
2301 const char *fname = BASEDIR "\\torture_file6.txt";
2302 int fnum1 = -1;
2303 int fnum2 = -1;
2304 bool ret = true;
2305 ssize_t written;
2306 struct timeval start;
2307 struct timeval end;
2308 double used_delay = torture_setting_int(tctx, "writetimeupdatedelay", 2000000);
2309 int normal_delay = 2000000;
2310 double sec = ((double)used_delay) / ((double)normal_delay);
2311 int msec = 1000 * sec;
2312 bool first = true;
2313
2314 torture_comment(tctx, "\nRunning test_delayed_write_update6\n");
2315
2316 torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
2317 again:
2318 torture_comment(tctx, "Open the file handle\n");
2319 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
2320 if (fnum1 == -1) {
2321 ret = false;
2322 torture_result(tctx, TORTURE_FAIL, __location__": unable to open %s", fname);
2323 goto done;
2324 }
2325
2326 if (fnum2 == -1) {
2327 torture_comment(tctx, "Open the 2nd file handle on 2nd connection\n");
2328 fnum2 = smbcli_open(cli2->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
2329 if (fnum2 == -1) {
2330 ret = false;
2331 torture_result(tctx, TORTURE_FAIL, __location__": unable to open %s", fname);
2332 goto done;
2333 }
2334 }
2335
2336 finfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
2337 finfo0.basic_info.in.file.fnum = fnum1;
2338 finfo1 = finfo0;
2339 finfo2 = finfo0;
2340 finfo3 = finfo0;
2341 finfo4 = finfo0;
2342 finfo5 = finfo0;
2343 pinfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
2344 pinfo0.basic_info.in.file.path = fname;
2345 pinfo1 = pinfo0;
2346 pinfo2 = pinfo0;
2347 pinfo3 = pinfo0;
2348 pinfo4 = pinfo0;
2349 pinfo5 = pinfo0;
2350 pinfo6 = pinfo0;
2351 pinfo7 = pinfo0;
2352
2353 /* get the initial times */
2354 GET_INFO_BOTH(finfo0,pinfo0);
2355
2356 /* do a write */
2357 torture_comment(tctx, "Do a write on the file handle\n");
2358 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
2359 if (written != 1) {
2360 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
2361 ret = false;
2362 goto done;
2363 }
2364
2365 GET_INFO_BOTH(finfo1,pinfo1);
2366
2367 torture_assert_u64_not_equal(tctx,
2368 finfo1.all_info.out.write_time,
2369 finfo0.all_info.out.write_time,
2370 "Server did not update write time "
2371 "immediately");
2372
2373 torture_comment(tctx, "Set write time in the future on the 2nd file handle\n");
2374 SET_INFO_FILE_EX(finfo0, time(NULL) + 86400, cli2->tree, fnum2);
2375 GET_INFO_BOTH(finfo2,pinfo2);
2376 COMPARE_WRITE_TIME_GREATER(finfo2, finfo1);
2377
2378 torture_comment(tctx, "Set write time in the past on the 2nd file handle\n");
2379 SET_INFO_FILE_EX(finfo0, time(NULL) - 86400, cli2->tree, fnum2);
2380 GET_INFO_BOTH(finfo2,pinfo2);
2381 COMPARE_WRITE_TIME_LESS(finfo2, finfo1);
2382
2383 /* check there's no delayed update */
2384 start = timeval_current();
2385 end = timeval_add(&start, 4 * sec, 0);
2386 while (!timeval_expired(&end)) {
2387
2388 /* get the times after the first write */
2389 GET_INFO_BOTH(finfo3,pinfo3);
2390
2391 torture_assert_u64_equal(tctx,
2392 finfo3.all_info.out.write_time,
2393 finfo2.all_info.out.write_time,
2394 "Server delayed a write time "
2395 "update");
2396
2397 smb_msleep(20);
2398 }
2399
2400 GET_INFO_BOTH(finfo3,pinfo3);
2401 COMPARE_WRITE_TIME_EQUAL(finfo3, finfo2);
2402
2403 torture_assert_u64_equal(tctx,
2404 finfo3.all_info.out.write_time,
2405 finfo2.all_info.out.write_time,
2406 "Server did not update write time "
2407 "immediately");
2408
2409 /* sure any further write doesn't update the write time */
2410 start = timeval_current();
2411 end = timeval_add(&start, 10 * sec, 0);
2412 while (!timeval_expired(&end)) {
2413 /* do a write */
2414 torture_comment(tctx, "Do a write on the file handle\n");
2415 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
2416 if (written != 1) {
2417 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
2418 ret = false;
2419 goto done;
2420 }
2421 /* get the times after the write */
2422 GET_INFO_BOTH(finfo4,pinfo4);
2423
2424 torture_assert_u64_not_equal(tctx,
2425 finfo4.all_info.out.write_time,
2426 finfo3.all_info.out.write_time,
2427 "Server did not update write time "
2428 "immediately");
2429
2430 smb_msleep(20);
2431 }
2432
2433 GET_INFO_BOTH(finfo4,pinfo4);
2434
2435 torture_assert_u64_not_equal(tctx,
2436 finfo4.all_info.out.write_time,
2437 finfo3.all_info.out.write_time,
2438 "Server did not update write time "
2439 "immediately");
2440
2441 /* Bypass possible filesystem granularity */
2442 smb_msleep(20);
2443
2444 GET_INFO_BOTH(finfo5,pinfo5);
2445
2446 torture_assert_u64_equal(tctx,
2447 finfo5.all_info.out.write_time,
2448 finfo4.all_info.out.write_time,
2449 "Server update write time");
2450
2451 /*
2452 * the close doesn't update the write time
2453 */
2454 torture_comment(tctx, "Close the file handle\n");
2455 smbcli_close(cli->tree, fnum1);
2456 fnum1 = -1;
2457
2458 GET_INFO_PATH(pinfo6);
2459
2460 torture_assert_u64_equal(tctx,
2461 pinfo6.all_info.out.write_time,
2462 finfo5.all_info.out.write_time,
2463 "Server update write time on close");
2464
2465 /* See what the second write handle thinks the time is ? */
2466 finfo5.basic_info.in.file.fnum = fnum2;
2467 GET_INFO_FILE2(finfo5);
2468
2469 torture_assert_u64_equal(tctx,
2470 pinfo6.all_info.out.write_time,
2471 finfo5.all_info.out.write_time,
2472 "Server updated write time");
2473
2474 /* See if we have lost the sticky write time on handle2 */
2475 smb_msleep(3 * msec);
2476 torture_comment(tctx, "Have we lost the sticky write time ?\n");
2477
2478 /* Make sure any further normal write doesn't update the write time */
2479 start = timeval_current();
2480 end = timeval_add(&start, 4 * sec, 0);
2481 while (!timeval_expired(&end)) {
2482 /* do a write */
2483 torture_comment(tctx, "Do a write on the second file handle\n");
2484 written = smbcli_write(cli2->tree, fnum2, 0, "x", 0, 1);
2485 if (written != 1) {
2486 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
2487 ret = false;
2488 goto done;
2489 }
2490 /* get the times after the write */
2491 GET_INFO_FILE2(finfo5);
2492 GET_INFO_PATH(pinfo6);
2493
2494 torture_assert_u64_equal(tctx,
2495 pinfo6.all_info.out.write_time,
2496 finfo5.all_info.out.write_time,
2497 "Server updated write time");
2498
2499 smb_msleep(1 * msec);
2500 }
2501
2502 /* What about a truncate write ? */
2503 start = timeval_current();
2504 end = timeval_add(&start, 4 * sec, 0);
2505 while (!timeval_expired(&end)) {
2506 /* do a write */
2507 torture_comment(tctx, "Do a truncate write on the second file handle\n");
2508 written = smbcli_write(cli2->tree, fnum2, 0, "x", 0, 0);
2509 if (written != 0) {
2510 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
2511 ret = false;
2512 goto done;
2513 }
2514 /* get the times after the write */
2515 GET_INFO_FILE2(finfo5);
2516 GET_INFO_PATH(pinfo6);
2517
2518 torture_assert_u64_equal(tctx,
2519 pinfo6.all_info.out.write_time,
2520 finfo5.all_info.out.write_time,
2521 "Server updated write time");
2522 smb_msleep(1 * msec);
2523 }
2524
2525
2526 /* keep the 2nd handle open and rerun tests */
2527 if (first) {
2528 first = false;
2529 goto again;
2530 }
2531
2532 /*
2533 * closing the 2nd handle will cause no write time update
2534 * as the write time was explicit set on this handle
2535 */
2536 torture_comment(tctx, "Close the 2nd file handle\n");
2537 smbcli_close(cli2->tree, fnum2);
2538 fnum2 = -1;
2539
2540 GET_INFO_PATH(pinfo7);
2541
2542 torture_assert_u64_equal(tctx,
2543 pinfo7.all_info.out.write_time,
2544 pinfo6.all_info.out.write_time,
2545 "Server updated write time");
2546
2547 done:
2548 if (fnum1 != -1)
2549 smbcli_close(cli->tree, fnum1);
2550 if (fnum2 != -1)
2551 smbcli_close(cli2->tree, fnum2);
2552 smbcli_unlink(cli->tree, fname);
2553 smbcli_deltree(cli->tree, BASEDIR);
2554
2555 return ret;
2556 }
2557
2558 static bool test_delayed_write_update7(struct torture_context *tctx, struct smbcli_state *cli)
2559 {
2560 union smb_open open_parms;
2561 union smb_fileinfo finfo1, finfo2, finfo3;
2562 const char *fname = BASEDIR "\\torture_file7.txt";
2563 NTSTATUS status;
2564 int fnum1 = -1;
2565 bool ret = true;
2566 TALLOC_CTX *mem_ctx;
2567
2568 torture_comment(tctx, "\nRunning test_delayed_write_update7 (timestamp resolution test)\n");
2569
2570 mem_ctx = talloc_init("test_delayed_write_update7");
2571 if (!mem_ctx) return false;
2572
2573 ZERO_STRUCT(finfo1);
2574 ZERO_STRUCT(finfo2);
2575 ZERO_STRUCT(finfo3);
2576 ZERO_STRUCT(open_parms);
2577
2578 torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
2579
2580 /* Create the file. */
2581 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
2582 if (fnum1 == -1) {
2583 torture_result(tctx, TORTURE_FAIL, "Failed to open %s", fname);
2584 return false;
2585 }
2586
2587 finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO;
2588 finfo1.basic_info.in.file.fnum = fnum1;
2589 finfo2 = finfo1;
2590 finfo3 = finfo1;
2591
2592 /* Get the initial timestamps. */
2593 status = smb_raw_fileinfo(cli->tree, tctx, &finfo1);
2594
2595 torture_assert_ntstatus_ok(tctx, status, "fileinfo failed");
2596
2597 /* Set the pending write time to a value with non zero msec. */
2598 SET_INFO_FILE_NS(finfo1, time(NULL) + 86400, 103 * NTTIME_MSEC,
2599 cli->tree, fnum1);
2600
2601 /* Get the current pending write time by fnum. */
2602 status = smb_raw_fileinfo(cli->tree, tctx, &finfo2);
2603
2604 torture_assert_ntstatus_ok(tctx, status, "fileinfo failed");
2605
2606 /* Ensure the time is actually different. */
2607 if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) {
2608 torture_result(tctx, TORTURE_FAIL,
2609 "setfileinfo time matches original fileinfo time");
2610 ret = false;
2611 }
2612
2613 /* Get the current pending write time by path. */
2614 finfo3.basic_info.in.file.path = fname;
2615 status = smb_raw_pathinfo(cli->tree, tctx, &finfo3);
2616
2617 if (finfo2.basic_info.out.write_time != finfo3.basic_info.out.write_time) {
2618 torture_result(tctx, TORTURE_FAIL,
2619 "qpathinfo time doesn't match fileinfo time");
2620 ret = false;
2621 }
2622
2623 /* Now close the file. Re-open and check that the write
2624 time is identical to the one we wrote. */
2625
2626 smbcli_close(cli->tree, fnum1);
2627
2628 open_parms.ntcreatex.level = RAW_OPEN_NTCREATEX;
2629 open_parms.ntcreatex.in.flags = 0;
2630 open_parms.ntcreatex.in.access_mask = SEC_GENERIC_READ;
2631 open_parms.ntcreatex.in.file_attr = 0;
2632 open_parms.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_DELETE|
2633 NTCREATEX_SHARE_ACCESS_READ|
2634 NTCREATEX_SHARE_ACCESS_WRITE;
2635 open_parms.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
2636 open_parms.ntcreatex.in.create_options = 0;
2637 open_parms.ntcreatex.in.fname = fname;
2638
2639 status = smb_raw_open(cli->tree, mem_ctx, &open_parms);
2640 talloc_free(mem_ctx);
2641
2642 if (!NT_STATUS_IS_OK(status)) {
2643 torture_result(tctx, TORTURE_FAIL,
2644 "setfileinfo time matches original fileinfo time");
2645 ret = false;
2646 }
2647
2648 fnum1 = open_parms.ntcreatex.out.file.fnum;
2649
2650 /* Check the returned time matches. */
2651 if (open_parms.ntcreatex.out.write_time != finfo2.basic_info.out.write_time) {
2652 torture_result(tctx, TORTURE_FAIL,
2653 "final open time does not match set time");
2654 ret = false;
2655 }
2656
2657 done:
2658
2659 smbcli_close(cli->tree, fnum1);
2660
2661 smbcli_unlink(cli->tree, fname);
2662 smbcli_deltree(cli->tree, BASEDIR);
2663 return ret;
2664 }
2665
2666 /*
2667 Test if creating a file in a directory with an open handle updates the
2668 write timestamp (it should).
2669 */
2670 static bool test_directory_update8(struct torture_context *tctx, struct smbcli_state *cli)
2671 {
2672 union smb_fileinfo dir_info1, dir_info2;
2673 union smb_open open_parms;
2674 const char *fname = BASEDIR "\\torture_file.txt";
2675 NTSTATUS status;
2676 int fnum1 = -1;
2677 int fnum2 = -1;
2678 bool ret = true;
2679 double used_delay = torture_setting_int(tctx, "writetimeupdatedelay", 2000000);
2680 int normal_delay = 2000000;
2681 double sec = ((double)used_delay) / ((double)normal_delay);
2682 int msec = 1000 * sec;
2683 TALLOC_CTX *mem_ctx = talloc_init("test_delayed_write_update8");
2684
2685 if (!mem_ctx) return false;
2686
2687 torture_comment(tctx, "\nRunning test directory write update\n");
2688
2689 torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
2690
2691 /* Open a handle on the directory - and leave it open. */
2692 ZERO_STRUCT(open_parms);
2693 open_parms.ntcreatex.level = RAW_OPEN_NTCREATEX;
2694 open_parms.ntcreatex.in.flags = 0;
2695 open_parms.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_READ;
2696 open_parms.ntcreatex.in.file_attr = 0;
2697 open_parms.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_DELETE|
2698 NTCREATEX_SHARE_ACCESS_READ|
2699 NTCREATEX_SHARE_ACCESS_WRITE;
2700 open_parms.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
2701 open_parms.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
2702 open_parms.ntcreatex.in.fname = BASEDIR;
2703
2704 status = smb_raw_open(cli->tree, mem_ctx, &open_parms);
2705 talloc_free(mem_ctx);
2706
2707 if (!NT_STATUS_IS_OK(status)) {
2708 torture_result(tctx, TORTURE_FAIL,
2709 "failed to open directory handle");
2710 ret = false;
2711 goto done;
2712 }
2713
2714 fnum1 = open_parms.ntcreatex.out.file.fnum;
2715
2716 /* Store the returned write time. */
2717 ZERO_STRUCT(dir_info1);
2718 dir_info1.basic_info.out.write_time = open_parms.ntcreatex.out.write_time;
2719
2720 torture_comment(tctx, "Initial write time %s\n",
2721 nt_time_string(tctx, dir_info1.basic_info.out.write_time));
2722
2723 /* sleep */
2724 smb_msleep(3 * msec);
2725
2726 /* Now create a file within the directory. */
2727 fnum2 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
2728 if (fnum2 == -1) {
2729 torture_result(tctx, TORTURE_FAIL, "Failed to open %s", fname);
2730 ret = false;
2731 goto done;
2732 }
2733 smbcli_close(cli->tree, fnum2);
2734
2735 /* Read the directory write time again. */
2736 ZERO_STRUCT(dir_info2);
2737 dir_info2.basic_info.level = RAW_FILEINFO_BASIC_INFO;
2738 dir_info2.basic_info.in.file.fnum = fnum1;
2739
2740 status = smb_raw_fileinfo(cli->tree, tctx, &dir_info2);
2741
2742 torture_assert_ntstatus_ok(tctx, status, "fileinfo failed");
2743
2744 /* Ensure it's been incremented. */
2745 COMPARE_WRITE_TIME_GREATER(dir_info2, dir_info1);
2746
2747 torture_comment(tctx, "Updated write time %s\n",
2748 nt_time_string(tctx, dir_info2.basic_info.out.write_time));
2749
2750 done:
2751
2752 if (fnum1 != -1)
2753 smbcli_close(cli->tree, fnum1);
2754 smbcli_unlink(cli->tree, fname);
2755 smbcli_deltree(cli->tree, BASEDIR);
2756
2757 return ret;
2758 }
2759
2760 /*
2761 * | Time | Handle 1 | Handle 2 |
2762 * |------+------------------------+------------------------|
2763 * | 1 | Create file | Open file |
2764 * | | Check Handle Time = 1 | Check Handle Time = 1 |
2765 * | | Check Path Time = 1 | Check Path Time = 1 |
2766 * | 2 | Write | |
2767 * | 3 | Check Handle Time = 2 | Check Handle Time = 2 |
2768 * | | Check Path Time = 2 | Check Path Time = 2 |
2769 * | 4 | Set Sticky Time = 99 | |
2770 * | 5 | Check Handle Time = 99 | Check Handle Time = 99 |
2771 * | | Check Path Time = 99 | Check Path Time = 99 |
2772 * | 6 | Write | |
2773 * | 7 | Check Handle Time = 99 | Check Handle Time = 99 |
2774 * | | Check Path Time = 99 | Check Path Time = 99 |
2775 * | 8 | | Write |
2776 * | 9 | Check Handle Time = 8 | Check Handle Time = 8 |
2777 * | | Check Path Time = 8 | Check Path Time = 8 |
2778 * | 10 | Write | |
2779 * | 11 | Check Handle Time = 8 | Check Handle Time = 8 |
2780 * | | Check Path Time = 8 | Check Path Time = 8 |
2781 * | 12 | Close | Close |
2782 * | 13 | Check Path Time = 8 | Check Path Time = 8 |
2783 */
2784 static bool test_modern_write_time1(struct torture_context *tctx,
2785 struct smbcli_state *cli,
2786 struct smbcli_state *cli2)
2787 {
2788 union smb_fileinfo finfo_prev, finfo_curr;
2789 union smb_fileinfo pinfo_prev, pinfo_curr;
2790 const char *fname = BASEDIR "\\torture_file_modern1.txt";
2791 time_t stickytime = time(NULL) + 86400;
2792 NTTIME stickynttime;
2793 int fnum1 = -1;
2794 int fnum2 = -1;
2795 ssize_t written;
2796 NTSTATUS status;
2797 bool ret = true;
2798
2799 unix_to_nt_time(&stickynttime, stickytime);
2800
2801 torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
2802
2803 fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
2804 if (fnum1 == -1) {
2805 ret = false;
2806 torture_result(tctx, TORTURE_FAIL, __location__": unable to open %s", fname);
2807 goto done;
2808 }
2809
2810 fnum2 = smbcli_open(cli2->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
2811 if (fnum2 == -1) {
2812 ret = false;
2813 torture_result(tctx, TORTURE_FAIL, __location__": unable to open %s", fname);
2814 goto done;
2815 }
2816
2817 finfo_prev.basic_info.level = RAW_FILEINFO_BASIC_INFO;
2818 finfo_curr = finfo_prev;
2819
2820 pinfo_prev.basic_info.level = RAW_FILEINFO_BASIC_INFO;
2821 pinfo_prev.basic_info.in.file.path = fname;
2822 pinfo_curr = pinfo_prev;
2823
2824 /* get the initial times */
2825 GET_INFO_BOTH_EX(cli, fnum1, finfo_prev, pinfo_prev);
2826
2827 /* 2 */
2828 torture_comment(tctx, "Do a write on the file handle\n");
2829 written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
2830 if (written != 1) {
2831 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 1", (int)written);
2832 ret = false;
2833 goto done;
2834 }
2835
2836 /* 3 */
2837 GET_INFO_BOTH_EX(cli, fnum1, finfo_curr, pinfo_curr);
2838 torture_assert_u64_not_equal_goto(tctx,
2839 finfo_curr.basic_info.out.write_time,
2840 finfo_prev.basic_info.out.write_time,
2841 ret, done,
2842 "Server did not update write time "
2843 "immediately");
2844 torture_assert_u64_not_equal_goto(tctx,
2845 pinfo_curr.basic_info.out.write_time,
2846 pinfo_prev.basic_info.out.write_time,
2847 ret, done,
2848 "Server did not update write time "
2849 "immediately");
2850
2851 GET_INFO_BOTH_EX(cli2, fnum2, finfo_curr, pinfo_curr);
2852 torture_assert_u64_not_equal_goto(tctx,
2853 finfo_curr.basic_info.out.write_time,
2854 finfo_prev.basic_info.out.write_time,
2855 ret, done,
2856 "Server did not update write time "
2857 "immediately");
2858 torture_assert_u64_not_equal_goto(tctx,
2859 pinfo_curr.basic_info.out.write_time,
2860 pinfo_prev.basic_info.out.write_time,
2861 ret, done,
2862 "Server did not update write time "
2863 "immediately");
2864 finfo_prev = finfo_curr;
2865 pinfo_prev = pinfo_curr;
2866
2867 /* 4 */
2868 torture_comment(tctx, "Set write time in the future on the 1st file handle\n");
2869 SET_INFO_FILE_EX(finfo_curr, stickytime, cli->tree, fnum1);
2870
2871
2872 /* 5 */
2873 GET_INFO_BOTH_EX(cli, fnum1, finfo_curr, pinfo_curr);
2874 torture_assert_u64_equal_goto(tctx,
2875 finfo_curr.basic_info.out.write_time,
2876 stickynttime,
2877 ret, done,
2878 "Server did not return sticky time");
2879 torture_assert_u64_equal_goto(tctx,
2880 pinfo_curr.basic_info.out.write_time,
2881 stickynttime,
2882 ret, done,
2883 "Server did not return sticky time");
2884 GET_INFO_BOTH_EX(cli2, fnum2, finfo_curr, pinfo_curr);
2885 torture_assert_u64_equal_goto(tctx,
2886 finfo_curr.basic_info.out.write_time,
2887 stickynttime,
2888 ret, done,
2889 "Server did not return sticky time");
2890 torture_assert_u64_equal_goto(tctx,
2891 pinfo_curr.basic_info.out.write_time,
2892 stickynttime,
2893 ret, done,
2894 "Server did not return sticky time");
2895
2896 /* 6 */
2897 written = smbcli_write(cli->tree, fnum1, 0, "xx", 0, 2);
2898 if (written != 2) {
2899 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 2", (int)written);
2900 ret = false;
2901 goto done;
2902 }
2903
2904 /* 7 */
2905 GET_INFO_BOTH_EX(cli, fnum1, finfo_curr, pinfo_curr);
2906 torture_assert_u64_equal_goto(tctx,
2907 finfo_curr.basic_info.out.write_time,
2908 stickynttime,
2909 ret, done,
2910 "Server did not return sticky time");
2911 torture_assert_u64_equal_goto(tctx,
2912 pinfo_curr.basic_info.out.write_time,
2913 stickynttime,
2914 ret, done,
2915 "Server did not return sticky time");
2916 GET_INFO_BOTH_EX(cli2, fnum2, finfo_curr, pinfo_curr);
2917 torture_assert_u64_equal_goto(tctx,
2918 finfo_curr.basic_info.out.write_time,
2919 stickynttime,
2920 ret, done,
2921 "Server did not return sticky time");
2922 torture_assert_u64_equal_goto(tctx,
2923 pinfo_curr.basic_info.out.write_time,
2924 stickynttime,
2925 ret, done,
2926 "Server did not return sticky time");
2927
2928 /* 8 */
2929 written = smbcli_write(cli2->tree, fnum2, 0, "xxx", 0, 3);
2930 if (written != 3) {
2931 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 3", (int)written);
2932 ret = false;
2933 goto done;
2934 }
2935
2936 /* 9 */
2937 GET_INFO_BOTH_EX(cli2, fnum2, finfo_curr, pinfo_curr);
2938 torture_assert_goto(tctx,
2939 finfo_curr.basic_info.out.write_time < stickynttime,
2940 ret, done,
2941 "Write did not update timestamp");
2942 torture_assert_goto(tctx,
2943 finfo_curr.basic_info.out.write_time >
2944 finfo_prev.basic_info.out.write_time,
2945 ret, done,
2946 "Write did not update timestamp");
2947 torture_assert_u64_equal_goto(tctx,
2948 finfo_curr.basic_info.out.write_time,
2949 pinfo_curr.basic_info.out.write_time,
2950 ret, done,
2951 "Write did not update timestamp");
2952
2953 GET_INFO_BOTH_EX(cli, fnum1, finfo_curr, pinfo_curr);
2954 torture_assert_goto(tctx,
2955 finfo_curr.basic_info.out.write_time < stickynttime,
2956 ret, done,
2957 "Write did not update timestamp");
2958 torture_assert_goto(tctx,
2959 finfo_curr.basic_info.out.write_time >
2960 finfo_prev.basic_info.out.write_time,
2961 ret, done,
2962 "Write did not update timestamp");
2963 torture_assert_u64_equal_goto(tctx,
2964 finfo_curr.basic_info.out.write_time,
2965 pinfo_curr.basic_info.out.write_time,
2966 ret, done,
2967 "Write did not update timestamp");
2968 finfo_prev = finfo_curr;
2969 pinfo_prev = pinfo_curr;
2970
2971 /* 10 */
2972 written = smbcli_write(cli->tree, fnum1, 0, "xxxx", 0, 4);
2973 if (written != 4) {
2974 torture_result(tctx, TORTURE_FAIL, __location__": written gave %d - should have been 4", (int)written);
2975 ret = false;
2976 goto done;
2977 }
2978
2979 /* 11 */
2980 GET_INFO_BOTH_EX(cli, fnum1, finfo_curr, pinfo_curr);
2981 torture_assert_u64_equal_goto(tctx,
2982 finfo_curr.basic_info.out.write_time,
2983 finfo_prev.basic_info.out.write_time,
2984 ret, done,
2985 "Server update write time");
2986 torture_assert_u64_equal_goto(tctx,
2987 pinfo_curr.basic_info.out.write_time,
2988 pinfo_prev.basic_info.out.write_time,
2989 ret, done,
2990 "Server update write time");
2991
2992 GET_INFO_BOTH_EX(cli2, fnum2, finfo_curr, pinfo_curr);
2993 torture_assert_u64_equal_goto(tctx,
2994 finfo_curr.basic_info.out.write_time,
2995 finfo_prev.basic_info.out.write_time,
2996 ret, done,
2997 "Server update write time");
2998 torture_assert_u64_equal_goto(tctx,
2999 pinfo_curr.basic_info.out.write_time,
3000 pinfo_prev.basic_info.out.write_time,
3001 ret, done,
3002 "Server update write time");
3003
3004 /* 12 */
3005
3006 status = smbcli_close(cli->tree, fnum1);
3007 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
3008 "smbcli_close failed");
3009 fnum1 = -1;
3010
3011 status = smbcli_close(cli2->tree, fnum2);
3012 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
3013 "smbcli_close failed");
3014 fnum2 = -1;
3015
3016 /* 13 */
3017 GET_INFO_PATH_EX(cli, pinfo_curr);
3018 torture_assert_u64_equal_goto(tctx,
3019 pinfo_curr.basic_info.out.write_time,
3020 pinfo_prev.basic_info.out.write_time,
3021 ret, done,
3022 "Server update write time");
3023 GET_INFO_PATH_EX(cli2, pinfo_curr);
3024 torture_assert_u64_equal_goto(tctx,
3025 pinfo_curr.basic_info.out.write_time,
3026 pinfo_prev.basic_info.out.write_time,
3027 ret, done,
3028 "Server update write time");
3029
3030 done:
3031 if (fnum1 != -1)
3032 smbcli_close(cli->tree, fnum1);
3033 if (fnum2 != -1)
3034 smbcli_close(cli2->tree, fnum2);
3035 smbcli_unlink(cli->tree, fname);
3036 smbcli_deltree(cli->tree, BASEDIR);
3037
3038 return ret;
3039 }
3040
3041 /*
3042 testing of delayed update of write_time
3043 */
3044 struct torture_suite *torture_delay_write(TALLOC_CTX *ctx)
3045 {
3046 struct torture_suite *suite = torture_suite_create(ctx, "delaywrite");
3047
3048 torture_suite_add_2smb_test(suite, "finfo update on close", test_finfo_after_write);
3049 torture_suite_add_1smb_test(suite, "delayed update of write time", test_delayed_write_update);
3050 torture_suite_add_1smb_test(suite, "update of write time and SMBwrite truncate", test_delayed_write_update1);
3051 torture_suite_add_1smb_test(suite, "update of write time and SMBwrite truncate expand", test_delayed_write_update1a);
3052 torture_suite_add_1smb_test(suite, "update of write time using SET_END_OF_FILE", test_delayed_write_update1b);
3053 torture_suite_add_1smb_test(suite, "update of write time using SET_ALLOCATION_SIZE", test_delayed_write_update1c);
3054 torture_suite_add_2smb_test(suite, "delayed update of write time using 2 connections", test_delayed_write_update2);
3055 torture_suite_add_2smb_test(suite, "delayed update of write time 3", test_delayed_write_update3);
3056 torture_suite_add_2smb_test(suite, "delayed update of write time 3a", test_delayed_write_update3a);
3057 torture_suite_add_2smb_test(suite, "delayed update of write time 3b", test_delayed_write_update3b);
3058 torture_suite_add_2smb_test(suite, "delayed update of write time 3c", test_delayed_write_update3c);
3059 torture_suite_add_2smb_test(suite, "delayed update of write time 4", test_delayed_write_update4);
3060 torture_suite_add_2smb_test(suite, "delayed update of write time 5", test_delayed_write_update5);
3061 torture_suite_add_2smb_test(suite, "delayed update of write time 5b", test_delayed_write_update5b);
3062 torture_suite_add_2smb_test(suite, "delayed update of write time 6", test_delayed_write_update6);
3063 torture_suite_add_1smb_test(suite, "timestamp resolution test", test_delayed_write_update7);
3064 torture_suite_add_1smb_test(suite, "directory timestamp update test", test_directory_update8);
3065 torture_suite_add_2smb_test(suite, "modern_write_time_update-1", test_modern_write_time1);
3066
3067 return suite;
3068 }