Home | History | Annotate | Line # | Download | only in scripts
test041-aci revision 1.1.1.6.6.1
      1 #! /bin/sh
      2 # $OpenLDAP$
      3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
      4 ##
      5 ## Copyright 1998-2019 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 case "$BACKEND" in ldif | null)
     17 	echo "$BACKEND backend does not support access controls, test skipped"
     18 	exit 0
     19 	;;
     20 esac
     21 
     22 echo "running defines.sh"
     23 . $SRCDIR/scripts/defines.sh
     24 
     25 if test "$ACI" = "acino" ; then
     26 	echo "ACI not enabled, test skipped"
     27 	exit 0
     28 fi
     29 
     30 mkdir -p $TESTDIR $DBDIR1
     31 
     32 echo "Running slapadd to build slapd database..."
     33 . $CONFFILTER $BACKEND $MONITORDB < $ACICONF > $CONF1
     34 $SLAPADD -f $CONF1 -l $LDIFORDERED
     35 RC=$?
     36 if test $RC != 0 ; then
     37 	echo "slapadd failed ($RC)!"
     38 	exit $RC
     39 fi
     40 
     41 echo "Starting slapd on TCP/IP port $PORT1..."
     42 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
     43 PID=$!
     44 if test $WAIT != 0 ; then
     45     echo PID $PID
     46     read foo
     47 fi
     48 KILLPIDS="$PID"
     49 
     50 sleep 1
     51 
     52 echo "Testing slapd ACI access control..."
     53 for i in 0 1 2 3 4 5; do
     54 	$LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
     55 		'objectclass=*' > /dev/null 2>&1
     56 	RC=$?
     57 	if test $RC = 0 ; then
     58 		break
     59 	fi
     60 	echo "Waiting 5 seconds for slapd to start..."
     61 	sleep 5
     62 done
     63 
     64 if test $RC != 0 ; then
     65 	echo "ldapsearch failed ($RC)!"
     66 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
     67 	exit $RC
     68 fi
     69 
     70 cat /dev/null > $SEARCHOUT
     71 cat /dev/null > $TESTOUT
     72 
     73 # Search must fail
     74 BASEDN="dc=example,dc=com"
     75 echo "Searching \"$BASEDN\" (should fail)..."
     76 echo "# Searching \"$BASEDN\" (should fail)..." >> $SEARCHOUT
     77 $LDAPSEARCH -s base -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
     78 	'(objectclass=*)' >> $SEARCHOUT 2>> $TESTOUT
     79 RC=$?
     80 if test $RC != 32 ; then
     81 	echo "ldapsearch should have failed with noSuchObject ($RC)!"
     82 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
     83 	if test $RC = 0 ; then
     84 		exit -1
     85 	fi
     86 	exit $RC
     87 fi
     88 
     89 # Bind must fail
     90 BINDDN="cn=Barbara Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com"
     91 BINDPW=bjensen
     92 echo "Testing ldapwhoami as ${BINDDN} (should fail)..."
     93 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "$BINDDN" -w $BINDPW
     94 RC=$?
     95 if test $RC = 0 ; then
     96 	echo "ldapwhoami should have failed!"
     97 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
     98 	exit -1
     99 fi
    100 
    101 # Populate ACIs
    102 echo "Writing ACIs as \"$MANAGERDN\"..."
    103 $LDAPMODIFY -D "$MANAGERDN" -w $PASSWD -h $LOCALHOST -p $PORT1 \
    104 	>> $TESTOUT 2>&1 << EOMODS0
    105 dn: dc=example,dc=com
    106 changetype: modify
    107 add: OpenLDAPaci
    108 OpenLDAPaci: 0#subtree#grant;d,c,s,r;[all]#group/groupOfUniqueNames/uniqueMe
    109  mber#cn=ITD Staff,ou=Groups,dc=example,dc=com
    110 OpenLDAPaci: 1#entry#grant;d;[all]#public#
    111 
    112 dn: ou=People,dc=example,dc=com
    113 changetype: modify
    114 add: OpenLDAPaci
    115 OpenLDAPaci: 0#subtree#grant;x;userPassword#public#
    116 OpenLDAPaci: 1#subtree#grant;w;userPassword#self#
    117 OpenLDAPaci: 2#subtree#grant;w;userPassword#access-id#cn=Bjorn Jensen,ou=Inf
    118  ormation Technology Division,ou=People,dc=example,dc=com
    119 
    120 dn: ou=Groups,dc=example,dc=com
    121 changetype: modify
    122 add: OpenLDAPaci
    123 OpenLDAPaci: 0#entry#grant;s;[all]#public#
    124 OpenLDAPaci: 1#children#grant;r;member;r;uniqueMember#access-id#cn=Bjorn Jen
    125  sen,ou=Information Technology Division,ou=People,dc=example,dc=com
    126 EOMODS0
    127 RC=$?
    128 if test $RC != 0 ; then
    129 	echo "ldapmodify failed ($RC)!"
    130 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    131 	exit $RC
    132 fi
    133 
    134 # Search must succeed with no results
    135 BASEDN="dc=example,dc=com"
    136 echo "Searching \"$BASEDN\" (should succeed with no results)..."
    137 echo "# Searching \"$BASEDN\" (should succeed with no results)..." >> $SEARCHOUT
    138 $LDAPSEARCH -s base -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
    139 	'(objectclass=*)' >> $SEARCHOUT 2>> $TESTOUT
    140 RC=$?
    141 if test $RC != 0 ; then
    142 	### TEMPORARY (see ITS#3963)
    143 	echo "ldapsearch failed ($RC)! IGNORED..."
    144 	###echo "ldapsearch failed ($RC)!"
    145 	###test $KILLSERVERS != no && kill -HUP $KILLPIDS
    146 	###exit $RC
    147 fi
    148 
    149 BINDDN="cn=Barbara Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com"
    150 BINDPW=bjensen
    151 echo "Testing ldapwhoami as ${BINDDN}..."
    152 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "$BINDDN" -w $BINDPW
    153 RC=$?
    154 if test $RC != 0 ; then
    155 	echo "ldapwhoami failed ($RC)!"
    156 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    157 	exit $RC
    158 fi
    159 
    160 # Search must succeed 
    161 BINDDN="cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com"
    162 BINDPW=bjorn
    163 BASEDN="dc=example,dc=com"
    164 echo "Searching \"$BASEDN\" as \"$BINDDN\" (should succeed)..."
    165 echo "# Searching \"$BASEDN\" as \"$BINDDN\" (should succeed)..." >> $SEARCHOUT
    166 $LDAPSEARCH -s base -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
    167 	-D "$BINDDN" -w "$BINDPW" \
    168 	'(objectClass=*)' >> $SEARCHOUT 2>> $TESTOUT
    169 RC=$?
    170 if test $RC != 0 ; then
    171 	echo "ldapsearch failed ($RC)!"
    172 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    173 	exit $RC
    174 fi
    175 
    176 # Passwd must succeed 
    177 BINDDN="cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com"
    178 BINDPW=bjorn
    179 TGT="cn=John Doe,ou=Information Technology Division,ou=People,dc=example,dc=com"
    180 NEWPW=jdoe
    181 echo "Setting \"$TGT\" password..."
    182 $LDAPPASSWD -h $LOCALHOST -p $PORT1 \
    183 	-w "$BINDPW" -s "$NEWPW" \
    184 	-D "$BINDDN" "$TGT" >> $TESTOUT 2>&1
    185 RC=$?
    186 if test $RC != 0 ; then
    187 	echo "ldappasswd failed ($RC)!"
    188 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    189 	exit $RC
    190 fi
    191 
    192 # Re-change as self...
    193 echo "Changing self password..."
    194 BINDDN="$TGT"
    195 BINDPW=$NEWPW
    196 TGT="cn=John Doe,ou=Information Technology Division,ou=People,dc=example,dc=com"
    197 NEWPW=newcred
    198 $LDAPPASSWD -h $LOCALHOST -p $PORT1 \
    199 	-w "$BINDPW" -s "$NEWPW" \
    200 	-D "$BINDDN" "$TGT" >> $TESTOUT 2>&1
    201 RC=$?
    202 if test $RC != 0 ; then
    203 	echo "ldappasswd failed ($RC)!"
    204 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    205 	exit $RC
    206 fi
    207 
    208 # Searching groups
    209 BINDPW=$NEWPW
    210 BASEDN="ou=Groups,dc=example,dc=com"
    211 echo "Searching \"$BASEDN\" as \"$BINDDN\" (should succeed)..."
    212 echo "# Searching \"$BASEDN\" as \"$BINDDN\" (should succeed)..." >> $SEARCHOUT
    213 $LDAPSEARCH -s one -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
    214 	-D "$BINDDN" -w "$BINDPW" \
    215 	'(objectClass=*)' >> $SEARCHOUT 2>> $TESTOUT
    216 RC=$?
    217 if test $RC != 0 ; then
    218 	echo "ldapsearch failed ($RC)!"
    219 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    220 	exit $RC
    221 fi
    222 
    223 # Search must fail
    224 BINDDN="cn=Barbara Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com"
    225 BINDPW=bjensen
    226 echo "Searching \"$BASEDN\" as \"$BINDDN\" (should succeed with no results)..."
    227 echo "# Searching \"$BASEDN\" as \"$BINDDN\" (should succeed with no results)..." >> $SEARCHOUT
    228 $LDAPSEARCH -s one -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
    229 	-D "$BINDDN" -w "$BINDPW" \
    230 	'(objectClass=*)' >> $SEARCHOUT 2>> $TESTOUT
    231 RC=$?
    232 if test $RC != 0 ; then
    233 	echo "ldapsearch failed ($RC)!"
    234 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    235 	exit $RC
    236 fi
    237 
    238 test $KILLSERVERS != no && kill -HUP $KILLPIDS
    239 
    240 LDIF=$ACIOUT
    241 
    242 echo "Filtering ldapsearch results..."
    243 $LDIFFILTER -s mdb=e < $SEARCHOUT > $SEARCHFLT
    244 echo "Filtering original ldif used to create database..."
    245 $LDIFFILTER -s mdb=e < $LDIF > $LDIFFLT
    246 echo "Comparing filter output..."
    247 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
    248 
    249 if test $? != 0 ; then
    250 	echo "comparison failed - operations did not complete correctly"
    251 	exit 1
    252 fi
    253 
    254 echo ">>>>> Test succeeded"
    255 
    256 test $KILLSERVERS != no && wait
    257 
    258 exit 0
    259