| 1 |
/* |
| 2 |
* Tests for mdssvc packets (un)marshalling |
| 3 |
* |
| 4 |
* Copyright Ralph Boehme <[email protected]> 2019 |
| 5 |
* |
| 6 |
* This program is free software; you can redistribute it and/or modify |
| 7 |
* it under the terms of the GNU General Public License as published by |
| 8 |
* the Free Software Foundation; either version 3 of the License, or |
| 9 |
* (at your option) any later version. |
| 10 |
* |
| 11 |
* This program is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
* GNU General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU General Public License |
| 17 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
*/ |
| 19 |
|
| 20 |
#include "replace.h" |
| 21 |
#include <talloc.h> |
| 22 |
#include "libcli/util/ntstatus.h" |
| 23 |
#include "lib/util/samba_util.h" |
| 24 |
#include "lib/torture/torture.h" |
| 25 |
#include "lib/util/data_blob.h" |
| 26 |
#include "torture/local/proto.h" |
| 27 |
#include "mdssvc/marshalling.h" |
| 28 |
|
| 29 |
static const unsigned char mdspkt_empty_cnid_fm[] = { |
| 30 |
0x34, 0x33, 0x32, 0x31, 0x33, 0x30, 0x64, 0x6d, |
| 31 |
0x0c, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, |
| 32 |
0x01, 0x00, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00, |
| 33 |
0x02, 0x00, 0x00, 0x84, 0x01, 0x00, 0x00, 0x00, |
| 34 |
0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 35 |
0x01, 0x00, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, |
| 36 |
0x01, 0x00, 0x00, 0x87, 0x08, 0x00, 0x00, 0x00, |
| 37 |
0x01, 0x00, 0x00, 0x02, 0x03, 0x00, 0x00, 0x00, |
| 38 |
0x01, 0x00, 0x00, 0x07, 0x08, 0x00, 0x00, 0x00, |
| 39 |
0x04, 0x00, 0x00, 0x88, 0x00, 0x00, 0x00, 0x00, |
| 40 |
0x02, 0x00, 0x00, 0x0a, 0x03, 0x00, 0x00, 0x00, |
| 41 |
0x05, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x00, |
| 42 |
0x07, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x00 |
| 43 |
}; |
| 44 |
|
| 45 |
static const char *mdspkt_empty_cnid_fm_dump = |
| 46 |
"DALLOC_CTX(#1): {\n" |
| 47 |
" sl_array_t(#3): {\n" |
| 48 |
" uint64_t: 0x0023\n" |
| 49 |
" CNIDs: unkn1: 0x0, unkn2: 0x0\n" |
| 50 |
" DALLOC_CTX(#0): {\n" |
| 51 |
" }\n" |
| 52 |
" sl_filemeta_t(#0): {\n" |
| 53 |
" }\n" |
| 54 |
" }\n" |
| 55 |
"}\n"; |
| 56 |
|
| 57 |
static bool test_mdspkt_empty_cnid_fm(struct torture_context *tctx) |
| 58 |
{ |
| 59 |
DALLOC_CTX *d = NULL; |
| 60 |
sl_cnids_t *cnids = NULL; |
| 61 |
char *dstr = NULL; |
| 62 |
size_t ncnids; |
| 63 |
bool ret = true; |
| 64 |
|
| 65 |
d = dalloc_new(tctx); |
| 66 |
torture_assert_not_null_goto(tctx, d, ret, done, |
| 67 |
"dalloc_new failed\n"); |
| 68 |
|
| 69 |
ret = sl_unpack(d, |
| 70 |
(const char *)mdspkt_empty_cnid_fm, |
| 71 |
sizeof(mdspkt_empty_cnid_fm)); |
| 72 |
torture_assert_goto(tctx, ret, ret, done, "sl_unpack failed\n"); |
| 73 |
|
| 74 |
cnids = dalloc_get(d, "DALLOC_CTX", 0, "sl_cnids_t", 1); |
| 75 |
torture_assert_not_null_goto(tctx, cnids, ret, done, |
| 76 |
"dalloc_get cnids failed\n"); |
| 77 |
|
| 78 |
ncnids = dalloc_size(cnids->ca_cnids); |
| 79 |
torture_assert_int_equal_goto(tctx, ncnids, 0, ret, done, |
| 80 |
"Wrong number of CNIDs\n"); |
| 81 |
|
| 82 |
dstr = dalloc_dump(d, 0); |
| 83 |
torture_assert_not_null_goto(tctx, dstr, ret, done, |
| 84 |
"dalloc_dump failed\n"); |
| 85 |
|
| 86 |
torture_assert_str_equal_goto(tctx, dstr, mdspkt_empty_cnid_fm_dump, |
| 87 |
ret, done, "Bad dump\n"); |
| 88 |
|
| 89 |
done: |
| 90 |
TALLOC_FREE(d); |
| 91 |
return ret; |
| 92 |
} |
| 93 |
|
| 94 |
struct torture_suite *torture_local_mdspkt(TALLOC_CTX *mem_ctx) |
| 95 |
{ |
| 96 |
struct torture_suite *suite = |
| 97 |
torture_suite_create(mem_ctx, "mdspkt"); |
| 98 |
|
| 99 |
torture_suite_add_simple_test(suite, |
| 100 |
"empty_cnid_fm", |
| 101 |
test_mdspkt_empty_cnid_fm); |
| 102 |
|
| 103 |
return suite; |
| 104 |
} |