]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/overlays/rwm.c
Use "pcache" to invoke the overlay instead of "proxycache"
[openldap] / servers / slapd / overlays / rwm.c
index 00227172c6c4db13531027568fcdc80d37acff28..85d73d2ad07e030d694d63944a1913689a5f2595 100644 (file)
@@ -73,14 +73,14 @@ rwm_op_dn_massage( Operation *op, SlapReply *rs, void *cookie )
                return LDAP_SUCCESS;
        }
 
-       op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
-       op->o_req_ndn = ndn;
        if ( op->o_req_dn.bv_val != op->o_req_ndn.bv_val ) {
                op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
                op->o_req_dn = dn;
        } else {
                op->o_req_dn = ndn;
        }
+       op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
+       op->o_req_ndn = ndn;
 
        return LDAP_SUCCESS;
 }
@@ -171,8 +171,8 @@ rwm_op_add( Operation *op, SlapReply *rs )
                                }
                        }
 
-                       if ( (*ap)->a_desc->ad_type->sat_syntax
-                                       == slap_schema.si_syn_distinguishedName )
+                       if ( (*ap)->a_desc->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName
+                                       || ( mapping != NULL && mapping->m_dst_ad->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName ) )
                        {
                                /*
                                 * FIXME: rewrite could fail; in this case
@@ -327,7 +327,8 @@ rwm_op_compare( Operation *op, SlapReply *rs )
                        ad = mapping->m_dst_ad;
                }
 
-               if ( op->orc_ava->aa_desc->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName )
+               if ( op->orc_ava->aa_desc->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName
+                               || ( mapping != NULL && mapping->m_dst_ad->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName ) )
                {
                        struct berval   *mapped_valsp[2];
                        
@@ -436,11 +437,11 @@ rwm_op_modify( Operation *op, SlapReply *rs )
                                last--;
 
                                for ( j = 0; !BER_BVISNULL( &(*mlp)->sml_values[ j ] ); j++ ) {
-                                       struct ldapmapping      *mapping = NULL;
-
+                                       struct ldapmapping      *oc_mapping = NULL;
+               
                                        ( void )rwm_mapping( &rwmap->rwm_oc, &(*mlp)->sml_values[ j ],
-                                                       &mapping, RWM_MAP );
-                                       if ( mapping == NULL ) {
+                                                       &oc_mapping, RWM_MAP );
+                                       if ( oc_mapping == NULL ) {
                                                if ( rwmap->rwm_at.drop_missing ) {
                                                        /* FIXME: we allow to remove objectClasses as well;
                                                         * if the resulting entry is inconsistent, that's
@@ -457,13 +458,13 @@ rwm_op_modify( Operation *op, SlapReply *rs )
        
                                        } else {
                                                ch_free( (*mlp)->sml_values[ j ].bv_val );
-                                               ber_dupbv( &(*mlp)->sml_values[ j ], &mapping->m_dst );
+                                               ber_dupbv( &(*mlp)->sml_values[ j ], &oc_mapping->m_dst );
                                        }
                                }
 
                        } else {
-                               if ( (*mlp)->sml_desc->ad_type->sat_syntax ==
-                                               slap_schema.si_syn_distinguishedName )
+                               if ( (*mlp)->sml_desc->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName
+                                               || ( mapping != NULL && mapping->m_dst_ad->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName ) )
                                {
 #ifdef ENABLE_REWRITE
                                        rc = rwm_dnattr_rewrite( op, rs, "modifyAttrDN",
@@ -516,7 +517,6 @@ cleanup_mod:;
                free( ml );
        }
 
-       /* TODO: rewrite attribute types, values of DN-valued attributes ... */
        return SLAP_CB_CONTINUE;
 }
 
@@ -822,7 +822,7 @@ rwm_attrs( Operation *op, SlapReply *rs, Attribute** a_first, int stripEntryDN )
         * about duplicate values?) */
        isupdate = be_shadow_update( op );
        for ( ap = a_first; *ap; ) {
-               struct ldapmapping      *mapping;
+               struct ldapmapping      *mapping = NULL;
                int                     drop_missing;
                int                     last;
                Attribute               *a;
@@ -832,6 +832,13 @@ rwm_attrs( Operation *op, SlapReply *rs, Attribute** a_first, int stripEntryDN )
                        /* go on */ ;
                        
                } else {
+                       if ( op->ors_attrs != NULL && 
+                                       !SLAP_USERATTRS( rs->sr_attr_flags ) &&
+                                       !ad_inlist( (*ap)->a_desc, op->ors_attrs ) )
+                       {
+                               goto cleanup_attr;
+                       }
+
                        drop_missing = rwm_mapping( &rwmap->rwm_at,
                                        &(*ap)->a_desc->ad_cname, &mapping, RWM_REMAP );
                        if ( drop_missing || ( mapping != NULL && BER_BVISEMPTY( &mapping->m_dst ) ) )
@@ -842,13 +849,6 @@ rwm_attrs( Operation *op, SlapReply *rs, Attribute** a_first, int stripEntryDN )
                        if ( mapping != NULL ) {
                                (*ap)->a_desc = mapping->m_dst_ad;
                        }
-
-                       if ( op->ors_attrs != NULL && 
-                                       !SLAP_USERATTRS( rs->sr_attr_flags ) &&
-                                       !ad_inlist( (*ap)->a_desc, op->ors_attrs ) )
-                       {
-                               goto cleanup_attr;
-                       }
                }
 
                if ( (*ap)->a_desc == slap_schema.si_ad_entryDN ) {
@@ -868,7 +868,7 @@ rwm_attrs( Operation *op, SlapReply *rs, Attribute** a_first, int stripEntryDN )
                        /* just count */ ;
 
                if ( last == 0 ) {
-                       /* empty? for now, we leave it in place */
+                       /* empty? leave it in place because of attrsonly and vlv */
                        goto next_attr;
                }
                last--;
@@ -915,8 +915,8 @@ rwm_attrs( Operation *op, SlapReply *rs, Attribute** a_first, int stripEntryDN )
                 * everything pass thru the ldap backend. */
                /* FIXME: handle distinguishedName-like syntaxes, like
                 * nameAndOptionalUID */
-               } else if ( (*ap)->a_desc->ad_type->sat_syntax ==
-                               slap_schema.si_syn_distinguishedName )
+               } else if ( (*ap)->a_desc->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName
+                               || ( mapping != NULL && mapping->m_src_ad->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName ) )
                {
 #ifdef ENABLE_REWRITE
                        dc.ctx = "searchAttrDN";
@@ -1045,6 +1045,18 @@ rwm_send_entry( Operation *op, SlapReply *rs )
        return SLAP_CB_CONTINUE;
 
 fail:;
+       if ( e != NULL && e != rs->sr_entry ) {
+               if ( e->e_name.bv_val == dn.bv_val ) {
+                       BER_BVZERO( &e->e_name );
+               }
+
+               if ( e->e_nname.bv_val == ndn.bv_val ) {
+                       BER_BVZERO( &e->e_nname );
+               }
+
+               entry_free( e );
+       }
+
        if ( !BER_BVISNULL( &dn ) ) {
                ch_free( dn.bv_val );
        }
@@ -1053,10 +1065,6 @@ fail:;
                ch_free( ndn.bv_val );
        }
 
-       if ( e != NULL && e != rs->sr_entry ) {
-               entry_free( e );
-       }
-
        return rc;
 }
 
@@ -1253,7 +1261,9 @@ rwm_response( Operation *op, SlapReply *rs )
        switch( op->o_tag ) {
        case LDAP_REQ_SEARCH:
                /* Note: the operation attrs are remapped */
-               if ( op->ors_attrs != NULL && op->ors_attrs != rs->sr_attrs )
+               if ( rs->sr_type == REP_RESULT
+                               && op->ors_attrs != NULL
+                               && op->ors_attrs != rs->sr_attrs )
                {
                        ch_free( op->ors_attrs );
                        op->ors_attrs = rs->sr_attrs;
@@ -1308,6 +1318,10 @@ rwm_db_config(
     char       **argv
 )
 {
+       slap_overinst           *on = (slap_overinst *) be->bd_info;
+       struct ldaprwmap        *rwmap = 
+                       (struct ldaprwmap *)on->on_bi.bi_private;
+
        int             rc = 0;
        char            *argv0 = NULL;
 
@@ -1325,6 +1339,33 @@ rwm_db_config(
        } else if ( strcasecmp( argv[0], "suffixmassage" ) == 0 ) {
                rc = rwm_suffixmassage_config( be, fname, lineno, argc, argv );
 
+       } else if ( strcasecmp( argv[0], "t-f-support" ) == 0 ) {
+               if ( argc != 2 ) {
+                       fprintf( stderr,
+               "%s: line %d: \"t-f-support {no|yes|discover}\" needs 1 argument.\n",
+                                       fname, lineno );
+                       return( 1 );
+               }
+
+               if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
+                       rwmap->rwm_flags &= ~(RWM_F_SUPPORT_T_F|RWM_F_SUPPORT_T_F_DISCOVER);
+
+               } else if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
+                       rwmap->rwm_flags |= RWM_F_SUPPORT_T_F;
+
+#if 0
+               /* TODO: not implemented yet */
+               } else if ( strcasecmp( argv[ 1 ], "discover" ) == 0 ) {
+                       rwmap->rwm_flags |= RWM_F_SUPPORT_T_F_DISCOVER;
+#endif
+
+               } else {
+                       fprintf( stderr,
+       "%s: line %d: unknown value \"%s\" for \"t-f-support {no|yes|discover}\".\n",
+                               fname, lineno, argv[ 1 ] );
+                       return 1;
+               }
+
        } else {
                rc = SLAP_CONF_UNKNOWN;
        }