1 /* rwm.c - rewrite/remap operations */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2003-2004 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>
30 rwm_op_dn_massage( Operation *op, SlapReply *rs, void *cookie )
32 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
33 struct ldaprwmap *rwmap =
34 (struct ldaprwmap *)on->on_bi.bi_private;
36 struct berval dn = BER_BVNULL,
42 * Rewrite the bind dn if needed
48 dc.ctx = (char *)cookie;
50 dc.tofrom = ((int *)cookie)[0];
54 rc = rwm_dn_massage( &dc, &op->o_req_dn, &dn, &ndn );
55 if ( rc != LDAP_SUCCESS ) {
59 if ( dn.bv_val == op->o_req_dn.bv_val ) {
63 op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
64 op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
73 rwm_add( Operation *op, SlapReply *rs )
75 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
76 struct ldaprwmap *rwmap =
77 (struct ldaprwmap *)on->on_bi.bi_private;
82 Attribute **ap = NULL;
85 rc = rwm_op_dn_massage( op, rs, "addDn" );
88 rc = rwm_op_dn_massage( op, rs, &rc );
90 if ( rc != LDAP_SUCCESS ) {
91 op->o_bd->bd_info = (BackendInfo *)on->on_info;
92 send_ldap_error( op, rs, rc, "addDn massage error" );
96 /* Count number of attributes in entry */
97 isupdate = be_shadow_update( op );
98 for ( i = 0, ap = &op->oq_add.rs_e->e_attrs; *ap; ) {
102 if ( !isupdate && (*ap)->a_desc->ad_type->sat_no_user_mod ) {
106 rwm_map( &rwmap->rwm_at, &(*ap)->a_desc->ad_cname,
108 if ( BER_BVISNULL( &mapped ) || BER_BVISEMPTY( &mapped ) ) {
112 if ( (*ap)->a_desc->ad_type->sat_syntax
113 == slap_schema.si_syn_distinguishedName )
116 * FIXME: rewrite could fail; in this case
117 * the operation should give up, right?
119 #ifdef ENABLE_REWRITE
120 rc = rwm_dnattr_rewrite( op, rs, "addDn", (*ap)->a_vals, NULL );
123 rc = rwm_dnattr_rewrite( op, rs, &rc, (*ap)->a_vals, NULL );
134 /* FIXME: leaking attribute/values? */
141 /* TODO: map attribute types, values of DN-valued attributes ... */
142 return SLAP_CB_CONTINUE;
146 rwm_bind( Operation *op, SlapReply *rs )
148 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
149 struct ldaprwmap *rwmap =
150 (struct ldaprwmap *)on->on_bi.bi_private;
153 #ifdef ENABLE_REWRITE
154 ( void )rewrite_session_delete( rwmap->rwm_rw, op->o_conn );
155 ( void )rewrite_session_init( rwmap->rwm_rw, op->o_conn );
157 rc = rwm_op_dn_massage( op, rs, "bindDn" );
160 rc = rwm_op_dn_massage( op, rs, &rc );
162 if ( rc != LDAP_SUCCESS ) {
163 op->o_bd->bd_info = (BackendInfo *)on->on_info;
164 send_ldap_error( op, rs, rc, "bindDn massage error" );
168 return SLAP_CB_CONTINUE;
172 rwm_unbind( Operation *op, SlapReply *rs )
174 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
175 struct ldaprwmap *rwmap =
176 (struct ldaprwmap *)on->on_bi.bi_private;
178 #ifdef ENABLE_REWRITE
179 rewrite_session_delete( rwmap->rwm_rw, op->o_conn );
182 return SLAP_CB_CONTINUE;
186 rwm_compare( 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;
193 struct berval mapped_at = BER_BVNULL,
194 mapped_vals[2] = { BER_BVNULL, BER_BVNULL };
196 #ifdef ENABLE_REWRITE
197 rc = rwm_op_dn_massage( op, rs, "compareDn" );
200 rc = rwm_op_dn_massage( op, rs, &rc );
202 if ( rc != LDAP_SUCCESS ) {
203 op->o_bd->bd_info = (BackendInfo *)on->on_info;
204 send_ldap_error( op, rs, rc, "compareDn massage error" );
208 /* if the attribute is an objectClass, try to remap its value */
209 if ( op->orc_ava->aa_desc == slap_schema.si_ad_objectClass
210 || op->orc_ava->aa_desc == slap_schema.si_ad_structuralObjectClass )
212 rwm_map( &rwmap->rwm_oc, &op->orc_ava->aa_value,
213 &mapped_vals[0], RWM_MAP );
214 if ( BER_BVISNULL( &mapped_vals[0] ) || BER_BVISEMPTY( &mapped_vals[0] ) )
216 op->o_bd->bd_info = (BackendInfo *)on->on_info;
217 send_ldap_error( op, rs, LDAP_OTHER, "compare objectClass map error" );
220 } else if ( mapped_vals[0].bv_val != op->orc_ava->aa_value.bv_val ) {
221 free( op->orc_ava->aa_value.bv_val );
222 op->orc_ava->aa_value = mapped_vals[0];
224 mapped_at = op->orc_ava->aa_desc->ad_cname;
227 rwm_map( &rwmap->rwm_at, &op->orc_ava->aa_desc->ad_cname,
228 &mapped_at, RWM_MAP );
229 if ( BER_BVISNULL( &mapped_at ) || BER_BVISEMPTY( &mapped_at ) )
231 op->o_bd->bd_info = (BackendInfo *)on->on_info;
232 send_ldap_error( op, rs, LDAP_OTHER, "compare attributeType map error" );
235 if ( op->orc_ava->aa_desc->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName )
237 mapped_vals[0] = op->orc_ava->aa_value;
239 #ifdef ENABLE_REWRITE
240 rc = rwm_dnattr_rewrite( op, rs, "compareAttrDN", mapped_vals, NULL );
243 rc = rwm_dnattr_rewrite( op, rs, &rc, mapped_vals, NULL );
246 if ( rc != LDAP_SUCCESS ) {
247 op->o_bd->bd_info = (BackendInfo *)on->on_info;
248 send_ldap_error( op, rs, rc, "compareAttrDN massage error" );
252 if ( mapped_vals[0].bv_val != op->orc_ava->aa_value.bv_val ) {
253 free( op->orc_ava->aa_value.bv_val );
254 op->orc_ava->aa_value = mapped_vals[0];
259 return SLAP_CB_CONTINUE;
263 rwm_delete( Operation *op, SlapReply *rs )
265 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
268 #ifdef ENABLE_REWRITE
269 rc = rwm_op_dn_massage( op, rs, "deleteDn" );
272 rc = rwm_op_dn_massage( op, rs, &rc );
274 if ( rc != LDAP_SUCCESS ) {
275 op->o_bd->bd_info = (BackendInfo *)on->on_info;
276 send_ldap_error( op, rs, rc, "deleteDn massage error" );
280 return SLAP_CB_CONTINUE;
284 rwm_modify( Operation *op, SlapReply *rs )
286 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
287 struct ldaprwmap *rwmap =
288 (struct ldaprwmap *)on->on_bi.bi_private;
294 #ifdef ENABLE_REWRITE
295 rc = rwm_op_dn_massage( op, rs, "modifyDn" );
298 rc = rwm_op_dn_massage( op, rs, &rc );
300 if ( rc != LDAP_SUCCESS ) {
301 op->o_bd->bd_info = (BackendInfo *)on->on_info;
302 send_ldap_error( op, rs, rc, "modifyDn massage error" );
306 isupdate = be_shadow_update( op );
307 for ( mlp = &op->oq_modify.rs_modlist; *mlp; ) {
310 if ( !isupdate && (*mlp)->sml_desc->ad_type->sat_no_user_mod ) {
314 *mlp = (*mlp)->sml_next;
315 slap_mod_free( &ml->sml_mod, 0 );
321 if ( (*mlp)->sml_desc == slap_schema.si_ad_objectClass
322 || (*mlp)->sml_desc == slap_schema.si_ad_structuralObjectClass ) {
326 struct ldapmapping *m;
329 drop_missing = rwm_mapping( &rwmap->rwm_at, &(*mlp)->sml_desc->ad_cname, &m, RWM_MAP );
330 if ( drop_missing || ( m != NULL && BER_BVISNULL( &m->m_dst ) ) )
335 *mlp = (*mlp)->sml_next;
336 slap_mod_free( &ml->sml_mod, 0 );
343 /* use new attribute description */
344 assert( m->m_dst_ad );
345 (*mlp)->sml_desc = m->m_dst_ad;
349 if ( (*mlp)->sml_values != NULL ) {
353 for ( last = 0; !BER_BVISNULL( &(*mlp)->sml_values[last] ); last++ )
357 for ( j = 0; !BER_BVISNULL( &(*mlp)->sml_values[j] ); j++ ) {
358 struct berval mapped = BER_BVNULL;
360 rwm_map( &rwmap->rwm_oc,
361 &(*mlp)->sml_values[j],
363 if ( BER_BVISNULL( &mapped ) || BER_BVISEMPTY( &mapped ) ) {
364 /* FIXME: we allow to remove objectClasses as well;
365 * if the resulting entry is inconsistent, that's
366 * the relayed database's business...
372 *mlp = (*mlp)->sml_next;
373 slap_mod_free( &ml->sml_mod, 0 );
379 (*mlp)->sml_values[j] = (*mlp)->sml_values[last];
380 BER_BVZERO( &(*mlp)->sml_values[last] );
385 ch_free( (*mlp)->sml_values[j].bv_val );
386 ber_dupbv( &(*mlp)->sml_values[j], &mapped );
391 if ( (*mlp)->sml_desc->ad_type->sat_syntax ==
392 slap_schema.si_syn_distinguishedName )
394 #ifdef ENABLE_REWRITE
395 rc = rwm_dnattr_rewrite( op, rs, "modifyDn",
396 (*mlp)->sml_values, &(*mlp)->sml_nvalues );
399 rc = rwm_dnattr_rewrite( op, rs, &rc,
400 (*mlp)->sml_values, &(*mlp)->sml_nvalues );
404 if ( rc != LDAP_SUCCESS ) {
408 *mlp = (*mlp)->sml_next;
409 slap_mod_free( &ml->sml_mod, 0 );
417 mlp = &(*mlp)->sml_next;
420 /* TODO: rewrite attribute types, values of DN-valued attributes ... */
421 return SLAP_CB_CONTINUE;
425 rwm_modrdn( Operation *op, SlapReply *rs )
427 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
430 #ifdef ENABLE_REWRITE
431 rc = rwm_op_dn_massage( op, rs, "renameDn" );
434 rc = rwm_op_dn_massage( op, rs, &rc );
436 if ( rc != LDAP_SUCCESS ) {
437 op->o_bd->bd_info = (BackendInfo *)on->on_info;
438 send_ldap_error( op, rs, rc, "renameDn massage error" );
442 /* TODO: rewrite attribute types, values of DN-valued attributes ... */
443 return SLAP_CB_CONTINUE;
447 rwm_swap_attrs( Operation *op, SlapReply *rs )
449 slap_callback *cb = op->o_callback;
450 AttributeName *an = (AttributeName *)cb->sc_private;
454 return SLAP_CB_CONTINUE;
458 rwm_mentry_free( Operation *op, SlapReply *rs )
460 slap_callback *cb = op->o_callback;
462 if ( rs->sr_mentry ) {
463 entry_free( rs->sr_mentry );
464 rs->sr_mentry = NULL;
467 return SLAP_CB_CONTINUE;
471 rwm_search( Operation *op, SlapReply *rs )
473 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
474 struct ldaprwmap *rwmap =
475 (struct ldaprwmap *)on->on_bi.bi_private;
480 struct berval fstr = BER_BVNULL;
484 AttributeName *an = NULL;
488 #ifdef ENABLE_REWRITE
489 rc = rwm_op_dn_massage( op, rs, "searchDn" );
492 rc = rwm_op_dn_massage( op, rs, &rc );
494 if ( rc != LDAP_SUCCESS ) {
495 text = "searchDn massage error";
500 * Rewrite the bind dn if needed
503 #ifdef ENABLE_REWRITE
504 dc.conn = op->o_conn;
506 dc.ctx = "searchFilterAttrDN";
512 rc = rwm_filter_map_rewrite( &dc, op->ors_filter, &fstr );
513 if ( rc != LDAP_SUCCESS ) {
514 text = "searchFilter/searchFilterAttrDN massage error";
518 f = str2filter_x( op, fstr.bv_val );
521 text = "massaged filter parse error";
525 if ( !BER_BVISNULL( &op->ors_filterstr ) ) {
526 ch_free( op->ors_filterstr.bv_val );
529 if( op->ors_filter ) {
530 filter_free_x( op, op->ors_filter );
534 op->ors_filterstr = fstr;
536 rc = rwm_map_attrnames( &rwmap->rwm_at, &rwmap->rwm_oc,
537 op->ors_attrs, &an, RWM_MAP );
538 if ( rc != LDAP_SUCCESS ) {
539 text = "attribute list mapping error";
543 cb = (slap_callback *) op->o_tmpcalloc( sizeof( slap_callback ),
544 1, op->o_tmpmemctx );
550 cb->sc_response = rwm_swap_attrs;
551 cb->sc_cleanup = rwm_mentry_free;
552 cb->sc_private = (void *)op->ors_attrs;
553 cb->sc_next = op->o_callback;
558 return SLAP_CB_CONTINUE;
566 filter_free_x( op, f );
569 if ( !BER_BVISNULL( &fstr ) ) {
570 ch_free( fstr.bv_val );
573 op->o_bd->bd_info = (BackendInfo *)on->on_info;
574 send_ldap_error( op, rs, rc, text );
581 rwm_extended( Operation *op, SlapReply *rs )
583 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
586 #ifdef ENABLE_REWRITE
587 rc = rwm_op_dn_massage( op, rs, "extendedDn" );
590 rc = rwm_op_dn_massage( op, rs, &rc );
592 if ( rc != LDAP_SUCCESS ) {
593 op->o_bd->bd_info = (BackendInfo *)on->on_info;
594 send_ldap_error( op, rs, rc, "extendedDn massage error" );
598 /* TODO: rewrite/map extended data ? ... */
603 rwm_matched( Operation *op, SlapReply *rs )
605 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
606 struct ldaprwmap *rwmap =
607 (struct ldaprwmap *)on->on_bi.bi_private;
609 struct berval dn, mdn;
613 if ( rs->sr_matched == NULL ) {
614 return SLAP_CB_CONTINUE;
618 #ifdef ENABLE_REWRITE
619 dc.conn = op->o_conn;
621 dc.ctx = "matchedDN";
626 ber_str2bv( rs->sr_matched, 0, 0, &dn );
627 rc = rwm_dn_massage( &dc, &dn, &mdn, NULL );
628 if ( rc != LDAP_SUCCESS ) {
630 rs->sr_text = "Rewrite error";
634 if ( mdn.bv_val != dn.bv_val ) {
635 if ( rs->sr_flags & REP_MATCHED_MUSTBEFREED ) {
636 ch_free( (void *)rs->sr_matched );
639 rs->sr_flags |= REP_MATCHED_MUSTBEFREED;
641 rs->sr_matched = mdn.bv_val;
644 return SLAP_CB_CONTINUE;
648 rwm_send_entry( Operation *op, SlapReply *rs )
650 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
651 struct ldaprwmap *rwmap =
652 (struct ldaprwmap *)on->on_bi.bi_private;
656 struct berval dn = BER_BVNULL,
662 assert( rs->sr_entry );
665 * Rewrite the dn of the result, if needed
668 #ifdef ENABLE_REWRITE
669 dc.conn = op->o_conn;
671 dc.ctx = "searchResult";
677 flags = rs->sr_flags;
679 if ( rs->sr_mentry != NULL ) {
685 if ( !( rs->sr_flags & REP_ENTRY_MODIFIABLE ) ) {
686 /* FIXME: all we need to duplicate are:
689 * - attributes that are requested
690 * - no values if attrsonly is set
699 // flags |= ( REP_ENTRY_MODIFIABLE | REP_ENTRY_MUSTBEFREED );
704 * Note: this may fail if the target host(s) schema differs
705 * from the one known to the meta, and a DN with unknown
706 * attributes is returned.
708 rc = rwm_dn_massage( &dc, &e->e_name, &dn, &ndn );
709 if ( rc != LDAP_SUCCESS ) {
713 if ( e->e_name.bv_val != dn.bv_val ) {
714 free( e->e_name.bv_val );
715 free( e->e_nname.bv_val );
721 /* TODO: map entry attribute types, objectclasses
722 * and dn-valued attribute values */
724 /* FIXME: the entries are in the remote mapping form;
725 * so we need to select those attributes we are willing
726 * to return, and remap them accordingly */
728 for ( ap = &e->e_attrs; *ap; ) {
729 struct ldapmapping *m;
733 if ( op->ors_attrs != NULL && !ad_inlist( (*ap)->a_desc, op->ors_attrs ) ) {
743 drop_missing = rwm_mapping( &rwmap->rwm_at,
744 &(*ap)->a_desc->ad_cname, &m, RWM_REMAP );
745 if ( drop_missing || ( m != NULL && BER_BVISEMPTY( &m->m_dst ) ) ) {
755 /* no subschemaSubentry */
756 if ( (*ap)->a_desc == slap_schema.si_ad_subschemaSubentry ) {
759 * We eat target's subschemaSubentry because
760 * a search for this value is likely not
761 * to resolve to the appropriate backend;
762 * later, the local subschemaSubentry is
774 for ( last = 0; !BER_BVISNULL( &(*ap)->a_vals[last] ); last++ )
778 /* empty? for now, we leave it in place */
783 if ( (*ap)->a_desc == slap_schema.si_ad_objectClass
784 || (*ap)->a_desc == slap_schema.si_ad_structuralObjectClass )
788 for ( bv = (*ap)->a_vals; !BER_BVISNULL( bv ); bv++ ) {
789 struct berval mapped;
791 rwm_map( &rwmap->rwm_oc, &bv[0], &mapped, RWM_REMAP );
792 if ( BER_BVISNULL( &mapped ) || BER_BVISEMPTY( &mapped ) ) {
793 ch_free( bv[0].bv_val );
794 BER_BVZERO( &bv[0] );
795 if ( &(*ap)->a_vals[last] > &bv[0] ) {
796 bv[0] = (*ap)->a_vals[last];
797 BER_BVZERO( &(*ap)->a_vals[last] );
802 } else if ( mapped.bv_val != bv[0].bv_val ) {
804 * FIXME: after LBER_FREEing
805 * the value is replaced by
808 free( bv[0].bv_val );
809 ber_dupbv( &bv[0], &mapped );
814 * It is necessary to try to rewrite attributes with
815 * dn syntax because they might be used in ACLs as
816 * members of groups; since ACLs are applied to the
817 * rewritten stuff, no dn-based subject clause could
818 * be used at the ldap backend side (see
819 * http://www.OpenLDAP.org/faq/data/cache/452.html)
820 * The problem can be overcome by moving the dn-based
821 * ACLs to the target directory server, and letting
822 * everything pass thru the ldap backend.
824 } else if ( (*ap)->a_desc->ad_type->sat_syntax ==
825 slap_schema.si_syn_distinguishedName )
827 rc = rwm_dnattr_result_rewrite( &dc, (*ap)->a_vals );
828 if ( rc != LDAP_SUCCESS ) {
840 /* rewrite the attribute description */
841 assert( m->m_dst_ad );
842 (*ap)->a_desc = m->m_dst_ad;
851 rs->sr_flags = flags;
853 return SLAP_CB_CONTINUE;
856 if ( !BER_BVISNULL( &dn ) ) {
857 ch_free( dn.bv_val );
860 if ( !BER_BVISNULL( &ndn ) ) {
861 ch_free( ndn.bv_val );
864 if ( e != NULL && e != rs->sr_mentry ) {
880 #ifdef ENABLE_REWRITE
881 slap_overinst *on = (slap_overinst *) be->bd_info;
882 struct ldaprwmap *rwmap =
883 (struct ldaprwmap *)on->on_bi.bi_private;
885 return rewrite_parse( rwmap->rwm_rw,
886 fname, lineno, argc, argv );
888 #else /* !ENABLE_REWRITE */
889 fprintf( stderr, "%s: line %d: rewrite capabilities "
890 "are not enabled\n", fname, lineno );
891 #endif /* !ENABLE_REWRITE */
897 rwm_suffixmassage_config(
905 slap_overinst *on = (slap_overinst *) be->bd_info;
906 struct ldaprwmap *rwmap =
907 (struct ldaprwmap *)on->on_bi.bi_private;
909 struct berval bvnc, nvnc, pvnc, brnc, nrnc, prnc;
910 #ifdef ENABLE_REWRITE
912 #endif /* ENABLE_REWRITE */
917 * suffixmassage <suffix> <massaged suffix>
919 * the <suffix> field must be defined as a valid suffix
920 * (or suffixAlias?) for the current database;
921 * the <massaged suffix> shouldn't have already been
922 * defined as a valid suffix or suffixAlias for the
926 fprintf( stderr, "%s: line %d: syntax is"
927 " \"suffixMassage <suffix>"
928 " <massaged suffix>\"\n",
933 ber_str2bv( argv[1], 0, 0, &bvnc );
934 if ( dnPrettyNormal( NULL, &bvnc, &pvnc, &nvnc, NULL ) != LDAP_SUCCESS ) {
935 fprintf( stderr, "%s: line %d: suffix DN %s is invalid\n",
936 fname, lineno, bvnc.bv_val );
940 ber_str2bv( argv[2], 0, 0, &brnc );
941 if ( dnPrettyNormal( NULL, &brnc, &prnc, &nrnc, NULL ) != LDAP_SUCCESS ) {
942 fprintf( stderr, "%s: line %d: suffix DN %s is invalid\n",
943 fname, lineno, brnc.bv_val );
949 #ifdef ENABLE_REWRITE
951 * The suffix massaging is emulated
952 * by means of the rewrite capabilities
954 rc = rwm_suffix_massage_config( rwmap->rwm_rw,
955 &pvnc, &nvnc, &prnc, &nrnc );
963 #else /* !ENABLE_REWRITE */
964 ber_bvarray_add( &rwmap->rwm_suffix_massage, &pvnc );
965 ber_bvarray_add( &rwmap->rwm_suffix_massage, &nvnc );
967 ber_bvarray_add( &rwmap->rwm_suffix_massage, &prnc );
968 ber_bvarray_add( &rwmap->rwm_suffix_massage, &nrnc );
969 #endif /* !ENABLE_REWRITE */
983 slap_overinst *on = (slap_overinst *) be->bd_info;
984 struct ldaprwmap *rwmap =
985 (struct ldaprwmap *)on->on_bi.bi_private;
987 /* objectclass/attribute mapping */
988 return rwm_map_config( &rwmap->rwm_oc,
990 fname, lineno, argc, argv );
994 rwm_response( Operation *op, SlapReply *rs )
998 if ( op->o_tag == LDAP_REQ_SEARCH && rs->sr_type == REP_SEARCH ) {
999 return rwm_send_entry( op, rs );
1002 switch( op->o_tag ) {
1003 case LDAP_REQ_SEARCH:
1004 /* Note: the operation attrs are remapped */
1005 if ( op->ors_attrs != NULL && op->ors_attrs != rs->sr_attrs )
1007 ch_free( op->ors_attrs );
1008 op->ors_attrs = rs->sr_attrs;
1014 case LDAP_REQ_DELETE:
1015 case LDAP_REQ_MODRDN:
1016 case LDAP_REQ_MODIFY:
1017 case LDAP_REQ_COMPARE:
1018 case LDAP_REQ_EXTENDED:
1019 rc = rwm_matched( op, rs );
1023 rc = SLAP_CB_CONTINUE;
1042 if ( strncasecmp( argv[ 0 ], "rwm-", STRLENOF( "rwm-" ) ) == 0 ) {
1044 argv[ 0 ] = &argv0[ STRLENOF( "rwm-" ) ];
1047 if ( strncasecmp( argv[0], "rewrite", STRLENOF("rewrite") ) == 0 ) {
1048 rc = rwm_rw_config( be, fname, lineno, argc, argv );
1050 } else if ( strcasecmp( argv[0], "map" ) == 0 ) {
1051 rc = rwm_m_config( be, fname, lineno, argc, argv );
1053 } else if ( strcasecmp( argv[0], "suffixmassage" ) == 0 ) {
1054 rc = rwm_suffixmassage_config( be, fname, lineno, argc, argv );
1057 rc = SLAP_CONF_UNKNOWN;
1072 slap_overinst *on = (slap_overinst *) be->bd_info;
1073 struct ldapmapping *mapping = NULL;
1074 struct ldaprwmap *rwmap;
1076 rwmap = (struct ldaprwmap *)ch_malloc(sizeof(struct ldaprwmap));
1077 memset(rwmap, 0, sizeof(struct ldaprwmap));
1079 #ifdef ENABLE_REWRITE
1080 rwmap->rwm_rw = rewrite_info_init( REWRITE_MODE_USE_DEFAULT );
1081 if ( rwmap->rwm_rw == NULL ) {
1089 /* this rewriteContext by default must be null;
1090 * rules can be added if required */
1091 rargv[ 0 ] = "rewriteContext";
1092 rargv[ 1 ] = "searchFilter";
1094 rewrite_parse( rwmap->rwm_rw, "<suffix massage>", 1, 2, rargv );
1096 rargv[ 0 ] = "rewriteContext";
1097 rargv[ 1 ] = "default";
1099 rewrite_parse( rwmap->rwm_rw, "<suffix massage>", 2, 2, rargv );
1102 #endif /* ENABLE_REWRITE */
1104 if ( rwm_map_init( &rwmap->rwm_oc, &mapping ) != LDAP_SUCCESS ||
1105 rwm_map_init( &rwmap->rwm_at, &mapping ) != LDAP_SUCCESS )
1110 on->on_bi.bi_private = (void *)rwmap;
1120 slap_overinst *on = (slap_overinst *) be->bd_info;
1123 if ( on->on_bi.bi_private ) {
1124 struct ldaprwmap *rwmap =
1125 (struct ldaprwmap *)on->on_bi.bi_private;
1127 #ifdef ENABLE_REWRITE
1128 if (rwmap->rwm_rw) {
1129 rewrite_info_delete( &rwmap->rwm_rw );
1131 #else /* !ENABLE_REWRITE */
1132 if ( rwmap->rwm_suffix_massage ) {
1133 ber_bvarray_free( rwmap->rwm_suffix_massage );
1135 #endif /* !ENABLE_REWRITE */
1137 avl_free( rwmap->rwm_oc.remap, NULL );
1138 avl_free( rwmap->rwm_oc.map, rwm_mapping_free );
1139 avl_free( rwmap->rwm_at.remap, NULL );
1140 avl_free( rwmap->rwm_at.map, rwm_mapping_free );
1146 static slap_overinst rwm = { { NULL } };
1151 memset( &rwm, 0, sizeof(slap_overinst) );
1153 rwm.on_bi.bi_type = "rwm";
1154 rwm.on_bi.bi_db_init = rwm_over_init;
1155 rwm.on_bi.bi_db_config = rwm_config;
1156 rwm.on_bi.bi_db_destroy = rwm_destroy;
1158 rwm.on_bi.bi_op_bind = rwm_bind;
1159 rwm.on_bi.bi_op_search = rwm_search;
1160 rwm.on_bi.bi_op_compare = rwm_compare;
1161 rwm.on_bi.bi_op_modify = rwm_modify;
1162 rwm.on_bi.bi_op_modrdn = rwm_modrdn;
1163 rwm.on_bi.bi_op_add = rwm_add;
1164 rwm.on_bi.bi_op_delete = rwm_delete;
1165 rwm.on_bi.bi_op_unbind = rwm_unbind;
1166 rwm.on_bi.bi_extended = rwm_extended;
1168 rwm.on_response = rwm_response;
1170 return overlay_register( &rwm );
1173 #if SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC
1174 int init_module(int argc, char *argv[]) {
1179 #endif /* SLAPD_OVER_RWM */