LCOV - code coverage report
Current view: top level - librpc/ndr - ndr_basic.c (source / functions) Hit Total Coverage
Test: coverage report for master 2b515b7d Lines: 589 758 77.7 %
Date: 2024-02-28 12:06:22 Functions: 106 128 82.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_PULL_I64(ndr, ofs) \
      40             :         (NDR_BE(ndr) ? PULL_BE_I64((ndr)->data, ofs) : PULL_LE_I64((ndr)->data, ofs))
      41             : 
      42             : #define NDR_PUSH_U16(ndr, ofs, v) \
      43             :         do { \
      44             :                 if (NDR_BE(ndr)) { \
      45             :                         PUSH_BE_U16(ndr->data, ofs, v); \
      46             :                 } else { \
      47             :                         PUSH_LE_U16(ndr->data, ofs, v); \
      48             :                 } \
      49             :         } while (0)
      50             : 
      51             : #define NDR_PUSH_U32(ndr, ofs, v) \
      52             :         do { \
      53             :                 if (NDR_BE(ndr)) { \
      54             :                         PUSH_BE_U32(ndr->data, ofs, v); \
      55             :                 } else { \
      56             :                         PUSH_LE_U32(ndr->data, ofs, v); \
      57             :                 } \
      58             :         } while (0)
      59             : 
      60             : #define NDR_PUSH_I32(ndr, ofs, v) \
      61             :         do { \
      62             :                 if (NDR_BE(ndr)) { \
      63             :                         PUSH_BE_U32(ndr->data, ofs, v); \
      64             :                 } else { \
      65             :                         PUSH_LE_U32(ndr->data, ofs, v); \
      66             :                 } \
      67             :         } while (0)
      68             : 
      69             : #define NDR_PUSH_I64(ndr, ofs, v) \
      70             :         do { \
      71             :                 if (NDR_BE(ndr)) { \
      72             :                         PUSH_BE_I64((ndr)->data, ofs, v);    \
      73             :                 } else { \
      74             :                         PUSH_LE_I64((ndr)->data, ofs, v);    \
      75             :                 } \
      76             :         } while (0)
      77             : 
      78             : static void ndr_dump_data(struct ndr_print *ndr, const uint8_t *buf, int len);
      79             : 
      80             : /*
      81             :   check for data leaks from the server by looking for non-zero pad bytes
      82             :   these could also indicate that real structure elements have been
      83             :   mistaken for padding in the IDL
      84             : */
      85           0 : _PUBLIC_ void ndr_check_padding(struct ndr_pull *ndr, size_t n)
      86             : {
      87           0 :         size_t ofs2 = (ndr->offset + (n-1)) & ~(n-1);
      88           0 :         size_t i;
      89           0 :         for (i=ndr->offset;i<ofs2;i++) {
      90           0 :                 if (ndr->data[i] != 0) {
      91           0 :                         break;
      92             :                 }
      93             :         }
      94           0 :         if (i<ofs2) {
      95           0 :                 DEBUG(0,("WARNING: Non-zero padding to %zu: ", n));
      96           0 :                 for (i=ndr->offset;i<ofs2;i++) {
      97           0 :                         DEBUG(0,("%02x ", ndr->data[i]));
      98             :                 }
      99           0 :                 DEBUG(0,("\n"));
     100             :         }
     101             : 
     102           0 : }
     103             : 
     104             : /*
     105             :   parse a int8_t
     106             : */
     107   356146786 : _PUBLIC_ enum ndr_err_code ndr_pull_int8(struct ndr_pull *ndr, ndr_flags_type ndr_flags, int8_t *v)
     108             : {
     109   356146786 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     110   356146786 :         NDR_PULL_NEED_BYTES(ndr, 1);
     111   356146736 :         *v = (int8_t)PULL_BE_U8(ndr->data, ndr->offset);
     112   356146736 :         ndr->offset += 1;
     113   356146736 :         return NDR_ERR_SUCCESS;
     114             : }
     115             : 
     116             : /*
     117             :   parse a uint8_t
     118             : */
     119   809498066 : _PUBLIC_ enum ndr_err_code ndr_pull_uint8(struct ndr_pull *ndr, ndr_flags_type ndr_flags, uint8_t *v)
     120             : {
     121   809498066 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     122   809498066 :         NDR_PULL_NEED_BYTES(ndr, 1);
     123   809497681 :         *v = PULL_BE_U8(ndr->data, ndr->offset);
     124   809497681 :         ndr->offset += 1;
     125   809497681 :         return NDR_ERR_SUCCESS;
     126             : }
     127             : 
     128             : /*
     129             :   parse a int16_t
     130             : */
     131           0 : _PUBLIC_ enum ndr_err_code ndr_pull_int16(struct ndr_pull *ndr, ndr_flags_type ndr_flags, int16_t *v)
     132             : {
     133           0 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     134           0 :         NDR_PULL_ALIGN(ndr, 2);
     135           0 :         NDR_PULL_NEED_BYTES(ndr, 2);
     136           0 :         *v = (uint16_t)NDR_PULL_U16(ndr, ndr->offset);
     137           0 :         ndr->offset += 2;
     138           0 :         return NDR_ERR_SUCCESS;
     139             : }
     140             : 
     141             : /*
     142             :   parse a uint16_t
     143             : */
     144  1476952472 : _PUBLIC_ enum ndr_err_code ndr_pull_uint16(struct ndr_pull *ndr, ndr_flags_type ndr_flags, uint16_t *v)
     145             : {
     146  1476952472 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     147  1476952472 :         NDR_PULL_ALIGN(ndr, 2);
     148  1476952472 :         NDR_PULL_NEED_BYTES(ndr, 2);
     149  1476952467 :         *v = NDR_PULL_U16(ndr, ndr->offset);
     150  1476952467 :         ndr->offset += 2;
     151  1476952467 :         return NDR_ERR_SUCCESS;
     152             : }
     153             : 
     154             : /*
     155             :   parse a uint1632_t
     156             : */
     157       51814 : _PUBLIC_ enum ndr_err_code ndr_pull_uint1632(struct ndr_pull *ndr, ndr_flags_type ndr_flags, uint16_t *v)
     158             : {
     159       51814 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     160       51814 :         if (unlikely(ndr->flags & LIBNDR_FLAG_NDR64)) {
     161           8 :                 uint32_t v32 = 0;
     162           8 :                 enum ndr_err_code err = ndr_pull_uint32(ndr, ndr_flags, &v32);
     163           8 :                 *v = v32;
     164           8 :                 if (unlikely(v32 != *v)) {
     165           0 :                         DEBUG(0,(__location__ ": non-zero upper 16 bits 0x%08"PRIx32"\n", v32));
     166           0 :                         return NDR_ERR_NDR64;
     167             :                 }
     168           0 :                 return err;
     169             :         }
     170       51806 :         return ndr_pull_uint16(ndr, ndr_flags, v);
     171             : }
     172             : 
     173             : /*
     174             :   parse a int32_t
     175             : */
     176     3274369 : _PUBLIC_ enum ndr_err_code ndr_pull_int32(struct ndr_pull *ndr, ndr_flags_type ndr_flags, int32_t *v)
     177             : {
     178     3274369 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     179     3274369 :         NDR_PULL_ALIGN(ndr, 4);
     180     3274369 :         NDR_PULL_NEED_BYTES(ndr, 4);
     181     3274369 :         *v = NDR_PULL_I32(ndr, ndr->offset);
     182     3274369 :         ndr->offset += 4;
     183     3274369 :         return NDR_ERR_SUCCESS;
     184             : }
     185             : 
     186             : /*
     187             :   parse a uint32_t
     188             : */
     189  3093494860 : _PUBLIC_ enum ndr_err_code ndr_pull_uint32(struct ndr_pull *ndr, ndr_flags_type ndr_flags, uint32_t *v)
     190             : {
     191  3093494860 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     192  3093494860 :         NDR_PULL_ALIGN(ndr, 4);
     193  3093494860 :         NDR_PULL_NEED_BYTES(ndr, 4);
     194  3093494788 :         *v = NDR_PULL_U32(ndr, ndr->offset);
     195  3093494788 :         ndr->offset += 4;
     196  3093494788 :         return NDR_ERR_SUCCESS;
     197             : }
     198             : 
     199             : /*
     200             :   parse a arch dependent uint32/uint64
     201             : */
     202   576771070 : _PUBLIC_ enum ndr_err_code ndr_pull_uint3264(struct ndr_pull *ndr, ndr_flags_type ndr_flags, uint32_t *v)
     203             : {
     204   576771070 :         uint64_t v64 = 0;
     205     3816726 :         enum ndr_err_code err;
     206   576771070 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     207   576771070 :         if (likely(!(ndr->flags & LIBNDR_FLAG_NDR64))) {
     208   576770470 :                 return ndr_pull_uint32(ndr, ndr_flags, v);
     209             :         }
     210         600 :         err = ndr_pull_hyper(ndr, ndr_flags, &v64);
     211         600 :         if (!NDR_ERR_CODE_IS_SUCCESS(err)) {
     212           0 :                 return err;
     213             :         }
     214         600 :         *v = (uint32_t)v64;
     215         600 :         if (unlikely(v64 != *v)) {
     216           0 :                 DEBUG(0,(__location__ ": non-zero upper 32 bits 0x%016"PRIx64"\n",
     217             :                          v64));
     218           0 :                 return ndr_pull_error(ndr, NDR_ERR_NDR64, __location__ ": non-zero upper 32 bits 0x%016"PRIx64"\n",
     219             :                          v64);
     220             :         }
     221           0 :         return err;
     222             : }
     223             : 
     224             : /*
     225             :   parse a double
     226             : */
     227           0 : _PUBLIC_ enum ndr_err_code ndr_pull_double(struct ndr_pull *ndr, ndr_flags_type ndr_flags, double *v)
     228             : {
     229           0 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     230           0 :         NDR_PULL_ALIGN(ndr, 8);
     231           0 :         NDR_PULL_NEED_BYTES(ndr, 8);
     232           0 :         memcpy(v, ndr->data+ndr->offset, 8);
     233           0 :         ndr->offset += 8;
     234           0 :         return NDR_ERR_SUCCESS;
     235             : }
     236             : 
     237             : /*
     238             :   parse a pointer referent identifier stored in 2 bytes
     239             : */
     240      539268 : _PUBLIC_ enum ndr_err_code ndr_pull_relative_ptr_short(struct ndr_pull *ndr, uint16_t *v)
     241             : {
     242      539268 :         NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, v));
     243      539268 :         if (*v != 0) {
     244      539216 :                 ndr->ptr_count++;
     245             :         }
     246      539268 :         *(v) -= ndr->relative_rap_convert;
     247      539268 :         return NDR_ERR_SUCCESS;
     248             : }
     249             : 
     250             : /*
     251             :   parse a pointer referent identifier
     252             : */
     253    97865089 : _PUBLIC_ enum ndr_err_code ndr_pull_generic_ptr(struct ndr_pull *ndr, uint32_t *v)
     254             : {
     255    97865089 :         NDR_CHECK(ndr_pull_uint3264(ndr, NDR_SCALARS, v));
     256    97865089 :         if (*v != 0) {
     257    89308181 :                 ndr->ptr_count++;
     258             :         }
     259    95245077 :         return NDR_ERR_SUCCESS;
     260             : }
     261             : 
     262             : /*
     263             :   parse a ref pointer referent identifier
     264             : */
     265       32930 : _PUBLIC_ enum ndr_err_code ndr_pull_ref_ptr(struct ndr_pull *ndr, uint32_t *v)
     266             : {
     267       32930 :         NDR_CHECK(ndr_pull_uint3264(ndr, NDR_SCALARS, v));
     268             :         /* ref pointers always point to data */
     269       32930 :         *v = 1;
     270       32930 :         return NDR_ERR_SUCCESS;
     271             : }
     272             : 
     273             : /*
     274             :   parse a udlong
     275             : */
     276   390044830 : _PUBLIC_ enum ndr_err_code ndr_pull_udlong(struct ndr_pull *ndr, ndr_flags_type ndr_flags, uint64_t *v)
     277             : {
     278   390044830 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     279   390044830 :         NDR_PULL_ALIGN(ndr, 4);
     280   390044830 :         NDR_PULL_NEED_BYTES(ndr, 8);
     281   390044821 :         *v = NDR_PULL_U32(ndr, ndr->offset);
     282   390044821 :         *v |= (uint64_t)(NDR_PULL_U32(ndr, ndr->offset+4)) << 32;
     283   390044821 :         ndr->offset += 8;
     284   390044821 :         return NDR_ERR_SUCCESS;
     285             : }
     286             : 
     287             : /*
     288             :   parse a udlongr
     289             : */
     290       14395 : _PUBLIC_ enum ndr_err_code ndr_pull_udlongr(struct ndr_pull *ndr, ndr_flags_type ndr_flags, uint64_t *v)
     291             : {
     292       14395 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     293       14395 :         NDR_PULL_ALIGN(ndr, 4);
     294       14395 :         NDR_PULL_NEED_BYTES(ndr, 8);
     295       14395 :         *v = ((uint64_t)NDR_PULL_U32(ndr, ndr->offset)) << 32;
     296       14395 :         *v |= NDR_PULL_U32(ndr, ndr->offset+4);
     297       14395 :         ndr->offset += 8;
     298       14395 :         return NDR_ERR_SUCCESS;
     299             : }
     300             : 
     301             : /*
     302             :   parse a dlong
     303             : */
     304         726 : _PUBLIC_ enum ndr_err_code ndr_pull_dlong(struct ndr_pull *ndr, ndr_flags_type ndr_flags, int64_t *v)
     305             : {
     306         726 :         return ndr_pull_udlong(ndr, ndr_flags, (uint64_t *)v);
     307             : }
     308             : 
     309             : /*
     310             :   parse a hyper
     311             : */
     312   377662660 : _PUBLIC_ enum ndr_err_code ndr_pull_hyper(struct ndr_pull *ndr, ndr_flags_type ndr_flags, uint64_t *v)
     313             : {
     314   377662660 :         NDR_PULL_ALIGN(ndr, 8);
     315   377662660 :         if (NDR_BE(ndr)) {
     316        8921 :                 return ndr_pull_udlongr(ndr, ndr_flags, v);
     317             :         }
     318   377653739 :         return ndr_pull_udlong(ndr, ndr_flags, v);
     319             : }
     320             : 
     321             : /*
     322             :   parse an int64
     323             : */
     324         417 : _PUBLIC_ enum ndr_err_code ndr_pull_int64(struct ndr_pull *ndr, ndr_flags_type ndr_flags, int64_t *v)
     325             : {
     326         417 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     327         417 :         NDR_PULL_ALIGN(ndr, 8);
     328         417 :         NDR_PULL_NEED_BYTES(ndr, 8);
     329         417 :         *v = NDR_PULL_I64(ndr, ndr->offset);
     330         417 :         ndr->offset += 8;
     331         417 :         return NDR_ERR_SUCCESS;
     332             : }
     333             : 
     334             : /*
     335             :   parse a pointer
     336             : */
     337      639607 : _PUBLIC_ enum ndr_err_code ndr_pull_pointer(struct ndr_pull *ndr, ndr_flags_type ndr_flags, void* *v)
     338             : {
     339           0 :         uintptr_t h;
     340      639607 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     341      639607 :         NDR_PULL_ALIGN(ndr, sizeof(h));
     342      639607 :         NDR_PULL_NEED_BYTES(ndr, sizeof(h));
     343      639607 :         memcpy(&h, ndr->data+ndr->offset, sizeof(h));
     344      639607 :         ndr->offset += sizeof(h);
     345      639607 :         *v = (void *)h;
     346      639607 :         return NDR_ERR_SUCCESS;
     347             : }
     348             : 
     349             : /*
     350             :   pull a NTSTATUS
     351             : */
     352      506843 : _PUBLIC_ enum ndr_err_code ndr_pull_NTSTATUS(struct ndr_pull *ndr, ndr_flags_type ndr_flags, NTSTATUS *status)
     353             : {
     354       36983 :         uint32_t v;
     355      506843 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     356      506843 :         NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &v));
     357      506843 :         *status = NT_STATUS(v);
     358      506843 :         return NDR_ERR_SUCCESS;
     359             : }
     360             : 
     361             : /*
     362             :   push a NTSTATUS
     363             : */
     364      913534 : _PUBLIC_ enum ndr_err_code ndr_push_NTSTATUS(struct ndr_push *ndr, ndr_flags_type ndr_flags, NTSTATUS status)
     365             : {
     366      913534 :         return ndr_push_uint32(ndr, ndr_flags, NT_STATUS_V(status));
     367             : }
     368             : 
     369       27278 : _PUBLIC_ void ndr_print_NTSTATUS(struct ndr_print *ndr, const char *name, NTSTATUS r)
     370             : {
     371       27278 :         ndr->print(ndr, "%-25s: %s", name, nt_errstr(r));
     372       27278 : }
     373             : 
     374             : /*
     375             :   pull a WERROR
     376             : */
     377      796926 : _PUBLIC_ enum ndr_err_code ndr_pull_WERROR(struct ndr_pull *ndr, ndr_flags_type ndr_flags, WERROR *status)
     378             : {
     379        2027 :         uint32_t v;
     380      796926 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     381      796926 :         NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &v));
     382      796926 :         *status = W_ERROR(v);
     383      796926 :         return NDR_ERR_SUCCESS;
     384             : }
     385             : 
     386             : /*
     387             :   pull a HRESULT
     388             : */
     389           8 : _PUBLIC_ enum ndr_err_code ndr_pull_HRESULT(struct ndr_pull *ndr, ndr_flags_type ndr_flags, HRESULT *status)
     390             : {
     391           8 :         uint32_t v;
     392           8 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     393           8 :         NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &v));
     394           8 :         *status = HRES_ERROR(v);
     395           8 :         return NDR_ERR_SUCCESS;
     396             : }
     397             : 
     398             : /*
     399             :   parse a uint8_t enum
     400             : */
     401   223421200 : _PUBLIC_ enum ndr_err_code ndr_pull_enum_uint8(struct ndr_pull *ndr, ndr_flags_type ndr_flags, uint8_t *v)
     402             : {
     403   223421200 :         return ndr_pull_uint8(ndr, ndr_flags, v);
     404             : }
     405             : 
     406             : /*
     407             :   parse a uint16_t enum
     408             : */
     409     1632459 : _PUBLIC_ enum ndr_err_code ndr_pull_enum_uint16(struct ndr_pull *ndr, ndr_flags_type ndr_flags, uint16_t *v)
     410             : {
     411     1632459 :         return ndr_pull_uint16(ndr, ndr_flags, v);
     412             : }
     413             : 
     414             : /*
     415             :   parse a uint1632_t enum (uint32_t on NDR64)
     416             : */
     417    92867892 : _PUBLIC_ enum ndr_err_code ndr_pull_enum_uint1632(struct ndr_pull *ndr, ndr_flags_type ndr_flags, uint16_t *v)
     418             : {
     419    92867892 :         if (unlikely(ndr->flags & LIBNDR_FLAG_NDR64)) {
     420          12 :                 uint32_t v32;
     421          12 :                 NDR_CHECK(ndr_pull_uint32(ndr, ndr_flags, &v32));
     422          12 :                 *v = v32;
     423          12 :                 if (v32 != *v) {
     424           0 :                         DEBUG(0,(__location__ ": non-zero upper 16 bits 0x%08"PRIx32"\n", v32));
     425           0 :                         return NDR_ERR_NDR64;
     426             :                 }
     427           0 :                 return NDR_ERR_SUCCESS;
     428             :         }
     429    92867880 :         return ndr_pull_uint16(ndr, ndr_flags, v);
     430             : }
     431             : 
     432             : /*
     433             :   parse a uint32_t enum
     434             : */
     435   108434890 : _PUBLIC_ enum ndr_err_code ndr_pull_enum_uint32(struct ndr_pull *ndr, ndr_flags_type ndr_flags, uint32_t *v)
     436             : {
     437   108434890 :         return ndr_pull_uint32(ndr, ndr_flags, v);
     438             : }
     439             : 
     440             : /*
     441             :   push a uint8_t enum
     442             : */
     443    68061829 : _PUBLIC_ enum ndr_err_code ndr_push_enum_uint8(struct ndr_push *ndr, ndr_flags_type ndr_flags, uint8_t v)
     444             : {
     445    68061829 :         return ndr_push_uint8(ndr, ndr_flags, v);
     446             : }
     447             : 
     448             : /*
     449             :   push a uint16_t enum
     450             : */
     451     1524411 : _PUBLIC_ enum ndr_err_code ndr_push_enum_uint16(struct ndr_push *ndr, ndr_flags_type ndr_flags, uint16_t v)
     452             : {
     453     1524411 :         return ndr_push_uint16(ndr, ndr_flags, v);
     454             : }
     455             : 
     456             : /*
     457             :   push a uint32_t enum
     458             : */
     459    97947131 : _PUBLIC_ enum ndr_err_code ndr_push_enum_uint32(struct ndr_push *ndr, ndr_flags_type ndr_flags, uint32_t v)
     460             : {
     461    97947131 :         return ndr_push_uint32(ndr, ndr_flags, v);
     462             : }
     463             : 
     464             : /*
     465             :   push a uint1632_t enum
     466             : */
     467    81016393 : _PUBLIC_ enum ndr_err_code ndr_push_enum_uint1632(struct ndr_push *ndr, ndr_flags_type ndr_flags, uint16_t v)
     468             : {
     469    81016393 :         if (unlikely(ndr->flags & LIBNDR_FLAG_NDR64)) {
     470           0 :                 return ndr_push_uint32(ndr, ndr_flags, v);
     471             :         }
     472    81016393 :         return ndr_push_uint16(ndr, ndr_flags, v);
     473             : }
     474             : 
     475             : /*
     476             :   push a WERROR
     477             : */
     478     2447478 : _PUBLIC_ enum ndr_err_code ndr_push_WERROR(struct ndr_push *ndr, ndr_flags_type ndr_flags, WERROR status)
     479             : {
     480     2447478 :         return ndr_push_uint32(ndr, NDR_SCALARS, W_ERROR_V(status));
     481             : }
     482             : 
     483       20544 : _PUBLIC_ void ndr_print_WERROR(struct ndr_print *ndr, const char *name, WERROR r)
     484             : {
     485       20544 :         ndr->print(ndr, "%-25s: %s", name, win_errstr(r));
     486       20544 : }
     487             : 
     488             : /*
     489             :   push a HRESULT
     490             : */
     491           0 : _PUBLIC_ enum ndr_err_code ndr_push_HRESULT(struct ndr_push *ndr, ndr_flags_type ndr_flags, HRESULT status)
     492             : {
     493           0 :         return ndr_push_uint32(ndr, NDR_SCALARS, HRES_ERROR_V(status));
     494             : }
     495             : 
     496           8 : _PUBLIC_ void ndr_print_HRESULT(struct ndr_print *ndr, const char *name, HRESULT r)
     497             : {
     498           8 :         ndr->print(ndr, "%-25s: %s", name, hresult_errstr(r));
     499           8 : }
     500             : 
     501             : 
     502             : /*
     503             :   parse a set of bytes
     504             : */
     505  1455209489 : _PUBLIC_ enum ndr_err_code ndr_pull_bytes(struct ndr_pull *ndr, uint8_t *data, uint32_t n)
     506             : {
     507  1455209489 :         NDR_PULL_NEED_BYTES(ndr, n);
     508  1455209489 :         memcpy(data, ndr->data + ndr->offset, n);
     509  1455209489 :         ndr->offset += n;
     510  1455209489 :         return NDR_ERR_SUCCESS;
     511             : }
     512             : 
     513             : /*
     514             :   pull an array of uint8
     515             : */
     516  1454356132 : _PUBLIC_ enum ndr_err_code ndr_pull_array_uint8(struct ndr_pull *ndr, ndr_flags_type ndr_flags, uint8_t *data, uint32_t n)
     517             : {
     518  1454356132 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     519  1454356132 :         if (!(ndr_flags & NDR_SCALARS)) {
     520           0 :                 return NDR_ERR_SUCCESS;
     521             :         }
     522  1454356132 :         return ndr_pull_bytes(ndr, data, n);
     523             : }
     524             : 
     525             : /*
     526             :   push a int8_t
     527             : */
     528   202512484 : _PUBLIC_ enum ndr_err_code ndr_push_int8(struct ndr_push *ndr, ndr_flags_type ndr_flags, int8_t v)
     529             : {
     530   202512484 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
     531   202512484 :         NDR_PUSH_NEED_BYTES(ndr, 1);
     532   202512484 :         PUSH_BE_U8(ndr->data, ndr->offset, (uint8_t)v);
     533   202512484 :         ndr->offset += 1;
     534   202512484 :         return NDR_ERR_SUCCESS;
     535             : }
     536             : 
     537             : /*
     538             :   push a uint8_t
     539             : */
     540   809413768 : _PUBLIC_ enum ndr_err_code ndr_push_uint8(struct ndr_push *ndr, ndr_flags_type ndr_flags, uint8_t v)
     541             : {
     542   809413768 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
     543   809413768 :         NDR_PUSH_NEED_BYTES(ndr, 1);
     544   809413768 :         PUSH_BE_U8(ndr->data, ndr->offset, v);
     545   809413768 :         ndr->offset += 1;
     546   809413768 :         return NDR_ERR_SUCCESS;
     547             : }
     548             : 
     549             : /*
     550             :   push a int16_t
     551             : */
     552           0 : _PUBLIC_ enum ndr_err_code ndr_push_int16(struct ndr_push *ndr, ndr_flags_type ndr_flags, int16_t v)
     553             : {
     554           0 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
     555           0 :         NDR_PUSH_ALIGN(ndr, 2);
     556           0 :         NDR_PUSH_NEED_BYTES(ndr, 2);
     557           0 :         NDR_PUSH_U16(ndr, ndr->offset, (uint16_t)v);
     558           0 :         ndr->offset += 2;
     559           0 :         return NDR_ERR_SUCCESS;
     560             : }
     561             : 
     562             : /*
     563             :   push a uint16_t
     564             : */
     565   801737541 : _PUBLIC_ enum ndr_err_code ndr_push_uint16(struct ndr_push *ndr, ndr_flags_type ndr_flags, uint16_t v)
     566             : {
     567   801737541 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
     568   807473676 :         NDR_PUSH_ALIGN(ndr, 2);
     569   801737541 :         NDR_PUSH_NEED_BYTES(ndr, 2);
     570   801737541 :         NDR_PUSH_U16(ndr, ndr->offset, v);
     571   801737541 :         ndr->offset += 2;
     572   801737541 :         return NDR_ERR_SUCCESS;
     573             : }
     574             : 
     575             : /*
     576             :   push a uint1632
     577             : */
     578           0 : _PUBLIC_ enum ndr_err_code ndr_push_uint1632(struct ndr_push *ndr, ndr_flags_type ndr_flags, uint16_t v)
     579             : {
     580           0 :         if (unlikely(ndr->flags & LIBNDR_FLAG_NDR64)) {
     581           0 :                 return ndr_push_uint32(ndr, ndr_flags, v);
     582             :         }
     583           0 :         return ndr_push_uint16(ndr, ndr_flags, v);
     584             : }
     585             : 
     586             : /*
     587             :   push a int32_t
     588             : */
     589     3301312 : _PUBLIC_ enum ndr_err_code ndr_push_int32(struct ndr_push *ndr, ndr_flags_type ndr_flags, int32_t v)
     590             : {
     591     3301312 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
     592     3301591 :         NDR_PUSH_ALIGN(ndr, 4);
     593     3301312 :         NDR_PUSH_NEED_BYTES(ndr, 4);
     594     3301312 :         NDR_PUSH_I32(ndr, ndr->offset, v);
     595     3301312 :         ndr->offset += 4;
     596     3301312 :         return NDR_ERR_SUCCESS;
     597             : }
     598             : 
     599             : /*
     600             :   push a uint32_t
     601             : */
     602  2507462672 : _PUBLIC_ enum ndr_err_code ndr_push_uint32(struct ndr_push *ndr, ndr_flags_type ndr_flags, uint32_t v)
     603             : {
     604  2507462672 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
     605  2569522442 :         NDR_PUSH_ALIGN(ndr, 4);
     606  2507462672 :         NDR_PUSH_NEED_BYTES(ndr, 4);
     607  2507462672 :         NDR_PUSH_U32(ndr, ndr->offset, v);
     608  2507462672 :         ndr->offset += 4;
     609  2507462672 :         return NDR_ERR_SUCCESS;
     610             : }
     611             : 
     612             : /*
     613             :   push a uint3264
     614             : */
     615   746293136 : _PUBLIC_ enum ndr_err_code ndr_push_uint3264(struct ndr_push *ndr, ndr_flags_type ndr_flags, uint32_t v)
     616             : {
     617   746293136 :         if (unlikely(ndr->flags & LIBNDR_FLAG_NDR64)) {
     618           0 :                 return ndr_push_hyper(ndr, ndr_flags, v);
     619             :         }
     620   746293136 :         return ndr_push_uint32(ndr, ndr_flags, v);
     621             : }
     622             : 
     623             : /*
     624             :   push a udlong
     625             : */
     626   300495971 : _PUBLIC_ enum ndr_err_code ndr_push_udlong(struct ndr_push *ndr, ndr_flags_type ndr_flags, uint64_t v)
     627             : {
     628   300495971 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
     629   301169883 :         NDR_PUSH_ALIGN(ndr, 4);
     630   300495971 :         NDR_PUSH_NEED_BYTES(ndr, 8);
     631   300495971 :         NDR_PUSH_U32(ndr, ndr->offset, (v & 0xFFFFFFFF));
     632   300495971 :         NDR_PUSH_U32(ndr, ndr->offset+4, (v>>32));
     633   300495971 :         ndr->offset += 8;
     634   300495971 :         return NDR_ERR_SUCCESS;
     635             : }
     636             : 
     637             : /*
     638             :   push a udlongr
     639             : */
     640      440636 : _PUBLIC_ enum ndr_err_code ndr_push_udlongr(struct ndr_push *ndr, ndr_flags_type ndr_flags, uint64_t v)
     641             : {
     642      440636 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
     643      440636 :         NDR_PUSH_ALIGN(ndr, 4);
     644      440636 :         NDR_PUSH_NEED_BYTES(ndr, 8);
     645      440636 :         NDR_PUSH_U32(ndr, ndr->offset, (v>>32));
     646      440636 :         NDR_PUSH_U32(ndr, ndr->offset+4, (v & 0xFFFFFFFF));
     647      440636 :         ndr->offset += 8;
     648      440636 :         return NDR_ERR_SUCCESS;
     649             : }
     650             : 
     651             : /*
     652             :   push a dlong
     653             : */
     654        1004 : _PUBLIC_ enum ndr_err_code ndr_push_dlong(struct ndr_push *ndr, ndr_flags_type ndr_flags, int64_t v)
     655             : {
     656        1004 :         return ndr_push_udlong(ndr, NDR_SCALARS, (uint64_t)v);
     657             : }
     658             : 
     659             : /*
     660             :   push a hyper
     661             : */
     662   288572883 : _PUBLIC_ enum ndr_err_code ndr_push_hyper(struct ndr_push *ndr, ndr_flags_type ndr_flags, uint64_t v)
     663             : {
     664   596088328 :         NDR_PUSH_ALIGN(ndr, 8);
     665   288572883 :         if (NDR_BE(ndr)) {
     666      429688 :                 return ndr_push_udlongr(ndr, NDR_SCALARS, v);
     667             :         }
     668   288143195 :         return ndr_push_udlong(ndr, NDR_SCALARS, v);
     669             : }
     670             : 
     671             : /*
     672             :   push an int64
     673             : */
     674        2950 : _PUBLIC_ enum ndr_err_code ndr_push_int64(struct ndr_push *ndr, ndr_flags_type ndr_flags, int64_t v)
     675             : {
     676        2950 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
     677        3930 :         NDR_PUSH_ALIGN(ndr, 8);
     678        2950 :         NDR_PUSH_NEED_BYTES(ndr, 8);
     679        2950 :         NDR_PUSH_I64(ndr, ndr->offset, v);
     680        2950 :         ndr->offset += 8;
     681        2950 :         return NDR_ERR_SUCCESS;
     682             : }
     683             : 
     684             : /*
     685             :   push a double
     686             : */
     687           0 : _PUBLIC_ enum ndr_err_code ndr_push_double(struct ndr_push *ndr, ndr_flags_type ndr_flags, double v)
     688             : {
     689           0 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
     690           0 :         NDR_PUSH_ALIGN(ndr, 8);
     691           0 :         NDR_PUSH_NEED_BYTES(ndr, 8);
     692           0 :         memcpy(ndr->data+ndr->offset, &v, 8);
     693           0 :         ndr->offset += 8;
     694           0 :         return NDR_ERR_SUCCESS;
     695             : }
     696             : 
     697             : /*
     698             :   push a pointer
     699             : */
     700      483582 : _PUBLIC_ enum ndr_err_code ndr_push_pointer(struct ndr_push *ndr, ndr_flags_type ndr_flags, void* v)
     701             : {
     702      483582 :         uintptr_t h = (intptr_t)v;
     703      483582 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
     704     1444282 :         NDR_PUSH_ALIGN(ndr, sizeof(h));
     705      483582 :         NDR_PUSH_NEED_BYTES(ndr, sizeof(h));
     706      483582 :         memcpy(ndr->data+ndr->offset, &h, sizeof(h));
     707      483582 :         ndr->offset += sizeof(h);
     708      483582 :         return NDR_ERR_SUCCESS;
     709             : }
     710             : 
     711  1093848365 : _PUBLIC_ enum ndr_err_code ndr_push_align(struct ndr_push *ndr, size_t size)
     712             : {
     713             :         /* this is a nasty hack to make pidl work with NDR64 */
     714  1093848365 :         if (size == 5) {
     715   322752389 :                 if (ndr->flags & LIBNDR_FLAG_NDR64) {
     716           0 :                         size = 8;
     717             :                 } else {
     718   322752389 :                         size = 4;
     719             :                 }
     720   771095976 :         } else if (size == 3) {
     721      128058 :                 if (ndr->flags & LIBNDR_FLAG_NDR64) {
     722           0 :                         size = 4;
     723             :                 } else {
     724      128058 :                         size = 2;
     725             :                 }
     726             :         }
     727  1167974280 :         NDR_PUSH_ALIGN(ndr, size);
     728  1080961644 :         return NDR_ERR_SUCCESS;
     729             : }
     730             : 
     731  1671378610 : _PUBLIC_ enum ndr_err_code ndr_pull_align(struct ndr_pull *ndr, size_t size)
     732             : {
     733             :         /* this is a nasty hack to make pidl work with NDR64 */
     734  1671378610 :         if (size == 5) {
     735   281336326 :                 if (ndr->flags & LIBNDR_FLAG_NDR64) {
     736           0 :                         size = 8;
     737             :                 } else {
     738   281336014 :                         size = 4;
     739             :                 }
     740  1390042284 :         } else if (size == 3) {
     741      315905 :                 if (ndr->flags & LIBNDR_FLAG_NDR64) {
     742           0 :                         size = 4;
     743             :                 } else {
     744      315905 :                         size = 2;
     745             :                 }
     746             :         }
     747  1671378610 :         NDR_PULL_ALIGN(ndr, size);
     748  1633793347 :         return NDR_ERR_SUCCESS;
     749             : }
     750             : 
     751   117553628 : _PUBLIC_ enum ndr_err_code ndr_push_union_align(struct ndr_push *ndr, size_t size)
     752             : {
     753             :         /* MS-RPCE section 2.2.5.3.4.4 */
     754   117553628 :         if (ndr->flags & LIBNDR_FLAG_NDR64) {
     755           0 :                 return ndr_push_align(ndr, size);
     756             :         }
     757   115679384 :         return NDR_ERR_SUCCESS;
     758             : }
     759             : 
     760   443515128 : _PUBLIC_ enum ndr_err_code ndr_pull_union_align(struct ndr_pull *ndr, size_t size)
     761             : {
     762             :         /* MS-RPCE section 2.2.5.3.4.4 */
     763   443515128 :         if (ndr->flags & LIBNDR_FLAG_NDR64) {
     764          76 :                 return ndr_pull_align(ndr, size);
     765             :         }
     766   432895129 :         return NDR_ERR_SUCCESS;
     767             : }
     768             : 
     769   871436512 : _PUBLIC_ enum ndr_err_code ndr_push_trailer_align(struct ndr_push *ndr, size_t size)
     770             : {
     771             :         /* MS-RPCE section 2.2.5.3.4.1 */
     772   871436512 :         if (ndr->flags & LIBNDR_FLAG_NDR64) {
     773           0 :                 return ndr_push_align(ndr, size);
     774             :         }
     775   861841571 :         return NDR_ERR_SUCCESS;
     776             : }
     777             : 
     778  1313371928 : _PUBLIC_ enum ndr_err_code ndr_pull_trailer_align(struct ndr_pull *ndr, size_t size)
     779             : {
     780             :         /* MS-RPCE section 2.2.5.3.4.1 */
     781  1313371928 :         if (ndr->flags & LIBNDR_FLAG_NDR64) {
     782         202 :                 return ndr_pull_align(ndr, size);
     783             :         }
     784  1283906646 :         return NDR_ERR_SUCCESS;
     785             : }
     786             : 
     787             : /*
     788             :   push some bytes
     789             : */
     790   923523929 : _PUBLIC_ enum ndr_err_code ndr_push_bytes(struct ndr_push *ndr, const uint8_t *data, uint32_t n)
     791             : {
     792   923523929 :         if (unlikely(n == 0)) {
     793     5430807 :                 return NDR_ERR_SUCCESS;
     794             :         }
     795   918067172 :         if (unlikely(data == NULL)) {
     796           0 :                 return NDR_ERR_INVALID_POINTER;
     797             :         }
     798   918067172 :         NDR_PUSH_NEED_BYTES(ndr, n);
     799   918067170 :         memcpy(ndr->data + ndr->offset, data, n);
     800   918067170 :         ndr->offset += n;
     801   918067170 :         return NDR_ERR_SUCCESS;
     802             : }
     803             : 
     804             : /*
     805             :   push some zero bytes
     806             : */
     807    17877167 : _PUBLIC_ enum ndr_err_code ndr_push_zero(struct ndr_push *ndr, uint32_t n)
     808             : {
     809    17877167 :         NDR_PUSH_NEED_BYTES(ndr, n);
     810    17877167 :         memset(ndr->data + ndr->offset, 0, n);
     811    17877167 :         ndr->offset += n;
     812    17877167 :         return NDR_ERR_SUCCESS;
     813             : }
     814             : 
     815             : /*
     816             :   push an array of uint8
     817             : */
     818   808945519 : _PUBLIC_ enum ndr_err_code ndr_push_array_uint8(struct ndr_push *ndr, ndr_flags_type ndr_flags, const uint8_t *data, uint32_t n)
     819             : {
     820   808945519 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
     821   808945519 :         if (!(ndr_flags & NDR_SCALARS)) {
     822           0 :                 return NDR_ERR_SUCCESS;
     823             :         }
     824   808945519 :         return ndr_push_bytes(ndr, data, n);
     825             : }
     826             : 
     827             : /*
     828             :   push a unique non-zero value if a pointer is non-NULL, otherwise 0
     829             : */
     830   210913556 : _PUBLIC_ enum ndr_err_code ndr_push_unique_ptr(struct ndr_push *ndr, const void *p)
     831             : {
     832   210913556 :         uint32_t ptr = 0;
     833   210913556 :         if (p) {
     834   204784115 :                 ptr = ndr->ptr_count * 4;
     835   204784115 :                 ptr |= 0x00020000;
     836   204784115 :                 ndr->ptr_count++;
     837             :         }
     838   210913556 :         return ndr_push_uint3264(ndr, NDR_SCALARS, ptr);
     839             : }
     840             : 
     841             : /*
     842             :   push a 'simple' full non-zero value if a pointer is non-NULL, otherwise 0
     843             : */
     844       67136 : _PUBLIC_ enum ndr_err_code ndr_push_full_ptr(struct ndr_push *ndr, const void *p)
     845             : {
     846       67136 :         enum ndr_err_code ret = NDR_ERR_SUCCESS;
     847       67136 :         uint32_t ptr = 0;
     848       67136 :         if (p) {
     849             :                 /* Check if the pointer already exists and has an id */
     850       66938 :                 ret = ndr_token_peek(&ndr->full_ptr_list, p, &ptr);
     851       66938 :                 if (ret == NDR_ERR_TOKEN) {
     852       66938 :                         ndr->ptr_count++;
     853       66938 :                         ptr = ndr->ptr_count;
     854       66938 :                         ret = ndr_token_store(ndr, &ndr->full_ptr_list, p, ptr);
     855       66938 :                         if (ret != NDR_ERR_SUCCESS) {
     856           0 :                                 return ret;
     857             :                         }
     858           0 :                 } else if (ret != NDR_ERR_SUCCESS) {
     859           0 :                         return ret;
     860             :                 }
     861             :         }
     862       67136 :         return ndr_push_uint3264(ndr, NDR_SCALARS, ptr);
     863             : }
     864             : 
     865             : /*
     866             :   push always a 0, if a pointer is NULL it's a fatal error
     867             : */
     868       20652 : _PUBLIC_ enum ndr_err_code ndr_push_ref_ptr(struct ndr_push *ndr)
     869             : {
     870       20652 :         return ndr_push_uint3264(ndr, NDR_SCALARS, 0xAEF1AEF1);
     871             : }
     872             : 
     873             : 
     874             : /*
     875             :   push a NTTIME
     876             : */
     877     9598550 : _PUBLIC_ enum ndr_err_code ndr_push_NTTIME(struct ndr_push *ndr, ndr_flags_type ndr_flags, NTTIME t)
     878             : {
     879     9598550 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
     880     9598550 :         NDR_CHECK(ndr_push_udlong(ndr, ndr_flags, t));
     881     9492925 :         return NDR_ERR_SUCCESS;
     882             : }
     883             : 
     884             : /*
     885             :   pull a NTTIME
     886             : */
     887     9730538 : _PUBLIC_ enum ndr_err_code ndr_pull_NTTIME(struct ndr_pull *ndr, ndr_flags_type ndr_flags, NTTIME *t)
     888             : {
     889     9730538 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     890     9730538 :         NDR_CHECK(ndr_pull_udlong(ndr, ndr_flags, t));
     891     9659325 :         return NDR_ERR_SUCCESS;
     892             : }
     893             : 
     894             : /*
     895             :   push a NTTIME_1sec
     896             : */
     897    92745995 : _PUBLIC_ enum ndr_err_code ndr_push_NTTIME_1sec(struct ndr_push *ndr, ndr_flags_type ndr_flags, NTTIME t)
     898             : {
     899    92745995 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
     900    92745995 :         t /= 10000000;
     901    92745995 :         NDR_CHECK(ndr_push_hyper(ndr, ndr_flags, t));
     902    90881627 :         return NDR_ERR_SUCCESS;
     903             : }
     904             : 
     905             : /*
     906             :   pull a NTTIME_1sec
     907             : */
     908   103293546 : _PUBLIC_ enum ndr_err_code ndr_pull_NTTIME_1sec(struct ndr_pull *ndr, ndr_flags_type ndr_flags, NTTIME *t)
     909             : {
     910   103293546 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     911   103293546 :         NDR_CHECK(ndr_pull_hyper(ndr, ndr_flags, t));
     912   103293546 :         (*t) *= 10000000;
     913   103293546 :         return NDR_ERR_SUCCESS;
     914             : }
     915             : 
     916             : /*
     917             :   pull a NTTIME_hyper
     918             : */
     919       24222 : _PUBLIC_ enum ndr_err_code ndr_pull_NTTIME_hyper(struct ndr_pull *ndr, ndr_flags_type ndr_flags, NTTIME *t)
     920             : {
     921       24222 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     922       24222 :         NDR_CHECK(ndr_pull_hyper(ndr, ndr_flags, t));
     923       24182 :         return NDR_ERR_SUCCESS;
     924             : }
     925             : 
     926             : /*
     927             :   push a NTTIME_hyper
     928             : */
     929       34627 : _PUBLIC_ enum ndr_err_code ndr_push_NTTIME_hyper(struct ndr_push *ndr, ndr_flags_type ndr_flags, NTTIME t)
     930             : {
     931       34627 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
     932       34627 :         NDR_CHECK(ndr_push_hyper(ndr, ndr_flags, t));
     933       34595 :         return NDR_ERR_SUCCESS;
     934             : }
     935             : 
     936             : /*
     937             :   push a time_t
     938             : */
     939       76899 : _PUBLIC_ enum ndr_err_code ndr_push_time_t(struct ndr_push *ndr, ndr_flags_type ndr_flags, time_t t)
     940             : {
     941       76899 :         return ndr_push_uint32(ndr, ndr_flags, t);
     942             : }
     943             : 
     944             : /*
     945             :   pull a time_t
     946             : */
     947      184587 : _PUBLIC_ enum ndr_err_code ndr_pull_time_t(struct ndr_pull *ndr, ndr_flags_type ndr_flags, time_t *t)
     948             : {
     949        6201 :         uint32_t tt;
     950      184587 :         NDR_CHECK(ndr_pull_uint32(ndr, ndr_flags, &tt));
     951      184587 :         *t = tt;
     952      184587 :         return NDR_ERR_SUCCESS;
     953             : }
     954             : 
     955             : 
     956             : /*
     957             :   push a uid_t
     958             : */
     959     2794686 : _PUBLIC_ enum ndr_err_code ndr_push_uid_t(struct ndr_push *ndr, ndr_flags_type ndr_flags, uid_t u)
     960             : {
     961     2794686 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
     962     2794686 :         return ndr_push_hyper(ndr, NDR_SCALARS, (uint64_t)u);
     963             : }
     964             : 
     965             : /*
     966             :   pull a uid_t
     967             : */
     968     1669399 : _PUBLIC_ enum ndr_err_code ndr_pull_uid_t(struct ndr_pull *ndr, ndr_flags_type ndr_flags, uid_t *u)
     969             : {
     970     1669399 :         uint64_t uu = 0;
     971     1669399 :         NDR_CHECK(ndr_pull_hyper(ndr, ndr_flags, &uu));
     972     1669399 :         *u = (uid_t)uu;
     973     1669399 :         if (unlikely(uu != *u)) {
     974           0 :                 DEBUG(0,(__location__ ": uid_t pull doesn't fit 0x%016"PRIx64"\n",
     975             :                          uu));
     976           0 :                 return NDR_ERR_NDR64;
     977             :         }
     978     1663284 :         return NDR_ERR_SUCCESS;
     979             : }
     980             : 
     981             : 
     982             : /*
     983             :   push a gid_t
     984             : */
     985     6087721 : _PUBLIC_ enum ndr_err_code ndr_push_gid_t(struct ndr_push *ndr, ndr_flags_type ndr_flags, gid_t g)
     986             : {
     987     6087721 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
     988     6087721 :         return ndr_push_hyper(ndr, NDR_SCALARS, (uint64_t)g);
     989             : }
     990             : 
     991             : /*
     992             :   pull a gid_t
     993             : */
     994     4279519 : _PUBLIC_ enum ndr_err_code ndr_pull_gid_t(struct ndr_pull *ndr, ndr_flags_type ndr_flags, gid_t *g)
     995             : {
     996     4279519 :         uint64_t gg = 0;
     997     4279519 :         NDR_CHECK(ndr_pull_hyper(ndr, ndr_flags, &gg));
     998     4279519 :         *g = (gid_t)gg;
     999     4279519 :         if (unlikely(gg != *g)) {
    1000           0 :                 DEBUG(0,(__location__ ": gid_t pull doesn't fit 0x%016"PRIx64"\n",
    1001             :                          gg));
    1002           0 :                 return NDR_ERR_NDR64;
    1003             :         }
    1004     4227124 :         return NDR_ERR_SUCCESS;
    1005             : }
    1006             : 
    1007             : 
    1008             : /*
    1009             :   pull a ipv4address
    1010             : */
    1011       83831 : _PUBLIC_ enum ndr_err_code ndr_pull_ipv4address(struct ndr_pull *ndr, ndr_flags_type ndr_flags, const char **address)
    1012             : {
    1013         353 :         uint32_t addr;
    1014         353 :         struct in_addr in;
    1015       83831 :         NDR_CHECK(ndr_pull_uint32(ndr, ndr_flags, &addr));
    1016       83831 :         in.s_addr = htonl(addr);
    1017       83831 :         *address = talloc_strdup(ndr->current_mem_ctx, inet_ntoa(in));
    1018       83831 :         NDR_ERR_HAVE_NO_MEMORY(*address);
    1019       83478 :         return NDR_ERR_SUCCESS;
    1020             : }
    1021             : 
    1022             : /*
    1023             :   push a ipv4address
    1024             : */
    1025      157105 : _PUBLIC_ enum ndr_err_code ndr_push_ipv4address(struct ndr_push *ndr, ndr_flags_type ndr_flags, const char *address)
    1026             : {
    1027        1868 :         uint32_t addr;
    1028      157105 :         if (!is_ipaddress_v4(address)) {
    1029          88 :                 return ndr_push_error(ndr, NDR_ERR_IPV4ADDRESS,
    1030             :                                       "Invalid IPv4 address: '%s'",
    1031             :                                       address);
    1032             :         }
    1033      157017 :         addr = inet_addr(address);
    1034      157017 :         NDR_CHECK(ndr_push_uint32(ndr, ndr_flags, htonl(addr)));
    1035      155149 :         return NDR_ERR_SUCCESS;
    1036             : }
    1037             : 
    1038             : /*
    1039             :   print a ipv4address
    1040             : */
    1041         326 : _PUBLIC_ void ndr_print_ipv4address(struct ndr_print *ndr, const char *name,
    1042             :                            const char *address)
    1043             : {
    1044         326 :         ndr->print(ndr, "%-25s: %s", name, address);
    1045         326 : }
    1046             : 
    1047             : /*
    1048             :   pull a ipv6address
    1049             : */
    1050             : #define IPV6_BYTES 16
    1051             : #define IPV6_ADDR_STR_LEN 39
    1052       31530 : _PUBLIC_ enum ndr_err_code ndr_pull_ipv6address(struct ndr_pull *ndr, ndr_flags_type ndr_flags, const char **address)
    1053             : {
    1054          12 :         uint8_t addr[IPV6_BYTES];
    1055       31530 :         char *addr_str = talloc_strdup(ndr->current_mem_ctx, "");
    1056          12 :         int i;
    1057       31530 :         NDR_ERR_HAVE_NO_MEMORY(addr_str);
    1058       31530 :         NDR_CHECK(ndr_pull_array_uint8(ndr, ndr_flags, addr, IPV6_BYTES));
    1059      536010 :         for (i = 0; i < IPV6_BYTES; ++i) {
    1060      504480 :                 addr_str = talloc_asprintf_append(addr_str, "%02x", addr[i]);
    1061      504480 :                 NDR_ERR_HAVE_NO_MEMORY(addr_str);
    1062             :                 /* We need a ':' every second byte but the last one */
    1063      504480 :                 if (i%2 == 1 && i != (IPV6_BYTES - 1)) {
    1064      220710 :                         addr_str = talloc_strdup_append(addr_str, ":");
    1065      220818 :                         NDR_ERR_HAVE_NO_MEMORY(addr_str);
    1066             :                 }
    1067             :         }
    1068       31530 :         *address = addr_str;
    1069       31530 :         NDR_ERR_HAVE_NO_MEMORY(*address);
    1070       31518 :         return NDR_ERR_SUCCESS;
    1071             : }
    1072             : 
    1073             : /*
    1074             :   push a ipv6address
    1075             : */
    1076       49597 : _PUBLIC_ enum ndr_err_code ndr_push_ipv6address(struct ndr_push *ndr, ndr_flags_type ndr_flags, const char *address)
    1077             : {
    1078             : #ifdef AF_INET6
    1079         232 :         uint8_t addr[IPV6_BYTES];
    1080         232 :         int ret;
    1081             : 
    1082       49597 :         if (!is_ipaddress(address)) {
    1083         264 :                 return ndr_push_error(ndr, NDR_ERR_IPV6ADDRESS,
    1084             :                                       "Invalid IPv6 address: '%s'",
    1085             :                                       address);
    1086             :         }
    1087       49333 :         ret = inet_pton(AF_INET6, address, addr);
    1088       49333 :         if (ret <= 0) {
    1089           0 :                 return NDR_ERR_IPV6ADDRESS;
    1090             :         }
    1091             : 
    1092       49333 :         NDR_CHECK(ndr_push_array_uint8(ndr, ndr_flags, addr, IPV6_BYTES));
    1093             : 
    1094       49101 :         return NDR_ERR_SUCCESS;
    1095             : #else
    1096             :         return NDR_ERR_IPV6ADDRESS;
    1097             : #endif
    1098             : }
    1099             : 
    1100             : /*
    1101             :   print a ipv6address
    1102             : */
    1103          70 : _PUBLIC_ void ndr_print_ipv6address(struct ndr_print *ndr, const char *name,
    1104             :                            const char *address)
    1105             : {
    1106          70 :         ndr->print(ndr, "%-25s: %s", name, address);
    1107          70 : }
    1108             : #undef IPV6_BYTES
    1109             : 
    1110     1255109 : _PUBLIC_ void ndr_print_struct(struct ndr_print *ndr, const char *name, const char *type)
    1111             : {
    1112     1255109 :         ndr->print(ndr, "%s: struct %s", name, type);
    1113     1255109 : }
    1114             : 
    1115           0 : _PUBLIC_ void ndr_print_null(struct ndr_print *ndr)
    1116             : {
    1117           0 :         ndr->print(ndr, "UNEXPECTED NULL POINTER");
    1118           0 : }
    1119             : 
    1120      264084 : _PUBLIC_ void ndr_print_enum(struct ndr_print *ndr, const char *name, const char *type,
    1121             :                     const char *val, uint32_t value)
    1122             : {
    1123      264084 :         if (ndr->flags & LIBNDR_PRINT_ARRAY_HEX) {
    1124      213822 :                 ndr->print(ndr, "%-25s: %s (0x%"PRIX32")", name, val?val:"UNKNOWN_ENUM_VALUE", value);
    1125             :         } else {
    1126       50311 :                 ndr->print(ndr, "%-25s: %s (%"PRIu32")", name, val?val:"UNKNOWN_ENUM_VALUE", value);
    1127             :         }
    1128      264084 : }
    1129             : 
    1130      549969 : _PUBLIC_ void ndr_print_bitmap_flag(struct ndr_print *ndr, size_t size, const char *flag_name, uint32_t flag, uint32_t value)
    1131             : {
    1132      549969 :         if (flag == 0) {
    1133          90 :                 return;
    1134             :         }
    1135             : 
    1136             :         /* this is an attempt to support multi-bit bitmap masks */
    1137      549879 :         value &= flag;
    1138             : 
    1139     5085326 :         while (!(flag & 1)) {
    1140     4535447 :                 flag >>= 1;
    1141     4535447 :                 value >>= 1;
    1142             :         }
    1143      549879 :         if (flag == 1) {
    1144      523900 :                 ndr->print(ndr, "   %"PRIu32": %-25s", value, flag_name);
    1145             :         } else {
    1146       25979 :                 ndr->print(ndr, "0x%02"PRIx32": %-25s (%"PRIu32")", value, flag_name, value);
    1147             :         }
    1148             : }
    1149             : 
    1150           0 : _PUBLIC_ void ndr_print_int8(struct ndr_print *ndr, const char *name, int8_t v)
    1151             : {
    1152           0 :         if (NDR_HIDE_SECRET(ndr)) {
    1153           0 :                 ndr->print(ndr, "%-25s: <REDACTED SECRET VALUE>", name);
    1154           0 :                 return;
    1155             :         }
    1156           0 :         ndr->print(ndr, "%-25s: %"PRId8, name, v);
    1157             : }
    1158             : 
    1159      478429 : _PUBLIC_ void ndr_print_uint8(struct ndr_print *ndr, const char *name, uint8_t v)
    1160             : {
    1161      478429 :         if (NDR_HIDE_SECRET(ndr)) {
    1162           0 :                 ndr->print(ndr, "%-25s: <REDACTED SECRET VALUE>", name);
    1163           0 :                 return;
    1164             :         }
    1165      478429 :         ndr->print(ndr, "%-25s: 0x%02"PRIx8" (%"PRIu8")", name, v, v);
    1166             : }
    1167             : 
    1168           0 : _PUBLIC_ void ndr_print_int16(struct ndr_print *ndr, const char *name, int16_t v)
    1169             : {
    1170           0 :         if (NDR_HIDE_SECRET(ndr)) {
    1171           0 :                 ndr->print(ndr, "%-25s: <REDACTED SECRET VALUE>", name);
    1172           0 :                 return;
    1173             :         }
    1174           0 :         ndr->print(ndr, "%-25s: %"PRId16, name, v);
    1175             : }
    1176             : 
    1177      141272 : _PUBLIC_ void ndr_print_uint16(struct ndr_print *ndr, const char *name, uint16_t v)
    1178             : {
    1179      141272 :         if (NDR_HIDE_SECRET(ndr)) {
    1180           0 :                 ndr->print(ndr, "%-25s: <REDACTED SECRET VALUE>", name);
    1181           0 :                 return;
    1182             :         }
    1183      141272 :         ndr->print(ndr, "%-25s: 0x%04"PRIx16" (%"PRIu16")", name, v, v);
    1184             : }
    1185             : 
    1186          10 : _PUBLIC_ void ndr_print_int32(struct ndr_print *ndr, const char *name, int32_t v)
    1187             : {
    1188          10 :         if (NDR_HIDE_SECRET(ndr)) {
    1189           0 :                 ndr->print(ndr, "%-25s: <REDACTED SECRET VALUE>", name);
    1190           0 :                 return;
    1191             :         }
    1192          10 :         ndr->print(ndr, "%-25s: %"PRId32, name, v);
    1193             : }
    1194             : 
    1195      943647 : _PUBLIC_ void ndr_print_uint32(struct ndr_print *ndr, const char *name, uint32_t v)
    1196             : {
    1197      943647 :         if (NDR_HIDE_SECRET(ndr)) {
    1198           0 :                 ndr->print(ndr, "%-25s: <REDACTED SECRET VALUE>", name);
    1199           0 :                 return;
    1200             :         }
    1201      943647 :         ndr->print(ndr, "%-25s: 0x%08"PRIx32" (%"PRIu32")", name, v, v);
    1202             : }
    1203             : 
    1204           0 : _PUBLIC_ void ndr_print_int3264(struct ndr_print *ndr, const char *name, int32_t v)
    1205             : {
    1206           0 :         if (NDR_HIDE_SECRET(ndr)) {
    1207           0 :                 ndr->print(ndr, "%-25s: <REDACTED SECRET VALUE>", name);
    1208           0 :                 return;
    1209             :         }
    1210           0 :         ndr->print(ndr, "%-25s: %"PRId32, name, v);
    1211             : }
    1212             : 
    1213         696 : _PUBLIC_ void ndr_print_uint3264(struct ndr_print *ndr, const char *name, uint32_t v)
    1214             : {
    1215         696 :         if (NDR_HIDE_SECRET(ndr)) {
    1216           0 :                 ndr->print(ndr, "%-25s: <REDACTED SECRET VALUE>", name);
    1217           0 :                 return;
    1218             :         }
    1219         696 :         ndr->print(ndr, "%-25s: 0x%08"PRIx32" (%"PRIu32")", name, v, v);
    1220             : }
    1221             : 
    1222          24 : _PUBLIC_ void ndr_print_udlong(struct ndr_print *ndr, const char *name, uint64_t v)
    1223             : {
    1224          24 :         ndr->print(ndr, "%-25s: 0x%016"PRIx64" (%"PRIu64")", name, v, v);
    1225          24 : }
    1226             : 
    1227           0 : _PUBLIC_ void ndr_print_udlongr(struct ndr_print *ndr, const char *name, uint64_t v)
    1228             : {
    1229           0 :         ndr_print_udlong(ndr, name, v);
    1230           0 : }
    1231             : 
    1232      221024 : _PUBLIC_ void ndr_print_dlong(struct ndr_print *ndr, const char *name, int64_t v)
    1233             : {
    1234      221024 :         if (NDR_HIDE_SECRET(ndr)) {
    1235           0 :                 ndr->print(ndr, "%-25s: <REDACTED SECRET VALUE>", name);
    1236           0 :                 return;
    1237             :         }
    1238      221024 :         ndr->print(ndr, "%-25s: 0x%016"PRIx64" (%"PRId64")", name, v, v);
    1239             : }
    1240             : 
    1241           0 : _PUBLIC_ void ndr_print_double(struct ndr_print *ndr, const char *name, double v)
    1242             : {
    1243           0 :         ndr->print(ndr, "%-25s: %f", name, v);
    1244           0 : }
    1245             : 
    1246      221016 : _PUBLIC_ void ndr_print_hyper(struct ndr_print *ndr, const char *name, uint64_t v)
    1247             : {
    1248      221016 :         ndr_print_dlong(ndr, name, v);
    1249      221016 : }
    1250             : 
    1251           0 : _PUBLIC_ void ndr_print_int64(struct ndr_print *ndr, const char *name, int64_t v)
    1252             : {
    1253           0 :         ndr_print_dlong(ndr, name, v);
    1254           0 : }
    1255             : 
    1256           0 : _PUBLIC_ void ndr_print_pointer(struct ndr_print *ndr, const char *name, void *v)
    1257             : {
    1258           0 :         ndr->print(ndr, "%-25s: %p", name, v);
    1259           0 : }
    1260             : 
    1261      648264 : _PUBLIC_ void ndr_print_ptr(struct ndr_print *ndr, const char *name, const void *p)
    1262             : {
    1263      648264 :         if (p) {
    1264      621758 :                 ndr->print(ndr, "%-25s: *", name);
    1265             :         } else {
    1266       26506 :                 ndr->print(ndr, "%-25s: NULL", name);
    1267             :         }
    1268      648264 : }
    1269             : 
    1270      245274 : _PUBLIC_ void ndr_print_NTTIME(struct ndr_print *ndr, const char *name, NTTIME t)
    1271             : {
    1272      245274 :         ndr->print(ndr, "%-25s: %s", name, nt_time_string(ndr, t));
    1273      245274 : }
    1274             : 
    1275      213396 : _PUBLIC_ void ndr_print_NTTIME_1sec(struct ndr_print *ndr, const char *name, NTTIME t)
    1276             : {
    1277             :         /* this is a standard NTTIME here
    1278             :          * as it's already converted in the pull/push code
    1279             :          */
    1280      213396 :         ndr_print_NTTIME(ndr, name, t);
    1281      213396 : }
    1282             : 
    1283         136 : _PUBLIC_ void ndr_print_NTTIME_hyper(struct ndr_print *ndr, const char *name, NTTIME t)
    1284             : {
    1285         136 :         ndr_print_NTTIME(ndr, name, t);
    1286         136 : }
    1287             : 
    1288        3438 : _PUBLIC_ void ndr_print_time_t(struct ndr_print *ndr, const char *name, time_t t)
    1289             : {
    1290        3438 :         if (t == (time_t)-1 || t == 0) {
    1291        3420 :                 ndr->print(ndr, "%-25s: (time_t)%d", name, (int)t);
    1292             :         } else {
    1293          18 :                 ndr->print(ndr, "%-25s: %s", name, timestring(ndr, t));
    1294             :         }
    1295        3438 : }
    1296             : 
    1297           0 : _PUBLIC_ void ndr_print_uid_t(struct ndr_print *ndr, const char *name, uid_t u)
    1298             : {
    1299           0 :         ndr_print_dlong(ndr, name, u);
    1300           0 : }
    1301             : 
    1302           0 : _PUBLIC_ void ndr_print_gid_t(struct ndr_print *ndr, const char *name, gid_t g)
    1303             : {
    1304           0 :         ndr_print_dlong(ndr, name, g);
    1305           0 : }
    1306             : 
    1307       27646 : _PUBLIC_ void ndr_print_union(struct ndr_print *ndr, const char *name, int level, const char *type)
    1308             : {
    1309       27646 :         if (ndr->flags & LIBNDR_PRINT_ARRAY_HEX) {
    1310          89 :                 ndr->print(ndr, "%-25s: union %s(case 0x%X)", name, type, level);
    1311             :         } else {
    1312       27557 :                 ndr->print(ndr, "%-25s: union %s(case %d)", name, type, level);
    1313             :         }
    1314       27646 : }
    1315             : 
    1316           0 : _PUBLIC_ void ndr_print_bad_level(struct ndr_print *ndr, const char *name, uint16_t level)
    1317             : {
    1318           0 :         ndr->print(ndr, "UNKNOWN LEVEL %"PRIu16, level);
    1319           0 : }
    1320             : 
    1321       18187 : _PUBLIC_ void ndr_print_array_uint8(struct ndr_print *ndr, const char *name,
    1322             :                            const uint8_t *data, uint32_t count)
    1323             : {
    1324        2296 :         uint32_t i;
    1325             : #define _ONELINE_LIMIT 32
    1326             : 
    1327       18187 :         if (data == NULL) {
    1328           0 :                 ndr->print(ndr, "%s: ARRAY(%"PRIu32") : NULL", name, count);
    1329           0 :                 return;
    1330             :         }
    1331             : 
    1332       18187 :         if (NDR_HIDE_SECRET(ndr)) {
    1333        7771 :                 ndr->print(ndr, "%s: ARRAY(%"PRIu32"): <REDACTED SECRET VALUES>", name, count);
    1334        7771 :                 return;
    1335             :         }
    1336             : 
    1337       10416 :         if (count <= _ONELINE_LIMIT && (ndr->flags & LIBNDR_PRINT_ARRAY_HEX)) {
    1338             :                 char s[(_ONELINE_LIMIT + 1) * 2];
    1339       90674 :                 for (i=0;i<count;i++) {
    1340       81036 :                         snprintf(&s[i*2], 3, "%02"PRIx8, data[i]);
    1341             :                 }
    1342        9638 :                 s[i*2] = 0;
    1343        9638 :                 ndr->print(ndr, "%-25s: %s", name, s);
    1344        9638 :                 return;
    1345             :         }
    1346             : 
    1347         778 :         ndr->print(ndr, "%s: ARRAY(%"PRIu32")", name, count);
    1348         778 :         if (count > _ONELINE_LIMIT && (ndr->flags & LIBNDR_PRINT_ARRAY_HEX)) {
    1349           8 :                 ndr_dump_data(ndr, data, count);
    1350           8 :                 return;
    1351             :         }
    1352             : 
    1353         770 :         ndr->depth++;
    1354      465794 :         for (i=0;i<count;i++) {
    1355      465024 :                 char *idx=NULL;
    1356      465024 :                 if (asprintf(&idx, "[%"PRIu32"]", i) != -1) {
    1357      465024 :                         ndr_print_uint8(ndr, idx, data[i]);
    1358      465024 :                         free(idx);
    1359             :                 }
    1360             :         }
    1361         770 :         ndr->depth--;
    1362             : #undef _ONELINE_LIMIT
    1363             : }
    1364             : 
    1365    32994095 : static void ndr_print_dump_data_cb(const char *buf, void *private_data)
    1366             : {
    1367    32994095 :         struct ndr_print *ndr = (struct ndr_print *)private_data;
    1368             : 
    1369    32994095 :         ndr->print(ndr, "%s", buf);
    1370    32994095 : }
    1371             : 
    1372             : /*
    1373             :   ndr_print version of dump_data()
    1374             :  */
    1375      191245 : static void ndr_dump_data(struct ndr_print *ndr, const uint8_t *buf, int len)
    1376             : {
    1377      191245 :         if (NDR_HIDE_SECRET(ndr)) {
    1378           6 :                 return;
    1379             :         }
    1380      191239 :         ndr->no_newline = true;
    1381      191239 :         dump_data_cb(buf, len, true, ndr_print_dump_data_cb, ndr);
    1382      191239 :         ndr->no_newline = false;
    1383             : }
    1384             : 
    1385             : 
    1386      197485 : _PUBLIC_ void ndr_print_DATA_BLOB(struct ndr_print *ndr, const char *name, DATA_BLOB r)
    1387             : {
    1388      197485 :         ndr->print(ndr, "%-25s: DATA_BLOB length=%zu", name, r.length);
    1389      197485 :         if (r.length) {
    1390      191237 :                 ndr_dump_data(ndr, r.data, r.length);
    1391             :         }
    1392      197485 : }
    1393             : 
    1394             : 
    1395             : /*
    1396             :  * Push a DATA_BLOB onto the wire.
    1397             :  * 1) When called with LIBNDR_FLAG_ALIGN* alignment flags set, push padding
    1398             :  *    bytes _only_. The length is determined by the alignment required and the
    1399             :  *    current ndr offset.
    1400             :  * 2) When called with the LIBNDR_FLAG_REMAINING flag, push the byte array to
    1401             :  *    the ndr buffer.
    1402             :  * 3) Otherwise, push a uint3264 length _and_ a corresponding byte array to the
    1403             :  *    ndr buffer.
    1404             :  */
    1405   104481823 : _PUBLIC_ enum ndr_err_code ndr_push_DATA_BLOB(struct ndr_push *ndr, ndr_flags_type ndr_flags, DATA_BLOB blob)
    1406             : {
    1407   104481823 :         if (ndr->flags & LIBNDR_FLAG_REMAINING) {
    1408             :                 /* nothing to do */
    1409    95313696 :         } else if (ndr->flags & (LIBNDR_ALIGN_FLAGS & ~LIBNDR_FLAG_NOALIGN)) {
    1410      336735 :                 if (ndr->flags & LIBNDR_FLAG_ALIGN2) {
    1411          60 :                         blob.length = NDR_ALIGN(ndr, 2);
    1412      336675 :                 } else if (ndr->flags & LIBNDR_FLAG_ALIGN4) {
    1413      275537 :                         blob.length = NDR_ALIGN(ndr, 4);
    1414       61138 :                 } else if (ndr->flags & LIBNDR_FLAG_ALIGN8) {
    1415       61138 :                         blob.length = NDR_ALIGN(ndr, 8);
    1416             :                 }
    1417      336735 :                 NDR_PUSH_ALLOC_SIZE(ndr, blob.data, blob.length);
    1418      336735 :                 data_blob_clear(&blob);
    1419             :         } else {
    1420    94976961 :                 NDR_CHECK(ndr_push_uint3264(ndr, NDR_SCALARS, blob.length));
    1421             :         }
    1422   104481823 :         NDR_CHECK(ndr_push_bytes(ndr, blob.data, blob.length));
    1423   104377617 :         return NDR_ERR_SUCCESS;
    1424             : }
    1425             : 
    1426             : /*
    1427             :  * Pull a DATA_BLOB from the wire.
    1428             :  * 1) when called with LIBNDR_FLAG_ALIGN* alignment flags set, pull padding
    1429             :  *    bytes _only_. The length is determined by the alignment required and the
    1430             :  *    current ndr offset.
    1431             :  * 2) When called with the LIBNDR_FLAG_REMAINING flag, pull all remaining bytes
    1432             :  *    from the ndr buffer.
    1433             :  * 3) Otherwise, pull a uint3264 length _and_ a corresponding byte array from the
    1434             :  *    ndr buffer.
    1435             :  */
    1436   126938614 : _PUBLIC_ enum ndr_err_code ndr_pull_DATA_BLOB(struct ndr_pull *ndr, ndr_flags_type ndr_flags, DATA_BLOB *blob)
    1437             : {
    1438   126938614 :         uint32_t length = 0;
    1439             : 
    1440   126938614 :         if (ndr->flags & LIBNDR_FLAG_REMAINING) {
    1441    10022357 :                 length = ndr->data_size - ndr->offset;
    1442   116916257 :         } else if (ndr->flags & (LIBNDR_ALIGN_FLAGS & ~LIBNDR_FLAG_NOALIGN)) {
    1443      283556 :                 if (ndr->flags & LIBNDR_FLAG_ALIGN2) {
    1444          62 :                         length = NDR_ALIGN(ndr, 2);
    1445      283494 :                 } else if (ndr->flags & LIBNDR_FLAG_ALIGN4) {
    1446      227414 :                         length = NDR_ALIGN(ndr, 4);
    1447       56080 :                 } else if (ndr->flags & LIBNDR_FLAG_ALIGN8) {
    1448       56080 :                         length = NDR_ALIGN(ndr, 8);
    1449             :                 }
    1450      283556 :                 if (ndr->data_size - ndr->offset < length) {
    1451           0 :                         length = ndr->data_size - ndr->offset;
    1452             :                 }
    1453             :         } else {
    1454   116632701 :                 NDR_CHECK(ndr_pull_uint3264(ndr, NDR_SCALARS, &length));
    1455             :         }
    1456   126938614 :         if (length == 0) {
    1457             :                 /* skip the talloc for an empty blob */
    1458      847253 :                 blob->data = NULL;
    1459      847253 :                 blob->length = 0;
    1460      847253 :                 return NDR_ERR_SUCCESS;
    1461             :         }
    1462   126091361 :         NDR_PULL_NEED_BYTES(ndr, length);
    1463   126091359 :         *blob = data_blob_talloc(ndr->current_mem_ctx, ndr->data+ndr->offset, length);
    1464   126091359 :         ndr->offset += length;
    1465   126091359 :         return NDR_ERR_SUCCESS;
    1466             : }
    1467             : 
    1468    89685991 : _PUBLIC_ uint32_t ndr_size_DATA_BLOB(int ret, const DATA_BLOB *data, ndr_flags_type flags)
    1469             : {
    1470    89685991 :         if (!data) return ret;
    1471    89685990 :         return ret + data->length;
    1472             : }
    1473             : 
    1474           0 : _PUBLIC_ void ndr_print_bool(struct ndr_print *ndr, const char *name, const bool b)
    1475             : {
    1476           0 :         ndr->print(ndr, "%-25s: %s", name, b?"true":"false");
    1477           0 : }
    1478             : 
    1479   346076197 : _PUBLIC_ NTSTATUS ndr_map_error2ntstatus(enum ndr_err_code ndr_err)
    1480             : {
    1481   346076197 :         switch (ndr_err) {
    1482   346076089 :         case NDR_ERR_SUCCESS:
    1483   346076103 :                 return NT_STATUS_OK;
    1484          14 :         case NDR_ERR_BUFSIZE:
    1485          14 :                 return NT_STATUS_BUFFER_TOO_SMALL;
    1486           0 :         case NDR_ERR_TOKEN:
    1487           0 :                 return NT_STATUS_INTERNAL_ERROR;
    1488           0 :         case NDR_ERR_ALLOC:
    1489           0 :                 return NT_STATUS_NO_MEMORY;
    1490           0 :         case NDR_ERR_ARRAY_SIZE:
    1491           0 :                 return NT_STATUS_ARRAY_BOUNDS_EXCEEDED;
    1492           2 :         case NDR_ERR_INVALID_POINTER:
    1493           2 :                 return NT_STATUS_INVALID_PARAMETER_MIX;
    1494           0 :         case NDR_ERR_UNREAD_BYTES:
    1495           0 :                 return NT_STATUS_PORT_MESSAGE_TOO_LONG;
    1496          92 :         default:
    1497          92 :                 break;
    1498             :         }
    1499             : 
    1500             :         /* we should map all error codes to different status codes */
    1501          92 :         return NT_STATUS_INVALID_PARAMETER;
    1502             : }
    1503             : 
    1504           0 : _PUBLIC_ int ndr_map_error2errno(enum ndr_err_code ndr_err)
    1505             : {
    1506           0 :         switch (ndr_err) {
    1507           0 :         case NDR_ERR_SUCCESS:
    1508           0 :                 return 0;
    1509           0 :         case NDR_ERR_BUFSIZE:
    1510           0 :                 return ENOSPC;
    1511           0 :         case NDR_ERR_TOKEN:
    1512           0 :                 return EINVAL;
    1513           0 :         case NDR_ERR_ALLOC:
    1514           0 :                 return ENOMEM;
    1515           0 :         case NDR_ERR_ARRAY_SIZE:
    1516           0 :                 return EMSGSIZE;
    1517           0 :         case NDR_ERR_INVALID_POINTER:
    1518           0 :                 return EINVAL;
    1519           0 :         case NDR_ERR_UNREAD_BYTES:
    1520           0 :                 return EOVERFLOW;
    1521           0 :         default:
    1522           0 :                 break;
    1523             :         }
    1524             : 
    1525             :         /* we should map all error codes to different status codes */
    1526           0 :         return EINVAL;
    1527             : }
    1528             : 
    1529        6720 : _PUBLIC_ enum ndr_err_code ndr_push_timespec(struct ndr_push *ndr,
    1530             :                                              ndr_flags_type ndr_flags,
    1531             :                                              const struct timespec *t)
    1532             : {
    1533        6720 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
    1534        6720 :         NDR_CHECK(ndr_push_hyper(ndr, ndr_flags, t->tv_sec));
    1535        6720 :         NDR_CHECK(ndr_push_uint32(ndr, ndr_flags, t->tv_nsec));
    1536        6720 :         return NDR_ERR_SUCCESS;
    1537             : }
    1538             : 
    1539        2608 : _PUBLIC_ enum ndr_err_code ndr_pull_timespec(struct ndr_pull *ndr,
    1540             :                                              ndr_flags_type ndr_flags,
    1541             :                                              struct timespec *t)
    1542             : {
    1543        2608 :         uint64_t secs = 0;
    1544        2608 :         uint32_t nsecs = 0;
    1545        2608 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
    1546        2608 :         NDR_CHECK(ndr_pull_hyper(ndr, ndr_flags, &secs));
    1547        2608 :         NDR_CHECK(ndr_pull_uint32(ndr, ndr_flags, &nsecs));
    1548        2608 :         t->tv_sec = secs;
    1549        2608 :         t->tv_nsec = nsecs;
    1550        2608 :         return NDR_ERR_SUCCESS;
    1551             : }
    1552             : 
    1553           0 : _PUBLIC_ void ndr_print_timespec(struct ndr_print *ndr, const char *name,
    1554             :                                  const struct timespec *t)
    1555             : {
    1556           0 :         char *str = timestring(ndr, t->tv_sec);
    1557           0 :         ndr->print(ndr, "%-25s: %s.%ld", name, str, t->tv_nsec);
    1558           0 :         TALLOC_FREE(str);
    1559           0 : }
    1560             : 
    1561      955046 : _PUBLIC_ enum ndr_err_code ndr_push_timeval(struct ndr_push *ndr,
    1562             :                                             ndr_flags_type ndr_flags,
    1563             :                                             const struct timeval *t)
    1564             : {
    1565      955046 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
    1566      955046 :         NDR_CHECK(ndr_push_hyper(ndr, ndr_flags, t->tv_sec));
    1567      955046 :         NDR_CHECK(ndr_push_uint32(ndr, ndr_flags, t->tv_usec));
    1568      952878 :         return NDR_ERR_SUCCESS;
    1569             : }
    1570             : 
    1571     2027138 : _PUBLIC_ enum ndr_err_code ndr_pull_timeval(struct ndr_pull *ndr,
    1572             :                                             ndr_flags_type ndr_flags,
    1573             :                                             struct timeval *t)
    1574             : {
    1575     2027138 :         uint64_t secs = 0;
    1576     2027138 :         uint32_t usecs = 0;
    1577     2027138 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
    1578     2027138 :         NDR_CHECK(ndr_pull_hyper(ndr, ndr_flags, &secs));
    1579     2027138 :         NDR_CHECK(ndr_pull_uint32(ndr, ndr_flags, &usecs));
    1580     2027138 :         t->tv_sec = secs;
    1581     2027138 :         t->tv_usec = usecs;
    1582     2027138 :         return NDR_ERR_SUCCESS;
    1583             : }
    1584             : 
    1585           0 : _PUBLIC_ void ndr_print_timeval(struct ndr_print *ndr, const char *name,
    1586             :                                 const struct timeval *t)
    1587             : {
    1588           0 :         ndr->print(ndr, "%-25s: %s.%ld", name, timestring(ndr, t->tv_sec),
    1589           0 :                    (long)t->tv_usec);
    1590           0 : }
    1591             : 
    1592          26 : _PUBLIC_ void ndr_print_libndr_flags(struct ndr_print *ndr, const char *name,
    1593             :                                        libndr_flags flags)
    1594             : {
    1595          26 :         ndr->print(ndr, "%-25s: 0x%016"PRI_LIBNDR_FLAGS" (%"PRI_LIBNDR_FLAGS_DECIMAL")", name, flags, flags);
    1596          26 : }

Generated by: LCOV version 1.14