1 /* database.c - deals with database subsystem */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2001-2004 The OpenLDAP Foundation.
6 * Portions Copyright 2001-2003 Pierangelo Masarati.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
13 * A copy of this license is available in file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
18 * This work was initially developed by Pierangelo Masarati for inclusion
19 * in OpenLDAP Software.
25 #include <ac/string.h>
28 #include "back-monitor.h"
30 #if defined(LDAP_SLAPI)
32 static int monitor_back_add_plugin( Backend *be, Entry *e );
33 #endif /* defined(LDAP_SLAPI) */
36 monitor_subsys_database_init(
40 struct monitorinfo *mi;
41 Entry *e, *e_database, *e_tmp;
43 struct monitorentrypriv *mp;
47 mi = ( struct monitorinfo * )be->be_private;
49 if ( monitor_cache_get( mi,
50 &monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn,
53 LDAP_LOG( OPERATION, CRIT,
54 "monitor_subsys_database_init: "
55 "unable to get entry '%s'\n",
56 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val, 0, 0 );
58 Debug( LDAP_DEBUG_ANY,
59 "monitor_subsys_database_init: "
60 "unable to get entry '%s'\n%s%s",
61 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val,
68 for ( i = nBackendDB; i--; ) {
69 char buf[ BACKMONITOR_BUFSIZE ];
71 slap_overinfo *oi = NULL;
75 if ( strcmp( be->bd_info->bi_type, "over" ) == 0 ) {
76 oi = (slap_overinfo *)be->bd_info;
81 /* Subordinates are not exposed as their own naming context */
82 if ( SLAP_GLUE_SUBORDINATE( be ) ) {
86 snprintf( buf, sizeof( buf ),
87 "dn: cn=Database %d,%s\n"
89 "structuralObjectClass: %s\n"
91 "description: This object contains the type of the database.\n"
93 "createTimestamp: %s\n"
94 "modifyTimestamp: %s\n",
96 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_dn.bv_val,
97 mi->mi_oc_monitoredObject->soc_cname.bv_val,
98 mi->mi_oc_monitoredObject->soc_cname.bv_val,
100 mi->mi_ad_monitoredInfo->ad_cname.bv_val,
101 be->bd_info->bi_type,
102 mi->mi_startTime.bv_val,
103 mi->mi_startTime.bv_val );
105 e = str2entry( buf );
108 LDAP_LOG( OPERATION, CRIT,
109 "monitor_subsys_database_init: "
110 "unable to create entry 'cn=Database %d,%s'\n",
111 i, monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val, 0 );
113 Debug( LDAP_DEBUG_ANY,
114 "monitor_subsys_database_init: "
115 "unable to create entry 'cn=Database %d,%s'\n%s",
117 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val,
123 if ( be->be_flags & SLAP_BFLAG_MONITOR ) {
124 attr_merge( e, slap_schema.si_ad_monitorContext,
125 be->be_suffix, be->be_nsuffix );
126 attr_merge( e_database, slap_schema.si_ad_monitorContext,
127 be->be_suffix, be->be_nsuffix );
129 attr_merge( e, slap_schema.si_ad_namingContexts,
130 be->be_suffix, be->be_nsuffix );
131 attr_merge( e_database, slap_schema.si_ad_namingContexts,
132 be->be_suffix, be->be_nsuffix );
136 slap_overinst *on = oi->oi_list;
138 for ( ; on; on = on->on_next ) {
142 bv.bv_val = on->on_bi.bi_type;
143 bv.bv_len = strlen( bv.bv_val );
144 attr_merge_normalize_one( e, mi->mi_ad_monitorOverlay,
147 for ( on2 = overlay_next( NULL ), j = 0; on2; on2 = overlay_next( on2 ), j++ ) {
148 if ( on2->on_bi.bi_type == on->on_bi.bi_type ) {
154 snprintf( buf, sizeof( buf ),
156 j, monitor_subsys[SLAPD_MONITOR_OVERLAY].mss_dn.bv_val );
158 bv.bv_len = strlen( buf );
159 attr_merge_normalize_one( e, mi->mi_ad_seeAlso,
164 for ( j = nBackendInfo; j--; ) {
165 if ( backendInfo[ j ].bi_type == be->bd_info->bi_type ) {
168 snprintf( buf, sizeof( buf ),
170 j, monitor_subsys[SLAPD_MONITOR_BACKEND].mss_dn.bv_val );
172 bv.bv_len = strlen( buf );
173 attr_merge_normalize_one( e, mi->mi_ad_seeAlso,
178 /* we must find it! */
181 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
182 e->e_private = ( void * )mp;
184 mp->mp_children = NULL;
185 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_DATABASE];
186 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_DATABASE].mss_flags
189 if ( monitor_cache_add( mi, e ) ) {
191 LDAP_LOG( OPERATION, CRIT,
192 "monitor_subsys_database_init: "
193 "unable to add entry 'cn=Database %d,%s'\n",
194 i, monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val, 0 );
196 Debug( LDAP_DEBUG_ANY,
197 "monitor_subsys_database_init: "
198 "unable to add entry 'cn=Database %d,%s'\n",
200 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val,
206 #if defined(LDAP_SLAPI)
207 monitor_back_add_plugin( be, e );
208 #endif /* defined(LDAP_SLAPI) */
213 mp = ( struct monitorentrypriv * )e_database->e_private;
214 mp->mp_children = e_tmp;
216 monitor_cache_release( mi, e_database );
221 #if defined(LDAP_SLAPI)
223 monitor_back_add_plugin( Backend *be, Entry *e_database )
225 Slapi_PBlock *pCurrentPB;
226 int i, rc = LDAP_SUCCESS;
227 struct monitorinfo *mi = ( struct monitorinfo * )be->be_private;
229 if ( slapi_int_pblock_get_first( be, &pCurrentPB ) != LDAP_SUCCESS ) {
231 * LDAP_OTHER is returned if no plugins are installed
239 Slapi_PluginDesc *srchdesc;
240 char buf[ BACKMONITOR_BUFSIZE ];
243 rc = slapi_pblock_get( pCurrentPB, SLAPI_PLUGIN_DESCRIPTION,
245 if ( rc != LDAP_SUCCESS ) {
249 snprintf( buf, sizeof(buf),
250 "plugin %d name: %s; "
256 srchdesc->spd_vendor,
257 srchdesc->spd_version,
258 srchdesc->spd_description );
261 bv.bv_len = strlen( buf );
262 attr_merge_normalize_one( e_database,
263 mi->mi_ad_monitoredInfo, &bv, NULL );
267 } while ( ( slapi_int_pblock_get_next( &pCurrentPB ) == LDAP_SUCCESS )
268 && ( pCurrentPB != NULL ) );
273 #endif /* defined(LDAP_SLAPI) */