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"
2013-02-25 20:34:21 +04:00
# include "system/filesys.h"
2011-03-22 18:57:01 +03:00
# include "smbd/smbd.h"
2009-01-08 14:03:45 +03:00
# include "smbd/globals.h"
2011-04-14 02:36:23 +04:00
# include "smbprofile.h"
2021-11-10 22:18:07 +03:00
# include "source3/lib/substitute.h"
1996-05-04 11:50:46 +04:00
2007-12-09 15:45:10 +03:00
struct msg_state {
char * from ;
char * to ;
char * msg ;
} ;
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
2007-12-09 15:45:10 +03:00
static void msg_deliver ( struct msg_state * state )
1996-05-04 11:50:46 +04:00
{
2007-12-09 15:45:10 +03:00
TALLOC_CTX * frame = talloc_stackframe ( ) ;
2019-11-05 12:59:40 +03:00
const struct loadparm_substitution * lp_sub =
loadparm_s3_global_substitution ( ) ;
2007-11-13 23:51:31 +03:00
char * name = NULL ;
2006-06-20 06:38:28 +04:00
int i ;
int fd ;
char * msg ;
2008-04-30 01:36:24 +04:00
size_t len ;
2006-06-20 06:38:28 +04:00
ssize_t sz ;
2007-12-09 15:45:10 +03:00
fstring alpha_buf ;
char * s ;
2013-02-25 20:34:21 +04:00
mode_t mask ;
2006-06-20 06:38:28 +04:00
2019-11-05 12:59:40 +03:00
if ( ! ( * lp_message_command ( frame , lp_sub ) ) ) {
2006-06-20 06:38:28 +04:00
DEBUG ( 1 , ( " no messaging command specified \n " ) ) ;
2007-12-09 15:45:10 +03:00
goto done ;
2006-06-20 06:38:28 +04:00
}
/* put it in a temporary file */
2007-12-09 15:45:10 +03:00
name = talloc_asprintf ( talloc_tos ( ) , " %s/msg.XXXXXX " , tmpdir ( ) ) ;
2007-11-13 23:51:31 +03:00
if ( ! name ) {
2007-12-09 15:45:10 +03:00
goto done ;
2007-11-13 23:51:31 +03:00
}
2013-02-25 20:34:21 +04:00
mask = umask ( S_IRWXO | S_IRWXG ) ;
2009-04-21 01:58:26 +04:00
fd = mkstemp ( name ) ;
2013-02-25 20:34:21 +04:00
umask ( mask ) ;
2006-06-20 06:38:28 +04:00
if ( fd = = - 1 ) {
2007-12-09 15:45:10 +03:00
DEBUG ( 1 , ( " can't open message file %s: %s \n " , name ,
strerror ( errno ) ) ) ;
goto done ;
2006-06-20 06:38:28 +04:00
}
/*
* Incoming message is in DOS codepage format . Convert to UNIX .
*/
2007-11-13 23:51:31 +03:00
2008-04-30 01:36:24 +04:00
if ( ! convert_string_talloc ( talloc_tos ( ) , CH_DOS , CH_UNIX , state - > msg ,
talloc_get_size ( state - > msg ) , ( void * ) & msg ,
2011-03-24 02:59:41 +03:00
& len ) ) {
2007-12-09 15:45:10 +03:00
DEBUG ( 3 , ( " Conversion failed, delivering message in DOS "
" codepage format \n " ) ) ;
msg = state - > msg ;
}
for ( i = 0 ; i < len ; i + + ) {
2008-04-30 01:36:24 +04:00
if ( ( msg [ i ] = = ' \r ' ) & &
( i < ( len - 1 ) ) & & ( msg [ i + 1 ] = = ' \n ' ) ) {
2007-12-09 15:45:10 +03:00
continue ;
2006-06-20 06:38:28 +04:00
}
2007-12-09 15:45:10 +03:00
sz = write ( fd , & msg [ i ] , 1 ) ;
if ( sz ! = 1 ) {
DEBUG ( 0 , ( " Write error to fd %d: %ld(%s) \n " , fd ,
( long ) sz , strerror ( errno ) ) ) ;
2006-06-20 06:38:28 +04:00
}
}
2007-12-09 15:45:10 +03:00
2006-06-20 06:38:28 +04:00
close ( fd ) ;
/* run the command */
2019-11-05 12:59:40 +03:00
s = lp_message_command ( frame , lp_sub ) ;
2007-12-09 15:45:10 +03:00
if ( s = = NULL ) {
goto done ;
}
alpha_strcpy ( alpha_buf , state - > from , NULL , sizeof ( alpha_buf ) ) ;
s = talloc_string_sub ( talloc_tos ( ) , s , " %f " , alpha_buf ) ;
if ( s = = NULL ) {
goto done ;
}
alpha_strcpy ( alpha_buf , state - > to , NULL , sizeof ( alpha_buf ) ) ;
s = talloc_string_sub ( talloc_tos ( ) , s , " %t " , alpha_buf ) ;
if ( s = = NULL ) {
goto done ;
2006-06-20 06:38:28 +04:00
}
2022-11-30 20:47:21 +03:00
s = talloc_sub_basic ( talloc_tos ( ) , get_current_username ( ) ,
2022-11-30 20:45:06 +03:00
get_current_user_info_domain ( ) , s ) ;
2007-12-09 15:45:10 +03:00
if ( s = = NULL ) {
goto done ;
}
s = talloc_string_sub ( talloc_tos ( ) , s , " %s " , name ) ;
if ( s = = NULL ) {
goto done ;
}
2016-10-12 18:55:15 +03:00
smbrun ( s , NULL , NULL ) ;
2007-12-09 15:45:10 +03:00
done :
TALLOC_FREE ( frame ) ;
return ;
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
2008-01-05 02:37:24 +03:00
void reply_sends ( struct smb_request * req )
1996-05-04 11:50:46 +04:00
{
2019-11-05 12:59:40 +03:00
const struct loadparm_substitution * lp_sub =
loadparm_s3_global_substitution ( ) ;
2007-12-09 15:45:10 +03:00
struct msg_state * state ;
2006-06-20 06:38:28 +04:00
int len ;
2014-02-26 23:16:26 +04:00
const uint8_t * msg ;
const uint8_t * 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
2019-11-05 12:59:40 +03:00
if ( ! ( * lp_message_command ( talloc_tos ( ) , lp_sub ) ) ) {
2009-12-21 22:05:25 +03:00
reply_nterror ( req , NT_STATUS_REQUEST_NOT_ACCEPTED ) ;
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
2023-08-11 20:52:31 +03:00
state = talloc_zero ( talloc_tos ( ) , struct msg_state ) ;
2007-12-09 15:45:10 +03:00
2014-02-26 23:16:26 +04:00
p = req - > buf + 1 ;
2008-11-02 03:07:46 +03:00
p + = srvstr_pull_req_talloc (
state , req , & state - > from , p , STR_ASCII | STR_TERMINATE ) + 1 ;
p + = srvstr_pull_req_talloc (
state , req , & state - > to , p , 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 ) ;
2008-11-02 03:21:53 +03:00
len = MIN ( len , smbreq_bufrem ( req , msg + 2 ) ) ;
1999-12-13 16:27:58 +03:00
2007-12-09 15:45:10 +03:00
state - > msg = talloc_array ( state , char , len ) ;
1996-05-04 11:50:46 +04:00
2007-12-09 15:45:10 +03:00
if ( state - > msg = = NULL ) {
reply_nterror ( req , NT_STATUS_NO_MEMORY ) ;
END_PROFILE ( SMBsends ) ;
return ;
}
memcpy ( state - > msg , msg + 2 , len ) ;
1996-05-04 11:50:46 +04:00
2007-12-09 15:45:10 +03:00
msg_deliver ( state ) ;
1996-05-04 11:50:46 +04:00
2022-04-05 05:53:20 +03:00
reply_smb1_outbuf ( req , 0 , 0 ) ;
2007-08-15 01:07:44 +04:00
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
2008-01-05 02:37:24 +03:00
void reply_sendstrt ( struct smb_request * req )
1996-05-04 11:50:46 +04:00
{
2019-11-05 12:59:40 +03:00
const struct loadparm_substitution * lp_sub =
loadparm_s3_global_substitution ( ) ;
2014-06-11 14:36:14 +04:00
struct smbXsrv_connection * xconn = req - > xconn ;
2014-02-26 23:16:26 +04:00
const uint8_t * 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
2019-11-05 12:59:40 +03:00
if ( ! ( * lp_message_command ( talloc_tos ( ) , lp_sub ) ) ) {
2009-12-21 22:05:25 +03:00
reply_nterror ( req , NT_STATUS_REQUEST_NOT_ACCEPTED ) ;
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
2014-06-11 14:36:14 +04:00
TALLOC_FREE ( xconn - > smb1 . msg_state ) ;
2007-12-09 15:45:10 +03:00
2014-06-11 14:36:14 +04:00
xconn - > smb1 . msg_state = talloc_zero ( xconn , struct msg_state ) ;
2007-12-09 15:45:10 +03:00
2014-06-11 14:36:14 +04:00
if ( xconn - > smb1 . msg_state = = NULL ) {
2007-12-09 15:45:10 +03:00
reply_nterror ( req , NT_STATUS_NO_MEMORY ) ;
END_PROFILE ( SMBsendstrt ) ;
return ;
}
1996-05-04 11:50:46 +04:00
2014-02-26 23:16:26 +04:00
p = req - > buf + 1 ;
2008-11-02 03:07:46 +03:00
p + = srvstr_pull_req_talloc (
2014-06-11 14:36:14 +04:00
xconn - > smb1 . msg_state , req ,
& xconn - > smb1 . msg_state - > from , p ,
2008-11-02 03:07:46 +03:00
STR_ASCII | STR_TERMINATE ) + 1 ;
p + = srvstr_pull_req_talloc (
2014-06-11 14:36:14 +04:00
xconn - > smb1 . msg_state , req ,
& xconn - > smb1 . msg_state - > to , p ,
2008-11-02 03:07:46 +03:00
STR_ASCII | STR_TERMINATE ) + 1 ;
1996-05-04 11:50:46 +04:00
2012-05-25 01:41:43 +04:00
DEBUG ( 3 , ( " SMBsendstrt (from %s to %s) \n " ,
2014-06-11 14:36:14 +04:00
xconn - > smb1 . msg_state - > from ,
xconn - > smb1 . msg_state - > to ) ) ;
1996-05-04 11:50:46 +04:00
2022-04-05 05:53:20 +03:00
reply_smb1_outbuf ( req , 0 , 0 ) ;
2007-08-15 01:07:44 +04:00
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
2008-01-05 02:37:24 +03:00
void reply_sendtxt ( struct smb_request * req )
1996-05-04 11:50:46 +04:00
{
2019-11-05 12:59:40 +03:00
const struct loadparm_substitution * lp_sub =
loadparm_s3_global_substitution ( ) ;
2014-06-11 14:36:14 +04:00
struct smbXsrv_connection * xconn = req - > xconn ;
2006-06-20 06:38:28 +04:00
int len ;
2008-11-01 19:35:48 +03:00
const char * msg ;
2007-12-09 15:45:10 +03:00
char * tmp ;
size_t old_len ;
2006-06-20 06:38:28 +04:00
START_PROFILE ( SMBsendtxt ) ;
1996-05-04 11:50:46 +04:00
2019-11-05 12:59:40 +03:00
if ( ! ( * lp_message_command ( talloc_tos ( ) , lp_sub ) ) ) {
2009-12-21 22:05:25 +03:00
reply_nterror ( req , NT_STATUS_REQUEST_NOT_ACCEPTED ) ;
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
2014-06-11 14:36:14 +04:00
if ( ( xconn - > smb1 . msg_state = = NULL ) | | ( req - > buflen < 3 ) ) {
2007-12-09 15:45:10 +03:00
reply_nterror ( req , NT_STATUS_INVALID_PARAMETER ) ;
END_PROFILE ( SMBsendtxt ) ;
return ;
}
2008-11-01 19:35:48 +03:00
msg = ( const char * ) req - > buf + 1 ;
1996-05-04 11:50:46 +04:00
2014-06-11 14:36:14 +04:00
old_len = talloc_get_size ( xconn - > smb1 . msg_state - > msg ) ;
2007-12-09 15:45:10 +03:00
2008-11-02 03:21:53 +03:00
len = MIN ( SVAL ( msg , 0 ) , smbreq_bufrem ( req , msg + 2 ) ) ;
1996-05-04 11:50:46 +04:00
2014-06-11 14:36:14 +04:00
tmp = talloc_realloc ( xconn - > smb1 . msg_state ,
xconn - > smb1 . msg_state - > msg ,
2012-05-25 01:41:43 +04:00
char , old_len + len ) ;
2007-12-09 15:45:10 +03:00
if ( tmp = = NULL ) {
reply_nterror ( req , NT_STATUS_NO_MEMORY ) ;
END_PROFILE ( SMBsendtxt ) ;
return ;
}
2014-06-11 14:36:14 +04:00
xconn - > smb1 . msg_state - > msg = tmp ;
2007-12-09 15:45:10 +03:00
2014-06-11 14:36:14 +04:00
memcpy ( & xconn - > smb1 . msg_state - > msg [ old_len ] , msg + 2 , 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
2022-04-05 05:53:20 +03:00
reply_smb1_outbuf ( req , 0 , 0 ) ;
2007-08-15 01:07:44 +04:00
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
2008-01-05 02:37:24 +03:00
void reply_sendend ( struct smb_request * req )
1996-05-04 11:50:46 +04:00
{
2019-11-05 12:59:40 +03:00
const struct loadparm_substitution * lp_sub =
loadparm_s3_global_substitution ( ) ;
2014-06-11 14:36:14 +04:00
struct smbXsrv_connection * xconn = req - > xconn ;
2006-06-20 06:38:28 +04:00
START_PROFILE ( SMBsendend ) ;
1996-05-04 11:50:46 +04:00
2019-11-05 12:59:40 +03:00
if ( ! ( * lp_message_command ( talloc_tos ( ) , lp_sub ) ) ) {
2009-12-21 22:05:25 +03:00
reply_nterror ( req , NT_STATUS_REQUEST_NOT_ACCEPTED ) ;
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
2019-03-07 01:44:23 +03:00
if ( xconn - > smb1 . msg_state = = NULL ) {
reply_nterror ( req , NT_STATUS_INVALID_PARAMETER ) ;
END_PROFILE ( SMBsendend ) ;
return ;
}
2006-06-20 06:38:28 +04:00
DEBUG ( 3 , ( " SMBsendend \n " ) ) ;
1996-05-04 11:50:46 +04:00
2014-06-11 14:36:14 +04:00
msg_deliver ( xconn - > smb1 . msg_state ) ;
2007-12-09 15:45:10 +03:00
2014-06-11 14:36:14 +04:00
TALLOC_FREE ( xconn - > smb1 . msg_state ) ;
1996-05-04 11:50:46 +04:00
2022-04-05 05:53:20 +03:00
reply_smb1_outbuf ( req , 0 , 0 ) ;
2007-08-15 01:07:44 +04:00
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
}