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 */
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;
338 opattrs = ( rs->sr_attrs == NULL ) ? 0 : an_find( rs->sr_attrs, &AllOper );
339 userattrs = ( rs->sr_attrs == NULL ) ? 1 : an_find( rs->sr_attrs, &AllUser );
340 #else /* SLAP_OPATTRS */
341 opattrs = SLAP_OPATTRS( rs->sr_attr_flags );
342 userattrs = SLAP_USERATTRS( rs->sr_attr_flags );
343 #endif /* SLAP_OPATTRS */
345 /* Don't generate member list if it wasn't requested */
346 if ( dli->dli_member_ad && !userattrs && !ad_inlist( dli->dli_member_ad, rs->sr_attrs ) ) {
347 return SLAP_CB_CONTINUE;
350 if ( ad_dgIdentity && ( id = attrs_find( rs->sr_entry->e_attrs, ad_dgIdentity ))) {
351 Attribute *authz = NULL;
353 /* if not rootdn and dgAuthz is present,
354 * check if user can be authorized as dgIdentity */
355 if ( ad_dgAuthz && !BER_BVISEMPTY( &id->a_nvals[0] ) && !be_isroot( op )
356 && ( authz = attrs_find( rs->sr_entry->e_attrs, ad_dgAuthz ) ) )
358 if ( slap_sasl_matches( op, authz->a_nvals,
359 &o.o_ndn, &o.o_ndn ) != LDAP_SUCCESS )
361 return SLAP_CB_CONTINUE;
365 o.o_dn = id->a_vals[0];
366 o.o_ndn = id->a_nvals[0];
370 if ( !( rs->sr_flags & REP_ENTRY_MODIFIABLE ) ) {
371 e = entry_dup( rs->sr_entry );
375 e_flags = rs->sr_flags | ( REP_ENTRY_MODIFIABLE | REP_ENTRY_MUSTBEFREED );
379 cb.sc_private = &dlc;
380 cb.sc_response = dynlist_sc_update;
381 cb.sc_cleanup = NULL;
385 o.ors_deref = LDAP_DEREF_NEVER;
387 o.ors_tlimit = SLAP_NO_LIMIT;
388 o.ors_slimit = SLAP_NO_LIMIT;
390 for ( url = a->a_nvals; !BER_BVISNULL( url ); url++ ) {
391 LDAPURLDesc *lud = NULL;
396 BER_BVZERO( &o.o_req_dn );
397 BER_BVZERO( &o.o_req_ndn );
400 BER_BVZERO( &o.ors_filterstr );
402 if ( ldap_url_parse( url->bv_val, &lud ) != LDAP_URL_SUCCESS ) {
407 if ( lud->lud_host != NULL ) {
408 /* FIXME: host not allowed; reject as illegal? */
409 Debug( LDAP_DEBUG_ANY, "dynlist_prepare_entry(\"%s\"): "
410 "illegal URI \"%s\"\n",
411 e->e_name.bv_val, url->bv_val, 0 );
415 if ( lud->lud_dn == NULL ) {
416 /* note that an empty base is not honored in terms
417 * of defaultSearchBase, because select_backend()
418 * is not aware of the defaultSearchBase option;
419 * this can be useful in case of a database serving
420 * the empty suffix */
421 BER_BVSTR( &dn, "" );
424 ber_str2bv( lud->lud_dn, 0, 0, &dn );
426 rc = dnPrettyNormal( NULL, &dn, &o.o_req_dn, &o.o_req_ndn, op->o_tmpmemctx );
427 if ( rc != LDAP_SUCCESS ) {
431 o.ors_scope = lud->lud_scope;
433 if ( dli->dli_member_ad != NULL ) {
434 /* if ( lud->lud_attrs != NULL ),
435 * the URL should be ignored */
436 o.ors_attrs = slap_anlist_no_attrs;
438 } else if ( lud->lud_attrs == NULL ) {
439 o.ors_attrs = rs->sr_attrs;
442 for ( i = 0; lud->lud_attrs[i]; i++)
445 o.ors_attrs = op->o_tmpcalloc( i + 1, sizeof( AttributeName ), op->o_tmpmemctx );
446 for ( i = 0, j = 0; lud->lud_attrs[i]; i++) {
447 const char *text = NULL;
449 ber_str2bv( lud->lud_attrs[i], 0, 0, &o.ors_attrs[j].an_name );
450 o.ors_attrs[j].an_desc = NULL;
451 (void)slap_bv2ad( &o.ors_attrs[j].an_name, &o.ors_attrs[j].an_desc, &text );
452 /* FIXME: ignore errors... */
454 if ( rs->sr_attrs == NULL ) {
455 if ( o.ors_attrs[j].an_desc != NULL &&
456 is_at_operational( o.ors_attrs[j].an_desc->ad_type ) )
462 if ( o.ors_attrs[j].an_desc != NULL &&
463 is_at_operational( o.ors_attrs[j].an_desc->ad_type ) )
465 if ( !opattrs && !ad_inlist( o.ors_attrs[j].an_desc, rs->sr_attrs ) )
472 o.ors_attrs[j].an_desc != NULL &&
473 !ad_inlist( o.ors_attrs[j].an_desc, rs->sr_attrs ) )
487 BER_BVZERO( &o.ors_attrs[j].an_name );
490 if ( lud->lud_filter == NULL ) {
491 ber_dupbv_x( &o.ors_filterstr,
492 &dli->dli_default_filter, op->o_tmpmemctx );
496 ber_str2bv( lud->lud_filter, 0, 0, &flt );
497 if ( dynlist_make_filter( op, &flt, &o.ors_filterstr ) ) {
502 o.ors_filter = str2filter_x( op, o.ors_filterstr.bv_val );
503 if ( o.ors_filter == NULL ) {
507 o.o_bd = select_backend( &o.o_req_ndn, 1 );
508 if ( o.o_bd && o.o_bd->be_search ) {
510 r.sr_attr_flags = slap_attr_flags( o.ors_attrs );
511 #endif /* SLAP_OPATTRS */
512 (void)o.o_bd->be_search( &o, &r );
517 slap_op_groups_free( &o );
519 if ( o.ors_filter ) {
520 filter_free_x( &o, o.ors_filter );
522 if ( o.ors_attrs && o.ors_attrs != rs->sr_attrs
523 && o.ors_attrs != slap_anlist_no_attrs )
525 op->o_tmpfree( o.ors_attrs, op->o_tmpmemctx );
527 if ( !BER_BVISNULL( &o.o_req_dn ) ) {
528 op->o_tmpfree( o.o_req_dn.bv_val, op->o_tmpmemctx );
530 if ( !BER_BVISNULL( &o.o_req_ndn ) ) {
531 op->o_tmpfree( o.o_req_ndn.bv_val, op->o_tmpmemctx );
533 assert( BER_BVISNULL( &o.ors_filterstr )
534 || o.ors_filterstr.bv_val != lud->lud_filter );
535 op->o_tmpfree( o.ors_filterstr.bv_val, op->o_tmpmemctx );
536 ldap_free_urldesc( lud );
540 rs->sr_flags = e_flags;
542 return SLAP_CB_CONTINUE;
546 dynlist_sc_save_entry( Operation *op, SlapReply *rs )
548 /* save the entry in the private field of the callback,
549 * so it doesn't get freed (it's temporary!) */
550 if ( rs->sr_entry != NULL ) {
551 dynlist_sc_t *dlc = (dynlist_sc_t *)op->o_callback->sc_private;
552 dlc->dlc_e = rs->sr_entry;
560 dynlist_compare( Operation *op, SlapReply *rs )
562 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
563 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private;
567 for ( ; dli != NULL; dli = dli->dli_next ) {
568 if ( op->oq_compare.rs_ava->aa_desc == dli->dli_member_ad ) {
569 /* This compare is for one of the attributes we're
570 * interested in. We'll use slapd's existing dyngroup
571 * evaluator to get the answer we want.
573 BerVarray id = NULL, authz = NULL;
575 o.o_do_not_cache = 1;
577 if ( ad_dgIdentity && backend_attribute( &o, NULL, &o.o_req_ndn,
578 ad_dgIdentity, &id, ACL_READ ) == LDAP_SUCCESS )
580 /* if not rootdn and dgAuthz is present,
581 * check if user can be authorized as dgIdentity */
582 if ( ad_dgAuthz && !BER_BVISEMPTY( id ) && !be_isroot( op )
583 && backend_attribute( &o, NULL, &o.o_req_ndn,
584 ad_dgAuthz, &authz, ACL_READ ) == LDAP_SUCCESS )
587 rs->sr_err = slap_sasl_matches( op, authz,
588 &o.o_ndn, &o.o_ndn );
589 ber_bvarray_free_x( authz, op->o_tmpmemctx );
590 if ( rs->sr_err != LDAP_SUCCESS ) {
597 o.o_groups = NULL; /* authz changed, invalidate cached groups */
600 rs->sr_err = backend_group( &o, NULL, &o.o_req_ndn,
601 &o.oq_compare.rs_ava->aa_value, dli->dli_oc, dli->dli_ad );
602 switch ( rs->sr_err ) {
604 rs->sr_err = LDAP_COMPARE_TRUE;
607 case LDAP_NO_SUCH_OBJECT:
608 /* NOTE: backend_group() returns noSuchObject
609 * if op_ndn does not exist; however, since
610 * dynamic list expansion means that the
611 * member attribute is virtually present, the
612 * non-existence of the asserted value implies
613 * the assertion is FALSE rather than
615 rs->sr_err = LDAP_COMPARE_FALSE;
620 if ( id ) ber_bvarray_free_x( id, o.o_tmpmemctx );
622 return SLAP_CB_CONTINUE;
626 if ( overlay_entry_get_ov( &o, &o.o_req_ndn, NULL, NULL, 0, &e, on ) !=
627 LDAP_SUCCESS || e == NULL )
629 return SLAP_CB_CONTINUE;
632 if ( ad_dgIdentity ) {
633 Attribute *id = attrs_find( e->e_attrs, ad_dgIdentity );
637 /* if not rootdn and dgAuthz is present,
638 * check if user can be authorized as dgIdentity */
639 if ( ad_dgAuthz && !BER_BVISEMPTY( &id->a_nvals[0] ) && !be_isroot( op )
640 && ( authz = attrs_find( e->e_attrs, ad_dgAuthz ) ) )
642 if ( slap_sasl_matches( op, authz->a_nvals,
643 &o.o_ndn, &o.o_ndn ) != LDAP_SUCCESS )
649 o.o_dn = id->a_vals[0];
650 o.o_ndn = id->a_nvals[0];
655 dli = (dynlist_info_t *)on->on_bi.bi_private;
656 for ( ; dli != NULL && rs->sr_err != LDAP_COMPARE_TRUE; dli = dli->dli_next ) {
659 SlapReply r = { REP_SEARCH };
662 dynlist_sc_t dlc = { 0 };
664 if ( !is_entry_objectclass_or_sub( e, dli->dli_oc ))
667 /* if the entry has the right objectClass, generate
668 * the dynamic list and compare */
670 cb.sc_private = &dlc;
671 cb.sc_response = dynlist_sc_save_entry;
672 cb.sc_cleanup = NULL;
676 o.o_tag = LDAP_REQ_SEARCH;
678 o.ors_tlimit = SLAP_NO_LIMIT;
679 o.ors_slimit = SLAP_NO_LIMIT;
681 o.o_bd = select_backend( &o.o_req_ndn, 1 );
682 if ( !o.o_bd || !o.o_bd->be_search ) {
686 BER_BVSTR( &o.ors_filterstr, "(objectClass=*)" );
687 o.ors_filter = str2filter_x( op, o.ors_filterstr.bv_val );
688 if ( o.ors_filter == NULL ) {
693 o.ors_scope = LDAP_SCOPE_BASE;
694 o.ors_deref = LDAP_DEREF_NEVER;
695 an[0].an_name = op->orc_ava->aa_desc->ad_cname;
696 an[0].an_desc = op->orc_ava->aa_desc;
697 BER_BVZERO( &an[1].an_name );
701 o.o_acl_priv = ACL_COMPARE;
703 rc = o.o_bd->be_search( &o, &r );
704 filter_free_x( &o, o.ors_filter );
706 if ( o.o_dn.bv_val != op->o_dn.bv_val ) {
707 slap_op_groups_free( &o );
714 if ( dlc.dlc_e != NULL ) {
715 r.sr_entry = dlc.dlc_e;
718 if ( r.sr_err != LDAP_SUCCESS || r.sr_entry == NULL ) {
723 for ( a = attrs_find( r.sr_entry->e_attrs, op->orc_ava->aa_desc );
725 a = attrs_find( a->a_next, op->orc_ava->aa_desc ) )
727 /* if we're here, we got a match... */
728 rs->sr_err = LDAP_COMPARE_FALSE;
730 if ( value_find_ex( op->orc_ava->aa_desc,
731 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
732 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
733 a->a_nvals, &op->orc_ava->aa_value, op->o_tmpmemctx ) == 0 )
735 rs->sr_err = LDAP_COMPARE_TRUE;
740 if ( r.sr_flags & REP_ENTRY_MUSTBEFREED ) {
741 entry_free( r.sr_entry );
747 overlay_entry_release_ov( &o, e, 0, on );
750 return SLAP_CB_CONTINUE;
754 dynlist_response( Operation *op, SlapReply *rs )
758 switch ( op->o_tag ) {
759 case LDAP_REQ_SEARCH:
760 if ( rs->sr_type == REP_SEARCH && !get_manageDSAit( op ) )
764 for ( dli = dynlist_is_dynlist_next( op, rs, NULL );
766 dli = dynlist_is_dynlist_next( op, rs, dli ) )
768 rc = dynlist_prepare_entry( op, rs, dli );
771 if ( rc != LDAP_OTHER ) {
777 case LDAP_REQ_COMPARE:
778 switch ( rs->sr_err ) {
779 /* NOTE: we waste a few cycles running the dynamic list
780 * also when the result is FALSE, which occurs if the
781 * dynamic entry itself contains the AVA attribute */
782 /* FIXME: this approach is less than optimal; a dedicated
783 * compare op should be implemented, that fetches the
784 * entry, checks if it has the appropriate objectClass
785 * and, in case, runs a compare thru all the URIs,
786 * stopping at the first positive occurrence; see ITS#3756 */
787 case LDAP_COMPARE_FALSE:
788 case LDAP_NO_SUCH_ATTRIBUTE:
789 return dynlist_compare( op, rs );
797 return SLAP_CB_CONTINUE;
801 dynlist_build_def_filter( dynlist_info_t *dli )
805 dli->dli_default_filter.bv_len = STRLENOF( "(!(objectClass=" "))" )
806 + dli->dli_oc->soc_cname.bv_len;
807 dli->dli_default_filter.bv_val = ch_malloc( dli->dli_default_filter.bv_len + 1 );
808 if ( dli->dli_default_filter.bv_val == NULL ) {
809 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: malloc failed.\n",
814 ptr = lutil_strcopy( dli->dli_default_filter.bv_val, "(!(objectClass=" );
815 ptr = lutil_strcopy( ptr, dli->dli_oc->soc_cname.bv_val );
816 ptr = lutil_strcopy( ptr, "))" );
818 assert( dli->dli_default_filter.bv_len == ptr - dli->dli_default_filter.bv_val );
832 slap_overinst *on = (slap_overinst *)be->bd_info;
836 if ( strcasecmp( argv[0], "dynlist-attrset" ) == 0 ) {
837 dynlist_info_t **dlip;
839 AttributeDescription *ad = NULL,
843 if ( argc < 3 || argc > 4 ) {
844 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
845 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
846 "invalid arg number #%d.\n",
847 fname, lineno, argc );
851 oc = oc_find( argv[1] );
853 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
854 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
855 "unable to find ObjectClass \"%s\"\n",
856 fname, lineno, argv[ 1 ] );
860 rc = slap_str2ad( argv[2], &ad, &text );
861 if ( rc != LDAP_SUCCESS ) {
862 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
863 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
864 "unable to find AttributeDescription \"%s\"\n",
865 fname, lineno, argv[2] );
869 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
870 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
871 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
872 "AttributeDescription \"%s\" "
873 "must be a subtype of \"labeledURI\"\n",
874 fname, lineno, argv[2] );
879 rc = slap_str2ad( argv[3], &member_ad, &text );
880 if ( rc != LDAP_SUCCESS ) {
881 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
882 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
883 "unable to find AttributeDescription \"%s\"\n",
884 fname, lineno, argv[3] );
889 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
890 *dlip; dlip = &(*dlip)->dli_next )
892 /* The same URL attribute / member attribute pair
893 * cannot be repeated */
894 if ( (*dlip)->dli_ad == ad && (*dlip)->dli_member_ad == member_ad ) {
895 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
896 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
897 "URL attributeDescription \"%s\" already mapped.\n",
898 fname, lineno, ad->ad_cname.bv_val );
900 /* make it a warning... */
906 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
907 (*dlip)->dli_oc = oc;
908 (*dlip)->dli_ad = ad;
909 (*dlip)->dli_member_ad = member_ad;
911 if ( dynlist_build_def_filter( *dlip ) ) {
917 /* allow dyngroup syntax */
918 } else if ( strcasecmp( argv[0], "dynlist-attrpair" ) == 0 ) {
919 dynlist_info_t **dlip;
921 AttributeDescription *ad = NULL,
926 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
927 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
928 "invalid arg number #%d.\n",
929 fname, lineno, argc );
933 oc = oc_find( "groupOfURLs" );
935 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
936 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
937 "unable to find default ObjectClass \"groupOfURLs\"\n",
942 rc = slap_str2ad( argv[1], &member_ad, &text );
943 if ( rc != LDAP_SUCCESS ) {
944 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
945 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
946 "unable to find AttributeDescription \"%s\"\n",
947 fname, lineno, argv[1] );
951 rc = slap_str2ad( argv[2], &ad, &text );
952 if ( rc != LDAP_SUCCESS ) {
953 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
954 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
955 "unable to find AttributeDescription \"%s\"\n",
956 fname, lineno, argv[2] );
960 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
961 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
962 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
963 "AttributeDescription \"%s\" "
964 "must be a subtype of \"labeledURI\"\n",
965 fname, lineno, argv[2] );
969 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
970 *dlip; dlip = &(*dlip)->dli_next )
972 /* The same URL attribute / member attribute pair
973 * cannot be repeated */
974 if ( (*dlip)->dli_ad == ad && (*dlip)->dli_member_ad == member_ad ) {
975 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
976 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
977 "URL attributeDescription \"%s\" already mapped.\n",
978 fname, lineno, ad->ad_cname.bv_val );
980 /* make it a warning... */
986 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
987 (*dlip)->dli_oc = oc;
988 (*dlip)->dli_ad = ad;
989 (*dlip)->dli_member_ad = member_ad;
991 if ( dynlist_build_def_filter( *dlip ) ) {
998 rc = SLAP_CONF_UNKNOWN;
1012 static ConfigDriver dl_cfgen;
1014 static ConfigTable dlcfg[] = {
1015 { "dynlist-attrset", "group-oc> <URL-ad> <member-ad",
1016 3, 4, 0, ARG_MAGIC|DL_ATTRSET, dl_cfgen,
1017 "( OLcfgOvAt:8.1 NAME 'olcDLattrSet' "
1018 "DESC 'Dynamic list: <group objectClass>, <URL attributeDescription>, <member attributeDescription>' "
1019 "EQUALITY caseIgnoreMatch "
1020 "SYNTAX OMsDirectoryString "
1021 "X-ORDERED 'VALUES' )",
1023 { "dynlist-attrpair", "member-ad> <URL-ad",
1024 3, 3, 0, ARG_MAGIC|DL_ATTRPAIR, dl_cfgen,
1026 #ifdef TAKEOVER_DYNGROUP
1027 { "attrpair", "member-ad> <URL-ad",
1028 3, 3, 0, ARG_MAGIC|DL_ATTRPAIR_COMPAT, dl_cfgen,
1031 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
1034 static ConfigOCs dlocs[] = {
1035 { "( OLcfgOvOc:8.1 "
1036 "NAME 'olcDynamicList' "
1037 "DESC 'Dynamic list configuration' "
1038 "SUP olcOverlayConfig "
1039 "MAY olcDLattrSet )",
1040 Cft_Overlay, dlcfg, NULL, NULL },
1045 dl_cfgen( ConfigArgs *c )
1047 slap_overinst *on = (slap_overinst *)c->bi;
1048 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private;
1052 if ( c->op == SLAP_CONFIG_EMIT ) {
1055 for ( i = 0; dli; i++, dli = dli->dli_next ) {
1057 char *ptr = c->cr_msg;
1059 assert( dli->dli_oc != NULL );
1060 assert( dli->dli_ad != NULL );
1062 ptr += snprintf( c->cr_msg, sizeof( c->cr_msg ),
1063 SLAP_X_ORDERED_FMT "%s %s", i,
1064 dli->dli_oc->soc_cname.bv_val,
1065 dli->dli_ad->ad_cname.bv_val );
1067 if ( dli->dli_member_ad != NULL ) {
1070 ptr = lutil_strcopy( ptr, dli->dli_member_ad->ad_cname.bv_val );
1073 bv.bv_val = c->cr_msg;
1074 bv.bv_len = ptr - bv.bv_val;
1075 value_add_one( &c->rvalue_vals, &bv );
1079 case DL_ATTRPAIR_COMPAT:
1091 } else if ( c->op == LDAP_MOD_DELETE ) {
1094 if ( c->valx < 0 ) {
1095 dynlist_info_t *dli_next;
1097 for ( dli_next = dli; dli_next; dli = dli_next ) {
1098 dli_next = dli->dli_next;
1100 ch_free( dli->dli_default_filter.bv_val );
1104 on->on_bi.bi_private = NULL;
1107 dynlist_info_t **dlip;
1109 for ( i = 0, dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1112 if ( *dlip == NULL ) {
1115 dlip = &(*dlip)->dli_next;
1119 *dlip = dli->dli_next;
1120 ch_free( dli->dli_default_filter.bv_val );
1123 dli = (dynlist_info_t *)on->on_bi.bi_private;
1127 case DL_ATTRPAIR_COMPAT:
1142 dynlist_info_t **dlip,
1144 ObjectClass *oc = NULL;
1145 AttributeDescription *ad = NULL,
1149 oc = oc_find( c->argv[ 1 ] );
1151 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1152 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1153 "unable to find ObjectClass \"%s\"",
1155 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1156 c->log, c->cr_msg, 0 );
1160 rc = slap_str2ad( c->argv[ 2 ], &ad, &text );
1161 if ( rc != LDAP_SUCCESS ) {
1162 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1163 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1164 "unable to find AttributeDescription \"%s\"",
1166 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1167 c->log, c->cr_msg, 0 );
1171 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
1172 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1173 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1174 "AttributeDescription \"%s\" "
1175 "must be a subtype of \"labeledURI\"",
1177 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1178 c->log, c->cr_msg, 0 );
1182 if ( c->argc == 4 ) {
1183 rc = slap_str2ad( c->argv[ 3 ], &member_ad, &text );
1184 if ( rc != LDAP_SUCCESS ) {
1185 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1186 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1187 "unable to find AttributeDescription \"%s\"\n",
1189 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1190 c->log, c->cr_msg, 0 );
1195 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1196 *dlip; dlip = &(*dlip)->dli_next )
1198 /* The same URL attribute / member attribute pair
1199 * cannot be repeated */
1200 if ( (*dlip)->dli_ad == ad && (*dlip)->dli_member_ad == member_ad ) {
1201 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1202 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1203 "URL attributeDescription \"%s\" already mapped.\n",
1204 ad->ad_cname.bv_val );
1205 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1206 c->log, c->cr_msg, 0 );
1208 /* make it a warning... */
1214 if ( c->valx > 0 ) {
1217 for ( i = 0, dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1220 if ( *dlip == NULL ) {
1221 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1222 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1223 "invalid index {%d}\n",
1225 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1226 c->log, c->cr_msg, 0 );
1229 dlip = &(*dlip)->dli_next;
1234 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1235 *dlip; dlip = &(*dlip)->dli_next )
1239 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
1241 (*dlip)->dli_oc = oc;
1242 (*dlip)->dli_ad = ad;
1243 (*dlip)->dli_member_ad = member_ad;
1244 (*dlip)->dli_next = dli_next;
1246 rc = dynlist_build_def_filter( *dlip );
1250 case DL_ATTRPAIR_COMPAT:
1251 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1252 "warning: \"attrpair\" only supported for limited "
1253 "backward compatibility with overlay \"dyngroup\"" );
1254 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
1258 dynlist_info_t **dlip;
1259 ObjectClass *oc = NULL;
1260 AttributeDescription *ad = NULL,
1264 oc = oc_find( "groupOfURLs" );
1266 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1267 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1268 "unable to find default ObjectClass \"groupOfURLs\"" );
1269 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1270 c->log, c->cr_msg, 0 );
1274 rc = slap_str2ad( c->argv[ 1 ], &member_ad, &text );
1275 if ( rc != LDAP_SUCCESS ) {
1276 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1277 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1278 "unable to find AttributeDescription \"%s\"",
1280 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1281 c->log, c->cr_msg, 0 );
1285 rc = slap_str2ad( c->argv[ 2 ], &ad, &text );
1286 if ( rc != LDAP_SUCCESS ) {
1287 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1288 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1289 "unable to find AttributeDescription \"%s\"\n",
1291 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1292 c->log, c->cr_msg, 0 );
1296 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
1297 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1298 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1299 "AttributeDescription \"%s\" "
1300 "must be a subtype of \"labeledURI\"",
1302 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1303 c->log, c->cr_msg, 0 );
1307 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1308 *dlip; dlip = &(*dlip)->dli_next )
1310 /* The same URL attribute / member attribute pair
1311 * cannot be repeated */
1312 if ( (*dlip)->dli_ad == ad && (*dlip)->dli_member_ad == member_ad ) {
1313 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1314 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1315 "URL attributeDescription \"%s\" already mapped.\n",
1316 ad->ad_cname.bv_val );
1317 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1318 c->log, c->cr_msg, 0 );
1320 /* make it a warning... */
1326 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
1328 (*dlip)->dli_oc = oc;
1329 (*dlip)->dli_ad = ad;
1330 (*dlip)->dli_member_ad = member_ad;
1332 rc = dynlist_build_def_filter( *dlip );
1350 slap_overinst *on = (slap_overinst *) be->bd_info;
1351 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private;
1352 ObjectClass *oc = NULL;
1353 AttributeDescription *ad = NULL;
1357 if ( dli == NULL ) {
1358 dli = ch_calloc( 1, sizeof( dynlist_info_t ) );
1359 on->on_bi.bi_private = (void *)dli;
1362 for ( ; dli; dli = dli->dli_next ) {
1363 if ( dli->dli_oc == NULL ) {
1365 oc = oc_find( "groupOfURLs" );
1367 sprintf( cr->msg, "unable to fetch objectClass \"groupOfURLs\"" );
1368 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: %s.\n", cr->msg, 0, 0 );
1376 if ( dli->dli_ad == NULL ) {
1378 rc = slap_str2ad( "memberURL", &ad, &text );
1379 if ( rc != LDAP_SUCCESS ) {
1380 sprintf( cr->msg, "unable to fetch attributeDescription \"memberURL\": %d (%s)",
1382 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: %s.\n", cr->msg, 0, 0 );
1390 if ( BER_BVISNULL( &dli->dli_default_filter ) ) {
1391 rc = dynlist_build_def_filter( dli );
1398 rc = slap_str2ad( "dgIdentity", &ad_dgIdentity, &text );
1399 if ( rc != LDAP_SUCCESS ) {
1400 snprintf( cr->msg, sizeof( cr->msg),
1401 "unable to fetch attributeDescription \"dgIdentity\": %d (%s)",
1403 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: %s\n", cr->msg, 0, 0 );
1404 /* Just a warning */
1407 rc = slap_str2ad( "dgAuthz", &ad_dgAuthz, &text );
1408 if ( rc != LDAP_SUCCESS ) {
1409 snprintf( cr->msg, sizeof( cr->msg),
1410 "unable to fetch attributeDescription \"dgAuthz\": %d (%s)",
1412 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: %s\n", cr->msg, 0, 0 );
1413 /* Just a warning */
1424 slap_overinst *on = (slap_overinst *) be->bd_info;
1426 if ( on->on_bi.bi_private ) {
1427 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private,
1430 for ( dli_next = dli; dli_next; dli = dli_next ) {
1431 dli_next = dli->dli_next;
1433 ch_free( dli->dli_default_filter.bv_val );
1441 static slap_overinst dynlist = { { NULL } };
1442 #ifdef TAKEOVER_DYNGROUP
1443 static char *obsolete_names[] = {
1449 #if SLAPD_OVER_DYNLIST == SLAPD_MOD_DYNAMIC
1451 #endif /* SLAPD_OVER_DYNLIST == SLAPD_MOD_DYNAMIC */
1453 dynlist_initialize(void)
1455 #ifndef OL_2_2_COMPAT
1459 dynlist.on_bi.bi_type = "dynlist";
1461 #ifdef TAKEOVER_DYNGROUP
1462 /* makes dynlist incompatible with dyngroup */
1463 dynlist.on_bi.bi_obsolete_names = obsolete_names;
1466 #ifdef OL_2_2_COMPAT
1467 dynlist.on_bi.bi_db_config = dynlist_db_config;
1469 dynlist.on_bi.bi_db_config = config_generic_wrapper;
1471 dynlist.on_bi.bi_db_open = dynlist_db_open;
1472 dynlist.on_bi.bi_db_destroy = dynlist_db_destroy;
1474 dynlist.on_response = dynlist_response;
1476 #ifndef OL_2_2_COMPAT
1477 dynlist.on_bi.bi_cf_ocs = dlocs;
1479 rc = config_register_schema( dlcfg, dlocs );
1485 return overlay_register( &dynlist );
1488 #if SLAPD_OVER_DYNLIST == SLAPD_MOD_DYNAMIC
1490 init_module( int argc, char *argv[] )
1492 return dynlist_initialize();
1496 #endif /* SLAPD_OVER_DYNLIST */