2 Unix SMB/Netbios implementation.
4 Pipe SMB reply routines
5 Copyright (C) Andrew Tridgell 1992-1998
6 Copyright (C) Luke Kenneth Casson Leighton 1996-1998
7 Copyright (C) Paul Ashton 1997-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 2 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, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 This file handles reply_ calls on named pipes that the server
25 makes to handle specific protocols
32 #define PIPE "\\PIPE\\"
33 #define PIPELEN strlen(PIPE)
35 extern int DEBUGLEVEL;
37 extern struct pipe_id_info pipe_names[];
39 /****************************************************************************
40 reply to an open and X on a named pipe
42 This code is basically stolen from reply_open_and_X with some
43 wrinkles to handle pipes.
44 ****************************************************************************/
45 int reply_open_pipe_and_X(connection_struct *conn,
46 char *inbuf,char *outbuf,int length,int bufsize)
49 uint16 vuid = SVAL(inbuf, smb_uid);
51 int smb_ofun = SVAL(inbuf,smb_vwv8);
52 int size=0,fmode=0,mtime=0,rmode=0;
55 /* XXXX we need to handle passed times, sattr and flags */
56 pstrcpy(fname,smb_buf(inbuf));
58 /* If the name doesn't start \PIPE\ then this is directed */
59 /* at a mailslot or something we really, really don't understand, */
60 /* not just something we really don't understand. */
61 if ( strncmp(fname,PIPE,PIPELEN) != 0 )
62 return(ERROR(ERRSRV,ERRaccess));
64 DEBUG(4,("Opening pipe %s.\n", fname));
66 /* See if it is one we want to handle. */
67 for( i = 0; pipe_names[i].client_pipe ; i++ )
68 if( strequal(fname,pipe_names[i].client_pipe) )
71 if (pipe_names[i].client_pipe == NULL)
72 return(ERROR(ERRSRV,ERRaccess));
74 /* Strip \PIPE\ off the name. */
75 pstrcpy(fname,smb_buf(inbuf) + PIPELEN);
78 * Hack for NT printers... JRA.
80 if(should_fail_next_srvsvc_open(fname))
81 return(ERROR(ERRSRV,ERRaccess));
83 /* Known pipes arrive with DIR attribs. Remove it so a regular file */
84 /* can be opened and add it in after the open. */
85 DEBUG(3,("Known pipe %s opening.\n",fname));
86 smb_ofun |= FILE_CREATE_IF_NOT_EXIST;
88 p = open_rpc_pipe_p(fname, conn, vuid);
89 if (!p) return(ERROR(ERRSRV,ERRnofids));
91 /* Prepare the reply */
92 set_message(outbuf,15,0,True);
94 /* Mark the opened file as an existing named pipe in message mode. */
95 SSVAL(outbuf,smb_vwv9,2);
96 SSVAL(outbuf,smb_vwv10,0xc700);
99 DEBUG(4,("Resetting open result to open from create.\n"));
103 SSVAL(outbuf,smb_vwv2, p->pnum);
104 SSVAL(outbuf,smb_vwv3,fmode);
105 put_dos_date3(outbuf,smb_vwv4,mtime);
106 SIVAL(outbuf,smb_vwv6,size);
107 SSVAL(outbuf,smb_vwv8,rmode);
108 SSVAL(outbuf,smb_vwv11,0x0001);
110 return chain_reply(inbuf,outbuf,length,bufsize);
113 /****************************************************************************
114 reply to a write on a pipe
115 ****************************************************************************/
116 int reply_pipe_write(char *inbuf,char *outbuf,int length,int dum_bufsize)
118 pipes_struct *p = get_rpc_pipe_p(inbuf,smb_vwv0);
119 size_t numtowrite = SVAL(inbuf,smb_vwv1);
125 return(ERROR(ERRDOS,ERRbadfid));
127 data = smb_buf(inbuf) + 3;
132 nwritten = write_to_pipe(p, data, numtowrite);
134 if ((nwritten == 0 && numtowrite != 0) || (nwritten < 0))
135 return (UNIXERROR(ERRDOS,ERRnoaccess));
137 outsize = set_message(outbuf,1,0,True);
139 SSVAL(outbuf,smb_vwv0,nwritten);
141 DEBUG(3,("write-IPC pnum=%04x nwritten=%d\n",
147 /****************************************************************************
148 reply to a write and X
150 This code is basically stolen from reply_write_and_X with some
151 wrinkles to handle pipes.
152 ****************************************************************************/
153 int reply_pipe_write_and_X(char *inbuf,char *outbuf,int length,int bufsize)
155 pipes_struct *p = get_rpc_pipe_p(inbuf,smb_vwv2);
156 size_t numtowrite = SVAL(inbuf,smb_vwv10);
158 int smb_doff = SVAL(inbuf, smb_vwv11);
162 return(ERROR(ERRDOS,ERRbadfid));
164 data = smb_base(inbuf) + smb_doff;
169 nwritten = write_to_pipe(p, data, numtowrite);
171 if ((nwritten == 0 && numtowrite != 0) || (nwritten < 0))
172 return (UNIXERROR(ERRDOS,ERRnoaccess));
174 set_message(outbuf,6,0,True);
176 SSVAL(outbuf,smb_vwv2,nwritten);
178 DEBUG(3,("writeX-IPC pnum=%04x nwritten=%d\n",
181 return chain_reply(inbuf,outbuf,length,bufsize);
184 /****************************************************************************
185 reply to a read and X
187 This code is basically stolen from reply_read_and_X with some
188 wrinkles to handle pipes.
189 ****************************************************************************/
190 int reply_pipe_read_and_X(char *inbuf,char *outbuf,int length,int bufsize)
192 pipes_struct *p = get_rpc_pipe_p(inbuf,smb_vwv2);
193 int smb_maxcnt = SVAL(inbuf,smb_vwv5);
194 int smb_mincnt = SVAL(inbuf,smb_vwv6);
197 /* we don't use the offset given to use for pipe reads. This
198 is deliberate, instead we always return the next lump of
201 uint32 smb_offs = IVAL(inbuf,smb_vwv3);
205 return(ERROR(ERRDOS,ERRbadfid));
207 set_message(outbuf,12,0,True);
208 data = smb_buf(outbuf);
210 nread = read_from_pipe(p, data, smb_maxcnt);
213 return(UNIXERROR(ERRDOS,ERRnoaccess));
215 SSVAL(outbuf,smb_vwv5,nread);
216 SSVAL(outbuf,smb_vwv6,smb_offset(data,outbuf));
217 SSVAL(smb_buf(outbuf),-2,nread);
219 DEBUG(3,("readX-IPC pnum=%04x min=%d max=%d nread=%d\n",
220 p->pnum, smb_mincnt, smb_maxcnt, nread));
222 return chain_reply(inbuf,outbuf,length,bufsize);
225 /****************************************************************************
227 ****************************************************************************/
228 int reply_pipe_close(connection_struct *conn, char *inbuf,char *outbuf)
230 pipes_struct *p = get_rpc_pipe_p(inbuf,smb_vwv0);
231 int outsize = set_message(outbuf,0,0,True);
234 return(ERROR(ERRDOS,ERRbadfid));
236 DEBUG(5,("reply_pipe_close: pnum:%x\n", p->pnum));
238 if (!close_rpc_pipe_hnd(p, conn))
239 return(ERROR(ERRDOS,ERRbadfid));