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 {
35 AttributeName *mapped_attrs;
40 rwm_db_destroy( BackendDB *be );
42 typedef struct rwm_op_cb {
48 rwm_op_cleanup( Operation *op, SlapReply *rs )
50 slap_callback *cb = op->o_callback;
51 rwm_op_state *ros = cb->sc_private;
53 if ( rs->sr_type == REP_RESULT || rs->sr_type == REP_EXTENDED ||
54 op->o_abandon || rs->sr_err == SLAPD_ABANDON ) {
56 op->o_req_dn = ros->ro_dn;
57 op->o_req_ndn = ros->ro_ndn;
59 if ( !BER_BVISEMPTY( &ros->r_dn )) ch_free( ros->r_dn.bv_val );
60 if ( !BER_BVISEMPTY( &ros->r_ndn )) ch_free( ros->r_ndn.bv_val );
62 switch( ros->r_tag ) {
63 case LDAP_REQ_COMPARE:
64 if ( op->orc_ava->aa_value.bv_val != ros->orc_ava->aa_value.bv_val )
65 op->o_tmpfree( op->orc_ava->aa_value.bv_val, op->o_tmpmemctx );
66 op->orc_ava = ros->orc_ava;
69 slap_mods_free( op->orm_modlist, 1 );
70 op->orm_modlist = ros->orm_modlist;
73 if ( op->orr_newSup != ros->orr_newSup ) {
74 ch_free( op->orr_newSup->bv_val );
75 ch_free( op->orr_nnewSup->bv_val );
76 op->o_tmpfree( op->orr_newSup, op->o_tmpmemctx );
77 op->o_tmpfree( op->orr_nnewSup, op->o_tmpmemctx );
78 op->orr_newSup = ros->orr_newSup;
79 op->orr_nnewSup = ros->orr_nnewSup;
83 ch_free( ros->mapped_attrs );
84 filter_free_x( op, op->ors_filter );
85 ch_free( op->ors_filterstr.bv_val );
86 op->ors_attrs = ros->ors_attrs;
87 op->ors_filter = ros->ors_filter;
88 op->ors_filterstr = ros->ors_filterstr;
90 case LDAP_REQ_EXTENDED:
91 if ( op->ore_reqdata != ros->ore_reqdata ) {
92 ber_bvfree( op->ore_reqdata );
93 op->ore_reqdata = ros->ore_reqdata;
98 op->o_callback = op->o_callback->sc_next;
99 op->o_tmpfree( cb, op->o_tmpmemctx );
102 return SLAP_CB_CONTINUE;
106 rwm_callback_get( Operation *op, SlapReply *rs )
108 rwm_op_cb *roc = NULL;
110 roc = op->o_tmpalloc( sizeof( struct rwm_op_cb ), op->o_tmpmemctx );
111 roc->cb.sc_cleanup = rwm_op_cleanup;
112 roc->cb.sc_response = NULL;
113 roc->cb.sc_next = op->o_callback;
114 roc->cb.sc_private = &roc->ros;
115 roc->ros.r_tag = op->o_tag;
116 roc->ros.ro_dn = op->o_req_dn;
117 roc->ros.ro_ndn = op->o_req_ndn;
118 roc->ros.o_request = op->o_request;
119 BER_BVZERO( &roc->ros.r_dn );
120 BER_BVZERO( &roc->ros.r_ndn );
127 rwm_op_dn_massage( Operation *op, SlapReply *rs, void *cookie,
130 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
131 struct ldaprwmap *rwmap =
132 (struct ldaprwmap *)on->on_bi.bi_private;
134 struct berval dn = BER_BVNULL,
140 * Rewrite the dn if needed
143 #ifdef ENABLE_REWRITE
144 dc.conn = op->o_conn;
146 dc.ctx = (char *)cookie;
147 #else /* ! ENABLE_REWRITE */
148 dc.tofrom = ((int *)cookie)[0];
150 #endif /* ! ENABLE_REWRITE */
152 /* NOTE: in those cases where only the ndn is available,
153 * and the caller sets op->o_req_dn = op->o_req_ndn,
154 * only rewrite the op->o_req_ndn and use it as
155 * op->o_req_dn as well */
157 if ( op->o_req_dn.bv_val != op->o_req_ndn.bv_val ) {
159 rc = rwm_dn_massage_pretty_normalize( &dc, &op->o_req_dn, &dn, &ndn );
161 rc = rwm_dn_massage_normalize( &dc, &op->o_req_ndn, &ndn );
164 if ( rc != LDAP_SUCCESS ) {
168 if ( ( op->o_req_dn.bv_val != op->o_req_ndn.bv_val && dn.bv_val == op->o_req_dn.bv_val )
169 || ndn.bv_val == op->o_req_ndn.bv_val )
174 if ( op->o_req_dn.bv_val != op->o_req_ndn.bv_val ) {
187 rwm_op_add( Operation *op, SlapReply *rs )
189 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
190 struct ldaprwmap *rwmap =
191 (struct ldaprwmap *)on->on_bi.bi_private;
195 Attribute **ap = NULL;
196 char *olddn = op->o_req_dn.bv_val;
199 rwm_op_cb *roc = rwm_callback_get( op, rs );
201 #ifdef ENABLE_REWRITE
202 rc = rwm_op_dn_massage( op, rs, "addDN", &roc->ros );
203 #else /* ! ENABLE_REWRITE */
205 rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros );
206 #endif /* ! ENABLE_REWRITE */
207 if ( rc != LDAP_SUCCESS ) {
208 op->o_bd->bd_info = (BackendInfo *)on->on_info;
209 send_ldap_error( op, rs, rc, "addDN massage error" );
213 if ( olddn != op->o_req_dn.bv_val ) {
214 ber_bvreplace( &op->ora_e->e_name, &op->o_req_dn );
215 ber_bvreplace( &op->ora_e->e_nname, &op->o_req_ndn );
218 /* Count number of attributes in entry */
219 isupdate = be_shadow_update( op );
220 for ( i = 0, ap = &op->oq_add.rs_e->e_attrs; *ap; ) {
223 if ( (*ap)->a_desc == slap_schema.si_ad_objectClass ||
224 (*ap)->a_desc == slap_schema.si_ad_structuralObjectClass )
228 for ( last = 0; !BER_BVISNULL( &(*ap)->a_vals[ last ] ); last++ )
231 for ( j = 0; !BER_BVISNULL( &(*ap)->a_vals[ j ] ); j++ ) {
232 struct ldapmapping *mapping = NULL;
234 ( void )rwm_mapping( &rwmap->rwm_oc, &(*ap)->a_vals[ j ],
236 if ( mapping == NULL ) {
237 if ( rwmap->rwm_at.drop_missing ) {
238 /* FIXME: we allow to remove objectClasses as well;
239 * if the resulting entry is inconsistent, that's
240 * the relayed database's business...
242 ch_free( (*ap)->a_vals[ j ].bv_val );
244 (*ap)->a_vals[ j ] = (*ap)->a_vals[ last ];
246 BER_BVZERO( &(*ap)->a_vals[ last ] );
252 ch_free( (*ap)->a_vals[ j ].bv_val );
253 ber_dupbv( &(*ap)->a_vals[ j ], &mapping->m_dst );
257 } else if ( !isupdate && !get_manageDIT( op ) && (*ap)->a_desc->ad_type->sat_no_user_mod )
262 struct ldapmapping *mapping = NULL;
264 ( void )rwm_mapping( &rwmap->rwm_at, &(*ap)->a_desc->ad_cname,
266 if ( mapping == NULL ) {
267 if ( rwmap->rwm_at.drop_missing ) {
272 if ( (*ap)->a_desc->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName
273 || ( mapping != NULL && mapping->m_dst_ad->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName ) )
276 * FIXME: rewrite could fail; in this case
277 * the operation should give up, right?
279 #ifdef ENABLE_REWRITE
280 rc = rwm_dnattr_rewrite( op, rs, "addAttrDN",
282 (*ap)->a_nvals ? &(*ap)->a_nvals : NULL );
283 #else /* ! ENABLE_REWRITE */
285 rc = rwm_dnattr_rewrite( op, rs, &rc, (*ap)->a_vals,
286 (*ap)->a_nvals ? &(*ap)->a_nvals : NULL );
287 #endif /* ! ENABLE_REWRITE */
292 } else if ( (*ap)->a_desc == slap_schema.si_ad_ref ) {
293 #ifdef ENABLE_REWRITE
294 rc = rwm_referral_rewrite( op, rs, "referralAttrDN",
296 (*ap)->a_nvals ? &(*ap)->a_nvals : NULL );
297 #else /* ! ENABLE_REWRITE */
299 rc = rwm_referral_rewrite( op, rs, &rc, (*ap)->a_vals,
300 (*ap)->a_nvals ? &(*ap)->a_nvals : NULL );
301 #endif /* ! ENABLE_REWRITE */
302 if ( rc != LDAP_SUCCESS ) {
307 if ( mapping != NULL ) {
308 assert( mapping->m_dst_ad != NULL );
309 (*ap)->a_desc = mapping->m_dst_ad;
318 /* FIXME: leaking attribute/values? */
325 op->o_callback = &roc->cb;
327 return SLAP_CB_CONTINUE;
330 #ifdef ENABLE_REWRITE
332 rwm_conn_init( BackendDB *be, Connection *conn )
334 slap_overinst *on = (slap_overinst *) be->bd_info;
335 struct ldaprwmap *rwmap =
336 (struct ldaprwmap *)on->on_bi.bi_private;
338 ( void )rewrite_session_init( rwmap->rwm_rw, conn );
340 return SLAP_CB_CONTINUE;
344 rwm_conn_destroy( BackendDB *be, Connection *conn )
346 slap_overinst *on = (slap_overinst *) be->bd_info;
347 struct ldaprwmap *rwmap =
348 (struct ldaprwmap *)on->on_bi.bi_private;
350 ( void )rewrite_session_delete( rwmap->rwm_rw, conn );
352 return SLAP_CB_CONTINUE;
354 #endif /* ENABLE_REWRITE */
357 rwm_op_bind( Operation *op, SlapReply *rs )
359 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
362 rwm_op_cb *roc = rwm_callback_get( op, rs );
364 #ifdef ENABLE_REWRITE
365 rc = rwm_op_dn_massage( op, rs, "bindDN", &roc->ros );
366 #else /* ! ENABLE_REWRITE */
368 rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros );
369 #endif /* ! ENABLE_REWRITE */
370 if ( rc != LDAP_SUCCESS ) {
371 op->o_bd->bd_info = (BackendInfo *)on->on_info;
372 send_ldap_error( op, rs, rc, "bindDN massage error" );
376 op->o_callback = &roc->cb;
378 return SLAP_CB_CONTINUE;
382 rwm_op_unbind( Operation *op, SlapReply *rs )
384 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
385 struct ldaprwmap *rwmap =
386 (struct ldaprwmap *)on->on_bi.bi_private;
388 #ifdef ENABLE_REWRITE
389 rewrite_session_delete( rwmap->rwm_rw, op->o_conn );
390 #endif /* ENABLE_REWRITE */
392 return SLAP_CB_CONTINUE;
396 rwm_op_compare( Operation *op, SlapReply *rs )
398 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
399 struct ldaprwmap *rwmap =
400 (struct ldaprwmap *)on->on_bi.bi_private;
403 struct berval mapped_vals[2] = { BER_BVNULL, BER_BVNULL };
405 rwm_op_cb *roc = rwm_callback_get( op, rs );
407 #ifdef ENABLE_REWRITE
408 rc = rwm_op_dn_massage( op, rs, "compareDN", &roc->ros );
409 #else /* ! ENABLE_REWRITE */
411 rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros );
412 #endif /* ! ENABLE_REWRITE */
413 if ( rc != LDAP_SUCCESS ) {
414 op->o_bd->bd_info = (BackendInfo *)on->on_info;
415 send_ldap_error( op, rs, rc, "compareDN massage error" );
419 /* if the attribute is an objectClass, try to remap its value */
420 if ( op->orc_ava->aa_desc == slap_schema.si_ad_objectClass
421 || op->orc_ava->aa_desc == slap_schema.si_ad_structuralObjectClass )
423 rwm_map( &rwmap->rwm_oc, &op->orc_ava->aa_value,
424 &mapped_vals[0], RWM_MAP );
425 if ( BER_BVISNULL( &mapped_vals[0] ) || BER_BVISEMPTY( &mapped_vals[0] ) )
427 op->o_bd->bd_info = (BackendInfo *)on->on_info;
428 send_ldap_error( op, rs, LDAP_OTHER, "compare objectClass map error" );
431 } else if ( mapped_vals[0].bv_val != op->orc_ava->aa_value.bv_val ) {
432 ber_dupbv_x( &op->orc_ava->aa_value, &mapped_vals[0],
437 struct ldapmapping *mapping = NULL;
438 AttributeDescription *ad = op->orc_ava->aa_desc;
440 ( void )rwm_mapping( &rwmap->rwm_at, &op->orc_ava->aa_desc->ad_cname,
442 if ( mapping == NULL ) {
443 if ( rwmap->rwm_at.drop_missing ) {
444 op->o_bd->bd_info = (BackendInfo *)on->on_info;
445 send_ldap_error( op, rs, LDAP_OTHER, "compare attributeType map error" );
450 assert( mapping->m_dst_ad != NULL );
451 ad = mapping->m_dst_ad;
454 if ( op->orc_ava->aa_desc->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName
455 || ( mapping != NULL && mapping->m_dst_ad->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName ) )
457 struct berval *mapped_valsp[2];
459 mapped_valsp[0] = &mapped_vals[0];
460 mapped_valsp[1] = &mapped_vals[1];
462 mapped_vals[0] = op->orc_ava->aa_value;
464 #ifdef ENABLE_REWRITE
465 rc = rwm_dnattr_rewrite( op, rs, "compareAttrDN", NULL, mapped_valsp );
466 #else /* ! ENABLE_REWRITE */
468 rc = rwm_dnattr_rewrite( op, rs, &rc, NULL, mapped_valsp );
469 #endif /* ! ENABLE_REWRITE */
471 if ( rc != LDAP_SUCCESS ) {
472 op->o_bd->bd_info = (BackendInfo *)on->on_info;
473 send_ldap_error( op, rs, rc, "compareAttrDN massage error" );
477 if ( mapped_vals[ 0 ].bv_val != op->orc_ava->aa_value.bv_val ) {
478 /* NOTE: if we get here, rwm_dnattr_rewrite()
479 * already freed the old value, so now
481 ber_dupbv_x( &op->orc_ava->aa_value, &mapped_vals[0],
483 ber_memfree_x( mapped_vals[ 0 ].bv_val, NULL );
486 op->orc_ava->aa_desc = ad;
489 op->o_callback = &roc->cb;
491 return SLAP_CB_CONTINUE;
495 rwm_op_delete( Operation *op, SlapReply *rs )
497 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
500 rwm_op_cb *roc = rwm_callback_get( op, rs );
502 #ifdef ENABLE_REWRITE
503 rc = rwm_op_dn_massage( op, rs, "deleteDN", &roc->ros );
504 #else /* ! ENABLE_REWRITE */
506 rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros );
507 #endif /* ! ENABLE_REWRITE */
508 if ( rc != LDAP_SUCCESS ) {
509 op->o_bd->bd_info = (BackendInfo *)on->on_info;
510 send_ldap_error( op, rs, rc, "deleteDN massage error" );
514 op->o_callback = &roc->cb;
516 return SLAP_CB_CONTINUE;
520 rwm_op_modify( Operation *op, SlapReply *rs )
522 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
523 struct ldaprwmap *rwmap =
524 (struct ldaprwmap *)on->on_bi.bi_private;
530 rwm_op_cb *roc = rwm_callback_get( op, rs );
532 #ifdef ENABLE_REWRITE
533 rc = rwm_op_dn_massage( op, rs, "modifyDN", &roc->ros );
534 #else /* ! ENABLE_REWRITE */
536 rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros );
537 #endif /* ! ENABLE_REWRITE */
538 if ( rc != LDAP_SUCCESS ) {
539 op->o_bd->bd_info = (BackendInfo *)on->on_info;
540 send_ldap_error( op, rs, rc, "modifyDN massage error" );
544 isupdate = be_shadow_update( op );
545 for ( mlp = &op->oq_modify.rs_modlist; *mlp; ) {
548 struct ldapmapping *mapping = NULL;
550 /* duplicate the modlist */
551 ml = ch_malloc( sizeof( Modifications ));
555 if ( ml->sml_desc == slap_schema.si_ad_objectClass
556 || ml->sml_desc == slap_schema.si_ad_structuralObjectClass )
560 } else if ( !isupdate && !get_manageDIT( op ) && (*mlp)->sml_desc->ad_type->sat_no_user_mod )
567 drop_missing = rwm_mapping( &rwmap->rwm_at,
568 &ml->sml_desc->ad_cname,
570 if ( drop_missing || ( mapping != NULL && BER_BVISNULL( &mapping->m_dst ) ) )
576 if ( ml->sml_values != NULL ) {
580 for ( num = 0; !BER_BVISNULL( &ml->sml_values[ num ] ); num++ )
583 bva = ch_malloc( (num+1) * sizeof( struct berval ));
584 for (i=0; i<num; i++)
585 ber_dupbv( &bva[i], &ml->sml_values[i] );
586 BER_BVZERO( &bva[i] );
587 ml->sml_values = bva;
589 if ( ml->sml_nvalues ) {
590 bva = ch_malloc( (num+1) * sizeof( struct berval ));
591 for (i=0; i<num; i++)
592 ber_dupbv( &bva[i], &ml->sml_nvalues[i] );
593 BER_BVZERO( &bva[i] );
594 ml->sml_nvalues = bva;
602 for ( j = 0; !BER_BVISNULL( &ml->sml_values[ j ] ); j++ ) {
603 struct ldapmapping *oc_mapping = NULL;
605 ( void )rwm_mapping( &rwmap->rwm_oc, &ml->sml_values[ j ],
606 &oc_mapping, RWM_MAP );
607 if ( oc_mapping == NULL ) {
608 if ( rwmap->rwm_at.drop_missing ) {
609 /* FIXME: we allow to remove objectClasses as well;
610 * if the resulting entry is inconsistent, that's
611 * the relayed database's business...
614 ch_free( ml->sml_values[ j ].bv_val );
615 ml->sml_values[ j ] = ml->sml_values[ last ];
617 BER_BVZERO( &ml->sml_values[ last ] );
623 ch_free( ml->sml_values[ j ].bv_val );
624 ber_dupbv( &ml->sml_values[ j ], &oc_mapping->m_dst );
629 if ( ml->sml_desc->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName
630 || ( mapping != NULL && mapping->m_dst_ad->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName ) )
632 #ifdef ENABLE_REWRITE
633 rc = rwm_dnattr_rewrite( op, rs, "modifyAttrDN",
635 ml->sml_nvalues ? &ml->sml_nvalues : NULL );
636 #else /* ! ENABLE_REWRITE */
638 rc = rwm_dnattr_rewrite( op, rs, &rc,
640 ml->sml_nvalues ? &ml->sml_nvalues : NULL );
641 #endif /* ! ENABLE_REWRITE */
643 } else if ( ml->sml_desc == slap_schema.si_ad_ref ) {
644 #ifdef ENABLE_REWRITE
645 rc = rwm_referral_rewrite( op, rs,
648 ml->sml_nvalues ? &ml->sml_nvalues : NULL );
649 #else /* ! ENABLE_REWRITE */
651 rc = rwm_referral_rewrite( op, rs, &rc,
653 ml->sml_nvalues ? &ml->sml_nvalues : NULL );
654 #endif /* ! ENABLE_REWRITE */
655 if ( rc != LDAP_SUCCESS ) {
660 if ( rc != LDAP_SUCCESS ) {
667 if ( mapping != NULL ) {
668 /* use new attribute description */
669 assert( mapping->m_dst_ad != NULL );
670 ml->sml_desc = mapping->m_dst_ad;
678 *mlp = (*mlp)->sml_next;
679 slap_mod_free( &ml->sml_mod, 0 );
683 op->o_callback = &roc->cb;
685 return SLAP_CB_CONTINUE;
689 rwm_op_modrdn( Operation *op, SlapReply *rs )
691 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
692 struct ldaprwmap *rwmap =
693 (struct ldaprwmap *)on->on_bi.bi_private;
697 rwm_op_cb *roc = rwm_callback_get( op, rs );
699 if ( op->orr_newSup ) {
701 struct berval nnewSup = BER_BVNULL;
702 struct berval newSup = BER_BVNULL;
705 * Rewrite the new superior, if defined and required
708 #ifdef ENABLE_REWRITE
709 dc.conn = op->o_conn;
711 dc.ctx = "newSuperiorDN";
712 #else /* ! ENABLE_REWRITE */
715 #endif /* ! ENABLE_REWRITE */
716 newSup = *op->orr_newSup;
717 nnewSup = *op->orr_nnewSup;
718 rc = rwm_dn_massage_pretty_normalize( &dc, op->orr_newSup, &newSup, &nnewSup );
719 if ( rc != LDAP_SUCCESS ) {
720 op->o_bd->bd_info = (BackendInfo *)on->on_info;
721 send_ldap_error( op, rs, rc, "newSuperiorDN massage error" );
725 if ( op->orr_newSup->bv_val != newSup.bv_val ) {
726 op->orr_newSup = op->o_tmpalloc( sizeof( struct berval ),
728 op->orr_nnewSup = op->o_tmpalloc( sizeof( struct berval ),
730 *op->orr_newSup = newSup;
731 *op->orr_nnewSup = nnewSup;
736 * Rewrite the dn, if needed
738 #ifdef ENABLE_REWRITE
739 rc = rwm_op_dn_massage( op, rs, "renameDN", &roc->ros );
740 #else /* ! ENABLE_REWRITE */
742 rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros );
743 #endif /* ! ENABLE_REWRITE */
744 if ( rc != LDAP_SUCCESS ) {
745 op->o_bd->bd_info = (BackendInfo *)on->on_info;
746 send_ldap_error( op, rs, rc, "renameDN massage error" );
747 if ( op->orr_newSup != roc->ros.orr_newSup ) {
748 ch_free( op->orr_newSup->bv_val );
749 ch_free( op->orr_nnewSup->bv_val );
750 op->o_tmpfree( op->orr_newSup, op->o_tmpmemctx );
751 op->o_tmpfree( op->orr_nnewSup, op->o_tmpmemctx );
752 op->orr_newSup = roc->ros.orr_newSup;
753 op->orr_nnewSup = roc->ros.orr_nnewSup;
758 /* TODO: rewrite newRDN, attribute types,
759 * values of DN-valued attributes ... */
761 op->o_callback = &roc->cb;
763 return SLAP_CB_CONTINUE;
768 rwm_swap_attrs( Operation *op, SlapReply *rs )
770 slap_callback *cb = op->o_callback;
771 rwm_op_state *ros = cb->sc_private;
773 rs->sr_attrs = ros->ors_attrs;
775 /* other overlays might have touched op->ors_attrs,
776 * so we restore the original version here, otherwise
777 * attribute-mapping might fail */
778 op->ors_attrs = ros->mapped_attrs;
780 return SLAP_CB_CONTINUE;
784 rwm_op_search( Operation *op, SlapReply *rs )
786 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
787 struct ldaprwmap *rwmap =
788 (struct ldaprwmap *)on->on_bi.bi_private;
793 struct berval fstr = BER_BVNULL;
796 AttributeName *an = NULL;
800 rwm_op_cb *roc = rwm_callback_get( op, rs );
802 #ifdef ENABLE_REWRITE
803 rc = rewrite_session_var_set( rwmap->rwm_rw, op->o_conn,
804 "searchFilter", op->ors_filterstr.bv_val );
805 if ( rc == LDAP_SUCCESS )
806 rc = rwm_op_dn_massage( op, rs, "searchDN", &roc->ros );
807 #else /* ! ENABLE_REWRITE */
809 rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros );
810 #endif /* ! ENABLE_REWRITE */
811 if ( rc != LDAP_SUCCESS ) {
812 text = "searchDN massage error";
817 * Rewrite the dn if needed
820 #ifdef ENABLE_REWRITE
821 dc.conn = op->o_conn;
823 dc.ctx = "searchFilterAttrDN";
824 #else /* ! ENABLE_REWRITE */
827 #endif /* ! ENABLE_REWRITE */
829 rc = rwm_filter_map_rewrite( op, &dc, op->ors_filter, &fstr );
830 if ( rc != LDAP_SUCCESS ) {
831 text = "searchFilter/searchFilterAttrDN massage error";
835 f = str2filter_x( op, fstr.bv_val );
838 text = "massaged filter parse error";
843 op->ors_filterstr = fstr;
845 rc = rwm_map_attrnames( &rwmap->rwm_at, &rwmap->rwm_oc,
846 op->ors_attrs, &an, RWM_MAP );
847 if ( rc != LDAP_SUCCESS ) {
848 text = "attribute list mapping error";
853 /* store the mapped Attributes for later usage, in
854 * the case that other overlays change op->ors_attrs */
855 roc->ros.mapped_attrs = an;
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
1141 && !get_manageDIT( op )
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";
1737 rwm.on_bi.bi_db_init = rwm_db_init;
1738 rwm.on_bi.bi_db_config = rwm_db_config;
1739 rwm.on_bi.bi_db_destroy = rwm_db_destroy;
1741 rwm.on_bi.bi_op_bind = rwm_op_bind;
1742 rwm.on_bi.bi_op_search = rwm_op_search;
1743 rwm.on_bi.bi_op_compare = rwm_op_compare;
1744 rwm.on_bi.bi_op_modify = rwm_op_modify;
1745 rwm.on_bi.bi_op_modrdn = rwm_op_modrdn;
1746 rwm.on_bi.bi_op_add = rwm_op_add;
1747 rwm.on_bi.bi_op_delete = rwm_op_delete;
1748 rwm.on_bi.bi_op_unbind = rwm_op_unbind;
1749 rwm.on_bi.bi_extended = rwm_extended;
1751 rwm.on_bi.bi_operational = rwm_operational;
1752 rwm.on_bi.bi_chk_referrals = 0 /* rwm_chk_referrals */ ;
1754 #ifdef ENABLE_REWRITE
1755 rwm.on_bi.bi_connection_init = rwm_conn_init;
1756 rwm.on_bi.bi_connection_destroy = rwm_conn_destroy;
1757 #endif /* ENABLE_REWRITE */
1759 rwm.on_response = rwm_response;
1761 return overlay_register( &rwm );
1764 #if SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC
1766 init_module( int argc, char *argv[] )
1768 return rwm_initialize();
1770 #endif /* SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC */
1772 #endif /* SLAPD_OVER_RWM */