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>
31 typedef struct rwm_op_state {
37 AttributeName *mapped_attrs;
42 rwm_db_destroy( BackendDB *be, ConfigArgs *ca );
44 typedef struct rwm_op_cb {
50 rwm_op_cleanup( Operation *op, SlapReply *rs )
52 slap_callback *cb = op->o_callback;
53 rwm_op_state *ros = cb->sc_private;
55 if ( rs->sr_type == REP_RESULT || rs->sr_type == REP_EXTENDED ||
56 op->o_abandon || rs->sr_err == SLAPD_ABANDON ) {
58 op->o_req_dn = ros->ro_dn;
59 op->o_req_ndn = ros->ro_ndn;
61 if ( !BER_BVISNULL( &ros->r_dn )
62 && ros->r_dn.bv_val != ros->r_ndn.bv_val )
64 ch_free( ros->r_dn.bv_val );
65 BER_BVZERO( &ros->r_dn );
68 if ( !BER_BVISNULL( &ros->r_ndn ) ) {
69 ch_free( ros->r_ndn.bv_val );
70 BER_BVZERO( &ros->r_ndn );
73 switch( ros->r_tag ) {
74 case LDAP_REQ_COMPARE:
75 if ( op->orc_ava->aa_value.bv_val != ros->orc_ava->aa_value.bv_val )
76 op->o_tmpfree( op->orc_ava->aa_value.bv_val, op->o_tmpmemctx );
77 op->orc_ava = ros->orc_ava;
80 slap_mods_free( op->orm_modlist, 1 );
81 op->orm_modlist = ros->orm_modlist;
84 if ( op->orr_newSup != ros->orr_newSup ) {
85 ch_free( op->orr_newSup->bv_val );
86 ch_free( op->orr_nnewSup->bv_val );
87 op->o_tmpfree( op->orr_newSup, op->o_tmpmemctx );
88 op->o_tmpfree( op->orr_nnewSup, op->o_tmpmemctx );
89 op->orr_newSup = ros->orr_newSup;
90 op->orr_nnewSup = ros->orr_nnewSup;
94 ch_free( ros->mapped_attrs );
95 filter_free_x( op, op->ors_filter );
96 ch_free( op->ors_filterstr.bv_val );
97 op->ors_attrs = ros->ors_attrs;
98 op->ors_filter = ros->ors_filter;
99 op->ors_filterstr = ros->ors_filterstr;
101 case LDAP_REQ_EXTENDED:
102 if ( op->ore_reqdata != ros->ore_reqdata ) {
103 ber_bvfree( op->ore_reqdata );
104 op->ore_reqdata = ros->ore_reqdata;
109 op->o_callback = op->o_callback->sc_next;
110 op->o_tmpfree( cb, op->o_tmpmemctx );
113 return SLAP_CB_CONTINUE;
117 rwm_callback_get( Operation *op, SlapReply *rs )
119 rwm_op_cb *roc = NULL;
121 roc = op->o_tmpalloc( sizeof( struct rwm_op_cb ), op->o_tmpmemctx );
122 roc->cb.sc_cleanup = rwm_op_cleanup;
123 roc->cb.sc_response = NULL;
124 roc->cb.sc_next = op->o_callback;
125 roc->cb.sc_private = &roc->ros;
126 roc->ros.r_tag = op->o_tag;
127 roc->ros.ro_dn = op->o_req_dn;
128 roc->ros.ro_ndn = op->o_req_ndn;
129 roc->ros.o_request = op->o_request;
130 BER_BVZERO( &roc->ros.r_dn );
131 BER_BVZERO( &roc->ros.r_ndn );
138 rwm_op_dn_massage( Operation *op, SlapReply *rs, void *cookie,
141 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
142 struct ldaprwmap *rwmap =
143 (struct ldaprwmap *)on->on_bi.bi_private;
145 struct berval dn = BER_BVNULL,
151 * Rewrite the dn if needed
154 dc.conn = op->o_conn;
156 dc.ctx = (char *)cookie;
158 /* NOTE: in those cases where only the ndn is available,
159 * and the caller sets op->o_req_dn = op->o_req_ndn,
160 * only rewrite the op->o_req_ndn and use it as
161 * op->o_req_dn as well */
163 if ( op->o_req_dn.bv_val != op->o_req_ndn.bv_val ) {
165 rc = rwm_dn_massage_pretty_normalize( &dc, &op->o_req_dn, &dn, &ndn );
167 rc = rwm_dn_massage_normalize( &dc, &op->o_req_ndn, &ndn );
170 if ( rc != LDAP_SUCCESS ) {
174 if ( ( op->o_req_dn.bv_val != op->o_req_ndn.bv_val && dn.bv_val == op->o_req_dn.bv_val )
175 || ndn.bv_val == op->o_req_ndn.bv_val )
180 if ( op->o_req_dn.bv_val != op->o_req_ndn.bv_val ) {
193 rwm_op_add( Operation *op, SlapReply *rs )
195 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
196 struct ldaprwmap *rwmap =
197 (struct ldaprwmap *)on->on_bi.bi_private;
201 Attribute **ap = NULL;
202 char *olddn = op->o_req_dn.bv_val;
205 rwm_op_cb *roc = rwm_callback_get( op, rs );
207 rc = rwm_op_dn_massage( op, rs, "addDN", &roc->ros );
208 if ( rc != LDAP_SUCCESS ) {
209 op->o_bd->bd_info = (BackendInfo *)on->on_info;
210 send_ldap_error( op, rs, rc, "addDN massage error" );
214 if ( olddn != op->o_req_dn.bv_val ) {
215 ber_bvreplace( &op->ora_e->e_name, &op->o_req_dn );
216 ber_bvreplace( &op->ora_e->e_nname, &op->o_req_ndn );
219 /* Count number of attributes in entry */
220 isupdate = be_shadow_update( op );
221 for ( i = 0, ap = &op->oq_add.rs_e->e_attrs; *ap; ) {
224 if ( (*ap)->a_desc == slap_schema.si_ad_objectClass ||
225 (*ap)->a_desc == slap_schema.si_ad_structuralObjectClass )
229 for ( last = 0; !BER_BVISNULL( &(*ap)->a_vals[ last ] ); last++ )
232 for ( j = 0; !BER_BVISNULL( &(*ap)->a_vals[ j ] ); j++ ) {
233 struct ldapmapping *mapping = NULL;
235 ( void )rwm_mapping( &rwmap->rwm_oc, &(*ap)->a_vals[ j ],
237 if ( mapping == NULL ) {
238 if ( rwmap->rwm_at.drop_missing ) {
239 /* FIXME: we allow to remove objectClasses as well;
240 * if the resulting entry is inconsistent, that's
241 * the relayed database's business...
243 ch_free( (*ap)->a_vals[ j ].bv_val );
245 (*ap)->a_vals[ j ] = (*ap)->a_vals[ last ];
247 BER_BVZERO( &(*ap)->a_vals[ last ] );
253 ch_free( (*ap)->a_vals[ j ].bv_val );
254 ber_dupbv( &(*ap)->a_vals[ j ], &mapping->m_dst );
258 } else if ( !isupdate && !get_relax( op ) && (*ap)->a_desc->ad_type->sat_no_user_mod )
263 struct ldapmapping *mapping = NULL;
265 ( void )rwm_mapping( &rwmap->rwm_at, &(*ap)->a_desc->ad_cname,
267 if ( mapping == NULL ) {
268 if ( rwmap->rwm_at.drop_missing ) {
273 if ( (*ap)->a_desc->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName
274 || ( mapping != NULL && mapping->m_dst_ad->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName ) )
277 * FIXME: rewrite could fail; in this case
278 * the operation should give up, right?
280 rc = rwm_dnattr_rewrite( op, rs, "addAttrDN",
282 (*ap)->a_nvals ? &(*ap)->a_nvals : NULL );
287 } else if ( (*ap)->a_desc == slap_schema.si_ad_ref ) {
288 rc = rwm_referral_rewrite( op, rs, "referralAttrDN",
290 (*ap)->a_nvals ? &(*ap)->a_nvals : NULL );
291 if ( rc != LDAP_SUCCESS ) {
296 if ( mapping != NULL ) {
297 assert( mapping->m_dst_ad != NULL );
298 (*ap)->a_desc = mapping->m_dst_ad;
307 /* FIXME: leaking attribute/values? */
314 op->o_callback = &roc->cb;
316 return SLAP_CB_CONTINUE;
320 rwm_conn_init( BackendDB *be, Connection *conn )
322 slap_overinst *on = (slap_overinst *) be->bd_info;
323 struct ldaprwmap *rwmap =
324 (struct ldaprwmap *)on->on_bi.bi_private;
326 ( void )rewrite_session_init( rwmap->rwm_rw, conn );
328 return SLAP_CB_CONTINUE;
332 rwm_conn_destroy( BackendDB *be, Connection *conn )
334 slap_overinst *on = (slap_overinst *) be->bd_info;
335 struct ldaprwmap *rwmap =
336 (struct ldaprwmap *)on->on_bi.bi_private;
338 ( void )rewrite_session_delete( rwmap->rwm_rw, conn );
340 return SLAP_CB_CONTINUE;
344 rwm_op_bind( Operation *op, SlapReply *rs )
346 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
349 rwm_op_cb *roc = rwm_callback_get( op, rs );
351 rc = rwm_op_dn_massage( op, rs, "bindDN", &roc->ros );
352 if ( rc != LDAP_SUCCESS ) {
353 op->o_bd->bd_info = (BackendInfo *)on->on_info;
354 send_ldap_error( op, rs, rc, "bindDN massage error" );
358 op->o_callback = &roc->cb;
360 return SLAP_CB_CONTINUE;
364 rwm_op_unbind( Operation *op, SlapReply *rs )
366 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
367 struct ldaprwmap *rwmap =
368 (struct ldaprwmap *)on->on_bi.bi_private;
370 rewrite_session_delete( rwmap->rwm_rw, op->o_conn );
372 return SLAP_CB_CONTINUE;
376 rwm_op_compare( Operation *op, SlapReply *rs )
378 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
379 struct ldaprwmap *rwmap =
380 (struct ldaprwmap *)on->on_bi.bi_private;
383 struct berval mapped_vals[2] = { BER_BVNULL, BER_BVNULL };
385 rwm_op_cb *roc = rwm_callback_get( op, rs );
387 rc = rwm_op_dn_massage( op, rs, "compareDN", &roc->ros );
388 if ( rc != LDAP_SUCCESS ) {
389 op->o_bd->bd_info = (BackendInfo *)on->on_info;
390 send_ldap_error( op, rs, rc, "compareDN massage error" );
394 /* if the attribute is an objectClass, try to remap its value */
395 if ( op->orc_ava->aa_desc == slap_schema.si_ad_objectClass
396 || op->orc_ava->aa_desc == slap_schema.si_ad_structuralObjectClass )
398 rwm_map( &rwmap->rwm_oc, &op->orc_ava->aa_value,
399 &mapped_vals[0], RWM_MAP );
400 if ( BER_BVISNULL( &mapped_vals[0] ) || BER_BVISEMPTY( &mapped_vals[0] ) )
402 op->o_bd->bd_info = (BackendInfo *)on->on_info;
403 send_ldap_error( op, rs, LDAP_OTHER, "compare objectClass map error" );
406 } else if ( mapped_vals[0].bv_val != op->orc_ava->aa_value.bv_val ) {
407 ber_dupbv_x( &op->orc_ava->aa_value, &mapped_vals[0],
412 struct ldapmapping *mapping = NULL;
413 AttributeDescription *ad = op->orc_ava->aa_desc;
415 ( void )rwm_mapping( &rwmap->rwm_at, &op->orc_ava->aa_desc->ad_cname,
417 if ( mapping == NULL ) {
418 if ( rwmap->rwm_at.drop_missing ) {
419 op->o_bd->bd_info = (BackendInfo *)on->on_info;
420 send_ldap_error( op, rs, LDAP_OTHER, "compare attributeType map error" );
425 assert( mapping->m_dst_ad != NULL );
426 ad = mapping->m_dst_ad;
429 if ( op->orc_ava->aa_desc->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName
430 || ( mapping != NULL && mapping->m_dst_ad->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName ) )
432 struct berval *mapped_valsp[2];
434 mapped_valsp[0] = &mapped_vals[0];
435 mapped_valsp[1] = &mapped_vals[1];
437 mapped_vals[0] = op->orc_ava->aa_value;
439 rc = rwm_dnattr_rewrite( op, rs, "compareAttrDN", NULL, mapped_valsp );
441 if ( rc != LDAP_SUCCESS ) {
442 op->o_bd->bd_info = (BackendInfo *)on->on_info;
443 send_ldap_error( op, rs, rc, "compareAttrDN massage error" );
447 if ( mapped_vals[ 0 ].bv_val != op->orc_ava->aa_value.bv_val ) {
448 /* NOTE: if we get here, rwm_dnattr_rewrite()
449 * already freed the old value, so now
451 ber_dupbv_x( &op->orc_ava->aa_value, &mapped_vals[0],
453 ber_memfree_x( mapped_vals[ 0 ].bv_val, NULL );
456 op->orc_ava->aa_desc = ad;
459 op->o_callback = &roc->cb;
461 return SLAP_CB_CONTINUE;
465 rwm_op_delete( Operation *op, SlapReply *rs )
467 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
470 rwm_op_cb *roc = rwm_callback_get( op, rs );
472 rc = rwm_op_dn_massage( op, rs, "deleteDN", &roc->ros );
473 if ( rc != LDAP_SUCCESS ) {
474 op->o_bd->bd_info = (BackendInfo *)on->on_info;
475 send_ldap_error( op, rs, rc, "deleteDN massage error" );
479 op->o_callback = &roc->cb;
481 return SLAP_CB_CONTINUE;
485 rwm_op_modify( Operation *op, SlapReply *rs )
487 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
488 struct ldaprwmap *rwmap =
489 (struct ldaprwmap *)on->on_bi.bi_private;
495 rwm_op_cb *roc = rwm_callback_get( op, rs );
497 rc = rwm_op_dn_massage( op, rs, "modifyDN", &roc->ros );
498 if ( rc != LDAP_SUCCESS ) {
499 op->o_bd->bd_info = (BackendInfo *)on->on_info;
500 send_ldap_error( op, rs, rc, "modifyDN massage error" );
504 isupdate = be_shadow_update( op );
505 for ( mlp = &op->oq_modify.rs_modlist; *mlp; ) {
508 struct ldapmapping *mapping = NULL;
510 /* duplicate the modlist */
511 ml = ch_malloc( sizeof( Modifications ));
515 if ( ml->sml_desc == slap_schema.si_ad_objectClass
516 || ml->sml_desc == slap_schema.si_ad_structuralObjectClass )
520 } else if ( !isupdate && !get_relax( op ) && ml->sml_desc->ad_type->sat_no_user_mod )
527 drop_missing = rwm_mapping( &rwmap->rwm_at,
528 &ml->sml_desc->ad_cname,
530 if ( drop_missing || ( mapping != NULL && BER_BVISNULL( &mapping->m_dst ) ) )
536 if ( ml->sml_values != NULL ) {
540 for ( num = 0; !BER_BVISNULL( &ml->sml_values[ num ] ); num++ )
543 bva = ch_malloc( (num+1) * sizeof( struct berval ));
544 for (i=0; i<num; i++)
545 ber_dupbv( &bva[i], &ml->sml_values[i] );
546 BER_BVZERO( &bva[i] );
547 ml->sml_values = bva;
549 if ( ml->sml_nvalues ) {
550 bva = ch_malloc( (num+1) * sizeof( struct berval ));
551 for (i=0; i<num; i++)
552 ber_dupbv( &bva[i], &ml->sml_nvalues[i] );
553 BER_BVZERO( &bva[i] );
554 ml->sml_nvalues = bva;
562 for ( j = 0; !BER_BVISNULL( &ml->sml_values[ j ] ); j++ ) {
563 struct ldapmapping *oc_mapping = NULL;
565 ( void )rwm_mapping( &rwmap->rwm_oc, &ml->sml_values[ j ],
566 &oc_mapping, RWM_MAP );
567 if ( oc_mapping == NULL ) {
568 if ( rwmap->rwm_at.drop_missing ) {
569 /* FIXME: we allow to remove objectClasses as well;
570 * if the resulting entry is inconsistent, that's
571 * the relayed database's business...
574 ch_free( ml->sml_values[ j ].bv_val );
575 ml->sml_values[ j ] = ml->sml_values[ last ];
577 BER_BVZERO( &ml->sml_values[ last ] );
583 ch_free( ml->sml_values[ j ].bv_val );
584 ber_dupbv( &ml->sml_values[ j ], &oc_mapping->m_dst );
589 if ( ml->sml_desc->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName
590 || ( mapping != NULL && mapping->m_dst_ad->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName ) )
592 rc = rwm_dnattr_rewrite( op, rs, "modifyAttrDN",
594 ml->sml_nvalues ? &ml->sml_nvalues : NULL );
596 } else if ( ml->sml_desc == slap_schema.si_ad_ref ) {
597 rc = rwm_referral_rewrite( op, rs,
600 ml->sml_nvalues ? &ml->sml_nvalues : NULL );
601 if ( rc != LDAP_SUCCESS ) {
606 if ( rc != LDAP_SUCCESS ) {
613 if ( mapping != NULL ) {
614 /* use new attribute description */
615 assert( mapping->m_dst_ad != NULL );
616 ml->sml_desc = mapping->m_dst_ad;
624 *mlp = (*mlp)->sml_next;
625 slap_mod_free( &ml->sml_mod, 0 );
629 op->o_callback = &roc->cb;
631 return SLAP_CB_CONTINUE;
635 rwm_op_modrdn( 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 rwm_op_cb *roc = rwm_callback_get( op, rs );
645 if ( op->orr_newSup ) {
647 struct berval nnewSup = BER_BVNULL;
648 struct berval newSup = BER_BVNULL;
651 * Rewrite the new superior, if defined and required
654 dc.conn = op->o_conn;
656 dc.ctx = "newSuperiorDN";
657 newSup = *op->orr_newSup;
658 nnewSup = *op->orr_nnewSup;
659 rc = rwm_dn_massage_pretty_normalize( &dc, op->orr_newSup, &newSup, &nnewSup );
660 if ( rc != LDAP_SUCCESS ) {
661 op->o_bd->bd_info = (BackendInfo *)on->on_info;
662 send_ldap_error( op, rs, rc, "newSuperiorDN massage error" );
666 if ( op->orr_newSup->bv_val != newSup.bv_val ) {
667 op->orr_newSup = op->o_tmpalloc( sizeof( struct berval ),
669 op->orr_nnewSup = op->o_tmpalloc( sizeof( struct berval ),
671 *op->orr_newSup = newSup;
672 *op->orr_nnewSup = nnewSup;
677 * Rewrite the dn, if needed
679 rc = rwm_op_dn_massage( op, rs, "renameDN", &roc->ros );
680 if ( rc != LDAP_SUCCESS ) {
681 op->o_bd->bd_info = (BackendInfo *)on->on_info;
682 send_ldap_error( op, rs, rc, "renameDN massage error" );
683 if ( op->orr_newSup != roc->ros.orr_newSup ) {
684 ch_free( op->orr_newSup->bv_val );
685 ch_free( op->orr_nnewSup->bv_val );
686 op->o_tmpfree( op->orr_newSup, op->o_tmpmemctx );
687 op->o_tmpfree( op->orr_nnewSup, op->o_tmpmemctx );
688 op->orr_newSup = roc->ros.orr_newSup;
689 op->orr_nnewSup = roc->ros.orr_nnewSup;
694 /* TODO: rewrite newRDN, attribute types,
695 * values of DN-valued attributes ... */
697 op->o_callback = &roc->cb;
699 return SLAP_CB_CONTINUE;
704 rwm_swap_attrs( Operation *op, SlapReply *rs )
706 slap_callback *cb = op->o_callback;
707 rwm_op_state *ros = cb->sc_private;
709 rs->sr_attrs = ros->ors_attrs;
711 /* other overlays might have touched op->ors_attrs,
712 * so we restore the original version here, otherwise
713 * attribute-mapping might fail */
714 op->ors_attrs = ros->mapped_attrs;
716 return SLAP_CB_CONTINUE;
720 rwm_op_search( Operation *op, SlapReply *rs )
722 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
723 struct ldaprwmap *rwmap =
724 (struct ldaprwmap *)on->on_bi.bi_private;
729 struct berval fstr = BER_BVNULL;
732 AttributeName *an = NULL;
736 rwm_op_cb *roc = rwm_callback_get( op, rs );
738 rc = rewrite_session_var_set( rwmap->rwm_rw, op->o_conn,
739 "searchFilter", op->ors_filterstr.bv_val );
740 if ( rc == LDAP_SUCCESS )
741 rc = rwm_op_dn_massage( op, rs, "searchDN", &roc->ros );
742 if ( rc != LDAP_SUCCESS ) {
743 text = "searchDN massage error";
748 * Rewrite the dn if needed
751 dc.conn = op->o_conn;
753 dc.ctx = "searchFilterAttrDN";
755 rc = rwm_filter_map_rewrite( op, &dc, op->ors_filter, &fstr );
756 if ( rc != LDAP_SUCCESS ) {
757 text = "searchFilter/searchFilterAttrDN massage error";
761 f = str2filter_x( op, fstr.bv_val );
764 text = "massaged filter parse error";
769 op->ors_filterstr = fstr;
771 rc = rwm_map_attrnames( &rwmap->rwm_at, &rwmap->rwm_oc,
772 op->ors_attrs, &an, RWM_MAP );
773 if ( rc != LDAP_SUCCESS ) {
774 text = "attribute list mapping error";
779 /* store the mapped Attributes for later usage, in
780 * the case that other overlays change op->ors_attrs */
781 roc->ros.mapped_attrs = an;
782 roc->cb.sc_response = rwm_swap_attrs;
784 op->o_callback = &roc->cb;
786 return SLAP_CB_CONTINUE;
794 filter_free_x( op, f );
797 if ( !BER_BVISNULL( &fstr ) ) {
798 ch_free( fstr.bv_val );
801 op->oq_search = roc->ros.oq_search;
803 op->o_bd->bd_info = (BackendInfo *)on->on_info;
804 send_ldap_error( op, rs, rc, text );
811 rwm_exop_passwd( Operation *op, SlapReply *rs )
813 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
817 struct berval id = BER_BVNULL,
820 BerElement *ber = NULL;
822 if ( !BER_BVISNULL( &op->o_req_ndn ) ) {
826 if ( !SLAP_ISGLOBALOVERLAY( op->o_bd ) ) {
827 rs->sr_err = LDAP_OTHER;
831 rs->sr_err = slap_passwd_parse( op->ore_reqdata, &id,
832 &pwold, &pwnew, &rs->sr_text );
833 if ( rs->sr_err != LDAP_SUCCESS ) {
837 if ( !BER_BVISNULL( &id ) ) {
838 rs->sr_err = dnPrettyNormal( NULL, &id, &op->o_req_dn,
839 &op->o_req_ndn, op->o_tmpmemctx );
840 if ( rs->sr_err != LDAP_SUCCESS ) {
841 rs->sr_text = "Invalid DN";
846 ber_dupbv_x( &op->o_req_dn, &op->o_dn, op->o_tmpmemctx );
847 ber_dupbv_x( &op->o_req_ndn, &op->o_ndn, op->o_tmpmemctx );
850 roc = rwm_callback_get( op, rs );
852 rc = rwm_op_dn_massage( op, rs, "extendedDN", &roc->ros );
853 if ( rc != LDAP_SUCCESS ) {
854 op->o_bd->bd_info = (BackendInfo *)on->on_info;
855 send_ldap_error( op, rs, rc, "extendedDN massage error" );
859 ber = ber_alloc_t( LBER_USE_DER );
861 rs->sr_err = LDAP_OTHER;
862 rs->sr_text = "No memory";
865 ber_printf( ber, "{" );
866 if ( !BER_BVISNULL( &id )) {
867 ber_printf( ber, "tO", LDAP_TAG_EXOP_MODIFY_PASSWD_ID,
870 if ( !BER_BVISNULL( &pwold )) {
871 ber_printf( ber, "tO", LDAP_TAG_EXOP_MODIFY_PASSWD_OLD, &pwold );
873 if ( !BER_BVISNULL( &pwnew )) {
874 ber_printf( ber, "tO", LDAP_TAG_EXOP_MODIFY_PASSWD_NEW, &pwnew );
876 ber_printf( ber, "N}" );
877 ber_flatten( ber, &op->ore_reqdata );
880 op->o_callback = &roc->cb;
882 return SLAP_CB_CONTINUE;
887 BI_op_extended *extended;
889 { BER_BVC(LDAP_EXOP_MODIFY_PASSWD), rwm_exop_passwd },
894 rwm_extended( Operation *op, SlapReply *rs )
896 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
902 for ( i = 0; exop_table[i].extended != NULL; i++ ) {
903 if ( bvmatch( &exop_table[i].oid, &op->oq_extended.rs_reqoid ) )
905 rc = exop_table[i].extended( op, rs );
910 case SLAP_CB_CONTINUE:
915 send_ldap_result( op, rs );
922 roc = rwm_callback_get( op, rs );
924 rc = rwm_op_dn_massage( op, rs, "extendedDN", &roc->ros );
925 if ( rc != LDAP_SUCCESS ) {
926 op->o_bd->bd_info = (BackendInfo *)on->on_info;
927 send_ldap_error( op, rs, rc, "extendedDN massage error" );
931 /* TODO: rewrite/map extended data ? ... */
932 op->o_callback = &roc->cb;
934 return SLAP_CB_CONTINUE;
938 rwm_matched( Operation *op, SlapReply *rs )
940 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
941 struct ldaprwmap *rwmap =
942 (struct ldaprwmap *)on->on_bi.bi_private;
944 struct berval dn, mdn;
948 if ( rs->sr_matched == NULL ) {
949 return SLAP_CB_CONTINUE;
953 dc.conn = op->o_conn;
955 dc.ctx = "matchedDN";
956 ber_str2bv( rs->sr_matched, 0, 0, &dn );
958 rc = rwm_dn_massage_pretty( &dc, &dn, &mdn );
959 if ( rc != LDAP_SUCCESS ) {
961 rs->sr_text = "Rewrite error";
965 if ( mdn.bv_val != dn.bv_val ) {
966 if ( rs->sr_flags & REP_MATCHED_MUSTBEFREED ) {
967 ch_free( (void *)rs->sr_matched );
970 rs->sr_flags |= REP_MATCHED_MUSTBEFREED;
972 rs->sr_matched = mdn.bv_val;
975 return SLAP_CB_CONTINUE;
979 rwm_attrs( Operation *op, SlapReply *rs, Attribute** a_first, int stripEntryDN )
981 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
982 struct ldaprwmap *rwmap =
983 (struct ldaprwmap *)on->on_bi.bi_private;
991 * Rewrite the dn attrs, if needed
994 dc.conn = op->o_conn;
997 /* FIXME: the entries are in the remote mapping form;
998 * so we need to select those attributes we are willing
999 * to return, and remap them accordingly */
1001 /* FIXME: in principle, one could map an attribute
1002 * on top of another, which already exists.
1003 * As such, in the end there might exist more than
1004 * one instance of an attribute.
1005 * We should at least check if this occurs, and issue
1006 * an error (because multiple instances of attrs in
1007 * response are not valid), or merge the values (what
1008 * about duplicate values?) */
1009 isupdate = be_shadow_update( op );
1010 for ( ap = a_first; *ap; ) {
1011 struct ldapmapping *mapping = NULL;
1016 if ( SLAP_OPATTRS( rs->sr_attr_flags ) && is_at_operational( (*ap)->a_desc->ad_type ) )
1021 if ( op->ors_attrs != NULL &&
1022 !SLAP_USERATTRS( rs->sr_attr_flags ) &&
1023 !ad_inlist( (*ap)->a_desc, op->ors_attrs ) )
1028 drop_missing = rwm_mapping( &rwmap->rwm_at,
1029 &(*ap)->a_desc->ad_cname, &mapping, RWM_REMAP );
1030 if ( drop_missing || ( mapping != NULL && BER_BVISEMPTY( &mapping->m_dst ) ) )
1034 if ( mapping != NULL ) {
1035 assert( mapping->m_dst_ad != NULL );
1037 /* try to normalize mapped Attributes if the original
1038 * AttributeType was not normalized */
1039 if ((rwmap->rwm_flags & RWM_F_NORMALIZE_MAPPED_ATTRS) &&
1040 (!(*ap)->a_desc->ad_type->sat_equality ||
1041 !(*ap)->a_desc->ad_type->sat_equality->smr_normalize) &&
1042 mapping->m_dst_ad->ad_type->sat_equality &&
1043 mapping->m_dst_ad->ad_type->sat_equality->smr_normalize )
1046 for ( last = 0; !BER_BVISNULL( &(*ap)->a_vals[last] ); last++ )
1051 (*ap)->a_nvals = ch_malloc( (last+1) * sizeof(struct berval) );
1053 for ( i = 0; !BER_BVISNULL( &(*ap)->a_vals[i]); i++ ) {
1056 * check that each value is valid per syntax
1057 * and pretty if appropriate
1059 rc = mapping->m_dst_ad->ad_type->sat_equality->smr_normalize(
1060 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
1061 mapping->m_dst_ad->ad_type->sat_syntax,
1062 mapping->m_dst_ad->ad_type->sat_equality,
1063 &(*ap)->a_vals[i], &(*ap)->a_nvals[i],
1066 if ( rc != LDAP_SUCCESS ) {
1067 BER_BVZERO( &(*ap)->a_nvals[i] );
1070 BER_BVZERO( &(*ap)->a_nvals[i] );
1073 /* rewrite the attribute description */
1074 (*ap)->a_desc = mapping->m_dst_ad;
1078 if ( (*ap)->a_desc == slap_schema.si_ad_entryDN ) {
1079 if ( stripEntryDN ) {
1080 /* will be generated by frontend */
1084 } else if ( !isupdate
1086 && (*ap)->a_desc->ad_type->sat_no_user_mod
1087 && (*ap)->a_desc->ad_type != slap_schema.si_at_undefined )
1092 if ( last == -1 ) { /* not yet counted */
1093 for ( last = 0; !BER_BVISNULL( &(*ap)->a_vals[last] ); last++ )
1098 /* empty? leave it in place because of attrsonly and vlv */
1103 if ( (*ap)->a_desc == slap_schema.si_ad_objectClass
1104 || (*ap)->a_desc == slap_schema.si_ad_structuralObjectClass )
1108 for ( bv = (*ap)->a_vals; !BER_BVISNULL( bv ); bv++ ) {
1109 struct berval mapped;
1111 rwm_map( &rwmap->rwm_oc, &bv[0], &mapped, RWM_REMAP );
1112 if ( BER_BVISNULL( &mapped ) || BER_BVISEMPTY( &mapped ) ) {
1113 ch_free( bv[0].bv_val );
1114 BER_BVZERO( &bv[0] );
1115 if ( &(*ap)->a_vals[last] > &bv[0] ) {
1116 bv[0] = (*ap)->a_vals[last];
1117 BER_BVZERO( &(*ap)->a_vals[last] );
1122 } else if ( mapped.bv_val != bv[0].bv_val ) {
1124 * FIXME: after LBER_FREEing
1125 * the value is replaced by
1126 * ch_alloc'ed memory
1128 ber_bvreplace( &bv[0], &mapped );
1133 * It is necessary to try to rewrite attributes with
1134 * dn syntax because they might be used in ACLs as
1135 * members of groups; since ACLs are applied to the
1136 * rewritten stuff, no dn-based subject clause could
1137 * be used at the ldap backend side (see
1138 * http://www.OpenLDAP.org/faq/data/cache/452.html)
1139 * The problem can be overcome by moving the dn-based
1140 * ACLs to the target directory server, and letting
1141 * everything pass thru the ldap backend. */
1142 /* FIXME: handle distinguishedName-like syntaxes, like
1143 * nameAndOptionalUID */
1144 } else if ( (*ap)->a_desc->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName
1145 || ( mapping != NULL && mapping->m_src_ad->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName ) )
1147 dc.ctx = "searchAttrDN";
1148 rc = rwm_dnattr_result_rewrite( &dc, (*ap)->a_vals );
1149 if ( rc != LDAP_SUCCESS ) {
1153 } else if ( (*ap)->a_desc == slap_schema.si_ad_ref ) {
1154 dc.ctx = "searchAttrDN";
1155 rc = rwm_referral_result_rewrite( &dc, (*ap)->a_vals );
1156 if ( rc != LDAP_SUCCESS ) {
1163 ap = &(*ap)->a_next;
1168 *ap = (*ap)->a_next;
1177 rwm_send_entry( Operation *op, SlapReply *rs )
1179 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
1180 struct ldaprwmap *rwmap =
1181 (struct ldaprwmap *)on->on_bi.bi_private;
1185 struct berval dn = BER_BVNULL,
1190 assert( rs->sr_entry != NULL );
1193 * Rewrite the dn of the result, if needed
1196 dc.conn = op->o_conn;
1198 dc.ctx = "searchEntryDN";
1201 flags = rs->sr_flags;
1202 if ( !( rs->sr_flags & REP_ENTRY_MODIFIABLE ) ) {
1203 /* FIXME: all we need to duplicate are:
1206 * - attributes that are requested
1207 * - no values if attrsonly is set
1212 rc = LDAP_NO_MEMORY;
1216 flags &= ~REP_ENTRY_MUSTRELEASE;
1217 flags |= ( REP_ENTRY_MODIFIABLE | REP_ENTRY_MUSTBEFREED );
1221 * Note: this may fail if the target host(s) schema differs
1222 * from the one known to the meta, and a DN with unknown
1223 * attributes is returned.
1227 rc = rwm_dn_massage_pretty_normalize( &dc, &e->e_name, &dn, &ndn );
1228 if ( rc != LDAP_SUCCESS ) {
1233 if ( e->e_name.bv_val != dn.bv_val ) {
1234 ch_free( e->e_name.bv_val );
1235 ch_free( e->e_nname.bv_val );
1241 /* TODO: map entry attribute types, objectclasses
1242 * and dn-valued attribute values */
1244 /* FIXME: the entries are in the remote mapping form;
1245 * so we need to select those attributes we are willing
1246 * to return, and remap them accordingly */
1247 (void)rwm_attrs( op, rs, &e->e_attrs, 1 );
1249 if ( rs->sr_flags & REP_ENTRY_MUSTRELEASE ) {
1250 be_entry_release_rw( op, rs->sr_entry, 0 );
1254 rs->sr_flags = flags;
1256 return SLAP_CB_CONTINUE;
1259 if ( e != NULL && e != rs->sr_entry ) {
1260 if ( e->e_name.bv_val == dn.bv_val ) {
1261 BER_BVZERO( &e->e_name );
1264 if ( e->e_nname.bv_val == ndn.bv_val ) {
1265 BER_BVZERO( &e->e_nname );
1271 if ( !BER_BVISNULL( &dn ) ) {
1272 ch_free( dn.bv_val );
1275 if ( !BER_BVISNULL( &ndn ) ) {
1276 ch_free( ndn.bv_val );
1283 rwm_operational( Operation *op, SlapReply *rs )
1285 /* FIXME: the entries are in the remote mapping form;
1286 * so we need to select those attributes we are willing
1287 * to return, and remap them accordingly */
1288 if ( rs->sr_operational_attrs ) {
1289 rwm_attrs( op, rs, &rs->sr_operational_attrs, 1 );
1292 return SLAP_CB_CONTINUE;
1296 /* don't use this; it cannot be reverted, and leaves op->o_req_dn
1297 * rewritten for subsequent operations; fine for plain suffixmassage,
1298 * but destroys everything else */
1300 rwm_chk_referrals( Operation *op, SlapReply *rs )
1302 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
1305 rc = rwm_op_dn_massage( op, rs, "referralCheckDN" );
1306 if ( rc != LDAP_SUCCESS ) {
1307 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1308 send_ldap_error( op, rs, rc, "referralCheckDN massage error" );
1312 return SLAP_CB_CONTINUE;
1324 slap_overinst *on = (slap_overinst *) be->bd_info;
1325 struct ldaprwmap *rwmap =
1326 (struct ldaprwmap *)on->on_bi.bi_private;
1328 return rewrite_parse( rwmap->rwm_rw,
1329 fname, lineno, argc, argv );
1335 rwm_suffixmassage_config(
1342 slap_overinst *on = (slap_overinst *) be->bd_info;
1343 struct ldaprwmap *rwmap =
1344 (struct ldaprwmap *)on->on_bi.bi_private;
1346 struct berval bvnc, nvnc, pvnc, brnc, nrnc, prnc;
1353 * suffixmassage [<suffix>] <massaged suffix>
1355 * the [<suffix>] field must be defined as a valid suffix
1356 * for the current database;
1357 * the <massaged suffix> shouldn't have already been
1358 * defined as a valid suffix for the current server
1361 if ( be->be_suffix == NULL ) {
1362 fprintf( stderr, "%s: line %d: "
1363 " \"suffixMassage [<suffix>]"
1364 " <massaged suffix>\" without "
1365 "<suffix> part requires database "
1366 "suffix be defined first.\n",
1370 bvnc = be->be_suffix[ 0 ];
1373 } else if ( argc == 3 ) {
1374 ber_str2bv( argv[ 1 ], 0, 0, &bvnc );
1378 fprintf( stderr, "%s: line %d: syntax is"
1379 " \"suffixMassage [<suffix>]"
1380 " <massaged suffix>\"\n",
1385 if ( dnPrettyNormal( NULL, &bvnc, &pvnc, &nvnc, NULL ) != LDAP_SUCCESS ) {
1386 fprintf( stderr, "%s: line %d: suffix DN %s is invalid\n",
1387 fname, lineno, bvnc.bv_val );
1391 ber_str2bv( argv[ massaged ], 0, 0, &brnc );
1392 if ( dnPrettyNormal( NULL, &brnc, &prnc, &nrnc, NULL ) != LDAP_SUCCESS ) {
1393 fprintf( stderr, "%s: line %d: suffix DN %s is invalid\n",
1394 fname, lineno, brnc.bv_val );
1395 free( nvnc.bv_val );
1396 free( pvnc.bv_val );
1401 * The suffix massaging is emulated
1402 * by means of the rewrite capabilities
1404 rc = rwm_suffix_massage_config( rwmap->rwm_rw,
1405 &pvnc, &nvnc, &prnc, &nrnc );
1406 free( nvnc.bv_val );
1407 free( pvnc.bv_val );
1408 free( nrnc.bv_val );
1409 free( prnc.bv_val );
1422 slap_overinst *on = (slap_overinst *) be->bd_info;
1423 struct ldaprwmap *rwmap =
1424 (struct ldaprwmap *)on->on_bi.bi_private;
1426 /* objectclass/attribute mapping */
1427 return rwm_map_config( &rwmap->rwm_oc,
1429 fname, lineno, argc, argv );
1433 rwm_response( Operation *op, SlapReply *rs )
1435 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
1436 struct ldaprwmap *rwmap =
1437 (struct ldaprwmap *)on->on_bi.bi_private;
1441 if ( op->o_tag == LDAP_REQ_SEARCH && rs->sr_type == REP_SEARCH ) {
1442 return rwm_send_entry( op, rs );
1445 switch( op->o_tag ) {
1446 case LDAP_REQ_SEARCH:
1449 case LDAP_REQ_DELETE:
1450 case LDAP_REQ_MODRDN:
1451 case LDAP_REQ_MODIFY:
1452 case LDAP_REQ_COMPARE:
1453 case LDAP_REQ_EXTENDED:
1458 * Rewrite the dn of the referrals, if needed
1461 dc.conn = op->o_conn;
1463 dc.ctx = "referralDN";
1464 rc = rwm_referral_result_rewrite( &dc, rs->sr_ref );
1465 if ( rc != LDAP_SUCCESS ) {
1470 rc = rwm_matched( op, rs );
1474 rc = SLAP_CB_CONTINUE;
1489 slap_overinst *on = (slap_overinst *) be->bd_info;
1490 struct ldaprwmap *rwmap =
1491 (struct ldaprwmap *)on->on_bi.bi_private;
1496 if ( strncasecmp( argv[ 0 ], "rwm-", STRLENOF( "rwm-" ) ) == 0 ) {
1498 argv[ 0 ] = &argv0[ STRLENOF( "rwm-" ) ];
1501 if ( strncasecmp( argv[0], "rewrite", STRLENOF("rewrite") ) == 0 ) {
1502 rc = rwm_rw_config( be, fname, lineno, argc, argv );
1504 } else if ( strcasecmp( argv[0], "map" ) == 0 ) {
1505 rc = rwm_m_config( be, fname, lineno, argc, argv );
1507 } else if ( strcasecmp( argv[0], "suffixmassage" ) == 0 ) {
1508 rc = rwm_suffixmassage_config( be, fname, lineno, argc, argv );
1510 } else if ( strcasecmp( argv[0], "t-f-support" ) == 0 ) {
1513 "%s: line %d: \"t-f-support {no|yes|discover}\" needs 1 argument.\n",
1518 if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
1519 rwmap->rwm_flags &= ~(RWM_F_SUPPORT_T_F_MASK2);
1521 } else if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
1522 rwmap->rwm_flags |= RWM_F_SUPPORT_T_F;
1524 /* TODO: not implemented yet */
1525 } else if ( strcasecmp( argv[ 1 ], "discover" ) == 0 ) {
1527 "%s: line %d: \"discover\" not supported yet "
1528 "in \"t-f-support {no|yes|discover}\".\n",
1532 rwmap->rwm_flags |= RWM_F_SUPPORT_T_F_DISCOVER;
1537 "%s: line %d: unknown value \"%s\" for \"t-f-support {no|yes|discover}\".\n",
1538 fname, lineno, argv[ 1 ] );
1541 } else if ( strcasecmp( argv[0], "normalize-mapped-attrs" ) == 0 ) {
1544 "%s: line %d: \"normalize-mapped-attrs {no|yes}\" needs 1 argument.\n",
1549 if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
1550 rwmap->rwm_flags &= ~(RWM_F_NORMALIZE_MAPPED_ATTRS);
1552 } else if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
1553 rwmap->rwm_flags |= RWM_F_NORMALIZE_MAPPED_ATTRS;
1557 rc = SLAP_CONF_UNKNOWN;
1568 * dynamic configuration...
1574 RWM_CF_SUFFIXMASSAGE,
1579 RWM_CF_NORMALIZE_MAPPED,
1584 static slap_verbmasks t_f_mode[] = {
1585 { BER_BVC( "yes" ), RWM_F_SUPPORT_T_F },
1586 { BER_BVC( "discover" ), RWM_F_SUPPORT_T_F_DISCOVER },
1587 { BER_BVC( "no" ), RWM_F_NONE },
1591 static ConfigDriver rwm_cf_gen;
1593 static ConfigTable rwmcfg[] = {
1594 { "rwm-rewrite", "rewrite",
1595 2, 0, STRLENOF("rwm-rewrite"),
1596 ARG_MAGIC|ARG_QUOTE|RWM_CF_REWRITE, rwm_cf_gen,
1597 "( OLcfgOvAt:16.1 NAME 'olcRwmRewrite' "
1598 "DESC 'Rewrites strings' "
1599 "EQUALITY caseIgnoreMatch "
1600 "SYNTAX OMsDirectoryString "
1601 "X-ORDERED 'VALUES' )",
1604 { "rwm-suffixmassage", "[virtual]> <real",
1605 2, 3, 0, ARG_MAGIC|RWM_CF_SUFFIXMASSAGE, rwm_cf_gen,
1608 { "rwm-t-f-support", "true|false|discover",
1609 2, 2, 0, ARG_MAGIC|RWM_CF_T_F_SUPPORT, rwm_cf_gen,
1610 "( OLcfgOvAt:16.2 NAME 'olcRwmTFSupport' "
1611 "DESC 'Absolute filters support' "
1612 "SYNTAX OMsDirectoryString "
1616 { "rwm-map", "{objectClass|attribute}",
1617 2, 4, 0, ARG_MAGIC|RWM_CF_MAP, rwm_cf_gen,
1618 "( OLcfgOvAt:16.3 NAME 'olcRwmMap' "
1619 "DESC 'maps attributes/objectClasses' "
1620 "SYNTAX OMsDirectoryString "
1621 "X-ORDERED 'VALUES' )",
1624 { "rwm-normalize-mapped-attrs", "true|false",
1625 2, 2, 0, ARG_MAGIC|ARG_ON_OFF|RWM_CF_NORMALIZE_MAPPED, rwm_cf_gen,
1626 "( OLcfgOvAt:16.4 NAME 'olcRwmNormalizeMapped' "
1627 "DESC 'Normalize mapped attributes/objectClasses' "
1628 "SYNTAX OMsBoolean "
1632 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
1635 static ConfigOCs rwmocs[] = {
1636 { "( OLcfgOvOc:16.1 "
1637 "NAME 'olcRwmConfig' "
1638 "DESC 'Rewrite/remap configuration' "
1639 "SUP olcOverlayConfig "
1642 "olcRwmTFSupport $ "
1644 "olcRwmNormalizeMapped "
1646 Cft_Overlay, rwmcfg, NULL, NULL },
1651 slap_rewrite_unparse( BerVarray in, BerVarray *out )
1654 BerVarray bva = NULL;
1655 char ibuf[32], *ptr;
1658 assert( in != NULL );
1660 for ( i = 0; !BER_BVISNULL( &in[i] ); i++ )
1669 bva = ch_malloc( ( i + 1 ) * sizeof(struct berval) );
1670 BER_BVZERO( &bva[ 0 ] );
1672 for ( i = 0; !BER_BVISNULL( &in[i] ); i++ ) {
1673 idx.bv_len = snprintf( idx.bv_val, sizeof( ibuf ), "{%d}", i );
1674 if ( idx.bv_len >= sizeof( ibuf ) ) {
1675 ber_bvarray_free( bva );
1679 bva[i].bv_len = idx.bv_len + in[i].bv_len;
1680 bva[i].bv_val = ch_malloc( bva[i].bv_len + 1 );
1681 ptr = lutil_strcopy( bva[i].bv_val, ibuf );
1682 ptr = lutil_strcopy( ptr, in[i].bv_val );
1684 BER_BVZERO( &bva[ i + 1 ] );
1691 rwm_cf_gen( ConfigArgs *c )
1693 slap_overinst *on = (slap_overinst *)c->bi;
1694 struct ldaprwmap *rwmap =
1695 (struct ldaprwmap *)on->on_bi.bi_private;
1704 if ( c->op == SLAP_CONFIG_EMIT ) {
1705 struct berval bv = BER_BVNULL;
1707 switch ( c->type ) {
1708 case RWM_CF_REWRITE:
1709 slap_rewrite_unparse( rwmap->rwm_bva_rewrite, &c->rvalue_vals );
1710 if ( !c->rvalue_vals ) rc = 1;
1713 case RWM_CF_T_F_SUPPORT:
1714 enum_to_verb( t_f_mode, (rwmap->rwm_flags & RWM_F_SUPPORT_T_F_MASK2), &bv );
1715 if ( BER_BVISNULL( &bv ) ) {
1716 /* there's something wrong... */
1721 value_add_one( &c->rvalue_vals, &bv );
1726 if ( rwmap->rwm_bva_map == NULL ) {
1730 value_add( &c->rvalue_vals, rwmap->rwm_bva_map );
1734 case RWM_CF_NORMALIZE_MAPPED:
1735 c->value_int = ( rwmap->rwm_flags & RWM_F_NORMALIZE_MAPPED_ATTRS );
1745 } else if ( c->op == LDAP_MOD_DELETE ) {
1746 switch ( c->type ) {
1747 case RWM_CF_REWRITE:
1748 if ( c->valx >= 0 ) {
1749 /* single modification is not allowed */
1753 rewrite_info_delete( &rwmap->rwm_rw );
1755 ber_bvarray_free( rwmap->rwm_bva_rewrite );
1756 rwmap->rwm_bva_rewrite = NULL;
1760 case RWM_CF_T_F_SUPPORT:
1761 rwmap->rwm_flags &= ~RWM_F_SUPPORT_T_F_MASK2;
1765 if ( c->valx >= 0 ) {
1766 /* single modification is not allowed */
1770 avl_free( rwmap->rwm_oc.remap, rwm_mapping_dst_free );
1771 avl_free( rwmap->rwm_oc.map, rwm_mapping_free );
1772 avl_free( rwmap->rwm_at.remap, rwm_mapping_dst_free );
1773 avl_free( rwmap->rwm_at.map, rwm_mapping_free );
1775 rwmap->rwm_oc.remap = NULL;
1776 rwmap->rwm_oc.map = NULL;
1777 rwmap->rwm_at.remap = NULL;
1778 rwmap->rwm_at.map = NULL;
1780 ber_bvarray_free( rwmap->rwm_bva_map );
1781 rwmap->rwm_bva_map = NULL;
1785 case RWM_CF_NORMALIZE_MAPPED:
1786 rwmap->rwm_flags &= ~RWM_F_NORMALIZE_MAPPED_ATTRS;
1795 switch ( c->type ) {
1796 case RWM_CF_REWRITE:
1797 argv0 = c->argv[ 0 ];
1798 c->argv[ 0 ] += STRLENOF( "rwm-" );
1799 rc = rwm_rw_config( &db, c->fname, c->lineno, c->argc, c->argv );
1800 c->argv[ 0 ] = argv0;
1808 line = ldap_charray2str( c->argv, "\" \"" );
1809 if ( line != NULL ) {
1810 int len = strlen( c->argv[ 0 ] );
1812 ber_str2bv( line, 0, 0, &bv );
1813 AC_MEMCPY( &bv.bv_val[ len ], &bv.bv_val[ len + 1 ],
1814 bv.bv_len - ( len + 1 ) );
1815 bv.bv_val[ bv.bv_len - 1 ] = '"';
1816 ber_bvarray_add( &rwmap->rwm_bva_rewrite, &bv );
1821 case RWM_CF_SUFFIXMASSAGE:
1822 argv0 = c->argv[ 0 ];
1823 c->argv[ 0 ] += STRLENOF( "rwm-" );
1824 rc = rwm_suffixmassage_config( &db, c->fname, c->lineno, c->argc, c->argv );
1825 c->argv[ 0 ] = argv0;
1833 /* FIXME: not optimal; in fact, this keeps track
1834 * of the fact that a set of rules was added
1835 * using the rwm-suffixmassage shortcut, but the
1836 * rules are not clarified */
1838 line = ldap_charray2str( c->argv, "\" \"" );
1839 if ( line != NULL ) {
1840 int len = strlen( c->argv[ 0 ] );
1842 ber_str2bv( line, 0, 0, &bv );
1843 AC_MEMCPY( &bv.bv_val[ len ], &bv.bv_val[ len + 1 ],
1844 bv.bv_len - ( len + 1 ) );
1845 bv.bv_val[ bv.bv_len - 1 ] = '"';
1846 ber_bvarray_add( &rwmap->rwm_bva_rewrite, &bv );
1851 case RWM_CF_T_F_SUPPORT:
1852 rc = verb_to_mask( c->argv[ 1 ], t_f_mode );
1853 if ( BER_BVISNULL( &t_f_mode[ rc ].word ) ) {
1857 rwmap->rwm_flags &= ~RWM_F_SUPPORT_T_F_MASK2;
1858 rwmap->rwm_flags |= t_f_mode[ rc ].mask;
1863 argv0 = c->argv[ 0 ];
1864 c->argv[ 0 ] += STRLENOF( "rwm-" );
1865 rc = rwm_m_config( &db, c->fname, c->lineno, c->argc, c->argv );
1866 c->argv[ 0 ] = argv0;
1874 line = ldap_charray2str( &c->argv[ 1 ], " " );
1875 if ( line != NULL ) {
1876 ber_str2bv( line, 0, 0, &bv );
1877 ber_bvarray_add( &rwmap->rwm_bva_map, &bv );
1882 case RWM_CF_NORMALIZE_MAPPED:
1883 if ( c->value_int ) {
1884 rwmap->rwm_flags |= RWM_F_NORMALIZE_MAPPED_ATTRS;
1886 rwmap->rwm_flags &= ~RWM_F_NORMALIZE_MAPPED_ATTRS;
1909 slap_overinst *on = (slap_overinst *) be->bd_info;
1910 struct ldaprwmap *rwmap;
1914 rwmap = (struct ldaprwmap *)ch_calloc( 1, sizeof( struct ldaprwmap ) );
1916 rwmap->rwm_rw = rewrite_info_init( REWRITE_MODE_USE_DEFAULT );
1917 if ( rwmap->rwm_rw == NULL ) {
1922 /* this rewriteContext by default must be null;
1923 * rules can be added if required */
1924 rargv[ 0 ] = "rewriteContext";
1925 rargv[ 1 ] = "searchFilter";
1927 rewrite_parse( rwmap->rwm_rw, "<suffix massage>", 1, 2, rargv );
1929 rargv[ 0 ] = "rewriteContext";
1930 rargv[ 1 ] = "default";
1932 rewrite_parse( rwmap->rwm_rw, "<suffix massage>", 2, 2, rargv );
1935 on->on_bi.bi_private = (void *)rwmap;
1938 (void)rwm_db_destroy( be, NULL );
1949 slap_overinst *on = (slap_overinst *) be->bd_info;
1952 if ( on->on_bi.bi_private ) {
1953 struct ldaprwmap *rwmap =
1954 (struct ldaprwmap *)on->on_bi.bi_private;
1956 if ( rwmap->rwm_rw ) {
1957 rewrite_info_delete( &rwmap->rwm_rw );
1958 ber_bvarray_free( rwmap->rwm_bva_rewrite );
1961 avl_free( rwmap->rwm_oc.remap, rwm_mapping_dst_free );
1962 avl_free( rwmap->rwm_oc.map, rwm_mapping_free );
1963 avl_free( rwmap->rwm_at.remap, rwm_mapping_dst_free );
1964 avl_free( rwmap->rwm_at.map, rwm_mapping_free );
1965 ber_bvarray_free( rwmap->rwm_bva_map );
1973 static slap_overinst rwm = { { NULL } };
1975 #if SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC
1977 #endif /* SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC */
1979 rwm_initialize( void )
1983 /* Make sure we don't exceed the bits reserved for userland */
1984 config_check_userland( RWM_CF_LAST );
1986 memset( &rwm, 0, sizeof( slap_overinst ) );
1988 rwm.on_bi.bi_type = "rwm";
1989 rwm.on_bi.bi_flags =
1990 SLAPO_BFLAG_SINGLE |
1993 rwm.on_bi.bi_db_init = rwm_db_init;
1994 rwm.on_bi.bi_db_config = rwm_db_config;
1995 rwm.on_bi.bi_db_destroy = rwm_db_destroy;
1997 rwm.on_bi.bi_op_bind = rwm_op_bind;
1998 rwm.on_bi.bi_op_search = rwm_op_search;
1999 rwm.on_bi.bi_op_compare = rwm_op_compare;
2000 rwm.on_bi.bi_op_modify = rwm_op_modify;
2001 rwm.on_bi.bi_op_modrdn = rwm_op_modrdn;
2002 rwm.on_bi.bi_op_add = rwm_op_add;
2003 rwm.on_bi.bi_op_delete = rwm_op_delete;
2004 rwm.on_bi.bi_op_unbind = rwm_op_unbind;
2005 rwm.on_bi.bi_extended = rwm_extended;
2007 rwm.on_bi.bi_operational = rwm_operational;
2008 rwm.on_bi.bi_chk_referrals = 0 /* rwm_chk_referrals */ ;
2010 rwm.on_bi.bi_connection_init = rwm_conn_init;
2011 rwm.on_bi.bi_connection_destroy = rwm_conn_destroy;
2013 rwm.on_response = rwm_response;
2015 rwm.on_bi.bi_cf_ocs = rwmocs;
2017 rc = config_register_schema( rwmcfg, rwmocs );
2022 return overlay_register( &rwm );
2025 #if SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC
2027 init_module( int argc, char *argv[] )
2029 return rwm_initialize();
2031 #endif /* SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC */
2033 #endif /* SLAPD_OVER_RWM */