3 * Unix SMB/Netbios implementation.
5 * RPC Pipe client / server routines
6 * Copyright (C) Andrew Tridgell 1992-1998
7 * Copyright (C) Luke Kenneth Casson Leighton 1996-1998,
8 * Copyright (C) Paul Ashton 1997-1998.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 /* this module apparently provides an implementation of DCE/RPC over a
26 * named pipe (IPC$ connection using SMBtrans). details of DCE/RPC
27 * documentation are available (in on-line form) from the X-Open group.
29 * this module should provide a level of abstraction between SMB
30 * and DCE/RPC, while minimising the amount of mallocs, unnecessary
31 * data copies, and network traffic.
33 * in this version, which takes a "let's learn what's going on and
34 * get something running" approach, there is additional network
35 * traffic generated, but the code should be easier to understand...
37 * ... if you read the docs. or stare at packets for weeks on end.
44 extern int DEBUGLEVEL;
46 /*******************************************************************
47 entry point from msrpc to smb. adds data received to pdu; checks
48 pdu; hands pdu off to msrpc, which gets a pdu back (except in the
49 case of the RPC_BINDCONT pdu).
50 ********************************************************************/
51 BOOL readwrite_pipe(pipes_struct *p, char *data, int len,
52 char **rdata, int *rlen)
54 DEBUG(10,("rpc_to_smb_readwrite: len %d\n", len));
56 if (write(p->m->fd, data, len) != len)
66 (*rdata) = (char*)Realloc((*rdata), (*rlen));
72 /* read a minimum of an rpc header, then wait for up to 10 seconds
73 * to read up to a maximum of the SMBtrans max data size
75 (*rlen) = read_with_timeout(p->m->fd, (*rdata), 16, (*rlen), 10000);
80 (*rdata) = (char*)Realloc((*rdata), (*rlen));
88 /****************************************************************************
89 writes data to a pipe.
90 ****************************************************************************/
91 ssize_t write_pipe(pipes_struct *p, char *data, size_t n)
93 DEBUG(6,("write_pipe: %x", p->pnum));
94 DEBUG(6,("name: %s open: %s len: %d",
95 p->name, BOOLSTR(p->open), n));
97 dump_data(50, data, n);
99 return write(p->m->fd, data, n);
103 /****************************************************************************
104 reads data from a pipe.
106 headers are interspersed with the data at regular intervals. by the time
107 this function is called, the start of the data could possibly have been
108 read by an SMBtrans (file_offset != 0).
110 ****************************************************************************/
111 int read_pipe(pipes_struct *p, char *data, int n)
113 DEBUG(6,("read_pipe: %x name: %s open: %s len: %d",
114 p->pnum, p->name, BOOLSTR(p->open), n));
118 DEBUG(6,("pipe not open\n"));
122 return read_data(p->m->fd, data, n);