]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/syncrepl.c
ITS5282 fix for 2.3
[openldap] / servers / slapd / syncrepl.c
index 6b743c96dac81a395f63de96dc5631fede6b5724..914b0a0b996acdce4b24a1fe01f992b633341910 100644 (file)
@@ -80,6 +80,7 @@ typedef struct syncinfo_s {
        int                                     si_tlimit;
        int                                     si_refreshDelete;
        int                                     si_refreshPresent;
+       int                                     si_refreshDone;
        int                                     si_syncdata;
        int                                     si_logstate;
        int                                     si_conn_setup;
@@ -584,6 +585,8 @@ do_syncrep1(
                        &si->si_syncCookie.ctxcsn, si->si_syncCookie.rid );
        }
 
+       si->si_refreshDone = 0;
+
        rc = ldap_sync_search( si, op->o_tmpmemctx );
 
        if( rc != LDAP_SUCCESS ) {
@@ -631,8 +634,6 @@ do_syncrep2(
        int     rc, err, i;
        ber_len_t       len;
 
-       int rc_efree = 1;
-
        struct berval   *psub;
        Modifications   *modlist = NULL;
 
@@ -643,7 +644,6 @@ do_syncrep2(
        struct timeval tout = { 0, 0 };
 
        int             refreshDeletes = 0;
-       int             refreshDone = 1;
        BerVarray syncUUIDs = NULL;
        ber_tag_t si_tag;
 
@@ -716,19 +716,19 @@ do_syncrep2(
                                                slap_parse_sync_cookie( &syncCookie, NULL );
                                        }
                                }
+                               rc = 0;
                                if ( si->si_syncdata && si->si_logstate == SYNCLOG_LOGGING ) {
-                                       entry = NULL;
                                        modlist = NULL;
-                                       if ( syncrepl_message_to_op( si, op, msg ) == LDAP_SUCCESS &&
+                                       if (( rc = syncrepl_message_to_op( si, op, msg )) == LDAP_SUCCESS &&
                                                !BER_BVISNULL( &syncCookie.ctxcsn ) ) {
                                                syncrepl_updateCookie( si, op, psub, &syncCookie );
                                        }
-                               } else if ( syncrepl_message_to_entry( si, op, msg,
-                                       &modlist, &entry, syncstate ) == LDAP_SUCCESS ) {
-                                       rc_efree = syncrepl_entry( si, op, entry, &modlist,
-                                               syncstate, &syncUUID, &syncCookie_req, &syncCookie.ctxcsn );
-                                       if ( !BER_BVISNULL( &syncCookie.ctxcsn ) )
-                                       {
+                               } else if (( rc = syncrepl_message_to_entry( si, op, msg,
+                                       &modlist, &entry, syncstate )) == LDAP_SUCCESS ) {
+                                       if (( rc = syncrepl_entry( si, op, entry, &modlist,
+                                               syncstate, &syncUUID, &syncCookie_req,
+                                               &syncCookie.ctxcsn )) == LDAP_SUCCESS &&
+                                               !BER_BVISNULL( &syncCookie.ctxcsn ) ) {
                                                syncrepl_updateCookie( si, op, psub, &syncCookie );
                                        }
                                }
@@ -736,10 +736,8 @@ do_syncrep2(
                                if ( modlist ) {
                                        slap_mods_free( modlist, 1 );
                                }
-                               if ( rc_efree && entry ) {
-                                       entry_free( entry );
-                               }
-                               entry = NULL;
+                               if ( rc )
+                                       goto done;
                                break;
 
                        case LDAP_RES_SEARCH_REFERENCE:
@@ -874,10 +872,14 @@ do_syncrep2(
                                                                slap_parse_sync_cookie( &syncCookie, NULL );
                                                        }
                                                }
+                                               /* Defaults to TRUE */
                                                if ( ber_peek_tag( ber, &len ) ==
                                                        LDAP_TAG_REFRESHDONE )
                                                {
-                                                       ber_scanf( ber, "b", &refreshDone );
+                                                       ber_scanf( ber, "b", &si->si_refreshDone );
+                                               } else
+                                               {
+                                                       si->si_refreshDone = 1;
                                                }
                                                ber_scanf( ber, /*"{"*/ "}" );
                                                break;
@@ -1522,7 +1524,6 @@ syncrepl_message_to_entry(
        }
 
        e = ( Entry * ) ch_calloc( 1, sizeof( Entry ) );
-       *entry = e;
        e->e_name = op->o_req_dn;
        e->e_nname = op->o_req_ndn;
 
@@ -1598,9 +1599,10 @@ done:
        if ( rc != LDAP_SUCCESS ) {
                if ( e ) {
                        entry_free( e );
-                       *entry = e = NULL;
+                       e = NULL;
                }
        }
+       *entry = e;
 
        return rc;
 }
@@ -1663,7 +1665,6 @@ syncrepl_entry(
        AttributeAssertion ava = { NULL, BER_BVNULL };
 #endif
        int rc = LDAP_SUCCESS;
-       int ret = LDAP_SUCCESS;
 
        struct berval pdn = BER_BVNULL;
        dninfo dni = {0};
@@ -1697,7 +1698,7 @@ syncrepl_entry(
        }
 
        if (( syncstate == LDAP_SYNC_PRESENT || syncstate == LDAP_SYNC_ADD )) {
-               if ( !si->si_refreshPresent ) {
+               if ( !si->si_refreshPresent && !si->si_refreshDone ) {
                        syncuuid_bv = ber_dupbv( NULL, syncUUID );
                        avl_insert( &si->si_presentlist, (caddr_t) syncuuid_bv,
                                syncuuid_cmp, avl_dup_error );
@@ -1832,15 +1833,15 @@ retry_add:;
                        switch ( rs_add.sr_err ) {
                        case LDAP_SUCCESS:
                                be_entry_release_w( op, entry );
-                               ret = 0;
+                               entry = NULL;
                                break;
 
                        case LDAP_REFERRAL:
                        /* we assume that LDAP_NO_SUCH_OBJECT is returned 
                         * only if the suffix entry is not present */
                        case LDAP_NO_SUCH_OBJECT:
-                               syncrepl_add_glue( op, entry );
-                               ret = 0;
+                               rc = syncrepl_add_glue( op, entry );
+                               entry = NULL;
                                break;
 
                        /* if an entry was added via syncrepl_add_glue(),
@@ -1876,7 +1877,8 @@ retry_add:;
                                        cb2.sc_response = dn_callback;
                                        cb2.sc_private = &dni;
 
-                                       be->be_search( &op2, &rs2 );
+                                       rc = be->be_search( &op2, &rs2 );
+                                       if ( rc ) goto done;
 
                                        retry = 0;
                                        slap_op_time( &op->o_time, &op->o_tincr );
@@ -1888,7 +1890,6 @@ retry_add:;
                                Debug( LDAP_DEBUG_ANY,
                                        "syncrepl_entry: rid %03d be_add failed (%d)\n",
                                        si->si_rid, rs_add.sr_err, 0 );
-                               ret = 1;
                                break;
                        }
                        goto done;
@@ -1922,7 +1923,6 @@ retry_add:;
                                op->o_req_dn = entry->e_name;
                                op->o_req_ndn = entry->e_nname;
                        } else {
-                               ret = 1;
                                goto done;
                        }
                        if ( dni.wasChanged )
@@ -1990,7 +1990,6 @@ retry_add:;
                                        si->si_rid, rs_modify.sr_err, 0 );
                        }
                }
-               ret = 1;
                goto done;
        case LDAP_SYNC_DELETE :
                if ( !BER_BVISNULL( &dni.dn )) {
@@ -2018,13 +2017,11 @@ retry_add:;
                                }
                        }
                }
-               ret = 0;
                goto done;
 
        default :
                Debug( LDAP_DEBUG_ANY,
                        "syncrepl_entry: rid %03d unknown syncstate\n", si->si_rid, 0, 0 );
-               ret = 1;
                goto done;
        }
 
@@ -2042,8 +2039,10 @@ done :
        if ( !BER_BVISNULL( &dni.dn ) ) {
                op->o_tmpfree( dni.dn.bv_val, op->o_tmpmemctx );
        }
+       if ( entry )
+               entry_free( entry );
        BER_BVZERO( &op->o_csn );
-       return ret;
+       return rc;
 }
 
 static struct berval gcbva[] = {
@@ -2109,11 +2108,8 @@ syncrepl_del_nonpresent(
 
                for (i=0; uuids[i].bv_val; i++) {
                        op->ors_slimit = 1;
-                       slap_uuidstr_from_normalized( &uf.f_av_value, &uuids[i],
-                               op->o_tmpmemctx );
-                       filter2bv_x( op, op->ors_filter, &op->ors_filterstr );
-                       op->o_tmpfree( uf.f_av_value.bv_val, op->o_tmpmemctx );
                        uf.f_av_value = uuids[i];
+                       filter2bv_x( op, op->ors_filter, &op->ors_filterstr );
                        rc = be->be_search( op, &rs_search );
                        op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx );
                }
@@ -2219,7 +2215,7 @@ syncrepl_del_nonpresent(
        return;
 }
 
-void
+int
 syncrepl_add_glue(
        Operation* op,
        Entry *e )
@@ -2329,6 +2325,10 @@ syncrepl_add_glue(
                } else {
                /* incl. ALREADY EXIST */
                        entry_free( glue );
+                       if ( rs_add.sr_err != LDAP_ALREADY_EXISTS ) {
+                               entry_free( e );
+                               return rc;
+                       }
                }
 
                /* Move to next child */
@@ -2359,7 +2359,7 @@ syncrepl_add_glue(
                entry_free( e );
        }
 
-       return;
+       return rc;
 }
 
 static void
@@ -2373,7 +2373,7 @@ syncrepl_updateCookie(
        Modifications mod = { { 0 } };
        struct berval vals[ 2 ];
 
-       int rc;
+       int rc, dbflags;
 
        slap_callback cb = { NULL };
        SlapReply       rs_modify = {REP_RESULT};
@@ -2405,7 +2405,10 @@ syncrepl_updateCookie(
        /* update contextCSN */
        op->o_msgid = SLAP_SYNC_UPDATE_MSGID;
        op->orm_modlist = &mod;
+       dbflags = SLAP_DBFLAGS(op->o_bd);
+       SLAP_DBFLAGS(op->o_bd) |= SLAP_DBFLAG_NOLASTMOD;
        rc = be->be_modify( op, &rs_modify );
+       SLAP_DBFLAGS(op->o_bd) = dbflags;
        op->o_msgid = 0;
 
        if ( rs_modify.sr_err != LDAP_SUCCESS ) {
@@ -2892,6 +2895,14 @@ parse_syncrepl_line(
                                Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
                                return -1;
                        }
+                       if ( select_backend( &si->si_base, 0, 0 ) != c->be ) {
+                               ber_memfree( si->si_base.bv_val );
+                               snprintf( c->msg, sizeof( c->msg ),
+                                       "Base DN \"%s\" is not within the database naming context",
+                                       val );
+                               Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
+                               return -1;
+                       }
                        gots |= GOT_BASE;
                } else if ( !strncasecmp( c->argv[ i ], LOGBASESTR "=",
                                        STRLENOF( LOGBASESTR "=" ) ) )