2003-08-13 05:53:07 +04:00
/*
Unix SMB / CIFS implementation .
client message handling routines
Copyright ( C ) Andrew Tridgell 1994 - 1998
Copyright ( C ) James J Myers 2003 < myersjj @ samba . org >
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-10 06:07:03 +04:00
the Free Software Foundation ; either version 3 of the License , or
2003-08-13 05:53:07 +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 06:07:03 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2003-08-13 05:53:07 +04:00
*/
# include "includes.h"
2004-11-01 04:03:22 +03:00
# include "libcli/raw/libcliraw.h"
2008-04-02 06:53:27 +04:00
# include "libcli/raw/raw_proto.h"
2007-09-08 17:27:14 +04:00
# include "libcli/libcli.h"
2003-08-13 05:53:07 +04:00
/****************************************************************************
start a message sequence
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-07 02:28:14 +04:00
bool smbcli_message_start ( struct smbcli_tree * tree , const char * host , const char * username ,
2004-02-08 03:51:07 +03:00
int * grp )
2003-08-13 05:53:07 +04:00
{
2004-08-04 17:23:35 +04:00
struct smbcli_request * req ;
2003-08-13 05:53:07 +04:00
2004-08-04 17:23:35 +04:00
req = smbcli_request_setup ( tree , SMBsendstrt , 0 , 0 ) ;
2013-02-19 12:00:51 +04:00
if ( req = = NULL ) {
return false ;
}
2004-08-04 17:23:35 +04:00
smbcli_req_append_string ( req , username , STR_TERMINATE ) ;
smbcli_req_append_string ( req , host , STR_TERMINATE ) ;
if ( ! smbcli_request_send ( req ) | |
! smbcli_request_receive ( req ) | |
smbcli_is_error ( tree ) ) {
smbcli_request_destroy ( req ) ;
2007-10-07 02:28:14 +04:00
return false ;
2003-08-13 05:53:07 +04:00
}
* grp = SVAL ( req - > in . vwv , VWV ( 0 ) ) ;
2004-08-04 17:23:35 +04:00
smbcli_request_destroy ( req ) ;
2003-08-13 05:53:07 +04:00
2007-10-07 02:28:14 +04:00
return true ;
2003-08-13 05:53:07 +04:00
}
/****************************************************************************
send a message
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-07 02:28:14 +04:00
bool smbcli_message_text ( struct smbcli_tree * tree , char * msg , int len , int grp )
2003-08-13 05:53:07 +04:00
{
2004-08-04 17:23:35 +04:00
struct smbcli_request * req ;
2003-08-13 05:53:07 +04:00
2004-08-04 17:23:35 +04:00
req = smbcli_request_setup ( tree , SMBsendtxt , 1 , 0 ) ;
2013-02-19 12:00:51 +04:00
if ( req = = NULL ) {
return false ;
}
2003-08-13 05:53:07 +04:00
SSVAL ( req - > out . vwv , VWV ( 0 ) , grp ) ;
2004-12-04 16:56:25 +03:00
smbcli_req_append_bytes ( req , ( const uint8_t * ) msg , len ) ;
2003-08-13 05:53:07 +04:00
2004-08-04 17:23:35 +04:00
if ( ! smbcli_request_send ( req ) | |
! smbcli_request_receive ( req ) | |
smbcli_is_error ( tree ) ) {
smbcli_request_destroy ( req ) ;
2007-10-07 02:28:14 +04:00
return false ;
2003-08-13 05:53:07 +04:00
}
2004-08-04 17:23:35 +04:00
smbcli_request_destroy ( req ) ;
2007-10-07 02:28:14 +04:00
return true ;
2003-08-13 05:53:07 +04:00
}
/****************************************************************************
end a message
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-07 02:28:14 +04:00
bool smbcli_message_end ( struct smbcli_tree * tree , int grp )
2003-08-13 05:53:07 +04:00
{
2004-08-04 17:23:35 +04:00
struct smbcli_request * req ;
2003-08-13 05:53:07 +04:00
2004-08-04 17:23:35 +04:00
req = smbcli_request_setup ( tree , SMBsendend , 1 , 0 ) ;
2013-02-19 12:00:51 +04:00
if ( req = = NULL ) {
return false ;
}
2003-08-13 05:53:07 +04:00
SSVAL ( req - > out . vwv , VWV ( 0 ) , grp ) ;
2004-08-04 17:23:35 +04:00
if ( ! smbcli_request_send ( req ) | |
! smbcli_request_receive ( req ) | |
smbcli_is_error ( tree ) ) {
smbcli_request_destroy ( req ) ;
2007-10-07 02:28:14 +04:00
return false ;
2003-08-13 05:53:07 +04:00
}
2004-08-04 17:23:35 +04:00
smbcli_request_destroy ( req ) ;
2007-10-07 02:28:14 +04:00
return true ;
2003-08-13 05:53:07 +04:00
}