1 /* init.c - initialize monitor backend */
3 * Copyright 1998-2002 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>
40 #include "back-monitor.h"
43 * used by many functions to add description to entries
45 AttributeDescription *monitor_ad_desc = NULL;
46 BackendDB *be_monitor = NULL;
51 struct monitorsubsys monitor_subsys[] = {
53 SLAPD_MONITOR_LISTENER, SLAPD_MONITOR_LISTENER_NAME,
54 { 0L, NULL }, { 0L, NULL }, { 0L, NULL },
55 MONITOR_F_PERSISTENT_CH,
56 monitor_subsys_listener_init,
61 SLAPD_MONITOR_DATABASE, SLAPD_MONITOR_DATABASE_NAME,
62 { 0L, NULL }, { 0L, NULL }, { 0L, NULL },
63 MONITOR_F_PERSISTENT_CH,
64 monitor_subsys_database_init,
69 SLAPD_MONITOR_BACKEND, SLAPD_MONITOR_BACKEND_NAME,
70 { 0L, NULL }, { 0L, NULL }, { 0L, NULL },
71 MONITOR_F_PERSISTENT_CH,
72 monitor_subsys_backend_init,
77 SLAPD_MONITOR_THREAD, SLAPD_MONITOR_THREAD_NAME,
78 { 0L, NULL }, { 0L, NULL }, { 0L, NULL },
80 monitor_subsys_thread_init,
81 monitor_subsys_thread_update,
85 SLAPD_MONITOR_SASL, SLAPD_MONITOR_SASL_NAME,
86 { 0L, NULL }, { 0L, NULL }, { 0L, NULL },
93 SLAPD_MONITOR_TLS, SLAPD_MONITOR_TLS_NAME,
94 { 0L, NULL }, { 0L, NULL }, { 0L, NULL },
101 SLAPD_MONITOR_CONN, SLAPD_MONITOR_CONN_NAME,
102 { 0L, NULL }, { 0L, NULL }, { 0L, NULL },
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 { 0L, NULL }, { 0L, NULL }, { 0L, NULL },
113 monitor_subsys_readw_update,
117 SLAPD_MONITOR_WRITEW, SLAPD_MONITOR_WRITEW_NAME,
118 { 0L, NULL }, { 0L, NULL }, { 0L, NULL },
121 monitor_subsys_writew_update,
125 SLAPD_MONITOR_LOG, SLAPD_MONITOR_LOG_NAME,
126 { 0L, NULL }, { 0L, NULL }, { 0L, NULL },
128 monitor_subsys_log_init,
131 monitor_subsys_log_modify
133 SLAPD_MONITOR_OPS, SLAPD_MONITOR_OPS_NAME,
134 { 0L, NULL }, { 0L, NULL }, { 0L, NULL },
135 MONITOR_F_PERSISTENT_CH,
136 monitor_subsys_ops_init,
137 monitor_subsys_ops_update,
141 SLAPD_MONITOR_SENT, SLAPD_MONITOR_SENT_NAME,
142 { 0L, NULL }, { 0L, NULL }, { 0L, NULL },
143 MONITOR_F_PERSISTENT_CH,
144 monitor_subsys_sent_init,
145 monitor_subsys_sent_update,
149 SLAPD_MONITOR_TIME, SLAPD_MONITOR_TIME_NAME,
150 { 0L, NULL }, { 0L, NULL }, { 0L, NULL },
151 MONITOR_F_PERSISTENT_CH,
152 monitor_subsys_time_init,
153 monitor_subsys_time_update,
160 monitor_back_initialize(
164 static char *controls[] = {
165 LDAP_CONTROL_MANAGEDSAIT,
169 bi->bi_controls = controls;
172 bi->bi_open = monitor_back_open;
173 bi->bi_config = monitor_back_config;
177 bi->bi_db_init = monitor_back_db_init;
178 bi->bi_db_config = monitor_back_db_config;
181 bi->bi_db_destroy = monitor_back_db_destroy;
183 bi->bi_op_bind = monitor_back_bind;
184 bi->bi_op_unbind = 0;
185 bi->bi_op_search = monitor_back_search;
186 bi->bi_op_compare = monitor_back_compare;
187 bi->bi_op_modify = monitor_back_modify;
188 bi->bi_op_modrdn = 0;
190 bi->bi_op_delete = 0;
191 bi->bi_op_abandon = 0;
195 bi->bi_entry_release_rw = 0;
196 bi->bi_acl_group = 0;
197 bi->bi_acl_attribute = 0;
198 bi->bi_chk_referrals = 0;
199 bi->bi_operational = monitor_back_operational;
202 * hooks for slap tools
204 bi->bi_tool_entry_open = 0;
205 bi->bi_tool_entry_close = 0;
206 bi->bi_tool_entry_first = 0;
207 bi->bi_tool_entry_next = 0;
208 bi->bi_tool_entry_get = 0;
209 bi->bi_tool_entry_put = 0;
210 bi->bi_tool_entry_reindex = 0;
211 bi->bi_tool_sync = 0;
213 bi->bi_connection_init = 0;
214 bi->bi_connection_destroy = 0;
220 monitor_back_db_init(
224 struct monitorinfo *mi;
226 struct monitorentrypriv *mp;
228 char buf[1024], *end_of_line;
229 struct berval dn, *ndn;
234 * database monitor can be defined once only
238 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
239 "only one monitor backend is allowed\n" ));
241 Debug( LDAP_DEBUG_ANY,
242 "only one monitor backend is allowed\n%s%s%s",
249 /* indicate system schema supported */
250 be->be_flags |= SLAP_BFLAG_MONITOR;
253 dn.bv_val = SLAPD_MONITOR_DN;
254 dn.bv_len = sizeof( SLAPD_MONITOR_DN ) - 1;
256 rc = dnNormalize( NULL, &dn, &ndn );
257 if( rc != LDAP_SUCCESS ) {
259 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
260 "monitor DN \"" SLAPD_MONITOR_DN "\" backend is allowed\n" ));
262 Debug( LDAP_DEBUG_ANY,
263 "monitor DN \"" SLAPD_MONITOR_DN "\" backend is allowed\n",
269 ber_bvecadd( &be->be_suffix, ber_dupbv( NULL, &dn ) );
270 ber_bvecadd( &be->be_nsuffix, ndn );
272 mi = ( struct monitorinfo * )ch_calloc( sizeof( struct monitorinfo ), 1 );
273 ldap_pvt_thread_mutex_init( &mi->mi_cache_mutex );
275 if ( slap_str2ad( "description", &monitor_ad_desc, &text ) ) {
277 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
278 "monitor_back_db_init: %s\n", text ));
280 Debug( LDAP_DEBUG_ANY,
281 "monitor_subsys_backend_init: %s\n%s%s",
288 * Create all the subsystem specific entries
291 for ( i = 0; monitor_subsys[ i ].mss_name != NULL; i++ ) {
292 int len = strlen( monitor_subsys[ i ].mss_name );
296 dn.bv_len = len + sizeof( "cn=" ) - 1;
297 dn.bv_val = ch_calloc( sizeof( char ), dn.bv_len + 1 );
298 strcpy( dn.bv_val, "cn=" );
299 strcat( dn.bv_val, monitor_subsys[ i ].mss_name );
300 rc = dnPretty2( NULL, &dn, &monitor_subsys[ i ].mss_rdn );
302 if ( rc != LDAP_SUCCESS ) {
304 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
305 "monitor RDN \"%s\" is invalid\n",
308 Debug( LDAP_DEBUG_ANY,
309 "monitor RDN \"%s\" is invalid\n",
315 dn.bv_len += sizeof( SLAPD_MONITOR_DN ); /* 1 for the , */
316 dn.bv_val = ch_malloc( dn.bv_len + 1 );
317 strcpy( dn.bv_val , monitor_subsys[ i ].mss_rdn.bv_val );
318 strcat( dn.bv_val, "," SLAPD_MONITOR_DN );
319 rc = dnPrettyNormal( NULL, &dn, &monitor_subsys[ i ].mss_dn,
320 &monitor_subsys[ i ].mss_ndn );
322 if ( rc != LDAP_SUCCESS ) {
324 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
325 "monitor DN \"%s\" is invalid\n",
328 Debug( LDAP_DEBUG_ANY,
329 "monitor DN \"%s\" is invalid\n",
335 snprintf( buf, sizeof( buf ),
337 SLAPD_MONITOR_OBJECTCLASSES
339 monitor_subsys[ i ].mss_dn.bv_val,
340 monitor_subsys[ i ].mss_name );
342 e = str2entry( buf );
346 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
347 "unable to create '%s' entry\n",
348 monitor_subsys[ i ].mss_dn.bv_val ));
350 Debug( LDAP_DEBUG_ANY,
351 "unable to create '%s' entry\n",
352 monitor_subsys[ i ].mss_dn.bv_val, 0, 0 );
357 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
358 e->e_private = ( void * )mp;
359 mp->mp_info = &monitor_subsys[ i ];
360 mp->mp_children = NULL;
362 mp->mp_flags = monitor_subsys[ i ].mss_flags;
364 if ( monitor_cache_add( mi, e ) ) {
366 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
367 "unable to add entry '%s' to cache\n",
368 monitor_subsys[ i ].mss_dn.bv_val ));
370 Debug( LDAP_DEBUG_ANY,
371 "unable to add entry '%s' to cache\n",
372 monitor_subsys[ i ].mss_dn.bv_val, 0, 0 );
381 * creates the "cn=Monitor" entry
383 snprintf( buf, sizeof( buf ),
384 "dn: " SLAPD_MONITOR_DN "\n"
386 "objectClass: monitor\n"
387 "objectClass: extensibleObject\n"
388 "structuralObjectClass: monitor\n"
391 e = str2entry( buf );
394 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
395 "unable to create '%s' entry\n",
398 Debug( LDAP_DEBUG_ANY,
399 "unable to create '%s' entry\n%s%s",
400 SLAPD_MONITOR_DN, "", "" );
405 bv[0].bv_val = (char *) Versionstr;
406 end_of_line = strchr( Versionstr, '\n' );
408 bv[0].bv_len = end_of_line - Versionstr;
410 bv[0].bv_len = strlen( Versionstr );
412 if ( attr_merge( e, monitor_ad_desc, bv ) ) {
414 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
415 "unable to add description to '%s' entry\n",
418 Debug( LDAP_DEBUG_ANY,
419 "unable to add description to '%s' entry\n%s%s",
420 SLAPD_MONITOR_DN, "", "" );
425 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
426 e->e_private = ( void * )mp;
429 mp->mp_children = e_tmp;
432 if ( monitor_cache_add( mi, e ) ) {
434 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
435 "unable to add entry '%s' to cache\n",
438 Debug( LDAP_DEBUG_ANY,
439 "unable to add entry '%s' to cache\n%s%s",
440 SLAPD_MONITOR_DN, "", "" );
456 struct monitorsubsys *ms;
457 struct berval dn = { sizeof(SLAPD_MONITOR_DN)-1, SLAPD_MONITOR_DN };
462 * adds the monitor backend
464 rc = dnNormalize2( NULL, &dn, &ndn );
465 if( rc != LDAP_SUCCESS ) {
467 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
468 "monitor DN \"" SLAPD_MONITOR_DN "\" is invalid\n" ));
470 Debug( LDAP_DEBUG_ANY,
471 "monitor DN \"" SLAPD_MONITOR_DN "\" is invalid\n",
477 be = select_backend( &ndn , 0, 0 );
482 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
483 "unable to get monitor backend\n" ));
485 Debug( LDAP_DEBUG_ANY,
486 "unable to get monitor backend\n", 0, 0, 0 );
491 for ( ms = monitor_subsys; ms->mss_name != NULL; ms++ ) {
492 if ( ms->mss_init && ( *ms->mss_init )( be ) ) {
510 * eventually, will hold backend specific configuration parameters
516 monitor_back_db_config(
525 LDAP_LOG(( "config", LDAP_DEBUG_CONFIG,
526 "line %d of file '%s' will be ignored\n", lineno, fname ));
528 Debug( LDAP_DEBUG_CONFIG,
529 "line %d of file '%s' will be ignored\n%s", lineno, fname, "" );
535 monitor_back_db_destroy(
540 * FIXME: destroys all the data