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 BackendDB *be_monitor = NULL;
51 struct monitorsubsys monitor_subsys[] = {
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,
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,
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,
77 SLAPD_MONITOR_THREAD, SLAPD_MONITOR_THREAD_NAME,
78 BER_BVNULL, BER_BVNULL, BER_BVNULL,
80 monitor_subsys_thread_init,
81 monitor_subsys_thread_update,
85 SLAPD_MONITOR_SASL, SLAPD_MONITOR_SASL_NAME,
86 BER_BVNULL, BER_BVNULL, BER_BVNULL,
93 SLAPD_MONITOR_TLS, SLAPD_MONITOR_TLS_NAME,
94 BER_BVNULL, BER_BVNULL, BER_BVNULL,
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,
109 SLAPD_MONITOR_READW, SLAPD_MONITOR_READW_NAME,
110 BER_BVNULL, BER_BVNULL, BER_BVNULL,
113 monitor_subsys_readw_update,
117 SLAPD_MONITOR_WRITEW, SLAPD_MONITOR_WRITEW_NAME,
118 BER_BVNULL, BER_BVNULL, BER_BVNULL,
121 monitor_subsys_writew_update,
125 SLAPD_MONITOR_LOG, SLAPD_MONITOR_LOG_NAME,
126 BER_BVNULL, BER_BVNULL, BER_BVNULL,
128 monitor_subsys_log_init,
131 monitor_subsys_log_modify
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,
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,
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,
159 #ifdef SLAPD_MONITOR_DYNAMIC
162 back_monitor_LTX_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_DYNAMIC */
176 monitor_back_initialize(
180 static char *controls[] = {
181 LDAP_CONTROL_MANAGEDSAIT,
182 LDAP_CONTROL_VALUESRETURNFILTER,
186 bi->bi_controls = controls;
190 bi->bi_config = monitor_back_config;
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;
198 bi->bi_db_destroy = monitor_back_db_destroy;
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;
207 bi->bi_op_delete = 0;
208 bi->bi_op_abandon = 0;
212 bi->bi_entry_release_rw = 0;
213 bi->bi_chk_referrals = 0;
214 bi->bi_operational = monitor_back_operational;
217 * hooks for slap tools
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;
228 bi->bi_connection_init = 0;
229 bi->bi_connection_destroy = 0;
235 monitor_back_db_init(
239 struct monitorinfo *mi;
241 struct monitorentrypriv *mp;
243 char buf[1024], *end_of_line;
244 struct berval dn, ndn;
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 */
292 { "monitoredInfo", "( 1.3.6.1.4.1.4203.666.1.14"
293 "NAME 'monitoredInfo' "
294 "DESC 'monitored info' "
296 "NO-USER-MODIFICATION )",
297 offsetof(struct monitorinfo, monitor_ad_monitoredInfo) },
298 { "managedInfo", "( 1.3.6.1.4.1.4203.666.1.15 "
299 "NAME 'managedInfo' "
300 "DESC 'monitor managed info' "
302 offsetof(struct monitorinfo, monitor_ad_managedInfo) },
303 { "monitorCounter", "( 1.3.6.1.4.1.4203.666.1.16 "
304 "NAME 'monitorCounter' "
305 "DESC 'monitor counter' "
306 "EQUALITY integerMatch "
307 "ORDERING integerOrderingMatch "
308 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 "
309 "NO-USER-MODIFICATION )",
310 offsetof(struct monitorinfo, monitor_ad_monitorCounter) },
311 { "monitorOpCompleted", "( 1.3.6.1.4.1.4203.666.1.17 "
312 "NAME 'monitorOpCompleted' "
313 "DESC 'monitor completed operations' "
314 "SUP monitorCounter )",
315 offsetof(struct monitorinfo, monitor_ad_monitorOpCompleted) },
316 { "monitorOpInitiated", "( 1.3.6.1.4.1.4203.666.1.18 "
317 "NAME 'monitorOpInitiated' "
318 "DESC 'monitor initiated operations' "
319 "SUP monitorCounter )",
320 offsetof(struct monitorinfo, monitor_ad_monitorOpInitiated) },
321 { "monitorConnectionNumber", "( 1.3.6.1.4.1.4203.666.1.19 "
322 "NAME 'monitorConnectionNumber' "
323 "DESC 'monitor connection number' "
324 "SUP monitorCounter )",
325 offsetof(struct monitorinfo, monitor_ad_monitorConnectionNumber) },
326 { "monitorConnectionAuthzDN", "( 1.3.6.1.4.1.4203.666.1.20 "
327 "NAME 'monitorConnectionAuthzDN' "
328 "DESC 'monitor connection authorization DN' "
329 "SUP distinguishedName "
330 "NO-USER-MODIFICATION )",
331 offsetof(struct monitorinfo, monitor_ad_monitorConnectionAuthzDN) },
332 { "monitorConnectionLocalAddress", "( 1.3.6.1.4.1.4203.666.1.21 "
333 "NAME 'monitorConnectionLocalAddress' "
334 "DESC 'monitor connection local address' "
335 "SUP monitoredInfo )",
336 offsetof(struct monitorinfo,
337 monitor_ad_monitorConnectionLocalAddress) },
338 { "monitorConnectionPeerAddress", "( 1.3.6.1.4.1.4203.666.1.22 "
339 "NAME 'monitorConnectionPeerAddress' "
340 "DESC 'monitor connection peer address' "
341 "SUP monitoredInfo )",
342 offsetof(struct monitorinfo,
343 monitor_ad_monitorConnectionPeerAddress) },
344 #endif /* MONITOR_DEVEL */
349 * database monitor can be defined once only
353 LDAP_LOG( OPERATION, CRIT,
354 "only one monitor backend is allowed\n", 0, 0, 0);
356 Debug( LDAP_DEBUG_ANY,
357 "only one monitor backend is allowed\n", 0, 0, 0 );
363 /* indicate system schema supported */
364 be->be_flags |= SLAP_BFLAG_MONITOR;
366 dn.bv_val = SLAPD_MONITOR_DN;
367 dn.bv_len = sizeof( SLAPD_MONITOR_DN ) - 1;
369 rc = dnNormalize2( NULL, &dn, &ndn, NULL );
370 if( rc != LDAP_SUCCESS ) {
372 LDAP_LOG( OPERATION, CRIT,
373 "unable to normalize monitor DN \"" SLAPD_MONITOR_DN
376 Debug( LDAP_DEBUG_ANY,
377 "unable to normalize monitor DN \"" SLAPD_MONITOR_DN
383 ber_dupbv( &bv, &dn );
384 ber_bvarray_add( &be->be_suffix, &bv );
385 ber_bvarray_add( &be->be_nsuffix, &ndn );
387 mi = ( struct monitorinfo * )ch_calloc( sizeof( struct monitorinfo ), 1 );
390 LDAP_LOG( OPERATION, CRIT,
391 "unable to initialize monitor backend\n", 0, 0, 0 );
393 Debug( LDAP_DEBUG_ANY,
394 "unable to initialize monitor backend\n", 0, 0, 0 );
399 ldap_pvt_thread_mutex_init( &mi->mi_cache_mutex );
401 for ( i = 0; moc[i].name; i++ ) {
407 oc = ldap_str2objectclass(moc[i].schema, &code, &err,
408 LDAP_SCHEMA_ALLOW_ALL );
411 LDAP_LOG( OPERATION, CRIT,
412 "unable to parse monitor objectclass '%s': "
413 "%s before %s\n" , moc[i].name,
414 ldap_scherr2str(code), err );
416 Debug( LDAP_DEBUG_ANY,
417 "unable to parse monitor objectclass '%s': "
418 "%s before %s\n" , moc[i].name,
419 ldap_scherr2str(code), err );
424 if ( oc->oc_oid == NULL ) {
426 LDAP_LOG( OPERATION, CRIT,
427 "objectclass '%s' has no OID\n" ,
430 Debug( LDAP_DEBUG_ANY,
431 "objectclass '%s' has no OID\n" ,
437 code = oc_add(oc,1,&err);
440 LDAP_LOG( OPERATION, CRIT,
441 "objectclass '%s': %s before %s\n" ,
442 moc[i].name, scherr2str(code), err );
444 Debug( LDAP_DEBUG_ANY,
445 "objectclass '%s': %s before %s\n" ,
446 moc[i].name, scherr2str(code), err );
453 Oc = oc_find( moc[i].name );
458 ((ObjectClass **)&(((char *)mi)[moc[i].offset]))[0] = Oc;
461 for ( i = 0; mat[i].name; i++ ) {
462 LDAPAttributeType *at;
465 AttributeDescription **ad;
467 at = ldap_str2attributetype( mat[i].schema, &code,
468 &err, LDAP_SCHEMA_ALLOW_ALL );
469 if ( !at || at->at_oid == NULL ) {
473 code = at_add(at,&err);
479 ad = ((AttributeDescription **)&(((char *)mi)[mat[i].offset]));
481 if ( slap_str2ad( mat[i].name, ad, &text ) ) {
483 LDAP_LOG( OPERATION, CRIT,
484 "monitor_back_db_init: %s\n", text, 0, 0 );
486 Debug( LDAP_DEBUG_ANY,
487 "monitor_back_db_init: %s\n", text, 0, 0 );
493 if ( slap_str2ad( "description", &mi->monitor_ad_description, &text ) ) {
495 LDAP_LOG( OPERATION, CRIT,
496 "monitor_back_db_init: %s\n", text, 0, 0 );
498 Debug( LDAP_DEBUG_ANY,
499 "monitor_back_db_init: %s\n", text, 0, 0 );
505 * Create all the subsystem specific entries
508 for ( i = 0; monitor_subsys[ i ].mss_name != NULL; i++ ) {
509 int len = strlen( monitor_subsys[ i ].mss_name );
513 dn.bv_len = len + sizeof( "cn=" ) - 1;
514 dn.bv_val = ch_calloc( sizeof( char ), dn.bv_len + 1 );
515 strcpy( dn.bv_val, "cn=" );
516 strcat( dn.bv_val, monitor_subsys[ i ].mss_name );
517 rc = dnPretty2( NULL, &dn, &monitor_subsys[ i ].mss_rdn, NULL );
519 if ( rc != LDAP_SUCCESS ) {
521 LDAP_LOG( OPERATION, CRIT,
522 "monitor RDN \"%s\" is invalid\n",
525 Debug( LDAP_DEBUG_ANY,
526 "monitor RDN \"%s\" is invalid\n",
532 dn.bv_len += sizeof( SLAPD_MONITOR_DN ); /* 1 for the , */
533 dn.bv_val = ch_malloc( dn.bv_len + 1 );
534 strcpy( dn.bv_val , monitor_subsys[ i ].mss_rdn.bv_val );
535 strcat( dn.bv_val, "," SLAPD_MONITOR_DN );
536 rc = dnPrettyNormal( NULL, &dn, &monitor_subsys[ i ].mss_dn,
537 &monitor_subsys[ i ].mss_ndn, NULL );
539 if ( rc != LDAP_SUCCESS ) {
541 LDAP_LOG( OPERATION, CRIT,
542 "monitor DN \"%s\" is invalid\n",
545 Debug( LDAP_DEBUG_ANY,
546 "monitor DN \"%s\" is invalid\n",
552 snprintf( buf, sizeof( buf ),
554 SLAPD_MONITOR_OBJECTCLASSES
556 monitor_subsys[ i ].mss_dn.bv_val,
557 monitor_subsys[ i ].mss_name );
559 e = str2entry( buf );
563 LDAP_LOG( OPERATION, CRIT,
564 "unable to create '%s' entry\n",
565 monitor_subsys[ i ].mss_dn.bv_val, 0, 0 );
567 Debug( LDAP_DEBUG_ANY,
568 "unable to create '%s' entry\n",
569 monitor_subsys[ i ].mss_dn.bv_val, 0, 0 );
574 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
575 e->e_private = ( void * )mp;
576 mp->mp_info = &monitor_subsys[ i ];
577 mp->mp_children = NULL;
579 mp->mp_flags = monitor_subsys[ i ].mss_flags;
581 if ( monitor_cache_add( mi, e ) ) {
583 LDAP_LOG( OPERATION, CRIT,
584 "unable to add entry '%s' to cache\n",
585 monitor_subsys[ i ].mss_dn.bv_val, 0, 0 );
587 Debug( LDAP_DEBUG_ANY,
588 "unable to add entry '%s' to cache\n",
589 monitor_subsys[ i ].mss_dn.bv_val, 0, 0 );
598 * creates the "cn=Monitor" entry
600 snprintf( buf, sizeof( buf ),
601 "dn: " SLAPD_MONITOR_DN "\n"
603 "objectClass: monitor\n"
604 "objectClass: extensibleObject\n"
605 "structuralObjectClass: monitor\n"
608 e = str2entry( buf );
611 LDAP_LOG( OPERATION, CRIT,
612 "unable to create '%s' entry\n",
613 SLAPD_MONITOR_DN, 0, 0 );
615 Debug( LDAP_DEBUG_ANY,
616 "unable to create '%s' entry\n%s%s",
617 SLAPD_MONITOR_DN, "", "" );
621 bv.bv_val = (char *) Versionstr;
622 end_of_line = strchr( Versionstr, '\n' );
624 bv.bv_len = end_of_line - Versionstr;
626 bv.bv_len = strlen( Versionstr );
628 if ( attr_merge_normalize_one( e, mi->monitor_ad_description,
631 LDAP_LOG( OPERATION, CRIT,
632 "unable to add description to '%s' entry\n",
633 SLAPD_MONITOR_DN, 0, 0 );
635 Debug( LDAP_DEBUG_ANY,
636 "unable to add description to '%s' entry\n%s%s",
637 SLAPD_MONITOR_DN, "", "" );
642 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
643 e->e_private = ( void * )mp;
646 mp->mp_children = e_tmp;
649 if ( monitor_cache_add( mi, e ) ) {
651 LDAP_LOG( OPERATION, CRIT,
652 "unable to add entry '%s' to cache\n",
653 SLAPD_MONITOR_DN, 0, 0 );
655 Debug( LDAP_DEBUG_ANY,
656 "unable to add entry '%s' to cache\n%s%s",
657 SLAPD_MONITOR_DN, "", "" );
668 monitor_back_db_open(
672 struct monitorsubsys *ms;
677 * opens the monitor backend
679 for ( ms = monitor_subsys; ms->mss_name != NULL; ms++ ) {
680 if ( ms->mss_init && ( *ms->mss_init )( be ) ) {
698 * eventually, will hold backend specific configuration parameters
704 monitor_back_db_config(
713 * eventually, will hold database specific configuration parameters
716 LDAP_LOG( CONFIG, INFO,
717 "line %d of file '%s' will be ignored\n", lineno, fname, 0 );
719 Debug( LDAP_DEBUG_CONFIG,
720 "line %d of file '%s' will be ignored\n%s", lineno, fname, "" );
726 monitor_back_db_destroy(
731 * FIXME: destroys all the data