r5084: - handle arbitrary data in the NULL record reply type for nbt name queries
[samba.git] / source / librpc / ndr / libndr.h
index 72d75f7d47584ca593f0af499e120d7c483c704f..5485c232b42e5d5d2c8d91b6b2bcc557ca2f0ba9 100644 (file)
@@ -47,6 +47,8 @@ struct ndr_pull {
        uint32_t offset;
 
        struct ndr_token_list *relative_list;
+       struct ndr_token_list *array_size_list;
+       struct ndr_token_list *array_length_list;
 
        /* this is used to ensure we generate unique reference IDs
           between request and reply */
@@ -99,7 +101,9 @@ struct ndr_print {
 #define LIBNDR_FLAG_STR_FIXLEN32       (1<<9)
 #define LIBNDR_FLAG_STR_CONFORMANT     (1<<10)
 #define LIBNDR_FLAG_STR_CHARLEN                (1<<11)
-#define LIBNDR_STRING_FLAGS            (0xFFC)
+#define LIBNDR_FLAG_STR_UTF8           (1<<12)
+#define LIBNDR_FLAG_STR_FIXLEN15       (1<<13)
+#define LIBNDR_STRING_FLAGS            (0x3FFC)
 
 
 #define LIBNDR_FLAG_REF_ALLOC    (1<<20)
@@ -123,6 +127,8 @@ struct ndr_print {
    offset, not base) */
 #define LIBNDR_FLAG_RELATIVE_CURRENT  (1<<29)
 
+/* set if an object uuid will be present */
+#define LIBNDR_FLAG_OBJECT_PRESENT    (1<<30)
 
 /* useful macro for debugging */
 #define NDR_PRINT_DEBUG(type, p) ndr_print_debug((ndr_print_fn_t)ndr_print_ ##type, #p, p)
@@ -146,7 +152,8 @@ enum ndr_err_code {
        NDR_ERR_VALIDATE,
        NDR_ERR_BUFSIZE,
        NDR_ERR_ALLOC,
-       NDR_ERR_RANGE
+       NDR_ERR_RANGE,
+       NDR_ERR_TOKEN
 };
 
 /*
@@ -178,7 +185,7 @@ enum ndr_err_code {
                } \
                ndr->offset = (ndr->offset + (n-1)) & ~(n-1); \
        } \
-       if (ndr->offset >= ndr->data_size) { \
+       if (ndr->offset > ndr->data_size) { \
                return ndr_pull_error(ndr, NDR_ERR_BUFSIZE, "Pull align %u", n); \
        } \
 } while(0)
@@ -192,12 +199,6 @@ enum ndr_err_code {
        } \
 } while(0)
 
-#define NDR_SIZE_ALIGN(t, n, flags) ((flags & LIBNDR_FLAG_NOALIGN)?(t):(((t) + (n-1)) & ~(n-1)))
-#define ndr_size_uint8(t, p, flags) (NDR_SIZE_ALIGN(t, 1, flags) + 1)
-#define ndr_size_uint16(t, p, flags) (NDR_SIZE_ALIGN(t, 2, flags) + 2)
-#define ndr_size_uint32(t, p, flags) (NDR_SIZE_ALIGN(t, 4, flags) + 4)
-#define ndr_size_ptr(t, p, flags) (NDR_SIZE_ALIGN(t, 4, flags) + 4)
-
 /* these are used to make the error checking on each element in libndr
    less tedious, hopefully making the code more readable */
 #define NDR_CHECK(call) do { NTSTATUS _status; \
@@ -208,7 +209,7 @@ enum ndr_err_code {
 
 
 #define NDR_ALLOC_SIZE(ndr, s, size) do { \
-                              (s) = talloc(ndr, size); \
+                              (s) = talloc_size(ndr, size); \
                                if ((size) && !(s)) return ndr_pull_error(ndr, NDR_ERR_ALLOC, \
                                                               "Alloc %u failed\n", \
                                                               size); \
@@ -218,30 +219,20 @@ enum ndr_err_code {
 
 
 #define NDR_ALLOC_N_SIZE(ndr, s, n, elsize) do { \
-                               if ((n) == 0) { \
-                                       (s) = NULL; \
-                               } else { \
-                                       (s) = talloc(ndr, (n) * elsize); \
-                                               if (!(s)) return ndr_pull_error(ndr, \
-                                                                       NDR_ERR_ALLOC, \
-                                                                       "Alloc %u * %u failed\n", \
-                                                                       n, elsize); \
-                               } \
-                           } while (0)
+       (s) = talloc_array_size(ndr, elsize, n); \
+       if (!(s)) return ndr_pull_error(ndr, NDR_ERR_ALLOC, "Alloc %u * %u failed\n", n, elsize); \
+} while (0)
 
 #define NDR_ALLOC_N(ndr, s, n) NDR_ALLOC_N_SIZE(ndr, s, n, sizeof(*(s)))
 
 
 #define NDR_PUSH_ALLOC_SIZE(ndr, s, size) do { \
-                              (s) = talloc(ndr, size); \
-                               if ((size) && !(s)) return ndr_push_error(ndr, NDR_ERR_ALLOC, \
-                                                              "push alloc %u failed\n",\
-                                                              size); \
-                           } while (0)
+       (s) = talloc_size(ndr, size); \
+       if (!(s)) return ndr_push_error(ndr, NDR_ERR_ALLOC, "push alloc %u failed\n", size); \
+} while (0)
 
 #define NDR_PUSH_ALLOC(ndr, s) NDR_PUSH_ALLOC_SIZE(ndr, s, sizeof(*(s)))
 
-
 /* these are used when generic fn pointers are needed for ndr push/pull fns */
 typedef NTSTATUS (*ndr_push_fn_t)(struct ndr_push *, void *);
 typedef NTSTATUS (*ndr_pull_fn_t)(struct ndr_pull *, void *);