Ignore:
Timestamp:
Nov 14, 2012, 12:59:34 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to 3.6.0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/librpc/ndr/ndr.c

    r594 r740  
    4747};
    4848
     49const struct ndr_syntax_id null_ndr_syntax_id = {
     50  { 0, 0, 0, { 0, 0 }, { 0, 0, 0, 0, 0, 0 } },
     51  0
     52};
     53
    4954/*
    5055  work out the number of bytes needed to align on a n byte boundary
     
    5964  initialise a ndr parse structure from a data blob
    6065*/
    61 _PUBLIC_ struct ndr_pull *ndr_pull_init_blob(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx, struct smb_iconv_convenience *iconv_convenience)
     66_PUBLIC_ struct ndr_pull *ndr_pull_init_blob(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx)
    6267{
    6368        struct ndr_pull *ndr;
     
    6974        ndr->data = blob->data;
    7075        ndr->data_size = blob->length;
    71         ndr->iconv_convenience = talloc_reference(ndr, iconv_convenience);
    7276
    7377        return ndr;
     
    103107
    104108/* create a ndr_push structure, ready for some marshalling */
    105 _PUBLIC_ struct ndr_push *ndr_push_init_ctx(TALLOC_CTX *mem_ctx, struct smb_iconv_convenience *iconv_convenience)
     109_PUBLIC_ struct ndr_push *ndr_push_init_ctx(TALLOC_CTX *mem_ctx)
    106110{
    107111        struct ndr_push *ndr;
     
    118122                return NULL;
    119123        }
    120         ndr->iconv_convenience = talloc_reference(ndr, iconv_convenience);
    121124
    122125        return ndr;
     
    169172        va_list ap;
    170173        char *s = NULL;
    171         int i, ret;
     174        uint32_t i;
     175        int ret;
    172176
    173177        va_start(ap, format);
     
    179183        }
    180184
     185        if (ndr->no_newline) {
     186                DEBUGADD(1,("%s", s));
     187                free(s);
     188                return;
     189        }
     190
    181191        for (i=0;i<ndr->depth;i++) {
    182192                DEBUGADD(1,("    "));
     
    187197}
    188198
     199_PUBLIC_ void ndr_print_printf_helper(struct ndr_print *ndr, const char *format, ...)
     200{
     201        va_list ap;
     202        uint32_t i;
     203
     204        if (!ndr->no_newline) {
     205                for (i=0;i<ndr->depth;i++) {
     206                        printf("    ");
     207                }
     208        }
     209
     210        va_start(ap, format);
     211        vprintf(format, ap);
     212        va_end(ap);
     213        if (!ndr->no_newline) {
     214                printf("\n");
     215        }
     216}
     217
    189218_PUBLIC_ void ndr_print_string_helper(struct ndr_print *ndr, const char *format, ...)
    190219{
    191220        va_list ap;
    192         int i;
    193 
    194         for (i=0;i<ndr->depth;i++) {
    195                 ndr->private_data = talloc_asprintf_append_buffer(
    196                                         (char *)ndr->private_data, "    ");
     221        uint32_t i;
     222
     223        if (!ndr->no_newline) {
     224                for (i=0;i<ndr->depth;i++) {
     225                        ndr->private_data = talloc_asprintf_append_buffer(
     226                                (char *)ndr->private_data, "    ");
     227                }
    197228        }
    198229
     
    201232                                                    format, ap);
    202233        va_end(ap);
    203         ndr->private_data = talloc_asprintf_append_buffer((char *)ndr->private_data,
    204                                                    "\n");
     234        if (!ndr->no_newline) {
     235                ndr->private_data = talloc_asprintf_append_buffer((char *)ndr->private_data,
     236                                                                  "\n");
     237        }
    205238}
    206239
     
    257290        ndr->flags = 0;
    258291
    259         /* this is a s4 hack until we build up the courage to pass
    260          * this all the way down
    261          */
    262 #if _SAMBA_BUILD_ == 4
    263         ndr->iconv_convenience = smb_iconv_convenience_init(talloc_autofree_context(), "ASCII", "UTF-8", true);
    264 #endif
    265 
    266292        fn(ndr, name, flags, ptr);
    267293        talloc_free(ndr);
     
    285311        ndr->depth = 1;
    286312        ndr->flags = 0;
    287 
    288         /* this is a s4 hack until we build up the courage to pass
    289          * this all the way down
    290          */
    291 #if _SAMBA_BUILD_ == 4
    292         ndr->iconv_convenience = smb_iconv_convenience_init(talloc_autofree_context(), "ASCII", "UTF-8", true);
    293 #endif
    294313
    295314        fn(ndr, name, ptr);
     
    554573        subndr->offset = 0;
    555574        subndr->data_size = r_content_size;
    556         subndr->iconv_convenience = talloc_reference(subndr, ndr->iconv_convenience);
    557575
    558576        if (force_le) {
     
    590608        struct ndr_push *subndr;
    591609
    592         subndr = ndr_push_init_ctx(ndr, ndr->iconv_convenience);
     610        subndr = ndr_push_init_ctx(ndr);
    593611        NDR_ERR_HAVE_NO_MEMORY(subndr);
    594612        subndr->flags   = ndr->flags & ~LIBNDR_FLAG_NDR64;
     
    812830}
    813831
     832_PUBLIC_ enum ndr_err_code ndr_push_pipe_chunk_trailer(struct ndr_push *ndr, int ndr_flags, uint32_t count)
     833{
     834        if (ndr->flags & LIBNDR_FLAG_NDR64) {
     835                int64_t tmp = 0 - (int64_t)count;
     836                uint64_t ncount = tmp;
     837
     838                NDR_CHECK(ndr_push_hyper(ndr, ndr_flags, ncount));
     839        }
     840
     841        return NDR_ERR_SUCCESS;
     842}
     843
     844_PUBLIC_ enum ndr_err_code ndr_check_pipe_chunk_trailer(struct ndr_pull *ndr, int ndr_flags, uint32_t count)
     845{
     846        if (ndr->flags & LIBNDR_FLAG_NDR64) {
     847                int64_t tmp = 0 - (int64_t)count;
     848                uint64_t ncount1 = tmp;
     849                uint64_t ncount2;
     850
     851                NDR_CHECK(ndr_pull_hyper(ndr, ndr_flags, &ncount2));
     852                if (ncount1 == ncount2) {
     853                        return NDR_ERR_SUCCESS;
     854                }
     855
     856                return ndr_pull_error(ndr, NDR_ERR_ARRAY_SIZE,
     857                        "Bad pipe trailer[%lld should be %lld] size was %lu\"",
     858                        (unsigned long long)ncount2,
     859                        (unsigned long long)ncount1,
     860                        (unsigned long)count);
     861        }
     862
     863        return NDR_ERR_SUCCESS;
     864}
     865
    814866/*
    815867  store a switch value
     
    851903  pull a struct from a blob using NDR
    852904*/
    853 _PUBLIC_ enum ndr_err_code ndr_pull_struct_blob(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx, struct smb_iconv_convenience *iconv_convenience, void *p,
     905_PUBLIC_ enum ndr_err_code ndr_pull_struct_blob(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx, void *p,
    854906                              ndr_pull_flags_fn_t fn)
    855907{
    856908        struct ndr_pull *ndr;
    857         ndr = ndr_pull_init_blob(blob, mem_ctx, iconv_convenience);
     909        ndr = ndr_pull_init_blob(blob, mem_ctx);
    858910        NDR_ERR_HAVE_NO_MEMORY(ndr);
    859911        NDR_CHECK_FREE(fn(ndr, NDR_SCALARS|NDR_BUFFERS, p));
     
    866918*/
    867919_PUBLIC_ enum ndr_err_code ndr_pull_struct_blob_all(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx,
    868                                                     struct smb_iconv_convenience *iconv_convenience,
    869920                                                    void *p, ndr_pull_flags_fn_t fn)
    870921{
    871922        struct ndr_pull *ndr;
    872         ndr = ndr_pull_init_blob(blob, mem_ctx, iconv_convenience);
     923        uint32_t highest_ofs;
     924        ndr = ndr_pull_init_blob(blob, mem_ctx);
    873925        NDR_ERR_HAVE_NO_MEMORY(ndr);
    874926        NDR_CHECK_FREE(fn(ndr, NDR_SCALARS|NDR_BUFFERS, p));
    875         if (ndr->offset < ndr->data_size) {
    876                 return ndr_pull_error(ndr, NDR_ERR_UNREAD_BYTES,
    877                                       "not all bytes consumed ofs[%u] size[%u]",
    878                                       ndr->offset, ndr->data_size);
     927        if (ndr->offset > ndr->relative_highest_offset) {
     928                highest_ofs = ndr->offset;
     929        } else {
     930                highest_ofs = ndr->relative_highest_offset;
     931        }
     932        if (highest_ofs < ndr->data_size) {
     933                enum ndr_err_code ret;
     934                ret = ndr_pull_error(ndr, NDR_ERR_UNREAD_BYTES,
     935                                     "not all bytes consumed ofs[%u] size[%u]",
     936                                     highest_ofs, ndr->data_size);
     937                talloc_free(ndr);
     938                return ret;
    879939        }
    880940        talloc_free(ndr);
     
    886946*/
    887947_PUBLIC_ enum ndr_err_code ndr_pull_union_blob(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx,
    888                                                struct smb_iconv_convenience *iconv_convenience, void *p,
     948                                               void *p,
    889949                             uint32_t level, ndr_pull_flags_fn_t fn)
    890950{
    891951        struct ndr_pull *ndr;
    892         ndr = ndr_pull_init_blob(blob, mem_ctx, iconv_convenience);
     952        ndr = ndr_pull_init_blob(blob, mem_ctx);
    893953        NDR_ERR_HAVE_NO_MEMORY(ndr);
    894954        NDR_CHECK_FREE(ndr_pull_set_switch_value(ndr, p, level));
     
    903963*/
    904964_PUBLIC_ enum ndr_err_code ndr_pull_union_blob_all(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx,
    905                                                    struct smb_iconv_convenience *iconv_convenience, void *p,
     965                                                   void *p,
    906966                             uint32_t level, ndr_pull_flags_fn_t fn)
    907967{
    908968        struct ndr_pull *ndr;
    909         ndr = ndr_pull_init_blob(blob, mem_ctx, iconv_convenience);
     969        uint32_t highest_ofs;
     970        ndr = ndr_pull_init_blob(blob, mem_ctx);
    910971        NDR_ERR_HAVE_NO_MEMORY(ndr);
    911972        NDR_CHECK_FREE(ndr_pull_set_switch_value(ndr, p, level));
    912973        NDR_CHECK_FREE(fn(ndr, NDR_SCALARS|NDR_BUFFERS, p));
    913         if (ndr->offset < ndr->data_size) {
     974        if (ndr->offset > ndr->relative_highest_offset) {
     975                highest_ofs = ndr->offset;
     976        } else {
     977                highest_ofs = ndr->relative_highest_offset;
     978        }
     979        if (highest_ofs < ndr->data_size) {
    914980                enum ndr_err_code ret;
    915981                ret = ndr_pull_error(ndr, NDR_ERR_UNREAD_BYTES,
    916982                                     "not all bytes consumed ofs[%u] size[%u]",
    917                                      ndr->offset, ndr->data_size);
     983                                     highest_ofs, ndr->data_size);
    918984                talloc_free(ndr);
    919985                return ret;
     
    926992  push a struct to a blob using NDR
    927993*/
    928 _PUBLIC_ enum ndr_err_code ndr_push_struct_blob(DATA_BLOB *blob, TALLOC_CTX *mem_ctx, struct smb_iconv_convenience *iconv_convenience, const void *p, ndr_push_flags_fn_t fn)
     994_PUBLIC_ enum ndr_err_code ndr_push_struct_blob(DATA_BLOB *blob, TALLOC_CTX *mem_ctx, const void *p, ndr_push_flags_fn_t fn)
    929995{
    930996        struct ndr_push *ndr;
    931         ndr = ndr_push_init_ctx(mem_ctx, iconv_convenience);
     997        ndr = ndr_push_init_ctx(mem_ctx);
    932998        NDR_ERR_HAVE_NO_MEMORY(ndr);
    933999
     
    9441010  push a union to a blob using NDR
    9451011*/
    946 _PUBLIC_ enum ndr_err_code ndr_push_union_blob(DATA_BLOB *blob, TALLOC_CTX *mem_ctx, struct smb_iconv_convenience *iconv_convenience, void *p,
     1012_PUBLIC_ enum ndr_err_code ndr_push_union_blob(DATA_BLOB *blob, TALLOC_CTX *mem_ctx, void *p,
    9471013                             uint32_t level, ndr_push_flags_fn_t fn)
    9481014{
    9491015        struct ndr_push *ndr;
    950         ndr = ndr_push_init_ctx(mem_ctx, iconv_convenience);
     1016        ndr = ndr_push_init_ctx(mem_ctx);
    9511017        NDR_ERR_HAVE_NO_MEMORY(ndr);
    9521018
     
    9641030  generic ndr_size_*() handler for structures
    9651031*/
    966 _PUBLIC_ size_t ndr_size_struct(const void *p, int flags, ndr_push_flags_fn_t push, struct smb_iconv_convenience *iconv_convenience)
     1032_PUBLIC_ size_t ndr_size_struct(const void *p, int flags, ndr_push_flags_fn_t push)
    9671033{
    9681034        struct ndr_push *ndr;
     
    9731039        if (flags & LIBNDR_FLAG_NO_NDR_SIZE) return 0;
    9741040
    975         ndr = ndr_push_init_ctx(NULL, iconv_convenience);
     1041        ndr = ndr_push_init_ctx(NULL);
    9761042        if (!ndr) return 0;
    9771043        ndr->flags |= flags | LIBNDR_FLAG_NO_NDR_SIZE;
     
    9891055  generic ndr_size_*() handler for unions
    9901056*/
    991 _PUBLIC_ size_t ndr_size_union(const void *p, int flags, uint32_t level, ndr_push_flags_fn_t push, struct smb_iconv_convenience *iconv_convenience)
     1057_PUBLIC_ size_t ndr_size_union(const void *p, int flags, uint32_t level, ndr_push_flags_fn_t push)
    9921058{
    9931059        struct ndr_push *ndr;
     
    9981064        if (flags & LIBNDR_FLAG_NO_NDR_SIZE) return 0;
    9991065
    1000         ndr = ndr_push_init_ctx(NULL, iconv_convenience);
     1066        ndr = ndr_push_init_ctx(NULL);
    10011067        if (!ndr) return 0;
    10021068        ndr->flags |= flags | LIBNDR_FLAG_NO_NDR_SIZE;
     
    10671133}
    10681134
     1135/*
     1136  push a short relative object - stage1
     1137  this is called during SCALARS processing
     1138*/
     1139_PUBLIC_ enum ndr_err_code ndr_push_short_relative_ptr1(struct ndr_push *ndr, const void *p)
     1140{
     1141        if (p == NULL) {
     1142                NDR_CHECK(ndr_push_uint16(ndr, NDR_SCALARS, 0));
     1143                return NDR_ERR_SUCCESS;
     1144        }
     1145        NDR_CHECK(ndr_push_align(ndr, 2));
     1146        NDR_CHECK(ndr_token_store(ndr, &ndr->relative_list, p, ndr->offset));
     1147        return ndr_push_uint16(ndr, NDR_SCALARS, 0xFFFF);
     1148}
    10691149/*
    10701150  push a relative object - stage2
     
    10921172        }       
    10931173        NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, save_offset - ndr->relative_base_offset));
     1174        ndr->offset = save_offset;
     1175        return NDR_ERR_SUCCESS;
     1176}
     1177/*
     1178  push a short relative object - stage2
     1179  this is called during buffers processing
     1180*/
     1181_PUBLIC_ enum ndr_err_code ndr_push_short_relative_ptr2(struct ndr_push *ndr, const void *p)
     1182{
     1183        uint32_t save_offset;
     1184        uint32_t ptr_offset = 0xFFFF;
     1185        if (p == NULL) {
     1186                return NDR_ERR_SUCCESS;
     1187        }
     1188        save_offset = ndr->offset;
     1189        NDR_CHECK(ndr_token_retrieve(&ndr->relative_list, p, &ptr_offset));
     1190        if (ptr_offset > ndr->offset) {
     1191                return ndr_push_error(ndr, NDR_ERR_BUFSIZE,
     1192                                      "ndr_push_short_relative_ptr2 ptr_offset(%u) > ndr->offset(%u)",
     1193                                      ptr_offset, ndr->offset);
     1194        }
     1195        ndr->offset = ptr_offset;
     1196        if (save_offset < ndr->relative_base_offset) {
     1197                return ndr_push_error(ndr, NDR_ERR_BUFSIZE,
     1198                                      "ndr_push_relative_ptr2 save_offset(%u) < ndr->relative_base_offset(%u)",
     1199                                      save_offset, ndr->relative_base_offset);
     1200        }
     1201        NDR_CHECK(ndr_push_uint16(ndr, NDR_SCALARS, save_offset - ndr->relative_base_offset));
    10941202        ndr->offset = save_offset;
    10951203        return NDR_ERR_SUCCESS;
Note: See TracChangeset for help on using the changeset viewer.