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.
42 #include "back-monitor.h"
45 * used by many functions to add description to entries
47 AttributeDescription *monitor_ad_desc = NULL;
52 struct monitorsubsys monitor_subsys[] = {
54 SLAPD_MONITOR_LISTENER, SLAPD_MONITOR_LISTENER_NAME,
62 SLAPD_MONITOR_DATABASE, SLAPD_MONITOR_DATABASE_NAME,
64 MONITOR_F_PERSISTENT_CH,
65 monitor_subsys_database_init,
70 SLAPD_MONITOR_BACKEND, SLAPD_MONITOR_BACKEND_NAME,
72 MONITOR_F_PERSISTENT_CH,
73 monitor_subsys_backend_init,
78 SLAPD_MONITOR_THREAD, SLAPD_MONITOR_THREAD_NAME,
81 monitor_subsys_thread_init,
82 monitor_subsys_thread_update,
86 SLAPD_MONITOR_SASL, SLAPD_MONITOR_SASL_NAME,
94 SLAPD_MONITOR_TLS, SLAPD_MONITOR_TLS_NAME,
102 SLAPD_MONITOR_CONN, SLAPD_MONITOR_CONN_NAME,
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,
114 monitor_subsys_readw_update,
118 SLAPD_MONITOR_WRITEW, SLAPD_MONITOR_WRITEW_NAME,
122 monitor_subsys_writew_update,
126 SLAPD_MONITOR_LOG, SLAPD_MONITOR_LOG_NAME,
129 monitor_subsys_log_init,
132 monitor_subsys_log_modify
137 monitor_back_initialize(
141 static char *controls[] = {
142 LDAP_CONTROL_MANAGEDSAIT,
146 bi->bi_controls = controls;
149 bi->bi_open = monitor_back_open;
150 bi->bi_config = monitor_back_config;
152 bi->bi_destroy = NULL;
154 bi->bi_db_init = monitor_back_db_init;
155 bi->bi_db_config = monitor_back_db_config;
156 bi->bi_db_open = NULL;
157 bi->bi_db_close = NULL;
158 bi->bi_db_destroy = monitor_back_db_destroy;
160 bi->bi_op_bind = monitor_back_bind;
161 bi->bi_op_unbind = NULL;
162 bi->bi_op_search = monitor_back_search;
163 bi->bi_op_compare = monitor_back_compare;
164 bi->bi_op_modify = monitor_back_modify;
165 bi->bi_op_modrdn = NULL;
166 bi->bi_op_add = NULL;
167 bi->bi_op_delete = NULL;
168 bi->bi_op_abandon = monitor_back_abandon;
170 bi->bi_extended = NULL;
172 bi->bi_entry_release_rw = NULL;
173 bi->bi_acl_group = NULL;
174 bi->bi_acl_attribute = NULL;
175 bi->bi_chk_referrals = NULL;
178 * hooks for slap tools
180 bi->bi_tool_entry_open = NULL;
181 bi->bi_tool_entry_close = NULL;
182 bi->bi_tool_entry_first = NULL;
183 bi->bi_tool_entry_next = NULL;
184 bi->bi_tool_entry_get = NULL;
185 bi->bi_tool_entry_put = NULL;
186 bi->bi_tool_entry_reindex = NULL;
187 bi->bi_tool_sync = NULL;
189 bi->bi_connection_init = 0;
190 bi->bi_connection_destroy = 0;
196 monitor_back_db_init(
200 struct monitorinfo *mi;
202 struct monitorentrypriv *mp;
204 char buf[1024], *ndn, *end_of_line;
206 struct berval val, *bv[2] = { &val, NULL };
209 * database monitor can be defined once only
211 static int monitor_defined = 0;
213 if ( monitor_defined ) {
215 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
216 "only one monitor backend is allowed\n" ));
218 Debug( LDAP_DEBUG_ANY,
219 "only one monitor backend is allowed\n%s%s%s",
226 ndn = ch_strdup( SLAPD_MONITOR_DN );
227 charray_add( &be->be_suffix, ndn );
229 ber_bvecadd( &be->be_nsuffix, ber_bvstr( ndn ) );
231 mi = ( struct monitorinfo * )ch_calloc( sizeof( struct monitorinfo ), 1 );
232 ldap_pvt_thread_mutex_init( &mi->mi_cache_mutex );
234 if ( slap_str2ad( "description", &monitor_ad_desc, &text ) ) {
236 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
237 "monitor_back_db_init: %s\n", text ));
239 Debug( LDAP_DEBUG_ANY,
240 "monitor_subsys_backend_init: %s\n%s%s",
247 * Create all the subsystem specific entries
250 for ( i = 0; monitor_subsys[ i ].mss_name != NULL; i++ ) {
251 int len = strlen( monitor_subsys[ i ].mss_name );
253 monitor_subsys[ i ].mss_rdn = ch_calloc( sizeof( char ),
255 strcpy( monitor_subsys[ i ].mss_rdn, "cn=" );
256 strcat( monitor_subsys[ i ].mss_rdn,
257 monitor_subsys[ i ].mss_name );
259 monitor_subsys[ i ].mss_dn = ch_calloc( sizeof( char ),
260 4 + len + sizeof( SLAPD_MONITOR_DN ) );
261 strcpy( monitor_subsys[ i ].mss_dn,
262 monitor_subsys[ i ].mss_rdn );
263 strcat( monitor_subsys[ i ].mss_dn, "," );
264 strcat( monitor_subsys[ i ].mss_dn, SLAPD_MONITOR_DN );
266 monitor_subsys[ i ].mss_ndn
267 = ch_strdup( monitor_subsys[ i ].mss_dn );
268 dn_normalize( monitor_subsys[ i ].mss_ndn );
270 snprintf( buf, sizeof( buf ),
273 "objectClass: LDAPsubEntry\n"
274 #ifdef SLAPD_MONITORSUBENTRY
275 "objectClass: monitorSubEntry\n"
276 #else /* !SLAPD_MONITORSUBENTRY */
277 "objectClass: extensibleObject\n"
278 #endif /* !SLAPD_MONITORSUBENTRY */
280 monitor_subsys[ i ].mss_dn,
281 monitor_subsys[ i ].mss_name );
283 e = str2entry( buf );
287 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
288 "unable to create '%s' entry\n",
289 monitor_subsys[ i ].mss_dn ));
291 Debug( LDAP_DEBUG_ANY,
292 "unable to create '%s' entry\n%s%s",
293 monitor_subsys[ i ].mss_dn, "", "" );
298 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
299 e->e_private = ( void * )mp;
300 mp->mp_info = &monitor_subsys[ i ];
301 mp->mp_children = NULL;
303 mp->mp_flags = monitor_subsys[ i ].mss_flags;
305 if ( monitor_cache_add( mi, e ) ) {
307 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
308 "unable to add entry '%s' to cache\n",
309 monitor_subsys[ i ].mss_dn ));
311 Debug( LDAP_DEBUG_ANY,
312 "unable to add entry '%s' to cache\n%s%s",
313 monitor_subsys[ i ].mss_dn, "", "" );
322 * creates the "cn=Monitor" entry
324 snprintf( buf, sizeof( buf ),
327 "objectClass: LDAPsubEntry\n"
328 #ifdef SLAPD_MONITORSUBENTRY
329 "objectClass: monitorSubEntry\n"
330 #else /* !SLAPD_MONITORSUBENTRY */
331 "objectClass: extensibleObject\n"
332 #endif /* !SLAPD_MONITORSUBENTRY */
336 e = str2entry( buf );
339 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
340 "unable to create '%s' entry\n",
343 Debug( LDAP_DEBUG_ANY,
344 "unable to create '%s' entry\n%s%s",
345 SLAPD_MONITOR_DN, "", "" );
349 val.bv_val = (char *) Versionstr;
350 end_of_line = strchr( Versionstr, '\n' );
352 val.bv_len = end_of_line - Versionstr;
354 val.bv_len = strlen( Versionstr );
356 if ( attr_merge( e, monitor_ad_desc, bv ) ) {
358 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
359 "unable to add description to '%s' entry\n",
362 Debug( LDAP_DEBUG_ANY,
363 "unable to add description to '%s' entry\n%s%s",
364 SLAPD_MONITOR_DN, "", "" );
369 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
370 e->e_private = ( void * )mp;
373 mp->mp_children = e_tmp;
376 if ( monitor_cache_add( mi, e ) ) {
378 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
379 "unable to add entry '%s' to cache\n",
382 Debug( LDAP_DEBUG_ANY,
383 "unable to add entry '%s' to cache\n%s%s",
384 SLAPD_MONITOR_DN, "", "" );
400 struct monitorsubsys *ms;
404 * adds the monitor backend
406 ndn = ch_strdup( SLAPD_MONITOR_DN );
408 be = select_backend( ndn , 0, 0 );
412 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
413 "unable to get monitor backend\n" ));
415 Debug( LDAP_DEBUG_ANY,
416 "unable to get monitor backend\n%s%s%s", "", "", "" );
421 for ( ms = monitor_subsys; ms->mss_name != NULL; ms++ ) {
422 if ( ms->mss_init && ( *ms->mss_init )( be ) ) {
440 * eventually, will hold backend specific configuration parameters
446 monitor_back_db_config(
455 LDAP_LOG(( "config", LDAP_DEBUG_NOTICE,
456 "line %d of file '%s' will be ignored\n", lineno, fname ));
458 Debug( LDAP_DEBUG_CONFIG,
459 "line %d of file '%s' will be ignored\n%s", lineno, fname, "" );
465 monitor_back_db_destroy(
470 * FIXME: destroys all the data