]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/overlays/rwm.c
Merge remote branch 'mdb/mdb.master'
[openldap] / servers / slapd / overlays / rwm.c
index 882fbe38588c9623c740c5a4443e9cc367141029..cf8b1da67f8013929b306341493ec40db3241025 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 2003-2010 The OpenLDAP Foundation.
+ * Copyright 2003-2011 The OpenLDAP Foundation.
  * Portions Copyright 2003 Pierangelo Masarati.
  * All rights reserved.
  *
@@ -34,6 +34,8 @@ typedef struct rwm_op_state {
        struct berval ro_ndn;
        struct berval r_dn;
        struct berval r_ndn;
+       struct berval rx_dn;
+       struct berval rx_ndn;
        AttributeName *mapped_attrs;
        OpRequest o_request;
 } rwm_op_state;
@@ -52,30 +54,46 @@ rwm_send_entry( Operation *op, SlapReply *rs );
 static void
 rwm_op_rollback( Operation *op, SlapReply *rs, rwm_op_state *ros )
 {
-       if ( !BER_BVISNULL( &ros->ro_dn ) ) {
-               op->o_req_dn = ros->ro_dn;
-       }
-       if ( !BER_BVISNULL( &ros->ro_ndn ) ) {
-               op->o_req_ndn = ros->ro_ndn;
-       }
+       /* in case of successful extended operation cleanup
+        * gets called *after* (ITS#6632); this hack counts
+        * on others to cleanup our o_req_dn/o_req_ndn,
+        * while we cleanup theirs. */
+       if ( ros->r_tag == LDAP_REQ_EXTENDED && rs->sr_err == LDAP_SUCCESS ) {
+               if ( !BER_BVISNULL( &ros->rx_dn ) ) {
+                       ch_free( ros->rx_dn.bv_val );
+               }
+               if ( !BER_BVISNULL( &ros->rx_ndn ) ) {
+                       ch_free( ros->rx_ndn.bv_val );
+               }
 
-       if ( !BER_BVISNULL( &ros->r_dn )
-               && ros->r_dn.bv_val != ros->ro_dn.bv_val )
-       {
-               assert( ros->r_dn.bv_val != ros->r_ndn.bv_val );
-               ch_free( ros->r_dn.bv_val );
-               BER_BVZERO( &ros->r_dn );
-       }
+       } else {
+               if ( !BER_BVISNULL( &ros->ro_dn ) ) {
+                       op->o_req_dn = ros->ro_dn;
+               }
+               if ( !BER_BVISNULL( &ros->ro_ndn ) ) {
+                       op->o_req_ndn = ros->ro_ndn;
+               }
 
-       if ( !BER_BVISNULL( &ros->r_ndn )
-               && ros->r_ndn.bv_val != ros->ro_ndn.bv_val )
-       {
-               ch_free( ros->r_ndn.bv_val );
-               BER_BVZERO( &ros->r_ndn );
+               if ( !BER_BVISNULL( &ros->r_dn )
+                       && ros->r_dn.bv_val != ros->ro_dn.bv_val )
+               {
+                       assert( ros->r_dn.bv_val != ros->r_ndn.bv_val );
+                       ch_free( ros->r_dn.bv_val );
+               }
+
+               if ( !BER_BVISNULL( &ros->r_ndn )
+                       && ros->r_ndn.bv_val != ros->ro_ndn.bv_val )
+               {
+                       ch_free( ros->r_ndn.bv_val );
+               }
        }
 
+       BER_BVZERO( &ros->r_dn );
+       BER_BVZERO( &ros->r_ndn );
        BER_BVZERO( &ros->ro_dn );
        BER_BVZERO( &ros->ro_ndn );
+       BER_BVZERO( &ros->rx_dn );
+       BER_BVZERO( &ros->rx_ndn );
 
        switch( ros->r_tag ) {
        case LDAP_REQ_COMPARE:
@@ -104,9 +122,9 @@ rwm_op_rollback( Operation *op, SlapReply *rs, rwm_op_state *ros )
                }
                break;
        case LDAP_REQ_SEARCH:
-               ch_free( ros->mapped_attrs );
+               op->o_tmpfree( ros->mapped_attrs, op->o_tmpmemctx );
                filter_free_x( op, op->ors_filter, 1 );
-               ch_free( op->ors_filterstr.bv_val );
+               op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx );
                op->ors_attrs = ros->ors_attrs;
                op->ors_filter = ros->ors_filter;
                op->ors_filterstr = ros->ors_filterstr;
@@ -122,7 +140,7 @@ rwm_op_rollback( Operation *op, SlapReply *rs, rwm_op_state *ros )
 #if 0
                        ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
                        /* too late, c_mutex released */
-                       fprintf( stderr, "*** DN: \"%s\" => \"%s\"\n",
+                       Debug( LDAP_DEBUG_ANY, "*** DN: \"%s\" => \"%s\"\n",
                                op->o_conn->c_ndn.bv_val,
                                op->o_req_ndn.bv_val );
                        ber_bvreplace( &op->o_conn->c_ndn,
@@ -154,9 +172,9 @@ rwm_op_cleanup( Operation *op, SlapReply *rs )
 }
 
 static rwm_op_cb *
-rwm_callback_get( Operation *op, SlapReply *rs )
+rwm_callback_get( Operation *op )
 {
-       rwm_op_cb       *roc = NULL;
+       rwm_op_cb       *roc;
 
        roc = op->o_tmpalloc( sizeof( struct rwm_op_cb ), op->o_tmpmemctx );
        roc->cb.sc_cleanup = rwm_op_cleanup;
@@ -166,9 +184,12 @@ rwm_callback_get( Operation *op, SlapReply *rs )
        roc->ros.r_tag = op->o_tag;
        roc->ros.ro_dn = op->o_req_dn;
        roc->ros.ro_ndn = op->o_req_ndn;
-       roc->ros.o_request = op->o_request;
        BER_BVZERO( &roc->ros.r_dn );
        BER_BVZERO( &roc->ros.r_ndn );
+       BER_BVZERO( &roc->ros.rx_dn );
+       BER_BVZERO( &roc->ros.rx_ndn );
+       roc->ros.mapped_attrs = NULL;
+       roc->ros.o_request = op->o_request;
 
        return roc;
 }
@@ -228,6 +249,11 @@ rwm_op_dn_massage( Operation *op, SlapReply *rs, void *cookie,
        assert( BER_BVISNULL( &ros->r_ndn ) );
        ros->r_ndn = ndn;
 
+       if ( ros->r_tag == LDAP_REQ_EXTENDED ) {
+               ros->rx_dn = ros->r_dn;
+               ros->rx_ndn = ros->r_ndn;
+       }
+
        return LDAP_SUCCESS;
 }
 
@@ -244,7 +270,7 @@ rwm_op_add( Operation *op, SlapReply *rs )
        char                    *olddn = op->o_req_dn.bv_val;
        int                     isupdate;
 
-       rwm_op_cb               *roc = rwm_callback_get( op, rs );
+       rwm_op_cb               *roc = rwm_callback_get( op );
 
        rc = rwm_op_dn_massage( op, rs, "addDN", &roc->ros );
        if ( rc != LDAP_SUCCESS ) {
@@ -387,7 +413,7 @@ rwm_op_bind( Operation *op, SlapReply *rs )
        slap_overinst           *on = (slap_overinst *) op->o_bd->bd_info;
        int                     rc;
 
-       rwm_op_cb               *roc = rwm_callback_get( op, rs );
+       rwm_op_cb               *roc = rwm_callback_get( op );
 
        rc = rwm_op_dn_massage( op, rs, "bindDN", &roc->ros );
        if ( rc != LDAP_SUCCESS ) {
@@ -423,7 +449,7 @@ rwm_op_compare( Operation *op, SlapReply *rs )
        int                     rc;
        struct berval           mapped_vals[2] = { BER_BVNULL, BER_BVNULL };
 
-       rwm_op_cb               *roc = rwm_callback_get( op, rs );
+       rwm_op_cb               *roc = rwm_callback_get( op );
 
        rc = rwm_op_dn_massage( op, rs, "compareDN", &roc->ros );
        if ( rc != LDAP_SUCCESS ) {
@@ -508,7 +534,7 @@ rwm_op_delete( Operation *op, SlapReply *rs )
        slap_overinst           *on = (slap_overinst *) op->o_bd->bd_info;
        int                     rc;
 
-       rwm_op_cb               *roc = rwm_callback_get( op, rs );
+       rwm_op_cb               *roc = rwm_callback_get( op );
 
        rc = rwm_op_dn_massage( op, rs, "deleteDN", &roc->ros );
        if ( rc != LDAP_SUCCESS ) {
@@ -533,7 +559,7 @@ rwm_op_modify( Operation *op, SlapReply *rs )
        Modifications           **mlp;
        int                     rc;
 
-       rwm_op_cb               *roc = rwm_callback_get( op, rs );
+       rwm_op_cb               *roc = rwm_callback_get( op );
 
        rc = rwm_op_dn_massage( op, rs, "modifyDN", &roc->ros );
        if ( rc != LDAP_SUCCESS ) {
@@ -575,7 +601,7 @@ rwm_op_modify( Operation *op, SlapReply *rs )
                                        &mapping, RWM_MAP );
                        if ( drop_missing || ( mapping != NULL && BER_BVISNULL( &mapping->m_dst ) ) )
                        {
-                               goto cleanup_mod;
+                               goto skip_mod;
                        }
                }
 
@@ -670,6 +696,10 @@ next_mod:;
                mlp = &ml->sml_next;
                continue;
 
+skip_mod:;
+               *mlp = (*mlp)->sml_next;
+               continue;
+
 cleanup_mod:;
                ml = *mlp;
                *mlp = (*mlp)->sml_next;
@@ -692,7 +722,7 @@ rwm_op_modrdn( Operation *op, SlapReply *rs )
        int                     rc;
        dncookie                dc;
 
-       rwm_op_cb               *roc = rwm_callback_get( op, rs );
+       rwm_op_cb               *roc = rwm_callback_get( op );
 
        if ( op->orr_newSup ) {
                struct berval   nnewSup = BER_BVNULL;
@@ -836,12 +866,7 @@ rwm_entry_get_rw( Operation *op, struct berval *ndn,
        ObjectClass *oc, AttributeDescription *at, int rw, Entry **ep )
 {
        slap_overinst           *on = (slap_overinst *) op->o_bd->bd_info;
-       struct ldaprwmap        *rwmap = 
-                       (struct ldaprwmap *)on->on_bi.bi_private;
-
        int                     rc;
-       dncookie                dc;
-
        BackendDB               db;
        Operation               op2;
        SlapReply               rs = { REP_SEARCH };
@@ -886,9 +911,16 @@ rwm_entry_get_rw( Operation *op, struct berval *ndn,
                /* duplicate & release */
                op2.o_bd->bd_info = (BackendInfo *)on;
                rc = rwm_send_entry( &op2, &rs );
+               RS_ASSERT( rs.sr_flags & REP_ENTRY_MUSTFLUSH );
                if ( rc == SLAP_CB_CONTINUE ) {
                        *ep = rs.sr_entry;
                        rc = LDAP_SUCCESS;
+               } else {
+                       assert( rc != LDAP_SUCCESS && rs.sr_entry == *ep );
+                       *ep = NULL;
+                       op2.o_bd->bd_info = (BackendInfo *)on->on_info;
+                       be_entry_release_r( &op2, rs.sr_entry );
+                       op2.o_bd->bd_info = (BackendInfo *)on;
                }
        }
 
@@ -916,7 +948,7 @@ rwm_op_search( Operation *op, SlapReply *rs )
 
        char                    *text = NULL;
 
-       rwm_op_cb               *roc = rwm_callback_get( op, rs );
+       rwm_op_cb               *roc = rwm_callback_get( op );
 
        rc = rewrite_session_var_set( rwmap->rwm_rw, op->o_conn,
                "searchFilter", op->ors_filterstr.bv_val );
@@ -951,7 +983,7 @@ rwm_op_search( Operation *op, SlapReply *rs )
        op->ors_filter = f;
        op->ors_filterstr = fstr;
 
-       rc = rwm_map_attrnames( &rwmap->rwm_at, &rwmap->rwm_oc,
+       rc = rwm_map_attrnames( op, &rwmap->rwm_at, &rwmap->rwm_oc,
                        op->ors_attrs, &an, RWM_MAP );
        if ( rc != LDAP_SUCCESS ) {
                text = "attribute list mapping error";
@@ -978,7 +1010,7 @@ error_return:;
        }
 
        if ( !BER_BVISNULL( &fstr ) ) {
-               ch_free( fstr.bv_val );
+               op->o_tmpfree( fstr.bv_val, op->o_tmpmemctx );
        }
 
        rwm_op_rollback( op, rs, &roc->ros );
@@ -1035,7 +1067,7 @@ rwm_exop_passwd( Operation *op, SlapReply *rs )
                ber_dupbv_x( &op->o_req_ndn, &op->o_ndn, op->o_tmpmemctx );
        }
 
-       roc = rwm_callback_get( op, rs );
+       roc = rwm_callback_get( op );
 
        rc = rwm_op_dn_massage( op, rs, "extendedDN", &roc->ros );
        if ( rc != LDAP_SUCCESS ) {
@@ -1107,7 +1139,7 @@ rwm_extended( Operation *op, SlapReply *rs )
                }
        }
 
-       roc = rwm_callback_get( op, rs );
+       roc = rwm_callback_get( op );
 
        rc = rwm_op_dn_massage( op, rs, "extendedDN", &roc->ros );
        if ( rc != LDAP_SUCCESS ) {
@@ -1122,7 +1154,7 @@ rwm_extended( Operation *op, SlapReply *rs )
        return SLAP_CB_CONTINUE;
 }
 
-static int
+static void
 rwm_matched( Operation *op, SlapReply *rs )
 {
        slap_overinst           *on = (slap_overinst *) op->o_bd->bd_info;
@@ -1134,7 +1166,7 @@ rwm_matched( Operation *op, SlapReply *rs )
        int                     rc;
 
        if ( rs->sr_matched == NULL ) {
-               return SLAP_CB_CONTINUE;
+               return;
        }
 
        dc.rwmap = rwmap;
@@ -1147,10 +1179,8 @@ rwm_matched( Operation *op, SlapReply *rs )
        if ( rc != LDAP_SUCCESS ) {
                rs->sr_err = rc;
                rs->sr_text = "Rewrite error";
-               return 1;
-       }
 
-       if ( mdn.bv_val != dn.bv_val ) {
+       } else if ( mdn.bv_val != dn.bv_val ) {
                if ( rs->sr_flags & REP_MATCHED_MUSTBEFREED ) {
                        ch_free( (void *)rs->sr_matched );
 
@@ -1159,8 +1189,6 @@ rwm_matched( Operation *op, SlapReply *rs )
                }
                rs->sr_matched = mdn.bv_val;
        }
-       
-       return SLAP_CB_CONTINUE;
 }
 
 static int
@@ -1431,6 +1459,7 @@ cleanup_attr:;
        return 0;
 }
 
+/* Should return SLAP_CB_CONTINUE or failure, never LDAP_SUCCESS. */
 static int
 rwm_send_entry( Operation *op, SlapReply *rs )
 {
@@ -1439,7 +1468,6 @@ rwm_send_entry( Operation *op, SlapReply *rs )
                        (struct ldaprwmap *)on->on_bi.bi_private;
 
        Entry                   *e = NULL;
-       slap_mask_t             flags;
        struct berval           dn = BER_BVNULL,
                                ndn = BER_BVNULL;
        dncookie                dc;
@@ -1456,7 +1484,6 @@ rwm_send_entry( Operation *op, SlapReply *rs )
        dc.ctx = "searchEntryDN";
 
        e = rs->sr_entry;
-       flags = rs->sr_flags;
        if ( !( rs->sr_flags & REP_ENTRY_MODIFIABLE ) ) {
                /* FIXME: all we need to duplicate are:
                 * - dn
@@ -1464,15 +1491,17 @@ rwm_send_entry( Operation *op, SlapReply *rs )
                 * - attributes that are requested
                 * - no values if attrsonly is set
                 */
-
                e = entry_dup( e );
                if ( e == NULL ) {
                        rc = LDAP_NO_MEMORY;
                        goto fail;
                }
-
-               flags &= ~REP_ENTRY_MUSTRELEASE;
-               flags |= ( REP_ENTRY_MODIFIABLE | REP_ENTRY_MUSTBEFREED );
+       } else if ( rs->sr_flags & REP_ENTRY_MUSTRELEASE ) {
+               /* ITS#6423: REP_ENTRY_MUSTRELEASE incompatible
+                * with REP_ENTRY_MODIFIABLE */
+               RS_ASSERT( 0 );
+               rc = 1;
+               goto fail;
        }
 
        /*
@@ -1504,22 +1533,21 @@ rwm_send_entry( Operation *op, SlapReply *rs )
         * to return, and remap them accordingly */
        (void)rwm_attrs( op, rs, &e->e_attrs, 1 );
 
-       if ( rs->sr_flags & REP_ENTRY_MUSTRELEASE ) {
-               /* ITS#6423: REP_ENTRY_MUSTRELEASE incompatible
-                * with REP_ENTRY_MODIFIABLE */
-               if ( rs->sr_entry == e ) {
-                       rc = 1;
-                       goto fail;
+       if ( e != rs->sr_entry ) {
+               /* Reimplementing rs_replace_entry(), I suppose to
+                * bypass our own dubious rwm_entry_release_rw() */
+               if ( rs->sr_flags & REP_ENTRY_MUSTRELEASE ) {
+                       rs->sr_flags ^= REP_ENTRY_MUSTRELEASE;
+                       op->o_bd->bd_info = (BackendInfo *)on->on_info;
+                       be_entry_release_r( op, rs->sr_entry );
+                       op->o_bd->bd_info = (BackendInfo *)on;
+               } else if ( rs->sr_flags & REP_ENTRY_MUSTBEFREED ) {
+                       entry_free( rs->sr_entry );
                }
-
-               op->o_bd->bd_info = (BackendInfo *)on->on_info;
-               be_entry_release_r( op, rs->sr_entry );
-               op->o_bd->bd_info = (BackendInfo *)on;
+               rs->sr_entry = e;
+               rs->sr_flags |= REP_ENTRY_MODIFIABLE | REP_ENTRY_MUSTBEFREED;
        }
 
-       rs->sr_entry = e;
-       rs->sr_flags = flags;
-
        return SLAP_CB_CONTINUE;
 
 fail:;
@@ -1626,12 +1654,12 @@ rwm_suffixmassage_config(
         */
        if ( argc == 2 ) {
                if ( be->be_suffix == NULL ) {
-                       fprintf( stderr, "%s: line %d: "
+                       Debug( LDAP_DEBUG_ANY, "%s: line %d: "
                                       " \"suffixMassage [<suffix>]"
                                       " <massaged suffix>\" without "
                                       "<suffix> part requires database "
                                       "suffix be defined first.\n",
-                               fname, lineno );
+                               fname, lineno, 0 );
                        return 1;
                }
                bvnc = be->be_suffix[ 0 ];
@@ -1642,22 +1670,22 @@ rwm_suffixmassage_config(
                massaged = 2;
 
        } else  {
-               fprintf( stderr, "%s: line %d: syntax is"
+               Debug( LDAP_DEBUG_ANY, "%s: line %d: syntax is"
                               " \"suffixMassage [<suffix>]"
                               " <massaged suffix>\"\n",
-                       fname, lineno );
+                       fname, lineno, 0 );
                return 1;
        }
 
        if ( dnPrettyNormal( NULL, &bvnc, &pvnc, &nvnc, NULL ) != LDAP_SUCCESS ) {
-               fprintf( stderr, "%s: line %d: suffix DN %s is invalid\n",
+               Debug( LDAP_DEBUG_ANY, "%s: line %d: suffix DN %s is invalid\n",
                        fname, lineno, bvnc.bv_val );
                return 1;
        }
 
        ber_str2bv( argv[ massaged ], 0, 0, &brnc );
        if ( dnPrettyNormal( NULL, &brnc, &prnc, &nrnc, NULL ) != LDAP_SUCCESS ) {
-               fprintf( stderr, "%s: line %d: suffix DN %s is invalid\n",
+               Debug( LDAP_DEBUG_ANY, "%s: line %d: suffix DN %s is invalid\n",
                                fname, lineno, brnc.bv_val );
                free( nvnc.bv_val );
                free( pvnc.bv_val );
@@ -1729,20 +1757,18 @@ rwm_response( Operation *op, SlapReply *rs )
                        dc.rs = NULL; 
                        dc.ctx = "referralDN";
                        rc = rwm_referral_result_rewrite( &dc, rs->sr_ref );
+                       /* FIXME: impossible, so far */
                        if ( rc != LDAP_SUCCESS ) {
-                               rc = 1;
+                               rs->sr_err = rc;
                                break;
                        }
                }
-               rc = rwm_matched( op, rs );
-               break;
 
-       default:
-               rc = SLAP_CB_CONTINUE;
+               rwm_matched( op, rs );
                break;
        }
 
-       return rc;
+       return SLAP_CB_CONTINUE;
 }
 
 static int
@@ -1776,9 +1802,9 @@ rwm_db_config(
 
        } else if ( strcasecmp( argv[0], "t-f-support" ) == 0 ) {
                if ( argc != 2 ) {
-                       fprintf( stderr,
+                       Debug( LDAP_DEBUG_ANY,
                "%s: line %d: \"t-f-support {no|yes|discover}\" needs 1 argument.\n",
-                                       fname, lineno );
+                                       fname, lineno, 0 );
                        return( 1 );
                }
 
@@ -1790,17 +1816,17 @@ rwm_db_config(
 
                /* TODO: not implemented yet */
                } else if ( strcasecmp( argv[ 1 ], "discover" ) == 0 ) {
-                       fprintf( stderr,
+                       Debug( LDAP_DEBUG_ANY,
                "%s: line %d: \"discover\" not supported yet "
                "in \"t-f-support {no|yes|discover}\".\n",
-                                       fname, lineno );
+                                       fname, lineno, 0 );
                        return( 1 );
 #if 0
                        rwmap->rwm_flags |= RWM_F_SUPPORT_T_F_DISCOVER;
 #endif
 
                } else {
-                       fprintf( stderr,
+                       Debug( LDAP_DEBUG_ANY,
        "%s: line %d: unknown value \"%s\" for \"t-f-support {no|yes|discover}\".\n",
                                fname, lineno, argv[ 1 ] );
                        return 1;
@@ -1808,9 +1834,9 @@ rwm_db_config(
 
        } else if ( strcasecmp( argv[0], "normalize-mapped-attrs" ) ==  0 ) {
                if ( argc !=2 ) { 
-                       fprintf( stderr,
+                       Debug( LDAP_DEBUG_ANY,
                "%s: line %d: \"normalize-mapped-attrs {no|yes}\" needs 1 argument.\n",
-                                       fname, lineno );
+                                       fname, lineno, 0 );
                        return( 1 );
                }
 
@@ -2006,6 +2032,7 @@ rwm_bva_rewrite_add(
        return rwm_bva_add( &rwmap->rwm_bva_rewrite, idx, argv );
 }
 
+#ifdef unused
 static int
 rwm_bva_map_add(
        struct ldaprwmap        *rwmap,
@@ -2014,6 +2041,7 @@ rwm_bva_map_add(
 {
        return rwm_bva_add( &rwmap->rwm_bva_map, idx, argv );
 }
+#endif /* unused */
 
 static int
 rwm_info_init( struct rewrite_info ** rwm_rw )
@@ -2114,7 +2142,6 @@ rwm_cf_gen( ConfigArgs *c )
                switch ( c->type ) {
                case RWM_CF_REWRITE:
                        if ( c->valx >= 0 ) {
-                               ConfigArgs ca = { 0 };
                                int i;
 
                                for ( i = 0; !BER_BVISNULL( &rwmap->rwm_bva_rewrite[ i ] ); i++ )
@@ -2139,6 +2166,8 @@ rwm_cf_gen( ConfigArgs *c )
 
                                for ( i = 0; !BER_BVISNULL( &rwmap->rwm_bva_rewrite[ i ] ); i++ )
                                {
+                                       ConfigArgs ca = { 0 };
+
                                        ca.line = rwmap->rwm_bva_rewrite[ i ].bv_val;
                                        ca.argc = 0;
                                        config_fp_parse_line( &ca );
@@ -2282,7 +2311,6 @@ rwm_cf_gen( ConfigArgs *c )
        case RWM_CF_REWRITE:
                if ( c->valx >= 0 ) {
                        struct rewrite_info *rwm_rw = rwmap->rwm_rw;
-                       ConfigArgs ca = { 0 };
                        int i, last;
 
                        for ( last = 0; rwmap->rwm_bva_rewrite && !BER_BVISNULL( &rwmap->rwm_bva_rewrite[ last ] ); last++ )
@@ -2296,6 +2324,8 @@ rwm_cf_gen( ConfigArgs *c )
                        rc = rwm_info_init( &rwmap->rwm_rw );
 
                        for ( i = 0; i < c->valx; i++ ) {
+                               ConfigArgs ca = { 0 };
+
                                ca.line = rwmap->rwm_bva_rewrite[ i ].bv_val;
                                ca.argc = 0;
                                config_fp_parse_line( &ca );
@@ -2344,6 +2374,8 @@ rwm_cf_gen( ConfigArgs *c )
 
                        for ( i = c->valx; rwmap->rwm_bva_rewrite && !BER_BVISNULL( &rwmap->rwm_bva_rewrite[ i ] ); i++ )
                        {
+                               ConfigArgs ca = { 0 };
+
                                ca.line = rwmap->rwm_bva_rewrite[ i ].bv_val;
                                ca.argc = 0;
                                config_fp_parse_line( &ca );