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 o.ors_filterstr = *slap_filterstr_objectClass_pres;
687 o.ors_filter = (Filter *) slap_filter_objectClass_pres;
689 o.ors_scope = LDAP_SCOPE_BASE;
690 o.ors_deref = LDAP_DEREF_NEVER;
691 an[0].an_name = op->orc_ava->aa_desc->ad_cname;
692 an[0].an_desc = op->orc_ava->aa_desc;
693 BER_BVZERO( &an[1].an_name );
697 o.o_acl_priv = ACL_COMPARE;
699 rc = o.o_bd->be_search( &o, &r );
701 if ( o.o_dn.bv_val != op->o_dn.bv_val ) {
702 slap_op_groups_free( &o );
709 if ( dlc.dlc_e != NULL ) {
710 r.sr_entry = dlc.dlc_e;
713 if ( r.sr_err != LDAP_SUCCESS || r.sr_entry == NULL ) {
718 for ( a = attrs_find( r.sr_entry->e_attrs, op->orc_ava->aa_desc );
720 a = attrs_find( a->a_next, op->orc_ava->aa_desc ) )
722 /* if we're here, we got a match... */
723 rs->sr_err = LDAP_COMPARE_FALSE;
725 if ( value_find_ex( op->orc_ava->aa_desc,
726 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
727 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
728 a->a_nvals, &op->orc_ava->aa_value, op->o_tmpmemctx ) == 0 )
730 rs->sr_err = LDAP_COMPARE_TRUE;
735 if ( r.sr_flags & REP_ENTRY_MUSTBEFREED ) {
736 entry_free( r.sr_entry );
742 overlay_entry_release_ov( &o, e, 0, on );
745 return SLAP_CB_CONTINUE;
749 dynlist_response( Operation *op, SlapReply *rs )
753 switch ( op->o_tag ) {
754 case LDAP_REQ_SEARCH:
755 if ( rs->sr_type == REP_SEARCH && !get_manageDSAit( op ) )
759 for ( dli = dynlist_is_dynlist_next( op, rs, NULL );
761 dli = dynlist_is_dynlist_next( op, rs, dli ) )
763 rc = dynlist_prepare_entry( op, rs, dli );
766 if ( rc != LDAP_OTHER ) {
772 case LDAP_REQ_COMPARE:
773 switch ( rs->sr_err ) {
774 /* NOTE: we waste a few cycles running the dynamic list
775 * also when the result is FALSE, which occurs if the
776 * dynamic entry itself contains the AVA attribute */
777 /* FIXME: this approach is less than optimal; a dedicated
778 * compare op should be implemented, that fetches the
779 * entry, checks if it has the appropriate objectClass
780 * and, in case, runs a compare thru all the URIs,
781 * stopping at the first positive occurrence; see ITS#3756 */
782 case LDAP_COMPARE_FALSE:
783 case LDAP_NO_SUCH_ATTRIBUTE:
784 return dynlist_compare( op, rs );
792 return SLAP_CB_CONTINUE;
796 dynlist_build_def_filter( dynlist_info_t *dli )
800 dli->dli_default_filter.bv_len = STRLENOF( "(!(objectClass=" "))" )
801 + dli->dli_oc->soc_cname.bv_len;
802 dli->dli_default_filter.bv_val = ch_malloc( dli->dli_default_filter.bv_len + 1 );
803 if ( dli->dli_default_filter.bv_val == NULL ) {
804 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: malloc failed.\n",
809 ptr = lutil_strcopy( dli->dli_default_filter.bv_val, "(!(objectClass=" );
810 ptr = lutil_strcopy( ptr, dli->dli_oc->soc_cname.bv_val );
811 ptr = lutil_strcopy( ptr, "))" );
813 assert( dli->dli_default_filter.bv_len == ptr - dli->dli_default_filter.bv_val );
827 slap_overinst *on = (slap_overinst *)be->bd_info;
831 if ( strcasecmp( argv[0], "dynlist-attrset" ) == 0 ) {
832 dynlist_info_t **dlip;
834 AttributeDescription *ad = NULL,
838 if ( argc < 3 || argc > 4 ) {
839 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
840 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
841 "invalid arg number #%d.\n",
842 fname, lineno, argc );
846 oc = oc_find( argv[1] );
848 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
849 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
850 "unable to find ObjectClass \"%s\"\n",
851 fname, lineno, argv[ 1 ] );
855 rc = slap_str2ad( argv[2], &ad, &text );
856 if ( rc != LDAP_SUCCESS ) {
857 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
858 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
859 "unable to find AttributeDescription \"%s\"\n",
860 fname, lineno, argv[2] );
864 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
865 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
866 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
867 "AttributeDescription \"%s\" "
868 "must be a subtype of \"labeledURI\"\n",
869 fname, lineno, argv[2] );
874 rc = slap_str2ad( argv[3], &member_ad, &text );
875 if ( rc != LDAP_SUCCESS ) {
876 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
877 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
878 "unable to find AttributeDescription \"%s\"\n",
879 fname, lineno, argv[3] );
884 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
885 *dlip; dlip = &(*dlip)->dli_next )
887 /* The same URL attribute / member attribute pair
888 * cannot be repeated */
889 if ( (*dlip)->dli_ad == ad && (*dlip)->dli_member_ad == member_ad ) {
890 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
891 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
892 "URL attributeDescription \"%s\" already mapped.\n",
893 fname, lineno, ad->ad_cname.bv_val );
895 /* make it a warning... */
901 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
902 (*dlip)->dli_oc = oc;
903 (*dlip)->dli_ad = ad;
904 (*dlip)->dli_member_ad = member_ad;
906 if ( dynlist_build_def_filter( *dlip ) ) {
912 /* allow dyngroup syntax */
913 } else if ( strcasecmp( argv[0], "dynlist-attrpair" ) == 0 ) {
914 dynlist_info_t **dlip;
916 AttributeDescription *ad = NULL,
921 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
922 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
923 "invalid arg number #%d.\n",
924 fname, lineno, argc );
928 oc = oc_find( "groupOfURLs" );
930 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
931 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
932 "unable to find default ObjectClass \"groupOfURLs\"\n",
937 rc = slap_str2ad( argv[1], &member_ad, &text );
938 if ( rc != LDAP_SUCCESS ) {
939 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
940 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
941 "unable to find AttributeDescription \"%s\"\n",
942 fname, lineno, argv[1] );
946 rc = slap_str2ad( argv[2], &ad, &text );
947 if ( rc != LDAP_SUCCESS ) {
948 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
949 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
950 "unable to find AttributeDescription \"%s\"\n",
951 fname, lineno, argv[2] );
955 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
956 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
957 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
958 "AttributeDescription \"%s\" "
959 "must be a subtype of \"labeledURI\"\n",
960 fname, lineno, argv[2] );
964 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
965 *dlip; dlip = &(*dlip)->dli_next )
967 /* The same URL attribute / member attribute pair
968 * cannot be repeated */
969 if ( (*dlip)->dli_ad == ad && (*dlip)->dli_member_ad == member_ad ) {
970 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
971 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
972 "URL attributeDescription \"%s\" already mapped.\n",
973 fname, lineno, ad->ad_cname.bv_val );
975 /* make it a warning... */
981 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
982 (*dlip)->dli_oc = oc;
983 (*dlip)->dli_ad = ad;
984 (*dlip)->dli_member_ad = member_ad;
986 if ( dynlist_build_def_filter( *dlip ) ) {
993 rc = SLAP_CONF_UNKNOWN;
1007 static ConfigDriver dl_cfgen;
1009 static ConfigTable dlcfg[] = {
1010 { "dynlist-attrset", "group-oc> <URL-ad> <member-ad",
1011 3, 4, 0, ARG_MAGIC|DL_ATTRSET, dl_cfgen,
1012 "( OLcfgOvAt:8.1 NAME 'olcDLattrSet' "
1013 "DESC 'Dynamic list: <group objectClass>, <URL attributeDescription>, <member attributeDescription>' "
1014 "EQUALITY caseIgnoreMatch "
1015 "SYNTAX OMsDirectoryString "
1016 "X-ORDERED 'VALUES' )",
1018 { "dynlist-attrpair", "member-ad> <URL-ad",
1019 3, 3, 0, ARG_MAGIC|DL_ATTRPAIR, dl_cfgen,
1021 #ifdef TAKEOVER_DYNGROUP
1022 { "attrpair", "member-ad> <URL-ad",
1023 3, 3, 0, ARG_MAGIC|DL_ATTRPAIR_COMPAT, dl_cfgen,
1026 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
1029 static ConfigOCs dlocs[] = {
1030 { "( OLcfgOvOc:8.1 "
1031 "NAME 'olcDynamicList' "
1032 "DESC 'Dynamic list configuration' "
1033 "SUP olcOverlayConfig "
1034 "MAY olcDLattrSet )",
1035 Cft_Overlay, dlcfg, NULL, NULL },
1040 dl_cfgen( ConfigArgs *c )
1042 slap_overinst *on = (slap_overinst *)c->bi;
1043 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private;
1047 if ( c->op == SLAP_CONFIG_EMIT ) {
1050 for ( i = 0; dli; i++, dli = dli->dli_next ) {
1052 char *ptr = c->cr_msg;
1054 assert( dli->dli_oc != NULL );
1055 assert( dli->dli_ad != NULL );
1057 ptr += snprintf( c->cr_msg, sizeof( c->cr_msg ),
1058 SLAP_X_ORDERED_FMT "%s %s", i,
1059 dli->dli_oc->soc_cname.bv_val,
1060 dli->dli_ad->ad_cname.bv_val );
1062 if ( dli->dli_member_ad != NULL ) {
1065 ptr = lutil_strcopy( ptr, dli->dli_member_ad->ad_cname.bv_val );
1068 bv.bv_val = c->cr_msg;
1069 bv.bv_len = ptr - bv.bv_val;
1070 value_add_one( &c->rvalue_vals, &bv );
1074 case DL_ATTRPAIR_COMPAT:
1086 } else if ( c->op == LDAP_MOD_DELETE ) {
1089 if ( c->valx < 0 ) {
1090 dynlist_info_t *dli_next;
1092 for ( dli_next = dli; dli_next; dli = dli_next ) {
1093 dli_next = dli->dli_next;
1095 ch_free( dli->dli_default_filter.bv_val );
1099 on->on_bi.bi_private = NULL;
1102 dynlist_info_t **dlip;
1104 for ( i = 0, dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1107 if ( *dlip == NULL ) {
1110 dlip = &(*dlip)->dli_next;
1114 *dlip = dli->dli_next;
1115 ch_free( dli->dli_default_filter.bv_val );
1118 dli = (dynlist_info_t *)on->on_bi.bi_private;
1122 case DL_ATTRPAIR_COMPAT:
1137 dynlist_info_t **dlip,
1139 ObjectClass *oc = NULL;
1140 AttributeDescription *ad = NULL,
1144 oc = oc_find( c->argv[ 1 ] );
1146 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1147 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1148 "unable to find ObjectClass \"%s\"",
1150 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1151 c->log, c->cr_msg, 0 );
1155 rc = slap_str2ad( c->argv[ 2 ], &ad, &text );
1156 if ( rc != LDAP_SUCCESS ) {
1157 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1158 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1159 "unable to find AttributeDescription \"%s\"",
1161 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1162 c->log, c->cr_msg, 0 );
1166 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
1167 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1168 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1169 "AttributeDescription \"%s\" "
1170 "must be a subtype of \"labeledURI\"",
1172 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1173 c->log, c->cr_msg, 0 );
1177 if ( c->argc == 4 ) {
1178 rc = slap_str2ad( c->argv[ 3 ], &member_ad, &text );
1179 if ( rc != LDAP_SUCCESS ) {
1180 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1181 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1182 "unable to find AttributeDescription \"%s\"\n",
1184 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1185 c->log, c->cr_msg, 0 );
1190 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1191 *dlip; dlip = &(*dlip)->dli_next )
1193 /* The same URL attribute / member attribute pair
1194 * cannot be repeated */
1195 if ( (*dlip)->dli_ad == ad && (*dlip)->dli_member_ad == member_ad ) {
1196 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1197 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1198 "URL attributeDescription \"%s\" already mapped.\n",
1199 ad->ad_cname.bv_val );
1200 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1201 c->log, c->cr_msg, 0 );
1203 /* make it a warning... */
1209 if ( c->valx > 0 ) {
1212 for ( i = 0, dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1215 if ( *dlip == NULL ) {
1216 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1217 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1218 "invalid index {%d}\n",
1220 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1221 c->log, c->cr_msg, 0 );
1224 dlip = &(*dlip)->dli_next;
1229 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1230 *dlip; dlip = &(*dlip)->dli_next )
1234 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
1236 (*dlip)->dli_oc = oc;
1237 (*dlip)->dli_ad = ad;
1238 (*dlip)->dli_member_ad = member_ad;
1239 (*dlip)->dli_next = dli_next;
1241 rc = dynlist_build_def_filter( *dlip );
1245 case DL_ATTRPAIR_COMPAT:
1246 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1247 "warning: \"attrpair\" only supported for limited "
1248 "backward compatibility with overlay \"dyngroup\"" );
1249 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
1253 dynlist_info_t **dlip;
1254 ObjectClass *oc = NULL;
1255 AttributeDescription *ad = NULL,
1259 oc = oc_find( "groupOfURLs" );
1261 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1262 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1263 "unable to find default ObjectClass \"groupOfURLs\"" );
1264 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1265 c->log, c->cr_msg, 0 );
1269 rc = slap_str2ad( c->argv[ 1 ], &member_ad, &text );
1270 if ( rc != LDAP_SUCCESS ) {
1271 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1272 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1273 "unable to find AttributeDescription \"%s\"",
1275 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1276 c->log, c->cr_msg, 0 );
1280 rc = slap_str2ad( c->argv[ 2 ], &ad, &text );
1281 if ( rc != LDAP_SUCCESS ) {
1282 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1283 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1284 "unable to find AttributeDescription \"%s\"\n",
1286 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1287 c->log, c->cr_msg, 0 );
1291 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
1292 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1293 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1294 "AttributeDescription \"%s\" "
1295 "must be a subtype of \"labeledURI\"",
1297 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1298 c->log, c->cr_msg, 0 );
1302 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1303 *dlip; dlip = &(*dlip)->dli_next )
1305 /* The same URL attribute / member attribute pair
1306 * cannot be repeated */
1307 if ( (*dlip)->dli_ad == ad && (*dlip)->dli_member_ad == member_ad ) {
1308 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1309 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1310 "URL attributeDescription \"%s\" already mapped.\n",
1311 ad->ad_cname.bv_val );
1312 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1313 c->log, c->cr_msg, 0 );
1315 /* make it a warning... */
1321 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
1323 (*dlip)->dli_oc = oc;
1324 (*dlip)->dli_ad = ad;
1325 (*dlip)->dli_member_ad = member_ad;
1327 rc = dynlist_build_def_filter( *dlip );
1345 slap_overinst *on = (slap_overinst *) be->bd_info;
1346 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private;
1347 ObjectClass *oc = NULL;
1348 AttributeDescription *ad = NULL;
1352 if ( dli == NULL ) {
1353 dli = ch_calloc( 1, sizeof( dynlist_info_t ) );
1354 on->on_bi.bi_private = (void *)dli;
1357 for ( ; dli; dli = dli->dli_next ) {
1358 if ( dli->dli_oc == NULL ) {
1360 oc = oc_find( "groupOfURLs" );
1362 sprintf( cr->msg, "unable to fetch objectClass \"groupOfURLs\"" );
1363 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: %s.\n", cr->msg, 0, 0 );
1371 if ( dli->dli_ad == NULL ) {
1373 rc = slap_str2ad( "memberURL", &ad, &text );
1374 if ( rc != LDAP_SUCCESS ) {
1375 sprintf( cr->msg, "unable to fetch attributeDescription \"memberURL\": %d (%s)",
1377 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: %s.\n", cr->msg, 0, 0 );
1385 if ( BER_BVISNULL( &dli->dli_default_filter ) ) {
1386 rc = dynlist_build_def_filter( dli );
1393 rc = slap_str2ad( "dgIdentity", &ad_dgIdentity, &text );
1394 if ( rc != LDAP_SUCCESS ) {
1395 snprintf( cr->msg, sizeof( cr->msg),
1396 "unable to fetch attributeDescription \"dgIdentity\": %d (%s)",
1398 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: %s\n", cr->msg, 0, 0 );
1399 /* Just a warning */
1402 rc = slap_str2ad( "dgAuthz", &ad_dgAuthz, &text );
1403 if ( rc != LDAP_SUCCESS ) {
1404 snprintf( cr->msg, sizeof( cr->msg),
1405 "unable to fetch attributeDescription \"dgAuthz\": %d (%s)",
1407 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: %s\n", cr->msg, 0, 0 );
1408 /* Just a warning */
1419 slap_overinst *on = (slap_overinst *) be->bd_info;
1421 if ( on->on_bi.bi_private ) {
1422 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private,
1425 for ( dli_next = dli; dli_next; dli = dli_next ) {
1426 dli_next = dli->dli_next;
1428 ch_free( dli->dli_default_filter.bv_val );
1436 static slap_overinst dynlist = { { NULL } };
1437 #ifdef TAKEOVER_DYNGROUP
1438 static char *obsolete_names[] = {
1444 #if SLAPD_OVER_DYNLIST == SLAPD_MOD_DYNAMIC
1446 #endif /* SLAPD_OVER_DYNLIST == SLAPD_MOD_DYNAMIC */
1448 dynlist_initialize(void)
1450 #ifndef OL_2_2_COMPAT
1454 dynlist.on_bi.bi_type = "dynlist";
1456 #ifdef TAKEOVER_DYNGROUP
1457 /* makes dynlist incompatible with dyngroup */
1458 dynlist.on_bi.bi_obsolete_names = obsolete_names;
1461 #ifdef OL_2_2_COMPAT
1462 dynlist.on_bi.bi_db_config = dynlist_db_config;
1464 dynlist.on_bi.bi_db_config = config_generic_wrapper;
1466 dynlist.on_bi.bi_db_open = dynlist_db_open;
1467 dynlist.on_bi.bi_db_destroy = dynlist_db_destroy;
1469 dynlist.on_response = dynlist_response;
1471 #ifndef OL_2_2_COMPAT
1472 dynlist.on_bi.bi_cf_ocs = dlocs;
1474 rc = config_register_schema( dlcfg, dlocs );
1480 return overlay_register( &dynlist );
1483 #if SLAPD_OVER_DYNLIST == SLAPD_MOD_DYNAMIC
1485 init_module( int argc, char *argv[] )
1487 return dynlist_initialize();
1491 #endif /* SLAPD_OVER_DYNLIST */