]> git.sur5r.net Git - openldap/blob - servers/slapd/back-monitor/init.c
997a194adb699eaae05bbdf6b9128ae7c9437b32
[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.3.7 "
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.3.8 "
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.3.8 "
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.3.9 "
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.3.10 "
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.3.11 "
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.3.12 "
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.1.14 "
293                         "NAME 'monitoredInfo' "
294                         "DESC 'monitored info' "
295                         /* "SUP name " */
296                         "EQUALITY caseIgnoreMatch "
297                         "SUBSTR caseIgnoreSubstringsMatch "
298                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} "
299                         "NO-USER-MODIFICATION "
300                         "USAGE directoryOperation )",
301                         offsetof(struct monitorinfo, monitor_ad_monitoredInfo) },
302                 { "managedInfo", "( 1.3.6.1.4.1.4203.666.1.15 "
303                         "NAME 'managedInfo' "
304                         "DESC 'monitor managed info' "
305                         "SUP name )",
306                         offsetof(struct monitorinfo, monitor_ad_managedInfo) },
307                 { "monitorCounter", "( 1.3.6.1.4.1.4203.666.1.16 "
308                         "NAME 'monitorCounter' "
309                         "DESC 'monitor counter' "
310                         "EQUALITY integerMatch "
311                         "ORDERING integerOrderingMatch "
312                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 "
313                         "NO-USER-MODIFICATION "
314                         "USAGE directoryOperation )",
315                         offsetof(struct monitorinfo, monitor_ad_monitorCounter) },
316                 { "monitorOpCompleted", "( 1.3.6.1.4.1.4203.666.1.17 "
317                         "NAME 'monitorOpCompleted' "
318                         "DESC 'monitor completed operations' "
319                         "SUP monitorCounter "
320                         "NO-USER-MODIFICATION "
321                         "USAGE directoryOperation )",
322                         offsetof(struct monitorinfo, monitor_ad_monitorOpCompleted) },
323                 { "monitorOpInitiated", "( 1.3.6.1.4.1.4203.666.1.18 "
324                         "NAME 'monitorOpInitiated' "
325                         "DESC 'monitor initiated operations' "
326                         "SUP monitorCounter "
327                         "NO-USER-MODIFICATION "
328                         "USAGE directoryOperation )",
329                         offsetof(struct monitorinfo, monitor_ad_monitorOpInitiated) },
330                 { "monitorConnectionNumber", "( 1.3.6.1.4.1.4203.666.1.19 "
331                         "NAME 'monitorConnectionNumber' "
332                         "DESC 'monitor connection number' "
333                         "SUP monitorCounter "
334                         "NO-USER-MODIFICATION "
335                         "USAGE directoryOperation )",
336                         offsetof(struct monitorinfo, monitor_ad_monitorConnectionNumber) },
337                 { "monitorConnectionAuthzDN", "( 1.3.6.1.4.1.4203.666.1.20 "
338                         "NAME 'monitorConnectionAuthzDN' "
339                         "DESC 'monitor connection authorization DN' "
340                         /* "SUP distinguishedName " */
341                         "EQUALITY distinguishedNameMatch "
342                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 "
343                         "NO-USER-MODIFICATION "
344                         "USAGE directoryOperation )",
345                         offsetof(struct monitorinfo, monitor_ad_monitorConnectionAuthzDN) },
346                 { "monitorConnectionLocalAddress", "( 1.3.6.1.4.1.4203.666.1.21 "
347                         "NAME 'monitorConnectionLocalAddress' "
348                         "DESC 'monitor connection local address' "
349                         "SUP monitoredInfo "
350                         "NO-USER-MODIFICATION "
351                         "USAGE directoryOperation )",
352                         offsetof(struct monitorinfo,
353                                 monitor_ad_monitorConnectionLocalAddress) },
354                 { "monitorConnectionPeerAddress", "( 1.3.6.1.4.1.4203.666.1.22 "
355                         "NAME 'monitorConnectionPeerAddress' "
356                         "DESC 'monitor connection peer address' "
357                         "SUP monitoredInfo "
358                         "NO-USER-MODIFICATION "
359                         "USAGE directoryOperation )",
360                         offsetof(struct monitorinfo,
361                                 monitor_ad_monitorConnectionPeerAddress) },
362 #endif /* MONITOR_DEVEL */
363                 { NULL, NULL, -1 }
364         };
365
366         /*
367          * database monitor can be defined once only
368          */
369         if ( be_monitor ) {
370 #ifdef NEW_LOGGING
371                 LDAP_LOG( OPERATION, CRIT,
372                         "only one monitor backend is allowed\n", 0, 0, 0);
373 #else
374                 Debug( LDAP_DEBUG_ANY,
375                         "only one monitor backend is allowed\n", 0, 0, 0 );
376 #endif
377                 return( -1 );
378         }
379         be_monitor = be;
380
381         /* indicate system schema supported */
382         be->be_flags |= SLAP_BFLAG_MONITOR;
383
384         dn.bv_val = SLAPD_MONITOR_DN;
385         dn.bv_len = sizeof( SLAPD_MONITOR_DN ) - 1;
386
387         rc = dnNormalize2( NULL, &dn, &ndn, NULL );
388         if( rc != LDAP_SUCCESS ) {
389 #ifdef NEW_LOGGING
390                 LDAP_LOG( OPERATION, CRIT,
391                         "unable to normalize monitor DN \"" SLAPD_MONITOR_DN
392                         "\"\n" , 0, 0, 0 );
393 #else
394                 Debug( LDAP_DEBUG_ANY,
395                         "unable to normalize monitor DN \"" SLAPD_MONITOR_DN
396                         "\"\n", 0, 0, 0 );
397 #endif
398                 return -1;
399         }
400
401         ber_dupbv( &bv, &dn );
402         ber_bvarray_add( &be->be_suffix, &bv );
403         ber_bvarray_add( &be->be_nsuffix, &ndn );
404
405         mi = ( struct monitorinfo * )ch_calloc( sizeof( struct monitorinfo ), 1 );
406         if ( mi == NULL ) {
407 #ifdef NEW_LOGGING
408                 LDAP_LOG( OPERATION, CRIT,
409                         "unable to initialize monitor backend\n", 0, 0, 0 );
410 #else
411                 Debug( LDAP_DEBUG_ANY,
412                         "unable to initialize monitor backend\n", 0, 0, 0 );
413 #endif
414                 return -1;
415         }
416
417         ldap_pvt_thread_mutex_init( &mi->mi_cache_mutex );
418
419         for ( i = 0; moc[i].name; i++ ) {
420                 LDAPObjectClass         *oc;
421                 int                     code;
422                 const char              *err;
423                 ObjectClass             *Oc;
424
425                 oc = ldap_str2objectclass(moc[i].schema, &code, &err,
426                                 LDAP_SCHEMA_ALLOW_ALL );
427                 if ( !oc ) {
428 #ifdef NEW_LOGGING
429                         LDAP_LOG( OPERATION, CRIT,
430                                 "unable to parse monitor objectclass '%s': "
431                                 "%s before %s\n" , moc[i].name,
432                                 ldap_scherr2str(code), err );
433 #else
434                         Debug( LDAP_DEBUG_ANY,
435                                 "unable to parse monitor objectclass '%s': "
436                                 "%s before %s\n" , moc[i].name,
437                                 ldap_scherr2str(code), err );
438 #endif
439                         return -1;
440                 }
441
442                 if ( oc->oc_oid == NULL ) {
443 #ifdef NEW_LOGGING
444                         LDAP_LOG( OPERATION, CRIT,
445                                 "objectclass '%s' has no OID\n" ,
446                                 moc[i].name, 0, 0 );
447 #else
448                         Debug( LDAP_DEBUG_ANY,
449                                 "objectclass '%s' has no OID\n" ,
450                                 moc[i].name, 0, 0 );
451 #endif
452                         return -1;
453                 }
454
455                 code = oc_add(oc,1,&err);
456                 if ( code ) {
457 #ifdef NEW_LOGGING
458                         LDAP_LOG( OPERATION, CRIT,
459                                 "objectclass '%s': %s before %s\n" ,
460                                 moc[i].name, scherr2str(code), err );
461 #else
462                         Debug( LDAP_DEBUG_ANY,
463                                 "objectclass '%s': %s before %s\n" ,
464                                 moc[i].name, scherr2str(code), err );
465 #endif
466                         return -1;
467                 }
468
469                 ldap_memfree(oc);
470
471                 Oc = oc_find( moc[i].name );
472                 if ( Oc == NULL ) {
473                         return -1;
474                 }
475
476                 ((ObjectClass **)&(((char *)mi)[moc[i].offset]))[0] = Oc;
477         }
478
479         for ( i = 0; mat[i].name; i++ ) {
480                 LDAPAttributeType *at;
481                 int             code;
482                 const char      *err;
483                 AttributeDescription **ad;
484
485                 at = ldap_str2attributetype( mat[i].schema, &code,
486                                 &err, LDAP_SCHEMA_ALLOW_ALL );
487                 if ( !at ) {
488 #ifdef NEW_LOGGING
489                         LDAP_LOG( OPERATION, CRIT, "monitor_back_db_init: "
490                                 "in AttributeType '%s' %s before %s\n",
491                                 mat[i].name, ldap_scherr2str(code), err );
492 #else
493                         Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
494                                 "in AttributeType '%s' %s before %s\n",
495                                 mat[i].name, ldap_scherr2str(code), err );
496 #endif
497                         return -1;
498                 }
499
500                 if ( at->at_oid == NULL ) {
501 #ifdef NEW_LOGGING
502                         LDAP_LOG( OPERATION, CRIT, "monitor_back_db_init: "
503                                 "null OID for attributeType '%s'\n",
504                                 mat[i].name, 0, 0 );
505 #else
506                         Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
507                                 "null OID for attributeType '%s'\n",
508                                 mat[i].name, 0, 0 );
509 #endif
510                         return -1;
511                 }
512
513                 code = at_add(at,&err);
514                 if ( code ) {
515 #ifdef NEW_LOGGING
516                         LDAP_LOG( OPERATION, CRIT, "monitor_back_db_init: "
517                                 "%s in attributeType '%s'\n",
518                                 scherr2str(code), mat[i].name, 0 );
519 #else
520                         Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
521                                 "%s in attributeType '%s'\n",
522                                 scherr2str(code), mat[i].name, 0 );
523 #endif
524                         return -1;
525                 }
526                 ldap_memfree(at);
527
528                 ad = ((AttributeDescription **)&(((char *)mi)[mat[i].offset]));
529                 ad[0] = NULL;
530                 if ( slap_str2ad( mat[i].name, ad, &text ) ) {
531 #ifdef NEW_LOGGING
532                         LDAP_LOG( OPERATION, CRIT,
533                                 "monitor_back_db_init: %s\n", text, 0, 0 );
534 #else
535                         Debug( LDAP_DEBUG_ANY,
536                                 "monitor_back_db_init: %s\n", text, 0, 0 );
537 #endif
538                         return -1;
539                 }
540         }
541
542         if ( slap_str2ad( "description", &mi->monitor_ad_description, &text ) ) {
543 #ifdef NEW_LOGGING
544                 LDAP_LOG( OPERATION, CRIT,
545                         "monitor_back_db_init: %s\n", text, 0, 0 );
546 #else
547                 Debug( LDAP_DEBUG_ANY,
548                         "monitor_back_db_init: %s\n", text, 0, 0 );
549 #endif
550                 return( -1 );
551         }
552
553         /*      
554          * Create all the subsystem specific entries
555          */
556         e_tmp = NULL;
557         for ( i = 0; monitor_subsys[ i ].mss_name != NULL; i++ ) {
558                 int             len = strlen( monitor_subsys[ i ].mss_name );
559                 struct berval   dn;
560                 int             rc;
561
562                 dn.bv_len = len + sizeof( "cn=" ) - 1;
563                 dn.bv_val = ch_calloc( sizeof( char ), dn.bv_len + 1 );
564                 strcpy( dn.bv_val, "cn=" );
565                 strcat( dn.bv_val, monitor_subsys[ i ].mss_name );
566                 rc = dnPretty2( NULL, &dn, &monitor_subsys[ i ].mss_rdn, NULL );
567                 free( dn.bv_val );
568                 if ( rc != LDAP_SUCCESS ) {
569 #ifdef NEW_LOGGING
570                         LDAP_LOG( OPERATION, CRIT,
571                                 "monitor RDN \"%s\" is invalid\n", 
572                                 dn.bv_val, 0, 0 );
573 #else
574                         Debug( LDAP_DEBUG_ANY,
575                                 "monitor RDN \"%s\" is invalid\n", 
576                                 dn.bv_val, 0, 0 );
577 #endif
578                         return( -1 );
579                 }
580
581                 dn.bv_len += sizeof( SLAPD_MONITOR_DN ); /* 1 for the , */
582                 dn.bv_val = ch_malloc( dn.bv_len + 1 );
583                 strcpy( dn.bv_val , monitor_subsys[ i ].mss_rdn.bv_val );
584                 strcat( dn.bv_val, "," SLAPD_MONITOR_DN );
585                 rc = dnPrettyNormal( NULL, &dn, &monitor_subsys[ i ].mss_dn,
586                         &monitor_subsys[ i ].mss_ndn, NULL );
587                 free( dn.bv_val );
588                 if ( rc != LDAP_SUCCESS ) {
589 #ifdef NEW_LOGGING
590                         LDAP_LOG( OPERATION, CRIT,
591                                 "monitor DN \"%s\" is invalid\n", 
592                                 dn.bv_val, 0, 0 );
593 #else
594                         Debug( LDAP_DEBUG_ANY,
595                                 "monitor DN \"%s\" is invalid\n", 
596                                 dn.bv_val, 0, 0 );
597 #endif
598                         return( -1 );
599                 }
600
601                 snprintf( buf, sizeof( buf ),
602                                 "dn: %s\n"
603                                 SLAPD_MONITOR_OBJECTCLASSES 
604                                 "cn: %s\n",
605                                 monitor_subsys[ i ].mss_dn.bv_val,
606                                 monitor_subsys[ i ].mss_name );
607                 
608                 e = str2entry( buf );
609                 
610                 if ( e == NULL) {
611 #ifdef NEW_LOGGING
612                         LDAP_LOG( OPERATION, CRIT,
613                                 "unable to create '%s' entry\n", 
614                                 monitor_subsys[ i ].mss_dn.bv_val, 0, 0 );
615 #else
616                         Debug( LDAP_DEBUG_ANY,
617                                 "unable to create '%s' entry\n", 
618                                 monitor_subsys[ i ].mss_dn.bv_val, 0, 0 );
619 #endif
620                         return( -1 );
621                 }
622
623                 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
624                 e->e_private = ( void * )mp;
625                 mp->mp_info = &monitor_subsys[ i ];
626                 mp->mp_children = NULL;
627                 mp->mp_next = e_tmp;
628                 mp->mp_flags = monitor_subsys[ i ].mss_flags;
629
630                 if ( monitor_cache_add( mi, e ) ) {
631 #ifdef NEW_LOGGING
632                         LDAP_LOG( OPERATION, CRIT,
633                                 "unable to add entry '%s' to cache\n",
634                                 monitor_subsys[ i ].mss_dn.bv_val, 0, 0 );
635 #else
636                         Debug( LDAP_DEBUG_ANY,
637                                 "unable to add entry '%s' to cache\n",
638                                 monitor_subsys[ i ].mss_dn.bv_val, 0, 0 );
639 #endif
640                         return -1;
641                 }
642
643                 e_tmp = e;
644         }
645
646         /*
647          * creates the "cn=Monitor" entry 
648          */
649         snprintf( buf, sizeof( buf ), 
650                         "dn: " SLAPD_MONITOR_DN "\n"
651                         "objectClass: top\n"
652                         "objectClass: monitor\n"
653                         "objectClass: extensibleObject\n"
654                         "structuralObjectClass: monitor\n"
655                         "cn: Monitor" );
656
657         e = str2entry( buf );
658         if ( e == NULL) {
659 #ifdef NEW_LOGGING
660                 LDAP_LOG( OPERATION, CRIT,
661                         "unable to create '%s' entry\n",
662                         SLAPD_MONITOR_DN, 0, 0 );
663 #else
664                 Debug( LDAP_DEBUG_ANY,
665                         "unable to create '%s' entry\n%s%s",
666                         SLAPD_MONITOR_DN, "", "" );
667 #endif
668                 return( -1 );
669         }
670         bv.bv_val = (char *) Versionstr;
671         end_of_line = strchr( Versionstr, '\n' );
672         if ( end_of_line ) {
673                 bv.bv_len = end_of_line - Versionstr;
674         } else {
675                 bv.bv_len = strlen( Versionstr );
676         }
677         if ( attr_merge_normalize_one( e, mi->monitor_ad_description,
678                                 &bv, NULL ) ) {
679 #ifdef NEW_LOGGING
680                 LDAP_LOG( OPERATION, CRIT,
681                         "unable to add description to '%s' entry\n",
682                         SLAPD_MONITOR_DN, 0, 0 );
683 #else
684                 Debug( LDAP_DEBUG_ANY,
685                         "unable to add description to '%s' entry\n%s%s",
686                         SLAPD_MONITOR_DN, "", "" );
687 #endif
688                 return( -1 );
689         }
690
691         mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
692         e->e_private = ( void * )mp;
693
694         mp->mp_info = NULL;
695         mp->mp_children = e_tmp;
696         mp->mp_next = NULL;
697
698         if ( monitor_cache_add( mi, e ) ) {
699 #ifdef NEW_LOGGING
700                 LDAP_LOG( OPERATION, CRIT,
701                         "unable to add entry '%s' to cache\n",
702                         SLAPD_MONITOR_DN, 0, 0 );
703 #else
704                 Debug( LDAP_DEBUG_ANY,
705                         "unable to add entry '%s' to cache\n%s%s",
706                         SLAPD_MONITOR_DN, "", "" );
707 #endif
708                 return -1;
709         }
710
711         be->be_private = mi;
712         
713         return 0;
714 }
715
716 int
717 monitor_back_db_open(
718         BackendDB       *be
719 )
720 {
721         struct monitorsubsys    *ms;
722
723         assert( be );
724
725         /*
726          * opens the monitor backend
727          */
728         for ( ms = monitor_subsys; ms->mss_name != NULL; ms++ ) {
729                 if ( ms->mss_init && ( *ms->mss_init )( be ) ) {
730                         return( -1 );
731                 }
732         }
733
734         return( 0 );
735 }
736
737 int
738 monitor_back_config(
739         BackendInfo     *bi,
740         const char      *fname,
741         int             lineno,
742         int             argc,
743         char            **argv
744 )
745 {
746         /*
747          * eventually, will hold backend specific configuration parameters
748          */
749         return 0;
750 }
751
752 int
753 monitor_back_db_config(
754         Backend     *be,
755         const char  *fname,
756         int         lineno,
757         int         argc,
758         char        **argv
759 )
760 {
761         /*
762          * eventually, will hold database specific configuration parameters
763          */
764 #ifdef NEW_LOGGING
765         LDAP_LOG( CONFIG, INFO,
766                 "line %d of file '%s' will be ignored\n", lineno, fname, 0 );
767 #else
768         Debug( LDAP_DEBUG_CONFIG, 
769                 "line %d of file '%s' will be ignored\n%s", lineno, fname, "" );
770 #endif
771         return( 0 );
772 }
773
774 int
775 monitor_back_db_destroy(
776         BackendDB       *be
777 )
778 {
779         /*
780          * FIXME: destroys all the data
781          */
782         return 0;
783 }
784