| 1 | #!/bin/sh |
| 2 | # $OpenLDAP$ |
| 3 | ## This work is part of OpenLDAP Software <http://www.openldap.org/>. |
| 4 | ## |
| 5 | ## Copyright 2021-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 $ARGON2 = argon2no; then |
| 20 | echo "argon2 overlay not available, test skipped" |
| 21 | exit 0 |
| 22 | fi |
| 23 | |
| 24 | USERDN="cn=argon2,$BASEDN" |
| 25 | |
| 26 | CONFDIR=$TESTDIR/slapd.d |
| 27 | mkdir -p $TESTDIR $CONFDIR $DBDIR1 |
| 28 | |
| 29 | $SLAPPASSWD -g -n >$CONFIGPWF |
| 30 | |
| 31 | cat > $TESTDIR/config.ldif <<EOF |
| 32 | dn: cn=config |
| 33 | objectClass: olcGlobal |
| 34 | cn: config |
| 35 | olcArgsFile: $TESTDIR/slapd.args |
| 36 | olcPidFile: $TESTDIR/slapd.pid |
| 37 | |
| 38 | dn: cn=schema,cn=config |
| 39 | objectClass: olcSchemaConfig |
| 40 | cn: schema |
| 41 | |
| 42 | include: file://$TESTWD/schema/core.ldif |
| 43 | include: file://$TESTWD/schema/cosine.ldif |
| 44 | include: file://$TESTWD/schema/inetorgperson.ldif |
| 45 | EOF |
| 46 | |
| 47 | if [ "$BACKENDTYPE" = mod ]; then |
| 48 | cat >> $TESTDIR/config.ldif <<EOF |
| 49 | |
| 50 | dn: cn=module,cn=config |
| 51 | objectClass: olcModuleList |
| 52 | cn: module |
| 53 | olcModulePath: $TESTWD/../servers/slapd/back-$BACKEND |
| 54 | olcModuleLoad: back_$BACKEND.la |
| 55 | EOF |
| 56 | fi |
| 57 | |
| 58 | if [ "$ARGON2" = argon2yes ]; then |
| 59 | cat >> $TESTDIR/config.ldif <<EOF |
| 60 | |
| 61 | dn: cn=module,cn=config |
| 62 | objectClass: olcModuleList |
| 63 | cn: module |
| 64 | olcModulePath: $TESTWD/../servers/slapd/pwmods |
| 65 | olcModuleLoad: argon2.la |
| 66 | EOF |
| 67 | fi |
| 68 | |
| 69 | cat >> $TESTDIR/config.ldif <<EOF |
| 70 | |
| 71 | dn: olcDatabase={-1}frontend,cn=config |
| 72 | objectClass: olcDatabaseConfig |
| 73 | objectClass: olcFrontendConfig |
| 74 | olcDatabase: {-1}frontend |
| 75 | olcPasswordHash: {ARGON2} |
| 76 | |
| 77 | dn: olcDatabase=config,cn=config |
| 78 | objectClass: olcDatabaseConfig |
| 79 | olcDatabase: config |
| 80 | olcRootPW:< file://$CONFIGPWF |
| 81 | |
| 82 | dn: olcDatabase={1}$BACKEND,cn=config |
| 83 | objectClass: olcDatabaseConfig |
| 84 | objectClass: olc${BACKEND}Config |
| 85 | olcDatabase: $BACKEND |
| 86 | olcSuffix: $BASEDN |
| 87 | olcRootDN: $MANAGERDN |
| 88 | olcRootPW: $PASSWD |
| 89 | olcDbDirectory: $TESTDIR/db.1.a |
| 90 | EOF |
| 91 | |
| 92 | if [ "$INDEXDB" = indexdb ]; then |
| 93 | cat >> $TESTDIR/config.ldif <<EOF |
| 94 | olcDbIndex: objectClass eq,pres |
| 95 | olcDbIndex: ou,cn,mail,surname,givenname eq,pres,sub |
| 96 | EOF |
| 97 | fi |
| 98 | |
| 99 | $SLAPADD -F $CONFDIR -n 0 -l $TESTDIR/config.ldif |
| 100 | RC=$? |
| 101 | if test $RC != 0 ; then |
| 102 | echo "slapadd failed ($RC)!" |
| 103 | exit $RC |
| 104 | fi |
| 105 | |
| 106 | echo "Starting slapd on TCP/IP port $PORT1..." |
| 107 | $SLAPD -F $CONFDIR -h $URI1 -d $LVL > $LOG1 2>&1 & |
| 108 | PID=$! |
| 109 | if test $WAIT != 0 ; then |
| 110 | echo PID $PID |
| 111 | read foo |
| 112 | fi |
| 113 | KILLPIDS="$PID" |
| 114 | sleep 1 |
| 115 | |
| 116 | echo "Using ldapsearch to check that slapd is running..." |
| 117 | for i in 0 1 2 3 4 5; do |
| 118 | $LDAPSEARCH -s base -b "$MONITOR" -H $URI1 \ |
| 119 | 'objectclass=*' > /dev/null 2>&1 |
| 120 | RC=$? |
| 121 | if test $RC = 0 ; then |
| 122 | break |
| 123 | fi |
| 124 | echo "Waiting 5 seconds for slapd to start..." |
| 125 | sleep 5 |
| 126 | done |
| 127 | if test $RC != 0 ; then |
| 128 | echo "ldapsearch failed ($RC)!" |
| 129 | test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 130 | exit $RC |
| 131 | fi |
| 132 | |
| 133 | echo "Adding basic structure..." |
| 134 | $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFPASSWD >/dev/null 2>&1 |
| 135 | RC=$? |
| 136 | if test $RC != 0 ; then |
| 137 | echo "ldapadd failed ($RC)!" |
| 138 | test $KILLSERVERS != no && kill -HUP $PID |
| 139 | exit $RC |
| 140 | fi |
| 141 | |
| 142 | BINDPW=secret |
| 143 | echo "Testing ldapwhoami as ${USERDN}..." |
| 144 | $LDAPWHOAMI -H $URI1 -D "$USERDN" -w $BINDPW |
| 145 | |
| 146 | RC=$? |
| 147 | if test $RC != 0 ; then |
| 148 | echo "ldapwhoami failed ($RC)!" |
| 149 | test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 150 | exit $RC |
| 151 | fi |
| 152 | |
| 153 | test $KILLSERVERS != no && kill -HUP $PID |
| 154 | |
| 155 | echo ">>>>> Test succeeded" |
| 156 | |
| 157 | test $KILLSERVERS != no && wait |
| 158 | |
| 159 | exit 0 |