s3:smb2_ioctl: call SMB_VFS_FSCTL() as fallback for non SMB2 specific functions
[samba.git] / source3 / smbd / smb2_ioctl.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 "smbd/smbd.h"
23 #include "smbd/globals.h"
24 #include "../libcli/smb/smb_common.h"
25 #include "../lib/util/tevent_ntstatus.h"
26 #include "rpc_server/srv_pipe_hnd.h"
27 #include "include/ntioctl.h"
28
29 static struct tevent_req *smbd_smb2_ioctl_send(TALLOC_CTX *mem_ctx,
30                                                struct tevent_context *ev,
31                                                struct smbd_smb2_request *smb2req,
32                                                uint32_t in_ctl_code,
33                                                uint64_t in_file_id_volatile,
34                                                DATA_BLOB in_input,
35                                                uint32_t in_max_output,
36                                                uint32_t in_flags);
37 static NTSTATUS smbd_smb2_ioctl_recv(struct tevent_req *req,
38                                      TALLOC_CTX *mem_ctx,
39                                      DATA_BLOB *out_output);
40
41 static void smbd_smb2_request_ioctl_done(struct tevent_req *subreq);
42 NTSTATUS smbd_smb2_request_process_ioctl(struct smbd_smb2_request *req)
43 {
44         NTSTATUS status;
45         const uint8_t *inbody;
46         int i = req->current_idx;
47         uint32_t in_ctl_code;
48         uint64_t in_file_id_persistent;
49         uint64_t in_file_id_volatile;
50         uint32_t in_input_offset;
51         uint32_t in_input_length;
52         DATA_BLOB in_input_buffer;
53         uint32_t in_max_output_length;
54         uint32_t in_flags;
55         struct tevent_req *subreq;
56
57         status = smbd_smb2_request_verify_sizes(req, 0x39);
58         if (!NT_STATUS_IS_OK(status)) {
59                 return smbd_smb2_request_error(req, status);
60         }
61         inbody = (const uint8_t *)req->in.vector[i+1].iov_base;
62
63         in_ctl_code             = IVAL(inbody, 0x04);
64         in_file_id_persistent   = BVAL(inbody, 0x08);
65         in_file_id_volatile     = BVAL(inbody, 0x10);
66         in_input_offset         = IVAL(inbody, 0x18);
67         in_input_length         = IVAL(inbody, 0x1C);
68         in_max_output_length    = IVAL(inbody, 0x2C);
69         in_flags                = IVAL(inbody, 0x30);
70
71         /*
72          * InputOffset (4 bytes): The offset, in bytes, from the beginning of
73          * the SMB2 header to the input data buffer. If no input data is
74          * required for the FSCTL/IOCTL command being issued, the client SHOULD
75          * set this value to 0.<49>
76          * <49> If no input data is required for the FSCTL/IOCTL command being
77          * issued, Windows-based clients set this field to any value.
78          */
79         if ((in_input_length > 0)
80          && (in_input_offset != (SMB2_HDR_BODY + req->in.vector[i+1].iov_len))) {
81                 return smbd_smb2_request_error(req, NT_STATUS_INVALID_PARAMETER);
82         }
83
84         if (in_input_length > req->in.vector[i+2].iov_len) {
85                 return smbd_smb2_request_error(req, NT_STATUS_INVALID_PARAMETER);
86         }
87
88         in_input_buffer.data = (uint8_t *)req->in.vector[i+2].iov_base;
89         in_input_buffer.length = in_input_length;
90
91         if (req->compat_chain_fsp) {
92                 /* skip check */
93         } else if (in_file_id_persistent == UINT64_MAX &&
94                    in_file_id_volatile == UINT64_MAX) {
95                 /* without a handle */
96         } else if (in_file_id_persistent != in_file_id_volatile) {
97                 return smbd_smb2_request_error(req, NT_STATUS_FILE_CLOSED);
98         }
99
100         subreq = smbd_smb2_ioctl_send(req,
101                                       req->sconn->ev_ctx,
102                                       req,
103                                       in_ctl_code,
104                                       in_file_id_volatile,
105                                       in_input_buffer,
106                                       in_max_output_length,
107                                       in_flags);
108         if (subreq == NULL) {
109                 return smbd_smb2_request_error(req, NT_STATUS_NO_MEMORY);
110         }
111         tevent_req_set_callback(subreq, smbd_smb2_request_ioctl_done, req);
112
113         return smbd_smb2_request_pending_queue(req, subreq, 1000);
114 }
115
116 static void smbd_smb2_request_ioctl_done(struct tevent_req *subreq)
117 {
118         struct smbd_smb2_request *req = tevent_req_callback_data(subreq,
119                                         struct smbd_smb2_request);
120         const uint8_t *inbody;
121         int i = req->current_idx;
122         DATA_BLOB outbody;
123         DATA_BLOB outdyn;
124         uint32_t in_ctl_code;
125         uint64_t in_file_id_persistent;
126         uint64_t in_file_id_volatile;
127         uint32_t out_input_offset;
128         uint32_t out_output_offset;
129         DATA_BLOB out_output_buffer = data_blob_null;
130         NTSTATUS status;
131         NTSTATUS error; /* transport error */
132
133         status = smbd_smb2_ioctl_recv(subreq, req, &out_output_buffer);
134
135         DEBUG(10,("smbd_smb2_request_ioctl_done: smbd_smb2_ioctl_recv returned "
136                 "%u status %s\n",
137                 (unsigned int)out_output_buffer.length,
138                 nt_errstr(status) ));
139
140         TALLOC_FREE(subreq);
141         if (NT_STATUS_EQUAL(status, STATUS_BUFFER_OVERFLOW)) {
142                 /* also ok */
143         } else if (!NT_STATUS_IS_OK(status)) {
144                 error = smbd_smb2_request_error(req, status);
145                 if (!NT_STATUS_IS_OK(error)) {
146                         smbd_server_connection_terminate(req->sconn,
147                                                          nt_errstr(error));
148                         return;
149                 }
150                 return;
151         }
152
153         out_input_offset = SMB2_HDR_BODY + 0x30;
154         out_output_offset = SMB2_HDR_BODY + 0x30;
155
156         inbody = (const uint8_t *)req->in.vector[i+1].iov_base;
157
158         in_ctl_code             = IVAL(inbody, 0x04);
159         in_file_id_persistent   = BVAL(inbody, 0x08);
160         in_file_id_volatile     = BVAL(inbody, 0x10);
161
162         outbody = data_blob_talloc(req->out.vector, NULL, 0x30);
163         if (outbody.data == NULL) {
164                 error = smbd_smb2_request_error(req, NT_STATUS_NO_MEMORY);
165                 if (!NT_STATUS_IS_OK(error)) {
166                         smbd_server_connection_terminate(req->sconn,
167                                                          nt_errstr(error));
168                         return;
169                 }
170                 return;
171         }
172
173         SSVAL(outbody.data, 0x00, 0x30 + 1);    /* struct size */
174         SSVAL(outbody.data, 0x02, 0);           /* reserved */
175         SIVAL(outbody.data, 0x04,
176               in_ctl_code);                     /* ctl code */
177         SBVAL(outbody.data, 0x08,
178               in_file_id_persistent);           /* file id (persistent) */
179         SBVAL(outbody.data, 0x10,
180               in_file_id_volatile);             /* file id (volatile) */
181         SIVAL(outbody.data, 0x18,
182               out_input_offset);                /* input offset */
183         SIVAL(outbody.data, 0x1C, 0);           /* input count */
184         SIVAL(outbody.data, 0x20,
185               out_output_offset);               /* output offset */
186         SIVAL(outbody.data, 0x24,
187               out_output_buffer.length);        /* output count */
188         SIVAL(outbody.data, 0x28, 0);           /* flags */
189         SIVAL(outbody.data, 0x2C, 0);           /* reserved */
190
191         /*
192          * Note: Windows Vista and 2008 send back also the
193          *       input from the request. But it was fixed in
194          *       Windows 7.
195          */
196         outdyn = out_output_buffer;
197
198         error = smbd_smb2_request_done_ex(req, status, outbody, &outdyn,
199                                           __location__);
200         if (!NT_STATUS_IS_OK(error)) {
201                 smbd_server_connection_terminate(req->sconn,
202                                                  nt_errstr(error));
203                 return;
204         }
205 }
206
207 struct smbd_smb2_ioctl_state {
208         struct smbd_smb2_request *smb2req;
209         struct smb_request *smbreq;
210         files_struct *fsp;
211         DATA_BLOB in_input;
212         uint32_t in_max_output;
213         DATA_BLOB out_output;
214 };
215
216 static void smbd_smb2_ioctl_pipe_write_done(struct tevent_req *subreq);
217 static void smbd_smb2_ioctl_pipe_read_done(struct tevent_req *subreq);
218
219 static struct tevent_req *smbd_smb2_ioctl_send(TALLOC_CTX *mem_ctx,
220                                                struct tevent_context *ev,
221                                                struct smbd_smb2_request *smb2req,
222                                                uint32_t in_ctl_code,
223                                                uint64_t in_file_id_volatile,
224                                                DATA_BLOB in_input,
225                                                uint32_t in_max_output,
226                                                uint32_t in_flags)
227 {
228         struct tevent_req *req;
229         struct smbd_smb2_ioctl_state *state;
230         struct smb_request *smbreq;
231         files_struct *fsp = NULL;
232         struct tevent_req *subreq;
233
234         req = tevent_req_create(mem_ctx, &state,
235                                 struct smbd_smb2_ioctl_state);
236         if (req == NULL) {
237                 return NULL;
238         }
239         state->smb2req = smb2req;
240         state->smbreq = NULL;
241         state->fsp = NULL;
242         state->in_input = in_input;
243         state->in_max_output = in_max_output;
244         state->out_output = data_blob_null;
245
246         DEBUG(10, ("smbd_smb2_ioctl: ctl_code[0x%08x] file_id[0x%016llX]\n",
247                    (unsigned)in_ctl_code,
248                    (unsigned long long)in_file_id_volatile));
249
250         smbreq = smbd_smb2_fake_smb_request(smb2req);
251         if (tevent_req_nomem(smbreq, req)) {
252                 return tevent_req_post(req, ev);
253         }
254         state->smbreq = smbreq;
255
256         if (in_file_id_volatile != UINT64_MAX) {
257                 fsp = file_fsp(smbreq, (uint16_t)in_file_id_volatile);
258                 if (fsp == NULL) {
259                         tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
260                         return tevent_req_post(req, ev);
261                 }
262                 if (smbreq->conn != fsp->conn) {
263                         tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
264                         return tevent_req_post(req, ev);
265                 }
266                 if (smb2req->session->vuid != fsp->vuid) {
267                         tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
268                         return tevent_req_post(req, ev);
269                 }
270                 state->fsp = fsp;
271         }
272
273         switch (in_ctl_code) {
274         case 0x00060194: /* FSCTL_DFS_GET_REFERRALS */
275         {
276                 uint16_t in_max_referral_level;
277                 DATA_BLOB in_file_name_buffer;
278                 char *in_file_name_string;
279                 size_t in_file_name_string_size;
280                 bool ok;
281                 bool overflow = false;
282                 NTSTATUS status;
283                 int dfs_size;
284                 char *dfs_data = NULL;
285
286                 if (!IS_IPC(smbreq->conn)) {
287                         tevent_req_nterror(req, NT_STATUS_INVALID_DEVICE_REQUEST);
288                         return tevent_req_post(req, ev);
289                 }
290
291                 if (!lp_host_msdfs()) {
292                         tevent_req_nterror(req, NT_STATUS_FS_DRIVER_REQUIRED);
293                         return tevent_req_post(req, ev);
294                 }
295
296                 if (in_input.length < (2 + 2)) {
297                         tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
298                         return tevent_req_post(req, ev);
299                 }
300
301                 in_max_referral_level = SVAL(in_input.data, 0);
302                 in_file_name_buffer.data = in_input.data + 2;
303                 in_file_name_buffer.length = in_input.length - 2;
304
305                 ok = convert_string_talloc(state, CH_UTF16, CH_UNIX,
306                                            in_file_name_buffer.data,
307                                            in_file_name_buffer.length,
308                                            &in_file_name_string,
309                                            &in_file_name_string_size);
310                 if (!ok) {
311                         tevent_req_nterror(req, NT_STATUS_ILLEGAL_CHARACTER);
312                         return tevent_req_post(req, ev);
313                 }
314
315                 dfs_size = setup_dfs_referral(smbreq->conn,
316                                               in_file_name_string,
317                                               in_max_referral_level,
318                                               &dfs_data, &status);
319                 if (dfs_size < 0) {
320                         tevent_req_nterror(req, status);
321                         return tevent_req_post(req, ev);
322                 }
323
324                 if (dfs_size > in_max_output) {
325                         /*
326                          * TODO: we need a testsuite for this
327                          */
328                         overflow = true;
329                         dfs_size = in_max_output;
330                 }
331
332                 state->out_output = data_blob_talloc(state,
333                                                      (uint8_t *)dfs_data,
334                                                      dfs_size);
335                 SAFE_FREE(dfs_data);
336                 if (dfs_size > 0 &&
337                     tevent_req_nomem(state->out_output.data, req)) {
338                         return tevent_req_post(req, ev);
339                 }
340
341                 if (overflow) {
342                         tevent_req_nterror(req, STATUS_BUFFER_OVERFLOW);
343                 } else {
344                         tevent_req_done(req);
345                 }
346                 return tevent_req_post(req, ev);
347         }
348         case 0x0011C017: /* FSCTL_PIPE_TRANSCEIVE */
349
350                 if (!IS_IPC(smbreq->conn)) {
351                         tevent_req_nterror(req, NT_STATUS_NOT_SUPPORTED);
352                         return tevent_req_post(req, ev);
353                 }
354
355                 if (fsp == NULL) {
356                         tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
357                         return tevent_req_post(req, ev);
358                 }
359
360                 if (!fsp_is_np(fsp)) {
361                         tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
362                         return tevent_req_post(req, ev);
363                 }
364
365                 DEBUG(10,("smbd_smb2_ioctl_send: np_write_send of size %u\n",
366                         (unsigned int)in_input.length ));
367
368                 subreq = np_write_send(state, ev,
369                                        fsp->fake_file_handle,
370                                        in_input.data,
371                                        in_input.length);
372                 if (tevent_req_nomem(subreq, req)) {
373                         return tevent_req_post(req, ev);
374                 }
375                 tevent_req_set_callback(subreq,
376                                         smbd_smb2_ioctl_pipe_write_done,
377                                         req);
378                 return req;
379
380         case 0x00144064:        /* FSCTL_SRV_ENUMERATE_SNAPSHOTS */
381         {
382                 /*
383                  * This is called to retrieve the number of Shadow Copies (a.k.a. snapshots)
384                  * and return their volume names.  If max_data_count is 16, then it is just
385                  * asking for the number of volumes and length of the combined names.
386                  *
387                  * pdata is the data allocated by our caller, but that uses
388                  * total_data_count (which is 0 in our case) rather than max_data_count.
389                  * Allocate the correct amount and return the pointer to let
390                  * it be deallocated when we return.
391                  */
392                 struct shadow_copy_data *shadow_data = NULL;
393                 bool labels = False;
394                 uint32_t labels_data_count = 0;
395                 uint32_t data_count;
396                 uint32_t i;
397                 char *pdata;
398                 NTSTATUS status;
399
400                 if (fsp == NULL) {
401                         tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
402                         return tevent_req_post(req, ev);
403                 }
404
405                 if (in_max_output < 16) {
406                         DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: "
407                                  "in_max_output(%u) < 16 is invalid!\n",
408                                  in_max_output));
409                         tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
410                         return tevent_req_post(req, ev);
411                 }
412
413                 if (in_max_output > 16) {
414                         labels = True;
415                 }
416
417                 shadow_data = talloc_zero(talloc_tos(),
418                                             struct shadow_copy_data);
419                 if (tevent_req_nomem(shadow_data, req)) {
420                         DEBUG(0,("TALLOC_ZERO() failed!\n"));
421                         return tevent_req_post(req, ev);
422                 }
423
424                 /*
425                  * Call the VFS routine to actually do the work.
426                  */
427                 if (SMB_VFS_GET_SHADOW_COPY_DATA(fsp, shadow_data, labels)
428                     != 0) {
429                         if (errno == ENOSYS) {
430                                 DEBUG(5, ("FSCTL_GET_SHADOW_COPY_DATA: "
431                                           "connectpath %s, not supported.\n",
432                                           smbreq->conn->connectpath));
433                                 status = NT_STATUS_NOT_SUPPORTED;
434                         } else {
435                                 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: "
436                                          "connectpath %s, failed.\n",
437                                          smbreq->conn->connectpath));
438                                 status = map_nt_error_from_unix(errno);
439                         }
440                         TALLOC_FREE(shadow_data);
441                         tevent_req_nterror(req, status);
442                         return tevent_req_post(req, ev);
443                 }
444
445                 labels_data_count =
446                         (shadow_data->num_volumes*2*sizeof(SHADOW_COPY_LABEL))
447                         + 2;
448
449                 if (labels) {
450                         data_count = 12+labels_data_count+4;
451                 } else {
452                         data_count = 16;
453                 }
454
455                 if (labels && (in_max_output < data_count)) {
456                         DEBUG(0, ("FSCTL_GET_SHADOW_COPY_DATA: "
457                                   "in_max_output(%u) too small (%u) bytes "
458                                   "needed!\n", in_max_output, data_count));
459                         TALLOC_FREE(shadow_data);
460                         tevent_req_nterror(req, NT_STATUS_BUFFER_TOO_SMALL);
461                         return tevent_req_post(req, ev);
462                 }
463
464                 state->out_output = data_blob_talloc(state, NULL, data_count);
465                 if (tevent_req_nomem(state->out_output.data, req)) {
466                         return tevent_req_post(req, ev);
467                 }
468
469                 pdata = (char *)state->out_output.data;
470
471                 /* num_volumes 4 bytes */
472                 SIVAL(pdata, 0, shadow_data->num_volumes);
473
474                 if (labels) {
475                         /* num_labels 4 bytes */
476                         SIVAL(pdata, 4, shadow_data->num_volumes);
477                 }
478
479                 /* needed_data_count 4 bytes */
480                 SIVAL(pdata, 8, labels_data_count+4);
481
482                 pdata += 12;
483
484                 DEBUG(10,("FSCTL_GET_SHADOW_COPY_DATA: %u volumes for "
485                           "path[%s].\n",
486                           shadow_data->num_volumes, fsp_str_dbg(fsp)));
487                 if (labels && shadow_data->labels) {
488                         for (i=0; i<shadow_data->num_volumes; i++) {
489                                 srvstr_push(pdata, smbreq->flags2,
490                                             pdata, shadow_data->labels[i],
491                                             2*sizeof(SHADOW_COPY_LABEL),
492                                             STR_UNICODE|STR_TERMINATE);
493                                 pdata += 2*sizeof(SHADOW_COPY_LABEL);
494                                 DEBUGADD(10, ("Label[%u]: '%s'\n", i,
495                                               shadow_data->labels[i]));
496                         }
497                 }
498
499                 TALLOC_FREE(shadow_data);
500
501                 tevent_req_done(req);
502                 return tevent_req_post(req, ev);
503         }
504
505         default: {
506                 uint8_t *out_data = NULL;
507                 uint32_t out_data_len = 0;
508                 NTSTATUS status;
509
510                 if (fsp == NULL) {
511                         tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
512                         return tevent_req_post(req, ev);
513                 }
514
515                 status = SMB_VFS_FSCTL(fsp,
516                                        state,
517                                        in_ctl_code,
518                                        smbreq->flags2,
519                                        in_input.data,
520                                        in_input.length,
521                                        &out_data,
522                                        in_max_output,
523                                        &out_data_len);
524                 state->out_output = data_blob_const(out_data, out_data_len);
525                 if (NT_STATUS_IS_OK(status)) {
526                         tevent_req_done(req);
527                         return tevent_req_post(req, ev);
528                 }
529
530                 if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) {
531                         if (IS_IPC(smbreq->conn)) {
532                                 status = NT_STATUS_FS_DRIVER_REQUIRED;
533                         } else {
534                                 status = NT_STATUS_INVALID_DEVICE_REQUEST;
535                         }
536                 }
537
538                 tevent_req_nterror(req, status);
539                 return tevent_req_post(req, ev);
540         }
541         }
542
543         tevent_req_nterror(req, NT_STATUS_INTERNAL_ERROR);
544         return tevent_req_post(req, ev);
545 }
546
547 static void smbd_smb2_ioctl_pipe_write_done(struct tevent_req *subreq)
548 {
549         struct tevent_req *req = tevent_req_callback_data(subreq,
550                                  struct tevent_req);
551         struct smbd_smb2_ioctl_state *state = tevent_req_data(req,
552                                               struct smbd_smb2_ioctl_state);
553         NTSTATUS status;
554         ssize_t nwritten = -1;
555
556         status = np_write_recv(subreq, &nwritten);
557
558         DEBUG(10,("smbd_smb2_ioctl_pipe_write_done: received %ld\n",
559                 (long int)nwritten ));
560
561         TALLOC_FREE(subreq);
562         if (!NT_STATUS_IS_OK(status)) {
563                 tevent_req_nterror(req, status);
564                 return;
565         }
566
567         if (nwritten != state->in_input.length) {
568                 tevent_req_nterror(req, NT_STATUS_PIPE_NOT_AVAILABLE);
569                 return;
570         }
571
572         state->out_output = data_blob_talloc(state, NULL, state->in_max_output);
573         if (state->in_max_output > 0 &&
574             tevent_req_nomem(state->out_output.data, req)) {
575                 return;
576         }
577
578         DEBUG(10,("smbd_smb2_ioctl_pipe_write_done: issuing np_read_send "
579                 "of size %u\n",
580                 (unsigned int)state->out_output.length ));
581
582         TALLOC_FREE(subreq);
583         subreq = np_read_send(state->smbreq->conn,
584                               state->smb2req->sconn->ev_ctx,
585                               state->fsp->fake_file_handle,
586                               state->out_output.data,
587                               state->out_output.length);
588         if (tevent_req_nomem(subreq, req)) {
589                 return;
590         }
591         tevent_req_set_callback(subreq, smbd_smb2_ioctl_pipe_read_done, req);
592 }
593
594 static void smbd_smb2_ioctl_pipe_read_done(struct tevent_req *subreq)
595 {
596         struct tevent_req *req = tevent_req_callback_data(subreq,
597                                  struct tevent_req);
598         struct smbd_smb2_ioctl_state *state = tevent_req_data(req,
599                                               struct smbd_smb2_ioctl_state);
600         NTSTATUS status;
601         ssize_t nread = -1;
602         bool is_data_outstanding = false;
603
604         status = np_read_recv(subreq, &nread, &is_data_outstanding);
605
606         DEBUG(10,("smbd_smb2_ioctl_pipe_read_done: np_read_recv nread = %d "
607                  "is_data_outstanding = %d, status = %s\n",
608                 (int)nread,
609                 (int)is_data_outstanding,
610                 nt_errstr(status) ));
611
612         TALLOC_FREE(subreq);
613         if (!NT_STATUS_IS_OK(status)) {
614                 tevent_req_nterror(req, status);
615                 return;
616         }
617
618         state->out_output.length = nread;
619
620         if (is_data_outstanding) {
621                 tevent_req_nterror(req, STATUS_BUFFER_OVERFLOW);
622                 return;
623         }
624
625         tevent_req_done(req);
626 }
627
628 static NTSTATUS smbd_smb2_ioctl_recv(struct tevent_req *req,
629                                      TALLOC_CTX *mem_ctx,
630                                      DATA_BLOB *out_output)
631 {
632         NTSTATUS status = NT_STATUS_OK;
633         struct smbd_smb2_ioctl_state *state = tevent_req_data(req,
634                                               struct smbd_smb2_ioctl_state);
635
636         if (tevent_req_is_nterror(req, &status)) {
637                 if (!NT_STATUS_EQUAL(status, STATUS_BUFFER_OVERFLOW)) {
638                         tevent_req_received(req);
639                         return status;
640                 }
641         }
642
643         *out_output = state->out_output;
644         talloc_steal(mem_ctx, out_output->data);
645
646         tevent_req_received(req);
647         return status;
648 }