1#!/bin/bash 2 3echo "running defines.sh" 4. $SRCDIR/scripts/defines.sh 5 6if test $CONSTRAINT = constraintno; then 7 echo "Constraint overlay not available, test skipped" 8 exit 0 9fi 10 11CONSTRAINTDIR="$DATADIR/constraint" 12ROOTLDIF="$CONSTRAINTDIR/root.ldif" 13USERLDIF="$CONSTRAINTDIR/user.ldif" 14RESULTOUT="$CONSTRAINTDIR/constraint.out" 15SCRIPTOUT="$TESTDIR/constraint.out" 16USERDN="cn=John Doe,ou=users,$BASEDN" 17 18CONFDIR=$TESTDIR/slapd.d 19mkdir -p $TESTDIR $CONFDIR $DBDIR1 20 21$SLAPPASSWD -g -n >$CONFIGPWF 22 23cat > $TESTDIR/config.ldif <<EOF 24dn: cn=config 25objectClass: olcGlobal 26cn: config 27olcArgsFile: $TESTDIR/slapd.args 28olcPidFile: $TESTDIR/slapd.pid 29 30dn: cn=schema,cn=config 31objectClass: olcSchemaConfig 32cn: schema 33 34include: file://$TESTWD/schema/core.ldif 35include: file://$TESTWD/schema/cosine.ldif 36include: file://$TESTWD/schema/inetorgperson.ldif 37 38dn: olcDatabase=config,cn=config 39objectClass: olcDatabaseConfig 40olcDatabase: config 41olcRootPW:< file://$CONFIGPWF 42EOF 43 44if [ "$BACKENDTYPE" = mod ]; then 45 cat >> $TESTDIR/config.ldif <<EOF 46 47dn: cn=module,cn=config 48objectClass: olcModuleList 49cn: module 50olcModulePath: $TESTWD/../servers/slapd/back-$BACKEND 51olcModuleLoad: back_$BACKEND.la 52EOF 53fi 54 55if [ "$CONSTRAINT" = constraintmod ]; then 56 cat >> $TESTDIR/config.ldif <<EOF 57 58dn: cn=module,cn=config 59objectClass: olcModuleList 60cn: module 61olcModulePath: $TESTWD/../servers/slapd/overlays 62olcModuleLoad: constraint.la 63EOF 64fi 65 66cat >> $TESTDIR/config.ldif <<EOF 67 68dn: olcDatabase={1}$BACKEND,cn=config 69objectClass: olcDatabaseConfig 70objectClass: olc${BACKEND}Config 71olcDatabase: $BACKEND 72olcSuffix: $BASEDN 73olcRootDN: $MANAGERDN 74olcRootPW: $PASSWD 75olcDbDirectory: $TESTDIR/db.1.a 76EOF 77 78if [ "$INDEXDB" = indexdb ]; then 79 cat >> $TESTDIR/config.ldif <<EOF 80olcDbIndex: objectClass eq,pres 81olcDbIndex: ou,cn,mail,surname,givenname eq,pres,sub 82EOF 83fi 84 85cat >> $TESTDIR/config.ldif <<EOF 86 87dn: olcOverlay=constraint,olcDatabase={1}$BACKEND,cn=config 88objectClass: olcOverlayConfig 89objectClass: olcConstraintConfig 90olcOverlay: constraint 91olcConstraintAttribute: mail 92 count 3 93 restrict="ldap:///ou=users,$BASEDN??one?(objectClass=inetOrgPerson)" 94# check if restrict works (if not, this will apply to ou=users subtree as well 95# and some tests will fail) 96olcConstraintAttribute: mail count 1 restrict="ldap:///ou=groups,$BASEDN??one" 97olcConstraintAttribute: mail regex ^[[:alnum:]]+@example.com$ 98olcConstraintAttribute: description count 2 99olcConstraintAttribute: jpegPhoto count 0 100# cn value has to be concatenated givenName SP sn 101olcConstraintAttribute: cn,sn,givenName 102 set "(this/givenName + [ ] + this/sn) & this/cn" 103 restrict="ldap:///$USERDN??sub?(objectClass=inetOrgPerson)" 104olcConstraintAttribute: uid 105 uri "ldap:///ou=groups,$BASEDN?uid?one?(objectClass=inetOrgPerson)" 106 restrict="ldap:///ou=users,$BASEDN??one" 107EOF 108 109$SLAPADD -F $CONFDIR -n 0 -l $TESTDIR/config.ldif 110 111echo "Starting slapd on TCP/IP port $PORT1..." 112$SLAPD -F $CONFDIR -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 & 113PID=$! 114if test $WAIT != 0 ; then 115 echo PID $PID 116 read foo 117fi 118KILLPIDS="$PID" 119sleep 1 120 121echo "Using ldapsearch to check that slapd is running..." 122for i in 0 1 2 3 4 5; do 123 $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \ 124 'objectclass=*' > /dev/null 2>&1 125 RC=$? 126 if test $RC = 0 ; then 127 break 128 fi 129 echo "Waiting 5 seconds for slapd to start..." 130 sleep 5 131done 132if test $RC != 0 ; then 133 echo "ldapsearch failed ($RC)!" 134 test $KILLSERVERS != no && kill -HUP $KILLPIDS 135 exit $RC 136fi 137 138echo "Adding basic structure..." 139$LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $ROOTLDIF &>/dev/null 140RC=$? 141if test $RC != 0 ; then 142 echo "ldapadd failed ($RC)!" 143 test $KILLSERVERS != no && kill -HUP $PID 144 exit $RC 145fi 146$LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $USERLDIF &>/dev/null 147RC=$? 148if test $RC != 0 ; then 149 echo "ldapadd failed ($RC)!" 150 test $KILLSERVERS != no && kill -HUP $PID 151 exit $RC 152fi 153 154echo "Running constraint tests..." 155for ldif in $SRCDIR/data/constraint/{*ok*,*fail*}.ldif; do 156 ### reload 157 $LDAPDELETE -D "$MANAGERDN" -H $URI1 -w $PASSWD "$USERDN" &>/dev/null 158 RC=$? 159 if test $RC != 0 ; then 160 echo "ldapdelete failed ($RC)!" 161 test $KILLSERVERS != no && kill -HUP $PID 162 exit $RC 163 fi 164 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $USERLDIF &>/dev/null 165 RC=$? 166 if test $RC != 0 ; then 167 echo "ldapadd failed ($RC)!" 168 test $KILLSERVERS != no && kill -HUP $PID 169 exit $RC 170 fi 171 172 ### info 173 echo -n " [$ldif]: " 174 175 ### modify 176 $LDAPMODIFY -H $URI1 -x -D "$MANAGERDN" -f $ldif -w $PASSWD &>/dev/null 177 RC=$? 178 if test $RC == 0 ; then 179 echo "OK" | tee -a $SCRIPTOUT 180 elif test $RC == 19 ; then 181 echo "FAIL" | tee -a $SCRIPTOUT 182 else 183 echo "UNEXPECTED ($RC)" 184 fi 185done 186 187echo "Comparing output..." 188$DIFF $SCRIPTOUT $RESULTOUT > $CMPOUT 189RC=$? 190if test $RC != 0 ; then 191 echo "Comparison failed" 192 test $KILLSERVERS != no && kill -HUP $PID 193 exit $RC 194fi 195 196test $KILLSERVERS != no && kill -HUP $PID 197 198echo ">>>>> Test succeeded" 199 200test $KILLSERVERS != no && wait 201 202exit 0 203