-/*
+/*
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/>.
*/
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);
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);
}
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;
}
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 */
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;
}
#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)
{
}
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)
{
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;
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));