| 1 |
/* |
| 2 |
Unix SMB/CIFS implementation. |
| 3 |
|
| 4 |
test timestamps |
| 5 |
|
| 6 |
Copyright (C) Ralph Boehme 2019 |
| 7 |
|
| 8 |
This program is free software; you can redistribute it and/or modify |
| 9 |
it under the terms of the GNU General Public License as published by |
| 10 |
the Free Software Foundation; either version 3 of the License, or |
| 11 |
(at your option) any later version. |
| 12 |
|
| 13 |
This program is distributed in the hope that it will be useful, |
| 14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
GNU General Public License for more details. |
| 17 |
|
| 18 |
You should have received a copy of the GNU General Public License |
| 19 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 |
*/ |
| 21 |
|
| 22 |
#include "includes.h" |
| 23 |
#include "libcli/smb2/smb2.h" |
| 24 |
#include "libcli/smb2/smb2_calls.h" |
| 25 |
#include "torture/torture.h" |
| 26 |
#include "torture/util.h" |
| 27 |
#include "torture/smb2/proto.h" |
| 28 |
|
| 29 |
#define BASEDIR "smb2-timestamps" |
| 30 |
#define FNAME "testfile.dat" |
| 31 |
|
| 32 |
static bool test_close_no_attrib(struct torture_context *tctx, |
| 33 |
struct smb2_tree *tree) |
| 34 |
{ |
| 35 |
const char *filename = BASEDIR "/" FNAME; |
| 36 |
struct smb2_create cr; |
| 37 |
struct smb2_handle handle = {{0}}; |
| 38 |
struct smb2_handle testdirh = {{0}}; |
| 39 |
struct smb2_close c; |
| 40 |
NTSTATUS status; |
| 41 |
bool ret = true; |
| 42 |
|
| 43 |
smb2_deltree(tree, BASEDIR); |
| 44 |
|
| 45 |
status = torture_smb2_testdir(tree, BASEDIR, &testdirh); |
| 46 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 47 |
"torture_smb2_testdir failed\n"); |
| 48 |
smb2_util_close(tree, testdirh); |
| 49 |
|
| 50 |
cr = (struct smb2_create) { |
| 51 |
.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED, |
| 52 |
.in.file_attributes = FILE_ATTRIBUTE_NORMAL, |
| 53 |
.in.share_access = NTCREATEX_SHARE_ACCESS_MASK, |
| 54 |
.in.create_disposition = NTCREATEX_DISP_OPEN_IF, |
| 55 |
.in.impersonation_level = NTCREATEX_IMPERSONATION_ANONYMOUS, |
| 56 |
.in.fname = filename, |
| 57 |
}; |
| 58 |
|
| 59 |
status = smb2_create(tree, tctx, &cr); |
| 60 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 61 |
"smb2_create failed\n"); |
| 62 |
handle = cr.out.file.handle; |
| 63 |
|
| 64 |
c = (struct smb2_close) { |
| 65 |
.in.file.handle = handle, |
| 66 |
}; |
| 67 |
|
| 68 |
status = smb2_close(tree, &c); |
| 69 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 70 |
"close failed\n"); |
| 71 |
ZERO_STRUCT(handle); |
| 72 |
|
| 73 |
torture_assert_u64_equal_goto(tctx, c.out.create_time, NTTIME_OMIT, |
| 74 |
ret, done, "Unexpected create time\n"); |
| 75 |
torture_assert_u64_equal_goto(tctx, c.out.access_time, NTTIME_OMIT, |
| 76 |
ret, done, "Unexpected access time\n"); |
| 77 |
torture_assert_u64_equal_goto(tctx, c.out.write_time, NTTIME_OMIT, |
| 78 |
ret, done, "Unexpected write time\n"); |
| 79 |
torture_assert_u64_equal_goto(tctx, c.out.size, 0, |
| 80 |
ret, done, "Unexpected size\n"); |
| 81 |
torture_assert_u64_equal_goto(tctx, c.out.file_attr, 0, |
| 82 |
ret, done, "Unexpected attributes\n"); |
| 83 |
|
| 84 |
done: |
| 85 |
if (!smb2_util_handle_empty(handle)) { |
| 86 |
smb2_util_close(tree, handle); |
| 87 |
} |
| 88 |
smb2_deltree(tree, BASEDIR); |
| 89 |
return ret; |
| 90 |
} |
| 91 |
|
| 92 |
static bool test_time_t(struct torture_context *tctx, |
| 93 |
struct smb2_tree *tree, |
| 94 |
const char *fname, |
| 95 |
time_t t) |
| 96 |
{ |
| 97 |
char *filename = NULL; |
| 98 |
struct smb2_create cr; |
| 99 |
struct smb2_handle handle = {{0}}; |
| 100 |
struct smb2_handle testdirh = {{0}}; |
| 101 |
struct timespec ts = { .tv_sec = t }; |
| 102 |
uint64_t nttime; |
| 103 |
union smb_fileinfo gi; |
| 104 |
union smb_setfileinfo si; |
| 105 |
struct smb2_find find; |
| 106 |
unsigned int count; |
| 107 |
union smb_search_data *d; |
| 108 |
NTSTATUS status; |
| 109 |
bool ret = true; |
| 110 |
|
| 111 |
smb2_deltree(tree, BASEDIR); |
| 112 |
|
| 113 |
status = torture_smb2_testdir(tree, BASEDIR, &testdirh); |
| 114 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 115 |
"torture_smb2_testdir failed\n"); |
| 116 |
|
| 117 |
filename = talloc_asprintf(tctx, "%s\\%s", BASEDIR, fname); |
| 118 |
torture_assert_not_null_goto(tctx, filename, ret, done, |
| 119 |
"talloc_asprintf failed\n"); |
| 120 |
|
| 121 |
cr = (struct smb2_create) { |
| 122 |
.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED, |
| 123 |
.in.file_attributes = FILE_ATTRIBUTE_NORMAL, |
| 124 |
.in.share_access = NTCREATEX_SHARE_ACCESS_MASK, |
| 125 |
.in.create_disposition = NTCREATEX_DISP_OPEN_IF, |
| 126 |
.in.impersonation_level = NTCREATEX_IMPERSONATION_ANONYMOUS, |
| 127 |
.in.fname = filename, |
| 128 |
}; |
| 129 |
|
| 130 |
status = smb2_create(tree, tctx, &cr); |
| 131 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 132 |
"smb2_create failed\n"); |
| 133 |
handle = cr.out.file.handle; |
| 134 |
|
| 135 |
si = (union smb_setfileinfo) { |
| 136 |
.basic_info.level = RAW_SFILEINFO_BASIC_INFORMATION, |
| 137 |
.basic_info.in.file.handle = handle, |
| 138 |
}; |
| 139 |
|
| 140 |
nttime = full_timespec_to_nt_time(&ts); |
| 141 |
si.basic_info.in.create_time = nttime; |
| 142 |
si.basic_info.in.write_time = nttime; |
| 143 |
|
| 144 |
status = smb2_setinfo_file(tree, &si); |
| 145 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 146 |
"smb2_setinfo_file failed\n"); |
| 147 |
|
| 148 |
gi = (union smb_fileinfo) { |
| 149 |
.generic.level = SMB_QFILEINFO_BASIC_INFORMATION, |
| 150 |
.generic.in.file.handle = handle, |
| 151 |
}; |
| 152 |
|
| 153 |
status = smb2_getinfo_file(tree, tctx, &gi); |
| 154 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 155 |
"smb2_getinfo_file failed\n"); |
| 156 |
|
| 157 |
torture_comment(tctx, "Got: create: %s, write: %s, change: %s\n", |
| 158 |
nt_time_string(tctx, gi.basic_info.out.create_time), |
| 159 |
nt_time_string(tctx, gi.basic_info.out.write_time), |
| 160 |
nt_time_string(tctx, gi.basic_info.out.change_time)); |
| 161 |
|
| 162 |
torture_assert_u64_equal_goto(tctx, |
| 163 |
gi.basic_info.out.create_time, |
| 164 |
nttime, |
| 165 |
ret, done, |
| 166 |
"Wrong create time\n"); |
| 167 |
torture_assert_u64_equal_goto(tctx, |
| 168 |
gi.basic_info.out.write_time, |
| 169 |
nttime, |
| 170 |
ret, done, |
| 171 |
"Wrong write time\n"); |
| 172 |
|
| 173 |
find = (struct smb2_find) { |
| 174 |
.in.file.handle = testdirh, |
| 175 |
.in.pattern = fname, |
| 176 |
.in.max_response_size = 0x1000, |
| 177 |
.in.level = SMB2_FIND_ID_BOTH_DIRECTORY_INFO, |
| 178 |
}; |
| 179 |
|
| 180 |
status = smb2_find_level(tree, tree, &find, &count, &d); |
| 181 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 182 |
"smb2_find_level failed\n"); |
| 183 |
|
| 184 |
torture_assert_u64_equal_goto(tctx, |
| 185 |
d[0].id_both_directory_info.create_time, |
| 186 |
nttime, |
| 187 |
ret, done, |
| 188 |
"Wrong create time\n"); |
| 189 |
torture_assert_u64_equal_goto(tctx, |
| 190 |
d[0].id_both_directory_info.write_time, |
| 191 |
nttime, |
| 192 |
ret, done, |
| 193 |
"Wrong write time\n"); |
| 194 |
|
| 195 |
status = smb2_util_close(tree, handle); |
| 196 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 197 |
"smb2_util_close failed\n"); |
| 198 |
ZERO_STRUCT(handle); |
| 199 |
|
| 200 |
cr = (struct smb2_create) { |
| 201 |
.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED, |
| 202 |
.in.file_attributes = FILE_ATTRIBUTE_NORMAL, |
| 203 |
.in.share_access = NTCREATEX_SHARE_ACCESS_MASK, |
| 204 |
.in.create_disposition = NTCREATEX_DISP_OPEN, |
| 205 |
.in.impersonation_level = NTCREATEX_IMPERSONATION_ANONYMOUS, |
| 206 |
.in.fname = filename, |
| 207 |
}; |
| 208 |
|
| 209 |
status = smb2_create(tree, tctx, &cr); |
| 210 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 211 |
"smb2_create failed\n"); |
| 212 |
handle = cr.out.file.handle; |
| 213 |
|
| 214 |
gi = (union smb_fileinfo) { |
| 215 |
.generic.level = SMB_QFILEINFO_BASIC_INFORMATION, |
| 216 |
.generic.in.file.handle = handle, |
| 217 |
}; |
| 218 |
|
| 219 |
status = smb2_getinfo_file(tree, tctx, &gi); |
| 220 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 221 |
"smb2_getinfo_file failed\n"); |
| 222 |
|
| 223 |
torture_comment(tctx, "Got: create: %s, write: %s, change: %s\n", |
| 224 |
nt_time_string(tctx, gi.basic_info.out.create_time), |
| 225 |
nt_time_string(tctx, gi.basic_info.out.write_time), |
| 226 |
nt_time_string(tctx, gi.basic_info.out.change_time)); |
| 227 |
|
| 228 |
torture_assert_u64_equal_goto(tctx, |
| 229 |
gi.basic_info.out.create_time, |
| 230 |
nttime, |
| 231 |
ret, done, |
| 232 |
"Wrong create time\n"); |
| 233 |
torture_assert_u64_equal_goto(tctx, |
| 234 |
gi.basic_info.out.write_time, |
| 235 |
nttime, |
| 236 |
ret, done, |
| 237 |
"Wrong write time\n"); |
| 238 |
|
| 239 |
find = (struct smb2_find) { |
| 240 |
.in.continue_flags = SMB2_CONTINUE_FLAG_RESTART, |
| 241 |
.in.file.handle = testdirh, |
| 242 |
.in.pattern = fname, |
| 243 |
.in.max_response_size = 0x1000, |
| 244 |
.in.level = SMB2_FIND_ID_BOTH_DIRECTORY_INFO, |
| 245 |
}; |
| 246 |
|
| 247 |
status = smb2_find_level(tree, tree, &find, &count, &d); |
| 248 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 249 |
"smb2_find_level failed\n"); |
| 250 |
|
| 251 |
torture_assert_u64_equal_goto(tctx, |
| 252 |
d[0].id_both_directory_info.create_time, |
| 253 |
nttime, |
| 254 |
ret, done, |
| 255 |
"Wrong create time\n"); |
| 256 |
torture_assert_u64_equal_goto(tctx, |
| 257 |
d[0].id_both_directory_info.write_time, |
| 258 |
nttime, |
| 259 |
ret, done, |
| 260 |
"Wrong write time\n"); |
| 261 |
|
| 262 |
status = smb2_util_close(tree, handle); |
| 263 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 264 |
"smb2_util_close failed\n"); |
| 265 |
ZERO_STRUCT(handle); |
| 266 |
|
| 267 |
done: |
| 268 |
if (!smb2_util_handle_empty(handle)) { |
| 269 |
smb2_util_close(tree, handle); |
| 270 |
} |
| 271 |
if (!smb2_util_handle_empty(testdirh)) { |
| 272 |
smb2_util_close(tree, testdirh); |
| 273 |
} |
| 274 |
smb2_deltree(tree, BASEDIR); |
| 275 |
return ret; |
| 276 |
} |
| 277 |
|
| 278 |
static bool test_time_t_15032385535(struct torture_context *tctx, |
| 279 |
struct smb2_tree *tree) |
| 280 |
{ |
| 281 |
return test_time_t(tctx, tree, "test_time_t_15032385535.txt", |
| 282 |
15032385535 /* >> INT32_MAX, limit on ext */); |
| 283 |
} |
| 284 |
|
| 285 |
static bool test_time_t_10000000000(struct torture_context *tctx, |
| 286 |
struct smb2_tree *tree) |
| 287 |
{ |
| 288 |
return test_time_t(tctx, tree, "test_time_t_10000000000.txt", |
| 289 |
10000000000 /* >> INT32_MAX */); |
| 290 |
} |
| 291 |
|
| 292 |
static bool test_time_t_4294967295(struct torture_context *tctx, |
| 293 |
struct smb2_tree *tree) |
| 294 |
{ |
| 295 |
return test_time_t(tctx, tree, "test_time_t_4294967295.txt", |
| 296 |
4294967295 /* INT32_MAX */); |
| 297 |
} |
| 298 |
|
| 299 |
static bool test_time_t_1(struct torture_context *tctx, |
| 300 |
struct smb2_tree *tree) |
| 301 |
{ |
| 302 |
return test_time_t(tctx, tree, "test_time_t_1.txt", 1); |
| 303 |
} |
| 304 |
|
| 305 |
static bool test_time_t_0(struct torture_context *tctx, |
| 306 |
struct smb2_tree *tree) |
| 307 |
{ |
| 308 |
return test_time_t(tctx, tree, "test_time_t_0.txt", 0); |
| 309 |
} |
| 310 |
|
| 311 |
static bool test_time_t_minus_1(struct torture_context *tctx, |
| 312 |
struct smb2_tree *tree) |
| 313 |
{ |
| 314 |
return test_time_t(tctx, tree, "test_time_t_-1.txt", -1); |
| 315 |
} |
| 316 |
|
| 317 |
static bool test_time_t_minus_2(struct torture_context *tctx, |
| 318 |
struct smb2_tree *tree) |
| 319 |
{ |
| 320 |
return test_time_t(tctx, tree, "test_time_t_-2.txt", -2); |
| 321 |
} |
| 322 |
|
| 323 |
static bool test_time_t_1968(struct torture_context *tctx, |
| 324 |
struct smb2_tree *tree) |
| 325 |
{ |
| 326 |
return test_time_t(tctx, tree, "test_time_t_1968.txt", |
| 327 |
-63158400 /* 1968 */); |
| 328 |
} |
| 329 |
|
| 330 |
static bool test_freeze_thaw(struct torture_context *tctx, |
| 331 |
struct smb2_tree *tree) |
| 332 |
{ |
| 333 |
const char *filename = BASEDIR "\\test_freeze_thaw"; |
| 334 |
struct smb2_create cr; |
| 335 |
struct smb2_handle handle = {{0}}; |
| 336 |
struct smb2_handle testdirh = {{0}}; |
| 337 |
struct timespec ts = { .tv_sec = time(NULL) }; |
| 338 |
uint64_t nttime; |
| 339 |
union smb_fileinfo gi; |
| 340 |
union smb_setfileinfo si; |
| 341 |
NTSTATUS status; |
| 342 |
bool ret = true; |
| 343 |
|
| 344 |
smb2_deltree(tree, BASEDIR); |
| 345 |
|
| 346 |
status = torture_smb2_testdir(tree, BASEDIR, &testdirh); |
| 347 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 348 |
"torture_smb2_testdir failed\n"); |
| 349 |
|
| 350 |
cr = (struct smb2_create) { |
| 351 |
.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED, |
| 352 |
.in.file_attributes = FILE_ATTRIBUTE_NORMAL, |
| 353 |
.in.share_access = NTCREATEX_SHARE_ACCESS_MASK, |
| 354 |
.in.create_disposition = NTCREATEX_DISP_OPEN_IF, |
| 355 |
.in.impersonation_level = NTCREATEX_IMPERSONATION_ANONYMOUS, |
| 356 |
.in.fname = filename, |
| 357 |
}; |
| 358 |
|
| 359 |
status = smb2_create(tree, tctx, &cr); |
| 360 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 361 |
"smb2_create failed\n"); |
| 362 |
handle = cr.out.file.handle; |
| 363 |
|
| 364 |
si = (union smb_setfileinfo) { |
| 365 |
.basic_info.level = RAW_SFILEINFO_BASIC_INFORMATION, |
| 366 |
.basic_info.in.file.handle = handle, |
| 367 |
}; |
| 368 |
|
| 369 |
/* |
| 370 |
* Step 1: |
| 371 |
* First set timestamps of testfile to current time |
| 372 |
*/ |
| 373 |
|
| 374 |
nttime = full_timespec_to_nt_time(&ts); |
| 375 |
si.basic_info.in.create_time = nttime; |
| 376 |
si.basic_info.in.write_time = nttime; |
| 377 |
|
| 378 |
status = smb2_setinfo_file(tree, &si); |
| 379 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 380 |
"smb2_setinfo_file failed\n"); |
| 381 |
|
| 382 |
gi = (union smb_fileinfo) { |
| 383 |
.generic.level = SMB_QFILEINFO_BASIC_INFORMATION, |
| 384 |
.generic.in.file.handle = handle, |
| 385 |
}; |
| 386 |
|
| 387 |
/* |
| 388 |
* Step 2: |
| 389 |
* Verify timestamps are indeed set to the value in "nttime". |
| 390 |
*/ |
| 391 |
|
| 392 |
status = smb2_getinfo_file(tree, tctx, &gi); |
| 393 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 394 |
"smb2_getinfo_file failed\n"); |
| 395 |
|
| 396 |
torture_comment(tctx, "Got: create: %s, write: %s, change: %s\n", |
| 397 |
nt_time_string(tctx, gi.basic_info.out.create_time), |
| 398 |
nt_time_string(tctx, gi.basic_info.out.write_time), |
| 399 |
nt_time_string(tctx, gi.basic_info.out.change_time)); |
| 400 |
|
| 401 |
torture_assert_u64_equal_goto(tctx, |
| 402 |
gi.basic_info.out.create_time, |
| 403 |
nttime, |
| 404 |
ret, done, |
| 405 |
"Wrong create time\n"); |
| 406 |
torture_assert_u64_equal_goto(tctx, |
| 407 |
gi.basic_info.out.write_time, |
| 408 |
nttime, |
| 409 |
ret, done, |
| 410 |
"Wrong write time\n"); |
| 411 |
|
| 412 |
/* |
| 413 |
* Step 3: |
| 414 |
* First set timestamps with NTTIME_FREEZE, must not change any |
| 415 |
* timestamp value. |
| 416 |
*/ |
| 417 |
|
| 418 |
si.basic_info.in.create_time = NTTIME_FREEZE; |
| 419 |
si.basic_info.in.write_time = NTTIME_FREEZE; |
| 420 |
|
| 421 |
status = smb2_setinfo_file(tree, &si); |
| 422 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 423 |
"smb2_setinfo_file failed\n"); |
| 424 |
|
| 425 |
gi = (union smb_fileinfo) { |
| 426 |
.generic.level = SMB_QFILEINFO_BASIC_INFORMATION, |
| 427 |
.generic.in.file.handle = handle, |
| 428 |
}; |
| 429 |
|
| 430 |
/* |
| 431 |
* Step 4: |
| 432 |
* Verify timestamps are unmodified from step 2. |
| 433 |
*/ |
| 434 |
|
| 435 |
gi = (union smb_fileinfo) { |
| 436 |
.generic.level = SMB_QFILEINFO_BASIC_INFORMATION, |
| 437 |
.generic.in.file.handle = handle, |
| 438 |
}; |
| 439 |
|
| 440 |
status = smb2_getinfo_file(tree, tctx, &gi); |
| 441 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 442 |
"smb2_getinfo_file failed\n"); |
| 443 |
|
| 444 |
torture_comment(tctx, "Got: create: %s, write: %s, change: %s\n", |
| 445 |
nt_time_string(tctx, gi.basic_info.out.create_time), |
| 446 |
nt_time_string(tctx, gi.basic_info.out.write_time), |
| 447 |
nt_time_string(tctx, gi.basic_info.out.change_time)); |
| 448 |
|
| 449 |
torture_assert_u64_equal_goto(tctx, |
| 450 |
gi.basic_info.out.create_time, |
| 451 |
nttime, |
| 452 |
ret, done, |
| 453 |
"Wrong create time\n"); |
| 454 |
torture_assert_u64_equal_goto(tctx, |
| 455 |
gi.basic_info.out.write_time, |
| 456 |
nttime, |
| 457 |
ret, done, |
| 458 |
"Wrong write time\n"); |
| 459 |
|
| 460 |
/* |
| 461 |
* Step 5: |
| 462 |
* First set timestamps with NTTIME_THAW, must not change any timestamp |
| 463 |
* value. |
| 464 |
*/ |
| 465 |
|
| 466 |
si.basic_info.in.create_time = NTTIME_THAW; |
| 467 |
si.basic_info.in.write_time = NTTIME_THAW; |
| 468 |
|
| 469 |
status = smb2_setinfo_file(tree, &si); |
| 470 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 471 |
"smb2_setinfo_file failed\n"); |
| 472 |
|
| 473 |
gi = (union smb_fileinfo) { |
| 474 |
.generic.level = SMB_QFILEINFO_BASIC_INFORMATION, |
| 475 |
.generic.in.file.handle = handle, |
| 476 |
}; |
| 477 |
|
| 478 |
/* |
| 479 |
* Step 6: |
| 480 |
* Verify timestamps are unmodified from step 2. |
| 481 |
*/ |
| 482 |
|
| 483 |
gi = (union smb_fileinfo) { |
| 484 |
.generic.level = SMB_QFILEINFO_BASIC_INFORMATION, |
| 485 |
.generic.in.file.handle = handle, |
| 486 |
}; |
| 487 |
|
| 488 |
status = smb2_getinfo_file(tree, tctx, &gi); |
| 489 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 490 |
"smb2_getinfo_file failed\n"); |
| 491 |
|
| 492 |
torture_comment(tctx, "Got: create: %s, write: %s, change: %s\n", |
| 493 |
nt_time_string(tctx, gi.basic_info.out.create_time), |
| 494 |
nt_time_string(tctx, gi.basic_info.out.write_time), |
| 495 |
nt_time_string(tctx, gi.basic_info.out.change_time)); |
| 496 |
|
| 497 |
torture_assert_u64_equal_goto(tctx, |
| 498 |
gi.basic_info.out.create_time, |
| 499 |
nttime, |
| 500 |
ret, done, |
| 501 |
"Wrong create time\n"); |
| 502 |
torture_assert_u64_equal_goto(tctx, |
| 503 |
gi.basic_info.out.write_time, |
| 504 |
nttime, |
| 505 |
ret, done, |
| 506 |
"Wrong write time\n"); |
| 507 |
|
| 508 |
done: |
| 509 |
if (!smb2_util_handle_empty(handle)) { |
| 510 |
smb2_util_close(tree, handle); |
| 511 |
} |
| 512 |
if (!smb2_util_handle_empty(testdirh)) { |
| 513 |
smb2_util_close(tree, testdirh); |
| 514 |
} |
| 515 |
smb2_deltree(tree, BASEDIR); |
| 516 |
return ret; |
| 517 |
} |
| 518 |
|
| 519 |
static bool test_delayed_write_vs_seteof(struct torture_context *tctx, |
| 520 |
struct smb2_tree *tree) |
| 521 |
{ |
| 522 |
struct smb2_create cr; |
| 523 |
struct smb2_handle h1 = {{0}}; |
| 524 |
struct smb2_handle h2 = {{0}}; |
| 525 |
NTTIME create_time; |
| 526 |
NTTIME set_time; |
| 527 |
NTTIME latest_time; |
| 528 |
union smb_fileinfo finfo; |
| 529 |
union smb_setfileinfo setinfo; |
| 530 |
struct smb2_close c; |
| 531 |
NTSTATUS status; |
| 532 |
bool ret = true; |
| 533 |
|
| 534 |
smb2_deltree(tree, BASEDIR); |
| 535 |
status = torture_smb2_testdir(tree, BASEDIR, &h1); |
| 536 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 537 |
"create failed\n"); |
| 538 |
status = smb2_util_close(tree, h1); |
| 539 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 540 |
"close failed\n"); |
| 541 |
|
| 542 |
torture_comment(tctx, "Open file-handle 1\n"); |
| 543 |
|
| 544 |
cr = (struct smb2_create) { |
| 545 |
.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED, |
| 546 |
.in.create_disposition = NTCREATEX_DISP_OPEN_IF, |
| 547 |
.in.share_access = NTCREATEX_SHARE_ACCESS_MASK, |
| 548 |
.in.fname = BASEDIR "\\" FNAME, |
| 549 |
}; |
| 550 |
status = smb2_create(tree, tctx, &cr); |
| 551 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 552 |
"create failed\n"); |
| 553 |
h1 = cr.out.file.handle; |
| 554 |
create_time = cr.out.create_time; |
| 555 |
sleep(1); |
| 556 |
|
| 557 |
/* Bypass possible filesystem granularity */ |
| 558 |
smb_msleep(20); |
| 559 |
|
| 560 |
torture_comment(tctx, "Setinfo EOF on file-handle 1," |
| 561 |
" should update writetime\n"); |
| 562 |
|
| 563 |
setinfo = (union smb_setfileinfo) { |
| 564 |
.generic.level = RAW_SFILEINFO_END_OF_FILE_INFORMATION, |
| 565 |
}; |
| 566 |
setinfo.end_of_file_info.in.file.handle = h1; |
| 567 |
setinfo.end_of_file_info.in.size = 0; /* same size! */ |
| 568 |
|
| 569 |
status = smb2_setinfo_file(tree, &setinfo); |
| 570 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 571 |
"close failed\n"); |
| 572 |
|
| 573 |
torture_comment(tctx, "Check writetime has been updated " |
| 574 |
"by the setinfo EOF\n"); |
| 575 |
|
| 576 |
finfo = (union smb_fileinfo) { |
| 577 |
.generic.level = RAW_FILEINFO_SMB2_ALL_INFORMATION, |
| 578 |
.generic.in.file.handle = h1, |
| 579 |
}; |
| 580 |
status = smb2_getinfo_file(tree, tree, &finfo); |
| 581 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 582 |
"getinfo failed\n"); |
| 583 |
if (!(finfo.all_info.out.write_time > create_time)) { |
| 584 |
ret = false; |
| 585 |
torture_fail_goto(tctx, done, "setinfo EOF hasn't updated writetime\n"); |
| 586 |
} |
| 587 |
|
| 588 |
/* Bypass possible filesystem granularity */ |
| 589 |
smb_msleep(20); |
| 590 |
|
| 591 |
torture_comment(tctx, "Write to file-handle 1\n"); |
| 592 |
|
| 593 |
status = smb2_util_write(tree, h1, "s", 0, 1); |
| 594 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 595 |
"write failed\n"); |
| 596 |
|
| 597 |
torture_comment(tctx, "Check writetime has been updated\n"); |
| 598 |
|
| 599 |
finfo = (union smb_fileinfo) { |
| 600 |
.generic.level = RAW_FILEINFO_SMB2_ALL_INFORMATION, |
| 601 |
.generic.in.file.handle = h1, |
| 602 |
}; |
| 603 |
status = smb2_getinfo_file(tree, tree, &finfo); |
| 604 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 605 |
"getinfo failed\n"); |
| 606 |
|
| 607 |
torture_assert_nttime_not_equal(tctx, |
| 608 |
finfo.all_info.out.write_time, |
| 609 |
create_time, |
| 610 |
"Writetime not updated\n"); |
| 611 |
latest_time = finfo.all_info.out.write_time; |
| 612 |
|
| 613 |
torture_comment(tctx, "Setinfo EOF on file-handle 1," |
| 614 |
" should update writetime\n"); |
| 615 |
|
| 616 |
/* Bypass possible filesystem granularity */ |
| 617 |
smb_msleep(20); |
| 618 |
|
| 619 |
setinfo = (union smb_setfileinfo) { |
| 620 |
.generic.level = RAW_SFILEINFO_END_OF_FILE_INFORMATION, |
| 621 |
}; |
| 622 |
setinfo.end_of_file_info.in.file.handle = h1; |
| 623 |
setinfo.end_of_file_info.in.size = 1; /* same size! */ |
| 624 |
|
| 625 |
status = smb2_setinfo_file(tree, &setinfo); |
| 626 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 627 |
"close failed\n"); |
| 628 |
|
| 629 |
torture_comment(tctx, "Check writetime has been updated " |
| 630 |
"by the setinfo EOF\n"); |
| 631 |
|
| 632 |
finfo = (union smb_fileinfo) { |
| 633 |
.generic.level = RAW_FILEINFO_SMB2_ALL_INFORMATION, |
| 634 |
.generic.in.file.handle = h1, |
| 635 |
}; |
| 636 |
status = smb2_getinfo_file(tree, tree, &finfo); |
| 637 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 638 |
"getinfo failed\n"); |
| 639 |
if (!(finfo.all_info.out.write_time > latest_time)) { |
| 640 |
ret = false; |
| 641 |
torture_fail_goto(tctx, done, "setinfo EOF hasn't updated writetime\n"); |
| 642 |
} |
| 643 |
|
| 644 |
torture_comment(tctx, "Open file-handle 2\n"); |
| 645 |
|
| 646 |
cr = (struct smb2_create) { |
| 647 |
.in.desired_access = SEC_FILE_WRITE_ATTRIBUTE, |
| 648 |
.in.create_disposition = NTCREATEX_DISP_OPEN, |
| 649 |
.in.share_access = NTCREATEX_SHARE_ACCESS_MASK, |
| 650 |
.in.fname = BASEDIR "\\" FNAME, |
| 651 |
}; |
| 652 |
status = smb2_create(tree, tctx, &cr); |
| 653 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 654 |
"create failed\n"); |
| 655 |
h2 = cr.out.file.handle; |
| 656 |
|
| 657 |
torture_comment(tctx, "Set write time on file-handle 2\n"); |
| 658 |
|
| 659 |
setinfo = (union smb_setfileinfo) { |
| 660 |
.generic.level = SMB_QFILEINFO_BASIC_INFORMATION, |
| 661 |
}; |
| 662 |
setinfo.generic.in.file.handle = h2; |
| 663 |
unix_to_nt_time(&set_time, time(NULL) + 86400); |
| 664 |
setinfo.basic_info.in.write_time = set_time; |
| 665 |
|
| 666 |
status = smb2_setinfo_file(tree, &setinfo); |
| 667 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 668 |
"close failed\n"); |
| 669 |
|
| 670 |
status = smb2_util_close(tree, h2); |
| 671 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 672 |
"close failed\n"); |
| 673 |
ZERO_STRUCT(h2); |
| 674 |
|
| 675 |
torture_comment(tctx, "Close file-handle 1, write-time should not be updated\n"); |
| 676 |
|
| 677 |
c = (struct smb2_close) { |
| 678 |
.in.file.handle = h1, |
| 679 |
.in.flags = SMB2_CLOSE_FLAGS_FULL_INFORMATION, |
| 680 |
}; |
| 681 |
|
| 682 |
status = smb2_close(tree, &c); |
| 683 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 684 |
"close failed\n"); |
| 685 |
ZERO_STRUCT(h1); |
| 686 |
|
| 687 |
torture_assert_nttime_equal(tctx, |
| 688 |
c.out.write_time, |
| 689 |
set_time, |
| 690 |
"Writetime != set_time (wrong!)\n"); |
| 691 |
|
| 692 |
done: |
| 693 |
if (!smb2_util_handle_empty(h1)) { |
| 694 |
smb2_util_close(tree, h1); |
| 695 |
} |
| 696 |
if (!smb2_util_handle_empty(h2)) { |
| 697 |
smb2_util_close(tree, h2); |
| 698 |
} |
| 699 |
smb2_deltree(tree, BASEDIR); |
| 700 |
return ret; |
| 701 |
} |
| 702 |
|
| 703 |
static bool test_delayed_write_vs_flush(struct torture_context *tctx, |
| 704 |
struct smb2_tree *tree) |
| 705 |
{ |
| 706 |
struct smb2_create cr; |
| 707 |
struct smb2_handle h1 = {{0}}; |
| 708 |
union smb_fileinfo finfo; |
| 709 |
struct smb2_flush f; |
| 710 |
struct smb2_close c; |
| 711 |
NTTIME create_time; |
| 712 |
NTTIME write_time; |
| 713 |
NTSTATUS status; |
| 714 |
bool ret = true; |
| 715 |
|
| 716 |
smb2_deltree(tree, BASEDIR); |
| 717 |
status = torture_smb2_testdir(tree, BASEDIR, &h1); |
| 718 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 719 |
"create failed\n"); |
| 720 |
status = smb2_util_close(tree, h1); |
| 721 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 722 |
"close failed\n"); |
| 723 |
|
| 724 |
torture_comment(tctx, "Open file-handle 1\n"); |
| 725 |
|
| 726 |
cr = (struct smb2_create) { |
| 727 |
.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED, |
| 728 |
.in.create_disposition = NTCREATEX_DISP_OPEN_IF, |
| 729 |
.in.share_access = NTCREATEX_SHARE_ACCESS_MASK, |
| 730 |
.in.fname = BASEDIR "\\" FNAME, |
| 731 |
}; |
| 732 |
status = smb2_create(tree, tctx, &cr); |
| 733 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 734 |
"create failed\n"); |
| 735 |
h1 = cr.out.file.handle; |
| 736 |
create_time = cr.out.create_time; |
| 737 |
sleep(1); |
| 738 |
|
| 739 |
torture_comment(tctx, "Write to file-handle 1\n"); |
| 740 |
|
| 741 |
status = smb2_util_write(tree, h1, "s", 0, 1); |
| 742 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 743 |
"write failed\n"); |
| 744 |
|
| 745 |
torture_comment(tctx, "Check writetime has been updated\n"); |
| 746 |
|
| 747 |
finfo = (union smb_fileinfo) { |
| 748 |
.generic.level = RAW_FILEINFO_SMB2_ALL_INFORMATION, |
| 749 |
.generic.in.file.handle = h1, |
| 750 |
}; |
| 751 |
status = smb2_getinfo_file(tree, tree, &finfo); |
| 752 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 753 |
"getinfo failed\n"); |
| 754 |
|
| 755 |
torture_assert_nttime_not_equal(tctx, |
| 756 |
finfo.all_info.out.write_time, |
| 757 |
create_time, |
| 758 |
"Writetime not updated\n"); |
| 759 |
write_time = finfo.all_info.out.write_time; |
| 760 |
|
| 761 |
torture_comment(tctx, "Flush file, " |
| 762 |
"there should be no pending writetime update\n"); |
| 763 |
|
| 764 |
f = (struct smb2_flush) { |
| 765 |
.in.file.handle = h1, |
| 766 |
}; |
| 767 |
|
| 768 |
status = smb2_flush(tree, &f); |
| 769 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 770 |
"flush failed\n"); |
| 771 |
|
| 772 |
torture_comment(tctx, "Check writetime has not been updated " |
| 773 |
"by the flush\n"); |
| 774 |
|
| 775 |
finfo = (union smb_fileinfo) { |
| 776 |
.generic.level = RAW_FILEINFO_SMB2_ALL_INFORMATION, |
| 777 |
.generic.in.file.handle = h1, |
| 778 |
}; |
| 779 |
status = smb2_getinfo_file(tree, tree, &finfo); |
| 780 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 781 |
"getinfo failed\n"); |
| 782 |
|
| 783 |
torture_assert_nttime_equal(tctx, |
| 784 |
finfo.all_info.out.write_time, |
| 785 |
write_time, |
| 786 |
"Writetime updated\n"); |
| 787 |
|
| 788 |
torture_comment(tctx, "Close file-handle 1, write-time should not be updated\n"); |
| 789 |
|
| 790 |
c = (struct smb2_close) { |
| 791 |
.in.file.handle = h1, |
| 792 |
.in.flags = SMB2_CLOSE_FLAGS_FULL_INFORMATION, |
| 793 |
}; |
| 794 |
|
| 795 |
status = smb2_close(tree, &c); |
| 796 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 797 |
"close failed\n"); |
| 798 |
ZERO_STRUCT(h1); |
| 799 |
|
| 800 |
torture_assert_nttime_equal(tctx, |
| 801 |
c.out.write_time, |
| 802 |
write_time, |
| 803 |
"writetime updated\n"); |
| 804 |
|
| 805 |
done: |
| 806 |
if (!smb2_util_handle_empty(h1)) { |
| 807 |
smb2_util_close(tree, h1); |
| 808 |
} |
| 809 |
smb2_deltree(tree, BASEDIR); |
| 810 |
return ret; |
| 811 |
} |
| 812 |
|
| 813 |
static bool test_delayed_write_vs_setbasic_do(struct torture_context *tctx, |
| 814 |
struct smb2_tree *tree, |
| 815 |
union smb_setfileinfo *setinfo) |
| 816 |
{ |
| 817 |
char *path = NULL; |
| 818 |
struct smb2_create cr; |
| 819 |
struct smb2_handle h1 = {{0}}; |
| 820 |
NTTIME create_time; |
| 821 |
NTTIME write_time; |
| 822 |
union smb_fileinfo finfo; |
| 823 |
NTSTATUS status; |
| 824 |
bool ret = true; |
| 825 |
|
| 826 |
torture_comment(tctx, "Create testfile\n"); |
| 827 |
|
| 828 |
path = talloc_asprintf(tree, BASEDIR "\\" FNAME ".%" PRIu32, |
| 829 |
generate_random()); |
| 830 |
torture_assert_not_null_goto(tctx, path, ret, done, "OOM\n"); |
| 831 |
|
| 832 |
cr = (struct smb2_create) { |
| 833 |
.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED, |
| 834 |
.in.create_disposition = NTCREATEX_DISP_CREATE, |
| 835 |
.in.share_access = NTCREATEX_SHARE_ACCESS_MASK, |
| 836 |
.in.fname = path, |
| 837 |
}; |
| 838 |
status = smb2_create(tree, tctx, &cr); |
| 839 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 840 |
"create failed\n"); |
| 841 |
h1 = cr.out.file.handle; |
| 842 |
create_time = cr.out.create_time; |
| 843 |
|
| 844 |
/* Bypass possible filesystem granularity */ |
| 845 |
smb_msleep(20); |
| 846 |
|
| 847 |
torture_comment(tctx, "Write to file\n"); |
| 848 |
|
| 849 |
status = smb2_util_write(tree, h1, "s", 0, 1); |
| 850 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 851 |
"write failed\n"); |
| 852 |
|
| 853 |
torture_comment(tctx, "Get timestamps\n"); |
| 854 |
|
| 855 |
finfo = (union smb_fileinfo) { |
| 856 |
.generic.level = RAW_FILEINFO_SMB2_ALL_INFORMATION, |
| 857 |
.generic.in.file.handle = h1, |
| 858 |
}; |
| 859 |
status = smb2_getinfo_file(tree, tree, &finfo); |
| 860 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 861 |
"getinfo failed\n"); |
| 862 |
|
| 863 |
write_time = finfo.all_info.out.write_time; |
| 864 |
torture_assert_nttime_not_equal_goto(tctx, |
| 865 |
write_time, |
| 866 |
create_time, |
| 867 |
ret, done, |
| 868 |
"Writetime == create_time (wrong!)\n"); |
| 869 |
torture_comment(tctx, "Set timestamps\n"); |
| 870 |
|
| 871 |
setinfo->basic_info.in.file.handle = h1; |
| 872 |
status = smb2_setinfo_file(tree, setinfo); |
| 873 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 874 |
"close failed\n"); |
| 875 |
|
| 876 |
torture_comment(tctx, "Check timestamps\n"); |
| 877 |
|
| 878 |
finfo = (union smb_fileinfo) { |
| 879 |
.generic.level = RAW_FILEINFO_SMB2_ALL_INFORMATION, |
| 880 |
.generic.in.file.handle = h1, |
| 881 |
}; |
| 882 |
status = smb2_getinfo_file(tree, tree, &finfo); |
| 883 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 884 |
"getinfo failed\n"); |
| 885 |
|
| 886 |
torture_assert_nttime_equal_goto(tctx, |
| 887 |
finfo.all_info.out.write_time, |
| 888 |
write_time, |
| 889 |
ret, done, |
| 890 |
"Writetime changed\n"); |
| 891 |
|
| 892 |
status = smb2_util_close(tree, h1); |
| 893 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 894 |
"close failed\n"); |
| 895 |
ZERO_STRUCT(h1); |
| 896 |
|
| 897 |
status = smb2_util_unlink(tree, path); |
| 898 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 899 |
"close failed\n"); |
| 900 |
|
| 901 |
done: |
| 902 |
TALLOC_FREE(path); |
| 903 |
if (!smb2_util_handle_empty(h1)) { |
| 904 |
smb2_util_close(tree, h1); |
| 905 |
} |
| 906 |
return ret; |
| 907 |
} |
| 908 |
|
| 909 |
static bool test_delayed_write_vs_setbasic(struct torture_context *tctx, |
| 910 |
struct smb2_tree *tree) |
| 911 |
{ |
| 912 |
struct smb2_handle h1 = {{0}}; |
| 913 |
union smb_setfileinfo setinfo; |
| 914 |
time_t t = time(NULL) - 86400; |
| 915 |
NTSTATUS status; |
| 916 |
bool ret = true; |
| 917 |
|
| 918 |
smb2_deltree(tree, BASEDIR); |
| 919 |
status = torture_smb2_testdir(tree, BASEDIR, &h1); |
| 920 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 921 |
"create failed\n"); |
| 922 |
status = smb2_util_close(tree, h1); |
| 923 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 924 |
"close failed\n"); |
| 925 |
|
| 926 |
/* |
| 927 |
* As there are no delayed updated with modern write behaviour, |
| 928 |
* setting atime/ctime/btime doesn't trigger anything. |
| 929 |
*/ |
| 930 |
torture_comment(tctx, "Test: setting all-0 timestamps\n"); |
| 931 |
|
| 932 |
setinfo = (union smb_setfileinfo) { |
| 933 |
.generic.level = RAW_SFILEINFO_BASIC_INFORMATION, |
| 934 |
}; |
| 935 |
ret = test_delayed_write_vs_setbasic_do(tctx, tree, &setinfo); |
| 936 |
torture_assert_goto(tctx, ret, ret, done, "failed"); |
| 937 |
|
| 938 |
torture_comment(tctx, "Test: setting create_time flushes?\n"); |
| 939 |
unix_to_nt_time(&setinfo.basic_info.in.create_time, t); |
| 940 |
ret = test_delayed_write_vs_setbasic_do(tctx, tree, &setinfo); |
| 941 |
torture_assert_goto(tctx, ret, ret, done, "failed"); |
| 942 |
|
| 943 |
torture_comment(tctx, "Test: setting access_time flushes?\n"); |
| 944 |
setinfo.basic_info.in.create_time = 0; |
| 945 |
unix_to_nt_time(&setinfo.basic_info.in.access_time, t); |
| 946 |
ret = test_delayed_write_vs_setbasic_do(tctx, tree, &setinfo); |
| 947 |
torture_assert_goto(tctx, ret, ret, done, "failed"); |
| 948 |
|
| 949 |
torture_comment(tctx, "Test: setting change_time flushes?\n"); |
| 950 |
setinfo.basic_info.in.access_time = 0; |
| 951 |
unix_to_nt_time(&setinfo.basic_info.in.change_time, t); |
| 952 |
ret = test_delayed_write_vs_setbasic_do(tctx, tree, &setinfo); |
| 953 |
torture_assert_goto(tctx, ret, ret, done, "failed"); |
| 954 |
|
| 955 |
done: |
| 956 |
smb2_deltree(tree, BASEDIR); |
| 957 |
return ret; |
| 958 |
} |
| 959 |
|
| 960 |
static bool test_delayed_1write(struct torture_context *tctx, |
| 961 |
struct smb2_tree *tree) |
| 962 |
{ |
| 963 |
struct smb2_create cr; |
| 964 |
struct smb2_handle h1 = {{0}}; |
| 965 |
union smb_fileinfo finfo; |
| 966 |
struct smb2_close c; |
| 967 |
NTTIME create_time; |
| 968 |
NTTIME write_time; |
| 969 |
NTTIME close_time; |
| 970 |
NTSTATUS status; |
| 971 |
bool ret = true; |
| 972 |
|
| 973 |
smb2_deltree(tree, BASEDIR); |
| 974 |
status = torture_smb2_testdir(tree, BASEDIR, &h1); |
| 975 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 976 |
"create failed\n"); |
| 977 |
status = smb2_util_close(tree, h1); |
| 978 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 979 |
"close failed\n"); |
| 980 |
|
| 981 |
torture_comment(tctx, "Open file-handle 1\n"); |
| 982 |
|
| 983 |
cr = (struct smb2_create) { |
| 984 |
.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED, |
| 985 |
.in.create_disposition = NTCREATEX_DISP_OPEN_IF, |
| 986 |
.in.share_access = NTCREATEX_SHARE_ACCESS_MASK, |
| 987 |
.in.fname = BASEDIR "\\" FNAME, |
| 988 |
}; |
| 989 |
status = smb2_create(tree, tctx, &cr); |
| 990 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 991 |
"create failed\n"); |
| 992 |
h1 = cr.out.file.handle; |
| 993 |
create_time = cr.out.create_time; |
| 994 |
sleep(1); |
| 995 |
|
| 996 |
torture_comment(tctx, "Write to file-handle 1\n"); |
| 997 |
|
| 998 |
status = smb2_util_write(tree, h1, "s", 0, 1); |
| 999 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 1000 |
"write failed\n"); |
| 1001 |
sleep(3); |
| 1002 |
|
| 1003 |
torture_comment(tctx, "Check writetime has been updated\n"); |
| 1004 |
|
| 1005 |
finfo = (union smb_fileinfo) { |
| 1006 |
.generic.level = RAW_FILEINFO_SMB2_ALL_INFORMATION, |
| 1007 |
.generic.in.file.handle = h1, |
| 1008 |
}; |
| 1009 |
status = smb2_getinfo_file(tree, tree, &finfo); |
| 1010 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 1011 |
"getinfo failed\n"); |
| 1012 |
write_time = finfo.all_info.out.write_time; |
| 1013 |
|
| 1014 |
if (!(write_time > create_time)) { |
| 1015 |
ret = false; |
| 1016 |
torture_fail_goto(tctx, done, |
| 1017 |
"Write-time not updated (wrong!)\n"); |
| 1018 |
} |
| 1019 |
|
| 1020 |
torture_comment(tctx, "Close file-handle 1\n"); |
| 1021 |
sleep(1); |
| 1022 |
|
| 1023 |
c = (struct smb2_close) { |
| 1024 |
.in.file.handle = h1, |
| 1025 |
.in.flags = SMB2_CLOSE_FLAGS_FULL_INFORMATION, |
| 1026 |
}; |
| 1027 |
|
| 1028 |
status = smb2_close(tree, &c); |
| 1029 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 1030 |
"close failed\n"); |
| 1031 |
ZERO_STRUCT(h1); |
| 1032 |
close_time = c.out.write_time; |
| 1033 |
|
| 1034 |
torture_assert_nttime_equal(tctx, close_time, write_time, |
| 1035 |
"Writetime != close_time (wrong!)\n"); |
| 1036 |
|
| 1037 |
done: |
| 1038 |
if (!smb2_util_handle_empty(h1)) { |
| 1039 |
smb2_util_close(tree, h1); |
| 1040 |
} |
| 1041 |
smb2_deltree(tree, BASEDIR); |
| 1042 |
return ret; |
| 1043 |
} |
| 1044 |
|
| 1045 |
static bool test_delayed_2write(struct torture_context *tctx, |
| 1046 |
struct smb2_tree *tree) |
| 1047 |
{ |
| 1048 |
struct smb2_create cr; |
| 1049 |
struct smb2_handle h1 = {{0}}; |
| 1050 |
union smb_fileinfo finfo; |
| 1051 |
struct smb2_close c; |
| 1052 |
NTTIME create_time; |
| 1053 |
NTTIME write_time; |
| 1054 |
NTTIME write_time2; |
| 1055 |
NTTIME close_time; |
| 1056 |
NTSTATUS status; |
| 1057 |
bool ret = true; |
| 1058 |
|
| 1059 |
smb2_deltree(tree, BASEDIR); |
| 1060 |
status = torture_smb2_testdir(tree, BASEDIR, &h1); |
| 1061 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 1062 |
"create failed\n"); |
| 1063 |
status = smb2_util_close(tree, h1); |
| 1064 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 1065 |
"close failed\n"); |
| 1066 |
|
| 1067 |
torture_comment(tctx, "Open file\n"); |
| 1068 |
|
| 1069 |
cr = (struct smb2_create) { |
| 1070 |
.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED, |
| 1071 |
.in.create_disposition = NTCREATEX_DISP_OPEN_IF, |
| 1072 |
.in.share_access = NTCREATEX_SHARE_ACCESS_MASK, |
| 1073 |
.in.fname = BASEDIR "\\" FNAME, |
| 1074 |
}; |
| 1075 |
status = smb2_create(tree, tctx, &cr); |
| 1076 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 1077 |
"create failed\n"); |
| 1078 |
h1 = cr.out.file.handle; |
| 1079 |
create_time = cr.out.create_time; |
| 1080 |
sleep(1); |
| 1081 |
|
| 1082 |
torture_comment(tctx, "Write to file\n"); |
| 1083 |
|
| 1084 |
status = smb2_util_write(tree, h1, "s", 0, 1); |
| 1085 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 1086 |
"write failed\n"); |
| 1087 |
sleep(3); |
| 1088 |
|
| 1089 |
torture_comment(tctx, "Check writetime has been updated\n"); |
| 1090 |
|
| 1091 |
finfo = (union smb_fileinfo) { |
| 1092 |
.generic.level = RAW_FILEINFO_SMB2_ALL_INFORMATION, |
| 1093 |
.generic.in.file.handle = h1, |
| 1094 |
}; |
| 1095 |
status = smb2_getinfo_file(tree, tree, &finfo); |
| 1096 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 1097 |
"getinfo failed\n"); |
| 1098 |
write_time = finfo.all_info.out.write_time; |
| 1099 |
|
| 1100 |
if (!(write_time > create_time)) { |
| 1101 |
ret = false; |
| 1102 |
torture_fail_goto(tctx, done, |
| 1103 |
"Write-time not updated (wrong!)\n"); |
| 1104 |
} |
| 1105 |
|
| 1106 |
torture_comment(tctx, "Write a second time\n"); |
| 1107 |
|
| 1108 |
status = smb2_util_write(tree, h1, "s", 0, 1); |
| 1109 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 1110 |
"write failed\n"); |
| 1111 |
sleep(3); |
| 1112 |
|
| 1113 |
torture_comment(tctx, "Check writetime has also been updated\n"); |
| 1114 |
|
| 1115 |
finfo = (union smb_fileinfo) { |
| 1116 |
.generic.level = RAW_FILEINFO_SMB2_ALL_INFORMATION, |
| 1117 |
.generic.in.file.handle = h1, |
| 1118 |
}; |
| 1119 |
status = smb2_getinfo_file(tree, tree, &finfo); |
| 1120 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 1121 |
"getinfo failed\n"); |
| 1122 |
write_time2 = finfo.all_info.out.write_time; |
| 1123 |
|
| 1124 |
torture_assert_nttime_not_equal(tctx, write_time2, write_time, |
| 1125 |
"second write updated write-time (wrong!)\n"); |
| 1126 |
|
| 1127 |
torture_comment(tctx, "Close file-handle 1\n"); |
| 1128 |
sleep(2); |
| 1129 |
|
| 1130 |
torture_comment(tctx, "Check writetime has not been updated\n"); |
| 1131 |
|
| 1132 |
c = (struct smb2_close) { |
| 1133 |
.in.file.handle = h1, |
| 1134 |
.in.flags = SMB2_CLOSE_FLAGS_FULL_INFORMATION, |
| 1135 |
}; |
| 1136 |
|
| 1137 |
status = smb2_close(tree, &c); |
| 1138 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 1139 |
"close failed\n"); |
| 1140 |
ZERO_STRUCT(h1); |
| 1141 |
close_time = c.out.write_time; |
| 1142 |
|
| 1143 |
if (close_time != write_time2) { |
| 1144 |
ret = false; |
| 1145 |
torture_fail_goto(tctx, done, |
| 1146 |
"Write-time updated (wrong!)\n"); |
| 1147 |
} |
| 1148 |
|
| 1149 |
done: |
| 1150 |
if (!smb2_util_handle_empty(h1)) { |
| 1151 |
smb2_util_close(tree, h1); |
| 1152 |
} |
| 1153 |
smb2_deltree(tree, BASEDIR); |
| 1154 |
return ret; |
| 1155 |
} |
| 1156 |
|
| 1157 |
static bool getinfo_both(struct torture_context *tctx, |
| 1158 |
struct smb2_tree *tree, |
| 1159 |
struct smb2_handle *h1, |
| 1160 |
const char *p, |
| 1161 |
NTTIME *mtime, |
| 1162 |
NTTIME *ctime) |
| 1163 |
{ |
| 1164 |
union smb_fileinfo finfo; |
| 1165 |
union smb_fileinfo pinfo; |
| 1166 |
struct smb2_create cr; |
| 1167 |
struct smb2_handle h2 = {0}; |
| 1168 |
NTSTATUS status; |
| 1169 |
bool ret = true; |
| 1170 |
|
| 1171 |
if (h1 != NULL) { |
| 1172 |
finfo = (union smb_fileinfo) { |
| 1173 |
.generic.level = RAW_FILEINFO_SMB2_ALL_INFORMATION, |
| 1174 |
.generic.in.file.handle = *h1, |
| 1175 |
}; |
| 1176 |
status = smb2_getinfo_file(tree, tree, &finfo); |
| 1177 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 1178 |
"getinfo failed\n"); |
| 1179 |
} |
| 1180 |
|
| 1181 |
cr = (struct smb2_create) { |
| 1182 |
.in.desired_access = SEC_FILE_READ_ATTRIBUTE, |
| 1183 |
.in.share_access = NTCREATEX_SHARE_ACCESS_MASK, |
| 1184 |
.in.create_disposition = NTCREATEX_DISP_OPEN, |
| 1185 |
.in.fname = p, |
| 1186 |
}; |
| 1187 |
status = smb2_create(tree, tree, &cr); |
| 1188 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 1189 |
"create failed\n"); |
| 1190 |
h2 = cr.out.file.handle; |
| 1191 |
|
| 1192 |
pinfo = (union smb_fileinfo) { |
| 1193 |
.generic.level = RAW_FILEINFO_SMB2_ALL_INFORMATION, |
| 1194 |
.generic.in.file.handle = h2, |
| 1195 |
}; |
| 1196 |
status = smb2_getinfo_file(tree, tree, &pinfo); |
| 1197 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 1198 |
"getinfo failed\n"); |
| 1199 |
|
| 1200 |
status = smb2_util_close(tree, h2); |
| 1201 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 1202 |
"close failed\n"); |
| 1203 |
ZERO_STRUCT(h2); |
| 1204 |
|
| 1205 |
if (h1 != NULL) { |
| 1206 |
torture_assert_nttime_equal_goto(tctx, |
| 1207 |
finfo.all_info.out.write_time, |
| 1208 |
pinfo.all_info.out.write_time, |
| 1209 |
ret, done, |
| 1210 |
"times don't match"); |
| 1211 |
} |
| 1212 |
|
| 1213 |
*mtime = pinfo.all_info.out.write_time; |
| 1214 |
if (ctime != NULL) { |
| 1215 |
*ctime = pinfo.all_info.out.change_time; |
| 1216 |
} |
| 1217 |
|
| 1218 |
done: |
| 1219 |
if (!smb2_util_handle_empty(h2)) { |
| 1220 |
smb2_util_close(tree, h2); |
| 1221 |
} |
| 1222 |
return ret; |
| 1223 |
} |
| 1224 |
|
| 1225 |
/* |
| 1226 |
* | Time | Handle 1 | Handle 2 | |
| 1227 |
* |------+------------------------+------------------------| |
| 1228 |
* | 1 | Create file | Open file | |
| 1229 |
* | | Check Handle Time = 1 | Check Handle Time = 1 | |
| 1230 |
* | | Check Path Time = 1 | Check Path Time = 1 | |
| 1231 |
* | 2 | Write | | |
| 1232 |
* | 3 | Check Handle Time = 2 | Check Handle Time = 2 | |
| 1233 |
* | | Check Path Time = 2 | Check Path Time = 2 | |
| 1234 |
* | 4 | Set Sticky Time = 99 | | |
| 1235 |
* | 5 | Check Handle Time = 99 | Check Handle Time = 99 | |
| 1236 |
* | | Check Path Time = 99 | Check Path Time = 99 | |
| 1237 |
* | 6 | Write | | |
| 1238 |
* | 7 | Check Handle Time = 99 | Check Handle Time = 99 | |
| 1239 |
* | | Check Path Time = 99 | Check Path Time = 99 | |
| 1240 |
* | 8 | | Write | |
| 1241 |
* | 9 | Check Handle Time = 8 | Check Handle Time = 8 | |
| 1242 |
* | | Check Path Time = 8 | Check Path Time = 8 | |
| 1243 |
* | 10 | Write | | |
| 1244 |
* | 11 | Check Handle Time = 8 | Check Handle Time = 8 | |
| 1245 |
* | | Check Path Time = 8 | Check Path Time = 8 | |
| 1246 |
* | 12 | Close | Close | |
| 1247 |
* | 13 | Check Path Time = 8 | Check Path Time = 8 | |
| 1248 |
*/ |
| 1249 |
static bool test_modern_write_time_update1(struct torture_context *tctx, |
| 1250 |
struct smb2_tree *tree1, |
| 1251 |
struct smb2_tree *tree2) |
| 1252 |
{ |
| 1253 |
const char *fname = BASEDIR "\\test_modern_write_time_update1"; |
| 1254 |
struct smb2_create cr; |
| 1255 |
struct smb2_handle h1 = {}; |
| 1256 |
struct smb2_handle h2 = {}; |
| 1257 |
union smb_setfileinfo setinfo; |
| 1258 |
NTTIME lasttime, currenttime1, currenttime2; |
| 1259 |
time_t stickytime = time(NULL) + 86400; |
| 1260 |
NTTIME stickynttime; |
| 1261 |
NTSTATUS status; |
| 1262 |
bool ret = true; |
| 1263 |
|
| 1264 |
unix_to_nt_time(&stickynttime, stickytime); |
| 1265 |
|
| 1266 |
smb2_deltree(tree1, BASEDIR); |
| 1267 |
status = torture_smb2_testdir(tree1, BASEDIR, &h1); |
| 1268 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 1269 |
"create failed\n"); |
| 1270 |
status = smb2_util_close(tree1, h1); |
| 1271 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 1272 |
"close failed\n"); |
| 1273 |
|
| 1274 |
/* 1 */ |
| 1275 |
|
| 1276 |
smb2_generic_create(&cr, NULL, false, fname, |
| 1277 |
NTCREATEX_DISP_CREATE, |
| 1278 |
smb2_util_oplock_level(""), 0, 0); |
| 1279 |
status = smb2_create(tree1, tree1, &cr); |
| 1280 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 1281 |
"create failed\n"); |
| 1282 |
h1 = cr.out.file.handle; |
| 1283 |
|
| 1284 |
smb2_generic_create(&cr, NULL, false, fname, |
| 1285 |
NTCREATEX_DISP_OPEN, |
| 1286 |
smb2_util_oplock_level(""), 0, 0); |
| 1287 |
status = smb2_create(tree2, tree2, &cr); |
| 1288 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 1289 |
"create failed\n"); |
| 1290 |
h2 = cr.out.file.handle; |
| 1291 |
|
| 1292 |
ret = getinfo_both(tctx, tree1, &h1, fname, ¤ttime1, NULL); |
| 1293 |
torture_assert_goto(tctx, ret, ret, done, "getinfo_both failed"); |
| 1294 |
ret = getinfo_both(tctx, tree2, &h2, fname, ¤ttime2, NULL); |
| 1295 |
torture_assert_goto(tctx, ret, ret, done, "getinfo_both failed"); |
| 1296 |
torture_assert_nttime_equal_goto(tctx, currenttime1, currenttime2, |
| 1297 |
ret, done, "bad times"); |
| 1298 |
lasttime = currenttime1; |
| 1299 |
|
| 1300 |
/* 2 */ |
| 1301 |
|
| 1302 |
/* Bypass possible filesystem granularity */ |
| 1303 |
smb_msleep(20); |
| 1304 |
|
| 1305 |
status = smb2_util_write(tree1, h1, "1", 0, 1); |
| 1306 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 1307 |
"write failed\n"); |
| 1308 |
|
| 1309 |
/* 3 */ |
| 1310 |
|
| 1311 |
ret = getinfo_both(tctx, tree1, &h1, fname, ¤ttime1, NULL); |
| 1312 |
torture_assert_goto(tctx, ret, ret, done, "getinfo_both failed"); |
| 1313 |
ret = getinfo_both(tctx, tree2, &h2, fname, ¤ttime2, NULL); |
| 1314 |
torture_assert_goto(tctx, ret, ret, done, "getinfo_both failed"); |
| 1315 |
torture_assert_nttime_equal_goto(tctx, currenttime1, currenttime2, |
| 1316 |
ret, done, "bad times"); |
| 1317 |
|
| 1318 |
torture_assert_nttime_not_equal_goto(tctx, |
| 1319 |
currenttime1, |
| 1320 |
lasttime, |
| 1321 |
ret, done, |
| 1322 |
"bad time\n"); |
| 1323 |
lasttime = currenttime1; |
| 1324 |
|
| 1325 |
/* 4 */ |
| 1326 |
|
| 1327 |
setinfo = (union smb_setfileinfo) { |
| 1328 |
.generic.level = SMB_QFILEINFO_BASIC_INFORMATION, |
| 1329 |
}; |
| 1330 |
setinfo.basic_info.in.file.handle = h1; |
| 1331 |
setinfo.basic_info.in.write_time = stickynttime; |
| 1332 |
|
| 1333 |
status = smb2_setinfo_file(tree1, &setinfo); |
| 1334 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 1335 |
"smb2_setinfo_file failed\n"); |
| 1336 |
|
| 1337 |
/* 5 */ |
| 1338 |
|
| 1339 |
ret = getinfo_both(tctx, tree1, &h1, fname, ¤ttime1, NULL); |
| 1340 |
torture_assert_goto(tctx, ret, ret, done, "getinfo_both failed"); |
| 1341 |
ret = getinfo_both(tctx, tree2, &h2, fname, ¤ttime2, NULL); |
| 1342 |
torture_assert_goto(tctx, ret, ret, done, "getinfo_both failed"); |
| 1343 |
torture_assert_nttime_equal_goto(tctx, currenttime1, currenttime2, |
| 1344 |
ret, done, "bad times"); |
| 1345 |
|
| 1346 |
torture_assert_nttime_equal_goto(tctx, |
| 1347 |
currenttime1, |
| 1348 |
stickynttime, |
| 1349 |
ret, done, |
| 1350 |
"bad time\n"); |
| 1351 |
lasttime = currenttime1; |
| 1352 |
|
| 1353 |
/* 6 */ |
| 1354 |
|
| 1355 |
/* Bypass possible filesystem granularity */ |
| 1356 |
smb_msleep(20); |
| 1357 |
|
| 1358 |
status = smb2_util_write(tree1, h1, "1", 0, 1); |
| 1359 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 1360 |
"write failed\n"); |
| 1361 |
|
| 1362 |
/* 7 */ |
| 1363 |
|
| 1364 |
ret = getinfo_both(tctx, tree1, &h1, fname, ¤ttime1, NULL); |
| 1365 |
torture_assert_goto(tctx, ret, ret, done, "getinfo_both failed"); |
| 1366 |
ret = getinfo_both(tctx, tree2, &h2, fname, ¤ttime2, NULL); |
| 1367 |
torture_assert_goto(tctx, ret, ret, done, "getinfo_both failed"); |
| 1368 |
torture_assert_nttime_equal_goto(tctx, currenttime1, currenttime2, |
| 1369 |
ret, done, "bad times"); |
| 1370 |
|
| 1371 |
torture_assert_nttime_equal_goto(tctx, |
| 1372 |
currenttime1, |
| 1373 |
stickynttime, |
| 1374 |
ret, done, |
| 1375 |
"bad time\n"); |
| 1376 |
|
| 1377 |
/* 8 */ |
| 1378 |
|
| 1379 |
/* Bypass possible filesystem granularity */ |
| 1380 |
smb_msleep(20); |
| 1381 |
|
| 1382 |
status = smb2_util_write(tree2, h2, "1", 0, 1); |
| 1383 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 1384 |
"write failed\n"); |
| 1385 |
|
| 1386 |
/* 9 */ |
| 1387 |
|
| 1388 |
ret = getinfo_both(tctx, tree1, &h1, fname, ¤ttime1, NULL); |
| 1389 |
torture_assert_goto(tctx, ret, ret, done, "getinfo_both failed"); |
| 1390 |
ret = getinfo_both(tctx, tree2, &h2, fname, ¤ttime2, NULL); |
| 1391 |
torture_assert_goto(tctx, ret, ret, done, "getinfo_both failed"); |
| 1392 |
torture_assert_nttime_equal_goto(tctx, currenttime1, currenttime2, |
| 1393 |
ret, done, "bad times"); |
| 1394 |
|
| 1395 |
torture_assert_nttime_not_equal_goto(tctx, |
| 1396 |
currenttime1, |
| 1397 |
stickynttime, |
| 1398 |
ret, done, |
| 1399 |
"bad time\n"); |
| 1400 |
lasttime = currenttime1; |
| 1401 |
|
| 1402 |
/* 10 */ |
| 1403 |
|
| 1404 |
/* Bypass possible filesystem granularity */ |
| 1405 |
smb_msleep(20); |
| 1406 |
|
| 1407 |
status = smb2_util_write(tree1, h1, "1", 0, 1); |
| 1408 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 1409 |
"write failed\n"); |
| 1410 |
|
| 1411 |
/* 11 */ |
| 1412 |
|
| 1413 |
ret = getinfo_both(tctx, tree1, &h1, fname, ¤ttime1, NULL); |
| 1414 |
torture_assert_goto(tctx, ret, ret, done, "getinfo_both failed"); |
| 1415 |
ret = getinfo_both(tctx, tree2, &h2, fname, ¤ttime2, NULL); |
| 1416 |
torture_assert_goto(tctx, ret, ret, done, "getinfo_both failed"); |
| 1417 |
torture_assert_nttime_equal_goto(tctx, currenttime1, currenttime2, |
| 1418 |
ret, done, "bad times"); |
| 1419 |
|
| 1420 |
torture_assert_nttime_equal_goto(tctx, |
| 1421 |
currenttime1, |
| 1422 |
lasttime, |
| 1423 |
ret, done, |
| 1424 |
"bad time\n"); |
| 1425 |
|
| 1426 |
/* 12 */ |
| 1427 |
|
| 1428 |
status = smb2_util_close(tree1, h1); |
| 1429 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 1430 |
"close failed\n"); |
| 1431 |
status = smb2_util_close(tree2, h2); |
| 1432 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 1433 |
"close failed\n"); |
| 1434 |
|
| 1435 |
/* 13 */ |
| 1436 |
|
| 1437 |
ret = getinfo_both(tctx, tree1, NULL, fname, ¤ttime1, NULL); |
| 1438 |
torture_assert_goto(tctx, ret, ret, done, "getinfo_both failed"); |
| 1439 |
ret = getinfo_both(tctx, tree2, NULL, fname, ¤ttime2, NULL); |
| 1440 |
torture_assert_goto(tctx, ret, ret, done, "getinfo_both failed"); |
| 1441 |
torture_assert_nttime_equal_goto(tctx, currenttime1, currenttime2, |
| 1442 |
ret, done, "bad times"); |
| 1443 |
|
| 1444 |
torture_assert_nttime_equal_goto(tctx, |
| 1445 |
currenttime1, |
| 1446 |
lasttime, |
| 1447 |
ret, done, |
| 1448 |
"bad time\n"); |
| 1449 |
|
| 1450 |
done: |
| 1451 |
if (!smb2_util_handle_empty(h1)) { |
| 1452 |
smb2_util_close(tree1, h1); |
| 1453 |
} |
| 1454 |
if (!smb2_util_handle_empty(h2)) { |
| 1455 |
smb2_util_close(tree2, h2); |
| 1456 |
} |
| 1457 |
smb2_deltree(tree1, BASEDIR); |
| 1458 |
return ret; |
| 1459 |
} |
| 1460 |
|
| 1461 |
|
| 1462 |
/* |
| 1463 |
* Test setting filesize and allocation info vs sticky mtime |
| 1464 |
* |
| 1465 |
* | Time | Handle 1 | Handle 2 | |
| 1466 |
* |------+------------------------+------------------------| |
| 1467 |
* | 1 | Create file | Open file | |
| 1468 |
* | | Check Handle Time = 1 | Check Handle Time = 1 | |
| 1469 |
* | | Check Path Time = 1 | Check Path Time = 1 | |
| 1470 |
* | 2 | Set Filesize 0 | | |
| 1471 |
* | 3 | Check Handle Time = 2 | Check Handle Time = 2 | |
| 1472 |
* | | Check Path Time = 2 | Check Path Time = 2 | |
| 1473 |
* | 4 | Set Allocation Size = 0| | |
| 1474 |
* | 5 | Check Handle Time = 4 | Check Handle Time = 4 | |
| 1475 |
* | | Check Path Time = 4 | Check Path Time = 4 | |
| 1476 |
* | 6 | Set Filesize 1 | | |
| 1477 |
* | 7 | Check Handle Time = 6 | Check Handle Time = 6 | |
| 1478 |
* | | Check Path Time = 6 | Check Path Time = 6 | |
| 1479 |
* | 8 | Set Allocation Size = 4096| | |
| 1480 |
* | 9 | Check Handle Time = 8 | Check Handle Time = 8 | |
| 1481 |
* | | Check Path Time = 8 | Check Path Time = 8 | |
| 1482 |
* | 10 | Set Sticky Time = 99 | | |
| 1483 |
* | 11 | Check Handle Time = 99 | Check Handle Time = 99 | |
| 1484 |
* | | Check Path Time = 99 | Check Path Time = 99 | |
| 1485 |
* | 12 | Set Filesize | | |
| 1486 |
* | 13 | Check Handle Time = 99 | Check Handle Time = 99 | |
| 1487 |
* | | Check Path Time = 99 | Check Path Time = 99 | |
| 1488 |
* | 14 | Set Allocation Size | | |
| 1489 |
* | 15 | Check Handle Time = 99 | Check Handle Time = 99 | |
| 1490 |
* | | Check Path Time = 99 | Check Path Time = 99 | |
| 1491 |
* | 16 | | Set Filesize | |
| 1492 |
* | 17 | Check Handle Time = 16 | Check Handle Time = 16 | |
| 1493 |
* | | Check Path Time = 16 | Check Path Time = 16 | |
| 1494 |
* | 18 | | Set Allocation Size | |
| 1495 |
* | 19 | Check Handle Time = 18 | Check Handle Time = 18 | |
| 1496 |
* | | Check Path Time = 18 | Check Path Time = 18 | |
| 1497 |
* | 20 | | Shrink Allocation Size | |
| 1498 |
* | 21 | Check Handle Time = 20 | Check Handle Time = 20 | |
| 1499 |
* | | Check Path Time = 20 | Check Path Time = 20 | |
| 1500 |
* | 22 | Close | Close | |
| 1501 |
* | 23 | Check Path Time = 20 | Check Path Time = 20 | |
| 1502 |
*/ |
| 1503 |
static bool test_modern_write_time_update2(struct torture_context *tctx, |
| 1504 |
struct smb2_tree *tree1, |
| 1505 |
struct smb2_tree *tree2) |
| 1506 |
{ |
| 1507 |
const char *fname = BASEDIR "\\test_modern_write_time_update2"; |
| 1508 |
struct smb2_create cr; |
| 1509 |
struct smb2_handle h1 = {}; |
| 1510 |
struct smb2_handle h2 = {}; |
| 1511 |
union smb_setfileinfo basicinfo; |
| 1512 |
union smb_setfileinfo eofinfo; |
| 1513 |
union smb_setfileinfo allocinfo; |
| 1514 |
NTTIME lasttime, currenttime1, currenttime2, ctime1, ctime2; |
| 1515 |
off_t size = 0; |
| 1516 |
size_t alloccount = 0; |
| 1517 |
off_t allocsize = 4096; |
| 1518 |
time_t stickytime = time(NULL) + 86400; |
| 1519 |
NTTIME stickynttime; |
| 1520 |
NTSTATUS status; |
| 1521 |
bool ret = true; |
| 1522 |
|
| 1523 |
unix_to_nt_time(&stickynttime, stickytime); |
| 1524 |
basicinfo = (union smb_setfileinfo) { |
| 1525 |
.generic.level = SMB_SFILEINFO_BASIC_INFORMATION, |
| 1526 |
}; |
| 1527 |
eofinfo = (union smb_setfileinfo) { |
| 1528 |
.generic.level = SMB_SFILEINFO_END_OF_FILE_INFORMATION, |
| 1529 |
}; |
| 1530 |
allocinfo = (union smb_setfileinfo) { |
| 1531 |
.generic.level = SMB_SFILEINFO_ALLOCATION_INFORMATION, |
| 1532 |
}; |
| 1533 |
|
| 1534 |
smb2_deltree(tree1, BASEDIR); |
| 1535 |
status = torture_smb2_testdir(tree1, BASEDIR, &h1); |
| 1536 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 1537 |
"create failed\n"); |
| 1538 |
status = smb2_util_close(tree1, h1); |
| 1539 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 1540 |
"close failed\n"); |
| 1541 |
|
| 1542 |
/* 1 */ |
| 1543 |
|
| 1544 |
smb2_generic_create(&cr, NULL, false, fname, |
| 1545 |
NTCREATEX_DISP_CREATE, |
| 1546 |
smb2_util_oplock_level(""), 0, 0); |
| 1547 |
status = smb2_create(tree1, tree1, &cr); |
| 1548 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 1549 |
"create failed\n"); |
| 1550 |
h1 = cr.out.file.handle; |
| 1551 |
|
| 1552 |
smb2_generic_create(&cr, NULL, false, fname, |
| 1553 |
NTCREATEX_DISP_OPEN, |
| 1554 |
smb2_util_oplock_level(""), 0, 0); |
| 1555 |
status = smb2_create(tree2, tree2, &cr); |
| 1556 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 1557 |
"create failed\n"); |
| 1558 |
h2 = cr.out.file.handle; |
| 1559 |
|
| 1560 |
ret = getinfo_both(tctx, tree1, &h1, fname, ¤ttime1, NULL); |
| 1561 |
torture_assert_goto(tctx, ret, ret, done, "getinfo_both failed"); |
| 1562 |
ret = getinfo_both(tctx, tree2, &h2, fname, ¤ttime2, NULL); |
| 1563 |
torture_assert_goto(tctx, ret, ret, done, "getinfo_both failed"); |
| 1564 |
torture_assert_nttime_equal_goto(tctx, currenttime1, currenttime2, |
| 1565 |
ret, done, "bad times"); |
| 1566 |
lasttime = currenttime1; |
| 1567 |
|
| 1568 |
/* 2: same size */ |
| 1569 |
|
| 1570 |
/* Bypass possible filesystem granularity */ |
| 1571 |
smb_msleep(20); |
| 1572 |
|
| 1573 |
eofinfo.end_of_file_info.in.file.handle = h1; |
| 1574 |
eofinfo.end_of_file_info.in.size = size; |
| 1575 |
|
| 1576 |
status = smb2_setinfo_file(tree1, &eofinfo); |
| 1577 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 1578 |
"smb2_setinfo_file failed\n"); |
| 1579 |
|
| 1580 |
/* 3 */ |
| 1581 |
|
| 1582 |
ret = getinfo_both(tctx, tree1, &h1, fname, ¤ttime1, NULL); |
| 1583 |
torture_assert_goto(tctx, ret, ret, done, "getinfo_both failed"); |
| 1584 |
ret = getinfo_both(tctx, tree2, &h2, fname, ¤ttime2, NULL); |
| 1585 |
torture_assert_goto(tctx, ret, ret, done, "getinfo_both failed"); |
| 1586 |
torture_assert_nttime_equal_goto(tctx, currenttime1, currenttime2, |
| 1587 |
ret, done, "bad times"); |
| 1588 |
|
| 1589 |
torture_assert_nttime_not_equal_goto(tctx, |
| 1590 |
currenttime1, |
| 1591 |
lasttime, |
| 1592 |
ret, done, |
| 1593 |
"bad time\n"); |
| 1594 |
lasttime = currenttime1; |
| 1595 |
|
| 1596 |
/* 4: same size */ |
| 1597 |
|
| 1598 |
/* Bypass possible filesystem granularity */ |
| 1599 |
smb_msleep(20); |
| 1600 |
|
| 1601 |
allocinfo.allocation_info.in.file.handle = h1; |
| 1602 |
allocinfo.allocation_info.in.alloc_size = 0; |
| 1603 |
|
| 1604 |
status = smb2_setinfo_file(tree1, &allocinfo); |
| 1605 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 1606 |
"smb2_setinfo_file failed\n"); |
| 1607 |
|
| 1608 |
/* 5 */ |
| 1609 |
|
| 1610 |
ret = getinfo_both(tctx, tree1, &h1, fname, ¤ttime1, &ctime1); |
| 1611 |
torture_assert_goto(tctx, ret, ret, done, "getinfo_both failed"); |
| 1612 |
ret = getinfo_both(tctx, tree2, &h2, fname, ¤ttime2, &ctime2); |
| 1613 |
torture_assert_goto(tctx, ret, ret, done, "getinfo_both failed"); |
| 1614 |
torture_assert_nttime_equal_goto(tctx, currenttime1, currenttime2, |
| 1615 |
ret, done, "bad times"); |
| 1616 |
torture_assert_nttime_equal_goto(tctx, ctime1, ctime2, |
| 1617 |
ret, done, "bad times"); |
| 1618 |
|
| 1619 |
torture_assert_nttime_equal_goto(tctx, |
| 1620 |
currenttime1, |
| 1621 |
lasttime, |
| 1622 |
ret, done, |
| 1623 |
"bad time\n"); |
| 1624 |
torture_assert_nttime_not_equal_goto(tctx, |
| 1625 |
ctime1, |
| 1626 |
lasttime, |
| 1627 |
ret, done, |
| 1628 |
"bad time\n"); |
| 1629 |
lasttime = currenttime1; |
| 1630 |
|
| 1631 |
/* 6: grow size */ |
| 1632 |
|
| 1633 |
/* Bypass possible filesystem granularity */ |
| 1634 |
smb_msleep(20); |
| 1635 |
|
| 1636 |
eofinfo.end_of_file_info.in.file.handle = h1; |
| 1637 |
eofinfo.end_of_file_info.in.size = ++size; |
| 1638 |
|
| 1639 |
status = smb2_setinfo_file(tree1, &eofinfo); |
| 1640 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 1641 |
"smb2_setinfo_file failed\n"); |
| 1642 |
|
| 1643 |
/* 7 */ |
| 1644 |
|
| 1645 |
ret = getinfo_both(tctx, tree1, &h1, fname, ¤ttime1, NULL); |
| 1646 |
torture_assert_goto(tctx, ret, ret, done, "getinfo_both failed"); |
| 1647 |
ret = getinfo_both(tctx, tree2, &h2, fname, ¤ttime2, NULL); |
| 1648 |
torture_assert_goto(tctx, ret, ret, done, "getinfo_both failed"); |
| 1649 |
torture_assert_nttime_equal_goto(tctx, currenttime1, currenttime2, |
| 1650 |
ret, done, "bad times"); |
| 1651 |
|
| 1652 |
torture_assert_nttime_not_equal_goto(tctx, |
| 1653 |
currenttime1, |
| 1654 |
lasttime, |
| 1655 |
ret, done, |
| 1656 |
"bad time\n"); |
| 1657 |
lasttime = currenttime1; |
| 1658 |
|
| 1659 |
/* 8: grow size */ |
| 1660 |
|
| 1661 |
/* Bypass possible filesystem granularity */ |
| 1662 |
smb_msleep(20); |
| 1663 |
|
| 1664 |
allocinfo.allocation_info.in.file.handle = h1; |
| 1665 |
allocinfo.allocation_info.in.alloc_size = ++alloccount * allocsize; |
| 1666 |
|
| 1667 |
status = smb2_setinfo_file(tree1, &allocinfo); |
| 1668 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 1669 |
"smb2_setinfo_file failed\n"); |
| 1670 |
|
| 1671 |
/* 9 */ |
| 1672 |
|
| 1673 |
ret = getinfo_both(tctx, tree1, &h1, fname, ¤ttime1, &ctime1); |
| 1674 |
torture_assert_goto(tctx, ret, ret, done, "getinfo_both failed"); |
| 1675 |
ret = getinfo_both(tctx, tree2, &h2, fname, ¤ttime2, &ctime2); |
| 1676 |
torture_assert_goto(tctx, ret, ret, done, "getinfo_both failed"); |
| 1677 |
torture_assert_nttime_equal_goto(tctx, currenttime1, currenttime2, |
| 1678 |
ret, done, "bad times"); |
| 1679 |
torture_assert_nttime_equal_goto(tctx, ctime1, ctime2, |
| 1680 |
ret, done, "bad times"); |
| 1681 |
|
| 1682 |
torture_assert_nttime_equal_goto(tctx, |
| 1683 |
currenttime1, |
| 1684 |
lasttime, |
| 1685 |
ret, done, |
| 1686 |
"bad time\n"); |
| 1687 |
torture_assert_nttime_not_equal_goto(tctx, |
| 1688 |
ctime1, |
| 1689 |
lasttime, |
| 1690 |
ret, done, |
| 1691 |
"bad time\n"); |
| 1692 |
lasttime = currenttime1; |
| 1693 |
|
| 1694 |
/* 10 */ |
| 1695 |
|
| 1696 |
basicinfo.basic_info.in.file.handle = h1; |
| 1697 |
basicinfo.basic_info.in.write_time = stickynttime; |
| 1698 |
|
| 1699 |
status = smb2_setinfo_file(tree1, &basicinfo); |
| 1700 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 1701 |
"smb2_setinfo_file failed\n"); |
| 1702 |
|
| 1703 |
/* 11 */ |
| 1704 |
|
| 1705 |
ret = getinfo_both(tctx, tree1, &h1, fname, ¤ttime1, NULL); |
| 1706 |
torture_assert_goto(tctx, ret, ret, done, "getinfo_both failed"); |
| 1707 |
ret = getinfo_both(tctx, tree2, &h2, fname, ¤ttime2, NULL); |
| 1708 |
torture_assert_goto(tctx, ret, ret, done, "getinfo_both failed"); |
| 1709 |
torture_assert_nttime_equal_goto(tctx, currenttime1, currenttime2, |
| 1710 |
ret, done, "bad times"); |
| 1711 |
|
| 1712 |
torture_assert_nttime_equal_goto(tctx, |
| 1713 |
currenttime1, |
| 1714 |
stickynttime, |
| 1715 |
ret, done, |
| 1716 |
"bad time\n"); |
| 1717 |
lasttime = currenttime1; |
| 1718 |
|
| 1719 |
/* 12 */ |
| 1720 |
|
| 1721 |
/* Bypass possible filesystem granularity */ |
| 1722 |
smb_msleep(20); |
| 1723 |
|
| 1724 |
eofinfo.end_of_file_info.in.file.handle = h1; |
| 1725 |
eofinfo.end_of_file_info.in.size = ++size; |
| 1726 |
|
| 1727 |
status = smb2_setinfo_file(tree1, &eofinfo); |
| 1728 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 1729 |
"smb2_setinfo_file failed\n"); |
| 1730 |
|
| 1731 |
/* 13 */ |
| 1732 |
|
| 1733 |
ret = getinfo_both(tctx, tree1, &h1, fname, ¤ttime1, NULL); |
| 1734 |
torture_assert_goto(tctx, ret, ret, done, "getinfo_both failed"); |
| 1735 |
ret = getinfo_both(tctx, tree2, &h2, fname, ¤ttime2, NULL); |
| 1736 |
torture_assert_goto(tctx, ret, ret, done, "getinfo_both failed"); |
| 1737 |
torture_assert_nttime_equal_goto(tctx, currenttime1, currenttime2, |
| 1738 |
ret, done, "bad times"); |
| 1739 |
|
| 1740 |
torture_assert_nttime_equal_goto(tctx, |
| 1741 |
currenttime1, |
| 1742 |
stickynttime, |
| 1743 |
ret, done, |
| 1744 |
"bad time\n"); |
| 1745 |
|
| 1746 |
/* 14 */ |
| 1747 |
|
| 1748 |
/* Bypass possible filesystem granularity */ |
| 1749 |
smb_msleep(20); |
| 1750 |
|
| 1751 |
allocinfo.allocation_info.in.file.handle = h1; |
| 1752 |
allocinfo.allocation_info.in.alloc_size = ++alloccount * allocsize; |
| 1753 |
|
| 1754 |
status = smb2_setinfo_file(tree1, &allocinfo); |
| 1755 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 1756 |
"smb2_setinfo_file failed\n"); |
| 1757 |
|
| 1758 |
/* 15 */ |
| 1759 |
|
| 1760 |
ret = getinfo_both(tctx, tree1, &h1, fname, ¤ttime1, NULL); |
| 1761 |
torture_assert_goto(tctx, ret, ret, done, "getinfo_both failed"); |
| 1762 |
ret = getinfo_both(tctx, tree2, &h2, fname, ¤ttime2, NULL); |
| 1763 |
torture_assert_goto(tctx, ret, ret, done, "getinfo_both failed"); |
| 1764 |
torture_assert_nttime_equal_goto(tctx, currenttime1, currenttime2, |
| 1765 |
ret, done, "bad times"); |
| 1766 |
|
| 1767 |
torture_assert_nttime_equal_goto(tctx, |
| 1768 |
currenttime1, |
| 1769 |
stickynttime, |
| 1770 |
ret, done, |
| 1771 |
"bad time\n"); |
| 1772 |
|
| 1773 |
/* 16 */ |
| 1774 |
|
| 1775 |
/* Bypass possible filesystem granularity */ |
| 1776 |
smb_msleep(20); |
| 1777 |
|
| 1778 |
eofinfo.end_of_file_info.in.file.handle = h2; |
| 1779 |
eofinfo.end_of_file_info.in.size = ++size; |
| 1780 |
|
| 1781 |
status = smb2_setinfo_file(tree2, &eofinfo); |
| 1782 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 1783 |
"smb2_setinfo_file failed\n"); |
| 1784 |
|
| 1785 |
/* 17 */ |
| 1786 |
|
| 1787 |
ret = getinfo_both(tctx, tree1, &h1, fname, ¤ttime1, NULL); |
| 1788 |
torture_assert_goto(tctx, ret, ret, done, "getinfo_both failed"); |
| 1789 |
ret = getinfo_both(tctx, tree2, &h2, fname, ¤ttime2, NULL); |
| 1790 |
torture_assert_goto(tctx, ret, ret, done, "getinfo_both failed"); |
| 1791 |
torture_assert_nttime_equal_goto(tctx, currenttime1, currenttime2, |
| 1792 |
ret, done, "bad times"); |
| 1793 |
|
| 1794 |
torture_assert_nttime_not_equal_goto(tctx, |
| 1795 |
currenttime1, |
| 1796 |
stickynttime, |
| 1797 |
ret, done, |
| 1798 |
"bad time\n"); |
| 1799 |
lasttime = currenttime1; |
| 1800 |
|
| 1801 |
/* 18 */ |
| 1802 |
|
| 1803 |
/* Bypass possible filesystem granularity */ |
| 1804 |
smb_msleep(20); |
| 1805 |
|
| 1806 |
allocinfo.allocation_info.in.file.handle = h2; |
| 1807 |
allocinfo.allocation_info.in.alloc_size = ++alloccount * allocsize; |
| 1808 |
|
| 1809 |
status = smb2_setinfo_file(tree2, &allocinfo); |
| 1810 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 1811 |
"smb2_setinfo_file failed\n"); |
| 1812 |
|
| 1813 |
/* 19 */ |
| 1814 |
|
| 1815 |
ret = getinfo_both(tctx, tree1, &h1, fname, ¤ttime1, &ctime1); |
| 1816 |
torture_assert_goto(tctx, ret, ret, done, "getinfo_both failed"); |
| 1817 |
ret = getinfo_both(tctx, tree2, &h2, fname, ¤ttime2, &ctime2); |
| 1818 |
torture_assert_goto(tctx, ret, ret, done, "getinfo_both failed"); |
| 1819 |
torture_assert_nttime_equal_goto(tctx, currenttime1, currenttime2, |
| 1820 |
ret, done, "bad times"); |
| 1821 |
torture_assert_nttime_equal_goto(tctx, ctime1, ctime2, |
| 1822 |
ret, done, "bad times"); |
| 1823 |
|
| 1824 |
torture_assert_nttime_equal_goto(tctx, |
| 1825 |
currenttime1, |
| 1826 |
lasttime, |
| 1827 |
ret, done, |
| 1828 |
"bad time\n"); |
| 1829 |
torture_assert_nttime_not_equal_goto(tctx, |
| 1830 |
ctime1, |
| 1831 |
lasttime, |
| 1832 |
ret, done, |
| 1833 |
"bad time\n"); |
| 1834 |
lasttime = currenttime1; |
| 1835 |
|
| 1836 |
/* 20: shrink allocation size, should update mtime+ctime */ |
| 1837 |
|
| 1838 |
/* Bypass possible filesystem granularity */ |
| 1839 |
smb_msleep(20); |
| 1840 |
|
| 1841 |
allocinfo.allocation_info.in.file.handle = h2; |
| 1842 |
allocinfo.allocation_info.in.alloc_size = 0; |
| 1843 |
|
| 1844 |
status = smb2_setinfo_file(tree2, &allocinfo); |
| 1845 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 1846 |
"smb2_setinfo_file failed\n"); |
| 1847 |
|
| 1848 |
/* 21 */ |
| 1849 |
|
| 1850 |
ret = getinfo_both(tctx, tree1, &h1, fname, ¤ttime1, &ctime1); |
| 1851 |
torture_assert_goto(tctx, ret, ret, done, "getinfo_both failed"); |
| 1852 |
ret = getinfo_both(tctx, tree2, &h2, fname, ¤ttime2, &ctime2); |
| 1853 |
torture_assert_goto(tctx, ret, ret, done, "getinfo_both failed"); |
| 1854 |
torture_assert_nttime_equal_goto(tctx, currenttime1, currenttime2, |
| 1855 |
ret, done, "bad times"); |
| 1856 |
torture_assert_nttime_equal_goto(tctx, ctime1, ctime2, |
| 1857 |
ret, done, "bad times"); |
| 1858 |
|
| 1859 |
torture_assert_nttime_not_equal_goto(tctx, |
| 1860 |
currenttime1, |
| 1861 |
lasttime, |
| 1862 |
ret, done, |
| 1863 |
"bad time\n"); |
| 1864 |
torture_assert_nttime_not_equal_goto(tctx, |
| 1865 |
ctime1, |
| 1866 |
lasttime, |
| 1867 |
ret, done, |
| 1868 |
"bad time\n"); |
| 1869 |
lasttime = currenttime1; |
| 1870 |
|
| 1871 |
/* 22 */ |
| 1872 |
|
| 1873 |
status = smb2_util_close(tree1, h1); |
| 1874 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 1875 |
"close failed\n"); |
| 1876 |
status = smb2_util_close(tree2, h2); |
| 1877 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 1878 |
"close failed\n"); |
| 1879 |
|
| 1880 |
/* 23 */ |
| 1881 |
|
| 1882 |
ret = getinfo_both(tctx, tree1, NULL, fname, ¤ttime1, NULL); |
| 1883 |
torture_assert_goto(tctx, ret, ret, done, "getinfo_both failed"); |
| 1884 |
ret = getinfo_both(tctx, tree2, NULL, fname, ¤ttime2, NULL); |
| 1885 |
torture_assert_goto(tctx, ret, ret, done, "getinfo_both failed"); |
| 1886 |
torture_assert_nttime_equal_goto(tctx, currenttime1, currenttime2, |
| 1887 |
ret, done, "bad times"); |
| 1888 |
|
| 1889 |
torture_assert_nttime_equal_goto(tctx, |
| 1890 |
currenttime1, |
| 1891 |
lasttime, |
| 1892 |
ret, done, |
| 1893 |
"bad time\n"); |
| 1894 |
|
| 1895 |
done: |
| 1896 |
if (!smb2_util_handle_empty(h1)) { |
| 1897 |
smb2_util_close(tree1, h1); |
| 1898 |
} |
| 1899 |
if (!smb2_util_handle_empty(h2)) { |
| 1900 |
smb2_util_close(tree2, h2); |
| 1901 |
} |
| 1902 |
smb2_deltree(tree1, BASEDIR); |
| 1903 |
return ret; |
| 1904 |
} |
| 1905 |
|
| 1906 |
/* |
| 1907 |
basic testing of SMB2 timestamps |
| 1908 |
*/ |
| 1909 |
struct torture_suite *torture_smb2_timestamps_init(TALLOC_CTX *ctx) |
| 1910 |
{ |
| 1911 |
struct torture_suite *suite = torture_suite_create(ctx, "timestamps"); |
| 1912 |
|
| 1913 |
torture_suite_add_1smb2_test(suite, "test_close_not_attrib", test_close_no_attrib); |
| 1914 |
torture_suite_add_1smb2_test(suite, "time_t_15032385535", test_time_t_15032385535); |
| 1915 |
torture_suite_add_1smb2_test(suite, "time_t_10000000000", test_time_t_10000000000); |
| 1916 |
torture_suite_add_1smb2_test(suite, "time_t_4294967295", test_time_t_4294967295); |
| 1917 |
torture_suite_add_1smb2_test(suite, "time_t_1", test_time_t_1); |
| 1918 |
torture_suite_add_1smb2_test(suite, "time_t_0", test_time_t_0); |
| 1919 |
torture_suite_add_1smb2_test(suite, "time_t_-1", test_time_t_minus_1); |
| 1920 |
torture_suite_add_1smb2_test(suite, "time_t_-2", test_time_t_minus_2); |
| 1921 |
torture_suite_add_1smb2_test(suite, "time_t_1968", test_time_t_1968); |
| 1922 |
torture_suite_add_1smb2_test(suite, "freeze-thaw", test_freeze_thaw); |
| 1923 |
|
| 1924 |
/* |
| 1925 |
* Testing of delayed write-time updates |
| 1926 |
*/ |
| 1927 |
torture_suite_add_1smb2_test(suite, "delayed-write-vs-seteof", test_delayed_write_vs_seteof); |
| 1928 |
torture_suite_add_1smb2_test(suite, "delayed-write-vs-flush", test_delayed_write_vs_flush); |
| 1929 |
torture_suite_add_1smb2_test(suite, "delayed-write-vs-setbasic", test_delayed_write_vs_setbasic); |
| 1930 |
torture_suite_add_1smb2_test(suite, "delayed-1write", test_delayed_1write); |
| 1931 |
torture_suite_add_1smb2_test(suite, "delayed-2write", test_delayed_2write); |
| 1932 |
torture_suite_add_2smb2_test(suite, "modern_write_time_update-1", test_modern_write_time_update1); |
| 1933 |
torture_suite_add_2smb2_test(suite, "modern_write_time_update-2", test_modern_write_time_update2); |
| 1934 |
|
| 1935 |
suite->description = talloc_strdup(suite, "SMB2 timestamp tests"); |
| 1936 |
|
| 1937 |
return suite; |
| 1938 |
} |
| 1939 |
|
| 1940 |
/* |
| 1941 |
* This test shows that Windows has a timestamp resolution of ~15ms. When so |
| 1942 |
* when a smaller amount of time than that has passed it's not necessarily |
| 1943 |
* detectable on a Windows 2019 and newer who implement immediate timestamp |
| 1944 |
* updates. |
| 1945 |
* |
| 1946 |
* Note that this test relies on a low latency SMB connection. Even with a low |
| 1947 |
* latency connection of eg 1m there's a chance of 1/15 that the first part of |
| 1948 |
* the test expecting no timestamp change fails as the writetime is updated. |
| 1949 |
* |
| 1950 |
* Due to this timing dependency this test is skipped in Samba CI, but it is |
| 1951 |
* preserved here for future SMB2 timestamps behaviour archealogists. |
| 1952 |
* |
| 1953 |
* See also: https://lists.samba.org/archive/cifs-protocol/2019-December/003358.html |
| 1954 |
*/ |
| 1955 |
static bool test_timestamp_resolution1(struct torture_context *tctx, |
| 1956 |
struct smb2_tree *tree) |
| 1957 |
{ |
| 1958 |
union smb_fileinfo finfo1; |
| 1959 |
const char *fname = BASEDIR "\\" FNAME; |
| 1960 |
struct smb2_create cr; |
| 1961 |
struct smb2_handle h = {{0}}; |
| 1962 |
struct smb2_close cl; |
| 1963 |
NTSTATUS status; |
| 1964 |
bool ret = true; |
| 1965 |
|
| 1966 |
smb2_deltree(tree, BASEDIR); |
| 1967 |
status = torture_smb2_testdir(tree, BASEDIR, &h); |
| 1968 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 1969 |
"create failed\n"); |
| 1970 |
status = smb2_util_close(tree, h ); |
| 1971 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 1972 |
"close failed\n"); |
| 1973 |
|
| 1974 |
torture_comment(tctx, "Write without delay, expect no " |
| 1975 |
"write-time change\n"); |
| 1976 |
|
| 1977 |
smb2_generic_create(&cr, NULL, false, fname, |
| 1978 |
NTCREATEX_DISP_CREATE, |
| 1979 |
smb2_util_oplock_level(""), 0, 0); |
| 1980 |
status = smb2_create(tree, tree, &cr); |
| 1981 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 1982 |
"create failed\n"); |
| 1983 |
h = cr.out.file.handle; |
| 1984 |
|
| 1985 |
finfo1 = (union smb_fileinfo) { |
| 1986 |
.generic.level = RAW_FILEINFO_SMB2_ALL_INFORMATION, |
| 1987 |
.generic.in.file.handle = h, |
| 1988 |
}; |
| 1989 |
status = smb2_getinfo_file(tree, tree, &finfo1); |
| 1990 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 1991 |
"getinfo failed\n"); |
| 1992 |
|
| 1993 |
status = smb2_util_write(tree, h, "123456789", 0, 9); |
| 1994 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 1995 |
"write failed\n"); |
| 1996 |
|
| 1997 |
cl = (struct smb2_close) { |
| 1998 |
.in.file.handle = h, |
| 1999 |
.in.flags = SMB2_CLOSE_FLAGS_FULL_INFORMATION, |
| 2000 |
}; |
| 2001 |
|
| 2002 |
status = smb2_close(tree, &cl); |
| 2003 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 2004 |
"close failed\n"); |
| 2005 |
ZERO_STRUCT(h); |
| 2006 |
|
| 2007 |
torture_comment(tctx, "Initial: %s\nClose: %s\n", |
| 2008 |
nt_time_string(tctx, finfo1.basic_info.out.write_time), |
| 2009 |
nt_time_string(tctx, cl.out.write_time)); |
| 2010 |
|
| 2011 |
torture_assert_u64_equal_goto(tctx, |
| 2012 |
finfo1.basic_info.out.write_time, |
| 2013 |
cl.out.write_time, |
| 2014 |
ret, done, |
| 2015 |
"Write time changed (wrong!)\n"); |
| 2016 |
|
| 2017 |
torture_comment(tctx, "Write with 20 ms delay, expect " |
| 2018 |
"write-time change\n"); |
| 2019 |
|
| 2020 |
smb2_generic_create(&cr, NULL, false, fname, |
| 2021 |
NTCREATEX_DISP_OPEN, |
| 2022 |
smb2_util_oplock_level(""), 0, 0); |
| 2023 |
status = smb2_create(tree, tree, &cr); |
| 2024 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 2025 |
"create failed\n"); |
| 2026 |
h = cr.out.file.handle; |
| 2027 |
|
| 2028 |
finfo1 = (union smb_fileinfo) { |
| 2029 |
.generic.level = RAW_FILEINFO_SMB2_ALL_INFORMATION, |
| 2030 |
.generic.in.file.handle = h, |
| 2031 |
}; |
| 2032 |
status = smb2_getinfo_file(tree, tree, &finfo1); |
| 2033 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 2034 |
"getinfo failed\n"); |
| 2035 |
|
| 2036 |
smb_msleep(20); |
| 2037 |
|
| 2038 |
status = smb2_util_write(tree, h, "123456789", 0, 9); |
| 2039 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 2040 |
"write failed\n"); |
| 2041 |
|
| 2042 |
cl = (struct smb2_close) { |
| 2043 |
.in.file.handle = h, |
| 2044 |
.in.flags = SMB2_CLOSE_FLAGS_FULL_INFORMATION, |
| 2045 |
}; |
| 2046 |
|
| 2047 |
status = smb2_close(tree, &cl); |
| 2048 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 2049 |
"close failed\n"); |
| 2050 |
ZERO_STRUCT(h); |
| 2051 |
|
| 2052 |
torture_comment(tctx, "Initial: %s\nClose: %s\n", |
| 2053 |
nt_time_string(tctx, finfo1.basic_info.out.write_time), |
| 2054 |
nt_time_string(tctx, cl.out.write_time)); |
| 2055 |
|
| 2056 |
torture_assert_u64_not_equal_goto( |
| 2057 |
tctx, |
| 2058 |
finfo1.basic_info.out.write_time, |
| 2059 |
cl.out.write_time, |
| 2060 |
ret, done, |
| 2061 |
"Write time did not change (wrong!)\n"); |
| 2062 |
|
| 2063 |
done: |
| 2064 |
if (!smb2_util_handle_empty(h)) { |
| 2065 |
smb2_util_close(tree, h); |
| 2066 |
} |
| 2067 |
smb2_deltree(tree, BASEDIR); |
| 2068 |
return ret; |
| 2069 |
} |
| 2070 |
|
| 2071 |
/* |
| 2072 |
basic testing of SMB2 timestamps |
| 2073 |
*/ |
| 2074 |
struct torture_suite *torture_smb2_timestamp_resolution_init(TALLOC_CTX *ctx) |
| 2075 |
{ |
| 2076 |
struct torture_suite *suite = torture_suite_create(ctx, "timestamp_resolution"); |
| 2077 |
|
| 2078 |
torture_suite_add_1smb2_test(suite, "resolution1", test_timestamp_resolution1); |
| 2079 |
|
| 2080 |
suite->description = talloc_strdup(suite, "SMB2 timestamp tests"); |
| 2081 |
|
| 2082 |
return suite; |
| 2083 |
} |