2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 1992-1998
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 This file handles the messaging system calls for winpopup style
27 extern userdom_struct current_user_info;
29 /* look in server.c for some explanation of these variables */
30 static char msgbuf[1600];
32 static fstring msgfrom;
35 /****************************************************************************
37 ****************************************************************************/
39 static void msg_deliver(void)
48 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.
67 if ((len = (int)convert_string_allocate(NULL,CH_DOS, CH_UNIX, msgbuf, msgpos, (void **)(void *)&msg, True)) < 0 || !msg) {
68 DEBUG(3,("Conversion failed, delivering message in DOS codepage format\n"));
69 for (i = 0; i < msgpos;) {
70 if (msgbuf[i] == '\r' && i < (msgpos-1) && msgbuf[i+1] == '\n') {
74 sz = write(fd, &msgbuf[i++], 1);
76 DEBUG(0,("Write error to fd %d: %ld(%d)\n",fd, (long)sz, errno ));
80 for (i = 0; i < len;) {
81 if (msg[i] == '\r' && i < (len-1) && msg[i+1] == '\n') {
85 sz = write(fd, &msg[i++],1);
87 DEBUG(0,("Write error to fd %d: %ld(%d)\n",fd, (long)sz, errno ));
95 if (*lp_msg_command()) {
96 fstring alpha_msgfrom;
100 pstrcpy(s,lp_msg_command());
101 pstring_sub(s,"%f",alpha_strcpy(alpha_msgfrom,msgfrom,NULL,sizeof(alpha_msgfrom)));
102 pstring_sub(s,"%t",alpha_strcpy(alpha_msgto,msgto,NULL,sizeof(alpha_msgto)));
103 standard_sub_basic(current_user_info.smb_name,
104 current_user_info.domain, s, sizeof(s));
105 pstring_sub(s,"%s",name);
112 /****************************************************************************
114 conn POINTER CAN BE NULL HERE !
115 ****************************************************************************/
117 int reply_sends(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize)
124 START_PROFILE(SMBsends);
128 if (! (*lp_msg_command())) {
129 END_PROFILE(SMBsends);
130 return(ERROR_DOS(ERRSRV,ERRmsgoff));
133 outsize = set_message(inbuf,outbuf,0,0,True);
135 p = smb_buf(inbuf)+1;
136 p += srvstr_pull_buf(inbuf, SVAL(inbuf, smb_flg2), msgfrom, p,
137 sizeof(msgfrom), STR_ASCII|STR_TERMINATE) + 1;
138 p += srvstr_pull_buf(inbuf, SVAL(inbuf, smb_flg2), msgto, p,
139 sizeof(msgto), STR_ASCII|STR_TERMINATE) + 1;
144 len = MIN(len,sizeof(msgbuf)-msgpos);
146 memset(msgbuf,'\0',sizeof(msgbuf));
148 memcpy(&msgbuf[msgpos],msg+2,len);
153 END_PROFILE(SMBsends);
157 /****************************************************************************
159 conn POINTER CAN BE NULL HERE !
160 ****************************************************************************/
162 int reply_sendstrt(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize)
167 START_PROFILE(SMBsendstrt);
169 if (! (*lp_msg_command())) {
170 END_PROFILE(SMBsendstrt);
171 return(ERROR_DOS(ERRSRV,ERRmsgoff));
174 outsize = set_message(inbuf,outbuf,1,0,True);
176 memset(msgbuf,'\0',sizeof(msgbuf));
179 p = smb_buf(inbuf)+1;
180 p += srvstr_pull_buf(inbuf, SVAL(inbuf, smb_flg2), msgfrom, p,
181 sizeof(msgfrom), STR_ASCII|STR_TERMINATE) + 1;
182 p += srvstr_pull_buf(inbuf, SVAL(inbuf, smb_flg2), msgto, p,
183 sizeof(msgto), STR_ASCII|STR_TERMINATE) + 1;
185 DEBUG( 3, ( "SMBsendstrt (from %s to %s)\n", msgfrom, msgto ) );
187 END_PROFILE(SMBsendstrt);
191 /****************************************************************************
193 conn POINTER CAN BE NULL HERE !
194 ****************************************************************************/
196 int reply_sendtxt(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize)
201 START_PROFILE(SMBsendtxt);
203 if (! (*lp_msg_command())) {
204 END_PROFILE(SMBsendtxt);
205 return(ERROR_DOS(ERRSRV,ERRmsgoff));
208 outsize = set_message(inbuf,outbuf,0,0,True);
210 msg = smb_buf(inbuf) + 1;
213 len = MIN(len,sizeof(msgbuf)-msgpos);
215 memcpy(&msgbuf[msgpos],msg+2,len);
218 DEBUG( 3, ( "SMBsendtxt\n" ) );
220 END_PROFILE(SMBsendtxt);
224 /****************************************************************************
226 conn POINTER CAN BE NULL HERE !
227 ****************************************************************************/
229 int reply_sendend(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize)
232 START_PROFILE(SMBsendend);
234 if (! (*lp_msg_command())) {
235 END_PROFILE(SMBsendend);
236 return(ERROR_DOS(ERRSRV,ERRmsgoff));
239 outsize = set_message(inbuf,outbuf,0,0,True);
241 DEBUG(3,("SMBsendend\n"));
245 END_PROFILE(SMBsendend);