]> git.sur5r.net Git - openldap/blob - servers/slapd/back-monitor/init.c
Sync with HEAD for OL 2.4.5
[openldap] / servers / slapd / back-monitor / init.c
1 /* init.c - initialize monitor backend */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2001-2007 The OpenLDAP Foundation.
6  * Portions Copyright 2001-2003 Pierangelo Masarati.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted only as authorized by the OpenLDAP
11  * Public License.
12  *
13  * A copy of this license is available in file LICENSE in the
14  * top-level directory of the distribution or, alternatively, at
15  * <http://www.OpenLDAP.org/license.html>.
16  */
17 /* ACKNOWLEDGEMENTS:
18  * This work was initially developed by Pierangelo Masarati for inclusion
19  * in OpenLDAP Software.
20  */
21
22 #include "portable.h"
23
24 #include <stdio.h>
25 #include <ac/string.h>
26
27 #include <lutil.h>
28 #include "slap.h"
29 #include "config.h"
30 #include "lber_pvt.h"
31 #include "back-monitor.h"
32
33 #include "config.h"
34
35 #undef INTEGRATE_CORE_SCHEMA
36
37 /*
38  * used by many functions to add description to entries
39  *
40  * WARNING: be_monitor may change as new databases are added,
41  * so it should not be used outside monitor_back_db_init()
42  * until monitor_back_db_open is called.
43  */
44 BackendDB                       *be_monitor;
45
46 static struct monitor_subsys_t  **monitor_subsys;
47 static int                      monitor_subsys_opened;
48 static monitor_info_t           monitor_info;
49 static const monitor_extra_t monitor_extra = {
50         monitor_back_is_configured,
51         monitor_back_get_subsys,
52         monitor_back_get_subsys_by_dn,
53
54         monitor_back_register_subsys,
55         monitor_back_register_backend,
56         monitor_back_register_database,
57         monitor_back_register_overlay_info,
58         monitor_back_register_overlay,
59         monitor_back_register_entry,
60         monitor_back_register_entry_parent,
61         monitor_back_register_entry_attrs,
62         monitor_back_register_entry_callback,
63
64         monitor_back_unregister_entry,
65         monitor_back_unregister_entry_parent,
66         monitor_back_unregister_entry_attrs,
67         monitor_back_unregister_entry_callback
68 };
69         
70
71 /*
72  * subsystem data
73  *
74  * the known subsystems are added to the subsystems
75  * array at backend initialization; other subsystems
76  * may be added by calling monitor_back_register_subsys()
77  * before the database is opened (e.g. by other backends
78  * or by overlays or modules).
79  */
80 static struct monitor_subsys_t known_monitor_subsys[] = {
81         { 
82                 SLAPD_MONITOR_BACKEND_NAME, 
83                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
84                 { BER_BVC( "This subsystem contains information about available backends." ),
85                         BER_BVNULL },
86                 MONITOR_F_PERSISTENT_CH,
87                 monitor_subsys_backend_init,
88                 NULL,   /* destroy */
89                 NULL,   /* update */
90                 NULL,   /* create */
91                 NULL    /* modify */
92         }, { 
93                 SLAPD_MONITOR_CONN_NAME,
94                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
95                 { BER_BVC( "This subsystem contains information about connections." ),
96                         BER_BVNULL },
97                 MONITOR_F_VOLATILE_CH,
98                 monitor_subsys_conn_init,
99                 NULL,   /* destroy */
100                 NULL,   /* update */
101                 NULL,   /* create */
102                 NULL    /* modify */
103         }, { 
104                 SLAPD_MONITOR_DATABASE_NAME,    
105                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
106                 { BER_BVC( "This subsystem contains information about configured databases." ),
107                         BER_BVNULL },
108                 MONITOR_F_PERSISTENT_CH,
109                 monitor_subsys_database_init,
110                 NULL,   /* destroy */
111                 NULL,   /* update */
112                 NULL,   /* create */
113                 NULL    /* modify */
114         }, { 
115                 SLAPD_MONITOR_LISTENER_NAME,    
116                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
117                 { BER_BVC( "This subsystem contains information about active listeners." ),
118                         BER_BVNULL },
119                 MONITOR_F_PERSISTENT_CH,
120                 monitor_subsys_listener_init,
121                 NULL,   /* destroy */
122                 NULL,   /* update */
123                 NULL,   /* create */
124                 NULL    /* modify */
125         }, { 
126                 SLAPD_MONITOR_LOG_NAME,
127                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
128                 { BER_BVC( "This subsystem contains information about logging." ),
129                         BER_BVC( "Set the attribute \"managedInfo\" to the desired log levels." ),
130                         BER_BVNULL },
131                 MONITOR_F_NONE,
132                 monitor_subsys_log_init,
133                 NULL,   /* destroy */
134                 NULL,   /* update */
135                 NULL,   /* create */
136                 NULL,   /* modify */
137         }, { 
138                 SLAPD_MONITOR_OPS_NAME,
139                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
140                 { BER_BVC( "This subsystem contains information about performed operations." ),
141                         BER_BVNULL },
142                 MONITOR_F_PERSISTENT_CH,
143                 monitor_subsys_ops_init,
144                 NULL,   /* destroy */
145                 NULL,   /* update */
146                 NULL,   /* create */
147                 NULL,   /* modify */
148         }, { 
149                 SLAPD_MONITOR_OVERLAY_NAME,
150                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
151                 { BER_BVC( "This subsystem contains information about available overlays." ),
152                         BER_BVNULL },
153                 MONITOR_F_PERSISTENT_CH,
154                 monitor_subsys_overlay_init,
155                 NULL,   /* destroy */
156                 NULL,   /* update */
157                 NULL,   /* create */
158                 NULL,   /* modify */
159         }, { 
160                 SLAPD_MONITOR_SASL_NAME,        
161                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
162                 { BER_BVC( "This subsystem contains information about SASL." ),
163                         BER_BVNULL },
164                 MONITOR_F_NONE,
165                 NULL,   /* init */
166                 NULL,   /* destroy */
167                 NULL,   /* update */
168                 NULL,   /* create */
169                 NULL    /* modify */
170         }, { 
171                 SLAPD_MONITOR_SENT_NAME,
172                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
173                 { BER_BVC( "This subsystem contains statistics." ),
174                         BER_BVNULL },
175                 MONITOR_F_PERSISTENT_CH,
176                 monitor_subsys_sent_init,
177                 NULL,   /* destroy */
178                 NULL,   /* update */
179                 NULL,   /* create */
180                 NULL,   /* modify */
181         }, { 
182                 SLAPD_MONITOR_THREAD_NAME,      
183                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
184                 { BER_BVC( "This subsystem contains information about threads." ),
185                         BER_BVNULL },
186                 MONITOR_F_PERSISTENT_CH,
187                 monitor_subsys_thread_init,
188                 NULL,   /* destroy */
189                 NULL,   /* update */
190                 NULL,   /* create */
191                 NULL    /* modify */
192         }, { 
193                 SLAPD_MONITOR_TIME_NAME,
194                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
195                 { BER_BVC( "This subsystem contains information about time." ),
196                         BER_BVNULL },
197                 MONITOR_F_PERSISTENT_CH,
198                 monitor_subsys_time_init,
199                 NULL,   /* destroy */
200                 NULL,   /* update */
201                 NULL,   /* create */
202                 NULL,   /* modify */
203         }, { 
204                 SLAPD_MONITOR_TLS_NAME,
205                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
206                 { BER_BVC( "This subsystem contains information about TLS." ),
207                         BER_BVNULL },
208                 MONITOR_F_NONE,
209                 NULL,   /* init */
210                 NULL,   /* destroy */
211                 NULL,   /* update */
212                 NULL,   /* create */
213                 NULL    /* modify */
214         }, { 
215                 SLAPD_MONITOR_RWW_NAME,
216                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
217                 { BER_BVC( "This subsystem contains information about read/write waiters." ),
218                         BER_BVNULL },
219                 MONITOR_F_PERSISTENT_CH,
220                 monitor_subsys_rww_init,
221                 NULL,   /* destroy */
222                 NULL,   /* update */
223                 NULL,   /* create */
224                 NULL    /* modify */
225         }, { NULL }
226 };
227
228 int
229 monitor_subsys_is_opened( void )
230 {
231         return monitor_subsys_opened;
232 }
233
234 int
235 monitor_back_register_subsys(
236         monitor_subsys_t        *ms )
237 {
238         int     i = 0;
239
240         if ( monitor_subsys ) {
241                 for ( ; monitor_subsys[ i ] != NULL; i++ )
242                         /* just count'em */ ;
243         }
244
245         monitor_subsys = ch_realloc( monitor_subsys,
246                         ( 2 + i ) * sizeof( monitor_subsys_t * ) );
247
248         if ( monitor_subsys == NULL ) {
249                 return -1;
250         }
251
252         monitor_subsys[ i ] = ms;
253         monitor_subsys[ i + 1 ] = NULL;
254
255         /* if a subsystem is registered __AFTER__ subsystem 
256          * initialization (depending on the sequence the databases
257          * are listed in slapd.conf), init it */
258         if ( monitor_subsys_is_opened() ) {
259
260                 /* FIXME: this should only be possible
261                  * if be_monitor is already initialized */
262                 assert( be_monitor != NULL );
263
264                 if ( ms->mss_open && ( *ms->mss_open )( be_monitor, ms ) ) {
265                         return -1;
266                 }
267
268                 ms->mss_flags |= MONITOR_F_OPENED;
269         }
270
271         return 0;
272 }
273
274 enum {
275         LIMBO_ENTRY,
276         LIMBO_ENTRY_PARENT,
277         LIMBO_ATTRS,
278         LIMBO_CB,
279         LIMBO_BACKEND,
280         LIMBO_DATABASE,
281         LIMBO_OVERLAY_INFO,
282         LIMBO_OVERLAY,
283
284         LIMBO_LAST
285 };
286
287 typedef struct entry_limbo_t {
288         int                     el_type;
289         BackendInfo             *el_bi;
290         BackendDB               *el_be;
291         slap_overinst           *el_on;
292         Entry                   *el_e;
293         Attribute               *el_a;
294         struct berval           el_ndn;
295         struct berval           el_nbase;
296         int                     el_scope;
297         struct berval           el_filter;
298         monitor_callback_t      *el_cb;
299         monitor_subsys_t        *el_mss;
300         unsigned long           el_flags;
301         struct entry_limbo_t    *el_next;
302 } entry_limbo_t;
303
304 int
305 monitor_back_is_configured( void )
306 {
307         return be_monitor != NULL;
308 }
309
310 int
311 monitor_back_register_backend(
312         BackendInfo             *bi )
313 {
314         return -1;
315 }
316
317 int
318 monitor_back_register_overlay_info(
319         slap_overinst           *on )
320 {
321         return -1;
322 }
323
324 int
325 monitor_back_register_overlay(
326         BackendDB               *be )
327 {
328         return -1;
329 }
330
331 int
332 monitor_back_register_backend_limbo(
333         BackendInfo             *bi )
334 {
335         return -1;
336 }
337
338 int
339 monitor_back_register_database_limbo(
340         BackendDB               *be )
341 {
342         entry_limbo_t   **elpp, el = { 0 };
343         monitor_info_t  *mi;
344
345         if ( be_monitor == NULL ) {
346                 Debug( LDAP_DEBUG_ANY,
347                         "monitor_back_register_database_limbo: "
348                         "monitor database not configured.\n",
349                         0, 0, 0 );
350                 return -1;
351         }
352
353         mi = ( monitor_info_t * )be_monitor->be_private;
354
355
356         el.el_type = LIMBO_DATABASE;
357
358         el.el_be = be;
359         
360         for ( elpp = &mi->mi_entry_limbo;
361                         *elpp;
362                         elpp = &(*elpp)->el_next )
363                 /* go to last */;
364
365         *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
366
367         el.el_next = NULL;
368         **elpp = el;
369
370         return 0;
371 }
372
373 int
374 monitor_back_register_overlay_info_limbo(
375         slap_overinst           *on )
376 {
377         return -1;
378 }
379
380 int
381 monitor_back_register_overlay_limbo(
382         BackendDB               *be )
383 {
384         return -1;
385 }
386
387 int
388 monitor_back_register_entry(
389         Entry                   *e,
390         monitor_callback_t      *cb,
391         monitor_subsys_t        *mss,
392         unsigned long           flags )
393 {
394         monitor_info_t  *mi;
395
396         if ( be_monitor == NULL ) {
397                 Debug( LDAP_DEBUG_ANY,
398                         "monitor_back_register_entry(\"%s\"): "
399                         "monitor database not configured.\n",
400                         e->e_name.bv_val, 0, 0 );
401                 return -1;
402         }
403
404         mi = ( monitor_info_t * )be_monitor->be_private;
405
406         assert( mi != NULL );
407         assert( e != NULL );
408         assert( e->e_private == NULL );
409         
410         if ( monitor_subsys_is_opened() ) {
411                 Entry           *e_parent = NULL,
412                                 *e_new = NULL,
413                                 **ep = NULL;
414                 struct berval   pdn = BER_BVNULL;
415                 monitor_entry_t *mp = NULL,
416                                 *mp_parent = NULL;
417                 int             rc = 0;
418
419                 if ( monitor_cache_get( mi, &e->e_nname, &e_parent ) == 0 ) {
420                         /* entry exists */
421                         Debug( LDAP_DEBUG_ANY,
422                                 "monitor_back_register_entry(\"%s\"): "
423                                 "entry exists\n",
424                                 e->e_name.bv_val, 0, 0 );
425                         monitor_cache_release( mi, e_parent );
426                         return -1;
427                 }
428
429                 dnParent( &e->e_nname, &pdn );
430                 if ( monitor_cache_get( mi, &pdn, &e_parent ) != 0 ) {
431                         /* parent does not exist */
432                         Debug( LDAP_DEBUG_ANY,
433                                 "monitor_back_register_entry(\"%s\"): "
434                                 "parent \"%s\" not found\n",
435                                 e->e_name.bv_val, pdn.bv_val, 0 );
436                         return -1;
437                 }
438
439                 assert( e_parent->e_private != NULL );
440                 mp_parent = ( monitor_entry_t * )e_parent->e_private;
441
442                 if ( mp_parent->mp_flags & MONITOR_F_VOLATILE ) {
443                         /* entry is volatile; cannot append children */
444                         Debug( LDAP_DEBUG_ANY,
445                                 "monitor_back_register_entry(\"%s\"): "
446                                 "parent \"%s\" is volatile\n",
447                                 e->e_name.bv_val, e_parent->e_name.bv_val, 0 );
448                         rc = -1;
449                         goto done;
450                 }
451
452                 mp = monitor_entrypriv_create();
453                 if ( mp == NULL ) {
454                         Debug( LDAP_DEBUG_ANY,
455                                 "monitor_back_register_entry(\"%s\"): "
456                                 "monitor_entrypriv_create() failed\n",
457                                 e->e_name.bv_val, 0, 0 );
458                         rc = -1;
459                         goto done;
460                 }
461
462                 e_new = entry_dup( e );
463                 if ( e_new == NULL ) {
464                         Debug( LDAP_DEBUG_ANY,
465                                 "monitor_back_register_entry(\"%s\"): "
466                                 "entry_dup() failed\n",
467                                 e->e_name.bv_val, 0, 0 );
468                         rc = -1;
469                         goto done;
470                 }
471                 
472                 e_new->e_private = ( void * )mp;
473                 if ( mss != NULL ) {
474                         mp->mp_info = mss;
475                         mp->mp_flags = flags;
476
477                 } else {
478                         mp->mp_info = mp_parent->mp_info;
479                         mp->mp_flags = mp_parent->mp_flags | MONITOR_F_SUB;
480                 }
481                 mp->mp_cb = cb;
482
483                 ep = &mp_parent->mp_children;
484                 for ( ; *ep; ) {
485                         mp_parent = ( monitor_entry_t * )(*ep)->e_private;
486                         ep = &mp_parent->mp_next;
487                 }
488                 *ep = e_new;
489
490                 if ( monitor_cache_add( mi, e_new ) ) {
491                         Debug( LDAP_DEBUG_ANY,
492                                 "monitor_back_register_entry(\"%s\"): "
493                                 "unable to add entry\n",
494                                 e->e_name.bv_val, 0, 0 );
495                         rc = -1;
496                         goto done;
497                 }
498
499 done:;
500                 if ( rc ) {
501                         if ( mp ) {
502                                 ch_free( mp );
503                         }
504                         if ( e_new ) {
505                                 e_new->e_private = NULL;
506                                 entry_free( e_new );
507                         }
508                 }
509
510                 if ( e_parent ) {
511                         monitor_cache_release( mi, e_parent );
512                 }
513
514         } else {
515                 entry_limbo_t   **elpp, el = { 0 };
516
517                 el.el_type = LIMBO_ENTRY;
518
519                 el.el_e = entry_dup( e );
520                 if ( el.el_e == NULL ) {
521                         Debug( LDAP_DEBUG_ANY,
522                                 "monitor_back_register_entry(\"%s\"): "
523                                 "entry_dup() failed\n",
524                                 e->e_name.bv_val, 0, 0 );
525                         return -1;
526                 }
527                 
528                 el.el_cb = cb;
529                 el.el_mss = mss;
530                 el.el_flags = flags;
531
532                 for ( elpp = &mi->mi_entry_limbo;
533                                 *elpp;
534                                 elpp = &(*elpp)->el_next )
535                         /* go to last */;
536
537                 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
538                 if ( *elpp == NULL ) {
539                         el.el_e->e_private = NULL;
540                         entry_free( el.el_e );
541                         return -1;
542                 }
543
544                 el.el_next = NULL;
545                 **elpp = el;
546         }
547
548         return 0;
549 }
550
551 int
552 monitor_back_register_entry_parent(
553         Entry                   *e,
554         monitor_callback_t      *cb,
555         monitor_subsys_t        *mss,
556         unsigned long           flags,
557         struct berval           *nbase,
558         int                     scope,
559         struct berval           *filter )
560 {
561         monitor_info_t  *mi;
562         struct berval   ndn = BER_BVNULL;
563
564         if ( be_monitor == NULL ) {
565                 Debug( LDAP_DEBUG_ANY,
566                         "monitor_back_register_entry_parent(base=\"%s\" scope=%s filter=\"%s\"): "
567                         "monitor database not configured.\n",
568                         BER_BVISNULL( nbase ) ? "" : nbase->bv_val,
569                         ldap_pvt_scope2str( scope ),
570                         BER_BVISNULL( filter ) ? "" : filter->bv_val );
571                 return -1;
572         }
573
574         mi = ( monitor_info_t * )be_monitor->be_private;
575
576         assert( mi != NULL );
577         assert( e != NULL );
578         assert( e->e_private == NULL );
579
580         if ( BER_BVISNULL( filter ) ) {
581                 /* need a filter */
582                 Debug( LDAP_DEBUG_ANY,
583                         "monitor_back_register_entry_parent(\"\"): "
584                         "need a valid filter\n",
585                         0, 0, 0 );
586                 return -1;
587         }
588
589         if ( monitor_subsys_is_opened() ) {
590                 Entry           *e_parent = NULL,
591                                 *e_new = NULL,
592                                 **ep = NULL;
593                 struct berval   e_name = BER_BVNULL,
594                                 e_nname = BER_BVNULL;
595                 monitor_entry_t *mp = NULL,
596                                 *mp_parent = NULL;
597                 int             rc = 0;
598
599                 if ( monitor_search2ndn( nbase, scope, filter, &ndn ) ) {
600                         /* entry does not exist */
601                         Debug( LDAP_DEBUG_ANY,
602                                 "monitor_back_register_entry_parent(\"\"): "
603                                 "base=\"%s\" scope=%s filter=\"%s\": "
604                                 "unable to find entry\n",
605                                 nbase->bv_val ? nbase->bv_val : "\"\"",
606                                 ldap_pvt_scope2str( scope ),
607                                 filter->bv_val );
608                         return -1;
609                 }
610
611                 if ( monitor_cache_get( mi, &ndn, &e_parent ) != 0 ) {
612                         /* entry does not exist */
613                         Debug( LDAP_DEBUG_ANY,
614                                 "monitor_back_register_entry_parent(\"%s\"): "
615                                 "parent entry does not exist\n",
616                                 ndn.bv_val, 0, 0 );
617                         rc = -1;
618                         goto done;
619                 }
620
621                 assert( e_parent->e_private != NULL );
622                 mp_parent = ( monitor_entry_t * )e_parent->e_private;
623
624                 if ( mp_parent->mp_flags & MONITOR_F_VOLATILE ) {
625                         /* entry is volatile; cannot append callback */
626                         Debug( LDAP_DEBUG_ANY,
627                                 "monitor_back_register_entry_parent(\"%s\"): "
628                                 "entry is volatile\n",
629                                 e_parent->e_name.bv_val, 0, 0 );
630                         rc = -1;
631                         goto done;
632                 }
633
634                 build_new_dn( &e_name, &e_parent->e_name, &e->e_name, NULL );
635                 build_new_dn( &e_nname, &e_parent->e_nname, &e->e_nname, NULL );
636
637                 if ( monitor_cache_get( mi, &e_nname, &e_new ) == 0 ) {
638                         /* entry already exists */
639                         Debug( LDAP_DEBUG_ANY,
640                                 "monitor_back_register_entry_parent(\"%s\"): "
641                                 "entry already exists\n",
642                                 e_name.bv_val, 0, 0 );
643                         monitor_cache_release( mi, e_new );
644                         e_new = NULL;
645                         rc = -1;
646                         goto done;
647                 }
648
649                 mp = monitor_entrypriv_create();
650                 if ( mp == NULL ) {
651                         Debug( LDAP_DEBUG_ANY,
652                                 "monitor_back_register_entry_parent(\"%s\"): "
653                                 "monitor_entrypriv_create() failed\n",
654                                 e->e_name.bv_val, 0, 0 );
655                         rc = -1;
656                         goto done;
657                 }
658
659                 e_new = entry_dup( e );
660                 if ( e_new == NULL ) {
661                         Debug( LDAP_DEBUG_ANY,
662                                 "monitor_back_register_entry(\"%s\"): "
663                                 "entry_dup() failed\n",
664                                 e->e_name.bv_val, 0, 0 );
665                         rc = -1;
666                         goto done;
667                 }
668                 ch_free( e_new->e_name.bv_val );
669                 ch_free( e_new->e_nname.bv_val );
670                 e_new->e_name = e_name;
671                 e_new->e_nname = e_nname;
672                 
673                 e_new->e_private = ( void * )mp;
674                 if ( mss != NULL ) {
675                         mp->mp_info = mss;
676                         mp->mp_flags = flags;
677
678                 } else {
679                         mp->mp_info = mp_parent->mp_info;
680                         mp->mp_flags = mp_parent->mp_flags | MONITOR_F_SUB;
681                 }
682                 mp->mp_cb = cb;
683
684                 ep = &mp_parent->mp_children;
685                 for ( ; *ep; ) {
686                         mp_parent = ( monitor_entry_t * )(*ep)->e_private;
687                         ep = &mp_parent->mp_next;
688                 }
689                 *ep = e_new;
690
691                 if ( monitor_cache_add( mi, e_new ) ) {
692                         Debug( LDAP_DEBUG_ANY,
693                                 "monitor_back_register_entry(\"%s\"): "
694                                 "unable to add entry\n",
695                                 e->e_name.bv_val, 0, 0 );
696                         rc = -1;
697                         goto done;
698                 }
699
700 done:;
701                 if ( !BER_BVISNULL( &ndn ) ) {
702                         ch_free( ndn.bv_val );
703                 }
704
705                 if ( rc ) {
706                         if ( mp ) {
707                                 ch_free( mp );
708                         }
709                         if ( e_new ) {
710                                 e_new->e_private = NULL;
711                                 entry_free( e_new );
712                         }
713                 }
714
715                 if ( e_parent ) {
716                         monitor_cache_release( mi, e_parent );
717                 }
718
719         } else {
720                 entry_limbo_t   **elpp = NULL, el = { 0 };
721
722                 el.el_type = LIMBO_ENTRY_PARENT;
723
724                 el.el_e = entry_dup( e );
725                 if ( el.el_e == NULL ) {
726                         Debug( LDAP_DEBUG_ANY,
727                                 "monitor_back_register_entry(\"%s\"): "
728                                 "entry_dup() failed\n",
729                                 e->e_name.bv_val, 0, 0 );
730                         goto done_limbo;
731                 }
732                 
733                 if ( !BER_BVISNULL( nbase ) ) {
734                         ber_dupbv( &el.el_nbase, nbase );
735                 }
736
737                 el.el_scope = scope;
738                 if ( !BER_BVISNULL( filter ) ) {
739                         ber_dupbv( &el.el_filter, filter  );
740                 }
741
742                 el.el_cb = cb;
743                 el.el_mss = mss;
744                 el.el_flags = flags;
745
746                 for ( elpp = &mi->mi_entry_limbo;
747                                 *elpp;
748                                 elpp = &(*elpp)->el_next )
749                         /* go to last */;
750
751                 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
752                 if ( *elpp == NULL ) {
753                         goto done_limbo;
754                 }
755
756 done_limbo:;
757                 if ( *elpp != NULL ) {
758                         el.el_next = NULL;
759                         **elpp = el;
760
761                 } else {
762                         if ( !BER_BVISNULL( &el.el_filter ) ) {
763                                 ch_free( el.el_filter.bv_val );
764                         }
765                         if ( !BER_BVISNULL( &el.el_nbase ) ) {
766                                 ch_free( el.el_nbase.bv_val );
767                         }
768                         entry_free( el.el_e );
769                         return -1;
770                 }
771         }
772
773         return 0;
774 }
775
776 static int
777 monitor_search2ndn_cb( Operation *op, SlapReply *rs )
778 {
779         if ( rs->sr_type == REP_SEARCH ) {
780                 struct berval   *ndn = op->o_callback->sc_private;
781
782                 if ( !BER_BVISNULL( ndn ) ) {
783                         rs->sr_err = LDAP_SIZELIMIT_EXCEEDED;
784                         ch_free( ndn->bv_val );
785                         BER_BVZERO( ndn );
786                         return rs->sr_err;
787                 }
788                 
789                 ber_dupbv( ndn, &rs->sr_entry->e_nname );
790         }
791
792         return 0;
793 }
794
795 int
796 monitor_search2ndn(
797         struct berval   *nbase,
798         int             scope,
799         struct berval   *filter,
800         struct berval   *ndn )
801 {
802         Connection      conn = { 0 };
803         OperationBuffer opbuf;
804         Operation       *op;
805         void    *thrctx;
806         SlapReply       rs = { 0 };
807         slap_callback   cb = { NULL, monitor_search2ndn_cb, NULL, NULL };
808         int             rc;
809
810         BER_BVZERO( ndn );
811
812         if ( be_monitor == NULL ) {
813                 return -1;
814         }
815
816         thrctx = ldap_pvt_thread_pool_context();
817         connection_fake_init( &conn, &opbuf, thrctx );
818         op = &opbuf.ob_op;
819
820         op->o_tag = LDAP_REQ_SEARCH;
821
822         /* use global malloc for now */
823         if ( op->o_tmpmemctx ) {
824                 op->o_tmpmemctx = NULL;
825         }
826         op->o_tmpmfuncs = &ch_mfuncs;
827
828         op->o_bd = be_monitor;
829         if ( nbase == NULL || BER_BVISNULL( nbase ) ) {
830                 ber_dupbv_x( &op->o_req_dn, &op->o_bd->be_suffix[ 0 ],
831                                 op->o_tmpmemctx );
832                 ber_dupbv_x( &op->o_req_ndn, &op->o_bd->be_nsuffix[ 0 ],
833                                 op->o_tmpmemctx );
834
835         } else {
836                 if ( dnPrettyNormal( NULL, nbase, &op->o_req_dn, &op->o_req_ndn,
837                                         op->o_tmpmemctx ) ) {
838                         return -1;
839                 }
840         }
841
842         op->o_callback = &cb;
843         cb.sc_private = (void *)ndn;
844
845         op->ors_scope = scope;
846         op->ors_filter = str2filter_x( op, filter->bv_val );
847         if ( op->ors_filter == NULL ) {
848                 rc = LDAP_OTHER;
849                 goto cleanup;
850         }
851         ber_dupbv_x( &op->ors_filterstr, filter, op->o_tmpmemctx );
852         op->ors_attrs = slap_anlist_no_attrs;
853         op->ors_attrsonly = 0;
854         op->ors_tlimit = SLAP_NO_LIMIT;
855         op->ors_slimit = 1;
856         op->ors_limit = NULL;
857         op->ors_deref = LDAP_DEREF_NEVER;
858
859         op->o_nocaching = 1;
860         op->o_managedsait = SLAP_CONTROL_NONCRITICAL;
861
862         op->o_dn = be_monitor->be_rootdn;
863         op->o_ndn = be_monitor->be_rootndn;
864
865         rc = op->o_bd->be_search( op, &rs );
866
867 cleanup:;
868         if ( op->ors_filter != NULL ) {
869                 filter_free_x( op, op->ors_filter );
870         }
871         if ( !BER_BVISNULL( &op->ors_filterstr ) ) {
872                 op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx );
873         }
874         if ( !BER_BVISNULL( &op->o_req_dn ) ) {
875                 op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
876         }
877         if ( !BER_BVISNULL( &op->o_req_ndn ) ) {
878                 op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
879         }
880
881         if ( rc != 0 ) {
882                 return rc;
883         }
884
885         switch ( rs.sr_err ) {
886         case LDAP_SUCCESS:
887                 if ( BER_BVISNULL( ndn ) ) {
888                         rc = -1;
889                 }
890                 break;
891                         
892         case LDAP_SIZELIMIT_EXCEEDED:
893         default:
894                 if ( !BER_BVISNULL( ndn ) ) {
895                         ber_memfree( ndn->bv_val );
896                         BER_BVZERO( ndn );
897                 }
898                 rc = -1;
899                 break;
900         }
901
902         return rc;
903 }
904
905 int
906 monitor_back_register_entry_attrs(
907         struct berval           *ndn_in,
908         Attribute               *a,
909         monitor_callback_t      *cb,
910         struct berval           *nbase,
911         int                     scope,
912         struct berval           *filter )
913 {
914         monitor_info_t  *mi;
915         struct berval   ndn = BER_BVNULL;
916         char            *fname = ( a == NULL ? "callback" : "attrs" );
917
918         if ( be_monitor == NULL ) {
919                 char            buf[ SLAP_TEXT_BUFLEN ];
920
921                 snprintf( buf, sizeof( buf ),
922                         "monitor_back_register_entry_%s(base=\"%s\" scope=%s filter=\"%s\"): "
923                         "monitor database not configured.\n",
924                         fname,
925                         BER_BVISNULL( nbase ) ? "" : nbase->bv_val,
926                         ldap_pvt_scope2str( scope ),
927                         BER_BVISNULL( filter ) ? "" : filter->bv_val );
928                 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
929
930                 return -1;
931         }
932
933         mi = ( monitor_info_t * )be_monitor->be_private;
934
935         assert( mi != NULL );
936
937         if ( ndn_in != NULL ) {
938                 ndn = *ndn_in;
939         }
940
941         if ( a == NULL && cb == NULL ) {
942                 /* nothing to do */
943                 return -1;
944         }
945
946         if ( ( ndn_in == NULL || BER_BVISNULL( &ndn ) )
947                         && BER_BVISNULL( filter ) )
948         {
949                 /* need a filter */
950                 Debug( LDAP_DEBUG_ANY,
951                         "monitor_back_register_entry_%s(\"\"): "
952                         "need a valid filter\n",
953                         fname, 0, 0 );
954                 return -1;
955         }
956
957         if ( monitor_subsys_is_opened() ) {
958                 Entry                   *e = NULL;
959                 Attribute               **atp = NULL;
960                 monitor_entry_t         *mp = NULL;
961                 monitor_callback_t      **mcp = NULL;
962                 int                     rc = 0;
963                 int                     freeit = 0;
964
965                 if ( BER_BVISNULL( &ndn ) ) {
966                         if ( monitor_search2ndn( nbase, scope, filter, &ndn ) ) {
967                                 char            buf[ SLAP_TEXT_BUFLEN ];
968
969                                 snprintf( buf, sizeof( buf ),
970                                         "monitor_back_register_entry_%s(\"\"): "
971                                         "base=\"%s\" scope=%s filter=\"%s\": "
972                                         "unable to find entry\n",
973                                         fname,
974                                         nbase->bv_val ? nbase->bv_val : "\"\"",
975                                         ldap_pvt_scope2str( scope ),
976                                         filter->bv_val );
977
978                                 /* entry does not exist */
979                                 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
980                                 return -1;
981                         }
982
983                         freeit = 1;
984                 }
985
986                 if ( monitor_cache_get( mi, &ndn, &e ) != 0 ) {
987                         /* entry does not exist */
988                         Debug( LDAP_DEBUG_ANY,
989                                 "monitor_back_register_entry_%s(\"%s\"): "
990                                 "entry does not exist\n",
991                                 fname, ndn.bv_val, 0 );
992                         rc = -1;
993                         goto done;
994                 }
995
996                 assert( e->e_private != NULL );
997                 mp = ( monitor_entry_t * )e->e_private;
998
999                 if ( mp->mp_flags & MONITOR_F_VOLATILE ) {
1000                         /* entry is volatile; cannot append callback */
1001                         Debug( LDAP_DEBUG_ANY,
1002                                 "monitor_back_register_entry_%s(\"%s\"): "
1003                                 "entry is volatile\n",
1004                                 fname, e->e_name.bv_val, 0 );
1005                         rc = -1;
1006                         goto done;
1007                 }
1008
1009                 if ( a ) {
1010                         for ( atp = &e->e_attrs; *atp; atp = &(*atp)->a_next )
1011                                 /* just get to last */ ;
1012
1013                         for ( ; a != NULL; a = a->a_next ) {
1014                                 assert( a->a_desc != NULL );
1015                                 assert( a->a_vals != NULL );
1016
1017                                 if ( attr_find( e->e_attrs, a->a_desc ) ) {
1018                                         attr_merge( e, a->a_desc, a->a_vals,
1019                                                 a->a_nvals == a->a_vals ? NULL : a->a_nvals );
1020
1021                                 } else {
1022                                         *atp = attr_dup( a );
1023                                         if ( *atp == NULL ) {
1024                                                 Debug( LDAP_DEBUG_ANY,
1025                                                         "monitor_back_register_entry_%s(\"%s\"): "
1026                                                         "attr_dup() failed\n",
1027                                                         fname, e->e_name.bv_val, 0 );
1028                                                 rc = -1;
1029                                                 goto done;
1030                                         }
1031                                         atp = &(*atp)->a_next;
1032                                 }
1033                         }
1034                 }
1035
1036                 if ( cb ) {
1037                         for ( mcp = &mp->mp_cb; *mcp; mcp = &(*mcp)->mc_next )
1038                                 /* go to tail */ ;
1039                 
1040                         /* NOTE: we do not clear cb->mc_next, so this function
1041                          * can be used to append a list of callbacks */
1042                         (*mcp) = cb;
1043                 }
1044
1045 done:;
1046                 if ( rc ) {
1047                         if ( atp && *atp ) {
1048                                 attrs_free( *atp );
1049                                 *atp = NULL;
1050                         }
1051                 }
1052
1053                 if ( freeit ) {
1054                         ber_memfree( ndn.bv_val );
1055                 }
1056
1057                 if ( e ) {
1058                         monitor_cache_release( mi, e );
1059                 }
1060
1061         } else {
1062                 entry_limbo_t   **elpp, el = { 0 };
1063
1064                 el.el_type = LIMBO_ATTRS;
1065                 if ( !BER_BVISNULL( &ndn ) ) {
1066                         ber_dupbv( &el.el_ndn, &ndn );
1067                 }
1068                 if ( !BER_BVISNULL( nbase ) ) {
1069                         ber_dupbv( &el.el_nbase, nbase);
1070                 }
1071                 el.el_scope = scope;
1072                 if ( !BER_BVISNULL( filter ) ) {
1073                         ber_dupbv( &el.el_filter, filter  );
1074                 }
1075
1076                 el.el_a = attrs_dup( a );
1077                 el.el_cb = cb;
1078
1079                 for ( elpp = &mi->mi_entry_limbo;
1080                                 *elpp;
1081                                 elpp = &(*elpp)->el_next )
1082                         /* go to last */;
1083
1084                 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
1085                 if ( *elpp == NULL ) {
1086                         el.el_e->e_private = NULL;
1087                         entry_free( el.el_e );
1088                         return -1;
1089                 }
1090
1091                 if ( *elpp != NULL ) {
1092                         el.el_next = NULL;
1093                         **elpp = el;
1094
1095                 } else {
1096                         if ( !BER_BVISNULL( &el.el_filter ) ) {
1097                                 ch_free( el.el_filter.bv_val );
1098                         }
1099                         if ( el.el_a != NULL ) {
1100                                 attrs_free( el.el_a );
1101                         }
1102                         if ( !BER_BVISNULL( &el.el_nbase ) ) {
1103                                 ch_free( &el.el_nbase.bv_val );
1104                         }
1105                         if ( !BER_BVISNULL( &el.el_ndn ) ) {
1106                                 ch_free( el.el_ndn.bv_val );
1107                         }
1108                         return -1;
1109                 }
1110         }
1111
1112         return 0;
1113 }
1114
1115 int
1116 monitor_back_register_entry_callback(
1117         struct berval           *ndn,
1118         monitor_callback_t      *cb,
1119         struct berval           *nbase,
1120         int                     scope,
1121         struct berval           *filter )
1122 {
1123         return monitor_back_register_entry_attrs( ndn, NULL, cb,
1124                         nbase, scope, filter );
1125 }
1126
1127 /*
1128  * TODO: add corresponding calls to remove installed callbacks, entries
1129  * and so, in case the entity that installed them is removed (e.g. a 
1130  * database, via back-config)
1131  */
1132 int
1133 monitor_back_unregister_entry(
1134         struct berval   *ndn )
1135 {
1136         monitor_info_t  *mi;
1137
1138         if ( be_monitor == NULL ) {
1139                 Debug( LDAP_DEBUG_ANY,
1140                         "monitor_back_unregister_entry(\"%s\"): "
1141                         "monitor database not configured.\n",
1142                         ndn->bv_val, 0, 0 );
1143
1144                 return -1;
1145         }
1146
1147         /* entry will be regularly freed, and resources released
1148          * according to callbacks */
1149         if ( slapd_shutdown ) {
1150                 return 0;
1151         }
1152
1153         mi = ( monitor_info_t * )be_monitor->be_private;
1154
1155         assert( mi != NULL );
1156
1157         if ( monitor_subsys_is_opened() ) {
1158                 Entry                   *e = NULL;
1159                 monitor_entry_t         *mp = NULL;
1160                 monitor_callback_t      *cb = NULL;
1161
1162                 if ( monitor_cache_remove( mi, ndn, &e ) != 0 ) {
1163                         /* entry does not exist */
1164                         Debug( LDAP_DEBUG_ANY,
1165                                 "monitor_back_unregister_entry(\"%s\"): "
1166                                 "entry removal failed.\n",
1167                                 ndn->bv_val, 0, 0 );
1168                         return -1;
1169                 }
1170
1171                 mp = (monitor_entry_t *)e->e_private;
1172                 assert( mp != NULL );
1173
1174                 for ( cb = mp->mp_cb; cb != NULL; ) {
1175                         monitor_callback_t      *next = cb->mc_next;
1176
1177                         if ( cb->mc_free ) {
1178                                 (void)cb->mc_free( e, &cb->mc_private );
1179                         }
1180                         ch_free( cb );
1181
1182                         cb = next;
1183                 }
1184
1185                 ch_free( mp );
1186                 e->e_private = NULL;
1187                 entry_free( e );
1188
1189         } else {
1190                 entry_limbo_t   **elpp;
1191
1192                 for ( elpp = &mi->mi_entry_limbo;
1193                         *elpp;
1194                         elpp = &(*elpp)->el_next )
1195                 {
1196                         entry_limbo_t   *elp = *elpp;
1197
1198                         if ( elp->el_type == LIMBO_ENTRY
1199                                 && dn_match( ndn, &elp->el_e->e_nname ) )
1200                         {
1201                                 monitor_callback_t      *cb, *next;
1202
1203                                 for ( cb = elp->el_cb; cb; cb = next ) {
1204                                         /* FIXME: call callbacks? */
1205                                         next = cb->mc_next;
1206                                         if ( cb->mc_dispose ) {
1207                                                 cb->mc_dispose( &cb->mc_private );
1208                                         }
1209                                         ch_free( cb );
1210                                 }
1211                                 assert( elp->el_e != NULL );
1212                                 elp->el_e->e_private = NULL;
1213                                 entry_free( elp->el_e );
1214                                 *elpp = elp->el_next;
1215                                 ch_free( elp );
1216                                 elpp = NULL;
1217                                 break;
1218                         }
1219                 }
1220
1221                 if ( elpp != NULL ) {
1222                         /* not found!  where did it go? */
1223                         return 1;
1224                 }
1225         }
1226
1227         return 0;
1228 }
1229
1230 int
1231 monitor_back_unregister_entry_parent(
1232         struct berval           *nrdn,
1233         monitor_callback_t      *target_cb,
1234         struct berval           *nbase,
1235         int                     scope,
1236         struct berval           *filter )
1237 {
1238         monitor_info_t  *mi;
1239         struct berval   ndn = BER_BVNULL;
1240
1241         if ( be_monitor == NULL ) {
1242                 Debug( LDAP_DEBUG_ANY,
1243                         "monitor_back_unregister_entry_parent(base=\"%s\" scope=%s filter=\"%s\"): "
1244                         "monitor database not configured.\n",
1245                         BER_BVISNULL( nbase ) ? "" : nbase->bv_val,
1246                         ldap_pvt_scope2str( scope ),
1247                         BER_BVISNULL( filter ) ? "" : filter->bv_val );
1248
1249                 return -1;
1250         }
1251
1252         /* entry will be regularly freed, and resources released
1253          * according to callbacks */
1254         if ( slapd_shutdown ) {
1255                 return 0;
1256         }
1257
1258         mi = ( monitor_info_t * )be_monitor->be_private;
1259
1260         assert( mi != NULL );
1261
1262         if ( ( nrdn == NULL || BER_BVISNULL( nrdn ) )
1263                         && BER_BVISNULL( filter ) )
1264         {
1265                 /* need a filter */
1266                 Debug( LDAP_DEBUG_ANY,
1267                         "monitor_back_unregister_entry_parent(\"\"): "
1268                         "need a valid filter\n",
1269                         0, 0, 0 );
1270                 return -1;
1271         }
1272
1273         if ( monitor_subsys_is_opened() ) {
1274                 Entry                   *e = NULL;
1275                 monitor_entry_t         *mp = NULL;
1276
1277                 if ( monitor_search2ndn( nbase, scope, filter, &ndn ) ) {
1278                         /* entry does not exist */
1279                         Debug( LDAP_DEBUG_ANY,
1280                                 "monitor_back_unregister_entry_parent(\"\"): "
1281                                 "base=\"%s\" scope=%s filter=\"%s\": "
1282                                 "unable to find entry\n",
1283                                 nbase->bv_val ? nbase->bv_val : "\"\"",
1284                                 ldap_pvt_scope2str( scope ),
1285                                 filter->bv_val );
1286                         return -1;
1287                 }
1288
1289                 if ( monitor_cache_remove( mi, &ndn, &e ) != 0 ) {
1290                         /* entry does not exist */
1291                         Debug( LDAP_DEBUG_ANY,
1292                                 "monitor_back_unregister_entry(\"%s\"): "
1293                                 "entry removal failed.\n",
1294                                 ndn.bv_val, 0, 0 );
1295                         ber_memfree( ndn.bv_val );
1296                         return -1;
1297                 }
1298                 ber_memfree( ndn.bv_val );
1299
1300                 mp = (monitor_entry_t *)e->e_private;
1301                 assert( mp != NULL );
1302
1303                 if ( target_cb != NULL ) {
1304                         monitor_callback_t      **cbp;
1305
1306                         for ( cbp = &mp->mp_cb; *cbp != NULL; cbp = &(*cbp)->mc_next ) {
1307                                 if ( *cbp == target_cb ) {
1308                                         if ( (*cbp)->mc_free ) {
1309                                                 (void)(*cbp)->mc_free( e, &(*cbp)->mc_private );
1310                                         }
1311                                         *cbp = (*cbp)->mc_next;
1312                                         ch_free( target_cb );
1313                                         break;
1314                                 }
1315                         }
1316                 }
1317
1318
1319                 ch_free( mp );
1320                 e->e_private = NULL;
1321                 entry_free( e );
1322
1323         } else {
1324                 entry_limbo_t   **elpp;
1325
1326                 for ( elpp = &mi->mi_entry_limbo;
1327                         *elpp;
1328                         elpp = &(*elpp)->el_next )
1329                 {
1330                         entry_limbo_t   *elp = *elpp;
1331
1332                         if ( elp->el_type == LIMBO_ENTRY_PARENT
1333                                 && dn_match( nrdn, &elp->el_e->e_nname )
1334                                 && dn_match( nbase, &elp->el_nbase )
1335                                 && scope == elp->el_scope
1336                                 && bvmatch( filter, &elp->el_filter ) )
1337                         {
1338                                 monitor_callback_t      *cb, *next;
1339
1340                                 for ( cb = elp->el_cb; cb; cb = next ) {
1341                                         /* FIXME: call callbacks? */
1342                                         next = cb->mc_next;
1343                                         if ( cb->mc_dispose ) {
1344                                                 cb->mc_dispose( &cb->mc_private );
1345                                         }
1346                                         ch_free( cb );
1347                                 }
1348                                 assert( elp->el_e != NULL );
1349                                 elp->el_e->e_private = NULL;
1350                                 entry_free( elp->el_e );
1351                                 if ( !BER_BVISNULL( &elp->el_nbase ) ) {
1352                                         ch_free( elp->el_nbase.bv_val );
1353                                 }
1354                                 if ( !BER_BVISNULL( &elp->el_filter ) ) {
1355                                         ch_free( elp->el_filter.bv_val );
1356                                 }
1357                                 *elpp = elp->el_next;
1358                                 ch_free( elp );
1359                                 elpp = NULL;
1360                                 break;
1361                         }
1362                 }
1363
1364                 if ( elpp != NULL ) {
1365                         /* not found!  where did it go? */
1366                         return 1;
1367                 }
1368         }
1369
1370         return 0;
1371 }
1372
1373 int
1374 monitor_back_unregister_entry_attrs(
1375         struct berval           *ndn_in,
1376         Attribute               *target_a,
1377         monitor_callback_t      *target_cb,
1378         struct berval           *nbase,
1379         int                     scope,
1380         struct berval           *filter )
1381 {
1382         monitor_info_t  *mi;
1383         struct berval   ndn = BER_BVNULL;
1384         char            *fname = ( target_a == NULL ? "callback" : "attrs" );
1385
1386         if ( be_monitor == NULL ) {
1387                 char            buf[ SLAP_TEXT_BUFLEN ];
1388
1389                 snprintf( buf, sizeof( buf ),
1390                         "monitor_back_unregister_entry_%s(base=\"%s\" scope=%s filter=\"%s\"): "
1391                         "monitor database not configured.\n",
1392                         fname,
1393                         BER_BVISNULL( nbase ) ? "" : nbase->bv_val,
1394                         ldap_pvt_scope2str( scope ),
1395                         BER_BVISNULL( filter ) ? "" : filter->bv_val );
1396                 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
1397
1398                 return -1;
1399         }
1400
1401         /* entry will be regularly freed, and resources released
1402          * according to callbacks */
1403         if ( slapd_shutdown ) {
1404                 return 0;
1405         }
1406
1407         mi = ( monitor_info_t * )be_monitor->be_private;
1408
1409         assert( mi != NULL );
1410
1411         if ( ndn_in != NULL ) {
1412                 ndn = *ndn_in;
1413         }
1414
1415         if ( target_a == NULL && target_cb == NULL ) {
1416                 /* nothing to do */
1417                 return -1;
1418         }
1419
1420         if ( ( ndn_in == NULL || BER_BVISNULL( &ndn ) )
1421                         && BER_BVISNULL( filter ) )
1422         {
1423                 /* need a filter */
1424                 Debug( LDAP_DEBUG_ANY,
1425                         "monitor_back_unregister_entry_%s(\"\"): "
1426                         "need a valid filter\n",
1427                         fname, 0, 0 );
1428                 return -1;
1429         }
1430
1431         if ( monitor_subsys_is_opened() ) {
1432                 Entry                   *e = NULL;
1433                 monitor_entry_t         *mp = NULL;
1434                 int                     freeit = 0;
1435
1436                 if ( BER_BVISNULL( &ndn ) ) {
1437                         if ( monitor_search2ndn( nbase, scope, filter, &ndn ) ) {
1438                                 char            buf[ SLAP_TEXT_BUFLEN ];
1439
1440                                 snprintf( buf, sizeof( buf ),
1441                                         "monitor_back_unregister_entry_%s(\"\"): "
1442                                         "base=\"%s\" scope=%d filter=\"%s\": "
1443                                         "unable to find entry\n",
1444                                         fname,
1445                                         nbase->bv_val ? nbase->bv_val : "\"\"",
1446                                         scope, filter->bv_val );
1447
1448                                 /* entry does not exist */
1449                                 Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
1450                                 return -1;
1451                         }
1452
1453                         freeit = 1;
1454                 }
1455
1456                 if ( monitor_cache_get( mi, &ndn, &e ) != 0 ) {
1457                         /* entry does not exist */
1458                         Debug( LDAP_DEBUG_ANY,
1459                                 "monitor_back_unregister_entry(\"%s\"): "
1460                                 "entry removal failed.\n",
1461                                 ndn.bv_val, 0, 0 );
1462                         return -1;
1463                 }
1464
1465                 mp = (monitor_entry_t *)e->e_private;
1466                 assert( mp != NULL );
1467
1468                 if ( target_cb != NULL ) {
1469                         monitor_callback_t      **cbp;
1470
1471                         for ( cbp = &mp->mp_cb; *cbp != NULL; cbp = &(*cbp)->mc_next ) {
1472                                 if ( *cbp == target_cb ) {
1473                                         if ( (*cbp)->mc_free ) {
1474                                                 (void)(*cbp)->mc_free( e, &(*cbp)->mc_private );
1475                                         }
1476                                         *cbp = (*cbp)->mc_next;
1477                                         ch_free( target_cb );
1478                                         break;
1479                                 }
1480                         }
1481                 }
1482
1483                 if ( target_a != NULL ) {
1484                         Attribute       *a;
1485
1486                         for ( a = target_a; a != NULL; a = a->a_next ) {
1487                                 Modification    mod = { 0 };
1488                                 const char      *text;
1489                                 char            textbuf[ SLAP_TEXT_BUFLEN ];
1490
1491                                 mod.sm_op = LDAP_MOD_DELETE;
1492                                 mod.sm_desc = a->a_desc;
1493                                 mod.sm_values = a->a_vals;
1494                                 mod.sm_nvalues = a->a_nvals;
1495
1496                                 (void)modify_delete_values( e, &mod, 1,
1497                                         &text, textbuf, sizeof( textbuf ) );
1498                         }
1499                 }
1500
1501                 if ( freeit ) {
1502                         ber_memfree( ndn.bv_val );
1503                 }
1504
1505                 monitor_cache_release( mi, e );
1506
1507         } else {
1508                 entry_limbo_t   **elpp;
1509
1510                 for ( elpp = &mi->mi_entry_limbo;
1511                         *elpp;
1512                         elpp = &(*elpp)->el_next )
1513                 {
1514                         entry_limbo_t   *elp = *elpp;
1515
1516                         if ( elp->el_type == LIMBO_ATTRS
1517                                 && dn_match( nbase, &elp->el_nbase )
1518                                 && scope == elp->el_scope
1519                                 && bvmatch( filter, &elp->el_filter ) )
1520                         {
1521                                 monitor_callback_t      *cb, *next;
1522
1523                                 for ( cb = elp->el_cb; cb; cb = next ) {
1524                                         /* FIXME: call callbacks? */
1525                                         next = cb->mc_next;
1526                                         if ( cb->mc_dispose ) {
1527                                                 cb->mc_dispose( &cb->mc_private );
1528                                         }
1529                                         ch_free( cb );
1530                                 }
1531                                 assert( elp->el_e == NULL );
1532                                 if ( elp->el_a != NULL ) {
1533                                         attrs_free( elp->el_a );
1534                                 }
1535                                 if ( !BER_BVISNULL( &elp->el_nbase ) ) {
1536                                         ch_free( elp->el_nbase.bv_val );
1537                                 }
1538                                 if ( !BER_BVISNULL( &elp->el_filter ) ) {
1539                                         ch_free( elp->el_filter.bv_val );
1540                                 }
1541                                 *elpp = elp->el_next;
1542                                 ch_free( elp );
1543                                 elpp = NULL;
1544                                 break;
1545                         }
1546                 }
1547
1548                 if ( elpp != NULL ) {
1549                         /* not found!  where did it go? */
1550                         return 1;
1551                 }
1552         }
1553
1554         return 0;
1555 }
1556
1557 int
1558 monitor_back_unregister_entry_callback(
1559         struct berval           *ndn,
1560         monitor_callback_t      *cb,
1561         struct berval           *nbase,
1562         int                     scope,
1563         struct berval           *filter )
1564 {
1565         /* TODO: lookup entry (by ndn, if not NULL, and/or by callback);
1566          * unregister the callback; if a is not null, unregister the
1567          * given attrs.  In any case, call cb->cb_free */
1568         return monitor_back_unregister_entry_attrs( ndn,
1569                 NULL, cb, nbase, scope, filter );
1570 }
1571
1572 monitor_subsys_t *
1573 monitor_back_get_subsys( const char *name )
1574 {
1575         if ( monitor_subsys != NULL ) {
1576                 int     i;
1577                 
1578                 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1579                         if ( strcasecmp( monitor_subsys[ i ]->mss_name, name ) == 0 ) {
1580                                 return monitor_subsys[ i ];
1581                         }
1582                 }
1583         }
1584
1585         return NULL;
1586 }
1587
1588 monitor_subsys_t *
1589 monitor_back_get_subsys_by_dn(
1590         struct berval   *ndn,
1591         int             sub )
1592 {
1593         if ( monitor_subsys != NULL ) {
1594                 int     i;
1595
1596                 if ( sub ) {
1597                         for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1598                                 if ( dnIsSuffix( ndn, &monitor_subsys[ i ]->mss_ndn ) ) {
1599                                         return monitor_subsys[ i ];
1600                                 }
1601                         }
1602
1603                 } else {
1604                         for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1605                                 if ( dn_match( ndn, &monitor_subsys[ i ]->mss_ndn ) ) {
1606                                         return monitor_subsys[ i ];
1607                                 }
1608                         }
1609                 }
1610         }
1611
1612         return NULL;
1613 }
1614
1615 int
1616 monitor_back_initialize(
1617         BackendInfo     *bi )
1618 {
1619         static char             *controls[] = {
1620                 LDAP_CONTROL_MANAGEDSAIT,
1621                 NULL
1622         };
1623
1624         static ConfigTable monitorcfg[] = {
1625                 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
1626                         NULL, NULL, NULL, NULL }
1627         };
1628
1629         static ConfigOCs monitorocs[] = {
1630                 { "( OLcfgDbOc:4.1 "
1631                         "NAME 'olcMonitorConfig' "
1632                         "DESC 'Monitor backend configuration' "
1633                         "SUP olcDatabaseConfig "
1634                         ")",
1635                                 Cft_Database, monitorcfg },
1636                 { NULL, 0, NULL }
1637         };
1638
1639         struct m_s {
1640                 char    *schema;
1641                 slap_mask_t flags;
1642                 int     offset;
1643         } moc[] = {
1644                 { "( 1.3.6.1.4.1.4203.666.3.16.1 "
1645                         "NAME 'monitor' "
1646                         "DESC 'OpenLDAP system monitoring' "
1647                         "SUP top STRUCTURAL "
1648                         "MUST cn "
1649                         "MAY ( "
1650                                 "description "
1651                                 "$ seeAlso "
1652                                 "$ labeledURI "
1653                                 "$ monitoredInfo "
1654                                 "$ managedInfo "
1655                                 "$ monitorOverlay "
1656                         ") )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1657                         offsetof(monitor_info_t, mi_oc_monitor) },
1658                 { "( 1.3.6.1.4.1.4203.666.3.16.2 "
1659                         "NAME 'monitorServer' "
1660                         "DESC 'Server monitoring root entry' "
1661                         "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1662                         offsetof(monitor_info_t, mi_oc_monitorServer) },
1663                 { "( 1.3.6.1.4.1.4203.666.3.16.3 "
1664                         "NAME 'monitorContainer' "
1665                         "DESC 'monitor container class' "
1666                         "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1667                         offsetof(monitor_info_t, mi_oc_monitorContainer) },
1668                 { "( 1.3.6.1.4.1.4203.666.3.16.4 "
1669                         "NAME 'monitorCounterObject' "
1670                         "DESC 'monitor counter class' "
1671                         "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1672                         offsetof(monitor_info_t, mi_oc_monitorCounterObject) },
1673                 { "( 1.3.6.1.4.1.4203.666.3.16.5 "
1674                         "NAME 'monitorOperation' "
1675                         "DESC 'monitor operation class' "
1676                         "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1677                         offsetof(monitor_info_t, mi_oc_monitorOperation) },
1678                 { "( 1.3.6.1.4.1.4203.666.3.16.6 "
1679                         "NAME 'monitorConnection' "
1680                         "DESC 'monitor connection class' "
1681                         "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1682                         offsetof(monitor_info_t, mi_oc_monitorConnection) },
1683                 { "( 1.3.6.1.4.1.4203.666.3.16.7 "
1684                         "NAME 'managedObject' "
1685                         "DESC 'monitor managed entity class' "
1686                         "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1687                         offsetof(monitor_info_t, mi_oc_managedObject) },
1688                 { "( 1.3.6.1.4.1.4203.666.3.16.8 "
1689                         "NAME 'monitoredObject' "
1690                         "DESC 'monitor monitored entity class' "
1691                         "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
1692                         offsetof(monitor_info_t, mi_oc_monitoredObject) },
1693                 { NULL, 0, -1 }
1694         }, mat[] = {
1695                 { "( 1.3.6.1.4.1.4203.666.1.55.1 "
1696                         "NAME 'monitoredInfo' "
1697                         "DESC 'monitored info' "
1698                         /* "SUP name " */
1699                         "EQUALITY caseIgnoreMatch "
1700                         "SUBSTR caseIgnoreSubstringsMatch "
1701                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} "
1702                         "NO-USER-MODIFICATION "
1703                         "USAGE dSAOperation )", SLAP_AT_HIDE,
1704                         offsetof(monitor_info_t, mi_ad_monitoredInfo) },
1705                 { "( 1.3.6.1.4.1.4203.666.1.55.2 "
1706                         "NAME 'managedInfo' "
1707                         "DESC 'monitor managed info' "
1708                         "SUP name )", SLAP_AT_HIDE,
1709                         offsetof(monitor_info_t, mi_ad_managedInfo) },
1710                 { "( 1.3.6.1.4.1.4203.666.1.55.3 "
1711                         "NAME 'monitorCounter' "
1712                         "DESC 'monitor counter' "
1713                         "EQUALITY integerMatch "
1714                         "ORDERING integerOrderingMatch "
1715                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 "
1716                         "NO-USER-MODIFICATION "
1717                         "USAGE dSAOperation )", SLAP_AT_HIDE,
1718                         offsetof(monitor_info_t, mi_ad_monitorCounter) },
1719                 { "( 1.3.6.1.4.1.4203.666.1.55.4 "
1720                         "NAME 'monitorOpCompleted' "
1721                         "DESC 'monitor completed operations' "
1722                         "SUP monitorCounter "
1723                         "NO-USER-MODIFICATION "
1724                         "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1725                         offsetof(monitor_info_t, mi_ad_monitorOpCompleted) },
1726                 { "( 1.3.6.1.4.1.4203.666.1.55.5 "
1727                         "NAME 'monitorOpInitiated' "
1728                         "DESC 'monitor initiated operations' "
1729                         "SUP monitorCounter "
1730                         "NO-USER-MODIFICATION "
1731                         "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1732                         offsetof(monitor_info_t, mi_ad_monitorOpInitiated) },
1733                 { "( 1.3.6.1.4.1.4203.666.1.55.6 "
1734                         "NAME 'monitorConnectionNumber' "
1735                         "DESC 'monitor connection number' "
1736                         "SUP monitorCounter "
1737                         "NO-USER-MODIFICATION "
1738                         "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1739                         offsetof(monitor_info_t, mi_ad_monitorConnectionNumber) },
1740                 { "( 1.3.6.1.4.1.4203.666.1.55.7 "
1741                         "NAME 'monitorConnectionAuthzDN' "
1742                         "DESC 'monitor connection authorization DN' "
1743                         /* "SUP distinguishedName " */
1744                         "EQUALITY distinguishedNameMatch "
1745                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 "
1746                         "NO-USER-MODIFICATION "
1747                         "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1748                         offsetof(monitor_info_t, mi_ad_monitorConnectionAuthzDN) },
1749                 { "( 1.3.6.1.4.1.4203.666.1.55.8 "
1750                         "NAME 'monitorConnectionLocalAddress' "
1751                         "DESC 'monitor connection local address' "
1752                         "SUP monitoredInfo "
1753                         "NO-USER-MODIFICATION "
1754                         "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1755                         offsetof(monitor_info_t, mi_ad_monitorConnectionLocalAddress) },
1756                 { "( 1.3.6.1.4.1.4203.666.1.55.9 "
1757                         "NAME 'monitorConnectionPeerAddress' "
1758                         "DESC 'monitor connection peer address' "
1759                         "SUP monitoredInfo "
1760                         "NO-USER-MODIFICATION "
1761                         "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1762                         offsetof(monitor_info_t, mi_ad_monitorConnectionPeerAddress) },
1763                 { "( 1.3.6.1.4.1.4203.666.1.55.10 "
1764                         "NAME 'monitorTimestamp' "
1765                         "DESC 'monitor timestamp' "
1766                         "EQUALITY generalizedTimeMatch "
1767                         "ORDERING generalizedTimeOrderingMatch "
1768                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 "
1769                         "SINGLE-VALUE "
1770                         "NO-USER-MODIFICATION "
1771                         "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1772                         offsetof(monitor_info_t, mi_ad_monitorTimestamp) },
1773                 { "( 1.3.6.1.4.1.4203.666.1.55.11 "
1774                         "NAME 'monitorOverlay' "
1775                         "DESC 'name of overlays defined for a given database' "
1776                         "SUP monitoredInfo "
1777                         "NO-USER-MODIFICATION "
1778                         "USAGE dSAOperation )", SLAP_AT_HIDE,
1779                         offsetof(monitor_info_t, mi_ad_monitorOverlay) },
1780                 { "( 1.3.6.1.4.1.4203.666.1.55.12 "
1781                         "NAME 'readOnly' "
1782                         "DESC 'read/write status of a given database' "
1783                         "EQUALITY booleanMatch "
1784                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1785                         "SINGLE-VALUE "
1786                         "USAGE dSAOperation )", SLAP_AT_HIDE,
1787                         offsetof(monitor_info_t, mi_ad_readOnly) },
1788                 { "( 1.3.6.1.4.1.4203.666.1.55.13 "
1789                         "NAME 'restrictedOperation' "
1790                         "DESC 'name of restricted operation for a given database' "
1791                         "SUP managedInfo )", SLAP_AT_HIDE,
1792                         offsetof(monitor_info_t, mi_ad_restrictedOperation ) },
1793                 { "( 1.3.6.1.4.1.4203.666.1.55.14 "
1794                         "NAME 'monitorConnectionProtocol' "
1795                         "DESC 'monitor connection protocol' "
1796                         "SUP monitoredInfo "
1797                         "NO-USER-MODIFICATION "
1798                         "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1799                         offsetof(monitor_info_t, mi_ad_monitorConnectionProtocol) },
1800                 { "( 1.3.6.1.4.1.4203.666.1.55.15 "
1801                         "NAME 'monitorConnectionOpsReceived' "
1802                         "DESC 'monitor number of operations received by the connection' "
1803                         "SUP monitorCounter "
1804                         "NO-USER-MODIFICATION "
1805                         "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1806                         offsetof(monitor_info_t, mi_ad_monitorConnectionOpsReceived) },
1807                 { "( 1.3.6.1.4.1.4203.666.1.55.16 "
1808                         "NAME 'monitorConnectionOpsExecuting' "
1809                         "DESC 'monitor number of operations in execution within the connection' "
1810                         "SUP monitorCounter "
1811                         "NO-USER-MODIFICATION "
1812                         "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1813                         offsetof(monitor_info_t, mi_ad_monitorConnectionOpsExecuting) },
1814                 { "( 1.3.6.1.4.1.4203.666.1.55.17 "
1815                         "NAME 'monitorConnectionOpsPending' "
1816                         "DESC 'monitor number of pending operations within the connection' "
1817                         "SUP monitorCounter "
1818                         "NO-USER-MODIFICATION "
1819                         "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1820                         offsetof(monitor_info_t, mi_ad_monitorConnectionOpsPending) },
1821                 { "( 1.3.6.1.4.1.4203.666.1.55.18 "
1822                         "NAME 'monitorConnectionOpsCompleted' "
1823                         "DESC 'monitor number of operations completed within the connection' "
1824                         "SUP monitorCounter "
1825                         "NO-USER-MODIFICATION "
1826                         "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1827                         offsetof(monitor_info_t, mi_ad_monitorConnectionOpsCompleted) },
1828                 { "( 1.3.6.1.4.1.4203.666.1.55.19 "
1829                         "NAME 'monitorConnectionGet' "
1830                         "DESC 'number of times connection_get() was called so far' "
1831                         "SUP monitorCounter "
1832                         "NO-USER-MODIFICATION "
1833                         "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1834                         offsetof(monitor_info_t, mi_ad_monitorConnectionGet) },
1835                 { "( 1.3.6.1.4.1.4203.666.1.55.20 "
1836                         "NAME 'monitorConnectionRead' "
1837                         "DESC 'number of times connection_read() was called so far' "
1838                         "SUP monitorCounter "
1839                         "NO-USER-MODIFICATION "
1840                         "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1841                         offsetof(monitor_info_t, mi_ad_monitorConnectionRead) },
1842                 { "( 1.3.6.1.4.1.4203.666.1.55.21 "
1843                         "NAME 'monitorConnectionWrite' "
1844                         "DESC 'number of times connection_write() was called so far' "
1845                         "SUP monitorCounter "
1846                         "NO-USER-MODIFICATION "
1847                         "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1848                         offsetof(monitor_info_t, mi_ad_monitorConnectionWrite) },
1849                 { "( 1.3.6.1.4.1.4203.666.1.55.22 "
1850                         "NAME 'monitorConnectionMask' "
1851                         "DESC 'monitor connection mask' "
1852                         "SUP monitoredInfo "
1853                         "NO-USER-MODIFICATION "
1854                         "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1855                         offsetof(monitor_info_t, mi_ad_monitorConnectionMask) },
1856                 { "( 1.3.6.1.4.1.4203.666.1.55.23 "
1857                         "NAME 'monitorConnectionListener' "
1858                         "DESC 'monitor connection listener' "
1859                         "SUP monitoredInfo "
1860                         "NO-USER-MODIFICATION "
1861                         "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1862                         offsetof(monitor_info_t, mi_ad_monitorConnectionListener) },
1863                 { "( 1.3.6.1.4.1.4203.666.1.55.24 "
1864                         "NAME 'monitorConnectionPeerDomain' "
1865                         "DESC 'monitor connection peer domain' "
1866                         "SUP monitoredInfo "
1867                         "NO-USER-MODIFICATION "
1868                         "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1869                         offsetof(monitor_info_t, mi_ad_monitorConnectionPeerDomain) },
1870                 { "( 1.3.6.1.4.1.4203.666.1.55.25 "
1871                         "NAME 'monitorConnectionStartTime' "
1872                         "DESC 'monitor connection start time' "
1873                         "SUP monitorTimestamp "
1874                         "SINGLE-VALUE "
1875                         "NO-USER-MODIFICATION "
1876                         "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1877                         offsetof(monitor_info_t, mi_ad_monitorConnectionStartTime) },
1878                 { "( 1.3.6.1.4.1.4203.666.1.55.26 "
1879                         "NAME 'monitorConnectionActivityTime' "
1880                         "DESC 'monitor connection activity time' "
1881                         "SUP monitorTimestamp "
1882                         "SINGLE-VALUE "
1883                         "NO-USER-MODIFICATION "
1884                         "USAGE dSAOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1885                         offsetof(monitor_info_t, mi_ad_monitorConnectionActivityTime) },
1886                 { "( 1.3.6.1.4.1.4203.666.1.55.27 "
1887                         "NAME 'monitorIsShadow' "
1888                         "DESC 'TRUE if the database is shadow' "
1889                         "EQUALITY booleanMatch "
1890                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1891                         "SINGLE-VALUE "
1892                         "USAGE dSAOperation )", SLAP_AT_HIDE,
1893                         offsetof(monitor_info_t, mi_ad_monitorIsShadow) },
1894                 { "( 1.3.6.1.4.1.4203.666.1.55.28 "
1895                         "NAME 'monitorUpdateRef' "
1896                         "DESC 'update referral for shadow databases' "
1897                         "SUP monitoredInfo "
1898                         "SINGLE-VALUE "
1899                         "USAGE dSAOperation )", SLAP_AT_HIDE,
1900                         offsetof(monitor_info_t, mi_ad_monitorUpdateRef) },
1901                 { "( 1.3.6.1.4.1.4203.666.1.55.29 "
1902                         "NAME 'monitorRuntimeConfig' "
1903                         "DESC 'TRUE if component allows runtime configuration' "
1904                         "EQUALITY booleanMatch "
1905                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1906                         "SINGLE-VALUE "
1907                         "USAGE dSAOperation )", SLAP_AT_HIDE,
1908                         offsetof(monitor_info_t, mi_ad_monitorRuntimeConfig) },
1909                 { NULL, 0, -1 }
1910         };
1911
1912         static struct {
1913                 char                    *name;
1914                 char                    *oid;
1915         }               s_oid[] = {
1916                 { "olmAttributes",                      "1.3.6.1.4.1.4203.666.1.55" },
1917                 { "olmSubSystemAttributes",             "olmAttributes:0" },
1918                 { "olmGenericAttributes",               "olmSubSystemAttributes:0" },
1919                 { "olmDatabaseAttributes",              "olmSubSystemAttributes:1" },
1920
1921                 /* for example, back-bdb specific attrs
1922                  * are in "olmDatabaseAttributes:1"
1923                  *
1924                  * NOTE: developers, please record here OID assignments
1925                  * for other modules */
1926
1927                 { "olmObjectClasses",                   "1.3.6.1.4.1.4203.666.3.16" },
1928                 { "olmSubSystemObjectClasses",          "olmObjectClasses:0" },
1929                 { "olmGenericObjectClasses",            "olmSubSystemObjectClasses:0" },
1930                 { "olmDatabaseObjectClasses",           "olmSubSystemObjectClasses:1" },
1931
1932                 /* for example, back-bdb specific objectClasses
1933                  * are in "olmDatabaseObjectClasses:1"
1934                  *
1935                  * NOTE: developers, please record here OID assignments
1936                  * for other modules */
1937
1938                 { NULL }
1939         };
1940
1941         int                     i, rc;
1942         monitor_info_t          *mi = &monitor_info;
1943         ConfigArgs c;
1944         char    *argv[ 3 ];
1945
1946         argv[ 0 ] = "monitor";
1947         c.argv = argv;
1948         c.argc = 3;
1949         c.fname = argv[0];
1950
1951         for ( i = 0; s_oid[ i ].name; i++ ) {
1952                 argv[ 1 ] = s_oid[ i ].name;
1953                 argv[ 2 ] = s_oid[ i ].oid;
1954
1955                 if ( parse_oidm( &c, 0, NULL ) != 0 ) {
1956                         Debug( LDAP_DEBUG_ANY,
1957                                 "monitor_back_initialize: unable to add "
1958                                 "objectIdentifier \"%s=%s\"\n",
1959                                 s_oid[ i ].name, s_oid[ i ].oid, 0 );
1960                         return 1;
1961                 }
1962         }
1963
1964         /* schema integration */
1965         for ( i = 0; mat[ i ].schema; i++ ) {
1966                 int                     code;
1967                 AttributeDescription **ad =
1968                         ((AttributeDescription **)&(((char *)mi)[ mat[ i ].offset ]));
1969
1970                 *ad = NULL;
1971                 code = register_at( mat[ i ].schema, ad, 0 );
1972
1973                 if ( code ) {
1974                         Debug( LDAP_DEBUG_ANY,
1975                                 "monitor_back_db_init: register_at failed\n", 0, 0, 0 );
1976                         return -1;
1977                 }
1978                 (*ad)->ad_type->sat_flags |= mat[ i ].flags;
1979         }
1980
1981         for ( i = 0; moc[ i ].schema; i++ ) {
1982                 int                     code;
1983                 ObjectClass             **Oc =
1984                         ((ObjectClass **)&(((char *)mi)[ moc[ i ].offset ]));
1985
1986                 code = register_oc( moc[ i ].schema, Oc, 0 );
1987                 if ( code ) {
1988                         Debug( LDAP_DEBUG_ANY,
1989                                 "monitor_back_db_init: register_oc failed\n", 0, 0, 0 );
1990                         return -1;
1991                 }
1992                 (*Oc)->soc_flags |= moc[ i ].flags;
1993         }
1994
1995         bi->bi_controls = controls;
1996
1997         bi->bi_init = 0;
1998         bi->bi_open = 0;
1999         bi->bi_config = monitor_back_config;
2000         bi->bi_close = 0;
2001         bi->bi_destroy = 0;
2002
2003         bi->bi_db_init = monitor_back_db_init;
2004 #if 0
2005         bi->bi_db_config = monitor_back_db_config;
2006 #endif
2007         bi->bi_db_open = monitor_back_db_open;
2008         bi->bi_db_close = 0;
2009         bi->bi_db_destroy = monitor_back_db_destroy;
2010
2011         bi->bi_op_bind = monitor_back_bind;
2012         bi->bi_op_unbind = 0;
2013         bi->bi_op_search = monitor_back_search;
2014         bi->bi_op_compare = monitor_back_compare;
2015         bi->bi_op_modify = monitor_back_modify;
2016         bi->bi_op_modrdn = 0;
2017         bi->bi_op_add = 0;
2018         bi->bi_op_delete = 0;
2019         bi->bi_op_abandon = 0;
2020
2021         bi->bi_extended = 0;
2022
2023         bi->bi_entry_release_rw = 0;
2024         bi->bi_chk_referrals = 0;
2025         bi->bi_operational = monitor_back_operational;
2026
2027         /*
2028          * hooks for slap tools
2029          */
2030         bi->bi_tool_entry_open = 0;
2031         bi->bi_tool_entry_close = 0;
2032         bi->bi_tool_entry_first = 0;
2033         bi->bi_tool_entry_next = 0;
2034         bi->bi_tool_entry_get = 0;
2035         bi->bi_tool_entry_put = 0;
2036         bi->bi_tool_entry_reindex = 0;
2037         bi->bi_tool_sync = 0;
2038         bi->bi_tool_dn2id_get = 0;
2039         bi->bi_tool_entry_modify = 0;
2040
2041         bi->bi_connection_init = 0;
2042         bi->bi_connection_destroy = 0;
2043
2044         bi->bi_extra = (void *)&monitor_extra;
2045
2046         /*
2047          * configuration objectClasses (fake)
2048          */
2049         bi->bi_cf_ocs = monitorocs;
2050
2051         rc = config_register_schema( monitorcfg, monitorocs );
2052         if ( rc ) {
2053                 return rc;
2054         }
2055
2056         return 0;
2057 }
2058
2059 int
2060 monitor_back_db_init(
2061         BackendDB       *be,
2062         ConfigReply     *c)
2063 {
2064         int                     rc;
2065         struct berval           dn = BER_BVC( SLAPD_MONITOR_DN ),
2066                                 pdn,
2067                                 ndn;
2068         BackendDB               *be2;
2069
2070         monitor_subsys_t        *ms;
2071
2072         /*
2073          * database monitor can be defined once only
2074          */
2075         if ( be_monitor != NULL ) {
2076                 if (c) {
2077                         snprintf(c->msg, sizeof(c->msg),"only one monitor database allowed");
2078                 }
2079                 return( -1 );
2080         }
2081         be_monitor = be;
2082
2083         /*
2084          * register subsys
2085          */
2086         for ( ms = known_monitor_subsys; ms->mss_name != NULL; ms++ ) {
2087                 if ( monitor_back_register_subsys( ms ) ) {
2088                         return -1;
2089                 }
2090         }
2091
2092         /* indicate system schema supported */
2093         SLAP_BFLAGS(be) |= SLAP_BFLAG_MONITOR;
2094
2095         rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn, NULL );
2096         if( rc != LDAP_SUCCESS ) {
2097                 Debug( LDAP_DEBUG_ANY,
2098                         "unable to normalize/pretty monitor DN \"%s\" (%d)\n",
2099                         dn.bv_val, rc, 0 );
2100                 return -1;
2101         }
2102
2103         ber_bvarray_add( &be->be_suffix, &pdn );
2104         ber_bvarray_add( &be->be_nsuffix, &ndn );
2105
2106         /* NOTE: only one monitor database is allowed,
2107          * so we use static storage */
2108         ldap_pvt_thread_mutex_init( &monitor_info.mi_cache_mutex );
2109
2110         be->be_private = &monitor_info;
2111
2112         be2 = select_backend( &ndn, 0 );
2113         if ( be2 != be ) {
2114                 char    *type = be2->bd_info->bi_type;
2115
2116                 if ( overlay_is_over( be2 ) ) {
2117                         slap_overinfo   *oi = (slap_overinfo *)be2->bd_info->bi_private;
2118                         type = oi->oi_orig->bi_type;
2119                 }
2120
2121                 if (c) {
2122                         snprintf(c->msg, sizeof(c->msg),
2123                                         "\"monitor\" database serving namingContext \"%s\" "
2124                                         "is hidden by \"%s\" database serving namingContext \"%s\".\n",
2125                                         pdn.bv_val, type, be2->be_nsuffix[ 0 ].bv_val );
2126                 }
2127                 return -1;
2128         }
2129
2130         return 0;
2131 }
2132
2133 static void
2134 monitor_back_destroy_limbo_entry(
2135         entry_limbo_t   *el,
2136         int             dispose )
2137 {
2138         if ( el->el_e ) {
2139                 entry_free( el->el_e );
2140         }
2141         if ( el->el_a ) {
2142                 attrs_free( el->el_a );
2143         }
2144         if ( !BER_BVISNULL( &el->el_ndn ) ) {
2145                 ber_memfree( el->el_ndn.bv_val );
2146         }
2147         if ( !BER_BVISNULL( &el->el_nbase ) ) {
2148                 ber_memfree( el->el_nbase.bv_val );
2149         }
2150         if ( !BER_BVISNULL( &el->el_filter ) ) {
2151                 ber_memfree( el->el_filter.bv_val );
2152         }
2153
2154         /* NOTE: callbacks are not copied; so only free them
2155          * if disposing of */
2156         if ( el->el_cb && dispose != 0 ) {
2157                 monitor_callback_t *next;
2158
2159                 for ( ; el->el_cb; el->el_cb = next ) {
2160                         next = el->el_cb->mc_next;
2161                         if ( el->el_cb->mc_dispose ) {
2162                                 el->el_cb->mc_dispose( &el->el_cb->mc_private );
2163                         }
2164                         ch_free( el->el_cb );
2165                 }
2166         }
2167
2168         ch_free( el );
2169 }
2170
2171 int
2172 monitor_back_db_open(
2173         BackendDB       *be,
2174         ConfigReply     *cr)
2175 {
2176         monitor_info_t          *mi = (monitor_info_t *)be->be_private;
2177         struct monitor_subsys_t **ms;
2178         Entry                   *e, **ep, *root;
2179         monitor_entry_t         *mp;
2180         int                     i;
2181         struct berval           bv, rdn = BER_BVC(SLAPD_MONITOR_DN);
2182         struct tm               *tms;
2183 #ifdef HAVE_GMTIME_R
2184         struct tm               tm_buf;
2185 #endif
2186         static char             tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
2187         struct berval   desc[] = {
2188                 BER_BVC("This subtree contains monitoring/managing objects."),
2189                 BER_BVC("This object contains information about this server."),
2190                 BER_BVC("Most of the information is held in operational"
2191                 " attributes, which must be explicitly requested."),
2192                 BER_BVNULL };
2193
2194         int                     retcode = 0;
2195
2196         assert( be_monitor != NULL );
2197         if ( be != be_monitor ) {
2198                 be_monitor = be;
2199         }
2200
2201         /*
2202          * Start
2203          */
2204 #ifndef HAVE_GMTIME_R
2205         ldap_pvt_thread_mutex_lock( &gmtime_mutex );
2206 #endif
2207 #ifdef HACK_LOCAL_TIME
2208 # ifdef HAVE_LOCALTIME_R
2209         tms = localtime_r( &starttime, &tm_buf );
2210 # else
2211         tms = localtime( &starttime );
2212 # endif /* HAVE_LOCALTIME_R */
2213         lutil_localtime( tmbuf, sizeof(tmbuf), tms, -timezone );
2214 #else /* !HACK_LOCAL_TIME */
2215 # ifdef HAVE_GMTIME_R
2216         tms = gmtime_r( &starttime, &tm_buf );
2217 # else
2218         tms = gmtime( &starttime );
2219 # endif /* HAVE_GMTIME_R */
2220         lutil_gentime( tmbuf, sizeof(tmbuf), tms );
2221 #endif /* !HACK_LOCAL_TIME */
2222 #ifndef HAVE_GMTIME_R
2223         ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
2224 #endif
2225
2226         mi->mi_startTime.bv_val = tmbuf;
2227         mi->mi_startTime.bv_len = strlen( tmbuf );
2228
2229         if ( BER_BVISEMPTY( &be->be_rootdn ) ) {
2230                 BER_BVSTR( &mi->mi_creatorsName, SLAPD_ANONYMOUS );
2231                 BER_BVSTR( &mi->mi_ncreatorsName, SLAPD_ANONYMOUS );
2232         } else {
2233                 mi->mi_creatorsName = be->be_rootdn;
2234                 mi->mi_ncreatorsName = be->be_rootndn;
2235         }
2236
2237         /*
2238          * creates the "cn=Monitor" entry 
2239          */
2240         e = monitor_entry_stub( NULL, NULL, &rdn, mi->mi_oc_monitorServer, mi,
2241                 NULL, NULL );
2242
2243         if ( e == NULL) {
2244                 Debug( LDAP_DEBUG_ANY,
2245                         "unable to create \"%s\" entry\n",
2246                         SLAPD_MONITOR_DN, 0, 0 );
2247                 return( -1 );
2248         }
2249
2250         attr_merge_normalize( e, slap_schema.si_ad_description, desc, NULL );
2251
2252         bv.bv_val = strchr( (char *) Versionstr, '$' );
2253         if ( bv.bv_val != NULL ) {
2254                 char    *end;
2255
2256                 bv.bv_val++;
2257                 for ( ; bv.bv_val[ 0 ] == ' '; bv.bv_val++ )
2258                         ;
2259
2260                 end = strchr( bv.bv_val, '$' );
2261                 if ( end != NULL ) {
2262                         end--;
2263
2264                         for ( ; end > bv.bv_val && end[ 0 ] == ' '; end-- )
2265                                 ;
2266
2267                         end++;
2268
2269                         bv.bv_len = end - bv.bv_val;
2270
2271                 } else {
2272                         bv.bv_len = strlen( bv.bv_val );
2273                 }
2274
2275                 if ( attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo,
2276                                         &bv, NULL ) ) {
2277                         Debug( LDAP_DEBUG_ANY,
2278                                 "unable to add monitoredInfo to \"%s\" entry\n",
2279                                 SLAPD_MONITOR_DN, 0, 0 );
2280                         return( -1 );
2281                 }
2282         }
2283
2284         mp = monitor_entrypriv_create();
2285         if ( mp == NULL ) {
2286                 return -1;
2287         }
2288         e->e_private = ( void * )mp;
2289         ep = &mp->mp_children;
2290
2291         if ( monitor_cache_add( mi, e ) ) {
2292                 Debug( LDAP_DEBUG_ANY,
2293                         "unable to add entry \"%s\" to cache\n",
2294                         SLAPD_MONITOR_DN, 0, 0 );
2295                 return -1;
2296         }
2297         root = e;
2298
2299         /*      
2300          * Create all the subsystem specific entries
2301          */
2302         for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
2303                 int             len = strlen( monitor_subsys[ i ]->mss_name );
2304                 struct berval   dn;
2305                 int             rc;
2306
2307                 dn.bv_len = len + sizeof( "cn=" ) - 1;
2308                 dn.bv_val = ch_calloc( sizeof( char ), dn.bv_len + 1 );
2309                 strcpy( dn.bv_val, "cn=" );
2310                 strcat( dn.bv_val, monitor_subsys[ i ]->mss_name );
2311                 rc = dnPretty( NULL, &dn, &monitor_subsys[ i ]->mss_rdn, NULL );
2312                 free( dn.bv_val );
2313                 if ( rc != LDAP_SUCCESS ) {
2314                         Debug( LDAP_DEBUG_ANY,
2315                                 "monitor RDN \"%s\" is invalid\n", 
2316                                 dn.bv_val, 0, 0 );
2317                         return( -1 );
2318                 }
2319
2320                 e = monitor_entry_stub( &root->e_name, &root->e_nname,
2321                         &monitor_subsys[ i ]->mss_rdn, mi->mi_oc_monitorContainer, mi,
2322                         NULL, NULL );
2323
2324                 if ( e == NULL) {
2325                         Debug( LDAP_DEBUG_ANY,
2326                                 "unable to create \"%s\" entry\n", 
2327                                 monitor_subsys[ i ]->mss_dn.bv_val, 0, 0 );
2328                         return( -1 );
2329                 }
2330                 monitor_subsys[i]->mss_dn = e->e_name;
2331                 monitor_subsys[i]->mss_ndn = e->e_nname;
2332
2333                 if ( !BER_BVISNULL( &monitor_subsys[ i ]->mss_desc[ 0 ] ) ) {
2334                         attr_merge_normalize( e, slap_schema.si_ad_description,
2335                                         monitor_subsys[ i ]->mss_desc, NULL );
2336                 }
2337
2338                 mp = monitor_entrypriv_create();
2339                 if ( mp == NULL ) {
2340                         return -1;
2341                 }
2342                 e->e_private = ( void * )mp;
2343                 mp->mp_info = monitor_subsys[ i ];
2344                 mp->mp_flags = monitor_subsys[ i ]->mss_flags;
2345
2346                 if ( monitor_cache_add( mi, e ) ) {
2347                         Debug( LDAP_DEBUG_ANY,
2348                                 "unable to add entry \"%s\" to cache\n",
2349                                 monitor_subsys[ i ]->mss_dn.bv_val, 0, 0 );
2350                         return -1;
2351                 }
2352
2353                 *ep = e;
2354                 ep = &mp->mp_next;
2355         }
2356
2357         assert( be != NULL );
2358
2359         be->be_private = mi;
2360         
2361         /*
2362          * opens the monitor backend subsystems
2363          */
2364         for ( ms = monitor_subsys; ms[ 0 ] != NULL; ms++ ) {
2365                 if ( ms[ 0 ]->mss_open && ( *ms[ 0 ]->mss_open )( be, ms[ 0 ] ) )
2366                 {
2367                         return( -1 );
2368                 }
2369                 ms[ 0 ]->mss_flags |= MONITOR_F_OPENED;
2370         }
2371
2372         monitor_subsys_opened = 1;
2373
2374         if ( mi->mi_entry_limbo ) {
2375                 entry_limbo_t   *el = mi->mi_entry_limbo;
2376
2377                 for ( ; el; ) {
2378                         entry_limbo_t   *tmp;
2379                         int             rc;
2380
2381                         switch ( el->el_type ) {
2382                         case LIMBO_ENTRY:
2383                                 rc = monitor_back_register_entry(
2384                                                 el->el_e,
2385                                                 el->el_cb,
2386                                                 el->el_mss,
2387                                                 el->el_flags );
2388                                 break;
2389
2390                         case LIMBO_ENTRY_PARENT:
2391                                 rc = monitor_back_register_entry_parent(
2392                                                 el->el_e,
2393                                                 el->el_cb,
2394                                                 el->el_mss,
2395                                                 el->el_flags,
2396                                                 &el->el_nbase,
2397                                                 el->el_scope,
2398                                                 &el->el_filter );
2399                                 break;
2400                                 
2401
2402                         case LIMBO_ATTRS:
2403                                 rc = monitor_back_register_entry_attrs(
2404                                                 &el->el_ndn,
2405                                                 el->el_a,
2406                                                 el->el_cb,
2407                                                 &el->el_nbase,
2408                                                 el->el_scope,
2409                                                 &el->el_filter );
2410                                 break;
2411
2412                         case LIMBO_CB:
2413                                 rc = monitor_back_register_entry_callback(
2414                                                 &el->el_ndn,
2415                                                 el->el_cb,
2416                                                 &el->el_nbase,
2417                                                 el->el_scope,
2418                                                 &el->el_filter );
2419                                 break;
2420
2421                         case LIMBO_BACKEND:
2422                                 rc = monitor_back_register_backend( el->el_bi );
2423                                 break;
2424
2425                         case LIMBO_DATABASE:
2426                                 rc = monitor_back_register_database( el->el_be );
2427                                 break;
2428
2429                         case LIMBO_OVERLAY_INFO:
2430                                 rc = monitor_back_register_overlay_info( el->el_on );
2431                                 break;
2432
2433                         case LIMBO_OVERLAY:
2434                                 rc = monitor_back_register_overlay( el->el_be );
2435                                 break;
2436
2437                         default:
2438                                 assert( 0 );
2439                         }
2440
2441                         tmp = el;
2442                         el = el->el_next;
2443                         monitor_back_destroy_limbo_entry( tmp, rc );
2444
2445                         if ( rc != 0 ) {
2446                                 /* try all, but report error at end */
2447                                 retcode = 1;
2448                         }
2449                 }
2450
2451                 mi->mi_entry_limbo = NULL;
2452         }
2453
2454         return retcode;
2455 }
2456
2457 int
2458 monitor_back_config(
2459         BackendInfo     *bi,
2460         const char      *fname,
2461         int             lineno,
2462         int             argc,
2463         char            **argv )
2464 {
2465         /*
2466          * eventually, will hold backend specific configuration parameters
2467          */
2468         return SLAP_CONF_UNKNOWN;
2469 }
2470
2471 #if 0
2472 int
2473 monitor_back_db_config(
2474         Backend     *be,
2475         const char  *fname,
2476         int         lineno,
2477         int         argc,
2478         char        **argv )
2479 {
2480         monitor_info_t  *mi = ( monitor_info_t * )be->be_private;
2481
2482         /*
2483          * eventually, will hold database specific configuration parameters
2484          */
2485         return SLAP_CONF_UNKNOWN;
2486 }
2487 #endif
2488
2489 int
2490 monitor_back_db_destroy(
2491         BackendDB       *be,
2492         ConfigReply     *cr)
2493 {
2494         monitor_info_t  *mi = ( monitor_info_t * )be->be_private;
2495
2496         if ( mi == NULL ) {
2497                 return -1;
2498         }
2499
2500         /*
2501          * FIXME: destroys all the data
2502          */
2503         /* NOTE: mi points to static storage; don't free it */
2504         
2505         (void)monitor_cache_destroy( mi );
2506
2507         if ( monitor_subsys ) {
2508                 int     i;
2509
2510                 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
2511                         if ( monitor_subsys[ i ]->mss_destroy ) {
2512                                 monitor_subsys[ i ]->mss_destroy( be, monitor_subsys[ i ] );
2513                         }
2514
2515                         if ( !BER_BVISNULL( &monitor_subsys[ i ]->mss_rdn ) ) {
2516                                 ch_free( monitor_subsys[ i ]->mss_rdn.bv_val );
2517                         }
2518                 }
2519
2520                 ch_free( monitor_subsys );
2521         }
2522
2523         if ( mi->mi_entry_limbo ) {
2524                 entry_limbo_t   *el = mi->mi_entry_limbo;
2525
2526                 for ( ; el; ) {
2527                         entry_limbo_t *tmp = el;
2528                         el = el->el_next;
2529                         monitor_back_destroy_limbo_entry( tmp, 1 );
2530                 }
2531         }
2532         
2533         ldap_pvt_thread_mutex_destroy( &monitor_info.mi_cache_mutex );
2534
2535         be->be_private = NULL;
2536
2537         return 0;
2538 }
2539
2540 #if SLAPD_MONITOR == SLAPD_MOD_DYNAMIC
2541
2542 /* conditionally define the init_module() function */
2543 SLAP_BACKEND_INIT_MODULE( monitor )
2544
2545 #endif /* SLAPD_MONITOR == SLAPD_MOD_DYNAMIC */
2546