1 /* rwm.c - rewrite/remap operations */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2003-2007 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 {
39 rwm_db_destroy( BackendDB *be );
41 typedef struct rwm_op_cb {
47 rwm_op_cleanup( Operation *op, SlapReply *rs )
49 slap_callback *cb = op->o_callback;
50 rwm_op_state *ros = cb->sc_private;
52 if ( rs->sr_type == REP_RESULT || rs->sr_type == REP_EXTENDED ||
53 op->o_abandon || rs->sr_err == SLAPD_ABANDON ) {
55 op->o_req_dn = ros->ro_dn;
56 op->o_req_ndn = ros->ro_ndn;
58 if ( !BER_BVISNULL( &ros->r_dn )
59 && ros->r_dn.bv_val != ros->r_ndn.bv_val )
61 ch_free( ros->r_dn.bv_val );
62 BER_BVZERO( &ros->r_dn );
65 if ( !BER_BVISNULL( &ros->r_ndn ) ) {
66 ch_free( ros->r_ndn.bv_val );
67 BER_BVZERO( &ros->r_ndn );
70 switch( ros->r_tag ) {
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;
98 case LDAP_REQ_EXTENDED:
99 if ( op->ore_reqdata != ros->ore_reqdata ) {
100 ber_bvfree( op->ore_reqdata );
101 op->ore_reqdata = ros->ore_reqdata;
106 op->o_callback = op->o_callback->sc_next;
107 op->o_tmpfree( cb, op->o_tmpmemctx );
110 return SLAP_CB_CONTINUE;
114 rwm_callback_get( Operation *op, SlapReply *rs )
116 rwm_op_cb *roc = NULL;
118 roc = op->o_tmpalloc( sizeof( struct rwm_op_cb ), op->o_tmpmemctx );
119 roc->cb.sc_cleanup = rwm_op_cleanup;
120 roc->cb.sc_response = NULL;
121 roc->cb.sc_next = op->o_callback;
122 roc->cb.sc_private = &roc->ros;
123 roc->ros.r_tag = op->o_tag;
124 roc->ros.ro_dn = op->o_req_dn;
125 roc->ros.ro_ndn = op->o_req_ndn;
126 roc->ros.o_request = op->o_request;
127 BER_BVZERO( &roc->ros.r_dn );
128 BER_BVZERO( &roc->ros.r_ndn );
135 rwm_op_dn_massage( Operation *op, SlapReply *rs, void *cookie,
138 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
139 struct ldaprwmap *rwmap =
140 (struct ldaprwmap *)on->on_bi.bi_private;
142 struct berval dn = BER_BVNULL,
148 * Rewrite the dn if needed
151 #ifdef ENABLE_REWRITE
152 dc.conn = op->o_conn;
154 dc.ctx = (char *)cookie;
155 #else /* ! ENABLE_REWRITE */
156 dc.tofrom = ((int *)cookie)[0];
158 #endif /* ! ENABLE_REWRITE */
160 /* NOTE: in those cases where only the ndn is available,
161 * and the caller sets op->o_req_dn = op->o_req_ndn,
162 * only rewrite the op->o_req_ndn and use it as
163 * op->o_req_dn as well */
165 if ( op->o_req_dn.bv_val != op->o_req_ndn.bv_val ) {
167 rc = rwm_dn_massage_pretty_normalize( &dc, &op->o_req_dn, &dn, &ndn );
169 rc = rwm_dn_massage_normalize( &dc, &op->o_req_ndn, &ndn );
172 if ( rc != LDAP_SUCCESS ) {
176 if ( ( op->o_req_dn.bv_val != op->o_req_ndn.bv_val && dn.bv_val == op->o_req_dn.bv_val )
177 || ndn.bv_val == op->o_req_ndn.bv_val )
182 if ( op->o_req_dn.bv_val != op->o_req_ndn.bv_val ) {
195 rwm_op_add( Operation *op, SlapReply *rs )
197 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
198 struct ldaprwmap *rwmap =
199 (struct ldaprwmap *)on->on_bi.bi_private;
203 Attribute **ap = NULL;
204 char *olddn = op->o_req_dn.bv_val;
207 rwm_op_cb *roc = rwm_callback_get( op, rs );
209 #ifdef ENABLE_REWRITE
210 rc = rwm_op_dn_massage( op, rs, "addDN", &roc->ros );
211 #else /* ! ENABLE_REWRITE */
213 rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros );
214 #endif /* ! ENABLE_REWRITE */
215 if ( rc != LDAP_SUCCESS ) {
216 op->o_bd->bd_info = (BackendInfo *)on->on_info;
217 send_ldap_error( op, rs, rc, "addDN massage error" );
221 if ( olddn != op->o_req_dn.bv_val ) {
222 ber_bvreplace( &op->ora_e->e_name, &op->o_req_dn );
223 ber_bvreplace( &op->ora_e->e_nname, &op->o_req_ndn );
226 /* Count number of attributes in entry */
227 isupdate = be_shadow_update( op );
228 for ( i = 0, ap = &op->oq_add.rs_e->e_attrs; *ap; ) {
231 if ( (*ap)->a_desc == slap_schema.si_ad_objectClass ||
232 (*ap)->a_desc == slap_schema.si_ad_structuralObjectClass )
236 for ( last = 0; !BER_BVISNULL( &(*ap)->a_vals[ last ] ); last++ )
239 for ( j = 0; !BER_BVISNULL( &(*ap)->a_vals[ j ] ); j++ ) {
240 struct ldapmapping *mapping = NULL;
242 ( void )rwm_mapping( &rwmap->rwm_oc, &(*ap)->a_vals[ j ],
244 if ( mapping == NULL ) {
245 if ( rwmap->rwm_at.drop_missing ) {
246 /* FIXME: we allow to remove objectClasses as well;
247 * if the resulting entry is inconsistent, that's
248 * the relayed database's business...
250 ch_free( (*ap)->a_vals[ j ].bv_val );
252 (*ap)->a_vals[ j ] = (*ap)->a_vals[ last ];
254 BER_BVZERO( &(*ap)->a_vals[ last ] );
260 ch_free( (*ap)->a_vals[ j ].bv_val );
261 ber_dupbv( &(*ap)->a_vals[ j ], &mapping->m_dst );
265 } else if ( !isupdate && !get_relax( op ) && (*ap)->a_desc->ad_type->sat_no_user_mod )
270 struct ldapmapping *mapping = NULL;
272 ( void )rwm_mapping( &rwmap->rwm_at, &(*ap)->a_desc->ad_cname,
274 if ( mapping == NULL ) {
275 if ( rwmap->rwm_at.drop_missing ) {
280 if ( (*ap)->a_desc->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName
281 || ( mapping != NULL && mapping->m_dst_ad->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName ) )
284 * FIXME: rewrite could fail; in this case
285 * the operation should give up, right?
287 #ifdef ENABLE_REWRITE
288 rc = rwm_dnattr_rewrite( op, rs, "addAttrDN",
290 (*ap)->a_nvals ? &(*ap)->a_nvals : NULL );
291 #else /* ! ENABLE_REWRITE */
293 rc = rwm_dnattr_rewrite( op, rs, &rc, (*ap)->a_vals,
294 (*ap)->a_nvals ? &(*ap)->a_nvals : NULL );
295 #endif /* ! ENABLE_REWRITE */
300 } else if ( (*ap)->a_desc == slap_schema.si_ad_ref ) {
301 #ifdef ENABLE_REWRITE
302 rc = rwm_referral_rewrite( op, rs, "referralAttrDN",
304 (*ap)->a_nvals ? &(*ap)->a_nvals : NULL );
305 #else /* ! ENABLE_REWRITE */
307 rc = rwm_referral_rewrite( op, rs, &rc, (*ap)->a_vals,
308 (*ap)->a_nvals ? &(*ap)->a_nvals : NULL );
309 #endif /* ! ENABLE_REWRITE */
310 if ( rc != LDAP_SUCCESS ) {
315 if ( mapping != NULL ) {
316 assert( mapping->m_dst_ad != NULL );
317 (*ap)->a_desc = mapping->m_dst_ad;
326 /* FIXME: leaking attribute/values? */
333 op->o_callback = &roc->cb;
335 return SLAP_CB_CONTINUE;
338 #ifdef ENABLE_REWRITE
340 rwm_conn_init( BackendDB *be, Connection *conn )
342 slap_overinst *on = (slap_overinst *) be->bd_info;
343 struct ldaprwmap *rwmap =
344 (struct ldaprwmap *)on->on_bi.bi_private;
346 ( void )rewrite_session_init( rwmap->rwm_rw, conn );
348 return SLAP_CB_CONTINUE;
352 rwm_conn_destroy( BackendDB *be, Connection *conn )
354 slap_overinst *on = (slap_overinst *) be->bd_info;
355 struct ldaprwmap *rwmap =
356 (struct ldaprwmap *)on->on_bi.bi_private;
358 ( void )rewrite_session_delete( rwmap->rwm_rw, conn );
360 return SLAP_CB_CONTINUE;
362 #endif /* ENABLE_REWRITE */
365 rwm_op_bind( Operation *op, SlapReply *rs )
367 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
370 rwm_op_cb *roc = rwm_callback_get( op, rs );
372 #ifdef ENABLE_REWRITE
373 rc = rwm_op_dn_massage( op, rs, "bindDN", &roc->ros );
374 #else /* ! ENABLE_REWRITE */
376 rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros );
377 #endif /* ! ENABLE_REWRITE */
378 if ( rc != LDAP_SUCCESS ) {
379 op->o_bd->bd_info = (BackendInfo *)on->on_info;
380 send_ldap_error( op, rs, rc, "bindDN massage error" );
384 op->o_callback = &roc->cb;
386 return SLAP_CB_CONTINUE;
390 rwm_op_unbind( Operation *op, SlapReply *rs )
392 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
393 struct ldaprwmap *rwmap =
394 (struct ldaprwmap *)on->on_bi.bi_private;
396 #ifdef ENABLE_REWRITE
397 rewrite_session_delete( rwmap->rwm_rw, op->o_conn );
398 #endif /* ENABLE_REWRITE */
400 return SLAP_CB_CONTINUE;
404 rwm_op_compare( Operation *op, SlapReply *rs )
406 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
407 struct ldaprwmap *rwmap =
408 (struct ldaprwmap *)on->on_bi.bi_private;
411 struct berval mapped_vals[2] = { BER_BVNULL, BER_BVNULL };
413 rwm_op_cb *roc = rwm_callback_get( op, rs );
415 #ifdef ENABLE_REWRITE
416 rc = rwm_op_dn_massage( op, rs, "compareDN", &roc->ros );
417 #else /* ! ENABLE_REWRITE */
419 rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros );
420 #endif /* ! ENABLE_REWRITE */
421 if ( rc != LDAP_SUCCESS ) {
422 op->o_bd->bd_info = (BackendInfo *)on->on_info;
423 send_ldap_error( op, rs, rc, "compareDN massage error" );
427 /* if the attribute is an objectClass, try to remap its value */
428 if ( op->orc_ava->aa_desc == slap_schema.si_ad_objectClass
429 || op->orc_ava->aa_desc == slap_schema.si_ad_structuralObjectClass )
431 rwm_map( &rwmap->rwm_oc, &op->orc_ava->aa_value,
432 &mapped_vals[0], RWM_MAP );
433 if ( BER_BVISNULL( &mapped_vals[0] ) || BER_BVISEMPTY( &mapped_vals[0] ) )
435 op->o_bd->bd_info = (BackendInfo *)on->on_info;
436 send_ldap_error( op, rs, LDAP_OTHER, "compare objectClass map error" );
439 } else if ( mapped_vals[0].bv_val != op->orc_ava->aa_value.bv_val ) {
440 ber_dupbv_x( &op->orc_ava->aa_value, &mapped_vals[0],
445 struct ldapmapping *mapping = NULL;
446 AttributeDescription *ad = op->orc_ava->aa_desc;
448 ( void )rwm_mapping( &rwmap->rwm_at, &op->orc_ava->aa_desc->ad_cname,
450 if ( mapping == NULL ) {
451 if ( rwmap->rwm_at.drop_missing ) {
452 op->o_bd->bd_info = (BackendInfo *)on->on_info;
453 send_ldap_error( op, rs, LDAP_OTHER, "compare attributeType map error" );
458 assert( mapping->m_dst_ad != NULL );
459 ad = mapping->m_dst_ad;
462 if ( op->orc_ava->aa_desc->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName
463 || ( mapping != NULL && mapping->m_dst_ad->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName ) )
465 struct berval *mapped_valsp[2];
467 mapped_valsp[0] = &mapped_vals[0];
468 mapped_valsp[1] = &mapped_vals[1];
470 mapped_vals[0] = op->orc_ava->aa_value;
472 #ifdef ENABLE_REWRITE
473 rc = rwm_dnattr_rewrite( op, rs, "compareAttrDN", NULL, mapped_valsp );
474 #else /* ! ENABLE_REWRITE */
476 rc = rwm_dnattr_rewrite( op, rs, &rc, NULL, mapped_valsp );
477 #endif /* ! ENABLE_REWRITE */
479 if ( rc != LDAP_SUCCESS ) {
480 op->o_bd->bd_info = (BackendInfo *)on->on_info;
481 send_ldap_error( op, rs, rc, "compareAttrDN massage error" );
485 if ( mapped_vals[ 0 ].bv_val != op->orc_ava->aa_value.bv_val ) {
486 /* NOTE: if we get here, rwm_dnattr_rewrite()
487 * already freed the old value, so now
489 ber_dupbv_x( &op->orc_ava->aa_value, &mapped_vals[0],
491 ber_memfree_x( mapped_vals[ 0 ].bv_val, NULL );
494 op->orc_ava->aa_desc = ad;
497 op->o_callback = &roc->cb;
499 return SLAP_CB_CONTINUE;
503 rwm_op_delete( Operation *op, SlapReply *rs )
505 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
508 rwm_op_cb *roc = rwm_callback_get( op, rs );
510 #ifdef ENABLE_REWRITE
511 rc = rwm_op_dn_massage( op, rs, "deleteDN", &roc->ros );
512 #else /* ! ENABLE_REWRITE */
514 rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros );
515 #endif /* ! ENABLE_REWRITE */
516 if ( rc != LDAP_SUCCESS ) {
517 op->o_bd->bd_info = (BackendInfo *)on->on_info;
518 send_ldap_error( op, rs, rc, "deleteDN massage error" );
522 op->o_callback = &roc->cb;
524 return SLAP_CB_CONTINUE;
528 rwm_op_modify( Operation *op, SlapReply *rs )
530 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
531 struct ldaprwmap *rwmap =
532 (struct ldaprwmap *)on->on_bi.bi_private;
538 rwm_op_cb *roc = rwm_callback_get( op, rs );
540 #ifdef ENABLE_REWRITE
541 rc = rwm_op_dn_massage( op, rs, "modifyDN", &roc->ros );
542 #else /* ! ENABLE_REWRITE */
544 rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros );
545 #endif /* ! ENABLE_REWRITE */
546 if ( rc != LDAP_SUCCESS ) {
547 op->o_bd->bd_info = (BackendInfo *)on->on_info;
548 send_ldap_error( op, rs, rc, "modifyDN massage error" );
552 isupdate = be_shadow_update( op );
553 for ( mlp = &op->oq_modify.rs_modlist; *mlp; ) {
556 struct ldapmapping *mapping = NULL;
558 /* duplicate the modlist */
559 ml = ch_malloc( sizeof( Modifications ));
563 if ( ml->sml_desc == slap_schema.si_ad_objectClass
564 || ml->sml_desc == slap_schema.si_ad_structuralObjectClass )
568 } else if ( !isupdate && !get_relax( op ) && ml->sml_desc->ad_type->sat_no_user_mod )
575 drop_missing = rwm_mapping( &rwmap->rwm_at,
576 &ml->sml_desc->ad_cname,
578 if ( drop_missing || ( mapping != NULL && BER_BVISNULL( &mapping->m_dst ) ) )
584 if ( ml->sml_values != NULL ) {
588 for ( num = 0; !BER_BVISNULL( &ml->sml_values[ num ] ); num++ )
591 bva = ch_malloc( (num+1) * sizeof( struct berval ));
592 for (i=0; i<num; i++)
593 ber_dupbv( &bva[i], &ml->sml_values[i] );
594 BER_BVZERO( &bva[i] );
595 ml->sml_values = bva;
597 if ( ml->sml_nvalues ) {
598 bva = ch_malloc( (num+1) * sizeof( struct berval ));
599 for (i=0; i<num; i++)
600 ber_dupbv( &bva[i], &ml->sml_nvalues[i] );
601 BER_BVZERO( &bva[i] );
602 ml->sml_nvalues = bva;
610 for ( j = 0; !BER_BVISNULL( &ml->sml_values[ j ] ); j++ ) {
611 struct ldapmapping *oc_mapping = NULL;
613 ( void )rwm_mapping( &rwmap->rwm_oc, &ml->sml_values[ j ],
614 &oc_mapping, RWM_MAP );
615 if ( oc_mapping == NULL ) {
616 if ( rwmap->rwm_at.drop_missing ) {
617 /* FIXME: we allow to remove objectClasses as well;
618 * if the resulting entry is inconsistent, that's
619 * the relayed database's business...
622 ch_free( ml->sml_values[ j ].bv_val );
623 ml->sml_values[ j ] = ml->sml_values[ last ];
625 BER_BVZERO( &ml->sml_values[ last ] );
631 ch_free( ml->sml_values[ j ].bv_val );
632 ber_dupbv( &ml->sml_values[ j ], &oc_mapping->m_dst );
637 if ( ml->sml_desc->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName
638 || ( mapping != NULL && mapping->m_dst_ad->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName ) )
640 #ifdef ENABLE_REWRITE
641 rc = rwm_dnattr_rewrite( op, rs, "modifyAttrDN",
643 ml->sml_nvalues ? &ml->sml_nvalues : NULL );
644 #else /* ! ENABLE_REWRITE */
646 rc = rwm_dnattr_rewrite( op, rs, &rc,
648 ml->sml_nvalues ? &ml->sml_nvalues : NULL );
649 #endif /* ! ENABLE_REWRITE */
651 } else if ( ml->sml_desc == slap_schema.si_ad_ref ) {
652 #ifdef ENABLE_REWRITE
653 rc = rwm_referral_rewrite( op, rs,
656 ml->sml_nvalues ? &ml->sml_nvalues : NULL );
657 #else /* ! ENABLE_REWRITE */
659 rc = rwm_referral_rewrite( op, rs, &rc,
661 ml->sml_nvalues ? &ml->sml_nvalues : NULL );
662 #endif /* ! ENABLE_REWRITE */
663 if ( rc != LDAP_SUCCESS ) {
668 if ( rc != LDAP_SUCCESS ) {
675 if ( mapping != NULL ) {
676 /* use new attribute description */
677 assert( mapping->m_dst_ad != NULL );
678 ml->sml_desc = mapping->m_dst_ad;
686 *mlp = (*mlp)->sml_next;
687 slap_mod_free( &ml->sml_mod, 0 );
691 op->o_callback = &roc->cb;
693 return SLAP_CB_CONTINUE;
697 rwm_op_modrdn( Operation *op, SlapReply *rs )
699 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
700 struct ldaprwmap *rwmap =
701 (struct ldaprwmap *)on->on_bi.bi_private;
705 rwm_op_cb *roc = rwm_callback_get( op, rs );
707 if ( op->orr_newSup ) {
709 struct berval nnewSup = BER_BVNULL;
710 struct berval newSup = BER_BVNULL;
713 * Rewrite the new superior, if defined and required
716 #ifdef ENABLE_REWRITE
717 dc.conn = op->o_conn;
719 dc.ctx = "newSuperiorDN";
720 #else /* ! ENABLE_REWRITE */
723 #endif /* ! ENABLE_REWRITE */
724 newSup = *op->orr_newSup;
725 nnewSup = *op->orr_nnewSup;
726 rc = rwm_dn_massage_pretty_normalize( &dc, op->orr_newSup, &newSup, &nnewSup );
727 if ( rc != LDAP_SUCCESS ) {
728 op->o_bd->bd_info = (BackendInfo *)on->on_info;
729 send_ldap_error( op, rs, rc, "newSuperiorDN massage error" );
733 if ( op->orr_newSup->bv_val != newSup.bv_val ) {
734 op->orr_newSup = op->o_tmpalloc( sizeof( struct berval ),
736 op->orr_nnewSup = op->o_tmpalloc( sizeof( struct berval ),
738 *op->orr_newSup = newSup;
739 *op->orr_nnewSup = nnewSup;
744 * Rewrite the dn, if needed
746 #ifdef ENABLE_REWRITE
747 rc = rwm_op_dn_massage( op, rs, "renameDN", &roc->ros );
748 #else /* ! ENABLE_REWRITE */
750 rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros );
751 #endif /* ! ENABLE_REWRITE */
752 if ( rc != LDAP_SUCCESS ) {
753 op->o_bd->bd_info = (BackendInfo *)on->on_info;
754 send_ldap_error( op, rs, rc, "renameDN massage error" );
755 if ( op->orr_newSup != roc->ros.orr_newSup ) {
756 ch_free( op->orr_newSup->bv_val );
757 ch_free( op->orr_nnewSup->bv_val );
758 op->o_tmpfree( op->orr_newSup, op->o_tmpmemctx );
759 op->o_tmpfree( op->orr_nnewSup, op->o_tmpmemctx );
760 op->orr_newSup = roc->ros.orr_newSup;
761 op->orr_nnewSup = roc->ros.orr_nnewSup;
766 /* TODO: rewrite newRDN, attribute types,
767 * values of DN-valued attributes ... */
769 op->o_callback = &roc->cb;
771 return SLAP_CB_CONTINUE;
776 rwm_swap_attrs( Operation *op, SlapReply *rs )
778 slap_callback *cb = op->o_callback;
779 rwm_op_state *ros = cb->sc_private;
781 rs->sr_attrs = ros->ors_attrs;
783 return SLAP_CB_CONTINUE;
787 rwm_op_search( Operation *op, SlapReply *rs )
789 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
790 struct ldaprwmap *rwmap =
791 (struct ldaprwmap *)on->on_bi.bi_private;
796 struct berval fstr = BER_BVNULL;
799 AttributeName *an = NULL;
803 rwm_op_cb *roc = rwm_callback_get( op, rs );
805 #ifdef ENABLE_REWRITE
806 rc = rewrite_session_var_set( rwmap->rwm_rw, op->o_conn,
807 "searchFilter", op->ors_filterstr.bv_val );
808 if ( rc == LDAP_SUCCESS )
809 rc = rwm_op_dn_massage( op, rs, "searchDN", &roc->ros );
810 #else /* ! ENABLE_REWRITE */
812 rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros );
813 #endif /* ! ENABLE_REWRITE */
814 if ( rc != LDAP_SUCCESS ) {
815 text = "searchDN massage error";
820 * Rewrite the dn if needed
823 #ifdef ENABLE_REWRITE
824 dc.conn = op->o_conn;
826 dc.ctx = "searchFilterAttrDN";
827 #else /* ! ENABLE_REWRITE */
830 #endif /* ! ENABLE_REWRITE */
832 rc = rwm_filter_map_rewrite( op, &dc, op->ors_filter, &fstr );
833 if ( rc != LDAP_SUCCESS ) {
834 text = "searchFilter/searchFilterAttrDN massage error";
838 f = str2filter_x( op, fstr.bv_val );
841 text = "massaged filter parse error";
846 op->ors_filterstr = fstr;
848 rc = rwm_map_attrnames( &rwmap->rwm_at, &rwmap->rwm_oc,
849 op->ors_attrs, &an, RWM_MAP );
850 if ( rc != LDAP_SUCCESS ) {
851 text = "attribute list mapping error";
856 roc->cb.sc_response = rwm_swap_attrs;
858 op->o_callback = &roc->cb;
860 return SLAP_CB_CONTINUE;
868 filter_free_x( op, f );
871 if ( !BER_BVISNULL( &fstr ) ) {
872 ch_free( fstr.bv_val );
875 op->oq_search = roc->ros.oq_search;
877 op->o_bd->bd_info = (BackendInfo *)on->on_info;
878 send_ldap_error( op, rs, rc, text );
885 rwm_exop_passwd( Operation *op, SlapReply *rs )
887 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
891 struct berval id = BER_BVNULL,
894 BerElement *ber = NULL;
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 ber = ber_alloc_t( LBER_USE_DER );
940 rs->sr_err = LDAP_OTHER;
941 rs->sr_text = "No memory";
944 ber_printf( ber, "{" );
945 if ( !BER_BVISNULL( &id )) {
946 ber_printf( ber, "tO", LDAP_TAG_EXOP_MODIFY_PASSWD_ID,
949 if ( !BER_BVISNULL( &pwold )) {
950 ber_printf( ber, "tO", LDAP_TAG_EXOP_MODIFY_PASSWD_OLD, &pwold );
952 if ( !BER_BVISNULL( &pwnew )) {
953 ber_printf( ber, "tO", LDAP_TAG_EXOP_MODIFY_PASSWD_NEW, &pwnew );
955 ber_printf( ber, "N}" );
956 ber_flatten( ber, &op->ore_reqdata );
959 op->o_callback = &roc->cb;
961 return SLAP_CB_CONTINUE;
966 BI_op_extended *extended;
968 { BER_BVC(LDAP_EXOP_MODIFY_PASSWD), rwm_exop_passwd },
973 rwm_extended( Operation *op, SlapReply *rs )
975 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
981 for ( i = 0; exop_table[i].extended != NULL; i++ ) {
982 if ( bvmatch( &exop_table[i].oid, &op->oq_extended.rs_reqoid ) )
984 rc = exop_table[i].extended( op, rs );
989 case SLAP_CB_CONTINUE:
994 send_ldap_result( op, rs );
1001 roc = rwm_callback_get( op, rs );
1003 #ifdef ENABLE_REWRITE
1004 rc = rwm_op_dn_massage( op, rs, "extendedDN", &roc->ros );
1005 #else /* ! ENABLE_REWRITE */
1007 rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros );
1008 #endif /* ! ENABLE_REWRITE */
1009 if ( rc != LDAP_SUCCESS ) {
1010 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1011 send_ldap_error( op, rs, rc, "extendedDN massage error" );
1015 /* TODO: rewrite/map extended data ? ... */
1016 op->o_callback = &roc->cb;
1018 return SLAP_CB_CONTINUE;
1022 rwm_matched( Operation *op, SlapReply *rs )
1024 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
1025 struct ldaprwmap *rwmap =
1026 (struct ldaprwmap *)on->on_bi.bi_private;
1028 struct berval dn, mdn;
1032 if ( rs->sr_matched == NULL ) {
1033 return SLAP_CB_CONTINUE;
1037 #ifdef ENABLE_REWRITE
1038 dc.conn = op->o_conn;
1040 dc.ctx = "matchedDN";
1041 #else /* ! ENABLE_REWRITE */
1044 #endif /* ! ENABLE_REWRITE */
1045 ber_str2bv( rs->sr_matched, 0, 0, &dn );
1047 rc = rwm_dn_massage_pretty( &dc, &dn, &mdn );
1048 if ( rc != LDAP_SUCCESS ) {
1050 rs->sr_text = "Rewrite error";
1054 if ( mdn.bv_val != dn.bv_val ) {
1055 if ( rs->sr_flags & REP_MATCHED_MUSTBEFREED ) {
1056 ch_free( (void *)rs->sr_matched );
1059 rs->sr_flags |= REP_MATCHED_MUSTBEFREED;
1061 rs->sr_matched = mdn.bv_val;
1064 return SLAP_CB_CONTINUE;
1068 rwm_attrs( Operation *op, SlapReply *rs, Attribute** a_first, int stripEntryDN )
1070 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
1071 struct ldaprwmap *rwmap =
1072 (struct ldaprwmap *)on->on_bi.bi_private;
1080 * Rewrite the dn attrs, if needed
1083 #ifdef ENABLE_REWRITE
1084 dc.conn = op->o_conn;
1086 #else /* ! ENABLE_REWRITE */
1089 #endif /* ! ENABLE_REWRITE */
1091 /* FIXME: the entries are in the remote mapping form;
1092 * so we need to select those attributes we are willing
1093 * to return, and remap them accordingly */
1095 /* FIXME: in principle, one could map an attribute
1096 * on top of another, which already exists.
1097 * As such, in the end there might exist more than
1098 * one instance of an attribute.
1099 * We should at least check if this occurs, and issue
1100 * an error (because multiple instances of attrs in
1101 * response are not valid), or merge the values (what
1102 * about duplicate values?) */
1103 isupdate = be_shadow_update( op );
1104 for ( ap = a_first; *ap; ) {
1105 struct ldapmapping *mapping = NULL;
1110 if ( SLAP_OPATTRS( rs->sr_attr_flags ) && is_at_operational( (*ap)->a_desc->ad_type ) )
1115 if ( op->ors_attrs != NULL &&
1116 !SLAP_USERATTRS( rs->sr_attr_flags ) &&
1117 !ad_inlist( (*ap)->a_desc, op->ors_attrs ) )
1122 drop_missing = rwm_mapping( &rwmap->rwm_at,
1123 &(*ap)->a_desc->ad_cname, &mapping, RWM_REMAP );
1124 if ( drop_missing || ( mapping != NULL && BER_BVISEMPTY( &mapping->m_dst ) ) )
1129 if ( mapping != NULL ) {
1130 (*ap)->a_desc = mapping->m_dst_ad;
1134 if ( (*ap)->a_desc == slap_schema.si_ad_entryDN ) {
1135 if ( stripEntryDN ) {
1136 /* will be generated by frontend */
1140 } else if ( !isupdate
1142 && (*ap)->a_desc->ad_type->sat_no_user_mod
1143 && (*ap)->a_desc->ad_type != slap_schema.si_at_undefined )
1148 for ( last = 0; !BER_BVISNULL( &(*ap)->a_vals[last] ); last++ )
1152 /* empty? leave it in place because of attrsonly and vlv */
1157 if ( (*ap)->a_desc == slap_schema.si_ad_objectClass
1158 || (*ap)->a_desc == slap_schema.si_ad_structuralObjectClass )
1162 for ( bv = (*ap)->a_vals; !BER_BVISNULL( bv ); bv++ ) {
1163 struct berval mapped;
1165 rwm_map( &rwmap->rwm_oc, &bv[0], &mapped, RWM_REMAP );
1166 if ( BER_BVISNULL( &mapped ) || BER_BVISEMPTY( &mapped ) ) {
1167 ch_free( bv[0].bv_val );
1168 BER_BVZERO( &bv[0] );
1169 if ( &(*ap)->a_vals[last] > &bv[0] ) {
1170 bv[0] = (*ap)->a_vals[last];
1171 BER_BVZERO( &(*ap)->a_vals[last] );
1176 } else if ( mapped.bv_val != bv[0].bv_val ) {
1178 * FIXME: after LBER_FREEing
1179 * the value is replaced by
1180 * ch_alloc'ed memory
1182 ber_bvreplace( &bv[0], &mapped );
1187 * It is necessary to try to rewrite attributes with
1188 * dn syntax because they might be used in ACLs as
1189 * members of groups; since ACLs are applied to the
1190 * rewritten stuff, no dn-based subject clause could
1191 * be used at the ldap backend side (see
1192 * http://www.OpenLDAP.org/faq/data/cache/452.html)
1193 * The problem can be overcome by moving the dn-based
1194 * ACLs to the target directory server, and letting
1195 * everything pass thru the ldap backend. */
1196 /* FIXME: handle distinguishedName-like syntaxes, like
1197 * nameAndOptionalUID */
1198 } else if ( (*ap)->a_desc->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName
1199 || ( mapping != NULL && mapping->m_src_ad->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName ) )
1201 #ifdef ENABLE_REWRITE
1202 dc.ctx = "searchAttrDN";
1203 #endif /* ENABLE_REWRITE */
1204 rc = rwm_dnattr_result_rewrite( &dc, (*ap)->a_vals );
1205 if ( rc != LDAP_SUCCESS ) {
1209 } else if ( (*ap)->a_desc == slap_schema.si_ad_ref ) {
1210 #ifdef ENABLE_REWRITE
1211 dc.ctx = "searchAttrDN";
1212 #endif /* ENABLE_REWRITE */
1213 rc = rwm_referral_result_rewrite( &dc, (*ap)->a_vals );
1214 if ( rc != LDAP_SUCCESS ) {
1219 if ( mapping != NULL ) {
1220 /* rewrite the attribute description */
1221 assert( mapping->m_dst_ad != NULL );
1222 (*ap)->a_desc = mapping->m_dst_ad;
1226 ap = &(*ap)->a_next;
1231 *ap = (*ap)->a_next;
1240 rwm_send_entry( Operation *op, SlapReply *rs )
1242 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
1243 struct ldaprwmap *rwmap =
1244 (struct ldaprwmap *)on->on_bi.bi_private;
1248 struct berval dn = BER_BVNULL,
1253 assert( rs->sr_entry != NULL );
1256 * Rewrite the dn of the result, if needed
1259 #ifdef ENABLE_REWRITE
1260 dc.conn = op->o_conn;
1262 dc.ctx = "searchEntryDN";
1263 #else /* ! ENABLE_REWRITE */
1266 #endif /* ! ENABLE_REWRITE */
1269 flags = rs->sr_flags;
1270 if ( !( rs->sr_flags & REP_ENTRY_MODIFIABLE ) ) {
1271 /* FIXME: all we need to duplicate are:
1274 * - attributes that are requested
1275 * - no values if attrsonly is set
1280 rc = LDAP_NO_MEMORY;
1284 flags &= ~REP_ENTRY_MUSTRELEASE;
1285 flags |= ( REP_ENTRY_MODIFIABLE | REP_ENTRY_MUSTBEFREED );
1289 * Note: this may fail if the target host(s) schema differs
1290 * from the one known to the meta, and a DN with unknown
1291 * attributes is returned.
1295 rc = rwm_dn_massage_pretty_normalize( &dc, &e->e_name, &dn, &ndn );
1296 if ( rc != LDAP_SUCCESS ) {
1301 if ( e->e_name.bv_val != dn.bv_val ) {
1302 ch_free( e->e_name.bv_val );
1303 ch_free( e->e_nname.bv_val );
1309 /* TODO: map entry attribute types, objectclasses
1310 * and dn-valued attribute values */
1312 /* FIXME: the entries are in the remote mapping form;
1313 * so we need to select those attributes we are willing
1314 * to return, and remap them accordingly */
1315 (void)rwm_attrs( op, rs, &e->e_attrs, 1 );
1317 if ( rs->sr_flags & REP_ENTRY_MUSTRELEASE ) {
1318 be_entry_release_rw( op, rs->sr_entry, 0 );
1322 rs->sr_flags = flags;
1324 return SLAP_CB_CONTINUE;
1327 if ( e != NULL && e != rs->sr_entry ) {
1328 if ( e->e_name.bv_val == dn.bv_val ) {
1329 BER_BVZERO( &e->e_name );
1332 if ( e->e_nname.bv_val == ndn.bv_val ) {
1333 BER_BVZERO( &e->e_nname );
1339 if ( !BER_BVISNULL( &dn ) ) {
1340 ch_free( dn.bv_val );
1343 if ( !BER_BVISNULL( &ndn ) ) {
1344 ch_free( ndn.bv_val );
1351 rwm_operational( Operation *op, SlapReply *rs )
1353 /* FIXME: the entries are in the remote mapping form;
1354 * so we need to select those attributes we are willing
1355 * to return, and remap them accordingly */
1356 if ( rs->sr_operational_attrs ) {
1357 rwm_attrs( op, rs, &rs->sr_operational_attrs, 1 );
1360 return SLAP_CB_CONTINUE;
1364 /* don't use this; it cannot be reverted, and leaves op->o_req_dn
1365 * rewritten for subsequent operations; fine for plain suffixmassage,
1366 * but destroys everything else */
1368 rwm_chk_referrals( Operation *op, SlapReply *rs )
1370 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
1373 #ifdef ENABLE_REWRITE
1374 rc = rwm_op_dn_massage( op, rs, "referralCheckDN" );
1375 #else /* ! ENABLE_REWRITE */
1377 rc = rwm_op_dn_massage( op, rs, &rc );
1378 #endif /* ! ENABLE_REWRITE */
1379 if ( rc != LDAP_SUCCESS ) {
1380 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1381 send_ldap_error( op, rs, rc, "referralCheckDN massage error" );
1385 return SLAP_CB_CONTINUE;
1397 #ifdef ENABLE_REWRITE
1398 slap_overinst *on = (slap_overinst *) be->bd_info;
1399 struct ldaprwmap *rwmap =
1400 (struct ldaprwmap *)on->on_bi.bi_private;
1402 return rewrite_parse( rwmap->rwm_rw,
1403 fname, lineno, argc, argv );
1405 #else /* !ENABLE_REWRITE */
1406 fprintf( stderr, "%s: line %d: rewrite capabilities "
1407 "are not enabled\n", fname, lineno );
1408 #endif /* !ENABLE_REWRITE */
1414 rwm_suffixmassage_config(
1421 slap_overinst *on = (slap_overinst *) be->bd_info;
1422 struct ldaprwmap *rwmap =
1423 (struct ldaprwmap *)on->on_bi.bi_private;
1425 struct berval bvnc, nvnc, pvnc, brnc, nrnc, prnc;
1427 #ifdef ENABLE_REWRITE
1429 #endif /* ENABLE_REWRITE */
1434 * suffixmassage [<suffix>] <massaged suffix>
1436 * the [<suffix>] field must be defined as a valid suffix
1437 * for the current database;
1438 * the <massaged suffix> shouldn't have already been
1439 * defined as a valid suffix for the current server
1442 if ( be->be_suffix == NULL ) {
1443 fprintf( stderr, "%s: line %d: "
1444 " \"suffixMassage [<suffix>]"
1445 " <massaged suffix>\" without "
1446 "<suffix> part requires database "
1447 "suffix be defined first.\n",
1451 bvnc = be->be_suffix[ 0 ];
1454 } else if ( argc == 3 ) {
1455 ber_str2bv( argv[ 1 ], 0, 0, &bvnc );
1459 fprintf( stderr, "%s: line %d: syntax is"
1460 " \"suffixMassage [<suffix>]"
1461 " <massaged suffix>\"\n",
1466 if ( dnPrettyNormal( NULL, &bvnc, &pvnc, &nvnc, NULL ) != LDAP_SUCCESS ) {
1467 fprintf( stderr, "%s: line %d: suffix DN %s is invalid\n",
1468 fname, lineno, bvnc.bv_val );
1472 ber_str2bv( argv[ massaged ], 0, 0, &brnc );
1473 if ( dnPrettyNormal( NULL, &brnc, &prnc, &nrnc, NULL ) != LDAP_SUCCESS ) {
1474 fprintf( stderr, "%s: line %d: suffix DN %s is invalid\n",
1475 fname, lineno, brnc.bv_val );
1476 free( nvnc.bv_val );
1477 free( pvnc.bv_val );
1481 #ifdef ENABLE_REWRITE
1483 * The suffix massaging is emulated
1484 * by means of the rewrite capabilities
1486 rc = rwm_suffix_massage_config( rwmap->rwm_rw,
1487 &pvnc, &nvnc, &prnc, &nrnc );
1488 free( nvnc.bv_val );
1489 free( pvnc.bv_val );
1490 free( nrnc.bv_val );
1491 free( prnc.bv_val );
1495 #else /* !ENABLE_REWRITE */
1496 ber_bvarray_add( &rwmap->rwm_suffix_massage, &pvnc );
1497 ber_bvarray_add( &rwmap->rwm_suffix_massage, &nvnc );
1499 ber_bvarray_add( &rwmap->rwm_suffix_massage, &prnc );
1500 ber_bvarray_add( &rwmap->rwm_suffix_massage, &nrnc );
1501 #endif /* !ENABLE_REWRITE */
1514 slap_overinst *on = (slap_overinst *) be->bd_info;
1515 struct ldaprwmap *rwmap =
1516 (struct ldaprwmap *)on->on_bi.bi_private;
1518 /* objectclass/attribute mapping */
1519 return rwm_map_config( &rwmap->rwm_oc,
1521 fname, lineno, argc, argv );
1525 rwm_response( Operation *op, SlapReply *rs )
1527 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
1528 struct ldaprwmap *rwmap =
1529 (struct ldaprwmap *)on->on_bi.bi_private;
1533 if ( op->o_tag == LDAP_REQ_SEARCH && rs->sr_type == REP_SEARCH ) {
1534 return rwm_send_entry( op, rs );
1537 switch( op->o_tag ) {
1538 case LDAP_REQ_SEARCH:
1541 case LDAP_REQ_DELETE:
1542 case LDAP_REQ_MODRDN:
1543 case LDAP_REQ_MODIFY:
1544 case LDAP_REQ_COMPARE:
1545 case LDAP_REQ_EXTENDED:
1550 * Rewrite the dn of the referrals, if needed
1553 #ifdef ENABLE_REWRITE
1554 dc.conn = op->o_conn;
1556 dc.ctx = "referralDN";
1557 #else /* ! ENABLE_REWRITE */
1560 #endif /* ! ENABLE_REWRITE */
1561 rc = rwm_referral_result_rewrite( &dc, rs->sr_ref );
1562 if ( rc != LDAP_SUCCESS ) {
1567 rc = rwm_matched( op, rs );
1571 rc = SLAP_CB_CONTINUE;
1586 slap_overinst *on = (slap_overinst *) be->bd_info;
1587 struct ldaprwmap *rwmap =
1588 (struct ldaprwmap *)on->on_bi.bi_private;
1593 if ( strncasecmp( argv[ 0 ], "rwm-", STRLENOF( "rwm-" ) ) == 0 ) {
1595 argv[ 0 ] = &argv0[ STRLENOF( "rwm-" ) ];
1598 if ( strncasecmp( argv[0], "rewrite", STRLENOF("rewrite") ) == 0 ) {
1599 rc = rwm_rw_config( be, fname, lineno, argc, argv );
1601 } else if ( strcasecmp( argv[0], "map" ) == 0 ) {
1602 rc = rwm_m_config( be, fname, lineno, argc, argv );
1604 } else if ( strcasecmp( argv[0], "suffixmassage" ) == 0 ) {
1605 rc = rwm_suffixmassage_config( be, fname, lineno, argc, argv );
1607 } else if ( strcasecmp( argv[0], "t-f-support" ) == 0 ) {
1610 "%s: line %d: \"t-f-support {no|yes|discover}\" needs 1 argument.\n",
1615 if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
1616 rwmap->rwm_flags &= ~(RWM_F_SUPPORT_T_F|RWM_F_SUPPORT_T_F_DISCOVER);
1618 } else if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
1619 rwmap->rwm_flags |= RWM_F_SUPPORT_T_F;
1621 /* TODO: not implemented yet */
1622 } else if ( strcasecmp( argv[ 1 ], "discover" ) == 0 ) {
1624 "%s: line %d: \"discover\" not supported yet "
1625 "in \"t-f-support {no|yes|discover}\".\n",
1629 rwmap->rwm_flags |= RWM_F_SUPPORT_T_F_DISCOVER;
1634 "%s: line %d: unknown value \"%s\" for \"t-f-support {no|yes|discover}\".\n",
1635 fname, lineno, argv[ 1 ] );
1640 rc = SLAP_CONF_UNKNOWN;
1654 slap_overinst *on = (slap_overinst *) be->bd_info;
1655 struct ldaprwmap *rwmap;
1656 #ifdef ENABLE_REWRITE
1658 #endif /* ENABLE_REWRITE */
1661 rwmap = (struct ldaprwmap *)ch_calloc( 1, sizeof( struct ldaprwmap ) );
1663 #ifdef ENABLE_REWRITE
1664 rwmap->rwm_rw = rewrite_info_init( REWRITE_MODE_USE_DEFAULT );
1665 if ( rwmap->rwm_rw == NULL ) {
1670 /* this rewriteContext by default must be null;
1671 * rules can be added if required */
1672 rargv[ 0 ] = "rewriteContext";
1673 rargv[ 1 ] = "searchFilter";
1675 rewrite_parse( rwmap->rwm_rw, "<suffix massage>", 1, 2, rargv );
1677 rargv[ 0 ] = "rewriteContext";
1678 rargv[ 1 ] = "default";
1680 rewrite_parse( rwmap->rwm_rw, "<suffix massage>", 2, 2, rargv );
1681 #endif /* ENABLE_REWRITE */
1684 on->on_bi.bi_private = (void *)rwmap;
1687 (void)rwm_db_destroy( be );
1697 slap_overinst *on = (slap_overinst *) be->bd_info;
1700 if ( on->on_bi.bi_private ) {
1701 struct ldaprwmap *rwmap =
1702 (struct ldaprwmap *)on->on_bi.bi_private;
1704 #ifdef ENABLE_REWRITE
1705 if ( rwmap->rwm_rw ) {
1706 rewrite_info_delete( &rwmap->rwm_rw );
1708 #else /* !ENABLE_REWRITE */
1709 if ( rwmap->rwm_suffix_massage ) {
1710 ber_bvarray_free( rwmap->rwm_suffix_massage );
1712 #endif /* !ENABLE_REWRITE */
1714 avl_free( rwmap->rwm_oc.remap, rwm_mapping_dst_free );
1715 avl_free( rwmap->rwm_oc.map, rwm_mapping_free );
1716 avl_free( rwmap->rwm_at.remap, rwm_mapping_dst_free );
1717 avl_free( rwmap->rwm_at.map, rwm_mapping_free );
1725 static slap_overinst rwm = { { NULL } };
1727 #if SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC
1729 #endif /* SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC */
1731 rwm_initialize( void )
1733 memset( &rwm, 0, sizeof( slap_overinst ) );
1735 rwm.on_bi.bi_type = "rwm";
1736 rwm.on_bi.bi_flags =
1737 SLAPO_BFLAG_SINGLE |
1740 rwm.on_bi.bi_db_init = rwm_db_init;
1741 rwm.on_bi.bi_db_config = rwm_db_config;
1742 rwm.on_bi.bi_db_destroy = rwm_db_destroy;
1744 rwm.on_bi.bi_op_bind = rwm_op_bind;
1745 rwm.on_bi.bi_op_search = rwm_op_search;
1746 rwm.on_bi.bi_op_compare = rwm_op_compare;
1747 rwm.on_bi.bi_op_modify = rwm_op_modify;
1748 rwm.on_bi.bi_op_modrdn = rwm_op_modrdn;
1749 rwm.on_bi.bi_op_add = rwm_op_add;
1750 rwm.on_bi.bi_op_delete = rwm_op_delete;
1751 rwm.on_bi.bi_op_unbind = rwm_op_unbind;
1752 rwm.on_bi.bi_extended = rwm_extended;
1754 rwm.on_bi.bi_operational = rwm_operational;
1755 rwm.on_bi.bi_chk_referrals = 0 /* rwm_chk_referrals */ ;
1757 #ifdef ENABLE_REWRITE
1758 rwm.on_bi.bi_connection_init = rwm_conn_init;
1759 rwm.on_bi.bi_connection_destroy = rwm_conn_destroy;
1760 #endif /* ENABLE_REWRITE */
1762 rwm.on_response = rwm_response;
1764 return overlay_register( &rwm );
1767 #if SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC
1769 init_module( int argc, char *argv[] )
1771 return rwm_initialize();
1773 #endif /* SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC */
1775 #endif /* SLAPD_OVER_RWM */