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( o.ors_filterstr.bv_val != lud->lud_filter );
493 op->o_tmpfree( o.ors_filterstr.bv_val, op->o_tmpmemctx );
494 ldap_free_urldesc( lud );
498 rs->sr_flags = e_flags;
500 return SLAP_CB_CONTINUE;
504 dynlist_sc_save_entry( Operation *op, SlapReply *rs )
506 /* save the entry in the private field of the callback,
507 * so it doesn't get freed (it's temporary!) */
508 if ( rs->sr_entry != NULL ) {
509 dynlist_sc_t *dlc = (dynlist_sc_t *)op->o_callback->sc_private;
510 dlc->dlc_e = rs->sr_entry;
518 dynlist_compare( Operation *op, SlapReply *rs )
520 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
521 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private;
523 for ( ; dli != NULL; dli = dli->dli_next ) {
524 if ( op->oq_compare.rs_ava->aa_desc == dli->dli_member_ad ) {
525 /* This compare is for one of the attributes we're
526 * interested in. We'll use slapd's existing dyngroup
527 * evaluator to get the answer we want.
529 int cache = op->o_do_not_cache;
531 op->o_do_not_cache = 1;
532 rs->sr_err = backend_group( op, NULL, &op->o_req_ndn,
533 &op->oq_compare.rs_ava->aa_value, dli->dli_oc, dli->dli_ad );
534 op->o_do_not_cache = cache;
535 switch ( rs->sr_err ) {
537 rs->sr_err = LDAP_COMPARE_TRUE;
540 case LDAP_NO_SUCH_OBJECT:
541 /* NOTE: backend_group() returns noSuchObject
542 * if op_ndn does not exist; however, since
543 * dynamic list expansion means that the
544 * member attribute is virtually present, the
545 * non-existence of the asserted value implies
546 * the assertion is FALSE rather than
548 rs->sr_err = LDAP_COMPARE_FALSE;
552 return SLAP_CB_CONTINUE;
556 dli = (dynlist_info_t *)on->on_bi.bi_private;
557 for ( ; dli != NULL && rs->sr_err != LDAP_COMPARE_TRUE; dli = dli->dli_next ) {
561 SlapReply r = { REP_SEARCH };
564 dynlist_sc_t dlc = { 0 };
567 int cache = op->o_do_not_cache;
568 struct berval op_dn = op->o_dn,
570 BackendDB *op_bd = op->o_bd;
572 /* fetch the entry as rootdn (a hack to see if it exists
573 * and if it has the right objectClass) */
574 op->o_do_not_cache = 1;
575 op->o_dn = op->o_bd->be_rootdn;
576 op->o_ndn = op->o_bd->be_rootndn;
577 op->o_bd = select_backend( &op->o_req_ndn, 0, 0 );
579 r.sr_err = be_entry_get_rw( op, &op->o_req_ndn,
580 dli->dli_oc, NULL, 0, &e );
582 be_entry_release_r( op, e );
584 op->o_do_not_cache = cache;
588 if ( r.sr_err != LDAP_SUCCESS ) {
592 /* if the entry has the right objectClass, generate
593 * the dynamic list and compare */
595 cb.sc_private = &dlc;
596 cb.sc_response = dynlist_sc_save_entry;
597 cb.sc_cleanup = NULL;
601 o.o_tag = LDAP_REQ_SEARCH;
603 o.ors_tlimit = SLAP_NO_LIMIT;
604 o.ors_slimit = SLAP_NO_LIMIT;
606 o.o_bd = select_backend( &o.o_req_ndn, 0, 1 );
607 if ( !o.o_bd || !o.o_bd->be_search ) {
608 return SLAP_CB_CONTINUE;
611 BER_BVSTR( &o.ors_filterstr, "(objectClass=*)" );
612 o.ors_filter = str2filter_x( op, o.ors_filterstr.bv_val );
613 if ( o.ors_filter == NULL ) {
615 return SLAP_CB_CONTINUE;
618 o.ors_scope = LDAP_SCOPE_BASE;
619 o.ors_deref = LDAP_DEREF_NEVER;
620 an[0].an_name = op->orc_ava->aa_desc->ad_cname;
621 an[0].an_desc = op->orc_ava->aa_desc;
622 BER_BVZERO( &an[1].an_name );
626 rc = o.o_bd->be_search( &o, &r );
627 filter_free_x( &o, o.ors_filter );
633 if ( dlc.dlc_e != NULL ) {
634 r.sr_entry = dlc.dlc_e;
637 if ( r.sr_err != LDAP_SUCCESS || r.sr_entry == NULL ) {
639 return SLAP_CB_CONTINUE;
642 for ( a = attrs_find( r.sr_entry->e_attrs, op->orc_ava->aa_desc );
644 a = attrs_find( a->a_next, op->orc_ava->aa_desc ) )
646 /* if we're here, we got a match... */
647 rs->sr_err = LDAP_COMPARE_FALSE;
649 if ( value_find_ex( op->orc_ava->aa_desc,
650 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
651 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
652 a->a_nvals, &op->orc_ava->aa_value, op->o_tmpmemctx ) == 0 )
654 rs->sr_err = LDAP_COMPARE_TRUE;
659 if ( r.sr_flags & REP_ENTRY_MUSTBEFREED ) {
660 entry_free( r.sr_entry );
664 return SLAP_CB_CONTINUE;
668 dynlist_response( Operation *op, SlapReply *rs )
672 switch ( op->o_tag ) {
673 case LDAP_REQ_SEARCH:
674 if ( rs->sr_type == REP_SEARCH && !get_manageDSAit( op ) )
676 dli = dynlist_is_dynlist( op, rs );
678 return dynlist_send_entry( op, rs, dli );
683 case LDAP_REQ_COMPARE:
684 switch ( rs->sr_err ) {
685 /* NOTE: we waste a few cycles running the dynamic list
686 * also when the result is FALSE, which occurs if the
687 * dynamic entry itself contains the AVA attribute */
688 /* FIXME: this approach is less than optimal; a dedicated
689 * compare op should be implemented, that fetches the
690 * entry, checks if it has the appropriate objectClass
691 * and, in case, runs a compare thru all the URIs,
692 * stopping at the first positive occurrence; see ITS#3756 */
693 case LDAP_COMPARE_FALSE:
694 case LDAP_NO_SUCH_ATTRIBUTE:
695 return dynlist_compare( op, rs );
703 return SLAP_CB_CONTINUE;
707 dynlist_build_def_filter( dynlist_info_t *dli )
711 dli->dli_default_filter.bv_len = STRLENOF( "(!(objectClass=" "))" )
712 + dli->dli_oc->soc_cname.bv_len;
713 dli->dli_default_filter.bv_val = ch_malloc( dli->dli_default_filter.bv_len + 1 );
714 if ( dli->dli_default_filter.bv_val == NULL ) {
715 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: malloc failed.\n",
720 ptr = lutil_strcopy( dli->dli_default_filter.bv_val, "(!(objectClass=" );
721 ptr = lutil_strcopy( ptr, dli->dli_oc->soc_cname.bv_val );
722 ptr = lutil_strcopy( ptr, "))" );
724 assert( dli->dli_default_filter.bv_len == ptr - dli->dli_default_filter.bv_val );
738 slap_overinst *on = (slap_overinst *)be->bd_info;
742 if ( strcasecmp( argv[0], "dynlist-attrset" ) == 0 ) {
743 dynlist_info_t **dlip;
745 AttributeDescription *ad = NULL,
749 if ( argc < 3 || argc > 4 ) {
750 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
751 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
752 "invalid arg number #%d.\n",
753 fname, lineno, argc );
757 oc = oc_find( argv[1] );
759 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
760 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
761 "unable to find ObjectClass \"%s\"\n",
762 fname, lineno, argv[ 1 ] );
766 rc = slap_str2ad( argv[2], &ad, &text );
767 if ( rc != LDAP_SUCCESS ) {
768 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
769 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
770 "unable to find AttributeDescription \"%s\"\n",
771 fname, lineno, argv[2] );
775 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
776 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
777 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
778 "AttributeDescription \"%s\" "
779 "must be a subtype of \"labeledURI\"\n",
780 fname, lineno, argv[2] );
785 rc = slap_str2ad( argv[3], &member_ad, &text );
786 if ( rc != LDAP_SUCCESS ) {
787 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
788 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
789 "unable to find AttributeDescription \"%s\"\n",
790 fname, lineno, argv[3] );
795 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
796 *dlip; dlip = &(*dlip)->dli_next )
798 /* The check on objectClass may be relaxed */
800 if ( (*dlip)->dli_oc == oc ) {
801 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
802 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
803 "objectClass \"%s\" already mapped.\n",
804 fname, lineno, oc->soc_cname.bv_val );
809 if ( (*dlip)->dli_ad == ad ) {
810 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
811 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
812 "URL attributeDescription \"%s\" already mapped.\n",
813 fname, lineno, ad->ad_cname.bv_val );
817 if ( member_ad != NULL && (*dlip)->dli_member_ad == member_ad ) {
818 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
819 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
820 "member attributeDescription \"%s\" already mapped.\n",
821 fname, lineno, member_ad->ad_cname.bv_val );
826 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
827 (*dlip)->dli_oc = oc;
828 (*dlip)->dli_ad = ad;
829 (*dlip)->dli_member_ad = member_ad;
831 if ( dynlist_build_def_filter( *dlip ) ) {
837 /* allow dyngroup syntax */
838 } else if ( strcasecmp( argv[0], "dynlist-attrpair" ) == 0 ) {
839 dynlist_info_t **dlip;
841 AttributeDescription *ad = NULL,
846 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
847 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
848 "invalid arg number #%d.\n",
849 fname, lineno, argc );
853 oc = oc_find( "groupOfURLs" );
855 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
856 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
857 "unable to find default ObjectClass \"groupOfURLs\"\n",
862 rc = slap_str2ad( argv[1], &member_ad, &text );
863 if ( rc != LDAP_SUCCESS ) {
864 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
865 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
866 "unable to find AttributeDescription \"%s\"\n",
867 fname, lineno, argv[1] );
871 rc = slap_str2ad( argv[2], &ad, &text );
872 if ( rc != LDAP_SUCCESS ) {
873 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
874 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
875 "unable to find AttributeDescription \"%s\"\n",
876 fname, lineno, argv[2] );
880 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
881 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
882 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
883 "AttributeDescription \"%s\" "
884 "must be a subtype of \"labeledURI\"\n",
885 fname, lineno, argv[2] );
890 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
891 *dlip; dlip = &(*dlip)->dli_next )
894 /* The check on objectClass may be relaxed */
895 if ( (*dlip)->dli_oc == oc ) {
896 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
897 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
898 "objectClass \"%s\" already mapped.\n",
899 fname, lineno, oc->soc_cname.bv_val );
904 if ( (*dlip)->dli_ad == ad ) {
905 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
906 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
907 "URL attributeDescription \"%s\" already mapped.\n",
908 fname, lineno, ad->ad_cname.bv_val );
912 if ( member_ad != NULL && (*dlip)->dli_member_ad == member_ad ) {
913 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
914 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
915 "member attributeDescription \"%s\" already mapped.\n",
916 fname, lineno, member_ad->ad_cname.bv_val );
921 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
922 (*dlip)->dli_oc = oc;
923 (*dlip)->dli_ad = ad;
924 (*dlip)->dli_member_ad = member_ad;
926 if ( dynlist_build_def_filter( *dlip ) ) {
933 rc = SLAP_CONF_UNKNOWN;
947 static ConfigDriver dl_cfgen;
949 static ConfigTable dlcfg[] = {
950 { "dynlist-attrset", "group-oc> <URL-ad> <member-ad",
951 3, 4, 0, ARG_MAGIC|DL_ATTRSET, dl_cfgen,
952 "( OLcfgOvAt:8.1 NAME 'olcDLattrSet' "
953 "DESC 'Dynamic list: <group objectClass>, <URL attributeDescription>, <member attributeDescription>' "
954 "EQUALITY caseIgnoreMatch "
955 "SYNTAX OMsDirectoryString "
956 "X-ORDERED 'VALUES' )",
958 { "dynlist-attrpair", "member-ad> <URL-ad",
959 3, 3, 0, ARG_MAGIC|DL_ATTRPAIR, dl_cfgen,
961 #ifdef TAKEOVER_DYNGROUP
962 { "attrpair", "member-ad> <URL-ad",
963 3, 3, 0, ARG_MAGIC|DL_ATTRPAIR_COMPAT, dl_cfgen,
966 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
969 static ConfigOCs dlocs[] = {
971 "NAME 'olcDynamicList' "
972 "DESC 'Dynamic list configuration' "
973 "SUP olcOverlayConfig "
974 "MAY olcDLattrSet )",
975 Cft_Overlay, dlcfg, NULL, NULL },
980 dl_cfgen( ConfigArgs *c )
982 slap_overinst *on = (slap_overinst *)c->bi;
983 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private;
987 if ( c->op == SLAP_CONFIG_EMIT ) {
990 for ( i = 0; dli; i++, dli = dli->dli_next ) {
994 assert( dli->dli_oc != NULL );
995 assert( dli->dli_ad != NULL );
997 ptr += snprintf( c->msg, sizeof( c->msg ),
998 SLAP_X_ORDERED_FMT "%s %s", i,
999 dli->dli_oc->soc_cname.bv_val,
1000 dli->dli_ad->ad_cname.bv_val );
1002 if ( dli->dli_member_ad != NULL ) {
1005 ptr = lutil_strcopy( ptr, dli->dli_member_ad->ad_cname.bv_val );
1009 bv.bv_len = ptr - bv.bv_val;
1010 value_add_one( &c->rvalue_vals, &bv );
1014 case DL_ATTRPAIR_COMPAT:
1026 } else if ( c->op == LDAP_MOD_DELETE ) {
1029 if ( c->valx < 0 ) {
1030 dynlist_info_t *dli_next;
1032 for ( dli_next = dli; dli_next; dli = dli_next ) {
1033 dli_next = dli->dli_next;
1035 ch_free( dli->dli_default_filter.bv_val );
1039 on->on_bi.bi_private = NULL;
1042 dynlist_info_t **dlip;
1044 for ( i = 0, dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1047 if ( *dlip == NULL ) {
1050 dlip = &(*dlip)->dli_next;
1054 *dlip = dli->dli_next;
1055 ch_free( dli->dli_default_filter.bv_val );
1058 dli = (dynlist_info_t *)on->on_bi.bi_private;
1062 case DL_ATTRPAIR_COMPAT:
1072 return 1; /* FIXME */
1077 dynlist_info_t **dlip,
1079 ObjectClass *oc = NULL;
1080 AttributeDescription *ad = NULL,
1084 oc = oc_find( c->argv[ 1 ] );
1086 snprintf( c->msg, sizeof( c->msg ),
1087 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1088 "unable to find ObjectClass \"%s\"",
1090 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1091 c->log, c->msg, 0 );
1095 rc = slap_str2ad( c->argv[ 2 ], &ad, &text );
1096 if ( rc != LDAP_SUCCESS ) {
1097 snprintf( c->msg, sizeof( c->msg ),
1098 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1099 "unable to find AttributeDescription \"%s\"",
1101 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1102 c->log, c->msg, 0 );
1106 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
1107 snprintf( c->msg, sizeof( c->msg ),
1108 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1109 "AttributeDescription \"%s\" "
1110 "must be a subtype of \"labeledURI\"",
1112 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1113 c->log, c->msg, 0 );
1117 if ( c->argc == 4 ) {
1118 rc = slap_str2ad( c->argv[ 3 ], &member_ad, &text );
1119 if ( rc != LDAP_SUCCESS ) {
1120 snprintf( c->msg, sizeof( c->msg ),
1121 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1122 "unable to find AttributeDescription \"%s\"\n",
1124 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1125 c->log, c->msg, 0 );
1130 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1131 *dlip; dlip = &(*dlip)->dli_next )
1133 /* The check on objectClass may be relaxed */
1135 if ( (*dlip)->dli_oc == oc ) {
1136 snprintf( c->msg, sizeof( c->msg ),
1137 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1138 "objectClass \"%s\" already mapped.\n",
1139 oc->soc_cname.bv_val );
1140 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1141 c->log, c->msg, 0 );
1146 if ( (*dlip)->dli_ad == ad ) {
1147 snprintf( c->msg, sizeof( c->msg ),
1148 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1149 "URL attributeDescription \"%s\" already mapped.\n",
1150 ad->ad_cname.bv_val );
1151 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1152 c->log, c->msg, 0 );
1156 if ( member_ad != NULL && (*dlip)->dli_member_ad == member_ad ) {
1157 snprintf( c->msg, sizeof( c->msg ),
1158 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1159 "member attributeDescription \"%s\" already mapped.\n",
1160 member_ad->ad_cname.bv_val );
1161 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1162 c->log, c->msg, 0 );
1167 if ( c->valx > 0 ) {
1170 for ( i = 0, dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1173 if ( *dlip == NULL ) {
1174 snprintf( c->msg, sizeof( c->msg ),
1175 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1176 "invalid index {%d}\n",
1178 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1179 c->log, c->msg, 0 );
1182 dlip = &(*dlip)->dli_next;
1187 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1188 *dlip; dlip = &(*dlip)->dli_next )
1192 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
1194 (*dlip)->dli_oc = oc;
1195 (*dlip)->dli_ad = ad;
1196 (*dlip)->dli_member_ad = member_ad;
1197 (*dlip)->dli_next = dli_next;
1199 rc = dynlist_build_def_filter( *dlip );
1203 case DL_ATTRPAIR_COMPAT:
1204 snprintf( c->msg, sizeof( c->msg ),
1205 "warning: \"attrpair\" only supported for limited "
1206 "backward compatibility with overlay \"dyngroup\"" );
1207 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1211 dynlist_info_t **dlip;
1212 ObjectClass *oc = NULL;
1213 AttributeDescription *ad = NULL,
1217 oc = oc_find( "groupOfURLs" );
1219 snprintf( c->msg, sizeof( c->msg ),
1220 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1221 "unable to find default ObjectClass \"groupOfURLs\"" );
1222 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1223 c->log, c->msg, 0 );
1227 rc = slap_str2ad( c->argv[ 1 ], &member_ad, &text );
1228 if ( rc != LDAP_SUCCESS ) {
1229 snprintf( c->msg, sizeof( c->msg ),
1230 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1231 "unable to find AttributeDescription \"%s\"",
1233 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1234 c->log, c->msg, 0 );
1238 rc = slap_str2ad( c->argv[ 2 ], &ad, &text );
1239 if ( rc != LDAP_SUCCESS ) {
1240 snprintf( c->msg, sizeof( c->msg ),
1241 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1242 "unable to find AttributeDescription \"%s\"\n",
1244 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1245 c->log, c->msg, 0 );
1249 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
1250 snprintf( c->msg, sizeof( c->msg ),
1251 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1252 "AttributeDescription \"%s\" "
1253 "must be a subtype of \"labeledURI\"",
1255 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1256 c->log, c->msg, 0 );
1260 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1261 *dlip; dlip = &(*dlip)->dli_next )
1263 /* The check on objectClass may be relaxed */
1265 if ( (*dlip)->dli_oc == oc ) {
1266 snprintf( c->msg, sizeof( c->msg ),
1267 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1268 "objectClass \"%s\" already mapped.\n",
1269 oc->soc_cname.bv_val );
1270 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1271 c->log, c->msg, 0 );
1276 if ( (*dlip)->dli_ad == ad ) {
1277 snprintf( c->msg, sizeof( c->msg ),
1278 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1279 "URL attributeDescription \"%s\" already mapped.\n",
1280 ad->ad_cname.bv_val );
1281 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1282 c->log, c->msg, 0 );
1286 if ( member_ad != NULL && (*dlip)->dli_member_ad == member_ad ) {
1287 snprintf( c->msg, sizeof( c->msg ),
1288 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1289 "member attributeDescription \"%s\" already mapped.\n",
1290 member_ad->ad_cname.bv_val );
1291 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1292 c->log, c->msg, 0 );
1297 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
1299 (*dlip)->dli_oc = oc;
1300 (*dlip)->dli_ad = ad;
1301 (*dlip)->dli_member_ad = member_ad;
1303 rc = dynlist_build_def_filter( *dlip );
1320 slap_overinst *on = (slap_overinst *) be->bd_info;
1321 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private;
1322 ObjectClass *oc = NULL;
1323 AttributeDescription *ad = NULL;
1325 if ( dli == NULL ) {
1326 dli = ch_calloc( 1, sizeof( dynlist_info_t ) );
1327 on->on_bi.bi_private = (void *)dli;
1330 for ( ; dli; dli = dli->dli_next ) {
1334 if ( dli->dli_oc == NULL ) {
1336 oc = oc_find( "groupOfURLs" );
1338 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: "
1339 "unable to fetch objectClass \"groupOfURLs\".\n",
1348 if ( dli->dli_ad == NULL ) {
1350 rc = slap_str2ad( "memberURL", &ad, &text );
1351 if ( rc != LDAP_SUCCESS ) {
1352 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: "
1353 "unable to fetch attributeDescription \"memberURL\": %d (%s).\n",
1362 if ( BER_BVISNULL( &dli->dli_default_filter ) ) {
1363 rc = dynlist_build_def_filter( dli );
1377 slap_overinst *on = (slap_overinst *) be->bd_info;
1379 if ( on->on_bi.bi_private ) {
1380 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private,
1383 for ( dli_next = dli; dli_next; dli = dli_next ) {
1384 dli_next = dli->dli_next;
1386 ch_free( dli->dli_default_filter.bv_val );
1394 static slap_overinst dynlist = { { NULL } };
1395 #ifdef TAKEOVER_DYNGROUP
1396 static char *obsolete_names[] = {
1402 #if SLAPD_OVER_DYNLIST == SLAPD_MOD_DYNAMIC
1404 #endif /* SLAPD_OVER_DYNLIST == SLAPD_MOD_DYNAMIC */
1406 dynlist_initialize(void)
1408 #ifndef OL_2_2_COMPAT
1412 dynlist.on_bi.bi_type = "dynlist";
1414 #ifdef TAKEOVER_DYNGROUP
1415 /* makes dynlist incompatible with dyngroup */
1416 dynlist.on_bi.bi_obsolete_names = obsolete_names;
1419 #ifdef OL_2_2_COMPAT
1420 dynlist.on_bi.bi_db_config = dynlist_db_config;
1422 dynlist.on_bi.bi_db_config = config_generic_wrapper;
1424 dynlist.on_bi.bi_db_open = dynlist_db_open;
1425 dynlist.on_bi.bi_db_destroy = dynlist_db_destroy;
1427 dynlist.on_response = dynlist_response;
1429 #ifndef OL_2_2_COMPAT
1430 dynlist.on_bi.bi_cf_ocs = dlocs;
1432 rc = config_register_schema( dlcfg, dlocs );
1438 return overlay_register( &dynlist );
1441 #if SLAPD_OVER_DYNLIST == SLAPD_MOD_DYNAMIC
1443 init_module( int argc, char *argv[] )
1445 return dynlist_initialize();
1449 #endif /* SLAPD_OVER_DYNLIST */