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 NTSTATUS
nt_status_np_pipe(NTSTATUS status
)
84 if (NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_DISCONNECTED
)) {
85 status
= NT_STATUS_PIPE_DISCONNECTED
;
86 } else if (NT_STATUS_EQUAL(status
, NT_STATUS_CONNECTION_RESET
)) {
87 status
= NT_STATUS_PIPE_BROKEN
;
93 /****************************************************************************
95 ****************************************************************************/
97 void send_trans_reply(connection_struct
*conn
,
98 struct smb_request
*req
,
99 char *rparam
, int rparam_len
,
100 char *rdata
, int rdata_len
,
101 bool buffer_too_large
)
103 int this_ldata
,this_lparam
;
104 int tot_data_sent
= 0;
105 int tot_param_sent
= 0;
108 int ldata
= rdata
? rdata_len
: 0;
109 int lparam
= rparam
? rparam_len
: 0;
110 struct smbd_server_connection
*sconn
= req
->sconn
;
111 int max_send
= sconn
->smb1
.sessions
.max_send
;
113 if (buffer_too_large
)
114 DEBUG(5,("send_trans_reply: buffer %d too large\n", ldata
));
116 this_lparam
= MIN(lparam
,max_send
- 500); /* hack */
117 this_ldata
= MIN(ldata
,max_send
- (500+this_lparam
));
119 align
= ((this_lparam
)%4);
121 reply_outbuf(req
, 10, 1+align
+this_ldata
+this_lparam
);
124 * We might have SMBtranss in req which was transferred to the outbuf,
127 SCVAL(req
->outbuf
, smb_com
, SMBtrans
);
129 copy_trans_params_and_data((char *)req
->outbuf
, align
,
130 rparam
, tot_param_sent
, this_lparam
,
131 rdata
, tot_data_sent
, this_ldata
);
133 SSVAL(req
->outbuf
,smb_vwv0
,lparam
);
134 SSVAL(req
->outbuf
,smb_vwv1
,ldata
);
135 SSVAL(req
->outbuf
,smb_vwv3
,this_lparam
);
136 SSVAL(req
->outbuf
,smb_vwv4
,
137 smb_offset(smb_buf(req
->outbuf
)+1, req
->outbuf
));
138 SSVAL(req
->outbuf
,smb_vwv5
,0);
139 SSVAL(req
->outbuf
,smb_vwv6
,this_ldata
);
140 SSVAL(req
->outbuf
,smb_vwv7
,
141 smb_offset(smb_buf(req
->outbuf
)+1+this_lparam
+align
,
143 SSVAL(req
->outbuf
,smb_vwv8
,0);
144 SSVAL(req
->outbuf
,smb_vwv9
,0);
146 if (buffer_too_large
) {
147 error_packet_set((char *)req
->outbuf
, ERRDOS
, ERRmoredata
,
148 STATUS_BUFFER_OVERFLOW
, __LINE__
, __FILE__
);
151 show_msg((char *)req
->outbuf
);
152 if (!srv_send_smb(sconn
, (char *)req
->outbuf
,
154 IS_CONN_ENCRYPTED(conn
), &req
->pcd
)) {
155 exit_server_cleanly("send_trans_reply: srv_send_smb failed.");
158 TALLOC_FREE(req
->outbuf
);
160 tot_data_sent
= this_ldata
;
161 tot_param_sent
= this_lparam
;
163 while (tot_data_sent
< ldata
|| tot_param_sent
< lparam
)
165 this_lparam
= MIN(lparam
-tot_param_sent
,
166 max_send
- 500); /* hack */
167 this_ldata
= MIN(ldata
-tot_data_sent
,
168 max_send
- (500+this_lparam
));
176 align
= (this_lparam
%4);
178 reply_outbuf(req
, 10, 1+align
+this_ldata
+this_lparam
);
181 * We might have SMBtranss in req which was transferred to the
184 SCVAL(req
->outbuf
, smb_com
, SMBtrans
);
186 copy_trans_params_and_data((char *)req
->outbuf
, align
,
187 rparam
, tot_param_sent
, this_lparam
,
188 rdata
, tot_data_sent
, this_ldata
);
190 SSVAL(req
->outbuf
,smb_vwv0
,lparam
);
191 SSVAL(req
->outbuf
,smb_vwv1
,ldata
);
193 SSVAL(req
->outbuf
,smb_vwv3
,this_lparam
);
194 SSVAL(req
->outbuf
,smb_vwv4
,
195 smb_offset(smb_buf(req
->outbuf
)+1,req
->outbuf
));
196 SSVAL(req
->outbuf
,smb_vwv5
,tot_param_sent
);
197 SSVAL(req
->outbuf
,smb_vwv6
,this_ldata
);
198 SSVAL(req
->outbuf
,smb_vwv7
,
199 smb_offset(smb_buf(req
->outbuf
)+1+this_lparam
+align
,
201 SSVAL(req
->outbuf
,smb_vwv8
,tot_data_sent
);
202 SSVAL(req
->outbuf
,smb_vwv9
,0);
204 if (buffer_too_large
) {
205 error_packet_set((char *)req
->outbuf
,
207 STATUS_BUFFER_OVERFLOW
,
211 show_msg((char *)req
->outbuf
);
212 if (!srv_send_smb(sconn
, (char *)req
->outbuf
,
214 IS_CONN_ENCRYPTED(conn
), &req
->pcd
))
215 exit_server_cleanly("send_trans_reply: srv_send_smb "
218 tot_data_sent
+= this_ldata
;
219 tot_param_sent
+= this_lparam
;
220 TALLOC_FREE(req
->outbuf
);
224 /****************************************************************************
225 Start the first part of an RPC reply which began with an SMBtrans request.
226 ****************************************************************************/
228 struct dcerpc_cmd_state
{
229 struct fake_file_handle
*handle
;
235 static void api_dcerpc_cmd_write_done(struct tevent_req
*subreq
);
236 static void api_dcerpc_cmd_read_done(struct tevent_req
*subreq
);
238 static void api_dcerpc_cmd(connection_struct
*conn
, struct smb_request
*req
,
239 files_struct
*fsp
, uint8_t *data
, size_t length
,
242 struct tevent_req
*subreq
;
243 struct dcerpc_cmd_state
*state
;
246 if (!fsp_is_np(fsp
)) {
247 api_no_reply(conn
, req
);
252 * Trans requests are only allowed
253 * if no other Trans or Read is active
255 busy
= np_read_in_progress(fsp
->fake_file_handle
);
257 reply_nterror(req
, NT_STATUS_PIPE_BUSY
);
261 state
= talloc(req
, struct dcerpc_cmd_state
);
263 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
266 req
->async_priv
= state
;
268 state
->handle
= fsp
->fake_file_handle
;
271 * This memdup severely sucks. But doing it properly essentially means
272 * to rewrite lanman.c, something which I don't really want to do now.
274 state
->data
= (uint8_t *)talloc_memdup(state
, data
, length
);
275 if (state
->data
== NULL
) {
276 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
279 state
->num_data
= length
;
280 state
->max_read
= max_read
;
282 subreq
= np_write_send(state
, req
->sconn
->ev_ctx
, state
->handle
,
283 state
->data
, length
);
284 if (subreq
== NULL
) {
286 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
289 tevent_req_set_callback(subreq
, api_dcerpc_cmd_write_done
,
290 talloc_move(conn
, &req
));
293 static void api_dcerpc_cmd_write_done(struct tevent_req
*subreq
)
295 struct smb_request
*req
= tevent_req_callback_data(
296 subreq
, struct smb_request
);
297 struct dcerpc_cmd_state
*state
= talloc_get_type_abort(
298 req
->async_priv
, struct dcerpc_cmd_state
);
300 ssize_t nwritten
= -1;
302 status
= np_write_recv(subreq
, &nwritten
);
304 if (!NT_STATUS_IS_OK(status
)) {
305 NTSTATUS old
= status
;
306 status
= nt_status_np_pipe(old
);
308 DEBUG(10, ("Could not write to pipe: %s%s%s\n",
310 NT_STATUS_EQUAL(old
, status
)?"":" => ",
311 NT_STATUS_EQUAL(old
, status
)?"":nt_errstr(status
)));
312 reply_nterror(req
, status
);
315 if (nwritten
!= state
->num_data
) {
316 status
= NT_STATUS_PIPE_NOT_AVAILABLE
;
317 DEBUG(10, ("Could not write to pipe: (%d/%d) => %s\n",
318 (int)state
->num_data
,
319 (int)nwritten
, nt_errstr(status
)));
320 reply_nterror(req
, status
);
324 state
->data
= talloc_realloc(state
, state
->data
, uint8_t,
326 if (state
->data
== NULL
) {
327 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
331 subreq
= np_read_send(state
, req
->sconn
->ev_ctx
,
332 state
->handle
, state
->data
, state
->max_read
);
333 if (subreq
== NULL
) {
334 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
337 tevent_req_set_callback(subreq
, api_dcerpc_cmd_read_done
, req
);
342 req
->sconn
, (char *)req
->outbuf
,
344 IS_CONN_ENCRYPTED(req
->conn
) || req
->encrypted
,
346 exit_server_cleanly("api_dcerpc_cmd_write_done: "
347 "srv_send_smb failed.");
352 static void api_dcerpc_cmd_read_done(struct tevent_req
*subreq
)
354 struct smb_request
*req
= tevent_req_callback_data(
355 subreq
, struct smb_request
);
356 struct dcerpc_cmd_state
*state
= talloc_get_type_abort(
357 req
->async_priv
, struct dcerpc_cmd_state
);
360 bool is_data_outstanding
;
362 status
= np_read_recv(subreq
, &nread
, &is_data_outstanding
);
365 if (!NT_STATUS_IS_OK(status
)) {
366 NTSTATUS old
= status
;
367 status
= nt_status_np_pipe(old
);
369 DEBUG(10, ("Could not read from to pipe: %s%s%s\n",
371 NT_STATUS_EQUAL(old
, status
)?"":" => ",
372 NT_STATUS_EQUAL(old
, status
)?"":nt_errstr(status
)));
373 reply_nterror(req
, status
);
375 if (!srv_send_smb(req
->sconn
, (char *)req
->outbuf
,
377 IS_CONN_ENCRYPTED(req
->conn
)
378 ||req
->encrypted
, &req
->pcd
)) {
379 exit_server_cleanly("api_dcerpc_cmd_read_done: "
380 "srv_send_smb failed.");
386 send_trans_reply(req
->conn
, req
, NULL
, 0, (char *)state
->data
, nread
,
387 is_data_outstanding
);
391 /****************************************************************************
392 WaitNamedPipeHandleState
393 ****************************************************************************/
395 static void api_WNPHS(connection_struct
*conn
, struct smb_request
*req
,
396 struct files_struct
*fsp
, char *param
, int param_len
)
398 if (!param
|| param_len
< 2) {
399 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
403 DEBUG(4,("WaitNamedPipeHandleState priority %x\n",
404 (int)SVAL(param
,0)));
406 send_trans_reply(conn
, req
, NULL
, 0, NULL
, 0, False
);
410 /****************************************************************************
411 SetNamedPipeHandleState
412 ****************************************************************************/
414 static void api_SNPHS(connection_struct
*conn
, struct smb_request
*req
,
415 struct files_struct
*fsp
, char *param
, int param_len
)
417 if (!param
|| param_len
< 2) {
418 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
422 DEBUG(4,("SetNamedPipeHandleState to code %x\n", (int)SVAL(param
,0)));
424 send_trans_reply(conn
, req
, NULL
, 0, NULL
, 0, False
);
428 /****************************************************************************
429 When no reply is generated, indicate unsupported.
430 ****************************************************************************/
432 static void api_no_reply(connection_struct
*conn
, struct smb_request
*req
)
437 SSVAL(rparam
,0,NERR_notsupported
);
438 SSVAL(rparam
,2,0); /* converter word */
440 DEBUG(3,("Unsupported API fd command\n"));
442 /* now send the reply */
443 send_trans_reply(conn
, req
, rparam
, 4, NULL
, 0, False
);
448 /****************************************************************************
449 Handle remote api calls delivered to a named pipe already opened.
450 ****************************************************************************/
452 static void api_fd_reply(connection_struct
*conn
, uint64_t vuid
,
453 struct smb_request
*req
,
454 uint16
*setup
, uint8_t *data
, char *params
,
455 int suwcnt
, int tdscnt
, int tpscnt
,
456 int mdrcnt
, int mprcnt
)
458 struct files_struct
*fsp
;
462 DEBUG(5,("api_fd_reply\n"));
464 /* First find out the name of this file. */
466 DEBUG(0,("Unexpected named pipe transaction.\n"));
467 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
471 /* Get the file handle and hence the file name. */
473 * NB. The setup array has already been transformed
474 * via SVAL and so is in host byte order.
476 pnum
= ((int)setup
[1]) & 0xFFFF;
477 subcommand
= ((int)setup
[0]) & 0xFFFF;
479 fsp
= file_fsp(req
, pnum
);
481 if (!fsp_is_np(fsp
)) {
482 if (subcommand
== TRANSACT_WAITNAMEDPIPEHANDLESTATE
) {
483 /* Win9x does this call with a unicode pipe name, not a pnum. */
484 /* Just return success for now... */
485 DEBUG(3,("Got TRANSACT_WAITNAMEDPIPEHANDLESTATE on text pipe name\n"));
486 send_trans_reply(conn
, req
, NULL
, 0, NULL
, 0, False
);
490 DEBUG(1,("api_fd_reply: INVALID PIPE HANDLE: %x\n", pnum
));
491 reply_nterror(req
, NT_STATUS_INVALID_HANDLE
);
495 if (vuid
!= fsp
->vuid
) {
496 DEBUG(1, ("Got pipe request (pnum %x) using invalid VUID %llu, "
497 "expected %llu\n", pnum
, (unsigned long long)vuid
,
498 (unsigned long long)fsp
->vuid
));
499 reply_nterror(req
, NT_STATUS_INVALID_HANDLE
);
503 DEBUG(3,("Got API command 0x%x on pipe \"%s\" (pnum %x)\n",
504 subcommand
, fsp_str_dbg(fsp
), pnum
));
506 DEBUG(10, ("api_fd_reply: p:%p max_trans_reply: %d\n", fsp
, mdrcnt
));
508 switch (subcommand
) {
509 case TRANSACT_DCERPCCMD
: {
510 /* dce/rpc command */
511 api_dcerpc_cmd(conn
, req
, fsp
, (uint8_t *)data
, tdscnt
,
515 case TRANSACT_WAITNAMEDPIPEHANDLESTATE
:
516 /* Wait Named Pipe Handle state */
517 api_WNPHS(conn
, req
, fsp
, params
, tpscnt
);
519 case TRANSACT_SETNAMEDPIPEHANDLESTATE
:
520 /* Set Named Pipe Handle state */
521 api_SNPHS(conn
, req
, fsp
, params
, tpscnt
);
524 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
529 /****************************************************************************
530 Handle named pipe commands.
531 ****************************************************************************/
533 static void named_pipe(connection_struct
*conn
, uint64_t vuid
,
534 struct smb_request
*req
,
535 const char *name
, uint16
*setup
,
536 char *data
, char *params
,
537 int suwcnt
, int tdscnt
,int tpscnt
,
538 int msrcnt
, int mdrcnt
, int mprcnt
)
540 DEBUG(3,("named pipe command on <%s> name\n", name
));
542 if (strequal(name
,"LANMAN")) {
543 api_reply(conn
, vuid
, req
,
550 if (strequal(name
,"WKSSVC") ||
551 strequal(name
,"SRVSVC") ||
552 strequal(name
,"WINREG") ||
553 strequal(name
,"SAMR") ||
554 strequal(name
,"LSARPC")) {
556 DEBUG(4,("named pipe command from Win95 (wow!)\n"));
558 api_fd_reply(conn
, vuid
, req
,
559 setup
, (uint8_t *)data
, params
,
560 suwcnt
, tdscnt
, tpscnt
,
565 if (strlen(name
) < 1) {
566 api_fd_reply(conn
, vuid
, req
,
567 setup
, (uint8_t *)data
,
568 params
, suwcnt
, tdscnt
,
569 tpscnt
, mdrcnt
, mprcnt
);
574 DEBUG(3,("unknown named pipe: setup 0x%X setup1=%d\n",
575 (int)setup
[0],(int)setup
[1]));
577 reply_nterror(req
, NT_STATUS_NOT_SUPPORTED
);
581 static void handle_trans(connection_struct
*conn
, struct smb_request
*req
,
582 struct trans_state
*state
)
584 char *local_machine_name
;
587 DEBUG(3,("trans <%s> data=%u params=%u setup=%u\n",
588 state
->name
,(unsigned int)state
->total_data
,(unsigned int)state
->total_param
,
589 (unsigned int)state
->setup_count
));
592 * WinCE wierdness....
595 local_machine_name
= talloc_asprintf(state
, "\\%s\\",
596 get_local_machine_name());
598 if (local_machine_name
== NULL
) {
599 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
603 if (strnequal(state
->name
, local_machine_name
,
604 strlen(local_machine_name
))) {
605 name_offset
= strlen(local_machine_name
)-1;
608 if (!strnequal(&state
->name
[name_offset
], "\\PIPE",
610 reply_nterror(req
, NT_STATUS_NOT_SUPPORTED
);
614 name_offset
+= strlen("\\PIPE");
616 /* Win9x weirdness. When talking to a unicode server Win9x
617 only sends \PIPE instead of \PIPE\ */
619 if (state
->name
[name_offset
] == '\\')
622 DEBUG(5,("calling named_pipe\n"));
623 named_pipe(conn
, state
->vuid
, req
,
624 state
->name
+name_offset
,
625 state
->setup
,state
->data
,
627 state
->setup_count
,state
->total_data
,
629 state
->max_setup_return
,
630 state
->max_data_return
,
631 state
->max_param_return
);
633 if (state
->close_on_completion
) {
634 close_cnum(conn
,state
->vuid
);
641 /****************************************************************************
643 ****************************************************************************/
645 void reply_trans(struct smb_request
*req
)
647 connection_struct
*conn
= req
->conn
;
652 struct trans_state
*state
;
655 START_PROFILE(SMBtrans
);
658 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
659 END_PROFILE(SMBtrans
);
663 dsoff
= SVAL(req
->vwv
+12, 0);
664 dscnt
= SVAL(req
->vwv
+11, 0);
665 psoff
= SVAL(req
->vwv
+10, 0);
666 pscnt
= SVAL(req
->vwv
+9, 0);
668 result
= allow_new_trans(conn
->pending_trans
, req
->mid
);
669 if (!NT_STATUS_IS_OK(result
)) {
670 DEBUG(2, ("Got invalid trans request: %s\n",
672 reply_nterror(req
, result
);
673 END_PROFILE(SMBtrans
);
677 if ((state
= talloc(conn
, struct trans_state
)) == NULL
) {
678 DEBUG(0, ("talloc failed\n"));
679 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
680 END_PROFILE(SMBtrans
);
684 state
->cmd
= SMBtrans
;
686 state
->mid
= req
->mid
;
687 state
->vuid
= req
->vuid
;
688 state
->setup_count
= CVAL(req
->vwv
+13, 0);
690 state
->total_param
= SVAL(req
->vwv
+0, 0);
692 state
->total_data
= SVAL(req
->vwv
+1, 0);
694 state
->max_param_return
= SVAL(req
->vwv
+2, 0);
695 state
->max_data_return
= SVAL(req
->vwv
+3, 0);
696 state
->max_setup_return
= CVAL(req
->vwv
+4, 0);
697 state
->close_on_completion
= BITSETW(req
->vwv
+5, 0);
698 state
->one_way
= BITSETW(req
->vwv
+5, 1);
700 srvstr_pull_req_talloc(state
, req
, &state
->name
, req
->buf
,
703 if ((dscnt
> state
->total_data
) || (pscnt
> state
->total_param
) ||
707 if (state
->total_data
) {
709 if (trans_oob(state
->total_data
, 0, dscnt
)
710 || trans_oob(smb_len(req
->inbuf
), dsoff
, dscnt
)) {
714 /* Can't use talloc here, the core routines do realloc on the
715 * params and data. Out of paranoia, 100 bytes too many. */
716 state
->data
= (char *)SMB_MALLOC(state
->total_data
+100);
717 if (state
->data
== NULL
) {
718 DEBUG(0,("reply_trans: data malloc fail for %u "
719 "bytes !\n", (unsigned int)state
->total_data
));
721 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
722 END_PROFILE(SMBtrans
);
725 /* null-terminate the slack space */
726 memset(&state
->data
[state
->total_data
], 0, 100);
728 memcpy(state
->data
,smb_base(req
->inbuf
)+dsoff
,dscnt
);
731 if (state
->total_param
) {
733 if (trans_oob(state
->total_param
, 0, pscnt
)
734 || trans_oob(smb_len(req
->inbuf
), psoff
, pscnt
)) {
738 /* Can't use talloc here, the core routines do realloc on the
739 * params and data. Out of paranoia, 100 bytes too many */
740 state
->param
= (char *)SMB_MALLOC(state
->total_param
+100);
741 if (state
->param
== NULL
) {
742 DEBUG(0,("reply_trans: param malloc fail for %u "
743 "bytes !\n", (unsigned int)state
->total_param
));
744 SAFE_FREE(state
->data
);
746 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
747 END_PROFILE(SMBtrans
);
750 /* null-terminate the slack space */
751 memset(&state
->param
[state
->total_param
], 0, 100);
753 memcpy(state
->param
,smb_base(req
->inbuf
)+psoff
,pscnt
);
756 state
->received_data
= dscnt
;
757 state
->received_param
= pscnt
;
759 if (state
->setup_count
) {
763 * No overflow possible here, state->setup_count is an
764 * unsigned int, being filled by a single byte from
765 * CVAL(req->vwv+13, 0) above. The cast in the comparison
766 * below is not necessary, it's here to clarify things. The
767 * validity of req->vwv and req->wct has been checked in
768 * init_smb_request already.
770 if (state
->setup_count
+ 14 > (unsigned int)req
->wct
) {
774 if((state
->setup
= talloc_array(
775 state
, uint16
, state
->setup_count
)) == NULL
) {
776 DEBUG(0,("reply_trans: setup malloc fail for %u "
777 "bytes !\n", (unsigned int)
778 (state
->setup_count
* sizeof(uint16
))));
779 SAFE_FREE(state
->data
);
780 SAFE_FREE(state
->param
);
782 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
783 END_PROFILE(SMBtrans
);
787 for (i
=0;i
<state
->setup_count
;i
++) {
788 state
->setup
[i
] = SVAL(req
->vwv
+ 14 + i
, 0);
792 state
->received_param
= pscnt
;
794 if ((state
->received_param
!= state
->total_param
) ||
795 (state
->received_data
!= state
->total_data
)) {
796 DLIST_ADD(conn
->pending_trans
, state
);
798 /* We need to send an interim response then receive the rest
799 of the parameter/data bytes */
800 reply_outbuf(req
, 0, 0);
801 show_msg((char *)req
->outbuf
);
802 END_PROFILE(SMBtrans
);
806 talloc_steal(talloc_tos(), state
);
808 handle_trans(conn
, req
, state
);
810 SAFE_FREE(state
->data
);
811 SAFE_FREE(state
->param
);
814 END_PROFILE(SMBtrans
);
819 DEBUG(0,("reply_trans: invalid trans parameters\n"));
820 SAFE_FREE(state
->data
);
821 SAFE_FREE(state
->param
);
823 END_PROFILE(SMBtrans
);
824 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
828 /****************************************************************************
829 Reply to a secondary SMBtrans.
830 ****************************************************************************/
832 void reply_transs(struct smb_request
*req
)
834 connection_struct
*conn
= req
->conn
;
835 unsigned int pcnt
,poff
,dcnt
,doff
,pdisp
,ddisp
;
836 struct trans_state
*state
;
838 START_PROFILE(SMBtranss
);
840 show_msg((const char *)req
->inbuf
);
843 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
844 END_PROFILE(SMBtranss
);
848 for (state
= conn
->pending_trans
; state
!= NULL
;
849 state
= state
->next
) {
850 if (state
->mid
== req
->mid
) {
855 if ((state
== NULL
) || (state
->cmd
!= SMBtrans
)) {
856 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
857 END_PROFILE(SMBtranss
);
861 /* Revise total_params and total_data in case they have changed
864 if (SVAL(req
->vwv
+0, 0) < state
->total_param
)
865 state
->total_param
= SVAL(req
->vwv
+0, 0);
866 if (SVAL(req
->vwv
+1, 0) < state
->total_data
)
867 state
->total_data
= SVAL(req
->vwv
+1, 0);
869 pcnt
= SVAL(req
->vwv
+2, 0);
870 poff
= SVAL(req
->vwv
+3, 0);
871 pdisp
= SVAL(req
->vwv
+4, 0);
873 dcnt
= SVAL(req
->vwv
+5, 0);
874 doff
= SVAL(req
->vwv
+6, 0);
875 ddisp
= SVAL(req
->vwv
+7, 0);
877 state
->received_param
+= pcnt
;
878 state
->received_data
+= dcnt
;
880 if ((state
->received_data
> state
->total_data
) ||
881 (state
->received_param
> state
->total_param
))
885 if (trans_oob(state
->total_param
, pdisp
, pcnt
)
886 || trans_oob(smb_len(req
->inbuf
), poff
, pcnt
)) {
889 memcpy(state
->param
+pdisp
,smb_base(req
->inbuf
)+poff
,pcnt
);
893 if (trans_oob(state
->total_data
, ddisp
, dcnt
)
894 || trans_oob(smb_len(req
->inbuf
), doff
, dcnt
)) {
897 memcpy(state
->data
+ddisp
, smb_base(req
->inbuf
)+doff
,dcnt
);
900 if ((state
->received_param
< state
->total_param
) ||
901 (state
->received_data
< state
->total_data
)) {
902 END_PROFILE(SMBtranss
);
906 talloc_steal(talloc_tos(), state
);
908 handle_trans(conn
, req
, state
);
910 DLIST_REMOVE(conn
->pending_trans
, state
);
911 SAFE_FREE(state
->data
);
912 SAFE_FREE(state
->param
);
915 END_PROFILE(SMBtranss
);
920 DEBUG(0,("reply_transs: invalid trans parameters\n"));
921 DLIST_REMOVE(conn
->pending_trans
, state
);
922 SAFE_FREE(state
->data
);
923 SAFE_FREE(state
->param
);
925 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
926 END_PROFILE(SMBtranss
);