1996-05-04 11:50:46 +04:00
/*
Unix SMB / Netbios implementation .
Version 1.9 .
SMB messaging
1998-01-22 16:27:43 +03:00
Copyright ( C ) Andrew Tridgell 1992 - 1998
1996-05-04 11:50:46 +04:00
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation ; either version 2 of the License , or
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program ; if not , write to the Free Software
Foundation , Inc . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
*/
/*
This file handles the messaging system calls for winpopup style
messages
*/
# include "includes.h"
/* look in server.c for some explanation of these variables */
extern int DEBUGLEVEL ;
static char msgbuf [ 1600 ] ;
static int msgpos = 0 ;
static fstring msgfrom = " " ;
static fstring msgto = " " ;
/****************************************************************************
deliver the message
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static void msg_deliver ( void )
{
pstring s ;
fstring name ;
int i ;
1996-10-04 13:31:07 +04:00
int fd ;
1996-05-04 11:50:46 +04:00
if ( ! ( * lp_msg_command ( ) ) )
{
DEBUG ( 1 , ( " no messaging command specified \n " ) ) ;
msgpos = 0 ;
return ;
}
/* put it in a temporary file */
1998-05-11 10:38:36 +04:00
slprintf ( s , sizeof ( s ) - 1 , " %s/msg.XXXXXX " , tmpdir ( ) ) ;
1999-12-13 16:27:58 +03:00
fstrcpy ( name , ( char * ) smbd_mktemp ( s ) ) ;
1996-05-04 11:50:46 +04:00
1998-11-17 23:50:07 +03:00
fd = sys_open ( name , O_WRONLY | O_CREAT | O_TRUNC | O_EXCL , 0600 ) ;
1996-10-04 13:31:07 +04:00
if ( fd = = - 1 ) {
DEBUG ( 1 , ( " can't open message file %s \n " , name ) ) ;
return ;
}
1996-05-04 11:50:46 +04:00
2000-01-27 04:09:21 +03:00
/*
* Incoming message is in DOS codepage format . Convert to UNIX in
* place .
*/
if ( msgpos > 0 ) {
msgbuf [ msgpos ] = ' \0 ' ; /* Ensure null terminated. */
dos_to_unix ( msgbuf , True ) ;
}
1996-10-04 13:31:07 +04:00
for ( i = 0 ; i < msgpos ; ) {
if ( msgbuf [ i ] = = ' \r ' & & i < ( msgpos - 1 ) & & msgbuf [ i + 1 ] = = ' \n ' ) {
i + + ; continue ;
1996-05-04 11:50:46 +04:00
}
1996-10-04 13:31:07 +04:00
write ( fd , & msgbuf [ i + + ] , 1 ) ;
}
close ( fd ) ;
1996-05-04 11:50:46 +04:00
/* run the command */
if ( * lp_msg_command ( ) )
{
1999-12-13 16:27:58 +03:00
fstring alpha_msgfrom ;
fstring alpha_msgto ;
1997-09-26 22:55:29 +04:00
pstrcpy ( s , lp_msg_command ( ) ) ;
1999-12-13 16:27:58 +03:00
pstring_sub ( s , " %s " , name ) ;
pstring_sub ( s , " %f " , alpha_strcpy ( alpha_msgfrom , msgfrom , sizeof ( alpha_msgfrom ) ) ) ;
pstring_sub ( s , " %t " , alpha_strcpy ( alpha_msgto , msgto , sizeof ( alpha_msgto ) ) ) ;
1998-08-14 21:38:29 +04:00
standard_sub_basic ( s ) ;
1996-10-04 13:31:07 +04:00
smbrun ( s , NULL , False ) ;
1996-05-04 11:50:46 +04:00
}
msgpos = 0 ;
}
/****************************************************************************
reply to a sends
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1998-08-14 21:38:29 +04:00
int reply_sends ( connection_struct * conn ,
char * inbuf , char * outbuf , int dum_size , int dum_buffsize )
1996-05-04 11:50:46 +04:00
{
int len ;
char * orig , * dest , * msg ;
int outsize = 0 ;
2000-10-11 09:31:39 +04:00
START_PROFILE ( SMBsends ) ;
1996-05-04 11:50:46 +04:00
msgpos = 0 ;
2000-10-11 09:31:39 +04:00
if ( ! ( * lp_msg_command ( ) ) ) {
END_PROFILE ( SMBsends ) ;
1996-05-04 11:50:46 +04:00
return ( ERROR ( ERRSRV , ERRmsgoff ) ) ;
2000-10-11 09:31:39 +04:00
}
1996-05-04 11:50:46 +04:00
outsize = set_message ( outbuf , 0 , 0 , True ) ;
orig = smb_buf ( inbuf ) + 1 ;
dest = skip_string ( orig , 1 ) + 1 ;
msg = skip_string ( dest , 1 ) + 1 ;
1997-09-26 22:55:29 +04:00
fstrcpy ( msgfrom , orig ) ;
fstrcpy ( msgto , dest ) ;
1996-05-04 11:50:46 +04:00
len = SVAL ( msg , 0 ) ;
1999-12-13 16:27:58 +03:00
len = MIN ( len , sizeof ( msgbuf ) - msgpos ) ;
memset ( msgbuf , ' \0 ' , sizeof ( msgbuf ) ) ;
1996-05-04 11:50:46 +04:00
memcpy ( & msgbuf [ msgpos ] , msg + 2 , len ) ;
msgpos + = len ;
1998-08-01 02:39:15 +04:00
DEBUG ( 3 , ( " SMBsends (from %s to %s) \n " , orig , dest ) ) ;
1996-05-04 11:50:46 +04:00
msg_deliver ( ) ;
2000-10-11 09:31:39 +04:00
END_PROFILE ( SMBsends ) ;
1996-05-04 11:50:46 +04:00
return ( outsize ) ;
}
/****************************************************************************
reply to a sendstrt
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1998-08-14 21:38:29 +04:00
int reply_sendstrt ( connection_struct * conn ,
char * inbuf , char * outbuf , int dum_size , int dum_buffsize )
1996-05-04 11:50:46 +04:00
{
char * orig , * dest ;
int outsize = 0 ;
2000-10-11 09:31:39 +04:00
START_PROFILE ( SMBsendstrt ) ;
1996-05-04 11:50:46 +04:00
2000-10-11 09:31:39 +04:00
if ( ! ( * lp_msg_command ( ) ) ) {
END_PROFILE ( SMBsendstrt ) ;
1996-05-04 11:50:46 +04:00
return ( ERROR ( ERRSRV , ERRmsgoff ) ) ;
2000-10-11 09:31:39 +04:00
}
1996-05-04 11:50:46 +04:00
outsize = set_message ( outbuf , 1 , 0 , True ) ;
1999-12-13 16:27:58 +03:00
memset ( msgbuf , ' \0 ' , sizeof ( msgbuf ) ) ;
1996-05-04 11:50:46 +04:00
msgpos = 0 ;
orig = smb_buf ( inbuf ) + 1 ;
dest = skip_string ( orig , 1 ) + 1 ;
1997-09-26 22:55:29 +04:00
fstrcpy ( msgfrom , orig ) ;
fstrcpy ( msgto , dest ) ;
1996-05-04 11:50:46 +04:00
1998-08-01 02:39:15 +04:00
DEBUG ( 3 , ( " SMBsendstrt (from %s to %s) \n " , msgfrom , msgto ) ) ;
1996-05-04 11:50:46 +04:00
2000-10-11 09:31:39 +04:00
END_PROFILE ( SMBsendstrt ) ;
1996-05-04 11:50:46 +04:00
return ( outsize ) ;
}
/****************************************************************************
reply to a sendtxt
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1998-08-14 21:38:29 +04:00
int reply_sendtxt ( connection_struct * conn ,
char * inbuf , char * outbuf , int dum_size , int dum_buffsize )
1996-05-04 11:50:46 +04:00
{
int len ;
int outsize = 0 ;
char * msg ;
2000-10-11 09:31:39 +04:00
START_PROFILE ( SMBsendtxt ) ;
1996-05-04 11:50:46 +04:00
2000-10-11 09:31:39 +04:00
if ( ! ( * lp_msg_command ( ) ) ) {
END_PROFILE ( SMBsendtxt ) ;
1996-05-04 11:50:46 +04:00
return ( ERROR ( ERRSRV , ERRmsgoff ) ) ;
2000-10-11 09:31:39 +04:00
}
1996-05-04 11:50:46 +04:00
outsize = set_message ( outbuf , 0 , 0 , True ) ;
msg = smb_buf ( inbuf ) + 1 ;
len = SVAL ( msg , 0 ) ;
1999-12-13 16:27:58 +03:00
len = MIN ( len , sizeof ( msgbuf ) - msgpos ) ;
1996-05-04 11:50:46 +04:00
memcpy ( & msgbuf [ msgpos ] , msg + 2 , len ) ;
msgpos + = len ;
1998-08-01 02:39:15 +04:00
DEBUG ( 3 , ( " SMBsendtxt \n " ) ) ;
1996-05-04 11:50:46 +04:00
2000-10-11 09:31:39 +04:00
END_PROFILE ( SMBsendtxt ) ;
1996-05-04 11:50:46 +04:00
return ( outsize ) ;
}
/****************************************************************************
reply to a sendend
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1998-08-14 21:38:29 +04:00
int reply_sendend ( connection_struct * conn ,
char * inbuf , char * outbuf , int dum_size , int dum_buffsize )
1996-05-04 11:50:46 +04:00
{
int outsize = 0 ;
2000-10-11 09:31:39 +04:00
START_PROFILE ( SMBsendend ) ;
1996-05-04 11:50:46 +04:00
2000-10-11 09:31:39 +04:00
if ( ! ( * lp_msg_command ( ) ) ) {
END_PROFILE ( SMBsendend ) ;
1996-05-04 11:50:46 +04:00
return ( ERROR ( ERRSRV , ERRmsgoff ) ) ;
2000-10-11 09:31:39 +04:00
}
1996-05-04 11:50:46 +04:00
outsize = set_message ( outbuf , 0 , 0 , True ) ;
1998-08-14 21:38:29 +04:00
DEBUG ( 3 , ( " SMBsendend \n " ) ) ;
1996-05-04 11:50:46 +04:00
msg_deliver ( ) ;
2000-10-11 09:31:39 +04:00
END_PROFILE ( SMBsendend ) ;
1996-05-04 11:50:46 +04:00
return ( outsize ) ;
}