1 /* rwm.c - rewrite/remap operations */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2003-2006 The OpenLDAP Foundation.
6 * Portions Copyright 2003 Pierangelo Masarati.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
13 * A copy of this license is available in the file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
24 #include <ac/string.h>
29 typedef struct rwm_op_state {
38 rwm_db_destroy( BackendDB *be );
40 typedef struct rwm_op_cb {
45 static rwm_op_cb rwm_cb;
52 ber_memfree_x( data, NULL );
56 rwm_op_cleanup( Operation *op, SlapReply *rs )
58 slap_callback *cb = op->o_callback;
59 rwm_op_state *ros = cb->sc_private;
61 if ( rs->sr_type == REP_RESULT || op->o_abandon ||
62 rs->sr_err == SLAPD_ABANDON ) {
64 op->o_req_dn = ros->ro_dn;
65 op->o_req_ndn = ros->ro_ndn;
67 if ( !BER_BVISEMPTY( &ros->r_dn )) ch_free( ros->r_dn.bv_val );
68 if ( !BER_BVISEMPTY( &ros->r_ndn )) ch_free( ros->r_ndn.bv_val );
71 case LDAP_REQ_COMPARE:
72 if ( op->orc_ava->aa_value.bv_val != ros->orc_ava->aa_value.bv_val )
73 op->o_tmpfree( op->orc_ava->aa_value.bv_val, op->o_tmpmemctx );
74 op->orc_ava = ros->orc_ava;
77 slap_mods_free( op->orm_modlist, 1 );
78 op->orm_modlist = ros->orm_modlist;
81 if ( op->orr_newSup != ros->orr_newSup ) {
82 ch_free( op->orr_newSup->bv_val );
83 ch_free( op->orr_nnewSup->bv_val );
84 op->o_tmpfree( op->orr_newSup, op->o_tmpmemctx );
85 op->o_tmpfree( op->orr_nnewSup, op->o_tmpmemctx );
86 op->orr_newSup = ros->orr_newSup;
87 op->orr_nnewSup = ros->orr_nnewSup;
91 ch_free( op->ors_attrs );
92 filter_free_x( op, op->ors_filter );
93 ch_free( op->ors_filterstr.bv_val );
94 op->ors_attrs = ros->ors_attrs;
95 op->ors_filter = ros->ors_filter;
96 op->ors_filterstr = ros->ors_filterstr;
102 return SLAP_CB_CONTINUE;
106 rwm_callback_get( Operation *op, SlapReply *rs )
108 rwm_op_cb *roc = NULL;
110 if ( op->o_threadctx == NULL ) {
113 ldap_pvt_thread_pool_getkey( op->o_threadctx,
114 rwm_keyfree, (void *)&roc, NULL );
116 roc = ch_malloc( sizeof( struct rwm_op_cb ));
117 ldap_pvt_thread_pool_setkey( op->o_threadctx,
118 rwm_keyfree, roc, rwm_keyfree );
121 roc->cb.sc_cleanup = rwm_op_cleanup;
122 roc->cb.sc_response = NULL;
123 roc->cb.sc_next = op->o_callback;
124 roc->cb.sc_private = &roc->ros;
125 roc->ros.ro_dn = op->o_req_dn;
126 roc->ros.ro_ndn = op->o_req_ndn;
127 roc->ros.o_request = op->o_request;
128 BER_BVZERO( &roc->ros.r_dn );
129 BER_BVZERO( &roc->ros.r_ndn );
136 rwm_op_dn_massage( Operation *op, SlapReply *rs, void *cookie,
139 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
140 struct ldaprwmap *rwmap =
141 (struct ldaprwmap *)on->on_bi.bi_private;
143 struct berval dn = BER_BVNULL,
149 * Rewrite the dn if needed
152 #ifdef ENABLE_REWRITE
153 dc.conn = op->o_conn;
155 dc.ctx = (char *)cookie;
156 #else /* ! ENABLE_REWRITE */
157 dc.tofrom = ((int *)cookie)[0];
159 #endif /* ! ENABLE_REWRITE */
161 /* NOTE: in those cases where only the ndn is available,
162 * and the caller sets op->o_req_dn = op->o_req_ndn,
163 * only rewrite the op->o_req_ndn and use it as
164 * op->o_req_dn as well */
166 if ( op->o_req_dn.bv_val != op->o_req_ndn.bv_val ) {
168 rc = rwm_dn_massage_pretty_normalize( &dc, &op->o_req_dn, &dn, &ndn );
170 rc = rwm_dn_massage_normalize( &dc, &op->o_req_ndn, &ndn );
173 if ( rc != LDAP_SUCCESS ) {
177 if ( ( op->o_req_dn.bv_val != op->o_req_ndn.bv_val && dn.bv_val == op->o_req_dn.bv_val )
178 || ndn.bv_val == op->o_req_ndn.bv_val )
183 if ( op->o_req_dn.bv_val != op->o_req_ndn.bv_val ) {
196 rwm_op_add( Operation *op, SlapReply *rs )
198 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
199 struct ldaprwmap *rwmap =
200 (struct ldaprwmap *)on->on_bi.bi_private;
204 Attribute **ap = NULL;
205 char *olddn = op->o_req_dn.bv_val;
208 rwm_op_cb *roc = rwm_callback_get( op, rs );
210 #ifdef ENABLE_REWRITE
211 rc = rwm_op_dn_massage( op, rs, "addDN", &roc->ros );
212 #else /* ! ENABLE_REWRITE */
214 rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros );
215 #endif /* ! ENABLE_REWRITE */
216 if ( rc != LDAP_SUCCESS ) {
217 op->o_bd->bd_info = (BackendInfo *)on->on_info;
218 send_ldap_error( op, rs, rc, "addDN massage error" );
222 if ( olddn != op->o_req_dn.bv_val ) {
223 ber_bvreplace( &op->ora_e->e_name, &op->o_req_dn );
224 ber_bvreplace( &op->ora_e->e_nname, &op->o_req_ndn );
227 /* Count number of attributes in entry */
228 isupdate = be_shadow_update( op );
229 for ( i = 0, ap = &op->oq_add.rs_e->e_attrs; *ap; ) {
232 if ( (*ap)->a_desc == slap_schema.si_ad_objectClass ||
233 (*ap)->a_desc == slap_schema.si_ad_structuralObjectClass )
237 for ( last = 0; !BER_BVISNULL( &(*ap)->a_vals[ last ] ); last++ )
240 for ( j = 0; !BER_BVISNULL( &(*ap)->a_vals[ j ] ); j++ ) {
241 struct ldapmapping *mapping = NULL;
243 ( void )rwm_mapping( &rwmap->rwm_oc, &(*ap)->a_vals[ j ],
245 if ( mapping == NULL ) {
246 if ( rwmap->rwm_at.drop_missing ) {
247 /* FIXME: we allow to remove objectClasses as well;
248 * if the resulting entry is inconsistent, that's
249 * the relayed database's business...
251 ch_free( (*ap)->a_vals[ j ].bv_val );
253 (*ap)->a_vals[ j ] = (*ap)->a_vals[ last ];
255 BER_BVZERO( &(*ap)->a_vals[ last ] );
261 ch_free( (*ap)->a_vals[ j ].bv_val );
262 ber_dupbv( &(*ap)->a_vals[ j ], &mapping->m_dst );
266 } else if ( !isupdate && !get_relax( op ) && (*ap)->a_desc->ad_type->sat_no_user_mod )
271 struct ldapmapping *mapping = NULL;
273 ( void )rwm_mapping( &rwmap->rwm_at, &(*ap)->a_desc->ad_cname,
275 if ( mapping == NULL ) {
276 if ( rwmap->rwm_at.drop_missing ) {
281 if ( (*ap)->a_desc->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName
282 || ( mapping != NULL && mapping->m_dst_ad->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName ) )
285 * FIXME: rewrite could fail; in this case
286 * the operation should give up, right?
288 #ifdef ENABLE_REWRITE
289 rc = rwm_dnattr_rewrite( op, rs, "addAttrDN",
291 (*ap)->a_nvals ? &(*ap)->a_nvals : NULL );
292 #else /* ! ENABLE_REWRITE */
294 rc = rwm_dnattr_rewrite( op, rs, &rc, (*ap)->a_vals,
295 (*ap)->a_nvals ? &(*ap)->a_nvals : NULL );
296 #endif /* ! ENABLE_REWRITE */
301 } else if ( (*ap)->a_desc == slap_schema.si_ad_ref ) {
302 #ifdef ENABLE_REWRITE
303 rc = rwm_referral_rewrite( op, rs, "referralAttrDN",
305 (*ap)->a_nvals ? &(*ap)->a_nvals : NULL );
306 #else /* ! ENABLE_REWRITE */
308 rc = rwm_referral_rewrite( op, rs, &rc, (*ap)->a_vals,
309 (*ap)->a_nvals ? &(*ap)->a_nvals : NULL );
310 #endif /* ! ENABLE_REWRITE */
311 if ( rc != LDAP_SUCCESS ) {
316 if ( mapping != NULL ) {
317 assert( mapping->m_dst_ad != NULL );
318 (*ap)->a_desc = mapping->m_dst_ad;
327 /* FIXME: leaking attribute/values? */
334 op->o_callback = &roc->cb;
336 return SLAP_CB_CONTINUE;
339 #ifdef ENABLE_REWRITE
341 rwm_conn_init( BackendDB *be, Connection *conn )
343 slap_overinst *on = (slap_overinst *) be->bd_info;
344 struct ldaprwmap *rwmap =
345 (struct ldaprwmap *)on->on_bi.bi_private;
347 ( void )rewrite_session_init( rwmap->rwm_rw, conn );
349 return SLAP_CB_CONTINUE;
353 rwm_conn_destroy( BackendDB *be, Connection *conn )
355 slap_overinst *on = (slap_overinst *) be->bd_info;
356 struct ldaprwmap *rwmap =
357 (struct ldaprwmap *)on->on_bi.bi_private;
359 ( void )rewrite_session_delete( rwmap->rwm_rw, conn );
361 return SLAP_CB_CONTINUE;
363 #endif /* ENABLE_REWRITE */
366 rwm_op_bind( Operation *op, SlapReply *rs )
368 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
371 rwm_op_cb *roc = rwm_callback_get( op, rs );
373 #ifdef ENABLE_REWRITE
374 rc = rwm_op_dn_massage( op, rs, "bindDN", &roc->ros );
375 #else /* ! ENABLE_REWRITE */
377 rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros );
378 #endif /* ! ENABLE_REWRITE */
379 if ( rc != LDAP_SUCCESS ) {
380 op->o_bd->bd_info = (BackendInfo *)on->on_info;
381 send_ldap_error( op, rs, rc, "bindDN massage error" );
385 op->o_callback = &roc->cb;
387 return SLAP_CB_CONTINUE;
391 rwm_op_unbind( Operation *op, SlapReply *rs )
393 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
394 struct ldaprwmap *rwmap =
395 (struct ldaprwmap *)on->on_bi.bi_private;
397 #ifdef ENABLE_REWRITE
398 rewrite_session_delete( rwmap->rwm_rw, op->o_conn );
399 #endif /* ENABLE_REWRITE */
401 return SLAP_CB_CONTINUE;
405 rwm_op_compare( Operation *op, SlapReply *rs )
407 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
408 struct ldaprwmap *rwmap =
409 (struct ldaprwmap *)on->on_bi.bi_private;
412 struct berval mapped_vals[2] = { BER_BVNULL, BER_BVNULL };
414 rwm_op_cb *roc = rwm_callback_get( op, rs );
416 #ifdef ENABLE_REWRITE
417 rc = rwm_op_dn_massage( op, rs, "compareDN", &roc->ros );
418 #else /* ! ENABLE_REWRITE */
420 rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros );
421 #endif /* ! ENABLE_REWRITE */
422 if ( rc != LDAP_SUCCESS ) {
423 op->o_bd->bd_info = (BackendInfo *)on->on_info;
424 send_ldap_error( op, rs, rc, "compareDN massage error" );
428 /* if the attribute is an objectClass, try to remap its value */
429 if ( op->orc_ava->aa_desc == slap_schema.si_ad_objectClass
430 || op->orc_ava->aa_desc == slap_schema.si_ad_structuralObjectClass )
432 rwm_map( &rwmap->rwm_oc, &op->orc_ava->aa_value,
433 &mapped_vals[0], RWM_MAP );
434 if ( BER_BVISNULL( &mapped_vals[0] ) || BER_BVISEMPTY( &mapped_vals[0] ) )
436 op->o_bd->bd_info = (BackendInfo *)on->on_info;
437 send_ldap_error( op, rs, LDAP_OTHER, "compare objectClass map error" );
440 } else if ( mapped_vals[0].bv_val != op->orc_ava->aa_value.bv_val ) {
441 ber_dupbv_x( &op->orc_ava->aa_value, &mapped_vals[0],
446 struct ldapmapping *mapping = NULL;
447 AttributeDescription *ad = op->orc_ava->aa_desc;
449 ( void )rwm_mapping( &rwmap->rwm_at, &op->orc_ava->aa_desc->ad_cname,
451 if ( mapping == NULL ) {
452 if ( rwmap->rwm_at.drop_missing ) {
453 op->o_bd->bd_info = (BackendInfo *)on->on_info;
454 send_ldap_error( op, rs, LDAP_OTHER, "compare attributeType map error" );
459 assert( mapping->m_dst_ad != NULL );
460 ad = mapping->m_dst_ad;
463 if ( op->orc_ava->aa_desc->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName
464 || ( mapping != NULL && mapping->m_dst_ad->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName ) )
466 struct berval *mapped_valsp[2];
468 mapped_valsp[0] = &mapped_vals[0];
469 mapped_valsp[1] = &mapped_vals[1];
471 mapped_vals[0] = op->orc_ava->aa_value;
473 #ifdef ENABLE_REWRITE
474 rc = rwm_dnattr_rewrite( op, rs, "compareAttrDN", NULL, mapped_valsp );
475 #else /* ! ENABLE_REWRITE */
477 rc = rwm_dnattr_rewrite( op, rs, &rc, NULL, mapped_valsp );
478 #endif /* ! ENABLE_REWRITE */
480 if ( rc != LDAP_SUCCESS ) {
481 op->o_bd->bd_info = (BackendInfo *)on->on_info;
482 send_ldap_error( op, rs, rc, "compareAttrDN massage error" );
486 if ( mapped_vals[ 0 ].bv_val != op->orc_ava->aa_value.bv_val ) {
487 /* NOTE: if we get here, rwm_dnattr_rewrite()
488 * already freed the old value, so now
490 ber_dupbv_x( &op->orc_ava->aa_value, &mapped_vals[0],
492 ber_memfree_x( mapped_vals[ 0 ].bv_val, NULL );
495 op->orc_ava->aa_desc = ad;
498 op->o_callback = &roc->cb;
500 return SLAP_CB_CONTINUE;
504 rwm_op_delete( Operation *op, SlapReply *rs )
506 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
509 rwm_op_cb *roc = rwm_callback_get( op, rs );
511 #ifdef ENABLE_REWRITE
512 rc = rwm_op_dn_massage( op, rs, "deleteDN", &roc->ros );
513 #else /* ! ENABLE_REWRITE */
515 rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros );
516 #endif /* ! ENABLE_REWRITE */
517 if ( rc != LDAP_SUCCESS ) {
518 op->o_bd->bd_info = (BackendInfo *)on->on_info;
519 send_ldap_error( op, rs, rc, "deleteDN massage error" );
523 op->o_callback = &roc->cb;
525 return SLAP_CB_CONTINUE;
529 rwm_op_modify( Operation *op, SlapReply *rs )
531 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
532 struct ldaprwmap *rwmap =
533 (struct ldaprwmap *)on->on_bi.bi_private;
539 rwm_op_cb *roc = rwm_callback_get( op, rs );
541 #ifdef ENABLE_REWRITE
542 rc = rwm_op_dn_massage( op, rs, "modifyDN", &roc->ros );
543 #else /* ! ENABLE_REWRITE */
545 rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros );
546 #endif /* ! ENABLE_REWRITE */
547 if ( rc != LDAP_SUCCESS ) {
548 op->o_bd->bd_info = (BackendInfo *)on->on_info;
549 send_ldap_error( op, rs, rc, "modifyDN massage error" );
553 isupdate = be_shadow_update( op );
554 for ( mlp = &op->oq_modify.rs_modlist; *mlp; ) {
557 struct ldapmapping *mapping = NULL;
559 /* duplicate the modlist */
560 ml = ch_malloc( sizeof( Modifications ));
564 if ( ml->sml_desc == slap_schema.si_ad_objectClass
565 || ml->sml_desc == slap_schema.si_ad_structuralObjectClass )
569 } else if ( !isupdate && !get_relax( op ) && ml->sml_desc->ad_type->sat_no_user_mod )
576 drop_missing = rwm_mapping( &rwmap->rwm_at,
577 &ml->sml_desc->ad_cname,
579 if ( drop_missing || ( mapping != NULL && BER_BVISNULL( &mapping->m_dst ) ) )
585 if ( ml->sml_values != NULL ) {
589 for ( num = 0; !BER_BVISNULL( &ml->sml_values[ num ] ); num++ )
592 bva = ch_malloc( (num+1) * sizeof( struct berval ));
593 for (i=0; i<num; i++)
594 ber_dupbv( &bva[i], &ml->sml_values[i] );
595 BER_BVZERO( &bva[i] );
596 ml->sml_values = bva;
598 if ( ml->sml_nvalues ) {
599 bva = ch_malloc( (num+1) * sizeof( struct berval ));
600 for (i=0; i<num; i++)
601 ber_dupbv( &bva[i], &ml->sml_nvalues[i] );
602 BER_BVZERO( &bva[i] );
603 ml->sml_nvalues = bva;
611 for ( j = 0; !BER_BVISNULL( &ml->sml_values[ j ] ); j++ ) {
612 struct ldapmapping *oc_mapping = NULL;
614 ( void )rwm_mapping( &rwmap->rwm_oc, &ml->sml_values[ j ],
615 &oc_mapping, RWM_MAP );
616 if ( oc_mapping == NULL ) {
617 if ( rwmap->rwm_at.drop_missing ) {
618 /* FIXME: we allow to remove objectClasses as well;
619 * if the resulting entry is inconsistent, that's
620 * the relayed database's business...
623 ch_free( ml->sml_values[ j ].bv_val );
624 ml->sml_values[ j ] = ml->sml_values[ last ];
626 BER_BVZERO( &ml->sml_values[ last ] );
632 ch_free( ml->sml_values[ j ].bv_val );
633 ber_dupbv( &ml->sml_values[ j ], &oc_mapping->m_dst );
638 if ( ml->sml_desc->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName
639 || ( mapping != NULL && mapping->m_dst_ad->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName ) )
641 #ifdef ENABLE_REWRITE
642 rc = rwm_dnattr_rewrite( op, rs, "modifyAttrDN",
644 ml->sml_nvalues ? &ml->sml_nvalues : NULL );
645 #else /* ! ENABLE_REWRITE */
647 rc = rwm_dnattr_rewrite( op, rs, &rc,
649 ml->sml_nvalues ? &ml->sml_nvalues : NULL );
650 #endif /* ! ENABLE_REWRITE */
652 } else if ( ml->sml_desc == slap_schema.si_ad_ref ) {
653 #ifdef ENABLE_REWRITE
654 rc = rwm_referral_rewrite( op, rs,
657 ml->sml_nvalues ? &ml->sml_nvalues : NULL );
658 #else /* ! ENABLE_REWRITE */
660 rc = rwm_referral_rewrite( op, rs, &rc,
662 ml->sml_nvalues ? &ml->sml_nvalues : NULL );
663 #endif /* ! ENABLE_REWRITE */
664 if ( rc != LDAP_SUCCESS ) {
669 if ( rc != LDAP_SUCCESS ) {
676 if ( mapping != NULL ) {
677 /* use new attribute description */
678 assert( mapping->m_dst_ad != NULL );
679 ml->sml_desc = mapping->m_dst_ad;
687 *mlp = (*mlp)->sml_next;
688 slap_mod_free( &ml->sml_mod, 0 );
692 op->o_callback = &roc->cb;
694 return SLAP_CB_CONTINUE;
698 rwm_op_modrdn( Operation *op, SlapReply *rs )
700 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
701 struct ldaprwmap *rwmap =
702 (struct ldaprwmap *)on->on_bi.bi_private;
706 rwm_op_cb *roc = rwm_callback_get( op, rs );
708 if ( op->orr_newSup ) {
710 struct berval nnewSup = BER_BVNULL;
711 struct berval newSup = BER_BVNULL;
714 * Rewrite the new superior, if defined and required
717 #ifdef ENABLE_REWRITE
718 dc.conn = op->o_conn;
720 dc.ctx = "newSuperiorDN";
721 #else /* ! ENABLE_REWRITE */
724 #endif /* ! ENABLE_REWRITE */
725 newSup = *op->orr_newSup;
726 nnewSup = *op->orr_nnewSup;
727 rc = rwm_dn_massage_pretty_normalize( &dc, op->orr_newSup, &newSup, &nnewSup );
728 if ( rc != LDAP_SUCCESS ) {
729 op->o_bd->bd_info = (BackendInfo *)on->on_info;
730 send_ldap_error( op, rs, rc, "newSuperiorDN massage error" );
734 if ( op->orr_newSup->bv_val != newSup.bv_val ) {
735 op->orr_newSup = op->o_tmpalloc( sizeof( struct berval ),
737 op->orr_nnewSup = op->o_tmpalloc( sizeof( struct berval ),
739 *op->orr_newSup = newSup;
740 *op->orr_nnewSup = nnewSup;
745 * Rewrite the dn, if needed
747 #ifdef ENABLE_REWRITE
748 rc = rwm_op_dn_massage( op, rs, "renameDN", &roc->ros );
749 #else /* ! ENABLE_REWRITE */
751 rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros );
752 #endif /* ! ENABLE_REWRITE */
753 if ( rc != LDAP_SUCCESS ) {
754 op->o_bd->bd_info = (BackendInfo *)on->on_info;
755 send_ldap_error( op, rs, rc, "renameDN massage error" );
756 if ( op->orr_newSup != roc->ros.orr_newSup ) {
757 ch_free( op->orr_newSup->bv_val );
758 ch_free( op->orr_nnewSup->bv_val );
759 op->o_tmpfree( op->orr_newSup, op->o_tmpmemctx );
760 op->o_tmpfree( op->orr_nnewSup, op->o_tmpmemctx );
761 op->orr_newSup = roc->ros.orr_newSup;
762 op->orr_nnewSup = roc->ros.orr_nnewSup;
767 /* TODO: rewrite newRDN, attribute types,
768 * values of DN-valued attributes ... */
770 op->o_callback = &roc->cb;
772 return SLAP_CB_CONTINUE;
777 rwm_swap_attrs( Operation *op, SlapReply *rs )
779 slap_callback *cb = op->o_callback;
780 rwm_op_state *ros = cb->sc_private;
782 rs->sr_attrs = ros->ors_attrs;
784 return SLAP_CB_CONTINUE;
788 rwm_op_search( Operation *op, SlapReply *rs )
790 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
791 struct ldaprwmap *rwmap =
792 (struct ldaprwmap *)on->on_bi.bi_private;
797 struct berval fstr = BER_BVNULL;
800 AttributeName *an = NULL;
804 rwm_op_cb *roc = rwm_callback_get( op, rs );
806 #ifdef ENABLE_REWRITE
807 rc = rewrite_session_var_set( rwmap->rwm_rw, op->o_conn,
808 "searchFilter", op->ors_filterstr.bv_val );
809 if ( rc == LDAP_SUCCESS )
810 rc = rwm_op_dn_massage( op, rs, "searchDN", &roc->ros );
811 #else /* ! ENABLE_REWRITE */
813 rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros );
814 #endif /* ! ENABLE_REWRITE */
815 if ( rc != LDAP_SUCCESS ) {
816 text = "searchDN massage error";
821 * Rewrite the dn if needed
824 #ifdef ENABLE_REWRITE
825 dc.conn = op->o_conn;
827 dc.ctx = "searchFilterAttrDN";
828 #else /* ! ENABLE_REWRITE */
831 #endif /* ! ENABLE_REWRITE */
833 rc = rwm_filter_map_rewrite( op, &dc, op->ors_filter, &fstr );
834 if ( rc != LDAP_SUCCESS ) {
835 text = "searchFilter/searchFilterAttrDN massage error";
839 f = str2filter_x( op, fstr.bv_val );
842 text = "massaged filter parse error";
847 op->ors_filterstr = fstr;
849 rc = rwm_map_attrnames( &rwmap->rwm_at, &rwmap->rwm_oc,
850 op->ors_attrs, &an, RWM_MAP );
851 if ( rc != LDAP_SUCCESS ) {
852 text = "attribute list mapping error";
857 roc->cb.sc_response = rwm_swap_attrs;
859 op->o_callback = &roc->cb;
861 return SLAP_CB_CONTINUE;
869 filter_free_x( op, f );
872 if ( !BER_BVISNULL( &fstr ) ) {
873 ch_free( fstr.bv_val );
876 op->oq_search = roc->ros.oq_search;
878 op->o_bd->bd_info = (BackendInfo *)on->on_info;
879 send_ldap_error( op, rs, rc, text );
886 rwm_exop_passwd( Operation *op, SlapReply *rs )
888 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
892 struct berval id = BER_BVNULL,
896 if ( !BER_BVISNULL( &op->o_req_ndn ) ) {
900 if ( !SLAP_ISGLOBALOVERLAY( op->o_bd ) ) {
901 rs->sr_err = LDAP_OTHER;
905 rs->sr_err = slap_passwd_parse( op->ore_reqdata, &id,
906 &pwold, &pwnew, &rs->sr_text );
907 if ( rs->sr_err != LDAP_SUCCESS ) {
911 if ( !BER_BVISNULL( &id ) ) {
912 rs->sr_err = dnPrettyNormal( NULL, &id, &op->o_req_dn,
913 &op->o_req_ndn, op->o_tmpmemctx );
914 if ( rs->sr_err != LDAP_SUCCESS ) {
915 rs->sr_text = "Invalid DN";
920 ber_dupbv_x( &op->o_req_dn, &op->o_dn, op->o_tmpmemctx );
921 ber_dupbv_x( &op->o_req_ndn, &op->o_ndn, op->o_tmpmemctx );
924 roc = rwm_callback_get( op, rs );
926 #ifdef ENABLE_REWRITE
927 rc = rwm_op_dn_massage( op, rs, "extendedDN", &roc->ros );
928 #else /* ! ENABLE_REWRITE */
930 rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros );
931 #endif /* ! ENABLE_REWRITE */
932 if ( rc != LDAP_SUCCESS ) {
933 op->o_bd->bd_info = (BackendInfo *)on->on_info;
934 send_ldap_error( op, rs, rc, "extendedDN massage error" );
938 /* TODO: re-encode the request with the massaged DN */
940 op->o_callback = &roc->cb;
942 return SLAP_CB_CONTINUE;
947 BI_op_extended *extended;
949 { BER_BVC(LDAP_EXOP_MODIFY_PASSWD), rwm_exop_passwd },
954 rwm_extended( Operation *op, SlapReply *rs )
956 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
962 for ( i = 0; exop_table[i].extended != NULL; i++ ) {
963 if ( bvmatch( &exop_table[i].oid, &op->oq_extended.rs_reqoid ) )
965 rc = exop_table[i].extended( op, rs );
970 case SLAP_CB_CONTINUE:
975 send_ldap_result( op, rs );
982 roc = rwm_callback_get( op, rs );
984 #ifdef ENABLE_REWRITE
985 rc = rwm_op_dn_massage( op, rs, "extendedDN", &roc->ros );
986 #else /* ! ENABLE_REWRITE */
988 rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros );
989 #endif /* ! ENABLE_REWRITE */
990 if ( rc != LDAP_SUCCESS ) {
991 op->o_bd->bd_info = (BackendInfo *)on->on_info;
992 send_ldap_error( op, rs, rc, "extendedDN massage error" );
996 /* TODO: rewrite/map extended data ? ... */
997 op->o_callback = &roc->cb;
999 return SLAP_CB_CONTINUE;
1003 rwm_matched( Operation *op, SlapReply *rs )
1005 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
1006 struct ldaprwmap *rwmap =
1007 (struct ldaprwmap *)on->on_bi.bi_private;
1009 struct berval dn, mdn;
1013 if ( rs->sr_matched == NULL ) {
1014 return SLAP_CB_CONTINUE;
1018 #ifdef ENABLE_REWRITE
1019 dc.conn = op->o_conn;
1021 dc.ctx = "matchedDN";
1022 #else /* ! ENABLE_REWRITE */
1025 #endif /* ! ENABLE_REWRITE */
1026 ber_str2bv( rs->sr_matched, 0, 0, &dn );
1028 rc = rwm_dn_massage_pretty( &dc, &dn, &mdn );
1029 if ( rc != LDAP_SUCCESS ) {
1031 rs->sr_text = "Rewrite error";
1035 if ( mdn.bv_val != dn.bv_val ) {
1036 if ( rs->sr_flags & REP_MATCHED_MUSTBEFREED ) {
1037 ch_free( (void *)rs->sr_matched );
1040 rs->sr_flags |= REP_MATCHED_MUSTBEFREED;
1042 rs->sr_matched = mdn.bv_val;
1045 return SLAP_CB_CONTINUE;
1049 rwm_attrs( Operation *op, SlapReply *rs, Attribute** a_first, int stripEntryDN )
1051 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
1052 struct ldaprwmap *rwmap =
1053 (struct ldaprwmap *)on->on_bi.bi_private;
1061 * Rewrite the dn attrs, if needed
1064 #ifdef ENABLE_REWRITE
1065 dc.conn = op->o_conn;
1067 #else /* ! ENABLE_REWRITE */
1070 #endif /* ! ENABLE_REWRITE */
1072 /* FIXME: the entries are in the remote mapping form;
1073 * so we need to select those attributes we are willing
1074 * to return, and remap them accordingly */
1076 /* FIXME: in principle, one could map an attribute
1077 * on top of another, which already exists.
1078 * As such, in the end there might exist more than
1079 * one instance of an attribute.
1080 * We should at least check if this occurs, and issue
1081 * an error (because multiple instances of attrs in
1082 * response are not valid), or merge the values (what
1083 * about duplicate values?) */
1084 isupdate = be_shadow_update( op );
1085 for ( ap = a_first; *ap; ) {
1086 struct ldapmapping *mapping = NULL;
1091 if ( SLAP_OPATTRS( rs->sr_attr_flags ) && is_at_operational( (*ap)->a_desc->ad_type ) )
1096 if ( op->ors_attrs != NULL &&
1097 !SLAP_USERATTRS( rs->sr_attr_flags ) &&
1098 !ad_inlist( (*ap)->a_desc, op->ors_attrs ) )
1103 drop_missing = rwm_mapping( &rwmap->rwm_at,
1104 &(*ap)->a_desc->ad_cname, &mapping, RWM_REMAP );
1105 if ( drop_missing || ( mapping != NULL && BER_BVISEMPTY( &mapping->m_dst ) ) )
1110 if ( mapping != NULL ) {
1111 (*ap)->a_desc = mapping->m_dst_ad;
1115 if ( (*ap)->a_desc == slap_schema.si_ad_entryDN ) {
1116 if ( stripEntryDN ) {
1117 /* will be generated by frontend */
1121 } else if ( !isupdate
1123 && (*ap)->a_desc->ad_type->sat_no_user_mod
1124 && (*ap)->a_desc->ad_type != slap_schema.si_at_undefined )
1129 for ( last = 0; !BER_BVISNULL( &(*ap)->a_vals[last] ); last++ )
1133 /* empty? leave it in place because of attrsonly and vlv */
1138 if ( (*ap)->a_desc == slap_schema.si_ad_objectClass
1139 || (*ap)->a_desc == slap_schema.si_ad_structuralObjectClass )
1143 for ( bv = (*ap)->a_vals; !BER_BVISNULL( bv ); bv++ ) {
1144 struct berval mapped;
1146 rwm_map( &rwmap->rwm_oc, &bv[0], &mapped, RWM_REMAP );
1147 if ( BER_BVISNULL( &mapped ) || BER_BVISEMPTY( &mapped ) ) {
1148 ch_free( bv[0].bv_val );
1149 BER_BVZERO( &bv[0] );
1150 if ( &(*ap)->a_vals[last] > &bv[0] ) {
1151 bv[0] = (*ap)->a_vals[last];
1152 BER_BVZERO( &(*ap)->a_vals[last] );
1157 } else if ( mapped.bv_val != bv[0].bv_val ) {
1159 * FIXME: after LBER_FREEing
1160 * the value is replaced by
1161 * ch_alloc'ed memory
1163 ber_bvreplace( &bv[0], &mapped );
1168 * It is necessary to try to rewrite attributes with
1169 * dn syntax because they might be used in ACLs as
1170 * members of groups; since ACLs are applied to the
1171 * rewritten stuff, no dn-based subject clause could
1172 * be used at the ldap backend side (see
1173 * http://www.OpenLDAP.org/faq/data/cache/452.html)
1174 * The problem can be overcome by moving the dn-based
1175 * ACLs to the target directory server, and letting
1176 * everything pass thru the ldap backend. */
1177 /* FIXME: handle distinguishedName-like syntaxes, like
1178 * nameAndOptionalUID */
1179 } else if ( (*ap)->a_desc->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName
1180 || ( mapping != NULL && mapping->m_src_ad->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName ) )
1182 #ifdef ENABLE_REWRITE
1183 dc.ctx = "searchAttrDN";
1184 #endif /* ENABLE_REWRITE */
1185 rc = rwm_dnattr_result_rewrite( &dc, (*ap)->a_vals );
1186 if ( rc != LDAP_SUCCESS ) {
1190 } else if ( (*ap)->a_desc == slap_schema.si_ad_ref ) {
1191 #ifdef ENABLE_REWRITE
1192 dc.ctx = "searchAttrDN";
1193 #endif /* ENABLE_REWRITE */
1194 rc = rwm_referral_result_rewrite( &dc, (*ap)->a_vals );
1195 if ( rc != LDAP_SUCCESS ) {
1200 if ( mapping != NULL ) {
1201 /* rewrite the attribute description */
1202 assert( mapping->m_dst_ad != NULL );
1203 (*ap)->a_desc = mapping->m_dst_ad;
1207 ap = &(*ap)->a_next;
1212 *ap = (*ap)->a_next;
1221 rwm_send_entry( Operation *op, SlapReply *rs )
1223 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
1224 struct ldaprwmap *rwmap =
1225 (struct ldaprwmap *)on->on_bi.bi_private;
1229 struct berval dn = BER_BVNULL,
1234 assert( rs->sr_entry != NULL );
1237 * Rewrite the dn of the result, if needed
1240 #ifdef ENABLE_REWRITE
1241 dc.conn = op->o_conn;
1243 dc.ctx = "searchEntryDN";
1244 #else /* ! ENABLE_REWRITE */
1247 #endif /* ! ENABLE_REWRITE */
1250 flags = rs->sr_flags;
1251 if ( !( rs->sr_flags & REP_ENTRY_MODIFIABLE ) ) {
1252 /* FIXME: all we need to duplicate are:
1255 * - attributes that are requested
1256 * - no values if attrsonly is set
1261 rc = LDAP_NO_MEMORY;
1265 flags &= ~REP_ENTRY_MUSTRELEASE;
1266 flags |= ( REP_ENTRY_MODIFIABLE | REP_ENTRY_MUSTBEFREED );
1270 * Note: this may fail if the target host(s) schema differs
1271 * from the one known to the meta, and a DN with unknown
1272 * attributes is returned.
1276 rc = rwm_dn_massage_pretty_normalize( &dc, &e->e_name, &dn, &ndn );
1277 if ( rc != LDAP_SUCCESS ) {
1282 if ( e->e_name.bv_val != dn.bv_val ) {
1283 ch_free( e->e_name.bv_val );
1284 ch_free( e->e_nname.bv_val );
1290 /* TODO: map entry attribute types, objectclasses
1291 * and dn-valued attribute values */
1293 /* FIXME: the entries are in the remote mapping form;
1294 * so we need to select those attributes we are willing
1295 * to return, and remap them accordingly */
1296 (void)rwm_attrs( op, rs, &e->e_attrs, 1 );
1298 if ( rs->sr_flags & REP_ENTRY_MUSTRELEASE ) {
1299 be_entry_release_rw( op, rs->sr_entry, 0 );
1303 rs->sr_flags = flags;
1305 return SLAP_CB_CONTINUE;
1308 if ( e != NULL && e != rs->sr_entry ) {
1309 if ( e->e_name.bv_val == dn.bv_val ) {
1310 BER_BVZERO( &e->e_name );
1313 if ( e->e_nname.bv_val == ndn.bv_val ) {
1314 BER_BVZERO( &e->e_nname );
1320 if ( !BER_BVISNULL( &dn ) ) {
1321 ch_free( dn.bv_val );
1324 if ( !BER_BVISNULL( &ndn ) ) {
1325 ch_free( ndn.bv_val );
1332 rwm_operational( Operation *op, SlapReply *rs )
1334 /* FIXME: the entries are in the remote mapping form;
1335 * so we need to select those attributes we are willing
1336 * to return, and remap them accordingly */
1337 if ( rs->sr_operational_attrs ) {
1338 rwm_attrs( op, rs, &rs->sr_operational_attrs, 1 );
1341 return SLAP_CB_CONTINUE;
1345 /* don't use this; it cannot be reverted, and leaves op->o_req_dn
1346 * rewritten for subsequent operations; fine for plain suffixmassage,
1347 * but destroys everything else */
1349 rwm_chk_referrals( Operation *op, SlapReply *rs )
1351 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
1354 #ifdef ENABLE_REWRITE
1355 rc = rwm_op_dn_massage( op, rs, "referralCheckDN" );
1356 #else /* ! ENABLE_REWRITE */
1358 rc = rwm_op_dn_massage( op, rs, &rc );
1359 #endif /* ! ENABLE_REWRITE */
1360 if ( rc != LDAP_SUCCESS ) {
1361 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1362 send_ldap_error( op, rs, rc, "referralCheckDN massage error" );
1366 return SLAP_CB_CONTINUE;
1378 #ifdef ENABLE_REWRITE
1379 slap_overinst *on = (slap_overinst *) be->bd_info;
1380 struct ldaprwmap *rwmap =
1381 (struct ldaprwmap *)on->on_bi.bi_private;
1383 return rewrite_parse( rwmap->rwm_rw,
1384 fname, lineno, argc, argv );
1386 #else /* !ENABLE_REWRITE */
1387 fprintf( stderr, "%s: line %d: rewrite capabilities "
1388 "are not enabled\n", fname, lineno );
1389 #endif /* !ENABLE_REWRITE */
1395 rwm_suffixmassage_config(
1402 slap_overinst *on = (slap_overinst *) be->bd_info;
1403 struct ldaprwmap *rwmap =
1404 (struct ldaprwmap *)on->on_bi.bi_private;
1406 struct berval bvnc, nvnc, pvnc, brnc, nrnc, prnc;
1408 #ifdef ENABLE_REWRITE
1410 #endif /* ENABLE_REWRITE */
1415 * suffixmassage [<suffix>] <massaged suffix>
1417 * the [<suffix>] field must be defined as a valid suffix
1418 * for the current database;
1419 * the <massaged suffix> shouldn't have already been
1420 * defined as a valid suffix for the current server
1423 if ( be->be_suffix == NULL ) {
1424 fprintf( stderr, "%s: line %d: "
1425 " \"suffixMassage [<suffix>]"
1426 " <massaged suffix>\" without "
1427 "<suffix> part requires database "
1428 "suffix be defined first.\n",
1432 bvnc = be->be_suffix[ 0 ];
1435 } else if ( argc == 3 ) {
1436 ber_str2bv( argv[ 1 ], 0, 0, &bvnc );
1440 fprintf( stderr, "%s: line %d: syntax is"
1441 " \"suffixMassage [<suffix>]"
1442 " <massaged suffix>\"\n",
1447 if ( dnPrettyNormal( NULL, &bvnc, &pvnc, &nvnc, NULL ) != LDAP_SUCCESS ) {
1448 fprintf( stderr, "%s: line %d: suffix DN %s is invalid\n",
1449 fname, lineno, bvnc.bv_val );
1453 ber_str2bv( argv[ massaged ], 0, 0, &brnc );
1454 if ( dnPrettyNormal( NULL, &brnc, &prnc, &nrnc, NULL ) != LDAP_SUCCESS ) {
1455 fprintf( stderr, "%s: line %d: suffix DN %s is invalid\n",
1456 fname, lineno, brnc.bv_val );
1457 free( nvnc.bv_val );
1458 free( pvnc.bv_val );
1462 #ifdef ENABLE_REWRITE
1464 * The suffix massaging is emulated
1465 * by means of the rewrite capabilities
1467 rc = rwm_suffix_massage_config( rwmap->rwm_rw,
1468 &pvnc, &nvnc, &prnc, &nrnc );
1469 free( nvnc.bv_val );
1470 free( pvnc.bv_val );
1471 free( nrnc.bv_val );
1472 free( prnc.bv_val );
1476 #else /* !ENABLE_REWRITE */
1477 ber_bvarray_add( &rwmap->rwm_suffix_massage, &pvnc );
1478 ber_bvarray_add( &rwmap->rwm_suffix_massage, &nvnc );
1480 ber_bvarray_add( &rwmap->rwm_suffix_massage, &prnc );
1481 ber_bvarray_add( &rwmap->rwm_suffix_massage, &nrnc );
1482 #endif /* !ENABLE_REWRITE */
1495 slap_overinst *on = (slap_overinst *) be->bd_info;
1496 struct ldaprwmap *rwmap =
1497 (struct ldaprwmap *)on->on_bi.bi_private;
1499 /* objectclass/attribute mapping */
1500 return rwm_map_config( &rwmap->rwm_oc,
1502 fname, lineno, argc, argv );
1506 rwm_response( Operation *op, SlapReply *rs )
1508 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
1509 struct ldaprwmap *rwmap =
1510 (struct ldaprwmap *)on->on_bi.bi_private;
1514 if ( op->o_tag == LDAP_REQ_SEARCH && rs->sr_type == REP_SEARCH ) {
1515 return rwm_send_entry( op, rs );
1518 switch( op->o_tag ) {
1519 case LDAP_REQ_SEARCH:
1520 /* Note: the operation attrs are remapped */
1521 if ( rs->sr_type == REP_RESULT
1522 && op->ors_attrs != NULL
1523 && op->ors_attrs != rs->sr_attrs )
1525 ch_free( op->ors_attrs );
1526 op->ors_attrs = rs->sr_attrs;
1532 case LDAP_REQ_DELETE:
1533 case LDAP_REQ_MODRDN:
1534 case LDAP_REQ_MODIFY:
1535 case LDAP_REQ_COMPARE:
1536 case LDAP_REQ_EXTENDED:
1541 * Rewrite the dn of the referrals, if needed
1544 #ifdef ENABLE_REWRITE
1545 dc.conn = op->o_conn;
1547 dc.ctx = "referralDN";
1548 #else /* ! ENABLE_REWRITE */
1551 #endif /* ! ENABLE_REWRITE */
1552 rc = rwm_referral_result_rewrite( &dc, rs->sr_ref );
1553 if ( rc != LDAP_SUCCESS ) {
1558 rc = rwm_matched( op, rs );
1562 rc = SLAP_CB_CONTINUE;
1577 slap_overinst *on = (slap_overinst *) be->bd_info;
1578 struct ldaprwmap *rwmap =
1579 (struct ldaprwmap *)on->on_bi.bi_private;
1584 if ( strncasecmp( argv[ 0 ], "rwm-", STRLENOF( "rwm-" ) ) == 0 ) {
1586 argv[ 0 ] = &argv0[ STRLENOF( "rwm-" ) ];
1589 if ( strncasecmp( argv[0], "rewrite", STRLENOF("rewrite") ) == 0 ) {
1590 rc = rwm_rw_config( be, fname, lineno, argc, argv );
1592 } else if ( strcasecmp( argv[0], "map" ) == 0 ) {
1593 rc = rwm_m_config( be, fname, lineno, argc, argv );
1595 } else if ( strcasecmp( argv[0], "suffixmassage" ) == 0 ) {
1596 rc = rwm_suffixmassage_config( be, fname, lineno, argc, argv );
1598 } else if ( strcasecmp( argv[0], "t-f-support" ) == 0 ) {
1601 "%s: line %d: \"t-f-support {no|yes|discover}\" needs 1 argument.\n",
1606 if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
1607 rwmap->rwm_flags &= ~(RWM_F_SUPPORT_T_F|RWM_F_SUPPORT_T_F_DISCOVER);
1609 } else if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
1610 rwmap->rwm_flags |= RWM_F_SUPPORT_T_F;
1612 /* TODO: not implemented yet */
1613 } else if ( strcasecmp( argv[ 1 ], "discover" ) == 0 ) {
1615 "%s: line %d: \"discover\" not supported yet "
1616 "in \"t-f-support {no|yes|discover}\".\n",
1620 rwmap->rwm_flags |= RWM_F_SUPPORT_T_F_DISCOVER;
1625 "%s: line %d: unknown value \"%s\" for \"t-f-support {no|yes|discover}\".\n",
1626 fname, lineno, argv[ 1 ] );
1631 rc = SLAP_CONF_UNKNOWN;
1645 slap_overinst *on = (slap_overinst *) be->bd_info;
1646 struct ldapmapping *mapping = NULL;
1647 struct ldaprwmap *rwmap;
1648 #ifdef ENABLE_REWRITE
1650 #endif /* ENABLE_REWRITE */
1653 rwmap = (struct ldaprwmap *)ch_calloc( 1, sizeof( struct ldaprwmap ) );
1655 #ifdef ENABLE_REWRITE
1656 rwmap->rwm_rw = rewrite_info_init( REWRITE_MODE_USE_DEFAULT );
1657 if ( rwmap->rwm_rw == NULL ) {
1662 /* this rewriteContext by default must be null;
1663 * rules can be added if required */
1664 rargv[ 0 ] = "rewriteContext";
1665 rargv[ 1 ] = "searchFilter";
1667 rewrite_parse( rwmap->rwm_rw, "<suffix massage>", 1, 2, rargv );
1669 rargv[ 0 ] = "rewriteContext";
1670 rargv[ 1 ] = "default";
1672 rewrite_parse( rwmap->rwm_rw, "<suffix massage>", 2, 2, rargv );
1673 #endif /* ENABLE_REWRITE */
1675 if ( rwm_map_init( &rwmap->rwm_oc, &mapping ) != LDAP_SUCCESS ||
1676 rwm_map_init( &rwmap->rwm_at, &mapping ) != LDAP_SUCCESS )
1683 on->on_bi.bi_private = (void *)rwmap;
1686 (void)rwm_db_destroy( be );
1696 slap_overinst *on = (slap_overinst *) be->bd_info;
1699 if ( on->on_bi.bi_private ) {
1700 struct ldaprwmap *rwmap =
1701 (struct ldaprwmap *)on->on_bi.bi_private;
1703 #ifdef ENABLE_REWRITE
1704 if ( rwmap->rwm_rw ) {
1705 rewrite_info_delete( &rwmap->rwm_rw );
1707 #else /* !ENABLE_REWRITE */
1708 if ( rwmap->rwm_suffix_massage ) {
1709 ber_bvarray_free( rwmap->rwm_suffix_massage );
1711 #endif /* !ENABLE_REWRITE */
1713 avl_free( rwmap->rwm_oc.remap, rwm_mapping_dst_free );
1714 avl_free( rwmap->rwm_oc.map, rwm_mapping_free );
1715 avl_free( rwmap->rwm_at.remap, rwm_mapping_dst_free );
1716 avl_free( rwmap->rwm_at.map, rwm_mapping_free );
1724 static slap_overinst rwm = { { NULL } };
1726 #if SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC
1728 #endif /* SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC */
1730 rwm_initialize( void )
1732 memset( &rwm, 0, sizeof( slap_overinst ) );
1734 rwm.on_bi.bi_type = "rwm";
1735 rwm.on_bi.bi_flags =
1736 SLAPO_BFLAG_SINGLE |
1739 rwm.on_bi.bi_db_init = rwm_db_init;
1740 rwm.on_bi.bi_db_config = rwm_db_config;
1741 rwm.on_bi.bi_db_destroy = rwm_db_destroy;
1743 rwm.on_bi.bi_op_bind = rwm_op_bind;
1744 rwm.on_bi.bi_op_search = rwm_op_search;
1745 rwm.on_bi.bi_op_compare = rwm_op_compare;
1746 rwm.on_bi.bi_op_modify = rwm_op_modify;
1747 rwm.on_bi.bi_op_modrdn = rwm_op_modrdn;
1748 rwm.on_bi.bi_op_add = rwm_op_add;
1749 rwm.on_bi.bi_op_delete = rwm_op_delete;
1750 rwm.on_bi.bi_op_unbind = rwm_op_unbind;
1751 rwm.on_bi.bi_extended = rwm_extended;
1753 rwm.on_bi.bi_operational = rwm_operational;
1754 rwm.on_bi.bi_chk_referrals = 0 /* rwm_chk_referrals */ ;
1756 #ifdef ENABLE_REWRITE
1757 rwm.on_bi.bi_connection_init = rwm_conn_init;
1758 rwm.on_bi.bi_connection_destroy = rwm_conn_destroy;
1759 #endif /* ENABLE_REWRITE */
1761 rwm.on_response = rwm_response;
1763 return overlay_register( &rwm );
1766 #if SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC
1768 init_module( int argc, char *argv[] )
1770 return rwm_initialize();
1772 #endif /* SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC */
1774 #endif /* SLAPD_OVER_RWM */