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)
47 if (! (*lp_msg_command()))
49 DEBUG(1,("no messaging command specified\n"));
54 /* put it in a temporary file */
55 slprintf(name,sizeof(name)-1, "%s/msg.XXXXXX",tmpdir());
56 fd = smb_mkstemp(name);
59 DEBUG(1,("can't open message file %s\n",name));
64 * Incoming message is in DOS codepage format. Convert to UNIX.
68 msgbuf[msgpos] = '\0'; /* Ensure null terminated. */
72 if (msgbuf[i]=='\r' && i<(msgpos-1) && msgbuf[i+1]=='\n') {
75 write(fd,&msgbuf[i++],1);
81 if (*lp_msg_command())
83 fstring alpha_msgfrom;
87 pstrcpy(s,lp_msg_command());
88 pstring_sub(s,"%f",alpha_strcpy(alpha_msgfrom,msgfrom,NULL,sizeof(alpha_msgfrom)));
89 pstring_sub(s,"%t",alpha_strcpy(alpha_msgto,msgto,NULL,sizeof(alpha_msgto)));
90 standard_sub_basic(s);
91 pstring_sub(s,"%s",name);
100 /****************************************************************************
102 ****************************************************************************/
103 int reply_sends(connection_struct *conn,
104 char *inbuf,char *outbuf, int dum_size, int dum_buffsize)
111 START_PROFILE(SMBsends);
115 if (! (*lp_msg_command())) {
116 END_PROFILE(SMBsends);
117 return(ERROR_DOS(ERRSRV,ERRmsgoff));
120 outsize = set_message(outbuf,0,0,True);
122 p = smb_buf(inbuf)+1;
123 p += srvstr_pull(inbuf, msgfrom, p, sizeof(msgfrom), -1, STR_TERMINATE) + 1;
124 p += srvstr_pull(inbuf, msgto, p, sizeof(msgto), -1, STR_TERMINATE) + 1;
129 len = MIN(len,sizeof(msgbuf)-msgpos);
131 memset(msgbuf,'\0',sizeof(msgbuf));
133 memcpy(&msgbuf[msgpos],msg+2,len);
138 END_PROFILE(SMBsends);
143 /****************************************************************************
145 ****************************************************************************/
146 int reply_sendstrt(connection_struct *conn,
147 char *inbuf,char *outbuf, int dum_size, int dum_buffsize)
152 START_PROFILE(SMBsendstrt);
154 if (! (*lp_msg_command())) {
155 END_PROFILE(SMBsendstrt);
156 return(ERROR_DOS(ERRSRV,ERRmsgoff));
159 outsize = set_message(outbuf,1,0,True);
161 memset(msgbuf,'\0',sizeof(msgbuf));
164 p = smb_buf(inbuf)+1;
165 p += srvstr_pull(inbuf, msgfrom, p, sizeof(msgfrom), -1, STR_TERMINATE) + 1;
166 p += srvstr_pull(inbuf, msgto, p, sizeof(msgto), -1, STR_TERMINATE) + 1;
168 DEBUG( 3, ( "SMBsendstrt (from %s to %s)\n", msgfrom, msgto ) );
170 END_PROFILE(SMBsendstrt);
175 /****************************************************************************
177 ****************************************************************************/
178 int reply_sendtxt(connection_struct *conn,
179 char *inbuf,char *outbuf, int dum_size, int dum_buffsize)
184 START_PROFILE(SMBsendtxt);
186 if (! (*lp_msg_command())) {
187 END_PROFILE(SMBsendtxt);
188 return(ERROR_DOS(ERRSRV,ERRmsgoff));
191 outsize = set_message(outbuf,0,0,True);
193 msg = smb_buf(inbuf) + 1;
196 len = MIN(len,sizeof(msgbuf)-msgpos);
198 memcpy(&msgbuf[msgpos],msg+2,len);
201 DEBUG( 3, ( "SMBsendtxt\n" ) );
203 END_PROFILE(SMBsendtxt);
208 /****************************************************************************
210 ****************************************************************************/
211 int reply_sendend(connection_struct *conn,
212 char *inbuf,char *outbuf, int dum_size, int dum_buffsize)
215 START_PROFILE(SMBsendend);
217 if (! (*lp_msg_command())) {
218 END_PROFILE(SMBsendend);
219 return(ERROR_DOS(ERRSRV,ERRmsgoff));
222 outsize = set_message(outbuf,0,0,True);
224 DEBUG(3,("SMBsendend\n"));
228 END_PROFILE(SMBsendend);