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
134 SLAPD_MONITOR_OPS, SLAPD_MONITOR_OPS_NAME,
137 monitor_subsys_ops_init,
138 monitor_subsys_ops_update,
142 SLAPD_MONITOR_SENT, SLAPD_MONITOR_SENT_NAME,
145 monitor_subsys_sent_init,
146 monitor_subsys_sent_update,
153 monitor_back_initialize(
157 static char *controls[] = {
158 LDAP_CONTROL_MANAGEDSAIT,
162 bi->bi_controls = controls;
165 bi->bi_open = monitor_back_open;
166 bi->bi_config = monitor_back_config;
168 bi->bi_destroy = NULL;
170 bi->bi_db_init = monitor_back_db_init;
171 bi->bi_db_config = monitor_back_db_config;
172 bi->bi_db_open = NULL;
173 bi->bi_db_close = NULL;
174 bi->bi_db_destroy = monitor_back_db_destroy;
176 bi->bi_op_bind = monitor_back_bind;
177 bi->bi_op_unbind = NULL;
178 bi->bi_op_search = monitor_back_search;
179 bi->bi_op_compare = monitor_back_compare;
180 bi->bi_op_modify = monitor_back_modify;
181 bi->bi_op_modrdn = NULL;
182 bi->bi_op_add = NULL;
183 bi->bi_op_delete = NULL;
184 bi->bi_op_abandon = monitor_back_abandon;
186 bi->bi_extended = NULL;
188 bi->bi_entry_release_rw = NULL;
189 bi->bi_acl_group = NULL;
190 bi->bi_acl_attribute = NULL;
191 bi->bi_chk_referrals = NULL;
192 bi->bi_operational = monitor_back_operational;
195 * hooks for slap tools
197 bi->bi_tool_entry_open = NULL;
198 bi->bi_tool_entry_close = NULL;
199 bi->bi_tool_entry_first = NULL;
200 bi->bi_tool_entry_next = NULL;
201 bi->bi_tool_entry_get = NULL;
202 bi->bi_tool_entry_put = NULL;
203 bi->bi_tool_entry_reindex = NULL;
204 bi->bi_tool_sync = NULL;
206 bi->bi_connection_init = 0;
207 bi->bi_connection_destroy = 0;
213 monitor_back_db_init(
217 struct monitorinfo *mi;
219 struct monitorentrypriv *mp;
221 char buf[1024], *ndn, *end_of_line;
223 struct berval val, *bv[2] = { &val, NULL };
226 * database monitor can be defined once only
228 static int monitor_defined = 0;
230 if ( monitor_defined ) {
232 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
233 "only one monitor backend is allowed\n" ));
235 Debug( LDAP_DEBUG_ANY,
236 "only one monitor backend is allowed\n%s%s%s",
243 ndn = ch_strdup( SLAPD_MONITOR_DN );
244 charray_add( &be->be_suffix, ndn );
246 ber_bvecadd( &be->be_nsuffix, ber_bvstr( ndn ) );
248 mi = ( struct monitorinfo * )ch_calloc( sizeof( struct monitorinfo ), 1 );
249 ldap_pvt_thread_mutex_init( &mi->mi_cache_mutex );
251 if ( slap_str2ad( "description", &monitor_ad_desc, &text ) ) {
253 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
254 "monitor_back_db_init: %s\n", text ));
256 Debug( LDAP_DEBUG_ANY,
257 "monitor_subsys_backend_init: %s\n%s%s",
264 * Create all the subsystem specific entries
267 for ( i = 0; monitor_subsys[ i ].mss_name != NULL; i++ ) {
268 int len = strlen( monitor_subsys[ i ].mss_name );
270 monitor_subsys[ i ].mss_rdn = ch_calloc( sizeof( char ),
272 strcpy( monitor_subsys[ i ].mss_rdn, "cn=" );
273 strcat( monitor_subsys[ i ].mss_rdn,
274 monitor_subsys[ i ].mss_name );
276 monitor_subsys[ i ].mss_dn = ch_calloc( sizeof( char ),
277 4 + len + sizeof( SLAPD_MONITOR_DN ) );
278 strcpy( monitor_subsys[ i ].mss_dn,
279 monitor_subsys[ i ].mss_rdn );
280 strcat( monitor_subsys[ i ].mss_dn, "," );
281 strcat( monitor_subsys[ i ].mss_dn, SLAPD_MONITOR_DN );
283 monitor_subsys[ i ].mss_ndn
284 = ch_strdup( monitor_subsys[ i ].mss_dn );
285 dn_normalize( monitor_subsys[ i ].mss_ndn );
287 snprintf( buf, sizeof( buf ),
290 "objectClass: LDAPsubEntry\n"
291 #ifdef SLAPD_MONITORSUBENTRY
292 "objectClass: monitorSubEntry\n"
293 #else /* !SLAPD_MONITORSUBENTRY */
294 "objectClass: extensibleObject\n"
295 #endif /* !SLAPD_MONITORSUBENTRY */
297 monitor_subsys[ i ].mss_dn,
298 monitor_subsys[ i ].mss_name );
300 e = str2entry( buf );
304 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
305 "unable to create '%s' entry\n",
306 monitor_subsys[ i ].mss_dn ));
308 Debug( LDAP_DEBUG_ANY,
309 "unable to create '%s' entry\n%s%s",
310 monitor_subsys[ i ].mss_dn, "", "" );
315 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
316 e->e_private = ( void * )mp;
317 mp->mp_info = &monitor_subsys[ i ];
318 mp->mp_children = NULL;
320 mp->mp_flags = monitor_subsys[ i ].mss_flags;
322 if ( monitor_cache_add( mi, e ) ) {
324 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
325 "unable to add entry '%s' to cache\n",
326 monitor_subsys[ i ].mss_dn ));
328 Debug( LDAP_DEBUG_ANY,
329 "unable to add entry '%s' to cache\n%s%s",
330 monitor_subsys[ i ].mss_dn, "", "" );
339 * creates the "cn=Monitor" entry
341 snprintf( buf, sizeof( buf ),
342 "dn: " SLAPD_MONITOR_DN "\n"
344 "objectClass: LDAPsubEntry\n"
345 #ifdef SLAPD_MONITORSUBENTRY
346 "objectClass: monitorSubEntry\n"
347 #else /* !SLAPD_MONITORSUBENTRY */
348 "objectClass: extensibleObject\n"
349 #endif /* !SLAPD_MONITORSUBENTRY */
352 e = str2entry( buf );
355 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
356 "unable to create '%s' entry\n",
359 Debug( LDAP_DEBUG_ANY,
360 "unable to create '%s' entry\n%s%s",
361 SLAPD_MONITOR_DN, "", "" );
365 val.bv_val = (char *) Versionstr;
366 end_of_line = strchr( Versionstr, '\n' );
368 val.bv_len = end_of_line - Versionstr;
370 val.bv_len = strlen( Versionstr );
372 if ( attr_merge( e, monitor_ad_desc, bv ) ) {
374 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
375 "unable to add description to '%s' entry\n",
378 Debug( LDAP_DEBUG_ANY,
379 "unable to add description to '%s' entry\n%s%s",
380 SLAPD_MONITOR_DN, "", "" );
385 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
386 e->e_private = ( void * )mp;
389 mp->mp_children = e_tmp;
392 if ( monitor_cache_add( mi, e ) ) {
394 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
395 "unable to add entry '%s' to cache\n",
398 Debug( LDAP_DEBUG_ANY,
399 "unable to add entry '%s' to cache\n%s%s",
400 SLAPD_MONITOR_DN, "", "" );
416 struct monitorsubsys *ms;
417 struct berval dn = { sizeof(SLAPD_MONITOR_DN)-1, SLAPD_MONITOR_DN };
418 struct berval *ndn = NULL;
422 * adds the monitor backend
424 rc = dnNormalize( NULL, &dn, &ndn );
425 if( rc != LDAP_SUCCESS ) {
427 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
428 "monitor DN \"" SLAPD_MONITOR_DN "\" is invalid\n" ));
430 Debug( LDAP_DEBUG_ANY,
431 "monitor DN \"" SLAPD_MONITOR_DN "\" is invalid\n",
437 be = select_backend( ndn , 0, 0 );
442 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
443 "unable to get monitor backend\n" ));
445 Debug( LDAP_DEBUG_ANY,
446 "unable to get monitor backend\n", 0, 0, 0 );
451 for ( ms = monitor_subsys; ms->mss_name != NULL; ms++ ) {
452 if ( ms->mss_init && ( *ms->mss_init )( be ) ) {
470 * eventually, will hold backend specific configuration parameters
476 monitor_back_db_config(
485 LDAP_LOG(( "config", LDAP_DEBUG_NOTICE,
486 "line %d of file '%s' will be ignored\n", lineno, fname ));
488 Debug( LDAP_DEBUG_CONFIG,
489 "line %d of file '%s' will be ignored\n%s", lineno, fname, "" );
495 monitor_back_db_destroy(
500 * FIXME: destroys all the data