summaryrefslogtreecommitdiff
path: root/source4/lib/tdr
diff options
context:
space:
mode:
Diffstat (limited to 'source4/lib/tdr')
-rw-r--r--source4/lib/tdr/tdr.c14
-rw-r--r--source4/lib/tdr/tdr.h1
-rw-r--r--source4/lib/tdr/testsuite.c77
3 files changed, 52 insertions, 40 deletions
diff --git a/source4/lib/tdr/tdr.c b/source4/lib/tdr/tdr.c
index 1a52f10569..f75cac9810 100644
--- a/source4/lib/tdr/tdr.c
+++ b/source4/lib/tdr/tdr.c
@@ -374,7 +374,7 @@ NTSTATUS tdr_pull_DATA_BLOB(struct tdr_pull *tdr, TALLOC_CTX *ctx, DATA_BLOB *bl
struct tdr_push *tdr_push_init(TALLOC_CTX *mem_ctx, struct smb_iconv_convenience *ic)
{
- struct tdr_push *push = talloc_zero(NULL, struct tdr_push);
+ struct tdr_push *push = talloc_zero(mem_ctx, struct tdr_push);
if (push == NULL)
return NULL;
@@ -384,6 +384,18 @@ struct tdr_push *tdr_push_init(TALLOC_CTX *mem_ctx, struct smb_iconv_convenience
return push;
}
+struct tdr_pull *tdr_pull_init(TALLOC_CTX *mem_ctx, struct smb_iconv_convenience *ic)
+{
+ 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)
{
struct tdr_push *push = tdr_push_init(NULL, iconv_convenience);
diff --git a/source4/lib/tdr/tdr.h b/source4/lib/tdr/tdr.h
index 84e04a5327..301cd3002e 100644
--- a/source4/lib/tdr/tdr.h
+++ b/source4/lib/tdr/tdr.h
@@ -33,6 +33,7 @@ struct tdr_pull {
DATA_BLOB data;
uint32_t offset;
int flags;
+ struct smb_iconv_convenience *iconv_convenience;
};
struct tdr_push {
diff --git a/source4/lib/tdr/testsuite.c b/source4/lib/tdr/testsuite.c
index c3c85b5ab6..44c5810f90 100644
--- a/source4/lib/tdr/testsuite.c
+++ b/source4/lib/tdr/testsuite.c
@@ -38,14 +38,14 @@ static bool test_pull_uint8(struct torture_context *tctx)
{
uint8_t d = 2;
uint8_t l;
- struct tdr_pull tdr;
- tdr.data.data = &d;
- tdr.data.length = 1;
- tdr.offset = 0;
- tdr.flags = 0;
- torture_assert_ntstatus_ok(tctx, tdr_pull_uint8(&tdr, tctx, &l),
+ struct tdr_pull *tdr = tdr_pull_init(tctx, lp_iconv_convenience(tctx->lp_ctx));
+ tdr->data.data = &d;
+ tdr->data.length = 1;
+ tdr->offset = 0;
+ tdr->flags = 0;
+ torture_assert_ntstatus_ok(tctx, tdr_pull_uint8(tdr, tctx, &l),
"pull failed");
- torture_assert_int_equal(tctx, 1, tdr.offset,
+ torture_assert_int_equal(tctx, 1, tdr->offset,
"offset invalid");
return true;
}
@@ -66,15 +66,14 @@ static bool test_pull_uint16(struct torture_context *tctx)
{
uint8_t d[2] = { 782 & 0xFF, (782 & 0xFF00) / 0x100 };
uint16_t l;
- struct tdr_pull tdr;
- tdr.data.data = d;
- tdr.data.length = 2;
- tdr.offset = 0;
- tdr.flags = 0;
- torture_assert_ntstatus_ok(tctx, tdr_pull_uint16(&tdr, tctx, &l),
+ struct tdr_pull *tdr = tdr_pull_init(tctx, lp_iconv_convenience(tctx->lp_ctx));
+ tdr->data.data = d;
+ tdr->data.length = 2;
+ tdr->offset = 0;
+ tdr->flags = 0;
+ torture_assert_ntstatus_ok(tctx, tdr_pull_uint16(tdr, tctx, &l),
"pull failed");
- torture_assert_int_equal(tctx, 2, tdr.offset,
- "offset invalid");
+ torture_assert_int_equal(tctx, 2, tdr->offset, "offset invalid");
torture_assert_int_equal(tctx, 782, l, "right int read");
return true;
}
@@ -97,35 +96,35 @@ static bool test_pull_uint32(struct torture_context *tctx)
{
uint8_t d[4] = { 782 & 0xFF, (782 & 0xFF00) / 0x100, 0, 0 };
uint32_t l;
- struct tdr_pull tdr;
- tdr.data.data = d;
- tdr.data.length = 4;
- tdr.offset = 0;
- tdr.flags = 0;
- torture_assert_ntstatus_ok(tctx, tdr_pull_uint32(&tdr, tctx, &l),
+ struct tdr_pull *tdr = tdr_pull_init(tctx, lp_iconv_convenience(tctx->lp_ctx));
+ tdr->data.data = d;
+ tdr->data.length = 4;
+ tdr->offset = 0;
+ tdr->flags = 0;
+ torture_assert_ntstatus_ok(tctx, tdr_pull_uint32(tdr, tctx, &l),
"pull failed");
- torture_assert_int_equal(tctx, 4, tdr.offset, "offset invalid");
+ torture_assert_int_equal(tctx, 4, tdr->offset, "offset invalid");
torture_assert_int_equal(tctx, 782, l, "right int read");
return true;
}
static bool test_pull_charset(struct torture_context *tctx)
{
- struct tdr_pull tdr;
+ struct tdr_pull *tdr = tdr_pull_init(tctx, lp_iconv_convenience(tctx->lp_ctx));
const char *l = NULL;
- tdr.data.data = (uint8_t *)talloc_strdup(tctx, "bla");
- tdr.data.length = 4;
- tdr.offset = 0;
- tdr.flags = 0;
- torture_assert_ntstatus_ok(tctx, tdr_pull_charset(&tdr, tctx, &l, -1, 1, CH_DOS),
+ tdr->data.data = (uint8_t *)talloc_strdup(tctx, "bla");
+ tdr->data.length = 4;
+ tdr->offset = 0;
+ tdr->flags = 0;
+ torture_assert_ntstatus_ok(tctx, tdr_pull_charset(tdr, tctx, &l, -1, 1, CH_DOS),
"pull failed");
- torture_assert_int_equal(tctx, 4, tdr.offset, "offset invalid");
+ torture_assert_int_equal(tctx, 4, tdr->offset, "offset invalid");
torture_assert_str_equal(tctx, "bla", l, "right int read");
- tdr.offset = 0;
- torture_assert_ntstatus_ok(tctx, tdr_pull_charset(&tdr, tctx, &l, 2, 1, CH_UNIX),
+ tdr->offset = 0;
+ torture_assert_ntstatus_ok(tctx, tdr_pull_charset(tdr, tctx, &l, 2, 1, CH_UNIX),
"pull failed");
- torture_assert_int_equal(tctx, 2, tdr.offset, "offset invalid");
+ torture_assert_int_equal(tctx, 2, tdr->offset, "offset invalid");
torture_assert_str_equal(tctx, "bl", l, "right int read");
return true;
@@ -133,15 +132,15 @@ static bool test_pull_charset(struct torture_context *tctx)
static bool test_pull_charset_empty(struct torture_context *tctx)
{
- struct tdr_pull tdr;
+ struct tdr_pull *tdr = tdr_pull_init(tctx, lp_iconv_convenience(tctx->lp_ctx));
const char *l = NULL;
- tdr.data.data = (uint8_t *)talloc_strdup(tctx, "bla");
- tdr.data.length = 4;
- tdr.offset = 0;
- tdr.flags = 0;
- torture_assert_ntstatus_ok(tctx, tdr_pull_charset(&tdr, tctx, &l, 0, 1, CH_DOS),
+ tdr->data.data = (uint8_t *)talloc_strdup(tctx, "bla");
+ tdr->data.length = 4;
+ tdr->offset = 0;
+ tdr->flags = 0;
+ torture_assert_ntstatus_ok(tctx, tdr_pull_charset(tdr, tctx, &l, 0, 1, CH_DOS),
"pull failed");
- torture_assert_int_equal(tctx, 0, tdr.offset, "offset invalid");
+ torture_assert_int_equal(tctx, 0, tdr->offset, "offset invalid");
torture_assert_str_equal(tctx, "", l, "right string read");
return true;