s3:torture: do some query_info and set_info calls in SMB2-SESSION-REAUTH
[kai/samba.git] / source3 / torture / test_smb2.c
1 /*
2    Unix SMB/CIFS implementation.
3    Initial test for the smb2 client lib
4    Copyright (C) Volker Lendecke 2011
5
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.
10
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.
15
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/>.
18 */
19
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"
30
31 extern fstring host, workgroup, share, password, username, myname;
32
33 bool run_smb2_basic(int dummy)
34 {
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         uint64_t saved_uid = 0;
45
46         printf("Starting SMB2-BASIC\n");
47
48         if (!torture_init_connection(&cli)) {
49                 return false;
50         }
51         cli->smb2.pid = 0xFEFF;
52
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;
58         }
59
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;
67         }
68
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;
73         }
74
75         status = smb2cli_create(cli, "smb2-basic.txt",
76                         SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
77                         SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
78                         SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
79                         FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
80                         FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
81                         FILE_CREATE, /* create_disposition, */
82                         FILE_DELETE_ON_CLOSE, /* create_options, */
83                         NULL, /* smb2_create_blobs *blobs */
84                         &fid_persistent,
85                         &fid_volatile);
86         if (!NT_STATUS_IS_OK(status)) {
87                 printf("smb2cli_create returned %s\n", nt_errstr(status));
88                 return false;
89         }
90
91         status = smb2cli_write(cli, strlen(hello), 0, fid_persistent,
92                                fid_volatile, 0, 0, (const uint8_t *)hello);
93         if (!NT_STATUS_IS_OK(status)) {
94                 printf("smb2cli_write returned %s\n", nt_errstr(status));
95                 return false;
96         }
97
98         status = smb2cli_flush(cli, fid_persistent, fid_volatile);
99         if (!NT_STATUS_IS_OK(status)) {
100                 printf("smb2cli_flush returned %s\n", nt_errstr(status));
101                 return false;
102         }
103
104         status = smb2cli_read(cli, 0x10000, 0, fid_persistent,
105                                fid_volatile, 2, 0,
106                                talloc_tos(), &result, &nread);
107         if (!NT_STATUS_IS_OK(status)) {
108                 printf("smb2cli_read returned %s\n", nt_errstr(status));
109                 return false;
110         }
111
112         if (nread != strlen(hello)) {
113                 printf("smb2cli_read returned %d bytes, expected %d\n",
114                        (int)nread, (int)strlen(hello));
115                 return false;
116         }
117
118         if (memcmp(hello, result, nread) != 0) {
119                 printf("smb2cli_read returned '%s', expected '%s'\n",
120                        result, hello);
121                 return false;
122         }
123
124         status = smb2cli_close(cli, 0, fid_persistent, fid_volatile);
125         if (!NT_STATUS_IS_OK(status)) {
126                 printf("smb2cli_close returned %s\n", nt_errstr(status));
127                 return false;
128         }
129
130         status = smb2cli_create(cli, "",
131                         SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
132                         SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
133                         SEC_STD_SYNCHRONIZE|
134                         SEC_DIR_LIST|
135                         SEC_DIR_READ_ATTRIBUTE, /* desired_access, */
136                         0, /* file_attributes, */
137                         FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
138                         FILE_OPEN, /* create_disposition, */
139                         FILE_SYNCHRONOUS_IO_NONALERT|FILE_DIRECTORY_FILE, /* create_options, */
140                         NULL, /* smb2_create_blobs *blobs */
141                         &fid_persistent,
142                         &fid_volatile);
143         if (!NT_STATUS_IS_OK(status)) {
144                 printf("smb2cli_create returned %s\n", nt_errstr(status));
145                 return false;
146         }
147
148         status = smb2cli_query_directory(
149                 cli, 1, 0, 0, fid_persistent, fid_volatile, "*", 0xffff,
150                 talloc_tos(), &dir_data, &dir_data_length);
151
152         if (!NT_STATUS_IS_OK(status)) {
153                 printf("smb2cli_query_directory returned %s\n", nt_errstr(status));
154                 return false;
155         }
156
157         status = smb2cli_close(cli, 0, fid_persistent, fid_volatile);
158         if (!NT_STATUS_IS_OK(status)) {
159                 printf("smb2cli_close returned %s\n", nt_errstr(status));
160                 return false;
161         }
162
163         saved_tid = cli->smb2.tid;
164         status = smb2cli_tdis(cli);
165         if (!NT_STATUS_IS_OK(status)) {
166                 printf("smb2cli_tdis returned %s\n", nt_errstr(status));
167                 return false;
168         }
169         cli->smb2.tid = saved_tid;
170
171         status = smb2cli_tdis(cli);
172         if (!NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED)) {
173                 printf("2nd smb2cli_tdis returned %s\n", nt_errstr(status));
174                 return false;
175         }
176
177         saved_uid = smb2cli_session_current_id(cli->smb2.session);
178         status = smb2cli_logoff(cli);
179         if (!NT_STATUS_IS_OK(status)) {
180                 printf("smb2cli_logoff returned %s\n", nt_errstr(status));
181                 return false;
182         }
183
184         cli->smb2.session = smbXcli_session_create(cli, cli->conn);
185         if (cli->smb2.session == NULL) {
186                 printf("smbXcli_session_create() returned NULL\n");
187                 return false;
188         }
189
190         smb2cli_session_set_id_and_flags(cli->smb2.session, saved_uid, 0);
191
192         status = smb2cli_logoff(cli);
193         if (!NT_STATUS_EQUAL(status, NT_STATUS_USER_SESSION_DELETED)) {
194                 printf("2nd smb2cli_logoff returned %s\n", nt_errstr(status));
195                 return false;
196         }
197
198         return true;
199 }
200
201 bool run_smb2_negprot(int dummy)
202 {
203         struct cli_state *cli;
204         NTSTATUS status;
205         enum protocol_types protocol;
206         const char *name = NULL;
207
208         printf("Starting SMB2-NEGPROT\n");
209
210         if (!torture_init_connection(&cli)) {
211                 return false;
212         }
213         cli->smb2.pid = 0xFEFF;
214
215         status = smbXcli_negprot(cli->conn, cli->timeout,
216                                  PROTOCOL_CORE, PROTOCOL_SMB2_24);
217         if (!NT_STATUS_IS_OK(status)) {
218                 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
219                 return false;
220         }
221
222         protocol = smbXcli_conn_protocol(cli->conn);
223
224         switch (protocol) {
225         case PROTOCOL_SMB2_02:
226                 name = "SMB2_02";
227                 break;
228         case PROTOCOL_SMB2_10:
229                 name = "SMB2_10";
230                 break;
231         case PROTOCOL_SMB2_22:
232                 name = "SMB2_22";
233                 break;
234         case PROTOCOL_SMB2_24:
235                 name = "SMB2_24";
236                 break;
237         default:
238                 break;
239         }
240
241         if (name) {
242                 printf("Server supports %s\n", name);
243         } else {
244                 printf("Server DOES NOT support SMB2\n");
245                 return false;
246         }
247
248         status = smbXcli_negprot(cli->conn, cli->timeout,
249                                  protocol, protocol);
250         if (!NT_STATUS_EQUAL(status, NT_STATUS_CONNECTION_RESET) &&
251             !NT_STATUS_EQUAL(status, NT_STATUS_CONNECTION_DISCONNECTED) &&
252             !NT_STATUS_EQUAL(status, NT_STATUS_CONNECTION_ABORTED)) {
253                 printf("2nd smbXcli_negprot should disconnect - returned %s\n",
254                         nt_errstr(status));
255                 return false;
256         }
257
258         if (smbXcli_conn_is_connected(cli->conn)) {
259                 printf("2nd smbXcli_negprot should disconnect "
260                        "- still connected\n");
261                 return false;
262         }
263
264         return true;
265 }
266
267 bool run_smb2_session_reconnect(int dummy)
268 {
269         struct cli_state *cli1;
270         struct cli_state *cli2;
271         NTSTATUS status;
272         bool ok;
273         uint64_t fid_persistent, fid_volatile;
274         struct tevent_context *ev;
275         struct tevent_req *subreq;
276         DATA_BLOB in_blob = data_blob_null;
277         DATA_BLOB out_blob;
278         DATA_BLOB session_key;
279         struct auth_generic_state *auth_generic_state;
280         struct iovec *recv_iov;
281         const char *hello = "Hello, world\n";
282         uint8_t *result;
283         uint32_t nread;
284
285         printf("Starting SMB2-SESSION-RECONNECT\n");
286
287         if (!torture_init_connection(&cli1)) {
288                 return false;
289         }
290         cli1->smb2.pid = 0xFEFF;
291
292         status = smbXcli_negprot(cli1->conn, cli1->timeout,
293                                  PROTOCOL_SMB2_02, PROTOCOL_SMB2_24);
294         if (!NT_STATUS_IS_OK(status)) {
295                 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
296                 return false;
297         }
298
299         status = cli_session_setup(cli1, username,
300                                    password, strlen(password),
301                                    password, strlen(password),
302                                    workgroup);
303         if (!NT_STATUS_IS_OK(status)) {
304                 printf("cli_session_setup returned %s\n", nt_errstr(status));
305                 return false;
306         }
307
308         status = cli_tree_connect(cli1, share, "?????", "", 0);
309         if (!NT_STATUS_IS_OK(status)) {
310                 printf("cli_tree_connect returned %s\n", nt_errstr(status));
311                 return false;
312         }
313
314         status = smb2cli_create(cli1, "session-reconnect.txt",
315                         SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
316                         SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
317                         SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
318                         FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
319                         FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
320                         FILE_CREATE, /* create_disposition, */
321                         FILE_DELETE_ON_CLOSE, /* create_options, */
322                         NULL, /* smb2_create_blobs *blobs */
323                         &fid_persistent,
324                         &fid_volatile);
325         if (!NT_STATUS_IS_OK(status)) {
326                 printf("smb2cli_create on cli1 %s\n", nt_errstr(status));
327                 return false;
328         }
329
330         status = smb2cli_write(cli1, strlen(hello), 0, fid_persistent,
331                                fid_volatile, 0, 0, (const uint8_t *)hello);
332         if (!NT_STATUS_IS_OK(status)) {
333                 printf("smb2cli_write returned %s\n", nt_errstr(status));
334                 return false;
335         }
336
337         status = smb2cli_flush(cli1, fid_persistent, fid_volatile);
338         if (!NT_STATUS_IS_OK(status)) {
339                 printf("smb2cli_flush returned %s\n", nt_errstr(status));
340                 return false;
341         }
342
343         status = smb2cli_read(cli1, 0x10000, 0, fid_persistent,
344                                fid_volatile, 2, 0,
345                                talloc_tos(), &result, &nread);
346         if (!NT_STATUS_IS_OK(status)) {
347                 printf("smb2cli_read returned %s\n", nt_errstr(status));
348                 return false;
349         }
350
351         if (nread != strlen(hello)) {
352                 printf("smb2cli_read returned %d bytes, expected %d\n",
353                        (int)nread, (int)strlen(hello));
354                 return false;
355         }
356
357         if (memcmp(hello, result, nread) != 0) {
358                 printf("smb2cli_read returned '%s', expected '%s'\n",
359                        result, hello);
360                 return false;
361         }
362
363         /* prepare second session */
364
365         if (!torture_init_connection(&cli2)) {
366                 return false;
367         }
368         cli2->smb2.pid = 0xFEFF;
369
370         status = smbXcli_negprot(cli2->conn, cli2->timeout,
371                                  PROTOCOL_SMB2_02, PROTOCOL_SMB2_24);
372         if (!NT_STATUS_IS_OK(status)) {
373                 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
374                 return false;
375         }
376
377         status = auth_generic_client_prepare(talloc_tos(), &auth_generic_state);
378         if (!NT_STATUS_IS_OK(status)) {
379                 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status));
380                 return false;
381         }
382
383         gensec_want_feature(auth_generic_state->gensec_security,
384                             GENSEC_FEATURE_SESSION_KEY);
385         status = auth_generic_set_username(auth_generic_state, username);
386         if (!NT_STATUS_IS_OK(status)) {
387                 printf("auth_generic_set_username returned %s\n", nt_errstr(status));
388                 return false;
389         }
390
391         status = auth_generic_set_domain(auth_generic_state, workgroup);
392         if (!NT_STATUS_IS_OK(status)) {
393                 printf("auth_generic_set_domain returned %s\n", nt_errstr(status));
394                 return false;
395         }
396
397         status = auth_generic_set_password(auth_generic_state, password);
398         if (!NT_STATUS_IS_OK(status)) {
399                 printf("auth_generic_set_password returned %s\n", nt_errstr(status));
400                 return false;
401         }
402
403         status = auth_generic_client_start(auth_generic_state, GENSEC_OID_NTLMSSP);
404         if (!NT_STATUS_IS_OK(status)) {
405                 printf("auth_generic_client_start returned %s\n", nt_errstr(status));
406                 return false;
407         }
408
409         ev = event_context_init(talloc_tos());
410         if (ev == NULL) {
411                 printf("event_context_init() returned NULL\n");
412                 return false;
413         }
414
415         status = gensec_update(auth_generic_state->gensec_security, talloc_tos(), ev, data_blob_null, &in_blob);
416         if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
417                 printf("gensec_update returned %s\n", nt_errstr(status));
418                 return false;
419         }
420
421         cli2->smb2.session = smbXcli_session_create(cli2, cli2->conn);
422
423         subreq = smb2cli_session_setup_send(talloc_tos(), ev,
424                                             cli2->conn,
425                                             cli2->timeout,
426                                             cli2->smb2.session,
427                                             0x0, /* in_flags */
428                                             SMB2_CAP_DFS, /* in_capabilities */
429                                             0, /* in_channel */
430                                             /* in_previous_session_id: */
431                                             smb2cli_session_current_id(cli1->smb2.session),
432                                             &in_blob); /* in_security_buffer */
433         if (subreq == NULL) {
434                 printf("smb2cli_session_setup_send() returned NULL\n");
435                 return false;
436         }
437
438         ok = tevent_req_poll(subreq, ev);
439         if (!ok) {
440                 printf("tevent_req_poll() returned false\n");
441                 return false;
442         }
443
444         status = smb2cli_session_setup_recv(subreq, talloc_tos(),
445                                             NULL, &out_blob);
446         if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
447                 printf("smb2cli_session_setup_recv returned %s\n",
448                         nt_errstr(status));
449                 return false;
450         }
451
452         status = gensec_update(auth_generic_state->gensec_security, talloc_tos(), ev, out_blob, &in_blob);
453         if (!NT_STATUS_IS_OK(status)) {
454                 printf("auth_generic_update returned %s\n", nt_errstr(status));
455                 return false;
456         }
457
458         subreq = smb2cli_session_setup_send(talloc_tos(), ev,
459                                             cli2->conn,
460                                             cli2->timeout,
461                                             cli2->smb2.session,
462                                             0x0, /* in_flags */
463                                             SMB2_CAP_DFS, /* in_capabilities */
464                                             0, /* in_channel */
465                                             /* in_previous_session_id: */
466                                             smb2cli_session_current_id(cli1->smb2.session),
467                                             &in_blob); /* in_security_buffer */
468         if (subreq == NULL) {
469                 printf("smb2cli_session_setup_send() returned NULL\n");
470                 return false;
471         }
472
473         ok = tevent_req_poll(subreq, ev);
474         if (!ok) {
475                 printf("tevent_req_poll() returned false\n");
476                 return false;
477         }
478
479         status = smb2cli_session_setup_recv(subreq, talloc_tos(),
480                                             &recv_iov, &out_blob);
481         if (!NT_STATUS_IS_OK(status)) {
482                 printf("smb2cli_session_setup_recv returned %s\n",
483                         nt_errstr(status));
484                 return false;
485         }
486
487         status = gensec_session_key(auth_generic_state->gensec_security, talloc_tos(),
488                                     &session_key);
489         if (!NT_STATUS_IS_OK(status)) {
490                 printf("gensec_session_key returned %s\n",
491                         nt_errstr(status));
492                 return false;
493         }
494
495         /* check file operation on the old client */
496
497         status = smb2cli_flush(cli1, fid_persistent, fid_volatile);
498         if (!NT_STATUS_EQUAL(status, NT_STATUS_USER_SESSION_DELETED)) {
499                 printf("smb2cli_flush returned %s\n", nt_errstr(status));
500                 return false;
501         }
502
503         status = cli_tree_connect(cli1, share, "?????", "", 0);
504         if (!NT_STATUS_EQUAL(status, NT_STATUS_USER_SESSION_DELETED)) {
505                 printf("cli_tree_connect returned %s\n", nt_errstr(status));
506                 return false;
507         }
508
509         /*
510          * checking file operations without signing.
511          * on w2k8r2 at least, flush, read and write also work the same way,
512          * while create gives ACCESS_DENIED without signing
513          */
514         status = smb2cli_flush(cli2, fid_persistent, fid_volatile);
515         if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED)) {
516                 printf("smb2cli_flush returned %s\n", nt_errstr(status));
517                 return false;
518         }
519
520         status = smb2cli_write(cli2, strlen(hello), 0, fid_persistent,
521                                fid_volatile, 0, 0, (const uint8_t *)hello);
522         if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED)) {
523                 printf("smb2cli_write returned %s\n", nt_errstr(status));
524                 return false;
525         }
526
527         status = smb2cli_read(cli2, 0x10000, 0, fid_persistent,
528                                fid_volatile, 2, 0,
529                                talloc_tos(), &result, &nread);
530         if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED)) {
531                 printf("smb2cli_read returned %s\n", nt_errstr(status));
532                 return false;
533         }
534
535         status = smb2cli_create(cli2, "session-reconnect.txt",
536                         SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
537                         SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
538                         SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
539                         FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
540                         FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
541                         FILE_CREATE, /* create_disposition, */
542                         FILE_DELETE_ON_CLOSE, /* create_options, */
543                         NULL, /* smb2_create_blobs *blobs */
544                         &fid_persistent,
545                         &fid_volatile);
546         if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED) &&
547             !NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED)) {
548                 printf("smb2cli_create on cli2 %s\n", nt_errstr(status));
549                 return false;
550         }
551
552         /* now grab the session key and try with signing */
553
554         status = smb2cli_session_set_session_key(cli2->smb2.session,
555                                                  session_key,
556                                                  recv_iov);
557         if (!NT_STATUS_IS_OK(status)) {
558                 printf("smb2cli_session_set_session_key %s\n", nt_errstr(status));
559                 return false;
560         }
561
562         /* the tid seems to be irrelevant at this stage */
563
564         cli2->smb2.tid = cli1->smb2.tid;
565
566         status = smb2cli_flush(cli2, fid_persistent, fid_volatile);
567         if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED)) {
568                 printf("smb2cli_flush returned %s\n", nt_errstr(status));
569                 return false;
570         }
571
572         status = smb2cli_write(cli2, strlen(hello), 0, fid_persistent,
573                                fid_volatile, 0, 0, (const uint8_t *)hello);
574         if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED)) {
575                 printf("smb2cli_write returned %s\n", nt_errstr(status));
576                 return false;
577         }
578
579         status = smb2cli_read(cli2, 0x10000, 0, fid_persistent,
580                                fid_volatile, 2, 0,
581                                talloc_tos(), &result, &nread);
582         if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED)) {
583                 printf("smb2cli_read returned %s\n", nt_errstr(status));
584                 return false;
585         }
586
587         status = smb2cli_create(cli2, "session-reconnect.txt",
588                         SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
589                         SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
590                         SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
591                         FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
592                         FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
593                         FILE_CREATE, /* create_disposition, */
594                         FILE_DELETE_ON_CLOSE, /* create_options, */
595                         NULL, /* smb2_create_blobs *blobs */
596                         &fid_persistent,
597                         &fid_volatile);
598         if (!NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED)) {
599                 printf("smb2cli_create on cli2 %s\n", nt_errstr(status));
600                 return false;
601         }
602
603         /* now do a new tcon and test file calls again */
604
605         status = cli_tree_connect(cli2, share, "?????", "", 0);
606         if (!NT_STATUS_IS_OK(status)) {
607                 printf("cli_tree_connect returned %s\n", nt_errstr(status));
608                 return false;
609         }
610
611         status = smb2cli_create(cli2, "session-reconnect.txt",
612                         SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
613                         SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
614                         SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
615                         FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
616                         FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
617                         FILE_CREATE, /* create_disposition, */
618                         FILE_DELETE_ON_CLOSE, /* create_options, */
619                         NULL, /* smb2_create_blobs *blobs */
620                         &fid_persistent,
621                         &fid_volatile);
622         if (!NT_STATUS_IS_OK(status)) {
623                 printf("smb2cli_create on cli2 %s\n", nt_errstr(status));
624                 return false;
625         }
626
627         status = smb2cli_write(cli2, strlen(hello), 0, fid_persistent,
628                                fid_volatile, 0, 0, (const uint8_t *)hello);
629         if (!NT_STATUS_IS_OK(status)) {
630                 printf("smb2cli_write returned %s\n", nt_errstr(status));
631                 return false;
632         }
633
634         status = smb2cli_flush(cli2, fid_persistent, fid_volatile);
635         if (!NT_STATUS_IS_OK(status)) {
636                 printf("smb2cli_flush returned %s\n", nt_errstr(status));
637                 return false;
638         }
639
640         status = smb2cli_read(cli2, 0x10000, 0, fid_persistent,
641                                fid_volatile, 2, 0,
642                                talloc_tos(), &result, &nread);
643         if (!NT_STATUS_IS_OK(status)) {
644                 printf("smb2cli_read returned %s\n", nt_errstr(status));
645                 return false;
646         }
647
648         if (nread != strlen(hello)) {
649                 printf("smb2cli_read returned %d bytes, expected %d\n",
650                        (int)nread, (int)strlen(hello));
651                 return false;
652         }
653
654         if (memcmp(hello, result, nread) != 0) {
655                 printf("smb2cli_read returned '%s', expected '%s'\n",
656                        result, hello);
657                 return false;
658         }
659
660         return true;
661 }
662
663 bool run_smb2_tcon_dependence(int dummy)
664 {
665         struct cli_state *cli;
666         NTSTATUS status;
667         uint64_t fid_persistent, fid_volatile;
668         const char *hello = "Hello, world\n";
669         uint8_t *result;
670         uint32_t nread;
671
672         printf("Starting SMB2-TCON-DEPENDENCE\n");
673
674         if (!torture_init_connection(&cli)) {
675                 return false;
676         }
677         cli->smb2.pid = 0xFEFF;
678
679         status = smbXcli_negprot(cli->conn, cli->timeout,
680                                  PROTOCOL_SMB2_02, PROTOCOL_SMB2_24);
681         if (!NT_STATUS_IS_OK(status)) {
682                 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
683                 return false;
684         }
685
686         status = cli_session_setup(cli, username,
687                                    password, strlen(password),
688                                    password, strlen(password),
689                                    workgroup);
690         if (!NT_STATUS_IS_OK(status)) {
691                 printf("cli_session_setup returned %s\n", nt_errstr(status));
692                 return false;
693         }
694
695         status = cli_tree_connect(cli, share, "?????", "", 0);
696         if (!NT_STATUS_IS_OK(status)) {
697                 printf("cli_tree_connect returned %s\n", nt_errstr(status));
698                 return false;
699         }
700
701         status = smb2cli_create(cli, "tcon_depedence.txt",
702                         SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
703                         SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
704                         SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
705                         FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
706                         FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
707                         FILE_CREATE, /* create_disposition, */
708                         FILE_DELETE_ON_CLOSE, /* create_options, */
709                         NULL, /* smb2_create_blobs *blobs */
710                         &fid_persistent,
711                         &fid_volatile);
712         if (!NT_STATUS_IS_OK(status)) {
713                 printf("smb2cli_create on cli %s\n", nt_errstr(status));
714                 return false;
715         }
716
717         status = smb2cli_write(cli, strlen(hello), 0, fid_persistent,
718                                fid_volatile, 0, 0, (const uint8_t *)hello);
719         if (!NT_STATUS_IS_OK(status)) {
720                 printf("smb2cli_write returned %s\n", nt_errstr(status));
721                 return false;
722         }
723
724         status = smb2cli_flush(cli, fid_persistent, fid_volatile);
725         if (!NT_STATUS_IS_OK(status)) {
726                 printf("smb2cli_flush returned %s\n", nt_errstr(status));
727                 return false;
728         }
729
730         status = smb2cli_read(cli, 0x10000, 0, fid_persistent,
731                                fid_volatile, 2, 0,
732                                talloc_tos(), &result, &nread);
733         if (!NT_STATUS_IS_OK(status)) {
734                 printf("smb2cli_read returned %s\n", nt_errstr(status));
735                 return false;
736         }
737
738         if (nread != strlen(hello)) {
739                 printf("smb2cli_read returned %d bytes, expected %d\n",
740                        (int)nread, (int)strlen(hello));
741                 return false;
742         }
743
744         if (memcmp(hello, result, nread) != 0) {
745                 printf("smb2cli_read returned '%s', expected '%s'\n",
746                        result, hello);
747                 return false;
748         }
749
750         /* check behaviour with wrong tid... */
751
752         cli->smb2.tid++;
753
754         status = smb2cli_read(cli, 0x10000, 0, fid_persistent,
755                                fid_volatile, 2, 0,
756                                talloc_tos(), &result, &nread);
757         if (!NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED)) {
758                 printf("smb2cli_read returned %s\n", nt_errstr(status));
759                 return false;
760         }
761
762         cli->smb2.tid--;
763
764         return true;
765 }
766
767 bool run_smb2_multi_channel(int dummy)
768 {
769         struct cli_state *cli1;
770         struct cli_state *cli2;
771         struct cli_state *cli3;
772         NTSTATUS status;
773         bool ok;
774         uint64_t fid_persistent, fid_volatile;
775         struct tevent_context *ev;
776         struct tevent_req *subreq;
777         DATA_BLOB in_blob = data_blob_null;
778         DATA_BLOB out_blob;
779         DATA_BLOB channel_session_key;
780         struct auth_generic_state *auth_generic_state;
781         struct iovec *recv_iov;
782         const char *hello = "Hello, world\n";
783         uint8_t *result;
784         uint32_t nread;
785
786         printf("Starting SMB2-MULTI-CHANNEL\n");
787
788         if (!torture_init_connection(&cli1)) {
789                 return false;
790         }
791         cli1->smb2.pid = 0xFEFF;
792
793         if (!torture_init_connection(&cli2)) {
794                 return false;
795         }
796         cli2->smb2.pid = 0xFEFF;
797
798         if (!torture_init_connection(&cli3)) {
799                 return false;
800         }
801         cli3->smb2.pid = 0xFEFF;
802
803         status = smbXcli_negprot(cli1->conn, cli1->timeout,
804                                  PROTOCOL_SMB2_22, PROTOCOL_SMB2_24);
805         if (!NT_STATUS_IS_OK(status)) {
806                 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
807                 return false;
808         }
809
810         status = smbXcli_negprot(cli2->conn, cli2->timeout,
811                                  PROTOCOL_SMB2_22, PROTOCOL_SMB2_24);
812         if (!NT_STATUS_IS_OK(status)) {
813                 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
814                 return false;
815         }
816
817         status = smbXcli_negprot(cli3->conn, cli3->timeout,
818                                  PROTOCOL_SMB2_22, PROTOCOL_SMB2_24);
819         if (!NT_STATUS_IS_OK(status)) {
820                 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
821                 return false;
822         }
823
824         status = cli_session_setup(cli1, username,
825                                    password, strlen(password),
826                                    password, strlen(password),
827                                    workgroup);
828         if (!NT_STATUS_IS_OK(status)) {
829                 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status));
830                 return false;
831         }
832
833         status = cli_tree_connect(cli1, share, "?????", "", 0);
834         if (!NT_STATUS_IS_OK(status)) {
835                 printf("cli_tree_connect returned %s\n", nt_errstr(status));
836                 return false;
837         }
838
839         status = smb2cli_session_create_channel(cli2,
840                                                 cli1->smb2.session,
841                                                 cli2->conn,
842                                                 &cli2->smb2.session);
843         if (!NT_STATUS_IS_OK(status)) {
844                 printf("smb2cli_session_create_channel returned %s\n",
845                         nt_errstr(status));
846                 return false;
847         }
848
849         status = auth_generic_client_prepare(talloc_tos(), &auth_generic_state);
850         if (!NT_STATUS_IS_OK(status)) {
851                 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status));
852                 return false;
853         }
854
855         gensec_want_feature(auth_generic_state->gensec_security,
856                             GENSEC_FEATURE_SESSION_KEY);
857         status = auth_generic_set_username(auth_generic_state, username);
858         if (!NT_STATUS_IS_OK(status)) {
859                 printf("auth_generic_set_username returned %s\n", nt_errstr(status));
860                 return false;
861         }
862
863         status = auth_generic_set_domain(auth_generic_state, workgroup);
864         if (!NT_STATUS_IS_OK(status)) {
865                 printf("auth_generic_set_domain returned %s\n", nt_errstr(status));
866                 return false;
867         }
868
869         status = auth_generic_set_password(auth_generic_state, password);
870         if (!NT_STATUS_IS_OK(status)) {
871                 printf("auth_generic_set_password returned %s\n", nt_errstr(status));
872                 return false;
873         }
874
875         status = auth_generic_client_start(auth_generic_state, GENSEC_OID_NTLMSSP);
876         if (!NT_STATUS_IS_OK(status)) {
877                 printf("auth_generic_client_start returned %s\n", nt_errstr(status));
878                 return false;
879         }
880
881         ev = event_context_init(talloc_tos());
882         if (ev == NULL) {
883                 printf("event_context_init() returned NULL\n");
884                 return false;
885         }
886
887         status = gensec_update(auth_generic_state->gensec_security, talloc_tos(), ev, data_blob_null, &in_blob);
888         if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
889                 printf("gensec_update returned %s\n", nt_errstr(status));
890                 return false;
891         }
892
893         subreq = smb2cli_session_setup_send(talloc_tos(), ev,
894                                             cli2->conn,
895                                             cli2->timeout,
896                                             cli2->smb2.session,
897                                             0x01, /* in_flags */
898                                             SMB2_CAP_DFS, /* in_capabilities */
899                                             0, /* in_channel */
900                                             0, /* in_previous_session_id */
901                                             &in_blob); /* in_security_buffer */
902         if (subreq == NULL) {
903                 printf("smb2cli_session_setup_send() returned NULL\n");
904                 return false;
905         }
906
907         ok = tevent_req_poll(subreq, ev);
908         if (!ok) {
909                 printf("tevent_req_poll() returned false\n");
910                 return false;
911         }
912
913         status = smb2cli_session_setup_recv(subreq, talloc_tos(),
914                                             NULL, &out_blob);
915         if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
916                 printf("smb2cli_session_setup_recv returned %s\n",
917                         nt_errstr(status));
918                 return false;
919         }
920
921         status = gensec_update(auth_generic_state->gensec_security, talloc_tos(), ev, out_blob, &in_blob);
922         if (!NT_STATUS_IS_OK(status)) {
923                 printf("auth_generic_update returned %s\n", nt_errstr(status));
924                 return false;
925         }
926
927         subreq = smb2cli_session_setup_send(talloc_tos(), ev,
928                                             cli2->conn,
929                                             cli2->timeout,
930                                             cli2->smb2.session,
931                                             0x01, /* in_flags */
932                                             SMB2_CAP_DFS, /* in_capabilities */
933                                             0, /* in_channel */
934                                             0, /* in_previous_session_id */
935                                             &in_blob); /* in_security_buffer */
936         if (subreq == NULL) {
937                 printf("smb2cli_session_setup_send() returned NULL\n");
938                 return false;
939         }
940
941         ok = tevent_req_poll(subreq, ev);
942         if (!ok) {
943                 printf("tevent_req_poll() returned false\n");
944                 return false;
945         }
946
947         status = smb2cli_session_setup_recv(subreq, talloc_tos(),
948                                             &recv_iov, &out_blob);
949         if (!NT_STATUS_IS_OK(status)) {
950                 printf("smb2cli_session_setup_recv returned %s\n",
951                         nt_errstr(status));
952                 return false;
953         }
954
955         status = gensec_session_key(auth_generic_state->gensec_security, talloc_tos(),
956                                     &channel_session_key);
957         if (!NT_STATUS_IS_OK(status)) {
958                 printf("gensec_session_key returned %s\n",
959                         nt_errstr(status));
960                 return false;
961         }
962
963         status = smb2cli_session_set_channel_key(cli2->smb2.session,
964                                                  channel_session_key,
965                                                  recv_iov);
966         if (!NT_STATUS_IS_OK(status)) {
967                 printf("smb2cli_session_set_channel_key %s\n", nt_errstr(status));
968                 return false;
969         }
970
971         cli2->smb2.tid = cli1->smb2.tid;
972
973         status = smb2cli_session_create_channel(cli3,
974                                                 cli2->smb2.session,
975                                                 cli3->conn,
976                                                 &cli3->smb2.session);
977         if (!NT_STATUS_IS_OK(status)) {
978                 printf("smb2cli_session_create_channel returned %s\n",
979                         nt_errstr(status));
980                 return false;
981         }
982
983         status = auth_generic_client_prepare(talloc_tos(), &auth_generic_state);
984         if (!NT_STATUS_IS_OK(status)) {
985                 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status));
986                 return false;
987         }
988
989         gensec_want_feature(auth_generic_state->gensec_security,
990                             GENSEC_FEATURE_SESSION_KEY);
991         status = auth_generic_set_username(auth_generic_state, username);
992         if (!NT_STATUS_IS_OK(status)) {
993                 printf("auth_generic_set_username returned %s\n", nt_errstr(status));
994                 return false;
995         }
996
997         status = auth_generic_set_domain(auth_generic_state, workgroup);
998         if (!NT_STATUS_IS_OK(status)) {
999                 printf("auth_generic_set_domain returned %s\n", nt_errstr(status));
1000                 return false;
1001         }
1002
1003         status = auth_generic_set_password(auth_generic_state, password);
1004         if (!NT_STATUS_IS_OK(status)) {
1005                 printf("auth_generic_set_password returned %s\n", nt_errstr(status));
1006                 return false;
1007         }
1008
1009         status = auth_generic_client_start(auth_generic_state, GENSEC_OID_NTLMSSP);
1010         if (!NT_STATUS_IS_OK(status)) {
1011                 printf("auth_generic_client_start returned %s\n", nt_errstr(status));
1012                 return false;
1013         }
1014
1015         status = gensec_update(auth_generic_state->gensec_security, talloc_tos(), ev, data_blob_null, &in_blob);
1016         if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
1017                 printf("gensec_update returned %s\n", nt_errstr(status));
1018                 return false;
1019         }
1020
1021         subreq = smb2cli_session_setup_send(talloc_tos(), ev,
1022                                             cli3->conn,
1023                                             cli3->timeout,
1024                                             cli3->smb2.session,
1025                                             0x01, /* in_flags */
1026                                             SMB2_CAP_DFS, /* in_capabilities */
1027                                             0, /* in_channel */
1028                                             0, /* in_previous_session_id */
1029                                             &in_blob); /* in_security_buffer */
1030         if (subreq == NULL) {
1031                 printf("smb2cli_session_setup_send() returned NULL\n");
1032                 return false;
1033         }
1034
1035         ok = tevent_req_poll(subreq, ev);
1036         if (!ok) {
1037                 printf("tevent_req_poll() returned false\n");
1038                 return false;
1039         }
1040
1041         status = smb2cli_session_setup_recv(subreq, talloc_tos(),
1042                                             NULL, &out_blob);
1043         if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
1044                 printf("smb2cli_session_setup_recv returned %s\n",
1045                         nt_errstr(status));
1046                 return false;
1047         }
1048
1049         status = gensec_update(auth_generic_state->gensec_security, talloc_tos(), ev, out_blob, &in_blob);
1050         if (!NT_STATUS_IS_OK(status)) {
1051                 printf("auth_generic_update returned %s\n", nt_errstr(status));
1052                 return false;
1053         }
1054
1055         subreq = smb2cli_session_setup_send(talloc_tos(), ev,
1056                                             cli3->conn,
1057                                             cli3->timeout,
1058                                             cli3->smb2.session,
1059                                             0x01, /* in_flags */
1060                                             SMB2_CAP_DFS, /* in_capabilities */
1061                                             0, /* in_channel */
1062                                             0, /* in_previous_session_id */
1063                                             &in_blob); /* in_security_buffer */
1064         if (subreq == NULL) {
1065                 printf("smb2cli_session_setup_send() returned NULL\n");
1066                 return false;
1067         }
1068
1069         ok = tevent_req_poll(subreq, ev);
1070         if (!ok) {
1071                 printf("tevent_req_poll() returned false\n");
1072                 return false;
1073         }
1074
1075         status = smb2cli_session_setup_recv(subreq, talloc_tos(),
1076                                             &recv_iov, &out_blob);
1077         if (!NT_STATUS_IS_OK(status)) {
1078                 printf("smb2cli_session_setup_recv returned %s\n",
1079                         nt_errstr(status));
1080                 return false;
1081         }
1082
1083         status = gensec_session_key(auth_generic_state->gensec_security, talloc_tos(),
1084                                     &channel_session_key);
1085         if (!NT_STATUS_IS_OK(status)) {
1086                 printf("gensec_session_key returned %s\n",
1087                         nt_errstr(status));
1088                 return false;
1089         }
1090
1091         status = smb2cli_session_set_channel_key(cli3->smb2.session,
1092                                                  channel_session_key,
1093                                                  recv_iov);
1094         if (!NT_STATUS_IS_OK(status)) {
1095                 printf("smb2cli_session_set_channel_key %s\n", nt_errstr(status));
1096                 return false;
1097         }
1098
1099         cli3->smb2.tid = cli2->smb2.tid;
1100
1101         status = smb2cli_create(cli2, "multi-channel.txt",
1102                         SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1103                         SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1104                         SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
1105                         FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
1106                         FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1107                         FILE_CREATE, /* create_disposition, */
1108                         FILE_DELETE_ON_CLOSE, /* create_options, */
1109                         NULL, /* smb2_create_blobs *blobs */
1110                         &fid_persistent,
1111                         &fid_volatile);
1112         if (!NT_STATUS_IS_OK(status)) {
1113                 printf("smb2cli_create on cli2 %s\n", nt_errstr(status));
1114                 return false;
1115         }
1116
1117         status = smb2cli_write(cli1, strlen(hello), 0, fid_persistent,
1118                                fid_volatile, 0, 0, (const uint8_t *)hello);
1119         if (!NT_STATUS_IS_OK(status)) {
1120                 printf("smb2cli_write returned %s\n", nt_errstr(status));
1121                 return false;
1122         }
1123
1124         status = smb2cli_flush(cli2, fid_persistent, fid_volatile);
1125         if (!NT_STATUS_IS_OK(status)) {
1126                 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1127                 return false;
1128         }
1129
1130         status = smb2cli_flush(cli1, fid_persistent, fid_volatile);
1131         if (!NT_STATUS_IS_OK(status)) {
1132                 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1133                 return false;
1134         }
1135
1136         status = smb2cli_flush(cli3, fid_persistent, fid_volatile);
1137         if (!NT_STATUS_IS_OK(status)) {
1138                 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1139                 return false;
1140         }
1141
1142         status = smb2cli_read(cli2, 0x10000, 0, fid_persistent,
1143                                fid_volatile, 2, 0,
1144                                talloc_tos(), &result, &nread);
1145         if (!NT_STATUS_IS_OK(status)) {
1146                 printf("smb2cli_read returned %s\n", nt_errstr(status));
1147                 return false;
1148         }
1149
1150         if (nread != strlen(hello)) {
1151                 printf("smb2cli_read returned %d bytes, expected %d\n",
1152                        (int)nread, (int)strlen(hello));
1153                 return false;
1154         }
1155
1156         if (memcmp(hello, result, nread) != 0) {
1157                 printf("smb2cli_read returned '%s', expected '%s'\n",
1158                        result, hello);
1159                 return false;
1160         }
1161
1162         status = auth_generic_client_prepare(talloc_tos(), &auth_generic_state);
1163         if (!NT_STATUS_IS_OK(status)) {
1164                 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status));
1165                 return false;
1166         }
1167
1168         gensec_want_feature(auth_generic_state->gensec_security,
1169                             GENSEC_FEATURE_SESSION_KEY);
1170         status = auth_generic_set_username(auth_generic_state, username);
1171         if (!NT_STATUS_IS_OK(status)) {
1172                 printf("auth_generic_set_username returned %s\n", nt_errstr(status));
1173                 return false;
1174         }
1175
1176         status = auth_generic_set_domain(auth_generic_state, workgroup);
1177         if (!NT_STATUS_IS_OK(status)) {
1178                 printf("auth_generic_set_domain returned %s\n", nt_errstr(status));
1179                 return false;
1180         }
1181
1182         status = auth_generic_set_password(auth_generic_state, password);
1183         if (!NT_STATUS_IS_OK(status)) {
1184                 printf("auth_generic_set_password returned %s\n", nt_errstr(status));
1185                 return false;
1186         }
1187
1188         status = auth_generic_client_start(auth_generic_state, GENSEC_OID_NTLMSSP);
1189         if (!NT_STATUS_IS_OK(status)) {
1190                 printf("auth_generic_client_start returned %s\n", nt_errstr(status));
1191                 return false;
1192         }
1193
1194         status = gensec_update(auth_generic_state->gensec_security, talloc_tos(), ev, data_blob_null, &in_blob);
1195         if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
1196                 printf("gensec_update returned %s\n", nt_errstr(status));
1197                 return false;
1198         }
1199
1200         subreq = smb2cli_session_setup_send(talloc_tos(), ev,
1201                                             cli3->conn,
1202                                             cli3->timeout,
1203                                             cli3->smb2.session,
1204                                             0x0, /* in_flags */
1205                                             SMB2_CAP_DFS, /* in_capabilities */
1206                                             0, /* in_channel */
1207                                             0, /* in_previous_session_id */
1208                                             &in_blob); /* in_security_buffer */
1209         if (subreq == NULL) {
1210                 printf("smb2cli_session_setup_send() returned NULL\n");
1211                 return false;
1212         }
1213
1214         ok = tevent_req_poll(subreq, ev);
1215         if (!ok) {
1216                 printf("tevent_req_poll() returned false\n");
1217                 return false;
1218         }
1219
1220         status = smb2cli_session_setup_recv(subreq, talloc_tos(),
1221                                             NULL, &out_blob);
1222         if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
1223                 printf("smb2cli_session_setup_recv returned %s\n",
1224                         nt_errstr(status));
1225                 return false;
1226         }
1227
1228         status = gensec_update(auth_generic_state->gensec_security, talloc_tos(), ev, out_blob, &in_blob);
1229         if (!NT_STATUS_IS_OK(status)) {
1230                 printf("auth_generic_update returned %s\n", nt_errstr(status));
1231                 return false;
1232         }
1233
1234         status = smb2cli_flush(cli1, fid_persistent, fid_volatile);
1235         if (!NT_STATUS_IS_OK(status)) {
1236                 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1237                 return false;
1238         }
1239
1240         status = smb2cli_flush(cli2, fid_persistent, fid_volatile);
1241         if (!NT_STATUS_IS_OK(status)) {
1242                 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1243                 return false;
1244         }
1245
1246         status = smb2cli_flush(cli3, fid_persistent, fid_volatile);
1247         if (!NT_STATUS_IS_OK(status)) {
1248                 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1249                 return false;
1250         }
1251
1252         status = smb2cli_create(cli1, "multi-channel-invalid.txt",
1253                         SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1254                         SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1255                         SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
1256                         FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
1257                         FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1258                         FILE_CREATE, /* create_disposition, */
1259                         FILE_DELETE_ON_CLOSE, /* create_options, */
1260                         NULL, /* smb2_create_blobs *blobs */
1261                         &fid_persistent,
1262                         &fid_volatile);
1263         if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1264                 printf("smb2cli_create %s\n", nt_errstr(status));
1265                 return false;
1266         }
1267
1268         status = smb2cli_create(cli2, "multi-channel-invalid.txt",
1269                         SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1270                         SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1271                         SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
1272                         FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
1273                         FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1274                         FILE_CREATE, /* create_disposition, */
1275                         FILE_DELETE_ON_CLOSE, /* create_options, */
1276                         NULL, /* smb2_create_blobs *blobs */
1277                         &fid_persistent,
1278                         &fid_volatile);
1279         if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1280                 printf("smb2cli_create %s\n", nt_errstr(status));
1281                 return false;
1282         }
1283
1284         status = smb2cli_create(cli3, "multi-channel-invalid.txt",
1285                         SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1286                         SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1287                         SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
1288                         FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
1289                         FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1290                         FILE_CREATE, /* create_disposition, */
1291                         FILE_DELETE_ON_CLOSE, /* create_options, */
1292                         NULL, /* smb2_create_blobs *blobs */
1293                         &fid_persistent,
1294                         &fid_volatile);
1295         if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1296                 printf("smb2cli_create %s\n", nt_errstr(status));
1297                 return false;
1298         }
1299
1300         subreq = smb2cli_session_setup_send(talloc_tos(), ev,
1301                                             cli2->conn,
1302                                             cli2->timeout,
1303                                             cli2->smb2.session,
1304                                             0x0, /* in_flags */
1305                                             SMB2_CAP_DFS, /* in_capabilities */
1306                                             0, /* in_channel */
1307                                             0, /* in_previous_session_id */
1308                                             &in_blob); /* in_security_buffer */
1309         if (subreq == NULL) {
1310                 printf("smb2cli_session_setup_send() returned NULL\n");
1311                 return false;
1312         }
1313
1314         ok = tevent_req_poll(subreq, ev);
1315         if (!ok) {
1316                 printf("tevent_req_poll() returned false\n");
1317                 return false;
1318         }
1319
1320         status = smb2cli_session_setup_recv(subreq, talloc_tos(),
1321                                             &recv_iov, &out_blob);
1322         if (!NT_STATUS_IS_OK(status)) {
1323                 printf("smb2cli_session_setup_recv returned %s\n",
1324                         nt_errstr(status));
1325                 return false;
1326         }
1327
1328         status = smb2cli_close(cli3, 0, fid_persistent, fid_volatile);
1329         if (!NT_STATUS_IS_OK(status)) {
1330                 printf("smb2cli_close returned %s\n", nt_errstr(status));
1331                 return false;
1332         }
1333
1334         status = smb2cli_flush(cli3, fid_persistent, fid_volatile);
1335         if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED)) {
1336                 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1337                 return false;
1338         }
1339
1340         status = smb2cli_flush(cli2, fid_persistent, fid_volatile);
1341         if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED)) {
1342                 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1343                 return false;
1344         }
1345
1346         status = smb2cli_flush(cli1, fid_persistent, fid_volatile);
1347         if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED)) {
1348                 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1349                 return false;
1350         }
1351
1352         return true;
1353 }
1354
1355 bool run_smb2_session_reauth(int dummy)
1356 {
1357         struct cli_state *cli;
1358         NTSTATUS status;
1359         bool ok;
1360         uint64_t fid_persistent, fid_volatile;
1361         uint64_t dir_persistent, dir_volatile;
1362         uint8_t *dir_data;
1363         uint32_t dir_data_length;
1364         struct tevent_context *ev;
1365         struct tevent_req *subreq;
1366         DATA_BLOB in_blob = data_blob_null;
1367         DATA_BLOB out_blob;
1368         DATA_BLOB in_input_buffer;
1369         DATA_BLOB out_output_buffer;
1370         uint8_t in_file_info_class;
1371         struct auth_generic_state *auth_generic_state;
1372         struct iovec *recv_iov;
1373         uint32_t saved_tid;
1374
1375         printf("Starting SMB2-SESSION_REAUTH\n");
1376
1377         if (!torture_init_connection(&cli)) {
1378                 return false;
1379         }
1380         cli->smb2.pid = 0xFEFF;
1381
1382         /*
1383          * PROTOCOL_SMB2_22 has a bug in win8pre0
1384          * it behaves like PROTOCOL_SMB2_02
1385          * and returns NT_STATUS_REQUEST_NOT_ACCEPTED,
1386          * while it allows it on PROTOCOL_SMB2_02.
1387          */
1388         status = smbXcli_negprot(cli->conn, cli->timeout,
1389                                  PROTOCOL_SMB2_10, PROTOCOL_SMB2_10);
1390         if (!NT_STATUS_IS_OK(status)) {
1391                 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
1392                 return false;
1393         }
1394
1395         status = cli_session_setup(cli, username,
1396                                    password, strlen(password),
1397                                    password, strlen(password),
1398                                    workgroup);
1399         if (!NT_STATUS_IS_OK(status)) {
1400                 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status));
1401                 return false;
1402         }
1403
1404         status = cli_tree_connect(cli, share, "?????", "", 0);
1405         if (!NT_STATUS_IS_OK(status)) {
1406                 printf("cli_tree_connect returned %s\n", nt_errstr(status));
1407                 return false;
1408         }
1409
1410         status = smb2cli_create(cli, "session-reauth.txt",
1411                         SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1412                         SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1413                         SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
1414                         FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
1415                         FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1416                         FILE_CREATE, /* create_disposition, */
1417                         FILE_DELETE_ON_CLOSE, /* create_options, */
1418                         NULL, /* smb2_create_blobs *blobs */
1419                         &fid_persistent,
1420                         &fid_volatile);
1421         if (!NT_STATUS_IS_OK(status)) {
1422                 printf("smb2cli_create %s\n", nt_errstr(status));
1423                 return false;
1424         }
1425
1426         status = smb2cli_create(cli, "",
1427                         SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1428                         SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1429                         SEC_STD_SYNCHRONIZE|
1430                         SEC_DIR_LIST|
1431                         SEC_DIR_READ_ATTRIBUTE, /* desired_access, */
1432                         0, /* file_attributes, */
1433                         FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1434                         FILE_OPEN, /* create_disposition, */
1435                         FILE_SYNCHRONOUS_IO_NONALERT|FILE_DIRECTORY_FILE, /* create_options, */
1436                         NULL, /* smb2_create_blobs *blobs */
1437                         &dir_persistent,
1438                         &dir_volatile);
1439         if (!NT_STATUS_IS_OK(status)) {
1440                 printf("smb2cli_create returned %s\n", nt_errstr(status));
1441                 return false;
1442         }
1443
1444         status = smb2cli_query_directory(
1445                 cli, 1, 0x3, 0, dir_persistent, dir_volatile,
1446                 "session-reauth.txt", 0xffff,
1447                 talloc_tos(), &dir_data, &dir_data_length);
1448         if (!NT_STATUS_IS_OK(status)) {
1449                 printf("smb2cli_query_directory returned %s\n", nt_errstr(status));
1450                 return false;
1451         }
1452
1453         status = auth_generic_client_prepare(talloc_tos(), &auth_generic_state);
1454         if (!NT_STATUS_IS_OK(status)) {
1455                 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status));
1456                 return false;
1457         }
1458
1459         gensec_want_feature(auth_generic_state->gensec_security,
1460                             GENSEC_FEATURE_SESSION_KEY);
1461         status = auth_generic_set_username(auth_generic_state, username);
1462         if (!NT_STATUS_IS_OK(status)) {
1463                 printf("auth_generic_set_username returned %s\n", nt_errstr(status));
1464                 return false;
1465         }
1466
1467         status = auth_generic_set_domain(auth_generic_state, workgroup);
1468         if (!NT_STATUS_IS_OK(status)) {
1469                 printf("auth_generic_set_domain returned %s\n", nt_errstr(status));
1470                 return false;
1471         }
1472
1473         status = auth_generic_set_password(auth_generic_state, password);
1474         if (!NT_STATUS_IS_OK(status)) {
1475                 printf("auth_generic_set_password returned %s\n", nt_errstr(status));
1476                 return false;
1477         }
1478
1479         status = auth_generic_client_start(auth_generic_state, GENSEC_OID_NTLMSSP);
1480         if (!NT_STATUS_IS_OK(status)) {
1481                 printf("auth_generic_client_start returned %s\n", nt_errstr(status));
1482                 return false;
1483         }
1484
1485         ev = event_context_init(talloc_tos());
1486         if (ev == NULL) {
1487                 printf("event_context_init() returned NULL\n");
1488                 return false;
1489         }
1490
1491         status = gensec_update(auth_generic_state->gensec_security, talloc_tos(), ev, data_blob_null, &in_blob);
1492         if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
1493                 printf("gensec_update returned %s\n", nt_errstr(status));
1494                 return false;
1495         }
1496
1497         subreq = smb2cli_session_setup_send(talloc_tos(), ev,
1498                                             cli->conn,
1499                                             cli->timeout,
1500                                             cli->smb2.session,
1501                                             0x0, /* in_flags */
1502                                             SMB2_CAP_DFS, /* in_capabilities */
1503                                             0, /* in_channel */
1504                                             0, /* in_previous_session_id */
1505                                             &in_blob); /* in_security_buffer */
1506         if (subreq == NULL) {
1507                 printf("smb2cli_session_setup_send() returned NULL\n");
1508                 return false;
1509         }
1510
1511         ok = tevent_req_poll(subreq, ev);
1512         if (!ok) {
1513                 printf("tevent_req_poll() returned false\n");
1514                 return false;
1515         }
1516
1517         status = smb2cli_session_setup_recv(subreq, talloc_tos(),
1518                                             NULL, &out_blob);
1519         if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
1520                 printf("smb2cli_session_setup_recv returned %s\n",
1521                         nt_errstr(status));
1522                 return false;
1523         }
1524
1525         status = gensec_update(auth_generic_state->gensec_security, talloc_tos(), ev, out_blob, &in_blob);
1526         if (!NT_STATUS_IS_OK(status)) {
1527                 printf("auth_generic_update returned %s\n", nt_errstr(status));
1528                 return false;
1529         }
1530
1531         status = smb2cli_flush(cli, fid_persistent, fid_volatile);
1532         if (!NT_STATUS_IS_OK(status)) {
1533                 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1534                 return false;
1535         }
1536
1537         status = smb2cli_query_directory(
1538                 cli, 1, 0x3, 0, dir_persistent, dir_volatile,
1539                 "session-reauth.txt", 0xffff,
1540                 talloc_tos(), &dir_data, &dir_data_length);
1541         if (!NT_STATUS_IS_OK(status)) {
1542                 printf("smb2cli_query_directory returned %s\n", nt_errstr(status));
1543                 return false;
1544         }
1545
1546         /*
1547          * query_info seems to be a path based operation on Windows...
1548          */
1549         status = smb2cli_query_info(cli->conn,
1550                                     cli->timeout,
1551                                     cli->smb2.session,
1552                                     cli->smb2.tid,
1553                                     SMB2_GETINFO_SECURITY,
1554                                     0, /* in_file_info_class */
1555                                     1024, /* in_max_output_length */
1556                                     NULL, /* in_input_buffer */
1557                                     SECINFO_OWNER, /* in_additional_info */
1558                                     0, /* in_flags */
1559                                     fid_persistent,
1560                                     fid_volatile,
1561                                     talloc_tos(),
1562                                     &out_output_buffer);
1563         if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1564                 printf("smb2cli_query_info (security) returned %s\n", nt_errstr(status));
1565                 return false;
1566         }
1567
1568         in_file_info_class = SMB_FILE_POSITION_INFORMATION - 1000;
1569         status = smb2cli_query_info(cli->conn,
1570                                     cli->timeout,
1571                                     cli->smb2.session,
1572                                     cli->smb2.tid,
1573                                     SMB2_GETINFO_FILE,
1574                                     in_file_info_class,
1575                                     1024, /* in_max_output_length */
1576                                     NULL, /* in_input_buffer */
1577                                     0, /* in_additional_info */
1578                                     0, /* in_flags */
1579                                     fid_persistent,
1580                                     fid_volatile,
1581                                     talloc_tos(),
1582                                     &out_output_buffer);
1583         if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1584                 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status));
1585                 return false;
1586         }
1587
1588         in_input_buffer = data_blob_talloc(talloc_tos(), NULL, 8);
1589         SBVAL(in_input_buffer.data, 0, 512);
1590
1591         in_file_info_class = SMB_FILE_POSITION_INFORMATION - 1000;
1592         status = smb2cli_set_info(cli->conn,
1593                                   cli->timeout,
1594                                   cli->smb2.session,
1595                                   cli->smb2.tid,
1596                                   SMB2_GETINFO_FILE,
1597                                   in_file_info_class,
1598                                   &in_input_buffer,
1599                                   0, /* in_additional_info */
1600                                   fid_persistent,
1601                                   fid_volatile);
1602         if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1603                 printf("smb2cli_set_info (position) returned %s\n", nt_errstr(status));
1604                 return false;
1605         }
1606
1607         status = smb2cli_create(cli, "session-reauth-invalid.txt",
1608                         SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1609                         SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1610                         SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
1611                         FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
1612                         FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1613                         FILE_CREATE, /* create_disposition, */
1614                         FILE_DELETE_ON_CLOSE, /* create_options, */
1615                         NULL, /* smb2_create_blobs *blobs */
1616                         &fid_persistent,
1617                         &fid_volatile);
1618         if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1619                 printf("smb2cli_create %s\n", nt_errstr(status));
1620                 return false;
1621         }
1622
1623         status = smb2cli_create(cli, "",
1624                         SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1625                         SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1626                         SEC_STD_SYNCHRONIZE|
1627                         SEC_DIR_LIST|
1628                         SEC_DIR_READ_ATTRIBUTE, /* desired_access, */
1629                         0, /* file_attributes, */
1630                         FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1631                         FILE_OPEN, /* create_disposition, */
1632                         FILE_SYNCHRONOUS_IO_NONALERT|FILE_DIRECTORY_FILE, /* create_options, */
1633                         NULL, /* smb2_create_blobs *blobs */
1634                         &dir_persistent,
1635                         &dir_volatile);
1636         if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1637                 printf("smb2cli_create returned %s\n", nt_errstr(status));
1638                 return false;
1639         }
1640
1641         saved_tid = cli->smb2.tid;
1642         status = cli_tree_connect(cli, share, "?????", "", 0);
1643         if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1644                 printf("cli_tree_connect returned %s\n", nt_errstr(status));
1645                 return false;
1646         }
1647         cli->smb2.tid = saved_tid;
1648
1649         subreq = smb2cli_session_setup_send(talloc_tos(), ev,
1650                                             cli->conn,
1651                                             cli->timeout,
1652                                             cli->smb2.session,
1653                                             0x0, /* in_flags */
1654                                             SMB2_CAP_DFS, /* in_capabilities */
1655                                             0, /* in_channel */
1656                                             0, /* in_previous_session_id */
1657                                             &in_blob); /* in_security_buffer */
1658         if (subreq == NULL) {
1659                 printf("smb2cli_session_setup_send() returned NULL\n");
1660                 return false;
1661         }
1662
1663         ok = tevent_req_poll(subreq, ev);
1664         if (!ok) {
1665                 printf("tevent_req_poll() returned false\n");
1666                 return false;
1667         }
1668
1669         status = smb2cli_session_setup_recv(subreq, talloc_tos(),
1670                                             &recv_iov, &out_blob);
1671         if (!NT_STATUS_IS_OK(status)) {
1672                 printf("smb2cli_session_setup_recv returned %s\n",
1673                         nt_errstr(status));
1674                 return false;
1675         }
1676
1677         status = smb2cli_flush(cli, fid_persistent, fid_volatile);
1678         if (!NT_STATUS_IS_OK(status)) {
1679                 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1680                 return false;
1681         }
1682
1683         status = smb2cli_query_info(cli->conn,
1684                                     cli->timeout,
1685                                     cli->smb2.session,
1686                                     cli->smb2.tid,
1687                                     SMB2_GETINFO_SECURITY,
1688                                     0, /* in_file_info_class */
1689                                     1024, /* in_max_output_length */
1690                                     NULL, /* in_input_buffer */
1691                                     SECINFO_OWNER, /* in_additional_info */
1692                                     0, /* in_flags */
1693                                     fid_persistent,
1694                                     fid_volatile,
1695                                     talloc_tos(),
1696                                     &out_output_buffer);
1697         if (!NT_STATUS_IS_OK(status)) {
1698                 printf("smb2cli_query_info (security) returned %s\n", nt_errstr(status));
1699                 return false;
1700         }
1701
1702         in_file_info_class = SMB_FILE_POSITION_INFORMATION - 1000;
1703         status = smb2cli_query_info(cli->conn,
1704                                     cli->timeout,
1705                                     cli->smb2.session,
1706                                     cli->smb2.tid,
1707                                     SMB2_GETINFO_FILE,
1708                                     in_file_info_class,
1709                                     1024, /* in_max_output_length */
1710                                     NULL, /* in_input_buffer */
1711                                     0, /* in_additional_info */
1712                                     0, /* in_flags */
1713                                     fid_persistent,
1714                                     fid_volatile,
1715                                     talloc_tos(),
1716                                     &out_output_buffer);
1717         if (!NT_STATUS_IS_OK(status)) {
1718                 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status));
1719                 return false;
1720         }
1721
1722         in_input_buffer = data_blob_talloc(talloc_tos(), NULL, 8);
1723         SBVAL(in_input_buffer.data, 0, 512);
1724
1725         in_file_info_class = SMB_FILE_POSITION_INFORMATION - 1000;
1726         status = smb2cli_set_info(cli->conn,
1727                                   cli->timeout,
1728                                   cli->smb2.session,
1729                                   cli->smb2.tid,
1730                                   SMB2_GETINFO_FILE,
1731                                   in_file_info_class,
1732                                   &in_input_buffer,
1733                                   0, /* in_additional_info */
1734                                   fid_persistent,
1735                                   fid_volatile);
1736         if (!NT_STATUS_IS_OK(status)) {
1737                 printf("smb2cli_set_info (position) returned %s\n", nt_errstr(status));
1738                 return false;
1739         }
1740
1741         in_file_info_class = SMB_FILE_POSITION_INFORMATION - 1000;
1742         status = smb2cli_query_info(cli->conn,
1743                                     cli->timeout,
1744                                     cli->smb2.session,
1745                                     cli->smb2.tid,
1746                                     SMB2_GETINFO_FILE,
1747                                     in_file_info_class,
1748                                     1024, /* in_max_output_length */
1749                                     NULL, /* in_input_buffer */
1750                                     0, /* in_additional_info */
1751                                     0, /* in_flags */
1752                                     fid_persistent,
1753                                     fid_volatile,
1754                                     talloc_tos(),
1755                                     &out_output_buffer);
1756         if (!NT_STATUS_IS_OK(status)) {
1757                 printf("smb2cli_query_info (position) returned %s\n", nt_errstr(status));
1758                 return false;
1759         }
1760
1761         status = smb2cli_close(cli, 0, fid_persistent, fid_volatile);
1762         if (!NT_STATUS_IS_OK(status)) {
1763                 printf("smb2cli_close returned %s\n", nt_errstr(status));
1764                 return false;
1765         }
1766
1767         status = smb2cli_create(cli, "session-reauth.txt",
1768                         SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1769                         SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1770                         SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
1771                         FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
1772                         FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1773                         FILE_CREATE, /* create_disposition, */
1774                         FILE_DELETE_ON_CLOSE, /* create_options, */
1775                         NULL, /* smb2_create_blobs *blobs */
1776                         &fid_persistent,
1777                         &fid_volatile);
1778         if (!NT_STATUS_IS_OK(status)) {
1779                 printf("smb2cli_create %s\n", nt_errstr(status));
1780                 return false;
1781         }
1782
1783         status = smb2cli_query_directory(
1784                 cli, 1, 0x3, 0, dir_persistent, dir_volatile,
1785                 "session-reauth.txt", 0xffff,
1786                 talloc_tos(), &dir_data, &dir_data_length);
1787         if (!NT_STATUS_IS_OK(status)) {
1788                 printf("smb2cli_query_directory returned %s\n", nt_errstr(status));
1789                 return false;
1790         }
1791
1792         status = smb2cli_close(cli, 0, dir_persistent, dir_volatile);
1793         if (!NT_STATUS_IS_OK(status)) {
1794                 printf("smb2cli_close returned %s\n", nt_errstr(status));
1795                 return false;
1796         }
1797
1798         status = smb2cli_close(cli, 0, fid_persistent, fid_volatile);
1799         if (!NT_STATUS_IS_OK(status)) {
1800                 printf("smb2cli_close returned %s\n", nt_errstr(status));
1801                 return false;
1802         }
1803
1804         saved_tid = cli->smb2.tid;
1805         status = cli_tree_connect(cli, share, "?????", "", 0);
1806         if (!NT_STATUS_IS_OK(status)) {
1807                 printf("cli_tree_connect returned %s\n", nt_errstr(status));
1808                 return false;
1809         }
1810         cli->smb2.tid = saved_tid;
1811
1812         return true;
1813 }