Home | History | Annotate | Line # | Download | only in scripts
      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 $BACKLDAP = ldapno; then
     20 	echo "LDAP backend not available, test skipped"
     21 	exit 0
     22 fi
     23 
     24 if test $RWM = rwmno; then
     25 	echo "rwm (rewrite/remap) overlay not available, test skipped"
     26 	exit 0
     27 fi
     28 
     29 if test $SYNCPROV = syncprovno; then 
     30 	echo "Syncrepl provider overlay not available, test skipped"
     31 	exit 0
     32 fi 
     33 
     34 RMTSUFFIX="dc=remote,$BASEDN"
     35 RMTROOTDN="cn=Manager,$RMTSUFFIX"
     36 
     37 RMTDIR=$TESTDIR/remote
     38 PR1DIR=$TESTDIR/provider1
     39 PR2DIR=$TESTDIR/provider2
     40 RMTCONF=$RMTDIR/slapd.d
     41 PR1CONF=$PR1DIR/slapd.d
     42 PR2CONF=$PR2DIR/slapd.d
     43 
     44 ENTRIES=$TESTDIR/entries.ldif
     45 SYNC1OUT=$TESTDIR/syncrepl1.out
     46 SYNC2OUT=$TESTDIR/syncrepl2.out
     47 
     48 mkdir -p $RMTDIR $RMTCONF $RMTDIR/db
     49 mkdir -p $PR1DIR $PR1CONF $PR1DIR/db
     50 mkdir -p $PR2DIR $PR2CONF $PR2DIR/db
     51 
     52 cd $TESTDIR
     53 
     54 KILLPIDS=
     55 
     56 $SLAPPASSWD -g -n > $CONFIGPWF
     57 
     58 cat <<EOF > $CONFLDIF
     59 dn: cn=config
     60 objectClass: olcGlobal
     61 cn: config
     62 
     63 dn: olcDatabase={0}config,cn=config
     64 objectClass: olcDatabaseConfig
     65 olcDatabase: {0}config
     66 olcRootPW:< file://$CONFIGPWF
     67 
     68 dn: cn=schema,cn=config
     69 objectClass: olcSchemaConfig
     70 cn: schema
     71 
     72 include: file://$ABS_SCHEMADIR/core.ldif
     73 include: file://$ABS_SCHEMADIR/cosine.ldif
     74 include: file://$ABS_SCHEMADIR/nis.ldif
     75 include: file://$ABS_SCHEMADIR/inetorgperson.ldif
     76 
     77 dn: cn=module,cn=config
     78 objectClass: olcModuleList
     79 cn: module
     80 olcModulePath: $TESTWD/../servers/slapd/overlays
     81 EOF
     82 
     83 [ "$BACKENDTYPE" = mod ] && echo "olcModuleLoad: $TESTWD/../servers/slapd/back-$BACKEND/back_$BACKEND.la" >> $CONFLDIF
     84 
     85 echo "Initializing remote configurations..."
     86 cat $CONFLDIF - <<EOF | $SLAPADD -F $RMTCONF -n 0
     87 
     88 dn: olcDatabase={1}$BACKEND,cn=config
     89 objectClass: olcDatabaseConfig
     90 ${nullExclude}objectClass: olc${BACKEND}Config
     91 olcDatabase: {1}$BACKEND
     92 ${nullExclude}olcDbDirectory: $RMTDIR/db
     93 olcSuffix: $RMTSUFFIX
     94 olcRootDN: $RMTROOTDN
     95 olcRootPW: $PASSWD
     96 EOF
     97 RC=$?
     98 if test $RC != 0 ; then
     99 	echo "slapadd failed ($RC)!"
    100 	exit $RC
    101 fi
    102 
    103 [ "$BACKLDAP" = ldapmod ] && echo "olcModuleLoad: $TESTWD/../servers/slapd/back-ldap/back_ldap.la" >> $CONFLDIF
    104 [ "$RWM" = rwmmod ] && echo "olcModuleLoad: rwm.la" >> $CONFLDIF
    105 [ "$SYNCPROV" = syncprovmod ] && echo "olcModuleLoad: syncprov.la" >> $CONFLDIF
    106 cat <<EOF >> $CONFLDIF
    107 
    108 dn: olcDatabase={1}ldap,cn=config
    109 objectClass: olcDatabaseConfig
    110 objectClass: olcLDAPConfig
    111 olcDatabase: {1}ldap
    112 olcSuffix: ou=remote,ou=users,$BASEDN
    113 olcSubordinate: TRUE
    114 olcDbURI: $URI1
    115 olcDbIDAssertBind: bindmethod=simple
    116   binddn="$RMTROOTDN"
    117   credentials=$PASSWD
    118   mode=none
    119 olcDbIDAssertAuthzFrom: dn.exact:$MANAGERDN
    120 olcRootDN: $MANAGERDN
    121 
    122 dn: olcOverlay={0}rwm,olcDatabase={1}ldap,cn=config
    123 objectClass: olcOverlayConfig
    124 objectClass: olcRwmConfig
    125 olcOverlay: {0}rwm
    126 olcRwmRewrite: rwm-suffixmassage "ou=users,$RMTSUFFIX"
    127 EOF
    128 
    129 echo "Initializing provider1 configurations..."
    130 cat $CONFLDIF - <<EOF | $SLAPADD -F $PR1CONF -n 0
    131 
    132 dn: olcDatabase={2}$BACKEND,cn=config
    133 objectClass: olcDatabaseConfig
    134 ${nullExclude}objectClass: olc${BACKEND}Config
    135 olcDatabase: {2}$BACKEND
    136 ${nullExclude}olcDbDirectory: $PR1DIR/db
    137 olcSuffix: $BASEDN
    138 olcRootDN: $MANAGERDN
    139 olcRootPW: $PASSWD
    140 
    141 dn: olcOverlay={0}syncprov,olcDatabase={2}$BACKEND,cn=config
    142 objectClass: olcOverlayConfig
    143 objectClass: olcSyncProvConfig
    144 olcOverlay: {0}syncprov
    145 EOF
    146 RC=$?
    147 if test $RC != 0 ; then
    148 	echo "slapadd failed ($RC)!"
    149 	exit $RC
    150 fi
    151 
    152 echo "Initializing provider2 configurations..."
    153 cat $CONFLDIF - <<EOF | $SLAPADD -F $PR2CONF -n 0
    154 
    155 dn: olcDatabase={2}$BACKEND,cn=config
    156 objectClass: olcDatabaseConfig
    157 ${nullExclude}objectClass: olc${BACKEND}Config
    158 olcDatabase: {2}$BACKEND
    159 ${nullExclude}olcDbDirectory: $PR2DIR/db
    160 olcSuffix: $BASEDN
    161 olcRootDN: $MANAGERDN
    162 olcRootPW: $PASSWD
    163 
    164 dn: olcOverlay={0}glue,olcDatabase={2}$BACKEND,cn=config
    165 objectClass: olcOverlayConfig
    166 objectClass: olcConfig
    167 olcOverlay: {0}glue
    168 
    169 dn: olcOverlay={1}syncprov,olcDatabase={2}$BACKEND,cn=config
    170 objectClass: olcOverlayConfig
    171 objectClass: olcSyncProvConfig
    172 olcOverlay: {1}syncprov
    173 EOF
    174 RC=$?
    175 if test $RC != 0 ; then
    176 	echo "slapadd failed ($RC)!"
    177 	exit $RC
    178 fi
    179 
    180 echo "Starting remote slapd on TCP/IP port $PORT1..."
    181 cd $RMTDIR
    182 $SLAPD -F slapd.d -h $URI1 -d $LVL > $LOG1 2>&1 &
    183 PID=$!
    184 if test $WAIT != 0 ; then
    185     echo PID $PID
    186     read foo
    187 fi
    188 KILLPIDS="$KILLPIDS $PID"
    189 cd $TESTWD
    190 sleep 1
    191 echo "Using ldapsearch to check that remote slapd is running..."
    192 for i in 0 1 2 3 4 5; do
    193 	$LDAPSEARCH -s base -b "" -H $URI1 \
    194 		'objectclass=*' > /dev/null 2>&1
    195 	RC=$?
    196 	if test $RC = 0 ; then
    197 		break
    198 	fi
    199 	echo "Waiting 5 seconds for slapd to start..."
    200 	sleep 5
    201 done
    202 if test $RC != 0 ; then
    203 	echo "ldapsearch failed ($RC)!"
    204 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    205 	exit $RC
    206 fi
    207 
    208 echo "Starting provider1 slapd on TCP/IP port $PORT2..."
    209 cd $PR1DIR
    210 $SLAPD -F slapd.d -h $URI2 -d $LVL > $LOG2 2>&1 &
    211 PID=$!
    212 if test $WAIT != 0 ; then
    213     echo PID $PID
    214     read foo
    215 fi
    216 KILLPIDS="$KILLPIDS $PID"
    217 cd $TESTWD
    218 sleep 1
    219 echo "Using ldapsearch to check that provider1 slapd is running..."
    220 for i in 0 1 2 3 4 5; do
    221 	$LDAPSEARCH -s base -b "" -H $URI2 \
    222 		'objectclass=*' > /dev/null 2>&1
    223 	RC=$?
    224 	if test $RC = 0 ; then
    225 		break
    226 	fi
    227 	echo "Waiting 5 seconds for slapd to start..."
    228 	sleep 5
    229 done
    230 if test $RC != 0 ; then
    231 	echo "ldapsearch failed ($RC)!"
    232 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    233 	exit $RC
    234 fi
    235 
    236 echo "Starting provider2 slapd on TCP/IP port $PORT3..."
    237 cd $PR2DIR
    238 $SLAPD -F slapd.d -h $URI3 -d $LVL > $LOG3 2>&1 &
    239 PID=$!
    240 if test $WAIT != 0 ; then
    241     echo PID $PID
    242     read foo
    243 fi
    244 KILLPIDS="$KILLPIDS $PID"
    245 cd $TESTWD
    246 sleep 1
    247 echo "Using ldapsearch to check that provider2 slapd is running..."
    248 for i in 0 1 2 3 4 5; do
    249 	$LDAPSEARCH -s base -b "" -H $URI3 \
    250 		'objectclass=*' > /dev/null 2>&1
    251 	RC=$?
    252 	if test $RC = 0 ; then
    253 		break
    254 	fi
    255 	echo "Waiting 5 seconds for slapd to start..."
    256 	sleep 5
    257 done
    258 if test $RC != 0 ; then
    259 	echo "ldapsearch failed ($RC)!"
    260 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    261 	exit $RC
    262 fi
    263 
    264 echo "Populating remote database entries..."
    265 $LDAPADD -D "$RMTROOTDN" -H $URI1 -w $PASSWD <<EOF >> $TESTOUT 2>&1
    266 dn: $RMTSUFFIX
    267 objectClass: dcObject
    268 objectClass: organization
    269 dc: `echo $RMTSUFFIX | sed 's/^dc=\([^,]*\),.*/\1/'`
    270 o: Example, Inc
    271 
    272 dn: ou=users,$RMTSUFFIX
    273 objectClass: organizationalUnit
    274 ou: users
    275 EOF
    276 RC=$?
    277 if test $RC != 0 ; then
    278 	echo "ldapadd failed to populate remote database entries ($RC)!"
    279 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    280 	exit $RC
    281 fi
    282 
    283 cat <<EOF > $ENTRIES
    284 dn: $BASEDN
    285 objectClass: dcObject
    286 objectClass: organization
    287 dc: example
    288 o: Example, Inc
    289 
    290 dn: ou=users,$BASEDN
    291 objectClass: organizationalUnit
    292 ou: users
    293 
    294 dn: ou=local,ou=users,$BASEDN
    295 objectClass: organizationalUnit
    296 ou: local
    297 EOF
    298 
    299 echo "Populating provider1 database entries..."
    300 $LDAPADD -D "$MANAGERDN" -H $URI2 -w $PASSWD < $ENTRIES >> $TESTOUT 2>&1
    301 RC=$?
    302 if test $RC != 0 ; then
    303 	echo "ldapadd failed to populate provider1 database entries ($RC)!"
    304 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    305 	exit $RC
    306 fi
    307 
    308 echo "Populating provider2 database entries..."
    309 $LDAPADD -D "$MANAGERDN" -H $URI3 -w $PASSWD < $ENTRIES >> $TESTOUT 2>&1
    310 RC=$?
    311 if test $RC != 0 ; then
    312 	echo "ldapadd failed to populate provider2 database entries ($RC)!"
    313 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    314 	exit $RC
    315 fi
    316 
    317 echo "Starting refreshAndPersist search on provider1..."
    318 $LDAPRSEARCH -D $MANAGERDN -H $URI2 -w $PASSWD -MM -E sync=rp -b $BASEDN '*' + 2>&1 > $SYNC1OUT &
    319 PID=$!
    320 RC=32
    321 for i in 0 1 2 3 4 5; do
    322 	echo "Waiting for refreshDone message..."
    323 	sleep $SLEEP0
    324 	if grep '^# refresh done, switching to persist stage' $SYNC1OUT; then
    325 		awk '/^result:/{print; exit $2}' $SYNC1OUT
    326 		RC=$?
    327 		break
    328 	fi
    329 done
    330 if test $RC != 0 ; then
    331 	echo "refresh failed ($RC)!"
    332 	kill $PID
    333 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    334 	exit $RC
    335 fi
    336 
    337 echo "Using ldapadd to add local entry on provider1..."
    338 $LDAPADD -D $MANAGERDN -H $URI2 -w $PASSWD <<EOF >> $TESTOUT 2>&1
    339 dn: cn=local_user,ou=local,ou=users,$BASEDN
    340 objectClass: person
    341 cn: local_user
    342 sn: local_user
    343 userPassword: $PASSWD
    344 description: add local_user
    345 EOF
    346 RC=32
    347 for i in 0 1 2 3 4 5; do
    348 	echo "Waiting for syncrepl to receive changes..."
    349 	sleep $SLEEP0
    350 	if grep -q '^dn: cn=local_user' $SYNC1OUT; then
    351 		RC=0
    352 		break
    353 	fi
    354 done
    355 if test $RC != 0 ; then
    356 	echo "syncrepl failed ($RC)!"
    357 	kill $PID
    358 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    359 	exit $RC
    360 fi
    361 
    362 echo "Using ldapmodify to modify local entry on provider1..."
    363 $LDAPMODIFY -D $MANAGERDN -H $URI2 -w $PASSWD <<EOF >> $TESTOUT 2>&1
    364 dn: cn=local_user,ou=local,ou=users,$BASEDN
    365 changeType: modify
    366 replace: description
    367 description: modify local_user
    368 EOF
    369 RC=32
    370 for i in 0 1 2 3 4 5; do
    371 	echo "Waiting for syncrepl to receive changes..."
    372 	sleep $SLEEP0
    373 	if grep -q '^description: modify local_user' $SYNC1OUT; then
    374 		RC=0
    375 		break
    376 	fi
    377 done
    378 if test $RC != 0 ; then
    379 	echo "syncrepl failed ($RC)!"
    380 	kill $PID
    381 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    382 	exit $RC
    383 fi
    384 
    385 echo "Using ldapmodrdn to rename local entry on provider1..."
    386 $LDAPMODRDN -D $MANAGERDN -H $URI2 -w $PASSWD -r <<EOF >> $TESTOUT 2>&1
    387 cn=local_user,ou=local,ou=users,$BASEDN
    388 cn=local_user1
    389 EOF
    390 RC=32
    391 for i in 0 1 2 3 4 5; do
    392 	echo "Waiting for syncrepl to receive changes..."
    393 	sleep $SLEEP0
    394 	if grep -q '^dn: cn=local_user1' $SYNC1OUT; then
    395 		RC=0
    396 		break
    397 	fi
    398 done
    399 kill $PID
    400 if test $RC != 0 ; then
    401 	echo "syncrepl failed ($RC)!"
    402 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    403 	exit $RC
    404 fi
    405 
    406 echo "Check that remote entries are NOT replicated..."
    407 if grep 'ou=remote,' $SYNC1OUT; then
    408 	echo "remote entries were unexpectedly replicated!"
    409 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    410 	exit 1
    411 fi
    412 
    413 echo "Starting refreshAndPersist search on provider2..."
    414 $LDAPRSEARCH -D $MANAGERDN -H $URI3 -w $PASSWD -MM -E sync=rp -b $BASEDN '*' + 2>&1 > $SYNC2OUT &
    415 PID=$!
    416 RC=32
    417 for i in 0 1 2 3 4 5; do
    418 	echo "Waiting for refreshDone message..."
    419 	sleep $SLEEP0
    420 	if grep '^# refresh done, switching to persist stage' $SYNC2OUT; then
    421 		awk '/^result:/{print; exit $2}' $SYNC2OUT
    422 		RC=$?
    423 		break
    424 	fi
    425 done
    426 if test $RC != 0 ; then
    427 	echo "refresh failed ($RC)!"
    428 	kill $PID
    429 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    430 	exit $RC
    431 fi
    432 
    433 echo "Using ldapadd to add local entry on provider2..."
    434 $LDAPADD -D $MANAGERDN -H $URI3 -w $PASSWD <<EOF >> $TESTOUT 2>&1
    435 dn: cn=local_user,ou=local,ou=users,$BASEDN
    436 objectClass: person
    437 cn: local_user
    438 sn: local_user
    439 userPassword: $PASSWD
    440 description: add local_user
    441 EOF
    442 RC=32
    443 for i in 0 1 2 3 4 5; do
    444 	echo "Waiting for syncrepl to receive changes..."
    445 	sleep $SLEEP0
    446 	if grep -q '^dn: cn=local_user' $SYNC2OUT; then
    447 		RC=0
    448 		break
    449 	fi
    450 done
    451 if test $RC != 0 ; then
    452 	echo "syncrepl failed ($RC)!"
    453 	kill $PID
    454 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    455 	exit $RC
    456 fi
    457 
    458 echo "Using ldapmodify to modify local entry on provider2..."
    459 $LDAPMODIFY -D $MANAGERDN -H $URI3 -w $PASSWD <<EOF >> $TESTOUT 2>&1
    460 dn: cn=local_user,ou=local,ou=users,$BASEDN
    461 changeType: modify
    462 replace: description
    463 description: modify local_user
    464 EOF
    465 RC=32
    466 for i in 0 1 2 3 4 5; do
    467 	echo "Waiting for syncrepl to receive changes..."
    468 	sleep $SLEEP0
    469 	if grep -q '^description: modify local_user' $SYNC2OUT; then
    470 		RC=0
    471 		break
    472 	fi
    473 done
    474 if test $RC != 0 ; then
    475 	echo "syncrepl failed ($RC)!"
    476 	kill $PID
    477 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    478 	exit $RC
    479 fi
    480 
    481 echo "Using ldapmodrdn to rename local entry on provider2..."
    482 $LDAPMODRDN -D $MANAGERDN -H $URI3 -w $PASSWD -r <<EOF >> $TESTOUT 2>&1
    483 cn=local_user,ou=local,ou=users,$BASEDN
    484 cn=local_user1
    485 EOF
    486 RC=32
    487 for i in 0 1 2 3 4 5; do
    488 	echo "Waiting for syncrepl to receive changes..."
    489 	sleep $SLEEP0
    490 	if grep -q '^dn: cn=local_user1' $SYNC2OUT; then
    491 		RC=0
    492 		break
    493 	fi
    494 done
    495 if test $RC != 0 ; then
    496 	echo "syncrepl failed ($RC)!"
    497 	kill $PID
    498 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    499 	exit $RC
    500 fi
    501 
    502 echo "Using ldapadd to add remote entry on provider2..."
    503 $LDAPADD -D $MANAGERDN -H $URI3 -w $PASSWD <<EOF >> $TESTOUT 2>&1
    504 dn: cn=remote_user,ou=remote,ou=users,$BASEDN
    505 objectClass: person
    506 cn: remote_user
    507 sn: remote_user
    508 userPassword: $PASSWD
    509 description: add remote_user
    510 EOF
    511 RC=32
    512 for i in 0 1 2 3 4 5; do
    513 	echo "Waiting for syncrepl to receive changes..."
    514 	sleep $SLEEP0
    515 	if grep -q '^dn: cn=remote_user' $SYNC2OUT; then
    516 		RC=0
    517 		break
    518 	fi
    519 done
    520 if test $RC != 0 ; then
    521 	echo "syncrepl failed ($RC)!"
    522 	kill $PID
    523 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    524 	exit $RC
    525 fi
    526 
    527 echo "Using ldapmodify to modify remote entry on provider2..."
    528 $LDAPMODIFY -D $MANAGERDN -H $URI3 -w $PASSWD <<EOF >> $TESTOUT 2>&1
    529 dn: cn=remote_user,ou=remote,ou=users,$BASEDN
    530 changeType: modify
    531 replace: description
    532 description: modify remote_user
    533 EOF
    534 RC=32
    535 for i in 0 1 2 3 4 5; do
    536 	echo "Waiting for syncrepl to receive changes..."
    537 	sleep $SLEEP0
    538 	if grep -q '^description: modify remote_user' $SYNC2OUT; then
    539 		RC=0
    540 		break
    541 	fi
    542 done
    543 if test $RC != 0 ; then
    544 	echo "syncrepl failed ($RC)!"
    545 	kill $PID
    546 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    547 	exit $RC
    548 fi
    549 
    550 echo "Using ldapmodrdn to rename remote entry on provider2..."
    551 $LDAPMODRDN -D $MANAGERDN -H $URI3 -w $PASSWD -r <<EOF >> $TESTOUT 2>&1
    552 cn=remote_user,ou=remote,ou=users,$BASEDN
    553 cn=remote_user1
    554 EOF
    555 RC=32
    556 for i in 0 1 2 3 4 5; do
    557 	echo "Waiting for syncrepl to receive changes..."
    558 	sleep $SLEEP0
    559 	if grep -q '^dn: cn=remote_user1' $SYNC2OUT; then
    560 		RC=0
    561 		break
    562 	fi
    563 done
    564 kill $PID
    565 if test $RC != 0 ; then
    566 	echo "syncrepl failed ($RC)!"
    567 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    568 	exit $RC
    569 fi
    570 
    571 test $KILLSERVERS != no && kill -HUP $KILLPIDS
    572 
    573 echo ">>>>> Test succeeded"
    574 exit 0
    575