Home | History | Annotate | Line # | Download | only in scripts
      1      1.1  christos #! /bin/sh
      2      1.1  christos ## $OpenLDAP$
      3      1.1  christos ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
      4      1.1  christos ##
      5  1.1.1.2  christos ## Copyright 2016-2024 The OpenLDAP Foundation.
      6      1.1  christos ## All rights reserved.
      7      1.1  christos ##
      8      1.1  christos ## Redistribution and use in source and binary forms, with or without
      9      1.1  christos ## modification, are permitted only as authorized by the OpenLDAP
     10      1.1  christos ## Public License.
     11      1.1  christos ##
     12      1.1  christos ## A copy of this license is available in the file LICENSE in the
     13      1.1  christos ## top-level directory of the distribution or, alternatively, at
     14      1.1  christos ## <http://www.OpenLDAP.org/license.html>.
     15      1.1  christos ##
     16      1.1  christos ## ACKNOWLEDGEMENTS:
     17      1.1  christos ## This module was written in 2016 by Ondej Kuznk for Symas Corp.
     18      1.1  christos 
     19      1.1  christos case "$BACKEND" in ldif | null)
     20      1.1  christos 	echo "$BACKEND backend does not support access controls, test skipped"
     21      1.1  christos 	exit 0
     22      1.1  christos esac
     23      1.1  christos 
     24      1.1  christos echo "running defines.sh"
     25      1.1  christos . $SRCDIR/scripts/defines.sh
     26      1.1  christos 
     27      1.1  christos CONF=$ACLCONF
     28      1.1  christos . ${SCRIPTDIR}/common.sh
     29      1.1  christos 
     30      1.1  christos echo "Applying test-specific configuration..."
     31      1.1  christos . $CONFFILTER $BACKEND $MONITORDB < data/test006-config.ldif | \
     32      1.1  christos $LDAPMODIFY -v -D cn=config -H $URI1 -y $CONFIGPWF \
     33      1.1  christos 	>> $TESTOUT 2>&1
     34      1.1  christos RC=$?
     35      1.1  christos if test $RC != 0 ; then
     36      1.1  christos 	echo "ldapmodify failed ($RC)!"
     37      1.1  christos 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
     38      1.1  christos 	exit $RC
     39      1.1  christos fi
     40      1.1  christos 
     41      1.1  christos $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD >> \
     42      1.1  christos 	$TESTOUT 2>&1 << EOMODS
     43      1.1  christos dn: ou=Add & Delete,dc=example,dc=com
     44      1.1  christos changetype: add
     45      1.1  christos objectClass: organizationalUnit
     46      1.1  christos ou: Add & Delete
     47      1.1  christos 
     48      1.1  christos dn: cn=group,ou=Add & Delete,dc=example,dc=com
     49      1.1  christos changetype: add
     50      1.1  christos objectclass: groupOfNames
     51      1.1  christos member: dc=example,dc=com
     52      1.1  christos 
     53      1.1  christos dn: sn=Doe,ou=Add & Delete,dc=example,dc=com
     54      1.1  christos changetype: add
     55      1.1  christos objectclass: OpenLDAPperson
     56      1.1  christos cn: John
     57      1.1  christos uid: jd
     58      1.1  christos 
     59      1.1  christos dn: sn=Elliot,ou=Add & Delete,dc=example,dc=com
     60      1.1  christos changetype: add
     61      1.1  christos objectclass: OpenLDAPperson
     62      1.1  christos cn: Mark
     63      1.1  christos uid: me
     64      1.1  christos EOMODS
     65      1.1  christos RC=$?
     66      1.1  christos if test $RC != 0 ; then
     67      1.1  christos 	echo "ldapmodify failed ($RC)!"
     68      1.1  christos 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
     69      1.1  christos 	exit $RC
     70      1.1  christos fi
     71      1.1  christos 
     72      1.1  christos echo "Testing search ACL processing..."
     73      1.1  christos 
     74      1.1  christos echo "# Try to read an entry inside the Alumni Association container.
     75      1.1  christos # It should give us noSuchObject if we're not bound..." \
     76      1.1  christos >> $SEARCHOUT
     77      1.1  christos # FIXME: temporarily remove the "No such object" message to make
     78      1.1  christos # the test succeed even if SLAP_ACL_HONOR_DISCLOSE is not #define'd
     79      1.1  christos $LDAPSEARCH -b "$MELLIOTDN" -H $URI1 "(objectclass=*)" \
     80      1.1  christos 	2>&1 | grep -v "No such object" >> $SEARCHOUT
     81      1.1  christos 
     82      1.1  christos echo >>$SEARCHOUT
     83      1.1  christos echo "# ... and should return appropriate attributes if we're bound as anyone
     84      1.1  christos # under Example." \
     85      1.1  christos >> $SEARCHOUT
     86      1.1  christos $LDAPSEARCH -b "$MELLIOTDN" -H $URI1 \
     87      1.1  christos 	-D "$BABSDN" -w bjensen "(objectclass=*)" >> $SEARCHOUT 2>&1
     88      1.1  christos 
     89      1.1  christos $LDAPSEARCH -b "$MELLIOTDN" -H $URI1 \
     90      1.1  christos 	-D "$BJORNSDN" -w bjorn "(objectclass=*)" >> $SEARCHOUT 2>&1
     91      1.1  christos 
     92      1.1  christos echo >>$SEARCHOUT
     93      1.1  christos echo "# Add & Delete subtree contents as seen by Babs" >> $SEARCHOUT
     94      1.1  christos $LDAPSEARCH -b "ou=Add & Delete,dc=example,dc=com" -H $URI1 \
     95      1.1  christos 	-D "$BABSDN" -w bjensen "(objectclass=*)" >> $SEARCHOUT 2>&1
     96      1.1  christos 
     97      1.1  christos echo >>$SEARCHOUT
     98      1.1  christos echo "# Add & Delete subtree contents as seen by Bjorn" >> $SEARCHOUT
     99      1.1  christos $LDAPSEARCH -b "ou=Add & Delete,dc=example,dc=com" -H $URI1 \
    100      1.1  christos 	-D "$BJORNSDN" -w bjorn "(objectclass=*)" >> $SEARCHOUT 2>&1
    101      1.1  christos 
    102      1.1  christos echo "Testing modifications..."
    103      1.1  christos echo "... ACL on the alternative entry"
    104      1.1  christos $LDAPMODIFY -D "$BJORNSDN" -H $URI1 -w bjorn >> \
    105      1.1  christos 	$TESTOUT 2>&1 << EOMODS
    106      1.1  christos dn: cn=group,ou=Add & Delete,dc=example,dc=com
    107      1.1  christos changetype: modify
    108      1.1  christos add: seealso
    109      1.1  christos seealso: $BJORNSDN
    110      1.1  christos EOMODS
    111      1.1  christos RC=$?
    112      1.1  christos if test $RC != 0 ; then
    113      1.1  christos 	echo "ldapmodify failed ($RC)!"
    114      1.1  christos 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    115      1.1  christos 	exit $RC
    116      1.1  christos fi
    117      1.1  christos 
    118      1.1  christos $LDAPMODIFY -D "$BABSDN" -H $URI1 -w bjensen >> \
    119      1.1  christos 	$TESTOUT 2>&1 << EOMODS
    120      1.1  christos dn: cn=Alumni Assoc Staff, ou=Groups, dc=example, dc=com
    121      1.1  christos changetype: modify
    122      1.1  christos add: description
    123      1.1  christos description: added by bjensen (should fail)
    124      1.1  christos EOMODS
    125      1.1  christos RC=$?
    126      1.1  christos case $RC in
    127      1.1  christos 50)
    128      1.1  christos 	;;
    129      1.1  christos 0)
    130      1.1  christos 	echo "ldapmodify should have failed ($RC)!"
    131      1.1  christos 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    132      1.1  christos 	exit -1
    133      1.1  christos 	;;
    134      1.1  christos *)
    135      1.1  christos 	echo "ldapmodify failed ($RC)!"
    136      1.1  christos 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    137      1.1  christos 	exit $RC
    138      1.1  christos 	;;
    139      1.1  christos esac
    140      1.1  christos 
    141      1.1  christos $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD >> \
    142      1.1  christos 	$TESTOUT 2>&1 << EOMODS
    143      1.1  christos dn: cn=group,ou=Add & Delete,dc=example,dc=com
    144      1.1  christos changetype: modify
    145      1.1  christos add: seealso
    146      1.1  christos seealso: $BABSDN
    147      1.1  christos EOMODS
    148      1.1  christos RC=$?
    149      1.1  christos if test $RC != 0 ; then
    150      1.1  christos 	echo "ldapmodify failed ($RC)!"
    151      1.1  christos 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    152      1.1  christos 	exit $RC
    153      1.1  christos fi
    154      1.1  christos 
    155      1.1  christos $LDAPMODIFY -D "$BJORNSDN" -H $URI1 -w bjorn >> \
    156      1.1  christos 	$TESTOUT 2>&1 << EOMODS
    157      1.1  christos dn: cn=Alumni Assoc Staff, ou=Groups, dc=example, dc=com
    158      1.1  christos changetype: modify
    159      1.1  christos add: description
    160      1.1  christos description: added by bjorn (removed later)
    161      1.1  christos EOMODS
    162      1.1  christos RC=$?
    163      1.1  christos if test $RC != 0 ; then
    164      1.1  christos 	echo "ldapmodify failed ($RC)!"
    165      1.1  christos 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    166      1.1  christos 	exit $RC
    167      1.1  christos fi
    168      1.1  christos 
    169      1.1  christos $LDAPMODIFY -D "$BABSDN" -H $URI1 -w bjensen >> \
    170      1.1  christos 	$TESTOUT 2>&1 << EOMODS
    171      1.1  christos dn: cn=Group,ou=Add & Delete,dc=example,dc=com
    172      1.1  christos changetype: modify
    173      1.1  christos delete: description
    174      1.1  christos description: added by bjorn (removed later)
    175      1.1  christos EOMODS
    176      1.1  christos RC=$?
    177      1.1  christos if test $RC != 0 ; then
    178      1.1  christos 	echo "ldapmodify failed ($RC)!"
    179      1.1  christos 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    180      1.1  christos 	exit $RC
    181      1.1  christos fi
    182      1.1  christos 
    183      1.1  christos $LDAPMODIFY -D "$BJORNSDN" -H $URI1 -w bjorn >> \
    184      1.1  christos 	$TESTOUT 2>&1 << EOMODS
    185      1.1  christos dn: cn=Added by Bjorn,ou=Add & Delete,dc=example,dc=com
    186      1.1  christos changetype: add
    187      1.1  christos objectClass: inetOrgPerson
    188      1.1  christos sn: Jensen
    189      1.1  christos EOMODS
    190      1.1  christos RC=$?
    191      1.1  christos if test $RC != 0 ; then
    192      1.1  christos 	echo "ldapmodify failed ($RC)!"
    193      1.1  christos 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    194      1.1  christos 	exit $RC
    195      1.1  christos fi
    196      1.1  christos 
    197      1.1  christos $LDAPMODIFY -D "$BJORNSDN" -H $URI1 -w bjorn >> \
    198      1.1  christos 	$TESTOUT 2>&1 << EOMODS
    199      1.1  christos dn: cn=Group,ou=Add & Delete,dc=example,dc=com
    200      1.1  christos changetype: modify
    201      1.1  christos add: description
    202      1.1  christos description: another one added by bjorn (should succeed)
    203      1.1  christos EOMODS
    204      1.1  christos RC=$?
    205      1.1  christos if test $RC != 0 ; then
    206      1.1  christos 	echo "ldapmodify failed ($RC)!"
    207      1.1  christos 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    208      1.1  christos 	exit $RC
    209      1.1  christos fi
    210      1.1  christos 
    211      1.1  christos echo "... ACL on the variant entry"
    212      1.1  christos $LDAPMODIFY -D "$BABSDN" -H $URI1 -w bjensen >> \
    213      1.1  christos 	$TESTOUT 2>&1 << EOMODS
    214      1.1  christos dn: cn=Group,ou=Add & Delete,dc=example,dc=com
    215      1.1  christos changetype: modify
    216      1.1  christos add: description
    217      1.1  christos description: added by bjensen (should fail)
    218      1.1  christos EOMODS
    219      1.1  christos RC=$?
    220      1.1  christos case $RC in
    221      1.1  christos 50)
    222      1.1  christos 	;;
    223      1.1  christos 0)
    224      1.1  christos 	echo "ldapmodify should have failed ($RC)!"
    225      1.1  christos 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    226      1.1  christos 	exit -1
    227      1.1  christos 	;;
    228      1.1  christos *)
    229      1.1  christos 	echo "ldapmodify failed ($RC)!"
    230      1.1  christos 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    231      1.1  christos 	exit $RC
    232      1.1  christos 	;;
    233      1.1  christos esac
    234      1.1  christos 
    235      1.1  christos $LDAPMODIFY -D "$BJORNSDN" -H $URI1 -w bjorn >> \
    236      1.1  christos 	$TESTOUT 2>&1 << EOMODS
    237      1.1  christos dn: sn=Doe,ou=Add & Delete,dc=example,dc=com
    238      1.1  christos changetype: modify
    239      1.1  christos add: description
    240      1.1  christos description: added by bjorn (will be removed)
    241      1.1  christos EOMODS
    242      1.1  christos RC=$?
    243      1.1  christos if test $RC != 0 ; then
    244      1.1  christos 	echo "ldapmodify failed ($RC)!"
    245      1.1  christos 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    246      1.1  christos 	exit $RC
    247      1.1  christos fi
    248      1.1  christos 
    249      1.1  christos $LDAPMODIFY -D "$BABSDN" -H $URI1 -w bjensen >> \
    250      1.1  christos 	$TESTOUT 2>&1 << EOMODS
    251      1.1  christos dn: cn=Added by Bjorn,ou=Add & Delete,dc=example,dc=com
    252      1.1  christos changetype: modify
    253      1.1  christos replace: description
    254      1.1  christos description: added by bjensen (should fail)
    255      1.1  christos EOMODS
    256      1.1  christos RC=$?
    257      1.1  christos case $RC in
    258      1.1  christos 50)
    259      1.1  christos 	;;
    260      1.1  christos 0)
    261      1.1  christos 	echo "ldapmodify should have failed ($RC)!"
    262      1.1  christos 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    263      1.1  christos 	exit -1
    264      1.1  christos 	;;
    265      1.1  christos *)
    266      1.1  christos 	echo "ldapmodify failed ($RC)!"
    267      1.1  christos 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    268      1.1  christos 	exit $RC
    269      1.1  christos 	;;
    270      1.1  christos esac
    271      1.1  christos 
    272      1.1  christos $LDAPMODIFY -D "$JAJDN" -H $URI1 -w jaj >> \
    273      1.1  christos 	$TESTOUT 2>&1 << EOMODS
    274      1.1  christos dn: sn=Elliot,ou=Add & Delete,dc=example,dc=com
    275      1.1  christos changetype: modify
    276      1.1  christos delete: description
    277      1.1  christos description: added by bjorn (will be removed)
    278      1.1  christos -
    279      1.1  christos add: description
    280      1.1  christos description: added by jaj (should succeed)
    281      1.1  christos EOMODS
    282      1.1  christos RC=$?
    283      1.1  christos if test $RC != 0 ; then
    284      1.1  christos 	echo "ldapmodify failed ($RC)!"
    285      1.1  christos 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    286      1.1  christos 	exit $RC
    287      1.1  christos fi
    288      1.1  christos 
    289      1.1  christos sleep $SLEEP0
    290      1.1  christos 
    291      1.1  christos echo >>$SEARCHOUT
    292      1.1  christos echo "Using ldapsearch to retrieve all the entries..."
    293      1.1  christos echo "# Using ldapsearch to retrieve all the entries..." >> $SEARCHOUT
    294      1.1  christos $LDAPSEARCH -S "" -b "ou=Add & Delete,dc=example,dc=com" \
    295      1.1  christos 	-D "$MANAGERDN" -H $URI1 -w $PASSWD \
    296      1.1  christos 	'objectClass=*' >> $SEARCHOUT 2>&1
    297      1.1  christos RC=$?
    298      1.1  christos if test $RC != 0 ; then
    299      1.1  christos 	echo "ldapsearch failed ($RC)!"
    300      1.1  christos 	exit $RC
    301      1.1  christos fi
    302      1.1  christos 
    303      1.1  christos test $KILLSERVERS != no && kill -HUP $KILLPIDS
    304      1.1  christos 
    305      1.1  christos LDIF=data/test006-out.ldif
    306      1.1  christos 
    307      1.1  christos echo "Filtering ldapsearch results..."
    308      1.1  christos $LDIFFILTER -s e < $SEARCHOUT > $SEARCHFLT
    309      1.1  christos echo "Filtering expected entries..."
    310      1.1  christos $LDIFFILTER -s e < $LDIF > $LDIFFLT
    311      1.1  christos echo "Comparing filter output..."
    312      1.1  christos $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
    313      1.1  christos 
    314      1.1  christos if test $? != 0 ; then
    315      1.1  christos 	echo "comparison failed - operations did not complete correctly"
    316      1.1  christos 	exit 1
    317      1.1  christos fi
    318      1.1  christos 
    319      1.1  christos echo ">>>>> Test succeeded"
    320      1.1  christos 
    321      1.1  christos test $KILLSERVERS != no && wait
    322      1.1  christos 
    323      1.1  christos exit 0
    324