s3:libsmb/clitrans: fix handling of multi pdu [nt]trans[s][2] calls
[Samba/gebeck_regimport.git] / source3 / libsmb / clitrans.c
blobe23598ccbbff733ac643b75af3cf8a1b488318f4
1 /*
2 Unix SMB/CIFS implementation.
3 client transaction calls
4 Copyright (C) Andrew Tridgell 1994-1998
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "includes.h"
21 #include "libsmb/libsmb.h"
22 #include "../lib/util/tevent_ntstatus.h"
23 #include "async_smb.h"
25 struct trans_recvblob {
26 uint8_t *data;
27 uint32_t max, total, received;
30 struct cli_trans_state {
31 struct cli_state *cli;
32 struct event_context *ev;
33 uint8_t cmd;
34 uint16_t mid;
35 uint32_t seqnum;
36 const char *pipe_name;
37 uint8_t *pipe_name_conv;
38 size_t pipe_name_conv_len;
39 uint16_t fid;
40 uint16_t function;
41 int flags;
42 uint16_t *setup;
43 uint8_t num_setup, max_setup;
44 uint8_t *param;
45 uint32_t num_param, param_sent;
46 uint8_t *data;
47 uint32_t num_data, data_sent;
49 uint8_t num_rsetup;
50 uint16_t *rsetup;
51 struct trans_recvblob rparam;
52 struct trans_recvblob rdata;
53 uint16_t recv_flags2;
55 struct iovec iov[6];
56 uint8_t pad[4];
57 uint8_t zero_pad[4];
58 uint16_t vwv[32];
60 struct tevent_req *primary_subreq;
63 static void cli_trans_cleanup_primary(struct cli_trans_state *state)
65 if (state->primary_subreq) {
66 cli_smb_req_set_mid(state->primary_subreq, 0);
67 cli_smb_req_unset_pending(state->primary_subreq);
68 cli_state_seqnum_remove(state->cli, state->mid);
69 TALLOC_FREE(state->primary_subreq);
73 static int cli_trans_state_destructor(struct cli_trans_state *state)
75 cli_trans_cleanup_primary(state);
76 return 0;
79 static NTSTATUS cli_pull_trans(uint8_t *inbuf,
80 uint8_t wct, uint16_t *vwv,
81 uint16_t num_bytes, uint8_t *bytes,
82 uint8_t smb_cmd, bool expect_first_reply,
83 uint8_t *pnum_setup, uint16_t **psetup,
84 uint32_t *ptotal_param, uint32_t *pnum_param,
85 uint32_t *pparam_disp, uint8_t **pparam,
86 uint32_t *ptotal_data, uint32_t *pnum_data,
87 uint32_t *pdata_disp, uint8_t **pdata)
89 uint32_t param_ofs, data_ofs;
91 if (expect_first_reply) {
92 if ((wct != 0) || (num_bytes != 0)) {
93 return NT_STATUS_INVALID_NETWORK_RESPONSE;
95 return NT_STATUS_OK;
98 switch (smb_cmd) {
99 case SMBtrans:
100 case SMBtrans2:
101 if (wct < 10) {
102 return NT_STATUS_INVALID_NETWORK_RESPONSE;
104 *ptotal_param = SVAL(vwv + 0, 0);
105 *ptotal_data = SVAL(vwv + 1, 0);
106 *pnum_param = SVAL(vwv + 3, 0);
107 param_ofs = SVAL(vwv + 4, 0);
108 *pparam_disp = SVAL(vwv + 5, 0);
109 *pnum_data = SVAL(vwv + 6, 0);
110 data_ofs = SVAL(vwv + 7, 0);
111 *pdata_disp = SVAL(vwv + 8, 0);
112 *pnum_setup = CVAL(vwv + 9, 0);
113 if (wct < 10 + (*pnum_setup)) {
114 return NT_STATUS_INVALID_NETWORK_RESPONSE;
116 *psetup = vwv + 10;
118 break;
119 case SMBnttrans:
120 if (wct < 18) {
121 return NT_STATUS_INVALID_NETWORK_RESPONSE;
123 *ptotal_param = IVAL(vwv, 3);
124 *ptotal_data = IVAL(vwv, 7);
125 *pnum_param = IVAL(vwv, 11);
126 param_ofs = IVAL(vwv, 15);
127 *pparam_disp = IVAL(vwv, 19);
128 *pnum_data = IVAL(vwv, 23);
129 data_ofs = IVAL(vwv, 27);
130 *pdata_disp = IVAL(vwv, 31);
131 *pnum_setup = CVAL(vwv, 35);
132 *psetup = vwv + 18;
133 break;
135 default:
136 return NT_STATUS_INTERNAL_ERROR;
140 * Check for buffer overflows. data_ofs needs to be checked against
141 * the incoming buffer length, data_disp against the total
142 * length. Likewise for param_ofs/param_disp.
145 if (trans_oob(smb_len(inbuf), param_ofs, *pnum_param)
146 || trans_oob(*ptotal_param, *pparam_disp, *pnum_param)
147 || trans_oob(smb_len(inbuf), data_ofs, *pnum_data)
148 || trans_oob(*ptotal_data, *pdata_disp, *pnum_data)) {
149 return NT_STATUS_INVALID_NETWORK_RESPONSE;
152 *pparam = (uint8_t *)inbuf + 4 + param_ofs;
153 *pdata = (uint8_t *)inbuf + 4 + data_ofs;
155 return NT_STATUS_OK;
158 static NTSTATUS cli_trans_pull_blob(TALLOC_CTX *mem_ctx,
159 struct trans_recvblob *blob,
160 uint32_t total, uint32_t thistime,
161 uint8_t *buf, uint32_t displacement)
163 if (blob->data == NULL) {
164 if (total > blob->max) {
165 return NT_STATUS_INVALID_NETWORK_RESPONSE;
167 blob->total = total;
168 blob->data = talloc_array(mem_ctx, uint8_t, total);
169 if (blob->data == NULL) {
170 return NT_STATUS_NO_MEMORY;
174 if (total > blob->total) {
175 return NT_STATUS_INVALID_NETWORK_RESPONSE;
178 if (thistime) {
179 memcpy(blob->data + displacement, buf, thistime);
180 blob->received += thistime;
183 return NT_STATUS_OK;
186 static void cli_trans_format(struct cli_trans_state *state, uint8_t *pwct,
187 int *piov_count)
189 uint8_t wct = 0;
190 struct iovec *iov = state->iov;
191 uint8_t *pad = state->pad;
192 uint16_t *vwv = state->vwv;
193 uint32_t param_offset;
194 uint32_t this_param = 0;
195 uint32_t param_pad;
196 uint32_t data_offset;
197 uint32_t this_data = 0;
198 uint32_t data_pad;
199 uint32_t useable_space;
200 uint8_t cmd;
202 cmd = state->cmd;
204 if ((state->param_sent != 0) || (state->data_sent != 0)) {
205 /* The secondary commands are one after the primary ones */
206 cmd += 1;
209 param_offset = smb_size - 4;
211 switch (cmd) {
212 case SMBtrans:
213 pad[0] = 0;
214 iov[0].iov_base = (void *)pad;
215 iov[0].iov_len = 1;
216 iov[1].iov_base = (void *)state->pipe_name_conv;
217 iov[1].iov_len = state->pipe_name_conv_len;
218 wct = 14 + state->num_setup;
219 param_offset += iov[0].iov_len + iov[1].iov_len;
220 iov += 2;
221 break;
222 case SMBtrans2:
223 pad[0] = 0;
224 pad[1] = 'D'; /* Copy this from "old" 3.0 behaviour */
225 pad[2] = ' ';
226 iov[0].iov_base = (void *)pad;
227 iov[0].iov_len = 3;
228 wct = 14 + state->num_setup;
229 param_offset += 3;
230 iov += 1;
231 break;
232 case SMBtranss:
233 wct = 8;
234 break;
235 case SMBtranss2:
236 wct = 9;
237 break;
238 case SMBnttrans:
239 wct = 19 + state->num_setup;
240 break;
241 case SMBnttranss:
242 wct = 18;
243 break;
246 param_offset += wct * sizeof(uint16_t);
247 useable_space = state->cli->max_xmit - param_offset;
249 param_pad = param_offset % 4;
250 if (param_pad > 0) {
251 param_pad = MIN(param_pad, useable_space);
252 iov[0].iov_base = (void *)state->zero_pad;
253 iov[0].iov_len = param_pad;
254 iov += 1;
255 param_offset += param_pad;
257 useable_space = state->cli->max_xmit - param_offset;
259 if (state->param_sent < state->num_param) {
260 this_param = MIN(state->num_param - state->param_sent,
261 useable_space);
262 iov[0].iov_base = (void *)(state->param + state->param_sent);
263 iov[0].iov_len = this_param;
264 iov += 1;
267 data_offset = param_offset + this_param;
268 useable_space = state->cli->max_xmit - data_offset;
270 data_pad = data_offset % 4;
271 if (data_pad > 0) {
272 data_pad = MIN(data_pad, useable_space);
273 iov[0].iov_base = (void *)state->zero_pad;
274 iov[0].iov_len = data_pad;
275 iov += 1;
276 data_offset += data_pad;
278 useable_space = state->cli->max_xmit - data_offset;
280 if (state->data_sent < state->num_data) {
281 this_data = MIN(state->num_data - state->data_sent,
282 useable_space);
283 iov[0].iov_base = (void *)(state->data + state->data_sent);
284 iov[0].iov_len = this_data;
285 iov += 1;
288 DEBUG(10, ("num_setup=%u, max_setup=%u, "
289 "param_total=%u, this_param=%u, max_param=%u, "
290 "data_total=%u, this_data=%u, max_data=%u, "
291 "param_offset=%u, param_pad=%u, param_disp=%u, "
292 "data_offset=%u, data_pad=%u, data_disp=%u\n",
293 (unsigned)state->num_setup, (unsigned)state->max_setup,
294 (unsigned)state->num_param, (unsigned)this_param,
295 (unsigned)state->rparam.max,
296 (unsigned)state->num_data, (unsigned)this_data,
297 (unsigned)state->rdata.max,
298 (unsigned)param_offset, (unsigned)param_pad,
299 (unsigned)state->param_sent,
300 (unsigned)data_offset, (unsigned)data_pad,
301 (unsigned)state->data_sent));
303 switch (cmd) {
304 case SMBtrans:
305 case SMBtrans2:
306 SSVAL(vwv + 0, 0, state->num_param);
307 SSVAL(vwv + 1, 0, state->num_data);
308 SSVAL(vwv + 2, 0, state->rparam.max);
309 SSVAL(vwv + 3, 0, state->rdata.max);
310 SCVAL(vwv + 4, 0, state->max_setup);
311 SCVAL(vwv + 4, 1, 0); /* reserved */
312 SSVAL(vwv + 5, 0, state->flags);
313 SIVAL(vwv + 6, 0, 0); /* timeout */
314 SSVAL(vwv + 8, 0, 0); /* reserved */
315 SSVAL(vwv + 9, 0, this_param);
316 SSVAL(vwv +10, 0, param_offset);
317 SSVAL(vwv +11, 0, this_data);
318 SSVAL(vwv +12, 0, data_offset);
319 SCVAL(vwv +13, 0, state->num_setup);
320 SCVAL(vwv +13, 1, 0); /* reserved */
321 memcpy(vwv + 14, state->setup,
322 sizeof(uint16_t) * state->num_setup);
323 break;
324 case SMBtranss:
325 case SMBtranss2:
326 SSVAL(vwv + 0, 0, state->num_param);
327 SSVAL(vwv + 1, 0, state->num_data);
328 SSVAL(vwv + 2, 0, this_param);
329 SSVAL(vwv + 3, 0, param_offset);
330 SSVAL(vwv + 4, 0, state->param_sent);
331 SSVAL(vwv + 5, 0, this_data);
332 SSVAL(vwv + 6, 0, data_offset);
333 SSVAL(vwv + 7, 0, state->data_sent);
334 if (cmd == SMBtranss2) {
335 SSVAL(vwv + 8, 0, state->fid);
337 break;
338 case SMBnttrans:
339 SCVAL(vwv + 0, 0, state->max_setup);
340 SSVAL(vwv + 0, 1, 0); /* reserved */
341 SIVAL(vwv + 1, 1, state->num_param);
342 SIVAL(vwv + 3, 1, state->num_data);
343 SIVAL(vwv + 5, 1, state->rparam.max);
344 SIVAL(vwv + 7, 1, state->rdata.max);
345 SIVAL(vwv + 9, 1, this_param);
346 SIVAL(vwv +11, 1, param_offset);
347 SIVAL(vwv +13, 1, this_data);
348 SIVAL(vwv +15, 1, data_offset);
349 SCVAL(vwv +17, 1, state->num_setup);
350 SSVAL(vwv +18, 0, state->function);
351 memcpy(vwv + 19, state->setup,
352 sizeof(uint16_t) * state->num_setup);
353 break;
354 case SMBnttranss:
355 SSVAL(vwv + 0, 0, 0); /* reserved */
356 SCVAL(vwv + 1, 0, 0); /* reserved */
357 SIVAL(vwv + 1, 1, state->num_param);
358 SIVAL(vwv + 3, 1, state->num_data);
359 SIVAL(vwv + 5, 1, this_param);
360 SIVAL(vwv + 7, 1, param_offset);
361 SIVAL(vwv + 9, 1, state->param_sent);
362 SIVAL(vwv +11, 1, this_data);
363 SIVAL(vwv +13, 1, data_offset);
364 SIVAL(vwv +15, 1, state->data_sent);
365 SCVAL(vwv +17, 1, 0); /* reserved */
366 break;
369 state->param_sent += this_param;
370 state->data_sent += this_data;
372 *pwct = wct;
373 *piov_count = iov - state->iov;
376 static void cli_trans_done(struct tevent_req *subreq);
378 struct tevent_req *cli_trans_send(
379 TALLOC_CTX *mem_ctx, struct event_context *ev,
380 struct cli_state *cli, uint8_t cmd,
381 const char *pipe_name, uint16_t fid, uint16_t function, int flags,
382 uint16_t *setup, uint8_t num_setup, uint8_t max_setup,
383 uint8_t *param, uint32_t num_param, uint32_t max_param,
384 uint8_t *data, uint32_t num_data, uint32_t max_data)
386 struct tevent_req *req, *subreq;
387 struct cli_trans_state *state;
388 int iov_count;
389 uint8_t wct;
390 NTSTATUS status;
392 req = tevent_req_create(mem_ctx, &state, struct cli_trans_state);
393 if (req == NULL) {
394 return NULL;
397 if ((cmd == SMBtrans) || (cmd == SMBtrans2)) {
398 if ((num_param > 0xffff) || (max_param > 0xffff)
399 || (num_data > 0xffff) || (max_data > 0xffff)) {
400 DEBUG(3, ("Attempt to send invalid trans2 request "
401 "(setup %u, params %u/%u, data %u/%u)\n",
402 (unsigned)num_setup,
403 (unsigned)num_param, (unsigned)max_param,
404 (unsigned)num_data, (unsigned)max_data));
405 tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
406 return tevent_req_post(req, ev);
411 * The largest wct will be for nttrans (19+num_setup). Make sure we
412 * don't overflow state->vwv in cli_trans_format.
415 if ((num_setup + 19) > ARRAY_SIZE(state->vwv)) {
416 tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
417 return tevent_req_post(req, ev);
420 state->cli = cli;
421 state->ev = ev;
422 state->cmd = cmd;
423 state->flags = flags;
424 state->num_rsetup = 0;
425 state->rsetup = NULL;
426 ZERO_STRUCT(state->rparam);
427 ZERO_STRUCT(state->rdata);
429 if ((pipe_name != NULL)
430 && (!convert_string_talloc(state, CH_UNIX,
431 cli_ucs2(cli) ? CH_UTF16LE : CH_DOS,
432 pipe_name, strlen(pipe_name) + 1,
433 &state->pipe_name_conv,
434 &state->pipe_name_conv_len))) {
435 tevent_req_nterror(req, NT_STATUS_NO_MEMORY);
436 return tevent_req_post(req, ev);
438 state->fid = fid; /* trans2 */
439 state->function = function; /* nttrans */
441 state->setup = setup;
442 state->num_setup = num_setup;
443 state->max_setup = max_setup;
445 state->param = param;
446 state->num_param = num_param;
447 state->param_sent = 0;
448 state->rparam.max = max_param;
450 state->data = data;
451 state->num_data = num_data;
452 state->data_sent = 0;
453 state->rdata.max = max_data;
455 cli_trans_format(state, &wct, &iov_count);
457 subreq = cli_smb_req_create(state, ev, cli, cmd, 0, wct, state->vwv,
458 iov_count, state->iov);
459 if (tevent_req_nomem(subreq, req)) {
460 return tevent_req_post(req, ev);
462 status = cli_smb_req_send(subreq);
463 if (!NT_STATUS_IS_OK(status)) {
464 tevent_req_nterror(req, status);
465 return tevent_req_post(req, state->ev);
467 tevent_req_set_callback(subreq, cli_trans_done, req);
470 * Now get the MID of the primary request
471 * and mark it as persistent. This means
472 * we will able to send and receive multiple
473 * SMB pdus using this MID in both directions
474 * (including correct SMB signing).
476 state->mid = cli_smb_req_mid(subreq);
477 cli_smb_req_set_mid(subreq, state->mid);
478 cli_state_seqnum_persistent(cli, state->mid);
479 state->primary_subreq = subreq;
480 talloc_set_destructor(state, cli_trans_state_destructor);
482 return req;
485 static void cli_trans_done2(struct tevent_req *subreq);
487 static void cli_trans_done(struct tevent_req *subreq)
489 struct tevent_req *req = tevent_req_callback_data(
490 subreq, struct tevent_req);
491 struct cli_trans_state *state = tevent_req_data(
492 req, struct cli_trans_state);
493 NTSTATUS status;
494 bool sent_all;
495 uint8_t wct;
496 uint16_t *vwv;
497 uint32_t num_bytes;
498 uint8_t *bytes;
499 uint8_t *inbuf;
500 uint8_t num_setup = 0;
501 uint16_t *setup = NULL;
502 uint32_t total_param = 0;
503 uint32_t num_param = 0;
504 uint32_t param_disp = 0;
505 uint32_t total_data = 0;
506 uint32_t num_data = 0;
507 uint32_t data_disp = 0;
508 uint8_t *param = NULL;
509 uint8_t *data = NULL;
511 status = cli_smb_recv(subreq, state, &inbuf, 0, &wct, &vwv,
512 &num_bytes, &bytes);
514 * Do not TALLOC_FREE(subreq) here, we might receive more than
515 * one response for the same mid.
519 * We can receive something like STATUS_MORE_ENTRIES, so don't use
520 * !NT_STATUS_IS_OK(status) here.
523 if (NT_STATUS_IS_ERR(status)) {
524 goto fail;
527 sent_all = ((state->param_sent == state->num_param)
528 && (state->data_sent == state->num_data));
530 status = cli_pull_trans(
531 inbuf, wct, vwv, num_bytes, bytes,
532 state->cmd, !sent_all, &num_setup, &setup,
533 &total_param, &num_param, &param_disp, &param,
534 &total_data, &num_data, &data_disp, &data);
536 if (!NT_STATUS_IS_OK(status)) {
537 goto fail;
540 if (!sent_all) {
541 int iov_count;
542 struct tevent_req *subreq2;
544 cli_trans_format(state, &wct, &iov_count);
546 subreq2 = cli_smb_req_create(state, state->ev, state->cli,
547 state->cmd + 1, 0, wct, state->vwv,
548 iov_count, state->iov);
549 if (tevent_req_nomem(subreq2, req)) {
550 return;
552 cli_smb_req_set_mid(subreq2, state->mid);
554 status = cli_smb_req_send(subreq2);
556 if (!NT_STATUS_IS_OK(status)) {
557 goto fail;
559 tevent_req_set_callback(subreq2, cli_trans_done2, req);
561 return;
564 status = cli_trans_pull_blob(
565 state, &state->rparam, total_param, num_param, param,
566 param_disp);
568 if (!NT_STATUS_IS_OK(status)) {
569 DEBUG(10, ("Pulling params failed: %s\n", nt_errstr(status)));
570 goto fail;
573 status = cli_trans_pull_blob(
574 state, &state->rdata, total_data, num_data, data,
575 data_disp);
577 if (!NT_STATUS_IS_OK(status)) {
578 DEBUG(10, ("Pulling data failed: %s\n", nt_errstr(status)));
579 goto fail;
582 if ((state->rparam.total == state->rparam.received)
583 && (state->rdata.total == state->rdata.received)) {
584 state->recv_flags2 = SVAL(inbuf, smb_flg2);
585 cli_trans_cleanup_primary(state);
586 tevent_req_done(req);
587 return;
590 TALLOC_FREE(inbuf);
592 return;
594 fail:
595 cli_trans_cleanup_primary(state);
596 tevent_req_nterror(req, status);
599 static void cli_trans_done2(struct tevent_req *subreq2)
601 struct tevent_req *req = tevent_req_callback_data(
602 subreq2, struct tevent_req);
603 struct cli_trans_state *state = tevent_req_data(
604 req, struct cli_trans_state);
605 NTSTATUS status;
606 bool sent_all;
607 uint8_t wct;
609 status = cli_smb_recv(subreq2, state, NULL, 0, &wct, NULL,
610 NULL, NULL);
611 TALLOC_FREE(subreq2);
613 if (!NT_STATUS_IS_OK(status)) {
614 goto fail;
617 if (wct != 0) {
618 status = NT_STATUS_INVALID_NETWORK_RESPONSE;
619 goto fail;
622 sent_all = ((state->param_sent == state->num_param)
623 && (state->data_sent == state->num_data));
625 if (!sent_all) {
626 int iov_count;
628 cli_trans_format(state, &wct, &iov_count);
630 subreq2 = cli_smb_req_create(state, state->ev, state->cli,
631 state->cmd + 1, 0, wct, state->vwv,
632 iov_count, state->iov);
633 if (tevent_req_nomem(subreq2, req)) {
634 return;
636 cli_smb_req_set_mid(subreq2, state->mid);
638 status = cli_smb_req_send(subreq2);
640 if (!NT_STATUS_IS_OK(status)) {
641 goto fail;
643 tevent_req_set_callback(subreq2, cli_trans_done2, req);
644 return;
647 return;
649 fail:
650 cli_trans_cleanup_primary(state);
651 tevent_req_nterror(req, status);
654 NTSTATUS cli_trans_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
655 uint16_t *recv_flags2,
656 uint16_t **setup, uint8_t min_setup,
657 uint8_t *num_setup,
658 uint8_t **param, uint32_t min_param,
659 uint32_t *num_param,
660 uint8_t **data, uint32_t min_data,
661 uint32_t *num_data)
663 struct cli_trans_state *state = tevent_req_data(
664 req, struct cli_trans_state);
665 NTSTATUS status;
667 cli_trans_cleanup_primary(state);
669 if (tevent_req_is_nterror(req, &status)) {
670 return status;
673 if ((state->num_rsetup < min_setup)
674 || (state->rparam.total < min_param)
675 || (state->rdata.total < min_data)) {
676 return NT_STATUS_INVALID_NETWORK_RESPONSE;
679 if (recv_flags2 != NULL) {
680 *recv_flags2 = state->recv_flags2;
683 if (setup != NULL) {
684 *setup = talloc_move(mem_ctx, &state->rsetup);
685 *num_setup = state->num_rsetup;
686 } else {
687 TALLOC_FREE(state->rsetup);
690 if (param != NULL) {
691 *param = talloc_move(mem_ctx, &state->rparam.data);
692 *num_param = state->rparam.total;
693 } else {
694 TALLOC_FREE(state->rparam.data);
697 if (data != NULL) {
698 *data = talloc_move(mem_ctx, &state->rdata.data);
699 *num_data = state->rdata.total;
700 } else {
701 TALLOC_FREE(state->rdata.data);
704 return NT_STATUS_OK;
707 NTSTATUS cli_trans(TALLOC_CTX *mem_ctx, struct cli_state *cli,
708 uint8_t trans_cmd,
709 const char *pipe_name, uint16_t fid, uint16_t function,
710 int flags,
711 uint16_t *setup, uint8_t num_setup, uint8_t max_setup,
712 uint8_t *param, uint32_t num_param, uint32_t max_param,
713 uint8_t *data, uint32_t num_data, uint32_t max_data,
714 uint16_t *recv_flags2,
715 uint16_t **rsetup, uint8_t min_rsetup, uint8_t *num_rsetup,
716 uint8_t **rparam, uint32_t min_rparam, uint32_t *num_rparam,
717 uint8_t **rdata, uint32_t min_rdata, uint32_t *num_rdata)
719 TALLOC_CTX *frame = talloc_stackframe();
720 struct event_context *ev;
721 struct tevent_req *req;
722 NTSTATUS status = NT_STATUS_OK;
724 if (cli_has_async_calls(cli)) {
726 * Can't use sync call while an async call is in flight
728 status = NT_STATUS_INVALID_PARAMETER;
729 goto fail;
732 ev = event_context_init(frame);
733 if (ev == NULL) {
734 status = NT_STATUS_NO_MEMORY;
735 goto fail;
738 req = cli_trans_send(frame, ev, cli, trans_cmd,
739 pipe_name, fid, function, flags,
740 setup, num_setup, max_setup,
741 param, num_param, max_param,
742 data, num_data, max_data);
743 if (req == NULL) {
744 status = NT_STATUS_NO_MEMORY;
745 goto fail;
748 if (!tevent_req_poll(req, ev)) {
749 status = map_nt_error_from_unix(errno);
750 goto fail;
753 status = cli_trans_recv(req, mem_ctx, recv_flags2,
754 rsetup, min_rsetup, num_rsetup,
755 rparam, min_rparam, num_rparam,
756 rdata, min_rdata, num_rdata);
757 fail:
758 TALLOC_FREE(frame);
759 return status;