1 /* init.c - initialize monitor backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2001-2004 The OpenLDAP Foundation.
6 * Portions Copyright 2001-2003 Pierangelo Masarati.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
13 * A copy of this license is available in file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
18 * This work was initially developed by Pierangelo Masarati for inclusion
19 * in OpenLDAP Software.
25 #include <ac/string.h>
30 #include "back-monitor.h"
32 #undef INTEGRATE_CORE_SCHEMA
35 * used by many functions to add description to entries
37 BackendDB *be_monitor = NULL;
39 static struct monitorsubsys **monitor_subsys = NULL;
40 static int monitor_subsys_opened = 0;
45 * the known subsystems are added to the subsystems
46 * array at backend initialization; other subsystems
47 * may be added by calling monitor_back_register_subsys()
48 * before the database is opened (e.g. by other backends
49 * or by overlays or modules).
51 static struct monitorsubsys known_monitor_subsys[] = {
53 SLAPD_MONITOR_BACKEND_NAME,
54 BER_BVNULL, BER_BVNULL, BER_BVNULL,
55 MONITOR_F_PERSISTENT_CH,
56 monitor_subsys_backend_init,
61 SLAPD_MONITOR_CONN_NAME,
62 BER_BVNULL, BER_BVNULL, BER_BVNULL,
63 MONITOR_F_VOLATILE_CH,
64 monitor_subsys_conn_init,
65 monitor_subsys_conn_update,
66 monitor_subsys_conn_create,
69 SLAPD_MONITOR_DATABASE_NAME,
70 BER_BVNULL, BER_BVNULL, BER_BVNULL,
71 MONITOR_F_PERSISTENT_CH,
72 monitor_subsys_database_init,
75 monitor_subsys_database_modify
77 SLAPD_MONITOR_LISTENER_NAME,
78 BER_BVNULL, BER_BVNULL, BER_BVNULL,
79 MONITOR_F_PERSISTENT_CH,
80 monitor_subsys_listener_init,
85 SLAPD_MONITOR_LOG_NAME,
86 BER_BVNULL, BER_BVNULL, BER_BVNULL,
88 monitor_subsys_log_init,
91 monitor_subsys_log_modify
93 SLAPD_MONITOR_OPS_NAME,
94 BER_BVNULL, BER_BVNULL, BER_BVNULL,
95 MONITOR_F_PERSISTENT_CH,
96 monitor_subsys_ops_init,
97 monitor_subsys_ops_update,
101 SLAPD_MONITOR_OVERLAY_NAME,
102 BER_BVNULL, BER_BVNULL, BER_BVNULL,
103 MONITOR_F_PERSISTENT_CH,
104 monitor_subsys_overlay_init,
109 SLAPD_MONITOR_SASL_NAME,
110 BER_BVNULL, BER_BVNULL, BER_BVNULL,
117 SLAPD_MONITOR_SENT_NAME,
118 BER_BVNULL, BER_BVNULL, BER_BVNULL,
119 MONITOR_F_PERSISTENT_CH,
120 monitor_subsys_sent_init,
121 monitor_subsys_sent_update,
125 SLAPD_MONITOR_THREAD_NAME,
126 BER_BVNULL, BER_BVNULL, BER_BVNULL,
127 MONITOR_F_PERSISTENT_CH,
128 monitor_subsys_thread_init,
129 monitor_subsys_thread_update,
133 SLAPD_MONITOR_TIME_NAME,
134 BER_BVNULL, BER_BVNULL, BER_BVNULL,
135 MONITOR_F_PERSISTENT_CH,
136 monitor_subsys_time_init,
137 monitor_subsys_time_update,
141 SLAPD_MONITOR_TLS_NAME,
142 BER_BVNULL, BER_BVNULL, BER_BVNULL,
149 SLAPD_MONITOR_RWW_NAME,
150 BER_BVNULL, BER_BVNULL, BER_BVNULL,
151 MONITOR_F_PERSISTENT_CH,
152 monitor_subsys_rww_init,
153 monitor_subsys_rww_update,
159 #if SLAPD_MONITOR == SLAPD_MOD_DYNAMIC
162 init_module( int argc, char *argv[] )
166 memset( &bi, '\0', sizeof(bi) );
167 bi.bi_type = "monitor";
168 bi.bi_init = monitor_back_initialize;
173 #endif /* SLAPD_MONITOR */
176 monitor_back_register_subsys( monitorsubsys *ms )
180 if ( monitor_subsys ) {
181 for ( ; monitor_subsys[ i ] != NULL; i++ )
182 /* just count'em */ ;
185 monitor_subsys = ch_realloc( monitor_subsys,
186 ( 2 + i ) * sizeof( monitorsubsys * ) );
188 if ( monitor_subsys == NULL ) {
192 monitor_subsys[ i ] = ms;
193 monitor_subsys[ i + 1 ] = NULL;
195 /* if a subsystem is registered __AFTER__ subsystem
196 * initialization (depending on the sequence the databases
197 * are listed in slapd.conf), init it */
198 if ( monitor_subsys_opened ) {
200 /* FIXME: this should only be possible
201 * if be_monitor is already initialized */
202 assert( be_monitor );
204 if ( ms->mss_open && ( *ms->mss_open )( be_monitor, ms ) ) {
208 ms->mss_flags |= MONITOR_F_OPENED;
215 monitor_back_get_subsys( const char *name )
217 if ( monitor_subsys != NULL ) {
220 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
221 if ( strcasecmp( monitor_subsys[ i ]->mss_name, name ) == 0 ) {
222 return monitor_subsys[ i ];
231 monitor_back_get_subsys_by_dn( struct berval *ndn, int sub )
233 if ( monitor_subsys != NULL ) {
237 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
238 if ( dnIsSuffix( ndn, &monitor_subsys[ i ]->mss_ndn ) ) {
239 return monitor_subsys[ i ];
244 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
245 if ( dn_match( ndn, &monitor_subsys[ i ]->mss_ndn ) ) {
246 return monitor_subsys[ i ];
256 monitor_back_initialize(
261 static char *controls[] = {
262 LDAP_CONTROL_MANAGEDSAIT,
263 LDAP_CONTROL_VALUESRETURNFILTER,
267 bi->bi_controls = controls;
271 bi->bi_config = monitor_back_config;
275 bi->bi_db_init = monitor_back_db_init;
276 bi->bi_db_config = monitor_back_db_config;
277 bi->bi_db_open = monitor_back_db_open;
279 bi->bi_db_destroy = monitor_back_db_destroy;
281 bi->bi_op_bind = monitor_back_bind;
282 bi->bi_op_unbind = 0;
283 bi->bi_op_search = monitor_back_search;
284 bi->bi_op_compare = monitor_back_compare;
285 bi->bi_op_modify = monitor_back_modify;
286 bi->bi_op_modrdn = 0;
288 bi->bi_op_delete = 0;
289 bi->bi_op_abandon = 0;
293 bi->bi_entry_release_rw = 0;
294 bi->bi_chk_referrals = 0;
295 bi->bi_operational = monitor_back_operational;
298 * hooks for slap tools
300 bi->bi_tool_entry_open = 0;
301 bi->bi_tool_entry_close = 0;
302 bi->bi_tool_entry_first = 0;
303 bi->bi_tool_entry_next = 0;
304 bi->bi_tool_entry_get = 0;
305 bi->bi_tool_entry_put = 0;
306 bi->bi_tool_entry_reindex = 0;
307 bi->bi_tool_sync = 0;
308 bi->bi_tool_dn2id_get = 0;
309 bi->bi_tool_id2entry_get = 0;
310 bi->bi_tool_entry_modify = 0;
312 bi->bi_connection_init = 0;
313 bi->bi_connection_destroy = 0;
315 for ( ms = known_monitor_subsys; ms->mss_name != NULL; ms++ ) {
316 if ( monitor_back_register_subsys( ms ) ) {
325 monitor_back_db_init(
329 struct monitorinfo *mi;
331 struct berval dn, ndn;
341 { "monitor", "( 1.3.6.1.4.1.4203.666.3.2 "
343 "DESC 'OpenLDAP system monitoring' "
344 "SUP top STRUCTURAL "
349 #if 0 /* temporarily disabled */
360 ") )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
361 offsetof(struct monitorinfo, mi_oc_monitor) },
362 { "monitorServer", "( 1.3.6.1.4.1.4203.666.3.7 "
363 "NAME 'monitorServer' "
364 "DESC 'Server monitoring root entry' "
365 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
366 offsetof(struct monitorinfo, mi_oc_monitorServer) },
367 { "monitorContainer", "( 1.3.6.1.4.1.4203.666.3.8 "
368 "NAME 'monitorContainer' "
369 "DESC 'monitor container class' "
370 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
371 offsetof(struct monitorinfo, mi_oc_monitorContainer) },
372 { "monitorCounterObject", "( 1.3.6.1.4.1.4203.666.3.9 "
373 "NAME 'monitorCounterObject' "
374 "DESC 'monitor counter class' "
375 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
376 offsetof(struct monitorinfo, mi_oc_monitorCounterObject) },
377 { "monitorOperation", "( 1.3.6.1.4.1.4203.666.3.10 "
378 "NAME 'monitorOperation' "
379 "DESC 'monitor operation class' "
380 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
381 offsetof(struct monitorinfo, mi_oc_monitorOperation) },
382 { "monitorConnection", "( 1.3.6.1.4.1.4203.666.3.11 "
383 "NAME 'monitorConnection' "
384 "DESC 'monitor connection class' "
385 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
386 offsetof(struct monitorinfo, mi_oc_monitorConnection) },
387 { "managedObject", "( 1.3.6.1.4.1.4203.666.3.12 "
388 "NAME 'managedObject' "
389 "DESC 'monitor managed entity class' "
390 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
391 offsetof(struct monitorinfo, mi_oc_managedObject) },
392 { "monitoredObject", "( 1.3.6.1.4.1.4203.666.3.13 "
393 "NAME 'monitoredObject' "
394 "DESC 'monitor monitored entity class' "
395 "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
396 offsetof(struct monitorinfo, mi_oc_monitoredObject) },
397 { NULL, NULL, 0, -1 }
399 { "monitoredInfo", "( 1.3.6.1.4.1.4203.666.1.14 "
400 "NAME 'monitoredInfo' "
401 "DESC 'monitored info' "
403 "EQUALITY caseIgnoreMatch "
404 "SUBSTR caseIgnoreSubstringsMatch "
405 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} "
406 "NO-USER-MODIFICATION "
407 "USAGE directoryOperation )", SLAP_AT_HIDE,
408 offsetof(struct monitorinfo, mi_ad_monitoredInfo) },
409 { "managedInfo", "( 1.3.6.1.4.1.4203.666.1.15 "
410 "NAME 'managedInfo' "
411 "DESC 'monitor managed info' "
412 "SUP name )", SLAP_AT_HIDE,
413 offsetof(struct monitorinfo, mi_ad_managedInfo) },
414 { "monitorCounter", "( 1.3.6.1.4.1.4203.666.1.16 "
415 "NAME 'monitorCounter' "
416 "DESC 'monitor counter' "
417 "EQUALITY integerMatch "
418 "ORDERING integerOrderingMatch "
419 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 "
420 "NO-USER-MODIFICATION "
421 "USAGE directoryOperation )", SLAP_AT_HIDE,
422 offsetof(struct monitorinfo, mi_ad_monitorCounter) },
423 { "monitorOpCompleted", "( 1.3.6.1.4.1.4203.666.1.17 "
424 "NAME 'monitorOpCompleted' "
425 "DESC 'monitor completed operations' "
426 "SUP monitorCounter "
427 "NO-USER-MODIFICATION "
428 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
429 offsetof(struct monitorinfo, mi_ad_monitorOpCompleted) },
430 { "monitorOpInitiated", "( 1.3.6.1.4.1.4203.666.1.18 "
431 "NAME 'monitorOpInitiated' "
432 "DESC 'monitor initiated operations' "
433 "SUP monitorCounter "
434 "NO-USER-MODIFICATION "
435 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
436 offsetof(struct monitorinfo, mi_ad_monitorOpInitiated) },
437 { "monitorConnectionNumber", "( 1.3.6.1.4.1.4203.666.1.19 "
438 "NAME 'monitorConnectionNumber' "
439 "DESC 'monitor connection number' "
440 "SUP monitorCounter "
441 "NO-USER-MODIFICATION "
442 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
443 offsetof(struct monitorinfo, mi_ad_monitorConnectionNumber) },
444 { "monitorConnectionAuthzDN", "( 1.3.6.1.4.1.4203.666.1.20 "
445 "NAME 'monitorConnectionAuthzDN' "
446 "DESC 'monitor connection authorization DN' "
447 /* "SUP distinguishedName " */
448 "EQUALITY distinguishedNameMatch "
449 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 "
450 "NO-USER-MODIFICATION "
451 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
452 offsetof(struct monitorinfo, mi_ad_monitorConnectionAuthzDN) },
453 { "monitorConnectionLocalAddress", "( 1.3.6.1.4.1.4203.666.1.21 "
454 "NAME 'monitorConnectionLocalAddress' "
455 "DESC 'monitor connection local address' "
457 "NO-USER-MODIFICATION "
458 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
459 offsetof(struct monitorinfo, mi_ad_monitorConnectionLocalAddress) },
460 { "monitorConnectionPeerAddress", "( 1.3.6.1.4.1.4203.666.1.22 "
461 "NAME 'monitorConnectionPeerAddress' "
462 "DESC 'monitor connection peer address' "
464 "NO-USER-MODIFICATION "
465 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
466 offsetof(struct monitorinfo, mi_ad_monitorConnectionPeerAddress) },
467 { "monitorTimestamp", "( 1.3.6.1.4.1.4203.666.1.24 "
468 "NAME 'monitorTimestamp' "
469 "DESC 'monitor timestamp' "
470 "EQUALITY generalizedTimeMatch "
471 "ORDERING generalizedTimeOrderingMatch "
472 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 "
474 "NO-USER-MODIFICATION "
475 "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
476 offsetof(struct monitorinfo, mi_ad_monitorTimestamp) },
477 { "monitorOverlay", "( 1.3.6.1.4.1.4203.666.1.27 "
478 "NAME 'monitorOverlay' "
479 "DESC 'name of overlays defined for a give database' "
481 "NO-USER-MODIFICATION "
482 "USAGE directoryOperation )", SLAP_AT_HIDE,
483 offsetof(struct monitorinfo, mi_ad_monitorOverlay) },
484 { "readOnly", "( 1.3.6.1.4.1.4203.666.1.31 "
486 "DESC 'read/write status of a given database' "
487 "EQUALITY booleanMatch "
488 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
490 "USAGE directoryOperation )", SLAP_AT_HIDE,
491 offsetof(struct monitorinfo, mi_ad_readOnly) },
492 { "restrictedOperation", "( 1.3.6.1.4.1.4203.666.1.32 "
493 "NAME 'restrictedOperation' "
494 "DESC 'name of restricted operation for a given database' "
495 "SUP managedInfo )", SLAP_AT_HIDE,
496 offsetof(struct monitorinfo, mi_ad_restrictedOperation ) },
497 #ifdef INTEGRATE_CORE_SCHEMA
498 { NULL, NULL, 0, -1 }, /* description */
499 { NULL, NULL, 0, -1 }, /* seeAlso */
500 { NULL, NULL, 0, -1 }, /* l */
501 { NULL, NULL, 0, -1 }, /* labeledURI */
502 #endif /* INTEGRATE_CORE_SCHEMA */
503 { NULL, NULL, 0, -1 }
505 { "description", "( 2.5.4.13 "
506 "NAME 'description' "
507 "DESC 'RFC2256: descriptive information' "
508 "EQUALITY caseIgnoreMatch "
509 "SUBSTR caseIgnoreSubstringsMatch "
510 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{1024} )", 0,
511 offsetof(struct monitorinfo, mi_ad_description) },
512 { "seeAlso", "( 2.5.4.34 "
514 "DESC 'RFC2256: DN of related object' "
515 "SUP distinguishedName )", 0,
516 offsetof(struct monitorinfo, mi_ad_seeAlso) },
518 "NAME ( 'l' 'localityName' ) "
519 "DESC 'RFC2256: locality which this object resides in' "
521 offsetof(struct monitorinfo, mi_ad_l) },
522 { "labeledURI", "( 1.3.6.1.4.1.250.1.57 "
524 "DESC 'RFC2079: Uniform Resource Identifier with optional label' "
525 "EQUALITY caseExactMatch "
526 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )", 0,
527 offsetof(struct monitorinfo, mi_ad_labeledURI) },
528 { NULL, NULL, 0, -1 }
532 * database monitor can be defined once only
535 Debug( LDAP_DEBUG_ANY,
536 "only one monitor backend is allowed\n", 0, 0, 0 );
541 /* indicate system schema supported */
542 SLAP_BFLAGS(be) |= SLAP_BFLAG_MONITOR;
544 dn.bv_val = SLAPD_MONITOR_DN;
545 dn.bv_len = sizeof( SLAPD_MONITOR_DN ) - 1;
547 rc = dnNormalize( 0, NULL, NULL, &dn, &ndn, NULL );
548 if( rc != LDAP_SUCCESS ) {
549 Debug( LDAP_DEBUG_ANY,
550 "unable to normalize monitor DN \"%s\"\n",
551 SLAPD_MONITOR_DN, 0, 0 );
555 ber_dupbv( &bv, &dn );
556 ber_bvarray_add( &be->be_suffix, &bv );
557 ber_bvarray_add( &be->be_nsuffix, &ndn );
559 mi = ( struct monitorinfo * )ch_calloc( sizeof( struct monitorinfo ), 1 );
561 Debug( LDAP_DEBUG_ANY,
562 "unable to initialize monitor backend\n", 0, 0, 0 );
566 memset( mi, 0, sizeof( struct monitorinfo ) );
568 ldap_pvt_thread_mutex_init( &mi->mi_cache_mutex );
572 #ifdef INTEGRATE_CORE_SCHEMA
573 /* prepare for schema integration */
574 for ( k = 0; mat[ k ].name != NULL; k++ );
575 #endif /* INTEGRATE_CORE_SCHEMA */
577 for ( i = 0; mat_core[ i ].name != NULL; i++ ) {
578 AttributeDescription **ad;
581 ad = ((AttributeDescription **)&(((char *)mi)[ mat_core[ i ].offset ]));
584 switch (slap_str2ad( mat_core[ i ].name, ad, &text ) ) {
588 #ifdef INTEGRATE_CORE_SCHEMA
589 case LDAP_UNDEFINED_TYPE:
590 mat[ k ] = mat_core[ i ];
593 #endif /* INTEGRATE_CORE_SCHEMA */
596 Debug( LDAP_DEBUG_ANY,
597 "monitor_back_db_init: %s: %s\n",
598 mat_core[ i ].name, text, 0 );
603 /* schema integration */
604 for ( i = 0; mat[ i ].name; i++ ) {
605 LDAPAttributeType *at;
608 AttributeDescription **ad;
610 at = ldap_str2attributetype( mat[ i ].schema, &code,
611 &err, LDAP_SCHEMA_ALLOW_ALL );
613 Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
614 "in AttributeType \"%s\" %s before %s\n",
615 mat[ i ].name, ldap_scherr2str(code), err );
619 if ( at->at_oid == NULL ) {
620 Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
621 "null OID for attributeType \"%s\"\n",
622 mat[ i ].name, 0, 0 );
626 code = at_add(at, &err);
628 Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
629 "%s in attributeType \"%s\"\n",
630 scherr2str(code), mat[ i ].name, 0 );
635 ad = ((AttributeDescription **)&(((char *)mi)[ mat[ i ].offset ]));
637 if ( slap_str2ad( mat[ i ].name, ad, &text ) ) {
638 Debug( LDAP_DEBUG_ANY,
639 "monitor_back_db_init: %s\n", text, 0, 0 );
643 (*ad)->ad_type->sat_flags |= mat[ i ].flags;
646 for ( i = 0; moc[ i ].name; i++ ) {
652 oc = ldap_str2objectclass(moc[ i ].schema, &code, &err,
653 LDAP_SCHEMA_ALLOW_ALL );
655 Debug( LDAP_DEBUG_ANY,
656 "unable to parse monitor objectclass \"%s\": "
657 "%s before %s\n" , moc[ i ].name,
658 ldap_scherr2str(code), err );
662 if ( oc->oc_oid == NULL ) {
663 Debug( LDAP_DEBUG_ANY,
664 "objectclass \"%s\" has no OID\n" ,
665 moc[ i ].name, 0, 0 );
669 code = oc_add(oc, 0, &err);
671 Debug( LDAP_DEBUG_ANY,
672 "objectclass \"%s\": %s \"%s\"\n" ,
673 moc[ i ].name, scherr2str(code), err );
679 Oc = oc_find( moc[ i ].name );
681 Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
682 "unable to find objectClass %s "
683 "(just added)\n", moc[ i ].name, 0, 0 );
687 Oc->soc_flags |= moc[ i ].flags;
689 ((ObjectClass **)&(((char *)mi)[ moc[ i ].offset ]))[ 0 ] = Oc;
696 monitor_back_db_open(
700 struct monitorinfo *mi = (struct monitorinfo *)be->be_private;
701 struct monitorsubsys **ms;
703 struct monitorentrypriv *mp;
705 char buf[ BACKMONITOR_BUFSIZE ],
712 static char tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
717 #ifndef HAVE_GMTIME_R
718 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
720 #ifdef HACK_LOCAL_TIME
721 # ifdef HAVE_LOCALTIME_R
722 tms = localtime_r( &starttime, &tm_buf );
724 tms = localtime( &starttime );
725 # endif /* HAVE_LOCALTIME_R */
726 lutil_localtime( tmbuf, sizeof(tmbuf), tms, -timezone );
727 #else /* !HACK_LOCAL_TIME */
728 # ifdef HAVE_GMTIME_R
729 tms = gmtime_r( &starttime, &tm_buf );
731 tms = gmtime( &starttime );
732 # endif /* HAVE_GMTIME_R */
733 lutil_gentime( tmbuf, sizeof(tmbuf), tms );
734 #endif /* !HACK_LOCAL_TIME */
735 #ifndef HAVE_GMTIME_R
736 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
739 mi->mi_startTime.bv_val = tmbuf;
740 mi->mi_startTime.bv_len = strlen( tmbuf );
742 if ( BER_BVISEMPTY( &be->be_rootdn ) ) {
743 BER_BVSTR( &mi->mi_creatorsName, SLAPD_ANONYMOUS );
745 mi->mi_creatorsName = be->be_rootdn;
749 * creates the "cn=Monitor" entry
751 snprintf( buf, sizeof( buf ),
754 "structuralObjectClass: %s\n"
756 "%s: This subtree contains monitoring/managing objects.\n"
757 "%s: This object contains information about this server.\n"
759 "%s: createTimestamp reflects the time this server instance was created.\n"
760 "%s: modifyTimestamp reflects the time this server instance was last accessed.\n"
763 "modifiersName: %s\n"
764 "createTimestamp: %s\n"
765 "modifyTimestamp: %s\n",
767 mi->mi_oc_monitorServer->soc_cname.bv_val,
768 mi->mi_oc_monitorServer->soc_cname.bv_val,
769 mi->mi_ad_description->ad_cname.bv_val,
770 mi->mi_ad_description->ad_cname.bv_val,
772 mi->mi_ad_description->ad_cname.bv_val,
773 mi->mi_ad_description->ad_cname.bv_val,
775 mi->mi_creatorsName.bv_val,
776 mi->mi_creatorsName.bv_val,
777 mi->mi_startTime.bv_val,
778 mi->mi_startTime.bv_val );
780 e = str2entry( buf );
782 Debug( LDAP_DEBUG_ANY,
783 "unable to create \"%s\" entry\n",
784 SLAPD_MONITOR_DN, 0, 0 );
788 bv.bv_val = (char *) Versionstr;
789 end_of_line = strchr( Versionstr, '\n' );
791 bv.bv_len = end_of_line - Versionstr;
793 bv.bv_len = strlen( Versionstr );
796 if ( attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo,
798 Debug( LDAP_DEBUG_ANY,
799 "unable to add monitoredInfo to \"%s\" entry\n",
800 SLAPD_MONITOR_DN, 0, 0 );
804 if ( mi->mi_l.bv_len ) {
805 if ( attr_merge_normalize_one( e, mi->mi_ad_l, &mi->mi_l, NULL ) ) {
806 Debug( LDAP_DEBUG_ANY,
807 "unable to add locality to \"%s\" entry\n",
808 SLAPD_MONITOR_DN, 0, 0 );
813 mp = monitor_entrypriv_create();
817 e->e_private = ( void * )mp;
818 ep = &mp->mp_children;
820 if ( monitor_cache_add( mi, e ) ) {
821 Debug( LDAP_DEBUG_ANY,
822 "unable to add entry \"%s\" to cache\n",
823 SLAPD_MONITOR_DN, 0, 0 );
828 * Create all the subsystem specific entries
830 for ( i = 0; monitor_subsys[ i ] != NULL; i++ ) {
831 int len = strlen( monitor_subsys[ i ]->mss_name );
835 dn.bv_len = len + sizeof( "cn=" ) - 1;
836 dn.bv_val = ch_calloc( sizeof( char ), dn.bv_len + 1 );
837 strcpy( dn.bv_val, "cn=" );
838 strcat( dn.bv_val, monitor_subsys[ i ]->mss_name );
839 rc = dnPretty( NULL, &dn, &monitor_subsys[ i ]->mss_rdn, NULL );
841 if ( rc != LDAP_SUCCESS ) {
842 Debug( LDAP_DEBUG_ANY,
843 "monitor RDN \"%s\" is invalid\n",
848 dn.bv_len += sizeof( SLAPD_MONITOR_DN ); /* 1 for the , */
849 dn.bv_val = ch_malloc( dn.bv_len + 1 );
850 strcpy( dn.bv_val , monitor_subsys[ i ]->mss_rdn.bv_val );
851 strcat( dn.bv_val, "," SLAPD_MONITOR_DN );
852 rc = dnPrettyNormal( NULL, &dn, &monitor_subsys[ i ]->mss_dn,
853 &monitor_subsys[ i ]->mss_ndn, NULL );
855 if ( rc != LDAP_SUCCESS ) {
856 Debug( LDAP_DEBUG_ANY,
857 "monitor DN \"%s\" is invalid\n",
862 snprintf( buf, sizeof( buf ),
865 "structuralObjectClass: %s\n"
868 "modifiersName: %s\n"
869 "createTimestamp: %s\n"
870 "modifyTimestamp: %s\n",
871 monitor_subsys[ i ]->mss_dn.bv_val,
872 mi->mi_oc_monitorContainer->soc_cname.bv_val,
873 mi->mi_oc_monitorContainer->soc_cname.bv_val,
874 monitor_subsys[ i ]->mss_name,
875 mi->mi_creatorsName.bv_val,
876 mi->mi_creatorsName.bv_val,
877 mi->mi_startTime.bv_val,
878 mi->mi_startTime.bv_val );
880 e = str2entry( buf );
883 Debug( LDAP_DEBUG_ANY,
884 "unable to create \"%s\" entry\n",
885 monitor_subsys[ i ]->mss_dn.bv_val, 0, 0 );
889 mp = monitor_entrypriv_create();
893 e->e_private = ( void * )mp;
894 mp->mp_info = monitor_subsys[ i ];
895 mp->mp_flags = monitor_subsys[ i ]->mss_flags;
897 if ( monitor_cache_add( mi, e ) ) {
898 Debug( LDAP_DEBUG_ANY,
899 "unable to add entry \"%s\" to cache\n",
900 monitor_subsys[ i ]->mss_dn.bv_val, 0, 0 );
913 * opens the monitor backend subsystems
915 for ( ms = monitor_subsys; ms[ 0 ] != NULL; ms++ ) {
916 if ( ms[ 0 ]->mss_open && ( *ms[ 0 ]->mss_open )( be, ms[ 0 ] ) )
920 ms[ 0 ]->mss_flags |= MONITOR_F_OPENED;
923 monitor_subsys_opened = 1;
938 * eventually, will hold backend specific configuration parameters
940 return SLAP_CONF_UNKNOWN;
944 monitor_back_db_config(
952 struct monitorinfo *mi = (struct monitorinfo *)be->be_private;
955 * eventually, will hold database specific configuration parameters
957 if ( strcasecmp( argv[ 0 ], "l" ) == 0 ) {
962 ber_str2bv( argv[ 1 ], 0, 1, &mi->mi_l );
965 return SLAP_CONF_UNKNOWN;
972 monitor_back_db_destroy(
977 * FIXME: destroys all the data