d639bbf9285841ad729fc06ed90a2ca155aaeed8
[kamenim/samba-autobuild/.git] / source3 / smbd / smb2_read.c
1 /*
2    Unix SMB/CIFS implementation.
3    Core SMB2 server
4
5    Copyright (C) Stefan Metzmacher 2009
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "includes.h"
22 #include "system/filesys.h"
23 #include "smbd/smbd.h"
24 #include "smbd/globals.h"
25 #include "../libcli/smb/smb_common.h"
26 #include "libcli/security/security.h"
27 #include "../lib/util/tevent_ntstatus.h"
28 #include "rpc_server/srv_pipe_hnd.h"
29 #include "lib/util/sys_rw_data.h"
30
31 static struct tevent_req *smbd_smb2_read_send(TALLOC_CTX *mem_ctx,
32                                               struct tevent_context *ev,
33                                               struct smbd_smb2_request *smb2req,
34                                               struct files_struct *in_fsp,
35                                               uint8_t in_flags,
36                                               uint32_t in_length,
37                                               uint64_t in_offset,
38                                               uint32_t in_minimum,
39                                               uint32_t in_remaining);
40 static NTSTATUS smbd_smb2_read_recv(struct tevent_req *req,
41                                     TALLOC_CTX *mem_ctx,
42                                     DATA_BLOB *out_data,
43                                     uint32_t *out_remaining);
44
45 static void smbd_smb2_request_read_done(struct tevent_req *subreq);
46 NTSTATUS smbd_smb2_request_process_read(struct smbd_smb2_request *req)
47 {
48         struct smbXsrv_connection *xconn = req->xconn;
49         NTSTATUS status;
50         const uint8_t *inbody;
51         uint8_t in_flags;
52         uint32_t in_length;
53         uint64_t in_offset;
54         uint64_t in_file_id_persistent;
55         uint64_t in_file_id_volatile;
56         struct files_struct *in_fsp;
57         uint32_t in_minimum_count;
58         uint32_t in_remaining_bytes;
59         struct tevent_req *subreq;
60
61         status = smbd_smb2_request_verify_sizes(req, 0x31);
62         if (!NT_STATUS_IS_OK(status)) {
63                 return smbd_smb2_request_error(req, status);
64         }
65         inbody = SMBD_SMB2_IN_BODY_PTR(req);
66
67         if (xconn->protocol >= PROTOCOL_SMB3_02) {
68                 in_flags                = CVAL(inbody, 0x03);
69         } else {
70                 in_flags                = 0;
71         }
72         in_length               = IVAL(inbody, 0x04);
73         in_offset               = BVAL(inbody, 0x08);
74         in_file_id_persistent   = BVAL(inbody, 0x10);
75         in_file_id_volatile     = BVAL(inbody, 0x18);
76         in_minimum_count        = IVAL(inbody, 0x20);
77         in_remaining_bytes      = IVAL(inbody, 0x28);
78
79         /* check the max read size */
80         if (in_length > xconn->smb2.server.max_read) {
81                 DEBUG(2,("smbd_smb2_request_process_read: "
82                          "client ignored max read: %s: 0x%08X: 0x%08X\n",
83                         __location__, in_length, xconn->smb2.server.max_read));
84                 return smbd_smb2_request_error(req, NT_STATUS_INVALID_PARAMETER);
85         }
86
87         status = smbd_smb2_request_verify_creditcharge(req, in_length);
88         if (!NT_STATUS_IS_OK(status)) {
89                 return smbd_smb2_request_error(req, status);
90         }
91
92         in_fsp = file_fsp_smb2(req, in_file_id_persistent, in_file_id_volatile);
93         if (in_fsp == NULL) {
94                 return smbd_smb2_request_error(req, NT_STATUS_FILE_CLOSED);
95         }
96
97         subreq = smbd_smb2_read_send(req, req->sconn->ev_ctx,
98                                      req, in_fsp,
99                                      in_flags,
100                                      in_length,
101                                      in_offset,
102                                      in_minimum_count,
103                                      in_remaining_bytes);
104         if (subreq == NULL) {
105                 return smbd_smb2_request_error(req, NT_STATUS_NO_MEMORY);
106         }
107         tevent_req_set_callback(subreq, smbd_smb2_request_read_done, req);
108
109         return smbd_smb2_request_pending_queue(req, subreq, 500);
110 }
111
112 static void smbd_smb2_request_read_done(struct tevent_req *subreq)
113 {
114         struct smbd_smb2_request *req = tevent_req_callback_data(subreq,
115                                         struct smbd_smb2_request);
116         DATA_BLOB outbody;
117         DATA_BLOB outdyn;
118         uint8_t out_data_offset;
119         DATA_BLOB out_data_buffer = data_blob_null;
120         uint32_t out_data_remaining = 0;
121         NTSTATUS status;
122         NTSTATUS error; /* transport error */
123
124         status = smbd_smb2_read_recv(subreq,
125                                      req,
126                                      &out_data_buffer,
127                                      &out_data_remaining);
128         TALLOC_FREE(subreq);
129         if (!NT_STATUS_IS_OK(status)) {
130                 error = smbd_smb2_request_error(req, status);
131                 if (!NT_STATUS_IS_OK(error)) {
132                         smbd_server_connection_terminate(req->xconn,
133                                                          nt_errstr(error));
134                         return;
135                 }
136                 return;
137         }
138
139         out_data_offset = SMB2_HDR_BODY + 0x10;
140
141         outbody = smbd_smb2_generate_outbody(req, 0x10);
142         if (outbody.data == NULL) {
143                 error = smbd_smb2_request_error(req, NT_STATUS_NO_MEMORY);
144                 if (!NT_STATUS_IS_OK(error)) {
145                         smbd_server_connection_terminate(req->xconn,
146                                                          nt_errstr(error));
147                         return;
148                 }
149                 return;
150         }
151
152         SSVAL(outbody.data, 0x00, 0x10 + 1);    /* struct size */
153         SCVAL(outbody.data, 0x02,
154               out_data_offset);                 /* data offset */
155         SCVAL(outbody.data, 0x03, 0);           /* reserved */
156         SIVAL(outbody.data, 0x04,
157               out_data_buffer.length);          /* data length */
158         SIVAL(outbody.data, 0x08,
159               out_data_remaining);              /* data remaining */
160         SIVAL(outbody.data, 0x0C, 0);           /* reserved */
161
162         outdyn = out_data_buffer;
163
164         error = smbd_smb2_request_done(req, outbody, &outdyn);
165         if (!NT_STATUS_IS_OK(error)) {
166                 smbd_server_connection_terminate(req->xconn,
167                                                  nt_errstr(error));
168                 return;
169         }
170 }
171
172 struct smbd_smb2_read_state {
173         struct smbd_smb2_request *smb2req;
174         struct smb_request *smbreq;
175         files_struct *fsp;
176         uint8_t in_flags;
177         uint32_t in_length;
178         uint64_t in_offset;
179         uint32_t in_minimum;
180         DATA_BLOB out_headers;
181         uint8_t _out_hdr_buf[NBT_HDR_SIZE + SMB2_HDR_BODY + 0x10];
182         DATA_BLOB out_data;
183         uint32_t out_remaining;
184 };
185
186 static int smb2_smb2_read_state_deny_destructor(struct smbd_smb2_read_state *state)
187 {
188         return -1;
189 }
190
191 /* struct smbd_smb2_read_state destructor. Send the SMB2_READ data. */
192 static int smb2_sendfile_send_data(struct smbd_smb2_read_state *state)
193 {
194         struct lock_struct lock;
195         uint32_t in_length = state->in_length;
196         uint64_t in_offset = state->in_offset;
197         files_struct *fsp = state->fsp;
198         const DATA_BLOB *hdr = state->smb2req->queue_entry.sendfile_header;
199         NTSTATUS *pstatus = state->smb2req->queue_entry.sendfile_status;
200         struct smbXsrv_connection *xconn = state->smb2req->xconn;
201         ssize_t nread;
202         ssize_t ret;
203         int saved_errno;
204
205         nread = SMB_VFS_SENDFILE(xconn->transport.sock,
206                                  fsp,
207                                  hdr,
208                                  in_offset,
209                                  in_length);
210         DEBUG(10,("smb2_sendfile_send_data: SMB_VFS_SENDFILE returned %d on file %s\n",
211                 (int)nread,
212                 fsp_str_dbg(fsp) ));
213
214         if (nread == -1) {
215                 saved_errno = errno;
216
217                 /*
218                  * Returning ENOSYS means no data at all was sent.
219                    Do this as a normal read. */
220                 if (errno == ENOSYS) {
221                         goto normal_read;
222                 }
223
224                 if (errno == ENOTSUP) {
225                         set_use_sendfile(SNUM(fsp->conn), false);
226                         DBG_WARNING("Disabling sendfile use as sendfile is "
227                                     "not supported by the system\n");
228                         goto normal_read;
229                 }
230
231                 if (errno == EINTR) {
232                         /*
233                          * Special hack for broken Linux with no working sendfile. If we
234                          * return EINTR we sent the header but not the rest of the data.
235                          * Fake this up by doing read/write calls.
236                          */
237                         set_use_sendfile(SNUM(fsp->conn), false);
238                         nread = fake_sendfile(xconn, fsp, in_offset, in_length);
239                         if (nread == -1) {
240                                 saved_errno = errno;
241                                 DEBUG(0,("smb2_sendfile_send_data: fake_sendfile "
242                                          "failed for file %s (%s) for client %s. "
243                                          "Terminating\n",
244                                          fsp_str_dbg(fsp), strerror(saved_errno),
245                                          smbXsrv_connection_dbg(xconn)));
246                                 *pstatus = map_nt_error_from_unix_common(saved_errno);
247                                 return 0;
248                         }
249                         goto out;
250                 }
251
252                 DEBUG(0,("smb2_sendfile_send_data: sendfile failed for file "
253                          "%s (%s) for client %s. Terminating\n",
254                          fsp_str_dbg(fsp), strerror(saved_errno),
255                          smbXsrv_connection_dbg(xconn)));
256                 *pstatus = map_nt_error_from_unix_common(saved_errno);
257                 return 0;
258         } else if (nread == 0) {
259                 /*
260                  * Some sendfile implementations return 0 to indicate
261                  * that there was a short read, but nothing was
262                  * actually written to the socket.  In this case,
263                  * fallback to the normal read path so the header gets
264                  * the correct byte count.
265                  */
266                 DEBUG(3, ("send_file_readX: sendfile sent zero bytes "
267                         "falling back to the normal read: %s\n",
268                         fsp_str_dbg(fsp)));
269                 goto normal_read;
270         }
271
272         /*
273          * We got a short read
274          */
275         goto out;
276
277 normal_read:
278         /* Send out the header. */
279         ret = write_data(xconn->transport.sock,
280                          (const char *)hdr->data, hdr->length);
281         if (ret != hdr->length) {
282                 saved_errno = errno;
283                 DEBUG(0,("smb2_sendfile_send_data: write_data failed for file "
284                          "%s (%s) for client %s. Terminating\n",
285                          fsp_str_dbg(fsp), strerror(saved_errno),
286                          smbXsrv_connection_dbg(xconn)));
287                 *pstatus = map_nt_error_from_unix_common(saved_errno);
288                 return 0;
289         }
290         nread = fake_sendfile(xconn, fsp, in_offset, in_length);
291         if (nread == -1) {
292                 saved_errno = errno;
293                 DEBUG(0,("smb2_sendfile_send_data: fake_sendfile "
294                          "failed for file %s (%s) for client %s. "
295                          "Terminating\n",
296                          fsp_str_dbg(fsp), strerror(saved_errno),
297                          smbXsrv_connection_dbg(xconn)));
298                 *pstatus = map_nt_error_from_unix_common(saved_errno);
299                 return 0;
300         }
301
302   out:
303
304         if (nread < in_length) {
305                 ret = sendfile_short_send(xconn, fsp, nread,
306                                           hdr->length, in_length);
307                 if (ret == -1) {
308                         saved_errno = errno;
309                         DEBUG(0,("%s: sendfile_short_send "
310                                  "failed for file %s (%s) for client %s. "
311                                  "Terminating\n",
312                                  __func__,
313                                  fsp_str_dbg(fsp), strerror(saved_errno),
314                                  smbXsrv_connection_dbg(xconn)));
315                         *pstatus = map_nt_error_from_unix_common(saved_errno);
316                         return 0;
317                 }
318         }
319
320         init_strict_lock_struct(fsp,
321                                 fsp->op->global->open_persistent_id,
322                                 in_offset,
323                                 in_length,
324                                 READ_LOCK,
325                                 &lock);
326
327         SMB_VFS_STRICT_UNLOCK(fsp->conn, fsp, &lock);
328
329         *pstatus = NT_STATUS_OK;
330         return 0;
331 }
332
333 static NTSTATUS schedule_smb2_sendfile_read(struct smbd_smb2_request *smb2req,
334                                         struct smbd_smb2_read_state *state)
335 {
336         files_struct *fsp = state->fsp;
337
338         /*
339          * We cannot use sendfile if...
340          * We were not configured to do so OR
341          * Signing is active OR
342          * This is a compound SMB2 operation OR
343          * fsp is a STREAM file OR
344          * We're using a write cache OR
345          * It's not a regular file OR
346          * Requested offset is greater than file size OR
347          * there's not enough data in the file.
348          * Phew :-). Luckily this means most
349          * reads on most normal files. JRA.
350         */
351
352         if (!lp__use_sendfile(SNUM(fsp->conn)) ||
353             smb2req->do_signing ||
354             smb2req->do_encryption ||
355             smb2req->in.vector_count >= (2*SMBD_SMB2_NUM_IOV_PER_REQ) ||
356             (fsp->base_fsp != NULL) ||
357             (fsp->wcp != NULL) ||
358             (!S_ISREG(fsp->fsp_name->st.st_ex_mode)) ||
359             (state->in_offset >= fsp->fsp_name->st.st_ex_size) ||
360             (fsp->fsp_name->st.st_ex_size < state->in_offset + state->in_length))
361         {
362                 return NT_STATUS_RETRY;
363         }
364
365         /* We've already checked there's this amount of data
366            to read. */
367         state->out_data.length = state->in_length;
368         state->out_remaining = 0;
369
370         state->out_headers = data_blob_const(state->_out_hdr_buf,
371                                              sizeof(state->_out_hdr_buf));
372         return NT_STATUS_OK;
373 }
374
375 static void smbd_smb2_read_pipe_done(struct tevent_req *subreq);
376
377 /*******************************************************************
378  Common read complete processing function for both synchronous and
379  asynchronous reads.
380 *******************************************************************/
381
382 NTSTATUS smb2_read_complete(struct tevent_req *req, ssize_t nread, int err)
383 {
384         struct smbd_smb2_read_state *state = tevent_req_data(req,
385                                         struct smbd_smb2_read_state);
386         files_struct *fsp = state->fsp;
387
388         if (nread < 0) {
389                 NTSTATUS status = map_nt_error_from_unix(err);
390
391                 DEBUG( 3,( "smb2_read_complete: file %s nread = %d. "
392                         "Error = %s (NTSTATUS %s)\n",
393                         fsp_str_dbg(fsp),
394                         (int)nread,
395                         strerror(err),
396                         nt_errstr(status)));
397
398                 return status;
399         }
400         if (nread == 0 && state->in_length != 0) {
401                 DEBUG(5,("smb2_read_complete: read_file[%s] end of file\n",
402                         fsp_str_dbg(fsp)));
403                 return NT_STATUS_END_OF_FILE;
404         }
405
406         if (nread < state->in_minimum) {
407                 DEBUG(5,("smb2_read_complete: read_file[%s] read less %d than "
408                         "minimum requested %u. Returning end of file\n",
409                         fsp_str_dbg(fsp),
410                         (int)nread,
411                         (unsigned int)state->in_minimum));
412                 return NT_STATUS_END_OF_FILE;
413         }
414
415         DEBUG(3,("smbd_smb2_read: %s, file %s, length=%lu offset=%lu read=%lu\n",
416                 fsp_fnum_dbg(fsp),
417                 fsp_str_dbg(fsp),
418                 (unsigned long)state->in_length,
419                 (unsigned long)state->in_offset,
420                 (unsigned long)nread));
421
422         state->out_data.length = nread;
423         state->out_remaining = 0;
424
425         return NT_STATUS_OK;
426 }
427
428 static bool smbd_smb2_read_cancel(struct tevent_req *req)
429 {
430         struct smbd_smb2_read_state *state =
431                 tevent_req_data(req,
432                 struct smbd_smb2_read_state);
433
434         return cancel_smb2_aio(state->smbreq);
435 }
436
437 static struct tevent_req *smbd_smb2_read_send(TALLOC_CTX *mem_ctx,
438                                               struct tevent_context *ev,
439                                               struct smbd_smb2_request *smb2req,
440                                               struct files_struct *fsp,
441                                               uint8_t in_flags,
442                                               uint32_t in_length,
443                                               uint64_t in_offset,
444                                               uint32_t in_minimum,
445                                               uint32_t in_remaining)
446 {
447         NTSTATUS status;
448         struct tevent_req *req = NULL;
449         struct smbd_smb2_read_state *state = NULL;
450         struct smb_request *smbreq = NULL;
451         connection_struct *conn = smb2req->tcon->compat;
452         ssize_t nread = -1;
453         struct lock_struct lock;
454         int saved_errno;
455
456         req = tevent_req_create(mem_ctx, &state,
457                                 struct smbd_smb2_read_state);
458         if (req == NULL) {
459                 return NULL;
460         }
461         state->smb2req = smb2req;
462         state->in_flags = in_flags;
463         state->in_length = in_length;
464         state->in_offset = in_offset;
465         state->in_minimum = in_minimum;
466         state->out_data = data_blob_null;
467         state->out_remaining = 0;
468
469         DEBUG(10,("smbd_smb2_read: %s - %s\n",
470                   fsp_str_dbg(fsp), fsp_fnum_dbg(fsp)));
471
472         smbreq = smbd_smb2_fake_smb_request(smb2req);
473         if (tevent_req_nomem(smbreq, req)) {
474                 return tevent_req_post(req, ev);
475         }
476         state->smbreq = smbreq;
477
478         if (fsp->is_directory) {
479                 tevent_req_nterror(req, NT_STATUS_INVALID_DEVICE_REQUEST);
480                 return tevent_req_post(req, ev);
481         }
482
483         state->fsp = fsp;
484
485         if (IS_IPC(smbreq->conn)) {
486                 struct tevent_req *subreq = NULL;
487
488                 state->out_data = data_blob_talloc(state, NULL, in_length);
489                 if (in_length > 0 && tevent_req_nomem(state->out_data.data, req)) {
490                         return tevent_req_post(req, ev);
491                 }
492
493                 if (!fsp_is_np(fsp)) {
494                         tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
495                         return tevent_req_post(req, ev);
496                 }
497
498                 subreq = np_read_send(state, ev,
499                                       fsp->fake_file_handle,
500                                       state->out_data.data,
501                                       state->out_data.length);
502                 if (tevent_req_nomem(subreq, req)) {
503                         return tevent_req_post(req, ev);
504                 }
505                 tevent_req_set_callback(subreq,
506                                         smbd_smb2_read_pipe_done,
507                                         req);
508                 return req;
509         }
510
511         if (!CHECK_READ_SMB2(fsp)) {
512                 tevent_req_nterror(req, NT_STATUS_ACCESS_DENIED);
513                 return tevent_req_post(req, ev);
514         }
515
516         status = schedule_smb2_aio_read(fsp->conn,
517                                 smbreq,
518                                 fsp,
519                                 state,
520                                 &state->out_data,
521                                 (off_t)in_offset,
522                                 (size_t)in_length);
523
524         if (NT_STATUS_IS_OK(status)) {
525                 /*
526                  * Doing an async read, allow this
527                  * request to be canceled
528                  */
529                 tevent_req_set_cancel_fn(req, smbd_smb2_read_cancel);
530                 return req;
531         }
532
533         if (!NT_STATUS_EQUAL(status, NT_STATUS_RETRY)) {
534                 /* Real error in setting up aio. Fail. */
535                 tevent_req_nterror(req, status);
536                 return tevent_req_post(req, ev);
537         }
538
539         /* Fallback to synchronous. */
540
541         init_strict_lock_struct(fsp,
542                                 fsp->op->global->open_persistent_id,
543                                 in_offset,
544                                 in_length,
545                                 READ_LOCK,
546                                 &lock);
547
548         if (!SMB_VFS_STRICT_LOCK(conn, fsp, &lock)) {
549                 tevent_req_nterror(req, NT_STATUS_FILE_LOCK_CONFLICT);
550                 return tevent_req_post(req, ev);
551         }
552
553         /* Try sendfile in preference. */
554         status = schedule_smb2_sendfile_read(smb2req, state);
555         if (NT_STATUS_IS_OK(status)) {
556                 tevent_req_done(req);
557                 return tevent_req_post(req, ev);
558         } else {
559                 if (!NT_STATUS_EQUAL(status, NT_STATUS_RETRY)) {
560                         SMB_VFS_STRICT_UNLOCK(conn, fsp, &lock);
561                         tevent_req_nterror(req, status);
562                         return tevent_req_post(req, ev);
563                 }
564         }
565
566         /* Ok, read into memory. Allocate the out buffer. */
567         state->out_data = data_blob_talloc(state, NULL, in_length);
568         if (in_length > 0 && tevent_req_nomem(state->out_data.data, req)) {
569                 SMB_VFS_STRICT_UNLOCK(conn, fsp, &lock);
570                 return tevent_req_post(req, ev);
571         }
572
573         nread = read_file(fsp,
574                           (char *)state->out_data.data,
575                           in_offset,
576                           in_length);
577
578         saved_errno = errno;
579
580         SMB_VFS_STRICT_UNLOCK(conn, fsp, &lock);
581
582         DEBUG(10,("smbd_smb2_read: file %s, %s, offset=%llu "
583                 "len=%llu returned %lld\n",
584                 fsp_str_dbg(fsp),
585                 fsp_fnum_dbg(fsp),
586                 (unsigned long long)in_offset,
587                 (unsigned long long)in_length,
588                 (long long)nread));
589
590         status = smb2_read_complete(req, nread, saved_errno);
591         if (!NT_STATUS_IS_OK(status)) {
592                 tevent_req_nterror(req, status);
593         } else {
594                 /* Success. */
595                 tevent_req_done(req);
596         }
597         return tevent_req_post(req, ev);
598 }
599
600 static void smbd_smb2_read_pipe_done(struct tevent_req *subreq)
601 {
602         struct tevent_req *req = tevent_req_callback_data(subreq,
603                                  struct tevent_req);
604         struct smbd_smb2_read_state *state = tevent_req_data(req,
605                                              struct smbd_smb2_read_state);
606         NTSTATUS status;
607         ssize_t nread = -1;
608         bool is_data_outstanding;
609
610         status = np_read_recv(subreq, &nread, &is_data_outstanding);
611         TALLOC_FREE(subreq);
612         if (!NT_STATUS_IS_OK(status)) {
613                 NTSTATUS old = status;
614                 status = nt_status_np_pipe(old);
615                 tevent_req_nterror(req, status);
616                 return;
617         }
618
619         if (nread == 0 && state->out_data.length != 0) {
620                 tevent_req_nterror(req, NT_STATUS_END_OF_FILE);
621                 return;
622         }
623
624         state->out_data.length = nread;
625         state->out_remaining = 0;
626
627         /*
628          * TODO: add STATUS_BUFFER_OVERFLOW handling, once we also
629          * handle it in SMB1 pipe_read_andx_done().
630          */
631
632         tevent_req_done(req);
633 }
634
635 static NTSTATUS smbd_smb2_read_recv(struct tevent_req *req,
636                                     TALLOC_CTX *mem_ctx,
637                                     DATA_BLOB *out_data,
638                                     uint32_t *out_remaining)
639 {
640         NTSTATUS status;
641         struct smbd_smb2_read_state *state = tevent_req_data(req,
642                                              struct smbd_smb2_read_state);
643
644         if (tevent_req_is_nterror(req, &status)) {
645                 tevent_req_received(req);
646                 return status;
647         }
648
649         *out_data = state->out_data;
650         talloc_steal(mem_ctx, out_data->data);
651         *out_remaining = state->out_remaining;
652
653         if (state->out_headers.length > 0) {
654                 talloc_steal(mem_ctx, state);
655                 talloc_set_destructor(state, smb2_smb2_read_state_deny_destructor);
656                 tevent_req_received(req);
657                 state->smb2req->queue_entry.sendfile_header = &state->out_headers;
658                 talloc_set_destructor(state, smb2_sendfile_send_data);
659         } else {
660                 tevent_req_received(req);
661         }
662
663         return NT_STATUS_OK;
664 }