s3:torture/test_smb2: fix missleading file name in reauth test
[nivanova/samba-autobuild/.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 "../libcli/smb/smbXcli_base.h"
24 #include "libsmb/smb2cli.h"
25 #include "libcli/security/security.h"
26 #include "libsmb/proto.h"
27 #include "auth/gensec/gensec.h"
28 #include "auth_generic.h"
29
30 extern fstring host, workgroup, share, password, username, myname;
31
32 bool run_smb2_basic(int dummy)
33 {
34         struct cli_state *cli;
35         NTSTATUS status;
36         uint64_t fid_persistent, fid_volatile;
37         const char *hello = "Hello, world\n";
38         uint8_t *result;
39         uint32_t nread;
40         uint8_t *dir_data;
41         uint32_t dir_data_length;
42         uint32_t saved_tid = 0;
43         uint64_t saved_uid = 0;
44
45         printf("Starting SMB2-BASIC\n");
46
47         if (!torture_init_connection(&cli)) {
48                 return false;
49         }
50         cli->smb2.pid = 0xFEFF;
51
52         status = smbXcli_negprot(cli->conn, cli->timeout,
53                                  PROTOCOL_SMB2_02, PROTOCOL_SMB2_02);
54         if (!NT_STATUS_IS_OK(status)) {
55                 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
56                 return false;
57         }
58
59         status = cli_session_setup(cli, username,
60                                    password, strlen(password),
61                                    password, strlen(password),
62                                    workgroup);
63         if (!NT_STATUS_IS_OK(status)) {
64                 printf("cli_session_setup returned %s\n", nt_errstr(status));
65                 return false;
66         }
67
68         status = cli_tree_connect(cli, share, "?????", "", 0);
69         if (!NT_STATUS_IS_OK(status)) {
70                 printf("cli_tree_connect returned %s\n", nt_errstr(status));
71                 return false;
72         }
73
74         status = smb2cli_create(cli, "smb2-basic.txt",
75                         SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
76                         SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
77                         SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
78                         FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
79                         FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
80                         FILE_CREATE, /* create_disposition, */
81                         FILE_DELETE_ON_CLOSE, /* create_options, */
82                         NULL, /* smb2_create_blobs *blobs */
83                         &fid_persistent,
84                         &fid_volatile);
85         if (!NT_STATUS_IS_OK(status)) {
86                 printf("smb2cli_create returned %s\n", nt_errstr(status));
87                 return false;
88         }
89
90         status = smb2cli_write(cli, strlen(hello), 0, fid_persistent,
91                                fid_volatile, 0, 0, (const uint8_t *)hello);
92         if (!NT_STATUS_IS_OK(status)) {
93                 printf("smb2cli_write returned %s\n", nt_errstr(status));
94                 return false;
95         }
96
97         status = smb2cli_flush(cli, fid_persistent, fid_volatile);
98         if (!NT_STATUS_IS_OK(status)) {
99                 printf("smb2cli_flush returned %s\n", nt_errstr(status));
100                 return false;
101         }
102
103         status = smb2cli_read(cli, 0x10000, 0, fid_persistent,
104                                fid_volatile, 2, 0,
105                                talloc_tos(), &result, &nread);
106         if (!NT_STATUS_IS_OK(status)) {
107                 printf("smb2cli_read returned %s\n", nt_errstr(status));
108                 return false;
109         }
110
111         if (nread != strlen(hello)) {
112                 printf("smb2cli_read returned %d bytes, expected %d\n",
113                        (int)nread, (int)strlen(hello));
114                 return false;
115         }
116
117         if (memcmp(hello, result, nread) != 0) {
118                 printf("smb2cli_read returned '%s', expected '%s'\n",
119                        result, hello);
120                 return false;
121         }
122
123         status = smb2cli_close(cli, 0, fid_persistent, fid_volatile);
124         if (!NT_STATUS_IS_OK(status)) {
125                 printf("smb2cli_close returned %s\n", nt_errstr(status));
126                 return false;
127         }
128
129         status = smb2cli_create(cli, "",
130                         SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
131                         SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
132                         SEC_STD_SYNCHRONIZE|
133                         SEC_DIR_LIST|
134                         SEC_DIR_READ_ATTRIBUTE, /* desired_access, */
135                         0, /* file_attributes, */
136                         FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
137                         FILE_OPEN, /* create_disposition, */
138                         FILE_SYNCHRONOUS_IO_NONALERT|FILE_DIRECTORY_FILE, /* create_options, */
139                         NULL, /* smb2_create_blobs *blobs */
140                         &fid_persistent,
141                         &fid_volatile);
142         if (!NT_STATUS_IS_OK(status)) {
143                 printf("smb2cli_create returned %s\n", nt_errstr(status));
144                 return false;
145         }
146
147         status = smb2cli_query_directory(
148                 cli, 1, 0, 0, fid_persistent, fid_volatile, "*", 0xffff,
149                 talloc_tos(), &dir_data, &dir_data_length);
150
151         if (!NT_STATUS_IS_OK(status)) {
152                 printf("smb2cli_query_directory returned %s\n", nt_errstr(status));
153                 return false;
154         }
155
156         status = smb2cli_close(cli, 0, fid_persistent, fid_volatile);
157         if (!NT_STATUS_IS_OK(status)) {
158                 printf("smb2cli_close returned %s\n", nt_errstr(status));
159                 return false;
160         }
161
162         saved_tid = cli->smb2.tid;
163         status = smb2cli_tdis(cli);
164         if (!NT_STATUS_IS_OK(status)) {
165                 printf("smb2cli_tdis returned %s\n", nt_errstr(status));
166                 return false;
167         }
168         cli->smb2.tid = saved_tid;
169
170         status = smb2cli_tdis(cli);
171         if (!NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED)) {
172                 printf("2nd smb2cli_tdis returned %s\n", nt_errstr(status));
173                 return false;
174         }
175
176         saved_uid = smb2cli_session_current_id(cli->smb2.session);
177         status = smb2cli_logoff(cli);
178         if (!NT_STATUS_IS_OK(status)) {
179                 printf("smb2cli_logoff returned %s\n", nt_errstr(status));
180                 return false;
181         }
182
183         cli->smb2.session = smbXcli_session_create(cli, cli->conn);
184         if (cli->smb2.session == NULL) {
185                 printf("smbXcli_session_create() returned NULL\n");
186                 return false;
187         }
188
189         smb2cli_session_set_id_and_flags(cli->smb2.session, saved_uid, 0);
190
191         status = smb2cli_logoff(cli);
192         if (!NT_STATUS_EQUAL(status, NT_STATUS_USER_SESSION_DELETED)) {
193                 printf("2nd smb2cli_logoff returned %s\n", nt_errstr(status));
194                 return false;
195         }
196
197         return true;
198 }
199
200 bool run_smb2_negprot(int dummy)
201 {
202         struct cli_state *cli;
203         NTSTATUS status;
204         enum protocol_types protocol;
205         const char *name = NULL;
206
207         printf("Starting SMB2-NEGPROT\n");
208
209         if (!torture_init_connection(&cli)) {
210                 return false;
211         }
212         cli->smb2.pid = 0xFEFF;
213
214         status = smbXcli_negprot(cli->conn, cli->timeout,
215                                  PROTOCOL_CORE, PROTOCOL_SMB2_24);
216         if (!NT_STATUS_IS_OK(status)) {
217                 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
218                 return false;
219         }
220
221         protocol = smbXcli_conn_protocol(cli->conn);
222
223         switch (protocol) {
224         case PROTOCOL_SMB2_02:
225                 name = "SMB2_02";
226                 break;
227         case PROTOCOL_SMB2_10:
228                 name = "SMB2_10";
229                 break;
230         case PROTOCOL_SMB2_22:
231                 name = "SMB2_22";
232                 break;
233         case PROTOCOL_SMB2_24:
234                 name = "SMB2_24";
235                 break;
236         default:
237                 break;
238         }
239
240         if (name) {
241                 printf("Server supports %s\n", name);
242         } else {
243                 printf("Server DOES NOT support SMB2\n");
244                 return false;
245         }
246
247         status = smbXcli_negprot(cli->conn, cli->timeout,
248                                  protocol, protocol);
249         if (!NT_STATUS_EQUAL(status, NT_STATUS_CONNECTION_RESET) &&
250             !NT_STATUS_EQUAL(status, NT_STATUS_CONNECTION_DISCONNECTED) &&
251             !NT_STATUS_EQUAL(status, NT_STATUS_CONNECTION_ABORTED)) {
252                 printf("2nd smbXcli_negprot should disconnect - returned %s\n",
253                         nt_errstr(status));
254                 return false;
255         }
256
257         if (smbXcli_conn_is_connected(cli->conn)) {
258                 printf("2nd smbXcli_negprot should disconnect "
259                        "- still connected\n");
260                 return false;
261         }
262
263         return true;
264 }
265
266 bool run_smb2_session_reconnect(int dummy)
267 {
268         struct cli_state *cli1;
269         struct cli_state *cli2;
270         NTSTATUS status;
271         bool ok;
272         uint64_t fid_persistent, fid_volatile;
273         struct tevent_context *ev;
274         struct tevent_req *subreq;
275         DATA_BLOB in_blob = data_blob_null;
276         DATA_BLOB out_blob;
277         DATA_BLOB session_key;
278         struct auth_generic_state *auth_generic_state;
279         struct iovec *recv_iov;
280         const char *hello = "Hello, world\n";
281         uint8_t *result;
282         uint32_t nread;
283
284         printf("Starting SMB2-SESSION-RECONNECT\n");
285
286         if (!torture_init_connection(&cli1)) {
287                 return false;
288         }
289         cli1->smb2.pid = 0xFEFF;
290
291         status = smbXcli_negprot(cli1->conn, cli1->timeout,
292                                  PROTOCOL_SMB2_02, PROTOCOL_SMB2_24);
293         if (!NT_STATUS_IS_OK(status)) {
294                 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
295                 return false;
296         }
297
298         status = cli_session_setup(cli1, username,
299                                    password, strlen(password),
300                                    password, strlen(password),
301                                    workgroup);
302         if (!NT_STATUS_IS_OK(status)) {
303                 printf("cli_session_setup returned %s\n", nt_errstr(status));
304                 return false;
305         }
306
307         status = cli_tree_connect(cli1, share, "?????", "", 0);
308         if (!NT_STATUS_IS_OK(status)) {
309                 printf("cli_tree_connect returned %s\n", nt_errstr(status));
310                 return false;
311         }
312
313         status = smb2cli_create(cli1, "session-reconnect.txt",
314                         SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
315                         SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
316                         SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
317                         FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
318                         FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
319                         FILE_CREATE, /* create_disposition, */
320                         FILE_DELETE_ON_CLOSE, /* create_options, */
321                         NULL, /* smb2_create_blobs *blobs */
322                         &fid_persistent,
323                         &fid_volatile);
324         if (!NT_STATUS_IS_OK(status)) {
325                 printf("smb2cli_create on cli1 %s\n", nt_errstr(status));
326                 return false;
327         }
328
329         status = smb2cli_write(cli1, strlen(hello), 0, fid_persistent,
330                                fid_volatile, 0, 0, (const uint8_t *)hello);
331         if (!NT_STATUS_IS_OK(status)) {
332                 printf("smb2cli_write returned %s\n", nt_errstr(status));
333                 return false;
334         }
335
336         status = smb2cli_flush(cli1, fid_persistent, fid_volatile);
337         if (!NT_STATUS_IS_OK(status)) {
338                 printf("smb2cli_flush returned %s\n", nt_errstr(status));
339                 return false;
340         }
341
342         status = smb2cli_read(cli1, 0x10000, 0, fid_persistent,
343                                fid_volatile, 2, 0,
344                                talloc_tos(), &result, &nread);
345         if (!NT_STATUS_IS_OK(status)) {
346                 printf("smb2cli_read returned %s\n", nt_errstr(status));
347                 return false;
348         }
349
350         if (nread != strlen(hello)) {
351                 printf("smb2cli_read returned %d bytes, expected %d\n",
352                        (int)nread, (int)strlen(hello));
353                 return false;
354         }
355
356         if (memcmp(hello, result, nread) != 0) {
357                 printf("smb2cli_read returned '%s', expected '%s'\n",
358                        result, hello);
359                 return false;
360         }
361
362         /* prepare second session */
363
364         if (!torture_init_connection(&cli2)) {
365                 return false;
366         }
367         cli2->smb2.pid = 0xFEFF;
368
369         status = smbXcli_negprot(cli2->conn, cli2->timeout,
370                                  PROTOCOL_SMB2_02, PROTOCOL_SMB2_24);
371         if (!NT_STATUS_IS_OK(status)) {
372                 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
373                 return false;
374         }
375
376         status = auth_generic_client_prepare(talloc_tos(), &auth_generic_state);
377         if (!NT_STATUS_IS_OK(status)) {
378                 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status));
379                 return false;
380         }
381
382         gensec_want_feature(auth_generic_state->gensec_security,
383                             GENSEC_FEATURE_SESSION_KEY);
384         status = auth_generic_set_username(auth_generic_state, username);
385         if (!NT_STATUS_IS_OK(status)) {
386                 printf("auth_generic_set_username returned %s\n", nt_errstr(status));
387                 return false;
388         }
389
390         status = auth_generic_set_domain(auth_generic_state, workgroup);
391         if (!NT_STATUS_IS_OK(status)) {
392                 printf("auth_generic_set_domain returned %s\n", nt_errstr(status));
393                 return false;
394         }
395
396         status = auth_generic_set_password(auth_generic_state, password);
397         if (!NT_STATUS_IS_OK(status)) {
398                 printf("auth_generic_set_password returned %s\n", nt_errstr(status));
399                 return false;
400         }
401
402         status = auth_generic_client_start(auth_generic_state, GENSEC_OID_NTLMSSP);
403         if (!NT_STATUS_IS_OK(status)) {
404                 printf("auth_generic_client_start returned %s\n", nt_errstr(status));
405                 return false;
406         }
407
408         ev = event_context_init(talloc_tos());
409         if (ev == NULL) {
410                 printf("event_context_init() returned NULL\n");
411                 return false;
412         }
413
414         status = gensec_update(auth_generic_state->gensec_security, talloc_tos(), ev, data_blob_null, &in_blob);
415         if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
416                 printf("gensec_update returned %s\n", nt_errstr(status));
417                 return false;
418         }
419
420         cli2->smb2.session = smbXcli_session_create(cli2, cli2->conn);
421
422         subreq = smb2cli_session_setup_send(talloc_tos(), ev,
423                                             cli2->conn,
424                                             cli2->timeout,
425                                             cli2->smb2.session,
426                                             0x0, /* in_flags */
427                                             SMB2_CAP_DFS, /* in_capabilities */
428                                             0, /* in_channel */
429                                             cli1->smb2.session, /* in_previous_session */
430                                             &in_blob); /* in_security_buffer */
431         if (subreq == NULL) {
432                 printf("smb2cli_session_setup_send() returned NULL\n");
433                 return false;
434         }
435
436         ok = tevent_req_poll(subreq, ev);
437         if (!ok) {
438                 printf("tevent_req_poll() returned false\n");
439                 return false;
440         }
441
442         status = smb2cli_session_setup_recv(subreq, talloc_tos(),
443                                             NULL, &out_blob);
444         if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
445                 printf("smb2cli_session_setup_recv returned %s\n",
446                         nt_errstr(status));
447                 return false;
448         }
449
450         status = gensec_update(auth_generic_state->gensec_security, talloc_tos(), ev, out_blob, &in_blob);
451         if (!NT_STATUS_IS_OK(status)) {
452                 printf("auth_generic_update returned %s\n", nt_errstr(status));
453                 return false;
454         }
455
456         subreq = smb2cli_session_setup_send(talloc_tos(), ev,
457                                             cli2->conn,
458                                             cli2->timeout,
459                                             cli2->smb2.session,
460                                             0x0, /* in_flags */
461                                             SMB2_CAP_DFS, /* in_capabilities */
462                                             0, /* in_channel */
463                                             cli1->smb2.session, /* in_previous_session */
464                                             &in_blob); /* in_security_buffer */
465         if (subreq == NULL) {
466                 printf("smb2cli_session_setup_send() returned NULL\n");
467                 return false;
468         }
469
470         ok = tevent_req_poll(subreq, ev);
471         if (!ok) {
472                 printf("tevent_req_poll() returned false\n");
473                 return false;
474         }
475
476         status = smb2cli_session_setup_recv(subreq, talloc_tos(),
477                                             &recv_iov, &out_blob);
478         if (!NT_STATUS_IS_OK(status)) {
479                 printf("smb2cli_session_setup_recv returned %s\n",
480                         nt_errstr(status));
481                 return false;
482         }
483
484         status = gensec_session_key(auth_generic_state->gensec_security, talloc_tos(),
485                                     &session_key);
486         if (!NT_STATUS_IS_OK(status)) {
487                 printf("gensec_session_key returned %s\n",
488                         nt_errstr(status));
489                 return false;
490         }
491
492         /* check file operation on the old client */
493
494         status = smb2cli_flush(cli1, fid_persistent, fid_volatile);
495         if (!NT_STATUS_EQUAL(status, NT_STATUS_USER_SESSION_DELETED)) {
496                 printf("smb2cli_flush returned %s\n", nt_errstr(status));
497                 return false;
498         }
499
500         status = cli_tree_connect(cli1, share, "?????", "", 0);
501         if (!NT_STATUS_EQUAL(status, NT_STATUS_USER_SESSION_DELETED)) {
502                 printf("cli_tree_connect returned %s\n", nt_errstr(status));
503                 return false;
504         }
505
506         /*
507          * checking file operations without signing.
508          * on w2k8r2 at least, flush, read and write also work the same way,
509          * while create gives ACCESS_DENIED without signing
510          */
511         status = smb2cli_flush(cli2, fid_persistent, fid_volatile);
512         if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED)) {
513                 printf("smb2cli_flush returned %s\n", nt_errstr(status));
514                 return false;
515         }
516
517         status = smb2cli_write(cli2, strlen(hello), 0, fid_persistent,
518                                fid_volatile, 0, 0, (const uint8_t *)hello);
519         if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED)) {
520                 printf("smb2cli_write returned %s\n", nt_errstr(status));
521                 return false;
522         }
523
524         status = smb2cli_read(cli2, 0x10000, 0, fid_persistent,
525                                fid_volatile, 2, 0,
526                                talloc_tos(), &result, &nread);
527         if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED)) {
528                 printf("smb2cli_read returned %s\n", nt_errstr(status));
529                 return false;
530         }
531
532         status = smb2cli_create(cli2, "session-reconnect.txt",
533                         SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
534                         SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
535                         SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
536                         FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
537                         FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
538                         FILE_CREATE, /* create_disposition, */
539                         FILE_DELETE_ON_CLOSE, /* create_options, */
540                         NULL, /* smb2_create_blobs *blobs */
541                         &fid_persistent,
542                         &fid_volatile);
543         if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED) &&
544             !NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED)) {
545                 printf("smb2cli_create on cli2 %s\n", nt_errstr(status));
546                 return false;
547         }
548
549         /* now grab the session key and try with signing */
550
551         status = smb2cli_session_set_session_key(cli2->smb2.session,
552                                                  session_key,
553                                                  recv_iov);
554         if (!NT_STATUS_IS_OK(status)) {
555                 printf("smb2cli_session_set_session_key %s\n", nt_errstr(status));
556                 return false;
557         }
558
559         /* the tid seems to be irrelevant at this stage */
560
561         cli2->smb2.tid = cli1->smb2.tid;
562
563         status = smb2cli_flush(cli2, fid_persistent, fid_volatile);
564         if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED)) {
565                 printf("smb2cli_flush returned %s\n", nt_errstr(status));
566                 return false;
567         }
568
569         status = smb2cli_write(cli2, strlen(hello), 0, fid_persistent,
570                                fid_volatile, 0, 0, (const uint8_t *)hello);
571         if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED)) {
572                 printf("smb2cli_write returned %s\n", nt_errstr(status));
573                 return false;
574         }
575
576         status = smb2cli_read(cli2, 0x10000, 0, fid_persistent,
577                                fid_volatile, 2, 0,
578                                talloc_tos(), &result, &nread);
579         if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED)) {
580                 printf("smb2cli_read returned %s\n", nt_errstr(status));
581                 return false;
582         }
583
584         status = smb2cli_create(cli2, "session-reconnect.txt",
585                         SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
586                         SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
587                         SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
588                         FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
589                         FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
590                         FILE_CREATE, /* create_disposition, */
591                         FILE_DELETE_ON_CLOSE, /* create_options, */
592                         NULL, /* smb2_create_blobs *blobs */
593                         &fid_persistent,
594                         &fid_volatile);
595         if (!NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED)) {
596                 printf("smb2cli_create on cli2 %s\n", nt_errstr(status));
597                 return false;
598         }
599
600         /* now do a new tcon and test file calls again */
601
602         status = cli_tree_connect(cli2, share, "?????", "", 0);
603         if (!NT_STATUS_IS_OK(status)) {
604                 printf("cli_tree_connect returned %s\n", nt_errstr(status));
605                 return false;
606         }
607
608         status = smb2cli_create(cli2, "session-reconnect.txt",
609                         SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
610                         SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
611                         SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
612                         FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
613                         FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
614                         FILE_CREATE, /* create_disposition, */
615                         FILE_DELETE_ON_CLOSE, /* create_options, */
616                         NULL, /* smb2_create_blobs *blobs */
617                         &fid_persistent,
618                         &fid_volatile);
619         if (!NT_STATUS_IS_OK(status)) {
620                 printf("smb2cli_create on cli2 %s\n", nt_errstr(status));
621                 return false;
622         }
623
624         status = smb2cli_write(cli2, strlen(hello), 0, fid_persistent,
625                                fid_volatile, 0, 0, (const uint8_t *)hello);
626         if (!NT_STATUS_IS_OK(status)) {
627                 printf("smb2cli_write returned %s\n", nt_errstr(status));
628                 return false;
629         }
630
631         status = smb2cli_flush(cli2, fid_persistent, fid_volatile);
632         if (!NT_STATUS_IS_OK(status)) {
633                 printf("smb2cli_flush returned %s\n", nt_errstr(status));
634                 return false;
635         }
636
637         status = smb2cli_read(cli2, 0x10000, 0, fid_persistent,
638                                fid_volatile, 2, 0,
639                                talloc_tos(), &result, &nread);
640         if (!NT_STATUS_IS_OK(status)) {
641                 printf("smb2cli_read returned %s\n", nt_errstr(status));
642                 return false;
643         }
644
645         if (nread != strlen(hello)) {
646                 printf("smb2cli_read returned %d bytes, expected %d\n",
647                        (int)nread, (int)strlen(hello));
648                 return false;
649         }
650
651         if (memcmp(hello, result, nread) != 0) {
652                 printf("smb2cli_read returned '%s', expected '%s'\n",
653                        result, hello);
654                 return false;
655         }
656
657         return true;
658 }
659
660 bool run_smb2_tcon_dependence(int dummy)
661 {
662         struct cli_state *cli;
663         NTSTATUS status;
664         uint64_t fid_persistent, fid_volatile;
665         const char *hello = "Hello, world\n";
666         uint8_t *result;
667         uint32_t nread;
668
669         printf("Starting SMB2-TCON-DEPENDENCE\n");
670
671         if (!torture_init_connection(&cli)) {
672                 return false;
673         }
674         cli->smb2.pid = 0xFEFF;
675
676         status = smbXcli_negprot(cli->conn, cli->timeout,
677                                  PROTOCOL_SMB2_02, PROTOCOL_SMB2_24);
678         if (!NT_STATUS_IS_OK(status)) {
679                 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
680                 return false;
681         }
682
683         status = cli_session_setup(cli, username,
684                                    password, strlen(password),
685                                    password, strlen(password),
686                                    workgroup);
687         if (!NT_STATUS_IS_OK(status)) {
688                 printf("cli_session_setup returned %s\n", nt_errstr(status));
689                 return false;
690         }
691
692         status = cli_tree_connect(cli, share, "?????", "", 0);
693         if (!NT_STATUS_IS_OK(status)) {
694                 printf("cli_tree_connect returned %s\n", nt_errstr(status));
695                 return false;
696         }
697
698         status = smb2cli_create(cli, "tcon_depedence.txt",
699                         SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
700                         SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
701                         SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
702                         FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
703                         FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
704                         FILE_CREATE, /* create_disposition, */
705                         FILE_DELETE_ON_CLOSE, /* create_options, */
706                         NULL, /* smb2_create_blobs *blobs */
707                         &fid_persistent,
708                         &fid_volatile);
709         if (!NT_STATUS_IS_OK(status)) {
710                 printf("smb2cli_create on cli %s\n", nt_errstr(status));
711                 return false;
712         }
713
714         status = smb2cli_write(cli, strlen(hello), 0, fid_persistent,
715                                fid_volatile, 0, 0, (const uint8_t *)hello);
716         if (!NT_STATUS_IS_OK(status)) {
717                 printf("smb2cli_write returned %s\n", nt_errstr(status));
718                 return false;
719         }
720
721         status = smb2cli_flush(cli, fid_persistent, fid_volatile);
722         if (!NT_STATUS_IS_OK(status)) {
723                 printf("smb2cli_flush returned %s\n", nt_errstr(status));
724                 return false;
725         }
726
727         status = smb2cli_read(cli, 0x10000, 0, fid_persistent,
728                                fid_volatile, 2, 0,
729                                talloc_tos(), &result, &nread);
730         if (!NT_STATUS_IS_OK(status)) {
731                 printf("smb2cli_read returned %s\n", nt_errstr(status));
732                 return false;
733         }
734
735         if (nread != strlen(hello)) {
736                 printf("smb2cli_read returned %d bytes, expected %d\n",
737                        (int)nread, (int)strlen(hello));
738                 return false;
739         }
740
741         if (memcmp(hello, result, nread) != 0) {
742                 printf("smb2cli_read returned '%s', expected '%s'\n",
743                        result, hello);
744                 return false;
745         }
746
747         /* check behaviour with wrong tid... */
748
749         cli->smb2.tid++;
750
751         status = smb2cli_read(cli, 0x10000, 0, fid_persistent,
752                                fid_volatile, 2, 0,
753                                talloc_tos(), &result, &nread);
754         if (!NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED)) {
755                 printf("smb2cli_read returned %s\n", nt_errstr(status));
756                 return false;
757         }
758
759         cli->smb2.tid--;
760
761         return true;
762 }
763
764 bool run_smb2_multi_channel(int dummy)
765 {
766         struct cli_state *cli1;
767         struct cli_state *cli2;
768         NTSTATUS status;
769         bool ok;
770         uint64_t fid_persistent, fid_volatile;
771         struct tevent_context *ev;
772         struct tevent_req *subreq;
773         DATA_BLOB in_blob = data_blob_null;
774         DATA_BLOB out_blob;
775         DATA_BLOB channel_session_key;
776         struct auth_generic_state *auth_generic_state;
777         struct iovec *recv_iov;
778         const char *hello = "Hello, world\n";
779         uint8_t *result;
780         uint32_t nread;
781
782         printf("Starting SMB2-MULTI-CHANNEL\n");
783
784         if (!torture_init_connection(&cli1)) {
785                 return false;
786         }
787         cli1->smb2.pid = 0xFEFF;
788
789         if (!torture_init_connection(&cli2)) {
790                 return false;
791         }
792         cli2->smb2.pid = 0xFEFF;
793
794         status = smbXcli_negprot(cli1->conn, cli1->timeout,
795                                  PROTOCOL_SMB2_22, PROTOCOL_SMB2_24);
796         if (!NT_STATUS_IS_OK(status)) {
797                 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
798                 return false;
799         }
800
801         status = smbXcli_negprot(cli2->conn, cli2->timeout,
802                                  PROTOCOL_SMB2_22, PROTOCOL_SMB2_24);
803         if (!NT_STATUS_IS_OK(status)) {
804                 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
805                 return false;
806         }
807
808         status = cli_session_setup(cli1, username,
809                                    password, strlen(password),
810                                    password, strlen(password),
811                                    workgroup);
812         if (!NT_STATUS_IS_OK(status)) {
813                 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status));
814                 return false;
815         }
816
817         status = cli_tree_connect(cli1, share, "?????", "", 0);
818         if (!NT_STATUS_IS_OK(status)) {
819                 printf("cli_tree_connect returned %s\n", nt_errstr(status));
820                 return false;
821         }
822
823         status = smb2cli_session_create_channel(cli2,
824                                                 cli1->smb2.session,
825                                                 cli2->conn,
826                                                 &cli2->smb2.session);
827         if (!NT_STATUS_IS_OK(status)) {
828                 printf("smb2cli_session_create_channel returned %s\n",
829                         nt_errstr(status));
830                 return false;
831         }
832
833         status = auth_generic_client_prepare(talloc_tos(), &auth_generic_state);
834         if (!NT_STATUS_IS_OK(status)) {
835                 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status));
836                 return false;
837         }
838
839         gensec_want_feature(auth_generic_state->gensec_security,
840                             GENSEC_FEATURE_SESSION_KEY);
841         status = auth_generic_set_username(auth_generic_state, username);
842         if (!NT_STATUS_IS_OK(status)) {
843                 printf("auth_generic_set_username returned %s\n", nt_errstr(status));
844                 return false;
845         }
846
847         status = auth_generic_set_domain(auth_generic_state, workgroup);
848         if (!NT_STATUS_IS_OK(status)) {
849                 printf("auth_generic_set_domain returned %s\n", nt_errstr(status));
850                 return false;
851         }
852
853         status = auth_generic_set_password(auth_generic_state, password);
854         if (!NT_STATUS_IS_OK(status)) {
855                 printf("auth_generic_set_password returned %s\n", nt_errstr(status));
856                 return false;
857         }
858
859         status = auth_generic_client_start(auth_generic_state, GENSEC_OID_NTLMSSP);
860         if (!NT_STATUS_IS_OK(status)) {
861                 printf("auth_generic_client_start returned %s\n", nt_errstr(status));
862                 return false;
863         }
864
865         ev = event_context_init(talloc_tos());
866         if (ev == NULL) {
867                 printf("event_context_init() returned NULL\n");
868                 return false;
869         }
870
871         status = gensec_update(auth_generic_state->gensec_security, talloc_tos(), ev, data_blob_null, &in_blob);
872         if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
873                 printf("gensec_update returned %s\n", nt_errstr(status));
874                 return false;
875         }
876
877         subreq = smb2cli_session_setup_send(talloc_tos(), ev,
878                                             cli2->conn,
879                                             cli2->timeout,
880                                             cli2->smb2.session,
881                                             0x01, /* in_flags */
882                                             SMB2_CAP_DFS, /* in_capabilities */
883                                             0, /* in_channel */
884                                             NULL, /* in_previous_session */
885                                             &in_blob); /* in_security_buffer */
886         if (subreq == NULL) {
887                 printf("smb2cli_session_setup_send() returned NULL\n");
888                 return false;
889         }
890
891         ok = tevent_req_poll(subreq, ev);
892         if (!ok) {
893                 printf("tevent_req_poll() returned false\n");
894                 return false;
895         }
896
897         status = smb2cli_session_setup_recv(subreq, talloc_tos(),
898                                             NULL, &out_blob);
899         if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
900                 printf("smb2cli_session_setup_recv returned %s\n",
901                         nt_errstr(status));
902                 return false;
903         }
904
905         status = gensec_update(auth_generic_state->gensec_security, talloc_tos(), ev, out_blob, &in_blob);
906         if (!NT_STATUS_IS_OK(status)) {
907                 printf("auth_generic_update returned %s\n", nt_errstr(status));
908                 return false;
909         }
910
911         subreq = smb2cli_session_setup_send(talloc_tos(), ev,
912                                             cli2->conn,
913                                             cli2->timeout,
914                                             cli2->smb2.session,
915                                             0x01, /* in_flags */
916                                             SMB2_CAP_DFS, /* in_capabilities */
917                                             0, /* in_channel */
918                                             NULL, /* in_previous_session */
919                                             &in_blob); /* in_security_buffer */
920         if (subreq == NULL) {
921                 printf("smb2cli_session_setup_send() returned NULL\n");
922                 return false;
923         }
924
925         ok = tevent_req_poll(subreq, ev);
926         if (!ok) {
927                 printf("tevent_req_poll() returned false\n");
928                 return false;
929         }
930
931         status = smb2cli_session_setup_recv(subreq, talloc_tos(),
932                                             &recv_iov, &out_blob);
933         if (!NT_STATUS_IS_OK(status)) {
934                 printf("smb2cli_session_setup_recv returned %s\n",
935                         nt_errstr(status));
936                 return false;
937         }
938
939         status = gensec_session_key(auth_generic_state->gensec_security, talloc_tos(),
940                                     &channel_session_key);
941         if (!NT_STATUS_IS_OK(status)) {
942                 printf("gensec_session_key returned %s\n",
943                         nt_errstr(status));
944                 return false;
945         }
946
947         status = smb2cli_session_set_channel_key(cli2->smb2.session,
948                                                  channel_session_key,
949                                                  recv_iov);
950         if (!NT_STATUS_IS_OK(status)) {
951                 printf("smb2cli_session_set_channel_key %s\n", nt_errstr(status));
952                 return false;
953         }
954
955         cli2->smb2.tid = cli1->smb2.tid;
956
957         status = smb2cli_create(cli2, "multi-channel.txt",
958                         SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
959                         SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
960                         SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
961                         FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
962                         FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
963                         FILE_CREATE, /* create_disposition, */
964                         FILE_DELETE_ON_CLOSE, /* create_options, */
965                         NULL, /* smb2_create_blobs *blobs */
966                         &fid_persistent,
967                         &fid_volatile);
968         if (!NT_STATUS_IS_OK(status)) {
969                 printf("smb2cli_create on cli2 %s\n", nt_errstr(status));
970                 return false;
971         }
972
973         status = smb2cli_write(cli1, strlen(hello), 0, fid_persistent,
974                                fid_volatile, 0, 0, (const uint8_t *)hello);
975         if (!NT_STATUS_IS_OK(status)) {
976                 printf("smb2cli_write returned %s\n", nt_errstr(status));
977                 return false;
978         }
979
980         status = smb2cli_flush(cli2, fid_persistent, fid_volatile);
981         if (!NT_STATUS_IS_OK(status)) {
982                 printf("smb2cli_flush returned %s\n", nt_errstr(status));
983                 return false;
984         }
985
986         status = smb2cli_flush(cli1, fid_persistent, fid_volatile);
987         if (!NT_STATUS_IS_OK(status)) {
988                 printf("smb2cli_flush returned %s\n", nt_errstr(status));
989                 return false;
990         }
991
992         status = smb2cli_read(cli2, 0x10000, 0, fid_persistent,
993                                fid_volatile, 2, 0,
994                                talloc_tos(), &result, &nread);
995         if (!NT_STATUS_IS_OK(status)) {
996                 printf("smb2cli_read returned %s\n", nt_errstr(status));
997                 return false;
998         }
999
1000         if (nread != strlen(hello)) {
1001                 printf("smb2cli_read returned %d bytes, expected %d\n",
1002                        (int)nread, (int)strlen(hello));
1003                 return false;
1004         }
1005
1006         if (memcmp(hello, result, nread) != 0) {
1007                 printf("smb2cli_read returned '%s', expected '%s'\n",
1008                        result, hello);
1009                 return false;
1010         }
1011
1012         status = smb2cli_close(cli1, 0, fid_persistent, fid_volatile);
1013         if (!NT_STATUS_IS_OK(status)) {
1014                 printf("smb2cli_close returned %s\n", nt_errstr(status));
1015                 return false;
1016         }
1017
1018         status = smb2cli_flush(cli2, fid_persistent, fid_volatile);
1019         if (!NT_STATUS_IS_OK(status)) {
1020                 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1021         }
1022
1023         status = smb2cli_flush(cli1, fid_persistent, fid_volatile);
1024         if (!NT_STATUS_IS_OK(status)) {
1025                 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1026         }
1027
1028         return true;
1029 }
1030
1031 bool run_smb2_session_reauth(int dummy)
1032 {
1033         struct cli_state *cli;
1034         NTSTATUS status;
1035         bool ok;
1036         uint64_t fid_persistent, fid_volatile;
1037         struct tevent_context *ev;
1038         struct tevent_req *subreq;
1039         DATA_BLOB in_blob = data_blob_null;
1040         DATA_BLOB out_blob;
1041         struct auth_generic_state *auth_generic_state;
1042         struct iovec *recv_iov;
1043
1044         printf("Starting SMB2-SESSION_REAUTH\n");
1045
1046         if (!torture_init_connection(&cli)) {
1047                 return false;
1048         }
1049         cli->smb2.pid = 0xFEFF;
1050
1051         /*
1052          * PROTOCOL_SMB2_22 has a bug in win8pre0
1053          * it behaves like PROTOCOL_SMB2_02
1054          * and returns NT_STATUS_REQUEST_NOT_ACCEPTED,
1055          * while it allows it on PROTOCOL_SMB2_02.
1056          */
1057         status = smbXcli_negprot(cli->conn, cli->timeout,
1058                                  PROTOCOL_SMB2_10, PROTOCOL_SMB2_10);
1059         if (!NT_STATUS_IS_OK(status)) {
1060                 printf("smbXcli_negprot returned %s\n", nt_errstr(status));
1061                 return false;
1062         }
1063
1064         status = cli_session_setup(cli, username,
1065                                    password, strlen(password),
1066                                    password, strlen(password),
1067                                    workgroup);
1068         if (!NT_STATUS_IS_OK(status)) {
1069                 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status));
1070                 return false;
1071         }
1072
1073         status = cli_tree_connect(cli, share, "?????", "", 0);
1074         if (!NT_STATUS_IS_OK(status)) {
1075                 printf("cli_tree_connect returned %s\n", nt_errstr(status));
1076                 return false;
1077         }
1078
1079         status = smb2cli_create(cli, "session-reauth.txt",
1080                         SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1081                         SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1082                         SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
1083                         FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
1084                         FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1085                         FILE_CREATE, /* create_disposition, */
1086                         FILE_DELETE_ON_CLOSE, /* create_options, */
1087                         NULL, /* smb2_create_blobs *blobs */
1088                         &fid_persistent,
1089                         &fid_volatile);
1090         if (!NT_STATUS_IS_OK(status)) {
1091                 printf("smb2cli_create %s\n", nt_errstr(status));
1092                 return false;
1093         }
1094
1095         status = auth_generic_client_prepare(talloc_tos(), &auth_generic_state);
1096         if (!NT_STATUS_IS_OK(status)) {
1097                 printf("auth_generic_client_prepare returned %s\n", nt_errstr(status));
1098                 return false;
1099         }
1100
1101         gensec_want_feature(auth_generic_state->gensec_security,
1102                             GENSEC_FEATURE_SESSION_KEY);
1103         status = auth_generic_set_username(auth_generic_state, username);
1104         if (!NT_STATUS_IS_OK(status)) {
1105                 printf("auth_generic_set_username returned %s\n", nt_errstr(status));
1106                 return false;
1107         }
1108
1109         status = auth_generic_set_domain(auth_generic_state, workgroup);
1110         if (!NT_STATUS_IS_OK(status)) {
1111                 printf("auth_generic_set_domain returned %s\n", nt_errstr(status));
1112                 return false;
1113         }
1114
1115         status = auth_generic_set_password(auth_generic_state, password);
1116         if (!NT_STATUS_IS_OK(status)) {
1117                 printf("auth_generic_set_password returned %s\n", nt_errstr(status));
1118                 return false;
1119         }
1120
1121         status = auth_generic_client_start(auth_generic_state, GENSEC_OID_NTLMSSP);
1122         if (!NT_STATUS_IS_OK(status)) {
1123                 printf("auth_generic_client_start returned %s\n", nt_errstr(status));
1124                 return false;
1125         }
1126
1127         ev = event_context_init(talloc_tos());
1128         if (ev == NULL) {
1129                 printf("event_context_init() returned NULL\n");
1130                 return false;
1131         }
1132
1133         status = gensec_update(auth_generic_state->gensec_security, talloc_tos(), ev, data_blob_null, &in_blob);
1134         if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
1135                 printf("gensec_update returned %s\n", nt_errstr(status));
1136                 return false;
1137         }
1138
1139         subreq = smb2cli_session_setup_send(talloc_tos(), ev,
1140                                             cli->conn,
1141                                             cli->timeout,
1142                                             cli->smb2.session,
1143                                             0x0, /* in_flags */
1144                                             SMB2_CAP_DFS, /* in_capabilities */
1145                                             0, /* in_channel */
1146                                             NULL, /* in_previous_session */
1147                                             &in_blob); /* in_security_buffer */
1148         if (subreq == NULL) {
1149                 printf("smb2cli_session_setup_send() returned NULL\n");
1150                 return false;
1151         }
1152
1153         ok = tevent_req_poll(subreq, ev);
1154         if (!ok) {
1155                 printf("tevent_req_poll() returned false\n");
1156                 return false;
1157         }
1158
1159         status = smb2cli_session_setup_recv(subreq, talloc_tos(),
1160                                             NULL, &out_blob);
1161         if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
1162                 printf("smb2cli_session_setup_recv returned %s\n",
1163                         nt_errstr(status));
1164                 return false;
1165         }
1166
1167         status = gensec_update(auth_generic_state->gensec_security, talloc_tos(), ev, out_blob, &in_blob);
1168         if (!NT_STATUS_IS_OK(status)) {
1169                 printf("auth_generic_update returned %s\n", nt_errstr(status));
1170                 return false;
1171         }
1172
1173         subreq = smb2cli_session_setup_send(talloc_tos(), ev,
1174                                             cli->conn,
1175                                             cli->timeout,
1176                                             cli->smb2.session,
1177                                             0x0, /* in_flags */
1178                                             SMB2_CAP_DFS, /* in_capabilities */
1179                                             0, /* in_channel */
1180                                             NULL, /* in_previous_session */
1181                                             &in_blob); /* in_security_buffer */
1182         if (subreq == NULL) {
1183                 printf("smb2cli_session_setup_send() returned NULL\n");
1184                 return false;
1185         }
1186
1187         ok = tevent_req_poll(subreq, ev);
1188         if (!ok) {
1189                 printf("tevent_req_poll() returned false\n");
1190                 return false;
1191         }
1192
1193         status = smb2cli_session_setup_recv(subreq, talloc_tos(),
1194                                             &recv_iov, &out_blob);
1195         if (!NT_STATUS_IS_OK(status)) {
1196                 printf("smb2cli_session_setup_recv returned %s\n",
1197                         nt_errstr(status));
1198                 return false;
1199         }
1200
1201         status = smb2cli_flush(cli, fid_persistent, fid_volatile);
1202         if (!NT_STATUS_IS_OK(status)) {
1203                 printf("smb2cli_flush returned %s\n", nt_errstr(status));
1204                 return false;
1205         }
1206
1207         status = smb2cli_close(cli, 0, fid_persistent, fid_volatile);
1208         if (!NT_STATUS_IS_OK(status)) {
1209                 printf("smb2cli_close returned %s\n", nt_errstr(status));
1210                 return false;
1211         }
1212
1213         status = smb2cli_create(cli, "session-reauth.txt",
1214                         SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
1215                         SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
1216                         SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */
1217                         FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
1218                         FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
1219                         FILE_CREATE, /* create_disposition, */
1220                         FILE_DELETE_ON_CLOSE, /* create_options, */
1221                         NULL, /* smb2_create_blobs *blobs */
1222                         &fid_persistent,
1223                         &fid_volatile);
1224         if (!NT_STATUS_IS_OK(status)) {
1225                 printf("smb2cli_create %s\n", nt_errstr(status));
1226                 return false;
1227         }
1228
1229         status = smb2cli_close(cli, 0, fid_persistent, fid_volatile);
1230         if (!NT_STATUS_IS_OK(status)) {
1231                 printf("smb2cli_close returned %s\n", nt_errstr(status));
1232                 return false;
1233         }
1234
1235         return true;
1236 }