1 | /*
|
---|
2 | Unix SMB/CIFS implementation.
|
---|
3 |
|
---|
4 | local testing of registry library
|
---|
5 |
|
---|
6 | Copyright (C) Jelmer Vernooij 2005-2007
|
---|
7 |
|
---|
8 | This program is free software; you can redistribute it and/or modify
|
---|
9 | it under the terms of the GNU General Public License as published by
|
---|
10 | the Free Software Foundation; either version 3 of the License, or
|
---|
11 | (at your option) any later version.
|
---|
12 |
|
---|
13 | This program is distributed in the hope that it will be useful,
|
---|
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
16 | GNU General Public License for more details.
|
---|
17 |
|
---|
18 | You should have received a copy of the GNU General Public License
|
---|
19 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
20 | */
|
---|
21 |
|
---|
22 | #include "includes.h"
|
---|
23 | #include "lib/registry/registry.h"
|
---|
24 | #include "torture/torture.h"
|
---|
25 | #include "librpc/gen_ndr/winreg.h"
|
---|
26 | #include "param/param.h"
|
---|
27 |
|
---|
28 | struct torture_suite *torture_registry_hive(TALLOC_CTX *mem_ctx);
|
---|
29 | struct torture_suite *torture_registry_registry(TALLOC_CTX *mem_ctx);
|
---|
30 | struct torture_suite *torture_registry_diff(TALLOC_CTX *mem_ctx);
|
---|
31 |
|
---|
32 | static bool test_str_regtype(struct torture_context *ctx)
|
---|
33 | {
|
---|
34 | torture_assert_str_equal(ctx, str_regtype(0),
|
---|
35 | "REG_NONE", "REG_NONE failed");
|
---|
36 | torture_assert_str_equal(ctx, str_regtype(1),
|
---|
37 | "REG_SZ", "REG_SZ failed");
|
---|
38 | torture_assert_str_equal(ctx, str_regtype(2),
|
---|
39 | "REG_EXPAND_SZ", "REG_EXPAND_SZ failed");
|
---|
40 | torture_assert_str_equal(ctx, str_regtype(3),
|
---|
41 | "REG_BINARY", "REG_BINARY failed");
|
---|
42 | torture_assert_str_equal(ctx, str_regtype(4),
|
---|
43 | "REG_DWORD", "REG_DWORD failed");
|
---|
44 | torture_assert_str_equal(ctx, str_regtype(5),
|
---|
45 | "REG_DWORD_BIG_ENDIAN", "REG_DWORD_BIG_ENDIAN failed");
|
---|
46 | torture_assert_str_equal(ctx, str_regtype(6),
|
---|
47 | "REG_LINK", "REG_LINK failed");
|
---|
48 | torture_assert_str_equal(ctx, str_regtype(7),
|
---|
49 | "REG_MULTI_SZ", "REG_MULTI_SZ failed");
|
---|
50 | torture_assert_str_equal(ctx, str_regtype(8),
|
---|
51 | "REG_RESOURCE_LIST", "REG_RESOURCE_LIST failed");
|
---|
52 | torture_assert_str_equal(ctx, str_regtype(9),
|
---|
53 | "REG_FULL_RESOURCE_DESCRIPTOR", "REG_FULL_RESOURCE_DESCRIPTOR failed");
|
---|
54 | torture_assert_str_equal(ctx, str_regtype(10),
|
---|
55 | "REG_RESOURCE_REQUIREMENTS_LIST", "REG_RESOURCE_REQUIREMENTS_LIST failed");
|
---|
56 | torture_assert_str_equal(ctx, str_regtype(11),
|
---|
57 | "REG_QWORD", "REG_QWORD failed");
|
---|
58 |
|
---|
59 | return true;
|
---|
60 | }
|
---|
61 |
|
---|
62 |
|
---|
63 | static bool test_reg_val_data_string_dword(struct torture_context *ctx)
|
---|
64 | {
|
---|
65 | uint8_t d[] = { 0x20, 0x00, 0x00, 0x00 };
|
---|
66 | DATA_BLOB db = { d, 4 };
|
---|
67 | torture_assert_str_equal(ctx, "0x00000020",
|
---|
68 | reg_val_data_string(ctx, REG_DWORD, db),
|
---|
69 | "dword failed");
|
---|
70 | return true;
|
---|
71 | }
|
---|
72 |
|
---|
73 | static bool test_reg_val_data_string_dword_big_endian(struct torture_context *ctx)
|
---|
74 | {
|
---|
75 | uint8_t d[] = { 0x20, 0x00, 0x00, 0x00 };
|
---|
76 | DATA_BLOB db = { d, 4 };
|
---|
77 | torture_assert_str_equal(ctx, "0x00000020",
|
---|
78 | reg_val_data_string(ctx, REG_DWORD_BIG_ENDIAN, db),
|
---|
79 | "dword failed");
|
---|
80 | return true;
|
---|
81 | }
|
---|
82 |
|
---|
83 | static bool test_reg_val_data_string_qword(struct torture_context *ctx)
|
---|
84 | {
|
---|
85 | uint8_t d[] = { 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
---|
86 | DATA_BLOB db = { d, 8 };
|
---|
87 | torture_assert_str_equal(ctx, "0x0000000000000020",
|
---|
88 | reg_val_data_string(ctx, REG_QWORD, db),
|
---|
89 | "qword failed");
|
---|
90 | return true;
|
---|
91 | }
|
---|
92 |
|
---|
93 | static bool test_reg_val_data_string_sz(struct torture_context *ctx)
|
---|
94 | {
|
---|
95 | DATA_BLOB db;
|
---|
96 | convert_string_talloc(ctx, CH_UTF8, CH_UTF16,
|
---|
97 | "bla", 3, (void **)&db.data, &db.length, false);
|
---|
98 | torture_assert_str_equal(ctx, "bla",
|
---|
99 | reg_val_data_string(ctx, REG_SZ, db),
|
---|
100 | "sz failed");
|
---|
101 | db.length = 4;
|
---|
102 | torture_assert_str_equal(ctx, "bl",
|
---|
103 | reg_val_data_string(ctx, REG_SZ, db),
|
---|
104 | "sz failed");
|
---|
105 | return true;
|
---|
106 | }
|
---|
107 |
|
---|
108 | static bool test_reg_val_data_string_binary(struct torture_context *ctx)
|
---|
109 | {
|
---|
110 | uint8_t x[] = { 0x1, 0x2, 0x3, 0x4 };
|
---|
111 | DATA_BLOB db = { x, 4 };
|
---|
112 | torture_assert_str_equal(ctx, "01020304",
|
---|
113 | reg_val_data_string(ctx, REG_BINARY, db),
|
---|
114 | "binary failed");
|
---|
115 | return true;
|
---|
116 | }
|
---|
117 |
|
---|
118 |
|
---|
119 | static bool test_reg_val_data_string_empty(struct torture_context *ctx)
|
---|
120 | {
|
---|
121 | DATA_BLOB db = { NULL, 0 };
|
---|
122 | torture_assert_str_equal(ctx, "",
|
---|
123 | reg_val_data_string(ctx, REG_BINARY, db),
|
---|
124 | "empty failed");
|
---|
125 | return true;
|
---|
126 | }
|
---|
127 |
|
---|
128 | static bool test_reg_val_description(struct torture_context *ctx)
|
---|
129 | {
|
---|
130 | DATA_BLOB data;
|
---|
131 | convert_string_talloc(ctx, CH_UTF8, CH_UTF16,
|
---|
132 | "stationary traveller",
|
---|
133 | strlen("stationary traveller"),
|
---|
134 | (void **)&data.data, &data.length, false);
|
---|
135 | torture_assert_str_equal(ctx, "camel = REG_SZ : stationary traveller",
|
---|
136 | reg_val_description(ctx, "camel", REG_SZ, data),
|
---|
137 | "reg_val_description failed");
|
---|
138 | return true;
|
---|
139 | }
|
---|
140 |
|
---|
141 |
|
---|
142 | static bool test_reg_val_description_nullname(struct torture_context *ctx)
|
---|
143 | {
|
---|
144 | DATA_BLOB data;
|
---|
145 | convert_string_talloc(ctx, CH_UTF8, CH_UTF16,
|
---|
146 | "west berlin",
|
---|
147 | strlen("west berlin"),
|
---|
148 | (void **)&data.data, &data.length, false);
|
---|
149 | torture_assert_str_equal(ctx, "<No Name> = REG_SZ : west berlin",
|
---|
150 | reg_val_description(ctx, NULL, REG_SZ, data),
|
---|
151 | "description with null name failed");
|
---|
152 | return true;
|
---|
153 | }
|
---|
154 |
|
---|
155 | struct torture_suite *torture_registry(TALLOC_CTX *mem_ctx)
|
---|
156 | {
|
---|
157 | struct torture_suite *suite = torture_suite_create(mem_ctx, "registry");
|
---|
158 | torture_suite_add_simple_test(suite, "str_regtype",
|
---|
159 | test_str_regtype);
|
---|
160 | torture_suite_add_simple_test(suite, "reg_val_data_string dword",
|
---|
161 | test_reg_val_data_string_dword);
|
---|
162 | torture_suite_add_simple_test(suite, "reg_val_data_string dword_big_endian",
|
---|
163 | test_reg_val_data_string_dword_big_endian);
|
---|
164 | torture_suite_add_simple_test(suite, "reg_val_data_string qword",
|
---|
165 | test_reg_val_data_string_qword);
|
---|
166 | torture_suite_add_simple_test(suite, "reg_val_data_string sz",
|
---|
167 | test_reg_val_data_string_sz);
|
---|
168 | torture_suite_add_simple_test(suite, "reg_val_data_string binary",
|
---|
169 | test_reg_val_data_string_binary);
|
---|
170 | torture_suite_add_simple_test(suite, "reg_val_data_string empty",
|
---|
171 | test_reg_val_data_string_empty);
|
---|
172 | torture_suite_add_simple_test(suite, "reg_val_description",
|
---|
173 | test_reg_val_description);
|
---|
174 | torture_suite_add_simple_test(suite, "reg_val_description null",
|
---|
175 | test_reg_val_description_nullname);
|
---|
176 |
|
---|
177 | torture_suite_add_suite(suite, torture_registry_hive(suite));
|
---|
178 | torture_suite_add_suite(suite, torture_registry_registry(suite));
|
---|
179 | torture_suite_add_suite(suite, torture_registry_diff(suite));
|
---|
180 |
|
---|
181 | return suite;
|
---|
182 | }
|
---|