libsmb: Make cli_smb2_create_fnum async
[Samba.git] / source3 / torture / test_smb2.c
blob1923668a15e32ae1059498a7c7a421f6adfb0fab
1 /*
2 Unix SMB/CIFS implementation.
3 Initial test for the smb2 client lib
4 Copyright (C) Volker Lendecke 2011
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "includes.h"
21 #include "torture/proto.h"
22 #include "client.h"
23 #include "trans2.h"
24 #include "../libcli/smb/smbXcli_base.h"
25 #include "libsmb/smb2cli.h"
26 #include "libcli/security/security.h"
27 #include "libsmb/proto.h"
28 #include "auth/gensec/gensec.h"
29 #include "auth_generic.h"
31 extern fstring host, workgroup, share, password, username, myname;
33 bool run_smb2_basic(int dummy)
35 struct cli_state *cli;
36 NTSTATUS status;
37 uint64_t fid_persistent, fid_volatile;
38 const char *hello = "Hello, world\n";
39 uint8_t *result;
40 uint32_t nread;
41 uint8_t *dir_data;
42 uint32_t dir_data_length;
43 uint32_t saved_tid = 0;
44 struct smbXcli_tcon *saved_tcon = NULL;
45 uint64_t saved_uid = 0;
47 printf("Starting SMB2-BASIC\n");
49 if (!torture_init_connection(&cli)) {
50 return false;
53 status = smbXcli_negprot(cli->conn, cli->timeout,
54 PROTOCOL_SMB2_02, PROTOCOL_SMB2_02);
55 if (!NT_STATUS_IS_OK(status)) {
56 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
57 return false;
60 status = cli_session_setup(cli, username,
61 password, strlen(password),
62 password, strlen(password),
63 workgroup);
64 if (!NT_STATUS_IS_OK(status)) {
65 printf("cli_session_setup returned %s\n", nt_errstr(status));
66 return false;
69 status = cli_tree_connect(cli, share, "?????", "", 0);
70 if (!NT_STATUS_IS_OK(status)) {
71 printf("cli_tree_connect returned %s\n", nt_errstr(status));
72 return false;
75 status = smb2cli_create(cli->conn, cli->timeout, cli->smb2.session,
76 cli->smb2.tcon, "smb2-basic.txt",
77 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
78 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
79 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
80 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
81 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
82 FILE_CREATE, /* create_disposition, */
83 FILE_DELETE_ON_CLOSE, /* create_options, */
84 NULL, /* smb2_create_blobs *blobs */
85 &fid_persistent,
86 &fid_volatile,
87 NULL);
88 if (!NT_STATUS_IS_OK(status)) {
89 printf("smb2cli_create returned %s\n", nt_errstr(status));
90 return false;
93 status = smb2cli_write(cli->conn, cli->timeout, cli->smb2.session,
94 cli->smb2.tcon, strlen(hello), 0, fid_persistent,
95 fid_volatile, 0, 0, (const uint8_t *)hello, NULL);
96 if (!NT_STATUS_IS_OK(status)) {
97 printf("smb2cli_write returned %s\n", nt_errstr(status));
98 return false;
101 status = smb2cli_flush(cli->conn, cli->timeout, cli->smb2.session,
102 cli->smb2.tcon, fid_persistent, fid_volatile);
103 if (!NT_STATUS_IS_OK(status)) {
104 printf("smb2cli_flush returned %s\n", nt_errstr(status));
105 return false;
108 status = smb2cli_read(cli->conn, cli->timeout, cli->smb2.session,
109 cli->smb2.tcon, 0x10000, 0, fid_persistent,
110 fid_volatile, 2, 0,
111 talloc_tos(), &result, &nread);
112 if (!NT_STATUS_IS_OK(status)) {
113 printf("smb2cli_read returned %s\n", nt_errstr(status));
114 return false;
117 if (nread != strlen(hello)) {
118 printf("smb2cli_read returned %d bytes, expected %d\n",
119 (int)nread, (int)strlen(hello));
120 return false;
123 if (memcmp(hello, result, nread) != 0) {
124 printf("smb2cli_read returned '%s', expected '%s'\n",
125 result, hello);
126 return false;
129 status = smb2cli_close(cli->conn, cli->timeout, cli->smb2.session,
130 cli->smb2.tcon, 0, fid_persistent, fid_volatile);
131 if (!NT_STATUS_IS_OK(status)) {
132 printf("smb2cli_close returned %s\n", nt_errstr(status));
133 return false;
136 status = smb2cli_create(cli->conn, cli->timeout, cli->smb2.session,
137 cli->smb2.tcon, "",
138 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
139 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
140 SEC_STD_SYNCHRONIZE|
141 SEC_DIR_LIST|
142 SEC_DIR_READ_ATTRIBUTE, /* desired_access, */
143 0, /* file_attributes, */
144 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
145 FILE_OPEN, /* create_disposition, */
146 FILE_SYNCHRONOUS_IO_NONALERT|FILE_DIRECTORY_FILE, /* create_options, */
147 NULL, /* smb2_create_blobs *blobs */
148 &fid_persistent,
149 &fid_volatile,
150 NULL);
151 if (!NT_STATUS_IS_OK(status)) {
152 printf("smb2cli_create returned %s\n", nt_errstr(status));
153 return false;
156 status = smb2cli_query_directory(
157 cli->conn, cli->timeout, cli->smb2.session, cli->smb2.tcon,
158 1, 0, 0, fid_persistent, fid_volatile, "*", 0xffff,
159 talloc_tos(), &dir_data, &dir_data_length);
161 if (!NT_STATUS_IS_OK(status)) {
162 printf("smb2cli_query_directory returned %s\n", nt_errstr(status));
163 return false;
166 status = smb2cli_close(cli->conn, cli->timeout, cli->smb2.session,
167 cli->smb2.tcon, 0, fid_persistent, fid_volatile);
168 if (!NT_STATUS_IS_OK(status)) {
169 printf("smb2cli_close returned %s\n", nt_errstr(status));
170 return false;
173 saved_tid = smb2cli_tcon_current_id(cli->smb2.tcon);
174 saved_tcon = cli->smb2.tcon;
175 cli->smb2.tcon = smbXcli_tcon_create(cli);
176 smb2cli_tcon_set_values(cli->smb2.tcon,
177 NULL, /* session */
178 saved_tid,
179 0, /* type */
180 0, /* flags */
181 0, /* capabilities */
182 0 /* maximal_access */);
183 status = smb2cli_tdis(cli);
184 if (!NT_STATUS_IS_OK(status)) {
185 printf("smb2cli_tdis returned %s\n", nt_errstr(status));
186 return false;
188 talloc_free(cli->smb2.tcon);
189 cli->smb2.tcon = saved_tcon;
191 status = smb2cli_tdis(cli);
192 if (!NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED)) {
193 printf("2nd smb2cli_tdis returned %s\n", nt_errstr(status));
194 return false;
197 saved_uid = smb2cli_session_current_id(cli->smb2.session);
198 status = smb2cli_logoff(cli->conn, cli->timeout, cli->smb2.session);
199 if (!NT_STATUS_IS_OK(status)) {
200 printf("smb2cli_logoff returned %s\n", nt_errstr(status));
201 return false;
204 cli->smb2.session = smbXcli_session_create(cli, cli->conn);
205 if (cli->smb2.session == NULL) {
206 printf("smbXcli_session_create() returned NULL\n");
207 return false;
210 smb2cli_session_set_id_and_flags(cli->smb2.session, saved_uid, 0);
212 status = smb2cli_logoff(cli->conn, cli->timeout, cli->smb2.session);
213 if (!NT_STATUS_EQUAL(status, NT_STATUS_USER_SESSION_DELETED)) {
214 printf("2nd smb2cli_logoff returned %s\n", nt_errstr(status));
215 return false;
218 return true;
221 bool run_smb2_negprot(int dummy)
223 struct cli_state *cli;
224 NTSTATUS status;
225 enum protocol_types protocol;
226 const char *name = NULL;
228 printf("Starting SMB2-NEGPROT\n");
230 if (!torture_init_connection(&cli)) {
231 return false;
234 status = smbXcli_negprot(cli->conn, cli->timeout,
235 PROTOCOL_CORE, PROTOCOL_LATEST);
236 if (!NT_STATUS_IS_OK(status)) {
237 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
238 return false;
241 protocol = smbXcli_conn_protocol(cli->conn);
243 switch (protocol) {
244 case PROTOCOL_SMB2_02:
245 name = "SMB2_02";
246 break;
247 case PROTOCOL_SMB2_10:
248 name = "SMB2_10";
249 break;
250 case PROTOCOL_SMB2_22:
251 name = "SMB2_22";
252 break;
253 case PROTOCOL_SMB2_24:
254 name = "SMB2_24";
255 break;
256 case PROTOCOL_SMB3_00:
257 name = "SMB3_00";
258 break;
259 case PROTOCOL_SMB3_02:
260 name = "SMB3_02";
261 break;
262 default:
263 break;
266 if (name) {
267 printf("Server supports %s\n", name);
268 } else {
269 printf("Server DOES NOT support SMB2\n");
270 return false;
273 status = smbXcli_negprot(cli->conn, cli->timeout,
274 protocol, protocol);
275 if (!NT_STATUS_EQUAL(status, NT_STATUS_CONNECTION_RESET) &&
276 !NT_STATUS_EQUAL(status, NT_STATUS_CONNECTION_DISCONNECTED) &&
277 !NT_STATUS_EQUAL(status, NT_STATUS_CONNECTION_ABORTED)) {
278 printf("2nd smbXcli_negprot should disconnect - returned %s\n",
279 nt_errstr(status));
280 return false;
283 if (smbXcli_conn_is_connected(cli->conn)) {
284 printf("2nd smbXcli_negprot should disconnect "
285 "- still connected\n");
286 return false;
289 return true;
292 bool run_smb2_session_reconnect(int dummy)
294 struct cli_state *cli1;
295 struct cli_state *cli2;
296 NTSTATUS status;
297 bool ok;
298 uint64_t fid_persistent, fid_volatile;
299 struct tevent_context *ev;
300 struct tevent_req *subreq;
301 DATA_BLOB in_blob = data_blob_null;
302 DATA_BLOB out_blob;
303 DATA_BLOB session_key;
304 struct auth_generic_state *auth_generic_state;
305 struct iovec *recv_iov;
306 const char *hello = "Hello, world\n";
307 uint8_t *result;
308 uint32_t nread;
310 printf("Starting SMB2-SESSION-RECONNECT\n");
312 if (!torture_init_connection(&cli1)) {
313 return false;
316 status = smbXcli_negprot(cli1->conn, cli1->timeout,
317 PROTOCOL_SMB2_02, PROTOCOL_LATEST);
318 if (!NT_STATUS_IS_OK(status)) {
319 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
320 return false;
323 status = cli_session_setup(cli1, username,
324 password, strlen(password),
325 password, strlen(password),
326 workgroup);
327 if (!NT_STATUS_IS_OK(status)) {
328 printf("cli_session_setup returned %s\n", nt_errstr(status));
329 return false;
332 status = cli_tree_connect(cli1, share, "?????", "", 0);
333 if (!NT_STATUS_IS_OK(status)) {
334 printf("cli_tree_connect returned %s\n", nt_errstr(status));
335 return false;
338 status = smb2cli_create(cli1->conn, cli1->timeout, cli1->smb2.session,
339 cli1->smb2.tcon, "session-reconnect.txt",
340 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
341 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
342 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
343 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
344 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
345 FILE_CREATE, /* create_disposition, */
346 FILE_DELETE_ON_CLOSE, /* create_options, */
347 NULL, /* smb2_create_blobs *blobs */
348 &fid_persistent,
349 &fid_volatile,
350 NULL);
351 if (!NT_STATUS_IS_OK(status)) {
352 printf("smb2cli_create on cli1 %s\n", nt_errstr(status));
353 return false;
356 status = smb2cli_write(cli1->conn, cli1->timeout, cli1->smb2.session,
357 cli1->smb2.tcon, strlen(hello), 0, fid_persistent,
358 fid_volatile, 0, 0, (const uint8_t *)hello, NULL);
359 if (!NT_STATUS_IS_OK(status)) {
360 printf("smb2cli_write returned %s\n", nt_errstr(status));
361 return false;
364 status = smb2cli_flush(cli1->conn, cli1->timeout, cli1->smb2.session,
365 cli1->smb2.tcon, fid_persistent, fid_volatile);
366 if (!NT_STATUS_IS_OK(status)) {
367 printf("smb2cli_flush returned %s\n", nt_errstr(status));
368 return false;
371 status = smb2cli_read(cli1->conn, cli1->timeout, cli1->smb2.session,
372 cli1->smb2.tcon, 0x10000, 0, fid_persistent,
373 fid_volatile, 2, 0,
374 talloc_tos(), &result, &nread);
375 if (!NT_STATUS_IS_OK(status)) {
376 printf("smb2cli_read returned %s\n", nt_errstr(status));
377 return false;
380 if (nread != strlen(hello)) {
381 printf("smb2cli_read returned %d bytes, expected %d\n",
382 (int)nread, (int)strlen(hello));
383 return false;
386 if (memcmp(hello, result, nread) != 0) {
387 printf("smb2cli_read returned '%s', expected '%s'\n",
388 result, hello);
389 return false;
392 /* prepare second session */
394 if (!torture_init_connection(&cli2)) {
395 return false;
398 status = smbXcli_negprot(cli2->conn, cli2->timeout,
399 PROTOCOL_SMB2_02, PROTOCOL_LATEST);
400 if (!NT_STATUS_IS_OK(status)) {
401 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
402 return false;
405 status = auth_generic_client_prepare(talloc_tos(), &auth_generic_state);
406 if (!NT_STATUS_IS_OK(status)) {
407 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status));
408 return false;
411 gensec_want_feature(auth_generic_state->gensec_security,
412 GENSEC_FEATURE_SESSION_KEY);
413 status = auth_generic_set_username(auth_generic_state, username);
414 if (!NT_STATUS_IS_OK(status)) {
415 printf("auth_generic_set_username returned %s\n", nt_errstr(status));
416 return false;
419 status = auth_generic_set_domain(auth_generic_state, workgroup);
420 if (!NT_STATUS_IS_OK(status)) {
421 printf("auth_generic_set_domain returned %s\n", nt_errstr(status));
422 return false;
425 status = auth_generic_set_password(auth_generic_state, password);
426 if (!NT_STATUS_IS_OK(status)) {
427 printf("auth_generic_set_password returned %s\n", nt_errstr(status));
428 return false;
431 status = auth_generic_client_start(auth_generic_state, GENSEC_OID_NTLMSSP);
432 if (!NT_STATUS_IS_OK(status)) {
433 printf("auth_generic_client_start returned %s\n", nt_errstr(status));
434 return false;
437 ev = samba_tevent_context_init(talloc_tos());
438 if (ev == NULL) {
439 printf("samba_tevent_context_init() returned NULL\n");
440 return false;
443 status = gensec_update(auth_generic_state->gensec_security,
444 talloc_tos(), data_blob_null, &in_blob);
445 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
446 printf("gensec_update returned %s\n", nt_errstr(status));
447 return false;
450 cli2->smb2.session = smbXcli_session_create(cli2, cli2->conn);
452 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
453 cli2->conn,
454 cli2->timeout,
455 cli2->smb2.session,
456 0x0, /* in_flags */
457 SMB2_CAP_DFS, /* in_capabilities */
458 0, /* in_channel */
459 /* in_previous_session_id: */
460 smb2cli_session_current_id(cli1->smb2.session),
461 &in_blob); /* in_security_buffer */
462 if (subreq == NULL) {
463 printf("smb2cli_session_setup_send() returned NULL\n");
464 return false;
467 ok = tevent_req_poll(subreq, ev);
468 if (!ok) {
469 printf("tevent_req_poll() returned false\n");
470 return false;
473 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
474 NULL, &out_blob);
475 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
476 printf("smb2cli_session_setup_recv returned %s\n",
477 nt_errstr(status));
478 return false;
481 status = gensec_update(auth_generic_state->gensec_security,
482 talloc_tos(), out_blob, &in_blob);
483 if (!NT_STATUS_IS_OK(status)) {
484 printf("auth_generic_update returned %s\n", nt_errstr(status));
485 return false;
488 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
489 cli2->conn,
490 cli2->timeout,
491 cli2->smb2.session,
492 0x0, /* in_flags */
493 SMB2_CAP_DFS, /* in_capabilities */
494 0, /* in_channel */
495 /* in_previous_session_id: */
496 smb2cli_session_current_id(cli1->smb2.session),
497 &in_blob); /* in_security_buffer */
498 if (subreq == NULL) {
499 printf("smb2cli_session_setup_send() returned NULL\n");
500 return false;
503 ok = tevent_req_poll(subreq, ev);
504 if (!ok) {
505 printf("tevent_req_poll() returned false\n");
506 return false;
509 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
510 &recv_iov, &out_blob);
511 if (!NT_STATUS_IS_OK(status)) {
512 printf("smb2cli_session_setup_recv returned %s\n",
513 nt_errstr(status));
514 return false;
517 status = gensec_session_key(auth_generic_state->gensec_security, talloc_tos(),
518 &session_key);
519 if (!NT_STATUS_IS_OK(status)) {
520 printf("gensec_session_key returned %s\n",
521 nt_errstr(status));
522 return false;
525 /* check file operation on the old client */
527 status = smb2cli_flush(cli1->conn, cli1->timeout, cli1->smb2.session,
528 cli1->smb2.tcon, fid_persistent, fid_volatile);
529 if (!NT_STATUS_EQUAL(status, NT_STATUS_USER_SESSION_DELETED)) {
530 printf("smb2cli_flush returned %s\n", nt_errstr(status));
531 return false;
534 status = cli_tree_connect(cli1, share, "?????", "", 0);
535 if (!NT_STATUS_EQUAL(status, NT_STATUS_USER_SESSION_DELETED)) {
536 printf("cli_tree_connect returned %s\n", nt_errstr(status));
537 return false;
541 * checking file operations without signing.
542 * on w2k8r2 at least, flush, read and write also work the same way,
543 * while create gives ACCESS_DENIED without signing
545 status = smb2cli_flush(cli2->conn, cli2->timeout, cli2->smb2.session,
546 cli2->smb2.tcon, fid_persistent, fid_volatile);
547 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED) &&
548 !NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED))
550 printf("smb2cli_flush returned %s\n", nt_errstr(status));
551 return false;
554 status = smb2cli_write(cli2->conn, cli2->timeout, cli2->smb2.session,
555 cli2->smb2.tcon, strlen(hello), 0, fid_persistent,
556 fid_volatile, 0, 0, (const uint8_t *)hello, NULL);
557 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED) &&
558 !NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED))
560 printf("smb2cli_write returned %s\n", nt_errstr(status));
561 return false;
564 status = smb2cli_read(cli2->conn, cli2->timeout, cli2->smb2.session,
565 cli2->smb2.tcon, 0x10000, 0, fid_persistent,
566 fid_volatile, 2, 0,
567 talloc_tos(), &result, &nread);
568 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED) &&
569 !NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED))
571 printf("smb2cli_read returned %s\n", nt_errstr(status));
572 return false;
575 status = smb2cli_create(cli2->conn, cli2->timeout, cli2->smb2.session,
576 cli2->smb2.tcon, "session-reconnect.txt",
577 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
578 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
579 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
580 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
581 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
582 FILE_CREATE, /* create_disposition, */
583 FILE_DELETE_ON_CLOSE, /* create_options, */
584 NULL, /* smb2_create_blobs *blobs */
585 &fid_persistent,
586 &fid_volatile,
587 NULL);
588 if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED) &&
589 !NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED)) {
590 printf("smb2cli_create on cli2 %s\n", nt_errstr(status));
591 return false;
594 /* now grab the session key and try with signing */
596 status = smb2cli_session_set_session_key(cli2->smb2.session,
597 session_key,
598 recv_iov);
599 if (!NT_STATUS_IS_OK(status)) {
600 printf("smb2cli_session_set_session_key %s\n", nt_errstr(status));
601 return false;
604 /* the tid seems to be irrelevant at this stage */
606 status = smb2cli_flush(cli2->conn, cli2->timeout, cli2->smb2.session,
607 cli1->smb2.tcon, fid_persistent, fid_volatile);
608 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED) &&
609 !NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED))
611 printf("smb2cli_flush returned %s\n", nt_errstr(status));
612 return false;
615 status = smb2cli_write(cli2->conn, cli2->timeout, cli2->smb2.session,
616 cli1->smb2.tcon, strlen(hello), 0, fid_persistent,
617 fid_volatile, 0, 0, (const uint8_t *)hello, NULL);
618 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED) &&
619 !NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED))
621 printf("smb2cli_write returned %s\n", nt_errstr(status));
622 return false;
625 status = smb2cli_read(cli2->conn, cli2->timeout, cli2->smb2.session,
626 cli1->smb2.tcon, 0x10000, 0, fid_persistent,
627 fid_volatile, 2, 0,
628 talloc_tos(), &result, &nread);
629 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED) &&
630 !NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED))
632 printf("smb2cli_read returned %s\n", nt_errstr(status));
633 return false;
636 status = smb2cli_create(cli2->conn, cli2->timeout, cli2->smb2.session,
637 cli1->smb2.tcon, "session-reconnect.txt",
638 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
639 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
640 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
641 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
642 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
643 FILE_CREATE, /* create_disposition, */
644 FILE_DELETE_ON_CLOSE, /* create_options, */
645 NULL, /* smb2_create_blobs *blobs */
646 &fid_persistent,
647 &fid_volatile,
648 NULL);
649 if (!NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED) &&
650 !NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED))
652 printf("smb2cli_create on cli2 %s\n", nt_errstr(status));
653 return false;
656 /* now do a new tcon and test file calls again */
658 status = cli_tree_connect(cli2, share, "?????", "", 0);
659 if (!NT_STATUS_IS_OK(status)) {
660 printf("cli_tree_connect returned %s\n", nt_errstr(status));
661 return false;
664 status = smb2cli_create(cli2->conn, cli2->timeout, cli2->smb2.session,
665 cli2->smb2.tcon, "session-reconnect.txt",
666 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
667 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
668 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
669 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
670 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
671 FILE_CREATE, /* create_disposition, */
672 FILE_DELETE_ON_CLOSE, /* create_options, */
673 NULL, /* smb2_create_blobs *blobs */
674 &fid_persistent,
675 &fid_volatile,
676 NULL);
677 if (!NT_STATUS_IS_OK(status)) {
678 printf("smb2cli_create on cli2 %s\n", nt_errstr(status));
679 return false;
682 status = smb2cli_write(cli2->conn, cli2->timeout, cli2->smb2.session,
683 cli2->smb2.tcon, strlen(hello), 0, fid_persistent,
684 fid_volatile, 0, 0, (const uint8_t *)hello, NULL);
685 if (!NT_STATUS_IS_OK(status)) {
686 printf("smb2cli_write returned %s\n", nt_errstr(status));
687 return false;
690 status = smb2cli_flush(cli2->conn, cli2->timeout, cli2->smb2.session,
691 cli2->smb2.tcon, fid_persistent, fid_volatile);
692 if (!NT_STATUS_IS_OK(status)) {
693 printf("smb2cli_flush returned %s\n", nt_errstr(status));
694 return false;
697 status = smb2cli_read(cli2->conn, cli2->timeout, cli2->smb2.session,
698 cli2->smb2.tcon, 0x10000, 0, fid_persistent,
699 fid_volatile, 2, 0,
700 talloc_tos(), &result, &nread);
701 if (!NT_STATUS_IS_OK(status)) {
702 printf("smb2cli_read returned %s\n", nt_errstr(status));
703 return false;
706 if (nread != strlen(hello)) {
707 printf("smb2cli_read returned %d bytes, expected %d\n",
708 (int)nread, (int)strlen(hello));
709 return false;
712 if (memcmp(hello, result, nread) != 0) {
713 printf("smb2cli_read returned '%s', expected '%s'\n",
714 result, hello);
715 return false;
718 return true;
721 bool run_smb2_tcon_dependence(int dummy)
723 struct cli_state *cli;
724 NTSTATUS status;
725 uint64_t fid_persistent, fid_volatile;
726 const char *hello = "Hello, world\n";
727 uint8_t *result;
728 uint32_t nread;
729 struct smbXcli_tcon *tcon2;
730 uint32_t tcon2_id;
732 printf("Starting SMB2-TCON-DEPENDENCE\n");
734 if (!torture_init_connection(&cli)) {
735 return false;
738 status = smbXcli_negprot(cli->conn, cli->timeout,
739 PROTOCOL_SMB2_02, PROTOCOL_LATEST);
740 if (!NT_STATUS_IS_OK(status)) {
741 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
742 return false;
745 status = cli_session_setup(cli, username,
746 password, strlen(password),
747 password, strlen(password),
748 workgroup);
749 if (!NT_STATUS_IS_OK(status)) {
750 printf("cli_session_setup returned %s\n", nt_errstr(status));
751 return false;
754 status = cli_tree_connect(cli, share, "?????", "", 0);
755 if (!NT_STATUS_IS_OK(status)) {
756 printf("cli_tree_connect returned %s\n", nt_errstr(status));
757 return false;
760 status = smb2cli_create(cli->conn, cli->timeout, cli->smb2.session,
761 cli->smb2.tcon, "tcon_depedence.txt",
762 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
763 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
764 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
765 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
766 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
767 FILE_CREATE, /* create_disposition, */
768 FILE_DELETE_ON_CLOSE, /* create_options, */
769 NULL, /* smb2_create_blobs *blobs */
770 &fid_persistent,
771 &fid_volatile,
772 NULL);
773 if (!NT_STATUS_IS_OK(status)) {
774 printf("smb2cli_create on cli %s\n", nt_errstr(status));
775 return false;
778 status = smb2cli_write(cli->conn, cli->timeout, cli->smb2.session,
779 cli->smb2.tcon, strlen(hello), 0, fid_persistent,
780 fid_volatile, 0, 0, (const uint8_t *)hello, NULL);
781 if (!NT_STATUS_IS_OK(status)) {
782 printf("smb2cli_write returned %s\n", nt_errstr(status));
783 return false;
786 status = smb2cli_flush(cli->conn, cli->timeout, cli->smb2.session,
787 cli->smb2.tcon, fid_persistent, fid_volatile);
788 if (!NT_STATUS_IS_OK(status)) {
789 printf("smb2cli_flush returned %s\n", nt_errstr(status));
790 return false;
793 status = smb2cli_read(cli->conn, cli->timeout, cli->smb2.session,
794 cli->smb2.tcon, 0x10000, 0, fid_persistent,
795 fid_volatile, 2, 0,
796 talloc_tos(), &result, &nread);
797 if (!NT_STATUS_IS_OK(status)) {
798 printf("smb2cli_read returned %s\n", nt_errstr(status));
799 return false;
802 if (nread != strlen(hello)) {
803 printf("smb2cli_read returned %d bytes, expected %d\n",
804 (int)nread, (int)strlen(hello));
805 return false;
808 if (memcmp(hello, result, nread) != 0) {
809 printf("smb2cli_read returned '%s', expected '%s'\n",
810 result, hello);
811 return false;
814 /* check behaviour with wrong tid... */
816 tcon2 = smbXcli_tcon_create(cli);
817 tcon2_id = smb2cli_tcon_current_id(cli->smb2.tcon);
818 tcon2_id++;
819 smb2cli_tcon_set_values(tcon2,
820 NULL, /* session */
821 tcon2_id,
822 0, /* type */
823 0, /* flags */
824 0, /* capabilities */
825 0 /* maximal_access */);
827 status = smb2cli_read(cli->conn, cli->timeout, cli->smb2.session,
828 tcon2, 0x10000, 0, fid_persistent,
829 fid_volatile, 2, 0,
830 talloc_tos(), &result, &nread);
831 if (!NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED)) {
832 printf("smb2cli_read returned %s\n", nt_errstr(status));
833 return false;
836 talloc_free(tcon2);
838 return true;
841 bool run_smb2_multi_channel(int dummy)
843 struct cli_state *cli1;
844 struct cli_state *cli2;
845 struct cli_state *cli3;
846 NTSTATUS status;
847 bool ok;
848 uint64_t fid_persistent, fid_volatile;
849 struct tevent_context *ev;
850 struct tevent_req *subreq;
851 DATA_BLOB in_blob = data_blob_null;
852 DATA_BLOB out_blob;
853 DATA_BLOB channel_session_key;
854 struct auth_generic_state *auth_generic_state;
855 struct iovec *recv_iov;
856 const char *hello = "Hello, world\n";
857 uint8_t *result;
858 uint32_t nread;
860 printf("Starting SMB2-MULTI-CHANNEL\n");
862 if (!torture_init_connection(&cli1)) {
863 return false;
866 if (!torture_init_connection(&cli2)) {
867 return false;
870 if (!torture_init_connection(&cli3)) {
871 return false;
874 status = smbXcli_negprot(cli1->conn, cli1->timeout,
875 PROTOCOL_SMB2_22, PROTOCOL_LATEST);
876 if (!NT_STATUS_IS_OK(status)) {
877 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
878 return false;
881 status = smbXcli_negprot(cli2->conn, cli2->timeout,
882 PROTOCOL_SMB2_22, PROTOCOL_LATEST);
883 if (!NT_STATUS_IS_OK(status)) {
884 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
885 return false;
888 status = smbXcli_negprot(cli3->conn, cli3->timeout,
889 PROTOCOL_SMB2_22, PROTOCOL_LATEST);
890 if (!NT_STATUS_IS_OK(status)) {
891 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
892 return false;
895 status = cli_session_setup(cli1, username,
896 password, strlen(password),
897 password, strlen(password),
898 workgroup);
899 if (!NT_STATUS_IS_OK(status)) {
900 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status));
901 return false;
904 status = cli_tree_connect(cli1, share, "?????", "", 0);
905 if (!NT_STATUS_IS_OK(status)) {
906 printf("cli_tree_connect returned %s\n", nt_errstr(status));
907 return false;
910 status = smb2cli_session_create_channel(cli2,
911 cli1->smb2.session,
912 cli2->conn,
913 &cli2->smb2.session);
914 if (!NT_STATUS_IS_OK(status)) {
915 printf("smb2cli_session_create_channel returned %s\n",
916 nt_errstr(status));
917 return false;
920 status = auth_generic_client_prepare(talloc_tos(), &auth_generic_state);
921 if (!NT_STATUS_IS_OK(status)) {
922 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status));
923 return false;
926 gensec_want_feature(auth_generic_state->gensec_security,
927 GENSEC_FEATURE_SESSION_KEY);
928 status = auth_generic_set_username(auth_generic_state, username);
929 if (!NT_STATUS_IS_OK(status)) {
930 printf("auth_generic_set_username returned %s\n", nt_errstr(status));
931 return false;
934 status = auth_generic_set_domain(auth_generic_state, workgroup);
935 if (!NT_STATUS_IS_OK(status)) {
936 printf("auth_generic_set_domain returned %s\n", nt_errstr(status));
937 return false;
940 status = auth_generic_set_password(auth_generic_state, password);
941 if (!NT_STATUS_IS_OK(status)) {
942 printf("auth_generic_set_password returned %s\n", nt_errstr(status));
943 return false;
946 status = auth_generic_client_start(auth_generic_state, GENSEC_OID_NTLMSSP);
947 if (!NT_STATUS_IS_OK(status)) {
948 printf("auth_generic_client_start returned %s\n", nt_errstr(status));
949 return false;
952 ev = samba_tevent_context_init(talloc_tos());
953 if (ev == NULL) {
954 printf("samba_tevent_context_init() returned NULL\n");
955 return false;
958 status = gensec_update(auth_generic_state->gensec_security,
959 talloc_tos(), data_blob_null, &in_blob);
960 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
961 printf("gensec_update returned %s\n", nt_errstr(status));
962 return false;
965 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
966 cli2->conn,
967 cli2->timeout,
968 cli2->smb2.session,
969 0x01, /* in_flags */
970 SMB2_CAP_DFS, /* in_capabilities */
971 0, /* in_channel */
972 0, /* in_previous_session_id */
973 &in_blob); /* in_security_buffer */
974 if (subreq == NULL) {
975 printf("smb2cli_session_setup_send() returned NULL\n");
976 return false;
979 ok = tevent_req_poll(subreq, ev);
980 if (!ok) {
981 printf("tevent_req_poll() returned false\n");
982 return false;
985 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
986 NULL, &out_blob);
987 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
988 printf("smb2cli_session_setup_recv returned %s\n",
989 nt_errstr(status));
990 return false;
993 status = gensec_update(auth_generic_state->gensec_security,
994 talloc_tos(), out_blob, &in_blob);
995 if (!NT_STATUS_IS_OK(status)) {
996 printf("auth_generic_update returned %s\n", nt_errstr(status));
997 return false;
1000 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
1001 cli2->conn,
1002 cli2->timeout,
1003 cli2->smb2.session,
1004 0x01, /* in_flags */
1005 SMB2_CAP_DFS, /* in_capabilities */
1006 0, /* in_channel */
1007 0, /* in_previous_session_id */
1008 &in_blob); /* in_security_buffer */
1009 if (subreq == NULL) {
1010 printf("smb2cli_session_setup_send() returned NULL\n");
1011 return false;
1014 ok = tevent_req_poll(subreq, ev);
1015 if (!ok) {
1016 printf("tevent_req_poll() returned false\n");
1017 return false;
1020 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
1021 &recv_iov, &out_blob);
1022 if (!NT_STATUS_IS_OK(status)) {
1023 printf("smb2cli_session_setup_recv returned %s\n",
1024 nt_errstr(status));
1025 return false;
1028 status = gensec_session_key(auth_generic_state->gensec_security, talloc_tos(),
1029 &channel_session_key);
1030 if (!NT_STATUS_IS_OK(status)) {
1031 printf("gensec_session_key returned %s\n",
1032 nt_errstr(status));
1033 return false;
1036 status = smb2cli_session_set_channel_key(cli2->smb2.session,
1037 channel_session_key,
1038 recv_iov);
1039 if (!NT_STATUS_IS_OK(status)) {
1040 printf("smb2cli_session_set_channel_key %s\n", nt_errstr(status));
1041 return false;
1044 status = smb2cli_session_create_channel(cli3,
1045 cli1->smb2.session,
1046 cli3->conn,
1047 &cli3->smb2.session);
1048 if (!NT_STATUS_IS_OK(status)) {
1049 printf("smb2cli_session_create_channel returned %s\n",
1050 nt_errstr(status));
1051 return false;
1054 status = auth_generic_client_prepare(talloc_tos(), &auth_generic_state);
1055 if (!NT_STATUS_IS_OK(status)) {
1056 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status));
1057 return false;
1060 gensec_want_feature(auth_generic_state->gensec_security,
1061 GENSEC_FEATURE_SESSION_KEY);
1062 status = auth_generic_set_username(auth_generic_state, username);
1063 if (!NT_STATUS_IS_OK(status)) {
1064 printf("auth_generic_set_username returned %s\n", nt_errstr(status));
1065 return false;
1068 status = auth_generic_set_domain(auth_generic_state, workgroup);
1069 if (!NT_STATUS_IS_OK(status)) {
1070 printf("auth_generic_set_domain returned %s\n", nt_errstr(status));
1071 return false;
1074 status = auth_generic_set_password(auth_generic_state, password);
1075 if (!NT_STATUS_IS_OK(status)) {
1076 printf("auth_generic_set_password returned %s\n", nt_errstr(status));
1077 return false;
1080 status = auth_generic_client_start(auth_generic_state, GENSEC_OID_NTLMSSP);
1081 if (!NT_STATUS_IS_OK(status)) {
1082 printf("auth_generic_client_start returned %s\n", nt_errstr(status));
1083 return false;
1086 status = gensec_update(auth_generic_state->gensec_security,
1087 talloc_tos(), data_blob_null, &in_blob);
1088 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
1089 printf("gensec_update returned %s\n", nt_errstr(status));
1090 return false;
1093 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
1094 cli3->conn,
1095 cli3->timeout,
1096 cli3->smb2.session,
1097 0x01, /* in_flags */
1098 SMB2_CAP_DFS, /* in_capabilities */
1099 0, /* in_channel */
1100 0, /* in_previous_session_id */
1101 &in_blob); /* in_security_buffer */
1102 if (subreq == NULL) {
1103 printf("smb2cli_session_setup_send() returned NULL\n");
1104 return false;
1107 ok = tevent_req_poll(subreq, ev);
1108 if (!ok) {
1109 printf("tevent_req_poll() returned false\n");
1110 return false;
1113 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
1114 NULL, &out_blob);
1115 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
1116 printf("smb2cli_session_setup_recv returned %s\n",
1117 nt_errstr(status));
1118 return false;
1121 status = gensec_update(auth_generic_state->gensec_security,
1122 talloc_tos(), out_blob, &in_blob);
1123 if (!NT_STATUS_IS_OK(status)) {
1124 printf("auth_generic_update returned %s\n", nt_errstr(status));
1125 return false;
1128 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
1129 cli3->conn,
1130 cli3->timeout,
1131 cli3->smb2.session,
1132 0x01, /* in_flags */
1133 SMB2_CAP_DFS, /* in_capabilities */
1134 0, /* in_channel */
1135 0, /* in_previous_session_id */
1136 &in_blob); /* in_security_buffer */
1137 if (subreq == NULL) {
1138 printf("smb2cli_session_setup_send() returned NULL\n");
1139 return false;
1142 ok = tevent_req_poll(subreq, ev);
1143 if (!ok) {
1144 printf("tevent_req_poll() returned false\n");
1145 return false;
1148 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
1149 &recv_iov, &out_blob);
1150 if (!NT_STATUS_IS_OK(status)) {
1151 printf("smb2cli_session_setup_recv returned %s\n",
1152 nt_errstr(status));
1153 return false;
1156 status = gensec_session_key(auth_generic_state->gensec_security, talloc_tos(),
1157 &channel_session_key);
1158 if (!NT_STATUS_IS_OK(status)) {
1159 printf("gensec_session_key returned %s\n",
1160 nt_errstr(status));
1161 return false;
1164 status = smb2cli_session_set_channel_key(cli3->smb2.session,
1165 channel_session_key,
1166 recv_iov);
1167 if (!NT_STATUS_IS_OK(status)) {
1168 printf("smb2cli_session_set_channel_key %s\n", nt_errstr(status));
1169 return false;
1172 status = smb2cli_create(cli2->conn, cli2->timeout, cli2->smb2.session,
1173 cli1->smb2.tcon, "multi-channel.txt",
1174 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1175 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1176 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
1177 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
1178 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1179 FILE_CREATE, /* create_disposition, */
1180 FILE_DELETE_ON_CLOSE, /* create_options, */
1181 NULL, /* smb2_create_blobs *blobs */
1182 &fid_persistent,
1183 &fid_volatile,
1184 NULL);
1185 if (!NT_STATUS_IS_OK(status)) {
1186 printf("smb2cli_create on cli2 %s\n", nt_errstr(status));
1187 return false;
1190 status = smb2cli_write(cli1->conn, cli1->timeout, cli1->smb2.session,
1191 cli1->smb2.tcon, strlen(hello), 0, fid_persistent,
1192 fid_volatile, 0, 0, (const uint8_t *)hello, NULL);
1193 if (!NT_STATUS_IS_OK(status)) {
1194 printf("smb2cli_write returned %s\n", nt_errstr(status));
1195 return false;
1198 status = smb2cli_flush(cli2->conn, cli2->timeout, cli2->smb2.session,
1199 cli1->smb2.tcon, fid_persistent, fid_volatile);
1200 if (!NT_STATUS_IS_OK(status)) {
1201 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1202 return false;
1205 status = smb2cli_flush(cli1->conn, cli1->timeout, cli1->smb2.session,
1206 cli1->smb2.tcon, fid_persistent, fid_volatile);
1207 if (!NT_STATUS_IS_OK(status)) {
1208 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1209 return false;
1212 status = smb2cli_flush(cli3->conn, cli3->timeout, cli3->smb2.session,
1213 cli1->smb2.tcon, fid_persistent, fid_volatile);
1214 if (!NT_STATUS_IS_OK(status)) {
1215 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1216 return false;
1219 status = smb2cli_read(cli2->conn, cli2->timeout, cli2->smb2.session,
1220 cli1->smb2.tcon, 0x10000, 0, fid_persistent,
1221 fid_volatile, 2, 0,
1222 talloc_tos(), &result, &nread);
1223 if (!NT_STATUS_IS_OK(status)) {
1224 printf("smb2cli_read returned %s\n", nt_errstr(status));
1225 return false;
1228 if (nread != strlen(hello)) {
1229 printf("smb2cli_read returned %d bytes, expected %d\n",
1230 (int)nread, (int)strlen(hello));
1231 return false;
1234 if (memcmp(hello, result, nread) != 0) {
1235 printf("smb2cli_read returned '%s', expected '%s'\n",
1236 result, hello);
1237 return false;
1240 status = auth_generic_client_prepare(talloc_tos(), &auth_generic_state);
1241 if (!NT_STATUS_IS_OK(status)) {
1242 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status));
1243 return false;
1246 gensec_want_feature(auth_generic_state->gensec_security,
1247 GENSEC_FEATURE_SESSION_KEY);
1248 status = auth_generic_set_username(auth_generic_state, username);
1249 if (!NT_STATUS_IS_OK(status)) {
1250 printf("auth_generic_set_username returned %s\n", nt_errstr(status));
1251 return false;
1254 status = auth_generic_set_domain(auth_generic_state, workgroup);
1255 if (!NT_STATUS_IS_OK(status)) {
1256 printf("auth_generic_set_domain returned %s\n", nt_errstr(status));
1257 return false;
1260 status = auth_generic_set_password(auth_generic_state, password);
1261 if (!NT_STATUS_IS_OK(status)) {
1262 printf("auth_generic_set_password returned %s\n", nt_errstr(status));
1263 return false;
1266 status = auth_generic_client_start(auth_generic_state, GENSEC_OID_NTLMSSP);
1267 if (!NT_STATUS_IS_OK(status)) {
1268 printf("auth_generic_client_start returned %s\n", nt_errstr(status));
1269 return false;
1272 status = gensec_update(auth_generic_state->gensec_security,
1273 talloc_tos(), data_blob_null, &in_blob);
1274 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
1275 printf("gensec_update returned %s\n", nt_errstr(status));
1276 return false;
1279 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
1280 cli3->conn,
1281 cli3->timeout,
1282 cli3->smb2.session,
1283 0x0, /* in_flags */
1284 SMB2_CAP_DFS, /* in_capabilities */
1285 0, /* in_channel */
1286 0, /* in_previous_session_id */
1287 &in_blob); /* in_security_buffer */
1288 if (subreq == NULL) {
1289 printf("smb2cli_session_setup_send() returned NULL\n");
1290 return false;
1293 ok = tevent_req_poll(subreq, ev);
1294 if (!ok) {
1295 printf("tevent_req_poll() returned false\n");
1296 return false;
1299 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
1300 NULL, &out_blob);
1301 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
1302 printf("smb2cli_session_setup_recv returned %s\n",
1303 nt_errstr(status));
1304 return false;
1307 status = gensec_update(auth_generic_state->gensec_security,
1308 talloc_tos(), out_blob, &in_blob);
1309 if (!NT_STATUS_IS_OK(status)) {
1310 printf("auth_generic_update returned %s\n", nt_errstr(status));
1311 return false;
1314 status = smb2cli_flush(cli1->conn, cli1->timeout, cli1->smb2.session,
1315 cli1->smb2.tcon, fid_persistent, fid_volatile);
1316 if (!NT_STATUS_IS_OK(status)) {
1317 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1318 return false;
1321 status = smb2cli_flush(cli2->conn, cli2->timeout, cli2->smb2.session,
1322 cli1->smb2.tcon, fid_persistent, fid_volatile);
1323 if (!NT_STATUS_IS_OK(status)) {
1324 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1325 return false;
1328 status = smb2cli_flush(cli3->conn, cli3->timeout, cli3->smb2.session,
1329 cli1->smb2.tcon, fid_persistent, fid_volatile);
1330 if (!NT_STATUS_IS_OK(status)) {
1331 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1332 return false;
1335 status = smb2cli_create(cli1->conn, cli1->timeout, cli1->smb2.session,
1336 cli1->smb2.tcon, "multi-channel-invalid.txt",
1337 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1338 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1339 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
1340 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
1341 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1342 FILE_CREATE, /* create_disposition, */
1343 FILE_DELETE_ON_CLOSE, /* create_options, */
1344 NULL, /* smb2_create_blobs *blobs */
1345 &fid_persistent,
1346 &fid_volatile,
1347 NULL);
1348 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1349 printf("smb2cli_create %s\n", nt_errstr(status));
1350 return false;
1353 status = smb2cli_create(cli2->conn, cli2->timeout, cli2->smb2.session,
1354 cli1->smb2.tcon, "multi-channel-invalid.txt",
1355 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1356 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1357 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
1358 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
1359 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1360 FILE_CREATE, /* create_disposition, */
1361 FILE_DELETE_ON_CLOSE, /* create_options, */
1362 NULL, /* smb2_create_blobs *blobs */
1363 &fid_persistent,
1364 &fid_volatile,
1365 NULL);
1366 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1367 printf("smb2cli_create %s\n", nt_errstr(status));
1368 return false;
1371 status = smb2cli_create(cli3->conn, cli3->timeout, cli3->smb2.session,
1372 cli1->smb2.tcon, "multi-channel-invalid.txt",
1373 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1374 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1375 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
1376 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
1377 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1378 FILE_CREATE, /* create_disposition, */
1379 FILE_DELETE_ON_CLOSE, /* create_options, */
1380 NULL, /* smb2_create_blobs *blobs */
1381 &fid_persistent,
1382 &fid_volatile,
1383 NULL);
1384 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1385 printf("smb2cli_create %s\n", nt_errstr(status));
1386 return false;
1389 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
1390 cli2->conn,
1391 cli2->timeout,
1392 cli2->smb2.session,
1393 0x0, /* in_flags */
1394 SMB2_CAP_DFS, /* in_capabilities */
1395 0, /* in_channel */
1396 0, /* in_previous_session_id */
1397 &in_blob); /* in_security_buffer */
1398 if (subreq == NULL) {
1399 printf("smb2cli_session_setup_send() returned NULL\n");
1400 return false;
1403 ok = tevent_req_poll(subreq, ev);
1404 if (!ok) {
1405 printf("tevent_req_poll() returned false\n");
1406 return false;
1409 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
1410 &recv_iov, &out_blob);
1411 if (!NT_STATUS_IS_OK(status)) {
1412 printf("smb2cli_session_setup_recv returned %s\n",
1413 nt_errstr(status));
1414 return false;
1417 status = smb2cli_close(cli3->conn, cli3->timeout, cli3->smb2.session,
1418 cli1->smb2.tcon, 0, fid_persistent, fid_volatile);
1419 if (!NT_STATUS_IS_OK(status)) {
1420 printf("smb2cli_close returned %s\n", nt_errstr(status));
1421 return false;
1424 status = smb2cli_flush(cli3->conn, cli3->timeout, cli3->smb2.session,
1425 cli1->smb2.tcon, fid_persistent, fid_volatile);
1426 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED)) {
1427 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1428 return false;
1431 status = smb2cli_flush(cli2->conn, cli2->timeout, cli2->smb2.session,
1432 cli1->smb2.tcon, fid_persistent, fid_volatile);
1433 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED)) {
1434 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1435 return false;
1438 status = smb2cli_flush(cli1->conn, cli1->timeout, cli1->smb2.session,
1439 cli1->smb2.tcon, fid_persistent, fid_volatile);
1440 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED)) {
1441 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1442 return false;
1445 return true;
1448 bool run_smb2_session_reauth(int dummy)
1450 struct cli_state *cli;
1451 NTSTATUS status;
1452 bool ok;
1453 uint64_t fid_persistent, fid_volatile;
1454 uint64_t dir_persistent, dir_volatile;
1455 uint8_t *dir_data;
1456 uint32_t dir_data_length;
1457 struct tevent_context *ev;
1458 struct tevent_req *subreq;
1459 DATA_BLOB in_blob = data_blob_null;
1460 DATA_BLOB out_blob;
1461 DATA_BLOB in_input_buffer;
1462 DATA_BLOB out_output_buffer;
1463 uint8_t in_file_info_class;
1464 struct auth_generic_state *auth_generic_state;
1465 struct iovec *recv_iov;
1466 uint32_t saved_tid;
1467 struct smbXcli_tcon *saved_tcon;
1469 printf("Starting SMB2-SESSION_REAUTH\n");
1471 if (!torture_init_connection(&cli)) {
1472 return false;
1476 * PROTOCOL_SMB2_22 has a bug in win8pre0
1477 * it behaves like PROTOCOL_SMB2_02
1478 * and returns NT_STATUS_REQUEST_NOT_ACCEPTED,
1479 * while it allows it on PROTOCOL_SMB2_02.
1481 status = smbXcli_negprot(cli->conn, cli->timeout,
1482 PROTOCOL_SMB2_10, PROTOCOL_SMB2_10);
1483 if (!NT_STATUS_IS_OK(status)) {
1484 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
1485 return false;
1488 status = cli_session_setup(cli, username,
1489 password, strlen(password),
1490 password, strlen(password),
1491 workgroup);
1492 if (!NT_STATUS_IS_OK(status)) {
1493 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status));
1494 return false;
1497 status = cli_tree_connect(cli, share, "?????", "", 0);
1498 if (!NT_STATUS_IS_OK(status)) {
1499 printf("cli_tree_connect returned %s\n", nt_errstr(status));
1500 return false;
1503 status = smb2cli_create(cli->conn, cli->timeout, cli->smb2.session,
1504 cli->smb2.tcon, "session-reauth.txt",
1505 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1506 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1507 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
1508 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
1509 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1510 FILE_CREATE, /* create_disposition, */
1511 FILE_DELETE_ON_CLOSE, /* create_options, */
1512 NULL, /* smb2_create_blobs *blobs */
1513 &fid_persistent,
1514 &fid_volatile,
1515 NULL);
1516 if (!NT_STATUS_IS_OK(status)) {
1517 printf("smb2cli_create %s\n", nt_errstr(status));
1518 return false;
1521 status = smb2cli_create(cli->conn, cli->timeout, cli->smb2.session,
1522 cli->smb2.tcon, "",
1523 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1524 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1525 SEC_STD_SYNCHRONIZE|
1526 SEC_DIR_LIST|
1527 SEC_DIR_READ_ATTRIBUTE, /* desired_access, */
1528 0, /* file_attributes, */
1529 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1530 FILE_OPEN, /* create_disposition, */
1531 FILE_SYNCHRONOUS_IO_NONALERT|FILE_DIRECTORY_FILE, /* create_options, */
1532 NULL, /* smb2_create_blobs *blobs */
1533 &dir_persistent,
1534 &dir_volatile,
1535 NULL);
1536 if (!NT_STATUS_IS_OK(status)) {
1537 printf("smb2cli_create returned %s\n", nt_errstr(status));
1538 return false;
1541 status = smb2cli_query_directory(
1542 cli->conn, cli->timeout, cli->smb2.session, cli->smb2.tcon,
1543 1, 0x3, 0, dir_persistent, dir_volatile,
1544 "session-reauth.txt", 0xffff,
1545 talloc_tos(), &dir_data, &dir_data_length);
1546 if (!NT_STATUS_IS_OK(status)) {
1547 printf("smb2cli_query_directory returned %s\n", nt_errstr(status));
1548 return false;
1551 status = auth_generic_client_prepare(talloc_tos(), &auth_generic_state);
1552 if (!NT_STATUS_IS_OK(status)) {
1553 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status));
1554 return false;
1557 gensec_want_feature(auth_generic_state->gensec_security,
1558 GENSEC_FEATURE_SESSION_KEY);
1559 status = auth_generic_set_username(auth_generic_state, username);
1560 if (!NT_STATUS_IS_OK(status)) {
1561 printf("auth_generic_set_username returned %s\n", nt_errstr(status));
1562 return false;
1565 status = auth_generic_set_domain(auth_generic_state, workgroup);
1566 if (!NT_STATUS_IS_OK(status)) {
1567 printf("auth_generic_set_domain returned %s\n", nt_errstr(status));
1568 return false;
1571 status = auth_generic_set_password(auth_generic_state, password);
1572 if (!NT_STATUS_IS_OK(status)) {
1573 printf("auth_generic_set_password returned %s\n", nt_errstr(status));
1574 return false;
1577 status = auth_generic_client_start(auth_generic_state, GENSEC_OID_NTLMSSP);
1578 if (!NT_STATUS_IS_OK(status)) {
1579 printf("auth_generic_client_start returned %s\n", nt_errstr(status));
1580 return false;
1583 ev = samba_tevent_context_init(talloc_tos());
1584 if (ev == NULL) {
1585 printf("samba_tevent_context_init() returned NULL\n");
1586 return false;
1589 status = gensec_update(auth_generic_state->gensec_security,
1590 talloc_tos(), data_blob_null, &in_blob);
1591 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
1592 printf("gensec_update returned %s\n", nt_errstr(status));
1593 return false;
1596 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
1597 cli->conn,
1598 cli->timeout,
1599 cli->smb2.session,
1600 0x0, /* in_flags */
1601 SMB2_CAP_DFS, /* in_capabilities */
1602 0, /* in_channel */
1603 0, /* in_previous_session_id */
1604 &in_blob); /* in_security_buffer */
1605 if (subreq == NULL) {
1606 printf("smb2cli_session_setup_send() returned NULL\n");
1607 return false;
1610 ok = tevent_req_poll(subreq, ev);
1611 if (!ok) {
1612 printf("tevent_req_poll() returned false\n");
1613 return false;
1616 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
1617 NULL, &out_blob);
1618 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
1619 printf("smb2cli_session_setup_recv returned %s\n",
1620 nt_errstr(status));
1621 return false;
1624 status = gensec_update(auth_generic_state->gensec_security,
1625 talloc_tos(), out_blob, &in_blob);
1626 if (!NT_STATUS_IS_OK(status)) {
1627 printf("auth_generic_update returned %s\n", nt_errstr(status));
1628 return false;
1631 status = smb2cli_flush(cli->conn, cli->timeout, cli->smb2.session,
1632 cli->smb2.tcon, fid_persistent, fid_volatile);
1633 if (!NT_STATUS_IS_OK(status)) {
1634 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1635 return false;
1638 status = smb2cli_query_directory(
1639 cli->conn, cli->timeout, cli->smb2.session, cli->smb2.tcon,
1640 1, 0x3, 0, dir_persistent, dir_volatile,
1641 "session-reauth.txt", 0xffff,
1642 talloc_tos(), &dir_data, &dir_data_length);
1643 if (!NT_STATUS_IS_OK(status)) {
1644 printf("smb2cli_query_directory returned %s\n", nt_errstr(status));
1645 return false;
1649 * query_info seems to be a path based operation on Windows...
1651 status = smb2cli_query_info(cli->conn,
1652 cli->timeout,
1653 cli->smb2.session,
1654 cli->smb2.tcon,
1655 SMB2_GETINFO_SECURITY,
1656 0, /* in_file_info_class */
1657 1024, /* in_max_output_length */
1658 NULL, /* in_input_buffer */
1659 SECINFO_OWNER, /* in_additional_info */
1660 0, /* in_flags */
1661 fid_persistent,
1662 fid_volatile,
1663 talloc_tos(),
1664 &out_output_buffer);
1665 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1666 printf("smb2cli_query_info (security) returned %s\n", nt_errstr(status));
1667 return false;
1670 in_file_info_class = SMB_FILE_POSITION_INFORMATION - 1000;
1671 status = smb2cli_query_info(cli->conn,
1672 cli->timeout,
1673 cli->smb2.session,
1674 cli->smb2.tcon,
1675 SMB2_GETINFO_FILE,
1676 in_file_info_class,
1677 1024, /* in_max_output_length */
1678 NULL, /* in_input_buffer */
1679 0, /* in_additional_info */
1680 0, /* in_flags */
1681 fid_persistent,
1682 fid_volatile,
1683 talloc_tos(),
1684 &out_output_buffer);
1685 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1686 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status));
1687 return false;
1690 in_input_buffer = data_blob_talloc(talloc_tos(), NULL, 8);
1691 SBVAL(in_input_buffer.data, 0, 512);
1693 in_file_info_class = SMB_FILE_POSITION_INFORMATION - 1000;
1694 status = smb2cli_set_info(cli->conn,
1695 cli->timeout,
1696 cli->smb2.session,
1697 cli->smb2.tcon,
1698 SMB2_GETINFO_FILE,
1699 in_file_info_class,
1700 &in_input_buffer,
1701 0, /* in_additional_info */
1702 fid_persistent,
1703 fid_volatile);
1704 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1705 printf("smb2cli_set_info (position) returned %s\n", nt_errstr(status));
1706 return false;
1709 status = smb2cli_create(cli->conn, cli->timeout, cli->smb2.session,
1710 cli->smb2.tcon, "session-reauth-invalid.txt",
1711 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1712 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1713 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
1714 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
1715 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1716 FILE_CREATE, /* create_disposition, */
1717 FILE_DELETE_ON_CLOSE, /* create_options, */
1718 NULL, /* smb2_create_blobs *blobs */
1719 &fid_persistent,
1720 &fid_volatile,
1721 NULL);
1722 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1723 printf("smb2cli_create %s\n", nt_errstr(status));
1724 return false;
1727 status = smb2cli_create(cli->conn, cli->timeout, cli->smb2.session,
1728 cli->smb2.tcon, "",
1729 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1730 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1731 SEC_STD_SYNCHRONIZE|
1732 SEC_DIR_LIST|
1733 SEC_DIR_READ_ATTRIBUTE, /* desired_access, */
1734 0, /* file_attributes, */
1735 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1736 FILE_OPEN, /* create_disposition, */
1737 FILE_SYNCHRONOUS_IO_NONALERT|FILE_DIRECTORY_FILE, /* create_options, */
1738 NULL, /* smb2_create_blobs *blobs */
1739 &dir_persistent,
1740 &dir_volatile,
1741 NULL);
1742 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1743 printf("smb2cli_create returned %s\n", nt_errstr(status));
1744 return false;
1747 saved_tid = smb2cli_tcon_current_id(cli->smb2.tcon);
1748 saved_tcon = cli->smb2.tcon;
1749 cli->smb2.tcon = smbXcli_tcon_create(cli);
1750 smb2cli_tcon_set_values(cli->smb2.tcon,
1751 NULL, /* session */
1752 saved_tid,
1753 0, /* type */
1754 0, /* flags */
1755 0, /* capabilities */
1756 0 /* maximal_access */);
1757 status = cli_tree_connect(cli, share, "?????", "", 0);
1758 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1759 printf("cli_tree_connect returned %s\n", nt_errstr(status));
1760 return false;
1762 talloc_free(cli->smb2.tcon);
1763 cli->smb2.tcon = saved_tcon;
1765 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
1766 cli->conn,
1767 cli->timeout,
1768 cli->smb2.session,
1769 0x0, /* in_flags */
1770 SMB2_CAP_DFS, /* in_capabilities */
1771 0, /* in_channel */
1772 0, /* in_previous_session_id */
1773 &in_blob); /* in_security_buffer */
1774 if (subreq == NULL) {
1775 printf("smb2cli_session_setup_send() returned NULL\n");
1776 return false;
1779 ok = tevent_req_poll(subreq, ev);
1780 if (!ok) {
1781 printf("tevent_req_poll() returned false\n");
1782 return false;
1785 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
1786 &recv_iov, &out_blob);
1787 if (!NT_STATUS_IS_OK(status)) {
1788 printf("smb2cli_session_setup_recv returned %s\n",
1789 nt_errstr(status));
1790 return false;
1793 status = smb2cli_flush(cli->conn, cli->timeout, cli->smb2.session,
1794 cli->smb2.tcon, fid_persistent, fid_volatile);
1795 if (!NT_STATUS_IS_OK(status)) {
1796 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1797 return false;
1800 status = smb2cli_query_info(cli->conn,
1801 cli->timeout,
1802 cli->smb2.session,
1803 cli->smb2.tcon,
1804 SMB2_GETINFO_SECURITY,
1805 0, /* in_file_info_class */
1806 1024, /* in_max_output_length */
1807 NULL, /* in_input_buffer */
1808 SECINFO_OWNER, /* in_additional_info */
1809 0, /* in_flags */
1810 fid_persistent,
1811 fid_volatile,
1812 talloc_tos(),
1813 &out_output_buffer);
1814 if (!NT_STATUS_IS_OK(status)) {
1815 printf("smb2cli_query_info (security) returned %s\n", nt_errstr(status));
1816 return false;
1819 in_file_info_class = SMB_FILE_POSITION_INFORMATION - 1000;
1820 status = smb2cli_query_info(cli->conn,
1821 cli->timeout,
1822 cli->smb2.session,
1823 cli->smb2.tcon,
1824 SMB2_GETINFO_FILE,
1825 in_file_info_class,
1826 1024, /* in_max_output_length */
1827 NULL, /* in_input_buffer */
1828 0, /* in_additional_info */
1829 0, /* in_flags */
1830 fid_persistent,
1831 fid_volatile,
1832 talloc_tos(),
1833 &out_output_buffer);
1834 if (!NT_STATUS_IS_OK(status)) {
1835 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status));
1836 return false;
1839 in_input_buffer = data_blob_talloc(talloc_tos(), NULL, 8);
1840 SBVAL(in_input_buffer.data, 0, 512);
1842 in_file_info_class = SMB_FILE_POSITION_INFORMATION - 1000;
1843 status = smb2cli_set_info(cli->conn,
1844 cli->timeout,
1845 cli->smb2.session,
1846 cli->smb2.tcon,
1847 SMB2_GETINFO_FILE,
1848 in_file_info_class,
1849 &in_input_buffer,
1850 0, /* in_additional_info */
1851 fid_persistent,
1852 fid_volatile);
1853 if (!NT_STATUS_IS_OK(status)) {
1854 printf("smb2cli_set_info (position) returned %s\n", nt_errstr(status));
1855 return false;
1858 in_file_info_class = SMB_FILE_POSITION_INFORMATION - 1000;
1859 status = smb2cli_query_info(cli->conn,
1860 cli->timeout,
1861 cli->smb2.session,
1862 cli->smb2.tcon,
1863 SMB2_GETINFO_FILE,
1864 in_file_info_class,
1865 1024, /* in_max_output_length */
1866 NULL, /* in_input_buffer */
1867 0, /* in_additional_info */
1868 0, /* in_flags */
1869 fid_persistent,
1870 fid_volatile,
1871 talloc_tos(),
1872 &out_output_buffer);
1873 if (!NT_STATUS_IS_OK(status)) {
1874 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status));
1875 return false;
1878 status = smb2cli_close(cli->conn, cli->timeout, cli->smb2.session,
1879 cli->smb2.tcon, 0, fid_persistent, fid_volatile);
1880 if (!NT_STATUS_IS_OK(status)) {
1881 printf("smb2cli_close returned %s\n", nt_errstr(status));
1882 return false;
1885 status = smb2cli_create(cli->conn, cli->timeout, cli->smb2.session,
1886 cli->smb2.tcon, "session-reauth.txt",
1887 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1888 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1889 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
1890 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
1891 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1892 FILE_CREATE, /* create_disposition, */
1893 FILE_DELETE_ON_CLOSE, /* create_options, */
1894 NULL, /* smb2_create_blobs *blobs */
1895 &fid_persistent,
1896 &fid_volatile,
1897 NULL);
1898 if (!NT_STATUS_IS_OK(status)) {
1899 printf("smb2cli_create %s\n", nt_errstr(status));
1900 return false;
1903 status = smb2cli_query_directory(
1904 cli->conn, cli->timeout, cli->smb2.session, cli->smb2.tcon,
1905 1, 0x3, 0, dir_persistent, dir_volatile,
1906 "session-reauth.txt", 0xffff,
1907 talloc_tos(), &dir_data, &dir_data_length);
1908 if (!NT_STATUS_IS_OK(status)) {
1909 printf("smb2cli_query_directory returned %s\n", nt_errstr(status));
1910 return false;
1913 status = smb2cli_close(cli->conn, cli->timeout, cli->smb2.session,
1914 cli->smb2.tcon, 0, dir_persistent, dir_volatile);
1915 if (!NT_STATUS_IS_OK(status)) {
1916 printf("smb2cli_close returned %s\n", nt_errstr(status));
1917 return false;
1920 status = smb2cli_close(cli->conn, cli->timeout, cli->smb2.session,
1921 cli->smb2.tcon, 0, fid_persistent, fid_volatile);
1922 if (!NT_STATUS_IS_OK(status)) {
1923 printf("smb2cli_close returned %s\n", nt_errstr(status));
1924 return false;
1927 saved_tid = smb2cli_tcon_current_id(cli->smb2.tcon);
1928 saved_tcon = cli->smb2.tcon;
1929 cli->smb2.tcon = smbXcli_tcon_create(cli);
1930 smb2cli_tcon_set_values(cli->smb2.tcon,
1931 NULL, /* session */
1932 saved_tid,
1933 0, /* type */
1934 0, /* flags */
1935 0, /* capabilities */
1936 0 /* maximal_access */);
1937 status = cli_tree_connect(cli, share, "?????", "", 0);
1938 if (!NT_STATUS_IS_OK(status)) {
1939 printf("cli_tree_connect returned %s\n", nt_errstr(status));
1940 return false;
1942 talloc_free(cli->smb2.tcon);
1943 cli->smb2.tcon = saved_tcon;
1945 return true;