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,
67 SLAPD_MONITOR_DATABASE, SLAPD_MONITOR_DATABASE_NAME,
69 MONITOR_F_PERSISTENT_CH,
70 monitor_subsys_database_init,
75 SLAPD_MONITOR_BACKEND, SLAPD_MONITOR_BACKEND_NAME,
77 MONITOR_F_PERSISTENT_CH,
78 monitor_subsys_backend_init,
83 SLAPD_MONITOR_THREAD, SLAPD_MONITOR_THREAD_NAME,
86 monitor_subsys_thread_init,
87 monitor_subsys_thread_update,
91 SLAPD_MONITOR_SASL, SLAPD_MONITOR_SASL_NAME,
99 SLAPD_MONITOR_TLS, SLAPD_MONITOR_TLS_NAME,
107 SLAPD_MONITOR_CONN, SLAPD_MONITOR_CONN_NAME,
109 MONITOR_F_VOLATILE_CH,
110 monitor_subsys_conn_init,
111 monitor_subsys_conn_update,
112 monitor_subsys_conn_create,
115 SLAPD_MONITOR_READW, SLAPD_MONITOR_READW_NAME,
119 monitor_subsys_readw_update,
123 SLAPD_MONITOR_WRITEW, SLAPD_MONITOR_WRITEW_NAME,
127 monitor_subsys_writew_update,
131 SLAPD_MONITOR_LOG, SLAPD_MONITOR_LOG_NAME,
134 monitor_subsys_log_init,
137 monitor_subsys_log_modify
142 monitor_back_initialize(
146 static char *controls[] = {
147 LDAP_CONTROL_MANAGEDSAIT,
151 bi->bi_controls = controls;
154 bi->bi_open = monitor_back_open;
155 bi->bi_config = monitor_back_config;
157 bi->bi_destroy = NULL;
159 bi->bi_db_init = monitor_back_db_init;
160 bi->bi_db_config = monitor_back_db_config;
161 bi->bi_db_open = NULL;
162 bi->bi_db_close = NULL;
163 bi->bi_db_destroy = monitor_back_db_destroy;
165 bi->bi_op_bind = monitor_back_bind;
166 bi->bi_op_unbind = NULL;
167 bi->bi_op_search = monitor_back_search;
168 bi->bi_op_compare = monitor_back_compare;
169 bi->bi_op_modify = monitor_back_modify;
170 bi->bi_op_modrdn = NULL;
171 bi->bi_op_add = NULL;
172 bi->bi_op_delete = NULL;
173 bi->bi_op_abandon = monitor_back_abandon;
175 bi->bi_extended = NULL;
177 bi->bi_entry_release_rw = NULL;
178 bi->bi_acl_group = NULL;
179 bi->bi_acl_attribute = NULL;
180 bi->bi_chk_referrals = NULL;
183 * hooks for slap tools
185 bi->bi_tool_entry_open = NULL;
186 bi->bi_tool_entry_close = NULL;
187 bi->bi_tool_entry_first = NULL;
188 bi->bi_tool_entry_next = NULL;
189 bi->bi_tool_entry_get = NULL;
190 bi->bi_tool_entry_put = NULL;
191 bi->bi_tool_entry_reindex = NULL;
192 bi->bi_tool_sync = NULL;
194 bi->bi_connection_init = 0;
195 bi->bi_connection_destroy = 0;
201 monitor_back_db_init(
205 struct monitorinfo *mi;
207 struct monitorentrypriv *mp;
209 char buf[1024], *ndn;
212 if ( monitor_defined ) {
214 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
215 "only one monitor backend is allowed\n" ));
217 Debug( LDAP_DEBUG_ANY,
218 "only one monitor backend is allowed\n%s%s%s",
225 ndn = ch_strdup( SLAPD_MONITOR_DN );
226 charray_add( &be->be_suffix, ndn );
228 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 for ( i = 0; monitor_subsys[ i ].mss_name != NULL; i++ ) {
248 int len = strlen( monitor_subsys[ i ].mss_name );
249 monitor_subsys[ i ].mss_rdn = ch_calloc( sizeof( char ),
251 strcpy( monitor_subsys[ i ].mss_rdn, "cn=" );
252 strcat( monitor_subsys[ i ].mss_rdn,
253 monitor_subsys[ i ].mss_name );
255 monitor_subsys[ i ].mss_dn = ch_calloc( sizeof( char ),
256 4 + len + sizeof( SLAPD_MONITOR_DN ) );
257 strcpy( monitor_subsys[ i ].mss_dn,
258 monitor_subsys[ i ].mss_rdn );
259 strcat( monitor_subsys[ i ].mss_dn, "," );
260 strcat( monitor_subsys[ i ].mss_dn, SLAPD_MONITOR_DN );
262 monitor_subsys[ i ].mss_ndn
263 = ch_strdup( monitor_subsys[ i ].mss_dn );
264 dn_normalize( monitor_subsys[ i ].mss_ndn );
266 snprintf( buf, sizeof( buf ),
269 "objectClass: LDAPsubEntry\n"
270 #ifdef SLAPD_MONITORSUBENTRY
271 "objectClass: monitorSubEntry\n"
272 #else /* !SLAPD_MONITORSUBENTRY */
273 "objectClass: extensibleObject\n"
274 #endif /* !SLAPD_MONITORSUBENTRY */
276 monitor_subsys[ i ].mss_dn,
277 monitor_subsys[ i ].mss_name );
279 e = str2entry( buf );
283 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
284 "unable to create '%s' entry\n",
285 monitor_subsys[ i ].mss_dn ));
287 Debug( LDAP_DEBUG_ANY,
288 "unable to create '%s' entry\n%s%s",
289 monitor_subsys[ i ].mss_dn, "", "" );
294 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
295 e->e_private = ( void * )mp;
296 mp->mp_info = &monitor_subsys[ i ];
297 mp->mp_children = NULL;
299 mp->mp_flags = monitor_subsys[ i ].mss_flags;
301 if ( monitor_cache_add( mi, e ) ) {
303 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
304 "unable to add entry '%s' to cache\n",
305 monitor_subsys[ i ].mss_dn ));
307 Debug( LDAP_DEBUG_ANY,
308 "unable to add entry '%s' to cache\n%s%s",
309 monitor_subsys[ i ].mss_dn, "", "" );
318 * creates the "cn=Monitor" entry
319 * and all the subsystem specific entries
321 snprintf( buf, sizeof( buf ),
324 "objectClass: LDAPsubEntry\n"
325 #ifdef SLAPD_MONITORSUBENTRY
326 "objectClass: monitorSubEntry\n"
327 #else /* !SLAPD_MONITORSUBENTRY */
328 "objectClass: extensibleObject\n"
329 #endif /* !SLAPD_MONITORSUBENTRY */
333 /* (char *) Versionstr */ "slapd 2.0"
335 e = str2entry( buf );
338 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
339 "unable to create '%s' entry\n",
342 Debug( LDAP_DEBUG_ANY,
343 "unable to create '%s' entry\n%s%s",
344 SLAPD_MONITOR_DN, "", "" );
349 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
350 e->e_private = ( void * )mp;
353 mp->mp_children = e_tmp;
356 if ( monitor_cache_add( mi, e ) ) {
358 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
359 "unable to add entry '%s' to cache\n",
362 Debug( LDAP_DEBUG_ANY,
363 "unable to add entry '%s' to cache\n%s%s",
364 SLAPD_MONITOR_DN, "", "" );
380 struct monitorsubsys *ms;
384 * adds the monitor backend
386 ndn = ch_strdup( SLAPD_MONITOR_DN );
388 be = select_backend( ndn , 0 );
392 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
393 "unable to get monitor backend\n" ));
395 Debug( LDAP_DEBUG_ANY,
396 "unable to get monitor backend\n%s%s%s", "", "", "" );
401 for ( ms = monitor_subsys; ms->mss_name != NULL; ms++ ) {
402 if ( ms->mss_init && ( *ms->mss_init )( be ) ) {
420 * eventually, will hold backend specific configuration parameters
426 monitor_back_db_config(
435 LDAP_LOG(( "config", LDAP_DEBUG_NOTICE,
436 "line %d of file '%s' will be ignored\n", lineno, fname ));
438 Debug( LDAP_DEBUG_CONFIG,
439 "line %d of file '%s' will be ignored\n%s", lineno, fname, "" );
445 monitor_back_db_destroy(
450 * FIXME: destroys all the data