1 /* dynlist.c - dynamic list overlay */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2003-2007 The OpenLDAP Foundation.
6 * Portions Copyright 2004-2005 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>.
18 * This work was initially developed by Pierangelo Masarati
19 * for SysNet s.n.c., for inclusion in OpenLDAP Software.
24 #ifdef SLAPD_OVER_DYNLIST
26 #if LDAP_VENDOR_VERSION_MINOR == X || LDAP_VENDOR_VERSION_MINOR > 3
27 #if SLAPD_OVER_DYNGROUP != SLAPD_MOD_STATIC
28 #define TAKEOVER_DYNGROUP
31 #if LDAP_VENDOR_VERSION_MINOR < 3
38 #include <ac/string.h>
46 /* FIXME: the code differs if SLAP_OPATTRS is defined or not;
47 * SLAP_OPATTRS is not defined in 2.2 yet, while this overlay
48 * expects HEAD code at least later than August 6, 2004. */
49 /* FIXME: slap_anlist_no_attrs was introduced in 2.3; here it
50 * is anticipated to allow using this overlay with 2.2. */
53 static AttributeName anlist_no_attrs[] = {
54 { BER_BVC( LDAP_NO_ATTRS ), NULL, 0, NULL },
55 { BER_BVNULL, NULL, 0, NULL }
58 static AttributeName *slap_anlist_no_attrs = anlist_no_attrs;
61 static AttributeDescription *ad_dgIdentity;
63 typedef struct dynlist_info_t {
65 AttributeDescription *dli_ad;
66 AttributeDescription *dli_member_ad;
67 struct berval dli_default_filter;
68 struct dynlist_info_t *dli_next;
71 static dynlist_info_t *
72 dynlist_is_dynlist_next( Operation *op, SlapReply *rs, dynlist_info_t *old_dli )
74 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
79 if ( old_dli == NULL ) {
80 dli = (dynlist_info_t *)on->on_bi.bi_private;
83 dli = old_dli->dli_next;
86 a = attrs_find( rs->sr_entry->e_attrs, slap_schema.si_ad_objectClass );
88 /* FIXME: objectClass must be present; for non-storage
89 * backends, like back-ldap, it needs to be added
90 * to the requested attributes */
94 for ( ; dli; dli = dli->dli_next ) {
96 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
97 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
98 &dli->dli_oc->soc_cname, NULL,
99 op->o_tmpmemctx ) == 0 )
109 dynlist_make_filter( Operation *op, struct berval *oldf, struct berval *newf )
111 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
112 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private;
116 assert( oldf != NULL );
117 assert( newf != NULL );
118 assert( !BER_BVISNULL( oldf ) );
119 assert( !BER_BVISEMPTY( oldf ) );
121 newf->bv_len = STRLENOF( "(&(!(objectClass=" "))" ")" )
122 + dli->dli_oc->soc_cname.bv_len + oldf->bv_len;
123 newf->bv_val = op->o_tmpalloc( newf->bv_len + 1, op->o_tmpmemctx );
124 if ( newf->bv_val == NULL ) {
127 ptr = lutil_strcopy( newf->bv_val, "(&(!(objectClass=" );
128 ptr = lutil_strcopy( ptr, dli->dli_oc->soc_cname.bv_val );
129 ptr = lutil_strcopy( ptr, "))" );
130 ptr = lutil_strcopy( ptr, oldf->bv_val );
131 ptr = lutil_strcopy( ptr, ")" );
132 newf->bv_len = ptr - newf->bv_val;
137 typedef struct dynlist_sc_t {
138 dynlist_info_t *dlc_dli;
143 dynlist_sc_update( Operation *op, SlapReply *rs )
149 AccessControlState acl_state = ACL_STATE_INIT;
153 if ( rs->sr_type != REP_SEARCH ) {
157 dlc = (dynlist_sc_t *)op->o_callback->sc_private;
161 assert( rs->sr_entry != NULL );
163 /* test access to entry */
164 if ( !access_allowed( op, rs->sr_entry, slap_schema.si_ad_entry,
165 NULL, ACL_READ, NULL ) )
170 if ( dlc->dlc_dli->dli_member_ad ) {
172 /* if access allowed, try to add values, emulating permissive
173 * control to silently ignore duplicates */
174 if ( access_allowed( op, rs->sr_entry, slap_schema.si_ad_entry,
175 NULL, ACL_READ, NULL ) )
178 const char *text = NULL;
180 struct berval vals[ 2 ], nvals[ 2 ];
182 vals[ 0 ] = rs->sr_entry->e_name;
183 BER_BVZERO( &vals[ 1 ] );
184 nvals[ 0 ] = rs->sr_entry->e_nname;
185 BER_BVZERO( &nvals[ 1 ] );
187 mod.sm_op = LDAP_MOD_ADD;
188 mod.sm_desc = dlc->dlc_dli->dli_member_ad;
189 mod.sm_type = dlc->dlc_dli->dli_member_ad->ad_cname;
190 mod.sm_values = vals;
191 mod.sm_nvalues = nvals;
194 (void)modify_add_values( e, &mod, /* permissive */ 1,
195 &text, textbuf, sizeof( textbuf ) );
202 opattrs = ( rs->sr_attrs == NULL ) ? 0 : an_find( rs->sr_attrs, &AllOper );
203 userattrs = ( rs->sr_attrs == NULL ) ? 1 : an_find( rs->sr_attrs, &AllUser );
204 #else /* SLAP_OPATTRS */
205 opattrs = SLAP_OPATTRS( rs->sr_attr_flags );
206 userattrs = SLAP_USERATTRS( rs->sr_attr_flags );
207 #endif /* SLAP_OPATTRS */
209 for ( a = rs->sr_entry->e_attrs; a != NULL; a = a->a_next ) {
210 BerVarray vals, nvals = NULL;
212 is_oc = a->a_desc == slap_schema.si_ad_objectClass;
214 /* if attribute is not requested, skip it */
215 if ( rs->sr_attrs == NULL ) {
216 if ( is_at_operational( a->a_desc->ad_type ) ) {
221 if ( is_at_operational( a->a_desc->ad_type ) ) {
222 if ( !opattrs && !ad_inlist( a->a_desc, rs->sr_attrs ) )
228 if ( !userattrs && !ad_inlist( a->a_desc, rs->sr_attrs ) )
235 /* test access to attribute */
236 if ( op->ors_attrsonly ) {
237 if ( !access_allowed( op, rs->sr_entry, a->a_desc, NULL,
238 ACL_READ, &acl_state ) )
244 /* single-value check: keep first only */
245 if ( is_at_single_value( a->a_desc->ad_type ) ) {
246 if ( attr_find( e->e_attrs, a->a_desc ) != NULL ) {
251 /* test access to attribute */
254 vals = op->o_tmpalloc( ( i + 1 ) * sizeof( struct berval ), op->o_tmpmemctx );
255 if ( a->a_nvals != a->a_vals ) {
256 nvals = op->o_tmpalloc( ( i + 1 ) * sizeof( struct berval ), op->o_tmpmemctx );
259 for ( i = 0, j = 0; !BER_BVISNULL( &a->a_vals[i] ); i++ ) {
261 ObjectClass *soc = oc_bvfind( &a->a_vals[i] );
263 if ( soc->soc_kind == LDAP_SCHEMA_STRUCTURAL ) {
268 if ( access_allowed( op, rs->sr_entry, a->a_desc,
269 &a->a_nvals[i], ACL_READ, &acl_state ) )
271 vals[j] = a->a_vals[i];
273 nvals[j] = a->a_nvals[i];
279 /* if access allowed, try to add values, emulating permissive
280 * control to silently ignore duplicates */
283 const char *text = NULL;
286 BER_BVZERO( &vals[j] );
288 BER_BVZERO( &nvals[j] );
291 mod.sm_op = LDAP_MOD_ADD;
292 mod.sm_desc = a->a_desc;
293 mod.sm_type = a->a_desc->ad_cname;
294 mod.sm_values = vals;
295 mod.sm_nvalues = nvals;
298 (void)modify_add_values( e, &mod, /* permissive */ 1,
299 &text, textbuf, sizeof( textbuf ) );
302 op->o_tmpfree( vals, op->o_tmpmemctx );
304 op->o_tmpfree( nvals, op->o_tmpmemctx );
309 if ( rs->sr_flags & REP_ENTRY_MUSTBEFREED ) {
310 entry_free( rs->sr_entry );
312 rs->sr_flags ^= REP_ENTRY_MUSTBEFREED;
319 dynlist_prepare_entry( Operation *op, SlapReply *rs, dynlist_info_t *dli )
321 Attribute *a, *id = NULL;
324 SlapReply r = { REP_SEARCH };
330 dynlist_sc_t dlc = { 0 };
332 a = attrs_find( rs->sr_entry->e_attrs, dli->dli_ad );
335 return SLAP_CB_CONTINUE;
339 opattrs = ( rs->sr_attrs == NULL ) ? 0 : an_find( rs->sr_attrs, &AllOper );
340 userattrs = ( rs->sr_attrs == NULL ) ? 1 : an_find( rs->sr_attrs, &AllUser );
341 #else /* SLAP_OPATTRS */
342 opattrs = SLAP_OPATTRS( rs->sr_attr_flags );
343 userattrs = SLAP_USERATTRS( rs->sr_attr_flags );
344 #endif /* SLAP_OPATTRS */
346 /* Don't generate member list if it wasn't requested */
347 if ( dli->dli_member_ad && !userattrs && !ad_inlist( dli->dli_member_ad, rs->sr_attrs ) ) {
348 return SLAP_CB_CONTINUE;
351 if ( !( rs->sr_flags & REP_ENTRY_MODIFIABLE ) ) {
352 e = entry_dup( rs->sr_entry );
356 e_flags = rs->sr_flags | ( REP_ENTRY_MODIFIABLE | REP_ENTRY_MUSTBEFREED );
358 if ( ad_dgIdentity && ( id = attrs_find( e->e_attrs, ad_dgIdentity ))) {
359 o.o_dn = id->a_vals[0];
360 o.o_ndn = id->a_nvals[0];
366 cb.sc_private = &dlc;
367 cb.sc_response = dynlist_sc_update;
368 cb.sc_cleanup = NULL;
372 o.ors_deref = LDAP_DEREF_NEVER;
374 o.ors_tlimit = SLAP_NO_LIMIT;
375 o.ors_slimit = SLAP_NO_LIMIT;
377 for ( url = a->a_nvals; !BER_BVISNULL( url ); url++ ) {
378 LDAPURLDesc *lud = NULL;
383 BER_BVZERO( &o.o_req_dn );
384 BER_BVZERO( &o.o_req_ndn );
387 BER_BVZERO( &o.ors_filterstr );
389 if ( ldap_url_parse( url->bv_val, &lud ) != LDAP_URL_SUCCESS ) {
394 if ( lud->lud_host != NULL ) {
395 /* FIXME: host not allowed; reject as illegal? */
396 Debug( LDAP_DEBUG_ANY, "dynlist_prepare_entry(\"%s\"): "
397 "illegal URI \"%s\"\n",
398 e->e_name.bv_val, url->bv_val, 0 );
402 if ( lud->lud_dn == NULL ) {
403 /* note that an empty base is not honored in terms
404 * of defaultSearchBase, because select_backend()
405 * is not aware of the defaultSearchBase option;
406 * this can be useful in case of a database serving
407 * the empty suffix */
408 BER_BVSTR( &dn, "" );
411 ber_str2bv( lud->lud_dn, 0, 0, &dn );
413 rc = dnPrettyNormal( NULL, &dn, &o.o_req_dn, &o.o_req_ndn, op->o_tmpmemctx );
414 if ( rc != LDAP_SUCCESS ) {
418 o.ors_scope = lud->lud_scope;
420 if ( dli->dli_member_ad != NULL ) {
421 /* if ( lud->lud_attrs != NULL ),
422 * the URL should be ignored */
423 o.ors_attrs = slap_anlist_no_attrs;
425 } else if ( lud->lud_attrs == NULL ) {
426 o.ors_attrs = rs->sr_attrs;
429 for ( i = 0; lud->lud_attrs[i]; i++)
432 o.ors_attrs = op->o_tmpcalloc( i + 1, sizeof( AttributeName ), op->o_tmpmemctx );
433 for ( i = 0, j = 0; lud->lud_attrs[i]; i++) {
434 const char *text = NULL;
436 ber_str2bv( lud->lud_attrs[i], 0, 0, &o.ors_attrs[j].an_name );
437 o.ors_attrs[j].an_desc = NULL;
438 (void)slap_bv2ad( &o.ors_attrs[j].an_name, &o.ors_attrs[j].an_desc, &text );
439 /* FIXME: ignore errors... */
441 if ( rs->sr_attrs == NULL ) {
442 if ( o.ors_attrs[j].an_desc != NULL &&
443 is_at_operational( o.ors_attrs[j].an_desc->ad_type ) )
449 if ( o.ors_attrs[j].an_desc != NULL &&
450 is_at_operational( o.ors_attrs[j].an_desc->ad_type ) )
452 if ( !opattrs && !ad_inlist( o.ors_attrs[j].an_desc, rs->sr_attrs ) )
459 o.ors_attrs[j].an_desc != NULL &&
460 !ad_inlist( o.ors_attrs[j].an_desc, rs->sr_attrs ) )
474 BER_BVZERO( &o.ors_attrs[j].an_name );
477 if ( lud->lud_filter == NULL ) {
478 ber_dupbv_x( &o.ors_filterstr,
479 &dli->dli_default_filter, op->o_tmpmemctx );
483 ber_str2bv( lud->lud_filter, 0, 0, &flt );
484 if ( dynlist_make_filter( op, &flt, &o.ors_filterstr ) ) {
489 o.ors_filter = str2filter_x( op, o.ors_filterstr.bv_val );
490 if ( o.ors_filter == NULL ) {
494 o.o_bd = select_backend( &o.o_req_ndn, 1 );
495 if ( o.o_bd && o.o_bd->be_search ) {
497 r.sr_attr_flags = slap_attr_flags( o.ors_attrs );
498 #endif /* SLAP_OPATTRS */
499 (void)o.o_bd->be_search( &o, &r );
504 slap_op_groups_free( &o );
506 if ( o.ors_filter ) {
507 filter_free_x( &o, o.ors_filter );
509 if ( o.ors_attrs && o.ors_attrs != rs->sr_attrs
510 && o.ors_attrs != slap_anlist_no_attrs )
512 op->o_tmpfree( o.ors_attrs, op->o_tmpmemctx );
514 if ( !BER_BVISNULL( &o.o_req_dn ) ) {
515 op->o_tmpfree( o.o_req_dn.bv_val, op->o_tmpmemctx );
517 if ( !BER_BVISNULL( &o.o_req_ndn ) ) {
518 op->o_tmpfree( o.o_req_ndn.bv_val, op->o_tmpmemctx );
520 assert( BER_BVISNULL( &o.ors_filterstr )
521 || o.ors_filterstr.bv_val != lud->lud_filter );
522 op->o_tmpfree( o.ors_filterstr.bv_val, op->o_tmpmemctx );
523 ldap_free_urldesc( lud );
527 rs->sr_flags = e_flags;
529 return SLAP_CB_CONTINUE;
533 dynlist_sc_save_entry( Operation *op, SlapReply *rs )
535 /* save the entry in the private field of the callback,
536 * so it doesn't get freed (it's temporary!) */
537 if ( rs->sr_entry != NULL ) {
538 dynlist_sc_t *dlc = (dynlist_sc_t *)op->o_callback->sc_private;
539 dlc->dlc_e = rs->sr_entry;
547 dynlist_compare( Operation *op, SlapReply *rs )
549 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
550 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private;
554 for ( ; dli != NULL; dli = dli->dli_next ) {
555 if ( op->oq_compare.rs_ava->aa_desc == dli->dli_member_ad ) {
556 /* This compare is for one of the attributes we're
557 * interested in. We'll use slapd's existing dyngroup
558 * evaluator to get the answer we want.
560 struct berval *id = NULL;
562 o.o_do_not_cache = 1;
564 if ( ad_dgIdentity && backend_attribute( &o, NULL, &o.o_req_ndn,
565 ad_dgIdentity, &id, ACL_READ ) == LDAP_SUCCESS ) {
568 o.o_groups = NULL; /* authz changed, invalidate cached groups */
570 rs->sr_err = backend_group( &o, NULL, &o.o_req_ndn,
571 &o.oq_compare.rs_ava->aa_value, dli->dli_oc, dli->dli_ad );
572 switch ( rs->sr_err ) {
574 rs->sr_err = LDAP_COMPARE_TRUE;
577 case LDAP_NO_SUCH_OBJECT:
578 /* NOTE: backend_group() returns noSuchObject
579 * if op_ndn does not exist; however, since
580 * dynamic list expansion means that the
581 * member attribute is virtually present, the
582 * non-existence of the asserted value implies
583 * the assertion is FALSE rather than
585 rs->sr_err = LDAP_COMPARE_FALSE;
589 if ( id ) ber_bvarray_free_x( id, o.o_tmpmemctx );
591 return SLAP_CB_CONTINUE;
595 if ( overlay_entry_get_ov( &o, &o.o_req_ndn, NULL, NULL, 0, &e, on ) !=
596 LDAP_SUCCESS || e == NULL ) {
597 return SLAP_CB_CONTINUE;
599 if ( ad_dgIdentity ) {
600 Attribute *id = attrs_find( e->e_attrs, ad_dgIdentity );
602 o.o_dn = id->a_vals[0];
603 o.o_ndn = id->a_nvals[0];
607 dli = (dynlist_info_t *)on->on_bi.bi_private;
608 for ( ; dli != NULL && rs->sr_err != LDAP_COMPARE_TRUE; dli = dli->dli_next ) {
611 SlapReply r = { REP_SEARCH };
614 dynlist_sc_t dlc = { 0 };
616 if ( !is_entry_objectclass_or_sub( e, dli->dli_oc ))
619 /* if the entry has the right objectClass, generate
620 * the dynamic list and compare */
622 cb.sc_private = &dlc;
623 cb.sc_response = dynlist_sc_save_entry;
624 cb.sc_cleanup = NULL;
628 o.o_tag = LDAP_REQ_SEARCH;
630 o.ors_tlimit = SLAP_NO_LIMIT;
631 o.ors_slimit = SLAP_NO_LIMIT;
633 o.o_bd = select_backend( &o.o_req_ndn, 1 );
634 if ( !o.o_bd || !o.o_bd->be_search ) {
638 o.ors_filterstr = *slap_filterstr_objectClass_pres;
639 o.ors_filter = (Filter *) slap_filter_objectClass_pres;
641 o.ors_scope = LDAP_SCOPE_BASE;
642 o.ors_deref = LDAP_DEREF_NEVER;
643 an[0].an_name = op->orc_ava->aa_desc->ad_cname;
644 an[0].an_desc = op->orc_ava->aa_desc;
645 BER_BVZERO( &an[1].an_name );
649 o.o_acl_priv = ACL_COMPARE;
651 rc = o.o_bd->be_search( &o, &r );
653 if ( o.o_dn.bv_val != op->o_dn.bv_val ) {
654 slap_op_groups_free( &o );
661 if ( dlc.dlc_e != NULL ) {
662 r.sr_entry = dlc.dlc_e;
665 if ( r.sr_err != LDAP_SUCCESS || r.sr_entry == NULL ) {
670 for ( a = attrs_find( r.sr_entry->e_attrs, op->orc_ava->aa_desc );
672 a = attrs_find( a->a_next, op->orc_ava->aa_desc ) )
674 /* if we're here, we got a match... */
675 rs->sr_err = LDAP_COMPARE_FALSE;
677 if ( attr_valfind( a,
678 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
679 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
680 &op->orc_ava->aa_value, NULL, op->o_tmpmemctx ) == 0 )
682 rs->sr_err = LDAP_COMPARE_TRUE;
687 if ( r.sr_flags & REP_ENTRY_MUSTBEFREED ) {
688 entry_free( r.sr_entry );
694 overlay_entry_release_ov( &o, e, 0, on );
697 return SLAP_CB_CONTINUE;
701 dynlist_response( Operation *op, SlapReply *rs )
705 switch ( op->o_tag ) {
706 case LDAP_REQ_SEARCH:
707 if ( rs->sr_type == REP_SEARCH && !get_manageDSAit( op ) )
711 for ( dli = dynlist_is_dynlist_next( op, rs, NULL );
713 dli = dynlist_is_dynlist_next( op, rs, dli ) )
715 rc = dynlist_prepare_entry( op, rs, dli );
718 if ( rc != LDAP_OTHER ) {
724 case LDAP_REQ_COMPARE:
725 switch ( rs->sr_err ) {
726 /* NOTE: we waste a few cycles running the dynamic list
727 * also when the result is FALSE, which occurs if the
728 * dynamic entry itself contains the AVA attribute */
729 /* FIXME: this approach is less than optimal; a dedicated
730 * compare op should be implemented, that fetches the
731 * entry, checks if it has the appropriate objectClass
732 * and, in case, runs a compare thru all the URIs,
733 * stopping at the first positive occurrence; see ITS#3756 */
734 case LDAP_COMPARE_FALSE:
735 case LDAP_NO_SUCH_ATTRIBUTE:
736 return dynlist_compare( op, rs );
744 return SLAP_CB_CONTINUE;
748 dynlist_build_def_filter( dynlist_info_t *dli )
752 dli->dli_default_filter.bv_len = STRLENOF( "(!(objectClass=" "))" )
753 + dli->dli_oc->soc_cname.bv_len;
754 dli->dli_default_filter.bv_val = ch_malloc( dli->dli_default_filter.bv_len + 1 );
755 if ( dli->dli_default_filter.bv_val == NULL ) {
756 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: malloc failed.\n",
761 ptr = lutil_strcopy( dli->dli_default_filter.bv_val, "(!(objectClass=" );
762 ptr = lutil_strcopy( ptr, dli->dli_oc->soc_cname.bv_val );
763 ptr = lutil_strcopy( ptr, "))" );
765 assert( dli->dli_default_filter.bv_len == ptr - dli->dli_default_filter.bv_val );
779 slap_overinst *on = (slap_overinst *)be->bd_info;
783 if ( strcasecmp( argv[0], "dynlist-attrset" ) == 0 ) {
784 dynlist_info_t **dlip;
786 AttributeDescription *ad = NULL,
790 if ( argc < 3 || argc > 4 ) {
791 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
792 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
793 "invalid arg number #%d.\n",
794 fname, lineno, argc );
798 oc = oc_find( argv[1] );
800 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
801 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
802 "unable to find ObjectClass \"%s\"\n",
803 fname, lineno, argv[ 1 ] );
807 rc = slap_str2ad( argv[2], &ad, &text );
808 if ( rc != LDAP_SUCCESS ) {
809 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
810 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
811 "unable to find AttributeDescription \"%s\"\n",
812 fname, lineno, argv[2] );
816 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
817 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
818 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
819 "AttributeDescription \"%s\" "
820 "must be a subtype of \"labeledURI\"\n",
821 fname, lineno, argv[2] );
826 rc = slap_str2ad( argv[3], &member_ad, &text );
827 if ( rc != LDAP_SUCCESS ) {
828 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
829 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
830 "unable to find AttributeDescription \"%s\"\n",
831 fname, lineno, argv[3] );
836 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
837 *dlip; dlip = &(*dlip)->dli_next )
839 /* The same URL attribute / member attribute pair
840 * cannot be repeated */
841 if ( (*dlip)->dli_ad == ad && (*dlip)->dli_member_ad == member_ad ) {
842 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
843 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
844 "URL attributeDescription \"%s\" already mapped.\n",
845 fname, lineno, ad->ad_cname.bv_val );
847 /* make it a warning... */
853 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
854 (*dlip)->dli_oc = oc;
855 (*dlip)->dli_ad = ad;
856 (*dlip)->dli_member_ad = member_ad;
858 if ( dynlist_build_def_filter( *dlip ) ) {
864 /* allow dyngroup syntax */
865 } else if ( strcasecmp( argv[0], "dynlist-attrpair" ) == 0 ) {
866 dynlist_info_t **dlip;
868 AttributeDescription *ad = NULL,
873 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
874 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
875 "invalid arg number #%d.\n",
876 fname, lineno, argc );
880 oc = oc_find( "groupOfURLs" );
882 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
883 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
884 "unable to find default ObjectClass \"groupOfURLs\"\n",
889 rc = slap_str2ad( argv[1], &member_ad, &text );
890 if ( rc != LDAP_SUCCESS ) {
891 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
892 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
893 "unable to find AttributeDescription \"%s\"\n",
894 fname, lineno, argv[1] );
898 rc = slap_str2ad( argv[2], &ad, &text );
899 if ( rc != LDAP_SUCCESS ) {
900 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
901 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
902 "unable to find AttributeDescription \"%s\"\n",
903 fname, lineno, argv[2] );
907 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
908 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
909 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
910 "AttributeDescription \"%s\" "
911 "must be a subtype of \"labeledURI\"\n",
912 fname, lineno, argv[2] );
916 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
917 *dlip; dlip = &(*dlip)->dli_next )
919 /* The same URL attribute / member attribute pair
920 * cannot be repeated */
921 if ( (*dlip)->dli_ad == ad && (*dlip)->dli_member_ad == member_ad ) {
922 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
923 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
924 "URL attributeDescription \"%s\" already mapped.\n",
925 fname, lineno, ad->ad_cname.bv_val );
927 /* make it a warning... */
933 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
934 (*dlip)->dli_oc = oc;
935 (*dlip)->dli_ad = ad;
936 (*dlip)->dli_member_ad = member_ad;
938 if ( dynlist_build_def_filter( *dlip ) ) {
945 rc = SLAP_CONF_UNKNOWN;
959 static ConfigDriver dl_cfgen;
961 static ConfigTable dlcfg[] = {
962 { "dynlist-attrset", "group-oc> <URL-ad> <member-ad",
963 3, 4, 0, ARG_MAGIC|DL_ATTRSET, dl_cfgen,
964 "( OLcfgOvAt:8.1 NAME 'olcDLattrSet' "
965 "DESC 'Dynamic list: <group objectClass>, <URL attributeDescription>, <member attributeDescription>' "
966 "EQUALITY caseIgnoreMatch "
967 "SYNTAX OMsDirectoryString "
968 "X-ORDERED 'VALUES' )",
970 { "dynlist-attrpair", "member-ad> <URL-ad",
971 3, 3, 0, ARG_MAGIC|DL_ATTRPAIR, dl_cfgen,
973 #ifdef TAKEOVER_DYNGROUP
974 { "attrpair", "member-ad> <URL-ad",
975 3, 3, 0, ARG_MAGIC|DL_ATTRPAIR_COMPAT, dl_cfgen,
978 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
981 static ConfigOCs dlocs[] = {
983 "NAME 'olcDynamicList' "
984 "DESC 'Dynamic list configuration' "
985 "SUP olcOverlayConfig "
986 "MAY olcDLattrSet )",
987 Cft_Overlay, dlcfg, NULL, NULL },
992 dl_cfgen( ConfigArgs *c )
994 slap_overinst *on = (slap_overinst *)c->bi;
995 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private;
999 if ( c->op == SLAP_CONFIG_EMIT ) {
1002 for ( i = 0; dli; i++, dli = dli->dli_next ) {
1004 char *ptr = c->cr_msg;
1006 assert( dli->dli_oc != NULL );
1007 assert( dli->dli_ad != NULL );
1009 ptr += snprintf( c->cr_msg, sizeof( c->cr_msg ),
1010 SLAP_X_ORDERED_FMT "%s %s", i,
1011 dli->dli_oc->soc_cname.bv_val,
1012 dli->dli_ad->ad_cname.bv_val );
1014 if ( dli->dli_member_ad != NULL ) {
1017 ptr = lutil_strcopy( ptr, dli->dli_member_ad->ad_cname.bv_val );
1020 bv.bv_val = c->cr_msg;
1021 bv.bv_len = ptr - bv.bv_val;
1022 value_add_one( &c->rvalue_vals, &bv );
1026 case DL_ATTRPAIR_COMPAT:
1038 } else if ( c->op == LDAP_MOD_DELETE ) {
1041 if ( c->valx < 0 ) {
1042 dynlist_info_t *dli_next;
1044 for ( dli_next = dli; dli_next; dli = dli_next ) {
1045 dli_next = dli->dli_next;
1047 ch_free( dli->dli_default_filter.bv_val );
1051 on->on_bi.bi_private = NULL;
1054 dynlist_info_t **dlip;
1056 for ( i = 0, dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1059 if ( *dlip == NULL ) {
1062 dlip = &(*dlip)->dli_next;
1066 *dlip = dli->dli_next;
1067 ch_free( dli->dli_default_filter.bv_val );
1070 dli = (dynlist_info_t *)on->on_bi.bi_private;
1074 case DL_ATTRPAIR_COMPAT:
1089 dynlist_info_t **dlip,
1091 ObjectClass *oc = NULL;
1092 AttributeDescription *ad = NULL,
1096 oc = oc_find( c->argv[ 1 ] );
1098 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1099 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1100 "unable to find ObjectClass \"%s\"",
1102 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1103 c->log, c->cr_msg, 0 );
1107 rc = slap_str2ad( c->argv[ 2 ], &ad, &text );
1108 if ( rc != LDAP_SUCCESS ) {
1109 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1110 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1111 "unable to find AttributeDescription \"%s\"",
1113 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1114 c->log, c->cr_msg, 0 );
1118 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
1119 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1120 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1121 "AttributeDescription \"%s\" "
1122 "must be a subtype of \"labeledURI\"",
1124 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1125 c->log, c->cr_msg, 0 );
1129 if ( c->argc == 4 ) {
1130 rc = slap_str2ad( c->argv[ 3 ], &member_ad, &text );
1131 if ( rc != LDAP_SUCCESS ) {
1132 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1133 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1134 "unable to find AttributeDescription \"%s\"\n",
1136 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1137 c->log, c->cr_msg, 0 );
1142 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1143 *dlip; dlip = &(*dlip)->dli_next )
1145 /* The same URL attribute / member attribute pair
1146 * cannot be repeated */
1147 if ( (*dlip)->dli_ad == ad && (*dlip)->dli_member_ad == member_ad ) {
1148 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1149 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1150 "URL attributeDescription \"%s\" already mapped.\n",
1151 ad->ad_cname.bv_val );
1152 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1153 c->log, c->cr_msg, 0 );
1155 /* make it a warning... */
1161 if ( c->valx > 0 ) {
1164 for ( i = 0, dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1167 if ( *dlip == NULL ) {
1168 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1169 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1170 "invalid index {%d}\n",
1172 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1173 c->log, c->cr_msg, 0 );
1176 dlip = &(*dlip)->dli_next;
1181 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1182 *dlip; dlip = &(*dlip)->dli_next )
1186 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
1188 (*dlip)->dli_oc = oc;
1189 (*dlip)->dli_ad = ad;
1190 (*dlip)->dli_member_ad = member_ad;
1191 (*dlip)->dli_next = dli_next;
1193 rc = dynlist_build_def_filter( *dlip );
1197 case DL_ATTRPAIR_COMPAT:
1198 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1199 "warning: \"attrpair\" only supported for limited "
1200 "backward compatibility with overlay \"dyngroup\"" );
1201 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
1205 dynlist_info_t **dlip;
1206 ObjectClass *oc = NULL;
1207 AttributeDescription *ad = NULL,
1211 oc = oc_find( "groupOfURLs" );
1213 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1214 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1215 "unable to find default ObjectClass \"groupOfURLs\"" );
1216 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1217 c->log, c->cr_msg, 0 );
1221 rc = slap_str2ad( c->argv[ 1 ], &member_ad, &text );
1222 if ( rc != LDAP_SUCCESS ) {
1223 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1224 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1225 "unable to find AttributeDescription \"%s\"",
1227 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1228 c->log, c->cr_msg, 0 );
1232 rc = slap_str2ad( c->argv[ 2 ], &ad, &text );
1233 if ( rc != LDAP_SUCCESS ) {
1234 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1235 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1236 "unable to find AttributeDescription \"%s\"\n",
1238 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1239 c->log, c->cr_msg, 0 );
1243 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
1244 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1245 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1246 "AttributeDescription \"%s\" "
1247 "must be a subtype of \"labeledURI\"",
1249 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1250 c->log, c->cr_msg, 0 );
1254 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1255 *dlip; dlip = &(*dlip)->dli_next )
1257 /* The same URL attribute / member attribute pair
1258 * cannot be repeated */
1259 if ( (*dlip)->dli_ad == ad && (*dlip)->dli_member_ad == member_ad ) {
1260 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1261 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1262 "URL attributeDescription \"%s\" already mapped.\n",
1263 ad->ad_cname.bv_val );
1264 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1265 c->log, c->cr_msg, 0 );
1267 /* make it a warning... */
1273 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
1275 (*dlip)->dli_oc = oc;
1276 (*dlip)->dli_ad = ad;
1277 (*dlip)->dli_member_ad = member_ad;
1279 rc = dynlist_build_def_filter( *dlip );
1297 slap_overinst *on = (slap_overinst *) be->bd_info;
1298 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private;
1299 ObjectClass *oc = NULL;
1300 AttributeDescription *ad = NULL;
1304 if ( dli == NULL ) {
1305 dli = ch_calloc( 1, sizeof( dynlist_info_t ) );
1306 on->on_bi.bi_private = (void *)dli;
1309 for ( ; dli; dli = dli->dli_next ) {
1310 if ( dli->dli_oc == NULL ) {
1312 oc = oc_find( "groupOfURLs" );
1314 sprintf( cr->msg, "unable to fetch objectClass \"groupOfURLs\"" );
1315 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: %s.\n", cr->msg, 0, 0 );
1323 if ( dli->dli_ad == NULL ) {
1325 rc = slap_str2ad( "memberURL", &ad, &text );
1326 if ( rc != LDAP_SUCCESS ) {
1327 sprintf( cr->msg, "unable to fetch attributeDescription \"memberURL\": %d (%s)",
1329 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: %s.\n", cr->msg, 0, 0 );
1337 if ( BER_BVISNULL( &dli->dli_default_filter ) ) {
1338 rc = dynlist_build_def_filter( dli );
1345 rc = slap_str2ad( "dgIdentity", &ad_dgIdentity, &text );
1346 if ( rc != LDAP_SUCCESS ) {
1347 snprintf( cr->msg, sizeof( cr->msg),
1348 "unable to fetch attributeDescription \"dgIdentity\": %d (%s)",
1350 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: %s\n", cr->msg, 0, 0 );
1351 /* Just a warning */
1362 slap_overinst *on = (slap_overinst *) be->bd_info;
1364 if ( on->on_bi.bi_private ) {
1365 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private,
1368 for ( dli_next = dli; dli_next; dli = dli_next ) {
1369 dli_next = dli->dli_next;
1371 ch_free( dli->dli_default_filter.bv_val );
1379 static slap_overinst dynlist = { { NULL } };
1380 #ifdef TAKEOVER_DYNGROUP
1381 static char *obsolete_names[] = {
1387 #if SLAPD_OVER_DYNLIST == SLAPD_MOD_DYNAMIC
1389 #endif /* SLAPD_OVER_DYNLIST == SLAPD_MOD_DYNAMIC */
1391 dynlist_initialize(void)
1393 #ifndef OL_2_2_COMPAT
1397 dynlist.on_bi.bi_type = "dynlist";
1399 #ifdef TAKEOVER_DYNGROUP
1400 /* makes dynlist incompatible with dyngroup */
1401 dynlist.on_bi.bi_obsolete_names = obsolete_names;
1404 #ifdef OL_2_2_COMPAT
1405 dynlist.on_bi.bi_db_config = dynlist_db_config;
1407 dynlist.on_bi.bi_db_config = config_generic_wrapper;
1409 dynlist.on_bi.bi_db_open = dynlist_db_open;
1410 dynlist.on_bi.bi_db_destroy = dynlist_db_destroy;
1412 dynlist.on_response = dynlist_response;
1414 #ifndef OL_2_2_COMPAT
1415 dynlist.on_bi.bi_cf_ocs = dlocs;
1417 rc = config_register_schema( dlcfg, dlocs );
1423 return overlay_register( &dynlist );
1426 #if SLAPD_OVER_DYNLIST == SLAPD_MOD_DYNAMIC
1428 init_module( int argc, char *argv[] )
1430 return dynlist_initialize();
1434 #endif /* SLAPD_OVER_DYNLIST */