3 echo "running defines.sh"
4 . $SRCDIR/scripts/defines.sh
6 if test $CONSTRAINT = constraintno; then
7 echo "Constraint overlay not available, test skipped"
11 CONSTRAINTDIR="$DATADIR/constraint"
12 ROOTLDIF="$CONSTRAINTDIR/root.ldif"
13 USERLDIF="$CONSTRAINTDIR/user.ldif"
14 RESULTOUT="$CONSTRAINTDIR/constraint.out"
15 SCRIPTOUT="$TESTDIR/constraint.out"
16 USERDN="cn=John Doe,ou=users,$BASEDN"
18 CONFDIR=$TESTDIR/slapd.d
19 mkdir -p $TESTDIR $CONFDIR $DBDIR1
21 $SLAPPASSWD -g -n >$CONFIGPWF
23 cat > $TESTDIR/config.ldif <<EOF
25 objectClass: olcGlobal
27 olcArgsFile: $TESTDIR/slapd.args
28 olcPidFile: $TESTDIR/slapd.pid
30 dn: cn=schema,cn=config
31 objectClass: olcSchemaConfig
34 include: file://$TESTWD/schema/core.ldif
35 include: file://$TESTWD/schema/cosine.ldif
36 include: file://$TESTWD/schema/inetorgperson.ldif
38 dn: olcDatabase=config,cn=config
39 objectClass: olcDatabaseConfig
41 olcRootPW:< file://$CONFIGPWF
44 if [ "$BACKENDTYPE" = mod ]; then
45 cat >> $TESTDIR/config.ldif <<EOF
47 dn: cn=module,cn=config
48 objectClass: olcModuleList
50 olcModulePath: $TESTWD/../servers/slapd/back-$BACKEND
51 olcModuleLoad: back_$BACKEND.la
55 if [ "$CONSTRAINT" = constraintmod ]; then
56 cat >> $TESTDIR/config.ldif <<EOF
58 dn: cn=module,cn=config
59 objectClass: olcModuleList
61 olcModulePath: $TESTWD/../servers/slapd/overlays
62 olcModuleLoad: constraint.la
66 cat >> $TESTDIR/config.ldif <<EOF
68 dn: olcDatabase={1}$BACKEND,cn=config
69 objectClass: olcDatabaseConfig
70 objectClass: olc${BACKEND}Config
75 olcDbDirectory: $TESTDIR/db.1.a
78 if [ "$INDEXDB" = indexdb ]; then
79 cat >> $TESTDIR/config.ldif <<EOF
80 olcDbIndex: objectClass eq,pres
81 olcDbIndex: ou,cn,mail,surname,givenname eq,pres,sub
85 cat >> $TESTDIR/config.ldif <<EOF
87 dn: olcOverlay=constraint,olcDatabase={1}$BACKEND,cn=config
88 objectClass: olcOverlayConfig
89 objectClass: olcConstraintConfig
90 olcOverlay: constraint
91 olcConstraintAttribute: mail
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)
96 olcConstraintAttribute: mail count 1 restrict="ldap:///ou=groups,$BASEDN??one"
97 olcConstraintAttribute: mail regex ^[[:alnum:]]+@example.com$
98 olcConstraintAttribute: description count 2
99 olcConstraintAttribute: jpegPhoto count 0
100 # cn value has to be concatenated givenName SP sn
101 olcConstraintAttribute: cn,sn,givenName
102 set "(this/givenName + [ ] + this/sn) & this/cn"
103 restrict="ldap:///$USERDN??sub?(objectClass=inetOrgPerson)"
104 olcConstraintAttribute: uid
105 uri "ldap:///ou=groups,$BASEDN?uid?one?(objectClass=inetOrgPerson)"
106 restrict="ldap:///ou=users,$BASEDN??one"
109 $SLAPADD -F $CONFDIR -n 0 -l $TESTDIR/config.ldif
111 echo "Starting slapd on TCP/IP port $PORT1..."
112 $SLAPD -F $CONFDIR -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
114 if test $WAIT != 0 ; then
121 echo "Using ldapsearch to check that slapd is running..."
122 for 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
126 if test $RC = 0 ; then
129 echo "Waiting 5 seconds for slapd to start..."
132 if test $RC != 0 ; then
133 echo "ldapsearch failed ($RC)!"
134 test $KILLSERVERS != no && kill -HUP $KILLPIDS
138 echo "Adding basic structure..."
139 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $ROOTLDIF &>/dev/null
141 if test $RC != 0 ; then
142 echo "ldapadd failed ($RC)!"
143 test $KILLSERVERS != no && kill -HUP $PID
146 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $USERLDIF &>/dev/null
148 if test $RC != 0 ; then
149 echo "ldapadd failed ($RC)!"
150 test $KILLSERVERS != no && kill -HUP $PID
154 echo "Running constraint tests..."
155 for ldif in $SRCDIR/data/constraint/{*ok*,*fail*}.ldif; do
157 $LDAPDELETE -D "$MANAGERDN" -H $URI1 -w $PASSWD "$USERDN" &>/dev/null
159 if test $RC != 0 ; then
160 echo "ldapdelete failed ($RC)!"
161 test $KILLSERVERS != no && kill -HUP $PID
164 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $USERLDIF &>/dev/null
166 if test $RC != 0 ; then
167 echo "ldapadd failed ($RC)!"
168 test $KILLSERVERS != no && kill -HUP $PID
176 $LDAPMODIFY -H $URI1 -x -D "$MANAGERDN" -f $ldif -w $PASSWD &>/dev/null
178 if test $RC == 0 ; then
179 echo "OK" | tee -a $SCRIPTOUT
180 elif test $RC == 19 ; then
181 echo "FAIL" | tee -a $SCRIPTOUT
183 echo "UNEXPECTED ($RC)"
187 echo "Comparing output..."
188 $DIFF $SCRIPTOUT $RESULTOUT > $CMPOUT
190 if test $RC != 0 ; then
191 echo "Comparison failed"
192 test $KILLSERVERS != no && kill -HUP $PID
196 test $KILLSERVERS != no && kill -HUP $PID
198 echo ">>>>> Test succeeded"
200 test $KILLSERVERS != no && wait