librpc: Add autogenerated total cabinet size for Cabinet files
[kai/samba-autobuild/.git] / librpc / ndr / ndr.c
index 78cde20f7d1d261c2ecd54776b58428218c5c2f0..22c4d763d09f719b9c8fedd440ad85e2b0f594c4 100644 (file)
@@ -254,6 +254,17 @@ _PUBLIC_ enum ndr_err_code ndr_push_expand(struct ndr_push *ndr, uint32_t extra_
                                      size);
        }
 
+       if (ndr->fixed_buf_size) {
+               if (ndr->alloc_size >= size) {
+                       return NDR_ERR_SUCCESS;
+               }
+               return ndr_push_error(ndr,
+                                     NDR_ERR_BUFSIZE,
+                                     "Overflow of fixed buffer in "
+                                     "push_expand to %u",
+                                     size);
+       }
+       
        if (ndr->alloc_size > size) {
                return NDR_ERR_SUCCESS;
        }
@@ -1264,6 +1275,35 @@ _PUBLIC_ enum ndr_err_code ndr_push_struct_blob(DATA_BLOB *blob, TALLOC_CTX *mem
        return NDR_ERR_SUCCESS;
 }
 
+/* 
+  push a struct into a provided blob using NDR. 
+  We error because we want to have the performance issue (extra
+  talloc() calls) show up as an error, not just slower code.  This is
+  used for things like GUIDs, which we expect to be a fixed size, and
+  SIDs that we can pre-calculate the size for.
+*/
+_PUBLIC_ enum ndr_err_code ndr_push_struct_into_fixed_blob(
+       DATA_BLOB *blob, const void *p, ndr_push_flags_fn_t fn)
+{
+       struct ndr_push ndr = {
+               .data = blob->data,
+               .alloc_size = blob->length,
+               .fixed_buf_size = true
+       };
+
+       NDR_CHECK(fn(&ndr, NDR_SCALARS|NDR_BUFFERS, p));
+
+       if (ndr.offset != blob->length) {
+               return ndr_push_error(&ndr, NDR_ERR_BUFSIZE,
+                                     "buffer was either to large or small "
+                                     "ofs[%u] size[%zu]",
+                                     ndr.offset, blob->length);
+       }
+
+       return NDR_ERR_SUCCESS;
+}
+
 /*
   push a union to a blob using NDR
 */