This commit was generated by cvs2svn to compensate for changes in r4,
[ira/wip.git] / source3 / smbd / message.c
1 /* 
2    Unix SMB/Netbios implementation.
3    Version 1.9.
4    SMB messaging
5    Copyright (C) Andrew Tridgell 1992-1995
6    
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.
11    
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.
16    
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.
20 */
21 /*
22    This file handles the messaging system calls for winpopup style
23    messages
24 */
25
26
27 #include "includes.h"
28 #include "loadparm.h"
29
30 /* look in server.c for some explanation of these variables */
31 extern int DEBUGLEVEL;
32
33
34 static char msgbuf[1600];
35 static int msgpos=0;
36 static fstring msgfrom="";
37 static fstring msgto="";
38
39 /****************************************************************************
40 deliver the message
41 ****************************************************************************/
42 static void msg_deliver(void)
43 {
44   pstring s;
45   fstring name;
46   FILE *f;
47   int i;
48
49   if (! (*lp_msg_command()))
50     {
51       DEBUG(1,("no messaging command specified\n"));
52       msgpos = 0;
53       return;
54     }
55
56   /* put it in a temporary file */
57   sprintf(s,"/tmp/msg.XXXXXX");
58   strcpy(name,(char *)mktemp(s));
59
60   f = fopen(name,"w");
61   if (!f)
62     {
63       DEBUG(1,("can't open message file %s\n",name));
64       return;
65     }
66
67   for (i=0;i<msgpos;)
68     {
69       if (msgbuf[i]=='\r' && i<(msgpos-1) && msgbuf[i+1]=='\n')
70         i++;
71       fputc(msgbuf[i++],f);
72     }
73
74   fclose(f);
75
76
77   /* run the command */
78   if (*lp_msg_command())
79     {
80       strcpy(s,lp_msg_command());
81       string_sub(s,"%s",name);
82       string_sub(s,"%f",msgfrom);
83       string_sub(s,"%t",msgto);
84       standard_sub(-1,s);
85       smbrun(s,NULL);
86     }
87
88   msgpos = 0;
89 }
90
91
92
93 /****************************************************************************
94   reply to a sends
95 ****************************************************************************/
96 int reply_sends(char *inbuf,char *outbuf)
97 {
98   int len;
99   char *orig,*dest,*msg;
100   int outsize = 0;
101
102   msgpos = 0;
103
104
105   if (! (*lp_msg_command()))
106     return(ERROR(ERRSRV,ERRmsgoff));
107
108   outsize = set_message(outbuf,0,0,True);
109
110   orig = smb_buf(inbuf)+1;
111   dest = skip_string(orig,1)+1;
112   msg = skip_string(dest,1)+1;
113
114   strcpy(msgfrom,orig);
115   strcpy(msgto,dest);
116
117   len = SVAL(msg,0);
118   len = MIN(len,1600-msgpos);
119
120   memcpy(&msgbuf[msgpos],msg+2,len);
121   msgpos += len;
122
123   DEBUG(3,("%s SMBsends (from %s to %s)\n",timestring(),orig,dest));
124
125   msg_deliver();
126
127   return(outsize);
128 }
129
130
131 /****************************************************************************
132   reply to a sendstrt
133 ****************************************************************************/
134 int reply_sendstrt(char *inbuf,char *outbuf)
135 {
136   char *orig,*dest;
137   int outsize = 0;
138
139   if (! (*lp_msg_command()))
140     return(ERROR(ERRSRV,ERRmsgoff));
141
142   outsize = set_message(outbuf,1,0,True);
143
144   msgpos = 0;
145
146   orig = smb_buf(inbuf)+1;
147   dest = skip_string(orig,1)+1;
148
149   strcpy(msgfrom,orig);
150   strcpy(msgto,dest);
151
152   DEBUG(3,("%s SMBsendstrt (from %s to %s)\n",timestring(),orig,dest));
153
154   return(outsize);
155 }
156
157
158 /****************************************************************************
159   reply to a sendtxt
160 ****************************************************************************/
161 int reply_sendtxt(char *inbuf,char *outbuf)
162 {
163   int len;
164   int outsize = 0;
165   char *msg;
166
167   if (! (*lp_msg_command()))
168     return(ERROR(ERRSRV,ERRmsgoff));
169
170   outsize = set_message(outbuf,0,0,True);
171
172   msg = smb_buf(inbuf) + 1;
173
174   len = SVAL(msg,0);
175   len = MIN(len,1600-msgpos);
176
177   memcpy(&msgbuf[msgpos],msg+2,len);
178   msgpos += len;
179
180   DEBUG(3,("%s SMBsendtxt\n",timestring()));
181
182   return(outsize);
183 }
184
185
186 /****************************************************************************
187   reply to a sendend
188 ****************************************************************************/
189 int reply_sendend(char *inbuf,char *outbuf)
190 {
191   int outsize = 0;
192
193   if (! (*lp_msg_command()))
194     return(ERROR(ERRSRV,ERRmsgoff));
195
196   outsize = set_message(outbuf,0,0,True);
197
198   DEBUG(3,("%s SMBsendend\n",timestring()));
199
200   msg_deliver();
201
202   return(outsize);
203 }
204