summaryrefslogtreecommitdiff
path: root/source4/torture/ndr
diff options
context:
space:
mode:
authorGünther Deschner <gd@samba.org>2010-09-16 16:21:39 +0200
committerGünther Deschner <gd@samba.org>2010-09-16 19:03:29 +0200
commitc29b16faa87dab686c8d36abc009c7d92d28a6b2 (patch)
tree2ccf5f089cb80135a1c4fb87d77a745a8ec311a9 /source4/torture/ndr
parent5f9caf18dbba8b6ddb2779bcec4836b605b5fa1e (diff)
downloadsamba-c29b16faa87dab686c8d36abc009c7d92d28a6b2.tar.gz
samba-c29b16faa87dab686c8d36abc009c7d92d28a6b2.tar.bz2
samba-c29b16faa87dab686c8d36abc009c7d92d28a6b2.zip
s4-smbtorture: add functions to do NDR_OUT ndr_pull validation including NDR_IN context.
Guenther
Diffstat (limited to 'source4/torture/ndr')
-rw-r--r--source4/torture/ndr/ndr.c83
-rw-r--r--source4/torture/ndr/ndr.h16
2 files changed, 99 insertions, 0 deletions
diff --git a/source4/torture/ndr/ndr.c b/source4/torture/ndr/ndr.c
index 03c751c364..e13cb94bbd 100644
--- a/source4/torture/ndr/ndr.c
+++ b/source4/torture/ndr/ndr.c
@@ -26,6 +26,7 @@
struct ndr_pull_test_data {
DATA_BLOB data;
+ DATA_BLOB data_context;
size_t struct_size;
ndr_pull_flags_fn_t pull_fn;
int ndr_flags;
@@ -88,6 +89,88 @@ _PUBLIC_ struct torture_test *_torture_suite_add_ndr_pull_test(
return test;
}
+static bool wrap_ndr_inout_pull_test(struct torture_context *tctx,
+ struct torture_tcase *tcase,
+ struct torture_test *test)
+{
+ bool (*check_fn) (struct torture_context *ctx, void *data) = test->fn;
+ const struct ndr_pull_test_data *data = (const struct ndr_pull_test_data *)test->data;
+ void *ds = talloc_zero_size(tctx, data->struct_size);
+ struct ndr_pull *ndr;
+
+ /* handle NDR_IN context */
+
+ ndr = ndr_pull_init_blob(&(data->data_context), tctx);
+ torture_assert(tctx, ndr, "ndr init failed");
+
+ ndr->flags |= LIBNDR_FLAG_REF_ALLOC;
+
+ torture_assert_ndr_success(tctx,
+ data->pull_fn(ndr, NDR_IN, ds),
+ "ndr pull of context failed");
+
+ torture_assert(tctx, ndr->offset == ndr->data_size,
+ talloc_asprintf(tctx, "%d unread bytes", ndr->data_size - ndr->offset));
+
+ talloc_free(ndr);
+
+ /* handle NDR_OUT */
+
+ ndr = ndr_pull_init_blob(&(data->data), tctx);
+ torture_assert(tctx, ndr, "ndr init failed");
+
+ ndr->flags |= LIBNDR_FLAG_REF_ALLOC;
+
+ torture_assert_ndr_success(tctx,
+ data->pull_fn(ndr, NDR_OUT, ds),
+ "ndr pull failed");
+
+ torture_assert(tctx, ndr->offset == ndr->data_size,
+ talloc_asprintf(tctx, "%d unread bytes", ndr->data_size - ndr->offset));
+
+ talloc_free(ndr);
+
+ if (check_fn) {
+ return check_fn(tctx, ds);
+ } else {
+ return true;
+ }
+}
+
+_PUBLIC_ struct torture_test *_torture_suite_add_ndr_pull_inout_test(
+ struct torture_suite *suite,
+ const char *name, ndr_pull_flags_fn_t pull_fn,
+ DATA_BLOB db_in,
+ DATA_BLOB db_out,
+ size_t struct_size,
+ bool (*check_fn) (struct torture_context *ctx, void *data))
+{
+ struct torture_test *test;
+ struct torture_tcase *tcase;
+ struct ndr_pull_test_data *data;
+
+ tcase = torture_suite_add_tcase(suite, name);
+
+ test = talloc(tcase, struct torture_test);
+
+ test->name = talloc_strdup(test, name);
+ test->description = NULL;
+ test->run = wrap_ndr_inout_pull_test;
+ data = talloc(test, struct ndr_pull_test_data);
+ data->data = db_out;
+ data->data_context = db_in;
+ data->ndr_flags = 0;
+ data->struct_size = struct_size;
+ data->pull_fn = pull_fn;
+ test->data = data;
+ test->fn = check_fn;
+ test->dangerous = false;
+
+ DLIST_ADD_END(tcase->tests, test, struct torture_test *);
+
+ return test;
+}
+
static bool test_check_string_terminator(struct torture_context *tctx)
{
struct ndr_pull *ndr;
diff --git a/source4/torture/ndr/ndr.h b/source4/torture/ndr/ndr.h
index 9438b16b65..3de6b8b0d3 100644
--- a/source4/torture/ndr/ndr.h
+++ b/source4/torture/ndr/ndr.h
@@ -32,6 +32,14 @@ _PUBLIC_ struct torture_test *_torture_suite_add_ndr_pull_test(
int ndr_flags,
bool (*check_fn) (struct torture_context *, void *data));
+_PUBLIC_ struct torture_test *_torture_suite_add_ndr_pull_inout_test(
+ struct torture_suite *suite,
+ const char *name, ndr_pull_flags_fn_t pull_fn,
+ DATA_BLOB db_in,
+ DATA_BLOB db_out,
+ size_t struct_size,
+ bool (*check_fn) (struct torture_context *ctx, void *data));
+
#define torture_suite_add_ndr_pull_test(suite,name,data,check_fn) \
_torture_suite_add_ndr_pull_test(suite, #name, \
(ndr_pull_flags_fn_t)ndr_pull_ ## name, data_blob_talloc(suite, data, sizeof(data)), \
@@ -42,6 +50,14 @@ _PUBLIC_ struct torture_test *_torture_suite_add_ndr_pull_test(
(ndr_pull_flags_fn_t)ndr_pull_ ## name, data_blob_talloc(suite, data, sizeof(data)), \
sizeof(struct name), flags, (bool (*) (struct torture_context *, void *)) check_fn);
+#define torture_suite_add_ndr_pull_io_test(suite,name,data_in,data_out,check_fn_out) \
+ _torture_suite_add_ndr_pull_inout_test(suite, #name "_INOUT", \
+ (ndr_pull_flags_fn_t)ndr_pull_ ## name, \
+ data_blob_talloc(suite, data_in, sizeof(data_in)), \
+ data_blob_talloc(suite, data_out, sizeof(data_out)), \
+ sizeof(struct name), \
+ (bool (*) (struct torture_context *, void *)) check_fn_out);
+
#define torture_assert_sid_equal(torture_ctx,got,expected,cmt)\
do { struct dom_sid *__got = (got), *__expected = (expected); \
if (!dom_sid_equal(__got, __expected)) { \