]> git.sur5r.net Git - openldap/blob - servers/slapd/overlays/dynlist.c
complete merging of dyngroup into dynlist; add back-config support
[openldap] / servers / slapd / overlays / dynlist.c
1 /* dynlist.c - dynamic list overlay */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3  *
4  * Copyright 2003-2005 The OpenLDAP Foundation.
5  * Portions Copyright 2004-2005 Pierangelo Masarati.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
12  * A copy of this license is available in the file LICENSE in the
13  * top-level directory of the distribution or, alternatively, at
14  * <http://www.OpenLDAP.org/license.html>.
15  */
16 /* ACKNOWLEDGEMENTS:
17  * This work was initially developed by Pierangelo Masarati
18  * for SysNet s.n.c., for inclusion in OpenLDAP Software.
19  */
20
21 #include "portable.h"
22
23 #ifdef SLAPD_OVER_DYNLIST
24
25 #if LDAP_VENDOR_VERSION_MINOR != X && LDAP_VENDOR_VERSION_MINOR < 3
26 #define OL_2_2_COMPAT
27 #endif
28
29 #include <stdio.h>
30
31 #include <ac/string.h>
32
33 #include "slap.h"
34 #ifndef OL_2_2_COMPAT
35 #include "config.h"
36 #endif
37 #include "lutil.h"
38
39 /* FIXME: the code differs if SLAP_OPATTRS is defined or not;
40  * SLAP_OPATTRS is not defined in 2.2 yet, while this overlay
41  * expects HEAD code at least later than August 6, 2004. */
42 /* FIXME: slap_anlist_no_attrs was introduced in 2.3; here it
43  * is anticipated to allow using this overlay with 2.2. */
44
45 #ifdef OL_2_2_COMPAT
46 static AttributeName anlist_no_attrs[] = {
47         { BER_BVC( LDAP_NO_ATTRS ), NULL, 0, NULL },
48         { BER_BVNULL, NULL, 0, NULL }
49 };
50
51 static AttributeName *slap_anlist_no_attrs = anlist_no_attrs;
52 #endif
53
54 typedef struct dynlist_info_t {
55         ObjectClass             *dli_oc;
56         AttributeDescription    *dli_ad;
57         AttributeDescription    *dli_member_ad;
58         struct berval           dli_default_filter;
59         struct dynlist_info_t   *dli_next;
60 } dynlist_info_t;
61
62 static dynlist_info_t *
63 dynlist_is_dynlist( Operation *op, SlapReply *rs )
64 {
65         slap_overinst   *on = (slap_overinst *)op->o_bd->bd_info;
66         dynlist_info_t  *dli = (dynlist_info_t *)on->on_bi.bi_private;
67
68         Attribute       *a;
69
70         a = attrs_find( rs->sr_entry->e_attrs, slap_schema.si_ad_objectClass );
71         if ( a == NULL ) {
72                 /* FIXME: objectClass must be present; for non-storage
73                  * backends, like back-ldap, it needs to be added
74                  * to the requested attributes */
75                 return NULL;
76         }
77
78         for ( ; dli; dli = dli->dli_next ) {
79                 if ( value_find_ex( slap_schema.si_ad_objectClass, 
80                                 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
81                                 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
82                                 a->a_nvals, &dli->dli_oc->soc_cname,
83                                 op->o_tmpmemctx ) == 0 )
84                 {
85                         return dli;
86                 }
87         }
88
89         return NULL;
90 }
91
92 static int
93 dynlist_make_filter( Operation *op, struct berval *oldf, struct berval *newf )
94 {
95         slap_overinst   *on = (slap_overinst *)op->o_bd->bd_info;
96         dynlist_info_t  *dli = (dynlist_info_t *)on->on_bi.bi_private;
97
98         char            *ptr;
99
100         assert( oldf != NULL );
101         assert( newf != NULL );
102         assert( !BER_BVISNULL( oldf ) );
103         assert( !BER_BVISEMPTY( oldf ) );
104
105         newf->bv_len = STRLENOF( "(&(!(objectClass=" "))" ")" )
106                 + dli->dli_oc->soc_cname.bv_len + oldf->bv_len;
107         newf->bv_val = op->o_tmpalloc( newf->bv_len + 1, op->o_tmpmemctx );
108         if ( newf->bv_val == NULL ) {
109                 return -1;
110         }
111         ptr = lutil_strcopy( newf->bv_val, "(&(!(objectClass=" );
112         ptr = lutil_strcopy( ptr, dli->dli_oc->soc_cname.bv_val );
113         ptr = lutil_strcopy( ptr, "))" );
114         ptr = lutil_strcopy( ptr, oldf->bv_val );
115         ptr = lutil_strcopy( ptr, ")" );
116         newf->bv_len = ptr - newf->bv_val;
117
118         return 0;
119 }
120
121 typedef struct dynlist_sc_t {
122         dynlist_info_t    *dlc_dli;
123         Entry           *dlc_e;
124 } dynlist_sc_t;
125
126 static int
127 dynlist_sc_update( Operation *op, SlapReply *rs )
128 {
129         Entry                   *e;
130         Attribute               *a;
131         int                     opattrs,
132                                 userattrs;
133         AccessControlState      acl_state = ACL_STATE_INIT;
134
135         dynlist_sc_t            *dlc;
136
137         if ( rs->sr_type != REP_SEARCH ) {
138                 return 0;
139         }
140
141         dlc = (dynlist_sc_t *)op->o_callback->sc_private;
142         e = dlc->dlc_e;
143
144         assert( e != NULL );
145         assert( rs->sr_entry != NULL );
146
147         /* test access to entry */
148         if ( !access_allowed( op, rs->sr_entry, slap_schema.si_ad_entry,
149                                 NULL, ACL_READ, NULL ) )
150         {
151                 goto done;
152         }
153
154         if ( dlc->dlc_dli->dli_member_ad ) {
155
156                 /* if access allowed, try to add values, emulating permissive
157                  * control to silently ignore duplicates */
158                 if ( access_allowed( op, rs->sr_entry, slap_schema.si_ad_entry,
159                                         NULL, ACL_READ, NULL ) )
160                 {
161                         Modification    mod;
162                         const char      *text = NULL;
163                         char            textbuf[1024];
164                         struct berval   vals[ 2 ], nvals[ 2 ];
165
166                         vals[ 0 ] = rs->sr_entry->e_name;
167                         BER_BVZERO( &vals[ 1 ] );
168                         nvals[ 0 ] = rs->sr_entry->e_nname;
169                         BER_BVZERO( &nvals[ 1 ] );
170
171                         mod.sm_op = LDAP_MOD_ADD;
172                         mod.sm_desc = dlc->dlc_dli->dli_member_ad;
173                         mod.sm_type = dlc->dlc_dli->dli_member_ad->ad_cname;
174                         mod.sm_values = vals;
175                         mod.sm_nvalues = nvals;
176
177                         (void)modify_add_values( e, &mod, /* permissive */ 1,
178                                         &text, textbuf, sizeof( textbuf ) );
179                 }
180
181                 goto done;
182         }
183
184 #ifndef SLAP_OPATTRS
185         opattrs = ( rs->sr_attrs == NULL ) ? 0 : an_find( rs->sr_attrs, &AllOper );
186         userattrs = ( rs->sr_attrs == NULL ) ? 1 : an_find( rs->sr_attrs, &AllUser );
187 #else /* SLAP_OPATTRS */
188         opattrs = SLAP_OPATTRS( rs->sr_attr_flags );
189         userattrs = SLAP_USERATTRS( rs->sr_attr_flags );
190 #endif /* SLAP_OPATTRS */
191
192         for ( a = rs->sr_entry->e_attrs; a != NULL; a = a->a_next ) {
193                 BerVarray       vals, nvals = NULL;
194                 int             i, j;
195
196                 /* if attribute is not requested, skip it */
197                 if ( rs->sr_attrs == NULL ) {
198                         if ( is_at_operational( a->a_desc->ad_type ) ) {
199                                 continue;
200                         }
201
202                 } else {
203                         if ( is_at_operational( a->a_desc->ad_type ) ) {
204                                 if ( !opattrs && !ad_inlist( a->a_desc, rs->sr_attrs ) )
205                                 {
206                                         continue;
207                                 }
208
209                         } else {
210                                 if ( !userattrs && !ad_inlist( a->a_desc, rs->sr_attrs ) )
211                                 {
212                                         continue;
213                                 }
214                         }
215                 }
216
217                 /* test access to attribute */
218                 if ( op->ors_attrsonly ) {
219                         if ( !access_allowed( op, rs->sr_entry, a->a_desc, NULL,
220                                                 ACL_READ, &acl_state ) )
221                         {
222                                 continue;
223                         }
224                 }
225
226                 /* single-value check: keep first only */
227                 if ( is_at_single_value( a->a_desc->ad_type ) ) {
228                         if ( attr_find( e->e_attrs, a->a_desc ) != NULL ) {
229                                 continue;
230                         }
231                 }
232
233                 /* test access to attribute */
234                 for ( i = 0; !BER_BVISNULL( &a->a_vals[i] ); i++ )
235                         /* just count */ ;
236
237                 vals = op->o_tmpalloc( ( i + 1 ) * sizeof( struct berval ), op->o_tmpmemctx );
238                 if ( a->a_nvals != a->a_vals ) {
239                         nvals = op->o_tmpalloc( ( i + 1 ) * sizeof( struct berval ), op->o_tmpmemctx );
240                 }
241
242                 for ( i = 0, j = 0; !BER_BVISNULL( &a->a_vals[i] ); i++ ) {
243                         if ( access_allowed( op, rs->sr_entry, a->a_desc,
244                                                 &a->a_nvals[i], ACL_READ, &acl_state ) )
245                         {
246                                 vals[j] = a->a_vals[i];
247                                 if ( nvals ) {
248                                         nvals[j] = a->a_nvals[i];
249                                 }
250                                 j++;
251                         }
252                 }
253
254                 /* if access allowed, try to add values, emulating permissive
255                  * control to silently ignore duplicates */
256                 if ( j != 0 ) {
257                         Modification    mod;
258                         const char      *text = NULL;
259                         char            textbuf[1024];
260
261                         BER_BVZERO( &vals[j] );
262                         if ( nvals ) {
263                                 BER_BVZERO( &nvals[j] );
264                         }
265
266                         mod.sm_op = LDAP_MOD_ADD;
267                         mod.sm_desc = a->a_desc;
268                         mod.sm_type = a->a_desc->ad_cname;
269                         mod.sm_values = vals;
270                         mod.sm_nvalues = nvals;
271
272                         (void)modify_add_values( e, &mod, /* permissive */ 1,
273                                         &text, textbuf, sizeof( textbuf ) );
274                 }
275
276                 op->o_tmpfree( vals, op->o_tmpmemctx );
277                 if ( nvals ) {
278                         op->o_tmpfree( nvals, op->o_tmpmemctx );
279                 }
280         }
281
282 done:;
283         if ( rs->sr_flags & REP_ENTRY_MUSTBEFREED ) {
284                 entry_free( rs->sr_entry );
285         }
286
287         return 0;
288 }
289         
290 static int
291 dynlist_send_entry( Operation *op, SlapReply *rs, dynlist_info_t *dli )
292 {
293         Attribute       *a;
294         slap_callback   cb;
295         Operation       o = *op;
296         SlapReply       r = { REP_SEARCH };
297         struct berval   *url;
298         Entry           *e;
299         slap_mask_t     e_flags;
300         int             opattrs,
301                         userattrs;
302         dynlist_sc_t    dlc = { 0 };
303
304         a = attrs_find( rs->sr_entry->e_attrs, dli->dli_ad );
305         if ( a == NULL ) {
306                 /* FIXME: error? */
307                 return SLAP_CB_CONTINUE;
308         }
309
310         e = entry_dup( rs->sr_entry );
311         e_flags = rs->sr_flags | ( REP_ENTRY_MODIFIABLE | REP_ENTRY_MUSTBEFREED );
312
313         dlc.dlc_e = e;
314         dlc.dlc_dli = dli;
315         cb.sc_private = &dlc;
316         cb.sc_response = dynlist_sc_update;
317         cb.sc_cleanup = NULL;
318         cb.sc_next = NULL;
319
320         o.o_callback = &cb;
321         o.ors_deref = LDAP_DEREF_NEVER;
322         o.ors_limit = NULL;
323         o.ors_tlimit = SLAP_NO_LIMIT;
324         o.ors_slimit = SLAP_NO_LIMIT;
325
326 #ifndef SLAP_OPATTRS
327         opattrs = ( rs->sr_attrs == NULL ) ? 0 : an_find( rs->sr_attrs, &AllOper );
328         userattrs = ( rs->sr_attrs == NULL ) ? 1 : an_find( rs->sr_attrs, &AllUser );
329 #else /* SLAP_OPATTRS */
330         opattrs = SLAP_OPATTRS( rs->sr_attr_flags );
331         userattrs = SLAP_USERATTRS( rs->sr_attr_flags );
332 #endif /* SLAP_OPATTRS */
333
334         for ( url = a->a_nvals; !BER_BVISNULL( url ); url++ ) {
335                 LDAPURLDesc     *lud = NULL;
336                 int             i, j;
337                 struct berval   dn;
338                 int             rc;
339
340                 BER_BVZERO( &o.o_req_dn );
341                 BER_BVZERO( &o.o_req_ndn );
342                 o.ors_filter = NULL;
343                 o.ors_attrs = NULL;
344                 BER_BVZERO( &o.ors_filterstr );
345
346                 if ( ldap_url_parse( url->bv_val, &lud ) != LDAP_URL_SUCCESS ) {
347                         /* FIXME: error? */
348                         continue;
349                 }
350
351                 if ( lud->lud_host ) {
352                         /* FIXME: host not allowed; reject as illegal? */
353                         Debug( LDAP_DEBUG_ANY, "dynlist_send_entry(\"%s\"): "
354                                 "illegal URI \"%s\"\n",
355                                 e->e_name.bv_val, url->bv_val, 0 );
356                         goto cleanup;
357                 }
358
359                 if ( lud->lud_dn == NULL ) {
360                         /* note that an empty base is not honored in terms
361                          * of defaultSearchBase, because select_backend()
362                          * is not aware of the defaultSearchBase option;
363                          * this can be useful in case of a database serving
364                          * the empty suffix */
365                         BER_BVSTR( &dn, "" );
366                 } else {
367                         ber_str2bv( lud->lud_dn, 0, 0, &dn );
368                 }
369                 rc = dnPrettyNormal( NULL, &dn, &o.o_req_dn, &o.o_req_ndn, op->o_tmpmemctx );
370                 if ( rc != LDAP_SUCCESS ) {
371                         /* FIXME: error? */
372                         goto cleanup;
373                 }
374                 o.ors_scope = lud->lud_scope;
375
376                 if ( dli->dli_member_ad != NULL ) {
377                         o.ors_attrs = slap_anlist_no_attrs;
378
379                 } else if ( lud->lud_attrs == NULL ) {
380                         o.ors_attrs = rs->sr_attrs;
381
382                 } else {
383                         for ( i = 0; lud->lud_attrs[i]; i++)
384                                 /* just count */ ;
385
386                         o.ors_attrs = op->o_tmpcalloc( i + 1, sizeof( AttributeName ), op->o_tmpmemctx );
387                         for ( i = 0, j = 0; lud->lud_attrs[i]; i++) {
388                                 const char      *text = NULL;
389         
390                                 ber_str2bv( lud->lud_attrs[i], 0, 0, &o.ors_attrs[j].an_name );
391                                 o.ors_attrs[j].an_desc = NULL;
392                                 (void)slap_bv2ad( &o.ors_attrs[j].an_name, &o.ors_attrs[j].an_desc, &text );
393                                 /* FIXME: ignore errors... */
394
395                                 if ( rs->sr_attrs == NULL ) {
396                                         if ( o.ors_attrs[j].an_desc != NULL &&
397                                                         is_at_operational( o.ors_attrs[j].an_desc->ad_type ) )
398                                         {
399                                                 continue;
400                                         }
401
402                                 } else {
403                                         if ( o.ors_attrs[j].an_desc != NULL &&
404                                                         is_at_operational( o.ors_attrs[j].an_desc->ad_type ) )
405                                         {
406                                                 if ( !opattrs && !ad_inlist( o.ors_attrs[j].an_desc, rs->sr_attrs ) )
407                                                 {
408                                                         continue;
409                                                 }
410
411                                         } else {
412                                                 if ( !userattrs && 
413                                                                 o.ors_attrs[j].an_desc != NULL &&
414                                                                 !ad_inlist( o.ors_attrs[j].an_desc, rs->sr_attrs ) )
415                                                 {
416                                                         continue;
417                                                 }
418                                         }
419                                 }
420
421                                 j++;
422                         }
423
424                         if ( j == 0 ) {
425                                 goto cleanup;
426                         }
427                 
428                         BER_BVZERO( &o.ors_attrs[j].an_name );
429                 }
430
431                 if ( lud->lud_filter == NULL ) {
432                         ber_dupbv_x( &o.ors_filterstr,
433                                         &dli->dli_default_filter, op->o_tmpmemctx );
434                 } else {
435                         struct berval   flt;
436                         ber_str2bv( lud->lud_filter, 0, 0, &flt );
437                         if ( dynlist_make_filter( op, &flt, &o.ors_filterstr ) ) {
438                                 /* error */
439                                 goto cleanup;
440                         }
441                 }
442                 o.ors_filter = str2filter_x( op, o.ors_filterstr.bv_val );
443                 if ( o.ors_filter == NULL ) {
444                         goto cleanup;
445                 }
446                 
447                 o.o_bd = select_backend( &o.o_req_ndn, 0, 1 );
448                 if ( o.o_bd && o.o_bd->be_search ) {
449 #ifdef SLAP_OPATTRS
450                         r.sr_attr_flags = slap_attr_flags( o.ors_attrs );
451 #endif /* SLAP_OPATTRS */
452                         (void)o.o_bd->be_search( &o, &r );
453                 }
454
455 cleanup:;
456                 if ( o.ors_filter ) {
457                         filter_free_x( &o, o.ors_filter );
458                 }
459                 if ( o.ors_attrs && o.ors_attrs != rs->sr_attrs
460                                 && o.ors_attrs != slap_anlist_no_attrs )
461                 {
462                         op->o_tmpfree( o.ors_attrs, op->o_tmpmemctx );
463                 }
464                 if ( !BER_BVISNULL( &o.o_req_dn ) ) {
465                         op->o_tmpfree( o.o_req_dn.bv_val, op->o_tmpmemctx );
466                 }
467                 if ( !BER_BVISNULL( &o.o_req_ndn ) ) {
468                         op->o_tmpfree( o.o_req_ndn.bv_val, op->o_tmpmemctx );
469                 }
470                 if ( o.ors_filterstr.bv_val != lud->lud_filter ) {
471                         op->o_tmpfree( o.ors_filterstr.bv_val, op->o_tmpmemctx );
472                         lud->lud_filter = NULL;
473                 }
474                 if ( lud ) {
475                         ldap_free_urldesc( lud );
476                 }
477         }
478
479         rs->sr_entry = e;
480         rs->sr_flags = e_flags;
481
482         return SLAP_CB_CONTINUE;
483 }
484
485 static int
486 dynlist_sc_save_entry( Operation *op, SlapReply *rs )
487 {
488         /* save the entry in the private field of the callback,
489          * so it doesn't get freed (it's temporary!) */
490         if ( rs->sr_entry != NULL ) {
491                 dynlist_sc_t    *dlc = (dynlist_sc_t *)op->o_callback->sc_private;
492                 dlc->dlc_e = rs->sr_entry;
493                 rs->sr_entry = NULL;
494         }
495
496         return 0;
497 }
498
499 static int
500 dynlist_compare( Operation *op, SlapReply *rs )
501 {
502         slap_overinst   *on = (slap_overinst *)op->o_bd->bd_info;
503         dynlist_info_t  *dli = (dynlist_info_t *)on->on_bi.bi_private;
504
505         for ( ; dli != NULL; dli = dli->dli_next ) {
506                 if ( op->oq_compare.rs_ava->aa_desc == dli->dli_member_ad ) {
507                         /* This compare is for one of the attributes we're
508                          * interested in. We'll use slapd's existing dyngroup
509                          * evaluator to get the answer we want.
510                          */
511                         int cache = op->o_do_not_cache;
512                                 
513                         op->o_do_not_cache = 1;
514                         rs->sr_err = backend_group( op, NULL, &op->o_req_ndn,
515                                 &op->oq_compare.rs_ava->aa_value, dli->dli_oc, dli->dli_ad );
516                         op->o_do_not_cache = cache;
517                         switch ( rs->sr_err ) {
518                         case LDAP_SUCCESS:
519                                 rs->sr_err = LDAP_COMPARE_TRUE;
520                                 break;
521
522                         case LDAP_NO_SUCH_OBJECT:
523                                 /* NOTE: backend_group() returns noSuchObject
524                                  * if op_ndn does not exist; however, since
525                                  * dynamic list expansion means that the
526                                  * member attribute is virtually present, the
527                                  * non-existence of the asserted value implies
528                                  * the assertion is FALSE rather than
529                                  * UNDEFINED */
530                                 rs->sr_err = LDAP_COMPARE_FALSE;
531                         }
532
533                         return SLAP_CB_CONTINUE;
534                 }
535         }
536
537         dli = (dynlist_info_t *)on->on_bi.bi_private;
538         for ( ; dli != NULL && rs->sr_err != LDAP_COMPARE_TRUE; dli = dli->dli_next ) {
539                 Attribute       *a;
540                 slap_callback   cb;
541                 Operation       o = *op;
542                 SlapReply       r = { REP_SEARCH };
543                 AttributeName   an[2];
544                 int             rc;
545                 dynlist_sc_t    dlc = { 0 };
546                 Entry           *e;
547
548                 int cache = op->o_do_not_cache;
549                 struct berval   op_dn = op->o_dn,
550                                 op_ndn = op->o_ndn;
551                 BackendDB       *op_bd = op->o_bd;
552
553                 /* fetch the entry as rootdn (a hack to see if it exists
554                  * and if it has the right objectClass) */
555                 op->o_do_not_cache = 1;
556                 op->o_dn = op->o_bd->be_rootdn;
557                 op->o_ndn = op->o_bd->be_rootndn;
558                 op->o_bd = select_backend( &op->o_req_ndn, 0, 0 );
559
560                 r.sr_err = be_entry_get_rw( op, &op->o_req_ndn,
561                         dli->dli_oc, NULL, 0, &e );
562                 if ( e != NULL ) {
563                         be_entry_release_r( op, e );
564                 }
565                 op->o_do_not_cache = cache;
566                 op->o_dn = op_dn;
567                 op->o_ndn = op_ndn;
568                 op->o_bd = op_bd;
569                 if ( r.sr_err != LDAP_SUCCESS ) {
570                         continue;
571                 }
572
573                 /* if the entry has the right objectClass, generate
574                  * the dynamic list and compare */
575                 dlc.dlc_dli = dli;
576                 cb.sc_private = &dlc;
577                 cb.sc_response = dynlist_sc_save_entry;
578                 cb.sc_cleanup = NULL;
579                 cb.sc_next = NULL;
580                 o.o_callback = &cb;
581
582                 o.o_tag = LDAP_REQ_SEARCH;
583                 o.ors_limit = NULL;
584                 o.ors_tlimit = SLAP_NO_LIMIT;
585                 o.ors_slimit = SLAP_NO_LIMIT;
586
587                 o.o_bd = select_backend( &o.o_req_ndn, 0, 1 );
588                 if ( !o.o_bd || !o.o_bd->be_search ) {
589                         return SLAP_CB_CONTINUE;
590                 }
591
592                 BER_BVSTR( &o.ors_filterstr, "(objectClass=*)" );
593                 o.ors_filter = str2filter_x( op, o.ors_filterstr.bv_val );
594                 if ( o.ors_filter == NULL ) {
595                         /* FIXME: error? */
596                         return SLAP_CB_CONTINUE;
597                 }
598
599                 o.ors_scope = LDAP_SCOPE_BASE;
600                 o.ors_deref = LDAP_DEREF_NEVER;
601                 an[0].an_name = op->orc_ava->aa_desc->ad_cname;
602                 an[0].an_desc = op->orc_ava->aa_desc;
603                 BER_BVZERO( &an[1].an_name );
604                 o.ors_attrs = an;
605                 o.ors_attrsonly = 0;
606
607                 rc = o.o_bd->be_search( &o, &r );
608                 filter_free_x( &o, o.ors_filter );
609
610                 if ( rc != 0 ) {
611                         return rc;
612                 }
613
614                 if ( dlc.dlc_e != NULL ) {
615                         r.sr_entry = dlc.dlc_e;
616                 }
617
618                 if ( r.sr_err != LDAP_SUCCESS || r.sr_entry == NULL ) {
619                         /* error? */
620                         return SLAP_CB_CONTINUE;
621                 }
622
623                 for ( a = attrs_find( r.sr_entry->e_attrs, op->orc_ava->aa_desc );
624                         a != NULL;
625                         a = attrs_find( a->a_next, op->orc_ava->aa_desc ) )
626                 {
627                         /* if we're here, we got a match... */
628                         rs->sr_err = LDAP_COMPARE_FALSE;
629
630                         if ( value_find_ex( op->orc_ava->aa_desc,
631                                 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
632                                         SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
633                                 a->a_nvals, &op->orc_ava->aa_value, op->o_tmpmemctx ) == 0 )
634                         {
635                                 rs->sr_err = LDAP_COMPARE_TRUE;
636                                 break;
637                         }
638                 }
639
640                 if ( r.sr_flags & REP_ENTRY_MUSTBEFREED ) {
641                         entry_free( r.sr_entry );
642                 }
643         }
644
645         return SLAP_CB_CONTINUE;
646 }
647
648 static int
649 dynlist_response( Operation *op, SlapReply *rs )
650 {
651         dynlist_info_t  *dli;
652
653         switch ( op->o_tag ) {
654         case LDAP_REQ_SEARCH:
655                 if ( rs->sr_type == REP_SEARCH && !get_manageDSAit( op ) )
656                 {
657                         dli = dynlist_is_dynlist( op, rs );
658                         if ( dli != NULL ) {
659                                 return dynlist_send_entry( op, rs, dli );
660                         }
661                 }
662                 break;
663
664         case LDAP_REQ_COMPARE:
665                 switch ( rs->sr_err ) {
666                 /* NOTE: we waste a few cycles running the dynamic list
667                  * also when the result is FALSE, which occurs if the
668                  * dynamic entry itself contains the AVA attribute  */
669                 /* FIXME: this approach is less than optimal; a dedicated
670                  * compare op should be implemented, that fetches the
671                  * entry, checks if it has the appropriate objectClass
672                  * and, in case, runs a compare thru all the URIs,
673                  * stopping at the first positive occurrence; see ITS#3756 */
674                 case LDAP_COMPARE_FALSE:
675                 case LDAP_NO_SUCH_ATTRIBUTE:
676                         return dynlist_compare( op, rs );
677                 }
678                 break;
679
680         default:
681                 break;
682         }
683
684         return SLAP_CB_CONTINUE;
685 }
686
687 static int
688 dynlist_build_def_filter( dynlist_info_t *dli )
689 {
690         char    *ptr;
691
692         dli->dli_default_filter.bv_len = STRLENOF( "(!(objectClass=" "))" )
693                 + dli->dli_oc->soc_cname.bv_len;
694         dli->dli_default_filter.bv_val = SLAP_MALLOC( dli->dli_default_filter.bv_len + 1 );
695         if ( dli->dli_default_filter.bv_val == NULL ) {
696                 Debug( LDAP_DEBUG_ANY, "dynlist_db_open: malloc failed.\n",
697                         0, 0, 0 );
698                 return -1;
699         }
700
701         ptr = lutil_strcopy( dli->dli_default_filter.bv_val, "(!(objectClass=" );
702         ptr = lutil_strcopy( ptr, dli->dli_oc->soc_cname.bv_val );
703         ptr = lutil_strcopy( ptr, "))" );
704
705         assert( dli->dli_default_filter.bv_len == ptr - dli->dli_default_filter.bv_val );
706
707         return 0;
708 }
709
710 #ifdef OL_2_2_COMPAT
711 static int
712 dynlist_db_config(
713         BackendDB       *be,
714         const char      *fname,
715         int             lineno,
716         int             argc,
717         char            **argv )
718 {
719         slap_overinst   *on = (slap_overinst *)be->bd_info;
720
721         int             rc = 0;
722
723         if ( strcasecmp( argv[0], "dynlist-attrset" ) == 0 ) {
724                 dynlist_info_t          **dlip;
725                 ObjectClass             *oc;
726                 AttributeDescription    *ad = NULL,
727                                         *member_ad = NULL;
728                 const char              *text;
729
730                 if ( argc < 3 || argc > 4 ) {
731                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
732                                 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
733                                 "invalid arg number #%d.\n",
734                                 fname, lineno, argc );
735                         return 1;
736                 }
737
738                 oc = oc_find( argv[1] );
739                 if ( oc == NULL ) {
740                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
741                                 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
742                                 "unable to find ObjectClass \"%s\"\n",
743                                 fname, lineno, argv[ 1 ] );
744                         return 1;
745                 }
746
747                 rc = slap_str2ad( argv[2], &ad, &text );
748                 if ( rc != LDAP_SUCCESS ) {
749                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
750                                 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
751                                 "unable to find AttributeDescription \"%s\"\n",
752                                 fname, lineno, argv[2] );
753                         return 1;
754                 }
755
756                 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
757                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
758                                 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
759                                 "AttributeDescription \"%s\" "
760                                 "must be a subtype of \"labeledURI\"\n",
761                                 fname, lineno, argv[2] );
762                         return 1;
763                 }
764
765                 if ( argc == 4 ) {
766                         rc = slap_str2ad( argv[3], &member_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[3] );
772                                 return 1;
773                         }
774                 }
775
776                 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
777                         *dlip; dlip = &(*dlip)->dli_next )
778                         /* go to last */;
779
780                 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
781                 (*dlip)->dli_oc = oc;
782                 (*dlip)->dli_ad = ad;
783                 (*dlip)->dli_member_ad = member_ad;
784
785                 if ( dynlist_build_def_filter( *dlip ) ) {
786                         ch_free( *dlip );
787                         *dlip = NULL;
788                         return 1;
789                 }
790
791         /* allow dyngroup syntax */
792         } else if ( strcasecmp( argv[0], "dynlist-attrpair" ) == 0 ) {
793                 dynlist_info_t          **dlip;
794                 ObjectClass             *oc;
795                 AttributeDescription    *ad = NULL,
796                                         *member_ad = NULL;
797                 const char              *text;
798
799                 if ( argc != 3 ) {
800                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
801                                 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
802                                 "invalid arg number #%d.\n",
803                                 fname, lineno, argc );
804                         return 1;
805                 }
806
807                 oc = oc_find( "groupOfURLs" );
808                 if ( oc == NULL ) {
809                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
810                                 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
811                                 "unable to find default ObjectClass \"groupOfURLs\"\n",
812                                 fname, lineno, 0 );
813                         return 1;
814                 }
815
816                 rc = slap_str2ad( argv[1], &member_ad, &text );
817                 if ( rc != LDAP_SUCCESS ) {
818                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
819                                 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
820                                 "unable to find AttributeDescription \"%s\"\n",
821                                 fname, lineno, argv[1] );
822                         return 1;
823                 }
824
825                 rc = slap_str2ad( argv[2], &ad, &text );
826                 if ( rc != LDAP_SUCCESS ) {
827                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
828                                 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
829                                 "unable to find AttributeDescription \"%s\"\n",
830                                 fname, lineno, argv[2] );
831                         return 1;
832                 }
833
834                 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
835                         Debug( LDAP_DEBUG_ANY, "%s: line %d: "
836                                 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
837                                 "AttributeDescription \"%s\" "
838                                 "must be a subtype of \"labeledURI\"\n",
839                                 fname, lineno, argv[2] );
840                         return 1;
841                 }
842
843
844                 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
845                         *dlip; dlip = &(*dlip)->dli_next )
846                         /* go to last */;
847
848                 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
849                 (*dlip)->dli_oc = oc;
850                 (*dlip)->dli_ad = ad;
851                 (*dlip)->dli_member_ad = member_ad;
852
853                 if ( dynlist_build_def_filter( *dlip ) ) {
854                         ch_free( *dlip );
855                         *dlip = NULL;
856                         return 1;
857                 }
858
859         } else {
860                 rc = SLAP_CONF_UNKNOWN;
861         }
862
863         return rc;
864 }
865
866 #else
867 enum {
868         DL_ATTRSET = 1,
869         DL_ATTRPAIR,
870         DL_LAST
871 };
872
873 static ConfigDriver     dl_cfgen;
874
875 static ConfigTable dlcfg[] = {
876         { "dynlist-attrset", "group-oc> <URL-ad> <member-ad",
877                 3, 4, 0, ARG_MAGIC|DL_ATTRSET, dl_cfgen,
878                 "( OLcfgOvAt:8.1 NAME 'olcDLattrSet' "
879                         "DESC 'Dynamic list: <group objectClass>, <URL attributeDescription>, <member attributeDescription>' "
880                         "EQUALITY caseIgnoreMatch "
881                         "SYNTAX OMsDirectoryString "
882                         "X-ORDERED 'VALUES' )",
883                         NULL, NULL },
884         { "dynlist-attrpair", "member-ad> <URL-ad",
885                 3, 3, 0, ARG_MAGIC|DL_ATTRPAIR, dl_cfgen,
886                         NULL, NULL, NULL },
887         { NULL, NULL, 0, 0, 0, ARG_IGNORED }
888 };
889
890 static ConfigOCs dlocs[] = {
891         { "( OLcfgOvOc:8.1 "
892                 "NAME 'olcDynamicList' "
893                 "DESC 'Dynamic list configuration' "
894                 "SUP olcOverlayConfig "
895                 "MAY olcDLattrSet )",
896                 Cft_Overlay, dlcfg, NULL, NULL },
897         { NULL, 0, NULL }
898 };
899
900 static int
901 dl_cfgen( ConfigArgs *c )
902 {
903         slap_overinst   *on = (slap_overinst *)c->bi;
904         dynlist_info_t  *dli = (dynlist_info_t *)on->on_bi.bi_private;
905
906         int             rc = 0, i;
907
908         if ( c->op == SLAP_CONFIG_EMIT ) {
909                 switch( c->type ) {
910                 case DL_ATTRSET:
911                         for ( i = 0; dli; i++, dli = dli->dli_next ) {
912                                 struct berval   bv;
913                                 char            *ptr = c->msg;
914
915                                 assert( dli->dli_oc != NULL );
916                                 assert( dli->dli_ad != NULL );
917
918                                 ptr += snprintf( c->msg, sizeof( c->msg ),
919                                         SLAP_X_ORDERED_FMT "%s %s", i,
920                                         dli->dli_oc->soc_cname.bv_val,
921                                         dli->dli_ad->ad_cname.bv_val );
922
923                                 if ( dli->dli_member_ad != NULL ) {
924                                         ptr[ 0 ] = ' ';
925                                         ptr++;
926                                         ptr = lutil_strcopy( ptr, dli->dli_member_ad->ad_cname.bv_val );
927                                 }
928
929                                 bv.bv_val = c->msg;
930                                 bv.bv_len = ptr - bv.bv_val;
931                                 value_add_one( &c->rvalue_vals, &bv );
932                         }
933                         break;
934
935                 case DL_ATTRPAIR:
936                         rc = 1;
937                         break;
938
939                 default:
940                         rc = 1;
941                         break;
942                 }
943
944                 return rc;
945
946         } else if ( c->op == LDAP_MOD_DELETE ) {
947                 switch( c->type ) {
948                 case DL_ATTRSET:
949                         if ( c->valx < 0 ) {
950                                 dynlist_info_t  *dli_next;
951
952                                 for ( dli_next = dli; dli_next; dli = dli_next ) {
953                                         dli_next = dli->dli_next;
954
955                                         ch_free( dli->dli_default_filter.bv_val );
956                                         ch_free( dli );
957                                 }
958
959                                 on->on_bi.bi_private = NULL;
960
961                         } else {
962                                 dynlist_info_t  **dlip;
963
964                                 for ( i = 0, dlip = (dynlist_info_t **)&on->on_bi.bi_private;
965                                         i < c->valx; i++ )
966                                 {
967                                         if ( *dlip == NULL ) {
968                                                 return 1;
969                                         }
970                                         dlip = &(*dlip)->dli_next;
971                                 }
972
973                                 dli = *dlip;
974                                 *dlip = dli->dli_next;
975                                 ch_free( dli->dli_default_filter.bv_val );
976                                 ch_free( dli );
977
978                                 dli = (dynlist_info_t *)on->on_bi.bi_private;
979                         }
980                         break;
981
982                 case DL_ATTRPAIR:
983                         rc = 1;
984                         break;
985
986                 default:
987                         rc = 1;
988                         break;
989                 }
990
991                 return 1;       /* FIXME */
992         }
993
994         switch( c->type ) {
995         case DL_ATTRSET: {
996                 dynlist_info_t          **dlip,
997                                         *dli_next = NULL;
998                 ObjectClass             *oc = NULL;
999                 AttributeDescription    *ad = NULL,
1000                                         *member_ad = NULL;
1001                 const char              *text;
1002
1003                 oc = oc_find( c->argv[ 1 ] );
1004                 if ( oc == NULL ) {
1005                         snprintf( c->msg, sizeof( c->msg ),
1006                                 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1007                                 "unable to find ObjectClass \"%s\"",
1008                                 c->argv[ 1 ] );
1009                         Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1010                                 c->log, c->msg, 0 );
1011                         return 1;
1012                 }
1013
1014                 rc = slap_str2ad( c->argv[ 2 ], &ad, &text );
1015                 if ( rc != LDAP_SUCCESS ) {
1016                         snprintf( c->msg, sizeof( c->msg ),
1017                                 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1018                                 "unable to find AttributeDescription \"%s\"",
1019                                 c->argv[ 2 ] );
1020                         Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1021                                 c->log, c->msg, 0 );
1022                         return 1;
1023                 }
1024
1025                 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
1026                         snprintf( c->msg, sizeof( c->msg ),
1027                                 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1028                                 "AttributeDescription \"%s\" "
1029                                 "must be a subtype of \"labeledURI\"",
1030                                 c->argv[ 2 ] );
1031                         Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1032                                 c->log, c->msg, 0 );
1033                         return 1;
1034                 }
1035
1036                 if ( c->argc == 4 ) {
1037                         rc = slap_str2ad( c->argv[ 3 ], &member_ad, &text );
1038                         if ( rc != LDAP_SUCCESS ) {
1039                                 snprintf( c->msg, sizeof( c->msg ),
1040                                         "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1041                                         "unable to find AttributeDescription \"%s\"\n",
1042                                         c->argv[ 3 ] );
1043                                 Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1044                                         c->log, c->msg, 0 );
1045                                 return 1;
1046                         }
1047                 }
1048
1049                 if ( c->valx > 0 ) {
1050                         int     i;
1051
1052                         for ( i = 0, dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1053                                 i < c->valx; i++ )
1054                         {
1055                                 if ( *dlip == NULL ) {
1056                                         snprintf( c->msg, sizeof( c->msg ),
1057                                                 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1058                                                 "invalid index {%d}\n",
1059                                                 c->valx );
1060                                         Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1061                                                 c->log, c->msg, 0 );
1062                                         return 1;
1063                                 }
1064                                 dlip = &(*dlip)->dli_next;
1065                         }
1066                         dli_next = *dlip;
1067
1068                 } else {
1069                         for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1070                                 *dlip; dlip = &(*dlip)->dli_next )
1071                                 /* goto last */;
1072                 }
1073
1074                 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
1075
1076                 (*dlip)->dli_oc = oc;
1077                 (*dlip)->dli_ad = ad;
1078                 (*dlip)->dli_member_ad = member_ad;
1079                 (*dlip)->dli_next = dli_next;
1080
1081                 rc = dynlist_build_def_filter( *dlip );
1082
1083                 } break;
1084
1085         case DL_ATTRPAIR: {
1086                 dynlist_info_t          **dlip;
1087                 ObjectClass             *oc = NULL;
1088                 AttributeDescription    *ad = NULL,
1089                                         *member_ad = NULL;
1090                 const char              *text;
1091
1092                 oc = oc_find( "groupOfURLs" );
1093                 if ( oc == NULL ) {
1094                         snprintf( c->msg, sizeof( c->msg ),
1095                                 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1096                                 "unable to find default ObjectClass \"groupOfURLs\"" );
1097                         Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1098                                 c->log, c->msg, 0 );
1099                         return 1;
1100                 }
1101
1102                 rc = slap_str2ad( c->argv[ 1 ], &member_ad, &text );
1103                 if ( rc != LDAP_SUCCESS ) {
1104                         snprintf( c->msg, sizeof( c->msg ),
1105                                 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1106                                 "unable to find AttributeDescription \"%s\"",
1107                                 c->argv[ 1 ] );
1108                         Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1109                                 c->log, c->msg, 0 );
1110                         return 1;
1111                 }
1112
1113                 rc = slap_str2ad( c->argv[ 2 ], &ad, &text );
1114                 if ( rc != LDAP_SUCCESS ) {
1115                         snprintf( c->msg, sizeof( c->msg ),
1116                                 "\"dynlist-attrpair <member-ad> <URL-ad>\": "
1117                                 "unable to find AttributeDescription \"%s\"\n",
1118                                 c->argv[ 2 ] );
1119                         Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1120                                 c->log, c->msg, 0 );
1121                         return 1;
1122                 }
1123
1124                 if ( !is_at_subtype( ad->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
1125                         snprintf( c->msg, sizeof( c->msg ),
1126                                 "\"dynlist-attrset <oc> <URL-ad> [<member-ad>]\": "
1127                                 "AttributeDescription \"%s\" "
1128                                 "must be a subtype of \"labeledURI\"",
1129                                 c->argv[ 2 ] );
1130                         Debug( LDAP_DEBUG_ANY, "%s: %s.\n",
1131                                 c->log, c->msg, 0 );
1132                         return 1;
1133                 }
1134
1135                 for ( dlip = (dynlist_info_t **)&on->on_bi.bi_private;
1136                         *dlip; dlip = &(*dlip)->dli_next )
1137                                 /* goto last */;
1138
1139                 *dlip = (dynlist_info_t *)ch_calloc( 1, sizeof( dynlist_info_t ) );
1140
1141                 (*dlip)->dli_oc = oc;
1142                 (*dlip)->dli_ad = ad;
1143                 (*dlip)->dli_member_ad = member_ad;
1144
1145                 rc = dynlist_build_def_filter( *dlip );
1146
1147                 } break;
1148
1149         default:
1150                 rc = 1;
1151                 break;
1152         }
1153
1154         return rc;
1155 }
1156 #endif
1157
1158 static int
1159 dynlist_db_open(
1160         BackendDB       *be )
1161 {
1162         slap_overinst           *on = (slap_overinst *) be->bd_info;
1163         dynlist_info_t          *dli = (dynlist_info_t *)on->on_bi.bi_private;
1164         ObjectClass             *oc = NULL;
1165         AttributeDescription    *ad = NULL;
1166
1167         if ( dli == NULL ) {
1168                 dli = ch_calloc( 1, sizeof( dynlist_info_t ) );
1169                 on->on_bi.bi_private = (void *)dli;
1170         }
1171
1172         for ( ; dli; dli = dli->dli_next ) {
1173                 const char      *text;
1174                 int             rc;
1175
1176                 if ( dli->dli_oc == NULL ) {
1177                         if ( oc == NULL ) {
1178                                 oc = oc_find( "groupOfURLs" );
1179                                 if ( oc == NULL ) {
1180                                         Debug( LDAP_DEBUG_ANY, "dynlist_db_open: "
1181                                                 "unable to fetch objectClass \"groupOfURLs\".\n",
1182                                                 0, 0, 0 );
1183                                         return 1;
1184                                 }
1185                         }
1186
1187                         dli->dli_oc = oc;
1188                 }
1189
1190                 if ( dli->dli_ad == NULL ) {
1191                         if ( ad == NULL ) {
1192                                 rc = slap_str2ad( "memberURL", &ad, &text );
1193                                 if ( rc != LDAP_SUCCESS ) {
1194                                         Debug( LDAP_DEBUG_ANY, "dynlist_db_open: "
1195                                                 "unable to fetch attributeDescription \"memberURL\": %d (%s).\n",
1196                                                 rc, text, 0 );
1197                                         return 1;
1198                                 }
1199                         }
1200                 
1201                         dli->dli_ad = ad;                       
1202                 }
1203
1204                 rc = dynlist_build_def_filter( dli );
1205                 if ( rc != 0 ) {
1206                         return rc;
1207                 }
1208         }
1209
1210         return 0;
1211 }
1212
1213 static int
1214 dynlist_db_destroy(
1215         BackendDB       *be )
1216 {
1217         slap_overinst   *on = (slap_overinst *) be->bd_info;
1218
1219         if ( on->on_bi.bi_private ) {
1220                 dynlist_info_t  *dli = (dynlist_info_t *)on->on_bi.bi_private,
1221                                 *dli_next;
1222
1223                 for ( dli_next = dli; dli_next; dli = dli_next ) {
1224                         dli_next = dli->dli_next;
1225
1226                         ch_free( dli->dli_default_filter.bv_val );
1227                         ch_free( dli );
1228                 }
1229         }
1230
1231         return 0;
1232 }
1233
1234 static slap_overinst dynlist = { { NULL } };
1235
1236 #if SLAPD_OVER_DYNLIST == SLAPD_MOD_DYNAMIC
1237 static
1238 #endif /* SLAPD_OVER_DYNLIST == SLAPD_MOD_DYNAMIC */
1239 int
1240 dynlist_initialize(void)
1241 {
1242 #ifndef OL_2_2_COMPAT
1243         int     rc = 0;
1244 #endif
1245
1246         dynlist.on_bi.bi_type = "dynlist";
1247 #ifdef OL_2_2_COMPAT
1248         dynlist.on_bi.bi_db_config = dynlist_db_config;
1249 #else
1250         dynlist.on_bi.bi_db_config = config_generic_wrapper;
1251 #endif
1252         dynlist.on_bi.bi_db_open = dynlist_db_open;
1253         dynlist.on_bi.bi_db_destroy = dynlist_db_destroy;
1254
1255         dynlist.on_response = dynlist_response;
1256
1257 #ifndef OL_2_2_COMPAT
1258         dynlist.on_bi.bi_cf_ocs = dlocs;
1259
1260         rc = config_register_schema( dlcfg, dlocs );
1261         if ( rc ) {
1262                 return rc;
1263         }
1264 #endif
1265
1266         return overlay_register( &dynlist );
1267 }
1268
1269 #if SLAPD_OVER_DYNLIST == SLAPD_MOD_DYNAMIC
1270 int
1271 init_module( int argc, char *argv[] )
1272 {
1273         return dynlist_initialize();
1274 }
1275 #endif
1276
1277 #endif /* SLAPD_OVER_DYNLIST */