made "hide files" and "veto files" into per-service parameter sections,
[Samba.git] / source / smbd / message.c
blob93a2d9d850a2c7be84e1ec7de311d1c658fbf55f
1 /*
2 Unix SMB/Netbios implementation.
3 Version 1.9.
4 SMB messaging
5 Copyright (C) Andrew Tridgell 1992-1997
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
23 messages
27 #include "includes.h"
29 /* look in server.c for some explanation of these variables */
30 extern int DEBUGLEVEL;
33 static char msgbuf[1600];
34 static int msgpos=0;
35 static fstring msgfrom="";
36 static fstring msgto="";
38 /****************************************************************************
39 deliver the message
40 ****************************************************************************/
41 static void msg_deliver(void)
43 pstring s;
44 fstring name;
45 int i;
46 int fd;
48 if (! (*lp_msg_command()))
50 DEBUG(1,("no messaging command specified\n"));
51 msgpos = 0;
52 return;
55 /* put it in a temporary file */
56 sprintf(s,"%s/msg.XXXXXX",tmpdir());
57 strcpy(name,(char *)mktemp(s));
59 fd = open(name,O_WRONLY|O_CREAT|O_TRUNC|O_EXCL,0600);
60 if (fd == -1) {
61 DEBUG(1,("can't open message file %s\n",name));
62 return;
65 for (i=0;i<msgpos;) {
66 if (msgbuf[i]=='\r' && i<(msgpos-1) && msgbuf[i+1]=='\n') {
67 i++; continue;
69 write(fd,&msgbuf[i++],1);
71 close(fd);
74 /* run the command */
75 if (*lp_msg_command())
77 strcpy(s,lp_msg_command());
78 string_sub(s,"%s",name);
79 string_sub(s,"%f",msgfrom);
80 string_sub(s,"%t",msgto);
81 standard_sub(-1,s);
82 smbrun(s,NULL,False);
85 msgpos = 0;
90 /****************************************************************************
91 reply to a sends
92 ****************************************************************************/
93 int reply_sends(char *inbuf,char *outbuf)
95 int len;
96 char *orig,*dest,*msg;
97 int outsize = 0;
99 msgpos = 0;
102 if (! (*lp_msg_command()))
103 return(ERROR(ERRSRV,ERRmsgoff));
105 outsize = set_message(outbuf,0,0,True);
107 orig = smb_buf(inbuf)+1;
108 dest = skip_string(orig,1)+1;
109 msg = skip_string(dest,1)+1;
111 strcpy(msgfrom,orig);
112 strcpy(msgto,dest);
114 len = SVAL(msg,0);
115 len = MIN(len,1600-msgpos);
117 memcpy(&msgbuf[msgpos],msg+2,len);
118 msgpos += len;
120 DEBUG(3,("%s SMBsends (from %s to %s)\n",timestring(),orig,dest));
122 msg_deliver();
124 return(outsize);
128 /****************************************************************************
129 reply to a sendstrt
130 ****************************************************************************/
131 int reply_sendstrt(char *inbuf,char *outbuf)
133 char *orig,*dest;
134 int outsize = 0;
136 if (! (*lp_msg_command()))
137 return(ERROR(ERRSRV,ERRmsgoff));
139 outsize = set_message(outbuf,1,0,True);
141 msgpos = 0;
143 orig = smb_buf(inbuf)+1;
144 dest = skip_string(orig,1)+1;
146 strcpy(msgfrom,orig);
147 strcpy(msgto,dest);
149 DEBUG(3,("%s SMBsendstrt (from %s to %s)\n",timestring(),orig,dest));
151 return(outsize);
155 /****************************************************************************
156 reply to a sendtxt
157 ****************************************************************************/
158 int reply_sendtxt(char *inbuf,char *outbuf)
160 int len;
161 int outsize = 0;
162 char *msg;
164 if (! (*lp_msg_command()))
165 return(ERROR(ERRSRV,ERRmsgoff));
167 outsize = set_message(outbuf,0,0,True);
169 msg = smb_buf(inbuf) + 1;
171 len = SVAL(msg,0);
172 len = MIN(len,1600-msgpos);
174 memcpy(&msgbuf[msgpos],msg+2,len);
175 msgpos += len;
177 DEBUG(3,("%s SMBsendtxt\n",timestring()));
179 return(outsize);
183 /****************************************************************************
184 reply to a sendend
185 ****************************************************************************/
186 int reply_sendend(char *inbuf,char *outbuf)
188 int outsize = 0;
190 if (! (*lp_msg_command()))
191 return(ERROR(ERRSRV,ERRmsgoff));
193 outsize = set_message(outbuf,0,0,True);
195 DEBUG(3,("%s SMBsendend\n",timestring()));
197 msg_deliver();
199 return(outsize);