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 typedef struct dynlist_info_t {
63 AttributeDescription *dli_ad;
64 AttributeDescription *dli_member_ad;
65 struct berval dli_default_filter;
66 struct dynlist_info_t *dli_next;
69 static dynlist_info_t *
70 dynlist_is_dynlist( Operation *op, SlapReply *rs )
72 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
73 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private;
77 a = attrs_find( rs->sr_entry->e_attrs, slap_schema.si_ad_objectClass );
79 /* FIXME: objectClass must be present; for non-storage
80 * backends, like back-ldap, it needs to be added
81 * to the requested attributes */
85 for ( ; dli; dli = dli->dli_next ) {
86 if ( value_find_ex( slap_schema.si_ad_objectClass,
87 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
88 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
89 a->a_nvals, &dli->dli_oc->soc_cname,
90 op->o_tmpmemctx ) == 0 )
100 dynlist_make_filter( Operation *op, struct berval *oldf, struct berval *newf )
102 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
103 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private;
107 assert( oldf != NULL );
108 assert( newf != NULL );
109 assert( !BER_BVISNULL( oldf ) );
110 assert( !BER_BVISEMPTY( oldf ) );
112 newf->bv_len = STRLENOF( "(&(!(objectClass=" "))" ")" )
113 + dli->dli_oc->soc_cname.bv_len + oldf->bv_len;
114 newf->bv_val = op->o_tmpalloc( newf->bv_len + 1, op->o_tmpmemctx );
115 if ( newf->bv_val == NULL ) {
118 ptr = lutil_strcopy( newf->bv_val, "(&(!(objectClass=" );
119 ptr = lutil_strcopy( ptr, dli->dli_oc->soc_cname.bv_val );
120 ptr = lutil_strcopy( ptr, "))" );
121 ptr = lutil_strcopy( ptr, oldf->bv_val );
122 ptr = lutil_strcopy( ptr, ")" );
123 newf->bv_len = ptr - newf->bv_val;
128 typedef struct dynlist_sc_t {
129 dynlist_info_t *dlc_dli;
134 dynlist_sc_update( Operation *op, SlapReply *rs )
140 AccessControlState acl_state = ACL_STATE_INIT;
144 if ( rs->sr_type != REP_SEARCH ) {
148 dlc = (dynlist_sc_t *)op->o_callback->sc_private;
152 assert( rs->sr_entry != NULL );
154 /* test access to entry */
155 if ( !access_allowed( op, rs->sr_entry, slap_schema.si_ad_entry,
156 NULL, ACL_READ, NULL ) )
161 if ( dlc->dlc_dli->dli_member_ad ) {
163 /* if access allowed, try to add values, emulating permissive
164 * control to silently ignore duplicates */
165 if ( access_allowed( op, rs->sr_entry, slap_schema.si_ad_entry,
166 NULL, ACL_READ, NULL ) )
169 const char *text = NULL;
171 struct berval vals[ 2 ], nvals[ 2 ];
173 vals[ 0 ] = rs->sr_entry->e_name;
174 BER_BVZERO( &vals[ 1 ] );
175 nvals[ 0 ] = rs->sr_entry->e_nname;
176 BER_BVZERO( &nvals[ 1 ] );
178 mod.sm_op = LDAP_MOD_ADD;
179 mod.sm_desc = dlc->dlc_dli->dli_member_ad;
180 mod.sm_type = dlc->dlc_dli->dli_member_ad->ad_cname;
181 mod.sm_values = vals;
182 mod.sm_nvalues = nvals;
184 (void)modify_add_values( e, &mod, /* permissive */ 1,
185 &text, textbuf, sizeof( textbuf ) );
192 opattrs = ( rs->sr_attrs == NULL ) ? 0 : an_find( rs->sr_attrs, &AllOper );
193 userattrs = ( rs->sr_attrs == NULL ) ? 1 : an_find( rs->sr_attrs, &AllUser );
194 #else /* SLAP_OPATTRS */
195 opattrs = SLAP_OPATTRS( rs->sr_attr_flags );
196 userattrs = SLAP_USERATTRS( rs->sr_attr_flags );
197 #endif /* SLAP_OPATTRS */
199 for ( a = rs->sr_entry->e_attrs; a != NULL; a = a->a_next ) {
200 BerVarray vals, nvals = NULL;
202 is_oc = a->a_desc == slap_schema.si_ad_objectClass;
204 /* if attribute is not requested, skip it */
205 if ( rs->sr_attrs == NULL ) {
206 if ( is_at_operational( a->a_desc->ad_type ) ) {
211 if ( is_at_operational( a->a_desc->ad_type ) ) {
212 if ( !opattrs && !ad_inlist( a->a_desc, rs->sr_attrs ) )
218 if ( !userattrs && !ad_inlist( a->a_desc, rs->sr_attrs ) )
225 /* test access to attribute */
226 if ( op->ors_attrsonly ) {
227 if ( !access_allowed( op, rs->sr_entry, a->a_desc, NULL,
228 ACL_READ, &acl_state ) )
234 /* single-value check: keep first only */
235 if ( is_at_single_value( a->a_desc->ad_type ) ) {
236 if ( attr_find( e->e_attrs, a->a_desc ) != NULL ) {
241 /* test access to attribute */
242 for ( i = 0; !BER_BVISNULL( &a->a_vals[i] ); i++ )
245 vals = op->o_tmpalloc( ( i + 1 ) * sizeof( struct berval ), op->o_tmpmemctx );
246 if ( a->a_nvals != a->a_vals ) {
247 nvals = op->o_tmpalloc( ( i + 1 ) * sizeof( struct berval ), op->o_tmpmemctx );
250 for ( i = 0, j = 0; !BER_BVISNULL( &a->a_vals[i] ); i++ ) {
252 ObjectClass *soc = oc_bvfind( &a->a_vals[i] );
254 if ( soc->soc_kind == LDAP_SCHEMA_STRUCTURAL ) {
259 if ( access_allowed( op, rs->sr_entry, a->a_desc,
260 &a->a_nvals[i], ACL_READ, &acl_state ) )
262 vals[j] = a->a_vals[i];
264 nvals[j] = a->a_nvals[i];
270 /* if access allowed, try to add values, emulating permissive
271 * control to silently ignore duplicates */
274 const char *text = NULL;
277 BER_BVZERO( &vals[j] );
279 BER_BVZERO( &nvals[j] );
282 mod.sm_op = LDAP_MOD_ADD;
283 mod.sm_desc = a->a_desc;
284 mod.sm_type = a->a_desc->ad_cname;
285 mod.sm_values = vals;
286 mod.sm_nvalues = nvals;
288 (void)modify_add_values( e, &mod, /* permissive */ 1,
289 &text, textbuf, sizeof( textbuf ) );
292 op->o_tmpfree( vals, op->o_tmpmemctx );
294 op->o_tmpfree( nvals, op->o_tmpmemctx );
299 if ( rs->sr_flags & REP_ENTRY_MUSTBEFREED ) {
300 entry_free( rs->sr_entry );
302 rs->sr_flags ^= REP_ENTRY_MUSTBEFREED;
309 dynlist_send_entry( Operation *op, SlapReply *rs, dynlist_info_t *dli )
314 SlapReply r = { REP_SEARCH };
320 dynlist_sc_t dlc = { 0 };
322 a = attrs_find( rs->sr_entry->e_attrs, dli->dli_ad );
325 return SLAP_CB_CONTINUE;
328 e = entry_dup( rs->sr_entry );
329 e_flags = rs->sr_flags | ( REP_ENTRY_MODIFIABLE | REP_ENTRY_MUSTBEFREED );
333 cb.sc_private = &dlc;
334 cb.sc_response = dynlist_sc_update;
335 cb.sc_cleanup = NULL;
339 o.ors_deref = LDAP_DEREF_NEVER;
341 o.ors_tlimit = SLAP_NO_LIMIT;
342 o.ors_slimit = SLAP_NO_LIMIT;
345 opattrs = ( rs->sr_attrs == NULL ) ? 0 : an_find( rs->sr_attrs, &AllOper );
346 userattrs = ( rs->sr_attrs == NULL ) ? 1 : an_find( rs->sr_attrs, &AllUser );
347 #else /* SLAP_OPATTRS */
348 opattrs = SLAP_OPATTRS( rs->sr_attr_flags );
349 userattrs = SLAP_USERATTRS( rs->sr_attr_flags );
350 #endif /* SLAP_OPATTRS */
352 for ( url = a->a_nvals; !BER_BVISNULL( url ); url++ ) {
353 LDAPURLDesc *lud = NULL;
358 BER_BVZERO( &o.o_req_dn );
359 BER_BVZERO( &o.o_req_ndn );
362 BER_BVZERO( &o.ors_filterstr );
364 if ( ldap_url_parse( url->bv_val, &lud ) != LDAP_URL_SUCCESS ) {
369 if ( lud->lud_host != NULL ) {
370 /* FIXME: host not allowed; reject as illegal? */
371 Debug( LDAP_DEBUG_ANY, "dynlist_send_entry(\"%s\"): "
372 "illegal URI \"%s\"\n",
373 e->e_name.bv_val, url->bv_val, 0 );
377 if ( lud->lud_dn == NULL ) {
378 /* note that an empty base is not honored in terms
379 * of defaultSearchBase, because select_backend()
380 * is not aware of the defaultSearchBase option;
381 * this can be useful in case of a database serving
382 * the empty suffix */
383 BER_BVSTR( &dn, "" );
386 ber_str2bv( lud->lud_dn, 0, 0, &dn );
388 rc = dnPrettyNormal( NULL, &dn, &o.o_req_dn, &o.o_req_ndn, op->o_tmpmemctx );
389 if ( rc != LDAP_SUCCESS ) {
393 o.ors_scope = lud->lud_scope;
395 if ( dli->dli_member_ad != NULL ) {
396 /* if ( lud->lud_attrs != NULL ),
397 * the URL should be ignored */
398 o.ors_attrs = slap_anlist_no_attrs;
400 } else if ( lud->lud_attrs == NULL ) {
401 o.ors_attrs = rs->sr_attrs;
404 for ( i = 0; lud->lud_attrs[i]; i++)
407 o.ors_attrs = op->o_tmpcalloc( i + 1, sizeof( AttributeName ), op->o_tmpmemctx );
408 for ( i = 0, j = 0; lud->lud_attrs[i]; i++) {
409 const char *text = NULL;
411 ber_str2bv( lud->lud_attrs[i], 0, 0, &o.ors_attrs[j].an_name );
412 o.ors_attrs[j].an_desc = NULL;
413 (void)slap_bv2ad( &o.ors_attrs[j].an_name, &o.ors_attrs[j].an_desc, &text );
414 /* FIXME: ignore errors... */
416 if ( rs->sr_attrs == NULL ) {
417 if ( o.ors_attrs[j].an_desc != NULL &&
418 is_at_operational( o.ors_attrs[j].an_desc->ad_type ) )
424 if ( o.ors_attrs[j].an_desc != NULL &&
425 is_at_operational( o.ors_attrs[j].an_desc->ad_type ) )
427 if ( !opattrs && !ad_inlist( o.ors_attrs[j].an_desc, rs->sr_attrs ) )
434 o.ors_attrs[j].an_desc != NULL &&
435 !ad_inlist( o.ors_attrs[j].an_desc, rs->sr_attrs ) )
449 BER_BVZERO( &o.ors_attrs[j].an_name );
452 if ( lud->lud_filter == NULL ) {
453 ber_dupbv_x( &o.ors_filterstr,
454 &dli->dli_default_filter, op->o_tmpmemctx );
458 ber_str2bv( lud->lud_filter, 0, 0, &flt );
459 if ( dynlist_make_filter( op, &flt, &o.ors_filterstr ) ) {
464 o.ors_filter = str2filter_x( op, o.ors_filterstr.bv_val );
465 if ( o.ors_filter == NULL ) {
469 o.o_bd = select_backend( &o.o_req_ndn, 0, 1 );
470 if ( o.o_bd && o.o_bd->be_search ) {
472 r.sr_attr_flags = slap_attr_flags( o.ors_attrs );
473 #endif /* SLAP_OPATTRS */
474 (void)o.o_bd->be_search( &o, &r );
478 if ( o.ors_filter ) {
479 filter_free_x( &o, o.ors_filter );
481 if ( o.ors_attrs && o.ors_attrs != rs->sr_attrs
482 && o.ors_attrs != slap_anlist_no_attrs )
484 op->o_tmpfree( o.ors_attrs, op->o_tmpmemctx );
486 if ( !BER_BVISNULL( &o.o_req_dn ) ) {
487 op->o_tmpfree( o.o_req_dn.bv_val, op->o_tmpmemctx );
489 if ( !BER_BVISNULL( &o.o_req_ndn ) ) {
490 op->o_tmpfree( o.o_req_ndn.bv_val, op->o_tmpmemctx );
492 assert( BER_BVISNULL( &o.ors_filterstr )
493 || o.ors_filterstr.bv_val != lud->lud_filter );
494 op->o_tmpfree( o.ors_filterstr.bv_val, op->o_tmpmemctx );
495 ldap_free_urldesc( lud );
499 rs->sr_flags = e_flags;
501 return SLAP_CB_CONTINUE;
505 dynlist_sc_save_entry( Operation *op, SlapReply *rs )
507 /* save the entry in the private field of the callback,
508 * so it doesn't get freed (it's temporary!) */
509 if ( rs->sr_entry != NULL ) {
510 dynlist_sc_t *dlc = (dynlist_sc_t *)op->o_callback->sc_private;
511 dlc->dlc_e = rs->sr_entry;
519 dynlist_compare( Operation *op, SlapReply *rs )
521 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
522 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private;
524 for ( ; dli != NULL; dli = dli->dli_next ) {
525 if ( op->oq_compare.rs_ava->aa_desc == dli->dli_member_ad ) {
526 /* This compare is for one of the attributes we're
527 * interested in. We'll use slapd's existing dyngroup
528 * evaluator to get the answer we want.
530 int cache = op->o_do_not_cache;
532 op->o_do_not_cache = 1;
533 rs->sr_err = backend_group( op, NULL, &op->o_req_ndn,
534 &op->oq_compare.rs_ava->aa_value, dli->dli_oc, dli->dli_ad );
535 op->o_do_not_cache = cache;
536 switch ( rs->sr_err ) {
538 rs->sr_err = LDAP_COMPARE_TRUE;
541 case LDAP_NO_SUCH_OBJECT:
542 /* NOTE: backend_group() returns noSuchObject
543 * if op_ndn does not exist; however, since
544 * dynamic list expansion means that the
545 * member attribute is virtually present, the
546 * non-existence of the asserted value implies
547 * the assertion is FALSE rather than
549 rs->sr_err = LDAP_COMPARE_FALSE;
553 return SLAP_CB_CONTINUE;
557 dli = (dynlist_info_t *)on->on_bi.bi_private;
558 for ( ; dli != NULL && rs->sr_err != LDAP_COMPARE_TRUE; dli = dli->dli_next ) {
562 SlapReply r = { REP_SEARCH };
565 dynlist_sc_t dlc = { 0 };
568 int cache = op->o_do_not_cache;
569 struct berval op_dn = op->o_dn,
571 BackendDB *op_bd = op->o_bd;
573 /* fetch the entry as rootdn (a hack to see if it exists
574 * and if it has the right objectClass) */
575 op->o_do_not_cache = 1;
576 op->o_dn = op->o_bd->be_rootdn;
577 op->o_ndn = op->o_bd->be_rootndn;
578 op->o_bd = select_backend( &op->o_req_ndn, 0, 0 );
580 r.sr_err = be_entry_get_rw( op, &op->o_req_ndn,
581 dli->dli_oc, NULL, 0, &e );
583 be_entry_release_r( op, e );
585 op->o_do_not_cache = cache;
589 if ( r.sr_err != LDAP_SUCCESS ) {
593 /* if the entry has the right objectClass, generate
594 * the dynamic list and compare */
596 cb.sc_private = &dlc;
597 cb.sc_response = dynlist_sc_save_entry;
598 cb.sc_cleanup = NULL;
602 o.o_tag = LDAP_REQ_SEARCH;
604 o.ors_tlimit = SLAP_NO_LIMIT;
605 o.ors_slimit = SLAP_NO_LIMIT;
607 o.o_bd = select_backend( &o.o_req_ndn, 0, 1 );
608 if ( !o.o_bd || !o.o_bd->be_search ) {
609 return SLAP_CB_CONTINUE;
612 BER_BVSTR( &o.ors_filterstr, "(objectClass=*)" );
613 o.ors_filter = str2filter_x( op, o.ors_filterstr.bv_val );
614 if ( o.ors_filter == NULL ) {
616 return SLAP_CB_CONTINUE;
619 o.ors_scope = LDAP_SCOPE_BASE;
620 o.ors_deref = LDAP_DEREF_NEVER;
621 an[0].an_name = op->orc_ava->aa_desc->ad_cname;
622 an[0].an_desc = op->orc_ava->aa_desc;
623 BER_BVZERO( &an[1].an_name );
627 o.o_acl_priv = ACL_COMPARE;
629 rc = o.o_bd->be_search( &o, &r );
630 filter_free_x( &o, o.ors_filter );
636 if ( dlc.dlc_e != NULL ) {
637 r.sr_entry = dlc.dlc_e;
640 if ( r.sr_err != LDAP_SUCCESS || r.sr_entry == NULL ) {
642 return SLAP_CB_CONTINUE;
645 for ( a = attrs_find( r.sr_entry->e_attrs, op->orc_ava->aa_desc );
647 a = attrs_find( a->a_next, op->orc_ava->aa_desc ) )
649 /* if we're here, we got a match... */
650 rs->sr_err = LDAP_COMPARE_FALSE;
652 if ( value_find_ex( op->orc_ava->aa_desc,
653 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
654 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
655 a->a_nvals, &op->orc_ava->aa_value, op->o_tmpmemctx ) == 0 )
657 rs->sr_err = LDAP_COMPARE_TRUE;
662 if ( r.sr_flags & REP_ENTRY_MUSTBEFREED ) {
663 entry_free( r.sr_entry );
667 return SLAP_CB_CONTINUE;
671 dynlist_response( Operation *op, SlapReply *rs )
675 switch ( op->o_tag ) {
676 case LDAP_REQ_SEARCH:
677 if ( rs->sr_type == REP_SEARCH && !get_manageDSAit( op ) )
679 dli = dynlist_is_dynlist( op, rs );
681 return dynlist_send_entry( op, rs, dli );
686 case LDAP_REQ_COMPARE:
687 switch ( rs->sr_err ) {
688 /* NOTE: we waste a few cycles running the dynamic list
689 * also when the result is FALSE, which occurs if the
690 * dynamic entry itself contains the AVA attribute */
691 /* FIXME: this approach is less than optimal; a dedicated
692 * compare op should be implemented, that fetches the
693 * entry, checks if it has the appropriate objectClass
694 * and, in case, runs a compare thru all the URIs,
695 * stopping at the first positive occurrence; see ITS#3756 */
696 case LDAP_COMPARE_FALSE:
697 case LDAP_NO_SUCH_ATTRIBUTE:
698 return dynlist_compare( op, rs );
706 return SLAP_CB_CONTINUE;
710 dynlist_build_def_filter( dynlist_info_t *dli )
714 dli->dli_default_filter.bv_len = STRLENOF( "(!(objectClass=" "))" )
715 + dli->dli_oc->soc_cname.bv_len;
716 dli->dli_default_filter.bv_val = ch_malloc( dli->dli_default_filter.bv_len + 1 );
717 if ( dli->dli_default_filter.bv_val == NULL ) {
718 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: malloc failed.\n",
723 ptr = lutil_strcopy( dli->dli_default_filter.bv_val, "(!(objectClass=" );
724 ptr = lutil_strcopy( ptr, dli->dli_oc->soc_cname.bv_val );
725 ptr = lutil_strcopy( ptr, "))" );
727 assert( dli->dli_default_filter.bv_len == ptr - dli->dli_default_filter.bv_val );
741 slap_overinst *on = (slap_overinst *)be->bd_info;
745 if ( strcasecmp( argv[0], "dynlist-attrset" ) == 0 ) {
746 dynlist_info_t **dlip;
748 AttributeDescription *ad = NULL,
752 if ( argc < 3 || argc > 4 ) {
753 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
754 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
755 "invalid arg number #%d.\n",
756 fname, lineno, argc );
760 oc = oc_find( argv[1] );
762 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
763 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
764 "unable to find ObjectClass \"%s\"\n",
765 fname, lineno, argv[ 1 ] );
769 rc = slap_str2ad( argv[2], &ad, &text );
770 if ( rc != LDAP_SUCCESS ) {
771 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
772 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
773 "unable to find AttributeDescription \"%s\"\n",
774 fname, lineno, argv[2] );
778 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
779 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
780 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
781 "AttributeDescription \"%s\" "
782 "must be a subtype of \"labeledURI\"\n",
783 fname, lineno, argv[2] );
788 rc = slap_str2ad( argv[3], &member_ad, &text );
789 if ( rc != LDAP_SUCCESS ) {
790 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
791 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
792 "unable to find AttributeDescription \"%s\"\n",
793 fname, lineno, argv[3] );
798 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
799 *dlip; dlip = &(*dlip)->dli_next )
801 /* The check on objectClass may be relaxed */
803 if ( (*dlip)->dli_oc == oc ) {
804 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
805 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
806 "objectClass \"%s\" already mapped.\n",
807 fname, lineno, oc->soc_cname.bv_val );
812 if ( (*dlip)->dli_ad == ad ) {
813 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
814 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
815 "URL attributeDescription \"%s\" already mapped.\n",
816 fname, lineno, ad->ad_cname.bv_val );
820 if ( member_ad != NULL && (*dlip)->dli_member_ad == member_ad ) {
821 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
822 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
823 "member attributeDescription \"%s\" already mapped.\n",
824 fname, lineno, member_ad->ad_cname.bv_val );
829 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
830 (*dlip)->dli_oc = oc;
831 (*dlip)->dli_ad = ad;
832 (*dlip)->dli_member_ad = member_ad;
834 if ( dynlist_build_def_filter( *dlip ) ) {
840 /* allow dyngroup syntax */
841 } else if ( strcasecmp( argv[0], "dynlist-attrpair" ) == 0 ) {
842 dynlist_info_t **dlip;
844 AttributeDescription *ad = NULL,
849 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
850 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
851 "invalid arg number #%d.\n",
852 fname, lineno, argc );
856 oc = oc_find( "groupOfURLs" );
858 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
859 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
860 "unable to find default ObjectClass \"groupOfURLs\"\n",
865 rc = slap_str2ad( argv[1], &member_ad, &text );
866 if ( rc != LDAP_SUCCESS ) {
867 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
868 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
869 "unable to find AttributeDescription \"%s\"\n",
870 fname, lineno, argv[1] );
874 rc = slap_str2ad( argv[2], &ad, &text );
875 if ( rc != LDAP_SUCCESS ) {
876 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
877 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
878 "unable to find AttributeDescription \"%s\"\n",
879 fname, lineno, argv[2] );
883 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
884 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
885 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
886 "AttributeDescription \"%s\" "
887 "must be a subtype of \"labeledURI\"\n",
888 fname, lineno, argv[2] );
893 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
894 *dlip; dlip = &(*dlip)->dli_next )
897 /* The check on objectClass may be relaxed */
898 if ( (*dlip)->dli_oc == oc ) {
899 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
900 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
901 "objectClass \"%s\" already mapped.\n",
902 fname, lineno, oc->soc_cname.bv_val );
907 if ( (*dlip)->dli_ad == ad ) {
908 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
909 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
910 "URL attributeDescription \"%s\" already mapped.\n",
911 fname, lineno, ad->ad_cname.bv_val );
915 if ( member_ad != NULL && (*dlip)->dli_member_ad == member_ad ) {
916 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
917 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
918 "member attributeDescription \"%s\" already mapped.\n",
919 fname, lineno, member_ad->ad_cname.bv_val );
924 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
925 (*dlip)->dli_oc = oc;
926 (*dlip)->dli_ad = ad;
927 (*dlip)->dli_member_ad = member_ad;
929 if ( dynlist_build_def_filter( *dlip ) ) {
936 rc = SLAP_CONF_UNKNOWN;
950 static ConfigDriver dl_cfgen;
952 static ConfigTable dlcfg[] = {
953 { "dynlist-attrset", "group-oc> <URL-ad> <member-ad",
954 3, 4, 0, ARG_MAGIC|DL_ATTRSET, dl_cfgen,
955 "( OLcfgOvAt:8.1 NAME 'olcDLattrSet' "
956 "DESC 'Dynamic list: <group objectClass>, <URL attributeDescription>, <member attributeDescription>' "
957 "EQUALITY caseIgnoreMatch "
958 "SYNTAX OMsDirectoryString "
959 "X-ORDERED 'VALUES' )",
961 { "dynlist-attrpair", "member-ad> <URL-ad",
962 3, 3, 0, ARG_MAGIC|DL_ATTRPAIR, dl_cfgen,
964 #ifdef TAKEOVER_DYNGROUP
965 { "attrpair", "member-ad> <URL-ad",
966 3, 3, 0, ARG_MAGIC|DL_ATTRPAIR_COMPAT, dl_cfgen,
969 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
972 static ConfigOCs dlocs[] = {
974 "NAME 'olcDynamicList' "
975 "DESC 'Dynamic list configuration' "
976 "SUP olcOverlayConfig "
977 "MAY olcDLattrSet )",
978 Cft_Overlay, dlcfg, NULL, NULL },
983 dl_cfgen( ConfigArgs *c )
985 slap_overinst *on = (slap_overinst *)c->bi;
986 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private;
990 if ( c->op == SLAP_CONFIG_EMIT ) {
993 for ( i = 0; dli; i++, dli = dli->dli_next ) {
997 assert( dli->dli_oc != NULL );
998 assert( dli->dli_ad != NULL );
1000 ptr += snprintf( c->msg, sizeof( c->msg ),
1001 SLAP_X_ORDERED_FMT "%s %s", i,
1002 dli->dli_oc->soc_cname.bv_val,
1003 dli->dli_ad->ad_cname.bv_val );
1005 if ( dli->dli_member_ad != NULL ) {
1008 ptr = lutil_strcopy( ptr, dli->dli_member_ad->ad_cname.bv_val );
1012 bv.bv_len = ptr - bv.bv_val;
1013 value_add_one( &c->rvalue_vals, &bv );
1017 case DL_ATTRPAIR_COMPAT:
1029 } else if ( c->op == LDAP_MOD_DELETE ) {
1032 if ( c->valx < 0 ) {
1033 dynlist_info_t *dli_next;
1035 for ( dli_next = dli; dli_next; dli = dli_next ) {
1036 dli_next = dli->dli_next;
1038 ch_free( dli->dli_default_filter.bv_val );
1042 on->on_bi.bi_private = NULL;
1045 dynlist_info_t **dlip;
1047 for ( i = 0, dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1050 if ( *dlip == NULL ) {
1053 dlip = &(*dlip)->dli_next;
1057 *dlip = dli->dli_next;
1058 ch_free( dli->dli_default_filter.bv_val );
1061 dli = (dynlist_info_t *)on->on_bi.bi_private;
1065 case DL_ATTRPAIR_COMPAT:
1075 return 1; /* FIXME */
1080 dynlist_info_t **dlip,
1082 ObjectClass *oc = NULL;
1083 AttributeDescription *ad = NULL,
1087 oc = oc_find( c->argv[ 1 ] );
1089 snprintf( c->msg, sizeof( c->msg ),
1090 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1091 "unable to find ObjectClass \"%s\"",
1093 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1094 c->log, c->msg, 0 );
1098 rc = slap_str2ad( c->argv[ 2 ], &ad, &text );
1099 if ( rc != LDAP_SUCCESS ) {
1100 snprintf( c->msg, sizeof( c->msg ),
1101 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1102 "unable to find AttributeDescription \"%s\"",
1104 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1105 c->log, c->msg, 0 );
1109 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
1110 snprintf( c->msg, sizeof( c->msg ),
1111 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1112 "AttributeDescription \"%s\" "
1113 "must be a subtype of \"labeledURI\"",
1115 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1116 c->log, c->msg, 0 );
1120 if ( c->argc == 4 ) {
1121 rc = slap_str2ad( c->argv[ 3 ], &member_ad, &text );
1122 if ( rc != LDAP_SUCCESS ) {
1123 snprintf( c->msg, sizeof( c->msg ),
1124 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1125 "unable to find AttributeDescription \"%s\"\n",
1127 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1128 c->log, c->msg, 0 );
1133 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1134 *dlip; dlip = &(*dlip)->dli_next )
1136 /* The check on objectClass may be relaxed */
1138 if ( (*dlip)->dli_oc == oc ) {
1139 snprintf( c->msg, sizeof( c->msg ),
1140 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1141 "objectClass \"%s\" already mapped.\n",
1142 oc->soc_cname.bv_val );
1143 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1144 c->log, c->msg, 0 );
1149 if ( (*dlip)->dli_ad == ad ) {
1150 snprintf( c->msg, sizeof( c->msg ),
1151 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1152 "URL attributeDescription \"%s\" already mapped.\n",
1153 ad->ad_cname.bv_val );
1154 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1155 c->log, c->msg, 0 );
1159 if ( member_ad != NULL && (*dlip)->dli_member_ad == member_ad ) {
1160 snprintf( c->msg, sizeof( c->msg ),
1161 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1162 "member attributeDescription \"%s\" already mapped.\n",
1163 member_ad->ad_cname.bv_val );
1164 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1165 c->log, c->msg, 0 );
1170 if ( c->valx > 0 ) {
1173 for ( i = 0, dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1176 if ( *dlip == NULL ) {
1177 snprintf( c->msg, sizeof( c->msg ),
1178 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1179 "invalid index {%d}\n",
1181 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1182 c->log, c->msg, 0 );
1185 dlip = &(*dlip)->dli_next;
1190 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1191 *dlip; dlip = &(*dlip)->dli_next )
1195 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
1197 (*dlip)->dli_oc = oc;
1198 (*dlip)->dli_ad = ad;
1199 (*dlip)->dli_member_ad = member_ad;
1200 (*dlip)->dli_next = dli_next;
1202 rc = dynlist_build_def_filter( *dlip );
1206 case DL_ATTRPAIR_COMPAT:
1207 snprintf( c->msg, sizeof( c->msg ),
1208 "warning: \"attrpair\" only supported for limited "
1209 "backward compatibility with overlay \"dyngroup\"" );
1210 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1214 dynlist_info_t **dlip;
1215 ObjectClass *oc = NULL;
1216 AttributeDescription *ad = NULL,
1220 oc = oc_find( "groupOfURLs" );
1222 snprintf( c->msg, sizeof( c->msg ),
1223 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1224 "unable to find default ObjectClass \"groupOfURLs\"" );
1225 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1226 c->log, c->msg, 0 );
1230 rc = slap_str2ad( c->argv[ 1 ], &member_ad, &text );
1231 if ( rc != LDAP_SUCCESS ) {
1232 snprintf( c->msg, sizeof( c->msg ),
1233 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1234 "unable to find AttributeDescription \"%s\"",
1236 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1237 c->log, c->msg, 0 );
1241 rc = slap_str2ad( c->argv[ 2 ], &ad, &text );
1242 if ( rc != LDAP_SUCCESS ) {
1243 snprintf( c->msg, sizeof( c->msg ),
1244 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1245 "unable to find AttributeDescription \"%s\"\n",
1247 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1248 c->log, c->msg, 0 );
1252 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
1253 snprintf( c->msg, sizeof( c->msg ),
1254 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1255 "AttributeDescription \"%s\" "
1256 "must be a subtype of \"labeledURI\"",
1258 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1259 c->log, c->msg, 0 );
1263 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1264 *dlip; dlip = &(*dlip)->dli_next )
1266 /* The check on objectClass may be relaxed */
1268 if ( (*dlip)->dli_oc == oc ) {
1269 snprintf( c->msg, sizeof( c->msg ),
1270 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1271 "objectClass \"%s\" already mapped.\n",
1272 oc->soc_cname.bv_val );
1273 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1274 c->log, c->msg, 0 );
1279 if ( (*dlip)->dli_ad == ad ) {
1280 snprintf( c->msg, sizeof( c->msg ),
1281 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1282 "URL attributeDescription \"%s\" already mapped.\n",
1283 ad->ad_cname.bv_val );
1284 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1285 c->log, c->msg, 0 );
1289 if ( member_ad != NULL && (*dlip)->dli_member_ad == member_ad ) {
1290 snprintf( c->msg, sizeof( c->msg ),
1291 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1292 "member attributeDescription \"%s\" already mapped.\n",
1293 member_ad->ad_cname.bv_val );
1294 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1295 c->log, c->msg, 0 );
1300 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
1302 (*dlip)->dli_oc = oc;
1303 (*dlip)->dli_ad = ad;
1304 (*dlip)->dli_member_ad = member_ad;
1306 rc = dynlist_build_def_filter( *dlip );
1323 slap_overinst *on = (slap_overinst *) be->bd_info;
1324 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private;
1325 ObjectClass *oc = NULL;
1326 AttributeDescription *ad = NULL;
1328 if ( dli == NULL ) {
1329 dli = ch_calloc( 1, sizeof( dynlist_info_t ) );
1330 on->on_bi.bi_private = (void *)dli;
1333 for ( ; dli; dli = dli->dli_next ) {
1337 if ( dli->dli_oc == NULL ) {
1339 oc = oc_find( "groupOfURLs" );
1341 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: "
1342 "unable to fetch objectClass \"groupOfURLs\".\n",
1351 if ( dli->dli_ad == NULL ) {
1353 rc = slap_str2ad( "memberURL", &ad, &text );
1354 if ( rc != LDAP_SUCCESS ) {
1355 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: "
1356 "unable to fetch attributeDescription \"memberURL\": %d (%s).\n",
1365 if ( BER_BVISNULL( &dli->dli_default_filter ) ) {
1366 rc = dynlist_build_def_filter( dli );
1380 slap_overinst *on = (slap_overinst *) be->bd_info;
1382 if ( on->on_bi.bi_private ) {
1383 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private,
1386 for ( dli_next = dli; dli_next; dli = dli_next ) {
1387 dli_next = dli->dli_next;
1389 ch_free( dli->dli_default_filter.bv_val );
1397 static slap_overinst dynlist = { { NULL } };
1398 #ifdef TAKEOVER_DYNGROUP
1399 static char *obsolete_names[] = {
1405 #if SLAPD_OVER_DYNLIST == SLAPD_MOD_DYNAMIC
1407 #endif /* SLAPD_OVER_DYNLIST == SLAPD_MOD_DYNAMIC */
1409 dynlist_initialize(void)
1411 #ifndef OL_2_2_COMPAT
1415 dynlist.on_bi.bi_type = "dynlist";
1417 #ifdef TAKEOVER_DYNGROUP
1418 /* makes dynlist incompatible with dyngroup */
1419 dynlist.on_bi.bi_obsolete_names = obsolete_names;
1422 #ifdef OL_2_2_COMPAT
1423 dynlist.on_bi.bi_db_config = dynlist_db_config;
1425 dynlist.on_bi.bi_db_config = config_generic_wrapper;
1427 dynlist.on_bi.bi_db_open = dynlist_db_open;
1428 dynlist.on_bi.bi_db_destroy = dynlist_db_destroy;
1430 dynlist.on_response = dynlist_response;
1432 #ifndef OL_2_2_COMPAT
1433 dynlist.on_bi.bi_cf_ocs = dlocs;
1435 rc = config_register_schema( dlcfg, dlocs );
1441 return overlay_register( &dynlist );
1444 #if SLAPD_OVER_DYNLIST == SLAPD_MOD_DYNAMIC
1446 init_module( int argc, char *argv[] )
1448 return dynlist_initialize();
1452 #endif /* SLAPD_OVER_DYNLIST */