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) */
35 #if defined(SLAPD_LDAP)
36 #include "../back-ldap/back-ldap.h"
37 #endif /* defined(SLAPD_LDAP) */
40 monitor_subsys_database_init(
44 struct monitorinfo *mi;
45 Entry *e, *e_database, *e_tmp;
47 struct monitorentrypriv *mp;
51 mi = ( struct monitorinfo * )be->be_private;
53 if ( monitor_cache_get( mi,
54 &monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn,
57 LDAP_LOG( OPERATION, CRIT,
58 "monitor_subsys_database_init: "
59 "unable to get entry '%s'\n",
60 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val, 0, 0 );
62 Debug( LDAP_DEBUG_ANY,
63 "monitor_subsys_database_init: "
64 "unable to get entry '%s'\n%s%s",
65 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val,
72 for ( i = nBackendDB; i--; ) {
73 char buf[ BACKMONITOR_BUFSIZE ];
75 slap_overinfo *oi = NULL;
79 if ( strcmp( be->bd_info->bi_type, "over" ) == 0 ) {
80 oi = (slap_overinfo *)be->bd_info;
85 /* Subordinates are not exposed as their own naming context */
86 if ( SLAP_GLUE_SUBORDINATE( be ) ) {
90 snprintf( buf, sizeof( buf ),
91 "dn: cn=Database %d,%s\n"
93 "structuralObjectClass: %s\n"
95 "description: This object contains the type of the database.\n"
97 "createTimestamp: %s\n"
98 "modifyTimestamp: %s\n",
100 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_dn.bv_val,
101 mi->mi_oc_monitoredObject->soc_cname.bv_val,
102 mi->mi_oc_monitoredObject->soc_cname.bv_val,
104 mi->mi_ad_monitoredInfo->ad_cname.bv_val,
105 be->bd_info->bi_type,
106 mi->mi_startTime.bv_val,
107 mi->mi_startTime.bv_val );
109 e = str2entry( buf );
112 LDAP_LOG( OPERATION, CRIT,
113 "monitor_subsys_database_init: "
114 "unable to create entry 'cn=Database %d,%s'\n",
115 i, monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val, 0 );
117 Debug( LDAP_DEBUG_ANY,
118 "monitor_subsys_database_init: "
119 "unable to create entry 'cn=Database %d,%s'\n%s",
121 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val,
127 if ( be->be_flags & SLAP_BFLAG_MONITOR ) {
128 attr_merge( e, slap_schema.si_ad_monitorContext,
129 be->be_suffix, be->be_nsuffix );
130 attr_merge( e_database, slap_schema.si_ad_monitorContext,
131 be->be_suffix, be->be_nsuffix );
133 attr_merge( e, slap_schema.si_ad_namingContexts,
134 be->be_suffix, be->be_nsuffix );
135 attr_merge( e_database, slap_schema.si_ad_namingContexts,
136 be->be_suffix, be->be_nsuffix );
140 slap_overinst *on = oi->oi_list;
142 for ( ; on; on = on->on_next ) {
146 bv.bv_val = on->on_bi.bi_type;
147 bv.bv_len = strlen( bv.bv_val );
148 attr_merge_normalize_one( e, mi->mi_ad_monitorOverlay,
151 for ( on2 = overlay_next( NULL ), j = 0; on2; on2 = overlay_next( on2 ), j++ ) {
152 if ( on2->on_bi.bi_type == on->on_bi.bi_type ) {
158 snprintf( buf, sizeof( buf ),
160 j, monitor_subsys[SLAPD_MONITOR_OVERLAY].mss_dn.bv_val );
162 bv.bv_len = strlen( buf );
163 attr_merge_normalize_one( e, mi->mi_ad_seeAlso,
168 #if defined(SLAPD_LDAP)
169 if ( strcmp( be->bd_info->bi_type, "ldap" ) == 0 ) {
170 struct ldapinfo *li = (struct ldapinfo *)be->be_private;
174 bv.bv_len = strlen( bv.bv_val );
175 attr_merge_normalize_one( e, mi->mi_ad_labeledURI,
178 #endif /* defined(SLAPD_LDAP) */
180 for ( j = nBackendInfo; j--; ) {
181 if ( backendInfo[ j ].bi_type == be->bd_info->bi_type ) {
184 snprintf( buf, sizeof( buf ),
186 j, monitor_subsys[SLAPD_MONITOR_BACKEND].mss_dn.bv_val );
188 bv.bv_len = strlen( buf );
189 attr_merge_normalize_one( e, mi->mi_ad_seeAlso,
194 /* we must find it! */
197 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
198 e->e_private = ( void * )mp;
200 mp->mp_children = NULL;
201 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_DATABASE];
202 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_DATABASE].mss_flags
205 if ( monitor_cache_add( mi, e ) ) {
207 LDAP_LOG( OPERATION, CRIT,
208 "monitor_subsys_database_init: "
209 "unable to add entry 'cn=Database %d,%s'\n",
210 i, monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val, 0 );
212 Debug( LDAP_DEBUG_ANY,
213 "monitor_subsys_database_init: "
214 "unable to add entry 'cn=Database %d,%s'\n",
216 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val,
222 #if defined(LDAP_SLAPI)
223 monitor_back_add_plugin( be, e );
224 #endif /* defined(LDAP_SLAPI) */
229 mp = ( struct monitorentrypriv * )e_database->e_private;
230 mp->mp_children = e_tmp;
232 monitor_cache_release( mi, e_database );
237 #if defined(LDAP_SLAPI)
239 monitor_back_add_plugin( Backend *be, Entry *e_database )
241 Slapi_PBlock *pCurrentPB;
242 int i, rc = LDAP_SUCCESS;
243 struct monitorinfo *mi = ( struct monitorinfo * )be->be_private;
245 if ( slapi_int_pblock_get_first( be, &pCurrentPB ) != LDAP_SUCCESS ) {
247 * LDAP_OTHER is returned if no plugins are installed
255 Slapi_PluginDesc *srchdesc;
256 char buf[ BACKMONITOR_BUFSIZE ];
259 rc = slapi_pblock_get( pCurrentPB, SLAPI_PLUGIN_DESCRIPTION,
261 if ( rc != LDAP_SUCCESS ) {
265 snprintf( buf, sizeof(buf),
266 "plugin %d name: %s; "
272 srchdesc->spd_vendor,
273 srchdesc->spd_version,
274 srchdesc->spd_description );
277 bv.bv_len = strlen( buf );
278 attr_merge_normalize_one( e_database,
279 mi->mi_ad_monitoredInfo, &bv, NULL );
283 } while ( ( slapi_int_pblock_get_next( &pCurrentPB ) == LDAP_SUCCESS )
284 && ( pCurrentPB != NULL ) );
289 #endif /* defined(LDAP_SLAPI) */