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