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 ) {
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 ( ad_dgIdentity && ( id = attrs_find( rs->sr_entry->e_attrs, ad_dgIdentity ))) {
352 Attribute *authz = NULL;
354 /* if not rootdn and dgAuthz is present,
355 * check if user can be authorized as dgIdentity */
356 if ( ad_dgAuthz && !BER_BVISEMPTY( &id->a_nvals[0] ) && !be_isroot( op )
357 && ( authz = attrs_find( rs->sr_entry->e_attrs, ad_dgAuthz ) ) )
359 if ( slap_sasl_matches( op, authz->a_nvals,
360 &o.o_ndn, &o.o_ndn ) != LDAP_SUCCESS )
362 return SLAP_CB_CONTINUE;
366 o.o_dn = id->a_vals[0];
367 o.o_ndn = id->a_nvals[0];
371 if ( !( rs->sr_flags & REP_ENTRY_MODIFIABLE ) ) {
372 e = entry_dup( rs->sr_entry );
376 e_flags = rs->sr_flags | ( REP_ENTRY_MODIFIABLE | REP_ENTRY_MUSTBEFREED );
380 cb.sc_private = &dlc;
381 cb.sc_response = dynlist_sc_update;
382 cb.sc_cleanup = NULL;
386 o.ors_deref = LDAP_DEREF_NEVER;
388 o.ors_tlimit = SLAP_NO_LIMIT;
389 o.ors_slimit = SLAP_NO_LIMIT;
391 for ( url = a->a_nvals; !BER_BVISNULL( url ); url++ ) {
392 LDAPURLDesc *lud = NULL;
397 BER_BVZERO( &o.o_req_dn );
398 BER_BVZERO( &o.o_req_ndn );
401 BER_BVZERO( &o.ors_filterstr );
403 if ( ldap_url_parse( url->bv_val, &lud ) != LDAP_URL_SUCCESS ) {
408 if ( lud->lud_host != NULL ) {
409 /* FIXME: host not allowed; reject as illegal? */
410 Debug( LDAP_DEBUG_ANY, "dynlist_prepare_entry(\"%s\"): "
411 "illegal URI \"%s\"\n",
412 e->e_name.bv_val, url->bv_val, 0 );
416 if ( lud->lud_dn == NULL ) {
417 /* note that an empty base is not honored in terms
418 * of defaultSearchBase, because select_backend()
419 * is not aware of the defaultSearchBase option;
420 * this can be useful in case of a database serving
421 * the empty suffix */
422 BER_BVSTR( &dn, "" );
425 ber_str2bv( lud->lud_dn, 0, 0, &dn );
427 rc = dnPrettyNormal( NULL, &dn, &o.o_req_dn, &o.o_req_ndn, op->o_tmpmemctx );
428 if ( rc != LDAP_SUCCESS ) {
432 o.ors_scope = lud->lud_scope;
434 if ( dli->dli_member_ad != NULL ) {
435 /* if ( lud->lud_attrs != NULL ),
436 * the URL should be ignored */
437 o.ors_attrs = slap_anlist_no_attrs;
439 } else if ( lud->lud_attrs == NULL ) {
440 o.ors_attrs = rs->sr_attrs;
443 for ( i = 0; lud->lud_attrs[i]; i++)
446 o.ors_attrs = op->o_tmpcalloc( i + 1, sizeof( AttributeName ), op->o_tmpmemctx );
447 for ( i = 0, j = 0; lud->lud_attrs[i]; i++) {
448 const char *text = NULL;
450 ber_str2bv( lud->lud_attrs[i], 0, 0, &o.ors_attrs[j].an_name );
451 o.ors_attrs[j].an_desc = NULL;
452 (void)slap_bv2ad( &o.ors_attrs[j].an_name, &o.ors_attrs[j].an_desc, &text );
453 /* FIXME: ignore errors... */
455 if ( rs->sr_attrs == NULL ) {
456 if ( o.ors_attrs[j].an_desc != NULL &&
457 is_at_operational( o.ors_attrs[j].an_desc->ad_type ) )
463 if ( o.ors_attrs[j].an_desc != NULL &&
464 is_at_operational( o.ors_attrs[j].an_desc->ad_type ) )
466 if ( !opattrs && !ad_inlist( o.ors_attrs[j].an_desc, rs->sr_attrs ) )
473 o.ors_attrs[j].an_desc != NULL &&
474 !ad_inlist( o.ors_attrs[j].an_desc, rs->sr_attrs ) )
488 BER_BVZERO( &o.ors_attrs[j].an_name );
491 if ( lud->lud_filter == NULL ) {
492 ber_dupbv_x( &o.ors_filterstr,
493 &dli->dli_default_filter, op->o_tmpmemctx );
497 ber_str2bv( lud->lud_filter, 0, 0, &flt );
498 if ( dynlist_make_filter( op, &flt, &o.ors_filterstr ) ) {
503 o.ors_filter = str2filter_x( op, o.ors_filterstr.bv_val );
504 if ( o.ors_filter == NULL ) {
508 o.o_bd = select_backend( &o.o_req_ndn, 1 );
509 if ( o.o_bd && o.o_bd->be_search ) {
511 r.sr_attr_flags = slap_attr_flags( o.ors_attrs );
512 #endif /* SLAP_OPATTRS */
513 (void)o.o_bd->be_search( &o, &r );
518 slap_op_groups_free( &o );
520 if ( o.ors_filter ) {
521 filter_free_x( &o, o.ors_filter );
523 if ( o.ors_attrs && o.ors_attrs != rs->sr_attrs
524 && o.ors_attrs != slap_anlist_no_attrs )
526 op->o_tmpfree( o.ors_attrs, op->o_tmpmemctx );
528 if ( !BER_BVISNULL( &o.o_req_dn ) ) {
529 op->o_tmpfree( o.o_req_dn.bv_val, op->o_tmpmemctx );
531 if ( !BER_BVISNULL( &o.o_req_ndn ) ) {
532 op->o_tmpfree( o.o_req_ndn.bv_val, op->o_tmpmemctx );
534 assert( BER_BVISNULL( &o.ors_filterstr )
535 || o.ors_filterstr.bv_val != lud->lud_filter );
536 op->o_tmpfree( o.ors_filterstr.bv_val, op->o_tmpmemctx );
537 ldap_free_urldesc( lud );
541 rs->sr_flags = e_flags;
543 return SLAP_CB_CONTINUE;
547 dynlist_sc_save_entry( Operation *op, SlapReply *rs )
549 /* save the entry in the private field of the callback,
550 * so it doesn't get freed (it's temporary!) */
551 if ( rs->sr_entry != NULL ) {
552 dynlist_sc_t *dlc = (dynlist_sc_t *)op->o_callback->sc_private;
553 dlc->dlc_e = rs->sr_entry;
561 dynlist_compare( Operation *op, SlapReply *rs )
563 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
564 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private;
568 for ( ; dli != NULL; dli = dli->dli_next ) {
569 if ( op->oq_compare.rs_ava->aa_desc == dli->dli_member_ad ) {
570 /* This compare is for one of the attributes we're
571 * interested in. We'll use slapd's existing dyngroup
572 * evaluator to get the answer we want.
574 BerVarray id = NULL, authz = NULL;
576 o.o_do_not_cache = 1;
578 if ( ad_dgIdentity && backend_attribute( &o, NULL, &o.o_req_ndn,
579 ad_dgIdentity, &id, ACL_READ ) == LDAP_SUCCESS )
581 /* if not rootdn and dgAuthz is present,
582 * check if user can be authorized as dgIdentity */
583 if ( ad_dgAuthz && !BER_BVISEMPTY( id ) && !be_isroot( op )
584 && backend_attribute( &o, NULL, &o.o_req_ndn,
585 ad_dgAuthz, &authz, ACL_READ ) == LDAP_SUCCESS )
588 rs->sr_err = slap_sasl_matches( op, authz,
589 &o.o_ndn, &o.o_ndn );
590 ber_bvarray_free_x( authz, op->o_tmpmemctx );
591 if ( rs->sr_err != LDAP_SUCCESS ) {
598 o.o_groups = NULL; /* authz changed, invalidate cached groups */
601 rs->sr_err = backend_group( &o, NULL, &o.o_req_ndn,
602 &o.oq_compare.rs_ava->aa_value, dli->dli_oc, dli->dli_ad );
603 switch ( rs->sr_err ) {
605 rs->sr_err = LDAP_COMPARE_TRUE;
608 case LDAP_NO_SUCH_OBJECT:
609 /* NOTE: backend_group() returns noSuchObject
610 * if op_ndn does not exist; however, since
611 * dynamic list expansion means that the
612 * member attribute is virtually present, the
613 * non-existence of the asserted value implies
614 * the assertion is FALSE rather than
616 rs->sr_err = LDAP_COMPARE_FALSE;
621 if ( id ) ber_bvarray_free_x( id, o.o_tmpmemctx );
623 return SLAP_CB_CONTINUE;
627 if ( overlay_entry_get_ov( &o, &o.o_req_ndn, NULL, NULL, 0, &e, on ) !=
628 LDAP_SUCCESS || e == NULL )
630 return SLAP_CB_CONTINUE;
633 if ( ad_dgIdentity ) {
634 Attribute *id = attrs_find( e->e_attrs, ad_dgIdentity );
638 /* if not rootdn and dgAuthz is present,
639 * check if user can be authorized as dgIdentity */
640 if ( ad_dgAuthz && !BER_BVISEMPTY( &id->a_nvals[0] ) && !be_isroot( op )
641 && ( authz = attrs_find( e->e_attrs, ad_dgAuthz ) ) )
643 if ( slap_sasl_matches( op, authz->a_nvals,
644 &o.o_ndn, &o.o_ndn ) != LDAP_SUCCESS )
650 o.o_dn = id->a_vals[0];
651 o.o_ndn = id->a_nvals[0];
656 dli = (dynlist_info_t *)on->on_bi.bi_private;
657 for ( ; dli != NULL && rs->sr_err != LDAP_COMPARE_TRUE; dli = dli->dli_next ) {
660 SlapReply r = { REP_SEARCH };
663 dynlist_sc_t dlc = { 0 };
665 if ( !is_entry_objectclass_or_sub( e, dli->dli_oc ))
668 /* if the entry has the right objectClass, generate
669 * the dynamic list and compare */
671 cb.sc_private = &dlc;
672 cb.sc_response = dynlist_sc_save_entry;
673 cb.sc_cleanup = NULL;
677 o.o_tag = LDAP_REQ_SEARCH;
679 o.ors_tlimit = SLAP_NO_LIMIT;
680 o.ors_slimit = SLAP_NO_LIMIT;
682 o.o_bd = select_backend( &o.o_req_ndn, 1 );
683 if ( !o.o_bd || !o.o_bd->be_search ) {
687 o.ors_filterstr = *slap_filterstr_objectClass_pres;
688 o.ors_filter = (Filter *) slap_filter_objectClass_pres;
690 o.ors_scope = LDAP_SCOPE_BASE;
691 o.ors_deref = LDAP_DEREF_NEVER;
692 an[0].an_name = op->orc_ava->aa_desc->ad_cname;
693 an[0].an_desc = op->orc_ava->aa_desc;
694 BER_BVZERO( &an[1].an_name );
698 o.o_acl_priv = ACL_COMPARE;
700 rc = o.o_bd->be_search( &o, &r );
702 if ( o.o_dn.bv_val != op->o_dn.bv_val ) {
703 slap_op_groups_free( &o );
710 if ( dlc.dlc_e != NULL ) {
711 r.sr_entry = dlc.dlc_e;
714 if ( r.sr_err != LDAP_SUCCESS || r.sr_entry == NULL ) {
719 for ( a = attrs_find( r.sr_entry->e_attrs, op->orc_ava->aa_desc );
721 a = attrs_find( a->a_next, op->orc_ava->aa_desc ) )
723 /* if we're here, we got a match... */
724 rs->sr_err = LDAP_COMPARE_FALSE;
726 if ( attr_valfind( a,
727 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
728 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
729 &op->orc_ava->aa_value, NULL, op->o_tmpmemctx ) == 0 )
731 rs->sr_err = LDAP_COMPARE_TRUE;
736 if ( r.sr_flags & REP_ENTRY_MUSTBEFREED ) {
737 entry_free( r.sr_entry );
743 overlay_entry_release_ov( &o, e, 0, on );
746 return SLAP_CB_CONTINUE;
750 dynlist_response( Operation *op, SlapReply *rs )
754 switch ( op->o_tag ) {
755 case LDAP_REQ_SEARCH:
756 if ( rs->sr_type == REP_SEARCH && !get_manageDSAit( op ) )
760 for ( dli = dynlist_is_dynlist_next( op, rs, NULL );
762 dli = dynlist_is_dynlist_next( op, rs, dli ) )
764 rc = dynlist_prepare_entry( op, rs, dli );
767 if ( rc != LDAP_OTHER ) {
773 case LDAP_REQ_COMPARE:
774 switch ( rs->sr_err ) {
775 /* NOTE: we waste a few cycles running the dynamic list
776 * also when the result is FALSE, which occurs if the
777 * dynamic entry itself contains the AVA attribute */
778 /* FIXME: this approach is less than optimal; a dedicated
779 * compare op should be implemented, that fetches the
780 * entry, checks if it has the appropriate objectClass
781 * and, in case, runs a compare thru all the URIs,
782 * stopping at the first positive occurrence; see ITS#3756 */
783 case LDAP_COMPARE_FALSE:
784 case LDAP_NO_SUCH_ATTRIBUTE:
785 return dynlist_compare( op, rs );
793 return SLAP_CB_CONTINUE;
797 dynlist_build_def_filter( dynlist_info_t *dli )
801 dli->dli_default_filter.bv_len = STRLENOF( "(!(objectClass=" "))" )
802 + dli->dli_oc->soc_cname.bv_len;
803 dli->dli_default_filter.bv_val = ch_malloc( dli->dli_default_filter.bv_len + 1 );
804 if ( dli->dli_default_filter.bv_val == NULL ) {
805 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: malloc failed.\n",
810 ptr = lutil_strcopy( dli->dli_default_filter.bv_val, "(!(objectClass=" );
811 ptr = lutil_strcopy( ptr, dli->dli_oc->soc_cname.bv_val );
812 ptr = lutil_strcopy( ptr, "))" );
814 assert( dli->dli_default_filter.bv_len == ptr - dli->dli_default_filter.bv_val );
828 slap_overinst *on = (slap_overinst *)be->bd_info;
832 if ( strcasecmp( argv[0], "dynlist-attrset" ) == 0 ) {
833 dynlist_info_t **dlip;
835 AttributeDescription *ad = NULL,
839 if ( argc < 3 || argc > 4 ) {
840 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
841 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
842 "invalid arg number #%d.\n",
843 fname, lineno, argc );
847 oc = oc_find( argv[1] );
849 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
850 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
851 "unable to find ObjectClass \"%s\"\n",
852 fname, lineno, argv[ 1 ] );
856 rc = slap_str2ad( argv[2], &ad, &text );
857 if ( rc != LDAP_SUCCESS ) {
858 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
859 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
860 "unable to find AttributeDescription \"%s\"\n",
861 fname, lineno, argv[2] );
865 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
866 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
867 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
868 "AttributeDescription \"%s\" "
869 "must be a subtype of \"labeledURI\"\n",
870 fname, lineno, argv[2] );
875 rc = slap_str2ad( argv[3], &member_ad, &text );
876 if ( rc != LDAP_SUCCESS ) {
877 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
878 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
879 "unable to find AttributeDescription \"%s\"\n",
880 fname, lineno, argv[3] );
885 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
886 *dlip; dlip = &(*dlip)->dli_next )
888 /* The same URL attribute / member attribute pair
889 * cannot be repeated */
890 if ( (*dlip)->dli_ad == ad && (*dlip)->dli_member_ad == member_ad ) {
891 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
892 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
893 "URL attributeDescription \"%s\" already mapped.\n",
894 fname, lineno, ad->ad_cname.bv_val );
896 /* make it a warning... */
902 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
903 (*dlip)->dli_oc = oc;
904 (*dlip)->dli_ad = ad;
905 (*dlip)->dli_member_ad = member_ad;
907 if ( dynlist_build_def_filter( *dlip ) ) {
913 /* allow dyngroup syntax */
914 } else if ( strcasecmp( argv[0], "dynlist-attrpair" ) == 0 ) {
915 dynlist_info_t **dlip;
917 AttributeDescription *ad = NULL,
922 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
923 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
924 "invalid arg number #%d.\n",
925 fname, lineno, argc );
929 oc = oc_find( "groupOfURLs" );
931 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
932 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
933 "unable to find default ObjectClass \"groupOfURLs\"\n",
938 rc = slap_str2ad( argv[1], &member_ad, &text );
939 if ( rc != LDAP_SUCCESS ) {
940 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
941 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
942 "unable to find AttributeDescription \"%s\"\n",
943 fname, lineno, argv[1] );
947 rc = slap_str2ad( argv[2], &ad, &text );
948 if ( rc != LDAP_SUCCESS ) {
949 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
950 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
951 "unable to find AttributeDescription \"%s\"\n",
952 fname, lineno, argv[2] );
956 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
957 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
958 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
959 "AttributeDescription \"%s\" "
960 "must be a subtype of \"labeledURI\"\n",
961 fname, lineno, argv[2] );
965 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
966 *dlip; dlip = &(*dlip)->dli_next )
968 /* The same URL attribute / member attribute pair
969 * cannot be repeated */
970 if ( (*dlip)->dli_ad == ad && (*dlip)->dli_member_ad == member_ad ) {
971 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
972 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
973 "URL attributeDescription \"%s\" already mapped.\n",
974 fname, lineno, ad->ad_cname.bv_val );
976 /* make it a warning... */
982 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
983 (*dlip)->dli_oc = oc;
984 (*dlip)->dli_ad = ad;
985 (*dlip)->dli_member_ad = member_ad;
987 if ( dynlist_build_def_filter( *dlip ) ) {
994 rc = SLAP_CONF_UNKNOWN;
1008 static ConfigDriver dl_cfgen;
1010 static ConfigTable dlcfg[] = {
1011 { "dynlist-attrset", "group-oc> <URL-ad> <member-ad",
1012 3, 4, 0, ARG_MAGIC|DL_ATTRSET, dl_cfgen,
1013 "( OLcfgOvAt:8.1 NAME 'olcDLattrSet' "
1014 "DESC 'Dynamic list: <group objectClass>, <URL attributeDescription>, <member attributeDescription>' "
1015 "EQUALITY caseIgnoreMatch "
1016 "SYNTAX OMsDirectoryString "
1017 "X-ORDERED 'VALUES' )",
1019 { "dynlist-attrpair", "member-ad> <URL-ad",
1020 3, 3, 0, ARG_MAGIC|DL_ATTRPAIR, dl_cfgen,
1022 #ifdef TAKEOVER_DYNGROUP
1023 { "attrpair", "member-ad> <URL-ad",
1024 3, 3, 0, ARG_MAGIC|DL_ATTRPAIR_COMPAT, dl_cfgen,
1027 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
1030 static ConfigOCs dlocs[] = {
1031 { "( OLcfgOvOc:8.1 "
1032 "NAME 'olcDynamicList' "
1033 "DESC 'Dynamic list configuration' "
1034 "SUP olcOverlayConfig "
1035 "MAY olcDLattrSet )",
1036 Cft_Overlay, dlcfg, NULL, NULL },
1041 dl_cfgen( ConfigArgs *c )
1043 slap_overinst *on = (slap_overinst *)c->bi;
1044 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private;
1048 if ( c->op == SLAP_CONFIG_EMIT ) {
1051 for ( i = 0; dli; i++, dli = dli->dli_next ) {
1053 char *ptr = c->cr_msg;
1055 assert( dli->dli_oc != NULL );
1056 assert( dli->dli_ad != NULL );
1058 ptr += snprintf( c->cr_msg, sizeof( c->cr_msg ),
1059 SLAP_X_ORDERED_FMT "%s %s", i,
1060 dli->dli_oc->soc_cname.bv_val,
1061 dli->dli_ad->ad_cname.bv_val );
1063 if ( dli->dli_member_ad != NULL ) {
1066 ptr = lutil_strcopy( ptr, dli->dli_member_ad->ad_cname.bv_val );
1069 bv.bv_val = c->cr_msg;
1070 bv.bv_len = ptr - bv.bv_val;
1071 value_add_one( &c->rvalue_vals, &bv );
1075 case DL_ATTRPAIR_COMPAT:
1087 } else if ( c->op == LDAP_MOD_DELETE ) {
1090 if ( c->valx < 0 ) {
1091 dynlist_info_t *dli_next;
1093 for ( dli_next = dli; dli_next; dli = dli_next ) {
1094 dli_next = dli->dli_next;
1096 ch_free( dli->dli_default_filter.bv_val );
1100 on->on_bi.bi_private = NULL;
1103 dynlist_info_t **dlip;
1105 for ( i = 0, dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1108 if ( *dlip == NULL ) {
1111 dlip = &(*dlip)->dli_next;
1115 *dlip = dli->dli_next;
1116 ch_free( dli->dli_default_filter.bv_val );
1119 dli = (dynlist_info_t *)on->on_bi.bi_private;
1123 case DL_ATTRPAIR_COMPAT:
1138 dynlist_info_t **dlip,
1140 ObjectClass *oc = NULL;
1141 AttributeDescription *ad = NULL,
1145 oc = oc_find( c->argv[ 1 ] );
1147 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1148 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1149 "unable to find ObjectClass \"%s\"",
1151 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1152 c->log, c->cr_msg, 0 );
1156 rc = slap_str2ad( c->argv[ 2 ], &ad, &text );
1157 if ( rc != LDAP_SUCCESS ) {
1158 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1159 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1160 "unable to find AttributeDescription \"%s\"",
1162 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1163 c->log, c->cr_msg, 0 );
1167 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
1168 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1169 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1170 "AttributeDescription \"%s\" "
1171 "must be a subtype of \"labeledURI\"",
1173 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1174 c->log, c->cr_msg, 0 );
1178 if ( c->argc == 4 ) {
1179 rc = slap_str2ad( c->argv[ 3 ], &member_ad, &text );
1180 if ( rc != LDAP_SUCCESS ) {
1181 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1182 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1183 "unable to find AttributeDescription \"%s\"\n",
1185 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1186 c->log, c->cr_msg, 0 );
1191 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1192 *dlip; dlip = &(*dlip)->dli_next )
1194 /* The same URL attribute / member attribute pair
1195 * cannot be repeated */
1196 if ( (*dlip)->dli_ad == ad && (*dlip)->dli_member_ad == member_ad ) {
1197 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1198 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1199 "URL attributeDescription \"%s\" already mapped.\n",
1200 ad->ad_cname.bv_val );
1201 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1202 c->log, c->cr_msg, 0 );
1204 /* make it a warning... */
1210 if ( c->valx > 0 ) {
1213 for ( i = 0, dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1216 if ( *dlip == NULL ) {
1217 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1218 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1219 "invalid index {%d}\n",
1221 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1222 c->log, c->cr_msg, 0 );
1225 dlip = &(*dlip)->dli_next;
1230 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1231 *dlip; dlip = &(*dlip)->dli_next )
1235 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
1237 (*dlip)->dli_oc = oc;
1238 (*dlip)->dli_ad = ad;
1239 (*dlip)->dli_member_ad = member_ad;
1240 (*dlip)->dli_next = dli_next;
1242 rc = dynlist_build_def_filter( *dlip );
1246 case DL_ATTRPAIR_COMPAT:
1247 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1248 "warning: \"attrpair\" only supported for limited "
1249 "backward compatibility with overlay \"dyngroup\"" );
1250 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
1254 dynlist_info_t **dlip;
1255 ObjectClass *oc = NULL;
1256 AttributeDescription *ad = NULL,
1260 oc = oc_find( "groupOfURLs" );
1262 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1263 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1264 "unable to find default ObjectClass \"groupOfURLs\"" );
1265 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1266 c->log, c->cr_msg, 0 );
1270 rc = slap_str2ad( c->argv[ 1 ], &member_ad, &text );
1271 if ( rc != LDAP_SUCCESS ) {
1272 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1273 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1274 "unable to find AttributeDescription \"%s\"",
1276 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1277 c->log, c->cr_msg, 0 );
1281 rc = slap_str2ad( c->argv[ 2 ], &ad, &text );
1282 if ( rc != LDAP_SUCCESS ) {
1283 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1284 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1285 "unable to find AttributeDescription \"%s\"\n",
1287 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1288 c->log, c->cr_msg, 0 );
1292 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
1293 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1294 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1295 "AttributeDescription \"%s\" "
1296 "must be a subtype of \"labeledURI\"",
1298 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1299 c->log, c->cr_msg, 0 );
1303 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1304 *dlip; dlip = &(*dlip)->dli_next )
1306 /* The same URL attribute / member attribute pair
1307 * cannot be repeated */
1308 if ( (*dlip)->dli_ad == ad && (*dlip)->dli_member_ad == member_ad ) {
1309 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1310 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1311 "URL attributeDescription \"%s\" already mapped.\n",
1312 ad->ad_cname.bv_val );
1313 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1314 c->log, c->cr_msg, 0 );
1316 /* make it a warning... */
1322 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
1324 (*dlip)->dli_oc = oc;
1325 (*dlip)->dli_ad = ad;
1326 (*dlip)->dli_member_ad = member_ad;
1328 rc = dynlist_build_def_filter( *dlip );
1346 slap_overinst *on = (slap_overinst *) be->bd_info;
1347 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private;
1348 ObjectClass *oc = NULL;
1349 AttributeDescription *ad = NULL;
1353 if ( dli == NULL ) {
1354 dli = ch_calloc( 1, sizeof( dynlist_info_t ) );
1355 on->on_bi.bi_private = (void *)dli;
1358 for ( ; dli; dli = dli->dli_next ) {
1359 if ( dli->dli_oc == NULL ) {
1361 oc = oc_find( "groupOfURLs" );
1363 snprintf( cr->msg, sizeof( cr->msg),
1364 "unable to fetch objectClass \"groupOfURLs\"" );
1365 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: %s.\n", cr->msg, 0, 0 );
1373 if ( dli->dli_ad == NULL ) {
1375 rc = slap_str2ad( "memberURL", &ad, &text );
1376 if ( rc != LDAP_SUCCESS ) {
1377 snprintf( cr->msg, sizeof( cr->msg),
1378 "unable to fetch attributeDescription \"memberURL\": %d (%s)",
1380 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: %s.\n", cr->msg, 0, 0 );
1388 if ( BER_BVISNULL( &dli->dli_default_filter ) ) {
1389 rc = dynlist_build_def_filter( dli );
1396 rc = slap_str2ad( "dgIdentity", &ad_dgIdentity, &text );
1397 if ( rc != LDAP_SUCCESS ) {
1398 snprintf( cr->msg, sizeof( cr->msg),
1399 "unable to fetch attributeDescription \"dgIdentity\": %d (%s)",
1401 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: %s\n", cr->msg, 0, 0 );
1402 /* Just a warning */
1405 rc = slap_str2ad( "dgAuthz", &ad_dgAuthz, &text );
1406 if ( rc != LDAP_SUCCESS ) {
1407 snprintf( cr->msg, sizeof( cr->msg),
1408 "unable to fetch attributeDescription \"dgAuthz\": %d (%s)",
1410 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: %s\n", cr->msg, 0, 0 );
1411 /* Just a warning */
1422 slap_overinst *on = (slap_overinst *) be->bd_info;
1424 if ( on->on_bi.bi_private ) {
1425 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private,
1428 for ( dli_next = dli; dli_next; dli = dli_next ) {
1429 dli_next = dli->dli_next;
1431 ch_free( dli->dli_default_filter.bv_val );
1439 static slap_overinst dynlist = { { NULL } };
1440 #ifdef TAKEOVER_DYNGROUP
1441 static char *obsolete_names[] = {
1447 #if SLAPD_OVER_DYNLIST == SLAPD_MOD_DYNAMIC
1449 #endif /* SLAPD_OVER_DYNLIST == SLAPD_MOD_DYNAMIC */
1451 dynlist_initialize(void)
1453 #ifndef OL_2_2_COMPAT
1457 dynlist.on_bi.bi_type = "dynlist";
1459 #ifdef TAKEOVER_DYNGROUP
1460 /* makes dynlist incompatible with dyngroup */
1461 dynlist.on_bi.bi_obsolete_names = obsolete_names;
1464 #ifdef OL_2_2_COMPAT
1465 dynlist.on_bi.bi_db_config = dynlist_db_config;
1467 dynlist.on_bi.bi_db_config = config_generic_wrapper;
1469 dynlist.on_bi.bi_db_open = dynlist_db_open;
1470 dynlist.on_bi.bi_db_destroy = dynlist_db_destroy;
1472 dynlist.on_response = dynlist_response;
1474 #ifndef OL_2_2_COMPAT
1475 dynlist.on_bi.bi_cf_ocs = dlocs;
1477 rc = config_register_schema( dlcfg, dlocs );
1483 return overlay_register( &dynlist );
1486 #if SLAPD_OVER_DYNLIST == SLAPD_MOD_DYNAMIC
1488 init_module( int argc, char *argv[] )
1490 return dynlist_initialize();
1494 #endif /* SLAPD_OVER_DYNLIST */