From: Howard Chu Date: Tue, 3 Aug 2021 12:09:26 +0000 (+0100) Subject: ITS#8649 syncrepl: fix backend selection in glued DBs X-Git-Tag: OPENLDAP_REL_ENG_2_6_0~139 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bc29154c620f6023aec361e15b1248a9cbbe6e50;p=thirdparty%2Fopenldap.git ITS#8649 syncrepl: fix backend selection in glued DBs --- diff --git a/servers/slapd/syncrepl.c b/servers/slapd/syncrepl.c index 2a6efe5e9a..30eac92885 100644 --- a/servers/slapd/syncrepl.c +++ b/servers/slapd/syncrepl.c @@ -2030,15 +2030,21 @@ do_syncrepl( * contextCSN updates should only go to the local DB. */ if ( !si->si_wbe ) { - if ( SLAP_GLUE_SUBORDINATE( be ) && !overlay_is_inst( be, "syncprov" )) { - BackendDB * top_be = select_backend( &be->be_nsuffix[0], 1 ); - if ( overlay_is_inst( top_be, "syncprov" )) - si->si_wbe = top_be; - else - si->si_wbe = be; - } else { - si->si_wbe = be; + if ( SLAP_GLUE_SUBORDINATE( be )) { + BackendDB *b0 = be; + struct berval ndn = be->be_nsuffix[0]; + while ( !overlay_is_inst( be, "syncprov" )) { + /* If we got all the way to the primary without any + * syncprov, just use original backend */ + if ( SLAP_GLUE_INSTANCE( be )) { + be = b0; + break; + } + dnParent( &ndn, &ndn ); + be = select_backend( &ndn, 0 ); + } } + si->si_wbe = be; if ( SLAP_SYNC_SUBENTRY( si->si_wbe )) { build_new_dn( &si->si_contextdn, &si->si_wbe->be_nsuffix[0], (struct berval *)&slap_ldapsync_cn_bv, NULL );