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"
2001-12-06 16:09:15 +03:00
extern userdom_struct current_user_info ;
1996-05-04 11:50:46 +04:00
/* look in server.c for some explanation of these variables */
static char msgbuf [ 1600 ] ;
2001-03-14 14:55:08 +03:00
static int msgpos ;
static fstring msgfrom ;
static fstring msgto ;
1996-05-04 11:50:46 +04:00
/****************************************************************************
deliver the message
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static void msg_deliver ( void )
{
2001-04-12 03:19:08 +04:00
pstring name ;
1996-05-04 11:50:46 +04:00
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 */
2001-04-12 03:19:08 +04:00
slprintf ( name , sizeof ( name ) - 1 , " %s/msg.XXXXXX " , tmpdir ( ) ) ;
fd = smb_mkstemp ( name ) ;
1996-05-04 11:50:46 +04:00
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
/*
2001-06-21 05:01:15 +04:00
* Incoming message is in DOS codepage format . Convert to UNIX .
2000-01-27 04:09:21 +03:00
*/
if ( msgpos > 0 ) {
msgbuf [ msgpos ] = ' \0 ' ; /* Ensure null terminated. */
}
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 ;
2001-04-12 03:19:08 +04:00
pstring s ;
1999-12-13 16:27:58 +03:00
1997-09-26 22:55:29 +04:00
pstrcpy ( s , lp_msg_command ( ) ) ;
2001-06-23 11:22:16 +04:00
pstring_sub ( s , " %f " , alpha_strcpy ( alpha_msgfrom , msgfrom , NULL , sizeof ( alpha_msgfrom ) ) ) ;
pstring_sub ( s , " %t " , alpha_strcpy ( alpha_msgto , msgto , NULL , sizeof ( alpha_msgto ) ) ) ;
2001-12-06 16:09:15 +03:00
standard_sub_basic ( current_user_info . smb_name , s ) ;
2001-04-12 03:19:08 +04:00
pstring_sub ( s , " %s " , name ) ;
2001-04-13 23:12:06 +04:00
smbrun ( s , NULL ) ;
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 ;
2001-03-14 14:55:08 +03:00
char * msg ;
1996-05-04 11:50:46 +04:00
int outsize = 0 ;
2001-03-14 14:55:08 +03:00
char * p ;
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 ) ;
2001-08-27 12:19:43 +04:00
return ( ERROR_DOS ( 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 ) ;
2001-03-14 14:55:08 +03:00
p = smb_buf ( inbuf ) + 1 ;
2001-07-04 11:15:53 +04:00
p + = srvstr_pull ( inbuf , msgfrom , p , sizeof ( msgfrom ) , - 1 , STR_TERMINATE ) + 1 ;
p + = srvstr_pull ( inbuf , msgto , p , sizeof ( msgto ) , - 1 , STR_TERMINATE ) + 1 ;
1996-05-04 11:50:46 +04:00
2001-03-14 14:55:08 +03:00
msg = p ;
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 ;
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
{
int outsize = 0 ;
2001-03-14 14:55:08 +03:00
char * p ;
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 ) ;
2001-08-27 12:19:43 +04:00
return ( ERROR_DOS ( 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 ;
2001-03-14 14:55:08 +03:00
p = smb_buf ( inbuf ) + 1 ;
2001-07-04 11:15:53 +04:00
p + = srvstr_pull ( inbuf , msgfrom , p , sizeof ( msgfrom ) , - 1 , STR_TERMINATE ) + 1 ;
p + = srvstr_pull ( inbuf , msgto , p , sizeof ( msgto ) , - 1 , STR_TERMINATE ) + 1 ;
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 ) ;
2001-08-27 12:19:43 +04:00
return ( ERROR_DOS ( 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 ) ;
2001-08-27 12:19:43 +04:00
return ( ERROR_DOS ( 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 ) ;
}