r5118: added support for node status replies in nbtd. nmblookup -S now works against...
[samba.git] / source / librpc / ndr / ndr_basic.c
index 570f7719a49c308875c8021a7bf62d83ffcaa739..61b3c9ec4dcaaea8f11f23dee4db20d7caed4061 100644 (file)
 #define NDR_BE(ndr) (((ndr)->flags & (LIBNDR_FLAG_BIGENDIAN|LIBNDR_FLAG_LITTLE_ENDIAN)) == LIBNDR_FLAG_BIGENDIAN)
 #define NDR_SVAL(ndr, ofs) (NDR_BE(ndr)?RSVAL(ndr->data,ofs):SVAL(ndr->data,ofs))
 #define NDR_IVAL(ndr, ofs) (NDR_BE(ndr)?RIVAL(ndr->data,ofs):IVAL(ndr->data,ofs))
+#define NDR_IVALS(ndr, ofs) (NDR_BE(ndr)?RIVALS(ndr->data,ofs):IVALS(ndr->data,ofs))
 #define NDR_SSVAL(ndr, ofs, v) do { if (NDR_BE(ndr))  { RSSVAL(ndr->data,ofs,v); } else SSVAL(ndr->data,ofs,v); } while (0)
 #define NDR_SIVAL(ndr, ofs, v) do { if (NDR_BE(ndr))  { RSIVAL(ndr->data,ofs,v); } else SIVAL(ndr->data,ofs,v); } while (0)
+#define NDR_SIVALS(ndr, ofs, v) do { if (NDR_BE(ndr))  { RSIVALS(ndr->data,ofs,v); } else SIVALS(ndr->data,ofs,v); } while (0)
+
+
+/*
+  check for data leaks from the server by looking for non-zero pad bytes
+  these could also indicate that real structure elements have been
+  mistaken for padding in the IDL
+*/
+void ndr_check_padding(struct ndr_pull *ndr, size_t n)
+{
+       size_t ofs2 = (ndr->offset + (n-1)) & ~(n-1);
+       int i;
+       for (i=ndr->offset;i<ofs2;i++) {
+               if (ndr->data[i] != 0) {
+                       break;
+               }
+       }
+       if (i<ofs2) {
+               DEBUG(0,("WARNING: Non-zero padding to %d: ", n));
+               for (i=ndr->offset;i<ofs2;i++) {
+                       DEBUG(0,("%02x ", ndr->data[i]));
+               }
+               DEBUG(0,("\n"));
+       }
+
+}
 
 /*
   parse a uint8
 */
-NTSTATUS ndr_pull_uint8(struct ndr_pull *ndr, uint8 *v)
+NTSTATUS ndr_pull_uint8(struct ndr_pull *ndr, uint8_t *v)
 {
        NDR_PULL_NEED_BYTES(ndr, 1);
        *v = CVAL(ndr->data, ndr->offset);
@@ -43,7 +70,7 @@ NTSTATUS ndr_pull_uint8(struct ndr_pull *ndr, uint8 *v)
 /*
   parse a uint16
 */
-NTSTATUS ndr_pull_uint16(struct ndr_pull *ndr, uint16 *v)
+NTSTATUS ndr_pull_uint16(struct ndr_pull *ndr, uint16_t *v)
 {
        NDR_PULL_ALIGN(ndr, 2);
        NDR_PULL_NEED_BYTES(ndr, 2);
@@ -54,9 +81,9 @@ NTSTATUS ndr_pull_uint16(struct ndr_pull *ndr, uint16 *v)
 
 
 /*
-  parse a uint32
+  parse a uint32_t
 */
-NTSTATUS ndr_pull_uint32(struct ndr_pull *ndr, uint32 *v)
+NTSTATUS ndr_pull_uint32(struct ndr_pull *ndr, uint32_t *v)
 {
        NDR_PULL_ALIGN(ndr, 4);
        NDR_PULL_NEED_BYTES(ndr, 4);
@@ -66,24 +93,66 @@ NTSTATUS ndr_pull_uint32(struct ndr_pull *ndr, uint32 *v)
 }
 
 /*
-  parse a HYPER_T
+  parse a int32_t
 */
-NTSTATUS ndr_pull_HYPER_T(struct ndr_pull *ndr, HYPER_T *v)
+NTSTATUS ndr_pull_int32(struct ndr_pull *ndr, int32_t *v)
 {
-       NDR_PULL_ALIGN(ndr, 8);
+       NDR_PULL_ALIGN(ndr, 4);
+       NDR_PULL_NEED_BYTES(ndr, 4);
+       *v = NDR_IVALS(ndr, ndr->offset);
+       ndr->offset += 4;
+       return NT_STATUS_OK;
+}
+
+/*
+  parse a pointer
+*/
+NTSTATUS ndr_pull_ptr(struct ndr_pull *ndr, uint32_t *v)
+{
+       NTSTATUS status;
+       status = ndr_pull_uint32(ndr, v);
+       if (*v != 0) {
+               ndr->ptr_count++;
+       }
+       return status;
+}
+
+/*
+  parse a udlong
+*/
+NTSTATUS ndr_pull_udlong(struct ndr_pull *ndr, uint64_t *v)
+{
+       NDR_PULL_ALIGN(ndr, 4);
        NDR_PULL_NEED_BYTES(ndr, 8);
-       v->low = NDR_IVAL(ndr, ndr->offset);
-       v->high = NDR_IVAL(ndr, ndr->offset+4);
+       *v = NDR_IVAL(ndr, ndr->offset);
+       *v |= (uint64_t)(NDR_IVAL(ndr, ndr->offset+4)) << 32;
        ndr->offset += 8;
        return NT_STATUS_OK;
 }
 
+/*
+  parse a dlong
+*/
+NTSTATUS ndr_pull_dlong(struct ndr_pull *ndr, int64_t *v)
+{
+       return ndr_pull_udlong(ndr, (uint64_t *)v);
+}
+
+/*
+  parse a hyper
+*/
+NTSTATUS ndr_pull_hyper(struct ndr_pull *ndr, uint64_t *v)
+{
+       NDR_PULL_ALIGN(ndr, 8);
+       return ndr_pull_udlong(ndr, v);
+}
+
 /*
   pull a NTSTATUS
 */
 NTSTATUS ndr_pull_NTSTATUS(struct ndr_pull *ndr, NTSTATUS *status)
 {
-       uint32 v;
+       uint32_t v;
        NDR_CHECK(ndr_pull_uint32(ndr, &v));
        *status = NT_STATUS(v);
        return NT_STATUS_OK;
@@ -107,7 +176,7 @@ void ndr_print_NTSTATUS(struct ndr_print *ndr, const char *name, NTSTATUS *r)
 */
 NTSTATUS ndr_pull_WERROR(struct ndr_pull *ndr, WERROR *status)
 {
-       uint32 v;
+       uint32_t v;
        NDR_CHECK(ndr_pull_uint32(ndr, &v));
        *status = W_ERROR(v);
        return NT_STATUS_OK;
@@ -121,15 +190,15 @@ NTSTATUS ndr_push_WERROR(struct ndr_push *ndr, WERROR status)
        return ndr_push_uint32(ndr, W_ERROR_V(status));
 }
 
-void ndr_print_WERROR(struct ndr_print *ndr, const char *name, WERROR *r)
+void ndr_print_WERROR(struct ndr_print *ndr, const char *name, WERROR r)
 {
-       ndr->print(ndr, "%-25s: %s", name, win_errstr(*r));
+       ndr->print(ndr, "%-25s: %s", name, win_errstr(r));
 }
 
 /*
   parse a set of bytes
 */
-NTSTATUS ndr_pull_bytes(struct ndr_pull *ndr, char *data, uint32 n)
+NTSTATUS ndr_pull_bytes(struct ndr_pull *ndr, uint8_t *data, uint32_t n)
 {
        NDR_PULL_NEED_BYTES(ndr, n);
        memcpy(data, ndr->data + ndr->offset, n);
@@ -140,7 +209,7 @@ NTSTATUS ndr_pull_bytes(struct ndr_pull *ndr, char *data, uint32 n)
 /*
   pull an array of uint8
 */
-NTSTATUS ndr_pull_array_uint8(struct ndr_pull *ndr, int ndr_flags, char *data, uint32 n)
+NTSTATUS ndr_pull_array_uint8(struct ndr_pull *ndr, int ndr_flags, uint8_t *data, uint32_t n)
 {
        if (!(ndr_flags & NDR_SCALARS)) {
                return NT_STATUS_OK;
@@ -152,9 +221,9 @@ NTSTATUS ndr_pull_array_uint8(struct ndr_pull *ndr, int ndr_flags, char *data, u
 /*
   pull an array of uint16
 */
-NTSTATUS ndr_pull_array_uint16(struct ndr_pull *ndr, int ndr_flags, uint16 *data, uint32 n)
+NTSTATUS ndr_pull_array_uint16(struct ndr_pull *ndr, int ndr_flags, uint16_t *data, uint32_t n)
 {
-       uint32 i;
+       uint32_t i;
        if (!(ndr_flags & NDR_SCALARS)) {
                return NT_STATUS_OK;
        }
@@ -165,11 +234,11 @@ NTSTATUS ndr_pull_array_uint16(struct ndr_pull *ndr, int ndr_flags, uint16 *data
 }
 
 /*
-  pull a const array of uint32
+  pull a const array of uint32_t
 */
-NTSTATUS ndr_pull_array_uint32(struct ndr_pull *ndr, int ndr_flags, uint32 *data, uint32 n)
+NTSTATUS ndr_pull_array_uint32(struct ndr_pull *ndr, int ndr_flags, uint32_t *data, uint32_t n)
 {
-       uint32 i;
+       uint32_t i;
        if (!(ndr_flags & NDR_SCALARS)) {
                return NT_STATUS_OK;
        }
@@ -179,10 +248,42 @@ NTSTATUS ndr_pull_array_uint32(struct ndr_pull *ndr, int ndr_flags, uint32 *data
        return NT_STATUS_OK;
 }
 
+/*
+  pull a const array of hyper
+*/
+NTSTATUS ndr_pull_array_hyper(struct ndr_pull *ndr, int ndr_flags, uint64_t *data, uint32_t n)
+{
+       uint32_t i;
+       if (!(ndr_flags & NDR_SCALARS)) {
+               return NT_STATUS_OK;
+       }
+       for (i=0;i<n;i++) {
+               NDR_CHECK(ndr_pull_hyper(ndr, &data[i]));
+       }
+       return NT_STATUS_OK;
+}
+
+/*
+  pull a const array of WERROR
+*/
+NTSTATUS ndr_pull_array_WERROR(struct ndr_pull *ndr, int ndr_flags, WERROR *data, uint32_t n)
+{
+       uint32_t i;
+       if (!(ndr_flags & NDR_SCALARS)) {
+               return NT_STATUS_OK;
+       }
+       for (i=0;i<n;i++) {
+               NDR_CHECK(ndr_pull_WERROR(ndr, &data[i]));
+       }
+       return NT_STATUS_OK;
+}
+
+
+
 /*
   push a uint8
 */
-NTSTATUS ndr_push_uint8(struct ndr_push *ndr, uint8 v)
+NTSTATUS ndr_push_uint8(struct ndr_push *ndr, uint8_t v)
 {
        NDR_PUSH_NEED_BYTES(ndr, 1);
        SCVAL(ndr->data, ndr->offset, v);
@@ -193,7 +294,7 @@ NTSTATUS ndr_push_uint8(struct ndr_push *ndr, uint8 v)
 /*
   push a uint16
 */
-NTSTATUS ndr_push_uint16(struct ndr_push *ndr, uint16 v)
+NTSTATUS ndr_push_uint16(struct ndr_push *ndr, uint16_t v)
 {
        NDR_PUSH_ALIGN(ndr, 2);
        NDR_PUSH_NEED_BYTES(ndr, 2);
@@ -203,9 +304,9 @@ NTSTATUS ndr_push_uint16(struct ndr_push *ndr, uint16 v)
 }
 
 /*
-  push a uint32
+  push a uint32_t
 */
-NTSTATUS ndr_push_uint32(struct ndr_push *ndr, uint32 v)
+NTSTATUS ndr_push_uint32(struct ndr_push *ndr, uint32_t v)
 {
        NDR_PUSH_ALIGN(ndr, 4);
        NDR_PUSH_NEED_BYTES(ndr, 4);
@@ -215,18 +316,47 @@ NTSTATUS ndr_push_uint32(struct ndr_push *ndr, uint32 v)
 }
 
 /*
-  push a HYPER_T
+  push a int32_t
 */
-NTSTATUS ndr_push_HYPER_T(struct ndr_push *ndr, HYPER_T v)
+NTSTATUS ndr_push_int32(struct ndr_push *ndr, int32_t v)
 {
-       NDR_PUSH_ALIGN(ndr, 8);
+       NDR_PUSH_ALIGN(ndr, 4);
+       NDR_PUSH_NEED_BYTES(ndr, 4);
+       NDR_SIVALS(ndr, ndr->offset, v);
+       ndr->offset += 4;
+       return NT_STATUS_OK;
+}
+
+/*
+  push a uint64
+*/
+NTSTATUS ndr_push_udlong(struct ndr_push *ndr, uint64_t v)
+{
+       NDR_PUSH_ALIGN(ndr, 4);
        NDR_PUSH_NEED_BYTES(ndr, 8);
-       NDR_SIVAL(ndr, ndr->offset, v.low);
-       NDR_SIVAL(ndr, ndr->offset+4, v.high);
+       NDR_SIVAL(ndr, ndr->offset, (v & 0xFFFFFFFF));
+       NDR_SIVAL(ndr, ndr->offset+4, (v>>32));
        ndr->offset += 8;
        return NT_STATUS_OK;
 }
 
+/*
+  push a int64
+*/
+NTSTATUS ndr_push_dlong(struct ndr_push *ndr, int64_t v)
+{
+       return ndr_push_udlong(ndr, (uint64_t)v);
+}
+
+/*
+  push a hyper
+*/
+NTSTATUS ndr_push_hyper(struct ndr_push *ndr, uint64_t v)
+{
+       NDR_PUSH_ALIGN(ndr, 8);
+       return ndr_push_udlong(ndr, v);
+}
+
 NTSTATUS ndr_push_align(struct ndr_push *ndr, size_t size)
 {
        NDR_PUSH_ALIGN(ndr, size);
@@ -242,7 +372,7 @@ NTSTATUS ndr_pull_align(struct ndr_pull *ndr, size_t size)
 /*
   push some bytes
 */
-NTSTATUS ndr_push_bytes(struct ndr_push *ndr, const char *data, uint32 n)
+NTSTATUS ndr_push_bytes(struct ndr_push *ndr, const uint8_t *data, uint32_t n)
 {
        NDR_PUSH_NEED_BYTES(ndr, n);
        memcpy(ndr->data + ndr->offset, data, n);
@@ -253,7 +383,7 @@ NTSTATUS ndr_push_bytes(struct ndr_push *ndr, const char *data, uint32 n)
 /*
   push some zero bytes
 */
-NTSTATUS ndr_push_zero(struct ndr_push *ndr, uint32 n)
+NTSTATUS ndr_push_zero(struct ndr_push *ndr, uint32_t n)
 {
        NDR_PUSH_NEED_BYTES(ndr, n);
        memset(ndr->data + ndr->offset, 0, n);
@@ -264,7 +394,7 @@ NTSTATUS ndr_push_zero(struct ndr_push *ndr, uint32 n)
 /*
   push an array of uint8
 */
-NTSTATUS ndr_push_array_uint8(struct ndr_push *ndr, int ndr_flags, const char *data, uint32 n)
+NTSTATUS ndr_push_array_uint8(struct ndr_push *ndr, int ndr_flags, const uint8_t *data, uint32_t n)
 {
        if (!(ndr_flags & NDR_SCALARS)) {
                return NT_STATUS_OK;
@@ -275,7 +405,7 @@ NTSTATUS ndr_push_array_uint8(struct ndr_push *ndr, int ndr_flags, const char *d
 /*
   push an array of uint16
 */
-NTSTATUS ndr_push_array_uint16(struct ndr_push *ndr, int ndr_flags, const uint16 *data, uint32 n)
+NTSTATUS ndr_push_array_uint16(struct ndr_push *ndr, int ndr_flags, const uint16_t *data, uint32_t n)
 {
        int i;
        if (!(ndr_flags & NDR_SCALARS)) {
@@ -288,9 +418,9 @@ NTSTATUS ndr_push_array_uint16(struct ndr_push *ndr, int ndr_flags, const uint16
 }
 
 /*
-  push an array of uint32
+  push an array of uint32_t
 */
-NTSTATUS ndr_push_array_uint32(struct ndr_push *ndr, int ndr_flags, const uint32 *data, uint32 n)
+NTSTATUS ndr_push_array_uint32(struct ndr_push *ndr, int ndr_flags, const uint32_t *data, uint32_t n)
 {
        int i;
        if (!(ndr_flags & NDR_SCALARS)) {
@@ -302,6 +432,36 @@ NTSTATUS ndr_push_array_uint32(struct ndr_push *ndr, int ndr_flags, const uint32
        return NT_STATUS_OK;
 }
 
+/*
+  push an array of hyper
+*/
+NTSTATUS ndr_push_array_hyper(struct ndr_push *ndr, int ndr_flags, const uint64_t *data, uint32_t n)
+{
+       int i;
+       if (!(ndr_flags & NDR_SCALARS)) {
+               return NT_STATUS_OK;
+       }
+       for (i=0;i<n;i++) {
+               NDR_CHECK(ndr_push_hyper(ndr, data[i]));
+       }
+       return NT_STATUS_OK;
+}
+
+/*
+  push an array of hyper
+*/
+NTSTATUS ndr_push_array_WERROR(struct ndr_push *ndr, int ndr_flags, const WERROR *data, uint32_t n)
+{
+       int i;
+       if (!(ndr_flags & NDR_SCALARS)) {
+               return NT_STATUS_OK;
+       }
+       for (i=0;i<n;i++) {
+               NDR_CHECK(ndr_push_WERROR(ndr, data[i]));
+       }
+       return NT_STATUS_OK;
+}
+
 /*
   save the current position
  */
@@ -323,7 +483,7 @@ void ndr_push_restore(struct ndr_push *ndr, struct ndr_push_save *save)
 */
 NTSTATUS ndr_push_ptr(struct ndr_push *ndr, const void *p)
 {
-       uint32 ptr = 0;
+       uint32_t ptr = 0;
        if (p) {
                /* we do this to ensure that we generate unique ref ids,
                   which means we can handle the case where a MS programmer
@@ -341,24 +501,49 @@ NTSTATUS ndr_push_ptr(struct ndr_push *ndr, const void *p)
 NTSTATUS ndr_pull_string(struct ndr_pull *ndr, int ndr_flags, const char **s)
 {
        char *as=NULL;
-       uint32 len1, ofs, len2;
-       uint16 len3;
+       uint32_t len1, ofs, len2;
+       uint16_t len3;
        int ret;
-       int chset = CH_UCS2;
+       int chset = CH_UTF16;
+       unsigned byte_mul = 2;
+       unsigned flags = ndr->flags;
+       unsigned c_len_term = 0;
 
        if (!(ndr_flags & NDR_SCALARS)) {
                return NT_STATUS_OK;
        }
 
        if (NDR_BE(ndr)) {
-               chset = CH_UCS2BE;
+               chset = CH_UTF16BE;
+       }
+
+       if (flags & LIBNDR_FLAG_STR_ASCII) {
+               chset = CH_DOS;
+               byte_mul = 1;
+               flags &= ~LIBNDR_FLAG_STR_ASCII;
+       }
+
+       if (flags & LIBNDR_FLAG_STR_UTF8) {
+               chset = CH_UTF8;
+               byte_mul = 1;
+               flags &= ~LIBNDR_FLAG_STR_UTF8;
+       }
+
+       flags &= ~LIBNDR_FLAG_STR_CONFORMANT;
+       if (flags & LIBNDR_FLAG_STR_CHARLEN) {
+               c_len_term = 1;
+               flags &= ~LIBNDR_FLAG_STR_CHARLEN;
        }
 
-       switch (ndr->flags & LIBNDR_STRING_FLAGS) {
+       switch (flags & LIBNDR_STRING_FLAGS) {
        case LIBNDR_FLAG_STR_LEN4|LIBNDR_FLAG_STR_SIZE4:
        case LIBNDR_FLAG_STR_LEN4|LIBNDR_FLAG_STR_SIZE4|LIBNDR_FLAG_STR_NOTERM:
                NDR_CHECK(ndr_pull_uint32(ndr, &len1));
                NDR_CHECK(ndr_pull_uint32(ndr, &ofs));
+               if (ofs != 0) {
+                       return ndr_pull_error(ndr, NDR_ERR_STRING, "non-zero array offset with string flags 0x%x\n",
+                                             ndr->flags & LIBNDR_STRING_FLAGS);
+               }
                NDR_CHECK(ndr_pull_uint32(ndr, &len2));
                if (len2 > len1) {
                        return ndr_pull_error(ndr, NDR_ERR_STRING, 
@@ -366,88 +551,187 @@ NTSTATUS ndr_pull_string(struct ndr_pull *ndr, int ndr_flags, const char **s)
                                              len1, ofs, len2);
                }
                if (len2 == 0) {
-                       *s = talloc_strdup(ndr->mem_ctx, "");
+                       *s = talloc_strdup(ndr, "");
                        break;
                }
-               NDR_PULL_NEED_BYTES(ndr, len2*2);
-               ret = convert_string_talloc(ndr->mem_ctx, chset, CH_UNIX, 
+               NDR_PULL_NEED_BYTES(ndr, (len2 + c_len_term)*byte_mul);
+               ret = convert_string_talloc(ndr, chset, CH_UNIX, 
                                            ndr->data+ndr->offset, 
-                                           len2*2,
-                                           (const void **)&as);
+                                           (len2 + c_len_term)*byte_mul,
+                                           (void **)&as);
                if (ret == -1) {
                        return ndr_pull_error(ndr, NDR_ERR_CHARCNV, 
                                              "Bad character conversion");
                }
-               NDR_CHECK(ndr_pull_advance(ndr, len2*2));
+               NDR_CHECK(ndr_pull_advance(ndr, (len2 + c_len_term)*byte_mul));
+
+               /* this is a way of detecting if a string is sent with the wrong
+                  termination */
+               if (ndr->flags & LIBNDR_FLAG_STR_NOTERM) {
+                       if (strlen(as) < (len2 + c_len_term)) {
+                               DEBUG(6,("short string '%s'\n", as));
+                       }
+               } else {
+                       if (strlen(as) == (len2 + c_len_term)) {
+                               DEBUG(6,("long string '%s'\n", as));
+                       }
+               }
                *s = as;
                break;
 
        case LIBNDR_FLAG_STR_SIZE4:
+       case LIBNDR_FLAG_STR_SIZE4|LIBNDR_FLAG_STR_NOTERM:
                NDR_CHECK(ndr_pull_uint32(ndr, &len1));
-               NDR_PULL_NEED_BYTES(ndr, len1*2);
+               NDR_PULL_NEED_BYTES(ndr, (len1 + c_len_term)*byte_mul);
                if (len1 == 0) {
-                       *s = talloc_strdup(ndr->mem_ctx, "");
+                       *s = talloc_strdup(ndr, "");
                        break;
                }
-               ret = convert_string_talloc(ndr->mem_ctx, chset, CH_UNIX, 
+               ret = convert_string_talloc(ndr, chset, CH_UNIX, 
                                            ndr->data+ndr->offset, 
-                                           len1*2,
-                                           (const void **)&as);
+                                           (len1 + c_len_term)*byte_mul,
+                                           (void **)&as);
                if (ret == -1) {
                        return ndr_pull_error(ndr, NDR_ERR_CHARCNV, 
                                              "Bad character conversion");
                }
-               NDR_CHECK(ndr_pull_advance(ndr, len1*2));
+               NDR_CHECK(ndr_pull_advance(ndr, (len1 + c_len_term)*byte_mul));
+
+               /* this is a way of detecting if a string is sent with the wrong
+                  termination */
+               if (ndr->flags & LIBNDR_FLAG_STR_NOTERM) {
+                       if (strlen(as) < (len1 + c_len_term)) {
+                               DEBUG(6,("short string '%s'\n", as));
+                       }
+               } else {
+                       if (strlen(as) == (len1 + c_len_term)) {
+                               DEBUG(6,("long string '%s'\n", as));
+                       }
+               }
                *s = as;
                break;
 
-       case LIBNDR_FLAG_STR_NULLTERM:
-               len1 = strnlen_w(ndr->data+ndr->offset, 
-                                (ndr->data_size - ndr->offset)/2);
-               if (len1*2+2 <= ndr->data_size - ndr->offset) {
-                       len1++;
+       case LIBNDR_FLAG_STR_LEN4:
+       case LIBNDR_FLAG_STR_LEN4|LIBNDR_FLAG_STR_NOTERM:
+               NDR_CHECK(ndr_pull_uint32(ndr, &ofs));
+               if (ofs != 0) {
+                       return ndr_pull_error(ndr, NDR_ERR_STRING, "non-zero array offset with string flags 0x%x\n",
+                                             ndr->flags & LIBNDR_STRING_FLAGS);
                }
-               ret = convert_string_talloc(ndr->mem_ctx, chset, CH_UNIX, 
+               NDR_CHECK(ndr_pull_uint32(ndr, &len1));
+               NDR_PULL_NEED_BYTES(ndr, (len1 + c_len_term)*byte_mul);
+               if (len1 == 0) {
+                       *s = talloc_strdup(ndr, "");
+                       break;
+               }
+               ret = convert_string_talloc(ndr, chset, CH_UNIX, 
                                            ndr->data+ndr->offset, 
-                                           len1*2,
-                                           (const void **)s);
+                                           (len1 + c_len_term)*byte_mul,
+                                           (void **)&as);
                if (ret == -1) {
                        return ndr_pull_error(ndr, NDR_ERR_CHARCNV, 
                                              "Bad character conversion");
                }
-               NDR_CHECK(ndr_pull_advance(ndr, len1*2));
+               NDR_CHECK(ndr_pull_advance(ndr, (len1 + c_len_term)*byte_mul));
+
+               /* this is a way of detecting if a string is sent with the wrong
+                  termination */
+               if (ndr->flags & LIBNDR_FLAG_STR_NOTERM) {
+                       if (strlen(as) < (len1 + c_len_term)) {
+                               DEBUG(6,("short string '%s'\n", as));
+                       }
+               } else {
+                       if (strlen(as) == (len1 + c_len_term)) {
+                               DEBUG(6,("long string '%s'\n", as));
+                       }
+               }
+               *s = as;
                break;
 
-       case LIBNDR_FLAG_STR_ASCII|LIBNDR_FLAG_STR_LEN4|LIBNDR_FLAG_STR_SIZE4:
-               NDR_CHECK(ndr_pull_uint32(ndr, &len1));
-               NDR_CHECK(ndr_pull_uint32(ndr, &ofs));
-               NDR_CHECK(ndr_pull_uint32(ndr, &len2));
-               if (len2 > len1) {
-                       return ndr_pull_error(ndr, NDR_ERR_STRING, 
-                                             "Bad ascii string lengths len1=%u ofs=%u len2=%u\n", 
-                                             len1, ofs, len2);
+
+       case LIBNDR_FLAG_STR_SIZE2:
+       case LIBNDR_FLAG_STR_SIZE2|LIBNDR_FLAG_STR_NOTERM:
+               NDR_CHECK(ndr_pull_uint16(ndr, &len3));
+               NDR_PULL_NEED_BYTES(ndr, (len3 + c_len_term)*byte_mul);
+               if (len3 == 0) {
+                       *s = talloc_strdup(ndr, "");
+                       break;
+               }
+               ret = convert_string_talloc(ndr, chset, CH_UNIX, 
+                                           ndr->data+ndr->offset, 
+                                           (len3 + c_len_term)*byte_mul,
+                                           (void **)&as);
+               if (ret == -1) {
+                       return ndr_pull_error(ndr, NDR_ERR_CHARCNV, 
+                                             "Bad character conversion");
+               }
+               NDR_CHECK(ndr_pull_advance(ndr, (len3 + c_len_term)*byte_mul));
+
+               /* this is a way of detecting if a string is sent with the wrong
+                  termination */
+               if (ndr->flags & LIBNDR_FLAG_STR_NOTERM) {
+                       if (strlen(as) < (len3 + c_len_term)) {
+                               DEBUG(6,("short string '%s'\n", as));
+                       }
+               } else {
+                       if (strlen(as) == (len3 + c_len_term)) {
+                               DEBUG(6,("long string '%s'\n", as));
+                       }
                }
-               NDR_ALLOC_N(ndr, as, (len2+1));
-               NDR_CHECK(ndr_pull_bytes(ndr, as, len2));
-               as[len2] = 0;
-               (*s) = as;
+               *s = as;
                break;
 
-       case LIBNDR_FLAG_STR_ASCII|LIBNDR_FLAG_STR_LEN4:
-               NDR_CHECK(ndr_pull_uint32(ndr, &ofs));
-               NDR_CHECK(ndr_pull_uint32(ndr, &len2));
-               NDR_ALLOC_N(ndr, as, (len2+1));
-               NDR_CHECK(ndr_pull_bytes(ndr, as, len2));
-               as[len2] = 0;
-               (*s) = as;
+       case LIBNDR_FLAG_STR_SIZE2|LIBNDR_FLAG_STR_NOTERM|LIBNDR_FLAG_STR_BYTESIZE:
+               NDR_CHECK(ndr_pull_uint16(ndr, &len3));
+               NDR_PULL_NEED_BYTES(ndr, len3);
+               if (len3 == 0) {
+                       *s = talloc_strdup(ndr, "");
+                       break;
+               }
+               ret = convert_string_talloc(ndr, chset, CH_UNIX, 
+                                           ndr->data+ndr->offset, 
+                                           len3,
+                                           (void **)&as);
+               if (ret == -1) {
+                       return ndr_pull_error(ndr, NDR_ERR_CHARCNV, 
+                                             "Bad character conversion");
+               }
+               NDR_CHECK(ndr_pull_advance(ndr, len3));
+               *s = as;
                break;
 
-       case LIBNDR_FLAG_STR_ASCII|LIBNDR_FLAG_STR_SIZE2:
-               NDR_CHECK(ndr_pull_uint16(ndr, &len3));
-               NDR_ALLOC_N(ndr, as, (len3+1));
-               NDR_CHECK(ndr_pull_bytes(ndr, as, len3));
-               as[len3] = 0;
-               (*s) = as;
+       case LIBNDR_FLAG_STR_NULLTERM:
+               if (byte_mul == 1) {
+                       len1 = ascii_len_n((const char *)(ndr->data+ndr->offset), ndr->data_size - ndr->offset);
+               } else {
+                       len1 = utf16_len_n(ndr->data+ndr->offset, ndr->data_size - ndr->offset);
+               }
+               ret = convert_string_talloc(ndr, chset, CH_UNIX, 
+                                           ndr->data+ndr->offset, 
+                                           len1,
+                                           (void **)&as);
+               if (ret == -1) {
+                       return ndr_pull_error(ndr, NDR_ERR_CHARCNV, 
+                                             "Bad character conversion");
+               }
+               NDR_CHECK(ndr_pull_advance(ndr, len1));
+               *s = as;
+               break;
+
+       case LIBNDR_FLAG_STR_FIXLEN15:
+       case LIBNDR_FLAG_STR_FIXLEN32:
+               len1 = (flags & LIBNDR_FLAG_STR_FIXLEN32)?32:15;
+               NDR_PULL_NEED_BYTES(ndr, len1*byte_mul);
+               ret = convert_string_talloc(ndr, chset, CH_UNIX, 
+                                           ndr->data+ndr->offset, 
+                                           len1*byte_mul,
+                                           (void **)&as);
+               if (ret == -1) {
+                       return ndr_pull_error(ndr, NDR_ERR_CHARCNV, 
+                                             "Bad character conversion");
+               }
+               NDR_CHECK(ndr_pull_advance(ndr, len1*byte_mul));
+               *s = as;
                break;
 
        default:
@@ -464,117 +748,152 @@ NTSTATUS ndr_pull_string(struct ndr_pull *ndr, int ndr_flags, const char **s)
 */
 NTSTATUS ndr_push_string(struct ndr_push *ndr, int ndr_flags, const char *s)
 {
-       ssize_t s_len, c_len;
+       ssize_t s_len, c_len, d_len;
        int ret;
-       int chset = CH_UCS2;
+       int chset = CH_UTF16;
+       unsigned flags = ndr->flags;
+       unsigned byte_mul = 2;
+       unsigned c_len_term = 1;
 
        if (!(ndr_flags & NDR_SCALARS)) {
                return NT_STATUS_OK;
        }
 
        if (NDR_BE(ndr)) {
-               chset = CH_UCS2BE;
+               chset = CH_UTF16BE;
        }
        
        s_len = s?strlen(s):0;
        c_len = s?strlen_m(s):0;
 
-       switch (ndr->flags & LIBNDR_STRING_FLAGS) {
+       if (flags & LIBNDR_FLAG_STR_ASCII) {
+               chset = CH_DOS;
+               byte_mul = 1;
+               flags &= ~LIBNDR_FLAG_STR_ASCII;
+       }
+
+       if (flags & LIBNDR_FLAG_STR_UTF8) {
+               chset = CH_UTF8;
+               byte_mul = 1;
+               flags &= ~LIBNDR_FLAG_STR_UTF8;
+       }
+
+       flags &= ~LIBNDR_FLAG_STR_CONFORMANT;
+
+       if (flags & LIBNDR_FLAG_STR_CHARLEN) {
+               c_len_term = 0;
+               flags &= ~LIBNDR_FLAG_STR_CHARLEN;
+       }
+
+       switch (flags & LIBNDR_STRING_FLAGS) {
        case LIBNDR_FLAG_STR_LEN4|LIBNDR_FLAG_STR_SIZE4:
-               NDR_CHECK(ndr_push_uint32(ndr, c_len+1));
+               NDR_CHECK(ndr_push_uint32(ndr, c_len+c_len_term));
                NDR_CHECK(ndr_push_uint32(ndr, 0));
-               NDR_CHECK(ndr_push_uint32(ndr, c_len+1));
-               NDR_PUSH_NEED_BYTES(ndr, c_len*2 + 2);
+               NDR_CHECK(ndr_push_uint32(ndr, c_len+c_len_term));
+               NDR_PUSH_NEED_BYTES(ndr, byte_mul*(c_len+1));
                ret = convert_string(CH_UNIX, chset, 
                                     s, s_len+1,
-                                    ndr->data+ndr->offset, c_len*2 + 2);
+                                    ndr->data+ndr->offset, 
+                                    byte_mul*(c_len+1));
                if (ret == -1) {
                        return ndr_push_error(ndr, NDR_ERR_CHARCNV, 
                                              "Bad character conversion");
                }
-               ndr->offset += c_len*2 + 2;
+               ndr->offset += byte_mul*(c_len+1);
                break;
 
        case LIBNDR_FLAG_STR_LEN4|LIBNDR_FLAG_STR_SIZE4|LIBNDR_FLAG_STR_NOTERM:
                NDR_CHECK(ndr_push_uint32(ndr, c_len));
                NDR_CHECK(ndr_push_uint32(ndr, 0));
                NDR_CHECK(ndr_push_uint32(ndr, c_len));
-               NDR_PUSH_NEED_BYTES(ndr, c_len*2);
+               NDR_PUSH_NEED_BYTES(ndr, c_len*byte_mul);
                ret = convert_string(CH_UNIX, chset, 
                                     s, s_len,
-                                    ndr->data+ndr->offset, c_len*2);
+                                    ndr->data+ndr->offset, c_len*byte_mul);
                if (ret == -1) {
                        return ndr_push_error(ndr, NDR_ERR_CHARCNV, 
                                              "Bad character conversion");
                }
-               ndr->offset += c_len*2;
+               ndr->offset += c_len*byte_mul;
                break;
 
-       case LIBNDR_FLAG_STR_SIZE4:
-               NDR_CHECK(ndr_push_uint32(ndr, c_len + 1));
-               NDR_PUSH_NEED_BYTES(ndr, c_len*2 + 2);
+       case LIBNDR_FLAG_STR_LEN4:
+               NDR_CHECK(ndr_push_uint32(ndr, 0));
+               NDR_CHECK(ndr_push_uint32(ndr, c_len + c_len_term));
+               NDR_PUSH_NEED_BYTES(ndr, byte_mul*(c_len+1));
                ret = convert_string(CH_UNIX, chset, 
                                     s, s_len + 1,
-                                    ndr->data+ndr->offset, c_len*2 + 2);
+                                    ndr->data+ndr->offset, byte_mul*(c_len+1));
                if (ret == -1) {
                        return ndr_push_error(ndr, NDR_ERR_CHARCNV, 
                                              "Bad character conversion");
                }
-               ndr->offset += c_len*2 + 2;
+               ndr->offset += byte_mul*(c_len+1);
                break;
 
-       case LIBNDR_FLAG_STR_NULLTERM:
-               NDR_PUSH_NEED_BYTES(ndr, c_len*2 + 2);
+       case LIBNDR_FLAG_STR_SIZE4:
+               NDR_CHECK(ndr_push_uint32(ndr, c_len + c_len_term));
+               NDR_PUSH_NEED_BYTES(ndr, byte_mul*(c_len+1));
                ret = convert_string(CH_UNIX, chset, 
-                                    s, s_len+1,
-                                    ndr->data+ndr->offset, c_len*2 + 2);
+                                    s, s_len + 1,
+                                    ndr->data+ndr->offset, byte_mul*(c_len+1));
                if (ret == -1) {
                        return ndr_push_error(ndr, NDR_ERR_CHARCNV, 
                                              "Bad character conversion");
                }
-               ndr->offset += c_len*2 + 2;
+               ndr->offset += byte_mul*(c_len+1);
                break;
-               
-       case LIBNDR_FLAG_STR_ASCII|LIBNDR_FLAG_STR_LEN4|LIBNDR_FLAG_STR_SIZE4:
-               NDR_CHECK(ndr_push_uint32(ndr, c_len+1));
-               NDR_CHECK(ndr_push_uint32(ndr, 0));
-               NDR_CHECK(ndr_push_uint32(ndr, c_len+1));
-               NDR_PUSH_NEED_BYTES(ndr, c_len + 1);
-               ret = convert_string(CH_UNIX, CH_DOS, 
+
+       case LIBNDR_FLAG_STR_SIZE2:
+               NDR_CHECK(ndr_push_uint16(ndr, c_len + c_len_term));
+               NDR_PUSH_NEED_BYTES(ndr, byte_mul*(c_len+1));
+               ret = convert_string(CH_UNIX, chset, 
                                     s, s_len + 1,
-                                    ndr->data+ndr->offset, c_len + 1);
+                                    ndr->data+ndr->offset, byte_mul*(c_len+1));
                if (ret == -1) {
                        return ndr_push_error(ndr, NDR_ERR_CHARCNV, 
                                              "Bad character conversion");
                }
-               ndr->offset += c_len + 1;
+               ndr->offset += byte_mul*(c_len+1);
                break;
 
-       case LIBNDR_FLAG_STR_ASCII|LIBNDR_FLAG_STR_LEN4:
-               NDR_CHECK(ndr_push_uint32(ndr, 0));
-               NDR_CHECK(ndr_push_uint32(ndr, c_len+1));
-               NDR_PUSH_NEED_BYTES(ndr, c_len + 1);
-               ret = convert_string(CH_UNIX, CH_DOS, 
-                                    s, s_len + 1,
-                                    ndr->data+ndr->offset, c_len + 1);
+       case LIBNDR_FLAG_STR_NULLTERM:
+               NDR_PUSH_NEED_BYTES(ndr, byte_mul*(c_len+1));
+               ret = convert_string(CH_UNIX, chset, 
+                                    s, s_len+1,
+                                    ndr->data+ndr->offset, byte_mul*(c_len+1));
                if (ret == -1) {
                        return ndr_push_error(ndr, NDR_ERR_CHARCNV, 
                                              "Bad character conversion");
                }
-               ndr->offset += c_len + 1;
+               ndr->offset += byte_mul*(c_len+1);
                break;
 
-       case LIBNDR_FLAG_STR_ASCII|LIBNDR_FLAG_STR_SIZE2:
-               NDR_CHECK(ndr_push_uint16(ndr, c_len+1));
-               NDR_PUSH_NEED_BYTES(ndr, c_len + 1);
-               ret = convert_string(CH_UNIX, CH_DOS, 
-                                    s, s_len + 1,
-                                    ndr->data+ndr->offset, c_len + 1);
+       case LIBNDR_FLAG_STR_SIZE2|LIBNDR_FLAG_STR_NOTERM|LIBNDR_FLAG_STR_BYTESIZE:
+               NDR_CHECK(ndr_push_uint16(ndr, c_len*byte_mul));
+               NDR_PUSH_NEED_BYTES(ndr, c_len*byte_mul);
+               ret = convert_string(CH_UNIX, chset, 
+                                    s, s_len,
+                                    ndr->data+ndr->offset, c_len*byte_mul);
+               if (ret == -1) {
+                       return ndr_push_error(ndr, NDR_ERR_CHARCNV, 
+                                             "Bad character conversion");
+               }
+               ndr->offset += c_len*byte_mul;
+               break;
+
+       case LIBNDR_FLAG_STR_FIXLEN15:
+       case LIBNDR_FLAG_STR_FIXLEN32:
+               d_len = (flags & LIBNDR_FLAG_STR_FIXLEN32)?32:15;
+               NDR_PUSH_NEED_BYTES(ndr, byte_mul*d_len);
+               ret = convert_string(CH_UNIX, chset, 
+                                    s, s_len,
+                                    ndr->data+ndr->offset, byte_mul*d_len);
                if (ret == -1) {
                        return ndr_push_error(ndr, NDR_ERR_CHARCNV, 
                                              "Bad character conversion");
                }
-               ndr->offset += c_len + 1;
+               ndr->offset += byte_mul*d_len;
                break;
 
        default:
@@ -585,13 +904,49 @@ NTSTATUS ndr_push_string(struct ndr_push *ndr, int ndr_flags, const char *s)
        return NT_STATUS_OK;
 }
 
+/*
+  push a general string onto the wire
+*/
+size_t ndr_string_array_size(struct ndr_push *ndr, const char *s)
+{
+       size_t c_len;
+       unsigned flags = ndr->flags;
+       unsigned byte_mul = 2;
+       unsigned c_len_term = 1;
+
+       if (flags & LIBNDR_FLAG_STR_FIXLEN32) {
+               return 32;
+       }
+       if (flags & LIBNDR_FLAG_STR_FIXLEN15) {
+               return 15;
+       }
+       
+       c_len = s?strlen_m(s):0;
+
+       if (flags & (LIBNDR_FLAG_STR_ASCII|LIBNDR_FLAG_STR_UTF8)) {
+               byte_mul = 1;
+       }
+
+       if (flags & LIBNDR_FLAG_STR_NOTERM) {
+               c_len_term = 0;
+       }
+
+       c_len = c_len + c_len_term;
+
+       if (flags & LIBNDR_FLAG_STR_BYTESIZE) {
+               c_len = c_len * byte_mul;
+       }
+
+       return c_len;
+}
+
+
 /*
   push a NTTIME
 */
 NTSTATUS ndr_push_NTTIME(struct ndr_push *ndr, NTTIME t)
 {
-       NDR_CHECK(ndr_push_uint32(ndr, t.low));
-       NDR_CHECK(ndr_push_uint32(ndr, t.high));
+       NDR_CHECK(ndr_push_udlong(ndr, t));
        return NT_STATUS_OK;
 }
 
@@ -600,8 +955,45 @@ NTSTATUS ndr_push_NTTIME(struct ndr_push *ndr, NTTIME t)
 */
 NTSTATUS ndr_pull_NTTIME(struct ndr_pull *ndr, NTTIME *t)
 {
-       NDR_CHECK(ndr_pull_uint32(ndr, &t->low));
-       NDR_CHECK(ndr_pull_uint32(ndr, &t->high));
+       NDR_CHECK(ndr_pull_udlong(ndr, t));
+       return NT_STATUS_OK;
+}
+
+/*
+  push a NTTIME
+*/
+NTSTATUS ndr_push_NTTIME_1sec(struct ndr_push *ndr, NTTIME t)
+{
+       t /= 10000000;
+       NDR_CHECK(ndr_push_hyper(ndr, t));
+       return NT_STATUS_OK;
+}
+
+/*
+  pull a NTTIME_1sec
+*/
+NTSTATUS ndr_pull_NTTIME_1sec(struct ndr_pull *ndr, NTTIME *t)
+{
+       NDR_CHECK(ndr_pull_hyper(ndr, t));
+       (*t) *= 10000000;
+       return NT_STATUS_OK;
+}
+
+/*
+  pull a NTTIME_hyper
+*/
+NTSTATUS ndr_pull_NTTIME_hyper(struct ndr_pull *ndr, NTTIME *t)
+{
+       NDR_CHECK(ndr_pull_hyper(ndr, t));
+       return NT_STATUS_OK;
+}
+
+/*
+  push a NTTIME_hyper
+*/
+NTSTATUS ndr_push_NTTIME_hyper(struct ndr_push *ndr, NTTIME t)
+{
+       NDR_CHECK(ndr_push_hyper(ndr, t));
        return NT_STATUS_OK;
 }
 
@@ -618,7 +1010,7 @@ NTSTATUS ndr_push_time_t(struct ndr_push *ndr, time_t t)
 */
 NTSTATUS ndr_pull_time_t(struct ndr_pull *ndr, time_t *t)
 {
-       uint32 tt;
+       uint32_t tt;
        NDR_CHECK(ndr_pull_uint32(ndr, &tt));
        *t = tt;
        return NT_STATUS_OK;
@@ -630,24 +1022,71 @@ void ndr_print_struct(struct ndr_print *ndr, const char *name, const char *type)
        ndr->print(ndr, "%s: struct %s", name, type);
 }
 
-void ndr_print_uint8(struct ndr_print *ndr, const char *name, uint8 v)
+void ndr_print_enum(struct ndr_print *ndr, const char *name, const char *type, 
+                   const char *val, uint_t value)
+{
+       if (ndr->flags & LIBNDR_PRINT_ARRAY_HEX) {
+               ndr->print(ndr, "%-25s: %s (0x%X)", name, val?val:"UNKNOWN_ENUM_VALUE", value);
+       } else {
+               ndr->print(ndr, "%-25s: %s (%d)", name, val?val:"UNKNOWN_ENUM_VALUE", value);
+       }
+}
+
+void ndr_print_bitmap_flag(struct ndr_print *ndr, size_t size, const char *flag_name, uint_t flag, uint_t value)
+{
+       /* this is an attempt to support multi-bit bitmap masks */
+       value &= flag;
+
+       while (!(flag & 1)) {
+               flag >>= 1;
+               value >>= 1;
+       }       
+       if (flag == 1) {
+               ndr->print(ndr, "   %d: %-25s", value, flag_name);
+       } else {
+               ndr->print(ndr, "0x%02x: %-25s (%d)", value, flag_name, value);
+       }
+}
+
+void ndr_print_uint8(struct ndr_print *ndr, const char *name, uint8_t v)
 {
        ndr->print(ndr, "%-25s: 0x%02x (%u)", name, v, v);
 }
 
-void ndr_print_uint16(struct ndr_print *ndr, const char *name, uint16 v)
+void ndr_print_uint16(struct ndr_print *ndr, const char *name, uint16_t v)
 {
        ndr->print(ndr, "%-25s: 0x%04x (%u)", name, v, v);
 }
 
-void ndr_print_uint32(struct ndr_print *ndr, const char *name, uint32 v)
+void ndr_print_uint32(struct ndr_print *ndr, const char *name, uint32_t v)
 {
        ndr->print(ndr, "%-25s: 0x%08x (%u)", name, v, v);
 }
 
-void ndr_print_HYPER_T(struct ndr_print *ndr, const char *name, HYPER_T v)
+void ndr_print_int32(struct ndr_print *ndr, const char *name, int32_t v)
+{
+       ndr->print(ndr, "%-25s: %d", name, v);
+}
+
+void ndr_print_udlong(struct ndr_print *ndr, const char *name, uint64_t v)
 {
-       ndr->print(ndr, "%-25s: 0x%08x%08x", name, v.high, v.low);
+       ndr->print(ndr, "%-25s: 0x%08x%08x (%llu)", name,
+                  (uint32_t)(v >> 32),
+                  (uint32_t)(v & 0xFFFFFFFF),
+                  v);
+}
+
+void ndr_print_dlong(struct ndr_print *ndr, const char *name, int64_t v)
+{
+       ndr->print(ndr, "%-25s: 0x%08x%08x (%lld)", name, 
+                  (uint32_t)(v >> 32), 
+                  (uint32_t)(v & 0xFFFFFFFF),
+                  v);
+}
+
+void ndr_print_hyper(struct ndr_print *ndr, const char *name, uint64_t v)
+{
+       ndr_print_dlong(ndr, name, v);
 }
 
 void ndr_print_ptr(struct ndr_print *ndr, const char *name, const void *p)
@@ -670,7 +1109,20 @@ void ndr_print_string(struct ndr_print *ndr, const char *name, const char *s)
 
 void ndr_print_NTTIME(struct ndr_print *ndr, const char *name, NTTIME t)
 {
-       ndr->print(ndr, "%-25s: %s", name, nt_time_string(ndr->mem_ctx, &t));
+       ndr->print(ndr, "%-25s: %s", name, nt_time_string(ndr, t));
+}
+
+void ndr_print_NTTIME_1sec(struct ndr_print *ndr, const char *name, NTTIME t)
+{
+       /* this is a standard NTTIME here
+        * as it's already converted in the pull/push code
+        */
+       ndr_print_NTTIME(ndr, name, t);
+}
+
+void ndr_print_NTTIME_hyper(struct ndr_print *ndr, const char *name, NTTIME t)
+{
+       ndr_print_NTTIME(ndr, name, t);
 }
 
 void ndr_print_time_t(struct ndr_print *ndr, const char *name, time_t t)
@@ -678,22 +1130,58 @@ void ndr_print_time_t(struct ndr_print *ndr, const char *name, time_t t)
        if (t == (time_t)-1 || t == 0) {
                ndr->print(ndr, "%-25s: (time_t)%d", name, (int)t);
        } else {
-               ndr->print(ndr, "%-25s: %s", name, timestring(ndr->mem_ctx, t));
+               ndr->print(ndr, "%-25s: %s", name, timestring(ndr, t));
        }
 }
 
-void ndr_print_union(struct ndr_print *ndr, const char *name, uint16 level, const char *type)
+void ndr_print_union(struct ndr_print *ndr, const char *name, int level, const char *type)
 {
-       ndr->print(ndr, "%-25s: union %s(case %u)", name, type, level);
+       ndr->print(ndr, "%-25s: union %s(case %d)", name, type, level);
 }
 
-void ndr_print_bad_level(struct ndr_print *ndr, const char *name, uint16 level)
+void ndr_print_bad_level(struct ndr_print *ndr, const char *name, uint16_t level)
 {
        ndr->print(ndr, "UNKNOWN LEVEL %u", level);
 }
 
+void ndr_print_array_WERROR(struct ndr_print *ndr, const char *name, 
+                           const WERROR *data, uint32_t count)
+{
+       int i;
+
+       ndr->print(ndr, "%s: ARRAY(%d)", name, count);
+       ndr->depth++;
+       for (i=0;i<count;i++) {
+               char *idx=NULL;
+               asprintf(&idx, "[%d]", i);
+               if (idx) {
+                       ndr_print_WERROR(ndr, idx, data[i]);
+                       free(idx);
+               }
+       }
+       ndr->depth--;   
+}
+
+void ndr_print_array_hyper(struct ndr_print *ndr, const char *name, 
+                           const uint64_t *data, uint32_t count)
+{
+       int i;
+
+       ndr->print(ndr, "%s: ARRAY(%d)", name, count);
+       ndr->depth++;
+       for (i=0;i<count;i++) {
+               char *idx=NULL;
+               asprintf(&idx, "[%d]", i);
+               if (idx) {
+                       ndr_print_hyper(ndr, idx, data[i]);
+                       free(idx);
+               }
+       }
+       ndr->depth--;   
+}
+
 void ndr_print_array_uint32(struct ndr_print *ndr, const char *name, 
-                           const uint32 *data, uint32 count)
+                           const uint32_t *data, uint32_t count)
 {
        int i;
 
@@ -711,7 +1199,7 @@ void ndr_print_array_uint32(struct ndr_print *ndr, const char *name,
 }
 
 void ndr_print_array_uint16(struct ndr_print *ndr, const char *name, 
-                           const uint16 *data, uint32 count)
+                           const uint16_t *data, uint32_t count)
 {
        int i;
 
@@ -729,12 +1217,12 @@ void ndr_print_array_uint16(struct ndr_print *ndr, const char *name,
 }
 
 void ndr_print_array_uint8(struct ndr_print *ndr, const char *name, 
-                          const uint8 *data, uint32 count)
+                          const uint8_t *data, uint32_t count)
 {
        int i;
 
-       if (count <= 32 && (ndr->flags & LIBNDR_PRINT_ARRAY_HEX)) {
-               char s[65];
+       if (count <= 600 && (ndr->flags & LIBNDR_PRINT_ARRAY_HEX)) {
+               char s[1202];
                for (i=0;i<count;i++) {
                        snprintf(&s[i*2], 3, "%02x", data[i]);
                }
@@ -756,57 +1244,6 @@ void ndr_print_array_uint8(struct ndr_print *ndr, const char *name,
        ndr->depth--;   
 }
 
-/*
-  build a GUID from a string
-*/
-NTSTATUS GUID_from_string(const char *s, struct GUID *guid)
-{
-        uint32 time_low;
-        uint32 time_mid, time_hi_and_version;
-        uint32 clock_seq[2];
-        uint32 node[6];
-        int i;
-
-        if (11 != sscanf(s, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
-                         &time_low, &time_mid, &time_hi_and_version, 
-                         &clock_seq[0], &clock_seq[1],
-                         &node[0], &node[1], &node[2], &node[3], &node[4], &node[5])) {
-                return NT_STATUS_INVALID_PARAMETER;
-        }
-
-       guid->time_low = time_low;
-       guid->time_mid = time_mid;
-       guid->time_hi_and_version = time_hi_and_version;
-       guid->clock_seq[0] = clock_seq[0];
-       guid->clock_seq[1] = clock_seq[1];
-        for (i=0;i<6;i++) {
-               guid->node[i] = node[i];
-       }
-
-        return NT_STATUS_OK;
-}
-
-/*
-  its useful to be able to display these in debugging messages
-*/
-const char *GUID_string(TALLOC_CTX *mem_ctx, const struct GUID *guid)
-{
-       return talloc_asprintf(mem_ctx, 
-                              "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
-                              guid->time_low, guid->time_mid,
-                              guid->time_hi_and_version,
-                              guid->clock_seq[0],
-                              guid->clock_seq[1],
-                              guid->node[0], guid->node[1],
-                              guid->node[2], guid->node[3],
-                              guid->node[4], guid->node[5]);
-}
-
-void ndr_print_GUID(struct ndr_print *ndr, const char *name, const struct GUID *guid)
-{
-       ndr->print(ndr, "%-25s: %s", name, GUID_string(ndr->mem_ctx, guid));
-}
-
 void ndr_print_DATA_BLOB(struct ndr_print *ndr, const char *name, DATA_BLOB r)
 {
        ndr->print(ndr, "%-25s: DATA_BLOB length=%u", name, r.length);
@@ -843,7 +1280,7 @@ NTSTATUS ndr_push_DATA_BLOB(struct ndr_push *ndr, DATA_BLOB blob)
 */
 NTSTATUS ndr_pull_DATA_BLOB(struct ndr_pull *ndr, DATA_BLOB *blob)
 {
-       uint32 length;
+       uint32_t length;
 
        if (ndr->flags & LIBNDR_ALIGN_FLAGS) {
                if (ndr->flags & LIBNDR_FLAG_ALIGN2) {
@@ -862,7 +1299,19 @@ NTSTATUS ndr_pull_DATA_BLOB(struct ndr_pull *ndr, DATA_BLOB *blob)
                NDR_CHECK(ndr_pull_uint32(ndr, &length));
        }
        NDR_PULL_NEED_BYTES(ndr, length);
-       *blob = data_blob_talloc(ndr->mem_ctx, ndr->data+ndr->offset, length);
+       *blob = data_blob_talloc(ndr, ndr->data+ndr->offset, length);
        ndr->offset += length;
        return NT_STATUS_OK;
 }
+
+uint32 ndr_size_DATA_BLOB(int ret, const DATA_BLOB *data, int flags)
+{
+       return ret + data->length;
+}
+
+uint32 ndr_size_string(int ret, const char * const* string, int flags) 
+{
+       /* FIXME: Is this correct for all strings ? */
+       if(!(*string)) return ret;
+       return ret+strlen(*string)+1;
+}