2
Unix SMB/CIFS implementation.
3
test suite for winreg ndr operations
5
Copyright (C) Jelmer Vernooij 2007
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 3 of the License, or
10
(at your option) any later version.
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
17
You should have received a copy of the GNU General Public License
18
along with this program. If not, see <http://www.gnu.org/licenses/>.
22
#include "torture/ndr/ndr.h"
23
#include "torture/ndr/proto.h"
24
#include "torture/torture.h"
25
#include "../lib/util/dlinklist.h"
26
#include "param/param.h"
28
struct ndr_pull_test_data {
31
ndr_pull_flags_fn_t pull_fn;
35
static bool wrap_ndr_pull_test(struct torture_context *tctx,
36
struct torture_tcase *tcase,
37
struct torture_test *test)
39
bool (*check_fn) (struct torture_context *ctx, void *data) = test->fn;
40
const struct ndr_pull_test_data *data = (const struct ndr_pull_test_data *)test->data;
41
void *ds = talloc_zero_size(tctx, data->struct_size);
42
struct ndr_pull *ndr = ndr_pull_init_blob(&(data->data), tctx, lp_iconv_convenience(tctx->lp_ctx));
44
ndr->flags |= LIBNDR_FLAG_REF_ALLOC;
46
torture_assert_ndr_success(tctx, data->pull_fn(ndr, data->ndr_flags, ds),
49
torture_assert(tctx, ndr->offset == ndr->data_size,
51
"%d unread bytes", ndr->data_size - ndr->offset));
54
return check_fn(tctx, ds);
59
_PUBLIC_ struct torture_test *_torture_suite_add_ndr_pull_test(
60
struct torture_suite *suite,
61
const char *name, ndr_pull_flags_fn_t pull_fn,
65
bool (*check_fn) (struct torture_context *ctx, void *data))
67
struct torture_test *test;
68
struct torture_tcase *tcase;
69
struct ndr_pull_test_data *data;
71
tcase = torture_suite_add_tcase(suite, name);
73
test = talloc(tcase, struct torture_test);
75
test->name = talloc_strdup(test, name);
76
test->description = NULL;
77
test->run = wrap_ndr_pull_test;
78
data = talloc(test, struct ndr_pull_test_data);
80
data->ndr_flags = ndr_flags;
81
data->struct_size = struct_size;
82
data->pull_fn = pull_fn;
85
test->dangerous = false;
87
DLIST_ADD_END(tcase->tests, test, struct torture_test *);
92
static bool test_check_string_terminator(struct torture_context *tctx)
96
TALLOC_CTX *mem_ctx = tctx;
99
blob = strhex_to_data_blob(tctx, "0000");
101
ndr = ndr_pull_init_blob(&blob, mem_ctx, lp_iconv_convenience(tctx->lp_ctx));
103
torture_assert_ndr_success(tctx, ndr_check_string_terminator(ndr, 1, 2),
104
"simple check_string_terminator test failed");
106
torture_assert(tctx, ndr->offset == 0,
107
"check_string_terminator did not reset offset");
109
if (NDR_ERR_CODE_IS_SUCCESS(ndr_check_string_terminator(ndr, 1, 3))) {
110
torture_fail(tctx, "check_string_terminator checked beyond string boundaries");
113
torture_assert(tctx, ndr->offset == 0,
114
"check_string_terminator did not reset offset");
118
blob = strhex_to_data_blob(tctx, "11220000");
119
ndr = ndr_pull_init_blob(&blob, mem_ctx, lp_iconv_convenience(tctx->lp_ctx));
121
torture_assert_ndr_success(tctx,
122
ndr_check_string_terminator(ndr, 4, 1),
123
"check_string_terminator failed to recognize terminator");
125
torture_assert_ndr_success(tctx,
126
ndr_check_string_terminator(ndr, 3, 1),
127
"check_string_terminator failed to recognize terminator");
129
if (NDR_ERR_CODE_IS_SUCCESS(ndr_check_string_terminator(ndr, 2, 1))) {
130
torture_fail(tctx, "check_string_terminator erroneously reported terminator");
133
torture_assert(tctx, ndr->offset == 0,
134
"check_string_terminator did not reset offset");
138
static bool test_guid_from_string_valid(struct torture_context *tctx)
144
static bool test_guid_from_string_null(struct torture_context *tctx)
147
torture_assert_ntstatus_equal(tctx, NT_STATUS_INVALID_PARAMETER,
148
GUID_from_string(NULL, &guid),
153
static bool test_guid_from_string_invalid(struct torture_context *tctx)
156
torture_assert_ntstatus_equal(tctx, NT_STATUS_INVALID_PARAMETER,
157
GUID_from_string("bla", &g1),
158
"parameter not invalid");
162
static bool test_guid_from_string(struct torture_context *tctx)
165
torture_assert_ntstatus_ok(tctx,
166
GUID_from_string("00000001-0002-0003-0405-060708090a0b", &g1),
167
"invalid return code");
170
exp.time_hi_and_version = 3;
171
exp.clock_seq[0] = 4;
172
exp.clock_seq[1] = 5;
179
torture_assert(tctx, GUID_equal(&g1, &exp), "UUID parsed incorrectly");
180
torture_assert_ntstatus_ok(tctx,
181
GUID_from_string("{00000001-0002-0003-0405-060708090a0b}", &g1),
182
"invalid return code");
183
torture_assert(tctx, GUID_equal(&g1, &exp), "UUID parsed incorrectly");
188
static bool test_guid_string_valid(struct torture_context *tctx)
193
g.time_hi_and_version = 3;
202
torture_assert_str_equal(tctx, "00000001-0002-0003-0405-060708090a0b", GUID_string(tctx, &g),
203
"parsing guid failed");
207
static bool test_guid_string2_valid(struct torture_context *tctx)
212
g.time_hi_and_version = 3;
221
torture_assert_str_equal(tctx, "{00000001-0002-0003-0405-060708090a0b}", GUID_string2(tctx, &g),
222
"parsing guid failed");
226
static bool test_compare_uuid(struct torture_context *tctx)
229
ZERO_STRUCT(g1); ZERO_STRUCT(g2);
230
torture_assert_int_equal(tctx, 0, GUID_compare(&g1, &g2),
233
torture_assert_int_equal(tctx, 1, GUID_compare(&g1, &g2),
234
"GUID diff invalid");
237
torture_assert_int_equal(tctx, 10, GUID_compare(&g1, &g2),
238
"GUID diff invalid");
241
g1.clock_seq[1] = 20;
242
torture_assert_int_equal(tctx, 20, GUID_compare(&g1, &g2),
243
"GUID diff invalid");
247
struct torture_suite *torture_local_ndr(TALLOC_CTX *mem_ctx)
249
struct torture_suite *suite = torture_suite_create(mem_ctx, "NDR");
251
torture_suite_add_suite(suite, ndr_winreg_suite(suite));
252
torture_suite_add_suite(suite, ndr_atsvc_suite(suite));
253
torture_suite_add_suite(suite, ndr_lsa_suite(suite));
254
torture_suite_add_suite(suite, ndr_epmap_suite(suite));
255
torture_suite_add_suite(suite, ndr_dfs_suite(suite));
256
torture_suite_add_suite(suite, ndr_netlogon_suite(suite));
257
torture_suite_add_suite(suite, ndr_drsuapi_suite(suite));
258
torture_suite_add_suite(suite, ndr_spoolss_suite(suite));
259
torture_suite_add_suite(suite, ndr_samr_suite(suite));
261
torture_suite_add_simple_test(suite, "string terminator",
262
test_check_string_terminator);
264
torture_suite_add_simple_test(suite, "guid_from_string_null",
265
test_guid_from_string_null);
267
torture_suite_add_simple_test(suite, "guid_from_string",
268
test_guid_from_string);
270
torture_suite_add_simple_test(suite, "guid_from_string_invalid",
271
test_guid_from_string_invalid);
273
torture_suite_add_simple_test(suite, "guid_string_valid",
274
test_guid_string_valid);
276
torture_suite_add_simple_test(suite, "guid_string2_valid",
277
test_guid_string2_valid);
279
torture_suite_add_simple_test(suite, "guid_from_string_valid",
280
test_guid_from_string_valid);
282
torture_suite_add_simple_test(suite, "compare_uuid",