1 /* dynlist.c - dynamic list overlay */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2003-2009 The OpenLDAP Foundation.
6 * Portions Copyright 2004-2005 Pierangelo Masarati.
7 * Portions Copyright 2008 Emmanuel Dreyfus.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted only as authorized by the OpenLDAP
14 * A copy of this license is available in the file LICENSE in the
15 * top-level directory of the distribution or, alternatively, at
16 * <http://www.OpenLDAP.org/license.html>.
19 * This work was initially developed by Pierangelo Masarati
20 * for SysNet s.n.c., for inclusion in OpenLDAP Software.
25 #ifdef SLAPD_OVER_DYNLIST
27 #if LDAP_VENDOR_VERSION_MINOR == X || LDAP_VENDOR_VERSION_MINOR > 3
28 #if SLAPD_OVER_DYNGROUP != SLAPD_MOD_STATIC
29 #define TAKEOVER_DYNGROUP
32 #if LDAP_VENDOR_VERSION_MINOR < 3
39 #include <ac/string.h>
47 /* FIXME: the code differs if SLAP_OPATTRS is defined or not;
48 * SLAP_OPATTRS is not defined in 2.2 yet, while this overlay
49 * expects HEAD code at least later than August 6, 2004. */
50 /* FIXME: slap_anlist_no_attrs was introduced in 2.3; here it
51 * is anticipated to allow using this overlay with 2.2. */
54 static AttributeName anlist_no_attrs[] = {
55 { BER_BVC( LDAP_NO_ATTRS ), NULL, 0, NULL },
56 { BER_BVNULL, NULL, 0, NULL }
59 static AttributeName *slap_anlist_no_attrs = anlist_no_attrs;
62 static AttributeDescription *ad_dgIdentity, *ad_dgAuthz;
64 typedef struct dynlist_map_t {
65 AttributeDescription *dlm_member_ad;
66 AttributeDescription *dlm_mapped_ad;
67 struct dynlist_map_t *dlm_next;
70 typedef struct dynlist_info_t {
72 AttributeDescription *dli_ad;
73 struct dynlist_map_t *dli_dlm;
74 struct berval dli_uri;
76 struct berval dli_uri_nbase;
77 Filter *dli_uri_filter;
78 struct berval dli_default_filter;
79 struct dynlist_info_t *dli_next;
82 #define DYNLIST_USAGE \
83 "\"dynlist-attrset <oc> [uri] <URL-ad> [[<mapped-ad>:]<member-ad> ...]\": "
85 static dynlist_info_t *
86 dynlist_is_dynlist_next( Operation *op, SlapReply *rs, dynlist_info_t *old_dli )
88 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
93 if ( old_dli == NULL ) {
94 dli = (dynlist_info_t *)on->on_bi.bi_private;
97 dli = old_dli->dli_next;
100 a = attrs_find( rs->sr_entry->e_attrs, slap_schema.si_ad_objectClass );
102 /* FIXME: objectClass must be present; for non-storage
103 * backends, like back-ldap, it needs to be added
104 * to the requested attributes */
108 for ( ; dli; dli = dli->dli_next ) {
109 if ( dli->dli_lud != NULL ) {
110 /* check base and scope */
111 if ( !BER_BVISNULL( &dli->dli_uri_nbase ) ) {
112 int d = rs->sr_entry->e_nname.bv_len - dli->dli_uri_nbase.bv_len;
118 if ( !dnIsSuffix( &rs->sr_entry->e_nname, &dli->dli_uri_nbase ) ) {
122 switch ( dli->dli_lud->lud_scope ) {
123 case LDAP_SCOPE_BASE:
129 case LDAP_SCOPE_ONELEVEL: {
132 dnParent( &rs->sr_entry->e_nname, &pdn );
133 if ( pdn.bv_len != dli->dli_uri_nbase.bv_len ) {
138 case LDAP_SCOPE_SUBORDINATE:
144 case LDAP_SCOPE_SUBTREE:
145 case LDAP_SCOPE_DEFAULT:
154 if ( dli->dli_uri_filter && test_filter( op, rs->sr_entry, dli->dli_uri_filter ) != LDAP_COMPARE_TRUE ) {
159 if ( attr_valfind( a,
160 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
161 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
162 &dli->dli_oc->soc_cname, NULL,
163 op->o_tmpmemctx ) == 0 )
173 dynlist_make_filter( Operation *op, struct berval *oldf, struct berval *newf )
175 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
176 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private;
180 assert( oldf != NULL );
181 assert( newf != NULL );
182 assert( !BER_BVISNULL( oldf ) );
183 assert( !BER_BVISEMPTY( oldf ) );
185 newf->bv_len = STRLENOF( "(&(!(objectClass=" "))" ")" )
186 + dli->dli_oc->soc_cname.bv_len + oldf->bv_len;
187 newf->bv_val = op->o_tmpalloc( newf->bv_len + 1, op->o_tmpmemctx );
188 if ( newf->bv_val == NULL ) {
191 ptr = lutil_strcopy( newf->bv_val, "(&(!(objectClass=" );
192 ptr = lutil_strcopy( ptr, dli->dli_oc->soc_cname.bv_val );
193 ptr = lutil_strcopy( ptr, "))" );
194 ptr = lutil_strcopy( ptr, oldf->bv_val );
195 ptr = lutil_strcopy( ptr, ")" );
196 newf->bv_len = ptr - newf->bv_val;
201 typedef struct dynlist_sc_t {
202 dynlist_info_t *dlc_dli;
207 dynlist_sc_update( Operation *op, SlapReply *rs )
213 AccessControlState acl_state = ACL_STATE_INIT;
218 if ( rs->sr_type != REP_SEARCH ) {
222 dlc = (dynlist_sc_t *)op->o_callback->sc_private;
226 assert( rs->sr_entry != NULL );
228 /* test access to entry */
229 if ( !access_allowed( op, rs->sr_entry, slap_schema.si_ad_entry,
230 NULL, ACL_READ, NULL ) )
235 /* if there is only one member_ad, and it's not mapped,
236 * consider it as old-style member listing */
237 dlm = dlc->dlc_dli->dli_dlm;
238 if ( dlm && dlm->dlm_mapped_ad == NULL && dlm->dlm_next == NULL ) {
239 /* if access allowed, try to add values, emulating permissive
240 * control to silently ignore duplicates */
241 if ( access_allowed( op, rs->sr_entry, slap_schema.si_ad_entry,
242 NULL, ACL_READ, NULL ) )
245 const char *text = NULL;
247 struct berval vals[ 2 ], nvals[ 2 ];
249 vals[ 0 ] = rs->sr_entry->e_name;
250 BER_BVZERO( &vals[ 1 ] );
251 nvals[ 0 ] = rs->sr_entry->e_nname;
252 BER_BVZERO( &nvals[ 1 ] );
254 mod.sm_op = LDAP_MOD_ADD;
255 mod.sm_desc = dlm->dlm_member_ad;
256 mod.sm_type = dlm->dlm_member_ad->ad_cname;
257 mod.sm_values = vals;
258 mod.sm_nvalues = nvals;
261 (void)modify_add_values( e, &mod, /* permissive */ 1,
262 &text, textbuf, sizeof( textbuf ) );
269 opattrs = ( rs->sr_attrs == NULL ) ? 0 : an_find( rs->sr_attrs, slap_bv_operational_attrs );
270 userattrs = ( rs->sr_attrs == NULL ) ? 1 : an_find( rs->sr_attrs, slap_bv_user_attrs );
271 #else /* SLAP_OPATTRS */
272 opattrs = SLAP_OPATTRS( rs->sr_attr_flags );
273 userattrs = SLAP_USERATTRS( rs->sr_attr_flags );
274 #endif /* SLAP_OPATTRS */
276 for ( a = rs->sr_entry->e_attrs; a != NULL; a = a->a_next ) {
277 BerVarray vals, nvals = NULL;
279 is_oc = a->a_desc == slap_schema.si_ad_objectClass;
281 /* if attribute is not requested, skip it */
282 if ( rs->sr_attrs == NULL ) {
283 if ( is_at_operational( a->a_desc->ad_type ) ) {
288 if ( is_at_operational( a->a_desc->ad_type ) ) {
289 if ( !opattrs && !ad_inlist( a->a_desc, rs->sr_attrs ) )
295 if ( !userattrs && !ad_inlist( a->a_desc, rs->sr_attrs ) )
302 /* test access to attribute */
303 if ( op->ors_attrsonly ) {
304 if ( !access_allowed( op, rs->sr_entry, a->a_desc, NULL,
305 ACL_READ, &acl_state ) )
311 /* single-value check: keep first only */
312 if ( is_at_single_value( a->a_desc->ad_type ) ) {
313 if ( attr_find( e->e_attrs, a->a_desc ) != NULL ) {
318 /* test access to attribute */
321 vals = op->o_tmpalloc( ( i + 1 ) * sizeof( struct berval ), op->o_tmpmemctx );
322 if ( a->a_nvals != a->a_vals ) {
323 nvals = op->o_tmpalloc( ( i + 1 ) * sizeof( struct berval ), op->o_tmpmemctx );
326 for ( i = 0, j = 0; !BER_BVISNULL( &a->a_vals[i] ); i++ ) {
328 ObjectClass *soc = oc_bvfind( &a->a_vals[i] );
330 if ( soc->soc_kind == LDAP_SCHEMA_STRUCTURAL ) {
335 if ( access_allowed( op, rs->sr_entry, a->a_desc,
336 &a->a_nvals[i], ACL_READ, &acl_state ) )
338 vals[j] = a->a_vals[i];
340 nvals[j] = a->a_nvals[i];
346 /* if access allowed, try to add values, emulating permissive
347 * control to silently ignore duplicates */
350 const char *text = NULL;
353 AttributeDescription *ad;
355 BER_BVZERO( &vals[j] );
357 BER_BVZERO( &nvals[j] );
361 for ( dlm = dlc->dlc_dli->dli_dlm; dlm; dlm = dlm->dlm_next ) {
362 if ( dlm->dlm_member_ad == a->a_desc ) {
363 if ( dlm->dlm_mapped_ad ) {
364 ad = dlm->dlm_mapped_ad;
370 mod.sm_op = LDAP_MOD_ADD;
372 mod.sm_type = ad->ad_cname;
373 mod.sm_values = vals;
374 mod.sm_nvalues = nvals;
377 (void)modify_add_values( e, &mod, /* permissive */ 1,
378 &text, textbuf, sizeof( textbuf ) );
381 op->o_tmpfree( vals, op->o_tmpmemctx );
383 op->o_tmpfree( nvals, op->o_tmpmemctx );
388 if ( rs->sr_flags & REP_ENTRY_MUSTBEFREED ) {
389 entry_free( rs->sr_entry );
391 rs->sr_flags ^= REP_ENTRY_MUSTBEFREED;
398 dynlist_prepare_entry( Operation *op, SlapReply *rs, dynlist_info_t *dli )
400 Attribute *a, *id = NULL;
403 SlapReply r = { REP_SEARCH };
409 dynlist_sc_t dlc = { 0 };
412 a = attrs_find( rs->sr_entry->e_attrs, dli->dli_ad );
415 return SLAP_CB_CONTINUE;
419 opattrs = ( rs->sr_attrs == NULL ) ? 0 : an_find( rs->sr_attrs, slap_bv_operational_attrs );
420 userattrs = ( rs->sr_attrs == NULL ) ? 1 : an_find( rs->sr_attrs, slap_bv_user_attrs );
421 #else /* SLAP_OPATTRS */
422 opattrs = SLAP_OPATTRS( rs->sr_attr_flags );
423 userattrs = SLAP_USERATTRS( rs->sr_attr_flags );
424 #endif /* SLAP_OPATTRS */
426 /* Don't generate member list if it wasn't requested */
427 for ( dlm = dli->dli_dlm; dlm; dlm = dlm->dlm_next ) {
428 AttributeDescription *ad = dlm->dlm_mapped_ad ? dlm->dlm_mapped_ad : dlm->dlm_member_ad;
429 if ( userattrs || ad_inlist( ad, rs->sr_attrs ) )
432 if ( dli->dli_dlm && !dlm )
433 return SLAP_CB_CONTINUE;
435 if ( ad_dgIdentity && ( id = attrs_find( rs->sr_entry->e_attrs, ad_dgIdentity ))) {
436 Attribute *authz = NULL;
438 /* if not rootdn and dgAuthz is present,
439 * check if user can be authorized as dgIdentity */
440 if ( ad_dgAuthz && !BER_BVISEMPTY( &id->a_nvals[0] ) && !be_isroot( op )
441 && ( authz = attrs_find( rs->sr_entry->e_attrs, ad_dgAuthz ) ) )
443 if ( slap_sasl_matches( op, authz->a_nvals,
444 &o.o_ndn, &o.o_ndn ) != LDAP_SUCCESS )
446 return SLAP_CB_CONTINUE;
450 o.o_dn = id->a_vals[0];
451 o.o_ndn = id->a_nvals[0];
455 e_flags = rs->sr_flags;
456 if ( !( rs->sr_flags & REP_ENTRY_MODIFIABLE ) ) {
457 e = entry_dup( rs->sr_entry );
458 e_flags |= ( REP_ENTRY_MODIFIABLE | REP_ENTRY_MUSTBEFREED );
465 cb.sc_private = &dlc;
466 cb.sc_response = dynlist_sc_update;
467 cb.sc_cleanup = NULL;
471 o.ors_deref = LDAP_DEREF_NEVER;
473 o.ors_tlimit = SLAP_NO_LIMIT;
474 o.ors_slimit = SLAP_NO_LIMIT;
476 for ( url = a->a_nvals; !BER_BVISNULL( url ); url++ ) {
477 LDAPURLDesc *lud = NULL;
482 BER_BVZERO( &o.o_req_dn );
483 BER_BVZERO( &o.o_req_ndn );
486 BER_BVZERO( &o.ors_filterstr );
488 if ( ldap_url_parse( url->bv_val, &lud ) != LDAP_URL_SUCCESS ) {
493 if ( lud->lud_host != NULL ) {
494 /* FIXME: host not allowed; reject as illegal? */
495 Debug( LDAP_DEBUG_ANY, "dynlist_prepare_entry(\"%s\"): "
496 "illegal URI \"%s\"\n",
497 e->e_name.bv_val, url->bv_val, 0 );
501 if ( lud->lud_dn == NULL ) {
502 /* note that an empty base is not honored in terms
503 * of defaultSearchBase, because select_backend()
504 * is not aware of the defaultSearchBase option;
505 * this can be useful in case of a database serving
506 * the empty suffix */
507 BER_BVSTR( &dn, "" );
510 ber_str2bv( lud->lud_dn, 0, 0, &dn );
512 rc = dnPrettyNormal( NULL, &dn, &o.o_req_dn, &o.o_req_ndn, op->o_tmpmemctx );
513 if ( rc != LDAP_SUCCESS ) {
517 o.ors_scope = lud->lud_scope;
519 for ( dlm = dli->dli_dlm; dlm; dlm = dlm->dlm_next ) {
520 if ( dlm->dlm_mapped_ad != NULL ) {
525 if ( dli->dli_dlm && !dlm ) {
526 /* if ( lud->lud_attrs != NULL ),
527 * the URL should be ignored */
528 o.ors_attrs = slap_anlist_no_attrs;
530 } else if ( lud->lud_attrs == NULL ) {
531 o.ors_attrs = rs->sr_attrs;
534 for ( i = 0; lud->lud_attrs[i]; i++)
537 o.ors_attrs = op->o_tmpcalloc( i + 1, sizeof( AttributeName ), op->o_tmpmemctx );
538 for ( i = 0, j = 0; lud->lud_attrs[i]; i++) {
539 const char *text = NULL;
541 ber_str2bv( lud->lud_attrs[i], 0, 0, &o.ors_attrs[j].an_name );
542 o.ors_attrs[j].an_desc = NULL;
543 (void)slap_bv2ad( &o.ors_attrs[j].an_name, &o.ors_attrs[j].an_desc, &text );
544 /* FIXME: ignore errors... */
546 if ( rs->sr_attrs == NULL ) {
547 if ( o.ors_attrs[j].an_desc != NULL &&
548 is_at_operational( o.ors_attrs[j].an_desc->ad_type ) )
554 if ( o.ors_attrs[j].an_desc != NULL &&
555 is_at_operational( o.ors_attrs[j].an_desc->ad_type ) )
561 if ( !ad_inlist( o.ors_attrs[j].an_desc, rs->sr_attrs ) ) {
562 /* lookup if mapped -- linear search,
563 * not very efficient unless list
565 for ( dlm = dli->dli_dlm; dlm; dlm = dlm->dlm_next ) {
566 if ( dlm->dlm_member_ad == o.ors_attrs[j].an_desc ) {
578 o.ors_attrs[j].an_desc != NULL &&
579 !ad_inlist( o.ors_attrs[j].an_desc, rs->sr_attrs ) )
581 /* lookup if mapped -- linear search,
582 * not very efficient unless list
584 for ( dlm = dli->dli_dlm; dlm; dlm = dlm->dlm_next ) {
585 if ( dlm->dlm_member_ad == o.ors_attrs[j].an_desc ) {
604 BER_BVZERO( &o.ors_attrs[j].an_name );
607 if ( lud->lud_filter == NULL ) {
608 ber_dupbv_x( &o.ors_filterstr,
609 &dli->dli_default_filter, op->o_tmpmemctx );
613 ber_str2bv( lud->lud_filter, 0, 0, &flt );
614 if ( dynlist_make_filter( op, &flt, &o.ors_filterstr ) ) {
619 o.ors_filter = str2filter_x( op, o.ors_filterstr.bv_val );
620 if ( o.ors_filter == NULL ) {
624 o.o_bd = select_backend( &o.o_req_ndn, 1 );
625 if ( o.o_bd && o.o_bd->be_search ) {
627 r.sr_attr_flags = slap_attr_flags( o.ors_attrs );
628 #endif /* SLAP_OPATTRS */
629 (void)o.o_bd->be_search( &o, &r );
634 slap_op_groups_free( &o );
636 if ( o.ors_filter ) {
637 filter_free_x( &o, o.ors_filter, 1 );
639 if ( o.ors_attrs && o.ors_attrs != rs->sr_attrs
640 && o.ors_attrs != slap_anlist_no_attrs )
642 op->o_tmpfree( o.ors_attrs, op->o_tmpmemctx );
644 if ( !BER_BVISNULL( &o.o_req_dn ) ) {
645 op->o_tmpfree( o.o_req_dn.bv_val, op->o_tmpmemctx );
647 if ( !BER_BVISNULL( &o.o_req_ndn ) ) {
648 op->o_tmpfree( o.o_req_ndn.bv_val, op->o_tmpmemctx );
650 assert( BER_BVISNULL( &o.ors_filterstr )
651 || o.ors_filterstr.bv_val != lud->lud_filter );
652 op->o_tmpfree( o.ors_filterstr.bv_val, op->o_tmpmemctx );
653 ldap_free_urldesc( lud );
657 rs->sr_flags = e_flags;
659 return SLAP_CB_CONTINUE;
663 dynlist_sc_save_entry( Operation *op, SlapReply *rs )
665 /* save the entry in the private field of the callback,
666 * so it doesn't get freed (it's temporary!) */
667 if ( rs->sr_entry != NULL ) {
668 dynlist_sc_t *dlc = (dynlist_sc_t *)op->o_callback->sc_private;
669 dlc->dlc_e = rs->sr_entry;
677 dynlist_compare( Operation *op, SlapReply *rs )
679 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
680 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private;
685 for ( ; dli != NULL; dli = dli->dli_next ) {
686 for ( dlm = dli->dli_dlm; dlm; dlm = dlm->dlm_next )
687 if ( op->oq_compare.rs_ava->aa_desc == dlm->dlm_member_ad )
690 if ( dli->dli_dlm && dlm ) {
691 /* This compare is for one of the attributes we're
692 * interested in. We'll use slapd's existing dyngroup
693 * evaluator to get the answer we want.
695 BerVarray id = NULL, authz = NULL;
697 o.o_do_not_cache = 1;
699 if ( ad_dgIdentity && backend_attribute( &o, NULL, &o.o_req_ndn,
700 ad_dgIdentity, &id, ACL_READ ) == LDAP_SUCCESS )
702 /* if not rootdn and dgAuthz is present,
703 * check if user can be authorized as dgIdentity */
704 if ( ad_dgAuthz && !BER_BVISEMPTY( id ) && !be_isroot( op )
705 && backend_attribute( &o, NULL, &o.o_req_ndn,
706 ad_dgAuthz, &authz, ACL_READ ) == LDAP_SUCCESS )
709 rs->sr_err = slap_sasl_matches( op, authz,
710 &o.o_ndn, &o.o_ndn );
711 ber_bvarray_free_x( authz, op->o_tmpmemctx );
712 if ( rs->sr_err != LDAP_SUCCESS ) {
719 o.o_groups = NULL; /* authz changed, invalidate cached groups */
722 rs->sr_err = backend_group( &o, NULL, &o.o_req_ndn,
723 &o.oq_compare.rs_ava->aa_value, dli->dli_oc, dli->dli_ad );
724 switch ( rs->sr_err ) {
726 rs->sr_err = LDAP_COMPARE_TRUE;
729 case LDAP_NO_SUCH_OBJECT:
730 /* NOTE: backend_group() returns noSuchObject
731 * if op_ndn does not exist; however, since
732 * dynamic list expansion means that the
733 * member attribute is virtually present, the
734 * non-existence of the asserted value implies
735 * the assertion is FALSE rather than
737 rs->sr_err = LDAP_COMPARE_FALSE;
742 if ( id ) ber_bvarray_free_x( id, o.o_tmpmemctx );
744 return SLAP_CB_CONTINUE;
748 if ( overlay_entry_get_ov( &o, &o.o_req_ndn, NULL, NULL, 0, &e, on ) !=
749 LDAP_SUCCESS || e == NULL )
751 return SLAP_CB_CONTINUE;
754 if ( ad_dgIdentity ) {
755 Attribute *id = attrs_find( e->e_attrs, ad_dgIdentity );
759 /* if not rootdn and dgAuthz is present,
760 * check if user can be authorized as dgIdentity */
761 if ( ad_dgAuthz && !BER_BVISEMPTY( &id->a_nvals[0] ) && !be_isroot( op )
762 && ( authz = attrs_find( e->e_attrs, ad_dgAuthz ) ) )
764 if ( slap_sasl_matches( op, authz->a_nvals,
765 &o.o_ndn, &o.o_ndn ) != LDAP_SUCCESS )
771 o.o_dn = id->a_vals[0];
772 o.o_ndn = id->a_nvals[0];
777 dli = (dynlist_info_t *)on->on_bi.bi_private;
778 for ( ; dli != NULL && rs->sr_err != LDAP_COMPARE_TRUE; dli = dli->dli_next ) {
781 SlapReply r = { REP_SEARCH };
784 dynlist_sc_t dlc = { 0 };
786 if ( !is_entry_objectclass_or_sub( e, dli->dli_oc ))
789 /* if the entry has the right objectClass, generate
790 * the dynamic list and compare */
792 cb.sc_private = &dlc;
793 cb.sc_response = dynlist_sc_save_entry;
794 cb.sc_cleanup = NULL;
798 o.o_tag = LDAP_REQ_SEARCH;
800 o.ors_tlimit = SLAP_NO_LIMIT;
801 o.ors_slimit = SLAP_NO_LIMIT;
803 o.o_bd = select_backend( &o.o_req_ndn, 1 );
804 if ( !o.o_bd || !o.o_bd->be_search ) {
808 o.ors_filterstr = *slap_filterstr_objectClass_pres;
809 o.ors_filter = (Filter *) slap_filter_objectClass_pres;
811 o.ors_scope = LDAP_SCOPE_BASE;
812 o.ors_deref = LDAP_DEREF_NEVER;
813 an[0].an_name = op->orc_ava->aa_desc->ad_cname;
814 an[0].an_desc = op->orc_ava->aa_desc;
815 BER_BVZERO( &an[1].an_name );
819 o.o_acl_priv = ACL_COMPARE;
821 rc = o.o_bd->be_search( &o, &r );
823 if ( o.o_dn.bv_val != op->o_dn.bv_val ) {
824 slap_op_groups_free( &o );
831 if ( dlc.dlc_e != NULL ) {
832 r.sr_entry = dlc.dlc_e;
835 if ( r.sr_err != LDAP_SUCCESS || r.sr_entry == NULL ) {
840 for ( a = attrs_find( r.sr_entry->e_attrs, op->orc_ava->aa_desc );
842 a = attrs_find( a->a_next, op->orc_ava->aa_desc ) )
844 /* if we're here, we got a match... */
845 rs->sr_err = LDAP_COMPARE_FALSE;
847 if ( attr_valfind( a,
848 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
849 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
850 &op->orc_ava->aa_value, NULL, op->o_tmpmemctx ) == 0 )
852 rs->sr_err = LDAP_COMPARE_TRUE;
857 if ( r.sr_flags & REP_ENTRY_MUSTBEFREED ) {
858 entry_free( r.sr_entry );
860 r.sr_flags ^= REP_ENTRY_MUSTBEFREED;
866 overlay_entry_release_ov( op, e, 0, on );
869 return SLAP_CB_CONTINUE;
873 dynlist_response( Operation *op, SlapReply *rs )
877 switch ( op->o_tag ) {
878 case LDAP_REQ_SEARCH:
879 if ( rs->sr_type == REP_SEARCH && !get_manageDSAit( op ) )
883 for ( dli = dynlist_is_dynlist_next( op, rs, NULL );
885 dli = dynlist_is_dynlist_next( op, rs, dli ) )
887 rc = dynlist_prepare_entry( op, rs, dli );
890 if ( rc != LDAP_OTHER ) {
896 case LDAP_REQ_COMPARE:
897 switch ( rs->sr_err ) {
898 /* NOTE: we waste a few cycles running the dynamic list
899 * also when the result is FALSE, which occurs if the
900 * dynamic entry itself contains the AVA attribute */
901 /* FIXME: this approach is less than optimal; a dedicated
902 * compare op should be implemented, that fetches the
903 * entry, checks if it has the appropriate objectClass
904 * and, in case, runs a compare thru all the URIs,
905 * stopping at the first positive occurrence; see ITS#3756 */
906 case LDAP_COMPARE_FALSE:
907 case LDAP_NO_SUCH_ATTRIBUTE:
908 return dynlist_compare( op, rs );
916 return SLAP_CB_CONTINUE;
920 dynlist_build_def_filter( dynlist_info_t *dli )
924 dli->dli_default_filter.bv_len = STRLENOF( "(!(objectClass=" "))" )
925 + dli->dli_oc->soc_cname.bv_len;
926 dli->dli_default_filter.bv_val = ch_malloc( dli->dli_default_filter.bv_len + 1 );
927 if ( dli->dli_default_filter.bv_val == NULL ) {
928 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: malloc failed.\n",
933 ptr = lutil_strcopy( dli->dli_default_filter.bv_val, "(!(objectClass=" );
934 ptr = lutil_strcopy( ptr, dli->dli_oc->soc_cname.bv_val );
935 ptr = lutil_strcopy( ptr, "))" );
937 assert( ptr == &dli->dli_default_filter.bv_val[dli->dli_default_filter.bv_len] );
951 slap_overinst *on = (slap_overinst *)be->bd_info;
955 if ( strcasecmp( argv[0], "dynlist-attrset" ) == 0 ) {
956 dynlist_info_t **dlip;
958 AttributeDescription *ad = NULL,
960 dynlist_map_t *dlm = NULL;
964 Debug( LDAP_DEBUG_ANY, "%s: line %d: " DYNLIST_USAGE
965 "invalid arg number #%d.\n",
966 fname, lineno, argc );
970 oc = oc_find( argv[1] );
972 Debug( LDAP_DEBUG_ANY, "%s: line %d: " DYNLIST_USAGE
973 "unable to find ObjectClass \"%s\"\n",
974 fname, lineno, argv[ 1 ] );
978 rc = slap_str2ad( argv[2], &ad, &text );
979 if ( rc != LDAP_SUCCESS ) {
980 Debug( LDAP_DEBUG_ANY, "%s: line %d: " DYNLIST_USAGE
981 "unable to find AttributeDescription \"%s\"\n",
982 fname, lineno, argv[2] );
986 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
987 Debug( LDAP_DEBUG_ANY, "%s: line %d: " DYNLIST_USAGE
988 "AttributeDescription \"%s\" "
989 "must be a subtype of \"labeledURI\"\n",
990 fname, lineno, argv[2] );
994 for ( i = 3; i < argc; i++ ) {
997 AttributeDescription *member_ad = NULL;
998 AttributeDescription *mapped_ad = NULL;
1000 dynlist_map_t *dlml;
1004 * If no mapped attribute is given, dn is used
1005 * for backward compatibility.
1008 if ( cp = strchr( arg, (int)':' ) != NULL ) {
1010 ber_str2bv( arg, cp - arg, 0, &bv );
1011 rc = slap_bv2ad( &bv, &mapped_ad, &text );
1012 if ( rc != LDAP_SUCCESS ) {
1013 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1015 "unable to find mapped AttributeDescription \"%s\"\n",
1016 fname, lineno, arg );
1023 rc = slap_str2ad( arg, &member_ad, &text );
1024 if ( rc != LDAP_SUCCESS ) {
1025 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1027 "unable to find AttributeDescription \"%s\"\n",
1028 fname, lineno, arg );
1032 dlmp = (dynlist_map_t *)ch_calloc( 1, sizeof( dynlist_map_t ) );
1033 if ( dlm == NULL ) {
1037 dlmp->dlm_member_ad = member_ad;
1038 dlmp->dlm_mapped_ad = mapped_ad;
1039 dlmp->dlm_next = NULL;
1042 dlml->dlm_next = dlmp;
1046 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1047 *dlip; dlip = &(*dlip)->dli_next )
1050 * The same URL attribute / member attribute pair
1051 * cannot be repeated, but we enforce this only
1052 * when the member attribute is unique. Performing
1053 * the check for multiple values would require
1054 * sorting and comparing the lists, which is left
1055 * as a future improvement
1057 if ( (*dlip)->dli_ad == ad &&
1058 (*dlip)->dli_dlm->dlm_next == NULL &&
1059 dlm->dlm_next == NULL &&
1060 dlm->dlm_member_ad == (*dlip)->dli_dlm->dlm_member_ad &&
1061 dlm->dlm_mapped_ad == (*dlip)->dli_dlm->dlm_mapped_ad ) {
1062 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1064 "URL attributeDescription \"%s\" already mapped.\n",
1065 fname, lineno, ad->ad_cname.bv_val );
1067 /* make it a warning... */
1073 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
1074 (*dlip)->dli_oc = oc;
1075 (*dlip)->dli_ad = ad;
1076 (*dlip)->dli_dlm = dlm;
1078 if ( dynlist_build_def_filter( *dlip ) ) {
1079 dynlist_map_t *dlm = (*dlip)->ldi_dlm;
1080 dynlist_map_t *dlm_next;
1082 while ( dlm != NULL ) {
1083 dlm_next = dlm->dlm_next;
1093 /* allow dyngroup syntax */
1094 } else if ( strcasecmp( argv[0], "dynlist-attrpair" ) == 0 ) {
1095 dynlist_info_t **dlip;
1097 AttributeDescription *ad = NULL,
1102 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1103 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1104 "invalid arg number #%d.\n",
1105 fname, lineno, argc );
1109 oc = oc_find( "groupOfURLs" );
1111 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1112 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1113 "unable to find default ObjectClass \"groupOfURLs\"\n",
1118 rc = slap_str2ad( argv[1], &member_ad, &text );
1119 if ( rc != LDAP_SUCCESS ) {
1120 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1121 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1122 "unable to find AttributeDescription \"%s\"\n",
1123 fname, lineno, argv[1] );
1127 rc = slap_str2ad( argv[2], &ad, &text );
1128 if ( rc != LDAP_SUCCESS ) {
1129 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1130 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1131 "unable to find AttributeDescription \"%s\"\n",
1132 fname, lineno, argv[2] );
1136 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
1137 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1138 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1139 "AttributeDescription \"%s\" "
1140 "must be a subtype of \"labeledURI\"\n",
1141 fname, lineno, argv[2] );
1145 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1146 *dlip; dlip = &(*dlip)->dli_next )
1149 * The same URL attribute / member attribute pair
1150 * cannot be repeated, but we enforce this only
1151 * when the member attribute is unique. Performing
1152 * the check for multiple values would require
1153 * sorting and comparing the lists, which is left
1154 * as a future improvement
1156 if ( (*dlip)->dli_ad == ad &&
1157 (*dlip)->dli_dlm->dlm_next == NULL &&
1158 member_ad == (*dlip)->dli_dlm->dlm_member_ad ) {
1159 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1160 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1161 "URL attributeDescription \"%s\" already mapped.\n",
1162 fname, lineno, ad->ad_cname.bv_val );
1164 /* make it a warning... */
1170 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
1171 (*dlip)->dli_oc = oc;
1172 (*dlip)->dli_ad = ad;
1173 (*dlip)->dli_dlm = (dynlist_map_t *)ch_calloc( 1, sizeof( dynlist_map_t ) );
1174 (*dlip)->dli_dlm->dlm_member_ad = member_ad;
1175 (*dlip)->dli_dlm->dlm_mapped_ad = NULL;
1177 if ( dynlist_build_def_filter( *dlip ) ) {
1178 ch_free( (*dlip)->dli_dlm );
1185 rc = SLAP_CONF_UNKNOWN;
1199 static ConfigDriver dl_cfgen;
1201 /* XXXmanu 255 is the maximum arguments we allow. Can we go beyond? */
1202 static ConfigTable dlcfg[] = {
1203 { "dynlist-attrset", "group-oc> [uri] <URL-ad> <[mapped:]member-ad> [...]",
1204 3, 0, 0, ARG_MAGIC|DL_ATTRSET, dl_cfgen,
1205 "( OLcfgOvAt:8.1 NAME 'olcDlAttrSet' "
1206 "DESC 'Dynamic list: <group objectClass>, <URL attributeDescription>, <member attributeDescription>' "
1207 "EQUALITY caseIgnoreMatch "
1208 "SYNTAX OMsDirectoryString "
1209 "X-ORDERED 'VALUES' )",
1211 { "dynlist-attrpair", "member-ad> <URL-ad",
1212 3, 3, 0, ARG_MAGIC|DL_ATTRPAIR, dl_cfgen,
1214 #ifdef TAKEOVER_DYNGROUP
1215 { "attrpair", "member-ad> <URL-ad",
1216 3, 3, 0, ARG_MAGIC|DL_ATTRPAIR_COMPAT, dl_cfgen,
1219 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
1222 static ConfigOCs dlocs[] = {
1223 { "( OLcfgOvOc:8.1 "
1224 "NAME 'olcDynamicList' "
1225 "DESC 'Dynamic list configuration' "
1226 "SUP olcOverlayConfig "
1227 "MAY olcDLattrSet )",
1228 Cft_Overlay, dlcfg, NULL, NULL },
1233 dl_cfgen( ConfigArgs *c )
1235 slap_overinst *on = (slap_overinst *)c->bi;
1236 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private;
1240 if ( c->op == SLAP_CONFIG_EMIT ) {
1243 for ( i = 0; dli; i++, dli = dli->dli_next ) {
1245 char *ptr = c->cr_msg;
1248 assert( dli->dli_oc != NULL );
1249 assert( dli->dli_ad != NULL );
1251 /* FIXME: check buffer overflow! */
1252 ptr += snprintf( c->cr_msg, sizeof( c->cr_msg ),
1253 SLAP_X_ORDERED_FMT "%s", i,
1254 dli->dli_oc->soc_cname.bv_val );
1256 if ( !BER_BVISNULL( &dli->dli_uri ) ) {
1259 ptr = lutil_strncopy( ptr, dli->dli_uri.bv_val,
1260 dli->dli_uri.bv_len );
1265 ptr = lutil_strncopy( ptr, dli->dli_oc->soc_cname.bv_val,
1266 dli->dli_oc->soc_cname.bv_len );
1268 for ( dlm = dli->dli_dlm; dlm; dlm = dlm->dlm_next ) {
1271 if ( dlm->dlm_mapped_ad ) {
1272 ptr = lutil_strcopy( ptr, dlm->dlm_mapped_ad->ad_cname.bv_val );
1277 ptr = lutil_strcopy( ptr, dlm->dlm_member_ad->ad_cname.bv_val );
1280 bv.bv_val = c->cr_msg;
1281 bv.bv_len = ptr - bv.bv_val;
1282 value_add_one( &c->rvalue_vals, &bv );
1286 case DL_ATTRPAIR_COMPAT:
1298 } else if ( c->op == LDAP_MOD_DELETE ) {
1301 if ( c->valx < 0 ) {
1302 dynlist_info_t *dli_next;
1304 for ( dli_next = dli; dli_next; dli = dli_next ) {
1305 dynlist_map_t *dlm = dli->dli_dlm;
1306 dynlist_map_t *dlm_next;
1308 dli_next = dli->dli_next;
1310 if ( !BER_BVISNULL( &dli->dli_uri ) ) {
1311 ch_free( dli->dli_uri.bv_val );
1314 if ( dli->dli_lud != NULL ) {
1315 ldap_free_urldesc( dli->dli_lud );
1318 if ( !BER_BVISNULL( &dli->dli_uri_nbase ) ) {
1319 ber_memfree( dli->dli_uri_nbase.bv_val );
1322 if ( dli->dli_uri_filter != NULL ) {
1323 filter_free( dli->dli_uri_filter );
1326 ch_free( dli->dli_default_filter.bv_val );
1328 while ( dlm != NULL ) {
1329 dlm_next = dlm->dlm_next;
1336 on->on_bi.bi_private = NULL;
1339 dynlist_info_t **dlip;
1341 dynlist_map_t *dlm_next;
1343 for ( i = 0, dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1346 if ( *dlip == NULL ) {
1349 dlip = &(*dlip)->dli_next;
1353 *dlip = dli->dli_next;
1355 if ( !BER_BVISNULL( &dli->dli_uri ) ) {
1356 ch_free( dli->dli_uri.bv_val );
1359 if ( dli->dli_lud != NULL ) {
1360 ldap_free_urldesc( dli->dli_lud );
1363 if ( !BER_BVISNULL( &dli->dli_uri_nbase ) ) {
1364 ber_memfree( dli->dli_uri_nbase.bv_val );
1367 if ( dli->dli_uri_filter != NULL ) {
1368 filter_free( dli->dli_uri_filter );
1371 ch_free( dli->dli_default_filter.bv_val );
1374 while ( dlm != NULL ) {
1375 dlm_next = dlm->dlm_next;
1381 dli = (dynlist_info_t *)on->on_bi.bi_private;
1385 case DL_ATTRPAIR_COMPAT:
1400 dynlist_info_t **dlip,
1402 ObjectClass *oc = NULL;
1403 AttributeDescription *ad = NULL;
1405 LDAPURLDesc *lud = NULL;
1406 struct berval nbase = BER_BVNULL;
1407 Filter *filter = NULL;
1408 struct berval uri = BER_BVNULL;
1409 dynlist_map_t *dlm = NULL;
1412 oc = oc_find( c->argv[ 1 ] );
1414 snprintf( c->cr_msg, sizeof( c->cr_msg ), DYNLIST_USAGE
1415 "unable to find ObjectClass \"%s\"",
1417 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1418 c->log, c->cr_msg, 0 );
1422 if ( strncasecmp( c->argv[ attridx ], "ldap://", STRLENOF("ldap://") ) == 0 ) {
1423 if ( ldap_url_parse( c->argv[ attridx ], &lud ) != LDAP_URL_SUCCESS ) {
1424 snprintf( c->cr_msg, sizeof( c->cr_msg ), DYNLIST_USAGE
1425 "unable to parse URI \"%s\"",
1426 c->argv[ attridx ] );
1431 if ( lud->lud_host != NULL ) {
1432 if ( lud->lud_host[0] == '\0' ) {
1433 ch_free( lud->lud_host );
1434 lud->lud_host = NULL;
1437 snprintf( c->cr_msg, sizeof( c->cr_msg ), DYNLIST_USAGE
1438 "host not allowed in URI \"%s\"",
1439 c->argv[ attridx ] );
1445 if ( lud->lud_attrs != NULL ) {
1446 snprintf( c->cr_msg, sizeof( c->cr_msg ), DYNLIST_USAGE
1447 "attrs not allowed in URI \"%s\"",
1448 c->argv[ attridx ] );
1453 if ( lud->lud_exts != NULL ) {
1454 snprintf( c->cr_msg, sizeof( c->cr_msg ), DYNLIST_USAGE
1455 "extensions not allowed in URI \"%s\"",
1456 c->argv[ attridx ] );
1461 if ( lud->lud_dn != NULL && lud->lud_dn[ 0 ] != '\0' ) {
1463 ber_str2bv( lud->lud_dn, 0, 0, &dn );
1464 rc = dnNormalize( 0, NULL, NULL, &dn, &nbase, NULL );
1465 if ( rc != LDAP_SUCCESS ) {
1466 snprintf( c->cr_msg, sizeof( c->cr_msg ), DYNLIST_USAGE
1467 "DN normalization failed in URI \"%s\"",
1468 c->argv[ attridx ] );
1473 if ( lud->lud_filter != NULL && lud->lud_filter[ 0 ] != '\0' ) {
1474 filter = str2filter( lud->lud_filter );
1475 if ( filter == NULL ) {
1476 snprintf( c->cr_msg, sizeof( c->cr_msg ), DYNLIST_USAGE
1477 "filter parsing failed in URI \"%s\"",
1478 c->argv[ attridx ] );
1484 ber_str2bv( c->argv[ attridx ], 0, 1, &uri );
1489 ldap_free_urldesc( lud );
1492 if ( !BER_BVISNULL( &nbase ) ) {
1493 ber_memfree( nbase.bv_val );
1496 if ( filter != NULL ) {
1497 filter_free( filter );
1500 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1501 c->log, c->cr_msg, 0 );
1509 rc = slap_str2ad( c->argv[ attridx ], &ad, &text );
1510 if ( rc != LDAP_SUCCESS ) {
1511 snprintf( c->cr_msg, sizeof( c->cr_msg ), DYNLIST_USAGE
1512 "unable to find AttributeDescription \"%s\"",
1513 c->argv[ attridx ] );
1514 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1515 c->log, c->cr_msg, 0 );
1519 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
1520 snprintf( c->cr_msg, sizeof( c->cr_msg ), DYNLIST_USAGE
1521 "AttributeDescription \"%s\" "
1522 "must be a subtype of \"labeledURI\"",
1523 c->argv[ attridx ] );
1524 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1525 c->log, c->cr_msg, 0 );
1531 for ( i = attridx; i < c->argc; i++ ) {
1534 AttributeDescription *member_ad = NULL;
1535 AttributeDescription *mapped_ad = NULL;
1536 dynlist_map_t *dlmp;
1537 dynlist_map_t *dlml;
1541 * If no mapped attribute is given, dn is used
1542 * for backward compatibility.
1545 if ( ( cp = strchr( arg, ':' ) ) != NULL ) {
1547 ber_str2bv( arg, cp - arg, 0, &bv );
1548 rc = slap_bv2ad( &bv, &mapped_ad, &text );
1549 if ( rc != LDAP_SUCCESS ) {
1550 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1552 "unable to find mapped AttributeDescription #%d \"%s\"\n",
1553 i - 3, c->argv[ i ] );
1554 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1555 c->log, c->cr_msg, 0 );
1561 rc = slap_str2ad( arg, &member_ad, &text );
1562 if ( rc != LDAP_SUCCESS ) {
1563 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1565 "unable to find AttributeDescription #%d \"%s\"\n",
1566 i - 3, c->argv[ i ] );
1567 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1568 c->log, c->cr_msg, 0 );
1572 dlmp = (dynlist_map_t *)ch_calloc( 1, sizeof( dynlist_map_t ) );
1573 if ( dlm == NULL ) {
1577 dlmp->dlm_member_ad = member_ad;
1578 dlmp->dlm_mapped_ad = mapped_ad;
1579 dlmp->dlm_next = NULL;
1582 dlml->dlm_next = dlmp;
1586 if ( c->valx > 0 ) {
1589 for ( i = 0, dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1592 if ( *dlip == NULL ) {
1593 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1595 "invalid index {%d}\n",
1597 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1598 c->log, c->cr_msg, 0 );
1601 dlip = &(*dlip)->dli_next;
1606 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1607 *dlip; dlip = &(*dlip)->dli_next )
1611 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
1613 (*dlip)->dli_oc = oc;
1614 (*dlip)->dli_ad = ad;
1615 (*dlip)->dli_dlm = dlm;
1616 (*dlip)->dli_next = dli_next;
1618 (*dlip)->dli_lud = lud;
1619 (*dlip)->dli_uri_nbase = nbase;
1620 (*dlip)->dli_uri_filter = filter;
1621 (*dlip)->dli_uri = uri;
1623 rc = dynlist_build_def_filter( *dlip );
1627 case DL_ATTRPAIR_COMPAT:
1628 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1629 "warning: \"attrpair\" only supported for limited "
1630 "backward compatibility with overlay \"dyngroup\"" );
1631 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
1635 dynlist_info_t **dlip;
1636 ObjectClass *oc = NULL;
1637 AttributeDescription *ad = NULL,
1641 oc = oc_find( "groupOfURLs" );
1643 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1644 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1645 "unable to find default ObjectClass \"groupOfURLs\"" );
1646 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1647 c->log, c->cr_msg, 0 );
1651 rc = slap_str2ad( c->argv[ 1 ], &member_ad, &text );
1652 if ( rc != LDAP_SUCCESS ) {
1653 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1654 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1655 "unable to find AttributeDescription \"%s\"",
1657 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1658 c->log, c->cr_msg, 0 );
1662 rc = slap_str2ad( c->argv[ 2 ], &ad, &text );
1663 if ( rc != LDAP_SUCCESS ) {
1664 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1665 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1666 "unable to find AttributeDescription \"%s\"\n",
1668 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1669 c->log, c->cr_msg, 0 );
1673 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
1674 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1676 "AttributeDescription \"%s\" "
1677 "must be a subtype of \"labeledURI\"",
1679 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1680 c->log, c->cr_msg, 0 );
1684 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1685 *dlip; dlip = &(*dlip)->dli_next )
1688 * The same URL attribute / member attribute pair
1689 * cannot be repeated, but we enforce this only
1690 * when the member attribute is unique. Performing
1691 * the check for multiple values would require
1692 * sorting and comparing the lists, which is left
1693 * as a future improvement
1695 if ( (*dlip)->dli_ad == ad &&
1696 (*dlip)->dli_dlm->dlm_next == NULL &&
1697 member_ad == (*dlip)->dli_dlm->dlm_member_ad ) {
1698 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1699 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1700 "URL attributeDescription \"%s\" already mapped.\n",
1701 ad->ad_cname.bv_val );
1702 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1703 c->log, c->cr_msg, 0 );
1705 /* make it a warning... */
1711 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
1713 (*dlip)->dli_oc = oc;
1714 (*dlip)->dli_ad = ad;
1715 (*dlip)->dli_dlm = (dynlist_map_t *)ch_calloc( 1, sizeof( dynlist_map_t ) );
1716 (*dlip)->dli_dlm->dlm_member_ad = member_ad;
1717 (*dlip)->dli_dlm->dlm_mapped_ad = NULL;
1719 rc = dynlist_build_def_filter( *dlip );
1737 slap_overinst *on = (slap_overinst *) be->bd_info;
1738 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private;
1739 ObjectClass *oc = NULL;
1740 AttributeDescription *ad = NULL;
1744 if ( dli == NULL ) {
1745 dli = ch_calloc( 1, sizeof( dynlist_info_t ) );
1746 on->on_bi.bi_private = (void *)dli;
1749 for ( ; dli; dli = dli->dli_next ) {
1750 if ( dli->dli_oc == NULL ) {
1752 oc = oc_find( "groupOfURLs" );
1754 snprintf( cr->msg, sizeof( cr->msg),
1755 "unable to fetch objectClass \"groupOfURLs\"" );
1756 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: %s.\n", cr->msg, 0, 0 );
1764 if ( dli->dli_ad == NULL ) {
1766 rc = slap_str2ad( "memberURL", &ad, &text );
1767 if ( rc != LDAP_SUCCESS ) {
1768 snprintf( cr->msg, sizeof( cr->msg),
1769 "unable to fetch attributeDescription \"memberURL\": %d (%s)",
1771 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: %s.\n", cr->msg, 0, 0 );
1779 if ( BER_BVISNULL( &dli->dli_default_filter ) ) {
1780 rc = dynlist_build_def_filter( dli );
1787 if ( ad_dgIdentity == NULL ) {
1788 rc = slap_str2ad( "dgIdentity", &ad_dgIdentity, &text );
1789 if ( rc != LDAP_SUCCESS ) {
1790 snprintf( cr->msg, sizeof( cr->msg),
1791 "unable to fetch attributeDescription \"dgIdentity\": %d (%s)",
1793 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: %s\n", cr->msg, 0, 0 );
1794 /* Just a warning */
1798 if ( ad_dgAuthz == NULL ) {
1799 rc = slap_str2ad( "dgAuthz", &ad_dgAuthz, &text );
1800 if ( rc != LDAP_SUCCESS ) {
1801 snprintf( cr->msg, sizeof( cr->msg),
1802 "unable to fetch attributeDescription \"dgAuthz\": %d (%s)",
1804 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: %s\n", cr->msg, 0, 0 );
1805 /* Just a warning */
1817 slap_overinst *on = (slap_overinst *) be->bd_info;
1819 if ( on->on_bi.bi_private ) {
1820 dynlist_info_t *dli = (dynlist_info_t *)on->on_bi.bi_private,
1823 for ( dli_next = dli; dli_next; dli = dli_next ) {
1825 dynlist_map_t *dlm_next;
1827 dli_next = dli->dli_next;
1829 if ( !BER_BVISNULL( &dli->dli_uri ) ) {
1830 ch_free( dli->dli_uri.bv_val );
1833 if ( dli->dli_lud != NULL ) {
1834 ldap_free_urldesc( dli->dli_lud );
1837 if ( !BER_BVISNULL( &dli->dli_uri_nbase ) ) {
1838 ber_memfree( dli->dli_uri_nbase.bv_val );
1841 if ( dli->dli_uri_filter != NULL ) {
1842 filter_free( dli->dli_uri_filter );
1845 ch_free( dli->dli_default_filter.bv_val );
1848 while ( dlm != NULL ) {
1849 dlm_next = dlm->dlm_next;
1860 static slap_overinst dynlist = { { NULL } };
1861 #ifdef TAKEOVER_DYNGROUP
1862 static char *obsolete_names[] = {
1868 #if SLAPD_OVER_DYNLIST == SLAPD_MOD_DYNAMIC
1870 #endif /* SLAPD_OVER_DYNLIST == SLAPD_MOD_DYNAMIC */
1872 dynlist_initialize(void)
1874 #ifndef OL_2_2_COMPAT
1878 dynlist.on_bi.bi_type = "dynlist";
1880 #ifdef TAKEOVER_DYNGROUP
1881 /* makes dynlist incompatible with dyngroup */
1882 dynlist.on_bi.bi_obsolete_names = obsolete_names;
1885 #ifdef OL_2_2_COMPAT
1886 dynlist.on_bi.bi_db_config = dynlist_db_config;
1888 dynlist.on_bi.bi_db_config = config_generic_wrapper;
1890 dynlist.on_bi.bi_db_open = dynlist_db_open;
1891 dynlist.on_bi.bi_db_destroy = dynlist_db_destroy;
1893 dynlist.on_response = dynlist_response;
1895 #ifndef OL_2_2_COMPAT
1896 dynlist.on_bi.bi_cf_ocs = dlocs;
1898 rc = config_register_schema( dlcfg, dlocs );
1904 return overlay_register( &dynlist );
1907 #if SLAPD_OVER_DYNLIST == SLAPD_MOD_DYNAMIC
1909 init_module( int argc, char *argv[] )
1911 return dynlist_initialize();
1915 #endif /* SLAPD_OVER_DYNLIST */