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