1996-05-04 11:50:46 +04:00
/*
2002-01-30 09:08:46 +03:00
Unix SMB / CIFS implementation .
1996-05-04 11:50:46 +04:00
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
2007-07-09 23:25:36 +04:00
the Free Software Foundation ; either version 3 of the License , or
1996-05-04 11:50:46 +04:00
( 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
2007-07-10 04:52:41 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
1996-05-04 11:50:46 +04:00
*/
/*
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
/****************************************************************************
2006-06-20 06:38:28 +04:00
Deliver the message .
1996-05-04 11:50:46 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2006-06-20 06:38:28 +04:00
1996-05-04 11:50:46 +04:00
static void msg_deliver ( void )
{
2006-06-20 06:38:28 +04:00
pstring name ;
int i ;
int fd ;
char * msg ;
int len ;
ssize_t sz ;
if ( ! ( * lp_msg_command ( ) ) ) {
DEBUG ( 1 , ( " no messaging command specified \n " ) ) ;
msgpos = 0 ;
return ;
}
/* put it in a temporary file */
slprintf ( name , sizeof ( name ) - 1 , " %s/msg.XXXXXX " , tmpdir ( ) ) ;
fd = smb_mkstemp ( name ) ;
if ( fd = = - 1 ) {
DEBUG ( 1 , ( " can't open message file %s \n " , name ) ) ;
return ;
}
/*
* Incoming message is in DOS codepage format . Convert to UNIX .
*/
2003-03-20 19:44:14 +03:00
2006-06-20 06:38:28 +04:00
if ( ( len = ( int ) convert_string_allocate ( NULL , CH_DOS , CH_UNIX , msgbuf , msgpos , ( void * * ) ( void * ) & msg , True ) ) < 0 | | ! msg ) {
DEBUG ( 3 , ( " Conversion failed, delivering message in DOS codepage format \n " ) ) ;
for ( i = 0 ; i < msgpos ; ) {
if ( msgbuf [ i ] = = ' \r ' & & i < ( msgpos - 1 ) & & msgbuf [ i + 1 ] = = ' \n ' ) {
i + + ;
continue ;
}
sz = write ( fd , & msgbuf [ i + + ] , 1 ) ;
if ( sz ! = 1 ) {
DEBUG ( 0 , ( " Write error to fd %d: %ld(%d) \n " , fd , ( long ) sz , errno ) ) ;
}
}
} else {
for ( i = 0 ; i < len ; ) {
if ( msg [ i ] = = ' \r ' & & i < ( len - 1 ) & & msg [ i + 1 ] = = ' \n ' ) {
i + + ;
continue ;
}
sz = write ( fd , & msg [ i + + ] , 1 ) ;
if ( sz ! = 1 ) {
DEBUG ( 0 , ( " Write error to fd %d: %ld(%d) \n " , fd , ( long ) sz , errno ) ) ;
}
}
SAFE_FREE ( msg ) ;
}
close ( fd ) ;
/* run the command */
if ( * lp_msg_command ( ) ) {
fstring alpha_msgfrom ;
fstring alpha_msgto ;
pstring s ;
pstrcpy ( s , lp_msg_command ( ) ) ;
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 ) ) ) ;
2006-07-11 22:01:26 +04:00
standard_sub_basic ( current_user_info . smb_name ,
current_user_info . domain , s , sizeof ( s ) ) ;
2006-06-20 06:38:28 +04:00
pstring_sub ( s , " %s " , name ) ;
smbrun ( s , NULL ) ;
}
msgpos = 0 ;
1996-05-04 11:50:46 +04:00
}
/****************************************************************************
2006-06-20 06:38:28 +04:00
Reply to a sends .
conn POINTER CAN BE NULL HERE !
1996-05-04 11:50:46 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2006-06-20 06:38:28 +04:00
2007-08-15 01:07:44 +04:00
void reply_sends ( connection_struct * conn , struct smb_request * req )
1996-05-04 11:50:46 +04:00
{
2006-06-20 06:38:28 +04:00
int len ;
char * msg ;
char * p ;
2001-03-14 14:55:08 +03:00
2006-06-20 06:38:28 +04:00
START_PROFILE ( SMBsends ) ;
1996-05-04 11:50:46 +04:00
2006-06-20 06:38:28 +04:00
msgpos = 0 ;
1996-05-04 11:50:46 +04:00
2006-06-20 06:38:28 +04:00
if ( ! ( * lp_msg_command ( ) ) ) {
2007-08-15 01:07:44 +04:00
reply_doserror ( req , ERRSRV , ERRmsgoff ) ;
2006-06-20 06:38:28 +04:00
END_PROFILE ( SMBsends ) ;
2007-08-15 01:07:44 +04:00
return ;
2006-06-20 06:38:28 +04:00
}
1996-05-04 11:50:46 +04:00
2007-08-15 01:07:44 +04:00
p = smb_buf ( req - > inbuf ) + 1 ;
p + = srvstr_pull_buf ( ( char * ) req - > inbuf , req - > flags2 , msgfrom , p ,
2007-07-05 20:33:37 +04:00
sizeof ( msgfrom ) , STR_ASCII | STR_TERMINATE ) + 1 ;
2007-08-15 01:07:44 +04:00
p + = srvstr_pull_buf ( ( char * ) req - > inbuf , req - > flags2 , msgto , p ,
2007-07-05 20:33:37 +04:00
sizeof ( msgto ) , STR_ASCII | STR_TERMINATE ) + 1 ;
1996-05-04 11:50:46 +04:00
2006-06-20 06:38:28 +04:00
msg = p ;
1996-05-04 11:50:46 +04:00
2006-06-20 06:38:28 +04:00
len = SVAL ( msg , 0 ) ;
len = MIN ( len , sizeof ( msgbuf ) - msgpos ) ;
1999-12-13 16:27:58 +03:00
2006-06-20 06:38:28 +04:00
memset ( msgbuf , ' \0 ' , sizeof ( msgbuf ) ) ;
1996-05-04 11:50:46 +04:00
2006-06-20 06:38:28 +04:00
memcpy ( & msgbuf [ msgpos ] , msg + 2 , len ) ;
msgpos + = len ;
1996-05-04 11:50:46 +04:00
2006-06-20 06:38:28 +04:00
msg_deliver ( ) ;
1996-05-04 11:50:46 +04:00
2007-08-15 01:07:44 +04:00
reply_outbuf ( req , 0 , 0 ) ;
2006-06-20 06:38:28 +04:00
END_PROFILE ( SMBsends ) ;
2007-08-15 01:07:44 +04:00
return ;
1996-05-04 11:50:46 +04:00
}
/****************************************************************************
2006-06-20 06:38:28 +04:00
Reply to a sendstrt .
conn POINTER CAN BE NULL HERE !
1996-05-04 11:50:46 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2006-06-20 06:38:28 +04:00
2007-08-15 01:07:44 +04:00
void reply_sendstrt ( connection_struct * conn , struct smb_request * req )
1996-05-04 11:50:46 +04:00
{
2006-06-20 06:38:28 +04:00
char * p ;
2001-03-14 14:55:08 +03:00
2006-06-20 06:38:28 +04:00
START_PROFILE ( SMBsendstrt ) ;
1996-05-04 11:50:46 +04:00
2006-06-20 06:38:28 +04:00
if ( ! ( * lp_msg_command ( ) ) ) {
2007-08-15 01:07:44 +04:00
reply_doserror ( req , ERRSRV , ERRmsgoff ) ;
2006-06-20 06:38:28 +04:00
END_PROFILE ( SMBsendstrt ) ;
2007-08-15 01:07:44 +04:00
return ;
2006-06-20 06:38:28 +04:00
}
1996-05-04 11:50:46 +04:00
2006-06-20 06:38:28 +04:00
memset ( msgbuf , ' \0 ' , sizeof ( msgbuf ) ) ;
msgpos = 0 ;
1996-05-04 11:50:46 +04:00
2007-08-15 01:07:44 +04:00
p = smb_buf ( req - > inbuf ) + 1 ;
p + = srvstr_pull_buf ( ( char * ) req - > inbuf , req - > flags2 , msgfrom , p ,
2007-07-05 20:33:37 +04:00
sizeof ( msgfrom ) , STR_ASCII | STR_TERMINATE ) + 1 ;
2007-08-15 01:07:44 +04:00
p + = srvstr_pull_buf ( ( char * ) req - > inbuf , req - > flags2 , msgto , p ,
2007-07-05 20:33:37 +04:00
sizeof ( msgto ) , STR_ASCII | STR_TERMINATE ) + 1 ;
1996-05-04 11:50:46 +04:00
2006-06-20 06:38:28 +04:00
DEBUG ( 3 , ( " SMBsendstrt (from %s to %s) \n " , msgfrom , msgto ) ) ;
1996-05-04 11:50:46 +04:00
2007-08-15 01:07:44 +04:00
reply_outbuf ( req , 0 , 0 ) ;
2006-06-20 06:38:28 +04:00
END_PROFILE ( SMBsendstrt ) ;
2007-08-15 01:07:44 +04:00
return ;
1996-05-04 11:50:46 +04:00
}
/****************************************************************************
2006-06-20 06:38:28 +04:00
Reply to a sendtxt .
conn POINTER CAN BE NULL HERE !
1996-05-04 11:50:46 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2006-06-20 06:38:28 +04:00
2007-08-15 01:07:44 +04:00
void reply_sendtxt ( connection_struct * conn , struct smb_request * req )
1996-05-04 11:50:46 +04:00
{
2006-06-20 06:38:28 +04:00
int len ;
char * msg ;
START_PROFILE ( SMBsendtxt ) ;
1996-05-04 11:50:46 +04:00
2006-06-20 06:38:28 +04:00
if ( ! ( * lp_msg_command ( ) ) ) {
2007-08-15 01:07:44 +04:00
reply_doserror ( req , ERRSRV , ERRmsgoff ) ;
2006-06-20 06:38:28 +04:00
END_PROFILE ( SMBsendtxt ) ;
2007-08-15 01:07:44 +04:00
return ;
2006-06-20 06:38:28 +04:00
}
1996-05-04 11:50:46 +04:00
2007-08-15 01:07:44 +04:00
msg = smb_buf ( req - > inbuf ) + 1 ;
1996-05-04 11:50:46 +04:00
2006-06-20 06:38:28 +04:00
len = SVAL ( msg , 0 ) ;
len = MIN ( len , sizeof ( msgbuf ) - msgpos ) ;
1996-05-04 11:50:46 +04:00
2006-06-20 06:38:28 +04:00
memcpy ( & msgbuf [ msgpos ] , msg + 2 , len ) ;
msgpos + = len ;
1996-05-04 11:50:46 +04:00
2006-06-20 06:38:28 +04:00
DEBUG ( 3 , ( " SMBsendtxt \n " ) ) ;
1996-05-04 11:50:46 +04:00
2007-08-15 01:07:44 +04:00
reply_outbuf ( req , 0 , 0 ) ;
2006-06-20 06:38:28 +04:00
END_PROFILE ( SMBsendtxt ) ;
2007-08-15 01:07:44 +04:00
return ;
1996-05-04 11:50:46 +04:00
}
/****************************************************************************
2006-06-20 06:38:28 +04:00
Reply to a sendend .
conn POINTER CAN BE NULL HERE !
1996-05-04 11:50:46 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2006-06-20 06:38:28 +04:00
2007-08-15 01:07:44 +04:00
void reply_sendend ( connection_struct * conn , struct smb_request * req )
1996-05-04 11:50:46 +04:00
{
2006-06-20 06:38:28 +04:00
START_PROFILE ( SMBsendend ) ;
1996-05-04 11:50:46 +04:00
2006-06-20 06:38:28 +04:00
if ( ! ( * lp_msg_command ( ) ) ) {
2007-08-15 01:07:44 +04:00
reply_doserror ( req , ERRSRV , ERRmsgoff ) ;
2006-06-20 06:38:28 +04:00
END_PROFILE ( SMBsendend ) ;
2007-08-15 01:07:44 +04:00
return ;
2006-06-20 06:38:28 +04:00
}
1996-05-04 11:50:46 +04:00
2006-06-20 06:38:28 +04:00
DEBUG ( 3 , ( " SMBsendend \n " ) ) ;
1996-05-04 11:50:46 +04:00
2006-06-20 06:38:28 +04:00
msg_deliver ( ) ;
1996-05-04 11:50:46 +04:00
2007-08-15 01:07:44 +04:00
reply_outbuf ( req , 0 , 0 ) ;
2006-06-20 06:38:28 +04:00
END_PROFILE ( SMBsendend ) ;
2007-08-15 01:07:44 +04:00
return ;
1996-05-04 11:50:46 +04:00
}