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 #define REALLOC(ptr,size) Realloc(ptr,MAX((size),4*1024))
37 /* look in server.c for some explanation of these variables */
39 extern int DEBUGLEVEL;
40 extern char magic_char;
41 extern BOOL case_sensitive;
42 extern pstring sesssetup_user;
45 #define VALID_PNUM(pnum) (((pnum) >= 0) && ((pnum) < MAX_OPEN_PIPES))
46 #define OPEN_PNUM(pnum) (VALID_PNUM(pnum) && Pipes[pnum].open)
47 #define PNUM_OK(pnum,c) (OPEN_PNUM(pnum) && (c)==Pipes[pnum].cnum)
49 /* this macro should always be used to extract an pnum (smb_fid) from
50 a packet to ensure chaining works correctly */
51 #define GETPNUM(buf,where) (chain_pnum!= -1?chain_pnum:SVAL(buf,where))
53 extern struct pipe_id_info pipe_names[];
55 /****************************************************************************
56 reply to an open and X on a named pipe
58 This code is basically stolen from reply_open_and_X with some
59 wrinkles to handle pipes.
60 ****************************************************************************/
61 int reply_open_pipe_and_X(char *inbuf,char *outbuf,int length,int bufsize)
64 uint16 cnum = SVAL(inbuf, smb_tid);
65 uint16 vuid = SVAL(inbuf, smb_uid);
67 int smb_ofun = SVAL(inbuf,smb_vwv8);
68 int size=0,fmode=0,mtime=0,rmode=0;
71 /* XXXX we need to handle passed times, sattr and flags */
72 pstrcpy(fname,smb_buf(inbuf));
74 /* If the name doesn't start \PIPE\ then this is directed */
75 /* at a mailslot or something we really, really don't understand, */
76 /* not just something we really don't understand. */
77 if ( strncmp(fname,PIPE,PIPELEN) != 0 )
78 return(ERROR(ERRSRV,ERRaccess));
80 DEBUG(4,("Opening pipe %s.\n", fname));
82 /* See if it is one we want to handle. */
83 for( i = 0; pipe_names[i].client_pipe ; i++ )
84 if( strequal(fname,pipe_names[i].client_pipe) )
87 if ( pipe_names[i].client_pipe == NULL )
88 return(ERROR(ERRSRV,ERRaccess));
90 /* Strip \PIPE\ off the name. */
91 pstrcpy(fname,smb_buf(inbuf) + PIPELEN);
93 /* Known pipes arrive with DIR attribs. Remove it so a regular file */
94 /* can be opened and add it in after the open. */
95 DEBUG(3,("Known pipe %s opening.\n",fname));
96 smb_ofun |= 0x10; /* Add Create it not exists flag */
98 pnum = open_rpc_pipe_hnd(fname, cnum, vuid);
99 if (pnum < 0) return(ERROR(ERRSRV,ERRnofids));
101 /* Prepare the reply */
102 set_message(outbuf,15,0,True);
104 /* Mark the opened file as an existing named pipe in message mode. */
105 SSVAL(outbuf,smb_vwv9,2);
106 SSVAL(outbuf,smb_vwv10,0xc700);
110 DEBUG(4,("Resetting open result to open from create.\n"));
114 SSVAL(outbuf,smb_vwv2, pnum + 0x800); /* mark file handle up into high range */
115 SSVAL(outbuf,smb_vwv3,fmode);
116 put_dos_date3(outbuf,smb_vwv4,mtime);
117 SIVAL(outbuf,smb_vwv6,size);
118 SSVAL(outbuf,smb_vwv8,rmode);
119 SSVAL(outbuf,smb_vwv11,0);
121 return chain_reply(inbuf,outbuf,length,bufsize);
125 /****************************************************************************
126 reply to a read and X
128 This code is basically stolen from reply_read_and_X with some
129 wrinkles to handle pipes.
130 ****************************************************************************/
131 int reply_pipe_read_and_X(char *inbuf,char *outbuf,int length,int bufsize)
133 int pnum = get_rpc_pipe_num(inbuf,smb_vwv2);
134 uint32 smb_offs = IVAL(inbuf,smb_vwv3);
135 int smb_maxcnt = SVAL(inbuf,smb_vwv5);
136 int smb_mincnt = SVAL(inbuf,smb_vwv6);
142 cnum = SVAL(inbuf,smb_tid);
145 CHECK_FNUM(fnum,cnum);
150 set_message(outbuf,12,0,True);
151 data = smb_buf(outbuf);
153 nread = read_pipe(pnum, data, smb_offs, smb_maxcnt);
158 return(UNIXERROR(ERRDOS,ERRnoaccess));
160 SSVAL(outbuf,smb_vwv5,nread);
161 SSVAL(outbuf,smb_vwv6,smb_offset(data,outbuf));
162 SSVAL(smb_buf(outbuf),-2,nread);
164 DEBUG( 3, ( "readX pnum=%04x cnum=%d min=%d max=%d nread=%d\n",
165 pnum, cnum, smb_mincnt, smb_maxcnt, nread ) );
167 set_chain_pnum(pnum);
169 return chain_reply(inbuf,outbuf,length,bufsize);
171 /****************************************************************************
173 ****************************************************************************/
174 int reply_pipe_close(char *inbuf,char *outbuf)
176 int pnum = get_rpc_pipe_num(inbuf,smb_vwv0);
177 int cnum = SVAL(inbuf,smb_tid);
178 int outsize = set_message(outbuf,0,0,True);
180 DEBUG(5,("reply_pipe_close: pnum:%x cnum:%x\n", pnum, cnum));
182 if (!close_rpc_pipe_hnd(pnum, cnum)) return(ERROR(ERRDOS,ERRbadfid));