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 ];
74 /* Subordinates are not exposed as their own naming context */
75 if ( SLAP_GLUE_SUBORDINATE( be ) ) {
79 snprintf( buf, sizeof( buf ),
80 "dn: cn=Database %d,%s\n"
82 "structuralObjectClass: %s\n"
84 "description: This object contains the type of the database.\n"
86 "createTimestamp: %s\n"
87 "modifyTimestamp: %s\n",
89 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_dn.bv_val,
90 mi->mi_oc_monitoredObject->soc_cname.bv_val,
91 mi->mi_oc_monitoredObject->soc_cname.bv_val,
93 mi->mi_ad_monitoredInfo->ad_cname.bv_val,
95 mi->mi_startTime.bv_val,
96 mi->mi_startTime.bv_val );
101 LDAP_LOG( OPERATION, CRIT,
102 "monitor_subsys_database_init: "
103 "unable to create entry 'cn=Database %d,%s'\n",
104 i, monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val, 0 );
106 Debug( LDAP_DEBUG_ANY,
107 "monitor_subsys_database_init: "
108 "unable to create entry 'cn=Database %d,%s'\n%s",
110 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val,
116 if ( be->be_flags & SLAP_BFLAG_MONITOR ) {
117 attr_merge( e, slap_schema.si_ad_monitorContext,
118 be->be_suffix, be->be_nsuffix );
119 attr_merge( e_database, slap_schema.si_ad_monitorContext,
120 be->be_suffix, be->be_nsuffix );
122 attr_merge( e, slap_schema.si_ad_namingContexts,
123 be->be_suffix, be->be_nsuffix );
124 attr_merge( e_database, slap_schema.si_ad_namingContexts,
125 be->be_suffix, be->be_nsuffix );
128 for ( j = nBackendInfo; j--; ) {
129 if ( backendInfo[ j ].bi_type == be->bd_info->bi_type ) {
132 snprintf( buf, sizeof( buf ),
134 j, monitor_subsys[SLAPD_MONITOR_BACKEND].mss_dn.bv_val );
136 bv.bv_len = strlen( buf );
137 attr_merge_normalize_one( e, mi->mi_ad_seeAlso,
142 /* we must find it! */
145 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
146 e->e_private = ( void * )mp;
148 mp->mp_children = NULL;
149 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_DATABASE];
150 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_DATABASE].mss_flags
153 if ( monitor_cache_add( mi, e ) ) {
155 LDAP_LOG( OPERATION, CRIT,
156 "monitor_subsys_database_init: "
157 "unable to add entry 'cn=Database %d,%s'\n",
158 i, monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val, 0 );
160 Debug( LDAP_DEBUG_ANY,
161 "monitor_subsys_database_init: "
162 "unable to add entry 'cn=Database %d,%s'\n",
164 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val,
170 #if defined(LDAP_SLAPI)
171 monitor_back_add_plugin( be, e );
172 #endif /* defined(LDAP_SLAPI) */
177 mp = ( struct monitorentrypriv * )e_database->e_private;
178 mp->mp_children = e_tmp;
180 monitor_cache_release( mi, e_database );
185 #if defined(LDAP_SLAPI)
187 monitor_back_add_plugin( Backend *be, Entry *e_database )
189 Slapi_PBlock *pCurrentPB;
190 int i, rc = LDAP_SUCCESS;
191 struct monitorinfo *mi = ( struct monitorinfo * )be->be_private;
193 if ( slapi_int_pblock_get_first( be, &pCurrentPB ) != LDAP_SUCCESS ) {
195 * LDAP_OTHER is returned if no plugins are installed
203 Slapi_PluginDesc *srchdesc;
204 char buf[ BACKMONITOR_BUFSIZE ];
207 rc = slapi_pblock_get( pCurrentPB, SLAPI_PLUGIN_DESCRIPTION,
209 if ( rc != LDAP_SUCCESS ) {
213 snprintf( buf, sizeof(buf),
214 "plugin %d name: %s; "
220 srchdesc->spd_vendor,
221 srchdesc->spd_version,
222 srchdesc->spd_description );
225 bv.bv_len = strlen( buf );
226 attr_merge_normalize_one( e_database,
227 mi->mi_ad_monitoredInfo, &bv, NULL );
231 } while ( ( slapi_int_pblock_get_next( &pCurrentPB ) == LDAP_SUCCESS )
232 && ( pCurrentPB != NULL ) );
237 #endif /* defined(LDAP_SLAPI) */