2013-09-14 15:44:54 +04:00
/*
2003-10-30 11:32:26 +03:00
Unix SMB / CIFS implementation .
routines for marshalling / unmarshalling basic types
Copyright ( C ) Andrew Tridgell 2003
2013-09-14 15:44:54 +04:00
2003-10-30 11:32:26 +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-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 .
2013-09-14 15:44:54 +04:00
2003-10-30 11:32:26 +03:00
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 .
2013-09-14 15:44:54 +04:00
2003-10-30 11:32:26 +03:00
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"
2010-03-26 09:36:02 +03:00
# include "lib/util/util_net.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
2013-09-23 09:39:43 +04:00
static void ndr_dump_data ( struct ndr_print * ndr , const uint8_t * buf , int len ) ;
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
{
2011-09-07 09:34:20 +04:00
NDR_PULL_CHECK_FLAGS ( ndr , ndr_flags ) ;
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
{
2011-09-07 09:34:20 +04:00
NDR_PULL_CHECK_FLAGS ( ndr , ndr_flags ) ;
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
{
2011-09-07 09:34:20 +04:00
NDR_PULL_CHECK_FLAGS ( ndr , ndr_flags ) ;
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
{
2011-09-07 09:34:20 +04:00
NDR_PULL_CHECK_FLAGS ( ndr , ndr_flags ) ;
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
}
2009-10-06 13:47:09 +04:00
/*
parse a uint1632_t
*/
_PUBLIC_ enum ndr_err_code ndr_pull_uint1632 ( struct ndr_pull * ndr , int ndr_flags , uint16_t * v )
{
2011-09-07 09:34:20 +04:00
NDR_PULL_CHECK_FLAGS ( ndr , ndr_flags ) ;
2009-10-06 13:47:09 +04:00
if ( unlikely ( ndr - > flags & LIBNDR_FLAG_NDR64 ) ) {
uint32_t v32 = 0 ;
enum ndr_err_code err = ndr_pull_uint32 ( ndr , ndr_flags , & v32 ) ;
* v = v32 ;
if ( unlikely ( v32 ! = * v ) ) {
DEBUG ( 0 , ( __location__ " : non-zero upper 16 bits 0x%08x \n " , ( unsigned ) v32 ) ) ;
return NDR_ERR_NDR64 ;
}
return err ;
}
return ndr_pull_uint16 ( ndr , ndr_flags , v ) ;
}
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
{
2011-09-07 09:34:20 +04:00
NDR_PULL_CHECK_FLAGS ( ndr , ndr_flags ) ;
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
{
2011-09-07 09:34:20 +04:00
NDR_PULL_CHECK_FLAGS ( ndr , ndr_flags ) ;
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
}
2009-09-17 10:57:32 +04:00
/*
parse a arch dependent uint32 / uint64
*/
_PUBLIC_ enum ndr_err_code ndr_pull_uint3264 ( struct ndr_pull * ndr , int ndr_flags , uint32_t * v )
{
uint64_t v64 ;
enum ndr_err_code err ;
2011-09-07 09:34:20 +04:00
NDR_PULL_CHECK_FLAGS ( ndr , ndr_flags ) ;
2009-09-17 20:08:47 +04:00
if ( likely ( ! ( ndr - > flags & LIBNDR_FLAG_NDR64 ) ) ) {
2009-09-17 10:57:32 +04:00
return ndr_pull_uint32 ( ndr , ndr_flags , v ) ;
}
err = ndr_pull_hyper ( ndr , ndr_flags , & v64 ) ;
* v = ( uint32_t ) v64 ;
2009-09-17 20:08:47 +04:00
if ( unlikely ( v64 ! = * v ) ) {
2009-09-17 10:57:32 +04:00
DEBUG ( 0 , ( __location__ " : non-zero upper 32 bits 0x%016llx \n " ,
( unsigned long long ) v64 ) ) ;
2013-09-23 04:17:16 +04:00
return ndr_pull_error ( ndr , NDR_ERR_NDR64 , __location__ " : non-zero upper 32 bits 0x%016llx \n " ,
( unsigned long long ) v64 ) ;
2009-09-17 10:57:32 +04:00
}
return err ;
}
2009-06-01 18:26:43 +04:00
/*
parse a double
*/
_PUBLIC_ enum ndr_err_code ndr_pull_double ( struct ndr_pull * ndr , int ndr_flags , double * v )
{
2011-09-07 09:34:20 +04:00
NDR_PULL_CHECK_FLAGS ( ndr , ndr_flags ) ;
2009-06-01 18:26:43 +04:00
NDR_PULL_ALIGN ( ndr , 8 ) ;
NDR_PULL_NEED_BYTES ( ndr , 8 ) ;
memcpy ( v , ndr - > data + ndr - > offset , 8 ) ;
ndr - > offset + = 8 ;
return NDR_ERR_SUCCESS ;
2009-12-10 10:04:48 +03:00
}
/*
parse a pointer referent identifier stored in 2 bytes
*/
_PUBLIC_ enum ndr_err_code ndr_pull_relative_ptr_short ( struct ndr_pull * ndr , uint16_t * v )
{
NDR_CHECK ( ndr_pull_uint16 ( ndr , NDR_SCALARS , v ) ) ;
if ( * v ! = 0 ) {
ndr - > ptr_count + + ;
}
2010-04-30 03:08:07 +04:00
* ( v ) - = ndr - > relative_rap_convert ;
2009-12-10 10:04:48 +03:00
return NDR_ERR_SUCCESS ;
2009-06-01 18:26:43 +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
{
2009-09-17 10:57:32 +04:00
NDR_CHECK ( ndr_pull_uint3264 ( ndr , NDR_SCALARS , v ) ) ;
2007-11-02 12:32:47 +03:00
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
{
2009-09-17 10:57:32 +04:00
NDR_CHECK ( ndr_pull_uint3264 ( ndr , NDR_SCALARS , v ) ) ;
2005-03-12 11:29:54 +03:00
/* 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
{
2011-09-07 09:34:20 +04:00
NDR_PULL_CHECK_FLAGS ( ndr , ndr_flags ) ;
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
{
2011-09-07 09:34:20 +04:00
NDR_PULL_CHECK_FLAGS ( ndr , ndr_flags ) ;
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 ) ;
2010-08-20 22:58:22 +04:00
if ( NDR_BE ( ndr ) ) {
return ndr_pull_udlongr ( ndr , ndr_flags , v ) ;
}
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 ;
2011-09-07 09:34:20 +04:00
NDR_PULL_CHECK_FLAGS ( ndr , ndr_flags ) ;
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 ;
2011-09-07 09:34:20 +04:00
NDR_PULL_CHECK_FLAGS ( ndr , ndr_flags ) ;
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 ;
2011-09-07 09:34:20 +04:00
NDR_PULL_CHECK_FLAGS ( ndr , ndr_flags ) ;
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
}
2009-09-18 02:14:31 +04:00
/*
parse a uint8_t enum
*/
_PUBLIC_ enum ndr_err_code ndr_pull_enum_uint8 ( struct ndr_pull * ndr , int ndr_flags , uint8_t * v )
{
return ndr_pull_uint8 ( ndr , ndr_flags , v ) ;
}
/*
2009-10-06 13:47:09 +04:00
parse a uint16_t enum
2009-09-18 02:14:31 +04:00
*/
_PUBLIC_ enum ndr_err_code ndr_pull_enum_uint16 ( struct ndr_pull * ndr , int ndr_flags , uint16_t * v )
2009-10-06 13:47:09 +04:00
{
return ndr_pull_uint16 ( ndr , ndr_flags , v ) ;
}
/*
parse a uint1632_t enum ( uint32_t on NDR64 )
*/
_PUBLIC_ enum ndr_err_code ndr_pull_enum_uint1632 ( struct ndr_pull * ndr , int ndr_flags , uint16_t * v )
2009-09-18 02:14:31 +04:00
{
if ( unlikely ( ndr - > flags & LIBNDR_FLAG_NDR64 ) ) {
uint32_t v32 ;
NDR_CHECK ( ndr_pull_uint32 ( ndr , ndr_flags , & v32 ) ) ;
* v = v32 ;
if ( v32 ! = * v ) {
DEBUG ( 0 , ( __location__ " : non-zero upper 16 bits 0x%08x \n " , ( unsigned ) v32 ) ) ;
return NDR_ERR_NDR64 ;
}
return NDR_ERR_SUCCESS ;
}
2009-10-06 13:47:09 +04:00
return ndr_pull_uint16 ( ndr , ndr_flags , v ) ;
2009-09-18 02:14:31 +04:00
}
/*
parse a uint32_t enum
*/
_PUBLIC_ enum ndr_err_code ndr_pull_enum_uint32 ( struct ndr_pull * ndr , int ndr_flags , uint32_t * v )
{
return ndr_pull_uint32 ( ndr , ndr_flags , v ) ;
}
/*
push a uint8_t enum
*/
_PUBLIC_ enum ndr_err_code ndr_push_enum_uint8 ( struct ndr_push * ndr , int ndr_flags , uint8_t v )
{
return ndr_push_uint8 ( ndr , ndr_flags , v ) ;
}
/*
2009-10-06 13:47:09 +04:00
push a uint16_t enum
2009-09-18 02:14:31 +04:00
*/
_PUBLIC_ enum ndr_err_code ndr_push_enum_uint16 ( struct ndr_push * ndr , int ndr_flags , uint16_t v )
{
return ndr_push_uint16 ( ndr , ndr_flags , v ) ;
}
/*
push a uint32_t enum
*/
_PUBLIC_ enum ndr_err_code ndr_push_enum_uint32 ( struct ndr_push * ndr , int ndr_flags , uint32_t v )
{
return ndr_push_uint32 ( ndr , ndr_flags , v ) ;
}
2009-10-06 13:47:09 +04:00
/*
push a uint1632_t enum
*/
_PUBLIC_ enum ndr_err_code ndr_push_enum_uint1632 ( struct ndr_push * ndr , int ndr_flags , uint16_t v )
{
if ( unlikely ( ndr - > flags & LIBNDR_FLAG_NDR64 ) ) {
return ndr_push_uint32 ( ndr , ndr_flags , v ) ;
}
return ndr_push_uint16 ( ndr , ndr_flags , v ) ;
}
2009-09-18 02:14:31 +04: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
{
2011-09-07 09:34:20 +04:00
NDR_PULL_CHECK_FLAGS ( ndr , ndr_flags ) ;
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
{
2011-09-07 09:34:20 +04:00
NDR_PUSH_CHECK_FLAGS ( ndr , ndr_flags ) ;
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
{
2011-09-07 09:34:20 +04:00
NDR_PUSH_CHECK_FLAGS ( ndr , ndr_flags ) ;
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
{
2011-09-07 09:34:20 +04:00
NDR_PUSH_CHECK_FLAGS ( ndr , ndr_flags ) ;
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
{
2011-09-07 09:34:20 +04:00
NDR_PUSH_CHECK_FLAGS ( ndr , ndr_flags ) ;
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
}
2009-10-06 13:47:09 +04:00
/*
push a uint1632
*/
_PUBLIC_ enum ndr_err_code ndr_push_uint1632 ( struct ndr_push * ndr , int ndr_flags , uint16_t v )
{
if ( unlikely ( ndr - > flags & LIBNDR_FLAG_NDR64 ) ) {
return ndr_push_uint32 ( ndr , ndr_flags , v ) ;
}
return ndr_push_uint16 ( ndr , ndr_flags , v ) ;
}
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
{
2011-09-07 09:34:20 +04:00
NDR_PUSH_CHECK_FLAGS ( ndr , ndr_flags ) ;
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
{
2011-09-07 09:34:20 +04:00
NDR_PUSH_CHECK_FLAGS ( ndr , ndr_flags ) ;
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
}
2009-09-17 20:08:47 +04:00
/*
push a uint3264
*/
_PUBLIC_ enum ndr_err_code ndr_push_uint3264 ( struct ndr_push * ndr , int ndr_flags , uint32_t v )
{
if ( unlikely ( ndr - > flags & LIBNDR_FLAG_NDR64 ) ) {
return ndr_push_hyper ( ndr , ndr_flags , v ) ;
}
2009-10-06 13:47:09 +04:00
return ndr_push_uint32 ( ndr , ndr_flags , v ) ;
2009-09-17 20:08:47 +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
{
2011-09-07 09:34:20 +04:00
NDR_PUSH_CHECK_FLAGS ( ndr , ndr_flags ) ;
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
{
2011-09-07 09:34:20 +04:00
NDR_PUSH_CHECK_FLAGS ( ndr , ndr_flags ) ;
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 ) ;
2010-08-20 22:58:22 +04:00
if ( NDR_BE ( ndr ) ) {
return ndr_push_udlongr ( ndr , NDR_SCALARS , v ) ;
}
2005-02-10 00:10:23 +03:00
return ndr_push_udlong ( ndr , NDR_SCALARS , v ) ;
2004-05-25 17:57:39 +04:00
}
2009-06-01 18:26:43 +04:00
/*
push a double
*/
_PUBLIC_ enum ndr_err_code ndr_push_double ( struct ndr_push * ndr , int ndr_flags , double v )
{
2011-09-07 09:34:20 +04:00
NDR_PUSH_CHECK_FLAGS ( ndr , ndr_flags ) ;
2009-06-01 18:26:43 +04:00
NDR_PUSH_ALIGN ( ndr , 8 ) ;
NDR_PUSH_NEED_BYTES ( ndr , 8 ) ;
memcpy ( ndr - > data + ndr - > offset , & v , 8 ) ;
ndr - > offset + = 8 ;
return NDR_ERR_SUCCESS ;
}
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 ;
2011-09-07 09:34:20 +04:00
NDR_PUSH_CHECK_FLAGS ( ndr , ndr_flags ) ;
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
{
2009-09-17 20:08:47 +04:00
/* this is a nasty hack to make pidl work with NDR64 */
if ( size = = 5 ) {
if ( ndr - > flags & LIBNDR_FLAG_NDR64 ) {
size = 8 ;
} else {
size = 4 ;
}
2009-10-06 13:47:09 +04:00
} else if ( size = = 3 ) {
if ( ndr - > flags & LIBNDR_FLAG_NDR64 ) {
size = 4 ;
} else {
size = 2 ;
}
2009-09-17 20:08:47 +04: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
{
2009-09-17 20:08:47 +04:00
/* this is a nasty hack to make pidl work with NDR64 */
if ( size = = 5 ) {
if ( ndr - > flags & LIBNDR_FLAG_NDR64 ) {
size = 8 ;
} else {
size = 4 ;
}
2009-10-06 13:47:09 +04:00
} else if ( size = = 3 ) {
if ( ndr - > flags & LIBNDR_FLAG_NDR64 ) {
size = 4 ;
} else {
size = 2 ;
}
2009-09-17 20:08:47 +04:00
}
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
}
2009-09-29 11:47:54 +04:00
_PUBLIC_ enum ndr_err_code ndr_push_union_align ( struct ndr_push * ndr , size_t size )
{
/* MS-RPCE section 2.2.5.3.4.4 */
if ( ndr - > flags & LIBNDR_FLAG_NDR64 ) {
return ndr_push_align ( ndr , size ) ;
}
return NDR_ERR_SUCCESS ;
}
_PUBLIC_ enum ndr_err_code ndr_pull_union_align ( struct ndr_pull * ndr , size_t size )
{
/* MS-RPCE section 2.2.5.3.4.4 */
if ( ndr - > flags & LIBNDR_FLAG_NDR64 ) {
return ndr_pull_align ( ndr , size ) ;
}
return NDR_ERR_SUCCESS ;
}
2009-10-01 10:08:02 +04:00
_PUBLIC_ enum ndr_err_code ndr_push_trailer_align ( struct ndr_push * ndr , size_t size )
{
/* MS-RPCE section 2.2.5.3.4.1 */
if ( ndr - > flags & LIBNDR_FLAG_NDR64 ) {
return ndr_push_align ( ndr , size ) ;
}
return NDR_ERR_SUCCESS ;
}
_PUBLIC_ enum ndr_err_code ndr_pull_trailer_align ( struct ndr_pull * ndr , size_t size )
{
/* MS-RPCE section 2.2.5.3.4.1 */
if ( ndr - > flags & LIBNDR_FLAG_NDR64 ) {
return ndr_pull_align ( ndr , size ) ;
}
return NDR_ERR_SUCCESS ;
}
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
{
2011-09-07 09:34:20 +04:00
NDR_PUSH_CHECK_FLAGS ( ndr , ndr_flags ) ;
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
}
2009-09-17 20:08:47 +04:00
return ndr_push_uint3264 ( ndr , NDR_SCALARS , ptr ) ;
2005-07-05 16:09:33 +04:00
}
/*
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
}
2009-09-17 20:08:47 +04:00
return ndr_push_uint3264 ( 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
{
2009-09-17 20:08:47 +04:00
return ndr_push_uint3264 ( 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
{
2011-09-07 09:34:20 +04:00
NDR_PUSH_CHECK_FLAGS ( ndr , ndr_flags ) ;
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
{
2011-09-07 09:34:20 +04:00
NDR_PULL_CHECK_FLAGS ( ndr , ndr_flags ) ;
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
/*
2009-06-01 18:26:43 +04:00
push 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_push_NTTIME_1sec ( struct ndr_push * ndr , int ndr_flags , NTTIME t )
2004-11-19 05:35:48 +03:00
{
2011-09-07 09:34:20 +04:00
NDR_PUSH_CHECK_FLAGS ( ndr , ndr_flags ) ;
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
{
2011-09-07 09:34:20 +04:00
NDR_PULL_CHECK_FLAGS ( ndr , ndr_flags ) ;
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
{
2011-09-07 09:34:20 +04:00
NDR_PULL_CHECK_FLAGS ( ndr , ndr_flags ) ;
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
{
2011-09-07 09:34:20 +04:00
NDR_PUSH_CHECK_FLAGS ( ndr , ndr_flags ) ;
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
2011-02-11 10:45:32 +03:00
/*
push a uid_t
*/
_PUBLIC_ enum ndr_err_code ndr_push_uid_t ( struct ndr_push * ndr , int ndr_flags , uid_t u )
{
2011-09-07 09:34:20 +04:00
NDR_PUSH_CHECK_FLAGS ( ndr , ndr_flags ) ;
2011-03-02 11:06:15 +03:00
return ndr_push_hyper ( ndr , NDR_SCALARS , ( uint64_t ) u ) ;
2011-02-11 10:45:32 +03:00
}
/*
pull a uid_t
*/
_PUBLIC_ enum ndr_err_code ndr_pull_uid_t ( struct ndr_pull * ndr , int ndr_flags , uid_t * u )
{
uint64_t uu ;
2011-03-02 11:06:15 +03:00
NDR_CHECK ( ndr_pull_hyper ( ndr , ndr_flags , & uu ) ) ;
2011-02-11 10:45:32 +03:00
* u = ( uid_t ) uu ;
if ( unlikely ( uu ! = * u ) ) {
DEBUG ( 0 , ( __location__ " : uid_t pull doesn't fit 0x%016llx \n " ,
( unsigned long long ) uu ) ) ;
return NDR_ERR_NDR64 ;
}
return NDR_ERR_SUCCESS ;
}
/*
push a gid_t
*/
_PUBLIC_ enum ndr_err_code ndr_push_gid_t ( struct ndr_push * ndr , int ndr_flags , gid_t g )
{
2011-09-07 09:34:20 +04:00
NDR_PUSH_CHECK_FLAGS ( ndr , ndr_flags ) ;
2011-03-02 11:06:15 +03:00
return ndr_push_hyper ( ndr , NDR_SCALARS , ( uint64_t ) g ) ;
2011-02-11 10:45:32 +03:00
}
/*
pull a gid_t
*/
_PUBLIC_ enum ndr_err_code ndr_pull_gid_t ( struct ndr_pull * ndr , int ndr_flags , gid_t * g )
{
uint64_t gg ;
2011-03-02 11:06:15 +03:00
NDR_CHECK ( ndr_pull_hyper ( ndr , ndr_flags , & gg ) ) ;
2011-02-11 10:45:32 +03:00
* g = ( gid_t ) gg ;
if ( unlikely ( gg ! = * g ) ) {
DEBUG ( 0 , ( __location__ " : gid_t pull doesn't fit 0x%016llx \n " ,
( unsigned long long ) gg ) ) ;
return NDR_ERR_NDR64 ;
}
return NDR_ERR_SUCCESS ;
}
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
{
2009-05-03 01:34:45 +04:00
uint32_t addr ;
2007-10-13 22:24:37 +04:00
struct in_addr in ;
2009-05-03 01:34:45 +04:00
NDR_CHECK ( ndr_pull_uint32 ( ndr , ndr_flags , & addr ) ) ;
in . s_addr = htonl ( addr ) ;
2007-10-13 22:24:37 +04:00
* 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 ,
2010-08-10 17:32:59 +04:00
" Invalid IPv4 address: '%s' " ,
2005-11-30 16:10:44 +03:00
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
*/
2010-08-10 17:32:59 +04: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 ) ;
}
2010-08-10 17:32:59 +04:00
/*
pull a ipv6address
*/
# define IPV6_BYTES 16
# define IPV6_ADDR_STR_LEN 39
_PUBLIC_ enum ndr_err_code ndr_pull_ipv6address ( struct ndr_pull * ndr , int ndr_flags , const char * * address )
{
uint8_t addr [ IPV6_BYTES ] ;
char * addr_str = talloc_strdup ( ndr - > current_mem_ctx , " " ) ;
int i ;
NDR_CHECK ( ndr_pull_array_uint8 ( ndr , ndr_flags , addr , IPV6_BYTES ) ) ;
for ( i = 0 ; i < IPV6_BYTES ; + + i ) {
addr_str = talloc_asprintf_append ( addr_str , " %02x " , addr [ i ] ) ;
/* We need a ':' every second byte but the last one */
if ( i % 2 = = 1 & & i ! = ( IPV6_BYTES - 1 ) ) {
addr_str = talloc_strdup_append ( addr_str , " : " ) ;
}
}
* address = addr_str ;
NDR_ERR_HAVE_NO_MEMORY ( * address ) ;
return NDR_ERR_SUCCESS ;
}
/*
push a ipv6address
*/
_PUBLIC_ enum ndr_err_code ndr_push_ipv6address ( struct ndr_push * ndr , int ndr_flags , const char * address )
{
2010-12-06 09:43:35 +03:00
# ifdef AF_INET6
2010-09-29 07:33:54 +04:00
uint8_t addr [ IPV6_BYTES ] ;
int ret ;
2010-08-10 17:32:59 +04:00
if ( ! is_ipaddress ( address ) ) {
2010-09-29 07:33:54 +04:00
return ndr_push_error ( ndr , NDR_ERR_IPV6ADDRESS ,
2010-08-10 17:32:59 +04:00
" Invalid IPv6 address: '%s' " ,
address ) ;
}
2010-09-29 07:33:54 +04:00
ret = inet_pton ( AF_INET6 , address , addr ) ;
if ( ret < = 0 ) {
return NDR_ERR_IPV6ADDRESS ;
}
NDR_CHECK ( ndr_push_array_uint8 ( ndr , ndr_flags , addr , IPV6_BYTES ) ) ;
2010-08-10 17:32:59 +04:00
return NDR_ERR_SUCCESS ;
2010-12-06 09:43:35 +03:00
# else
return NDR_ERR_IPV6ADDRESS ;
# endif
2010-08-10 17:32:59 +04:00
}
/*
print a ipv6address
*/
_PUBLIC_ void ndr_print_ipv6address ( struct ndr_print * ndr , const char * name ,
const char * address )
{
ndr - > print ( ndr , " %-25s: %s " , name , address ) ;
}
# undef IPV6_BYTES
2005-02-01 07:12:44 +03:00
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
}
2010-09-16 10:57:21 +04:00
_PUBLIC_ void ndr_print_null ( struct ndr_print * ndr )
{
ndr - > print ( ndr , " UNEXPECTED NULL POINTER " ) ;
}
2013-09-14 15:44:54 +04: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 ;
2013-09-14 15:43:03 +04:00
if ( value = = 0 ) {
return ;
}
2005-01-21 09:54:10 +03:00
while ( ! ( flag & 1 ) ) {
flag > > = 1 ;
value > > = 1 ;
2013-09-14 15:44:54 +04:00
}
2005-01-21 09:54:10 +03:00
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 ) ;
}
2009-10-03 12:13:25 +04:00
_PUBLIC_ void ndr_print_int3264 ( struct ndr_print * ndr , const char * name , int32_t v )
{
ndr - > print ( ndr , " %-25s: %d " , name , v ) ;
}
_PUBLIC_ void ndr_print_uint3264 ( struct ndr_print * ndr , const char * name , uint32_t v )
{
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
}
2009-06-01 18:26:43 +04:00
_PUBLIC_ void ndr_print_double ( struct ndr_print * ndr , const char * name , double v )
{
ndr - > print ( ndr , " %-25s: %f " , name , v ) ;
}
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
}
}
2011-02-11 10:45:32 +03:00
_PUBLIC_ void ndr_print_uid_t ( struct ndr_print * ndr , const char * name , uid_t u )
{
ndr_print_dlong ( ndr , name , u ) ;
}
_PUBLIC_ void ndr_print_gid_t ( struct ndr_print * ndr , const char * name , gid_t g )
{
ndr_print_dlong ( ndr , name , g ) ;
}
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
2013-09-14 15:44:54 +04: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 ;
2013-09-23 09:39:43 +04:00
# define _ONELINE_LIMIT 32
2003-11-15 13:58:29 +03:00
2010-09-16 10:57:21 +04:00
if ( data = = NULL ) {
ndr - > print ( ndr , " %s: ARRAY(%d) : NULL " , name , count ) ;
return ;
}
2013-09-23 09:39:43 +04:00
if ( count < = _ONELINE_LIMIT & & ( ndr - > flags & LIBNDR_PRINT_ARRAY_HEX ) ) {
char s [ ( _ONELINE_LIMIT + 1 ) * 2 ] ;
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 ) ;
2013-09-23 09:39:43 +04:00
if ( count > _ONELINE_LIMIT & & ( ndr - > flags & LIBNDR_PRINT_ARRAY_HEX ) ) {
ndr_dump_data ( ndr , data , count ) ;
return ;
}
2003-11-15 13:58:29 +03:00
ndr - > depth + + ;
for ( i = 0 ; i < count ; i + + ) {
char * idx = NULL ;
2009-01-01 05:34:52 +03:00
if ( asprintf ( & idx , " [%d] " , i ) ! = - 1 ) {
2003-11-15 13:58:29 +03:00
ndr_print_uint8 ( ndr , idx , data [ i ] ) ;
free ( idx ) ;
}
}
2013-09-14 15:44:54 +04:00
ndr - > depth - - ;
2013-09-23 09:39:43 +04:00
# undef _ONELINE_LIMIT
2003-11-15 13:58:29 +03:00
}
2010-08-09 10:37:52 +04:00
static void ndr_print_asc ( struct ndr_print * ndr , const uint8_t * buf , int len )
{
int i ;
for ( i = 0 ; i < len ; i + + )
ndr - > print ( ndr , " %c " , isprint ( buf [ i ] ) ? buf [ i ] : ' . ' ) ;
}
/*
ndr_print version of dump_data ( )
*/
static void ndr_dump_data ( struct ndr_print * ndr , const uint8_t * buf , int len )
{
int i = 0 ;
ndr - > no_newline = true ;
for ( i = 0 ; i < len ; ) {
if ( i % 16 = = 0 & & i < len ) {
ndr - > print ( ndr , " [%04X] " , i ) ;
}
ndr - > print ( ndr , " %02X " , ( int ) buf [ i ] ) ;
i + + ;
if ( i % 8 = = 0 ) ndr - > print ( ndr , " " ) ;
if ( i % 16 = = 0 ) {
ndr_print_asc ( ndr , & buf [ i - 16 ] , 8 ) ; ndr - > print ( ndr , " " ) ;
ndr_print_asc ( ndr , & buf [ i - 8 ] , 8 ) ; ndr - > print ( ndr , " \n " ) ;
}
}
if ( i % 16 ) {
int n ;
n = 16 - ( i % 16 ) ;
ndr - > print ( ndr , " " ) ;
if ( n > 8 ) ndr - > print ( ndr , " " ) ;
while ( n - - ) ndr - > print ( ndr , " " ) ;
n = MIN ( 8 , i % 16 ) ;
ndr_print_asc ( ndr , & buf [ i - ( i % 16 ) ] , n ) ; ndr - > print ( ndr , " " ) ;
n = ( i % 16 ) - n ;
if ( n > 0 ) ndr_print_asc ( ndr , & buf [ i - n ] , n ) ;
ndr - > print ( ndr , " \n " ) ;
}
ndr - > no_newline = false ;
}
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 ) {
2010-08-09 10:37:52 +04:00
ndr_dump_data ( ndr , r . data , r . length ) ;
2003-11-24 13:15:17 +03:00
}
2003-11-17 14:55:56 +03:00
}
2003-11-17 05:18:11 +03:00
/*
2012-07-06 16:00:27 +04:00
* Push a DATA_BLOB onto the wire .
* 1 ) When called with LIBNDR_FLAG_ALIGN * alignment flags set , push padding
* bytes _only_ . The length is determined by the alignment required and the
* current ndr offset .
* 2 ) When called with the LIBNDR_FLAG_REMAINING flag , push the byte array to
* the ndr buffer .
2013-09-23 09:20:00 +04:00
* 3 ) Otherwise , push a uint3264 length _and_ a corresponding byte array to the
2012-07-06 16:00:27 +04:00
* ndr buffer .
*/
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
{
2011-02-22 20:19:13 +03:00
if ( ndr - > flags & LIBNDR_FLAG_REMAINING ) {
2011-03-01 16:20:32 +03:00
/* nothing to do */
2012-07-06 16:00:27 +04:00
} else if ( ndr - > flags & ( LIBNDR_ALIGN_FLAGS & ~ LIBNDR_FLAG_NOALIGN ) ) {
if ( ndr - > flags & LIBNDR_FLAG_ALIGN2 ) {
2003-11-23 09:28:12 +03:00
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 ) ;
2011-03-01 16:20:32 +03:00
} else {
2013-09-23 09:20:00 +04:00
NDR_CHECK ( ndr_push_uint3264 ( 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
}
/*
2012-07-06 16:00:27 +04:00
* Pull a DATA_BLOB from the wire .
* 1 ) when called with LIBNDR_FLAG_ALIGN * alignment flags set , pull padding
* bytes _only_ . The length is determined by the alignment required and the
* current ndr offset .
* 2 ) When called with the LIBNDR_FLAG_REMAINING flag , pull all remaining bytes
* from the ndr buffer .
2013-09-23 09:20:00 +04:00
* 3 ) Otherwise , pull a uint3264 length _and_ a corresponding byte array from the
2012-07-06 16:00:27 +04:00
* ndr buffer .
*/
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
2011-02-22 20:19:13 +03:00
if ( ndr - > flags & LIBNDR_FLAG_REMAINING ) {
length = ndr - > data_size - ndr - > offset ;
2012-07-06 16:00:27 +04:00
} else if ( ndr - > flags & ( LIBNDR_ALIGN_FLAGS & ~ LIBNDR_FLAG_NOALIGN ) ) {
if ( ndr - > flags & LIBNDR_FLAG_ALIGN2 ) {
2003-11-23 09:28:12 +03:00
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 {
2013-09-23 09:20:00 +04:00
NDR_CHECK ( ndr_pull_uint3264 ( 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 ;
}
2011-01-25 02:52:10 +03:00
_PUBLIC_ void ndr_print_bool ( struct ndr_print * ndr , const char * name , const bool b )
{
ndr - > print ( ndr , " %-25s: %s " , name , b ? " true " : " false " ) ;
}
2011-01-29 01:38:21 +03:00
_PUBLIC_ NTSTATUS ndr_map_error2ntstatus ( enum ndr_err_code ndr_err )
{
switch ( ndr_err ) {
case NDR_ERR_SUCCESS :
return NT_STATUS_OK ;
case NDR_ERR_BUFSIZE :
return NT_STATUS_BUFFER_TOO_SMALL ;
case NDR_ERR_TOKEN :
return NT_STATUS_INTERNAL_ERROR ;
case NDR_ERR_ALLOC :
return NT_STATUS_NO_MEMORY ;
case NDR_ERR_ARRAY_SIZE :
return NT_STATUS_ARRAY_BOUNDS_EXCEEDED ;
case NDR_ERR_INVALID_POINTER :
return NT_STATUS_INVALID_PARAMETER_MIX ;
case NDR_ERR_UNREAD_BYTES :
return NT_STATUS_PORT_MESSAGE_TOO_LONG ;
default :
break ;
}
/* we should map all error codes to different status codes */
return NT_STATUS_INVALID_PARAMETER ;
}
2011-11-24 12:48:40 +04:00
2012-02-13 16:27:22 +04:00
_PUBLIC_ int ndr_map_error2errno ( enum ndr_err_code ndr_err )
{
switch ( ndr_err ) {
case NDR_ERR_SUCCESS :
return 0 ;
case NDR_ERR_BUFSIZE :
return ENOSPC ;
case NDR_ERR_TOKEN :
return EINVAL ;
case NDR_ERR_ALLOC :
return ENOMEM ;
case NDR_ERR_ARRAY_SIZE :
return EMSGSIZE ;
case NDR_ERR_INVALID_POINTER :
return EINVAL ;
case NDR_ERR_UNREAD_BYTES :
return EOVERFLOW ;
default :
break ;
}
/* we should map all error codes to different status codes */
return EINVAL ;
}
2011-11-24 12:48:40 +04:00
_PUBLIC_ enum ndr_err_code ndr_push_timespec ( struct ndr_push * ndr ,
int ndr_flags ,
const struct timespec * t )
{
NDR_PUSH_CHECK_FLAGS ( ndr , ndr_flags ) ;
NDR_CHECK ( ndr_push_hyper ( ndr , ndr_flags , t - > tv_sec ) ) ;
NDR_CHECK ( ndr_push_uint32 ( ndr , ndr_flags , t - > tv_nsec ) ) ;
return NDR_ERR_SUCCESS ;
}
_PUBLIC_ enum ndr_err_code ndr_pull_timespec ( struct ndr_pull * ndr ,
int ndr_flags ,
struct timespec * t )
{
uint64_t secs ;
uint32_t nsecs ;
NDR_PULL_CHECK_FLAGS ( ndr , ndr_flags ) ;
NDR_CHECK ( ndr_pull_hyper ( ndr , ndr_flags , & secs ) ) ;
NDR_CHECK ( ndr_pull_uint32 ( ndr , ndr_flags , & nsecs ) ) ;
t - > tv_sec = secs ;
t - > tv_nsec = nsecs ;
return NDR_ERR_SUCCESS ;
}
_PUBLIC_ void ndr_print_timespec ( struct ndr_print * ndr , const char * name ,
const struct timespec * t )
{
ndr - > print ( ndr , " %-25s: %s.%ld " , name , timestring ( ndr , t - > tv_sec ) ,
( long ) t - > tv_nsec ) ;
}
2011-11-24 12:49:19 +04:00
_PUBLIC_ enum ndr_err_code ndr_push_timeval ( struct ndr_push * ndr ,
int ndr_flags ,
const struct timeval * t )
{
NDR_PUSH_CHECK_FLAGS ( ndr , ndr_flags ) ;
NDR_CHECK ( ndr_push_hyper ( ndr , ndr_flags , t - > tv_sec ) ) ;
NDR_CHECK ( ndr_push_uint32 ( ndr , ndr_flags , t - > tv_usec ) ) ;
return NDR_ERR_SUCCESS ;
}
_PUBLIC_ enum ndr_err_code ndr_pull_timeval ( struct ndr_pull * ndr ,
int ndr_flags ,
struct timeval * t )
{
uint64_t secs ;
uint32_t usecs ;
NDR_PULL_CHECK_FLAGS ( ndr , ndr_flags ) ;
NDR_CHECK ( ndr_pull_hyper ( ndr , ndr_flags , & secs ) ) ;
NDR_CHECK ( ndr_pull_uint32 ( ndr , ndr_flags , & usecs ) ) ;
t - > tv_sec = secs ;
t - > tv_usec = usecs ;
return NDR_ERR_SUCCESS ;
}
_PUBLIC_ void ndr_print_timeval ( struct ndr_print * ndr , const char * name ,
const struct timeval * t )
{
ndr - > print ( ndr , " %-25s: %s.%ld " , name , timestring ( ndr , t - > tv_sec ) ,
( long ) t - > tv_usec ) ;
}