]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/syncrepl.c
Fix one time memory leaks
[openldap] / servers / slapd / syncrepl.c
index 68dcf4e0e481b517e317879ad0435ae50bd45424..901e65433c107b16ade6b1cd16ea921864656cdc 100644 (file)
@@ -91,7 +91,7 @@ typedef struct syncinfo_s {
 
 static int syncuuid_cmp( const void *, const void * );
 static void avl_ber_bvfree( void * );
-static void syncrepl_del_nonpresent( Operation *, syncinfo_t *, BerVarray );
+static void syncrepl_del_nonpresent( Operation *, syncinfo_t *, BerVarray, struct berval * );
 static int syncrepl_message_to_op(
                                        syncinfo_t *, Operation *, LDAPMessage * );
 static int syncrepl_message_to_entry(
@@ -797,11 +797,6 @@ do_syncrep2(
                                                &syncCookie_req.ctxcsn, &syncCookie.ctxcsn,
                                                &text );
                                }
-                               if ( !BER_BVISNULL( &syncCookie.ctxcsn ) &&
-                                       match < 0 && err == LDAP_SUCCESS )
-                               {
-                                       syncrepl_updateCookie( si, op, psub, &syncCookie );
-                               }
                                if ( rctrls ) {
                                        ldap_controls_free( rctrls );
                                }
@@ -813,12 +808,17 @@ do_syncrep2(
                                        if ( refreshDeletes == 0 && match < 0 &&
                                                err == LDAP_SUCCESS )
                                        {
-                                               syncrepl_del_nonpresent( op, si, NULL );
+                                               syncrepl_del_nonpresent( op, si, NULL, &syncCookie.ctxcsn );
                                        } else {
                                                avl_free( si->si_presentlist, avl_ber_bvfree );
                                                si->si_presentlist = NULL;
                                        }
                                }
+                               if ( !BER_BVISNULL( &syncCookie.ctxcsn ) &&
+                                       match < 0 && err == LDAP_SUCCESS )
+                               {
+                                       syncrepl_updateCookie( si, op, psub, &syncCookie );
+                               }
                                if ( err == LDAP_SUCCESS
                                        && si->si_logstate == SYNCLOG_FALLBACK ) {
                                        si->si_logstate = SYNCLOG_LOGGING;
@@ -905,7 +905,8 @@ do_syncrep2(
                                                ber_scanf( ber, "[W]", &syncUUIDs );
                                                ber_scanf( ber, /*"{"*/ "}" );
                                                if ( refreshDeletes ) {
-                                                       syncrepl_del_nonpresent( op, si, syncUUIDs );
+                                                       syncrepl_del_nonpresent( op, si, syncUUIDs,
+                                                               &syncCookie.ctxcsn );
                                                        ber_bvarray_free_x( syncUUIDs, op->o_tmpmemctx );
                                                } else {
                                                        for ( i = 0; !BER_BVISNULL( &syncUUIDs[i] ); i++ ) {
@@ -918,6 +919,7 @@ do_syncrep2(
                                                        }
                                                        slap_sl_free( syncUUIDs, op->o_tmpmemctx );
                                                }
+                                               slap_sync_cookie_free( &syncCookie, 0 );
                                                break;
                                        default:
                                                Debug( LDAP_DEBUG_ANY,
@@ -940,15 +942,13 @@ do_syncrep2(
                                                        &syncCookie.ctxcsn, &text );
                                        }
 
-                                       if ( !BER_BVISNULL( &syncCookie.ctxcsn ) &&
-                                               match < 0 )
-                                       {
-                                               syncrepl_updateCookie( si, op, psub, &syncCookie);
-                                       }
-
-                                       if ( si->si_refreshPresent == 1 ) {
-                                               if ( match < 0 ) {
-                                                       syncrepl_del_nonpresent( op, si, NULL );
+                                       if ( match < 0 ) {
+                                               if ( si->si_refreshPresent == 1 ) {
+                                                       syncrepl_del_nonpresent( op, si, NULL, &syncCookie.ctxcsn );
+                                               }
+                                               if ( !BER_BVISNULL( &syncCookie.ctxcsn ))
+                                               {
+                                                       syncrepl_updateCookie( si, op, psub, &syncCookie);
                                                }
                                        } 
 
@@ -1338,6 +1338,7 @@ syncrepl_message_to_op(
        }
 
        op->o_callback = &cb;
+       slap_op_time( &op->o_time, &op->o_tincr );
 
        switch( op->o_tag ) {
        case LDAP_REQ_ADD:
@@ -1748,8 +1749,25 @@ syncrepl_entry(
                        ber_memfree( a->a_vals[0].bv_val );
                        ber_dupbv( &a->a_vals[0], &syncUUID_strrep );
                }
+               /* Don't save the contextCSN on the inooming context entry,
+                * we'll write it when syncrepl_updateCookie eventually
+                * gets called. (ITS#4622)
+                */
+               if ( syncstate == LDAP_SYNC_ADD && dn_match( &entry->e_nname,
+                       &be->be_nsuffix[0] )) {
+                       Attribute **ap;
+                       for ( ap = &entry->e_attrs; *ap; ap=&(*ap)->a_next ) {
+                               a = *ap;
+                               if ( a->a_desc == slap_schema.si_ad_contextCSN ) {
+                                       *ap = a->a_next;
+                                       attr_free( a );
+                                       break;
+                               }
+                       }
+               }
        }
 
+       slap_op_time( &op->o_time, &op->o_tincr );
        switch ( syncstate ) {
        case LDAP_SYNC_ADD:
        case LDAP_SYNC_MODIFY:
@@ -1820,6 +1838,7 @@ retry_add:;
                                        be->be_search( &op2, &rs2 );
 
                                        retry = 0;
+                                       slap_op_time( &op->o_time, &op->o_tincr );
                                        goto retry_add;
                                }
                                /* FALLTHRU */
@@ -1862,6 +1881,8 @@ retry_add:;
                                ret = 1;
                                goto done;
                        }
+                       if ( dni.wasChanged )
+                               slap_op_time( &op->o_time, &op->o_tincr );
                }
                if ( dni.wasChanged ) {
                        Modifications *mod, *modhead = NULL;
@@ -1993,7 +2014,8 @@ static void
 syncrepl_del_nonpresent(
        Operation *op,
        syncinfo_t *si,
-       BerVarray uuids )
+       BerVarray uuids,
+       struct berval *cookiecsn )
 {
        Backend* be = op->o_bd;
        slap_callback   cb = { NULL };
@@ -2005,6 +2027,7 @@ syncrepl_del_nonpresent(
        AttributeName   an[2];
 
        struct berval pdn = BER_BVNULL;
+       struct berval csn;
 
        op->o_req_dn = si->si_base;
        op->o_req_ndn = si->si_base;
@@ -2071,7 +2094,12 @@ syncrepl_del_nonpresent(
 
        if ( !LDAP_LIST_EMPTY( &si->si_nonpresentlist ) ) {
 
-               slap_queue_csn( op, &si->si_syncCookie.ctxcsn );
+               if ( cookiecsn && !BER_BVISNULL( cookiecsn ))
+                       csn = *cookiecsn;
+               else
+                       csn = si->si_syncCookie.ctxcsn;
+
+               slap_queue_csn( op, &csn );
 
                np_list = LDAP_LIST_FIRST( &si->si_nonpresentlist );
                while ( np_list != NULL ) {
@@ -3148,8 +3176,14 @@ add_syncrepl(
        int     rc = 0;
 
        if ( !( c->be->be_search && c->be->be_add && c->be->be_modify && c->be->be_delete ) ) {
-               Debug( LDAP_DEBUG_ANY, "%s: database %s does not support operations "
-                       "required for syncrepl\n", c->log, c->be->be_type, 0 );
+               snprintf( c->msg, sizeof(c->msg), "database %s does not support "
+                       "operations required for syncrepl", c->be->be_type );
+               Debug( LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
+               return 1;
+       }
+       if ( BER_BVISEMPTY( &c->be->be_rootdn )) {
+               strcpy( c->msg, "rootDN must be defined before syncrepl may be used" );
+               Debug( LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 );
                return 1;
        }
        si = (syncinfo_t *) ch_calloc( 1, sizeof( syncinfo_t ) );