torture-krb5: Do not do post-recv checks if the packet recv failed
[Samba.git] / source3 / torture / test_smb2.c
blob301c6e7014c8ad0e8bd1715a6ca806d2639855be
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 "libcli/security/security.h"
26 #include "libsmb/proto.h"
27 #include "auth/gensec/gensec.h"
28 #include "auth_generic.h"
29 #include "../librpc/ndr/libndr.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, NULL, 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, NULL, 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->conn,
184 cli->timeout,
185 cli->smb2.session,
186 cli->smb2.tcon);
187 if (!NT_STATUS_IS_OK(status)) {
188 printf("smb2cli_tdis returned %s\n", nt_errstr(status));
189 return false;
191 talloc_free(cli->smb2.tcon);
192 cli->smb2.tcon = saved_tcon;
194 status = smb2cli_tdis(cli->conn,
195 cli->timeout,
196 cli->smb2.session,
197 cli->smb2.tcon);
198 if (!NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED)) {
199 printf("2nd smb2cli_tdis returned %s\n", nt_errstr(status));
200 return false;
203 saved_uid = smb2cli_session_current_id(cli->smb2.session);
204 status = smb2cli_logoff(cli->conn, cli->timeout, cli->smb2.session);
205 if (!NT_STATUS_IS_OK(status)) {
206 printf("smb2cli_logoff returned %s\n", nt_errstr(status));
207 return false;
210 cli->smb2.session = smbXcli_session_create(cli, cli->conn);
211 if (cli->smb2.session == NULL) {
212 printf("smbXcli_session_create() returned NULL\n");
213 return false;
216 smb2cli_session_set_id_and_flags(cli->smb2.session, saved_uid, 0);
218 status = smb2cli_logoff(cli->conn, cli->timeout, cli->smb2.session);
219 if (!NT_STATUS_EQUAL(status, NT_STATUS_USER_SESSION_DELETED)) {
220 printf("2nd smb2cli_logoff returned %s\n", nt_errstr(status));
221 return false;
224 return true;
227 bool run_smb2_negprot(int dummy)
229 struct cli_state *cli;
230 NTSTATUS status;
231 enum protocol_types protocol;
232 const char *name = NULL;
234 printf("Starting SMB2-NEGPROT\n");
236 if (!torture_init_connection(&cli)) {
237 return false;
240 status = smbXcli_negprot(cli->conn, cli->timeout,
241 PROTOCOL_CORE, PROTOCOL_LATEST);
242 if (!NT_STATUS_IS_OK(status)) {
243 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
244 return false;
247 protocol = smbXcli_conn_protocol(cli->conn);
249 switch (protocol) {
250 case PROTOCOL_SMB2_02:
251 name = "SMB2_02";
252 break;
253 case PROTOCOL_SMB2_10:
254 name = "SMB2_10";
255 break;
256 case PROTOCOL_SMB2_22:
257 name = "SMB2_22";
258 break;
259 case PROTOCOL_SMB2_24:
260 name = "SMB2_24";
261 break;
262 case PROTOCOL_SMB3_00:
263 name = "SMB3_00";
264 break;
265 case PROTOCOL_SMB3_02:
266 name = "SMB3_02";
267 break;
268 case PROTOCOL_SMB3_10:
269 name = "SMB3_10";
270 break;
271 default:
272 break;
275 if (name) {
276 printf("Server supports %s\n", name);
277 } else {
278 printf("Server DOES NOT support SMB2\n");
279 return false;
282 status = smbXcli_negprot(cli->conn, cli->timeout,
283 protocol, protocol);
284 if (!NT_STATUS_EQUAL(status, NT_STATUS_CONNECTION_RESET) &&
285 !NT_STATUS_EQUAL(status, NT_STATUS_CONNECTION_DISCONNECTED) &&
286 !NT_STATUS_EQUAL(status, NT_STATUS_CONNECTION_ABORTED)) {
287 printf("2nd smbXcli_negprot should disconnect - returned %s\n",
288 nt_errstr(status));
289 return false;
292 if (smbXcli_conn_is_connected(cli->conn)) {
293 printf("2nd smbXcli_negprot should disconnect "
294 "- still connected\n");
295 return false;
298 return true;
301 bool run_smb2_session_reconnect(int dummy)
303 struct cli_state *cli1;
304 struct cli_state *cli2;
305 NTSTATUS status;
306 bool ok;
307 uint64_t fid_persistent, fid_volatile;
308 struct tevent_context *ev;
309 struct tevent_req *subreq;
310 DATA_BLOB in_blob = data_blob_null;
311 DATA_BLOB out_blob;
312 DATA_BLOB session_key;
313 struct auth_generic_state *auth_generic_state;
314 struct iovec *recv_iov;
315 const char *hello = "Hello, world\n";
316 uint8_t *result;
317 uint32_t nread;
319 printf("Starting SMB2-SESSION-RECONNECT\n");
321 if (!torture_init_connection(&cli1)) {
322 return false;
325 status = smbXcli_negprot(cli1->conn, cli1->timeout,
326 PROTOCOL_SMB2_02, PROTOCOL_LATEST);
327 if (!NT_STATUS_IS_OK(status)) {
328 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
329 return false;
332 status = cli_session_setup(cli1, username,
333 password, strlen(password),
334 password, strlen(password),
335 workgroup);
336 if (!NT_STATUS_IS_OK(status)) {
337 printf("cli_session_setup returned %s\n", nt_errstr(status));
338 return false;
341 status = cli_tree_connect(cli1, share, "?????", "", 0);
342 if (!NT_STATUS_IS_OK(status)) {
343 printf("cli_tree_connect returned %s\n", nt_errstr(status));
344 return false;
347 status = smb2cli_create(cli1->conn, cli1->timeout, cli1->smb2.session,
348 cli1->smb2.tcon, "session-reconnect.txt",
349 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
350 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
351 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
352 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
353 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
354 FILE_CREATE, /* create_disposition, */
355 FILE_DELETE_ON_CLOSE, /* create_options, */
356 NULL, /* smb2_create_blobs *blobs */
357 &fid_persistent,
358 &fid_volatile,
359 NULL, NULL, NULL);
360 if (!NT_STATUS_IS_OK(status)) {
361 printf("smb2cli_create on cli1 %s\n", nt_errstr(status));
362 return false;
365 status = smb2cli_write(cli1->conn, cli1->timeout, cli1->smb2.session,
366 cli1->smb2.tcon, strlen(hello), 0, fid_persistent,
367 fid_volatile, 0, 0, (const uint8_t *)hello, NULL);
368 if (!NT_STATUS_IS_OK(status)) {
369 printf("smb2cli_write returned %s\n", nt_errstr(status));
370 return false;
373 status = smb2cli_flush(cli1->conn, cli1->timeout, cli1->smb2.session,
374 cli1->smb2.tcon, fid_persistent, fid_volatile);
375 if (!NT_STATUS_IS_OK(status)) {
376 printf("smb2cli_flush returned %s\n", nt_errstr(status));
377 return false;
380 status = smb2cli_read(cli1->conn, cli1->timeout, cli1->smb2.session,
381 cli1->smb2.tcon, 0x10000, 0, fid_persistent,
382 fid_volatile, 2, 0,
383 talloc_tos(), &result, &nread);
384 if (!NT_STATUS_IS_OK(status)) {
385 printf("smb2cli_read returned %s\n", nt_errstr(status));
386 return false;
389 if (nread != strlen(hello)) {
390 printf("smb2cli_read returned %d bytes, expected %d\n",
391 (int)nread, (int)strlen(hello));
392 return false;
395 if (memcmp(hello, result, nread) != 0) {
396 printf("smb2cli_read returned '%s', expected '%s'\n",
397 result, hello);
398 return false;
401 /* prepare second session */
403 if (!torture_init_connection(&cli2)) {
404 return false;
407 status = smbXcli_negprot(cli2->conn, cli2->timeout,
408 PROTOCOL_SMB2_02, PROTOCOL_LATEST);
409 if (!NT_STATUS_IS_OK(status)) {
410 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
411 return false;
414 status = auth_generic_client_prepare(talloc_tos(), &auth_generic_state);
415 if (!NT_STATUS_IS_OK(status)) {
416 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status));
417 return false;
420 gensec_want_feature(auth_generic_state->gensec_security,
421 GENSEC_FEATURE_SESSION_KEY);
422 status = auth_generic_set_username(auth_generic_state, username);
423 if (!NT_STATUS_IS_OK(status)) {
424 printf("auth_generic_set_username returned %s\n", nt_errstr(status));
425 return false;
428 status = auth_generic_set_domain(auth_generic_state, workgroup);
429 if (!NT_STATUS_IS_OK(status)) {
430 printf("auth_generic_set_domain returned %s\n", nt_errstr(status));
431 return false;
434 status = auth_generic_set_password(auth_generic_state, password);
435 if (!NT_STATUS_IS_OK(status)) {
436 printf("auth_generic_set_password returned %s\n", nt_errstr(status));
437 return false;
440 status = auth_generic_client_start(auth_generic_state, GENSEC_OID_NTLMSSP);
441 if (!NT_STATUS_IS_OK(status)) {
442 printf("auth_generic_client_start returned %s\n", nt_errstr(status));
443 return false;
446 ev = samba_tevent_context_init(talloc_tos());
447 if (ev == NULL) {
448 printf("samba_tevent_context_init() returned NULL\n");
449 return false;
452 status = gensec_update(auth_generic_state->gensec_security,
453 talloc_tos(), data_blob_null, &in_blob);
454 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
455 printf("gensec_update returned %s\n", nt_errstr(status));
456 return false;
459 cli2->smb2.session = smbXcli_session_create(cli2, cli2->conn);
461 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
462 cli2->conn,
463 cli2->timeout,
464 cli2->smb2.session,
465 0x0, /* in_flags */
466 SMB2_CAP_DFS, /* in_capabilities */
467 0, /* in_channel */
468 /* in_previous_session_id: */
469 smb2cli_session_current_id(cli1->smb2.session),
470 &in_blob); /* in_security_buffer */
471 if (subreq == NULL) {
472 printf("smb2cli_session_setup_send() returned NULL\n");
473 return false;
476 ok = tevent_req_poll(subreq, ev);
477 if (!ok) {
478 printf("tevent_req_poll() returned false\n");
479 return false;
482 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
483 NULL, &out_blob);
484 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
485 printf("smb2cli_session_setup_recv returned %s\n",
486 nt_errstr(status));
487 return false;
490 status = gensec_update(auth_generic_state->gensec_security,
491 talloc_tos(), out_blob, &in_blob);
492 if (!NT_STATUS_IS_OK(status)) {
493 printf("auth_generic_update returned %s\n", nt_errstr(status));
494 return false;
497 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
498 cli2->conn,
499 cli2->timeout,
500 cli2->smb2.session,
501 0x0, /* in_flags */
502 SMB2_CAP_DFS, /* in_capabilities */
503 0, /* in_channel */
504 /* in_previous_session_id: */
505 smb2cli_session_current_id(cli1->smb2.session),
506 &in_blob); /* in_security_buffer */
507 if (subreq == NULL) {
508 printf("smb2cli_session_setup_send() returned NULL\n");
509 return false;
512 ok = tevent_req_poll(subreq, ev);
513 if (!ok) {
514 printf("tevent_req_poll() returned false\n");
515 return false;
518 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
519 &recv_iov, &out_blob);
520 if (!NT_STATUS_IS_OK(status)) {
521 printf("smb2cli_session_setup_recv returned %s\n",
522 nt_errstr(status));
523 return false;
526 status = gensec_session_key(auth_generic_state->gensec_security, talloc_tos(),
527 &session_key);
528 if (!NT_STATUS_IS_OK(status)) {
529 printf("gensec_session_key returned %s\n",
530 nt_errstr(status));
531 return false;
534 /* check file operation on the old client */
536 status = smb2cli_flush(cli1->conn, cli1->timeout, cli1->smb2.session,
537 cli1->smb2.tcon, fid_persistent, fid_volatile);
538 if (!NT_STATUS_EQUAL(status, NT_STATUS_USER_SESSION_DELETED)) {
539 printf("smb2cli_flush returned %s\n", nt_errstr(status));
540 return false;
543 status = cli_tree_connect(cli1, share, "?????", "", 0);
544 if (!NT_STATUS_EQUAL(status, NT_STATUS_USER_SESSION_DELETED)) {
545 printf("cli_tree_connect returned %s\n", nt_errstr(status));
546 return false;
550 * checking file operations without signing.
551 * on w2k8r2 at least, flush, read and write also work the same way,
552 * while create gives ACCESS_DENIED without signing
554 status = smb2cli_flush(cli2->conn, cli2->timeout, cli2->smb2.session,
555 cli2->smb2.tcon, fid_persistent, fid_volatile);
556 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED) &&
557 !NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED))
559 printf("smb2cli_flush returned %s\n", nt_errstr(status));
560 return false;
563 status = smb2cli_write(cli2->conn, cli2->timeout, cli2->smb2.session,
564 cli2->smb2.tcon, strlen(hello), 0, fid_persistent,
565 fid_volatile, 0, 0, (const uint8_t *)hello, NULL);
566 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED) &&
567 !NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED))
569 printf("smb2cli_write returned %s\n", nt_errstr(status));
570 return false;
573 status = smb2cli_read(cli2->conn, cli2->timeout, cli2->smb2.session,
574 cli2->smb2.tcon, 0x10000, 0, fid_persistent,
575 fid_volatile, 2, 0,
576 talloc_tos(), &result, &nread);
577 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED) &&
578 !NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED))
580 printf("smb2cli_read returned %s\n", nt_errstr(status));
581 return false;
584 status = smb2cli_create(cli2->conn, cli2->timeout, cli2->smb2.session,
585 cli2->smb2.tcon, "session-reconnect.txt",
586 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
587 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
588 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
589 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
590 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
591 FILE_CREATE, /* create_disposition, */
592 FILE_DELETE_ON_CLOSE, /* create_options, */
593 NULL, /* smb2_create_blobs *blobs */
594 &fid_persistent,
595 &fid_volatile,
596 NULL, NULL, NULL);
597 if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED) &&
598 !NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED)) {
599 printf("smb2cli_create on cli2 %s\n", nt_errstr(status));
600 return false;
603 /* now grab the session key and try with signing */
605 status = smb2cli_session_set_session_key(cli2->smb2.session,
606 session_key,
607 recv_iov);
608 if (!NT_STATUS_IS_OK(status)) {
609 printf("smb2cli_session_set_session_key %s\n", nt_errstr(status));
610 return false;
613 /* the tid seems to be irrelevant at this stage */
615 status = smb2cli_flush(cli2->conn, cli2->timeout, cli2->smb2.session,
616 cli1->smb2.tcon, fid_persistent, fid_volatile);
617 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED) &&
618 !NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED))
620 printf("smb2cli_flush returned %s\n", nt_errstr(status));
621 return false;
624 status = smb2cli_write(cli2->conn, cli2->timeout, cli2->smb2.session,
625 cli1->smb2.tcon, strlen(hello), 0, fid_persistent,
626 fid_volatile, 0, 0, (const uint8_t *)hello, NULL);
627 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED) &&
628 !NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED))
630 printf("smb2cli_write returned %s\n", nt_errstr(status));
631 return false;
634 status = smb2cli_read(cli2->conn, cli2->timeout, cli2->smb2.session,
635 cli1->smb2.tcon, 0x10000, 0, fid_persistent,
636 fid_volatile, 2, 0,
637 talloc_tos(), &result, &nread);
638 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED) &&
639 !NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED))
641 printf("smb2cli_read returned %s\n", nt_errstr(status));
642 return false;
645 status = smb2cli_create(cli2->conn, cli2->timeout, cli2->smb2.session,
646 cli1->smb2.tcon, "session-reconnect.txt",
647 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
648 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
649 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
650 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
651 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
652 FILE_CREATE, /* create_disposition, */
653 FILE_DELETE_ON_CLOSE, /* create_options, */
654 NULL, /* smb2_create_blobs *blobs */
655 &fid_persistent,
656 &fid_volatile,
657 NULL, NULL, NULL);
658 if (!NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED) &&
659 !NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED))
661 printf("smb2cli_create on cli2 %s\n", nt_errstr(status));
662 return false;
665 /* now do a new tcon and test file calls again */
667 status = cli_tree_connect(cli2, share, "?????", "", 0);
668 if (!NT_STATUS_IS_OK(status)) {
669 printf("cli_tree_connect returned %s\n", nt_errstr(status));
670 return false;
673 status = smb2cli_create(cli2->conn, cli2->timeout, cli2->smb2.session,
674 cli2->smb2.tcon, "session-reconnect.txt",
675 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
676 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
677 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
678 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
679 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
680 FILE_CREATE, /* create_disposition, */
681 FILE_DELETE_ON_CLOSE, /* create_options, */
682 NULL, /* smb2_create_blobs *blobs */
683 &fid_persistent,
684 &fid_volatile,
685 NULL, NULL, NULL);
686 if (!NT_STATUS_IS_OK(status)) {
687 printf("smb2cli_create on cli2 %s\n", nt_errstr(status));
688 return false;
691 status = smb2cli_write(cli2->conn, cli2->timeout, cli2->smb2.session,
692 cli2->smb2.tcon, strlen(hello), 0, fid_persistent,
693 fid_volatile, 0, 0, (const uint8_t *)hello, NULL);
694 if (!NT_STATUS_IS_OK(status)) {
695 printf("smb2cli_write returned %s\n", nt_errstr(status));
696 return false;
699 status = smb2cli_flush(cli2->conn, cli2->timeout, cli2->smb2.session,
700 cli2->smb2.tcon, fid_persistent, fid_volatile);
701 if (!NT_STATUS_IS_OK(status)) {
702 printf("smb2cli_flush returned %s\n", nt_errstr(status));
703 return false;
706 status = smb2cli_read(cli2->conn, cli2->timeout, cli2->smb2.session,
707 cli2->smb2.tcon, 0x10000, 0, fid_persistent,
708 fid_volatile, 2, 0,
709 talloc_tos(), &result, &nread);
710 if (!NT_STATUS_IS_OK(status)) {
711 printf("smb2cli_read returned %s\n", nt_errstr(status));
712 return false;
715 if (nread != strlen(hello)) {
716 printf("smb2cli_read returned %d bytes, expected %d\n",
717 (int)nread, (int)strlen(hello));
718 return false;
721 if (memcmp(hello, result, nread) != 0) {
722 printf("smb2cli_read returned '%s', expected '%s'\n",
723 result, hello);
724 return false;
727 return true;
730 bool run_smb2_tcon_dependence(int dummy)
732 struct cli_state *cli;
733 NTSTATUS status;
734 uint64_t fid_persistent, fid_volatile;
735 const char *hello = "Hello, world\n";
736 uint8_t *result;
737 uint32_t nread;
738 struct smbXcli_tcon *tcon2;
739 uint32_t tcon2_id;
741 printf("Starting SMB2-TCON-DEPENDENCE\n");
743 if (!torture_init_connection(&cli)) {
744 return false;
747 status = smbXcli_negprot(cli->conn, cli->timeout,
748 PROTOCOL_SMB2_02, PROTOCOL_LATEST);
749 if (!NT_STATUS_IS_OK(status)) {
750 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
751 return false;
754 status = cli_session_setup(cli, username,
755 password, strlen(password),
756 password, strlen(password),
757 workgroup);
758 if (!NT_STATUS_IS_OK(status)) {
759 printf("cli_session_setup returned %s\n", nt_errstr(status));
760 return false;
763 status = cli_tree_connect(cli, share, "?????", "", 0);
764 if (!NT_STATUS_IS_OK(status)) {
765 printf("cli_tree_connect returned %s\n", nt_errstr(status));
766 return false;
769 status = smb2cli_create(cli->conn, cli->timeout, cli->smb2.session,
770 cli->smb2.tcon, "tcon_depedence.txt",
771 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
772 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
773 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
774 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
775 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
776 FILE_CREATE, /* create_disposition, */
777 FILE_DELETE_ON_CLOSE, /* create_options, */
778 NULL, /* smb2_create_blobs *blobs */
779 &fid_persistent,
780 &fid_volatile,
781 NULL, NULL, NULL);
782 if (!NT_STATUS_IS_OK(status)) {
783 printf("smb2cli_create on cli %s\n", nt_errstr(status));
784 return false;
787 status = smb2cli_write(cli->conn, cli->timeout, cli->smb2.session,
788 cli->smb2.tcon, strlen(hello), 0, fid_persistent,
789 fid_volatile, 0, 0, (const uint8_t *)hello, NULL);
790 if (!NT_STATUS_IS_OK(status)) {
791 printf("smb2cli_write returned %s\n", nt_errstr(status));
792 return false;
795 status = smb2cli_flush(cli->conn, cli->timeout, cli->smb2.session,
796 cli->smb2.tcon, fid_persistent, fid_volatile);
797 if (!NT_STATUS_IS_OK(status)) {
798 printf("smb2cli_flush returned %s\n", nt_errstr(status));
799 return false;
802 status = smb2cli_read(cli->conn, cli->timeout, cli->smb2.session,
803 cli->smb2.tcon, 0x10000, 0, fid_persistent,
804 fid_volatile, 2, 0,
805 talloc_tos(), &result, &nread);
806 if (!NT_STATUS_IS_OK(status)) {
807 printf("smb2cli_read returned %s\n", nt_errstr(status));
808 return false;
811 if (nread != strlen(hello)) {
812 printf("smb2cli_read returned %d bytes, expected %d\n",
813 (int)nread, (int)strlen(hello));
814 return false;
817 if (memcmp(hello, result, nread) != 0) {
818 printf("smb2cli_read returned '%s', expected '%s'\n",
819 result, hello);
820 return false;
823 /* check behaviour with wrong tid... */
825 tcon2 = smbXcli_tcon_create(cli);
826 tcon2_id = smb2cli_tcon_current_id(cli->smb2.tcon);
827 tcon2_id++;
828 smb2cli_tcon_set_values(tcon2,
829 NULL, /* session */
830 tcon2_id,
831 0, /* type */
832 0, /* flags */
833 0, /* capabilities */
834 0 /* maximal_access */);
836 status = smb2cli_read(cli->conn, cli->timeout, cli->smb2.session,
837 tcon2, 0x10000, 0, fid_persistent,
838 fid_volatile, 2, 0,
839 talloc_tos(), &result, &nread);
840 if (!NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED)) {
841 printf("smb2cli_read returned %s\n", nt_errstr(status));
842 return false;
845 talloc_free(tcon2);
847 return true;
850 bool run_smb2_multi_channel(int dummy)
852 struct cli_state *cli1;
853 struct cli_state *cli2;
854 struct cli_state *cli3;
855 NTSTATUS status;
856 bool ok;
857 uint64_t fid_persistent, fid_volatile;
858 struct tevent_context *ev;
859 struct tevent_req *subreq;
860 DATA_BLOB in_blob = data_blob_null;
861 DATA_BLOB out_blob;
862 DATA_BLOB channel_session_key;
863 struct auth_generic_state *auth_generic_state;
864 struct iovec *recv_iov;
865 const char *hello = "Hello, world\n";
866 uint8_t *result;
867 uint32_t nread;
868 struct GUID saved_guid = cli_state_client_guid;
870 printf("Starting SMB2-MULTI-CHANNEL\n");
872 cli_state_client_guid = GUID_random();
874 if (!torture_init_connection(&cli1)) {
875 return false;
878 if (!torture_init_connection(&cli2)) {
879 return false;
882 if (!torture_init_connection(&cli3)) {
883 return false;
886 cli_state_client_guid = saved_guid;
888 status = smbXcli_negprot(cli1->conn, cli1->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 = smbXcli_negprot(cli2->conn, cli2->timeout,
896 PROTOCOL_SMB2_22, PROTOCOL_LATEST);
897 if (!NT_STATUS_IS_OK(status)) {
898 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
899 return false;
902 status = smbXcli_negprot(cli3->conn, cli3->timeout,
903 PROTOCOL_SMB2_22, PROTOCOL_LATEST);
904 if (!NT_STATUS_IS_OK(status)) {
905 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
906 return false;
909 status = cli_session_setup(cli1, username,
910 password, strlen(password),
911 password, strlen(password),
912 workgroup);
913 if (!NT_STATUS_IS_OK(status)) {
914 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status));
915 return false;
918 status = cli_tree_connect(cli1, share, "?????", "", 0);
919 if (!NT_STATUS_IS_OK(status)) {
920 printf("cli_tree_connect returned %s\n", nt_errstr(status));
921 return false;
924 status = smb2cli_session_create_channel(cli2,
925 cli1->smb2.session,
926 cli2->conn,
927 &cli2->smb2.session);
928 if (!NT_STATUS_IS_OK(status)) {
929 printf("smb2cli_session_create_channel returned %s\n",
930 nt_errstr(status));
931 return false;
934 status = auth_generic_client_prepare(talloc_tos(), &auth_generic_state);
935 if (!NT_STATUS_IS_OK(status)) {
936 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status));
937 return false;
940 gensec_want_feature(auth_generic_state->gensec_security,
941 GENSEC_FEATURE_SESSION_KEY);
942 status = auth_generic_set_username(auth_generic_state, username);
943 if (!NT_STATUS_IS_OK(status)) {
944 printf("auth_generic_set_username returned %s\n", nt_errstr(status));
945 return false;
948 status = auth_generic_set_domain(auth_generic_state, workgroup);
949 if (!NT_STATUS_IS_OK(status)) {
950 printf("auth_generic_set_domain returned %s\n", nt_errstr(status));
951 return false;
954 status = auth_generic_set_password(auth_generic_state, password);
955 if (!NT_STATUS_IS_OK(status)) {
956 printf("auth_generic_set_password returned %s\n", nt_errstr(status));
957 return false;
960 status = auth_generic_client_start(auth_generic_state, GENSEC_OID_NTLMSSP);
961 if (!NT_STATUS_IS_OK(status)) {
962 printf("auth_generic_client_start returned %s\n", nt_errstr(status));
963 return false;
966 ev = samba_tevent_context_init(talloc_tos());
967 if (ev == NULL) {
968 printf("samba_tevent_context_init() returned NULL\n");
969 return false;
972 status = gensec_update(auth_generic_state->gensec_security,
973 talloc_tos(), data_blob_null, &in_blob);
974 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
975 printf("gensec_update returned %s\n", nt_errstr(status));
976 return false;
979 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
980 cli2->conn,
981 cli2->timeout,
982 cli2->smb2.session,
983 0x01, /* in_flags */
984 SMB2_CAP_DFS, /* in_capabilities */
985 0, /* in_channel */
986 0, /* in_previous_session_id */
987 &in_blob); /* in_security_buffer */
988 if (subreq == NULL) {
989 printf("smb2cli_session_setup_send() returned NULL\n");
990 return false;
993 ok = tevent_req_poll(subreq, ev);
994 if (!ok) {
995 printf("tevent_req_poll() returned false\n");
996 return false;
999 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
1000 NULL, &out_blob);
1001 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
1002 printf("smb2cli_session_setup_recv returned %s\n",
1003 nt_errstr(status));
1004 return false;
1007 status = gensec_update(auth_generic_state->gensec_security,
1008 talloc_tos(), out_blob, &in_blob);
1009 if (!NT_STATUS_IS_OK(status)) {
1010 printf("auth_generic_update returned %s\n", nt_errstr(status));
1011 return false;
1014 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
1015 cli2->conn,
1016 cli2->timeout,
1017 cli2->smb2.session,
1018 0x01, /* in_flags */
1019 SMB2_CAP_DFS, /* in_capabilities */
1020 0, /* in_channel */
1021 0, /* in_previous_session_id */
1022 &in_blob); /* in_security_buffer */
1023 if (subreq == NULL) {
1024 printf("smb2cli_session_setup_send() returned NULL\n");
1025 return false;
1028 ok = tevent_req_poll(subreq, ev);
1029 if (!ok) {
1030 printf("tevent_req_poll() returned false\n");
1031 return false;
1034 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
1035 &recv_iov, &out_blob);
1036 if (!NT_STATUS_IS_OK(status)) {
1037 printf("smb2cli_session_setup_recv returned %s\n",
1038 nt_errstr(status));
1039 return false;
1042 status = gensec_session_key(auth_generic_state->gensec_security, talloc_tos(),
1043 &channel_session_key);
1044 if (!NT_STATUS_IS_OK(status)) {
1045 printf("gensec_session_key returned %s\n",
1046 nt_errstr(status));
1047 return false;
1050 status = smb2cli_session_set_channel_key(cli2->smb2.session,
1051 channel_session_key,
1052 recv_iov);
1053 if (!NT_STATUS_IS_OK(status)) {
1054 printf("smb2cli_session_set_channel_key %s\n", nt_errstr(status));
1055 return false;
1058 status = smb2cli_session_create_channel(cli3,
1059 cli1->smb2.session,
1060 cli3->conn,
1061 &cli3->smb2.session);
1062 if (!NT_STATUS_IS_OK(status)) {
1063 printf("smb2cli_session_create_channel returned %s\n",
1064 nt_errstr(status));
1065 return false;
1068 status = auth_generic_client_prepare(talloc_tos(), &auth_generic_state);
1069 if (!NT_STATUS_IS_OK(status)) {
1070 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status));
1071 return false;
1074 gensec_want_feature(auth_generic_state->gensec_security,
1075 GENSEC_FEATURE_SESSION_KEY);
1076 status = auth_generic_set_username(auth_generic_state, username);
1077 if (!NT_STATUS_IS_OK(status)) {
1078 printf("auth_generic_set_username returned %s\n", nt_errstr(status));
1079 return false;
1082 status = auth_generic_set_domain(auth_generic_state, workgroup);
1083 if (!NT_STATUS_IS_OK(status)) {
1084 printf("auth_generic_set_domain returned %s\n", nt_errstr(status));
1085 return false;
1088 status = auth_generic_set_password(auth_generic_state, password);
1089 if (!NT_STATUS_IS_OK(status)) {
1090 printf("auth_generic_set_password returned %s\n", nt_errstr(status));
1091 return false;
1094 status = auth_generic_client_start(auth_generic_state, GENSEC_OID_NTLMSSP);
1095 if (!NT_STATUS_IS_OK(status)) {
1096 printf("auth_generic_client_start returned %s\n", nt_errstr(status));
1097 return false;
1100 status = gensec_update(auth_generic_state->gensec_security,
1101 talloc_tos(), data_blob_null, &in_blob);
1102 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
1103 printf("gensec_update returned %s\n", nt_errstr(status));
1104 return false;
1107 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
1108 cli3->conn,
1109 cli3->timeout,
1110 cli3->smb2.session,
1111 0x01, /* in_flags */
1112 SMB2_CAP_DFS, /* in_capabilities */
1113 0, /* in_channel */
1114 0, /* in_previous_session_id */
1115 &in_blob); /* in_security_buffer */
1116 if (subreq == NULL) {
1117 printf("smb2cli_session_setup_send() returned NULL\n");
1118 return false;
1121 ok = tevent_req_poll(subreq, ev);
1122 if (!ok) {
1123 printf("tevent_req_poll() returned false\n");
1124 return false;
1127 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
1128 NULL, &out_blob);
1129 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
1130 printf("smb2cli_session_setup_recv returned %s\n",
1131 nt_errstr(status));
1132 return false;
1135 status = gensec_update(auth_generic_state->gensec_security,
1136 talloc_tos(), out_blob, &in_blob);
1137 if (!NT_STATUS_IS_OK(status)) {
1138 printf("auth_generic_update returned %s\n", nt_errstr(status));
1139 return false;
1142 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
1143 cli3->conn,
1144 cli3->timeout,
1145 cli3->smb2.session,
1146 0x01, /* in_flags */
1147 SMB2_CAP_DFS, /* in_capabilities */
1148 0, /* in_channel */
1149 0, /* in_previous_session_id */
1150 &in_blob); /* in_security_buffer */
1151 if (subreq == NULL) {
1152 printf("smb2cli_session_setup_send() returned NULL\n");
1153 return false;
1156 ok = tevent_req_poll(subreq, ev);
1157 if (!ok) {
1158 printf("tevent_req_poll() returned false\n");
1159 return false;
1162 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
1163 &recv_iov, &out_blob);
1164 if (!NT_STATUS_IS_OK(status)) {
1165 printf("smb2cli_session_setup_recv returned %s\n",
1166 nt_errstr(status));
1167 return false;
1170 status = gensec_session_key(auth_generic_state->gensec_security, talloc_tos(),
1171 &channel_session_key);
1172 if (!NT_STATUS_IS_OK(status)) {
1173 printf("gensec_session_key returned %s\n",
1174 nt_errstr(status));
1175 return false;
1178 status = smb2cli_session_set_channel_key(cli3->smb2.session,
1179 channel_session_key,
1180 recv_iov);
1181 if (!NT_STATUS_IS_OK(status)) {
1182 printf("smb2cli_session_set_channel_key %s\n", nt_errstr(status));
1183 return false;
1186 status = smb2cli_create(cli2->conn, cli2->timeout, cli2->smb2.session,
1187 cli1->smb2.tcon, "multi-channel.txt",
1188 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1189 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1190 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
1191 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
1192 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1193 FILE_CREATE, /* create_disposition, */
1194 FILE_DELETE_ON_CLOSE, /* create_options, */
1195 NULL, /* smb2_create_blobs *blobs */
1196 &fid_persistent,
1197 &fid_volatile,
1198 NULL, NULL, NULL);
1199 if (!NT_STATUS_IS_OK(status)) {
1200 printf("smb2cli_create on cli2 %s\n", nt_errstr(status));
1201 return false;
1204 status = smb2cli_write(cli1->conn, cli1->timeout, cli1->smb2.session,
1205 cli1->smb2.tcon, strlen(hello), 0, fid_persistent,
1206 fid_volatile, 0, 0, (const uint8_t *)hello, NULL);
1207 if (!NT_STATUS_IS_OK(status)) {
1208 printf("smb2cli_write returned %s\n", nt_errstr(status));
1209 return false;
1212 status = smb2cli_flush(cli2->conn, cli2->timeout, cli2->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_flush(cli1->conn, cli1->timeout, cli1->smb2.session,
1220 cli1->smb2.tcon, fid_persistent, fid_volatile);
1221 if (!NT_STATUS_IS_OK(status)) {
1222 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1223 return false;
1226 status = smb2cli_flush(cli3->conn, cli3->timeout, cli3->smb2.session,
1227 cli1->smb2.tcon, fid_persistent, fid_volatile);
1228 if (!NT_STATUS_IS_OK(status)) {
1229 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1230 return false;
1233 status = smb2cli_read(cli2->conn, cli2->timeout, cli2->smb2.session,
1234 cli1->smb2.tcon, 0x10000, 0, fid_persistent,
1235 fid_volatile, 2, 0,
1236 talloc_tos(), &result, &nread);
1237 if (!NT_STATUS_IS_OK(status)) {
1238 printf("smb2cli_read returned %s\n", nt_errstr(status));
1239 return false;
1242 if (nread != strlen(hello)) {
1243 printf("smb2cli_read returned %d bytes, expected %d\n",
1244 (int)nread, (int)strlen(hello));
1245 return false;
1248 if (memcmp(hello, result, nread) != 0) {
1249 printf("smb2cli_read returned '%s', expected '%s'\n",
1250 result, hello);
1251 return false;
1254 status = auth_generic_client_prepare(talloc_tos(), &auth_generic_state);
1255 if (!NT_STATUS_IS_OK(status)) {
1256 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status));
1257 return false;
1260 gensec_want_feature(auth_generic_state->gensec_security,
1261 GENSEC_FEATURE_SESSION_KEY);
1262 status = auth_generic_set_username(auth_generic_state, username);
1263 if (!NT_STATUS_IS_OK(status)) {
1264 printf("auth_generic_set_username returned %s\n", nt_errstr(status));
1265 return false;
1268 status = auth_generic_set_domain(auth_generic_state, workgroup);
1269 if (!NT_STATUS_IS_OK(status)) {
1270 printf("auth_generic_set_domain returned %s\n", nt_errstr(status));
1271 return false;
1274 status = auth_generic_set_password(auth_generic_state, password);
1275 if (!NT_STATUS_IS_OK(status)) {
1276 printf("auth_generic_set_password returned %s\n", nt_errstr(status));
1277 return false;
1280 status = auth_generic_client_start(auth_generic_state, GENSEC_OID_NTLMSSP);
1281 if (!NT_STATUS_IS_OK(status)) {
1282 printf("auth_generic_client_start returned %s\n", nt_errstr(status));
1283 return false;
1286 status = gensec_update(auth_generic_state->gensec_security,
1287 talloc_tos(), data_blob_null, &in_blob);
1288 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
1289 printf("gensec_update returned %s\n", nt_errstr(status));
1290 return false;
1293 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
1294 cli3->conn,
1295 cli3->timeout,
1296 cli3->smb2.session,
1297 0x0, /* in_flags */
1298 SMB2_CAP_DFS, /* in_capabilities */
1299 0, /* in_channel */
1300 0, /* in_previous_session_id */
1301 &in_blob); /* in_security_buffer */
1302 if (subreq == NULL) {
1303 printf("smb2cli_session_setup_send() returned NULL\n");
1304 return false;
1307 ok = tevent_req_poll(subreq, ev);
1308 if (!ok) {
1309 printf("tevent_req_poll() returned false\n");
1310 return false;
1313 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
1314 NULL, &out_blob);
1315 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
1316 printf("smb2cli_session_setup_recv returned %s\n",
1317 nt_errstr(status));
1318 return false;
1321 status = gensec_update(auth_generic_state->gensec_security,
1322 talloc_tos(), out_blob, &in_blob);
1323 if (!NT_STATUS_IS_OK(status)) {
1324 printf("auth_generic_update returned %s\n", nt_errstr(status));
1325 return false;
1328 status = smb2cli_flush(cli1->conn, cli1->timeout, cli1->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_flush(cli2->conn, cli2->timeout, cli2->smb2.session,
1336 cli1->smb2.tcon, fid_persistent, fid_volatile);
1337 if (!NT_STATUS_IS_OK(status)) {
1338 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1339 return false;
1342 status = smb2cli_flush(cli3->conn, cli3->timeout, cli3->smb2.session,
1343 cli1->smb2.tcon, fid_persistent, fid_volatile);
1344 if (!NT_STATUS_IS_OK(status)) {
1345 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1346 return false;
1349 status = smb2cli_create(cli1->conn, cli1->timeout, cli1->smb2.session,
1350 cli1->smb2.tcon, "multi-channel-invalid.txt",
1351 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1352 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1353 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
1354 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
1355 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1356 FILE_CREATE, /* create_disposition, */
1357 FILE_DELETE_ON_CLOSE, /* create_options, */
1358 NULL, /* smb2_create_blobs *blobs */
1359 &fid_persistent,
1360 &fid_volatile,
1361 NULL, NULL, NULL);
1362 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1363 printf("smb2cli_create %s\n", nt_errstr(status));
1364 return false;
1367 status = smb2cli_create(cli2->conn, cli2->timeout, cli2->smb2.session,
1368 cli1->smb2.tcon, "multi-channel-invalid.txt",
1369 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1370 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1371 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
1372 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
1373 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1374 FILE_CREATE, /* create_disposition, */
1375 FILE_DELETE_ON_CLOSE, /* create_options, */
1376 NULL, /* smb2_create_blobs *blobs */
1377 &fid_persistent,
1378 &fid_volatile,
1379 NULL, NULL, NULL);
1380 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1381 printf("smb2cli_create %s\n", nt_errstr(status));
1382 return false;
1385 status = smb2cli_create(cli3->conn, cli3->timeout, cli3->smb2.session,
1386 cli1->smb2.tcon, "multi-channel-invalid.txt",
1387 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1388 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1389 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
1390 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
1391 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1392 FILE_CREATE, /* create_disposition, */
1393 FILE_DELETE_ON_CLOSE, /* create_options, */
1394 NULL, /* smb2_create_blobs *blobs */
1395 &fid_persistent,
1396 &fid_volatile,
1397 NULL, NULL, NULL);
1398 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1399 printf("smb2cli_create %s\n", nt_errstr(status));
1400 return false;
1403 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
1404 cli2->conn,
1405 cli2->timeout,
1406 cli2->smb2.session,
1407 0x0, /* in_flags */
1408 SMB2_CAP_DFS, /* in_capabilities */
1409 0, /* in_channel */
1410 0, /* in_previous_session_id */
1411 &in_blob); /* in_security_buffer */
1412 if (subreq == NULL) {
1413 printf("smb2cli_session_setup_send() returned NULL\n");
1414 return false;
1417 ok = tevent_req_poll(subreq, ev);
1418 if (!ok) {
1419 printf("tevent_req_poll() returned false\n");
1420 return false;
1423 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
1424 &recv_iov, &out_blob);
1425 if (!NT_STATUS_IS_OK(status)) {
1426 printf("smb2cli_session_setup_recv returned %s\n",
1427 nt_errstr(status));
1428 return false;
1431 status = smb2cli_close(cli3->conn, cli3->timeout, cli3->smb2.session,
1432 cli1->smb2.tcon, 0, fid_persistent, fid_volatile);
1433 if (!NT_STATUS_IS_OK(status)) {
1434 printf("smb2cli_close returned %s\n", nt_errstr(status));
1435 return false;
1438 status = smb2cli_flush(cli3->conn, cli3->timeout, cli3->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 status = smb2cli_flush(cli2->conn, cli2->timeout, cli2->smb2.session,
1446 cli1->smb2.tcon, fid_persistent, fid_volatile);
1447 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED)) {
1448 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1449 return false;
1452 status = smb2cli_flush(cli1->conn, cli1->timeout, cli1->smb2.session,
1453 cli1->smb2.tcon, fid_persistent, fid_volatile);
1454 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED)) {
1455 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1456 return false;
1459 return true;
1462 bool run_smb2_session_reauth(int dummy)
1464 struct cli_state *cli;
1465 NTSTATUS status;
1466 bool ok;
1467 uint64_t fid_persistent, fid_volatile;
1468 uint64_t dir_persistent, dir_volatile;
1469 uint8_t *dir_data;
1470 uint32_t dir_data_length;
1471 struct tevent_context *ev;
1472 struct tevent_req *subreq;
1473 DATA_BLOB in_blob = data_blob_null;
1474 DATA_BLOB out_blob;
1475 DATA_BLOB in_input_buffer;
1476 DATA_BLOB out_output_buffer;
1477 uint8_t in_file_info_class;
1478 struct auth_generic_state *auth_generic_state;
1479 struct iovec *recv_iov;
1480 uint32_t saved_tid;
1481 struct smbXcli_tcon *saved_tcon;
1483 printf("Starting SMB2-SESSION_REAUTH\n");
1485 if (!torture_init_connection(&cli)) {
1486 return false;
1490 * PROTOCOL_SMB2_22 has a bug in win8pre0
1491 * it behaves like PROTOCOL_SMB2_02
1492 * and returns NT_STATUS_REQUEST_NOT_ACCEPTED,
1493 * while it allows it on PROTOCOL_SMB2_02.
1495 status = smbXcli_negprot(cli->conn, cli->timeout,
1496 PROTOCOL_SMB2_10, PROTOCOL_SMB2_10);
1497 if (!NT_STATUS_IS_OK(status)) {
1498 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
1499 return false;
1502 status = cli_session_setup(cli, username,
1503 password, strlen(password),
1504 password, strlen(password),
1505 workgroup);
1506 if (!NT_STATUS_IS_OK(status)) {
1507 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status));
1508 return false;
1511 status = cli_tree_connect(cli, share, "?????", "", 0);
1512 if (!NT_STATUS_IS_OK(status)) {
1513 printf("cli_tree_connect returned %s\n", nt_errstr(status));
1514 return false;
1517 status = smb2cli_create(cli->conn, cli->timeout, cli->smb2.session,
1518 cli->smb2.tcon, "session-reauth.txt",
1519 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1520 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1521 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
1522 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
1523 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1524 FILE_CREATE, /* create_disposition, */
1525 FILE_DELETE_ON_CLOSE, /* create_options, */
1526 NULL, /* smb2_create_blobs *blobs */
1527 &fid_persistent,
1528 &fid_volatile,
1529 NULL, NULL, NULL);
1530 if (!NT_STATUS_IS_OK(status)) {
1531 printf("smb2cli_create %s\n", nt_errstr(status));
1532 return false;
1535 status = smb2cli_create(cli->conn, cli->timeout, cli->smb2.session,
1536 cli->smb2.tcon, "",
1537 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1538 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1539 SEC_STD_SYNCHRONIZE|
1540 SEC_DIR_LIST|
1541 SEC_DIR_READ_ATTRIBUTE, /* desired_access, */
1542 0, /* file_attributes, */
1543 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1544 FILE_OPEN, /* create_disposition, */
1545 FILE_SYNCHRONOUS_IO_NONALERT|FILE_DIRECTORY_FILE, /* create_options, */
1546 NULL, /* smb2_create_blobs *blobs */
1547 &dir_persistent,
1548 &dir_volatile,
1549 NULL, NULL, NULL);
1550 if (!NT_STATUS_IS_OK(status)) {
1551 printf("smb2cli_create returned %s\n", nt_errstr(status));
1552 return false;
1555 status = smb2cli_query_directory(
1556 cli->conn, cli->timeout, cli->smb2.session, cli->smb2.tcon,
1557 1, 0x3, 0, dir_persistent, dir_volatile,
1558 "session-reauth.txt", 0xffff,
1559 talloc_tos(), &dir_data, &dir_data_length);
1560 if (!NT_STATUS_IS_OK(status)) {
1561 printf("smb2cli_query_directory returned %s\n", nt_errstr(status));
1562 return false;
1565 status = auth_generic_client_prepare(talloc_tos(), &auth_generic_state);
1566 if (!NT_STATUS_IS_OK(status)) {
1567 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status));
1568 return false;
1571 gensec_want_feature(auth_generic_state->gensec_security,
1572 GENSEC_FEATURE_SESSION_KEY);
1573 status = auth_generic_set_username(auth_generic_state, username);
1574 if (!NT_STATUS_IS_OK(status)) {
1575 printf("auth_generic_set_username returned %s\n", nt_errstr(status));
1576 return false;
1579 status = auth_generic_set_domain(auth_generic_state, workgroup);
1580 if (!NT_STATUS_IS_OK(status)) {
1581 printf("auth_generic_set_domain returned %s\n", nt_errstr(status));
1582 return false;
1585 status = auth_generic_set_password(auth_generic_state, password);
1586 if (!NT_STATUS_IS_OK(status)) {
1587 printf("auth_generic_set_password returned %s\n", nt_errstr(status));
1588 return false;
1591 status = auth_generic_client_start(auth_generic_state, GENSEC_OID_NTLMSSP);
1592 if (!NT_STATUS_IS_OK(status)) {
1593 printf("auth_generic_client_start returned %s\n", nt_errstr(status));
1594 return false;
1597 ev = samba_tevent_context_init(talloc_tos());
1598 if (ev == NULL) {
1599 printf("samba_tevent_context_init() returned NULL\n");
1600 return false;
1603 status = gensec_update(auth_generic_state->gensec_security,
1604 talloc_tos(), data_blob_null, &in_blob);
1605 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
1606 printf("gensec_update returned %s\n", nt_errstr(status));
1607 return false;
1610 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
1611 cli->conn,
1612 cli->timeout,
1613 cli->smb2.session,
1614 0x0, /* in_flags */
1615 SMB2_CAP_DFS, /* in_capabilities */
1616 0, /* in_channel */
1617 0, /* in_previous_session_id */
1618 &in_blob); /* in_security_buffer */
1619 if (subreq == NULL) {
1620 printf("smb2cli_session_setup_send() returned NULL\n");
1621 return false;
1624 ok = tevent_req_poll(subreq, ev);
1625 if (!ok) {
1626 printf("tevent_req_poll() returned false\n");
1627 return false;
1630 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
1631 NULL, &out_blob);
1632 if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
1633 printf("smb2cli_session_setup_recv returned %s\n",
1634 nt_errstr(status));
1635 return false;
1638 status = gensec_update(auth_generic_state->gensec_security,
1639 talloc_tos(), out_blob, &in_blob);
1640 if (!NT_STATUS_IS_OK(status)) {
1641 printf("auth_generic_update returned %s\n", nt_errstr(status));
1642 return false;
1645 status = smb2cli_flush(cli->conn, cli->timeout, cli->smb2.session,
1646 cli->smb2.tcon, fid_persistent, fid_volatile);
1647 if (!NT_STATUS_IS_OK(status)) {
1648 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1649 return false;
1652 status = smb2cli_query_directory(
1653 cli->conn, cli->timeout, cli->smb2.session, cli->smb2.tcon,
1654 1, 0x3, 0, dir_persistent, dir_volatile,
1655 "session-reauth.txt", 0xffff,
1656 talloc_tos(), &dir_data, &dir_data_length);
1657 if (!NT_STATUS_IS_OK(status)) {
1658 printf("smb2cli_query_directory returned %s\n", nt_errstr(status));
1659 return false;
1663 * query_info seems to be a path based operation on Windows...
1665 status = smb2cli_query_info(cli->conn,
1666 cli->timeout,
1667 cli->smb2.session,
1668 cli->smb2.tcon,
1669 SMB2_GETINFO_SECURITY,
1670 0, /* in_file_info_class */
1671 1024, /* in_max_output_length */
1672 NULL, /* in_input_buffer */
1673 SECINFO_OWNER, /* in_additional_info */
1674 0, /* in_flags */
1675 fid_persistent,
1676 fid_volatile,
1677 talloc_tos(),
1678 &out_output_buffer);
1679 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1680 printf("smb2cli_query_info (security) returned %s\n", nt_errstr(status));
1681 return false;
1684 in_file_info_class = SMB_FILE_POSITION_INFORMATION - 1000;
1685 status = smb2cli_query_info(cli->conn,
1686 cli->timeout,
1687 cli->smb2.session,
1688 cli->smb2.tcon,
1689 SMB2_GETINFO_FILE,
1690 in_file_info_class,
1691 1024, /* in_max_output_length */
1692 NULL, /* in_input_buffer */
1693 0, /* in_additional_info */
1694 0, /* in_flags */
1695 fid_persistent,
1696 fid_volatile,
1697 talloc_tos(),
1698 &out_output_buffer);
1699 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1700 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status));
1701 return false;
1704 in_input_buffer = data_blob_talloc(talloc_tos(), NULL, 8);
1705 SBVAL(in_input_buffer.data, 0, 512);
1707 in_file_info_class = SMB_FILE_POSITION_INFORMATION - 1000;
1708 status = smb2cli_set_info(cli->conn,
1709 cli->timeout,
1710 cli->smb2.session,
1711 cli->smb2.tcon,
1712 SMB2_GETINFO_FILE,
1713 in_file_info_class,
1714 &in_input_buffer,
1715 0, /* in_additional_info */
1716 fid_persistent,
1717 fid_volatile);
1718 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1719 printf("smb2cli_set_info (position) returned %s\n", nt_errstr(status));
1720 return false;
1723 status = smb2cli_create(cli->conn, cli->timeout, cli->smb2.session,
1724 cli->smb2.tcon, "session-reauth-invalid.txt",
1725 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1726 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1727 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
1728 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
1729 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1730 FILE_CREATE, /* create_disposition, */
1731 FILE_DELETE_ON_CLOSE, /* create_options, */
1732 NULL, /* smb2_create_blobs *blobs */
1733 &fid_persistent,
1734 &fid_volatile,
1735 NULL, NULL, NULL);
1736 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1737 printf("smb2cli_create %s\n", nt_errstr(status));
1738 return false;
1741 status = smb2cli_create(cli->conn, cli->timeout, cli->smb2.session,
1742 cli->smb2.tcon, "",
1743 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1744 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1745 SEC_STD_SYNCHRONIZE|
1746 SEC_DIR_LIST|
1747 SEC_DIR_READ_ATTRIBUTE, /* desired_access, */
1748 0, /* file_attributes, */
1749 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1750 FILE_OPEN, /* create_disposition, */
1751 FILE_SYNCHRONOUS_IO_NONALERT|FILE_DIRECTORY_FILE, /* create_options, */
1752 NULL, /* smb2_create_blobs *blobs */
1753 &dir_persistent,
1754 &dir_volatile,
1755 NULL, NULL, NULL);
1756 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1757 printf("smb2cli_create returned %s\n", nt_errstr(status));
1758 return false;
1761 saved_tid = smb2cli_tcon_current_id(cli->smb2.tcon);
1762 saved_tcon = cli->smb2.tcon;
1763 cli->smb2.tcon = smbXcli_tcon_create(cli);
1764 smb2cli_tcon_set_values(cli->smb2.tcon,
1765 NULL, /* session */
1766 saved_tid,
1767 0, /* type */
1768 0, /* flags */
1769 0, /* capabilities */
1770 0 /* maximal_access */);
1771 status = cli_tree_connect(cli, share, "?????", "", 0);
1772 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1773 printf("cli_tree_connect returned %s\n", nt_errstr(status));
1774 return false;
1776 talloc_free(cli->smb2.tcon);
1777 cli->smb2.tcon = saved_tcon;
1779 subreq = smb2cli_session_setup_send(talloc_tos(), ev,
1780 cli->conn,
1781 cli->timeout,
1782 cli->smb2.session,
1783 0x0, /* in_flags */
1784 SMB2_CAP_DFS, /* in_capabilities */
1785 0, /* in_channel */
1786 0, /* in_previous_session_id */
1787 &in_blob); /* in_security_buffer */
1788 if (subreq == NULL) {
1789 printf("smb2cli_session_setup_send() returned NULL\n");
1790 return false;
1793 ok = tevent_req_poll(subreq, ev);
1794 if (!ok) {
1795 printf("tevent_req_poll() returned false\n");
1796 return false;
1799 status = smb2cli_session_setup_recv(subreq, talloc_tos(),
1800 &recv_iov, &out_blob);
1801 if (!NT_STATUS_IS_OK(status)) {
1802 printf("smb2cli_session_setup_recv returned %s\n",
1803 nt_errstr(status));
1804 return false;
1807 status = smb2cli_flush(cli->conn, cli->timeout, cli->smb2.session,
1808 cli->smb2.tcon, fid_persistent, fid_volatile);
1809 if (!NT_STATUS_IS_OK(status)) {
1810 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1811 return false;
1814 status = smb2cli_query_info(cli->conn,
1815 cli->timeout,
1816 cli->smb2.session,
1817 cli->smb2.tcon,
1818 SMB2_GETINFO_SECURITY,
1819 0, /* in_file_info_class */
1820 1024, /* in_max_output_length */
1821 NULL, /* in_input_buffer */
1822 SECINFO_OWNER, /* in_additional_info */
1823 0, /* in_flags */
1824 fid_persistent,
1825 fid_volatile,
1826 talloc_tos(),
1827 &out_output_buffer);
1828 if (!NT_STATUS_IS_OK(status)) {
1829 printf("smb2cli_query_info (security) returned %s\n", nt_errstr(status));
1830 return false;
1833 in_file_info_class = SMB_FILE_POSITION_INFORMATION - 1000;
1834 status = smb2cli_query_info(cli->conn,
1835 cli->timeout,
1836 cli->smb2.session,
1837 cli->smb2.tcon,
1838 SMB2_GETINFO_FILE,
1839 in_file_info_class,
1840 1024, /* in_max_output_length */
1841 NULL, /* in_input_buffer */
1842 0, /* in_additional_info */
1843 0, /* in_flags */
1844 fid_persistent,
1845 fid_volatile,
1846 talloc_tos(),
1847 &out_output_buffer);
1848 if (!NT_STATUS_IS_OK(status)) {
1849 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status));
1850 return false;
1853 in_input_buffer = data_blob_talloc(talloc_tos(), NULL, 8);
1854 SBVAL(in_input_buffer.data, 0, 512);
1856 in_file_info_class = SMB_FILE_POSITION_INFORMATION - 1000;
1857 status = smb2cli_set_info(cli->conn,
1858 cli->timeout,
1859 cli->smb2.session,
1860 cli->smb2.tcon,
1861 SMB2_GETINFO_FILE,
1862 in_file_info_class,
1863 &in_input_buffer,
1864 0, /* in_additional_info */
1865 fid_persistent,
1866 fid_volatile);
1867 if (!NT_STATUS_IS_OK(status)) {
1868 printf("smb2cli_set_info (position) returned %s\n", nt_errstr(status));
1869 return false;
1872 in_file_info_class = SMB_FILE_POSITION_INFORMATION - 1000;
1873 status = smb2cli_query_info(cli->conn,
1874 cli->timeout,
1875 cli->smb2.session,
1876 cli->smb2.tcon,
1877 SMB2_GETINFO_FILE,
1878 in_file_info_class,
1879 1024, /* in_max_output_length */
1880 NULL, /* in_input_buffer */
1881 0, /* in_additional_info */
1882 0, /* in_flags */
1883 fid_persistent,
1884 fid_volatile,
1885 talloc_tos(),
1886 &out_output_buffer);
1887 if (!NT_STATUS_IS_OK(status)) {
1888 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status));
1889 return false;
1892 status = smb2cli_close(cli->conn, cli->timeout, cli->smb2.session,
1893 cli->smb2.tcon, 0, fid_persistent, fid_volatile);
1894 if (!NT_STATUS_IS_OK(status)) {
1895 printf("smb2cli_close returned %s\n", nt_errstr(status));
1896 return false;
1899 status = smb2cli_create(cli->conn, cli->timeout, cli->smb2.session,
1900 cli->smb2.tcon, "session-reauth.txt",
1901 SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1902 SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1903 SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
1904 FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
1905 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1906 FILE_CREATE, /* create_disposition, */
1907 FILE_DELETE_ON_CLOSE, /* create_options, */
1908 NULL, /* smb2_create_blobs *blobs */
1909 &fid_persistent,
1910 &fid_volatile,
1911 NULL, NULL, NULL);
1912 if (!NT_STATUS_IS_OK(status)) {
1913 printf("smb2cli_create %s\n", nt_errstr(status));
1914 return false;
1917 status = smb2cli_query_directory(
1918 cli->conn, cli->timeout, cli->smb2.session, cli->smb2.tcon,
1919 1, 0x3, 0, dir_persistent, dir_volatile,
1920 "session-reauth.txt", 0xffff,
1921 talloc_tos(), &dir_data, &dir_data_length);
1922 if (!NT_STATUS_IS_OK(status)) {
1923 printf("smb2cli_query_directory returned %s\n", nt_errstr(status));
1924 return false;
1927 status = smb2cli_close(cli->conn, cli->timeout, cli->smb2.session,
1928 cli->smb2.tcon, 0, dir_persistent, dir_volatile);
1929 if (!NT_STATUS_IS_OK(status)) {
1930 printf("smb2cli_close returned %s\n", nt_errstr(status));
1931 return false;
1934 status = smb2cli_close(cli->conn, cli->timeout, cli->smb2.session,
1935 cli->smb2.tcon, 0, fid_persistent, fid_volatile);
1936 if (!NT_STATUS_IS_OK(status)) {
1937 printf("smb2cli_close returned %s\n", nt_errstr(status));
1938 return false;
1941 saved_tid = smb2cli_tcon_current_id(cli->smb2.tcon);
1942 saved_tcon = cli->smb2.tcon;
1943 cli->smb2.tcon = smbXcli_tcon_create(cli);
1944 smb2cli_tcon_set_values(cli->smb2.tcon,
1945 NULL, /* session */
1946 saved_tid,
1947 0, /* type */
1948 0, /* flags */
1949 0, /* capabilities */
1950 0 /* maximal_access */);
1951 status = cli_tree_connect(cli, share, "?????", "", 0);
1952 if (!NT_STATUS_IS_OK(status)) {
1953 printf("cli_tree_connect returned %s\n", nt_errstr(status));
1954 return false;
1956 talloc_free(cli->smb2.tcon);
1957 cli->smb2.tcon = saved_tcon;
1959 return true;