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 ) {
95 if ( value_find_ex( slap_schema.si_ad_objectClass,
96 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
97 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
98 a->a_nvals, &dli->dli_oc->soc_cname,
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;
193 (void)modify_add_values( e, &mod, /* permissive */ 1,
194 &text, textbuf, sizeof( textbuf ) );
201 opattrs = ( rs->sr_attrs == NULL ) ? 0 : an_find( rs->sr_attrs, &AllOper );
202 userattrs = ( rs->sr_attrs == NULL ) ? 1 : an_find( rs->sr_attrs, &AllUser );
203 #else /* SLAP_OPATTRS */
204 opattrs = SLAP_OPATTRS( rs->sr_attr_flags );
205 userattrs = SLAP_USERATTRS( rs->sr_attr_flags );
206 #endif /* SLAP_OPATTRS */
208 for ( a = rs->sr_entry->e_attrs; a != NULL; a = a->a_next ) {
209 BerVarray vals, nvals = NULL;
211 is_oc = a->a_desc == slap_schema.si_ad_objectClass;
213 /* if attribute is not requested, skip it */
214 if ( rs->sr_attrs == NULL ) {
215 if ( is_at_operational( a->a_desc->ad_type ) ) {
220 if ( is_at_operational( a->a_desc->ad_type ) ) {
221 if ( !opattrs && !ad_inlist( a->a_desc, rs->sr_attrs ) )
227 if ( !userattrs && !ad_inlist( a->a_desc, rs->sr_attrs ) )
234 /* test access to attribute */
235 if ( op->ors_attrsonly ) {
236 if ( !access_allowed( op, rs->sr_entry, a->a_desc, NULL,
237 ACL_READ, &acl_state ) )
243 /* single-value check: keep first only */
244 if ( is_at_single_value( a->a_desc->ad_type ) ) {
245 if ( attr_find( e->e_attrs, a->a_desc ) != NULL ) {
250 /* test access to attribute */
251 for ( i = 0; !BER_BVISNULL( &a->a_vals[i] ); i++ )
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;
297 (void)modify_add_values( e, &mod, /* permissive */ 1,
298 &text, textbuf, sizeof( textbuf ) );
301 op->o_tmpfree( vals, op->o_tmpmemctx );
303 op->o_tmpfree( nvals, op->o_tmpmemctx );
308 if ( rs->sr_flags & REP_ENTRY_MUSTBEFREED ) {
309 entry_free( rs->sr_entry );
311 rs->sr_flags ^= REP_ENTRY_MUSTBEFREED;
318 dynlist_prepare_entry( Operation *op, SlapReply *rs, dynlist_info_t *dli )
320 Attribute *a, *id = NULL;
323 SlapReply r = { REP_SEARCH };
329 dynlist_sc_t dlc = { 0 };
331 a = attrs_find( rs->sr_entry->e_attrs, dli->dli_ad );
334 return SLAP_CB_CONTINUE;
337 if ( !( rs->sr_flags & REP_ENTRY_MODIFIABLE ) ) {
338 e = entry_dup( rs->sr_entry );
342 e_flags = rs->sr_flags | ( REP_ENTRY_MODIFIABLE | REP_ENTRY_MUSTBEFREED );
344 if ( ad_dgIdentity && ( id = attrs_find( e->e_attrs, ad_dgIdentity ))) {
345 o.o_dn = id->a_vals[0];
346 o.o_ndn = id->a_nvals[0];
352 cb.sc_private = &dlc;
353 cb.sc_response = dynlist_sc_update;
354 cb.sc_cleanup = NULL;
358 o.ors_deref = LDAP_DEREF_NEVER;
360 o.ors_tlimit = SLAP_NO_LIMIT;
361 o.ors_slimit = SLAP_NO_LIMIT;
364 opattrs = ( rs->sr_attrs == NULL ) ? 0 : an_find( rs->sr_attrs, &AllOper );
365 userattrs = ( rs->sr_attrs == NULL ) ? 1 : an_find( rs->sr_attrs, &AllUser );
366 #else /* SLAP_OPATTRS */
367 opattrs = SLAP_OPATTRS( rs->sr_attr_flags );
368 userattrs = SLAP_USERATTRS( rs->sr_attr_flags );
369 #endif /* SLAP_OPATTRS */
371 for ( url = a->a_nvals; !BER_BVISNULL( url ); url++ ) {
372 LDAPURLDesc *lud = NULL;
377 BER_BVZERO( &o.o_req_dn );
378 BER_BVZERO( &o.o_req_ndn );
381 BER_BVZERO( &o.ors_filterstr );
383 if ( ldap_url_parse( url->bv_val, &lud ) != LDAP_URL_SUCCESS ) {
388 if ( lud->lud_host != NULL ) {
389 /* FIXME: host not allowed; reject as illegal? */
390 Debug( LDAP_DEBUG_ANY, "dynlist_prepare_entry(\"%s\"): "
391 "illegal URI \"%s\"\n",
392 e->e_name.bv_val, url->bv_val, 0 );
396 if ( lud->lud_dn == NULL ) {
397 /* note that an empty base is not honored in terms
398 * of defaultSearchBase, because select_backend()
399 * is not aware of the defaultSearchBase option;
400 * this can be useful in case of a database serving
401 * the empty suffix */
402 BER_BVSTR( &dn, "" );
405 ber_str2bv( lud->lud_dn, 0, 0, &dn );
407 rc = dnPrettyNormal( NULL, &dn, &o.o_req_dn, &o.o_req_ndn, op->o_tmpmemctx );
408 if ( rc != LDAP_SUCCESS ) {
412 o.ors_scope = lud->lud_scope;
414 if ( dli->dli_member_ad != NULL ) {
415 /* if ( lud->lud_attrs != NULL ),
416 * the URL should be ignored */
417 o.ors_attrs = slap_anlist_no_attrs;
419 } else if ( lud->lud_attrs == NULL ) {
420 o.ors_attrs = rs->sr_attrs;
423 for ( i = 0; lud->lud_attrs[i]; i++)
426 o.ors_attrs = op->o_tmpcalloc( i + 1, sizeof( AttributeName ), op->o_tmpmemctx );
427 for ( i = 0, j = 0; lud->lud_attrs[i]; i++) {
428 const char *text = NULL;
430 ber_str2bv( lud->lud_attrs[i], 0, 0, &o.ors_attrs[j].an_name );
431 o.ors_attrs[j].an_desc = NULL;
432 (void)slap_bv2ad( &o.ors_attrs[j].an_name, &o.ors_attrs[j].an_desc, &text );
433 /* FIXME: ignore errors... */
435 if ( rs->sr_attrs == NULL ) {
436 if ( o.ors_attrs[j].an_desc != NULL &&
437 is_at_operational( o.ors_attrs[j].an_desc->ad_type ) )
443 if ( o.ors_attrs[j].an_desc != NULL &&
444 is_at_operational( o.ors_attrs[j].an_desc->ad_type ) )
446 if ( !opattrs && !ad_inlist( o.ors_attrs[j].an_desc, rs->sr_attrs ) )
453 o.ors_attrs[j].an_desc != NULL &&
454 !ad_inlist( o.ors_attrs[j].an_desc, rs->sr_attrs ) )
468 BER_BVZERO( &o.ors_attrs[j].an_name );
471 if ( lud->lud_filter == NULL ) {
472 ber_dupbv_x( &o.ors_filterstr,
473 &dli->dli_default_filter, op->o_tmpmemctx );
477 ber_str2bv( lud->lud_filter, 0, 0, &flt );
478 if ( dynlist_make_filter( op, &flt, &o.ors_filterstr ) ) {
483 o.ors_filter = str2filter_x( op, o.ors_filterstr.bv_val );
484 if ( o.ors_filter == NULL ) {
488 o.o_bd = select_backend( &o.o_req_ndn, 1 );
489 if ( o.o_bd && o.o_bd->be_search ) {
491 r.sr_attr_flags = slap_attr_flags( o.ors_attrs );
492 #endif /* SLAP_OPATTRS */
493 (void)o.o_bd->be_search( &o, &r );
498 slap_op_groups_free( &o );
500 if ( o.ors_filter ) {
501 filter_free_x( &o, o.ors_filter );
503 if ( o.ors_attrs && o.ors_attrs != rs->sr_attrs
504 && o.ors_attrs != slap_anlist_no_attrs )
506 op->o_tmpfree( o.ors_attrs, op->o_tmpmemctx );
508 if ( !BER_BVISNULL( &o.o_req_dn ) ) {
509 op->o_tmpfree( o.o_req_dn.bv_val, op->o_tmpmemctx );
511 if ( !BER_BVISNULL( &o.o_req_ndn ) ) {
512 op->o_tmpfree( o.o_req_ndn.bv_val, op->o_tmpmemctx );
514 assert( BER_BVISNULL( &o.ors_filterstr )
515 || o.ors_filterstr.bv_val != lud->lud_filter );
516 op->o_tmpfree( o.ors_filterstr.bv_val, op->o_tmpmemctx );
517 ldap_free_urldesc( lud );
521 rs->sr_flags = e_flags;
523 return SLAP_CB_CONTINUE;
527 dynlist_sc_save_entry( Operation *op, SlapReply *rs )
529 /* save the entry in the private field of the callback,
530 * so it doesn't get freed (it's temporary!) */
531 if ( rs->sr_entry != NULL ) {
532 dynlist_sc_t *dlc = (dynlist_sc_t *)op->o_callback->sc_private;
533 dlc->dlc_e = rs->sr_entry;
541 dynlist_compare( Operation *op, SlapReply *rs )
543 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
544 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private;
548 for ( ; dli != NULL; dli = dli->dli_next ) {
549 if ( op->oq_compare.rs_ava->aa_desc == dli->dli_member_ad ) {
550 /* This compare is for one of the attributes we're
551 * interested in. We'll use slapd's existing dyngroup
552 * evaluator to get the answer we want.
554 struct berval *id = NULL;
556 o.o_do_not_cache = 1;
558 if ( ad_dgIdentity && backend_attribute( &o, NULL, &o.o_req_ndn,
559 ad_dgIdentity, &id, ACL_READ ) == LDAP_SUCCESS ) {
562 o.o_groups = NULL; /* authz changed, invalidate cached groups */
564 rs->sr_err = backend_group( &o, NULL, &o.o_req_ndn,
565 &o.oq_compare.rs_ava->aa_value, dli->dli_oc, dli->dli_ad );
566 switch ( rs->sr_err ) {
568 rs->sr_err = LDAP_COMPARE_TRUE;
571 case LDAP_NO_SUCH_OBJECT:
572 /* NOTE: backend_group() returns noSuchObject
573 * if op_ndn does not exist; however, since
574 * dynamic list expansion means that the
575 * member attribute is virtually present, the
576 * non-existence of the asserted value implies
577 * the assertion is FALSE rather than
579 rs->sr_err = LDAP_COMPARE_FALSE;
583 if ( id ) ber_bvarray_free_x( id, o.o_tmpmemctx );
585 return SLAP_CB_CONTINUE;
589 if ( overlay_entry_get_ov( &o, &o.o_req_ndn, NULL, NULL, 0, &e, on ) !=
590 LDAP_SUCCESS || e == NULL ) {
591 return SLAP_CB_CONTINUE;
593 if ( ad_dgIdentity ) {
594 Attribute *id = attrs_find( e->e_attrs, ad_dgIdentity );
596 o.o_dn = id->a_vals[0];
597 o.o_ndn = id->a_nvals[0];
601 dli = (dynlist_info_t *)on->on_bi.bi_private;
602 for ( ; dli != NULL && rs->sr_err != LDAP_COMPARE_TRUE; dli = dli->dli_next ) {
605 SlapReply r = { REP_SEARCH };
608 dynlist_sc_t dlc = { 0 };
610 if ( !is_entry_objectclass_or_sub( e, dli->dli_oc ))
613 /* if the entry has the right objectClass, generate
614 * the dynamic list and compare */
616 cb.sc_private = &dlc;
617 cb.sc_response = dynlist_sc_save_entry;
618 cb.sc_cleanup = NULL;
622 o.o_tag = LDAP_REQ_SEARCH;
624 o.ors_tlimit = SLAP_NO_LIMIT;
625 o.ors_slimit = SLAP_NO_LIMIT;
627 o.o_bd = select_backend( &o.o_req_ndn, 1 );
628 if ( !o.o_bd || !o.o_bd->be_search ) {
629 return SLAP_CB_CONTINUE;
632 BER_BVSTR( &o.ors_filterstr, "(objectClass=*)" );
633 o.ors_filter = str2filter_x( op, o.ors_filterstr.bv_val );
634 if ( o.ors_filter == NULL ) {
636 return SLAP_CB_CONTINUE;
639 o.ors_scope = LDAP_SCOPE_BASE;
640 o.ors_deref = LDAP_DEREF_NEVER;
641 an[0].an_name = op->orc_ava->aa_desc->ad_cname;
642 an[0].an_desc = op->orc_ava->aa_desc;
643 BER_BVZERO( &an[1].an_name );
647 o.o_acl_priv = ACL_COMPARE;
649 rc = o.o_bd->be_search( &o, &r );
650 filter_free_x( &o, o.ors_filter );
652 if ( o.o_dn.bv_val != op->o_dn.bv_val ) {
653 slap_op_groups_free( &o );
660 if ( dlc.dlc_e != NULL ) {
661 r.sr_entry = dlc.dlc_e;
664 if ( r.sr_err != LDAP_SUCCESS || r.sr_entry == NULL ) {
666 return SLAP_CB_CONTINUE;
669 for ( a = attrs_find( r.sr_entry->e_attrs, op->orc_ava->aa_desc );
671 a = attrs_find( a->a_next, op->orc_ava->aa_desc ) )
673 /* if we're here, we got a match... */
674 rs->sr_err = LDAP_COMPARE_FALSE;
676 if ( value_find_ex( op->orc_ava->aa_desc,
677 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
678 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
679 a->a_nvals, &op->orc_ava->aa_value, op->o_tmpmemctx ) == 0 )
681 rs->sr_err = LDAP_COMPARE_TRUE;
686 if ( r.sr_flags & REP_ENTRY_MUSTBEFREED ) {
687 entry_free( r.sr_entry );
691 return SLAP_CB_CONTINUE;
695 dynlist_response( Operation *op, SlapReply *rs )
699 switch ( op->o_tag ) {
700 case LDAP_REQ_SEARCH:
701 if ( rs->sr_type == REP_SEARCH && !get_manageDSAit( op ) )
705 for ( dli = dynlist_is_dynlist_next( op, rs, NULL );
707 dli = dynlist_is_dynlist_next( op, rs, dli ) )
709 rc = dynlist_prepare_entry( op, rs, dli );
712 if ( rc != LDAP_OTHER ) {
718 case LDAP_REQ_COMPARE:
719 switch ( rs->sr_err ) {
720 /* NOTE: we waste a few cycles running the dynamic list
721 * also when the result is FALSE, which occurs if the
722 * dynamic entry itself contains the AVA attribute */
723 /* FIXME: this approach is less than optimal; a dedicated
724 * compare op should be implemented, that fetches the
725 * entry, checks if it has the appropriate objectClass
726 * and, in case, runs a compare thru all the URIs,
727 * stopping at the first positive occurrence; see ITS#3756 */
728 case LDAP_COMPARE_FALSE:
729 case LDAP_NO_SUCH_ATTRIBUTE:
730 return dynlist_compare( op, rs );
738 return SLAP_CB_CONTINUE;
742 dynlist_build_def_filter( dynlist_info_t *dli )
746 dli->dli_default_filter.bv_len = STRLENOF( "(!(objectClass=" "))" )
747 + dli->dli_oc->soc_cname.bv_len;
748 dli->dli_default_filter.bv_val = ch_malloc( dli->dli_default_filter.bv_len + 1 );
749 if ( dli->dli_default_filter.bv_val == NULL ) {
750 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: malloc failed.\n",
755 ptr = lutil_strcopy( dli->dli_default_filter.bv_val, "(!(objectClass=" );
756 ptr = lutil_strcopy( ptr, dli->dli_oc->soc_cname.bv_val );
757 ptr = lutil_strcopy( ptr, "))" );
759 assert( dli->dli_default_filter.bv_len == ptr - dli->dli_default_filter.bv_val );
773 slap_overinst *on = (slap_overinst *)be->bd_info;
777 if ( strcasecmp( argv[0], "dynlist-attrset" ) == 0 ) {
778 dynlist_info_t **dlip;
780 AttributeDescription *ad = NULL,
784 if ( argc < 3 || argc > 4 ) {
785 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
786 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
787 "invalid arg number #%d.\n",
788 fname, lineno, argc );
792 oc = oc_find( argv[1] );
794 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
795 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
796 "unable to find ObjectClass \"%s\"\n",
797 fname, lineno, argv[ 1 ] );
801 rc = slap_str2ad( argv[2], &ad, &text );
802 if ( rc != LDAP_SUCCESS ) {
803 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
804 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
805 "unable to find AttributeDescription \"%s\"\n",
806 fname, lineno, argv[2] );
810 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
811 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
812 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
813 "AttributeDescription \"%s\" "
814 "must be a subtype of \"labeledURI\"\n",
815 fname, lineno, argv[2] );
820 rc = slap_str2ad( argv[3], &member_ad, &text );
821 if ( rc != LDAP_SUCCESS ) {
822 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
823 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
824 "unable to find AttributeDescription \"%s\"\n",
825 fname, lineno, argv[3] );
830 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
831 *dlip; dlip = &(*dlip)->dli_next )
833 /* The same URL attribute / member attribute pair
834 * cannot be repeated */
835 if ( (*dlip)->dli_ad == ad && (*dlip)->dli_member_ad == member_ad ) {
836 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
837 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
838 "URL attributeDescription \"%s\" already mapped.\n",
839 fname, lineno, ad->ad_cname.bv_val );
841 /* make it a warning... */
847 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
848 (*dlip)->dli_oc = oc;
849 (*dlip)->dli_ad = ad;
850 (*dlip)->dli_member_ad = member_ad;
852 if ( dynlist_build_def_filter( *dlip ) ) {
858 /* allow dyngroup syntax */
859 } else if ( strcasecmp( argv[0], "dynlist-attrpair" ) == 0 ) {
860 dynlist_info_t **dlip;
862 AttributeDescription *ad = NULL,
867 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
868 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
869 "invalid arg number #%d.\n",
870 fname, lineno, argc );
874 oc = oc_find( "groupOfURLs" );
876 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
877 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
878 "unable to find default ObjectClass \"groupOfURLs\"\n",
883 rc = slap_str2ad( argv[1], &member_ad, &text );
884 if ( rc != LDAP_SUCCESS ) {
885 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
886 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
887 "unable to find AttributeDescription \"%s\"\n",
888 fname, lineno, argv[1] );
892 rc = slap_str2ad( argv[2], &ad, &text );
893 if ( rc != LDAP_SUCCESS ) {
894 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
895 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
896 "unable to find AttributeDescription \"%s\"\n",
897 fname, lineno, argv[2] );
901 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
902 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
903 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
904 "AttributeDescription \"%s\" "
905 "must be a subtype of \"labeledURI\"\n",
906 fname, lineno, argv[2] );
910 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
911 *dlip; dlip = &(*dlip)->dli_next )
913 /* The same URL attribute / member attribute pair
914 * cannot be repeated */
915 if ( (*dlip)->dli_ad == ad && (*dlip)->dli_member_ad == member_ad ) {
916 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
917 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
918 "URL attributeDescription \"%s\" already mapped.\n",
919 fname, lineno, ad->ad_cname.bv_val );
921 /* make it a warning... */
927 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
928 (*dlip)->dli_oc = oc;
929 (*dlip)->dli_ad = ad;
930 (*dlip)->dli_member_ad = member_ad;
932 if ( dynlist_build_def_filter( *dlip ) ) {
939 rc = SLAP_CONF_UNKNOWN;
953 static ConfigDriver dl_cfgen;
955 static ConfigTable dlcfg[] = {
956 { "dynlist-attrset", "group-oc> <URL-ad> <member-ad",
957 3, 4, 0, ARG_MAGIC|DL_ATTRSET, dl_cfgen,
958 "( OLcfgOvAt:8.1 NAME 'olcDLattrSet' "
959 "DESC 'Dynamic list: <group objectClass>, <URL attributeDescription>, <member attributeDescription>' "
960 "EQUALITY caseIgnoreMatch "
961 "SYNTAX OMsDirectoryString "
962 "X-ORDERED 'VALUES' )",
964 { "dynlist-attrpair", "member-ad> <URL-ad",
965 3, 3, 0, ARG_MAGIC|DL_ATTRPAIR, dl_cfgen,
967 #ifdef TAKEOVER_DYNGROUP
968 { "attrpair", "member-ad> <URL-ad",
969 3, 3, 0, ARG_MAGIC|DL_ATTRPAIR_COMPAT, dl_cfgen,
972 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
975 static ConfigOCs dlocs[] = {
977 "NAME 'olcDynamicList' "
978 "DESC 'Dynamic list configuration' "
979 "SUP olcOverlayConfig "
980 "MAY olcDLattrSet )",
981 Cft_Overlay, dlcfg, NULL, NULL },
986 dl_cfgen( ConfigArgs *c )
988 slap_overinst *on = (slap_overinst *)c->bi;
989 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private;
993 if ( c->op == SLAP_CONFIG_EMIT ) {
996 for ( i = 0; dli; i++, dli = dli->dli_next ) {
998 char *ptr = c->cr_msg;
1000 assert( dli->dli_oc != NULL );
1001 assert( dli->dli_ad != NULL );
1003 ptr += snprintf( c->cr_msg, sizeof( c->cr_msg ),
1004 SLAP_X_ORDERED_FMT "%s %s", i,
1005 dli->dli_oc->soc_cname.bv_val,
1006 dli->dli_ad->ad_cname.bv_val );
1008 if ( dli->dli_member_ad != NULL ) {
1011 ptr = lutil_strcopy( ptr, dli->dli_member_ad->ad_cname.bv_val );
1014 bv.bv_val = c->cr_msg;
1015 bv.bv_len = ptr - bv.bv_val;
1016 value_add_one( &c->rvalue_vals, &bv );
1020 case DL_ATTRPAIR_COMPAT:
1032 } else if ( c->op == LDAP_MOD_DELETE ) {
1035 if ( c->valx < 0 ) {
1036 dynlist_info_t *dli_next;
1038 for ( dli_next = dli; dli_next; dli = dli_next ) {
1039 dli_next = dli->dli_next;
1041 ch_free( dli->dli_default_filter.bv_val );
1045 on->on_bi.bi_private = NULL;
1048 dynlist_info_t **dlip;
1050 for ( i = 0, dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1053 if ( *dlip == NULL ) {
1056 dlip = &(*dlip)->dli_next;
1060 *dlip = dli->dli_next;
1061 ch_free( dli->dli_default_filter.bv_val );
1064 dli = (dynlist_info_t *)on->on_bi.bi_private;
1068 case DL_ATTRPAIR_COMPAT:
1078 return 1; /* FIXME */
1083 dynlist_info_t **dlip,
1085 ObjectClass *oc = NULL;
1086 AttributeDescription *ad = NULL,
1090 oc = oc_find( c->argv[ 1 ] );
1092 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1093 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1094 "unable to find ObjectClass \"%s\"",
1096 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1097 c->log, c->cr_msg, 0 );
1101 rc = slap_str2ad( c->argv[ 2 ], &ad, &text );
1102 if ( rc != LDAP_SUCCESS ) {
1103 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1104 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1105 "unable to find AttributeDescription \"%s\"",
1107 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1108 c->log, c->cr_msg, 0 );
1112 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
1113 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1114 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1115 "AttributeDescription \"%s\" "
1116 "must be a subtype of \"labeledURI\"",
1118 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1119 c->log, c->cr_msg, 0 );
1123 if ( c->argc == 4 ) {
1124 rc = slap_str2ad( c->argv[ 3 ], &member_ad, &text );
1125 if ( rc != LDAP_SUCCESS ) {
1126 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1127 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1128 "unable to find AttributeDescription \"%s\"\n",
1130 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1131 c->log, c->cr_msg, 0 );
1136 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1137 *dlip; dlip = &(*dlip)->dli_next )
1139 /* The same URL attribute / member attribute pair
1140 * cannot be repeated */
1141 if ( (*dlip)->dli_ad == ad && (*dlip)->dli_member_ad == member_ad ) {
1142 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1143 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1144 "URL attributeDescription \"%s\" already mapped.\n",
1145 ad->ad_cname.bv_val );
1146 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1147 c->log, c->cr_msg, 0 );
1149 /* make it a warning... */
1155 if ( c->valx > 0 ) {
1158 for ( i = 0, dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1161 if ( *dlip == NULL ) {
1162 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1163 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1164 "invalid index {%d}\n",
1166 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1167 c->log, c->cr_msg, 0 );
1170 dlip = &(*dlip)->dli_next;
1175 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1176 *dlip; dlip = &(*dlip)->dli_next )
1180 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
1182 (*dlip)->dli_oc = oc;
1183 (*dlip)->dli_ad = ad;
1184 (*dlip)->dli_member_ad = member_ad;
1185 (*dlip)->dli_next = dli_next;
1187 rc = dynlist_build_def_filter( *dlip );
1191 case DL_ATTRPAIR_COMPAT:
1192 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1193 "warning: \"attrpair\" only supported for limited "
1194 "backward compatibility with overlay \"dyngroup\"" );
1195 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
1199 dynlist_info_t **dlip;
1200 ObjectClass *oc = NULL;
1201 AttributeDescription *ad = NULL,
1205 oc = oc_find( "groupOfURLs" );
1207 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1208 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1209 "unable to find default ObjectClass \"groupOfURLs\"" );
1210 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1211 c->log, c->cr_msg, 0 );
1215 rc = slap_str2ad( c->argv[ 1 ], &member_ad, &text );
1216 if ( rc != LDAP_SUCCESS ) {
1217 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1218 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1219 "unable to find AttributeDescription \"%s\"",
1221 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1222 c->log, c->cr_msg, 0 );
1226 rc = slap_str2ad( c->argv[ 2 ], &ad, &text );
1227 if ( rc != LDAP_SUCCESS ) {
1228 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1229 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1230 "unable to find AttributeDescription \"%s\"\n",
1232 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1233 c->log, c->cr_msg, 0 );
1237 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
1238 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1239 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1240 "AttributeDescription \"%s\" "
1241 "must be a subtype of \"labeledURI\"",
1243 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1244 c->log, c->cr_msg, 0 );
1248 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1249 *dlip; dlip = &(*dlip)->dli_next )
1251 /* The same URL attribute / member attribute pair
1252 * cannot be repeated */
1253 if ( (*dlip)->dli_ad == ad && (*dlip)->dli_member_ad == member_ad ) {
1254 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1255 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1256 "URL attributeDescription \"%s\" already mapped.\n",
1257 ad->ad_cname.bv_val );
1258 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1259 c->log, c->cr_msg, 0 );
1261 /* make it a warning... */
1267 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
1269 (*dlip)->dli_oc = oc;
1270 (*dlip)->dli_ad = ad;
1271 (*dlip)->dli_member_ad = member_ad;
1273 rc = dynlist_build_def_filter( *dlip );
1291 slap_overinst *on = (slap_overinst *) be->bd_info;
1292 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private;
1293 ObjectClass *oc = NULL;
1294 AttributeDescription *ad = NULL;
1298 if ( dli == NULL ) {
1299 dli = ch_calloc( 1, sizeof( dynlist_info_t ) );
1300 on->on_bi.bi_private = (void *)dli;
1303 for ( ; dli; dli = dli->dli_next ) {
1304 if ( dli->dli_oc == NULL ) {
1306 oc = oc_find( "groupOfURLs" );
1308 sprintf( cr->msg, "unable to fetch objectClass \"groupOfURLs\"" );
1309 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: %s.\n", cr->msg, 0, 0 );
1317 if ( dli->dli_ad == NULL ) {
1319 rc = slap_str2ad( "memberURL", &ad, &text );
1320 if ( rc != LDAP_SUCCESS ) {
1321 sprintf( cr->msg, "unable to fetch attributeDescription \"memberURL\": %d (%s)",
1323 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: %s.\n", cr->msg, 0, 0 );
1331 if ( BER_BVISNULL( &dli->dli_default_filter ) ) {
1332 rc = dynlist_build_def_filter( dli );
1339 rc = slap_str2ad( "dgIdentity", &ad_dgIdentity, &text );
1340 if ( rc != LDAP_SUCCESS ) {
1341 sprintf( cr->msg, "unable to fetch attributeDescription \"dgIdentity\": %d (%s)",
1343 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: %s\n", cr->msg, 0, 0 );
1344 /* Just a warning */
1355 slap_overinst *on = (slap_overinst *) be->bd_info;
1357 if ( on->on_bi.bi_private ) {
1358 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private,
1361 for ( dli_next = dli; dli_next; dli = dli_next ) {
1362 dli_next = dli->dli_next;
1364 ch_free( dli->dli_default_filter.bv_val );
1372 static slap_overinst dynlist = { { NULL } };
1373 #ifdef TAKEOVER_DYNGROUP
1374 static char *obsolete_names[] = {
1380 #if SLAPD_OVER_DYNLIST == SLAPD_MOD_DYNAMIC
1382 #endif /* SLAPD_OVER_DYNLIST == SLAPD_MOD_DYNAMIC */
1384 dynlist_initialize(void)
1386 #ifndef OL_2_2_COMPAT
1390 dynlist.on_bi.bi_type = "dynlist";
1392 #ifdef TAKEOVER_DYNGROUP
1393 /* makes dynlist incompatible with dyngroup */
1394 dynlist.on_bi.bi_obsolete_names = obsolete_names;
1397 #ifdef OL_2_2_COMPAT
1398 dynlist.on_bi.bi_db_config = dynlist_db_config;
1400 dynlist.on_bi.bi_db_config = config_generic_wrapper;
1402 dynlist.on_bi.bi_db_open = dynlist_db_open;
1403 dynlist.on_bi.bi_db_destroy = dynlist_db_destroy;
1405 dynlist.on_response = dynlist_response;
1407 #ifndef OL_2_2_COMPAT
1408 dynlist.on_bi.bi_cf_ocs = dlocs;
1410 rc = config_register_schema( dlcfg, dlocs );
1416 return overlay_register( &dynlist );
1419 #if SLAPD_OVER_DYNLIST == SLAPD_MOD_DYNAMIC
1421 init_module( int argc, char *argv[] )
1423 return dynlist_initialize();
1427 #endif /* SLAPD_OVER_DYNLIST */