]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-bdb/add.c
Fix ITS#3255, boi_bdb comparisons
[openldap] / servers / slapd / back-bdb / add.c
index a40c68ac8a7b65c1f9c38d199361c9ad8041eec1..6174a516167868d07a9399669df41b0ebf1dd65c 100644 (file)
@@ -27,7 +27,7 @@ bdb_add(Operation *op, SlapReply *rs )
 {
        struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
        struct berval   pdn;
-       Entry           *p;
+       Entry           *p = NULL;
        EntryInfo       *ei;
        char textbuf[SLAP_TEXT_BUFLEN];
        size_t textlen = sizeof textbuf;
@@ -49,6 +49,7 @@ bdb_add(Operation *op, SlapReply *rs )
        Entry           *ctxcsn_e;
        int                     ctxcsn_added = 0;
 
+       LDAPControl **postread_ctrl = NULL;
        LDAPControl *ctrls[SLAP_MAX_RESPONSE_CONTROLS];
        int num_ctrls = 0;
 
@@ -60,6 +61,8 @@ bdb_add(Operation *op, SlapReply *rs )
                op->oq_add.rs_e->e_name.bv_val, 0, 0);
 #endif
 
+       ctrls[num_ctrls] = 0;
+
        /* check entry's schema */
        rs->sr_err = entry_schema_check( op->o_bd, op->oq_add.rs_e,
                NULL, &rs->sr_text, textbuf, textlen );
@@ -447,8 +450,12 @@ retry:     /* transaction retry */
 
        /* post-read */
        if( op->o_postread ) {
+               if( postread_ctrl == NULL ) {
+                       postread_ctrl = &ctrls[num_ctrls++];
+                       ctrls[num_ctrls] = NULL;
+               }
                if ( slap_read_controls( op, rs, op->oq_add.rs_e,
-                       &slap_post_read_bv, &ctrls[num_ctrls] ) )
+                       &slap_post_read_bv, postread_ctrl ) )
                {
 #ifdef NEW_LOGGING
                        LDAP_LOG ( OPERATION, DETAIL1, 
@@ -459,9 +466,6 @@ retry:      /* transaction retry */
 #endif
                        goto return_results;
                }
-               ctrls[++num_ctrls] = NULL;
-               op->o_postread = 0;  /* prevent redo on retry */
-               /* FIXME: should read entry on the last retry */
        }
 
        if ( op->o_noop ) {
@@ -500,8 +504,18 @@ retry:     /* transaction retry */
                        ldap_pvt_thread_rdwr_wlock( &bdb->bi_pslist_rwlock );
                        assert( BEI(e) );
                        LDAP_LIST_FOREACH ( ps_list, &bdb->bi_psearch_list, o_ps_link ) {
-                               bdb_psearch( op, rs, ps_list, e,
-                                       LDAP_PSEARCH_BY_ADD );
+                               rc = bdb_psearch( op, rs, ps_list, e, LDAP_PSEARCH_BY_ADD );
+                               if ( rc ) {
+#ifdef NEW_LOGGING
+                                       LDAP_LOG ( OPERATION, ERR, 
+                                               "bdb_add: persistent search failed (%d,%d)\n",
+                                               rc, rs->sr_err, 0 );
+#else
+                                       Debug( LDAP_DEBUG_TRACE,
+                                               "bdb_add: persistent search failed (%d,%d)\n",
+                                               rc, rs->sr_err, 0 );
+#endif
+                               }
                        }
                        ldap_pvt_thread_rdwr_wunlock( &bdb->bi_pslist_rwlock );
                }
@@ -557,5 +571,9 @@ done:
                op->o_private = NULL;
        }
 
+       if( postread_ctrl != NULL ) {
+               slap_sl_free( (*postread_ctrl)->ldctl_value.bv_val, &op->o_tmpmemctx );
+               slap_sl_free( *postread_ctrl, &op->o_tmpmemctx );
+       }
        return rs->sr_err;
 }