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 ****************************************************************************/
40 static void msg_deliver(void)
49 if (! (*lp_msg_command())) {
50 DEBUG(1,("no messaging command specified\n"));
55 /* put it in a temporary file */
56 slprintf(name
,sizeof(name
)-1, "%s/msg.XXXXXX",tmpdir());
57 fd
= smb_mkstemp(name
);
60 DEBUG(1,("can't open message file %s\n",name
));
65 * Incoming message is in DOS codepage format. Convert to UNIX.
68 if ((len
= (int)convert_string_allocate(NULL
,CH_DOS
, CH_UNIX
, msgbuf
, msgpos
, (void **)(void *)&msg
, True
)) < 0 || !msg
) {
69 DEBUG(3,("Conversion failed, delivering message in DOS codepage format\n"));
70 for (i
= 0; i
< msgpos
;) {
71 if (msgbuf
[i
] == '\r' && i
< (msgpos
-1) && msgbuf
[i
+1] == '\n') {
75 sz
= write(fd
, &msgbuf
[i
++], 1);
77 DEBUG(0,("Write error to fd %d: %ld(%d)\n",fd
, (long)sz
, errno
));
81 for (i
= 0; i
< len
;) {
82 if (msg
[i
] == '\r' && i
< (len
-1) && msg
[i
+1] == '\n') {
86 sz
= write(fd
, &msg
[i
++],1);
88 DEBUG(0,("Write error to fd %d: %ld(%d)\n",fd
, (long)sz
, errno
));
96 if (*lp_msg_command()) {
97 fstring alpha_msgfrom
;
101 pstrcpy(s
,lp_msg_command());
102 pstring_sub(s
,"%f",alpha_strcpy(alpha_msgfrom
,msgfrom
,NULL
,sizeof(alpha_msgfrom
)));
103 pstring_sub(s
,"%t",alpha_strcpy(alpha_msgto
,msgto
,NULL
,sizeof(alpha_msgto
)));
104 standard_sub_basic(current_user_info
.smb_name
,
105 current_user_info
.domain
, s
, sizeof(s
));
106 pstring_sub(s
,"%s",name
);
113 /****************************************************************************
115 conn POINTER CAN BE NULL HERE !
116 ****************************************************************************/
118 int reply_sends(connection_struct
*conn
, char *inbuf
,char *outbuf
, int dum_size
, int dum_buffsize
)
125 START_PROFILE(SMBsends
);
129 if (! (*lp_msg_command())) {
130 END_PROFILE(SMBsends
);
131 return(ERROR_DOS(ERRSRV
,ERRmsgoff
));
134 outsize
= set_message(outbuf
,0,0,True
);
136 p
= smb_buf(inbuf
)+1;
137 p
+= srvstr_pull_buf(inbuf
, msgfrom
, p
, sizeof(msgfrom
), STR_ASCII
|STR_TERMINATE
) + 1;
138 p
+= srvstr_pull_buf(inbuf
, msgto
, p
, sizeof(msgto
), STR_ASCII
|STR_TERMINATE
) + 1;
143 len
= MIN(len
,sizeof(msgbuf
)-msgpos
);
145 memset(msgbuf
,'\0',sizeof(msgbuf
));
147 memcpy(&msgbuf
[msgpos
],msg
+2,len
);
152 END_PROFILE(SMBsends
);
156 /****************************************************************************
158 conn POINTER CAN BE NULL HERE !
159 ****************************************************************************/
161 int reply_sendstrt(connection_struct
*conn
, char *inbuf
,char *outbuf
, int dum_size
, int dum_buffsize
)
166 START_PROFILE(SMBsendstrt
);
168 if (! (*lp_msg_command())) {
169 END_PROFILE(SMBsendstrt
);
170 return(ERROR_DOS(ERRSRV
,ERRmsgoff
));
173 outsize
= set_message(outbuf
,1,0,True
);
175 memset(msgbuf
,'\0',sizeof(msgbuf
));
178 p
= smb_buf(inbuf
)+1;
179 p
+= srvstr_pull_buf(inbuf
, msgfrom
, p
, sizeof(msgfrom
), STR_ASCII
|STR_TERMINATE
) + 1;
180 p
+= srvstr_pull_buf(inbuf
, msgto
, p
, sizeof(msgto
), STR_ASCII
|STR_TERMINATE
) + 1;
182 DEBUG( 3, ( "SMBsendstrt (from %s to %s)\n", msgfrom
, msgto
) );
184 END_PROFILE(SMBsendstrt
);
188 /****************************************************************************
190 conn POINTER CAN BE NULL HERE !
191 ****************************************************************************/
193 int reply_sendtxt(connection_struct
*conn
, char *inbuf
,char *outbuf
, int dum_size
, int dum_buffsize
)
198 START_PROFILE(SMBsendtxt
);
200 if (! (*lp_msg_command())) {
201 END_PROFILE(SMBsendtxt
);
202 return(ERROR_DOS(ERRSRV
,ERRmsgoff
));
205 outsize
= set_message(outbuf
,0,0,True
);
207 msg
= smb_buf(inbuf
) + 1;
210 len
= MIN(len
,sizeof(msgbuf
)-msgpos
);
212 memcpy(&msgbuf
[msgpos
],msg
+2,len
);
215 DEBUG( 3, ( "SMBsendtxt\n" ) );
217 END_PROFILE(SMBsendtxt
);
221 /****************************************************************************
223 conn POINTER CAN BE NULL HERE !
224 ****************************************************************************/
226 int reply_sendend(connection_struct
*conn
, char *inbuf
,char *outbuf
, int dum_size
, int dum_buffsize
)
229 START_PROFILE(SMBsendend
);
231 if (! (*lp_msg_command())) {
232 END_PROFILE(SMBsendend
);
233 return(ERROR_DOS(ERRSRV
,ERRmsgoff
));
236 outsize
= set_message(outbuf
,0,0,True
);
238 DEBUG(3,("SMBsendend\n"));
242 END_PROFILE(SMBsendend
);