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 * database monitor can be defined once only
47 static int monitor_defined = 0;
50 * used by many functions to add description to entries
52 AttributeDescription *monitor_ad_desc = NULL;
57 struct monitorsubsys monitor_subsys[] = {
59 SLAPD_MONITOR_LISTENER, SLAPD_MONITOR_LISTENER_NAME,
66 SLAPD_MONITOR_DATABASE, SLAPD_MONITOR_DATABASE_NAME,
68 MONITOR_F_PERSISTENT_CH,
69 monitor_subsys_database_init,
73 SLAPD_MONITOR_BACKEND, SLAPD_MONITOR_BACKEND_NAME,
75 MONITOR_F_PERSISTENT_CH,
76 monitor_subsys_backend_init,
80 SLAPD_MONITOR_THREAD, SLAPD_MONITOR_THREAD_NAME,
84 monitor_subsys_thread_update,
87 SLAPD_MONITOR_SASL, SLAPD_MONITOR_SASL_NAME,
94 SLAPD_MONITOR_TLS, SLAPD_MONITOR_TLS_NAME,
101 SLAPD_MONITOR_CONN, SLAPD_MONITOR_CONN_NAME,
103 MONITOR_F_VOLATILE_CH,
104 monitor_subsys_conn_init,
105 monitor_subsys_conn_update,
106 monitor_subsys_conn_create
108 SLAPD_MONITOR_READW, SLAPD_MONITOR_READW_NAME,
112 monitor_subsys_readw_update,
115 SLAPD_MONITOR_WRITEW, SLAPD_MONITOR_WRITEW_NAME,
119 monitor_subsys_writew_update,
125 monitor_back_initialize(
129 static char *controls[] = {
130 LDAP_CONTROL_MANAGEDSAIT,
134 bi->bi_controls = controls;
137 bi->bi_open = monitor_back_open;
138 bi->bi_config = monitor_back_config;
140 bi->bi_destroy = NULL;
142 bi->bi_db_init = monitor_back_db_init;
143 bi->bi_db_config = monitor_back_db_config;
144 bi->bi_db_open = NULL;
145 bi->bi_db_close = NULL;
146 bi->bi_db_destroy = monitor_back_db_destroy;
148 bi->bi_op_bind = NULL;
149 bi->bi_op_unbind = NULL;
150 bi->bi_op_search = monitor_back_search;
151 bi->bi_op_compare = monitor_back_compare;
152 bi->bi_op_modify = NULL;
153 bi->bi_op_modrdn = NULL;
154 bi->bi_op_add = NULL;
155 bi->bi_op_delete = NULL;
156 bi->bi_op_abandon = monitor_back_abandon;
158 bi->bi_extended = NULL;
160 bi->bi_entry_release_rw = NULL;
161 bi->bi_acl_group = NULL;
162 bi->bi_acl_attribute = NULL;
163 bi->bi_chk_referrals = NULL;
166 * hooks for slap tools
168 bi->bi_tool_entry_open = NULL;
169 bi->bi_tool_entry_close = NULL;
170 bi->bi_tool_entry_first = NULL;
171 bi->bi_tool_entry_next = NULL;
172 bi->bi_tool_entry_get = NULL;
173 bi->bi_tool_entry_put = NULL;
174 bi->bi_tool_entry_reindex = NULL;
175 bi->bi_tool_sync = NULL;
177 bi->bi_connection_init = 0;
178 bi->bi_connection_destroy = 0;
184 monitor_back_db_init(
188 struct monitorinfo *mi;
190 struct monitorentrypriv *mp;
195 if ( monitor_defined ) {
197 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
198 "only one monitor backend is allowed\n" ));
200 Debug( LDAP_DEBUG_ANY,
201 "only one monitor backend is allowed\n%s%s%s",
208 charray_add( &be->be_suffix, SLAPD_MONITOR_DN );
209 charray_add( &be->be_nsuffix, SLAPD_MONITOR_NDN );
211 mi = ( struct monitorinfo * )ch_calloc( sizeof( struct monitorinfo ), 1 );
212 ldap_pvt_thread_mutex_init( &mi->mi_cache_mutex );
214 if ( slap_str2ad( "description", &monitor_ad_desc, &text ) ) {
216 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
217 "monitor_back_db_init: %s\n", text ));
219 Debug( LDAP_DEBUG_ANY,
220 "monitor_subsys_backend_init: %s\n%s%s",
227 for ( i = 0; monitor_subsys[ i ].mss_name != NULL; i++ ) {
228 int len = strlen( monitor_subsys[ i ].mss_name );
229 monitor_subsys[ i ].mss_rdn = ch_calloc( sizeof( char ),
231 strcpy( monitor_subsys[ i ].mss_rdn, "cn=" );
232 strcat( monitor_subsys[ i ].mss_rdn,
233 monitor_subsys[ i ].mss_name );
235 monitor_subsys[ i ].mss_dn = ch_calloc( sizeof( char ),
236 4 + len + sizeof( SLAPD_MONITOR_DN ) );
237 strcpy( monitor_subsys[ i ].mss_dn,
238 monitor_subsys[ i ].mss_rdn );
239 strcat( monitor_subsys[ i ].mss_dn, "," );
240 strcat( monitor_subsys[ i ].mss_dn, SLAPD_MONITOR_DN );
242 monitor_subsys[ i ].mss_ndn
243 = ch_strdup( monitor_subsys[ i ].mss_dn );
244 dn_normalize( monitor_subsys[ i ].mss_ndn );
246 snprintf( buf, sizeof( buf ),
249 "objectClass: LDAPsubEntry\n"
250 #ifdef SLAPD_MONITORSUBENTRY
251 "objectClass: monitorSubEntry\n"
252 #else /* !SLAPD_MONITORSUBENTRY */
253 "objectClass: extensibleObject\n"
254 #endif /* !SLAPD_MONITORSUBENTRY */
256 monitor_subsys[ i ].mss_dn,
257 monitor_subsys[ i ].mss_name );
259 e = str2entry( buf );
263 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
264 "unable to create '%s' entry\n",
265 monitor_subsys[ i ].mss_dn ));
267 Debug( LDAP_DEBUG_ANY,
268 "unable to create '%s' entry\n%s%s",
269 monitor_subsys[ i ].mss_dn, "", "" );
274 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
275 e->e_private = ( void * )mp;
276 mp->mp_info = &monitor_subsys[ i ];
277 mp->mp_children = NULL;
279 mp->mp_flags = monitor_subsys[ i ].mss_flags;
281 if ( monitor_cache_add( mi, e ) ) {
283 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
284 "unable to add entry '%s' to cache\n",
285 monitor_subsys[ i ].mss_dn ));
287 Debug( LDAP_DEBUG_ANY,
288 "unable to add entry '%s' to cache\n%s%s",
289 monitor_subsys[ i ].mss_dn, "", "" );
298 * creates the "cn=Monitor" entry
299 * and all the subsystem specific entries
301 snprintf( buf, sizeof( buf ),
304 "objectClass: LDAPsubEntry\n"
305 #ifdef SLAPD_MONITORSUBENTRY
306 "objectClass: monitorSubEntry\n"
307 #else /* !SLAPD_MONITORSUBENTRY */
308 "objectClass: extensibleObject\n"
309 #endif /* !SLAPD_MONITORSUBENTRY */
315 e = str2entry( buf );
318 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
319 "unable to create '%s' entry\n",
322 Debug( LDAP_DEBUG_ANY,
323 "unable to create '%s' entry\n%s%s",
324 SLAPD_MONITOR_DN, "", "" );
329 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
330 e->e_private = ( void * )mp;
333 mp->mp_children = e_tmp;
336 if ( monitor_cache_add( mi, e ) ) {
338 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
339 "unable to add entry '%s' to cache\n",
342 Debug( LDAP_DEBUG_ANY,
343 "unable to add entry '%s' to cache\n%s%s",
344 SLAPD_MONITOR_DN, "", "" );
360 struct monitorsubsys *ms;
363 * adds the monitor backend
365 be = select_backend( SLAPD_MONITOR_NDN, 0 );
368 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
369 "unable to get monitor backend\n" ));
371 Debug( LDAP_DEBUG_ANY,
372 "unable to get monitor backend\n%s%s%s", "", "", "" );
377 for ( ms = monitor_subsys; ms->mss_name != NULL; ms++ ) {
378 if ( ms->mss_init && ( *ms->mss_init )( be ) ) {
396 * eventually, will hold backend specific configuration parameters
402 monitor_back_db_config(
411 LDAP_LOG(( "config", LDAP_DEBUG_NOTICE,
412 "line %d of file '%s' will be ignored\n", lineno, fname ));
414 Debug( LDAP_DEBUG_CONFIG,
415 "line %d of file '%s' will be ignored\n%s", lineno, fname, "" );
421 monitor_back_db_destroy(
426 * FIXME: destroys all the data