2003-10-30 11:32:26 +03:00
/*
Unix SMB / CIFS implementation .
routines for marshalling / unmarshalling basic types
Copyright ( C ) Andrew Tridgell 2003
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-10-30 11:32:26 +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 06:07:03 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2003-10-30 11:32:26 +03:00
*/
# include "includes.h"
2005-02-01 07:12:44 +03:00
# include "system/network.h"
2006-03-18 18:42:57 +03:00
# include "librpc/ndr/libndr.h"
2003-10-30 11:32:26 +03:00
2003-12-16 12:02:58 +03:00
# define NDR_SVAL(ndr, ofs) (NDR_BE(ndr)?RSVAL(ndr->data,ofs):SVAL(ndr->data,ofs))
# define NDR_IVAL(ndr, ofs) (NDR_BE(ndr)?RIVAL(ndr->data,ofs):IVAL(ndr->data,ofs))
2004-10-15 11:19:09 +04:00
# define NDR_IVALS(ndr, ofs) (NDR_BE(ndr)?RIVALS(ndr->data,ofs):IVALS(ndr->data,ofs))
2003-12-16 12:02:58 +03:00
# define NDR_SSVAL(ndr, ofs, v) do { if (NDR_BE(ndr)) { RSSVAL(ndr->data,ofs,v); } else SSVAL(ndr->data,ofs,v); } while (0)
# define NDR_SIVAL(ndr, ofs, v) do { if (NDR_BE(ndr)) { RSIVAL(ndr->data,ofs,v); } else SIVAL(ndr->data,ofs,v); } while (0)
2004-10-15 11:19:09 +04:00
# define NDR_SIVALS(ndr, ofs, v) do { if (NDR_BE(ndr)) { RSIVALS(ndr->data,ofs,v); } else SIVALS(ndr->data,ofs,v); } while (0)
2003-12-16 12:02:58 +03:00
2004-09-02 14:45:58 +04:00
/*
check for data leaks from the server by looking for non - zero pad bytes
these could also indicate that real structure elements have been
mistaken for padding in the IDL
*/
2006-03-05 20:15:19 +03:00
_PUBLIC_ void ndr_check_padding ( struct ndr_pull * ndr , size_t n )
2004-09-02 14:45:58 +04:00
{
size_t ofs2 = ( ndr - > offset + ( n - 1 ) ) & ~ ( n - 1 ) ;
int i ;
for ( i = ndr - > offset ; i < ofs2 ; i + + ) {
if ( ndr - > data [ i ] ! = 0 ) {
break ;
}
}
if ( i < ofs2 ) {
2005-07-17 13:20:52 +04:00
DEBUG ( 0 , ( " WARNING: Non-zero padding to %d: " , ( int ) n ) ) ;
2004-09-02 14:45:58 +04:00
for ( i = ndr - > offset ; i < ofs2 ; i + + ) {
DEBUG ( 0 , ( " %02x " , ndr - > data [ i ] ) ) ;
}
DEBUG ( 0 , ( " \n " ) ) ;
}
}
2003-10-30 11:32:26 +03:00
/*
2005-03-15 17:25:59 +03:00
parse a int8_t
*/
2007-11-09 21:23:40 +03:00
_PUBLIC_ enum ndr_err_code ndr_pull_int8 ( struct ndr_pull * ndr , int ndr_flags , int8_t * v )
2005-03-15 17:25:59 +03:00
{
NDR_PULL_NEED_BYTES ( ndr , 1 ) ;
* v = ( int8_t ) CVAL ( ndr - > data , ndr - > offset ) ;
ndr - > offset + = 1 ;
2007-11-09 21:23:40 +03:00
return NDR_ERR_SUCCESS ;
2005-03-15 17:25:59 +03:00
}
/*
parse a uint8_t
2003-10-30 11:32:26 +03:00
*/
2007-11-09 21:23:40 +03:00
_PUBLIC_ enum ndr_err_code ndr_pull_uint8 ( struct ndr_pull * ndr , int ndr_flags , uint8_t * v )
2003-10-30 11:32:26 +03:00
{
2003-11-03 09:22:45 +03:00
NDR_PULL_NEED_BYTES ( ndr , 1 ) ;
2003-10-30 11:32:26 +03:00
* v = CVAL ( ndr - > data , ndr - > offset ) ;
ndr - > offset + = 1 ;
2007-11-09 21:23:40 +03:00
return NDR_ERR_SUCCESS ;
2003-10-30 11:32:26 +03:00
}
2005-03-15 17:25:59 +03:00
/*
parse a int16_t
*/
2007-11-09 21:23:40 +03:00
_PUBLIC_ enum ndr_err_code ndr_pull_int16 ( struct ndr_pull * ndr , int ndr_flags , int16_t * v )
2005-03-15 17:25:59 +03:00
{
NDR_PULL_ALIGN ( ndr , 2 ) ;
NDR_PULL_NEED_BYTES ( ndr , 2 ) ;
* v = ( uint16_t ) NDR_SVAL ( ndr , ndr - > offset ) ;
ndr - > offset + = 2 ;
2007-11-09 21:23:40 +03:00
return NDR_ERR_SUCCESS ;
2005-03-15 17:25:59 +03:00
}
2003-10-30 11:32:26 +03:00
/*
2005-03-15 17:25:59 +03:00
parse a uint16_t
2003-10-30 11:32:26 +03:00
*/
2007-11-09 21:23:40 +03:00
_PUBLIC_ enum ndr_err_code ndr_pull_uint16 ( struct ndr_pull * ndr , int ndr_flags , uint16_t * v )
2003-10-30 11:32:26 +03:00
{
2003-11-03 09:22:45 +03:00
NDR_PULL_ALIGN ( ndr , 2 ) ;
NDR_PULL_NEED_BYTES ( ndr , 2 ) ;
2003-12-16 12:02:58 +03:00
* v = NDR_SVAL ( ndr , ndr - > offset ) ;
2003-10-30 11:32:26 +03:00
ndr - > offset + = 2 ;
2007-11-09 21:23:40 +03:00
return NDR_ERR_SUCCESS ;
2003-10-30 11:32:26 +03:00
}
/*
2005-03-15 17:25:59 +03:00
parse a int32_t
2003-10-30 11:32:26 +03:00
*/
2007-11-09 21:23:40 +03:00
_PUBLIC_ enum ndr_err_code ndr_pull_int32 ( struct ndr_pull * ndr , int ndr_flags , int32_t * v )
2003-10-30 11:32:26 +03:00
{
2003-11-03 09:22:45 +03:00
NDR_PULL_ALIGN ( ndr , 4 ) ;
NDR_PULL_NEED_BYTES ( ndr , 4 ) ;
2005-03-15 17:25:59 +03:00
* v = NDR_IVALS ( ndr , ndr - > offset ) ;
2003-11-03 12:18:38 +03:00
ndr - > offset + = 4 ;
2007-11-09 21:23:40 +03:00
return NDR_ERR_SUCCESS ;
2003-11-03 12:18:38 +03:00
}
2004-10-15 11:19:09 +04:00
/*
2005-03-15 17:25:59 +03:00
parse a uint32_t
2004-10-15 11:19:09 +04:00
*/
2007-11-09 21:23:40 +03:00
_PUBLIC_ enum ndr_err_code ndr_pull_uint32 ( struct ndr_pull * ndr , int ndr_flags , uint32_t * v )
2004-10-15 11:19:09 +04:00
{
NDR_PULL_ALIGN ( ndr , 4 ) ;
NDR_PULL_NEED_BYTES ( ndr , 4 ) ;
2005-03-15 17:25:59 +03:00
* v = NDR_IVAL ( ndr , ndr - > offset ) ;
2004-10-15 11:19:09 +04:00
ndr - > offset + = 4 ;
2007-11-09 21:23:40 +03:00
return NDR_ERR_SUCCESS ;
2004-10-15 11:19:09 +04:00
}
2004-06-14 11:27:22 +04:00
/*
2005-02-13 00:43:08 +03:00
parse a pointer referent identifier
2004-06-14 11:27:22 +04:00
*/
2007-11-09 21:23:40 +03:00
_PUBLIC_ enum ndr_err_code ndr_pull_generic_ptr ( struct ndr_pull * ndr , uint32_t * v )
2004-06-14 11:27:22 +04:00
{
2007-11-02 12:32:47 +03:00
NDR_CHECK ( ndr_pull_uint32 ( ndr , NDR_SCALARS , v ) ) ;
if ( * v ! = 0 ) {
2004-08-12 09:15:41 +04:00
ndr - > ptr_count + + ;
}
2007-11-09 21:23:40 +03:00
return NDR_ERR_SUCCESS ;
2004-06-14 11:27:22 +04:00
}
2005-03-12 11:29:54 +03:00
/*
parse a ref pointer referent identifier
*/
2007-11-09 21:23:40 +03:00
_PUBLIC_ enum ndr_err_code ndr_pull_ref_ptr ( struct ndr_pull * ndr , uint32_t * v )
2005-03-12 11:29:54 +03:00
{
NDR_CHECK ( ndr_pull_uint32 ( ndr , NDR_SCALARS , v ) ) ;
/* ref pointers always point to data */
* v = 1 ;
2007-11-09 21:23:40 +03:00
return NDR_ERR_SUCCESS ;
2005-03-12 11:29:54 +03:00
}
2003-11-11 10:57:08 +03:00
/*
2005-01-27 09:16:59 +03:00
parse a udlong
2003-11-11 10:57:08 +03:00
*/
2007-11-09 21:23:40 +03:00
_PUBLIC_ enum ndr_err_code ndr_pull_udlong ( struct ndr_pull * ndr , int ndr_flags , uint64_t * v )
2003-11-11 10:57:08 +03:00
{
2004-05-25 17:57:39 +04:00
NDR_PULL_ALIGN ( ndr , 4 ) ;
2003-11-11 10:57:08 +03:00
NDR_PULL_NEED_BYTES ( ndr , 8 ) ;
2004-05-25 17:57:39 +04:00
* v = NDR_IVAL ( ndr , ndr - > offset ) ;
* v | = ( uint64_t ) ( NDR_IVAL ( ndr , ndr - > offset + 4 ) ) < < 32 ;
2003-11-11 10:57:08 +03:00
ndr - > offset + = 8 ;
2007-11-09 21:23:40 +03:00
return NDR_ERR_SUCCESS ;
2003-11-11 10:57:08 +03:00
}
2005-02-16 13:03:18 +03:00
/*
parse a udlongr
*/
2007-11-09 21:23:40 +03:00
_PUBLIC_ enum ndr_err_code ndr_pull_udlongr ( struct ndr_pull * ndr , int ndr_flags , uint64_t * v )
2005-02-16 13:03:18 +03:00
{
NDR_PULL_ALIGN ( ndr , 4 ) ;
NDR_PULL_NEED_BYTES ( ndr , 8 ) ;
* v = ( ( uint64_t ) NDR_IVAL ( ndr , ndr - > offset ) ) < < 32 ;
* v | = NDR_IVAL ( ndr , ndr - > offset + 4 ) ;
ndr - > offset + = 8 ;
2007-11-09 21:23:40 +03:00
return NDR_ERR_SUCCESS ;
2005-02-16 13:03:18 +03:00
}
2004-05-25 17:57:39 +04:00
/*
2005-01-27 09:16:59 +03:00
parse a dlong
2004-05-25 17:57:39 +04:00
*/
2007-11-09 21:23:40 +03:00
_PUBLIC_ enum ndr_err_code ndr_pull_dlong ( struct ndr_pull * ndr , int ndr_flags , int64_t * v )
2004-05-25 17:57:39 +04:00
{
2005-02-10 00:10:23 +03:00
return ndr_pull_udlong ( ndr , ndr_flags , ( uint64_t * ) v ) ;
2004-05-25 17:57:39 +04:00
}
/*
2005-01-27 09:16:59 +03:00
parse a hyper
2004-05-25 17:57:39 +04:00
*/
2007-11-09 21:23:40 +03:00
_PUBLIC_ enum ndr_err_code ndr_pull_hyper ( struct ndr_pull * ndr , int ndr_flags , uint64_t * v )
2004-05-25 17:57:39 +04:00
{
NDR_PULL_ALIGN ( ndr , 8 ) ;
2005-02-10 00:10:23 +03:00
return ndr_pull_udlong ( ndr , ndr_flags , v ) ;
2004-05-25 17:57:39 +04:00
}
2006-02-28 06:42:19 +03:00
/*
parse a pointer
*/
2007-11-09 21:23:40 +03:00
_PUBLIC_ enum ndr_err_code ndr_pull_pointer ( struct ndr_pull * ndr , int ndr_flags , void * * v )
2006-02-28 06:42:19 +03:00
{
2008-04-17 16:47:07 +04:00
uintptr_t h ;
2006-02-28 07:02:26 +03:00
NDR_PULL_ALIGN ( ndr , sizeof ( h ) ) ;
NDR_PULL_NEED_BYTES ( ndr , sizeof ( h ) ) ;
memcpy ( & h , ndr - > data + ndr - > offset , sizeof ( h ) ) ;
ndr - > offset + = sizeof ( h ) ;
* v = ( void * ) h ;
2007-11-09 21:23:40 +03:00
return NDR_ERR_SUCCESS ;
2006-02-28 06:42:19 +03:00
}
2003-11-04 12:10:31 +03:00
/*
pull a NTSTATUS
*/
2007-11-09 21:23:40 +03:00
_PUBLIC_ enum ndr_err_code ndr_pull_NTSTATUS ( struct ndr_pull * ndr , int ndr_flags , NTSTATUS * status )
2003-11-04 12:10:31 +03:00
{
2004-05-25 20:24:13 +04:00
uint32_t v ;
2005-02-10 00:10:23 +03:00
NDR_CHECK ( ndr_pull_uint32 ( ndr , NDR_SCALARS , & v ) ) ;
2003-11-04 12:10:31 +03:00
* status = NT_STATUS ( v ) ;
2007-11-09 21:23:40 +03:00
return NDR_ERR_SUCCESS ;
2003-11-04 12:10:31 +03:00
}
2003-11-22 11:11:32 +03:00
/*
push a NTSTATUS
*/
2007-11-09 21:23:40 +03:00
_PUBLIC_ enum ndr_err_code ndr_push_NTSTATUS ( struct ndr_push * ndr , int ndr_flags , NTSTATUS status )
2003-11-22 11:11:32 +03:00
{
2005-02-10 00:10:23 +03:00
return ndr_push_uint32 ( ndr , ndr_flags , NT_STATUS_V ( status ) ) ;
2003-11-22 11:11:32 +03:00
}
2006-03-05 20:15:19 +03:00
_PUBLIC_ void ndr_print_NTSTATUS ( struct ndr_print * ndr , const char * name , NTSTATUS r )
2003-11-18 04:18:24 +03:00
{
2005-02-17 14:42:38 +03:00
ndr - > print ( ndr , " %-25s: %s " , name , nt_errstr ( r ) ) ;
2003-11-18 04:18:24 +03:00
}
2003-11-17 05:58:10 +03:00
/*
pull a WERROR
*/
2007-11-09 21:23:40 +03:00
_PUBLIC_ enum ndr_err_code ndr_pull_WERROR ( struct ndr_pull * ndr , int ndr_flags , WERROR * status )
2003-11-17 05:58:10 +03:00
{
2004-05-25 20:24:13 +04:00
uint32_t v ;
2005-02-10 00:10:23 +03:00
NDR_CHECK ( ndr_pull_uint32 ( ndr , NDR_SCALARS , & v ) ) ;
2003-11-17 05:58:10 +03:00
* status = W_ERROR ( v ) ;
2007-11-09 21:23:40 +03:00
return NDR_ERR_SUCCESS ;
2003-11-17 05:58:10 +03:00
}
2003-11-22 11:11:32 +03:00
/*
push a WERROR
*/
2007-11-09 21:23:40 +03:00
_PUBLIC_ enum ndr_err_code ndr_push_WERROR ( struct ndr_push * ndr , int ndr_flags , WERROR status )
2003-11-22 11:11:32 +03:00
{
2005-02-10 00:10:23 +03:00
return ndr_push_uint32 ( ndr , NDR_SCALARS , W_ERROR_V ( status ) ) ;
2003-11-22 11:11:32 +03:00
}
2006-03-05 20:15:19 +03:00
_PUBLIC_ void ndr_print_WERROR ( struct ndr_print * ndr , const char * name , WERROR r )
2003-11-18 04:18:24 +03:00
{
2004-11-01 15:40:43 +03:00
ndr - > print ( ndr , " %-25s: %s " , name , win_errstr ( r ) ) ;
2003-11-18 04:18:24 +03:00
}
2003-11-03 12:18:38 +03:00
/*
parse a set of bytes
*/
2007-11-09 21:23:40 +03:00
_PUBLIC_ enum ndr_err_code ndr_pull_bytes ( struct ndr_pull * ndr , uint8_t * data , uint32_t n )
2003-11-03 12:18:38 +03:00
{
NDR_PULL_NEED_BYTES ( ndr , n ) ;
2003-11-04 12:10:31 +03:00
memcpy ( data , ndr - > data + ndr - > offset , n ) ;
2003-11-03 12:18:38 +03:00
ndr - > offset + = n ;
2007-11-09 21:23:40 +03:00
return NDR_ERR_SUCCESS ;
2003-10-30 11:32:26 +03:00
}
2003-11-09 10:24:06 +03:00
/*
pull an array of uint8
*/
2007-11-09 21:23:40 +03:00
_PUBLIC_ enum ndr_err_code ndr_pull_array_uint8 ( struct ndr_pull * ndr , int ndr_flags , uint8_t * data , uint32_t n )
2003-11-09 10:24:06 +03:00
{
2003-11-17 09:27:45 +03:00
if ( ! ( ndr_flags & NDR_SCALARS ) ) {
2007-11-09 21:23:40 +03:00
return NDR_ERR_SUCCESS ;
2003-11-17 09:27:45 +03:00
}
2003-11-13 12:26:53 +03:00
return ndr_pull_bytes ( ndr , data , n ) ;
2003-11-09 10:24:06 +03:00
}
2005-03-15 17:25:59 +03:00
/*
push a int8_t
*/
2007-11-09 21:23:40 +03:00
_PUBLIC_ enum ndr_err_code ndr_push_int8 ( struct ndr_push * ndr , int ndr_flags , int8_t v )
2005-03-15 17:25:59 +03:00
{
NDR_PUSH_NEED_BYTES ( ndr , 1 ) ;
SCVAL ( ndr - > data , ndr - > offset , ( uint8_t ) v ) ;
ndr - > offset + = 1 ;
2007-11-09 21:23:40 +03:00
return NDR_ERR_SUCCESS ;
2005-03-15 17:25:59 +03:00
}
2004-11-01 15:40:43 +03:00
2003-11-03 09:22:45 +03:00
/*
2005-03-15 17:25:59 +03:00
push a uint8_t
2003-11-03 09:22:45 +03:00
*/
2007-11-09 21:23:40 +03:00
_PUBLIC_ enum ndr_err_code ndr_push_uint8 ( struct ndr_push * ndr , int ndr_flags , uint8_t v )
2003-11-03 09:22:45 +03:00
{
NDR_PUSH_NEED_BYTES ( ndr , 1 ) ;
SCVAL ( ndr - > data , ndr - > offset , v ) ;
ndr - > offset + = 1 ;
2007-11-09 21:23:40 +03:00
return NDR_ERR_SUCCESS ;
2003-11-03 09:22:45 +03:00
}
/*
2005-03-15 17:25:59 +03:00
push a int16_t
*/
2007-11-09 21:23:40 +03:00
_PUBLIC_ enum ndr_err_code ndr_push_int16 ( struct ndr_push * ndr , int ndr_flags , int16_t v )
2005-03-15 17:25:59 +03:00
{
NDR_PUSH_ALIGN ( ndr , 2 ) ;
NDR_PUSH_NEED_BYTES ( ndr , 2 ) ;
NDR_SSVAL ( ndr , ndr - > offset , ( uint16_t ) v ) ;
ndr - > offset + = 2 ;
2007-11-09 21:23:40 +03:00
return NDR_ERR_SUCCESS ;
2005-03-15 17:25:59 +03:00
}
/*
push a uint16_t
2003-11-03 09:22:45 +03:00
*/
2007-11-09 21:23:40 +03:00
_PUBLIC_ enum ndr_err_code ndr_push_uint16 ( struct ndr_push * ndr , int ndr_flags , uint16_t v )
2003-11-03 09:22:45 +03:00
{
NDR_PUSH_ALIGN ( ndr , 2 ) ;
NDR_PUSH_NEED_BYTES ( ndr , 2 ) ;
2003-12-16 12:02:58 +03:00
NDR_SSVAL ( ndr , ndr - > offset , v ) ;
2003-11-03 09:22:45 +03:00
ndr - > offset + = 2 ;
2007-11-09 21:23:40 +03:00
return NDR_ERR_SUCCESS ;
2003-11-03 09:22:45 +03:00
}
/*
2005-03-15 17:25:59 +03:00
push a int32_t
2003-11-03 09:22:45 +03:00
*/
2007-11-09 21:23:40 +03:00
_PUBLIC_ enum ndr_err_code ndr_push_int32 ( struct ndr_push * ndr , int ndr_flags , int32_t v )
2003-11-03 09:22:45 +03:00
{
NDR_PUSH_ALIGN ( ndr , 4 ) ;
NDR_PUSH_NEED_BYTES ( ndr , 4 ) ;
2005-03-15 17:25:59 +03:00
NDR_SIVALS ( ndr , ndr - > offset , v ) ;
2003-11-03 09:22:45 +03:00
ndr - > offset + = 4 ;
2007-11-09 21:23:40 +03:00
return NDR_ERR_SUCCESS ;
2003-11-03 09:22:45 +03:00
}
2003-11-03 12:18:38 +03:00
2004-10-15 11:19:09 +04:00
/*
2005-03-15 17:25:59 +03:00
push a uint32_t
2004-10-15 11:19:09 +04:00
*/
2007-11-09 21:23:40 +03:00
_PUBLIC_ enum ndr_err_code ndr_push_uint32 ( struct ndr_push * ndr , int ndr_flags , uint32_t v )
2004-10-15 11:19:09 +04:00
{
NDR_PUSH_ALIGN ( ndr , 4 ) ;
NDR_PUSH_NEED_BYTES ( ndr , 4 ) ;
2005-03-15 17:25:59 +03:00
NDR_SIVAL ( ndr , ndr - > offset , v ) ;
2004-10-15 11:19:09 +04:00
ndr - > offset + = 4 ;
2007-11-09 21:23:40 +03:00
return NDR_ERR_SUCCESS ;
2004-10-15 11:19:09 +04:00
}
2003-11-11 10:57:08 +03:00
/*
2005-02-16 13:03:18 +03:00
push a udlong
2003-11-11 10:57:08 +03:00
*/
2007-11-09 21:23:40 +03:00
_PUBLIC_ enum ndr_err_code ndr_push_udlong ( struct ndr_push * ndr , int ndr_flags , uint64_t v )
2003-11-11 10:57:08 +03:00
{
2004-05-25 17:57:39 +04:00
NDR_PUSH_ALIGN ( ndr , 4 ) ;
2003-11-11 10:57:08 +03:00
NDR_PUSH_NEED_BYTES ( ndr , 8 ) ;
2004-05-25 17:57:39 +04:00
NDR_SIVAL ( ndr , ndr - > offset , ( v & 0xFFFFFFFF ) ) ;
NDR_SIVAL ( ndr , ndr - > offset + 4 , ( v > > 32 ) ) ;
2003-11-11 10:57:08 +03:00
ndr - > offset + = 8 ;
2007-11-09 21:23:40 +03:00
return NDR_ERR_SUCCESS ;
2003-11-11 10:57:08 +03:00
}
2005-02-16 13:03:18 +03:00
/*
push a udlongr
*/
2007-11-09 21:23:40 +03:00
_PUBLIC_ enum ndr_err_code ndr_push_udlongr ( struct ndr_push * ndr , int ndr_flags , uint64_t v )
2005-02-16 13:03:18 +03:00
{
NDR_PUSH_ALIGN ( ndr , 4 ) ;
NDR_PUSH_NEED_BYTES ( ndr , 8 ) ;
2005-09-20 11:56:54 +04:00
NDR_SIVAL ( ndr , ndr - > offset , ( v > > 32 ) ) ;
NDR_SIVAL ( ndr , ndr - > offset + 4 , ( v & 0xFFFFFFFF ) ) ;
2005-02-16 13:03:18 +03:00
ndr - > offset + = 8 ;
2007-11-09 21:23:40 +03:00
return NDR_ERR_SUCCESS ;
2005-02-16 13:03:18 +03:00
}
2004-05-25 17:57:39 +04:00
/*
2005-03-15 17:25:59 +03:00
push a dlong
2004-05-25 17:57:39 +04:00
*/
2007-11-09 21:23:40 +03:00
_PUBLIC_ enum ndr_err_code ndr_push_dlong ( struct ndr_push * ndr , int ndr_flags , int64_t v )
2004-05-25 17:57:39 +04:00
{
2005-02-10 00:10:23 +03:00
return ndr_push_udlong ( ndr , NDR_SCALARS , ( uint64_t ) v ) ;
2004-05-25 17:57:39 +04:00
}
/*
2005-01-27 09:33:07 +03:00
push a hyper
2004-05-25 17:57:39 +04:00
*/
2007-11-09 21:23:40 +03:00
_PUBLIC_ enum ndr_err_code ndr_push_hyper ( struct ndr_push * ndr , int ndr_flags , uint64_t v )
2004-05-25 17:57:39 +04:00
{
NDR_PUSH_ALIGN ( ndr , 8 ) ;
2005-02-10 00:10:23 +03:00
return ndr_push_udlong ( ndr , NDR_SCALARS , v ) ;
2004-05-25 17:57:39 +04:00
}
2006-02-28 06:42:19 +03:00
/*
push a pointer
*/
2007-11-09 21:23:40 +03:00
_PUBLIC_ enum ndr_err_code ndr_push_pointer ( struct ndr_push * ndr , int ndr_flags , void * v )
2006-02-28 06:42:19 +03:00
{
2008-04-17 16:47:07 +04:00
uintptr_t h = ( intptr_t ) v ;
2006-02-28 07:02:26 +03:00
NDR_PUSH_ALIGN ( ndr , sizeof ( h ) ) ;
NDR_PUSH_NEED_BYTES ( ndr , sizeof ( h ) ) ;
memcpy ( ndr - > data + ndr - > offset , & h , sizeof ( h ) ) ;
ndr - > offset + = sizeof ( h ) ;
2007-11-09 21:23:40 +03:00
return NDR_ERR_SUCCESS ;
2006-02-28 06:42:19 +03:00
}
2007-11-09 21:23:40 +03:00
_PUBLIC_ enum ndr_err_code ndr_push_align ( struct ndr_push * ndr , size_t size )
2003-11-06 15:34:04 +03:00
{
2003-11-11 09:54:54 +03:00
NDR_PUSH_ALIGN ( ndr , size ) ;
2007-11-09 21:23:40 +03:00
return NDR_ERR_SUCCESS ;
2003-11-11 09:54:54 +03:00
}
2007-11-09 21:23:40 +03:00
_PUBLIC_ enum ndr_err_code ndr_pull_align ( struct ndr_pull * ndr , size_t size )
2003-11-11 09:54:54 +03:00
{
NDR_PULL_ALIGN ( ndr , size ) ;
2007-11-09 21:23:40 +03:00
return NDR_ERR_SUCCESS ;
2003-11-06 15:34:04 +03:00
}
2003-11-03 12:18:38 +03:00
/*
push some bytes
*/
2007-11-09 21:23:40 +03:00
_PUBLIC_ enum ndr_err_code ndr_push_bytes ( struct ndr_push * ndr , const uint8_t * data , uint32_t n )
2003-11-03 12:18:38 +03:00
{
NDR_PUSH_NEED_BYTES ( ndr , n ) ;
memcpy ( ndr - > data + ndr - > offset , data , n ) ;
ndr - > offset + = n ;
2007-11-09 21:23:40 +03:00
return NDR_ERR_SUCCESS ;
2003-11-03 12:18:38 +03:00
}
2003-11-04 12:10:31 +03:00
2003-11-26 04:16:41 +03:00
/*
push some zero bytes
*/
2007-11-09 21:23:40 +03:00
_PUBLIC_ enum ndr_err_code ndr_push_zero ( struct ndr_push * ndr , uint32_t n )
2003-11-26 04:16:41 +03:00
{
NDR_PUSH_NEED_BYTES ( ndr , n ) ;
memset ( ndr - > data + ndr - > offset , 0 , n ) ;
ndr - > offset + = n ;
2007-11-09 21:23:40 +03:00
return NDR_ERR_SUCCESS ;
2003-11-26 04:16:41 +03:00
}
2003-11-09 10:24:06 +03:00
/*
push an array of uint8
*/
2007-11-09 21:23:40 +03:00
_PUBLIC_ enum ndr_err_code ndr_push_array_uint8 ( struct ndr_push * ndr , int ndr_flags , const uint8_t * data , uint32_t n )
2003-11-09 10:24:06 +03:00
{
2003-11-17 09:27:45 +03:00
if ( ! ( ndr_flags & NDR_SCALARS ) ) {
2007-11-09 21:23:40 +03:00
return NDR_ERR_SUCCESS ;
2003-11-17 09:27:45 +03:00
}
2003-11-09 10:24:06 +03:00
return ndr_push_bytes ( ndr , data , n ) ;
}
2003-11-04 12:10:31 +03:00
/*
2005-03-12 11:29:54 +03:00
push a unique non - zero value if a pointer is non - NULL , otherwise 0
2003-11-04 12:10:31 +03:00
*/
2007-11-09 21:23:40 +03:00
_PUBLIC_ enum ndr_err_code ndr_push_unique_ptr ( struct ndr_push * ndr , const void * p )
2003-11-04 12:10:31 +03:00
{
2004-05-25 20:24:13 +04:00
uint32_t ptr = 0 ;
2003-11-20 06:09:19 +03:00
if ( p ) {
2005-07-05 10:17:47 +04:00
ptr = ndr - > ptr_count * 4 ;
ptr | = 0x00020000 ;
ndr - > ptr_count + + ;
2005-07-05 16:09:33 +04:00
}
return ndr_push_uint32 ( ndr , NDR_SCALARS , ptr ) ;
}
/*
push a ' simple ' full non - zero value if a pointer is non - NULL , otherwise 0
*/
2007-11-09 21:23:40 +03:00
_PUBLIC_ enum ndr_err_code ndr_push_full_ptr ( struct ndr_push * ndr , const void * p )
2005-07-05 16:09:33 +04:00
{
uint32_t ptr = 0 ;
if ( p ) {
2006-11-23 19:02:20 +03:00
/* Check if the pointer already exists and has an id */
ptr = ndr_token_peek ( & ndr - > full_ptr_list , p ) ;
if ( ptr = = 0 ) {
ndr - > ptr_count + + ;
ptr = ndr - > ptr_count ;
ndr_token_store ( ndr , & ndr - > full_ptr_list , p , ptr ) ;
}
2003-11-20 06:09:19 +03:00
}
2005-02-10 00:10:23 +03:00
return ndr_push_uint32 ( ndr , NDR_SCALARS , ptr ) ;
2003-11-04 12:10:31 +03:00
}
2005-03-12 11:29:54 +03:00
/*
push always a 0 , if a pointer is NULL it ' s a fatal error
*/
2007-11-09 21:23:40 +03:00
_PUBLIC_ enum ndr_err_code ndr_push_ref_ptr ( struct ndr_push * ndr )
2005-03-12 11:29:54 +03:00
{
2005-05-02 18:53:19 +04:00
return ndr_push_uint32 ( ndr , NDR_SCALARS , 0xAEF1AEF1 ) ;
2005-03-12 11:29:54 +03:00
}
2003-11-04 12:10:31 +03:00
2004-11-02 16:46:39 +03:00
2003-11-11 05:02:29 +03:00
/*
push a NTTIME
*/
2007-11-09 21:23:40 +03:00
_PUBLIC_ enum ndr_err_code ndr_push_NTTIME ( struct ndr_push * ndr , int ndr_flags , NTTIME t )
2003-11-11 05:02:29 +03:00
{
2005-02-10 00:10:23 +03:00
NDR_CHECK ( ndr_push_udlong ( ndr , ndr_flags , t ) ) ;
2007-11-09 21:23:40 +03:00
return NDR_ERR_SUCCESS ;
2003-11-11 05:02:29 +03:00
}
/*
pull a NTTIME
*/
2007-11-09 21:23:40 +03:00
_PUBLIC_ enum ndr_err_code ndr_pull_NTTIME ( struct ndr_pull * ndr , int ndr_flags , NTTIME * t )
2003-11-11 05:02:29 +03:00
{
2005-02-10 00:10:23 +03:00
NDR_CHECK ( ndr_pull_udlong ( ndr , ndr_flags , t ) ) ;
2007-11-09 21:23:40 +03:00
return NDR_ERR_SUCCESS ;
2003-11-11 05:02:29 +03:00
}
2003-11-11 07:04:36 +03:00
2004-11-19 05:35:48 +03:00
/*
push a NTTIME
*/
2007-11-09 21:23:40 +03:00
_PUBLIC_ enum ndr_err_code ndr_push_NTTIME_1sec ( struct ndr_push * ndr , int ndr_flags , NTTIME t )
2004-11-19 05:35:48 +03:00
{
t / = 10000000 ;
2005-02-10 00:10:23 +03:00
NDR_CHECK ( ndr_push_hyper ( ndr , ndr_flags , t ) ) ;
2007-11-09 21:23:40 +03:00
return NDR_ERR_SUCCESS ;
2004-11-19 05:35:48 +03:00
}
/*
2005-01-11 08:16:43 +03:00
pull a NTTIME_1sec
2004-11-19 05:35:48 +03:00
*/
2007-11-09 21:23:40 +03:00
_PUBLIC_ enum ndr_err_code ndr_pull_NTTIME_1sec ( struct ndr_pull * ndr , int ndr_flags , NTTIME * t )
2004-11-19 05:35:48 +03:00
{
2005-02-10 00:10:23 +03:00
NDR_CHECK ( ndr_pull_hyper ( ndr , ndr_flags , t ) ) ;
2004-11-19 05:35:48 +03:00
( * t ) * = 10000000 ;
2007-11-09 21:23:40 +03:00
return NDR_ERR_SUCCESS ;
2004-11-19 05:35:48 +03:00
}
2005-01-11 08:16:43 +03:00
/*
pull a NTTIME_hyper
*/
2007-11-09 21:23:40 +03:00
_PUBLIC_ enum ndr_err_code ndr_pull_NTTIME_hyper ( struct ndr_pull * ndr , int ndr_flags , NTTIME * t )
2005-01-11 08:16:43 +03:00
{
2005-02-10 00:10:23 +03:00
NDR_CHECK ( ndr_pull_hyper ( ndr , ndr_flags , t ) ) ;
2007-11-09 21:23:40 +03:00
return NDR_ERR_SUCCESS ;
2005-01-11 08:16:43 +03:00
}
/*
push a NTTIME_hyper
*/
2007-11-09 21:23:40 +03:00
_PUBLIC_ enum ndr_err_code ndr_push_NTTIME_hyper ( struct ndr_push * ndr , int ndr_flags , NTTIME t )
2005-01-11 08:16:43 +03:00
{
2005-02-10 00:10:23 +03:00
NDR_CHECK ( ndr_push_hyper ( ndr , ndr_flags , t ) ) ;
2007-11-09 21:23:40 +03:00
return NDR_ERR_SUCCESS ;
2005-01-11 08:16:43 +03:00
}
2003-12-01 04:41:38 +03:00
/*
push a time_t
*/
2007-11-09 21:23:40 +03:00
_PUBLIC_ enum ndr_err_code ndr_push_time_t ( struct ndr_push * ndr , int ndr_flags , time_t t )
2003-12-01 04:41:38 +03:00
{
2005-02-10 00:10:23 +03:00
return ndr_push_uint32 ( ndr , ndr_flags , t ) ;
2003-12-01 04:41:38 +03:00
}
/*
pull a time_t
*/
2007-11-09 21:23:40 +03:00
_PUBLIC_ enum ndr_err_code ndr_pull_time_t ( struct ndr_pull * ndr , int ndr_flags , time_t * t )
2003-12-01 04:41:38 +03:00
{
2004-05-25 20:24:13 +04:00
uint32_t tt ;
2005-02-10 00:10:23 +03:00
NDR_CHECK ( ndr_pull_uint32 ( ndr , ndr_flags , & tt ) ) ;
2003-12-01 04:41:38 +03:00
* t = tt ;
2007-11-09 21:23:40 +03:00
return NDR_ERR_SUCCESS ;
2003-12-01 04:41:38 +03:00
}
2003-11-11 07:04:36 +03:00
2005-02-01 07:12:44 +03:00
/*
pull a ipv4address
*/
2007-11-09 21:23:40 +03:00
_PUBLIC_ enum ndr_err_code ndr_pull_ipv4address ( struct ndr_pull * ndr , int ndr_flags , const char * * address )
2005-02-01 07:12:44 +03:00
{
2007-10-13 22:24:37 +04:00
struct in_addr in ;
NDR_CHECK ( ndr_pull_uint32 ( ndr , ndr_flags , & in . s_addr ) ) ;
in . s_addr = htonl ( in . s_addr ) ;
* address = talloc_strdup ( ndr - > current_mem_ctx , inet_ntoa ( in ) ) ;
2007-11-09 21:23:40 +03:00
NDR_ERR_HAVE_NO_MEMORY ( * address ) ;
return NDR_ERR_SUCCESS ;
2005-02-01 07:12:44 +03:00
}
/*
push a ipv4address
*/
2007-11-09 21:23:40 +03:00
_PUBLIC_ enum ndr_err_code ndr_push_ipv4address ( struct ndr_push * ndr , int ndr_flags , const char * address )
2005-02-01 07:12:44 +03:00
{
2005-09-20 15:39:40 +04:00
uint32_t addr ;
2005-11-30 16:10:44 +03:00
if ( ! is_ipaddress ( address ) ) {
return ndr_push_error ( ndr , NDR_ERR_IPV4ADDRESS ,
" Invalid IPv4 address: '%s' " ,
address ) ;
}
2005-09-23 04:38:22 +04:00
addr = inet_addr ( address ) ;
2005-02-10 00:10:23 +03:00
NDR_CHECK ( ndr_push_uint32 ( ndr , ndr_flags , htonl ( addr ) ) ) ;
2007-11-09 21:23:40 +03:00
return NDR_ERR_SUCCESS ;
2005-02-01 07:12:44 +03:00
}
/*
print a ipv4address
*/
2006-03-05 20:15:19 +03:00
_PUBLIC_ void ndr_print_ipv4address ( struct ndr_print * ndr , const char * name ,
2005-02-01 07:12:44 +03:00
const char * address )
{
ndr - > print ( ndr , " %-25s: %s " , name , address ) ;
}
2006-03-05 20:15:19 +03:00
_PUBLIC_ void ndr_print_struct ( struct ndr_print * ndr , const char * name , const char * type )
2003-11-11 07:04:36 +03:00
{
2003-11-11 07:38:51 +03:00
ndr - > print ( ndr , " %s: struct %s " , name , type ) ;
2003-11-11 07:04:36 +03:00
}
2006-03-05 20:15:19 +03:00
_PUBLIC_ void ndr_print_enum ( struct ndr_print * ndr , const char * name , const char * type ,
2006-05-03 13:10:45 +04:00
const char * val , uint32_t value )
2005-01-05 02:26:12 +03:00
{
2005-01-06 10:29:55 +03:00
if ( ndr - > flags & LIBNDR_PRINT_ARRAY_HEX ) {
ndr - > print ( ndr , " %-25s: %s (0x%X) " , name , val ? val : " UNKNOWN_ENUM_VALUE " , value ) ;
} else {
ndr - > print ( ndr , " %-25s: %s (%d) " , name , val ? val : " UNKNOWN_ENUM_VALUE " , value ) ;
}
2005-01-05 18:36:26 +03:00
}
2006-05-03 13:10:45 +04:00
_PUBLIC_ void ndr_print_bitmap_flag ( struct ndr_print * ndr , size_t size , const char * flag_name , uint32_t flag , uint32_t value )
2005-01-05 18:36:26 +03:00
{
2005-01-21 09:54:10 +03:00
/* this is an attempt to support multi-bit bitmap masks */
value & = flag ;
while ( ! ( flag & 1 ) ) {
flag > > = 1 ;
value > > = 1 ;
}
if ( flag = = 1 ) {
ndr - > print ( ndr , " %d: %-25s " , value , flag_name ) ;
} else {
ndr - > print ( ndr , " 0x%02x: %-25s (%d) " , value , flag_name , value ) ;
}
2005-01-05 02:26:12 +03:00
}
2006-03-05 20:15:19 +03:00
_PUBLIC_ void ndr_print_int8 ( struct ndr_print * ndr , const char * name , int8_t v )
2005-03-15 17:25:59 +03:00
{
ndr - > print ( ndr , " %-25s: %d " , name , v ) ;
}
2006-03-05 20:15:19 +03:00
_PUBLIC_ void ndr_print_uint8 ( struct ndr_print * ndr , const char * name , uint8_t v )
2003-11-11 07:04:36 +03:00
{
ndr - > print ( ndr , " %-25s: 0x%02x (%u) " , name , v , v ) ;
}
2006-03-05 20:15:19 +03:00
_PUBLIC_ void ndr_print_int16 ( struct ndr_print * ndr , const char * name , int16_t v )
2003-11-11 07:04:36 +03:00
{
2005-03-15 17:25:59 +03:00
ndr - > print ( ndr , " %-25s: %d " , name , v ) ;
2003-11-11 07:04:36 +03:00
}
2006-03-05 20:15:19 +03:00
_PUBLIC_ void ndr_print_uint16 ( struct ndr_print * ndr , const char * name , uint16_t v )
2003-11-11 07:04:36 +03:00
{
2005-03-15 17:25:59 +03:00
ndr - > print ( ndr , " %-25s: 0x%04x (%u) " , name , v , v ) ;
2003-11-11 07:04:36 +03:00
}
2006-03-05 20:15:19 +03:00
_PUBLIC_ void ndr_print_int32 ( struct ndr_print * ndr , const char * name , int32_t v )
2004-10-15 11:19:09 +04:00
{
ndr - > print ( ndr , " %-25s: %d " , name , v ) ;
}
2006-03-05 20:15:19 +03:00
_PUBLIC_ void ndr_print_uint32 ( struct ndr_print * ndr , const char * name , uint32_t v )
2005-03-15 17:25:59 +03:00
{
ndr - > print ( ndr , " %-25s: 0x%08x (%u) " , name , v , v ) ;
}
2006-03-05 20:15:19 +03:00
_PUBLIC_ void ndr_print_udlong ( struct ndr_print * ndr , const char * name , uint64_t v )
2004-05-25 17:57:39 +04:00
{
2006-09-09 14:05:58 +04:00
ndr - > print ( ndr , " %-25s: 0x%016llx (%llu) " , name , ( unsigned long long ) v , ( unsigned long long ) v ) ;
2004-05-25 17:57:39 +04:00
}
2006-03-05 20:15:19 +03:00
_PUBLIC_ void ndr_print_udlongr ( struct ndr_print * ndr , const char * name , uint64_t v )
2005-02-16 13:03:18 +03:00
{
ndr_print_udlong ( ndr , name , v ) ;
}
2006-03-05 20:15:19 +03:00
_PUBLIC_ void ndr_print_dlong ( struct ndr_print * ndr , const char * name , int64_t v )
2004-05-25 17:57:39 +04:00
{
2006-09-09 14:05:58 +04:00
ndr - > print ( ndr , " %-25s: 0x%016llx (%lld) " , name , ( unsigned long long ) v , ( long long ) v ) ;
2004-05-25 17:57:39 +04:00
}
2006-03-05 20:15:19 +03:00
_PUBLIC_ void ndr_print_hyper ( struct ndr_print * ndr , const char * name , uint64_t v )
2003-11-11 10:57:08 +03:00
{
2005-01-27 09:16:59 +03:00
ndr_print_dlong ( ndr , name , v ) ;
2003-11-11 10:57:08 +03:00
}
2006-03-05 20:15:19 +03:00
_PUBLIC_ void ndr_print_pointer ( struct ndr_print * ndr , const char * name , void * v )
2006-02-28 06:42:19 +03:00
{
ndr - > print ( ndr , " %-25s: %p " , name , v ) ;
}
2006-03-05 20:15:19 +03:00
_PUBLIC_ void ndr_print_ptr ( struct ndr_print * ndr , const char * name , const void * p )
2003-11-11 07:04:36 +03:00
{
if ( p ) {
ndr - > print ( ndr , " %-25s: * " , name ) ;
} else {
ndr - > print ( ndr , " %-25s: NULL " , name ) ;
}
}
2006-03-05 20:15:19 +03:00
_PUBLIC_ void ndr_print_NTTIME ( struct ndr_print * ndr , const char * name , NTTIME t )
2003-11-11 07:04:36 +03:00
{
2004-08-21 11:43:29 +04:00
ndr - > print ( ndr , " %-25s: %s " , name , nt_time_string ( ndr , t ) ) ;
2003-11-11 07:04:36 +03:00
}
2003-11-11 07:38:51 +03:00
2006-03-05 20:15:19 +03:00
_PUBLIC_ void ndr_print_NTTIME_1sec ( struct ndr_print * ndr , const char * name , NTTIME t )
2005-01-11 08:16:43 +03:00
{
2005-01-11 09:47:15 +03:00
/* this is a standard NTTIME here
* as it ' s already converted in the pull / push code
*/
ndr_print_NTTIME ( ndr , name , t ) ;
2005-01-11 08:16:43 +03:00
}
2006-03-05 20:15:19 +03:00
_PUBLIC_ void ndr_print_NTTIME_hyper ( struct ndr_print * ndr , const char * name , NTTIME t )
2004-11-19 05:35:48 +03:00
{
ndr_print_NTTIME ( ndr , name , t ) ;
}
2006-03-05 20:15:19 +03:00
_PUBLIC_ void ndr_print_time_t ( struct ndr_print * ndr , const char * name , time_t t )
2003-12-01 04:41:38 +03:00
{
if ( t = = ( time_t ) - 1 | | t = = 0 ) {
ndr - > print ( ndr , " %-25s: (time_t)%d " , name , ( int ) t ) ;
} else {
2004-08-21 11:43:29 +04:00
ndr - > print ( ndr , " %-25s: %s " , name , timestring ( ndr , t ) ) ;
2003-12-01 04:41:38 +03:00
}
}
2006-03-05 20:15:19 +03:00
_PUBLIC_ void ndr_print_union ( struct ndr_print * ndr , const char * name , int level , const char * type )
2003-11-11 07:38:51 +03:00
{
2005-10-10 15:47:23 +04:00
if ( ndr - > flags & LIBNDR_PRINT_ARRAY_HEX ) {
ndr - > print ( ndr , " %-25s: union %s(case 0x%X) " , name , type , level ) ;
} else {
ndr - > print ( ndr , " %-25s: union %s(case %d) " , name , type , level ) ;
}
2003-11-11 07:38:51 +03:00
}
2006-03-05 20:15:19 +03:00
_PUBLIC_ void ndr_print_bad_level ( struct ndr_print * ndr , const char * name , uint16_t level )
2003-11-11 07:38:51 +03:00
{
ndr - > print ( ndr , " UNKNOWN LEVEL %u " , level ) ;
}
2003-11-11 09:22:58 +03:00
2006-03-05 20:15:19 +03:00
_PUBLIC_ void ndr_print_array_uint8 ( struct ndr_print * ndr , const char * name ,
2004-05-25 21:50:17 +04:00
const uint8_t * data , uint32_t count )
2003-11-15 13:58:29 +03:00
{
int i ;
2004-04-19 09:48:03 +04:00
if ( count < = 600 & & ( ndr - > flags & LIBNDR_PRINT_ARRAY_HEX ) ) {
char s [ 1202 ] ;
2003-12-01 06:19:43 +03:00
for ( i = 0 ; i < count ; i + + ) {
snprintf ( & s [ i * 2 ] , 3 , " %02x " , data [ i ] ) ;
}
s [ i * 2 ] = 0 ;
ndr - > print ( ndr , " %-25s: %s " , name , s ) ;
return ;
}
2003-11-15 13:58:29 +03:00
ndr - > print ( ndr , " %s: ARRAY(%d) " , name , count ) ;
ndr - > depth + + ;
for ( i = 0 ; i < count ; i + + ) {
char * idx = NULL ;
asprintf ( & idx , " [%d] " , i ) ;
if ( idx ) {
ndr_print_uint8 ( ndr , idx , data [ i ] ) ;
free ( idx ) ;
}
}
ndr - > depth - - ;
}
2006-03-05 20:15:19 +03:00
_PUBLIC_ void ndr_print_DATA_BLOB ( struct ndr_print * ndr , const char * name , DATA_BLOB r )
2003-11-17 14:55:56 +03:00
{
2006-09-09 14:05:58 +04:00
ndr - > print ( ndr , " %-25s: DATA_BLOB length=%u " , name , ( unsigned ) r . length ) ;
2003-11-24 13:15:17 +03:00
if ( r . length ) {
dump_data ( 10 , r . data , r . length ) ;
}
2003-11-17 14:55:56 +03:00
}
2003-11-17 05:18:11 +03:00
/*
push a DATA_BLOB onto the wire .
*/
2007-11-09 21:23:40 +03:00
_PUBLIC_ enum ndr_err_code ndr_push_DATA_BLOB ( struct ndr_push * ndr , int ndr_flags , DATA_BLOB blob )
2003-11-17 05:18:11 +03:00
{
2003-11-23 09:28:12 +03:00
if ( ndr - > flags & LIBNDR_ALIGN_FLAGS ) {
if ( ndr - > flags & LIBNDR_FLAG_ALIGN2 ) {
blob . length = NDR_ALIGN ( ndr , 2 ) ;
} else if ( ndr - > flags & LIBNDR_FLAG_ALIGN4 ) {
blob . length = NDR_ALIGN ( ndr , 4 ) ;
} else if ( ndr - > flags & LIBNDR_FLAG_ALIGN8 ) {
blob . length = NDR_ALIGN ( ndr , 8 ) ;
}
NDR_PUSH_ALLOC_SIZE ( ndr , blob . data , blob . length ) ;
data_blob_clear ( & blob ) ;
} else if ( ! ( ndr - > flags & LIBNDR_FLAG_REMAINING ) ) {
2005-02-10 00:10:23 +03:00
NDR_CHECK ( ndr_push_uint32 ( ndr , NDR_SCALARS , blob . length ) ) ;
2003-11-23 09:28:12 +03:00
}
2003-11-17 05:18:11 +03:00
NDR_CHECK ( ndr_push_bytes ( ndr , blob . data , blob . length ) ) ;
2007-11-09 21:23:40 +03:00
return NDR_ERR_SUCCESS ;
2003-11-17 05:18:11 +03:00
}
/*
pull a DATA_BLOB from the wire .
*/
2007-11-09 21:23:40 +03:00
_PUBLIC_ enum ndr_err_code ndr_pull_DATA_BLOB ( struct ndr_pull * ndr , int ndr_flags , DATA_BLOB * blob )
2003-11-17 05:18:11 +03:00
{
2006-03-13 09:58:51 +03:00
uint32_t length = 0 ;
2003-11-23 09:28:12 +03:00
if ( ndr - > flags & LIBNDR_ALIGN_FLAGS ) {
if ( ndr - > flags & LIBNDR_FLAG_ALIGN2 ) {
length = NDR_ALIGN ( ndr , 2 ) ;
} else if ( ndr - > flags & LIBNDR_FLAG_ALIGN4 ) {
length = NDR_ALIGN ( ndr , 4 ) ;
} else if ( ndr - > flags & LIBNDR_FLAG_ALIGN8 ) {
length = NDR_ALIGN ( ndr , 8 ) ;
}
if ( ndr - > data_size - ndr - > offset < length ) {
length = ndr - > data_size - ndr - > offset ;
}
} else if ( ndr - > flags & LIBNDR_FLAG_REMAINING ) {
length = ndr - > data_size - ndr - > offset ;
} else {
2005-02-10 00:10:23 +03:00
NDR_CHECK ( ndr_pull_uint32 ( ndr , NDR_SCALARS , & length ) ) ;
2003-11-23 09:28:12 +03:00
}
2003-11-17 05:18:11 +03:00
NDR_PULL_NEED_BYTES ( ndr , length ) ;
2005-09-30 05:49:32 +04:00
* blob = data_blob_talloc ( ndr - > current_mem_ctx , ndr - > data + ndr - > offset , length ) ;
2003-11-17 05:18:11 +03:00
ndr - > offset + = length ;
2007-11-09 21:23:40 +03:00
return NDR_ERR_SUCCESS ;
2003-11-17 05:18:11 +03:00
}
2004-10-15 13:22:21 +04:00
2006-03-05 20:15:19 +03:00
_PUBLIC_ uint32_t ndr_size_DATA_BLOB ( int ret , const DATA_BLOB * data , int flags )
2004-10-15 13:22:21 +04:00
{
2006-12-30 13:42:01 +03:00
if ( ! data ) return ret ;
2004-10-15 13:22:21 +04:00
return ret + data - > length ;
}