From c282d76d556ae3744cae3f113afeda746b93949f Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Sat, 4 May 2019 08:53:48 +0200 Subject: [PATCH] torture: start of a mdssvc packet (un)marshalling testsuite Signed-off-by: Ralph Boehme Reviewed-by: Jeremy Allison --- selftest/knownfail.d/samba4.local.mdspkt | 1 + source4/torture/local/local.c | 1 + source4/torture/local/mdspkt.c | 104 +++++++++++++++++++++++ source4/torture/local/wscript_build | 1 + source4/torture/wscript_build | 2 + 5 files changed, 109 insertions(+) create mode 100644 selftest/knownfail.d/samba4.local.mdspkt create mode 100644 source4/torture/local/mdspkt.c diff --git a/selftest/knownfail.d/samba4.local.mdspkt b/selftest/knownfail.d/samba4.local.mdspkt new file mode 100644 index 00000000000..fcfc083cd15 --- /dev/null +++ b/selftest/knownfail.d/samba4.local.mdspkt @@ -0,0 +1 @@ +^samba4.local.mdspkt.empty_cnid_fm\(none\) diff --git a/source4/torture/local/local.c b/source4/torture/local/local.c index acd88772ab7..0403e14697b 100644 --- a/source4/torture/local/local.c +++ b/source4/torture/local/local.c @@ -77,6 +77,7 @@ torture_local_fsrvp, torture_local_util_str_escape, torture_local_tfork, + torture_local_mdspkt, NULL }; diff --git a/source4/torture/local/mdspkt.c b/source4/torture/local/mdspkt.c new file mode 100644 index 00000000000..a73c176e746 --- /dev/null +++ b/source4/torture/local/mdspkt.c @@ -0,0 +1,104 @@ +/* + * Tests for mdssvc packets (un)marshalling + * + * Copyright Ralph Boehme 2019 + * + * 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 . + */ + +#include "replace.h" +#include +#include "libcli/util/ntstatus.h" +#include "lib/util/samba_util.h" +#include "lib/torture/torture.h" +#include "lib/util/data_blob.h" +#include "torture/local/proto.h" +#include "mdssvc/marshalling.h" + +static const unsigned char mdspkt_empty_cnid_fm[] = { + 0x34, 0x33, 0x32, 0x31, 0x33, 0x30, 0x64, 0x6d, + 0x0c, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x84, 0x01, 0x00, 0x00, 0x00, + 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x87, 0x08, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x02, 0x03, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x07, 0x08, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x88, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x0a, 0x03, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x00, + 0x07, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x00 +}; + +static const char *mdspkt_empty_cnid_fm_dump = +"DALLOC_CTX(#1): {\n" +" sl_array_t(#3): {\n" +" uint64_t: 0x0023\n" +" CNIDs: unkn1: 0x0, unkn2: 0x0\n" +" DALLOC_CTX(#0): {\n" +" }\n" +" sl_filemeta_t(#0): {\n" +" }\n" +" }\n" +"}\n"; + +static bool test_mdspkt_empty_cnid_fm(struct torture_context *tctx) +{ + DALLOC_CTX *d = NULL; + sl_cnids_t *cnids = NULL; + char *dstr = NULL; + size_t ncnids; + bool ret = true; + + d = dalloc_new(tctx); + torture_assert_not_null_goto(tctx, d, ret, done, + "dalloc_new failed\n"); + + ret = sl_unpack(d, + (const char *)mdspkt_empty_cnid_fm, + sizeof(mdspkt_empty_cnid_fm)); + torture_assert_goto(tctx, ret, ret, done, "sl_unpack failed\n"); + + cnids = dalloc_get(d, "DALLOC_CTX", 0, "sl_cnids_t", 1); + torture_assert_not_null_goto(tctx, d, ret, done, + "dalloc_get cnids failed\n"); + + ncnids = dalloc_size(cnids->ca_cnids); + torture_assert_int_equal_goto(tctx, ncnids, 0, ret, done, + "Wrong number of CNIDs\n"); + + dstr = dalloc_dump(d, 0); + torture_assert_not_null_goto(tctx, dstr, ret, done, + "dalloc_dump failed\n"); + + torture_assert_str_equal_goto(tctx, dstr, mdspkt_empty_cnid_fm_dump, + ret, done, "Bad dump\n"); + +done: + TALLOC_FREE(d); + return ret; +} + +struct torture_suite *torture_local_mdspkt(TALLOC_CTX *mem_ctx) +{ + struct torture_suite *suite = + torture_suite_create(mem_ctx, "mdspkt"); + + torture_suite_add_simple_test(suite, + "empty_cnid_fm", + test_mdspkt_empty_cnid_fm); + + return suite; +} diff --git a/source4/torture/local/wscript_build b/source4/torture/local/wscript_build index a79b6d9f10d..654b3f9c271 100644 --- a/source4/torture/local/wscript_build +++ b/source4/torture/local/wscript_build @@ -27,6 +27,7 @@ TORTURE_LOCAL_SOURCE = '''../../../lib/util/charset/tests/iconv.c ../../../lib/util/tests/tfork.c verif_trailer.c nss_tests.c + mdspkt.c fsrvp_state.c''' TORTURE_LOCAL_DEPS = 'RPC_NDR_ECHO TDR LIBCLI_SMB MESSAGING iconv POPT_CREDENTIALS TORTURE_AUTH TORTURE_UTIL TORTURE_NDR TORTURE_LIBCRYPTO share torture_registry %s ldb samdb replace-test RPC_FSS_STATE util_str_escape' % provision diff --git a/source4/torture/wscript_build b/source4/torture/wscript_build index 7dde54fefba..cc9c26399a5 100644 --- a/source4/torture/wscript_build +++ b/source4/torture/wscript_build @@ -193,6 +193,8 @@ bld.SAMBA_MODULE('torture_rpc', RPC_NDR_WINSPOOL IREMOTEWINSPOOL_COMMON printer_driver + RPC_NDR_MDSSVC + mdssvc ''' % samba_net + ntvfs_specific['deps'], internal_module=True, enabled=bld.PYTHON_BUILD_IS_ENABLED()) -- 2.34.1