1 /* dynlist.c - dynamic list overlay */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2003-2006 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 #define TAKEOVER_DYNGROUP
28 #elif LDAP_VENDOR_VERSION_MINOR < 3
34 #include <ac/string.h>
42 /* FIXME: the code differs if SLAP_OPATTRS is defined or not;
43 * SLAP_OPATTRS is not defined in 2.2 yet, while this overlay
44 * expects HEAD code at least later than August 6, 2004. */
45 /* FIXME: slap_anlist_no_attrs was introduced in 2.3; here it
46 * is anticipated to allow using this overlay with 2.2. */
49 static AttributeName anlist_no_attrs[] = {
50 { BER_BVC( LDAP_NO_ATTRS ), NULL, 0, NULL },
51 { BER_BVNULL, NULL, 0, NULL }
54 static AttributeName *slap_anlist_no_attrs = anlist_no_attrs;
57 typedef struct dynlist_info_t {
59 AttributeDescription *dli_ad;
60 AttributeDescription *dli_member_ad;
61 struct berval dli_default_filter;
62 struct dynlist_info_t *dli_next;
65 static dynlist_info_t *
66 dynlist_is_dynlist( Operation *op, SlapReply *rs )
68 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
69 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private;
73 a = attrs_find( rs->sr_entry->e_attrs, slap_schema.si_ad_objectClass );
75 /* FIXME: objectClass must be present; for non-storage
76 * backends, like back-ldap, it needs to be added
77 * to the requested attributes */
81 for ( ; dli; dli = dli->dli_next ) {
82 if ( value_find_ex( slap_schema.si_ad_objectClass,
83 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
84 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
85 a->a_nvals, &dli->dli_oc->soc_cname,
86 op->o_tmpmemctx ) == 0 )
96 dynlist_make_filter( Operation *op, struct berval *oldf, struct berval *newf )
98 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
99 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private;
103 assert( oldf != NULL );
104 assert( newf != NULL );
105 assert( !BER_BVISNULL( oldf ) );
106 assert( !BER_BVISEMPTY( oldf ) );
108 newf->bv_len = STRLENOF( "(&(!(objectClass=" "))" ")" )
109 + dli->dli_oc->soc_cname.bv_len + oldf->bv_len;
110 newf->bv_val = op->o_tmpalloc( newf->bv_len + 1, op->o_tmpmemctx );
111 if ( newf->bv_val == NULL ) {
114 ptr = lutil_strcopy( newf->bv_val, "(&(!(objectClass=" );
115 ptr = lutil_strcopy( ptr, dli->dli_oc->soc_cname.bv_val );
116 ptr = lutil_strcopy( ptr, "))" );
117 ptr = lutil_strcopy( ptr, oldf->bv_val );
118 ptr = lutil_strcopy( ptr, ")" );
119 newf->bv_len = ptr - newf->bv_val;
124 typedef struct dynlist_sc_t {
125 dynlist_info_t *dlc_dli;
130 dynlist_sc_update( Operation *op, SlapReply *rs )
136 AccessControlState acl_state = ACL_STATE_INIT;
140 if ( rs->sr_type != REP_SEARCH ) {
144 dlc = (dynlist_sc_t *)op->o_callback->sc_private;
148 assert( rs->sr_entry != NULL );
150 /* test access to entry */
151 if ( !access_allowed( op, rs->sr_entry, slap_schema.si_ad_entry,
152 NULL, ACL_READ, NULL ) )
157 if ( dlc->dlc_dli->dli_member_ad ) {
159 /* if access allowed, try to add values, emulating permissive
160 * control to silently ignore duplicates */
161 if ( access_allowed( op, rs->sr_entry, slap_schema.si_ad_entry,
162 NULL, ACL_READ, NULL ) )
165 const char *text = NULL;
167 struct berval vals[ 2 ], nvals[ 2 ];
169 vals[ 0 ] = rs->sr_entry->e_name;
170 BER_BVZERO( &vals[ 1 ] );
171 nvals[ 0 ] = rs->sr_entry->e_nname;
172 BER_BVZERO( &nvals[ 1 ] );
174 mod.sm_op = LDAP_MOD_ADD;
175 mod.sm_desc = dlc->dlc_dli->dli_member_ad;
176 mod.sm_type = dlc->dlc_dli->dli_member_ad->ad_cname;
177 mod.sm_values = vals;
178 mod.sm_nvalues = nvals;
180 (void)modify_add_values( e, &mod, /* permissive */ 1,
181 &text, textbuf, sizeof( textbuf ) );
188 opattrs = ( rs->sr_attrs == NULL ) ? 0 : an_find( rs->sr_attrs, &AllOper );
189 userattrs = ( rs->sr_attrs == NULL ) ? 1 : an_find( rs->sr_attrs, &AllUser );
190 #else /* SLAP_OPATTRS */
191 opattrs = SLAP_OPATTRS( rs->sr_attr_flags );
192 userattrs = SLAP_USERATTRS( rs->sr_attr_flags );
193 #endif /* SLAP_OPATTRS */
195 for ( a = rs->sr_entry->e_attrs; a != NULL; a = a->a_next ) {
196 BerVarray vals, nvals = NULL;
199 /* if attribute is not requested, skip it */
200 if ( rs->sr_attrs == NULL ) {
201 if ( is_at_operational( a->a_desc->ad_type ) ) {
206 if ( is_at_operational( a->a_desc->ad_type ) ) {
207 if ( !opattrs && !ad_inlist( a->a_desc, rs->sr_attrs ) )
213 if ( !userattrs && !ad_inlist( a->a_desc, rs->sr_attrs ) )
220 /* test access to attribute */
221 if ( op->ors_attrsonly ) {
222 if ( !access_allowed( op, rs->sr_entry, a->a_desc, NULL,
223 ACL_READ, &acl_state ) )
229 /* single-value check: keep first only */
230 if ( is_at_single_value( a->a_desc->ad_type ) ) {
231 if ( attr_find( e->e_attrs, a->a_desc ) != NULL ) {
236 /* test access to attribute */
237 for ( i = 0; !BER_BVISNULL( &a->a_vals[i] ); i++ )
240 vals = op->o_tmpalloc( ( i + 1 ) * sizeof( struct berval ), op->o_tmpmemctx );
241 if ( a->a_nvals != a->a_vals ) {
242 nvals = op->o_tmpalloc( ( i + 1 ) * sizeof( struct berval ), op->o_tmpmemctx );
245 for ( i = 0, j = 0; !BER_BVISNULL( &a->a_vals[i] ); i++ ) {
246 if ( access_allowed( op, rs->sr_entry, a->a_desc,
247 &a->a_nvals[i], ACL_READ, &acl_state ) )
249 vals[j] = a->a_vals[i];
251 nvals[j] = a->a_nvals[i];
257 /* if access allowed, try to add values, emulating permissive
258 * control to silently ignore duplicates */
261 const char *text = NULL;
264 BER_BVZERO( &vals[j] );
266 BER_BVZERO( &nvals[j] );
269 mod.sm_op = LDAP_MOD_ADD;
270 mod.sm_desc = a->a_desc;
271 mod.sm_type = a->a_desc->ad_cname;
272 mod.sm_values = vals;
273 mod.sm_nvalues = nvals;
275 (void)modify_add_values( e, &mod, /* permissive */ 1,
276 &text, textbuf, sizeof( textbuf ) );
279 op->o_tmpfree( vals, op->o_tmpmemctx );
281 op->o_tmpfree( nvals, op->o_tmpmemctx );
286 if ( rs->sr_flags & REP_ENTRY_MUSTBEFREED ) {
287 entry_free( rs->sr_entry );
294 dynlist_send_entry( Operation *op, SlapReply *rs, dynlist_info_t *dli )
299 SlapReply r = { REP_SEARCH };
305 dynlist_sc_t dlc = { 0 };
307 a = attrs_find( rs->sr_entry->e_attrs, dli->dli_ad );
310 return SLAP_CB_CONTINUE;
313 e = entry_dup( rs->sr_entry );
314 e_flags = rs->sr_flags | ( REP_ENTRY_MODIFIABLE | REP_ENTRY_MUSTBEFREED );
318 cb.sc_private = &dlc;
319 cb.sc_response = dynlist_sc_update;
320 cb.sc_cleanup = NULL;
324 o.ors_deref = LDAP_DEREF_NEVER;
326 o.ors_tlimit = SLAP_NO_LIMIT;
327 o.ors_slimit = SLAP_NO_LIMIT;
330 opattrs = ( rs->sr_attrs == NULL ) ? 0 : an_find( rs->sr_attrs, &AllOper );
331 userattrs = ( rs->sr_attrs == NULL ) ? 1 : an_find( rs->sr_attrs, &AllUser );
332 #else /* SLAP_OPATTRS */
333 opattrs = SLAP_OPATTRS( rs->sr_attr_flags );
334 userattrs = SLAP_USERATTRS( rs->sr_attr_flags );
335 #endif /* SLAP_OPATTRS */
337 for ( url = a->a_nvals; !BER_BVISNULL( url ); url++ ) {
338 LDAPURLDesc *lud = NULL;
343 BER_BVZERO( &o.o_req_dn );
344 BER_BVZERO( &o.o_req_ndn );
347 BER_BVZERO( &o.ors_filterstr );
349 if ( ldap_url_parse( url->bv_val, &lud ) != LDAP_URL_SUCCESS ) {
354 if ( lud->lud_host != NULL ) {
355 /* FIXME: host not allowed; reject as illegal? */
356 Debug( LDAP_DEBUG_ANY, "dynlist_send_entry(\"%s\"): "
357 "illegal URI \"%s\"\n",
358 e->e_name.bv_val, url->bv_val, 0 );
362 if ( lud->lud_dn == NULL ) {
363 /* note that an empty base is not honored in terms
364 * of defaultSearchBase, because select_backend()
365 * is not aware of the defaultSearchBase option;
366 * this can be useful in case of a database serving
367 * the empty suffix */
368 BER_BVSTR( &dn, "" );
371 ber_str2bv( lud->lud_dn, 0, 0, &dn );
373 rc = dnPrettyNormal( NULL, &dn, &o.o_req_dn, &o.o_req_ndn, op->o_tmpmemctx );
374 if ( rc != LDAP_SUCCESS ) {
378 o.ors_scope = lud->lud_scope;
380 if ( dli->dli_member_ad != NULL ) {
381 /* if ( lud->lud_attrs != NULL ),
382 * the URL should be ignored */
383 o.ors_attrs = slap_anlist_no_attrs;
385 } else if ( lud->lud_attrs == NULL ) {
386 o.ors_attrs = rs->sr_attrs;
389 for ( i = 0; lud->lud_attrs[i]; i++)
392 o.ors_attrs = op->o_tmpcalloc( i + 1, sizeof( AttributeName ), op->o_tmpmemctx );
393 for ( i = 0, j = 0; lud->lud_attrs[i]; i++) {
394 const char *text = NULL;
396 ber_str2bv( lud->lud_attrs[i], 0, 0, &o.ors_attrs[j].an_name );
397 o.ors_attrs[j].an_desc = NULL;
398 (void)slap_bv2ad( &o.ors_attrs[j].an_name, &o.ors_attrs[j].an_desc, &text );
399 /* FIXME: ignore errors... */
401 if ( rs->sr_attrs == NULL ) {
402 if ( o.ors_attrs[j].an_desc != NULL &&
403 is_at_operational( o.ors_attrs[j].an_desc->ad_type ) )
409 if ( o.ors_attrs[j].an_desc != NULL &&
410 is_at_operational( o.ors_attrs[j].an_desc->ad_type ) )
412 if ( !opattrs && !ad_inlist( o.ors_attrs[j].an_desc, rs->sr_attrs ) )
419 o.ors_attrs[j].an_desc != NULL &&
420 !ad_inlist( o.ors_attrs[j].an_desc, rs->sr_attrs ) )
434 BER_BVZERO( &o.ors_attrs[j].an_name );
437 if ( lud->lud_filter == NULL ) {
438 ber_dupbv_x( &o.ors_filterstr,
439 &dli->dli_default_filter, op->o_tmpmemctx );
443 ber_str2bv( lud->lud_filter, 0, 0, &flt );
444 if ( dynlist_make_filter( op, &flt, &o.ors_filterstr ) ) {
449 o.ors_filter = str2filter_x( op, o.ors_filterstr.bv_val );
450 if ( o.ors_filter == NULL ) {
454 o.o_bd = select_backend( &o.o_req_ndn, 0, 1 );
455 if ( o.o_bd && o.o_bd->be_search ) {
457 r.sr_attr_flags = slap_attr_flags( o.ors_attrs );
458 #endif /* SLAP_OPATTRS */
459 (void)o.o_bd->be_search( &o, &r );
463 if ( o.ors_filter ) {
464 filter_free_x( &o, o.ors_filter );
466 if ( o.ors_attrs && o.ors_attrs != rs->sr_attrs
467 && o.ors_attrs != slap_anlist_no_attrs )
469 op->o_tmpfree( o.ors_attrs, op->o_tmpmemctx );
471 if ( !BER_BVISNULL( &o.o_req_dn ) ) {
472 op->o_tmpfree( o.o_req_dn.bv_val, op->o_tmpmemctx );
474 if ( !BER_BVISNULL( &o.o_req_ndn ) ) {
475 op->o_tmpfree( o.o_req_ndn.bv_val, op->o_tmpmemctx );
477 assert( o.ors_filterstr.bv_val != lud->lud_filter );
478 op->o_tmpfree( o.ors_filterstr.bv_val, op->o_tmpmemctx );
479 ldap_free_urldesc( lud );
483 rs->sr_flags = e_flags;
485 return SLAP_CB_CONTINUE;
489 dynlist_sc_save_entry( Operation *op, SlapReply *rs )
491 /* save the entry in the private field of the callback,
492 * so it doesn't get freed (it's temporary!) */
493 if ( rs->sr_entry != NULL ) {
494 dynlist_sc_t *dlc = (dynlist_sc_t *)op->o_callback->sc_private;
495 dlc->dlc_e = rs->sr_entry;
503 dynlist_compare( Operation *op, SlapReply *rs )
505 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
506 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private;
508 for ( ; dli != NULL; dli = dli->dli_next ) {
509 if ( op->oq_compare.rs_ava->aa_desc == dli->dli_member_ad ) {
510 /* This compare is for one of the attributes we're
511 * interested in. We'll use slapd's existing dyngroup
512 * evaluator to get the answer we want.
514 int cache = op->o_do_not_cache;
516 op->o_do_not_cache = 1;
517 rs->sr_err = backend_group( op, NULL, &op->o_req_ndn,
518 &op->oq_compare.rs_ava->aa_value, dli->dli_oc, dli->dli_ad );
519 op->o_do_not_cache = cache;
520 switch ( rs->sr_err ) {
522 rs->sr_err = LDAP_COMPARE_TRUE;
525 case LDAP_NO_SUCH_OBJECT:
526 /* NOTE: backend_group() returns noSuchObject
527 * if op_ndn does not exist; however, since
528 * dynamic list expansion means that the
529 * member attribute is virtually present, the
530 * non-existence of the asserted value implies
531 * the assertion is FALSE rather than
533 rs->sr_err = LDAP_COMPARE_FALSE;
537 return SLAP_CB_CONTINUE;
541 dli = (dynlist_info_t *)on->on_bi.bi_private;
542 for ( ; dli != NULL && rs->sr_err != LDAP_COMPARE_TRUE; dli = dli->dli_next ) {
546 SlapReply r = { REP_SEARCH };
549 dynlist_sc_t dlc = { 0 };
552 int cache = op->o_do_not_cache;
553 struct berval op_dn = op->o_dn,
555 BackendDB *op_bd = op->o_bd;
557 /* fetch the entry as rootdn (a hack to see if it exists
558 * and if it has the right objectClass) */
559 op->o_do_not_cache = 1;
560 op->o_dn = op->o_bd->be_rootdn;
561 op->o_ndn = op->o_bd->be_rootndn;
562 op->o_bd = select_backend( &op->o_req_ndn, 0, 0 );
564 r.sr_err = be_entry_get_rw( op, &op->o_req_ndn,
565 dli->dli_oc, NULL, 0, &e );
567 be_entry_release_r( op, e );
569 op->o_do_not_cache = cache;
573 if ( r.sr_err != LDAP_SUCCESS ) {
577 /* if the entry has the right objectClass, generate
578 * the dynamic list and compare */
580 cb.sc_private = &dlc;
581 cb.sc_response = dynlist_sc_save_entry;
582 cb.sc_cleanup = NULL;
586 o.o_tag = LDAP_REQ_SEARCH;
588 o.ors_tlimit = SLAP_NO_LIMIT;
589 o.ors_slimit = SLAP_NO_LIMIT;
591 o.o_bd = select_backend( &o.o_req_ndn, 0, 1 );
592 if ( !o.o_bd || !o.o_bd->be_search ) {
593 return SLAP_CB_CONTINUE;
596 BER_BVSTR( &o.ors_filterstr, "(objectClass=*)" );
597 o.ors_filter = str2filter_x( op, o.ors_filterstr.bv_val );
598 if ( o.ors_filter == NULL ) {
600 return SLAP_CB_CONTINUE;
603 o.ors_scope = LDAP_SCOPE_BASE;
604 o.ors_deref = LDAP_DEREF_NEVER;
605 an[0].an_name = op->orc_ava->aa_desc->ad_cname;
606 an[0].an_desc = op->orc_ava->aa_desc;
607 BER_BVZERO( &an[1].an_name );
611 rc = o.o_bd->be_search( &o, &r );
612 filter_free_x( &o, o.ors_filter );
618 if ( dlc.dlc_e != NULL ) {
619 r.sr_entry = dlc.dlc_e;
622 if ( r.sr_err != LDAP_SUCCESS || r.sr_entry == NULL ) {
624 return SLAP_CB_CONTINUE;
627 for ( a = attrs_find( r.sr_entry->e_attrs, op->orc_ava->aa_desc );
629 a = attrs_find( a->a_next, op->orc_ava->aa_desc ) )
631 /* if we're here, we got a match... */
632 rs->sr_err = LDAP_COMPARE_FALSE;
634 if ( value_find_ex( op->orc_ava->aa_desc,
635 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
636 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
637 a->a_nvals, &op->orc_ava->aa_value, op->o_tmpmemctx ) == 0 )
639 rs->sr_err = LDAP_COMPARE_TRUE;
644 if ( r.sr_flags & REP_ENTRY_MUSTBEFREED ) {
645 entry_free( r.sr_entry );
649 return SLAP_CB_CONTINUE;
653 dynlist_response( Operation *op, SlapReply *rs )
657 switch ( op->o_tag ) {
658 case LDAP_REQ_SEARCH:
659 if ( rs->sr_type == REP_SEARCH && !get_manageDSAit( op ) )
661 dli = dynlist_is_dynlist( op, rs );
663 return dynlist_send_entry( op, rs, dli );
668 case LDAP_REQ_COMPARE:
669 switch ( rs->sr_err ) {
670 /* NOTE: we waste a few cycles running the dynamic list
671 * also when the result is FALSE, which occurs if the
672 * dynamic entry itself contains the AVA attribute */
673 /* FIXME: this approach is less than optimal; a dedicated
674 * compare op should be implemented, that fetches the
675 * entry, checks if it has the appropriate objectClass
676 * and, in case, runs a compare thru all the URIs,
677 * stopping at the first positive occurrence; see ITS#3756 */
678 case LDAP_COMPARE_FALSE:
679 case LDAP_NO_SUCH_ATTRIBUTE:
680 return dynlist_compare( op, rs );
688 return SLAP_CB_CONTINUE;
692 dynlist_build_def_filter( dynlist_info_t *dli )
696 dli->dli_default_filter.bv_len = STRLENOF( "(!(objectClass=" "))" )
697 + dli->dli_oc->soc_cname.bv_len;
698 dli->dli_default_filter.bv_val = ch_malloc( dli->dli_default_filter.bv_len + 1 );
699 if ( dli->dli_default_filter.bv_val == NULL ) {
700 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: malloc failed.\n",
705 ptr = lutil_strcopy( dli->dli_default_filter.bv_val, "(!(objectClass=" );
706 ptr = lutil_strcopy( ptr, dli->dli_oc->soc_cname.bv_val );
707 ptr = lutil_strcopy( ptr, "))" );
709 assert( dli->dli_default_filter.bv_len == ptr - dli->dli_default_filter.bv_val );
723 slap_overinst *on = (slap_overinst *)be->bd_info;
727 if ( strcasecmp( argv[0], "dynlist-attrset" ) == 0 ) {
728 dynlist_info_t **dlip;
730 AttributeDescription *ad = NULL,
734 if ( argc < 3 || argc > 4 ) {
735 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
736 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
737 "invalid arg number #%d.\n",
738 fname, lineno, argc );
742 oc = oc_find( argv[1] );
744 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
745 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
746 "unable to find ObjectClass \"%s\"\n",
747 fname, lineno, argv[ 1 ] );
751 rc = slap_str2ad( argv[2], &ad, &text );
752 if ( rc != LDAP_SUCCESS ) {
753 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
754 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
755 "unable to find AttributeDescription \"%s\"\n",
756 fname, lineno, argv[2] );
760 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
761 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
762 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
763 "AttributeDescription \"%s\" "
764 "must be a subtype of \"labeledURI\"\n",
765 fname, lineno, argv[2] );
770 rc = slap_str2ad( argv[3], &member_ad, &text );
771 if ( rc != LDAP_SUCCESS ) {
772 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
773 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
774 "unable to find AttributeDescription \"%s\"\n",
775 fname, lineno, argv[3] );
780 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
781 *dlip; dlip = &(*dlip)->dli_next )
783 /* The check on objectClass may be relaxed */
785 if ( (*dlip)->dli_oc == oc ) {
786 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
787 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
788 "objectClass \"%s\" already mapped.\n",
789 fname, lineno, oc->soc_cname.bv_val );
794 if ( (*dlip)->dli_ad == ad ) {
795 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
796 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
797 "URL attributeDescription \"%s\" already mapped.\n",
798 fname, lineno, ad->ad_cname.bv_val );
802 if ( member_ad != NULL && (*dlip)->dli_member_ad == member_ad ) {
803 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
804 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
805 "member attributeDescription \"%s\" already mapped.\n",
806 fname, lineno, member_ad->ad_cname.bv_val );
811 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
812 (*dlip)->dli_oc = oc;
813 (*dlip)->dli_ad = ad;
814 (*dlip)->dli_member_ad = member_ad;
816 if ( dynlist_build_def_filter( *dlip ) ) {
822 /* allow dyngroup syntax */
823 } else if ( strcasecmp( argv[0], "dynlist-attrpair" ) == 0 ) {
824 dynlist_info_t **dlip;
826 AttributeDescription *ad = NULL,
831 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
832 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
833 "invalid arg number #%d.\n",
834 fname, lineno, argc );
838 oc = oc_find( "groupOfURLs" );
840 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
841 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
842 "unable to find default ObjectClass \"groupOfURLs\"\n",
847 rc = slap_str2ad( argv[1], &member_ad, &text );
848 if ( rc != LDAP_SUCCESS ) {
849 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
850 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
851 "unable to find AttributeDescription \"%s\"\n",
852 fname, lineno, argv[1] );
856 rc = slap_str2ad( argv[2], &ad, &text );
857 if ( rc != LDAP_SUCCESS ) {
858 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
859 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
860 "unable to find AttributeDescription \"%s\"\n",
861 fname, lineno, argv[2] );
865 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
866 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
867 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
868 "AttributeDescription \"%s\" "
869 "must be a subtype of \"labeledURI\"\n",
870 fname, lineno, argv[2] );
875 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
876 *dlip; dlip = &(*dlip)->dli_next )
879 /* The check on objectClass may be relaxed */
880 if ( (*dlip)->dli_oc == oc ) {
881 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
882 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
883 "objectClass \"%s\" already mapped.\n",
884 fname, lineno, oc->soc_cname.bv_val );
889 if ( (*dlip)->dli_ad == ad ) {
890 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
891 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
892 "URL attributeDescription \"%s\" already mapped.\n",
893 fname, lineno, ad->ad_cname.bv_val );
897 if ( member_ad != NULL && (*dlip)->dli_member_ad == member_ad ) {
898 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
899 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
900 "member attributeDescription \"%s\" already mapped.\n",
901 fname, lineno, member_ad->ad_cname.bv_val );
906 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
907 (*dlip)->dli_oc = oc;
908 (*dlip)->dli_ad = ad;
909 (*dlip)->dli_member_ad = member_ad;
911 if ( dynlist_build_def_filter( *dlip ) ) {
918 rc = SLAP_CONF_UNKNOWN;
932 static ConfigDriver dl_cfgen;
934 static ConfigTable dlcfg[] = {
935 { "dynlist-attrset", "group-oc> <URL-ad> <member-ad",
936 3, 4, 0, ARG_MAGIC|DL_ATTRSET, dl_cfgen,
937 "( OLcfgOvAt:8.1 NAME 'olcDLattrSet' "
938 "DESC 'Dynamic list: <group objectClass>, <URL attributeDescription>, <member attributeDescription>' "
939 "EQUALITY caseIgnoreMatch "
940 "SYNTAX OMsDirectoryString "
941 "X-ORDERED 'VALUES' )",
943 { "dynlist-attrpair", "member-ad> <URL-ad",
944 3, 3, 0, ARG_MAGIC|DL_ATTRPAIR, dl_cfgen,
946 #ifdef TAKEOVER_DYNGROUP
947 { "attrpair", "member-ad> <URL-ad",
948 3, 3, 0, ARG_MAGIC|DL_ATTRPAIR_COMPAT, dl_cfgen,
951 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
954 static ConfigOCs dlocs[] = {
956 "NAME 'olcDynamicList' "
957 "DESC 'Dynamic list configuration' "
958 "SUP olcOverlayConfig "
959 "MAY olcDLattrSet )",
960 Cft_Overlay, dlcfg, NULL, NULL },
965 dl_cfgen( ConfigArgs *c )
967 slap_overinst *on = (slap_overinst *)c->bi;
968 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private;
972 if ( c->op == SLAP_CONFIG_EMIT ) {
975 for ( i = 0; dli; i++, dli = dli->dli_next ) {
979 assert( dli->dli_oc != NULL );
980 assert( dli->dli_ad != NULL );
982 ptr += snprintf( c->msg, sizeof( c->msg ),
983 SLAP_X_ORDERED_FMT "%s %s", i,
984 dli->dli_oc->soc_cname.bv_val,
985 dli->dli_ad->ad_cname.bv_val );
987 if ( dli->dli_member_ad != NULL ) {
990 ptr = lutil_strcopy( ptr, dli->dli_member_ad->ad_cname.bv_val );
994 bv.bv_len = ptr - bv.bv_val;
995 value_add_one( &c->rvalue_vals, &bv );
999 case DL_ATTRPAIR_COMPAT:
1011 } else if ( c->op == LDAP_MOD_DELETE ) {
1014 if ( c->valx < 0 ) {
1015 dynlist_info_t *dli_next;
1017 for ( dli_next = dli; dli_next; dli = dli_next ) {
1018 dli_next = dli->dli_next;
1020 ch_free( dli->dli_default_filter.bv_val );
1024 on->on_bi.bi_private = NULL;
1027 dynlist_info_t **dlip;
1029 for ( i = 0, dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1032 if ( *dlip == NULL ) {
1035 dlip = &(*dlip)->dli_next;
1039 *dlip = dli->dli_next;
1040 ch_free( dli->dli_default_filter.bv_val );
1043 dli = (dynlist_info_t *)on->on_bi.bi_private;
1047 case DL_ATTRPAIR_COMPAT:
1057 return 1; /* FIXME */
1062 dynlist_info_t **dlip,
1064 ObjectClass *oc = NULL;
1065 AttributeDescription *ad = NULL,
1069 oc = oc_find( c->argv[ 1 ] );
1071 snprintf( c->msg, sizeof( c->msg ),
1072 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1073 "unable to find ObjectClass \"%s\"",
1075 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1076 c->log, c->msg, 0 );
1080 rc = slap_str2ad( c->argv[ 2 ], &ad, &text );
1081 if ( rc != LDAP_SUCCESS ) {
1082 snprintf( c->msg, sizeof( c->msg ),
1083 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1084 "unable to find AttributeDescription \"%s\"",
1086 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1087 c->log, c->msg, 0 );
1091 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
1092 snprintf( c->msg, sizeof( c->msg ),
1093 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1094 "AttributeDescription \"%s\" "
1095 "must be a subtype of \"labeledURI\"",
1097 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1098 c->log, c->msg, 0 );
1102 if ( c->argc == 4 ) {
1103 rc = slap_str2ad( c->argv[ 3 ], &member_ad, &text );
1104 if ( rc != LDAP_SUCCESS ) {
1105 snprintf( c->msg, sizeof( c->msg ),
1106 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1107 "unable to find AttributeDescription \"%s\"\n",
1109 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1110 c->log, c->msg, 0 );
1115 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1116 *dlip; dlip = &(*dlip)->dli_next )
1118 /* The check on objectClass may be relaxed */
1120 if ( (*dlip)->dli_oc == oc ) {
1121 snprintf( c->msg, sizeof( c->msg ),
1122 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1123 "objectClass \"%s\" already mapped.\n",
1124 oc->soc_cname.bv_val );
1125 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1126 c->log, c->msg, 0 );
1131 if ( (*dlip)->dli_ad == ad ) {
1132 snprintf( c->msg, sizeof( c->msg ),
1133 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1134 "URL attributeDescription \"%s\" already mapped.\n",
1135 ad->ad_cname.bv_val );
1136 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1137 c->log, c->msg, 0 );
1141 if ( member_ad != NULL && (*dlip)->dli_member_ad == member_ad ) {
1142 snprintf( c->msg, sizeof( c->msg ),
1143 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1144 "member attributeDescription \"%s\" already mapped.\n",
1145 member_ad->ad_cname.bv_val );
1146 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1147 c->log, c->msg, 0 );
1152 if ( c->valx > 0 ) {
1155 for ( i = 0, dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1158 if ( *dlip == NULL ) {
1159 snprintf( c->msg, sizeof( c->msg ),
1160 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1161 "invalid index {%d}\n",
1163 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1164 c->log, c->msg, 0 );
1167 dlip = &(*dlip)->dli_next;
1172 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1173 *dlip; dlip = &(*dlip)->dli_next )
1177 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
1179 (*dlip)->dli_oc = oc;
1180 (*dlip)->dli_ad = ad;
1181 (*dlip)->dli_member_ad = member_ad;
1182 (*dlip)->dli_next = dli_next;
1184 rc = dynlist_build_def_filter( *dlip );
1188 case DL_ATTRPAIR_COMPAT:
1189 snprintf( c->msg, sizeof( c->msg ),
1190 "warning: \"attrpair\" only supported for limited "
1191 "backward compatibility with overlay \"dyngroup\"" );
1192 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1196 dynlist_info_t **dlip;
1197 ObjectClass *oc = NULL;
1198 AttributeDescription *ad = NULL,
1202 oc = oc_find( "groupOfURLs" );
1204 snprintf( c->msg, sizeof( c->msg ),
1205 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1206 "unable to find default ObjectClass \"groupOfURLs\"" );
1207 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1208 c->log, c->msg, 0 );
1212 rc = slap_str2ad( c->argv[ 1 ], &member_ad, &text );
1213 if ( rc != LDAP_SUCCESS ) {
1214 snprintf( c->msg, sizeof( c->msg ),
1215 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1216 "unable to find AttributeDescription \"%s\"",
1218 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1219 c->log, c->msg, 0 );
1223 rc = slap_str2ad( c->argv[ 2 ], &ad, &text );
1224 if ( rc != LDAP_SUCCESS ) {
1225 snprintf( c->msg, sizeof( c->msg ),
1226 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1227 "unable to find AttributeDescription \"%s\"\n",
1229 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1230 c->log, c->msg, 0 );
1234 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
1235 snprintf( c->msg, sizeof( c->msg ),
1236 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1237 "AttributeDescription \"%s\" "
1238 "must be a subtype of \"labeledURI\"",
1240 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1241 c->log, c->msg, 0 );
1245 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1246 *dlip; dlip = &(*dlip)->dli_next )
1248 /* The check on objectClass may be relaxed */
1250 if ( (*dlip)->dli_oc == oc ) {
1251 snprintf( c->msg, sizeof( c->msg ),
1252 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1253 "objectClass \"%s\" already mapped.\n",
1254 oc->soc_cname.bv_val );
1255 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1256 c->log, c->msg, 0 );
1261 if ( (*dlip)->dli_ad == ad ) {
1262 snprintf( c->msg, sizeof( c->msg ),
1263 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1264 "URL attributeDescription \"%s\" already mapped.\n",
1265 ad->ad_cname.bv_val );
1266 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1267 c->log, c->msg, 0 );
1271 if ( member_ad != NULL && (*dlip)->dli_member_ad == member_ad ) {
1272 snprintf( c->msg, sizeof( c->msg ),
1273 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1274 "member attributeDescription \"%s\" already mapped.\n",
1275 member_ad->ad_cname.bv_val );
1276 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1277 c->log, c->msg, 0 );
1282 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
1284 (*dlip)->dli_oc = oc;
1285 (*dlip)->dli_ad = ad;
1286 (*dlip)->dli_member_ad = member_ad;
1288 rc = dynlist_build_def_filter( *dlip );
1305 slap_overinst *on = (slap_overinst *) be->bd_info;
1306 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private;
1307 ObjectClass *oc = NULL;
1308 AttributeDescription *ad = NULL;
1310 if ( dli == NULL ) {
1311 dli = ch_calloc( 1, sizeof( dynlist_info_t ) );
1312 on->on_bi.bi_private = (void *)dli;
1315 for ( ; dli; dli = dli->dli_next ) {
1319 if ( dli->dli_oc == NULL ) {
1321 oc = oc_find( "groupOfURLs" );
1323 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: "
1324 "unable to fetch objectClass \"groupOfURLs\".\n",
1333 if ( dli->dli_ad == NULL ) {
1335 rc = slap_str2ad( "memberURL", &ad, &text );
1336 if ( rc != LDAP_SUCCESS ) {
1337 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: "
1338 "unable to fetch attributeDescription \"memberURL\": %d (%s).\n",
1347 if ( BER_BVISNULL( &dli->dli_default_filter ) ) {
1348 rc = dynlist_build_def_filter( dli );
1362 slap_overinst *on = (slap_overinst *) be->bd_info;
1364 if ( on->on_bi.bi_private ) {
1365 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private,
1368 for ( dli_next = dli; dli_next; dli = dli_next ) {
1369 dli_next = dli->dli_next;
1371 ch_free( dli->dli_default_filter.bv_val );
1379 static slap_overinst dynlist = { { NULL } };
1380 #ifdef TAKEOVER_DYNGROUP
1381 static char *obsolete_names[] = {
1387 #if SLAPD_OVER_DYNLIST == SLAPD_MOD_DYNAMIC
1389 #endif /* SLAPD_OVER_DYNLIST == SLAPD_MOD_DYNAMIC */
1391 dynlist_initialize(void)
1393 #ifndef OL_2_2_COMPAT
1397 dynlist.on_bi.bi_type = "dynlist";
1399 #ifdef TAKEOVER_DYNGROUP
1400 /* makes dynlist incompatible with dyngroup */
1401 dynlist.on_bi.bi_obsolete_names = obsolete_names;
1404 #ifdef OL_2_2_COMPAT
1405 dynlist.on_bi.bi_db_config = dynlist_db_config;
1407 dynlist.on_bi.bi_db_config = config_generic_wrapper;
1409 dynlist.on_bi.bi_db_open = dynlist_db_open;
1410 dynlist.on_bi.bi_db_destroy = dynlist_db_destroy;
1412 dynlist.on_response = dynlist_response;
1414 #ifndef OL_2_2_COMPAT
1415 dynlist.on_bi.bi_cf_ocs = dlocs;
1417 rc = config_register_schema( dlcfg, dlocs );
1423 return overlay_register( &dynlist );
1426 #if SLAPD_OVER_DYNLIST == SLAPD_MOD_DYNAMIC
1428 init_module( int argc, char *argv[] )
1430 return dynlist_initialize();
1434 #endif /* SLAPD_OVER_DYNLIST */