ldb: Add ldb_unpack_data_only_attr_list_flags()
[Samba.git] / source4 / torture / ldb / ldb.c
blobf7f04db0242f24c1ae85ae8e3cc3aac651a2d77d
1 /*
2 Unix SMB/CIFS implementation.
4 Test LDB attribute functions
6 Copyright (C) Andrew Bartlet <abartlet@samba.org> 2008
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.
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.
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/>.
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"
35 static const char *sid = "S-1-5-21-4177067393-1453636373-93818737";
36 static const char *hex_sid = "01040000000000051500000081fdf8f815bba456718f9705";
37 static const char *guid = "975ac5fa-35d9-431d-b86a-845bcd34fff9";
38 static const char *guid2 = "{975ac5fa-35d9-431d-b86a-845bcd34fff9}";
39 static const char *hex_guid = "fac55a97d9351d43b86a845bcd34fff9";
41 static const char *prefix_map_newline = "2:1.2.840.113556.1.2\n5:2.16.840.1.101.2.2.3";
42 static const char *prefix_map_semi = "2:1.2.840.113556.1.2;5:2.16.840.1.101.2.2.3";
44 /**
45 * This is the hex code derived from the tdbdump for
46 * "st/ad_dc/private/sam.ldb.d/DC=ADDC,DC=SAMBA,DC=EXAMPLE,DC=COM.ldb"
47 * key "DN=CN=DDA1D01D-4BD7-4C49-A184-46F9241B560E,CN=OPERATIONS,CN=DOMAINUPDATES,CN=SYSTEM,DC=ADDC,DC=SAMBA,DC=EXAMPLE,DC=COM\00"
48 * -- adrianc
51 static const uint8_t dda1d01d_bin[] = {
52 0x67, 0x19, 0x01, 0x26, 0x0d, 0x00, 0x00, 0x00, 0x43, 0x4e, 0x3d, 0x64, 0x64, 0x61, 0x31, 0x64,
53 0x30, 0x31, 0x64, 0x2d, 0x34, 0x62, 0x64, 0x37, 0x2d, 0x34, 0x63, 0x34, 0x39, 0x2d, 0x61, 0x31,
54 0x38, 0x34, 0x2d, 0x34, 0x36, 0x66, 0x39, 0x32, 0x34, 0x31, 0x62, 0x35, 0x36, 0x30, 0x65, 0x2c,
55 0x43, 0x4e, 0x3d, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2c, 0x43, 0x4e,
56 0x3d, 0x44, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x73, 0x2c, 0x43,
57 0x4e, 0x3d, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2c, 0x44, 0x43, 0x3d, 0x61, 0x64, 0x64, 0x63,
58 0x2c, 0x44, 0x43, 0x3d, 0x73, 0x61, 0x6d, 0x62, 0x61, 0x2c, 0x44, 0x43, 0x3d, 0x65, 0x78, 0x61,
59 0x6d, 0x70, 0x6c, 0x65, 0x2c, 0x44, 0x43, 0x3d, 0x63, 0x6f, 0x6d, 0x00, 0x6f, 0x62, 0x6a, 0x65,
60 0x63, 0x74, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
61 0x74, 0x6f, 0x70, 0x00, 0x09, 0x00, 0x00, 0x00, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65,
62 0x72, 0x00, 0x63, 0x6e, 0x00, 0x01, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x64, 0x64, 0x61,
63 0x31, 0x64, 0x30, 0x31, 0x64, 0x2d, 0x34, 0x62, 0x64, 0x37, 0x2d, 0x34, 0x63, 0x34, 0x39, 0x2d,
64 0x61, 0x31, 0x38, 0x34, 0x2d, 0x34, 0x36, 0x66, 0x39, 0x32, 0x34, 0x31, 0x62, 0x35, 0x36, 0x30,
65 0x65, 0x00, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x54, 0x79, 0x70, 0x65, 0x00, 0x01,
66 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x34, 0x00, 0x77, 0x68, 0x65, 0x6e, 0x43, 0x72, 0x65,
67 0x61, 0x74, 0x65, 0x64, 0x00, 0x01, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x32, 0x30, 0x31,
68 0x35, 0x30, 0x37, 0x30, 0x38, 0x32, 0x32, 0x34, 0x33, 0x31, 0x30, 0x2e, 0x30, 0x5a, 0x00, 0x77,
69 0x68, 0x65, 0x6e, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x64, 0x00, 0x01, 0x00, 0x00, 0x00, 0x11,
70 0x00, 0x00, 0x00, 0x32, 0x30, 0x31, 0x35, 0x30, 0x37, 0x30, 0x38, 0x32, 0x32, 0x34, 0x33, 0x31,
71 0x30, 0x2e, 0x30, 0x5a, 0x00, 0x75, 0x53, 0x4e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x00,
72 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x33, 0x34, 0x36, 0x37, 0x00, 0x75, 0x53, 0x4e,
73 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x64, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
74 0x33, 0x34, 0x36, 0x37, 0x00, 0x73, 0x68, 0x6f, 0x77, 0x49, 0x6e, 0x41, 0x64, 0x76, 0x61, 0x6e,
75 0x63, 0x65, 0x64, 0x56, 0x69, 0x65, 0x77, 0x4f, 0x6e, 0x6c, 0x79, 0x00, 0x01, 0x00, 0x00, 0x00,
76 0x04, 0x00, 0x00, 0x00, 0x54, 0x52, 0x55, 0x45, 0x00, 0x6e, 0x54, 0x53, 0x65, 0x63, 0x75, 0x72,
77 0x69, 0x74, 0x79, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0x00, 0x01, 0x00,
78 0x00, 0x00, 0x18, 0x05, 0x00, 0x00, 0x01, 0x00, 0x17, 0x8c, 0x14, 0x00, 0x00, 0x00, 0x30, 0x00,
79 0x00, 0x00, 0x4c, 0x00, 0x00, 0x00, 0xc4, 0x00, 0x00, 0x00, 0x01, 0x05, 0x00, 0x00, 0x00, 0x00,
80 0x00, 0x05, 0x15, 0x00, 0x00, 0x00, 0x9a, 0xbd, 0x91, 0x7d, 0xd5, 0xe0, 0x11, 0x3c, 0x6e, 0x5e,
81 0x1a, 0x4b, 0x00, 0x02, 0x00, 0x00, 0x01, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x15, 0x00,
82 0x00, 0x00, 0x9a, 0xbd, 0x91, 0x7d, 0xd5, 0xe0, 0x11, 0x3c, 0x6e, 0x5e, 0x1a, 0x4b, 0x00, 0x02,
83 0x00, 0x00, 0x04, 0x00, 0x78, 0x00, 0x02, 0x00, 0x00, 0x00, 0x07, 0x5a, 0x38, 0x00, 0x20, 0x00,
84 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xbe, 0x3b, 0x0e, 0xf3, 0xf0, 0x9f, 0xd1, 0x11, 0xb6, 0x03,
85 0x00, 0x00, 0xf8, 0x03, 0x67, 0xc1, 0xa5, 0x7a, 0x96, 0xbf, 0xe6, 0x0d, 0xd0, 0x11, 0xa2, 0x85,
86 0x00, 0xaa, 0x00, 0x30, 0x49, 0xe2, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
87 0x00, 0x00, 0x07, 0x5a, 0x38, 0x00, 0x20, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xbf, 0x3b,
88 0x0e, 0xf3, 0xf0, 0x9f, 0xd1, 0x11, 0xb6, 0x03, 0x00, 0x00, 0xf8, 0x03, 0x67, 0xc1, 0xa5, 0x7a,
89 0x96, 0xbf, 0xe6, 0x0d, 0xd0, 0x11, 0xa2, 0x85, 0x00, 0xaa, 0x00, 0x30, 0x49, 0xe2, 0x01, 0x01,
90 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x54, 0x04, 0x17, 0x00,
91 0x00, 0x00, 0x00, 0x00, 0x24, 0x00, 0xff, 0x01, 0x0f, 0x00, 0x01, 0x05, 0x00, 0x00, 0x00, 0x00,
92 0x00, 0x05, 0x15, 0x00, 0x00, 0x00, 0x9a, 0xbd, 0x91, 0x7d, 0xd5, 0xe0, 0x11, 0x3c, 0x6e, 0x5e,
93 0x1a, 0x4b, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0xff, 0x01, 0x0f, 0x00, 0x01, 0x01,
94 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x94, 0x00,
95 0x02, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x0b, 0x00, 0x00, 0x00, 0x05, 0x1a,
96 0x3c, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x42, 0x16, 0x4c, 0xc0, 0x20,
97 0xd0, 0x11, 0xa7, 0x68, 0x00, 0xaa, 0x00, 0x6e, 0x05, 0x29, 0x14, 0xcc, 0x28, 0x48, 0x37, 0x14,
98 0xbc, 0x45, 0x9b, 0x07, 0xad, 0x6f, 0x01, 0x5e, 0x5f, 0x28, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00,
99 0x00, 0x05, 0x20, 0x00, 0x00, 0x00, 0x2a, 0x02, 0x00, 0x00, 0x05, 0x1a, 0x3c, 0x00, 0x10, 0x00,
100 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x42, 0x16, 0x4c, 0xc0, 0x20, 0xd0, 0x11, 0xa7, 0x68,
101 0x00, 0xaa, 0x00, 0x6e, 0x05, 0x29, 0xba, 0x7a, 0x96, 0xbf, 0xe6, 0x0d, 0xd0, 0x11, 0xa2, 0x85,
102 0x00, 0xaa, 0x00, 0x30, 0x49, 0xe2, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x20, 0x00,
103 0x00, 0x00, 0x2a, 0x02, 0x00, 0x00, 0x05, 0x1a, 0x3c, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x00,
104 0x00, 0x00, 0x10, 0x20, 0x20, 0x5f, 0xa5, 0x79, 0xd0, 0x11, 0x90, 0x20, 0x00, 0xc0, 0x4f, 0xc2,
105 0xd4, 0xcf, 0x14, 0xcc, 0x28, 0x48, 0x37, 0x14, 0xbc, 0x45, 0x9b, 0x07, 0xad, 0x6f, 0x01, 0x5e,
106 0x5f, 0x28, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x20, 0x00, 0x00, 0x00, 0x2a, 0x02,
107 0x00, 0x00, 0x05, 0x1a, 0x3c, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, 0x20,
108 0x20, 0x5f, 0xa5, 0x79, 0xd0, 0x11, 0x90, 0x20, 0x00, 0xc0, 0x4f, 0xc2, 0xd4, 0xcf, 0xba, 0x7a,
109 0x96, 0xbf, 0xe6, 0x0d, 0xd0, 0x11, 0xa2, 0x85, 0x00, 0xaa, 0x00, 0x30, 0x49, 0xe2, 0x01, 0x02,
110 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x20, 0x00, 0x00, 0x00, 0x2a, 0x02, 0x00, 0x00, 0x05, 0x1a,
111 0x3c, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x40, 0xc2, 0x0a, 0xbc, 0xa9, 0x79,
112 0xd0, 0x11, 0x90, 0x20, 0x00, 0xc0, 0x4f, 0xc2, 0xd4, 0xcf, 0x14, 0xcc, 0x28, 0x48, 0x37, 0x14,
113 0xbc, 0x45, 0x9b, 0x07, 0xad, 0x6f, 0x01, 0x5e, 0x5f, 0x28, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00,
114 0x00, 0x05, 0x20, 0x00, 0x00, 0x00, 0x2a, 0x02, 0x00, 0x00, 0x05, 0x1a, 0x3c, 0x00, 0x10, 0x00,
115 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x40, 0xc2, 0x0a, 0xbc, 0xa9, 0x79, 0xd0, 0x11, 0x90, 0x20,
116 0x00, 0xc0, 0x4f, 0xc2, 0xd4, 0xcf, 0xba, 0x7a, 0x96, 0xbf, 0xe6, 0x0d, 0xd0, 0x11, 0xa2, 0x85,
117 0x00, 0xaa, 0x00, 0x30, 0x49, 0xe2, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x20, 0x00,
118 0x00, 0x00, 0x2a, 0x02, 0x00, 0x00, 0x05, 0x1a, 0x3c, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x00,
119 0x00, 0x00, 0x42, 0x2f, 0xba, 0x59, 0xa2, 0x79, 0xd0, 0x11, 0x90, 0x20, 0x00, 0xc0, 0x4f, 0xc2,
120 0xd3, 0xcf, 0x14, 0xcc, 0x28, 0x48, 0x37, 0x14, 0xbc, 0x45, 0x9b, 0x07, 0xad, 0x6f, 0x01, 0x5e,
121 0x5f, 0x28, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x20, 0x00, 0x00, 0x00, 0x2a, 0x02,
122 0x00, 0x00, 0x05, 0x1a, 0x3c, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x42, 0x2f,
123 0xba, 0x59, 0xa2, 0x79, 0xd0, 0x11, 0x90, 0x20, 0x00, 0xc0, 0x4f, 0xc2, 0xd3, 0xcf, 0xba, 0x7a,
124 0x96, 0xbf, 0xe6, 0x0d, 0xd0, 0x11, 0xa2, 0x85, 0x00, 0xaa, 0x00, 0x30, 0x49, 0xe2, 0x01, 0x02,
125 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x20, 0x00, 0x00, 0x00, 0x2a, 0x02, 0x00, 0x00, 0x05, 0x1a,
126 0x3c, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xf8, 0x88, 0x70, 0x03, 0xe1, 0x0a,
127 0xd2, 0x11, 0xb4, 0x22, 0x00, 0xa0, 0xc9, 0x68, 0xf9, 0x39, 0x14, 0xcc, 0x28, 0x48, 0x37, 0x14,
128 0xbc, 0x45, 0x9b, 0x07, 0xad, 0x6f, 0x01, 0x5e, 0x5f, 0x28, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00,
129 0x00, 0x05, 0x20, 0x00, 0x00, 0x00, 0x2a, 0x02, 0x00, 0x00, 0x05, 0x1a, 0x3c, 0x00, 0x10, 0x00,
130 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xf8, 0x88, 0x70, 0x03, 0xe1, 0x0a, 0xd2, 0x11, 0xb4, 0x22,
131 0x00, 0xa0, 0xc9, 0x68, 0xf9, 0x39, 0xba, 0x7a, 0x96, 0xbf, 0xe6, 0x0d, 0xd0, 0x11, 0xa2, 0x85,
132 0x00, 0xaa, 0x00, 0x30, 0x49, 0xe2, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x20, 0x00,
133 0x00, 0x00, 0x2a, 0x02, 0x00, 0x00, 0x05, 0x1a, 0x38, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x00,
134 0x00, 0x00, 0x6d, 0x9e, 0xc6, 0xb7, 0xc7, 0x2c, 0xd2, 0x11, 0x85, 0x4e, 0x00, 0xa0, 0xc9, 0x83,
135 0xf6, 0x08, 0x86, 0x7a, 0x96, 0xbf, 0xe6, 0x0d, 0xd0, 0x11, 0xa2, 0x85, 0x00, 0xaa, 0x00, 0x30,
136 0x49, 0xe2, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x09, 0x00, 0x00, 0x00, 0x05, 0x1a,
137 0x38, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x6d, 0x9e, 0xc6, 0xb7, 0xc7, 0x2c,
138 0xd2, 0x11, 0x85, 0x4e, 0x00, 0xa0, 0xc9, 0x83, 0xf6, 0x08, 0x9c, 0x7a, 0x96, 0xbf, 0xe6, 0x0d,
139 0xd0, 0x11, 0xa2, 0x85, 0x00, 0xaa, 0x00, 0x30, 0x49, 0xe2, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
140 0x00, 0x05, 0x09, 0x00, 0x00, 0x00, 0x05, 0x1a, 0x38, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x00,
141 0x00, 0x00, 0x6d, 0x9e, 0xc6, 0xb7, 0xc7, 0x2c, 0xd2, 0x11, 0x85, 0x4e, 0x00, 0xa0, 0xc9, 0x83,
142 0xf6, 0x08, 0xba, 0x7a, 0x96, 0xbf, 0xe6, 0x0d, 0xd0, 0x11, 0xa2, 0x85, 0x00, 0xaa, 0x00, 0x30,
143 0x49, 0xe2, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x09, 0x00, 0x00, 0x00, 0x05, 0x1a,
144 0x2c, 0x00, 0x94, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x14, 0xcc, 0x28, 0x48, 0x37, 0x14,
145 0xbc, 0x45, 0x9b, 0x07, 0xad, 0x6f, 0x01, 0x5e, 0x5f, 0x28, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00,
146 0x00, 0x05, 0x20, 0x00, 0x00, 0x00, 0x2a, 0x02, 0x00, 0x00, 0x05, 0x1a, 0x2c, 0x00, 0x94, 0x00,
147 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x9c, 0x7a, 0x96, 0xbf, 0xe6, 0x0d, 0xd0, 0x11, 0xa2, 0x85,
148 0x00, 0xaa, 0x00, 0x30, 0x49, 0xe2, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x20, 0x00,
149 0x00, 0x00, 0x2a, 0x02, 0x00, 0x00, 0x05, 0x1a, 0x2c, 0x00, 0x94, 0x00, 0x02, 0x00, 0x02, 0x00,
150 0x00, 0x00, 0xba, 0x7a, 0x96, 0xbf, 0xe6, 0x0d, 0xd0, 0x11, 0xa2, 0x85, 0x00, 0xaa, 0x00, 0x30,
151 0x49, 0xe2, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x20, 0x00, 0x00, 0x00, 0x2a, 0x02,
152 0x00, 0x00, 0x05, 0x12, 0x28, 0x00, 0x30, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xde, 0x47,
153 0xe6, 0x91, 0x6f, 0xd9, 0x70, 0x4b, 0x95, 0x57, 0xd6, 0x3f, 0xf4, 0xf3, 0xcc, 0xd8, 0x01, 0x01,
154 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x12, 0x24, 0x00, 0xff, 0x01,
155 0x0f, 0x00, 0x01, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x15, 0x00, 0x00, 0x00, 0x9a, 0xbd,
156 0x91, 0x7d, 0xd5, 0xe0, 0x11, 0x3c, 0x6e, 0x5e, 0x1a, 0x4b, 0x07, 0x02, 0x00, 0x00, 0x00, 0x12,
157 0x18, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x20, 0x00,
158 0x00, 0x00, 0x2a, 0x02, 0x00, 0x00, 0x00, 0x12, 0x18, 0x00, 0xbd, 0x01, 0x0f, 0x00, 0x01, 0x02,
159 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x20, 0x00, 0x00, 0x00, 0x20, 0x02, 0x00, 0x00, 0x00, 0x6e,
160 0x61, 0x6d, 0x65, 0x00, 0x01, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x64, 0x64, 0x61, 0x31,
161 0x64, 0x30, 0x31, 0x64, 0x2d, 0x34, 0x62, 0x64, 0x37, 0x2d, 0x34, 0x63, 0x34, 0x39, 0x2d, 0x61,
162 0x31, 0x38, 0x34, 0x2d, 0x34, 0x36, 0x66, 0x39, 0x32, 0x34, 0x31, 0x62, 0x35, 0x36, 0x30, 0x65,
163 0x00, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x47, 0x55, 0x49, 0x44, 0x00, 0x01, 0x00, 0x00, 0x00,
164 0x10, 0x00, 0x00, 0x00, 0x57, 0x93, 0x1e, 0x29, 0x25, 0x49, 0xe5, 0x40, 0x9d, 0x98, 0x36, 0x07,
165 0x11, 0x9e, 0xbd, 0xe5, 0x00, 0x72, 0x65, 0x70, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74,
166 0x79, 0x4d, 0x65, 0x74, 0x61, 0x44, 0x61, 0x74, 0x61, 0x00, 0x01, 0x00, 0x00, 0x00, 0x90, 0x01,
167 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
168 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x7e, 0x38, 0xae, 0x0b, 0x03, 0x00,
169 0x00, 0x00, 0x9d, 0xcd, 0xcd, 0x57, 0xee, 0x58, 0x6e, 0x4e, 0x96, 0x99, 0xcc, 0x7d, 0xe1, 0x96,
170 0xf1, 0x05, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00,
171 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x7e, 0x38, 0xae, 0x0b, 0x03, 0x00,
172 0x00, 0x00, 0x9d, 0xcd, 0xcd, 0x57, 0xee, 0x58, 0x6e, 0x4e, 0x96, 0x99, 0xcc, 0x7d, 0xe1, 0x96,
173 0xf1, 0x05, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00,
174 0x00, 0x00, 0x02, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x7e, 0x38, 0xae, 0x0b, 0x03, 0x00,
175 0x00, 0x00, 0x9d, 0xcd, 0xcd, 0x57, 0xee, 0x58, 0x6e, 0x4e, 0x96, 0x99, 0xcc, 0x7d, 0xe1, 0x96,
176 0xf1, 0x05, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00,
177 0x00, 0x00, 0xa9, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x7e, 0x38, 0xae, 0x0b, 0x03, 0x00,
178 0x00, 0x00, 0x9d, 0xcd, 0xcd, 0x57, 0xee, 0x58, 0x6e, 0x4e, 0x96, 0x99, 0xcc, 0x7d, 0xe1, 0x96,
179 0xf1, 0x05, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00,
180 0x00, 0x00, 0x19, 0x01, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x7e, 0x38, 0xae, 0x0b, 0x03, 0x00,
181 0x00, 0x00, 0x9d, 0xcd, 0xcd, 0x57, 0xee, 0x58, 0x6e, 0x4e, 0x96, 0x99, 0xcc, 0x7d, 0xe1, 0x96,
182 0xf1, 0x05, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00,
183 0x00, 0x00, 0x01, 0x00, 0x09, 0x00, 0x01, 0x00, 0x00, 0x00, 0x7e, 0x38, 0xae, 0x0b, 0x03, 0x00,
184 0x00, 0x00, 0x9d, 0xcd, 0xcd, 0x57, 0xee, 0x58, 0x6e, 0x4e, 0x96, 0x99, 0xcc, 0x7d, 0xe1, 0x96,
185 0xf1, 0x05, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00,
186 0x00, 0x00, 0x0e, 0x03, 0x09, 0x00, 0x01, 0x00, 0x00, 0x00, 0x7e, 0x38, 0xae, 0x0b, 0x03, 0x00,
187 0x00, 0x00, 0x9d, 0xcd, 0xcd, 0x57, 0xee, 0x58, 0x6e, 0x4e, 0x96, 0x99, 0xcc, 0x7d, 0xe1, 0x96,
188 0xf1, 0x05, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00,
189 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x7e, 0x38, 0xae, 0x0b, 0x03, 0x00,
190 0x00, 0x00, 0x9d, 0xcd, 0xcd, 0x57, 0xee, 0x58, 0x6e, 0x4e, 0x96, 0x99, 0xcc, 0x7d, 0xe1, 0x96,
191 0xf1, 0x05, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8b, 0x0d, 0x00, 0x00, 0x00, 0x00,
192 0x00, 0x00, 0x00, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72,
193 0x79, 0x00, 0x01, 0x00, 0x00, 0x00, 0x76, 0x00, 0x00, 0x00, 0x3c, 0x47, 0x55, 0x49, 0x44, 0x3d,
194 0x35, 0x32, 0x34, 0x32, 0x39, 0x30, 0x33, 0x38, 0x2d, 0x65, 0x34, 0x33, 0x35, 0x2d, 0x34, 0x66,
195 0x65, 0x33, 0x2d, 0x39, 0x36, 0x34, 0x65, 0x2d, 0x38, 0x30, 0x64, 0x61, 0x31, 0x35, 0x34, 0x39,
196 0x39, 0x63, 0x39, 0x63, 0x3e, 0x3b, 0x43, 0x4e, 0x3d, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e,
197 0x65, 0x72, 0x2c, 0x43, 0x4e, 0x3d, 0x53, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x2c, 0x43, 0x4e, 0x3d,
198 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2c, 0x44, 0x43,
199 0x3d, 0x61, 0x64, 0x64, 0x63, 0x2c, 0x44, 0x43, 0x3d, 0x73, 0x61, 0x6d, 0x62, 0x61, 0x2c, 0x44,
200 0x43, 0x3d, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2c, 0x44, 0x43, 0x3d, 0x63, 0x6f, 0x6d,
201 0x00
204 static const char dda1d01d_ldif[] = ""
205 "dn: CN=dda1d01d-4bd7-4c49-a184-46f9241b560e,CN=Operations,CN=DomainUpdates,CN=System,DC=addc,DC=samba,DC=example,DC=com\n"
206 "objectClass: top\n"
207 "objectClass: container\n"
208 "cn: dda1d01d-4bd7-4c49-a184-46f9241b560e\n"
209 "instanceType: 4\n"
210 "whenCreated: 20150708224310.0Z\n"
211 "whenChanged: 20150708224310.0Z\n"
212 "uSNCreated: 3467\n"
213 "uSNChanged: 3467\n"
214 "showInAdvancedViewOnly: TRUE\n"
215 "nTSecurityDescriptor: O:S-1-5-21-2106703258-1007804629-1260019310-512G:S-1-5-2\n"
216 " 1-2106703258-1007804629-1260019310-512D:AI(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;S-\n"
217 " 1-5-21-2106703258-1007804629-1260019310-512)(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;\n"
218 " SY)(A;;RPLCLORC;;;AU)(OA;CIIOID;RP;4c164200-20c0-11d0-a768-00aa006e0529;4828c\n"
219 " c14-1437-45bc-9b07-ad6f015e5f28;RU)(OA;CIIOID;RP;4c164200-20c0-11d0-a768-00aa\n"
220 " 006e0529;bf967aba-0de6-11d0-a285-00aa003049e2;RU)(OA;CIIOID;RP;5f202010-79a5-\n"
221 " 11d0-9020-00c04fc2d4cf;4828cc14-1437-45bc-9b07-ad6f015e5f28;RU)(OA;CIIOID;RP;\n"
222 " 5f202010-79a5-11d0-9020-00c04fc2d4cf;bf967aba-0de6-11d0-a285-00aa003049e2;RU)\n"
223 " (OA;CIIOID;RP;bc0ac240-79a9-11d0-9020-00c04fc2d4cf;4828cc14-1437-45bc-9b07-ad\n"
224 " 6f015e5f28;RU)(OA;CIIOID;RP;bc0ac240-79a9-11d0-9020-00c04fc2d4cf;bf967aba-0de\n"
225 " 6-11d0-a285-00aa003049e2;RU)(OA;CIIOID;RP;59ba2f42-79a2-11d0-9020-00c04fc2d3c\n"
226 " f;4828cc14-1437-45bc-9b07-ad6f015e5f28;RU)(OA;CIIOID;RP;59ba2f42-79a2-11d0-90\n"
227 " 20-00c04fc2d3cf;bf967aba-0de6-11d0-a285-00aa003049e2;RU)(OA;CIIOID;RP;037088f\n"
228 " 8-0ae1-11d2-b422-00a0c968f939;4828cc14-1437-45bc-9b07-ad6f015e5f28;RU)(OA;CII\n"
229 " OID;RP;037088f8-0ae1-11d2-b422-00a0c968f939;bf967aba-0de6-11d0-a285-00aa00304\n"
230 " 9e2;RU)(OA;CIIOID;RP;b7c69e6d-2cc7-11d2-854e-00a0c983f608;bf967a86-0de6-11d0-\n"
231 " a285-00aa003049e2;ED)(OA;CIIOID;RP;b7c69e6d-2cc7-11d2-854e-00a0c983f608;bf967\n"
232 " a9c-0de6-11d0-a285-00aa003049e2;ED)(OA;CIIOID;RP;b7c69e6d-2cc7-11d2-854e-00a0\n"
233 " c983f608;bf967aba-0de6-11d0-a285-00aa003049e2;ED)(OA;CIIOID;RPLCLORC;;4828cc1\n"
234 " 4-1437-45bc-9b07-ad6f015e5f28;RU)(OA;CIIOID;RPLCLORC;;bf967a9c-0de6-11d0-a285\n"
235 " -00aa003049e2;RU)(OA;CIIOID;RPLCLORC;;bf967aba-0de6-11d0-a285-00aa003049e2;RU\n"
236 " )(OA;CIID;RPWPCR;91e647de-d96f-4b70-9557-d63ff4f3ccd8;;PS)(A;CIID;RPWPCRCCDCL\n"
237 " CLORCWOWDSDDTSW;;;S-1-5-21-2106703258-1007804629-1260019310-519)(A;CIID;LC;;;\n"
238 " RU)(A;CIID;RPWPCRCCLCLORCWOWDSDSW;;;BA)S:AI(OU;CIIOIDSA;WP;f30e3bbe-9ff0-11d1\n"
239 " -b603-0000f80367c1;bf967aa5-0de6-11d0-a285-00aa003049e2;WD)(OU;CIIOIDSA;WP;f3\n"
240 " 0e3bbf-9ff0-11d1-b603-0000f80367c1;bf967aa5-0de6-11d0-a285-00aa003049e2;WD)\n"
241 "name: dda1d01d-4bd7-4c49-a184-46f9241b560e\n"
242 "objectGUID: 291e9357-4925-40e5-9d98-3607119ebde5\n"
243 "replPropertyMetaData:: AQAAAAAAAAAIAAAAAAAAAAAAAAABAAAAfjiuCwMAAACdzc1X7lhuTpa\n"
244 " ZzH3hlvEFiw0AAAAAAACLDQAAAAAAAAEAAgABAAAAfjiuCwMAAACdzc1X7lhuTpaZzH3hlvEFiw0A\n"
245 " AAAAAACLDQAAAAAAAAIAAgABAAAAfjiuCwMAAACdzc1X7lhuTpaZzH3hlvEFiw0AAAAAAACLDQAAA\n"
246 " AAAAKkAAgABAAAAfjiuCwMAAACdzc1X7lhuTpaZzH3hlvEFiw0AAAAAAACLDQAAAAAAABkBAgABAA\n"
247 " AAfjiuCwMAAACdzc1X7lhuTpaZzH3hlvEFiw0AAAAAAACLDQAAAAAAAAEACQABAAAAfjiuCwMAAAC\n"
248 " dzc1X7lhuTpaZzH3hlvEFiw0AAAAAAACLDQAAAAAAAA4DCQABAAAAfjiuCwMAAACdzc1X7lhuTpaZ\n"
249 " zH3hlvEFiw0AAAAAAACLDQAAAAAAAAMAAAABAAAAfjiuCwMAAACdzc1X7lhuTpaZzH3hlvEFiw0AA\n"
250 " AAAAACLDQAAAAAAAA==\n"
251 "objectCategory: <GUID=52429038-e435-4fe3-964e-80da15499c9c>;CN=Container,CN=Sc\n"
252 " hema,CN=Configuration,DC=addc,DC=samba,DC=example,DC=com\n\n";
254 static const char *dda1d01d_ldif_reduced = ""
255 "dn: CN=dda1d01d-4bd7-4c49-a184-46f9241b560e,CN=Operations,CN=DomainUpdates,CN=System,DC=addc,DC=samba,DC=example,DC=com\n"
256 "objectClass: top\n"
257 "objectClass: container\n"
258 "instanceType: 4\n"
259 "whenChanged: 20150708224310.0Z\n"
260 "uSNCreated: 3467\n"
261 "showInAdvancedViewOnly: TRUE\n"
262 "name: dda1d01d-4bd7-4c49-a184-46f9241b560e\n\n";
264 static bool torture_ldb_attrs(struct torture_context *torture)
266 TALLOC_CTX *mem_ctx = talloc_new(torture);
267 struct ldb_context *ldb;
268 const struct ldb_schema_attribute *attr;
269 struct ldb_val string_sid_blob, binary_sid_blob;
270 struct ldb_val string_guid_blob, string_guid_blob2, binary_guid_blob;
271 struct ldb_val string_prefix_map_newline_blob, string_prefix_map_semi_blob, string_prefix_map_blob;
272 struct ldb_val prefix_map_blob;
274 DATA_BLOB sid_blob = strhex_to_data_blob(mem_ctx, hex_sid);
275 DATA_BLOB guid_blob = strhex_to_data_blob(mem_ctx, hex_guid);
277 torture_assert(torture,
278 ldb = ldb_init(mem_ctx, torture->ev),
279 "Failed to init ldb");
281 torture_assert_int_equal(torture,
282 ldb_register_samba_handlers(ldb), LDB_SUCCESS,
283 "Failed to register Samba handlers");
285 ldb_set_utf8_fns(ldb, NULL, wrap_casefold);
287 /* Test SID behaviour */
288 torture_assert(torture, attr = ldb_schema_attribute_by_name(ldb, "objectSid"),
289 "Failed to get objectSid schema attribute");
291 string_sid_blob = data_blob_string_const(sid);
293 torture_assert_int_equal(torture,
294 attr->syntax->ldif_read_fn(ldb, mem_ctx,
295 &string_sid_blob, &binary_sid_blob), 0,
296 "Failed to parse string SID");
298 torture_assert_data_blob_equal(torture, binary_sid_blob, sid_blob,
299 "Read SID into blob form failed");
301 torture_assert_int_equal(torture,
302 attr->syntax->ldif_read_fn(ldb, mem_ctx,
303 &sid_blob, &binary_sid_blob), -1,
304 "Should have failed to parse binary SID");
306 torture_assert_int_equal(torture,
307 attr->syntax->ldif_write_fn(ldb, mem_ctx, &binary_sid_blob, &string_sid_blob), 0,
308 "Failed to parse binary SID");
310 torture_assert_data_blob_equal(torture,
311 string_sid_blob, data_blob_string_const(sid),
312 "Write SID into string form failed");
314 torture_assert_int_equal(torture,
315 attr->syntax->comparison_fn(ldb, mem_ctx, &binary_sid_blob, &string_sid_blob), 0,
316 "Failed to compare binary and string SID");
318 torture_assert_int_equal(torture,
319 attr->syntax->comparison_fn(ldb, mem_ctx, &string_sid_blob, &binary_sid_blob), 0,
320 "Failed to compare string and binary binary SID");
322 torture_assert_int_equal(torture,
323 attr->syntax->comparison_fn(ldb, mem_ctx, &string_sid_blob, &string_sid_blob), 0,
324 "Failed to compare string and string SID");
326 torture_assert_int_equal(torture,
327 attr->syntax->comparison_fn(ldb, mem_ctx, &binary_sid_blob, &binary_sid_blob), 0,
328 "Failed to compare binary and binary SID");
330 torture_assert(torture, attr->syntax->comparison_fn(ldb, mem_ctx, &guid_blob, &binary_sid_blob) != 0,
331 "Failed to distinguish binary GUID and binary SID");
334 /* Test GUID behaviour */
335 torture_assert(torture, attr = ldb_schema_attribute_by_name(ldb, "objectGUID"),
336 "Failed to get objectGUID schema attribute");
338 string_guid_blob = data_blob_string_const(guid);
340 torture_assert_int_equal(torture,
341 attr->syntax->ldif_read_fn(ldb, mem_ctx,
342 &string_guid_blob, &binary_guid_blob), 0,
343 "Failed to parse string GUID");
345 torture_assert_data_blob_equal(torture, binary_guid_blob, guid_blob,
346 "Read GUID into blob form failed");
348 string_guid_blob2 = data_blob_string_const(guid2);
350 torture_assert_int_equal(torture,
351 attr->syntax->ldif_read_fn(ldb, mem_ctx,
352 &string_guid_blob2, &binary_guid_blob), 0,
353 "Failed to parse string GUID");
355 torture_assert_data_blob_equal(torture, binary_guid_blob, guid_blob,
356 "Read GUID into blob form failed");
358 torture_assert_int_equal(torture,
359 attr->syntax->ldif_read_fn(ldb, mem_ctx,
360 &guid_blob, &binary_guid_blob), 0,
361 "Failed to parse binary GUID");
363 torture_assert_data_blob_equal(torture, binary_guid_blob, guid_blob,
364 "Read GUID into blob form failed");
366 torture_assert_int_equal(torture,
367 attr->syntax->ldif_write_fn(ldb, mem_ctx, &binary_guid_blob, &string_guid_blob), 0,
368 "Failed to print binary GUID as string");
370 torture_assert_data_blob_equal(torture, string_sid_blob, data_blob_string_const(sid),
371 "Write SID into string form failed");
373 torture_assert_int_equal(torture,
374 attr->syntax->comparison_fn(ldb, mem_ctx, &binary_guid_blob, &string_guid_blob), 0,
375 "Failed to compare binary and string GUID");
377 torture_assert_int_equal(torture,
378 attr->syntax->comparison_fn(ldb, mem_ctx, &string_guid_blob, &binary_guid_blob), 0,
379 "Failed to compare string and binary binary GUID");
381 torture_assert_int_equal(torture,
382 attr->syntax->comparison_fn(ldb, mem_ctx, &string_guid_blob, &string_guid_blob), 0,
383 "Failed to compare string and string GUID");
385 torture_assert_int_equal(torture,
386 attr->syntax->comparison_fn(ldb, mem_ctx, &binary_guid_blob, &binary_guid_blob), 0,
387 "Failed to compare binary and binary GUID");
389 string_prefix_map_newline_blob = data_blob_string_const(prefix_map_newline);
391 string_prefix_map_semi_blob = data_blob_string_const(prefix_map_semi);
393 /* Test prefixMap behaviour */
394 torture_assert(torture, attr = ldb_schema_attribute_by_name(ldb, "prefixMap"),
395 "Failed to get prefixMap schema attribute");
397 torture_assert_int_equal(torture,
398 attr->syntax->comparison_fn(ldb, mem_ctx, &string_prefix_map_newline_blob, &string_prefix_map_semi_blob), 0,
399 "Failed to compare prefixMap with newlines and prefixMap with semicolons");
401 torture_assert_int_equal(torture,
402 attr->syntax->ldif_read_fn(ldb, mem_ctx, &string_prefix_map_newline_blob, &prefix_map_blob), 0,
403 "Failed to read prefixMap with newlines");
404 torture_assert_int_equal(torture,
405 attr->syntax->comparison_fn(ldb, mem_ctx, &string_prefix_map_newline_blob, &prefix_map_blob), 0,
406 "Failed to compare prefixMap with newlines and prefixMap binary");
408 torture_assert_int_equal(torture,
409 attr->syntax->ldif_write_fn(ldb, mem_ctx, &prefix_map_blob, &string_prefix_map_blob), 0,
410 "Failed to write prefixMap");
411 torture_assert_int_equal(torture,
412 attr->syntax->comparison_fn(ldb, mem_ctx, &string_prefix_map_blob, &prefix_map_blob), 0,
413 "Failed to compare prefixMap ldif write and prefixMap binary");
415 torture_assert_data_blob_equal(torture, string_prefix_map_blob, string_prefix_map_semi_blob,
416 "Failed to compare prefixMap ldif write and prefixMap binary");
420 talloc_free(mem_ctx);
421 return true;
424 static bool torture_ldb_dn_attrs(struct torture_context *torture)
426 TALLOC_CTX *mem_ctx = talloc_new(torture);
427 struct ldb_context *ldb;
428 const struct ldb_dn_extended_syntax *attr;
429 struct ldb_val string_sid_blob, binary_sid_blob;
430 struct ldb_val string_guid_blob, binary_guid_blob;
431 struct ldb_val hex_sid_blob, hex_guid_blob;
433 DATA_BLOB sid_blob = strhex_to_data_blob(mem_ctx, hex_sid);
434 DATA_BLOB guid_blob = strhex_to_data_blob(mem_ctx, hex_guid);
436 torture_assert(torture,
437 ldb = ldb_init(mem_ctx, torture->ev),
438 "Failed to init ldb");
440 torture_assert_int_equal(torture,
441 ldb_register_samba_handlers(ldb), LDB_SUCCESS,
442 "Failed to register Samba handlers");
444 ldb_set_utf8_fns(ldb, NULL, wrap_casefold);
446 /* Test SID behaviour */
447 torture_assert(torture, attr = ldb_dn_extended_syntax_by_name(ldb, "SID"),
448 "Failed to get SID DN syntax");
450 string_sid_blob = data_blob_string_const(sid);
452 torture_assert_int_equal(torture,
453 attr->read_fn(ldb, mem_ctx,
454 &string_sid_blob, &binary_sid_blob), 0,
455 "Failed to parse string SID");
457 torture_assert_data_blob_equal(torture, binary_sid_blob, sid_blob,
458 "Read SID into blob form failed");
460 hex_sid_blob = data_blob_string_const(hex_sid);
462 torture_assert_int_equal(torture,
463 attr->read_fn(ldb, mem_ctx,
464 &hex_sid_blob, &binary_sid_blob), 0,
465 "Failed to parse HEX SID");
467 torture_assert_data_blob_equal(torture, binary_sid_blob, sid_blob,
468 "Read SID into blob form failed");
470 torture_assert_int_equal(torture,
471 attr->read_fn(ldb, mem_ctx,
472 &sid_blob, &binary_sid_blob), -1,
473 "Should have failed to parse binary SID");
475 torture_assert_int_equal(torture,
476 attr->write_hex_fn(ldb, mem_ctx, &sid_blob, &hex_sid_blob), 0,
477 "Failed to parse binary SID");
479 torture_assert_data_blob_equal(torture,
480 hex_sid_blob, data_blob_string_const(hex_sid),
481 "Write SID into HEX string form failed");
483 torture_assert_int_equal(torture,
484 attr->write_clear_fn(ldb, mem_ctx, &sid_blob, &string_sid_blob), 0,
485 "Failed to parse binary SID");
487 torture_assert_data_blob_equal(torture,
488 string_sid_blob, data_blob_string_const(sid),
489 "Write SID into clear string form failed");
492 /* Test GUID behaviour */
493 torture_assert(torture, attr = ldb_dn_extended_syntax_by_name(ldb, "GUID"),
494 "Failed to get GUID DN syntax");
496 string_guid_blob = data_blob_string_const(guid);
498 torture_assert_int_equal(torture,
499 attr->read_fn(ldb, mem_ctx,
500 &string_guid_blob, &binary_guid_blob), 0,
501 "Failed to parse string GUID");
503 torture_assert_data_blob_equal(torture, binary_guid_blob, guid_blob,
504 "Read GUID into blob form failed");
506 hex_guid_blob = data_blob_string_const(hex_guid);
508 torture_assert_int_equal(torture,
509 attr->read_fn(ldb, mem_ctx,
510 &hex_guid_blob, &binary_guid_blob), 0,
511 "Failed to parse HEX GUID");
513 torture_assert_data_blob_equal(torture, binary_guid_blob, guid_blob,
514 "Read GUID into blob form failed");
516 torture_assert_int_equal(torture,
517 attr->read_fn(ldb, mem_ctx,
518 &guid_blob, &binary_guid_blob), -1,
519 "Should have failed to parse binary GUID");
521 torture_assert_int_equal(torture,
522 attr->write_hex_fn(ldb, mem_ctx, &guid_blob, &hex_guid_blob), 0,
523 "Failed to parse binary GUID");
525 torture_assert_data_blob_equal(torture,
526 hex_guid_blob, data_blob_string_const(hex_guid),
527 "Write GUID into HEX string form failed");
529 torture_assert_int_equal(torture,
530 attr->write_clear_fn(ldb, mem_ctx, &guid_blob, &string_guid_blob), 0,
531 "Failed to parse binary GUID");
533 torture_assert_data_blob_equal(torture,
534 string_guid_blob, data_blob_string_const(guid),
535 "Write GUID into clear string form failed");
539 talloc_free(mem_ctx);
540 return true;
543 static bool torture_ldb_dn_extended(struct torture_context *torture)
545 TALLOC_CTX *mem_ctx = talloc_new(torture);
546 struct ldb_context *ldb;
547 struct ldb_dn *dn, *dn2;
549 DATA_BLOB sid_blob = strhex_to_data_blob(mem_ctx, hex_sid);
550 DATA_BLOB guid_blob = strhex_to_data_blob(mem_ctx, hex_guid);
552 const char *dn_str = "cn=admin,cn=users,dc=samba,dc=org";
554 torture_assert(torture,
555 ldb = ldb_init(mem_ctx, torture->ev),
556 "Failed to init ldb");
558 torture_assert_int_equal(torture,
559 ldb_register_samba_handlers(ldb), LDB_SUCCESS,
560 "Failed to register Samba handlers");
562 ldb_set_utf8_fns(ldb, NULL, wrap_casefold);
564 /* Check behaviour of a normal DN */
565 torture_assert(torture,
566 dn = ldb_dn_new(mem_ctx, ldb, dn_str),
567 "Failed to create a 'normal' DN");
569 torture_assert(torture,
570 ldb_dn_validate(dn),
571 "Failed to validate 'normal' DN");
573 torture_assert(torture, ldb_dn_has_extended(dn) == false,
574 "Should not find plain DN to be 'extended'");
576 torture_assert(torture, ldb_dn_get_extended_component(dn, "SID") == NULL,
577 "Should not find an SID on plain DN");
579 torture_assert(torture, ldb_dn_get_extended_component(dn, "GUID") == NULL,
580 "Should not find an GUID on plain DN");
582 torture_assert(torture, ldb_dn_get_extended_component(dn, "WKGUID") == NULL,
583 "Should not find an WKGUID on plain DN");
585 /* Now make an extended DN */
586 torture_assert(torture,
587 dn = ldb_dn_new_fmt(mem_ctx, ldb, "<GUID=%s>;<SID=%s>;%s",
588 guid, sid, dn_str),
589 "Failed to create an 'extended' DN");
591 torture_assert(torture,
592 dn2 = ldb_dn_copy(mem_ctx, dn),
593 "Failed to copy the 'extended' DN");
594 talloc_free(dn);
595 dn = dn2;
597 torture_assert(torture,
598 ldb_dn_validate(dn),
599 "Failed to validate 'extended' DN");
601 torture_assert(torture, ldb_dn_has_extended(dn) == true,
602 "Should find extended DN to be 'extended'");
604 torture_assert(torture, ldb_dn_get_extended_component(dn, "SID") != NULL,
605 "Should find an SID on extended DN");
607 torture_assert(torture, ldb_dn_get_extended_component(dn, "GUID") != NULL,
608 "Should find an GUID on extended DN");
610 torture_assert_data_blob_equal(torture, *ldb_dn_get_extended_component(dn, "SID"), sid_blob,
611 "Extended DN SID incorect");
613 torture_assert_data_blob_equal(torture, *ldb_dn_get_extended_component(dn, "GUID"), guid_blob,
614 "Extended DN GUID incorect");
616 torture_assert_str_equal(torture, ldb_dn_get_linearized(dn), dn_str,
617 "linearized DN incorrect");
619 torture_assert_str_equal(torture, ldb_dn_get_casefold(dn), strupper_talloc(mem_ctx, dn_str),
620 "casefolded DN incorrect");
622 torture_assert_str_equal(torture, ldb_dn_get_component_name(dn, 0), "cn",
623 "componet zero incorrect");
625 torture_assert_data_blob_equal(torture, *ldb_dn_get_component_val(dn, 0), data_blob_string_const("admin"),
626 "componet zero incorrect");
628 torture_assert_str_equal(torture, ldb_dn_get_extended_linearized(mem_ctx, dn, 1),
629 talloc_asprintf(mem_ctx, "<GUID=%s>;<SID=%s>;%s",
630 guid, sid, dn_str),
631 "Clear extended linearized DN incorrect");
633 torture_assert_str_equal(torture, ldb_dn_get_extended_linearized(mem_ctx, dn, 0),
634 talloc_asprintf(mem_ctx, "<GUID=%s>;<SID=%s>;%s",
635 hex_guid, hex_sid, dn_str),
636 "HEX extended linearized DN incorrect");
638 torture_assert(torture, ldb_dn_remove_child_components(dn, 1) == true,
639 "Failed to remove DN child");
641 torture_assert(torture, ldb_dn_has_extended(dn) == false,
642 "Extended DN flag should be cleared after child element removal");
644 torture_assert(torture, ldb_dn_get_extended_component(dn, "SID") == NULL,
645 "Should not find an SID on DN");
647 torture_assert(torture, ldb_dn_get_extended_component(dn, "GUID") == NULL,
648 "Should not find an GUID on DN");
651 /* TODO: test setting these in the other order, and ensure it still comes out 'GUID first' */
652 torture_assert_int_equal(torture, ldb_dn_set_extended_component(dn, "GUID", &guid_blob), 0,
653 "Failed to set a GUID on DN");
655 torture_assert_int_equal(torture, ldb_dn_set_extended_component(dn, "SID", &sid_blob), 0,
656 "Failed to set a SID on DN");
658 torture_assert_data_blob_equal(torture, *ldb_dn_get_extended_component(dn, "SID"), sid_blob,
659 "Extended DN SID incorect");
661 torture_assert_data_blob_equal(torture, *ldb_dn_get_extended_component(dn, "GUID"), guid_blob,
662 "Extended DN GUID incorect");
664 torture_assert_str_equal(torture, ldb_dn_get_linearized(dn), "cn=users,dc=samba,dc=org",
665 "linearized DN incorrect");
667 torture_assert_str_equal(torture, ldb_dn_get_extended_linearized(mem_ctx, dn, 1),
668 talloc_asprintf(mem_ctx, "<GUID=%s>;<SID=%s>;%s",
669 guid, sid, "cn=users,dc=samba,dc=org"),
670 "Clear extended linearized DN incorrect");
672 torture_assert_str_equal(torture, ldb_dn_get_extended_linearized(mem_ctx, dn, 0),
673 talloc_asprintf(mem_ctx, "<GUID=%s>;<SID=%s>;%s",
674 hex_guid, hex_sid, "cn=users,dc=samba,dc=org"),
675 "HEX extended linearized DN incorrect");
677 /* Now check a 'just GUID' DN (clear format) */
678 torture_assert(torture,
679 dn = ldb_dn_new_fmt(mem_ctx, ldb, "<GUID=%s>",
680 guid),
681 "Failed to create an 'extended' DN");
683 torture_assert(torture,
684 ldb_dn_validate(dn),
685 "Failed to validate 'extended' DN");
687 torture_assert(torture, ldb_dn_has_extended(dn) == true,
688 "Should find extended DN to be 'extended'");
690 torture_assert(torture, ldb_dn_get_extended_component(dn, "SID") == NULL,
691 "Should not find an SID on this DN");
693 torture_assert_int_equal(torture, ldb_dn_get_comp_num(dn), 0,
694 "Should not find an 'normal' componet on this DN");
696 torture_assert(torture, ldb_dn_get_extended_component(dn, "GUID") != NULL,
697 "Should find an GUID on this DN");
699 torture_assert_data_blob_equal(torture, *ldb_dn_get_extended_component(dn, "GUID"), guid_blob,
700 "Extended DN GUID incorect");
702 torture_assert_str_equal(torture, ldb_dn_get_linearized(dn), "",
703 "linearized DN incorrect");
705 torture_assert_str_equal(torture, ldb_dn_get_extended_linearized(mem_ctx, dn, 1),
706 talloc_asprintf(mem_ctx, "<GUID=%s>",
707 guid),
708 "Clear extended linearized DN incorrect");
710 torture_assert_str_equal(torture, ldb_dn_get_extended_linearized(mem_ctx, dn, 0),
711 talloc_asprintf(mem_ctx, "<GUID=%s>",
712 hex_guid),
713 "HEX extended linearized DN incorrect");
715 /* Now check a 'just GUID' DN (HEX format) */
716 torture_assert(torture,
717 dn = ldb_dn_new_fmt(mem_ctx, ldb, "<GUID=%s>",
718 hex_guid),
719 "Failed to create an 'extended' DN");
721 torture_assert(torture,
722 ldb_dn_validate(dn),
723 "Failed to validate 'extended' DN");
725 torture_assert(torture, ldb_dn_has_extended(dn) == true,
726 "Should find extended DN to be 'extended'");
728 torture_assert(torture, ldb_dn_get_extended_component(dn, "SID") == NULL,
729 "Should not find an SID on this DN");
731 torture_assert(torture, ldb_dn_get_extended_component(dn, "GUID") != NULL,
732 "Should find an GUID on this DN");
734 torture_assert_data_blob_equal(torture, *ldb_dn_get_extended_component(dn, "GUID"), guid_blob,
735 "Extended DN GUID incorect");
737 torture_assert_str_equal(torture, ldb_dn_get_linearized(dn), "",
738 "linearized DN incorrect");
740 /* Now check a 'just SID' DN (clear format) */
741 torture_assert(torture,
742 dn = ldb_dn_new_fmt(mem_ctx, ldb, "<SID=%s>",
743 sid),
744 "Failed to create an 'extended' DN");
746 torture_assert(torture,
747 ldb_dn_validate(dn),
748 "Failed to validate 'extended' DN");
750 torture_assert(torture, ldb_dn_has_extended(dn) == true,
751 "Should find extended DN to be 'extended'");
753 torture_assert(torture, ldb_dn_get_extended_component(dn, "GUID") == NULL,
754 "Should not find an SID on this DN");
756 torture_assert(torture, ldb_dn_get_extended_component(dn, "SID") != NULL,
757 "Should find an SID on this DN");
759 torture_assert_data_blob_equal(torture, *ldb_dn_get_extended_component(dn, "SID"), sid_blob,
760 "Extended DN SID incorect");
762 torture_assert_str_equal(torture, ldb_dn_get_linearized(dn), "",
763 "linearized DN incorrect");
765 torture_assert_str_equal(torture, ldb_dn_get_extended_linearized(mem_ctx, dn, 1),
766 talloc_asprintf(mem_ctx, "<SID=%s>",
767 sid),
768 "Clear extended linearized DN incorrect");
770 torture_assert_str_equal(torture, ldb_dn_get_extended_linearized(mem_ctx, dn, 0),
771 talloc_asprintf(mem_ctx, "<SID=%s>",
772 hex_sid),
773 "HEX extended linearized DN incorrect");
775 /* Now check a 'just SID' DN (HEX format) */
776 torture_assert(torture,
777 dn = ldb_dn_new_fmt(mem_ctx, ldb, "<SID=%s>",
778 hex_sid),
779 "Failed to create an 'extended' DN");
781 torture_assert(torture,
782 ldb_dn_validate(dn),
783 "Failed to validate 'extended' DN");
785 torture_assert(torture, ldb_dn_has_extended(dn) == true,
786 "Should find extended DN to be 'extended'");
788 torture_assert(torture, ldb_dn_get_extended_component(dn, "GUID") == NULL,
789 "Should not find an SID on this DN");
791 torture_assert(torture, ldb_dn_get_extended_component(dn, "SID") != NULL,
792 "Should find an SID on this DN");
794 torture_assert_data_blob_equal(torture, *ldb_dn_get_extended_component(dn, "SID"), sid_blob,
795 "Extended DN SID incorect");
797 torture_assert_str_equal(torture, ldb_dn_get_linearized(dn), "",
798 "linearized DN incorrect");
800 talloc_free(mem_ctx);
801 return true;
805 static bool torture_ldb_dn(struct torture_context *torture)
807 TALLOC_CTX *mem_ctx = talloc_new(torture);
808 struct ldb_context *ldb;
809 struct ldb_dn *dn;
810 struct ldb_dn *child_dn;
811 struct ldb_dn *typo_dn;
812 struct ldb_dn *special_dn;
813 struct ldb_val val;
815 torture_assert(torture,
816 ldb = ldb_init(mem_ctx, torture->ev),
817 "Failed to init ldb");
819 torture_assert_int_equal(torture,
820 ldb_register_samba_handlers(ldb), LDB_SUCCESS,
821 "Failed to register Samba handlers");
823 ldb_set_utf8_fns(ldb, NULL, wrap_casefold);
825 /* Check behaviour of a normal DN */
826 torture_assert(torture,
827 dn = ldb_dn_new(mem_ctx, ldb, NULL),
828 "Failed to create a NULL DN");
830 torture_assert(torture,
831 ldb_dn_validate(dn),
832 "Failed to validate NULL DN");
834 torture_assert(torture,
835 ldb_dn_add_base_fmt(dn, "dc=org"),
836 "Failed to add base DN");
838 torture_assert(torture,
839 ldb_dn_add_child_fmt(dn, "dc=samba"),
840 "Failed to add base DN");
842 torture_assert_str_equal(torture, ldb_dn_get_linearized(dn), "dc=samba,dc=org",
843 "linearized DN incorrect");
845 torture_assert_str_equal(torture, ldb_dn_get_extended_linearized(mem_ctx, dn, 0), "dc=samba,dc=org",
846 "extended linearized DN incorrect");
848 /* Check child DN comparisons */
849 torture_assert(torture,
850 child_dn = ldb_dn_new(mem_ctx, ldb, "CN=users,DC=SAMBA,DC=org"),
851 "Failed to create child DN");
853 torture_assert(torture,
854 ldb_dn_compare(dn, child_dn) != 0,
855 "Comparison on dc=samba,dc=org and CN=users,DC=SAMBA,DC=org should != 0");
857 torture_assert(torture,
858 ldb_dn_compare_base(child_dn, dn) != 0,
859 "Base Comparison of CN=users,DC=SAMBA,DC=org and dc=samba,dc=org should != 0");
861 torture_assert(torture,
862 ldb_dn_compare_base(dn, child_dn) == 0,
863 "Base Comparison on dc=samba,dc=org and CN=users,DC=SAMBA,DC=org should == 0");
865 /* Check comparisons with a truncated DN */
866 torture_assert(torture,
867 typo_dn = ldb_dn_new(mem_ctx, ldb, "c=samba,dc=org"),
868 "Failed to create 'typo' DN");
870 torture_assert(torture,
871 ldb_dn_compare(dn, typo_dn) != 0,
872 "Comparison on dc=samba,dc=org and c=samba,dc=org should != 0");
874 torture_assert(torture,
875 ldb_dn_compare_base(typo_dn, dn) != 0,
876 "Base Comparison of c=samba,dc=org and dc=samba,dc=org should != 0");
878 torture_assert(torture,
879 ldb_dn_compare_base(dn, typo_dn) != 0,
880 "Base Comparison on dc=samba,dc=org and c=samba,dc=org should != 0");
882 /* Check comparisons with a special DN */
883 torture_assert(torture,
884 special_dn = ldb_dn_new(mem_ctx, ldb, "@special_dn"),
885 "Failed to create 'special' DN");
887 torture_assert(torture,
888 ldb_dn_compare(dn, special_dn) != 0,
889 "Comparison on dc=samba,dc=org and @special_dn should != 0");
891 torture_assert(torture,
892 ldb_dn_compare_base(special_dn, dn) > 0,
893 "Base Comparison of @special_dn and dc=samba,dc=org should > 0");
895 torture_assert(torture,
896 ldb_dn_compare_base(dn, special_dn) < 0,
897 "Base Comparison on dc=samba,dc=org and @special_dn should < 0");
899 /* Check DN based on MS-ADTS:3.1.1.5.1.2 Naming Constraints*/
900 torture_assert(torture,
901 dn = ldb_dn_new(mem_ctx, ldb, "CN=New\nLine,DC=SAMBA,DC=org"),
902 "Failed to create a DN with 0xA in it");
904 /* this is a warning until we work out how the DEL: CNs work */
905 if (ldb_dn_validate(dn) != false) {
906 torture_warning(torture,
907 "should have failed to validate a DN with 0xA in it");
910 /* Escaped comma */
911 torture_assert(torture,
912 dn = ldb_dn_new(mem_ctx, ldb, "CN=A\\,comma,DC=SAMBA,DC=org"),
913 "Failed to create a DN with an escaped comma in it");
916 val = data_blob_const("CN=Zer\0,DC=SAMBA,DC=org", 23);
917 torture_assert(torture,
918 NULL == ldb_dn_from_ldb_val(mem_ctx, ldb, &val),
919 "should fail to create a DN with 0x0 in it");
921 talloc_free(mem_ctx);
922 return true;
925 static bool torture_ldb_dn_invalid_extended(struct torture_context *torture)
927 TALLOC_CTX *mem_ctx = talloc_new(torture);
928 struct ldb_context *ldb;
929 struct ldb_dn *dn;
931 const char *dn_str = "cn=admin,cn=users,dc=samba,dc=org";
933 torture_assert(torture,
934 ldb = ldb_init(mem_ctx, torture->ev),
935 "Failed to init ldb");
937 torture_assert_int_equal(torture,
938 ldb_register_samba_handlers(ldb), LDB_SUCCESS,
939 "Failed to register Samba handlers");
941 ldb_set_utf8_fns(ldb, NULL, wrap_casefold);
943 /* Check behaviour of a normal DN */
944 torture_assert(torture,
945 dn = ldb_dn_new(mem_ctx, ldb, "samba,dc=org"),
946 "Failed to create a 'normal' invalid DN");
948 torture_assert(torture,
949 ldb_dn_validate(dn) == false,
950 "should have failed to validate 'normal' invalid DN");
952 /* Now make an extended DN */
953 torture_assert(torture,
954 dn = ldb_dn_new_fmt(mem_ctx, ldb, "<PID=%s>;%s",
955 sid, dn_str),
956 "Failed to create an invalid 'extended' DN");
958 torture_assert(torture,
959 ldb_dn_validate(dn) == false,
960 "should have failed to validate 'extended' DN");
962 torture_assert(torture,
963 dn = ldb_dn_new_fmt(mem_ctx, ldb, "<GUID=%s>%s",
964 sid, dn_str),
965 "Failed to create an invalid 'extended' DN");
967 torture_assert(torture,
968 ldb_dn_validate(dn) == false,
969 "should have failed to validate 'extended' DN");
971 torture_assert(torture,
972 dn = ldb_dn_new_fmt(mem_ctx, ldb, "<GUID=%s>;",
973 sid),
974 "Failed to create an invalid 'extended' DN");
976 torture_assert(torture,
977 ldb_dn_validate(dn) == false,
978 "should have failed to validate 'extended' DN");
980 torture_assert(torture,
981 dn = ldb_dn_new_fmt(mem_ctx, ldb, "<GUID=%s>;",
982 hex_sid),
983 "Failed to create an invalid 'extended' DN");
985 torture_assert(torture,
986 ldb_dn_validate(dn) == false,
987 "should have failed to validate 'extended' DN");
989 torture_assert(torture,
990 dn = ldb_dn_new_fmt(mem_ctx, ldb, "<SID=%s>;",
991 hex_guid),
992 "Failed to create an invalid 'extended' DN");
994 torture_assert(torture,
995 ldb_dn_validate(dn) == false,
996 "should have failed to validate 'extended' DN");
998 torture_assert(torture,
999 dn = ldb_dn_new_fmt(mem_ctx, ldb, "<SID=%s>;",
1000 guid),
1001 "Failed to create an invalid 'extended' DN");
1003 torture_assert(torture,
1004 ldb_dn_validate(dn) == false,
1005 "should have failed to validate 'extended' DN");
1007 torture_assert(torture,
1008 dn = ldb_dn_new_fmt(mem_ctx, ldb, "<GUID=>"),
1009 "Failed to create an invalid 'extended' DN");
1011 torture_assert(torture,
1012 ldb_dn_validate(dn) == false,
1013 "should have failed to validate 'extended' DN");
1015 return true;
1018 static bool helper_ldb_message_compare(struct torture_context *torture,
1019 struct ldb_message *a,
1020 struct ldb_message *b)
1022 int i;
1024 if (a->num_elements != b->num_elements) {
1025 return false;
1028 for (i = 0; i < a->num_elements; i++) {
1029 int j;
1030 struct ldb_message_element x = a->elements[i];
1031 struct ldb_message_element y = b->elements[i];
1033 torture_comment(torture, "#%s\n", x.name);
1034 torture_assert_int_equal(torture, x.flags, y.flags,
1035 "Flags do not match");
1036 torture_assert_str_equal(torture, x.name, y.name,
1037 "Names do not match in field");
1038 torture_assert_int_equal(torture, x.num_values, y.num_values,
1039 "Number of values do not match");
1042 * Records cannot round trip via the SDDL string with a
1043 * nTSecurityDescriptor field.
1045 * Parsing from SDDL and diffing the NDR dump output gives the
1046 * following:
1048 * in: struct decode_security_descriptor
1049 * sd: struct security_descriptor
1050 * revision : SECURITY_DESCRIPTOR_REVISION_1 (1)
1051 *- type : 0x8c14 (35860)
1052 *- 0: SEC_DESC_OWNER_DEFAULTED
1053 *- 0: SEC_DESC_GROUP_DEFAULTED
1054 *+ type : 0x8c17 (35863)
1055 *+ 1: SEC_DESC_OWNER_DEFAULTED
1056 *+ 1: SEC_DESC_GROUP_DEFAULTED
1057 * 1: SEC_DESC_DACL_PRESENT
1058 * 0: SEC_DESC_DACL_DEFAULTED
1059 * 1: SEC_DESC_SACL_PRESENT
1061 if (strcmp(x.name, "nTSecurityDescriptor") == 0) {
1062 continue;
1064 for (j = 0; j < x.num_values; j++) {
1065 torture_assert_int_equal(torture, x.values[j].length,
1066 y.values[j].length,
1067 "Does not match in length");
1068 torture_assert_mem_equal(torture,
1069 x.values[j].data,
1070 y.values[j].data,
1071 x.values[j].length,
1072 "Does not match in data");
1075 return true;
1078 static bool torture_ldb_unpack(struct torture_context *torture)
1080 TALLOC_CTX *mem_ctx = talloc_new(torture);
1081 struct ldb_context *ldb;
1082 struct ldb_val data = data_blob_const(dda1d01d_bin, sizeof(dda1d01d_bin));
1083 struct ldb_message *msg = ldb_msg_new(mem_ctx);
1084 const char *ldif_text = dda1d01d_ldif;
1085 struct ldb_ldif ldif;
1087 ldb = samba_ldb_init(mem_ctx, torture->ev, NULL, NULL, NULL);
1088 torture_assert(torture,
1089 ldb != NULL,
1090 "Failed to init ldb");
1092 torture_assert_int_equal(torture, ldb_unpack_data(ldb, &data, msg), 0,
1093 "ldb_unpack_data failed");
1095 ldif.changetype = LDB_CHANGETYPE_NONE;
1096 ldif.msg = msg;
1097 ldif_text = ldb_ldif_write_string(ldb, mem_ctx, &ldif);
1099 torture_assert_int_equal(torture,
1100 strcmp(ldif_text, dda1d01d_ldif), 0,
1101 "ldif form differs from binary form");
1102 return true;
1105 static bool torture_ldb_unpack_flags(struct torture_context *torture)
1107 TALLOC_CTX *mem_ctx = talloc_new(torture);
1108 struct ldb_context *ldb;
1109 struct ldb_val data = data_blob_const(dda1d01d_bin, sizeof(dda1d01d_bin));
1110 struct ldb_message *msg = ldb_msg_new(mem_ctx);
1111 const char *ldif_text = dda1d01d_ldif;
1112 struct ldb_ldif ldif;
1113 unsigned int nb_elements_in_db;
1115 ldb = samba_ldb_init(mem_ctx, torture->ev, NULL, NULL, NULL);
1116 torture_assert(torture,
1117 ldb != NULL,
1118 "Failed to init ldb");
1120 torture_assert_int_equal(torture,
1121 ldb_unpack_data_only_attr_list_flags(ldb, &data,
1122 msg,
1123 NULL, 0,
1124 LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC,
1125 &nb_elements_in_db),
1127 "ldb_unpack_data failed");
1129 ldif.changetype = LDB_CHANGETYPE_NONE;
1130 ldif.msg = msg;
1131 ldif_text = ldb_ldif_write_string(ldb, mem_ctx, &ldif);
1133 torture_assert_int_equal(torture,
1134 strcmp(ldif_text, dda1d01d_ldif), 0,
1135 "ldif form differs from binary form");
1137 torture_assert_int_equal(torture,
1138 ldb_unpack_data_only_attr_list_flags(ldb, &data,
1139 msg,
1140 NULL, 0,
1141 LDB_UNPACK_DATA_FLAG_NO_DN,
1142 &nb_elements_in_db),
1144 "ldb_unpack_data failed");
1146 torture_assert(torture,
1147 msg->dn == NULL,
1148 "msg->dn should be NULL");
1150 return true;
1153 static bool torture_ldb_parse_ldif(struct torture_context *torture)
1155 TALLOC_CTX *mem_ctx = talloc_new(torture);
1156 const char *ldif_text = dda1d01d_ldif;
1157 struct ldb_context *ldb;
1158 struct ldb_ldif *ldif;
1159 struct ldb_val binary;
1160 struct ldb_val data = data_blob_const(dda1d01d_bin, sizeof(dda1d01d_bin));
1161 struct ldb_message *msg = ldb_msg_new(mem_ctx);
1163 ldb = samba_ldb_init(mem_ctx, torture->ev, NULL,NULL,NULL);
1164 torture_assert(torture,
1165 ldb != NULL,
1166 "Failed to init ldb");
1168 ldif = ldb_ldif_read_string(ldb, &ldif_text);
1169 torture_assert(torture,
1170 ldif != NULL,
1171 "ldb_ldif_read_string failed");
1172 torture_assert_int_equal(torture, ldif->changetype, LDB_CHANGETYPE_NONE,
1173 "changetype is incorrect");
1174 torture_assert_int_equal(torture,
1175 ldb_pack_data(ldb, ldif->msg, &binary), 0,
1176 "ldb_pack_data failed");
1178 torture_assert_int_equal(torture, ldb_unpack_data(ldb, &data, msg), 0,
1179 "ldb_unpack_data failed");
1181 torture_assert(torture,
1182 helper_ldb_message_compare(torture, ldif->msg, msg),
1183 "Forms differ in memory");
1185 return true;
1188 static bool torture_ldb_unpack_only_attr_list(struct torture_context *torture)
1190 TALLOC_CTX *mem_ctx = talloc_new(torture);
1191 struct ldb_context *ldb;
1192 struct ldb_val data = data_blob_const(dda1d01d_bin, sizeof(dda1d01d_bin));
1193 struct ldb_message *msg = ldb_msg_new(mem_ctx);
1194 const char *lookup_names[] = {"instanceType", "nonexistant", "whenChanged",
1195 "objectClass", "uSNCreated",
1196 "showInAdvancedViewOnly", "name", "cnNotHere"};
1197 unsigned int nb_elements_in_db;
1198 const char *ldif_text;
1199 struct ldb_ldif ldif;
1201 ldb = samba_ldb_init(mem_ctx, torture->ev, NULL, NULL, NULL);
1202 torture_assert(torture,
1203 ldb != NULL,
1204 "Failed to init samba");
1206 torture_assert_int_equal(torture,
1207 ldb_unpack_data_only_attr_list(ldb, &data, msg,
1208 lookup_names, ARRAY_SIZE(lookup_names),
1209 &nb_elements_in_db), 0,
1210 "ldb_unpack_data_only_attr_list failed");
1211 torture_assert_int_equal(torture, nb_elements_in_db, 13,
1212 "Got wrong count of elements");
1214 /* Compare data in binary form */
1215 torture_assert_int_equal(torture, msg->num_elements, 6,
1216 "Got wrong number of parsed elements");
1218 torture_assert_str_equal(torture, msg->elements[0].name, "objectClass",
1219 "First element has wrong name");
1220 torture_assert_int_equal(torture, msg->elements[0].num_values, 2,
1221 "First element has wrong count of values");
1222 torture_assert_int_equal(torture,
1223 msg->elements[0].values[0].length, 3,
1224 "First element's first value is of wrong length");
1225 torture_assert_mem_equal(torture,
1226 msg->elements[0].values[0].data, "top", 3,
1227 "First element's first value is incorrect");
1228 torture_assert_int_equal(torture,
1229 msg->elements[0].values[1].length, strlen("container"),
1230 "First element's second value is of wrong length");
1231 torture_assert_mem_equal(torture, msg->elements[0].values[1].data,
1232 "container", strlen("container"),
1233 "First element's second value is incorrect");
1235 torture_assert_str_equal(torture, msg->elements[1].name, "instanceType",
1236 "Second element has wrong name");
1237 torture_assert_int_equal(torture, msg->elements[1].num_values, 1,
1238 "Second element has too many values");
1239 torture_assert_int_equal(torture, msg->elements[1].values[0].length, 1,
1240 "Second element's value is of wrong length");
1241 torture_assert_mem_equal(torture, msg->elements[1].values[0].data,
1242 "4", 1,
1243 "Second element's value is incorrect");
1245 torture_assert_str_equal(torture, msg->elements[2].name, "whenChanged",
1246 "Third element has wrong name");
1247 torture_assert_int_equal(torture, msg->elements[2].num_values, 1,
1248 "Third element has too many values");
1249 torture_assert_int_equal(torture, msg->elements[2].values[0].length,
1250 strlen("20150708224310.0Z"),
1251 "Third element's value is of wrong length");
1252 torture_assert_mem_equal(torture, msg->elements[2].values[0].data,
1253 "20150708224310.0Z", strlen("20150708224310.0Z"),
1254 "Third element's value is incorrect");
1256 torture_assert_str_equal(torture, msg->elements[3].name, "uSNCreated",
1257 "Fourth element has wrong name");
1258 torture_assert_int_equal(torture, msg->elements[3].num_values, 1,
1259 "Fourth element has too many values");
1260 torture_assert_int_equal(torture, msg->elements[3].values[0].length, 4,
1261 "Fourth element's value is of wrong length");
1262 torture_assert_mem_equal(torture, msg->elements[3].values[0].data,
1263 "3467", 4,
1264 "Fourth element's value is incorrect");
1266 torture_assert_str_equal(torture, msg->elements[4].name, "showInAdvancedViewOnly",
1267 "Fifth element has wrong name");
1268 torture_assert_int_equal(torture, msg->elements[4].num_values, 1,
1269 "Fifth element has too many values");
1270 torture_assert_int_equal(torture, msg->elements[4].values[0].length, 4,
1271 "Fifth element's value is of wrong length");
1272 torture_assert_mem_equal(torture, msg->elements[4].values[0].data,
1273 "TRUE", 4,
1274 "Fourth element's value is incorrect");
1276 torture_assert_str_equal(torture, msg->elements[5].name, "name",
1277 "Sixth element has wrong name");
1278 torture_assert_int_equal(torture, msg->elements[5].num_values, 1,
1279 "Sixth element has too many values");
1280 torture_assert_int_equal(torture, msg->elements[5].values[0].length,
1281 strlen("dda1d01d-4bd7-4c49-a184-46f9241b560e"),
1282 "Sixth element's value is of wrong length");
1283 torture_assert_mem_equal(torture, msg->elements[5].values[0].data,
1284 "dda1d01d-4bd7-4c49-a184-46f9241b560e",
1285 strlen("dda1d01d-4bd7-4c49-a184-46f9241b560e"),
1286 "Sixth element's value is incorrect");
1288 /* Compare data in ldif form */
1289 ldif.changetype = LDB_CHANGETYPE_NONE;
1290 ldif.msg = msg;
1291 ldif_text = ldb_ldif_write_string(ldb, mem_ctx, &ldif);
1293 torture_assert_str_equal(torture, ldif_text, dda1d01d_ldif_reduced,
1294 "Expected fields did not match");
1296 return true;
1299 struct torture_suite *torture_ldb(TALLOC_CTX *mem_ctx)
1301 struct torture_suite *suite = torture_suite_create(mem_ctx, "ldb");
1303 if (suite == NULL) {
1304 return NULL;
1307 torture_suite_add_simple_test(suite, "attrs", torture_ldb_attrs);
1308 torture_suite_add_simple_test(suite, "dn-attrs", torture_ldb_dn_attrs);
1309 torture_suite_add_simple_test(suite, "dn-extended",
1310 torture_ldb_dn_extended);
1311 torture_suite_add_simple_test(suite, "dn-invalid-extended",
1312 torture_ldb_dn_invalid_extended);
1313 torture_suite_add_simple_test(suite, "dn", torture_ldb_dn);
1314 torture_suite_add_simple_test(suite, "unpack-data",
1315 torture_ldb_unpack);
1316 torture_suite_add_simple_test(suite, "unpack-data-flags",
1317 torture_ldb_unpack_flags);
1318 torture_suite_add_simple_test(suite, "parse-ldif",
1319 torture_ldb_parse_ldif);
1320 torture_suite_add_simple_test(suite, "unpack-data-only-attr-list",
1321 torture_ldb_unpack_only_attr_list);
1323 suite->description = talloc_strdup(suite, "LDB (samba-specific behaviour) tests");
1325 return suite;