2000-04-25 18:04:06 +04:00
/*
2002-01-30 09:08:46 +03:00
Unix SMB / CIFS implementation .
2000-04-25 18:04:06 +04:00
client message handling routines
Copyright ( C ) Andrew Tridgell 1994 - 1998
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
2000-04-25 18:04:06 +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/>.
2000-04-25 18:04:06 +04:00
*/
# include "includes.h"
/****************************************************************************
start a message sequence
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2003-06-07 03:09:39 +04:00
int cli_message_start_build ( struct cli_state * cli , char * host , char * username )
2000-04-25 18:04:06 +04:00
{
char * p ;
2003-06-07 03:09:39 +04:00
/* construct a SMBsendstrt command */
2000-04-25 18:04:06 +04:00
memset ( cli - > outbuf , ' \0 ' , smb_size ) ;
2007-10-11 00:34:30 +04:00
set_message ( cli - > outbuf , 0 , 0 , True ) ;
2002-01-11 22:10:25 +03:00
SCVAL ( cli - > outbuf , smb_com , SMBsendstrt ) ;
2000-04-25 18:04:06 +04:00
SSVAL ( cli - > outbuf , smb_tid , cli - > cnum ) ;
cli_setup_packet ( cli ) ;
p = smb_buf ( cli - > outbuf ) ;
* p + + = 4 ;
2003-05-07 06:00:58 +04:00
p + = clistr_push ( cli , p , username , - 1 , STR_ASCII | STR_TERMINATE ) ;
2000-04-25 18:04:06 +04:00
* p + + = 4 ;
2003-05-07 06:00:58 +04:00
p + = clistr_push ( cli , p , host , - 1 , STR_ASCII | STR_TERMINATE ) ;
2000-04-25 18:04:06 +04:00
2001-02-20 15:45:50 +03:00
cli_setup_bcc ( cli , p ) ;
2003-06-07 03:09:39 +04:00
return ( PTR_DIFF ( p , cli - > outbuf ) ) ;
}
2007-10-19 04:40:25 +04:00
bool cli_message_start ( struct cli_state * cli , char * host , char * username ,
2003-06-07 03:09:39 +04:00
int * grp )
{
cli_message_start_build ( cli , host , username ) ;
2000-04-25 18:04:06 +04:00
cli_send_smb ( cli ) ;
if ( ! cli_receive_smb ( cli ) ) {
return False ;
}
2001-08-10 10:00:33 +04:00
if ( cli_is_error ( cli ) ) return False ;
2000-04-25 18:04:06 +04:00
* grp = SVAL ( cli - > inbuf , smb_vwv0 ) ;
return True ;
}
/****************************************************************************
send a message
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2003-06-07 03:09:39 +04:00
int cli_message_text_build ( struct cli_state * cli , char * msg , int len , int grp )
2000-04-25 18:04:06 +04:00
{
2003-03-20 19:44:14 +03:00
char * msgdos ;
int lendos ;
2000-04-25 18:04:06 +04:00
char * p ;
memset ( cli - > outbuf , ' \0 ' , smb_size ) ;
2007-10-11 00:34:30 +04:00
set_message ( cli - > outbuf , 1 , 0 , True ) ;
2002-01-11 22:10:25 +03:00
SCVAL ( cli - > outbuf , smb_com , SMBsendtxt ) ;
2000-04-25 18:04:06 +04:00
SSVAL ( cli - > outbuf , smb_tid , cli - > cnum ) ;
cli_setup_packet ( cli ) ;
SSVAL ( cli - > outbuf , smb_vwv0 , grp ) ;
p = smb_buf ( cli - > outbuf ) ;
2001-06-21 09:38:28 +04:00
* p + + = 1 ;
2003-03-20 19:44:14 +03:00
2005-12-03 09:46:46 +03:00
if ( ( lendos = ( int ) convert_string_allocate ( NULL , CH_UNIX , CH_DOS , msg , len , ( void * * ) ( void * ) & msgdos , True ) ) < 0 | | ! msgdos ) {
2003-03-20 19:44:14 +03:00
DEBUG ( 3 , ( " Conversion failed, sending message in UNIX charset \n " ) ) ;
SSVAL ( p , 0 , len ) ; p + = 2 ;
memcpy ( p , msg , len ) ;
p + = len ;
} else {
SSVAL ( p , 0 , lendos ) ; p + = 2 ;
memcpy ( p , msgdos , lendos ) ;
p + = lendos ;
SAFE_FREE ( msgdos ) ;
}
2001-06-21 09:38:28 +04:00
cli_setup_bcc ( cli , p ) ;
2003-06-07 03:09:39 +04:00
return ( PTR_DIFF ( p , cli - > outbuf ) ) ;
}
2007-10-19 04:40:25 +04:00
bool cli_message_text ( struct cli_state * cli , char * msg , int len , int grp )
2003-06-07 03:09:39 +04:00
{
cli_message_text_build ( cli , msg , len , grp ) ;
2000-04-25 18:04:06 +04:00
cli_send_smb ( cli ) ;
if ( ! cli_receive_smb ( cli ) ) {
return False ;
}
2001-08-10 10:00:33 +04:00
if ( cli_is_error ( cli ) ) return False ;
2000-04-25 18:04:06 +04:00
return True ;
}
/****************************************************************************
end a message
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2003-06-07 03:09:39 +04:00
int cli_message_end_build ( struct cli_state * cli , int grp )
2000-04-25 18:04:06 +04:00
{
2003-06-07 03:09:39 +04:00
char * p ;
2000-04-25 18:04:06 +04:00
memset ( cli - > outbuf , ' \0 ' , smb_size ) ;
2007-10-11 00:34:30 +04:00
set_message ( cli - > outbuf , 1 , 0 , True ) ;
2002-01-11 22:10:25 +03:00
SCVAL ( cli - > outbuf , smb_com , SMBsendend ) ;
2000-04-25 18:04:06 +04:00
SSVAL ( cli - > outbuf , smb_tid , cli - > cnum ) ;
SSVAL ( cli - > outbuf , smb_vwv0 , grp ) ;
cli_setup_packet ( cli ) ;
2003-06-07 03:09:39 +04:00
p = smb_buf ( cli - > outbuf ) ;
return ( PTR_DIFF ( p , cli - > outbuf ) ) ;
}
2007-10-19 04:40:25 +04:00
bool cli_message_end ( struct cli_state * cli , int grp )
2003-06-07 03:09:39 +04:00
{
cli_message_end_build ( cli , grp ) ;
2000-04-25 18:04:06 +04:00
cli_send_smb ( cli ) ;
if ( ! cli_receive_smb ( cli ) ) {
return False ;
}
2001-08-10 10:00:33 +04:00
if ( cli_is_error ( cli ) ) return False ;
2000-04-25 18:04:06 +04:00
return True ;
}