r4627: - simplified the dcerpc auth code using a common function
[samba.git] / source4 / librpc / ndr / ndr.c
index 0543fbf0d36125384e9162aff499750ac39c8d2e..7cc832c68e30ccb442d353457be759523281eae0 100644 (file)
@@ -128,7 +128,7 @@ struct ndr_push *ndr_push_init_ctx(TALLOC_CTX *mem_ctx)
 
        ndr->flags = 0;
        ndr->alloc_size = NDR_BASE_MARSHALL_SIZE;
-       ndr->data = talloc(ndr, ndr->alloc_size);
+       ndr->data = talloc_array_p(ndr, uint8_t, ndr->alloc_size);
        if (!ndr->data) {
                return NULL;
        }
@@ -173,7 +173,7 @@ NTSTATUS ndr_push_expand(struct ndr_push *ndr, uint32_t size)
        if (size > ndr->alloc_size) {
                ndr->alloc_size = size;
        }
-       ndr->data = talloc_realloc(ndr, ndr->data, ndr->alloc_size);
+       ndr->data = talloc_realloc(ndr, ndr->data, uint8_t, ndr->alloc_size);
        if (!ndr->data) {
                return ndr_push_error(ndr, NDR_ERR_ALLOC, "Failed to push_expand to %u",
                                      ndr->alloc_size);
@@ -862,3 +862,24 @@ NTSTATUS ndr_push_struct_blob(DATA_BLOB *blob, TALLOC_CTX *mem_ctx, void *p,
 
        return NT_STATUS_OK;
 }
+
+/*
+  generic ndr_size_*() handler for structures
+*/
+size_t ndr_size_struct(const void *p, int flags, ndr_push_flags_fn_t push)
+{
+       struct ndr_push *ndr;
+       NTSTATUS status;
+       size_t ret;
+
+       ndr = ndr_push_init_ctx(NULL);
+       if (!ndr) return 0;
+       ndr->flags |= flags;
+       status = push(ndr, NDR_SCALARS|NDR_BUFFERS, discard_const(p));
+       if (!NT_STATUS_IS_OK(status)) {
+               return 0;
+       }
+       ret = ndr->offset;
+       talloc_free(ndr);
+       return ret;
+}