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/>.
23
#include "lib/events/events.h"
24
#include "lib/ldb/include/ldb.h"
25
#include "lib/ldb/include/ldb_errors.h"
26
#include "lib/ldb-samba/ldif_handlers.h"
28
#include "dsdb/samdb/samdb.h"
29
#include "param/param.h"
30
#include "torture/smbtorture.h"
31
#include "torture/ldb/proto.h"
33
static const char *sid = "S-1-5-21-4177067393-1453636373-93818737";
34
static const char *hex_sid = "01040000000000051500000081FDF8F815BBA456718F9705";
35
static const char *guid = "975ac5fa-35d9-431d-b86a-845bcd34fff9";
36
static const char *guid2 = "{975ac5fa-35d9-431d-b86a-845bcd34fff9}";
37
static const char *hex_guid = "FAC55A97D9351D43B86A845BCD34FFF9";
39
static bool torture_ldb_attrs(struct torture_context *torture)
41
TALLOC_CTX *mem_ctx = talloc_new(torture);
42
struct ldb_context *ldb;
43
const struct ldb_schema_attribute *attr;
44
struct ldb_val string_sid_blob, binary_sid_blob;
45
struct ldb_val string_guid_blob, string_guid_blob2, binary_guid_blob;
47
DATA_BLOB sid_blob = strhex_to_data_blob(mem_ctx, hex_sid);
48
DATA_BLOB guid_blob = strhex_to_data_blob(mem_ctx, hex_guid);
50
torture_assert(torture,
51
ldb = ldb_init(mem_ctx, torture->ev),
52
"Failed to init ldb");
54
torture_assert_int_equal(torture,
55
ldb_register_samba_handlers(ldb), 0,
56
"Failed to register Samba handlers");
58
ldb_set_utf8_fns(ldb, NULL, wrap_casefold);
60
/* Test SID behaviour */
61
torture_assert(torture, attr = ldb_schema_attribute_by_name(ldb, "objectSid"),
62
"Failed to get objectSid schema attribute");
64
string_sid_blob = data_blob_string_const(sid);
66
torture_assert_int_equal(torture,
67
attr->syntax->ldif_read_fn(ldb, mem_ctx,
68
&string_sid_blob, &binary_sid_blob), 0,
69
"Failed to parse string SID");
71
torture_assert_data_blob_equal(torture, binary_sid_blob, sid_blob,
72
"Read SID into blob form failed");
74
torture_assert_int_equal(torture,
75
attr->syntax->ldif_read_fn(ldb, mem_ctx,
76
&sid_blob, &binary_sid_blob), -1,
77
"Should have failed to parse binary SID");
79
torture_assert_int_equal(torture,
80
attr->syntax->ldif_write_fn(ldb, mem_ctx, &binary_sid_blob, &string_sid_blob), 0,
81
"Failed to parse binary SID");
83
torture_assert_data_blob_equal(torture,
84
string_sid_blob, data_blob_string_const(sid),
85
"Write SID into string form failed");
87
torture_assert_int_equal(torture,
88
attr->syntax->comparison_fn(ldb, mem_ctx, &binary_sid_blob, &string_sid_blob), 0,
89
"Failed to compare binary and string SID");
91
torture_assert_int_equal(torture,
92
attr->syntax->comparison_fn(ldb, mem_ctx, &string_sid_blob, &binary_sid_blob), 0,
93
"Failed to compare string and binary binary SID");
95
torture_assert_int_equal(torture,
96
attr->syntax->comparison_fn(ldb, mem_ctx, &string_sid_blob, &string_sid_blob), 0,
97
"Failed to compare string and string SID");
99
torture_assert_int_equal(torture,
100
attr->syntax->comparison_fn(ldb, mem_ctx, &binary_sid_blob, &binary_sid_blob), 0,
101
"Failed to compare binary and binary SID");
103
torture_assert(torture, attr->syntax->comparison_fn(ldb, mem_ctx, &guid_blob, &binary_sid_blob) != 0,
104
"Failed to distinguish binary GUID and binary SID");
107
/* Test GUID behaviour */
108
torture_assert(torture, attr = ldb_schema_attribute_by_name(ldb, "objectGUID"),
109
"Failed to get objectGUID schema attribute");
111
string_guid_blob = data_blob_string_const(guid);
113
torture_assert_int_equal(torture,
114
attr->syntax->ldif_read_fn(ldb, mem_ctx,
115
&string_guid_blob, &binary_guid_blob), 0,
116
"Failed to parse string GUID");
118
torture_assert_data_blob_equal(torture, binary_guid_blob, guid_blob,
119
"Read GUID into blob form failed");
121
string_guid_blob2 = data_blob_string_const(guid2);
123
torture_assert_int_equal(torture,
124
attr->syntax->ldif_read_fn(ldb, mem_ctx,
125
&string_guid_blob2, &binary_guid_blob), 0,
126
"Failed to parse string GUID");
128
torture_assert_data_blob_equal(torture, binary_guid_blob, guid_blob,
129
"Read GUID into blob form failed");
131
torture_assert_int_equal(torture,
132
attr->syntax->ldif_read_fn(ldb, mem_ctx,
133
&guid_blob, &binary_guid_blob), 0,
134
"Failed to parse binary GUID");
136
torture_assert_data_blob_equal(torture, binary_guid_blob, guid_blob,
137
"Read GUID into blob form failed");
139
torture_assert_int_equal(torture,
140
attr->syntax->ldif_write_fn(ldb, mem_ctx, &binary_guid_blob, &string_guid_blob), 0,
141
"Failed to print binary GUID as string");
143
torture_assert_data_blob_equal(torture, string_sid_blob, data_blob_string_const(sid),
144
"Write SID into string form failed");
146
torture_assert_int_equal(torture,
147
attr->syntax->comparison_fn(ldb, mem_ctx, &binary_guid_blob, &string_guid_blob), 0,
148
"Failed to compare binary and string GUID");
150
torture_assert_int_equal(torture,
151
attr->syntax->comparison_fn(ldb, mem_ctx, &string_guid_blob, &binary_guid_blob), 0,
152
"Failed to compare string and binary binary GUID");
154
torture_assert_int_equal(torture,
155
attr->syntax->comparison_fn(ldb, mem_ctx, &string_guid_blob, &string_guid_blob), 0,
156
"Failed to compare string and string GUID");
158
torture_assert_int_equal(torture,
159
attr->syntax->comparison_fn(ldb, mem_ctx, &binary_guid_blob, &binary_guid_blob), 0,
160
"Failed to compare binary and binary GUID");
164
talloc_free(mem_ctx);
168
static bool torture_ldb_dn_attrs(struct torture_context *torture)
170
TALLOC_CTX *mem_ctx = talloc_new(torture);
171
struct ldb_context *ldb;
172
const struct ldb_dn_extended_syntax *attr;
173
struct ldb_val string_sid_blob, binary_sid_blob;
174
struct ldb_val string_guid_blob, binary_guid_blob;
175
struct ldb_val hex_sid_blob, hex_guid_blob;
177
DATA_BLOB sid_blob = strhex_to_data_blob(mem_ctx, hex_sid);
178
DATA_BLOB guid_blob = strhex_to_data_blob(mem_ctx, hex_guid);
180
torture_assert(torture,
181
ldb = ldb_init(mem_ctx, torture->ev),
182
"Failed to init ldb");
184
torture_assert_int_equal(torture,
185
ldb_register_samba_handlers(ldb), 0,
186
"Failed to register Samba handlers");
188
ldb_set_utf8_fns(ldb, NULL, wrap_casefold);
190
/* Test SID behaviour */
191
torture_assert(torture, attr = ldb_dn_extended_syntax_by_name(ldb, "SID"),
192
"Failed to get SID DN syntax");
194
string_sid_blob = data_blob_string_const(sid);
196
torture_assert_int_equal(torture,
197
attr->read_fn(ldb, mem_ctx,
198
&string_sid_blob, &binary_sid_blob), 0,
199
"Failed to parse string SID");
201
torture_assert_data_blob_equal(torture, binary_sid_blob, sid_blob,
202
"Read SID into blob form failed");
204
hex_sid_blob = data_blob_string_const(hex_sid);
206
torture_assert_int_equal(torture,
207
attr->read_fn(ldb, mem_ctx,
208
&hex_sid_blob, &binary_sid_blob), 0,
209
"Failed to parse HEX SID");
211
torture_assert_data_blob_equal(torture, binary_sid_blob, sid_blob,
212
"Read SID into blob form failed");
214
torture_assert_int_equal(torture,
215
attr->read_fn(ldb, mem_ctx,
216
&sid_blob, &binary_sid_blob), -1,
217
"Should have failed to parse binary SID");
219
torture_assert_int_equal(torture,
220
attr->write_hex_fn(ldb, mem_ctx, &sid_blob, &hex_sid_blob), 0,
221
"Failed to parse binary SID");
223
torture_assert_data_blob_equal(torture,
224
hex_sid_blob, data_blob_string_const(hex_sid),
225
"Write SID into HEX string form failed");
227
torture_assert_int_equal(torture,
228
attr->write_clear_fn(ldb, mem_ctx, &sid_blob, &string_sid_blob), 0,
229
"Failed to parse binary SID");
231
torture_assert_data_blob_equal(torture,
232
string_sid_blob, data_blob_string_const(sid),
233
"Write SID into clear string form failed");
236
/* Test GUID behaviour */
237
torture_assert(torture, attr = ldb_dn_extended_syntax_by_name(ldb, "GUID"),
238
"Failed to get GUID DN syntax");
240
string_guid_blob = data_blob_string_const(guid);
242
torture_assert_int_equal(torture,
243
attr->read_fn(ldb, mem_ctx,
244
&string_guid_blob, &binary_guid_blob), 0,
245
"Failed to parse string GUID");
247
torture_assert_data_blob_equal(torture, binary_guid_blob, guid_blob,
248
"Read GUID into blob form failed");
250
hex_guid_blob = data_blob_string_const(hex_guid);
252
torture_assert_int_equal(torture,
253
attr->read_fn(ldb, mem_ctx,
254
&hex_guid_blob, &binary_guid_blob), 0,
255
"Failed to parse HEX GUID");
257
torture_assert_data_blob_equal(torture, binary_guid_blob, guid_blob,
258
"Read GUID into blob form failed");
260
torture_assert_int_equal(torture,
261
attr->read_fn(ldb, mem_ctx,
262
&guid_blob, &binary_guid_blob), -1,
263
"Should have failed to parse binary GUID");
265
torture_assert_int_equal(torture,
266
attr->write_hex_fn(ldb, mem_ctx, &guid_blob, &hex_guid_blob), 0,
267
"Failed to parse binary GUID");
269
torture_assert_data_blob_equal(torture,
270
hex_guid_blob, data_blob_string_const(hex_guid),
271
"Write GUID into HEX string form failed");
273
torture_assert_int_equal(torture,
274
attr->write_clear_fn(ldb, mem_ctx, &guid_blob, &string_guid_blob), 0,
275
"Failed to parse binary GUID");
277
torture_assert_data_blob_equal(torture,
278
string_guid_blob, data_blob_string_const(guid),
279
"Write GUID into clear string form failed");
283
talloc_free(mem_ctx);
287
static bool torture_ldb_dn_extended(struct torture_context *torture)
289
TALLOC_CTX *mem_ctx = talloc_new(torture);
290
struct ldb_context *ldb;
291
struct ldb_dn *dn, *dn2;
293
DATA_BLOB sid_blob = strhex_to_data_blob(mem_ctx, hex_sid);
294
DATA_BLOB guid_blob = strhex_to_data_blob(mem_ctx, hex_guid);
296
const char *dn_str = "cn=admin,cn=users,dc=samba,dc=org";
298
torture_assert(torture,
299
ldb = ldb_init(mem_ctx, torture->ev),
300
"Failed to init ldb");
302
torture_assert_int_equal(torture,
303
ldb_register_samba_handlers(ldb), 0,
304
"Failed to register Samba handlers");
306
ldb_set_utf8_fns(ldb, NULL, wrap_casefold);
308
/* Check behaviour of a normal DN */
309
torture_assert(torture,
310
dn = ldb_dn_new(mem_ctx, ldb, dn_str),
311
"Failed to create a 'normal' DN");
313
torture_assert(torture,
315
"Failed to validate 'normal' DN");
317
torture_assert(torture, ldb_dn_has_extended(dn) == false,
318
"Should not find plain DN to be 'extended'");
320
torture_assert(torture, ldb_dn_get_extended_component(dn, "SID") == NULL,
321
"Should not find an SID on plain DN");
323
torture_assert(torture, ldb_dn_get_extended_component(dn, "GUID") == NULL,
324
"Should not find an GUID on plain DN");
326
torture_assert(torture, ldb_dn_get_extended_component(dn, "WKGUID") == NULL,
327
"Should not find an WKGUID on plain DN");
329
/* Now make an extended DN */
330
torture_assert(torture,
331
dn = ldb_dn_new_fmt(mem_ctx, ldb, "<GUID=%s>;<SID=%s>;%s",
333
"Failed to create an 'extended' DN");
335
torture_assert(torture,
336
dn2 = ldb_dn_copy(mem_ctx, dn),
337
"Failed to copy the 'extended' DN");
341
torture_assert(torture,
343
"Failed to validate 'extended' DN");
345
torture_assert(torture, ldb_dn_has_extended(dn) == true,
346
"Should find extended DN to be 'extended'");
348
torture_assert(torture, ldb_dn_get_extended_component(dn, "SID") != NULL,
349
"Should find an SID on extended DN");
351
torture_assert(torture, ldb_dn_get_extended_component(dn, "GUID") != NULL,
352
"Should find an GUID on extended DN");
354
torture_assert_data_blob_equal(torture, *ldb_dn_get_extended_component(dn, "SID"), sid_blob,
355
"Extended DN SID incorect");
357
torture_assert_data_blob_equal(torture, *ldb_dn_get_extended_component(dn, "GUID"), guid_blob,
358
"Extended DN GUID incorect");
360
torture_assert_str_equal(torture, ldb_dn_get_linearized(dn), dn_str,
361
"linearized DN incorrect");
363
torture_assert_str_equal(torture, ldb_dn_get_casefold(dn), strupper_talloc(mem_ctx, dn_str),
364
"casefolded DN incorrect");
366
torture_assert_str_equal(torture, ldb_dn_get_component_name(dn, 0), "cn",
367
"componet zero incorrect");
369
torture_assert_data_blob_equal(torture, *ldb_dn_get_component_val(dn, 0), data_blob_string_const("admin"),
370
"componet zero incorrect");
372
torture_assert_str_equal(torture, ldb_dn_get_extended_linearized(mem_ctx, dn, 1),
373
talloc_asprintf(mem_ctx, "<GUID=%s>;<SID=%s>;%s",
375
"Clear extended linearized DN incorrect");
377
torture_assert_str_equal(torture, ldb_dn_get_extended_linearized(mem_ctx, dn, 0),
378
talloc_asprintf(mem_ctx, "<GUID=%s>;<SID=%s>;%s",
379
hex_guid, hex_sid, dn_str),
380
"HEX extended linearized DN incorrect");
382
torture_assert(torture, ldb_dn_remove_child_components(dn, 1) == true,
383
"Failed to remove DN child");
385
torture_assert(torture, ldb_dn_has_extended(dn) == false,
386
"Extended DN flag should be cleared after child element removal");
388
torture_assert(torture, ldb_dn_get_extended_component(dn, "SID") == NULL,
389
"Should not find an SID on DN");
391
torture_assert(torture, ldb_dn_get_extended_component(dn, "GUID") == NULL,
392
"Should not find an GUID on DN");
395
/* TODO: test setting these in the other order, and ensure it still comes out 'GUID first' */
396
torture_assert_int_equal(torture, ldb_dn_set_extended_component(dn, "GUID", &guid_blob), 0,
397
"Failed to set a GUID on DN");
399
torture_assert_int_equal(torture, ldb_dn_set_extended_component(dn, "SID", &sid_blob), 0,
400
"Failed to set a SID on DN");
402
torture_assert_data_blob_equal(torture, *ldb_dn_get_extended_component(dn, "SID"), sid_blob,
403
"Extended DN SID incorect");
405
torture_assert_data_blob_equal(torture, *ldb_dn_get_extended_component(dn, "GUID"), guid_blob,
406
"Extended DN GUID incorect");
408
torture_assert_str_equal(torture, ldb_dn_get_linearized(dn), "cn=users,dc=samba,dc=org",
409
"linearized DN incorrect");
411
torture_assert_str_equal(torture, ldb_dn_get_extended_linearized(mem_ctx, dn, 1),
412
talloc_asprintf(mem_ctx, "<GUID=%s>;<SID=%s>;%s",
413
guid, sid, "cn=users,dc=samba,dc=org"),
414
"Clear extended linearized DN incorrect");
416
torture_assert_str_equal(torture, ldb_dn_get_extended_linearized(mem_ctx, dn, 0),
417
talloc_asprintf(mem_ctx, "<GUID=%s>;<SID=%s>;%s",
418
hex_guid, hex_sid, "cn=users,dc=samba,dc=org"),
419
"HEX extended linearized DN incorrect");
421
/* Now check a 'just GUID' DN (clear format) */
422
torture_assert(torture,
423
dn = ldb_dn_new_fmt(mem_ctx, ldb, "<GUID=%s>",
425
"Failed to create an 'extended' DN");
427
torture_assert(torture,
429
"Failed to validate 'extended' DN");
431
torture_assert(torture, ldb_dn_has_extended(dn) == true,
432
"Should find extended DN to be 'extended'");
434
torture_assert(torture, ldb_dn_get_extended_component(dn, "SID") == NULL,
435
"Should not find an SID on this DN");
437
torture_assert_int_equal(torture, ldb_dn_get_comp_num(dn), 0,
438
"Should not find an 'normal' componet on this DN");
440
torture_assert(torture, ldb_dn_get_extended_component(dn, "GUID") != NULL,
441
"Should find an GUID on this DN");
443
torture_assert_data_blob_equal(torture, *ldb_dn_get_extended_component(dn, "GUID"), guid_blob,
444
"Extended DN GUID incorect");
446
torture_assert_str_equal(torture, ldb_dn_get_linearized(dn), "",
447
"linearized DN incorrect");
449
torture_assert_str_equal(torture, ldb_dn_get_extended_linearized(mem_ctx, dn, 1),
450
talloc_asprintf(mem_ctx, "<GUID=%s>",
452
"Clear extended linearized DN incorrect");
454
torture_assert_str_equal(torture, ldb_dn_get_extended_linearized(mem_ctx, dn, 0),
455
talloc_asprintf(mem_ctx, "<GUID=%s>",
457
"HEX extended linearized DN incorrect");
459
/* Now check a 'just GUID' DN (HEX format) */
460
torture_assert(torture,
461
dn = ldb_dn_new_fmt(mem_ctx, ldb, "<GUID=%s>",
463
"Failed to create an 'extended' DN");
465
torture_assert(torture,
467
"Failed to validate 'extended' DN");
469
torture_assert(torture, ldb_dn_has_extended(dn) == true,
470
"Should find extended DN to be 'extended'");
472
torture_assert(torture, ldb_dn_get_extended_component(dn, "SID") == NULL,
473
"Should not find an SID on this DN");
475
torture_assert(torture, ldb_dn_get_extended_component(dn, "GUID") != NULL,
476
"Should find an GUID on this DN");
478
torture_assert_data_blob_equal(torture, *ldb_dn_get_extended_component(dn, "GUID"), guid_blob,
479
"Extended DN GUID incorect");
481
torture_assert_str_equal(torture, ldb_dn_get_linearized(dn), "",
482
"linearized DN incorrect");
484
/* Now check a 'just SID' DN (clear format) */
485
torture_assert(torture,
486
dn = ldb_dn_new_fmt(mem_ctx, ldb, "<SID=%s>",
488
"Failed to create an 'extended' DN");
490
torture_assert(torture,
492
"Failed to validate 'extended' DN");
494
torture_assert(torture, ldb_dn_has_extended(dn) == true,
495
"Should find extended DN to be 'extended'");
497
torture_assert(torture, ldb_dn_get_extended_component(dn, "GUID") == NULL,
498
"Should not find an SID on this DN");
500
torture_assert(torture, ldb_dn_get_extended_component(dn, "SID") != NULL,
501
"Should find an SID on this DN");
503
torture_assert_data_blob_equal(torture, *ldb_dn_get_extended_component(dn, "SID"), sid_blob,
504
"Extended DN SID incorect");
506
torture_assert_str_equal(torture, ldb_dn_get_linearized(dn), "",
507
"linearized DN incorrect");
509
torture_assert_str_equal(torture, ldb_dn_get_extended_linearized(mem_ctx, dn, 1),
510
talloc_asprintf(mem_ctx, "<SID=%s>",
512
"Clear extended linearized DN incorrect");
514
torture_assert_str_equal(torture, ldb_dn_get_extended_linearized(mem_ctx, dn, 0),
515
talloc_asprintf(mem_ctx, "<SID=%s>",
517
"HEX extended linearized DN incorrect");
519
/* Now check a 'just SID' DN (HEX format) */
520
torture_assert(torture,
521
dn = ldb_dn_new_fmt(mem_ctx, ldb, "<SID=%s>",
523
"Failed to create an 'extended' DN");
525
torture_assert(torture,
527
"Failed to validate 'extended' DN");
529
torture_assert(torture, ldb_dn_has_extended(dn) == true,
530
"Should find extended DN to be 'extended'");
532
torture_assert(torture, ldb_dn_get_extended_component(dn, "GUID") == NULL,
533
"Should not find an SID on this DN");
535
torture_assert(torture, ldb_dn_get_extended_component(dn, "SID") != NULL,
536
"Should find an SID on this DN");
538
torture_assert_data_blob_equal(torture, *ldb_dn_get_extended_component(dn, "SID"), sid_blob,
539
"Extended DN SID incorect");
541
torture_assert_str_equal(torture, ldb_dn_get_linearized(dn), "",
542
"linearized DN incorrect");
544
talloc_free(mem_ctx);
549
static bool torture_ldb_dn(struct torture_context *torture)
551
TALLOC_CTX *mem_ctx = talloc_new(torture);
552
struct ldb_context *ldb;
554
struct ldb_dn *child_dn;
555
struct ldb_dn *typo_dn;
557
torture_assert(torture,
558
ldb = ldb_init(mem_ctx, torture->ev),
559
"Failed to init ldb");
561
torture_assert_int_equal(torture,
562
ldb_register_samba_handlers(ldb), 0,
563
"Failed to register Samba handlers");
565
ldb_set_utf8_fns(ldb, NULL, wrap_casefold);
567
/* Check behaviour of a normal DN */
568
torture_assert(torture,
569
dn = ldb_dn_new(mem_ctx, ldb, NULL),
570
"Failed to create a NULL DN");
572
torture_assert(torture,
574
"Failed to validate NULL DN");
576
torture_assert(torture,
577
ldb_dn_add_base_fmt(dn, "dc=org"),
578
"Failed to add base DN");
580
torture_assert(torture,
581
ldb_dn_add_child_fmt(dn, "dc=samba"),
582
"Failed to add base DN");
584
torture_assert_str_equal(torture, ldb_dn_get_linearized(dn), "dc=samba,dc=org",
585
"linearized DN incorrect");
587
torture_assert_str_equal(torture, ldb_dn_get_extended_linearized(mem_ctx, dn, 0), "dc=samba,dc=org",
588
"extended linearized DN incorrect");
590
/* Check child DN comparisons */
591
torture_assert(torture,
592
child_dn = ldb_dn_new(mem_ctx, ldb, "CN=users,DC=SAMBA,DC=org"),
593
"Failed to create child DN");
595
torture_assert(torture,
596
ldb_dn_compare(dn, child_dn) != 0,
597
"Comparison on dc=samba,dc=org and CN=users,DC=SAMBA,DC=org should != 0");
599
torture_assert(torture,
600
ldb_dn_compare_base(child_dn, dn) != 0,
601
"Base Comparison of CN=users,DC=SAMBA,DC=org and dc=samba,dc=org should != 0");
603
torture_assert(torture,
604
ldb_dn_compare_base(dn, child_dn) == 0,
605
"Base Comparison on dc=samba,dc=org and CN=users,DC=SAMBA,DC=org should == 0");
607
/* Check comparisons with a truncated DN */
608
torture_assert(torture,
609
typo_dn = ldb_dn_new(mem_ctx, ldb, "c=samba,dc=org"),
610
"Failed to create 'typo' DN");
612
torture_assert(torture,
613
ldb_dn_compare(dn, typo_dn) != 0,
614
"Comparison on dc=samba,dc=org and c=samba,dc=org should != 0");
616
torture_assert(torture,
617
ldb_dn_compare_base(typo_dn, dn) != 0,
618
"Base Comparison of c=samba,dc=org and dc=samba,dc=org should != 0");
620
torture_assert(torture,
621
ldb_dn_compare_base(dn, typo_dn) != 0,
622
"Base Comparison on dc=samba,dc=org and c=samba,dc=org should != 0");
624
talloc_free(mem_ctx);
628
static bool torture_ldb_dn_invalid_extended(struct torture_context *torture)
630
TALLOC_CTX *mem_ctx = talloc_new(torture);
631
struct ldb_context *ldb;
634
const char *dn_str = "cn=admin,cn=users,dc=samba,dc=org";
636
torture_assert(torture,
637
ldb = ldb_init(mem_ctx, torture->ev),
638
"Failed to init ldb");
640
torture_assert_int_equal(torture,
641
ldb_register_samba_handlers(ldb), 0,
642
"Failed to register Samba handlers");
644
ldb_set_utf8_fns(ldb, NULL, wrap_casefold);
646
/* Check behaviour of a normal DN */
647
torture_assert(torture,
648
dn = ldb_dn_new(mem_ctx, ldb, "samba,dc=org"),
649
"Failed to create a 'normal' invalid DN");
651
torture_assert(torture,
652
ldb_dn_validate(dn) == false,
653
"should have failed to validate 'normal' invalid DN");
655
/* Now make an extended DN */
656
torture_assert(torture,
657
dn = ldb_dn_new_fmt(mem_ctx, ldb, "<PID=%s>;%s",
659
"Failed to create an invalid 'extended' DN");
661
torture_assert(torture,
662
ldb_dn_validate(dn) == false,
663
"should have failed to validate 'extended' DN");
665
torture_assert(torture,
666
dn = ldb_dn_new_fmt(mem_ctx, ldb, "<GUID=%s>%s",
668
"Failed to create an invalid 'extended' DN");
670
torture_assert(torture,
671
ldb_dn_validate(dn) == false,
672
"should have failed to validate 'extended' DN");
674
torture_assert(torture,
675
dn = ldb_dn_new_fmt(mem_ctx, ldb, "<GUID=%s>;",
677
"Failed to create an invalid 'extended' DN");
679
torture_assert(torture,
680
ldb_dn_validate(dn) == false,
681
"should have failed to validate 'extended' DN");
683
torture_assert(torture,
684
dn = ldb_dn_new_fmt(mem_ctx, ldb, "<GUID=%s>;",
686
"Failed to create an invalid 'extended' DN");
688
torture_assert(torture,
689
ldb_dn_validate(dn) == false,
690
"should have failed to validate 'extended' DN");
692
torture_assert(torture,
693
dn = ldb_dn_new_fmt(mem_ctx, ldb, "<SID=%s>;",
695
"Failed to create an invalid 'extended' DN");
697
torture_assert(torture,
698
ldb_dn_validate(dn) == false,
699
"should have failed to validate 'extended' DN");
701
torture_assert(torture,
702
dn = ldb_dn_new_fmt(mem_ctx, ldb, "<SID=%s>;",
704
"Failed to create an invalid 'extended' DN");
706
torture_assert(torture,
707
ldb_dn_validate(dn) == false,
708
"should have failed to validate 'extended' DN");
710
torture_assert(torture,
711
dn = ldb_dn_new_fmt(mem_ctx, ldb, "<GUID=>"),
712
"Failed to create an invalid 'extended' DN");
714
torture_assert(torture,
715
ldb_dn_validate(dn) == false,
716
"should have failed to validate 'extended' DN");
721
NTSTATUS torture_ldb_init(void)
723
struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "LDB");
724
torture_suite_add_simple_test(suite, "ATTRS", torture_ldb_attrs);
725
torture_suite_add_simple_test(suite, "DN-ATTRS", torture_ldb_dn_attrs);
726
torture_suite_add_simple_test(suite, "DN-EXTENDED", torture_ldb_dn_extended);
727
torture_suite_add_simple_test(suite, "DN-INVALID-EXTENDED", torture_ldb_dn_invalid_extended);
728
torture_suite_add_simple_test(suite, "DN", torture_ldb_dn);
730
suite->description = talloc_strdup(suite, "LDB (samba-specific behaviour) tests");
732
torture_register_suite(suite);