1#! /bin/sh 2# $OpenLDAP$ 3## This work is part of OpenLDAP Software <http://www.openldap.org/>. 4## 5## Copyright 2021 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 16echo "running defines.sh" 17. $SRCDIR/scripts/defines.sh 18 19if test $HOMEDIR = homedirno; then 20 echo "Homedir overlay not available, test skipped" 21 exit 0 22fi 23 24mkdir -p $TESTDIR $DBDIR1 $TESTDIR/home $TESTDIR/archive 25 26$SLAPPASSWD -g -n >$CONFIGPWF 27echo "rootpw `$SLAPPASSWD -T $CONFIGPWF`" >$TESTDIR/configpw.conf 28 29echo "Running slapadd to build slapd database..." 30. $CONFFILTER $BACKEND < $HOMEDIRCONF | sed "s/@MINUID@/`id -u`/" > $CONF1 31$SLAPADD -f $CONF1 -l $LDIF 32RC=$? 33if test $RC != 0 ; then 34 echo "slapadd failed ($RC)!" 35 exit $RC 36fi 37 38echo "Starting slapd on TCP/IP port $PORT1..." 39$SLAPD -f $CONF1 -h $URI1 -d $LVL > $LOG1 2>&1 & 40PID=$! 41if test $WAIT != 0 ; then 42 echo PID $PID 43 read foo 44fi 45KILLPIDS="$PID" 46 47sleep 1 48 49echo "Using ldapsearch to check that slapd is running..." 50for i in 0 1 2 3 4 5; do 51 $LDAPSEARCH -s base -b "$MONITOR" -H $URI1 \ 52 'objectclass=*' > /dev/null 2>&1 53 RC=$? 54 if test $RC = 0 ; then 55 break 56 fi 57 echo "Waiting 5 seconds for slapd to start..." 58 sleep 5 59done 60if test $RC != 0 ; then 61 echo "ldapsearch failed ($RC)!" 62 test $KILLSERVERS != no && kill -HUP $KILLPIDS 63 exit $RC 64fi 65 66echo "Adding a new user..." 67$LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD <<EOMOD >> $TESTOUT 2>&1 68dn: uid=user1,ou=People,$BASEDN 69objectClass: account 70objectClass: posixAccount 71uid: user1 72cn: One user 73uidNumber: `id -u` 74gidNumber: `id -g` 75homeDirectory: /home/user1 76EOMOD 77RC=$? 78if test $RC != 0 ; then 79 echo "ldapadd failed ($RC)!" 80 test $KILLSERVERS != no && kill -HUP $KILLPIDS 81 exit $RC 82fi 83 84sleep 1 85 86if ! test -e $TESTDIR/home/user1 ; then 87 echo "Home directory for user1 not created!" 88 test $KILLSERVERS != no && kill -HUP $KILLPIDS 89 exit 1 90fi 91 92echo "Moving home directory for user1..." 93$LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD <<EOMOD >> $TESTOUT 2>&1 94dn: uid=user1,ou=People,$BASEDN 95changetype: modify 96replace: homeDirectory 97homeDirectory: /home/user1_new 98EOMOD 99RC=$? 100if test $RC != 0 ; then 101 echo "ldapadd failed ($RC)!" 102 test $KILLSERVERS != no && kill -HUP $KILLPIDS 103 exit $RC 104fi 105 106sleep 1 107 108if test -e $TESTDIR/home/user1 || ! test -e $TESTDIR/home/user1_new ; then 109 echo "Home directory for user1 not moved!" 110 test $KILLSERVERS != no && kill -HUP $KILLPIDS 111 exit 1 112fi 113 114echo "Removing user1, should get archived..." 115$LDAPDELETE -D "$MANAGERDN" -H $URI1 -w $PASSWD \ 116 "uid=user1,ou=People,$BASEDN" >> $TESTOUT 117RC=$? 118if test $RC != 0 ; then 119 echo "ldapdelete failed ($RC)!" 120 test $KILLSERVERS != no && kill -HUP $KILLPIDS 121 exit $RC 122fi 123 124sleep 1 125 126if test -e $TESTDIR/home/user1_new || \ 127 ! test -e $TESTDIR/archive/user1_new-*-0.tar ; then 128 echo "Home directory for user1 not archived properly!" 129 test $KILLSERVERS != no && kill -HUP $KILLPIDS 130 exit 1 131fi 132 133test $KILLSERVERS != no && kill -HUP $KILLPIDS 134 135test $KILLSERVERS != no && wait 136 137echo ">>>>> Test succeeded" 138 139exit 0 140