xref: /netbsd-src/external/bsd/openldap/dist/tests/scripts/test085-homedir (revision e670fd5c413e99c2f6a37901bb21c537fcd322d2)
1*e670fd5cSchristos#! /bin/sh
2*e670fd5cSchristos# $OpenLDAP$
3*e670fd5cSchristos## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4*e670fd5cSchristos##
5*e670fd5cSchristos## Copyright 2021 The OpenLDAP Foundation.
6*e670fd5cSchristos## All rights reserved.
7*e670fd5cSchristos##
8*e670fd5cSchristos## Redistribution and use in source and binary forms, with or without
9*e670fd5cSchristos## modification, are permitted only as authorized by the OpenLDAP
10*e670fd5cSchristos## Public License.
11*e670fd5cSchristos##
12*e670fd5cSchristos## A copy of this license is available in the file LICENSE in the
13*e670fd5cSchristos## top-level directory of the distribution or, alternatively, at
14*e670fd5cSchristos## <http://www.OpenLDAP.org/license.html>.
15*e670fd5cSchristos
16*e670fd5cSchristosecho "running defines.sh"
17*e670fd5cSchristos. $SRCDIR/scripts/defines.sh
18*e670fd5cSchristos
19*e670fd5cSchristosif test $HOMEDIR = homedirno; then
20*e670fd5cSchristos	echo "Homedir overlay not available, test skipped"
21*e670fd5cSchristos	exit 0
22*e670fd5cSchristosfi
23*e670fd5cSchristos
24*e670fd5cSchristosmkdir -p $TESTDIR $DBDIR1 $TESTDIR/home $TESTDIR/archive
25*e670fd5cSchristos
26*e670fd5cSchristos$SLAPPASSWD -g -n >$CONFIGPWF
27*e670fd5cSchristosecho "rootpw `$SLAPPASSWD -T $CONFIGPWF`" >$TESTDIR/configpw.conf
28*e670fd5cSchristos
29*e670fd5cSchristosecho "Running slapadd to build slapd database..."
30*e670fd5cSchristos. $CONFFILTER $BACKEND < $HOMEDIRCONF | sed "s/@MINUID@/`id -u`/" > $CONF1
31*e670fd5cSchristos$SLAPADD -f $CONF1 -l $LDIF
32*e670fd5cSchristosRC=$?
33*e670fd5cSchristosif test $RC != 0 ; then
34*e670fd5cSchristos	echo "slapadd failed ($RC)!"
35*e670fd5cSchristos	exit $RC
36*e670fd5cSchristosfi
37*e670fd5cSchristos
38*e670fd5cSchristosecho "Starting slapd on TCP/IP port $PORT1..."
39*e670fd5cSchristos$SLAPD -f $CONF1 -h $URI1 -d $LVL > $LOG1 2>&1 &
40*e670fd5cSchristosPID=$!
41*e670fd5cSchristosif test $WAIT != 0 ; then
42*e670fd5cSchristos    echo PID $PID
43*e670fd5cSchristos    read foo
44*e670fd5cSchristosfi
45*e670fd5cSchristosKILLPIDS="$PID"
46*e670fd5cSchristos
47*e670fd5cSchristossleep 1
48*e670fd5cSchristos
49*e670fd5cSchristosecho "Using ldapsearch to check that slapd is running..."
50*e670fd5cSchristosfor i in 0 1 2 3 4 5; do
51*e670fd5cSchristos	$LDAPSEARCH -s base -b "$MONITOR" -H $URI1 \
52*e670fd5cSchristos		'objectclass=*' > /dev/null 2>&1
53*e670fd5cSchristos	RC=$?
54*e670fd5cSchristos	if test $RC = 0 ; then
55*e670fd5cSchristos		break
56*e670fd5cSchristos	fi
57*e670fd5cSchristos	echo "Waiting 5 seconds for slapd to start..."
58*e670fd5cSchristos	sleep 5
59*e670fd5cSchristosdone
60*e670fd5cSchristosif test $RC != 0 ; then
61*e670fd5cSchristos	echo "ldapsearch failed ($RC)!"
62*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
63*e670fd5cSchristos	exit $RC
64*e670fd5cSchristosfi
65*e670fd5cSchristos
66*e670fd5cSchristosecho "Adding a new user..."
67*e670fd5cSchristos$LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD <<EOMOD >> $TESTOUT 2>&1
68*e670fd5cSchristosdn: uid=user1,ou=People,$BASEDN
69*e670fd5cSchristosobjectClass: account
70*e670fd5cSchristosobjectClass: posixAccount
71*e670fd5cSchristosuid: user1
72*e670fd5cSchristoscn: One user
73*e670fd5cSchristosuidNumber: `id -u`
74*e670fd5cSchristosgidNumber: `id -g`
75*e670fd5cSchristoshomeDirectory: /home/user1
76*e670fd5cSchristosEOMOD
77*e670fd5cSchristosRC=$?
78*e670fd5cSchristosif test $RC != 0 ; then
79*e670fd5cSchristos	echo "ldapadd failed ($RC)!"
80*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
81*e670fd5cSchristos	exit $RC
82*e670fd5cSchristosfi
83*e670fd5cSchristos
84*e670fd5cSchristossleep 1
85*e670fd5cSchristos
86*e670fd5cSchristosif ! test -e $TESTDIR/home/user1 ; then
87*e670fd5cSchristos	echo "Home directory for user1 not created!"
88*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
89*e670fd5cSchristos	exit 1
90*e670fd5cSchristosfi
91*e670fd5cSchristos
92*e670fd5cSchristosecho "Moving home directory for user1..."
93*e670fd5cSchristos$LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD <<EOMOD >> $TESTOUT 2>&1
94*e670fd5cSchristosdn: uid=user1,ou=People,$BASEDN
95*e670fd5cSchristoschangetype: modify
96*e670fd5cSchristosreplace: homeDirectory
97*e670fd5cSchristoshomeDirectory: /home/user1_new
98*e670fd5cSchristosEOMOD
99*e670fd5cSchristosRC=$?
100*e670fd5cSchristosif test $RC != 0 ; then
101*e670fd5cSchristos	echo "ldapadd failed ($RC)!"
102*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
103*e670fd5cSchristos	exit $RC
104*e670fd5cSchristosfi
105*e670fd5cSchristos
106*e670fd5cSchristossleep 1
107*e670fd5cSchristos
108*e670fd5cSchristosif test -e $TESTDIR/home/user1 || ! test -e $TESTDIR/home/user1_new ; then
109*e670fd5cSchristos	echo "Home directory for user1 not moved!"
110*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
111*e670fd5cSchristos	exit 1
112*e670fd5cSchristosfi
113*e670fd5cSchristos
114*e670fd5cSchristosecho "Removing user1, should get archived..."
115*e670fd5cSchristos$LDAPDELETE -D "$MANAGERDN" -H $URI1 -w $PASSWD \
116*e670fd5cSchristos    "uid=user1,ou=People,$BASEDN" >> $TESTOUT
117*e670fd5cSchristosRC=$?
118*e670fd5cSchristosif test $RC != 0 ; then
119*e670fd5cSchristos	echo "ldapdelete failed ($RC)!"
120*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
121*e670fd5cSchristos	exit $RC
122*e670fd5cSchristosfi
123*e670fd5cSchristos
124*e670fd5cSchristossleep 1
125*e670fd5cSchristos
126*e670fd5cSchristosif test -e $TESTDIR/home/user1_new || \
127*e670fd5cSchristos		! test -e $TESTDIR/archive/user1_new-*-0.tar ; then
128*e670fd5cSchristos	echo "Home directory for user1 not archived properly!"
129*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
130*e670fd5cSchristos	exit 1
131*e670fd5cSchristosfi
132*e670fd5cSchristos
133*e670fd5cSchristostest $KILLSERVERS != no && kill -HUP $KILLPIDS
134*e670fd5cSchristos
135*e670fd5cSchristostest $KILLSERVERS != no && wait
136*e670fd5cSchristos
137*e670fd5cSchristosecho ">>>>> Test succeeded"
138*e670fd5cSchristos
139*e670fd5cSchristosexit 0
140