]> git.sur5r.net Git - openldap/blob - servers/slapd/back-monitor/init.c
HEADS-UP: complete reworking of back-monitor
[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_RWW, SLAPD_MONITOR_RWW_NAME,
110                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
111                 MONITOR_F_PERSISTENT_CH,
112                 monitor_subsys_rww_init,
113                 monitor_subsys_rww_update,
114                 NULL,   /* create */
115                 NULL    /* modify */
116         }, { 
117                 SLAPD_MONITOR_LOG, SLAPD_MONITOR_LOG_NAME,
118                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
119                 MONITOR_F_NONE,
120                 monitor_subsys_log_init,
121                 NULL,   /* update */
122                 NULL,   /* create */
123                 monitor_subsys_log_modify
124         }, { 
125                 SLAPD_MONITOR_OPS, SLAPD_MONITOR_OPS_NAME,
126                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
127                 MONITOR_F_PERSISTENT_CH,
128                 monitor_subsys_ops_init,
129                 monitor_subsys_ops_update,
130                 NULL,   /* create */
131                 NULL,   /* modify */
132         }, { 
133                 SLAPD_MONITOR_SENT, SLAPD_MONITOR_SENT_NAME,
134                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
135                 MONITOR_F_PERSISTENT_CH,
136                 monitor_subsys_sent_init,
137                 monitor_subsys_sent_update,
138                 NULL,   /* create */
139                 NULL,   /* modify */
140         }, { 
141                 SLAPD_MONITOR_TIME, SLAPD_MONITOR_TIME_NAME,
142                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
143                 MONITOR_F_PERSISTENT_CH,
144                 monitor_subsys_time_init,
145                 monitor_subsys_time_update,
146                 NULL,   /* create */
147                 NULL,   /* modify */
148         }, { -1, NULL }
149 };
150
151 #ifdef SLAPD_MONITOR_DYNAMIC
152
153 int
154 back_monitor_LTX_init_module( int argc, char *argv[] )
155 {
156         BackendInfo bi;
157
158         memset( &bi, '\0', sizeof(bi) );
159         bi.bi_type = "monitor";
160         bi.bi_init = monitor_back_initialize;
161         backend_add( &bi );
162         return 0;
163 }
164
165 #endif /* SLAPD_MONITOR_DYNAMIC */
166
167 int
168 monitor_back_initialize(
169         BackendInfo     *bi
170 )
171 {
172         static char *controls[] = {
173                 LDAP_CONTROL_MANAGEDSAIT,
174                 LDAP_CONTROL_VALUESRETURNFILTER,
175                 NULL
176         };
177
178         bi->bi_controls = controls;
179
180         bi->bi_init = 0;
181         bi->bi_open = 0;
182         bi->bi_config = monitor_back_config;
183         bi->bi_close = 0;
184         bi->bi_destroy = 0;
185
186         bi->bi_db_init = monitor_back_db_init;
187         bi->bi_db_config = monitor_back_db_config;
188         bi->bi_db_open = monitor_back_db_open;
189         bi->bi_db_close = 0;
190         bi->bi_db_destroy = monitor_back_db_destroy;
191
192         bi->bi_op_bind = monitor_back_bind;
193         bi->bi_op_unbind = 0;
194         bi->bi_op_search = monitor_back_search;
195         bi->bi_op_compare = monitor_back_compare;
196         bi->bi_op_modify = monitor_back_modify;
197         bi->bi_op_modrdn = 0;
198         bi->bi_op_add = 0;
199         bi->bi_op_delete = 0;
200         bi->bi_op_abandon = 0;
201
202         bi->bi_extended = 0;
203
204         bi->bi_entry_release_rw = 0;
205         bi->bi_chk_referrals = 0;
206         bi->bi_operational = monitor_back_operational;
207
208         /*
209          * hooks for slap tools
210          */
211         bi->bi_tool_entry_open = 0;
212         bi->bi_tool_entry_close = 0;
213         bi->bi_tool_entry_first = 0;
214         bi->bi_tool_entry_next = 0;
215         bi->bi_tool_entry_get = 0;
216         bi->bi_tool_entry_put = 0;
217         bi->bi_tool_entry_reindex = 0;
218         bi->bi_tool_sync = 0;
219
220         bi->bi_connection_init = 0;
221         bi->bi_connection_destroy = 0;
222
223         return 0;
224 }
225
226 int
227 monitor_back_db_init(
228         BackendDB       *be
229 )
230 {
231         struct monitorinfo      *mi;
232         int                     rc;
233         struct berval           dn, ndn;
234         struct berval           bv;
235
236         /*
237          * database monitor can be defined once only
238          */
239         if ( be_monitor ) {
240 #ifdef NEW_LOGGING
241                 LDAP_LOG( OPERATION, CRIT,
242                         "only one monitor backend is allowed\n", 0, 0, 0);
243 #else
244                 Debug( LDAP_DEBUG_ANY,
245                         "only one monitor backend is allowed\n", 0, 0, 0 );
246 #endif
247                 return( -1 );
248         }
249         be_monitor = be;
250
251         /* indicate system schema supported */
252         be->be_flags |= SLAP_BFLAG_MONITOR;
253
254         dn.bv_val = SLAPD_MONITOR_DN;
255         dn.bv_len = sizeof( SLAPD_MONITOR_DN ) - 1;
256
257         rc = dnNormalize2( NULL, &dn, &ndn, NULL );
258         if( rc != LDAP_SUCCESS ) {
259 #ifdef NEW_LOGGING
260                 LDAP_LOG( OPERATION, CRIT,
261                         "unable to normalize monitor DN \"" SLAPD_MONITOR_DN
262                         "\"\n" , 0, 0, 0 );
263 #else
264                 Debug( LDAP_DEBUG_ANY,
265                         "unable to normalize monitor DN \"" SLAPD_MONITOR_DN
266                         "\"\n", 0, 0, 0 );
267 #endif
268                 return -1;
269         }
270
271         ber_dupbv( &bv, &dn );
272         ber_bvarray_add( &be->be_suffix, &bv );
273         ber_bvarray_add( &be->be_nsuffix, &ndn );
274
275         mi = ( struct monitorinfo * )ch_calloc( sizeof( struct monitorinfo ), 1 );
276         if ( mi == NULL ) {
277 #ifdef NEW_LOGGING
278                 LDAP_LOG( OPERATION, CRIT,
279                         "unable to initialize monitor backend\n", 0, 0, 0 );
280 #else
281                 Debug( LDAP_DEBUG_ANY,
282                         "unable to initialize monitor backend\n", 0, 0, 0 );
283 #endif
284                 return -1;
285         }
286
287         memset( mi, 0, sizeof( struct monitorinfo ) );
288
289         ldap_pvt_thread_mutex_init( &mi->mi_cache_mutex );
290
291         be->be_private = mi;
292         
293         return 0;
294 }
295
296 int
297 monitor_back_db_open(
298         BackendDB       *be
299 )
300 {
301         struct monitorinfo      *mi = (struct monitorinfo *)be->be_private;
302         struct monitorsubsys    *ms;
303         Entry                   *e, *e_tmp;
304         struct monitorentrypriv *mp;
305         int                     i;
306         char                    buf[1024], *end_of_line;
307         const char              *text;
308         struct berval           bv;
309         struct m_s {
310                 char    *name;
311                 char    *schema;
312                 int     offset;
313         } moc[] = {
314                 { "monitor", "( 1.3.6.1.4.1.4203.666.3.2 "
315                         "NAME 'monitor' "
316                         "DESC 'OpenLDAP system monitoring' "
317                         "SUP top STRUCTURAL "
318                         "MUST cn "
319                         "MAY ( "
320                                 "description "
321                                 "$ seeAlso "
322                                 "$ monitoredInfo "
323                         ") )",
324                         offsetof(struct monitorinfo, oc_monitor) },
325                 { "monitorServer", "( 1.3.6.1.4.1.4203.666.3.7 "
326                         "NAME 'monitorServer' "
327                         "DESC 'Server monitoring root entry' "
328                         "SUP monitor STRUCTURAL "
329                         "MAY ( "
330                                 "l "
331                         ") )",
332                         offsetof(struct monitorinfo, oc_monitorServer) },
333                 { "monitorContainer", "( 1.3.6.1.4.1.4203.666.3.8 "
334                         "NAME 'monitorContainer' "
335                         "DESC 'monitor container class' "
336                         "SUP monitor STRUCTURAL )",
337                         offsetof(struct monitorinfo, oc_monitorContainer) },
338                 { "monitorCounterObject", "( 1.3.6.1.4.1.4203.666.3.9 "
339                         "NAME 'monitorCounterObject' "
340                         "DESC 'monitor counter class' "
341                         "SUP monitor STRUCTURAL )",
342                         offsetof(struct monitorinfo, oc_monitorCounterObject) },
343                 { "monitorOperation", "( 1.3.6.1.4.1.4203.666.3.10 "
344                         "NAME 'monitorOperation' "
345                         "DESC 'monitor operation class' "
346                         "SUP monitor STRUCTURAL )",
347                         offsetof(struct monitorinfo, oc_monitorOperation) },
348                 { "monitorConnection", "( 1.3.6.1.4.1.4203.666.3.11 "
349                         "NAME 'monitorConnection' "
350                         "DESC 'monitor connection class' "
351                         "SUP monitor STRUCTURAL )",
352                         offsetof(struct monitorinfo, oc_monitorConnection) },
353                 { "managedObject", "( 1.3.6.1.4.1.4203.666.3.12 "
354                         "NAME 'managedObject' "
355                         "DESC 'monitor managed entity class' "
356                         "SUP monitor STRUCTURAL )",
357                         offsetof(struct monitorinfo, oc_managedObject) },
358                 { "monitoredObject", "( 1.3.6.1.4.1.4203.666.3.13 "
359                         "NAME 'monitoredObject' "
360                         "DESC 'monitor monitored entity class' "
361                         "SUP monitor STRUCTURAL )",
362                         offsetof(struct monitorinfo, oc_monitoredObject) },
363                 { NULL, NULL, -1 }
364         }, mat[] = {
365                 { "monitoredInfo", "( 1.3.6.1.4.1.4203.666.1.14 "
366                         "NAME 'monitoredInfo' "
367                         "DESC 'monitored info' "
368                         /* "SUP name " */
369                         "EQUALITY caseIgnoreMatch "
370                         "SUBSTR caseIgnoreSubstringsMatch "
371                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} "
372                         "NO-USER-MODIFICATION "
373                         "USAGE directoryOperation )",
374                         offsetof(struct monitorinfo, ad_monitoredInfo) },
375                 { "managedInfo", "( 1.3.6.1.4.1.4203.666.1.15 "
376                         "NAME 'managedInfo' "
377                         "DESC 'monitor managed info' "
378                         "SUP name )",
379                         offsetof(struct monitorinfo, ad_managedInfo) },
380                 { "monitorCounter", "( 1.3.6.1.4.1.4203.666.1.16 "
381                         "NAME 'monitorCounter' "
382                         "DESC 'monitor counter' "
383                         "EQUALITY integerMatch "
384                         "ORDERING integerOrderingMatch "
385                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 "
386                         "NO-USER-MODIFICATION "
387                         "USAGE directoryOperation )",
388                         offsetof(struct monitorinfo, ad_monitorCounter) },
389                 { "monitorOpCompleted", "( 1.3.6.1.4.1.4203.666.1.17 "
390                         "NAME 'monitorOpCompleted' "
391                         "DESC 'monitor completed operations' "
392                         "SUP monitorCounter "
393                         "NO-USER-MODIFICATION "
394                         "USAGE directoryOperation )",
395                         offsetof(struct monitorinfo, ad_monitorOpCompleted) },
396                 { "monitorOpInitiated", "( 1.3.6.1.4.1.4203.666.1.18 "
397                         "NAME 'monitorOpInitiated' "
398                         "DESC 'monitor initiated operations' "
399                         "SUP monitorCounter "
400                         "NO-USER-MODIFICATION "
401                         "USAGE directoryOperation )",
402                         offsetof(struct monitorinfo, ad_monitorOpInitiated) },
403                 { "monitorConnectionNumber", "( 1.3.6.1.4.1.4203.666.1.19 "
404                         "NAME 'monitorConnectionNumber' "
405                         "DESC 'monitor connection number' "
406                         "SUP monitorCounter "
407                         "NO-USER-MODIFICATION "
408                         "USAGE directoryOperation )",
409                         offsetof(struct monitorinfo, ad_monitorConnectionNumber) },
410                 { "monitorConnectionAuthzDN", "( 1.3.6.1.4.1.4203.666.1.20 "
411                         "NAME 'monitorConnectionAuthzDN' "
412                         "DESC 'monitor connection authorization DN' "
413                         /* "SUP distinguishedName " */
414                         "EQUALITY distinguishedNameMatch "
415                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 "
416                         "NO-USER-MODIFICATION "
417                         "USAGE directoryOperation )",
418                         offsetof(struct monitorinfo, ad_monitorConnectionAuthzDN) },
419                 { "monitorConnectionLocalAddress", "( 1.3.6.1.4.1.4203.666.1.21 "
420                         "NAME 'monitorConnectionLocalAddress' "
421                         "DESC 'monitor connection local address' "
422                         "SUP monitoredInfo "
423                         "NO-USER-MODIFICATION "
424                         "USAGE directoryOperation )",
425                         offsetof(struct monitorinfo, ad_monitorConnectionLocalAddress) },
426                 { "monitorConnectionPeerAddress", "( 1.3.6.1.4.1.4203.666.1.22 "
427                         "NAME 'monitorConnectionPeerAddress' "
428                         "DESC 'monitor connection peer address' "
429                         "SUP monitoredInfo "
430                         "NO-USER-MODIFICATION "
431                         "USAGE directoryOperation )",
432                         offsetof(struct monitorinfo, ad_monitorConnectionPeerAddress) },
433                 { NULL, NULL, -1 }
434         };
435
436         for ( i = 0; mat[i].name; i++ ) {
437                 LDAPAttributeType *at;
438                 int             code;
439                 const char      *err;
440                 AttributeDescription **ad;
441
442                 at = ldap_str2attributetype( mat[i].schema, &code,
443                                 &err, LDAP_SCHEMA_ALLOW_ALL );
444                 if ( !at ) {
445 #ifdef NEW_LOGGING
446                         LDAP_LOG( OPERATION, CRIT, "monitor_back_db_init: "
447                                 "in AttributeType '%s' %s before %s\n",
448                                 mat[i].name, ldap_scherr2str(code), err );
449 #else
450                         Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
451                                 "in AttributeType '%s' %s before %s\n",
452                                 mat[i].name, ldap_scherr2str(code), err );
453 #endif
454                         return -1;
455                 }
456
457                 if ( at->at_oid == NULL ) {
458 #ifdef NEW_LOGGING
459                         LDAP_LOG( OPERATION, CRIT, "monitor_back_db_init: "
460                                 "null OID for attributeType '%s'\n",
461                                 mat[i].name, 0, 0 );
462 #else
463                         Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
464                                 "null OID for attributeType '%s'\n",
465                                 mat[i].name, 0, 0 );
466 #endif
467                         return -1;
468                 }
469
470                 code = at_add(at, &err);
471                 if ( code ) {
472 #ifdef NEW_LOGGING
473                         LDAP_LOG( OPERATION, CRIT, "monitor_back_db_init: "
474                                 "%s in attributeType '%s'\n",
475                                 scherr2str(code), mat[i].name, 0 );
476 #else
477                         Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
478                                 "%s in attributeType '%s'\n",
479                                 scherr2str(code), mat[i].name, 0 );
480 #endif
481                         return -1;
482                 }
483                 ldap_memfree(at);
484
485                 ad = ((AttributeDescription **)&(((char *)mi)[mat[i].offset]));
486                 ad[0] = NULL;
487                 if ( slap_str2ad( mat[i].name, ad, &text ) ) {
488 #ifdef NEW_LOGGING
489                         LDAP_LOG( OPERATION, CRIT,
490                                 "monitor_back_db_init: %s\n", text, 0, 0 );
491 #else
492                         Debug( LDAP_DEBUG_ANY,
493                                 "monitor_back_db_init: %s\n", text, 0, 0 );
494 #endif
495                         return -1;
496                 }
497         }
498
499         if ( slap_str2ad( "description", &mi->ad_description, &text ) ) {
500 #ifdef NEW_LOGGING
501                 LDAP_LOG( OPERATION, CRIT,
502                         "monitor_back_db_init: description: %s\n", text, 0, 0 );
503 #else
504                 Debug( LDAP_DEBUG_ANY,
505                         "monitor_back_db_init: description: %s\n", text, 0, 0 );
506 #endif
507                 return( -1 );
508         }
509
510         if ( slap_str2ad( "seeAlso", &mi->ad_seeAlso, &text ) ) {
511 #ifdef NEW_LOGGING
512                 LDAP_LOG( OPERATION, CRIT,
513                         "monitor_back_db_init: seeAlso: %s\n", text, 0, 0 );
514 #else
515                 Debug( LDAP_DEBUG_ANY,
516                         "monitor_back_db_init: seeAlso: %s\n", text, 0, 0 );
517 #endif
518                 return( -1 );
519         }
520
521         for ( i = 0; moc[i].name; i++ ) {
522                 LDAPObjectClass         *oc;
523                 int                     code;
524                 const char              *err;
525                 ObjectClass             *Oc;
526
527                 oc = ldap_str2objectclass(moc[i].schema, &code, &err,
528                                 LDAP_SCHEMA_ALLOW_ALL );
529                 if ( !oc ) {
530 #ifdef NEW_LOGGING
531                         LDAP_LOG( OPERATION, CRIT,
532                                 "unable to parse monitor objectclass '%s': "
533                                 "%s before %s\n" , moc[i].name,
534                                 ldap_scherr2str(code), err );
535 #else
536                         Debug( LDAP_DEBUG_ANY,
537                                 "unable to parse monitor objectclass '%s': "
538                                 "%s before %s\n" , moc[i].name,
539                                 ldap_scherr2str(code), err );
540 #endif
541                         return -1;
542                 }
543
544                 if ( oc->oc_oid == NULL ) {
545 #ifdef NEW_LOGGING
546                         LDAP_LOG( OPERATION, CRIT,
547                                 "objectclass '%s' has no OID\n" ,
548                                 moc[i].name, 0, 0 );
549 #else
550                         Debug( LDAP_DEBUG_ANY,
551                                 "objectclass '%s' has no OID\n" ,
552                                 moc[i].name, 0, 0 );
553 #endif
554                         return -1;
555                 }
556
557                 code = oc_add(oc, 0, &err);
558                 if ( code ) {
559 #ifdef NEW_LOGGING
560                         LDAP_LOG( OPERATION, CRIT,
561                                 "objectclass '%s': %s \"%s\"\n" ,
562                                 moc[i].name, scherr2str(code), err );
563 #else
564                         Debug( LDAP_DEBUG_ANY,
565                                 "objectclass '%s': %s \"%s\"\n" ,
566                                 moc[i].name, scherr2str(code), err );
567 #endif
568                         return -1;
569                 }
570
571                 ldap_memfree(oc);
572
573                 Oc = oc_find( moc[i].name );
574                 if ( Oc == NULL ) {
575 #ifdef NEW_LOGGING
576                         LDAP_LOG( OPERATION, CRIT, "monitor_back_db_init: "
577                                         "unable to find objectClass %s "
578                                         "(just added)\n", moc[i].name, 0, 0 );
579 #else
580                         Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
581                                         "unable to find objectClass %s "
582                                         "(just added)\n", moc[i].name, 0, 0 );
583 #endif
584                         return -1;
585                 }
586
587                 ((ObjectClass **)&(((char *)mi)[moc[i].offset]))[0] = Oc;
588         }
589
590         /*      
591          * Create all the subsystem specific entries
592          */
593         e_tmp = NULL;
594         for ( i = 0; monitor_subsys[ i ].mss_name != NULL; i++ ) {
595                 int             len = strlen( monitor_subsys[ i ].mss_name );
596                 struct berval   dn;
597                 int             rc;
598
599                 dn.bv_len = len + sizeof( "cn=" ) - 1;
600                 dn.bv_val = ch_calloc( sizeof( char ), dn.bv_len + 1 );
601                 strcpy( dn.bv_val, "cn=" );
602                 strcat( dn.bv_val, monitor_subsys[ i ].mss_name );
603                 rc = dnPretty2( NULL, &dn, &monitor_subsys[ i ].mss_rdn, NULL );
604                 free( dn.bv_val );
605                 if ( rc != LDAP_SUCCESS ) {
606 #ifdef NEW_LOGGING
607                         LDAP_LOG( OPERATION, CRIT,
608                                 "monitor RDN \"%s\" is invalid\n", 
609                                 dn.bv_val, 0, 0 );
610 #else
611                         Debug( LDAP_DEBUG_ANY,
612                                 "monitor RDN \"%s\" is invalid\n", 
613                                 dn.bv_val, 0, 0 );
614 #endif
615                         return( -1 );
616                 }
617
618                 dn.bv_len += sizeof( SLAPD_MONITOR_DN ); /* 1 for the , */
619                 dn.bv_val = ch_malloc( dn.bv_len + 1 );
620                 strcpy( dn.bv_val , monitor_subsys[ i ].mss_rdn.bv_val );
621                 strcat( dn.bv_val, "," SLAPD_MONITOR_DN );
622                 rc = dnPrettyNormal( NULL, &dn, &monitor_subsys[ i ].mss_dn,
623                         &monitor_subsys[ i ].mss_ndn, NULL );
624                 free( dn.bv_val );
625                 if ( rc != LDAP_SUCCESS ) {
626 #ifdef NEW_LOGGING
627                         LDAP_LOG( OPERATION, CRIT,
628                                 "monitor DN \"%s\" is invalid\n", 
629                                 dn.bv_val, 0, 0 );
630 #else
631                         Debug( LDAP_DEBUG_ANY,
632                                 "monitor DN \"%s\" is invalid\n", 
633                                 dn.bv_val, 0, 0 );
634 #endif
635                         return( -1 );
636                 }
637
638                 snprintf( buf, sizeof( buf ),
639                                 "dn: %s\n"
640                                 "objectClass: %s\n"
641                                 "structuralObjectClass: %s\n"
642                                 "cn: %s\n",
643                                 monitor_subsys[ i ].mss_dn.bv_val,
644                                 mi->oc_monitorContainer->soc_cname.bv_val,
645                                 mi->oc_monitorContainer->soc_cname.bv_val,
646                                 monitor_subsys[ i ].mss_name );
647                 
648                 e = str2entry( buf );
649                 
650                 if ( e == NULL) {
651 #ifdef NEW_LOGGING
652                         LDAP_LOG( OPERATION, CRIT,
653                                 "unable to create '%s' entry\n", 
654                                 monitor_subsys[ i ].mss_dn.bv_val, 0, 0 );
655 #else
656                         Debug( LDAP_DEBUG_ANY,
657                                 "unable to create '%s' entry\n", 
658                                 monitor_subsys[ i ].mss_dn.bv_val, 0, 0 );
659 #endif
660                         return( -1 );
661                 }
662
663                 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
664                 e->e_private = ( void * )mp;
665                 mp->mp_info = &monitor_subsys[ i ];
666                 mp->mp_children = NULL;
667                 mp->mp_next = e_tmp;
668                 mp->mp_flags = monitor_subsys[ i ].mss_flags;
669
670                 if ( monitor_cache_add( mi, e ) ) {
671 #ifdef NEW_LOGGING
672                         LDAP_LOG( OPERATION, CRIT,
673                                 "unable to add entry '%s' to cache\n",
674                                 monitor_subsys[ i ].mss_dn.bv_val, 0, 0 );
675 #else
676                         Debug( LDAP_DEBUG_ANY,
677                                 "unable to add entry '%s' to cache\n",
678                                 monitor_subsys[ i ].mss_dn.bv_val, 0, 0 );
679 #endif
680                         return -1;
681                 }
682
683                 e_tmp = e;
684         }
685
686         /*
687          * creates the "cn=Monitor" entry 
688          */
689         snprintf( buf, sizeof( buf ), 
690                 "dn: " SLAPD_MONITOR_DN "\n"
691                 "objectClass: %s\n"
692                 "structuralObjectClass: %s\n"
693                 "cn: Monitor\n"
694                 "%s: This subtree contains monitoring/managing objects.\n"
695                 "%s: This object contains information about this server.\n"
696                 "%s: createTimeStamp reflects the time this server instance was created.\n"
697                 "%s: modifyTimeStamp reflects the current time.\n",
698                 mi->oc_monitorServer->soc_cname.bv_val,
699                 mi->oc_monitorServer->soc_cname.bv_val,
700                 mi->ad_description->ad_cname.bv_val,
701                 mi->ad_description->ad_cname.bv_val,
702                 mi->ad_description->ad_cname.bv_val,
703                 mi->ad_description->ad_cname.bv_val );
704
705         e = str2entry( buf );
706         if ( e == NULL) {
707 #ifdef NEW_LOGGING
708                 LDAP_LOG( OPERATION, CRIT,
709                         "unable to create '%s' entry\n",
710                         SLAPD_MONITOR_DN, 0, 0 );
711 #else
712                 Debug( LDAP_DEBUG_ANY,
713                         "unable to create '%s' entry\n",
714                         SLAPD_MONITOR_DN, 0, 0 );
715 #endif
716                 return( -1 );
717         }
718
719         bv.bv_val = (char *) Versionstr;
720         end_of_line = strchr( Versionstr, '\n' );
721         if ( end_of_line ) {
722                 bv.bv_len = end_of_line - Versionstr;
723         } else {
724                 bv.bv_len = strlen( Versionstr );
725         }
726
727         if ( attr_merge_normalize_one( e, mi->ad_monitoredInfo,
728                                 &bv, NULL ) ) {
729 #ifdef NEW_LOGGING
730                 LDAP_LOG( OPERATION, CRIT,
731                         "unable to add monitoredInfo to '%s' entry\n",
732                         SLAPD_MONITOR_DN, 0, 0 );
733 #else
734                 Debug( LDAP_DEBUG_ANY,
735                         "unable to add monitoredInfo to '%s' entry\n",
736                         SLAPD_MONITOR_DN, 0, 0 );
737 #endif
738                 return( -1 );
739         }
740
741         if ( mi->l.bv_len ) {
742                 AttributeDescription    *ad = NULL;
743                 const char              *text = NULL;
744
745                 if ( slap_str2ad( "l", &ad, &text ) ) {
746 #ifdef NEW_LOGGING
747                         LDAP_LOG( OPERATION, CRIT, "unable to get 'l'\n",
748                                 SLAPD_MONITOR_DN, 0, 0 );
749 #else
750                         Debug( LDAP_DEBUG_ANY, "unable to get 'l'\n",
751                                 SLAPD_MONITOR_DN, 0, 0 );
752 #endif
753                         return( -1 );
754                 }
755                 
756                 if ( attr_merge_normalize_one( e, ad, &mi->l, NULL ) ) {
757 #ifdef NEW_LOGGING
758                         LDAP_LOG( OPERATION, CRIT,
759                                 "unable to add locality to '%s' entry\n",
760                                 SLAPD_MONITOR_DN, 0, 0 );
761 #else
762                         Debug( LDAP_DEBUG_ANY,
763                                 "unable to add locality to '%s' entry\n",
764                                 SLAPD_MONITOR_DN, 0, 0 );
765 #endif
766                         return( -1 );
767                 }
768         }
769
770         mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
771         e->e_private = ( void * )mp;
772
773         mp->mp_info = NULL;
774         mp->mp_children = e_tmp;
775         mp->mp_next = NULL;
776
777         if ( monitor_cache_add( mi, e ) ) {
778 #ifdef NEW_LOGGING
779                 LDAP_LOG( OPERATION, CRIT,
780                         "unable to add entry '%s' to cache\n",
781                         SLAPD_MONITOR_DN, 0, 0 );
782 #else
783                 Debug( LDAP_DEBUG_ANY,
784                         "unable to add entry '%s' to cache\n",
785                         SLAPD_MONITOR_DN, 0, 0 );
786 #endif
787                 return -1;
788         }
789
790         be->be_private = mi;
791         
792         assert( be );
793
794         /*
795          * opens the monitor backend
796          */
797         for ( ms = monitor_subsys; ms->mss_name != NULL; ms++ ) {
798                 if ( ms->mss_init && ( *ms->mss_init )( be ) ) {
799                         return( -1 );
800                 }
801         }
802
803         return( 0 );
804 }
805
806 int
807 monitor_back_config(
808         BackendInfo     *bi,
809         const char      *fname,
810         int             lineno,
811         int             argc,
812         char            **argv
813 )
814 {
815         /*
816          * eventually, will hold backend specific configuration parameters
817          */
818         return 0;
819 }
820
821 int
822 monitor_back_db_config(
823         Backend     *be,
824         const char  *fname,
825         int         lineno,
826         int         argc,
827         char        **argv
828 )
829 {
830         struct monitorinfo *mi = (struct monitorinfo *)be->be_private;
831
832         /*
833          * eventually, will hold database specific configuration parameters
834          */
835         if ( strcasecmp( argv[ 0 ], "l" ) == 0 ) {
836                 if ( argc != 2 ) {
837                         return 1;
838                 }
839                 
840                 ber_str2bv( argv[ 1 ], 0, 1, &mi->l );
841
842         } else {
843 #ifdef NEW_LOGGING
844                 LDAP_LOG( CONFIG, INFO,
845                         "line %d of file '%s' will be ignored\n",
846                         lineno, fname, 0 );
847 #else
848                 Debug( LDAP_DEBUG_CONFIG, 
849                         "line %d of file '%s' will be ignored\n",
850                         lineno, fname, 0 );
851 #endif
852         }
853
854         return( 0 );
855 }
856
857 int
858 monitor_back_db_destroy(
859         BackendDB       *be
860 )
861 {
862         /*
863          * FIXME: destroys all the data
864          */
865         return 0;
866 }
867