summaryrefslogtreecommitdiffstats
path: root/tests/slapd.sh.in
blob: f63d7a9280688219c193c3584d95369f6073140e (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
#!/bin/sh
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"

PORT=@test_ldapport@
export PORT
PW=password
export PW
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 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 -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
	@NIS_PLUGIN_CONTINUE_WITHOUT_PORTMAP_ENV@=1 \
	@TRACE_CMD@ \
	$SLAPD -D $BTESTDIR/config -i $STATEDIR/pid -w $STATEDIR/pid
	if ! add -f $BTESTDIR/config/userRoot.ldif > /dev/null 2> /dev/null ; then
		local i
		local max=30
		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
}