1 /* dynlist.c - dynamic list overlay */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2003-2009 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;
661 for ( ; dli != NULL; dli = dli->dli_next ) {
662 for ( dlm = dli->dli_dlm; dlm; dlm = dlm->dlm_next )
663 if ( op->oq_compare.rs_ava->aa_desc == dlm->dlm_member_ad )
666 if ( dli->dli_dlm && dlm ) {
667 /* This compare is for one of the attributes we're
668 * interested in. We'll use slapd's existing dyngroup
669 * evaluator to get the answer we want.
671 BerVarray id = NULL, authz = NULL;
673 o.o_do_not_cache = 1;
675 if ( ad_dgIdentity && backend_attribute( &o, NULL, &o.o_req_ndn,
676 ad_dgIdentity, &id, ACL_READ ) == LDAP_SUCCESS )
678 /* if not rootdn and dgAuthz is present,
679 * check if user can be authorized as dgIdentity */
680 if ( ad_dgAuthz && !BER_BVISEMPTY( id ) && !be_isroot( op )
681 && backend_attribute( &o, NULL, &o.o_req_ndn,
682 ad_dgAuthz, &authz, ACL_READ ) == LDAP_SUCCESS )
685 rs->sr_err = slap_sasl_matches( op, authz,
686 &o.o_ndn, &o.o_ndn );
687 ber_bvarray_free_x( authz, op->o_tmpmemctx );
688 if ( rs->sr_err != LDAP_SUCCESS ) {
695 o.o_groups = NULL; /* authz changed, invalidate cached groups */
698 rs->sr_err = backend_group( &o, NULL, &o.o_req_ndn,
699 &o.oq_compare.rs_ava->aa_value, dli->dli_oc, dli->dli_ad );
700 switch ( rs->sr_err ) {
702 rs->sr_err = LDAP_COMPARE_TRUE;
705 case LDAP_NO_SUCH_OBJECT:
706 /* NOTE: backend_group() returns noSuchObject
707 * if op_ndn does not exist; however, since
708 * dynamic list expansion means that the
709 * member attribute is virtually present, the
710 * non-existence of the asserted value implies
711 * the assertion is FALSE rather than
713 rs->sr_err = LDAP_COMPARE_FALSE;
718 if ( id ) ber_bvarray_free_x( id, o.o_tmpmemctx );
720 return SLAP_CB_CONTINUE;
724 if ( overlay_entry_get_ov( &o, &o.o_req_ndn, NULL, NULL, 0, &e, on ) !=
725 LDAP_SUCCESS || e == NULL )
727 return SLAP_CB_CONTINUE;
730 if ( ad_dgIdentity ) {
731 Attribute *id = attrs_find( e->e_attrs, ad_dgIdentity );
735 /* if not rootdn and dgAuthz is present,
736 * check if user can be authorized as dgIdentity */
737 if ( ad_dgAuthz && !BER_BVISEMPTY( &id->a_nvals[0] ) && !be_isroot( op )
738 && ( authz = attrs_find( e->e_attrs, ad_dgAuthz ) ) )
740 if ( slap_sasl_matches( op, authz->a_nvals,
741 &o.o_ndn, &o.o_ndn ) != LDAP_SUCCESS )
747 o.o_dn = id->a_vals[0];
748 o.o_ndn = id->a_nvals[0];
753 dli = (dynlist_info_t *)on->on_bi.bi_private;
754 for ( ; dli != NULL && rs->sr_err != LDAP_COMPARE_TRUE; dli = dli->dli_next ) {
757 SlapReply r = { REP_SEARCH };
760 dynlist_sc_t dlc = { 0 };
762 if ( !is_entry_objectclass_or_sub( e, dli->dli_oc ))
765 /* if the entry has the right objectClass, generate
766 * the dynamic list and compare */
768 cb.sc_private = &dlc;
769 cb.sc_response = dynlist_sc_save_entry;
770 cb.sc_cleanup = NULL;
774 o.o_tag = LDAP_REQ_SEARCH;
776 o.ors_tlimit = SLAP_NO_LIMIT;
777 o.ors_slimit = SLAP_NO_LIMIT;
779 o.o_bd = select_backend( &o.o_req_ndn, 1 );
780 if ( !o.o_bd || !o.o_bd->be_search ) {
784 o.ors_filterstr = *slap_filterstr_objectClass_pres;
785 o.ors_filter = (Filter *) slap_filter_objectClass_pres;
787 o.ors_scope = LDAP_SCOPE_BASE;
788 o.ors_deref = LDAP_DEREF_NEVER;
789 an[0].an_name = op->orc_ava->aa_desc->ad_cname;
790 an[0].an_desc = op->orc_ava->aa_desc;
791 BER_BVZERO( &an[1].an_name );
795 o.o_acl_priv = ACL_COMPARE;
797 rc = o.o_bd->be_search( &o, &r );
799 if ( o.o_dn.bv_val != op->o_dn.bv_val ) {
800 slap_op_groups_free( &o );
807 if ( dlc.dlc_e != NULL ) {
808 r.sr_entry = dlc.dlc_e;
811 if ( r.sr_err != LDAP_SUCCESS || r.sr_entry == NULL ) {
816 for ( a = attrs_find( r.sr_entry->e_attrs, op->orc_ava->aa_desc );
818 a = attrs_find( a->a_next, op->orc_ava->aa_desc ) )
820 /* if we're here, we got a match... */
821 rs->sr_err = LDAP_COMPARE_FALSE;
823 if ( attr_valfind( a,
824 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
825 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
826 &op->orc_ava->aa_value, NULL, op->o_tmpmemctx ) == 0 )
828 rs->sr_err = LDAP_COMPARE_TRUE;
833 if ( r.sr_flags & REP_ENTRY_MUSTBEFREED ) {
834 entry_free( r.sr_entry );
836 r.sr_flags ^= REP_ENTRY_MUSTBEFREED;
842 overlay_entry_release_ov( &o, e, 0, on );
845 return SLAP_CB_CONTINUE;
849 dynlist_response( Operation *op, SlapReply *rs )
853 switch ( op->o_tag ) {
854 case LDAP_REQ_SEARCH:
855 if ( rs->sr_type == REP_SEARCH && !get_manageDSAit( op ) )
859 for ( dli = dynlist_is_dynlist_next( op, rs, NULL );
861 dli = dynlist_is_dynlist_next( op, rs, dli ) )
863 rc = dynlist_prepare_entry( op, rs, dli );
866 if ( rc != LDAP_OTHER ) {
872 case LDAP_REQ_COMPARE:
873 switch ( rs->sr_err ) {
874 /* NOTE: we waste a few cycles running the dynamic list
875 * also when the result is FALSE, which occurs if the
876 * dynamic entry itself contains the AVA attribute */
877 /* FIXME: this approach is less than optimal; a dedicated
878 * compare op should be implemented, that fetches the
879 * entry, checks if it has the appropriate objectClass
880 * and, in case, runs a compare thru all the URIs,
881 * stopping at the first positive occurrence; see ITS#3756 */
882 case LDAP_COMPARE_FALSE:
883 case LDAP_NO_SUCH_ATTRIBUTE:
884 return dynlist_compare( op, rs );
892 return SLAP_CB_CONTINUE;
896 dynlist_build_def_filter( dynlist_info_t *dli )
900 dli->dli_default_filter.bv_len = STRLENOF( "(!(objectClass=" "))" )
901 + dli->dli_oc->soc_cname.bv_len;
902 dli->dli_default_filter.bv_val = ch_malloc( dli->dli_default_filter.bv_len + 1 );
903 if ( dli->dli_default_filter.bv_val == NULL ) {
904 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: malloc failed.\n",
909 ptr = lutil_strcopy( dli->dli_default_filter.bv_val, "(!(objectClass=" );
910 ptr = lutil_strcopy( ptr, dli->dli_oc->soc_cname.bv_val );
911 ptr = lutil_strcopy( ptr, "))" );
913 assert( ptr == &dli->dli_default_filter.bv_val[dli->dli_default_filter.bv_len] );
927 slap_overinst *on = (slap_overinst *)be->bd_info;
931 if ( strcasecmp( argv[0], "dynlist-attrset" ) == 0 ) {
932 dynlist_info_t **dlip;
934 AttributeDescription *ad = NULL,
936 dynlist_map_t *dlm = NULL, *dlml = NULL;
940 Debug( LDAP_DEBUG_ANY, "%s: line %d: " DYNLIST_USAGE
941 "invalid arg number #%d.\n",
942 fname, lineno, argc );
946 oc = oc_find( argv[1] );
948 Debug( LDAP_DEBUG_ANY, "%s: line %d: " DYNLIST_USAGE
949 "unable to find ObjectClass \"%s\"\n",
950 fname, lineno, argv[ 1 ] );
954 rc = slap_str2ad( argv[2], &ad, &text );
955 if ( rc != LDAP_SUCCESS ) {
956 Debug( LDAP_DEBUG_ANY, "%s: line %d: " DYNLIST_USAGE
957 "unable to find AttributeDescription \"%s\"\n",
958 fname, lineno, argv[2] );
962 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
963 Debug( LDAP_DEBUG_ANY, "%s: line %d: " DYNLIST_USAGE
964 "AttributeDescription \"%s\" "
965 "must be a subtype of \"labeledURI\"\n",
966 fname, lineno, argv[2] );
970 for ( i = 3; i < argc; i++ ) {
973 AttributeDescription *member_ad = NULL;
974 AttributeDescription *mapped_ad = NULL;
979 * If no mapped attribute is given, dn is used
980 * for backward compatibility.
983 if ( cp = strchr( arg, (int)':' ) != NULL ) {
985 ber_str2bv( arg, cp - arg, 0, &bv );
986 rc = slap_bv2ad( &bv, &mapped_ad, &text );
987 if ( rc != LDAP_SUCCESS ) {
988 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
990 "unable to find mapped AttributeDescription \"%s\"\n",
991 fname, lineno, arg );
998 rc = slap_str2ad( arg, &member_ad, &text );
999 if ( rc != LDAP_SUCCESS ) {
1000 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1002 "unable to find AttributeDescription \"%s\"\n",
1003 fname, lineno, arg );
1007 dlmp = (dynlist_map_t *)ch_calloc( 1, sizeof( dynlist_map_t ) );
1008 if ( dlm == NULL ) {
1011 dlmp->dlm_member_ad = member_ad;
1012 dlmp->dlm_mapped_ad = mapped_ad;
1013 dlmp->dlm_next = NULL;
1016 dlml->dlm_next = dlmp;
1020 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1021 *dlip; dlip = &(*dlip)->dli_next )
1024 * The same URL attribute / member attribute pair
1025 * cannot be repeated, but we enforce this only
1026 * when the member attribute is unique. Performing
1027 * the check for multiple values would require
1028 * sorting and comparing the lists, which is left
1029 * as a future improvement
1031 if ( (*dlip)->dli_ad == ad &&
1032 (*dlip)->dli_dlm->dlm_next == NULL &&
1033 dlm->dlm_next == NULL &&
1034 dlm->dlm_member_ad == (*dlip)->dli_dlm->dlm_member_ad &&
1035 dlm->dlm_mapped_ad == (*dlip)->dli_dlm->dlm_mapped_ad ) {
1036 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1038 "URL attributeDescription \"%s\" already mapped.\n",
1039 fname, lineno, ad->ad_cname.bv_val );
1041 /* make it a warning... */
1047 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
1048 (*dlip)->dli_oc = oc;
1049 (*dlip)->dli_ad = ad;
1050 (*dlip)->dli_dlm = dlm;
1052 if ( dynlist_build_def_filter( *dlip ) ) {
1053 dynlist_map_t *dlm = (*dlip)->ldi_dlm;
1054 dynlist_map_t *dlm_next;
1056 while ( dlm != NULL ) {
1057 dlm_next = dlm->dlm_next;
1067 /* allow dyngroup syntax */
1068 } else if ( strcasecmp( argv[0], "dynlist-attrpair" ) == 0 ) {
1069 dynlist_info_t **dlip;
1071 AttributeDescription *ad = NULL,
1076 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1077 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1078 "invalid arg number #%d.\n",
1079 fname, lineno, argc );
1083 oc = oc_find( "groupOfURLs" );
1085 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1086 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1087 "unable to find default ObjectClass \"groupOfURLs\"\n",
1092 rc = slap_str2ad( argv[1], &member_ad, &text );
1093 if ( rc != LDAP_SUCCESS ) {
1094 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1095 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1096 "unable to find AttributeDescription \"%s\"\n",
1097 fname, lineno, argv[1] );
1101 rc = slap_str2ad( argv[2], &ad, &text );
1102 if ( rc != LDAP_SUCCESS ) {
1103 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1104 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1105 "unable to find AttributeDescription \"%s\"\n",
1106 fname, lineno, argv[2] );
1110 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
1111 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1112 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1113 "AttributeDescription \"%s\" "
1114 "must be a subtype of \"labeledURI\"\n",
1115 fname, lineno, argv[2] );
1119 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1120 *dlip; dlip = &(*dlip)->dli_next )
1123 * The same URL attribute / member attribute pair
1124 * cannot be repeated, but we enforce this only
1125 * when the member attribute is unique. Performing
1126 * the check for multiple values would require
1127 * sorting and comparing the lists, which is left
1128 * as a future improvement
1130 if ( (*dlip)->dli_ad == ad &&
1131 (*dlip)->dli_dlm->dlm_next == NULL &&
1132 member_ad == (*dlip)->dli_dlm->dlm_member_ad ) {
1133 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1134 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1135 "URL attributeDescription \"%s\" already mapped.\n",
1136 fname, lineno, ad->ad_cname.bv_val );
1138 /* make it a warning... */
1144 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
1145 (*dlip)->dli_oc = oc;
1146 (*dlip)->dli_ad = ad;
1147 (*dlip)->dli_dlm = (dynlist_map_t *)ch_calloc( 1, sizeof( dynlist_map_t ) );
1148 (*dlip)->dli_dlm->dlm_member_ad = member_ad;
1149 (*dlip)->dli_dlm->dlm_mapped_ad = NULL;
1151 if ( dynlist_build_def_filter( *dlip ) ) {
1152 ch_free( (*dlip)->dli_dlm );
1159 rc = SLAP_CONF_UNKNOWN;
1173 static ConfigDriver dl_cfgen;
1175 /* XXXmanu 255 is the maximum arguments we allow. Can we go beyond? */
1176 static ConfigTable dlcfg[] = {
1177 { "dynlist-attrset", "group-oc> [uri] <URL-ad> <[mapped:]member-ad> [...]",
1178 3, 0, 0, ARG_MAGIC|DL_ATTRSET, dl_cfgen,
1179 "( OLcfgOvAt:8.1 NAME 'olcDlAttrSet' "
1180 "DESC 'Dynamic list: <group objectClass>, <URL attributeDescription>, <member attributeDescription>' "
1181 "EQUALITY caseIgnoreMatch "
1182 "SYNTAX OMsDirectoryString "
1183 "X-ORDERED 'VALUES' )",
1185 { "dynlist-attrpair", "member-ad> <URL-ad",
1186 3, 3, 0, ARG_MAGIC|DL_ATTRPAIR, dl_cfgen,
1188 #ifdef TAKEOVER_DYNGROUP
1189 { "attrpair", "member-ad> <URL-ad",
1190 3, 3, 0, ARG_MAGIC|DL_ATTRPAIR_COMPAT, dl_cfgen,
1193 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
1196 static ConfigOCs dlocs[] = {
1197 { "( OLcfgOvOc:8.1 "
1198 "NAME 'olcDynamicList' "
1199 "DESC 'Dynamic list configuration' "
1200 "SUP olcOverlayConfig "
1201 "MAY olcDLattrSet )",
1202 Cft_Overlay, dlcfg, NULL, NULL },
1207 dl_cfgen( ConfigArgs *c )
1209 slap_overinst *on = (slap_overinst *)c->bi;
1210 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private;
1214 if ( c->op == SLAP_CONFIG_EMIT ) {
1217 for ( i = 0; dli; i++, dli = dli->dli_next ) {
1219 char *ptr = c->cr_msg;
1222 assert( dli->dli_oc != NULL );
1223 assert( dli->dli_ad != NULL );
1225 /* FIXME: check buffer overflow! */
1226 ptr += snprintf( c->cr_msg, sizeof( c->cr_msg ),
1227 SLAP_X_ORDERED_FMT "%s", i,
1228 dli->dli_oc->soc_cname.bv_val );
1230 if ( !BER_BVISNULL( &dli->dli_uri ) ) {
1233 ptr = lutil_strncopy( ptr, dli->dli_uri.bv_val,
1234 dli->dli_uri.bv_len );
1239 ptr = lutil_strncopy( ptr, dli->dli_ad->ad_cname.bv_val,
1240 dli->dli_ad->ad_cname.bv_len );
1242 for ( dlm = dli->dli_dlm; dlm; dlm = dlm->dlm_next ) {
1245 if ( dlm->dlm_mapped_ad ) {
1246 ptr = lutil_strcopy( ptr, dlm->dlm_mapped_ad->ad_cname.bv_val );
1251 ptr = lutil_strcopy( ptr, dlm->dlm_member_ad->ad_cname.bv_val );
1254 bv.bv_val = c->cr_msg;
1255 bv.bv_len = ptr - bv.bv_val;
1256 value_add_one( &c->rvalue_vals, &bv );
1260 case DL_ATTRPAIR_COMPAT:
1272 } else if ( c->op == LDAP_MOD_DELETE ) {
1275 if ( c->valx < 0 ) {
1276 dynlist_info_t *dli_next;
1278 for ( dli_next = dli; dli_next; dli = dli_next ) {
1279 dynlist_map_t *dlm = dli->dli_dlm;
1280 dynlist_map_t *dlm_next;
1282 dli_next = dli->dli_next;
1284 if ( !BER_BVISNULL( &dli->dli_uri ) ) {
1285 ch_free( dli->dli_uri.bv_val );
1288 if ( dli->dli_lud != NULL ) {
1289 ldap_free_urldesc( dli->dli_lud );
1292 if ( !BER_BVISNULL( &dli->dli_uri_nbase ) ) {
1293 ber_memfree( dli->dli_uri_nbase.bv_val );
1296 if ( dli->dli_uri_filter != NULL ) {
1297 filter_free( dli->dli_uri_filter );
1300 ch_free( dli->dli_default_filter.bv_val );
1302 while ( dlm != NULL ) {
1303 dlm_next = dlm->dlm_next;
1310 on->on_bi.bi_private = NULL;
1313 dynlist_info_t **dlip;
1315 dynlist_map_t *dlm_next;
1317 for ( i = 0, dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1320 if ( *dlip == NULL ) {
1323 dlip = &(*dlip)->dli_next;
1327 *dlip = dli->dli_next;
1329 if ( !BER_BVISNULL( &dli->dli_uri ) ) {
1330 ch_free( dli->dli_uri.bv_val );
1333 if ( dli->dli_lud != NULL ) {
1334 ldap_free_urldesc( dli->dli_lud );
1337 if ( !BER_BVISNULL( &dli->dli_uri_nbase ) ) {
1338 ber_memfree( dli->dli_uri_nbase.bv_val );
1341 if ( dli->dli_uri_filter != NULL ) {
1342 filter_free( dli->dli_uri_filter );
1345 ch_free( dli->dli_default_filter.bv_val );
1348 while ( dlm != NULL ) {
1349 dlm_next = dlm->dlm_next;
1355 dli = (dynlist_info_t *)on->on_bi.bi_private;
1359 case DL_ATTRPAIR_COMPAT:
1374 dynlist_info_t **dlip,
1376 ObjectClass *oc = NULL;
1377 AttributeDescription *ad = NULL;
1379 LDAPURLDesc *lud = NULL;
1380 struct berval nbase = BER_BVNULL;
1381 Filter *filter = NULL;
1382 struct berval uri = BER_BVNULL;
1383 dynlist_map_t *dlm = NULL, *dlml = NULL;
1386 oc = oc_find( c->argv[ 1 ] );
1388 snprintf( c->cr_msg, sizeof( c->cr_msg ), DYNLIST_USAGE
1389 "unable to find ObjectClass \"%s\"",
1391 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1392 c->log, c->cr_msg, 0 );
1396 if ( strncasecmp( c->argv[ attridx ], "ldap://", STRLENOF("ldap://") ) == 0 ) {
1397 if ( ldap_url_parse( c->argv[ attridx ], &lud ) != LDAP_URL_SUCCESS ) {
1398 snprintf( c->cr_msg, sizeof( c->cr_msg ), DYNLIST_USAGE
1399 "unable to parse URI \"%s\"",
1400 c->argv[ attridx ] );
1405 if ( lud->lud_host != NULL ) {
1406 if ( lud->lud_host[0] == '\0' ) {
1407 ch_free( lud->lud_host );
1408 lud->lud_host = NULL;
1411 snprintf( c->cr_msg, sizeof( c->cr_msg ), DYNLIST_USAGE
1412 "host not allowed in URI \"%s\"",
1413 c->argv[ attridx ] );
1419 if ( lud->lud_attrs != NULL ) {
1420 snprintf( c->cr_msg, sizeof( c->cr_msg ), DYNLIST_USAGE
1421 "attrs not allowed in URI \"%s\"",
1422 c->argv[ attridx ] );
1427 if ( lud->lud_exts != NULL ) {
1428 snprintf( c->cr_msg, sizeof( c->cr_msg ), DYNLIST_USAGE
1429 "extensions not allowed in URI \"%s\"",
1430 c->argv[ attridx ] );
1435 if ( lud->lud_dn != NULL && lud->lud_dn[ 0 ] != '\0' ) {
1437 ber_str2bv( lud->lud_dn, 0, 0, &dn );
1438 rc = dnNormalize( 0, NULL, NULL, &dn, &nbase, NULL );
1439 if ( rc != LDAP_SUCCESS ) {
1440 snprintf( c->cr_msg, sizeof( c->cr_msg ), DYNLIST_USAGE
1441 "DN normalization failed in URI \"%s\"",
1442 c->argv[ attridx ] );
1447 if ( lud->lud_filter != NULL && lud->lud_filter[ 0 ] != '\0' ) {
1448 filter = str2filter( lud->lud_filter );
1449 if ( filter == NULL ) {
1450 snprintf( c->cr_msg, sizeof( c->cr_msg ), DYNLIST_USAGE
1451 "filter parsing failed in URI \"%s\"",
1452 c->argv[ attridx ] );
1458 ber_str2bv( c->argv[ attridx ], 0, 1, &uri );
1463 ldap_free_urldesc( lud );
1466 if ( !BER_BVISNULL( &nbase ) ) {
1467 ber_memfree( nbase.bv_val );
1470 if ( filter != NULL ) {
1471 filter_free( filter );
1474 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1475 c->log, c->cr_msg, 0 );
1483 rc = slap_str2ad( c->argv[ attridx ], &ad, &text );
1484 if ( rc != LDAP_SUCCESS ) {
1485 snprintf( c->cr_msg, sizeof( c->cr_msg ), DYNLIST_USAGE
1486 "unable to find AttributeDescription \"%s\"",
1487 c->argv[ attridx ] );
1488 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1489 c->log, c->cr_msg, 0 );
1493 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
1494 snprintf( c->cr_msg, sizeof( c->cr_msg ), DYNLIST_USAGE
1495 "AttributeDescription \"%s\" "
1496 "must be a subtype of \"labeledURI\"",
1497 c->argv[ attridx ] );
1498 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1499 c->log, c->cr_msg, 0 );
1505 for ( i = attridx; i < c->argc; i++ ) {
1508 AttributeDescription *member_ad = NULL;
1509 AttributeDescription *mapped_ad = NULL;
1510 dynlist_map_t *dlmp;
1514 * If no mapped attribute is given, dn is used
1515 * for backward compatibility.
1518 if ( ( cp = strchr( arg, ':' ) ) != NULL ) {
1520 ber_str2bv( arg, cp - arg, 0, &bv );
1521 rc = slap_bv2ad( &bv, &mapped_ad, &text );
1522 if ( rc != LDAP_SUCCESS ) {
1523 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1525 "unable to find mapped AttributeDescription #%d \"%s\"\n",
1526 i - 3, c->argv[ i ] );
1527 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1528 c->log, c->cr_msg, 0 );
1534 rc = slap_str2ad( arg, &member_ad, &text );
1535 if ( rc != LDAP_SUCCESS ) {
1536 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1538 "unable to find AttributeDescription #%d \"%s\"\n",
1539 i - 3, c->argv[ i ] );
1540 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1541 c->log, c->cr_msg, 0 );
1545 dlmp = (dynlist_map_t *)ch_calloc( 1, sizeof( dynlist_map_t ) );
1546 if ( dlm == NULL ) {
1549 dlmp->dlm_member_ad = member_ad;
1550 dlmp->dlm_mapped_ad = mapped_ad;
1551 dlmp->dlm_next = NULL;
1554 dlml->dlm_next = dlmp;
1558 if ( c->valx > 0 ) {
1561 for ( i = 0, dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1564 if ( *dlip == NULL ) {
1565 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1567 "invalid index {%d}\n",
1569 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1570 c->log, c->cr_msg, 0 );
1573 dlip = &(*dlip)->dli_next;
1578 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1579 *dlip; dlip = &(*dlip)->dli_next )
1583 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
1585 (*dlip)->dli_oc = oc;
1586 (*dlip)->dli_ad = ad;
1587 (*dlip)->dli_dlm = dlm;
1588 (*dlip)->dli_next = dli_next;
1590 (*dlip)->dli_lud = lud;
1591 (*dlip)->dli_uri_nbase = nbase;
1592 (*dlip)->dli_uri_filter = filter;
1593 (*dlip)->dli_uri = uri;
1595 rc = dynlist_build_def_filter( *dlip );
1599 case DL_ATTRPAIR_COMPAT:
1600 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1601 "warning: \"attrpair\" only supported for limited "
1602 "backward compatibility with overlay \"dyngroup\"" );
1603 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
1607 dynlist_info_t **dlip;
1608 ObjectClass *oc = NULL;
1609 AttributeDescription *ad = NULL,
1613 oc = oc_find( "groupOfURLs" );
1615 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1616 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1617 "unable to find default ObjectClass \"groupOfURLs\"" );
1618 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1619 c->log, c->cr_msg, 0 );
1623 rc = slap_str2ad( c->argv[ 1 ], &member_ad, &text );
1624 if ( rc != LDAP_SUCCESS ) {
1625 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1626 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1627 "unable to find AttributeDescription \"%s\"",
1629 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1630 c->log, c->cr_msg, 0 );
1634 rc = slap_str2ad( c->argv[ 2 ], &ad, &text );
1635 if ( rc != LDAP_SUCCESS ) {
1636 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1637 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1638 "unable to find AttributeDescription \"%s\"\n",
1640 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1641 c->log, c->cr_msg, 0 );
1645 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
1646 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1648 "AttributeDescription \"%s\" "
1649 "must be a subtype of \"labeledURI\"",
1651 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1652 c->log, c->cr_msg, 0 );
1656 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1657 *dlip; dlip = &(*dlip)->dli_next )
1660 * The same URL attribute / member attribute pair
1661 * cannot be repeated, but we enforce this only
1662 * when the member attribute is unique. Performing
1663 * the check for multiple values would require
1664 * sorting and comparing the lists, which is left
1665 * as a future improvement
1667 if ( (*dlip)->dli_ad == ad &&
1668 (*dlip)->dli_dlm->dlm_next == NULL &&
1669 member_ad == (*dlip)->dli_dlm->dlm_member_ad ) {
1670 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1671 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1672 "URL attributeDescription \"%s\" already mapped.\n",
1673 ad->ad_cname.bv_val );
1674 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1675 c->log, c->cr_msg, 0 );
1677 /* make it a warning... */
1683 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
1685 (*dlip)->dli_oc = oc;
1686 (*dlip)->dli_ad = ad;
1687 (*dlip)->dli_dlm = (dynlist_map_t *)ch_calloc( 1, sizeof( dynlist_map_t ) );
1688 (*dlip)->dli_dlm->dlm_member_ad = member_ad;
1689 (*dlip)->dli_dlm->dlm_mapped_ad = NULL;
1691 rc = dynlist_build_def_filter( *dlip );
1709 slap_overinst *on = (slap_overinst *) be->bd_info;
1710 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private;
1711 ObjectClass *oc = NULL;
1712 AttributeDescription *ad = NULL;
1716 if ( dli == NULL ) {
1717 dli = ch_calloc( 1, sizeof( dynlist_info_t ) );
1718 on->on_bi.bi_private = (void *)dli;
1721 for ( ; dli; dli = dli->dli_next ) {
1722 if ( dli->dli_oc == NULL ) {
1724 oc = oc_find( "groupOfURLs" );
1726 snprintf( cr->msg, sizeof( cr->msg),
1727 "unable to fetch objectClass \"groupOfURLs\"" );
1728 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: %s.\n", cr->msg, 0, 0 );
1736 if ( dli->dli_ad == NULL ) {
1738 rc = slap_str2ad( "memberURL", &ad, &text );
1739 if ( rc != LDAP_SUCCESS ) {
1740 snprintf( cr->msg, sizeof( cr->msg),
1741 "unable to fetch attributeDescription \"memberURL\": %d (%s)",
1743 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: %s.\n", cr->msg, 0, 0 );
1751 if ( BER_BVISNULL( &dli->dli_default_filter ) ) {
1752 rc = dynlist_build_def_filter( dli );
1759 if ( ad_dgIdentity == NULL ) {
1760 rc = slap_str2ad( "dgIdentity", &ad_dgIdentity, &text );
1761 if ( rc != LDAP_SUCCESS ) {
1762 snprintf( cr->msg, sizeof( cr->msg),
1763 "unable to fetch attributeDescription \"dgIdentity\": %d (%s)",
1765 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: %s\n", cr->msg, 0, 0 );
1766 /* Just a warning */
1770 if ( ad_dgAuthz == NULL ) {
1771 rc = slap_str2ad( "dgAuthz", &ad_dgAuthz, &text );
1772 if ( rc != LDAP_SUCCESS ) {
1773 snprintf( cr->msg, sizeof( cr->msg),
1774 "unable to fetch attributeDescription \"dgAuthz\": %d (%s)",
1776 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: %s\n", cr->msg, 0, 0 );
1777 /* Just a warning */
1789 slap_overinst *on = (slap_overinst *) be->bd_info;
1791 if ( on->on_bi.bi_private ) {
1792 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private,
1795 for ( dli_next = dli; dli_next; dli = dli_next ) {
1797 dynlist_map_t *dlm_next;
1799 dli_next = dli->dli_next;
1801 if ( !BER_BVISNULL( &dli->dli_uri ) ) {
1802 ch_free( dli->dli_uri.bv_val );
1805 if ( dli->dli_lud != NULL ) {
1806 ldap_free_urldesc( dli->dli_lud );
1809 if ( !BER_BVISNULL( &dli->dli_uri_nbase ) ) {
1810 ber_memfree( dli->dli_uri_nbase.bv_val );
1813 if ( dli->dli_uri_filter != NULL ) {
1814 filter_free( dli->dli_uri_filter );
1817 ch_free( dli->dli_default_filter.bv_val );
1820 while ( dlm != NULL ) {
1821 dlm_next = dlm->dlm_next;
1832 static slap_overinst dynlist = { { NULL } };
1833 #ifdef TAKEOVER_DYNGROUP
1834 static char *obsolete_names[] = {
1840 #if SLAPD_OVER_DYNLIST == SLAPD_MOD_DYNAMIC
1842 #endif /* SLAPD_OVER_DYNLIST == SLAPD_MOD_DYNAMIC */
1844 dynlist_initialize(void)
1846 #ifndef OL_2_2_COMPAT
1850 dynlist.on_bi.bi_type = "dynlist";
1852 #ifdef TAKEOVER_DYNGROUP
1853 /* makes dynlist incompatible with dyngroup */
1854 dynlist.on_bi.bi_obsolete_names = obsolete_names;
1857 #ifdef OL_2_2_COMPAT
1858 dynlist.on_bi.bi_db_config = dynlist_db_config;
1860 dynlist.on_bi.bi_db_config = config_generic_wrapper;
1862 dynlist.on_bi.bi_db_open = dynlist_db_open;
1863 dynlist.on_bi.bi_db_destroy = dynlist_db_destroy;
1865 dynlist.on_response = dynlist_response;
1867 #ifndef OL_2_2_COMPAT
1868 dynlist.on_bi.bi_cf_ocs = dlocs;
1870 rc = config_register_schema( dlcfg, dlocs );
1876 return overlay_register( &dynlist );
1879 #if SLAPD_OVER_DYNLIST == SLAPD_MOD_DYNAMIC
1881 init_module( int argc, char *argv[] )
1883 return dynlist_initialize();
1887 #endif /* SLAPD_OVER_DYNLIST */