1 /* init.c - initialize monitor backend */
3 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
7 * Copyright 2001 The OpenLDAP Foundation, All Rights Reserved.
8 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
10 * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
12 * This work has beed deveolped for the OpenLDAP Foundation
13 * in the hope that it may be useful to the Open Source community,
14 * but WITHOUT ANY WARRANTY.
16 * Permission is granted to anyone to use this software for any purpose
17 * on any computer system, and to alter it and redistribute it, subject
18 * to the following restrictions:
20 * 1. The author and SysNet s.n.c. are not responsible for the consequences
21 * of use of this software, no matter how awful, even if they arise from
24 * 2. The origin of this software must not be misrepresented, either by
25 * explicit claim or by omission. Since few users ever read sources,
26 * credits should appear in the documentation.
28 * 3. Altered versions must be plainly marked as such, and must not be
29 * misrepresented as being the original software. Since few users
30 * ever read sources, credits should appear in the documentation.
31 * SysNet s.n.c. cannot be responsible for the consequences of the
34 * 4. This notice may not be removed or altered.
40 #include <ac/string.h>
43 #include "back-monitor.h"
46 * used by many functions to add description to entries
48 AttributeDescription *monitor_ad_desc = NULL;
53 struct monitorsubsys monitor_subsys[] = {
55 SLAPD_MONITOR_LISTENER, SLAPD_MONITOR_LISTENER_NAME,
63 SLAPD_MONITOR_DATABASE, SLAPD_MONITOR_DATABASE_NAME,
65 MONITOR_F_PERSISTENT_CH,
66 monitor_subsys_database_init,
71 SLAPD_MONITOR_BACKEND, SLAPD_MONITOR_BACKEND_NAME,
73 MONITOR_F_PERSISTENT_CH,
74 monitor_subsys_backend_init,
79 SLAPD_MONITOR_THREAD, SLAPD_MONITOR_THREAD_NAME,
82 monitor_subsys_thread_init,
83 monitor_subsys_thread_update,
87 SLAPD_MONITOR_SASL, SLAPD_MONITOR_SASL_NAME,
95 SLAPD_MONITOR_TLS, SLAPD_MONITOR_TLS_NAME,
103 SLAPD_MONITOR_CONN, SLAPD_MONITOR_CONN_NAME,
105 MONITOR_F_VOLATILE_CH,
106 monitor_subsys_conn_init,
107 monitor_subsys_conn_update,
108 monitor_subsys_conn_create,
111 SLAPD_MONITOR_READW, SLAPD_MONITOR_READW_NAME,
115 monitor_subsys_readw_update,
119 SLAPD_MONITOR_WRITEW, SLAPD_MONITOR_WRITEW_NAME,
123 monitor_subsys_writew_update,
127 SLAPD_MONITOR_LOG, SLAPD_MONITOR_LOG_NAME,
130 monitor_subsys_log_init,
133 monitor_subsys_log_modify
135 SLAPD_MONITOR_OPS, SLAPD_MONITOR_OPS_NAME,
138 monitor_subsys_ops_init,
139 monitor_subsys_ops_update,
143 SLAPD_MONITOR_SENT, SLAPD_MONITOR_SENT_NAME,
146 monitor_subsys_sent_init,
147 monitor_subsys_sent_update,
154 monitor_back_initialize(
158 static char *controls[] = {
159 LDAP_CONTROL_MANAGEDSAIT,
163 bi->bi_controls = controls;
166 bi->bi_open = monitor_back_open;
167 bi->bi_config = monitor_back_config;
169 bi->bi_destroy = NULL;
171 bi->bi_db_init = monitor_back_db_init;
172 bi->bi_db_config = monitor_back_db_config;
173 bi->bi_db_open = NULL;
174 bi->bi_db_close = NULL;
175 bi->bi_db_destroy = monitor_back_db_destroy;
177 bi->bi_op_bind = monitor_back_bind;
178 bi->bi_op_unbind = NULL;
179 bi->bi_op_search = monitor_back_search;
180 bi->bi_op_compare = monitor_back_compare;
181 bi->bi_op_modify = monitor_back_modify;
182 bi->bi_op_modrdn = NULL;
183 bi->bi_op_add = NULL;
184 bi->bi_op_delete = NULL;
185 bi->bi_op_abandon = monitor_back_abandon;
187 bi->bi_extended = NULL;
189 bi->bi_entry_release_rw = NULL;
190 bi->bi_acl_group = NULL;
191 bi->bi_acl_attribute = NULL;
192 bi->bi_chk_referrals = NULL;
193 bi->bi_operational = monitor_back_operational;
196 * hooks for slap tools
198 bi->bi_tool_entry_open = NULL;
199 bi->bi_tool_entry_close = NULL;
200 bi->bi_tool_entry_first = NULL;
201 bi->bi_tool_entry_next = NULL;
202 bi->bi_tool_entry_get = NULL;
203 bi->bi_tool_entry_put = NULL;
204 bi->bi_tool_entry_reindex = NULL;
205 bi->bi_tool_sync = NULL;
207 bi->bi_connection_init = 0;
208 bi->bi_connection_destroy = 0;
214 monitor_back_db_init(
218 struct monitorinfo *mi;
220 struct monitorentrypriv *mp;
222 char buf[1024], *end_of_line;
223 struct berval dn, *ndn;
225 struct berval val, *bv[2] = { &val, NULL };
228 * database monitor can be defined once only
230 static int monitor_defined = 0;
232 if ( monitor_defined ) {
234 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
235 "only one monitor backend is allowed\n" ));
237 Debug( LDAP_DEBUG_ANY,
238 "only one monitor backend is allowed\n%s%s%s",
246 dn.bv_val = SLAPD_MONITOR_DN;
247 dn.bv_len = sizeof( SLAPD_MONITOR_DN ) - 1;
249 rc = dnNormalize( NULL, &dn, &ndn );
250 if( rc != LDAP_SUCCESS ) {
252 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
253 "monitor DN \"" SLAPD_MONITOR_DN "\" backend is allowed\n" ));
255 Debug( LDAP_DEBUG_ANY,
256 "monitor DN \"" SLAPD_MONITOR_DN "\" backend is allowed\n",
262 ber_bvecadd( &be->be_nsuffix, ndn );
264 mi = ( struct monitorinfo * )ch_calloc( sizeof( struct monitorinfo ), 1 );
265 ldap_pvt_thread_mutex_init( &mi->mi_cache_mutex );
267 if ( slap_str2ad( "description", &monitor_ad_desc, &text ) ) {
269 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
270 "monitor_back_db_init: %s\n", text ));
272 Debug( LDAP_DEBUG_ANY,
273 "monitor_subsys_backend_init: %s\n%s%s",
280 * Create all the subsystem specific entries
283 for ( i = 0; monitor_subsys[ i ].mss_name != NULL; i++ ) {
284 int len = strlen( monitor_subsys[ i ].mss_name );
286 monitor_subsys[ i ].mss_rdn = ch_calloc( sizeof( char ),
288 strcpy( monitor_subsys[ i ].mss_rdn, "cn=" );
289 strcat( monitor_subsys[ i ].mss_rdn,
290 monitor_subsys[ i ].mss_name );
292 monitor_subsys[ i ].mss_dn = ch_calloc( sizeof( char ),
293 4 + len + sizeof( SLAPD_MONITOR_DN ) );
294 strcpy( monitor_subsys[ i ].mss_dn,
295 monitor_subsys[ i ].mss_rdn );
296 strcat( monitor_subsys[ i ].mss_dn, "," );
297 strcat( monitor_subsys[ i ].mss_dn, SLAPD_MONITOR_DN );
299 monitor_subsys[ i ].mss_ndn
300 = ch_strdup( monitor_subsys[ i ].mss_dn );
301 dn_normalize( monitor_subsys[ i ].mss_ndn );
303 snprintf( buf, sizeof( buf ),
306 "objectClass: LDAPsubEntry\n"
307 #ifdef SLAPD_MONITORSUBENTRY
308 "objectClass: monitorSubEntry\n"
309 #else /* !SLAPD_MONITORSUBENTRY */
310 "objectClass: extensibleObject\n"
311 #endif /* !SLAPD_MONITORSUBENTRY */
313 monitor_subsys[ i ].mss_dn,
314 monitor_subsys[ i ].mss_name );
316 e = str2entry( buf );
320 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
321 "unable to create '%s' entry\n",
322 monitor_subsys[ i ].mss_dn ));
324 Debug( LDAP_DEBUG_ANY,
325 "unable to create '%s' entry\n%s%s",
326 monitor_subsys[ i ].mss_dn, "", "" );
331 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
332 e->e_private = ( void * )mp;
333 mp->mp_info = &monitor_subsys[ i ];
334 mp->mp_children = NULL;
336 mp->mp_flags = monitor_subsys[ i ].mss_flags;
338 if ( monitor_cache_add( mi, e ) ) {
340 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
341 "unable to add entry '%s' to cache\n",
342 monitor_subsys[ i ].mss_dn ));
344 Debug( LDAP_DEBUG_ANY,
345 "unable to add entry '%s' to cache\n%s%s",
346 monitor_subsys[ i ].mss_dn, "", "" );
355 * creates the "cn=Monitor" entry
357 snprintf( buf, sizeof( buf ),
358 "dn: " SLAPD_MONITOR_DN "\n"
360 "objectClass: LDAPsubEntry\n"
361 #ifdef SLAPD_MONITORSUBENTRY
362 "objectClass: monitorSubEntry\n"
363 #else /* !SLAPD_MONITORSUBENTRY */
364 "objectClass: extensibleObject\n"
365 #endif /* !SLAPD_MONITORSUBENTRY */
368 e = str2entry( buf );
371 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
372 "unable to create '%s' entry\n",
375 Debug( LDAP_DEBUG_ANY,
376 "unable to create '%s' entry\n%s%s",
377 SLAPD_MONITOR_DN, "", "" );
381 val.bv_val = (char *) Versionstr;
382 end_of_line = strchr( Versionstr, '\n' );
384 val.bv_len = end_of_line - Versionstr;
386 val.bv_len = strlen( Versionstr );
388 if ( attr_merge( e, monitor_ad_desc, bv ) ) {
390 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
391 "unable to add description to '%s' entry\n",
394 Debug( LDAP_DEBUG_ANY,
395 "unable to add description to '%s' entry\n%s%s",
396 SLAPD_MONITOR_DN, "", "" );
401 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
402 e->e_private = ( void * )mp;
405 mp->mp_children = e_tmp;
408 if ( monitor_cache_add( mi, e ) ) {
410 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
411 "unable to add entry '%s' to cache\n",
414 Debug( LDAP_DEBUG_ANY,
415 "unable to add entry '%s' to cache\n%s%s",
416 SLAPD_MONITOR_DN, "", "" );
432 struct monitorsubsys *ms;
433 struct berval dn = { sizeof(SLAPD_MONITOR_DN)-1, SLAPD_MONITOR_DN };
434 struct berval *ndn = NULL;
438 * adds the monitor backend
440 rc = dnNormalize( NULL, &dn, &ndn );
441 if( rc != LDAP_SUCCESS ) {
443 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
444 "monitor DN \"" SLAPD_MONITOR_DN "\" is invalid\n" ));
446 Debug( LDAP_DEBUG_ANY,
447 "monitor DN \"" SLAPD_MONITOR_DN "\" is invalid\n",
453 be = select_backend( ndn , 0, 0 );
458 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
459 "unable to get monitor backend\n" ));
461 Debug( LDAP_DEBUG_ANY,
462 "unable to get monitor backend\n", 0, 0, 0 );
467 for ( ms = monitor_subsys; ms->mss_name != NULL; ms++ ) {
468 if ( ms->mss_init && ( *ms->mss_init )( be ) ) {
486 * eventually, will hold backend specific configuration parameters
492 monitor_back_db_config(
501 LDAP_LOG(( "config", LDAP_DEBUG_NOTICE,
502 "line %d of file '%s' will be ignored\n", lineno, fname ));
504 Debug( LDAP_DEBUG_CONFIG,
505 "line %d of file '%s' will be ignored\n%s", lineno, fname, "" );
511 monitor_back_db_destroy(
516 * FIXME: destroys all the data