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 ) {
141 bv.bv_val = on->on_bi.bi_type;
142 bv.bv_len = strlen( bv.bv_val );
143 attr_merge_normalize_one( e, mi->mi_ad_monitorOverlay,
148 for ( j = nBackendInfo; j--; ) {
149 if ( backendInfo[ j ].bi_type == be->bd_info->bi_type ) {
152 snprintf( buf, sizeof( buf ),
154 j, monitor_subsys[SLAPD_MONITOR_BACKEND].mss_dn.bv_val );
156 bv.bv_len = strlen( buf );
157 attr_merge_normalize_one( e, mi->mi_ad_seeAlso,
162 /* we must find it! */
165 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
166 e->e_private = ( void * )mp;
168 mp->mp_children = NULL;
169 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_DATABASE];
170 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_DATABASE].mss_flags
173 if ( monitor_cache_add( mi, e ) ) {
175 LDAP_LOG( OPERATION, CRIT,
176 "monitor_subsys_database_init: "
177 "unable to add entry 'cn=Database %d,%s'\n",
178 i, monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val, 0 );
180 Debug( LDAP_DEBUG_ANY,
181 "monitor_subsys_database_init: "
182 "unable to add entry 'cn=Database %d,%s'\n",
184 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val,
190 #if defined(LDAP_SLAPI)
191 monitor_back_add_plugin( be, e );
192 #endif /* defined(LDAP_SLAPI) */
197 mp = ( struct monitorentrypriv * )e_database->e_private;
198 mp->mp_children = e_tmp;
200 monitor_cache_release( mi, e_database );
205 #if defined(LDAP_SLAPI)
207 monitor_back_add_plugin( Backend *be, Entry *e_database )
209 Slapi_PBlock *pCurrentPB;
210 int i, rc = LDAP_SUCCESS;
211 struct monitorinfo *mi = ( struct monitorinfo * )be->be_private;
213 if ( slapi_int_pblock_get_first( be, &pCurrentPB ) != LDAP_SUCCESS ) {
215 * LDAP_OTHER is returned if no plugins are installed
223 Slapi_PluginDesc *srchdesc;
224 char buf[ BACKMONITOR_BUFSIZE ];
227 rc = slapi_pblock_get( pCurrentPB, SLAPI_PLUGIN_DESCRIPTION,
229 if ( rc != LDAP_SUCCESS ) {
233 snprintf( buf, sizeof(buf),
234 "plugin %d name: %s; "
240 srchdesc->spd_vendor,
241 srchdesc->spd_version,
242 srchdesc->spd_description );
245 bv.bv_len = strlen( buf );
246 attr_merge_normalize_one( e_database,
247 mi->mi_ad_monitoredInfo, &bv, NULL );
251 } while ( ( slapi_int_pblock_get_next( &pCurrentPB ) == LDAP_SUCCESS )
252 && ( pCurrentPB != NULL ) );
257 #endif /* defined(LDAP_SLAPI) */