| 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 |
if test $WITH_TLS = no ; then |
| 20 |
echo "TLS support not available, test skipped" |
| 21 |
exit 0 |
| 22 |
fi |
| 23 |
|
| 24 |
if test $BACKLDAP = "ldapno" ; then |
| 25 |
echo "LDAP backend not available, test skipped" |
| 26 |
exit 0 |
| 27 |
fi |
| 28 |
|
| 29 |
if test "$BACKEND" = "ldap"; then |
| 30 |
echo "LDAP backend not valid, test skipped" |
| 31 |
exit 0 |
| 32 |
fi |
| 33 |
|
| 34 |
mkdir -p $TESTDIR $DBDIR1 |
| 35 |
cp -r $DATADIR/tls $TESTDIR |
| 36 |
|
| 37 |
$SLAPPASSWD -g -n >$CONFIGPWF |
| 38 |
echo "rootpw `$SLAPPASSWD -T $CONFIGPWF`" >$TESTDIR/configpw.conf |
| 39 |
|
| 40 |
ITS=8427 |
| 41 |
ITSDIR=$DATADIR/regressions/its$ITS |
| 42 |
|
| 43 |
echo "Running slapadd to build slapd database..." |
| 44 |
. $CONFFILTER $BACKEND < $TLSCONF > $CONF1 |
| 45 |
$SLAPADD -f $CONF1 -l $LDIFORDERED |
| 46 |
RC=$? |
| 47 |
if test $RC != 0 ; then |
| 48 |
echo "slapadd failed ($RC)!" |
| 49 |
exit $RC |
| 50 |
fi |
| 51 |
|
| 52 |
echo "database config" >> $CONF1 |
| 53 |
echo "include $TESTDIR/configpw.conf" >> $CONF1 |
| 54 |
|
| 55 |
echo "Starting slapd listening on $URIP1 and $SURIP2..." |
| 56 |
$SLAPD -f $CONF1 -h "$URIP1 $SURIP2" -d $LVL > $LOG1 2>&1 & |
| 57 |
SERVERPID=$! |
| 58 |
if test $WAIT != 0 ; then |
| 59 |
echo SERVERPID $SERVERPID |
| 60 |
read foo |
| 61 |
fi |
| 62 |
KILLPIDS="$SERVERPID" |
| 63 |
|
| 64 |
sleep 1 |
| 65 |
|
| 66 |
echo "Using ldapsearch to check that slapd is running..." |
| 67 |
for i in 0 1 2 3 4 5; do |
| 68 |
$LDAPSEARCH -s base -b "$MONITOR" -H $URI1 \ |
| 69 |
'objectclass=*' > /dev/null 2>&1 |
| 70 |
RC=$? |
| 71 |
if test $RC = 0 ; then |
| 72 |
break |
| 73 |
fi |
| 74 |
echo "Waiting 5 seconds for slapd to start..." |
| 75 |
sleep 5 |
| 76 |
done |
| 77 |
|
| 78 |
if test $RC != 0 ; then |
| 79 |
echo "ldapsearch failed ($RC)!" |
| 80 |
test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 81 |
exit $RC |
| 82 |
fi |
| 83 |
|
| 84 |
echo "database config" >> $CONF2 |
| 85 |
echo "include $TESTDIR/configpw.conf" >> $CONF2 |
| 86 |
|
| 87 |
echo "Starting proxy slapd on TCP/IP port $PORT3..." |
| 88 |
. $CONFFILTER $BACKEND < $ITSDIR/slapd.conf > $CONF2 |
| 89 |
$SLAPD -f $CONF2 -h $URI3 -d $LVL > $LOG2 2>&1 & |
| 90 |
PROXYPID=$! |
| 91 |
if test $WAIT != 0 ; then |
| 92 |
echo PROXYPID $PROXYPID |
| 93 |
read foo |
| 94 |
fi |
| 95 |
KILLPIDS="$KILLPIDS $PROXYPID" |
| 96 |
|
| 97 |
sleep 1 |
| 98 |
|
| 99 |
echo "Using ldapsearch to check that proxy slapd is running..." |
| 100 |
for i in 0 1 2 3 4 5; do |
| 101 |
$LDAPSEARCH -s base -b "$MONITOR" -H $URI3 \ |
| 102 |
'objectclass=*' > /dev/null 2>&1 |
| 103 |
RC=$? |
| 104 |
if test $RC = 0 ; then |
| 105 |
break |
| 106 |
fi |
| 107 |
echo "Waiting 5 seconds for slapd to start..." |
| 108 |
sleep 5 |
| 109 |
done |
| 110 |
|
| 111 |
if test $RC != 0 ; then |
| 112 |
echo "ldapsearch failed ($RC)!" |
| 113 |
test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 114 |
exit $RC |
| 115 |
fi |
| 116 |
|
| 117 |
echo "Configuring proxy..." |
| 118 |
$LDAPMODIFY -D cn=config -H $URI3 -y $CONFIGPWF \ |
| 119 |
> $TESTOUT 2>&1 <<EOF |
| 120 |
dn: olcDatabase={2}ldap,cn=config |
| 121 |
changetype: add |
| 122 |
objectClass: olcLDAPConfig |
| 123 |
olcDbUri: $URI1 |
| 124 |
olcSuffix: $BASEDN |
| 125 |
olcRootDN: $MANAGERDN |
| 126 |
olcRootPW: $PASSWD |
| 127 |
EOF |
| 128 |
RC=$? |
| 129 |
if test $RC != 0 ; then |
| 130 |
echo "modification failed ($RC)" |
| 131 |
test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 132 |
exit $RC |
| 133 |
fi |
| 134 |
|
| 135 |
echo "Privileged WhoAmI (proxy uses plain ldap://)..." |
| 136 |
$LDAPWHOAMI -H $URI3 -D "$MANAGERDN" -w $PASSWD |
| 137 |
RC=$? |
| 138 |
if test $RC != 0 ; then |
| 139 |
echo "ldapwhoami failed ($RC)!" |
| 140 |
test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 141 |
exit $RC |
| 142 |
fi |
| 143 |
|
| 144 |
echo "WhoAmI (proxy uses plain ldap://)..." |
| 145 |
$LDAPWHOAMI -H $URI3 -D "$BABSDN" -w bjensen |
| 146 |
RC=$? |
| 147 |
if test $RC != 0 ; then |
| 148 |
echo "ldapwhoami failed ($RC)!" |
| 149 |
test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 150 |
exit $RC |
| 151 |
fi |
| 152 |
|
| 153 |
echo "Searching (proxy uses plain ldap://)..." |
| 154 |
echo "# Searching (proxy uses plain ldap://)..." > $SEARCHOUT |
| 155 |
$LDAPSEARCH -b "$BASEDN" -H $URI3 \ |
| 156 |
-D "$BABSDN" -w bjensen \ |
| 157 |
'(objectClass=*)' >> $SEARCHOUT 2>&1 |
| 158 |
RC=$? |
| 159 |
if test $RC != 0 ; then |
| 160 |
echo "ldapsearch failed ($RC)!" |
| 161 |
test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 162 |
exit $RC |
| 163 |
fi |
| 164 |
|
| 165 |
echo "Filtering ldapsearch results..." |
| 166 |
$LDIFFILTER < $SEARCHOUT > $SEARCHFLT |
| 167 |
echo "Filtering original ldif used to create database..." |
| 168 |
$LDIFFILTER < $LDIFORDERED > $LDIFFLT |
| 169 |
echo "" >> $LDIFFLT |
| 170 |
echo "Comparing filter output..." |
| 171 |
$CMP $SEARCHFLT $LDIFFLT > $CMPOUT |
| 172 |
|
| 173 |
if test $? != 0 ; then |
| 174 |
echo "Comparison failed" |
| 175 |
test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 176 |
exit 1 |
| 177 |
fi |
| 178 |
|
| 179 |
echo "Reconfiguring database to only allow TLS binds..." |
| 180 |
$LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF \ |
| 181 |
> $TESTOUT 2>&1 <<EOF |
| 182 |
dn: olcDatabase={1}$BACKEND,cn=config |
| 183 |
changetype: modify |
| 184 |
add: olcAccess |
| 185 |
olcAccess: to attrs=userPassword by anonymous ssf=2 auth by users read |
| 186 |
olcAccess: to * by users read |
| 187 |
EOF |
| 188 |
RC=$? |
| 189 |
if test $RC != 0 ; then |
| 190 |
echo "modification failed ($RC)" |
| 191 |
test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 192 |
exit $RC |
| 193 |
fi |
| 194 |
|
| 195 |
echo "Re-configuring proxy to use ldaps:// on privileged connections only..." |
| 196 |
$LDAPMODIFY -D cn=config -H $URI3 -y $CONFIGPWF \ |
| 197 |
> $TESTOUT 2>&1 <<EOF |
| 198 |
dn: olcDatabase={2}ldap,cn=config |
| 199 |
changetype: delete |
| 200 |
|
| 201 |
dn: olcDatabase={2}ldap,cn=config |
| 202 |
changetype: add |
| 203 |
objectClass: olcLDAPConfig |
| 204 |
olcDbUri: $SURIP2 |
| 205 |
olcSuffix: $BASEDN |
| 206 |
olcRootDN: $MANAGERDN |
| 207 |
olcRootPW: $PASSWD |
| 208 |
olcDbIDAssertBind: bindmethod=simple binddn="$MANAGERDN" credentials="$PASSWD" tls_cacert=$TESTDIR/tls/ca/certs/testsuiteCA.crt |
| 209 |
EOF |
| 210 |
RC=$? |
| 211 |
if test $RC != 0 ; then |
| 212 |
echo "modification failed ($RC)" |
| 213 |
test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 214 |
exit $RC |
| 215 |
fi |
| 216 |
|
| 217 |
echo "Privileged WhoAmI (proxy uses ldaps://)..." |
| 218 |
$LDAPWHOAMI -H $URI3 -D "$MANAGERDN" -w $PASSWD |
| 219 |
RC=$? |
| 220 |
if test $RC != 0 ; then |
| 221 |
echo "ldapwhoami failed ($RC)!" |
| 222 |
test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 223 |
exit $RC |
| 224 |
fi |
| 225 |
|
| 226 |
echo "WhoAmI (proxy uses ldaps://), which should fail..." |
| 227 |
$LDAPWHOAMI -H $URI3 -D "$BABSDN" -w bjensen |
| 228 |
RC=$? |
| 229 |
case $RC in |
| 230 |
52) |
| 231 |
;; |
| 232 |
0) |
| 233 |
echo "ldapwhoami should have failed ($RC)!" |
| 234 |
test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 235 |
exit 1 |
| 236 |
;; |
| 237 |
*) |
| 238 |
echo "ldapwhoami failed ($RC)!" |
| 239 |
test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 240 |
exit $RC |
| 241 |
;; |
| 242 |
esac |
| 243 |
|
| 244 |
# FIXME: just adding olcDbStartTLS to the DB doesn't have an effect, why? |
| 245 |
echo "Re-configuring proxy to use ldaps:// everywhere..." |
| 246 |
$LDAPMODIFY -D cn=config -H $URI3 -y $CONFIGPWF \ |
| 247 |
> $TESTOUT 2>&1 <<EOF |
| 248 |
dn: olcDatabase={2}ldap,cn=config |
| 249 |
changetype: modify |
| 250 |
add: olcDbStartTLS |
| 251 |
olcDbStartTLS: ldaps tls_cacert=$TESTDIR/tls/ca/certs/testsuiteCA.crt |
| 252 |
EOF |
| 253 |
RC=$? |
| 254 |
if test $RC != 0 ; then |
| 255 |
echo "modification failed ($RC)" |
| 256 |
test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 257 |
exit $RC |
| 258 |
fi |
| 259 |
|
| 260 |
echo "WhoAmI again (proxy uses ldaps://)..." |
| 261 |
$LDAPWHOAMI -H $URI3 -D "$BABSDN" -w bjensen |
| 262 |
RC=$? |
| 263 |
if test $RC != 0 ; then |
| 264 |
echo "ldapwhoami failed ($RC)!" |
| 265 |
test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 266 |
exit $RC |
| 267 |
fi |
| 268 |
|
| 269 |
echo "Searching (proxy uses ldaps://)..." |
| 270 |
echo "# Searching (proxy uses ldaps://)..." > $SEARCHOUT |
| 271 |
$LDAPSEARCH -b "$BASEDN" -H $URI3 \ |
| 272 |
-D "$BABSDN" -w bjensen \ |
| 273 |
'(objectClass=*)' >> $SEARCHOUT 2>&1 |
| 274 |
RC=$? |
| 275 |
if test $RC != 0 ; then |
| 276 |
echo "ldapsearch failed ($RC)!" |
| 277 |
test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 278 |
exit $RC |
| 279 |
fi |
| 280 |
|
| 281 |
echo "Filtering ldapsearch results..." |
| 282 |
$LDIFFILTER < $SEARCHOUT > $SEARCHFLT |
| 283 |
echo "Comparing filter output..." |
| 284 |
$CMP $SEARCHFLT $LDIFFLT > $CMPOUT |
| 285 |
|
| 286 |
if test $? != 0 ; then |
| 287 |
echo "Comparison failed" |
| 288 |
test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 289 |
exit 1 |
| 290 |
fi |
| 291 |
|
| 292 |
echo "Re-configuring proxy to use LDAP+StartTLS correctly on privileged connections..." |
| 293 |
$LDAPMODIFY -D cn=config -H $URI3 -y $CONFIGPWF \ |
| 294 |
> $TESTOUT 2>&1 <<EOF |
| 295 |
dn: olcDatabase={2}ldap,cn=config |
| 296 |
changetype: delete |
| 297 |
|
| 298 |
dn: olcDatabase={2}ldap,cn=config |
| 299 |
changetype: add |
| 300 |
objectClass: olcLDAPConfig |
| 301 |
olcDbUri: $URIP1 |
| 302 |
olcSuffix: $BASEDN |
| 303 |
olcRootDN: $MANAGERDN |
| 304 |
olcRootPW: $PASSWD |
| 305 |
olcDbIDAssertBind: bindmethod=none tls_cacert=$TESTDIR/tls/ca/certs/testsuiteCA.crt |
| 306 |
EOF |
| 307 |
RC=$? |
| 308 |
if test $RC != 0 ; then |
| 309 |
echo "modification failed ($RC)" |
| 310 |
test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 311 |
exit $RC |
| 312 |
fi |
| 313 |
|
| 314 |
echo "Privileged WhoAmI (proxy requests StartTLS)..." |
| 315 |
$LDAPWHOAMI -H $URI3 -D "$MANAGERDN" -w $PASSWD |
| 316 |
RC=$? |
| 317 |
if test $RC != 0 ; then |
| 318 |
echo "ldapwhoami failed ($RC)!" |
| 319 |
test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 320 |
exit $RC |
| 321 |
fi |
| 322 |
|
| 323 |
echo "WhoAmI (proxy requests StartTLS), which should fail..." |
| 324 |
$LDAPWHOAMI -H $URI3 -D "$BABSDN" -w bjensen |
| 325 |
RC=$? |
| 326 |
case $RC in |
| 327 |
49|52) # ACL forbids plaintext binds against userPassword |
| 328 |
;; |
| 329 |
0) |
| 330 |
echo "ldapwhoami should have failed ($RC)!" |
| 331 |
test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 332 |
exit 1 |
| 333 |
;; |
| 334 |
*) |
| 335 |
echo "ldapwhoami failed ($RC)!" |
| 336 |
test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 337 |
exit $RC |
| 338 |
;; |
| 339 |
esac |
| 340 |
|
| 341 |
# FIXME: just adding olcDbStartTLS to the DB doesn't have an effect, why? |
| 342 |
echo "Re-configuring proxy to use ldaps:// everywhere..." |
| 343 |
$LDAPMODIFY -D cn=config -H $URI3 -y $CONFIGPWF \ |
| 344 |
> $TESTOUT 2>&1 <<EOF |
| 345 |
dn: olcDatabase={2}ldap,cn=config |
| 346 |
changetype: modify |
| 347 |
add: olcDbStartTLS |
| 348 |
olcDbStartTLS: start tls_cacert=$TESTDIR/tls/ca/certs/testsuiteCA.crt |
| 349 |
EOF |
| 350 |
RC=$? |
| 351 |
if test $RC != 0 ; then |
| 352 |
echo "modification failed ($RC)" |
| 353 |
test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 354 |
exit $RC |
| 355 |
fi |
| 356 |
|
| 357 |
echo "WhoAmI (proxy requests StartTLS)..." |
| 358 |
$LDAPWHOAMI -H $URI3 -D "$BABSDN" -w bjensen |
| 359 |
RC=$? |
| 360 |
if test $RC != 0 ; then |
| 361 |
echo "ldapwhoami failed ($RC)!" |
| 362 |
test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 363 |
exit $RC |
| 364 |
fi |
| 365 |
|
| 366 |
echo "Searching (proxy requests StartTLS)..." |
| 367 |
echo "# Searching (proxy requests StartTLS)..." > $SEARCHOUT |
| 368 |
$LDAPSEARCH -b "$BASEDN" -H $URI3 \ |
| 369 |
-D "$BABSDN" -w bjensen \ |
| 370 |
'(objectClass=*)' >> $SEARCHOUT 2>&1 |
| 371 |
RC=$? |
| 372 |
if test $RC != 0 ; then |
| 373 |
echo "ldapsearch failed ($RC)!" |
| 374 |
test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 375 |
exit $RC |
| 376 |
fi |
| 377 |
|
| 378 |
echo "Filtering ldapsearch results..." |
| 379 |
$LDIFFILTER < $SEARCHOUT > $SEARCHFLT |
| 380 |
echo "Comparing filter output..." |
| 381 |
$CMP $SEARCHFLT $LDIFFLT > $CMPOUT |
| 382 |
|
| 383 |
if test $? != 0 ; then |
| 384 |
echo "Comparison failed" |
| 385 |
test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 386 |
exit 1 |
| 387 |
fi |
| 388 |
|
| 389 |
test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 390 |
|
| 391 |
echo ">>>>> Test succeeded" |
| 392 |
|
| 393 |
test $KILLSERVERS != no && wait |
| 394 |
|
| 395 |
exit 0 |