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
the Free Software Foundation ; either version 2 of the License , or
( 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
along with this program ; if not , write to the Free Software
Foundation , Inc . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
*/
# include "includes.h"
2005-02-01 07:12:44 +03:00
# include "system/network.h"
2003-10-30 11:32:26 +03:00
2003-12-31 04:32:33 +03:00
# define NDR_BE(ndr) (((ndr)->flags & (LIBNDR_FLAG_BIGENDIAN|LIBNDR_FLAG_LITTLE_ENDIAN)) == LIBNDR_FLAG_BIGENDIAN)
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
*/
void ndr_check_padding ( struct ndr_pull * ndr , size_t n )
{
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 ) {
DEBUG ( 0 , ( " WARNING: Non-zero padding to %d: " , n ) ) ;
for ( i = ndr - > offset ; i < ofs2 ; i + + ) {
DEBUG ( 0 , ( " %02x " , ndr - > data [ i ] ) ) ;
}
DEBUG ( 0 , ( " \n " ) ) ;
}
}
2003-10-30 11:32:26 +03:00
/*
2003-11-06 15:34:04 +03:00
parse a uint8
2003-10-30 11:32:26 +03:00
*/
2005-02-10 00:10:23 +03:00
NTSTATUS 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 ;
return NT_STATUS_OK ;
}
/*
2003-11-06 15:34:04 +03:00
parse a uint16
2003-10-30 11:32:26 +03:00
*/
2005-02-10 00:10:23 +03:00
NTSTATUS 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 ;
return NT_STATUS_OK ;
}
/*
2004-05-25 20:24:13 +04:00
parse a uint32_t
2003-10-30 11:32:26 +03:00
*/
2005-02-10 00:10:23 +03:00
NTSTATUS ndr_pull_uint32 ( struct ndr_pull * ndr , int ndr_flags , uint32_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 ) ;
2003-12-16 12:02:58 +03:00
* v = NDR_IVAL ( ndr , ndr - > offset ) ;
2003-11-03 12:18:38 +03:00
ndr - > offset + = 4 ;
return NT_STATUS_OK ;
}
2004-10-15 11:19:09 +04:00
/*
parse a int32_t
*/
2005-02-10 00:10:23 +03:00
NTSTATUS ndr_pull_int32 ( struct ndr_pull * ndr , int ndr_flags , int32_t * v )
2004-10-15 11:19:09 +04:00
{
NDR_PULL_ALIGN ( ndr , 4 ) ;
NDR_PULL_NEED_BYTES ( ndr , 4 ) ;
* v = NDR_IVALS ( ndr , ndr - > offset ) ;
ndr - > offset + = 4 ;
return NT_STATUS_OK ;
}
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
*/
2005-02-13 03:07:17 +03:00
NTSTATUS ndr_pull_unique_ptr ( struct ndr_pull * ndr , uint32_t * v )
2004-06-14 11:27:22 +04:00
{
NTSTATUS status ;
2005-02-10 00:10:23 +03:00
status = ndr_pull_uint32 ( ndr , NDR_SCALARS , v ) ;
2004-08-12 09:15:41 +04:00
if ( * v ! = 0 ) {
ndr - > ptr_count + + ;
}
2004-06-14 11:27:22 +04:00
return status ;
}
2005-03-12 11:29:54 +03:00
/*
parse a ref pointer referent identifier
*/
NTSTATUS ndr_pull_ref_ptr ( struct ndr_pull * ndr , uint32_t * v )
{
NTSTATUS status ;
NDR_CHECK ( ndr_pull_uint32 ( ndr , NDR_SCALARS , v ) ) ;
/* ref pointers always point to data */
* v = 1 ;
return status ;
}
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
*/
2005-02-10 00:10:23 +03:00
NTSTATUS 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 ;
return NT_STATUS_OK ;
}
2005-02-16 13:03:18 +03:00
/*
parse a udlongr
*/
NTSTATUS ndr_pull_udlongr ( struct ndr_pull * ndr , int ndr_flags , uint64_t * v )
{
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 ;
return NT_STATUS_OK ;
}
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
*/
2005-02-10 00:10:23 +03:00
NTSTATUS 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
*/
2005-02-10 00:10:23 +03:00
NTSTATUS 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
}
2003-11-04 12:10:31 +03:00
/*
pull a NTSTATUS
*/
2005-02-10 00:10:23 +03:00
NTSTATUS 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 ) ;
return NT_STATUS_OK ;
}
2003-11-22 11:11:32 +03:00
/*
push a NTSTATUS
*/
2005-02-10 00:10:23 +03:00
NTSTATUS 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
}
2005-02-17 14:42:38 +03:00
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
*/
2005-02-10 00:10:23 +03:00
NTSTATUS 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 ) ;
return NT_STATUS_OK ;
}
2003-11-22 11:11:32 +03:00
/*
push a WERROR
*/
2005-02-10 00:10:23 +03:00
NTSTATUS 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
}
2004-11-01 15:40:43 +03:00
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
*/
2004-11-06 23:08:05 +03:00
NTSTATUS 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 ;
2003-10-30 11:32:26 +03:00
return NT_STATUS_OK ;
}
2003-11-09 10:24:06 +03:00
/*
pull an array of uint8
*/
2004-11-06 23:08:05 +03:00
NTSTATUS 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 ) ) {
return NT_STATUS_OK ;
}
2003-11-13 12:26:53 +03:00
return ndr_pull_bytes ( ndr , data , n ) ;
2003-11-09 10:24:06 +03:00
}
2003-11-11 09:22:58 +03:00
/*
pull an array of uint16
*/
2004-05-25 21:24:24 +04:00
NTSTATUS ndr_pull_array_uint16 ( struct ndr_pull * ndr , int ndr_flags , uint16_t * data , uint32_t n )
2003-11-11 09:22:58 +03:00
{
2004-05-25 20:24:13 +04:00
uint32_t i ;
2003-11-17 09:27:45 +03:00
if ( ! ( ndr_flags & NDR_SCALARS ) ) {
return NT_STATUS_OK ;
}
2003-11-11 09:22:58 +03:00
for ( i = 0 ; i < n ; i + + ) {
2005-02-10 00:10:23 +03:00
NDR_CHECK ( ndr_pull_uint16 ( ndr , NDR_SCALARS , & data [ i ] ) ) ;
2003-11-11 09:22:58 +03:00
}
return NT_STATUS_OK ;
}
2003-11-12 08:34:21 +03:00
/*
2004-05-25 20:24:13 +04:00
pull a const array of uint32_t
2003-11-12 08:34:21 +03:00
*/
2004-05-25 20:24:13 +04:00
NTSTATUS ndr_pull_array_uint32 ( struct ndr_pull * ndr , int ndr_flags , uint32_t * data , uint32_t n )
2003-11-12 08:34:21 +03:00
{
2004-05-25 20:24:13 +04:00
uint32_t i ;
2003-11-17 09:27:45 +03:00
if ( ! ( ndr_flags & NDR_SCALARS ) ) {
return NT_STATUS_OK ;
}
2003-11-12 08:34:21 +03:00
for ( i = 0 ; i < n ; i + + ) {
2005-02-10 00:10:23 +03:00
NDR_CHECK ( ndr_pull_uint32 ( ndr , NDR_SCALARS , & data [ i ] ) ) ;
2003-11-12 08:34:21 +03:00
}
return NT_STATUS_OK ;
}
2004-08-11 23:48:36 +04:00
/*
2005-01-27 09:33:07 +03:00
pull a const array of hyper
2004-08-11 23:48:36 +04:00
*/
2005-01-27 09:33:07 +03:00
NTSTATUS ndr_pull_array_hyper ( struct ndr_pull * ndr , int ndr_flags , uint64_t * data , uint32_t n )
2004-08-11 23:48:36 +04:00
{
uint32_t i ;
if ( ! ( ndr_flags & NDR_SCALARS ) ) {
return NT_STATUS_OK ;
}
for ( i = 0 ; i < n ; i + + ) {
2005-02-10 00:10:23 +03:00
NDR_CHECK ( ndr_pull_hyper ( ndr , NDR_SCALARS , & data [ i ] ) ) ;
2004-08-11 23:48:36 +04:00
}
return NT_STATUS_OK ;
}
2004-11-01 15:40:43 +03:00
/*
pull a const array of WERROR
*/
NTSTATUS ndr_pull_array_WERROR ( struct ndr_pull * ndr , int ndr_flags , WERROR * data , uint32_t n )
{
uint32_t i ;
if ( ! ( ndr_flags & NDR_SCALARS ) ) {
return NT_STATUS_OK ;
}
for ( i = 0 ; i < n ; i + + ) {
2005-02-10 00:10:23 +03:00
NDR_CHECK ( ndr_pull_WERROR ( ndr , NDR_SCALARS , & data [ i ] ) ) ;
2004-11-01 15:40:43 +03:00
}
return NT_STATUS_OK ;
}
2003-11-03 09:22:45 +03:00
/*
2003-11-06 15:34:04 +03:00
push a uint8
2003-11-03 09:22:45 +03:00
*/
2005-02-10 00:10:23 +03:00
NTSTATUS 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 ;
return NT_STATUS_OK ;
}
/*
2003-11-06 15:34:04 +03:00
push a uint16
2003-11-03 09:22:45 +03:00
*/
2005-02-10 00:10:23 +03:00
NTSTATUS 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 ;
return NT_STATUS_OK ;
}
/*
2004-05-25 20:24:13 +04:00
push a uint32_t
2003-11-03 09:22:45 +03:00
*/
2005-02-10 00:10:23 +03:00
NTSTATUS ndr_push_uint32 ( struct ndr_push * ndr , int ndr_flags , uint32_t v )
2003-11-03 09:22:45 +03:00
{
NDR_PUSH_ALIGN ( ndr , 4 ) ;
NDR_PUSH_NEED_BYTES ( ndr , 4 ) ;
2003-12-16 12:02:58 +03:00
NDR_SIVAL ( ndr , ndr - > offset , v ) ;
2003-11-03 09:22:45 +03:00
ndr - > offset + = 4 ;
return NT_STATUS_OK ;
}
2003-11-03 12:18:38 +03:00
2004-10-15 11:19:09 +04:00
/*
push a int32_t
*/
2005-02-10 00:10:23 +03:00
NTSTATUS ndr_push_int32 ( struct ndr_push * ndr , int ndr_flags , int32_t v )
2004-10-15 11:19:09 +04:00
{
NDR_PUSH_ALIGN ( ndr , 4 ) ;
NDR_PUSH_NEED_BYTES ( ndr , 4 ) ;
NDR_SIVALS ( ndr , ndr - > offset , v ) ;
ndr - > offset + = 4 ;
return NT_STATUS_OK ;
}
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
*/
2005-02-10 00:10:23 +03:00
NTSTATUS 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 ;
return NT_STATUS_OK ;
}
2005-02-16 13:03:18 +03:00
/*
push a udlongr
*/
NTSTATUS ndr_push_udlongr ( struct ndr_push * ndr , int ndr_flags , uint64_t v )
{
NDR_PUSH_ALIGN ( ndr , 4 ) ;
NDR_PUSH_NEED_BYTES ( ndr , 8 ) ;
NDR_SIVAL ( ndr , ndr - > offset + 4 , ( v > > 32 ) ) ;
NDR_SIVAL ( ndr , ndr - > offset , ( v & 0xFFFFFFFF ) ) ;
ndr - > offset + = 8 ;
return NT_STATUS_OK ;
}
2004-05-25 17:57:39 +04:00
/*
push a int64
*/
2005-02-10 00:10:23 +03:00
NTSTATUS 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
*/
2005-02-10 00:10:23 +03:00
NTSTATUS 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
}
2003-11-11 09:54:54 +03:00
NTSTATUS 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 ) ;
return NT_STATUS_OK ;
}
NTSTATUS ndr_pull_align ( struct ndr_pull * ndr , size_t size )
{
NDR_PULL_ALIGN ( ndr , size ) ;
2003-11-06 15:34:04 +03:00
return NT_STATUS_OK ;
}
2003-11-03 12:18:38 +03:00
/*
push some bytes
*/
2004-11-06 23:08:05 +03:00
NTSTATUS 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 ;
return NT_STATUS_OK ;
}
2003-11-04 12:10:31 +03:00
2003-11-26 04:16:41 +03:00
/*
push some zero bytes
*/
2004-05-25 20:24:13 +04:00
NTSTATUS 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 ;
return NT_STATUS_OK ;
}
2003-11-09 10:24:06 +03:00
/*
push an array of uint8
*/
2004-11-06 23:08:05 +03:00
NTSTATUS 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 ) ) {
return NT_STATUS_OK ;
}
2003-11-09 10:24:06 +03:00
return ndr_push_bytes ( ndr , data , n ) ;
}
2003-12-12 09:26:34 +03:00
/*
push an array of uint16
*/
2004-05-25 21:24:24 +04:00
NTSTATUS ndr_push_array_uint16 ( struct ndr_push * ndr , int ndr_flags , const uint16_t * data , uint32_t n )
2003-12-12 09:26:34 +03:00
{
int i ;
if ( ! ( ndr_flags & NDR_SCALARS ) ) {
return NT_STATUS_OK ;
}
for ( i = 0 ; i < n ; i + + ) {
2005-02-10 00:10:23 +03:00
NDR_CHECK ( ndr_push_uint16 ( ndr , NDR_SCALARS , data [ i ] ) ) ;
2003-12-12 09:26:34 +03:00
}
return NT_STATUS_OK ;
}
2003-11-14 10:20:46 +03:00
/*
2004-05-25 20:24:13 +04:00
push an array of uint32_t
2003-11-14 10:20:46 +03:00
*/
2004-05-25 20:24:13 +04:00
NTSTATUS ndr_push_array_uint32 ( struct ndr_push * ndr , int ndr_flags , const uint32_t * data , uint32_t n )
2003-11-14 10:20:46 +03:00
{
int i ;
2003-11-17 09:27:45 +03:00
if ( ! ( ndr_flags & NDR_SCALARS ) ) {
return NT_STATUS_OK ;
}
2003-11-14 10:20:46 +03:00
for ( i = 0 ; i < n ; i + + ) {
2005-02-10 00:10:23 +03:00
NDR_CHECK ( ndr_push_uint32 ( ndr , NDR_SCALARS , data [ i ] ) ) ;
2003-11-14 10:20:46 +03:00
}
return NT_STATUS_OK ;
}
2004-08-11 23:48:36 +04:00
/*
2005-01-27 09:33:07 +03:00
push an array of hyper
2004-08-11 23:48:36 +04:00
*/
2005-01-27 09:33:07 +03:00
NTSTATUS ndr_push_array_hyper ( struct ndr_push * ndr , int ndr_flags , const uint64_t * data , uint32_t n )
2004-08-11 23:48:36 +04:00
{
int i ;
if ( ! ( ndr_flags & NDR_SCALARS ) ) {
return NT_STATUS_OK ;
}
for ( i = 0 ; i < n ; i + + ) {
2005-02-10 00:10:23 +03:00
NDR_CHECK ( ndr_push_hyper ( ndr , NDR_SCALARS , data [ i ] ) ) ;
2004-08-11 23:48:36 +04:00
}
return NT_STATUS_OK ;
}
2004-11-01 15:40:43 +03:00
/*
2005-01-27 09:33:07 +03:00
push an array of hyper
2004-11-01 15:40:43 +03:00
*/
NTSTATUS ndr_push_array_WERROR ( struct ndr_push * ndr , int ndr_flags , const WERROR * data , uint32_t n )
{
int i ;
if ( ! ( ndr_flags & NDR_SCALARS ) ) {
return NT_STATUS_OK ;
}
for ( i = 0 ; i < n ; i + + ) {
2005-02-10 00:10:23 +03:00
NDR_CHECK ( ndr_push_WERROR ( ndr , NDR_SCALARS , data [ i ] ) ) ;
2004-11-01 15:40:43 +03:00
}
return NT_STATUS_OK ;
}
2003-11-05 03:49:42 +03:00
/*
save the current position
*/
void ndr_push_save ( struct ndr_push * ndr , struct ndr_push_save * save )
{
save - > offset = ndr - > offset ;
}
/*
restore the position
*/
void ndr_push_restore ( struct ndr_push * ndr , struct ndr_push_save * save )
{
ndr - > offset = save - > offset ;
}
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
*/
2005-02-13 03:07:17 +03:00
NTSTATUS 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 ) {
ndr - > ptr_count + + ;
2003-11-21 16:14:17 +03:00
ptr = ndr - > ptr_count ;
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
*/
NTSTATUS ndr_push_ref_ptr ( struct ndr_push * ndr , const void * p )
{
if ( p = = NULL ) {
return NT_STATUS_INVALID_PARAMETER_MIX ;
}
return ndr_push_uint32 ( ndr , NDR_SCALARS , 0 ) ;
}
2003-11-04 12:10:31 +03:00
2003-11-21 05:19:47 +03:00
/*
2003-11-21 16:14:17 +03:00
pull a general string from the wire
2003-11-21 05:19:47 +03:00
*/
2003-11-21 16:14:17 +03:00
NTSTATUS ndr_pull_string ( struct ndr_pull * ndr , int ndr_flags , const char * * s )
2003-11-21 05:19:47 +03:00
{
2003-11-21 16:14:17 +03:00
char * as = NULL ;
2004-05-25 20:24:13 +04:00
uint32_t len1 , ofs , len2 ;
2004-05-25 21:24:24 +04:00
uint16_t len3 ;
2003-11-21 16:14:17 +03:00
int ret ;
2004-09-01 08:39:06 +04:00
int chset = CH_UTF16 ;
2004-10-11 13:27:19 +04:00
unsigned byte_mul = 2 ;
unsigned flags = ndr - > flags ;
2004-11-29 14:04:36 +03:00
unsigned c_len_term = 0 ;
2003-11-21 16:14:17 +03:00
if ( ! ( ndr_flags & NDR_SCALARS ) ) {
return NT_STATUS_OK ;
2003-11-21 05:19:47 +03:00
}
2003-12-31 04:32:33 +03:00
if ( NDR_BE ( ndr ) ) {
2004-09-01 08:39:06 +04:00
chset = CH_UTF16BE ;
2003-12-16 12:20:34 +03:00
}
2004-10-11 13:27:19 +04:00
if ( flags & LIBNDR_FLAG_STR_ASCII ) {
chset = CH_DOS ;
byte_mul = 1 ;
flags & = ~ LIBNDR_FLAG_STR_ASCII ;
}
2004-11-05 14:31:35 +03:00
if ( flags & LIBNDR_FLAG_STR_UTF8 ) {
chset = CH_UTF8 ;
byte_mul = 1 ;
flags & = ~ LIBNDR_FLAG_STR_UTF8 ;
}
2004-11-02 16:46:39 +03:00
flags & = ~ LIBNDR_FLAG_STR_CONFORMANT ;
2004-11-29 14:04:36 +03:00
if ( flags & LIBNDR_FLAG_STR_CHARLEN ) {
c_len_term = 1 ;
flags & = ~ LIBNDR_FLAG_STR_CHARLEN ;
}
2004-11-02 16:46:39 +03:00
2004-10-11 13:27:19 +04:00
switch ( flags & LIBNDR_STRING_FLAGS ) {
2003-11-21 16:14:17 +03:00
case LIBNDR_FLAG_STR_LEN4 | LIBNDR_FLAG_STR_SIZE4 :
case LIBNDR_FLAG_STR_LEN4 | LIBNDR_FLAG_STR_SIZE4 | LIBNDR_FLAG_STR_NOTERM :
2005-02-10 00:10:23 +03:00
NDR_CHECK ( ndr_pull_uint32 ( ndr , NDR_SCALARS , & len1 ) ) ;
NDR_CHECK ( ndr_pull_uint32 ( ndr , NDR_SCALARS , & ofs ) ) ;
2004-10-11 13:27:19 +04:00
if ( ofs ! = 0 ) {
return ndr_pull_error ( ndr , NDR_ERR_STRING , " non-zero array offset with string flags 0x%x \n " ,
ndr - > flags & LIBNDR_STRING_FLAGS ) ;
}
2005-02-10 00:10:23 +03:00
NDR_CHECK ( ndr_pull_uint32 ( ndr , NDR_SCALARS , & len2 ) ) ;
2003-11-21 16:14:17 +03:00
if ( len2 > len1 ) {
2003-11-22 11:11:32 +03:00
return ndr_pull_error ( ndr , NDR_ERR_STRING ,
" Bad string lengths len1=%u ofs=%u len2=%u \n " ,
len1 , ofs , len2 ) ;
2003-11-21 16:14:17 +03:00
}
if ( len2 = = 0 ) {
2004-08-21 11:43:29 +04:00
* s = talloc_strdup ( ndr , " " ) ;
2003-11-21 16:14:17 +03:00
break ;
}
2004-11-29 14:04:36 +03:00
NDR_PULL_NEED_BYTES ( ndr , ( len2 + c_len_term ) * byte_mul ) ;
2004-08-21 11:43:29 +04:00
ret = convert_string_talloc ( ndr , chset , CH_UNIX ,
2003-11-21 16:14:17 +03:00
ndr - > data + ndr - > offset ,
2004-11-29 14:04:36 +03:00
( len2 + c_len_term ) * byte_mul ,
r2552: Character set conversion and string handling updates.
The intial motivation for this commit was to merge in some of the
bugfixes present in Samba3's chrcnv and string handling code into
Samba4. However, along the way I found a lot of unused functions, and
decided to do a bit more...
The strlen_m code now does not use a fixed buffer, but more work is
needed to finish off other functions in str_util.c. These fixed
length buffers hav caused very nasty, hard to chase down bugs at some
sites.
The strupper_m() function has a strupper_talloc() to replace it (we
need to go around and fix more uses, but it's a start). Use of these
new functions will avoid bugs where the upper or lowercase version of
a string is a different length.
I have removed the push_*_allocate functions, which are replaced by
calls to push_*_talloc. Likewise, pstring and other 'fixed length'
wrappers are removed, where possible.
I have removed the first ('base pointer') argument, used by push_ucs2,
as the Samba4 way of doing things ensures that this is always on an
even boundary anyway. (It was used in only one place, in any case).
(This used to be commit dfecb0150627b500cb026b8a4932fe87902ca392)
2004-09-23 04:51:45 +04:00
( void * * ) & as ) ;
2003-11-21 16:14:17 +03:00
if ( ret = = - 1 ) {
return ndr_pull_error ( ndr , NDR_ERR_CHARCNV ,
" Bad character conversion " ) ;
}
2004-11-29 14:04:36 +03:00
NDR_CHECK ( ndr_pull_advance ( ndr , ( len2 + c_len_term ) * byte_mul ) ) ;
2004-05-28 17:23:30 +04:00
/* this is a way of detecting if a string is sent with the wrong
termination */
if ( ndr - > flags & LIBNDR_FLAG_STR_NOTERM ) {
2004-11-29 14:04:36 +03:00
if ( strlen ( as ) < ( len2 + c_len_term ) ) {
2004-05-28 17:23:30 +04:00
DEBUG ( 6 , ( " short string '%s' \n " , as ) ) ;
}
} else {
2004-11-29 14:04:36 +03:00
if ( strlen ( as ) = = ( len2 + c_len_term ) ) {
2004-05-28 17:23:30 +04:00
DEBUG ( 6 , ( " long string '%s' \n " , as ) ) ;
}
}
2003-11-21 16:14:17 +03:00
* s = as ;
break ;
case LIBNDR_FLAG_STR_SIZE4 :
2004-08-17 13:14:46 +04:00
case LIBNDR_FLAG_STR_SIZE4 | LIBNDR_FLAG_STR_NOTERM :
2005-02-10 00:10:23 +03:00
NDR_CHECK ( ndr_pull_uint32 ( ndr , NDR_SCALARS , & len1 ) ) ;
2004-11-29 14:04:36 +03:00
NDR_PULL_NEED_BYTES ( ndr , ( len1 + c_len_term ) * byte_mul ) ;
2003-11-21 16:14:17 +03:00
if ( len1 = = 0 ) {
2004-08-21 11:43:29 +04:00
* s = talloc_strdup ( ndr , " " ) ;
2003-11-21 16:14:17 +03:00
break ;
}
2004-08-21 11:43:29 +04:00
ret = convert_string_talloc ( ndr , chset , CH_UNIX ,
2003-11-21 16:14:17 +03:00
ndr - > data + ndr - > offset ,
2004-11-29 14:04:36 +03:00
( len1 + c_len_term ) * byte_mul ,
r2552: Character set conversion and string handling updates.
The intial motivation for this commit was to merge in some of the
bugfixes present in Samba3's chrcnv and string handling code into
Samba4. However, along the way I found a lot of unused functions, and
decided to do a bit more...
The strlen_m code now does not use a fixed buffer, but more work is
needed to finish off other functions in str_util.c. These fixed
length buffers hav caused very nasty, hard to chase down bugs at some
sites.
The strupper_m() function has a strupper_talloc() to replace it (we
need to go around and fix more uses, but it's a start). Use of these
new functions will avoid bugs where the upper or lowercase version of
a string is a different length.
I have removed the push_*_allocate functions, which are replaced by
calls to push_*_talloc. Likewise, pstring and other 'fixed length'
wrappers are removed, where possible.
I have removed the first ('base pointer') argument, used by push_ucs2,
as the Samba4 way of doing things ensures that this is always on an
even boundary anyway. (It was used in only one place, in any case).
(This used to be commit dfecb0150627b500cb026b8a4932fe87902ca392)
2004-09-23 04:51:45 +04:00
( void * * ) & as ) ;
2003-11-21 16:14:17 +03:00
if ( ret = = - 1 ) {
return ndr_pull_error ( ndr , NDR_ERR_CHARCNV ,
" Bad character conversion " ) ;
}
2004-11-29 14:04:36 +03:00
NDR_CHECK ( ndr_pull_advance ( ndr , ( len1 + c_len_term ) * byte_mul ) ) ;
2004-08-17 13:14:46 +04:00
/* this is a way of detecting if a string is sent with the wrong
termination */
if ( ndr - > flags & LIBNDR_FLAG_STR_NOTERM ) {
2004-11-29 14:04:36 +03:00
if ( strlen ( as ) < ( len1 + c_len_term ) ) {
2004-08-17 13:14:46 +04:00
DEBUG ( 6 , ( " short string '%s' \n " , as ) ) ;
}
} else {
2004-11-29 14:04:36 +03:00
if ( strlen ( as ) = = ( len1 + c_len_term ) ) {
2004-08-17 13:14:46 +04:00
DEBUG ( 6 , ( " long string '%s' \n " , as ) ) ;
}
}
* s = as ;
break ;
2004-10-11 13:27:19 +04:00
case LIBNDR_FLAG_STR_LEN4 :
case LIBNDR_FLAG_STR_LEN4 | LIBNDR_FLAG_STR_NOTERM :
2005-02-10 00:10:23 +03:00
NDR_CHECK ( ndr_pull_uint32 ( ndr , NDR_SCALARS , & ofs ) ) ;
2004-10-11 13:27:19 +04:00
if ( ofs ! = 0 ) {
return ndr_pull_error ( ndr , NDR_ERR_STRING , " non-zero array offset with string flags 0x%x \n " ,
ndr - > flags & LIBNDR_STRING_FLAGS ) ;
}
2005-02-10 00:10:23 +03:00
NDR_CHECK ( ndr_pull_uint32 ( ndr , NDR_SCALARS , & len1 ) ) ;
2004-11-29 14:04:36 +03:00
NDR_PULL_NEED_BYTES ( ndr , ( len1 + c_len_term ) * byte_mul ) ;
2004-10-11 13:27:19 +04:00
if ( len1 = = 0 ) {
2004-08-21 11:43:29 +04:00
* s = talloc_strdup ( ndr , " " ) ;
2004-08-17 13:14:46 +04:00
break ;
}
2004-08-21 11:43:29 +04:00
ret = convert_string_talloc ( ndr , chset , CH_UNIX ,
2004-08-17 13:14:46 +04:00
ndr - > data + ndr - > offset ,
2004-11-29 14:04:36 +03:00
( len1 + c_len_term ) * byte_mul ,
r2552: Character set conversion and string handling updates.
The intial motivation for this commit was to merge in some of the
bugfixes present in Samba3's chrcnv and string handling code into
Samba4. However, along the way I found a lot of unused functions, and
decided to do a bit more...
The strlen_m code now does not use a fixed buffer, but more work is
needed to finish off other functions in str_util.c. These fixed
length buffers hav caused very nasty, hard to chase down bugs at some
sites.
The strupper_m() function has a strupper_talloc() to replace it (we
need to go around and fix more uses, but it's a start). Use of these
new functions will avoid bugs where the upper or lowercase version of
a string is a different length.
I have removed the push_*_allocate functions, which are replaced by
calls to push_*_talloc. Likewise, pstring and other 'fixed length'
wrappers are removed, where possible.
I have removed the first ('base pointer') argument, used by push_ucs2,
as the Samba4 way of doing things ensures that this is always on an
even boundary anyway. (It was used in only one place, in any case).
(This used to be commit dfecb0150627b500cb026b8a4932fe87902ca392)
2004-09-23 04:51:45 +04:00
( void * * ) & as ) ;
2004-08-17 13:14:46 +04:00
if ( ret = = - 1 ) {
return ndr_pull_error ( ndr , NDR_ERR_CHARCNV ,
" Bad character conversion " ) ;
}
2004-11-29 14:04:36 +03:00
NDR_CHECK ( ndr_pull_advance ( ndr , ( len1 + c_len_term ) * byte_mul ) ) ;
2004-10-11 13:27:19 +04:00
/* this is a way of detecting if a string is sent with the wrong
termination */
if ( ndr - > flags & LIBNDR_FLAG_STR_NOTERM ) {
2004-11-29 14:04:36 +03:00
if ( strlen ( as ) < ( len1 + c_len_term ) ) {
2004-10-11 13:27:19 +04:00
DEBUG ( 6 , ( " short string '%s' \n " , as ) ) ;
}
} else {
2004-11-29 14:04:36 +03:00
if ( strlen ( as ) = = ( len1 + c_len_term ) ) {
2004-10-11 13:27:19 +04:00
DEBUG ( 6 , ( " long string '%s' \n " , as ) ) ;
}
}
2003-11-21 16:14:17 +03:00
* s = as ;
break ;
2004-10-11 13:27:19 +04:00
case LIBNDR_FLAG_STR_SIZE2 :
case LIBNDR_FLAG_STR_SIZE2 | LIBNDR_FLAG_STR_NOTERM :
2005-02-10 00:10:23 +03:00
NDR_CHECK ( ndr_pull_uint16 ( ndr , NDR_SCALARS , & len3 ) ) ;
2004-11-29 14:04:36 +03:00
NDR_PULL_NEED_BYTES ( ndr , ( len3 + c_len_term ) * byte_mul ) ;
2004-10-11 13:27:19 +04:00
if ( len3 = = 0 ) {
* s = talloc_strdup ( ndr , " " ) ;
break ;
}
2004-08-21 11:43:29 +04:00
ret = convert_string_talloc ( ndr , chset , CH_UNIX ,
2003-11-21 16:14:17 +03:00
ndr - > data + ndr - > offset ,
2004-11-29 14:04:36 +03:00
( len3 + c_len_term ) * byte_mul ,
r2552: Character set conversion and string handling updates.
The intial motivation for this commit was to merge in some of the
bugfixes present in Samba3's chrcnv and string handling code into
Samba4. However, along the way I found a lot of unused functions, and
decided to do a bit more...
The strlen_m code now does not use a fixed buffer, but more work is
needed to finish off other functions in str_util.c. These fixed
length buffers hav caused very nasty, hard to chase down bugs at some
sites.
The strupper_m() function has a strupper_talloc() to replace it (we
need to go around and fix more uses, but it's a start). Use of these
new functions will avoid bugs where the upper or lowercase version of
a string is a different length.
I have removed the push_*_allocate functions, which are replaced by
calls to push_*_talloc. Likewise, pstring and other 'fixed length'
wrappers are removed, where possible.
I have removed the first ('base pointer') argument, used by push_ucs2,
as the Samba4 way of doing things ensures that this is always on an
even boundary anyway. (It was used in only one place, in any case).
(This used to be commit dfecb0150627b500cb026b8a4932fe87902ca392)
2004-09-23 04:51:45 +04:00
( void * * ) & as ) ;
2003-11-21 16:14:17 +03:00
if ( ret = = - 1 ) {
return ndr_pull_error ( ndr , NDR_ERR_CHARCNV ,
" Bad character conversion " ) ;
}
2004-11-29 14:04:36 +03:00
NDR_CHECK ( ndr_pull_advance ( ndr , ( len3 + c_len_term ) * byte_mul ) ) ;
2003-11-21 16:14:17 +03:00
2004-10-11 13:27:19 +04:00
/* this is a way of detecting if a string is sent with the wrong
termination */
if ( ndr - > flags & LIBNDR_FLAG_STR_NOTERM ) {
2004-11-29 14:04:36 +03:00
if ( strlen ( as ) < ( len3 + c_len_term ) ) {
2004-10-11 13:27:19 +04:00
DEBUG ( 6 , ( " short string '%s' \n " , as ) ) ;
}
} else {
2004-11-29 14:04:36 +03:00
if ( strlen ( as ) = = ( len3 + c_len_term ) ) {
2004-10-11 13:27:19 +04:00
DEBUG ( 6 , ( " long string '%s' \n " , as ) ) ;
}
2003-11-21 16:14:17 +03:00
}
2004-08-17 13:14:46 +04:00
* s = as ;
2003-11-21 16:14:17 +03:00
break ;
2004-10-11 13:27:19 +04:00
case LIBNDR_FLAG_STR_SIZE2 | LIBNDR_FLAG_STR_NOTERM | LIBNDR_FLAG_STR_BYTESIZE :
2005-02-10 00:10:23 +03:00
NDR_CHECK ( ndr_pull_uint16 ( ndr , NDR_SCALARS , & len3 ) ) ;
2004-10-11 13:27:19 +04:00
NDR_PULL_NEED_BYTES ( ndr , len3 ) ;
if ( len3 = = 0 ) {
* s = talloc_strdup ( ndr , " " ) ;
break ;
}
ret = convert_string_talloc ( ndr , chset , CH_UNIX ,
ndr - > data + ndr - > offset ,
len3 ,
( void * * ) & as ) ;
if ( ret = = - 1 ) {
return ndr_pull_error ( ndr , NDR_ERR_CHARCNV ,
" Bad character conversion " ) ;
}
NDR_CHECK ( ndr_pull_advance ( ndr , len3 ) ) ;
2004-08-17 13:14:46 +04:00
* s = as ;
2003-11-23 09:28:12 +03:00
break ;
2004-10-11 13:27:19 +04:00
case LIBNDR_FLAG_STR_NULLTERM :
if ( byte_mul = = 1 ) {
2004-11-06 23:08:05 +03:00
len1 = ascii_len_n ( ( const char * ) ( ndr - > data + ndr - > offset ) , ndr - > data_size - ndr - > offset ) ;
2004-10-11 13:27:19 +04:00
} else {
len1 = utf16_len_n ( ndr - > data + ndr - > offset , ndr - > data_size - ndr - > offset ) ;
}
ret = convert_string_talloc ( ndr , chset , CH_UNIX ,
ndr - > data + ndr - > offset ,
len1 ,
( void * * ) & as ) ;
if ( ret = = - 1 ) {
return ndr_pull_error ( ndr , NDR_ERR_CHARCNV ,
" Bad character conversion " ) ;
2004-06-05 09:01:38 +04:00
}
2004-10-11 13:27:19 +04:00
NDR_CHECK ( ndr_pull_advance ( ndr , len1 ) ) ;
2004-08-17 13:14:46 +04:00
* s = as ;
2004-06-05 09:01:38 +04:00
break ;
2005-01-21 09:54:10 +03:00
case LIBNDR_FLAG_STR_FIXLEN15 :
2004-10-31 02:19:09 +03:00
case LIBNDR_FLAG_STR_FIXLEN32 :
2005-01-21 09:54:10 +03:00
len1 = ( flags & LIBNDR_FLAG_STR_FIXLEN32 ) ? 32 : 15 ;
2004-10-31 02:19:09 +03:00
NDR_PULL_NEED_BYTES ( ndr , len1 * byte_mul ) ;
ret = convert_string_talloc ( ndr , chset , CH_UNIX ,
ndr - > data + ndr - > offset ,
len1 * byte_mul ,
( void * * ) & as ) ;
if ( ret = = - 1 ) {
return ndr_pull_error ( ndr , NDR_ERR_CHARCNV ,
" Bad character conversion " ) ;
}
NDR_CHECK ( ndr_pull_advance ( ndr , len1 * byte_mul ) ) ;
* s = as ;
break ;
2003-11-21 16:14:17 +03:00
default :
return ndr_pull_error ( ndr , NDR_ERR_STRING , " Bad string flags 0x%x \n " ,
ndr - > flags & LIBNDR_STRING_FLAGS ) ;
2003-11-09 05:21:24 +03:00
}
2003-11-21 16:14:17 +03:00
2003-11-09 05:21:24 +03:00
return NT_STATUS_OK ;
}
2003-11-21 16:14:17 +03:00
2003-11-08 14:21:57 +03:00
/*
2003-11-21 16:14:17 +03:00
push a general string onto the wire
2003-11-08 14:21:57 +03:00
*/
2003-11-21 16:14:17 +03:00
NTSTATUS ndr_push_string ( struct ndr_push * ndr , int ndr_flags , const char * s )
2003-11-08 14:21:57 +03:00
{
2005-01-21 09:54:10 +03:00
ssize_t s_len , c_len , d_len ;
2003-11-21 16:14:17 +03:00
int ret ;
2004-09-01 08:39:06 +04:00
int chset = CH_UTF16 ;
2004-10-11 13:27:19 +04:00
unsigned flags = ndr - > flags ;
unsigned byte_mul = 2 ;
2004-11-02 16:46:39 +03:00
unsigned c_len_term = 1 ;
2003-11-08 14:21:57 +03:00
2003-11-21 16:14:17 +03:00
if ( ! ( ndr_flags & NDR_SCALARS ) ) {
return NT_STATUS_OK ;
2003-11-08 14:21:57 +03:00
}
2003-12-16 12:20:34 +03:00
2003-12-31 04:32:33 +03:00
if ( NDR_BE ( ndr ) ) {
2004-09-01 08:39:06 +04:00
chset = CH_UTF16BE ;
2003-12-16 12:20:34 +03:00
}
2003-11-21 16:14:17 +03:00
s_len = s ? strlen ( s ) : 0 ;
c_len = s ? strlen_m ( s ) : 0 ;
2003-11-08 14:21:57 +03:00
2004-10-11 13:27:19 +04:00
if ( flags & LIBNDR_FLAG_STR_ASCII ) {
chset = CH_DOS ;
byte_mul = 1 ;
flags & = ~ LIBNDR_FLAG_STR_ASCII ;
}
2004-11-05 14:31:35 +03:00
if ( flags & LIBNDR_FLAG_STR_UTF8 ) {
chset = CH_UTF8 ;
byte_mul = 1 ;
flags & = ~ LIBNDR_FLAG_STR_UTF8 ;
}
2004-11-02 16:46:39 +03:00
flags & = ~ LIBNDR_FLAG_STR_CONFORMANT ;
if ( flags & LIBNDR_FLAG_STR_CHARLEN ) {
c_len_term = 0 ;
flags & = ~ LIBNDR_FLAG_STR_CHARLEN ;
}
2004-10-11 13:27:19 +04:00
switch ( flags & LIBNDR_STRING_FLAGS ) {
2003-11-21 16:14:17 +03:00
case LIBNDR_FLAG_STR_LEN4 | LIBNDR_FLAG_STR_SIZE4 :
2005-02-10 00:10:23 +03:00
NDR_CHECK ( ndr_push_uint32 ( ndr , NDR_SCALARS , c_len + c_len_term ) ) ;
NDR_CHECK ( ndr_push_uint32 ( ndr , NDR_SCALARS , 0 ) ) ;
NDR_CHECK ( ndr_push_uint32 ( ndr , NDR_SCALARS , c_len + c_len_term ) ) ;
2004-10-11 13:27:19 +04:00
NDR_PUSH_NEED_BYTES ( ndr , byte_mul * ( c_len + 1 ) ) ;
2003-12-16 12:20:34 +03:00
ret = convert_string ( CH_UNIX , chset ,
2003-11-21 16:14:17 +03:00
s , s_len + 1 ,
2004-10-11 13:27:19 +04:00
ndr - > data + ndr - > offset ,
byte_mul * ( c_len + 1 ) ) ;
2003-11-21 16:14:17 +03:00
if ( ret = = - 1 ) {
return ndr_push_error ( ndr , NDR_ERR_CHARCNV ,
" Bad character conversion " ) ;
}
2004-10-11 13:27:19 +04:00
ndr - > offset + = byte_mul * ( c_len + 1 ) ;
2003-11-21 16:14:17 +03:00
break ;
case LIBNDR_FLAG_STR_LEN4 | LIBNDR_FLAG_STR_SIZE4 | LIBNDR_FLAG_STR_NOTERM :
2005-02-10 00:10:23 +03:00
NDR_CHECK ( ndr_push_uint32 ( ndr , NDR_SCALARS , c_len ) ) ;
NDR_CHECK ( ndr_push_uint32 ( ndr , NDR_SCALARS , 0 ) ) ;
NDR_CHECK ( ndr_push_uint32 ( ndr , NDR_SCALARS , c_len ) ) ;
2004-10-11 13:27:19 +04:00
NDR_PUSH_NEED_BYTES ( ndr , c_len * byte_mul ) ;
2003-12-16 12:20:34 +03:00
ret = convert_string ( CH_UNIX , chset ,
2003-11-21 16:14:17 +03:00
s , s_len ,
2004-10-11 13:27:19 +04:00
ndr - > data + ndr - > offset , c_len * byte_mul ) ;
2003-11-21 16:14:17 +03:00
if ( ret = = - 1 ) {
return ndr_push_error ( ndr , NDR_ERR_CHARCNV ,
" Bad character conversion " ) ;
}
2004-10-11 13:27:19 +04:00
ndr - > offset + = c_len * byte_mul ;
2003-11-21 16:14:17 +03:00
break ;
2004-10-11 13:27:19 +04:00
case LIBNDR_FLAG_STR_LEN4 :
2005-02-10 00:10:23 +03:00
NDR_CHECK ( ndr_push_uint32 ( ndr , NDR_SCALARS , 0 ) ) ;
NDR_CHECK ( ndr_push_uint32 ( ndr , NDR_SCALARS , c_len + c_len_term ) ) ;
2004-10-11 13:27:19 +04:00
NDR_PUSH_NEED_BYTES ( ndr , byte_mul * ( c_len + 1 ) ) ;
2003-12-16 12:20:34 +03:00
ret = convert_string ( CH_UNIX , chset ,
2003-11-21 16:14:17 +03:00
s , s_len + 1 ,
2004-10-11 13:27:19 +04:00
ndr - > data + ndr - > offset , byte_mul * ( c_len + 1 ) ) ;
2003-11-21 16:14:17 +03:00
if ( ret = = - 1 ) {
return ndr_push_error ( ndr , NDR_ERR_CHARCNV ,
" Bad character conversion " ) ;
}
2004-10-11 13:27:19 +04:00
ndr - > offset + = byte_mul * ( c_len + 1 ) ;
2003-11-21 16:14:17 +03:00
break ;
2004-08-17 13:14:46 +04:00
2004-10-11 13:27:19 +04:00
case LIBNDR_FLAG_STR_SIZE4 :
2005-02-10 00:10:23 +03:00
NDR_CHECK ( ndr_push_uint32 ( ndr , NDR_SCALARS , c_len + c_len_term ) ) ;
2004-10-11 13:27:19 +04:00
NDR_PUSH_NEED_BYTES ( ndr , byte_mul * ( c_len + 1 ) ) ;
2004-08-17 13:14:46 +04:00
ret = convert_string ( CH_UNIX , chset ,
2003-11-21 16:14:17 +03:00
s , s_len + 1 ,
2004-10-11 13:27:19 +04:00
ndr - > data + ndr - > offset , byte_mul * ( c_len + 1 ) ) ;
2004-04-19 09:48:03 +04:00
if ( ret = = - 1 ) {
return ndr_push_error ( ndr , NDR_ERR_CHARCNV ,
" Bad character conversion " ) ;
}
2004-10-11 13:27:19 +04:00
ndr - > offset + = byte_mul * ( c_len + 1 ) ;
2004-04-19 09:48:03 +04:00
break ;
2004-10-11 13:27:19 +04:00
case LIBNDR_FLAG_STR_SIZE2 :
2005-02-10 00:10:23 +03:00
NDR_CHECK ( ndr_push_uint16 ( ndr , NDR_SCALARS , c_len + c_len_term ) ) ;
2004-10-11 13:27:19 +04:00
NDR_PUSH_NEED_BYTES ( ndr , byte_mul * ( c_len + 1 ) ) ;
ret = convert_string ( CH_UNIX , chset ,
2003-11-21 16:14:17 +03:00
s , s_len + 1 ,
2004-10-11 13:27:19 +04:00
ndr - > data + ndr - > offset , byte_mul * ( c_len + 1 ) ) ;
2003-11-21 16:14:17 +03:00
if ( ret = = - 1 ) {
return ndr_push_error ( ndr , NDR_ERR_CHARCNV ,
" Bad character conversion " ) ;
}
2004-10-11 13:27:19 +04:00
ndr - > offset + = byte_mul * ( c_len + 1 ) ;
2003-11-21 16:14:17 +03:00
break ;
2003-11-21 05:19:47 +03:00
2004-10-11 13:27:19 +04:00
case LIBNDR_FLAG_STR_NULLTERM :
NDR_PUSH_NEED_BYTES ( ndr , byte_mul * ( c_len + 1 ) ) ;
ret = convert_string ( CH_UNIX , chset ,
s , s_len + 1 ,
ndr - > data + ndr - > offset , byte_mul * ( c_len + 1 ) ) ;
2003-11-23 09:28:12 +03:00
if ( ret = = - 1 ) {
return ndr_push_error ( ndr , NDR_ERR_CHARCNV ,
" Bad character conversion " ) ;
}
2004-10-11 13:27:19 +04:00
ndr - > offset + = byte_mul * ( c_len + 1 ) ;
2003-11-23 09:28:12 +03:00
break ;
2004-10-11 13:27:19 +04:00
case LIBNDR_FLAG_STR_SIZE2 | LIBNDR_FLAG_STR_NOTERM | LIBNDR_FLAG_STR_BYTESIZE :
2005-02-10 00:10:23 +03:00
NDR_CHECK ( ndr_push_uint16 ( ndr , NDR_SCALARS , c_len * byte_mul ) ) ;
2004-10-11 13:27:19 +04:00
NDR_PUSH_NEED_BYTES ( ndr , c_len * byte_mul ) ;
ret = convert_string ( CH_UNIX , chset ,
s , s_len ,
ndr - > data + ndr - > offset , c_len * byte_mul ) ;
2004-06-05 09:01:38 +04:00
if ( ret = = - 1 ) {
return ndr_push_error ( ndr , NDR_ERR_CHARCNV ,
" Bad character conversion " ) ;
}
2004-10-11 13:27:19 +04:00
ndr - > offset + = c_len * byte_mul ;
2004-06-05 09:01:38 +04:00
break ;
2005-01-21 09:54:10 +03:00
case LIBNDR_FLAG_STR_FIXLEN15 :
2004-10-31 02:19:09 +03:00
case LIBNDR_FLAG_STR_FIXLEN32 :
2005-01-21 09:54:10 +03:00
d_len = ( flags & LIBNDR_FLAG_STR_FIXLEN32 ) ? 32 : 15 ;
NDR_PUSH_NEED_BYTES ( ndr , byte_mul * d_len ) ;
2004-10-31 02:19:09 +03:00
ret = convert_string ( CH_UNIX , chset ,
2005-01-31 07:15:58 +03:00
s , s_len ,
2005-01-21 09:54:10 +03:00
ndr - > data + ndr - > offset , byte_mul * d_len ) ;
2004-10-31 02:19:09 +03:00
if ( ret = = - 1 ) {
return ndr_push_error ( ndr , NDR_ERR_CHARCNV ,
" Bad character conversion " ) ;
}
2005-01-21 09:54:10 +03:00
ndr - > offset + = byte_mul * d_len ;
2004-10-31 02:19:09 +03:00
break ;
2003-11-21 16:14:17 +03:00
default :
return ndr_push_error ( ndr , NDR_ERR_STRING , " Bad string flags 0x%x \n " ,
ndr - > flags & LIBNDR_STRING_FLAGS ) ;
2003-11-21 05:19:47 +03:00
}
2003-11-21 16:14:17 +03:00
return NT_STATUS_OK ;
2003-11-09 05:21:24 +03:00
}
2004-11-02 16:46:39 +03:00
/*
push a general string onto the wire
*/
size_t ndr_string_array_size ( struct ndr_push * ndr , const char * s )
{
size_t c_len ;
unsigned flags = ndr - > flags ;
unsigned byte_mul = 2 ;
unsigned c_len_term = 1 ;
if ( flags & LIBNDR_FLAG_STR_FIXLEN32 ) {
return 32 ;
}
2005-01-21 09:54:10 +03:00
if ( flags & LIBNDR_FLAG_STR_FIXLEN15 ) {
return 15 ;
}
2004-11-02 16:46:39 +03:00
c_len = s ? strlen_m ( s ) : 0 ;
2004-11-05 14:31:35 +03:00
if ( flags & ( LIBNDR_FLAG_STR_ASCII | LIBNDR_FLAG_STR_UTF8 ) ) {
2004-11-02 16:46:39 +03:00
byte_mul = 1 ;
}
if ( flags & LIBNDR_FLAG_STR_NOTERM ) {
c_len_term = 0 ;
}
c_len = c_len + c_len_term ;
if ( flags & LIBNDR_FLAG_STR_BYTESIZE ) {
c_len = c_len * byte_mul ;
}
return c_len ;
}
2003-11-11 05:02:29 +03:00
/*
push a NTTIME
*/
2005-02-10 00:10:23 +03:00
NTSTATUS 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 ) ) ;
2003-11-11 05:02:29 +03:00
return NT_STATUS_OK ;
}
/*
pull a NTTIME
*/
2005-02-10 00:10:23 +03:00
NTSTATUS 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 ) ) ;
2003-11-11 05:02:29 +03:00
return NT_STATUS_OK ;
}
2003-11-11 07:04:36 +03:00
2004-11-19 05:35:48 +03:00
/*
push a NTTIME
*/
2005-02-10 00:10:23 +03:00
NTSTATUS 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 ) ) ;
2004-11-19 05:35:48 +03:00
return NT_STATUS_OK ;
}
/*
2005-01-11 08:16:43 +03:00
pull a NTTIME_1sec
2004-11-19 05:35:48 +03:00
*/
2005-02-10 00:10:23 +03:00
NTSTATUS 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 ;
return NT_STATUS_OK ;
}
2005-01-11 08:16:43 +03:00
/*
pull a NTTIME_hyper
*/
2005-02-10 00:10:23 +03:00
NTSTATUS 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 ) ) ;
2005-01-11 08:16:43 +03:00
return NT_STATUS_OK ;
}
/*
push a NTTIME_hyper
*/
2005-02-10 00:10:23 +03:00
NTSTATUS 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 ) ) ;
2005-01-11 08:16:43 +03:00
return NT_STATUS_OK ;
}
2003-12-01 04:41:38 +03:00
/*
push a time_t
*/
2005-02-10 00:10:23 +03:00
NTSTATUS 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
*/
2005-02-10 00:10:23 +03:00
NTSTATUS 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 ;
return NT_STATUS_OK ;
}
2003-11-11 07:04:36 +03:00
2005-02-01 07:12:44 +03:00
/*
pull a ipv4address
*/
2005-02-10 00:10:23 +03:00
NTSTATUS ndr_pull_ipv4address ( struct ndr_pull * ndr , int ndr_flags , const char * * address )
2005-02-01 07:12:44 +03:00
{
struct ipv4_addr in ;
2005-02-10 00:10:23 +03:00
NDR_CHECK ( ndr_pull_uint32 ( ndr , ndr_flags , & in . addr ) ) ;
2005-02-01 07:12:44 +03:00
in . addr = htonl ( in . addr ) ;
* address = talloc_strdup ( ndr , sys_inet_ntoa ( in ) ) ;
NT_STATUS_HAVE_NO_MEMORY ( * address ) ;
return NT_STATUS_OK ;
}
/*
push a ipv4address
*/
2005-02-10 00:10:23 +03:00
NTSTATUS ndr_push_ipv4address ( struct ndr_push * ndr , int ndr_flags , const char * address )
2005-02-01 07:12:44 +03:00
{
uint32_t addr = interpret_addr ( address ) ;
2005-02-10 00:10:23 +03:00
NDR_CHECK ( ndr_push_uint32 ( ndr , ndr_flags , htonl ( addr ) ) ) ;
2005-02-01 07:12:44 +03:00
return NT_STATUS_OK ;
}
/*
print a ipv4address
*/
void ndr_print_ipv4address ( struct ndr_print * ndr , const char * name ,
const char * address )
{
ndr - > print ( ndr , " %-25s: %s " , name , address ) ;
}
2003-11-11 07:38:51 +03:00
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
}
2005-01-05 02:26:12 +03:00
void ndr_print_enum ( struct ndr_print * ndr , const char * name , const char * type ,
2005-01-05 18:36:26 +03:00
const char * val , uint_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
}
void ndr_print_bitmap_flag ( struct ndr_print * ndr , size_t size , const char * flag_name , uint_t flag , uint_t value )
{
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
}
2004-05-25 21:50:17 +04:00
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 ) ;
}
2004-05-25 21:24:24 +04:00
void ndr_print_uint16 ( struct ndr_print * ndr , const char * name , uint16_t v )
2003-11-11 07:04:36 +03:00
{
ndr - > print ( ndr , " %-25s: 0x%04x (%u) " , name , v , v ) ;
}
2004-05-25 20:24:13 +04:00
void ndr_print_uint32 ( struct ndr_print * ndr , const char * name , uint32_t v )
2003-11-11 07:04:36 +03:00
{
ndr - > print ( ndr , " %-25s: 0x%08x (%u) " , name , v , v ) ;
}
2004-10-15 11:19:09 +04:00
void ndr_print_int32 ( struct ndr_print * ndr , const char * name , int32_t v )
{
ndr - > print ( ndr , " %-25s: %d " , name , v ) ;
}
2005-01-27 09:16:59 +03:00
void ndr_print_udlong ( struct ndr_print * ndr , const char * name , uint64_t v )
2004-05-25 17:57:39 +04:00
{
2004-11-19 05:35:48 +03:00
ndr - > print ( ndr , " %-25s: 0x%08x%08x (%llu) " , name ,
( uint32_t ) ( v > > 32 ) ,
( uint32_t ) ( v & 0xFFFFFFFF ) ,
v ) ;
2004-05-25 17:57:39 +04:00
}
2005-02-16 13:03:18 +03:00
void ndr_print_udlongr ( struct ndr_print * ndr , const char * name , uint64_t v )
{
ndr_print_udlong ( ndr , name , v ) ;
}
2005-01-27 09:16:59 +03:00
void ndr_print_dlong ( struct ndr_print * ndr , const char * name , int64_t v )
2004-05-25 17:57:39 +04:00
{
ndr - > print ( ndr , " %-25s: 0x%08x%08x (%lld) " , name ,
2004-05-25 20:24:13 +04:00
( uint32_t ) ( v > > 32 ) ,
( uint32_t ) ( v & 0xFFFFFFFF ) ,
2004-05-25 17:57:39 +04:00
v ) ;
}
2005-01-27 09:33:07 +03:00
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
}
2003-11-11 07:04:36 +03:00
void ndr_print_ptr ( struct ndr_print * ndr , const char * name , const void * p )
{
if ( p ) {
ndr - > print ( ndr , " %-25s: * " , name ) ;
} else {
ndr - > print ( ndr , " %-25s: NULL " , name ) ;
}
}
2003-11-21 16:14:17 +03:00
void ndr_print_string ( struct ndr_print * ndr , const char * name , const char * s )
2003-11-11 07:04:36 +03:00
{
2003-11-17 05:18:11 +03:00
if ( s ) {
ndr - > print ( ndr , " %-25s: '%s' " , name , s ) ;
} else {
ndr - > print ( ndr , " %-25s: NULL " , name ) ;
}
2003-11-11 07:04:36 +03:00
}
void ndr_print_NTTIME ( struct ndr_print * ndr , const char * name , NTTIME t )
{
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
2005-01-27 09:16:59 +03:00
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
}
2005-01-27 09:16:59 +03:00
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 ) ;
}
2003-12-01 04:41:38 +03:00
void ndr_print_time_t ( struct ndr_print * ndr , const char * name , time_t t )
{
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
}
}
2004-10-15 11:38:46 +04:00
void ndr_print_union ( struct ndr_print * ndr , const char * name , int level , const char * type )
2003-11-11 07:38:51 +03:00
{
2004-10-15 11:38:46 +04:00
ndr - > print ( ndr , " %-25s: union %s(case %d) " , name , type , level ) ;
2003-11-11 07:38:51 +03:00
}
2004-05-25 21:24:24 +04:00
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
2004-11-01 15:40:43 +03:00
void ndr_print_array_WERROR ( struct ndr_print * ndr , const char * name ,
const WERROR * data , uint32_t count )
{
int i ;
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_WERROR ( ndr , idx , data [ i ] ) ;
free ( idx ) ;
}
}
ndr - > depth - - ;
}
2005-01-27 09:33:07 +03:00
void ndr_print_array_hyper ( struct ndr_print * ndr , const char * name ,
2005-01-27 09:16:59 +03:00
const uint64_t * data , uint32_t count )
2004-08-11 23:48:36 +04:00
{
int i ;
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 ) {
2005-01-27 09:33:07 +03:00
ndr_print_hyper ( ndr , idx , data [ i ] ) ;
2004-08-11 23:48:36 +04:00
free ( idx ) ;
}
}
ndr - > depth - - ;
}
2003-11-11 09:22:58 +03:00
void ndr_print_array_uint32 ( struct ndr_print * ndr , const char * name ,
2004-05-25 20:24:13 +04:00
const uint32_t * data , uint32_t count )
2003-11-11 09:22:58 +03:00
{
int i ;
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_uint32 ( ndr , idx , data [ i ] ) ;
free ( idx ) ;
}
}
ndr - > depth - - ;
}
2003-11-11 10:57:08 +03:00
2003-12-12 09:26:34 +03:00
void ndr_print_array_uint16 ( struct ndr_print * ndr , const char * name ,
2004-05-25 21:24:24 +04:00
const uint16_t * data , uint32_t count )
2003-12-12 09:26:34 +03:00
{
int i ;
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_uint16 ( ndr , idx , data [ i ] ) ;
free ( idx ) ;
}
}
ndr - > depth - - ;
}
2003-11-15 13:58:29 +03:00
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 - - ;
}
2003-11-17 14:55:56 +03:00
void ndr_print_DATA_BLOB ( struct ndr_print * ndr , const char * name , DATA_BLOB r )
{
ndr - > print ( ndr , " %-25s: DATA_BLOB length=%u " , name , 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 .
*/
2005-02-10 00:10:23 +03:00
NTSTATUS 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 ) ) ;
return NT_STATUS_OK ;
}
/*
pull a DATA_BLOB from the wire .
*/
2005-02-10 00:10:23 +03:00
NTSTATUS ndr_pull_DATA_BLOB ( struct ndr_pull * ndr , int ndr_flags , DATA_BLOB * blob )
2003-11-17 05:18:11 +03:00
{
2004-05-25 20:24:13 +04:00
uint32_t length ;
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 ) ;
2004-08-21 11:43:29 +04:00
* blob = data_blob_talloc ( ndr , ndr - > data + ndr - > offset , length ) ;
2003-11-17 05:18:11 +03:00
ndr - > offset + = length ;
return NT_STATUS_OK ;
}
2004-10-15 13:22:21 +04:00
2005-01-31 19:10:36 +03:00
uint32_t ndr_size_DATA_BLOB ( int ret , const DATA_BLOB * data , int flags )
2004-10-15 13:22:21 +04:00
{
return ret + data - > length ;
}
2005-01-31 19:10:36 +03:00
uint32_t ndr_size_string ( int ret , const char * const * string , int flags )
2004-10-15 13:22:21 +04:00
{
/* FIXME: Is this correct for all strings ? */
if ( ! ( * string ) ) return ret ;
return ret + strlen ( * string ) + 1 ;
}