r24240: Push down reply_prep_legacy one level inside api_fd_reply
[Samba.git] / source / smbd / ipc.c
blobddc42c408eba007134d439a40e32676bf0363eea
1 /*
2 Unix SMB/CIFS implementation.
3 Inter-process communication and named pipe handling
4 Copyright (C) Andrew Tridgell 1992-1998
6 SMB Version handling
7 Copyright (C) John H Terpstra 1995-1998
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 This file handles the named pipe and mailslot calls
24 in the SMBtrans protocol
27 #include "includes.h"
29 extern int max_send;
31 #define NERR_notsupported 50
33 extern int smb_read_error;
35 /*******************************************************************
36 copies parameters and data, as needed, into the smb buffer
38 *both* the data and params sections should be aligned. this
39 is fudged in the rpc pipes by
40 at present, only the data section is. this may be a possible
41 cause of some of the ipc problems being experienced. lkcl26dec97
43 ******************************************************************/
45 static void copy_trans_params_and_data(char *outbuf, int align,
46 char *rparam, int param_offset, int param_len,
47 char *rdata, int data_offset, int data_len)
49 char *copy_into = smb_buf(outbuf)+1;
51 if(param_len < 0)
52 param_len = 0;
54 if(data_len < 0)
55 data_len = 0;
57 DEBUG(5,("copy_trans_params_and_data: params[%d..%d] data[%d..%d]\n",
58 param_offset, param_offset + param_len,
59 data_offset , data_offset + data_len));
61 if (param_len)
62 memcpy(copy_into, &rparam[param_offset], param_len);
64 copy_into += param_len + align;
66 if (data_len )
67 memcpy(copy_into, &rdata[data_offset], data_len);
70 /****************************************************************************
71 Send a trans reply.
72 ****************************************************************************/
74 void send_trans_reply(const char *inbuf,
75 char *outbuf,
76 char *rparam,
77 int rparam_len,
78 char *rdata,
79 int rdata_len,
80 BOOL buffer_too_large)
82 int this_ldata,this_lparam;
83 int tot_data_sent = 0;
84 int tot_param_sent = 0;
85 int align;
87 int ldata = rdata ? rdata_len : 0;
88 int lparam = rparam ? rparam_len : 0;
90 if (buffer_too_large)
91 DEBUG(5,("send_trans_reply: buffer %d too large\n", ldata ));
93 this_lparam = MIN(lparam,max_send - 500); /* hack */
94 this_ldata = MIN(ldata,max_send - (500+this_lparam));
96 align = ((this_lparam)%4);
98 if (buffer_too_large) {
99 ERROR_BOTH(STATUS_BUFFER_OVERFLOW,ERRDOS,ERRmoredata);
102 set_message(inbuf,outbuf,10,1+align+this_ldata+this_lparam,True);
104 copy_trans_params_and_data(outbuf, align,
105 rparam, tot_param_sent, this_lparam,
106 rdata, tot_data_sent, this_ldata);
108 SSVAL(outbuf,smb_vwv0,lparam);
109 SSVAL(outbuf,smb_vwv1,ldata);
110 SSVAL(outbuf,smb_vwv3,this_lparam);
111 SSVAL(outbuf,smb_vwv4,smb_offset(smb_buf(outbuf)+1,outbuf));
112 SSVAL(outbuf,smb_vwv5,0);
113 SSVAL(outbuf,smb_vwv6,this_ldata);
114 SSVAL(outbuf,smb_vwv7,smb_offset(smb_buf(outbuf)+1+this_lparam+align,outbuf));
115 SSVAL(outbuf,smb_vwv8,0);
116 SSVAL(outbuf,smb_vwv9,0);
118 show_msg(outbuf);
119 if (!send_smb(smbd_server_fd(),outbuf))
120 exit_server_cleanly("send_trans_reply: send_smb failed.");
122 tot_data_sent = this_ldata;
123 tot_param_sent = this_lparam;
125 while (tot_data_sent < ldata || tot_param_sent < lparam)
127 this_lparam = MIN(lparam-tot_param_sent, max_send - 500); /* hack */
128 this_ldata = MIN(ldata -tot_data_sent, max_send - (500+this_lparam));
130 if(this_lparam < 0)
131 this_lparam = 0;
133 if(this_ldata < 0)
134 this_ldata = 0;
136 align = (this_lparam%4);
138 set_message(inbuf,outbuf,10,1+this_ldata+this_lparam+align,False);
140 copy_trans_params_and_data(outbuf, align,
141 rparam, tot_param_sent, this_lparam,
142 rdata, tot_data_sent, this_ldata);
144 SSVAL(outbuf,smb_vwv3,this_lparam);
145 SSVAL(outbuf,smb_vwv4,smb_offset(smb_buf(outbuf)+1,outbuf));
146 SSVAL(outbuf,smb_vwv5,tot_param_sent);
147 SSVAL(outbuf,smb_vwv6,this_ldata);
148 SSVAL(outbuf,smb_vwv7,smb_offset(smb_buf(outbuf)+1+this_lparam+align,outbuf));
149 SSVAL(outbuf,smb_vwv8,tot_data_sent);
150 SSVAL(outbuf,smb_vwv9,0);
152 show_msg(outbuf);
153 if (!send_smb(smbd_server_fd(),outbuf))
154 exit_server_cleanly("send_trans_reply: send_smb failed.");
156 tot_data_sent += this_ldata;
157 tot_param_sent += this_lparam;
161 void send_trans_reply_new(struct smb_request *req,
162 char *rparam, int rparam_len,
163 char *rdata, int rdata_len,
164 BOOL buffer_too_large)
166 char *inbuf, *outbuf;
167 int size, buflength;
169 if (!reply_prep_legacy(req, &inbuf, &outbuf, &size, &buflength)) {
170 reply_nterror(req, NT_STATUS_NO_MEMORY);
171 return;
174 send_trans_reply(inbuf, outbuf, rparam, rparam_len,
175 rdata, rdata_len, buffer_too_large);
176 reply_post_legacy(req, -1);
179 /****************************************************************************
180 Start the first part of an RPC reply which began with an SMBtrans request.
181 ****************************************************************************/
183 static BOOL api_rpc_trans_reply(const char *inbuf,
184 char *outbuf,
185 smb_np_struct *p)
187 BOOL is_data_outstanding;
188 char *rdata = (char *)SMB_MALLOC(p->max_trans_reply);
189 int data_len;
191 if(rdata == NULL) {
192 DEBUG(0,("api_rpc_trans_reply: malloc fail.\n"));
193 return False;
196 if((data_len = read_from_pipe( p, rdata, p->max_trans_reply,
197 &is_data_outstanding)) < 0) {
198 SAFE_FREE(rdata);
199 return False;
202 send_trans_reply(inbuf, outbuf, NULL, 0, rdata, data_len, is_data_outstanding);
204 SAFE_FREE(rdata);
205 return True;
208 /****************************************************************************
209 WaitNamedPipeHandleState
210 ****************************************************************************/
212 static BOOL api_WNPHS(const char *inbuf,
213 char *outbuf,
214 smb_np_struct *p,
215 char *param,
216 int param_len)
218 uint16 priority;
220 if (!param || param_len < 2)
221 return False;
223 priority = SVAL(param,0);
224 DEBUG(4,("WaitNamedPipeHandleState priority %x\n", priority));
226 if (wait_rpc_pipe_hnd_state(p, priority)) {
227 /* now send the reply */
228 send_trans_reply(inbuf, outbuf, NULL, 0, NULL, 0, False);
229 return True;
231 return False;
235 /****************************************************************************
236 SetNamedPipeHandleState
237 ****************************************************************************/
239 static BOOL api_SNPHS(const char *inbuf,
240 char *outbuf,
241 smb_np_struct *p,
242 char *param,
243 int param_len)
245 uint16 id;
247 if (!param || param_len < 2)
248 return False;
250 id = SVAL(param,0);
251 DEBUG(4,("SetNamedPipeHandleState to code %x\n", id));
253 if (set_rpc_pipe_hnd_state(p, id)) {
254 /* now send the reply */
255 send_trans_reply(inbuf, outbuf, NULL, 0, NULL, 0, False);
256 return True;
258 return False;
262 /****************************************************************************
263 When no reply is generated, indicate unsupported.
264 ****************************************************************************/
266 static void api_no_reply(struct smb_request *req)
268 char rparam[4];
270 /* unsupported */
271 SSVAL(rparam,0,NERR_notsupported);
272 SSVAL(rparam,2,0); /* converter word */
274 DEBUG(3,("Unsupported API fd command\n"));
276 /* now send the reply */
277 send_trans_reply_new(req, rparam, 4, NULL, 0, False);
279 return;
282 /****************************************************************************
283 Handle remote api calls delivered to a named pipe already opened.
284 ****************************************************************************/
286 static void api_fd_reply(connection_struct *conn, uint16 vuid,
287 struct smb_request *req,
288 uint16 *setup, char *data, char *params,
289 int suwcnt, int tdscnt, int tpscnt,
290 int mdrcnt, int mprcnt)
292 BOOL reply = False;
293 smb_np_struct *p = NULL;
294 int pnum;
295 int subcommand;
297 DEBUG(5,("api_fd_reply\n"));
299 /* First find out the name of this file. */
300 if (suwcnt != 2) {
301 DEBUG(0,("Unexpected named pipe transaction.\n"));
302 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
303 return;
306 /* Get the file handle and hence the file name. */
308 * NB. The setup array has already been transformed
309 * via SVAL and so is in gost byte order.
311 pnum = ((int)setup[1]) & 0xFFFF;
312 subcommand = ((int)setup[0]) & 0xFFFF;
314 if(!(p = get_rpc_pipe(pnum))) {
315 if (subcommand == TRANSACT_WAITNAMEDPIPEHANDLESTATE) {
316 /* Win9x does this call with a unicode pipe name, not a pnum. */
317 /* Just return success for now... */
318 DEBUG(3,("Got TRANSACT_WAITNAMEDPIPEHANDLESTATE on text pipe name\n"));
319 send_trans_reply_new(req, NULL, 0, NULL, 0, False);
320 return;
323 DEBUG(1,("api_fd_reply: INVALID PIPE HANDLE: %x\n", pnum));
324 reply_nterror(req, NT_STATUS_INVALID_HANDLE);
325 return;
328 if (vuid != p->vuid) {
329 DEBUG(1, ("Got pipe request (pnum %x) using invalid VUID %d, "
330 "expected %d\n", pnum, vuid, p->vuid));
331 reply_nterror(req, NT_STATUS_INVALID_HANDLE);
332 return;
335 DEBUG(3,("Got API command 0x%x on pipe \"%s\" (pnum %x)\n", subcommand, p->name, pnum));
337 /* record maximum data length that can be transmitted in an SMBtrans */
338 p->max_trans_reply = mdrcnt;
340 DEBUG(10,("api_fd_reply: p:%p max_trans_reply: %d\n", p, p->max_trans_reply));
342 switch (subcommand) {
343 case TRANSACT_DCERPCCMD: {
345 char *inbuf, *outbuf;
346 int size, buflength;
348 if (!reply_prep_legacy(req, &inbuf, &outbuf, &size,
349 &buflength)) {
350 reply_nterror(req, NT_STATUS_NO_MEMORY);
351 return;
354 /* dce/rpc command */
355 reply = write_to_pipe(p, data, tdscnt);
356 if (reply)
357 reply = api_rpc_trans_reply(inbuf, outbuf, p);
359 if (!reply) {
360 api_no_reply(req);
361 return;
363 reply_post_legacy(req, -1);
364 break;
366 case TRANSACT_WAITNAMEDPIPEHANDLESTATE: {
368 char *inbuf, *outbuf;
369 int size, buflength;
371 if (!reply_prep_legacy(req, &inbuf, &outbuf, &size,
372 &buflength)) {
373 reply_nterror(req, NT_STATUS_NO_MEMORY);
374 return;
377 /* Wait Named Pipe Handle state */
378 if (!api_WNPHS(inbuf, outbuf, p, params, tpscnt)) {
379 api_no_reply(req);
380 return;
383 reply_post_legacy(req, -1);
384 break;
386 case TRANSACT_SETNAMEDPIPEHANDLESTATE: {
388 char *inbuf, *outbuf;
389 int size, buflength;
391 if (!reply_prep_legacy(req, &inbuf, &outbuf, &size,
392 &buflength)) {
393 reply_nterror(req, NT_STATUS_NO_MEMORY);
394 return;
397 /* Set Named Pipe Handle state */
398 if (!api_SNPHS(inbuf, outbuf, p, params, tpscnt)) {
399 api_no_reply(req);
400 return;
403 reply_post_legacy(req, -1);
404 break;
406 default:
407 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
408 return;
412 /****************************************************************************
413 Handle named pipe commands.
414 ****************************************************************************/
416 static void named_pipe(connection_struct *conn, uint16 vuid,
417 struct smb_request *req,
418 char *name, uint16 *setup,
419 char *data, char *params,
420 int suwcnt, int tdscnt,int tpscnt,
421 int msrcnt, int mdrcnt, int mprcnt)
423 DEBUG(3,("named pipe command on <%s> name\n", name));
425 if (strequal(name,"LANMAN")) {
426 char *inbuf, *outbuf;
427 int size, bufsize;
429 if (!reply_prep_legacy(req, &inbuf, &outbuf, &size, &bufsize)) {
430 reply_nterror(req, NT_STATUS_NO_MEMORY);
431 return;
434 reply_post_legacy(
435 req,
436 api_reply(conn, vuid, inbuf, outbuf,
437 data, params,
438 tdscnt, tpscnt,
439 mdrcnt, mprcnt));
440 return;
443 if (strequal(name,"WKSSVC") ||
444 strequal(name,"SRVSVC") ||
445 strequal(name,"WINREG") ||
446 strequal(name,"SAMR") ||
447 strequal(name,"LSARPC")) {
449 DEBUG(4,("named pipe command from Win95 (wow!)\n"));
451 api_fd_reply(conn, vuid, req,
452 setup, data, params,
453 suwcnt, tdscnt, tpscnt,
454 mdrcnt, mprcnt);
455 return;
458 if (strlen(name) < 1) {
459 api_fd_reply(conn, vuid, req,
460 setup, data,
461 params, suwcnt, tdscnt,
462 tpscnt, mdrcnt, mprcnt);
463 return;
466 if (setup)
467 DEBUG(3,("unknown named pipe: setup 0x%X setup1=%d\n",
468 (int)setup[0],(int)setup[1]));
470 reply_nterror(req, NT_STATUS_NOT_SUPPORTED);
471 return;
474 static void handle_trans(connection_struct *conn, struct smb_request *req,
475 struct trans_state *state)
477 char *local_machine_name;
478 int name_offset = 0;
480 DEBUG(3,("trans <%s> data=%u params=%u setup=%u\n",
481 state->name,(unsigned int)state->total_data,(unsigned int)state->total_param,
482 (unsigned int)state->setup_count));
485 * WinCE wierdness....
488 local_machine_name = talloc_asprintf(state, "\\%s\\",
489 get_local_machine_name());
491 if (local_machine_name == NULL) {
492 reply_nterror(req, NT_STATUS_NO_MEMORY);
493 return;
496 if (strnequal(state->name, local_machine_name,
497 strlen(local_machine_name))) {
498 name_offset = strlen(local_machine_name)-1;
501 if (!strnequal(&state->name[name_offset], "\\PIPE",
502 strlen("\\PIPE"))) {
503 reply_nterror(req, NT_STATUS_NOT_SUPPORTED);
504 return;
507 name_offset += strlen("\\PIPE");
509 /* Win9x weirdness. When talking to a unicode server Win9x
510 only sends \PIPE instead of \PIPE\ */
512 if (state->name[name_offset] == '\\')
513 name_offset++;
515 DEBUG(5,("calling named_pipe\n"));
516 named_pipe(conn, state->vuid, req,
517 state->name+name_offset,
518 state->setup,state->data,
519 state->param,
520 state->setup_count,state->total_data,
521 state->total_param,
522 state->max_setup_return,
523 state->max_data_return,
524 state->max_param_return);
526 if (state->close_on_completion)
527 close_cnum(conn,state->vuid);
529 return;
532 /****************************************************************************
533 Reply to a SMBtrans.
534 ****************************************************************************/
536 void reply_trans(connection_struct *conn, struct smb_request *req)
538 unsigned int dsoff;
539 unsigned int dscnt;
540 unsigned int psoff;
541 unsigned int pscnt;
542 struct trans_state *state;
543 NTSTATUS result;
544 int size;
546 START_PROFILE(SMBtrans);
548 if (SVAL(req->inbuf, smb_wct) < 10) {
549 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
550 END_PROFILE(SMBtrans);
551 return;
554 size = smb_len(req->inbuf) + 4;
555 dsoff = SVAL(req->inbuf, smb_dsoff);
556 dscnt = SVAL(req->inbuf, smb_dscnt);
557 psoff = SVAL(req->inbuf, smb_psoff);
558 pscnt = SVAL(req->inbuf, smb_pscnt);
560 result = allow_new_trans(conn->pending_trans, req->mid);
561 if (!NT_STATUS_IS_OK(result)) {
562 DEBUG(2, ("Got invalid trans request: %s\n",
563 nt_errstr(result)));
564 reply_nterror(req, result);
565 END_PROFILE(SMBtrans);
566 return;
569 if ((state = TALLOC_P(conn->mem_ctx, struct trans_state)) == NULL) {
570 DEBUG(0, ("talloc failed\n"));
571 reply_nterror(req, NT_STATUS_NO_MEMORY);
572 END_PROFILE(SMBtrans);
573 return;
576 state->cmd = SMBtrans;
578 state->mid = req->mid;
579 state->vuid = req->vuid;
580 state->setup_count = CVAL(req->inbuf, smb_suwcnt);
581 state->setup = NULL;
582 state->total_param = SVAL(req->inbuf, smb_tpscnt);
583 state->param = NULL;
584 state->total_data = SVAL(req->inbuf, smb_tdscnt);
585 state->data = NULL;
586 state->max_param_return = SVAL(req->inbuf, smb_mprcnt);
587 state->max_data_return = SVAL(req->inbuf, smb_mdrcnt);
588 state->max_setup_return = CVAL(req->inbuf, smb_msrcnt);
589 state->close_on_completion = BITSETW(req->inbuf+smb_vwv5,0);
590 state->one_way = BITSETW(req->inbuf+smb_vwv5,1);
592 memset(state->name, '\0',sizeof(state->name));
593 srvstr_pull_buf(req->inbuf, req->flags2, state->name,
594 smb_buf(req->inbuf), sizeof(state->name),
595 STR_TERMINATE);
597 if ((dscnt > state->total_data) || (pscnt > state->total_param))
598 goto bad_param;
600 if (state->total_data) {
601 /* Can't use talloc here, the core routines do realloc on the
602 * params and data. Out of paranoia, 100 bytes too many. */
603 state->data = (char *)SMB_MALLOC(state->total_data+100);
604 if (state->data == NULL) {
605 DEBUG(0,("reply_trans: data malloc fail for %u "
606 "bytes !\n", (unsigned int)state->total_data));
607 TALLOC_FREE(state);
608 reply_nterror(req, NT_STATUS_NO_MEMORY);
609 END_PROFILE(SMBtrans);
610 return;
612 /* null-terminate the slack space */
613 memset(&state->data[state->total_data], 0, 100);
614 if ((dsoff+dscnt < dsoff) || (dsoff+dscnt < dscnt))
615 goto bad_param;
616 if ((smb_base(req->inbuf)+dsoff+dscnt
617 > (char *)req->inbuf + size) ||
618 (smb_base(req->inbuf)+dsoff+dscnt < smb_base(req->inbuf)))
619 goto bad_param;
621 memcpy(state->data,smb_base(req->inbuf)+dsoff,dscnt);
624 if (state->total_param) {
625 /* Can't use talloc here, the core routines do realloc on the
626 * params and data. Out of paranoia, 100 bytes too many */
627 state->param = (char *)SMB_MALLOC(state->total_param+100);
628 if (state->param == NULL) {
629 DEBUG(0,("reply_trans: param malloc fail for %u "
630 "bytes !\n", (unsigned int)state->total_param));
631 SAFE_FREE(state->data);
632 TALLOC_FREE(state);
633 reply_nterror(req, NT_STATUS_NO_MEMORY);
634 END_PROFILE(SMBtrans);
635 return;
637 /* null-terminate the slack space */
638 memset(&state->param[state->total_param], 0, 100);
639 if ((psoff+pscnt < psoff) || (psoff+pscnt < pscnt))
640 goto bad_param;
641 if ((smb_base(req->inbuf)+psoff+pscnt
642 > (char *)req->inbuf + size) ||
643 (smb_base(req->inbuf)+psoff+pscnt < smb_base(req->inbuf)))
644 goto bad_param;
646 memcpy(state->param,smb_base(req->inbuf)+psoff,pscnt);
649 state->received_data = dscnt;
650 state->received_param = pscnt;
652 if (state->setup_count) {
653 unsigned int i;
654 if((state->setup = TALLOC_ARRAY(
655 state, uint16, state->setup_count)) == NULL) {
656 DEBUG(0,("reply_trans: setup malloc fail for %u "
657 "bytes !\n", (unsigned int)
658 (state->setup_count * sizeof(uint16))));
659 SAFE_FREE(state->data);
660 SAFE_FREE(state->param);
661 TALLOC_FREE(state);
662 reply_nterror(req, NT_STATUS_NO_MEMORY);
663 END_PROFILE(SMBtrans);
664 return;
666 if (req->inbuf+smb_vwv14+(state->setup_count*SIZEOFWORD) >
667 req->inbuf + size)
668 goto bad_param;
669 if ((smb_vwv14+(state->setup_count*SIZEOFWORD) < smb_vwv14) ||
670 (smb_vwv14+(state->setup_count*SIZEOFWORD) <
671 (state->setup_count*SIZEOFWORD)))
672 goto bad_param;
674 for (i=0;i<state->setup_count;i++)
675 state->setup[i] = SVAL(req->inbuf,
676 smb_vwv14+i*SIZEOFWORD);
679 state->received_param = pscnt;
681 if ((state->received_param != state->total_param) ||
682 (state->received_data != state->total_data)) {
683 DLIST_ADD(conn->pending_trans, state);
685 /* We need to send an interim response then receive the rest
686 of the parameter/data bytes */
687 reply_outbuf(req, 0, 0);
688 show_msg((char *)req->outbuf);
689 END_PROFILE(SMBtrans);
690 return;
693 handle_trans(conn, req, state);
695 SAFE_FREE(state->data);
696 SAFE_FREE(state->param);
697 TALLOC_FREE(state);
699 END_PROFILE(SMBtrans);
700 return;
702 bad_param:
704 DEBUG(0,("reply_trans: invalid trans parameters\n"));
705 SAFE_FREE(state->data);
706 SAFE_FREE(state->param);
707 TALLOC_FREE(state);
708 END_PROFILE(SMBtrans);
709 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
710 return;
713 /****************************************************************************
714 Reply to a secondary SMBtrans.
715 ****************************************************************************/
717 void reply_transs(connection_struct *conn, struct smb_request *req)
719 unsigned int pcnt,poff,dcnt,doff,pdisp,ddisp;
720 struct trans_state *state;
721 int size;
723 START_PROFILE(SMBtranss);
725 show_msg((char *)req->inbuf);
727 if (req->wct < 10) {
728 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
729 END_PROFILE(SMBtranss);
730 return;
733 for (state = conn->pending_trans; state != NULL;
734 state = state->next) {
735 if (state->mid == req->mid) {
736 break;
740 if ((state == NULL) || (state->cmd != SMBtrans)) {
741 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
742 END_PROFILE(SMBtranss);
743 return;
746 /* Revise total_params and total_data in case they have changed
747 * downwards */
749 if (SVAL(req->inbuf, smb_vwv0) < state->total_param)
750 state->total_param = SVAL(req->inbuf,smb_vwv0);
751 if (SVAL(req->inbuf, smb_vwv1) < state->total_data)
752 state->total_data = SVAL(req->inbuf,smb_vwv1);
754 size = smb_len(req->inbuf) + 4;
756 pcnt = SVAL(req->inbuf, smb_spscnt);
757 poff = SVAL(req->inbuf, smb_spsoff);
758 pdisp = SVAL(req->inbuf, smb_spsdisp);
760 dcnt = SVAL(req->inbuf, smb_sdscnt);
761 doff = SVAL(req->inbuf, smb_sdsoff);
762 ddisp = SVAL(req->inbuf, smb_sdsdisp);
764 state->received_param += pcnt;
765 state->received_data += dcnt;
767 if ((state->received_data > state->total_data) ||
768 (state->received_param > state->total_param))
769 goto bad_param;
771 if (pcnt) {
772 if (pdisp+pcnt > state->total_param)
773 goto bad_param;
774 if ((pdisp+pcnt < pdisp) || (pdisp+pcnt < pcnt))
775 goto bad_param;
776 if (pdisp > state->total_param)
777 goto bad_param;
778 if ((smb_base(req->inbuf) + poff + pcnt
779 > (char *)req->inbuf + size) ||
780 (smb_base(req->inbuf) + poff + pcnt
781 < smb_base(req->inbuf)))
782 goto bad_param;
783 if (state->param + pdisp < state->param)
784 goto bad_param;
786 memcpy(state->param+pdisp,smb_base(req->inbuf)+poff,
787 pcnt);
790 if (dcnt) {
791 if (ddisp+dcnt > state->total_data)
792 goto bad_param;
793 if ((ddisp+dcnt < ddisp) || (ddisp+dcnt < dcnt))
794 goto bad_param;
795 if (ddisp > state->total_data)
796 goto bad_param;
797 if ((smb_base(req->inbuf) + doff + dcnt
798 > (char *)req->inbuf + size) ||
799 (smb_base(req->inbuf) + doff + dcnt
800 < smb_base(req->inbuf)))
801 goto bad_param;
802 if (state->data + ddisp < state->data)
803 goto bad_param;
805 memcpy(state->data+ddisp, smb_base(req->inbuf)+doff,
806 dcnt);
809 if ((state->received_param < state->total_param) ||
810 (state->received_data < state->total_data)) {
811 END_PROFILE(SMBtranss);
812 return;
815 /* construct_reply_common has done us the favor to pre-fill the
816 * command field with SMBtranss which is wrong :-)
818 SCVAL(req->outbuf,smb_com,SMBtrans);
820 handle_trans(conn, req, state);
822 DLIST_REMOVE(conn->pending_trans, state);
823 SAFE_FREE(state->data);
824 SAFE_FREE(state->param);
825 TALLOC_FREE(state);
827 END_PROFILE(SMBtranss);
828 return;
830 bad_param:
832 DEBUG(0,("reply_transs: invalid trans parameters\n"));
833 DLIST_REMOVE(conn->pending_trans, state);
834 SAFE_FREE(state->data);
835 SAFE_FREE(state->param);
836 TALLOC_FREE(state);
837 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
838 END_PROFILE(SMBtranss);
839 return;