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 2 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, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 This file handles the messaging system calls for winpopup style
28 extern userdom_struct current_user_info
;
30 /* look in server.c for some explanation of these variables */
31 static char msgbuf
[1600];
33 static fstring msgfrom
;
36 /****************************************************************************
38 ****************************************************************************/
39 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.
67 if ((len
= convert_string_allocate(NULL
,CH_DOS
, CH_UNIX
, msgbuf
, msgpos
, (void **) &msg
)) < 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') {
73 write(fd
, &msgbuf
[i
++], 1);
76 for (i
= 0; i
< len
;) {
77 if (msg
[i
] == '\r' && i
< (len
-1) && msg
[i
+1] == '\n') {
80 write(fd
, &msg
[i
++],1);
88 if (*lp_msg_command())
90 fstring alpha_msgfrom
;
94 pstrcpy(s
,lp_msg_command());
95 pstring_sub(s
,"%f",alpha_strcpy(alpha_msgfrom
,msgfrom
,NULL
,sizeof(alpha_msgfrom
)));
96 pstring_sub(s
,"%t",alpha_strcpy(alpha_msgto
,msgto
,NULL
,sizeof(alpha_msgto
)));
97 standard_sub_basic(current_user_info
.smb_name
, s
, sizeof(s
));
98 pstring_sub(s
,"%s",name
);
107 /****************************************************************************
109 ****************************************************************************/
110 int reply_sends(connection_struct
*conn
,
111 char *inbuf
,char *outbuf
, int dum_size
, int dum_buffsize
)
118 START_PROFILE(SMBsends
);
122 if (! (*lp_msg_command())) {
123 END_PROFILE(SMBsends
);
124 return(ERROR_DOS(ERRSRV
,ERRmsgoff
));
127 outsize
= set_message(outbuf
,0,0,True
);
129 p
= smb_buf(inbuf
)+1;
130 p
+= srvstr_pull_buf(inbuf
, msgfrom
, p
, sizeof(msgfrom
), STR_TERMINATE
) + 1;
131 p
+= srvstr_pull_buf(inbuf
, msgto
, p
, sizeof(msgto
), STR_TERMINATE
) + 1;
136 len
= MIN(len
,sizeof(msgbuf
)-msgpos
);
138 memset(msgbuf
,'\0',sizeof(msgbuf
));
140 memcpy(&msgbuf
[msgpos
],msg
+2,len
);
145 END_PROFILE(SMBsends
);
150 /****************************************************************************
152 ****************************************************************************/
153 int reply_sendstrt(connection_struct
*conn
,
154 char *inbuf
,char *outbuf
, int dum_size
, int dum_buffsize
)
159 START_PROFILE(SMBsendstrt
);
161 if (! (*lp_msg_command())) {
162 END_PROFILE(SMBsendstrt
);
163 return(ERROR_DOS(ERRSRV
,ERRmsgoff
));
166 outsize
= set_message(outbuf
,1,0,True
);
168 memset(msgbuf
,'\0',sizeof(msgbuf
));
171 p
= smb_buf(inbuf
)+1;
172 p
+= srvstr_pull_buf(inbuf
, msgfrom
, p
, sizeof(msgfrom
), STR_TERMINATE
) + 1;
173 p
+= srvstr_pull_buf(inbuf
, msgto
, p
, sizeof(msgto
), STR_TERMINATE
) + 1;
175 DEBUG( 3, ( "SMBsendstrt (from %s to %s)\n", msgfrom
, msgto
) );
177 END_PROFILE(SMBsendstrt
);
182 /****************************************************************************
184 ****************************************************************************/
185 int reply_sendtxt(connection_struct
*conn
,
186 char *inbuf
,char *outbuf
, int dum_size
, int dum_buffsize
)
191 START_PROFILE(SMBsendtxt
);
193 if (! (*lp_msg_command())) {
194 END_PROFILE(SMBsendtxt
);
195 return(ERROR_DOS(ERRSRV
,ERRmsgoff
));
198 outsize
= set_message(outbuf
,0,0,True
);
200 msg
= smb_buf(inbuf
) + 1;
203 len
= MIN(len
,sizeof(msgbuf
)-msgpos
);
205 memcpy(&msgbuf
[msgpos
],msg
+2,len
);
208 DEBUG( 3, ( "SMBsendtxt\n" ) );
210 END_PROFILE(SMBsendtxt
);
215 /****************************************************************************
217 ****************************************************************************/
218 int reply_sendend(connection_struct
*conn
,
219 char *inbuf
,char *outbuf
, int dum_size
, int dum_buffsize
)
222 START_PROFILE(SMBsendend
);
224 if (! (*lp_msg_command())) {
225 END_PROFILE(SMBsendend
);
226 return(ERROR_DOS(ERRSRV
,ERRmsgoff
));
229 outsize
= set_message(outbuf
,0,0,True
);
231 DEBUG(3,("SMBsendend\n"));
235 END_PROFILE(SMBsendend
);