LCOV - code coverage report
Current view: top level - librpc/ndr - ndr_basic.c (source / functions) Hit Total Coverage
Test: coverage report for v4-17-lts 011c5a9f Lines: 511 715 71.5 %
Date: 2026-05-29 04:08:37 Functions: 99 124 79.8 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             : 
       4             :    routines for marshalling/unmarshalling basic types
       5             : 
       6             :    Copyright (C) Andrew Tridgell 2003
       7             : 
       8             :    This program is free software; you can redistribute it and/or modify
       9             :    it under the terms of the GNU General Public License as published by
      10             :    the Free Software Foundation; either version 3 of the License, or
      11             :    (at your option) any later version.
      12             : 
      13             :    This program is distributed in the hope that it will be useful,
      14             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      15             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      16             :    GNU General Public License for more details.
      17             : 
      18             :    You should have received a copy of the GNU General Public License
      19             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      20             : */
      21             : 
      22             : #include "replace.h"
      23             : #include "system/network.h"
      24             : #include "librpc/ndr/libndr.h"
      25             : #include "lib/util/util_net.h"
      26             : #include "lib/util/debug.h"
      27             : #include "lib/util/util.h"
      28             : #include "lib/util/bytearray.h"
      29             : 
      30             : #define NDR_PULL_U16(ndr, ofs) \
      31             :         (NDR_BE(ndr) ? PULL_BE_U16(ndr->data,ofs) : PULL_LE_U16(ndr->data,ofs))
      32             : 
      33             : #define NDR_PULL_U32(ndr, ofs) \
      34             :         (NDR_BE(ndr) ? PULL_BE_U32(ndr->data,ofs) : PULL_LE_U32(ndr->data,ofs))
      35             : 
      36             : #define NDR_PULL_I32(ndr, ofs) \
      37             :         (int32_t)(NDR_BE(ndr) ? PULL_BE_U32(ndr->data,ofs) : PULL_LE_U32(ndr->data,ofs))
      38             : 
      39             : #define NDR_PUSH_U16(ndr, ofs, v) \
      40             :         do { \
      41             :                 if (NDR_BE(ndr)) { \
      42             :                         PUSH_BE_U16(ndr->data, ofs, v); \
      43             :                 } else { \
      44             :                         PUSH_LE_U16(ndr->data, ofs, v); \
      45             :                 } \
      46             :         } while (0)
      47             : 
      48             : #define NDR_PUSH_U32(ndr, ofs, v) \
      49             :         do { \
      50             :                 if (NDR_BE(ndr)) { \
      51             :                         PUSH_BE_U32(ndr->data, ofs, v); \
      52             :                 } else { \
      53             :                         PUSH_LE_U32(ndr->data, ofs, v); \
      54             :                 } \
      55             :         } while (0)
      56             : 
      57             : #define NDR_PUSH_I32(ndr, ofs, v) \
      58             :         do { \
      59             :                 if (NDR_BE(ndr)) { \
      60             :                         PUSH_BE_U32(ndr->data, ofs, v); \
      61             :                 } else { \
      62             :                         PUSH_LE_U32(ndr->data, ofs, v); \
      63             :                 } \
      64             :         } while (0)
      65             : 
      66             : static void ndr_dump_data(struct ndr_print *ndr, const uint8_t *buf, int len);
      67             : 
      68             : /*
      69             :   check for data leaks from the server by looking for non-zero pad bytes
      70             :   these could also indicate that real structure elements have been
      71             :   mistaken for padding in the IDL
      72             : */
      73           0 : _PUBLIC_ void ndr_check_padding(struct ndr_pull *ndr, size_t n)
      74             : {
      75           0 :         size_t ofs2 = (ndr->offset + (n-1)) & ~(n-1);
      76             :         size_t i;
      77           0 :         for (i=ndr->offset;i<ofs2;i++) {
      78           0 :                 if (ndr->data[i] != 0) {
      79           0 :                         break;
      80             :                 }
      81             :         }
      82           0 :         if (i<ofs2) {
      83           0 :                 DEBUG(0,("WARNING: Non-zero padding to %d: ", (int)n));
      84           0 :                 for (i=ndr->offset;i<ofs2;i++) {
      85           0 :                         DEBUG(0,("%02x ", ndr->data[i]));
      86             :                 }
      87           0 :                 DEBUG(0,("\n"));
      88             :         }
      89             : 
      90           0 : }
      91             : 
      92             : /*
      93             :   parse a int8_t
      94             : */
      95   165534877 : _PUBLIC_ enum ndr_err_code ndr_pull_int8(struct ndr_pull *ndr, int ndr_flags, int8_t *v)
      96             : {
      97   165534877 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
      98   165534877 :         NDR_PULL_NEED_BYTES(ndr, 1);
      99   165534877 :         *v = (int8_t)PULL_BE_U8(ndr->data, ndr->offset);
     100   165534877 :         ndr->offset += 1;
     101   165534877 :         return NDR_ERR_SUCCESS;
     102             : }
     103             : 
     104             : /*
     105             :   parse a uint8_t
     106             : */
     107   467057515 : _PUBLIC_ enum ndr_err_code ndr_pull_uint8(struct ndr_pull *ndr, int ndr_flags, uint8_t *v)
     108             : {
     109   467057515 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     110   467057515 :         NDR_PULL_NEED_BYTES(ndr, 1);
     111   467057515 :         *v = PULL_BE_U8(ndr->data, ndr->offset);
     112   467057515 :         ndr->offset += 1;
     113   467057515 :         return NDR_ERR_SUCCESS;
     114             : }
     115             : 
     116             : /*
     117             :   parse a int16_t
     118             : */
     119           0 : _PUBLIC_ enum ndr_err_code ndr_pull_int16(struct ndr_pull *ndr, int ndr_flags, int16_t *v)
     120             : {
     121           0 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     122           0 :         NDR_PULL_ALIGN(ndr, 2);
     123           0 :         NDR_PULL_NEED_BYTES(ndr, 2);
     124           0 :         *v = (uint16_t)NDR_PULL_U16(ndr, ndr->offset);
     125           0 :         ndr->offset += 2;
     126           0 :         return NDR_ERR_SUCCESS;
     127             : }
     128             : 
     129             : /*
     130             :   parse a uint16_t
     131             : */
     132   935659828 : _PUBLIC_ enum ndr_err_code ndr_pull_uint16(struct ndr_pull *ndr, int ndr_flags, uint16_t *v)
     133             : {
     134   935659828 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     135   935659828 :         NDR_PULL_ALIGN(ndr, 2);
     136   935659828 :         NDR_PULL_NEED_BYTES(ndr, 2);
     137   935659828 :         *v = NDR_PULL_U16(ndr, ndr->offset);
     138   935659828 :         ndr->offset += 2;
     139   935659828 :         return NDR_ERR_SUCCESS;
     140             : }
     141             : 
     142             : /*
     143             :   parse a uint1632_t
     144             : */
     145       33742 : _PUBLIC_ enum ndr_err_code ndr_pull_uint1632(struct ndr_pull *ndr, int ndr_flags, uint16_t *v)
     146             : {
     147       33742 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     148       33742 :         if (unlikely(ndr->flags & LIBNDR_FLAG_NDR64)) {
     149           0 :                 uint32_t v32 = 0;
     150           0 :                 enum ndr_err_code err = ndr_pull_uint32(ndr, ndr_flags, &v32);
     151           0 :                 *v = v32;
     152           0 :                 if (unlikely(v32 != *v)) {
     153           0 :                         DEBUG(0,(__location__ ": non-zero upper 16 bits 0x%08x\n", (unsigned)v32));
     154           0 :                         return NDR_ERR_NDR64;
     155             :                 }
     156           0 :                 return err;
     157             :         }
     158       33742 :         return ndr_pull_uint16(ndr, ndr_flags, v);
     159             : }
     160             : 
     161             : /*
     162             :   parse a int32_t
     163             : */
     164       21706 : _PUBLIC_ enum ndr_err_code ndr_pull_int32(struct ndr_pull *ndr, int ndr_flags, int32_t *v)
     165             : {
     166       21706 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     167       21706 :         NDR_PULL_ALIGN(ndr, 4);
     168       21706 :         NDR_PULL_NEED_BYTES(ndr, 4);
     169       21706 :         *v = NDR_PULL_I32(ndr, ndr->offset);
     170       21706 :         ndr->offset += 4;
     171       21706 :         return NDR_ERR_SUCCESS;
     172             : }
     173             : 
     174             : /*
     175             :   parse a uint32_t
     176             : */
     177  1362872319 : _PUBLIC_ enum ndr_err_code ndr_pull_uint32(struct ndr_pull *ndr, int ndr_flags, uint32_t *v)
     178             : {
     179  1362872319 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     180  1362872319 :         NDR_PULL_ALIGN(ndr, 4);
     181  1362872319 :         NDR_PULL_NEED_BYTES(ndr, 4);
     182  1362872273 :         *v = NDR_PULL_U32(ndr, ndr->offset);
     183  1362872273 :         ndr->offset += 4;
     184  1362872273 :         return NDR_ERR_SUCCESS;
     185             : }
     186             : 
     187             : /*
     188             :   parse a arch dependent uint32/uint64
     189             : */
     190   101600883 : _PUBLIC_ enum ndr_err_code ndr_pull_uint3264(struct ndr_pull *ndr, int ndr_flags, uint32_t *v)
     191             : {
     192   101600883 :         uint64_t v64 = 0;
     193             :         enum ndr_err_code err;
     194   101600883 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     195   101600883 :         if (likely(!(ndr->flags & LIBNDR_FLAG_NDR64))) {
     196   101600883 :                 return ndr_pull_uint32(ndr, ndr_flags, v);
     197             :         }
     198           0 :         err = ndr_pull_hyper(ndr, ndr_flags, &v64);
     199           0 :         if (!NDR_ERR_CODE_IS_SUCCESS(err)) {
     200           0 :                 return err;
     201             :         }
     202           0 :         *v = (uint32_t)v64;
     203           0 :         if (unlikely(v64 != *v)) {
     204           0 :                 DEBUG(0,(__location__ ": non-zero upper 32 bits 0x%016llx\n",
     205             :                          (unsigned long long)v64));
     206           0 :                 return ndr_pull_error(ndr, NDR_ERR_NDR64, __location__ ": non-zero upper 32 bits 0x%016llx\n",
     207             :                          (unsigned long long)v64);
     208             :         }
     209           0 :         return err;
     210             : }
     211             : 
     212             : /*
     213             :   parse a double
     214             : */
     215           0 : _PUBLIC_ enum ndr_err_code ndr_pull_double(struct ndr_pull *ndr, int ndr_flags, double *v)
     216             : {
     217           0 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     218           0 :         NDR_PULL_ALIGN(ndr, 8);
     219           0 :         NDR_PULL_NEED_BYTES(ndr, 8);
     220           0 :         memcpy(v, ndr->data+ndr->offset, 8);
     221           0 :         ndr->offset += 8;
     222           0 :         return NDR_ERR_SUCCESS;
     223             : }
     224             : 
     225             : /*
     226             :   parse a pointer referent identifier stored in 2 bytes
     227             : */
     228      380634 : _PUBLIC_ enum ndr_err_code ndr_pull_relative_ptr_short(struct ndr_pull *ndr, uint16_t *v)
     229             : {
     230      380634 :         NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, v));
     231      380634 :         if (*v != 0) {
     232      380622 :                 ndr->ptr_count++;
     233             :         }
     234      380634 :         *(v) -= ndr->relative_rap_convert;
     235      380634 :         return NDR_ERR_SUCCESS;
     236             : }
     237             : 
     238             : /*
     239             :   parse a pointer referent identifier
     240             : */
     241    61586628 : _PUBLIC_ enum ndr_err_code ndr_pull_generic_ptr(struct ndr_pull *ndr, uint32_t *v)
     242             : {
     243    61586628 :         NDR_CHECK(ndr_pull_uint3264(ndr, NDR_SCALARS, v));
     244    61586628 :         if (*v != 0) {
     245    56644105 :                 ndr->ptr_count++;
     246             :         }
     247    61586628 :         return NDR_ERR_SUCCESS;
     248             : }
     249             : 
     250             : /*
     251             :   parse a ref pointer referent identifier
     252             : */
     253       27788 : _PUBLIC_ enum ndr_err_code ndr_pull_ref_ptr(struct ndr_pull *ndr, uint32_t *v)
     254             : {
     255       27788 :         NDR_CHECK(ndr_pull_uint3264(ndr, NDR_SCALARS, v));
     256             :         /* ref pointers always point to data */
     257       27788 :         *v = 1;
     258       27788 :         return NDR_ERR_SUCCESS;
     259             : }
     260             : 
     261             : /*
     262             :   parse a udlong
     263             : */
     264   238813532 : _PUBLIC_ enum ndr_err_code ndr_pull_udlong(struct ndr_pull *ndr, int ndr_flags, uint64_t *v)
     265             : {
     266   238813532 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     267   238813532 :         NDR_PULL_ALIGN(ndr, 4);
     268   238813532 :         NDR_PULL_NEED_BYTES(ndr, 8);
     269   238813522 :         *v = NDR_PULL_U32(ndr, ndr->offset);
     270   238813522 :         *v |= (uint64_t)(NDR_PULL_U32(ndr, ndr->offset+4)) << 32;
     271   238813522 :         ndr->offset += 8;
     272   238813522 :         return NDR_ERR_SUCCESS;
     273             : }
     274             : 
     275             : /*
     276             :   parse a udlongr
     277             : */
     278       12732 : _PUBLIC_ enum ndr_err_code ndr_pull_udlongr(struct ndr_pull *ndr, int ndr_flags, uint64_t *v)
     279             : {
     280       12732 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     281       12732 :         NDR_PULL_ALIGN(ndr, 4);
     282       12732 :         NDR_PULL_NEED_BYTES(ndr, 8);
     283       12732 :         *v = ((uint64_t)NDR_PULL_U32(ndr, ndr->offset)) << 32;
     284       12732 :         *v |= NDR_PULL_U32(ndr, ndr->offset+4);
     285       12732 :         ndr->offset += 8;
     286       12732 :         return NDR_ERR_SUCCESS;
     287             : }
     288             : 
     289             : /*
     290             :   parse a dlong
     291             : */
     292         686 : _PUBLIC_ enum ndr_err_code ndr_pull_dlong(struct ndr_pull *ndr, int ndr_flags, int64_t *v)
     293             : {
     294         686 :         return ndr_pull_udlong(ndr, ndr_flags, (uint64_t *)v);
     295             : }
     296             : 
     297             : /*
     298             :   parse a hyper
     299             : */
     300   234140057 : _PUBLIC_ enum ndr_err_code ndr_pull_hyper(struct ndr_pull *ndr, int ndr_flags, uint64_t *v)
     301             : {
     302   234140057 :         NDR_PULL_ALIGN(ndr, 8);
     303   234140057 :         if (NDR_BE(ndr)) {
     304        7251 :                 return ndr_pull_udlongr(ndr, ndr_flags, v);
     305             :         }
     306   234132806 :         return ndr_pull_udlong(ndr, ndr_flags, v);
     307             : }
     308             : 
     309             : /*
     310             :   parse a pointer
     311             : */
     312      674196 : _PUBLIC_ enum ndr_err_code ndr_pull_pointer(struct ndr_pull *ndr, int ndr_flags, void* *v)
     313             : {
     314             :         uintptr_t h;
     315      674196 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     316      674196 :         NDR_PULL_ALIGN(ndr, sizeof(h));
     317      674196 :         NDR_PULL_NEED_BYTES(ndr, sizeof(h));
     318      674196 :         memcpy(&h, ndr->data+ndr->offset, sizeof(h));
     319      674196 :         ndr->offset += sizeof(h);
     320      674196 :         *v = (void *)h;
     321      674196 :         return NDR_ERR_SUCCESS;
     322             : }
     323             : 
     324             : /*
     325             :   pull a NTSTATUS
     326             : */
     327      131027 : _PUBLIC_ enum ndr_err_code ndr_pull_NTSTATUS(struct ndr_pull *ndr, int ndr_flags, NTSTATUS *status)
     328             : {
     329             :         uint32_t v;
     330      131027 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     331      131027 :         NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &v));
     332      131027 :         *status = NT_STATUS(v);
     333      131027 :         return NDR_ERR_SUCCESS;
     334             : }
     335             : 
     336             : /*
     337             :   push a NTSTATUS
     338             : */
     339      699828 : _PUBLIC_ enum ndr_err_code ndr_push_NTSTATUS(struct ndr_push *ndr, int ndr_flags, NTSTATUS status)
     340             : {
     341      699828 :         return ndr_push_uint32(ndr, ndr_flags, NT_STATUS_V(status));
     342             : }
     343             : 
     344       19978 : _PUBLIC_ void ndr_print_NTSTATUS(struct ndr_print *ndr, const char *name, NTSTATUS r)
     345             : {
     346       19978 :         ndr->print(ndr, "%-25s: %s", name, nt_errstr(r));
     347       19978 : }
     348             : 
     349             : /*
     350             :   pull a WERROR
     351             : */
     352      159144 : _PUBLIC_ enum ndr_err_code ndr_pull_WERROR(struct ndr_pull *ndr, int ndr_flags, WERROR *status)
     353             : {
     354             :         uint32_t v;
     355      159144 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     356      159144 :         NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &v));
     357      159144 :         *status = W_ERROR(v);
     358      159144 :         return NDR_ERR_SUCCESS;
     359             : }
     360             : 
     361             : /*
     362             :   pull a HRESULT
     363             : */
     364           0 : _PUBLIC_ enum ndr_err_code ndr_pull_HRESULT(struct ndr_pull *ndr, int ndr_flags, HRESULT *status)
     365             : {
     366             :         uint32_t v;
     367           0 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     368           0 :         NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &v));
     369           0 :         *status = HRES_ERROR(v);
     370           0 :         return NDR_ERR_SUCCESS;
     371             : }
     372             : 
     373             : /*
     374             :   parse a uint8_t enum
     375             : */
     376   148458199 : _PUBLIC_ enum ndr_err_code ndr_pull_enum_uint8(struct ndr_pull *ndr, int ndr_flags, uint8_t *v)
     377             : {
     378   148458199 :         return ndr_pull_uint8(ndr, ndr_flags, v);
     379             : }
     380             : 
     381             : /*
     382             :   parse a uint16_t enum
     383             : */
     384      745590 : _PUBLIC_ enum ndr_err_code ndr_pull_enum_uint16(struct ndr_pull *ndr, int ndr_flags, uint16_t *v)
     385             : {
     386      745590 :         return ndr_pull_uint16(ndr, ndr_flags, v);
     387             : }
     388             : 
     389             : /*
     390             :   parse a uint1632_t enum (uint32_t on NDR64)
     391             : */
     392    14796436 : _PUBLIC_ enum ndr_err_code ndr_pull_enum_uint1632(struct ndr_pull *ndr, int ndr_flags, uint16_t *v)
     393             : {
     394    14796436 :         if (unlikely(ndr->flags & LIBNDR_FLAG_NDR64)) {
     395             :                 uint32_t v32;
     396           0 :                 NDR_CHECK(ndr_pull_uint32(ndr, ndr_flags, &v32));
     397           0 :                 *v = v32;
     398           0 :                 if (v32 != *v) {
     399           0 :                         DEBUG(0,(__location__ ": non-zero upper 16 bits 0x%08x\n", (unsigned)v32));
     400           0 :                         return NDR_ERR_NDR64;
     401             :                 }
     402           0 :                 return NDR_ERR_SUCCESS;
     403             :         }
     404    14796436 :         return ndr_pull_uint16(ndr, ndr_flags, v);
     405             : }
     406             : 
     407             : /*
     408             :   parse a uint32_t enum
     409             : */
     410    84342130 : _PUBLIC_ enum ndr_err_code ndr_pull_enum_uint32(struct ndr_pull *ndr, int ndr_flags, uint32_t *v)
     411             : {
     412    84342130 :         return ndr_pull_uint32(ndr, ndr_flags, v);
     413             : }
     414             : 
     415             : /*
     416             :   push a uint8_t enum
     417             : */
     418    46377865 : _PUBLIC_ enum ndr_err_code ndr_push_enum_uint8(struct ndr_push *ndr, int ndr_flags, uint8_t v)
     419             : {
     420    46377865 :         return ndr_push_uint8(ndr, ndr_flags, v);
     421             : }
     422             : 
     423             : /*
     424             :   push a uint16_t enum
     425             : */
     426     1001738 : _PUBLIC_ enum ndr_err_code ndr_push_enum_uint16(struct ndr_push *ndr, int ndr_flags, uint16_t v)
     427             : {
     428     1001738 :         return ndr_push_uint16(ndr, ndr_flags, v);
     429             : }
     430             : 
     431             : /*
     432             :   push a uint32_t enum
     433             : */
     434    86928790 : _PUBLIC_ enum ndr_err_code ndr_push_enum_uint32(struct ndr_push *ndr, int ndr_flags, uint32_t v)
     435             : {
     436    86928790 :         return ndr_push_uint32(ndr, ndr_flags, v);
     437             : }
     438             : 
     439             : /*
     440             :   push a uint1632_t enum
     441             : */
     442     6807868 : _PUBLIC_ enum ndr_err_code ndr_push_enum_uint1632(struct ndr_push *ndr, int ndr_flags, uint16_t v)
     443             : {
     444     6807868 :         if (unlikely(ndr->flags & LIBNDR_FLAG_NDR64)) {
     445           0 :                 return ndr_push_uint32(ndr, ndr_flags, v);
     446             :         }
     447     6807868 :         return ndr_push_uint16(ndr, ndr_flags, v);
     448             : }
     449             : 
     450             : /*
     451             :   push a WERROR
     452             : */
     453     1022438 : _PUBLIC_ enum ndr_err_code ndr_push_WERROR(struct ndr_push *ndr, int ndr_flags, WERROR status)
     454             : {
     455     1022438 :         return ndr_push_uint32(ndr, NDR_SCALARS, W_ERROR_V(status));
     456             : }
     457             : 
     458        9169 : _PUBLIC_ void ndr_print_WERROR(struct ndr_print *ndr, const char *name, WERROR r)
     459             : {
     460        9169 :         ndr->print(ndr, "%-25s: %s", name, win_errstr(r));
     461        9169 : }
     462             : 
     463             : /*
     464             :   push a HRESULT
     465             : */
     466           0 : _PUBLIC_ enum ndr_err_code ndr_push_HRESULT(struct ndr_push *ndr, int ndr_flags, HRESULT status)
     467             : {
     468           0 :         return ndr_push_uint32(ndr, NDR_SCALARS, HRES_ERROR_V(status));
     469             : }
     470             : 
     471           0 : _PUBLIC_ void ndr_print_HRESULT(struct ndr_print *ndr, const char *name, HRESULT r)
     472             : {
     473           0 :         ndr->print(ndr, "%-25s: %s", name, hresult_errstr(r));
     474           0 : }
     475             : 
     476             : 
     477             : /*
     478             :   parse a set of bytes
     479             : */
     480   909641580 : _PUBLIC_ enum ndr_err_code ndr_pull_bytes(struct ndr_pull *ndr, uint8_t *data, uint32_t n)
     481             : {
     482   909641580 :         NDR_PULL_NEED_BYTES(ndr, n);
     483   909641580 :         memcpy(data, ndr->data + ndr->offset, n);
     484   909641580 :         ndr->offset += n;
     485   909641580 :         return NDR_ERR_SUCCESS;
     486             : }
     487             : 
     488             : /*
     489             :   pull an array of uint8
     490             : */
     491   908391166 : _PUBLIC_ enum ndr_err_code ndr_pull_array_uint8(struct ndr_pull *ndr, int ndr_flags, uint8_t *data, uint32_t n)
     492             : {
     493   908391166 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     494   908391166 :         if (!(ndr_flags & NDR_SCALARS)) {
     495           0 :                 return NDR_ERR_SUCCESS;
     496             :         }
     497   908391166 :         return ndr_pull_bytes(ndr, data, n);
     498             : }
     499             : 
     500             : /*
     501             :   push a int8_t
     502             : */
     503    64878542 : _PUBLIC_ enum ndr_err_code ndr_push_int8(struct ndr_push *ndr, int ndr_flags, int8_t v)
     504             : {
     505    64878542 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
     506    64878542 :         NDR_PUSH_NEED_BYTES(ndr, 1);
     507    64878542 :         PUSH_BE_U8(ndr->data, ndr->offset, (uint8_t)v);
     508    64878542 :         ndr->offset += 1;
     509    64878542 :         return NDR_ERR_SUCCESS;
     510             : }
     511             : 
     512             : /*
     513             :   push a uint8_t
     514             : */
     515   512386025 : _PUBLIC_ enum ndr_err_code ndr_push_uint8(struct ndr_push *ndr, int ndr_flags, uint8_t v)
     516             : {
     517   512386025 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
     518   512386025 :         NDR_PUSH_NEED_BYTES(ndr, 1);
     519   512386025 :         PUSH_BE_U8(ndr->data, ndr->offset, v);
     520   512386025 :         ndr->offset += 1;
     521   512386025 :         return NDR_ERR_SUCCESS;
     522             : }
     523             : 
     524             : /*
     525             :   push a int16_t
     526             : */
     527           0 : _PUBLIC_ enum ndr_err_code ndr_push_int16(struct ndr_push *ndr, int ndr_flags, int16_t v)
     528             : {
     529           0 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
     530           0 :         NDR_PUSH_ALIGN(ndr, 2);
     531           0 :         NDR_PUSH_NEED_BYTES(ndr, 2);
     532           0 :         NDR_PUSH_U16(ndr, ndr->offset, (uint16_t)v);
     533           0 :         ndr->offset += 2;
     534           0 :         return NDR_ERR_SUCCESS;
     535             : }
     536             : 
     537             : /*
     538             :   push a uint16_t
     539             : */
     540   502934258 : _PUBLIC_ enum ndr_err_code ndr_push_uint16(struct ndr_push *ndr, int ndr_flags, uint16_t v)
     541             : {
     542   502934258 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
     543   503212995 :         NDR_PUSH_ALIGN(ndr, 2);
     544   502934258 :         NDR_PUSH_NEED_BYTES(ndr, 2);
     545   502934258 :         NDR_PUSH_U16(ndr, ndr->offset, v);
     546   502934258 :         ndr->offset += 2;
     547   502934258 :         return NDR_ERR_SUCCESS;
     548             : }
     549             : 
     550             : /*
     551             :   push a uint1632
     552             : */
     553           0 : _PUBLIC_ enum ndr_err_code ndr_push_uint1632(struct ndr_push *ndr, int ndr_flags, uint16_t v)
     554             : {
     555           0 :         if (unlikely(ndr->flags & LIBNDR_FLAG_NDR64)) {
     556           0 :                 return ndr_push_uint32(ndr, ndr_flags, v);
     557             :         }
     558           0 :         return ndr_push_uint16(ndr, ndr_flags, v);
     559             : }
     560             : 
     561             : /*
     562             :   push a int32_t
     563             : */
     564       21145 : _PUBLIC_ enum ndr_err_code ndr_push_int32(struct ndr_push *ndr, int ndr_flags, int32_t v)
     565             : {
     566       21145 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
     567       21145 :         NDR_PUSH_ALIGN(ndr, 4);
     568       21145 :         NDR_PUSH_NEED_BYTES(ndr, 4);
     569       21145 :         NDR_PUSH_I32(ndr, ndr->offset, v);
     570       21145 :         ndr->offset += 4;
     571       21145 :         return NDR_ERR_SUCCESS;
     572             : }
     573             : 
     574             : /*
     575             :   push a uint32_t
     576             : */
     577  1214670192 : _PUBLIC_ enum ndr_err_code ndr_push_uint32(struct ndr_push *ndr, int ndr_flags, uint32_t v)
     578             : {
     579  1214670192 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
     580  1216015950 :         NDR_PUSH_ALIGN(ndr, 4);
     581  1214670192 :         NDR_PUSH_NEED_BYTES(ndr, 4);
     582  1214670192 :         NDR_PUSH_U32(ndr, ndr->offset, v);
     583  1214670192 :         ndr->offset += 4;
     584  1214670192 :         return NDR_ERR_SUCCESS;
     585             : }
     586             : 
     587             : /*
     588             :   push a uint3264
     589             : */
     590   359544368 : _PUBLIC_ enum ndr_err_code ndr_push_uint3264(struct ndr_push *ndr, int ndr_flags, uint32_t v)
     591             : {
     592   359544368 :         if (unlikely(ndr->flags & LIBNDR_FLAG_NDR64)) {
     593           0 :                 return ndr_push_hyper(ndr, ndr_flags, v);
     594             :         }
     595   359544368 :         return ndr_push_uint32(ndr, ndr_flags, v);
     596             : }
     597             : 
     598             : /*
     599             :   push a udlong
     600             : */
     601   186937499 : _PUBLIC_ enum ndr_err_code ndr_push_udlong(struct ndr_push *ndr, int ndr_flags, uint64_t v)
     602             : {
     603   186937499 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
     604   186937589 :         NDR_PUSH_ALIGN(ndr, 4);
     605   186937499 :         NDR_PUSH_NEED_BYTES(ndr, 8);
     606   186937499 :         NDR_PUSH_U32(ndr, ndr->offset, (v & 0xFFFFFFFF));
     607   186937499 :         NDR_PUSH_U32(ndr, ndr->offset+4, (v>>32));
     608   186937499 :         ndr->offset += 8;
     609   186937499 :         return NDR_ERR_SUCCESS;
     610             : }
     611             : 
     612             : /*
     613             :   push a udlongr
     614             : */
     615      104794 : _PUBLIC_ enum ndr_err_code ndr_push_udlongr(struct ndr_push *ndr, int ndr_flags, uint64_t v)
     616             : {
     617      104794 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
     618      104794 :         NDR_PUSH_ALIGN(ndr, 4);
     619      104794 :         NDR_PUSH_NEED_BYTES(ndr, 8);
     620      104794 :         NDR_PUSH_U32(ndr, ndr->offset, (v>>32));
     621      104794 :         NDR_PUSH_U32(ndr, ndr->offset+4, (v & 0xFFFFFFFF));
     622      104794 :         ndr->offset += 8;
     623      104794 :         return NDR_ERR_SUCCESS;
     624             : }
     625             : 
     626             : /*
     627             :   push a dlong
     628             : */
     629        1424 : _PUBLIC_ enum ndr_err_code ndr_push_dlong(struct ndr_push *ndr, int ndr_flags, int64_t v)
     630             : {
     631        1424 :         return ndr_push_udlong(ndr, NDR_SCALARS, (uint64_t)v);
     632             : }
     633             : 
     634             : /*
     635             :   push a hyper
     636             : */
     637   183761812 : _PUBLIC_ enum ndr_err_code ndr_push_hyper(struct ndr_push *ndr, int ndr_flags, uint64_t v)
     638             : {
     639   189119406 :         NDR_PUSH_ALIGN(ndr, 8);
     640   183761812 :         if (NDR_BE(ndr)) {
     641       93832 :                 return ndr_push_udlongr(ndr, NDR_SCALARS, v);
     642             :         }
     643   183667980 :         return ndr_push_udlong(ndr, NDR_SCALARS, v);
     644             : }
     645             : 
     646             : /*
     647             :   push a double
     648             : */
     649           0 : _PUBLIC_ enum ndr_err_code ndr_push_double(struct ndr_push *ndr, int ndr_flags, double v)
     650             : {
     651           0 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
     652           0 :         NDR_PUSH_ALIGN(ndr, 8);
     653           0 :         NDR_PUSH_NEED_BYTES(ndr, 8);
     654           0 :         memcpy(ndr->data+ndr->offset, &v, 8);
     655           0 :         ndr->offset += 8;
     656           0 :         return NDR_ERR_SUCCESS;
     657             : }
     658             : 
     659             : /*
     660             :   push a pointer
     661             : */
     662      509057 : _PUBLIC_ enum ndr_err_code ndr_push_pointer(struct ndr_push *ndr, int ndr_flags, void* v)
     663             : {
     664      509057 :         uintptr_t h = (intptr_t)v;
     665      509057 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
     666      509161 :         NDR_PUSH_ALIGN(ndr, sizeof(h));
     667      509057 :         NDR_PUSH_NEED_BYTES(ndr, sizeof(h));
     668      509057 :         memcpy(ndr->data+ndr->offset, &h, sizeof(h));
     669      509057 :         ndr->offset += sizeof(h);
     670      509057 :         return NDR_ERR_SUCCESS;
     671             : }
     672             : 
     673   703218001 : _PUBLIC_ enum ndr_err_code ndr_push_align(struct ndr_push *ndr, size_t size)
     674             : {
     675             :         /* this is a nasty hack to make pidl work with NDR64 */
     676   703218001 :         if (size == 5) {
     677   238847590 :                 if (ndr->flags & LIBNDR_FLAG_NDR64) {
     678           0 :                         size = 8;
     679             :                 } else {
     680   238847590 :                         size = 4;
     681             :                 }
     682   464370411 :         } else if (size == 3) {
     683       99053 :                 if (ndr->flags & LIBNDR_FLAG_NDR64) {
     684           0 :                         size = 4;
     685             :                 } else {
     686       99053 :                         size = 2;
     687             :                 }
     688             :         }
     689   704085161 :         NDR_PUSH_ALIGN(ndr, size);
     690   703218001 :         return NDR_ERR_SUCCESS;
     691             : }
     692             : 
     693   919731332 : _PUBLIC_ enum ndr_err_code ndr_pull_align(struct ndr_pull *ndr, size_t size)
     694             : {
     695             :         /* this is a nasty hack to make pidl work with NDR64 */
     696   919731332 :         if (size == 5) {
     697    40943746 :                 if (ndr->flags & LIBNDR_FLAG_NDR64) {
     698           0 :                         size = 8;
     699             :                 } else {
     700    40943746 :                         size = 4;
     701             :                 }
     702   878787586 :         } else if (size == 3) {
     703      223023 :                 if (ndr->flags & LIBNDR_FLAG_NDR64) {
     704           0 :                         size = 4;
     705             :                 } else {
     706      223023 :                         size = 2;
     707             :                 }
     708             :         }
     709   919731332 :         NDR_PULL_ALIGN(ndr, size);
     710   919731332 :         return NDR_ERR_SUCCESS;
     711             : }
     712             : 
     713    72815134 : _PUBLIC_ enum ndr_err_code ndr_push_union_align(struct ndr_push *ndr, size_t size)
     714             : {
     715             :         /* MS-RPCE section 2.2.5.3.4.4 */
     716    72815134 :         if (ndr->flags & LIBNDR_FLAG_NDR64) {
     717           0 :                 return ndr_push_align(ndr, size);
     718             :         }
     719    72815134 :         return NDR_ERR_SUCCESS;
     720             : }
     721             : 
     722   314655981 : _PUBLIC_ enum ndr_err_code ndr_pull_union_align(struct ndr_pull *ndr, size_t size)
     723             : {
     724             :         /* MS-RPCE section 2.2.5.3.4.4 */
     725   314655981 :         if (ndr->flags & LIBNDR_FLAG_NDR64) {
     726           0 :                 return ndr_pull_align(ndr, size);
     727             :         }
     728   314655981 :         return NDR_ERR_SUCCESS;
     729             : }
     730             : 
     731   624249483 : _PUBLIC_ enum ndr_err_code ndr_push_trailer_align(struct ndr_push *ndr, size_t size)
     732             : {
     733             :         /* MS-RPCE section 2.2.5.3.4.1 */
     734   624249483 :         if (ndr->flags & LIBNDR_FLAG_NDR64) {
     735           0 :                 return ndr_push_align(ndr, size);
     736             :         }
     737   624249483 :         return NDR_ERR_SUCCESS;
     738             : }
     739             : 
     740   619897094 : _PUBLIC_ enum ndr_err_code ndr_pull_trailer_align(struct ndr_pull *ndr, size_t size)
     741             : {
     742             :         /* MS-RPCE section 2.2.5.3.4.1 */
     743   619897094 :         if (ndr->flags & LIBNDR_FLAG_NDR64) {
     744           0 :                 return ndr_pull_align(ndr, size);
     745             :         }
     746   619897094 :         return NDR_ERR_SUCCESS;
     747             : }
     748             : 
     749             : /*
     750             :   push some bytes
     751             : */
     752   590666917 : _PUBLIC_ enum ndr_err_code ndr_push_bytes(struct ndr_push *ndr, const uint8_t *data, uint32_t n)
     753             : {
     754   590666917 :         if (unlikely(n == 0)) {
     755     3375600 :                 return NDR_ERR_SUCCESS;
     756             :         }
     757   587291317 :         if (unlikely(data == NULL)) {
     758           0 :                 return NDR_ERR_INVALID_POINTER;
     759             :         }
     760   587291317 :         NDR_PUSH_NEED_BYTES(ndr, n);
     761   587291317 :         memcpy(ndr->data + ndr->offset, data, n);
     762   587291317 :         ndr->offset += n;
     763   587291317 :         return NDR_ERR_SUCCESS;
     764             : }
     765             : 
     766             : /*
     767             :   push some zero bytes
     768             : */
     769    15655603 : _PUBLIC_ enum ndr_err_code ndr_push_zero(struct ndr_push *ndr, uint32_t n)
     770             : {
     771    15655603 :         NDR_PUSH_NEED_BYTES(ndr, n);
     772    15655603 :         memset(ndr->data + ndr->offset, 0, n);
     773    15655603 :         ndr->offset += n;
     774    15655603 :         return NDR_ERR_SUCCESS;
     775             : }
     776             : 
     777             : /*
     778             :   push an array of uint8
     779             : */
     780   493468136 : _PUBLIC_ enum ndr_err_code ndr_push_array_uint8(struct ndr_push *ndr, int ndr_flags, const uint8_t *data, uint32_t n)
     781             : {
     782   493468136 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
     783   493468136 :         if (!(ndr_flags & NDR_SCALARS)) {
     784           0 :                 return NDR_ERR_SUCCESS;
     785             :         }
     786   493468136 :         return ndr_push_bytes(ndr, data, n);
     787             : }
     788             : 
     789             : /*
     790             :   push a unique non-zero value if a pointer is non-NULL, otherwise 0
     791             : */
     792   180235024 : _PUBLIC_ enum ndr_err_code ndr_push_unique_ptr(struct ndr_push *ndr, const void *p)
     793             : {
     794   180235024 :         uint32_t ptr = 0;
     795   180235024 :         if (p) {
     796   176988548 :                 ptr = ndr->ptr_count * 4;
     797   176988548 :                 ptr |= 0x00020000;
     798   176988548 :                 ndr->ptr_count++;
     799             :         }
     800   180235024 :         return ndr_push_uint3264(ndr, NDR_SCALARS, ptr);
     801             : }
     802             : 
     803             : /*
     804             :   push a 'simple' full non-zero value if a pointer is non-NULL, otherwise 0
     805             : */
     806       58374 : _PUBLIC_ enum ndr_err_code ndr_push_full_ptr(struct ndr_push *ndr, const void *p)
     807             : {
     808       58374 :         enum ndr_err_code ret = NDR_ERR_SUCCESS;
     809       58374 :         uint32_t ptr = 0;
     810       58374 :         if (p) {
     811             :                 /* Check if the pointer already exists and has an id */
     812       58244 :                 ret = ndr_token_peek(&ndr->full_ptr_list, p, &ptr);
     813       58244 :                 if (ret == NDR_ERR_TOKEN) {
     814       58244 :                         ndr->ptr_count++;
     815       58244 :                         ptr = ndr->ptr_count;
     816       58244 :                         ret = ndr_token_store(ndr, &ndr->full_ptr_list, p, ptr);
     817       58244 :                         if (ret != NDR_ERR_SUCCESS) {
     818           0 :                                 return ret;
     819             :                         }
     820           0 :                 } else if (ret != NDR_ERR_SUCCESS) {
     821           0 :                         return ret;
     822             :                 }
     823             :         }
     824       58374 :         return ndr_push_uint3264(ndr, NDR_SCALARS, ptr);
     825             : }
     826             : 
     827             : /*
     828             :   push always a 0, if a pointer is NULL it's a fatal error
     829             : */
     830       18685 : _PUBLIC_ enum ndr_err_code ndr_push_ref_ptr(struct ndr_push *ndr)
     831             : {
     832       18685 :         return ndr_push_uint3264(ndr, NDR_SCALARS, 0xAEF1AEF1);
     833             : }
     834             : 
     835             : 
     836             : /*
     837             :   push a NTTIME
     838             : */
     839     2980344 : _PUBLIC_ enum ndr_err_code ndr_push_NTTIME(struct ndr_push *ndr, int ndr_flags, NTTIME t)
     840             : {
     841     2980344 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
     842     2980344 :         NDR_CHECK(ndr_push_udlong(ndr, ndr_flags, t));
     843     2980344 :         return NDR_ERR_SUCCESS;
     844             : }
     845             : 
     846             : /*
     847             :   pull a NTTIME
     848             : */
     849     3916395 : _PUBLIC_ enum ndr_err_code ndr_pull_NTTIME(struct ndr_pull *ndr, int ndr_flags, NTTIME *t)
     850             : {
     851     3916395 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     852     3916395 :         NDR_CHECK(ndr_pull_udlong(ndr, ndr_flags, t));
     853     3916395 :         return NDR_ERR_SUCCESS;
     854             : }
     855             : 
     856             : /*
     857             :   push a NTTIME_1sec
     858             : */
     859    82577743 : _PUBLIC_ enum ndr_err_code ndr_push_NTTIME_1sec(struct ndr_push *ndr, int ndr_flags, NTTIME t)
     860             : {
     861    82577743 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
     862    82577743 :         t /= 10000000;
     863    82577743 :         NDR_CHECK(ndr_push_hyper(ndr, ndr_flags, t));
     864    82577743 :         return NDR_ERR_SUCCESS;
     865             : }
     866             : 
     867             : /*
     868             :   pull a NTTIME_1sec
     869             : */
     870    79696910 : _PUBLIC_ enum ndr_err_code ndr_pull_NTTIME_1sec(struct ndr_pull *ndr, int ndr_flags, NTTIME *t)
     871             : {
     872    79696910 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     873    79696910 :         NDR_CHECK(ndr_pull_hyper(ndr, ndr_flags, t));
     874    79696910 :         (*t) *= 10000000;
     875    79696910 :         return NDR_ERR_SUCCESS;
     876             : }
     877             : 
     878             : /*
     879             :   pull a NTTIME_hyper
     880             : */
     881       11036 : _PUBLIC_ enum ndr_err_code ndr_pull_NTTIME_hyper(struct ndr_pull *ndr, int ndr_flags, NTTIME *t)
     882             : {
     883       11036 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     884       11036 :         NDR_CHECK(ndr_pull_hyper(ndr, ndr_flags, t));
     885       11036 :         return NDR_ERR_SUCCESS;
     886             : }
     887             : 
     888             : /*
     889             :   push a NTTIME_hyper
     890             : */
     891       12285 : _PUBLIC_ enum ndr_err_code ndr_push_NTTIME_hyper(struct ndr_push *ndr, int ndr_flags, NTTIME t)
     892             : {
     893       12285 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
     894       12285 :         NDR_CHECK(ndr_push_hyper(ndr, ndr_flags, t));
     895       12285 :         return NDR_ERR_SUCCESS;
     896             : }
     897             : 
     898             : /*
     899             :   push a time_t
     900             : */
     901       54330 : _PUBLIC_ enum ndr_err_code ndr_push_time_t(struct ndr_push *ndr, int ndr_flags, time_t t)
     902             : {
     903       54330 :         return ndr_push_uint32(ndr, ndr_flags, t);
     904             : }
     905             : 
     906             : /*
     907             :   pull a time_t
     908             : */
     909       73901 : _PUBLIC_ enum ndr_err_code ndr_pull_time_t(struct ndr_pull *ndr, int ndr_flags, time_t *t)
     910             : {
     911             :         uint32_t tt;
     912       73901 :         NDR_CHECK(ndr_pull_uint32(ndr, ndr_flags, &tt));
     913       73901 :         *t = tt;
     914       73901 :         return NDR_ERR_SUCCESS;
     915             : }
     916             : 
     917             : 
     918             : /*
     919             :   push a uid_t
     920             : */
     921       88711 : _PUBLIC_ enum ndr_err_code ndr_push_uid_t(struct ndr_push *ndr, int ndr_flags, uid_t u)
     922             : {
     923       88711 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
     924       88711 :         return ndr_push_hyper(ndr, NDR_SCALARS, (uint64_t)u);
     925             : }
     926             : 
     927             : /*
     928             :   pull a uid_t
     929             : */
     930       80496 : _PUBLIC_ enum ndr_err_code ndr_pull_uid_t(struct ndr_pull *ndr, int ndr_flags, uid_t *u)
     931             : {
     932       80496 :         uint64_t uu = 0;
     933       80496 :         NDR_CHECK(ndr_pull_hyper(ndr, ndr_flags, &uu));
     934       80496 :         *u = (uid_t)uu;
     935       80496 :         if (unlikely(uu != *u)) {
     936           0 :                 DEBUG(0,(__location__ ": uid_t pull doesn't fit 0x%016llx\n",
     937             :                          (unsigned long long)uu));
     938           0 :                 return NDR_ERR_NDR64;
     939             :         }
     940       80496 :         return NDR_ERR_SUCCESS;
     941             : }
     942             : 
     943             : 
     944             : /*
     945             :   push a gid_t
     946             : */
     947      576254 : _PUBLIC_ enum ndr_err_code ndr_push_gid_t(struct ndr_push *ndr, int ndr_flags, gid_t g)
     948             : {
     949      576254 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
     950      576254 :         return ndr_push_hyper(ndr, NDR_SCALARS, (uint64_t)g);
     951             : }
     952             : 
     953             : /*
     954             :   pull a gid_t
     955             : */
     956      531214 : _PUBLIC_ enum ndr_err_code ndr_pull_gid_t(struct ndr_pull *ndr, int ndr_flags, gid_t *g)
     957             : {
     958      531214 :         uint64_t gg = 0;
     959      531214 :         NDR_CHECK(ndr_pull_hyper(ndr, ndr_flags, &gg));
     960      531214 :         *g = (gid_t)gg;
     961      531214 :         if (unlikely(gg != *g)) {
     962           0 :                 DEBUG(0,(__location__ ": gid_t pull doesn't fit 0x%016llx\n",
     963             :                          (unsigned long long)gg));
     964           0 :                 return NDR_ERR_NDR64;
     965             :         }
     966      531214 :         return NDR_ERR_SUCCESS;
     967             : }
     968             : 
     969             : 
     970             : /*
     971             :   pull a ipv4address
     972             : */
     973       90680 : _PUBLIC_ enum ndr_err_code ndr_pull_ipv4address(struct ndr_pull *ndr, int ndr_flags, const char **address)
     974             : {
     975             :         uint32_t addr;
     976             :         struct in_addr in;
     977       90680 :         NDR_CHECK(ndr_pull_uint32(ndr, ndr_flags, &addr));
     978       90680 :         in.s_addr = htonl(addr);
     979       90680 :         *address = talloc_strdup(ndr->current_mem_ctx, inet_ntoa(in));
     980       90680 :         NDR_ERR_HAVE_NO_MEMORY(*address);
     981       90680 :         return NDR_ERR_SUCCESS;
     982             : }
     983             : 
     984             : /*
     985             :   push a ipv4address
     986             : */
     987      150312 : _PUBLIC_ enum ndr_err_code ndr_push_ipv4address(struct ndr_push *ndr, int ndr_flags, const char *address)
     988             : {
     989             :         uint32_t addr;
     990      150312 :         if (!is_ipaddress(address)) {
     991          40 :                 return ndr_push_error(ndr, NDR_ERR_IPV4ADDRESS,
     992             :                                       "Invalid IPv4 address: '%s'",
     993             :                                       address);
     994             :         }
     995      150272 :         addr = inet_addr(address);
     996      150272 :         NDR_CHECK(ndr_push_uint32(ndr, ndr_flags, htonl(addr)));
     997      150272 :         return NDR_ERR_SUCCESS;
     998             : }
     999             : 
    1000             : /*
    1001             :   print a ipv4address
    1002             : */
    1003         260 : _PUBLIC_ void ndr_print_ipv4address(struct ndr_print *ndr, const char *name,
    1004             :                            const char *address)
    1005             : {
    1006         260 :         ndr->print(ndr, "%-25s: %s", name, address);
    1007         260 : }
    1008             : 
    1009             : /*
    1010             :   pull a ipv6address
    1011             : */
    1012             : #define IPV6_BYTES 16
    1013             : #define IPV6_ADDR_STR_LEN 39
    1014       43550 : _PUBLIC_ enum ndr_err_code ndr_pull_ipv6address(struct ndr_pull *ndr, int ndr_flags, const char **address)
    1015             : {
    1016             :         uint8_t addr[IPV6_BYTES];
    1017       43550 :         char *addr_str = talloc_strdup(ndr->current_mem_ctx, "");
    1018             :         int i;
    1019       43550 :         NDR_CHECK(ndr_pull_array_uint8(ndr, ndr_flags, addr, IPV6_BYTES));
    1020      740350 :         for (i = 0; i < IPV6_BYTES; ++i) {
    1021      696800 :                 addr_str = talloc_asprintf_append(addr_str, "%02x", addr[i]);
    1022             :                 /* We need a ':' every second byte but the last one */
    1023      696800 :                 if (i%2 == 1 && i != (IPV6_BYTES - 1)) {
    1024      304850 :                         addr_str = talloc_strdup_append(addr_str, ":");
    1025             :                 }
    1026             :         }
    1027       43550 :         *address = addr_str;
    1028       43550 :         NDR_ERR_HAVE_NO_MEMORY(*address);
    1029       43550 :         return NDR_ERR_SUCCESS;
    1030             : }
    1031             : 
    1032             : /*
    1033             :   push a ipv6address
    1034             : */
    1035       53417 : _PUBLIC_ enum ndr_err_code ndr_push_ipv6address(struct ndr_push *ndr, int ndr_flags, const char *address)
    1036             : {
    1037             : #ifdef AF_INET6
    1038             :         uint8_t addr[IPV6_BYTES];
    1039             :         int ret;
    1040             : 
    1041       53417 :         if (!is_ipaddress(address)) {
    1042         120 :                 return ndr_push_error(ndr, NDR_ERR_IPV6ADDRESS,
    1043             :                                       "Invalid IPv6 address: '%s'",
    1044             :                                       address);
    1045             :         }
    1046       53297 :         ret = inet_pton(AF_INET6, address, addr);
    1047       53297 :         if (ret <= 0) {
    1048           0 :                 return NDR_ERR_IPV6ADDRESS;
    1049             :         }
    1050             : 
    1051       53297 :         NDR_CHECK(ndr_push_array_uint8(ndr, ndr_flags, addr, IPV6_BYTES));
    1052             : 
    1053       53297 :         return NDR_ERR_SUCCESS;
    1054             : #else
    1055             :         return NDR_ERR_IPV6ADDRESS;
    1056             : #endif
    1057             : }
    1058             : 
    1059             : /*
    1060             :   print a ipv6address
    1061             : */
    1062          13 : _PUBLIC_ void ndr_print_ipv6address(struct ndr_print *ndr, const char *name,
    1063             :                            const char *address)
    1064             : {
    1065          13 :         ndr->print(ndr, "%-25s: %s", name, address);
    1066          13 : }
    1067             : #undef IPV6_BYTES
    1068             : 
    1069     1198255 : _PUBLIC_ void ndr_print_struct(struct ndr_print *ndr, const char *name, const char *type)
    1070             : {
    1071     1198255 :         ndr->print(ndr, "%s: struct %s", name, type);
    1072     1198255 : }
    1073             : 
    1074           0 : _PUBLIC_ void ndr_print_null(struct ndr_print *ndr)
    1075             : {
    1076           0 :         ndr->print(ndr, "UNEXPECTED NULL POINTER");
    1077           0 : }
    1078             : 
    1079      250519 : _PUBLIC_ void ndr_print_enum(struct ndr_print *ndr, const char *name, const char *type,
    1080             :                     const char *val, uint32_t value)
    1081             : {
    1082      250519 :         if (ndr->flags & LIBNDR_PRINT_ARRAY_HEX) {
    1083      228924 :                 ndr->print(ndr, "%-25s: %s (0x%X)", name, val?val:"UNKNOWN_ENUM_VALUE", value);
    1084             :         } else {
    1085       21595 :                 ndr->print(ndr, "%-25s: %s (%d)", name, val?val:"UNKNOWN_ENUM_VALUE", value);
    1086             :         }
    1087      250519 : }
    1088             : 
    1089      278866 : _PUBLIC_ void ndr_print_bitmap_flag(struct ndr_print *ndr, size_t size, const char *flag_name, uint32_t flag, uint32_t value)
    1090             : {
    1091      278866 :         if (flag == 0) {
    1092           0 :                 return;
    1093             :         }
    1094             : 
    1095             :         /* this is an attempt to support multi-bit bitmap masks */
    1096      278866 :         value &= flag;
    1097             : 
    1098     2898774 :         while (!(flag & 1)) {
    1099     2341869 :                 flag >>= 1;
    1100     2341869 :                 value >>= 1;
    1101             :         }
    1102      278866 :         if (flag == 1) {
    1103      266772 :                 ndr->print(ndr, "   %d: %-25s", value, flag_name);
    1104             :         } else {
    1105       12094 :                 ndr->print(ndr, "0x%02x: %-25s (%d)", value, flag_name, value);
    1106             :         }
    1107             : }
    1108             : 
    1109           0 : _PUBLIC_ void ndr_print_int8(struct ndr_print *ndr, const char *name, int8_t v)
    1110             : {
    1111           0 :         if (NDR_HIDE_SECRET(ndr)) {
    1112           0 :                 ndr->print(ndr, "%-25s: <REDACTED SECRET VALUE>", name);
    1113           0 :                 return;
    1114             :         }
    1115           0 :         ndr->print(ndr, "%-25s: %d", name, v);
    1116             : }
    1117             : 
    1118      440383 : _PUBLIC_ void ndr_print_uint8(struct ndr_print *ndr, const char *name, uint8_t v)
    1119             : {
    1120      440383 :         if (NDR_HIDE_SECRET(ndr)) {
    1121           0 :                 ndr->print(ndr, "%-25s: <REDACTED SECRET VALUE>", name);
    1122           0 :                 return;
    1123             :         }
    1124      440383 :         ndr->print(ndr, "%-25s: 0x%02x (%u)", name, v, v);
    1125             : }
    1126             : 
    1127           0 : _PUBLIC_ void ndr_print_int16(struct ndr_print *ndr, const char *name, int16_t v)
    1128             : {
    1129           0 :         if (NDR_HIDE_SECRET(ndr)) {
    1130           0 :                 ndr->print(ndr, "%-25s: <REDACTED SECRET VALUE>", name);
    1131           0 :                 return;
    1132             :         }
    1133           0 :         ndr->print(ndr, "%-25s: %d", name, v);
    1134             : }
    1135             : 
    1136       69830 : _PUBLIC_ void ndr_print_uint16(struct ndr_print *ndr, const char *name, uint16_t v)
    1137             : {
    1138       69830 :         if (NDR_HIDE_SECRET(ndr)) {
    1139           0 :                 ndr->print(ndr, "%-25s: <REDACTED SECRET VALUE>", name);
    1140           0 :                 return;
    1141             :         }
    1142       69830 :         ndr->print(ndr, "%-25s: 0x%04x (%u)", name, v, v);
    1143             : }
    1144             : 
    1145           2 : _PUBLIC_ void ndr_print_int32(struct ndr_print *ndr, const char *name, int32_t v)
    1146             : {
    1147           2 :         if (NDR_HIDE_SECRET(ndr)) {
    1148           0 :                 ndr->print(ndr, "%-25s: <REDACTED SECRET VALUE>", name);
    1149           0 :                 return;
    1150             :         }
    1151           2 :         ndr->print(ndr, "%-25s: %d", name, v);
    1152             : }
    1153             : 
    1154      906518 : _PUBLIC_ void ndr_print_uint32(struct ndr_print *ndr, const char *name, uint32_t v)
    1155             : {
    1156      906518 :         if (NDR_HIDE_SECRET(ndr)) {
    1157           0 :                 ndr->print(ndr, "%-25s: <REDACTED SECRET VALUE>", name);
    1158           0 :                 return;
    1159             :         }
    1160      906518 :         ndr->print(ndr, "%-25s: 0x%08x (%u)", name, v, v);
    1161             : }
    1162             : 
    1163           0 : _PUBLIC_ void ndr_print_int3264(struct ndr_print *ndr, const char *name, int32_t v)
    1164             : {
    1165           0 :         if (NDR_HIDE_SECRET(ndr)) {
    1166           0 :                 ndr->print(ndr, "%-25s: <REDACTED SECRET VALUE>", name);
    1167           0 :                 return;
    1168             :         }
    1169           0 :         ndr->print(ndr, "%-25s: %d", name, v);
    1170             : }
    1171             : 
    1172         330 : _PUBLIC_ void ndr_print_uint3264(struct ndr_print *ndr, const char *name, uint32_t v)
    1173             : {
    1174         330 :         if (NDR_HIDE_SECRET(ndr)) {
    1175           0 :                 ndr->print(ndr, "%-25s: <REDACTED SECRET VALUE>", name);
    1176           0 :                 return;
    1177             :         }
    1178         330 :         ndr->print(ndr, "%-25s: 0x%08x (%u)", name, v, v);
    1179             : }
    1180             : 
    1181           2 : _PUBLIC_ void ndr_print_udlong(struct ndr_print *ndr, const char *name, uint64_t v)
    1182             : {
    1183           2 :         ndr->print(ndr, "%-25s: 0x%016llx (%llu)", name, (unsigned long long)v, (unsigned long long)v);
    1184           2 : }
    1185             : 
    1186           0 : _PUBLIC_ void ndr_print_udlongr(struct ndr_print *ndr, const char *name, uint64_t v)
    1187             : {
    1188           0 :         ndr_print_udlong(ndr, name, v);
    1189           0 : }
    1190             : 
    1191      236108 : _PUBLIC_ void ndr_print_dlong(struct ndr_print *ndr, const char *name, int64_t v)
    1192             : {
    1193      236108 :         if (NDR_HIDE_SECRET(ndr)) {
    1194           0 :                 ndr->print(ndr, "%-25s: <REDACTED SECRET VALUE>", name);
    1195           0 :                 return;
    1196             :         }
    1197      236108 :         ndr->print(ndr, "%-25s: 0x%016llx (%lld)", name, (unsigned long long)v, (long long)v);
    1198             : }
    1199             : 
    1200           0 : _PUBLIC_ void ndr_print_double(struct ndr_print *ndr, const char *name, double v)
    1201             : {
    1202           0 :         ndr->print(ndr, "%-25s: %f", name, v);
    1203           0 : }
    1204             : 
    1205      236104 : _PUBLIC_ void ndr_print_hyper(struct ndr_print *ndr, const char *name, uint64_t v)
    1206             : {
    1207      236104 :         ndr_print_dlong(ndr, name, v);
    1208      236104 : }
    1209             : 
    1210           0 : _PUBLIC_ void ndr_print_pointer(struct ndr_print *ndr, const char *name, void *v)
    1211             : {
    1212           0 :         ndr->print(ndr, "%-25s: %p", name, v);
    1213           0 : }
    1214             : 
    1215      591280 : _PUBLIC_ void ndr_print_ptr(struct ndr_print *ndr, const char *name, const void *p)
    1216             : {
    1217      591280 :         if (p) {
    1218      575929 :                 ndr->print(ndr, "%-25s: *", name);
    1219             :         } else {
    1220       15351 :                 ndr->print(ndr, "%-25s: NULL", name);
    1221             :         }
    1222      591280 : }
    1223             : 
    1224      244909 : _PUBLIC_ void ndr_print_NTTIME(struct ndr_print *ndr, const char *name, NTTIME t)
    1225             : {
    1226      244909 :         ndr->print(ndr, "%-25s: %s", name, nt_time_string(ndr, t));
    1227      244909 : }
    1228             : 
    1229      228692 : _PUBLIC_ void ndr_print_NTTIME_1sec(struct ndr_print *ndr, const char *name, NTTIME t)
    1230             : {
    1231             :         /* this is a standard NTTIME here
    1232             :          * as it's already converted in the pull/push code
    1233             :          */
    1234      228692 :         ndr_print_NTTIME(ndr, name, t);
    1235      228692 : }
    1236             : 
    1237          60 : _PUBLIC_ void ndr_print_NTTIME_hyper(struct ndr_print *ndr, const char *name, NTTIME t)
    1238             : {
    1239          60 :         ndr_print_NTTIME(ndr, name, t);
    1240          60 : }
    1241             : 
    1242        1766 : _PUBLIC_ void ndr_print_time_t(struct ndr_print *ndr, const char *name, time_t t)
    1243             : {
    1244        1766 :         if (t == (time_t)-1 || t == 0) {
    1245        1766 :                 ndr->print(ndr, "%-25s: (time_t)%d", name, (int)t);
    1246             :         } else {
    1247           0 :                 ndr->print(ndr, "%-25s: %s", name, timestring(ndr, t));
    1248             :         }
    1249        1766 : }
    1250             : 
    1251           0 : _PUBLIC_ void ndr_print_uid_t(struct ndr_print *ndr, const char *name, uid_t u)
    1252             : {
    1253           0 :         ndr_print_dlong(ndr, name, u);
    1254           0 : }
    1255             : 
    1256           0 : _PUBLIC_ void ndr_print_gid_t(struct ndr_print *ndr, const char *name, gid_t g)
    1257             : {
    1258           0 :         ndr_print_dlong(ndr, name, g);
    1259           0 : }
    1260             : 
    1261       11996 : _PUBLIC_ void ndr_print_union(struct ndr_print *ndr, const char *name, int level, const char *type)
    1262             : {
    1263       11996 :         if (ndr->flags & LIBNDR_PRINT_ARRAY_HEX) {
    1264           0 :                 ndr->print(ndr, "%-25s: union %s(case 0x%X)", name, type, level);
    1265             :         } else {
    1266       11996 :                 ndr->print(ndr, "%-25s: union %s(case %d)", name, type, level);
    1267             :         }
    1268       11996 : }
    1269             : 
    1270           0 : _PUBLIC_ void ndr_print_bad_level(struct ndr_print *ndr, const char *name, uint16_t level)
    1271             : {
    1272           0 :         ndr->print(ndr, "UNKNOWN LEVEL %u", level);
    1273           0 : }
    1274             : 
    1275       11365 : _PUBLIC_ void ndr_print_array_uint8(struct ndr_print *ndr, const char *name,
    1276             :                            const uint8_t *data, uint32_t count)
    1277             : {
    1278             :         int i;
    1279             : #define _ONELINE_LIMIT 32
    1280             : 
    1281       11365 :         if (data == NULL) {
    1282           0 :                 ndr->print(ndr, "%s: ARRAY(%d) : NULL", name, count);
    1283           0 :                 return;
    1284             :         }
    1285             : 
    1286       11365 :         if (NDR_HIDE_SECRET(ndr)) {
    1287        3897 :                 ndr->print(ndr, "%s: ARRAY(%d): <REDACTED SECRET VALUES>", name, count);
    1288        3897 :                 return;
    1289             :         }
    1290             : 
    1291        7468 :         if (count <= _ONELINE_LIMIT && (ndr->flags & LIBNDR_PRINT_ARRAY_HEX)) {
    1292             :                 char s[(_ONELINE_LIMIT + 1) * 2];
    1293       67010 :                 for (i=0;i<count;i++) {
    1294       59826 :                         snprintf(&s[i*2], 3, "%02x", data[i]);
    1295             :                 }
    1296        7184 :                 s[i*2] = 0;
    1297        7184 :                 ndr->print(ndr, "%-25s: %s", name, s);
    1298        7184 :                 return;
    1299             :         }
    1300             : 
    1301         284 :         ndr->print(ndr, "%s: ARRAY(%d)", name, count);
    1302         284 :         if (count > _ONELINE_LIMIT && (ndr->flags & LIBNDR_PRINT_ARRAY_HEX)) {
    1303           0 :                 ndr_dump_data(ndr, data, count);
    1304           0 :                 return;
    1305             :         }
    1306             : 
    1307         284 :         ndr->depth++;
    1308      436210 :         for (i=0;i<count;i++) {
    1309      435926 :                 char *idx=NULL;
    1310      435926 :                 if (asprintf(&idx, "[%d]", i) != -1) {
    1311      435926 :                         ndr_print_uint8(ndr, idx, data[i]);
    1312      435926 :                         free(idx);
    1313             :                 }
    1314             :         }
    1315         284 :         ndr->depth--;
    1316             : #undef _ONELINE_LIMIT
    1317             : }
    1318             : 
    1319    31853276 : static void ndr_print_dump_data_cb(const char *buf, void *private_data)
    1320             : {
    1321    31853276 :         struct ndr_print *ndr = (struct ndr_print *)private_data;
    1322             : 
    1323    31853276 :         ndr->print(ndr, "%s", buf);
    1324    31853276 : }
    1325             : 
    1326             : /*
    1327             :   ndr_print version of dump_data()
    1328             :  */
    1329      199844 : static void ndr_dump_data(struct ndr_print *ndr, const uint8_t *buf, int len)
    1330             : {
    1331      199844 :         if (NDR_HIDE_SECRET(ndr)) {
    1332           2 :                 return;
    1333             :         }
    1334      199842 :         ndr->no_newline = true;
    1335      199842 :         dump_data_cb(buf, len, true, ndr_print_dump_data_cb, ndr);
    1336      199842 :         ndr->no_newline = false;
    1337             : }
    1338             : 
    1339             : 
    1340      201400 : _PUBLIC_ void ndr_print_DATA_BLOB(struct ndr_print *ndr, const char *name, DATA_BLOB r)
    1341             : {
    1342      201400 :         ndr->print(ndr, "%-25s: DATA_BLOB length=%u", name, (unsigned)r.length);
    1343      201400 :         if (r.length) {
    1344      199844 :                 ndr_dump_data(ndr, r.data, r.length);
    1345             :         }
    1346      201400 : }
    1347             : 
    1348             : 
    1349             : /*
    1350             :  * Push a DATA_BLOB onto the wire.
    1351             :  * 1) When called with LIBNDR_FLAG_ALIGN* alignment flags set, push padding
    1352             :  *    bytes _only_. The length is determined by the alignment required and the
    1353             :  *    current ndr offset.
    1354             :  * 2) When called with the LIBNDR_FLAG_REMAINING flag, push the byte array to
    1355             :  *    the ndr buffer.
    1356             :  * 3) Otherwise, push a uint3264 length _and_ a corresponding byte array to the
    1357             :  *    ndr buffer.
    1358             :  */
    1359    91912362 : _PUBLIC_ enum ndr_err_code ndr_push_DATA_BLOB(struct ndr_push *ndr, int ndr_flags, DATA_BLOB blob)
    1360             : {
    1361    91912362 :         if (ndr->flags & LIBNDR_FLAG_REMAINING) {
    1362             :                 /* nothing to do */
    1363    85231767 :         } else if (ndr->flags & (LIBNDR_ALIGN_FLAGS & ~LIBNDR_FLAG_NOALIGN)) {
    1364      224637 :                 if (ndr->flags & LIBNDR_FLAG_ALIGN2) {
    1365           6 :                         blob.length = NDR_ALIGN(ndr, 2);
    1366      224631 :                 } else if (ndr->flags & LIBNDR_FLAG_ALIGN4) {
    1367      194625 :                         blob.length = NDR_ALIGN(ndr, 4);
    1368       30006 :                 } else if (ndr->flags & LIBNDR_FLAG_ALIGN8) {
    1369       30006 :                         blob.length = NDR_ALIGN(ndr, 8);
    1370             :                 }
    1371      224637 :                 NDR_PUSH_ALLOC_SIZE(ndr, blob.data, blob.length);
    1372      224637 :                 data_blob_clear(&blob);
    1373             :         } else {
    1374    85007130 :                 NDR_CHECK(ndr_push_uint3264(ndr, NDR_SCALARS, blob.length));
    1375             :         }
    1376    91912362 :         NDR_CHECK(ndr_push_bytes(ndr, blob.data, blob.length));
    1377    91912362 :         return NDR_ERR_SUCCESS;
    1378             : }
    1379             : 
    1380             : /*
    1381             :  * Pull a DATA_BLOB from the wire.
    1382             :  * 1) when called with LIBNDR_FLAG_ALIGN* alignment flags set, pull padding
    1383             :  *    bytes _only_. The length is determined by the alignment required and the
    1384             :  *    current ndr offset.
    1385             :  * 2) When called with the LIBNDR_FLAG_REMAINING flag, pull all remaining bytes
    1386             :  *    from the ndr buffer.
    1387             :  * 3) Otherwise, pull a uint3264 length _and_ a corresponding byte array from the
    1388             :  *    ndr buffer.
    1389             :  */
    1390    17930291 : _PUBLIC_ enum ndr_err_code ndr_pull_DATA_BLOB(struct ndr_pull *ndr, int ndr_flags, DATA_BLOB *blob)
    1391             : {
    1392    17930291 :         uint32_t length = 0;
    1393             : 
    1394    17930291 :         if (ndr->flags & LIBNDR_FLAG_REMAINING) {
    1395     6886838 :                 length = ndr->data_size - ndr->offset;
    1396    11043453 :         } else if (ndr->flags & (LIBNDR_ALIGN_FLAGS & ~LIBNDR_FLAG_NOALIGN)) {
    1397      178253 :                 if (ndr->flags & LIBNDR_FLAG_ALIGN2) {
    1398           6 :                         length = NDR_ALIGN(ndr, 2);
    1399      178247 :                 } else if (ndr->flags & LIBNDR_FLAG_ALIGN4) {
    1400      153324 :                         length = NDR_ALIGN(ndr, 4);
    1401       24923 :                 } else if (ndr->flags & LIBNDR_FLAG_ALIGN8) {
    1402       24923 :                         length = NDR_ALIGN(ndr, 8);
    1403             :                 }
    1404      178253 :                 if (ndr->data_size - ndr->offset < length) {
    1405           0 :                         length = ndr->data_size - ndr->offset;
    1406             :                 }
    1407             :         } else {
    1408    10865200 :                 NDR_CHECK(ndr_pull_uint3264(ndr, NDR_SCALARS, &length));
    1409             :         }
    1410    17930291 :         NDR_PULL_NEED_BYTES(ndr, length);
    1411    17930291 :         *blob = data_blob_talloc(ndr->current_mem_ctx, ndr->data+ndr->offset, length);
    1412    17930291 :         ndr->offset += length;
    1413    17930291 :         return NDR_ERR_SUCCESS;
    1414             : }
    1415             : 
    1416    84467293 : _PUBLIC_ uint32_t ndr_size_DATA_BLOB(int ret, const DATA_BLOB *data, int flags)
    1417             : {
    1418    84467293 :         if (!data) return ret;
    1419    84467293 :         return ret + data->length;
    1420             : }
    1421             : 
    1422           0 : _PUBLIC_ void ndr_print_bool(struct ndr_print *ndr, const char *name, const bool b)
    1423             : {
    1424           0 :         ndr->print(ndr, "%-25s: %s", name, b?"true":"false");
    1425           0 : }
    1426             : 
    1427   233874462 : _PUBLIC_ NTSTATUS ndr_map_error2ntstatus(enum ndr_err_code ndr_err)
    1428             : {
    1429   233874462 :         switch (ndr_err) {
    1430   233874418 :         case NDR_ERR_SUCCESS:
    1431   233874419 :                 return NT_STATUS_OK;
    1432           2 :         case NDR_ERR_BUFSIZE:
    1433           2 :                 return NT_STATUS_BUFFER_TOO_SMALL;
    1434           0 :         case NDR_ERR_TOKEN:
    1435           0 :                 return NT_STATUS_INTERNAL_ERROR;
    1436           0 :         case NDR_ERR_ALLOC:
    1437           0 :                 return NT_STATUS_NO_MEMORY;
    1438           0 :         case NDR_ERR_ARRAY_SIZE:
    1439           0 :                 return NT_STATUS_ARRAY_BOUNDS_EXCEEDED;
    1440           2 :         case NDR_ERR_INVALID_POINTER:
    1441           2 :                 return NT_STATUS_INVALID_PARAMETER_MIX;
    1442           0 :         case NDR_ERR_UNREAD_BYTES:
    1443           0 :                 return NT_STATUS_PORT_MESSAGE_TOO_LONG;
    1444          40 :         default:
    1445          40 :                 break;
    1446             :         }
    1447             : 
    1448             :         /* we should map all error codes to different status codes */
    1449          40 :         return NT_STATUS_INVALID_PARAMETER;
    1450             : }
    1451             : 
    1452           0 : _PUBLIC_ int ndr_map_error2errno(enum ndr_err_code ndr_err)
    1453             : {
    1454           0 :         switch (ndr_err) {
    1455           0 :         case NDR_ERR_SUCCESS:
    1456           0 :                 return 0;
    1457           0 :         case NDR_ERR_BUFSIZE:
    1458           0 :                 return ENOSPC;
    1459           0 :         case NDR_ERR_TOKEN:
    1460           0 :                 return EINVAL;
    1461           0 :         case NDR_ERR_ALLOC:
    1462           0 :                 return ENOMEM;
    1463           0 :         case NDR_ERR_ARRAY_SIZE:
    1464           0 :                 return EMSGSIZE;
    1465           0 :         case NDR_ERR_INVALID_POINTER:
    1466           0 :                 return EINVAL;
    1467           0 :         case NDR_ERR_UNREAD_BYTES:
    1468           0 :                 return EOVERFLOW;
    1469           0 :         default:
    1470           0 :                 break;
    1471             :         }
    1472             : 
    1473             :         /* we should map all error codes to different status codes */
    1474           0 :         return EINVAL;
    1475             : }
    1476             : 
    1477           0 : _PUBLIC_ enum ndr_err_code ndr_push_timespec(struct ndr_push *ndr,
    1478             :                                              int ndr_flags,
    1479             :                                              const struct timespec *t)
    1480             : {
    1481           0 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
    1482           0 :         NDR_CHECK(ndr_push_hyper(ndr, ndr_flags, t->tv_sec));
    1483           0 :         NDR_CHECK(ndr_push_uint32(ndr, ndr_flags, t->tv_nsec));
    1484           0 :         return NDR_ERR_SUCCESS;
    1485             : }
    1486             : 
    1487           0 : _PUBLIC_ enum ndr_err_code ndr_pull_timespec(struct ndr_pull *ndr,
    1488             :                                              int ndr_flags,
    1489             :                                              struct timespec *t)
    1490             : {
    1491           0 :         uint64_t secs = 0;
    1492           0 :         uint32_t nsecs = 0;
    1493           0 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
    1494           0 :         NDR_CHECK(ndr_pull_hyper(ndr, ndr_flags, &secs));
    1495           0 :         NDR_CHECK(ndr_pull_uint32(ndr, ndr_flags, &nsecs));
    1496           0 :         t->tv_sec = secs;
    1497           0 :         t->tv_nsec = nsecs;
    1498           0 :         return NDR_ERR_SUCCESS;
    1499             : }
    1500             : 
    1501           0 : _PUBLIC_ void ndr_print_timespec(struct ndr_print *ndr, const char *name,
    1502             :                                  const struct timespec *t)
    1503             : {
    1504           0 :         char *str = timestring(ndr, t->tv_sec);
    1505           0 :         ndr->print(ndr, "%-25s: %s.%ld", name, str, t->tv_nsec);
    1506           0 :         TALLOC_FREE(str);
    1507           0 : }
    1508             : 
    1509       25312 : _PUBLIC_ enum ndr_err_code ndr_push_timeval(struct ndr_push *ndr,
    1510             :                                             int ndr_flags,
    1511             :                                             const struct timeval *t)
    1512             : {
    1513       25312 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
    1514       25312 :         NDR_CHECK(ndr_push_hyper(ndr, ndr_flags, t->tv_sec));
    1515       25312 :         NDR_CHECK(ndr_push_uint32(ndr, ndr_flags, t->tv_usec));
    1516       25312 :         return NDR_ERR_SUCCESS;
    1517             : }
    1518             : 
    1519       44618 : _PUBLIC_ enum ndr_err_code ndr_pull_timeval(struct ndr_pull *ndr,
    1520             :                                             int ndr_flags,
    1521             :                                             struct timeval *t)
    1522             : {
    1523       44618 :         uint64_t secs = 0;
    1524       44618 :         uint32_t usecs = 0;
    1525       44618 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
    1526       44618 :         NDR_CHECK(ndr_pull_hyper(ndr, ndr_flags, &secs));
    1527       44618 :         NDR_CHECK(ndr_pull_uint32(ndr, ndr_flags, &usecs));
    1528       44618 :         t->tv_sec = secs;
    1529       44618 :         t->tv_usec = usecs;
    1530       44618 :         return NDR_ERR_SUCCESS;
    1531             : }
    1532             : 
    1533           0 : _PUBLIC_ void ndr_print_timeval(struct ndr_print *ndr, const char *name,
    1534             :                                 const struct timeval *t)
    1535             : {
    1536           0 :         ndr->print(ndr, "%-25s: %s.%ld", name, timestring(ndr, t->tv_sec),
    1537           0 :                    (long)t->tv_usec);
    1538           0 : }

Generated by: LCOV version 1.13