mrc0mmand / rpms / openldap

Forked from rpms/openldap 3 years ago
Clone

Blame SOURCES/openldap-cbinding-ITS-8573-TLS-option-test-suite.patch

ad145f
From eb087e0861f207858a4e08c72836a86f26d9701c Mon Sep 17 00:00:00 2001
ad145f
From: Quanah Gibson-Mount <quanah@openldap.org>
ad145f
Date: Thu, 14 Jun 2018 16:12:59 +0100
ad145f
Subject: [PATCH] ITS#8573 TLS option test suite
ad145f
ad145f
---
ad145f
 configure                                     |   4 +
ad145f
 configure.in                                  |   4 +
ad145f
 tests/data/slapd-tls-sasl.conf                |  65 ++
ad145f
 tests/data/slapd-tls.conf                     |  61 ++
ad145f
 tests/data/tls/ca/certs/testsuiteCA.crt       |  16 +
ad145f
 tests/data/tls/ca/private/testsuiteCA.key     |  16 +
ad145f
 .../tls/certs/bjensen@mailgw.example.com.crt  |  16 +
ad145f
 tests/data/tls/certs/localhost.crt            |  16 +
ad145f
 tests/data/tls/conf/openssl.cnf               | 129 ++++
ad145f
 tests/data/tls/create-crt.sh                  |  78 +++
ad145f
 .../private/bjensen@mailgw.example.com.key    |  16 +
ad145f
 tests/data/tls/private/localhost.key          |  16 +
ad145f
 tests/run.in                                  |   3 +-
ad145f
 tests/scripts/defines.sh                      |  21 +-
ad145f
 tests/scripts/test067-tls                     | 140 +++++
ad145f
 tests/scripts/test068-sasl-tls-external       | 102 ++++
ad145f
 .../test069-delta-multimaster-starttls        | 574 ++++++++++++++++++
ad145f
 tests/scripts/test070-delta-multimaster-ldaps | 571 +++++++++++++++++
ad145f
 18 files changed, 1846 insertions(+), 2 deletions(-)
ad145f
 create mode 100644 tests/data/slapd-tls-sasl.conf
ad145f
 create mode 100644 tests/data/slapd-tls.conf
ad145f
 create mode 100644 tests/data/tls/ca/certs/testsuiteCA.crt
ad145f
 create mode 100644 tests/data/tls/ca/private/testsuiteCA.key
ad145f
 create mode 100644 tests/data/tls/certs/bjensen@mailgw.example.com.crt
ad145f
 create mode 100644 tests/data/tls/certs/localhost.crt
ad145f
 create mode 100644 tests/data/tls/conf/openssl.cnf
ad145f
 create mode 100755 tests/data/tls/create-crt.sh
ad145f
 create mode 100644 tests/data/tls/private/bjensen@mailgw.example.com.key
ad145f
 create mode 100644 tests/data/tls/private/localhost.key
ad145f
 create mode 100755 tests/scripts/test067-tls
ad145f
 create mode 100755 tests/scripts/test068-sasl-tls-external
ad145f
 create mode 100755 tests/scripts/test069-delta-multimaster-starttls
ad145f
 create mode 100755 tests/scripts/test070-delta-multimaster-ldaps
ad145f
ad145f
diff --git a/configure b/configure
ad145f
index 16d4ab884..29b7ad91d 100755
ad145f
--- a/configure
ad145f
+++ b/configure
ad145f
@@ -761,6 +761,7 @@ AUTH_LIBS
ad145f
 LIBSLAPI
ad145f
 SLAPI_LIBS
ad145f
 MODULES_LIBS
ad145f
+WITH_TLS_TYPE
ad145f
 TLS_LIBS
ad145f
 SASL_LIBS
ad145f
 KRB5_LIBS
ad145f
@@ -5223,6 +5224,7 @@ KRB4_LIBS=
ad145f
 KRB5_LIBS=
ad145f
 SASL_LIBS=
ad145f
 TLS_LIBS=
ad145f
+WITH_TLS_TYPE=
ad145f
 MODULES_LIBS=
ad145f
 SLAPI_LIBS=
ad145f
 LIBSLAPI=
ad145f
@@ -15701,6 +15703,7 @@ fi
ad145f
 		if test $have_openssl = yes ; then
ad145f
 			ol_with_tls=openssl
ad145f
 			ol_link_tls=yes
ad145f
+			WITH_TLS_TYPE=openssl
ad145f
 
ad145f
 
ad145f
 $as_echo "#define HAVE_OPENSSL 1" >>confdefs.h
ad145f
@@ -15835,6 +15838,7 @@ fi
ad145f
 			if test $have_gnutls = yes ; then
ad145f
 				ol_with_tls=gnutls
ad145f
 				ol_link_tls=yes
ad145f
+				WITH_TLS_TYPE=gnutls
ad145f
 
ad145f
 				TLS_LIBS="-lgnutls"
ad145f
 
ad145f
diff --git a/configure.in b/configure.in
ad145f
index ee25a4a90..60c446096 100644
ad145f
--- a/configure.in
ad145f
+++ b/configure.in
ad145f
@@ -610,6 +610,7 @@ KRB4_LIBS=
ad145f
 KRB5_LIBS=
ad145f
 SASL_LIBS=
ad145f
 TLS_LIBS=
ad145f
+WITH_TLS_TYPE=
ad145f
 MODULES_LIBS=
ad145f
 SLAPI_LIBS=
ad145f
 LIBSLAPI=
ad145f
@@ -1210,6 +1211,7 @@ if test $ol_with_tls = openssl || test $ol_with_tls = auto ; then
ad145f
 		if test $have_openssl = yes ; then
ad145f
 			ol_with_tls=openssl
ad145f
 			ol_link_tls=yes
ad145f
+			WITH_TLS_TYPE=openssl
ad145f
 
ad145f
 			AC_DEFINE(HAVE_OPENSSL, 1, 
ad145f
 				[define if you have OpenSSL])
ad145f
@@ -1250,6 +1252,7 @@ if test $ol_link_tls = no ; then
ad145f
 			if test $have_gnutls = yes ; then
ad145f
 				ol_with_tls=gnutls
ad145f
 				ol_link_tls=yes
ad145f
+				WITH_TLS_TYPE=gnutls
ad145f
 
ad145f
 				TLS_LIBS="-lgnutls"
ad145f
 
ad145f
@@ -3261,6 +3264,7 @@ AC_SUBST(KRB4_LIBS)
ad145f
 AC_SUBST(KRB5_LIBS)
ad145f
 AC_SUBST(SASL_LIBS)
ad145f
 AC_SUBST(TLS_LIBS)
ad145f
+AC_SUBST(WITH_TLS_TYPE)
ad145f
 AC_SUBST(MODULES_LIBS)
ad145f
 AC_SUBST(SLAPI_LIBS)
ad145f
 AC_SUBST(LIBSLAPI)
ad145f
diff --git a/tests/data/slapd-tls-sasl.conf b/tests/data/slapd-tls-sasl.conf
ad145f
new file mode 100644
ad145f
index 000000000..f4bb0773e
ad145f
--- /dev/null
ad145f
+++ b/tests/data/slapd-tls-sasl.conf
ad145f
@@ -0,0 +1,65 @@
ad145f
+# stand-alone slapd config -- for testing (with indexing)
ad145f
+# $OpenLDAP$
ad145f
+## This work is part of OpenLDAP Software <http://www.openldap.org/>.
ad145f
+##
ad145f
+## Copyright 1998-2017 The OpenLDAP Foundation.
ad145f
+## All rights reserved.
ad145f
+##
ad145f
+## Redistribution and use in source and binary forms, with or without
ad145f
+## modification, are permitted only as authorized by the OpenLDAP
ad145f
+## Public License.
ad145f
+##
ad145f
+## A copy of this license is available in the file LICENSE in the
ad145f
+## top-level directory of the distribution or, alternatively, at
ad145f
+## <http://www.OpenLDAP.org/license.html>.
ad145f
+
ad145f
+#
ad145f
+include		@SCHEMADIR@/core.schema
ad145f
+include		@SCHEMADIR@/cosine.schema
ad145f
+#
ad145f
+include		@SCHEMADIR@/corba.schema
ad145f
+include		@SCHEMADIR@/java.schema
ad145f
+include		@SCHEMADIR@/inetorgperson.schema
ad145f
+include		@SCHEMADIR@/misc.schema
ad145f
+include		@SCHEMADIR@/nis.schema
ad145f
+include		@SCHEMADIR@/openldap.schema
ad145f
+#
ad145f
+include		@SCHEMADIR@/duaconf.schema
ad145f
+include		@SCHEMADIR@/dyngroup.schema
ad145f
+include		@SCHEMADIR@/ppolicy.schema
ad145f
+
ad145f
+#
ad145f
+pidfile		@TESTDIR@/slapd.1.pid
ad145f
+argsfile	@TESTDIR@/slapd.1.args
ad145f
+
ad145f
+# SSL configuration
ad145f
+TLSCACertificateFile @TESTDIR@/tls/ca/certs/testsuiteCA.crt
ad145f
+TLSCertificateKeyFile @TESTDIR@/tls/private/localhost.key
ad145f
+TLSCertificateFile @TESTDIR@/tls/certs/localhost.crt
ad145f
+TLSVerifyClient hard
ad145f
+
ad145f
+#
ad145f
+rootdse 	@DATADIR@/rootdse.ldif
ad145f
+
ad145f
+#mod#modulepath	../servers/slapd/back-@BACKEND@/
ad145f
+#mod#moduleload	back_@BACKEND@.la
ad145f
+#monitormod#modulepath ../servers/slapd/back-monitor/
ad145f
+#monitormod#moduleload back_monitor.la
ad145f
+
ad145f
+authz-regexp "email=([^,]*),cn=[^,]*,ou=OpenLDAP,o=OpenLDAP Foundation,st=CA,c=US" ldap:///ou=People,dc=example,dc=com??sub?(mail=$1)
ad145f
+
ad145f
+#######################################################################
ad145f
+# database definitions
ad145f
+#######################################################################
ad145f
+
ad145f
+database	@BACKEND@
ad145f
+suffix          "dc=example,dc=com"
ad145f
+rootdn          "cn=Manager,dc=example,dc=com"
ad145f
+rootpw          secret
ad145f
+#~null~#directory	@TESTDIR@/db.1.a
ad145f
+#indexdb#index		objectClass eq
ad145f
+#indexdb#index		mail eq
ad145f
+#ndb#dbname db_1_a
ad145f
+#ndb#include @DATADIR@/ndb.conf
ad145f
+
ad145f
+#monitor#database	monitor
ad145f
diff --git a/tests/data/slapd-tls.conf b/tests/data/slapd-tls.conf
ad145f
new file mode 100644
ad145f
index 000000000..6a7785557
ad145f
--- /dev/null
ad145f
+++ b/tests/data/slapd-tls.conf
ad145f
@@ -0,0 +1,61 @@
ad145f
+# stand-alone slapd config -- for testing (with indexing)
ad145f
+# $OpenLDAP$
ad145f
+## This work is part of OpenLDAP Software <http://www.openldap.org/>.
ad145f
+##
ad145f
+## Copyright 1998-2017 The OpenLDAP Foundation.
ad145f
+## All rights reserved.
ad145f
+##
ad145f
+## Redistribution and use in source and binary forms, with or without
ad145f
+## modification, are permitted only as authorized by the OpenLDAP
ad145f
+## Public License.
ad145f
+##
ad145f
+## A copy of this license is available in the file LICENSE in the
ad145f
+## top-level directory of the distribution or, alternatively, at
ad145f
+## <http://www.OpenLDAP.org/license.html>.
ad145f
+
ad145f
+#
ad145f
+include		@SCHEMADIR@/core.schema
ad145f
+include		@SCHEMADIR@/cosine.schema
ad145f
+#
ad145f
+include		@SCHEMADIR@/corba.schema
ad145f
+include		@SCHEMADIR@/java.schema
ad145f
+include		@SCHEMADIR@/inetorgperson.schema
ad145f
+include		@SCHEMADIR@/misc.schema
ad145f
+include		@SCHEMADIR@/nis.schema
ad145f
+include		@SCHEMADIR@/openldap.schema
ad145f
+#
ad145f
+include		@SCHEMADIR@/duaconf.schema
ad145f
+include		@SCHEMADIR@/dyngroup.schema
ad145f
+include		@SCHEMADIR@/ppolicy.schema
ad145f
+
ad145f
+#
ad145f
+pidfile		@TESTDIR@/slapd.1.pid
ad145f
+argsfile	@TESTDIR@/slapd.1.args
ad145f
+
ad145f
+# SSL configuration
ad145f
+TLSCertificateKeyFile @TESTDIR@/tls/private/localhost.key
ad145f
+TLSCertificateFile @TESTDIR@/tls/certs/localhost.crt
ad145f
+
ad145f
+#
ad145f
+rootdse 	@DATADIR@/rootdse.ldif
ad145f
+
ad145f
+#mod#modulepath	../servers/slapd/back-@BACKEND@/
ad145f
+#mod#moduleload	back_@BACKEND@.la
ad145f
+#monitormod#modulepath ../servers/slapd/back-monitor/
ad145f
+#monitormod#moduleload back_monitor.la
ad145f
+
ad145f
+#######################################################################
ad145f
+# database definitions
ad145f
+#######################################################################
ad145f
+
ad145f
+database	@BACKEND@
ad145f
+suffix          "dc=example,dc=com"
ad145f
+rootdn          "cn=Manager,dc=example,dc=com"
ad145f
+rootpw          secret
ad145f
+#~null~#directory	@TESTDIR@/db.1.a
ad145f
+#indexdb#index		objectClass eq
ad145f
+#indexdb#index		mail eq
ad145f
+#ndb#dbname db_1_a
ad145f
+#ndb#include @DATADIR@/ndb.conf
ad145f
+
ad145f
+#monitor#database	monitor
ad145f
diff --git a/tests/data/tls/ca/certs/testsuiteCA.crt b/tests/data/tls/ca/certs/testsuiteCA.crt
ad145f
new file mode 100644
ad145f
index 000000000..7458e7461
ad145f
--- /dev/null
ad145f
+++ b/tests/data/tls/ca/certs/testsuiteCA.crt
ad145f
@@ -0,0 +1,16 @@
ad145f
+-----BEGIN CERTIFICATE-----
ad145f
+MIICgjCCAeugAwIBAgIJAJGJtO9oGgLiMA0GCSqGSIb3DQEBCwUAMFkxCzAJBgNV
ad145f
+BAYTAlVTMQswCQYDVQQIDAJDQTEcMBoGA1UECgwTT3BlbkxEQVAgRm91bmRhdGlv
ad145f
+bjEfMB0GA1UECwwWT3BlbkxEQVAgVGVzdCBTdWl0ZSBDQTAgFw0xNzAxMTkyMDI0
ad145f
+NTFaGA8yNTE4MDIwMjIwMjQ1MVowWTELMAkGA1UEBhMCVVMxCzAJBgNVBAgMAkNB
ad145f
+MRwwGgYDVQQKDBNPcGVuTERBUCBGb3VuZGF0aW9uMR8wHQYDVQQLDBZPcGVuTERB
ad145f
+UCBUZXN0IFN1aXRlIENBMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC3xcMd
ad145f
+rvEPxIzZ0FnGVfk6sLXW//4UbBZmmsHSNT7UDNpL301QrsOaATyiOMSPHxmQoLPb
ad145f
+lYOtTCPaHN9/KIHoCnEQ6tJRe30okA0DFnZvSH5jAm9E2QvsXMVXU5XIi9dZTNdL
ad145f
+6jwRajPQP3YfK+PyrtIqc0IvhB4Ori39vrFLpQIDAQABo1AwTjAdBgNVHQ4EFgQU
ad145f
+7fEPwfVJESrieK5MzzjBSK8xEfIwHwYDVR0jBBgwFoAU7fEPwfVJESrieK5MzzjB
ad145f
+SK8xEfIwDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQsFAAOBgQBtXLZWW6ZKZux/
ad145f
+wk7uLNZl01kPJUBiI+yMU5uY5PgOph1CpaUXp3QftCb0yRQ2g5d0CNYI5DyXuHws
ad145f
+ZSZRFF8SRwm3AogkMzYKenPF5m2OXSpvOMdnlbbFmIJnvwUfKhtinw+r0zvW8I8Q
ad145f
+aL52EFPS0o3tiAJXS82U2wrQdJ0YEw==
ad145f
+-----END CERTIFICATE-----
ad145f
diff --git a/tests/data/tls/ca/private/testsuiteCA.key b/tests/data/tls/ca/private/testsuiteCA.key
ad145f
new file mode 100644
ad145f
index 000000000..2e14d7033
ad145f
--- /dev/null
ad145f
+++ b/tests/data/tls/ca/private/testsuiteCA.key
ad145f
@@ -0,0 +1,16 @@
ad145f
+-----BEGIN PRIVATE KEY-----
ad145f
+MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBALfFwx2u8Q/EjNnQ
ad145f
+WcZV+Tqwtdb//hRsFmaawdI1PtQM2kvfTVCuw5oBPKI4xI8fGZCgs9uVg61MI9oc
ad145f
+338ogegKcRDq0lF7fSiQDQMWdm9IfmMCb0TZC+xcxVdTlciL11lM10vqPBFqM9A/
ad145f
+dh8r4/Ku0ipzQi+EHg6uLf2+sUulAgMBAAECgYBDOb7kjuh0Iix8SXFt0ml3hMkg
ad145f
+O0kQ43FWW2pnoT64h3MbqjY4O5YmMimiFi4hRPkvJPpma01eCapb0ZAYjhLm1bpf
ad145f
+7Ey+724CEN3/DnorbQ3b/Fe2AVl4msJKEQFoercnaS9tFDPoijzH/quC2agH41tn
ad145f
+rGWTpahq6JUIP6xkwQJBAPHJZVHGQ8P/5bGxqOkPLtjIfDLtAgInMxZgDjHhHw2f
ad145f
+wGoeRrZ3J1yW0tnWtTXBN+5fKjCd6QpEvBmwhiZ+S+0CQQDCk1JBq64UotqeSWnk
ad145f
+AmhRMyVs87P0DPW2Gg8y96Q3d5Rwmy65ITr4pf/xufcSkrTSObDLhfhRyJKz7W4l
ad145f
+vjeZAkBq99CtZuugENxLyu+RfDgbjEb2OMjErxb49TISeyhD3MNBr3dVTk3Jtqg9
ad145f
+27F7wKm/+bYuoA3zjwkwzFntOb7ZAkAY0Hz/DwwGabaD1U0B3SS8pk8xk+rxRu3X
ad145f
+KX+iul5hDIkLy16sEYbZyyHXDCZsYfVZki3v5sgCdhfvhmozugyRAkBQgCeI8K1N
ad145f
+I9rHrcMZUjVT/3AdjSu6xIM87Vv/oIzGUNaadnQONRaXZ+Kp5pv9j4B/18rPcQwL
ad145f
++b2qljWeZbGH
ad145f
+-----END PRIVATE KEY-----
ad145f
diff --git a/tests/data/tls/certs/bjensen@mailgw.example.com.crt b/tests/data/tls/certs/bjensen@mailgw.example.com.crt
ad145f
new file mode 100644
ad145f
index 000000000..93e3a0d39
ad145f
--- /dev/null
ad145f
+++ b/tests/data/tls/certs/bjensen@mailgw.example.com.crt
ad145f
@@ -0,0 +1,16 @@
ad145f
+-----BEGIN CERTIFICATE-----
ad145f
+MIICejCCAeOgAwIBAgIBADANBgkqhkiG9w0BAQsFADBZMQswCQYDVQQGEwJVUzEL
ad145f
+MAkGA1UECAwCQ0ExHDAaBgNVBAoME09wZW5MREFQIEZvdW5kYXRpb24xHzAdBgNV
ad145f
+BAsMFk9wZW5MREFQIFRlc3QgU3VpdGUgQ0EwIBcNMTcwNTEwMjMxNjExWhgPMjUx
ad145f
+ODA1MjQyMzE2MTFaMIGbMQswCQYDVQQGEwJVUzELMAkGA1UECAwCQ0ExHDAaBgNV
ad145f
+BAoME09wZW5MREFQIEZvdW5kYXRpb24xETAPBgNVBAsMCE9wZW5MREFQMSMwIQYD
ad145f
+VQQDDBpiamVuc2VuQG1haWxndy5leGFtcGxlLmNvbTEpMCcGCSqGSIb3DQEJARYa
ad145f
+YmplbnNlbkBtYWlsZ3cuZXhhbXBsZS5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0A
ad145f
+MIGJAoGBAMjb2C5VL+f/B/f2xJyhsdXeaGhWdABWqJlCiupk7QVPotpZphqJ2fKg
ad145f
+QbX2w0sPazujt8hG96F2mBv49pHqzhSrKN70EA/E7b8d6ynjJpBU2P9ZgVlttnmU
ad145f
+U++22BSuhthP5VQK7IqNyI7ZyQ4hFzuqb/XrHD1VCDo/Z/JAkw7jAgMBAAGjDTAL
ad145f
+MAkGA1UdEwQCMAAwDQYJKoZIhvcNAQELBQADgYEAmAQhIIKqjC13rtAGEQHV/pKn
ad145f
+wOnLbNOumODqM+0MkEfqXXtR6eNGres2RNAtCJ5fqqDBTQCTqRzIt67cqdlJle2f
ad145f
+7vXYm8Y6NgxHwG+N1y7S0Xf+oo7/BJ+YJTLF7CLJuPNRqILWvXGlcNDcM1nekeKo
ad145f
+4DnnYQBDnq48VORVX94=
ad145f
+-----END CERTIFICATE-----
ad145f
diff --git a/tests/data/tls/certs/localhost.crt b/tests/data/tls/certs/localhost.crt
ad145f
new file mode 100644
ad145f
index 000000000..194cb119d
ad145f
--- /dev/null
ad145f
+++ b/tests/data/tls/certs/localhost.crt
ad145f
@@ -0,0 +1,16 @@
ad145f
+-----BEGIN CERTIFICATE-----
ad145f
+MIICgzCCAeygAwIBAgIBADANBgkqhkiG9w0BAQsFADBZMQswCQYDVQQGEwJVUzEL
ad145f
+MAkGA1UECAwCQ0ExHDAaBgNVBAoME09wZW5MREFQIEZvdW5kYXRpb24xHzAdBgNV
ad145f
+BAsMFk9wZW5MREFQIFRlc3QgU3VpdGUgQ0EwIBcNMTcwNTEwMjMxNjExWhgPMjUx
ad145f
+ODA1MjQyMzE2MTFaMGoxCzAJBgNVBAYTAlVTMQswCQYDVQQIDAJDQTEcMBoGA1UE
ad145f
+CgwTT3BlbkxEQVAgRm91bmRhdGlvbjEcMBoGA1UECwwTT3BlbkxEQVAgVGVzdCBT
ad145f
+dWl0ZTESMBAGA1UEAwwJbG9jYWxob3N0MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCB
ad145f
+iQKBgQDutp3GaZXGSm7joDm1TYI+dhBAuL1+O+oJlmZL10GX/oHqc8WNobvuZGH4
ad145f
+7H8mQf7zWwJQWxL805oBDMPi2ncgha5ydaVsf4rBZATpweji04vd+672qtR/dGgv
ad145f
+8Re5G3ZFYWxUv8nb/DJojG601V2Ye/K3rf+Xwa9u4Q9EJqIivwIDAQABo0gwRjAJ
ad145f
+BgNVHRMEAjAAMAsGA1UdDwQEAwIF4DAsBgNVHREEJTAjgglsb2NhbGhvc3SHBH8A
ad145f
+AAGHEAAAAAAAAAAAAAAAAAAAAAEwDQYJKoZIhvcNAQELBQADgYEAYItH9TDh/lqG
ad145f
+8XcBPi0bzGaUPkGlDY615xvsVCflnsfRqLKP/dCfi1GjaDajEmE874pvnmmZfwxl
ad145f
+0MRTqnhEmFdqjPzVSVKCeNQYWGr3wzKwI7qrhTLMg3Tz98Sz0+HUY8G9fwsNekAR
ad145f
+GjeZB1FxqDGHjxBq2O828iejw28bSz4=
ad145f
+-----END CERTIFICATE-----
ad145f
diff --git a/tests/data/tls/conf/openssl.cnf b/tests/data/tls/conf/openssl.cnf
ad145f
new file mode 100644
ad145f
index 000000000..a3c8ad9f6
ad145f
--- /dev/null
ad145f
+++ b/tests/data/tls/conf/openssl.cnf
ad145f
@@ -0,0 +1,129 @@
ad145f
+HOME                    = .
ad145f
+RANDFILE                = $ENV::HOME/.rnd
ad145f
+
ad145f
+oid_section             = new_oids
ad145f
+
ad145f
+[ new_oids ]
ad145f
+tsa_policy1 = 1.2.3.4.1
ad145f
+tsa_policy2 = 1.2.3.4.5.6
ad145f
+tsa_policy3 = 1.2.3.4.5.7
ad145f
+
ad145f
+[ ca ]
ad145f
+default_ca      = CA_default            # The default ca section
ad145f
+
ad145f
+[ CA_default ]
ad145f
+
ad145f
+dir             = ./cruft		# Where everything is kept
ad145f
+certs           = $dir/certs            # Where the issued certs are kept
ad145f
+crl_dir         = $dir/crl              # Where the issued crl are kept
ad145f
+database        = $dir/index.txt        # database index file.
ad145f
+new_certs_dir   = $dir/certs         # default place for new certs.
ad145f
+certificate     = $dir/cacert.pem       # The CA certificate
ad145f
+serial          = $dir/serial           # The current serial number
ad145f
+crlnumber       = $dir/crlnumber        # the current crl number
ad145f
+crl             = $dir/crl.pem          # The current CRL
ad145f
+private_key     = $dir/private/cakey.pem# The private key
ad145f
+RANDFILE        = $dir/private/.rand    # private random number file
ad145f
+x509_extensions = usr_cert              # The extentions to add to the cert
ad145f
+name_opt        = ca_default            # Subject Name options
ad145f
+cert_opt        = ca_default            # Certificate field options
ad145f
+default_days    = 365                   # how long to certify for
ad145f
+default_crl_days= 30                    # how long before next CRL
ad145f
+default_md      = default               # use public key default MD
ad145f
+preserve        = no                    # keep passed DN ordering
ad145f
+policy          = policy_match
ad145f
+
ad145f
+[ policy_match ]
ad145f
+countryName             = match
ad145f
+stateOrProvinceName     = match
ad145f
+organizationName        = match
ad145f
+organizationalUnitName  = optional
ad145f
+commonName              = supplied
ad145f
+emailAddress            = optional
ad145f
+
ad145f
+[ policy_anything ]
ad145f
+countryName             = optional
ad145f
+stateOrProvinceName     = optional
ad145f
+localityName            = optional
ad145f
+organizationName        = optional
ad145f
+organizationalUnitName  = optional
ad145f
+commonName              = supplied
ad145f
+emailAddress            = optional
ad145f
+
ad145f
+[ req ]
ad145f
+default_bits            = 2048
ad145f
+default_keyfile         = privkey.pem
ad145f
+distinguished_name      = req_distinguished_name
ad145f
+attributes              = req_attributes
ad145f
+x509_extensions = v3_ca # The extentions to add to the self signed cert
ad145f
+
ad145f
+string_mask = utf8only
ad145f
+
ad145f
+[ req_distinguished_name ]
ad145f
+basicConstraints=CA:FALSE
ad145f
+
ad145f
+[ req_attributes ]
ad145f
+challengePassword               = A challenge password
ad145f
+challengePassword_min           = 4
ad145f
+challengePassword_max           = 20
ad145f
+
ad145f
+unstructuredName                = An optional company name
ad145f
+
ad145f
+[ usr_cert ]
ad145f
+
ad145f
+basicConstraints=CA:FALSE
ad145f
+nsComment                       = "OpenSSL Generated Certificate"
ad145f
+
ad145f
+subjectKeyIdentifier=hash
ad145f
+authorityKeyIdentifier=keyid,issuer
ad145f
+
ad145f
+[ v3_req ]
ad145f
+
ad145f
+basicConstraints = CA:FALSE
ad145f
+keyUsage = nonRepudiation, digitalSignature, keyEncipherment
ad145f
+subjectAltName = DNS:localhost,IP:127.0.0.1,IP:::1
ad145f
+
ad145f
+[ v3_ca ]
ad145f
+subjectKeyIdentifier=hash
ad145f
+authorityKeyIdentifier=keyid:always,issuer
ad145f
+basicConstraints = CA:true
ad145f
+
ad145f
+[ crl_ext ]
ad145f
+
ad145f
+authorityKeyIdentifier=keyid:always
ad145f
+
ad145f
+[ proxy_cert_ext ]
ad145f
+basicConstraints=CA:FALSE
ad145f
+nsComment                       = "OpenSSL Generated Certificate"
ad145f
+
ad145f
+subjectKeyIdentifier=hash
ad145f
+authorityKeyIdentifier=keyid,issuer
ad145f
+proxyCertInfo=critical,language:id-ppl-anyLanguage,pathlen:3,policy:foo
ad145f
+
ad145f
+[ tsa ]
ad145f
+
ad145f
+default_tsa = tsa_config1       # the default TSA section
ad145f
+
ad145f
+[ tsa_config1 ]
ad145f
+
ad145f
+dir             = ./demoCA              # TSA root directory
ad145f
+serial          = $dir/tsaserial        # The current serial number (mandatory)
ad145f
+crypto_device   = builtin               # OpenSSL engine to use for signing
ad145f
+signer_cert     = $dir/tsacert.pem      # The TSA signing certificate
ad145f
+                                        # (optional)
ad145f
+certs           = $dir/cacert.pem       # Certificate chain to include in reply
ad145f
+                                        # (optional)
ad145f
+signer_key      = $dir/private/tsakey.pem # The TSA private key (optional)
ad145f
+
ad145f
+default_policy  = tsa_policy1           # Policy if request did not specify it
ad145f
+                                        # (optional)
ad145f
+other_policies  = tsa_policy2, tsa_policy3      # acceptable policies (optional)
ad145f
+digests         = md5, sha1             # Acceptable message digests (mandatory)
ad145f
+accuracy        = secs:1, millisecs:500, microsecs:100  # (optional)
ad145f
+clock_precision_digits  = 0     # number of digits after dot. (optional)
ad145f
+ordering                = yes   # Is ordering defined for timestamps?
ad145f
+                                # (optional, default: no)
ad145f
+tsa_name                = yes   # Must the TSA name be included in the reply?
ad145f
+                                # (optional, default: no)
ad145f
+ess_cert_id_chain       = no    # Must the ESS cert id chain be included?
ad145f
+                                # (optional, default: no)
ad145f
diff --git a/tests/data/tls/create-crt.sh b/tests/data/tls/create-crt.sh
ad145f
new file mode 100755
ad145f
index 000000000..8c33a24fe
ad145f
--- /dev/null
ad145f
+++ b/tests/data/tls/create-crt.sh
ad145f
@@ -0,0 +1,78 @@
ad145f
+#!/bin/sh
ad145f
+openssl=$(which openssl)
ad145f
+
ad145f
+if [ x"$openssl" = "x" ]; then
ad145f
+echo "OpenSSL command line binary not found, skipping..."
ad145f
+fi
ad145f
+
ad145f
+USAGE="$0 [-s] [-u <user@domain.com>]"
ad145f
+SERVER=0
ad145f
+USER=0
ad145f
+EMAIL=
ad145f
+
ad145f
+while test $# -gt 0 ; do
ad145f
+	case "$1" in
ad145f
+		-s | -server)
ad145f
+			SERVER=1;
ad145f
+			shift;;
ad145f
+		-u | -user)
ad145f
+			if [ x"$2" = "x" ]; then
ad145f
+				echo "User cert requires an email address as an argument"
ad145f
+				exit;
ad145f
+			fi
ad145f
+			USER=1;
ad145f
+			EMAIL="$2";
ad145f
+			shift; shift;;
ad145f
+		-)
ad145f
+			shift;;
ad145f
+		-*)
ad145f
+			echo "$USAGE"; exit 1
ad145f
+			;;
ad145f
+		*)
ad145f
+			break;;
ad145f
+	esac
ad145f
+done
ad145f
+
ad145f
+if [ $SERVER = 0 -a $USER = 0 ]; then
ad145f
+	echo "$USAGE";
ad145f
+	exit 1;
ad145f
+fi
ad145f
+
ad145f
+rm -rf ./openssl.cnf cruft
ad145f
+mkdir -p private certs cruft/private cruft/certs
ad145f
+
ad145f
+echo "00" > cruft/serial
ad145f
+touch cruft/index.txt
ad145f
+touch cruft/index.txt.attr
ad145f
+hn=$(hostname -f)
ad145f
+sed -e "s;@HOSTNAME@;$hn;" conf/openssl.cnf >  ./openssl.cnf
ad145f
+
ad145f
+if [ $SERVER = 1 ]; then
ad145f
+	rm -rf private/localhost.key certs/localhost.crt
ad145f
+
ad145f
+	$openssl req -new -nodes -out localhost.csr -keyout private/localhost.key \
ad145f
+		-newkey rsa:1024 -config ./openssl.cnf \
ad145f
+		-subj "/CN=localhost/OU=OpenLDAP Test Suite/O=OpenLDAP Foundation/ST=CA/C=US" \
ad145f
+		-batch > /dev/null 2>&1
ad145f
+
ad145f
+	$openssl ca -out certs/localhost.crt -notext -config ./openssl.cnf -days 183000 -in localhost.csr \
ad145f
+		-keyfile ca/private/testsuiteCA.key -extensions v3_req -cert ca/certs/testsuiteCA.crt \
ad145f
+		-batch >/dev/null 2>&1
ad145f
+
ad145f
+	rm -rf ./openssl.cnf ./localhost.csr cruft
ad145f
+fi
ad145f
+
ad145f
+if [ $USER = 1 ]; then
ad145f
+	rm -f certs/$EMAIL.crt private/$EMAIL.key $EMAIL.csr
ad145f
+
ad145f
+	$openssl req -new -nodes -out $EMAIL.csr -keyout private/$EMAIL.key \
ad145f
+		-newkey rsa:1024 -config ./openssl.cnf \
ad145f
+		-subj "/emailAddress=$EMAIL/CN=$EMAIL/OU=OpenLDAP/O=OpenLDAP Foundation/ST=CA/C=US" \
ad145f
+		-batch >/dev/null 2>&1
ad145f
+
ad145f
+	$openssl ca -out certs/$EMAIL.crt -notext -config ./openssl.cnf -days 183000 -in $EMAIL.csr \
ad145f
+		-keyfile ca/private/testsuiteCA.key -extensions req_distinguished_name \
ad145f
+		-cert ca/certs/testsuiteCA.crt -batch >/dev/null 2>&1
ad145f
+
ad145f
+	rm -rf ./openssl.cnf ./$EMAIL.csr cruft
ad145f
+fi
ad145f
diff --git a/tests/data/tls/private/bjensen@mailgw.example.com.key b/tests/data/tls/private/bjensen@mailgw.example.com.key
ad145f
new file mode 100644
ad145f
index 000000000..5f4625fd7
ad145f
--- /dev/null
ad145f
+++ b/tests/data/tls/private/bjensen@mailgw.example.com.key
ad145f
@@ -0,0 +1,16 @@
ad145f
+-----BEGIN PRIVATE KEY-----
ad145f
+MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAMjb2C5VL+f/B/f2
ad145f
+xJyhsdXeaGhWdABWqJlCiupk7QVPotpZphqJ2fKgQbX2w0sPazujt8hG96F2mBv4
ad145f
+9pHqzhSrKN70EA/E7b8d6ynjJpBU2P9ZgVlttnmUU++22BSuhthP5VQK7IqNyI7Z
ad145f
+yQ4hFzuqb/XrHD1VCDo/Z/JAkw7jAgMBAAECgYEApDgKQadoaZd7nmJlUWJqEV+r
ad145f
+oVK9uOEhK1zaUtV9bBA2J6uQQLZgORyJXQqJlT7f/3zVb6uGHr7lkkk03wxIu+3e
ad145f
+nIi7or/Cw6KmxhgslsQamf/ujjeqRlij/4pJIpEYByme9SstfzMBFNWU4t+fguPg
ad145f
+xXz6lvVZuNiYRWWuXxECQQDwakp31mNczqLPg8fuhdgixz7HCK5g6p4XDw+Cu9Ra
ad145f
+EenuOJVlnwXdW+g5jooiV5RWhxbTO6ImtgbcBGoeLSbVAkEA1eEcifIzgSi8XODd
ad145f
+9i6dCSMHKk4FgDRk2DJxRePLK2J1kt2bhOz/N1130fTargDWo8QiQAnd7RBOMJO/
ad145f
+pGaq1wJAZ2afzrjzlWf+WFgqdmk0k4i0dHBEZ8Sg5/P/TNAyPeb0gRPvFXz2zcUI
ad145f
+tTCcMrcOQsTpSUKdtB6YBqsTZRUwXQI/FbjHLTtr/7Ijb0tnP5l8WXE1SRajeGHZ
ad145f
+3BtDZdW8zKszRbc8FEP9p6HWiXxUuVdcdUV2NQrLf0goqMZYsFm9AkBtV3URLS4D
ad145f
+tw0VPr/TtzDx0UTJU5POdRcNrrpm233A0EyGNmLuM7y0iLxrvCIN9z0RVu7AeMBg
ad145f
+36Ixj3L+5H18
ad145f
+-----END PRIVATE KEY-----
ad145f
diff --git a/tests/data/tls/private/localhost.key b/tests/data/tls/private/localhost.key
ad145f
new file mode 100644
ad145f
index 000000000..8a24f69f8
ad145f
--- /dev/null
ad145f
+++ b/tests/data/tls/private/localhost.key
ad145f
@@ -0,0 +1,16 @@
ad145f
+-----BEGIN PRIVATE KEY-----
ad145f
+MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAO62ncZplcZKbuOg
ad145f
+ObVNgj52EEC4vX476gmWZkvXQZf+gepzxY2hu+5kYfjsfyZB/vNbAlBbEvzTmgEM
ad145f
+w+LadyCFrnJ1pWx/isFkBOnB6OLTi937rvaq1H90aC/xF7kbdkVhbFS/ydv8MmiM
ad145f
+brTVXZh78ret/5fBr27hD0QmoiK/AgMBAAECgYEA0gs5tNY/BaWFASGA5bj3u4Ij
ad145f
+Nu/XPPX3Lsx54o3bl6RIKEYKNF91f4QweNmP39f+P596373jbTe7sOTMkBXu7qnf
ad145f
+2B51VBJ72Uq92gO2VXImK+uuC6JdZfYTlX1QJkaR6mxhBl3KAgUeGUgbL0Xp9XeJ
ad145f
+bVcPqDOpRyIlW/80EHECQQD6PWRkk+0H4EMRA3GAnMQv/+Cy+sqF0T0OBNsQ846q
ad145f
+1hQhJfVvjgj2flmJZpH9zBTaqDn4grJDfQ9cViZwf4k7AkEA9DVNHPNVpkeToWrf
ad145f
+3yH55Ya5WEAl/6oNsHlaSZ88SHCZGqY7hQrpjSycsEezmsnDeqfdVuO97G2nHC7U
ad145f
+VdPUTQJAAq8r54RKs53tOj5+NjH4TMeC4oicKYlQDVlx/CGQszZuqthcZKDyaap7
ad145f
+TWUDReStiJbrYEYOoXiy9HucF/LWRwJAQKeH9f06lN5oaJkKEmJFbg5ALew14z1b
ad145f
+iHhofgtpg2hEMLkIEw4zjUvdZBJnq7h1R5j/0cxT8S+KybxgPSTrFQJBAPTrj7bP
ad145f
+5M7tPyQtyFxhFhas6g4ZHz/D2yB7BL+hL3IiJf3fdWNcHTzBDFEgDOVjR/7CZ6L3
ad145f
+b61hkjQZfbEg5cg=
ad145f
+-----END PRIVATE KEY-----
ad145f
diff --git a/tests/run.in b/tests/run.in
ad145f
index 6c33d4d20..793e388c1 100644
ad145f
--- a/tests/run.in
ad145f
+++ b/tests/run.in
ad145f
@@ -57,6 +57,7 @@ AC_valsort=valsort@BUILD_VALSORT@
ad145f
 # misc
ad145f
 AC_WITH_SASL=@WITH_SASL@
ad145f
 AC_WITH_TLS=@WITH_TLS@
ad145f
+AC_TLS_TYPE=@WITH_TLS_TYPE@
ad145f
 AC_WITH_MODULES_ENABLED=@WITH_MODULES_ENABLED@
ad145f
 AC_ACI_ENABLED=aci@WITH_ACI_ENABLED@
ad145f
 AC_THREADS=threads@BUILD_THREAD@
ad145f
@@ -75,7 +76,7 @@ export AC_bdb AC_hdb AC_ldap AC_mdb AC_meta AC_monitor AC_null AC_relay AC_sql \
ad145f
 	AC_refint AC_retcode AC_rwm AC_unique AC_syncprov AC_translucent \
ad145f
 	AC_valsort \
ad145f
 	AC_WITH_SASL AC_WITH_TLS AC_WITH_MODULES_ENABLED AC_ACI_ENABLED \
ad145f
-	AC_THREADS AC_LIBS_DYNAMIC
ad145f
+	AC_THREADS AC_LIBS_DYNAMIC AC_WITH_TLS AC_TLS_TYPE
ad145f
 
ad145f
 if test ! -x ../servers/slapd/slapd ; then
ad145f
 	echo "Could not locate slapd(8)"
ad145f
diff --git a/tests/scripts/defines.sh b/tests/scripts/defines.sh
ad145f
index a7dacebdd..2c9e8f76a 100755
ad145f
--- a/tests/scripts/defines.sh
ad145f
+++ b/tests/scripts/defines.sh
ad145f
@@ -46,6 +46,9 @@ VALSORT=${AC_valsort-valsortno}
ad145f
 # misc
ad145f
 WITH_SASL=${AC_WITH_SASL-no}
ad145f
 USE_SASL=${SLAPD_USE_SASL-no}
ad145f
+WITH_TLS=${AC_WITH_TLS-no}
ad145f
+WITH_TLS_TYPE=${AC_TLS_TYPE-no}
ad145f
+
ad145f
 ACI=${AC_ACI_ENABLED-acino}
ad145f
 THREADS=${AC_THREADS-threadsno}
ad145f
 SLEEP0=${SLEEP0-1}
ad145f
@@ -104,6 +107,8 @@ P2SRSLAVECONF=$DATADIR/slapd-syncrepl-slave-persist2.conf
ad145f
 P3SRSLAVECONF=$DATADIR/slapd-syncrepl-slave-persist3.conf
ad145f
 REFSLAVECONF=$DATADIR/slapd-ref-slave.conf
ad145f
 SCHEMACONF=$DATADIR/slapd-schema.conf
ad145f
+TLSCONF=$DATADIR/slapd-tls.conf
ad145f
+TLSSASLCONF=$DATADIR/slapd-tls-sasl.conf
ad145f
 GLUECONF=$DATADIR/slapd-glue.conf
ad145f
 REFINTCONF=$DATADIR/slapd-refint.conf
ad145f
 RETCODECONF=$DATADIR/slapd-retcode.conf
ad145f
@@ -164,6 +169,7 @@ SLURPLOG=$TESTDIR/slurp.log
ad145f
 CONFIGPWF=$TESTDIR/configpw
ad145f
 
ad145f
 # args
ad145f
+SASLARGS="-Q"
ad145f
 TOOLARGS="-x $LDAP_TOOLARGS"
ad145f
 TOOLPROTO="-P 3"
ad145f
 
ad145f
@@ -186,7 +192,8 @@ BCMP="diff -iB"
ad145f
 CMPOUT=/dev/null
ad145f
 SLAPD="$TESTWD/../servers/slapd/slapd -s0"
ad145f
 LDAPPASSWD="$CLIENTDIR/ldappasswd $TOOLARGS"
ad145f
-LDAPSASLSEARCH="$CLIENTDIR/ldapsearch $TOOLPROTO $LDAP_TOOLARGS -LLL"
ad145f
+LDAPSASLSEARCH="$CLIENTDIR/ldapsearch $SASLARGS $TOOLPROTO $LDAP_TOOLARGS -LLL"
ad145f
+LDAPSASLWHOAMI="$CLIENTDIR/ldapwhoami $SASLARGS $LDAP_TOOLARGS"
ad145f
 LDAPSEARCH="$CLIENTDIR/ldapsearch $TOOLPROTO $TOOLARGS -LLL"
ad145f
 LDAPRSEARCH="$CLIENTDIR/ldapsearch $TOOLPROTO $TOOLARGS"
ad145f
 LDAPDELETE="$CLIENTDIR/ldapdelete $TOOLPROTO $TOOLARGS"
ad145f
@@ -201,6 +208,7 @@ LDIFFILTER=$PROGDIR/ldif-filter
ad145f
 SLAPDMTREAD=$PROGDIR/slapd-mtread
ad145f
 LVL=${SLAPD_DEBUG-0x4105}
ad145f
 LOCALHOST=localhost
ad145f
+LOCALIP=127.0.0.1
ad145f
 BASEPORT=${SLAPD_BASEPORT-9010}
ad145f
 PORT1=`expr $BASEPORT + 1`
ad145f
 PORT2=`expr $BASEPORT + 2`
ad145f
@@ -209,11 +217,22 @@ PORT4=`expr $BASEPORT + 4`
ad145f
 PORT5=`expr $BASEPORT + 5`
ad145f
 PORT6=`expr $BASEPORT + 6`
ad145f
 URI1="ldap://${LOCALHOST}:$PORT1/"
ad145f
+URIP1="ldap://${LOCALIP}:$PORT1/"
ad145f
 URI2="ldap://${LOCALHOST}:$PORT2/"
ad145f
+URIP2="ldap://${LOCALIP}:$PORT2/"
ad145f
 URI3="ldap://${LOCALHOST}:$PORT3/"
ad145f
+URIP3="ldap://${LOCALIP}:$PORT3/"
ad145f
 URI4="ldap://${LOCALHOST}:$PORT4/"
ad145f
 URI5="ldap://${LOCALHOST}:$PORT5/"
ad145f
 URI6="ldap://${LOCALHOST}:$PORT6/"
ad145f
+SURI1="ldaps://${LOCALHOST}:$PORT1/"
ad145f
+SURIP1="ldaps://${LOCALIP}:$PORT1/"
ad145f
+SURI2="ldaps://${LOCALHOST}:$PORT2/"
ad145f
+SURIP2="ldaps://${LOCALIP}:$PORT2/"
ad145f
+SURI3="ldaps://${LOCALHOST}:$PORT3/"
ad145f
+SURI4="ldaps://${LOCALHOST}:$PORT4/"
ad145f
+SURI5="ldaps://${LOCALHOST}:$PORT5/"
ad145f
+SURI6="ldaps://${LOCALHOST}:$PORT6/"
ad145f
 
ad145f
 # LDIF
ad145f
 LDIF=$DATADIR/test.ldif
ad145f
diff --git a/tests/scripts/test067-tls b/tests/scripts/test067-tls
ad145f
new file mode 100755
ad145f
index 000000000..2b245f5f5
ad145f
--- /dev/null
ad145f
+++ b/tests/scripts/test067-tls
ad145f
@@ -0,0 +1,140 @@
ad145f
+#! /bin/sh
ad145f
+# $OpenLDAP$
ad145f
+## This work is part of OpenLDAP Software <http://www.openldap.org/>.
ad145f
+##
ad145f
+## Copyright 1998-2017 The OpenLDAP Foundation.
ad145f
+## All rights reserved.
ad145f
+##
ad145f
+## Redistribution and use in source and binary forms, with or without
ad145f
+## modification, are permitted only as authorized by the OpenLDAP
ad145f
+## Public License.
ad145f
+##
ad145f
+## A copy of this license is available in the file LICENSE in the
ad145f
+## top-level directory of the distribution or, alternatively, at
ad145f
+## <http://www.OpenLDAP.org/license.html>.
ad145f
+
ad145f
+echo "running defines.sh"
ad145f
+. $SRCDIR/scripts/defines.sh
ad145f
+
ad145f
+if test $WITH_TLS = no ; then
ad145f
+        echo "TLS support not available, test skipped"
ad145f
+        exit 0
ad145f
+fi
ad145f
+
ad145f
+mkdir -p $TESTDIR $DBDIR1
ad145f
+cp -r $DATADIR/tls $TESTDIR
ad145f
+
ad145f
+cd $TESTWD
ad145f
+
ad145f
+echo "Starting ldap:/// slapd on TCP/IP port $PORT1 and ldaps:/// slapd on $PORT2..."
ad145f
+. $CONFFILTER $BACKEND $MONITORDB < $TLSCONF > $CONF1
ad145f
+$SLAPD -f $CONF1 -h "$URI1 $SURI2" -d $LVL $TIMING > $LOG1 2>&1 &
ad145f
+PID=$!
ad145f
+if test $WAIT != 0 ; then
ad145f
+    echo PID $PID
ad145f
+    read foo
ad145f
+fi
ad145f
+KILLPIDS="$PID"
ad145f
+
ad145f
+sleep 1
ad145f
+
ad145f
+for i in 0 1 2 3 4 5; do
ad145f
+	$LDAPSEARCH -s base -b "" -H $URI1 \
ad145f
+		'objectclass=*' > /dev/null 2>&1
ad145f
+        RC=$?
ad145f
+        if test $RC = 0 ; then
ad145f
+                break
ad145f
+        fi
ad145f
+        echo "Waiting 5 seconds for slapd to start..."
ad145f
+        sleep 5
ad145f
+done
ad145f
+
ad145f
+if test $RC != 0 ; then
ad145f
+	echo "ldapsearch failed ($RC)!"
ad145f
+	test $KILLSERVERS != no && kill -HUP $KILLPIDS
ad145f
+	exit $RC
ad145f
+fi
ad145f
+
ad145f
+echo -n "Using ldapsearch with startTLS with no server cert validation...."
ad145f
+$LDAPSEARCH -o tls_reqcert=never -ZZ -b "" -s base -H $URIP1 \
ad145f
+	'@extensibleObject' > $SEARCHOUT 2>&1
ad145f
+RC=$?
ad145f
+if test $RC != 0 ; then
ad145f
+	echo "ldapsearch (startTLS) failed ($RC)!"
ad145f
+	exit $RC
ad145f
+else
ad145f
+	echo "success"
ad145f
+fi
ad145f
+
ad145f
+echo -n "Using ldapsearch with startTLS with hard require cert...."
ad145f
+$LDAPSEARCH -o tls_cacert=$TESTDIR/tls/ca/certs/testsuiteCA.crt -o tls_reqcert=hard -ZZ -b "" -s base -H $URIP1 \
ad145f
+	'@extensibleObject' > $SEARCHOUT 2>&1
ad145f
+RC=$?
ad145f
+if test $RC != 0 ; then
ad145f
+	echo "ldapsearch (startTLS) failed ($RC)!"
ad145f
+	exit $RC
ad145f
+else
ad145f
+	echo "success"
ad145f
+fi
ad145f
+
ad145f
+if test $WITH_TLS_TYPE = openssl ; then
ad145f
+	echo -n "Using ldapsearch with startTLS and specific protocol version...."
ad145f
+	$LDAPSEARCH -o tls_cacert=$TESTDIR/tls/ca/certs/testsuiteCA.crt -o tls_reqcert=hard -o tls_protocol_min=3.3 -ZZ -b "" -s base -H $URIP1 \
ad145f
+		'@extensibleObject' > $SEARCHOUT 2>&1
ad145f
+	RC=$?
ad145f
+	if test $RC != 0 ; then
ad145f
+		echo "ldapsearch (protocol-min) failed ($RC)!"
ad145f
+		exit $RC
ad145f
+	else
ad145f
+		echo "success"
ad145f
+	fi
ad145f
+fi
ad145f
+
ad145f
+echo -n "Using ldapsearch on $SURI2 with no server cert validation..."
ad145f
+$LDAPSEARCH -o tls_reqcert=never -b "cn=Subschema" -s base -H $SURIP2 \
ad145f
+	'(&(objectClasses=top)(objectClasses=2.5.6.0))' cn objectClass \
ad145f
+	>> $SEARCHOUT  2>&1
ad145f
+RC=$?
ad145f
+if test $RC != 0 ; then
ad145f
+	echo "ldapsearch (ldaps) failed($RC)!"
ad145f
+	exit $RC
ad145f
+else
ad145f
+	echo "success"
ad145f
+fi
ad145f
+
ad145f
+echo -n "Using ldapsearch on $SURI2 with reqcert HARD and no CA cert.  Should fail..."
ad145f
+$LDAPSEARCH -o tls_reqcert=hard -b "cn=Subschema" -s base -H $SURIP2 \
ad145f
+	'(&(objectClasses=top)(objectClasses=2.5.6.0))' cn objectClass \
ad145f
+	>> $SEARCHOUT  2>&1
ad145f
+RC=$?
ad145f
+if test $RC = 0 ; then
ad145f
+	echo "ldapsearch (ldaps) succeeded when it should have failed($RC)!"
ad145f
+	exit 1
ad145f
+else
ad145f
+	echo "failed correctly with error code ($RC)"
ad145f
+fi
ad145f
+
ad145f
+echo -n "Using ldapsearch on $SURI2 with CA cert and reqcert HARD..."
ad145f
+$LDAPSEARCH -o tls_cacert=$TESTDIR/tls/ca/certs/testsuiteCA.crt -o tls_reqcert=hard -b "cn=Subschema" -s base -H $SURIP2 \
ad145f
+	'(&(objectClasses=top)(objectClasses=2.5.6.0))' cn objectClass \
ad145f
+	>> $SEARCHOUT  2>&1
ad145f
+RC=$?
ad145f
+if test $RC != 0 ; then
ad145f
+	echo "ldapsearch (ldaps) failed ($RC)!"
ad145f
+	exit $RC
ad145f
+else
ad145f
+	echo "success"
ad145f
+fi
ad145f
+
ad145f
+test $KILLSERVERS != no && kill -HUP $KILLPIDS
ad145f
+
ad145f
+if test $RC != 0 ; then
ad145f
+	echo ">>>>> Test failed"
ad145f
+else
ad145f
+	echo ">>>>> Test succeeded"
ad145f
+	RC=0
ad145f
+fi
ad145f
+
ad145f
+test $KILLSERVERS != no && wait
ad145f
+
ad145f
+exit $RC
ad145f
diff --git a/tests/scripts/test068-sasl-tls-external b/tests/scripts/test068-sasl-tls-external
ad145f
new file mode 100755
ad145f
index 000000000..dcbc50fd4
ad145f
--- /dev/null
ad145f
+++ b/tests/scripts/test068-sasl-tls-external
ad145f
@@ -0,0 +1,102 @@
ad145f
+#! /bin/sh
ad145f
+# $OpenLDAP$
ad145f
+## This work is part of OpenLDAP Software <http://www.openldap.org/>.
ad145f
+##
ad145f
+## Copyright 1998-2017 The OpenLDAP Foundation.
ad145f
+## All rights reserved.
ad145f
+##
ad145f
+## Redistribution and use in source and binary forms, with or without
ad145f
+## modification, are permitted only as authorized by the OpenLDAP
ad145f
+## Public License.
ad145f
+##
ad145f
+## A copy of this license is available in the file LICENSE in the
ad145f
+## top-level directory of the distribution or, alternatively, at
ad145f
+## <http://www.OpenLDAP.org/license.html>.
ad145f
+
ad145f
+echo "running defines.sh"
ad145f
+. $SRCDIR/scripts/defines.sh
ad145f
+
ad145f
+if test $WITH_TLS = no ; then
ad145f
+        echo "TLS support not available, test skipped"
ad145f
+        exit 0
ad145f
+fi
ad145f
+
ad145f
+mkdir -p $TESTDIR $DBDIR1
ad145f
+cp -r $DATADIR/tls $TESTDIR
ad145f
+
ad145f
+cd $TESTWD
ad145f
+
ad145f
+echo "Running slapadd to build slapd database..."
ad145f
+. $CONFFILTER $BACKEND $MONITORDB < $TLSSASLCONF > $CONF1
ad145f
+$SLAPADD -f $CONF1 -l $LDIFORDERED
ad145f
+RC=$?
ad145f
+if test $RC != 0 ; then
ad145f
+        echo "slapadd failed ($RC)!"
ad145f
+        exit $RC
ad145f
+fi
ad145f
+
ad145f
+echo "Starting ldap:/// slapd on TCP/IP port $PORT1 and ldaps:/// slapd on $PORT2..."
ad145f
+$SLAPD -f $CONF1 -h "$URI1 $SURI2" -d $LVL $TIMING > $LOG1 2>&1 &
ad145f
+PID=$!
ad145f
+if test $WAIT != 0 ; then
ad145f
+    echo PID $PID
ad145f
+    read foo
ad145f
+fi
ad145f
+KILLPIDS="$PID"
ad145f
+
ad145f
+sleep 1
ad145f
+
ad145f
+for i in 0 1 2 3 4 5; do
ad145f
+	$LDAPSEARCH -s base -b "" -H $URI1 \
ad145f
+		'objectclass=*' > /dev/null 2>&1
ad145f
+        RC=$?
ad145f
+        if test $RC = 0 ; then
ad145f
+                break
ad145f
+        fi
ad145f
+        echo "Waiting 5 seconds for slapd to start..."
ad145f
+        sleep 5
ad145f
+done
ad145f
+
ad145f
+if test $RC != 0 ; then
ad145f
+	echo "ldapsearch failed ($RC)!"
ad145f
+	test $KILLSERVERS != no && kill -HUP $KILLPIDS
ad145f
+	exit $RC
ad145f
+fi
ad145f
+
ad145f
+echo -n "Using ldapwhoami with SASL/EXTERNAL...."
ad145f
+$LDAPSASLWHOAMI -o tls_cacert=$TESTDIR/tls/ca/certs/testsuiteCA.crt -o tls_reqcert=hard \
ad145f
+	-o tls_cert=$TESTDIR/tls/certs/bjensen@mailgw.example.com.crt -o tls_key=$TESTDIR/tls/private/bjensen@mailgw.example.com.key -ZZ -Y EXTERNAL -H $URIP1 \
ad145f
+	> $TESTOUT 2>&1
ad145f
+RC=$?
ad145f
+if test $RC != 0 ; then
ad145f
+	echo "ldapwhoami (startTLS) failed ($RC)!"
ad145f
+	exit $RC
ad145f
+else
ad145f
+	echo "success"
ad145f
+fi
ad145f
+
ad145f
+echo -n "Validating mapped SASL ID..."
ad145f
+echo 'dn:cn=barbara jensen,ou=information technology division,ou=people,dc=example,dc=com' > $TESTDIR/dn.out
ad145f
+$CMP $TESTDIR/dn.out $TESTOUT > $CMPOUT
ad145f
+
ad145f
+RC=$?
ad145f
+if test $RC != 0 ; then
ad145f
+	echo "Comparison failed"
ad145f
+	test $KILLSERVERS != no && kill -HUP $PID
ad145f
+	exit $RC
ad145f
+else
ad145f
+	echo "success"
ad145f
+fi
ad145f
+
ad145f
+test $KILLSERVERS != no && kill -HUP $KILLPIDS
ad145f
+
ad145f
+if test $RC != 0 ; then
ad145f
+	echo ">>>>> Test failed"
ad145f
+else
ad145f
+	echo ">>>>> Test succeeded"
ad145f
+	RC=0
ad145f
+fi
ad145f
+
ad145f
+test $KILLSERVERS != no && wait
ad145f
+
ad145f
+exit $RC
ad145f
diff --git a/tests/scripts/test069-delta-multimaster-starttls b/tests/scripts/test069-delta-multimaster-starttls
ad145f
new file mode 100755
ad145f
index 000000000..2dfbb30a1
ad145f
--- /dev/null
ad145f
+++ b/tests/scripts/test069-delta-multimaster-starttls
ad145f
@@ -0,0 +1,574 @@
ad145f
+#! /bin/sh
ad145f
+# $OpenLDAP$
ad145f
+## This work is part of OpenLDAP Software <http://www.openldap.org/>.
ad145f
+##
ad145f
+## Copyright 1998-2017 The OpenLDAP Foundation.
ad145f
+## All rights reserved.
ad145f
+##
ad145f
+## Redistribution and use in source and binary forms, with or without
ad145f
+## modification, are permitted only as authorized by the OpenLDAP
ad145f
+## Public License.
ad145f
+##
ad145f
+## A copy of this license is available in the file LICENSE in the
ad145f
+## top-level directory of the distribution or, alternatively, at
ad145f
+## <http://www.OpenLDAP.org/license.html>.
ad145f
+
ad145f
+echo "running defines.sh"
ad145f
+. $SRCDIR/scripts/defines.sh
ad145f
+
ad145f
+if test $WITH_TLS = no ; then
ad145f
+        echo "TLS support not available, test skipped"
ad145f
+        exit 0
ad145f
+fi
ad145f
+
ad145f
+if test $SYNCPROV = syncprovno; then
ad145f
+	echo "Syncrepl provider overlay not available, test skipped"
ad145f
+	exit 0
ad145f
+fi
ad145f
+if test $ACCESSLOG = accesslogno; then
ad145f
+	echo "Accesslog overlay not available, test skipped"
ad145f
+	exit 0
ad145f
+fi
ad145f
+
ad145f
+MMR=2
ad145f
+
ad145f
+XDIR=$TESTDIR/srv
ad145f
+TMP=$TESTDIR/tmp
ad145f
+
ad145f
+mkdir -p $TESTDIR
ad145f
+cp -r $DATADIR/tls $TESTDIR
ad145f
+
ad145f
+$SLAPPASSWD -g -n >$CONFIGPWF
ad145f
+
ad145f
+if test x"$SYNCMODE" = x ; then
ad145f
+	SYNCMODE=rp
ad145f
+fi
ad145f
+case "$SYNCMODE" in
ad145f
+	ro)
ad145f
+		SYNCTYPE="type=refreshOnly interval=00:00:00:03"
ad145f
+		;;
ad145f
+	rp)
ad145f
+		SYNCTYPE="type=refreshAndPersist interval=00:00:00:03"
ad145f
+		;;
ad145f
+	*)
ad145f
+		echo "unknown sync mode $SYNCMODE"
ad145f
+		exit 1;
ad145f
+		;;
ad145f
+esac
ad145f
+
ad145f
+#
ad145f
+# Test delta-sync mmr
ad145f
+# - start servers
ad145f
+# - configure over ldap
ad145f
+# - populate over ldap
ad145f
+# - configure syncrepl over ldap
ad145f
+# - break replication
ad145f
+# - modify each server separately
ad145f
+# - restore replication
ad145f
+# - compare results
ad145f
+#
ad145f
+
ad145f
+nullExclude=""
ad145f
+test $BACKEND = null && nullExclude="# "
ad145f
+
ad145f
+KILLPIDS=
ad145f
+
ad145f
+echo "Initializing server configurations..."
ad145f
+n=1
ad145f
+while [ $n -le $MMR ]; do
ad145f
+
ad145f
+DBDIR=${XDIR}$n/db
ad145f
+CFDIR=${XDIR}$n/slapd.d
ad145f
+
ad145f
+mkdir -p ${XDIR}$n $DBDIR.1 $DBDIR.2 $CFDIR
ad145f
+
ad145f
+o=`expr 3 - $n`
ad145f
+cat > $TMP <
ad145f
+dn: cn=config
ad145f
+objectClass: olcGlobal
ad145f
+cn: config
ad145f
+olcServerID: $n
ad145f
+olcTLSCertificateFile: $TESTDIR/tls/certs/localhost.crt
ad145f
+olcTLSCertificateKeyFile: $TESTDIR/tls/private/localhost.key
ad145f
+
ad145f
+EOF
ad145f
+
ad145f
+if [ "$SYNCPROV" = syncprovmod -o "$ACCESSLOG" = accesslogmod ]; then
ad145f
+  cat <<EOF >> $TMP
ad145f
+dn: cn=module,cn=config
ad145f
+objectClass: olcModuleList
ad145f
+cn: module
ad145f
+olcModulePath: $TESTWD/../servers/slapd/overlays
ad145f
+EOF
ad145f
+  if [ "$SYNCPROV" = syncprovmod ]; then
ad145f
+  echo "olcModuleLoad: syncprov.la" >> $TMP
ad145f
+  fi
ad145f
+  if [ "$ACCESSLOG" = accesslogmod ]; then
ad145f
+  echo "olcModuleLoad: accesslog.la" >> $TMP
ad145f
+  fi
ad145f
+  echo "" >> $TMP
ad145f
+fi
ad145f
+
ad145f
+if [ "$BACKENDTYPE" = mod ]; then
ad145f
+cat <<EOF >> $TMP
ad145f
+dn: cn=module,cn=config
ad145f
+objectClass: olcModuleList
ad145f
+cn: module
ad145f
+olcModulePath: $TESTWD/../servers/slapd/back-$BACKEND
ad145f
+olcModuleLoad: back_$BACKEND.la
ad145f
+
ad145f
+EOF
ad145f
+fi
ad145f
+MYURI=`eval echo '$URI'$n`
ad145f
+PROVIDERURI=`eval echo '$URIP'$o`
ad145f
+if test $INDEXDB = indexdb ; then
ad145f
+INDEX1="olcDbIndex: objectClass,entryCSN,reqStart,reqDN,reqResult eq"
ad145f
+INDEX2="olcDbIndex: objectClass,entryCSN,entryUUID eq"
ad145f
+else
ad145f
+INDEX1=
ad145f
+INDEX2=
ad145f
+fi
ad145f
+cat >> $TMP <
ad145f
+dn: cn=schema,cn=config
ad145f
+objectclass: olcSchemaconfig
ad145f
+cn: schema
ad145f
+
ad145f
+include: file://$ABS_SCHEMADIR/core.ldif
ad145f
+
ad145f
+include: file://$ABS_SCHEMADIR/cosine.ldif
ad145f
+
ad145f
+include: file://$ABS_SCHEMADIR/inetorgperson.ldif
ad145f
+
ad145f
+include: file://$ABS_SCHEMADIR/openldap.ldif
ad145f
+
ad145f
+include: file://$ABS_SCHEMADIR/nis.ldif
ad145f
+
ad145f
+dn: olcDatabase={0}config,cn=config
ad145f
+objectClass: olcDatabaseConfig
ad145f
+olcDatabase: {0}config
ad145f
+olcRootPW:< file://$CONFIGPWF
ad145f
+
ad145f
+dn: olcDatabase={1}$BACKEND,cn=config
ad145f
+objectClass: olcDatabaseConfig
ad145f
+${nullExclude}objectClass: olc${BACKEND}Config
ad145f
+olcDatabase: {1}$BACKEND
ad145f
+olcSuffix: cn=log
ad145f
+${nullExclude}olcDbDirectory: ${DBDIR}.1
ad145f
+olcRootDN: $MANAGERDN
ad145f
+$INDEX1
ad145f
+
ad145f
+dn: olcOverlay=syncprov,olcDatabase={1}$BACKEND,cn=config
ad145f
+objectClass: olcOverlayConfig
ad145f
+objectClass: olcSyncProvConfig
ad145f
+olcOverlay: syncprov
ad145f
+olcSpNoPresent: TRUE
ad145f
+olcSpReloadHint: TRUE
ad145f
+
ad145f
+dn: olcDatabase={2}$BACKEND,cn=config
ad145f
+objectClass: olcDatabaseConfig
ad145f
+${nullExclude}objectClass: olc${BACKEND}Config
ad145f
+olcDatabase: {2}$BACKEND
ad145f
+olcSuffix: $BASEDN
ad145f
+${nullExclude}olcDbDirectory: ${DBDIR}.2
ad145f
+olcRootDN: $MANAGERDN
ad145f
+olcRootPW: $PASSWD
ad145f
+olcSyncRepl: rid=001 provider=$PROVIDERURI binddn="$MANAGERDN" bindmethod=simple
ad145f
+  credentials=$PASSWD searchbase="$BASEDN" $SYNCTYPE
ad145f
+  retry="3 +" timeout=3 logbase="cn=log"
ad145f
+  logfilter="(&(objectclass=auditWriteObject)(reqresult=0))"
ad145f
+  syncdata=accesslog tls_cacert=$TESTDIR/tls/ca/certs/testsuiteCA.crt
ad145f
+  starttls=critical
ad145f
+olcMirrorMode: TRUE
ad145f
+$INDEX2
ad145f
+
ad145f
+dn: olcOverlay=syncprov,olcDatabase={2}$BACKEND,cn=config
ad145f
+objectClass: olcOverlayConfig
ad145f
+objectClass: olcSyncProvConfig
ad145f
+olcOverlay: syncprov
ad145f
+
ad145f
+dn: olcOverlay=accesslog,olcDatabase={2}$BACKEND,cn=config
ad145f
+objectClass: olcOverlayConfig
ad145f
+objectClass: olcAccessLogConfig
ad145f
+olcOverlay: accesslog
ad145f
+olcAccessLogDB: cn=log
ad145f
+olcAccessLogOps: writes
ad145f
+olcAccessLogSuccess: TRUE
ad145f
+
ad145f
+EOF
ad145f
+$SLAPADD -F $CFDIR -n 0  -d-1< $TMP > $TESTOUT 2>&1
ad145f
+PORT=`eval echo '$PORT'$n`
ad145f
+echo "Starting server $n on TCP/IP port $PORT..."
ad145f
+cd ${XDIR}${n}
ad145f
+LOG=`eval echo '$LOG'$n`
ad145f
+$SLAPD -F slapd.d -h $MYURI -d $LVL $TIMING > $LOG 2>&1 &
ad145f
+PID=$!
ad145f
+if test $WAIT != 0 ; then
ad145f
+    echo PID $PID
ad145f
+    read foo
ad145f
+fi
ad145f
+KILLPIDS="$PID $KILLPIDS"
ad145f
+cd $TESTWD
ad145f
+
ad145f
+echo "Using ldapsearch to check that server $n is running..."
ad145f
+for i in 0 1 2 3 4 5; do
ad145f
+	$LDAPSEARCH -s base -b "" -H $MYURI \
ad145f
+		'objectclass=*' > /dev/null 2>&1
ad145f
+	RC=$?
ad145f
+	if test $RC = 0 ; then
ad145f
+		break
ad145f
+	fi
ad145f
+	echo "Waiting 5 seconds for slapd to start..."
ad145f
+	sleep 5
ad145f
+done
ad145f
+
ad145f
+if test $RC != 0 ; then
ad145f
+	echo "ldapsearch failed ($RC)!"
ad145f
+	test $KILLSERVERS != no && kill -HUP $KILLPIDS
ad145f
+	exit $RC
ad145f
+fi
ad145f
+
ad145f
+if [ $n = 1 ]; then
ad145f
+echo "Using ldapadd for context on server 1..."
ad145f
+$LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFORDEREDCP \
ad145f
+	>> $TESTOUT 2>&1
ad145f
+RC=$?
ad145f
+if test $RC != 0 ; then
ad145f
+	echo "ldapadd failed for server $n database ($RC)!"
ad145f
+	test $KILLSERVERS != no && kill -HUP $KILLPIDS
ad145f
+	exit $RC
ad145f
+fi
ad145f
+fi
ad145f
+
ad145f
+n=`expr $n + 1`
ad145f
+done
ad145f
+
ad145f
+echo "Using ldapadd to populate server 1..."
ad145f
+$LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFORDEREDNOCP \
ad145f
+	>> $TESTOUT 2>&1
ad145f
+RC=$?
ad145f
+if test $RC != 0 ; then
ad145f
+	echo "ldapadd failed for server $n database ($RC)!"
ad145f
+	test $KILLSERVERS != no && kill -HUP $KILLPIDS
ad145f
+	exit $RC
ad145f
+fi
ad145f
+
ad145f
+echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
ad145f
+sleep $SLEEP1
ad145f
+
ad145f
+n=1
ad145f
+while [ $n -le $MMR ]; do
ad145f
+PORT=`expr $BASEPORT + $n`
ad145f
+URI="ldap://${LOCALHOST}:$PORT/"
ad145f
+
ad145f
+echo "Using ldapsearch to read all the entries from server $n..."
ad145f
+$LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD  \
ad145f
+	'objectclass=*' > $TESTDIR/server$n.out 2>&1
ad145f
+RC=$?
ad145f
+
ad145f
+if test $RC != 0 ; then
ad145f
+	echo "ldapsearch failed at server $n ($RC)!"
ad145f
+	test $KILLSERVERS != no && kill -HUP $KILLPIDS
ad145f
+	exit $RC
ad145f
+fi
ad145f
+$LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
ad145f
+n=`expr $n + 1`
ad145f
+done
ad145f
+
ad145f
+n=2
ad145f
+while [ $n -le $MMR ]; do
ad145f
+echo "Comparing retrieved entries from server 1 and server $n..."
ad145f
+$CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
ad145f
+
ad145f
+if test $? != 0 ; then
ad145f
+	echo "test failed - server 1 and server $n databases differ"
ad145f
+	test $KILLSERVERS != no && kill -HUP $KILLPIDS
ad145f
+	exit 1
ad145f
+fi
ad145f
+n=`expr $n + 1`
ad145f
+done
ad145f
+
ad145f
+echo "Using ldapadd to populate server 2..."
ad145f
+$LDAPADD -D "$MANAGERDN" -H $URI2 -w $PASSWD -f $LDIFADD1 \
ad145f
+	>> $TESTOUT 2>&1
ad145f
+RC=$?
ad145f
+if test $RC != 0 ; then
ad145f
+	echo "ldapadd failed for server 2 database ($RC)!"
ad145f
+	test $KILLSERVERS != no && kill -HUP $KILLPIDS
ad145f
+	exit $RC
ad145f
+fi
ad145f
+
ad145f
+THEDN="cn=James A Jones 2,ou=Alumni Association,ou=People,dc=example,dc=com"
ad145f
+sleep 1
ad145f
+for i in 1 2 3; do
ad145f
+	$LDAPSEARCH -S "" -b "$THEDN" -H $URI1 \
ad145f
+		-s base '(objectClass=*)' entryCSN > "${MASTEROUT}.$i" 2>&1
ad145f
+	RC=$?
ad145f
+
ad145f
+	if test $RC = 0 ; then
ad145f
+		break
ad145f
+	fi
ad145f
+
ad145f
+	if test $RC != 32 ; then
ad145f
+		echo "ldapsearch failed at slave ($RC)!"
ad145f
+		test $KILLSERVERS != no && kill -HUP $KILLPIDS
ad145f
+		exit $RC
ad145f
+	fi
ad145f
+
ad145f
+	echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
ad145f
+	sleep $SLEEP1
ad145f
+done
ad145f
+
ad145f
+n=1
ad145f
+while [ $n -le $MMR ]; do
ad145f
+PORT=`expr $BASEPORT + $n`
ad145f
+URI="ldap://${LOCALHOST}:$PORT/"
ad145f
+
ad145f
+echo "Using ldapsearch to read all the entries from server $n..."
ad145f
+$LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD  \
ad145f
+	'objectclass=*' > $TESTDIR/server$n.out 2>&1
ad145f
+RC=$?
ad145f
+
ad145f
+if test $RC != 0 ; then
ad145f
+	echo "ldapsearch failed at server $n ($RC)!"
ad145f
+	test $KILLSERVERS != no && kill -HUP $KILLPIDS
ad145f
+	exit $RC
ad145f
+fi
ad145f
+$LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
ad145f
+n=`expr $n + 1`
ad145f
+done
ad145f
+
ad145f
+n=2
ad145f
+while [ $n -le $MMR ]; do
ad145f
+echo "Comparing retrieved entries from server 1 and server $n..."
ad145f
+$CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
ad145f
+
ad145f
+if test $? != 0 ; then
ad145f
+	echo "test failed - server 1 and server $n databases differ"
ad145f
+	test $KILLSERVERS != no && kill -HUP $KILLPIDS
ad145f
+	exit 1
ad145f
+fi
ad145f
+n=`expr $n + 1`
ad145f
+done
ad145f
+
ad145f
+echo "Breaking replication between server 1 and 2..."
ad145f
+n=1
ad145f
+while [ $n -le $MMR ]; do
ad145f
+o=`expr 3 - $n`
ad145f
+MYURI=`eval echo '$URI'$n`
ad145f
+PROVIDERURI=`eval echo '$URIP'$o`
ad145f
+$LDAPMODIFY -D cn=config -H $MYURI -y $CONFIGPWF > $TESTOUT 2>&1 <
ad145f
+dn: olcDatabase={2}$BACKEND,cn=config
ad145f
+changetype: modify
ad145f
+replace: olcSyncRepl
ad145f
+olcSyncRepl: rid=001 provider=$PROVIDERURI binddn="$MANAGERDN" bindmethod=simple
ad145f
+  credentials=InvalidPw searchbase="$BASEDN" $SYNCTYPE
ad145f
+  retry="3 +" timeout=3 logbase="cn=log"
ad145f
+  logfilter="(&(objectclass=auditWriteObject)(reqresult=0))"
ad145f
+  syncdata=accesslog tls_cacert=$TESTDIR/tls/ca/certs/testsuiteCA.crt
ad145f
+  starttls=critical
ad145f
+-
ad145f
+replace: olcMirrorMode
ad145f
+olcMirrorMode: TRUE
ad145f
+
ad145f
+EOF
ad145f
+RC=$?
ad145f
+if test $RC != 0 ; then
ad145f
+	echo "ldapmodify failed for server $n config ($RC)!"
ad145f
+	test $KILLSERVERS != no && kill -HUP $KILLPIDS
ad145f
+	exit $RC
ad145f
+fi
ad145f
+n=`expr $n + 1`
ad145f
+done
ad145f
+
ad145f
+echo "Using ldapmodify to force conflicts between server 1 and 2..."
ad145f
+$LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
ad145f
+	>> $TESTOUT 2>&1 << EOF
ad145f
+dn: $THEDN
ad145f
+changetype: modify
ad145f
+add: description
ad145f
+description: Amazing
ad145f
+
ad145f
+EOF
ad145f
+RC=$?
ad145f
+if test $RC != 0 ; then
ad145f
+	echo "ldapmodify failed for server 1 database ($RC)!"
ad145f
+	test $KILLSERVERS != no && kill -HUP $KILLPIDS
ad145f
+	exit $RC
ad145f
+fi
ad145f
+
ad145f
+$LDAPMODIFY -D "$MANAGERDN" -H $URI2 -w $PASSWD \
ad145f
+	>> $TESTOUT 2>&1 << EOF
ad145f
+dn: $THEDN
ad145f
+changetype: modify
ad145f
+add: description
ad145f
+description: Stupendous
ad145f
+
ad145f
+EOF
ad145f
+RC=$?
ad145f
+if test $RC != 0 ; then
ad145f
+	echo "ldapmodify failed for server 2 database ($RC)!"
ad145f
+	test $KILLSERVERS != no && kill -HUP $KILLPIDS
ad145f
+	exit $RC
ad145f
+fi
ad145f
+
ad145f
+$LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
ad145f
+	>> $TESTOUT 2>&1 << EOF
ad145f
+dn: $THEDN
ad145f
+changetype: modify
ad145f
+delete: description
ad145f
+description: Outstanding
ad145f
+-
ad145f
+add: description
ad145f
+description: Mindboggling
ad145f
+
ad145f
+EOF
ad145f
+RC=$?
ad145f
+if test $RC != 0 ; then
ad145f
+	echo "ldapmodify failed for server 1 database ($RC)!"
ad145f
+	test $KILLSERVERS != no && kill -HUP $KILLPIDS
ad145f
+	exit $RC
ad145f
+fi
ad145f
+
ad145f
+$LDAPMODIFY -D "$MANAGERDN" -H $URI2 -w $PASSWD \
ad145f
+	>> $TESTOUT 2>&1 << EOF
ad145f
+dn: $THEDN
ad145f
+changetype: modify
ad145f
+delete: description
ad145f
+description: OutStanding
ad145f
+-
ad145f
+add: description
ad145f
+description: Bizarre
ad145f
+
ad145f
+EOF
ad145f
+RC=$?
ad145f
+if test $RC != 0 ; then
ad145f
+	echo "ldapmodify failed for server 2 database ($RC)!"
ad145f
+	test $KILLSERVERS != no && kill -HUP $KILLPIDS
ad145f
+	exit $RC
ad145f
+fi
ad145f
+
ad145f
+$LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
ad145f
+	>> $TESTOUT 2>&1 << EOF
ad145f
+dn: $THEDN
ad145f
+changetype: modify
ad145f
+add: carLicense
ad145f
+carLicense: 123-XYZ
ad145f
+-
ad145f
+add: employeeNumber
ad145f
+employeeNumber: 32
ad145f
+
ad145f
+EOF
ad145f
+RC=$?
ad145f
+if test $RC != 0 ; then
ad145f
+	echo "ldapmodify failed for server 1 database ($RC)!"
ad145f
+	test $KILLSERVERS != no && kill -HUP $KILLPIDS
ad145f
+	exit $RC
ad145f
+fi
ad145f
+
ad145f
+$LDAPMODIFY -D "$MANAGERDN" -H $URI2 -w $PASSWD \
ad145f
+	>> $TESTOUT 2>&1 << EOF
ad145f
+dn: $THEDN
ad145f
+changetype: modify
ad145f
+add: employeeType
ad145f
+employeeType: deadwood
ad145f
+-
ad145f
+add: employeeNumber
ad145f
+employeeNumber: 64
ad145f
+
ad145f
+EOF
ad145f
+RC=$?
ad145f
+if test $RC != 0 ; then
ad145f
+	echo "ldapmodify failed for server 2 database ($RC)!"
ad145f
+	test $KILLSERVERS != no && kill -HUP $KILLPIDS
ad145f
+	exit $RC
ad145f
+fi
ad145f
+
ad145f
+$LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
ad145f
+	>> $TESTOUT 2>&1 << EOF
ad145f
+dn: $THEDN
ad145f
+changetype: modify
ad145f
+replace: sn
ad145f
+sn: Replaced later
ad145f
+-
ad145f
+replace: sn
ad145f
+sn: Surname
ad145f
+EOF
ad145f
+RC=$?
ad145f
+if test $RC != 0 ; then
ad145f
+	echo "ldapmodify failed for server 1 database ($RC)!"
ad145f
+	test $KILLSERVERS != no && kill -HUP $KILLPIDS
ad145f
+	exit $RC
ad145f
+fi
ad145f
+
ad145f
+echo "Restoring replication between server 1 and 2..."
ad145f
+n=1
ad145f
+while [ $n -le $MMR ]; do
ad145f
+o=`expr 3 - $n`
ad145f
+MYURI=`eval echo '$URI'$n`
ad145f
+PROVIDERURI=`eval echo '$URIP'$o`
ad145f
+$LDAPMODIFY -D cn=config -H $MYURI -y $CONFIGPWF > $TESTOUT 2>&1 <
ad145f
+dn: olcDatabase={2}$BACKEND,cn=config
ad145f
+changetype: modify
ad145f
+replace: olcSyncRepl
ad145f
+olcSyncRepl: rid=001 provider=$PROVIDERURI binddn="$MANAGERDN" bindmethod=simple
ad145f
+  credentials=$PASSWD searchbase="$BASEDN" $SYNCTYPE
ad145f
+  retry="3 +" timeout=3 logbase="cn=log"
ad145f
+  logfilter="(&(objectclass=auditWriteObject)(reqresult=0))"
ad145f
+  syncdata=accesslog tls_cacert=$TESTDIR/tls/ca/certs/testsuiteCA.crt
ad145f
+  starttls=critical
ad145f
+-
ad145f
+replace: olcMirrorMode
ad145f
+olcMirrorMode: TRUE
ad145f
+
ad145f
+EOF
ad145f
+RC=$?
ad145f
+if test $RC != 0 ; then
ad145f
+	echo "ldapmodify failed for server $n config ($RC)!"
ad145f
+	test $KILLSERVERS != no && kill -HUP $KILLPIDS
ad145f
+	exit $RC
ad145f
+fi
ad145f
+n=`expr $n + 1`
ad145f
+done
ad145f
+
ad145f
+echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
ad145f
+sleep $SLEEP1
ad145f
+
ad145f
+n=1
ad145f
+while [ $n -le $MMR ]; do
ad145f
+PORT=`expr $BASEPORT + $n`
ad145f
+URI="ldap://${LOCALHOST}:$PORT/"
ad145f
+
ad145f
+echo "Using ldapsearch to read all the entries from server $n..."
ad145f
+$LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD  \
ad145f
+	'objectclass=*' > $TESTDIR/server$n.out 2>&1
ad145f
+RC=$?
ad145f
+
ad145f
+if test $RC != 0 ; then
ad145f
+	echo "ldapsearch failed at server $n ($RC)!"
ad145f
+	test $KILLSERVERS != no && kill -HUP $KILLPIDS
ad145f
+	exit $RC
ad145f
+fi
ad145f
+$LDIFFILTER -s a < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
ad145f
+n=`expr $n + 1`
ad145f
+done
ad145f
+
ad145f
+n=2
ad145f
+while [ $n -le $MMR ]; do
ad145f
+echo "Comparing retrieved entries from server 1 and server $n..."
ad145f
+$CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
ad145f
+
ad145f
+if test $? != 0 ; then
ad145f
+	echo "test failed - server 1 and server $n databases differ"
ad145f
+	test $KILLSERVERS != no && kill -HUP $KILLPIDS
ad145f
+	exit 1
ad145f
+fi
ad145f
+n=`expr $n + 1`
ad145f
+done
ad145f
+
ad145f
+test $KILLSERVERS != no && kill -HUP $KILLPIDS
ad145f
+
ad145f
+echo ">>>>> Test succeeded"
ad145f
+
ad145f
+test $KILLSERVERS != no && wait
ad145f
+
ad145f
+exit 0
ad145f
diff --git a/tests/scripts/test070-delta-multimaster-ldaps b/tests/scripts/test070-delta-multimaster-ldaps
ad145f
new file mode 100755
ad145f
index 000000000..1024640ef
ad145f
--- /dev/null
ad145f
+++ b/tests/scripts/test070-delta-multimaster-ldaps
ad145f
@@ -0,0 +1,571 @@
ad145f
+#! /bin/sh
ad145f
+# $OpenLDAP$
ad145f
+## This work is part of OpenLDAP Software <http://www.openldap.org/>.
ad145f
+##
ad145f
+## Copyright 1998-2017 The OpenLDAP Foundation.
ad145f
+## All rights reserved.
ad145f
+##
ad145f
+## Redistribution and use in source and binary forms, with or without
ad145f
+## modification, are permitted only as authorized by the OpenLDAP
ad145f
+## Public License.
ad145f
+##
ad145f
+## A copy of this license is available in the file LICENSE in the
ad145f
+## top-level directory of the distribution or, alternatively, at
ad145f
+## <http://www.OpenLDAP.org/license.html>.
ad145f
+
ad145f
+echo "running defines.sh"
ad145f
+. $SRCDIR/scripts/defines.sh
ad145f
+
ad145f
+if test $WITH_TLS = no ; then
ad145f
+        echo "TLS support not available, test skipped"
ad145f
+        exit 0
ad145f
+fi
ad145f
+
ad145f
+if test $SYNCPROV = syncprovno; then
ad145f
+	echo "Syncrepl provider overlay not available, test skipped"
ad145f
+	exit 0
ad145f
+fi
ad145f
+if test $ACCESSLOG = accesslogno; then
ad145f
+	echo "Accesslog overlay not available, test skipped"
ad145f
+	exit 0
ad145f
+fi
ad145f
+
ad145f
+MMR=2
ad145f
+
ad145f
+XDIR=$TESTDIR/srv
ad145f
+TMP=$TESTDIR/tmp
ad145f
+
ad145f
+mkdir -p $TESTDIR
ad145f
+cp -r $DATADIR/tls $TESTDIR
ad145f
+
ad145f
+$SLAPPASSWD -g -n >$CONFIGPWF
ad145f
+
ad145f
+if test x"$SYNCMODE" = x ; then
ad145f
+	SYNCMODE=rp
ad145f
+fi
ad145f
+case "$SYNCMODE" in
ad145f
+	ro)
ad145f
+		SYNCTYPE="type=refreshOnly interval=00:00:00:03"
ad145f
+		;;
ad145f
+	rp)
ad145f
+		SYNCTYPE="type=refreshAndPersist interval=00:00:00:03"
ad145f
+		;;
ad145f
+	*)
ad145f
+		echo "unknown sync mode $SYNCMODE"
ad145f
+		exit 1;
ad145f
+		;;
ad145f
+esac
ad145f
+
ad145f
+#
ad145f
+# Test delta-sync mmr
ad145f
+# - start servers
ad145f
+# - configure over ldap
ad145f
+# - populate over ldap
ad145f
+# - configure syncrepl over ldap
ad145f
+# - break replication
ad145f
+# - modify each server separately
ad145f
+# - restore replication
ad145f
+# - compare results
ad145f
+#
ad145f
+
ad145f
+nullExclude=""
ad145f
+test $BACKEND = null && nullExclude="# "
ad145f
+
ad145f
+KILLPIDS=
ad145f
+
ad145f
+echo "Initializing server configurations..."
ad145f
+n=1
ad145f
+while [ $n -le $MMR ]; do
ad145f
+
ad145f
+DBDIR=${XDIR}$n/db
ad145f
+CFDIR=${XDIR}$n/slapd.d
ad145f
+
ad145f
+mkdir -p ${XDIR}$n $DBDIR.1 $DBDIR.2 $CFDIR
ad145f
+
ad145f
+o=`expr 3 - $n`
ad145f
+cat > $TMP <
ad145f
+dn: cn=config
ad145f
+objectClass: olcGlobal
ad145f
+cn: config
ad145f
+olcServerID: $n
ad145f
+olcTLSCertificateFile: $TESTDIR/tls/certs/localhost.crt
ad145f
+olcTLSCertificateKeyFile: $TESTDIR/tls/private/localhost.key
ad145f
+
ad145f
+EOF
ad145f
+
ad145f
+if [ "$SYNCPROV" = syncprovmod -o "$ACCESSLOG" = accesslogmod ]; then
ad145f
+  cat <<EOF >> $TMP
ad145f
+dn: cn=module,cn=config
ad145f
+objectClass: olcModuleList
ad145f
+cn: module
ad145f
+olcModulePath: $TESTWD/../servers/slapd/overlays
ad145f
+EOF
ad145f
+  if [ "$SYNCPROV" = syncprovmod ]; then
ad145f
+  echo "olcModuleLoad: syncprov.la" >> $TMP
ad145f
+  fi
ad145f
+  if [ "$ACCESSLOG" = accesslogmod ]; then
ad145f
+  echo "olcModuleLoad: accesslog.la" >> $TMP
ad145f
+  fi
ad145f
+  echo "" >> $TMP
ad145f
+fi
ad145f
+
ad145f
+if [ "$BACKENDTYPE" = mod ]; then
ad145f
+cat <<EOF >> $TMP
ad145f
+dn: cn=module,cn=config
ad145f
+objectClass: olcModuleList
ad145f
+cn: module
ad145f
+olcModulePath: $TESTWD/../servers/slapd/back-$BACKEND
ad145f
+olcModuleLoad: back_$BACKEND.la
ad145f
+
ad145f
+EOF
ad145f
+fi
ad145f
+MYURI=`eval echo '$SURIP'$n`
ad145f
+PROVIDERURI=`eval echo '$SURIP'$o`
ad145f
+if test $INDEXDB = indexdb ; then
ad145f
+INDEX1="olcDbIndex: objectClass,entryCSN,reqStart,reqDN,reqResult eq"
ad145f
+INDEX2="olcDbIndex: objectClass,entryCSN,entryUUID eq"
ad145f
+else
ad145f
+INDEX1=
ad145f
+INDEX2=
ad145f
+fi
ad145f
+cat >> $TMP <
ad145f
+dn: cn=schema,cn=config
ad145f
+objectclass: olcSchemaconfig
ad145f
+cn: schema
ad145f
+
ad145f
+include: file://$ABS_SCHEMADIR/core.ldif
ad145f
+
ad145f
+include: file://$ABS_SCHEMADIR/cosine.ldif
ad145f
+
ad145f
+include: file://$ABS_SCHEMADIR/inetorgperson.ldif
ad145f
+
ad145f
+include: file://$ABS_SCHEMADIR/openldap.ldif
ad145f
+
ad145f
+include: file://$ABS_SCHEMADIR/nis.ldif
ad145f
+
ad145f
+dn: olcDatabase={0}config,cn=config
ad145f
+objectClass: olcDatabaseConfig
ad145f
+olcDatabase: {0}config
ad145f
+olcRootPW:< file://$CONFIGPWF
ad145f
+
ad145f
+dn: olcDatabase={1}$BACKEND,cn=config
ad145f
+objectClass: olcDatabaseConfig
ad145f
+${nullExclude}objectClass: olc${BACKEND}Config
ad145f
+olcDatabase: {1}$BACKEND
ad145f
+olcSuffix: cn=log
ad145f
+${nullExclude}olcDbDirectory: ${DBDIR}.1
ad145f
+olcRootDN: $MANAGERDN
ad145f
+$INDEX1
ad145f
+
ad145f
+dn: olcOverlay=syncprov,olcDatabase={1}$BACKEND,cn=config
ad145f
+objectClass: olcOverlayConfig
ad145f
+objectClass: olcSyncProvConfig
ad145f
+olcOverlay: syncprov
ad145f
+olcSpNoPresent: TRUE
ad145f
+olcSpReloadHint: TRUE
ad145f
+
ad145f
+dn: olcDatabase={2}$BACKEND,cn=config
ad145f
+objectClass: olcDatabaseConfig
ad145f
+${nullExclude}objectClass: olc${BACKEND}Config
ad145f
+olcDatabase: {2}$BACKEND
ad145f
+olcSuffix: $BASEDN
ad145f
+${nullExclude}olcDbDirectory: ${DBDIR}.2
ad145f
+olcRootDN: $MANAGERDN
ad145f
+olcRootPW: $PASSWD
ad145f
+olcSyncRepl: rid=001 provider=$PROVIDERURI binddn="$MANAGERDN" bindmethod=simple
ad145f
+  credentials=$PASSWD searchbase="$BASEDN" $SYNCTYPE
ad145f
+  retry="3 +" timeout=3 logbase="cn=log"
ad145f
+  logfilter="(&(objectclass=auditWriteObject)(reqresult=0))"
ad145f
+  syncdata=accesslog tls_cacert=$TESTDIR/tls/ca/certs/testsuiteCA.crt
ad145f
+olcMirrorMode: TRUE
ad145f
+$INDEX2
ad145f
+
ad145f
+dn: olcOverlay=syncprov,olcDatabase={2}$BACKEND,cn=config
ad145f
+objectClass: olcOverlayConfig
ad145f
+objectClass: olcSyncProvConfig
ad145f
+olcOverlay: syncprov
ad145f
+
ad145f
+dn: olcOverlay=accesslog,olcDatabase={2}$BACKEND,cn=config
ad145f
+objectClass: olcOverlayConfig
ad145f
+objectClass: olcAccessLogConfig
ad145f
+olcOverlay: accesslog
ad145f
+olcAccessLogDB: cn=log
ad145f
+olcAccessLogOps: writes
ad145f
+olcAccessLogSuccess: TRUE
ad145f
+
ad145f
+EOF
ad145f
+$SLAPADD -F $CFDIR -n 0  -d-1< $TMP > $TESTOUT 2>&1
ad145f
+PORT=`eval echo '$PORT'$n`
ad145f
+echo "Starting server $n on TCP/IP port $PORT..."
ad145f
+cd ${XDIR}${n}
ad145f
+LOG=`eval echo '$LOG'$n`
ad145f
+$SLAPD -F slapd.d -h $MYURI -d $LVL $TIMING > $LOG 2>&1 &
ad145f
+PID=$!
ad145f
+if test $WAIT != 0 ; then
ad145f
+    echo PID $PID
ad145f
+    read foo
ad145f
+fi
ad145f
+KILLPIDS="$PID $KILLPIDS"
ad145f
+cd $TESTWD
ad145f
+
ad145f
+echo "Using ldapsearch to check that server $n is running..."
ad145f
+for i in 0 1 2 3 4 5; do
ad145f
+	$LDAPSEARCH -o tls_cacert=$TESTDIR/tls/ca/certs/testsuiteCA.crt -s base -b "" -H $MYURI \
ad145f
+		'objectclass=*' > /dev/null 2>&1
ad145f
+	RC=$?
ad145f
+	if test $RC = 0 ; then
ad145f
+		break
ad145f
+	fi
ad145f
+	echo "Waiting 5 seconds for slapd to start..."
ad145f
+	sleep 5
ad145f
+done
ad145f
+
ad145f
+if test $RC != 0 ; then
ad145f
+	echo "ldapsearch failed ($RC)!"
ad145f
+	test $KILLSERVERS != no && kill -HUP $KILLPIDS
ad145f
+	exit $RC
ad145f
+fi
ad145f
+
ad145f
+if [ $n = 1 ]; then
ad145f
+echo "Using ldapadd for context on server 1..."
ad145f
+$LDAPADD -D "$MANAGERDN" -H $SURIP1 -w $PASSWD -o tls_cacert=$TESTDIR/tls/ca/certs/testsuiteCA.crt -f $LDIFORDEREDCP \
ad145f
+	>> $TESTOUT 2>&1
ad145f
+RC=$?
ad145f
+if test $RC != 0 ; then
ad145f
+	echo "ldapadd failed for server $n database ($RC)!"
ad145f
+	test $KILLSERVERS != no && kill -HUP $KILLPIDS
ad145f
+	exit $RC
ad145f
+fi
ad145f
+fi
ad145f
+
ad145f
+n=`expr $n + 1`
ad145f
+done
ad145f
+
ad145f
+echo "Using ldapadd to populate server 1..."
ad145f
+$LDAPADD -D "$MANAGERDN" -H $SURIP1 -w $PASSWD -o tls_cacert=$TESTDIR/tls/ca/certs/testsuiteCA.crt -f $LDIFORDEREDNOCP \
ad145f
+	>> $TESTOUT 2>&1
ad145f
+RC=$?
ad145f
+if test $RC != 0 ; then
ad145f
+	echo "ldapadd failed for server $n database ($RC)!"
ad145f
+	test $KILLSERVERS != no && kill -HUP $KILLPIDS
ad145f
+	exit $RC
ad145f
+fi
ad145f
+
ad145f
+echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
ad145f
+sleep $SLEEP1
ad145f
+
ad145f
+n=1
ad145f
+while [ $n -le $MMR ]; do
ad145f
+PORT=`expr $BASEPORT + $n`
ad145f
+URI="ldaps://${LOCALIP}:$PORT/"
ad145f
+
ad145f
+echo "Using ldapsearch to read all the entries from server $n..."
ad145f
+$LDAPSEARCH -S "" -b "$BASEDN" -o tls_cacert=$TESTDIR/tls/ca/certs/testsuiteCA.crt -D "$MANAGERDN" -H $URI -w $PASSWD  \
ad145f
+	'objectclass=*' > $TESTDIR/server$n.out 2>&1
ad145f
+RC=$?
ad145f
+
ad145f
+if test $RC != 0 ; then
ad145f
+	echo "ldapsearch failed at server $n ($RC)!"
ad145f
+	test $KILLSERVERS != no && kill -HUP $KILLPIDS
ad145f
+	exit $RC
ad145f
+fi
ad145f
+$LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
ad145f
+n=`expr $n + 1`
ad145f
+done
ad145f
+
ad145f
+n=2
ad145f
+while [ $n -le $MMR ]; do
ad145f
+echo "Comparing retrieved entries from server 1 and server $n..."
ad145f
+$CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
ad145f
+
ad145f
+if test $? != 0 ; then
ad145f
+	echo "test failed - server 1 and server $n databases differ"
ad145f
+	test $KILLSERVERS != no && kill -HUP $KILLPIDS
ad145f
+	exit 1
ad145f
+fi
ad145f
+n=`expr $n + 1`
ad145f
+done
ad145f
+
ad145f
+echo "Using ldapadd to populate server 2..."
ad145f
+$LDAPADD -o tls_cacert=$TESTDIR/tls/ca/certs/testsuiteCA.crt -D "$MANAGERDN" -H $SURIP2 -w $PASSWD -f $LDIFADD1 \
ad145f
+	>> $TESTOUT 2>&1
ad145f
+RC=$?
ad145f
+if test $RC != 0 ; then
ad145f
+	echo "ldapadd failed for server 2 database ($RC)!"
ad145f
+	test $KILLSERVERS != no && kill -HUP $KILLPIDS
ad145f
+	exit $RC
ad145f
+fi
ad145f
+
ad145f
+THEDN="cn=James A Jones 2,ou=Alumni Association,ou=People,dc=example,dc=com"
ad145f
+sleep 1
ad145f
+for i in 1 2 3; do
ad145f
+	$LDAPSEARCH -S "" -b "$THEDN" -o tls_cacert=$TESTDIR/tls/ca/certs/testsuiteCA.crt -H $SURIP1 \
ad145f
+		-s base '(objectClass=*)' entryCSN > "${MASTEROUT}.$i" 2>&1
ad145f
+	RC=$?
ad145f
+
ad145f
+	if test $RC = 0 ; then
ad145f
+		break
ad145f
+	fi
ad145f
+
ad145f
+	if test $RC != 32 ; then
ad145f
+		echo "ldapsearch failed at slave ($RC)!"
ad145f
+		test $KILLSERVERS != no && kill -HUP $KILLPIDS
ad145f
+		exit $RC
ad145f
+	fi
ad145f
+
ad145f
+	echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
ad145f
+	sleep $SLEEP1
ad145f
+done
ad145f
+
ad145f
+n=1
ad145f
+while [ $n -le $MMR ]; do
ad145f
+PORT=`expr $BASEPORT + $n`
ad145f
+URI="ldaps://${LOCALIP}:$PORT/"
ad145f
+
ad145f
+echo "Using ldapsearch to read all the entries from server $n..."
ad145f
+$LDAPSEARCH -S "" -o tls_cacert=$TESTDIR/tls/ca/certs/testsuiteCA.crt -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD  \
ad145f
+	'objectclass=*' > $TESTDIR/server$n.out 2>&1
ad145f
+RC=$?
ad145f
+
ad145f
+if test $RC != 0 ; then
ad145f
+	echo "ldapsearch failed at server $n ($RC)!"
ad145f
+	test $KILLSERVERS != no && kill -HUP $KILLPIDS
ad145f
+	exit $RC
ad145f
+fi
ad145f
+$LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
ad145f
+n=`expr $n + 1`
ad145f
+done
ad145f
+
ad145f
+n=2
ad145f
+while [ $n -le $MMR ]; do
ad145f
+echo "Comparing retrieved entries from server 1 and server $n..."
ad145f
+$CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
ad145f
+
ad145f
+if test $? != 0 ; then
ad145f
+	echo "test failed - server 1 and server $n databases differ"
ad145f
+	test $KILLSERVERS != no && kill -HUP $KILLPIDS
ad145f
+	exit 1
ad145f
+fi
ad145f
+n=`expr $n + 1`
ad145f
+done
ad145f
+
ad145f
+echo "Breaking replication between server 1 and 2..."
ad145f
+n=1
ad145f
+while [ $n -le $MMR ]; do
ad145f
+o=`expr 3 - $n`
ad145f
+MYURI=`eval echo '$SURIP'$n`
ad145f
+PROVIDERURI=`eval echo '$SURIP'$o`
ad145f
+$LDAPMODIFY -o tls_cacert=$TESTDIR/tls/ca/certs/testsuiteCA.crt -D cn=config -H $MYURI -y $CONFIGPWF > $TESTOUT 2>&1 <
ad145f
+dn: olcDatabase={2}$BACKEND,cn=config
ad145f
+changetype: modify
ad145f
+replace: olcSyncRepl
ad145f
+olcSyncRepl: rid=001 provider=$PROVIDERURI binddn="$MANAGERDN" bindmethod=simple
ad145f
+  credentials=InvalidPw searchbase="$BASEDN" $SYNCTYPE
ad145f
+  retry="3 +" timeout=3 logbase="cn=log"
ad145f
+  logfilter="(&(objectclass=auditWriteObject)(reqresult=0))"
ad145f
+  syncdata=accesslog tls_cacert=$TESTDIR/tls/ca/certs/testsuiteCA.crt
ad145f
+-
ad145f
+replace: olcMirrorMode
ad145f
+olcMirrorMode: TRUE
ad145f
+
ad145f
+EOF
ad145f
+RC=$?
ad145f
+if test $RC != 0 ; then
ad145f
+	echo "ldapmodify failed for server $n config ($RC)!"
ad145f
+	test $KILLSERVERS != no && kill -HUP $KILLPIDS
ad145f
+	exit $RC
ad145f
+fi
ad145f
+n=`expr $n + 1`
ad145f
+done
ad145f
+
ad145f
+echo "Using ldapmodify to force conflicts between server 1 and 2..."
ad145f
+$LDAPMODIFY -o tls_cacert=$TESTDIR/tls/ca/certs/testsuiteCA.crt -D "$MANAGERDN" -H $SURIP1 -w $PASSWD \
ad145f
+	>> $TESTOUT 2>&1 << EOF
ad145f
+dn: $THEDN
ad145f
+changetype: modify
ad145f
+add: description
ad145f
+description: Amazing
ad145f
+
ad145f
+EOF
ad145f
+RC=$?
ad145f
+if test $RC != 0 ; then
ad145f
+	echo "ldapmodify failed for server 1 database ($RC)!"
ad145f
+	test $KILLSERVERS != no && kill -HUP $KILLPIDS
ad145f
+	exit $RC
ad145f
+fi
ad145f
+
ad145f
+$LDAPMODIFY -o tls_cacert=$TESTDIR/tls/ca/certs/testsuiteCA.crt -D "$MANAGERDN" -H $SURIP2 -w $PASSWD \
ad145f
+	>> $TESTOUT 2>&1 << EOF
ad145f
+dn: $THEDN
ad145f
+changetype: modify
ad145f
+add: description
ad145f
+description: Stupendous
ad145f
+
ad145f
+EOF
ad145f
+RC=$?
ad145f
+if test $RC != 0 ; then
ad145f
+	echo "ldapmodify failed for server 2 database ($RC)!"
ad145f
+	test $KILLSERVERS != no && kill -HUP $KILLPIDS
ad145f
+	exit $RC
ad145f
+fi
ad145f
+
ad145f
+$LDAPMODIFY -o tls_cacert=$TESTDIR/tls/ca/certs/testsuiteCA.crt -D "$MANAGERDN" -H $SURIP1 -w $PASSWD \
ad145f
+	>> $TESTOUT 2>&1 << EOF
ad145f
+dn: $THEDN
ad145f
+changetype: modify
ad145f
+delete: description
ad145f
+description: Outstanding
ad145f
+-
ad145f
+add: description
ad145f
+description: Mindboggling
ad145f
+
ad145f
+EOF
ad145f
+RC=$?
ad145f
+if test $RC != 0 ; then
ad145f
+	echo "ldapmodify failed for server 1 database ($RC)!"
ad145f
+	test $KILLSERVERS != no && kill -HUP $KILLPIDS
ad145f
+	exit $RC
ad145f
+fi
ad145f
+
ad145f
+$LDAPMODIFY -o tls_cacert=$TESTDIR/tls/ca/certs/testsuiteCA.crt -D "$MANAGERDN" -H $SURIP2 -w $PASSWD \
ad145f
+	>> $TESTOUT 2>&1 << EOF
ad145f
+dn: $THEDN
ad145f
+changetype: modify
ad145f
+delete: description
ad145f
+description: OutStanding
ad145f
+-
ad145f
+add: description
ad145f
+description: Bizarre
ad145f
+
ad145f
+EOF
ad145f
+RC=$?
ad145f
+if test $RC != 0 ; then
ad145f
+	echo "ldapmodify failed for server 2 database ($RC)!"
ad145f
+	test $KILLSERVERS != no && kill -HUP $KILLPIDS
ad145f
+	exit $RC
ad145f
+fi
ad145f
+
ad145f
+$LDAPMODIFY -o tls_cacert=$TESTDIR/tls/ca/certs/testsuiteCA.crt -D "$MANAGERDN" -H $SURIP1 -w $PASSWD \
ad145f
+	>> $TESTOUT 2>&1 << EOF
ad145f
+dn: $THEDN
ad145f
+changetype: modify
ad145f
+add: carLicense
ad145f
+carLicense: 123-XYZ
ad145f
+-
ad145f
+add: employeeNumber
ad145f
+employeeNumber: 32
ad145f
+
ad145f
+EOF
ad145f
+RC=$?
ad145f
+if test $RC != 0 ; then
ad145f
+	echo "ldapmodify failed for server 1 database ($RC)!"
ad145f
+	test $KILLSERVERS != no && kill -HUP $KILLPIDS
ad145f
+	exit $RC
ad145f
+fi
ad145f
+
ad145f
+$LDAPMODIFY -o tls_cacert=$TESTDIR/tls/ca/certs/testsuiteCA.crt -D "$MANAGERDN" -H $SURIP2 -w $PASSWD \
ad145f
+	>> $TESTOUT 2>&1 << EOF
ad145f
+dn: $THEDN
ad145f
+changetype: modify
ad145f
+add: employeeType
ad145f
+employeeType: deadwood
ad145f
+-
ad145f
+add: employeeNumber
ad145f
+employeeNumber: 64
ad145f
+
ad145f
+EOF
ad145f
+RC=$?
ad145f
+if test $RC != 0 ; then
ad145f
+	echo "ldapmodify failed for server 2 database ($RC)!"
ad145f
+	test $KILLSERVERS != no && kill -HUP $KILLPIDS
ad145f
+	exit $RC
ad145f
+fi
ad145f
+
ad145f
+$LDAPMODIFY -o tls_cacert=$TESTDIR/tls/ca/certs/testsuiteCA.crt -D "$MANAGERDN" -H $SURIP1 -w $PASSWD \
ad145f
+	>> $TESTOUT 2>&1 << EOF
ad145f
+dn: $THEDN
ad145f
+changetype: modify
ad145f
+replace: sn
ad145f
+sn: Replaced later
ad145f
+-
ad145f
+replace: sn
ad145f
+sn: Surname
ad145f
+EOF
ad145f
+RC=$?
ad145f
+if test $RC != 0 ; then
ad145f
+	echo "ldapmodify failed for server 1 database ($RC)!"
ad145f
+	test $KILLSERVERS != no && kill -HUP $KILLPIDS
ad145f
+	exit $RC
ad145f
+fi
ad145f
+
ad145f
+echo "Restoring replication between server 1 and 2..."
ad145f
+n=1
ad145f
+while [ $n -le $MMR ]; do
ad145f
+o=`expr 3 - $n`
ad145f
+MYURI=`eval echo '$SURIP'$n`
ad145f
+PROVIDERURI=`eval echo '$SURIP'$o`
ad145f
+$LDAPMODIFY -D cn=config -o tls_cacert=$TESTDIR/tls/ca/certs/testsuiteCA.crt -H $MYURI -y $CONFIGPWF > $TESTOUT 2>&1 <
ad145f
+dn: olcDatabase={2}$BACKEND,cn=config
ad145f
+changetype: modify
ad145f
+replace: olcSyncRepl
ad145f
+olcSyncRepl: rid=001 provider=$PROVIDERURI binddn="$MANAGERDN" bindmethod=simple
ad145f
+  credentials=$PASSWD searchbase="$BASEDN" $SYNCTYPE
ad145f
+  retry="3 +" timeout=3 logbase="cn=log"
ad145f
+  logfilter="(&(objectclass=auditWriteObject)(reqresult=0))"
ad145f
+  syncdata=accesslog tls_cacert=$TESTDIR/tls/ca/certs/testsuiteCA.crt
ad145f
+-
ad145f
+replace: olcMirrorMode
ad145f
+olcMirrorMode: TRUE
ad145f
+
ad145f
+EOF
ad145f
+RC=$?
ad145f
+if test $RC != 0 ; then
ad145f
+	echo "ldapmodify failed for server $n config ($RC)!"
ad145f
+	test $KILLSERVERS != no && kill -HUP $KILLPIDS
ad145f
+	exit $RC
ad145f
+fi
ad145f
+n=`expr $n + 1`
ad145f
+done
ad145f
+
ad145f
+echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
ad145f
+sleep $SLEEP1
ad145f
+
ad145f
+n=1
ad145f
+while [ $n -le $MMR ]; do
ad145f
+PORT=`expr $BASEPORT + $n`
ad145f
+URI="ldaps://${LOCALIP}:$PORT/"
ad145f
+
ad145f
+echo "Using ldapsearch to read all the entries from server $n..."
ad145f
+$LDAPSEARCH -o tls_cacert=$TESTDIR/tls/ca/certs/testsuiteCA.crt -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD  \
ad145f
+	'objectclass=*' > $TESTDIR/server$n.out 2>&1
ad145f
+RC=$?
ad145f
+
ad145f
+if test $RC != 0 ; then
ad145f
+	echo "ldapsearch failed at server $n ($RC)!"
ad145f
+	test $KILLSERVERS != no && kill -HUP $KILLPIDS
ad145f
+	exit $RC
ad145f
+fi
ad145f
+$LDIFFILTER -s a < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
ad145f
+n=`expr $n + 1`
ad145f
+done
ad145f
+
ad145f
+n=2
ad145f
+while [ $n -le $MMR ]; do
ad145f
+echo "Comparing retrieved entries from server 1 and server $n..."
ad145f
+$CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
ad145f
+
ad145f
+if test $? != 0 ; then
ad145f
+	echo "test failed - server 1 and server $n databases differ"
ad145f
+	test $KILLSERVERS != no && kill -HUP $KILLPIDS
ad145f
+	exit 1
ad145f
+fi
ad145f
+n=`expr $n + 1`
ad145f
+done
ad145f
+
ad145f
+test $KILLSERVERS != no && kill -HUP $KILLPIDS
ad145f
+
ad145f
+echo ">>>>> Test succeeded"
ad145f
+
ad145f
+test $KILLSERVERS != no && wait
ad145f
+
ad145f
+exit 0
ad145f
-- 
ad145f
2.26.2
ad145f