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_search( Operation *op, SlapReply *rs )
460 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
461 struct ldaprwmap *rwmap =
462 (struct ldaprwmap *)on->on_bi.bi_private;
467 struct berval fstr = BER_BVNULL;
471 AttributeName *an = NULL;
475 #ifdef ENABLE_REWRITE
476 rc = rwm_op_dn_massage( op, rs, "searchDn" );
479 rc = rwm_op_dn_massage( op, rs, &rc );
481 if ( rc != LDAP_SUCCESS ) {
482 text = "searchDn massage error";
487 * Rewrite the bind dn if needed
490 #ifdef ENABLE_REWRITE
491 dc.conn = op->o_conn;
493 dc.ctx = "searchFilterAttrDN";
499 rc = rwm_filter_map_rewrite( &dc, op->ors_filter, &fstr );
500 if ( rc != LDAP_SUCCESS ) {
501 text = "searchFilter/searchFilterAttrDN massage error";
505 f = str2filter_x( op, fstr.bv_val );
508 text = "massaged filter parse error";
512 if ( !BER_BVISNULL( &op->ors_filterstr ) ) {
513 ch_free( op->ors_filterstr.bv_val );
516 if( op->ors_filter ) {
517 filter_free_x( op, op->ors_filter );
521 op->ors_filterstr = fstr;
523 rc = rwm_map_attrnames( &rwmap->rwm_at, &rwmap->rwm_oc,
524 op->ors_attrs, &an, RWM_MAP );
525 if ( rc != LDAP_SUCCESS ) {
526 text = "attribute list mapping error";
530 cb = (slap_callback *)ch_malloc( sizeof( slap_callback ) );
536 cb->sc_response = rwm_swap_attrs;
537 cb->sc_cleanup = NULL;
538 cb->sc_private = (void *)op->ors_attrs;
539 cb->sc_next = op->o_callback;
544 /* TODO: rewrite/map filter & attrs */
545 return SLAP_CB_CONTINUE;
553 filter_free_x( op, f );
556 if ( !BER_BVISNULL( &fstr ) ) {
557 ch_free( fstr.bv_val );
560 op->o_bd->bd_info = (BackendInfo *)on->on_info;
561 send_ldap_error( op, rs, rc, text );
568 rwm_extended( Operation *op, SlapReply *rs )
570 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
573 #ifdef ENABLE_REWRITE
574 rc = rwm_op_dn_massage( op, rs, "extendedDn" );
577 rc = rwm_op_dn_massage( op, rs, &rc );
579 if ( rc != LDAP_SUCCESS ) {
580 op->o_bd->bd_info = (BackendInfo *)on->on_info;
581 send_ldap_error( op, rs, rc, "extendedDn massage error" );
585 /* TODO: rewrite/map extended data ? ... */
590 rwm_matched( Operation *op, SlapReply *rs )
592 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
593 struct ldaprwmap *rwmap =
594 (struct ldaprwmap *)on->on_bi.bi_private;
596 struct berval dn, mdn;
600 if ( rs->sr_matched == NULL ) {
601 return SLAP_CB_CONTINUE;
605 #ifdef ENABLE_REWRITE
606 dc.conn = op->o_conn;
608 dc.ctx = "matchedDN";
613 ber_str2bv( rs->sr_matched, 0, 0, &dn );
614 rc = rwm_dn_massage( &dc, &dn, &mdn, NULL );
615 if ( rc != LDAP_SUCCESS ) {
617 rs->sr_text = "Rewrite error";
621 if ( mdn.bv_val != dn.bv_val ) {
622 if ( rs->sr_flags & REP_MATCHED_MUSTBEFREED ) {
623 ch_free( (void *)rs->sr_matched );
626 rs->sr_flags |= REP_MATCHED_MUSTBEFREED;
628 rs->sr_matched = mdn.bv_val;
631 return SLAP_CB_CONTINUE;
635 rwm_send_entry( Operation *op, SlapReply *rs )
637 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
638 struct ldaprwmap *rwmap =
639 (struct ldaprwmap *)on->on_bi.bi_private;
643 struct berval dn = BER_BVNULL,
649 assert( rs->sr_entry );
654 * Rewrite the dn of the result, if needed
657 #ifdef ENABLE_REWRITE
658 dc.conn = op->o_conn;
660 dc.ctx = "searchResult";
666 flags = rs->sr_flags;
668 if ( !( rs->sr_flags & REP_ENTRY_MODIFIABLE ) ) {
669 /* FIXME: all we need to duplicate are:
672 * - attributes that are requested
673 * - no values if attrsonly is set
682 flags |= ( REP_ENTRY_MODIFIABLE | REP_ENTRY_MUSTBEFREED );
686 * Note: this may fail if the target host(s) schema differs
687 * from the one known to the meta, and a DN with unknown
688 * attributes is returned.
690 rc = rwm_dn_massage( &dc, &e->e_name, &dn, &ndn );
691 if ( rc != LDAP_SUCCESS ) {
695 if ( e->e_name.bv_val != dn.bv_val ) {
696 free( e->e_name.bv_val );
697 free( e->e_nname.bv_val );
703 /* TODO: map entry attribute types, objectclasses
704 * and dn-valued attribute values */
706 /* FIXME: the entries are in the remote mapping form;
707 * so we need to select those attributes we are willing
708 * to return, and remap them accordingly */
710 for ( ap = &e->e_attrs; *ap; ) {
711 struct ldapmapping *m;
715 if ( op->ors_attrs != NULL && !ad_inlist( (*ap)->a_desc, op->ors_attrs ) ) {
725 drop_missing = rwm_mapping( &rwmap->rwm_at,
726 &(*ap)->a_desc->ad_cname, &m, RWM_REMAP );
727 if ( drop_missing || ( m != NULL && BER_BVISEMPTY( &m->m_dst ) ) ) {
737 /* no subschemaSubentry */
738 if ( (*ap)->a_desc == slap_schema.si_ad_subschemaSubentry ) {
741 * We eat target's subschemaSubentry because
742 * a search for this value is likely not
743 * to resolve to the appropriate backend;
744 * later, the local subschemaSubentry is
756 for ( last = 0; !BER_BVISNULL( &(*ap)->a_vals[last] ); last++ )
760 /* empty? for now, we leave it in place */
765 if ( (*ap)->a_desc == slap_schema.si_ad_objectClass
766 || (*ap)->a_desc == slap_schema.si_ad_structuralObjectClass )
770 for ( bv = (*ap)->a_vals; !BER_BVISNULL( bv ); bv++ ) {
771 struct berval mapped;
773 rwm_map( &rwmap->rwm_oc, &bv[0], &mapped, RWM_REMAP );
774 if ( BER_BVISNULL( &mapped ) || BER_BVISEMPTY( &mapped ) ) {
775 ch_free( bv[0].bv_val );
776 BER_BVZERO( &bv[0] );
777 if ( &(*ap)->a_vals[last] > &bv[0] ) {
778 bv[0] = (*ap)->a_vals[last];
779 BER_BVZERO( &(*ap)->a_vals[last] );
784 } else if ( mapped.bv_val != bv[0].bv_val ) {
786 * FIXME: after LBER_FREEing
787 * the value is replaced by
790 free( bv[0].bv_val );
791 ber_dupbv( &bv[0], &mapped );
796 * It is necessary to try to rewrite attributes with
797 * dn syntax because they might be used in ACLs as
798 * members of groups; since ACLs are applied to the
799 * rewritten stuff, no dn-based subject clause could
800 * be used at the ldap backend side (see
801 * http://www.OpenLDAP.org/faq/data/cache/452.html)
802 * The problem can be overcome by moving the dn-based
803 * ACLs to the target directory server, and letting
804 * everything pass thru the ldap backend.
806 } else if ( (*ap)->a_desc->ad_type->sat_syntax ==
807 slap_schema.si_syn_distinguishedName )
809 rc = rwm_dnattr_result_rewrite( &dc, (*ap)->a_vals );
810 if ( rc != LDAP_SUCCESS ) {
822 /* rewrite the attribute description */
823 assert( m->m_dst_ad );
824 (*ap)->a_desc = m->m_dst_ad;
833 rs->sr_flags = flags;
835 return SLAP_CB_CONTINUE;
838 if ( !BER_BVISNULL( &dn ) ) {
839 ch_free( dn.bv_val );
842 if ( !BER_BVISNULL( &ndn ) ) {
843 ch_free( ndn.bv_val );
846 if ( e != NULL && e != rs->sr_entry ) {
862 #ifdef ENABLE_REWRITE
863 slap_overinst *on = (slap_overinst *) be->bd_info;
864 struct ldaprwmap *rwmap =
865 (struct ldaprwmap *)on->on_bi.bi_private;
867 return rewrite_parse( rwmap->rwm_rw,
868 fname, lineno, argc, argv );
870 #else /* !ENABLE_REWRITE */
871 fprintf( stderr, "%s: line %d: rewrite capabilities "
872 "are not enabled\n", fname, lineno );
873 #endif /* !ENABLE_REWRITE */
879 rwm_suffixmassage_config(
887 slap_overinst *on = (slap_overinst *) be->bd_info;
888 struct ldaprwmap *rwmap =
889 (struct ldaprwmap *)on->on_bi.bi_private;
891 struct berval bvnc, nvnc, pvnc, brnc, nrnc, prnc;
892 #ifdef ENABLE_REWRITE
894 #endif /* ENABLE_REWRITE */
899 * suffixmassage <suffix> <massaged suffix>
901 * the <suffix> field must be defined as a valid suffix
902 * (or suffixAlias?) for the current database;
903 * the <massaged suffix> shouldn't have already been
904 * defined as a valid suffix or suffixAlias for the
908 fprintf( stderr, "%s: line %d: syntax is"
909 " \"suffixMassage <suffix>"
910 " <massaged suffix>\"\n",
915 ber_str2bv( argv[1], 0, 0, &bvnc );
916 if ( dnPrettyNormal( NULL, &bvnc, &pvnc, &nvnc, NULL ) != LDAP_SUCCESS ) {
917 fprintf( stderr, "%s: line %d: suffix DN %s is invalid\n",
918 fname, lineno, bvnc.bv_val );
922 ber_str2bv( argv[2], 0, 0, &brnc );
923 if ( dnPrettyNormal( NULL, &brnc, &prnc, &nrnc, NULL ) != LDAP_SUCCESS ) {
924 fprintf( stderr, "%s: line %d: suffix DN %s is invalid\n",
925 fname, lineno, brnc.bv_val );
931 #ifdef ENABLE_REWRITE
933 * The suffix massaging is emulated
934 * by means of the rewrite capabilities
936 rc = rwm_suffix_massage_config( rwmap->rwm_rw,
937 &pvnc, &nvnc, &prnc, &nrnc );
945 #else /* !ENABLE_REWRITE */
946 ber_bvarray_add( &rwmap->rwm_suffix_massage, &pvnc );
947 ber_bvarray_add( &rwmap->rwm_suffix_massage, &nvnc );
949 ber_bvarray_add( &rwmap->rwm_suffix_massage, &prnc );
950 ber_bvarray_add( &rwmap->rwm_suffix_massage, &nrnc );
951 #endif /* !ENABLE_REWRITE */
965 slap_overinst *on = (slap_overinst *) be->bd_info;
966 struct ldaprwmap *rwmap =
967 (struct ldaprwmap *)on->on_bi.bi_private;
969 /* objectclass/attribute mapping */
970 return rwm_map_config( &rwmap->rwm_oc,
972 fname, lineno, argc, argv );
976 rwm_response( Operation *op, SlapReply *rs )
980 if ( op->o_tag == LDAP_REQ_SEARCH && rs->sr_type == REP_SEARCH ) {
981 return rwm_send_entry( op, rs );
984 switch( op->o_tag ) {
985 case LDAP_REQ_SEARCH:
986 /* Note: the operation attrs are remapped */
987 if ( op->ors_attrs != NULL && op->ors_attrs != rs->sr_attrs )
989 ch_free( op->ors_attrs );
990 op->ors_attrs = rs->sr_attrs;
996 case LDAP_REQ_DELETE:
997 case LDAP_REQ_MODRDN:
998 case LDAP_REQ_MODIFY:
999 case LDAP_REQ_COMPARE:
1000 case LDAP_REQ_EXTENDED:
1001 rc = rwm_matched( op, rs );
1005 rc = SLAP_CB_CONTINUE;
1024 if ( strncasecmp( argv[ 0 ], "rwm-", STRLENOF( "rwm-" ) ) == 0 ) {
1026 argv[ 0 ] = &argv0[ STRLENOF( "rwm-" ) ];
1029 if ( strncasecmp( argv[0], "rewrite", STRLENOF("rewrite") ) == 0 ) {
1030 rc = rwm_rw_config( be, fname, lineno, argc, argv );
1032 } else if ( strcasecmp( argv[0], "map" ) == 0 ) {
1033 rc = rwm_m_config( be, fname, lineno, argc, argv );
1035 } else if ( strcasecmp( argv[0], "suffixmassage" ) == 0 ) {
1036 rc = rwm_suffixmassage_config( be, fname, lineno, argc, argv );
1039 rc = SLAP_CONF_UNKNOWN;
1054 slap_overinst *on = (slap_overinst *) be->bd_info;
1055 struct ldapmapping *mapping = NULL;
1056 struct ldaprwmap *rwmap;
1058 rwmap = (struct ldaprwmap *)ch_malloc(sizeof(struct ldaprwmap));
1059 memset(rwmap, 0, sizeof(struct ldaprwmap));
1061 #ifdef ENABLE_REWRITE
1062 rwmap->rwm_rw = rewrite_info_init( REWRITE_MODE_USE_DEFAULT );
1063 if ( rwmap->rwm_rw == NULL ) {
1071 /* this rewriteContext by default must be null;
1072 * rules can be added if required */
1073 rargv[ 0 ] = "rewriteContext";
1074 rargv[ 1 ] = "searchFilter";
1076 rewrite_parse( rwmap->rwm_rw, "<suffix massage>", 1, 2, rargv );
1078 rargv[ 0 ] = "rewriteContext";
1079 rargv[ 1 ] = "default";
1081 rewrite_parse( rwmap->rwm_rw, "<suffix massage>", 2, 2, rargv );
1084 #endif /* ENABLE_REWRITE */
1086 if ( rwm_map_init( &rwmap->rwm_oc, &mapping ) != LDAP_SUCCESS ||
1087 rwm_map_init( &rwmap->rwm_at, &mapping ) != LDAP_SUCCESS )
1092 on->on_bi.bi_private = (void *)rwmap;
1102 slap_overinst *on = (slap_overinst *) be->bd_info;
1105 if ( on->on_bi.bi_private ) {
1106 struct ldaprwmap *rwmap =
1107 (struct ldaprwmap *)on->on_bi.bi_private;
1109 #ifdef ENABLE_REWRITE
1110 if (rwmap->rwm_rw) {
1111 rewrite_info_delete( &rwmap->rwm_rw );
1113 #else /* !ENABLE_REWRITE */
1114 if ( rwmap->rwm_suffix_massage ) {
1115 ber_bvarray_free( rwmap->rwm_suffix_massage );
1117 #endif /* !ENABLE_REWRITE */
1119 avl_free( rwmap->rwm_oc.remap, NULL );
1120 avl_free( rwmap->rwm_oc.map, rwm_mapping_free );
1121 avl_free( rwmap->rwm_at.remap, NULL );
1122 avl_free( rwmap->rwm_at.map, rwm_mapping_free );
1128 static slap_overinst rwm = { { NULL } };
1133 memset( &rwm, 0, sizeof(slap_overinst) );
1135 rwm.on_bi.bi_type = "rwm";
1136 rwm.on_bi.bi_db_init = rwm_over_init;
1137 rwm.on_bi.bi_db_config = rwm_config;
1138 rwm.on_bi.bi_db_destroy = rwm_destroy;
1140 rwm.on_bi.bi_op_bind = rwm_bind;
1141 rwm.on_bi.bi_op_search = rwm_search;
1142 rwm.on_bi.bi_op_compare = rwm_compare;
1143 rwm.on_bi.bi_op_modify = rwm_modify;
1144 rwm.on_bi.bi_op_modrdn = rwm_modrdn;
1145 rwm.on_bi.bi_op_add = rwm_add;
1146 rwm.on_bi.bi_op_delete = rwm_delete;
1147 rwm.on_bi.bi_op_unbind = rwm_unbind;
1148 rwm.on_bi.bi_extended = rwm_extended;
1150 rwm.on_response = rwm_response;
1152 return overlay_register( &rwm );
1155 #if SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC
1156 int init_module(int argc, char *argv[]) {
1161 #endif /* SLAPD_OVER_RWM */