1 /* database.c - deals with database subsystem */
3 * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
7 * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
9 * This work has beed deveolped for the OpenLDAP Foundation
10 * in the hope that it may be useful to the Open Source community,
11 * but WITHOUT ANY WARRANTY.
13 * Permission is granted to anyone to use this software for any purpose
14 * on any computer system, and to alter it and redistribute it, subject
15 * to the following restrictions:
17 * 1. The author and SysNet s.n.c. are not responsible for the consequences
18 * of use of this software, no matter how awful, even if they arise from
21 * 2. The origin of this software must not be misrepresented, either by
22 * explicit claim or by omission. Since few users ever read sources,
23 * credits should appear in the documentation.
25 * 3. Altered versions must be plainly marked as such, and must not be
26 * misrepresented as being the original software. Since few users
27 * ever read sources, credits should appear in the documentation.
28 * SysNet s.n.c. cannot be responsible for the consequences of the
31 * 4. This notice may not be removed or altered.
39 #include "back-monitor.h"
41 #if defined(LDAP_SLAPI)
43 static int monitor_back_add_plugin( Backend *be, Entry *e );
44 #endif /* defined(LDAP_SLAPI) */
47 monitor_subsys_database_init(
51 struct monitorinfo *mi;
52 Entry *e, *e_database, *e_tmp;
54 struct monitorentrypriv *mp;
55 const char *text = NULL;
59 mi = ( struct monitorinfo * )be->be_private;
61 if ( monitor_cache_get( mi,
62 &monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn,
65 LDAP_LOG( OPERATION, CRIT,
66 "monitor_subsys_database_init: "
67 "unable to get entry '%s'\n",
68 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val, 0, 0 );
70 Debug( LDAP_DEBUG_ANY,
71 "monitor_subsys_database_init: "
72 "unable to get entry '%s'\n%s%s",
73 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val,
80 for ( i = nBackendDB; i--; ) {
81 char buf[ BACKMONITOR_BUFSIZE ];
86 /* Subordinates are not exposed as their own naming context */
87 if ( SLAP_GLUE_SUBORDINATE( be ) ) {
91 snprintf( buf, sizeof( buf ),
92 "dn: cn=Database %d,%s\n"
94 "structuralObjectClass: %s\n"
96 "description: This object contains the type of the database.\n"
99 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_dn.bv_val,
100 mi->oc_monitoredObject->soc_cname.bv_val,
101 mi->oc_monitoredObject->soc_cname.bv_val,
103 mi->ad_monitoredInfo->ad_cname.bv_val,
104 be->bd_info->bi_type );
106 e = str2entry( buf );
109 LDAP_LOG( OPERATION, CRIT,
110 "monitor_subsys_database_init: "
111 "unable to create entry 'cn=Database %d,%s'\n",
112 i, monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val, 0 );
114 Debug( LDAP_DEBUG_ANY,
115 "monitor_subsys_database_init: "
116 "unable to create entry 'cn=Database %d,%s'\n%s",
118 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val,
124 if ( be->be_flags & SLAP_BFLAG_MONITOR ) {
125 attr_merge( e, slap_schema.si_ad_monitorContext,
126 be->be_suffix, be->be_nsuffix );
127 attr_merge( e_database, slap_schema.si_ad_monitorContext,
128 be->be_suffix, be->be_nsuffix );
130 attr_merge( e, slap_schema.si_ad_namingContexts,
131 be->be_suffix, be->be_nsuffix );
132 attr_merge( e_database, slap_schema.si_ad_namingContexts,
133 be->be_suffix, be->be_nsuffix );
136 for ( j = nBackendInfo; j--; ) {
137 if ( backendInfo[ j ].bi_type == be->bd_info->bi_type ) {
140 snprintf( buf, sizeof( buf ),
142 j, monitor_subsys[SLAPD_MONITOR_BACKEND].mss_dn.bv_val );
144 bv.bv_len = strlen( buf );
145 attr_merge_normalize_one( e, mi->ad_seeAlso,
150 /* we must find it! */
153 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
154 e->e_private = ( void * )mp;
156 mp->mp_children = NULL;
157 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_DATABASE];
158 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_DATABASE].mss_flags
161 if ( monitor_cache_add( mi, e ) ) {
163 LDAP_LOG( OPERATION, CRIT,
164 "monitor_subsys_database_init: "
165 "unable to add entry 'cn=Database %d,%s'\n",
166 i, monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val, 0 );
168 Debug( LDAP_DEBUG_ANY,
169 "monitor_subsys_database_init: "
170 "unable to add entry 'cn=Database %d,%s'\n",
172 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val,
178 #if defined(LDAP_SLAPI)
179 monitor_back_add_plugin( be, e );
180 #endif /* defined(LDAP_SLAPI) */
185 mp = ( struct monitorentrypriv * )e_database->e_private;
186 mp->mp_children = e_tmp;
188 monitor_cache_release( mi, e_database );
193 #if defined(LDAP_SLAPI)
195 monitor_back_add_plugin( Backend *be, Entry *e_database )
197 Slapi_PBlock *pCurrentPB;
198 int i, rc = LDAP_SUCCESS;
199 struct monitorinfo *mi = ( struct monitorinfo * )be->be_private;
201 if ( slapi_x_pblock_get_first( be, &pCurrentPB ) != LDAP_SUCCESS ) {
203 * LDAP_OTHER is returned if no plugins are installed
211 Slapi_PluginDesc *srchdesc;
212 char buf[ BACKMONITOR_BUFSIZE ];
215 rc = slapi_pblock_get( pCurrentPB, SLAPI_PLUGIN_DESCRIPTION,
217 if ( rc != LDAP_SUCCESS ) {
221 snprintf( buf, sizeof(buf),
222 "plugin %d name: %s; "
228 srchdesc->spd_vendor,
229 srchdesc->spd_version,
230 srchdesc->spd_description );
233 bv.bv_len = strlen( buf );
234 attr_merge_normalize_one( e_database,
235 mi->ad_monitoredInfo, &bv, NULL );
239 } while ( ( slapi_x_pblock_get_next( &pCurrentPB ) == LDAP_SUCCESS )
240 && ( pCurrentPB != NULL ) );
245 #endif /* defined(LDAP_SLAPI) */