]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/overlays/rwm.c
trim listed modules
[openldap] / servers / slapd / overlays / rwm.c
index 507dac309ed3394bb8de4ecd5e39d8d958b486b9..4e87d36dd2b05098e299f092f6df37b6f482f5ab 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 2003-2006 The OpenLDAP Foundation.
+ * Copyright 2003-2007 The OpenLDAP Foundation.
  * Portions Copyright 2003 Pierangelo Masarati.
  * All rights reserved.
  *
@@ -27,6 +27,7 @@
 #include "rwm.h"
 
 typedef struct rwm_op_state {
+       ber_tag_t r_tag;
        struct berval ro_dn;
        struct berval ro_ndn;
        struct berval r_dn;
@@ -42,24 +43,14 @@ typedef struct rwm_op_cb {
        rwm_op_state ros;
 } rwm_op_cb;
 
-static rwm_op_cb rwm_cb;
-
-static void
-rwm_keyfree(
-       void            *key,
-       void            *data )
-{
-       ber_memfree_x( data, NULL );
-}
-
 static int
 rwm_op_cleanup( Operation *op, SlapReply *rs )
 {
        slap_callback   *cb = op->o_callback;
        rwm_op_state *ros = cb->sc_private;
 
-       if ( rs->sr_type == REP_RESULT || op->o_abandon ||
-               rs->sr_err == SLAPD_ABANDON ) {
+       if ( rs->sr_type == REP_RESULT || rs->sr_type == REP_EXTENDED ||
+               op->o_abandon || rs->sr_err == SLAPD_ABANDON ) {
 
                op->o_req_dn = ros->ro_dn;
                op->o_req_ndn = ros->ro_ndn;
@@ -67,7 +58,7 @@ rwm_op_cleanup( Operation *op, SlapReply *rs )
                if ( !BER_BVISEMPTY( &ros->r_dn )) ch_free( ros->r_dn.bv_val );
                if ( !BER_BVISEMPTY( &ros->r_ndn )) ch_free( ros->r_ndn.bv_val );
 
-               switch( op->o_tag ) {
+               switch( ros->r_tag ) {
                case LDAP_REQ_COMPARE:
                        if ( op->orc_ava->aa_value.bv_val != ros->orc_ava->aa_value.bv_val )
                                op->o_tmpfree( op->orc_ava->aa_value.bv_val, op->o_tmpmemctx );
@@ -95,8 +86,16 @@ rwm_op_cleanup( Operation *op, SlapReply *rs )
                        op->ors_filter = ros->ors_filter;
                        op->ors_filterstr = ros->ors_filterstr;
                        break;
+               case LDAP_REQ_EXTENDED:
+                       if ( op->ore_reqdata != ros->ore_reqdata ) {
+                               ber_bvfree( op->ore_reqdata );
+                               op->ore_reqdata = ros->ore_reqdata;
+                       }
+                       break;
                default:        break;
                }
+               op->o_callback = op->o_callback->sc_next;
+               op->o_tmpfree( cb, op->o_tmpmemctx );
        }
 
        return SLAP_CB_CONTINUE;
@@ -107,21 +106,12 @@ rwm_callback_get( Operation *op, SlapReply *rs )
 {
        rwm_op_cb       *roc = NULL;
 
-       if ( op->o_threadctx == NULL ) {
-               roc = &rwm_cb;
-       } else {
-               ldap_pvt_thread_pool_getkey( op->o_threadctx,
-                               rwm_keyfree, (void *)&roc, NULL );
-               if ( roc == NULL ) {
-                       roc = ch_malloc( sizeof( struct rwm_op_cb ));
-                       ldap_pvt_thread_pool_setkey( op->o_threadctx,
-                                       rwm_keyfree, roc, rwm_keyfree );
-               }
-       }
+       roc = op->o_tmpalloc( sizeof( struct rwm_op_cb ), op->o_tmpmemctx );
        roc->cb.sc_cleanup = rwm_op_cleanup;
        roc->cb.sc_response = NULL;
        roc->cb.sc_next = op->o_callback;
        roc->cb.sc_private = &roc->ros;
+       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;
@@ -892,6 +882,7 @@ rwm_exop_passwd( Operation *op, SlapReply *rs )
        struct berval   id = BER_BVNULL,
                        pwold = BER_BVNULL,
                        pwnew = BER_BVNULL;
+       BerElement *ber = NULL;
 
        if ( !BER_BVISNULL( &op->o_req_ndn ) ) {
                return LDAP_SUCCESS;
@@ -935,7 +926,26 @@ rwm_exop_passwd( Operation *op, SlapReply *rs )
                return -1;
        }
 
-       /* TODO: re-encode the request with the massaged DN */
+       ber = ber_alloc_t( LBER_USE_DER );
+       if ( !ber ) {
+               rs->sr_err = LDAP_OTHER;
+               rs->sr_text = "No memory";
+               return rs->sr_err;
+       }
+       ber_printf( ber, "{" );
+       if ( !BER_BVISNULL( &id )) {
+               ber_printf( ber, "tO", LDAP_TAG_EXOP_MODIFY_PASSWD_ID, 
+                       &op->o_req_dn );
+       }
+       if ( !BER_BVISNULL( &pwold )) {
+               ber_printf( ber, "tO", LDAP_TAG_EXOP_MODIFY_PASSWD_OLD, &pwold );
+       }
+       if ( !BER_BVISNULL( &pwnew )) {
+               ber_printf( ber, "tO", LDAP_TAG_EXOP_MODIFY_PASSWD_NEW, &pwnew );
+       }
+       ber_printf( ber, "N}" );
+       ber_flatten( ber, &op->ore_reqdata );
+       ber_free( ber, 1 );
 
        op->o_callback = &roc->cb;
 
@@ -1517,16 +1527,6 @@ rwm_response( Operation *op, SlapReply *rs )
 
        switch( op->o_tag ) {
        case LDAP_REQ_SEARCH:
-               /* Note: the operation attrs are remapped */
-               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;
-               }
-               /* fall thru */
-
        case LDAP_REQ_BIND:
        case LDAP_REQ_ADD:
        case LDAP_REQ_DELETE:
@@ -1643,7 +1643,6 @@ rwm_db_init(
        BackendDB       *be )
 {
        slap_overinst           *on = (slap_overinst *) be->bd_info;
-       struct ldapmapping      *mapping = NULL;
        struct ldaprwmap        *rwmap;
 #ifdef ENABLE_REWRITE
        char                    *rargv[ 3 ];
@@ -1672,13 +1671,6 @@ rwm_db_init(
        rewrite_parse( rwmap->rwm_rw, "<suffix massage>", 2, 2, rargv );
 #endif /* ENABLE_REWRITE */
 
-       if ( rwm_map_init( &rwmap->rwm_oc, &mapping ) != LDAP_SUCCESS ||
-                       rwm_map_init( &rwmap->rwm_at, &mapping ) != LDAP_SUCCESS )
-       {
-               rc = 1;
-               goto error_return;
-       }
-
 error_return:;
        on->on_bi.bi_private = (void *)rwmap;