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_BVISEMPTY( &ros->r_dn )) ch_free( ros->r_dn.bv_val );
59 if ( !BER_BVISEMPTY( &ros->r_ndn )) ch_free( ros->r_ndn.bv_val );
61 switch( ros->r_tag ) {
62 case LDAP_REQ_COMPARE:
63 if ( op->orc_ava->aa_value.bv_val != ros->orc_ava->aa_value.bv_val )
64 op->o_tmpfree( op->orc_ava->aa_value.bv_val, op->o_tmpmemctx );
65 op->orc_ava = ros->orc_ava;
68 slap_mods_free( op->orm_modlist, 1 );
69 op->orm_modlist = ros->orm_modlist;
72 if ( op->orr_newSup != ros->orr_newSup ) {
73 ch_free( op->orr_newSup->bv_val );
74 ch_free( op->orr_nnewSup->bv_val );
75 op->o_tmpfree( op->orr_newSup, op->o_tmpmemctx );
76 op->o_tmpfree( op->orr_nnewSup, op->o_tmpmemctx );
77 op->orr_newSup = ros->orr_newSup;
78 op->orr_nnewSup = ros->orr_nnewSup;
82 ch_free( op->ors_attrs );
83 filter_free_x( op, op->ors_filter );
84 ch_free( op->ors_filterstr.bv_val );
85 op->ors_attrs = ros->ors_attrs;
86 op->ors_filter = ros->ors_filter;
87 op->ors_filterstr = ros->ors_filterstr;
89 case LDAP_REQ_EXTENDED:
90 if ( op->ore_reqdata != ros->ore_reqdata ) {
91 ber_bvfree( op->ore_reqdata );
92 op->ore_reqdata = ros->ore_reqdata;
97 op->o_callback = op->o_callback->sc_next;
98 op->o_tmpfree( cb, op->o_tmpmemctx );
101 return SLAP_CB_CONTINUE;
105 rwm_callback_get( Operation *op, SlapReply *rs )
107 rwm_op_cb *roc = NULL;
109 roc = op->o_tmpalloc( sizeof( struct rwm_op_cb ), op->o_tmpmemctx );
110 roc->cb.sc_cleanup = rwm_op_cleanup;
111 roc->cb.sc_response = NULL;
112 roc->cb.sc_next = op->o_callback;
113 roc->cb.sc_private = &roc->ros;
114 roc->ros.r_tag = op->o_tag;
115 roc->ros.ro_dn = op->o_req_dn;
116 roc->ros.ro_ndn = op->o_req_ndn;
117 roc->ros.o_request = op->o_request;
118 BER_BVZERO( &roc->ros.r_dn );
119 BER_BVZERO( &roc->ros.r_ndn );
126 rwm_op_dn_massage( Operation *op, SlapReply *rs, void *cookie,
129 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
130 struct ldaprwmap *rwmap =
131 (struct ldaprwmap *)on->on_bi.bi_private;
133 struct berval dn = BER_BVNULL,
139 * Rewrite the dn if needed
142 #ifdef ENABLE_REWRITE
143 dc.conn = op->o_conn;
145 dc.ctx = (char *)cookie;
146 #else /* ! ENABLE_REWRITE */
147 dc.tofrom = ((int *)cookie)[0];
149 #endif /* ! ENABLE_REWRITE */
151 /* NOTE: in those cases where only the ndn is available,
152 * and the caller sets op->o_req_dn = op->o_req_ndn,
153 * only rewrite the op->o_req_ndn and use it as
154 * op->o_req_dn as well */
156 if ( op->o_req_dn.bv_val != op->o_req_ndn.bv_val ) {
158 rc = rwm_dn_massage_pretty_normalize( &dc, &op->o_req_dn, &dn, &ndn );
160 rc = rwm_dn_massage_normalize( &dc, &op->o_req_ndn, &ndn );
163 if ( rc != LDAP_SUCCESS ) {
167 if ( ( op->o_req_dn.bv_val != op->o_req_ndn.bv_val && dn.bv_val == op->o_req_dn.bv_val )
168 || ndn.bv_val == op->o_req_ndn.bv_val )
173 if ( op->o_req_dn.bv_val != op->o_req_ndn.bv_val ) {
186 rwm_op_add( Operation *op, SlapReply *rs )
188 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
189 struct ldaprwmap *rwmap =
190 (struct ldaprwmap *)on->on_bi.bi_private;
194 Attribute **ap = NULL;
195 char *olddn = op->o_req_dn.bv_val;
198 rwm_op_cb *roc = rwm_callback_get( op, rs );
200 #ifdef ENABLE_REWRITE
201 rc = rwm_op_dn_massage( op, rs, "addDN", &roc->ros );
202 #else /* ! ENABLE_REWRITE */
204 rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros );
205 #endif /* ! ENABLE_REWRITE */
206 if ( rc != LDAP_SUCCESS ) {
207 op->o_bd->bd_info = (BackendInfo *)on->on_info;
208 send_ldap_error( op, rs, rc, "addDN massage error" );
212 if ( olddn != op->o_req_dn.bv_val ) {
213 ber_bvreplace( &op->ora_e->e_name, &op->o_req_dn );
214 ber_bvreplace( &op->ora_e->e_nname, &op->o_req_ndn );
217 /* Count number of attributes in entry */
218 isupdate = be_shadow_update( op );
219 for ( i = 0, ap = &op->oq_add.rs_e->e_attrs; *ap; ) {
222 if ( (*ap)->a_desc == slap_schema.si_ad_objectClass ||
223 (*ap)->a_desc == slap_schema.si_ad_structuralObjectClass )
227 for ( last = 0; !BER_BVISNULL( &(*ap)->a_vals[ last ] ); last++ )
230 for ( j = 0; !BER_BVISNULL( &(*ap)->a_vals[ j ] ); j++ ) {
231 struct ldapmapping *mapping = NULL;
233 ( void )rwm_mapping( &rwmap->rwm_oc, &(*ap)->a_vals[ j ],
235 if ( mapping == NULL ) {
236 if ( rwmap->rwm_at.drop_missing ) {
237 /* FIXME: we allow to remove objectClasses as well;
238 * if the resulting entry is inconsistent, that's
239 * the relayed database's business...
241 ch_free( (*ap)->a_vals[ j ].bv_val );
243 (*ap)->a_vals[ j ] = (*ap)->a_vals[ last ];
245 BER_BVZERO( &(*ap)->a_vals[ last ] );
251 ch_free( (*ap)->a_vals[ j ].bv_val );
252 ber_dupbv( &(*ap)->a_vals[ j ], &mapping->m_dst );
256 } else if ( !isupdate && !get_relax( op ) && (*ap)->a_desc->ad_type->sat_no_user_mod )
261 struct ldapmapping *mapping = NULL;
263 ( void )rwm_mapping( &rwmap->rwm_at, &(*ap)->a_desc->ad_cname,
265 if ( mapping == NULL ) {
266 if ( rwmap->rwm_at.drop_missing ) {
271 if ( (*ap)->a_desc->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName
272 || ( mapping != NULL && mapping->m_dst_ad->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName ) )
275 * FIXME: rewrite could fail; in this case
276 * the operation should give up, right?
278 #ifdef ENABLE_REWRITE
279 rc = rwm_dnattr_rewrite( op, rs, "addAttrDN",
281 (*ap)->a_nvals ? &(*ap)->a_nvals : NULL );
282 #else /* ! ENABLE_REWRITE */
284 rc = rwm_dnattr_rewrite( op, rs, &rc, (*ap)->a_vals,
285 (*ap)->a_nvals ? &(*ap)->a_nvals : NULL );
286 #endif /* ! ENABLE_REWRITE */
291 } else if ( (*ap)->a_desc == slap_schema.si_ad_ref ) {
292 #ifdef ENABLE_REWRITE
293 rc = rwm_referral_rewrite( op, rs, "referralAttrDN",
295 (*ap)->a_nvals ? &(*ap)->a_nvals : NULL );
296 #else /* ! ENABLE_REWRITE */
298 rc = rwm_referral_rewrite( op, rs, &rc, (*ap)->a_vals,
299 (*ap)->a_nvals ? &(*ap)->a_nvals : NULL );
300 #endif /* ! ENABLE_REWRITE */
301 if ( rc != LDAP_SUCCESS ) {
306 if ( mapping != NULL ) {
307 assert( mapping->m_dst_ad != NULL );
308 (*ap)->a_desc = mapping->m_dst_ad;
317 /* FIXME: leaking attribute/values? */
324 op->o_callback = &roc->cb;
326 return SLAP_CB_CONTINUE;
329 #ifdef ENABLE_REWRITE
331 rwm_conn_init( BackendDB *be, Connection *conn )
333 slap_overinst *on = (slap_overinst *) be->bd_info;
334 struct ldaprwmap *rwmap =
335 (struct ldaprwmap *)on->on_bi.bi_private;
337 ( void )rewrite_session_init( rwmap->rwm_rw, conn );
339 return SLAP_CB_CONTINUE;
343 rwm_conn_destroy( BackendDB *be, Connection *conn )
345 slap_overinst *on = (slap_overinst *) be->bd_info;
346 struct ldaprwmap *rwmap =
347 (struct ldaprwmap *)on->on_bi.bi_private;
349 ( void )rewrite_session_delete( rwmap->rwm_rw, conn );
351 return SLAP_CB_CONTINUE;
353 #endif /* ENABLE_REWRITE */
356 rwm_op_bind( Operation *op, SlapReply *rs )
358 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
361 rwm_op_cb *roc = rwm_callback_get( op, rs );
363 #ifdef ENABLE_REWRITE
364 rc = rwm_op_dn_massage( op, rs, "bindDN", &roc->ros );
365 #else /* ! ENABLE_REWRITE */
367 rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros );
368 #endif /* ! ENABLE_REWRITE */
369 if ( rc != LDAP_SUCCESS ) {
370 op->o_bd->bd_info = (BackendInfo *)on->on_info;
371 send_ldap_error( op, rs, rc, "bindDN massage error" );
375 op->o_callback = &roc->cb;
377 return SLAP_CB_CONTINUE;
381 rwm_op_unbind( Operation *op, SlapReply *rs )
383 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
384 struct ldaprwmap *rwmap =
385 (struct ldaprwmap *)on->on_bi.bi_private;
387 #ifdef ENABLE_REWRITE
388 rewrite_session_delete( rwmap->rwm_rw, op->o_conn );
389 #endif /* ENABLE_REWRITE */
391 return SLAP_CB_CONTINUE;
395 rwm_op_compare( Operation *op, SlapReply *rs )
397 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
398 struct ldaprwmap *rwmap =
399 (struct ldaprwmap *)on->on_bi.bi_private;
402 struct berval mapped_vals[2] = { BER_BVNULL, BER_BVNULL };
404 rwm_op_cb *roc = rwm_callback_get( op, rs );
406 #ifdef ENABLE_REWRITE
407 rc = rwm_op_dn_massage( op, rs, "compareDN", &roc->ros );
408 #else /* ! ENABLE_REWRITE */
410 rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros );
411 #endif /* ! ENABLE_REWRITE */
412 if ( rc != LDAP_SUCCESS ) {
413 op->o_bd->bd_info = (BackendInfo *)on->on_info;
414 send_ldap_error( op, rs, rc, "compareDN massage error" );
418 /* if the attribute is an objectClass, try to remap its value */
419 if ( op->orc_ava->aa_desc == slap_schema.si_ad_objectClass
420 || op->orc_ava->aa_desc == slap_schema.si_ad_structuralObjectClass )
422 rwm_map( &rwmap->rwm_oc, &op->orc_ava->aa_value,
423 &mapped_vals[0], RWM_MAP );
424 if ( BER_BVISNULL( &mapped_vals[0] ) || BER_BVISEMPTY( &mapped_vals[0] ) )
426 op->o_bd->bd_info = (BackendInfo *)on->on_info;
427 send_ldap_error( op, rs, LDAP_OTHER, "compare objectClass map error" );
430 } else if ( mapped_vals[0].bv_val != op->orc_ava->aa_value.bv_val ) {
431 ber_dupbv_x( &op->orc_ava->aa_value, &mapped_vals[0],
436 struct ldapmapping *mapping = NULL;
437 AttributeDescription *ad = op->orc_ava->aa_desc;
439 ( void )rwm_mapping( &rwmap->rwm_at, &op->orc_ava->aa_desc->ad_cname,
441 if ( mapping == NULL ) {
442 if ( rwmap->rwm_at.drop_missing ) {
443 op->o_bd->bd_info = (BackendInfo *)on->on_info;
444 send_ldap_error( op, rs, LDAP_OTHER, "compare attributeType map error" );
449 assert( mapping->m_dst_ad != NULL );
450 ad = mapping->m_dst_ad;
453 if ( op->orc_ava->aa_desc->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName
454 || ( mapping != NULL && mapping->m_dst_ad->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName ) )
456 struct berval *mapped_valsp[2];
458 mapped_valsp[0] = &mapped_vals[0];
459 mapped_valsp[1] = &mapped_vals[1];
461 mapped_vals[0] = op->orc_ava->aa_value;
463 #ifdef ENABLE_REWRITE
464 rc = rwm_dnattr_rewrite( op, rs, "compareAttrDN", NULL, mapped_valsp );
465 #else /* ! ENABLE_REWRITE */
467 rc = rwm_dnattr_rewrite( op, rs, &rc, NULL, mapped_valsp );
468 #endif /* ! ENABLE_REWRITE */
470 if ( rc != LDAP_SUCCESS ) {
471 op->o_bd->bd_info = (BackendInfo *)on->on_info;
472 send_ldap_error( op, rs, rc, "compareAttrDN massage error" );
476 if ( mapped_vals[ 0 ].bv_val != op->orc_ava->aa_value.bv_val ) {
477 /* NOTE: if we get here, rwm_dnattr_rewrite()
478 * already freed the old value, so now
480 ber_dupbv_x( &op->orc_ava->aa_value, &mapped_vals[0],
482 ber_memfree_x( mapped_vals[ 0 ].bv_val, NULL );
485 op->orc_ava->aa_desc = ad;
488 op->o_callback = &roc->cb;
490 return SLAP_CB_CONTINUE;
494 rwm_op_delete( Operation *op, SlapReply *rs )
496 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
499 rwm_op_cb *roc = rwm_callback_get( op, rs );
501 #ifdef ENABLE_REWRITE
502 rc = rwm_op_dn_massage( op, rs, "deleteDN", &roc->ros );
503 #else /* ! ENABLE_REWRITE */
505 rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros );
506 #endif /* ! ENABLE_REWRITE */
507 if ( rc != LDAP_SUCCESS ) {
508 op->o_bd->bd_info = (BackendInfo *)on->on_info;
509 send_ldap_error( op, rs, rc, "deleteDN massage error" );
513 op->o_callback = &roc->cb;
515 return SLAP_CB_CONTINUE;
519 rwm_op_modify( Operation *op, SlapReply *rs )
521 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
522 struct ldaprwmap *rwmap =
523 (struct ldaprwmap *)on->on_bi.bi_private;
529 rwm_op_cb *roc = rwm_callback_get( op, rs );
531 #ifdef ENABLE_REWRITE
532 rc = rwm_op_dn_massage( op, rs, "modifyDN", &roc->ros );
533 #else /* ! ENABLE_REWRITE */
535 rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros );
536 #endif /* ! ENABLE_REWRITE */
537 if ( rc != LDAP_SUCCESS ) {
538 op->o_bd->bd_info = (BackendInfo *)on->on_info;
539 send_ldap_error( op, rs, rc, "modifyDN massage error" );
543 isupdate = be_shadow_update( op );
544 for ( mlp = &op->oq_modify.rs_modlist; *mlp; ) {
547 struct ldapmapping *mapping = NULL;
549 /* duplicate the modlist */
550 ml = ch_malloc( sizeof( Modifications ));
554 if ( ml->sml_desc == slap_schema.si_ad_objectClass
555 || ml->sml_desc == slap_schema.si_ad_structuralObjectClass )
559 } else if ( !isupdate && !get_relax( op ) && ml->sml_desc->ad_type->sat_no_user_mod )
566 drop_missing = rwm_mapping( &rwmap->rwm_at,
567 &ml->sml_desc->ad_cname,
569 if ( drop_missing || ( mapping != NULL && BER_BVISNULL( &mapping->m_dst ) ) )
575 if ( ml->sml_values != NULL ) {
579 for ( num = 0; !BER_BVISNULL( &ml->sml_values[ num ] ); num++ )
582 bva = ch_malloc( (num+1) * sizeof( struct berval ));
583 for (i=0; i<num; i++)
584 ber_dupbv( &bva[i], &ml->sml_values[i] );
585 BER_BVZERO( &bva[i] );
586 ml->sml_values = bva;
588 if ( ml->sml_nvalues ) {
589 bva = ch_malloc( (num+1) * sizeof( struct berval ));
590 for (i=0; i<num; i++)
591 ber_dupbv( &bva[i], &ml->sml_nvalues[i] );
592 BER_BVZERO( &bva[i] );
593 ml->sml_nvalues = bva;
601 for ( j = 0; !BER_BVISNULL( &ml->sml_values[ j ] ); j++ ) {
602 struct ldapmapping *oc_mapping = NULL;
604 ( void )rwm_mapping( &rwmap->rwm_oc, &ml->sml_values[ j ],
605 &oc_mapping, RWM_MAP );
606 if ( oc_mapping == NULL ) {
607 if ( rwmap->rwm_at.drop_missing ) {
608 /* FIXME: we allow to remove objectClasses as well;
609 * if the resulting entry is inconsistent, that's
610 * the relayed database's business...
613 ch_free( ml->sml_values[ j ].bv_val );
614 ml->sml_values[ j ] = ml->sml_values[ last ];
616 BER_BVZERO( &ml->sml_values[ last ] );
622 ch_free( ml->sml_values[ j ].bv_val );
623 ber_dupbv( &ml->sml_values[ j ], &oc_mapping->m_dst );
628 if ( ml->sml_desc->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName
629 || ( mapping != NULL && mapping->m_dst_ad->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName ) )
631 #ifdef ENABLE_REWRITE
632 rc = rwm_dnattr_rewrite( op, rs, "modifyAttrDN",
634 ml->sml_nvalues ? &ml->sml_nvalues : NULL );
635 #else /* ! ENABLE_REWRITE */
637 rc = rwm_dnattr_rewrite( op, rs, &rc,
639 ml->sml_nvalues ? &ml->sml_nvalues : NULL );
640 #endif /* ! ENABLE_REWRITE */
642 } else if ( ml->sml_desc == slap_schema.si_ad_ref ) {
643 #ifdef ENABLE_REWRITE
644 rc = rwm_referral_rewrite( op, rs,
647 ml->sml_nvalues ? &ml->sml_nvalues : NULL );
648 #else /* ! ENABLE_REWRITE */
650 rc = rwm_referral_rewrite( op, rs, &rc,
652 ml->sml_nvalues ? &ml->sml_nvalues : NULL );
653 #endif /* ! ENABLE_REWRITE */
654 if ( rc != LDAP_SUCCESS ) {
659 if ( rc != LDAP_SUCCESS ) {
666 if ( mapping != NULL ) {
667 /* use new attribute description */
668 assert( mapping->m_dst_ad != NULL );
669 ml->sml_desc = mapping->m_dst_ad;
677 *mlp = (*mlp)->sml_next;
678 slap_mod_free( &ml->sml_mod, 0 );
682 op->o_callback = &roc->cb;
684 return SLAP_CB_CONTINUE;
688 rwm_op_modrdn( Operation *op, SlapReply *rs )
690 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
691 struct ldaprwmap *rwmap =
692 (struct ldaprwmap *)on->on_bi.bi_private;
696 rwm_op_cb *roc = rwm_callback_get( op, rs );
698 if ( op->orr_newSup ) {
700 struct berval nnewSup = BER_BVNULL;
701 struct berval newSup = BER_BVNULL;
704 * Rewrite the new superior, if defined and required
707 #ifdef ENABLE_REWRITE
708 dc.conn = op->o_conn;
710 dc.ctx = "newSuperiorDN";
711 #else /* ! ENABLE_REWRITE */
714 #endif /* ! ENABLE_REWRITE */
715 newSup = *op->orr_newSup;
716 nnewSup = *op->orr_nnewSup;
717 rc = rwm_dn_massage_pretty_normalize( &dc, op->orr_newSup, &newSup, &nnewSup );
718 if ( rc != LDAP_SUCCESS ) {
719 op->o_bd->bd_info = (BackendInfo *)on->on_info;
720 send_ldap_error( op, rs, rc, "newSuperiorDN massage error" );
724 if ( op->orr_newSup->bv_val != newSup.bv_val ) {
725 op->orr_newSup = op->o_tmpalloc( sizeof( struct berval ),
727 op->orr_nnewSup = op->o_tmpalloc( sizeof( struct berval ),
729 *op->orr_newSup = newSup;
730 *op->orr_nnewSup = nnewSup;
735 * Rewrite the dn, if needed
737 #ifdef ENABLE_REWRITE
738 rc = rwm_op_dn_massage( op, rs, "renameDN", &roc->ros );
739 #else /* ! ENABLE_REWRITE */
741 rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros );
742 #endif /* ! ENABLE_REWRITE */
743 if ( rc != LDAP_SUCCESS ) {
744 op->o_bd->bd_info = (BackendInfo *)on->on_info;
745 send_ldap_error( op, rs, rc, "renameDN massage error" );
746 if ( op->orr_newSup != roc->ros.orr_newSup ) {
747 ch_free( op->orr_newSup->bv_val );
748 ch_free( op->orr_nnewSup->bv_val );
749 op->o_tmpfree( op->orr_newSup, op->o_tmpmemctx );
750 op->o_tmpfree( op->orr_nnewSup, op->o_tmpmemctx );
751 op->orr_newSup = roc->ros.orr_newSup;
752 op->orr_nnewSup = roc->ros.orr_nnewSup;
757 /* TODO: rewrite newRDN, attribute types,
758 * values of DN-valued attributes ... */
760 op->o_callback = &roc->cb;
762 return SLAP_CB_CONTINUE;
767 rwm_swap_attrs( Operation *op, SlapReply *rs )
769 slap_callback *cb = op->o_callback;
770 rwm_op_state *ros = cb->sc_private;
772 rs->sr_attrs = ros->ors_attrs;
774 return SLAP_CB_CONTINUE;
778 rwm_op_search( Operation *op, SlapReply *rs )
780 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
781 struct ldaprwmap *rwmap =
782 (struct ldaprwmap *)on->on_bi.bi_private;
787 struct berval fstr = BER_BVNULL;
790 AttributeName *an = NULL;
794 rwm_op_cb *roc = rwm_callback_get( op, rs );
796 #ifdef ENABLE_REWRITE
797 rc = rewrite_session_var_set( rwmap->rwm_rw, op->o_conn,
798 "searchFilter", op->ors_filterstr.bv_val );
799 if ( rc == LDAP_SUCCESS )
800 rc = rwm_op_dn_massage( op, rs, "searchDN", &roc->ros );
801 #else /* ! ENABLE_REWRITE */
803 rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros );
804 #endif /* ! ENABLE_REWRITE */
805 if ( rc != LDAP_SUCCESS ) {
806 text = "searchDN massage error";
811 * Rewrite the dn if needed
814 #ifdef ENABLE_REWRITE
815 dc.conn = op->o_conn;
817 dc.ctx = "searchFilterAttrDN";
818 #else /* ! ENABLE_REWRITE */
821 #endif /* ! ENABLE_REWRITE */
823 rc = rwm_filter_map_rewrite( op, &dc, op->ors_filter, &fstr );
824 if ( rc != LDAP_SUCCESS ) {
825 text = "searchFilter/searchFilterAttrDN massage error";
829 f = str2filter_x( op, fstr.bv_val );
832 text = "massaged filter parse error";
837 op->ors_filterstr = fstr;
839 rc = rwm_map_attrnames( &rwmap->rwm_at, &rwmap->rwm_oc,
840 op->ors_attrs, &an, RWM_MAP );
841 if ( rc != LDAP_SUCCESS ) {
842 text = "attribute list mapping error";
847 roc->cb.sc_response = rwm_swap_attrs;
849 op->o_callback = &roc->cb;
851 return SLAP_CB_CONTINUE;
859 filter_free_x( op, f );
862 if ( !BER_BVISNULL( &fstr ) ) {
863 ch_free( fstr.bv_val );
866 op->oq_search = roc->ros.oq_search;
868 op->o_bd->bd_info = (BackendInfo *)on->on_info;
869 send_ldap_error( op, rs, rc, text );
876 rwm_exop_passwd( Operation *op, SlapReply *rs )
878 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
882 struct berval id = BER_BVNULL,
885 BerElement *ber = NULL;
887 if ( !BER_BVISNULL( &op->o_req_ndn ) ) {
891 if ( !SLAP_ISGLOBALOVERLAY( op->o_bd ) ) {
892 rs->sr_err = LDAP_OTHER;
896 rs->sr_err = slap_passwd_parse( op->ore_reqdata, &id,
897 &pwold, &pwnew, &rs->sr_text );
898 if ( rs->sr_err != LDAP_SUCCESS ) {
902 if ( !BER_BVISNULL( &id ) ) {
903 rs->sr_err = dnPrettyNormal( NULL, &id, &op->o_req_dn,
904 &op->o_req_ndn, op->o_tmpmemctx );
905 if ( rs->sr_err != LDAP_SUCCESS ) {
906 rs->sr_text = "Invalid DN";
911 ber_dupbv_x( &op->o_req_dn, &op->o_dn, op->o_tmpmemctx );
912 ber_dupbv_x( &op->o_req_ndn, &op->o_ndn, op->o_tmpmemctx );
915 roc = rwm_callback_get( op, rs );
917 #ifdef ENABLE_REWRITE
918 rc = rwm_op_dn_massage( op, rs, "extendedDN", &roc->ros );
919 #else /* ! ENABLE_REWRITE */
921 rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros );
922 #endif /* ! ENABLE_REWRITE */
923 if ( rc != LDAP_SUCCESS ) {
924 op->o_bd->bd_info = (BackendInfo *)on->on_info;
925 send_ldap_error( op, rs, rc, "extendedDN massage error" );
929 ber = ber_alloc_t( LBER_USE_DER );
931 rs->sr_err = LDAP_OTHER;
932 rs->sr_text = "No memory";
935 ber_printf( ber, "{" );
936 if ( !BER_BVISNULL( &id )) {
937 ber_printf( ber, "tO", LDAP_TAG_EXOP_MODIFY_PASSWD_ID,
940 if ( !BER_BVISNULL( &pwold )) {
941 ber_printf( ber, "tO", LDAP_TAG_EXOP_MODIFY_PASSWD_OLD, &pwold );
943 if ( !BER_BVISNULL( &pwnew )) {
944 ber_printf( ber, "tO", LDAP_TAG_EXOP_MODIFY_PASSWD_NEW, &pwnew );
946 ber_printf( ber, "N}" );
947 ber_flatten( ber, &op->ore_reqdata );
950 op->o_callback = &roc->cb;
952 return SLAP_CB_CONTINUE;
957 BI_op_extended *extended;
959 { BER_BVC(LDAP_EXOP_MODIFY_PASSWD), rwm_exop_passwd },
964 rwm_extended( Operation *op, SlapReply *rs )
966 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
972 for ( i = 0; exop_table[i].extended != NULL; i++ ) {
973 if ( bvmatch( &exop_table[i].oid, &op->oq_extended.rs_reqoid ) )
975 rc = exop_table[i].extended( op, rs );
980 case SLAP_CB_CONTINUE:
985 send_ldap_result( op, rs );
992 roc = rwm_callback_get( op, rs );
994 #ifdef ENABLE_REWRITE
995 rc = rwm_op_dn_massage( op, rs, "extendedDN", &roc->ros );
996 #else /* ! ENABLE_REWRITE */
998 rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros );
999 #endif /* ! ENABLE_REWRITE */
1000 if ( rc != LDAP_SUCCESS ) {
1001 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1002 send_ldap_error( op, rs, rc, "extendedDN massage error" );
1006 /* TODO: rewrite/map extended data ? ... */
1007 op->o_callback = &roc->cb;
1009 return SLAP_CB_CONTINUE;
1013 rwm_matched( Operation *op, SlapReply *rs )
1015 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
1016 struct ldaprwmap *rwmap =
1017 (struct ldaprwmap *)on->on_bi.bi_private;
1019 struct berval dn, mdn;
1023 if ( rs->sr_matched == NULL ) {
1024 return SLAP_CB_CONTINUE;
1028 #ifdef ENABLE_REWRITE
1029 dc.conn = op->o_conn;
1031 dc.ctx = "matchedDN";
1032 #else /* ! ENABLE_REWRITE */
1035 #endif /* ! ENABLE_REWRITE */
1036 ber_str2bv( rs->sr_matched, 0, 0, &dn );
1038 rc = rwm_dn_massage_pretty( &dc, &dn, &mdn );
1039 if ( rc != LDAP_SUCCESS ) {
1041 rs->sr_text = "Rewrite error";
1045 if ( mdn.bv_val != dn.bv_val ) {
1046 if ( rs->sr_flags & REP_MATCHED_MUSTBEFREED ) {
1047 ch_free( (void *)rs->sr_matched );
1050 rs->sr_flags |= REP_MATCHED_MUSTBEFREED;
1052 rs->sr_matched = mdn.bv_val;
1055 return SLAP_CB_CONTINUE;
1059 rwm_attrs( Operation *op, SlapReply *rs, Attribute** a_first, int stripEntryDN )
1061 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
1062 struct ldaprwmap *rwmap =
1063 (struct ldaprwmap *)on->on_bi.bi_private;
1071 * Rewrite the dn attrs, if needed
1074 #ifdef ENABLE_REWRITE
1075 dc.conn = op->o_conn;
1077 #else /* ! ENABLE_REWRITE */
1080 #endif /* ! ENABLE_REWRITE */
1082 /* FIXME: the entries are in the remote mapping form;
1083 * so we need to select those attributes we are willing
1084 * to return, and remap them accordingly */
1086 /* FIXME: in principle, one could map an attribute
1087 * on top of another, which already exists.
1088 * As such, in the end there might exist more than
1089 * one instance of an attribute.
1090 * We should at least check if this occurs, and issue
1091 * an error (because multiple instances of attrs in
1092 * response are not valid), or merge the values (what
1093 * about duplicate values?) */
1094 isupdate = be_shadow_update( op );
1095 for ( ap = a_first; *ap; ) {
1096 struct ldapmapping *mapping = NULL;
1101 if ( SLAP_OPATTRS( rs->sr_attr_flags ) && is_at_operational( (*ap)->a_desc->ad_type ) )
1106 if ( op->ors_attrs != NULL &&
1107 !SLAP_USERATTRS( rs->sr_attr_flags ) &&
1108 !ad_inlist( (*ap)->a_desc, op->ors_attrs ) )
1113 drop_missing = rwm_mapping( &rwmap->rwm_at,
1114 &(*ap)->a_desc->ad_cname, &mapping, RWM_REMAP );
1115 if ( drop_missing || ( mapping != NULL && BER_BVISEMPTY( &mapping->m_dst ) ) )
1120 if ( mapping != NULL ) {
1121 (*ap)->a_desc = mapping->m_dst_ad;
1125 if ( (*ap)->a_desc == slap_schema.si_ad_entryDN ) {
1126 if ( stripEntryDN ) {
1127 /* will be generated by frontend */
1131 } else if ( !isupdate
1133 && (*ap)->a_desc->ad_type->sat_no_user_mod
1134 && (*ap)->a_desc->ad_type != slap_schema.si_at_undefined )
1139 for ( last = 0; !BER_BVISNULL( &(*ap)->a_vals[last] ); last++ )
1143 /* empty? leave it in place because of attrsonly and vlv */
1148 if ( (*ap)->a_desc == slap_schema.si_ad_objectClass
1149 || (*ap)->a_desc == slap_schema.si_ad_structuralObjectClass )
1153 for ( bv = (*ap)->a_vals; !BER_BVISNULL( bv ); bv++ ) {
1154 struct berval mapped;
1156 rwm_map( &rwmap->rwm_oc, &bv[0], &mapped, RWM_REMAP );
1157 if ( BER_BVISNULL( &mapped ) || BER_BVISEMPTY( &mapped ) ) {
1158 ch_free( bv[0].bv_val );
1159 BER_BVZERO( &bv[0] );
1160 if ( &(*ap)->a_vals[last] > &bv[0] ) {
1161 bv[0] = (*ap)->a_vals[last];
1162 BER_BVZERO( &(*ap)->a_vals[last] );
1167 } else if ( mapped.bv_val != bv[0].bv_val ) {
1169 * FIXME: after LBER_FREEing
1170 * the value is replaced by
1171 * ch_alloc'ed memory
1173 ber_bvreplace( &bv[0], &mapped );
1178 * It is necessary to try to rewrite attributes with
1179 * dn syntax because they might be used in ACLs as
1180 * members of groups; since ACLs are applied to the
1181 * rewritten stuff, no dn-based subject clause could
1182 * be used at the ldap backend side (see
1183 * http://www.OpenLDAP.org/faq/data/cache/452.html)
1184 * The problem can be overcome by moving the dn-based
1185 * ACLs to the target directory server, and letting
1186 * everything pass thru the ldap backend. */
1187 /* FIXME: handle distinguishedName-like syntaxes, like
1188 * nameAndOptionalUID */
1189 } else if ( (*ap)->a_desc->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName
1190 || ( mapping != NULL && mapping->m_src_ad->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName ) )
1192 #ifdef ENABLE_REWRITE
1193 dc.ctx = "searchAttrDN";
1194 #endif /* ENABLE_REWRITE */
1195 rc = rwm_dnattr_result_rewrite( &dc, (*ap)->a_vals );
1196 if ( rc != LDAP_SUCCESS ) {
1200 } else if ( (*ap)->a_desc == slap_schema.si_ad_ref ) {
1201 #ifdef ENABLE_REWRITE
1202 dc.ctx = "searchAttrDN";
1203 #endif /* ENABLE_REWRITE */
1204 rc = rwm_referral_result_rewrite( &dc, (*ap)->a_vals );
1205 if ( rc != LDAP_SUCCESS ) {
1210 if ( mapping != NULL ) {
1211 /* rewrite the attribute description */
1212 assert( mapping->m_dst_ad != NULL );
1213 (*ap)->a_desc = mapping->m_dst_ad;
1217 ap = &(*ap)->a_next;
1222 *ap = (*ap)->a_next;
1231 rwm_send_entry( Operation *op, SlapReply *rs )
1233 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
1234 struct ldaprwmap *rwmap =
1235 (struct ldaprwmap *)on->on_bi.bi_private;
1239 struct berval dn = BER_BVNULL,
1244 assert( rs->sr_entry != NULL );
1247 * Rewrite the dn of the result, if needed
1250 #ifdef ENABLE_REWRITE
1251 dc.conn = op->o_conn;
1253 dc.ctx = "searchEntryDN";
1254 #else /* ! ENABLE_REWRITE */
1257 #endif /* ! ENABLE_REWRITE */
1260 flags = rs->sr_flags;
1261 if ( !( rs->sr_flags & REP_ENTRY_MODIFIABLE ) ) {
1262 /* FIXME: all we need to duplicate are:
1265 * - attributes that are requested
1266 * - no values if attrsonly is set
1271 rc = LDAP_NO_MEMORY;
1275 flags &= ~REP_ENTRY_MUSTRELEASE;
1276 flags |= ( REP_ENTRY_MODIFIABLE | REP_ENTRY_MUSTBEFREED );
1280 * Note: this may fail if the target host(s) schema differs
1281 * from the one known to the meta, and a DN with unknown
1282 * attributes is returned.
1286 rc = rwm_dn_massage_pretty_normalize( &dc, &e->e_name, &dn, &ndn );
1287 if ( rc != LDAP_SUCCESS ) {
1292 if ( e->e_name.bv_val != dn.bv_val ) {
1293 ch_free( e->e_name.bv_val );
1294 ch_free( e->e_nname.bv_val );
1300 /* TODO: map entry attribute types, objectclasses
1301 * and dn-valued attribute values */
1303 /* FIXME: the entries are in the remote mapping form;
1304 * so we need to select those attributes we are willing
1305 * to return, and remap them accordingly */
1306 (void)rwm_attrs( op, rs, &e->e_attrs, 1 );
1308 if ( rs->sr_flags & REP_ENTRY_MUSTRELEASE ) {
1309 be_entry_release_rw( op, rs->sr_entry, 0 );
1313 rs->sr_flags = flags;
1315 return SLAP_CB_CONTINUE;
1318 if ( e != NULL && e != rs->sr_entry ) {
1319 if ( e->e_name.bv_val == dn.bv_val ) {
1320 BER_BVZERO( &e->e_name );
1323 if ( e->e_nname.bv_val == ndn.bv_val ) {
1324 BER_BVZERO( &e->e_nname );
1330 if ( !BER_BVISNULL( &dn ) ) {
1331 ch_free( dn.bv_val );
1334 if ( !BER_BVISNULL( &ndn ) ) {
1335 ch_free( ndn.bv_val );
1342 rwm_operational( Operation *op, SlapReply *rs )
1344 /* FIXME: the entries are in the remote mapping form;
1345 * so we need to select those attributes we are willing
1346 * to return, and remap them accordingly */
1347 if ( rs->sr_operational_attrs ) {
1348 rwm_attrs( op, rs, &rs->sr_operational_attrs, 1 );
1351 return SLAP_CB_CONTINUE;
1355 /* don't use this; it cannot be reverted, and leaves op->o_req_dn
1356 * rewritten for subsequent operations; fine for plain suffixmassage,
1357 * but destroys everything else */
1359 rwm_chk_referrals( Operation *op, SlapReply *rs )
1361 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
1364 #ifdef ENABLE_REWRITE
1365 rc = rwm_op_dn_massage( op, rs, "referralCheckDN" );
1366 #else /* ! ENABLE_REWRITE */
1368 rc = rwm_op_dn_massage( op, rs, &rc );
1369 #endif /* ! ENABLE_REWRITE */
1370 if ( rc != LDAP_SUCCESS ) {
1371 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1372 send_ldap_error( op, rs, rc, "referralCheckDN massage error" );
1376 return SLAP_CB_CONTINUE;
1388 #ifdef ENABLE_REWRITE
1389 slap_overinst *on = (slap_overinst *) be->bd_info;
1390 struct ldaprwmap *rwmap =
1391 (struct ldaprwmap *)on->on_bi.bi_private;
1393 return rewrite_parse( rwmap->rwm_rw,
1394 fname, lineno, argc, argv );
1396 #else /* !ENABLE_REWRITE */
1397 fprintf( stderr, "%s: line %d: rewrite capabilities "
1398 "are not enabled\n", fname, lineno );
1399 #endif /* !ENABLE_REWRITE */
1405 rwm_suffixmassage_config(
1412 slap_overinst *on = (slap_overinst *) be->bd_info;
1413 struct ldaprwmap *rwmap =
1414 (struct ldaprwmap *)on->on_bi.bi_private;
1416 struct berval bvnc, nvnc, pvnc, brnc, nrnc, prnc;
1418 #ifdef ENABLE_REWRITE
1420 #endif /* ENABLE_REWRITE */
1425 * suffixmassage [<suffix>] <massaged suffix>
1427 * the [<suffix>] field must be defined as a valid suffix
1428 * for the current database;
1429 * the <massaged suffix> shouldn't have already been
1430 * defined as a valid suffix for the current server
1433 if ( be->be_suffix == NULL ) {
1434 fprintf( stderr, "%s: line %d: "
1435 " \"suffixMassage [<suffix>]"
1436 " <massaged suffix>\" without "
1437 "<suffix> part requires database "
1438 "suffix be defined first.\n",
1442 bvnc = be->be_suffix[ 0 ];
1445 } else if ( argc == 3 ) {
1446 ber_str2bv( argv[ 1 ], 0, 0, &bvnc );
1450 fprintf( stderr, "%s: line %d: syntax is"
1451 " \"suffixMassage [<suffix>]"
1452 " <massaged suffix>\"\n",
1457 if ( dnPrettyNormal( NULL, &bvnc, &pvnc, &nvnc, NULL ) != LDAP_SUCCESS ) {
1458 fprintf( stderr, "%s: line %d: suffix DN %s is invalid\n",
1459 fname, lineno, bvnc.bv_val );
1463 ber_str2bv( argv[ massaged ], 0, 0, &brnc );
1464 if ( dnPrettyNormal( NULL, &brnc, &prnc, &nrnc, NULL ) != LDAP_SUCCESS ) {
1465 fprintf( stderr, "%s: line %d: suffix DN %s is invalid\n",
1466 fname, lineno, brnc.bv_val );
1467 free( nvnc.bv_val );
1468 free( pvnc.bv_val );
1472 #ifdef ENABLE_REWRITE
1474 * The suffix massaging is emulated
1475 * by means of the rewrite capabilities
1477 rc = rwm_suffix_massage_config( rwmap->rwm_rw,
1478 &pvnc, &nvnc, &prnc, &nrnc );
1479 free( nvnc.bv_val );
1480 free( pvnc.bv_val );
1481 free( nrnc.bv_val );
1482 free( prnc.bv_val );
1486 #else /* !ENABLE_REWRITE */
1487 ber_bvarray_add( &rwmap->rwm_suffix_massage, &pvnc );
1488 ber_bvarray_add( &rwmap->rwm_suffix_massage, &nvnc );
1490 ber_bvarray_add( &rwmap->rwm_suffix_massage, &prnc );
1491 ber_bvarray_add( &rwmap->rwm_suffix_massage, &nrnc );
1492 #endif /* !ENABLE_REWRITE */
1505 slap_overinst *on = (slap_overinst *) be->bd_info;
1506 struct ldaprwmap *rwmap =
1507 (struct ldaprwmap *)on->on_bi.bi_private;
1509 /* objectclass/attribute mapping */
1510 return rwm_map_config( &rwmap->rwm_oc,
1512 fname, lineno, argc, argv );
1516 rwm_response( Operation *op, SlapReply *rs )
1518 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
1519 struct ldaprwmap *rwmap =
1520 (struct ldaprwmap *)on->on_bi.bi_private;
1524 if ( op->o_tag == LDAP_REQ_SEARCH && rs->sr_type == REP_SEARCH ) {
1525 return rwm_send_entry( op, rs );
1528 switch( op->o_tag ) {
1529 case LDAP_REQ_SEARCH:
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 ldaprwmap *rwmap;
1647 #ifdef ENABLE_REWRITE
1649 #endif /* ENABLE_REWRITE */
1652 rwmap = (struct ldaprwmap *)ch_calloc( 1, sizeof( struct ldaprwmap ) );
1654 #ifdef ENABLE_REWRITE
1655 rwmap->rwm_rw = rewrite_info_init( REWRITE_MODE_USE_DEFAULT );
1656 if ( rwmap->rwm_rw == NULL ) {
1661 /* this rewriteContext by default must be null;
1662 * rules can be added if required */
1663 rargv[ 0 ] = "rewriteContext";
1664 rargv[ 1 ] = "searchFilter";
1666 rewrite_parse( rwmap->rwm_rw, "<suffix massage>", 1, 2, rargv );
1668 rargv[ 0 ] = "rewriteContext";
1669 rargv[ 1 ] = "default";
1671 rewrite_parse( rwmap->rwm_rw, "<suffix massage>", 2, 2, rargv );
1672 #endif /* ENABLE_REWRITE */
1675 on->on_bi.bi_private = (void *)rwmap;
1678 (void)rwm_db_destroy( be );
1688 slap_overinst *on = (slap_overinst *) be->bd_info;
1691 if ( on->on_bi.bi_private ) {
1692 struct ldaprwmap *rwmap =
1693 (struct ldaprwmap *)on->on_bi.bi_private;
1695 #ifdef ENABLE_REWRITE
1696 if ( rwmap->rwm_rw ) {
1697 rewrite_info_delete( &rwmap->rwm_rw );
1699 #else /* !ENABLE_REWRITE */
1700 if ( rwmap->rwm_suffix_massage ) {
1701 ber_bvarray_free( rwmap->rwm_suffix_massage );
1703 #endif /* !ENABLE_REWRITE */
1705 avl_free( rwmap->rwm_oc.remap, rwm_mapping_dst_free );
1706 avl_free( rwmap->rwm_oc.map, rwm_mapping_free );
1707 avl_free( rwmap->rwm_at.remap, rwm_mapping_dst_free );
1708 avl_free( rwmap->rwm_at.map, rwm_mapping_free );
1716 static slap_overinst rwm = { { NULL } };
1718 #if SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC
1720 #endif /* SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC */
1722 rwm_initialize( void )
1724 memset( &rwm, 0, sizeof( slap_overinst ) );
1726 rwm.on_bi.bi_type = "rwm";
1727 rwm.on_bi.bi_flags =
1728 SLAPO_BFLAG_SINGLE |
1731 rwm.on_bi.bi_db_init = rwm_db_init;
1732 rwm.on_bi.bi_db_config = rwm_db_config;
1733 rwm.on_bi.bi_db_destroy = rwm_db_destroy;
1735 rwm.on_bi.bi_op_bind = rwm_op_bind;
1736 rwm.on_bi.bi_op_search = rwm_op_search;
1737 rwm.on_bi.bi_op_compare = rwm_op_compare;
1738 rwm.on_bi.bi_op_modify = rwm_op_modify;
1739 rwm.on_bi.bi_op_modrdn = rwm_op_modrdn;
1740 rwm.on_bi.bi_op_add = rwm_op_add;
1741 rwm.on_bi.bi_op_delete = rwm_op_delete;
1742 rwm.on_bi.bi_op_unbind = rwm_op_unbind;
1743 rwm.on_bi.bi_extended = rwm_extended;
1745 rwm.on_bi.bi_operational = rwm_operational;
1746 rwm.on_bi.bi_chk_referrals = 0 /* rwm_chk_referrals */ ;
1748 #ifdef ENABLE_REWRITE
1749 rwm.on_bi.bi_connection_init = rwm_conn_init;
1750 rwm.on_bi.bi_connection_destroy = rwm_conn_destroy;
1751 #endif /* ENABLE_REWRITE */
1753 rwm.on_response = rwm_response;
1755 return overlay_register( &rwm );
1758 #if SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC
1760 init_module( int argc, char *argv[] )
1762 return rwm_initialize();
1764 #endif /* SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC */
1766 #endif /* SLAPD_OVER_RWM */