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_BVISNULL( &ros->r_dn )
60 && ros->r_dn.bv_val != ros->r_ndn.bv_val )
62 ch_free( ros->r_dn.bv_val );
63 BER_BVZERO( &ros->r_dn );
66 if ( !BER_BVISNULL( &ros->r_ndn ) ) {
67 ch_free( ros->r_ndn.bv_val );
68 BER_BVZERO( &ros->r_ndn );
71 switch( ros->r_tag ) {
72 case LDAP_REQ_COMPARE:
73 if ( op->orc_ava->aa_value.bv_val != ros->orc_ava->aa_value.bv_val )
74 op->o_tmpfree( op->orc_ava->aa_value.bv_val, op->o_tmpmemctx );
75 op->orc_ava = ros->orc_ava;
78 slap_mods_free( op->orm_modlist, 1 );
79 op->orm_modlist = ros->orm_modlist;
82 if ( op->orr_newSup != ros->orr_newSup ) {
83 ch_free( op->orr_newSup->bv_val );
84 ch_free( op->orr_nnewSup->bv_val );
85 op->o_tmpfree( op->orr_newSup, op->o_tmpmemctx );
86 op->o_tmpfree( op->orr_nnewSup, op->o_tmpmemctx );
87 op->orr_newSup = ros->orr_newSup;
88 op->orr_nnewSup = ros->orr_nnewSup;
92 ch_free( ros->mapped_attrs );
93 filter_free_x( op, op->ors_filter );
94 ch_free( op->ors_filterstr.bv_val );
95 op->ors_attrs = ros->ors_attrs;
96 op->ors_filter = ros->ors_filter;
97 op->ors_filterstr = ros->ors_filterstr;
99 case LDAP_REQ_EXTENDED:
100 if ( op->ore_reqdata != ros->ore_reqdata ) {
101 ber_bvfree( op->ore_reqdata );
102 op->ore_reqdata = ros->ore_reqdata;
107 op->o_callback = op->o_callback->sc_next;
108 op->o_tmpfree( cb, op->o_tmpmemctx );
111 return SLAP_CB_CONTINUE;
115 rwm_callback_get( Operation *op, SlapReply *rs )
117 rwm_op_cb *roc = NULL;
119 roc = op->o_tmpalloc( sizeof( struct rwm_op_cb ), op->o_tmpmemctx );
120 roc->cb.sc_cleanup = rwm_op_cleanup;
121 roc->cb.sc_response = NULL;
122 roc->cb.sc_next = op->o_callback;
123 roc->cb.sc_private = &roc->ros;
124 roc->ros.r_tag = op->o_tag;
125 roc->ros.ro_dn = op->o_req_dn;
126 roc->ros.ro_ndn = op->o_req_ndn;
127 roc->ros.o_request = op->o_request;
128 BER_BVZERO( &roc->ros.r_dn );
129 BER_BVZERO( &roc->ros.r_ndn );
136 rwm_op_dn_massage( Operation *op, SlapReply *rs, void *cookie,
139 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
140 struct ldaprwmap *rwmap =
141 (struct ldaprwmap *)on->on_bi.bi_private;
143 struct berval dn = BER_BVNULL,
149 * Rewrite the dn if needed
152 #ifdef ENABLE_REWRITE
153 dc.conn = op->o_conn;
155 dc.ctx = (char *)cookie;
156 #else /* ! ENABLE_REWRITE */
157 dc.tofrom = ((int *)cookie)[0];
159 #endif /* ! ENABLE_REWRITE */
161 /* NOTE: in those cases where only the ndn is available,
162 * and the caller sets op->o_req_dn = op->o_req_ndn,
163 * only rewrite the op->o_req_ndn and use it as
164 * op->o_req_dn as well */
166 if ( op->o_req_dn.bv_val != op->o_req_ndn.bv_val ) {
168 rc = rwm_dn_massage_pretty_normalize( &dc, &op->o_req_dn, &dn, &ndn );
170 rc = rwm_dn_massage_normalize( &dc, &op->o_req_ndn, &ndn );
173 if ( rc != LDAP_SUCCESS ) {
177 if ( ( op->o_req_dn.bv_val != op->o_req_ndn.bv_val && dn.bv_val == op->o_req_dn.bv_val )
178 || ndn.bv_val == op->o_req_ndn.bv_val )
183 if ( op->o_req_dn.bv_val != op->o_req_ndn.bv_val ) {
196 rwm_op_add( Operation *op, SlapReply *rs )
198 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
199 struct ldaprwmap *rwmap =
200 (struct ldaprwmap *)on->on_bi.bi_private;
204 Attribute **ap = NULL;
205 char *olddn = op->o_req_dn.bv_val;
208 rwm_op_cb *roc = rwm_callback_get( op, rs );
210 #ifdef ENABLE_REWRITE
211 rc = rwm_op_dn_massage( op, rs, "addDN", &roc->ros );
212 #else /* ! ENABLE_REWRITE */
214 rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros );
215 #endif /* ! ENABLE_REWRITE */
216 if ( rc != LDAP_SUCCESS ) {
217 op->o_bd->bd_info = (BackendInfo *)on->on_info;
218 send_ldap_error( op, rs, rc, "addDN massage error" );
222 if ( olddn != op->o_req_dn.bv_val ) {
223 ber_bvreplace( &op->ora_e->e_name, &op->o_req_dn );
224 ber_bvreplace( &op->ora_e->e_nname, &op->o_req_ndn );
227 /* Count number of attributes in entry */
228 isupdate = be_shadow_update( op );
229 for ( i = 0, ap = &op->oq_add.rs_e->e_attrs; *ap; ) {
232 if ( (*ap)->a_desc == slap_schema.si_ad_objectClass ||
233 (*ap)->a_desc == slap_schema.si_ad_structuralObjectClass )
237 for ( last = 0; !BER_BVISNULL( &(*ap)->a_vals[ last ] ); last++ )
240 for ( j = 0; !BER_BVISNULL( &(*ap)->a_vals[ j ] ); j++ ) {
241 struct ldapmapping *mapping = NULL;
243 ( void )rwm_mapping( &rwmap->rwm_oc, &(*ap)->a_vals[ j ],
245 if ( mapping == NULL ) {
246 if ( rwmap->rwm_at.drop_missing ) {
247 /* FIXME: we allow to remove objectClasses as well;
248 * if the resulting entry is inconsistent, that's
249 * the relayed database's business...
251 ch_free( (*ap)->a_vals[ j ].bv_val );
253 (*ap)->a_vals[ j ] = (*ap)->a_vals[ last ];
255 BER_BVZERO( &(*ap)->a_vals[ last ] );
261 ch_free( (*ap)->a_vals[ j ].bv_val );
262 ber_dupbv( &(*ap)->a_vals[ j ], &mapping->m_dst );
266 } else if ( !isupdate && !get_relax( op ) && (*ap)->a_desc->ad_type->sat_no_user_mod )
271 struct ldapmapping *mapping = NULL;
273 ( void )rwm_mapping( &rwmap->rwm_at, &(*ap)->a_desc->ad_cname,
275 if ( mapping == NULL ) {
276 if ( rwmap->rwm_at.drop_missing ) {
281 if ( (*ap)->a_desc->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName
282 || ( mapping != NULL && mapping->m_dst_ad->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName ) )
285 * FIXME: rewrite could fail; in this case
286 * the operation should give up, right?
288 #ifdef ENABLE_REWRITE
289 rc = rwm_dnattr_rewrite( op, rs, "addAttrDN",
291 (*ap)->a_nvals ? &(*ap)->a_nvals : NULL );
292 #else /* ! ENABLE_REWRITE */
294 rc = rwm_dnattr_rewrite( op, rs, &rc, (*ap)->a_vals,
295 (*ap)->a_nvals ? &(*ap)->a_nvals : NULL );
296 #endif /* ! ENABLE_REWRITE */
301 } else if ( (*ap)->a_desc == slap_schema.si_ad_ref ) {
302 #ifdef ENABLE_REWRITE
303 rc = rwm_referral_rewrite( op, rs, "referralAttrDN",
305 (*ap)->a_nvals ? &(*ap)->a_nvals : NULL );
306 #else /* ! ENABLE_REWRITE */
308 rc = rwm_referral_rewrite( op, rs, &rc, (*ap)->a_vals,
309 (*ap)->a_nvals ? &(*ap)->a_nvals : NULL );
310 #endif /* ! ENABLE_REWRITE */
311 if ( rc != LDAP_SUCCESS ) {
316 if ( mapping != NULL ) {
317 assert( mapping->m_dst_ad != NULL );
318 (*ap)->a_desc = mapping->m_dst_ad;
327 /* FIXME: leaking attribute/values? */
334 op->o_callback = &roc->cb;
336 return SLAP_CB_CONTINUE;
339 #ifdef ENABLE_REWRITE
341 rwm_conn_init( BackendDB *be, Connection *conn )
343 slap_overinst *on = (slap_overinst *) be->bd_info;
344 struct ldaprwmap *rwmap =
345 (struct ldaprwmap *)on->on_bi.bi_private;
347 ( void )rewrite_session_init( rwmap->rwm_rw, conn );
349 return SLAP_CB_CONTINUE;
353 rwm_conn_destroy( BackendDB *be, Connection *conn )
355 slap_overinst *on = (slap_overinst *) be->bd_info;
356 struct ldaprwmap *rwmap =
357 (struct ldaprwmap *)on->on_bi.bi_private;
359 ( void )rewrite_session_delete( rwmap->rwm_rw, conn );
361 return SLAP_CB_CONTINUE;
363 #endif /* ENABLE_REWRITE */
366 rwm_op_bind( Operation *op, SlapReply *rs )
368 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
371 rwm_op_cb *roc = rwm_callback_get( op, rs );
373 #ifdef ENABLE_REWRITE
374 rc = rwm_op_dn_massage( op, rs, "bindDN", &roc->ros );
375 #else /* ! ENABLE_REWRITE */
377 rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros );
378 #endif /* ! ENABLE_REWRITE */
379 if ( rc != LDAP_SUCCESS ) {
380 op->o_bd->bd_info = (BackendInfo *)on->on_info;
381 send_ldap_error( op, rs, rc, "bindDN massage error" );
385 op->o_callback = &roc->cb;
387 return SLAP_CB_CONTINUE;
391 rwm_op_unbind( Operation *op, SlapReply *rs )
393 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
394 struct ldaprwmap *rwmap =
395 (struct ldaprwmap *)on->on_bi.bi_private;
397 #ifdef ENABLE_REWRITE
398 rewrite_session_delete( rwmap->rwm_rw, op->o_conn );
399 #endif /* ENABLE_REWRITE */
401 return SLAP_CB_CONTINUE;
405 rwm_op_compare( Operation *op, SlapReply *rs )
407 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
408 struct ldaprwmap *rwmap =
409 (struct ldaprwmap *)on->on_bi.bi_private;
412 struct berval mapped_vals[2] = { BER_BVNULL, BER_BVNULL };
414 rwm_op_cb *roc = rwm_callback_get( op, rs );
416 #ifdef ENABLE_REWRITE
417 rc = rwm_op_dn_massage( op, rs, "compareDN", &roc->ros );
418 #else /* ! ENABLE_REWRITE */
420 rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros );
421 #endif /* ! ENABLE_REWRITE */
422 if ( rc != LDAP_SUCCESS ) {
423 op->o_bd->bd_info = (BackendInfo *)on->on_info;
424 send_ldap_error( op, rs, rc, "compareDN massage error" );
428 /* if the attribute is an objectClass, try to remap its value */
429 if ( op->orc_ava->aa_desc == slap_schema.si_ad_objectClass
430 || op->orc_ava->aa_desc == slap_schema.si_ad_structuralObjectClass )
432 rwm_map( &rwmap->rwm_oc, &op->orc_ava->aa_value,
433 &mapped_vals[0], RWM_MAP );
434 if ( BER_BVISNULL( &mapped_vals[0] ) || BER_BVISEMPTY( &mapped_vals[0] ) )
436 op->o_bd->bd_info = (BackendInfo *)on->on_info;
437 send_ldap_error( op, rs, LDAP_OTHER, "compare objectClass map error" );
440 } else if ( mapped_vals[0].bv_val != op->orc_ava->aa_value.bv_val ) {
441 ber_dupbv_x( &op->orc_ava->aa_value, &mapped_vals[0],
446 struct ldapmapping *mapping = NULL;
447 AttributeDescription *ad = op->orc_ava->aa_desc;
449 ( void )rwm_mapping( &rwmap->rwm_at, &op->orc_ava->aa_desc->ad_cname,
451 if ( mapping == NULL ) {
452 if ( rwmap->rwm_at.drop_missing ) {
453 op->o_bd->bd_info = (BackendInfo *)on->on_info;
454 send_ldap_error( op, rs, LDAP_OTHER, "compare attributeType map error" );
459 assert( mapping->m_dst_ad != NULL );
460 ad = mapping->m_dst_ad;
463 if ( op->orc_ava->aa_desc->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName
464 || ( mapping != NULL && mapping->m_dst_ad->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName ) )
466 struct berval *mapped_valsp[2];
468 mapped_valsp[0] = &mapped_vals[0];
469 mapped_valsp[1] = &mapped_vals[1];
471 mapped_vals[0] = op->orc_ava->aa_value;
473 #ifdef ENABLE_REWRITE
474 rc = rwm_dnattr_rewrite( op, rs, "compareAttrDN", NULL, mapped_valsp );
475 #else /* ! ENABLE_REWRITE */
477 rc = rwm_dnattr_rewrite( op, rs, &rc, NULL, mapped_valsp );
478 #endif /* ! ENABLE_REWRITE */
480 if ( rc != LDAP_SUCCESS ) {
481 op->o_bd->bd_info = (BackendInfo *)on->on_info;
482 send_ldap_error( op, rs, rc, "compareAttrDN massage error" );
486 if ( mapped_vals[ 0 ].bv_val != op->orc_ava->aa_value.bv_val ) {
487 /* NOTE: if we get here, rwm_dnattr_rewrite()
488 * already freed the old value, so now
490 ber_dupbv_x( &op->orc_ava->aa_value, &mapped_vals[0],
492 ber_memfree_x( mapped_vals[ 0 ].bv_val, NULL );
495 op->orc_ava->aa_desc = ad;
498 op->o_callback = &roc->cb;
500 return SLAP_CB_CONTINUE;
504 rwm_op_delete( Operation *op, SlapReply *rs )
506 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
509 rwm_op_cb *roc = rwm_callback_get( op, rs );
511 #ifdef ENABLE_REWRITE
512 rc = rwm_op_dn_massage( op, rs, "deleteDN", &roc->ros );
513 #else /* ! ENABLE_REWRITE */
515 rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros );
516 #endif /* ! ENABLE_REWRITE */
517 if ( rc != LDAP_SUCCESS ) {
518 op->o_bd->bd_info = (BackendInfo *)on->on_info;
519 send_ldap_error( op, rs, rc, "deleteDN massage error" );
523 op->o_callback = &roc->cb;
525 return SLAP_CB_CONTINUE;
529 rwm_op_modify( Operation *op, SlapReply *rs )
531 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
532 struct ldaprwmap *rwmap =
533 (struct ldaprwmap *)on->on_bi.bi_private;
539 rwm_op_cb *roc = rwm_callback_get( op, rs );
541 #ifdef ENABLE_REWRITE
542 rc = rwm_op_dn_massage( op, rs, "modifyDN", &roc->ros );
543 #else /* ! ENABLE_REWRITE */
545 rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros );
546 #endif /* ! ENABLE_REWRITE */
547 if ( rc != LDAP_SUCCESS ) {
548 op->o_bd->bd_info = (BackendInfo *)on->on_info;
549 send_ldap_error( op, rs, rc, "modifyDN massage error" );
553 isupdate = be_shadow_update( op );
554 for ( mlp = &op->oq_modify.rs_modlist; *mlp; ) {
557 struct ldapmapping *mapping = NULL;
559 /* duplicate the modlist */
560 ml = ch_malloc( sizeof( Modifications ));
564 if ( ml->sml_desc == slap_schema.si_ad_objectClass
565 || ml->sml_desc == slap_schema.si_ad_structuralObjectClass )
569 } else if ( !isupdate && !get_relax( op ) && ml->sml_desc->ad_type->sat_no_user_mod )
576 drop_missing = rwm_mapping( &rwmap->rwm_at,
577 &ml->sml_desc->ad_cname,
579 if ( drop_missing || ( mapping != NULL && BER_BVISNULL( &mapping->m_dst ) ) )
585 if ( ml->sml_values != NULL ) {
589 for ( num = 0; !BER_BVISNULL( &ml->sml_values[ num ] ); num++ )
592 bva = ch_malloc( (num+1) * sizeof( struct berval ));
593 for (i=0; i<num; i++)
594 ber_dupbv( &bva[i], &ml->sml_values[i] );
595 BER_BVZERO( &bva[i] );
596 ml->sml_values = bva;
598 if ( ml->sml_nvalues ) {
599 bva = ch_malloc( (num+1) * sizeof( struct berval ));
600 for (i=0; i<num; i++)
601 ber_dupbv( &bva[i], &ml->sml_nvalues[i] );
602 BER_BVZERO( &bva[i] );
603 ml->sml_nvalues = bva;
611 for ( j = 0; !BER_BVISNULL( &ml->sml_values[ j ] ); j++ ) {
612 struct ldapmapping *oc_mapping = NULL;
614 ( void )rwm_mapping( &rwmap->rwm_oc, &ml->sml_values[ j ],
615 &oc_mapping, RWM_MAP );
616 if ( oc_mapping == NULL ) {
617 if ( rwmap->rwm_at.drop_missing ) {
618 /* FIXME: we allow to remove objectClasses as well;
619 * if the resulting entry is inconsistent, that's
620 * the relayed database's business...
623 ch_free( ml->sml_values[ j ].bv_val );
624 ml->sml_values[ j ] = ml->sml_values[ last ];
626 BER_BVZERO( &ml->sml_values[ last ] );
632 ch_free( ml->sml_values[ j ].bv_val );
633 ber_dupbv( &ml->sml_values[ j ], &oc_mapping->m_dst );
638 if ( ml->sml_desc->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName
639 || ( mapping != NULL && mapping->m_dst_ad->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName ) )
641 #ifdef ENABLE_REWRITE
642 rc = rwm_dnattr_rewrite( op, rs, "modifyAttrDN",
644 ml->sml_nvalues ? &ml->sml_nvalues : NULL );
645 #else /* ! ENABLE_REWRITE */
647 rc = rwm_dnattr_rewrite( op, rs, &rc,
649 ml->sml_nvalues ? &ml->sml_nvalues : NULL );
650 #endif /* ! ENABLE_REWRITE */
652 } else if ( ml->sml_desc == slap_schema.si_ad_ref ) {
653 #ifdef ENABLE_REWRITE
654 rc = rwm_referral_rewrite( op, rs,
657 ml->sml_nvalues ? &ml->sml_nvalues : NULL );
658 #else /* ! ENABLE_REWRITE */
660 rc = rwm_referral_rewrite( op, rs, &rc,
662 ml->sml_nvalues ? &ml->sml_nvalues : NULL );
663 #endif /* ! ENABLE_REWRITE */
664 if ( rc != LDAP_SUCCESS ) {
669 if ( rc != LDAP_SUCCESS ) {
676 if ( mapping != NULL ) {
677 /* use new attribute description */
678 assert( mapping->m_dst_ad != NULL );
679 ml->sml_desc = mapping->m_dst_ad;
687 *mlp = (*mlp)->sml_next;
688 slap_mod_free( &ml->sml_mod, 0 );
692 op->o_callback = &roc->cb;
694 return SLAP_CB_CONTINUE;
698 rwm_op_modrdn( Operation *op, SlapReply *rs )
700 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
701 struct ldaprwmap *rwmap =
702 (struct ldaprwmap *)on->on_bi.bi_private;
706 rwm_op_cb *roc = rwm_callback_get( op, rs );
708 if ( op->orr_newSup ) {
710 struct berval nnewSup = BER_BVNULL;
711 struct berval newSup = BER_BVNULL;
714 * Rewrite the new superior, if defined and required
717 #ifdef ENABLE_REWRITE
718 dc.conn = op->o_conn;
720 dc.ctx = "newSuperiorDN";
721 #else /* ! ENABLE_REWRITE */
724 #endif /* ! ENABLE_REWRITE */
725 newSup = *op->orr_newSup;
726 nnewSup = *op->orr_nnewSup;
727 rc = rwm_dn_massage_pretty_normalize( &dc, op->orr_newSup, &newSup, &nnewSup );
728 if ( rc != LDAP_SUCCESS ) {
729 op->o_bd->bd_info = (BackendInfo *)on->on_info;
730 send_ldap_error( op, rs, rc, "newSuperiorDN massage error" );
734 if ( op->orr_newSup->bv_val != newSup.bv_val ) {
735 op->orr_newSup = op->o_tmpalloc( sizeof( struct berval ),
737 op->orr_nnewSup = op->o_tmpalloc( sizeof( struct berval ),
739 *op->orr_newSup = newSup;
740 *op->orr_nnewSup = nnewSup;
745 * Rewrite the dn, if needed
747 #ifdef ENABLE_REWRITE
748 rc = rwm_op_dn_massage( op, rs, "renameDN", &roc->ros );
749 #else /* ! ENABLE_REWRITE */
751 rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros );
752 #endif /* ! ENABLE_REWRITE */
753 if ( rc != LDAP_SUCCESS ) {
754 op->o_bd->bd_info = (BackendInfo *)on->on_info;
755 send_ldap_error( op, rs, rc, "renameDN massage error" );
756 if ( op->orr_newSup != roc->ros.orr_newSup ) {
757 ch_free( op->orr_newSup->bv_val );
758 ch_free( op->orr_nnewSup->bv_val );
759 op->o_tmpfree( op->orr_newSup, op->o_tmpmemctx );
760 op->o_tmpfree( op->orr_nnewSup, op->o_tmpmemctx );
761 op->orr_newSup = roc->ros.orr_newSup;
762 op->orr_nnewSup = roc->ros.orr_nnewSup;
767 /* TODO: rewrite newRDN, attribute types,
768 * values of DN-valued attributes ... */
770 op->o_callback = &roc->cb;
772 return SLAP_CB_CONTINUE;
777 rwm_swap_attrs( Operation *op, SlapReply *rs )
779 slap_callback *cb = op->o_callback;
780 rwm_op_state *ros = cb->sc_private;
782 rs->sr_attrs = ros->ors_attrs;
784 /* other overlays might have touched op->ors_attrs,
785 * so we restore the original version here, otherwise
786 * attribute-mapping might fail */
787 op->ors_attrs = ros->mapped_attrs;
789 return SLAP_CB_CONTINUE;
793 rwm_op_search( Operation *op, SlapReply *rs )
795 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
796 struct ldaprwmap *rwmap =
797 (struct ldaprwmap *)on->on_bi.bi_private;
802 struct berval fstr = BER_BVNULL;
805 AttributeName *an = NULL;
809 rwm_op_cb *roc = rwm_callback_get( op, rs );
811 #ifdef ENABLE_REWRITE
812 rc = rewrite_session_var_set( rwmap->rwm_rw, op->o_conn,
813 "searchFilter", op->ors_filterstr.bv_val );
814 if ( rc == LDAP_SUCCESS )
815 rc = rwm_op_dn_massage( op, rs, "searchDN", &roc->ros );
816 #else /* ! ENABLE_REWRITE */
818 rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros );
819 #endif /* ! ENABLE_REWRITE */
820 if ( rc != LDAP_SUCCESS ) {
821 text = "searchDN massage error";
826 * Rewrite the dn if needed
829 #ifdef ENABLE_REWRITE
830 dc.conn = op->o_conn;
832 dc.ctx = "searchFilterAttrDN";
833 #else /* ! ENABLE_REWRITE */
836 #endif /* ! ENABLE_REWRITE */
838 rc = rwm_filter_map_rewrite( op, &dc, op->ors_filter, &fstr );
839 if ( rc != LDAP_SUCCESS ) {
840 text = "searchFilter/searchFilterAttrDN massage error";
844 f = str2filter_x( op, fstr.bv_val );
847 text = "massaged filter parse error";
852 op->ors_filterstr = fstr;
854 rc = rwm_map_attrnames( &rwmap->rwm_at, &rwmap->rwm_oc,
855 op->ors_attrs, &an, RWM_MAP );
856 if ( rc != LDAP_SUCCESS ) {
857 text = "attribute list mapping error";
862 /* store the mapped Attributes for later usage, in
863 * the case that other overlays change op->ors_attrs */
864 roc->ros.mapped_attrs = an;
865 roc->cb.sc_response = rwm_swap_attrs;
867 op->o_callback = &roc->cb;
869 return SLAP_CB_CONTINUE;
877 filter_free_x( op, f );
880 if ( !BER_BVISNULL( &fstr ) ) {
881 ch_free( fstr.bv_val );
884 op->oq_search = roc->ros.oq_search;
886 op->o_bd->bd_info = (BackendInfo *)on->on_info;
887 send_ldap_error( op, rs, rc, text );
894 rwm_exop_passwd( Operation *op, SlapReply *rs )
896 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
900 struct berval id = BER_BVNULL,
903 BerElement *ber = NULL;
905 if ( !BER_BVISNULL( &op->o_req_ndn ) ) {
909 if ( !SLAP_ISGLOBALOVERLAY( op->o_bd ) ) {
910 rs->sr_err = LDAP_OTHER;
914 rs->sr_err = slap_passwd_parse( op->ore_reqdata, &id,
915 &pwold, &pwnew, &rs->sr_text );
916 if ( rs->sr_err != LDAP_SUCCESS ) {
920 if ( !BER_BVISNULL( &id ) ) {
921 rs->sr_err = dnPrettyNormal( NULL, &id, &op->o_req_dn,
922 &op->o_req_ndn, op->o_tmpmemctx );
923 if ( rs->sr_err != LDAP_SUCCESS ) {
924 rs->sr_text = "Invalid DN";
929 ber_dupbv_x( &op->o_req_dn, &op->o_dn, op->o_tmpmemctx );
930 ber_dupbv_x( &op->o_req_ndn, &op->o_ndn, op->o_tmpmemctx );
933 roc = rwm_callback_get( op, rs );
935 #ifdef ENABLE_REWRITE
936 rc = rwm_op_dn_massage( op, rs, "extendedDN", &roc->ros );
937 #else /* ! ENABLE_REWRITE */
939 rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros );
940 #endif /* ! ENABLE_REWRITE */
941 if ( rc != LDAP_SUCCESS ) {
942 op->o_bd->bd_info = (BackendInfo *)on->on_info;
943 send_ldap_error( op, rs, rc, "extendedDN massage error" );
947 ber = ber_alloc_t( LBER_USE_DER );
949 rs->sr_err = LDAP_OTHER;
950 rs->sr_text = "No memory";
953 ber_printf( ber, "{" );
954 if ( !BER_BVISNULL( &id )) {
955 ber_printf( ber, "tO", LDAP_TAG_EXOP_MODIFY_PASSWD_ID,
958 if ( !BER_BVISNULL( &pwold )) {
959 ber_printf( ber, "tO", LDAP_TAG_EXOP_MODIFY_PASSWD_OLD, &pwold );
961 if ( !BER_BVISNULL( &pwnew )) {
962 ber_printf( ber, "tO", LDAP_TAG_EXOP_MODIFY_PASSWD_NEW, &pwnew );
964 ber_printf( ber, "N}" );
965 ber_flatten( ber, &op->ore_reqdata );
968 op->o_callback = &roc->cb;
970 return SLAP_CB_CONTINUE;
975 BI_op_extended *extended;
977 { BER_BVC(LDAP_EXOP_MODIFY_PASSWD), rwm_exop_passwd },
982 rwm_extended( Operation *op, SlapReply *rs )
984 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
990 for ( i = 0; exop_table[i].extended != NULL; i++ ) {
991 if ( bvmatch( &exop_table[i].oid, &op->oq_extended.rs_reqoid ) )
993 rc = exop_table[i].extended( op, rs );
998 case SLAP_CB_CONTINUE:
1003 send_ldap_result( op, rs );
1010 roc = rwm_callback_get( op, rs );
1012 #ifdef ENABLE_REWRITE
1013 rc = rwm_op_dn_massage( op, rs, "extendedDN", &roc->ros );
1014 #else /* ! ENABLE_REWRITE */
1016 rc = rwm_op_dn_massage( op, rs, &rc, &roc->ros );
1017 #endif /* ! ENABLE_REWRITE */
1018 if ( rc != LDAP_SUCCESS ) {
1019 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1020 send_ldap_error( op, rs, rc, "extendedDN massage error" );
1024 /* TODO: rewrite/map extended data ? ... */
1025 op->o_callback = &roc->cb;
1027 return SLAP_CB_CONTINUE;
1031 rwm_matched( Operation *op, SlapReply *rs )
1033 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
1034 struct ldaprwmap *rwmap =
1035 (struct ldaprwmap *)on->on_bi.bi_private;
1037 struct berval dn, mdn;
1041 if ( rs->sr_matched == NULL ) {
1042 return SLAP_CB_CONTINUE;
1046 #ifdef ENABLE_REWRITE
1047 dc.conn = op->o_conn;
1049 dc.ctx = "matchedDN";
1050 #else /* ! ENABLE_REWRITE */
1053 #endif /* ! ENABLE_REWRITE */
1054 ber_str2bv( rs->sr_matched, 0, 0, &dn );
1056 rc = rwm_dn_massage_pretty( &dc, &dn, &mdn );
1057 if ( rc != LDAP_SUCCESS ) {
1059 rs->sr_text = "Rewrite error";
1063 if ( mdn.bv_val != dn.bv_val ) {
1064 if ( rs->sr_flags & REP_MATCHED_MUSTBEFREED ) {
1065 ch_free( (void *)rs->sr_matched );
1068 rs->sr_flags |= REP_MATCHED_MUSTBEFREED;
1070 rs->sr_matched = mdn.bv_val;
1073 return SLAP_CB_CONTINUE;
1077 rwm_attrs( Operation *op, SlapReply *rs, Attribute** a_first, int stripEntryDN )
1079 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
1080 struct ldaprwmap *rwmap =
1081 (struct ldaprwmap *)on->on_bi.bi_private;
1089 * Rewrite the dn attrs, if needed
1092 #ifdef ENABLE_REWRITE
1093 dc.conn = op->o_conn;
1095 #else /* ! ENABLE_REWRITE */
1098 #endif /* ! ENABLE_REWRITE */
1100 /* FIXME: the entries are in the remote mapping form;
1101 * so we need to select those attributes we are willing
1102 * to return, and remap them accordingly */
1104 /* FIXME: in principle, one could map an attribute
1105 * on top of another, which already exists.
1106 * As such, in the end there might exist more than
1107 * one instance of an attribute.
1108 * We should at least check if this occurs, and issue
1109 * an error (because multiple instances of attrs in
1110 * response are not valid), or merge the values (what
1111 * about duplicate values?) */
1112 isupdate = be_shadow_update( op );
1113 for ( ap = a_first; *ap; ) {
1114 struct ldapmapping *mapping = NULL;
1119 if ( SLAP_OPATTRS( rs->sr_attr_flags ) && is_at_operational( (*ap)->a_desc->ad_type ) )
1124 if ( op->ors_attrs != NULL &&
1125 !SLAP_USERATTRS( rs->sr_attr_flags ) &&
1126 !ad_inlist( (*ap)->a_desc, op->ors_attrs ) )
1131 drop_missing = rwm_mapping( &rwmap->rwm_at,
1132 &(*ap)->a_desc->ad_cname, &mapping, RWM_REMAP );
1133 if ( drop_missing || ( mapping != NULL && BER_BVISEMPTY( &mapping->m_dst ) ) )
1137 if ( mapping != NULL ) {
1138 assert( mapping->m_dst_ad != NULL );
1140 /* try to normalize mapped Attributes if the original
1141 * AttributeType was not normalized */
1142 if ((rwmap->rwm_flags & RWM_F_NORMALIZE_MAPPED_ATTRS) &&
1143 (!(*ap)->a_desc->ad_type->sat_equality ||
1144 !(*ap)->a_desc->ad_type->sat_equality->smr_normalize) &&
1145 mapping->m_dst_ad->ad_type->sat_equality &&
1146 mapping->m_dst_ad->ad_type->sat_equality->smr_normalize )
1149 for ( last = 0; !BER_BVISNULL( &(*ap)->a_vals[last] ); last++ )
1154 (*ap)->a_nvals = ch_malloc( (last+1) * sizeof(struct berval) );
1156 for ( i = 0; !BER_BVISNULL( &(*ap)->a_vals[i]); i++ ) {
1159 * check that each value is valid per syntax
1160 * and pretty if appropriate
1162 rc = mapping->m_dst_ad->ad_type->sat_equality->smr_normalize(
1163 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
1164 mapping->m_dst_ad->ad_type->sat_syntax,
1165 mapping->m_dst_ad->ad_type->sat_equality,
1166 &(*ap)->a_vals[i], &(*ap)->a_nvals[i],
1169 if ( rc != LDAP_SUCCESS ) {
1170 BER_BVZERO( &(*ap)->a_nvals[i] );
1173 BER_BVZERO( &(*ap)->a_nvals[i] );
1176 /* rewrite the attribute description */
1177 (*ap)->a_desc = mapping->m_dst_ad;
1181 if ( (*ap)->a_desc == slap_schema.si_ad_entryDN ) {
1182 if ( stripEntryDN ) {
1183 /* will be generated by frontend */
1187 } else if ( !isupdate
1189 && (*ap)->a_desc->ad_type->sat_no_user_mod
1190 && (*ap)->a_desc->ad_type != slap_schema.si_at_undefined )
1195 if ( last == -1 ) { /* not yet counted */
1196 for ( last = 0; !BER_BVISNULL( &(*ap)->a_vals[last] ); last++ )
1201 /* empty? leave it in place because of attrsonly and vlv */
1206 if ( (*ap)->a_desc == slap_schema.si_ad_objectClass
1207 || (*ap)->a_desc == slap_schema.si_ad_structuralObjectClass )
1211 for ( bv = (*ap)->a_vals; !BER_BVISNULL( bv ); bv++ ) {
1212 struct berval mapped;
1214 rwm_map( &rwmap->rwm_oc, &bv[0], &mapped, RWM_REMAP );
1215 if ( BER_BVISNULL( &mapped ) || BER_BVISEMPTY( &mapped ) ) {
1216 ch_free( bv[0].bv_val );
1217 BER_BVZERO( &bv[0] );
1218 if ( &(*ap)->a_vals[last] > &bv[0] ) {
1219 bv[0] = (*ap)->a_vals[last];
1220 BER_BVZERO( &(*ap)->a_vals[last] );
1225 } else if ( mapped.bv_val != bv[0].bv_val ) {
1227 * FIXME: after LBER_FREEing
1228 * the value is replaced by
1229 * ch_alloc'ed memory
1231 ber_bvreplace( &bv[0], &mapped );
1236 * It is necessary to try to rewrite attributes with
1237 * dn syntax because they might be used in ACLs as
1238 * members of groups; since ACLs are applied to the
1239 * rewritten stuff, no dn-based subject clause could
1240 * be used at the ldap backend side (see
1241 * http://www.OpenLDAP.org/faq/data/cache/452.html)
1242 * The problem can be overcome by moving the dn-based
1243 * ACLs to the target directory server, and letting
1244 * everything pass thru the ldap backend. */
1245 /* FIXME: handle distinguishedName-like syntaxes, like
1246 * nameAndOptionalUID */
1247 } else if ( (*ap)->a_desc->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName
1248 || ( mapping != NULL && mapping->m_src_ad->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName ) )
1250 #ifdef ENABLE_REWRITE
1251 dc.ctx = "searchAttrDN";
1252 #endif /* ENABLE_REWRITE */
1253 rc = rwm_dnattr_result_rewrite( &dc, (*ap)->a_vals );
1254 if ( rc != LDAP_SUCCESS ) {
1258 } else if ( (*ap)->a_desc == slap_schema.si_ad_ref ) {
1259 #ifdef ENABLE_REWRITE
1260 dc.ctx = "searchAttrDN";
1261 #endif /* ENABLE_REWRITE */
1262 rc = rwm_referral_result_rewrite( &dc, (*ap)->a_vals );
1263 if ( rc != LDAP_SUCCESS ) {
1270 ap = &(*ap)->a_next;
1275 *ap = (*ap)->a_next;
1284 rwm_send_entry( Operation *op, SlapReply *rs )
1286 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
1287 struct ldaprwmap *rwmap =
1288 (struct ldaprwmap *)on->on_bi.bi_private;
1292 struct berval dn = BER_BVNULL,
1297 assert( rs->sr_entry != NULL );
1300 * Rewrite the dn of the result, if needed
1303 #ifdef ENABLE_REWRITE
1304 dc.conn = op->o_conn;
1306 dc.ctx = "searchEntryDN";
1307 #else /* ! ENABLE_REWRITE */
1310 #endif /* ! ENABLE_REWRITE */
1313 flags = rs->sr_flags;
1314 if ( !( rs->sr_flags & REP_ENTRY_MODIFIABLE ) ) {
1315 /* FIXME: all we need to duplicate are:
1318 * - attributes that are requested
1319 * - no values if attrsonly is set
1324 rc = LDAP_NO_MEMORY;
1328 flags &= ~REP_ENTRY_MUSTRELEASE;
1329 flags |= ( REP_ENTRY_MODIFIABLE | REP_ENTRY_MUSTBEFREED );
1333 * Note: this may fail if the target host(s) schema differs
1334 * from the one known to the meta, and a DN with unknown
1335 * attributes is returned.
1339 rc = rwm_dn_massage_pretty_normalize( &dc, &e->e_name, &dn, &ndn );
1340 if ( rc != LDAP_SUCCESS ) {
1345 if ( e->e_name.bv_val != dn.bv_val ) {
1346 ch_free( e->e_name.bv_val );
1347 ch_free( e->e_nname.bv_val );
1353 /* TODO: map entry attribute types, objectclasses
1354 * and dn-valued attribute values */
1356 /* FIXME: the entries are in the remote mapping form;
1357 * so we need to select those attributes we are willing
1358 * to return, and remap them accordingly */
1359 (void)rwm_attrs( op, rs, &e->e_attrs, 1 );
1361 if ( rs->sr_flags & REP_ENTRY_MUSTRELEASE ) {
1362 be_entry_release_rw( op, rs->sr_entry, 0 );
1366 rs->sr_flags = flags;
1368 return SLAP_CB_CONTINUE;
1371 if ( e != NULL && e != rs->sr_entry ) {
1372 if ( e->e_name.bv_val == dn.bv_val ) {
1373 BER_BVZERO( &e->e_name );
1376 if ( e->e_nname.bv_val == ndn.bv_val ) {
1377 BER_BVZERO( &e->e_nname );
1383 if ( !BER_BVISNULL( &dn ) ) {
1384 ch_free( dn.bv_val );
1387 if ( !BER_BVISNULL( &ndn ) ) {
1388 ch_free( ndn.bv_val );
1395 rwm_operational( Operation *op, SlapReply *rs )
1397 /* FIXME: the entries are in the remote mapping form;
1398 * so we need to select those attributes we are willing
1399 * to return, and remap them accordingly */
1400 if ( rs->sr_operational_attrs ) {
1401 rwm_attrs( op, rs, &rs->sr_operational_attrs, 1 );
1404 return SLAP_CB_CONTINUE;
1408 /* don't use this; it cannot be reverted, and leaves op->o_req_dn
1409 * rewritten for subsequent operations; fine for plain suffixmassage,
1410 * but destroys everything else */
1412 rwm_chk_referrals( Operation *op, SlapReply *rs )
1414 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
1417 #ifdef ENABLE_REWRITE
1418 rc = rwm_op_dn_massage( op, rs, "referralCheckDN" );
1419 #else /* ! ENABLE_REWRITE */
1421 rc = rwm_op_dn_massage( op, rs, &rc );
1422 #endif /* ! ENABLE_REWRITE */
1423 if ( rc != LDAP_SUCCESS ) {
1424 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1425 send_ldap_error( op, rs, rc, "referralCheckDN massage error" );
1429 return SLAP_CB_CONTINUE;
1441 #ifdef ENABLE_REWRITE
1442 slap_overinst *on = (slap_overinst *) be->bd_info;
1443 struct ldaprwmap *rwmap =
1444 (struct ldaprwmap *)on->on_bi.bi_private;
1446 return rewrite_parse( rwmap->rwm_rw,
1447 fname, lineno, argc, argv );
1449 #else /* !ENABLE_REWRITE */
1450 fprintf( stderr, "%s: line %d: rewrite capabilities "
1451 "are not enabled\n", fname, lineno );
1452 #endif /* !ENABLE_REWRITE */
1458 rwm_suffixmassage_config(
1465 slap_overinst *on = (slap_overinst *) be->bd_info;
1466 struct ldaprwmap *rwmap =
1467 (struct ldaprwmap *)on->on_bi.bi_private;
1469 struct berval bvnc, nvnc, pvnc, brnc, nrnc, prnc;
1471 #ifdef ENABLE_REWRITE
1473 #endif /* ENABLE_REWRITE */
1478 * suffixmassage [<suffix>] <massaged suffix>
1480 * the [<suffix>] field must be defined as a valid suffix
1481 * for the current database;
1482 * the <massaged suffix> shouldn't have already been
1483 * defined as a valid suffix for the current server
1486 if ( be->be_suffix == NULL ) {
1487 fprintf( stderr, "%s: line %d: "
1488 " \"suffixMassage [<suffix>]"
1489 " <massaged suffix>\" without "
1490 "<suffix> part requires database "
1491 "suffix be defined first.\n",
1495 bvnc = be->be_suffix[ 0 ];
1498 } else if ( argc == 3 ) {
1499 ber_str2bv( argv[ 1 ], 0, 0, &bvnc );
1503 fprintf( stderr, "%s: line %d: syntax is"
1504 " \"suffixMassage [<suffix>]"
1505 " <massaged suffix>\"\n",
1510 if ( dnPrettyNormal( NULL, &bvnc, &pvnc, &nvnc, NULL ) != LDAP_SUCCESS ) {
1511 fprintf( stderr, "%s: line %d: suffix DN %s is invalid\n",
1512 fname, lineno, bvnc.bv_val );
1516 ber_str2bv( argv[ massaged ], 0, 0, &brnc );
1517 if ( dnPrettyNormal( NULL, &brnc, &prnc, &nrnc, NULL ) != LDAP_SUCCESS ) {
1518 fprintf( stderr, "%s: line %d: suffix DN %s is invalid\n",
1519 fname, lineno, brnc.bv_val );
1520 free( nvnc.bv_val );
1521 free( pvnc.bv_val );
1525 #ifdef ENABLE_REWRITE
1527 * The suffix massaging is emulated
1528 * by means of the rewrite capabilities
1530 rc = rwm_suffix_massage_config( rwmap->rwm_rw,
1531 &pvnc, &nvnc, &prnc, &nrnc );
1532 free( nvnc.bv_val );
1533 free( pvnc.bv_val );
1534 free( nrnc.bv_val );
1535 free( prnc.bv_val );
1539 #else /* !ENABLE_REWRITE */
1540 ber_bvarray_add( &rwmap->rwm_suffix_massage, &pvnc );
1541 ber_bvarray_add( &rwmap->rwm_suffix_massage, &nvnc );
1543 ber_bvarray_add( &rwmap->rwm_suffix_massage, &prnc );
1544 ber_bvarray_add( &rwmap->rwm_suffix_massage, &nrnc );
1545 #endif /* !ENABLE_REWRITE */
1558 slap_overinst *on = (slap_overinst *) be->bd_info;
1559 struct ldaprwmap *rwmap =
1560 (struct ldaprwmap *)on->on_bi.bi_private;
1562 /* objectclass/attribute mapping */
1563 return rwm_map_config( &rwmap->rwm_oc,
1565 fname, lineno, argc, argv );
1569 rwm_response( Operation *op, SlapReply *rs )
1571 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
1572 struct ldaprwmap *rwmap =
1573 (struct ldaprwmap *)on->on_bi.bi_private;
1577 if ( op->o_tag == LDAP_REQ_SEARCH && rs->sr_type == REP_SEARCH ) {
1578 return rwm_send_entry( op, rs );
1581 switch( op->o_tag ) {
1582 case LDAP_REQ_SEARCH:
1585 case LDAP_REQ_DELETE:
1586 case LDAP_REQ_MODRDN:
1587 case LDAP_REQ_MODIFY:
1588 case LDAP_REQ_COMPARE:
1589 case LDAP_REQ_EXTENDED:
1594 * Rewrite the dn of the referrals, if needed
1597 #ifdef ENABLE_REWRITE
1598 dc.conn = op->o_conn;
1600 dc.ctx = "referralDN";
1601 #else /* ! ENABLE_REWRITE */
1604 #endif /* ! ENABLE_REWRITE */
1605 rc = rwm_referral_result_rewrite( &dc, rs->sr_ref );
1606 if ( rc != LDAP_SUCCESS ) {
1611 rc = rwm_matched( op, rs );
1615 rc = SLAP_CB_CONTINUE;
1630 slap_overinst *on = (slap_overinst *) be->bd_info;
1631 struct ldaprwmap *rwmap =
1632 (struct ldaprwmap *)on->on_bi.bi_private;
1637 if ( strncasecmp( argv[ 0 ], "rwm-", STRLENOF( "rwm-" ) ) == 0 ) {
1639 argv[ 0 ] = &argv0[ STRLENOF( "rwm-" ) ];
1642 if ( strncasecmp( argv[0], "rewrite", STRLENOF("rewrite") ) == 0 ) {
1643 rc = rwm_rw_config( be, fname, lineno, argc, argv );
1645 } else if ( strcasecmp( argv[0], "map" ) == 0 ) {
1646 rc = rwm_m_config( be, fname, lineno, argc, argv );
1648 } else if ( strcasecmp( argv[0], "suffixmassage" ) == 0 ) {
1649 rc = rwm_suffixmassage_config( be, fname, lineno, argc, argv );
1651 } else if ( strcasecmp( argv[0], "t-f-support" ) == 0 ) {
1654 "%s: line %d: \"t-f-support {no|yes|discover}\" needs 1 argument.\n",
1659 if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
1660 rwmap->rwm_flags &= ~(RWM_F_SUPPORT_T_F|RWM_F_SUPPORT_T_F_DISCOVER);
1662 } else if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
1663 rwmap->rwm_flags |= RWM_F_SUPPORT_T_F;
1665 /* TODO: not implemented yet */
1666 } else if ( strcasecmp( argv[ 1 ], "discover" ) == 0 ) {
1668 "%s: line %d: \"discover\" not supported yet "
1669 "in \"t-f-support {no|yes|discover}\".\n",
1673 rwmap->rwm_flags |= RWM_F_SUPPORT_T_F_DISCOVER;
1678 "%s: line %d: unknown value \"%s\" for \"t-f-support {no|yes|discover}\".\n",
1679 fname, lineno, argv[ 1 ] );
1682 } else if ( strcasecmp( argv[0], "normalize-mapped-attrs" ) == 0 ) {
1685 "%s: line %d: \"normalize-mapped-attrs {no|yes}\" needs 1 argument.\n",
1690 if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
1691 rwmap->rwm_flags &= ~(RWM_F_NORMALIZE_MAPPED_ATTRS);
1692 } else if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
1693 rwmap->rwm_flags |= RWM_F_NORMALIZE_MAPPED_ATTRS ;
1697 rc = SLAP_CONF_UNKNOWN;
1711 slap_overinst *on = (slap_overinst *) be->bd_info;
1712 struct ldaprwmap *rwmap;
1713 #ifdef ENABLE_REWRITE
1715 #endif /* ENABLE_REWRITE */
1718 rwmap = (struct ldaprwmap *)ch_calloc( 1, sizeof( struct ldaprwmap ) );
1720 #ifdef ENABLE_REWRITE
1721 rwmap->rwm_rw = rewrite_info_init( REWRITE_MODE_USE_DEFAULT );
1722 if ( rwmap->rwm_rw == NULL ) {
1727 /* this rewriteContext by default must be null;
1728 * rules can be added if required */
1729 rargv[ 0 ] = "rewriteContext";
1730 rargv[ 1 ] = "searchFilter";
1732 rewrite_parse( rwmap->rwm_rw, "<suffix massage>", 1, 2, rargv );
1734 rargv[ 0 ] = "rewriteContext";
1735 rargv[ 1 ] = "default";
1737 rewrite_parse( rwmap->rwm_rw, "<suffix massage>", 2, 2, rargv );
1738 #endif /* ENABLE_REWRITE */
1741 on->on_bi.bi_private = (void *)rwmap;
1744 (void)rwm_db_destroy( be );
1754 slap_overinst *on = (slap_overinst *) be->bd_info;
1757 if ( on->on_bi.bi_private ) {
1758 struct ldaprwmap *rwmap =
1759 (struct ldaprwmap *)on->on_bi.bi_private;
1761 #ifdef ENABLE_REWRITE
1762 if ( rwmap->rwm_rw ) {
1763 rewrite_info_delete( &rwmap->rwm_rw );
1765 #else /* !ENABLE_REWRITE */
1766 if ( rwmap->rwm_suffix_massage ) {
1767 ber_bvarray_free( rwmap->rwm_suffix_massage );
1769 #endif /* !ENABLE_REWRITE */
1771 avl_free( rwmap->rwm_oc.remap, rwm_mapping_dst_free );
1772 avl_free( rwmap->rwm_oc.map, rwm_mapping_free );
1773 avl_free( rwmap->rwm_at.remap, rwm_mapping_dst_free );
1774 avl_free( rwmap->rwm_at.map, rwm_mapping_free );
1782 static slap_overinst rwm = { { NULL } };
1784 #if SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC
1786 #endif /* SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC */
1788 rwm_initialize( void )
1790 memset( &rwm, 0, sizeof( slap_overinst ) );
1792 rwm.on_bi.bi_type = "rwm";
1793 rwm.on_bi.bi_flags =
1794 SLAPO_BFLAG_SINGLE |
1797 rwm.on_bi.bi_db_init = rwm_db_init;
1798 rwm.on_bi.bi_db_config = rwm_db_config;
1799 rwm.on_bi.bi_db_destroy = rwm_db_destroy;
1801 rwm.on_bi.bi_op_bind = rwm_op_bind;
1802 rwm.on_bi.bi_op_search = rwm_op_search;
1803 rwm.on_bi.bi_op_compare = rwm_op_compare;
1804 rwm.on_bi.bi_op_modify = rwm_op_modify;
1805 rwm.on_bi.bi_op_modrdn = rwm_op_modrdn;
1806 rwm.on_bi.bi_op_add = rwm_op_add;
1807 rwm.on_bi.bi_op_delete = rwm_op_delete;
1808 rwm.on_bi.bi_op_unbind = rwm_op_unbind;
1809 rwm.on_bi.bi_extended = rwm_extended;
1811 rwm.on_bi.bi_operational = rwm_operational;
1812 rwm.on_bi.bi_chk_referrals = 0 /* rwm_chk_referrals */ ;
1814 #ifdef ENABLE_REWRITE
1815 rwm.on_bi.bi_connection_init = rwm_conn_init;
1816 rwm.on_bi.bi_connection_destroy = rwm_conn_destroy;
1817 #endif /* ENABLE_REWRITE */
1819 rwm.on_response = rwm_response;
1821 return overlay_register( &rwm );
1824 #if SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC
1826 init_module( int argc, char *argv[] )
1828 return rwm_initialize();
1830 #endif /* SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC */
1832 #endif /* SLAPD_OVER_RWM */