1998-03-12 00:11:04 +03:00
/*
2002-01-30 09:08:46 +03:00
* Unix SMB / CIFS implementation .
1998-03-12 00:11:04 +03:00
* RPC Pipe client / server routines
* Copyright ( C ) Andrew Tridgell 1992 - 1997 ,
* Copyright ( C ) Luke Kenneth Casson Leighton 1996 - 1997 ,
* Copyright ( C ) Paul Ashton 1997.
2005-04-07 02:27:55 +04:00
* Copyright ( C ) Gerald ( Jerry ) Carter 2005
1998-03-12 00:11:04 +03: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
1998-03-12 00:11:04 +03: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 09:23:25 +04:00
* along with this program ; if not , see < http : //www.gnu.org/licenses/>.
1998-03-12 00:11:04 +03:00
*/
# include "includes.h"
2002-07-15 14:35:28 +04:00
# undef DBGC_CLASS
# define DBGC_CLASS DBGC_RPC_PARSE
1999-04-08 09:36:15 +04:00
/*******************************************************************
1999-12-13 16:27:58 +03:00
Reads or writes a UTIME type .
1999-04-08 09:36:15 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
static bool smb_io_utime ( const char * desc , UTIME * t , prs_struct * ps , int depth )
1998-03-12 00:11:04 +03:00
{
1999-12-13 16:27:58 +03:00
if ( t = = NULL )
return False ;
1998-03-12 00:11:04 +03:00
prs_debug ( ps , depth , desc , " smb_io_utime " ) ;
depth + + ;
1999-12-13 16:27:58 +03:00
if ( ! prs_align ( ps ) )
return False ;
1998-03-12 00:11:04 +03:00
1999-12-13 16:27:58 +03:00
if ( ! prs_uint32 ( " time " , ps , depth , & t - > time ) )
return False ;
1999-10-15 22:46:22 +04:00
return True ;
1998-03-12 00:11:04 +03:00
}
/*******************************************************************
1999-12-13 16:27:58 +03:00
Reads or writes an NTTIME structure .
1998-03-12 00:11:04 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
2007-10-19 04:40:25 +04:00
bool smb_io_time ( const char * desc , NTTIME * nttime , prs_struct * ps , int depth )
1998-03-12 00:11:04 +03:00
{
2006-09-06 22:32:20 +04:00
uint32 low , high ;
1999-12-13 16:27:58 +03:00
if ( nttime = = NULL )
return False ;
1998-03-12 00:11:04 +03:00
prs_debug ( ps , depth , desc , " smb_io_time " ) ;
depth + + ;
1999-12-13 16:27:58 +03:00
if ( ! prs_align ( ps ) )
return False ;
2007-10-11 00:34:30 +04:00
2006-09-18 00:28:46 +04:00
if ( MARSHALLING ( ps ) ) {
low = * nttime & 0xFFFFFFFF ;
high = * nttime > > 32 ;
}
1998-03-12 00:11:04 +03:00
2006-09-06 22:32:20 +04:00
if ( ! prs_uint32 ( " low " , ps , depth , & low ) ) /* low part */
1999-12-13 16:27:58 +03:00
return False ;
2006-09-06 22:32:20 +04:00
if ( ! prs_uint32 ( " high " , ps , depth , & high ) ) /* high part */
1999-12-13 16:27:58 +03:00
return False ;
1999-10-15 22:46:22 +04:00
2006-09-18 00:28:46 +04:00
if ( UNMARSHALLING ( ps ) ) {
* nttime = ( ( ( uint64_t ) high < < 32 ) + low ) ;
}
2006-09-06 22:32:20 +04:00
1999-10-15 22:46:22 +04:00
return True ;
1998-03-12 00:11:04 +03:00
}
2005-05-23 20:25:31 +04:00
/*******************************************************************
Reads or writes an NTTIME structure .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
bool smb_io_nttime ( const char * desc , prs_struct * ps , int depth , NTTIME * nttime )
2005-05-23 20:25:31 +04:00
{
return smb_io_time ( desc , nttime , ps , depth ) ;
}
2007-10-11 00:34:30 +04:00
/*******************************************************************
Gets an enumeration handle from an ENUM_HND structure .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
uint32 get_enum_hnd ( ENUM_HND * enh )
{
return ( enh & & enh - > ptr_hnd ! = 0 ) ? enh - > handle : 0 ;
}
/*******************************************************************
Inits an ENUM_HND structure .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void init_enum_hnd ( ENUM_HND * enh , uint32 hnd )
{
DEBUG ( 5 , ( " smb_io_enum_hnd \n " ) ) ;
enh - > ptr_hnd = ( hnd ! = 0 ) ? 1 : 0 ;
enh - > handle = hnd ;
}
/*******************************************************************
Reads or writes an ENUM_HND structure .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
bool smb_io_enum_hnd ( const char * desc , ENUM_HND * hnd , prs_struct * ps , int depth )
2007-10-11 00:34:30 +04:00
{
if ( hnd = = NULL )
return False ;
prs_debug ( ps , depth , desc , " smb_io_enum_hnd " ) ;
depth + + ;
if ( ! prs_align ( ps ) )
return False ;
if ( ! prs_uint32 ( " ptr_hnd " , ps , depth , & hnd - > ptr_hnd ) ) /* pointer */
return False ;
if ( hnd - > ptr_hnd ! = 0 ) {
if ( ! prs_uint32 ( " handle " , ps , depth , & hnd - > handle ) ) /* enum handle */
return False ;
}
return True ;
}
1998-03-12 00:11:04 +03:00
/*******************************************************************
1999-12-13 16:27:58 +03:00
Reads or writes a DOM_SID structure .
1998-03-12 00:11:04 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
2007-10-19 04:40:25 +04:00
bool smb_io_dom_sid ( const char * desc , DOM_SID * sid , prs_struct * ps , int depth )
1998-03-12 00:11:04 +03:00
{
int i ;
1999-12-13 16:27:58 +03:00
if ( sid = = NULL )
return False ;
1998-03-12 00:11:04 +03:00
prs_debug ( ps , depth , desc , " smb_io_dom_sid " ) ;
depth + + ;
1999-12-13 16:27:58 +03:00
if ( ! prs_uint8 ( " sid_rev_num " , ps , depth , & sid - > sid_rev_num ) )
return False ;
2003-01-29 00:09:56 +03:00
1999-12-13 16:27:58 +03:00
if ( ! prs_uint8 ( " num_auths " , ps , depth , & sid - > num_auths ) )
return False ;
1998-03-12 00:11:04 +03:00
for ( i = 0 ; i < 6 ; i + + )
{
fstring tmp ;
1998-05-12 04:55:32 +04:00
slprintf ( tmp , sizeof ( tmp ) - 1 , " id_auth[%d] " , i ) ;
1999-12-13 16:27:58 +03:00
if ( ! prs_uint8 ( tmp , ps , depth , & sid - > id_auth [ i ] ) )
return False ;
1998-03-12 00:11:04 +03:00
}
/* oops! XXXX should really issue a warning here... */
1999-12-13 16:27:58 +03:00
if ( sid - > num_auths > MAXSUBAUTHS )
sid - > num_auths = MAXSUBAUTHS ;
1998-03-12 00:11:04 +03:00
1999-12-13 16:27:58 +03:00
if ( ! prs_uint32s ( False , " sub_auths " , ps , depth , sid - > sub_auths , sid - > num_auths ) )
return False ;
1999-10-15 22:46:22 +04:00
return True ;
1998-03-12 00:11:04 +03:00
}
/*******************************************************************
1999-12-13 16:27:58 +03:00
Inits a DOM_SID2 structure .
1998-03-12 00:11:04 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-10-15 22:46:22 +04:00
2001-12-05 03:22:24 +03:00
void init_dom_sid2 ( DOM_SID2 * sid2 , const DOM_SID * sid )
1999-12-13 16:27:58 +03:00
{
sid2 - > sid = * sid ;
sid2 - > num_auths = sid2 - > sid . num_auths ;
1998-03-12 00:11:04 +03:00
}
/*******************************************************************
1999-12-13 16:27:58 +03:00
Reads or writes a DOM_SID2 structure .
1998-03-12 00:11:04 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
2007-10-19 04:40:25 +04:00
bool smb_io_dom_sid2_p ( const char * desc , prs_struct * ps , int depth , DOM_SID2 * * sid2 )
2005-04-07 02:27:55 +04:00
{
uint32 data_p ;
/* caputure the pointer value to stream */
2005-09-30 21:13:37 +04:00
data_p = * sid2 ? 0xf000baaa : 0 ;
2005-04-07 02:27:55 +04:00
if ( ! prs_uint32 ( " dom_sid2_p " , ps , depth , & data_p ) )
return False ;
/* we're done if there is no data */
if ( ! data_p )
return True ;
if ( UNMARSHALLING ( ps ) ) {
if ( ! ( * sid2 = PRS_ALLOC_MEM ( ps , DOM_SID2 , 1 ) ) )
2007-04-28 03:18:41 +04:00
return False ;
2005-04-07 02:27:55 +04:00
}
return True ;
}
/*******************************************************************
Reads or writes a DOM_SID2 structure .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
bool smb_io_dom_sid2 ( const char * desc , DOM_SID2 * sid , prs_struct * ps , int depth )
1998-03-12 00:11:04 +03:00
{
1999-12-13 16:27:58 +03:00
if ( sid = = NULL )
return False ;
1998-03-12 00:11:04 +03:00
1999-12-13 16:27:58 +03:00
prs_debug ( ps , depth , desc , " smb_io_dom_sid2 " ) ;
1998-03-12 00:11:04 +03:00
depth + + ;
1999-12-13 16:27:58 +03:00
if ( ! prs_align ( ps ) )
return False ;
1998-03-12 00:11:04 +03:00
1999-12-13 16:27:58 +03:00
if ( ! prs_uint32 ( " num_auths " , ps , depth , & sid - > num_auths ) )
return False ;
1998-03-12 00:11:04 +03:00
1999-12-13 16:27:58 +03:00
if ( ! smb_io_dom_sid ( " sid " , & sid - > sid , ps , depth ) )
return False ;
1999-10-15 22:46:22 +04:00
return True ;
1998-03-12 00:11:04 +03:00
}
2004-04-13 18:39:48 +04:00
/*******************************************************************
2006-09-19 04:12:11 +04:00
Reads or writes a struct GUID
2004-04-13 18:39:48 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
bool smb_io_uuid ( const char * desc , struct GUID * uuid ,
2004-04-13 18:39:48 +04:00
prs_struct * ps , int depth )
{
if ( uuid = = NULL )
return False ;
prs_debug ( ps , depth , desc , " smb_io_uuid " ) ;
depth + + ;
if ( ! prs_uint32 ( " data " , ps , depth , & uuid - > time_low ) )
return False ;
if ( ! prs_uint16 ( " data " , ps , depth , & uuid - > time_mid ) )
return False ;
if ( ! prs_uint16 ( " data " , ps , depth , & uuid - > time_hi_and_version ) )
return False ;
if ( ! prs_uint8s ( False , " data " , ps , depth , uuid - > clock_seq , sizeof ( uuid - > clock_seq ) ) )
return False ;
if ( ! prs_uint8s ( False , " data " , ps , depth , uuid - > node , sizeof ( uuid - > node ) ) )
return False ;
return True ;
}
1999-03-18 08:16:59 +03:00
/*******************************************************************
1999-12-13 16:27:58 +03:00
creates a STRHDR structure .
1999-03-18 08:16:59 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
void init_str_hdr ( STRHDR * hdr , int max_len , int len , uint32 buffer )
1999-03-18 08:16:59 +03:00
{
hdr - > str_max_len = max_len ;
hdr - > str_str_len = len ;
hdr - > buffer = buffer ;
}
/*******************************************************************
1999-12-13 16:27:58 +03:00
Reads or writes a STRHDR structure .
1999-03-18 08:16:59 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
2007-10-19 04:40:25 +04:00
bool smb_io_strhdr ( const char * desc , STRHDR * hdr , prs_struct * ps , int depth )
1999-03-18 08:16:59 +03:00
{
1999-12-13 16:27:58 +03:00
if ( hdr = = NULL )
return False ;
1999-03-18 08:16:59 +03:00
prs_debug ( ps , depth , desc , " smb_io_strhdr " ) ;
depth + + ;
prs_align ( ps ) ;
1999-12-13 16:27:58 +03:00
if ( ! prs_uint16 ( " str_str_len " , ps , depth , & hdr - > str_str_len ) )
return False ;
if ( ! prs_uint16 ( " str_max_len " , ps , depth , & hdr - > str_max_len ) )
return False ;
if ( ! prs_uint32 ( " buffer " , ps , depth , & hdr - > buffer ) )
return False ;
1999-03-18 08:16:59 +03:00
1999-10-15 22:46:22 +04:00
return True ;
1999-03-18 08:16:59 +03:00
}
1998-03-12 00:11:04 +03:00
/*******************************************************************
1999-12-13 16:27:58 +03:00
Inits a UNIHDR structure .
1998-03-12 00:11:04 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
2003-09-26 01:26:16 +04:00
void init_uni_hdr ( UNIHDR * hdr , UNISTR2 * str2 )
1998-03-12 00:11:04 +03:00
{
2003-09-26 01:26:16 +04:00
hdr - > uni_str_len = 2 * ( str2 - > uni_str_len ) ;
hdr - > uni_max_len = 2 * ( str2 - > uni_max_len ) ;
hdr - > buffer = ( str2 - > uni_str_len ! = 0 ) ? 1 : 0 ;
1998-03-12 00:11:04 +03:00
}
/*******************************************************************
1999-12-13 16:27:58 +03:00
Reads or writes a UNIHDR structure .
1998-03-12 00:11:04 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
2007-10-19 04:40:25 +04:00
bool smb_io_unihdr ( const char * desc , UNIHDR * hdr , prs_struct * ps , int depth )
1998-03-12 00:11:04 +03:00
{
1999-12-13 16:27:58 +03:00
if ( hdr = = NULL )
return False ;
1998-03-12 00:11:04 +03:00
prs_debug ( ps , depth , desc , " smb_io_unihdr " ) ;
depth + + ;
1999-12-13 16:27:58 +03:00
if ( ! prs_align ( ps ) )
return False ;
1998-03-12 00:11:04 +03:00
1999-12-13 16:27:58 +03:00
if ( ! prs_uint16 ( " uni_str_len " , ps , depth , & hdr - > uni_str_len ) )
return False ;
if ( ! prs_uint16 ( " uni_max_len " , ps , depth , & hdr - > uni_max_len ) )
return False ;
if ( ! prs_uint32 ( " buffer " , ps , depth , & hdr - > buffer ) )
return False ;
1998-03-12 00:11:04 +03:00
1999-10-15 22:46:22 +04:00
return True ;
1998-03-12 00:11:04 +03:00
}
1998-11-10 22:05:00 +03:00
/*******************************************************************
1999-12-13 16:27:58 +03:00
Inits a BUFHDR structure .
1998-11-10 22:05:00 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
void init_buf_hdr ( BUFHDR * hdr , int max_len , int len )
1998-11-10 22:05:00 +03:00
{
hdr - > buf_max_len = max_len ;
hdr - > buf_len = len ;
}
1998-11-12 19:03:35 +03:00
/*******************************************************************
1999-12-13 16:27:58 +03:00
prs_uint16 wrapper . Call this and it sets up a pointer to where the
uint16 should be stored , or gets the size if reading .
1998-11-12 19:03:35 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
2007-10-19 04:40:25 +04:00
bool smb_io_hdrbuf_pre ( const char * desc , BUFHDR * hdr , prs_struct * ps , int depth , uint32 * offset )
1998-11-12 19:03:35 +03:00
{
1999-12-13 16:27:58 +03:00
( * offset ) = prs_offset ( ps ) ;
if ( ps - > io ) {
1998-11-12 19:03:35 +03:00
/* reading. */
1999-12-13 16:27:58 +03:00
if ( ! smb_io_hdrbuf ( desc , hdr , ps , depth ) )
return False ;
} else {
/* writing. */
if ( ! prs_set_offset ( ps , prs_offset ( ps ) + ( sizeof ( uint32 ) * 2 ) ) )
return False ;
1998-11-12 19:03:35 +03:00
}
1999-10-15 22:46:22 +04:00
return True ;
1998-11-12 19:03:35 +03:00
}
/*******************************************************************
1999-12-13 16:27:58 +03:00
smb_io_hdrbuf wrapper . Call this and it retrospectively stores the size .
Does nothing on reading , as that is already handled by . . . . _pre ( )
1998-11-12 19:03:35 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
2007-10-19 04:40:25 +04:00
bool smb_io_hdrbuf_post ( const char * desc , BUFHDR * hdr , prs_struct * ps , int depth ,
1998-11-12 22:21:20 +03:00
uint32 ptr_hdrbuf , uint32 max_len , uint32 len )
1998-11-12 19:03:35 +03:00
{
1999-12-13 16:27:58 +03:00
if ( ! ps - > io ) {
/* writing: go back and do a retrospective job. i hate this */
uint32 old_offset = prs_offset ( ps ) ;
1998-11-12 19:03:35 +03:00
1999-12-13 16:27:58 +03:00
init_buf_hdr ( hdr , max_len , len ) ;
if ( ! prs_set_offset ( ps , ptr_hdrbuf ) )
return False ;
if ( ! smb_io_hdrbuf ( desc , hdr , ps , depth ) )
return False ;
if ( ! prs_set_offset ( ps , old_offset ) )
return False ;
1998-11-12 19:03:35 +03:00
}
1999-10-15 22:46:22 +04:00
return True ;
1998-11-12 19:03:35 +03:00
}
1999-04-08 09:36:15 +04:00
1998-11-10 22:05:00 +03:00
/*******************************************************************
1999-12-13 16:27:58 +03:00
Reads or writes a BUFHDR structure .
1998-11-10 22:05:00 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
2007-10-19 04:40:25 +04:00
bool smb_io_hdrbuf ( const char * desc , BUFHDR * hdr , prs_struct * ps , int depth )
1998-11-10 22:05:00 +03:00
{
1999-12-13 16:27:58 +03:00
if ( hdr = = NULL )
return False ;
1998-11-10 22:05:00 +03:00
prs_debug ( ps , depth , desc , " smb_io_hdrbuf " ) ;
depth + + ;
1999-12-13 16:27:58 +03:00
if ( ! prs_align ( ps ) )
return False ;
1998-11-10 22:05:00 +03:00
1999-12-13 16:27:58 +03:00
if ( ! prs_uint32 ( " buf_max_len " , ps , depth , & hdr - > buf_max_len ) )
return False ;
if ( ! prs_uint32 ( " buf_len " , ps , depth , & hdr - > buf_len ) )
return False ;
1998-11-10 22:05:00 +03:00
1999-10-15 22:46:22 +04:00
return True ;
1998-11-10 22:05:00 +03:00
}
1998-03-12 00:11:04 +03:00
/*******************************************************************
1999-12-13 16:27:58 +03:00
Inits a UNISTR structure .
1998-03-12 00:11:04 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-10-15 22:46:22 +04:00
2000-05-29 03:07:26 +04:00
void init_unistr ( UNISTR * str , const char * buf )
1999-12-13 16:27:58 +03:00
{
2000-08-10 00:14:29 +04:00
size_t len ;
2000-07-27 04:47:19 +04:00
2000-08-12 03:13:09 +04:00
if ( buf = = NULL ) {
2000-08-10 00:14:29 +04:00
str - > buffer = NULL ;
return ;
}
2007-11-28 04:48:44 +03:00
len = rpcstr_push_talloc ( talloc_tos ( ) , & str - > buffer , buf ) ;
if ( len = = ( size_t ) - 1 ) {
2007-04-30 04:48:20 +04:00
str - > buffer = NULL ;
}
1998-03-12 00:11:04 +03:00
}
/*******************************************************************
reads or writes a UNISTR structure .
XXXX NOTE : UNISTR structures NEED to be null - terminated .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
2007-10-19 04:40:25 +04:00
bool smb_io_unistr ( const char * desc , UNISTR * uni , prs_struct * ps , int depth )
1998-03-12 00:11:04 +03:00
{
1999-12-13 16:27:58 +03:00
if ( uni = = NULL )
return False ;
1998-03-12 00:11:04 +03:00
prs_debug ( ps , depth , desc , " smb_io_unistr " ) ;
depth + + ;
1999-12-13 16:27:58 +03:00
if ( ! prs_unistr ( " unistr " , ps , depth , uni ) )
return False ;
1999-10-15 22:46:22 +04:00
return True ;
1998-03-12 00:11:04 +03:00
}
2000-07-27 04:47:19 +04:00
/*******************************************************************
2005-04-07 08:58:38 +04:00
Allocate the RPC_DATA_BLOB memory .
2000-07-27 04:47:19 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-05-05 02:15:33 +04:00
static void create_rpc_blob ( RPC_DATA_BLOB * str , size_t len )
2000-07-27 04:47:19 +04:00
{
2007-05-05 02:15:33 +04:00
if ( len ) {
2007-08-30 23:48:31 +04:00
str - > buffer = ( uint8 * ) TALLOC_ZERO ( talloc_tos ( ) , len ) ;
2007-05-05 02:15:33 +04:00
if ( str - > buffer = = NULL )
2007-06-16 01:58:49 +04:00
smb_panic ( " create_rpc_blob: talloc fail " ) ;
2007-05-05 02:15:33 +04:00
str - > buf_len = len ;
} else {
str - > buffer = NULL ;
str - > buf_len = 0 ;
}
2000-07-27 04:47:19 +04:00
}
1998-03-12 00:11:04 +03:00
/*******************************************************************
2005-04-07 08:58:38 +04:00
Inits a RPC_DATA_BLOB structure from a uint32
1998-03-12 00:11:04 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
2005-04-07 08:58:38 +04:00
void init_rpc_blob_uint32 ( RPC_DATA_BLOB * str , uint32 val )
1998-03-12 00:11:04 +03:00
{
1998-11-10 22:05:00 +03:00
ZERO_STRUCTP ( str ) ;
/* set up string lengths. */
2007-05-05 02:15:33 +04:00
create_rpc_blob ( str , sizeof ( uint32 ) ) ;
1998-11-10 22:05:00 +03:00
SIVAL ( str - > buffer , 0 , val ) ;
}
/*******************************************************************
2005-04-07 08:58:38 +04:00
Inits a RPC_DATA_BLOB structure .
1998-11-10 22:05:00 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
2005-04-07 08:58:38 +04:00
void init_rpc_blob_str ( RPC_DATA_BLOB * str , const char * buf , int len )
1998-11-10 22:05:00 +03:00
{
ZERO_STRUCTP ( str ) ;
/* set up string lengths. */
2007-05-05 02:15:33 +04:00
if ( len ) {
create_rpc_blob ( str , len * 2 ) ;
rpcstr_push ( str - > buffer , buf , ( size_t ) str - > buf_len , STR_TERMINATE ) ;
}
1998-11-10 22:05:00 +03:00
}
/*******************************************************************
2005-04-07 08:58:38 +04:00
Inits a RPC_DATA_BLOB structure from a hex string .
1998-11-10 22:05:00 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
2005-04-07 08:58:38 +04:00
void init_rpc_blob_hex ( RPC_DATA_BLOB * str , const char * buf )
1998-11-10 22:05:00 +03:00
{
ZERO_STRUCTP ( str ) ;
2007-05-05 02:15:33 +04:00
if ( buf & & * buf ) {
2007-12-04 04:17:05 +03:00
size_t len = strlen ( buf ) ;
create_rpc_blob ( str , len ) ;
str - > buf_len = strhex_to_str ( ( char * ) str - > buffer , str - > buf_len ,
buf , len ) ;
2007-05-05 02:15:33 +04:00
}
1998-11-10 22:05:00 +03:00
}
/*******************************************************************
2005-04-07 08:58:38 +04:00
Inits a RPC_DATA_BLOB structure .
1998-11-10 22:05:00 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
2005-04-07 08:58:38 +04:00
void init_rpc_blob_bytes ( RPC_DATA_BLOB * str , uint8 * buf , size_t len )
1998-11-10 22:05:00 +03:00
{
ZERO_STRUCTP ( str ) ;
/* max buffer size (allocated size) */
2007-05-05 02:15:33 +04:00
if ( buf ! = NULL & & len ) {
create_rpc_blob ( str , len ) ;
2000-07-27 04:47:19 +04:00
memcpy ( str - > buffer , buf , len ) ;
}
2005-04-07 08:58:38 +04:00
str - > buf_len = len ;
1999-04-27 14:43:32 +04:00
}
2000-02-07 19:25:15 +03:00
/*******************************************************************
reads or writes a BUFFER5 structure .
the buf_len member tells you how large the buffer is .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
bool smb_io_buffer5 ( const char * desc , BUFFER5 * buf5 , prs_struct * ps , int depth )
2000-02-07 19:25:15 +03:00
{
2000-03-29 16:36:44 +04:00
prs_debug ( ps , depth , desc , " smb_io_buffer5 " ) ;
2000-02-07 19:25:15 +03:00
depth + + ;
if ( buf5 = = NULL ) return False ;
2000-12-15 12:31:56 +03:00
if ( ! prs_align ( ps ) )
return False ;
if ( ! prs_uint32 ( " buf_len " , ps , depth , & buf5 - > buf_len ) )
return False ;
2000-02-07 19:25:15 +03:00
2002-11-07 10:08:04 +03:00
if ( buf5 - > buf_len ) {
if ( ! prs_buffer5 ( True , " buffer " , ps , depth , buf5 ) )
return False ;
}
2000-02-07 19:25:15 +03:00
return True ;
}
1999-04-27 14:43:32 +04:00
/*******************************************************************
2005-03-24 02:26:33 +03:00
Inits a REGVAL_BUFFER structure .
1999-04-27 14:43:32 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2005-03-24 02:26:33 +03:00
void init_regval_buffer ( REGVAL_BUFFER * str , const uint8 * buf , size_t len )
1999-11-17 00:14:53 +03:00
{
ZERO_STRUCTP ( str ) ;
1999-12-13 16:27:58 +03:00
/* max buffer size (allocated size) */
str - > buf_max_len = len ;
2003-09-26 01:26:16 +04:00
str - > offset = 0 ;
1999-12-13 16:27:58 +03:00
str - > buf_len = buf ! = NULL ? len : 0 ;
1999-11-17 00:14:53 +03:00
2000-07-27 04:47:19 +04:00
if ( buf ! = NULL ) {
2005-01-08 03:51:12 +03:00
SMB_ASSERT ( str - > buf_max_len > = str - > buf_len ) ;
2007-08-30 23:48:31 +04:00
str - > buffer = ( uint16 * ) TALLOC_ZERO ( talloc_tos ( ) ,
2006-07-30 20:36:56 +04:00
str - > buf_max_len ) ;
2000-07-27 04:47:19 +04:00
if ( str - > buffer = = NULL )
2007-06-16 01:58:49 +04:00
smb_panic ( " init_regval_buffer: talloc fail " ) ;
2005-01-08 03:51:12 +03:00
memcpy ( str - > buffer , buf , str - > buf_len ) ;
2000-07-27 04:47:19 +04:00
}
1999-11-17 00:14:53 +03:00
}
1999-04-27 14:43:32 +04:00
/*******************************************************************
2005-03-24 02:26:33 +03:00
Reads or writes a REGVAL_BUFFER structure .
1999-12-13 16:27:58 +03:00
the uni_max_len member tells you how large the buffer is .
the uni_str_len member tells you how much of the buffer is really used .
1998-11-10 22:05:00 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
bool smb_io_regval_buffer ( const char * desc , prs_struct * ps , int depth , REGVAL_BUFFER * buf2 )
1998-03-12 00:11:04 +03:00
{
1999-12-13 16:27:58 +03:00
2005-03-24 02:26:33 +03:00
prs_debug ( ps , depth , desc , " smb_io_regval_buffer " ) ;
depth + + ;
1998-03-12 00:11:04 +03:00
2005-03-24 02:26:33 +03:00
if ( ! prs_align ( ps ) )
return False ;
1998-03-12 00:11:04 +03:00
2005-05-23 20:25:31 +04:00
if ( ! prs_uint32 ( " buf_max_len " , ps , depth , & buf2 - > buf_max_len ) )
2005-03-24 02:26:33 +03:00
return False ;
if ( ! prs_uint32 ( " offset " , ps , depth , & buf2 - > offset ) )
return False ;
if ( ! prs_uint32 ( " buf_len " , ps , depth , & buf2 - > buf_len ) )
return False ;
1999-12-13 16:27:58 +03:00
2005-03-24 02:26:33 +03:00
/* buffer advanced by indicated length of string
NOT by searching for null - termination */
1999-12-13 16:27:58 +03:00
2005-03-24 02:26:33 +03:00
if ( ! prs_regval_buffer ( True , " buffer " , ps , depth , buf2 ) )
return False ;
1999-10-15 22:46:22 +04:00
return True ;
1998-03-12 00:11:04 +03:00
}
/*******************************************************************
creates a UNISTR2 structure : sets up the buffer , too
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
2000-06-01 22:17:22 +04:00
void init_buf_unistr2 ( UNISTR2 * str , uint32 * ptr , const char * buf )
1998-03-12 00:11:04 +03:00
{
1999-12-13 16:27:58 +03:00
if ( buf ! = NULL ) {
1998-03-12 00:11:04 +03:00
* ptr = 1 ;
2003-09-26 01:26:16 +04:00
init_unistr2 ( str , buf , UNI_STR_TERMINATE ) ;
1999-12-13 16:27:58 +03:00
} else {
1998-03-12 00:11:04 +03:00
* ptr = 0 ;
2003-09-26 01:26:16 +04:00
init_unistr2 ( str , NULL , UNI_FLAGS_NONE ) ;
1999-10-15 22:46:22 +04:00
1999-12-13 16:27:58 +03:00
}
1998-03-12 00:11:04 +03:00
}
/*******************************************************************
1999-12-13 16:27:58 +03:00
Copies a UNISTR2 structure .
1998-03-12 00:11:04 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-11-24 02:05:47 +03:00
2001-08-31 07:38:48 +04:00
void copy_unistr2 ( UNISTR2 * str , const UNISTR2 * from )
1999-12-13 16:27:58 +03:00
{
2005-01-08 03:51:12 +03:00
if ( from - > buffer = = NULL ) {
ZERO_STRUCTP ( str ) ;
return ;
}
SMB_ASSERT ( from - > uni_max_len > = from - > uni_str_len ) ;
1999-12-13 16:27:58 +03:00
str - > uni_max_len = from - > uni_max_len ;
2003-09-26 01:26:16 +04:00
str - > offset = from - > offset ;
1999-12-13 16:27:58 +03:00
str - > uni_str_len = from - > uni_str_len ;
1998-07-07 02:48:21 +04:00
2000-08-16 07:41:02 +04:00
/* the string buffer is allocated to the maximum size
( the the length of the source string ) to prevent
reallocation of memory . */
2000-07-27 04:47:19 +04:00
if ( str - > buffer = = NULL ) {
2007-04-30 04:48:20 +04:00
if ( str - > uni_max_len ) {
2007-08-30 23:48:31 +04:00
str - > buffer = ( uint16 * ) TALLOC_ZERO_ARRAY ( talloc_tos ( ) , uint16 , str - > uni_max_len ) ;
2007-04-30 04:48:20 +04:00
if ( ( str - > buffer = = NULL ) ) {
2007-06-16 01:58:49 +04:00
smb_panic ( " copy_unistr2: talloc fail " ) ;
2007-04-30 04:48:20 +04:00
return ;
}
/* copy the string */
memcpy ( str - > buffer , from - > buffer , str - > uni_max_len * sizeof ( uint16 ) ) ;
} else {
str - > buffer = NULL ;
2000-08-16 07:41:02 +04:00
}
2000-07-27 04:47:19 +04:00
}
1999-11-24 02:05:47 +03:00
}
/*******************************************************************
1999-12-13 16:27:58 +03:00
Creates a STRING2 structure .
1999-11-24 02:05:47 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
2005-01-08 03:51:12 +03:00
void init_string2 ( STRING2 * str , const char * buf , size_t max_len , size_t str_len )
1999-11-24 02:05:47 +03:00
{
2000-07-27 04:47:19 +04:00
/* set up string lengths. */
2005-01-08 03:51:12 +03:00
SMB_ASSERT ( max_len > = str_len ) ;
2006-03-08 23:02:50 +03:00
/* Ensure buf is valid if str_len was set. Coverity check. */
if ( str_len & & ! buf ) {
return ;
}
2001-11-22 02:25:30 +03:00
str - > str_max_len = max_len ;
2003-09-26 01:26:16 +04:00
str - > offset = 0 ;
2001-11-22 02:25:30 +03:00
str - > str_str_len = str_len ;
2000-07-27 04:47:19 +04:00
/* store the string */
2001-11-22 02:25:30 +03:00
if ( str_len ! = 0 ) {
2007-08-30 23:48:31 +04:00
str - > buffer = ( uint8 * ) TALLOC_ZERO ( talloc_tos ( ) ,
2006-07-30 20:36:56 +04:00
str - > str_max_len ) ;
2000-07-27 04:47:19 +04:00
if ( str - > buffer = = NULL )
2007-06-16 01:58:49 +04:00
smb_panic ( " init_string2: malloc fail " ) ;
2001-11-22 02:25:30 +03:00
memcpy ( str - > buffer , buf , str_len ) ;
2003-09-26 01:26:16 +04:00
}
1998-03-12 00:11:04 +03:00
}
/*******************************************************************
1999-12-13 16:27:58 +03:00
Reads or writes a STRING2 structure .
XXXX NOTE : STRING2 structures need NOT be null - terminated .
the str_str_len member tells you how long the string is ;
the str_max_len member tells you how large the buffer is .
1998-03-12 00:11:04 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
2007-10-19 04:40:25 +04:00
bool smb_io_string2 ( const char * desc , STRING2 * str2 , uint32 buffer , prs_struct * ps , int depth )
1998-03-12 00:11:04 +03:00
{
1999-12-13 16:27:58 +03:00
if ( str2 = = NULL )
return False ;
if ( buffer ) {
1998-03-12 00:11:04 +03:00
prs_debug ( ps , depth , desc , " smb_io_string2 " ) ;
depth + + ;
1999-12-13 16:27:58 +03:00
if ( ! prs_align ( ps ) )
return False ;
1998-03-12 00:11:04 +03:00
1999-12-13 16:27:58 +03:00
if ( ! prs_uint32 ( " str_max_len " , ps , depth , & str2 - > str_max_len ) )
return False ;
2003-09-26 01:26:16 +04:00
if ( ! prs_uint32 ( " offset " , ps , depth , & str2 - > offset ) )
1999-12-13 16:27:58 +03:00
return False ;
if ( ! prs_uint32 ( " str_str_len " , ps , depth , & str2 - > str_str_len ) )
return False ;
1998-03-12 00:11:04 +03:00
/* buffer advanced by indicated length of string
NOT by searching for null - termination */
1999-12-13 16:27:58 +03:00
if ( ! prs_string2 ( True , " buffer " , ps , depth , str2 ) )
return False ;
} else {
1998-03-12 00:11:04 +03:00
prs_debug ( ps , depth , desc , " smb_io_string2 - NULL " ) ;
depth + + ;
1999-12-13 16:27:58 +03:00
memset ( ( char * ) str2 , ' \0 ' , sizeof ( * str2 ) ) ;
1998-03-12 00:11:04 +03:00
}
1999-10-15 22:46:22 +04:00
return True ;
1998-03-12 00:11:04 +03:00
}
/*******************************************************************
1999-12-13 16:27:58 +03:00
Inits a UNISTR2 structure .
1998-03-12 00:11:04 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
2003-09-26 01:26:16 +04:00
void init_unistr2 ( UNISTR2 * str , const char * buf , enum unistr2_term_codes flags )
1998-03-12 00:11:04 +03:00
{
2003-09-26 01:26:16 +04:00
size_t len = 0 ;
uint32 num_chars = 0 ;
1998-10-28 21:32:34 +03:00
2003-09-26 01:26:16 +04:00
if ( buf ) {
/* We always null terminate the copy. */
len = strlen ( buf ) + 1 ;
2005-10-06 21:48:03 +04:00
if ( flags = = UNI_STR_DBLTERMINATE )
len + + ;
2007-04-30 04:48:20 +04:00
}
if ( buf = = NULL | | len = = 0 ) {
2005-01-11 05:53:00 +03:00
/* no buffer -- nothing to do */
str - > uni_max_len = 0 ;
str - > offset = 0 ;
str - > uni_str_len = 0 ;
return ;
2003-09-26 01:26:16 +04:00
}
2005-01-11 05:53:00 +03:00
1998-03-12 00:11:04 +03:00
2007-08-30 23:48:31 +04:00
str - > buffer = TALLOC_ZERO_ARRAY ( talloc_tos ( ) , uint16 , len ) ;
2004-12-07 21:25:53 +03:00
if ( str - > buffer = = NULL ) {
2007-06-16 01:58:49 +04:00
smb_panic ( " init_unistr2: malloc fail " ) ;
2000-08-16 07:41:02 +04:00
return ;
}
2000-07-27 04:47:19 +04:00
2004-12-07 21:25:53 +03:00
/* Ensure len is the length in *bytes* */
len * = sizeof ( uint16 ) ;
2001-07-09 22:21:03 +04:00
/*
2003-09-26 01:26:16 +04:00
* The UNISTR2 must be initialized ! ! !
2001-07-09 22:21:03 +04:00
* jfm , 7 / 7 / 2001.
*/
2003-09-26 01:26:16 +04:00
if ( buf ) {
rpcstr_push ( ( char * ) str - > buffer , buf , len , STR_TERMINATE ) ;
num_chars = strlen_w ( str - > buffer ) ;
2004-11-29 22:28:12 +03:00
if ( flags = = UNI_STR_TERMINATE | | flags = = UNI_MAXLEN_TERMINATE ) {
2003-09-26 01:26:16 +04:00
num_chars + + ;
}
2005-10-06 21:48:03 +04:00
if ( flags = = UNI_STR_DBLTERMINATE )
num_chars + = 2 ;
2003-09-26 01:26:16 +04:00
}
2001-07-09 22:21:03 +04:00
2003-09-26 01:26:16 +04:00
str - > uni_max_len = num_chars ;
str - > offset = 0 ;
str - > uni_str_len = num_chars ;
2003-12-11 00:13:44 +03:00
if ( num_chars & & ( ( flags = = UNI_MAXLEN_TERMINATE ) | | ( flags = = UNI_BROKEN_NON_NULL ) ) )
2003-09-26 01:26:16 +04:00
str - > uni_max_len + + ;
1998-03-12 00:11:04 +03:00
}
2005-03-24 02:26:33 +03:00
/*******************************************************************
Inits a UNISTR4 structure .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void init_unistr4 ( UNISTR4 * uni4 , const char * buf , enum unistr2_term_codes flags )
{
2007-08-30 23:48:31 +04:00
uni4 - > string = TALLOC_P ( talloc_tos ( ) , UNISTR2 ) ;
2006-03-30 02:56:05 +04:00
if ( ! uni4 - > string ) {
2007-06-16 01:58:49 +04:00
smb_panic ( " init_unistr4: talloc fail " ) ;
2006-03-30 02:56:05 +04:00
return ;
}
2005-03-24 02:26:33 +03:00
init_unistr2 ( uni4 - > string , buf , flags ) ;
uni4 - > length = 2 * ( uni4 - > string - > uni_str_len ) ;
uni4 - > size = 2 * ( uni4 - > string - > uni_max_len ) ;
}
2005-04-07 02:27:55 +04:00
void init_unistr4_w ( TALLOC_CTX * ctx , UNISTR4 * uni4 , const smb_ucs2_t * buf )
{
uni4 - > string = TALLOC_P ( ctx , UNISTR2 ) ;
2006-03-30 02:56:05 +04:00
if ( ! uni4 - > string ) {
2007-06-16 01:58:49 +04:00
smb_panic ( " init_unistr4_w: talloc fail " ) ;
2006-03-30 02:56:05 +04:00
return ;
}
2005-04-07 02:27:55 +04:00
init_unistr2_w ( ctx , uni4 - > string , buf ) ;
uni4 - > length = 2 * ( uni4 - > string - > uni_str_len ) ;
uni4 - > size = 2 * ( uni4 - > string - > uni_max_len ) ;
}
2005-03-24 02:26:33 +03:00
2002-07-15 14:35:28 +04:00
/**
* Inits a UNISTR2 structure .
* @ param ctx talloc context to allocate string on
* @ param str pointer to string to create
* @ param buf UCS2 null - terminated buffer to init from
*/
void init_unistr2_w ( TALLOC_CTX * ctx , UNISTR2 * str , const smb_ucs2_t * buf )
{
2006-03-12 02:11:24 +03:00
uint32 len = buf ? strlen_w ( buf ) : 0 ;
2002-07-15 14:35:28 +04:00
ZERO_STRUCTP ( str ) ;
/* set up string lengths. */
str - > uni_max_len = len ;
2003-09-26 01:26:16 +04:00
str - > offset = 0 ;
2002-07-15 14:35:28 +04:00
str - > uni_str_len = len ;
2007-04-30 04:48:20 +04:00
if ( len + 1 ) {
str - > buffer = TALLOC_ZERO_ARRAY ( ctx , uint16 , len + 1 ) ;
if ( str - > buffer = = NULL ) {
2007-06-16 01:58:49 +04:00
smb_panic ( " init_unistr2_w: talloc fail " ) ;
2007-04-30 04:48:20 +04:00
return ;
}
} else {
str - > buffer = NULL ;
2002-07-15 14:35:28 +04:00
}
/*
* don ' t move this test above ! The UNISTR2 must be initialized ! ! !
* jfm , 7 / 7 / 2001.
*/
if ( buf = = NULL )
return ;
/* Yes, this is a strncpy( foo, bar, strlen(bar)) - but as
long as the buffer above is talloc ( ) ed correctly then this
is the correct thing to do */
2007-04-30 04:48:20 +04:00
if ( len + 1 ) {
strncpy_w ( str - > buffer , buf , len + 1 ) ;
}
2002-07-15 14:35:28 +04:00
}
2000-08-04 16:42:19 +04:00
/*******************************************************************
Inits a UNISTR2 structure from a UNISTR
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-11-28 04:48:44 +03:00
void init_unistr2_from_unistr ( TALLOC_CTX * ctx , UNISTR2 * to , const UNISTR * from )
2003-09-26 01:26:16 +04:00
{
2000-08-08 10:59:35 +04:00
uint32 i ;
2000-08-04 16:42:19 +04:00
2000-08-08 10:59:35 +04:00
/* the destination UNISTR2 should never be NULL.
if it is it is a programming error */
2000-08-04 16:42:19 +04:00
2000-08-08 10:59:35 +04:00
/* if the source UNISTR is NULL, then zero out
the destination string and return */
ZERO_STRUCTP ( to ) ;
if ( ( from = = NULL ) | | ( from - > buffer = = NULL ) )
2000-08-04 16:42:19 +04:00
return ;
2000-08-08 10:59:35 +04:00
/* get the length; UNISTR must be NULL terminated */
i = 0 ;
while ( ( from - > buffer ) [ i ] ! = ' \0 ' )
i + + ;
2000-08-16 07:41:02 +04:00
i + + ; /* one more to catch the terminating NULL */
2000-08-18 00:03:53 +04:00
/* is this necessary -- jerry? I need to think */
2000-08-08 10:59:35 +04:00
/* set up string lengths; uni_max_len is set to i+1
because we need to account for the final NULL termination */
2000-08-16 07:41:02 +04:00
to - > uni_max_len = i ;
2003-09-26 01:26:16 +04:00
to - > offset = 0 ;
2000-08-16 07:41:02 +04:00
to - > uni_str_len = i ;
2000-08-04 16:42:19 +04:00
2000-08-08 10:59:35 +04:00
/* allocate the space and copy the string buffer */
2007-04-30 04:48:20 +04:00
if ( i ) {
2007-11-28 04:48:44 +03:00
to - > buffer = TALLOC_ZERO_ARRAY ( ctx , uint16 , i ) ;
2007-04-30 04:48:20 +04:00
if ( to - > buffer = = NULL )
2007-11-28 04:48:44 +03:00
smb_panic ( " init_unistr2_from_unistr: talloc fail " ) ;
2007-04-30 04:48:20 +04:00
memcpy ( to - > buffer , from - > buffer , i * sizeof ( uint16 ) ) ;
} else {
to - > buffer = NULL ;
}
2000-08-04 16:42:19 +04:00
return ;
}
2003-11-07 21:32:23 +03:00
/*******************************************************************
Inits a UNISTR2 structure from a DATA_BLOB .
The length of the data_blob must count the bytes of the buffer .
Copies the blob data .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void init_unistr2_from_datablob ( UNISTR2 * str , DATA_BLOB * blob )
{
/* Allocs the unistring */
init_unistr2 ( str , NULL , UNI_FLAGS_NONE ) ;
/* Sets the values */
str - > uni_str_len = blob - > length / sizeof ( uint16 ) ;
str - > uni_max_len = str - > uni_str_len ;
str - > offset = 0 ;
2003-11-18 01:07:47 +03:00
if ( blob - > length ) {
str - > buffer = ( uint16 * ) memdup ( blob - > data , blob - > length ) ;
} else {
str - > buffer = NULL ;
}
2003-11-11 22:22:00 +03:00
if ( ( str - > buffer = = NULL ) & & ( blob - > length > 0 ) ) {
2007-06-16 01:58:49 +04:00
smb_panic ( " init_unistr2_from_datablob: malloc fail " ) ;
2003-11-07 21:32:23 +03:00
}
}
2005-03-24 02:26:33 +03:00
/*******************************************************************
UNISTR2 * are a little different in that the pointer and the UNISTR2
are not necessarily read / written back to back . So we break it up
into 2 separate functions .
See SPOOL_USER_1 in include / rpc_spoolss . h for an example .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
bool prs_io_unistr2_p ( const char * desc , prs_struct * ps , int depth , UNISTR2 * * uni2 )
2005-03-24 02:26:33 +03:00
{
uint32 data_p ;
/* caputure the pointer value to stream */
2005-09-30 21:13:37 +04:00
data_p = * uni2 ? 0xf000baaa : 0 ;
2005-03-24 02:26:33 +03:00
if ( ! prs_uint32 ( " ptr " , ps , depth , & data_p ) )
return False ;
/* we're done if there is no data */
if ( ! data_p )
return True ;
if ( UNMARSHALLING ( ps ) ) {
if ( ! ( * uni2 = PRS_ALLOC_MEM ( ps , UNISTR2 , 1 ) ) )
return False ;
}
return True ;
}
/*******************************************************************
now read / write the actual UNISTR2 . Memory for the UNISTR2 ( but
not UNISTR2 . buffer ) has been allocated previously by prs_unistr2_p ( )
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
bool prs_io_unistr2 ( const char * desc , prs_struct * ps , int depth , UNISTR2 * uni2 )
2005-03-24 02:26:33 +03:00
{
/* just return true if there is no pointer to deal with.
the memory must have been previously allocated on unmarshalling
by prs_unistr2_p ( ) */
if ( ! uni2 )
return True ;
/* just pass off to smb_io_unstr2() passing the uni2 address as
the pointer ( like you would expect ) */
2005-09-30 21:13:37 +04:00
return smb_io_unistr2 ( desc , uni2 , uni2 ? 1 : 0 , ps , depth ) ;
2005-03-24 02:26:33 +03:00
}
1998-03-12 00:11:04 +03:00
/*******************************************************************
1999-12-13 16:27:58 +03:00
Reads or writes a UNISTR2 structure .
XXXX NOTE : UNISTR2 structures need NOT be null - terminated .
the uni_str_len member tells you how long the string is ;
the uni_max_len member tells you how large the buffer is .
1998-03-12 00:11:04 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
2007-10-19 04:40:25 +04:00
bool smb_io_unistr2 ( const char * desc , UNISTR2 * uni2 , uint32 buffer , prs_struct * ps , int depth )
1998-03-12 00:11:04 +03:00
{
1999-12-13 16:27:58 +03:00
if ( uni2 = = NULL )
return False ;
if ( buffer ) {
1998-03-12 00:11:04 +03:00
prs_debug ( ps , depth , desc , " smb_io_unistr2 " ) ;
depth + + ;
1999-12-13 16:27:58 +03:00
if ( ! prs_align ( ps ) )
return False ;
1998-03-12 00:11:04 +03:00
1999-12-13 16:27:58 +03:00
if ( ! prs_uint32 ( " uni_max_len " , ps , depth , & uni2 - > uni_max_len ) )
return False ;
2003-09-26 01:26:16 +04:00
if ( ! prs_uint32 ( " offset " , ps , depth , & uni2 - > offset ) )
1999-12-13 16:27:58 +03:00
return False ;
if ( ! prs_uint32 ( " uni_str_len " , ps , depth , & uni2 - > uni_str_len ) )
return False ;
1998-03-12 00:11:04 +03:00
/* buffer advanced by indicated length of string
NOT by searching for null - termination */
1999-12-13 16:27:58 +03:00
if ( ! prs_unistr2 ( True , " buffer " , ps , depth , uni2 ) )
return False ;
} else {
1998-03-12 00:11:04 +03:00
prs_debug ( ps , depth , desc , " smb_io_unistr2 - NULL " ) ;
depth + + ;
1999-12-13 16:27:58 +03:00
memset ( ( char * ) uni2 , ' \0 ' , sizeof ( * uni2 ) ) ;
1998-03-12 00:11:04 +03:00
}
1999-10-15 22:46:22 +04:00
return True ;
1998-03-12 00:11:04 +03:00
}
2005-03-24 02:26:33 +03:00
/*******************************************************************
now read / write UNISTR4
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
bool prs_unistr4 ( const char * desc , prs_struct * ps , int depth , UNISTR4 * uni4 )
2005-03-24 02:26:33 +03:00
{
2006-06-17 00:44:49 +04:00
void * ptr ;
2005-05-23 20:25:31 +04:00
prs_debug ( ps , depth , desc , " prs_unistr4 " ) ;
depth + + ;
2005-03-24 02:26:33 +03:00
if ( ! prs_uint16 ( " length " , ps , depth , & uni4 - > length ) )
return False ;
if ( ! prs_uint16 ( " size " , ps , depth , & uni4 - > size ) )
return False ;
2006-06-17 00:44:49 +04:00
ptr = uni4 - > string ;
if ( ! prs_pointer ( desc , ps , depth , & ptr , sizeof ( UNISTR2 ) , ( PRS_POINTER_CAST ) prs_io_unistr2 ) )
2005-03-24 02:26:33 +03:00
return False ;
2006-06-17 00:44:49 +04:00
uni4 - > string = ( UNISTR2 * ) ptr ;
2005-03-24 02:26:33 +03:00
return True ;
}
2005-03-26 09:52:56 +03:00
/*******************************************************************
now read / write UNISTR4 header
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
bool prs_unistr4_hdr ( const char * desc , prs_struct * ps , int depth , UNISTR4 * uni4 )
2005-03-26 09:52:56 +03:00
{
prs_debug ( ps , depth , desc , " prs_unistr4_hdr " ) ;
depth + + ;
if ( ! prs_uint16 ( " length " , ps , depth , & uni4 - > length ) )
return False ;
if ( ! prs_uint16 ( " size " , ps , depth , & uni4 - > size ) )
return False ;
if ( ! prs_io_unistr2_p ( desc , ps , depth , & uni4 - > string ) )
return False ;
return True ;
}
/*******************************************************************
now read / write UNISTR4 string
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
bool prs_unistr4_str ( const char * desc , prs_struct * ps , int depth , UNISTR4 * uni4 )
2005-03-26 09:52:56 +03:00
{
prs_debug ( ps , depth , desc , " prs_unistr4_str " ) ;
depth + + ;
if ( ! prs_io_unistr2 ( desc , ps , depth , uni4 - > string ) )
return False ;
return True ;
}
/*******************************************************************
2005-09-30 21:13:37 +04:00
Reads or writes a UNISTR4_ARRAY structure .
2005-03-26 09:52:56 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
bool prs_unistr4_array ( const char * desc , prs_struct * ps , int depth , UNISTR4_ARRAY * array )
2005-03-26 09:52:56 +03:00
{
unsigned int i ;
prs_debug ( ps , depth , desc , " prs_unistr4_array " ) ;
depth + + ;
if ( ! prs_uint32 ( " count " , ps , depth , & array - > count ) )
return False ;
if ( UNMARSHALLING ( ps ) ) {
2007-04-30 04:48:20 +04:00
if ( array - > count ) {
2007-08-30 23:48:31 +04:00
if ( ! ( array - > strings = TALLOC_ZERO_ARRAY ( talloc_tos ( ) , UNISTR4 , array - > count ) ) )
2007-04-30 04:48:20 +04:00
return False ;
} else {
array - > strings = NULL ;
}
2005-03-26 09:52:56 +03:00
}
/* write the headers and then the actual string buffer */
for ( i = 0 ; i < array - > count ; i + + ) {
if ( ! prs_unistr4_hdr ( " string " , ps , depth , & array - > strings [ i ] ) )
return False ;
}
for ( i = 0 ; i < array - > count ; i + + ) {
if ( ! prs_unistr4_str ( " string " , ps , depth , & array - > strings [ i ] ) )
return False ;
}
return True ;
}
2005-03-24 02:26:33 +03:00
/********************************************************************
2003-01-29 00:09:56 +03:00
initialise a UNISTR_ARRAY from a char * *
2005-03-24 02:26:33 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
bool init_unistr4_array ( UNISTR4_ARRAY * array , uint32 count , const char * * strings )
2003-01-29 00:09:56 +03:00
{
2003-03-18 02:04:03 +03:00
unsigned int i ;
2003-01-29 00:09:56 +03:00
array - > count = count ;
2005-03-26 09:52:56 +03:00
/* allocate memory for the array of UNISTR4 objects */
2007-04-30 04:48:20 +04:00
if ( array - > count ) {
2007-08-30 23:48:31 +04:00
if ( ! ( array - > strings = TALLOC_ZERO_ARRAY ( talloc_tos ( ) , UNISTR4 , count ) ) )
2007-04-30 04:48:20 +04:00
return False ;
} else {
array - > strings = NULL ;
}
2003-01-29 00:09:56 +03:00
2005-03-26 09:52:56 +03:00
for ( i = 0 ; i < count ; i + + )
2005-07-19 02:10:20 +04:00
init_unistr4 ( & array - > strings [ i ] , strings [ i ] , UNI_STR_TERMINATE ) ;
2003-01-29 00:09:56 +03:00
return True ;
}
2007-10-19 04:40:25 +04:00
bool smb_io_lockout_string_hdr ( const char * desc , HDR_LOCKOUT_STRING * hdr_account_lockout , prs_struct * ps , int depth )
2004-12-20 15:52:33 +03:00
{
prs_debug ( ps , depth , desc , " smb_io_lockout_string_hdr " ) ;
depth + + ;
if ( ! prs_align ( ps ) )
return False ;
if ( ! prs_uint16 ( " size " , ps , depth , & hdr_account_lockout - > size ) )
return False ;
if ( ! prs_uint16 ( " length " , ps , depth , & hdr_account_lockout - > length ) )
return False ;
if ( ! prs_uint32 ( " buffer " , ps , depth , & hdr_account_lockout - > buffer ) )
return False ;
return True ;
}
2007-10-19 04:40:25 +04:00
bool smb_io_account_lockout_str ( const char * desc , LOCKOUT_STRING * account_lockout , uint32 buffer , prs_struct * ps , int depth )
2004-12-20 15:52:33 +03:00
{
prs_debug ( ps , depth , desc , " smb_io_account_lockout_string " ) ;
depth + + ;
if ( ! prs_uint32 ( " array_size " , ps , depth , & account_lockout - > array_size ) )
return False ;
if ( ! prs_uint32 ( " offset " , ps , depth , & account_lockout - > offset ) )
return False ;
if ( ! prs_uint32 ( " length " , ps , depth , & account_lockout - > length ) )
return False ;
if ( ! prs_uint64 ( " lockout_duration " , ps , depth , & account_lockout - > lockout_duration ) )
return False ;
if ( ! prs_uint64 ( " reset_count " , ps , depth , & account_lockout - > reset_count ) )
return False ;
if ( ! prs_uint32 ( " bad_attempt_lockout " , ps , depth , & account_lockout - > bad_attempt_lockout ) )
return False ;
if ( ! prs_uint32 ( " dummy " , ps , depth , & account_lockout - > dummy ) )
return False ;
#if 0
if ( ! prs_uint16s ( False , " bindata " , ps , depth , & account_lockout - > bindata , length ) )
return False ;
# endif
return True ;
}
1998-03-12 00:11:04 +03:00
/*******************************************************************
2006-02-11 05:46:41 +03:00
Inits a DOM_RID structure .
1998-03-12 00:11:04 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
2006-03-03 02:32:44 +03:00
void init_dom_rid ( DOM_RID * prid , uint32 rid , uint16 type , uint32 idx )
1998-03-12 00:11:04 +03:00
{
2006-02-11 05:46:41 +03:00
prid - > type = type ;
prid - > rid = rid ;
prid - > rid_idx = idx ;
}
/*******************************************************************
Reads or writes a DOM_RID structure .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
bool smb_io_dom_rid ( const char * desc , DOM_RID * rid , prs_struct * ps , int depth )
2006-02-11 05:46:41 +03:00
{
if ( rid = = NULL )
return False ;
prs_debug ( ps , depth , desc , " smb_io_dom_rid " ) ;
depth + + ;
if ( ! prs_align ( ps ) )
return False ;
2006-03-03 02:32:44 +03:00
if ( ! prs_uint16 ( " type " , ps , depth , & rid - > type ) )
2006-02-11 05:46:41 +03:00
return False ;
if ( ! prs_align ( ps ) )
return False ;
if ( ! prs_uint32 ( " rid " , ps , depth , & rid - > rid ) )
return False ;
if ( ! prs_uint32 ( " rid_idx " , ps , depth , & rid - > rid_idx ) )
return False ;
return True ;
1998-03-12 00:11:04 +03:00
}
/*******************************************************************
1999-12-13 16:27:58 +03:00
Reads or writes a DOM_RID2 structure .
1998-03-12 00:11:04 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
2007-10-19 04:40:25 +04:00
bool smb_io_dom_rid2 ( const char * desc , DOM_RID2 * rid , prs_struct * ps , int depth )
1998-03-12 00:11:04 +03:00
{
2006-02-11 05:46:41 +03:00
if ( rid = = NULL )
1999-12-13 16:27:58 +03:00
return False ;
1998-03-12 00:11:04 +03:00
prs_debug ( ps , depth , desc , " smb_io_dom_rid2 " ) ;
depth + + ;
1999-12-13 16:27:58 +03:00
if ( ! prs_align ( ps ) )
return False ;
2006-03-03 02:32:44 +03:00
if ( ! prs_uint16 ( " type " , ps , depth , & rid - > type ) )
1999-12-13 16:27:58 +03:00
return False ;
if ( ! prs_align ( ps ) )
return False ;
2006-02-11 05:46:41 +03:00
if ( ! prs_uint32 ( " rid " , ps , depth , & rid - > rid ) )
1999-12-13 16:27:58 +03:00
return False ;
2006-02-11 05:46:41 +03:00
if ( ! prs_uint32 ( " rid_idx " , ps , depth , & rid - > rid_idx ) )
return False ;
if ( ! prs_uint32 ( " unknown " , ps , depth , & rid - > unknown ) )
1999-12-13 16:27:58 +03:00
return False ;
1999-10-15 22:46:22 +04:00
return True ;
1998-03-12 00:11:04 +03:00
}
2006-02-11 05:46:41 +03:00
1998-03-12 00:11:04 +03:00
/*******************************************************************
creates a DOM_RID3 structure .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-10-15 22:46:22 +04:00
1999-12-13 16:27:58 +03:00
void init_dom_rid3 ( DOM_RID3 * rid3 , uint32 rid , uint8 type )
{
rid3 - > rid = rid ;
rid3 - > type1 = type ;
rid3 - > ptr_type = 0x1 ; /* non-zero, basically. */
rid3 - > type2 = 0x1 ;
rid3 - > unk = type ;
1998-03-12 00:11:04 +03:00
}
/*******************************************************************
reads or writes a DOM_RID3 structure .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
2007-10-19 04:40:25 +04:00
bool smb_io_dom_rid3 ( const char * desc , DOM_RID3 * rid3 , prs_struct * ps , int depth )
1998-03-12 00:11:04 +03:00
{
1999-12-13 16:27:58 +03:00
if ( rid3 = = NULL )
return False ;
1998-03-12 00:11:04 +03:00
prs_debug ( ps , depth , desc , " smb_io_dom_rid3 " ) ;
depth + + ;
1999-12-13 16:27:58 +03:00
if ( ! prs_align ( ps ) )
return False ;
if ( ! prs_uint32 ( " rid " , ps , depth , & rid3 - > rid ) )
return False ;
if ( ! prs_uint32 ( " type1 " , ps , depth , & rid3 - > type1 ) )
return False ;
if ( ! prs_uint32 ( " ptr_type " , ps , depth , & rid3 - > ptr_type ) )
return False ;
if ( ! prs_uint32 ( " type2 " , ps , depth , & rid3 - > type2 ) )
return False ;
if ( ! prs_uint32 ( " unk " , ps , depth , & rid3 - > unk ) )
return False ;
1999-10-15 22:46:22 +04:00
return True ;
1998-03-12 00:11:04 +03:00
}
/*******************************************************************
1999-12-13 16:27:58 +03:00
Inits a DOM_RID4 structure .
1998-03-12 00:11:04 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
void init_dom_rid4 ( DOM_RID4 * rid4 , uint16 unknown , uint16 attr , uint32 rid )
1998-03-12 00:11:04 +03:00
{
1999-12-13 16:27:58 +03:00
rid4 - > unknown = unknown ;
rid4 - > attr = attr ;
rid4 - > rid = rid ;
}
1998-03-12 00:11:04 +03:00
1999-12-13 16:27:58 +03:00
/*******************************************************************
Inits a DOM_CLNT_SRV structure .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1998-03-12 00:11:04 +03:00
2007-05-23 19:17:49 +04:00
void init_clnt_srv ( DOM_CLNT_SRV * logcln , const char * logon_srv ,
const char * comp_name )
1999-12-13 16:27:58 +03:00
{
DEBUG ( 5 , ( " init_clnt_srv: %d \n " , __LINE__ ) ) ;
if ( logon_srv ! = NULL ) {
2003-05-26 20:54:39 +04:00
logcln - > undoc_buffer = 1 ;
2003-09-26 01:26:16 +04:00
init_unistr2 ( & logcln - > uni_logon_srv , logon_srv , UNI_STR_TERMINATE ) ;
1999-12-13 16:27:58 +03:00
} else {
2003-05-26 20:54:39 +04:00
logcln - > undoc_buffer = 0 ;
1998-03-12 00:11:04 +03:00
}
1999-12-13 16:27:58 +03:00
if ( comp_name ! = NULL ) {
2003-05-26 20:54:39 +04:00
logcln - > undoc_buffer2 = 1 ;
2003-09-26 01:26:16 +04:00
init_unistr2 ( & logcln - > uni_comp_name , comp_name , UNI_STR_TERMINATE ) ;
1999-12-13 16:27:58 +03:00
} else {
2003-05-26 20:54:39 +04:00
logcln - > undoc_buffer2 = 0 ;
1998-03-12 00:11:04 +03:00
}
}
/*******************************************************************
1999-12-13 16:27:58 +03:00
Inits or writes a DOM_CLNT_SRV structure .
1998-03-12 00:11:04 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
2007-10-19 04:40:25 +04:00
bool smb_io_clnt_srv ( const char * desc , DOM_CLNT_SRV * logcln , prs_struct * ps , int depth )
1998-03-12 00:11:04 +03:00
{
2003-05-26 20:54:39 +04:00
if ( logcln = = NULL )
1999-12-13 16:27:58 +03:00
return False ;
1998-03-12 00:11:04 +03:00
prs_debug ( ps , depth , desc , " smb_io_clnt_srv " ) ;
depth + + ;
1999-12-13 16:27:58 +03:00
if ( ! prs_align ( ps ) )
return False ;
1998-03-12 00:11:04 +03:00
2003-05-26 20:54:39 +04:00
if ( ! prs_uint32 ( " undoc_buffer " , ps , depth , & logcln - > undoc_buffer ) )
1999-12-13 16:27:58 +03:00
return False ;
2003-05-26 20:54:39 +04:00
if ( logcln - > undoc_buffer ! = 0 ) {
if ( ! smb_io_unistr2 ( " unistr2 " , & logcln - > uni_logon_srv , logcln - > undoc_buffer , ps , depth ) )
1999-12-13 16:27:58 +03:00
return False ;
1998-03-12 00:11:04 +03:00
}
1999-12-13 16:27:58 +03:00
if ( ! prs_align ( ps ) )
return False ;
1998-03-12 00:11:04 +03:00
2003-05-26 20:54:39 +04:00
if ( ! prs_uint32 ( " undoc_buffer2 " , ps , depth , & logcln - > undoc_buffer2 ) )
1999-12-13 16:27:58 +03:00
return False ;
2003-05-26 20:54:39 +04:00
if ( logcln - > undoc_buffer2 ! = 0 ) {
if ( ! smb_io_unistr2 ( " unistr2 " , & logcln - > uni_comp_name , logcln - > undoc_buffer2 , ps , depth ) )
1999-12-13 16:27:58 +03:00
return False ;
1998-03-12 00:11:04 +03:00
}
1999-10-15 22:46:22 +04:00
return True ;
1998-03-12 00:11:04 +03:00
}
/*******************************************************************
1999-12-13 16:27:58 +03:00
Inits a DOM_LOG_INFO structure .
1998-03-12 00:11:04 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2003-05-26 20:54:39 +04:00
void init_log_info ( DOM_LOG_INFO * loginfo , const char * logon_srv , const char * acct_name ,
2002-03-02 12:15:56 +03:00
uint16 sec_chan , const char * comp_name )
1999-12-13 16:27:58 +03:00
{
1998-03-12 00:11:04 +03:00
DEBUG ( 5 , ( " make_log_info %d \n " , __LINE__ ) ) ;
2003-05-26 20:54:39 +04:00
loginfo - > undoc_buffer = 1 ;
1998-03-12 00:11:04 +03:00
2003-09-26 01:26:16 +04:00
init_unistr2 ( & loginfo - > uni_logon_srv , logon_srv , UNI_STR_TERMINATE ) ;
init_unistr2 ( & loginfo - > uni_acct_name , acct_name , UNI_STR_TERMINATE ) ;
1998-03-12 00:11:04 +03:00
2003-05-26 20:54:39 +04:00
loginfo - > sec_chan = sec_chan ;
1998-03-12 00:11:04 +03:00
2003-09-26 01:26:16 +04:00
init_unistr2 ( & loginfo - > uni_comp_name , comp_name , UNI_STR_TERMINATE ) ;
1998-03-12 00:11:04 +03:00
}
/*******************************************************************
1999-12-13 16:27:58 +03:00
Reads or writes a DOM_LOG_INFO structure .
1998-03-12 00:11:04 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
2007-10-19 04:40:25 +04:00
bool smb_io_log_info ( const char * desc , DOM_LOG_INFO * loginfo , prs_struct * ps , int depth )
1998-03-12 00:11:04 +03:00
{
2003-05-26 20:54:39 +04:00
if ( loginfo = = NULL )
1999-12-13 16:27:58 +03:00
return False ;
1998-03-12 00:11:04 +03:00
prs_debug ( ps , depth , desc , " smb_io_log_info " ) ;
depth + + ;
1999-12-13 16:27:58 +03:00
if ( ! prs_align ( ps ) )
return False ;
1998-03-12 00:11:04 +03:00
2003-05-26 20:54:39 +04:00
if ( ! prs_uint32 ( " undoc_buffer " , ps , depth , & loginfo - > undoc_buffer ) )
1999-12-13 16:27:58 +03:00
return False ;
1998-03-12 00:11:04 +03:00
2003-05-26 20:54:39 +04:00
if ( ! smb_io_unistr2 ( " unistr2 " , & loginfo - > uni_logon_srv , True , ps , depth ) )
1999-12-13 16:27:58 +03:00
return False ;
2003-05-26 20:54:39 +04:00
if ( ! smb_io_unistr2 ( " unistr2 " , & loginfo - > uni_acct_name , True , ps , depth ) )
1999-12-13 16:27:58 +03:00
return False ;
1998-03-12 00:11:04 +03:00
2003-05-26 20:54:39 +04:00
if ( ! prs_uint16 ( " sec_chan " , ps , depth , & loginfo - > sec_chan ) )
1999-12-13 16:27:58 +03:00
return False ;
1998-03-12 00:11:04 +03:00
2003-05-26 20:54:39 +04:00
if ( ! smb_io_unistr2 ( " unistr2 " , & loginfo - > uni_comp_name , True , ps , depth ) )
1999-12-13 16:27:58 +03:00
return False ;
1999-10-15 22:46:22 +04:00
return True ;
1998-03-12 00:11:04 +03:00
}
/*******************************************************************
1999-12-13 16:27:58 +03:00
Reads or writes a DOM_CHAL structure .
1998-03-12 00:11:04 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
2007-10-19 04:40:25 +04:00
bool smb_io_chal ( const char * desc , DOM_CHAL * chal , prs_struct * ps , int depth )
1998-03-12 00:11:04 +03:00
{
1999-12-13 16:27:58 +03:00
if ( chal = = NULL )
return False ;
1998-03-12 00:11:04 +03:00
prs_debug ( ps , depth , desc , " smb_io_chal " ) ;
depth + + ;
1999-12-13 16:27:58 +03:00
if ( ! prs_uint8s ( False , " data " , ps , depth , chal - > data , 8 ) )
return False ;
1999-10-15 22:46:22 +04:00
return True ;
1998-03-12 00:11:04 +03:00
}
/*******************************************************************
1999-12-13 16:27:58 +03:00
Reads or writes a DOM_CRED structure .
1998-03-12 00:11:04 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
2007-10-19 04:40:25 +04:00
bool smb_io_cred ( const char * desc , DOM_CRED * cred , prs_struct * ps , int depth )
1998-03-12 00:11:04 +03:00
{
1999-12-13 16:27:58 +03:00
if ( cred = = NULL )
return False ;
1998-03-12 00:11:04 +03:00
prs_debug ( ps , depth , desc , " smb_io_cred " ) ;
depth + + ;
1999-12-13 16:27:58 +03:00
if ( ! prs_align ( ps ) )
return False ;
if ( ! smb_io_chal ( " " , & cred - > challenge , ps , depth ) )
return False ;
2001-10-02 10:57:18 +04:00
1999-12-13 16:27:58 +03:00
if ( ! smb_io_utime ( " " , & cred - > timestamp , ps , depth ) )
return False ;
1999-10-15 22:46:22 +04:00
return True ;
1998-03-12 00:11:04 +03:00
}
/*******************************************************************
1999-12-13 16:27:58 +03:00
Inits a DOM_CLNT_INFO2 structure .
1998-03-12 00:11:04 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
void init_clnt_info2 ( DOM_CLNT_INFO2 * clnt ,
2002-11-13 02:20:50 +03:00
const char * logon_srv , const char * comp_name ,
const DOM_CRED * clnt_cred )
1998-03-12 00:11:04 +03:00
{
DEBUG ( 5 , ( " make_clnt_info: %d \n " , __LINE__ ) ) ;
2002-11-13 02:20:50 +03:00
init_clnt_srv ( & clnt - > login , logon_srv , comp_name ) ;
1998-03-12 00:11:04 +03:00
1999-12-13 16:27:58 +03:00
if ( clnt_cred ! = NULL ) {
1998-03-12 00:11:04 +03:00
clnt - > ptr_cred = 1 ;
2002-11-13 02:20:50 +03:00
memcpy ( & clnt - > cred , clnt_cred , sizeof ( clnt - > cred ) ) ;
1999-12-13 16:27:58 +03:00
} else {
1998-03-12 00:11:04 +03:00
clnt - > ptr_cred = 0 ;
}
}
/*******************************************************************
1999-12-13 16:27:58 +03:00
Reads or writes a DOM_CLNT_INFO2 structure .
1998-03-12 00:11:04 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
2007-10-19 04:40:25 +04:00
bool smb_io_clnt_info2 ( const char * desc , DOM_CLNT_INFO2 * clnt , prs_struct * ps , int depth )
1998-03-12 00:11:04 +03:00
{
1999-12-13 16:27:58 +03:00
if ( clnt = = NULL )
return False ;
1998-03-12 00:11:04 +03:00
prs_debug ( ps , depth , desc , " smb_io_clnt_info2 " ) ;
depth + + ;
1999-12-13 16:27:58 +03:00
if ( ! prs_align ( ps ) )
return False ;
1998-03-12 00:11:04 +03:00
1999-12-13 16:27:58 +03:00
if ( ! smb_io_clnt_srv ( " " , & clnt - > login , ps , depth ) )
return False ;
1998-03-12 00:11:04 +03:00
1999-12-13 16:27:58 +03:00
if ( ! prs_align ( ps ) )
return False ;
1998-03-12 00:11:04 +03:00
1999-12-13 16:27:58 +03:00
if ( ! prs_uint32 ( " ptr_cred " , ps , depth , & clnt - > ptr_cred ) )
return False ;
if ( ! smb_io_cred ( " " , & clnt - > cred , ps , depth ) )
return False ;
1999-10-15 22:46:22 +04:00
return True ;
1998-03-12 00:11:04 +03:00
}
/*******************************************************************
1999-12-13 16:27:58 +03:00
Inits a DOM_CLNT_INFO structure .
1998-03-12 00:11:04 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
void init_clnt_info ( DOM_CLNT_INFO * clnt ,
2002-11-13 02:20:50 +03:00
const char * logon_srv , const char * acct_name ,
uint16 sec_chan , const char * comp_name ,
const DOM_CRED * cred )
1998-03-12 00:11:04 +03:00
{
DEBUG ( 5 , ( " make_clnt_info \n " ) ) ;
1999-12-13 16:27:58 +03:00
init_log_info ( & clnt - > login , logon_srv , acct_name , sec_chan , comp_name ) ;
memcpy ( & clnt - > cred , cred , sizeof ( clnt - > cred ) ) ;
1998-03-12 00:11:04 +03:00
}
/*******************************************************************
1999-12-13 16:27:58 +03:00
Reads or writes a DOM_CLNT_INFO structure .
1998-03-12 00:11:04 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
2007-10-19 04:40:25 +04:00
bool smb_io_clnt_info ( const char * desc , DOM_CLNT_INFO * clnt , prs_struct * ps , int depth )
1998-03-12 00:11:04 +03:00
{
1999-12-13 16:27:58 +03:00
if ( clnt = = NULL )
return False ;
1998-03-12 00:11:04 +03:00
prs_debug ( ps , depth , desc , " smb_io_clnt_info " ) ;
depth + + ;
1999-12-13 16:27:58 +03:00
if ( ! prs_align ( ps ) )
return False ;
1998-03-12 00:11:04 +03:00
1999-12-13 16:27:58 +03:00
if ( ! smb_io_log_info ( " " , & clnt - > login , ps , depth ) )
return False ;
if ( ! smb_io_cred ( " " , & clnt - > cred , ps , depth ) )
return False ;
1999-10-15 22:46:22 +04:00
return True ;
1998-03-12 00:11:04 +03:00
}
/*******************************************************************
1999-12-13 16:27:58 +03:00
Inits a DOM_LOGON_ID structure .
1998-03-12 00:11:04 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
2003-05-26 20:54:39 +04:00
void init_logon_id ( DOM_LOGON_ID * logonid , uint32 log_id_low , uint32 log_id_high )
1998-03-12 00:11:04 +03:00
{
1999-12-13 16:27:58 +03:00
DEBUG ( 5 , ( " make_logon_id: %d \n " , __LINE__ ) ) ;
2003-05-26 20:54:39 +04:00
logonid - > low = log_id_low ;
logonid - > high = log_id_high ;
1999-12-13 16:27:58 +03:00
}
/*******************************************************************
Reads or writes a DOM_LOGON_ID structure .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1998-03-12 00:11:04 +03:00
2007-10-19 04:40:25 +04:00
bool smb_io_logon_id ( const char * desc , DOM_LOGON_ID * logonid , prs_struct * ps , int depth )
1999-12-13 16:27:58 +03:00
{
2003-05-26 20:54:39 +04:00
if ( logonid = = NULL )
1999-12-13 16:27:58 +03:00
return False ;
prs_debug ( ps , depth , desc , " smb_io_logon_id " ) ;
depth + + ;
if ( ! prs_align ( ps ) )
return False ;
2003-05-26 20:54:39 +04:00
if ( ! prs_uint32 ( " low " , ps , depth , & logonid - > low ) )
1999-12-13 16:27:58 +03:00
return False ;
2003-05-26 20:54:39 +04:00
if ( ! prs_uint32 ( " high " , ps , depth , & logonid - > high ) )
1999-12-13 16:27:58 +03:00
return False ;
return True ;
}
/*******************************************************************
Inits an OWF_INFO structure .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-11-13 02:20:50 +03:00
void init_owf_info ( OWF_INFO * hash , const uint8 data [ 16 ] )
1999-12-13 16:27:58 +03:00
{
DEBUG ( 5 , ( " init_owf_info: %d \n " , __LINE__ ) ) ;
1998-03-12 00:11:04 +03:00
if ( data ! = NULL )
memcpy ( hash - > data , data , sizeof ( hash - > data ) ) ;
else
1999-12-13 16:27:58 +03:00
memset ( ( char * ) hash - > data , ' \0 ' , sizeof ( hash - > data ) ) ;
1998-03-12 00:11:04 +03:00
}
/*******************************************************************
1999-12-13 16:27:58 +03:00
Reads or writes an OWF_INFO structure .
1998-03-12 00:11:04 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
2007-10-19 04:40:25 +04:00
bool smb_io_owf_info ( const char * desc , OWF_INFO * hash , prs_struct * ps , int depth )
1998-03-12 00:11:04 +03:00
{
1999-12-13 16:27:58 +03:00
if ( hash = = NULL )
return False ;
1998-03-12 00:11:04 +03:00
1998-03-24 03:37:53 +03:00
prs_debug ( ps , depth , desc , " smb_io_owf_info " ) ;
1998-03-12 00:11:04 +03:00
depth + + ;
1999-12-13 16:27:58 +03:00
if ( ! prs_align ( ps ) )
return False ;
1998-03-12 00:11:04 +03:00
1999-12-13 16:27:58 +03:00
if ( ! prs_uint8s ( False , " data " , ps , depth , hash - > data , 16 ) )
return False ;
1999-10-15 22:46:22 +04:00
return True ;
1998-03-12 00:11:04 +03:00
}
/*******************************************************************
1999-12-13 16:27:58 +03:00
Reads or writes a DOM_GID structure .
1998-03-12 00:11:04 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
2007-10-19 04:40:25 +04:00
bool smb_io_gid ( const char * desc , DOM_GID * gid , prs_struct * ps , int depth )
1998-03-12 00:11:04 +03:00
{
1999-12-13 16:27:58 +03:00
if ( gid = = NULL )
return False ;
1998-03-12 00:11:04 +03:00
prs_debug ( ps , depth , desc , " smb_io_gid " ) ;
depth + + ;
1999-12-13 16:27:58 +03:00
if ( ! prs_align ( ps ) )
return False ;
1998-03-12 00:11:04 +03:00
1999-12-13 16:27:58 +03:00
if ( ! prs_uint32 ( " g_rid " , ps , depth , & gid - > g_rid ) )
return False ;
if ( ! prs_uint32 ( " attr " , ps , depth , & gid - > attr ) )
return False ;
1999-10-15 22:46:22 +04:00
return True ;
1998-03-12 00:11:04 +03:00
}
/*******************************************************************
1999-12-13 16:27:58 +03:00
Reads or writes an POLICY_HND structure .
1998-03-12 00:11:04 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
2007-10-19 04:40:25 +04:00
bool smb_io_pol_hnd ( const char * desc , POLICY_HND * pol , prs_struct * ps , int depth )
1998-03-12 00:11:04 +03:00
{
1999-12-13 16:27:58 +03:00
if ( pol = = NULL )
return False ;
1998-03-12 00:11:04 +03:00
prs_debug ( ps , depth , desc , " smb_io_pol_hnd " ) ;
depth + + ;
1999-12-13 16:27:58 +03:00
if ( ! prs_align ( ps ) )
return False ;
2001-03-08 02:59:13 +03:00
if ( UNMARSHALLING ( ps ) )
ZERO_STRUCTP ( pol ) ;
1998-03-12 00:11:04 +03:00
2006-09-12 02:02:34 +04:00
if ( ! prs_uint32 ( " handle_type " , ps , depth , & pol - > handle_type ) )
2001-03-08 02:59:13 +03:00
return False ;
2006-09-19 04:12:11 +04:00
if ( ! smb_io_uuid ( " uuid " , ( struct GUID * ) & pol - > uuid , ps , depth ) )
1999-12-13 16:27:58 +03:00
return False ;
1999-10-15 22:46:22 +04:00
return True ;
1998-03-12 00:11:04 +03:00
}
2001-05-01 05:01:19 +04:00
/*******************************************************************
Create a UNISTR3 .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void init_unistr3 ( UNISTR3 * str , const char * buf )
{
if ( buf = = NULL ) {
str - > uni_str_len = 0 ;
str - > str . buffer = NULL ;
return ;
}
2005-01-08 03:51:12 +03:00
str - > uni_str_len = strlen ( buf ) + 1 ;
2001-05-01 05:01:19 +04:00
2007-04-30 04:48:20 +04:00
if ( str - > uni_str_len ) {
2007-08-30 23:48:31 +04:00
str - > str . buffer = TALLOC_ZERO_ARRAY ( talloc_tos ( ) , uint16 , str - > uni_str_len ) ;
2007-04-30 04:48:20 +04:00
if ( str - > str . buffer = = NULL )
2007-06-16 01:58:49 +04:00
smb_panic ( " init_unistr3: malloc fail " ) ;
2001-05-01 05:01:19 +04:00
2007-04-30 04:48:20 +04:00
rpcstr_push ( ( char * ) str - > str . buffer , buf , str - > uni_str_len * sizeof ( uint16 ) , STR_TERMINATE ) ;
} else {
str - > str . buffer = NULL ;
}
2001-05-01 05:01:19 +04:00
}
1998-03-12 00:11:04 +03:00
/*******************************************************************
1999-12-13 16:27:58 +03:00
Reads or writes a UNISTR3 structure .
1998-03-12 00:11:04 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
2007-10-19 04:40:25 +04:00
bool smb_io_unistr3 ( const char * desc , UNISTR3 * name , prs_struct * ps , int depth )
1998-03-12 00:11:04 +03:00
{
1999-12-13 16:27:58 +03:00
if ( name = = NULL )
return False ;
1998-03-12 00:11:04 +03:00
1998-11-10 22:05:00 +03:00
prs_debug ( ps , depth , desc , " smb_io_unistr3 " ) ;
1998-03-12 00:11:04 +03:00
depth + + ;
1999-12-13 16:27:58 +03:00
if ( ! prs_align ( ps ) )
return False ;
1998-03-12 00:11:04 +03:00
1999-12-13 16:27:58 +03:00
if ( ! prs_uint32 ( " uni_str_len " , ps , depth , & name - > uni_str_len ) )
return False ;
2005-05-23 20:25:31 +04:00
/* we're done if there is no string */
if ( name - > uni_str_len = = 0 )
return True ;
1998-03-12 00:11:04 +03:00
/* don't know if len is specified by uni_str_len member... */
/* assume unicode string is unicode-null-terminated, instead */
1999-12-13 16:27:58 +03:00
if ( ! prs_unistr3 ( True , " unistr " , name , ps , depth ) )
return False ;
1999-10-15 22:46:22 +04:00
return True ;
1998-03-12 00:11:04 +03:00
}
2000-05-12 18:28:46 +04:00
/*******************************************************************
Stream a uint64_struct
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
bool prs_uint64 ( const char * name , prs_struct * ps , int depth , uint64 * data64 )
2000-05-12 18:28:46 +04:00
{
2006-09-06 22:32:20 +04:00
if ( UNMARSHALLING ( ps ) ) {
uint32 high , low ;
if ( ! prs_uint32 ( name , ps , depth + 1 , & low ) )
return False ;
if ( ! prs_uint32 ( name , ps , depth + 1 , & high ) )
return False ;
* data64 = ( ( uint64_t ) high < < 32 ) + low ;
return True ;
} else {
uint32 high = ( * data64 ) > > 32 , low = ( * data64 ) & 0xFFFFFFFF ;
return prs_uint32 ( name , ps , depth + 1 , & low ) & &
prs_uint32 ( name , ps , depth + 1 , & high ) ;
}
2000-05-12 18:28:46 +04:00
}
2001-08-28 10:43:43 +04:00
/*******************************************************************
reads or writes a BUFHDR2 structure .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
bool smb_io_bufhdr2 ( const char * desc , BUFHDR2 * hdr , prs_struct * ps , int depth )
2001-08-28 10:43:43 +04:00
{
prs_debug ( ps , depth , desc , " smb_io_bufhdr2 " ) ;
depth + + ;
prs_align ( ps ) ;
prs_uint32 ( " info_level " , ps , depth , & ( hdr - > info_level ) ) ;
prs_uint32 ( " length " , ps , depth , & ( hdr - > length ) ) ;
prs_uint32 ( " buffer " , ps , depth , & ( hdr - > buffer ) ) ;
return True ;
}
2004-12-20 15:52:33 +03:00
/*******************************************************************
reads or writes a BUFHDR4 structure .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
bool smb_io_bufhdr4 ( const char * desc , BUFHDR4 * hdr , prs_struct * ps , int depth )
2004-12-20 15:52:33 +03:00
{
prs_debug ( ps , depth , desc , " smb_io_bufhdr4 " ) ;
depth + + ;
prs_align ( ps ) ;
2005-01-08 03:51:12 +03:00
prs_uint32 ( " size " , ps , depth , & hdr - > size ) ;
prs_uint32 ( " buffer " , ps , depth , & hdr - > buffer ) ;
2004-12-20 15:52:33 +03:00
return True ;
}
2001-08-28 10:43:43 +04:00
/*******************************************************************
2005-04-07 08:58:38 +04:00
reads or writes a RPC_DATA_BLOB structure .
2001-08-28 10:43:43 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2005-01-08 03:51:12 +03:00
2007-10-19 04:40:25 +04:00
bool smb_io_rpc_blob ( const char * desc , RPC_DATA_BLOB * blob , prs_struct * ps , int depth )
2001-08-28 10:43:43 +04:00
{
2005-04-07 08:58:38 +04:00
prs_debug ( ps , depth , desc , " smb_io_rpc_blob " ) ;
2001-08-28 10:43:43 +04:00
depth + + ;
prs_align ( ps ) ;
2005-04-07 08:58:38 +04:00
if ( ! prs_uint32 ( " buf_len " , ps , depth , & blob - > buf_len ) )
return False ;
if ( blob - > buf_len = = 0 )
return True ;
2005-01-08 03:51:12 +03:00
if ( UNMARSHALLING ( ps ) ) {
2005-04-07 08:58:38 +04:00
blob - > buffer = PRS_ALLOC_MEM ( ps , uint8 , blob - > buf_len ) ;
if ( ! blob - > buffer ) {
2005-01-08 03:51:12 +03:00
return False ;
}
2001-08-28 10:43:43 +04:00
}
2005-04-07 08:58:38 +04:00
if ( ! prs_uint8s ( True , " buffer " , ps , depth , blob - > buffer , blob - > buf_len ) )
return False ;
2001-08-28 10:43:43 +04:00
return True ;
}
/*******************************************************************
creates a UNIHDR structure .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
bool make_uni_hdr ( UNIHDR * hdr , int len )
2001-08-28 10:43:43 +04:00
{
if ( hdr = = NULL )
{
return False ;
}
hdr - > uni_str_len = 2 * len ;
hdr - > uni_max_len = 2 * len ;
hdr - > buffer = len ! = 0 ? 1 : 0 ;
return True ;
}
2000-05-12 18:28:46 +04:00
2001-08-28 10:43:43 +04:00
/*******************************************************************
creates a BUFHDR2 structure .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
bool make_bufhdr2 ( BUFHDR2 * hdr , uint32 info_level , uint32 length , uint32 buffer )
2001-08-28 10:43:43 +04:00
{
hdr - > info_level = info_level ;
hdr - > length = length ;
hdr - > buffer = buffer ;
return True ;
}
2005-03-15 22:43:44 +03:00
/*******************************************************************
return the length of a UNISTR string .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
uint32 str_len_uni ( UNISTR * source )
{
uint32 i = 0 ;
if ( ! source - > buffer )
return 0 ;
while ( source - > buffer [ i ] )
i + + ;
return i ;
}