1 /* database.c - deals with database subsystem */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2003 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
17 * This work was initially developed by Pierangelo Masarati for inclusion
18 * in OpenLDAP Software.
20 /* This is an altered version */
22 * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
24 * This work has beed deveolped for the OpenLDAP Foundation
25 * in the hope that it may be useful to the Open Source community,
26 * but WITHOUT ANY WARRANTY.
28 * Permission is granted to anyone to use this software for any purpose
29 * on any computer system, and to alter it and redistribute it, subject
30 * to the following restrictions:
32 * 1. The author and SysNet s.n.c. are not responsible for the consequences
33 * of use of this software, no matter how awful, even if they arise from
36 * 2. The origin of this software must not be misrepresented, either by
37 * explicit claim or by omission. Since few users ever read sources,
38 * credits should appear in the documentation.
40 * 3. Altered versions must be plainly marked as such, and must not be
41 * misrepresented as being the original software. Since few users
42 * ever read sources, credits should appear in the documentation.
43 * SysNet s.n.c. cannot be responsible for the consequences of the
46 * 4. This notice may not be removed or altered.
49 #ifndef _BACK_MONITOR_H_
50 #define _BACK_MONITOR_H_
53 #include <ldap_pvt_thread.h>
60 * The cache maps DNs to Entries.
62 * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
64 * This work has beed deveolped for the OpenLDAP Foundation
65 * in the hope that it may be useful to the Open Source community,
66 * but WITHOUT ANY WARRANTY.
68 * Permission is granted to anyone to use this software for any purpose
69 * on any computer system, and to alter it and redistribute it, subject
70 * to the following restrictions:
72 * 1. The author and SysNet s.n.c. are not responsible for the consequences
73 * of use of this software, no matter how awful, even if they arise from
76 * 2. The origin of this software must not be misrepresented, either by
77 * explicit claim or by omission. Since few users ever read sources,
78 * credits should appear in the documentation.
80 * 3. Altered versions must be plainly marked as such, and must not be
81 * misrepresented as being the original software. Since few users
82 * ever read sources, credits should appear in the documentation.
83 * SysNet s.n.c. cannot be responsible for the consequences of the
86 * 4. This notice may not be removed or altered.
92 #include <ac/string.h>
95 #include "back-monitor.h"
97 #if defined(LDAP_SLAPI)
99 static int monitor_back_add_plugin( Backend *be, Entry *e );
100 #endif /* defined(LDAP_SLAPI) */
103 monitor_subsys_database_init(
107 struct monitorinfo *mi;
108 Entry *e, *e_database, *e_tmp;
110 struct monitorentrypriv *mp;
112 assert( be != NULL );
114 mi = ( struct monitorinfo * )be->be_private;
116 if ( monitor_cache_get( mi,
117 &monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn,
120 LDAP_LOG( OPERATION, CRIT,
121 "monitor_subsys_database_init: "
122 "unable to get entry '%s'\n",
123 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val, 0, 0 );
125 Debug( LDAP_DEBUG_ANY,
126 "monitor_subsys_database_init: "
127 "unable to get entry '%s'\n%s%s",
128 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val,
135 for ( i = nBackendDB; i--; ) {
136 char buf[ BACKMONITOR_BUFSIZE ];
141 /* Subordinates are not exposed as their own naming context */
142 if ( SLAP_GLUE_SUBORDINATE( be ) ) {
146 snprintf( buf, sizeof( buf ),
147 "dn: cn=Database %d,%s\n"
149 "structuralObjectClass: %s\n"
151 "description: This object contains the type of the database.\n"
153 "createTimestamp: %s\n"
154 "modifyTimestamp: %s\n",
156 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_dn.bv_val,
157 mi->mi_oc_monitoredObject->soc_cname.bv_val,
158 mi->mi_oc_monitoredObject->soc_cname.bv_val,
160 mi->mi_ad_monitoredInfo->ad_cname.bv_val,
161 be->bd_info->bi_type,
162 mi->mi_startTime.bv_val,
163 mi->mi_startTime.bv_val );
165 e = str2entry( buf );
168 LDAP_LOG( OPERATION, CRIT,
169 "monitor_subsys_database_init: "
170 "unable to create entry 'cn=Database %d,%s'\n",
171 i, monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val, 0 );
173 Debug( LDAP_DEBUG_ANY,
174 "monitor_subsys_database_init: "
175 "unable to create entry 'cn=Database %d,%s'\n%s",
177 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val,
183 if ( be->be_flags & SLAP_BFLAG_MONITOR ) {
184 attr_merge( e, slap_schema.si_ad_monitorContext,
185 be->be_suffix, be->be_nsuffix );
186 attr_merge( e_database, slap_schema.si_ad_monitorContext,
187 be->be_suffix, be->be_nsuffix );
189 attr_merge( e, slap_schema.si_ad_namingContexts,
190 be->be_suffix, be->be_nsuffix );
191 attr_merge( e_database, slap_schema.si_ad_namingContexts,
192 be->be_suffix, be->be_nsuffix );
195 for ( j = nBackendInfo; j--; ) {
196 if ( backendInfo[ j ].bi_type == be->bd_info->bi_type ) {
199 snprintf( buf, sizeof( buf ),
201 j, monitor_subsys[SLAPD_MONITOR_BACKEND].mss_dn.bv_val );
203 bv.bv_len = strlen( buf );
204 attr_merge_normalize_one( e, mi->mi_ad_seeAlso,
209 /* we must find it! */
212 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
213 e->e_private = ( void * )mp;
215 mp->mp_children = NULL;
216 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_DATABASE];
217 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_DATABASE].mss_flags
220 if ( monitor_cache_add( mi, e ) ) {
222 LDAP_LOG( OPERATION, CRIT,
223 "monitor_subsys_database_init: "
224 "unable to add entry 'cn=Database %d,%s'\n",
225 i, monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val, 0 );
227 Debug( LDAP_DEBUG_ANY,
228 "monitor_subsys_database_init: "
229 "unable to add entry 'cn=Database %d,%s'\n",
231 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val,
237 #if defined(LDAP_SLAPI)
238 monitor_back_add_plugin( be, e );
239 #endif /* defined(LDAP_SLAPI) */
244 mp = ( struct monitorentrypriv * )e_database->e_private;
245 mp->mp_children = e_tmp;
247 monitor_cache_release( mi, e_database );
252 #if defined(LDAP_SLAPI)
254 monitor_back_add_plugin( Backend *be, Entry *e_database )
256 Slapi_PBlock *pCurrentPB;
257 int i, rc = LDAP_SUCCESS;
258 struct monitorinfo *mi = ( struct monitorinfo * )be->be_private;
260 if ( slapi_x_pblock_get_first( be, &pCurrentPB ) != LDAP_SUCCESS ) {
262 * LDAP_OTHER is returned if no plugins are installed
270 Slapi_PluginDesc *srchdesc;
271 char buf[ BACKMONITOR_BUFSIZE ];
274 rc = slapi_pblock_get( pCurrentPB, SLAPI_PLUGIN_DESCRIPTION,
276 if ( rc != LDAP_SUCCESS ) {
280 snprintf( buf, sizeof(buf),
281 "plugin %d name: %s; "
287 srchdesc->spd_vendor,
288 srchdesc->spd_version,
289 srchdesc->spd_description );
292 bv.bv_len = strlen( buf );
293 attr_merge_normalize_one( e_database,
294 mi->mi_ad_monitoredInfo, &bv, NULL );
298 } while ( ( slapi_x_pblock_get_next( &pCurrentPB ) == LDAP_SUCCESS )
299 && ( pCurrentPB != NULL ) );
304 #endif /* defined(LDAP_SLAPI) */