]> git.sur5r.net Git - openldap/blob - servers/slapd/back-monitor/init.c
slight improvement
[openldap] / servers / slapd / back-monitor / init.c
1 /* init.c - initialize monitor backend */
2 /*
3  * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
4  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5  */
6 /*
7  * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
8  * 
9  * This work has beed deveolped for the OpenLDAP Foundation 
10  * in the hope that it may be useful to the Open Source community, 
11  * but WITHOUT ANY WARRANTY.
12  * 
13  * Permission is granted to anyone to use this software for any purpose
14  * on any computer system, and to alter it and redistribute it, subject
15  * to the following restrictions:
16  * 
17  * 1. The author and SysNet s.n.c. are not responsible for the consequences
18  *    of use of this software, no matter how awful, even if they arise from
19  *    flaws in it.
20  * 
21  * 2. The origin of this software must not be misrepresented, either by
22  *    explicit claim or by omission.  Since few users ever read sources,
23  *    credits should appear in the documentation.
24  * 
25  * 3. Altered versions must be plainly marked as such, and must not be
26  *    misrepresented as being the original software.  Since few users
27  *    ever read sources, credits should appear in the documentation.
28  *    SysNet s.n.c. cannot be responsible for the consequences of the
29  *    alterations.
30  * 
31  * 4. This notice may not be removed or altered.
32  */
33
34 #include "portable.h"
35
36 #include <stdio.h>
37 #include <ac/string.h>
38
39 #include "slap.h"
40 #include "lber_pvt.h"
41 #include "back-monitor.h"
42
43 /*
44  * used by many functions to add description to entries
45  */
46 AttributeDescription *monitor_ad_desc = NULL;
47 BackendDB *be_monitor = NULL;
48
49 /*
50  * subsystem data
51  */
52 struct monitorsubsys monitor_subsys[] = {
53         { 
54                 SLAPD_MONITOR_LISTENER, SLAPD_MONITOR_LISTENER_NAME,    
55                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
56                 MONITOR_F_PERSISTENT_CH,
57                 monitor_subsys_listener_init,
58                 NULL,   /* update */
59                 NULL,   /* create */
60                 NULL    /* modify */
61         }, { 
62                 SLAPD_MONITOR_DATABASE, SLAPD_MONITOR_DATABASE_NAME,    
63                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
64                 MONITOR_F_PERSISTENT_CH,
65                 monitor_subsys_database_init,
66                 NULL,   /* update */
67                 NULL,   /* create */
68                 NULL    /* modify */
69         }, { 
70                 SLAPD_MONITOR_BACKEND, SLAPD_MONITOR_BACKEND_NAME, 
71                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
72                 MONITOR_F_PERSISTENT_CH,
73                 monitor_subsys_backend_init,
74                 NULL,   /* update */
75                 NULL,   /* create */
76                 NULL    /* modify */
77         }, { 
78                 SLAPD_MONITOR_THREAD, SLAPD_MONITOR_THREAD_NAME,        
79                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
80                 MONITOR_F_NONE,
81                 monitor_subsys_thread_init,
82                 monitor_subsys_thread_update,
83                 NULL,   /* create */
84                 NULL    /* modify */
85         }, { 
86                 SLAPD_MONITOR_SASL, SLAPD_MONITOR_SASL_NAME,    
87                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
88                 MONITOR_F_NONE,
89                 NULL,   /* init */
90                 NULL,   /* update */
91                 NULL,   /* create */
92                 NULL    /* modify */
93         }, { 
94                 SLAPD_MONITOR_TLS, SLAPD_MONITOR_TLS_NAME,
95                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
96                 MONITOR_F_NONE,
97                 NULL,   /* init */
98                 NULL,   /* update */
99                 NULL,   /* create */
100                 NULL    /* modify */
101         }, { 
102                 SLAPD_MONITOR_CONN, SLAPD_MONITOR_CONN_NAME,
103                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
104                 MONITOR_F_VOLATILE_CH,
105                 monitor_subsys_conn_init,
106                 monitor_subsys_conn_update,
107                 monitor_subsys_conn_create,
108                 NULL    /* modify */
109         }, { 
110                 SLAPD_MONITOR_READW, SLAPD_MONITOR_READW_NAME,
111                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
112                 MONITOR_F_NONE,
113                 NULL,   /* init */
114                 monitor_subsys_readw_update,
115                 NULL,   /* create */
116                 NULL    /* modify */
117         }, { 
118                 SLAPD_MONITOR_WRITEW, SLAPD_MONITOR_WRITEW_NAME,
119                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
120                 MONITOR_F_NONE,
121                 NULL,   /* init */
122                 monitor_subsys_writew_update,
123                 NULL,   /* create */
124                 NULL    /* modify */
125         }, { 
126                 SLAPD_MONITOR_LOG, SLAPD_MONITOR_LOG_NAME,
127                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
128                 MONITOR_F_NONE,
129                 monitor_subsys_log_init,
130                 NULL,   /* update */
131                 NULL,   /* create */
132                 monitor_subsys_log_modify
133         }, { 
134                 SLAPD_MONITOR_OPS, SLAPD_MONITOR_OPS_NAME,
135                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
136                 MONITOR_F_PERSISTENT_CH,
137                 monitor_subsys_ops_init,
138                 monitor_subsys_ops_update,
139                 NULL,   /* create */
140                 NULL,   /* modify */
141         }, { 
142                 SLAPD_MONITOR_SENT, SLAPD_MONITOR_SENT_NAME,
143                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
144                 MONITOR_F_PERSISTENT_CH,
145                 monitor_subsys_sent_init,
146                 monitor_subsys_sent_update,
147                 NULL,   /* create */
148                 NULL,   /* modify */
149         }, { 
150                 SLAPD_MONITOR_TIME, SLAPD_MONITOR_TIME_NAME,
151                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
152                 MONITOR_F_PERSISTENT_CH,
153                 monitor_subsys_time_init,
154                 monitor_subsys_time_update,
155                 NULL,   /* create */
156                 NULL,   /* modify */
157         }, { -1, NULL }
158 };
159
160 #ifdef SLAPD_MONITOR_DYNAMIC
161
162 int
163 back_monitor_LTX_init_module( int argc, char *argv[] )
164 {
165         BackendInfo bi;
166
167         memset( &bi, '\0', sizeof(bi) );
168         bi.bi_type = "monitor";
169         bi.bi_init = monitor_back_initialize;
170         backend_add( &bi );
171         return 0;
172 }
173
174 #endif /* SLAPD_MONITOR_DYNAMIC */
175
176 int
177 monitor_back_initialize(
178         BackendInfo     *bi
179 )
180 {
181         static char *controls[] = {
182                 LDAP_CONTROL_MANAGEDSAIT,
183                 LDAP_CONTROL_VALUESRETURNFILTER,
184                 NULL
185         };
186
187         bi->bi_controls = controls;
188
189         bi->bi_init = 0;
190         bi->bi_open = 0;
191         bi->bi_config = monitor_back_config;
192         bi->bi_close = 0;
193         bi->bi_destroy = 0;
194
195         bi->bi_db_init = monitor_back_db_init;
196         bi->bi_db_config = monitor_back_db_config;
197         bi->bi_db_open = monitor_back_db_open;
198         bi->bi_db_close = 0;
199         bi->bi_db_destroy = monitor_back_db_destroy;
200
201         bi->bi_op_bind = monitor_back_bind;
202         bi->bi_op_unbind = 0;
203         bi->bi_op_search = monitor_back_search;
204         bi->bi_op_compare = monitor_back_compare;
205         bi->bi_op_modify = monitor_back_modify;
206         bi->bi_op_modrdn = 0;
207         bi->bi_op_add = 0;
208         bi->bi_op_delete = 0;
209         bi->bi_op_abandon = 0;
210
211         bi->bi_extended = 0;
212
213         bi->bi_entry_release_rw = 0;
214         bi->bi_chk_referrals = 0;
215         bi->bi_operational = monitor_back_operational;
216
217         /*
218          * hooks for slap tools
219          */
220         bi->bi_tool_entry_open = 0;
221         bi->bi_tool_entry_close = 0;
222         bi->bi_tool_entry_first = 0;
223         bi->bi_tool_entry_next = 0;
224         bi->bi_tool_entry_get = 0;
225         bi->bi_tool_entry_put = 0;
226         bi->bi_tool_entry_reindex = 0;
227         bi->bi_tool_sync = 0;
228
229         bi->bi_connection_init = 0;
230         bi->bi_connection_destroy = 0;
231
232         return 0;
233 }
234
235 int
236 monitor_back_db_init(
237         BackendDB       *be
238 )
239 {
240         struct monitorinfo      *mi;
241         Entry                   *e, *e_tmp;
242         struct monitorentrypriv *mp;
243         int                     i, rc;
244         char                    buf[1024], *end_of_line;
245         struct berval           dn, ndn;
246         const char              *text;
247         struct berval           bv;
248         struct m_s {
249                 char    *name;
250                 char    *schema;
251                 int     offset;
252         } moc[] = {
253                 { "monitorServer", "( 1.3.6.1.4.1.4203.666.XXX "
254                         "NAME 'monitorServer' "
255                         "DESC 'Server monitoring root entry' "
256                         "SUP monitor STRUCTURAL)",
257                         offsetof(struct monitorinfo, monitor_oc_monitorServer) },
258                 { "monitorContainer", "( 1.3.6.1.4.1.4203.666.XXX "
259                         "NAME 'monitorContainer' "
260                         "DESC 'monitor container class' "
261                         "SUP monitor STRUCTURAL)",
262                         offsetof(struct monitorinfo, monitor_oc_monitorContainer) },
263                 { "monitorCounter", "( 1.3.6.1.4.1.4203.666.XXX "
264                         "NAME 'monitorCounter' "
265                         "DESC 'monitor counter class' "
266                         "SUP monitor STRUCTURAL)",
267                         offsetof(struct monitorinfo, monitor_oc_monitorCounter) },
268                 { "monitorOperation", "( 1.3.6.1.4.1.4203.666.XXX "
269                         "NAME 'monitorOperation' "
270                         "DESC 'monitor operation class' "
271                         "SUP monitor STRUCTURAL)",
272                         offsetof(struct monitorinfo, monitor_oc_monitorOperation) },
273                 { "monitorConnection", "( 1.3.6.1.4.1.4203.666.XXX "
274                         "NAME 'monitorConnection' "
275                         "DESC 'monitor connection class' "
276                         "SUP monitor STRUCTURAL)",
277                         offsetof(struct monitorinfo, monitor_oc_monitorConnection) },
278                 { "managedObject", "( 1.3.6.1.4.1.4203.666.XXX "
279                         "NAME 'managedObject' "
280                         "DESC 'monitor managed entity class' "
281                         "SUP monitor STRUCTURAL)",
282                         offsetof(struct monitorinfo, monitor_oc_managedObject) },
283                 { "monitoredObject", "( 1.3.6.1.4.1.4203.666.XXX "
284                         "NAME 'monitoredObject' "
285                         "DESC 'monitor monitored entity class' "
286                         "SUP monitor STRUCTURAL)",
287                         offsetof(struct monitorinfo, monitor_oc_monitoredObject) },
288                 { NULL, NULL, -1 }
289         }, mat[] = {
290                 { "monitoredInfo", "( 1.3.6.1.4.1.4203.666.XXX"
291                         "NAME 'monitoredInfo' "
292                         "DESC 'monitored info' "
293                         "SUP name "
294                         "NO-USER-MODIFICATION )",
295                         offsetof(struct monitorinfo, monitor_ad_monitoredInfo) },
296                 { "managedInfo", "( 1.3.6.1.4.1.4203.666.XXX"
297                         "NAME 'managedInfo' "
298                         "DESC 'monitor managed info' "
299                         "SUP name )",
300                         offsetof(struct monitorinfo, monitor_ad_managedInfo) },
301                 { "monitorCounter", "( 1.3.6.1.4.1.4203.666.XXX"
302                         "NAME 'monitorCounter' "
303                         "DESC 'monitor counter' "
304                         "EQUALITY integerMatch "
305                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 "
306                         "NO-USER-MODIFICATION )",
307                         offsetof(struct monitorinfo, monitor_ad_monitorCounter) },
308                 { "monitorOpCompleted", "( 1.3.6.1.4.1.4203.666.XXX"
309                         "NAME 'monitorOpCompleted' "
310                         "DESC 'monitor completed operations' "
311                         "SUP monitorCounter )",
312                         offsetof(struct monitorinfo, monitor_ad_monitorOpCompleted) },
313                 { "monitorOpInitiated", "( 1.3.6.1.4.1.4203.666.XXX"
314                         "NAME 'monitorOpInitiated' "
315                         "DESC 'monitor initiated operations' "
316                         "SUP monitorCounter )",
317                         offsetof(struct monitorinfo, monitor_ad_monitorOpInitiated) },
318                 { "monitorConnectionNumber", "( 1.3.6.1.4.1.4203.666.XXX"
319                         "NAME 'monitorConnectionNumber' "
320                         "DESC 'monitor connection number' "
321                         "SUP monitorCounter )",
322                         offsetof(struct monitorinfo, monitor_ad_monitorConnectionNumber) },
323                 { "monitorConnectionAuthzDN", "( 1.3.6.1.4.1.4203.666.XXX"
324                         "NAME 'monitorConnectionAuthzDN' "
325                         "DESC 'monitor connection authorization DN' "
326                         "SUP distinguishedName "
327                         "NO-USER-MODIFICATION )",
328                         offsetof(struct monitorinfo, monitor_ad_monitorConnectionAuthzDN) },
329                 { "monitorConnectionLocalAddress", "( 1.3.6.1.4.1.4203.666.XXX"
330                         "NAME 'monitorConnectionLocalAddress' "
331                         "DESC 'monitor connection local address' "
332                         "SUP monitoredInfo)",
333                         offsetof(struct monitorinfo, monitor_ad_monitorConnectionLocalAddress) },
334                 { "monitorConnectionPeerAddress", "( 1.3.6.1.4.1.4203.666.XXX"
335                         "NAME 'monitorConnectionPeerAddress' "
336                         "DESC 'monitor connection peer address' "
337                         "SUP monitoredInfo)",
338                         offsetof(struct monitorinfo, monitor_ad_monitorConnectionPeerAddress) },
339                 { NULL, NULL, -1 }
340         };
341
342         /*
343          * database monitor can be defined once only
344          */
345         if ( be_monitor ) {
346 #ifdef NEW_LOGGING
347                 LDAP_LOG( OPERATION, CRIT,
348                         "only one monitor backend is allowed\n", 0, 0, 0);
349 #else
350                 Debug( LDAP_DEBUG_ANY,
351                         "only one monitor backend is allowed\n", 0, 0, 0 );
352 #endif
353                 return( -1 );
354         }
355         be_monitor = be;
356
357         /* indicate system schema supported */
358         be->be_flags |= SLAP_BFLAG_MONITOR;
359
360         dn.bv_val = SLAPD_MONITOR_DN;
361         dn.bv_len = sizeof( SLAPD_MONITOR_DN ) - 1;
362
363         rc = dnNormalize2( NULL, &dn, &ndn, NULL );
364         if( rc != LDAP_SUCCESS ) {
365 #ifdef NEW_LOGGING
366                 LDAP_LOG( OPERATION, CRIT,
367                         "unable to normalize monitor DN \"" SLAPD_MONITOR_DN
368                         "\"\n" , 0, 0, 0 );
369 #else
370                 Debug( LDAP_DEBUG_ANY,
371                         "unable to normalize monitor DN \"" SLAPD_MONITOR_DN
372                         "\"\n", 0, 0, 0 );
373 #endif
374                 return -1;
375         }
376
377         ber_dupbv( &bv, &dn );
378         ber_bvarray_add( &be->be_suffix, &bv );
379         ber_bvarray_add( &be->be_nsuffix, &ndn );
380
381         mi = ( struct monitorinfo * )ch_calloc( sizeof( struct monitorinfo ), 1 );
382         if ( mi == NULL ) {
383                 return -1;
384         }
385
386         ldap_pvt_thread_mutex_init( &mi->mi_cache_mutex );
387
388         for ( i = 0; moc[i].name; i++ ) {
389                 LDAPObjectClass         *oc;
390                 int                     code;
391                 const char              *err;
392                 ObjectClass             *Oc;
393
394                 oc = ldap_str2objectclass(moc[i].schema, &code, &err,
395                                 LDAP_SCHEMA_ALLOW_ALL );
396                 if ( !oc ) {
397 #ifdef NEW_LOGGING
398                         LDAP_LOG( OPERATION, CRIT,
399                                 "unable to parse monitor objectclass '%s' "
400                                 "(%s before %s)\n" , moc[i].name,
401                                 ldap_scherr2str(code), err );
402 #else
403                         Debug( LDAP_DEBUG_ANY,
404                                 "unable to parse monitor objectclass '%s' "
405                                 "(%s before %s)\n" , moc[i].name,
406                                 ldap_scherr2str(code), err );
407 #endif
408                         return -1;
409                 }
410
411                 if ( oc->oc_oid == NULL ) {
412 #ifdef NEW_LOGGING
413                         LDAP_LOG( OPERATION, CRIT,
414                                 "objectclass '%s' has no OID\n" ,
415                                 moc[i].name, 0, 0 );
416 #else
417                         Debug( LDAP_DEBUG_ANY,
418                                 "objectclass '%s' has no OID\n" ,
419                                 moc[i].name, 0, 0 );
420 #endif
421                         return -1;
422                 }
423
424                 code = oc_add(oc,1,&err);
425                 if ( code ) {
426 #ifdef NEW_LOGGING
427                         LDAP_LOG( OPERATION, CRIT,
428                                 "objectclass '%s' (%s before %s)\n" ,
429                                 moc[i].name, scherr2str(code), err );
430 #else
431                         Debug( LDAP_DEBUG_ANY,
432                                 "objectclass '%s' (%s before %s)\n" ,
433                                 moc[i].name, scherr2str(code), err );
434 #endif
435                         return -1;
436                 }
437
438                 ldap_memfree(oc);
439
440                 Oc = oc_find( moc[i].name );
441                 if ( Oc == NULL ) {
442                         return -1;
443                 }
444
445                 ((ObjectClass **)&(((char *)mi)[moc[i].offset]))[0] = Oc;
446         }
447
448         for ( i = 0; mat[i].name; i++ ) {
449                 LDAPAttributeType *at;
450                 int             code;
451                 const char      *err;
452                 AttributeDescription **ad;
453
454                 at = ldap_str2attributetype( mat[i].schema, &code,
455                                 &err, LDAP_SCHEMA_ALLOW_ALL );
456                 if ( !at ) {
457                         return 1;
458                 }
459
460                 if ( at->at_oid == NULL ) {
461                         return 1;
462                 }
463
464                 /* operational attributes should be defined internally
465                 if ( at->at_usage ) {
466                         fprintf( stderr, "%s: line %d: attribute type \"%s\" is operational\n",
467                                  fname, lineno, at->at_oid );
468                         return 1;
469                 } */
470
471                 code = at_add(at,&err);
472                 if ( code ) {
473                         return 1;
474                 }
475                 ldap_memfree(at);
476
477                 ad = ((AttributeDescription **)&(((char *)mi)[mat[i].offset]));
478                 ad[0] = NULL;
479                 if ( slap_str2ad( mat[i].name, ad, &text ) ) {
480 #ifdef NEW_LOGGING
481                         LDAP_LOG( OPERATION, CRIT,
482                                 "monitor_back_db_init: %s\n", text, 0, 0 );
483 #else
484                         Debug( LDAP_DEBUG_ANY,
485                                 "monitor_subsys_backend_init: %s\n%s%s", 
486                                 text, "", "" );
487 #endif
488                         return -1;
489                 }
490         }
491
492         if ( slap_str2ad( "description", &mi->monitor_ad_description, &text ) ) {
493 #ifdef NEW_LOGGING
494                 LDAP_LOG( OPERATION, CRIT,
495                         "monitor_back_db_init: %s\n", text, 0, 0 );
496 #else
497                 Debug( LDAP_DEBUG_ANY,
498                         "monitor_subsys_backend_init: %s\n%s%s", 
499                         text, "", "" );
500 #endif
501                 return( -1 );
502         }
503
504         /*      
505          * Create all the subsystem specific entries
506          */
507         e_tmp = NULL;
508         for ( i = 0; monitor_subsys[ i ].mss_name != NULL; i++ ) {
509                 int             len = strlen( monitor_subsys[ i ].mss_name );
510                 struct berval   dn;
511                 int             rc;
512
513                 dn.bv_len = len + sizeof( "cn=" ) - 1;
514                 dn.bv_val = ch_calloc( sizeof( char ), dn.bv_len + 1 );
515                 strcpy( dn.bv_val, "cn=" );
516                 strcat( dn.bv_val, monitor_subsys[ i ].mss_name );
517                 rc = dnPretty2( NULL, &dn, &monitor_subsys[ i ].mss_rdn, NULL );
518                 free( dn.bv_val );
519                 if ( rc != LDAP_SUCCESS ) {
520 #ifdef NEW_LOGGING
521                         LDAP_LOG( OPERATION, CRIT,
522                                 "monitor RDN \"%s\" is invalid\n", 
523                                 dn.bv_val, 0, 0 );
524 #else
525                         Debug( LDAP_DEBUG_ANY,
526                                 "monitor RDN \"%s\" is invalid\n", 
527                                 dn.bv_val, 0, 0 );
528 #endif
529                         return( -1 );
530                 }
531
532                 dn.bv_len += sizeof( SLAPD_MONITOR_DN ); /* 1 for the , */
533                 dn.bv_val = ch_malloc( dn.bv_len + 1 );
534                 strcpy( dn.bv_val , monitor_subsys[ i ].mss_rdn.bv_val );
535                 strcat( dn.bv_val, "," SLAPD_MONITOR_DN );
536                 rc = dnPrettyNormal( NULL, &dn, &monitor_subsys[ i ].mss_dn,
537                         &monitor_subsys[ i ].mss_ndn, NULL );
538                 free( dn.bv_val );
539                 if ( rc != LDAP_SUCCESS ) {
540 #ifdef NEW_LOGGING
541                         LDAP_LOG( OPERATION, CRIT,
542                                 "monitor DN \"%s\" is invalid\n", 
543                                 dn.bv_val, 0, 0 );
544 #else
545                         Debug( LDAP_DEBUG_ANY,
546                                 "monitor DN \"%s\" is invalid\n", 
547                                 dn.bv_val, 0, 0 );
548 #endif
549                         return( -1 );
550                 }
551
552                 snprintf( buf, sizeof( buf ),
553                                 "dn: %s\n"
554                                 SLAPD_MONITOR_OBJECTCLASSES 
555                                 "cn: %s\n",
556                                 monitor_subsys[ i ].mss_dn.bv_val,
557                                 monitor_subsys[ i ].mss_name );
558                 
559                 e = str2entry( buf );
560                 
561                 if ( e == NULL) {
562 #ifdef NEW_LOGGING
563                         LDAP_LOG( OPERATION, CRIT,
564                                 "unable to create '%s' entry\n", 
565                                 monitor_subsys[ i ].mss_dn.bv_val, 0, 0 );
566 #else
567                         Debug( LDAP_DEBUG_ANY,
568                                 "unable to create '%s' entry\n", 
569                                 monitor_subsys[ i ].mss_dn.bv_val, 0, 0 );
570 #endif
571                         return( -1 );
572                 }
573
574                 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
575                 e->e_private = ( void * )mp;
576                 mp->mp_info = &monitor_subsys[ i ];
577                 mp->mp_children = NULL;
578                 mp->mp_next = e_tmp;
579                 mp->mp_flags = monitor_subsys[ i ].mss_flags;
580
581                 if ( monitor_cache_add( mi, e ) ) {
582 #ifdef NEW_LOGGING
583                         LDAP_LOG( OPERATION, CRIT,
584                                 "unable to add entry '%s' to cache\n",
585                                 monitor_subsys[ i ].mss_dn.bv_val, 0, 0 );
586 #else
587                         Debug( LDAP_DEBUG_ANY,
588                                 "unable to add entry '%s' to cache\n",
589                                 monitor_subsys[ i ].mss_dn.bv_val, 0, 0 );
590 #endif
591                         return -1;
592                 }
593
594                 e_tmp = e;
595         }
596
597         /*
598          * creates the "cn=Monitor" entry 
599          */
600         snprintf( buf, sizeof( buf ), 
601                         "dn: " SLAPD_MONITOR_DN "\n"
602                         "objectClass: top\n"
603                         "objectClass: monitor\n"
604                         "objectClass: extensibleObject\n"
605                         "structuralObjectClass: monitor\n"
606                         "cn: Monitor" );
607
608         e = str2entry( buf );
609         if ( e == NULL) {
610 #ifdef NEW_LOGGING
611                 LDAP_LOG( OPERATION, CRIT,
612                         "unable to create '%s' entry\n",
613                         SLAPD_MONITOR_DN, 0, 0 );
614 #else
615                 Debug( LDAP_DEBUG_ANY,
616                         "unable to create '%s' entry\n%s%s",
617                         SLAPD_MONITOR_DN, "", "" );
618 #endif
619                 return( -1 );
620         }
621         bv.bv_val = (char *) Versionstr;
622         end_of_line = strchr( Versionstr, '\n' );
623         if ( end_of_line ) {
624                 bv.bv_len = end_of_line - Versionstr;
625         } else {
626                 bv.bv_len = strlen( Versionstr );
627         }
628         if ( attr_merge_normalize_one( e, monitor_ad_desc, &bv, NULL ) ) {
629 #ifdef NEW_LOGGING
630                 LDAP_LOG( OPERATION, CRIT,
631                         "unable to add description to '%s' entry\n",
632                         SLAPD_MONITOR_DN, 0, 0 );
633 #else
634                 Debug( LDAP_DEBUG_ANY,
635                         "unable to add description to '%s' entry\n%s%s",
636                         SLAPD_MONITOR_DN, "", "" );
637 #endif
638                 return( -1 );
639         }
640
641         mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
642         e->e_private = ( void * )mp;
643
644         mp->mp_info = NULL;
645         mp->mp_children = e_tmp;
646         mp->mp_next = NULL;
647
648         if ( monitor_cache_add( mi, e ) ) {
649 #ifdef NEW_LOGGING
650                 LDAP_LOG( OPERATION, CRIT,
651                         "unable to add entry '%s' to cache\n",
652                         SLAPD_MONITOR_DN, 0, 0 );
653 #else
654                 Debug( LDAP_DEBUG_ANY,
655                         "unable to add entry '%s' to cache\n%s%s",
656                         SLAPD_MONITOR_DN, "", "" );
657 #endif
658                 return -1;
659         }
660
661         be->be_private = mi;
662         
663         return 0;
664 }
665
666 int
667 monitor_back_db_open(
668         BackendDB       *be
669 )
670 {
671         struct monitorsubsys    *ms;
672
673         assert( be );
674
675         /*
676          * opens the monitor backend
677          */
678         for ( ms = monitor_subsys; ms->mss_name != NULL; ms++ ) {
679                 if ( ms->mss_init && ( *ms->mss_init )( be ) ) {
680                         return( -1 );
681                 }
682         }
683
684         return( 0 );
685 }
686
687 int
688 monitor_back_config(
689         BackendInfo     *bi,
690         const char      *fname,
691         int             lineno,
692         int             argc,
693         char            **argv
694 )
695 {
696         /*
697          * eventually, will hold backend specific configuration parameters
698          */
699         return 0;
700 }
701
702 int
703 monitor_back_db_config(
704         Backend     *be,
705         const char  *fname,
706         int         lineno,
707         int         argc,
708         char        **argv
709 )
710 {
711         /*
712          * eventually, will hold database specific configuration parameters
713          */
714 #ifdef NEW_LOGGING
715         LDAP_LOG( CONFIG, INFO,
716                 "line %d of file '%s' will be ignored\n", lineno, fname, 0 );
717 #else
718         Debug( LDAP_DEBUG_CONFIG, 
719                 "line %d of file '%s' will be ignored\n%s", lineno, fname, "" );
720 #endif
721         return( 0 );
722 }
723
724 int
725 monitor_back_db_destroy(
726         BackendDB       *be
727 )
728 {
729         /*
730          * FIXME: destroys all the data
731          */
732         return 0;
733 }
734