1 /* init.c - initialize monitor backend */
3 * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
7 * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
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.
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:
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
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.
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
31 * 4. This notice may not be removed or altered.
37 #include <ac/string.h>
41 #include "back-monitor.h"
44 * used by many functions to add description to entries
46 AttributeDescription *monitor_ad_desc = NULL;
47 BackendDB *be_monitor = NULL;
52 struct monitorsubsys monitor_subsys[] = {
54 SLAPD_MONITOR_LISTENER, SLAPD_MONITOR_LISTENER_NAME,
55 BER_BVNULL, BER_BVNULL, BER_BVNULL,
56 MONITOR_F_PERSISTENT_CH,
57 monitor_subsys_listener_init,
62 SLAPD_MONITOR_DATABASE, SLAPD_MONITOR_DATABASE_NAME,
63 BER_BVNULL, BER_BVNULL, BER_BVNULL,
64 MONITOR_F_PERSISTENT_CH,
65 monitor_subsys_database_init,
70 SLAPD_MONITOR_BACKEND, SLAPD_MONITOR_BACKEND_NAME,
71 BER_BVNULL, BER_BVNULL, BER_BVNULL,
72 MONITOR_F_PERSISTENT_CH,
73 monitor_subsys_backend_init,
78 SLAPD_MONITOR_THREAD, SLAPD_MONITOR_THREAD_NAME,
79 BER_BVNULL, BER_BVNULL, BER_BVNULL,
81 monitor_subsys_thread_init,
82 monitor_subsys_thread_update,
86 SLAPD_MONITOR_SASL, SLAPD_MONITOR_SASL_NAME,
87 BER_BVNULL, BER_BVNULL, BER_BVNULL,
94 SLAPD_MONITOR_TLS, SLAPD_MONITOR_TLS_NAME,
95 BER_BVNULL, BER_BVNULL, BER_BVNULL,
102 SLAPD_MONITOR_CONN, SLAPD_MONITOR_CONN_NAME,
103 BER_BVNULL, BER_BVNULL, BER_BVNULL,
104 MONITOR_F_VOLATILE_CH,
105 monitor_subsys_conn_init,
106 monitor_subsys_conn_update,
107 monitor_subsys_conn_create,
110 SLAPD_MONITOR_READW, SLAPD_MONITOR_READW_NAME,
111 BER_BVNULL, BER_BVNULL, BER_BVNULL,
114 monitor_subsys_readw_update,
118 SLAPD_MONITOR_WRITEW, SLAPD_MONITOR_WRITEW_NAME,
119 BER_BVNULL, BER_BVNULL, BER_BVNULL,
122 monitor_subsys_writew_update,
126 SLAPD_MONITOR_LOG, SLAPD_MONITOR_LOG_NAME,
127 BER_BVNULL, BER_BVNULL, BER_BVNULL,
129 monitor_subsys_log_init,
132 monitor_subsys_log_modify
134 SLAPD_MONITOR_OPS, SLAPD_MONITOR_OPS_NAME,
135 BER_BVNULL, BER_BVNULL, BER_BVNULL,
136 MONITOR_F_PERSISTENT_CH,
137 monitor_subsys_ops_init,
138 monitor_subsys_ops_update,
142 SLAPD_MONITOR_SENT, SLAPD_MONITOR_SENT_NAME,
143 BER_BVNULL, BER_BVNULL, BER_BVNULL,
144 MONITOR_F_PERSISTENT_CH,
145 monitor_subsys_sent_init,
146 monitor_subsys_sent_update,
150 SLAPD_MONITOR_TIME, SLAPD_MONITOR_TIME_NAME,
151 BER_BVNULL, BER_BVNULL, BER_BVNULL,
152 MONITOR_F_PERSISTENT_CH,
153 monitor_subsys_time_init,
154 monitor_subsys_time_update,
160 #ifdef SLAPD_MONITOR_DYNAMIC
163 back_monitor_LTX_init_module( int argc, char *argv[] )
167 memset( &bi, '\0', sizeof(bi) );
168 bi.bi_type = "monitor";
169 bi.bi_init = monitor_back_initialize;
174 #endif /* SLAPD_MONITOR_DYNAMIC */
177 monitor_back_initialize(
181 static char *controls[] = {
182 LDAP_CONTROL_MANAGEDSAIT,
183 LDAP_CONTROL_VALUESRETURNFILTER,
187 bi->bi_controls = controls;
191 bi->bi_config = monitor_back_config;
195 bi->bi_db_init = monitor_back_db_init;
196 bi->bi_db_config = monitor_back_db_config;
197 bi->bi_db_open = monitor_back_db_open;
199 bi->bi_db_destroy = monitor_back_db_destroy;
201 bi->bi_op_bind = monitor_back_bind;
202 bi->bi_op_unbind = 0;
203 bi->bi_op_search = monitor_back_search;
204 bi->bi_op_compare = monitor_back_compare;
205 bi->bi_op_modify = monitor_back_modify;
206 bi->bi_op_modrdn = 0;
208 bi->bi_op_delete = 0;
209 bi->bi_op_abandon = 0;
213 bi->bi_entry_release_rw = 0;
214 bi->bi_chk_referrals = 0;
215 bi->bi_operational = monitor_back_operational;
218 * hooks for slap tools
220 bi->bi_tool_entry_open = 0;
221 bi->bi_tool_entry_close = 0;
222 bi->bi_tool_entry_first = 0;
223 bi->bi_tool_entry_next = 0;
224 bi->bi_tool_entry_get = 0;
225 bi->bi_tool_entry_put = 0;
226 bi->bi_tool_entry_reindex = 0;
227 bi->bi_tool_sync = 0;
229 bi->bi_connection_init = 0;
230 bi->bi_connection_destroy = 0;
236 monitor_back_db_init(
240 struct monitorinfo *mi;
242 struct monitorentrypriv *mp;
244 char buf[1024], *end_of_line;
245 struct berval dn, ndn;
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) },
290 { "monitoredInfo", "( 1.3.6.1.4.1.4203.666.XXX"
291 "NAME 'monitoredInfo' "
292 "DESC 'monitored info' "
294 offsetof(struct monitorinfo, monitor_ad_monitoredInfo) },
295 { "managedInfo", "( 1.3.6.1.4.1.4203.666.XXX"
296 "NAME 'managedInfo' "
297 "DESC 'monitor managed info' "
299 offsetof(struct monitorinfo, monitor_ad_managedInfo) },
300 { "monitorCounter", "( 1.3.6.1.4.1.4203.666.XXX"
301 "NAME 'monitorCounter' "
302 "DESC 'monitor counter' "
303 "EQUALITY integerMatch "
304 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
305 offsetof(struct monitorinfo, monitor_ad_monitorCounter) },
306 { "monitorOpCompleted", "( 1.3.6.1.4.1.4203.666.XXX"
307 "NAME 'monitorOpCompleted' "
308 "DESC 'monitor completed operations' "
309 "SUP monitorCounter )",
310 offsetof(struct monitorinfo, monitor_ad_monitorOpCompleted) },
311 { "monitorOpInitiated", "( 1.3.6.1.4.1.4203.666.XXX"
312 "NAME 'monitorOpInitiated' "
313 "DESC 'monitor initiated operations' "
314 "SUP monitorCounter )",
315 offsetof(struct monitorinfo, monitor_ad_monitorOpInitiated) },
316 { "monitorConnectionNumber", "( 1.3.6.1.4.1.4203.666.XXX"
317 "NAME 'monitorConnectionNumber' "
318 "DESC 'monitor connection number' "
319 "SUP monitorCounter )",
320 offsetof(struct monitorinfo, monitor_ad_monitorConnectionNumber) },
321 { "monitorConnectionAuthzDN", "( 1.3.6.1.4.1.4203.666.XXX"
322 "NAME 'monitorConnectionAuthzDN' "
323 "DESC 'monitor connection authorization DN' "
324 "SUP distinguishedName)",
325 offsetof(struct monitorinfo, monitor_ad_monitorConnectionAuthzDN) },
326 { "monitorConnectionLocalAddress", "( 1.3.6.1.4.1.4203.666.XXX"
327 "NAME 'monitorConnectionLocalAddress' "
328 "DESC 'monitor connection local address' "
329 "SUP monitoredInfo)",
330 offsetof(struct monitorinfo, monitor_ad_monitorConnectionLocalAddress) },
331 { "monitorConnectionPeerAddress", "( 1.3.6.1.4.1.4203.666.XXX"
332 "NAME 'monitorConnectionPeerAddress' "
333 "DESC 'monitor connection peer address' "
334 "SUP monitoredInfo)",
335 offsetof(struct monitorinfo, monitor_ad_monitorConnectionPeerAddress) },
340 * database monitor can be defined once only
344 LDAP_LOG( OPERATION, CRIT,
345 "only one monitor backend is allowed\n", 0, 0, 0);
347 Debug( LDAP_DEBUG_ANY,
348 "only one monitor backend is allowed\n", 0, 0, 0 );
354 /* indicate system schema supported */
355 be->be_flags |= SLAP_BFLAG_MONITOR;
357 dn.bv_val = SLAPD_MONITOR_DN;
358 dn.bv_len = sizeof( SLAPD_MONITOR_DN ) - 1;
360 rc = dnNormalize2( NULL, &dn, &ndn, NULL );
361 if( rc != LDAP_SUCCESS ) {
363 LDAP_LOG( OPERATION, CRIT,
364 "unable to normalize monitor DN \"" SLAPD_MONITOR_DN
367 Debug( LDAP_DEBUG_ANY,
368 "unable to normalize monitor DN \"" SLAPD_MONITOR_DN
374 ber_dupbv( &bv, &dn );
375 ber_bvarray_add( &be->be_suffix, &bv );
376 ber_bvarray_add( &be->be_nsuffix, &ndn );
378 mi = ( struct monitorinfo * )ch_calloc( sizeof( struct monitorinfo ), 1 );
383 ldap_pvt_thread_mutex_init( &mi->mi_cache_mutex );
385 for ( i = 0; moc[i].name; i++ ) {
391 oc = ldap_str2objectclass(moc[i].schema, &code, &err,
392 LDAP_SCHEMA_ALLOW_ALL );
395 LDAP_LOG( OPERATION, CRIT,
396 "unable to parse monitor objectclass '%s' "
397 "(%s before %s)\n" , moc[i].name,
398 ldap_scherr2str(code), err );
400 Debug( LDAP_DEBUG_ANY,
401 "unable to parse monitor objectclass '%s' "
402 "(%s before %s)\n" , moc[i].name,
403 ldap_scherr2str(code), err );
408 if ( oc->oc_oid == NULL ) {
410 LDAP_LOG( OPERATION, CRIT,
411 "objectclass '%s' has no OID\n" ,
414 Debug( LDAP_DEBUG_ANY,
415 "objectclass '%s' has no OID\n" ,
421 code = oc_add(oc,1,&err);
424 LDAP_LOG( OPERATION, CRIT,
425 "objectclass '%s' (%s before %s)\n" ,
426 moc[i].name, scherr2str(code), err );
428 Debug( LDAP_DEBUG_ANY,
429 "objectclass '%s' (%s before %s)\n" ,
430 moc[i].name, scherr2str(code), err );
437 Oc = oc_find( moc[i].name );
442 ((ObjectClass **)&(((char *)mi)[moc[i].offset]))[0] = Oc;
445 for ( i = 0; mat[i].name; i++ ) {
446 LDAPAttributeType *at;
449 AttributeDescription **ad;
451 at = ldap_str2attributetype( mat[i].schema, &code,
452 &err, LDAP_SCHEMA_ALLOW_ALL );
457 if ( at->at_oid == NULL ) {
461 /* operational attributes should be defined internally
462 if ( at->at_usage ) {
463 fprintf( stderr, "%s: line %d: attribute type \"%s\" is operational\n",
464 fname, lineno, at->at_oid );
468 code = at_add(at,&err);
474 ad = ((AttributeDescription **)&(((char *)mi)[mat[i].offset]));
476 if ( slap_str2ad( mat[i].name, ad, &text ) ) {
478 LDAP_LOG( OPERATION, CRIT,
479 "monitor_back_db_init: %s\n", text, 0, 0 );
481 Debug( LDAP_DEBUG_ANY,
482 "monitor_subsys_backend_init: %s\n%s%s",
489 if ( slap_str2ad( "description", &mi->monitor_ad_description, &text ) ) {
491 LDAP_LOG( OPERATION, CRIT,
492 "monitor_back_db_init: %s\n", text, 0, 0 );
494 Debug( LDAP_DEBUG_ANY,
495 "monitor_subsys_backend_init: %s\n%s%s",
502 * Create all the subsystem specific entries
505 for ( i = 0; monitor_subsys[ i ].mss_name != NULL; i++ ) {
506 int len = strlen( monitor_subsys[ i ].mss_name );
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 );
516 if ( rc != LDAP_SUCCESS ) {
518 LDAP_LOG( OPERATION, CRIT,
519 "monitor RDN \"%s\" is invalid\n",
522 Debug( LDAP_DEBUG_ANY,
523 "monitor RDN \"%s\" is invalid\n",
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 );
536 if ( rc != LDAP_SUCCESS ) {
538 LDAP_LOG( OPERATION, CRIT,
539 "monitor DN \"%s\" is invalid\n",
542 Debug( LDAP_DEBUG_ANY,
543 "monitor DN \"%s\" is invalid\n",
549 snprintf( buf, sizeof( buf ),
551 SLAPD_MONITOR_OBJECTCLASSES
553 monitor_subsys[ i ].mss_dn.bv_val,
554 monitor_subsys[ i ].mss_name );
556 e = str2entry( buf );
560 LDAP_LOG( OPERATION, CRIT,
561 "unable to create '%s' entry\n",
562 monitor_subsys[ i ].mss_dn.bv_val, 0, 0 );
564 Debug( LDAP_DEBUG_ANY,
565 "unable to create '%s' entry\n",
566 monitor_subsys[ i ].mss_dn.bv_val, 0, 0 );
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;
576 mp->mp_flags = monitor_subsys[ i ].mss_flags;
578 if ( monitor_cache_add( mi, e ) ) {
580 LDAP_LOG( OPERATION, CRIT,
581 "unable to add entry '%s' to cache\n",
582 monitor_subsys[ i ].mss_dn.bv_val, 0, 0 );
584 Debug( LDAP_DEBUG_ANY,
585 "unable to add entry '%s' to cache\n",
586 monitor_subsys[ i ].mss_dn.bv_val, 0, 0 );
595 * creates the "cn=Monitor" entry
597 snprintf( buf, sizeof( buf ),
598 "dn: " SLAPD_MONITOR_DN "\n"
600 "objectClass: monitor\n"
601 "objectClass: extensibleObject\n"
602 "structuralObjectClass: monitor\n"
605 e = str2entry( buf );
608 LDAP_LOG( OPERATION, CRIT,
609 "unable to create '%s' entry\n",
610 SLAPD_MONITOR_DN, 0, 0 );
612 Debug( LDAP_DEBUG_ANY,
613 "unable to create '%s' entry\n%s%s",
614 SLAPD_MONITOR_DN, "", "" );
618 bv.bv_val = (char *) Versionstr;
619 end_of_line = strchr( Versionstr, '\n' );
621 bv.bv_len = end_of_line - Versionstr;
623 bv.bv_len = strlen( Versionstr );
625 if ( attr_merge_normalize_one( e, monitor_ad_desc, &bv, NULL ) ) {
627 LDAP_LOG( OPERATION, CRIT,
628 "unable to add description to '%s' entry\n",
629 SLAPD_MONITOR_DN, 0, 0 );
631 Debug( LDAP_DEBUG_ANY,
632 "unable to add description to '%s' entry\n%s%s",
633 SLAPD_MONITOR_DN, "", "" );
638 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
639 e->e_private = ( void * )mp;
642 mp->mp_children = e_tmp;
645 if ( monitor_cache_add( mi, e ) ) {
647 LDAP_LOG( OPERATION, CRIT,
648 "unable to add entry '%s' to cache\n",
649 SLAPD_MONITOR_DN, 0, 0 );
651 Debug( LDAP_DEBUG_ANY,
652 "unable to add entry '%s' to cache\n%s%s",
653 SLAPD_MONITOR_DN, "", "" );
664 monitor_back_db_open(
668 struct monitorsubsys *ms;
673 * opens the monitor backend
675 for ( ms = monitor_subsys; ms->mss_name != NULL; ms++ ) {
676 if ( ms->mss_init && ( *ms->mss_init )( be ) ) {
694 * eventually, will hold backend specific configuration parameters
700 monitor_back_db_config(
709 * eventually, will hold database specific configuration parameters
712 LDAP_LOG( CONFIG, INFO,
713 "line %d of file '%s' will be ignored\n", lineno, fname, 0 );
715 Debug( LDAP_DEBUG_CONFIG,
716 "line %d of file '%s' will be ignored\n%s", lineno, fname, "" );
722 monitor_back_db_destroy(
727 * FIXME: destroys all the data