1 /* dynlist.c - dynamic list overlay */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2003-2010 The OpenLDAP Foundation.
6 * Portions Copyright 2004-2005 Pierangelo Masarati.
7 * Portions Copyright 2008 Emmanuel Dreyfus.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted only as authorized by the OpenLDAP
14 * A copy of this license is available in the file LICENSE in the
15 * top-level directory of the distribution or, alternatively, at
16 * <http://www.OpenLDAP.org/license.html>.
19 * This work was initially developed by Pierangelo Masarati
20 * for SysNet s.n.c., for inclusion in OpenLDAP Software.
25 #ifdef SLAPD_OVER_DYNLIST
27 #if LDAP_VENDOR_VERSION_MINOR == X || LDAP_VENDOR_VERSION_MINOR > 3
28 #if SLAPD_OVER_DYNGROUP != SLAPD_MOD_STATIC
29 #define TAKEOVER_DYNGROUP
32 #if LDAP_VENDOR_VERSION_MINOR < 3
39 #include <ac/string.h>
47 /* FIXME: the code differs if SLAP_OPATTRS is defined or not;
48 * SLAP_OPATTRS is not defined in 2.2 yet, while this overlay
49 * expects HEAD code at least later than August 6, 2004. */
50 /* FIXME: slap_anlist_no_attrs was introduced in 2.3; here it
51 * is anticipated to allow using this overlay with 2.2. */
54 static AttributeName anlist_no_attrs[] = {
55 { BER_BVC( LDAP_NO_ATTRS ), NULL, 0, NULL },
56 { BER_BVNULL, NULL, 0, NULL }
59 static AttributeName *slap_anlist_no_attrs = anlist_no_attrs;
62 static AttributeDescription *ad_dgIdentity, *ad_dgAuthz;
64 typedef struct dynlist_map_t {
65 AttributeDescription *dlm_member_ad;
66 AttributeDescription *dlm_mapped_ad;
67 struct dynlist_map_t *dlm_next;
70 typedef struct dynlist_info_t {
72 AttributeDescription *dli_ad;
73 struct dynlist_map_t *dli_dlm;
74 struct berval dli_uri;
76 struct berval dli_uri_nbase;
77 Filter *dli_uri_filter;
78 struct berval dli_default_filter;
79 struct dynlist_info_t *dli_next;
82 #define DYNLIST_USAGE \
83 "\"dynlist-attrset <oc> [uri] <URL-ad> [[<mapped-ad>:]<member-ad> ...]\": "
85 static dynlist_info_t *
86 dynlist_is_dynlist_next( Operation *op, SlapReply *rs, dynlist_info_t *old_dli )
88 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
93 if ( old_dli == NULL ) {
94 dli = (dynlist_info_t *)on->on_bi.bi_private;
97 dli = old_dli->dli_next;
100 a = attrs_find( rs->sr_entry->e_attrs, slap_schema.si_ad_objectClass );
102 /* FIXME: objectClass must be present; for non-storage
103 * backends, like back-ldap, it needs to be added
104 * to the requested attributes */
108 for ( ; dli; dli = dli->dli_next ) {
109 if ( dli->dli_lud != NULL ) {
110 /* check base and scope */
111 if ( !BER_BVISNULL( &dli->dli_uri_nbase )
112 && !dnIsSuffixScope( &rs->sr_entry->e_nname,
114 dli->dli_lud->lud_scope ) )
120 if ( dli->dli_uri_filter && test_filter( op, rs->sr_entry, dli->dli_uri_filter ) != LDAP_COMPARE_TRUE ) {
125 if ( attr_valfind( a,
126 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
127 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
128 &dli->dli_oc->soc_cname, NULL,
129 op->o_tmpmemctx ) == 0 )
139 dynlist_make_filter( Operation *op, Entry *e, const char *url, struct berval *oldf, struct berval *newf )
141 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
142 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private;
145 int needBrackets = 0;
147 assert( oldf != NULL );
148 assert( newf != NULL );
149 assert( !BER_BVISNULL( oldf ) );
150 assert( !BER_BVISEMPTY( oldf ) );
152 if ( oldf->bv_val[0] != '(' ) {
153 Debug( LDAP_DEBUG_ANY, "%s: dynlist, DN=\"%s\": missing brackets in URI=\"%s\" filter\n",
154 op->o_log_prefix, e->e_name.bv_val, url );
158 newf->bv_len = STRLENOF( "(&(!(objectClass=" "))" ")" )
159 + dli->dli_oc->soc_cname.bv_len + oldf->bv_len + needBrackets;
160 newf->bv_val = op->o_tmpalloc( newf->bv_len + 1, op->o_tmpmemctx );
161 if ( newf->bv_val == NULL ) {
164 ptr = lutil_strcopy( newf->bv_val, "(&(!(objectClass=" );
165 ptr = lutil_strcopy( ptr, dli->dli_oc->soc_cname.bv_val );
166 ptr = lutil_strcopy( ptr, "))" );
167 if ( needBrackets ) *ptr++ = '(';
168 ptr = lutil_strcopy( ptr, oldf->bv_val );
169 if ( needBrackets ) *ptr++ = ')';
170 ptr = lutil_strcopy( ptr, ")" );
171 newf->bv_len = ptr - newf->bv_val;
176 typedef struct dynlist_sc_t {
177 dynlist_info_t *dlc_dli;
182 dynlist_sc_update( Operation *op, SlapReply *rs )
188 AccessControlState acl_state = ACL_STATE_INIT;
193 if ( rs->sr_type != REP_SEARCH ) {
197 dlc = (dynlist_sc_t *)op->o_callback->sc_private;
201 assert( rs->sr_entry != NULL );
203 /* test access to entry */
204 if ( !access_allowed( op, rs->sr_entry, slap_schema.si_ad_entry,
205 NULL, ACL_READ, NULL ) )
210 /* if there is only one member_ad, and it's not mapped,
211 * consider it as old-style member listing */
212 dlm = dlc->dlc_dli->dli_dlm;
213 if ( dlm && dlm->dlm_mapped_ad == NULL && dlm->dlm_next == NULL ) {
214 /* if access allowed, try to add values, emulating permissive
215 * control to silently ignore duplicates */
216 if ( access_allowed( op, rs->sr_entry, slap_schema.si_ad_entry,
217 NULL, ACL_READ, NULL ) )
220 const char *text = NULL;
222 struct berval vals[ 2 ], nvals[ 2 ];
224 vals[ 0 ] = rs->sr_entry->e_name;
225 BER_BVZERO( &vals[ 1 ] );
226 nvals[ 0 ] = rs->sr_entry->e_nname;
227 BER_BVZERO( &nvals[ 1 ] );
229 mod.sm_op = LDAP_MOD_ADD;
230 mod.sm_desc = dlm->dlm_member_ad;
231 mod.sm_type = dlm->dlm_member_ad->ad_cname;
232 mod.sm_values = vals;
233 mod.sm_nvalues = nvals;
236 (void)modify_add_values( e, &mod, /* permissive */ 1,
237 &text, textbuf, sizeof( textbuf ) );
244 opattrs = ( rs->sr_attrs == NULL ) ? 0 : an_find( rs->sr_attrs, slap_bv_operational_attrs );
245 userattrs = ( rs->sr_attrs == NULL ) ? 1 : an_find( rs->sr_attrs, slap_bv_user_attrs );
246 #else /* SLAP_OPATTRS */
247 opattrs = SLAP_OPATTRS( rs->sr_attr_flags );
248 userattrs = SLAP_USERATTRS( rs->sr_attr_flags );
249 #endif /* SLAP_OPATTRS */
251 for ( a = rs->sr_entry->e_attrs; a != NULL; a = a->a_next ) {
252 BerVarray vals, nvals = NULL;
254 is_oc = a->a_desc == slap_schema.si_ad_objectClass;
256 /* if attribute is not requested, skip it */
257 if ( rs->sr_attrs == NULL ) {
258 if ( is_at_operational( a->a_desc->ad_type ) ) {
263 if ( is_at_operational( a->a_desc->ad_type ) ) {
264 if ( !opattrs && !ad_inlist( a->a_desc, rs->sr_attrs ) )
270 if ( !userattrs && !ad_inlist( a->a_desc, rs->sr_attrs ) )
277 /* test access to attribute */
278 if ( op->ors_attrsonly ) {
279 if ( !access_allowed( op, rs->sr_entry, a->a_desc, NULL,
280 ACL_READ, &acl_state ) )
286 /* single-value check: keep first only */
287 if ( is_at_single_value( a->a_desc->ad_type ) ) {
288 if ( attr_find( e->e_attrs, a->a_desc ) != NULL ) {
293 /* test access to attribute */
296 vals = op->o_tmpalloc( ( i + 1 ) * sizeof( struct berval ), op->o_tmpmemctx );
297 if ( a->a_nvals != a->a_vals ) {
298 nvals = op->o_tmpalloc( ( i + 1 ) * sizeof( struct berval ), op->o_tmpmemctx );
301 for ( i = 0, j = 0; !BER_BVISNULL( &a->a_vals[i] ); i++ ) {
303 ObjectClass *soc = oc_bvfind( &a->a_vals[i] );
305 if ( soc->soc_kind == LDAP_SCHEMA_STRUCTURAL ) {
310 if ( access_allowed( op, rs->sr_entry, a->a_desc,
311 &a->a_nvals[i], ACL_READ, &acl_state ) )
313 vals[j] = a->a_vals[i];
315 nvals[j] = a->a_nvals[i];
321 /* if access allowed, try to add values, emulating permissive
322 * control to silently ignore duplicates */
325 const char *text = NULL;
328 AttributeDescription *ad;
330 BER_BVZERO( &vals[j] );
332 BER_BVZERO( &nvals[j] );
336 for ( dlm = dlc->dlc_dli->dli_dlm; dlm; dlm = dlm->dlm_next ) {
337 if ( dlm->dlm_member_ad == a->a_desc ) {
338 if ( dlm->dlm_mapped_ad ) {
339 ad = dlm->dlm_mapped_ad;
345 mod.sm_op = LDAP_MOD_ADD;
347 mod.sm_type = ad->ad_cname;
348 mod.sm_values = vals;
349 mod.sm_nvalues = nvals;
352 (void)modify_add_values( e, &mod, /* permissive */ 1,
353 &text, textbuf, sizeof( textbuf ) );
356 op->o_tmpfree( vals, op->o_tmpmemctx );
358 op->o_tmpfree( nvals, op->o_tmpmemctx );
363 if ( rs->sr_flags & REP_ENTRY_MUSTBEFREED ) {
364 entry_free( rs->sr_entry );
366 rs->sr_flags ^= REP_ENTRY_MUSTBEFREED;
373 dynlist_prepare_entry( Operation *op, SlapReply *rs, dynlist_info_t *dli )
375 Attribute *a, *id = NULL;
378 SlapReply r = { REP_SEARCH };
384 dynlist_sc_t dlc = { 0 };
387 a = attrs_find( rs->sr_entry->e_attrs, dli->dli_ad );
390 return SLAP_CB_CONTINUE;
394 opattrs = ( rs->sr_attrs == NULL ) ? 0 : an_find( rs->sr_attrs, slap_bv_operational_attrs );
395 userattrs = ( rs->sr_attrs == NULL ) ? 1 : an_find( rs->sr_attrs, slap_bv_user_attrs );
396 #else /* SLAP_OPATTRS */
397 opattrs = SLAP_OPATTRS( rs->sr_attr_flags );
398 userattrs = SLAP_USERATTRS( rs->sr_attr_flags );
399 #endif /* SLAP_OPATTRS */
401 /* Don't generate member list if it wasn't requested */
402 for ( dlm = dli->dli_dlm; dlm; dlm = dlm->dlm_next ) {
403 AttributeDescription *ad = dlm->dlm_mapped_ad ? dlm->dlm_mapped_ad : dlm->dlm_member_ad;
404 if ( userattrs || ad_inlist( ad, rs->sr_attrs ) )
407 if ( dli->dli_dlm && !dlm )
408 return SLAP_CB_CONTINUE;
410 if ( ad_dgIdentity && ( id = attrs_find( rs->sr_entry->e_attrs, ad_dgIdentity ))) {
411 Attribute *authz = NULL;
413 /* if not rootdn and dgAuthz is present,
414 * check if user can be authorized as dgIdentity */
415 if ( ad_dgAuthz && !BER_BVISEMPTY( &id->a_nvals[0] ) && !be_isroot( op )
416 && ( authz = attrs_find( rs->sr_entry->e_attrs, ad_dgAuthz ) ) )
418 if ( slap_sasl_matches( op, authz->a_nvals,
419 &o.o_ndn, &o.o_ndn ) != LDAP_SUCCESS )
421 return SLAP_CB_CONTINUE;
425 o.o_dn = id->a_vals[0];
426 o.o_ndn = id->a_nvals[0];
430 e_flags = rs->sr_flags;
431 if ( !( rs->sr_flags & REP_ENTRY_MODIFIABLE ) ) {
432 e = entry_dup( rs->sr_entry );
433 e_flags |= ( REP_ENTRY_MODIFIABLE | REP_ENTRY_MUSTBEFREED );
434 e_flags &= ~REP_ENTRY_MUSTRELEASE;
441 cb.sc_private = &dlc;
442 cb.sc_response = dynlist_sc_update;
443 cb.sc_cleanup = NULL;
447 o.ors_deref = LDAP_DEREF_NEVER;
449 o.ors_tlimit = SLAP_NO_LIMIT;
450 o.ors_slimit = SLAP_NO_LIMIT;
452 for ( url = a->a_nvals; !BER_BVISNULL( url ); url++ ) {
453 LDAPURLDesc *lud = NULL;
458 BER_BVZERO( &o.o_req_dn );
459 BER_BVZERO( &o.o_req_ndn );
462 BER_BVZERO( &o.ors_filterstr );
464 if ( ldap_url_parse( url->bv_val, &lud ) != LDAP_URL_SUCCESS ) {
469 if ( lud->lud_host != NULL ) {
470 /* FIXME: host not allowed; reject as illegal? */
471 Debug( LDAP_DEBUG_ANY, "dynlist_prepare_entry(\"%s\"): "
472 "illegal URI \"%s\"\n",
473 e->e_name.bv_val, url->bv_val, 0 );
477 if ( lud->lud_dn == NULL ) {
478 /* note that an empty base is not honored in terms
479 * of defaultSearchBase, because select_backend()
480 * is not aware of the defaultSearchBase option;
481 * this can be useful in case of a database serving
482 * the empty suffix */
483 BER_BVSTR( &dn, "" );
486 ber_str2bv( lud->lud_dn, 0, 0, &dn );
488 rc = dnPrettyNormal( NULL, &dn, &o.o_req_dn, &o.o_req_ndn, op->o_tmpmemctx );
489 if ( rc != LDAP_SUCCESS ) {
493 o.ors_scope = lud->lud_scope;
495 for ( dlm = dli->dli_dlm; dlm; dlm = dlm->dlm_next ) {
496 if ( dlm->dlm_mapped_ad != NULL ) {
501 if ( dli->dli_dlm && !dlm ) {
502 /* if ( lud->lud_attrs != NULL ),
503 * the URL should be ignored */
504 o.ors_attrs = slap_anlist_no_attrs;
506 } else if ( lud->lud_attrs == NULL ) {
507 o.ors_attrs = rs->sr_attrs;
510 for ( i = 0; lud->lud_attrs[i]; i++)
513 o.ors_attrs = op->o_tmpcalloc( i + 1, sizeof( AttributeName ), op->o_tmpmemctx );
514 for ( i = 0, j = 0; lud->lud_attrs[i]; i++) {
515 const char *text = NULL;
517 ber_str2bv( lud->lud_attrs[i], 0, 0, &o.ors_attrs[j].an_name );
518 o.ors_attrs[j].an_desc = NULL;
519 (void)slap_bv2ad( &o.ors_attrs[j].an_name, &o.ors_attrs[j].an_desc, &text );
520 /* FIXME: ignore errors... */
522 if ( rs->sr_attrs == NULL ) {
523 if ( o.ors_attrs[j].an_desc != NULL &&
524 is_at_operational( o.ors_attrs[j].an_desc->ad_type ) )
530 if ( o.ors_attrs[j].an_desc != NULL &&
531 is_at_operational( o.ors_attrs[j].an_desc->ad_type ) )
537 if ( !ad_inlist( o.ors_attrs[j].an_desc, rs->sr_attrs ) ) {
538 /* lookup if mapped -- linear search,
539 * not very efficient unless list
541 for ( dlm = dli->dli_dlm; dlm; dlm = dlm->dlm_next ) {
542 if ( dlm->dlm_member_ad == o.ors_attrs[j].an_desc ) {
554 o.ors_attrs[j].an_desc != NULL &&
555 !ad_inlist( o.ors_attrs[j].an_desc, rs->sr_attrs ) )
557 /* lookup if mapped -- linear search,
558 * not very efficient unless list
560 for ( dlm = dli->dli_dlm; dlm; dlm = dlm->dlm_next ) {
561 if ( dlm->dlm_member_ad == o.ors_attrs[j].an_desc ) {
580 BER_BVZERO( &o.ors_attrs[j].an_name );
583 if ( lud->lud_filter == NULL ) {
584 ber_dupbv_x( &o.ors_filterstr,
585 &dli->dli_default_filter, op->o_tmpmemctx );
589 ber_str2bv( lud->lud_filter, 0, 0, &flt );
590 if ( dynlist_make_filter( op, rs->sr_entry, url->bv_val, &flt, &o.ors_filterstr ) ) {
595 o.ors_filter = str2filter_x( op, o.ors_filterstr.bv_val );
596 if ( o.ors_filter == NULL ) {
600 o.o_bd = select_backend( &o.o_req_ndn, 1 );
601 if ( o.o_bd && o.o_bd->be_search ) {
603 r.sr_attr_flags = slap_attr_flags( o.ors_attrs );
604 #endif /* SLAP_OPATTRS */
605 (void)o.o_bd->be_search( &o, &r );
610 slap_op_groups_free( &o );
612 if ( o.ors_filter ) {
613 filter_free_x( &o, o.ors_filter, 1 );
615 if ( o.ors_attrs && o.ors_attrs != rs->sr_attrs
616 && o.ors_attrs != slap_anlist_no_attrs )
618 op->o_tmpfree( o.ors_attrs, op->o_tmpmemctx );
620 if ( !BER_BVISNULL( &o.o_req_dn ) ) {
621 op->o_tmpfree( o.o_req_dn.bv_val, op->o_tmpmemctx );
623 if ( !BER_BVISNULL( &o.o_req_ndn ) ) {
624 op->o_tmpfree( o.o_req_ndn.bv_val, op->o_tmpmemctx );
626 assert( BER_BVISNULL( &o.ors_filterstr )
627 || o.ors_filterstr.bv_val != lud->lud_filter );
628 op->o_tmpfree( o.ors_filterstr.bv_val, op->o_tmpmemctx );
629 ldap_free_urldesc( lud );
633 rs->sr_flags = e_flags;
635 return SLAP_CB_CONTINUE;
639 dynlist_sc_save_entry( Operation *op, SlapReply *rs )
641 /* save the entry in the private field of the callback,
642 * so it doesn't get freed (it's temporary!) */
643 if ( rs->sr_entry != NULL ) {
644 dynlist_sc_t *dlc = (dynlist_sc_t *)op->o_callback->sc_private;
645 dlc->dlc_e = rs->sr_entry;
653 dynlist_compare( Operation *op, SlapReply *rs )
655 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
656 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private;
662 for ( ; dli != NULL; dli = dli->dli_next ) {
663 for ( dlm = dli->dli_dlm; dlm; dlm = dlm->dlm_next )
664 if ( op->oq_compare.rs_ava->aa_desc == dlm->dlm_member_ad )
668 /* This compare is for one of the attributes we're
669 * interested in. We'll use slapd's existing dyngroup
670 * evaluator to get the answer we want.
672 BerVarray id = NULL, authz = NULL;
674 o.o_do_not_cache = 1;
676 if ( ad_dgIdentity && backend_attribute( &o, NULL, &o.o_req_ndn,
677 ad_dgIdentity, &id, ACL_READ ) == LDAP_SUCCESS )
679 /* if not rootdn and dgAuthz is present,
680 * check if user can be authorized as dgIdentity */
681 if ( ad_dgAuthz && !BER_BVISEMPTY( id ) && !be_isroot( op )
682 && backend_attribute( &o, NULL, &o.o_req_ndn,
683 ad_dgAuthz, &authz, ACL_READ ) == LDAP_SUCCESS )
686 rs->sr_err = slap_sasl_matches( op, authz,
687 &o.o_ndn, &o.o_ndn );
688 ber_bvarray_free_x( authz, op->o_tmpmemctx );
689 if ( rs->sr_err != LDAP_SUCCESS ) {
696 o.o_groups = NULL; /* authz changed, invalidate cached groups */
699 rs->sr_err = backend_group( &o, NULL, &o.o_req_ndn,
700 &o.oq_compare.rs_ava->aa_value, dli->dli_oc, dli->dli_ad );
701 switch ( rs->sr_err ) {
703 rs->sr_err = LDAP_COMPARE_TRUE;
706 case LDAP_NO_SUCH_OBJECT:
707 /* NOTE: backend_group() returns noSuchObject
708 * if op_ndn does not exist; however, since
709 * dynamic list expansion means that the
710 * member attribute is virtually present, the
711 * non-existence of the asserted value implies
712 * the assertion is FALSE rather than
714 rs->sr_err = LDAP_COMPARE_FALSE;
719 if ( id ) ber_bvarray_free_x( id, o.o_tmpmemctx );
721 return SLAP_CB_CONTINUE;
725 be = select_backend( &o.o_req_ndn, 1 );
726 if ( !be || !be->be_search ) {
727 return SLAP_CB_CONTINUE;
730 if ( overlay_entry_get_ov( &o, &o.o_req_ndn, NULL, NULL, 0, &e, on ) !=
731 LDAP_SUCCESS || e == NULL )
733 return SLAP_CB_CONTINUE;
736 /* check for dynlist objectClass; done if not found */
737 dli = (dynlist_info_t *)on->on_bi.bi_private;
738 while ( dli != NULL && !is_entry_objectclass_or_sub( e, dli->dli_oc ) ) {
745 if ( ad_dgIdentity ) {
746 Attribute *id = attrs_find( e->e_attrs, ad_dgIdentity );
750 /* if not rootdn and dgAuthz is present,
751 * check if user can be authorized as dgIdentity */
752 if ( ad_dgAuthz && !BER_BVISEMPTY( &id->a_nvals[0] ) && !be_isroot( op )
753 && ( authz = attrs_find( e->e_attrs, ad_dgAuthz ) ) )
755 if ( slap_sasl_matches( op, authz->a_nvals,
756 &o.o_ndn, &o.o_ndn ) != LDAP_SUCCESS )
762 o.o_dn = id->a_vals[0];
763 o.o_ndn = id->a_nvals[0];
768 /* generate dynamic list with dynlist_response() and compare */
772 SlapReply r = { REP_SEARCH };
775 dynlist_sc_t dlc = { 0 };
777 cb.sc_private = &dlc;
778 cb.sc_response = dynlist_sc_save_entry;
779 cb.sc_cleanup = NULL;
783 o.o_tag = LDAP_REQ_SEARCH;
785 o.ors_tlimit = SLAP_NO_LIMIT;
786 o.ors_slimit = SLAP_NO_LIMIT;
788 o.ors_filterstr = *slap_filterstr_objectClass_pres;
789 o.ors_filter = (Filter *) slap_filter_objectClass_pres;
791 o.ors_scope = LDAP_SCOPE_BASE;
792 o.ors_deref = LDAP_DEREF_NEVER;
793 an[0].an_name = op->orc_ava->aa_desc->ad_cname;
794 an[0].an_desc = op->orc_ava->aa_desc;
795 BER_BVZERO( &an[1].an_name );
799 o.o_acl_priv = ACL_COMPARE;
802 rc = o.o_bd->be_search( &o, &r );
804 if ( o.o_dn.bv_val != op->o_dn.bv_val ) {
805 slap_op_groups_free( &o );
812 if ( dlc.dlc_e != NULL ) {
813 r.sr_entry = dlc.dlc_e;
816 if ( r.sr_err != LDAP_SUCCESS || r.sr_entry == NULL ) {
821 for ( a = attrs_find( r.sr_entry->e_attrs, op->orc_ava->aa_desc );
823 a = attrs_find( a->a_next, op->orc_ava->aa_desc ) )
825 /* if we're here, we got a match... */
826 rs->sr_err = LDAP_COMPARE_FALSE;
828 if ( attr_valfind( a,
829 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
830 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
831 &op->orc_ava->aa_value, NULL, op->o_tmpmemctx ) == 0 )
833 rs->sr_err = LDAP_COMPARE_TRUE;
838 if ( r.sr_flags & REP_ENTRY_MUSTBEFREED ) {
839 entry_free( r.sr_entry );
841 r.sr_flags ^= REP_ENTRY_MUSTBEFREED;
847 overlay_entry_release_ov( &o, e, 0, on );
850 return SLAP_CB_CONTINUE;
854 dynlist_response( Operation *op, SlapReply *rs )
856 switch ( op->o_tag ) {
857 case LDAP_REQ_SEARCH:
858 if ( rs->sr_type == REP_SEARCH && !get_manageDSAit( op ) )
860 int rc = SLAP_CB_CONTINUE;
861 dynlist_info_t *dli = NULL;
863 while ( (dli = dynlist_is_dynlist_next( op, rs, dli )) != NULL ) {
864 rc = dynlist_prepare_entry( op, rs, dli );
871 case LDAP_REQ_COMPARE:
872 switch ( rs->sr_err ) {
873 /* NOTE: we waste a few cycles running the dynamic list
874 * also when the result is FALSE, which occurs if the
875 * dynamic entry itself contains the AVA attribute */
876 /* FIXME: this approach is less than optimal; a dedicated
877 * compare op should be implemented, that fetches the
878 * entry, checks if it has the appropriate objectClass
879 * and, in case, runs a compare thru all the URIs,
880 * stopping at the first positive occurrence; see ITS#3756 */
881 case LDAP_COMPARE_FALSE:
882 case LDAP_NO_SUCH_ATTRIBUTE:
883 return dynlist_compare( op, rs );
888 return SLAP_CB_CONTINUE;
892 dynlist_build_def_filter( dynlist_info_t *dli )
896 dli->dli_default_filter.bv_len = STRLENOF( "(!(objectClass=" "))" )
897 + dli->dli_oc->soc_cname.bv_len;
898 dli->dli_default_filter.bv_val = ch_malloc( dli->dli_default_filter.bv_len + 1 );
899 if ( dli->dli_default_filter.bv_val == NULL ) {
900 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: malloc failed.\n",
905 ptr = lutil_strcopy( dli->dli_default_filter.bv_val, "(!(objectClass=" );
906 ptr = lutil_strcopy( ptr, dli->dli_oc->soc_cname.bv_val );
907 ptr = lutil_strcopy( ptr, "))" );
909 assert( ptr == &dli->dli_default_filter.bv_val[dli->dli_default_filter.bv_len] );
923 slap_overinst *on = (slap_overinst *)be->bd_info;
927 if ( strcasecmp( argv[0], "dynlist-attrset" ) == 0 ) {
928 dynlist_info_t **dlip;
930 AttributeDescription *ad = NULL,
932 dynlist_map_t *dlm = NULL, *dlml = NULL;
936 Debug( LDAP_DEBUG_ANY, "%s: line %d: " DYNLIST_USAGE
937 "invalid arg number #%d.\n",
938 fname, lineno, argc );
942 oc = oc_find( argv[1] );
944 Debug( LDAP_DEBUG_ANY, "%s: line %d: " DYNLIST_USAGE
945 "unable to find ObjectClass \"%s\"\n",
946 fname, lineno, argv[ 1 ] );
950 rc = slap_str2ad( argv[2], &ad, &text );
951 if ( rc != LDAP_SUCCESS ) {
952 Debug( LDAP_DEBUG_ANY, "%s: line %d: " DYNLIST_USAGE
953 "unable to find AttributeDescription \"%s\"\n",
954 fname, lineno, argv[2] );
958 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
959 Debug( LDAP_DEBUG_ANY, "%s: line %d: " DYNLIST_USAGE
960 "AttributeDescription \"%s\" "
961 "must be a subtype of \"labeledURI\"\n",
962 fname, lineno, argv[2] );
966 for ( i = 3; i < argc; i++ ) {
969 AttributeDescription *member_ad = NULL;
970 AttributeDescription *mapped_ad = NULL;
975 * If no mapped attribute is given, dn is used
976 * for backward compatibility.
979 if ( cp = strchr( arg, (int)':' ) != NULL ) {
981 ber_str2bv( arg, cp - arg, 0, &bv );
982 rc = slap_bv2ad( &bv, &mapped_ad, &text );
983 if ( rc != LDAP_SUCCESS ) {
984 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
986 "unable to find mapped AttributeDescription \"%s\"\n",
987 fname, lineno, arg );
994 rc = slap_str2ad( arg, &member_ad, &text );
995 if ( rc != LDAP_SUCCESS ) {
996 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
998 "unable to find AttributeDescription \"%s\"\n",
999 fname, lineno, arg );
1003 dlmp = (dynlist_map_t *)ch_calloc( 1, sizeof( dynlist_map_t ) );
1004 if ( dlm == NULL ) {
1007 dlmp->dlm_member_ad = member_ad;
1008 dlmp->dlm_mapped_ad = mapped_ad;
1009 dlmp->dlm_next = NULL;
1012 dlml->dlm_next = dlmp;
1016 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1017 *dlip; dlip = &(*dlip)->dli_next )
1020 * The same URL attribute / member attribute pair
1021 * cannot be repeated, but we enforce this only
1022 * when the member attribute is unique. Performing
1023 * the check for multiple values would require
1024 * sorting and comparing the lists, which is left
1025 * as a future improvement
1027 if ( (*dlip)->dli_ad == ad &&
1028 (*dlip)->dli_dlm->dlm_next == NULL &&
1029 dlm->dlm_next == NULL &&
1030 dlm->dlm_member_ad == (*dlip)->dli_dlm->dlm_member_ad &&
1031 dlm->dlm_mapped_ad == (*dlip)->dli_dlm->dlm_mapped_ad ) {
1032 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1034 "URL attributeDescription \"%s\" already mapped.\n",
1035 fname, lineno, ad->ad_cname.bv_val );
1037 /* make it a warning... */
1043 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
1044 (*dlip)->dli_oc = oc;
1045 (*dlip)->dli_ad = ad;
1046 (*dlip)->dli_dlm = dlm;
1048 if ( dynlist_build_def_filter( *dlip ) ) {
1049 dynlist_map_t *dlm = (*dlip)->ldi_dlm;
1050 dynlist_map_t *dlm_next;
1052 while ( dlm != NULL ) {
1053 dlm_next = dlm->dlm_next;
1063 /* allow dyngroup syntax */
1064 } else if ( strcasecmp( argv[0], "dynlist-attrpair" ) == 0 ) {
1065 dynlist_info_t **dlip;
1067 AttributeDescription *ad = NULL,
1072 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1073 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1074 "invalid arg number #%d.\n",
1075 fname, lineno, argc );
1079 oc = oc_find( "groupOfURLs" );
1081 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1082 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1083 "unable to find default ObjectClass \"groupOfURLs\"\n",
1088 rc = slap_str2ad( argv[1], &member_ad, &text );
1089 if ( rc != LDAP_SUCCESS ) {
1090 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1091 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1092 "unable to find AttributeDescription \"%s\"\n",
1093 fname, lineno, argv[1] );
1097 rc = slap_str2ad( argv[2], &ad, &text );
1098 if ( rc != LDAP_SUCCESS ) {
1099 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1100 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1101 "unable to find AttributeDescription \"%s\"\n",
1102 fname, lineno, argv[2] );
1106 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
1107 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1108 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1109 "AttributeDescription \"%s\" "
1110 "must be a subtype of \"labeledURI\"\n",
1111 fname, lineno, argv[2] );
1115 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1116 *dlip; dlip = &(*dlip)->dli_next )
1119 * The same URL attribute / member attribute pair
1120 * cannot be repeated, but we enforce this only
1121 * when the member attribute is unique. Performing
1122 * the check for multiple values would require
1123 * sorting and comparing the lists, which is left
1124 * as a future improvement
1126 if ( (*dlip)->dli_ad == ad &&
1127 (*dlip)->dli_dlm->dlm_next == NULL &&
1128 member_ad == (*dlip)->dli_dlm->dlm_member_ad ) {
1129 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1130 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1131 "URL attributeDescription \"%s\" already mapped.\n",
1132 fname, lineno, ad->ad_cname.bv_val );
1134 /* make it a warning... */
1140 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
1141 (*dlip)->dli_oc = oc;
1142 (*dlip)->dli_ad = ad;
1143 (*dlip)->dli_dlm = (dynlist_map_t *)ch_calloc( 1, sizeof( dynlist_map_t ) );
1144 (*dlip)->dli_dlm->dlm_member_ad = member_ad;
1145 (*dlip)->dli_dlm->dlm_mapped_ad = NULL;
1147 if ( dynlist_build_def_filter( *dlip ) ) {
1148 ch_free( (*dlip)->dli_dlm );
1155 rc = SLAP_CONF_UNKNOWN;
1169 static ConfigDriver dl_cfgen;
1171 /* XXXmanu 255 is the maximum arguments we allow. Can we go beyond? */
1172 static ConfigTable dlcfg[] = {
1173 { "dynlist-attrset", "group-oc> [uri] <URL-ad> <[mapped:]member-ad> [...]",
1174 3, 0, 0, ARG_MAGIC|DL_ATTRSET, dl_cfgen,
1175 "( OLcfgOvAt:8.1 NAME 'olcDlAttrSet' "
1176 "DESC 'Dynamic list: <group objectClass>, <URL attributeDescription>, <member attributeDescription>' "
1177 "EQUALITY caseIgnoreMatch "
1178 "SYNTAX OMsDirectoryString "
1179 "X-ORDERED 'VALUES' )",
1181 { "dynlist-attrpair", "member-ad> <URL-ad",
1182 3, 3, 0, ARG_MAGIC|DL_ATTRPAIR, dl_cfgen,
1184 #ifdef TAKEOVER_DYNGROUP
1185 { "attrpair", "member-ad> <URL-ad",
1186 3, 3, 0, ARG_MAGIC|DL_ATTRPAIR_COMPAT, dl_cfgen,
1189 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
1192 static ConfigOCs dlocs[] = {
1193 { "( OLcfgOvOc:8.1 "
1194 "NAME 'olcDynamicList' "
1195 "DESC 'Dynamic list configuration' "
1196 "SUP olcOverlayConfig "
1197 "MAY olcDLattrSet )",
1198 Cft_Overlay, dlcfg, NULL, NULL },
1203 dl_cfgen( ConfigArgs *c )
1205 slap_overinst *on = (slap_overinst *)c->bi;
1206 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private;
1210 if ( c->op == SLAP_CONFIG_EMIT ) {
1213 for ( i = 0; dli; i++, dli = dli->dli_next ) {
1215 char *ptr = c->cr_msg;
1218 assert( dli->dli_oc != NULL );
1219 assert( dli->dli_ad != NULL );
1221 /* FIXME: check buffer overflow! */
1222 ptr += snprintf( c->cr_msg, sizeof( c->cr_msg ),
1223 SLAP_X_ORDERED_FMT "%s", i,
1224 dli->dli_oc->soc_cname.bv_val );
1226 if ( !BER_BVISNULL( &dli->dli_uri ) ) {
1229 ptr = lutil_strncopy( ptr, dli->dli_uri.bv_val,
1230 dli->dli_uri.bv_len );
1235 ptr = lutil_strncopy( ptr, dli->dli_ad->ad_cname.bv_val,
1236 dli->dli_ad->ad_cname.bv_len );
1238 for ( dlm = dli->dli_dlm; dlm; dlm = dlm->dlm_next ) {
1241 if ( dlm->dlm_mapped_ad ) {
1242 ptr = lutil_strcopy( ptr, dlm->dlm_mapped_ad->ad_cname.bv_val );
1247 ptr = lutil_strcopy( ptr, dlm->dlm_member_ad->ad_cname.bv_val );
1250 bv.bv_val = c->cr_msg;
1251 bv.bv_len = ptr - bv.bv_val;
1252 value_add_one( &c->rvalue_vals, &bv );
1256 case DL_ATTRPAIR_COMPAT:
1268 } else if ( c->op == LDAP_MOD_DELETE ) {
1271 if ( c->valx < 0 ) {
1272 dynlist_info_t *dli_next;
1274 for ( dli_next = dli; dli_next; dli = dli_next ) {
1275 dynlist_map_t *dlm = dli->dli_dlm;
1276 dynlist_map_t *dlm_next;
1278 dli_next = dli->dli_next;
1280 if ( !BER_BVISNULL( &dli->dli_uri ) ) {
1281 ch_free( dli->dli_uri.bv_val );
1284 if ( dli->dli_lud != NULL ) {
1285 ldap_free_urldesc( dli->dli_lud );
1288 if ( !BER_BVISNULL( &dli->dli_uri_nbase ) ) {
1289 ber_memfree( dli->dli_uri_nbase.bv_val );
1292 if ( dli->dli_uri_filter != NULL ) {
1293 filter_free( dli->dli_uri_filter );
1296 ch_free( dli->dli_default_filter.bv_val );
1298 while ( dlm != NULL ) {
1299 dlm_next = dlm->dlm_next;
1306 on->on_bi.bi_private = NULL;
1309 dynlist_info_t **dlip;
1311 dynlist_map_t *dlm_next;
1313 for ( i = 0, dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1316 if ( *dlip == NULL ) {
1319 dlip = &(*dlip)->dli_next;
1323 *dlip = dli->dli_next;
1325 if ( !BER_BVISNULL( &dli->dli_uri ) ) {
1326 ch_free( dli->dli_uri.bv_val );
1329 if ( dli->dli_lud != NULL ) {
1330 ldap_free_urldesc( dli->dli_lud );
1333 if ( !BER_BVISNULL( &dli->dli_uri_nbase ) ) {
1334 ber_memfree( dli->dli_uri_nbase.bv_val );
1337 if ( dli->dli_uri_filter != NULL ) {
1338 filter_free( dli->dli_uri_filter );
1341 ch_free( dli->dli_default_filter.bv_val );
1344 while ( dlm != NULL ) {
1345 dlm_next = dlm->dlm_next;
1351 dli = (dynlist_info_t *)on->on_bi.bi_private;
1355 case DL_ATTRPAIR_COMPAT:
1370 dynlist_info_t **dlip,
1372 ObjectClass *oc = NULL;
1373 AttributeDescription *ad = NULL;
1375 LDAPURLDesc *lud = NULL;
1376 struct berval nbase = BER_BVNULL;
1377 Filter *filter = NULL;
1378 struct berval uri = BER_BVNULL;
1379 dynlist_map_t *dlm = NULL, *dlml = NULL;
1382 oc = oc_find( c->argv[ 1 ] );
1384 snprintf( c->cr_msg, sizeof( c->cr_msg ), DYNLIST_USAGE
1385 "unable to find ObjectClass \"%s\"",
1387 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1388 c->log, c->cr_msg, 0 );
1392 if ( strncasecmp( c->argv[ attridx ], "ldap://", STRLENOF("ldap://") ) == 0 ) {
1393 if ( ldap_url_parse( c->argv[ attridx ], &lud ) != LDAP_URL_SUCCESS ) {
1394 snprintf( c->cr_msg, sizeof( c->cr_msg ), DYNLIST_USAGE
1395 "unable to parse URI \"%s\"",
1396 c->argv[ attridx ] );
1401 if ( lud->lud_host != NULL ) {
1402 if ( lud->lud_host[0] == '\0' ) {
1403 ch_free( lud->lud_host );
1404 lud->lud_host = NULL;
1407 snprintf( c->cr_msg, sizeof( c->cr_msg ), DYNLIST_USAGE
1408 "host not allowed in URI \"%s\"",
1409 c->argv[ attridx ] );
1415 if ( lud->lud_attrs != NULL ) {
1416 snprintf( c->cr_msg, sizeof( c->cr_msg ), DYNLIST_USAGE
1417 "attrs not allowed in URI \"%s\"",
1418 c->argv[ attridx ] );
1423 if ( lud->lud_exts != NULL ) {
1424 snprintf( c->cr_msg, sizeof( c->cr_msg ), DYNLIST_USAGE
1425 "extensions not allowed in URI \"%s\"",
1426 c->argv[ attridx ] );
1431 if ( lud->lud_dn != NULL && lud->lud_dn[ 0 ] != '\0' ) {
1433 ber_str2bv( lud->lud_dn, 0, 0, &dn );
1434 rc = dnNormalize( 0, NULL, NULL, &dn, &nbase, NULL );
1435 if ( rc != LDAP_SUCCESS ) {
1436 snprintf( c->cr_msg, sizeof( c->cr_msg ), DYNLIST_USAGE
1437 "DN normalization failed in URI \"%s\"",
1438 c->argv[ attridx ] );
1443 if ( lud->lud_filter != NULL && lud->lud_filter[ 0 ] != '\0' ) {
1444 filter = str2filter( lud->lud_filter );
1445 if ( filter == NULL ) {
1446 snprintf( c->cr_msg, sizeof( c->cr_msg ), DYNLIST_USAGE
1447 "filter parsing failed in URI \"%s\"",
1448 c->argv[ attridx ] );
1454 ber_str2bv( c->argv[ attridx ], 0, 1, &uri );
1459 ldap_free_urldesc( lud );
1462 if ( !BER_BVISNULL( &nbase ) ) {
1463 ber_memfree( nbase.bv_val );
1466 if ( filter != NULL ) {
1467 filter_free( filter );
1470 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1471 c->log, c->cr_msg, 0 );
1479 rc = slap_str2ad( c->argv[ attridx ], &ad, &text );
1480 if ( rc != LDAP_SUCCESS ) {
1481 snprintf( c->cr_msg, sizeof( c->cr_msg ), DYNLIST_USAGE
1482 "unable to find AttributeDescription \"%s\"",
1483 c->argv[ attridx ] );
1484 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1485 c->log, c->cr_msg, 0 );
1489 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
1490 snprintf( c->cr_msg, sizeof( c->cr_msg ), DYNLIST_USAGE
1491 "AttributeDescription \"%s\" "
1492 "must be a subtype of \"labeledURI\"",
1493 c->argv[ attridx ] );
1494 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1495 c->log, c->cr_msg, 0 );
1501 for ( i = attridx; i < c->argc; i++ ) {
1504 AttributeDescription *member_ad = NULL;
1505 AttributeDescription *mapped_ad = NULL;
1506 dynlist_map_t *dlmp;
1510 * If no mapped attribute is given, dn is used
1511 * for backward compatibility.
1514 if ( ( cp = strchr( arg, ':' ) ) != NULL ) {
1516 ber_str2bv( arg, cp - arg, 0, &bv );
1517 rc = slap_bv2ad( &bv, &mapped_ad, &text );
1518 if ( rc != LDAP_SUCCESS ) {
1519 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1521 "unable to find mapped AttributeDescription #%d \"%s\"\n",
1522 i - 3, c->argv[ i ] );
1523 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1524 c->log, c->cr_msg, 0 );
1530 rc = slap_str2ad( arg, &member_ad, &text );
1531 if ( rc != LDAP_SUCCESS ) {
1532 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1534 "unable to find AttributeDescription #%d \"%s\"\n",
1535 i - 3, c->argv[ i ] );
1536 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1537 c->log, c->cr_msg, 0 );
1541 dlmp = (dynlist_map_t *)ch_calloc( 1, sizeof( dynlist_map_t ) );
1542 if ( dlm == NULL ) {
1545 dlmp->dlm_member_ad = member_ad;
1546 dlmp->dlm_mapped_ad = mapped_ad;
1547 dlmp->dlm_next = NULL;
1550 dlml->dlm_next = dlmp;
1554 if ( c->valx > 0 ) {
1557 for ( i = 0, dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1560 if ( *dlip == NULL ) {
1561 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1563 "invalid index {%d}\n",
1565 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1566 c->log, c->cr_msg, 0 );
1569 dlip = &(*dlip)->dli_next;
1574 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1575 *dlip; dlip = &(*dlip)->dli_next )
1579 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
1581 (*dlip)->dli_oc = oc;
1582 (*dlip)->dli_ad = ad;
1583 (*dlip)->dli_dlm = dlm;
1584 (*dlip)->dli_next = dli_next;
1586 (*dlip)->dli_lud = lud;
1587 (*dlip)->dli_uri_nbase = nbase;
1588 (*dlip)->dli_uri_filter = filter;
1589 (*dlip)->dli_uri = uri;
1591 rc = dynlist_build_def_filter( *dlip );
1595 case DL_ATTRPAIR_COMPAT:
1596 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1597 "warning: \"attrpair\" only supported for limited "
1598 "backward compatibility with overlay \"dyngroup\"" );
1599 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
1603 dynlist_info_t **dlip;
1604 ObjectClass *oc = NULL;
1605 AttributeDescription *ad = NULL,
1609 oc = oc_find( "groupOfURLs" );
1611 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1612 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1613 "unable to find default ObjectClass \"groupOfURLs\"" );
1614 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1615 c->log, c->cr_msg, 0 );
1619 rc = slap_str2ad( c->argv[ 1 ], &member_ad, &text );
1620 if ( rc != LDAP_SUCCESS ) {
1621 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1622 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1623 "unable to find AttributeDescription \"%s\"",
1625 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1626 c->log, c->cr_msg, 0 );
1630 rc = slap_str2ad( c->argv[ 2 ], &ad, &text );
1631 if ( rc != LDAP_SUCCESS ) {
1632 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1633 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1634 "unable to find AttributeDescription \"%s\"\n",
1636 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1637 c->log, c->cr_msg, 0 );
1641 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
1642 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1644 "AttributeDescription \"%s\" "
1645 "must be a subtype of \"labeledURI\"",
1647 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1648 c->log, c->cr_msg, 0 );
1652 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1653 *dlip; dlip = &(*dlip)->dli_next )
1656 * The same URL attribute / member attribute pair
1657 * cannot be repeated, but we enforce this only
1658 * when the member attribute is unique. Performing
1659 * the check for multiple values would require
1660 * sorting and comparing the lists, which is left
1661 * as a future improvement
1663 if ( (*dlip)->dli_ad == ad &&
1664 (*dlip)->dli_dlm->dlm_next == NULL &&
1665 member_ad == (*dlip)->dli_dlm->dlm_member_ad ) {
1666 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1667 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1668 "URL attributeDescription \"%s\" already mapped.\n",
1669 ad->ad_cname.bv_val );
1670 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1671 c->log, c->cr_msg, 0 );
1673 /* make it a warning... */
1679 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
1681 (*dlip)->dli_oc = oc;
1682 (*dlip)->dli_ad = ad;
1683 (*dlip)->dli_dlm = (dynlist_map_t *)ch_calloc( 1, sizeof( dynlist_map_t ) );
1684 (*dlip)->dli_dlm->dlm_member_ad = member_ad;
1685 (*dlip)->dli_dlm->dlm_mapped_ad = NULL;
1687 rc = dynlist_build_def_filter( *dlip );
1705 slap_overinst *on = (slap_overinst *) be->bd_info;
1706 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private;
1707 ObjectClass *oc = NULL;
1708 AttributeDescription *ad = NULL;
1712 if ( dli == NULL ) {
1713 dli = ch_calloc( 1, sizeof( dynlist_info_t ) );
1714 on->on_bi.bi_private = (void *)dli;
1717 for ( ; dli; dli = dli->dli_next ) {
1718 if ( dli->dli_oc == NULL ) {
1720 oc = oc_find( "groupOfURLs" );
1722 snprintf( cr->msg, sizeof( cr->msg),
1723 "unable to fetch objectClass \"groupOfURLs\"" );
1724 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: %s.\n", cr->msg, 0, 0 );
1732 if ( dli->dli_ad == NULL ) {
1734 rc = slap_str2ad( "memberURL", &ad, &text );
1735 if ( rc != LDAP_SUCCESS ) {
1736 snprintf( cr->msg, sizeof( cr->msg),
1737 "unable to fetch attributeDescription \"memberURL\": %d (%s)",
1739 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: %s.\n", cr->msg, 0, 0 );
1747 if ( BER_BVISNULL( &dli->dli_default_filter ) ) {
1748 rc = dynlist_build_def_filter( dli );
1755 if ( ad_dgIdentity == NULL ) {
1756 rc = slap_str2ad( "dgIdentity", &ad_dgIdentity, &text );
1757 if ( rc != LDAP_SUCCESS ) {
1758 snprintf( cr->msg, sizeof( cr->msg),
1759 "unable to fetch attributeDescription \"dgIdentity\": %d (%s)",
1761 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: %s\n", cr->msg, 0, 0 );
1762 /* Just a warning */
1766 if ( ad_dgAuthz == NULL ) {
1767 rc = slap_str2ad( "dgAuthz", &ad_dgAuthz, &text );
1768 if ( rc != LDAP_SUCCESS ) {
1769 snprintf( cr->msg, sizeof( cr->msg),
1770 "unable to fetch attributeDescription \"dgAuthz\": %d (%s)",
1772 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: %s\n", cr->msg, 0, 0 );
1773 /* Just a warning */
1785 slap_overinst *on = (slap_overinst *) be->bd_info;
1787 if ( on->on_bi.bi_private ) {
1788 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private,
1791 for ( dli_next = dli; dli_next; dli = dli_next ) {
1793 dynlist_map_t *dlm_next;
1795 dli_next = dli->dli_next;
1797 if ( !BER_BVISNULL( &dli->dli_uri ) ) {
1798 ch_free( dli->dli_uri.bv_val );
1801 if ( dli->dli_lud != NULL ) {
1802 ldap_free_urldesc( dli->dli_lud );
1805 if ( !BER_BVISNULL( &dli->dli_uri_nbase ) ) {
1806 ber_memfree( dli->dli_uri_nbase.bv_val );
1809 if ( dli->dli_uri_filter != NULL ) {
1810 filter_free( dli->dli_uri_filter );
1813 ch_free( dli->dli_default_filter.bv_val );
1816 while ( dlm != NULL ) {
1817 dlm_next = dlm->dlm_next;
1828 static slap_overinst dynlist = { { NULL } };
1829 #ifdef TAKEOVER_DYNGROUP
1830 static char *obsolete_names[] = {
1836 #if SLAPD_OVER_DYNLIST == SLAPD_MOD_DYNAMIC
1838 #endif /* SLAPD_OVER_DYNLIST == SLAPD_MOD_DYNAMIC */
1840 dynlist_initialize(void)
1842 #ifndef OL_2_2_COMPAT
1846 dynlist.on_bi.bi_type = "dynlist";
1848 #ifdef TAKEOVER_DYNGROUP
1849 /* makes dynlist incompatible with dyngroup */
1850 dynlist.on_bi.bi_obsolete_names = obsolete_names;
1853 #ifdef OL_2_2_COMPAT
1854 dynlist.on_bi.bi_db_config = dynlist_db_config;
1856 dynlist.on_bi.bi_db_config = config_generic_wrapper;
1858 dynlist.on_bi.bi_db_open = dynlist_db_open;
1859 dynlist.on_bi.bi_db_destroy = dynlist_db_destroy;
1861 dynlist.on_response = dynlist_response;
1863 #ifndef OL_2_2_COMPAT
1864 dynlist.on_bi.bi_cf_ocs = dlocs;
1866 rc = config_register_schema( dlcfg, dlocs );
1872 return overlay_register( &dynlist );
1875 #if SLAPD_OVER_DYNLIST == SLAPD_MOD_DYNAMIC
1877 init_module( int argc, char *argv[] )
1879 return dynlist_initialize();
1883 #endif /* SLAPD_OVER_DYNLIST */