1de24cbc7edbfbce87303bd1cb4e567725cecd39
[samba.git] / source4 / torture / ldb / ldb.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    Test LDB attribute functions
5
6    Copyright (C) Andrew Bartlet <abartlet@samba.org> 2008
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/events/events.h"
24 #include <ldb.h>
25 #include <ldb-samba/ldb_wrap.h>
26 #include <ldb_errors.h>
27 #include <ldb_module.h>
28 #include "lib/ldb-samba/ldif_handlers.h"
29 #include "ldb_wrap.h"
30 #include "dsdb/samdb/samdb.h"
31 #include "param/param.h"
32 #include "torture/smbtorture.h"
33 #include "torture/local/proto.h"
34 #include <time.h>
35
36 static const char *sid = "S-1-5-21-4177067393-1453636373-93818737";
37 static const char *hex_sid = "01040000000000051500000081fdf8f815bba456718f9705";
38 static const char *guid = "975ac5fa-35d9-431d-b86a-845bcd34fff9";
39 static const char *guid2 = "{975ac5fa-35d9-431d-b86a-845bcd34fff9}";
40 static const char *hex_guid = "fac55a97d9351d43b86a845bcd34fff9";
41
42 static const char *prefix_map_newline = "2:1.2.840.113556.1.2\n5:2.16.840.1.101.2.2.3";
43 static const char *prefix_map_semi = "2:1.2.840.113556.1.2;5:2.16.840.1.101.2.2.3";
44
45 /**
46  * This is the hex code derived from the tdbdump for
47  * "st/ad_dc/private/sam.ldb.d/DC=ADDC,DC=SAMBA,DC=EXAMPLE,DC=COM.ldb"
48  * key "DN=CN=DDA1D01D-4BD7-4C49-A184-46F9241B560E,CN=OPERATIONS,CN=DOMAINUPDATES,CN=SYSTEM,DC=ADDC,DC=SAMBA,DC=EXAMPLE,DC=COM\00"
49  *   -- adrianc
50  */
51
52 static const uint8_t dda1d01d_bin_v1[] = {
53         0x67, 0x19, 0x01, 0x26, 0x0d, 0x00, 0x00, 0x00, 0x43, 0x4e, 0x3d, 0x64, 0x64, 0x61, 0x31, 0x64,
54         0x30, 0x31, 0x64, 0x2d, 0x34, 0x62, 0x64, 0x37, 0x2d, 0x34, 0x63, 0x34, 0x39, 0x2d, 0x61, 0x31,
55         0x38, 0x34, 0x2d, 0x34, 0x36, 0x66, 0x39, 0x32, 0x34, 0x31, 0x62, 0x35, 0x36, 0x30, 0x65, 0x2c,
56         0x43, 0x4e, 0x3d, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2c, 0x43, 0x4e,
57         0x3d, 0x44, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x73, 0x2c, 0x43,
58         0x4e, 0x3d, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2c, 0x44, 0x43, 0x3d, 0x61, 0x64, 0x64, 0x63,
59         0x2c, 0x44, 0x43, 0x3d, 0x73, 0x61, 0x6d, 0x62, 0x61, 0x2c, 0x44, 0x43, 0x3d, 0x65, 0x78, 0x61,
60         0x6d, 0x70, 0x6c, 0x65, 0x2c, 0x44, 0x43, 0x3d, 0x63, 0x6f, 0x6d, 0x00, 0x6f, 0x62, 0x6a, 0x65,
61         0x63, 0x74, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
62         0x74, 0x6f, 0x70, 0x00, 0x09, 0x00, 0x00, 0x00, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65,
63         0x72, 0x00, 0x63, 0x6e, 0x00, 0x01, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x64, 0x64, 0x61,
64         0x31, 0x64, 0x30, 0x31, 0x64, 0x2d, 0x34, 0x62, 0x64, 0x37, 0x2d, 0x34, 0x63, 0x34, 0x39, 0x2d,
65         0x61, 0x31, 0x38, 0x34, 0x2d, 0x34, 0x36, 0x66, 0x39, 0x32, 0x34, 0x31, 0x62, 0x35, 0x36, 0x30,
66         0x65, 0x00, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x54, 0x79, 0x70, 0x65, 0x00, 0x01,
67         0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x34, 0x00, 0x77, 0x68, 0x65, 0x6e, 0x43, 0x72, 0x65,
68         0x61, 0x74, 0x65, 0x64, 0x00, 0x01, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x32, 0x30, 0x31,
69         0x35, 0x30, 0x37, 0x30, 0x38, 0x32, 0x32, 0x34, 0x33, 0x31, 0x30, 0x2e, 0x30, 0x5a, 0x00, 0x77,
70         0x68, 0x65, 0x6e, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x64, 0x00, 0x01, 0x00, 0x00, 0x00, 0x11,
71         0x00, 0x00, 0x00, 0x32, 0x30, 0x31, 0x35, 0x30, 0x37, 0x30, 0x38, 0x32, 0x32, 0x34, 0x33, 0x31,
72         0x30, 0x2e, 0x30, 0x5a, 0x00, 0x75, 0x53, 0x4e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x00,
73         0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x33, 0x34, 0x36, 0x37, 0x00, 0x75, 0x53, 0x4e,
74         0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x64, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
75         0x33, 0x34, 0x36, 0x37, 0x00, 0x73, 0x68, 0x6f, 0x77, 0x49, 0x6e, 0x41, 0x64, 0x76, 0x61, 0x6e,
76         0x63, 0x65, 0x64, 0x56, 0x69, 0x65, 0x77, 0x4f, 0x6e, 0x6c, 0x79, 0x00, 0x01, 0x00, 0x00, 0x00,
77         0x04, 0x00, 0x00, 0x00, 0x54, 0x52, 0x55, 0x45, 0x00, 0x6e, 0x54, 0x53, 0x65, 0x63, 0x75, 0x72,
78         0x69, 0x74, 0x79, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0x00, 0x01, 0x00,
79         0x00, 0x00, 0x18, 0x05, 0x00, 0x00, 0x01, 0x00, 0x17, 0x8c, 0x14, 0x00, 0x00, 0x00, 0x30, 0x00,
80         0x00, 0x00, 0x4c, 0x00, 0x00, 0x00, 0xc4, 0x00, 0x00, 0x00, 0x01, 0x05, 0x00, 0x00, 0x00, 0x00,
81         0x00, 0x05, 0x15, 0x00, 0x00, 0x00, 0x9a, 0xbd, 0x91, 0x7d, 0xd5, 0xe0, 0x11, 0x3c, 0x6e, 0x5e,
82         0x1a, 0x4b, 0x00, 0x02, 0x00, 0x00, 0x01, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x15, 0x00,
83         0x00, 0x00, 0x9a, 0xbd, 0x91, 0x7d, 0xd5, 0xe0, 0x11, 0x3c, 0x6e, 0x5e, 0x1a, 0x4b, 0x00, 0x02,
84         0x00, 0x00, 0x04, 0x00, 0x78, 0x00, 0x02, 0x00, 0x00, 0x00, 0x07, 0x5a, 0x38, 0x00, 0x20, 0x00,
85         0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xbe, 0x3b, 0x0e, 0xf3, 0xf0, 0x9f, 0xd1, 0x11, 0xb6, 0x03,
86         0x00, 0x00, 0xf8, 0x03, 0x67, 0xc1, 0xa5, 0x7a, 0x96, 0xbf, 0xe6, 0x0d, 0xd0, 0x11, 0xa2, 0x85,
87         0x00, 0xaa, 0x00, 0x30, 0x49, 0xe2, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
88         0x00, 0x00, 0x07, 0x5a, 0x38, 0x00, 0x20, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xbf, 0x3b,
89         0x0e, 0xf3, 0xf0, 0x9f, 0xd1, 0x11, 0xb6, 0x03, 0x00, 0x00, 0xf8, 0x03, 0x67, 0xc1, 0xa5, 0x7a,
90         0x96, 0xbf, 0xe6, 0x0d, 0xd0, 0x11, 0xa2, 0x85, 0x00, 0xaa, 0x00, 0x30, 0x49, 0xe2, 0x01, 0x01,
91         0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x54, 0x04, 0x17, 0x00,
92         0x00, 0x00, 0x00, 0x00, 0x24, 0x00, 0xff, 0x01, 0x0f, 0x00, 0x01, 0x05, 0x00, 0x00, 0x00, 0x00,
93         0x00, 0x05, 0x15, 0x00, 0x00, 0x00, 0x9a, 0xbd, 0x91, 0x7d, 0xd5, 0xe0, 0x11, 0x3c, 0x6e, 0x5e,
94         0x1a, 0x4b, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0xff, 0x01, 0x0f, 0x00, 0x01, 0x01,
95         0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x94, 0x00,
96         0x02, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x0b, 0x00, 0x00, 0x00, 0x05, 0x1a,
97         0x3c, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x42, 0x16, 0x4c, 0xc0, 0x20,
98         0xd0, 0x11, 0xa7, 0x68, 0x00, 0xaa, 0x00, 0x6e, 0x05, 0x29, 0x14, 0xcc, 0x28, 0x48, 0x37, 0x14,
99         0xbc, 0x45, 0x9b, 0x07, 0xad, 0x6f, 0x01, 0x5e, 0x5f, 0x28, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00,
100         0x00, 0x05, 0x20, 0x00, 0x00, 0x00, 0x2a, 0x02, 0x00, 0x00, 0x05, 0x1a, 0x3c, 0x00, 0x10, 0x00,
101         0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x42, 0x16, 0x4c, 0xc0, 0x20, 0xd0, 0x11, 0xa7, 0x68,
102         0x00, 0xaa, 0x00, 0x6e, 0x05, 0x29, 0xba, 0x7a, 0x96, 0xbf, 0xe6, 0x0d, 0xd0, 0x11, 0xa2, 0x85,
103         0x00, 0xaa, 0x00, 0x30, 0x49, 0xe2, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x20, 0x00,
104         0x00, 0x00, 0x2a, 0x02, 0x00, 0x00, 0x05, 0x1a, 0x3c, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x00,
105         0x00, 0x00, 0x10, 0x20, 0x20, 0x5f, 0xa5, 0x79, 0xd0, 0x11, 0x90, 0x20, 0x00, 0xc0, 0x4f, 0xc2,
106         0xd4, 0xcf, 0x14, 0xcc, 0x28, 0x48, 0x37, 0x14, 0xbc, 0x45, 0x9b, 0x07, 0xad, 0x6f, 0x01, 0x5e,
107         0x5f, 0x28, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x20, 0x00, 0x00, 0x00, 0x2a, 0x02,
108         0x00, 0x00, 0x05, 0x1a, 0x3c, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, 0x20,
109         0x20, 0x5f, 0xa5, 0x79, 0xd0, 0x11, 0x90, 0x20, 0x00, 0xc0, 0x4f, 0xc2, 0xd4, 0xcf, 0xba, 0x7a,
110         0x96, 0xbf, 0xe6, 0x0d, 0xd0, 0x11, 0xa2, 0x85, 0x00, 0xaa, 0x00, 0x30, 0x49, 0xe2, 0x01, 0x02,
111         0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x20, 0x00, 0x00, 0x00, 0x2a, 0x02, 0x00, 0x00, 0x05, 0x1a,
112         0x3c, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x40, 0xc2, 0x0a, 0xbc, 0xa9, 0x79,
113         0xd0, 0x11, 0x90, 0x20, 0x00, 0xc0, 0x4f, 0xc2, 0xd4, 0xcf, 0x14, 0xcc, 0x28, 0x48, 0x37, 0x14,
114         0xbc, 0x45, 0x9b, 0x07, 0xad, 0x6f, 0x01, 0x5e, 0x5f, 0x28, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00,
115         0x00, 0x05, 0x20, 0x00, 0x00, 0x00, 0x2a, 0x02, 0x00, 0x00, 0x05, 0x1a, 0x3c, 0x00, 0x10, 0x00,
116         0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x40, 0xc2, 0x0a, 0xbc, 0xa9, 0x79, 0xd0, 0x11, 0x90, 0x20,
117         0x00, 0xc0, 0x4f, 0xc2, 0xd4, 0xcf, 0xba, 0x7a, 0x96, 0xbf, 0xe6, 0x0d, 0xd0, 0x11, 0xa2, 0x85,
118         0x00, 0xaa, 0x00, 0x30, 0x49, 0xe2, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x20, 0x00,
119         0x00, 0x00, 0x2a, 0x02, 0x00, 0x00, 0x05, 0x1a, 0x3c, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x00,
120         0x00, 0x00, 0x42, 0x2f, 0xba, 0x59, 0xa2, 0x79, 0xd0, 0x11, 0x90, 0x20, 0x00, 0xc0, 0x4f, 0xc2,
121         0xd3, 0xcf, 0x14, 0xcc, 0x28, 0x48, 0x37, 0x14, 0xbc, 0x45, 0x9b, 0x07, 0xad, 0x6f, 0x01, 0x5e,
122         0x5f, 0x28, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x20, 0x00, 0x00, 0x00, 0x2a, 0x02,
123         0x00, 0x00, 0x05, 0x1a, 0x3c, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x42, 0x2f,
124         0xba, 0x59, 0xa2, 0x79, 0xd0, 0x11, 0x90, 0x20, 0x00, 0xc0, 0x4f, 0xc2, 0xd3, 0xcf, 0xba, 0x7a,
125         0x96, 0xbf, 0xe6, 0x0d, 0xd0, 0x11, 0xa2, 0x85, 0x00, 0xaa, 0x00, 0x30, 0x49, 0xe2, 0x01, 0x02,
126         0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x20, 0x00, 0x00, 0x00, 0x2a, 0x02, 0x00, 0x00, 0x05, 0x1a,
127         0x3c, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xf8, 0x88, 0x70, 0x03, 0xe1, 0x0a,
128         0xd2, 0x11, 0xb4, 0x22, 0x00, 0xa0, 0xc9, 0x68, 0xf9, 0x39, 0x14, 0xcc, 0x28, 0x48, 0x37, 0x14,
129         0xbc, 0x45, 0x9b, 0x07, 0xad, 0x6f, 0x01, 0x5e, 0x5f, 0x28, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00,
130         0x00, 0x05, 0x20, 0x00, 0x00, 0x00, 0x2a, 0x02, 0x00, 0x00, 0x05, 0x1a, 0x3c, 0x00, 0x10, 0x00,
131         0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xf8, 0x88, 0x70, 0x03, 0xe1, 0x0a, 0xd2, 0x11, 0xb4, 0x22,
132         0x00, 0xa0, 0xc9, 0x68, 0xf9, 0x39, 0xba, 0x7a, 0x96, 0xbf, 0xe6, 0x0d, 0xd0, 0x11, 0xa2, 0x85,
133         0x00, 0xaa, 0x00, 0x30, 0x49, 0xe2, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x20, 0x00,
134         0x00, 0x00, 0x2a, 0x02, 0x00, 0x00, 0x05, 0x1a, 0x38, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x00,
135         0x00, 0x00, 0x6d, 0x9e, 0xc6, 0xb7, 0xc7, 0x2c, 0xd2, 0x11, 0x85, 0x4e, 0x00, 0xa0, 0xc9, 0x83,
136         0xf6, 0x08, 0x86, 0x7a, 0x96, 0xbf, 0xe6, 0x0d, 0xd0, 0x11, 0xa2, 0x85, 0x00, 0xaa, 0x00, 0x30,
137         0x49, 0xe2, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x09, 0x00, 0x00, 0x00, 0x05, 0x1a,
138         0x38, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x6d, 0x9e, 0xc6, 0xb7, 0xc7, 0x2c,
139         0xd2, 0x11, 0x85, 0x4e, 0x00, 0xa0, 0xc9, 0x83, 0xf6, 0x08, 0x9c, 0x7a, 0x96, 0xbf, 0xe6, 0x0d,
140         0xd0, 0x11, 0xa2, 0x85, 0x00, 0xaa, 0x00, 0x30, 0x49, 0xe2, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
141         0x00, 0x05, 0x09, 0x00, 0x00, 0x00, 0x05, 0x1a, 0x38, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x00,
142         0x00, 0x00, 0x6d, 0x9e, 0xc6, 0xb7, 0xc7, 0x2c, 0xd2, 0x11, 0x85, 0x4e, 0x00, 0xa0, 0xc9, 0x83,
143         0xf6, 0x08, 0xba, 0x7a, 0x96, 0xbf, 0xe6, 0x0d, 0xd0, 0x11, 0xa2, 0x85, 0x00, 0xaa, 0x00, 0x30,
144         0x49, 0xe2, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x09, 0x00, 0x00, 0x00, 0x05, 0x1a,
145         0x2c, 0x00, 0x94, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x14, 0xcc, 0x28, 0x48, 0x37, 0x14,
146         0xbc, 0x45, 0x9b, 0x07, 0xad, 0x6f, 0x01, 0x5e, 0x5f, 0x28, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00,
147         0x00, 0x05, 0x20, 0x00, 0x00, 0x00, 0x2a, 0x02, 0x00, 0x00, 0x05, 0x1a, 0x2c, 0x00, 0x94, 0x00,
148         0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x9c, 0x7a, 0x96, 0xbf, 0xe6, 0x0d, 0xd0, 0x11, 0xa2, 0x85,
149         0x00, 0xaa, 0x00, 0x30, 0x49, 0xe2, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x20, 0x00,
150         0x00, 0x00, 0x2a, 0x02, 0x00, 0x00, 0x05, 0x1a, 0x2c, 0x00, 0x94, 0x00, 0x02, 0x00, 0x02, 0x00,
151         0x00, 0x00, 0xba, 0x7a, 0x96, 0xbf, 0xe6, 0x0d, 0xd0, 0x11, 0xa2, 0x85, 0x00, 0xaa, 0x00, 0x30,
152         0x49, 0xe2, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x20, 0x00, 0x00, 0x00, 0x2a, 0x02,
153         0x00, 0x00, 0x05, 0x12, 0x28, 0x00, 0x30, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xde, 0x47,
154         0xe6, 0x91, 0x6f, 0xd9, 0x70, 0x4b, 0x95, 0x57, 0xd6, 0x3f, 0xf4, 0xf3, 0xcc, 0xd8, 0x01, 0x01,
155         0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x12, 0x24, 0x00, 0xff, 0x01,
156         0x0f, 0x00, 0x01, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x15, 0x00, 0x00, 0x00, 0x9a, 0xbd,
157         0x91, 0x7d, 0xd5, 0xe0, 0x11, 0x3c, 0x6e, 0x5e, 0x1a, 0x4b, 0x07, 0x02, 0x00, 0x00, 0x00, 0x12,
158         0x18, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x20, 0x00,
159         0x00, 0x00, 0x2a, 0x02, 0x00, 0x00, 0x00, 0x12, 0x18, 0x00, 0xbd, 0x01, 0x0f, 0x00, 0x01, 0x02,
160         0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x20, 0x00, 0x00, 0x00, 0x20, 0x02, 0x00, 0x00, 0x00, 0x6e,
161         0x61, 0x6d, 0x65, 0x00, 0x01, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x64, 0x64, 0x61, 0x31,
162         0x64, 0x30, 0x31, 0x64, 0x2d, 0x34, 0x62, 0x64, 0x37, 0x2d, 0x34, 0x63, 0x34, 0x39, 0x2d, 0x61,
163         0x31, 0x38, 0x34, 0x2d, 0x34, 0x36, 0x66, 0x39, 0x32, 0x34, 0x31, 0x62, 0x35, 0x36, 0x30, 0x65,
164         0x00, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x47, 0x55, 0x49, 0x44, 0x00, 0x01, 0x00, 0x00, 0x00,
165         0x10, 0x00, 0x00, 0x00, 0x57, 0x93, 0x1e, 0x29, 0x25, 0x49, 0xe5, 0x40, 0x9d, 0x98, 0x36, 0x07,
166         0x11, 0x9e, 0xbd, 0xe5, 0x00, 0x72, 0x65, 0x70, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74,
167         0x79, 0x4d, 0x65, 0x74, 0x61, 0x44, 0x61, 0x74, 0x61, 0x00, 0x01, 0x00, 0x00, 0x00, 0x90, 0x01,
168         0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
169         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x7e, 0x38, 0xae, 0x0b, 0x03, 0x00,
170         0x00, 0x00, 0x9d, 0xcd, 0xcd, 0x57, 0xee, 0x58, 0x6e, 0x4e, 0x96, 0x99, 0xcc, 0x7d, 0xe1, 0x96,
171         0xf1, 0x05, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00,
172         0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x7e, 0x38, 0xae, 0x0b, 0x03, 0x00,
173         0x00, 0x00, 0x9d, 0xcd, 0xcd, 0x57, 0xee, 0x58, 0x6e, 0x4e, 0x96, 0x99, 0xcc, 0x7d, 0xe1, 0x96,
174         0xf1, 0x05, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00,
175         0x00, 0x00, 0x02, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x7e, 0x38, 0xae, 0x0b, 0x03, 0x00,
176         0x00, 0x00, 0x9d, 0xcd, 0xcd, 0x57, 0xee, 0x58, 0x6e, 0x4e, 0x96, 0x99, 0xcc, 0x7d, 0xe1, 0x96,
177         0xf1, 0x05, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00,
178         0x00, 0x00, 0xa9, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x7e, 0x38, 0xae, 0x0b, 0x03, 0x00,
179         0x00, 0x00, 0x9d, 0xcd, 0xcd, 0x57, 0xee, 0x58, 0x6e, 0x4e, 0x96, 0x99, 0xcc, 0x7d, 0xe1, 0x96,
180         0xf1, 0x05, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00,
181         0x00, 0x00, 0x19, 0x01, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x7e, 0x38, 0xae, 0x0b, 0x03, 0x00,
182         0x00, 0x00, 0x9d, 0xcd, 0xcd, 0x57, 0xee, 0x58, 0x6e, 0x4e, 0x96, 0x99, 0xcc, 0x7d, 0xe1, 0x96,
183         0xf1, 0x05, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00,
184         0x00, 0x00, 0x01, 0x00, 0x09, 0x00, 0x01, 0x00, 0x00, 0x00, 0x7e, 0x38, 0xae, 0x0b, 0x03, 0x00,
185         0x00, 0x00, 0x9d, 0xcd, 0xcd, 0x57, 0xee, 0x58, 0x6e, 0x4e, 0x96, 0x99, 0xcc, 0x7d, 0xe1, 0x96,
186         0xf1, 0x05, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00,
187         0x00, 0x00, 0x0e, 0x03, 0x09, 0x00, 0x01, 0x00, 0x00, 0x00, 0x7e, 0x38, 0xae, 0x0b, 0x03, 0x00,
188         0x00, 0x00, 0x9d, 0xcd, 0xcd, 0x57, 0xee, 0x58, 0x6e, 0x4e, 0x96, 0x99, 0xcc, 0x7d, 0xe1, 0x96,
189         0xf1, 0x05, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00,
190         0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x7e, 0x38, 0xae, 0x0b, 0x03, 0x00,
191         0x00, 0x00, 0x9d, 0xcd, 0xcd, 0x57, 0xee, 0x58, 0x6e, 0x4e, 0x96, 0x99, 0xcc, 0x7d, 0xe1, 0x96,
192         0xf1, 0x05, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00,
193         0x00, 0x00, 0x00, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72,
194         0x79, 0x00, 0x01, 0x00, 0x00, 0x00, 0x76, 0x00, 0x00, 0x00, 0x3c, 0x47, 0x55, 0x49, 0x44, 0x3d,
195         0x35, 0x32, 0x34, 0x32, 0x39, 0x30, 0x33, 0x38, 0x2d, 0x65, 0x34, 0x33, 0x35, 0x2d, 0x34, 0x66,
196         0x65, 0x33, 0x2d, 0x39, 0x36, 0x34, 0x65, 0x2d, 0x38, 0x30, 0x64, 0x61, 0x31, 0x35, 0x34, 0x39,
197         0x39, 0x63, 0x39, 0x63, 0x3e, 0x3b, 0x43, 0x4e, 0x3d, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e,
198         0x65, 0x72, 0x2c, 0x43, 0x4e, 0x3d, 0x53, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x2c, 0x43, 0x4e, 0x3d,
199         0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2c, 0x44, 0x43,
200         0x3d, 0x61, 0x64, 0x64, 0x63, 0x2c, 0x44, 0x43, 0x3d, 0x73, 0x61, 0x6d, 0x62, 0x61, 0x2c, 0x44,
201         0x43, 0x3d, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2c, 0x44, 0x43, 0x3d, 0x63, 0x6f, 0x6d,
202         0x00
203 };
204
205 static const uint8_t dda1d01d_bin_v2[] = {
206         0x68, 0x19, 0x01, 0x26, 0x0d, 0x00, 0x00, 0x00, 0x73, 0x00, 0x00, 0x00, 0x43, 0x4e, 0x3d, 0x64,
207         0x64, 0x61, 0x31, 0x64, 0x30, 0x31, 0x64, 0x2d, 0x34, 0x62, 0x64, 0x37, 0x2d, 0x34, 0x63, 0x34,
208         0x39, 0x2d, 0x61, 0x31, 0x38, 0x34, 0x2d, 0x34, 0x36, 0x66, 0x39, 0x32, 0x34, 0x31, 0x62, 0x35,
209         0x36, 0x30, 0x65, 0x2c, 0x43, 0x4e, 0x3d, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e,
210         0x73, 0x2c, 0x43, 0x4e, 0x3d, 0x44, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x55, 0x70, 0x64, 0x61, 0x74,
211         0x65, 0x73, 0x2c, 0x43, 0x4e, 0x3d, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2c, 0x44, 0x43, 0x3d,
212         0x61, 0x64, 0x64, 0x63, 0x2c, 0x44, 0x43, 0x3d, 0x73, 0x61, 0x6d, 0x62, 0x61, 0x2c, 0x44, 0x43,
213         0x3d, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2c, 0x44, 0x43, 0x3d, 0x63, 0x6f, 0x6d, 0x00,
214         0x5b, 0x00, 0x00, 0x00, 0x61, 0x64, 0x64, 0x63, 0x2e, 0x73, 0x61, 0x6d, 0x62, 0x61, 0x2e, 0x65,
215         0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x53, 0x79, 0x73, 0x74, 0x65,
216         0x6d, 0x2f, 0x44, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x73, 0x2f,
217         0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2f, 0x64, 0x64, 0x61, 0x31, 0x64,
218         0x30, 0x31, 0x64, 0x2d, 0x34, 0x62, 0x64, 0x37, 0x2d, 0x34, 0x63, 0x34, 0x39, 0x2d, 0x61, 0x31,
219         0x38, 0x34, 0x2d, 0x34, 0x36, 0x66, 0x39, 0x32, 0x34, 0x31, 0x62, 0x35, 0x36, 0x30, 0x65, 0x00,
220         0x33, 0x01, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x43, 0x6c,
221         0x61, 0x73, 0x73, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x03, 0x09, 0x02, 0x00, 0x00, 0x00, 0x63,
222         0x6e, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x24, 0x0c, 0x00, 0x00, 0x00, 0x69, 0x6e, 0x73, 0x74,
223         0x61, 0x6e, 0x63, 0x65, 0x54, 0x79, 0x70, 0x65, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x0b,
224         0x00, 0x00, 0x00, 0x77, 0x68, 0x65, 0x6e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x00, 0x01,
225         0x00, 0x00, 0x00, 0x01, 0x11, 0x0b, 0x00, 0x00, 0x00, 0x77, 0x68, 0x65, 0x6e, 0x43, 0x68, 0x61,
226         0x6e, 0x67, 0x65, 0x64, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x11, 0x0a, 0x00, 0x00, 0x00, 0x75,
227         0x53, 0x4e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x04,
228         0x0a, 0x00, 0x00, 0x00, 0x75, 0x53, 0x4e, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x64, 0x00, 0x01,
229         0x00, 0x00, 0x00, 0x01, 0x04, 0x16, 0x00, 0x00, 0x00, 0x73, 0x68, 0x6f, 0x77, 0x49, 0x6e, 0x41,
230         0x64, 0x76, 0x61, 0x6e, 0x63, 0x65, 0x64, 0x56, 0x69, 0x65, 0x77, 0x4f, 0x6e, 0x6c, 0x79, 0x00,
231         0x01, 0x00, 0x00, 0x00, 0x01, 0x04, 0x14, 0x00, 0x00, 0x00, 0x6e, 0x54, 0x53, 0x65, 0x63, 0x75,
232         0x72, 0x69, 0x74, 0x79, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0x00, 0x01,
233         0x00, 0x00, 0x00, 0x02, 0x18, 0x05, 0x04, 0x00, 0x00, 0x00, 0x6e, 0x61, 0x6d, 0x65, 0x00, 0x01,
234         0x00, 0x00, 0x00, 0x01, 0x24, 0x0a, 0x00, 0x00, 0x00, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x47,
235         0x55, 0x49, 0x44, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x10, 0x14, 0x00, 0x00, 0x00, 0x72, 0x65,
236         0x70, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x4d, 0x65, 0x74, 0x61, 0x44, 0x61,
237         0x74, 0x61, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x90, 0x01, 0x0e, 0x00, 0x00, 0x00, 0x6f, 0x62,
238         0x6a, 0x65, 0x63, 0x74, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x00, 0x01, 0x00, 0x00,
239         0x00, 0x01, 0x76, 0x74, 0x6f, 0x70, 0x00, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72,
240         0x00, 0x64, 0x64, 0x61, 0x31, 0x64, 0x30, 0x31, 0x64, 0x2d, 0x34, 0x62, 0x64, 0x37, 0x2d, 0x34,
241         0x63, 0x34, 0x39, 0x2d, 0x61, 0x31, 0x38, 0x34, 0x2d, 0x34, 0x36, 0x66, 0x39, 0x32, 0x34, 0x31,
242         0x62, 0x35, 0x36, 0x30, 0x65, 0x00, 0x34, 0x00, 0x32, 0x30, 0x31, 0x35, 0x30, 0x37, 0x30, 0x38,
243         0x32, 0x32, 0x34, 0x33, 0x31, 0x30, 0x2e, 0x30, 0x5a, 0x00, 0x32, 0x30, 0x31, 0x35, 0x30, 0x37,
244         0x30, 0x38, 0x32, 0x32, 0x34, 0x33, 0x31, 0x30, 0x2e, 0x30, 0x5a, 0x00, 0x33, 0x34, 0x36, 0x37,
245         0x00, 0x33, 0x34, 0x36, 0x37, 0x00, 0x54, 0x52, 0x55, 0x45, 0x00, 0x01, 0x00, 0x14, 0x8c, 0x14,
246         0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x4c, 0x00, 0x00, 0x00, 0xc4, 0x00, 0x00, 0x00, 0x01,
247         0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x15, 0x00, 0x00, 0x00, 0x9a, 0xbd, 0x91, 0x7d, 0xd5,
248         0xe0, 0x11, 0x3c, 0x6e, 0x5e, 0x1a, 0x4b, 0x00, 0x02, 0x00, 0x00, 0x01, 0x05, 0x00, 0x00, 0x00,
249         0x00, 0x00, 0x05, 0x15, 0x00, 0x00, 0x00, 0x9a, 0xbd, 0x91, 0x7d, 0xd5, 0xe0, 0x11, 0x3c, 0x6e,
250         0x5e, 0x1a, 0x4b, 0x00, 0x02, 0x00, 0x00, 0x04, 0x00, 0x78, 0x00, 0x02, 0x00, 0x00, 0x00, 0x07,
251         0x5a, 0x38, 0x00, 0x20, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xbe, 0x3b, 0x0e, 0xf3, 0xf0,
252         0x9f, 0xd1, 0x11, 0xb6, 0x03, 0x00, 0x00, 0xf8, 0x03, 0x67, 0xc1, 0xa5, 0x7a, 0x96, 0xbf, 0xe6,
253         0x0d, 0xd0, 0x11, 0xa2, 0x85, 0x00, 0xaa, 0x00, 0x30, 0x49, 0xe2, 0x01, 0x01, 0x00, 0x00, 0x00,
254         0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x07, 0x5a, 0x38, 0x00, 0x20, 0x00, 0x00, 0x00, 0x03,
255         0x00, 0x00, 0x00, 0xbf, 0x3b, 0x0e, 0xf3, 0xf0, 0x9f, 0xd1, 0x11, 0xb6, 0x03, 0x00, 0x00, 0xf8,
256         0x03, 0x67, 0xc1, 0xa5, 0x7a, 0x96, 0xbf, 0xe6, 0x0d, 0xd0, 0x11, 0xa2, 0x85, 0x00, 0xaa, 0x00,
257         0x30, 0x49, 0xe2, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x04,
258         0x00, 0x54, 0x04, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x00, 0xff, 0x01, 0x0f, 0x00, 0x01,
259         0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x15, 0x00, 0x00, 0x00, 0x9a, 0xbd, 0x91, 0x7d, 0xd5,
260         0xe0, 0x11, 0x3c, 0x6e, 0x5e, 0x1a, 0x4b, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0xff,
261         0x01, 0x0f, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x12, 0x00, 0x00, 0x00, 0x00,
262         0x00, 0x14, 0x00, 0x94, 0x00, 0x02, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x0b,
263         0x00, 0x00, 0x00, 0x05, 0x1a, 0x3c, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
264         0x42, 0x16, 0x4c, 0xc0, 0x20, 0xd0, 0x11, 0xa7, 0x68, 0x00, 0xaa, 0x00, 0x6e, 0x05, 0x29, 0x14,
265         0xcc, 0x28, 0x48, 0x37, 0x14, 0xbc, 0x45, 0x9b, 0x07, 0xad, 0x6f, 0x01, 0x5e, 0x5f, 0x28, 0x01,
266         0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x20, 0x00, 0x00, 0x00, 0x2a, 0x02, 0x00, 0x00, 0x05,
267         0x1a, 0x3c, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x42, 0x16, 0x4c, 0xc0,
268         0x20, 0xd0, 0x11, 0xa7, 0x68, 0x00, 0xaa, 0x00, 0x6e, 0x05, 0x29, 0xba, 0x7a, 0x96, 0xbf, 0xe6,
269         0x0d, 0xd0, 0x11, 0xa2, 0x85, 0x00, 0xaa, 0x00, 0x30, 0x49, 0xe2, 0x01, 0x02, 0x00, 0x00, 0x00,
270         0x00, 0x00, 0x05, 0x20, 0x00, 0x00, 0x00, 0x2a, 0x02, 0x00, 0x00, 0x05, 0x1a, 0x3c, 0x00, 0x10,
271         0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, 0x20, 0x20, 0x5f, 0xa5, 0x79, 0xd0, 0x11, 0x90,
272         0x20, 0x00, 0xc0, 0x4f, 0xc2, 0xd4, 0xcf, 0x14, 0xcc, 0x28, 0x48, 0x37, 0x14, 0xbc, 0x45, 0x9b,
273         0x07, 0xad, 0x6f, 0x01, 0x5e, 0x5f, 0x28, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x20,
274         0x00, 0x00, 0x00, 0x2a, 0x02, 0x00, 0x00, 0x05, 0x1a, 0x3c, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03,
275         0x00, 0x00, 0x00, 0x10, 0x20, 0x20, 0x5f, 0xa5, 0x79, 0xd0, 0x11, 0x90, 0x20, 0x00, 0xc0, 0x4f,
276         0xc2, 0xd4, 0xcf, 0xba, 0x7a, 0x96, 0xbf, 0xe6, 0x0d, 0xd0, 0x11, 0xa2, 0x85, 0x00, 0xaa, 0x00,
277         0x30, 0x49, 0xe2, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x20, 0x00, 0x00, 0x00, 0x2a,
278         0x02, 0x00, 0x00, 0x05, 0x1a, 0x3c, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x40,
279         0xc2, 0x0a, 0xbc, 0xa9, 0x79, 0xd0, 0x11, 0x90, 0x20, 0x00, 0xc0, 0x4f, 0xc2, 0xd4, 0xcf, 0x14,
280         0xcc, 0x28, 0x48, 0x37, 0x14, 0xbc, 0x45, 0x9b, 0x07, 0xad, 0x6f, 0x01, 0x5e, 0x5f, 0x28, 0x01,
281         0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x20, 0x00, 0x00, 0x00, 0x2a, 0x02, 0x00, 0x00, 0x05,
282         0x1a, 0x3c, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x40, 0xc2, 0x0a, 0xbc, 0xa9,
283         0x79, 0xd0, 0x11, 0x90, 0x20, 0x00, 0xc0, 0x4f, 0xc2, 0xd4, 0xcf, 0xba, 0x7a, 0x96, 0xbf, 0xe6,
284         0x0d, 0xd0, 0x11, 0xa2, 0x85, 0x00, 0xaa, 0x00, 0x30, 0x49, 0xe2, 0x01, 0x02, 0x00, 0x00, 0x00,
285         0x00, 0x00, 0x05, 0x20, 0x00, 0x00, 0x00, 0x2a, 0x02, 0x00, 0x00, 0x05, 0x1a, 0x3c, 0x00, 0x10,
286         0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x42, 0x2f, 0xba, 0x59, 0xa2, 0x79, 0xd0, 0x11, 0x90,
287         0x20, 0x00, 0xc0, 0x4f, 0xc2, 0xd3, 0xcf, 0x14, 0xcc, 0x28, 0x48, 0x37, 0x14, 0xbc, 0x45, 0x9b,
288         0x07, 0xad, 0x6f, 0x01, 0x5e, 0x5f, 0x28, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x20,
289         0x00, 0x00, 0x00, 0x2a, 0x02, 0x00, 0x00, 0x05, 0x1a, 0x3c, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03,
290         0x00, 0x00, 0x00, 0x42, 0x2f, 0xba, 0x59, 0xa2, 0x79, 0xd0, 0x11, 0x90, 0x20, 0x00, 0xc0, 0x4f,
291         0xc2, 0xd3, 0xcf, 0xba, 0x7a, 0x96, 0xbf, 0xe6, 0x0d, 0xd0, 0x11, 0xa2, 0x85, 0x00, 0xaa, 0x00,
292         0x30, 0x49, 0xe2, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x20, 0x00, 0x00, 0x00, 0x2a,
293         0x02, 0x00, 0x00, 0x05, 0x1a, 0x3c, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xf8,
294         0x88, 0x70, 0x03, 0xe1, 0x0a, 0xd2, 0x11, 0xb4, 0x22, 0x00, 0xa0, 0xc9, 0x68, 0xf9, 0x39, 0x14,
295         0xcc, 0x28, 0x48, 0x37, 0x14, 0xbc, 0x45, 0x9b, 0x07, 0xad, 0x6f, 0x01, 0x5e, 0x5f, 0x28, 0x01,
296         0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x20, 0x00, 0x00, 0x00, 0x2a, 0x02, 0x00, 0x00, 0x05,
297         0x1a, 0x3c, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xf8, 0x88, 0x70, 0x03, 0xe1,
298         0x0a, 0xd2, 0x11, 0xb4, 0x22, 0x00, 0xa0, 0xc9, 0x68, 0xf9, 0x39, 0xba, 0x7a, 0x96, 0xbf, 0xe6,
299         0x0d, 0xd0, 0x11, 0xa2, 0x85, 0x00, 0xaa, 0x00, 0x30, 0x49, 0xe2, 0x01, 0x02, 0x00, 0x00, 0x00,
300         0x00, 0x00, 0x05, 0x20, 0x00, 0x00, 0x00, 0x2a, 0x02, 0x00, 0x00, 0x05, 0x1a, 0x38, 0x00, 0x10,
301         0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x6d, 0x9e, 0xc6, 0xb7, 0xc7, 0x2c, 0xd2, 0x11, 0x85,
302         0x4e, 0x00, 0xa0, 0xc9, 0x83, 0xf6, 0x08, 0x86, 0x7a, 0x96, 0xbf, 0xe6, 0x0d, 0xd0, 0x11, 0xa2,
303         0x85, 0x00, 0xaa, 0x00, 0x30, 0x49, 0xe2, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x09,
304         0x00, 0x00, 0x00, 0x05, 0x1a, 0x38, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x6d,
305         0x9e, 0xc6, 0xb7, 0xc7, 0x2c, 0xd2, 0x11, 0x85, 0x4e, 0x00, 0xa0, 0xc9, 0x83, 0xf6, 0x08, 0x9c,
306         0x7a, 0x96, 0xbf, 0xe6, 0x0d, 0xd0, 0x11, 0xa2, 0x85, 0x00, 0xaa, 0x00, 0x30, 0x49, 0xe2, 0x01,
307         0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x09, 0x00, 0x00, 0x00, 0x05, 0x1a, 0x38, 0x00, 0x10,
308         0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x6d, 0x9e, 0xc6, 0xb7, 0xc7, 0x2c, 0xd2, 0x11, 0x85,
309         0x4e, 0x00, 0xa0, 0xc9, 0x83, 0xf6, 0x08, 0xba, 0x7a, 0x96, 0xbf, 0xe6, 0x0d, 0xd0, 0x11, 0xa2,
310         0x85, 0x00, 0xaa, 0x00, 0x30, 0x49, 0xe2, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x09,
311         0x00, 0x00, 0x00, 0x05, 0x1a, 0x2c, 0x00, 0x94, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x14,
312         0xcc, 0x28, 0x48, 0x37, 0x14, 0xbc, 0x45, 0x9b, 0x07, 0xad, 0x6f, 0x01, 0x5e, 0x5f, 0x28, 0x01,
313         0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x20, 0x00, 0x00, 0x00, 0x2a, 0x02, 0x00, 0x00, 0x05,
314         0x1a, 0x2c, 0x00, 0x94, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x9c, 0x7a, 0x96, 0xbf, 0xe6,
315         0x0d, 0xd0, 0x11, 0xa2, 0x85, 0x00, 0xaa, 0x00, 0x30, 0x49, 0xe2, 0x01, 0x02, 0x00, 0x00, 0x00,
316         0x00, 0x00, 0x05, 0x20, 0x00, 0x00, 0x00, 0x2a, 0x02, 0x00, 0x00, 0x05, 0x1a, 0x2c, 0x00, 0x94,
317         0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0xba, 0x7a, 0x96, 0xbf, 0xe6, 0x0d, 0xd0, 0x11, 0xa2,
318         0x85, 0x00, 0xaa, 0x00, 0x30, 0x49, 0xe2, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x20,
319         0x00, 0x00, 0x00, 0x2a, 0x02, 0x00, 0x00, 0x05, 0x12, 0x28, 0x00, 0x30, 0x01, 0x00, 0x00, 0x01,
320         0x00, 0x00, 0x00, 0xde, 0x47, 0xe6, 0x91, 0x6f, 0xd9, 0x70, 0x4b, 0x95, 0x57, 0xd6, 0x3f, 0xf4,
321         0xf3, 0xcc, 0xd8, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x0a, 0x00, 0x00, 0x00, 0x00,
322         0x12, 0x24, 0x00, 0xff, 0x01, 0x0f, 0x00, 0x01, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x15,
323         0x00, 0x00, 0x00, 0x9a, 0xbd, 0x91, 0x7d, 0xd5, 0xe0, 0x11, 0x3c, 0x6e, 0x5e, 0x1a, 0x4b, 0x07,
324         0x02, 0x00, 0x00, 0x00, 0x12, 0x18, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 0x00,
325         0x00, 0x00, 0x05, 0x20, 0x00, 0x00, 0x00, 0x2a, 0x02, 0x00, 0x00, 0x00, 0x12, 0x18, 0x00, 0xbd,
326         0x01, 0x0f, 0x00, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x20, 0x00, 0x00, 0x00, 0x20,
327         0x02, 0x00, 0x00, 0x00, 0x64, 0x64, 0x61, 0x31, 0x64, 0x30, 0x31, 0x64, 0x2d, 0x34, 0x62, 0x64,
328         0x37, 0x2d, 0x34, 0x63, 0x34, 0x39, 0x2d, 0x61, 0x31, 0x38, 0x34, 0x2d, 0x34, 0x36, 0x66, 0x39,
329         0x32, 0x34, 0x31, 0x62, 0x35, 0x36, 0x30, 0x65, 0x00, 0x57, 0x93, 0x1e, 0x29, 0x25, 0x49, 0xe5,
330         0x40, 0x9d, 0x98, 0x36, 0x07, 0x11, 0x9e, 0xbd, 0xe5, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
331         0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
332         0x00, 0x00, 0x7e, 0x38, 0xae, 0x0b, 0x03, 0x00, 0x00, 0x00, 0x9d, 0xcd, 0xcd, 0x57, 0xee, 0x58,
333         0x6e, 0x4e, 0x96, 0x99, 0xcc, 0x7d, 0xe1, 0x96, 0xf1, 0x05, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00,
334         0x00, 0x00, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
335         0x00, 0x00, 0x7e, 0x38, 0xae, 0x0b, 0x03, 0x00, 0x00, 0x00, 0x9d, 0xcd, 0xcd, 0x57, 0xee, 0x58,
336         0x6e, 0x4e, 0x96, 0x99, 0xcc, 0x7d, 0xe1, 0x96, 0xf1, 0x05, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00,
337         0x00, 0x00, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02, 0x00, 0x01, 0x00,
338         0x00, 0x00, 0x7e, 0x38, 0xae, 0x0b, 0x03, 0x00, 0x00, 0x00, 0x9d, 0xcd, 0xcd, 0x57, 0xee, 0x58,
339         0x6e, 0x4e, 0x96, 0x99, 0xcc, 0x7d, 0xe1, 0x96, 0xf1, 0x05, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00,
340         0x00, 0x00, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa9, 0x00, 0x02, 0x00, 0x01, 0x00,
341         0x00, 0x00, 0x7e, 0x38, 0xae, 0x0b, 0x03, 0x00, 0x00, 0x00, 0x9d, 0xcd, 0xcd, 0x57, 0xee, 0x58,
342         0x6e, 0x4e, 0x96, 0x99, 0xcc, 0x7d, 0xe1, 0x96, 0xf1, 0x05, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00,
343         0x00, 0x00, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0x01, 0x02, 0x00, 0x01, 0x00,
344         0x00, 0x00, 0x7e, 0x38, 0xae, 0x0b, 0x03, 0x00, 0x00, 0x00, 0x9d, 0xcd, 0xcd, 0x57, 0xee, 0x58,
345         0x6e, 0x4e, 0x96, 0x99, 0xcc, 0x7d, 0xe1, 0x96, 0xf1, 0x05, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00,
346         0x00, 0x00, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x09, 0x00, 0x01, 0x00,
347         0x00, 0x00, 0x7e, 0x38, 0xae, 0x0b, 0x03, 0x00, 0x00, 0x00, 0x9d, 0xcd, 0xcd, 0x57, 0xee, 0x58,
348         0x6e, 0x4e, 0x96, 0x99, 0xcc, 0x7d, 0xe1, 0x96, 0xf1, 0x05, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00,
349         0x00, 0x00, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x03, 0x09, 0x00, 0x01, 0x00,
350         0x00, 0x00, 0x7e, 0x38, 0xae, 0x0b, 0x03, 0x00, 0x00, 0x00, 0x9d, 0xcd, 0xcd, 0x57, 0xee, 0x58,
351         0x6e, 0x4e, 0x96, 0x99, 0xcc, 0x7d, 0xe1, 0x96, 0xf1, 0x05, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00,
352         0x00, 0x00, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00,
353         0x00, 0x00, 0x7e, 0x38, 0xae, 0x0b, 0x03, 0x00, 0x00, 0x00, 0x9d, 0xcd, 0xcd, 0x57, 0xee, 0x58,
354         0x6e, 0x4e, 0x96, 0x99, 0xcc, 0x7d, 0xe1, 0x96, 0xf1, 0x05, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00,
355         0x00, 0x00, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x47, 0x55, 0x49, 0x44,
356         0x3d, 0x35, 0x32, 0x34, 0x32, 0x39, 0x30, 0x33, 0x38, 0x2d, 0x65, 0x34, 0x33, 0x35, 0x2d, 0x34,
357         0x66, 0x65, 0x33, 0x2d, 0x39, 0x36, 0x34, 0x65, 0x2d, 0x38, 0x30, 0x64, 0x61, 0x31, 0x35, 0x34,
358         0x39, 0x39, 0x63, 0x39, 0x63, 0x3e, 0x3b, 0x43, 0x4e, 0x3d, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69,
359         0x6e, 0x65, 0x72, 0x2c, 0x43, 0x4e, 0x3d, 0x53, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x2c, 0x43, 0x4e,
360         0x3d, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2c, 0x44,
361         0x43, 0x3d, 0x61, 0x64, 0x64, 0x63, 0x2c, 0x44, 0x43, 0x3d, 0x73, 0x61, 0x6d, 0x62, 0x61, 0x2c,
362         0x44, 0x43, 0x3d, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2c, 0x44, 0x43, 0x3d, 0x63, 0x6f,
363         0x6d, 0x00
364 };
365
366 static const char dda1d01d_ldif[] = ""
367 "dn: CN=dda1d01d-4bd7-4c49-a184-46f9241b560e,CN=Operations,CN=DomainUpdates,CN=System,DC=addc,DC=samba,DC=example,DC=com\n"
368 "objectClass: top\n"
369 "objectClass: container\n"
370 "cn: dda1d01d-4bd7-4c49-a184-46f9241b560e\n"
371 "instanceType: 4\n"
372 "whenCreated: 20150708224310.0Z\n"
373 "whenChanged: 20150708224310.0Z\n"
374 "uSNCreated: 3467\n"
375 "uSNChanged: 3467\n"
376 "showInAdvancedViewOnly: TRUE\n"
377 "nTSecurityDescriptor: O:S-1-5-21-2106703258-1007804629-1260019310-512G:S-1-5-2\n"
378 " 1-2106703258-1007804629-1260019310-512D:AI(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;S-\n"
379 " 1-5-21-2106703258-1007804629-1260019310-512)(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;\n"
380 " SY)(A;;RPLCLORC;;;AU)(OA;CIIOID;RP;4c164200-20c0-11d0-a768-00aa006e0529;4828c\n"
381 " c14-1437-45bc-9b07-ad6f015e5f28;RU)(OA;CIIOID;RP;4c164200-20c0-11d0-a768-00aa\n"
382 " 006e0529;bf967aba-0de6-11d0-a285-00aa003049e2;RU)(OA;CIIOID;RP;5f202010-79a5-\n"
383 " 11d0-9020-00c04fc2d4cf;4828cc14-1437-45bc-9b07-ad6f015e5f28;RU)(OA;CIIOID;RP;\n"
384 " 5f202010-79a5-11d0-9020-00c04fc2d4cf;bf967aba-0de6-11d0-a285-00aa003049e2;RU)\n"
385 " (OA;CIIOID;RP;bc0ac240-79a9-11d0-9020-00c04fc2d4cf;4828cc14-1437-45bc-9b07-ad\n"
386 " 6f015e5f28;RU)(OA;CIIOID;RP;bc0ac240-79a9-11d0-9020-00c04fc2d4cf;bf967aba-0de\n"
387 " 6-11d0-a285-00aa003049e2;RU)(OA;CIIOID;RP;59ba2f42-79a2-11d0-9020-00c04fc2d3c\n"
388 " f;4828cc14-1437-45bc-9b07-ad6f015e5f28;RU)(OA;CIIOID;RP;59ba2f42-79a2-11d0-90\n"
389 " 20-00c04fc2d3cf;bf967aba-0de6-11d0-a285-00aa003049e2;RU)(OA;CIIOID;RP;037088f\n"
390 " 8-0ae1-11d2-b422-00a0c968f939;4828cc14-1437-45bc-9b07-ad6f015e5f28;RU)(OA;CII\n"
391 " OID;RP;037088f8-0ae1-11d2-b422-00a0c968f939;bf967aba-0de6-11d0-a285-00aa00304\n"
392 " 9e2;RU)(OA;CIIOID;RP;b7c69e6d-2cc7-11d2-854e-00a0c983f608;bf967a86-0de6-11d0-\n"
393 " a285-00aa003049e2;ED)(OA;CIIOID;RP;b7c69e6d-2cc7-11d2-854e-00a0c983f608;bf967\n"
394 " a9c-0de6-11d0-a285-00aa003049e2;ED)(OA;CIIOID;RP;b7c69e6d-2cc7-11d2-854e-00a0\n"
395 " c983f608;bf967aba-0de6-11d0-a285-00aa003049e2;ED)(OA;CIIOID;RPLCLORC;;4828cc1\n"
396 " 4-1437-45bc-9b07-ad6f015e5f28;RU)(OA;CIIOID;RPLCLORC;;bf967a9c-0de6-11d0-a285\n"
397 " -00aa003049e2;RU)(OA;CIIOID;RPLCLORC;;bf967aba-0de6-11d0-a285-00aa003049e2;RU\n"
398 " )(OA;CIID;RPWPCR;91e647de-d96f-4b70-9557-d63ff4f3ccd8;;PS)(A;CIID;RPWPCRCCDCL\n"
399 " CLORCWOWDSDDTSW;;;S-1-5-21-2106703258-1007804629-1260019310-519)(A;CIID;LC;;;\n"
400 " RU)(A;CIID;RPWPCRCCLCLORCWOWDSDSW;;;BA)S:AI(OU;CIIOIDSA;WP;f30e3bbe-9ff0-11d1\n"
401 " -b603-0000f80367c1;bf967aa5-0de6-11d0-a285-00aa003049e2;WD)(OU;CIIOIDSA;WP;f3\n"
402 " 0e3bbf-9ff0-11d1-b603-0000f80367c1;bf967aa5-0de6-11d0-a285-00aa003049e2;WD)\n"
403 "name: dda1d01d-4bd7-4c49-a184-46f9241b560e\n"
404 "objectGUID: 291e9357-4925-40e5-9d98-3607119ebde5\n"
405 "replPropertyMetaData:: AQAAAAAAAAAIAAAAAAAAAAAAAAABAAAAfjiuCwMAAACdzc1X7lhuTpa\n"
406 " ZzH3hlvEFiw0AAAAAAACLDQAAAAAAAAEAAgABAAAAfjiuCwMAAACdzc1X7lhuTpaZzH3hlvEFiw0A\n"
407 " AAAAAACLDQAAAAAAAAIAAgABAAAAfjiuCwMAAACdzc1X7lhuTpaZzH3hlvEFiw0AAAAAAACLDQAAA\n"
408 " AAAAKkAAgABAAAAfjiuCwMAAACdzc1X7lhuTpaZzH3hlvEFiw0AAAAAAACLDQAAAAAAABkBAgABAA\n"
409 " AAfjiuCwMAAACdzc1X7lhuTpaZzH3hlvEFiw0AAAAAAACLDQAAAAAAAAEACQABAAAAfjiuCwMAAAC\n"
410 " dzc1X7lhuTpaZzH3hlvEFiw0AAAAAAACLDQAAAAAAAA4DCQABAAAAfjiuCwMAAACdzc1X7lhuTpaZ\n"
411 " zH3hlvEFiw0AAAAAAACLDQAAAAAAAAMAAAABAAAAfjiuCwMAAACdzc1X7lhuTpaZzH3hlvEFiw0AA\n"
412 " AAAAACLDQAAAAAAAA==\n"
413 "objectCategory: <GUID=52429038-e435-4fe3-964e-80da15499c9c>;CN=Container,CN=Sc\n"
414 " hema,CN=Configuration,DC=addc,DC=samba,DC=example,DC=com\n\n";
415
416 static const char *dda1d01d_ldif_reduced = ""
417 "dn: CN=dda1d01d-4bd7-4c49-a184-46f9241b560e,CN=Operations,CN=DomainUpdates,CN=System,DC=addc,DC=samba,DC=example,DC=com\n"
418 "objectClass: top\n"
419 "objectClass: container\n"
420 "instanceType: 4\n"
421 "whenChanged: 20150708224310.0Z\n"
422 "uSNCreated: 3467\n"
423 "showInAdvancedViewOnly: TRUE\n"
424 "name: dda1d01d-4bd7-4c49-a184-46f9241b560e\n\n";
425
426 static bool torture_ldb_attrs(struct torture_context *torture)
427 {
428         TALLOC_CTX *mem_ctx = talloc_new(torture);
429         struct ldb_context *ldb;
430         const struct ldb_schema_attribute *attr;
431         struct ldb_val string_sid_blob, binary_sid_blob;
432         struct ldb_val string_guid_blob, string_guid_blob2, binary_guid_blob;
433         struct ldb_val string_prefix_map_newline_blob, string_prefix_map_semi_blob, string_prefix_map_blob;
434         struct ldb_val prefix_map_blob;
435
436         DATA_BLOB sid_blob = strhex_to_data_blob(mem_ctx, hex_sid);
437         DATA_BLOB guid_blob = strhex_to_data_blob(mem_ctx, hex_guid);
438
439         torture_assert(torture, 
440                        ldb = ldb_init(mem_ctx, torture->ev),
441                        "Failed to init ldb");
442
443         torture_assert_int_equal(torture, 
444                                  ldb_register_samba_handlers(ldb), LDB_SUCCESS,
445                                  "Failed to register Samba handlers");
446
447         ldb_set_utf8_fns(ldb, NULL, wrap_casefold);
448
449         /* Test SID behaviour */
450         torture_assert(torture, attr = ldb_schema_attribute_by_name(ldb, "objectSid"), 
451                        "Failed to get objectSid schema attribute");
452         
453         string_sid_blob = data_blob_string_const(sid);
454
455         torture_assert_int_equal(torture, 
456                                  attr->syntax->ldif_read_fn(ldb, mem_ctx, 
457                                                             &string_sid_blob, &binary_sid_blob), 0,
458                                  "Failed to parse string SID");
459         
460         torture_assert_data_blob_equal(torture, binary_sid_blob, sid_blob, 
461                                        "Read SID into blob form failed");
462         
463         torture_assert_int_equal(torture, 
464                                  attr->syntax->ldif_read_fn(ldb, mem_ctx, 
465                                                             &sid_blob, &binary_sid_blob), -1,
466                                  "Should have failed to parse binary SID");
467         
468         torture_assert_int_equal(torture, 
469                                  attr->syntax->ldif_write_fn(ldb, mem_ctx, &binary_sid_blob, &string_sid_blob), 0,
470                                  "Failed to parse binary SID");
471         
472         torture_assert_data_blob_equal(torture, 
473                                        string_sid_blob, data_blob_string_const(sid),
474                                        "Write SID into string form failed");
475         
476         torture_assert_int_equal(torture, 
477                                  attr->syntax->comparison_fn(ldb, mem_ctx, &binary_sid_blob, &string_sid_blob), 0,
478                                  "Failed to compare binary and string SID");
479         
480         torture_assert_int_equal(torture, 
481                                  attr->syntax->comparison_fn(ldb, mem_ctx, &string_sid_blob, &binary_sid_blob), 0,
482                                  "Failed to compare string and binary binary SID");
483         
484         torture_assert_int_equal(torture, 
485                                  attr->syntax->comparison_fn(ldb, mem_ctx, &string_sid_blob, &string_sid_blob), 0,
486                                  "Failed to compare string and string SID");
487         
488         torture_assert_int_equal(torture, 
489                                  attr->syntax->comparison_fn(ldb, mem_ctx, &binary_sid_blob, &binary_sid_blob), 0,
490                                  "Failed to compare binary and binary SID");
491         
492         torture_assert(torture, attr->syntax->comparison_fn(ldb, mem_ctx, &guid_blob, &binary_sid_blob) != 0,
493                        "Failed to distinguish binary GUID and binary SID");
494
495
496         /* Test GUID behaviour */
497         torture_assert(torture, attr = ldb_schema_attribute_by_name(ldb, "objectGUID"), 
498                        "Failed to get objectGUID schema attribute");
499         
500         string_guid_blob = data_blob_string_const(guid);
501
502         torture_assert_int_equal(torture, 
503                                  attr->syntax->ldif_read_fn(ldb, mem_ctx, 
504                                                             &string_guid_blob, &binary_guid_blob), 0,
505                                  "Failed to parse string GUID");
506         
507         torture_assert_data_blob_equal(torture, binary_guid_blob, guid_blob, 
508                                        "Read GUID into blob form failed");
509         
510         string_guid_blob2 = data_blob_string_const(guid2);
511         
512         torture_assert_int_equal(torture, 
513                                  attr->syntax->ldif_read_fn(ldb, mem_ctx, 
514                                                             &string_guid_blob2, &binary_guid_blob), 0,
515                                  "Failed to parse string GUID");
516         
517         torture_assert_data_blob_equal(torture, binary_guid_blob, guid_blob, 
518                                        "Read GUID into blob form failed");
519         
520         torture_assert_int_equal(torture, 
521                                  attr->syntax->ldif_read_fn(ldb, mem_ctx, 
522                                                             &guid_blob, &binary_guid_blob), 0,
523                                  "Failed to parse binary GUID");
524         
525         torture_assert_data_blob_equal(torture, binary_guid_blob, guid_blob, 
526                                        "Read GUID into blob form failed");
527         
528         torture_assert_int_equal(torture, 
529                                  attr->syntax->ldif_write_fn(ldb, mem_ctx, &binary_guid_blob, &string_guid_blob), 0,
530                                  "Failed to print binary GUID as string");
531
532         torture_assert_data_blob_equal(torture, string_sid_blob, data_blob_string_const(sid),
533                                        "Write SID into string form failed");
534         
535         torture_assert_int_equal(torture, 
536                                  attr->syntax->comparison_fn(ldb, mem_ctx, &binary_guid_blob, &string_guid_blob), 0,
537                                  "Failed to compare binary and string GUID");
538         
539         torture_assert_int_equal(torture, 
540                                  attr->syntax->comparison_fn(ldb, mem_ctx, &string_guid_blob, &binary_guid_blob), 0,
541                                  "Failed to compare string and binary binary GUID");
542         
543         torture_assert_int_equal(torture, 
544                                  attr->syntax->comparison_fn(ldb, mem_ctx, &string_guid_blob, &string_guid_blob), 0,
545                                  "Failed to compare string and string GUID");
546         
547         torture_assert_int_equal(torture, 
548                                  attr->syntax->comparison_fn(ldb, mem_ctx, &binary_guid_blob, &binary_guid_blob), 0,
549                                  "Failed to compare binary and binary GUID");
550         
551         string_prefix_map_newline_blob = data_blob_string_const(prefix_map_newline);
552         
553         string_prefix_map_semi_blob = data_blob_string_const(prefix_map_semi);
554         
555         /* Test prefixMap behaviour */
556         torture_assert(torture, attr = ldb_schema_attribute_by_name(ldb, "prefixMap"), 
557                        "Failed to get prefixMap schema attribute");
558         
559         torture_assert_int_equal(torture, 
560                                  attr->syntax->comparison_fn(ldb, mem_ctx, &string_prefix_map_newline_blob, &string_prefix_map_semi_blob), 0,
561                                  "Failed to compare prefixMap with newlines and prefixMap with semicolons");
562         
563         torture_assert_int_equal(torture, 
564                                  attr->syntax->ldif_read_fn(ldb, mem_ctx, &string_prefix_map_newline_blob, &prefix_map_blob), 0,
565                                  "Failed to read prefixMap with newlines");
566         torture_assert_int_equal(torture, 
567                                  attr->syntax->comparison_fn(ldb, mem_ctx, &string_prefix_map_newline_blob, &prefix_map_blob), 0,
568                                  "Failed to compare prefixMap with newlines and prefixMap binary");
569         
570         torture_assert_int_equal(torture, 
571                                  attr->syntax->ldif_write_fn(ldb, mem_ctx, &prefix_map_blob, &string_prefix_map_blob), 0,
572                                  "Failed to write prefixMap");
573         torture_assert_int_equal(torture, 
574                                  attr->syntax->comparison_fn(ldb, mem_ctx, &string_prefix_map_blob, &prefix_map_blob), 0,
575                                  "Failed to compare prefixMap ldif write and prefixMap binary");
576         
577         torture_assert_data_blob_equal(torture, string_prefix_map_blob, string_prefix_map_semi_blob,
578                 "Failed to compare prefixMap ldif write and prefixMap binary");
579         
580
581
582         talloc_free(mem_ctx);
583         return true;
584 }
585
586 static bool torture_ldb_dn_attrs(struct torture_context *torture)
587 {
588         TALLOC_CTX *mem_ctx = talloc_new(torture);
589         struct ldb_context *ldb;
590         const struct ldb_dn_extended_syntax *attr;
591         struct ldb_val string_sid_blob, binary_sid_blob;
592         struct ldb_val string_guid_blob, binary_guid_blob;
593         struct ldb_val hex_sid_blob, hex_guid_blob;
594
595         DATA_BLOB sid_blob = strhex_to_data_blob(mem_ctx, hex_sid);
596         DATA_BLOB guid_blob = strhex_to_data_blob(mem_ctx, hex_guid);
597
598         torture_assert(torture, 
599                        ldb = ldb_init(mem_ctx, torture->ev),
600                        "Failed to init ldb");
601
602         torture_assert_int_equal(torture, 
603                                  ldb_register_samba_handlers(ldb), LDB_SUCCESS,
604                                  "Failed to register Samba handlers");
605
606         ldb_set_utf8_fns(ldb, NULL, wrap_casefold);
607
608         /* Test SID behaviour */
609         torture_assert(torture, attr = ldb_dn_extended_syntax_by_name(ldb, "SID"), 
610                        "Failed to get SID DN syntax");
611         
612         string_sid_blob = data_blob_string_const(sid);
613
614         torture_assert_int_equal(torture, 
615                                  attr->read_fn(ldb, mem_ctx, 
616                                                &string_sid_blob, &binary_sid_blob), 0,
617                                  "Failed to parse string SID");
618         
619         torture_assert_data_blob_equal(torture, binary_sid_blob, sid_blob, 
620                                        "Read SID into blob form failed");
621
622         hex_sid_blob = data_blob_string_const(hex_sid);
623         
624         torture_assert_int_equal(torture, 
625                                  attr->read_fn(ldb, mem_ctx, 
626                                                &hex_sid_blob, &binary_sid_blob), 0,
627                                  "Failed to parse HEX SID");
628         
629         torture_assert_data_blob_equal(torture, binary_sid_blob, sid_blob, 
630                                        "Read SID into blob form failed");
631         
632         torture_assert_int_equal(torture, 
633                                  attr->read_fn(ldb, mem_ctx, 
634                                                &sid_blob, &binary_sid_blob), -1,
635                                  "Should have failed to parse binary SID");
636         
637         torture_assert_int_equal(torture, 
638                                  attr->write_hex_fn(ldb, mem_ctx, &sid_blob, &hex_sid_blob), 0,
639                                  "Failed to parse binary SID");
640         
641         torture_assert_data_blob_equal(torture, 
642                                        hex_sid_blob, data_blob_string_const(hex_sid),
643                                        "Write SID into HEX string form failed");
644         
645         torture_assert_int_equal(torture, 
646                                  attr->write_clear_fn(ldb, mem_ctx, &sid_blob, &string_sid_blob), 0,
647                                  "Failed to parse binary SID");
648         
649         torture_assert_data_blob_equal(torture, 
650                                        string_sid_blob, data_blob_string_const(sid),
651                                        "Write SID into clear string form failed");
652         
653
654         /* Test GUID behaviour */
655         torture_assert(torture, attr = ldb_dn_extended_syntax_by_name(ldb, "GUID"), 
656                        "Failed to get GUID DN syntax");
657         
658         string_guid_blob = data_blob_string_const(guid);
659
660         torture_assert_int_equal(torture, 
661                                  attr->read_fn(ldb, mem_ctx, 
662                                                &string_guid_blob, &binary_guid_blob), 0,
663                                  "Failed to parse string GUID");
664         
665         torture_assert_data_blob_equal(torture, binary_guid_blob, guid_blob, 
666                                        "Read GUID into blob form failed");
667         
668         hex_guid_blob = data_blob_string_const(hex_guid);
669         
670         torture_assert_int_equal(torture, 
671                                  attr->read_fn(ldb, mem_ctx, 
672                                                &hex_guid_blob, &binary_guid_blob), 0,
673                                  "Failed to parse HEX GUID");
674         
675         torture_assert_data_blob_equal(torture, binary_guid_blob, guid_blob, 
676                                        "Read GUID into blob form failed");
677         
678         torture_assert_int_equal(torture, 
679                                  attr->read_fn(ldb, mem_ctx, 
680                                                &guid_blob, &binary_guid_blob), -1,
681                                  "Should have failed to parse binary GUID");
682         
683         torture_assert_int_equal(torture, 
684                                  attr->write_hex_fn(ldb, mem_ctx, &guid_blob, &hex_guid_blob), 0,
685                                  "Failed to parse binary GUID");
686         
687         torture_assert_data_blob_equal(torture, 
688                                        hex_guid_blob, data_blob_string_const(hex_guid),
689                                        "Write GUID into HEX string form failed");
690         
691         torture_assert_int_equal(torture, 
692                                  attr->write_clear_fn(ldb, mem_ctx, &guid_blob, &string_guid_blob), 0,
693                                  "Failed to parse binary GUID");
694         
695         torture_assert_data_blob_equal(torture, 
696                                        string_guid_blob, data_blob_string_const(guid),
697                                        "Write GUID into clear string form failed");
698         
699
700
701         talloc_free(mem_ctx);
702         return true;
703 }
704
705 static bool torture_ldb_dn_extended(struct torture_context *torture)
706 {
707         TALLOC_CTX *mem_ctx = talloc_new(torture);
708         struct ldb_context *ldb;
709         struct ldb_dn *dn, *dn2;
710
711         DATA_BLOB sid_blob = strhex_to_data_blob(mem_ctx, hex_sid);
712         DATA_BLOB guid_blob = strhex_to_data_blob(mem_ctx, hex_guid);
713
714         const char *dn_str = "cn=admin,cn=users,dc=samba,dc=org";
715
716         torture_assert(torture, 
717                        ldb = ldb_init(mem_ctx, torture->ev),
718                        "Failed to init ldb");
719
720         torture_assert_int_equal(torture, 
721                                  ldb_register_samba_handlers(ldb), LDB_SUCCESS,
722                                  "Failed to register Samba handlers");
723
724         ldb_set_utf8_fns(ldb, NULL, wrap_casefold);
725
726         /* Check behaviour of a normal DN */
727         torture_assert(torture, 
728                        dn = ldb_dn_new(mem_ctx, ldb, dn_str), 
729                        "Failed to create a 'normal' DN");
730
731         torture_assert(torture, 
732                        ldb_dn_validate(dn),
733                        "Failed to validate 'normal' DN");
734
735         torture_assert(torture, ldb_dn_has_extended(dn) == false, 
736                        "Should not find plain DN to be 'extended'");
737
738         torture_assert(torture, ldb_dn_get_extended_component(dn, "SID") == NULL, 
739                        "Should not find an SID on plain DN");
740
741         torture_assert(torture, ldb_dn_get_extended_component(dn, "GUID") == NULL, 
742                        "Should not find an GUID on plain DN");
743         
744         torture_assert(torture, ldb_dn_get_extended_component(dn, "WKGUID") == NULL, 
745                        "Should not find an WKGUID on plain DN");
746         
747         /* Now make an extended DN */
748         torture_assert(torture, 
749                        dn = ldb_dn_new_fmt(mem_ctx, ldb, "<GUID=%s>;<SID=%s>;%s",
750                                            guid, sid, dn_str), 
751                        "Failed to create an 'extended' DN");
752
753         torture_assert(torture, 
754                        dn2 = ldb_dn_copy(mem_ctx, dn), 
755                        "Failed to copy the 'extended' DN");
756         talloc_free(dn);
757         dn = dn2;
758
759         torture_assert(torture, 
760                        ldb_dn_validate(dn),
761                        "Failed to validate 'extended' DN");
762
763         torture_assert(torture, ldb_dn_has_extended(dn) == true, 
764                        "Should find extended DN to be 'extended'");
765
766         torture_assert(torture, ldb_dn_get_extended_component(dn, "SID") != NULL, 
767                        "Should find an SID on extended DN");
768
769         torture_assert(torture, ldb_dn_get_extended_component(dn, "GUID") != NULL, 
770                        "Should find an GUID on extended DN");
771         
772         torture_assert_data_blob_equal(torture, *ldb_dn_get_extended_component(dn, "SID"), sid_blob, 
773                                        "Extended DN SID incorect");
774
775         torture_assert_data_blob_equal(torture, *ldb_dn_get_extended_component(dn, "GUID"), guid_blob, 
776                                        "Extended DN GUID incorect");
777
778         torture_assert_str_equal(torture, ldb_dn_get_linearized(dn), dn_str, 
779                                  "linearized DN incorrect");
780
781         torture_assert_str_equal(torture, ldb_dn_get_casefold(dn), strupper_talloc(mem_ctx, dn_str), 
782                                  "casefolded DN incorrect");
783
784         torture_assert_str_equal(torture, ldb_dn_get_component_name(dn, 0), "cn", 
785                                  "componet zero incorrect");
786
787         torture_assert_data_blob_equal(torture, *ldb_dn_get_component_val(dn, 0), data_blob_string_const("admin"), 
788                                  "componet zero incorrect");
789
790         torture_assert_str_equal(torture, ldb_dn_get_extended_linearized(mem_ctx, dn, 1),
791                                  talloc_asprintf(mem_ctx, "<GUID=%s>;<SID=%s>;%s", 
792                                                  guid, sid, dn_str),
793                                  "Clear extended linearized DN incorrect");
794
795         torture_assert_str_equal(torture, ldb_dn_get_extended_linearized(mem_ctx, dn, 0),
796                                  talloc_asprintf(mem_ctx, "<GUID=%s>;<SID=%s>;%s", 
797                                                  hex_guid, hex_sid, dn_str),
798                                  "HEX extended linearized DN incorrect");
799
800         torture_assert(torture, ldb_dn_remove_child_components(dn, 1) == true,
801                                  "Failed to remove DN child");
802                        
803         torture_assert(torture, ldb_dn_has_extended(dn) == false, 
804                        "Extended DN flag should be cleared after child element removal");
805         
806         torture_assert(torture, ldb_dn_get_extended_component(dn, "SID") == NULL, 
807                        "Should not find an SID on DN");
808
809         torture_assert(torture, ldb_dn_get_extended_component(dn, "GUID") == NULL, 
810                        "Should not find an GUID on DN");
811
812
813         /* TODO:  test setting these in the other order, and ensure it still comes out 'GUID first' */
814         torture_assert_int_equal(torture, ldb_dn_set_extended_component(dn, "GUID", &guid_blob), 0, 
815                        "Failed to set a GUID on DN");
816         
817         torture_assert_int_equal(torture, ldb_dn_set_extended_component(dn, "SID", &sid_blob), 0, 
818                        "Failed to set a SID on DN");
819
820         torture_assert_data_blob_equal(torture, *ldb_dn_get_extended_component(dn, "SID"), sid_blob, 
821                                        "Extended DN SID incorect");
822
823         torture_assert_data_blob_equal(torture, *ldb_dn_get_extended_component(dn, "GUID"), guid_blob, 
824                                        "Extended DN GUID incorect");
825
826         torture_assert_str_equal(torture, ldb_dn_get_linearized(dn), "cn=users,dc=samba,dc=org", 
827                                  "linearized DN incorrect");
828
829         torture_assert_str_equal(torture, ldb_dn_get_extended_linearized(mem_ctx, dn, 1),
830                                  talloc_asprintf(mem_ctx, "<GUID=%s>;<SID=%s>;%s", 
831                                                  guid, sid, "cn=users,dc=samba,dc=org"),
832                                  "Clear extended linearized DN incorrect");
833
834         torture_assert_str_equal(torture, ldb_dn_get_extended_linearized(mem_ctx, dn, 0),
835                                  talloc_asprintf(mem_ctx, "<GUID=%s>;<SID=%s>;%s", 
836                                                  hex_guid, hex_sid, "cn=users,dc=samba,dc=org"),
837                                  "HEX extended linearized DN incorrect");
838
839         /* Now check a 'just GUID' DN (clear format) */
840         torture_assert(torture, 
841                        dn = ldb_dn_new_fmt(mem_ctx, ldb, "<GUID=%s>",
842                                            guid), 
843                        "Failed to create an 'extended' DN");
844
845         torture_assert(torture, 
846                        ldb_dn_validate(dn),
847                        "Failed to validate 'extended' DN");
848
849         torture_assert(torture, ldb_dn_has_extended(dn) == true, 
850                        "Should find extended DN to be 'extended'");
851
852         torture_assert(torture, ldb_dn_get_extended_component(dn, "SID") == NULL, 
853                        "Should not find an SID on this DN");
854
855         torture_assert_int_equal(torture, ldb_dn_get_comp_num(dn), 0, 
856                        "Should not find an 'normal' componet on this DN");
857
858         torture_assert(torture, ldb_dn_get_extended_component(dn, "GUID") != NULL, 
859                        "Should find an GUID on this DN");
860         
861         torture_assert_data_blob_equal(torture, *ldb_dn_get_extended_component(dn, "GUID"), guid_blob, 
862                                        "Extended DN GUID incorect");
863
864         torture_assert_str_equal(torture, ldb_dn_get_linearized(dn), "", 
865                                  "linearized DN incorrect");
866
867         torture_assert_str_equal(torture, ldb_dn_get_extended_linearized(mem_ctx, dn, 1),
868                                  talloc_asprintf(mem_ctx, "<GUID=%s>", 
869                                                  guid),
870                                  "Clear extended linearized DN incorrect");
871
872         torture_assert_str_equal(torture, ldb_dn_get_extended_linearized(mem_ctx, dn, 0),
873                                  talloc_asprintf(mem_ctx, "<GUID=%s>", 
874                                                  hex_guid),
875                                  "HEX extended linearized DN incorrect");
876
877         /* Now check a 'just GUID' DN (HEX format) */
878         torture_assert(torture, 
879                        dn = ldb_dn_new_fmt(mem_ctx, ldb, "<GUID=%s>",
880                                            hex_guid), 
881                        "Failed to create an 'extended' DN");
882
883         torture_assert(torture, 
884                        ldb_dn_validate(dn),
885                        "Failed to validate 'extended' DN");
886
887         torture_assert(torture, ldb_dn_has_extended(dn) == true, 
888                        "Should find extended DN to be 'extended'");
889
890         torture_assert(torture, ldb_dn_get_extended_component(dn, "SID") == NULL, 
891                        "Should not find an SID on this DN");
892
893         torture_assert(torture, ldb_dn_get_extended_component(dn, "GUID") != NULL, 
894                        "Should find an GUID on this DN");
895         
896         torture_assert_data_blob_equal(torture, *ldb_dn_get_extended_component(dn, "GUID"), guid_blob, 
897                                        "Extended DN GUID incorect");
898
899         torture_assert_str_equal(torture, ldb_dn_get_linearized(dn), "", 
900                                  "linearized DN incorrect");
901
902         /* Now check a 'just SID' DN (clear format) */
903         torture_assert(torture, 
904                        dn = ldb_dn_new_fmt(mem_ctx, ldb, "<SID=%s>",
905                                            sid), 
906                        "Failed to create an 'extended' DN");
907
908         torture_assert(torture, 
909                        ldb_dn_validate(dn),
910                        "Failed to validate 'extended' DN");
911
912         torture_assert(torture, ldb_dn_has_extended(dn) == true, 
913                        "Should find extended DN to be 'extended'");
914
915         torture_assert(torture, ldb_dn_get_extended_component(dn, "GUID") == NULL, 
916                        "Should not find an SID on this DN");
917
918         torture_assert(torture, ldb_dn_get_extended_component(dn, "SID") != NULL, 
919                        "Should find an SID on this DN");
920         
921         torture_assert_data_blob_equal(torture, *ldb_dn_get_extended_component(dn, "SID"), sid_blob, 
922                                        "Extended DN SID incorect");
923
924         torture_assert_str_equal(torture, ldb_dn_get_linearized(dn), "", 
925                                  "linearized DN incorrect");
926
927         torture_assert_str_equal(torture, ldb_dn_get_extended_linearized(mem_ctx, dn, 1),
928                                  talloc_asprintf(mem_ctx, "<SID=%s>", 
929                                                  sid),
930                                  "Clear extended linearized DN incorrect");
931
932         torture_assert_str_equal(torture, ldb_dn_get_extended_linearized(mem_ctx, dn, 0),
933                                  talloc_asprintf(mem_ctx, "<SID=%s>", 
934                                                  hex_sid),
935                                  "HEX extended linearized DN incorrect");
936
937         /* Now check a 'just SID' DN (HEX format) */
938         torture_assert(torture, 
939                        dn = ldb_dn_new_fmt(mem_ctx, ldb, "<SID=%s>",
940                                            hex_sid), 
941                        "Failed to create an 'extended' DN");
942
943         torture_assert(torture, 
944                        ldb_dn_validate(dn),
945                        "Failed to validate 'extended' DN");
946
947         torture_assert(torture, ldb_dn_has_extended(dn) == true, 
948                        "Should find extended DN to be 'extended'");
949
950         torture_assert(torture, ldb_dn_get_extended_component(dn, "GUID") == NULL, 
951                        "Should not find an SID on this DN");
952
953         torture_assert(torture, ldb_dn_get_extended_component(dn, "SID") != NULL, 
954                        "Should find an SID on this DN");
955         
956         torture_assert_data_blob_equal(torture, *ldb_dn_get_extended_component(dn, "SID"), sid_blob, 
957                                        "Extended DN SID incorect");
958
959         torture_assert_str_equal(torture, ldb_dn_get_linearized(dn), "", 
960                                  "linearized DN incorrect");
961
962         talloc_free(mem_ctx);
963         return true;
964 }
965
966
967 static bool torture_ldb_dn(struct torture_context *torture)
968 {
969         TALLOC_CTX *mem_ctx = talloc_new(torture);
970         struct ldb_context *ldb;
971         struct ldb_dn *dn;
972         struct ldb_dn *child_dn;
973         struct ldb_dn *typo_dn;
974         struct ldb_dn *special_dn;
975         struct ldb_val val;
976
977         torture_assert(torture, 
978                        ldb = ldb_init(mem_ctx, torture->ev),
979                        "Failed to init ldb");
980
981         torture_assert_int_equal(torture, 
982                                  ldb_register_samba_handlers(ldb), LDB_SUCCESS,
983                                  "Failed to register Samba handlers");
984
985         ldb_set_utf8_fns(ldb, NULL, wrap_casefold);
986
987         /* Check behaviour of a normal DN */
988         torture_assert(torture, 
989                        dn = ldb_dn_new(mem_ctx, ldb, NULL), 
990                        "Failed to create a NULL DN");
991
992         torture_assert(torture, 
993                        ldb_dn_validate(dn),
994                        "Failed to validate NULL DN");
995
996         torture_assert(torture, 
997                        ldb_dn_add_base_fmt(dn, "dc=org"), 
998                        "Failed to add base DN");
999
1000         torture_assert(torture, 
1001                        ldb_dn_add_child_fmt(dn, "dc=samba"), 
1002                        "Failed to add base DN");
1003
1004         torture_assert_str_equal(torture, ldb_dn_get_linearized(dn), "dc=samba,dc=org", 
1005                                  "linearized DN incorrect");
1006
1007         torture_assert_str_equal(torture, ldb_dn_get_extended_linearized(mem_ctx, dn, 0), "dc=samba,dc=org", 
1008                                  "extended linearized DN incorrect");
1009
1010         /* Check child DN comparisons */
1011         torture_assert(torture, 
1012                        child_dn = ldb_dn_new(mem_ctx, ldb, "CN=users,DC=SAMBA,DC=org"), 
1013                        "Failed to create child DN");
1014
1015         torture_assert(torture, 
1016                        ldb_dn_compare(dn, child_dn) != 0,
1017                        "Comparison on dc=samba,dc=org and CN=users,DC=SAMBA,DC=org should != 0");
1018
1019         torture_assert(torture, 
1020                        ldb_dn_compare_base(child_dn, dn) != 0,
1021                        "Base Comparison of CN=users,DC=SAMBA,DC=org and dc=samba,dc=org should != 0");
1022
1023         torture_assert(torture, 
1024                        ldb_dn_compare_base(dn, child_dn) == 0,
1025                        "Base Comparison on dc=samba,dc=org and CN=users,DC=SAMBA,DC=org should == 0");
1026
1027         /* Check comparisons with a truncated DN */
1028         torture_assert(torture, 
1029                        typo_dn = ldb_dn_new(mem_ctx, ldb, "c=samba,dc=org"), 
1030                        "Failed to create 'typo' DN");
1031
1032         torture_assert(torture, 
1033                        ldb_dn_compare(dn, typo_dn) != 0,
1034                        "Comparison on dc=samba,dc=org and c=samba,dc=org should != 0");
1035
1036         torture_assert(torture, 
1037                        ldb_dn_compare_base(typo_dn, dn) != 0,
1038                        "Base Comparison of c=samba,dc=org and dc=samba,dc=org should != 0");
1039
1040         torture_assert(torture, 
1041                        ldb_dn_compare_base(dn, typo_dn) != 0,
1042                        "Base Comparison on dc=samba,dc=org and c=samba,dc=org should != 0");
1043
1044         /* Check comparisons with a special DN */
1045         torture_assert(torture,
1046                        special_dn = ldb_dn_new(mem_ctx, ldb, "@special_dn"),
1047                        "Failed to create 'special' DN");
1048
1049         torture_assert(torture,
1050                        ldb_dn_compare(dn, special_dn) != 0,
1051                        "Comparison on dc=samba,dc=org and @special_dn should != 0");
1052
1053         torture_assert(torture,
1054                        ldb_dn_compare_base(special_dn, dn) > 0,
1055                        "Base Comparison of @special_dn and dc=samba,dc=org should > 0");
1056
1057         torture_assert(torture,
1058                        ldb_dn_compare_base(dn, special_dn) < 0,
1059                        "Base Comparison on dc=samba,dc=org and @special_dn should < 0");
1060
1061         /* Check DN based on MS-ADTS:3.1.1.5.1.2 Naming Constraints*/
1062         torture_assert(torture,
1063                        dn = ldb_dn_new(mem_ctx, ldb, "CN=New\nLine,DC=SAMBA,DC=org"),
1064                        "Failed to create a DN with 0xA in it");
1065
1066         /* this is a warning until we work out how the DEL: CNs work */
1067         if (ldb_dn_validate(dn) != false) {
1068                 torture_warning(torture,
1069                                 "should have failed to validate a DN with 0xA in it");
1070         }
1071
1072         /* Escaped comma */
1073         torture_assert(torture,
1074                        dn = ldb_dn_new(mem_ctx, ldb, "CN=A\\,comma,DC=SAMBA,DC=org"),
1075                        "Failed to create a DN with an escaped comma in it");
1076
1077
1078         val = data_blob_const("CN=Zer\0,DC=SAMBA,DC=org", 23);
1079         torture_assert(torture,
1080                        NULL == ldb_dn_from_ldb_val(mem_ctx, ldb, &val),
1081                        "should fail to create a DN with 0x0 in it");
1082
1083         talloc_free(mem_ctx);
1084         return true;
1085 }
1086
1087 static bool torture_ldb_dn_invalid_extended(struct torture_context *torture)
1088 {
1089         TALLOC_CTX *mem_ctx = talloc_new(torture);
1090         struct ldb_context *ldb;
1091         struct ldb_dn *dn;
1092
1093         const char *dn_str = "cn=admin,cn=users,dc=samba,dc=org";
1094
1095         torture_assert(torture, 
1096                        ldb = ldb_init(mem_ctx, torture->ev),
1097                        "Failed to init ldb");
1098
1099         torture_assert_int_equal(torture, 
1100                                  ldb_register_samba_handlers(ldb), LDB_SUCCESS,
1101                                  "Failed to register Samba handlers");
1102
1103         ldb_set_utf8_fns(ldb, NULL, wrap_casefold);
1104
1105         /* Check behaviour of a normal DN */
1106         torture_assert(torture, 
1107                        dn = ldb_dn_new(mem_ctx, ldb, "samba,dc=org"), 
1108                        "Failed to create a 'normal' invalid DN");
1109
1110         torture_assert(torture, 
1111                        ldb_dn_validate(dn) == false,
1112                        "should have failed to validate 'normal' invalid DN");
1113
1114         /* Now make an extended DN */
1115         torture_assert(torture, 
1116                        dn = ldb_dn_new_fmt(mem_ctx, ldb, "<PID=%s>;%s",
1117                                            sid, dn_str), 
1118                        "Failed to create an invalid 'extended' DN");
1119
1120         torture_assert(torture, 
1121                        ldb_dn_validate(dn) == false,
1122                        "should have failed to validate 'extended' DN");
1123
1124         torture_assert(torture, 
1125                        dn = ldb_dn_new_fmt(mem_ctx, ldb, "<GUID=%s>%s",
1126                                            sid, dn_str), 
1127                        "Failed to create an invalid 'extended' DN");
1128
1129         torture_assert(torture, 
1130                        ldb_dn_validate(dn) == false,
1131                        "should have failed to validate 'extended' DN");
1132
1133         torture_assert(torture, 
1134                        dn = ldb_dn_new_fmt(mem_ctx, ldb, "<GUID=%s>;",
1135                                            sid), 
1136                        "Failed to create an invalid 'extended' DN");
1137
1138         torture_assert(torture, 
1139                        ldb_dn_validate(dn) == false,
1140                        "should have failed to validate 'extended' DN");
1141
1142         torture_assert(torture, 
1143                        dn = ldb_dn_new_fmt(mem_ctx, ldb, "<GUID=%s>;",
1144                                            hex_sid), 
1145                        "Failed to create an invalid 'extended' DN");
1146
1147         torture_assert(torture, 
1148                        ldb_dn_validate(dn) == false,
1149                        "should have failed to validate 'extended' DN");
1150
1151         torture_assert(torture, 
1152                        dn = ldb_dn_new_fmt(mem_ctx, ldb, "<SID=%s>;",
1153                                            hex_guid), 
1154                        "Failed to create an invalid 'extended' DN");
1155
1156         torture_assert(torture, 
1157                        ldb_dn_validate(dn) == false,
1158                        "should have failed to validate 'extended' DN");
1159
1160         torture_assert(torture, 
1161                        dn = ldb_dn_new_fmt(mem_ctx, ldb, "<SID=%s>;",
1162                                            guid), 
1163                        "Failed to create an invalid 'extended' DN");
1164
1165         torture_assert(torture, 
1166                        ldb_dn_validate(dn) == false,
1167                        "should have failed to validate 'extended' DN");
1168
1169         torture_assert(torture, 
1170                        dn = ldb_dn_new_fmt(mem_ctx, ldb, "<GUID=>"), 
1171                        "Failed to create an invalid 'extended' DN");
1172
1173         torture_assert(torture, 
1174                        ldb_dn_validate(dn) == false,
1175                        "should have failed to validate 'extended' DN");
1176
1177         return true;
1178 }
1179
1180 static bool helper_ldb_message_compare(struct torture_context *torture,
1181                                        struct ldb_message *a,
1182                                        struct ldb_message *b)
1183 {
1184         int i;
1185
1186         if (a->num_elements != b->num_elements) {
1187                 return false;
1188         }
1189
1190         for (i = 0; i < a->num_elements; i++) {
1191                 int j;
1192                 struct ldb_message_element x = a->elements[i];
1193                 struct ldb_message_element y = b->elements[i];
1194
1195                 torture_comment(torture, "#%s\n", x.name);
1196                 torture_assert_int_equal(torture, x.flags, y.flags,
1197                                          "Flags do not match");
1198                 torture_assert_str_equal(torture, x.name, y.name,
1199                                          "Names do not match in field");
1200                 torture_assert_int_equal(torture, x.num_values, y.num_values,
1201                                          "Number of values do not match");
1202
1203                 /*
1204                  * Records cannot round trip via the SDDL string with a
1205                  * nTSecurityDescriptor field.
1206                  *
1207                  * Parsing from SDDL and diffing the NDR dump output gives the
1208                  * following:
1209                  *
1210                  *          in: struct decode_security_descriptor
1211                  *             sd: struct security_descriptor
1212                  *                 revision                 : SECURITY_DESCRIPTOR_REVISION_1 (1)
1213                  *-                type                     : 0x8c14 (35860)
1214                  *-                       0: SEC_DESC_OWNER_DEFAULTED
1215                  *-                       0: SEC_DESC_GROUP_DEFAULTED
1216                  *+                type                     : 0x8c17 (35863)
1217                  *+                       1: SEC_DESC_OWNER_DEFAULTED
1218                  *+                       1: SEC_DESC_GROUP_DEFAULTED
1219                  *                        1: SEC_DESC_DACL_PRESENT
1220                  *                        0: SEC_DESC_DACL_DEFAULTED
1221                  *                        1: SEC_DESC_SACL_PRESENT
1222                  */
1223                 if (strcmp(x.name, "nTSecurityDescriptor") == 0) {
1224                         continue;
1225                 }
1226                 for (j = 0; j < x.num_values; j++) {
1227                         torture_assert_int_equal(torture, x.values[j].length,
1228                                                  y.values[j].length,
1229                                                  "Does not match in length");
1230                         torture_assert_mem_equal(torture,
1231                                                  x.values[j].data,
1232                                                  y.values[j].data,
1233                                                  x.values[j].length,
1234                                                  "Does not match in data");
1235                 }
1236         }
1237         return true;
1238 }
1239
1240 static bool torture_ldb_unpack(struct torture_context *torture,
1241                                const void *data_p)
1242 {
1243         TALLOC_CTX *mem_ctx = talloc_new(torture);
1244         struct ldb_context *ldb;
1245         struct ldb_val data = *discard_const_p(struct ldb_val, data_p);
1246         struct ldb_message *msg = ldb_msg_new(mem_ctx);
1247         const char *ldif_text = dda1d01d_ldif;
1248         struct ldb_ldif ldif;
1249
1250         ldb = samba_ldb_init(mem_ctx, torture->ev, NULL, NULL, NULL);
1251         torture_assert(torture,
1252                        ldb != NULL,
1253                        "Failed to init ldb");
1254
1255         torture_assert_int_equal(torture, ldb_unpack_data(ldb, &data, msg), 0,
1256                                  "ldb_unpack_data failed");
1257
1258         ldif.changetype = LDB_CHANGETYPE_NONE;
1259         ldif.msg = msg;
1260         ldif_text = ldb_ldif_write_string(ldb, mem_ctx, &ldif);
1261
1262         torture_assert_int_equal(torture,
1263                                  strcmp(ldif_text, dda1d01d_ldif), 0,
1264                                  "ldif form differs from binary form");
1265         return true;
1266 }
1267
1268 static bool torture_ldb_unpack_flags(struct torture_context *torture,
1269                                      const void *data_p)
1270 {
1271         TALLOC_CTX *mem_ctx = talloc_new(torture);
1272         struct ldb_context *ldb;
1273         struct ldb_val data = *discard_const_p(struct ldb_val, data_p);
1274         struct ldb_message *msg = ldb_msg_new(mem_ctx);
1275         const char *ldif_text = dda1d01d_ldif;
1276         struct ldb_ldif ldif;
1277
1278         ldb = samba_ldb_init(mem_ctx, torture->ev, NULL, NULL, NULL);
1279         torture_assert(torture,
1280                        ldb != NULL,
1281                        "Failed to init ldb");
1282
1283         torture_assert_int_equal(torture,
1284                                  ldb_unpack_data_flags(ldb, &data, msg,
1285                                         LDB_UNPACK_DATA_FLAG_NO_VALUES_ALLOC),
1286                                  0,
1287                                  "ldb_unpack_data failed");
1288
1289         ldif.changetype = LDB_CHANGETYPE_NONE;
1290         ldif.msg = msg;
1291         ldif_text = ldb_ldif_write_string(ldb, mem_ctx, &ldif);
1292
1293         torture_assert_int_equal(torture,
1294                                  strcmp(ldif_text, dda1d01d_ldif), 0,
1295                                  "ldif form differs from binary form");
1296
1297         torture_assert_int_equal(torture,
1298                                  ldb_unpack_data_flags(ldb, &data, msg,
1299                                                 LDB_UNPACK_DATA_FLAG_NO_DN),
1300                                  0,
1301                                  "ldb_unpack_data failed");
1302
1303         torture_assert(torture,
1304                        msg->dn == NULL,
1305                        "msg->dn should be NULL");
1306
1307         return true;
1308 }
1309
1310 static bool torture_ldb_unpack_data_corrupt(struct torture_context *torture)
1311 {
1312         TALLOC_CTX *mem_ctx = talloc_new(torture);
1313         struct ldb_context *ldb;
1314
1315         uint8_t bin[] = {0x68, 0x19, 0x01, 0x26, /* version */
1316                 1, 0, 0, 0, /* num elements */
1317                 4, 0, 0, 0, /* dn length */
1318                 'D', 'N', '=', 'A', 0, /* dn with null term */
1319                 2, 0, 0, 0, /* canonicalized dn length */
1320                 '/', 'A', 0, /* canonicalized dn with null term */
1321                 18, 0, 0, 0, /* size of name and sizes section + 4 (this field) */
1322                 3, 0, 0, 0, /* el name length */
1323                 'a', 'b', 'c', 0, /* name with null term */
1324                 1, 0, 0, 0, 1, /* num values and length width */
1325                 1, /* value lengths */
1326                 '1', 0}; /* values for abc */
1327
1328         struct ldb_val binary = data_blob_const(bin, sizeof(bin));
1329         struct ldb_val bin_copy;
1330         struct ldb_message *msg;
1331
1332         int i, j, current, expect_rcode, ret;
1333         const char *comment;
1334         const char *comment_fmt = "Expected unpack rcode for index %d "
1335                                   "(corrupt bytes index %d) "
1336                                   "to be %d but got %d";
1337
1338         /*
1339          * List of corruptible byte ranges. First 12 bytes are corruptible,
1340          * next 4 bytes are not, next 5 bytes are corruptible, etc.
1341          */
1342         uint8_t corrupt_bytes[] = {12, 4, 5, 2, 9, 3, 7, 2};
1343
1344         ldb = samba_ldb_init(mem_ctx, torture->ev, NULL,NULL,NULL);
1345         torture_assert(torture, ldb != NULL, "Failed to init ldb");
1346
1347         current = 0;
1348         for (i=0; i<sizeof(corrupt_bytes); i++) {
1349                 expect_rcode = i % 2 == 0 ? -1 : 0;
1350
1351                 for (j=0; j<corrupt_bytes[i]; j++, current++) {
1352                         bin_copy.data = talloc_size(NULL, binary.length);
1353                         memcpy(bin_copy.data, binary.data, binary.length);
1354                         bin_copy.length = binary.length;
1355                         msg = ldb_msg_new(bin_copy.data);
1356
1357                         bin_copy.data[current]++;
1358
1359                         ret = ldb_unpack_data(ldb, &bin_copy, msg);
1360
1361                         comment = talloc_asprintf(bin_copy.data, comment_fmt,
1362                                                   current, i,
1363                                                   expect_rcode, ret);
1364                         torture_assert_int_equal(torture, ret, expect_rcode,
1365                                                  comment);
1366
1367                         talloc_free(bin_copy.data);
1368                 }
1369         }
1370
1371         return true;
1372 }
1373
1374 static bool torture_ldb_pack_data_v2(struct torture_context *torture)
1375 {
1376         TALLOC_CTX *mem_ctx = talloc_new(torture);
1377         struct ldb_context *ldb;
1378         struct ldb_val binary;
1379
1380         uint8_t bin[] = {0x68, 0x19, 0x01, 0x26, /* version */
1381                 2, 0, 0, 0, /* num elements */
1382                 4, 0, 0, 0, /* dn length */
1383                 'D', 'N', '=', 'A', 0, /* dn with null term */
1384                 2, 0, 0, 0, /* canonicalized dn length */
1385                 '/', 'A', 0, /* canonicalized dn with null term */
1386                 42, 0, 0, 0, /* distance from here to values section */
1387                 3, 0, 0, 0, /* el name length */
1388                 'a', 'b', 'c', 0, /* name with null term */
1389                 4, 0, 0, 0, 1, /* num values and length width */
1390                 1, 1, 1, 1, /* value lengths */
1391                 3, 0, 0, 0, /* el name length */
1392                 'd', 'e', 'f', 0, /* name def with null term */
1393                 4, 0, 0, 0, 2, /* num of values and length width */
1394                 1, 0, 1, 0, 1, 0, 0, 1, /* value lengths */
1395                 '1', 0, '2', 0, '3', 0, '4', 0, /* values for abc */
1396                 '5', 0, '6', 0, '7', 0}; /* first 3 values for def */
1397
1398         char eight_256[257] =\
1399                 "88888888888888888888888888888888888888888888888888888888888"
1400                 "88888888888888888888888888888888888888888888888888888888888"
1401                 "88888888888888888888888888888888888888888888888888888888888"
1402                 "88888888888888888888888888888888888888888888888888888888888"
1403                 "88888888888888888888"; /* def's 4th value */
1404
1405         struct ldb_val vals[4] = {{.data=discard_const_p(uint8_t, "1"),
1406                                    .length=1},
1407                                   {.data=discard_const_p(uint8_t, "2"),
1408                                    .length=1},
1409                                   {.data=discard_const_p(uint8_t, "3"),
1410                                    .length=1},
1411                                   {.data=discard_const_p(uint8_t, "4"),
1412                                    .length=1}};
1413         struct ldb_val vals2[4] = {{.data=discard_const_p(uint8_t,"5"),
1414                                    .length=1},
1415                                   {.data=discard_const_p(uint8_t, "6"),
1416                                    .length=1},
1417                                   {.data=discard_const_p(uint8_t, "7"),
1418                                    .length=1},
1419                                   {.data=discard_const_p(uint8_t, eight_256),
1420                                    .length=256}};
1421         struct ldb_message_element els[2] = {{.name=discard_const_p(char, "abc"),
1422                                            .num_values=4, .values=vals},
1423                                           {.name=discard_const_p(char, "def"),
1424                                            .num_values=4, .values=vals2}};
1425         struct ldb_message msg = {.num_elements=2, .elements=els};
1426
1427         uint8_t *expect_bin;
1428         struct ldb_val expect_bin_ldb;
1429         size_t expect_size = sizeof(bin) + sizeof(eight_256);
1430         expect_bin = talloc_size(NULL, expect_size);
1431         memcpy(expect_bin, bin, sizeof(bin));
1432         memcpy(expect_bin + sizeof(bin), eight_256, sizeof(eight_256));
1433         expect_bin_ldb = data_blob_const(expect_bin, expect_size);
1434
1435         ldb = samba_ldb_init(mem_ctx, torture->ev, NULL,NULL,NULL);
1436         torture_assert(torture, ldb != NULL, "Failed to init ldb");
1437
1438         msg.dn = ldb_dn_new(NULL, ldb, "DN=A");
1439
1440         torture_assert_int_equal(torture,
1441                                  ldb_pack_data(ldb, &msg, &binary,
1442                                                LDB_PACKING_FORMAT_V2),
1443                                  0, "ldb_pack_data failed");
1444
1445         torture_assert_int_equal(torture, expect_bin_ldb.length,
1446                                  binary.length,
1447                                  "packed data length not as expected");
1448
1449         torture_assert_mem_equal(torture,
1450                                  expect_bin_ldb.data,
1451                                  binary.data,
1452                                  binary.length,
1453                                  "packed data not as expected");
1454         talloc_free(expect_bin);
1455
1456         return true;
1457 }
1458
1459 static bool torture_ldb_pack_data_v2_special(struct torture_context *torture)
1460 {
1461         TALLOC_CTX *mem_ctx = talloc_new(torture);
1462         struct ldb_context *ldb;
1463         struct ldb_val binary;
1464
1465         uint8_t bin[] = {0x68, 0x19, 0x01, 0x26, /* version */
1466                 1, 0, 0, 0, /* num elements */
1467                 2, 0, 0, 0, /* dn length */
1468                 '@', 'A', 0, /* dn with null term */
1469                 0, 0, 0, 0, /* canonicalized dn length */
1470                 0, /* no canonicalized dn, just null term */
1471                 18, 0, 0, 0, /* distance from here to values section */
1472                 3, 0, 0, 0, /* el name length */
1473                 'a', 'b', 'c', 0, /* name with null term */
1474                 1, 0, 0, 0, 1, /* num values and length width */
1475                 1, /* value lengths */
1476                 '1', 0}; /* values for abc */
1477
1478         struct ldb_val vals[1] = {{.data=discard_const_p(uint8_t, "1"),
1479                                    .length=1}};
1480         struct ldb_message_element els[1] = {{.name=discard_const_p(char,
1481                                                                     "abc"),
1482                                               .num_values=1, .values=vals}};
1483         struct ldb_message msg = {.num_elements=1, .elements=els};
1484
1485         struct ldb_val expect_bin_ldb;
1486         expect_bin_ldb = data_blob_const(bin, sizeof(bin));
1487
1488         ldb = samba_ldb_init(mem_ctx, torture->ev, NULL,NULL,NULL);
1489         torture_assert(torture, ldb != NULL, "Failed to init ldb");
1490
1491         msg.dn = ldb_dn_new(NULL, ldb, "@A");
1492
1493         torture_assert_int_equal(torture,
1494                                  ldb_pack_data(ldb, &msg, &binary,
1495                                                LDB_PACKING_FORMAT_V2),
1496                                  0, "ldb_pack_data failed");
1497
1498         torture_assert_int_equal(torture, expect_bin_ldb.length,
1499                                  binary.length,
1500                                  "packed data length not as expected");
1501
1502         torture_assert_mem_equal(torture,
1503                                  expect_bin_ldb.data,
1504                                  binary.data,
1505                                  binary.length,
1506                                  "packed data not as expected");
1507
1508         return true;
1509 }
1510
1511 static bool torture_ldb_parse_ldif(struct torture_context *torture,
1512                                    const void *data_p)
1513 {
1514         TALLOC_CTX *mem_ctx = talloc_new(torture);
1515         const char *ldif_text = dda1d01d_ldif;
1516         struct ldb_context *ldb;
1517         struct ldb_ldif *ldif;
1518         struct ldb_val binary;
1519         struct ldb_val data = *discard_const_p(struct ldb_val, data_p);
1520         struct ldb_message *msg = ldb_msg_new(mem_ctx);
1521
1522         ldb = samba_ldb_init(mem_ctx, torture->ev, NULL,NULL,NULL);
1523         torture_assert(torture,
1524                        ldb != NULL,
1525                        "Failed to init ldb");
1526
1527         ldif = ldb_ldif_read_string(ldb, &ldif_text);
1528         torture_assert(torture,
1529                        ldif != NULL,
1530                        "ldb_ldif_read_string failed");
1531         torture_assert_int_equal(torture, ldif->changetype, LDB_CHANGETYPE_NONE,
1532                                  "changetype is incorrect");
1533         torture_assert_int_equal(torture,
1534                                  ldb_pack_data(ldb, ldif->msg, &binary,
1535                                                LDB_PACKING_FORMAT_V2),
1536                                  0, "ldb_pack_data failed");
1537
1538         torture_assert_int_equal(torture, ldb_unpack_data(ldb, &data, msg), 0,
1539                                  "ldb_unpack_data failed");
1540
1541         torture_assert(torture,
1542                        helper_ldb_message_compare(torture, ldif->msg, msg),
1543                        "Forms differ in memory");
1544
1545         return true;
1546 }
1547
1548 static bool torture_ldb_pack_format_perf(struct torture_context *torture)
1549 {
1550         TALLOC_CTX *mem_ctx = talloc_new(torture);
1551         char *unp_ldif_text = talloc_strndup(mem_ctx, dda1d01d_ldif,
1552                                                sizeof(dda1d01d_ldif)-1);
1553         const char *ldif_text;
1554         struct ldb_context *ldb;
1555         struct ldb_ldif *ldif;
1556         struct ldb_val binary;
1557         struct ldb_message *msg = ldb_msg_new(mem_ctx);
1558         int ret, i;
1559         clock_t start, diff;
1560
1561         ldb = samba_ldb_init(mem_ctx, torture->ev, NULL,NULL,NULL);
1562         torture_assert(torture,
1563                        ldb != NULL,
1564                        "Failed to init ldb");
1565
1566         unp_ldif_text[sizeof(dda1d01d_ldif)-2] = '\0';
1567         ldif_text = unp_ldif_text;
1568
1569         for (i=0; i<10000; i++) {
1570                 ldif_text = talloc_asprintf_append(
1571                                 discard_const_p(char, ldif_text),
1572                                 "member: fillerfillerfillerfillerfillerfiller"
1573                                 "fillerfillerfillerfillerfillerfillerfiller"
1574                                 "fillerfillerfillerfillerfiller-group%d\n", i);
1575         }
1576
1577         ldif = ldb_ldif_read_string(ldb, &ldif_text);
1578         torture_assert(torture,
1579                        ldif != NULL,
1580                        "ldb_ldif_read_string failed");
1581         torture_assert_int_equal(torture, ldif->changetype, LDB_CHANGETYPE_NONE,
1582                                  "changetype is incorrect");
1583         torture_assert_int_equal(torture,
1584                                  ldb_pack_data(ldb, ldif->msg, &binary,
1585                                                LDB_PACKING_FORMAT_V2),
1586                                  0, "ldb_pack_data failed");
1587
1588         ret = ldb_unpack_data(ldb, &binary, msg);
1589         torture_assert_int_equal(torture, ret, 0,
1590                                  "ldb_unpack_data failed");
1591
1592         torture_assert(torture,
1593                        helper_ldb_message_compare(torture, ldif->msg, msg),
1594                        "Forms differ in memory");
1595
1596         i = 0;
1597         start = clock();
1598         while (true) {
1599                 ldb_pack_data(ldb, ldif->msg, &binary, LDB_PACKING_FORMAT_V2);
1600                 i++;
1601
1602                 if (i >= 1000) {
1603                         break;
1604                 }
1605         }
1606         diff = (clock() - start) * 1000 / CLOCKS_PER_SEC;
1607         printf("\n%d pack runs took: %ldms\n", i, diff);
1608
1609         i = 0;
1610         start = clock();
1611         while (true) {
1612                 ldb_unpack_data(ldb, &binary, msg);
1613                 i++;
1614
1615                 if (i >= 1000) {
1616                         break;
1617                 }
1618         }
1619         diff = (clock() - start) * 1000 / CLOCKS_PER_SEC;
1620         printf("%d unpack runs took: %ldms\n", i, diff);
1621
1622         return true;
1623 }
1624
1625 static bool torture_ldb_unpack_and_filter(struct torture_context *torture,
1626                                           const void *data_p)
1627 {
1628         TALLOC_CTX *mem_ctx = talloc_new(torture);
1629         struct ldb_context *ldb;
1630         struct ldb_val data = *discard_const_p(struct ldb_val, data_p);
1631         struct ldb_message *unpack_msg = ldb_msg_new(mem_ctx);
1632         struct ldb_message *msg = ldb_msg_new(mem_ctx);
1633         const char *lookup_names[] = {"instanceType", "nonexistant",
1634                                       "whenChanged", "objectClass",
1635                                       "uSNCreated", "showInAdvancedViewOnly",
1636                                       "name", "cnNotHere", NULL};
1637         const char *ldif_text;
1638         struct ldb_ldif ldif;
1639
1640         ldb = samba_ldb_init(mem_ctx, torture->ev, NULL, NULL, NULL);
1641         torture_assert(torture,
1642                        ldb != NULL,
1643                        "Failed to init samba");
1644
1645         torture_assert_int_equal(torture,
1646                                  ldb_unpack_data(ldb, &data, unpack_msg),
1647                                  0, "ldb_unpack_data failed");
1648
1649         torture_assert_int_equal(torture, unpack_msg->num_elements, 13,
1650                                  "Got wrong count of elements");
1651
1652         msg->dn = talloc_steal(msg, unpack_msg->dn);
1653
1654         torture_assert_int_equal(torture,
1655                                  ldb_filter_attrs(ldb, unpack_msg,
1656                                                   lookup_names, msg),
1657                                  0, "ldb_kv_filter_attrs failed");
1658
1659         /* Compare data in binary form */
1660         torture_assert_int_equal(torture, msg->num_elements, 6,
1661                                  "Got wrong number of parsed elements");
1662
1663         torture_assert_str_equal(torture, msg->elements[0].name, "objectClass",
1664                                  "First element has wrong name");
1665         torture_assert_int_equal(torture, msg->elements[0].num_values, 2,
1666                                  "First element has wrong count of values");
1667         torture_assert_int_equal(torture,
1668                                  msg->elements[0].values[0].length, 3,
1669                                  "First element's first value is of wrong length");
1670         torture_assert_mem_equal(torture,
1671                                  msg->elements[0].values[0].data, "top", 3,
1672                                  "First element's first value is incorrect");
1673         torture_assert_int_equal(torture,
1674                                  msg->elements[0].values[1].length, strlen("container"),
1675                                  "First element's second value is of wrong length");
1676         torture_assert_mem_equal(torture, msg->elements[0].values[1].data,
1677                                  "container", strlen("container"),
1678                                  "First element's second value is incorrect");
1679
1680         torture_assert_str_equal(torture, msg->elements[1].name, "instanceType",
1681                                  "Second element has wrong name");
1682         torture_assert_int_equal(torture, msg->elements[1].num_values, 1,
1683                                  "Second element has too many values");
1684         torture_assert_int_equal(torture, msg->elements[1].values[0].length, 1,
1685                                  "Second element's value is of wrong length");
1686         torture_assert_mem_equal(torture, msg->elements[1].values[0].data,
1687                                  "4", 1,
1688                                  "Second element's value is incorrect");
1689
1690         torture_assert_str_equal(torture, msg->elements[2].name, "whenChanged",
1691                                  "Third element has wrong name");
1692         torture_assert_int_equal(torture, msg->elements[2].num_values, 1,
1693                                  "Third element has too many values");
1694         torture_assert_int_equal(torture, msg->elements[2].values[0].length,
1695                                  strlen("20150708224310.0Z"),
1696                                  "Third element's value is of wrong length");
1697         torture_assert_mem_equal(torture, msg->elements[2].values[0].data,
1698                                  "20150708224310.0Z", strlen("20150708224310.0Z"),
1699                                  "Third element's value is incorrect");
1700
1701         torture_assert_str_equal(torture, msg->elements[3].name, "uSNCreated",
1702                                  "Fourth element has wrong name");
1703         torture_assert_int_equal(torture, msg->elements[3].num_values, 1,
1704                                  "Fourth element has too many values");
1705         torture_assert_int_equal(torture, msg->elements[3].values[0].length, 4,
1706                                  "Fourth element's value is of wrong length");
1707         torture_assert_mem_equal(torture, msg->elements[3].values[0].data,
1708                                  "3467", 4,
1709                                  "Fourth element's value is incorrect");
1710
1711         torture_assert_str_equal(torture, msg->elements[4].name, "showInAdvancedViewOnly",
1712                                  "Fifth element has wrong name");
1713         torture_assert_int_equal(torture, msg->elements[4].num_values, 1,
1714                                  "Fifth element has too many values");
1715         torture_assert_int_equal(torture, msg->elements[4].values[0].length, 4,
1716                                  "Fifth element's value is of wrong length");
1717         torture_assert_mem_equal(torture, msg->elements[4].values[0].data,
1718                                  "TRUE", 4,
1719                                  "Fourth element's value is incorrect");
1720
1721         torture_assert_str_equal(torture, msg->elements[5].name, "name",
1722                                  "Sixth element has wrong name");
1723         torture_assert_int_equal(torture, msg->elements[5].num_values, 1,
1724                                  "Sixth element has too many values");
1725         torture_assert_int_equal(torture, msg->elements[5].values[0].length,
1726                                  strlen("dda1d01d-4bd7-4c49-a184-46f9241b560e"),
1727                                  "Sixth element's value is of wrong length");
1728         torture_assert_mem_equal(torture, msg->elements[5].values[0].data,
1729                                  "dda1d01d-4bd7-4c49-a184-46f9241b560e",
1730                                  strlen("dda1d01d-4bd7-4c49-a184-46f9241b560e"),
1731                                  "Sixth element's value is incorrect");
1732
1733         /* Compare data in ldif form */
1734         ldif.changetype = LDB_CHANGETYPE_NONE;
1735         ldif.msg = msg;
1736         ldif_text = ldb_ldif_write_string(ldb, mem_ctx, &ldif);
1737
1738         torture_assert_str_equal(torture, ldif_text, dda1d01d_ldif_reduced,
1739                                  "Expected fields did not match");
1740
1741         return true;
1742 }
1743
1744 struct torture_suite *torture_ldb(TALLOC_CTX *mem_ctx)
1745 {
1746         int i;
1747         struct ldb_val *bins = talloc_array(NULL, struct ldb_val, 2);
1748         struct torture_suite *suite = torture_suite_create(mem_ctx, "ldb");
1749
1750         if (suite == NULL) {
1751                 return NULL;
1752         }
1753
1754         bins[0] = data_blob_const(dda1d01d_bin_v1, sizeof(dda1d01d_bin_v1));
1755         bins[1] = data_blob_const(dda1d01d_bin_v2, sizeof(dda1d01d_bin_v2));
1756
1757         torture_suite_add_simple_test(suite, "attrs", torture_ldb_attrs);
1758         torture_suite_add_simple_test(suite, "dn-attrs", torture_ldb_dn_attrs);
1759         torture_suite_add_simple_test(suite, "dn-extended",
1760                                       torture_ldb_dn_extended);
1761         torture_suite_add_simple_test(suite, "dn-invalid-extended",
1762                                       torture_ldb_dn_invalid_extended);
1763         torture_suite_add_simple_test(suite, "dn", torture_ldb_dn);
1764         torture_suite_add_simple_test(suite, "pack-format-perf",
1765                                       torture_ldb_pack_format_perf);
1766         torture_suite_add_simple_test(suite, "pack-data-v2",
1767                                       torture_ldb_pack_data_v2);
1768         torture_suite_add_simple_test(suite, "pack-data-special-v2",
1769                                       torture_ldb_pack_data_v2_special);
1770         torture_suite_add_simple_test(suite, "unpack-corrupt-v2",
1771                                       torture_ldb_unpack_data_corrupt);
1772
1773         for (i=0; i<2; i++) {
1774                 torture_suite_add_simple_tcase_const(suite,
1775                         talloc_asprintf(mem_ctx, "unpack-data-v%d", i+1),
1776                         torture_ldb_unpack, &bins[i]);
1777                 torture_suite_add_simple_tcase_const(suite,
1778                         talloc_asprintf(mem_ctx, "unpack-data-flags-v%d", i+1),
1779                         torture_ldb_unpack_flags, &bins[i]);
1780                 torture_suite_add_simple_tcase_const(suite,
1781                         talloc_asprintf(mem_ctx, "parse-ldif-v%d", i+1),
1782                         torture_ldb_parse_ldif, &bins[i]);
1783                 torture_suite_add_simple_tcase_const(suite,
1784                         talloc_asprintf(mem_ctx,
1785                                         "unpack-data-and-filter-v%d", i+1),
1786                         torture_ldb_unpack_and_filter, &bins[i]);
1787         }
1788
1789         suite->description = talloc_strdup(suite, "LDB (samba-specific behaviour) tests");
1790
1791         return suite;
1792 }