2 Unix SMB/CIFS implementation.
3 Inter-process communication and named pipe handling
4 Copyright (C) Andrew Tridgell 1992-1998
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
28 #include "smbd/smbd.h"
29 #include "smbd/globals.h"
30 #include "smbprofile.h"
31 #include "rpc_server/srv_pipe_hnd.h"
33 #define NERR_notsupported 50
35 static void api_no_reply(connection_struct
*conn
, struct smb_request
*req
);
37 /*******************************************************************
38 copies parameters and data, as needed, into the smb buffer
40 *both* the data and params sections should be aligned. this
41 is fudged in the rpc pipes by
42 at present, only the data section is. this may be a possible
43 cause of some of the ipc problems being experienced. lkcl26dec97
45 ******************************************************************/
47 static void copy_trans_params_and_data(char *outbuf
, int align
,
48 char *rparam
, int param_offset
, int param_len
,
49 char *rdata
, int data_offset
, int data_len
)
51 char *copy_into
= smb_buf(outbuf
);
59 DEBUG(5,("copy_trans_params_and_data: params[%d..%d] data[%d..%d] (align %d)\n",
60 param_offset
, param_offset
+ param_len
,
61 data_offset
, data_offset
+ data_len
,
69 memcpy(copy_into
, &rparam
[param_offset
], param_len
);
71 copy_into
+= param_len
;
73 memset(copy_into
, '\0', align
);
79 memcpy(copy_into
, &rdata
[data_offset
], data_len
);
82 /****************************************************************************
84 ****************************************************************************/
86 void send_trans_reply(connection_struct
*conn
,
87 struct smb_request
*req
,
88 char *rparam
, int rparam_len
,
89 char *rdata
, int rdata_len
,
90 bool buffer_too_large
)
92 int this_ldata
,this_lparam
;
93 int tot_data_sent
= 0;
94 int tot_param_sent
= 0;
97 int ldata
= rdata
? rdata_len
: 0;
98 int lparam
= rparam
? rparam_len
: 0;
99 struct smbd_server_connection
*sconn
= req
->sconn
;
100 int max_send
= sconn
->smb1
.sessions
.max_send
;
102 if (buffer_too_large
)
103 DEBUG(5,("send_trans_reply: buffer %d too large\n", ldata
));
105 this_lparam
= MIN(lparam
,max_send
- 500); /* hack */
106 this_ldata
= MIN(ldata
,max_send
- (500+this_lparam
));
108 align
= ((this_lparam
)%4);
110 reply_outbuf(req
, 10, 1+align
+this_ldata
+this_lparam
);
113 * We might have SMBtranss in req which was transferred to the outbuf,
116 SCVAL(req
->outbuf
, smb_com
, SMBtrans
);
118 copy_trans_params_and_data((char *)req
->outbuf
, align
,
119 rparam
, tot_param_sent
, this_lparam
,
120 rdata
, tot_data_sent
, this_ldata
);
122 SSVAL(req
->outbuf
,smb_vwv0
,lparam
);
123 SSVAL(req
->outbuf
,smb_vwv1
,ldata
);
124 SSVAL(req
->outbuf
,smb_vwv3
,this_lparam
);
125 SSVAL(req
->outbuf
,smb_vwv4
,
126 smb_offset(smb_buf(req
->outbuf
)+1, req
->outbuf
));
127 SSVAL(req
->outbuf
,smb_vwv5
,0);
128 SSVAL(req
->outbuf
,smb_vwv6
,this_ldata
);
129 SSVAL(req
->outbuf
,smb_vwv7
,
130 smb_offset(smb_buf(req
->outbuf
)+1+this_lparam
+align
,
132 SSVAL(req
->outbuf
,smb_vwv8
,0);
133 SSVAL(req
->outbuf
,smb_vwv9
,0);
135 if (buffer_too_large
) {
136 error_packet_set((char *)req
->outbuf
, ERRDOS
, ERRmoredata
,
137 STATUS_BUFFER_OVERFLOW
, __LINE__
, __FILE__
);
140 show_msg((char *)req
->outbuf
);
141 if (!srv_send_smb(sconn
, (char *)req
->outbuf
,
143 IS_CONN_ENCRYPTED(conn
), &req
->pcd
)) {
144 exit_server_cleanly("send_trans_reply: srv_send_smb failed.");
147 TALLOC_FREE(req
->outbuf
);
149 tot_data_sent
= this_ldata
;
150 tot_param_sent
= this_lparam
;
152 while (tot_data_sent
< ldata
|| tot_param_sent
< lparam
)
154 this_lparam
= MIN(lparam
-tot_param_sent
,
155 max_send
- 500); /* hack */
156 this_ldata
= MIN(ldata
-tot_data_sent
,
157 max_send
- (500+this_lparam
));
165 align
= (this_lparam
%4);
167 reply_outbuf(req
, 10, 1+align
+this_ldata
+this_lparam
);
170 * We might have SMBtranss in req which was transferred to the
173 SCVAL(req
->outbuf
, smb_com
, SMBtrans
);
175 copy_trans_params_and_data((char *)req
->outbuf
, align
,
176 rparam
, tot_param_sent
, this_lparam
,
177 rdata
, tot_data_sent
, this_ldata
);
179 SSVAL(req
->outbuf
,smb_vwv0
,lparam
);
180 SSVAL(req
->outbuf
,smb_vwv1
,ldata
);
182 SSVAL(req
->outbuf
,smb_vwv3
,this_lparam
);
183 SSVAL(req
->outbuf
,smb_vwv4
,
184 smb_offset(smb_buf(req
->outbuf
)+1,req
->outbuf
));
185 SSVAL(req
->outbuf
,smb_vwv5
,tot_param_sent
);
186 SSVAL(req
->outbuf
,smb_vwv6
,this_ldata
);
187 SSVAL(req
->outbuf
,smb_vwv7
,
188 smb_offset(smb_buf(req
->outbuf
)+1+this_lparam
+align
,
190 SSVAL(req
->outbuf
,smb_vwv8
,tot_data_sent
);
191 SSVAL(req
->outbuf
,smb_vwv9
,0);
193 if (buffer_too_large
) {
194 error_packet_set((char *)req
->outbuf
,
196 STATUS_BUFFER_OVERFLOW
,
200 show_msg((char *)req
->outbuf
);
201 if (!srv_send_smb(sconn
, (char *)req
->outbuf
,
203 IS_CONN_ENCRYPTED(conn
), &req
->pcd
))
204 exit_server_cleanly("send_trans_reply: srv_send_smb "
207 tot_data_sent
+= this_ldata
;
208 tot_param_sent
+= this_lparam
;
209 TALLOC_FREE(req
->outbuf
);
213 /****************************************************************************
214 Start the first part of an RPC reply which began with an SMBtrans request.
215 ****************************************************************************/
217 struct dcerpc_cmd_state
{
218 struct fake_file_handle
*handle
;
224 static void api_dcerpc_cmd_write_done(struct tevent_req
*subreq
);
225 static void api_dcerpc_cmd_read_done(struct tevent_req
*subreq
);
227 static void api_dcerpc_cmd(connection_struct
*conn
, struct smb_request
*req
,
228 files_struct
*fsp
, uint8_t *data
, size_t length
,
231 struct tevent_req
*subreq
;
232 struct dcerpc_cmd_state
*state
;
235 if (!fsp_is_np(fsp
)) {
236 api_no_reply(conn
, req
);
241 * Trans requests are only allowed
242 * if no other Trans or Read is active
244 busy
= np_read_in_progress(fsp
->fake_file_handle
);
246 reply_nterror(req
, NT_STATUS_PIPE_BUSY
);
250 state
= talloc(req
, struct dcerpc_cmd_state
);
252 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
255 req
->async_priv
= state
;
257 state
->handle
= fsp
->fake_file_handle
;
260 * This memdup severely sucks. But doing it properly essentially means
261 * to rewrite lanman.c, something which I don't really want to do now.
263 state
->data
= (uint8_t *)talloc_memdup(state
, data
, length
);
264 if (state
->data
== NULL
) {
265 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
268 state
->num_data
= length
;
269 state
->max_read
= max_read
;
271 subreq
= np_write_send(state
, smbd_event_context(), state
->handle
,
272 state
->data
, length
);
273 if (subreq
== NULL
) {
275 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
278 tevent_req_set_callback(subreq
, api_dcerpc_cmd_write_done
,
279 talloc_move(conn
, &req
));
282 static void api_dcerpc_cmd_write_done(struct tevent_req
*subreq
)
284 struct smb_request
*req
= tevent_req_callback_data(
285 subreq
, struct smb_request
);
286 struct dcerpc_cmd_state
*state
= talloc_get_type_abort(
287 req
->async_priv
, struct dcerpc_cmd_state
);
289 ssize_t nwritten
= -1;
291 status
= np_write_recv(subreq
, &nwritten
);
293 if (!NT_STATUS_IS_OK(status
) || (nwritten
!= state
->num_data
)) {
294 DEBUG(10, ("Could not write to pipe: %s (%d/%d)\n",
295 nt_errstr(status
), (int)state
->num_data
,
297 reply_nterror(req
, NT_STATUS_PIPE_NOT_AVAILABLE
);
301 state
->data
= TALLOC_REALLOC_ARRAY(state
, state
->data
, uint8_t,
303 if (state
->data
== NULL
) {
304 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
308 subreq
= np_read_send(req
->conn
, smbd_event_context(),
309 state
->handle
, state
->data
, state
->max_read
);
310 if (subreq
== NULL
) {
311 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
314 tevent_req_set_callback(subreq
, api_dcerpc_cmd_read_done
, req
);
319 req
->sconn
, (char *)req
->outbuf
,
321 IS_CONN_ENCRYPTED(req
->conn
) || req
->encrypted
,
323 exit_server_cleanly("api_dcerpc_cmd_write_done: "
324 "srv_send_smb failed.");
329 static void api_dcerpc_cmd_read_done(struct tevent_req
*subreq
)
331 struct smb_request
*req
= tevent_req_callback_data(
332 subreq
, struct smb_request
);
333 struct dcerpc_cmd_state
*state
= talloc_get_type_abort(
334 req
->async_priv
, struct dcerpc_cmd_state
);
337 bool is_data_outstanding
;
339 status
= np_read_recv(subreq
, &nread
, &is_data_outstanding
);
342 if (!NT_STATUS_IS_OK(status
)) {
343 DEBUG(10, ("Could not read from to pipe: %s\n",
345 reply_nterror(req
, status
);
347 if (!srv_send_smb(req
->sconn
, (char *)req
->outbuf
,
349 IS_CONN_ENCRYPTED(req
->conn
)
350 ||req
->encrypted
, &req
->pcd
)) {
351 exit_server_cleanly("api_dcerpc_cmd_read_done: "
352 "srv_send_smb failed.");
358 send_trans_reply(req
->conn
, req
, NULL
, 0, (char *)state
->data
, nread
,
359 is_data_outstanding
);
363 /****************************************************************************
364 WaitNamedPipeHandleState
365 ****************************************************************************/
367 static void api_WNPHS(connection_struct
*conn
, struct smb_request
*req
,
368 struct files_struct
*fsp
, char *param
, int param_len
)
370 if (!param
|| param_len
< 2) {
371 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
375 DEBUG(4,("WaitNamedPipeHandleState priority %x\n",
376 (int)SVAL(param
,0)));
378 send_trans_reply(conn
, req
, NULL
, 0, NULL
, 0, False
);
382 /****************************************************************************
383 SetNamedPipeHandleState
384 ****************************************************************************/
386 static void api_SNPHS(connection_struct
*conn
, struct smb_request
*req
,
387 struct files_struct
*fsp
, char *param
, int param_len
)
389 if (!param
|| param_len
< 2) {
390 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
394 DEBUG(4,("SetNamedPipeHandleState to code %x\n", (int)SVAL(param
,0)));
396 send_trans_reply(conn
, req
, NULL
, 0, NULL
, 0, False
);
400 /****************************************************************************
401 When no reply is generated, indicate unsupported.
402 ****************************************************************************/
404 static void api_no_reply(connection_struct
*conn
, struct smb_request
*req
)
409 SSVAL(rparam
,0,NERR_notsupported
);
410 SSVAL(rparam
,2,0); /* converter word */
412 DEBUG(3,("Unsupported API fd command\n"));
414 /* now send the reply */
415 send_trans_reply(conn
, req
, rparam
, 4, NULL
, 0, False
);
420 /****************************************************************************
421 Handle remote api calls delivered to a named pipe already opened.
422 ****************************************************************************/
424 static void api_fd_reply(connection_struct
*conn
, uint16 vuid
,
425 struct smb_request
*req
,
426 uint16
*setup
, uint8_t *data
, char *params
,
427 int suwcnt
, int tdscnt
, int tpscnt
,
428 int mdrcnt
, int mprcnt
)
430 struct files_struct
*fsp
;
434 DEBUG(5,("api_fd_reply\n"));
436 /* First find out the name of this file. */
438 DEBUG(0,("Unexpected named pipe transaction.\n"));
439 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
443 /* Get the file handle and hence the file name. */
445 * NB. The setup array has already been transformed
446 * via SVAL and so is in host byte order.
448 pnum
= ((int)setup
[1]) & 0xFFFF;
449 subcommand
= ((int)setup
[0]) & 0xFFFF;
451 fsp
= file_fsp(req
, pnum
);
453 if (!fsp_is_np(fsp
)) {
454 if (subcommand
== TRANSACT_WAITNAMEDPIPEHANDLESTATE
) {
455 /* Win9x does this call with a unicode pipe name, not a pnum. */
456 /* Just return success for now... */
457 DEBUG(3,("Got TRANSACT_WAITNAMEDPIPEHANDLESTATE on text pipe name\n"));
458 send_trans_reply(conn
, req
, NULL
, 0, NULL
, 0, False
);
462 DEBUG(1,("api_fd_reply: INVALID PIPE HANDLE: %x\n", pnum
));
463 reply_nterror(req
, NT_STATUS_INVALID_HANDLE
);
467 if (vuid
!= fsp
->vuid
) {
468 DEBUG(1, ("Got pipe request (pnum %x) using invalid VUID %d, "
469 "expected %d\n", pnum
, vuid
, fsp
->vuid
));
470 reply_nterror(req
, NT_STATUS_INVALID_HANDLE
);
474 DEBUG(3,("Got API command 0x%x on pipe \"%s\" (pnum %x)\n",
475 subcommand
, fsp_str_dbg(fsp
), pnum
));
477 DEBUG(10, ("api_fd_reply: p:%p max_trans_reply: %d\n", fsp
, mdrcnt
));
479 switch (subcommand
) {
480 case TRANSACT_DCERPCCMD
: {
481 /* dce/rpc command */
482 api_dcerpc_cmd(conn
, req
, fsp
, (uint8_t *)data
, tdscnt
,
486 case TRANSACT_WAITNAMEDPIPEHANDLESTATE
:
487 /* Wait Named Pipe Handle state */
488 api_WNPHS(conn
, req
, fsp
, params
, tpscnt
);
490 case TRANSACT_SETNAMEDPIPEHANDLESTATE
:
491 /* Set Named Pipe Handle state */
492 api_SNPHS(conn
, req
, fsp
, params
, tpscnt
);
495 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
500 /****************************************************************************
501 Handle named pipe commands.
502 ****************************************************************************/
504 static void named_pipe(connection_struct
*conn
, uint16 vuid
,
505 struct smb_request
*req
,
506 const char *name
, uint16
*setup
,
507 char *data
, char *params
,
508 int suwcnt
, int tdscnt
,int tpscnt
,
509 int msrcnt
, int mdrcnt
, int mprcnt
)
511 DEBUG(3,("named pipe command on <%s> name\n", name
));
513 if (strequal(name
,"LANMAN")) {
514 api_reply(conn
, vuid
, req
,
521 if (strequal(name
,"WKSSVC") ||
522 strequal(name
,"SRVSVC") ||
523 strequal(name
,"WINREG") ||
524 strequal(name
,"SAMR") ||
525 strequal(name
,"LSARPC")) {
527 DEBUG(4,("named pipe command from Win95 (wow!)\n"));
529 api_fd_reply(conn
, vuid
, req
,
530 setup
, (uint8_t *)data
, params
,
531 suwcnt
, tdscnt
, tpscnt
,
536 if (strlen(name
) < 1) {
537 api_fd_reply(conn
, vuid
, req
,
538 setup
, (uint8_t *)data
,
539 params
, suwcnt
, tdscnt
,
540 tpscnt
, mdrcnt
, mprcnt
);
545 DEBUG(3,("unknown named pipe: setup 0x%X setup1=%d\n",
546 (int)setup
[0],(int)setup
[1]));
548 reply_nterror(req
, NT_STATUS_NOT_SUPPORTED
);
552 static void handle_trans(connection_struct
*conn
, struct smb_request
*req
,
553 struct trans_state
*state
)
555 char *local_machine_name
;
558 DEBUG(3,("trans <%s> data=%u params=%u setup=%u\n",
559 state
->name
,(unsigned int)state
->total_data
,(unsigned int)state
->total_param
,
560 (unsigned int)state
->setup_count
));
563 * WinCE wierdness....
566 local_machine_name
= talloc_asprintf(state
, "\\%s\\",
567 get_local_machine_name());
569 if (local_machine_name
== NULL
) {
570 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
574 if (strnequal(state
->name
, local_machine_name
,
575 strlen(local_machine_name
))) {
576 name_offset
= strlen(local_machine_name
)-1;
579 if (!strnequal(&state
->name
[name_offset
], "\\PIPE",
581 reply_nterror(req
, NT_STATUS_NOT_SUPPORTED
);
585 name_offset
+= strlen("\\PIPE");
587 /* Win9x weirdness. When talking to a unicode server Win9x
588 only sends \PIPE instead of \PIPE\ */
590 if (state
->name
[name_offset
] == '\\')
593 DEBUG(5,("calling named_pipe\n"));
594 named_pipe(conn
, state
->vuid
, req
,
595 state
->name
+name_offset
,
596 state
->setup
,state
->data
,
598 state
->setup_count
,state
->total_data
,
600 state
->max_setup_return
,
601 state
->max_data_return
,
602 state
->max_param_return
);
604 if (state
->close_on_completion
) {
605 close_cnum(conn
,state
->vuid
);
612 /****************************************************************************
614 ****************************************************************************/
616 void reply_trans(struct smb_request
*req
)
618 connection_struct
*conn
= req
->conn
;
623 struct trans_state
*state
;
626 START_PROFILE(SMBtrans
);
629 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
630 END_PROFILE(SMBtrans
);
634 dsoff
= SVAL(req
->vwv
+12, 0);
635 dscnt
= SVAL(req
->vwv
+11, 0);
636 psoff
= SVAL(req
->vwv
+10, 0);
637 pscnt
= SVAL(req
->vwv
+9, 0);
639 result
= allow_new_trans(conn
->pending_trans
, req
->mid
);
640 if (!NT_STATUS_IS_OK(result
)) {
641 DEBUG(2, ("Got invalid trans request: %s\n",
643 reply_nterror(req
, result
);
644 END_PROFILE(SMBtrans
);
648 if ((state
= TALLOC_P(conn
, struct trans_state
)) == NULL
) {
649 DEBUG(0, ("talloc failed\n"));
650 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
651 END_PROFILE(SMBtrans
);
655 state
->cmd
= SMBtrans
;
657 state
->mid
= req
->mid
;
658 state
->vuid
= req
->vuid
;
659 state
->setup_count
= CVAL(req
->vwv
+13, 0);
661 state
->total_param
= SVAL(req
->vwv
+0, 0);
663 state
->total_data
= SVAL(req
->vwv
+1, 0);
665 state
->max_param_return
= SVAL(req
->vwv
+2, 0);
666 state
->max_data_return
= SVAL(req
->vwv
+3, 0);
667 state
->max_setup_return
= CVAL(req
->vwv
+4, 0);
668 state
->close_on_completion
= BITSETW(req
->vwv
+5, 0);
669 state
->one_way
= BITSETW(req
->vwv
+5, 1);
671 srvstr_pull_req_talloc(state
, req
, &state
->name
, req
->buf
,
674 if ((dscnt
> state
->total_data
) || (pscnt
> state
->total_param
) ||
678 if (state
->total_data
) {
680 if (trans_oob(state
->total_data
, 0, dscnt
)
681 || trans_oob(smb_len(req
->inbuf
), dsoff
, dscnt
)) {
685 /* Can't use talloc here, the core routines do realloc on the
686 * params and data. Out of paranoia, 100 bytes too many. */
687 state
->data
= (char *)SMB_MALLOC(state
->total_data
+100);
688 if (state
->data
== NULL
) {
689 DEBUG(0,("reply_trans: data malloc fail for %u "
690 "bytes !\n", (unsigned int)state
->total_data
));
692 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
693 END_PROFILE(SMBtrans
);
696 /* null-terminate the slack space */
697 memset(&state
->data
[state
->total_data
], 0, 100);
699 memcpy(state
->data
,smb_base(req
->inbuf
)+dsoff
,dscnt
);
702 if (state
->total_param
) {
704 if (trans_oob(state
->total_param
, 0, pscnt
)
705 || trans_oob(smb_len(req
->inbuf
), psoff
, pscnt
)) {
709 /* Can't use talloc here, the core routines do realloc on the
710 * params and data. Out of paranoia, 100 bytes too many */
711 state
->param
= (char *)SMB_MALLOC(state
->total_param
+100);
712 if (state
->param
== NULL
) {
713 DEBUG(0,("reply_trans: param malloc fail for %u "
714 "bytes !\n", (unsigned int)state
->total_param
));
715 SAFE_FREE(state
->data
);
717 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
718 END_PROFILE(SMBtrans
);
721 /* null-terminate the slack space */
722 memset(&state
->param
[state
->total_param
], 0, 100);
724 memcpy(state
->param
,smb_base(req
->inbuf
)+psoff
,pscnt
);
727 state
->received_data
= dscnt
;
728 state
->received_param
= pscnt
;
730 if (state
->setup_count
) {
734 * No overflow possible here, state->setup_count is an
735 * unsigned int, being filled by a single byte from
736 * CVAL(req->vwv+13, 0) above. The cast in the comparison
737 * below is not necessary, it's here to clarify things. The
738 * validity of req->vwv and req->wct has been checked in
739 * init_smb_request already.
741 if (state
->setup_count
+ 14 > (unsigned int)req
->wct
) {
745 if((state
->setup
= TALLOC_ARRAY(
746 state
, uint16
, state
->setup_count
)) == NULL
) {
747 DEBUG(0,("reply_trans: setup malloc fail for %u "
748 "bytes !\n", (unsigned int)
749 (state
->setup_count
* sizeof(uint16
))));
750 SAFE_FREE(state
->data
);
751 SAFE_FREE(state
->param
);
753 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
754 END_PROFILE(SMBtrans
);
758 for (i
=0;i
<state
->setup_count
;i
++) {
759 state
->setup
[i
] = SVAL(req
->vwv
+ 14 + i
, 0);
763 state
->received_param
= pscnt
;
765 if ((state
->received_param
!= state
->total_param
) ||
766 (state
->received_data
!= state
->total_data
)) {
767 DLIST_ADD(conn
->pending_trans
, state
);
769 /* We need to send an interim response then receive the rest
770 of the parameter/data bytes */
771 reply_outbuf(req
, 0, 0);
772 show_msg((char *)req
->outbuf
);
773 END_PROFILE(SMBtrans
);
777 talloc_steal(talloc_tos(), state
);
779 handle_trans(conn
, req
, state
);
781 SAFE_FREE(state
->data
);
782 SAFE_FREE(state
->param
);
785 END_PROFILE(SMBtrans
);
790 DEBUG(0,("reply_trans: invalid trans parameters\n"));
791 SAFE_FREE(state
->data
);
792 SAFE_FREE(state
->param
);
794 END_PROFILE(SMBtrans
);
795 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
799 /****************************************************************************
800 Reply to a secondary SMBtrans.
801 ****************************************************************************/
803 void reply_transs(struct smb_request
*req
)
805 connection_struct
*conn
= req
->conn
;
806 unsigned int pcnt
,poff
,dcnt
,doff
,pdisp
,ddisp
;
807 struct trans_state
*state
;
809 START_PROFILE(SMBtranss
);
811 show_msg((char *)req
->inbuf
);
814 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
815 END_PROFILE(SMBtranss
);
819 for (state
= conn
->pending_trans
; state
!= NULL
;
820 state
= state
->next
) {
821 if (state
->mid
== req
->mid
) {
826 if ((state
== NULL
) || (state
->cmd
!= SMBtrans
)) {
827 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
828 END_PROFILE(SMBtranss
);
832 /* Revise total_params and total_data in case they have changed
835 if (SVAL(req
->vwv
+0, 0) < state
->total_param
)
836 state
->total_param
= SVAL(req
->vwv
+0, 0);
837 if (SVAL(req
->vwv
+1, 0) < state
->total_data
)
838 state
->total_data
= SVAL(req
->vwv
+1, 0);
840 pcnt
= SVAL(req
->vwv
+2, 0);
841 poff
= SVAL(req
->vwv
+3, 0);
842 pdisp
= SVAL(req
->vwv
+4, 0);
844 dcnt
= SVAL(req
->vwv
+5, 0);
845 doff
= SVAL(req
->vwv
+6, 0);
846 ddisp
= SVAL(req
->vwv
+7, 0);
848 state
->received_param
+= pcnt
;
849 state
->received_data
+= dcnt
;
851 if ((state
->received_data
> state
->total_data
) ||
852 (state
->received_param
> state
->total_param
))
856 if (trans_oob(state
->total_param
, pdisp
, pcnt
)
857 || trans_oob(smb_len(req
->inbuf
), poff
, pcnt
)) {
860 memcpy(state
->param
+pdisp
,smb_base(req
->inbuf
)+poff
,pcnt
);
864 if (trans_oob(state
->total_data
, ddisp
, dcnt
)
865 || trans_oob(smb_len(req
->inbuf
), doff
, dcnt
)) {
868 memcpy(state
->data
+ddisp
, smb_base(req
->inbuf
)+doff
,dcnt
);
871 if ((state
->received_param
< state
->total_param
) ||
872 (state
->received_data
< state
->total_data
)) {
873 END_PROFILE(SMBtranss
);
877 talloc_steal(talloc_tos(), state
);
879 handle_trans(conn
, req
, state
);
881 DLIST_REMOVE(conn
->pending_trans
, state
);
882 SAFE_FREE(state
->data
);
883 SAFE_FREE(state
->param
);
886 END_PROFILE(SMBtranss
);
891 DEBUG(0,("reply_transs: invalid trans parameters\n"));
892 DLIST_REMOVE(conn
->pending_trans
, state
);
893 SAFE_FREE(state
->data
);
894 SAFE_FREE(state
->param
);
896 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
897 END_PROFILE(SMBtranss
);