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;
176 bi->bi_operational = monitor_back_operational;
179 * hooks for slap tools
181 bi->bi_tool_entry_open = NULL;
182 bi->bi_tool_entry_close = NULL;
183 bi->bi_tool_entry_first = NULL;
184 bi->bi_tool_entry_next = NULL;
185 bi->bi_tool_entry_get = NULL;
186 bi->bi_tool_entry_put = NULL;
187 bi->bi_tool_entry_reindex = NULL;
188 bi->bi_tool_sync = NULL;
190 bi->bi_connection_init = 0;
191 bi->bi_connection_destroy = 0;
197 monitor_back_db_init(
201 struct monitorinfo *mi;
203 struct monitorentrypriv *mp;
205 char buf[1024], *ndn, *end_of_line;
207 struct berval val, *bv[2] = { &val, NULL };
210 * database monitor can be defined once only
212 static int monitor_defined = 0;
214 if ( monitor_defined ) {
216 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
217 "only one monitor backend is allowed\n" ));
219 Debug( LDAP_DEBUG_ANY,
220 "only one monitor backend is allowed\n%s%s%s",
227 ndn = ch_strdup( SLAPD_MONITOR_DN );
228 charray_add( &be->be_suffix, ndn );
230 ber_bvecadd( &be->be_nsuffix, ber_bvstr( ndn ) );
232 mi = ( struct monitorinfo * )ch_calloc( sizeof( struct monitorinfo ), 1 );
233 ldap_pvt_thread_mutex_init( &mi->mi_cache_mutex );
235 if ( slap_str2ad( "description", &monitor_ad_desc, &text ) ) {
237 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
238 "monitor_back_db_init: %s\n", text ));
240 Debug( LDAP_DEBUG_ANY,
241 "monitor_subsys_backend_init: %s\n%s%s",
248 * Create all the subsystem specific entries
251 for ( i = 0; monitor_subsys[ i ].mss_name != NULL; i++ ) {
252 int len = strlen( monitor_subsys[ i ].mss_name );
254 monitor_subsys[ i ].mss_rdn = ch_calloc( sizeof( char ),
256 strcpy( monitor_subsys[ i ].mss_rdn, "cn=" );
257 strcat( monitor_subsys[ i ].mss_rdn,
258 monitor_subsys[ i ].mss_name );
260 monitor_subsys[ i ].mss_dn = ch_calloc( sizeof( char ),
261 4 + len + sizeof( SLAPD_MONITOR_DN ) );
262 strcpy( monitor_subsys[ i ].mss_dn,
263 monitor_subsys[ i ].mss_rdn );
264 strcat( monitor_subsys[ i ].mss_dn, "," );
265 strcat( monitor_subsys[ i ].mss_dn, SLAPD_MONITOR_DN );
267 monitor_subsys[ i ].mss_ndn
268 = ch_strdup( monitor_subsys[ i ].mss_dn );
269 dn_normalize( monitor_subsys[ i ].mss_ndn );
271 snprintf( buf, sizeof( buf ),
274 "objectClass: LDAPsubEntry\n"
275 #ifdef SLAPD_MONITORSUBENTRY
276 "objectClass: monitorSubEntry\n"
277 #else /* !SLAPD_MONITORSUBENTRY */
278 "objectClass: extensibleObject\n"
279 #endif /* !SLAPD_MONITORSUBENTRY */
281 monitor_subsys[ i ].mss_dn,
282 monitor_subsys[ i ].mss_name );
284 e = str2entry( buf );
288 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
289 "unable to create '%s' entry\n",
290 monitor_subsys[ i ].mss_dn ));
292 Debug( LDAP_DEBUG_ANY,
293 "unable to create '%s' entry\n%s%s",
294 monitor_subsys[ i ].mss_dn, "", "" );
299 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
300 e->e_private = ( void * )mp;
301 mp->mp_info = &monitor_subsys[ i ];
302 mp->mp_children = NULL;
304 mp->mp_flags = monitor_subsys[ i ].mss_flags;
306 if ( monitor_cache_add( mi, e ) ) {
308 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
309 "unable to add entry '%s' to cache\n",
310 monitor_subsys[ i ].mss_dn ));
312 Debug( LDAP_DEBUG_ANY,
313 "unable to add entry '%s' to cache\n%s%s",
314 monitor_subsys[ i ].mss_dn, "", "" );
323 * creates the "cn=Monitor" entry
325 snprintf( buf, sizeof( buf ),
328 "objectClass: LDAPsubEntry\n"
329 #ifdef SLAPD_MONITORSUBENTRY
330 "objectClass: monitorSubEntry\n"
331 #else /* !SLAPD_MONITORSUBENTRY */
332 "objectClass: extensibleObject\n"
333 #endif /* !SLAPD_MONITORSUBENTRY */
337 e = str2entry( buf );
340 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
341 "unable to create '%s' entry\n",
344 Debug( LDAP_DEBUG_ANY,
345 "unable to create '%s' entry\n%s%s",
346 SLAPD_MONITOR_DN, "", "" );
350 val.bv_val = (char *) Versionstr;
351 end_of_line = strchr( Versionstr, '\n' );
353 val.bv_len = end_of_line - Versionstr;
355 val.bv_len = strlen( Versionstr );
357 if ( attr_merge( e, monitor_ad_desc, bv ) ) {
359 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
360 "unable to add description to '%s' entry\n",
363 Debug( LDAP_DEBUG_ANY,
364 "unable to add description to '%s' entry\n%s%s",
365 SLAPD_MONITOR_DN, "", "" );
370 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
371 e->e_private = ( void * )mp;
374 mp->mp_children = e_tmp;
377 if ( monitor_cache_add( mi, e ) ) {
379 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
380 "unable to add entry '%s' to cache\n",
383 Debug( LDAP_DEBUG_ANY,
384 "unable to add entry '%s' to cache\n%s%s",
385 SLAPD_MONITOR_DN, "", "" );
401 struct monitorsubsys *ms;
405 * adds the monitor backend
407 ndn = ch_strdup( SLAPD_MONITOR_DN );
409 be = select_backend( ndn , 0, 0 );
413 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
414 "unable to get monitor backend\n" ));
416 Debug( LDAP_DEBUG_ANY,
417 "unable to get monitor backend\n%s%s%s", "", "", "" );
422 for ( ms = monitor_subsys; ms->mss_name != NULL; ms++ ) {
423 if ( ms->mss_init && ( *ms->mss_init )( be ) ) {
441 * eventually, will hold backend specific configuration parameters
447 monitor_back_db_config(
456 LDAP_LOG(( "config", LDAP_DEBUG_NOTICE,
457 "line %d of file '%s' will be ignored\n", lineno, fname ));
459 Debug( LDAP_DEBUG_CONFIG,
460 "line %d of file '%s' will be ignored\n%s", lineno, fname, "" );
466 monitor_back_db_destroy(
471 * FIXME: destroys all the data