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