2 Unix SMB/Netbios implementation.
5 Copyright (C) Andrew Tridgell 1992-1998
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 This file handles the messaging system calls for winpopup style
29 /* look in server.c for some explanation of these variables */
30 extern int DEBUGLEVEL;
33 static char msgbuf[1600];
35 static fstring msgfrom;
38 /****************************************************************************
40 ****************************************************************************/
41 static void msg_deliver(void)
48 if (! (*lp_msg_command()))
50 DEBUG(1,("no messaging command specified\n"));
55 /* put it in a temporary file */
56 slprintf(s,sizeof(s)-1, "%s/msg.XXXXXX",tmpdir());
57 fstrcpy(name,(char *)smbd_mktemp(s));
59 fd = sys_open(name,O_WRONLY|O_CREAT|O_TRUNC|O_EXCL,0600);
61 DEBUG(1,("can't open message file %s\n",name));
66 * Incoming message is in DOS codepage format. Convert to UNIX in
71 msgbuf[msgpos] = '\0'; /* Ensure null terminated. */
72 dos_to_unix(msgbuf,True);
76 if (msgbuf[i]=='\r' && i<(msgpos-1) && msgbuf[i+1]=='\n') {
79 write(fd,&msgbuf[i++],1);
85 if (*lp_msg_command())
87 fstring alpha_msgfrom;
90 pstrcpy(s,lp_msg_command());
91 pstring_sub(s,"%s",name);
92 pstring_sub(s,"%f",alpha_strcpy(alpha_msgfrom,msgfrom,sizeof(alpha_msgfrom)));
93 pstring_sub(s,"%t",alpha_strcpy(alpha_msgto,msgto,sizeof(alpha_msgto)));
94 standard_sub_basic(s);
103 /****************************************************************************
105 ****************************************************************************/
106 int reply_sends(connection_struct *conn,
107 char *inbuf,char *outbuf, int dum_size, int dum_buffsize)
114 START_PROFILE(SMBsends);
118 if (! (*lp_msg_command())) {
119 END_PROFILE(SMBsends);
120 return(ERROR(ERRSRV,ERRmsgoff));
123 outsize = set_message(outbuf,0,0,True);
125 p = smb_buf(inbuf)+1;
126 p += srvstr_pull(inbuf, msgfrom, p, sizeof(msgfrom), -1, STR_TERMINATE|STR_CONVERT) + 1;
127 p += srvstr_pull(inbuf, msgto, p, sizeof(msgto), -1, STR_TERMINATE|STR_CONVERT) + 1;
132 len = MIN(len,sizeof(msgbuf)-msgpos);
134 memset(msgbuf,'\0',sizeof(msgbuf));
136 memcpy(&msgbuf[msgpos],msg+2,len);
141 END_PROFILE(SMBsends);
146 /****************************************************************************
148 ****************************************************************************/
149 int reply_sendstrt(connection_struct *conn,
150 char *inbuf,char *outbuf, int dum_size, int dum_buffsize)
155 START_PROFILE(SMBsendstrt);
157 if (! (*lp_msg_command())) {
158 END_PROFILE(SMBsendstrt);
159 return(ERROR(ERRSRV,ERRmsgoff));
162 outsize = set_message(outbuf,1,0,True);
164 memset(msgbuf,'\0',sizeof(msgbuf));
167 p = smb_buf(inbuf)+1;
168 p += srvstr_pull(inbuf, msgfrom, p, sizeof(msgfrom), -1, STR_TERMINATE|STR_CONVERT) + 1;
169 p += srvstr_pull(inbuf, msgto, p, sizeof(msgto), -1, STR_TERMINATE|STR_CONVERT) + 1;
171 DEBUG( 3, ( "SMBsendstrt (from %s to %s)\n", msgfrom, msgto ) );
173 END_PROFILE(SMBsendstrt);
178 /****************************************************************************
180 ****************************************************************************/
181 int reply_sendtxt(connection_struct *conn,
182 char *inbuf,char *outbuf, int dum_size, int dum_buffsize)
187 START_PROFILE(SMBsendtxt);
189 if (! (*lp_msg_command())) {
190 END_PROFILE(SMBsendtxt);
191 return(ERROR(ERRSRV,ERRmsgoff));
194 outsize = set_message(outbuf,0,0,True);
196 msg = smb_buf(inbuf) + 1;
199 len = MIN(len,sizeof(msgbuf)-msgpos);
201 memcpy(&msgbuf[msgpos],msg+2,len);
204 DEBUG( 3, ( "SMBsendtxt\n" ) );
206 END_PROFILE(SMBsendtxt);
211 /****************************************************************************
213 ****************************************************************************/
214 int reply_sendend(connection_struct *conn,
215 char *inbuf,char *outbuf, int dum_size, int dum_buffsize)
218 START_PROFILE(SMBsendend);
220 if (! (*lp_msg_command())) {
221 END_PROFILE(SMBsendend);
222 return(ERROR(ERRSRV,ERRmsgoff));
225 outsize = set_message(outbuf,0,0,True);
227 DEBUG(3,("SMBsendend\n"));
231 END_PROFILE(SMBsendend);