Line data Source code
1 : /*
2 : Unix SMB/CIFS implementation.
3 : test suite for dnsp ndr operations
4 :
5 : Copyright (C) Stefan Metzmacher 2019
6 :
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.
11 :
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.
16 :
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/>.
19 : */
20 :
21 : #include "includes.h"
22 : #include "torture/ndr/ndr.h"
23 : #include "librpc/gen_ndr/ndr_dnsp.h"
24 : #include "torture/ndr/proto.h"
25 : #include "lib/util/base64.h"
26 :
27 : /*
28 : * base64_decode_data_blob_talloc() => dump_data() gives:
29 : *
30 : * [0000] 0C 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 ........ ........
31 : * [0010] 81 00 00 00 02 00 00 00 AC 1F 63 21 AC 1F 63 2C ........ ..c!..c,
32 : * [0020] 00 00 00 00
33 : */
34 : static const char *dnsp_dnsProperty_ip4_array_b64 =
35 : "DAAAAAAAAAAAAAAAAQAAAIEAAAACAAAArB9jIawfYywAAAAA";
36 :
37 2 : static bool dnsp_dnsProperty_ip4_array_check(struct torture_context *tctx,
38 : struct dnsp_DnsProperty *r)
39 : {
40 : /*
41 : * NDR_PRINT_DEBUG(dnsp_DnsProperty, r); gave:
42 : *
43 : * r: struct dnsp_DnsProperty
44 : * wDataLength : 0x0000000c (12)
45 : * namelength : 0x00000000 (0)
46 : * flag : 0x00000000 (0)
47 : * version : 0x00000001 (1)
48 : * id : DSPROPERTY_ZONE_MASTER_SERVERS (129)
49 : * data : union dnsPropertyData(case 129)
50 : * master_servers: struct dnsp_ip4_array
51 : * addrCount : 0x00000002 (2)
52 : * addrArray: ARRAY(2)
53 : * addrArray : 0x21631fac (560144300)
54 : * addrArray : 0x2c631fac (744693676)
55 : * name : 0x00000000 (0)
56 : *
57 : */
58 :
59 2 : torture_assert_int_equal(tctx, r->wDataLength, 12, "wDataLength");
60 2 : torture_assert_int_equal(tctx, r->namelength, 0, "namelength");
61 2 : torture_assert_int_equal(tctx, r->flag, 0, "flag");
62 2 : torture_assert_int_equal(tctx, r->version, 1, "version");
63 2 : torture_assert_int_equal(tctx, r->id, DSPROPERTY_ZONE_MASTER_SERVERS, "id");
64 2 : torture_assert_int_equal(tctx, r->data.master_servers.addrCount, 2, "addrCount");
65 : /*
66 : * This should be an array of [flag(NDR_BIG_ENDIAN)] ipv4address
67 : * instead of uint32!
68 : * 0x21631fac is 172.31.99.33
69 : * 0x2c631fac is 172.31.99.44
70 : */
71 2 : torture_assert_int_equal(tctx, r->data.master_servers.addrArray[0], 0x21631fac, "addrArray[0]");
72 2 : torture_assert_int_equal(tctx, r->data.master_servers.addrArray[1], 0x2c631fac, "addrArray[1]");
73 2 : torture_assert_int_equal(tctx, r->name, 0, "name");
74 :
75 0 : return true;
76 : }
77 :
78 : /*
79 : * base64_decode_data_blob_talloc() => dump_data() gives:
80 : *
81 : * [0000] E0 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 ........ ........
82 : * [0010] 91 00 00 00 03 00 00 00 03 00 00 00 00 00 00 00 ........ ........
83 : * [0020] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ........ ........
84 : * [0030] 00 00 00 00 02 00 00 35 AC 1F 63 21 00 00 00 00 .......5 ..c!....
85 : * [0040] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ........ ........
86 : * [0050] 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 00 ........ ........
87 : * [0060] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ........ ........
88 : * [0070] 00 00 00 00 02 00 00 35 AC 1F 63 2C 00 00 00 00 .......5 ..c,....
89 : * [0080] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ........ ........
90 : * [0090] 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 00 ........ ........
91 : * [00A0] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ........ ........
92 : * [00B0] 00 00 00 00 17 00 00 35 00 00 00 00 FD 3A AA A3 .......5 .....:..
93 : * [00C0] EE 87 FF 09 02 00 00 FF FE 99 FF FF 00 00 00 00 ........ ........
94 : * [00D0] 00 00 00 00 1C 00 00 00 00 00 00 00 00 00 00 00 ........ ........
95 : * [00E0] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ........ ........
96 : * [00F0] 00 00 00 00 00 00 00 00 ........
97 : */
98 : static const char *dnsp_dnsProperty_addr_array_b64 =
99 : "4AAAAAAAAAAAAAAAAQAAAJEAAAADAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
100 : "AAAAAAIAADWsH2MhAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAA"
101 : "AAAAAAAAAAAAAAAAAAAAAAAAAAACAAA1rB9jLAAAAAAAAAAAAAAAAAAAAAAAAAAA"
102 : "AAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFwAANQAAAAD9Oqqj"
103 : "7of/CQIAAP/+mf//AAAAAAAAAAAcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
104 : "AAAAAAAAAAA=DAAAAAAAAAAAAAAAAQAAAIEAAAACAAAArB9jIawfYywAAAAA";
105 :
106 2 : static bool dnsp_dnsProperty_addr_array_check(struct torture_context *tctx,
107 : struct dnsp_DnsProperty *r)
108 : {
109 2 : const struct dnsp_dns_addr_array *da = NULL;
110 2 : const struct dnsp_dns_addr *a0 = NULL;
111 2 : const struct dnsp_dns_addr *a1 = NULL;
112 2 : const struct dnsp_dns_addr *a2 = NULL;
113 :
114 : /*
115 : * NDR_PRINT_DEBUG(dnsp_DnsProperty, r); gave:
116 : *
117 : * r: struct dnsp_DnsProperty
118 : * wDataLength : 0x000000e0 (224)
119 : * namelength : 0x00000000 (0)
120 : * flag : 0x00000000 (0)
121 : * version : 0x00000001 (1)
122 : * id : DSPROPERTY_ZONE_MASTER_SERVERS_DA (145)
123 : * data : union dnsPropertyData(case 145)
124 : * z_master_servers: struct dnsp_dns_addr_array
125 : * MaxCount : 0x00000003 (3)
126 : * AddrCount : 0x00000003 (3)
127 : * Tag : 0x00000000 (0)
128 : * Family : 0x0000 (0)
129 : * Reserved0 : 0x0000 (0)
130 : * Flags : 0x00000000 (0)
131 : * MatchFlag : 0x00000000 (0)
132 : * Reserved1 : 0x00000000 (0)
133 : * Reserved2 : 0x00000000 (0)
134 : * AddrArray: ARRAY(3)
135 : * AddrArray: struct dnsp_dns_addr
136 : * family : 0x0002 (2)
137 : * port : 0x0035 (53)
138 : * ipv4 : 172.31.99.33
139 : * ipv6 : 0000:0000:0000:0000:0000:0000:0000:0000
140 : * pad: ARRAY(8)
141 : * [0] : 0x00 (0)
142 : * [1] : 0x00 (0)
143 : * [2] : 0x00 (0)
144 : * [3] : 0x00 (0)
145 : * [4] : 0x00 (0)
146 : * [5] : 0x00 (0)
147 : * [6] : 0x00 (0)
148 : * [7] : 0x00 (0)
149 : * unused: ARRAY(8)
150 : * unused : 0x00000010 (16)
151 : * unused : 0x00000000 (0)
152 : * unused : 0x00000000 (0)
153 : * unused : 0x00000000 (0)
154 : * unused : 0x00000000 (0)
155 : * unused : 0x00000000 (0)
156 : * unused : 0x00000000 (0)
157 : * unused : 0x00000000 (0)
158 : * AddrArray: struct dnsp_dns_addr
159 : * family : 0x0002 (2)
160 : * port : 0x0035 (53)
161 : * ipv4 : 172.31.99.44
162 : * ipv6 : 0000:0000:0000:0000:0000:0000:0000:0000
163 : * pad: ARRAY(8)
164 : * [0] : 0x00 (0)
165 : * [1] : 0x00 (0)
166 : * [2] : 0x00 (0)
167 : * [3] : 0x00 (0)
168 : * [4] : 0x00 (0)
169 : * [5] : 0x00 (0)
170 : * [6] : 0x00 (0)
171 : * [7] : 0x00 (0)
172 : * unused: ARRAY(8)
173 : * unused : 0x00000010 (16)
174 : * unused : 0x00000000 (0)
175 : * unused : 0x00000000 (0)
176 : * unused : 0x00000000 (0)
177 : * unused : 0x00000000 (0)
178 : * unused : 0x00000000 (0)
179 : * unused : 0x00000000 (0)
180 : * unused : 0x00000000 (0)
181 : * AddrArray: struct dnsp_dns_addr
182 : * family : 0x0017 (23)
183 : * port : 0x0035 (53)
184 : * ipv4 : 0.0.0.0
185 : * ipv6 : fd3a:aaa3:ee87:ff09:0200:00ff:fe99:ffff
186 : * pad: ARRAY(8)
187 : * [0] : 0x00 (0)
188 : * [1] : 0x00 (0)
189 : * [2] : 0x00 (0)
190 : * [3] : 0x00 (0)
191 : * [4] : 0x00 (0)
192 : * [5] : 0x00 (0)
193 : * [6] : 0x00 (0)
194 : * [7] : 0x00 (0)
195 : * unused: ARRAY(8)
196 : * unused : 0x0000001c (28)
197 : * unused : 0x00000000 (0)
198 : * unused : 0x00000000 (0)
199 : * unused : 0x00000000 (0)
200 : * unused : 0x00000000 (0)
201 : * unused : 0x00000000 (0)
202 : * unused : 0x00000000 (0)
203 : * unused : 0x00000000 (0)
204 : * name : 0x00000000 (0)
205 : *
206 : */
207 :
208 2 : torture_assert_int_equal(tctx, r->wDataLength, 224, "wDataLength");
209 2 : torture_assert_int_equal(tctx, r->namelength, 0, "namelength");
210 2 : torture_assert_int_equal(tctx, r->flag, 0, "flag");
211 2 : torture_assert_int_equal(tctx, r->version, 1, "version");
212 2 : torture_assert_int_equal(tctx, r->id, DSPROPERTY_ZONE_MASTER_SERVERS_DA, "id");
213 2 : da = &r->data.z_master_servers;
214 2 : torture_assert_int_equal(tctx, da->MaxCount, 3, "MaxCount");
215 2 : torture_assert_int_equal(tctx, da->AddrCount, 3, "AddrCount");
216 2 : torture_assert_int_equal(tctx, da->Tag, 0, "Tag");
217 2 : torture_assert_int_equal(tctx, da->Family, 0, "Family");
218 2 : torture_assert_int_equal(tctx, da->Reserved0, 0, "Reserved0");
219 2 : torture_assert_int_equal(tctx, da->Flags, 0, "Flags");
220 2 : torture_assert_int_equal(tctx, da->MatchFlag, 0, "MatchFlag");
221 2 : torture_assert_int_equal(tctx, da->Reserved1, 0, "Reserved1");
222 2 : torture_assert_int_equal(tctx, da->Reserved2, 0, "Reserved2");
223 2 : a0 = &da->AddrArray[0];
224 2 : torture_assert_int_equal(tctx, a0->family, 2, "family v4");
225 2 : torture_assert_int_equal(tctx, a0->port, 53, "port");
226 2 : torture_assert_str_equal(tctx, a0->ipv4, "172.31.99.33", "ipv4");
227 2 : torture_assert_str_equal(tctx, a0->ipv6,
228 : "0000:0000:0000:0000:0000:0000:0000:0000",
229 : "ipv6 (zero)");
230 2 : torture_assert_int_equal(tctx, a0->pad[0], 0, "pad[0]");
231 2 : torture_assert_int_equal(tctx, a0->pad[1], 0, "pad[1]");
232 2 : torture_assert_int_equal(tctx, a0->pad[2], 0, "pad[2]");
233 2 : torture_assert_int_equal(tctx, a0->pad[3], 0, "pad[3]");
234 2 : torture_assert_int_equal(tctx, a0->pad[4], 0, "pad[4]");
235 2 : torture_assert_int_equal(tctx, a0->pad[5], 0, "pad[5]");
236 2 : torture_assert_int_equal(tctx, a0->pad[6], 0, "pad[6]");
237 2 : torture_assert_int_equal(tctx, a0->pad[7], 0, "pad[7]");
238 2 : torture_assert_int_equal(tctx, a0->unused[0], 16, "unused[0]");
239 2 : torture_assert_int_equal(tctx, a0->unused[1], 0, "unused[1]");
240 2 : torture_assert_int_equal(tctx, a0->unused[2], 0, "unused[2]");
241 2 : torture_assert_int_equal(tctx, a0->unused[3], 0, "unused[3]");
242 2 : torture_assert_int_equal(tctx, a0->unused[4], 0, "unused[4]");
243 2 : torture_assert_int_equal(tctx, a0->unused[5], 0, "unused[5]");
244 2 : torture_assert_int_equal(tctx, a0->unused[6], 0, "unused[6]");
245 2 : torture_assert_int_equal(tctx, a0->unused[7], 0, "unused[7]");
246 2 : a1 = &da->AddrArray[1];
247 2 : torture_assert_int_equal(tctx, a1->family, 2, "family v4");
248 2 : torture_assert_int_equal(tctx, a1->port, 53, "port");
249 2 : torture_assert_str_equal(tctx, a1->ipv4, "172.31.99.44", "ipv4");
250 2 : torture_assert_str_equal(tctx, a1->ipv6,
251 : "0000:0000:0000:0000:0000:0000:0000:0000",
252 : "ipv6 (zero)");
253 2 : torture_assert_int_equal(tctx, a1->pad[0], 0, "pad[0]");
254 2 : torture_assert_int_equal(tctx, a1->pad[1], 0, "pad[1]");
255 2 : torture_assert_int_equal(tctx, a1->pad[2], 0, "pad[2]");
256 2 : torture_assert_int_equal(tctx, a1->pad[3], 0, "pad[3]");
257 2 : torture_assert_int_equal(tctx, a1->pad[4], 0, "pad[4]");
258 2 : torture_assert_int_equal(tctx, a1->pad[5], 0, "pad[5]");
259 2 : torture_assert_int_equal(tctx, a1->pad[6], 0, "pad[6]");
260 2 : torture_assert_int_equal(tctx, a1->pad[7], 0, "pad[7]");
261 2 : torture_assert_int_equal(tctx, a1->unused[0], 16, "unused[0]");
262 2 : torture_assert_int_equal(tctx, a1->unused[1], 0, "unused[1]");
263 2 : torture_assert_int_equal(tctx, a1->unused[2], 0, "unused[2]");
264 2 : torture_assert_int_equal(tctx, a1->unused[3], 0, "unused[3]");
265 2 : torture_assert_int_equal(tctx, a1->unused[4], 0, "unused[4]");
266 2 : torture_assert_int_equal(tctx, a1->unused[5], 0, "unused[5]");
267 2 : torture_assert_int_equal(tctx, a1->unused[6], 0, "unused[6]");
268 2 : torture_assert_int_equal(tctx, a1->unused[7], 0, "unused[7]");
269 2 : a2 = &da->AddrArray[2];
270 2 : torture_assert_int_equal(tctx, a2->family, 23, "family v6");
271 2 : torture_assert_int_equal(tctx, a2->port, 53, "port");
272 2 : torture_assert_str_equal(tctx, a2->ipv4, "0.0.0.0", "ipv4 (zero)");
273 2 : torture_assert_str_equal(tctx, a2->ipv6,
274 : "fd3a:aaa3:ee87:ff09:0200:00ff:fe99:ffff",
275 : "ipv6");
276 2 : torture_assert_int_equal(tctx, a2->pad[0], 0, "pad[0]");
277 2 : torture_assert_int_equal(tctx, a2->pad[1], 0, "pad[1]");
278 2 : torture_assert_int_equal(tctx, a2->pad[2], 0, "pad[2]");
279 2 : torture_assert_int_equal(tctx, a2->pad[3], 0, "pad[3]");
280 2 : torture_assert_int_equal(tctx, a2->pad[4], 0, "pad[4]");
281 2 : torture_assert_int_equal(tctx, a2->pad[5], 0, "pad[5]");
282 2 : torture_assert_int_equal(tctx, a2->pad[6], 0, "pad[6]");
283 2 : torture_assert_int_equal(tctx, a2->pad[7], 0, "pad[7]");
284 2 : torture_assert_int_equal(tctx, a2->unused[0], 28, "unused[0]");
285 2 : torture_assert_int_equal(tctx, a2->unused[1], 0, "unused[1]");
286 2 : torture_assert_int_equal(tctx, a2->unused[2], 0, "unused[2]");
287 2 : torture_assert_int_equal(tctx, a2->unused[3], 0, "unused[3]");
288 2 : torture_assert_int_equal(tctx, a2->unused[4], 0, "unused[4]");
289 2 : torture_assert_int_equal(tctx, a2->unused[5], 0, "unused[5]");
290 2 : torture_assert_int_equal(tctx, a2->unused[6], 0, "unused[6]");
291 2 : torture_assert_int_equal(tctx, a2->unused[7], 0, "unused[7]");
292 2 : torture_assert_int_equal(tctx, r->name, 0, "name");
293 :
294 0 : return true;
295 : }
296 :
297 : /*
298 : * base64_decode_data_blob_talloc() => dump_data() gives:
299 : *
300 : * [0000] 26 00 00 00 01 EE C4 71 00 00 00 00 01 00 00 00 &......q ........
301 : * [0010] 80 00 00 00 77 00 32 00 6B 00 33 00 2D 00 31 00 ....w.2. k.3.-.1.
302 : * [0020] 39 00 31 00 2E 00 77 00 32 00 6B 00 33 00 2E 00 9.1...w. 2.k.3...
303 : * [0030] 62 00 61 00 73 00 65 00 00 00 C4 71 EC F3 b.a.s.e. ...q..
304 : */
305 : static const char *dnsp_dnsProperty_deleted_by_b64 =
306 : "JgAAAAHuxHEAAAAAAQAAAIAAAAB3ADIAawAzAC0AMQA5ADEALgB3ADIAawAzAC4A"
307 : "YgBhAHMAZQAAAMRx7PM=";
308 :
309 2 : static bool dnsp_dnsProperty_deleted_by_check(struct torture_context *tctx,
310 : struct dnsp_DnsProperty *r)
311 : {
312 : /*
313 : * NDR_PRINT_DEBUG(dnsp_DnsProperty, r); gave:
314 : *
315 : * r: struct dnsp_DnsProperty
316 : * wDataLength : 0x00000026 (38)
317 : * namelength : 0x71c4ee01 (1908731393)
318 : * flag : 0x00000000 (0)
319 : * version : 0x00000001 (1)
320 : * id : DSPROPERTY_ZONE_DELETED_FROM_HOSTNAME (128)
321 : * data : union dnsPropertyData(case 128)
322 : * deleted_by_hostname : 'w2k3-191.w2k3.base'
323 : * name : 0xf3ec71c4 (4092359108)
324 : *
325 : * Note Windows 2003 didn't seem to initialize namelength and name
326 : * both are 'Not Used. The value MUST be ignored ...'
327 : */
328 :
329 2 : torture_assert_int_equal(tctx, r->wDataLength, 38, "wDataLength");
330 2 : torture_assert_int_equal(tctx, r->namelength, 1908731393, "namelength (random)");
331 2 : torture_assert_int_equal(tctx, r->flag, 0, "flag");
332 2 : torture_assert_int_equal(tctx, r->version, 1, "version");
333 2 : torture_assert_int_equal(tctx, r->id, DSPROPERTY_ZONE_DELETED_FROM_HOSTNAME, "id");
334 2 : torture_assert_str_equal(tctx, r->data.deleted_by_hostname, "w2k3-191.w2k3.base", "hostname");
335 2 : torture_assert_int_equal(tctx, r->name, 0xf3ec71c4, "name (random)");
336 :
337 0 : return true;
338 : }
339 :
340 : /*
341 : * Copy of dnsp_dnsProperty_deleted_by_b64 with wDataLength set to 0
342 : * and no data in the data element.
343 : * This is a reproducer for https://bugzilla.samba.org/show_bug.cgi?id=14206
344 : * The dns_property_id was retained so once parsed this structure referenced
345 : * memory past it's end.
346 : *
347 : * [0000] 00 00 00 00 01 EE C4 71 00 00 00 00 01 00 00 00 &......q ........
348 : * [0010] 80 00 00 00 77 00 32 00 6B 00 33 00 2D 00 31 00 ....w.2. k.3.-.1.
349 : * [0020] 39 00 31 00 2E 00 77 00 32 00 6B 00 33 00 2E 00 9.1...w. 2.k.3...
350 : * [0030] 62 00 61 00 73 00 65 00 00 00 C4 71 EC F3 b.a.s.e. ...q..
351 : */
352 : static const uint8_t dnsp_dnsProperty_deleted_by_zero_wDataLength[] = {
353 : 0x00, 0x00, 0x00, 0x00, 0x01, 0xEE, 0xC4, 0x71, 0x00, 0x00, 0x00,
354 : 0x00, 0x01, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00,
355 : 0xC4, 0x71, 0xEC, 0xF3 };
356 :
357 2354 : struct torture_suite *ndr_dnsp_suite(TALLOC_CTX *ctx)
358 : {
359 2354 : struct torture_suite *suite = torture_suite_create(ctx, "dnsp");
360 :
361 2354 : torture_suite_add_ndr_pull_validate_test_b64(
362 : suite,
363 : dnsp_DnsProperty,
364 : "ZONE_MASTER_SERVERS",
365 : dnsp_dnsProperty_ip4_array_b64,
366 : dnsp_dnsProperty_ip4_array_check);
367 :
368 2354 : torture_suite_add_ndr_pull_validate_test_b64(
369 : suite,
370 : dnsp_DnsProperty,
371 : "ZONE_MASTER_SERVERS_DA",
372 : dnsp_dnsProperty_addr_array_b64,
373 : dnsp_dnsProperty_addr_array_check);
374 :
375 2354 : torture_suite_add_ndr_pull_validate_test_b64(
376 : suite,
377 : dnsp_DnsProperty,
378 : "DELETED_FROM_HOSTNAME",
379 : dnsp_dnsProperty_deleted_by_b64,
380 : dnsp_dnsProperty_deleted_by_check);
381 :
382 2354 : torture_suite_add_ndr_pull_invalid_data_test(
383 : suite,
384 : dnsp_DnsProperty,
385 : dnsp_dnsProperty_deleted_by_zero_wDataLength,
386 125 : NDR_ERR_BUFSIZE);
387 :
388 2354 : return suite;
389 : }
|