| 1 |
/* |
| 2 |
Unix SMB/CIFS implementation. |
| 3 |
|
| 4 |
test suite for SMB2 version two of durable opens |
| 5 |
|
| 6 |
Copyright (C) Michael Adam 2012 |
| 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 "../libcli/smb/smbXcli_base.h" |
| 26 |
#include "torture/torture.h" |
| 27 |
#include "torture/smb2/proto.h" |
| 28 |
#include "librpc/ndr/libndr.h" |
| 29 |
#include "lease_break_handler.h" |
| 30 |
|
| 31 |
#define CHECK_VAL(v, correct) \ |
| 32 |
torture_assert_u64_equal_goto(tctx, v, correct, ret, done, __location__) |
| 33 |
|
| 34 |
#define CHECK_STATUS(status, correct) \ |
| 35 |
torture_assert_ntstatus_equal_goto(tctx, status, correct, ret, done, __location__) |
| 36 |
|
| 37 |
#define CHECK_CREATED(__io, __created, __attribute) \ |
| 38 |
do { \ |
| 39 |
CHECK_VAL((__io)->out.create_action, NTCREATEX_ACTION_ ## __created); \ |
| 40 |
CHECK_VAL((__io)->out.size, 0); \ |
| 41 |
CHECK_VAL((__io)->out.file_attr, (__attribute)); \ |
| 42 |
CHECK_VAL((__io)->out.reserved2, 0); \ |
| 43 |
} while(0) |
| 44 |
|
| 45 |
#define CHECK_LEASE_V2(__io, __state, __oplevel, __key, __flags, __parent, __epoch) \ |
| 46 |
do { \ |
| 47 |
CHECK_VAL((__io)->out.lease_response_v2.lease_version, 2); \ |
| 48 |
if (__oplevel) { \ |
| 49 |
CHECK_VAL((__io)->out.oplock_level, SMB2_OPLOCK_LEVEL_LEASE); \ |
| 50 |
CHECK_VAL((__io)->out.lease_response_v2.lease_key.data[0], (__key)); \ |
| 51 |
CHECK_VAL((__io)->out.lease_response_v2.lease_key.data[1], ~(__key)); \ |
| 52 |
CHECK_VAL((__io)->out.lease_response_v2.lease_state, smb2_util_lease_state(__state)); \ |
| 53 |
} else { \ |
| 54 |
CHECK_VAL((__io)->out.oplock_level, SMB2_OPLOCK_LEVEL_NONE); \ |
| 55 |
CHECK_VAL((__io)->out.lease_response_v2.lease_key.data[0], 0); \ |
| 56 |
CHECK_VAL((__io)->out.lease_response_v2.lease_key.data[1], 0); \ |
| 57 |
CHECK_VAL((__io)->out.lease_response_v2.lease_state, 0); \ |
| 58 |
} \ |
| 59 |
\ |
| 60 |
CHECK_VAL((__io)->out.lease_response_v2.lease_flags, __flags); \ |
| 61 |
if (__flags & SMB2_LEASE_FLAG_PARENT_LEASE_KEY_SET) { \ |
| 62 |
CHECK_VAL((__io)->out.lease_response_v2.parent_lease_key.data[0], (__parent)); \ |
| 63 |
CHECK_VAL((__io)->out.lease_response_v2.parent_lease_key.data[1], ~(__parent)); \ |
| 64 |
} \ |
| 65 |
CHECK_VAL((__io)->out.lease_response_v2.lease_duration, 0); \ |
| 66 |
CHECK_VAL((__io)->out.lease_response_v2.lease_epoch, (__epoch)); \ |
| 67 |
} while(0) |
| 68 |
|
| 69 |
static struct { |
| 70 |
int count; |
| 71 |
struct smb2_close cl; |
| 72 |
} break_info; |
| 73 |
|
| 74 |
static void torture_oplock_close_callback(struct smb2_request *req) |
| 75 |
{ |
| 76 |
smb2_close_recv(req, &break_info.cl); |
| 77 |
} |
| 78 |
|
| 79 |
/* A general oplock break notification handler. This should be used when a |
| 80 |
* test expects to break from batch or exclusive to a lower level. */ |
| 81 |
static bool torture_oplock_handler(struct smb2_transport *transport, |
| 82 |
const struct smb2_handle *handle, |
| 83 |
uint8_t level, |
| 84 |
void *private_data) |
| 85 |
{ |
| 86 |
struct smb2_tree *tree = private_data; |
| 87 |
struct smb2_request *req; |
| 88 |
|
| 89 |
break_info.count++; |
| 90 |
|
| 91 |
ZERO_STRUCT(break_info.cl); |
| 92 |
break_info.cl.in.file.handle = *handle; |
| 93 |
|
| 94 |
req = smb2_close_send(tree, &break_info.cl); |
| 95 |
req->async.fn = torture_oplock_close_callback; |
| 96 |
req->async.private_data = NULL; |
| 97 |
return true; |
| 98 |
} |
| 99 |
|
| 100 |
/** |
| 101 |
* testing various create blob combinations. |
| 102 |
*/ |
| 103 |
bool test_durable_v2_open_create_blob(struct torture_context *tctx, |
| 104 |
struct smb2_tree *tree) |
| 105 |
{ |
| 106 |
NTSTATUS status; |
| 107 |
TALLOC_CTX *mem_ctx = talloc_new(tctx); |
| 108 |
char fname[256]; |
| 109 |
struct smb2_handle _h; |
| 110 |
struct smb2_handle *h = NULL; |
| 111 |
struct smb2_create io; |
| 112 |
struct GUID create_guid = GUID_random(); |
| 113 |
bool ret = true; |
| 114 |
struct smbcli_options options; |
| 115 |
uint32_t share_capabilities; |
| 116 |
bool share_is_so; |
| 117 |
uint8_t expected_oplock_granted; |
| 118 |
bool expected_dhv2_granted; |
| 119 |
uint32_t expected_dhv2_timeout; |
| 120 |
|
| 121 |
share_capabilities = smb2cli_tcon_capabilities(tree->smbXcli); |
| 122 |
share_is_so = share_capabilities & SMB2_SHARE_CAP_SCALEOUT; |
| 123 |
|
| 124 |
if (share_is_so) { |
| 125 |
expected_oplock_granted = SMB2_OPLOCK_LEVEL_II; |
| 126 |
expected_dhv2_granted = false; |
| 127 |
expected_dhv2_timeout = 0; |
| 128 |
} else { |
| 129 |
expected_oplock_granted = SMB2_OPLOCK_LEVEL_BATCH; |
| 130 |
expected_dhv2_granted = true; |
| 131 |
expected_dhv2_timeout = 300*1000; |
| 132 |
} |
| 133 |
|
| 134 |
options = tree->session->transport->options; |
| 135 |
|
| 136 |
/* Choose a random name in case the state is left a little funky. */ |
| 137 |
snprintf(fname, 256, "durable_v2_open_create_blob_%s.dat", |
| 138 |
generate_random_str(tctx, 8)); |
| 139 |
|
| 140 |
smb2_util_unlink(tree, fname); |
| 141 |
|
| 142 |
smb2_oplock_create_share(&io, fname, |
| 143 |
smb2_util_share_access(""), |
| 144 |
smb2_util_oplock_level("b")); |
| 145 |
io.in.durable_open = false; |
| 146 |
io.in.durable_open_v2 = true; |
| 147 |
io.in.persistent_open = false; |
| 148 |
io.in.create_guid = create_guid; |
| 149 |
io.in.timeout = UINT32_MAX; |
| 150 |
|
| 151 |
status = smb2_create(tree, mem_ctx, &io); |
| 152 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 153 |
_h = io.out.file.handle; |
| 154 |
h = &_h; |
| 155 |
CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE); |
| 156 |
CHECK_VAL(io.out.oplock_level, expected_oplock_granted); |
| 157 |
CHECK_VAL(io.out.durable_open, false); |
| 158 |
CHECK_VAL(io.out.durable_open_v2, expected_dhv2_granted); |
| 159 |
CHECK_VAL(io.out.persistent_open, false); |
| 160 |
CHECK_VAL(io.out.timeout, expected_dhv2_timeout); |
| 161 |
|
| 162 |
/* disconnect */ |
| 163 |
TALLOC_FREE(tree); |
| 164 |
|
| 165 |
/* create a new session (same client_guid) */ |
| 166 |
if (!torture_smb2_connection_ext(tctx, 0, &options, &tree)) { |
| 167 |
torture_warning(tctx, "couldn't reconnect, bailing\n"); |
| 168 |
ret = false; |
| 169 |
goto done; |
| 170 |
} |
| 171 |
|
| 172 |
/* |
| 173 |
* check invalid combinations of durable handle |
| 174 |
* request and reconnect blobs |
| 175 |
* See MS-SMB2: 3.3.5.9.12 |
| 176 |
* Handling the SMB2_CREATE_DURABLE_HANDLE_RECONNECT_V2 Create Context |
| 177 |
*/ |
| 178 |
ZERO_STRUCT(io); |
| 179 |
io.in.fname = fname; |
| 180 |
io.in.durable_handle_v2 = h; /* durable v2 reconnect request */ |
| 181 |
io.in.durable_open = true; /* durable v1 handle request */ |
| 182 |
io.in.create_guid = create_guid; |
| 183 |
status = smb2_create(tree, mem_ctx, &io); |
| 184 |
CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER); |
| 185 |
|
| 186 |
ZERO_STRUCT(io); |
| 187 |
io.in.fname = fname; |
| 188 |
io.in.durable_handle = h; /* durable v1 reconnect request */ |
| 189 |
io.in.durable_open_v2 = true; /* durable v2 handle request */ |
| 190 |
io.in.create_guid = create_guid; |
| 191 |
status = smb2_create(tree, mem_ctx, &io); |
| 192 |
CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER); |
| 193 |
|
| 194 |
ZERO_STRUCT(io); |
| 195 |
io.in.fname = fname; |
| 196 |
io.in.durable_handle = h; /* durable v1 reconnect request */ |
| 197 |
io.in.durable_handle_v2 = h; /* durable v2 reconnect request */ |
| 198 |
io.in.create_guid = create_guid; |
| 199 |
status = smb2_create(tree, mem_ctx, &io); |
| 200 |
CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER); |
| 201 |
|
| 202 |
ZERO_STRUCT(io); |
| 203 |
io.in.fname = fname; |
| 204 |
io.in.durable_handle_v2 = h; /* durable v2 reconnect request */ |
| 205 |
io.in.durable_open_v2 = true; /* durable v2 handle request */ |
| 206 |
io.in.create_guid = create_guid; |
| 207 |
status = smb2_create(tree, mem_ctx, &io); |
| 208 |
CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER); |
| 209 |
|
| 210 |
done: |
| 211 |
if (h != NULL) { |
| 212 |
smb2_util_close(tree, *h); |
| 213 |
} |
| 214 |
|
| 215 |
smb2_util_unlink(tree, fname); |
| 216 |
|
| 217 |
talloc_free(tree); |
| 218 |
|
| 219 |
talloc_free(mem_ctx); |
| 220 |
|
| 221 |
return ret; |
| 222 |
} |
| 223 |
|
| 224 |
|
| 225 |
/** |
| 226 |
* basic durable_open test. |
| 227 |
* durable state should only be granted when requested |
| 228 |
* along with a batch oplock or a handle lease. |
| 229 |
* |
| 230 |
* This test tests durable open with all possible oplock types. |
| 231 |
*/ |
| 232 |
|
| 233 |
struct durable_open_vs_oplock { |
| 234 |
const char *level; |
| 235 |
const char *share_mode; |
| 236 |
bool durable; |
| 237 |
bool persistent; |
| 238 |
}; |
| 239 |
|
| 240 |
#define NUM_OPLOCK_TYPES 4 |
| 241 |
#define NUM_SHARE_MODES 8 |
| 242 |
#define NUM_OPLOCK_OPEN_TESTS ( NUM_OPLOCK_TYPES * NUM_SHARE_MODES ) |
| 243 |
static struct durable_open_vs_oplock durable_open_vs_oplock_table[NUM_OPLOCK_OPEN_TESTS] = |
| 244 |
{ |
| 245 |
{ "", "", false, false }, |
| 246 |
{ "", "R", false, false }, |
| 247 |
{ "", "W", false, false }, |
| 248 |
{ "", "D", false, false }, |
| 249 |
{ "", "RD", false, false }, |
| 250 |
{ "", "RW", false, false }, |
| 251 |
{ "", "WD", false, false }, |
| 252 |
{ "", "RWD", false, false }, |
| 253 |
|
| 254 |
{ "s", "", false, false }, |
| 255 |
{ "s", "R", false, false }, |
| 256 |
{ "s", "W", false, false }, |
| 257 |
{ "s", "D", false, false }, |
| 258 |
{ "s", "RD", false, false }, |
| 259 |
{ "s", "RW", false, false }, |
| 260 |
{ "s", "WD", false, false }, |
| 261 |
{ "s", "RWD", false, false }, |
| 262 |
|
| 263 |
{ "x", "", false, false }, |
| 264 |
{ "x", "R", false, false }, |
| 265 |
{ "x", "W", false, false }, |
| 266 |
{ "x", "D", false, false }, |
| 267 |
{ "x", "RD", false, false }, |
| 268 |
{ "x", "RW", false, false }, |
| 269 |
{ "x", "WD", false, false }, |
| 270 |
{ "x", "RWD", false, false }, |
| 271 |
|
| 272 |
{ "b", "", true, false }, |
| 273 |
{ "b", "R", true, false }, |
| 274 |
{ "b", "W", true, false }, |
| 275 |
{ "b", "D", true, false }, |
| 276 |
{ "b", "RD", true, false }, |
| 277 |
{ "b", "RW", true, false }, |
| 278 |
{ "b", "WD", true, false }, |
| 279 |
{ "b", "RWD", true, false }, |
| 280 |
}; |
| 281 |
|
| 282 |
static bool test_one_durable_v2_open_oplock(struct torture_context *tctx, |
| 283 |
struct smb2_tree *tree, |
| 284 |
const char *fname, |
| 285 |
bool request_persistent, |
| 286 |
struct durable_open_vs_oplock test) |
| 287 |
{ |
| 288 |
NTSTATUS status; |
| 289 |
TALLOC_CTX *mem_ctx = talloc_new(tctx); |
| 290 |
uint32_t share_capabilities; |
| 291 |
bool share_is_so; |
| 292 |
struct smb2_handle _h; |
| 293 |
struct smb2_handle *h = NULL; |
| 294 |
bool ret = true; |
| 295 |
struct smb2_create io; |
| 296 |
uint8_t expected_oplock_level; |
| 297 |
bool expected_durable; |
| 298 |
|
| 299 |
smb2_util_unlink(tree, fname); |
| 300 |
|
| 301 |
share_capabilities = smb2cli_tcon_capabilities(tree->smbXcli); |
| 302 |
share_is_so = share_capabilities & SMB2_SHARE_CAP_SCALEOUT; |
| 303 |
|
| 304 |
expected_oplock_level = smb2_util_oplock_level(test.level); |
| 305 |
expected_durable = test.durable; |
| 306 |
|
| 307 |
if (share_is_so) { |
| 308 |
/* |
| 309 |
* MS-SMB2 3.3.5.9 Receiving an SMB2 CREATE Request |
| 310 |
* |
| 311 |
* If Connection.Dialect belongs to the SMB 3.x dialect family, |
| 312 |
* TreeConnect.Share.Type is STYPE_CLUSTER_SOFS as specified in |
| 313 |
* [MS-SRVS] section 2.2.2.4, and the RequestedOplockLevel is |
| 314 |
* SMB2_OPLOCK_LEVEL_BATCH, the server MUST set |
| 315 |
* RequestedOplockLevel to SMB2_OPLOCK_LEVEL_II. |
| 316 |
*/ |
| 317 |
if (expected_oplock_level == SMB2_OPLOCK_LEVEL_BATCH) { |
| 318 |
expected_oplock_level = SMB2_OPLOCK_LEVEL_II; |
| 319 |
} |
| 320 |
/* |
| 321 |
* No Durable Handles on SOFS shares, only Persistent Handles. |
| 322 |
*/ |
| 323 |
if (!request_persistent) { |
| 324 |
expected_durable = false; |
| 325 |
} |
| 326 |
} |
| 327 |
|
| 328 |
smb2_oplock_create_share(&io, fname, |
| 329 |
smb2_util_share_access(test.share_mode), |
| 330 |
smb2_util_oplock_level(test.level)); |
| 331 |
io.in.durable_open = false; |
| 332 |
io.in.durable_open_v2 = true; |
| 333 |
io.in.persistent_open = request_persistent; |
| 334 |
io.in.create_guid = GUID_random(); |
| 335 |
|
| 336 |
status = smb2_create(tree, mem_ctx, &io); |
| 337 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 338 |
_h = io.out.file.handle; |
| 339 |
h = &_h; |
| 340 |
CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE); |
| 341 |
CHECK_VAL(io.out.durable_open, false); |
| 342 |
CHECK_VAL(io.out.durable_open_v2, expected_durable); |
| 343 |
CHECK_VAL(io.out.persistent_open, test.persistent); |
| 344 |
CHECK_VAL(io.out.oplock_level, expected_oplock_level); |
| 345 |
|
| 346 |
done: |
| 347 |
if (h != NULL) { |
| 348 |
smb2_util_close(tree, *h); |
| 349 |
} |
| 350 |
smb2_util_unlink(tree, fname); |
| 351 |
talloc_free(mem_ctx); |
| 352 |
|
| 353 |
return ret; |
| 354 |
} |
| 355 |
|
| 356 |
static bool test_durable_v2_open_oplock_table(struct torture_context *tctx, |
| 357 |
struct smb2_tree *tree, |
| 358 |
const char *fname, |
| 359 |
bool request_persistent, |
| 360 |
struct durable_open_vs_oplock *table, |
| 361 |
uint8_t num_tests) |
| 362 |
{ |
| 363 |
bool ret = true; |
| 364 |
uint8_t i; |
| 365 |
|
| 366 |
smb2_util_unlink(tree, fname); |
| 367 |
|
| 368 |
for (i = 0; i < num_tests; i++) { |
| 369 |
ret = test_one_durable_v2_open_oplock(tctx, |
| 370 |
tree, |
| 371 |
fname, |
| 372 |
request_persistent, |
| 373 |
table[i]); |
| 374 |
if (ret == false) { |
| 375 |
goto done; |
| 376 |
} |
| 377 |
} |
| 378 |
|
| 379 |
done: |
| 380 |
smb2_util_unlink(tree, fname); |
| 381 |
|
| 382 |
return ret; |
| 383 |
} |
| 384 |
|
| 385 |
bool test_durable_v2_open_oplock(struct torture_context *tctx, |
| 386 |
struct smb2_tree *tree) |
| 387 |
{ |
| 388 |
bool ret; |
| 389 |
char fname[256]; |
| 390 |
|
| 391 |
/* Choose a random name in case the state is left a little funky. */ |
| 392 |
snprintf(fname, 256, "durable_open_oplock_%s.dat", |
| 393 |
generate_random_str(tctx, 8)); |
| 394 |
|
| 395 |
ret = test_durable_v2_open_oplock_table(tctx, tree, fname, |
| 396 |
false, /* request_persistent */ |
| 397 |
durable_open_vs_oplock_table, |
| 398 |
NUM_OPLOCK_OPEN_TESTS); |
| 399 |
|
| 400 |
talloc_free(tree); |
| 401 |
|
| 402 |
return ret; |
| 403 |
} |
| 404 |
|
| 405 |
/** |
| 406 |
* basic durable handle open test. |
| 407 |
* persistent state should only be granted when requested |
| 408 |
* along with a batch oplock or a handle lease. |
| 409 |
* |
| 410 |
* This test tests persistent open with all valid lease types. |
| 411 |
*/ |
| 412 |
|
| 413 |
struct durable_open_vs_lease { |
| 414 |
const char *type; |
| 415 |
const char *share_mode; |
| 416 |
bool durable; |
| 417 |
bool persistent; |
| 418 |
}; |
| 419 |
|
| 420 |
#define NUM_LEASE_TYPES 5 |
| 421 |
#define NUM_LEASE_OPEN_TESTS ( NUM_LEASE_TYPES * NUM_SHARE_MODES ) |
| 422 |
static struct durable_open_vs_lease durable_open_vs_lease_table[NUM_LEASE_OPEN_TESTS] = |
| 423 |
{ |
| 424 |
{ "", "", false, false }, |
| 425 |
{ "", "R", false, false }, |
| 426 |
{ "", "W", false, false }, |
| 427 |
{ "", "D", false, false }, |
| 428 |
{ "", "RW", false, false }, |
| 429 |
{ "", "RD", false, false }, |
| 430 |
{ "", "WD", false, false }, |
| 431 |
{ "", "RWD", false, false }, |
| 432 |
|
| 433 |
{ "R", "", false, false }, |
| 434 |
{ "R", "R", false, false }, |
| 435 |
{ "R", "W", false, false }, |
| 436 |
{ "R", "D", false, false }, |
| 437 |
{ "R", "RW", false, false }, |
| 438 |
{ "R", "RD", false, false }, |
| 439 |
{ "R", "DW", false, false }, |
| 440 |
{ "R", "RWD", false, false }, |
| 441 |
|
| 442 |
{ "RW", "", false, false }, |
| 443 |
{ "RW", "R", false, false }, |
| 444 |
{ "RW", "W", false, false }, |
| 445 |
{ "RW", "D", false, false }, |
| 446 |
{ "RW", "RW", false, false }, |
| 447 |
{ "RW", "RD", false, false }, |
| 448 |
{ "RW", "WD", false, false }, |
| 449 |
{ "RW", "RWD", false, false }, |
| 450 |
|
| 451 |
{ "RH", "", true, false }, |
| 452 |
{ "RH", "R", true, false }, |
| 453 |
{ "RH", "W", true, false }, |
| 454 |
{ "RH", "D", true, false }, |
| 455 |
{ "RH", "RW", true, false }, |
| 456 |
{ "RH", "RD", true, false }, |
| 457 |
{ "RH", "WD", true, false }, |
| 458 |
{ "RH", "RWD", true, false }, |
| 459 |
|
| 460 |
{ "RHW", "", true, false }, |
| 461 |
{ "RHW", "R", true, false }, |
| 462 |
{ "RHW", "W", true, false }, |
| 463 |
{ "RHW", "D", true, false }, |
| 464 |
{ "RHW", "RW", true, false }, |
| 465 |
{ "RHW", "RD", true, false }, |
| 466 |
{ "RHW", "WD", true, false }, |
| 467 |
{ "RHW", "RWD", true, false }, |
| 468 |
}; |
| 469 |
|
| 470 |
static bool test_one_durable_v2_open_lease(struct torture_context *tctx, |
| 471 |
struct smb2_tree *tree, |
| 472 |
const char *fname, |
| 473 |
bool request_persistent, |
| 474 |
bool share_is_so, |
| 475 |
struct durable_open_vs_lease test) |
| 476 |
{ |
| 477 |
NTSTATUS status; |
| 478 |
TALLOC_CTX *mem_ctx = talloc_new(tctx); |
| 479 |
struct smb2_handle _h; |
| 480 |
struct smb2_handle *h = NULL; |
| 481 |
bool ret = true; |
| 482 |
struct smb2_create io; |
| 483 |
struct smb2_lease ls; |
| 484 |
uint64_t lease; |
| 485 |
uint8_t expected_lease_granted; |
| 486 |
bool expected_durable; |
| 487 |
|
| 488 |
smb2_util_unlink(tree, fname); |
| 489 |
|
| 490 |
lease = random(); |
| 491 |
|
| 492 |
expected_lease_granted = smb2_util_lease_state(test.type); |
| 493 |
expected_durable = test.durable; |
| 494 |
if (share_is_so) { |
| 495 |
expected_lease_granted &= SMB2_LEASE_READ; |
| 496 |
if (!request_persistent) { |
| 497 |
expected_durable = false; |
| 498 |
} |
| 499 |
} |
| 500 |
|
| 501 |
smb2_lease_create_share(&io, &ls, false /* dir */, fname, |
| 502 |
smb2_util_share_access(test.share_mode), |
| 503 |
lease, |
| 504 |
smb2_util_lease_state(test.type)); |
| 505 |
io.in.durable_open = false; |
| 506 |
io.in.durable_open_v2 = true; |
| 507 |
io.in.persistent_open = request_persistent; |
| 508 |
io.in.create_guid = GUID_random(); |
| 509 |
|
| 510 |
status = smb2_create(tree, mem_ctx, &io); |
| 511 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 512 |
_h = io.out.file.handle; |
| 513 |
h = &_h; |
| 514 |
CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE); |
| 515 |
CHECK_VAL(io.out.durable_open, false); |
| 516 |
CHECK_VAL(io.out.durable_open_v2, expected_durable); |
| 517 |
CHECK_VAL(io.out.persistent_open, test.persistent); |
| 518 |
if (smb2_util_lease_state(test.type) != 0) { |
| 519 |
CHECK_VAL(io.out.oplock_level, SMB2_OPLOCK_LEVEL_LEASE); |
| 520 |
CHECK_VAL(io.out.lease_response.lease_key.data[0], lease); |
| 521 |
CHECK_VAL(io.out.lease_response.lease_key.data[1], ~lease); |
| 522 |
CHECK_VAL(io.out.lease_response.lease_state, |
| 523 |
expected_lease_granted); |
| 524 |
} |
| 525 |
done: |
| 526 |
if (h != NULL) { |
| 527 |
smb2_util_close(tree, *h); |
| 528 |
} |
| 529 |
smb2_util_unlink(tree, fname); |
| 530 |
talloc_free(mem_ctx); |
| 531 |
|
| 532 |
return ret; |
| 533 |
} |
| 534 |
|
| 535 |
static bool test_durable_v2_open_lease_table(struct torture_context *tctx, |
| 536 |
struct smb2_tree *tree, |
| 537 |
const char *fname, |
| 538 |
bool request_persistent, |
| 539 |
bool share_is_so, |
| 540 |
struct durable_open_vs_lease *table, |
| 541 |
uint8_t num_tests) |
| 542 |
{ |
| 543 |
bool ret = true; |
| 544 |
uint8_t i; |
| 545 |
|
| 546 |
smb2_util_unlink(tree, fname); |
| 547 |
|
| 548 |
for (i = 0; i < num_tests; i++) { |
| 549 |
ret = test_one_durable_v2_open_lease(tctx, |
| 550 |
tree, |
| 551 |
fname, |
| 552 |
request_persistent, |
| 553 |
share_is_so, |
| 554 |
table[i]); |
| 555 |
if (ret == false) { |
| 556 |
goto done; |
| 557 |
} |
| 558 |
} |
| 559 |
|
| 560 |
done: |
| 561 |
smb2_util_unlink(tree, fname); |
| 562 |
|
| 563 |
return ret; |
| 564 |
} |
| 565 |
|
| 566 |
bool test_durable_v2_open_lease(struct torture_context *tctx, |
| 567 |
struct smb2_tree *tree) |
| 568 |
{ |
| 569 |
char fname[256]; |
| 570 |
bool ret = true; |
| 571 |
uint32_t caps; |
| 572 |
uint32_t share_capabilities; |
| 573 |
bool share_is_so; |
| 574 |
|
| 575 |
caps = smb2cli_conn_server_capabilities(tree->session->transport->conn); |
| 576 |
if (!(caps & SMB2_CAP_LEASING)) { |
| 577 |
torture_skip(tctx, "leases are not supported"); |
| 578 |
} |
| 579 |
|
| 580 |
share_capabilities = smb2cli_tcon_capabilities(tree->smbXcli); |
| 581 |
share_is_so = share_capabilities & SMB2_SHARE_CAP_SCALEOUT; |
| 582 |
|
| 583 |
/* Choose a random name in case the state is left a little funky. */ |
| 584 |
snprintf(fname, 256, "durable_open_lease_%s.dat", generate_random_str(tctx, 8)); |
| 585 |
|
| 586 |
ret = test_durable_v2_open_lease_table(tctx, tree, fname, |
| 587 |
false, /* request_persistent */ |
| 588 |
share_is_so, |
| 589 |
durable_open_vs_lease_table, |
| 590 |
NUM_LEASE_OPEN_TESTS); |
| 591 |
|
| 592 |
talloc_free(tree); |
| 593 |
return ret; |
| 594 |
} |
| 595 |
|
| 596 |
/** |
| 597 |
* basic test for doing a durable open |
| 598 |
* and do a durable reopen on the same connection |
| 599 |
* while the first open is still active (fails) |
| 600 |
*/ |
| 601 |
bool test_durable_v2_open_reopen1(struct torture_context *tctx, |
| 602 |
struct smb2_tree *tree) |
| 603 |
{ |
| 604 |
NTSTATUS status; |
| 605 |
TALLOC_CTX *mem_ctx = talloc_new(tctx); |
| 606 |
char fname[256]; |
| 607 |
struct smb2_handle _h; |
| 608 |
struct smb2_handle *h = NULL; |
| 609 |
struct smb2_create io; |
| 610 |
struct GUID create_guid = GUID_random(); |
| 611 |
bool ret = true; |
| 612 |
|
| 613 |
/* Choose a random name in case the state is left a little funky. */ |
| 614 |
snprintf(fname, 256, "durable_v2_open_reopen1_%s.dat", |
| 615 |
generate_random_str(tctx, 8)); |
| 616 |
|
| 617 |
smb2_util_unlink(tree, fname); |
| 618 |
|
| 619 |
smb2_oplock_create_share(&io, fname, |
| 620 |
smb2_util_share_access(""), |
| 621 |
smb2_util_oplock_level("b")); |
| 622 |
io.in.durable_open = false; |
| 623 |
io.in.durable_open_v2 = true; |
| 624 |
io.in.persistent_open = false; |
| 625 |
io.in.create_guid = create_guid; |
| 626 |
io.in.timeout = UINT32_MAX; |
| 627 |
|
| 628 |
status = smb2_create(tree, mem_ctx, &io); |
| 629 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 630 |
_h = io.out.file.handle; |
| 631 |
h = &_h; |
| 632 |
CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE); |
| 633 |
CHECK_VAL(io.out.oplock_level, smb2_util_oplock_level("b")); |
| 634 |
CHECK_VAL(io.out.durable_open, false); |
| 635 |
CHECK_VAL(io.out.durable_open_v2, true); |
| 636 |
CHECK_VAL(io.out.persistent_open, false); |
| 637 |
CHECK_VAL(io.out.timeout, 300*1000); |
| 638 |
|
| 639 |
/* try a durable reconnect while the file is still open */ |
| 640 |
ZERO_STRUCT(io); |
| 641 |
io.in.fname = ""; |
| 642 |
io.in.durable_handle_v2 = h; |
| 643 |
io.in.create_guid = create_guid; |
| 644 |
status = smb2_create(tree, mem_ctx, &io); |
| 645 |
CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND); |
| 646 |
|
| 647 |
done: |
| 648 |
if (h != NULL) { |
| 649 |
smb2_util_close(tree, *h); |
| 650 |
} |
| 651 |
|
| 652 |
smb2_util_unlink(tree, fname); |
| 653 |
|
| 654 |
talloc_free(tree); |
| 655 |
|
| 656 |
talloc_free(mem_ctx); |
| 657 |
|
| 658 |
return ret; |
| 659 |
} |
| 660 |
|
| 661 |
/** |
| 662 |
* Basic test for doing a durable open |
| 663 |
* and do a session reconnect while the first |
| 664 |
* session is still active and the handle is |
| 665 |
* still open in the client. |
| 666 |
* This closes the original session and a |
| 667 |
* durable reconnect on the new session succeeds. |
| 668 |
*/ |
| 669 |
bool test_durable_v2_open_reopen1a(struct torture_context *tctx, |
| 670 |
struct smb2_tree *tree) |
| 671 |
{ |
| 672 |
NTSTATUS status; |
| 673 |
TALLOC_CTX *mem_ctx = talloc_new(tctx); |
| 674 |
char fname[256]; |
| 675 |
struct smb2_handle _h; |
| 676 |
struct smb2_handle *h = NULL; |
| 677 |
struct smb2_create io; |
| 678 |
struct GUID create_guid = GUID_random(); |
| 679 |
bool ret = true; |
| 680 |
struct smb2_tree *tree2 = NULL; |
| 681 |
struct smb2_tree *tree3 = NULL; |
| 682 |
uint64_t previous_session_id; |
| 683 |
struct smbcli_options options; |
| 684 |
struct GUID orig_client_guid; |
| 685 |
|
| 686 |
options = tree->session->transport->options; |
| 687 |
orig_client_guid = options.client_guid; |
| 688 |
|
| 689 |
/* Choose a random name in case the state is left a little funky. */ |
| 690 |
snprintf(fname, 256, "durable_v2_open_reopen1a_%s.dat", |
| 691 |
generate_random_str(tctx, 8)); |
| 692 |
|
| 693 |
smb2_util_unlink(tree, fname); |
| 694 |
|
| 695 |
smb2_oplock_create_share(&io, fname, |
| 696 |
smb2_util_share_access(""), |
| 697 |
smb2_util_oplock_level("b")); |
| 698 |
io.in.durable_open = false; |
| 699 |
io.in.durable_open_v2 = true; |
| 700 |
io.in.persistent_open = false; |
| 701 |
io.in.create_guid = create_guid; |
| 702 |
io.in.timeout = UINT32_MAX; |
| 703 |
|
| 704 |
status = smb2_create(tree, mem_ctx, &io); |
| 705 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 706 |
_h = io.out.file.handle; |
| 707 |
h = &_h; |
| 708 |
CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE); |
| 709 |
CHECK_VAL(io.out.oplock_level, smb2_util_oplock_level("b")); |
| 710 |
CHECK_VAL(io.out.durable_open, false); |
| 711 |
CHECK_VAL(io.out.durable_open_v2, true); |
| 712 |
CHECK_VAL(io.out.persistent_open, false); |
| 713 |
CHECK_VAL(io.out.timeout, 300*1000); |
| 714 |
|
| 715 |
/* |
| 716 |
* a session reconnect on a second tcp connection |
| 717 |
*/ |
| 718 |
|
| 719 |
previous_session_id = smb2cli_session_current_id(tree->session->smbXcli); |
| 720 |
|
| 721 |
/* for oplocks, the client guid can be different: */ |
| 722 |
options.client_guid = GUID_random(); |
| 723 |
|
| 724 |
ret = torture_smb2_connection_ext(tctx, previous_session_id, |
| 725 |
&options, &tree2); |
| 726 |
torture_assert_goto(tctx, ret, ret, done, "couldn't reconnect"); |
| 727 |
|
| 728 |
/* |
| 729 |
* check that this has deleted the old session |
| 730 |
*/ |
| 731 |
|
| 732 |
ZERO_STRUCT(io); |
| 733 |
io.in.fname = ""; |
| 734 |
io.in.durable_handle_v2 = h; |
| 735 |
io.in.create_guid = create_guid; |
| 736 |
status = smb2_create(tree, mem_ctx, &io); |
| 737 |
CHECK_STATUS(status, NT_STATUS_USER_SESSION_DELETED); |
| 738 |
|
| 739 |
TALLOC_FREE(tree); |
| 740 |
|
| 741 |
/* |
| 742 |
* but a durable reconnect on the new session succeeds: |
| 743 |
*/ |
| 744 |
|
| 745 |
ZERO_STRUCT(io); |
| 746 |
io.in.fname = ""; |
| 747 |
io.in.durable_handle_v2 = h; |
| 748 |
io.in.create_guid = create_guid; |
| 749 |
status = smb2_create(tree2, mem_ctx, &io); |
| 750 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 751 |
CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE); |
| 752 |
CHECK_VAL(io.out.oplock_level, smb2_util_oplock_level("b")); |
| 753 |
CHECK_VAL(io.out.durable_open, false); |
| 754 |
CHECK_VAL(io.out.durable_open_v2, false); /* no dh2q response blob */ |
| 755 |
CHECK_VAL(io.out.persistent_open, false); |
| 756 |
CHECK_VAL(io.out.timeout, 0); |
| 757 |
_h = io.out.file.handle; |
| 758 |
h = &_h; |
| 759 |
|
| 760 |
/* |
| 761 |
* a session reconnect on a second tcp connection |
| 762 |
*/ |
| 763 |
|
| 764 |
previous_session_id = smb2cli_session_current_id(tree2->session->smbXcli); |
| 765 |
|
| 766 |
/* it works the same with the original guid */ |
| 767 |
options.client_guid = orig_client_guid; |
| 768 |
|
| 769 |
ret = torture_smb2_connection_ext(tctx, previous_session_id, |
| 770 |
&options, &tree3); |
| 771 |
torture_assert_goto(tctx, ret, ret, done, "couldn't reconnect"); |
| 772 |
|
| 773 |
/* |
| 774 |
* check that this has deleted the old session |
| 775 |
*/ |
| 776 |
|
| 777 |
ZERO_STRUCT(io); |
| 778 |
io.in.fname = ""; |
| 779 |
io.in.durable_handle_v2 = h; |
| 780 |
io.in.create_guid = create_guid; |
| 781 |
status = smb2_create(tree2, mem_ctx, &io); |
| 782 |
CHECK_STATUS(status, NT_STATUS_USER_SESSION_DELETED); |
| 783 |
TALLOC_FREE(tree2); |
| 784 |
|
| 785 |
/* |
| 786 |
* but a durable reconnect on the new session succeeds: |
| 787 |
*/ |
| 788 |
|
| 789 |
ZERO_STRUCT(io); |
| 790 |
io.in.fname = ""; |
| 791 |
io.in.durable_handle_v2 = h; |
| 792 |
io.in.create_guid = create_guid; |
| 793 |
status = smb2_create(tree3, mem_ctx, &io); |
| 794 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 795 |
CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE); |
| 796 |
CHECK_VAL(io.out.oplock_level, smb2_util_oplock_level("b")); |
| 797 |
CHECK_VAL(io.out.durable_open, false); |
| 798 |
CHECK_VAL(io.out.durable_open_v2, false); /* no dh2q response blob */ |
| 799 |
CHECK_VAL(io.out.persistent_open, false); |
| 800 |
CHECK_VAL(io.out.timeout, 0); |
| 801 |
_h = io.out.file.handle; |
| 802 |
h = &_h; |
| 803 |
|
| 804 |
done: |
| 805 |
if (tree == NULL) { |
| 806 |
tree = tree2; |
| 807 |
} |
| 808 |
|
| 809 |
if (tree == NULL) { |
| 810 |
tree = tree3; |
| 811 |
} |
| 812 |
|
| 813 |
if (tree != NULL) { |
| 814 |
if (h != NULL) { |
| 815 |
smb2_util_close(tree, *h); |
| 816 |
} |
| 817 |
|
| 818 |
smb2_util_unlink(tree, fname); |
| 819 |
|
| 820 |
talloc_free(tree); |
| 821 |
} |
| 822 |
|
| 823 |
talloc_free(mem_ctx); |
| 824 |
|
| 825 |
return ret; |
| 826 |
} |
| 827 |
|
| 828 |
/** |
| 829 |
* lease variant of reopen1a |
| 830 |
* |
| 831 |
* Basic test for doing a durable open and doing a session |
| 832 |
* reconnect while the first session is still active and the |
| 833 |
* handle is still open in the client. |
| 834 |
* This closes the original session and a durable reconnect on |
| 835 |
* the new session succeeds depending on the client guid: |
| 836 |
* |
| 837 |
* Durable reconnect on a session with a different client guid fails. |
| 838 |
* Durable reconnect on a session with the original client guid succeeds. |
| 839 |
*/ |
| 840 |
bool test_durable_v2_open_reopen1a_lease(struct torture_context *tctx, |
| 841 |
struct smb2_tree *tree) |
| 842 |
{ |
| 843 |
NTSTATUS status; |
| 844 |
TALLOC_CTX *mem_ctx = talloc_new(tctx); |
| 845 |
char fname[256]; |
| 846 |
struct smb2_handle _h; |
| 847 |
struct smb2_handle *h = NULL; |
| 848 |
struct smb2_create io; |
| 849 |
struct GUID create_guid = GUID_random(); |
| 850 |
struct smb2_lease ls; |
| 851 |
uint64_t lease_key; |
| 852 |
bool ret = true; |
| 853 |
struct smb2_tree *tree2 = NULL; |
| 854 |
struct smb2_tree *tree3 = NULL; |
| 855 |
uint64_t previous_session_id; |
| 856 |
struct smbcli_options options; |
| 857 |
struct GUID orig_client_guid; |
| 858 |
|
| 859 |
options = tree->session->transport->options; |
| 860 |
orig_client_guid = options.client_guid; |
| 861 |
|
| 862 |
/* Choose a random name in case the state is left a little funky. */ |
| 863 |
snprintf(fname, 256, "durable_v2_open_reopen1a_lease_%s.dat", |
| 864 |
generate_random_str(tctx, 8)); |
| 865 |
|
| 866 |
smb2_util_unlink(tree, fname); |
| 867 |
|
| 868 |
lease_key = random(); |
| 869 |
smb2_lease_create(&io, &ls, false /* dir */, fname, |
| 870 |
lease_key, smb2_util_lease_state("RWH")); |
| 871 |
io.in.durable_open = false; |
| 872 |
io.in.durable_open_v2 = true; |
| 873 |
io.in.persistent_open = false; |
| 874 |
io.in.create_guid = create_guid; |
| 875 |
io.in.timeout = UINT32_MAX; |
| 876 |
|
| 877 |
status = smb2_create(tree, mem_ctx, &io); |
| 878 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 879 |
_h = io.out.file.handle; |
| 880 |
h = &_h; |
| 881 |
CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE); |
| 882 |
CHECK_VAL(io.out.durable_open, false); |
| 883 |
CHECK_VAL(io.out.durable_open_v2, true); |
| 884 |
CHECK_VAL(io.out.persistent_open, false); |
| 885 |
CHECK_VAL(io.out.timeout, 300*1000); |
| 886 |
CHECK_VAL(io.out.oplock_level, SMB2_OPLOCK_LEVEL_LEASE); |
| 887 |
CHECK_VAL(io.out.lease_response.lease_key.data[0], lease_key); |
| 888 |
CHECK_VAL(io.out.lease_response.lease_key.data[1], ~lease_key); |
| 889 |
CHECK_VAL(io.out.lease_response.lease_state, |
| 890 |
smb2_util_lease_state("RWH")); |
| 891 |
CHECK_VAL(io.out.lease_response.lease_flags, 0); |
| 892 |
CHECK_VAL(io.out.lease_response.lease_duration, 0); |
| 893 |
|
| 894 |
previous_session_id = smb2cli_session_current_id(tree->session->smbXcli); |
| 895 |
|
| 896 |
/* |
| 897 |
* a session reconnect on a second tcp connection |
| 898 |
* with a different client_guid does not allow |
| 899 |
* the durable reconnect. |
| 900 |
*/ |
| 901 |
|
| 902 |
options.client_guid = GUID_random(); |
| 903 |
|
| 904 |
ret = torture_smb2_connection_ext(tctx, previous_session_id, |
| 905 |
&options, &tree2); |
| 906 |
torture_assert_goto(tctx, ret, ret, done, "couldn't reconnect"); |
| 907 |
|
| 908 |
/* |
| 909 |
* check that this has deleted the old session |
| 910 |
*/ |
| 911 |
|
| 912 |
ZERO_STRUCT(io); |
| 913 |
io.in.fname = fname; |
| 914 |
io.in.durable_handle_v2 = h; |
| 915 |
io.in.create_guid = create_guid; |
| 916 |
io.in.lease_request = &ls; |
| 917 |
status = smb2_create(tree, mem_ctx, &io); |
| 918 |
CHECK_STATUS(status, NT_STATUS_USER_SESSION_DELETED); |
| 919 |
TALLOC_FREE(tree); |
| 920 |
|
| 921 |
/* |
| 922 |
* but a durable reconnect on the new session with the wrong |
| 923 |
* client guid fails |
| 924 |
*/ |
| 925 |
|
| 926 |
ZERO_STRUCT(io); |
| 927 |
io.in.fname = fname; |
| 928 |
io.in.durable_handle_v2 = h; |
| 929 |
io.in.create_guid = create_guid; |
| 930 |
io.in.lease_request = &ls; |
| 931 |
status = smb2_create(tree2, mem_ctx, &io); |
| 932 |
CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND); |
| 933 |
|
| 934 |
|
| 935 |
/* |
| 936 |
* now a session reconnect on a second tcp connection |
| 937 |
* with original client_guid allows the durable reconnect. |
| 938 |
*/ |
| 939 |
|
| 940 |
options.client_guid = orig_client_guid; |
| 941 |
//options.client_guid = GUID_random(); |
| 942 |
|
| 943 |
ret = torture_smb2_connection_ext(tctx, previous_session_id, |
| 944 |
&options, &tree3); |
| 945 |
torture_assert_goto(tctx, ret, ret, done, "couldn't reconnect"); |
| 946 |
|
| 947 |
/* |
| 948 |
* check that this has deleted the old session |
| 949 |
*/ |
| 950 |
|
| 951 |
ZERO_STRUCT(io); |
| 952 |
io.in.fname = fname; |
| 953 |
io.in.durable_handle_v2 = h; |
| 954 |
io.in.create_guid = create_guid; |
| 955 |
io.in.lease_request = &ls; |
| 956 |
status = smb2_create(tree2, mem_ctx, &io); |
| 957 |
CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND); |
| 958 |
TALLOC_FREE(tree2); |
| 959 |
|
| 960 |
/* |
| 961 |
* but a durable reconnect on the new session succeeds: |
| 962 |
*/ |
| 963 |
|
| 964 |
ZERO_STRUCT(io); |
| 965 |
io.in.fname = fname; |
| 966 |
io.in.durable_handle_v2 = h; |
| 967 |
io.in.create_guid = create_guid; |
| 968 |
io.in.lease_request = &ls; |
| 969 |
status = smb2_create(tree3, mem_ctx, &io); |
| 970 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 971 |
CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE); |
| 972 |
CHECK_VAL(io.out.durable_open, false); |
| 973 |
CHECK_VAL(io.out.durable_open_v2, false); /* no dh2q response blob */ |
| 974 |
CHECK_VAL(io.out.persistent_open, false); |
| 975 |
CHECK_VAL(io.out.timeout, 0); |
| 976 |
CHECK_VAL(io.out.oplock_level, SMB2_OPLOCK_LEVEL_LEASE); |
| 977 |
CHECK_VAL(io.out.lease_response.lease_key.data[0], lease_key); |
| 978 |
CHECK_VAL(io.out.lease_response.lease_key.data[1], ~lease_key); |
| 979 |
CHECK_VAL(io.out.lease_response.lease_state, |
| 980 |
smb2_util_lease_state("RWH")); |
| 981 |
CHECK_VAL(io.out.lease_response.lease_flags, 0); |
| 982 |
CHECK_VAL(io.out.lease_response.lease_duration, 0); |
| 983 |
_h = io.out.file.handle; |
| 984 |
h = &_h; |
| 985 |
|
| 986 |
done: |
| 987 |
if (tree == NULL) { |
| 988 |
tree = tree2; |
| 989 |
} |
| 990 |
|
| 991 |
if (tree == NULL) { |
| 992 |
tree = tree3; |
| 993 |
} |
| 994 |
|
| 995 |
if (tree != NULL) { |
| 996 |
if (h != NULL) { |
| 997 |
smb2_util_close(tree, *h); |
| 998 |
} |
| 999 |
|
| 1000 |
smb2_util_unlink(tree, fname); |
| 1001 |
|
| 1002 |
talloc_free(tree); |
| 1003 |
} |
| 1004 |
|
| 1005 |
talloc_free(mem_ctx); |
| 1006 |
|
| 1007 |
return ret; |
| 1008 |
} |
| 1009 |
|
| 1010 |
/** |
| 1011 |
* basic test for doing a durable open |
| 1012 |
* tcp disconnect, reconnect, do a durable reopen (succeeds) |
| 1013 |
*/ |
| 1014 |
bool test_durable_v2_open_reopen2(struct torture_context *tctx, |
| 1015 |
struct smb2_tree *tree) |
| 1016 |
{ |
| 1017 |
NTSTATUS status; |
| 1018 |
TALLOC_CTX *mem_ctx = talloc_new(tctx); |
| 1019 |
char fname[256]; |
| 1020 |
struct smb2_handle _h; |
| 1021 |
struct smb2_handle *h = NULL; |
| 1022 |
struct smb2_create io; |
| 1023 |
struct GUID create_guid = GUID_random(); |
| 1024 |
struct GUID create_guid_invalid = GUID_random(); |
| 1025 |
bool ret = true; |
| 1026 |
|
| 1027 |
/* Choose a random name in case the state is left a little funky. */ |
| 1028 |
snprintf(fname, 256, "durable_v2_open_reopen2_%s.dat", |
| 1029 |
generate_random_str(tctx, 8)); |
| 1030 |
|
| 1031 |
smb2_util_unlink(tree, fname); |
| 1032 |
|
| 1033 |
smb2_oplock_create_share(&io, fname, |
| 1034 |
smb2_util_share_access(""), |
| 1035 |
smb2_util_oplock_level("b")); |
| 1036 |
io.in.durable_open = false; |
| 1037 |
io.in.durable_open_v2 = true; |
| 1038 |
io.in.persistent_open = false; |
| 1039 |
io.in.create_guid = create_guid; |
| 1040 |
io.in.timeout = UINT32_MAX; |
| 1041 |
|
| 1042 |
status = smb2_create(tree, mem_ctx, &io); |
| 1043 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 1044 |
_h = io.out.file.handle; |
| 1045 |
h = &_h; |
| 1046 |
CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE); |
| 1047 |
CHECK_VAL(io.out.oplock_level, smb2_util_oplock_level("b")); |
| 1048 |
CHECK_VAL(io.out.durable_open, false); |
| 1049 |
CHECK_VAL(io.out.durable_open_v2, true); |
| 1050 |
CHECK_VAL(io.out.persistent_open, false); |
| 1051 |
CHECK_VAL(io.out.timeout, 300*1000); |
| 1052 |
|
| 1053 |
/* disconnect, leaving the durable open */ |
| 1054 |
TALLOC_FREE(tree); |
| 1055 |
|
| 1056 |
if (!torture_smb2_connection(tctx, &tree)) { |
| 1057 |
torture_warning(tctx, "couldn't reconnect, bailing\n"); |
| 1058 |
ret = false; |
| 1059 |
goto done; |
| 1060 |
} |
| 1061 |
|
| 1062 |
/* |
| 1063 |
* first a few failure cases |
| 1064 |
*/ |
| 1065 |
|
| 1066 |
ZERO_STRUCT(io); |
| 1067 |
io.in.fname = ""; |
| 1068 |
io.in.durable_handle_v2 = h; |
| 1069 |
status = smb2_create(tree, mem_ctx, &io); |
| 1070 |
CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND); |
| 1071 |
|
| 1072 |
ZERO_STRUCT(io); |
| 1073 |
io.in.fname = "__non_existing_fname__"; |
| 1074 |
io.in.durable_handle_v2 = h; |
| 1075 |
status = smb2_create(tree, mem_ctx, &io); |
| 1076 |
CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND); |
| 1077 |
|
| 1078 |
ZERO_STRUCT(io); |
| 1079 |
io.in.fname = fname; |
| 1080 |
io.in.durable_handle_v2 = h; |
| 1081 |
status = smb2_create(tree, mem_ctx, &io); |
| 1082 |
CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND); |
| 1083 |
|
| 1084 |
/* a non-zero but non-matching create_guid does not change it: */ |
| 1085 |
ZERO_STRUCT(io); |
| 1086 |
io.in.fname = fname; |
| 1087 |
io.in.durable_handle_v2 = h; |
| 1088 |
io.in.create_guid = create_guid_invalid; |
| 1089 |
status = smb2_create(tree, mem_ctx, &io); |
| 1090 |
CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND); |
| 1091 |
|
| 1092 |
/* |
| 1093 |
* now success: |
| 1094 |
* The important difference is that the create_guid is provided. |
| 1095 |
*/ |
| 1096 |
ZERO_STRUCT(io); |
| 1097 |
io.in.fname = fname; |
| 1098 |
io.in.durable_open_v2 = false; |
| 1099 |
io.in.durable_handle_v2 = h; |
| 1100 |
io.in.create_guid = create_guid; |
| 1101 |
h = NULL; |
| 1102 |
|
| 1103 |
status = smb2_create(tree, mem_ctx, &io); |
| 1104 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 1105 |
CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE); |
| 1106 |
CHECK_VAL(io.out.durable_open, false); |
| 1107 |
CHECK_VAL(io.out.durable_open_v2, false); /* no dh2q response blob */ |
| 1108 |
CHECK_VAL(io.out.persistent_open, false); |
| 1109 |
CHECK_VAL(io.out.oplock_level, smb2_util_oplock_level("b")); |
| 1110 |
_h = io.out.file.handle; |
| 1111 |
h = &_h; |
| 1112 |
|
| 1113 |
/* disconnect one more time */ |
| 1114 |
TALLOC_FREE(tree); |
| 1115 |
|
| 1116 |
if (!torture_smb2_connection(tctx, &tree)) { |
| 1117 |
torture_warning(tctx, "couldn't reconnect, bailing\n"); |
| 1118 |
ret = false; |
| 1119 |
goto done; |
| 1120 |
} |
| 1121 |
|
| 1122 |
ZERO_STRUCT(io); |
| 1123 |
/* These are completely ignored by the server */ |
| 1124 |
io.in.security_flags = 0x78; |
| 1125 |
io.in.oplock_level = 0x78; |
| 1126 |
io.in.impersonation_level = 0x12345678; |
| 1127 |
io.in.create_flags = 0x12345678; |
| 1128 |
io.in.reserved = 0x12345678; |
| 1129 |
io.in.desired_access = 0x12345678; |
| 1130 |
io.in.file_attributes = 0x12345678; |
| 1131 |
io.in.share_access = 0x12345678; |
| 1132 |
io.in.create_disposition = 0x12345678; |
| 1133 |
io.in.create_options = 0x12345678; |
| 1134 |
io.in.fname = "__non_existing_fname__"; |
| 1135 |
|
| 1136 |
/* |
| 1137 |
* only io.in.durable_handle_v2 and |
| 1138 |
* io.in.create_guid are checked |
| 1139 |
*/ |
| 1140 |
io.in.durable_open_v2 = false; |
| 1141 |
io.in.durable_handle_v2 = h; |
| 1142 |
io.in.create_guid = create_guid; |
| 1143 |
h = NULL; |
| 1144 |
|
| 1145 |
status = smb2_create(tree, mem_ctx, &io); |
| 1146 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 1147 |
CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE); |
| 1148 |
CHECK_VAL(io.out.durable_open, false); |
| 1149 |
CHECK_VAL(io.out.durable_open_v2, false); /* no dh2q response blob */ |
| 1150 |
CHECK_VAL(io.out.persistent_open, false); |
| 1151 |
CHECK_VAL(io.out.oplock_level, smb2_util_oplock_level("b")); |
| 1152 |
_h = io.out.file.handle; |
| 1153 |
h = &_h; |
| 1154 |
|
| 1155 |
done: |
| 1156 |
if (h != NULL) { |
| 1157 |
smb2_util_close(tree, *h); |
| 1158 |
} |
| 1159 |
|
| 1160 |
smb2_util_unlink(tree, fname); |
| 1161 |
|
| 1162 |
talloc_free(tree); |
| 1163 |
|
| 1164 |
talloc_free(mem_ctx); |
| 1165 |
|
| 1166 |
return ret; |
| 1167 |
} |
| 1168 |
|
| 1169 |
/** |
| 1170 |
* durable reconnect test: |
| 1171 |
* connect with v2, reconnect with v1 |
| 1172 |
*/ |
| 1173 |
bool test_durable_v2_open_reopen2b(struct torture_context *tctx, |
| 1174 |
struct smb2_tree *tree) |
| 1175 |
{ |
| 1176 |
NTSTATUS status; |
| 1177 |
TALLOC_CTX *mem_ctx = talloc_new(tctx); |
| 1178 |
char fname[256]; |
| 1179 |
struct smb2_handle _h; |
| 1180 |
struct smb2_handle *h = NULL; |
| 1181 |
struct smb2_create io; |
| 1182 |
struct GUID create_guid = GUID_random(); |
| 1183 |
bool ret = true; |
| 1184 |
struct smbcli_options options; |
| 1185 |
|
| 1186 |
options = tree->session->transport->options; |
| 1187 |
|
| 1188 |
/* Choose a random name in case the state is left a little funky. */ |
| 1189 |
snprintf(fname, 256, "durable_v2_open_reopen2b_%s.dat", |
| 1190 |
generate_random_str(tctx, 8)); |
| 1191 |
|
| 1192 |
smb2_util_unlink(tree, fname); |
| 1193 |
|
| 1194 |
smb2_oplock_create_share(&io, fname, |
| 1195 |
smb2_util_share_access(""), |
| 1196 |
smb2_util_oplock_level("b")); |
| 1197 |
io.in.durable_open = false; |
| 1198 |
io.in.durable_open_v2 = true; |
| 1199 |
io.in.persistent_open = false; |
| 1200 |
io.in.create_guid = create_guid; |
| 1201 |
io.in.timeout = UINT32_MAX; |
| 1202 |
|
| 1203 |
status = smb2_create(tree, mem_ctx, &io); |
| 1204 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 1205 |
_h = io.out.file.handle; |
| 1206 |
h = &_h; |
| 1207 |
CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE); |
| 1208 |
CHECK_VAL(io.out.oplock_level, smb2_util_oplock_level("b")); |
| 1209 |
CHECK_VAL(io.out.durable_open, false); |
| 1210 |
CHECK_VAL(io.out.durable_open_v2, true); |
| 1211 |
CHECK_VAL(io.out.persistent_open, false); |
| 1212 |
CHECK_VAL(io.out.timeout, 300*1000); |
| 1213 |
|
| 1214 |
/* disconnect, leaving the durable open */ |
| 1215 |
TALLOC_FREE(tree); |
| 1216 |
|
| 1217 |
if (!torture_smb2_connection_ext(tctx, 0, &options, &tree)) { |
| 1218 |
torture_warning(tctx, "couldn't reconnect, bailing\n"); |
| 1219 |
ret = false; |
| 1220 |
goto done; |
| 1221 |
} |
| 1222 |
|
| 1223 |
ZERO_STRUCT(io); |
| 1224 |
io.in.fname = fname; |
| 1225 |
io.in.durable_handle_v2 = h; /* durable v2 reconnect */ |
| 1226 |
io.in.create_guid = GUID_zero(); /* but zero create GUID */ |
| 1227 |
status = smb2_create(tree, mem_ctx, &io); |
| 1228 |
CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND); |
| 1229 |
|
| 1230 |
ZERO_STRUCT(io); |
| 1231 |
io.in.fname = fname; |
| 1232 |
io.in.durable_handle = h; /* durable v1 (!) reconnect */ |
| 1233 |
h = NULL; |
| 1234 |
|
| 1235 |
status = smb2_create(tree, mem_ctx, &io); |
| 1236 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 1237 |
CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE); |
| 1238 |
CHECK_VAL(io.out.durable_open, false); |
| 1239 |
CHECK_VAL(io.out.durable_open_v2, false); /* no dh2q response blob */ |
| 1240 |
CHECK_VAL(io.out.persistent_open, false); |
| 1241 |
CHECK_VAL(io.out.oplock_level, smb2_util_oplock_level("b")); |
| 1242 |
_h = io.out.file.handle; |
| 1243 |
h = &_h; |
| 1244 |
|
| 1245 |
done: |
| 1246 |
if (h != NULL) { |
| 1247 |
smb2_util_close(tree, *h); |
| 1248 |
} |
| 1249 |
|
| 1250 |
smb2_util_unlink(tree, fname); |
| 1251 |
|
| 1252 |
talloc_free(tree); |
| 1253 |
|
| 1254 |
talloc_free(mem_ctx); |
| 1255 |
|
| 1256 |
return ret; |
| 1257 |
} |
| 1258 |
/** |
| 1259 |
* durable reconnect test: |
| 1260 |
* connect with v1, reconnect with v2 : fails (no create_guid...) |
| 1261 |
*/ |
| 1262 |
bool test_durable_v2_open_reopen2c(struct torture_context *tctx, |
| 1263 |
struct smb2_tree *tree) |
| 1264 |
{ |
| 1265 |
NTSTATUS status; |
| 1266 |
TALLOC_CTX *mem_ctx = talloc_new(tctx); |
| 1267 |
char fname[256]; |
| 1268 |
struct smb2_handle _h; |
| 1269 |
struct smb2_handle *h = NULL; |
| 1270 |
struct smb2_create io; |
| 1271 |
struct GUID create_guid = GUID_random(); |
| 1272 |
bool ret = true; |
| 1273 |
struct smbcli_options options; |
| 1274 |
|
| 1275 |
options = tree->session->transport->options; |
| 1276 |
|
| 1277 |
/* Choose a random name in case the state is left a little funky. */ |
| 1278 |
snprintf(fname, 256, "durable_v2_open_reopen2c_%s.dat", |
| 1279 |
generate_random_str(tctx, 8)); |
| 1280 |
|
| 1281 |
smb2_util_unlink(tree, fname); |
| 1282 |
|
| 1283 |
smb2_oplock_create_share(&io, fname, |
| 1284 |
smb2_util_share_access(""), |
| 1285 |
smb2_util_oplock_level("b")); |
| 1286 |
io.in.durable_open = true; |
| 1287 |
io.in.durable_open_v2 = false; |
| 1288 |
io.in.persistent_open = false; |
| 1289 |
io.in.create_guid = create_guid; |
| 1290 |
io.in.timeout = UINT32_MAX; |
| 1291 |
|
| 1292 |
status = smb2_create(tree, mem_ctx, &io); |
| 1293 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 1294 |
_h = io.out.file.handle; |
| 1295 |
h = &_h; |
| 1296 |
CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE); |
| 1297 |
CHECK_VAL(io.out.oplock_level, smb2_util_oplock_level("b")); |
| 1298 |
CHECK_VAL(io.out.durable_open, true); |
| 1299 |
CHECK_VAL(io.out.durable_open_v2, false); |
| 1300 |
CHECK_VAL(io.out.persistent_open, false); |
| 1301 |
CHECK_VAL(io.out.timeout, 0); |
| 1302 |
|
| 1303 |
/* disconnect, leaving the durable open */ |
| 1304 |
TALLOC_FREE(tree); |
| 1305 |
|
| 1306 |
if (!torture_smb2_connection_ext(tctx, 0, &options, &tree)) { |
| 1307 |
torture_warning(tctx, "couldn't reconnect, bailing\n"); |
| 1308 |
ret = false; |
| 1309 |
goto done; |
| 1310 |
} |
| 1311 |
|
| 1312 |
ZERO_STRUCT(io); |
| 1313 |
io.in.fname = fname; |
| 1314 |
io.in.durable_handle_v2 = h; /* durable v2 reconnect */ |
| 1315 |
io.in.create_guid = create_guid; |
| 1316 |
status = smb2_create(tree, mem_ctx, &io); |
| 1317 |
CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND); |
| 1318 |
|
| 1319 |
done: |
| 1320 |
if (h != NULL) { |
| 1321 |
smb2_util_close(tree, *h); |
| 1322 |
} |
| 1323 |
|
| 1324 |
smb2_util_unlink(tree, fname); |
| 1325 |
|
| 1326 |
talloc_free(tree); |
| 1327 |
|
| 1328 |
talloc_free(mem_ctx); |
| 1329 |
|
| 1330 |
return ret; |
| 1331 |
} |
| 1332 |
|
| 1333 |
/** |
| 1334 |
* lease variant of reopen2 |
| 1335 |
* basic test for doing a durable open |
| 1336 |
* tcp disconnect, reconnect, do a durable reopen (succeeds) |
| 1337 |
*/ |
| 1338 |
bool test_durable_v2_open_reopen2_lease(struct torture_context *tctx, |
| 1339 |
struct smb2_tree *tree) |
| 1340 |
{ |
| 1341 |
NTSTATUS status; |
| 1342 |
TALLOC_CTX *mem_ctx = talloc_new(tctx); |
| 1343 |
char fname[256]; |
| 1344 |
struct smb2_handle _h; |
| 1345 |
struct smb2_handle *h = NULL; |
| 1346 |
struct smb2_create io; |
| 1347 |
struct GUID create_guid = GUID_random(); |
| 1348 |
struct smb2_lease ls; |
| 1349 |
uint64_t lease_key; |
| 1350 |
bool ret = true; |
| 1351 |
struct smbcli_options options; |
| 1352 |
uint32_t caps; |
| 1353 |
|
| 1354 |
caps = smb2cli_conn_server_capabilities(tree->session->transport->conn); |
| 1355 |
if (!(caps & SMB2_CAP_LEASING)) { |
| 1356 |
torture_skip(tctx, "leases are not supported"); |
| 1357 |
} |
| 1358 |
|
| 1359 |
options = tree->session->transport->options; |
| 1360 |
|
| 1361 |
/* Choose a random name in case the state is left a little funky. */ |
| 1362 |
snprintf(fname, 256, "durable_v2_open_reopen2_%s.dat", |
| 1363 |
generate_random_str(tctx, 8)); |
| 1364 |
|
| 1365 |
smb2_util_unlink(tree, fname); |
| 1366 |
|
| 1367 |
lease_key = generate_random_u64(); |
| 1368 |
smb2_lease_create(&io, &ls, false /* dir */, fname, |
| 1369 |
lease_key, smb2_util_lease_state("RWH")); |
| 1370 |
io.in.durable_open = false; |
| 1371 |
io.in.durable_open_v2 = true; |
| 1372 |
io.in.persistent_open = false; |
| 1373 |
io.in.create_guid = create_guid; |
| 1374 |
io.in.timeout = UINT32_MAX; |
| 1375 |
|
| 1376 |
status = smb2_create(tree, mem_ctx, &io); |
| 1377 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 1378 |
_h = io.out.file.handle; |
| 1379 |
h = &_h; |
| 1380 |
CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE); |
| 1381 |
CHECK_VAL(io.out.durable_open, false); |
| 1382 |
CHECK_VAL(io.out.durable_open_v2, true); |
| 1383 |
CHECK_VAL(io.out.persistent_open, false); |
| 1384 |
CHECK_VAL(io.out.timeout, 300*1000); |
| 1385 |
CHECK_VAL(io.out.oplock_level, SMB2_OPLOCK_LEVEL_LEASE); |
| 1386 |
CHECK_VAL(io.out.lease_response.lease_key.data[0], lease_key); |
| 1387 |
CHECK_VAL(io.out.lease_response.lease_key.data[1], ~lease_key); |
| 1388 |
CHECK_VAL(io.out.lease_response.lease_state, |
| 1389 |
smb2_util_lease_state("RWH")); |
| 1390 |
CHECK_VAL(io.out.lease_response.lease_flags, 0); |
| 1391 |
CHECK_VAL(io.out.lease_response.lease_duration, 0); |
| 1392 |
|
| 1393 |
/* disconnect, reconnect and then do durable reopen */ |
| 1394 |
TALLOC_FREE(tree); |
| 1395 |
|
| 1396 |
if (!torture_smb2_connection_ext(tctx, 0, &options, &tree)) { |
| 1397 |
torture_warning(tctx, "couldn't reconnect, bailing\n"); |
| 1398 |
ret = false; |
| 1399 |
goto done; |
| 1400 |
} |
| 1401 |
|
| 1402 |
/* a few failure tests: */ |
| 1403 |
|
| 1404 |
/* |
| 1405 |
* several attempts without lease attached: |
| 1406 |
* all fail with NT_STATUS_OBJECT_NAME_NOT_FOUND |
| 1407 |
* irrespective of file name provided |
| 1408 |
*/ |
| 1409 |
|
| 1410 |
ZERO_STRUCT(io); |
| 1411 |
io.in.fname = ""; |
| 1412 |
io.in.durable_handle_v2 = h; |
| 1413 |
status = smb2_create(tree, mem_ctx, &io); |
| 1414 |
CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND); |
| 1415 |
|
| 1416 |
ZERO_STRUCT(io); |
| 1417 |
io.in.fname = "__non_existing_fname__"; |
| 1418 |
io.in.durable_handle_v2 = h; |
| 1419 |
status = smb2_create(tree, mem_ctx, &io); |
| 1420 |
CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND); |
| 1421 |
|
| 1422 |
ZERO_STRUCT(io); |
| 1423 |
io.in.fname = fname; |
| 1424 |
io.in.durable_handle_v2 = h; |
| 1425 |
status = smb2_create(tree, mem_ctx, &io); |
| 1426 |
CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND); |
| 1427 |
|
| 1428 |
/* |
| 1429 |
* attempt with lease provided, but |
| 1430 |
* with a changed lease key. => fails |
| 1431 |
*/ |
| 1432 |
ZERO_STRUCT(io); |
| 1433 |
io.in.fname = fname; |
| 1434 |
io.in.durable_open_v2 = false; |
| 1435 |
io.in.durable_handle_v2 = h; |
| 1436 |
io.in.create_guid = create_guid; |
| 1437 |
io.in.lease_request = &ls; |
| 1438 |
io.in.oplock_level = SMB2_OPLOCK_LEVEL_LEASE; |
| 1439 |
/* a wrong lease key lets the request fail */ |
| 1440 |
ls.lease_key.data[0]++; |
| 1441 |
|
| 1442 |
status = smb2_create(tree, mem_ctx, &io); |
| 1443 |
CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND); |
| 1444 |
|
| 1445 |
/* restore the correct lease key */ |
| 1446 |
ls.lease_key.data[0]--; |
| 1447 |
|
| 1448 |
/* |
| 1449 |
* this last failing attempt is almost correct: |
| 1450 |
* only problem is: we use the wrong filename... |
| 1451 |
* Note that this gives INVALID_PARAMETER. |
| 1452 |
* This is different from oplocks! |
| 1453 |
*/ |
| 1454 |
ZERO_STRUCT(io); |
| 1455 |
io.in.fname = "__non_existing_fname__"; |
| 1456 |
io.in.durable_open_v2 = false; |
| 1457 |
io.in.durable_handle_v2 = h; |
| 1458 |
io.in.create_guid = create_guid; |
| 1459 |
io.in.lease_request = &ls; |
| 1460 |
io.in.oplock_level = SMB2_OPLOCK_LEVEL_LEASE; |
| 1461 |
|
| 1462 |
status = smb2_create(tree, mem_ctx, &io); |
| 1463 |
CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER); |
| 1464 |
|
| 1465 |
/* |
| 1466 |
* Now for a succeeding reconnect: |
| 1467 |
*/ |
| 1468 |
|
| 1469 |
ZERO_STRUCT(io); |
| 1470 |
io.in.fname = fname; |
| 1471 |
io.in.durable_open_v2 = false; |
| 1472 |
io.in.durable_handle_v2 = h; |
| 1473 |
io.in.create_guid = create_guid; |
| 1474 |
io.in.lease_request = &ls; |
| 1475 |
io.in.oplock_level = SMB2_OPLOCK_LEVEL_LEASE; |
| 1476 |
|
| 1477 |
/* the requested lease state is irrelevant */ |
| 1478 |
ls.lease_state = smb2_util_lease_state(""); |
| 1479 |
|
| 1480 |
h = NULL; |
| 1481 |
|
| 1482 |
status = smb2_create(tree, mem_ctx, &io); |
| 1483 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 1484 |
|
| 1485 |
CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE); |
| 1486 |
CHECK_VAL(io.out.durable_open, false); |
| 1487 |
CHECK_VAL(io.out.durable_open_v2, false); /* no dh2q response blob */ |
| 1488 |
CHECK_VAL(io.out.persistent_open, false); |
| 1489 |
CHECK_VAL(io.out.oplock_level, SMB2_OPLOCK_LEVEL_LEASE); |
| 1490 |
CHECK_VAL(io.out.lease_response.lease_key.data[0], lease_key); |
| 1491 |
CHECK_VAL(io.out.lease_response.lease_key.data[1], ~lease_key); |
| 1492 |
CHECK_VAL(io.out.lease_response.lease_state, |
| 1493 |
smb2_util_lease_state("RWH")); |
| 1494 |
CHECK_VAL(io.out.lease_response.lease_flags, 0); |
| 1495 |
CHECK_VAL(io.out.lease_response.lease_duration, 0); |
| 1496 |
_h = io.out.file.handle; |
| 1497 |
h = &_h; |
| 1498 |
|
| 1499 |
/* disconnect one more time */ |
| 1500 |
TALLOC_FREE(tree); |
| 1501 |
|
| 1502 |
if (!torture_smb2_connection_ext(tctx, 0, &options, &tree)) { |
| 1503 |
torture_warning(tctx, "couldn't reconnect, bailing\n"); |
| 1504 |
ret = false; |
| 1505 |
goto done; |
| 1506 |
} |
| 1507 |
|
| 1508 |
/* |
| 1509 |
* demonstrate that various parameters are ignored |
| 1510 |
* in the reconnect |
| 1511 |
*/ |
| 1512 |
|
| 1513 |
ZERO_STRUCT(io); |
| 1514 |
/* |
| 1515 |
* These are completely ignored by the server |
| 1516 |
*/ |
| 1517 |
io.in.security_flags = 0x78; |
| 1518 |
io.in.oplock_level = 0x78; |
| 1519 |
io.in.impersonation_level = 0x12345678; |
| 1520 |
io.in.create_flags = 0x12345678; |
| 1521 |
io.in.reserved = 0x12345678; |
| 1522 |
io.in.desired_access = 0x12345678; |
| 1523 |
io.in.file_attributes = 0x12345678; |
| 1524 |
io.in.share_access = 0x12345678; |
| 1525 |
io.in.create_disposition = 0x12345678; |
| 1526 |
io.in.create_options = 0x12345678; |
| 1527 |
|
| 1528 |
/* |
| 1529 |
* only these are checked: |
| 1530 |
* - io.in.fname |
| 1531 |
* - io.in.durable_handle_v2, |
| 1532 |
* - io.in.create_guid |
| 1533 |
* - io.in.lease_request->lease_key |
| 1534 |
*/ |
| 1535 |
|
| 1536 |
io.in.fname = fname; |
| 1537 |
io.in.durable_open_v2 = false; |
| 1538 |
io.in.durable_handle_v2 = h; |
| 1539 |
io.in.create_guid = create_guid; |
| 1540 |
io.in.lease_request = &ls; |
| 1541 |
|
| 1542 |
/* the requested lease state is irrelevant */ |
| 1543 |
ls.lease_state = smb2_util_lease_state(""); |
| 1544 |
|
| 1545 |
h = NULL; |
| 1546 |
|
| 1547 |
status = smb2_create(tree, mem_ctx, &io); |
| 1548 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 1549 |
|
| 1550 |
CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE); |
| 1551 |
CHECK_VAL(io.out.durable_open, false); |
| 1552 |
CHECK_VAL(io.out.durable_open_v2, false); /* no dh2q response blob */ |
| 1553 |
CHECK_VAL(io.out.persistent_open, false); |
| 1554 |
CHECK_VAL(io.out.oplock_level, SMB2_OPLOCK_LEVEL_LEASE); |
| 1555 |
CHECK_VAL(io.out.lease_response.lease_key.data[0], lease_key); |
| 1556 |
CHECK_VAL(io.out.lease_response.lease_key.data[1], ~lease_key); |
| 1557 |
CHECK_VAL(io.out.lease_response.lease_state, |
| 1558 |
smb2_util_lease_state("RWH")); |
| 1559 |
CHECK_VAL(io.out.lease_response.lease_flags, 0); |
| 1560 |
CHECK_VAL(io.out.lease_response.lease_duration, 0); |
| 1561 |
|
| 1562 |
_h = io.out.file.handle; |
| 1563 |
h = &_h; |
| 1564 |
|
| 1565 |
done: |
| 1566 |
if (h != NULL) { |
| 1567 |
smb2_util_close(tree, *h); |
| 1568 |
} |
| 1569 |
|
| 1570 |
smb2_util_unlink(tree, fname); |
| 1571 |
|
| 1572 |
talloc_free(tree); |
| 1573 |
|
| 1574 |
talloc_free(mem_ctx); |
| 1575 |
|
| 1576 |
return ret; |
| 1577 |
} |
| 1578 |
|
| 1579 |
/** |
| 1580 |
* lease_v2 variant of reopen2 |
| 1581 |
* basic test for doing a durable open |
| 1582 |
* tcp disconnect, reconnect, do a durable reopen (succeeds) |
| 1583 |
*/ |
| 1584 |
bool test_durable_v2_open_reopen2_lease_v2(struct torture_context *tctx, |
| 1585 |
struct smb2_tree *tree) |
| 1586 |
{ |
| 1587 |
NTSTATUS status; |
| 1588 |
TALLOC_CTX *mem_ctx = talloc_new(tctx); |
| 1589 |
char fname[256]; |
| 1590 |
struct smb2_handle _h; |
| 1591 |
struct smb2_handle *h = NULL; |
| 1592 |
struct smb2_create io; |
| 1593 |
struct GUID create_guid = GUID_random(); |
| 1594 |
struct smb2_lease ls; |
| 1595 |
uint64_t lease_key; |
| 1596 |
bool ret = true; |
| 1597 |
struct smbcli_options options; |
| 1598 |
uint32_t caps; |
| 1599 |
|
| 1600 |
caps = smb2cli_conn_server_capabilities(tree->session->transport->conn); |
| 1601 |
if (!(caps & SMB2_CAP_LEASING)) { |
| 1602 |
torture_skip(tctx, "leases are not supported"); |
| 1603 |
} |
| 1604 |
|
| 1605 |
options = tree->session->transport->options; |
| 1606 |
|
| 1607 |
smb2_deltree(tree, __func__); |
| 1608 |
status = torture_smb2_testdir(tree, __func__, &_h); |
| 1609 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 1610 |
"torture_smb2_testdir failed\n"); |
| 1611 |
smb2_util_close(tree, _h); |
| 1612 |
|
| 1613 |
/* Choose a random name in case the state is left a little funky. */ |
| 1614 |
snprintf(fname, 256, "%s\\durable_v2_open_reopen2_%s.dat", |
| 1615 |
__func__, generate_random_str(tctx, 8)); |
| 1616 |
|
| 1617 |
smb2_util_unlink(tree, fname); |
| 1618 |
|
| 1619 |
lease_key = random(); |
| 1620 |
smb2_lease_v2_create(&io, &ls, false /* dir */, fname, |
| 1621 |
lease_key, 0, /* parent lease key */ |
| 1622 |
smb2_util_lease_state("RWH"), 0 /* lease epoch */); |
| 1623 |
io.in.durable_open = false; |
| 1624 |
io.in.durable_open_v2 = true; |
| 1625 |
io.in.persistent_open = false; |
| 1626 |
io.in.create_guid = create_guid; |
| 1627 |
io.in.timeout = UINT32_MAX; |
| 1628 |
|
| 1629 |
status = smb2_create(tree, mem_ctx, &io); |
| 1630 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 1631 |
_h = io.out.file.handle; |
| 1632 |
h = &_h; |
| 1633 |
CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE); |
| 1634 |
CHECK_VAL(io.out.durable_open, false); |
| 1635 |
CHECK_VAL(io.out.durable_open_v2, true); |
| 1636 |
CHECK_VAL(io.out.persistent_open, false); |
| 1637 |
CHECK_VAL(io.out.timeout, 300*1000); |
| 1638 |
CHECK_VAL(io.out.oplock_level, SMB2_OPLOCK_LEVEL_LEASE); |
| 1639 |
CHECK_VAL(io.out.lease_response_v2.lease_key.data[0], lease_key); |
| 1640 |
CHECK_VAL(io.out.lease_response_v2.lease_key.data[1], ~lease_key); |
| 1641 |
|
| 1642 |
/* disconnect, reconnect and then do durable reopen */ |
| 1643 |
TALLOC_FREE(tree); |
| 1644 |
|
| 1645 |
if (!torture_smb2_connection_ext(tctx, 0, &options, &tree)) { |
| 1646 |
torture_warning(tctx, "couldn't reconnect, bailing\n"); |
| 1647 |
ret = false; |
| 1648 |
goto done; |
| 1649 |
} |
| 1650 |
|
| 1651 |
/* a few failure tests: */ |
| 1652 |
|
| 1653 |
/* |
| 1654 |
* several attempts without lease attached: |
| 1655 |
* all fail with NT_STATUS_OBJECT_NAME_NOT_FOUND |
| 1656 |
* irrespective of file name provided |
| 1657 |
*/ |
| 1658 |
|
| 1659 |
ZERO_STRUCT(io); |
| 1660 |
io.in.fname = ""; |
| 1661 |
io.in.durable_handle_v2 = h; |
| 1662 |
status = smb2_create(tree, mem_ctx, &io); |
| 1663 |
CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND); |
| 1664 |
|
| 1665 |
ZERO_STRUCT(io); |
| 1666 |
io.in.fname = "__non_existing_fname__"; |
| 1667 |
io.in.durable_handle_v2 = h; |
| 1668 |
status = smb2_create(tree, mem_ctx, &io); |
| 1669 |
CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND); |
| 1670 |
|
| 1671 |
ZERO_STRUCT(io); |
| 1672 |
io.in.fname = fname; |
| 1673 |
io.in.durable_handle_v2 = h; |
| 1674 |
status = smb2_create(tree, mem_ctx, &io); |
| 1675 |
CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND); |
| 1676 |
|
| 1677 |
/* |
| 1678 |
* attempt with lease provided, but |
| 1679 |
* with a changed lease key. => fails |
| 1680 |
*/ |
| 1681 |
ZERO_STRUCT(io); |
| 1682 |
io.in.fname = fname; |
| 1683 |
io.in.durable_open_v2 = false; |
| 1684 |
io.in.durable_handle_v2 = h; |
| 1685 |
io.in.create_guid = create_guid; |
| 1686 |
io.in.lease_request_v2 = &ls; |
| 1687 |
io.in.oplock_level = SMB2_OPLOCK_LEVEL_LEASE; |
| 1688 |
/* a wrong lease key lets the request fail */ |
| 1689 |
ls.lease_key.data[0]++; |
| 1690 |
|
| 1691 |
status = smb2_create(tree, mem_ctx, &io); |
| 1692 |
CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND); |
| 1693 |
|
| 1694 |
/* restore the correct lease key */ |
| 1695 |
ls.lease_key.data[0]--; |
| 1696 |
|
| 1697 |
|
| 1698 |
/* |
| 1699 |
* this last failing attempt is almost correct: |
| 1700 |
* only problem is: we use the wrong filename... |
| 1701 |
* Note that this gives INVALID_PARAMETER. |
| 1702 |
* This is different from oplocks! |
| 1703 |
*/ |
| 1704 |
ZERO_STRUCT(io); |
| 1705 |
io.in.fname = "__non_existing_fname__"; |
| 1706 |
io.in.durable_open_v2 = false; |
| 1707 |
io.in.durable_handle_v2 = h; |
| 1708 |
io.in.create_guid = create_guid; |
| 1709 |
io.in.lease_request_v2 = &ls; |
| 1710 |
io.in.oplock_level = SMB2_OPLOCK_LEVEL_LEASE; |
| 1711 |
|
| 1712 |
status = smb2_create(tree, mem_ctx, &io); |
| 1713 |
CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER); |
| 1714 |
|
| 1715 |
/* |
| 1716 |
* Now for a succeeding reconnect: |
| 1717 |
*/ |
| 1718 |
|
| 1719 |
ZERO_STRUCT(io); |
| 1720 |
io.in.fname = fname; |
| 1721 |
io.in.durable_open_v2 = false; |
| 1722 |
io.in.durable_handle_v2 = h; |
| 1723 |
io.in.create_guid = create_guid; |
| 1724 |
io.in.lease_request_v2 = &ls; |
| 1725 |
io.in.oplock_level = SMB2_OPLOCK_LEVEL_LEASE; |
| 1726 |
|
| 1727 |
/* the requested lease state is irrelevant */ |
| 1728 |
ls.lease_state = smb2_util_lease_state(""); |
| 1729 |
|
| 1730 |
h = NULL; |
| 1731 |
|
| 1732 |
status = smb2_create(tree, mem_ctx, &io); |
| 1733 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 1734 |
|
| 1735 |
CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE); |
| 1736 |
CHECK_VAL(io.out.durable_open, false); |
| 1737 |
CHECK_VAL(io.out.durable_open_v2, false); /* no dh2q response blob */ |
| 1738 |
CHECK_VAL(io.out.persistent_open, false); |
| 1739 |
CHECK_VAL(io.out.oplock_level, SMB2_OPLOCK_LEVEL_LEASE); |
| 1740 |
CHECK_VAL(io.out.lease_response_v2.lease_key.data[0], lease_key); |
| 1741 |
CHECK_VAL(io.out.lease_response_v2.lease_key.data[1], ~lease_key); |
| 1742 |
CHECK_VAL(io.out.lease_response_v2.lease_state, |
| 1743 |
smb2_util_lease_state("RWH")); |
| 1744 |
CHECK_VAL(io.out.lease_response_v2.lease_flags, 0); |
| 1745 |
CHECK_VAL(io.out.lease_response_v2.lease_duration, 0); |
| 1746 |
_h = io.out.file.handle; |
| 1747 |
h = &_h; |
| 1748 |
|
| 1749 |
/* disconnect one more time */ |
| 1750 |
TALLOC_FREE(tree); |
| 1751 |
|
| 1752 |
if (!torture_smb2_connection_ext(tctx, 0, &options, &tree)) { |
| 1753 |
torture_warning(tctx, "couldn't reconnect, bailing\n"); |
| 1754 |
ret = false; |
| 1755 |
goto done; |
| 1756 |
} |
| 1757 |
|
| 1758 |
/* |
| 1759 |
* demonstrate that various parameters are ignored |
| 1760 |
* in the reconnect |
| 1761 |
*/ |
| 1762 |
|
| 1763 |
ZERO_STRUCT(io); |
| 1764 |
/* |
| 1765 |
* These are completely ignored by the server |
| 1766 |
*/ |
| 1767 |
io.in.security_flags = 0x78; |
| 1768 |
io.in.oplock_level = 0x78; |
| 1769 |
io.in.impersonation_level = 0x12345678; |
| 1770 |
io.in.create_flags = 0x12345678; |
| 1771 |
io.in.reserved = 0x12345678; |
| 1772 |
io.in.desired_access = 0x12345678; |
| 1773 |
io.in.file_attributes = 0x12345678; |
| 1774 |
io.in.share_access = 0x12345678; |
| 1775 |
io.in.create_disposition = 0x12345678; |
| 1776 |
io.in.create_options = 0x12345678; |
| 1777 |
io.in.fname = "__non_existing_fname__"; |
| 1778 |
|
| 1779 |
/* |
| 1780 |
* only these are checked: |
| 1781 |
* - io.in.fname |
| 1782 |
* - io.in.durable_handle_v2, |
| 1783 |
* - io.in.create_guid |
| 1784 |
* - io.in.lease_request_v2->lease_key |
| 1785 |
*/ |
| 1786 |
|
| 1787 |
io.in.fname = fname; |
| 1788 |
io.in.durable_open_v2 = false; |
| 1789 |
io.in.durable_handle_v2 = h; |
| 1790 |
io.in.create_guid = create_guid; |
| 1791 |
io.in.lease_request_v2 = &ls; |
| 1792 |
|
| 1793 |
/* the requested lease state is irrelevant */ |
| 1794 |
ls.lease_state = smb2_util_lease_state(""); |
| 1795 |
|
| 1796 |
h = NULL; |
| 1797 |
|
| 1798 |
status = smb2_create(tree, mem_ctx, &io); |
| 1799 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 1800 |
CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE); |
| 1801 |
CHECK_VAL(io.out.durable_open, false); |
| 1802 |
CHECK_VAL(io.out.durable_open_v2, false); /* no dh2q response blob */ |
| 1803 |
CHECK_VAL(io.out.persistent_open, false); |
| 1804 |
CHECK_VAL(io.out.oplock_level, SMB2_OPLOCK_LEVEL_LEASE); |
| 1805 |
CHECK_VAL(io.out.lease_response_v2.lease_key.data[0], lease_key); |
| 1806 |
CHECK_VAL(io.out.lease_response_v2.lease_key.data[1], ~lease_key); |
| 1807 |
CHECK_VAL(io.out.lease_response_v2.lease_state, |
| 1808 |
smb2_util_lease_state("RWH")); |
| 1809 |
CHECK_VAL(io.out.lease_response_v2.lease_flags, 0); |
| 1810 |
CHECK_VAL(io.out.lease_response_v2.lease_duration, 0); |
| 1811 |
|
| 1812 |
_h = io.out.file.handle; |
| 1813 |
h = &_h; |
| 1814 |
|
| 1815 |
done: |
| 1816 |
if (h != NULL) { |
| 1817 |
smb2_util_close(tree, *h); |
| 1818 |
} |
| 1819 |
|
| 1820 |
smb2_util_unlink(tree, fname); |
| 1821 |
smb2_deltree(tree, __func__); |
| 1822 |
|
| 1823 |
talloc_free(tree); |
| 1824 |
|
| 1825 |
talloc_free(mem_ctx); |
| 1826 |
|
| 1827 |
return ret; |
| 1828 |
} |
| 1829 |
|
| 1830 |
/* |
| 1831 |
Open(BATCH), take BRL, disconnect, reconnect. |
| 1832 |
*/ |
| 1833 |
static bool test_durable_v2_open_lock_oplock(struct torture_context *tctx, |
| 1834 |
struct smb2_tree *tree) |
| 1835 |
{ |
| 1836 |
TALLOC_CTX *mem_ctx = talloc_new(tctx); |
| 1837 |
struct smb2_create io; |
| 1838 |
struct GUID create_guid = GUID_random(); |
| 1839 |
struct smb2_handle h = {{0}}; |
| 1840 |
struct smb2_lock lck; |
| 1841 |
struct smb2_lock_element el[2]; |
| 1842 |
NTSTATUS status; |
| 1843 |
char fname[256]; |
| 1844 |
bool ret = true; |
| 1845 |
struct smbcli_options options; |
| 1846 |
|
| 1847 |
options = tree->session->transport->options; |
| 1848 |
|
| 1849 |
snprintf(fname, 256, "durable_v2_open_lock_oplock_%s.dat", generate_random_str(tctx, 8)); |
| 1850 |
|
| 1851 |
/* Clean slate */ |
| 1852 |
smb2_util_unlink(tree, fname); |
| 1853 |
|
| 1854 |
/* Create with lease */ |
| 1855 |
|
| 1856 |
smb2_oplock_create_share(&io, fname, |
| 1857 |
smb2_util_share_access(""), |
| 1858 |
smb2_util_oplock_level("b")); |
| 1859 |
io.in.durable_open = false; |
| 1860 |
io.in.durable_open_v2 = true; |
| 1861 |
io.in.persistent_open = false; |
| 1862 |
io.in.create_guid = create_guid; |
| 1863 |
io.in.timeout = UINT32_MAX; |
| 1864 |
|
| 1865 |
status = smb2_create(tree, mem_ctx, &io); |
| 1866 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 1867 |
h = io.out.file.handle; |
| 1868 |
CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE); |
| 1869 |
CHECK_VAL(io.out.durable_open, false); |
| 1870 |
CHECK_VAL(io.out.durable_open_v2, true); |
| 1871 |
CHECK_VAL(io.out.persistent_open, false); |
| 1872 |
CHECK_VAL(io.out.oplock_level, smb2_util_oplock_level("b")); |
| 1873 |
|
| 1874 |
ZERO_STRUCT(lck); |
| 1875 |
ZERO_STRUCT(el); |
| 1876 |
lck.in.locks = el; |
| 1877 |
lck.in.lock_count = 0x0001; |
| 1878 |
lck.in.lock_sequence = 0x00000000; |
| 1879 |
lck.in.file.handle = h; |
| 1880 |
el[0].offset = 0; |
| 1881 |
el[0].length = 1; |
| 1882 |
el[0].reserved = 0x00000000; |
| 1883 |
el[0].flags = SMB2_LOCK_FLAG_EXCLUSIVE; |
| 1884 |
status = smb2_lock(tree, &lck); |
| 1885 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 1886 |
|
| 1887 |
/* Disconnect/Reconnect. */ |
| 1888 |
talloc_free(tree); |
| 1889 |
tree = NULL; |
| 1890 |
|
| 1891 |
if (!torture_smb2_connection_ext(tctx, 0, &options, &tree)) { |
| 1892 |
torture_warning(tctx, "couldn't reconnect, bailing\n"); |
| 1893 |
ret = false; |
| 1894 |
goto done; |
| 1895 |
} |
| 1896 |
|
| 1897 |
ZERO_STRUCT(io); |
| 1898 |
io.in.fname = fname; |
| 1899 |
io.in.durable_open_v2 = false; |
| 1900 |
io.in.durable_handle_v2 = &h; |
| 1901 |
io.in.create_guid = create_guid; |
| 1902 |
|
| 1903 |
status = smb2_create(tree, mem_ctx, &io); |
| 1904 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 1905 |
h = io.out.file.handle; |
| 1906 |
CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE); |
| 1907 |
CHECK_VAL(io.out.durable_open, false); |
| 1908 |
CHECK_VAL(io.out.durable_open_v2, false); /* no dh2q response blob */ |
| 1909 |
CHECK_VAL(io.out.persistent_open, false); |
| 1910 |
CHECK_VAL(io.out.oplock_level, smb2_util_oplock_level("b")); |
| 1911 |
|
| 1912 |
lck.in.file.handle = h; |
| 1913 |
el[0].flags = SMB2_LOCK_FLAG_UNLOCK; |
| 1914 |
status = smb2_lock(tree, &lck); |
| 1915 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 1916 |
|
| 1917 |
done: |
| 1918 |
smb2_util_close(tree, h); |
| 1919 |
smb2_util_unlink(tree, fname); |
| 1920 |
talloc_free(tree); |
| 1921 |
|
| 1922 |
return ret; |
| 1923 |
} |
| 1924 |
|
| 1925 |
/* |
| 1926 |
Open(RWH), take BRL, disconnect, reconnect. |
| 1927 |
*/ |
| 1928 |
static bool test_durable_v2_open_lock_lease(struct torture_context *tctx, |
| 1929 |
struct smb2_tree *tree) |
| 1930 |
{ |
| 1931 |
TALLOC_CTX *mem_ctx = talloc_new(tctx); |
| 1932 |
struct smb2_create io; |
| 1933 |
struct smb2_lease ls; |
| 1934 |
struct GUID create_guid = GUID_random(); |
| 1935 |
struct smb2_handle h = {{0}}; |
| 1936 |
struct smb2_lock lck; |
| 1937 |
struct smb2_lock_element el[2]; |
| 1938 |
NTSTATUS status; |
| 1939 |
char fname[256]; |
| 1940 |
bool ret = true; |
| 1941 |
uint64_t lease; |
| 1942 |
uint32_t caps; |
| 1943 |
struct smbcli_options options; |
| 1944 |
|
| 1945 |
options = tree->session->transport->options; |
| 1946 |
|
| 1947 |
caps = smb2cli_conn_server_capabilities(tree->session->transport->conn); |
| 1948 |
if (!(caps & SMB2_CAP_LEASING)) { |
| 1949 |
torture_skip(tctx, "leases are not supported"); |
| 1950 |
} |
| 1951 |
|
| 1952 |
/* |
| 1953 |
* Choose a random name and random lease in case the state is left a |
| 1954 |
* little funky. |
| 1955 |
*/ |
| 1956 |
lease = random(); |
| 1957 |
snprintf(fname, 256, "durable_v2_open_lock_lease_%s.dat", generate_random_str(tctx, 8)); |
| 1958 |
|
| 1959 |
/* Clean slate */ |
| 1960 |
smb2_util_unlink(tree, fname); |
| 1961 |
|
| 1962 |
/* Create with lease */ |
| 1963 |
|
| 1964 |
smb2_lease_v2_create(&io, &ls, false /* dir */, fname, |
| 1965 |
lease, 0, /* parent lease key */ |
| 1966 |
smb2_util_lease_state("RWH"), 0 /* lease epoch */); |
| 1967 |
io.in.durable_open = false; |
| 1968 |
io.in.durable_open_v2 = true; |
| 1969 |
io.in.persistent_open = false; |
| 1970 |
io.in.create_guid = create_guid; |
| 1971 |
io.in.timeout = UINT32_MAX; |
| 1972 |
|
| 1973 |
status = smb2_create(tree, mem_ctx, &io); |
| 1974 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 1975 |
h = io.out.file.handle; |
| 1976 |
CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE); |
| 1977 |
CHECK_VAL(io.out.durable_open, false); |
| 1978 |
CHECK_VAL(io.out.durable_open_v2, true); |
| 1979 |
CHECK_VAL(io.out.persistent_open, false); |
| 1980 |
ls.lease_epoch += 1; |
| 1981 |
CHECK_LEASE_V2(&io, "RWH", true, lease, |
| 1982 |
0, 0, ls.lease_epoch); |
| 1983 |
|
| 1984 |
ZERO_STRUCT(lck); |
| 1985 |
ZERO_STRUCT(el); |
| 1986 |
lck.in.locks = el; |
| 1987 |
lck.in.lock_count = 0x0001; |
| 1988 |
lck.in.lock_sequence = 0x00000000; |
| 1989 |
lck.in.file.handle = h; |
| 1990 |
el[0].offset = 0; |
| 1991 |
el[0].length = 1; |
| 1992 |
el[0].reserved = 0x00000000; |
| 1993 |
el[0].flags = SMB2_LOCK_FLAG_EXCLUSIVE; |
| 1994 |
status = smb2_lock(tree, &lck); |
| 1995 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 1996 |
|
| 1997 |
/* Disconnect/Reconnect. */ |
| 1998 |
talloc_free(tree); |
| 1999 |
tree = NULL; |
| 2000 |
|
| 2001 |
if (!torture_smb2_connection_ext(tctx, 0, &options, &tree)) { |
| 2002 |
torture_warning(tctx, "couldn't reconnect, bailing\n"); |
| 2003 |
ret = false; |
| 2004 |
goto done; |
| 2005 |
} |
| 2006 |
|
| 2007 |
ZERO_STRUCT(io); |
| 2008 |
io.in.fname = fname; |
| 2009 |
io.in.durable_open_v2 = false; |
| 2010 |
io.in.durable_handle_v2 = &h; |
| 2011 |
io.in.create_guid = create_guid; |
| 2012 |
io.in.lease_request_v2 = &ls; |
| 2013 |
io.in.oplock_level = SMB2_OPLOCK_LEVEL_LEASE; |
| 2014 |
|
| 2015 |
status = smb2_create(tree, mem_ctx, &io); |
| 2016 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 2017 |
h = io.out.file.handle; |
| 2018 |
CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE); |
| 2019 |
CHECK_VAL(io.out.durable_open, false); |
| 2020 |
CHECK_VAL(io.out.durable_open_v2, false); /* no dh2q response blob */ |
| 2021 |
CHECK_VAL(io.out.persistent_open, false); |
| 2022 |
CHECK_LEASE_V2(&io, "RWH", true, lease, |
| 2023 |
0, 0, ls.lease_epoch); |
| 2024 |
|
| 2025 |
lck.in.file.handle = h; |
| 2026 |
el[0].flags = SMB2_LOCK_FLAG_UNLOCK; |
| 2027 |
status = smb2_lock(tree, &lck); |
| 2028 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 2029 |
|
| 2030 |
done: |
| 2031 |
smb2_util_close(tree, h); |
| 2032 |
smb2_util_unlink(tree, fname); |
| 2033 |
talloc_free(tree); |
| 2034 |
|
| 2035 |
return ret; |
| 2036 |
} |
| 2037 |
|
| 2038 |
/* |
| 2039 |
Open(RH), take BRL, disconnect, fails reconnect without W LEASE |
| 2040 |
*/ |
| 2041 |
static bool test_durable_v2_open_lock_noW_lease(struct torture_context *tctx, |
| 2042 |
struct smb2_tree *tree) |
| 2043 |
{ |
| 2044 |
TALLOC_CTX *mem_ctx = talloc_new(tctx); |
| 2045 |
struct smb2_create io; |
| 2046 |
struct smb2_lease ls; |
| 2047 |
struct GUID create_guid = GUID_random(); |
| 2048 |
struct smb2_handle h = {{0}}; |
| 2049 |
struct smb2_lock lck; |
| 2050 |
struct smb2_lock_element el[2]; |
| 2051 |
NTSTATUS status; |
| 2052 |
char fname[256]; |
| 2053 |
bool ret = true; |
| 2054 |
uint64_t lease; |
| 2055 |
uint32_t caps; |
| 2056 |
struct smbcli_options options; |
| 2057 |
|
| 2058 |
options = tree->session->transport->options; |
| 2059 |
|
| 2060 |
caps = smb2cli_conn_server_capabilities(tree->session->transport->conn); |
| 2061 |
if (!(caps & SMB2_CAP_LEASING)) { |
| 2062 |
torture_skip(tctx, "leases are not supported"); |
| 2063 |
} |
| 2064 |
|
| 2065 |
/* |
| 2066 |
* Choose a random name and random lease in case the state is left a |
| 2067 |
* little funky. |
| 2068 |
*/ |
| 2069 |
lease = random(); |
| 2070 |
snprintf(fname, 256, "durable_v2_open_lock_noW_lease_%s.dat", generate_random_str(tctx, 8)); |
| 2071 |
|
| 2072 |
/* Clean slate */ |
| 2073 |
smb2_util_unlink(tree, fname); |
| 2074 |
|
| 2075 |
/* Create with lease */ |
| 2076 |
|
| 2077 |
smb2_lease_v2_create(&io, &ls, false /* dir */, fname, |
| 2078 |
lease, 0, /* parent lease key */ |
| 2079 |
smb2_util_lease_state("RH"), 0 /* lease epoch */); |
| 2080 |
io.in.durable_open = false; |
| 2081 |
io.in.durable_open_v2 = true; |
| 2082 |
io.in.persistent_open = false; |
| 2083 |
io.in.create_guid = create_guid; |
| 2084 |
io.in.timeout = UINT32_MAX; |
| 2085 |
|
| 2086 |
status = smb2_create(tree, mem_ctx, &io); |
| 2087 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 2088 |
h = io.out.file.handle; |
| 2089 |
CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE); |
| 2090 |
CHECK_VAL(io.out.durable_open, false); |
| 2091 |
CHECK_VAL(io.out.durable_open_v2, true); |
| 2092 |
CHECK_VAL(io.out.persistent_open, false); |
| 2093 |
ls.lease_epoch += 1; |
| 2094 |
CHECK_LEASE_V2(&io, "RH", true, lease, |
| 2095 |
0, 0, ls.lease_epoch); |
| 2096 |
|
| 2097 |
ZERO_STRUCT(lck); |
| 2098 |
ZERO_STRUCT(el); |
| 2099 |
lck.in.locks = el; |
| 2100 |
lck.in.lock_count = 0x0001; |
| 2101 |
lck.in.lock_sequence = 0x00000000; |
| 2102 |
lck.in.file.handle = h; |
| 2103 |
el[0].offset = 0; |
| 2104 |
el[0].length = 1; |
| 2105 |
el[0].reserved = 0x00000000; |
| 2106 |
el[0].flags = SMB2_LOCK_FLAG_EXCLUSIVE; |
| 2107 |
status = smb2_lock(tree, &lck); |
| 2108 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 2109 |
|
| 2110 |
/* Disconnect/Reconnect. */ |
| 2111 |
talloc_free(tree); |
| 2112 |
tree = NULL; |
| 2113 |
|
| 2114 |
if (!torture_smb2_connection_ext(tctx, 0, &options, &tree)) { |
| 2115 |
torture_warning(tctx, "couldn't reconnect, bailing\n"); |
| 2116 |
ret = false; |
| 2117 |
goto done; |
| 2118 |
} |
| 2119 |
|
| 2120 |
ZERO_STRUCT(io); |
| 2121 |
io.in.fname = fname; |
| 2122 |
io.in.durable_open_v2 = false; |
| 2123 |
io.in.durable_handle_v2 = &h; |
| 2124 |
io.in.create_guid = create_guid; |
| 2125 |
io.in.lease_request_v2 = &ls; |
| 2126 |
io.in.oplock_level = SMB2_OPLOCK_LEVEL_LEASE; |
| 2127 |
|
| 2128 |
status = smb2_create(tree, mem_ctx, &io); |
| 2129 |
CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND); |
| 2130 |
|
| 2131 |
done: |
| 2132 |
smb2_util_close(tree, h); |
| 2133 |
smb2_util_unlink(tree, fname); |
| 2134 |
talloc_free(tree); |
| 2135 |
|
| 2136 |
return ret; |
| 2137 |
} |
| 2138 |
|
| 2139 |
/** |
| 2140 |
* 1. stat open (without lease) => h1 |
| 2141 |
* 2. durable open with RWH => h2 |
| 2142 |
* 3. disconnect |
| 2143 |
* 4. reconnect |
| 2144 |
* 5. durable reconnect RWH => h2 |
| 2145 |
*/ |
| 2146 |
static bool test_durable_v2_open_stat_and_lease(struct torture_context *tctx, |
| 2147 |
struct smb2_tree *tree1) |
| 2148 |
{ |
| 2149 |
TALLOC_CTX *mem_ctx = talloc_new(tctx); |
| 2150 |
NTSTATUS status; |
| 2151 |
char fname[256]; |
| 2152 |
struct smb2_handle dh; |
| 2153 |
struct smb2_handle _h1; |
| 2154 |
struct smb2_handle *h1 = NULL; |
| 2155 |
struct smb2_handle _h2; |
| 2156 |
struct smb2_handle *h2 = NULL; |
| 2157 |
struct smb2_create io; |
| 2158 |
struct GUID create_guid2 = GUID_random(); |
| 2159 |
struct smb2_lease ls; |
| 2160 |
uint64_t lease_key; |
| 2161 |
bool ret = true; |
| 2162 |
struct smbcli_options options1; |
| 2163 |
uint32_t caps; |
| 2164 |
|
| 2165 |
caps = smb2cli_conn_server_capabilities(tree1->session->transport->conn); |
| 2166 |
if (!(caps & SMB2_CAP_LEASING)) { |
| 2167 |
torture_skip(tctx, "leases are not supported"); |
| 2168 |
} |
| 2169 |
|
| 2170 |
options1 = tree1->session->transport->options; |
| 2171 |
|
| 2172 |
smb2_deltree(tree1, __func__); |
| 2173 |
status = torture_smb2_testdir(tree1, __func__, &dh); |
| 2174 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 2175 |
"torture_smb2_testdir failed\n"); |
| 2176 |
smb2_util_close(tree1, dh); |
| 2177 |
|
| 2178 |
/* Choose a random name in case the state is left a little funky. */ |
| 2179 |
snprintf(fname, 256, "%s\\file_%s.dat", |
| 2180 |
__func__, generate_random_str(tctx, 8)); |
| 2181 |
|
| 2182 |
smb2_util_unlink(tree1, fname); |
| 2183 |
|
| 2184 |
smb2_generic_create(&io, NULL, false /* dir */, fname, |
| 2185 |
FILE_OPEN_IF, 0, 0, 0); |
| 2186 |
io.in.desired_access = SEC_FILE_READ_ATTRIBUTE; |
| 2187 |
io.in.desired_access |= SEC_FILE_WRITE_ATTRIBUTE; |
| 2188 |
io.in.desired_access |= SEC_STD_SYNCHRONIZE; |
| 2189 |
|
| 2190 |
status = smb2_create(tree1, mem_ctx, &io); |
| 2191 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 2192 |
_h1 = io.out.file.handle; |
| 2193 |
h1 = &_h1; |
| 2194 |
CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE); |
| 2195 |
CHECK_VAL(io.out.durable_open, false); |
| 2196 |
CHECK_VAL(io.out.durable_open_v2, false); |
| 2197 |
CHECK_VAL(io.out.persistent_open, false); |
| 2198 |
CHECK_VAL(io.out.oplock_level, SMB2_OPLOCK_LEVEL_NONE); |
| 2199 |
|
| 2200 |
lease_key = random(); |
| 2201 |
smb2_lease_v2_create(&io, &ls, false /* dir */, fname, |
| 2202 |
lease_key, 0, /* parent lease key */ |
| 2203 |
smb2_util_lease_state("RWH"), 0 /* lease epoch */); |
| 2204 |
io.in.durable_open = false; |
| 2205 |
io.in.durable_open_v2 = true; |
| 2206 |
io.in.persistent_open = false; |
| 2207 |
io.in.create_guid = create_guid2; |
| 2208 |
io.in.timeout = UINT32_MAX; |
| 2209 |
|
| 2210 |
status = smb2_create(tree1, mem_ctx, &io); |
| 2211 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 2212 |
_h2 = io.out.file.handle; |
| 2213 |
h2 = &_h2; |
| 2214 |
CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE); |
| 2215 |
CHECK_VAL(io.out.durable_open, false); |
| 2216 |
CHECK_VAL(io.out.durable_open_v2, true); |
| 2217 |
CHECK_VAL(io.out.persistent_open, false); |
| 2218 |
CHECK_VAL(io.out.timeout, 300*1000); |
| 2219 |
ls.lease_epoch += 1; |
| 2220 |
CHECK_LEASE_V2(&io, "RWH", true, lease_key, |
| 2221 |
0, 0, ls.lease_epoch); |
| 2222 |
|
| 2223 |
/* disconnect, reconnect and then do durable reopen */ |
| 2224 |
TALLOC_FREE(tree1); |
| 2225 |
h1 = NULL; |
| 2226 |
|
| 2227 |
if (!torture_smb2_connection_ext(tctx, 0, &options1, &tree1)) { |
| 2228 |
torture_warning(tctx, "couldn't reconnect, bailing\n"); |
| 2229 |
ret = false; |
| 2230 |
goto done; |
| 2231 |
} |
| 2232 |
|
| 2233 |
ZERO_STRUCT(io); |
| 2234 |
io.in.fname = fname; |
| 2235 |
io.in.durable_open_v2 = false; |
| 2236 |
io.in.durable_handle_v2 = h2; |
| 2237 |
io.in.create_guid = create_guid2; |
| 2238 |
io.in.lease_request_v2 = &ls; |
| 2239 |
io.in.oplock_level = SMB2_OPLOCK_LEVEL_LEASE; |
| 2240 |
|
| 2241 |
status = smb2_create(tree1, mem_ctx, &io); |
| 2242 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 2243 |
_h2 = io.out.file.handle; |
| 2244 |
h2 = &_h2; |
| 2245 |
CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE); |
| 2246 |
CHECK_VAL(io.out.durable_open, false); |
| 2247 |
CHECK_VAL(io.out.durable_open_v2, false); /* no dh2q response blob */ |
| 2248 |
CHECK_VAL(io.out.persistent_open, false); |
| 2249 |
CHECK_LEASE_V2(&io, "RWH", true, lease_key, |
| 2250 |
0, 0, ls.lease_epoch); |
| 2251 |
|
| 2252 |
status = smb2_util_close(tree1, *h2); |
| 2253 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 2254 |
h2 = NULL; |
| 2255 |
|
| 2256 |
done: |
| 2257 |
if (tree1 != NULL) { |
| 2258 |
smb2_keepalive(tree1->session->transport); |
| 2259 |
} |
| 2260 |
|
| 2261 |
if (tree1 != NULL && h1 != NULL) { |
| 2262 |
smb2_util_close(tree1, *h1); |
| 2263 |
} |
| 2264 |
if (tree1 != NULL && h2 != NULL) { |
| 2265 |
smb2_util_close(tree1, *h2); |
| 2266 |
} |
| 2267 |
|
| 2268 |
if (tree1 != NULL) { |
| 2269 |
smb2_util_unlink(tree1, fname); |
| 2270 |
smb2_deltree(tree1, __func__); |
| 2271 |
|
| 2272 |
TALLOC_FREE(tree1); |
| 2273 |
} |
| 2274 |
|
| 2275 |
talloc_free(mem_ctx); |
| 2276 |
|
| 2277 |
return ret; |
| 2278 |
} |
| 2279 |
|
| 2280 |
/** |
| 2281 |
* 1. non stat open (without a lease) => h1 |
| 2282 |
* 2. durable open with RWH => h2 => RH |
| 2283 |
* 3. disconnect |
| 2284 |
* 4. reconnect |
| 2285 |
* 5. durable reconnect RH => h2 |
| 2286 |
*/ |
| 2287 |
static bool test_durable_v2_open_nonstat_and_lease(struct torture_context *tctx, |
| 2288 |
struct smb2_tree *tree1) |
| 2289 |
{ |
| 2290 |
TALLOC_CTX *mem_ctx = talloc_new(tctx); |
| 2291 |
NTSTATUS status; |
| 2292 |
char fname[256]; |
| 2293 |
struct smb2_handle dh; |
| 2294 |
struct smb2_handle _h1; |
| 2295 |
struct smb2_handle *h1 = NULL; |
| 2296 |
struct smb2_handle _h2; |
| 2297 |
struct smb2_handle *h2 = NULL; |
| 2298 |
struct smb2_create io; |
| 2299 |
struct GUID create_guid2 = GUID_random(); |
| 2300 |
struct smb2_lease ls; |
| 2301 |
uint64_t lease_key; |
| 2302 |
bool ret = true; |
| 2303 |
struct smbcli_options options1; |
| 2304 |
uint32_t caps; |
| 2305 |
|
| 2306 |
caps = smb2cli_conn_server_capabilities(tree1->session->transport->conn); |
| 2307 |
if (!(caps & SMB2_CAP_LEASING)) { |
| 2308 |
torture_skip(tctx, "leases are not supported"); |
| 2309 |
} |
| 2310 |
|
| 2311 |
options1 = tree1->session->transport->options; |
| 2312 |
|
| 2313 |
smb2_deltree(tree1, __func__); |
| 2314 |
status = torture_smb2_testdir(tree1, __func__, &dh); |
| 2315 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 2316 |
"torture_smb2_testdir failed\n"); |
| 2317 |
smb2_util_close(tree1, dh); |
| 2318 |
|
| 2319 |
/* Choose a random name in case the state is left a little funky. */ |
| 2320 |
snprintf(fname, 256, "%s\\file_%s.dat", |
| 2321 |
__func__, generate_random_str(tctx, 8)); |
| 2322 |
|
| 2323 |
smb2_util_unlink(tree1, fname); |
| 2324 |
|
| 2325 |
smb2_generic_create(&io, NULL, false /* dir */, fname, |
| 2326 |
FILE_OPEN_IF, 0, 0, 0); |
| 2327 |
io.in.desired_access = SEC_FILE_READ_ATTRIBUTE; |
| 2328 |
io.in.desired_access |= SEC_FILE_WRITE_ATTRIBUTE; |
| 2329 |
io.in.desired_access |= SEC_STD_SYNCHRONIZE; |
| 2330 |
/* |
| 2331 |
* SEC_STD_READ_CONTROL means we no longer |
| 2332 |
* have a stat open that would allow a RWH lease |
| 2333 |
*/ |
| 2334 |
io.in.desired_access |= SEC_STD_READ_CONTROL; |
| 2335 |
|
| 2336 |
status = smb2_create(tree1, mem_ctx, &io); |
| 2337 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 2338 |
_h1 = io.out.file.handle; |
| 2339 |
h1 = &_h1; |
| 2340 |
CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE); |
| 2341 |
CHECK_VAL(io.out.durable_open, false); |
| 2342 |
CHECK_VAL(io.out.durable_open_v2, false); |
| 2343 |
CHECK_VAL(io.out.persistent_open, false); |
| 2344 |
CHECK_VAL(io.out.oplock_level, SMB2_OPLOCK_LEVEL_NONE); |
| 2345 |
|
| 2346 |
lease_key = random(); |
| 2347 |
smb2_lease_v2_create(&io, &ls, false /* dir */, fname, |
| 2348 |
lease_key, 0, /* parent lease key */ |
| 2349 |
smb2_util_lease_state("RWH"), 0 /* lease epoch */); |
| 2350 |
io.in.durable_open = false; |
| 2351 |
io.in.durable_open_v2 = true; |
| 2352 |
io.in.persistent_open = false; |
| 2353 |
io.in.create_guid = create_guid2; |
| 2354 |
io.in.timeout = UINT32_MAX; |
| 2355 |
|
| 2356 |
status = smb2_create(tree1, mem_ctx, &io); |
| 2357 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 2358 |
_h2 = io.out.file.handle; |
| 2359 |
h2 = &_h2; |
| 2360 |
CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE); |
| 2361 |
CHECK_VAL(io.out.durable_open, false); |
| 2362 |
CHECK_VAL(io.out.durable_open_v2, true); |
| 2363 |
CHECK_VAL(io.out.persistent_open, false); |
| 2364 |
CHECK_VAL(io.out.timeout, 300*1000); |
| 2365 |
ls.lease_epoch += 1; |
| 2366 |
CHECK_LEASE_V2(&io, "RH", true, lease_key, |
| 2367 |
0, 0, ls.lease_epoch); |
| 2368 |
|
| 2369 |
/* disconnect, reconnect and then do durable reopen */ |
| 2370 |
TALLOC_FREE(tree1); |
| 2371 |
h1 = NULL; |
| 2372 |
|
| 2373 |
if (!torture_smb2_connection_ext(tctx, 0, &options1, &tree1)) { |
| 2374 |
torture_warning(tctx, "couldn't reconnect, bailing\n"); |
| 2375 |
ret = false; |
| 2376 |
goto done; |
| 2377 |
} |
| 2378 |
|
| 2379 |
ZERO_STRUCT(io); |
| 2380 |
io.in.fname = fname; |
| 2381 |
io.in.durable_open_v2 = false; |
| 2382 |
io.in.durable_handle_v2 = h2; |
| 2383 |
io.in.create_guid = create_guid2; |
| 2384 |
io.in.lease_request_v2 = &ls; |
| 2385 |
io.in.oplock_level = SMB2_OPLOCK_LEVEL_LEASE; |
| 2386 |
|
| 2387 |
status = smb2_create(tree1, mem_ctx, &io); |
| 2388 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 2389 |
_h2 = io.out.file.handle; |
| 2390 |
h2 = &_h2; |
| 2391 |
CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE); |
| 2392 |
CHECK_VAL(io.out.durable_open, false); |
| 2393 |
CHECK_VAL(io.out.durable_open_v2, false); /* no dh2q response blob */ |
| 2394 |
CHECK_VAL(io.out.persistent_open, false); |
| 2395 |
CHECK_LEASE_V2(&io, "RH", true, lease_key, |
| 2396 |
0, 0, ls.lease_epoch); |
| 2397 |
|
| 2398 |
status = smb2_util_close(tree1, *h2); |
| 2399 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 2400 |
h2 = NULL; |
| 2401 |
|
| 2402 |
done: |
| 2403 |
if (tree1 != NULL) { |
| 2404 |
smb2_keepalive(tree1->session->transport); |
| 2405 |
} |
| 2406 |
|
| 2407 |
if (tree1 != NULL && h1 != NULL) { |
| 2408 |
smb2_util_close(tree1, *h1); |
| 2409 |
} |
| 2410 |
if (tree1 != NULL && h2 != NULL) { |
| 2411 |
smb2_util_close(tree1, *h2); |
| 2412 |
} |
| 2413 |
|
| 2414 |
if (tree1 != NULL) { |
| 2415 |
smb2_util_unlink(tree1, fname); |
| 2416 |
smb2_deltree(tree1, __func__); |
| 2417 |
|
| 2418 |
TALLOC_FREE(tree1); |
| 2419 |
} |
| 2420 |
|
| 2421 |
talloc_free(mem_ctx); |
| 2422 |
|
| 2423 |
return ret; |
| 2424 |
} |
| 2425 |
|
| 2426 |
/** |
| 2427 |
* 1. stat open with RH lease => h1 |
| 2428 |
* 2. durable open with RWH => h2 => RH |
| 2429 |
* 3. disconnect |
| 2430 |
* 4. reconnect |
| 2431 |
* 5. durable reconnect RH => h2 |
| 2432 |
*/ |
| 2433 |
static bool test_durable_v2_open_statRH_and_lease(struct torture_context *tctx, |
| 2434 |
struct smb2_tree *tree1) |
| 2435 |
{ |
| 2436 |
TALLOC_CTX *mem_ctx = talloc_new(tctx); |
| 2437 |
NTSTATUS status; |
| 2438 |
char fname[256]; |
| 2439 |
struct smb2_handle dh; |
| 2440 |
struct smb2_handle _h1; |
| 2441 |
struct smb2_handle *h1 = NULL; |
| 2442 |
struct smb2_handle _h2; |
| 2443 |
struct smb2_handle *h2 = NULL; |
| 2444 |
struct smb2_create io; |
| 2445 |
struct GUID create_guid2 = GUID_random(); |
| 2446 |
struct smb2_lease ls; |
| 2447 |
uint64_t lease_key; |
| 2448 |
bool ret = true; |
| 2449 |
struct smbcli_options options1; |
| 2450 |
uint32_t caps; |
| 2451 |
|
| 2452 |
caps = smb2cli_conn_server_capabilities(tree1->session->transport->conn); |
| 2453 |
if (!(caps & SMB2_CAP_LEASING)) { |
| 2454 |
torture_skip(tctx, "leases are not supported"); |
| 2455 |
} |
| 2456 |
|
| 2457 |
options1 = tree1->session->transport->options; |
| 2458 |
|
| 2459 |
smb2_deltree(tree1, __func__); |
| 2460 |
status = torture_smb2_testdir(tree1, __func__, &dh); |
| 2461 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 2462 |
"torture_smb2_testdir failed\n"); |
| 2463 |
smb2_util_close(tree1, dh); |
| 2464 |
|
| 2465 |
/* Choose a random name in case the state is left a little funky. */ |
| 2466 |
snprintf(fname, 256, "%s\\file_%s.dat", |
| 2467 |
__func__, generate_random_str(tctx, 8)); |
| 2468 |
|
| 2469 |
smb2_util_unlink(tree1, fname); |
| 2470 |
|
| 2471 |
smb2_generic_create(&io, NULL, false /* dir */, fname, |
| 2472 |
FILE_OPEN_IF, 0, 0, 0); |
| 2473 |
lease_key = random(); |
| 2474 |
smb2_lease_v2_create(&io, &ls, false /* dir */, fname, |
| 2475 |
lease_key, 0, /* parent lease key */ |
| 2476 |
smb2_util_lease_state("RH"), 0 /* lease epoch */); |
| 2477 |
io.in.desired_access = SEC_FILE_READ_ATTRIBUTE; |
| 2478 |
|
| 2479 |
status = smb2_create(tree1, mem_ctx, &io); |
| 2480 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 2481 |
_h1 = io.out.file.handle; |
| 2482 |
h1 = &_h1; |
| 2483 |
CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE); |
| 2484 |
CHECK_VAL(io.out.durable_open, false); |
| 2485 |
CHECK_VAL(io.out.durable_open_v2, false); |
| 2486 |
CHECK_VAL(io.out.persistent_open, false); |
| 2487 |
CHECK_VAL(io.out.oplock_level, SMB2_OPLOCK_LEVEL_LEASE); |
| 2488 |
ls.lease_epoch += 1; |
| 2489 |
CHECK_LEASE_V2(&io, "RH", true, lease_key, |
| 2490 |
0, 0, ls.lease_epoch); |
| 2491 |
|
| 2492 |
lease_key = random(); |
| 2493 |
smb2_lease_v2_create(&io, &ls, false /* dir */, fname, |
| 2494 |
lease_key, 0, /* parent lease key */ |
| 2495 |
smb2_util_lease_state("RWH"), 0 /* lease epoch */); |
| 2496 |
io.in.durable_open = false; |
| 2497 |
io.in.durable_open_v2 = true; |
| 2498 |
io.in.persistent_open = false; |
| 2499 |
io.in.create_guid = create_guid2; |
| 2500 |
io.in.timeout = UINT32_MAX; |
| 2501 |
|
| 2502 |
status = smb2_create(tree1, mem_ctx, &io); |
| 2503 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 2504 |
_h2 = io.out.file.handle; |
| 2505 |
h2 = &_h2; |
| 2506 |
CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE); |
| 2507 |
CHECK_VAL(io.out.durable_open, false); |
| 2508 |
CHECK_VAL(io.out.durable_open_v2, true); |
| 2509 |
CHECK_VAL(io.out.persistent_open, false); |
| 2510 |
CHECK_VAL(io.out.timeout, 300*1000); |
| 2511 |
ls.lease_epoch += 1; |
| 2512 |
CHECK_LEASE_V2(&io, "RH", true, lease_key, |
| 2513 |
0, 0, ls.lease_epoch); |
| 2514 |
|
| 2515 |
/* disconnect, reconnect and then do durable reopen */ |
| 2516 |
TALLOC_FREE(tree1); |
| 2517 |
h1 = NULL; |
| 2518 |
|
| 2519 |
if (!torture_smb2_connection_ext(tctx, 0, &options1, &tree1)) { |
| 2520 |
torture_warning(tctx, "couldn't reconnect, bailing\n"); |
| 2521 |
ret = false; |
| 2522 |
goto done; |
| 2523 |
} |
| 2524 |
|
| 2525 |
ZERO_STRUCT(io); |
| 2526 |
io.in.fname = fname; |
| 2527 |
io.in.durable_open_v2 = false; |
| 2528 |
io.in.durable_handle_v2 = h2; |
| 2529 |
io.in.create_guid = create_guid2; |
| 2530 |
io.in.lease_request_v2 = &ls; |
| 2531 |
io.in.oplock_level = SMB2_OPLOCK_LEVEL_LEASE; |
| 2532 |
|
| 2533 |
status = smb2_create(tree1, mem_ctx, &io); |
| 2534 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 2535 |
_h2 = io.out.file.handle; |
| 2536 |
h2 = &_h2; |
| 2537 |
CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE); |
| 2538 |
CHECK_VAL(io.out.durable_open, false); |
| 2539 |
CHECK_VAL(io.out.durable_open_v2, false); /* no dh2q response blob */ |
| 2540 |
CHECK_VAL(io.out.persistent_open, false); |
| 2541 |
CHECK_LEASE_V2(&io, "RH", true, lease_key, |
| 2542 |
0, 0, ls.lease_epoch); |
| 2543 |
|
| 2544 |
status = smb2_util_close(tree1, *h2); |
| 2545 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 2546 |
h2 = NULL; |
| 2547 |
|
| 2548 |
done: |
| 2549 |
if (tree1 != NULL) { |
| 2550 |
smb2_keepalive(tree1->session->transport); |
| 2551 |
} |
| 2552 |
|
| 2553 |
if (tree1 != NULL && h1 != NULL) { |
| 2554 |
smb2_util_close(tree1, *h1); |
| 2555 |
} |
| 2556 |
if (tree1 != NULL && h2 != NULL) { |
| 2557 |
smb2_util_close(tree1, *h2); |
| 2558 |
} |
| 2559 |
|
| 2560 |
if (tree1 != NULL) { |
| 2561 |
smb2_util_unlink(tree1, fname); |
| 2562 |
smb2_deltree(tree1, __func__); |
| 2563 |
|
| 2564 |
TALLOC_FREE(tree1); |
| 2565 |
} |
| 2566 |
|
| 2567 |
talloc_free(mem_ctx); |
| 2568 |
|
| 2569 |
return ret; |
| 2570 |
} |
| 2571 |
|
| 2572 |
/** |
| 2573 |
* 1. durable open with L1(RWH) => h1 |
| 2574 |
* 2. durable open with L1(RWH) => h2 |
| 2575 |
* 3. disconnect |
| 2576 |
* 4. reconnect |
| 2577 |
* 5. durable reconnect L1(RWH) => h1 |
| 2578 |
* 6. durable reconnect L1(RWH) => h2 |
| 2579 |
*/ |
| 2580 |
static bool test_durable_v2_open_two_same_lease(struct torture_context *tctx, |
| 2581 |
struct smb2_tree *tree1) |
| 2582 |
{ |
| 2583 |
TALLOC_CTX *mem_ctx = talloc_new(tctx); |
| 2584 |
NTSTATUS status; |
| 2585 |
char fname[256]; |
| 2586 |
struct smb2_handle dh; |
| 2587 |
struct smb2_handle _h1; |
| 2588 |
struct smb2_handle *h1 = NULL; |
| 2589 |
struct smb2_handle _h2; |
| 2590 |
struct smb2_handle *h2 = NULL; |
| 2591 |
struct smb2_create io; |
| 2592 |
struct GUID create_guid1 = GUID_random(); |
| 2593 |
struct GUID create_guid2 = GUID_random(); |
| 2594 |
struct smb2_lease ls; |
| 2595 |
uint64_t lease_key; |
| 2596 |
bool ret = true; |
| 2597 |
struct smbcli_options options1; |
| 2598 |
uint32_t caps; |
| 2599 |
|
| 2600 |
caps = smb2cli_conn_server_capabilities(tree1->session->transport->conn); |
| 2601 |
if (!(caps & SMB2_CAP_LEASING)) { |
| 2602 |
torture_skip(tctx, "leases are not supported"); |
| 2603 |
} |
| 2604 |
|
| 2605 |
options1 = tree1->session->transport->options; |
| 2606 |
|
| 2607 |
smb2_deltree(tree1, __func__); |
| 2608 |
status = torture_smb2_testdir(tree1, __func__, &dh); |
| 2609 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 2610 |
"torture_smb2_testdir failed\n"); |
| 2611 |
smb2_util_close(tree1, dh); |
| 2612 |
|
| 2613 |
/* Choose a random name in case the state is left a little funky. */ |
| 2614 |
snprintf(fname, 256, "%s\\file_%s.dat", |
| 2615 |
__func__, generate_random_str(tctx, 8)); |
| 2616 |
|
| 2617 |
smb2_util_unlink(tree1, fname); |
| 2618 |
|
| 2619 |
lease_key = random(); |
| 2620 |
smb2_lease_v2_create(&io, &ls, false /* dir */, fname, |
| 2621 |
lease_key, 0, /* parent lease key */ |
| 2622 |
smb2_util_lease_state("RWH"), 0 /* lease epoch */); |
| 2623 |
io.in.durable_open = false; |
| 2624 |
io.in.durable_open_v2 = true; |
| 2625 |
io.in.persistent_open = false; |
| 2626 |
io.in.create_guid = create_guid1; |
| 2627 |
io.in.timeout = UINT32_MAX; |
| 2628 |
|
| 2629 |
status = smb2_create(tree1, mem_ctx, &io); |
| 2630 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 2631 |
_h1 = io.out.file.handle; |
| 2632 |
h1 = &_h1; |
| 2633 |
CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE); |
| 2634 |
CHECK_VAL(io.out.durable_open, false); |
| 2635 |
CHECK_VAL(io.out.durable_open_v2, true); |
| 2636 |
CHECK_VAL(io.out.persistent_open, false); |
| 2637 |
CHECK_VAL(io.out.timeout, 300*1000); |
| 2638 |
ls.lease_epoch += 1; |
| 2639 |
CHECK_LEASE_V2(&io, "RWH", true, lease_key, |
| 2640 |
0, 0, ls.lease_epoch); |
| 2641 |
|
| 2642 |
smb2_lease_v2_create(&io, &ls, false /* dir */, fname, |
| 2643 |
lease_key, 0, /* parent lease key */ |
| 2644 |
smb2_util_lease_state("RWH"), 0 /* lease epoch */); |
| 2645 |
io.in.durable_open = false; |
| 2646 |
io.in.durable_open_v2 = true; |
| 2647 |
io.in.persistent_open = false; |
| 2648 |
io.in.create_guid = create_guid2; |
| 2649 |
io.in.timeout = UINT32_MAX; |
| 2650 |
|
| 2651 |
status = smb2_create(tree1, mem_ctx, &io); |
| 2652 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 2653 |
_h2 = io.out.file.handle; |
| 2654 |
h2 = &_h2; |
| 2655 |
CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE); |
| 2656 |
CHECK_VAL(io.out.durable_open, false); |
| 2657 |
CHECK_VAL(io.out.durable_open_v2, true); |
| 2658 |
CHECK_VAL(io.out.persistent_open, false); |
| 2659 |
CHECK_VAL(io.out.timeout, 300*1000); |
| 2660 |
ls.lease_epoch += 1; |
| 2661 |
CHECK_LEASE_V2(&io, "RWH", true, lease_key, |
| 2662 |
0, 0, ls.lease_epoch); |
| 2663 |
|
| 2664 |
/* disconnect, reconnect and then do durable reopen */ |
| 2665 |
TALLOC_FREE(tree1); |
| 2666 |
|
| 2667 |
if (!torture_smb2_connection_ext(tctx, 0, &options1, &tree1)) { |
| 2668 |
torture_warning(tctx, "couldn't reconnect, bailing\n"); |
| 2669 |
ret = false; |
| 2670 |
goto done; |
| 2671 |
} |
| 2672 |
|
| 2673 |
ZERO_STRUCT(io); |
| 2674 |
io.in.fname = fname; |
| 2675 |
io.in.durable_open_v2 = false; |
| 2676 |
io.in.durable_handle_v2 = h1; |
| 2677 |
io.in.create_guid = create_guid1; |
| 2678 |
io.in.lease_request_v2 = &ls; |
| 2679 |
io.in.oplock_level = SMB2_OPLOCK_LEVEL_LEASE; |
| 2680 |
|
| 2681 |
status = smb2_create(tree1, mem_ctx, &io); |
| 2682 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 2683 |
_h1 = io.out.file.handle; |
| 2684 |
h1 = &_h1; |
| 2685 |
CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE); |
| 2686 |
CHECK_VAL(io.out.durable_open, false); |
| 2687 |
CHECK_VAL(io.out.durable_open_v2, false); /* no dh2q response blob */ |
| 2688 |
CHECK_VAL(io.out.persistent_open, false); |
| 2689 |
CHECK_LEASE_V2(&io, "RWH", true, lease_key, |
| 2690 |
0, 0, ls.lease_epoch); |
| 2691 |
|
| 2692 |
ZERO_STRUCT(io); |
| 2693 |
io.in.fname = fname; |
| 2694 |
io.in.durable_open_v2 = false; |
| 2695 |
io.in.durable_handle_v2 = h2; |
| 2696 |
io.in.create_guid = create_guid2; |
| 2697 |
io.in.lease_request_v2 = &ls; |
| 2698 |
io.in.oplock_level = SMB2_OPLOCK_LEVEL_LEASE; |
| 2699 |
|
| 2700 |
status = smb2_create(tree1, mem_ctx, &io); |
| 2701 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 2702 |
_h2 = io.out.file.handle; |
| 2703 |
h2 = &_h2; |
| 2704 |
CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE); |
| 2705 |
CHECK_VAL(io.out.durable_open, false); |
| 2706 |
CHECK_VAL(io.out.durable_open_v2, false); /* no dh2q response blob */ |
| 2707 |
CHECK_VAL(io.out.persistent_open, false); |
| 2708 |
CHECK_LEASE_V2(&io, "RWH", true, lease_key, |
| 2709 |
0, 0, ls.lease_epoch); |
| 2710 |
|
| 2711 |
status = smb2_util_close(tree1, *h1); |
| 2712 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 2713 |
h1 = NULL; |
| 2714 |
|
| 2715 |
status = smb2_util_close(tree1, *h2); |
| 2716 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 2717 |
h2 = NULL; |
| 2718 |
|
| 2719 |
done: |
| 2720 |
if (tree1 != NULL) { |
| 2721 |
smb2_keepalive(tree1->session->transport); |
| 2722 |
} |
| 2723 |
|
| 2724 |
if (tree1 != NULL && h1 != NULL) { |
| 2725 |
smb2_util_close(tree1, *h1); |
| 2726 |
} |
| 2727 |
if (tree1 != NULL && h2 != NULL) { |
| 2728 |
smb2_util_close(tree1, *h2); |
| 2729 |
} |
| 2730 |
|
| 2731 |
if (tree1 != NULL) { |
| 2732 |
smb2_util_unlink(tree1, fname); |
| 2733 |
smb2_deltree(tree1, __func__); |
| 2734 |
|
| 2735 |
TALLOC_FREE(tree1); |
| 2736 |
} |
| 2737 |
|
| 2738 |
talloc_free(mem_ctx); |
| 2739 |
|
| 2740 |
return ret; |
| 2741 |
} |
| 2742 |
|
| 2743 |
/** |
| 2744 |
* 1. durable open with L1(RH) => h1 |
| 2745 |
* 2. durable open with L2(RH) => h2 |
| 2746 |
* 3. disconnect |
| 2747 |
* 4. reconnect |
| 2748 |
* 5. durable reconnect L1(RH) => h1 |
| 2749 |
* 6. durable reconnect L2(RH) => h2 |
| 2750 |
*/ |
| 2751 |
static bool test_durable_v2_open_two_different_leases(struct torture_context *tctx, |
| 2752 |
struct smb2_tree *tree1) |
| 2753 |
{ |
| 2754 |
TALLOC_CTX *mem_ctx = talloc_new(tctx); |
| 2755 |
NTSTATUS status; |
| 2756 |
char fname[256]; |
| 2757 |
struct smb2_handle dh; |
| 2758 |
struct smb2_handle _h1; |
| 2759 |
struct smb2_handle *h1 = NULL; |
| 2760 |
struct smb2_handle _h2; |
| 2761 |
struct smb2_handle *h2 = NULL; |
| 2762 |
struct smb2_create io; |
| 2763 |
struct GUID create_guid1 = GUID_random(); |
| 2764 |
struct GUID create_guid2 = GUID_random(); |
| 2765 |
struct smb2_lease ls1; |
| 2766 |
uint64_t lease_key1; |
| 2767 |
struct smb2_lease ls2; |
| 2768 |
uint64_t lease_key2; |
| 2769 |
bool ret = true; |
| 2770 |
struct smbcli_options options1; |
| 2771 |
uint32_t caps; |
| 2772 |
|
| 2773 |
caps = smb2cli_conn_server_capabilities(tree1->session->transport->conn); |
| 2774 |
if (!(caps & SMB2_CAP_LEASING)) { |
| 2775 |
torture_skip(tctx, "leases are not supported"); |
| 2776 |
} |
| 2777 |
|
| 2778 |
options1 = tree1->session->transport->options; |
| 2779 |
|
| 2780 |
smb2_deltree(tree1, __func__); |
| 2781 |
status = torture_smb2_testdir(tree1, __func__, &dh); |
| 2782 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 2783 |
"torture_smb2_testdir failed\n"); |
| 2784 |
smb2_util_close(tree1, dh); |
| 2785 |
|
| 2786 |
/* Choose a random name in case the state is left a little funky. */ |
| 2787 |
snprintf(fname, 256, "%s\\file_%s.dat", |
| 2788 |
__func__, generate_random_str(tctx, 8)); |
| 2789 |
|
| 2790 |
smb2_util_unlink(tree1, fname); |
| 2791 |
|
| 2792 |
lease_key1 = random(); |
| 2793 |
smb2_lease_v2_create(&io, &ls1, false /* dir */, fname, |
| 2794 |
lease_key1, 0, /* parent lease key */ |
| 2795 |
smb2_util_lease_state("RH"), 0 /* lease epoch */); |
| 2796 |
io.in.durable_open = false; |
| 2797 |
io.in.durable_open_v2 = true; |
| 2798 |
io.in.persistent_open = false; |
| 2799 |
io.in.create_guid = create_guid1; |
| 2800 |
io.in.timeout = UINT32_MAX; |
| 2801 |
|
| 2802 |
status = smb2_create(tree1, mem_ctx, &io); |
| 2803 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 2804 |
_h1 = io.out.file.handle; |
| 2805 |
h1 = &_h1; |
| 2806 |
CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE); |
| 2807 |
CHECK_VAL(io.out.durable_open, false); |
| 2808 |
CHECK_VAL(io.out.durable_open_v2, true); |
| 2809 |
CHECK_VAL(io.out.persistent_open, false); |
| 2810 |
CHECK_VAL(io.out.timeout, 300*1000); |
| 2811 |
ls1.lease_epoch += 1; |
| 2812 |
CHECK_LEASE_V2(&io, "RH", true, lease_key1, |
| 2813 |
0, 0, ls1.lease_epoch); |
| 2814 |
|
| 2815 |
lease_key2 = random(); |
| 2816 |
smb2_lease_v2_create(&io, &ls2, false /* dir */, fname, |
| 2817 |
lease_key2, 0, /* parent lease key */ |
| 2818 |
smb2_util_lease_state("RH"), 0 /* lease epoch */); |
| 2819 |
io.in.durable_open = false; |
| 2820 |
io.in.durable_open_v2 = true; |
| 2821 |
io.in.persistent_open = false; |
| 2822 |
io.in.create_guid = create_guid2; |
| 2823 |
io.in.timeout = UINT32_MAX; |
| 2824 |
|
| 2825 |
status = smb2_create(tree1, mem_ctx, &io); |
| 2826 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 2827 |
_h2 = io.out.file.handle; |
| 2828 |
h2 = &_h2; |
| 2829 |
CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE); |
| 2830 |
CHECK_VAL(io.out.durable_open, false); |
| 2831 |
CHECK_VAL(io.out.durable_open_v2, true); |
| 2832 |
CHECK_VAL(io.out.persistent_open, false); |
| 2833 |
CHECK_VAL(io.out.timeout, 300*1000); |
| 2834 |
ls2.lease_epoch += 1; |
| 2835 |
CHECK_LEASE_V2(&io, "RH", true, lease_key2, |
| 2836 |
0, 0, ls2.lease_epoch); |
| 2837 |
|
| 2838 |
/* disconnect, reconnect and then do durable reopen */ |
| 2839 |
TALLOC_FREE(tree1); |
| 2840 |
|
| 2841 |
if (!torture_smb2_connection_ext(tctx, 0, &options1, &tree1)) { |
| 2842 |
torture_warning(tctx, "couldn't reconnect, bailing\n"); |
| 2843 |
ret = false; |
| 2844 |
goto done; |
| 2845 |
} |
| 2846 |
|
| 2847 |
ZERO_STRUCT(io); |
| 2848 |
io.in.fname = fname; |
| 2849 |
io.in.durable_open_v2 = false; |
| 2850 |
io.in.durable_handle_v2 = h1; |
| 2851 |
io.in.create_guid = create_guid1; |
| 2852 |
io.in.lease_request_v2 = &ls1; |
| 2853 |
io.in.oplock_level = SMB2_OPLOCK_LEVEL_LEASE; |
| 2854 |
|
| 2855 |
status = smb2_create(tree1, mem_ctx, &io); |
| 2856 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 2857 |
_h1 = io.out.file.handle; |
| 2858 |
h1 = &_h1; |
| 2859 |
CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE); |
| 2860 |
CHECK_VAL(io.out.durable_open, false); |
| 2861 |
CHECK_VAL(io.out.durable_open_v2, false); /* no dh2q response blob */ |
| 2862 |
CHECK_VAL(io.out.persistent_open, false); |
| 2863 |
CHECK_LEASE_V2(&io, "RH", true, lease_key1, |
| 2864 |
0, 0, ls1.lease_epoch); |
| 2865 |
|
| 2866 |
ZERO_STRUCT(io); |
| 2867 |
io.in.fname = fname; |
| 2868 |
io.in.durable_open_v2 = false; |
| 2869 |
io.in.durable_handle_v2 = h2; |
| 2870 |
io.in.create_guid = create_guid2; |
| 2871 |
io.in.lease_request_v2 = &ls2; |
| 2872 |
io.in.oplock_level = SMB2_OPLOCK_LEVEL_LEASE; |
| 2873 |
|
| 2874 |
status = smb2_create(tree1, mem_ctx, &io); |
| 2875 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 2876 |
_h2 = io.out.file.handle; |
| 2877 |
h2 = &_h2; |
| 2878 |
CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE); |
| 2879 |
CHECK_VAL(io.out.durable_open, false); |
| 2880 |
CHECK_VAL(io.out.durable_open_v2, false); /* no dh2q response blob */ |
| 2881 |
CHECK_VAL(io.out.persistent_open, false); |
| 2882 |
CHECK_LEASE_V2(&io, "RH", true, lease_key2, |
| 2883 |
0, 0, ls2.lease_epoch); |
| 2884 |
|
| 2885 |
status = smb2_util_close(tree1, *h1); |
| 2886 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 2887 |
h1 = NULL; |
| 2888 |
|
| 2889 |
status = smb2_util_close(tree1, *h2); |
| 2890 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 2891 |
h2 = NULL; |
| 2892 |
|
| 2893 |
done: |
| 2894 |
if (tree1 != NULL) { |
| 2895 |
smb2_keepalive(tree1->session->transport); |
| 2896 |
} |
| 2897 |
|
| 2898 |
if (tree1 != NULL && h1 != NULL) { |
| 2899 |
smb2_util_close(tree1, *h1); |
| 2900 |
} |
| 2901 |
if (tree1 != NULL && h2 != NULL) { |
| 2902 |
smb2_util_close(tree1, *h2); |
| 2903 |
} |
| 2904 |
|
| 2905 |
if (tree1 != NULL) { |
| 2906 |
smb2_util_unlink(tree1, fname); |
| 2907 |
smb2_deltree(tree1, __func__); |
| 2908 |
|
| 2909 |
TALLOC_FREE(tree1); |
| 2910 |
} |
| 2911 |
|
| 2912 |
talloc_free(mem_ctx); |
| 2913 |
|
| 2914 |
return ret; |
| 2915 |
} |
| 2916 |
|
| 2917 |
/** |
| 2918 |
* 1. durable open with L1A(RH) on tree1 => h1a |
| 2919 |
* 1. durable open with L1B(RH) on tree1 => h1b |
| 2920 |
* 2. disconnect tree1 |
| 2921 |
* 3. stat open on tree2 => h2 |
| 2922 |
* 4. reconnect tree1 |
| 2923 |
* 5. durable reconnect L1A(RH) => h1a |
| 2924 |
* 6. durable reconnect L1B(RH) => h1a |
| 2925 |
*/ |
| 2926 |
static bool test_durable_v2_open_keep_disconnected_rh_with_stat_open(struct torture_context *tctx, |
| 2927 |
struct smb2_tree *tree1, |
| 2928 |
struct smb2_tree *tree2) |
| 2929 |
{ |
| 2930 |
TALLOC_CTX *mem_ctx = talloc_new(tctx); |
| 2931 |
NTSTATUS status; |
| 2932 |
char fname[256]; |
| 2933 |
struct smb2_handle dh; |
| 2934 |
struct smb2_handle _h1a; |
| 2935 |
struct smb2_handle *h1a = NULL; |
| 2936 |
struct smb2_handle _h1b; |
| 2937 |
struct smb2_handle *h1b = NULL; |
| 2938 |
struct smb2_handle _h2; |
| 2939 |
struct smb2_handle *h2 = NULL; |
| 2940 |
struct smb2_create io; |
| 2941 |
struct GUID create_guid1a = GUID_random(); |
| 2942 |
struct GUID create_guid1b = GUID_random(); |
| 2943 |
struct smb2_lease ls1a; |
| 2944 |
uint64_t lease_key1a; |
| 2945 |
struct smb2_lease ls1b; |
| 2946 |
uint64_t lease_key1b; |
| 2947 |
bool ret = true; |
| 2948 |
struct smbcli_options options1; |
| 2949 |
uint32_t caps; |
| 2950 |
|
| 2951 |
caps = smb2cli_conn_server_capabilities(tree1->session->transport->conn); |
| 2952 |
if (!(caps & SMB2_CAP_LEASING)) { |
| 2953 |
torture_skip(tctx, "leases are not supported"); |
| 2954 |
} |
| 2955 |
|
| 2956 |
options1 = tree1->session->transport->options; |
| 2957 |
|
| 2958 |
tree1->session->transport->lease.handler = torture_lease_handler; |
| 2959 |
tree1->session->transport->lease.private_data = tree1; |
| 2960 |
|
| 2961 |
tree2->session->transport->lease.handler = torture_lease_handler; |
| 2962 |
tree2->session->transport->lease.private_data = tree2; |
| 2963 |
|
| 2964 |
torture_reset_lease_break_info(tctx, &lease_break_info); |
| 2965 |
|
| 2966 |
smb2_deltree(tree1, __func__); |
| 2967 |
status = torture_smb2_testdir(tree1, __func__, &dh); |
| 2968 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 2969 |
"torture_smb2_testdir failed\n"); |
| 2970 |
smb2_util_close(tree1, dh); |
| 2971 |
|
| 2972 |
/* Choose a random name in case the state is left a little funky. */ |
| 2973 |
snprintf(fname, 256, "%s\\file_%s.dat", |
| 2974 |
__func__, generate_random_str(tctx, 8)); |
| 2975 |
|
| 2976 |
smb2_util_unlink(tree1, fname); |
| 2977 |
|
| 2978 |
lease_key1a = random(); |
| 2979 |
smb2_lease_v2_create(&io, &ls1a, false /* dir */, fname, |
| 2980 |
lease_key1a, 0, /* parent lease key */ |
| 2981 |
smb2_util_lease_state("RH"), 0 /* lease epoch */); |
| 2982 |
io.in.durable_open = false; |
| 2983 |
io.in.durable_open_v2 = true; |
| 2984 |
io.in.persistent_open = false; |
| 2985 |
io.in.create_guid = create_guid1a; |
| 2986 |
io.in.timeout = UINT32_MAX; |
| 2987 |
|
| 2988 |
status = smb2_create(tree1, mem_ctx, &io); |
| 2989 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 2990 |
_h1a = io.out.file.handle; |
| 2991 |
h1a = &_h1a; |
| 2992 |
CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE); |
| 2993 |
CHECK_VAL(io.out.durable_open, false); |
| 2994 |
CHECK_VAL(io.out.durable_open_v2, true); |
| 2995 |
CHECK_VAL(io.out.persistent_open, false); |
| 2996 |
CHECK_VAL(io.out.timeout, 300*1000); |
| 2997 |
ls1a.lease_epoch += 1; |
| 2998 |
CHECK_LEASE_V2(&io, "RH", true, lease_key1a, |
| 2999 |
0, 0, ls1a.lease_epoch); |
| 3000 |
|
| 3001 |
lease_key1b = random(); |
| 3002 |
smb2_lease_v2_create(&io, &ls1b, false /* dir */, fname, |
| 3003 |
lease_key1b, 0, /* parent lease key */ |
| 3004 |
smb2_util_lease_state("RH"), 0 /* lease epoch */); |
| 3005 |
io.in.durable_open = false; |
| 3006 |
io.in.durable_open_v2 = true; |
| 3007 |
io.in.persistent_open = false; |
| 3008 |
io.in.create_guid = create_guid1b; |
| 3009 |
io.in.timeout = UINT32_MAX; |
| 3010 |
|
| 3011 |
status = smb2_create(tree1, mem_ctx, &io); |
| 3012 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 3013 |
_h1b = io.out.file.handle; |
| 3014 |
h1b = &_h1b; |
| 3015 |
CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE); |
| 3016 |
CHECK_VAL(io.out.durable_open, false); |
| 3017 |
CHECK_VAL(io.out.durable_open_v2, true); |
| 3018 |
CHECK_VAL(io.out.persistent_open, false); |
| 3019 |
CHECK_VAL(io.out.timeout, 300*1000); |
| 3020 |
ls1b.lease_epoch += 1; |
| 3021 |
CHECK_LEASE_V2(&io, "RH", true, lease_key1b, |
| 3022 |
0, 0, ls1b.lease_epoch); |
| 3023 |
|
| 3024 |
CHECK_NO_BREAK(tctx); |
| 3025 |
|
| 3026 |
/* disconnect, reconnect and then do durable reopen */ |
| 3027 |
TALLOC_FREE(tree1); |
| 3028 |
|
| 3029 |
CHECK_NO_BREAK(tctx); |
| 3030 |
|
| 3031 |
smb2_generic_create(&io, NULL, false /* dir */, fname, |
| 3032 |
FILE_OPEN_IF, 0, 0, 0); |
| 3033 |
io.in.desired_access = SEC_FILE_READ_ATTRIBUTE; |
| 3034 |
status = smb2_create(tree2, mem_ctx, &io); |
| 3035 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 3036 |
_h2 = io.out.file.handle; |
| 3037 |
h2 = &_h2; |
| 3038 |
CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE); |
| 3039 |
CHECK_VAL(io.out.durable_open, false); |
| 3040 |
CHECK_VAL(io.out.durable_open_v2, false); |
| 3041 |
CHECK_VAL(io.out.persistent_open, false); |
| 3042 |
|
| 3043 |
CHECK_NO_BREAK(tctx); |
| 3044 |
|
| 3045 |
if (!torture_smb2_connection_ext(tctx, 0, &options1, &tree1)) { |
| 3046 |
torture_warning(tctx, "couldn't reconnect, bailing\n"); |
| 3047 |
ret = false; |
| 3048 |
goto done; |
| 3049 |
} |
| 3050 |
|
| 3051 |
ZERO_STRUCT(io); |
| 3052 |
io.in.fname = fname; |
| 3053 |
io.in.durable_open_v2 = false; |
| 3054 |
io.in.durable_handle_v2 = h1a; |
| 3055 |
io.in.create_guid = create_guid1a; |
| 3056 |
io.in.lease_request_v2 = &ls1a; |
| 3057 |
io.in.oplock_level = SMB2_OPLOCK_LEVEL_LEASE; |
| 3058 |
|
| 3059 |
status = smb2_create(tree1, mem_ctx, &io); |
| 3060 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 3061 |
_h1a = io.out.file.handle; |
| 3062 |
h1a = &_h1a; |
| 3063 |
CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE); |
| 3064 |
CHECK_VAL(io.out.durable_open, false); |
| 3065 |
CHECK_VAL(io.out.durable_open_v2, false); /* no dh2q response blob */ |
| 3066 |
CHECK_VAL(io.out.persistent_open, false); |
| 3067 |
CHECK_LEASE_V2(&io, "RH", true, lease_key1a, |
| 3068 |
0, 0, ls1a.lease_epoch); |
| 3069 |
|
| 3070 |
ZERO_STRUCT(io); |
| 3071 |
io.in.fname = fname; |
| 3072 |
io.in.durable_open_v2 = false; |
| 3073 |
io.in.durable_handle_v2 = h1b; |
| 3074 |
io.in.create_guid = create_guid1b; |
| 3075 |
io.in.lease_request_v2 = &ls1b; |
| 3076 |
io.in.oplock_level = SMB2_OPLOCK_LEVEL_LEASE; |
| 3077 |
|
| 3078 |
status = smb2_create(tree1, mem_ctx, &io); |
| 3079 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 3080 |
_h1b = io.out.file.handle; |
| 3081 |
h1b = &_h1b; |
| 3082 |
CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE); |
| 3083 |
CHECK_VAL(io.out.durable_open, false); |
| 3084 |
CHECK_VAL(io.out.durable_open_v2, false); /* no dh2q response blob */ |
| 3085 |
CHECK_VAL(io.out.persistent_open, false); |
| 3086 |
CHECK_LEASE_V2(&io, "RH", true, lease_key1b, |
| 3087 |
0, 0, ls1b.lease_epoch); |
| 3088 |
|
| 3089 |
status = smb2_util_close(tree1, *h1a); |
| 3090 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 3091 |
h1a = NULL; |
| 3092 |
|
| 3093 |
status = smb2_util_close(tree1, *h1b); |
| 3094 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 3095 |
h1b = NULL; |
| 3096 |
|
| 3097 |
status = smb2_util_close(tree2, *h2); |
| 3098 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 3099 |
h2 = NULL; |
| 3100 |
|
| 3101 |
CHECK_NO_BREAK(tctx); |
| 3102 |
|
| 3103 |
done: |
| 3104 |
if (tree1 != NULL) { |
| 3105 |
smb2_keepalive(tree1->session->transport); |
| 3106 |
} |
| 3107 |
if (tree2 != NULL) { |
| 3108 |
smb2_keepalive(tree2->session->transport); |
| 3109 |
} |
| 3110 |
if (tree1 != NULL && h1a != NULL) { |
| 3111 |
smb2_util_close(tree1, *h1a); |
| 3112 |
} |
| 3113 |
if (tree1 != NULL && h1b != NULL) { |
| 3114 |
smb2_util_close(tree1, *h1b); |
| 3115 |
} |
| 3116 |
if (tree2 != NULL && h2 != NULL) { |
| 3117 |
smb2_util_close(tree2, *h2); |
| 3118 |
} |
| 3119 |
|
| 3120 |
if (tree1 != NULL) { |
| 3121 |
smb2_util_unlink(tree1, fname); |
| 3122 |
smb2_deltree(tree1, __func__); |
| 3123 |
|
| 3124 |
TALLOC_FREE(tree1); |
| 3125 |
} |
| 3126 |
|
| 3127 |
TALLOC_FREE(tree2); |
| 3128 |
|
| 3129 |
talloc_free(mem_ctx); |
| 3130 |
|
| 3131 |
return ret; |
| 3132 |
} |
| 3133 |
|
| 3134 |
/** |
| 3135 |
* 1. durable open with L1A(RH) on tree1 => h1a |
| 3136 |
* 1. durable open with L1B(RH) on tree1 => h1b |
| 3137 |
* 2. disconnect tree1 |
| 3138 |
* 3. durable open with L2(RH) on tree2 => h2 |
| 3139 |
* 4. reconnect tree1 |
| 3140 |
* 5. durable reconnect L1A(RH) => h1a |
| 3141 |
* 6. durable reconnect L1B(RH) => h1a |
| 3142 |
*/ |
| 3143 |
static bool test_durable_v2_open_keep_disconnected_rh_with_rh_open(struct torture_context *tctx, |
| 3144 |
struct smb2_tree *tree1, |
| 3145 |
struct smb2_tree *tree2) |
| 3146 |
{ |
| 3147 |
TALLOC_CTX *mem_ctx = talloc_new(tctx); |
| 3148 |
NTSTATUS status; |
| 3149 |
char fname[256]; |
| 3150 |
struct smb2_handle dh; |
| 3151 |
struct smb2_handle _h1a; |
| 3152 |
struct smb2_handle *h1a = NULL; |
| 3153 |
struct smb2_handle _h1b; |
| 3154 |
struct smb2_handle *h1b = NULL; |
| 3155 |
struct smb2_handle _h2; |
| 3156 |
struct smb2_handle *h2 = NULL; |
| 3157 |
struct smb2_create io; |
| 3158 |
struct GUID create_guid1a = GUID_random(); |
| 3159 |
struct GUID create_guid1b = GUID_random(); |
| 3160 |
struct GUID create_guid2 = GUID_random(); |
| 3161 |
struct smb2_lease ls1a; |
| 3162 |
uint64_t lease_key1a; |
| 3163 |
struct smb2_lease ls1b; |
| 3164 |
uint64_t lease_key1b; |
| 3165 |
struct smb2_lease ls2; |
| 3166 |
uint64_t lease_key2; |
| 3167 |
bool ret = true; |
| 3168 |
struct smbcli_options options1; |
| 3169 |
uint32_t caps; |
| 3170 |
|
| 3171 |
caps = smb2cli_conn_server_capabilities(tree1->session->transport->conn); |
| 3172 |
if (!(caps & SMB2_CAP_LEASING)) { |
| 3173 |
torture_skip(tctx, "leases are not supported"); |
| 3174 |
} |
| 3175 |
|
| 3176 |
options1 = tree1->session->transport->options; |
| 3177 |
|
| 3178 |
tree1->session->transport->lease.handler = torture_lease_handler; |
| 3179 |
tree1->session->transport->lease.private_data = tree1; |
| 3180 |
|
| 3181 |
tree2->session->transport->lease.handler = torture_lease_handler; |
| 3182 |
tree2->session->transport->lease.private_data = tree2; |
| 3183 |
|
| 3184 |
torture_reset_lease_break_info(tctx, &lease_break_info); |
| 3185 |
|
| 3186 |
smb2_deltree(tree1, __func__); |
| 3187 |
status = torture_smb2_testdir(tree1, __func__, &dh); |
| 3188 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 3189 |
"torture_smb2_testdir failed\n"); |
| 3190 |
smb2_util_close(tree1, dh); |
| 3191 |
|
| 3192 |
/* Choose a random name in case the state is left a little funky. */ |
| 3193 |
snprintf(fname, 256, "%s\\file_%s.dat", |
| 3194 |
__func__, generate_random_str(tctx, 8)); |
| 3195 |
|
| 3196 |
smb2_util_unlink(tree1, fname); |
| 3197 |
|
| 3198 |
lease_key1a = random(); |
| 3199 |
smb2_lease_v2_create(&io, &ls1a, false /* dir */, fname, |
| 3200 |
lease_key1a, 0, /* parent lease key */ |
| 3201 |
smb2_util_lease_state("RH"), 0 /* lease epoch */); |
| 3202 |
io.in.durable_open = false; |
| 3203 |
io.in.durable_open_v2 = true; |
| 3204 |
io.in.persistent_open = false; |
| 3205 |
io.in.create_guid = create_guid1a; |
| 3206 |
io.in.timeout = UINT32_MAX; |
| 3207 |
|
| 3208 |
status = smb2_create(tree1, mem_ctx, &io); |
| 3209 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 3210 |
_h1a = io.out.file.handle; |
| 3211 |
h1a = &_h1a; |
| 3212 |
CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE); |
| 3213 |
CHECK_VAL(io.out.durable_open, false); |
| 3214 |
CHECK_VAL(io.out.durable_open_v2, true); |
| 3215 |
CHECK_VAL(io.out.persistent_open, false); |
| 3216 |
CHECK_VAL(io.out.timeout, 300*1000); |
| 3217 |
ls1a.lease_epoch += 1; |
| 3218 |
CHECK_LEASE_V2(&io, "RH", true, lease_key1a, |
| 3219 |
0, 0, ls1a.lease_epoch); |
| 3220 |
|
| 3221 |
lease_key1b = random(); |
| 3222 |
smb2_lease_v2_create(&io, &ls1b, false /* dir */, fname, |
| 3223 |
lease_key1b, 0, /* parent lease key */ |
| 3224 |
smb2_util_lease_state("RH"), 0 /* lease epoch */); |
| 3225 |
io.in.durable_open = false; |
| 3226 |
io.in.durable_open_v2 = true; |
| 3227 |
io.in.persistent_open = false; |
| 3228 |
io.in.create_guid = create_guid1b; |
| 3229 |
io.in.timeout = UINT32_MAX; |
| 3230 |
|
| 3231 |
status = smb2_create(tree1, mem_ctx, &io); |
| 3232 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 3233 |
_h1b = io.out.file.handle; |
| 3234 |
h1b = &_h1b; |
| 3235 |
CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE); |
| 3236 |
CHECK_VAL(io.out.durable_open, false); |
| 3237 |
CHECK_VAL(io.out.durable_open_v2, true); |
| 3238 |
CHECK_VAL(io.out.persistent_open, false); |
| 3239 |
CHECK_VAL(io.out.timeout, 300*1000); |
| 3240 |
ls1b.lease_epoch += 1; |
| 3241 |
CHECK_LEASE_V2(&io, "RH", true, lease_key1b, |
| 3242 |
0, 0, ls1b.lease_epoch); |
| 3243 |
|
| 3244 |
CHECK_NO_BREAK(tctx); |
| 3245 |
|
| 3246 |
/* disconnect, reconnect and then do durable reopen */ |
| 3247 |
TALLOC_FREE(tree1); |
| 3248 |
|
| 3249 |
CHECK_NO_BREAK(tctx); |
| 3250 |
|
| 3251 |
lease_key2 = random(); |
| 3252 |
smb2_lease_v2_create(&io, &ls2, false /* dir */, fname, |
| 3253 |
lease_key2, 0, /* parent lease key */ |
| 3254 |
smb2_util_lease_state("RH"), 0 /* lease epoch */); |
| 3255 |
io.in.durable_open = false; |
| 3256 |
io.in.durable_open_v2 = true; |
| 3257 |
io.in.persistent_open = false; |
| 3258 |
io.in.create_guid = create_guid2; |
| 3259 |
io.in.timeout = UINT32_MAX; |
| 3260 |
|
| 3261 |
status = smb2_create(tree2, mem_ctx, &io); |
| 3262 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 3263 |
_h2 = io.out.file.handle; |
| 3264 |
h2 = &_h2; |
| 3265 |
CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE); |
| 3266 |
CHECK_VAL(io.out.durable_open, false); |
| 3267 |
CHECK_VAL(io.out.durable_open_v2, true); |
| 3268 |
CHECK_VAL(io.out.persistent_open, false); |
| 3269 |
CHECK_VAL(io.out.timeout, 300*1000); |
| 3270 |
ls2.lease_epoch += 1; |
| 3271 |
CHECK_LEASE_V2(&io, "RH", true, lease_key2, |
| 3272 |
0, 0, ls2.lease_epoch); |
| 3273 |
|
| 3274 |
CHECK_NO_BREAK(tctx); |
| 3275 |
|
| 3276 |
if (!torture_smb2_connection_ext(tctx, 0, &options1, &tree1)) { |
| 3277 |
torture_warning(tctx, "couldn't reconnect, bailing\n"); |
| 3278 |
ret = false; |
| 3279 |
goto done; |
| 3280 |
} |
| 3281 |
|
| 3282 |
ZERO_STRUCT(io); |
| 3283 |
io.in.fname = fname; |
| 3284 |
io.in.durable_open_v2 = false; |
| 3285 |
io.in.durable_handle_v2 = h1a; |
| 3286 |
io.in.create_guid = create_guid1a; |
| 3287 |
io.in.lease_request_v2 = &ls1a; |
| 3288 |
io.in.oplock_level = SMB2_OPLOCK_LEVEL_LEASE; |
| 3289 |
|
| 3290 |
status = smb2_create(tree1, mem_ctx, &io); |
| 3291 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 3292 |
_h1a = io.out.file.handle; |
| 3293 |
h1a = &_h1a; |
| 3294 |
CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE); |
| 3295 |
CHECK_VAL(io.out.durable_open, false); |
| 3296 |
CHECK_VAL(io.out.durable_open_v2, false); /* no dh2q response blob */ |
| 3297 |
CHECK_VAL(io.out.persistent_open, false); |
| 3298 |
CHECK_LEASE_V2(&io, "RH", true, lease_key1a, |
| 3299 |
0, 0, ls1a.lease_epoch); |
| 3300 |
|
| 3301 |
ZERO_STRUCT(io); |
| 3302 |
io.in.fname = fname; |
| 3303 |
io.in.durable_open_v2 = false; |
| 3304 |
io.in.durable_handle_v2 = h1b; |
| 3305 |
io.in.create_guid = create_guid1b; |
| 3306 |
io.in.lease_request_v2 = &ls1b; |
| 3307 |
io.in.oplock_level = SMB2_OPLOCK_LEVEL_LEASE; |
| 3308 |
|
| 3309 |
status = smb2_create(tree1, mem_ctx, &io); |
| 3310 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 3311 |
_h1b = io.out.file.handle; |
| 3312 |
h1b = &_h1b; |
| 3313 |
CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE); |
| 3314 |
CHECK_VAL(io.out.durable_open, false); |
| 3315 |
CHECK_VAL(io.out.durable_open_v2, false); /* no dh2q response blob */ |
| 3316 |
CHECK_VAL(io.out.persistent_open, false); |
| 3317 |
CHECK_LEASE_V2(&io, "RH", true, lease_key1b, |
| 3318 |
0, 0, ls1b.lease_epoch); |
| 3319 |
|
| 3320 |
status = smb2_util_close(tree1, *h1a); |
| 3321 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 3322 |
h1a = NULL; |
| 3323 |
|
| 3324 |
status = smb2_util_close(tree1, *h1b); |
| 3325 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 3326 |
h1b = NULL; |
| 3327 |
|
| 3328 |
status = smb2_util_close(tree2, *h2); |
| 3329 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 3330 |
h2 = NULL; |
| 3331 |
|
| 3332 |
CHECK_NO_BREAK(tctx); |
| 3333 |
|
| 3334 |
done: |
| 3335 |
if (tree1 != NULL) { |
| 3336 |
smb2_keepalive(tree1->session->transport); |
| 3337 |
} |
| 3338 |
if (tree2 != NULL) { |
| 3339 |
smb2_keepalive(tree2->session->transport); |
| 3340 |
} |
| 3341 |
if (tree1 != NULL && h1a != NULL) { |
| 3342 |
smb2_util_close(tree1, *h1a); |
| 3343 |
} |
| 3344 |
if (tree1 != NULL && h1b != NULL) { |
| 3345 |
smb2_util_close(tree1, *h1b); |
| 3346 |
} |
| 3347 |
if (tree2 != NULL && h2 != NULL) { |
| 3348 |
smb2_util_close(tree2, *h2); |
| 3349 |
} |
| 3350 |
|
| 3351 |
if (tree1 != NULL) { |
| 3352 |
smb2_util_unlink(tree1, fname); |
| 3353 |
smb2_deltree(tree1, __func__); |
| 3354 |
|
| 3355 |
TALLOC_FREE(tree1); |
| 3356 |
} |
| 3357 |
|
| 3358 |
TALLOC_FREE(tree2); |
| 3359 |
|
| 3360 |
talloc_free(mem_ctx); |
| 3361 |
|
| 3362 |
return ret; |
| 3363 |
} |
| 3364 |
|
| 3365 |
/** |
| 3366 |
* 1. durable open with L1A(RH) on tree1 => h1a |
| 3367 |
* 1. durable open with L1B(RH) on tree1 => h1b |
| 3368 |
* 2. disconnect tree1 |
| 3369 |
* 3. durable open with L2(RWH) on tree2 => h2 => RH |
| 3370 |
* 4. reconnect tree1 |
| 3371 |
* 5. durable reconnect L1A(RH) => h1a |
| 3372 |
* 6. durable reconnect L1B(RH) => h1a |
| 3373 |
*/ |
| 3374 |
static bool test_durable_v2_open_keep_disconnected_rh_with_rwh_open(struct torture_context *tctx, |
| 3375 |
struct smb2_tree *tree1, |
| 3376 |
struct smb2_tree *tree2) |
| 3377 |
{ |
| 3378 |
TALLOC_CTX *mem_ctx = talloc_new(tctx); |
| 3379 |
NTSTATUS status; |
| 3380 |
char fname[256]; |
| 3381 |
struct smb2_handle dh; |
| 3382 |
struct smb2_handle _h1a; |
| 3383 |
struct smb2_handle *h1a = NULL; |
| 3384 |
struct smb2_handle _h1b; |
| 3385 |
struct smb2_handle *h1b = NULL; |
| 3386 |
struct smb2_handle _h2; |
| 3387 |
struct smb2_handle *h2 = NULL; |
| 3388 |
struct smb2_create io; |
| 3389 |
struct GUID create_guid1a = GUID_random(); |
| 3390 |
struct GUID create_guid1b = GUID_random(); |
| 3391 |
struct GUID create_guid2 = GUID_random(); |
| 3392 |
struct smb2_lease ls1a; |
| 3393 |
uint64_t lease_key1a; |
| 3394 |
struct smb2_lease ls1b; |
| 3395 |
uint64_t lease_key1b; |
| 3396 |
struct smb2_lease ls2; |
| 3397 |
uint64_t lease_key2; |
| 3398 |
bool ret = true; |
| 3399 |
struct smbcli_options options1; |
| 3400 |
uint32_t caps; |
| 3401 |
|
| 3402 |
caps = smb2cli_conn_server_capabilities(tree1->session->transport->conn); |
| 3403 |
if (!(caps & SMB2_CAP_LEASING)) { |
| 3404 |
torture_skip(tctx, "leases are not supported"); |
| 3405 |
} |
| 3406 |
|
| 3407 |
options1 = tree1->session->transport->options; |
| 3408 |
|
| 3409 |
tree1->session->transport->lease.handler = torture_lease_handler; |
| 3410 |
tree1->session->transport->lease.private_data = tree1; |
| 3411 |
|
| 3412 |
tree2->session->transport->lease.handler = torture_lease_handler; |
| 3413 |
tree2->session->transport->lease.private_data = tree2; |
| 3414 |
|
| 3415 |
torture_reset_lease_break_info(tctx, &lease_break_info); |
| 3416 |
|
| 3417 |
smb2_deltree(tree1, __func__); |
| 3418 |
status = torture_smb2_testdir(tree1, __func__, &dh); |
| 3419 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 3420 |
"torture_smb2_testdir failed\n"); |
| 3421 |
smb2_util_close(tree1, dh); |
| 3422 |
|
| 3423 |
/* Choose a random name in case the state is left a little funky. */ |
| 3424 |
snprintf(fname, 256, "%s\\file_%s.dat", |
| 3425 |
__func__, generate_random_str(tctx, 8)); |
| 3426 |
|
| 3427 |
smb2_util_unlink(tree1, fname); |
| 3428 |
|
| 3429 |
lease_key1a = random(); |
| 3430 |
smb2_lease_v2_create(&io, &ls1a, false /* dir */, fname, |
| 3431 |
lease_key1a, 0, /* parent lease key */ |
| 3432 |
smb2_util_lease_state("RH"), 0 /* lease epoch */); |
| 3433 |
io.in.durable_open = false; |
| 3434 |
io.in.durable_open_v2 = true; |
| 3435 |
io.in.persistent_open = false; |
| 3436 |
io.in.create_guid = create_guid1a; |
| 3437 |
io.in.timeout = UINT32_MAX; |
| 3438 |
|
| 3439 |
status = smb2_create(tree1, mem_ctx, &io); |
| 3440 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 3441 |
_h1a = io.out.file.handle; |
| 3442 |
h1a = &_h1a; |
| 3443 |
CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE); |
| 3444 |
CHECK_VAL(io.out.durable_open, false); |
| 3445 |
CHECK_VAL(io.out.durable_open_v2, true); |
| 3446 |
CHECK_VAL(io.out.persistent_open, false); |
| 3447 |
CHECK_VAL(io.out.timeout, 300*1000); |
| 3448 |
ls1a.lease_epoch += 1; |
| 3449 |
CHECK_LEASE_V2(&io, "RH", true, lease_key1a, |
| 3450 |
0, 0, ls1a.lease_epoch); |
| 3451 |
|
| 3452 |
lease_key1b = random(); |
| 3453 |
smb2_lease_v2_create(&io, &ls1b, false /* dir */, fname, |
| 3454 |
lease_key1b, 0, /* parent lease key */ |
| 3455 |
smb2_util_lease_state("RH"), 0 /* lease epoch */); |
| 3456 |
io.in.durable_open = false; |
| 3457 |
io.in.durable_open_v2 = true; |
| 3458 |
io.in.persistent_open = false; |
| 3459 |
io.in.create_guid = create_guid1b; |
| 3460 |
io.in.timeout = UINT32_MAX; |
| 3461 |
|
| 3462 |
status = smb2_create(tree1, mem_ctx, &io); |
| 3463 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 3464 |
_h1b = io.out.file.handle; |
| 3465 |
h1b = &_h1b; |
| 3466 |
CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE); |
| 3467 |
CHECK_VAL(io.out.durable_open, false); |
| 3468 |
CHECK_VAL(io.out.durable_open_v2, true); |
| 3469 |
CHECK_VAL(io.out.persistent_open, false); |
| 3470 |
CHECK_VAL(io.out.timeout, 300*1000); |
| 3471 |
ls1b.lease_epoch += 1; |
| 3472 |
CHECK_LEASE_V2(&io, "RH", true, lease_key1b, |
| 3473 |
0, 0, ls1b.lease_epoch); |
| 3474 |
|
| 3475 |
CHECK_NO_BREAK(tctx); |
| 3476 |
|
| 3477 |
/* disconnect, reconnect and then do durable reopen */ |
| 3478 |
TALLOC_FREE(tree1); |
| 3479 |
|
| 3480 |
CHECK_NO_BREAK(tctx); |
| 3481 |
|
| 3482 |
lease_key2 = random(); |
| 3483 |
smb2_lease_v2_create(&io, &ls2, false /* dir */, fname, |
| 3484 |
lease_key2, 0, /* parent lease key */ |
| 3485 |
smb2_util_lease_state("RWH"), 0 /* lease epoch */); |
| 3486 |
io.in.durable_open = false; |
| 3487 |
io.in.durable_open_v2 = true; |
| 3488 |
io.in.persistent_open = false; |
| 3489 |
io.in.create_guid = create_guid2; |
| 3490 |
io.in.timeout = UINT32_MAX; |
| 3491 |
|
| 3492 |
status = smb2_create(tree2, mem_ctx, &io); |
| 3493 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 3494 |
_h2 = io.out.file.handle; |
| 3495 |
h2 = &_h2; |
| 3496 |
CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE); |
| 3497 |
CHECK_VAL(io.out.durable_open, false); |
| 3498 |
CHECK_VAL(io.out.durable_open_v2, true); |
| 3499 |
CHECK_VAL(io.out.persistent_open, false); |
| 3500 |
CHECK_VAL(io.out.timeout, 300*1000); |
| 3501 |
ls2.lease_epoch += 1; |
| 3502 |
CHECK_LEASE_V2(&io, "RH", true, lease_key2, |
| 3503 |
0, 0, ls2.lease_epoch); |
| 3504 |
|
| 3505 |
CHECK_NO_BREAK(tctx); |
| 3506 |
|
| 3507 |
if (!torture_smb2_connection_ext(tctx, 0, &options1, &tree1)) { |
| 3508 |
torture_warning(tctx, "couldn't reconnect, bailing\n"); |
| 3509 |
ret = false; |
| 3510 |
goto done; |
| 3511 |
} |
| 3512 |
|
| 3513 |
ZERO_STRUCT(io); |
| 3514 |
io.in.fname = fname; |
| 3515 |
io.in.durable_open_v2 = false; |
| 3516 |
io.in.durable_handle_v2 = h1a; |
| 3517 |
io.in.create_guid = create_guid1a; |
| 3518 |
io.in.lease_request_v2 = &ls1a; |
| 3519 |
io.in.oplock_level = SMB2_OPLOCK_LEVEL_LEASE; |
| 3520 |
|
| 3521 |
status = smb2_create(tree1, mem_ctx, &io); |
| 3522 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 3523 |
_h1a = io.out.file.handle; |
| 3524 |
h1a = &_h1a; |
| 3525 |
CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE); |
| 3526 |
CHECK_VAL(io.out.durable_open, false); |
| 3527 |
CHECK_VAL(io.out.durable_open_v2, false); /* no dh2q response blob */ |
| 3528 |
CHECK_VAL(io.out.persistent_open, false); |
| 3529 |
CHECK_LEASE_V2(&io, "RH", true, lease_key1a, |
| 3530 |
0, 0, ls1a.lease_epoch); |
| 3531 |
|
| 3532 |
ZERO_STRUCT(io); |
| 3533 |
io.in.fname = fname; |
| 3534 |
io.in.durable_open_v2 = false; |
| 3535 |
io.in.durable_handle_v2 = h1b; |
| 3536 |
io.in.create_guid = create_guid1b; |
| 3537 |
io.in.lease_request_v2 = &ls1b; |
| 3538 |
io.in.oplock_level = SMB2_OPLOCK_LEVEL_LEASE; |
| 3539 |
|
| 3540 |
status = smb2_create(tree1, mem_ctx, &io); |
| 3541 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 3542 |
_h1b = io.out.file.handle; |
| 3543 |
h1b = &_h1b; |
| 3544 |
CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE); |
| 3545 |
CHECK_VAL(io.out.durable_open, false); |
| 3546 |
CHECK_VAL(io.out.durable_open_v2, false); /* no dh2q response blob */ |
| 3547 |
CHECK_VAL(io.out.persistent_open, false); |
| 3548 |
CHECK_LEASE_V2(&io, "RH", true, lease_key1b, |
| 3549 |
0, 0, ls1b.lease_epoch); |
| 3550 |
|
| 3551 |
status = smb2_util_close(tree1, *h1a); |
| 3552 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 3553 |
h1a = NULL; |
| 3554 |
|
| 3555 |
status = smb2_util_close(tree1, *h1b); |
| 3556 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 3557 |
h1b = NULL; |
| 3558 |
|
| 3559 |
status = smb2_util_close(tree2, *h2); |
| 3560 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 3561 |
h2 = NULL; |
| 3562 |
|
| 3563 |
CHECK_NO_BREAK(tctx); |
| 3564 |
|
| 3565 |
done: |
| 3566 |
if (tree1 != NULL) { |
| 3567 |
smb2_keepalive(tree1->session->transport); |
| 3568 |
} |
| 3569 |
if (tree2 != NULL) { |
| 3570 |
smb2_keepalive(tree2->session->transport); |
| 3571 |
} |
| 3572 |
if (tree1 != NULL && h1a != NULL) { |
| 3573 |
smb2_util_close(tree1, *h1a); |
| 3574 |
} |
| 3575 |
if (tree1 != NULL && h1b != NULL) { |
| 3576 |
smb2_util_close(tree1, *h1b); |
| 3577 |
} |
| 3578 |
if (tree2 != NULL && h2 != NULL) { |
| 3579 |
smb2_util_close(tree2, *h2); |
| 3580 |
} |
| 3581 |
|
| 3582 |
if (tree1 != NULL) { |
| 3583 |
smb2_util_unlink(tree1, fname); |
| 3584 |
smb2_deltree(tree1, __func__); |
| 3585 |
|
| 3586 |
TALLOC_FREE(tree1); |
| 3587 |
} |
| 3588 |
|
| 3589 |
TALLOC_FREE(tree2); |
| 3590 |
|
| 3591 |
talloc_free(mem_ctx); |
| 3592 |
|
| 3593 |
return ret; |
| 3594 |
} |
| 3595 |
|
| 3596 |
/** |
| 3597 |
* 1. durable open with L1(RWH) on tree1 => h1 |
| 3598 |
* 2. disconnect tree1 |
| 3599 |
* 3. stat open on tree2 => h2 |
| 3600 |
* 4. reconnect tree1 |
| 3601 |
* 5. durable reconnect L1(RWH) => h1 |
| 3602 |
*/ |
| 3603 |
static bool test_durable_v2_open_keep_disconnected_rwh_with_stat_open(struct torture_context *tctx, |
| 3604 |
struct smb2_tree *tree1, |
| 3605 |
struct smb2_tree *tree2) |
| 3606 |
{ |
| 3607 |
TALLOC_CTX *mem_ctx = talloc_new(tctx); |
| 3608 |
NTSTATUS status; |
| 3609 |
char fname[256]; |
| 3610 |
struct smb2_handle dh; |
| 3611 |
struct smb2_handle _h1; |
| 3612 |
struct smb2_handle *h1 = NULL; |
| 3613 |
struct smb2_handle _h2; |
| 3614 |
struct smb2_handle *h2 = NULL; |
| 3615 |
struct smb2_create io; |
| 3616 |
struct GUID create_guid1 = GUID_random(); |
| 3617 |
struct smb2_lease ls1; |
| 3618 |
uint64_t lease_key1; |
| 3619 |
bool ret = true; |
| 3620 |
struct smbcli_options options1; |
| 3621 |
uint32_t caps; |
| 3622 |
|
| 3623 |
caps = smb2cli_conn_server_capabilities(tree1->session->transport->conn); |
| 3624 |
if (!(caps & SMB2_CAP_LEASING)) { |
| 3625 |
torture_skip(tctx, "leases are not supported"); |
| 3626 |
} |
| 3627 |
|
| 3628 |
options1 = tree1->session->transport->options; |
| 3629 |
|
| 3630 |
tree1->session->transport->lease.handler = torture_lease_handler; |
| 3631 |
tree1->session->transport->lease.private_data = tree1; |
| 3632 |
|
| 3633 |
tree2->session->transport->lease.handler = torture_lease_handler; |
| 3634 |
tree2->session->transport->lease.private_data = tree2; |
| 3635 |
|
| 3636 |
torture_reset_lease_break_info(tctx, &lease_break_info); |
| 3637 |
|
| 3638 |
smb2_deltree(tree1, __func__); |
| 3639 |
status = torture_smb2_testdir(tree1, __func__, &dh); |
| 3640 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 3641 |
"torture_smb2_testdir failed\n"); |
| 3642 |
smb2_util_close(tree1, dh); |
| 3643 |
|
| 3644 |
/* Choose a random name in case the state is left a little funky. */ |
| 3645 |
snprintf(fname, 256, "%s\\file_%s.dat", |
| 3646 |
__func__, generate_random_str(tctx, 8)); |
| 3647 |
|
| 3648 |
smb2_util_unlink(tree1, fname); |
| 3649 |
|
| 3650 |
lease_key1 = random(); |
| 3651 |
smb2_lease_v2_create(&io, &ls1, false /* dir */, fname, |
| 3652 |
lease_key1, 0, /* parent lease key */ |
| 3653 |
smb2_util_lease_state("RWH"), 0 /* lease epoch */); |
| 3654 |
io.in.durable_open = false; |
| 3655 |
io.in.durable_open_v2 = true; |
| 3656 |
io.in.persistent_open = false; |
| 3657 |
io.in.create_guid = create_guid1; |
| 3658 |
io.in.timeout = UINT32_MAX; |
| 3659 |
|
| 3660 |
status = smb2_create(tree1, mem_ctx, &io); |
| 3661 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 3662 |
_h1 = io.out.file.handle; |
| 3663 |
h1 = &_h1; |
| 3664 |
CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE); |
| 3665 |
CHECK_VAL(io.out.durable_open, false); |
| 3666 |
CHECK_VAL(io.out.durable_open_v2, true); |
| 3667 |
CHECK_VAL(io.out.persistent_open, false); |
| 3668 |
CHECK_VAL(io.out.timeout, 300*1000); |
| 3669 |
ls1.lease_epoch += 1; |
| 3670 |
CHECK_LEASE_V2(&io, "RWH", true, lease_key1, |
| 3671 |
0, 0, ls1.lease_epoch); |
| 3672 |
|
| 3673 |
CHECK_NO_BREAK(tctx); |
| 3674 |
|
| 3675 |
/* disconnect, reconnect and then do durable reopen */ |
| 3676 |
TALLOC_FREE(tree1); |
| 3677 |
|
| 3678 |
CHECK_NO_BREAK(tctx); |
| 3679 |
|
| 3680 |
smb2_generic_create(&io, NULL, false /* dir */, fname, |
| 3681 |
FILE_OPEN_IF, 0, 0, 0); |
| 3682 |
io.in.desired_access = SEC_FILE_READ_ATTRIBUTE; |
| 3683 |
status = smb2_create(tree2, mem_ctx, &io); |
| 3684 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 3685 |
_h2 = io.out.file.handle; |
| 3686 |
h2 = &_h2; |
| 3687 |
CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE); |
| 3688 |
CHECK_VAL(io.out.durable_open, false); |
| 3689 |
CHECK_VAL(io.out.durable_open_v2, false); |
| 3690 |
CHECK_VAL(io.out.persistent_open, false); |
| 3691 |
|
| 3692 |
CHECK_NO_BREAK(tctx); |
| 3693 |
|
| 3694 |
if (!torture_smb2_connection_ext(tctx, 0, &options1, &tree1)) { |
| 3695 |
torture_warning(tctx, "couldn't reconnect, bailing\n"); |
| 3696 |
ret = false; |
| 3697 |
goto done; |
| 3698 |
} |
| 3699 |
|
| 3700 |
ZERO_STRUCT(io); |
| 3701 |
io.in.fname = fname; |
| 3702 |
io.in.durable_open_v2 = false; |
| 3703 |
io.in.durable_handle_v2 = h1; |
| 3704 |
io.in.create_guid = create_guid1; |
| 3705 |
io.in.lease_request_v2 = &ls1; |
| 3706 |
io.in.oplock_level = SMB2_OPLOCK_LEVEL_LEASE; |
| 3707 |
|
| 3708 |
status = smb2_create(tree1, mem_ctx, &io); |
| 3709 |
|
| 3710 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 3711 |
_h1 = io.out.file.handle; |
| 3712 |
h1 = &_h1; |
| 3713 |
CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE); |
| 3714 |
CHECK_VAL(io.out.durable_open, false); |
| 3715 |
CHECK_VAL(io.out.durable_open_v2, false); /* no dh2q response blob */ |
| 3716 |
CHECK_VAL(io.out.persistent_open, false); |
| 3717 |
CHECK_LEASE_V2(&io, "RWH", true, lease_key1, |
| 3718 |
0, 0, ls1.lease_epoch); |
| 3719 |
|
| 3720 |
status = smb2_util_close(tree1, *h1); |
| 3721 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 3722 |
h1 = NULL; |
| 3723 |
|
| 3724 |
status = smb2_util_close(tree2, *h2); |
| 3725 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 3726 |
h2 = NULL; |
| 3727 |
|
| 3728 |
CHECK_NO_BREAK(tctx); |
| 3729 |
|
| 3730 |
done: |
| 3731 |
if (tree1 != NULL) { |
| 3732 |
smb2_keepalive(tree1->session->transport); |
| 3733 |
} |
| 3734 |
if (tree2 != NULL) { |
| 3735 |
smb2_keepalive(tree2->session->transport); |
| 3736 |
} |
| 3737 |
if (tree1 != NULL && h1 != NULL) { |
| 3738 |
smb2_util_close(tree1, *h1); |
| 3739 |
} |
| 3740 |
if (tree2 != NULL && h2 != NULL) { |
| 3741 |
smb2_util_close(tree2, *h2); |
| 3742 |
} |
| 3743 |
|
| 3744 |
if (tree1 != NULL) { |
| 3745 |
smb2_util_unlink(tree1, fname); |
| 3746 |
smb2_deltree(tree1, __func__); |
| 3747 |
|
| 3748 |
TALLOC_FREE(tree1); |
| 3749 |
} |
| 3750 |
|
| 3751 |
TALLOC_FREE(tree2); |
| 3752 |
|
| 3753 |
talloc_free(mem_ctx); |
| 3754 |
|
| 3755 |
return ret; |
| 3756 |
} |
| 3757 |
|
| 3758 |
/** |
| 3759 |
* 1. durable open with L1(RWH) on tree1 => h1 |
| 3760 |
* 2. disconnect tree1 |
| 3761 |
* 3. durable open with L2(RWH) on tree2 => h2 |
| 3762 |
* 4. reconnect tree1 |
| 3763 |
* 5. durable reconnect L1(RH) => h1 => not found |
| 3764 |
*/ |
| 3765 |
static bool test_durable_v2_open_purge_disconnected_rwh_with_rwh_open(struct torture_context *tctx, |
| 3766 |
struct smb2_tree *tree1, |
| 3767 |
struct smb2_tree *tree2) |
| 3768 |
{ |
| 3769 |
TALLOC_CTX *mem_ctx = talloc_new(tctx); |
| 3770 |
NTSTATUS status; |
| 3771 |
char fname[256]; |
| 3772 |
struct smb2_handle dh; |
| 3773 |
struct smb2_handle _h1; |
| 3774 |
struct smb2_handle *h1 = NULL; |
| 3775 |
struct smb2_handle _h2; |
| 3776 |
struct smb2_handle *h2 = NULL; |
| 3777 |
struct smb2_create io; |
| 3778 |
struct GUID create_guid1 = GUID_random(); |
| 3779 |
struct GUID create_guid2 = GUID_random(); |
| 3780 |
struct smb2_lease ls1; |
| 3781 |
uint64_t lease_key1; |
| 3782 |
struct smb2_lease ls2; |
| 3783 |
uint64_t lease_key2; |
| 3784 |
bool ret = true; |
| 3785 |
struct smbcli_options options1; |
| 3786 |
uint32_t caps; |
| 3787 |
|
| 3788 |
caps = smb2cli_conn_server_capabilities(tree1->session->transport->conn); |
| 3789 |
if (!(caps & SMB2_CAP_LEASING)) { |
| 3790 |
torture_skip(tctx, "leases are not supported"); |
| 3791 |
} |
| 3792 |
|
| 3793 |
options1 = tree1->session->transport->options; |
| 3794 |
|
| 3795 |
tree1->session->transport->lease.handler = torture_lease_handler; |
| 3796 |
tree1->session->transport->lease.private_data = tree1; |
| 3797 |
|
| 3798 |
tree2->session->transport->lease.handler = torture_lease_handler; |
| 3799 |
tree2->session->transport->lease.private_data = tree2; |
| 3800 |
|
| 3801 |
torture_reset_lease_break_info(tctx, &lease_break_info); |
| 3802 |
|
| 3803 |
smb2_deltree(tree1, __func__); |
| 3804 |
status = torture_smb2_testdir(tree1, __func__, &dh); |
| 3805 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 3806 |
"torture_smb2_testdir failed\n"); |
| 3807 |
smb2_util_close(tree1, dh); |
| 3808 |
|
| 3809 |
/* Choose a random name in case the state is left a little funky. */ |
| 3810 |
snprintf(fname, 256, "%s\\file_%s.dat", |
| 3811 |
__func__, generate_random_str(tctx, 8)); |
| 3812 |
|
| 3813 |
smb2_util_unlink(tree1, fname); |
| 3814 |
|
| 3815 |
lease_key1 = random(); |
| 3816 |
smb2_lease_v2_create(&io, &ls1, false /* dir */, fname, |
| 3817 |
lease_key1, 0, /* parent lease key */ |
| 3818 |
smb2_util_lease_state("RWH"), 0 /* lease epoch */); |
| 3819 |
io.in.durable_open = false; |
| 3820 |
io.in.durable_open_v2 = true; |
| 3821 |
io.in.persistent_open = false; |
| 3822 |
io.in.create_guid = create_guid1; |
| 3823 |
io.in.timeout = UINT32_MAX; |
| 3824 |
|
| 3825 |
status = smb2_create(tree1, mem_ctx, &io); |
| 3826 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 3827 |
_h1 = io.out.file.handle; |
| 3828 |
h1 = &_h1; |
| 3829 |
CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE); |
| 3830 |
CHECK_VAL(io.out.durable_open, false); |
| 3831 |
CHECK_VAL(io.out.durable_open_v2, true); |
| 3832 |
CHECK_VAL(io.out.persistent_open, false); |
| 3833 |
CHECK_VAL(io.out.timeout, 300*1000); |
| 3834 |
ls1.lease_epoch += 1; |
| 3835 |
CHECK_LEASE_V2(&io, "RWH", true, lease_key1, |
| 3836 |
0, 0, ls1.lease_epoch); |
| 3837 |
|
| 3838 |
CHECK_NO_BREAK(tctx); |
| 3839 |
|
| 3840 |
/* disconnect, reconnect and then do durable reopen */ |
| 3841 |
TALLOC_FREE(tree1); |
| 3842 |
|
| 3843 |
CHECK_NO_BREAK(tctx); |
| 3844 |
|
| 3845 |
lease_key2 = random(); |
| 3846 |
smb2_lease_v2_create(&io, &ls2, false /* dir */, fname, |
| 3847 |
lease_key2, 0, /* parent lease key */ |
| 3848 |
smb2_util_lease_state("RWH"), 0 /* lease epoch */); |
| 3849 |
io.in.durable_open = false; |
| 3850 |
io.in.durable_open_v2 = true; |
| 3851 |
io.in.persistent_open = false; |
| 3852 |
io.in.create_guid = create_guid2; |
| 3853 |
io.in.timeout = UINT32_MAX; |
| 3854 |
|
| 3855 |
status = smb2_create(tree2, mem_ctx, &io); |
| 3856 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 3857 |
_h2 = io.out.file.handle; |
| 3858 |
h2 = &_h2; |
| 3859 |
CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE); |
| 3860 |
CHECK_VAL(io.out.durable_open, false); |
| 3861 |
CHECK_VAL(io.out.durable_open_v2, true); |
| 3862 |
CHECK_VAL(io.out.persistent_open, false); |
| 3863 |
CHECK_VAL(io.out.timeout, 300*1000); |
| 3864 |
ls2.lease_epoch += 1; |
| 3865 |
CHECK_LEASE_V2(&io, "RWH", true, lease_key2, |
| 3866 |
0, 0, ls2.lease_epoch); |
| 3867 |
|
| 3868 |
CHECK_NO_BREAK(tctx); |
| 3869 |
|
| 3870 |
if (!torture_smb2_connection_ext(tctx, 0, &options1, &tree1)) { |
| 3871 |
torture_warning(tctx, "couldn't reconnect, bailing\n"); |
| 3872 |
ret = false; |
| 3873 |
goto done; |
| 3874 |
} |
| 3875 |
|
| 3876 |
ZERO_STRUCT(io); |
| 3877 |
io.in.fname = fname; |
| 3878 |
io.in.durable_open_v2 = false; |
| 3879 |
io.in.durable_handle_v2 = h1; |
| 3880 |
io.in.create_guid = create_guid1; |
| 3881 |
io.in.lease_request_v2 = &ls1; |
| 3882 |
io.in.oplock_level = SMB2_OPLOCK_LEVEL_LEASE; |
| 3883 |
ls1.lease_state = smb2_util_lease_state("RH"); |
| 3884 |
|
| 3885 |
status = smb2_create(tree1, mem_ctx, &io); |
| 3886 |
CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND); |
| 3887 |
|
| 3888 |
status = smb2_util_close(tree2, *h2); |
| 3889 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 3890 |
h2 = NULL; |
| 3891 |
|
| 3892 |
CHECK_NO_BREAK(tctx); |
| 3893 |
|
| 3894 |
done: |
| 3895 |
if (tree1 != NULL) { |
| 3896 |
smb2_keepalive(tree1->session->transport); |
| 3897 |
} |
| 3898 |
if (tree2 != NULL) { |
| 3899 |
smb2_keepalive(tree2->session->transport); |
| 3900 |
} |
| 3901 |
if (tree1 != NULL && h1 != NULL) { |
| 3902 |
smb2_util_close(tree1, *h1); |
| 3903 |
} |
| 3904 |
if (tree2 != NULL && h2 != NULL) { |
| 3905 |
smb2_util_close(tree2, *h2); |
| 3906 |
} |
| 3907 |
|
| 3908 |
if (tree1 != NULL) { |
| 3909 |
smb2_util_unlink(tree1, fname); |
| 3910 |
smb2_deltree(tree1, __func__); |
| 3911 |
|
| 3912 |
TALLOC_FREE(tree1); |
| 3913 |
} |
| 3914 |
|
| 3915 |
TALLOC_FREE(tree2); |
| 3916 |
|
| 3917 |
talloc_free(mem_ctx); |
| 3918 |
|
| 3919 |
return ret; |
| 3920 |
} |
| 3921 |
|
| 3922 |
/** |
| 3923 |
* 1. durable open with L1(RWH) on tree1 => h1 |
| 3924 |
* 2. disconnect tree1 |
| 3925 |
* 3. durable open with L2(RH) on tree2 => h2 |
| 3926 |
* 4. reconnect tree1 |
| 3927 |
* 5. durable reconnect L1(RH) => h1 => not found |
| 3928 |
*/ |
| 3929 |
static bool test_durable_v2_open_purge_disconnected_rwh_with_rh_open(struct torture_context *tctx, |
| 3930 |
struct smb2_tree *tree1, |
| 3931 |
struct smb2_tree *tree2) |
| 3932 |
{ |
| 3933 |
TALLOC_CTX *mem_ctx = talloc_new(tctx); |
| 3934 |
NTSTATUS status; |
| 3935 |
char fname[256]; |
| 3936 |
struct smb2_handle dh; |
| 3937 |
struct smb2_handle _h1; |
| 3938 |
struct smb2_handle *h1 = NULL; |
| 3939 |
struct smb2_handle _h2; |
| 3940 |
struct smb2_handle *h2 = NULL; |
| 3941 |
struct smb2_create io; |
| 3942 |
struct GUID create_guid1 = GUID_random(); |
| 3943 |
struct GUID create_guid2 = GUID_random(); |
| 3944 |
struct smb2_lease ls1; |
| 3945 |
uint64_t lease_key1; |
| 3946 |
struct smb2_lease ls2; |
| 3947 |
uint64_t lease_key2; |
| 3948 |
bool ret = true; |
| 3949 |
struct smbcli_options options1; |
| 3950 |
uint32_t caps; |
| 3951 |
|
| 3952 |
caps = smb2cli_conn_server_capabilities(tree1->session->transport->conn); |
| 3953 |
if (!(caps & SMB2_CAP_LEASING)) { |
| 3954 |
torture_skip(tctx, "leases are not supported"); |
| 3955 |
} |
| 3956 |
|
| 3957 |
options1 = tree1->session->transport->options; |
| 3958 |
|
| 3959 |
tree1->session->transport->lease.handler = torture_lease_handler; |
| 3960 |
tree1->session->transport->lease.private_data = tree1; |
| 3961 |
|
| 3962 |
tree2->session->transport->lease.handler = torture_lease_handler; |
| 3963 |
tree2->session->transport->lease.private_data = tree2; |
| 3964 |
|
| 3965 |
torture_reset_lease_break_info(tctx, &lease_break_info); |
| 3966 |
|
| 3967 |
smb2_deltree(tree1, __func__); |
| 3968 |
status = torture_smb2_testdir(tree1, __func__, &dh); |
| 3969 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 3970 |
"torture_smb2_testdir failed\n"); |
| 3971 |
smb2_util_close(tree1, dh); |
| 3972 |
|
| 3973 |
/* Choose a random name in case the state is left a little funky. */ |
| 3974 |
snprintf(fname, 256, "%s\\file_%s.dat", |
| 3975 |
__func__, generate_random_str(tctx, 8)); |
| 3976 |
|
| 3977 |
smb2_util_unlink(tree1, fname); |
| 3978 |
|
| 3979 |
lease_key1 = random(); |
| 3980 |
smb2_lease_v2_create(&io, &ls1, false /* dir */, fname, |
| 3981 |
lease_key1, 0, /* parent lease key */ |
| 3982 |
smb2_util_lease_state("RWH"), 0 /* lease epoch */); |
| 3983 |
io.in.durable_open = false; |
| 3984 |
io.in.durable_open_v2 = true; |
| 3985 |
io.in.persistent_open = false; |
| 3986 |
io.in.create_guid = create_guid1; |
| 3987 |
io.in.timeout = UINT32_MAX; |
| 3988 |
|
| 3989 |
status = smb2_create(tree1, mem_ctx, &io); |
| 3990 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 3991 |
_h1 = io.out.file.handle; |
| 3992 |
h1 = &_h1; |
| 3993 |
CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE); |
| 3994 |
CHECK_VAL(io.out.durable_open, false); |
| 3995 |
CHECK_VAL(io.out.durable_open_v2, true); |
| 3996 |
CHECK_VAL(io.out.persistent_open, false); |
| 3997 |
CHECK_VAL(io.out.timeout, 300*1000); |
| 3998 |
ls1.lease_epoch += 1; |
| 3999 |
CHECK_LEASE_V2(&io, "RWH", true, lease_key1, |
| 4000 |
0, 0, ls1.lease_epoch); |
| 4001 |
|
| 4002 |
CHECK_NO_BREAK(tctx); |
| 4003 |
|
| 4004 |
/* disconnect, reconnect and then do durable reopen */ |
| 4005 |
TALLOC_FREE(tree1); |
| 4006 |
|
| 4007 |
CHECK_NO_BREAK(tctx); |
| 4008 |
|
| 4009 |
lease_key2 = random(); |
| 4010 |
smb2_lease_v2_create(&io, &ls2, false /* dir */, fname, |
| 4011 |
lease_key2, 0, /* parent lease key */ |
| 4012 |
smb2_util_lease_state("RH"), 0 /* lease epoch */); |
| 4013 |
io.in.durable_open = false; |
| 4014 |
io.in.durable_open_v2 = true; |
| 4015 |
io.in.persistent_open = false; |
| 4016 |
io.in.create_guid = create_guid2; |
| 4017 |
io.in.timeout = UINT32_MAX; |
| 4018 |
|
| 4019 |
status = smb2_create(tree2, mem_ctx, &io); |
| 4020 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 4021 |
_h2 = io.out.file.handle; |
| 4022 |
h2 = &_h2; |
| 4023 |
CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE); |
| 4024 |
CHECK_VAL(io.out.durable_open, false); |
| 4025 |
CHECK_VAL(io.out.durable_open_v2, true); |
| 4026 |
CHECK_VAL(io.out.persistent_open, false); |
| 4027 |
CHECK_VAL(io.out.timeout, 300*1000); |
| 4028 |
ls2.lease_epoch += 1; |
| 4029 |
CHECK_LEASE_V2(&io, "RH", true, lease_key2, |
| 4030 |
0, 0, ls2.lease_epoch); |
| 4031 |
|
| 4032 |
CHECK_NO_BREAK(tctx); |
| 4033 |
|
| 4034 |
if (!torture_smb2_connection_ext(tctx, 0, &options1, &tree1)) { |
| 4035 |
torture_warning(tctx, "couldn't reconnect, bailing\n"); |
| 4036 |
ret = false; |
| 4037 |
goto done; |
| 4038 |
} |
| 4039 |
|
| 4040 |
ZERO_STRUCT(io); |
| 4041 |
io.in.fname = fname; |
| 4042 |
io.in.durable_open_v2 = false; |
| 4043 |
io.in.durable_handle_v2 = h1; |
| 4044 |
io.in.create_guid = create_guid1; |
| 4045 |
io.in.lease_request_v2 = &ls1; |
| 4046 |
io.in.oplock_level = SMB2_OPLOCK_LEVEL_LEASE; |
| 4047 |
ls1.lease_state = smb2_util_lease_state("RH"); |
| 4048 |
|
| 4049 |
status = smb2_create(tree1, mem_ctx, &io); |
| 4050 |
CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND); |
| 4051 |
|
| 4052 |
status = smb2_util_close(tree2, *h2); |
| 4053 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 4054 |
h2 = NULL; |
| 4055 |
|
| 4056 |
CHECK_NO_BREAK(tctx); |
| 4057 |
|
| 4058 |
done: |
| 4059 |
if (tree1 != NULL) { |
| 4060 |
smb2_keepalive(tree1->session->transport); |
| 4061 |
} |
| 4062 |
if (tree2 != NULL) { |
| 4063 |
smb2_keepalive(tree2->session->transport); |
| 4064 |
} |
| 4065 |
if (tree1 != NULL && h1 != NULL) { |
| 4066 |
smb2_util_close(tree1, *h1); |
| 4067 |
} |
| 4068 |
if (tree2 != NULL && h2 != NULL) { |
| 4069 |
smb2_util_close(tree2, *h2); |
| 4070 |
} |
| 4071 |
|
| 4072 |
if (tree1 != NULL) { |
| 4073 |
smb2_util_unlink(tree1, fname); |
| 4074 |
smb2_deltree(tree1, __func__); |
| 4075 |
|
| 4076 |
TALLOC_FREE(tree1); |
| 4077 |
} |
| 4078 |
|
| 4079 |
TALLOC_FREE(tree2); |
| 4080 |
|
| 4081 |
talloc_free(mem_ctx); |
| 4082 |
|
| 4083 |
return ret; |
| 4084 |
} |
| 4085 |
|
| 4086 |
/** |
| 4087 |
* 1. durable open with L1A(RH) on tree1 => h1a |
| 4088 |
* 2. durable open with L1B(RH) on tree1 => h1b |
| 4089 |
* 3. disconnect tree1 |
| 4090 |
* 4. open with SHARE_NONE on tree2 => h2 |
| 4091 |
* 5. reconnect tree1 |
| 4092 |
* 6. durable reconnect L1A(RH) => not found |
| 4093 |
* 7. durable reconnect L1B(RH) => not found |
| 4094 |
*/ |
| 4095 |
static bool test_durable_v2_open_purge_disconnected_rh_with_share_none_open(struct torture_context *tctx, |
| 4096 |
struct smb2_tree *tree1, |
| 4097 |
struct smb2_tree *tree2) |
| 4098 |
{ |
| 4099 |
TALLOC_CTX *mem_ctx = talloc_new(tctx); |
| 4100 |
NTSTATUS status; |
| 4101 |
char fname[256]; |
| 4102 |
struct smb2_handle dh; |
| 4103 |
struct smb2_handle _h1a; |
| 4104 |
struct smb2_handle *h1a = NULL; |
| 4105 |
struct smb2_handle _h1b; |
| 4106 |
struct smb2_handle *h1b = NULL; |
| 4107 |
struct smb2_handle _h2; |
| 4108 |
struct smb2_handle *h2 = NULL; |
| 4109 |
struct smb2_create io; |
| 4110 |
struct GUID create_guid1a = GUID_random(); |
| 4111 |
struct GUID create_guid1b = GUID_random(); |
| 4112 |
struct smb2_lease ls1a; |
| 4113 |
uint64_t lease_key1a; |
| 4114 |
struct smb2_lease ls1b; |
| 4115 |
uint64_t lease_key1b; |
| 4116 |
bool ret = true; |
| 4117 |
struct smbcli_options options1; |
| 4118 |
uint32_t caps; |
| 4119 |
|
| 4120 |
caps = smb2cli_conn_server_capabilities(tree1->session->transport->conn); |
| 4121 |
if (!(caps & SMB2_CAP_LEASING)) { |
| 4122 |
torture_skip(tctx, "leases are not supported"); |
| 4123 |
} |
| 4124 |
|
| 4125 |
options1 = tree1->session->transport->options; |
| 4126 |
|
| 4127 |
tree1->session->transport->lease.handler = torture_lease_handler; |
| 4128 |
tree1->session->transport->lease.private_data = tree1; |
| 4129 |
|
| 4130 |
tree2->session->transport->lease.handler = torture_lease_handler; |
| 4131 |
tree2->session->transport->lease.private_data = tree2; |
| 4132 |
|
| 4133 |
torture_reset_lease_break_info(tctx, &lease_break_info); |
| 4134 |
|
| 4135 |
smb2_deltree(tree1, __func__); |
| 4136 |
status = torture_smb2_testdir(tree1, __func__, &dh); |
| 4137 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 4138 |
"torture_smb2_testdir failed\n"); |
| 4139 |
smb2_util_close(tree1, dh); |
| 4140 |
|
| 4141 |
/* Choose a random name in case the state is left a little funky. */ |
| 4142 |
snprintf(fname, 256, "%s\\file_%s.dat", |
| 4143 |
__func__, generate_random_str(tctx, 8)); |
| 4144 |
|
| 4145 |
smb2_util_unlink(tree1, fname); |
| 4146 |
|
| 4147 |
lease_key1a = random(); |
| 4148 |
smb2_lease_v2_create(&io, &ls1a, false /* dir */, fname, |
| 4149 |
lease_key1a, 0, /* parent lease key */ |
| 4150 |
smb2_util_lease_state("RH"), 0 /* lease epoch */); |
| 4151 |
io.in.durable_open = false; |
| 4152 |
io.in.durable_open_v2 = true; |
| 4153 |
io.in.persistent_open = false; |
| 4154 |
io.in.create_guid = create_guid1a; |
| 4155 |
io.in.timeout = UINT32_MAX; |
| 4156 |
|
| 4157 |
status = smb2_create(tree1, mem_ctx, &io); |
| 4158 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 4159 |
_h1a = io.out.file.handle; |
| 4160 |
h1a = &_h1a; |
| 4161 |
CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE); |
| 4162 |
CHECK_VAL(io.out.durable_open, false); |
| 4163 |
CHECK_VAL(io.out.durable_open_v2, true); |
| 4164 |
CHECK_VAL(io.out.persistent_open, false); |
| 4165 |
CHECK_VAL(io.out.timeout, 300*1000); |
| 4166 |
ls1a.lease_epoch += 1; |
| 4167 |
CHECK_LEASE_V2(&io, "RH", true, lease_key1a, |
| 4168 |
0, 0, ls1a.lease_epoch); |
| 4169 |
|
| 4170 |
lease_key1b = random(); |
| 4171 |
smb2_lease_v2_create(&io, &ls1b, false /* dir */, fname, |
| 4172 |
lease_key1b, 0, /* parent lease key */ |
| 4173 |
smb2_util_lease_state("RH"), 0 /* lease epoch */); |
| 4174 |
io.in.durable_open = false; |
| 4175 |
io.in.durable_open_v2 = true; |
| 4176 |
io.in.persistent_open = false; |
| 4177 |
io.in.create_guid = create_guid1b; |
| 4178 |
io.in.timeout = UINT32_MAX; |
| 4179 |
|
| 4180 |
status = smb2_create(tree1, mem_ctx, &io); |
| 4181 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 4182 |
_h1b = io.out.file.handle; |
| 4183 |
h1b = &_h1b; |
| 4184 |
CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE); |
| 4185 |
CHECK_VAL(io.out.durable_open, false); |
| 4186 |
CHECK_VAL(io.out.durable_open_v2, true); |
| 4187 |
CHECK_VAL(io.out.persistent_open, false); |
| 4188 |
CHECK_VAL(io.out.timeout, 300*1000); |
| 4189 |
ls1b.lease_epoch += 1; |
| 4190 |
CHECK_LEASE_V2(&io, "RH", true, lease_key1b, |
| 4191 |
0, 0, ls1b.lease_epoch); |
| 4192 |
|
| 4193 |
CHECK_NO_BREAK(tctx); |
| 4194 |
|
| 4195 |
/* disconnect, reconnect and then do durable reopen */ |
| 4196 |
TALLOC_FREE(tree1); |
| 4197 |
|
| 4198 |
CHECK_NO_BREAK(tctx); |
| 4199 |
|
| 4200 |
smb2_generic_create_share(&io, &ls1a, false /* dir */, fname, |
| 4201 |
NTCREATEX_DISP_OPEN_IF, |
| 4202 |
FILE_SHARE_NONE, |
| 4203 |
SMB2_OPLOCK_LEVEL_NONE, 0, 0); |
| 4204 |
status = smb2_create(tree2, mem_ctx, &io); |
| 4205 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 4206 |
_h2 = io.out.file.handle; |
| 4207 |
h2 = &_h2; |
| 4208 |
CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE); |
| 4209 |
CHECK_VAL(io.out.durable_open, false); |
| 4210 |
CHECK_VAL(io.out.durable_open_v2, false); |
| 4211 |
CHECK_VAL(io.out.persistent_open, false); |
| 4212 |
|
| 4213 |
CHECK_NO_BREAK(tctx); |
| 4214 |
|
| 4215 |
if (!torture_smb2_connection_ext(tctx, 0, &options1, &tree1)) { |
| 4216 |
torture_warning(tctx, "couldn't reconnect, bailing\n"); |
| 4217 |
ret = false; |
| 4218 |
goto done; |
| 4219 |
} |
| 4220 |
|
| 4221 |
ZERO_STRUCT(io); |
| 4222 |
io.in.fname = fname; |
| 4223 |
io.in.durable_open_v2 = false; |
| 4224 |
io.in.durable_handle_v2 = h1a; |
| 4225 |
io.in.create_guid = create_guid1a; |
| 4226 |
io.in.lease_request_v2 = &ls1a; |
| 4227 |
io.in.oplock_level = SMB2_OPLOCK_LEVEL_LEASE; |
| 4228 |
|
| 4229 |
status = smb2_create(tree1, mem_ctx, &io); |
| 4230 |
CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND); |
| 4231 |
h1a = NULL; |
| 4232 |
|
| 4233 |
ZERO_STRUCT(io); |
| 4234 |
io.in.fname = fname; |
| 4235 |
io.in.durable_open_v2 = false; |
| 4236 |
io.in.durable_handle_v2 = h1b; |
| 4237 |
io.in.create_guid = create_guid1b; |
| 4238 |
io.in.lease_request_v2 = &ls1b; |
| 4239 |
io.in.oplock_level = SMB2_OPLOCK_LEVEL_LEASE; |
| 4240 |
|
| 4241 |
status = smb2_create(tree1, mem_ctx, &io); |
| 4242 |
CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND); |
| 4243 |
h1b = NULL; |
| 4244 |
|
| 4245 |
status = smb2_util_close(tree2, *h2); |
| 4246 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 4247 |
h2 = NULL; |
| 4248 |
|
| 4249 |
CHECK_NO_BREAK(tctx); |
| 4250 |
|
| 4251 |
done: |
| 4252 |
if (tree1 != NULL) { |
| 4253 |
smb2_keepalive(tree1->session->transport); |
| 4254 |
} |
| 4255 |
if (tree2 != NULL) { |
| 4256 |
smb2_keepalive(tree2->session->transport); |
| 4257 |
} |
| 4258 |
if (tree1 != NULL && h1a != NULL) { |
| 4259 |
smb2_util_close(tree1, *h1a); |
| 4260 |
} |
| 4261 |
if (tree1 != NULL && h1b != NULL) { |
| 4262 |
smb2_util_close(tree1, *h1b); |
| 4263 |
} |
| 4264 |
if (tree2 != NULL && h2 != NULL) { |
| 4265 |
smb2_util_close(tree2, *h2); |
| 4266 |
} |
| 4267 |
|
| 4268 |
if (tree1 != NULL) { |
| 4269 |
smb2_util_unlink(tree1, fname); |
| 4270 |
smb2_deltree(tree1, __func__); |
| 4271 |
|
| 4272 |
TALLOC_FREE(tree1); |
| 4273 |
} |
| 4274 |
|
| 4275 |
TALLOC_FREE(tree2); |
| 4276 |
|
| 4277 |
talloc_free(mem_ctx); |
| 4278 |
|
| 4279 |
return ret; |
| 4280 |
} |
| 4281 |
|
| 4282 |
/** |
| 4283 |
* 1. durable open with L1A(RH) on tree1 => h1a |
| 4284 |
* 2. durable open with L1B(RH) on tree1 => h1b |
| 4285 |
* 3. durable open with L2(RH) on tree2 => h2 |
| 4286 |
* 4. disconnect tree2 |
| 4287 |
* 5.1 write to h1a |
| 4288 |
* 5.2 lease break to NONE for L1B (ack requested, but ignored) |
| 4289 |
* 6. reconnect tree2 |
| 4290 |
* 7. durable reconnect L2(RH) => h2 => not found |
| 4291 |
* 8. close h1a |
| 4292 |
* 9. durable open with L1A(RWH) on tree1 => h1a only RH |
| 4293 |
*/ |
| 4294 |
static bool test_durable_v2_open_purge_disconnected_rh_with_write(struct torture_context *tctx, |
| 4295 |
struct smb2_tree *tree1, |
| 4296 |
struct smb2_tree *tree2) |
| 4297 |
{ |
| 4298 |
TALLOC_CTX *mem_ctx = talloc_new(tctx); |
| 4299 |
NTSTATUS status; |
| 4300 |
char fname[256]; |
| 4301 |
struct smb2_handle dh; |
| 4302 |
struct smb2_handle _h1a; |
| 4303 |
struct smb2_handle *h1a = NULL; |
| 4304 |
struct smb2_handle _h1b; |
| 4305 |
struct smb2_handle *h1b = NULL; |
| 4306 |
struct smb2_handle _h2; |
| 4307 |
struct smb2_handle *h2 = NULL; |
| 4308 |
struct smb2_create io; |
| 4309 |
struct GUID create_guid1a = GUID_random(); |
| 4310 |
struct GUID create_guid1b = GUID_random(); |
| 4311 |
struct GUID create_guid2 = GUID_random(); |
| 4312 |
struct smb2_lease ls1a; |
| 4313 |
uint64_t lease_key1a; |
| 4314 |
struct smb2_lease ls1b; |
| 4315 |
uint64_t lease_key1b; |
| 4316 |
struct smb2_lease ls2; |
| 4317 |
uint64_t lease_key2; |
| 4318 |
struct smb2_write wrt; |
| 4319 |
bool ret = true; |
| 4320 |
struct smbcli_options options2; |
| 4321 |
uint32_t caps; |
| 4322 |
|
| 4323 |
caps = smb2cli_conn_server_capabilities(tree1->session->transport->conn); |
| 4324 |
if (!(caps & SMB2_CAP_LEASING)) { |
| 4325 |
torture_skip(tctx, "leases are not supported"); |
| 4326 |
} |
| 4327 |
|
| 4328 |
options2 = tree2->session->transport->options; |
| 4329 |
|
| 4330 |
tree1->session->transport->lease.handler = torture_lease_handler; |
| 4331 |
tree1->session->transport->lease.private_data = tree1; |
| 4332 |
|
| 4333 |
tree2->session->transport->lease.handler = torture_lease_handler; |
| 4334 |
tree2->session->transport->lease.private_data = tree2; |
| 4335 |
|
| 4336 |
torture_reset_lease_break_info(tctx, &lease_break_info); |
| 4337 |
|
| 4338 |
smb2_deltree(tree1, __func__); |
| 4339 |
status = torture_smb2_testdir(tree1, __func__, &dh); |
| 4340 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 4341 |
"torture_smb2_testdir failed\n"); |
| 4342 |
smb2_util_close(tree1, dh); |
| 4343 |
|
| 4344 |
/* Choose a random name in case the state is left a little funky. */ |
| 4345 |
snprintf(fname, 256, "%s\\file_%s.dat", |
| 4346 |
__func__, generate_random_str(tctx, 8)); |
| 4347 |
|
| 4348 |
smb2_util_unlink(tree1, fname); |
| 4349 |
|
| 4350 |
lease_key1a = random(); |
| 4351 |
smb2_lease_v2_create(&io, &ls1a, false /* dir */, fname, |
| 4352 |
lease_key1a, 0, /* parent lease key */ |
| 4353 |
smb2_util_lease_state("RH"), 0 /* lease epoch */); |
| 4354 |
io.in.durable_open = false; |
| 4355 |
io.in.durable_open_v2 = true; |
| 4356 |
io.in.persistent_open = false; |
| 4357 |
io.in.create_guid = create_guid1a; |
| 4358 |
io.in.timeout = UINT32_MAX; |
| 4359 |
|
| 4360 |
status = smb2_create(tree1, mem_ctx, &io); |
| 4361 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 4362 |
_h1a = io.out.file.handle; |
| 4363 |
h1a = &_h1a; |
| 4364 |
CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE); |
| 4365 |
CHECK_VAL(io.out.durable_open, false); |
| 4366 |
CHECK_VAL(io.out.durable_open_v2, true); |
| 4367 |
CHECK_VAL(io.out.persistent_open, false); |
| 4368 |
CHECK_VAL(io.out.timeout, 300*1000); |
| 4369 |
ls1a.lease_epoch += 1; |
| 4370 |
CHECK_LEASE_V2(&io, "RH", true, lease_key1a, |
| 4371 |
0, 0, ls1a.lease_epoch); |
| 4372 |
|
| 4373 |
lease_key1b = random(); |
| 4374 |
smb2_lease_v2_create(&io, &ls1b, false /* dir */, fname, |
| 4375 |
lease_key1b, 0, /* parent lease key */ |
| 4376 |
smb2_util_lease_state("RH"), 0 /* lease epoch */); |
| 4377 |
io.in.durable_open = false; |
| 4378 |
io.in.durable_open_v2 = true; |
| 4379 |
io.in.persistent_open = false; |
| 4380 |
io.in.create_guid = create_guid1b; |
| 4381 |
io.in.timeout = UINT32_MAX; |
| 4382 |
|
| 4383 |
status = smb2_create(tree1, mem_ctx, &io); |
| 4384 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 4385 |
_h1b = io.out.file.handle; |
| 4386 |
h1b = &_h1b; |
| 4387 |
CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE); |
| 4388 |
CHECK_VAL(io.out.durable_open, false); |
| 4389 |
CHECK_VAL(io.out.durable_open_v2, true); |
| 4390 |
CHECK_VAL(io.out.persistent_open, false); |
| 4391 |
CHECK_VAL(io.out.timeout, 300*1000); |
| 4392 |
ls1b.lease_epoch += 1; |
| 4393 |
CHECK_LEASE_V2(&io, "RH", true, lease_key1b, |
| 4394 |
0, 0, ls1b.lease_epoch); |
| 4395 |
|
| 4396 |
lease_key2 = random(); |
| 4397 |
smb2_lease_v2_create(&io, &ls2, false /* dir */, fname, |
| 4398 |
lease_key2, 0, /* parent lease key */ |
| 4399 |
smb2_util_lease_state("RH"), 0 /* lease epoch */); |
| 4400 |
io.in.durable_open = false; |
| 4401 |
io.in.durable_open_v2 = true; |
| 4402 |
io.in.persistent_open = false; |
| 4403 |
io.in.create_guid = create_guid2; |
| 4404 |
io.in.timeout = UINT32_MAX; |
| 4405 |
|
| 4406 |
status = smb2_create(tree2, mem_ctx, &io); |
| 4407 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 4408 |
_h2 = io.out.file.handle; |
| 4409 |
h2 = &_h2; |
| 4410 |
CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE); |
| 4411 |
CHECK_VAL(io.out.durable_open, false); |
| 4412 |
CHECK_VAL(io.out.durable_open_v2, true); |
| 4413 |
CHECK_VAL(io.out.persistent_open, false); |
| 4414 |
CHECK_VAL(io.out.timeout, 300*1000); |
| 4415 |
ls2.lease_epoch += 1; |
| 4416 |
CHECK_LEASE_V2(&io, "RH", true, lease_key2, |
| 4417 |
0, 0, ls2.lease_epoch); |
| 4418 |
|
| 4419 |
CHECK_NO_BREAK(tctx); |
| 4420 |
|
| 4421 |
/* disconnect, reconnect and then do durable reopen */ |
| 4422 |
TALLOC_FREE(tree2); |
| 4423 |
|
| 4424 |
CHECK_NO_BREAK(tctx); |
| 4425 |
lease_break_info.lease_skip_ack = true; |
| 4426 |
|
| 4427 |
ZERO_STRUCT(wrt); |
| 4428 |
wrt.in.file.handle = *h1a; |
| 4429 |
wrt.in.offset = 0; |
| 4430 |
wrt.in.data = data_blob_string_const("data"); |
| 4431 |
status = smb2_write(tree1, &wrt); |
| 4432 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 4433 |
|
| 4434 |
ls1b.lease_epoch += 1; |
| 4435 |
CHECK_BREAK_INFO_V2(tree1->session->transport, |
| 4436 |
"RH", "", lease_key1b, ls1b.lease_epoch); |
| 4437 |
torture_reset_lease_break_info(tctx, &lease_break_info); |
| 4438 |
CHECK_NO_BREAK(tctx); |
| 4439 |
|
| 4440 |
if (!torture_smb2_connection_ext(tctx, 0, &options2, &tree2)) { |
| 4441 |
torture_warning(tctx, "couldn't reconnect, bailing\n"); |
| 4442 |
ret = false; |
| 4443 |
goto done; |
| 4444 |
} |
| 4445 |
|
| 4446 |
tree2->session->transport->lease.handler = torture_lease_handler; |
| 4447 |
tree2->session->transport->lease.private_data = tree2; |
| 4448 |
|
| 4449 |
ZERO_STRUCT(io); |
| 4450 |
io.in.fname = fname; |
| 4451 |
io.in.durable_open_v2 = false; |
| 4452 |
io.in.durable_handle_v2 = h2; |
| 4453 |
io.in.create_guid = create_guid2; |
| 4454 |
io.in.lease_request_v2 = &ls2; |
| 4455 |
io.in.oplock_level = SMB2_OPLOCK_LEVEL_LEASE; |
| 4456 |
|
| 4457 |
status = smb2_create(tree2, mem_ctx, &io); |
| 4458 |
CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND); |
| 4459 |
h2 = NULL; |
| 4460 |
|
| 4461 |
status = smb2_util_close(tree1, *h1a); |
| 4462 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 4463 |
h1a = NULL; |
| 4464 |
|
| 4465 |
/* |
| 4466 |
* Now there's only lease_key2 with state NONE |
| 4467 |
* |
| 4468 |
* And that means an additional open still |
| 4469 |
* only gets RH... |
| 4470 |
*/ |
| 4471 |
smb2_lease_v2_create(&io, &ls1a, false /* dir */, fname, |
| 4472 |
lease_key1a, 0, /* parent lease key */ |
| 4473 |
smb2_util_lease_state("RHW"), 0 /* lease epoch */); |
| 4474 |
io.in.durable_open = false; |
| 4475 |
io.in.durable_open_v2 = true; |
| 4476 |
io.in.persistent_open = false; |
| 4477 |
io.in.create_guid = create_guid1a; |
| 4478 |
io.in.timeout = UINT32_MAX; |
| 4479 |
|
| 4480 |
status = smb2_create(tree1, mem_ctx, &io); |
| 4481 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 4482 |
_h1a = io.out.file.handle; |
| 4483 |
h1a = &_h1a; |
| 4484 |
CHECK_VAL(io.out.create_action, NTCREATEX_ACTION_EXISTED); |
| 4485 |
CHECK_VAL(io.out.size, wrt.in.data.length); |
| 4486 |
CHECK_VAL(io.out.file_attr, FILE_ATTRIBUTE_ARCHIVE); |
| 4487 |
CHECK_VAL(io.out.durable_open, false); |
| 4488 |
CHECK_VAL(io.out.durable_open_v2, true); |
| 4489 |
CHECK_VAL(io.out.persistent_open, false); |
| 4490 |
CHECK_VAL(io.out.timeout, 300*1000); |
| 4491 |
ls1a.lease_epoch += 1; |
| 4492 |
CHECK_LEASE_V2(&io, "RH", true, lease_key1a, |
| 4493 |
0, 0, ls1a.lease_epoch); |
| 4494 |
|
| 4495 |
status = smb2_util_close(tree1, *h1a); |
| 4496 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 4497 |
h1a = NULL; |
| 4498 |
|
| 4499 |
status = smb2_util_close(tree1, *h1b); |
| 4500 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 4501 |
h1b = NULL; |
| 4502 |
|
| 4503 |
CHECK_NO_BREAK(tctx); |
| 4504 |
|
| 4505 |
done: |
| 4506 |
if (tree1 != NULL) { |
| 4507 |
smb2_keepalive(tree1->session->transport); |
| 4508 |
} |
| 4509 |
if (tree2 != NULL) { |
| 4510 |
smb2_keepalive(tree2->session->transport); |
| 4511 |
} |
| 4512 |
if (tree1 != NULL && h1a != NULL) { |
| 4513 |
smb2_util_close(tree1, *h1a); |
| 4514 |
} |
| 4515 |
if (tree1 != NULL && h1b != NULL) { |
| 4516 |
smb2_util_close(tree1, *h1b); |
| 4517 |
} |
| 4518 |
if (tree2 != NULL && h2 != NULL) { |
| 4519 |
smb2_util_close(tree2, *h2); |
| 4520 |
} |
| 4521 |
|
| 4522 |
if (tree1 != NULL) { |
| 4523 |
smb2_util_unlink(tree1, fname); |
| 4524 |
smb2_deltree(tree1, __func__); |
| 4525 |
|
| 4526 |
TALLOC_FREE(tree1); |
| 4527 |
} |
| 4528 |
|
| 4529 |
TALLOC_FREE(tree2); |
| 4530 |
|
| 4531 |
talloc_free(mem_ctx); |
| 4532 |
|
| 4533 |
return ret; |
| 4534 |
} |
| 4535 |
|
| 4536 |
/** |
| 4537 |
* 1. durable open with L1A(RH) on tree1 => h1a |
| 4538 |
* 2. durable open with L1B(RH) on tree1 => h1b |
| 4539 |
* 3. durable open with L2(RH) on tree2 => h2 |
| 4540 |
* 4. disconnect tree2 |
| 4541 |
* 5.1 rename h1a |
| 4542 |
* 5.2 lease break to R for L1B (ack requested, and required) |
| 4543 |
* 6. reconnect tree2 |
| 4544 |
* 7. durable reconnect L2(RH) => h2 => not found |
| 4545 |
*/ |
| 4546 |
static bool test_durable_v2_open_purge_disconnected_rh_with_rename(struct torture_context *tctx, |
| 4547 |
struct smb2_tree *tree1, |
| 4548 |
struct smb2_tree *tree2) |
| 4549 |
{ |
| 4550 |
TALLOC_CTX *mem_ctx = talloc_new(tctx); |
| 4551 |
NTSTATUS status; |
| 4552 |
char fname[128]; |
| 4553 |
char fname_renamed[140]; |
| 4554 |
struct smb2_handle dh; |
| 4555 |
struct smb2_handle _h1a; |
| 4556 |
struct smb2_handle *h1a = NULL; |
| 4557 |
struct smb2_handle _h1b; |
| 4558 |
struct smb2_handle *h1b = NULL; |
| 4559 |
struct smb2_handle _h2; |
| 4560 |
struct smb2_handle *h2 = NULL; |
| 4561 |
struct smb2_create io; |
| 4562 |
struct GUID create_guid1a = GUID_random(); |
| 4563 |
struct GUID create_guid1b = GUID_random(); |
| 4564 |
struct GUID create_guid2 = GUID_random(); |
| 4565 |
struct smb2_lease ls1a; |
| 4566 |
uint64_t lease_key1a; |
| 4567 |
struct smb2_lease ls1b; |
| 4568 |
uint64_t lease_key1b; |
| 4569 |
struct smb2_lease ls2; |
| 4570 |
uint64_t lease_key2; |
| 4571 |
union smb_setfileinfo sinfo; |
| 4572 |
bool ret = true; |
| 4573 |
struct smbcli_options options2; |
| 4574 |
uint32_t caps; |
| 4575 |
|
| 4576 |
caps = smb2cli_conn_server_capabilities(tree1->session->transport->conn); |
| 4577 |
if (!(caps & SMB2_CAP_LEASING)) { |
| 4578 |
torture_skip(tctx, "leases are not supported"); |
| 4579 |
} |
| 4580 |
|
| 4581 |
options2 = tree2->session->transport->options; |
| 4582 |
|
| 4583 |
tree1->session->transport->lease.handler = torture_lease_handler; |
| 4584 |
tree1->session->transport->lease.private_data = tree1; |
| 4585 |
|
| 4586 |
tree2->session->transport->lease.handler = torture_lease_handler; |
| 4587 |
tree2->session->transport->lease.private_data = tree2; |
| 4588 |
|
| 4589 |
torture_reset_lease_break_info(tctx, &lease_break_info); |
| 4590 |
|
| 4591 |
smb2_deltree(tree1, __func__); |
| 4592 |
status = torture_smb2_testdir(tree1, __func__, &dh); |
| 4593 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 4594 |
"torture_smb2_testdir failed\n"); |
| 4595 |
smb2_util_close(tree1, dh); |
| 4596 |
|
| 4597 |
/* Choose a random name in case the state is left a little funky. */ |
| 4598 |
snprintf(fname, 128, "%s\\file_%s.dat", |
| 4599 |
__func__, generate_random_str(tctx, 8)); |
| 4600 |
snprintf(fname_renamed, 140, "%s.renamed", fname); |
| 4601 |
|
| 4602 |
smb2_util_unlink(tree1, fname); |
| 4603 |
smb2_util_unlink(tree1, fname_renamed); |
| 4604 |
|
| 4605 |
lease_key1a = random(); |
| 4606 |
smb2_lease_v2_create(&io, &ls1a, false /* dir */, fname, |
| 4607 |
lease_key1a, 0, /* parent lease key */ |
| 4608 |
smb2_util_lease_state("RH"), 0 /* lease epoch */); |
| 4609 |
io.in.durable_open = false; |
| 4610 |
io.in.durable_open_v2 = true; |
| 4611 |
io.in.persistent_open = false; |
| 4612 |
io.in.create_guid = create_guid1a; |
| 4613 |
io.in.timeout = UINT32_MAX; |
| 4614 |
|
| 4615 |
status = smb2_create(tree1, mem_ctx, &io); |
| 4616 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 4617 |
_h1a = io.out.file.handle; |
| 4618 |
h1a = &_h1a; |
| 4619 |
CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE); |
| 4620 |
CHECK_VAL(io.out.durable_open, false); |
| 4621 |
CHECK_VAL(io.out.durable_open_v2, true); |
| 4622 |
CHECK_VAL(io.out.persistent_open, false); |
| 4623 |
CHECK_VAL(io.out.timeout, 300*1000); |
| 4624 |
ls1a.lease_epoch += 1; |
| 4625 |
CHECK_LEASE_V2(&io, "RH", true, lease_key1a, |
| 4626 |
0, 0, ls1a.lease_epoch); |
| 4627 |
|
| 4628 |
lease_key1b = random(); |
| 4629 |
smb2_lease_v2_create(&io, &ls1b, false /* dir */, fname, |
| 4630 |
lease_key1b, 0, /* parent lease key */ |
| 4631 |
smb2_util_lease_state("RH"), 0 /* lease epoch */); |
| 4632 |
io.in.durable_open = false; |
| 4633 |
io.in.durable_open_v2 = true; |
| 4634 |
io.in.persistent_open = false; |
| 4635 |
io.in.create_guid = create_guid1b; |
| 4636 |
io.in.timeout = UINT32_MAX; |
| 4637 |
|
| 4638 |
status = smb2_create(tree1, mem_ctx, &io); |
| 4639 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 4640 |
_h1b = io.out.file.handle; |
| 4641 |
h1b = &_h1b; |
| 4642 |
CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE); |
| 4643 |
CHECK_VAL(io.out.durable_open, false); |
| 4644 |
CHECK_VAL(io.out.durable_open_v2, true); |
| 4645 |
CHECK_VAL(io.out.persistent_open, false); |
| 4646 |
CHECK_VAL(io.out.timeout, 300*1000); |
| 4647 |
ls1b.lease_epoch += 1; |
| 4648 |
CHECK_LEASE_V2(&io, "RH", true, lease_key1b, |
| 4649 |
0, 0, ls1b.lease_epoch); |
| 4650 |
|
| 4651 |
lease_key2 = random(); |
| 4652 |
smb2_lease_v2_create(&io, &ls2, false /* dir */, fname, |
| 4653 |
lease_key2, 0, /* parent lease key */ |
| 4654 |
smb2_util_lease_state("RH"), 0 /* lease epoch */); |
| 4655 |
io.in.durable_open = false; |
| 4656 |
io.in.durable_open_v2 = true; |
| 4657 |
io.in.persistent_open = false; |
| 4658 |
io.in.create_guid = create_guid2; |
| 4659 |
io.in.timeout = UINT32_MAX; |
| 4660 |
|
| 4661 |
status = smb2_create(tree2, mem_ctx, &io); |
| 4662 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 4663 |
_h2 = io.out.file.handle; |
| 4664 |
h2 = &_h2; |
| 4665 |
CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE); |
| 4666 |
CHECK_VAL(io.out.durable_open, false); |
| 4667 |
CHECK_VAL(io.out.durable_open_v2, true); |
| 4668 |
CHECK_VAL(io.out.persistent_open, false); |
| 4669 |
CHECK_VAL(io.out.timeout, 300*1000); |
| 4670 |
ls2.lease_epoch += 1; |
| 4671 |
CHECK_LEASE_V2(&io, "RH", true, lease_key2, |
| 4672 |
0, 0, ls2.lease_epoch); |
| 4673 |
|
| 4674 |
CHECK_NO_BREAK(tctx); |
| 4675 |
|
| 4676 |
/* disconnect, reconnect and then do durable reopen */ |
| 4677 |
TALLOC_FREE(tree2); |
| 4678 |
|
| 4679 |
CHECK_NO_BREAK(tctx); |
| 4680 |
|
| 4681 |
ZERO_STRUCT(sinfo); |
| 4682 |
sinfo.rename_information.level = RAW_SFILEINFO_RENAME_INFORMATION; |
| 4683 |
sinfo.rename_information.in.file.handle = *h1a; |
| 4684 |
sinfo.rename_information.in.overwrite = 0; |
| 4685 |
sinfo.rename_information.in.root_fid = 0; |
| 4686 |
sinfo.rename_information.in.new_name = fname_renamed; |
| 4687 |
status = smb2_setinfo_file(tree1, &sinfo); |
| 4688 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 4689 |
|
| 4690 |
ls1b.lease_epoch += 1; |
| 4691 |
CHECK_BREAK_INFO_V2(tree1->session->transport, |
| 4692 |
"RH", "R", lease_key1b, ls1b.lease_epoch); |
| 4693 |
torture_reset_lease_break_info(tctx, &lease_break_info); |
| 4694 |
CHECK_NO_BREAK(tctx); |
| 4695 |
|
| 4696 |
if (!torture_smb2_connection_ext(tctx, 0, &options2, &tree2)) { |
| 4697 |
torture_warning(tctx, "couldn't reconnect, bailing\n"); |
| 4698 |
ret = false; |
| 4699 |
goto done; |
| 4700 |
} |
| 4701 |
|
| 4702 |
tree2->session->transport->lease.handler = torture_lease_handler; |
| 4703 |
tree2->session->transport->lease.private_data = tree2; |
| 4704 |
|
| 4705 |
ZERO_STRUCT(io); |
| 4706 |
io.in.fname = fname; |
| 4707 |
io.in.durable_open_v2 = false; |
| 4708 |
io.in.durable_handle_v2 = h2; |
| 4709 |
io.in.create_guid = create_guid2; |
| 4710 |
io.in.lease_request_v2 = &ls2; |
| 4711 |
io.in.oplock_level = SMB2_OPLOCK_LEVEL_LEASE; |
| 4712 |
|
| 4713 |
status = smb2_create(tree2, mem_ctx, &io); |
| 4714 |
CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND); |
| 4715 |
h2 = NULL; |
| 4716 |
|
| 4717 |
status = smb2_util_close(tree1, *h1a); |
| 4718 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 4719 |
h1a = NULL; |
| 4720 |
|
| 4721 |
status = smb2_util_close(tree1, *h1b); |
| 4722 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 4723 |
h1b = NULL; |
| 4724 |
|
| 4725 |
CHECK_NO_BREAK(tctx); |
| 4726 |
|
| 4727 |
done: |
| 4728 |
if (tree1 != NULL) { |
| 4729 |
smb2_keepalive(tree1->session->transport); |
| 4730 |
} |
| 4731 |
if (tree2 != NULL) { |
| 4732 |
smb2_keepalive(tree2->session->transport); |
| 4733 |
} |
| 4734 |
if (tree1 != NULL && h1a != NULL) { |
| 4735 |
smb2_util_close(tree1, *h1a); |
| 4736 |
} |
| 4737 |
if (tree1 != NULL && h1b != NULL) { |
| 4738 |
smb2_util_close(tree1, *h1b); |
| 4739 |
} |
| 4740 |
if (tree2 != NULL && h2 != NULL) { |
| 4741 |
smb2_util_close(tree2, *h2); |
| 4742 |
} |
| 4743 |
|
| 4744 |
if (tree1 != NULL) { |
| 4745 |
smb2_util_unlink(tree1, fname); |
| 4746 |
smb2_util_unlink(tree1, fname_renamed); |
| 4747 |
smb2_deltree(tree1, __func__); |
| 4748 |
|
| 4749 |
TALLOC_FREE(tree1); |
| 4750 |
} |
| 4751 |
|
| 4752 |
TALLOC_FREE(tree2); |
| 4753 |
|
| 4754 |
talloc_free(mem_ctx); |
| 4755 |
|
| 4756 |
return ret; |
| 4757 |
} |
| 4758 |
|
| 4759 |
/** |
| 4760 |
* Test durable request / reconnect with AppInstanceId |
| 4761 |
*/ |
| 4762 |
bool test_durable_v2_open_app_instance(struct torture_context *tctx, |
| 4763 |
struct smb2_tree *tree1, |
| 4764 |
struct smb2_tree *tree2) |
| 4765 |
{ |
| 4766 |
NTSTATUS status; |
| 4767 |
TALLOC_CTX *mem_ctx = talloc_new(tctx); |
| 4768 |
char fname[256]; |
| 4769 |
struct smb2_handle _h1, _h2; |
| 4770 |
struct smb2_handle *h1 = NULL, *h2 = NULL; |
| 4771 |
struct smb2_create io1, io2; |
| 4772 |
bool ret = true; |
| 4773 |
struct GUID create_guid_1 = GUID_random(); |
| 4774 |
struct GUID create_guid_2 = GUID_random(); |
| 4775 |
struct GUID app_instance_id = GUID_random(); |
| 4776 |
|
| 4777 |
/* Choose a random name in case the state is left a little funky. */ |
| 4778 |
snprintf(fname, 256, "durable_v2_open_app_instance_%s.dat", |
| 4779 |
generate_random_str(tctx, 8)); |
| 4780 |
|
| 4781 |
smb2_util_unlink(tree1, fname); |
| 4782 |
|
| 4783 |
ZERO_STRUCT(break_info); |
| 4784 |
tree1->session->transport->oplock.handler = torture_oplock_handler; |
| 4785 |
tree1->session->transport->oplock.private_data = tree1; |
| 4786 |
|
| 4787 |
smb2_oplock_create_share(&io1, fname, |
| 4788 |
smb2_util_share_access(""), |
| 4789 |
smb2_util_oplock_level("b")); |
| 4790 |
io1.in.durable_open = false; |
| 4791 |
io1.in.durable_open_v2 = true; |
| 4792 |
io1.in.persistent_open = false; |
| 4793 |
io1.in.create_guid = create_guid_1; |
| 4794 |
io1.in.app_instance_id = &app_instance_id; |
| 4795 |
io1.in.timeout = UINT32_MAX; |
| 4796 |
|
| 4797 |
status = smb2_create(tree1, mem_ctx, &io1); |
| 4798 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 4799 |
_h1 = io1.out.file.handle; |
| 4800 |
h1 = &_h1; |
| 4801 |
CHECK_CREATED(&io1, CREATED, FILE_ATTRIBUTE_ARCHIVE); |
| 4802 |
CHECK_VAL(io1.out.oplock_level, smb2_util_oplock_level("b")); |
| 4803 |
CHECK_VAL(io1.out.durable_open, false); |
| 4804 |
CHECK_VAL(io1.out.durable_open_v2, true); |
| 4805 |
CHECK_VAL(io1.out.persistent_open, false); |
| 4806 |
CHECK_VAL(io1.out.timeout, 300*1000); |
| 4807 |
|
| 4808 |
/* |
| 4809 |
* try to open the file as durable from a second tree with |
| 4810 |
* a different create guid but the same app_instance_id |
| 4811 |
* while the first handle is still open. |
| 4812 |
*/ |
| 4813 |
|
| 4814 |
smb2_oplock_create_share(&io2, fname, |
| 4815 |
smb2_util_share_access(""), |
| 4816 |
smb2_util_oplock_level("b")); |
| 4817 |
io2.in.durable_open = false; |
| 4818 |
io2.in.durable_open_v2 = true; |
| 4819 |
io2.in.persistent_open = false; |
| 4820 |
io2.in.create_guid = create_guid_2; |
| 4821 |
io2.in.app_instance_id = &app_instance_id; |
| 4822 |
io2.in.timeout = UINT32_MAX; |
| 4823 |
|
| 4824 |
status = smb2_create(tree2, mem_ctx, &io2); |
| 4825 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 4826 |
_h2 = io2.out.file.handle; |
| 4827 |
h2 = &_h2; |
| 4828 |
CHECK_CREATED(&io2, EXISTED, FILE_ATTRIBUTE_ARCHIVE); |
| 4829 |
CHECK_VAL(io2.out.oplock_level, smb2_util_oplock_level("b")); |
| 4830 |
CHECK_VAL(io2.out.durable_open, false); |
| 4831 |
CHECK_VAL(io2.out.durable_open_v2, true); |
| 4832 |
CHECK_VAL(io2.out.persistent_open, false); |
| 4833 |
CHECK_VAL(io2.out.timeout, 300*1000); |
| 4834 |
|
| 4835 |
CHECK_VAL(break_info.count, 0); |
| 4836 |
|
| 4837 |
status = smb2_util_close(tree1, *h1); |
| 4838 |
CHECK_STATUS(status, NT_STATUS_FILE_CLOSED); |
| 4839 |
h1 = NULL; |
| 4840 |
|
| 4841 |
done: |
| 4842 |
if (h1 != NULL) { |
| 4843 |
smb2_util_close(tree1, *h1); |
| 4844 |
} |
| 4845 |
if (h2 != NULL) { |
| 4846 |
smb2_util_close(tree2, *h2); |
| 4847 |
} |
| 4848 |
|
| 4849 |
smb2_util_unlink(tree2, fname); |
| 4850 |
|
| 4851 |
talloc_free(tree1); |
| 4852 |
talloc_free(tree2); |
| 4853 |
|
| 4854 |
talloc_free(mem_ctx); |
| 4855 |
|
| 4856 |
return ret; |
| 4857 |
} |
| 4858 |
|
| 4859 |
|
| 4860 |
/** |
| 4861 |
* basic persistent open test. |
| 4862 |
* |
| 4863 |
* This test tests durable open with all possible oplock types. |
| 4864 |
*/ |
| 4865 |
|
| 4866 |
struct durable_open_vs_oplock persistent_open_oplock_ca_table[NUM_OPLOCK_OPEN_TESTS] = |
| 4867 |
{ |
| 4868 |
{ "", "", true, true }, |
| 4869 |
{ "", "R", true, true }, |
| 4870 |
{ "", "W", true, true }, |
| 4871 |
{ "", "D", true, true }, |
| 4872 |
{ "", "RD", true, true }, |
| 4873 |
{ "", "RW", true, true }, |
| 4874 |
{ "", "WD", true, true }, |
| 4875 |
{ "", "RWD", true, true }, |
| 4876 |
|
| 4877 |
{ "s", "", true, true }, |
| 4878 |
{ "s", "R", true, true }, |
| 4879 |
{ "s", "W", true, true }, |
| 4880 |
{ "s", "D", true, true }, |
| 4881 |
{ "s", "RD", true, true }, |
| 4882 |
{ "s", "RW", true, true }, |
| 4883 |
{ "s", "WD", true, true }, |
| 4884 |
{ "s", "RWD", true, true }, |
| 4885 |
|
| 4886 |
{ "x", "", true, true }, |
| 4887 |
{ "x", "R", true, true }, |
| 4888 |
{ "x", "W", true, true }, |
| 4889 |
{ "x", "D", true, true }, |
| 4890 |
{ "x", "RD", true, true }, |
| 4891 |
{ "x", "RW", true, true }, |
| 4892 |
{ "x", "WD", true, true }, |
| 4893 |
{ "x", "RWD", true, true }, |
| 4894 |
|
| 4895 |
{ "b", "", true, true }, |
| 4896 |
{ "b", "R", true, true }, |
| 4897 |
{ "b", "W", true, true }, |
| 4898 |
{ "b", "D", true, true }, |
| 4899 |
{ "b", "RD", true, true }, |
| 4900 |
{ "b", "RW", true, true }, |
| 4901 |
{ "b", "WD", true, true }, |
| 4902 |
{ "b", "RWD", true, true }, |
| 4903 |
}; |
| 4904 |
|
| 4905 |
bool test_persistent_open_oplock(struct torture_context *tctx, |
| 4906 |
struct smb2_tree *tree) |
| 4907 |
{ |
| 4908 |
char fname[256]; |
| 4909 |
bool ret = true; |
| 4910 |
uint32_t share_capabilities; |
| 4911 |
bool share_is_ca = false; |
| 4912 |
struct durable_open_vs_oplock *table; |
| 4913 |
|
| 4914 |
/* Choose a random name in case the state is left a little funky. */ |
| 4915 |
snprintf(fname, 256, "persistent_open_oplock_%s.dat", generate_random_str(tctx, 8)); |
| 4916 |
|
| 4917 |
share_capabilities = smb2cli_tcon_capabilities(tree->smbXcli); |
| 4918 |
share_is_ca = share_capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY; |
| 4919 |
|
| 4920 |
if (share_is_ca) { |
| 4921 |
table = persistent_open_oplock_ca_table; |
| 4922 |
} else { |
| 4923 |
table = durable_open_vs_oplock_table; |
| 4924 |
} |
| 4925 |
|
| 4926 |
ret = test_durable_v2_open_oplock_table(tctx, tree, fname, |
| 4927 |
true, /* request_persistent */ |
| 4928 |
table, |
| 4929 |
NUM_OPLOCK_OPEN_TESTS); |
| 4930 |
|
| 4931 |
talloc_free(tree); |
| 4932 |
|
| 4933 |
return ret; |
| 4934 |
} |
| 4935 |
|
| 4936 |
/** |
| 4937 |
* basic persistent handle open test. |
| 4938 |
* persistent state should only be granted when requested |
| 4939 |
* along with a batch oplock or a handle lease. |
| 4940 |
* |
| 4941 |
* This test tests persistent open with all valid lease types. |
| 4942 |
*/ |
| 4943 |
|
| 4944 |
struct durable_open_vs_lease persistent_open_lease_ca_table[NUM_LEASE_OPEN_TESTS] = |
| 4945 |
{ |
| 4946 |
{ "", "", true, true }, |
| 4947 |
{ "", "R", true, true }, |
| 4948 |
{ "", "W", true, true }, |
| 4949 |
{ "", "D", true, true }, |
| 4950 |
{ "", "RW", true, true }, |
| 4951 |
{ "", "RD", true, true }, |
| 4952 |
{ "", "WD", true, true }, |
| 4953 |
{ "", "RWD", true, true }, |
| 4954 |
|
| 4955 |
{ "R", "", true, true }, |
| 4956 |
{ "R", "R", true, true }, |
| 4957 |
{ "R", "W", true, true }, |
| 4958 |
{ "R", "D", true, true }, |
| 4959 |
{ "R", "RW", true, true }, |
| 4960 |
{ "R", "RD", true, true }, |
| 4961 |
{ "R", "DW", true, true }, |
| 4962 |
{ "R", "RWD", true, true }, |
| 4963 |
|
| 4964 |
{ "RW", "", true, true }, |
| 4965 |
{ "RW", "R", true, true }, |
| 4966 |
{ "RW", "W", true, true }, |
| 4967 |
{ "RW", "D", true, true }, |
| 4968 |
{ "RW", "RW", true, true }, |
| 4969 |
{ "RW", "RD", true, true }, |
| 4970 |
{ "RW", "WD", true, true }, |
| 4971 |
{ "RW", "RWD", true, true }, |
| 4972 |
|
| 4973 |
{ "RH", "", true, true }, |
| 4974 |
{ "RH", "R", true, true }, |
| 4975 |
{ "RH", "W", true, true }, |
| 4976 |
{ "RH", "D", true, true }, |
| 4977 |
{ "RH", "RW", true, true }, |
| 4978 |
{ "RH", "RD", true, true }, |
| 4979 |
{ "RH", "WD", true, true }, |
| 4980 |
{ "RH", "RWD", true, true }, |
| 4981 |
|
| 4982 |
{ "RHW", "", true, true }, |
| 4983 |
{ "RHW", "R", true, true }, |
| 4984 |
{ "RHW", "W", true, true }, |
| 4985 |
{ "RHW", "D", true, true }, |
| 4986 |
{ "RHW", "RW", true, true }, |
| 4987 |
{ "RHW", "RD", true, true }, |
| 4988 |
{ "RHW", "WD", true, true }, |
| 4989 |
{ "RHW", "RWD", true, true }, |
| 4990 |
}; |
| 4991 |
|
| 4992 |
bool test_persistent_open_lease(struct torture_context *tctx, |
| 4993 |
struct smb2_tree *tree) |
| 4994 |
{ |
| 4995 |
char fname[256]; |
| 4996 |
bool ret = true; |
| 4997 |
uint32_t caps; |
| 4998 |
uint32_t share_capabilities; |
| 4999 |
bool share_is_ca; |
| 5000 |
bool share_is_so; |
| 5001 |
struct durable_open_vs_lease *table; |
| 5002 |
|
| 5003 |
caps = smb2cli_conn_server_capabilities(tree->session->transport->conn); |
| 5004 |
if (!(caps & SMB2_CAP_LEASING)) { |
| 5005 |
torture_skip(tctx, "leases are not supported"); |
| 5006 |
} |
| 5007 |
|
| 5008 |
/* Choose a random name in case the state is left a little funky. */ |
| 5009 |
snprintf(fname, 256, "persistent_open_lease_%s.dat", generate_random_str(tctx, 8)); |
| 5010 |
|
| 5011 |
share_capabilities = smb2cli_tcon_capabilities(tree->smbXcli); |
| 5012 |
share_is_ca = share_capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY; |
| 5013 |
share_is_so = share_capabilities & SMB2_SHARE_CAP_SCALEOUT; |
| 5014 |
|
| 5015 |
if (share_is_ca) { |
| 5016 |
table = persistent_open_lease_ca_table; |
| 5017 |
} else { |
| 5018 |
table = durable_open_vs_lease_table; |
| 5019 |
} |
| 5020 |
|
| 5021 |
ret = test_durable_v2_open_lease_table(tctx, tree, fname, |
| 5022 |
true, /* request_persistent */ |
| 5023 |
share_is_so, |
| 5024 |
table, |
| 5025 |
NUM_LEASE_OPEN_TESTS); |
| 5026 |
|
| 5027 |
talloc_free(tree); |
| 5028 |
|
| 5029 |
return ret; |
| 5030 |
} |
| 5031 |
|
| 5032 |
/** |
| 5033 |
* setfileinfo test for doing a durable open |
| 5034 |
* create the file with lease and durable handle, |
| 5035 |
* write to it (via set end-of-file), tcp disconnect, |
| 5036 |
* reconnect, do a durable reopen - should succeed. |
| 5037 |
* |
| 5038 |
* BUG: https://bugzilla.samba.org/show_bug.cgi?id=15022 |
| 5039 |
*/ |
| 5040 |
bool test_durable_v2_setinfo(struct torture_context *tctx, |
| 5041 |
struct smb2_tree *tree) |
| 5042 |
{ |
| 5043 |
NTSTATUS status; |
| 5044 |
TALLOC_CTX *mem_ctx = talloc_new(tctx); |
| 5045 |
char fname[256]; |
| 5046 |
struct smb2_handle _h; |
| 5047 |
struct smb2_handle *h = NULL; |
| 5048 |
struct smb2_create io; |
| 5049 |
union smb_setfileinfo si; |
| 5050 |
struct GUID create_guid = GUID_random(); |
| 5051 |
struct smb2_lease ls; |
| 5052 |
uint64_t lease_key; |
| 5053 |
bool ret = true; |
| 5054 |
struct smbcli_options options; |
| 5055 |
uint32_t caps; |
| 5056 |
|
| 5057 |
caps = smb2cli_conn_server_capabilities(tree->session->transport->conn); |
| 5058 |
if (!(caps & SMB2_CAP_LEASING)) { |
| 5059 |
torture_skip(tctx, "leases are not supported"); |
| 5060 |
} |
| 5061 |
|
| 5062 |
options = tree->session->transport->options; |
| 5063 |
|
| 5064 |
smb2_deltree(tree, __func__); |
| 5065 |
status = torture_smb2_testdir(tree, __func__, &_h); |
| 5066 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 5067 |
"torture_smb2_testdir failed\n"); |
| 5068 |
smb2_util_close(tree, _h); |
| 5069 |
|
| 5070 |
/* Choose a random name in case the state is left a little funky. */ |
| 5071 |
snprintf(fname, 256, "%s\\durable_v2_setinfo%s.dat", |
| 5072 |
__func__, generate_random_str(tctx, 8)); |
| 5073 |
|
| 5074 |
smb2_util_unlink(tree, fname); |
| 5075 |
|
| 5076 |
lease_key = random(); |
| 5077 |
smb2_lease_v2_create(&io, &ls, false /* dir */, fname, |
| 5078 |
lease_key, 0, /* parent lease key */ |
| 5079 |
smb2_util_lease_state("RWH"), 0 /* lease epoch */); |
| 5080 |
io.in.durable_open = false; |
| 5081 |
io.in.durable_open_v2 = true; |
| 5082 |
io.in.persistent_open = false; |
| 5083 |
io.in.create_guid = create_guid; |
| 5084 |
io.in.timeout = UINT32_MAX; |
| 5085 |
|
| 5086 |
status = smb2_create(tree, mem_ctx, &io); |
| 5087 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 5088 |
_h = io.out.file.handle; |
| 5089 |
h = &_h; |
| 5090 |
CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE); |
| 5091 |
CHECK_VAL(io.out.durable_open, false); |
| 5092 |
CHECK_VAL(io.out.durable_open_v2, true); |
| 5093 |
CHECK_VAL(io.out.persistent_open, false); |
| 5094 |
CHECK_VAL(io.out.timeout, 300*1000); |
| 5095 |
CHECK_VAL(io.out.oplock_level, SMB2_OPLOCK_LEVEL_LEASE); |
| 5096 |
CHECK_VAL(io.out.lease_response_v2.lease_key.data[0], lease_key); |
| 5097 |
CHECK_VAL(io.out.lease_response_v2.lease_key.data[1], ~lease_key); |
| 5098 |
|
| 5099 |
/* |
| 5100 |
* Set EOF to 0x100000. |
| 5101 |
* Mimics an Apple client test, but most importantly |
| 5102 |
* causes the mtime timestamp on disk to be updated. |
| 5103 |
*/ |
| 5104 |
ZERO_STRUCT(si); |
| 5105 |
si.generic.level = SMB_SFILEINFO_END_OF_FILE_INFORMATION; |
| 5106 |
si.generic.in.file.handle = io.out.file.handle; |
| 5107 |
si.end_of_file_info.in.size = 0x100000; |
| 5108 |
status = smb2_setinfo_file(tree, &si); |
| 5109 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 5110 |
|
| 5111 |
/* disconnect, reconnect and then do durable reopen */ |
| 5112 |
TALLOC_FREE(tree); |
| 5113 |
|
| 5114 |
if (!torture_smb2_connection_ext(tctx, 0, &options, &tree)) { |
| 5115 |
torture_warning(tctx, "couldn't reconnect, bailing\n"); |
| 5116 |
ret = false; |
| 5117 |
goto done; |
| 5118 |
} |
| 5119 |
|
| 5120 |
/* |
| 5121 |
* Now for a succeeding reconnect: |
| 5122 |
*/ |
| 5123 |
|
| 5124 |
ZERO_STRUCT(io); |
| 5125 |
io.in.fname = fname; |
| 5126 |
io.in.durable_open_v2 = false; |
| 5127 |
io.in.durable_handle_v2 = h; |
| 5128 |
io.in.create_guid = create_guid; |
| 5129 |
io.in.lease_request_v2 = &ls; |
| 5130 |
io.in.oplock_level = SMB2_OPLOCK_LEVEL_LEASE; |
| 5131 |
|
| 5132 |
/* the requested lease state is irrelevant */ |
| 5133 |
ls.lease_state = smb2_util_lease_state(""); |
| 5134 |
|
| 5135 |
h = NULL; |
| 5136 |
|
| 5137 |
status = smb2_create(tree, mem_ctx, &io); |
| 5138 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 5139 |
|
| 5140 |
CHECK_VAL(io.out.create_action, NTCREATEX_ACTION_EXISTED); |
| 5141 |
CHECK_VAL(io.out.size, 0x100000); \ |
| 5142 |
CHECK_VAL(io.out.durable_open, false); |
| 5143 |
CHECK_VAL(io.out.durable_open_v2, false); /* no dh2q response blob */ |
| 5144 |
CHECK_VAL(io.out.persistent_open, false); |
| 5145 |
CHECK_VAL(io.out.oplock_level, SMB2_OPLOCK_LEVEL_LEASE); |
| 5146 |
CHECK_VAL(io.out.lease_response_v2.lease_key.data[0], lease_key); |
| 5147 |
CHECK_VAL(io.out.lease_response_v2.lease_key.data[1], ~lease_key); |
| 5148 |
CHECK_VAL(io.out.lease_response_v2.lease_state, |
| 5149 |
smb2_util_lease_state("RWH")); |
| 5150 |
CHECK_VAL(io.out.lease_response_v2.lease_flags, 0); |
| 5151 |
CHECK_VAL(io.out.lease_response_v2.lease_duration, 0); |
| 5152 |
_h = io.out.file.handle; |
| 5153 |
h = &_h; |
| 5154 |
|
| 5155 |
done: |
| 5156 |
|
| 5157 |
if (h != NULL) { |
| 5158 |
smb2_util_close(tree, *h); |
| 5159 |
} |
| 5160 |
|
| 5161 |
smb2_util_unlink(tree, fname); |
| 5162 |
smb2_deltree(tree, __func__); |
| 5163 |
|
| 5164 |
talloc_free(tree); |
| 5165 |
|
| 5166 |
talloc_free(mem_ctx); |
| 5167 |
|
| 5168 |
return ret; |
| 5169 |
} |
| 5170 |
|
| 5171 |
static bool test_reconnect_twice(struct torture_context *tctx, |
| 5172 |
struct smb2_tree *tree, |
| 5173 |
struct smb2_tree *tree2) |
| 5174 |
{ |
| 5175 |
NTSTATUS status; |
| 5176 |
TALLOC_CTX *mem_ctx = talloc_new(tctx); |
| 5177 |
char fname[256]; |
| 5178 |
struct smb2_handle _h; |
| 5179 |
struct smb2_handle *h = NULL; |
| 5180 |
struct smb2_create io; |
| 5181 |
struct GUID create_guid = GUID_random(); |
| 5182 |
struct smbcli_options options; |
| 5183 |
uint64_t previous_session_id; |
| 5184 |
uint8_t b = 0; |
| 5185 |
bool ret = true; |
| 5186 |
bool ok; |
| 5187 |
|
| 5188 |
options = tree->session->transport->options; |
| 5189 |
previous_session_id = smb2cli_session_current_id(tree->session->smbXcli); |
| 5190 |
|
| 5191 |
/* Choose a random name in case the state is left a little funky. */ |
| 5192 |
snprintf(fname, |
| 5193 |
sizeof(fname), |
| 5194 |
"durable_v2_reconnect_delay_%s.dat", |
| 5195 |
generate_random_str(tctx, 8)); |
| 5196 |
|
| 5197 |
smb2_util_unlink(tree, fname); |
| 5198 |
|
| 5199 |
smb2_oplock_create_share(&io, fname, |
| 5200 |
smb2_util_share_access(""), |
| 5201 |
smb2_util_oplock_level("b")); |
| 5202 |
io.in.durable_open = false; |
| 5203 |
io.in.durable_open_v2 = true; |
| 5204 |
io.in.persistent_open = false; |
| 5205 |
io.in.create_guid = create_guid; |
| 5206 |
io.in.timeout = 5000; |
| 5207 |
|
| 5208 |
status = smb2_create(tree, mem_ctx, &io); |
| 5209 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 5210 |
|
| 5211 |
_h = io.out.file.handle; |
| 5212 |
h = &_h; |
| 5213 |
CHECK_VAL(io.out.oplock_level, smb2_util_oplock_level("b")); |
| 5214 |
CHECK_VAL(io.out.durable_open_v2, true); |
| 5215 |
|
| 5216 |
status = smb2_util_write(tree, *h, &b, 0, 1); |
| 5217 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 5218 |
|
| 5219 |
/* disconnect, leaving the durable open */ |
| 5220 |
TALLOC_FREE(tree); |
| 5221 |
h = NULL; |
| 5222 |
|
| 5223 |
/* |
| 5224 |
* Getting us closer to the time the Durable Handle scavenger fires: in |
| 5225 |
* one second it will go off... |
| 5226 |
*/ |
| 5227 |
sleep(4); |
| 5228 |
|
| 5229 |
ok = torture_smb2_connection_ext(tctx, previous_session_id, |
| 5230 |
&options, &tree); |
| 5231 |
torture_assert_goto(tctx, ok, ret, done, "couldn't reconnect, bailing\n"); |
| 5232 |
|
| 5233 |
ZERO_STRUCT(io); |
| 5234 |
io.in.fname = fname; |
| 5235 |
io.in.durable_open_v2 = false; |
| 5236 |
io.in.durable_handle_v2 = &_h; |
| 5237 |
io.in.create_guid = create_guid; |
| 5238 |
|
| 5239 |
status = smb2_create(tree, mem_ctx, &io); |
| 5240 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 5241 |
CHECK_VAL(io.out.oplock_level, smb2_util_oplock_level("b")); |
| 5242 |
_h = io.out.file.handle; |
| 5243 |
h = &_h; |
| 5244 |
|
| 5245 |
/* Second disconnect, leaving the durable open */ |
| 5246 |
TALLOC_FREE(tree); |
| 5247 |
h = NULL; |
| 5248 |
|
| 5249 |
/* |
| 5250 |
* Sleep longer then remaining first timeout and check if the |
| 5251 |
* scavenger time started by the first disconnect wipes the handle. |
| 5252 |
*/ |
| 5253 |
sleep(2); |
| 5254 |
|
| 5255 |
ok = torture_smb2_connection_ext(tctx, previous_session_id, |
| 5256 |
&options, &tree); |
| 5257 |
torture_assert_goto(tctx, ok, ret, done, "couldn't reconnect, bailing\n"); |
| 5258 |
|
| 5259 |
ZERO_STRUCT(io); |
| 5260 |
io.in.fname = fname; |
| 5261 |
io.in.durable_open_v2 = false; |
| 5262 |
io.in.durable_handle_v2 = &_h; |
| 5263 |
io.in.create_guid = create_guid; |
| 5264 |
|
| 5265 |
status = smb2_create(tree, mem_ctx, &io); |
| 5266 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 5267 |
CHECK_VAL(io.out.oplock_level, smb2_util_oplock_level("b")); |
| 5268 |
_h = io.out.file.handle; |
| 5269 |
h = &_h; |
| 5270 |
|
| 5271 |
done: |
| 5272 |
if (h != NULL) { |
| 5273 |
smb2_util_close(tree, *h); |
| 5274 |
} |
| 5275 |
smb2_util_unlink(tree2, fname); |
| 5276 |
talloc_free(mem_ctx); |
| 5277 |
return ret; |
| 5278 |
} |
| 5279 |
|
| 5280 |
struct torture_suite *torture_smb2_durable_v2_open_init(TALLOC_CTX *ctx) |
| 5281 |
{ |
| 5282 |
struct torture_suite *suite = |
| 5283 |
torture_suite_create(ctx, "durable-v2-open"); |
| 5284 |
|
| 5285 |
torture_suite_add_1smb2_test(suite, "create-blob", test_durable_v2_open_create_blob); |
| 5286 |
torture_suite_add_1smb2_test(suite, "open-oplock", test_durable_v2_open_oplock); |
| 5287 |
torture_suite_add_1smb2_test(suite, "open-lease", test_durable_v2_open_lease); |
| 5288 |
torture_suite_add_1smb2_test(suite, "reopen1", test_durable_v2_open_reopen1); |
| 5289 |
torture_suite_add_1smb2_test(suite, "reopen1a", test_durable_v2_open_reopen1a); |
| 5290 |
torture_suite_add_1smb2_test(suite, "reopen1a-lease", test_durable_v2_open_reopen1a_lease); |
| 5291 |
torture_suite_add_1smb2_test(suite, "reopen2", test_durable_v2_open_reopen2); |
| 5292 |
torture_suite_add_1smb2_test(suite, "reopen2b", test_durable_v2_open_reopen2b); |
| 5293 |
torture_suite_add_1smb2_test(suite, "reopen2c", test_durable_v2_open_reopen2c); |
| 5294 |
torture_suite_add_1smb2_test(suite, "reopen2-lease", test_durable_v2_open_reopen2_lease); |
| 5295 |
torture_suite_add_1smb2_test(suite, "reopen2-lease-v2", test_durable_v2_open_reopen2_lease_v2); |
| 5296 |
torture_suite_add_1smb2_test(suite, "durable-v2-setinfo", test_durable_v2_setinfo); |
| 5297 |
torture_suite_add_1smb2_test(suite, "lock-oplock", test_durable_v2_open_lock_oplock); |
| 5298 |
torture_suite_add_1smb2_test(suite, "lock-lease", test_durable_v2_open_lock_lease); |
| 5299 |
torture_suite_add_1smb2_test(suite, "lock-noW-lease", test_durable_v2_open_lock_noW_lease); |
| 5300 |
torture_suite_add_1smb2_test(suite, "stat-and-lease", test_durable_v2_open_stat_and_lease); |
| 5301 |
torture_suite_add_1smb2_test(suite, "nonstat-and-lease", test_durable_v2_open_nonstat_and_lease); |
| 5302 |
torture_suite_add_1smb2_test(suite, "statRH-and-lease", test_durable_v2_open_statRH_and_lease); |
| 5303 |
torture_suite_add_1smb2_test(suite, "two-same-lease", test_durable_v2_open_two_same_lease); |
| 5304 |
torture_suite_add_1smb2_test(suite, "two-different-lease", test_durable_v2_open_two_different_leases); |
| 5305 |
torture_suite_add_2smb2_test(suite, "keep-disconnected-rh-with-stat-open", test_durable_v2_open_keep_disconnected_rh_with_stat_open); |
| 5306 |
torture_suite_add_2smb2_test(suite, "keep-disconnected-rh-with-rh-open", test_durable_v2_open_keep_disconnected_rh_with_rh_open); |
| 5307 |
torture_suite_add_2smb2_test(suite, "keep-disconnected-rh-with-rwh-open", test_durable_v2_open_keep_disconnected_rh_with_rwh_open); |
| 5308 |
torture_suite_add_2smb2_test(suite, "keep-disconnected-rwh-with-stat-open", test_durable_v2_open_keep_disconnected_rwh_with_stat_open); |
| 5309 |
torture_suite_add_2smb2_test(suite, "purge-disconnected-rwh-with-rwh-open", test_durable_v2_open_purge_disconnected_rwh_with_rwh_open); |
| 5310 |
torture_suite_add_2smb2_test(suite, "purge-disconnected-rwh-with-rh-open", test_durable_v2_open_purge_disconnected_rwh_with_rh_open); |
| 5311 |
torture_suite_add_2smb2_test(suite, "purge-disconnected-rh-with-share-none-open", test_durable_v2_open_purge_disconnected_rh_with_share_none_open); |
| 5312 |
torture_suite_add_2smb2_test(suite, "purge-disconnected-rh-with-write", test_durable_v2_open_purge_disconnected_rh_with_write); |
| 5313 |
torture_suite_add_2smb2_test(suite, "purge-disconnected-rh-with-rename", test_durable_v2_open_purge_disconnected_rh_with_rename); |
| 5314 |
torture_suite_add_2smb2_test(suite, "app-instance", test_durable_v2_open_app_instance); |
| 5315 |
torture_suite_add_1smb2_test(suite, "persistent-open-oplock", test_persistent_open_oplock); |
| 5316 |
torture_suite_add_1smb2_test(suite, "persistent-open-lease", test_persistent_open_lease); |
| 5317 |
torture_suite_add_2smb2_test(suite, "reconnect-twice", test_reconnect_twice); |
| 5318 |
|
| 5319 |
suite->description = talloc_strdup(suite, "SMB2-DURABLE-V2-OPEN tests"); |
| 5320 |
|
| 5321 |
return suite; |
| 5322 |
} |
| 5323 |
|
| 5324 |
/** |
| 5325 |
* basic test for doing a durable open |
| 5326 |
* tcp disconnect, reconnect, do a durable reopen (succeeds) |
| 5327 |
*/ |
| 5328 |
static bool test_durable_v2_reconnect_delay(struct torture_context *tctx, |
| 5329 |
struct smb2_tree *tree, |
| 5330 |
struct smb2_tree *tree2) |
| 5331 |
{ |
| 5332 |
NTSTATUS status; |
| 5333 |
TALLOC_CTX *mem_ctx = talloc_new(tctx); |
| 5334 |
char fname[256]; |
| 5335 |
struct smb2_handle _h; |
| 5336 |
struct smb2_handle *h = NULL; |
| 5337 |
struct smb2_create io; |
| 5338 |
struct GUID create_guid = GUID_random(); |
| 5339 |
struct smbcli_options options; |
| 5340 |
uint64_t previous_session_id; |
| 5341 |
uint8_t b = 0; |
| 5342 |
bool ret = true; |
| 5343 |
bool ok; |
| 5344 |
|
| 5345 |
options = tree->session->transport->options; |
| 5346 |
previous_session_id = smb2cli_session_current_id(tree->session->smbXcli); |
| 5347 |
|
| 5348 |
/* Choose a random name in case the state is left a little funky. */ |
| 5349 |
snprintf(fname, |
| 5350 |
sizeof(fname), |
| 5351 |
"durable_v2_reconnect_delay_%s.dat", |
| 5352 |
generate_random_str(tctx, 8)); |
| 5353 |
|
| 5354 |
smb2_util_unlink(tree, fname); |
| 5355 |
|
| 5356 |
smb2_oplock_create_share(&io, fname, |
| 5357 |
smb2_util_share_access(""), |
| 5358 |
smb2_util_oplock_level("b")); |
| 5359 |
io.in.durable_open = false; |
| 5360 |
io.in.durable_open_v2 = true; |
| 5361 |
io.in.persistent_open = false; |
| 5362 |
io.in.create_guid = create_guid; |
| 5363 |
io.in.timeout = 0; |
| 5364 |
|
| 5365 |
status = smb2_create(tree, mem_ctx, &io); |
| 5366 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 5367 |
|
| 5368 |
_h = io.out.file.handle; |
| 5369 |
h = &_h; |
| 5370 |
CHECK_VAL(io.out.oplock_level, smb2_util_oplock_level("b")); |
| 5371 |
CHECK_VAL(io.out.durable_open_v2, true); |
| 5372 |
|
| 5373 |
status = smb2_util_write(tree, *h, &b, 0, 1); |
| 5374 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 5375 |
|
| 5376 |
/* disconnect, leaving the durable open */ |
| 5377 |
TALLOC_FREE(tree); |
| 5378 |
h = NULL; |
| 5379 |
|
| 5380 |
ok = torture_smb2_connection_ext(tctx, previous_session_id, |
| 5381 |
&options, &tree); |
| 5382 |
torture_assert_goto(tctx, ok, ret, done, "couldn't reconnect, bailing\n"); |
| 5383 |
|
| 5384 |
ZERO_STRUCT(io); |
| 5385 |
io.in.fname = fname; |
| 5386 |
io.in.durable_open_v2 = false; |
| 5387 |
io.in.durable_handle_v2 = &_h; |
| 5388 |
io.in.create_guid = create_guid; |
| 5389 |
|
| 5390 |
status = smb2_create(tree, mem_ctx, &io); |
| 5391 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 5392 |
CHECK_VAL(io.out.oplock_level, smb2_util_oplock_level("b")); |
| 5393 |
_h = io.out.file.handle; |
| 5394 |
h = &_h; |
| 5395 |
|
| 5396 |
done: |
| 5397 |
if (h != NULL) { |
| 5398 |
smb2_util_close(tree, *h); |
| 5399 |
} |
| 5400 |
TALLOC_FREE(tree); |
| 5401 |
|
| 5402 |
smb2_util_unlink(tree2, fname); |
| 5403 |
|
| 5404 |
TALLOC_FREE(tree2); |
| 5405 |
|
| 5406 |
talloc_free(mem_ctx); |
| 5407 |
|
| 5408 |
return ret; |
| 5409 |
} |
| 5410 |
|
| 5411 |
/** |
| 5412 |
* basic test for doing a durable open with 1msec cleanup time |
| 5413 |
* tcp disconnect, wait a bit, reconnect, do a durable reopen (fails) |
| 5414 |
*/ |
| 5415 |
static bool test_durable_v2_reconnect_delay_msec(struct torture_context *tctx, |
| 5416 |
struct smb2_tree *tree, |
| 5417 |
struct smb2_tree *tree2) |
| 5418 |
{ |
| 5419 |
NTSTATUS status; |
| 5420 |
TALLOC_CTX *mem_ctx = talloc_new(tctx); |
| 5421 |
char fname[256]; |
| 5422 |
struct smb2_handle _h; |
| 5423 |
struct smb2_handle *h = NULL; |
| 5424 |
struct smb2_create io; |
| 5425 |
struct smb2_lease ls; |
| 5426 |
struct GUID create_guid = GUID_random(); |
| 5427 |
struct smbcli_options options; |
| 5428 |
uint64_t previous_session_id; |
| 5429 |
uint8_t b = 0; |
| 5430 |
bool ret = true; |
| 5431 |
bool ok; |
| 5432 |
|
| 5433 |
options = tree->session->transport->options; |
| 5434 |
previous_session_id = smb2cli_session_current_id(tree->session->smbXcli); |
| 5435 |
|
| 5436 |
/* Choose a random name in case the state is left a little funky. */ |
| 5437 |
snprintf(fname, |
| 5438 |
sizeof(fname), |
| 5439 |
"durable_v2_reconnect_delay_%s.dat", |
| 5440 |
generate_random_str(tctx, 8)); |
| 5441 |
|
| 5442 |
smb2_util_unlink(tree, fname); |
| 5443 |
|
| 5444 |
smb2_lease_create( |
| 5445 |
&io, |
| 5446 |
&ls, |
| 5447 |
false /* dir */, |
| 5448 |
fname, |
| 5449 |
generate_random_u64(), |
| 5450 |
smb2_util_lease_state("RWH")); |
| 5451 |
io.in.durable_open = false; |
| 5452 |
io.in.durable_open_v2 = true; |
| 5453 |
io.in.persistent_open = false; |
| 5454 |
io.in.create_guid = create_guid; |
| 5455 |
io.in.timeout = 1; |
| 5456 |
|
| 5457 |
status = smb2_create(tree, mem_ctx, &io); |
| 5458 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 5459 |
|
| 5460 |
_h = io.out.file.handle; |
| 5461 |
h = &_h; |
| 5462 |
CHECK_VAL(io.out.oplock_level, SMB2_OPLOCK_LEVEL_LEASE); |
| 5463 |
CHECK_VAL(io.out.durable_open_v2, true); |
| 5464 |
|
| 5465 |
status = smb2_util_write(tree, *h, &b, 0, 1); |
| 5466 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 5467 |
|
| 5468 |
/* disconnect, leaving the durable open */ |
| 5469 |
TALLOC_FREE(tree); |
| 5470 |
h = NULL; |
| 5471 |
|
| 5472 |
ok = torture_smb2_connection_ext(tctx, previous_session_id, |
| 5473 |
&options, &tree); |
| 5474 |
torture_assert_goto(tctx, ok, ret, done, "couldn't reconnect, bailing\n"); |
| 5475 |
|
| 5476 |
sleep(10); |
| 5477 |
|
| 5478 |
ZERO_STRUCT(io); |
| 5479 |
io.in.fname = fname; |
| 5480 |
io.in.durable_open_v2 = false; |
| 5481 |
io.in.durable_handle_v2 = &_h; |
| 5482 |
io.in.create_guid = create_guid; |
| 5483 |
|
| 5484 |
status = smb2_create(tree, mem_ctx, &io); |
| 5485 |
CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND); |
| 5486 |
_h = io.out.file.handle; |
| 5487 |
h = &_h; |
| 5488 |
|
| 5489 |
done: |
| 5490 |
if (h != NULL) { |
| 5491 |
smb2_util_close(tree, *h); |
| 5492 |
} |
| 5493 |
TALLOC_FREE(tree); |
| 5494 |
|
| 5495 |
smb2_util_unlink(tree2, fname); |
| 5496 |
|
| 5497 |
TALLOC_FREE(tree2); |
| 5498 |
|
| 5499 |
talloc_free(mem_ctx); |
| 5500 |
|
| 5501 |
return ret; |
| 5502 |
} |
| 5503 |
|
| 5504 |
/** |
| 5505 |
* basic test for doing a durable open |
| 5506 |
* tcp disconnect, reconnect, do a durable reopen (succeeds) |
| 5507 |
*/ |
| 5508 |
static bool test_durable_v2_reconnect_bug15624(struct torture_context *tctx, |
| 5509 |
struct smb2_tree *tree, |
| 5510 |
struct smb2_tree *tree2) |
| 5511 |
{ |
| 5512 |
NTSTATUS status; |
| 5513 |
TALLOC_CTX *mem_ctx = talloc_new(tctx); |
| 5514 |
char fname[256]; |
| 5515 |
struct smb2_handle _h; |
| 5516 |
struct smb2_handle *h = NULL; |
| 5517 |
struct smb2_create io; |
| 5518 |
struct GUID create_guid = GUID_random(); |
| 5519 |
struct smbcli_options options; |
| 5520 |
uint64_t previous_session_id; |
| 5521 |
uint8_t b = 0; |
| 5522 |
bool ret = true; |
| 5523 |
bool ok; |
| 5524 |
|
| 5525 |
if (!torture_setting_bool(tctx, "bug15624", false)) { |
| 5526 |
torture_comment(tctx, |
| 5527 |
"share requires:\n" |
| 5528 |
"'vfs objects = error_inject'\n" |
| 5529 |
"'error_inject:durable_reconnect=st_ex_nlink'\n" |
| 5530 |
"test requires:\n" |
| 5531 |
"'--option=torture:bug15624=yes'\n"); |
| 5532 |
torture_skip(tctx, "'--option=torture:bug15624=yes' missing"); |
| 5533 |
} |
| 5534 |
|
| 5535 |
options = tree->session->transport->options; |
| 5536 |
previous_session_id = smb2cli_session_current_id(tree->session->smbXcli); |
| 5537 |
|
| 5538 |
/* Choose a random name in case the state is left a little funky. */ |
| 5539 |
snprintf(fname, |
| 5540 |
sizeof(fname), |
| 5541 |
"durable_v2_reconnect_bug15624_%s.dat", |
| 5542 |
generate_random_str(tctx, 8)); |
| 5543 |
|
| 5544 |
smb2_util_unlink(tree, fname); |
| 5545 |
|
| 5546 |
smb2_oplock_create_share(&io, fname, |
| 5547 |
smb2_util_share_access(""), |
| 5548 |
smb2_util_oplock_level("b")); |
| 5549 |
io.in.durable_open = false; |
| 5550 |
io.in.durable_open_v2 = true; |
| 5551 |
io.in.persistent_open = false; |
| 5552 |
io.in.create_guid = create_guid; |
| 5553 |
io.in.timeout = 0; |
| 5554 |
|
| 5555 |
status = smb2_create(tree, mem_ctx, &io); |
| 5556 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 5557 |
|
| 5558 |
_h = io.out.file.handle; |
| 5559 |
h = &_h; |
| 5560 |
CHECK_VAL(io.out.oplock_level, smb2_util_oplock_level("b")); |
| 5561 |
CHECK_VAL(io.out.durable_open_v2, true); |
| 5562 |
|
| 5563 |
status = smb2_util_write(tree, *h, &b, 0, 1); |
| 5564 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 5565 |
|
| 5566 |
/* disconnect, leaving the durable open */ |
| 5567 |
TALLOC_FREE(tree); |
| 5568 |
h = NULL; |
| 5569 |
|
| 5570 |
ok = torture_smb2_connection_ext(tctx, previous_session_id, |
| 5571 |
&options, &tree); |
| 5572 |
torture_assert_goto(tctx, ok, ret, done, "couldn't reconnect, bailing\n"); |
| 5573 |
|
| 5574 |
ZERO_STRUCT(io); |
| 5575 |
io.in.fname = fname; |
| 5576 |
io.in.durable_open_v2 = false; |
| 5577 |
io.in.durable_handle_v2 = &_h; |
| 5578 |
io.in.create_guid = create_guid; |
| 5579 |
|
| 5580 |
/* |
| 5581 |
* This assumes 'error_inject:durable_reconnect = st_ex_nlink' |
| 5582 |
* will cause the durable reconnect to fail... |
| 5583 |
* in order to have a regression test for the dead lock. |
| 5584 |
*/ |
| 5585 |
status = smb2_create(tree, mem_ctx, &io); |
| 5586 |
CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND); |
| 5587 |
|
| 5588 |
/* |
| 5589 |
* With the regression this will fail with |
| 5590 |
* a timeout... |
| 5591 |
*/ |
| 5592 |
status = smb2_util_unlink(tree2, fname); |
| 5593 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 5594 |
|
| 5595 |
done: |
| 5596 |
if (h != NULL) { |
| 5597 |
smb2_util_close(tree, *h); |
| 5598 |
} |
| 5599 |
TALLOC_FREE(tree); |
| 5600 |
|
| 5601 |
smb2_util_unlink(tree2, fname); |
| 5602 |
|
| 5603 |
TALLOC_FREE(tree2); |
| 5604 |
|
| 5605 |
talloc_free(mem_ctx); |
| 5606 |
|
| 5607 |
return ret; |
| 5608 |
} |
| 5609 |
|
| 5610 |
struct torture_suite *torture_smb2_durable_v2_delay_init(TALLOC_CTX *ctx) |
| 5611 |
{ |
| 5612 |
struct torture_suite *suite = |
| 5613 |
torture_suite_create(ctx, "durable-v2-delay"); |
| 5614 |
|
| 5615 |
torture_suite_add_2smb2_test(suite, |
| 5616 |
"durable_v2_reconnect_delay", |
| 5617 |
test_durable_v2_reconnect_delay); |
| 5618 |
torture_suite_add_2smb2_test(suite, |
| 5619 |
"durable_v2_reconnect_delay_msec", |
| 5620 |
test_durable_v2_reconnect_delay_msec); |
| 5621 |
|
| 5622 |
return suite; |
| 5623 |
} |
| 5624 |
|
| 5625 |
struct torture_suite *torture_smb2_durable_v2_regressions_init(TALLOC_CTX *ctx) |
| 5626 |
{ |
| 5627 |
struct torture_suite *suite = |
| 5628 |
torture_suite_create(ctx, "durable-v2-regressions"); |
| 5629 |
|
| 5630 |
torture_suite_add_2smb2_test(suite, |
| 5631 |
"durable_v2_reconnect_bug15624", |
| 5632 |
test_durable_v2_reconnect_bug15624); |
| 5633 |
|
| 5634 |
return suite; |
| 5635 |
} |