LCOV - code coverage report
Current view: top level - librpc/ndr - ndr_basic.c (source / functions) Hit Total Coverage
Test: coverage report for v4-17-test 1498b464 Lines: 511 715 71.5 %
Date: 2024-06-13 04:01: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   163841308 : _PUBLIC_ enum ndr_err_code ndr_pull_int8(struct ndr_pull *ndr, int ndr_flags, int8_t *v)
      96             : {
      97   163841308 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
      98   163841308 :         NDR_PULL_NEED_BYTES(ndr, 1);
      99   163841308 :         *v = (int8_t)PULL_BE_U8(ndr->data, ndr->offset);
     100   163841308 :         ndr->offset += 1;
     101   163841308 :         return NDR_ERR_SUCCESS;
     102             : }
     103             : 
     104             : /*
     105             :   parse a uint8_t
     106             : */
     107   462609718 : _PUBLIC_ enum ndr_err_code ndr_pull_uint8(struct ndr_pull *ndr, int ndr_flags, uint8_t *v)
     108             : {
     109   462609718 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     110   462609718 :         NDR_PULL_NEED_BYTES(ndr, 1);
     111   462609718 :         *v = PULL_BE_U8(ndr->data, ndr->offset);
     112   462609718 :         ndr->offset += 1;
     113   462609718 :         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   930327998 : _PUBLIC_ enum ndr_err_code ndr_pull_uint16(struct ndr_pull *ndr, int ndr_flags, uint16_t *v)
     133             : {
     134   930327998 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     135   930327998 :         NDR_PULL_ALIGN(ndr, 2);
     136   930327998 :         NDR_PULL_NEED_BYTES(ndr, 2);
     137   930327998 :         *v = NDR_PULL_U16(ndr, ndr->offset);
     138   930327998 :         ndr->offset += 2;
     139   930327998 :         return NDR_ERR_SUCCESS;
     140             : }
     141             : 
     142             : /*
     143             :   parse a uint1632_t
     144             : */
     145       34017 : _PUBLIC_ enum ndr_err_code ndr_pull_uint1632(struct ndr_pull *ndr, int ndr_flags, uint16_t *v)
     146             : {
     147       34017 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     148       34017 :         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       34017 :         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  1357054835 : _PUBLIC_ enum ndr_err_code ndr_pull_uint32(struct ndr_pull *ndr, int ndr_flags, uint32_t *v)
     178             : {
     179  1357054835 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     180  1357054835 :         NDR_PULL_ALIGN(ndr, 4);
     181  1357054835 :         NDR_PULL_NEED_BYTES(ndr, 4);
     182  1357054789 :         *v = NDR_PULL_U32(ndr, ndr->offset);
     183  1357054789 :         ndr->offset += 4;
     184  1357054789 :         return NDR_ERR_SUCCESS;
     185             : }
     186             : 
     187             : /*
     188             :   parse a arch dependent uint32/uint64
     189             : */
     190   102011480 : _PUBLIC_ enum ndr_err_code ndr_pull_uint3264(struct ndr_pull *ndr, int ndr_flags, uint32_t *v)
     191             : {
     192   102011480 :         uint64_t v64 = 0;
     193             :         enum ndr_err_code err;
     194   102011480 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     195   102011480 :         if (likely(!(ndr->flags & LIBNDR_FLAG_NDR64))) {
     196   102011480 :                 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      381294 : _PUBLIC_ enum ndr_err_code ndr_pull_relative_ptr_short(struct ndr_pull *ndr, uint16_t *v)
     229             : {
     230      381294 :         NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, v));
     231      381294 :         if (*v != 0) {
     232      381282 :                 ndr->ptr_count++;
     233             :         }
     234      381294 :         *(v) -= ndr->relative_rap_convert;
     235      381294 :         return NDR_ERR_SUCCESS;
     236             : }
     237             : 
     238             : /*
     239             :   parse a pointer referent identifier
     240             : */
     241    61622177 : _PUBLIC_ enum ndr_err_code ndr_pull_generic_ptr(struct ndr_pull *ndr, uint32_t *v)
     242             : {
     243    61622177 :         NDR_CHECK(ndr_pull_uint3264(ndr, NDR_SCALARS, v));
     244    61622177 :         if (*v != 0) {
     245    56598616 :                 ndr->ptr_count++;
     246             :         }
     247    61622177 :         return NDR_ERR_SUCCESS;
     248             : }
     249             : 
     250             : /*
     251             :   parse a ref pointer referent identifier
     252             : */
     253       28627 : _PUBLIC_ enum ndr_err_code ndr_pull_ref_ptr(struct ndr_pull *ndr, uint32_t *v)
     254             : {
     255       28627 :         NDR_CHECK(ndr_pull_uint3264(ndr, NDR_SCALARS, v));
     256             :         /* ref pointers always point to data */
     257       28627 :         *v = 1;
     258       28627 :         return NDR_ERR_SUCCESS;
     259             : }
     260             : 
     261             : /*
     262             :   parse a udlong
     263             : */
     264   241245795 : _PUBLIC_ enum ndr_err_code ndr_pull_udlong(struct ndr_pull *ndr, int ndr_flags, uint64_t *v)
     265             : {
     266   241245795 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     267   241245795 :         NDR_PULL_ALIGN(ndr, 4);
     268   241245795 :         NDR_PULL_NEED_BYTES(ndr, 8);
     269   241245785 :         *v = NDR_PULL_U32(ndr, ndr->offset);
     270   241245785 :         *v |= (uint64_t)(NDR_PULL_U32(ndr, ndr->offset+4)) << 32;
     271   241245785 :         ndr->offset += 8;
     272   241245785 :         return NDR_ERR_SUCCESS;
     273             : }
     274             : 
     275             : /*
     276             :   parse a udlongr
     277             : */
     278       12907 : _PUBLIC_ enum ndr_err_code ndr_pull_udlongr(struct ndr_pull *ndr, int ndr_flags, uint64_t *v)
     279             : {
     280       12907 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     281       12907 :         NDR_PULL_ALIGN(ndr, 4);
     282       12907 :         NDR_PULL_NEED_BYTES(ndr, 8);
     283       12907 :         *v = ((uint64_t)NDR_PULL_U32(ndr, ndr->offset)) << 32;
     284       12907 :         *v |= NDR_PULL_U32(ndr, ndr->offset+4);
     285       12907 :         ndr->offset += 8;
     286       12907 :         return NDR_ERR_SUCCESS;
     287             : }
     288             : 
     289             : /*
     290             :   parse a dlong
     291             : */
     292         690 : _PUBLIC_ enum ndr_err_code ndr_pull_dlong(struct ndr_pull *ndr, int ndr_flags, int64_t *v)
     293             : {
     294         690 :         return ndr_pull_udlong(ndr, ndr_flags, (uint64_t *)v);
     295             : }
     296             : 
     297             : /*
     298             :   parse a hyper
     299             : */
     300   236575398 : _PUBLIC_ enum ndr_err_code ndr_pull_hyper(struct ndr_pull *ndr, int ndr_flags, uint64_t *v)
     301             : {
     302   236575398 :         NDR_PULL_ALIGN(ndr, 8);
     303   236575398 :         if (NDR_BE(ndr)) {
     304        7433 :                 return ndr_pull_udlongr(ndr, ndr_flags, v);
     305             :         }
     306   236567965 :         return ndr_pull_udlong(ndr, ndr_flags, v);
     307             : }
     308             : 
     309             : /*
     310             :   parse a pointer
     311             : */
     312      629257 : _PUBLIC_ enum ndr_err_code ndr_pull_pointer(struct ndr_pull *ndr, int ndr_flags, void* *v)
     313             : {
     314             :         uintptr_t h;
     315      629257 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     316      629257 :         NDR_PULL_ALIGN(ndr, sizeof(h));
     317      629257 :         NDR_PULL_NEED_BYTES(ndr, sizeof(h));
     318      629257 :         memcpy(&h, ndr->data+ndr->offset, sizeof(h));
     319      629257 :         ndr->offset += sizeof(h);
     320      629257 :         *v = (void *)h;
     321      629257 :         return NDR_ERR_SUCCESS;
     322             : }
     323             : 
     324             : /*
     325             :   pull a NTSTATUS
     326             : */
     327      130707 : _PUBLIC_ enum ndr_err_code ndr_pull_NTSTATUS(struct ndr_pull *ndr, int ndr_flags, NTSTATUS *status)
     328             : {
     329             :         uint32_t v;
     330      130707 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     331      130707 :         NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &v));
     332      130707 :         *status = NT_STATUS(v);
     333      130707 :         return NDR_ERR_SUCCESS;
     334             : }
     335             : 
     336             : /*
     337             :   push a NTSTATUS
     338             : */
     339      749499 : _PUBLIC_ enum ndr_err_code ndr_push_NTSTATUS(struct ndr_push *ndr, int ndr_flags, NTSTATUS status)
     340             : {
     341      749499 :         return ndr_push_uint32(ndr, ndr_flags, NT_STATUS_V(status));
     342             : }
     343             : 
     344       18424 : _PUBLIC_ void ndr_print_NTSTATUS(struct ndr_print *ndr, const char *name, NTSTATUS r)
     345             : {
     346       18424 :         ndr->print(ndr, "%-25s: %s", name, nt_errstr(r));
     347       18424 : }
     348             : 
     349             : /*
     350             :   pull a WERROR
     351             : */
     352      168476 : _PUBLIC_ enum ndr_err_code ndr_pull_WERROR(struct ndr_pull *ndr, int ndr_flags, WERROR *status)
     353             : {
     354             :         uint32_t v;
     355      168476 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     356      168476 :         NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &v));
     357      168476 :         *status = W_ERROR(v);
     358      168476 :         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   146936883 : _PUBLIC_ enum ndr_err_code ndr_pull_enum_uint8(struct ndr_pull *ndr, int ndr_flags, uint8_t *v)
     377             : {
     378   146936883 :         return ndr_pull_uint8(ndr, ndr_flags, v);
     379             : }
     380             : 
     381             : /*
     382             :   parse a uint16_t enum
     383             : */
     384      784159 : _PUBLIC_ enum ndr_err_code ndr_pull_enum_uint16(struct ndr_pull *ndr, int ndr_flags, uint16_t *v)
     385             : {
     386      784159 :         return ndr_pull_uint16(ndr, ndr_flags, v);
     387             : }
     388             : 
     389             : /*
     390             :   parse a uint1632_t enum (uint32_t on NDR64)
     391             : */
     392    14750690 : _PUBLIC_ enum ndr_err_code ndr_pull_enum_uint1632(struct ndr_pull *ndr, int ndr_flags, uint16_t *v)
     393             : {
     394    14750690 :         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    14750690 :         return ndr_pull_uint16(ndr, ndr_flags, v);
     405             : }
     406             : 
     407             : /*
     408             :   parse a uint32_t enum
     409             : */
     410    85170866 : _PUBLIC_ enum ndr_err_code ndr_pull_enum_uint32(struct ndr_pull *ndr, int ndr_flags, uint32_t *v)
     411             : {
     412    85170866 :         return ndr_pull_uint32(ndr, ndr_flags, v);
     413             : }
     414             : 
     415             : /*
     416             :   push a uint8_t enum
     417             : */
     418    47034572 : _PUBLIC_ enum ndr_err_code ndr_push_enum_uint8(struct ndr_push *ndr, int ndr_flags, uint8_t v)
     419             : {
     420    47034572 :         return ndr_push_uint8(ndr, ndr_flags, v);
     421             : }
     422             : 
     423             : /*
     424             :   push a uint16_t enum
     425             : */
     426     1043117 : _PUBLIC_ enum ndr_err_code ndr_push_enum_uint16(struct ndr_push *ndr, int ndr_flags, uint16_t v)
     427             : {
     428     1043117 :         return ndr_push_uint16(ndr, ndr_flags, v);
     429             : }
     430             : 
     431             : /*
     432             :   push a uint32_t enum
     433             : */
     434    88317963 : _PUBLIC_ enum ndr_err_code ndr_push_enum_uint32(struct ndr_push *ndr, int ndr_flags, uint32_t v)
     435             : {
     436    88317963 :         return ndr_push_uint32(ndr, ndr_flags, v);
     437             : }
     438             : 
     439             : /*
     440             :   push a uint1632_t enum
     441             : */
     442     6883570 : _PUBLIC_ enum ndr_err_code ndr_push_enum_uint1632(struct ndr_push *ndr, int ndr_flags, uint16_t v)
     443             : {
     444     6883570 :         if (unlikely(ndr->flags & LIBNDR_FLAG_NDR64)) {
     445           0 :                 return ndr_push_uint32(ndr, ndr_flags, v);
     446             :         }
     447     6883570 :         return ndr_push_uint16(ndr, ndr_flags, v);
     448             : }
     449             : 
     450             : /*
     451             :   push a WERROR
     452             : */
     453     1055308 : _PUBLIC_ enum ndr_err_code ndr_push_WERROR(struct ndr_push *ndr, int ndr_flags, WERROR status)
     454             : {
     455     1055308 :         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   904086990 : _PUBLIC_ enum ndr_err_code ndr_pull_bytes(struct ndr_pull *ndr, uint8_t *data, uint32_t n)
     481             : {
     482   904086990 :         NDR_PULL_NEED_BYTES(ndr, n);
     483   904086990 :         memcpy(data, ndr->data + ndr->offset, n);
     484   904086990 :         ndr->offset += n;
     485   904086990 :         return NDR_ERR_SUCCESS;
     486             : }
     487             : 
     488             : /*
     489             :   pull an array of uint8
     490             : */
     491   902768446 : _PUBLIC_ enum ndr_err_code ndr_pull_array_uint8(struct ndr_pull *ndr, int ndr_flags, uint8_t *data, uint32_t n)
     492             : {
     493   902768446 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     494   902768446 :         if (!(ndr_flags & NDR_SCALARS)) {
     495           0 :                 return NDR_ERR_SUCCESS;
     496             :         }
     497   902768446 :         return ndr_pull_bytes(ndr, data, n);
     498             : }
     499             : 
     500             : /*
     501             :   push a int8_t
     502             : */
     503    65602928 : _PUBLIC_ enum ndr_err_code ndr_push_int8(struct ndr_push *ndr, int ndr_flags, int8_t v)
     504             : {
     505    65602928 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
     506    65602928 :         NDR_PUSH_NEED_BYTES(ndr, 1);
     507    65602928 :         PUSH_BE_U8(ndr->data, ndr->offset, (uint8_t)v);
     508    65602928 :         ndr->offset += 1;
     509    65602928 :         return NDR_ERR_SUCCESS;
     510             : }
     511             : 
     512             : /*
     513             :   push a uint8_t
     514             : */
     515   521189474 : _PUBLIC_ enum ndr_err_code ndr_push_uint8(struct ndr_push *ndr, int ndr_flags, uint8_t v)
     516             : {
     517   521189474 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
     518   521189474 :         NDR_PUSH_NEED_BYTES(ndr, 1);
     519   521189474 :         PUSH_BE_U8(ndr->data, ndr->offset, v);
     520   521189474 :         ndr->offset += 1;
     521   521189474 :         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   506714069 : _PUBLIC_ enum ndr_err_code ndr_push_uint16(struct ndr_push *ndr, int ndr_flags, uint16_t v)
     541             : {
     542   506714069 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
     543   506992812 :         NDR_PUSH_ALIGN(ndr, 2);
     544   506714069 :         NDR_PUSH_NEED_BYTES(ndr, 2);
     545   506714069 :         NDR_PUSH_U16(ndr, ndr->offset, v);
     546   506714069 :         ndr->offset += 2;
     547   506714069 :         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       21175 : _PUBLIC_ enum ndr_err_code ndr_push_int32(struct ndr_push *ndr, int ndr_flags, int32_t v)
     565             : {
     566       21175 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
     567       21175 :         NDR_PUSH_ALIGN(ndr, 4);
     568       21175 :         NDR_PUSH_NEED_BYTES(ndr, 4);
     569       21175 :         NDR_PUSH_I32(ndr, ndr->offset, v);
     570       21175 :         ndr->offset += 4;
     571       21175 :         return NDR_ERR_SUCCESS;
     572             : }
     573             : 
     574             : /*
     575             :   push a uint32_t
     576             : */
     577  1232750985 : _PUBLIC_ enum ndr_err_code ndr_push_uint32(struct ndr_push *ndr, int ndr_flags, uint32_t v)
     578             : {
     579  1232750985 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
     580  1234096036 :         NDR_PUSH_ALIGN(ndr, 4);
     581  1232750985 :         NDR_PUSH_NEED_BYTES(ndr, 4);
     582  1232750985 :         NDR_PUSH_U32(ndr, ndr->offset, v);
     583  1232750985 :         ndr->offset += 4;
     584  1232750985 :         return NDR_ERR_SUCCESS;
     585             : }
     586             : 
     587             : /*
     588             :   push a uint3264
     589             : */
     590   366639841 : _PUBLIC_ enum ndr_err_code ndr_push_uint3264(struct ndr_push *ndr, int ndr_flags, uint32_t v)
     591             : {
     592   366639841 :         if (unlikely(ndr->flags & LIBNDR_FLAG_NDR64)) {
     593           0 :                 return ndr_push_hyper(ndr, ndr_flags, v);
     594             :         }
     595   366639841 :         return ndr_push_uint32(ndr, ndr_flags, v);
     596             : }
     597             : 
     598             : /*
     599             :   push a udlong
     600             : */
     601   189651577 : _PUBLIC_ enum ndr_err_code ndr_push_udlong(struct ndr_push *ndr, int ndr_flags, uint64_t v)
     602             : {
     603   189651577 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
     604   189651667 :         NDR_PUSH_ALIGN(ndr, 4);
     605   189651577 :         NDR_PUSH_NEED_BYTES(ndr, 8);
     606   189651577 :         NDR_PUSH_U32(ndr, ndr->offset, (v & 0xFFFFFFFF));
     607   189651577 :         NDR_PUSH_U32(ndr, ndr->offset+4, (v>>32));
     608   189651577 :         ndr->offset += 8;
     609   189651577 :         return NDR_ERR_SUCCESS;
     610             : }
     611             : 
     612             : /*
     613             :   push a udlongr
     614             : */
     615      105228 : _PUBLIC_ enum ndr_err_code ndr_push_udlongr(struct ndr_push *ndr, int ndr_flags, uint64_t v)
     616             : {
     617      105228 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
     618      105228 :         NDR_PUSH_ALIGN(ndr, 4);
     619      105228 :         NDR_PUSH_NEED_BYTES(ndr, 8);
     620      105228 :         NDR_PUSH_U32(ndr, ndr->offset, (v>>32));
     621      105228 :         NDR_PUSH_U32(ndr, ndr->offset+4, (v & 0xFFFFFFFF));
     622      105228 :         ndr->offset += 8;
     623      105228 :         return NDR_ERR_SUCCESS;
     624             : }
     625             : 
     626             : /*
     627             :   push a dlong
     628             : */
     629        1456 : _PUBLIC_ enum ndr_err_code ndr_push_dlong(struct ndr_push *ndr, int ndr_flags, int64_t v)
     630             : {
     631        1456 :         return ndr_push_udlong(ndr, NDR_SCALARS, (uint64_t)v);
     632             : }
     633             : 
     634             : /*
     635             :   push a hyper
     636             : */
     637   186474294 : _PUBLIC_ enum ndr_err_code ndr_push_hyper(struct ndr_push *ndr, int ndr_flags, uint64_t v)
     638             : {
     639   191831792 :         NDR_PUSH_ALIGN(ndr, 8);
     640   186474294 :         if (NDR_BE(ndr)) {
     641       94280 :                 return ndr_push_udlongr(ndr, NDR_SCALARS, v);
     642             :         }
     643   186380014 :         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      476360 : _PUBLIC_ enum ndr_err_code ndr_push_pointer(struct ndr_push *ndr, int ndr_flags, void* v)
     663             : {
     664      476360 :         uintptr_t h = (intptr_t)v;
     665      476360 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
     666      476464 :         NDR_PUSH_ALIGN(ndr, sizeof(h));
     667      476360 :         NDR_PUSH_NEED_BYTES(ndr, sizeof(h));
     668      476360 :         memcpy(ndr->data+ndr->offset, &h, sizeof(h));
     669      476360 :         ndr->offset += sizeof(h);
     670      476360 :         return NDR_ERR_SUCCESS;
     671             : }
     672             : 
     673   712773362 : _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   712773362 :         if (size == 5) {
     677   243535386 :                 if (ndr->flags & LIBNDR_FLAG_NDR64) {
     678           0 :                         size = 8;
     679             :                 } else {
     680   243535386 :                         size = 4;
     681             :                 }
     682   469237976 :         } else if (size == 3) {
     683       99885 :                 if (ndr->flags & LIBNDR_FLAG_NDR64) {
     684           0 :                         size = 4;
     685             :                 } else {
     686       99885 :                         size = 2;
     687             :                 }
     688             :         }
     689   713640871 :         NDR_PUSH_ALIGN(ndr, size);
     690   712773362 :         return NDR_ERR_SUCCESS;
     691             : }
     692             : 
     693   914032641 : _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   914032641 :         if (size == 5) {
     697    40868710 :                 if (ndr->flags & LIBNDR_FLAG_NDR64) {
     698           0 :                         size = 8;
     699             :                 } else {
     700    40868710 :                         size = 4;
     701             :                 }
     702   873163931 :         } else if (size == 3) {
     703      223219 :                 if (ndr->flags & LIBNDR_FLAG_NDR64) {
     704           0 :                         size = 4;
     705             :                 } else {
     706      223219 :                         size = 2;
     707             :                 }
     708             :         }
     709   914032641 :         NDR_PULL_ALIGN(ndr, size);
     710   914032641 :         return NDR_ERR_SUCCESS;
     711             : }
     712             : 
     713    73510677 : _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    73510677 :         if (ndr->flags & LIBNDR_FLAG_NDR64) {
     717           0 :                 return ndr_push_align(ndr, size);
     718             :         }
     719    73510677 :         return NDR_ERR_SUCCESS;
     720             : }
     721             : 
     722   310232993 : _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   310232993 :         if (ndr->flags & LIBNDR_FLAG_NDR64) {
     726           0 :                 return ndr_pull_align(ndr, size);
     727             :         }
     728   310232993 :         return NDR_ERR_SUCCESS;
     729             : }
     730             : 
     731   632904352 : _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   632904352 :         if (ndr->flags & LIBNDR_FLAG_NDR64) {
     735           0 :                 return ndr_push_align(ndr, size);
     736             :         }
     737   632904352 :         return NDR_ERR_SUCCESS;
     738             : }
     739             : 
     740   617618934 : _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   617618934 :         if (ndr->flags & LIBNDR_FLAG_NDR64) {
     744           0 :                 return ndr_pull_align(ndr, size);
     745             :         }
     746   617618934 :         return NDR_ERR_SUCCESS;
     747             : }
     748             : 
     749             : /*
     750             :   push some bytes
     751             : */
     752   596321953 : _PUBLIC_ enum ndr_err_code ndr_push_bytes(struct ndr_push *ndr, const uint8_t *data, uint32_t n)
     753             : {
     754   596321953 :         if (unlikely(n == 0)) {
     755     3485358 :                 return NDR_ERR_SUCCESS;
     756             :         }
     757   592836595 :         if (unlikely(data == NULL)) {
     758           0 :                 return NDR_ERR_INVALID_POINTER;
     759             :         }
     760   592836595 :         NDR_PUSH_NEED_BYTES(ndr, n);
     761   592836595 :         memcpy(ndr->data + ndr->offset, data, n);
     762   592836595 :         ndr->offset += n;
     763   592836595 :         return NDR_ERR_SUCCESS;
     764             : }
     765             : 
     766             : /*
     767             :   push some zero bytes
     768             : */
     769    16023188 : _PUBLIC_ enum ndr_err_code ndr_push_zero(struct ndr_push *ndr, uint32_t n)
     770             : {
     771    16023188 :         NDR_PUSH_NEED_BYTES(ndr, n);
     772    16023188 :         memset(ndr->data + ndr->offset, 0, n);
     773    16023188 :         ndr->offset += n;
     774    16023188 :         return NDR_ERR_SUCCESS;
     775             : }
     776             : 
     777             : /*
     778             :   push an array of uint8
     779             : */
     780   497055825 : _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   497055825 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
     783   497055825 :         if (!(ndr_flags & NDR_SCALARS)) {
     784           0 :                 return NDR_ERR_SUCCESS;
     785             :         }
     786   497055825 :         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   183772132 : _PUBLIC_ enum ndr_err_code ndr_push_unique_ptr(struct ndr_push *ndr, const void *p)
     793             : {
     794   183772132 :         uint32_t ptr = 0;
     795   183772132 :         if (p) {
     796   180505559 :                 ptr = ndr->ptr_count * 4;
     797   180505559 :                 ptr |= 0x00020000;
     798   180505559 :                 ndr->ptr_count++;
     799             :         }
     800   183772132 :         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       58948 : _PUBLIC_ enum ndr_err_code ndr_push_full_ptr(struct ndr_push *ndr, const void *p)
     807             : {
     808       58948 :         enum ndr_err_code ret = NDR_ERR_SUCCESS;
     809       58948 :         uint32_t ptr = 0;
     810       58948 :         if (p) {
     811             :                 /* Check if the pointer already exists and has an id */
     812       58816 :                 ret = ndr_token_peek(&ndr->full_ptr_list, p, &ptr);
     813       58816 :                 if (ret == NDR_ERR_TOKEN) {
     814       58816 :                         ndr->ptr_count++;
     815       58816 :                         ptr = ndr->ptr_count;
     816       58816 :                         ret = ndr_token_store(ndr, &ndr->full_ptr_list, p, ptr);
     817       58816 :                         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       58948 :         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       19377 : _PUBLIC_ enum ndr_err_code ndr_push_ref_ptr(struct ndr_push *ndr)
     831             : {
     832       19377 :         return ndr_push_uint3264(ndr, NDR_SCALARS, 0xAEF1AEF1);
     833             : }
     834             : 
     835             : 
     836             : /*
     837             :   push a NTTIME
     838             : */
     839     2983198 : _PUBLIC_ enum ndr_err_code ndr_push_NTTIME(struct ndr_push *ndr, int ndr_flags, NTTIME t)
     840             : {
     841     2983198 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
     842     2983198 :         NDR_CHECK(ndr_push_udlong(ndr, ndr_flags, t));
     843     2983198 :         return NDR_ERR_SUCCESS;
     844             : }
     845             : 
     846             : /*
     847             :   pull a NTTIME
     848             : */
     849     3915716 : _PUBLIC_ enum ndr_err_code ndr_pull_NTTIME(struct ndr_pull *ndr, int ndr_flags, NTTIME *t)
     850             : {
     851     3915716 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     852     3915716 :         NDR_CHECK(ndr_pull_udlong(ndr, ndr_flags, t));
     853     3915716 :         return NDR_ERR_SUCCESS;
     854             : }
     855             : 
     856             : /*
     857             :   push a NTTIME_1sec
     858             : */
     859    83925499 : _PUBLIC_ enum ndr_err_code ndr_push_NTTIME_1sec(struct ndr_push *ndr, int ndr_flags, NTTIME t)
     860             : {
     861    83925499 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
     862    83925499 :         t /= 10000000;
     863    83925499 :         NDR_CHECK(ndr_push_hyper(ndr, ndr_flags, t));
     864    83925499 :         return NDR_ERR_SUCCESS;
     865             : }
     866             : 
     867             : /*
     868             :   pull a NTTIME_1sec
     869             : */
     870    80521080 : _PUBLIC_ enum ndr_err_code ndr_pull_NTTIME_1sec(struct ndr_pull *ndr, int ndr_flags, NTTIME *t)
     871             : {
     872    80521080 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     873    80521080 :         NDR_CHECK(ndr_pull_hyper(ndr, ndr_flags, t));
     874    80521080 :         (*t) *= 10000000;
     875    80521080 :         return NDR_ERR_SUCCESS;
     876             : }
     877             : 
     878             : /*
     879             :   pull a NTTIME_hyper
     880             : */
     881       11090 : _PUBLIC_ enum ndr_err_code ndr_pull_NTTIME_hyper(struct ndr_pull *ndr, int ndr_flags, NTTIME *t)
     882             : {
     883       11090 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
     884       11090 :         NDR_CHECK(ndr_pull_hyper(ndr, ndr_flags, t));
     885       11090 :         return NDR_ERR_SUCCESS;
     886             : }
     887             : 
     888             : /*
     889             :   push a NTTIME_hyper
     890             : */
     891       12355 : _PUBLIC_ enum ndr_err_code ndr_push_NTTIME_hyper(struct ndr_push *ndr, int ndr_flags, NTTIME t)
     892             : {
     893       12355 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
     894       12355 :         NDR_CHECK(ndr_push_hyper(ndr, ndr_flags, t));
     895       12355 :         return NDR_ERR_SUCCESS;
     896             : }
     897             : 
     898             : /*
     899             :   push a time_t
     900             : */
     901       54812 : _PUBLIC_ enum ndr_err_code ndr_push_time_t(struct ndr_push *ndr, int ndr_flags, time_t t)
     902             : {
     903       54812 :         return ndr_push_uint32(ndr, ndr_flags, t);
     904             : }
     905             : 
     906             : /*
     907             :   pull a time_t
     908             : */
     909       74767 : _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       74767 :         NDR_CHECK(ndr_pull_uint32(ndr, ndr_flags, &tt));
     913       74767 :         *t = tt;
     914       74767 :         return NDR_ERR_SUCCESS;
     915             : }
     916             : 
     917             : 
     918             : /*
     919             :   push a uid_t
     920             : */
     921       88663 : _PUBLIC_ enum ndr_err_code ndr_push_uid_t(struct ndr_push *ndr, int ndr_flags, uid_t u)
     922             : {
     923       88663 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
     924       88663 :         return ndr_push_hyper(ndr, NDR_SCALARS, (uint64_t)u);
     925             : }
     926             : 
     927             : /*
     928             :   pull a uid_t
     929             : */
     930       80464 : _PUBLIC_ enum ndr_err_code ndr_pull_uid_t(struct ndr_pull *ndr, int ndr_flags, uid_t *u)
     931             : {
     932       80464 :         uint64_t uu = 0;
     933       80464 :         NDR_CHECK(ndr_pull_hyper(ndr, ndr_flags, &uu));
     934       80464 :         *u = (uid_t)uu;
     935       80464 :         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       80464 :         return NDR_ERR_SUCCESS;
     941             : }
     942             : 
     943             : 
     944             : /*
     945             :   push a gid_t
     946             : */
     947      573726 : _PUBLIC_ enum ndr_err_code ndr_push_gid_t(struct ndr_push *ndr, int ndr_flags, gid_t g)
     948             : {
     949      573726 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
     950      573726 :         return ndr_push_hyper(ndr, NDR_SCALARS, (uint64_t)g);
     951             : }
     952             : 
     953             : /*
     954             :   pull a gid_t
     955             : */
     956      529338 : _PUBLIC_ enum ndr_err_code ndr_pull_gid_t(struct ndr_pull *ndr, int ndr_flags, gid_t *g)
     957             : {
     958      529338 :         uint64_t gg = 0;
     959      529338 :         NDR_CHECK(ndr_pull_hyper(ndr, ndr_flags, &gg));
     960      529338 :         *g = (gid_t)gg;
     961      529338 :         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      529338 :         return NDR_ERR_SUCCESS;
     967             : }
     968             : 
     969             : 
     970             : /*
     971             :   pull a ipv4address
     972             : */
     973       91834 : _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       91834 :         NDR_CHECK(ndr_pull_uint32(ndr, ndr_flags, &addr));
     978       91834 :         in.s_addr = htonl(addr);
     979       91834 :         *address = talloc_strdup(ndr->current_mem_ctx, inet_ntoa(in));
     980       91834 :         NDR_ERR_HAVE_NO_MEMORY(*address);
     981       91834 :         return NDR_ERR_SUCCESS;
     982             : }
     983             : 
     984             : /*
     985             :   push a ipv4address
     986             : */
     987      152348 : _PUBLIC_ enum ndr_err_code ndr_push_ipv4address(struct ndr_push *ndr, int ndr_flags, const char *address)
     988             : {
     989             :         uint32_t addr;
     990      152348 :         if (!is_ipaddress(address)) {
     991          40 :                 return ndr_push_error(ndr, NDR_ERR_IPV4ADDRESS,
     992             :                                       "Invalid IPv4 address: '%s'",
     993             :                                       address);
     994             :         }
     995      152308 :         addr = inet_addr(address);
     996      152308 :         NDR_CHECK(ndr_push_uint32(ndr, ndr_flags, htonl(addr)));
     997      152308 :         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       44802 : _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       44802 :         char *addr_str = talloc_strdup(ndr->current_mem_ctx, "");
    1018             :         int i;
    1019       44802 :         NDR_CHECK(ndr_pull_array_uint8(ndr, ndr_flags, addr, IPV6_BYTES));
    1020      761634 :         for (i = 0; i < IPV6_BYTES; ++i) {
    1021      716832 :                 addr_str = talloc_asprintf_append(addr_str, "%02x", addr[i]);
    1022             :                 /* We need a ':' every second byte but the last one */
    1023      716832 :                 if (i%2 == 1 && i != (IPV6_BYTES - 1)) {
    1024      313614 :                         addr_str = talloc_strdup_append(addr_str, ":");
    1025             :                 }
    1026             :         }
    1027       44802 :         *address = addr_str;
    1028       44802 :         NDR_ERR_HAVE_NO_MEMORY(*address);
    1029       44802 :         return NDR_ERR_SUCCESS;
    1030             : }
    1031             : 
    1032             : /*
    1033             :   push a ipv6address
    1034             : */
    1035       55011 : _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       55011 :         if (!is_ipaddress(address)) {
    1042         120 :                 return ndr_push_error(ndr, NDR_ERR_IPV6ADDRESS,
    1043             :                                       "Invalid IPv6 address: '%s'",
    1044             :                                       address);
    1045             :         }
    1046       54891 :         ret = inet_pton(AF_INET6, address, addr);
    1047       54891 :         if (ret <= 0) {
    1048           0 :                 return NDR_ERR_IPV6ADDRESS;
    1049             :         }
    1050             : 
    1051       54891 :         NDR_CHECK(ndr_push_array_uint8(ndr, ndr_flags, addr, IPV6_BYTES));
    1052             : 
    1053       54891 :         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     1193603 : _PUBLIC_ void ndr_print_struct(struct ndr_print *ndr, const char *name, const char *type)
    1070             : {
    1071     1193603 :         ndr->print(ndr, "%s: struct %s", name, type);
    1072     1193603 : }
    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      278848 : _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      278848 :         if (flag == 0) {
    1092           0 :                 return;
    1093             :         }
    1094             : 
    1095             :         /* this is an attempt to support multi-bit bitmap masks */
    1096      278848 :         value &= flag;
    1097             : 
    1098     2898614 :         while (!(flag & 1)) {
    1099     2341709 :                 flag >>= 1;
    1100     2341709 :                 value >>= 1;
    1101             :         }
    1102      278848 :         if (flag == 1) {
    1103      266756 :                 ndr->print(ndr, "   %d: %-25s", value, flag_name);
    1104             :         } else {
    1105       12092 :                 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      428469 : _PUBLIC_ void ndr_print_uint8(struct ndr_print *ndr, const char *name, uint8_t v)
    1119             : {
    1120      428469 :         if (NDR_HIDE_SECRET(ndr)) {
    1121           0 :                 ndr->print(ndr, "%-25s: <REDACTED SECRET VALUE>", name);
    1122           0 :                 return;
    1123             :         }
    1124      428469 :         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       69870 : _PUBLIC_ void ndr_print_uint16(struct ndr_print *ndr, const char *name, uint16_t v)
    1137             : {
    1138       69870 :         if (NDR_HIDE_SECRET(ndr)) {
    1139           0 :                 ndr->print(ndr, "%-25s: <REDACTED SECRET VALUE>", name);
    1140           0 :                 return;
    1141             :         }
    1142       69870 :         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      906516 : _PUBLIC_ void ndr_print_uint32(struct ndr_print *ndr, const char *name, uint32_t v)
    1155             : {
    1156      906516 :         if (NDR_HIDE_SECRET(ndr)) {
    1157           0 :                 ndr->print(ndr, "%-25s: <REDACTED SECRET VALUE>", name);
    1158           0 :                 return;
    1159             :         }
    1160      906516 :         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      589742 : _PUBLIC_ void ndr_print_ptr(struct ndr_print *ndr, const char *name, const void *p)
    1216             : {
    1217      589742 :         if (p) {
    1218      574381 :                 ndr->print(ndr, "%-25s: *", name);
    1219             :         } else {
    1220       15361 :                 ndr->print(ndr, "%-25s: NULL", name);
    1221             :         }
    1222      589742 : }
    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       12002 : _PUBLIC_ void ndr_print_union(struct ndr_print *ndr, const char *name, int level, const char *type)
    1262             : {
    1263       12002 :         if (ndr->flags & LIBNDR_PRINT_ARRAY_HEX) {
    1264           0 :                 ndr->print(ndr, "%-25s: union %s(case 0x%X)", name, type, level);
    1265             :         } else {
    1266       12002 :                 ndr->print(ndr, "%-25s: union %s(case %d)", name, type, level);
    1267             :         }
    1268       12002 : }
    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        9805 : _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        9805 :         if (data == NULL) {
    1282           0 :                 ndr->print(ndr, "%s: ARRAY(%d) : NULL", name, count);
    1283           0 :                 return;
    1284             :         }
    1285             : 
    1286        9805 :         if (NDR_HIDE_SECRET(ndr)) {
    1287        3897 :                 ndr->print(ndr, "%s: ARRAY(%d): <REDACTED SECRET VALUES>", name, count);
    1288        3897 :                 return;
    1289             :         }
    1290             : 
    1291        5908 :         if (count <= _ONELINE_LIMIT && (ndr->flags & LIBNDR_PRINT_ARRAY_HEX)) {
    1292             :                 char s[(_ONELINE_LIMIT + 1) * 2];
    1293       52970 :                 for (i=0;i<count;i++) {
    1294       47346 :                         snprintf(&s[i*2], 3, "%02x", data[i]);
    1295             :                 }
    1296        5624 :                 s[i*2] = 0;
    1297        5624 :                 ndr->print(ndr, "%-25s: %s", name, s);
    1298        5624 :                 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      424296 :         for (i=0;i<count;i++) {
    1309      424012 :                 char *idx=NULL;
    1310      424012 :                 if (asprintf(&idx, "[%d]", i) != -1) {
    1311      424012 :                         ndr_print_uint8(ndr, idx, data[i]);
    1312      424012 :                         free(idx);
    1313             :                 }
    1314             :         }
    1315         284 :         ndr->depth--;
    1316             : #undef _ONELINE_LIMIT
    1317             : }
    1318             : 
    1319    31854656 : static void ndr_print_dump_data_cb(const char *buf, void *private_data)
    1320             : {
    1321    31854656 :         struct ndr_print *ndr = (struct ndr_print *)private_data;
    1322             : 
    1323    31854656 :         ndr->print(ndr, "%s", buf);
    1324    31854656 : }
    1325             : 
    1326             : /*
    1327             :   ndr_print version of dump_data()
    1328             :  */
    1329      199848 : static void ndr_dump_data(struct ndr_print *ndr, const uint8_t *buf, int len)
    1330             : {
    1331      199848 :         if (NDR_HIDE_SECRET(ndr)) {
    1332           2 :                 return;
    1333             :         }
    1334      199846 :         ndr->no_newline = true;
    1335      199846 :         dump_data_cb(buf, len, true, ndr_print_dump_data_cb, ndr);
    1336      199846 :         ndr->no_newline = false;
    1337             : }
    1338             : 
    1339             : 
    1340      201404 : _PUBLIC_ void ndr_print_DATA_BLOB(struct ndr_print *ndr, const char *name, DATA_BLOB r)
    1341             : {
    1342      201404 :         ndr->print(ndr, "%-25s: DATA_BLOB length=%u", name, (unsigned)r.length);
    1343      201404 :         if (r.length) {
    1344      199848 :                 ndr_dump_data(ndr, r.data, r.length);
    1345             :         }
    1346      201404 : }
    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    93826779 : _PUBLIC_ enum ndr_err_code ndr_push_DATA_BLOB(struct ndr_push *ndr, int ndr_flags, DATA_BLOB blob)
    1360             : {
    1361    93826779 :         if (ndr->flags & LIBNDR_FLAG_REMAINING) {
    1362             :                 /* nothing to do */
    1363    86941113 :         } else if (ndr->flags & (LIBNDR_ALIGN_FLAGS & ~LIBNDR_FLAG_NOALIGN)) {
    1364      227494 :                 if (ndr->flags & LIBNDR_FLAG_ALIGN2) {
    1365           6 :                         blob.length = NDR_ALIGN(ndr, 2);
    1366      227488 :                 } else if (ndr->flags & LIBNDR_FLAG_ALIGN4) {
    1367      196774 :                         blob.length = NDR_ALIGN(ndr, 4);
    1368       30714 :                 } else if (ndr->flags & LIBNDR_FLAG_ALIGN8) {
    1369       30714 :                         blob.length = NDR_ALIGN(ndr, 8);
    1370             :                 }
    1371      227494 :                 NDR_PUSH_ALLOC_SIZE(ndr, blob.data, blob.length);
    1372      227494 :                 data_blob_clear(&blob);
    1373             :         } else {
    1374    86713619 :                 NDR_CHECK(ndr_push_uint3264(ndr, NDR_SCALARS, blob.length));
    1375             :         }
    1376    93826779 :         NDR_CHECK(ndr_push_bytes(ndr, blob.data, blob.length));
    1377    93826779 :         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    18095214 : _PUBLIC_ enum ndr_err_code ndr_pull_DATA_BLOB(struct ndr_pull *ndr, int ndr_flags, DATA_BLOB *blob)
    1391             : {
    1392    18095214 :         uint32_t length = 0;
    1393             : 
    1394    18095214 :         if (ndr->flags & LIBNDR_FLAG_REMAINING) {
    1395     7054673 :                 length = ndr->data_size - ndr->offset;
    1396    11040541 :         } else if (ndr->flags & (LIBNDR_ALIGN_FLAGS & ~LIBNDR_FLAG_NOALIGN)) {
    1397      179557 :                 if (ndr->flags & LIBNDR_FLAG_ALIGN2) {
    1398           6 :                         length = NDR_ALIGN(ndr, 2);
    1399      179551 :                 } else if (ndr->flags & LIBNDR_FLAG_ALIGN4) {
    1400      153830 :                         length = NDR_ALIGN(ndr, 4);
    1401       25721 :                 } else if (ndr->flags & LIBNDR_FLAG_ALIGN8) {
    1402       25721 :                         length = NDR_ALIGN(ndr, 8);
    1403             :                 }
    1404      179557 :                 if (ndr->data_size - ndr->offset < length) {
    1405           0 :                         length = ndr->data_size - ndr->offset;
    1406             :                 }
    1407             :         } else {
    1408    10860984 :                 NDR_CHECK(ndr_pull_uint3264(ndr, NDR_SCALARS, &length));
    1409             :         }
    1410    18095214 :         NDR_PULL_NEED_BYTES(ndr, length);
    1411    18095214 :         *blob = data_blob_talloc(ndr->current_mem_ctx, ndr->data+ndr->offset, length);
    1412    18095214 :         ndr->offset += length;
    1413    18095214 :         return NDR_ERR_SUCCESS;
    1414             : }
    1415             : 
    1416    86170003 : _PUBLIC_ uint32_t ndr_size_DATA_BLOB(int ret, const DATA_BLOB *data, int flags)
    1417             : {
    1418    86170003 :         if (!data) return ret;
    1419    86170003 :         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   232504251 : _PUBLIC_ NTSTATUS ndr_map_error2ntstatus(enum ndr_err_code ndr_err)
    1428             : {
    1429   232504251 :         switch (ndr_err) {
    1430   232504207 :         case NDR_ERR_SUCCESS:
    1431   232504208 :                 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       24420 : _PUBLIC_ enum ndr_err_code ndr_push_timeval(struct ndr_push *ndr,
    1510             :                                             int ndr_flags,
    1511             :                                             const struct timeval *t)
    1512             : {
    1513       24420 :         NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
    1514       24420 :         NDR_CHECK(ndr_push_hyper(ndr, ndr_flags, t->tv_sec));
    1515       24420 :         NDR_CHECK(ndr_push_uint32(ndr, ndr_flags, t->tv_usec));
    1516       24420 :         return NDR_ERR_SUCCESS;
    1517             : }
    1518             : 
    1519       42762 : _PUBLIC_ enum ndr_err_code ndr_pull_timeval(struct ndr_pull *ndr,
    1520             :                                             int ndr_flags,
    1521             :                                             struct timeval *t)
    1522             : {
    1523       42762 :         uint64_t secs = 0;
    1524       42762 :         uint32_t usecs = 0;
    1525       42762 :         NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
    1526       42762 :         NDR_CHECK(ndr_pull_hyper(ndr, ndr_flags, &secs));
    1527       42762 :         NDR_CHECK(ndr_pull_uint32(ndr, ndr_flags, &usecs));
    1528       42762 :         t->tv_sec = secs;
    1529       42762 :         t->tv_usec = usecs;
    1530       42762 :         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