talloc: use the system pytalloc-util for python3 as well
[sfrench/samba-autobuild/.git] / lib / tdr / tdr.c
index 293436ed5e3474a942a1ab53efadbe65892aec3e..401e1ccf6ef61b26ffe32a72efd1d15c4e4cca50 100644 (file)
@@ -1,21 +1,21 @@
-/* 
+/*
    Unix SMB/CIFS implementation.
 
    TDR (Trivial Data Representation) helper functions
      Based loosely on ndr.c by Andrew Tridgell.
 
    Copyright (C) Jelmer Vernooij 2005
-   
+
    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
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
-   
+
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
-   
+
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
@@ -92,6 +92,11 @@ NTSTATUS tdr_pull_uint16(struct tdr_pull *tdr, TALLOC_CTX *ctx, uint16_t *v)
        return NT_STATUS_OK;
 }
 
+NTSTATUS tdr_pull_uint1632(struct tdr_pull *tdr, TALLOC_CTX *ctx, uint16_t *v)
+{
+       return tdr_pull_uint16(tdr, ctx, v);
+}
+
 NTSTATUS tdr_push_uint16(struct tdr_push *tdr, const uint16_t *v)
 {
        TDR_PUSH_NEED_BYTES(tdr, 2);
@@ -100,6 +105,11 @@ NTSTATUS tdr_push_uint16(struct tdr_push *tdr, const uint16_t *v)
        return NT_STATUS_OK;
 }
 
+NTSTATUS tdr_push_uint1632(struct tdr_push *tdr, const uint16_t *v)
+{
+       return tdr_push_uint16(tdr, v);
+}
+
 NTSTATUS tdr_print_uint16(struct tdr_print *tdr, const char *name, uint16_t *v)
 {
        tdr->print(tdr, "%-25s: 0x%02x (%u)", name, *v, *v);
@@ -152,8 +162,8 @@ NTSTATUS tdr_pull_charset(struct tdr_pull *tdr, TALLOC_CTX *ctx, const char **v,
        }
 
        TDR_PULL_NEED_BYTES(tdr, el_size*length);
-       
-       if (!convert_string_talloc_convenience(ctx, tdr->iconv_convenience, chset, CH_UNIX, tdr->data.data+tdr->offset, el_size*length, discard_const_p(void *, v), &ret, false)) {
+
+       if (!convert_string_talloc(ctx, chset, CH_UNIX, tdr->data.data+tdr->offset, el_size*length, discard_const_p(void *, v), &ret)) {
                return NT_STATUS_INVALID_PARAMETER;
        }
 
@@ -164,7 +174,8 @@ NTSTATUS tdr_pull_charset(struct tdr_pull *tdr, TALLOC_CTX *ctx, const char **v,
 
 NTSTATUS tdr_push_charset(struct tdr_push *tdr, const char **v, uint32_t length, uint32_t el_size, charset_t chset)
 {
-       size_t ret, required;
+       size_t required, size = 0;
+       bool ret;
 
        if (length == -1) {
                length = strlen(*v) + 1; /* Extra element for null character */
@@ -173,17 +184,18 @@ NTSTATUS tdr_push_charset(struct tdr_push *tdr, const char **v, uint32_t length,
        required = el_size * length;
        TDR_PUSH_NEED_BYTES(tdr, required);
 
-       if (!convert_string_convenience(tdr->iconv_convenience, CH_UNIX, chset, *v, strlen(*v), tdr->data.data+tdr->data.length, required, &ret, false)) {
+       ret = convert_string(CH_UNIX, chset, *v, strlen(*v), tdr->data.data+tdr->data.length, required, &size);
+       if (ret == false) {
                return NT_STATUS_INVALID_PARAMETER;
        }
 
        /* Make sure the remaining part of the string is filled with zeroes */
-       if (ret < required) {
-               memset(tdr->data.data+tdr->data.length+ret, 0, required-ret);
+       if (size < required) {
+               memset(tdr->data.data+tdr->data.length+size, 0, required-size);
        }
-       
+
        tdr->data.length += required;
-                                                
+
        return NT_STATUS_OK;
 }
 
@@ -285,7 +297,7 @@ NTSTATUS tdr_print_DATA_BLOB(struct tdr_print *tdr, const char *name, DATA_BLOB
 #define TDR_ALIGN(l,n) (((l) & ((n)-1)) == 0?0:((n)-((l)&((n)-1))))
 
 /*
-  push a DATA_BLOB onto the wire. 
+  push a DATA_BLOB onto the wire.
 */
 NTSTATUS tdr_push_DATA_BLOB(struct tdr_push *tdr, DATA_BLOB *blob)
 {
@@ -298,13 +310,13 @@ NTSTATUS tdr_push_DATA_BLOB(struct tdr_push *tdr, DATA_BLOB *blob)
        }
 
        TDR_PUSH_NEED_BYTES(tdr, blob->length);
-       
+
        memcpy(tdr->data.data+tdr->data.length, blob->data, blob->length);
        return NT_STATUS_OK;
 }
 
 /*
-  pull a DATA_BLOB from the wire. 
+  pull a DATA_BLOB from the wire.
 */
 NTSTATUS tdr_pull_DATA_BLOB(struct tdr_pull *tdr, TALLOC_CTX *ctx, DATA_BLOB *blob)
 {
@@ -333,33 +345,29 @@ NTSTATUS tdr_pull_DATA_BLOB(struct tdr_pull *tdr, TALLOC_CTX *ctx, DATA_BLOB *bl
        return NT_STATUS_OK;
 }
 
-struct tdr_push *tdr_push_init(TALLOC_CTX *mem_ctx, struct smb_iconv_convenience *ic)
+struct tdr_push *tdr_push_init(TALLOC_CTX *mem_ctx)
 {
        struct tdr_push *push = talloc_zero(mem_ctx, struct tdr_push);
 
        if (push == NULL)
                return NULL;
 
-       push->iconv_convenience = talloc_reference(push, ic);
-
        return push;
 }
 
-struct tdr_pull *tdr_pull_init(TALLOC_CTX *mem_ctx, struct smb_iconv_convenience *ic)
+struct tdr_pull *tdr_pull_init(TALLOC_CTX *mem_ctx)
 {
        struct tdr_pull *pull = talloc_zero(mem_ctx, struct tdr_pull);
 
        if (pull == NULL)
                return NULL;
 
-       pull->iconv_convenience = talloc_reference(pull, ic);
-
        return pull;
 }
 
-NTSTATUS tdr_push_to_fd(int fd, struct smb_iconv_convenience *iconv_convenience, tdr_push_fn_t push_fn, const void *p)
+NTSTATUS tdr_push_to_fd(int fd, tdr_push_fn_t push_fn, const void *p)
 {
-       struct tdr_push *push = tdr_push_init(NULL, iconv_convenience);
+       struct tdr_push *push = tdr_push_init(NULL);
 
        if (push == NULL)
                return NT_STATUS_NO_MEMORY;
@@ -380,16 +388,20 @@ NTSTATUS tdr_push_to_fd(int fd, struct smb_iconv_convenience *iconv_convenience,
        return NT_STATUS_OK;
 }
 
-void tdr_print_debug_helper(struct tdr_print *tdr, const char *format, ...) _PRINTF_ATTRIBUTE(2,3)
+void tdr_print_debug_helper(struct tdr_print *tdr, const char *format, ...)
 {
        va_list ap;
        char *s = NULL;
-       int i;
+       int i, ret;
 
        va_start(ap, format);
-       vasprintf(&s, format, ap);
+       ret = vasprintf(&s, format, ap);
        va_end(ap);
 
+       if (ret == -1) {
+               return;
+       }
+
        for (i=0;i<tdr->level;i++) { DEBUG(0,("    ")); }
 
        DEBUG(0,("%s\n", s));