]> git.sur5r.net Git - openldap/blob - servers/slapd/back-monitor/init.c
plug more one-time leaks; rearrange subsystems setup
[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-2005 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 #undef INTEGRATE_CORE_SCHEMA
34
35 /*
36  * used by many functions to add description to entries
37  *
38  * WARNING: be_monitor may change as new databases are added,
39  * so it should not be used outside monitor_back_db_init()
40  * until monitor_back_db_open is called.
41  */
42 BackendDB                       *be_monitor;
43
44 static struct monitor_subsys_t  **monitor_subsys;
45 static int                      monitor_subsys_opened;
46 static monitor_info_t           monitor_info;
47
48 /*
49  * subsystem data
50  *
51  * the known subsystems are added to the subsystems
52  * array at backend initialization; other subsystems
53  * may be added by calling monitor_back_register_subsys()
54  * before the database is opened (e.g. by other backends
55  * or by overlays or modules).
56  */
57 static struct monitor_subsys_t known_monitor_subsys[] = {
58         { 
59                 SLAPD_MONITOR_BACKEND_NAME, 
60                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
61                 { BER_BVC( "This subsystem contains information about available backends." ),
62                         BER_BVNULL },
63                 MONITOR_F_PERSISTENT_CH,
64                 monitor_subsys_backend_init,
65                 NULL,   /* destroy */
66                 NULL,   /* update */
67                 NULL,   /* create */
68                 NULL    /* modify */
69         }, { 
70                 SLAPD_MONITOR_CONN_NAME,
71                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
72                 { BER_BVC( "This subsystem contains information about connections." ),
73                         BER_BVNULL },
74                 MONITOR_F_VOLATILE_CH,
75                 monitor_subsys_conn_init,
76                 NULL,   /* destroy */
77                 NULL,   /* update */
78                 NULL,   /* create */
79                 NULL    /* modify */
80         }, { 
81                 SLAPD_MONITOR_DATABASE_NAME,    
82                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
83                 { BER_BVC( "This subsystem contains information about configured databases." ),
84                         BER_BVNULL },
85                 MONITOR_F_PERSISTENT_CH,
86                 monitor_subsys_database_init,
87                 NULL,   /* destroy */
88                 NULL,   /* update */
89                 NULL,   /* create */
90                 NULL    /* modify */
91         }, { 
92                 SLAPD_MONITOR_LISTENER_NAME,    
93                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
94                 { BER_BVC( "This subsystem contains information about active listeners." ),
95                         BER_BVNULL },
96                 MONITOR_F_PERSISTENT_CH,
97                 monitor_subsys_listener_init,
98                 NULL,   /* destroy */
99                 NULL,   /* update */
100                 NULL,   /* create */
101                 NULL    /* modify */
102         }, { 
103                 SLAPD_MONITOR_LOG_NAME,
104                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
105                 { BER_BVC( "This subsystem contains information about logging." ),
106                         BER_BVC( "Set the attribute \"managedInfo\" to the desired log levels." ),
107                         BER_BVNULL },
108                 MONITOR_F_NONE,
109                 monitor_subsys_log_init,
110                 NULL,   /* destroy */
111                 NULL,   /* update */
112                 NULL,   /* create */
113                 NULL,   /* modify */
114         }, { 
115                 SLAPD_MONITOR_OPS_NAME,
116                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
117                 { BER_BVC( "This subsystem contains information about performed operations." ),
118                         BER_BVNULL },
119                 MONITOR_F_PERSISTENT_CH,
120                 monitor_subsys_ops_init,
121                 NULL,   /* destroy */
122                 NULL,   /* update */
123                 NULL,   /* create */
124                 NULL,   /* modify */
125         }, { 
126                 SLAPD_MONITOR_OVERLAY_NAME,
127                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
128                 { BER_BVC( "This subsystem contains information about available overlays." ),
129                         BER_BVNULL },
130                 MONITOR_F_PERSISTENT_CH,
131                 monitor_subsys_overlay_init,
132                 NULL,   /* destroy */
133                 NULL,   /* update */
134                 NULL,   /* create */
135                 NULL,   /* modify */
136         }, { 
137                 SLAPD_MONITOR_SASL_NAME,        
138                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
139                 { BER_BVC( "This subsystem contains information about SASL." ),
140                         BER_BVNULL },
141                 MONITOR_F_NONE,
142                 NULL,   /* init */
143                 NULL,   /* destroy */
144                 NULL,   /* update */
145                 NULL,   /* create */
146                 NULL    /* modify */
147         }, { 
148                 SLAPD_MONITOR_SENT_NAME,
149                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
150                 { BER_BVC( "This subsystem contains statistics." ),
151                         BER_BVNULL },
152                 MONITOR_F_PERSISTENT_CH,
153                 monitor_subsys_sent_init,
154                 NULL,   /* destroy */
155                 NULL,   /* update */
156                 NULL,   /* create */
157                 NULL,   /* modify */
158         }, { 
159                 SLAPD_MONITOR_THREAD_NAME,      
160                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
161                 { BER_BVC( "This subsystem contains information about threads." ),
162                         BER_BVNULL },
163                 MONITOR_F_PERSISTENT_CH,
164                 monitor_subsys_thread_init,
165                 NULL,   /* destroy */
166                 NULL,   /* update */
167                 NULL,   /* create */
168                 NULL    /* modify */
169         }, { 
170                 SLAPD_MONITOR_TIME_NAME,
171                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
172                 { BER_BVC( "This subsystem contains information about time." ),
173                         BER_BVNULL },
174                 MONITOR_F_PERSISTENT_CH,
175                 monitor_subsys_time_init,
176                 NULL,   /* destroy */
177                 NULL,   /* update */
178                 NULL,   /* create */
179                 NULL,   /* modify */
180         }, { 
181                 SLAPD_MONITOR_TLS_NAME,
182                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
183                 { BER_BVC( "This subsystem contains information about TLS." ),
184                         BER_BVNULL },
185                 MONITOR_F_NONE,
186                 NULL,   /* init */
187                 NULL,   /* destroy */
188                 NULL,   /* update */
189                 NULL,   /* create */
190                 NULL    /* modify */
191         }, { 
192                 SLAPD_MONITOR_RWW_NAME,
193                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
194                 { BER_BVC( "This subsystem contains information about read/write waiters." ),
195                         BER_BVNULL },
196                 MONITOR_F_PERSISTENT_CH,
197                 monitor_subsys_rww_init,
198                 NULL,   /* destroy */
199                 NULL,   /* update */
200                 NULL,   /* create */
201                 NULL    /* modify */
202         }, { NULL }
203 };
204
205 int
206 monitor_back_register_subsys(
207         monitor_subsys_t        *ms )
208 {
209         int     i = 0;
210
211         if ( monitor_subsys ) {
212                 for ( ; monitor_subsys[ i ] != NULL; i++ )
213                         /* just count'em */ ;
214         }
215
216         monitor_subsys = ch_realloc( monitor_subsys,
217                         ( 2 + i ) * sizeof( monitor_subsys_t * ) );
218
219         if ( monitor_subsys == NULL ) {
220                 return -1;
221         }
222
223         monitor_subsys[ i ] = ms;
224         monitor_subsys[ i + 1 ] = NULL;
225
226         /* if a subsystem is registered __AFTER__ subsystem 
227          * initialization (depending on the sequence the databases
228          * are listed in slapd.conf), init it */
229         if ( monitor_subsys_opened ) {
230
231                 /* FIXME: this should only be possible
232                  * if be_monitor is already initialized */
233                 assert( be_monitor != NULL );
234
235                 if ( ms->mss_open && ( *ms->mss_open )( be_monitor, ms ) ) {
236                         return -1;
237                 }
238
239                 ms->mss_flags |= MONITOR_F_OPENED;
240         }
241
242         return 0;
243 }
244
245 enum {
246         LIMBO_ENTRY,
247         LIMBO_ENTRY_PARENT,
248         LIMBO_ATTRS,
249         LIMBO_CB
250 };
251
252 typedef struct entry_limbo_t {
253         int                     el_type;
254         Entry                   *el_e;
255         Attribute               *el_a;
256         struct berval           el_ndn;
257         struct berval           el_base;
258         int                     el_scope;
259         struct berval           el_filter;
260         monitor_callback_t      *el_cb;
261         struct entry_limbo_t    *el_next;
262 } entry_limbo_t;
263
264 int
265 monitor_back_register_entry(
266         Entry                   *e,
267         monitor_callback_t      *cb )
268 {
269         monitor_info_t  *mi = ( monitor_info_t * )be_monitor->be_private;
270
271         assert( mi != NULL );
272         assert( e != NULL );
273         assert( e->e_private == NULL );
274         
275         if ( monitor_subsys_opened ) {
276                 Entry           *e_parent = NULL,
277                                 *e_new = NULL,
278                                 **ep = NULL;
279                 struct berval   pdn = BER_BVNULL;
280                 monitor_entry_t *mp = NULL,
281                                 *mp_parent = NULL;
282                 int             rc = 0;
283
284                 if ( monitor_cache_get( mi, &e->e_nname, &e_parent ) == 0 ) {
285                         /* entry exists */
286                         Debug( LDAP_DEBUG_ANY,
287                                 "monitor_back_register_entry(\"%s\"): "
288                                 "entry exists\n",
289                                 e->e_name.bv_val, 0, 0 );
290                         monitor_cache_release( mi, e_parent );
291                         return -1;
292                 }
293
294                 dnParent( &e->e_nname, &pdn );
295                 if ( monitor_cache_get( mi, &pdn, &e_parent ) != 0 ) {
296                         /* parent does not exist */
297                         Debug( LDAP_DEBUG_ANY,
298                                 "monitor_back_register_entry(\"%s\"): "
299                                 "parent \"%s\" not found\n",
300                                 e->e_name.bv_val, pdn.bv_val, 0 );
301                         return -1;
302                 }
303
304                 assert( e_parent->e_private != NULL );
305                 mp_parent = ( monitor_entry_t * )e_parent->e_private;
306
307                 if ( mp_parent->mp_flags & MONITOR_F_VOLATILE ) {
308                         /* entry is volatile; cannot append children */
309                         Debug( LDAP_DEBUG_ANY,
310                                 "monitor_back_register_entry(\"%s\"): "
311                                 "parent \"%s\" is volatile\n",
312                                 e->e_name.bv_val, e_parent->e_name.bv_val, 0 );
313                         rc = -1;
314                         goto done;
315                 }
316
317                 mp = monitor_entrypriv_create();
318                 if ( mp == NULL ) {
319                         Debug( LDAP_DEBUG_ANY,
320                                 "monitor_back_register_entry(\"%s\"): "
321                                 "monitor_entrypriv_create() failed\n",
322                                 e->e_name.bv_val, 0, 0 );
323                         rc = -1;
324                         goto done;
325                 }
326
327                 e_new = entry_dup( e );
328                 if ( e_new == NULL ) {
329                         Debug( LDAP_DEBUG_ANY,
330                                 "monitor_back_register_entry(\"%s\"): "
331                                 "entry_dup() failed\n",
332                                 e->e_name.bv_val, 0, 0 );
333                         rc = -1;
334                         goto done;
335                 }
336                 
337                 e_new->e_private = ( void * )mp;
338                 mp->mp_info = mp_parent->mp_info;
339                 mp->mp_flags = mp_parent->mp_flags | MONITOR_F_SUB;
340                 mp->mp_cb = cb;
341
342                 ep = &mp_parent->mp_children;
343                 for ( ; *ep; ) {
344                         mp_parent = ( monitor_entry_t * )(*ep)->e_private;
345                         ep = &mp_parent->mp_next;
346                 }
347                 *ep = e_new;
348
349                 if ( monitor_cache_add( mi, e_new ) ) {
350                         Debug( LDAP_DEBUG_ANY,
351                                 "monitor_back_register_entry(\"%s\"): "
352                                 "unable to add entry\n",
353                                 e->e_name.bv_val, 0, 0 );
354                         rc = -1;
355                         goto done;
356                 }
357
358 done:;
359                 if ( rc ) {
360                         if ( mp ) {
361                                 ch_free( mp );
362                         }
363                         if ( e_new ) {
364                                 e_new->e_private = NULL;
365                                 entry_free( e_new );
366                         }
367                 }
368
369                 if ( e_parent ) {
370                         monitor_cache_release( mi, e_parent );
371                 }
372
373         } else {
374                 entry_limbo_t   **elpp, el = { 0 };
375
376                 el.el_type = LIMBO_ENTRY;
377
378                 el.el_e = entry_dup( e );
379                 if ( el.el_e == NULL ) {
380                         Debug( LDAP_DEBUG_ANY,
381                                 "monitor_back_register_entry(\"%s\"): "
382                                 "entry_dup() failed\n",
383                                 e->e_name.bv_val, 0, 0 );
384                         return -1;
385                 }
386                 
387                 el.el_cb = cb;
388
389                 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
390                                 *elpp;
391                                 elpp = &(*elpp)->el_next )
392                         /* go to last */;
393
394                 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
395                 if ( *elpp == NULL ) {
396                         el.el_e->e_private = NULL;
397                         entry_free( el.el_e );
398                         return -1;
399                 }
400
401                 el.el_next = NULL;
402                 **elpp = el;
403         }
404
405         return 0;
406 }
407
408 int
409 monitor_back_register_entry_parent(
410         Entry                   *e,
411         monitor_callback_t      *cb,
412         struct berval           *base,
413         int                     scope,
414         struct berval           *filter )
415 {
416         monitor_info_t  *mi = ( monitor_info_t * )be_monitor->be_private;
417         struct berval   ndn = BER_BVNULL;
418
419         assert( mi != NULL );
420         assert( e != NULL );
421         assert( e->e_private == NULL );
422
423         if ( BER_BVISNULL( filter ) ) {
424                 /* need a filter */
425                 Debug( LDAP_DEBUG_ANY,
426                         "monitor_back_register_entry_parent(\"\"): "
427                         "need a valid filter\n",
428                         0, 0, 0 );
429                 return -1;
430         }
431
432         if ( monitor_subsys_opened ) {
433                 Entry           *e_parent = NULL,
434                                 *e_new = NULL,
435                                 **ep = NULL;
436                 struct berval   e_name = BER_BVNULL,
437                                 e_nname = BER_BVNULL;
438                 monitor_entry_t *mp = NULL,
439                                 *mp_parent = NULL;
440                 int             rc = 0;
441
442                 if ( monitor_filter2ndn( base, scope, filter, &ndn ) ) {
443                         /* entry does not exist */
444                         Debug( LDAP_DEBUG_ANY,
445                                 "monitor_back_register_entry_parent(\"\"): "
446                                 "base=%s scope=%d filter=%s : "
447                                 "unable to find entry\n",
448                                 base->bv_val ? base->bv_val : "\"\"",
449                                 scope, filter->bv_val );
450                         return -1;
451                 }
452
453                 if ( monitor_cache_get( mi, &ndn, &e_parent ) != 0 ) {
454                         /* entry does not exist */
455                         Debug( LDAP_DEBUG_ANY,
456                                 "monitor_back_register_entry_parent(\"%s\"): "
457                                 "parent entry does not exist\n",
458                                 ndn.bv_val, 0, 0 );
459                         rc = -1;
460                         goto done;
461                 }
462
463                 assert( e_parent->e_private != NULL );
464                 mp_parent = ( monitor_entry_t * )e_parent->e_private;
465
466                 if ( mp_parent->mp_flags & MONITOR_F_VOLATILE ) {
467                         /* entry is volatile; cannot append callback */
468                         Debug( LDAP_DEBUG_ANY,
469                                 "monitor_back_register_entry_parent(\"%s\"): "
470                                 "entry is volatile\n",
471                                 e_parent->e_name.bv_val, 0, 0 );
472                         rc = -1;
473                         goto done;
474                 }
475
476                 build_new_dn( &e_name, &e_parent->e_name, &e->e_name, NULL );
477                 build_new_dn( &e_nname, &e_parent->e_nname, &e->e_nname, NULL );
478
479                 if ( monitor_cache_get( mi, &e_nname, &e_new ) == 0 ) {
480                         /* entry already exists */
481                         Debug( LDAP_DEBUG_ANY,
482                                 "monitor_back_register_entry_parent(\"%s\"): "
483                                 "entry already exists\n",
484                                 e_name.bv_val, 0, 0 );
485                         monitor_cache_release( mi, e_new );
486                         rc = -1;
487                         goto done;
488                 }
489
490                 mp = monitor_entrypriv_create();
491                 if ( mp == NULL ) {
492                         Debug( LDAP_DEBUG_ANY,
493                                 "monitor_back_register_entry_parent(\"%s\"): "
494                                 "monitor_entrypriv_create() failed\n",
495                                 e->e_name.bv_val, 0, 0 );
496                         rc = -1;
497                         goto done;
498                 }
499
500                 e_new = entry_dup( e );
501                 if ( e_new == NULL ) {
502                         Debug( LDAP_DEBUG_ANY,
503                                 "monitor_back_register_entry(\"%s\"): "
504                                 "entry_dup() failed\n",
505                                 e->e_name.bv_val, 0, 0 );
506                         rc = -1;
507                         goto done;
508                 }
509                 ch_free( e_new->e_name.bv_val );
510                 ch_free( e_new->e_nname.bv_val );
511                 e_new->e_name = e_name;
512                 e_new->e_nname = e_nname;
513                 
514                 e_new->e_private = ( void * )mp;
515                 mp->mp_info = mp_parent->mp_info;
516                 mp->mp_flags = mp_parent->mp_flags | MONITOR_F_SUB;
517                 mp->mp_cb = cb;
518
519                 ep = &mp_parent->mp_children;
520                 for ( ; *ep; ) {
521                         mp_parent = ( monitor_entry_t * )(*ep)->e_private;
522                         ep = &mp_parent->mp_next;
523                 }
524                 *ep = e_new;
525
526                 if ( monitor_cache_add( mi, e_new ) ) {
527                         Debug( LDAP_DEBUG_ANY,
528                                 "monitor_back_register_entry(\"%s\"): "
529                                 "unable to add entry\n",
530                                 e->e_name.bv_val, 0, 0 );
531                         rc = -1;
532                         goto done;
533                 }
534
535 done:;
536                 if ( !BER_BVISNULL( &ndn ) ) {
537                         ch_free( ndn.bv_val );
538                 }
539
540                 if ( rc ) {
541                         if ( mp ) {
542                                 ch_free( mp );
543                         }
544                         if ( e_new ) {
545                                 e_new->e_private = NULL;
546                                 entry_free( e_new );
547                         }
548                 }
549
550                 if ( e_parent ) {
551                         monitor_cache_release( mi, e_parent );
552                 }
553
554         } else {
555                 entry_limbo_t   **elpp, el = { 0 };
556
557                 el.el_type = LIMBO_ENTRY_PARENT;
558
559                 el.el_e = entry_dup( e );
560                 if ( el.el_e == NULL ) {
561                         Debug( LDAP_DEBUG_ANY,
562                                 "monitor_back_register_entry(\"%s\"): "
563                                 "entry_dup() failed\n",
564                                 e->e_name.bv_val, 0, 0 );
565                         return -1;
566                 }
567                 
568                 if ( !BER_BVISNULL( base ) ) {
569                         ber_dupbv( &el.el_base, base );
570                 }
571                 el.el_scope = scope;
572                 if ( !BER_BVISNULL( filter ) ) {
573                         ber_dupbv( &el.el_filter, filter );
574                 }
575
576                 el.el_cb = cb;
577
578                 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
579                                 *elpp;
580                                 elpp = &(*elpp)->el_next )
581                         /* go to last */;
582
583                 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
584                 if ( *elpp == NULL ) {
585                         el.el_e->e_private = NULL;
586                         entry_free( el.el_e );
587                         return -1;
588                 }
589
590                 el.el_next = NULL;
591                 **elpp = el;
592         }
593
594         return 0;
595 }
596
597 static int
598 monitor_filter2ndn_cb( Operation *op, SlapReply *rs )
599 {
600         if ( rs->sr_type == REP_SEARCH ) {
601                 struct berval   *ndn = op->o_callback->sc_private;
602                 
603                 ber_dupbv( ndn, &rs->sr_entry->e_nname );
604         }
605
606         return 0;
607 }
608
609 int
610 monitor_filter2ndn(
611         struct berval   *base,
612         int             scope,
613         struct berval   *filter,
614         struct berval   *ndn )
615 {
616         Connection      conn = { 0 };
617         char            opbuf[OPERATION_BUFFER_SIZE];
618         Operation       *op;
619         SlapReply       rs = { 0 };
620         slap_callback   cb = { NULL, monitor_filter2ndn_cb, NULL, NULL };
621         int             rc;
622
623         BER_BVZERO( ndn );
624
625         if ( be_monitor == NULL ) {
626                 return -1;
627         }
628
629         op = (Operation *)opbuf;
630         connection_fake_init( &conn, op, &conn );
631
632         op->o_tag = LDAP_REQ_SEARCH;
633
634         /* use global malloc for now */
635         if ( op->o_tmpmemctx ) {
636                 /* FIXME: connection_fake_init() calls slap_sl_mem_create, so we destroy it for now */
637                 slap_sl_mem_destroy( NULL, op->o_tmpmemctx );
638                 op->o_tmpmemctx = NULL;
639         }
640         op->o_tmpmfuncs = &ch_mfuncs;
641
642         op->o_bd = be_monitor;
643         if ( base == NULL || BER_BVISNULL( base ) ) {
644                 ber_dupbv_x( &op->o_req_dn, &op->o_bd->be_suffix[ 0 ],
645                                 op->o_tmpmemctx );
646                 ber_dupbv_x( &op->o_req_ndn, &op->o_bd->be_nsuffix[ 0 ],
647                                 op->o_tmpmemctx );
648
649         } else {
650                 if ( dnPrettyNormal( NULL, base, &op->o_req_dn, &op->o_req_ndn,
651                                         op->o_tmpmemctx ) ) {
652                         return -1;
653                 }
654         }
655
656         op->o_callback = &cb;
657         cb.sc_private = (void *)ndn;
658
659         op->ors_scope = scope;
660         ber_dupbv_x( &op->ors_filterstr, filter, op->o_tmpmemctx );
661         op->ors_filter = str2filter_x( op, filter->bv_val );
662         op->ors_attrs = slap_anlist_no_attrs;
663         op->ors_attrsonly = 0;
664         op->ors_tlimit = SLAP_NO_LIMIT;
665         op->ors_slimit = 1;
666         op->ors_limit = NULL;
667         op->ors_deref = LDAP_DEREF_NEVER;
668
669         op->o_nocaching = 1;
670         op->o_managedsait = SLAP_CONTROL_NONCRITICAL;
671
672         op->o_dn = be_monitor->be_rootdn;
673         op->o_ndn = be_monitor->be_rootndn;
674
675         rc = op->o_bd->be_search( op, &rs );
676
677         filter_free_x( op, op->ors_filter );
678         op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx );
679         op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
680         op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
681
682         if ( rc != 0 ) {
683                 return rc;
684         }
685
686         switch ( rs.sr_err ) {
687         case LDAP_SUCCESS:
688                 if ( BER_BVISNULL( ndn ) ) {
689                         rc = -1;
690                 }
691                 break;
692                         
693         case LDAP_SIZELIMIT_EXCEEDED:
694         default:
695                 if ( !BER_BVISNULL( ndn ) ) {
696                         ber_memfree( ndn->bv_val );
697                         BER_BVZERO( ndn );
698                 }
699                 rc = -1;
700                 break;
701         }
702
703         return rc;
704 }
705
706 int
707 monitor_back_register_entry_attrs(
708         struct berval           *ndn_in,
709         Attribute               *a,
710         monitor_callback_t      *cb,
711         struct berval           *base,
712         int                     scope,
713         struct berval           *filter )
714 {
715         monitor_info_t  *mi = ( monitor_info_t * )be_monitor->be_private;
716         struct berval   ndn = BER_BVNULL;
717
718         assert( mi != NULL );
719
720         if ( ndn_in != NULL ) {
721                 ndn = *ndn_in;
722         }
723
724         if ( a == NULL && cb == NULL ) {
725                 /* nothing to do */
726                 return -1;
727         }
728
729         if ( ( ndn_in == NULL || BER_BVISNULL( &ndn ) )
730                         && BER_BVISNULL( filter ) )
731         {
732                 /* need a filter */
733                 Debug( LDAP_DEBUG_ANY,
734                         "monitor_back_register_entry_*(\"\"): "
735                         "need a valid filter\n",
736                         0, 0, 0 );
737                 return -1;
738         }
739
740         if ( monitor_subsys_opened ) {
741                 Entry                   *e = NULL;
742                 Attribute               **atp = NULL;
743                 monitor_entry_t         *mp = NULL;
744                 monitor_callback_t      **mcp = NULL;
745                 int                     rc = 0;
746                 int                     freeit = 0;
747
748                 if ( BER_BVISNULL( &ndn ) ) {
749                         if ( monitor_filter2ndn( base, scope, filter, &ndn ) ) {
750                                 /* entry does not exist */
751                                 Debug( LDAP_DEBUG_ANY,
752                                         "monitor_back_register_entry_*(\"\"): "
753                                         "base=%s scope=%d filter=%s : "
754                                         "unable to find entry\n",
755                                         base->bv_val ? base->bv_val : "\"\"",
756                                         scope, filter->bv_val );
757                                 return -1;
758                         }
759
760                         freeit = 1;
761                 }
762
763                 if ( monitor_cache_get( mi, &ndn, &e ) != 0 ) {
764                         /* entry does not exist */
765                         Debug( LDAP_DEBUG_ANY,
766                                 "monitor_back_register_entry_*(\"%s\"): "
767                                 "entry does not exist\n",
768                                 ndn.bv_val, 0, 0 );
769                         rc = -1;
770                         goto done;
771                 }
772
773                 assert( e->e_private != NULL );
774                 mp = ( monitor_entry_t * )e->e_private;
775
776                 if ( mp->mp_flags & MONITOR_F_VOLATILE ) {
777                         /* entry is volatile; cannot append callback */
778                         Debug( LDAP_DEBUG_ANY,
779                                 "monitor_back_register_entry_*(\"%s\"): "
780                                 "entry is volatile\n",
781                                 e->e_name.bv_val, 0, 0 );
782                         rc = -1;
783                         goto done;
784                 }
785
786                 if ( a ) {
787                         for ( atp = &e->e_attrs; *atp; atp = &(*atp)->a_next )
788                                 /* just get to last */ ;
789
790                         *atp = attrs_dup( a );
791                         if ( *atp == NULL ) {
792                                 Debug( LDAP_DEBUG_ANY,
793                                         "monitor_back_register_entry_*(\"%s\"): "
794                                         "attrs_dup() failed\n",
795                                         e->e_name.bv_val, 0, 0 );
796                                 rc = -1;
797                                 goto done;
798                         }
799                 }
800
801                 if ( cb ) {
802                         for ( mcp = &mp->mp_cb; *mcp; mcp = &(*mcp)->mc_next )
803                                 /* go to tail */ ;
804                 
805                         /* NOTE: we do not clear cb->mc_next, so this function
806                          * can be used to append a list of callbacks */
807                         (*mcp) = cb;
808                 }
809
810 done:;
811                 if ( rc ) {
812                         if ( *atp ) {
813                                 attrs_free( *atp );
814                                 *atp = NULL;
815                         }
816                 }
817
818                 if ( freeit ) {
819                         ber_memfree( ndn.bv_val );
820                 }
821
822                 if ( e ) {
823                         monitor_cache_release( mi, e );
824                 }
825
826         } else {
827                 entry_limbo_t   **elpp, el = { 0 };
828
829                 el.el_type = LIMBO_ATTRS;
830                 if ( !BER_BVISNULL( &ndn ) ) {
831                         ber_dupbv( &el.el_ndn, &ndn );
832                 }
833                 if ( !BER_BVISNULL( base ) ) {
834                         ber_dupbv( &el.el_base, base);
835                 }
836                 el.el_scope = scope;
837                 if ( !BER_BVISNULL( filter ) ) {
838                         ber_dupbv( &el.el_filter, filter );
839                 }
840
841                 el.el_a = attrs_dup( a );
842                 el.el_cb = cb;
843
844                 for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo;
845                                 *elpp;
846                                 elpp = &(*elpp)->el_next )
847                         /* go to last */;
848
849                 *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) );
850                 if ( *elpp == NULL ) {
851                         el.el_e->e_private = NULL;
852                         entry_free( el.el_e );
853                         return -1;
854                 }
855
856                 el.el_next = NULL;
857                 **elpp = el;
858         }
859
860         return 0;
861 }
862
863 int
864 monitor_back_register_entry_callback(
865         struct berval           *ndn,
866         monitor_callback_t      *cb,
867         struct berval           *base,
868         int                     scope,
869         struct berval           *filter )
870 {
871         return monitor_back_register_entry_attrs( ndn, NULL, cb,
872                         base, scope, filter );
873 }
874
875 monitor_subsys_t *
876 monitor_back_get_subsys( const char *name )
877 {
878         if ( monitor_subsys != NULL ) {
879                 int     i;
880                 
881                 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
882                         if ( strcasecmp( monitor_subsys[ i ]->mss_name, name ) == 0 ) {
883                                 return monitor_subsys[ i ];
884                         }
885                 }
886         }
887
888         return NULL;
889 }
890
891 monitor_subsys_t *
892 monitor_back_get_subsys_by_dn(
893         struct berval   *ndn,
894         int             sub )
895 {
896         if ( monitor_subsys != NULL ) {
897                 int     i;
898
899                 if ( sub ) {
900                         for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
901                                 if ( dnIsSuffix( ndn, &monitor_subsys[ i ]->mss_ndn ) ) {
902                                         return monitor_subsys[ i ];
903                                 }
904                         }
905
906                 } else {
907                         for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
908                                 if ( dn_match( ndn, &monitor_subsys[ i ]->mss_ndn ) ) {
909                                         return monitor_subsys[ i ];
910                                 }
911                         }
912                 }
913         }
914
915         return NULL;
916 }
917
918 int
919 monitor_back_initialize(
920         BackendInfo     *bi )
921 {
922         monitor_subsys_t        *ms;
923         static char             *controls[] = {
924                 LDAP_CONTROL_MANAGEDSAIT,
925                 NULL
926         };
927         monitor_info_t          *mi = &monitor_info;
928         int                     i;
929         const char              *text;
930
931         struct m_s {
932                 char    *name;
933                 char    *schema;
934                 slap_mask_t flags;
935                 int     offset;
936         } moc[] = {
937                 { "monitor", "( 1.3.6.1.4.1.4203.666.3.16.1 "
938                         "NAME 'monitor' "
939                         "DESC 'OpenLDAP system monitoring' "
940                         "SUP top STRUCTURAL "
941                         "MUST cn "
942                         "MAY ( "
943                                 "description "
944                                 "$ seeAlso "
945                                 "$ labeledURI "
946                                 "$ monitoredInfo "
947                                 "$ managedInfo "
948                                 "$ monitorOverlay "
949                         ") )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
950                         offsetof(monitor_info_t, mi_oc_monitor) },
951                 { "monitorServer", "( 1.3.6.1.4.1.4203.666.3.16.2 "
952                         "NAME 'monitorServer' "
953                         "DESC 'Server monitoring root entry' "
954                         "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
955                         offsetof(monitor_info_t, mi_oc_monitorServer) },
956                 { "monitorContainer", "( 1.3.6.1.4.1.4203.666.3.16.3 "
957                         "NAME 'monitorContainer' "
958                         "DESC 'monitor container class' "
959                         "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
960                         offsetof(monitor_info_t, mi_oc_monitorContainer) },
961                 { "monitorCounterObject", "( 1.3.6.1.4.1.4203.666.3.16.4 "
962                         "NAME 'monitorCounterObject' "
963                         "DESC 'monitor counter class' "
964                         "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
965                         offsetof(monitor_info_t, mi_oc_monitorCounterObject) },
966                 { "monitorOperation", "( 1.3.6.1.4.1.4203.666.3.16.5 "
967                         "NAME 'monitorOperation' "
968                         "DESC 'monitor operation class' "
969                         "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
970                         offsetof(monitor_info_t, mi_oc_monitorOperation) },
971                 { "monitorConnection", "( 1.3.6.1.4.1.4203.666.3.16.6 "
972                         "NAME 'monitorConnection' "
973                         "DESC 'monitor connection class' "
974                         "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
975                         offsetof(monitor_info_t, mi_oc_monitorConnection) },
976                 { "managedObject", "( 1.3.6.1.4.1.4203.666.3.16.7 "
977                         "NAME 'managedObject' "
978                         "DESC 'monitor managed entity class' "
979                         "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
980                         offsetof(monitor_info_t, mi_oc_managedObject) },
981                 { "monitoredObject", "( 1.3.6.1.4.1.4203.666.3.16.8 "
982                         "NAME 'monitoredObject' "
983                         "DESC 'monitor monitored entity class' "
984                         "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
985                         offsetof(monitor_info_t, mi_oc_monitoredObject) },
986                 { NULL, NULL, 0, -1 }
987         }, mat[] = {
988                 { "monitoredInfo", "( 1.3.6.1.4.1.4203.666.1.55.1 "
989                         "NAME 'monitoredInfo' "
990                         "DESC 'monitored info' "
991                         /* "SUP name " */
992                         "EQUALITY caseIgnoreMatch "
993                         "SUBSTR caseIgnoreSubstringsMatch "
994                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} "
995                         "NO-USER-MODIFICATION "
996                         "USAGE directoryOperation )", SLAP_AT_HIDE,
997                         offsetof(monitor_info_t, mi_ad_monitoredInfo) },
998                 { "managedInfo", "( 1.3.6.1.4.1.4203.666.1.55.2 "
999                         "NAME 'managedInfo' "
1000                         "DESC 'monitor managed info' "
1001                         "SUP name )", SLAP_AT_HIDE,
1002                         offsetof(monitor_info_t, mi_ad_managedInfo) },
1003                 { "monitorCounter", "( 1.3.6.1.4.1.4203.666.1.55.3 "
1004                         "NAME 'monitorCounter' "
1005                         "DESC 'monitor counter' "
1006                         "EQUALITY integerMatch "
1007                         "ORDERING integerOrderingMatch "
1008                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 "
1009                         "NO-USER-MODIFICATION "
1010                         "USAGE directoryOperation )", SLAP_AT_HIDE,
1011                         offsetof(monitor_info_t, mi_ad_monitorCounter) },
1012                 { "monitorOpCompleted", "( 1.3.6.1.4.1.4203.666.1.55.4 "
1013                         "NAME 'monitorOpCompleted' "
1014                         "DESC 'monitor completed operations' "
1015                         "SUP monitorCounter "
1016                         "NO-USER-MODIFICATION "
1017                         "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1018                         offsetof(monitor_info_t, mi_ad_monitorOpCompleted) },
1019                 { "monitorOpInitiated", "( 1.3.6.1.4.1.4203.666.1.55.5 "
1020                         "NAME 'monitorOpInitiated' "
1021                         "DESC 'monitor initiated operations' "
1022                         "SUP monitorCounter "
1023                         "NO-USER-MODIFICATION "
1024                         "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1025                         offsetof(monitor_info_t, mi_ad_monitorOpInitiated) },
1026                 { "monitorConnectionNumber", "( 1.3.6.1.4.1.4203.666.1.55.6 "
1027                         "NAME 'monitorConnectionNumber' "
1028                         "DESC 'monitor connection number' "
1029                         "SUP monitorCounter "
1030                         "NO-USER-MODIFICATION "
1031                         "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1032                         offsetof(monitor_info_t, mi_ad_monitorConnectionNumber) },
1033                 { "monitorConnectionAuthzDN", "( 1.3.6.1.4.1.4203.666.1.55.7 "
1034                         "NAME 'monitorConnectionAuthzDN' "
1035                         "DESC 'monitor connection authorization DN' "
1036                         /* "SUP distinguishedName " */
1037                         "EQUALITY distinguishedNameMatch "
1038                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 "
1039                         "NO-USER-MODIFICATION "
1040                         "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1041                         offsetof(monitor_info_t, mi_ad_monitorConnectionAuthzDN) },
1042                 { "monitorConnectionLocalAddress", "( 1.3.6.1.4.1.4203.666.1.55.8 "
1043                         "NAME 'monitorConnectionLocalAddress' "
1044                         "DESC 'monitor connection local address' "
1045                         "SUP monitoredInfo "
1046                         "NO-USER-MODIFICATION "
1047                         "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1048                         offsetof(monitor_info_t, mi_ad_monitorConnectionLocalAddress) },
1049                 { "monitorConnectionPeerAddress", "( 1.3.6.1.4.1.4203.666.1.55.9 "
1050                         "NAME 'monitorConnectionPeerAddress' "
1051                         "DESC 'monitor connection peer address' "
1052                         "SUP monitoredInfo "
1053                         "NO-USER-MODIFICATION "
1054                         "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1055                         offsetof(monitor_info_t, mi_ad_monitorConnectionPeerAddress) },
1056                 { "monitorTimestamp", "( 1.3.6.1.4.1.4203.666.1.55.10 "
1057                         "NAME 'monitorTimestamp' "
1058                         "DESC 'monitor timestamp' "
1059                         "EQUALITY generalizedTimeMatch "
1060                         "ORDERING generalizedTimeOrderingMatch "
1061                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 "
1062                         "SINGLE-VALUE "
1063                         "NO-USER-MODIFICATION "
1064                         "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1065                         offsetof(monitor_info_t, mi_ad_monitorTimestamp) },
1066                 { "monitorOverlay", "( 1.3.6.1.4.1.4203.666.1.55.11 "
1067                         "NAME 'monitorOverlay' "
1068                         "DESC 'name of overlays defined for a given database' "
1069                         "SUP monitoredInfo "
1070                         "NO-USER-MODIFICATION "
1071                         "USAGE directoryOperation )", SLAP_AT_HIDE,
1072                         offsetof(monitor_info_t, mi_ad_monitorOverlay) },
1073                 { "readOnly", "( 1.3.6.1.4.1.4203.666.1.55.12 "
1074                         "NAME 'readOnly' "
1075                         "DESC 'read/write status of a given database' "
1076                         "EQUALITY booleanMatch "
1077                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1078                         "SINGLE-VALUE "
1079                         "USAGE directoryOperation )", SLAP_AT_HIDE,
1080                         offsetof(monitor_info_t, mi_ad_readOnly) },
1081                 { "restrictedOperation", "( 1.3.6.1.4.1.4203.666.1.55.13 "
1082                         "NAME 'restrictedOperation' "
1083                         "DESC 'name of restricted operation for a given database' "
1084                         "SUP managedInfo )", SLAP_AT_HIDE,
1085                         offsetof(monitor_info_t, mi_ad_restrictedOperation ) },
1086                 { "monitorConnectionProtocol", "( 1.3.6.1.4.1.4203.666.1.55.14 "
1087                         "NAME 'monitorConnectionProtocol' "
1088                         "DESC 'monitor connection protocol' "
1089                         "SUP monitoredInfo "
1090                         "NO-USER-MODIFICATION "
1091                         "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1092                         offsetof(monitor_info_t, mi_ad_monitorConnectionProtocol) },
1093                 { "monitorConnectionOpsReceived", "( 1.3.6.1.4.1.4203.666.1.55.15 "
1094                         "NAME 'monitorConnectionOpsReceived' "
1095                         "DESC 'monitor number of operations received by the connection' "
1096                         "SUP monitorCounter "
1097                         "NO-USER-MODIFICATION "
1098                         "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1099                         offsetof(monitor_info_t, mi_ad_monitorConnectionOpsReceived) },
1100                 { "monitorConnectionOpsExecuting", "( 1.3.6.1.4.1.4203.666.1.55.16 "
1101                         "NAME 'monitorConnectionOpsExecuting' "
1102                         "DESC 'monitor number of operations in execution within the connection' "
1103                         "SUP monitorCounter "
1104                         "NO-USER-MODIFICATION "
1105                         "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1106                         offsetof(monitor_info_t, mi_ad_monitorConnectionOpsExecuting) },
1107                 { "monitorConnectionOpsPending", "( 1.3.6.1.4.1.4203.666.1.55.17 "
1108                         "NAME 'monitorConnectionOpsPending' "
1109                         "DESC 'monitor number of pending operations within the connection' "
1110                         "SUP monitorCounter "
1111                         "NO-USER-MODIFICATION "
1112                         "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1113                         offsetof(monitor_info_t, mi_ad_monitorConnectionOpsPending) },
1114                 { "monitorConnectionOpsCompleted", "( 1.3.6.1.4.1.4203.666.1.55.18 "
1115                         "NAME 'monitorConnectionOpsCompleted' "
1116                         "DESC 'monitor number of operations completed within the connection' "
1117                         "SUP monitorCounter "
1118                         "NO-USER-MODIFICATION "
1119                         "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1120                         offsetof(monitor_info_t, mi_ad_monitorConnectionOpsCompleted) },
1121                 { "monitorConnectionGet", "( 1.3.6.1.4.1.4203.666.1.55.19 "
1122                         "NAME 'monitorConnectionGet' "
1123                         "DESC 'number of times connection_get() was called so far' "
1124                         "SUP monitorCounter "
1125                         "NO-USER-MODIFICATION "
1126                         "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1127                         offsetof(monitor_info_t, mi_ad_monitorConnectionGet) },
1128                 { "monitorConnectionRead", "( 1.3.6.1.4.1.4203.666.1.55.20 "
1129                         "NAME 'monitorConnectionRead' "
1130                         "DESC 'number of times connection_read() was called so far' "
1131                         "SUP monitorCounter "
1132                         "NO-USER-MODIFICATION "
1133                         "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1134                         offsetof(monitor_info_t, mi_ad_monitorConnectionRead) },
1135                 { "monitorConnectionWrite", "( 1.3.6.1.4.1.4203.666.1.55.21 "
1136                         "NAME 'monitorConnectionWrite' "
1137                         "DESC 'number of times connection_write() was called so far' "
1138                         "SUP monitorCounter "
1139                         "NO-USER-MODIFICATION "
1140                         "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1141                         offsetof(monitor_info_t, mi_ad_monitorConnectionWrite) },
1142                 { "monitorConnectionMask", "( 1.3.6.1.4.1.4203.666.1.55.22 "
1143                         "NAME 'monitorConnectionMask' "
1144                         "DESC 'monitor connection mask' "
1145                         "SUP monitoredInfo "
1146                         "NO-USER-MODIFICATION "
1147                         "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1148                         offsetof(monitor_info_t, mi_ad_monitorConnectionMask) },
1149                 { "monitorConnectionListener", "( 1.3.6.1.4.1.4203.666.1.55.23 "
1150                         "NAME 'monitorConnectionListener' "
1151                         "DESC 'monitor connection listener' "
1152                         "SUP monitoredInfo "
1153                         "NO-USER-MODIFICATION "
1154                         "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1155                         offsetof(monitor_info_t, mi_ad_monitorConnectionListener) },
1156                 { "monitorConnectionPeerDomain", "( 1.3.6.1.4.1.4203.666.1.55.24 "
1157                         "NAME 'monitorConnectionPeerDomain' "
1158                         "DESC 'monitor connection peer domain' "
1159                         "SUP monitoredInfo "
1160                         "NO-USER-MODIFICATION "
1161                         "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1162                         offsetof(monitor_info_t, mi_ad_monitorConnectionPeerDomain) },
1163                 { "monitorConnectionStartTime", "( 1.3.6.1.4.1.4203.666.1.55.25 "
1164                         "NAME 'monitorConnectionStartTime' "
1165                         "DESC 'monitor connection start time' "
1166                         "SUP monitorTimestamp "
1167                         "SINGLE-VALUE "
1168                         "NO-USER-MODIFICATION "
1169                         "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1170                         offsetof(monitor_info_t, mi_ad_monitorConnectionStartTime) },
1171                 { "monitorConnectionActivityTime", "( 1.3.6.1.4.1.4203.666.1.55.26 "
1172                         "NAME 'monitorConnectionActivityTime' "
1173                         "DESC 'monitor connection activity time' "
1174                         "SUP monitorTimestamp "
1175                         "SINGLE-VALUE "
1176                         "NO-USER-MODIFICATION "
1177                         "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
1178                         offsetof(monitor_info_t, mi_ad_monitorConnectionActivityTime) },
1179                 { "monitorIsShadow", "( 1.3.6.1.4.1.4203.666.1.55.27 "
1180                         "NAME 'monitorIsShadow' "
1181                         "DESC 'TRUE if the database is shadow' "
1182                         "EQUALITY booleanMatch "
1183                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1184                         "SINGLE-VALUE "
1185                         "USAGE directoryOperation )", SLAP_AT_HIDE,
1186                         offsetof(monitor_info_t, mi_ad_monitorIsShadow) },
1187                 { "monitorUpdateRef", "( 1.3.6.1.4.1.4203.666.1.55.28 "
1188                         "NAME 'monitorUpdateRef' "
1189                         "DESC 'update referral for shadow databases' "
1190                         "SUP monitoredInfo "
1191                         "SINGLE-VALUE "
1192                         "USAGE directoryOperation )", SLAP_AT_HIDE,
1193                         offsetof(monitor_info_t, mi_ad_monitorUpdateRef) },
1194                 { "monitorRuntimeConfig", "( 1.3.6.1.4.1.4203.666.1.55.29 "
1195                         "NAME 'monitorRuntimeConfig' "
1196                         "DESC 'TRUE if component allows runtime configuration' "
1197                         "EQUALITY booleanMatch "
1198                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
1199                         "SINGLE-VALUE "
1200                         "USAGE directoryOperation )", SLAP_AT_HIDE,
1201                         offsetof(monitor_info_t, mi_ad_monitorRuntimeConfig) },
1202                 { NULL, NULL, 0, -1 }
1203         };
1204         static ConfigTable monitorcfg[] = {
1205                 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
1206                         NULL, NULL, NULL, NULL }
1207         };
1208         static ConfigOCs monitorocs[] = {
1209                 { "( OLcfgDbOc:4.1 "
1210                         "NAME 'olcMonitorConfig' "
1211                         "DESC 'Monitor backend configuration' "
1212                         "SUP olcDatabaseConfig "
1213                         ")",
1214                                 Cft_Database, monitorcfg },
1215                 { NULL, 0, NULL }
1216         };
1217         int             rc;
1218
1219         bi->bi_controls = controls;
1220
1221         bi->bi_init = 0;
1222         bi->bi_open = 0;
1223         bi->bi_config = monitor_back_config;
1224         bi->bi_close = 0;
1225         bi->bi_destroy = 0;
1226
1227         bi->bi_db_init = monitor_back_db_init;
1228         bi->bi_db_config = monitor_back_db_config;
1229         bi->bi_db_open = monitor_back_db_open;
1230         bi->bi_db_close = 0;
1231         bi->bi_db_destroy = monitor_back_db_destroy;
1232
1233         bi->bi_op_bind = monitor_back_bind;
1234         bi->bi_op_unbind = 0;
1235         bi->bi_op_search = monitor_back_search;
1236         bi->bi_op_compare = monitor_back_compare;
1237         bi->bi_op_modify = monitor_back_modify;
1238         bi->bi_op_modrdn = 0;
1239         bi->bi_op_add = 0;
1240         bi->bi_op_delete = 0;
1241         bi->bi_op_abandon = 0;
1242
1243         bi->bi_extended = 0;
1244
1245         bi->bi_entry_release_rw = 0;
1246         bi->bi_chk_referrals = 0;
1247         bi->bi_operational = monitor_back_operational;
1248
1249         /*
1250          * hooks for slap tools
1251          */
1252         bi->bi_tool_entry_open = 0;
1253         bi->bi_tool_entry_close = 0;
1254         bi->bi_tool_entry_first = 0;
1255         bi->bi_tool_entry_next = 0;
1256         bi->bi_tool_entry_get = 0;
1257         bi->bi_tool_entry_put = 0;
1258         bi->bi_tool_entry_reindex = 0;
1259         bi->bi_tool_sync = 0;
1260         bi->bi_tool_dn2id_get = 0;
1261         bi->bi_tool_id2entry_get = 0;
1262         bi->bi_tool_entry_modify = 0;
1263
1264         bi->bi_connection_init = 0;
1265         bi->bi_connection_destroy = 0;
1266
1267         /*
1268          * configuration objectClasses (fake)
1269          */
1270         bi->bi_cf_ocs = monitorocs;
1271
1272         rc = config_register_schema( monitorcfg, monitorocs );
1273         if ( rc ) {
1274                 return rc;
1275         }
1276
1277         /*
1278          * register subsys
1279          */
1280         for ( ms = known_monitor_subsys; ms->mss_name != NULL; ms++ ) {
1281                 if ( monitor_back_register_subsys( ms ) ) {
1282                         return -1;
1283                 }
1284         }
1285
1286         /* schema integration */
1287         for ( i = 0; mat[ i ].name; i++ ) {
1288                 LDAPAttributeType       *at;
1289                 int                     code;
1290                 const char              *err;
1291                 AttributeDescription    **ad;
1292
1293                 at = ldap_str2attributetype( mat[ i ].schema, &code,
1294                         &err, LDAP_SCHEMA_ALLOW_ALL );
1295                 if ( !at ) {
1296                         Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
1297                                 "in AttributeType \"%s\" %s before %s\n",
1298                                 mat[ i ].name, ldap_scherr2str(code), err );
1299                         return -1;
1300                 }
1301
1302                 if ( at->at_oid == NULL ) {
1303                         Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
1304                                 "null OID for attributeType \"%s\"\n",
1305                                 mat[ i ].name, 0, 0 );
1306                         return -1;
1307                 }
1308
1309                 code = at_add(at, 0, NULL, &err);
1310                 if ( code ) {
1311                         Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
1312                                 "%s in attributeType \"%s\"\n",
1313                                 scherr2str(code), mat[ i ].name, 0 );
1314                         return -1;
1315                 }
1316                 ldap_memfree(at);
1317
1318                 ad = ((AttributeDescription **)&(((char *)mi)[ mat[ i ].offset ]));
1319                 ad[ 0 ] = NULL;
1320                 if ( slap_str2ad( mat[ i ].name, ad, &text ) ) {
1321                         Debug( LDAP_DEBUG_ANY,
1322                                 "monitor_back_db_init: %s\n", text, 0, 0 );
1323                         return -1;
1324                 }
1325
1326                 (*ad)->ad_type->sat_flags |= mat[ i ].flags;
1327         }
1328
1329         for ( i = 0; moc[ i ].name; i++ ) {
1330                 LDAPObjectClass         *oc;
1331                 int                     code;
1332                 const char              *err;
1333                 ObjectClass             *Oc;
1334
1335                 oc = ldap_str2objectclass(moc[ i ].schema, &code, &err,
1336                                 LDAP_SCHEMA_ALLOW_ALL );
1337                 if ( !oc ) {
1338                         Debug( LDAP_DEBUG_ANY,
1339                                 "unable to parse monitor objectclass \"%s\": "
1340                                 "%s before %s\n" , moc[ i ].name,
1341                                 ldap_scherr2str(code), err );
1342                         return -1;
1343                 }
1344
1345                 if ( oc->oc_oid == NULL ) {
1346                         Debug( LDAP_DEBUG_ANY,
1347                                 "objectclass \"%s\" has no OID\n" ,
1348                                 moc[ i ].name, 0, 0 );
1349                         return -1;
1350                 }
1351
1352                 code = oc_add(oc, 0, NULL, &err);
1353                 if ( code ) {
1354                         Debug( LDAP_DEBUG_ANY,
1355                                 "objectclass \"%s\": %s \"%s\"\n" ,
1356                                 moc[ i ].name, scherr2str(code), err );
1357                         return -1;
1358                 }
1359
1360                 ldap_memfree(oc);
1361
1362                 Oc = oc_find( moc[ i ].name );
1363                 if ( Oc == NULL ) {
1364                         Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
1365                                         "unable to find objectClass %s "
1366                                         "(just added)\n", moc[ i ].name, 0, 0 );
1367                         return -1;
1368                 }
1369
1370                 Oc->soc_flags |= moc[ i ].flags;
1371
1372                 ((ObjectClass **)&(((char *)mi)[ moc[ i ].offset ]))[ 0 ] = Oc;
1373         }
1374
1375         return 0;
1376 }
1377
1378 int
1379 monitor_back_db_init(
1380         BackendDB       *be )
1381 {
1382         int             rc;
1383         struct berval   dn, ndn;
1384         struct berval   bv;
1385
1386         /*
1387          * database monitor can be defined once only
1388          */
1389         if ( be_monitor != NULL ) {
1390                 Debug( LDAP_DEBUG_ANY,
1391                         "only one monitor database is allowed\n", 0, 0, 0 );
1392                 return( -1 );
1393         }
1394         be_monitor = be;
1395
1396         /* indicate system schema supported */
1397         SLAP_BFLAGS(be) |= SLAP_BFLAG_MONITOR;
1398
1399         dn.bv_val = SLAPD_MONITOR_DN;
1400         dn.bv_len = sizeof( SLAPD_MONITOR_DN ) - 1;
1401
1402         rc = dnNormalize( 0, NULL, NULL, &dn, &ndn, NULL );
1403         if( rc != LDAP_SUCCESS ) {
1404                 Debug( LDAP_DEBUG_ANY,
1405                         "unable to normalize monitor DN \"%s\" (%d)\n",
1406                         dn.bv_val, rc, 0 );
1407                 return -1;
1408         }
1409
1410         ber_dupbv( &bv, &dn );
1411         ber_bvarray_add( &be->be_suffix, &bv );
1412         ber_bvarray_add( &be->be_nsuffix, &ndn );
1413
1414         /* NOTE: only one monitor database is allowed,
1415          * so we use static storage */
1416         ldap_pvt_thread_mutex_init( &monitor_info.mi_cache_mutex );
1417
1418         be->be_private = &monitor_info;
1419
1420         return 0;
1421 }
1422
1423 int
1424 monitor_back_db_open(
1425         BackendDB       *be )
1426 {
1427         monitor_info_t          *mi = (monitor_info_t *)be->be_private;
1428         struct monitor_subsys_t **ms;
1429         Entry                   *e, **ep;
1430         monitor_entry_t         *mp;
1431         int                     i;
1432         char                    buf[ BACKMONITOR_BUFSIZE ];
1433         struct berval           bv;
1434         struct tm               *tms;
1435 #ifdef HAVE_GMTIME_R
1436         struct tm               tm_buf;
1437 #endif
1438         static char             tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
1439
1440         assert( be_monitor != NULL );
1441         if ( be != be_monitor ) {
1442                 be_monitor = be;
1443         }
1444
1445         /*
1446          * Start
1447          */
1448 #ifndef HAVE_GMTIME_R
1449         ldap_pvt_thread_mutex_lock( &gmtime_mutex );
1450 #endif
1451 #ifdef HACK_LOCAL_TIME
1452 # ifdef HAVE_LOCALTIME_R
1453         tms = localtime_r( &starttime, &tm_buf );
1454 # else
1455         tms = localtime( &starttime );
1456 # endif /* HAVE_LOCALTIME_R */
1457         lutil_localtime( tmbuf, sizeof(tmbuf), tms, -timezone );
1458 #else /* !HACK_LOCAL_TIME */
1459 # ifdef HAVE_GMTIME_R
1460         tms = gmtime_r( &starttime, &tm_buf );
1461 # else
1462         tms = gmtime( &starttime );
1463 # endif /* HAVE_GMTIME_R */
1464         lutil_gentime( tmbuf, sizeof(tmbuf), tms );
1465 #endif /* !HACK_LOCAL_TIME */
1466 #ifndef HAVE_GMTIME_R
1467         ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
1468 #endif
1469
1470         mi->mi_startTime.bv_val = tmbuf;
1471         mi->mi_startTime.bv_len = strlen( tmbuf );
1472
1473         if ( BER_BVISEMPTY( &be->be_rootdn ) ) {
1474                 BER_BVSTR( &mi->mi_creatorsName, SLAPD_ANONYMOUS );
1475         } else {
1476                 mi->mi_creatorsName = be->be_rootdn;
1477         }
1478
1479         /*
1480          * creates the "cn=Monitor" entry 
1481          */
1482         snprintf( buf, sizeof( buf ), 
1483                 "dn: %s\n"
1484                 "objectClass: %s\n"
1485                 "structuralObjectClass: %s\n"
1486                 "cn: Monitor\n"
1487                 "description: This subtree contains monitoring/managing objects.\n"
1488                 "description: This object contains information about this server.\n"
1489                 "description: Most of the information is held in operational"
1490                 " attributeTypes, which must be explicitly requested.\n"
1491                 "creatorsName: %s\n"
1492                 "modifiersName: %s\n"
1493                 "createTimestamp: %s\n"
1494                 "modifyTimestamp: %s\n",
1495                 SLAPD_MONITOR_DN,
1496                 mi->mi_oc_monitorServer->soc_cname.bv_val,
1497                 mi->mi_oc_monitorServer->soc_cname.bv_val,
1498                 mi->mi_creatorsName.bv_val,
1499                 mi->mi_creatorsName.bv_val,
1500                 mi->mi_startTime.bv_val,
1501                 mi->mi_startTime.bv_val );
1502
1503         e = str2entry( buf );
1504         if ( e == NULL) {
1505                 Debug( LDAP_DEBUG_ANY,
1506                         "unable to create \"%s\" entry\n",
1507                         SLAPD_MONITOR_DN, 0, 0 );
1508                 return( -1 );
1509         }
1510
1511         bv.bv_val = strchr( (char *) Versionstr, '$' );
1512         if ( bv.bv_val != NULL ) {
1513                 char    *end;
1514
1515                 bv.bv_val++;
1516                 for ( ; bv.bv_val[ 0 ] == ' '; bv.bv_val++ )
1517                         ;
1518
1519                 end = strchr( bv.bv_val, '$' );
1520                 if ( end != NULL ) {
1521                         end--;
1522
1523                         for ( ; end > bv.bv_val && end[ 0 ] == ' '; end-- )
1524                                 ;
1525
1526                         end++;
1527
1528                         bv.bv_len = end - bv.bv_val;
1529
1530                 } else {
1531                         bv.bv_len = strlen( bv.bv_val );
1532                 }
1533
1534                 if ( attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo,
1535                                         &bv, NULL ) ) {
1536                         Debug( LDAP_DEBUG_ANY,
1537                                 "unable to add monitoredInfo to \"%s\" entry\n",
1538                                 SLAPD_MONITOR_DN, 0, 0 );
1539                         return( -1 );
1540                 }
1541         }
1542
1543         mp = monitor_entrypriv_create();
1544         if ( mp == NULL ) {
1545                 return -1;
1546         }
1547         e->e_private = ( void * )mp;
1548         ep = &mp->mp_children;
1549
1550         if ( monitor_cache_add( mi, e ) ) {
1551                 Debug( LDAP_DEBUG_ANY,
1552                         "unable to add entry \"%s\" to cache\n",
1553                         SLAPD_MONITOR_DN, 0, 0 );
1554                 return -1;
1555         }
1556
1557         /*      
1558          * Create all the subsystem specific entries
1559          */
1560         for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1561                 int             len = strlen( monitor_subsys[ i ]->mss_name );
1562                 struct berval   dn;
1563                 int             rc;
1564
1565                 dn.bv_len = len + sizeof( "cn=" ) - 1;
1566                 dn.bv_val = ch_calloc( sizeof( char ), dn.bv_len + 1 );
1567                 strcpy( dn.bv_val, "cn=" );
1568                 strcat( dn.bv_val, monitor_subsys[ i ]->mss_name );
1569                 rc = dnPretty( NULL, &dn, &monitor_subsys[ i ]->mss_rdn, NULL );
1570                 free( dn.bv_val );
1571                 if ( rc != LDAP_SUCCESS ) {
1572                         Debug( LDAP_DEBUG_ANY,
1573                                 "monitor RDN \"%s\" is invalid\n", 
1574                                 dn.bv_val, 0, 0 );
1575                         return( -1 );
1576                 }
1577
1578                 dn.bv_len += sizeof( SLAPD_MONITOR_DN ); /* 1 for the , */
1579                 dn.bv_val = ch_malloc( dn.bv_len + 1 );
1580                 strcpy( dn.bv_val , monitor_subsys[ i ]->mss_rdn.bv_val );
1581                 strcat( dn.bv_val, "," SLAPD_MONITOR_DN );
1582                 rc = dnPrettyNormal( NULL, &dn, &monitor_subsys[ i ]->mss_dn,
1583                         &monitor_subsys[ i ]->mss_ndn, NULL );
1584                 free( dn.bv_val );
1585                 if ( rc != LDAP_SUCCESS ) {
1586                         Debug( LDAP_DEBUG_ANY,
1587                                 "monitor DN \"%s\" is invalid\n", 
1588                                 dn.bv_val, 0, 0 );
1589                         return( -1 );
1590                 }
1591
1592                 snprintf( buf, sizeof( buf ),
1593                                 "dn: %s\n"
1594                                 "objectClass: %s\n"
1595                                 "structuralObjectClass: %s\n"
1596                                 "cn: %s\n"
1597                                 "creatorsName: %s\n"
1598                                 "modifiersName: %s\n"
1599                                 "createTimestamp: %s\n"
1600                                 "modifyTimestamp: %s\n",
1601                                 monitor_subsys[ i ]->mss_dn.bv_val,
1602                                 mi->mi_oc_monitorContainer->soc_cname.bv_val,
1603                                 mi->mi_oc_monitorContainer->soc_cname.bv_val,
1604                                 monitor_subsys[ i ]->mss_name,
1605                                 mi->mi_creatorsName.bv_val,
1606                                 mi->mi_creatorsName.bv_val,
1607                                 mi->mi_startTime.bv_val,
1608                                 mi->mi_startTime.bv_val );
1609                 
1610                 e = str2entry( buf );
1611                 
1612                 if ( e == NULL) {
1613                         Debug( LDAP_DEBUG_ANY,
1614                                 "unable to create \"%s\" entry\n", 
1615                                 monitor_subsys[ i ]->mss_dn.bv_val, 0, 0 );
1616                         return( -1 );
1617                 }
1618
1619                 if ( !BER_BVISNULL( &monitor_subsys[ i ]->mss_desc[ 0 ] ) ) {
1620                         attr_merge_normalize( e, slap_schema.si_ad_description,
1621                                         monitor_subsys[ i ]->mss_desc, NULL );
1622                 }
1623
1624                 mp = monitor_entrypriv_create();
1625                 if ( mp == NULL ) {
1626                         return -1;
1627                 }
1628                 e->e_private = ( void * )mp;
1629                 mp->mp_info = monitor_subsys[ i ];
1630                 mp->mp_flags = monitor_subsys[ i ]->mss_flags;
1631
1632                 if ( monitor_cache_add( mi, e ) ) {
1633                         Debug( LDAP_DEBUG_ANY,
1634                                 "unable to add entry \"%s\" to cache\n",
1635                                 monitor_subsys[ i ]->mss_dn.bv_val, 0, 0 );
1636                         return -1;
1637                 }
1638
1639                 *ep = e;
1640                 ep = &mp->mp_next;
1641         }
1642
1643         assert( be != NULL );
1644
1645         be->be_private = mi;
1646         
1647         /*
1648          * opens the monitor backend subsystems
1649          */
1650         for ( ms = monitor_subsys; ms[ 0 ] != NULL; ms++ ) {
1651                 if ( ms[ 0 ]->mss_open && ( *ms[ 0 ]->mss_open )( be, ms[ 0 ] ) )
1652                 {
1653                         return( -1 );
1654                 }
1655                 ms[ 0 ]->mss_flags |= MONITOR_F_OPENED;
1656         }
1657
1658         monitor_subsys_opened = 1;
1659
1660         if ( mi->mi_entry_limbo ) {
1661                 entry_limbo_t   *el = (entry_limbo_t *)mi->mi_entry_limbo;
1662
1663                 for ( ; el; ) {
1664                         entry_limbo_t   *tmp;
1665
1666                         switch ( el->el_type ) {
1667                         case LIMBO_ENTRY:
1668                                 monitor_back_register_entry(
1669                                                 el->el_e,
1670                                                 el->el_cb );
1671                                 break;
1672
1673                         case LIMBO_ENTRY_PARENT:
1674                                 monitor_back_register_entry_parent(
1675                                                 el->el_e,
1676                                                 el->el_cb,
1677                                                 &el->el_base,
1678                                                 el->el_scope,
1679                                                 &el->el_filter );
1680                                 break;
1681                                 
1682
1683                         case LIMBO_ATTRS:
1684                                 monitor_back_register_entry_attrs(
1685                                                 &el->el_ndn,
1686                                                 el->el_a,
1687                                                 el->el_cb,
1688                                                 &el->el_base,
1689                                                 el->el_scope,
1690                                                 &el->el_filter );
1691                                 break;
1692
1693                         case LIMBO_CB:
1694                                 monitor_back_register_entry_callback(
1695                                                 &el->el_ndn,
1696                                                 el->el_cb,
1697                                                 &el->el_base,
1698                                                 el->el_scope,
1699                                                 &el->el_filter );
1700                                 break;
1701
1702                         default:
1703                                 assert( 0 );
1704                         }
1705
1706                         if ( el->el_e ) {
1707                                 entry_free( el->el_e );
1708                         }
1709                         if ( el->el_a ) {
1710                                 attrs_free( el->el_a );
1711                         }
1712                         if ( !BER_BVISNULL( &el->el_ndn ) ) {
1713                                 ber_memfree( el->el_ndn.bv_val );
1714                         }
1715                         if ( !BER_BVISNULL( &el->el_base ) ) {
1716                                 ber_memfree( el->el_base.bv_val );
1717                         }
1718                         if ( !BER_BVISNULL( &el->el_filter ) ) {
1719                                 ber_memfree( el->el_filter.bv_val );
1720                         }
1721
1722                         tmp = el;
1723                         el = el->el_next;
1724                         ch_free( tmp );
1725                 }
1726
1727                 mi->mi_entry_limbo = NULL;
1728         }
1729
1730         return( 0 );
1731 }
1732
1733 int
1734 monitor_back_config(
1735         BackendInfo     *bi,
1736         const char      *fname,
1737         int             lineno,
1738         int             argc,
1739         char            **argv )
1740 {
1741         /*
1742          * eventually, will hold backend specific configuration parameters
1743          */
1744         return SLAP_CONF_UNKNOWN;
1745 }
1746
1747 int
1748 monitor_back_db_config(
1749         Backend     *be,
1750         const char  *fname,
1751         int         lineno,
1752         int         argc,
1753         char        **argv )
1754 {
1755 #if 0
1756         monitor_info_t  *mi = ( monitor_info_t * )be->be_private;
1757 #endif
1758
1759         /*
1760          * eventually, will hold database specific configuration parameters
1761          */
1762         return SLAP_CONF_UNKNOWN;
1763 }
1764
1765 int
1766 monitor_back_db_destroy(
1767         BackendDB       *be )
1768 {
1769         monitor_info_t  *mi = ( monitor_info_t * )be->be_private;
1770
1771         /*
1772          * FIXME: destroys all the data
1773          */
1774         /* NOTE: mi points to static storage; don't free it */
1775         
1776         (void)monitor_cache_destroy( mi );
1777
1778         if ( monitor_subsys ) {
1779                 int     i;
1780
1781                 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
1782                         if ( monitor_subsys[ i ]->mss_destroy ) {
1783                                 monitor_subsys[ i ]->mss_destroy( be, monitor_subsys[ i ] );
1784                         }
1785
1786                         if ( !BER_BVISNULL( &monitor_subsys[ i ]->mss_rdn ) ) {
1787                                 ch_free( monitor_subsys[ i ]->mss_rdn.bv_val );
1788                         }
1789                 }
1790
1791                 ch_free( monitor_subsys );
1792         }
1793         
1794         return 0;
1795 }
1796
1797 #if SLAPD_MONITOR == SLAPD_MOD_DYNAMIC
1798
1799 /* conditionally define the init_module() function */
1800 SLAP_BACKEND_INIT_MODULE( monitor )
1801
1802 #endif /* SLAPD_MONITOR == SLAPD_MOD_DYNAMIC */
1803