Debian Codegraph @

tests/scripts/test024-unique

raw
1 #! /bin/sh
2 # $OpenLDAP$
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 2004-2024 The OpenLDAP Foundation.
6 ## All rights reserved.
7 ##
8 ## Redistribution and use in source and binary forms, with or without
9 ## modification, are permitted only as authorized by the OpenLDAP
10 ## Public License.
11 ##
12 ## A copy of this license is available in the file LICENSE in the
13 ## top-level directory of the distribution or, alternatively, at
14 ## <http://www.OpenLDAP.org/license.html>.
15
16 echo "running defines.sh"
17 . $SRCDIR/scripts/defines.sh
18
19 if test $UNIQUE = uniqueno; then
20 echo "Attribute Uniqueness overlay not available, test skipped"
21 exit 0
22 fi
23
24 RCODEconstraint=19
25 RCODEnorelax=50
26 test $BACKEND = null && RCODEconstraint=0
27
28 mkdir -p $TESTDIR $DBDIR1
29
30 $SLAPPASSWD -g -n >$CONFIGPWF
31 echo "rootpw `$SLAPPASSWD -T $CONFIGPWF`" >$TESTDIR/configpw.conf
32
33 echo "Running slapadd to build slapd database..."
34 . $CONFFILTER $BACKEND < $UNIQUECONF > $CONF1
35 $SLAPADD -f $CONF1 -l $LDIFUNIQUE
36 RC=$?
37 if test $RC != 0 ; then
38 echo "slapadd failed ($RC)!"
39 exit $RC
40 fi
41
42 echo "Starting slapd on TCP/IP port $PORT1..."
43 mkdir $TESTDIR/confdir
44 $SLAPD -f $CONF1 -F $TESTDIR/confdir -h $URI1 -d $LVL > $LOG1 2>&1 &
45 PID=$!
46 if test $WAIT != 0 ; then
47 echo PID $PID
48 read foo
49 fi
50 KILLPIDS="$PID"
51
52 sleep 1
53
54 echo "Testing slapd attribute uniqueness operations..."
55 for i in 0 1 2 3 4 5; do
56 $LDAPSEARCH -s base -b "$MONITOR" -H $URI1 \
57 'objectclass=*' > /dev/null 2>&1
58 RC=$?
59 if test $RC = 0 ; then
60 break
61 fi
62 echo "Waiting 5 seconds for slapd to start..."
63 sleep 5
64 done
65
66 if test $RC != 0 ; then
67 echo "ldapsearch failed ($RC)!"
68 test $KILLSERVERS != no && kill -HUP $KILLPIDS
69 exit $RC
70 fi
71
72 echo "Adding a unique record..."
73 $LDAPADD -D "$UNIQUEDN" -H $URI1 -w $PASSWD \
74 > /dev/null << EOTUNIQ1
75 dn: uid=dave,ou=users,o=unique
76 objectClass: inetOrgPerson
77 objectClass: simpleSecurityObject
78 uid: dave
79 sn: nothere
80 cn: dave
81 businessCategory: otest
82 carLicense: TEST
83 departmentNumber: 42
84 # NOTE: use special chars in attr value to be used
85 # in internal searches ITS#4212
86 displayName: Dave (ITS#4212)
87 employeeNumber: 69
88 employeeType: contractor
89 givenName: Dave
90 userpassword: $PASSWD
91 EOTUNIQ1
92 RC=$?
93 if test $RC != 0 ; then
94 echo "ldapadd failed ($RC)!"
95 test $KILLSERVERS != no && kill -HUP $KILLPIDS
96 exit $RC
97 fi
98
99 echo "Adding a non-unique record..."
100 $LDAPADD -D "uid=dave,ou=users,o=unique" -H $URI1 -w $PASSWD > \
101 $TESTOUT 2>&1 << EOTUNIQ2
102 dn: uid=bill,ou=users,o=unique
103 objectClass: inetOrgPerson
104 uid: bill
105 sn: johnson
106 cn: bill
107 businessCategory: rtest
108 carLicense: ABC123
109 departmentNumber: 42
110 displayName: Bill
111 employeeNumber: 5150
112 employeeType: contractor
113 givenName: Bill
114 EOTUNIQ2
115 RC=$?
116 if test $RC != $RCODEconstraint ; then
117 echo "unique check failed ($RC)!"
118 test $KILLSERVERS != no && kill -HUP $KILLPIDS
119 exit 1
120 fi
121
122 # ITS#6641/8057/8245
123 echo "Trying to bypass uniqueness as a normal user..."
124 $LDAPADD -e \!relax -D "uid=dave,ou=users,o=unique" -H $URI1 -w $PASSWD > \
125 $TESTOUT 2>&1 << EOTUNIQ2
126 dn: uid=bill,ou=users,o=unique
127 objectClass: inetOrgPerson
128 uid: bill
129 sn: johnson
130 cn: bill
131 businessCategory: rtest
132 carLicense: ABC123
133 departmentNumber: 42
134 displayName: Bill
135 employeeNumber: 5150
136 employeeType: contractor
137 givenName: Bill
138 EOTUNIQ2
139 RC=$?
140 if test $RC != $RCODEnorelax && test $RC != $RCODEconstraint ; then
141 echo "unique check failed ($RC)!"
142 test $KILLSERVERS != no && kill -HUP $KILLPIDS
143 exit 1
144 fi
145
146 echo "Trying to bypass uniqueness as a normal user with ManageDSAIt..."
147 $LDAPADD -M -D "uid=dave,ou=users,o=unique" -H $URI1 -w $PASSWD > \
148 $TESTOUT 2>&1 << EOTUNIQ2
149 dn: uid=bill,ou=users,o=unique
150 objectClass: inetOrgPerson
151 uid: bill
152 sn: johnson
153 cn: bill
154 businessCategory: rtest
155 carLicense: ABC123
156 departmentNumber: 42
157 displayName: Bill
158 employeeNumber: 5150
159 employeeType: contractor
160 givenName: Bill
161 EOTUNIQ2
162 RC=$?
163 if test $RC != $RCODEconstraint ; then
164 echo "unique check failed ($RC)!"
165 test $KILLSERVERS != no && kill -HUP $KILLPIDS
166 exit 1
167 fi
168
169 echo "Bypassing uniqueness as an admin user..."
170 $LDAPADD -e \!relax -D "$UNIQUEDN" -H $URI1 -w $PASSWD > \
171 $TESTOUT 2>&1 << EOTUNIQ2
172 dn: uid=bill,ou=users,o=unique
173 objectClass: inetOrgPerson
174 uid: bill
175 sn: johnson
176 cn: bill
177 businessCategory: rtest
178 carLicense: ABC123
179 departmentNumber: 42
180 displayName: Bill
181 employeeNumber: 5150
182 employeeType: contractor
183 givenName: Bill
184 EOTUNIQ2
185 RC=$?
186 if test $RC != 0 ; then
187 echo "spurious unique error ($RC)!"
188 test $KILLSERVERS != no && kill -HUP $KILLPIDS
189 exit $RC
190 fi
191
192 echo "Cleaning up"
193 $LDAPDELETE -D "$UNIQUEDN" -H $URI1 -w $PASSWD \
194 "uid=bill,ou=users,o=unique" > $TESTOUT 2>&1
195 RC=$?
196 if test $RC != 0; then
197 echo "ldapdelete failed ($RC)!"
198 test $KILLSERVERS != no && kill -HUP $KILLPIDS
199 exit $RC
200 fi
201
202 echo Dynamically retrieving initial configuration...
203 $LDAPSEARCH -S "" -b olcOverlay='{0}'unique,olcDatabase='{1}'$BACKEND,cn=config -D cn=config -y $CONFIGPWF -H $URI1 -LLL | tr -d \\r >$TESTDIR/initial-config.ldif
204 cat <<EOF >$TESTDIR/initial-reference.ldif
205 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
206 objectClass: olcOverlayConfig
207 objectClass: olcUniqueConfig
208 olcOverlay: {0}unique
209 olcUniqueBase: o=unique
210 olcUniqueAttribute: employeeNumber
211 olcUniqueAttribute: displayName
212
213 EOF
214 diff $TESTDIR/initial-config.ldif $TESTDIR/initial-reference.ldif > /dev/null 2>&1
215 RC=$?
216 if test $RC != 0 ; then
217 echo "Initial configuration is not reported correctly."
218 test $KILLSERVERS != no && kill -HUP $KILLPIDS
219 exit 1
220 fi
221
222 echo Dynamically trying to add a URI with legacy attrs present...
223 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF \
224 > $TESTOUT 2>&1 <<EOF
225 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
226 changetype: modify
227 add: olcUniqueURI
228 olcUniqueURI: ldap:///?employeeNumber,displayName?sub
229 EOF
230 RC=$?
231 if test $RC != 80 ; then
232 echo "legacy and unique_uri allowed together"
233 test $KILLSERVERS != no && kill -HUP $KILLPIDS
234 exit 1
235 fi
236
237 echo Dynamically trying to add legacy ignored attrs with legacy attrs present...
238 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF \
239 > $TESTOUT 2>&1 <<EOF
240 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
241 changetype: modify
242 add: olcUniqueIgnore
243 olcUniqueIgnore: objectClass
244 EOF
245 RC=$?
246 if test $RC != 80 ; then
247 echo "legacy attrs and legacy ignore attrs allowed together"
248 test $KILLSERVERS != no && kill -HUP $KILLPIDS
249 exit 1
250 fi
251
252 echo Verifying initial configuration intact...
253 $LDAPSEARCH -S "" -b olcOverlay='{0}'unique,olcDatabase='{1}'$BACKEND,cn=config -D cn=config -y $CONFIGPWF -H $URI1 -LLL | tr -d \\r >$TESTDIR/initial-config-recheck.ldif
254 diff $TESTDIR/initial-config-recheck.ldif $TESTDIR/initial-reference.ldif > /dev/null 2>&1
255 RC=$?
256 if test $RC != 0 ; then
257 echo "Initial configuration damaged by unsuccessful modifies."
258 test $KILLSERVERS != no && kill -HUP $KILLPIDS
259 exit 1
260 fi
261
262 echo Dynamically removing legacy base...
263 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF \
264 > $TESTOUT 2>&1 <<EOF
265 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
266 changetype: modify
267 delete: olcUniqueBase
268 EOF
269 RC=$?
270 if test $RC != 0 ; then
271 echo "base removal failed"
272 test $KILLSERVERS != no && kill -HUP $KILLPIDS
273 exit 1
274 fi
275
276 echo Verifying base removal...
277 $LDAPSEARCH -S "" -b olcOverlay='{0}'unique,olcDatabase='{1}'$BACKEND,cn=config -D cn=config -y $CONFIGPWF -H $URI1 -LLL | tr -d \\r >$TESTDIR/baseremoval-config.ldif
278 cat >$TESTDIR/baseremoval-reference.ldif <<EOF
279 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
280 objectClass: olcOverlayConfig
281 objectClass: olcUniqueConfig
282 olcOverlay: {0}unique
283 olcUniqueAttribute: employeeNumber
284 olcUniqueAttribute: displayName
285
286 EOF
287 diff $TESTDIR/baseremoval-config.ldif $TESTDIR/baseremoval-reference.ldif > /dev/null 2>&1
288 RC=$?
289 if test $RC != 0 ; then
290 echo "Configuration damaged by base removal"
291 test $KILLSERVERS != no && kill -HUP $KILLPIDS
292 exit 1
293 fi
294
295 echo "Adding a non-unique record..."
296 $LDAPADD -D "uid=dave,ou=users,o=unique" -H $URI1 -w $PASSWD > \
297 $TESTOUT 2>&1 << EOTUNIQ2
298 dn: uid=bill,ou=users,o=unique
299 objectClass: inetOrgPerson
300 uid: bill
301 sn: johnson
302 cn: bill
303 businessCategory: rtest
304 carLicense: ABC123
305 departmentNumber: 42
306 displayName: Bill
307 employeeNumber: 5150
308 employeeType: contractor
309 givenName: Bill
310 EOTUNIQ2
311 RC=$?
312 if test $RC != $RCODEconstraint ; then
313 echo "unique check failed ($RC)!"
314 test $KILLSERVERS != no && kill -HUP $KILLPIDS
315 exit 1
316 fi
317
318 echo Trying a legacy base outside of the backend...
319 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF \
320 > $TESTOUT 2>&1 <<EOF
321 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
322 changetype: modify
323 add: olcUniqueBase
324 olcUniqueBase: cn=config
325 EOF
326 RC=$?
327 if test $RC != 80 ; then
328 echo "out of backend scope base allowed"
329 test $KILLSERVERS != no && kill -HUP $KILLPIDS
330 exit 1
331 fi
332
333 echo "Adding and removing attrs..."
334 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF \
335 > $TESTOUT 2>&1 <<EOF
336 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
337 changetype: modify
338 add: olcUniqueAttribute
339 olcUniqueAttribute: description
340 olcUniqueAttribute: telephoneNumber
341 -
342 delete: olcUniqueAttribute
343 olcUniqueAttribute: displayName
344 EOF
345 RC=$?
346 if test $RC != 0 ; then
347 echo "Unable to remove an attribute"
348 test $KILLSERVERS != no && kill -HUP $KILLPIDS
349 exit 1
350 fi
351
352 echo "Verifying we removed the right attr..."
353 $LDAPADD -D "uid=dave,ou=users,o=unique" -H $URI1 -w $PASSWD > \
354 $TESTOUT 2>&1 << EOTUNIQ2
355 dn: uid=bill,ou=users,o=unique
356 objectClass: inetOrgPerson
357 uid: bill
358 sn: johnson
359 cn: bill
360 businessCategory: rtest
361 carLicense: ABC123
362 departmentNumber: 42
363 displayName: Bill
364 employeeNumber: 5150
365 employeeType: contractor
366 givenName: Bill
367 EOTUNIQ2
368 RC=$?
369 if test $RC != $RCODEconstraint ; then
370 echo "olcUniqueAttribute single deletion hit the wrong value"
371 test $KILLSERVERS != no && kill -HUP $KILLPIDS
372 exit 1
373 fi
374
375 echo Removing legacy config and adding URIs...
376 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF \
377 > $TESTOUT 2>&1 <<EOF
378 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
379 changetype: modify
380 delete: olcUniqueAttribute
381 -
382 add: olcUniqueURI
383 olcUniqueURI: ldap:///?employeeNumber,displayName?sub
384 olcUniqueURI: ldap:///?description?one
385 EOF
386 RC=$?
387 if test $RC != 0 ; then
388 echo "Reconfiguration to URIs failed"
389 test $KILLSERVERS != no && kill -HUP $KILLPIDS
390 exit 1
391 fi
392
393 echo Dynamically retrieving second configuration...
394 $LDAPSEARCH -S "" -b olcOverlay='{0}'unique,olcDatabase='{1}'$BACKEND,cn=config -D cn=config -y $CONFIGPWF -H $URI1 -LLL | tr -d \\r >$TESTDIR/second-config.ldif
395 cat >$TESTDIR/second-reference.ldif <<EOF
396 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
397 objectClass: olcOverlayConfig
398 objectClass: olcUniqueConfig
399 olcOverlay: {0}unique
400 olcUniqueURI: ldap:///?employeeNumber,displayName?sub
401 olcUniqueURI: ldap:///?description?one
402
403 EOF
404 diff $TESTDIR/second-config.ldif $TESTDIR/second-reference.ldif > /dev/null 2>&1
405 RC=$?
406 if test $RC != 0 ; then
407 echo "Second configuration is not reported correctly."
408 test $KILLSERVERS != no && kill -HUP $KILLPIDS
409 exit 1
410 fi
411
412 echo "Adding a non-unique record..."
413 $LDAPADD -D "uid=dave,ou=users,o=unique" -H $URI1 -w $PASSWD > \
414 $TESTOUT 2>&1 << EOTUNIQ2
415 dn: uid=bill,ou=users,o=unique
416 objectClass: inetOrgPerson
417 uid: bill
418 sn: johnson
419 cn: bill
420 businessCategory: rtest
421 carLicense: ABC123
422 departmentNumber: 42
423 displayName: Bill
424 employeeNumber: 5150
425 employeeType: contractor
426 givenName: Bill
427 EOTUNIQ2
428 RC=$?
429 if test $RC != $RCODEconstraint ; then
430 echo "unique check failed ($RC)!"
431 test $KILLSERVERS != no && kill -HUP $KILLPIDS
432 exit 1
433 fi
434
435 echo Dynamically trying to add legacy base
436 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF \
437 > $TESTOUT 2>&1 <<EOF
438 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
439 changetype: modify
440 add: olcUniqueBase
441 olcUniqueBase: o=unique
442 EOF
443 RC=$?
444 if test $RC != 80 ; then
445 echo "legacy base allowed with URIs"
446 test $KILLSERVERS != no && kill -HUP $KILLPIDS
447 exit 1
448 fi
449
450 echo Dynamically trying to add legacy attrs
451 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF \
452 > $TESTOUT 2>&1 <<EOF
453 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
454 changetype: modify
455 add: olcUniqueAttribute
456 olcUniqueAttribute: description
457 EOF
458 RC=$?
459 if test $RC != 80 ; then
460 echo "legacy attributes allowed with URIs"
461 test $KILLSERVERS != no && kill -HUP $KILLPIDS
462 exit 1
463 fi
464
465 echo Dynamically trying to add legacy strictness
466 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF \
467 > $TESTOUT 2>&1 <<EOF
468 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
469 changetype: modify
470 add: olcUniqueStrict
471 olcUniqueStrict: TRUE
472 EOF
473 RC=$?
474 if test $RC != 80 ; then
475 echo "legacy strictness allowed with URIs"
476 test $KILLSERVERS != no && kill -HUP $KILLPIDS
477 exit 1
478 fi
479
480 #echo ----------------------
481 echo Dynamically trying a bad filter...
482 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF \
483 > $TESTOUT 2>&1 <<EOF
484 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
485 changetype: modify
486 replace: olcUniqueURI
487 olcUniqueURI: ldap:///?sn?sub?((cn=e*))
488 EOF
489 RC=$?
490 if test $RC != 80 ; then
491 echo "bad filter allowed"
492 test $KILLSERVERS != no && kill -HUP $KILLPIDS
493 exit 1
494 fi
495
496 echo Verifying second configuration intact...
497 $LDAPSEARCH -S "" -b olcOverlay='{0}'unique,olcDatabase='{1}'$BACKEND,cn=config -D cn=config -y $CONFIGPWF -H $URI1 -LLL | tr -d \\r >$TESTDIR/second-config-recheck.ldif
498 diff $TESTDIR/second-config-recheck.ldif $TESTDIR/second-reference.ldif > /dev/null 2>&1
499 RC=$?
500 if test $RC != 0 ; then
501 echo "Second configuration damaged by rejected modifies."
502 test $KILLSERVERS != no && kill -HUP $KILLPIDS
503 exit 1
504 fi
505
506 #echo ----------------------
507 echo Dynamically reconfiguring to use different URIs...
508 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF \
509 > $TESTOUT 2>&1 <<EOF
510 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
511 changetype: modify
512 add: olcUniqueURI
513 olcUniqueURI: ldap:///?sn?sub?(cn=e*)
514 olcUniqueURI: ldap:///?uid?sub?(cn=edgar)
515 -
516 delete: olcUniqueURI
517 olcUniqueURI: ldap:///?description?one
518 EOF
519 RC=$?
520 if test $RC != 0 ; then
521 echo "unable to reconfigure"
522 test $KILLSERVERS != no && kill -HUP $KILLPIDS
523 exit 1
524 fi
525
526 echo Dynamically retrieving third configuration...
527 $LDAPSEARCH -S "" -b olcOverlay='{0}'unique,olcDatabase='{1}'$BACKEND,cn=config -D cn=config -y $CONFIGPWF -H $URI1 -LLL | tr -d \\r >$TESTDIR/third-config.ldif
528 cat >$TESTDIR/third-reference.ldif <<EOF
529 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
530 objectClass: olcOverlayConfig
531 objectClass: olcUniqueConfig
532 olcOverlay: {0}unique
533 olcUniqueURI: ldap:///?employeeNumber,displayName?sub
534 olcUniqueURI: ldap:///?sn?sub?(cn=e*)
535 olcUniqueURI: ldap:///?uid?sub?(cn=edgar)
536
537 EOF
538 diff $TESTDIR/third-config.ldif $TESTDIR/third-reference.ldif > /dev/null 2>&1
539 RC=$?
540 if test $RC != 0 ; then
541 echo "Third configuration is not reported correctly."
542 test $KILLSERVERS != no && kill -HUP $KILLPIDS
543 exit 1
544 fi
545
546 echo "Adding a record unique in both domains if filtered..."
547
548 $LDAPADD -D "$UNIQUEDN" -H $URI1 -w $PASSWD > \
549 $TESTOUT 2>&1 << EOF
550 dn: uid=edgar,ou=users,o=unique
551 objectClass: inetOrgPerson
552 uid: edgar
553 sn: johnson
554 cn: edgar
555 EOF
556
557 RC=$?
558 if test $RC != 0 ; then
559 echo "unique check failed ($RC)!"
560 test $KILLSERVERS != no && kill -HUP $KILLPIDS
561 exit 1
562 fi
563
564 echo "Adding a record unique in all domains because of filter conditions "
565 $LDAPADD -D "$UNIQUEDN" -H $URI1 -w $PASSWD > \
566 $TESTOUT 2>&1 << EOF
567 dn: uid=empty,ou=users,o=unique
568 objectClass: inetOrgPerson
569 uid: edgar
570 cn: empty
571 sn: empty
572 EOF
573
574 RC=$?
575 if test $RC != 0 ; then
576 echo "spurious unique error ($RC)!"
577 test $KILLSERVERS != no && kill -HUP $KILLPIDS
578 exit 1
579 fi
580
581 echo "Sending an empty modification"
582
583 $LDAPMODIFY -D "$UNIQUEDN" -H $URI1 -w $PASSWD > \
584 $TESTOUT 2>&1 << EOF
585 dn: uid=empty,ou=users,o=unique
586 changetype: modify
587 EOF
588
589 RC=$?
590 if test $RC != 0 ; then
591 echo "spurious unique error ($RC)!"
592 test $KILLSERVERS != no && kill -HUP $KILLPIDS
593 exit 1
594 fi
595
596 echo "Making a record non-unique"
597 $LDAPMODIFY -D "uid=dave,ou=users,o=unique" -H $URI1 -w $PASSWD > \
598 $TESTOUT 2>&1 << EOF
599 dn: uid=empty,ou=users,o=unique
600 changetype: modify
601 replace: sn
602 sn: johnson
603 EOF
604
605 RC=$?
606 if test $RC != $RCODEconstraint ; then
607 echo "unique check failed ($RC)!"
608 test $KILLSERVERS != no && kill -HUP $KILLPIDS
609 exit 1
610 fi
611
612 # ITS#6641/8057/8245
613 echo "Trying to bypass uniqueness as a normal user..."
614 $LDAPMODIFY -e \!relax -D "uid=dave,ou=users,o=unique" -H $URI1 -w $PASSWD > \
615 $TESTOUT 2>&1 << EOF
616 dn: uid=empty,ou=users,o=unique
617 changetype: modify
618 replace: sn
619 sn: johnson
620 EOF
621
622 RC=$?
623 if test $RC != $RCODEnorelax && test $RC != $RCODEconstraint ; then
624 echo "unique check failed ($RC)!"
625 test $KILLSERVERS != no && kill -HUP $KILLPIDS
626 exit 1
627 fi
628
629 echo "Trying to bypass uniqueness as a normal user with ManageDSAIt..."
630 $LDAPMODIFY -M -D "uid=dave,ou=users,o=unique" -H $URI1 -w $PASSWD > \
631 $TESTOUT 2>&1 << EOF
632 dn: uid=empty,ou=users,o=unique
633 changetype: modify
634 replace: sn
635 sn: johnson
636 EOF
637
638 RC=$?
639 if test $RC != $RCODEconstraint ; then
640 echo "unique check failed ($RC)!"
641 test $KILLSERVERS != no && kill -HUP $KILLPIDS
642 exit 1
643 fi
644
645 echo "Bypassing uniqueness as an admin user..."
646 $LDAPMODIFY -e \!relax -D "$UNIQUEDN" -H $URI1 -w $PASSWD > \
647 $TESTOUT 2>&1 << EOF
648 dn: uid=empty,ou=users,o=unique
649 changetype: modify
650 replace: sn
651 sn: johnson
652 EOF
653
654 RC=$?
655 if test $RC != 0 ; then
656 echo "spurious unique error ($RC)!"
657 test $KILLSERVERS != no && kill -HUP $KILLPIDS
658 exit $RC
659 fi
660
661 echo "Cleaning up"
662 $LDAPMODIFY -D "$UNIQUEDN" -H $URI1 -w $PASSWD > \
663 $TESTOUT 2>&1 << EOF
664 dn: uid=empty,ou=users,o=unique
665 changetype: modify
666 replace: sn
667 sn: empty
668 EOF
669
670 RC=$?
671 if test $RC != 0; then
672 echo "ldapmodify failed ($RC)!"
673 test $KILLSERVERS != no && kill -HUP $KILLPIDS
674 exit $RC
675 fi
676
677 echo "Adding another unique record..."
678 $LDAPADD -D "$UNIQUEDN" -H $URI1 -w $PASSWD > \
679 $TESTOUT 2>&1 << EOF
680 dn: uid=not edgar,uid=edgar,ou=users,o=unique
681 objectClass: inetOrgPerson
682 uid: not edgar
683 sn: Alan
684 cn: not edgar
685 EOF
686
687 RC=$?
688 if test $RC != 0 ; then
689 echo "unique check failed ($RC)!"
690 test $KILLSERVERS != no && kill -HUP $KILLPIDS
691 exit 1
692 fi
693
694 echo "Making the record non-unique with modrdn..."
695 $LDAPMODRDN -D "uid=dave,ou=users,o=unique" -H $URI1 -w $PASSWD \
696 "uid=not edgar,uid=edgar,ou=users,o=unique" "uid=edgar" > $TESTOUT 2>&1
697
698 RC=$?
699 if test $RC != $RCODEconstraint ; then
700 echo "unique check failed ($RC)!"
701 test $KILLSERVERS != no && kill -HUP $KILLPIDS
702 exit 1
703 fi
704
705 # ITS#6641/8057/8245
706 echo "Trying to bypass uniqueness as a normal user..."
707 $LDAPMODRDN -e \!relax -D "uid=dave,ou=users,o=unique" -H $URI1 -w $PASSWD \
708 "uid=not edgar,uid=edgar,ou=users,o=unique" "uid=edgar" > $TESTOUT 2>&1
709
710 RC=$?
711 if test $RC != $RCODEnorelax && test $RC != $RCODEconstraint ; then
712 echo "unique check failed ($RC)!"
713 test $KILLSERVERS != no && kill -HUP $KILLPIDS
714 exit 1
715 fi
716
717 echo "Trying to bypass uniqueness as a normal user with a ManageDSAIt control..."
718 $LDAPMODRDN -M -D "uid=dave,ou=users,o=unique" -H $URI1 -w $PASSWD \
719 "uid=not edgar,uid=edgar,ou=users,o=unique" "uid=edgar" > $TESTOUT 2>&1
720
721 RC=$?
722 if test $RC != $RCODEconstraint ; then
723 echo "unique check failed ($RC)!"
724 test $KILLSERVERS != no && kill -HUP $KILLPIDS
725 exit 1
726 fi
727
728 echo "Bypassing uniqueness as an admin user..."
729 $LDAPMODRDN -e \!relax -D "$UNIQUEDN" -H $URI1 -w $PASSWD \
730 "uid=not edgar,uid=edgar,ou=users,o=unique" "uid=edgar" > $TESTOUT 2>&1
731
732 RC=$?
733 if test $RC != 0 ; then
734 echo "spurious unique error ($RC)!"
735 test $KILLSERVERS != no && kill -HUP $KILLPIDS
736 exit $RC
737 fi
738
739 echo "Cleaning up"
740 $LDAPDELETE -D "$UNIQUEDN" -H $URI1 -w $PASSWD \
741 "uid=edgar,uid=edgar,ou=users,o=unique" > $TESTOUT 2>&1
742 RC=$?
743 if test $RC != 0; then
744 echo "ldapdelete failed ($RC)!"
745 test $KILLSERVERS != no && kill -HUP $KILLPIDS
746 exit $RC
747 fi
748
749 echo "Adding a record unique in one domain, non-unique in the filtered domain..."
750
751 $LDAPADD -D "uid=dave,ou=users,o=unique" -H $URI1 -w $PASSWD > \
752 $TESTOUT 2>&1 << EOF
753 dn: uid=elvis,ou=users,o=unique
754 objectClass: inetOrgPerson
755 uid: elvis
756 sn: johnson
757 cn: elvis
758 EOF
759
760 RC=$?
761 if test $RC != $RCODEconstraint ; then
762 echo "unique check failed ($RC)!"
763 test $KILLSERVERS != no && kill -HUP $KILLPIDS
764 exit 1
765 fi
766
767 #echo ----------------------
768 echo Dynamically reconfiguring to use attribute-ignore URIs...
769 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF \
770 > $TESTOUT 2>&1 <<EOF
771 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
772 changetype: modify
773 replace: olcUniqueURI
774 olcUniqueURI: ignore ldap:///?objectClass,uid,cn,sn?sub
775 EOF
776 RC=$?
777 if test $RC != 0 ; then
778 echo "unable to reconfigure"
779 test $KILLSERVERS != no && kill -HUP $KILLPIDS
780 exit 1
781 fi
782
783 echo Dynamically retrieving fourth configuration...
784 $LDAPSEARCH -S "" -b olcOverlay='{0}'unique,olcDatabase='{1}'$BACKEND,cn=config -D cn=config -y $CONFIGPWF -H $URI1 -LLL | tr -d \\r >$TESTDIR/fourth-config.ldif
785 cat >$TESTDIR/fourth-reference.ldif <<EOF
786 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
787 objectClass: olcOverlayConfig
788 objectClass: olcUniqueConfig
789 olcOverlay: {0}unique
790 olcUniqueURI: ignore ldap:///?objectClass,uid,cn,sn?sub
791
792 EOF
793 diff $TESTDIR/fourth-config.ldif $TESTDIR/fourth-reference.ldif > /dev/null 2>&1
794 RC=$?
795 if test $RC != 0 ; then
796 echo "Fourth configuration is not reported correctly."
797 test $KILLSERVERS != no && kill -HUP $KILLPIDS
798 exit 1
799 fi
800
801 echo "Adding a record unique in the ignore-domain..."
802
803 $LDAPADD -D "$UNIQUEDN" -H $URI1 -w $PASSWD > \
804 $TESTOUT 2>&1 << EOF
805 dn: uid=elvis,ou=users,o=unique
806 objectClass: inetOrgPerson
807 uid: elvis
808 sn: johnson
809 cn: elvis
810 description: left the building
811 EOF
812
813 RC=$?
814 if test $RC != 0 ; then
815 echo "unique check failed ($RC)!"
816 test $KILLSERVERS != no && kill -HUP $KILLPIDS
817 exit 1
818 fi
819
820 echo "Adding a record non-unique in the ignore-domain..."
821
822 $LDAPADD -D "uid=dave,ou=users,o=unique" -H $URI1 -w $PASSWD > \
823 $TESTOUT 2>&1 << EOF
824 dn: uid=harry,ou=users,o=unique
825 objectClass: inetOrgPerson
826 uid: harry
827 sn: johnson
828 cn: harry
829 description: left the building
830 EOF
831
832 RC=$?
833 if test $RC != $RCODEconstraint ; then
834 echo "unique check failed ($RC)!"
835 test $KILLSERVERS != no && kill -HUP $KILLPIDS
836 exit 1
837 fi
838
839 test $KILLSERVERS != no && kill -HUP $KILLPIDS
840
841 echo ">>>>> Test succeeded"
842
843 test $KILLSERVERS != no && wait
844
845 exit 0