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, *ad_dgAuthz;
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 */
253 vals = op->o_tmpalloc( ( i + 1 ) * sizeof( struct berval ), op->o_tmpmemctx );
254 if ( a->a_nvals != a->a_vals ) {
255 nvals = op->o_tmpalloc( ( i + 1 ) * sizeof( struct berval ), op->o_tmpmemctx );
258 for ( i = 0, j = 0; !BER_BVISNULL( &a->a_vals[i] ); i++ ) {
260 ObjectClass *soc = oc_bvfind( &a->a_vals[i] );
262 if ( soc->soc_kind == LDAP_SCHEMA_STRUCTURAL ) {
267 if ( access_allowed( op, rs->sr_entry, a->a_desc,
268 &a->a_nvals[i], ACL_READ, &acl_state ) )
270 vals[j] = a->a_vals[i];
272 nvals[j] = a->a_nvals[i];
278 /* if access allowed, try to add values, emulating permissive
279 * control to silently ignore duplicates */
282 const char *text = NULL;
285 BER_BVZERO( &vals[j] );
287 BER_BVZERO( &nvals[j] );
290 mod.sm_op = LDAP_MOD_ADD;
291 mod.sm_desc = a->a_desc;
292 mod.sm_type = a->a_desc->ad_cname;
293 mod.sm_values = vals;
294 mod.sm_nvalues = nvals;
296 (void)modify_add_values( e, &mod, /* permissive */ 1,
297 &text, textbuf, sizeof( textbuf ) );
300 op->o_tmpfree( vals, op->o_tmpmemctx );
302 op->o_tmpfree( nvals, op->o_tmpmemctx );
307 if ( rs->sr_flags & REP_ENTRY_MUSTBEFREED ) {
308 entry_free( rs->sr_entry );
310 rs->sr_flags ^= REP_ENTRY_MUSTBEFREED;
317 dynlist_prepare_entry( Operation *op, SlapReply *rs, dynlist_info_t *dli )
319 Attribute *a, *id = NULL;
322 SlapReply r = { REP_SEARCH };
328 dynlist_sc_t dlc = { 0 };
330 a = attrs_find( rs->sr_entry->e_attrs, dli->dli_ad );
333 return SLAP_CB_CONTINUE;
337 opattrs = ( rs->sr_attrs == NULL ) ? 0 : an_find( rs->sr_attrs, &AllOper );
338 userattrs = ( rs->sr_attrs == NULL ) ? 1 : an_find( rs->sr_attrs, &AllUser );
339 #else /* SLAP_OPATTRS */
340 opattrs = SLAP_OPATTRS( rs->sr_attr_flags );
341 userattrs = SLAP_USERATTRS( rs->sr_attr_flags );
342 #endif /* SLAP_OPATTRS */
344 /* Don't generate member list if it wasn't requested */
345 if ( dli->dli_member_ad && !userattrs && !ad_inlist( dli->dli_member_ad, rs->sr_attrs ) ) {
346 return SLAP_CB_CONTINUE;
349 if ( ad_dgIdentity && ( id = attrs_find( rs->sr_entry->e_attrs, ad_dgIdentity ))) {
350 Attribute *authz = NULL;
352 /* if not rootdn and dgAuthz is present,
353 * check if user can be authorized as dgIdentity */
354 if ( ad_dgAuthz && !BER_BVISEMPTY( &id->a_nvals[0] ) && !be_isroot( op )
355 && ( authz = attrs_find( rs->sr_entry->e_attrs, ad_dgAuthz ) ) )
357 if ( slap_sasl_matches( op, authz->a_nvals,
358 &o.o_ndn, &o.o_ndn ) != LDAP_SUCCESS )
360 return SLAP_CB_CONTINUE;
364 o.o_dn = id->a_vals[0];
365 o.o_ndn = id->a_nvals[0];
369 if ( !( rs->sr_flags & REP_ENTRY_MODIFIABLE ) ) {
370 e = entry_dup( rs->sr_entry );
374 e_flags = rs->sr_flags | ( REP_ENTRY_MODIFIABLE | REP_ENTRY_MUSTBEFREED );
378 cb.sc_private = &dlc;
379 cb.sc_response = dynlist_sc_update;
380 cb.sc_cleanup = NULL;
384 o.ors_deref = LDAP_DEREF_NEVER;
386 o.ors_tlimit = SLAP_NO_LIMIT;
387 o.ors_slimit = SLAP_NO_LIMIT;
389 for ( url = a->a_nvals; !BER_BVISNULL( url ); url++ ) {
390 LDAPURLDesc *lud = NULL;
395 BER_BVZERO( &o.o_req_dn );
396 BER_BVZERO( &o.o_req_ndn );
399 BER_BVZERO( &o.ors_filterstr );
401 if ( ldap_url_parse( url->bv_val, &lud ) != LDAP_URL_SUCCESS ) {
406 if ( lud->lud_host != NULL ) {
407 /* FIXME: host not allowed; reject as illegal? */
408 Debug( LDAP_DEBUG_ANY, "dynlist_prepare_entry(\"%s\"): "
409 "illegal URI \"%s\"\n",
410 e->e_name.bv_val, url->bv_val, 0 );
414 if ( lud->lud_dn == NULL ) {
415 /* note that an empty base is not honored in terms
416 * of defaultSearchBase, because select_backend()
417 * is not aware of the defaultSearchBase option;
418 * this can be useful in case of a database serving
419 * the empty suffix */
420 BER_BVSTR( &dn, "" );
423 ber_str2bv( lud->lud_dn, 0, 0, &dn );
425 rc = dnPrettyNormal( NULL, &dn, &o.o_req_dn, &o.o_req_ndn, op->o_tmpmemctx );
426 if ( rc != LDAP_SUCCESS ) {
430 o.ors_scope = lud->lud_scope;
432 if ( dli->dli_member_ad != NULL ) {
433 /* if ( lud->lud_attrs != NULL ),
434 * the URL should be ignored */
435 o.ors_attrs = slap_anlist_no_attrs;
437 } else if ( lud->lud_attrs == NULL ) {
438 o.ors_attrs = rs->sr_attrs;
441 for ( i = 0; lud->lud_attrs[i]; i++)
444 o.ors_attrs = op->o_tmpcalloc( i + 1, sizeof( AttributeName ), op->o_tmpmemctx );
445 for ( i = 0, j = 0; lud->lud_attrs[i]; i++) {
446 const char *text = NULL;
448 ber_str2bv( lud->lud_attrs[i], 0, 0, &o.ors_attrs[j].an_name );
449 o.ors_attrs[j].an_desc = NULL;
450 (void)slap_bv2ad( &o.ors_attrs[j].an_name, &o.ors_attrs[j].an_desc, &text );
451 /* FIXME: ignore errors... */
453 if ( rs->sr_attrs == NULL ) {
454 if ( o.ors_attrs[j].an_desc != NULL &&
455 is_at_operational( o.ors_attrs[j].an_desc->ad_type ) )
461 if ( o.ors_attrs[j].an_desc != NULL &&
462 is_at_operational( o.ors_attrs[j].an_desc->ad_type ) )
464 if ( !opattrs && !ad_inlist( o.ors_attrs[j].an_desc, rs->sr_attrs ) )
471 o.ors_attrs[j].an_desc != NULL &&
472 !ad_inlist( o.ors_attrs[j].an_desc, rs->sr_attrs ) )
486 BER_BVZERO( &o.ors_attrs[j].an_name );
489 if ( lud->lud_filter == NULL ) {
490 ber_dupbv_x( &o.ors_filterstr,
491 &dli->dli_default_filter, op->o_tmpmemctx );
495 ber_str2bv( lud->lud_filter, 0, 0, &flt );
496 if ( dynlist_make_filter( op, &flt, &o.ors_filterstr ) ) {
501 o.ors_filter = str2filter_x( op, o.ors_filterstr.bv_val );
502 if ( o.ors_filter == NULL ) {
506 o.o_bd = select_backend( &o.o_req_ndn, 1 );
507 if ( o.o_bd && o.o_bd->be_search ) {
509 r.sr_attr_flags = slap_attr_flags( o.ors_attrs );
510 #endif /* SLAP_OPATTRS */
511 (void)o.o_bd->be_search( &o, &r );
516 slap_op_groups_free( &o );
518 if ( o.ors_filter ) {
519 filter_free_x( &o, o.ors_filter );
521 if ( o.ors_attrs && o.ors_attrs != rs->sr_attrs
522 && o.ors_attrs != slap_anlist_no_attrs )
524 op->o_tmpfree( o.ors_attrs, op->o_tmpmemctx );
526 if ( !BER_BVISNULL( &o.o_req_dn ) ) {
527 op->o_tmpfree( o.o_req_dn.bv_val, op->o_tmpmemctx );
529 if ( !BER_BVISNULL( &o.o_req_ndn ) ) {
530 op->o_tmpfree( o.o_req_ndn.bv_val, op->o_tmpmemctx );
532 assert( BER_BVISNULL( &o.ors_filterstr )
533 || o.ors_filterstr.bv_val != lud->lud_filter );
534 op->o_tmpfree( o.ors_filterstr.bv_val, op->o_tmpmemctx );
535 ldap_free_urldesc( lud );
539 rs->sr_flags = e_flags;
541 return SLAP_CB_CONTINUE;
545 dynlist_sc_save_entry( Operation *op, SlapReply *rs )
547 /* save the entry in the private field of the callback,
548 * so it doesn't get freed (it's temporary!) */
549 if ( rs->sr_entry != NULL ) {
550 dynlist_sc_t *dlc = (dynlist_sc_t *)op->o_callback->sc_private;
551 dlc->dlc_e = rs->sr_entry;
559 dynlist_compare( Operation *op, SlapReply *rs )
561 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
562 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private;
566 for ( ; dli != NULL; dli = dli->dli_next ) {
567 if ( op->oq_compare.rs_ava->aa_desc == dli->dli_member_ad ) {
568 /* This compare is for one of the attributes we're
569 * interested in. We'll use slapd's existing dyngroup
570 * evaluator to get the answer we want.
572 BerVarray id = NULL, authz = NULL;
574 o.o_do_not_cache = 1;
576 if ( ad_dgIdentity && backend_attribute( &o, NULL, &o.o_req_ndn,
577 ad_dgIdentity, &id, ACL_READ ) == LDAP_SUCCESS )
579 /* if not rootdn and dgAuthz is present,
580 * check if user can be authorized as dgIdentity */
581 if ( ad_dgAuthz && !BER_BVISEMPTY( id ) && !be_isroot( op )
582 && backend_attribute( &o, NULL, &o.o_req_ndn,
583 ad_dgAuthz, &authz, ACL_READ ) == LDAP_SUCCESS )
586 rs->sr_err = slap_sasl_matches( op, authz,
587 &o.o_ndn, &o.o_ndn );
588 ber_bvarray_free_x( authz, op->o_tmpmemctx );
589 if ( rs->sr_err != LDAP_SUCCESS ) {
596 o.o_groups = NULL; /* authz changed, invalidate cached groups */
599 rs->sr_err = backend_group( &o, NULL, &o.o_req_ndn,
600 &o.oq_compare.rs_ava->aa_value, dli->dli_oc, dli->dli_ad );
601 switch ( rs->sr_err ) {
603 rs->sr_err = LDAP_COMPARE_TRUE;
606 case LDAP_NO_SUCH_OBJECT:
607 /* NOTE: backend_group() returns noSuchObject
608 * if op_ndn does not exist; however, since
609 * dynamic list expansion means that the
610 * member attribute is virtually present, the
611 * non-existence of the asserted value implies
612 * the assertion is FALSE rather than
614 rs->sr_err = LDAP_COMPARE_FALSE;
619 if ( id ) ber_bvarray_free_x( id, o.o_tmpmemctx );
621 return SLAP_CB_CONTINUE;
625 if ( overlay_entry_get_ov( &o, &o.o_req_ndn, NULL, NULL, 0, &e, on ) !=
626 LDAP_SUCCESS || e == NULL )
628 return SLAP_CB_CONTINUE;
631 if ( ad_dgIdentity ) {
632 Attribute *id = attrs_find( e->e_attrs, ad_dgIdentity );
636 /* if not rootdn and dgAuthz is present,
637 * check if user can be authorized as dgIdentity */
638 if ( ad_dgAuthz && !BER_BVISEMPTY( &id->a_nvals[0] ) && !be_isroot( op )
639 && ( authz = attrs_find( e->e_attrs, ad_dgAuthz ) ) )
641 if ( slap_sasl_matches( op, authz->a_nvals,
642 &o.o_ndn, &o.o_ndn ) != LDAP_SUCCESS )
648 o.o_dn = id->a_vals[0];
649 o.o_ndn = id->a_nvals[0];
654 dli = (dynlist_info_t *)on->on_bi.bi_private;
655 for ( ; dli != NULL && rs->sr_err != LDAP_COMPARE_TRUE; dli = dli->dli_next ) {
658 SlapReply r = { REP_SEARCH };
661 dynlist_sc_t dlc = { 0 };
663 if ( !is_entry_objectclass_or_sub( e, dli->dli_oc ))
666 /* if the entry has the right objectClass, generate
667 * the dynamic list and compare */
669 cb.sc_private = &dlc;
670 cb.sc_response = dynlist_sc_save_entry;
671 cb.sc_cleanup = NULL;
675 o.o_tag = LDAP_REQ_SEARCH;
677 o.ors_tlimit = SLAP_NO_LIMIT;
678 o.ors_slimit = SLAP_NO_LIMIT;
680 o.o_bd = select_backend( &o.o_req_ndn, 1 );
681 if ( !o.o_bd || !o.o_bd->be_search ) {
685 o.ors_filterstr = *slap_filterstr_objectClass_pres;
686 o.ors_filter = (Filter *) slap_filter_objectClass_pres;
688 o.ors_scope = LDAP_SCOPE_BASE;
689 o.ors_deref = LDAP_DEREF_NEVER;
690 an[0].an_name = op->orc_ava->aa_desc->ad_cname;
691 an[0].an_desc = op->orc_ava->aa_desc;
692 BER_BVZERO( &an[1].an_name );
696 o.o_acl_priv = ACL_COMPARE;
698 rc = o.o_bd->be_search( &o, &r );
700 if ( o.o_dn.bv_val != op->o_dn.bv_val ) {
701 slap_op_groups_free( &o );
708 if ( dlc.dlc_e != NULL ) {
709 r.sr_entry = dlc.dlc_e;
712 if ( r.sr_err != LDAP_SUCCESS || r.sr_entry == NULL ) {
717 for ( a = attrs_find( r.sr_entry->e_attrs, op->orc_ava->aa_desc );
719 a = attrs_find( a->a_next, op->orc_ava->aa_desc ) )
721 /* if we're here, we got a match... */
722 rs->sr_err = LDAP_COMPARE_FALSE;
724 if ( value_find_ex( op->orc_ava->aa_desc,
725 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
726 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
727 a->a_nvals, &op->orc_ava->aa_value, op->o_tmpmemctx ) == 0 )
729 rs->sr_err = LDAP_COMPARE_TRUE;
734 if ( r.sr_flags & REP_ENTRY_MUSTBEFREED ) {
735 entry_free( r.sr_entry );
741 overlay_entry_release_ov( &o, e, 0, on );
744 return SLAP_CB_CONTINUE;
748 dynlist_response( Operation *op, SlapReply *rs )
752 switch ( op->o_tag ) {
753 case LDAP_REQ_SEARCH:
754 if ( rs->sr_type == REP_SEARCH && !get_manageDSAit( op ) )
758 for ( dli = dynlist_is_dynlist_next( op, rs, NULL );
760 dli = dynlist_is_dynlist_next( op, rs, dli ) )
762 rc = dynlist_prepare_entry( op, rs, dli );
765 if ( rc != LDAP_OTHER ) {
771 case LDAP_REQ_COMPARE:
772 switch ( rs->sr_err ) {
773 /* NOTE: we waste a few cycles running the dynamic list
774 * also when the result is FALSE, which occurs if the
775 * dynamic entry itself contains the AVA attribute */
776 /* FIXME: this approach is less than optimal; a dedicated
777 * compare op should be implemented, that fetches the
778 * entry, checks if it has the appropriate objectClass
779 * and, in case, runs a compare thru all the URIs,
780 * stopping at the first positive occurrence; see ITS#3756 */
781 case LDAP_COMPARE_FALSE:
782 case LDAP_NO_SUCH_ATTRIBUTE:
783 return dynlist_compare( op, rs );
791 return SLAP_CB_CONTINUE;
795 dynlist_build_def_filter( dynlist_info_t *dli )
799 dli->dli_default_filter.bv_len = STRLENOF( "(!(objectClass=" "))" )
800 + dli->dli_oc->soc_cname.bv_len;
801 dli->dli_default_filter.bv_val = ch_malloc( dli->dli_default_filter.bv_len + 1 );
802 if ( dli->dli_default_filter.bv_val == NULL ) {
803 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: malloc failed.\n",
808 ptr = lutil_strcopy( dli->dli_default_filter.bv_val, "(!(objectClass=" );
809 ptr = lutil_strcopy( ptr, dli->dli_oc->soc_cname.bv_val );
810 ptr = lutil_strcopy( ptr, "))" );
812 assert( dli->dli_default_filter.bv_len == ptr - dli->dli_default_filter.bv_val );
826 slap_overinst *on = (slap_overinst *)be->bd_info;
830 if ( strcasecmp( argv[0], "dynlist-attrset" ) == 0 ) {
831 dynlist_info_t **dlip;
833 AttributeDescription *ad = NULL,
837 if ( argc < 3 || argc > 4 ) {
838 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
839 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
840 "invalid arg number #%d.\n",
841 fname, lineno, argc );
845 oc = oc_find( argv[1] );
847 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
848 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
849 "unable to find ObjectClass \"%s\"\n",
850 fname, lineno, argv[ 1 ] );
854 rc = slap_str2ad( argv[2], &ad, &text );
855 if ( rc != LDAP_SUCCESS ) {
856 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
857 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
858 "unable to find AttributeDescription \"%s\"\n",
859 fname, lineno, argv[2] );
863 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
864 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
865 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
866 "AttributeDescription \"%s\" "
867 "must be a subtype of \"labeledURI\"\n",
868 fname, lineno, argv[2] );
873 rc = slap_str2ad( argv[3], &member_ad, &text );
874 if ( rc != LDAP_SUCCESS ) {
875 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
876 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
877 "unable to find AttributeDescription \"%s\"\n",
878 fname, lineno, argv[3] );
883 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
884 *dlip; dlip = &(*dlip)->dli_next )
886 /* The same URL attribute / member attribute pair
887 * cannot be repeated */
888 if ( (*dlip)->dli_ad == ad && (*dlip)->dli_member_ad == member_ad ) {
889 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
890 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
891 "URL attributeDescription \"%s\" already mapped.\n",
892 fname, lineno, ad->ad_cname.bv_val );
894 /* make it a warning... */
900 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
901 (*dlip)->dli_oc = oc;
902 (*dlip)->dli_ad = ad;
903 (*dlip)->dli_member_ad = member_ad;
905 if ( dynlist_build_def_filter( *dlip ) ) {
911 /* allow dyngroup syntax */
912 } else if ( strcasecmp( argv[0], "dynlist-attrpair" ) == 0 ) {
913 dynlist_info_t **dlip;
915 AttributeDescription *ad = NULL,
920 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
921 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
922 "invalid arg number #%d.\n",
923 fname, lineno, argc );
927 oc = oc_find( "groupOfURLs" );
929 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
930 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
931 "unable to find default ObjectClass \"groupOfURLs\"\n",
936 rc = slap_str2ad( argv[1], &member_ad, &text );
937 if ( rc != LDAP_SUCCESS ) {
938 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
939 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
940 "unable to find AttributeDescription \"%s\"\n",
941 fname, lineno, argv[1] );
945 rc = slap_str2ad( argv[2], &ad, &text );
946 if ( rc != LDAP_SUCCESS ) {
947 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
948 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
949 "unable to find AttributeDescription \"%s\"\n",
950 fname, lineno, argv[2] );
954 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
955 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
956 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
957 "AttributeDescription \"%s\" "
958 "must be a subtype of \"labeledURI\"\n",
959 fname, lineno, argv[2] );
963 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
964 *dlip; dlip = &(*dlip)->dli_next )
966 /* The same URL attribute / member attribute pair
967 * cannot be repeated */
968 if ( (*dlip)->dli_ad == ad && (*dlip)->dli_member_ad == member_ad ) {
969 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
970 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
971 "URL attributeDescription \"%s\" already mapped.\n",
972 fname, lineno, ad->ad_cname.bv_val );
974 /* make it a warning... */
980 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
981 (*dlip)->dli_oc = oc;
982 (*dlip)->dli_ad = ad;
983 (*dlip)->dli_member_ad = member_ad;
985 if ( dynlist_build_def_filter( *dlip ) ) {
992 rc = SLAP_CONF_UNKNOWN;
1006 static ConfigDriver dl_cfgen;
1008 static ConfigTable dlcfg[] = {
1009 { "dynlist-attrset", "group-oc> <URL-ad> <member-ad",
1010 3, 4, 0, ARG_MAGIC|DL_ATTRSET, dl_cfgen,
1011 "( OLcfgOvAt:8.1 NAME 'olcDLattrSet' "
1012 "DESC 'Dynamic list: <group objectClass>, <URL attributeDescription>, <member attributeDescription>' "
1013 "EQUALITY caseIgnoreMatch "
1014 "SYNTAX OMsDirectoryString "
1015 "X-ORDERED 'VALUES' )",
1017 { "dynlist-attrpair", "member-ad> <URL-ad",
1018 3, 3, 0, ARG_MAGIC|DL_ATTRPAIR, dl_cfgen,
1020 #ifdef TAKEOVER_DYNGROUP
1021 { "attrpair", "member-ad> <URL-ad",
1022 3, 3, 0, ARG_MAGIC|DL_ATTRPAIR_COMPAT, dl_cfgen,
1025 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
1028 static ConfigOCs dlocs[] = {
1029 { "( OLcfgOvOc:8.1 "
1030 "NAME 'olcDynamicList' "
1031 "DESC 'Dynamic list configuration' "
1032 "SUP olcOverlayConfig "
1033 "MAY olcDLattrSet )",
1034 Cft_Overlay, dlcfg, NULL, NULL },
1039 dl_cfgen( ConfigArgs *c )
1041 slap_overinst *on = (slap_overinst *)c->bi;
1042 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private;
1046 if ( c->op == SLAP_CONFIG_EMIT ) {
1049 for ( i = 0; dli; i++, dli = dli->dli_next ) {
1051 char *ptr = c->cr_msg;
1053 assert( dli->dli_oc != NULL );
1054 assert( dli->dli_ad != NULL );
1056 ptr += snprintf( c->cr_msg, sizeof( c->cr_msg ),
1057 SLAP_X_ORDERED_FMT "%s %s", i,
1058 dli->dli_oc->soc_cname.bv_val,
1059 dli->dli_ad->ad_cname.bv_val );
1061 if ( dli->dli_member_ad != NULL ) {
1064 ptr = lutil_strcopy( ptr, dli->dli_member_ad->ad_cname.bv_val );
1067 bv.bv_val = c->cr_msg;
1068 bv.bv_len = ptr - bv.bv_val;
1069 value_add_one( &c->rvalue_vals, &bv );
1073 case DL_ATTRPAIR_COMPAT:
1085 } else if ( c->op == LDAP_MOD_DELETE ) {
1088 if ( c->valx < 0 ) {
1089 dynlist_info_t *dli_next;
1091 for ( dli_next = dli; dli_next; dli = dli_next ) {
1092 dli_next = dli->dli_next;
1094 ch_free( dli->dli_default_filter.bv_val );
1098 on->on_bi.bi_private = NULL;
1101 dynlist_info_t **dlip;
1103 for ( i = 0, dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1106 if ( *dlip == NULL ) {
1109 dlip = &(*dlip)->dli_next;
1113 *dlip = dli->dli_next;
1114 ch_free( dli->dli_default_filter.bv_val );
1117 dli = (dynlist_info_t *)on->on_bi.bi_private;
1121 case DL_ATTRPAIR_COMPAT:
1136 dynlist_info_t **dlip,
1138 ObjectClass *oc = NULL;
1139 AttributeDescription *ad = NULL,
1143 oc = oc_find( c->argv[ 1 ] );
1145 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1146 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1147 "unable to find ObjectClass \"%s\"",
1149 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1150 c->log, c->cr_msg, 0 );
1154 rc = slap_str2ad( c->argv[ 2 ], &ad, &text );
1155 if ( rc != LDAP_SUCCESS ) {
1156 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1157 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1158 "unable to find AttributeDescription \"%s\"",
1160 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1161 c->log, c->cr_msg, 0 );
1165 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
1166 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1167 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1168 "AttributeDescription \"%s\" "
1169 "must be a subtype of \"labeledURI\"",
1171 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1172 c->log, c->cr_msg, 0 );
1176 if ( c->argc == 4 ) {
1177 rc = slap_str2ad( c->argv[ 3 ], &member_ad, &text );
1178 if ( rc != LDAP_SUCCESS ) {
1179 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1180 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1181 "unable to find AttributeDescription \"%s\"\n",
1183 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1184 c->log, c->cr_msg, 0 );
1189 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1190 *dlip; dlip = &(*dlip)->dli_next )
1192 /* The same URL attribute / member attribute pair
1193 * cannot be repeated */
1194 if ( (*dlip)->dli_ad == ad && (*dlip)->dli_member_ad == member_ad ) {
1195 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1196 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1197 "URL attributeDescription \"%s\" already mapped.\n",
1198 ad->ad_cname.bv_val );
1199 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1200 c->log, c->cr_msg, 0 );
1202 /* make it a warning... */
1208 if ( c->valx > 0 ) {
1211 for ( i = 0, dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1214 if ( *dlip == NULL ) {
1215 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1216 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1217 "invalid index {%d}\n",
1219 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1220 c->log, c->cr_msg, 0 );
1223 dlip = &(*dlip)->dli_next;
1228 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1229 *dlip; dlip = &(*dlip)->dli_next )
1233 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
1235 (*dlip)->dli_oc = oc;
1236 (*dlip)->dli_ad = ad;
1237 (*dlip)->dli_member_ad = member_ad;
1238 (*dlip)->dli_next = dli_next;
1240 rc = dynlist_build_def_filter( *dlip );
1244 case DL_ATTRPAIR_COMPAT:
1245 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1246 "warning: \"attrpair\" only supported for limited "
1247 "backward compatibility with overlay \"dyngroup\"" );
1248 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
1252 dynlist_info_t **dlip;
1253 ObjectClass *oc = NULL;
1254 AttributeDescription *ad = NULL,
1258 oc = oc_find( "groupOfURLs" );
1260 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1261 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1262 "unable to find default ObjectClass \"groupOfURLs\"" );
1263 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1264 c->log, c->cr_msg, 0 );
1268 rc = slap_str2ad( c->argv[ 1 ], &member_ad, &text );
1269 if ( rc != LDAP_SUCCESS ) {
1270 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1271 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1272 "unable to find AttributeDescription \"%s\"",
1274 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1275 c->log, c->cr_msg, 0 );
1279 rc = slap_str2ad( c->argv[ 2 ], &ad, &text );
1280 if ( rc != LDAP_SUCCESS ) {
1281 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1282 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1283 "unable to find AttributeDescription \"%s\"\n",
1285 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1286 c->log, c->cr_msg, 0 );
1290 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
1291 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1292 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1293 "AttributeDescription \"%s\" "
1294 "must be a subtype of \"labeledURI\"",
1296 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1297 c->log, c->cr_msg, 0 );
1301 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1302 *dlip; dlip = &(*dlip)->dli_next )
1304 /* The same URL attribute / member attribute pair
1305 * cannot be repeated */
1306 if ( (*dlip)->dli_ad == ad && (*dlip)->dli_member_ad == member_ad ) {
1307 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1308 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1309 "URL attributeDescription \"%s\" already mapped.\n",
1310 ad->ad_cname.bv_val );
1311 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1312 c->log, c->cr_msg, 0 );
1314 /* make it a warning... */
1320 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
1322 (*dlip)->dli_oc = oc;
1323 (*dlip)->dli_ad = ad;
1324 (*dlip)->dli_member_ad = member_ad;
1326 rc = dynlist_build_def_filter( *dlip );
1344 slap_overinst *on = (slap_overinst *) be->bd_info;
1345 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private;
1346 ObjectClass *oc = NULL;
1347 AttributeDescription *ad = NULL;
1351 if ( dli == NULL ) {
1352 dli = ch_calloc( 1, sizeof( dynlist_info_t ) );
1353 on->on_bi.bi_private = (void *)dli;
1356 for ( ; dli; dli = dli->dli_next ) {
1357 if ( dli->dli_oc == NULL ) {
1359 oc = oc_find( "groupOfURLs" );
1361 sprintf( cr->msg, "unable to fetch objectClass \"groupOfURLs\"" );
1362 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: %s.\n", cr->msg, 0, 0 );
1370 if ( dli->dli_ad == NULL ) {
1372 rc = slap_str2ad( "memberURL", &ad, &text );
1373 if ( rc != LDAP_SUCCESS ) {
1374 sprintf( cr->msg, "unable to fetch attributeDescription \"memberURL\": %d (%s)",
1376 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: %s.\n", cr->msg, 0, 0 );
1384 if ( BER_BVISNULL( &dli->dli_default_filter ) ) {
1385 rc = dynlist_build_def_filter( dli );
1392 rc = slap_str2ad( "dgIdentity", &ad_dgIdentity, &text );
1393 if ( rc != LDAP_SUCCESS ) {
1394 snprintf( cr->msg, sizeof( cr->msg),
1395 "unable to fetch attributeDescription \"dgIdentity\": %d (%s)",
1397 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: %s\n", cr->msg, 0, 0 );
1398 /* Just a warning */
1401 rc = slap_str2ad( "dgAuthz", &ad_dgAuthz, &text );
1402 if ( rc != LDAP_SUCCESS ) {
1403 snprintf( cr->msg, sizeof( cr->msg),
1404 "unable to fetch attributeDescription \"dgAuthz\": %d (%s)",
1406 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: %s\n", cr->msg, 0, 0 );
1407 /* Just a warning */
1418 slap_overinst *on = (slap_overinst *) be->bd_info;
1420 if ( on->on_bi.bi_private ) {
1421 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private,
1424 for ( dli_next = dli; dli_next; dli = dli_next ) {
1425 dli_next = dli->dli_next;
1427 ch_free( dli->dli_default_filter.bv_val );
1435 static slap_overinst dynlist = { { NULL } };
1436 #ifdef TAKEOVER_DYNGROUP
1437 static char *obsolete_names[] = {
1443 #if SLAPD_OVER_DYNLIST == SLAPD_MOD_DYNAMIC
1445 #endif /* SLAPD_OVER_DYNLIST == SLAPD_MOD_DYNAMIC */
1447 dynlist_initialize(void)
1449 #ifndef OL_2_2_COMPAT
1453 dynlist.on_bi.bi_type = "dynlist";
1455 #ifdef TAKEOVER_DYNGROUP
1456 /* makes dynlist incompatible with dyngroup */
1457 dynlist.on_bi.bi_obsolete_names = obsolete_names;
1460 #ifdef OL_2_2_COMPAT
1461 dynlist.on_bi.bi_db_config = dynlist_db_config;
1463 dynlist.on_bi.bi_db_config = config_generic_wrapper;
1465 dynlist.on_bi.bi_db_open = dynlist_db_open;
1466 dynlist.on_bi.bi_db_destroy = dynlist_db_destroy;
1468 dynlist.on_response = dynlist_response;
1470 #ifndef OL_2_2_COMPAT
1471 dynlist.on_bi.bi_cf_ocs = dlocs;
1473 rc = config_register_schema( dlcfg, dlocs );
1479 return overlay_register( &dynlist );
1482 #if SLAPD_OVER_DYNLIST == SLAPD_MOD_DYNAMIC
1484 init_module( int argc, char *argv[] )
1486 return dynlist_initialize();
1490 #endif /* SLAPD_OVER_DYNLIST */