summaryrefslogtreecommitdiffstats
path: root/tests/slapd.sh.in
blob: 28c14316d0261672a31f0b1614b4e1f90cb47bdc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/bin/bash
SLAPD=@SLAPD@
TESTDIR=@abs_srcdir@
BTESTDIR=@abs_builddir@
STATEDIR=@abs_builddir@/state

YP="@abs_builddir@/clients/yp -p @test_nisport@"
export YP
LDIFSORT="@abs_builddir@/clients/ldifsort"
export LDIFSORT
VALGRIND="valgrind --leak-check=full --log-file=valgrind.log --num-callers=50 --track-origins=yes --show-reachable=yes --suppressions=@abs_srcdir@/slapi-nis.supp --gen-suppressions=all"

TESTS_USE_REFINT=@TESTS_USE_REFINT@
TESTS_USE_MEMBEROF=@TESTS_USE_MEMBEROF@
PORT=@test_ldapport@
export PORT
PW=password
export PW
simplebind() {
	ldapsearch -h localhost -p $PORT -x -b '' -s base dn: "$@"
}
add() {
	ldapadd -h localhost -p $PORT -x -D "cn=Directory Manager" -w $PW "$@"
}
modify() {
	ldapmodify -h localhost -p $PORT -x -D "cn=Directory Manager" -w $PW "$@"
}
modrdn() {
	ldapmodrdn -h localhost -p $PORT -x -D "cn=Directory Manager" -w $PW "$@"
}
delete() {
	ldapdelete -h localhost -p $PORT -x -D "cn=Directory Manager" -w $PW "$@"
}
search() {
	ldapsearch -h localhost -p $PORT -x -D "cn=Directory Manager" -w $PW "$@"
}
compare() {
	ldapcompare -h localhost -p $PORT -x -D "cn=Directory Manager" -w $PW "$@"
}
export -f simplebind add modify modrdn delete search compare

stopslapd() {
	if test -s $STATEDIR/pid ; then
		pid=`cat $STATEDIR/pid`
		kill -s HUP $pid 2> /dev/null
		sleep 1
		if kill -s 0 $pid 2> /dev/null ; then
			kill $pid 2> /dev/null
			sleep 1
			if kill -s 0 $pid 2> /dev/null ; then
				kill -s 9 $pid 2> /dev/null
				sleep 1
			fi
		fi
		if ! kill -s 0 $pid 2> /dev/null ; then
			rm -f $STATEDIR/pid
		fi
	fi
}
startslapd() {
	stopslapd
	rm -rf $STATEDIR/db
	local subdir=
	for subdir in bak db/userRoot ldif lock log tmp run ; do
		test -d $STATEDIR/$subdir || mkdir -p $STATEDIR/$subdir
	done
	test -s $BTESTDIR/config/schema/00core.ldif || ln -s -t $BTESTDIR/config $TESTDIR/config/schema
	cat $BTESTDIR/config/dse.ldif.initial > $BTESTDIR/config/dse.ldif
	if ! test -s $TESTDIR/$TEST/plugin-skip-refint.txt ; then
		cat $BTESTDIR/config/dse.ldif.refint >> $BTESTDIR/config/dse.ldif
	fi
	if ! test -s $TESTDIR/$TEST/plugin-skip-memberof.txt ; then
		cat $BTESTDIR/config/dse.ldif.memberof >> $BTESTDIR/config/dse.ldif
	fi
	if ! test -s $TESTDIR/$TEST/plugin-skip-mep.txt ; then
		cat $BTESTDIR/config/dse.ldif.mep >> $BTESTDIR/config/dse.ldif
	fi
	if ! test -s $TESTDIR/$TEST/plugin-skip-usn.txt ; then
		cat $BTESTDIR/config/dse.ldif.usn >> $BTESTDIR/config/dse.ldif
	fi
	process_all=0
	if test -s $TESTDIR/$TEST/plugin-process-all.txt ; then
		process_all=1
	fi
	if test -n "$1" && test -s "$1" ; then
		cat "$1" >> $BTESTDIR/config/dse.ldif
	fi
	if test -x $TESTDIR/$TEST/edit-dse-config.sh ; then
		if ! $TESTDIR/$TEST/edit-dse-config.sh $BTESTDIR/config/dse.ldif ; then
			echo ERROR: failed to edit dse.ldif before starting server.
			exit 1
		fi
	fi
	old_ld_preload="$LD_PRELOAD"
	if test -s $TESTDIR/$TEST/plugin-need-wrappers.txt ; then
		ENVCMD="`cat $TESTDIR/$TEST/plugin-need-wrappers.txt`"
		ENVCMD=env\ `eval echo $ENVCMD`
		LD_PRELOAD=$BTESTDIR/wrappers.so${LD_PRELOAD:+:$LD_PRELOAD}
		export LD_PRELOAD
	else
		ENVCMD=
		LD_PRELOAD="$old_ld_preload"
		if test -n "$LD_PRELOAD" ; then
			export LD_PRELOAD
		else
			export -n LD_PRELOAD
		fi
	fi
	@NIS_PLUGIN_CONTINUE_WITHOUT_PORTMAP_ENV@=1 \
	@NIS_PLUGIN_PROCESS_UNINTERESTING_UPDATES_ENV@=$process_all \
	@SCHEMA_COMPAT_PLUGIN_PROCESS_UNINTERESTING_UPDATES_ENV@=$process_all \
	$ENVCMD @TRACE_CMD@ \
	$SLAPD -D $BTESTDIR/config -i $STATEDIR/pid -w $STATEDIR/pid
	LD_PRELOAD="$old_ld_preload"
	if test -n "$LD_PRELOAD" ; then
		export LD_PRELOAD
	else
		export -n LD_PRELOAD
	fi
	if ! add -f $BTESTDIR/config/userRoot.ldif > /dev/null 2> /dev/null ; then
		local i
		local max=60
		for i in `seq $max` ; do
			sleep 1
			if add -f $TESTDIR/config/userRoot.ldif > /dev/null 2> /dev/null ; then
				break
			fi
		done
		if test $i -eq $max ; then
			echo ERROR: failed to add default entry set to server.
			exit 1
		fi
	fi
	if test -n "$2" && test -s "$2" ; then
		if ! add -f "$2" > /dev/null 2> /dev/null ; then
			echo ERROR: failed to add test-specific entries to server.
			exit 1
		fi
	fi
}