From 562360fa181a704ebaddf5be39271aaf9e17de57 Mon Sep 17 00:00:00 2001
From: Quanah Gibson-Mount <quanah@openldap.org>
Date: Sat, 29 Jul 2006 00:11:19 +0000
Subject: [PATCH] ITS#4613 fix more ITS#4622 fixes: syncprov: delete contextCSN
 on checkpoint if ctxcsn is empty

---
 servers/slapd/overlays/syncprov.c | 31 ++++++++++++++++++++++---------
 1 file changed, 22 insertions(+), 9 deletions(-)

diff --git a/servers/slapd/overlays/syncprov.c b/servers/slapd/overlays/syncprov.c
index 5a3b4185c6..271a48a672 100644
--- a/servers/slapd/overlays/syncprov.c
+++ b/servers/slapd/overlays/syncprov.c
@@ -1244,9 +1244,14 @@ syncprov_checkpoint( Operation *op, SlapReply *rs, slap_overinst *on )
 	struct berval bv[2];
 	slap_callback cb = {0};
 
-	mod.sml_values = bv;
-	bv[1].bv_val = NULL;
-	bv[0] = si->si_ctxcsn;
+	/* If ctxcsn is empty, delete it */
+	if ( BER_BVISEMPTY( &si->si_ctxcsn )) {
+		mod.sml_values = NULL;
+	} else {
+		mod.sml_values = bv;
+		bv[1].bv_val = NULL;
+		bv[0] = si->si_ctxcsn;
+	}
 	mod.sml_nvalues = NULL;
 	mod.sml_desc = slap_schema.si_ad_contextCSN;
 	mod.sml_op = LDAP_MOD_REPLACE;
@@ -1366,6 +1371,7 @@ syncprov_playlog( Operation *op, SlapReply *rs, sessionlog *sl,
 			i++;
 			AC_MEMCPY( cbuf, se->se_csn.bv_val, se->se_csn.bv_len );
 			delcsn.bv_len = se->se_csn.bv_len;
+			delcsn.bv_val[delcsn.bv_len] = '\0';
 		} else {
 			nmods++;
 			j = num - nmods;
@@ -2326,6 +2332,12 @@ syncprov_db_open(
 	int rc;
 	void *thrctx = NULL;
 
+	if ( !SLAP_LASTMOD( be )) {
+		Debug( LDAP_DEBUG_ANY,
+			"syncprov_db_open: invalid config, lastmod must be enabled\n", 0, 0, 0 );
+		return -1;
+	}
+
 	if ( slapMode & SLAP_TOOL_MODE ) {
 		return 0;
 	}
@@ -2369,15 +2381,16 @@ syncprov_db_open(
 			ldap_pvt_thread_create( &tid, 0, syncprov_db_otask, op );
 			ldap_pvt_thread_join( tid, NULL );
 		}
-	} else if ( SLAP_SYNC_SHADOW( op->o_bd )) {
-		/* If we're also a consumer, and we didn't find the context entry,
-		 * then don't generate anything, wait for our provider to send it
-		 * to us.
-		 */
-		goto out;
 	}
 
 	if ( BER_BVISEMPTY( &si->si_ctxcsn ) ) {
+		if ( SLAP_SYNC_SHADOW( op->o_bd )) {
+		/* If we're also a consumer, and we didn't get a contextCSN,
+		 * then don't generate anything, wait for our provider to send it
+		 * to us.
+		 */
+			goto out;
+		}
 		si->si_ctxcsn.bv_len = sizeof( si->si_ctxcsnbuf );
 		slap_get_csn( op, &si->si_ctxcsn, 0 );
 	}
-- 
GitLab