librpc/ndr: Use portable format specifiers
[vlendec/samba-autobuild/.git] / librpc / ndr / ndr_drsblobs.c
index 9b55c5d5e1ebe871461f6d11f7d9b0bbdd906ae4..99dd32e0416e17418bf6d93d084a7a5e74deb5e7 100644 (file)
@@ -4,6 +4,7 @@
    Manually parsed structures found in the DRS protocol
 
    Copyright (C) Andrew Bartlett <abartlet@samba.org> 2008
+   Copyright (C) Guenther Deschner <gd@samba.org> 2010
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
 #include "librpc/gen_ndr/ndr_drsblobs.h"
 #include "../lib/util/asn1.h"
 
-/* parser auto-generated by pidl, then hand-modified by abartlet */
-
-/* Modified to have 'count' specified */
-static enum ndr_err_code ndr_push_AuthenticationInformationArray_with_count(struct ndr_push *ndr, int ndr_flags, int count, 
-                                                                const struct AuthenticationInformationArray *r)
+_PUBLIC_ enum ndr_err_code ndr_push_AuthenticationInformationArray(struct ndr_push *ndr, int ndr_flags, const struct AuthenticationInformationArray *r)
 {
        uint32_t cntr_array_0;
        if (ndr_flags & NDR_SCALARS) {
                NDR_CHECK(ndr_push_align(ndr, 4));
-               for (cntr_array_0 = 0; cntr_array_0 < count; cntr_array_0++) {
+               for (cntr_array_0 = 0; cntr_array_0 < r->count; cntr_array_0++) {
                        NDR_CHECK(ndr_push_AuthenticationInformation(ndr, NDR_SCALARS, &r->array[cntr_array_0]));
                }
+               NDR_CHECK(ndr_push_align(ndr, 4));
        }
        if (ndr_flags & NDR_BUFFERS) {
-               for (cntr_array_0 = 0; cntr_array_0 < count; cntr_array_0++) {
-                       NDR_CHECK(ndr_push_AuthenticationInformation(ndr, NDR_BUFFERS, &r->array[cntr_array_0]));
-               }
        }
        return NDR_ERR_SUCCESS;
 }
 
-/* Modified to have 'count' specified, and to allocate the array */
-static enum ndr_err_code ndr_pull_AuthenticationInformationArray_with_count(struct ndr_pull *ndr, int ndr_flags, int count, struct AuthenticationInformationArray *r)
+_PUBLIC_ enum ndr_err_code ndr_pull_AuthenticationInformationArray(struct ndr_pull *ndr, int ndr_flags, struct AuthenticationInformationArray *r)
 {
-       uint32_t cntr_array_0;
-       TALLOC_CTX *_mem_save_array_0;
        if (ndr_flags & NDR_SCALARS) {
-               NDR_CHECK(ndr_pull_align(ndr, 4));
-               NDR_PULL_ALLOC_N(ndr, r->array, count);
-               _mem_save_array_0 = NDR_PULL_GET_MEM_CTX(ndr);
-               NDR_PULL_SET_MEM_CTX(ndr, r->array, 0);
-               for (cntr_array_0 = 0; cntr_array_0 < count; cntr_array_0++) {
-                       NDR_CHECK(ndr_pull_AuthenticationInformation(ndr, NDR_SCALARS, &r->array[cntr_array_0]));
+               r->count = 0;
+               NDR_PULL_ALLOC_N(ndr, r->array, r->count);
+               /* entry is at least 16 bytes large */
+               while (ndr->offset + 16 <= ndr->data_size) {
+                       r->array = talloc_realloc(ndr, r->array, struct AuthenticationInformation, r->count + 1);
+                       NDR_ERR_HAVE_NO_MEMORY(r->array);
+                       NDR_CHECK(ndr_pull_AuthenticationInformation(ndr, NDR_SCALARS, &r->array[r->count]));
+                       r->count++;
                }
-               NDR_PULL_SET_MEM_CTX(ndr, _mem_save_array_0, 0);
+               NDR_CHECK(ndr_pull_align(ndr, 4));
        }
        if (ndr_flags & NDR_BUFFERS) {
-               for (cntr_array_0 = 0; cntr_array_0 < count; cntr_array_0++) {
-                       NDR_CHECK(ndr_pull_AuthenticationInformation(ndr, NDR_BUFFERS, &r->array[cntr_array_0]));
-               }
        }
        return NDR_ERR_SUCCESS;
 }
 
-/* Modified to have 'count' specified */
-_PUBLIC_ void ndr_print_AuthenticationInformationArray_with_count(struct ndr_print *ndr, const char *name, int count, const struct AuthenticationInformationArray *r)
-{
-       uint32_t cntr_array_0;
-       ndr_print_struct(ndr, name, "AuthenticationInformationArray");
-       ndr->depth++;
-       ndr->print(ndr, "%s: ARRAY(%d)", "array", (int)1);
-       ndr->depth++;
-       for (cntr_array_0=0;cntr_array_0<count;cntr_array_0++) {
-               char *idx_0=NULL;
-               if (asprintf(&idx_0, "[%d]", cntr_array_0) != -1) {
-                       ndr_print_AuthenticationInformation(ndr, "array", &r->array[cntr_array_0]);
-                       free(idx_0);
-               }
-       }
-       ndr->depth--;
-       ndr->depth--;
-}
-
-/* Modified to call AuthenticationInformationArray with 'count' specified */
 _PUBLIC_ enum ndr_err_code ndr_push_trustAuthInOutBlob(struct ndr_push *ndr, int ndr_flags, const struct trustAuthInOutBlob *r)
 {
        if (ndr_flags & NDR_SCALARS) {
                NDR_CHECK(ndr_push_align(ndr, 4));
                NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, r->count));
-               NDR_CHECK(ndr_push_relative_ptr1(ndr, r->current));
-               NDR_CHECK(ndr_push_relative_ptr1(ndr, r->previous));
-       }
-       if (ndr_flags & NDR_BUFFERS) {
-               if (r->current) {
-                       NDR_CHECK(ndr_push_relative_ptr2_start(ndr, r->current));
-                       NDR_CHECK(ndr_push_AuthenticationInformationArray_with_count(ndr, NDR_SCALARS|NDR_BUFFERS, r->count, r->current));
-                       NDR_CHECK(ndr_push_relative_ptr2_end(ndr, r->current));
-               }
-               if (r->previous) {
-                       NDR_CHECK(ndr_push_relative_ptr2_start(ndr, r->previous));
-                       NDR_CHECK(ndr_push_AuthenticationInformationArray_with_count(ndr, NDR_SCALARS|NDR_BUFFERS, r->count, r->previous));
-                       NDR_CHECK(ndr_push_relative_ptr2_end(ndr, r->previous));
-               }
-       }
-       return NDR_ERR_SUCCESS;
-}
-
-_PUBLIC_ enum ndr_err_code ndr_pull_trustAuthInOutBlob(struct ndr_pull *ndr, int ndr_flags, struct trustAuthInOutBlob *r)
-{
-       uint32_t _ptr_current;
-       TALLOC_CTX *_mem_save_current_0;
-       uint32_t _ptr_previous;
-       TALLOC_CTX *_mem_save_previous_0;
-       if (ndr_flags & NDR_SCALARS) {
-               NDR_CHECK(ndr_pull_align(ndr, 4));
-               NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->count));
-               NDR_CHECK(ndr_pull_generic_ptr(ndr, &_ptr_current));
-               if (_ptr_current) {
-                       NDR_PULL_ALLOC(ndr, r->current);
-                       NDR_CHECK(ndr_pull_relative_ptr1(ndr, r->current, _ptr_current));
-               } else {
-                       r->current = NULL;
+               NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, (r->count > 0)?12:0));
+               NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, (r->count > 0)?12 + ndr_size_AuthenticationInformationArray(&r->current, 0):0));
+               {
+                       struct ndr_push *_ndr_current;
+                       NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_current, 0, ((r->count > 0)?12 + ndr_size_AuthenticationInformationArray(&r->current, 0):0) - ((r->count > 0)?12:0)));
+                       NDR_CHECK(ndr_push_AuthenticationInformationArray(_ndr_current, NDR_SCALARS, &r->current));
+                       NDR_CHECK(ndr_push_subcontext_end(ndr, _ndr_current, 0, ((r->count > 0)?12 + ndr_size_AuthenticationInformationArray(&r->current, 0):0) - ((r->count > 0)?12:0)));
                }
-               NDR_CHECK(ndr_pull_generic_ptr(ndr, &_ptr_previous));
-               if (_ptr_previous) {
-                       NDR_PULL_ALLOC(ndr, r->previous);
-                       NDR_CHECK(ndr_pull_relative_ptr1(ndr, r->previous, _ptr_previous));
-               } else {
-                       r->previous = NULL;
+               {
+                       uint32_t _flags_save_AuthenticationInformationArray = ndr->flags;
+                       ndr_set_flags(&ndr->flags, LIBNDR_FLAG_REMAINING);
+                       {
+                               struct ndr_push *_ndr_previous;
+                               NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_previous, 0, -1));
+                               NDR_CHECK(ndr_push_AuthenticationInformationArray(_ndr_previous, NDR_SCALARS, &r->previous));
+                               NDR_CHECK(ndr_push_subcontext_end(ndr, _ndr_previous, 0, -1));
+                       }
+                       ndr->flags = _flags_save_AuthenticationInformationArray;
                }
+               NDR_CHECK(ndr_push_trailer_align(ndr, 4));
        }
        if (ndr_flags & NDR_BUFFERS) {
-               if (r->current) {
-                       uint32_t _relative_save_offset;
-                       _relative_save_offset = ndr->offset;
-                       NDR_CHECK(ndr_pull_relative_ptr2(ndr, r->current));
-                       _mem_save_current_0 = NDR_PULL_GET_MEM_CTX(ndr);
-                       NDR_PULL_SET_MEM_CTX(ndr, r->current, 0);
-                       NDR_CHECK(ndr_pull_AuthenticationInformationArray_with_count(ndr, NDR_SCALARS|NDR_BUFFERS, r->count, r->current));
-                       NDR_PULL_SET_MEM_CTX(ndr, _mem_save_current_0, 0);
-                       ndr->offset = _relative_save_offset;
-               }
-               if (r->previous) {
-                       uint32_t _relative_save_offset;
-                       _relative_save_offset = ndr->offset;
-                       NDR_CHECK(ndr_pull_relative_ptr2(ndr, r->previous));
-                       _mem_save_previous_0 = NDR_PULL_GET_MEM_CTX(ndr);
-                       NDR_PULL_SET_MEM_CTX(ndr, r->previous, 0);
-                       NDR_CHECK(ndr_pull_AuthenticationInformationArray_with_count(ndr, NDR_SCALARS|NDR_BUFFERS, r->count, r->previous));
-                       NDR_PULL_SET_MEM_CTX(ndr, _mem_save_previous_0, 0);
-                       ndr->offset = _relative_save_offset;
-               }
        }
        return NDR_ERR_SUCCESS;
 }
 
-_PUBLIC_ void ndr_print_trustAuthInOutBlob(struct ndr_print *ndr, const char *name, const struct trustAuthInOutBlob *r)
-{
-       ndr_print_struct(ndr, name, "trustAuthInOutBlob");
-       ndr->depth++;
-       ndr_print_uint32(ndr, "count", r->count);
-       ndr_print_ptr(ndr, "current", r->current);
-       ndr->depth++;
-       if (r->current) {
-               ndr_print_AuthenticationInformationArray_with_count(ndr, "current", r->count, r->current);
-       }
-       ndr->depth--;
-       ndr_print_ptr(ndr, "previous", r->previous);
-       ndr->depth++;
-       if (r->previous) {
-               ndr_print_AuthenticationInformationArray_with_count(ndr, "previous", r->count, r->previous);
-       }
-       ndr->depth--;
-       ndr->depth--;
-}
 
 _PUBLIC_ enum ndr_err_code ndr_pull_trustDomainPasswords(struct ndr_pull *ndr, int ndr_flags, struct trustDomainPasswords *r)
 {
@@ -197,13 +108,13 @@ _PUBLIC_ enum ndr_err_code ndr_pull_trustDomainPasswords(struct ndr_pull *ndr, i
                {
                        struct ndr_pull *_ndr_outgoing;
                        NDR_CHECK(ndr_pull_subcontext_start(ndr, &_ndr_outgoing, 0, r->outgoing_size));
-                       NDR_CHECK(ndr_pull_trustCurrentPasswords(_ndr_outgoing, NDR_SCALARS|NDR_BUFFERS, &r->outgoing));
+                       NDR_CHECK(ndr_pull_trustAuthInOutBlob(_ndr_outgoing, NDR_SCALARS|NDR_BUFFERS, &r->outgoing));
                        NDR_CHECK(ndr_pull_subcontext_end(ndr, _ndr_outgoing, 0, r->outgoing_size));
                }
                {
                        struct ndr_pull *_ndr_incoming;
                        NDR_CHECK(ndr_pull_subcontext_start(ndr, &_ndr_incoming, 0, r->incoming_size));
-                       NDR_CHECK(ndr_pull_trustCurrentPasswords(_ndr_incoming, NDR_SCALARS|NDR_BUFFERS, &r->incoming));
+                       NDR_CHECK(ndr_pull_trustAuthInOutBlob(_ndr_incoming, NDR_SCALARS|NDR_BUFFERS, &r->incoming));
                        NDR_CHECK(ndr_pull_subcontext_end(ndr, _ndr_incoming, 0, r->incoming_size));
                }
                NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &r->outgoing_size));
@@ -222,12 +133,12 @@ _PUBLIC_ void ndr_print_drsuapi_MSPrefixMap_Entry(struct ndr_print *ndr, const c
                ndr_set_flags(&ndr->flags, LIBNDR_FLAG_NOALIGN);
                ndr->depth++;
                ndr_print_uint16(ndr, "entryID", r->entryID);
-               ndr->print(ndr, "%-25s: length=%u", "oid", r->length);
+               ndr->print(ndr, "%-25s: length=%"PRIu16, "oid", r->length);
                if (r->binary_oid) {
                        char *partial_oid = NULL;
                        DATA_BLOB oid_blob = data_blob_const(r->binary_oid, r->length);
                        char *hex_str = data_blob_hex_string_upper(ndr, &oid_blob);
-                       ber_read_partial_OID_String(ndr, oid_blob, (const char **)&partial_oid);
+                       ber_read_partial_OID_String(ndr, oid_blob, &partial_oid);
                        ndr->depth++;
                        ndr->print(ndr, "%-25s: 0x%s (%s)", "binary_oid", hex_str, partial_oid);
                        ndr->depth--;
@@ -238,3 +149,72 @@ _PUBLIC_ void ndr_print_drsuapi_MSPrefixMap_Entry(struct ndr_print *ndr, const c
                ndr->flags = _flags_save_STRUCT;
        }
 }
+
+_PUBLIC_ enum ndr_err_code ndr_push_supplementalCredentialsSubBlob(struct ndr_push *ndr, int ndr_flags, const struct supplementalCredentialsSubBlob *r)
+{
+       uint32_t cntr_packages_0;
+       NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
+       if (ndr_flags & NDR_SCALARS) {
+               if ((r->signature != SUPPLEMENTAL_CREDENTIALS_SIGNATURE)
+                   && (r->num_packages == 0)) {
+                       return NDR_ERR_SUCCESS;
+               }
+               NDR_CHECK(ndr_push_align(ndr, 3));
+               NDR_CHECK(ndr_push_charset(ndr, NDR_SCALARS, SUPPLEMENTAL_CREDENTIALS_PREFIX, 0x30, sizeof(uint16_t), CH_UTF16));
+               NDR_CHECK(ndr_push_supplementalCredentialsSignature(ndr, NDR_SCALARS, SUPPLEMENTAL_CREDENTIALS_SIGNATURE));
+               if (r->num_packages > 0) {
+                       NDR_CHECK(ndr_push_uint16(ndr, NDR_SCALARS, r->num_packages));
+               }
+               for (cntr_packages_0 = 0; cntr_packages_0 < (r->num_packages); cntr_packages_0++) {
+                       NDR_CHECK(ndr_push_supplementalCredentialsPackage(ndr, NDR_SCALARS, &r->packages[cntr_packages_0]));
+               }
+               NDR_CHECK(ndr_push_trailer_align(ndr, 3));
+       }
+       if (ndr_flags & NDR_BUFFERS) {
+       }
+       return NDR_ERR_SUCCESS;
+}
+
+_PUBLIC_ enum ndr_err_code ndr_pull_supplementalCredentialsSubBlob(struct ndr_pull *ndr, int ndr_flags, struct supplementalCredentialsSubBlob *r)
+{
+       uint32_t size_prefix_0 = 0;
+       uint32_t size_packages_0 = 0;
+       uint32_t cntr_packages_0;
+       TALLOC_CTX *_mem_save_packages_0 = NULL;
+       NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
+       if (ndr_flags & NDR_SCALARS) {
+               uint32_t remaining = 0;
+               NDR_CHECK(ndr_pull_align(ndr, 3));
+               size_prefix_0 = 0x30;
+               remaining = ndr->data_size - ndr->offset;
+               if (remaining >= size_prefix_0) {
+                       NDR_CHECK(ndr_pull_charset(ndr, NDR_SCALARS, &r->prefix, size_prefix_0, sizeof(uint16_t), CH_UTF16));
+               } else {
+                       r->prefix = NULL;
+               }
+               remaining = ndr->data_size - ndr->offset;
+               if (remaining >= 2) {
+                       NDR_CHECK(ndr_pull_supplementalCredentialsSignature(ndr, NDR_SCALARS, &r->signature));
+               } else {
+                       r->signature = 0;
+               }
+               remaining = ndr->data_size - ndr->offset;
+               if (remaining > 0) {
+                       NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &r->num_packages));
+               } else {
+                       r->num_packages = 0;
+               }
+               size_packages_0 = r->num_packages;
+               NDR_PULL_ALLOC_N(ndr, r->packages, size_packages_0);
+               _mem_save_packages_0 = NDR_PULL_GET_MEM_CTX(ndr);
+               NDR_PULL_SET_MEM_CTX(ndr, r->packages, 0);
+               for (cntr_packages_0 = 0; cntr_packages_0 < (size_packages_0); cntr_packages_0++) {
+                       NDR_CHECK(ndr_pull_supplementalCredentialsPackage(ndr, NDR_SCALARS, &r->packages[cntr_packages_0]));
+               }
+               NDR_PULL_SET_MEM_CTX(ndr, _mem_save_packages_0, 0);
+               NDR_CHECK(ndr_pull_trailer_align(ndr, 3));
+       }
+       if (ndr_flags & NDR_BUFFERS) {
+       }
+       return NDR_ERR_SUCCESS;
+}