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"
32 #include "source3/lib/substitute.h"
34 #define NERR_notsupported 50
36 static void api_no_reply(connection_struct *conn, struct smb_request *req);
38 /*******************************************************************
39 copies parameters and data, as needed, into the smb buffer
41 *both* the data and params sections should be aligned. this
42 is fudged in the rpc pipes by
43 at present, only the data section is. this may be a possible
44 cause of some of the ipc problems being experienced. lkcl26dec97
46 ******************************************************************/
48 static void copy_trans_params_and_data(char *outbuf, int align,
49 char *rparam, int param_offset, int param_len,
50 char *rdata, int data_offset, int data_len)
52 char *copy_into = smb_buf(outbuf);
60 DEBUG(5,("copy_trans_params_and_data: params[%d..%d] data[%d..%d] (align %d)\n",
61 param_offset, param_offset + param_len,
62 data_offset , data_offset + data_len,
70 memcpy(copy_into, &rparam[param_offset], param_len);
72 copy_into += param_len;
74 memset(copy_into, '\0', align);
80 memcpy(copy_into, &rdata[data_offset], data_len);
83 NTSTATUS nt_status_np_pipe(NTSTATUS status)
85 if (NT_STATUS_EQUAL(status, NT_STATUS_CONNECTION_DISCONNECTED)) {
86 status = NT_STATUS_PIPE_DISCONNECTED;
87 } else if (NT_STATUS_EQUAL(status, NT_STATUS_CONNECTION_RESET)) {
88 status = NT_STATUS_PIPE_BROKEN;
94 /****************************************************************************
96 ****************************************************************************/
98 void send_trans_reply(connection_struct *conn,
99 struct smb_request *req,
100 char *rparam, int rparam_len,
101 char *rdata, int rdata_len,
102 bool buffer_too_large)
104 int this_ldata,this_lparam;
105 int tot_data_sent = 0;
106 int tot_param_sent = 0;
109 int ldata = rdata ? rdata_len : 0;
110 int lparam = rparam ? rparam_len : 0;
111 struct smbXsrv_connection *xconn = req->xconn;
112 int max_send = xconn->smb1.sessions.max_send;
113 /* HACK: make sure we send at least 128 byte in one go */
114 int hdr_overhead = SMB_BUFFER_SIZE_MIN - 128;
116 if (buffer_too_large)
117 DEBUG(5,("send_trans_reply: buffer %d too large\n", ldata ));
119 this_lparam = MIN(lparam,max_send - hdr_overhead);
120 this_ldata = MIN(ldata,max_send - (hdr_overhead+this_lparam));
122 align = ((this_lparam)%4);
124 reply_outbuf(req, 10, 1+align+this_ldata+this_lparam);
127 * We might have SMBtranss in req which was transferred to the outbuf,
130 SCVAL(req->outbuf, smb_com, SMBtrans);
132 copy_trans_params_and_data((char *)req->outbuf, align,
133 rparam, tot_param_sent, this_lparam,
134 rdata, tot_data_sent, this_ldata);
136 SSVAL(req->outbuf,smb_vwv0,lparam);
137 SSVAL(req->outbuf,smb_vwv1,ldata);
138 SSVAL(req->outbuf,smb_vwv3,this_lparam);
139 SSVAL(req->outbuf,smb_vwv4,
140 smb_offset(smb_buf(req->outbuf)+1, req->outbuf));
141 SSVAL(req->outbuf,smb_vwv5,0);
142 SSVAL(req->outbuf,smb_vwv6,this_ldata);
143 SSVAL(req->outbuf,smb_vwv7,
144 smb_offset(smb_buf(req->outbuf)+1+this_lparam+align,
146 SSVAL(req->outbuf,smb_vwv8,0);
147 SSVAL(req->outbuf,smb_vwv9,0);
149 if (buffer_too_large) {
150 error_packet_set((char *)req->outbuf, ERRDOS, ERRmoredata,
151 STATUS_BUFFER_OVERFLOW, __LINE__, __FILE__);
154 show_msg((char *)req->outbuf);
155 if (!srv_send_smb(xconn, (char *)req->outbuf,
157 IS_CONN_ENCRYPTED(conn), &req->pcd)) {
158 exit_server_cleanly("send_trans_reply: srv_send_smb failed.");
161 TALLOC_FREE(req->outbuf);
163 tot_data_sent = this_ldata;
164 tot_param_sent = this_lparam;
166 while (tot_data_sent < ldata || tot_param_sent < lparam)
168 this_lparam = MIN(lparam-tot_param_sent,
169 max_send - hdr_overhead);
170 this_ldata = MIN(ldata -tot_data_sent,
171 max_send - (hdr_overhead+this_lparam));
179 align = (this_lparam%4);
181 reply_outbuf(req, 10, 1+align+this_ldata+this_lparam);
184 * We might have SMBtranss in req which was transferred to the
187 SCVAL(req->outbuf, smb_com, SMBtrans);
189 copy_trans_params_and_data((char *)req->outbuf, align,
190 rparam, tot_param_sent, this_lparam,
191 rdata, tot_data_sent, this_ldata);
193 SSVAL(req->outbuf,smb_vwv0,lparam);
194 SSVAL(req->outbuf,smb_vwv1,ldata);
196 SSVAL(req->outbuf,smb_vwv3,this_lparam);
197 SSVAL(req->outbuf,smb_vwv4,
198 smb_offset(smb_buf(req->outbuf)+1,req->outbuf));
199 SSVAL(req->outbuf,smb_vwv5,tot_param_sent);
200 SSVAL(req->outbuf,smb_vwv6,this_ldata);
201 SSVAL(req->outbuf,smb_vwv7,
202 smb_offset(smb_buf(req->outbuf)+1+this_lparam+align,
204 SSVAL(req->outbuf,smb_vwv8,tot_data_sent);
205 SSVAL(req->outbuf,smb_vwv9,0);
207 if (buffer_too_large) {
208 error_packet_set((char *)req->outbuf,
210 STATUS_BUFFER_OVERFLOW,
214 show_msg((char *)req->outbuf);
215 if (!srv_send_smb(xconn, (char *)req->outbuf,
217 IS_CONN_ENCRYPTED(conn), &req->pcd))
218 exit_server_cleanly("send_trans_reply: srv_send_smb "
221 tot_data_sent += this_ldata;
222 tot_param_sent += this_lparam;
223 TALLOC_FREE(req->outbuf);
227 /****************************************************************************
228 Start the first part of an RPC reply which began with an SMBtrans request.
229 ****************************************************************************/
231 struct dcerpc_cmd_state {
232 struct fake_file_handle *handle;
238 static void api_dcerpc_cmd_write_done(struct tevent_req *subreq);
239 static void api_dcerpc_cmd_read_done(struct tevent_req *subreq);
241 static void api_dcerpc_cmd(connection_struct *conn, struct smb_request *req,
242 files_struct *fsp, uint8_t *data, size_t length,
245 struct tevent_req *subreq;
246 struct dcerpc_cmd_state *state;
249 if (!fsp_is_np(fsp)) {
250 api_no_reply(conn, req);
255 * Trans requests are only allowed
256 * if no other Trans or Read is active
258 busy = np_read_in_progress(fsp->fake_file_handle);
260 reply_nterror(req, NT_STATUS_PIPE_BUSY);
264 state = talloc(req, struct dcerpc_cmd_state);
266 reply_nterror(req, NT_STATUS_NO_MEMORY);
269 req->async_priv = state;
271 state->handle = fsp->fake_file_handle;
274 * This memdup severely sucks. But doing it properly essentially means
275 * to rewrite lanman.c, something which I don't really want to do now.
277 state->data = (uint8_t *)talloc_memdup(state, data, length);
278 if (state->data == NULL) {
279 reply_nterror(req, NT_STATUS_NO_MEMORY);
282 state->num_data = length;
283 state->max_read = max_read;
285 subreq = np_write_send(state, req->sconn->ev_ctx, state->handle,
286 state->data, length);
287 if (subreq == NULL) {
289 reply_nterror(req, NT_STATUS_NO_MEMORY);
292 tevent_req_set_callback(subreq, api_dcerpc_cmd_write_done,
293 talloc_move(conn, &req));
296 static void api_dcerpc_cmd_write_done(struct tevent_req *subreq)
298 struct smb_request *req = tevent_req_callback_data(
299 subreq, struct smb_request);
300 struct dcerpc_cmd_state *state = talloc_get_type_abort(
301 req->async_priv, struct dcerpc_cmd_state);
303 ssize_t nwritten = -1;
305 status = np_write_recv(subreq, &nwritten);
307 if (!NT_STATUS_IS_OK(status)) {
308 NTSTATUS old = status;
309 status = nt_status_np_pipe(old);
311 DEBUG(10, ("Could not write to pipe: %s%s%s\n",
313 NT_STATUS_EQUAL(old, status)?"":" => ",
314 NT_STATUS_EQUAL(old, status)?"":nt_errstr(status)));
315 reply_nterror(req, status);
318 if (nwritten != state->num_data) {
319 status = NT_STATUS_PIPE_NOT_AVAILABLE;
320 DEBUG(10, ("Could not write to pipe: (%d/%d) => %s\n",
321 (int)state->num_data,
322 (int)nwritten, nt_errstr(status)));
323 reply_nterror(req, status);
327 state->data = talloc_realloc(state, state->data, uint8_t,
329 if (state->data == NULL) {
330 reply_nterror(req, NT_STATUS_NO_MEMORY);
334 subreq = np_read_send(state, req->sconn->ev_ctx,
335 state->handle, state->data, state->max_read);
336 if (subreq == NULL) {
337 reply_nterror(req, NT_STATUS_NO_MEMORY);
340 tevent_req_set_callback(subreq, api_dcerpc_cmd_read_done, req);
345 req->xconn, (char *)req->outbuf,
347 IS_CONN_ENCRYPTED(req->conn) || req->encrypted,
349 exit_server_cleanly("api_dcerpc_cmd_write_done: "
350 "srv_send_smb failed.");
355 static void api_dcerpc_cmd_read_done(struct tevent_req *subreq)
357 struct smb_request *req = tevent_req_callback_data(
358 subreq, struct smb_request);
359 struct dcerpc_cmd_state *state = talloc_get_type_abort(
360 req->async_priv, struct dcerpc_cmd_state);
363 bool is_data_outstanding;
365 status = np_read_recv(subreq, &nread, &is_data_outstanding);
368 if (!NT_STATUS_IS_OK(status)) {
369 NTSTATUS old = status;
370 status = nt_status_np_pipe(old);
372 DEBUG(10, ("Could not read from to pipe: %s%s%s\n",
374 NT_STATUS_EQUAL(old, status)?"":" => ",
375 NT_STATUS_EQUAL(old, status)?"":nt_errstr(status)));
376 reply_nterror(req, status);
378 if (!srv_send_smb(req->xconn, (char *)req->outbuf,
380 IS_CONN_ENCRYPTED(req->conn)
381 ||req->encrypted, &req->pcd)) {
382 exit_server_cleanly("api_dcerpc_cmd_read_done: "
383 "srv_send_smb failed.");
389 send_trans_reply(req->conn, req, NULL, 0, (char *)state->data, nread,
390 is_data_outstanding);
394 /****************************************************************************
395 WaitNamedPipeHandleState
396 ****************************************************************************/
398 static void api_WNPHS(connection_struct *conn, struct smb_request *req,
399 struct files_struct *fsp, char *param, int param_len)
401 if (!param || param_len < 2) {
402 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
406 DEBUG(4,("WaitNamedPipeHandleState priority %x\n",
407 (int)SVAL(param,0)));
409 send_trans_reply(conn, req, NULL, 0, NULL, 0, False);
413 /****************************************************************************
414 SetNamedPipeHandleState
415 ****************************************************************************/
417 static void api_SNPHS(connection_struct *conn, struct smb_request *req,
418 struct files_struct *fsp, char *param, int param_len)
420 if (!param || param_len < 2) {
421 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
425 DEBUG(4,("SetNamedPipeHandleState to code %x\n", (int)SVAL(param,0)));
427 send_trans_reply(conn, req, NULL, 0, NULL, 0, False);
431 /****************************************************************************
432 When no reply is generated, indicate unsupported.
433 ****************************************************************************/
435 static void api_no_reply(connection_struct *conn, struct smb_request *req)
440 SSVAL(rparam,0,NERR_notsupported);
441 SSVAL(rparam,2,0); /* converter word */
443 DEBUG(3,("Unsupported API fd command\n"));
445 /* now send the reply */
446 send_trans_reply(conn, req, rparam, 4, NULL, 0, False);
451 /****************************************************************************
452 Handle remote api calls delivered to a named pipe already opened.
453 ****************************************************************************/
455 static void api_fd_reply(connection_struct *conn, uint64_t vuid,
456 struct smb_request *req,
457 uint16_t *setup, uint8_t *data, char *params,
458 int suwcnt, int tdscnt, int tpscnt,
459 int mdrcnt, int mprcnt)
461 struct files_struct *fsp;
465 DEBUG(5,("api_fd_reply\n"));
467 /* First find out the name of this file. */
469 DEBUG(0,("Unexpected named pipe transaction.\n"));
470 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
474 /* Get the file handle and hence the file name. */
476 * NB. The setup array has already been transformed
477 * via SVAL and so is in host byte order.
479 pnum = ((int)setup[1]) & 0xFFFF;
480 subcommand = ((int)setup[0]) & 0xFFFF;
482 fsp = file_fsp(req, pnum);
484 if (!fsp_is_np(fsp)) {
485 if (subcommand == TRANSACT_WAITNAMEDPIPEHANDLESTATE) {
486 /* Win9x does this call with a unicode pipe name, not a pnum. */
487 /* Just return success for now... */
488 DEBUG(3,("Got TRANSACT_WAITNAMEDPIPEHANDLESTATE on text pipe name\n"));
489 send_trans_reply(conn, req, NULL, 0, NULL, 0, False);
493 DEBUG(1,("api_fd_reply: INVALID PIPE HANDLE: %x\n", pnum));
494 reply_nterror(req, NT_STATUS_INVALID_HANDLE);
498 if (vuid != fsp->vuid) {
499 DEBUG(1, ("Got pipe request (pnum %x) using invalid VUID %llu, "
500 "expected %llu\n", pnum, (unsigned long long)vuid,
501 (unsigned long long)fsp->vuid));
502 reply_nterror(req, NT_STATUS_INVALID_HANDLE);
506 DEBUG(3,("Got API command 0x%x on pipe \"%s\" (pnum %x)\n",
507 subcommand, fsp_str_dbg(fsp), pnum));
509 DEBUG(10, ("api_fd_reply: p:%p max_trans_reply: %d\n", fsp, mdrcnt));
511 switch (subcommand) {
512 case TRANSACT_DCERPCCMD: {
513 /* dce/rpc command */
514 api_dcerpc_cmd(conn, req, fsp, (uint8_t *)data, tdscnt,
518 case TRANSACT_WAITNAMEDPIPEHANDLESTATE:
519 /* Wait Named Pipe Handle state */
520 api_WNPHS(conn, req, fsp, params, tpscnt);
522 case TRANSACT_SETNAMEDPIPEHANDLESTATE:
523 /* Set Named Pipe Handle state */
524 api_SNPHS(conn, req, fsp, params, tpscnt);
527 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
532 /****************************************************************************
533 Handle named pipe commands.
534 ****************************************************************************/
536 static void named_pipe(connection_struct *conn, uint64_t vuid,
537 struct smb_request *req,
538 const char *name, uint16_t *setup,
539 char *data, char *params,
540 int suwcnt, int tdscnt,int tpscnt,
541 int msrcnt, int mdrcnt, int mprcnt)
543 DEBUG(3,("named pipe command on <%s> name\n", name));
545 if (strequal(name,"LANMAN")) {
546 api_reply(conn, vuid, req,
553 if (strequal(name,"WKSSVC") ||
554 strequal(name,"SRVSVC") ||
555 strequal(name,"WINREG") ||
556 strequal(name,"SAMR") ||
557 strequal(name,"LSARPC")) {
559 DEBUG(4,("named pipe command from Win95 (wow!)\n"));
561 api_fd_reply(conn, vuid, req,
562 setup, (uint8_t *)data, params,
563 suwcnt, tdscnt, tpscnt,
568 if (strlen(name) < 1) {
569 api_fd_reply(conn, vuid, req,
570 setup, (uint8_t *)data,
571 params, suwcnt, tdscnt,
572 tpscnt, mdrcnt, mprcnt);
577 DEBUG(3,("unknown named pipe: setup 0x%X setup1=%d\n",
578 (int)setup[0],(int)setup[1]));
580 reply_nterror(req, NT_STATUS_NOT_SUPPORTED);
584 static void handle_trans(connection_struct *conn, struct smb_request *req,
585 struct trans_state *state)
587 char *local_machine_name;
590 DEBUG(3,("trans <%s> data=%u params=%u setup=%u\n",
591 state->name,(unsigned int)state->total_data,(unsigned int)state->total_param,
592 (unsigned int)state->setup_count));
595 * WinCE wierdness....
598 local_machine_name = talloc_asprintf(state, "\\%s\\",
599 get_local_machine_name());
601 if (local_machine_name == NULL) {
602 reply_nterror(req, NT_STATUS_NO_MEMORY);
606 if (strnequal(state->name, local_machine_name,
607 strlen(local_machine_name))) {
608 name_offset = strlen(local_machine_name)-1;
611 if (!strnequal(&state->name[name_offset], "\\PIPE",
613 reply_nterror(req, NT_STATUS_NOT_SUPPORTED);
617 name_offset += strlen("\\PIPE");
619 /* Win9x weirdness. When talking to a unicode server Win9x
620 only sends \PIPE instead of \PIPE\ */
622 if (state->name[name_offset] == '\\')
625 DEBUG(5,("calling named_pipe\n"));
626 named_pipe(conn, state->vuid, req,
627 state->name+name_offset,
628 state->setup,state->data,
630 state->setup_count,state->total_data,
632 state->max_setup_return,
633 state->max_data_return,
634 state->max_param_return);
636 if (state->close_on_completion) {
637 struct smbXsrv_tcon *tcon;
645 * TODO: cancel all outstanding requests on the tcon
647 status = smbXsrv_tcon_disconnect(tcon, state->vuid);
648 if (!NT_STATUS_IS_OK(status)) {
649 DEBUG(0, ("handle_trans: "
650 "smbXsrv_tcon_disconnect() failed: %s\n",
653 * If we hit this case, there is something completely
654 * wrong, so we better disconnect the transport connection.
656 exit_server(__location__ ": smbXsrv_tcon_disconnect failed");
666 /****************************************************************************
668 ****************************************************************************/
670 void reply_trans(struct smb_request *req)
672 connection_struct *conn = req->conn;
677 struct trans_state *state;
680 START_PROFILE(SMBtrans);
683 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
684 END_PROFILE(SMBtrans);
688 dsoff = SVAL(req->vwv+12, 0);
689 dscnt = SVAL(req->vwv+11, 0);
690 psoff = SVAL(req->vwv+10, 0);
691 pscnt = SVAL(req->vwv+9, 0);
693 result = allow_new_trans(conn->pending_trans, req->mid);
694 if (!NT_STATUS_IS_OK(result)) {
695 DEBUG(2, ("Got invalid trans request: %s\n",
697 reply_nterror(req, result);
698 END_PROFILE(SMBtrans);
702 if ((state = talloc(conn, struct trans_state)) == NULL) {
703 DEBUG(0, ("talloc failed\n"));
704 reply_nterror(req, NT_STATUS_NO_MEMORY);
705 END_PROFILE(SMBtrans);
709 state->cmd = SMBtrans;
711 state->mid = req->mid;
712 state->vuid = req->vuid;
713 state->setup_count = CVAL(req->vwv+13, 0);
715 state->total_param = SVAL(req->vwv+0, 0);
717 state->total_data = SVAL(req->vwv+1, 0);
719 state->max_param_return = SVAL(req->vwv+2, 0);
720 state->max_data_return = SVAL(req->vwv+3, 0);
721 state->max_setup_return = CVAL(req->vwv+4, 0);
722 state->close_on_completion = BITSETW(req->vwv+5, 0);
723 state->one_way = BITSETW(req->vwv+5, 1);
725 srvstr_pull_req_talloc(state, req, &state->name, req->buf,
728 if ((dscnt > state->total_data) || (pscnt > state->total_param) ||
732 if (state->total_data) {
734 if (trans_oob(state->total_data, 0, dscnt)
735 || trans_oob(smb_len(req->inbuf), dsoff, dscnt)) {
739 /* Can't use talloc here, the core routines do realloc on the
740 * params and data. Out of paranoia, 100 bytes too many. */
741 state->data = (char *)SMB_MALLOC(state->total_data+100);
742 if (state->data == NULL) {
743 DEBUG(0,("reply_trans: data malloc fail for %u "
744 "bytes !\n", (unsigned int)state->total_data));
746 reply_nterror(req, NT_STATUS_NO_MEMORY);
747 END_PROFILE(SMBtrans);
750 /* null-terminate the slack space */
751 memset(&state->data[state->total_data], 0, 100);
753 memcpy(state->data,smb_base(req->inbuf)+dsoff,dscnt);
756 if (state->total_param) {
758 if (trans_oob(state->total_param, 0, pscnt)
759 || trans_oob(smb_len(req->inbuf), psoff, pscnt)) {
763 /* Can't use talloc here, the core routines do realloc on the
764 * params and data. Out of paranoia, 100 bytes too many */
765 state->param = (char *)SMB_MALLOC(state->total_param+100);
766 if (state->param == NULL) {
767 DEBUG(0,("reply_trans: param malloc fail for %u "
768 "bytes !\n", (unsigned int)state->total_param));
769 SAFE_FREE(state->data);
771 reply_nterror(req, NT_STATUS_NO_MEMORY);
772 END_PROFILE(SMBtrans);
775 /* null-terminate the slack space */
776 memset(&state->param[state->total_param], 0, 100);
778 memcpy(state->param,smb_base(req->inbuf)+psoff,pscnt);
781 state->received_data = dscnt;
782 state->received_param = pscnt;
784 if (state->setup_count) {
788 * No overflow possible here, state->setup_count is an
789 * unsigned int, being filled by a single byte from
790 * CVAL(req->vwv+13, 0) above. The cast in the comparison
791 * below is not necessary, it's here to clarify things. The
792 * validity of req->vwv and req->wct has been checked in
793 * init_smb_request already.
795 if (state->setup_count + 14 > (unsigned int)req->wct) {
799 if((state->setup = talloc_array(
800 state, uint16_t, state->setup_count)) == NULL) {
801 DEBUG(0,("reply_trans: setup malloc fail for %u "
802 "bytes !\n", (unsigned int)
803 (state->setup_count * sizeof(uint16_t))));
804 SAFE_FREE(state->data);
805 SAFE_FREE(state->param);
807 reply_nterror(req, NT_STATUS_NO_MEMORY);
808 END_PROFILE(SMBtrans);
812 for (i=0;i<state->setup_count;i++) {
813 state->setup[i] = SVAL(req->vwv + 14 + i, 0);
817 state->received_param = pscnt;
819 if ((state->received_param != state->total_param) ||
820 (state->received_data != state->total_data)) {
821 DLIST_ADD(conn->pending_trans, state);
823 /* We need to send an interim response then receive the rest
824 of the parameter/data bytes */
825 reply_outbuf(req, 0, 0);
826 show_msg((char *)req->outbuf);
827 END_PROFILE(SMBtrans);
831 talloc_steal(talloc_tos(), state);
833 handle_trans(conn, req, state);
835 SAFE_FREE(state->data);
836 SAFE_FREE(state->param);
839 END_PROFILE(SMBtrans);
844 DEBUG(0,("reply_trans: invalid trans parameters\n"));
845 SAFE_FREE(state->data);
846 SAFE_FREE(state->param);
848 END_PROFILE(SMBtrans);
849 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
853 /****************************************************************************
854 Reply to a secondary SMBtrans.
855 ****************************************************************************/
857 void reply_transs(struct smb_request *req)
859 connection_struct *conn = req->conn;
860 unsigned int pcnt,poff,dcnt,doff,pdisp,ddisp;
861 struct trans_state *state;
863 START_PROFILE(SMBtranss);
865 show_msg((const char *)req->inbuf);
868 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
869 END_PROFILE(SMBtranss);
873 for (state = conn->pending_trans; state != NULL;
874 state = state->next) {
875 if (state->mid == req->mid) {
880 if ((state == NULL) || (state->cmd != SMBtrans)) {
881 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
882 END_PROFILE(SMBtranss);
886 /* Revise total_params and total_data in case they have changed
889 if (SVAL(req->vwv+0, 0) < state->total_param)
890 state->total_param = SVAL(req->vwv+0, 0);
891 if (SVAL(req->vwv+1, 0) < state->total_data)
892 state->total_data = SVAL(req->vwv+1, 0);
894 pcnt = SVAL(req->vwv+2, 0);
895 poff = SVAL(req->vwv+3, 0);
896 pdisp = SVAL(req->vwv+4, 0);
898 dcnt = SVAL(req->vwv+5, 0);
899 doff = SVAL(req->vwv+6, 0);
900 ddisp = SVAL(req->vwv+7, 0);
902 state->received_param += pcnt;
903 state->received_data += dcnt;
905 if ((state->received_data > state->total_data) ||
906 (state->received_param > state->total_param))
910 if (trans_oob(state->total_param, pdisp, pcnt)
911 || trans_oob(smb_len(req->inbuf), poff, pcnt)) {
914 memcpy(state->param+pdisp,smb_base(req->inbuf)+poff,pcnt);
918 if (trans_oob(state->total_data, ddisp, dcnt)
919 || trans_oob(smb_len(req->inbuf), doff, dcnt)) {
922 memcpy(state->data+ddisp, smb_base(req->inbuf)+doff,dcnt);
925 if ((state->received_param < state->total_param) ||
926 (state->received_data < state->total_data)) {
927 END_PROFILE(SMBtranss);
931 talloc_steal(talloc_tos(), state);
933 handle_trans(conn, req, state);
935 DLIST_REMOVE(conn->pending_trans, state);
936 SAFE_FREE(state->data);
937 SAFE_FREE(state->param);
940 END_PROFILE(SMBtranss);
945 DEBUG(0,("reply_transs: invalid trans parameters\n"));
946 DLIST_REMOVE(conn->pending_trans, state);
947 SAFE_FREE(state->data);
948 SAFE_FREE(state->param);
950 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
951 END_PROFILE(SMBtranss);