| 1 |
#! /bin/sh |
| 2 |
# $OpenLDAP$ |
| 3 |
## This work is part of OpenLDAP Software <http://www.openldap.org/>. |
| 4 |
## |
| 5 |
## Copyright 1998-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 |
echo "### This test requires the LDAP backend and the rwm overlay." |
| 20 |
echo "### If available, and explicitly requested, it can use SASL bind;" |
| 21 |
echo "### note that SASL must be properly set up, and the requested" |
| 22 |
echo "### mechanism must be available. Define SLAPD_USE_SASL={yes|<mech>}," |
| 23 |
echo "### with \"yes\" defaulting to SCRAM-SHA-256 to enable SASL authc[/authz]." |
| 24 |
|
| 25 |
if test $BACKLDAP = "ldapno" ; then |
| 26 |
echo "LDAP backend not available, test skipped" |
| 27 |
exit 0 |
| 28 |
fi |
| 29 |
|
| 30 |
if test $RWM = "rwmno" ; then |
| 31 |
echo "Rewrite/remap overlay not available, test skipped" |
| 32 |
exit 0 |
| 33 |
fi |
| 34 |
|
| 35 |
if test $WITH_SASL = "yes" ; then |
| 36 |
if test $USE_SASL != "no" ; then |
| 37 |
if test $USE_SASL = "yes" ; then |
| 38 |
MECH="SCRAM-SHA-256" |
| 39 |
else |
| 40 |
MECH="$USE_SASL" |
| 41 |
fi |
| 42 |
echo "Using SASL authc[/authz] with mech=$MECH; unset SLAPD_USE_SASL to disable" |
| 43 |
else |
| 44 |
echo "Using proxyAuthz with simple authc..." |
| 45 |
fi |
| 46 |
else |
| 47 |
echo "SASL not available; using proxyAuthz with simple authc..." |
| 48 |
fi |
| 49 |
|
| 50 |
mkdir -p $TESTDIR $DBDIR1 $DBDIR2 |
| 51 |
|
| 52 |
echo "Running slapadd to build slapd database..." |
| 53 |
. $CONFFILTER $BACKEND < $IDASSERTCONF > $ADDCONF |
| 54 |
$SLAPADD -f $ADDCONF -l $LDIFIDASSERT1 -n 1 |
| 55 |
RC=$? |
| 56 |
if test $RC != 0 ; then |
| 57 |
echo "slapadd -n 1 failed ($RC)!" |
| 58 |
exit $RC |
| 59 |
fi |
| 60 |
$SLAPADD -f $ADDCONF -l $LDIFIDASSERT2 -n 2 |
| 61 |
RC=$? |
| 62 |
if test $RC != 0 ; then |
| 63 |
echo "slapadd -n 2 failed ($RC)!" |
| 64 |
exit $RC |
| 65 |
fi |
| 66 |
|
| 67 |
echo "Starting slapd on TCP/IP port $PORT..." |
| 68 |
. $CONFFILTER $BACKEND < $IDASSERTCONF > $CONF1 |
| 69 |
$SLAPD -f $CONF1 -h $URI1 -d $LVL > $LOG1 2>&1 & |
| 70 |
PID=$! |
| 71 |
if test $WAIT != 0 ; then |
| 72 |
echo PID $PID |
| 73 |
read foo |
| 74 |
fi |
| 75 |
KILLPIDS="$PID" |
| 76 |
|
| 77 |
sleep 1 |
| 78 |
|
| 79 |
echo "Using ldapsearch to check that slapd is running..." |
| 80 |
for i in 0 1 2 3 4 5; do |
| 81 |
$LDAPSEARCH -s base -b "$MONITOR" -H $URI1 \ |
| 82 |
'objectclass=*' > /dev/null 2>&1 |
| 83 |
RC=$? |
| 84 |
if test $RC = 0 ; then |
| 85 |
break |
| 86 |
fi |
| 87 |
echo "Waiting 5 seconds for slapd to start..." |
| 88 |
sleep 5 |
| 89 |
done |
| 90 |
|
| 91 |
echo "Testing ldapwhoami as proxy US..." |
| 92 |
$LDAPWHOAMI -H $URI1 -D "cn=proxy US,ou=Admin,dc=example,dc=com" -w proxy |
| 93 |
RC=$? |
| 94 |
if test $RC != 0 ; then |
| 95 |
echo "ldapwhoami failed ($RC)!" |
| 96 |
test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 97 |
exit $RC |
| 98 |
fi |
| 99 |
|
| 100 |
AUTHZID="u:it/jaj" |
| 101 |
echo "Testing ldapwhoami as proxy US, $AUTHZID..." |
| 102 |
$LDAPWHOAMI -H $URI1 -D "cn=proxy US,ou=Admin,dc=example,dc=com" -w proxy -e\!"authzid=$AUTHZID" |
| 103 |
RC=$? |
| 104 |
if test $RC != 0 && test $BACKEND != null ; then |
| 105 |
echo "ldapwhoami failed ($RC)!" |
| 106 |
test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 107 |
exit $RC |
| 108 |
fi |
| 109 |
|
| 110 |
AUTHZID="u:bjorn" |
| 111 |
echo "Testing ldapwhoami as proxy US, $AUTHZID... (should fail)" |
| 112 |
$LDAPWHOAMI -H $URI1 -D "cn=proxy US,ou=Admin,dc=example,dc=com" -w proxy -e\!"authzid=$AUTHZID" |
| 113 |
RC=$? |
| 114 |
if test $RC != 1 ; then |
| 115 |
echo "ldapwhoami should have failed ($RC)!" |
| 116 |
test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 117 |
exit 1 |
| 118 |
fi |
| 119 |
|
| 120 |
AUTHZID="u:bjensen" |
| 121 |
echo "Testing ldapwhoami as proxy US, $AUTHZID... (should fail)" |
| 122 |
$LDAPWHOAMI -H $URI1 -D "cn=proxy US,ou=Admin,dc=example,dc=com" -w proxy -e\!"authzid=$AUTHZID" |
| 123 |
RC=$? |
| 124 |
if test $RC != 1 ; then |
| 125 |
echo "ldapwhoami should have failed ($RC)!" |
| 126 |
test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 127 |
exit 1 |
| 128 |
fi |
| 129 |
|
| 130 |
echo "Testing ldapwhoami as proxy IT..." |
| 131 |
$LDAPWHOAMI -H $URI1 -D "cn=proxy IT,ou=Admin,dc=example,dc=com" -w proxy |
| 132 |
RC=$? |
| 133 |
if test $RC != 0 ; then |
| 134 |
echo "ldapwhoami failed ($RC)!" |
| 135 |
test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 136 |
exit $RC |
| 137 |
fi |
| 138 |
|
| 139 |
AUTHZID="u:it/jaj" |
| 140 |
echo "Testing ldapwhoami as proxy IT, $AUTHZID... (should fail)" |
| 141 |
$LDAPWHOAMI -H $URI1 -D "cn=proxy IT,ou=Admin,dc=example,dc=com" -w proxy -e\!"authzid=$AUTHZID" |
| 142 |
RC=$? |
| 143 |
if test $RC != 1 ; then |
| 144 |
echo "ldapwhoami should have failed ($RC)!" |
| 145 |
test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 146 |
exit 1 |
| 147 |
fi |
| 148 |
|
| 149 |
AUTHZID="u:bjorn" |
| 150 |
echo "Testing ldapwhoami as proxy IT, $AUTHZID... (should fail)" |
| 151 |
$LDAPWHOAMI -H $URI1 -D "cn=proxy IT,ou=Admin,dc=example,dc=com" -w proxy -e\!"authzid=$AUTHZID" |
| 152 |
RC=$? |
| 153 |
if test $RC != 1 ; then |
| 154 |
echo "ldapwhoami should have failed ($RC)!" |
| 155 |
test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 156 |
exit 1 |
| 157 |
fi |
| 158 |
|
| 159 |
AUTHZID="dn:cn=Sandbox,ou=Admin,dc=example,dc=com" |
| 160 |
echo "Testing ldapwhoami as proxy IT, $AUTHZID..." |
| 161 |
$LDAPWHOAMI -H $URI1 -D "cn=proxy IT,ou=Admin,dc=example,dc=com" -w proxy -e\!"authzid=$AUTHZID" |
| 162 |
RC=$? |
| 163 |
if test $RC != 0 && test $BACKEND != null ; then |
| 164 |
echo "ldapwhoami failed ($RC)!" |
| 165 |
test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 166 |
exit $RC |
| 167 |
fi |
| 168 |
|
| 169 |
AUTHZID="dn:uid=bjorn,ou=People,o=Example,c=US" |
| 170 |
echo "Testing ldapwhoami as bjorn, $AUTHZID..." |
| 171 |
$LDAPWHOAMI -H $URI1 -D "uid=bjorn,ou=people,dc=example,dc=com" -w bjorn -e\!"authzid=$AUTHZID" |
| 172 |
RC=$? |
| 173 |
if test $RC != 0 ; then |
| 174 |
echo "ldapwhoami failed ($RC)!" |
| 175 |
test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 176 |
exit $RC |
| 177 |
fi |
| 178 |
|
| 179 |
AUTHZID="dn:uid=bjorn,ou=People,o=Esempio,c=IT" |
| 180 |
echo "Testing ldapwhoami as bjorn, $AUTHZID..." |
| 181 |
$LDAPWHOAMI -H $URI1 -D "uid=bjorn,ou=people,dc=example,dc=com" -w bjorn -e\!"authzid=$AUTHZID" |
| 182 |
RC=$? |
| 183 |
if test $RC != 0 ; then |
| 184 |
echo "ldapwhoami failed ($RC)!" |
| 185 |
test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 186 |
exit $RC |
| 187 |
fi |
| 188 |
|
| 189 |
AUTHZID="u:it/jaj" |
| 190 |
echo "Checking another DB's rootdn can't assert identity from another DB..." |
| 191 |
$LDAPWHOAMI -H $URI1 -D "$MANAGERDN" -w $PASSWD -e\!"authzid=$AUTHZID" |
| 192 |
|
| 193 |
RC=$? |
| 194 |
if test $RC != 1 ; then |
| 195 |
echo "ldapwhoami should have failed ($RC)!" |
| 196 |
test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 197 |
exit 1 |
| 198 |
fi |
| 199 |
|
| 200 |
ID="uid=jaj,ou=People,dc=example,dc=it" |
| 201 |
BASE="o=Example,c=US" |
| 202 |
echo "Testing ldapsearch as $ID for \"$BASE\"..." |
| 203 |
$LDAPSEARCH -H $URI1 -b "$BASE" \ |
| 204 |
-D "$ID" -w jaj > $SEARCHOUT 2>&1 |
| 205 |
|
| 206 |
RC=$? |
| 207 |
if test $RC != 0 && test $BACKEND != null ; then |
| 208 |
echo "ldapsearch failed ($RC)!" |
| 209 |
test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 210 |
exit $RC |
| 211 |
fi |
| 212 |
|
| 213 |
echo "Filtering ldapsearch results..." |
| 214 |
$LDIFFILTER -s ldif=e < $SEARCHOUT > $SEARCHFLT |
| 215 |
echo "Filtering original ldif used to create database..." |
| 216 |
$LDIFFILTER -s ldif=e < $IDASSERTOUT > $LDIFFLT |
| 217 |
echo "Comparing filter output..." |
| 218 |
$CMP $SEARCHFLT $LDIFFLT > $CMPOUT |
| 219 |
|
| 220 |
if test $? != 0 ; then |
| 221 |
echo "comparison failed - search with identity assertion didn't succeed" |
| 222 |
test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 223 |
exit 1 |
| 224 |
fi |
| 225 |
|
| 226 |
if test $USE_SASL != "no" ; then |
| 227 |
ID="it/jaj" |
| 228 |
BASE="o=Example,c=US" |
| 229 |
echo "Testing ldapsearch as $ID for \"$BASE\" with SASL bind and identity assertion..." |
| 230 |
$LDAPSASLSEARCH -H $URI1 -b "$BASE" \ |
| 231 |
-Q -U "$ID" -w jaj -Y $MECH > $SEARCHOUT 2>&1 |
| 232 |
|
| 233 |
RC=$? |
| 234 |
if test $RC != 0 ; then |
| 235 |
echo "ldapsearch failed ($RC)!" |
| 236 |
test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 237 |
exit $RC |
| 238 |
fi |
| 239 |
|
| 240 |
ID="manager" |
| 241 |
AUTHZID="u:it/jaj" |
| 242 |
echo "Checking another DB's rootdn can't assert in another (with SASL bind this time)..." |
| 243 |
$LDAPSASLWHOAMI -H $URI1 \ |
| 244 |
-Q -U "$ID" -w $PASSWD -Y $MECH -X $AUTHZID |
| 245 |
|
| 246 |
RC=$? |
| 247 |
if test $RC != 50 ; then |
| 248 |
echo "ldapwhoami should have failed ($RC)!" |
| 249 |
test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 250 |
exit 1 |
| 251 |
fi |
| 252 |
|
| 253 |
echo "Filtering ldapsearch results..." |
| 254 |
$LDIFFILTER < $SEARCHOUT > $SEARCHFLT |
| 255 |
echo "Filtering original ldif used to create database..." |
| 256 |
$LDIFFILTER < $IDASSERTOUT > $LDIFFLT |
| 257 |
echo "Comparing filter output..." |
| 258 |
$CMP $SEARCHFLT $LDIFFLT > $CMPOUT |
| 259 |
|
| 260 |
if test $? != 0 ; then |
| 261 |
echo "comparison failed - search with SASL bind and identity assertion didn't succeed" |
| 262 |
test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 263 |
exit 1 |
| 264 |
fi |
| 265 |
fi |
| 266 |
|
| 267 |
test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 268 |
|
| 269 |
echo ">>>>> Test succeeded" |
| 270 |
|
| 271 |
test $KILLSERVERS != no && wait |
| 272 |
|
| 273 |
exit 0 |