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;
82 if ( strcmp( be->bd_info->bi_type, "over" ) == 0 ) {
83 oi = (slap_overinfo *)be->bd_info;
87 /* Subordinates are not exposed as their own naming context */
88 if ( SLAP_GLUE_SUBORDINATE( be ) ) {
92 snprintf( buf, sizeof( buf ),
93 "dn: cn=Database %d,%s\n"
95 "structuralObjectClass: %s\n"
97 "description: This object contains the type of the database.\n"
99 "createTimestamp: %s\n"
100 "modifyTimestamp: %s\n",
102 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_dn.bv_val,
103 mi->mi_oc_monitoredObject->soc_cname.bv_val,
104 mi->mi_oc_monitoredObject->soc_cname.bv_val,
106 mi->mi_ad_monitoredInfo->ad_cname.bv_val,
108 mi->mi_startTime.bv_val,
109 mi->mi_startTime.bv_val );
111 e = str2entry( buf );
114 LDAP_LOG( OPERATION, CRIT,
115 "monitor_subsys_database_init: "
116 "unable to create entry 'cn=Database %d,%s'\n",
117 i, monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val, 0 );
119 Debug( LDAP_DEBUG_ANY,
120 "monitor_subsys_database_init: "
121 "unable to create entry 'cn=Database %d,%s'\n%s",
123 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val,
129 if ( SLAP_MONITOR(be) ) {
130 attr_merge( e, slap_schema.si_ad_monitorContext,
131 be->be_suffix, be->be_nsuffix );
132 attr_merge( e_database, slap_schema.si_ad_monitorContext,
133 be->be_suffix, be->be_nsuffix );
135 attr_merge( e, slap_schema.si_ad_namingContexts,
136 be->be_suffix, be->be_nsuffix );
137 attr_merge( e_database, slap_schema.si_ad_namingContexts,
138 be->be_suffix, be->be_nsuffix );
142 slap_overinst *on = oi->oi_list;
144 for ( ; on; on = on->on_next ) {
148 bv.bv_val = on->on_bi.bi_type;
149 bv.bv_len = strlen( bv.bv_val );
150 attr_merge_normalize_one( e, mi->mi_ad_monitorOverlay,
153 for ( on2 = overlay_next( NULL ), j = 0; on2; on2 = overlay_next( on2 ), j++ ) {
154 if ( on2->on_bi.bi_type == on->on_bi.bi_type ) {
160 snprintf( buf, sizeof( buf ),
162 j, monitor_subsys[SLAPD_MONITOR_OVERLAY].mss_dn.bv_val );
164 bv.bv_len = strlen( buf );
165 attr_merge_normalize_one( e, mi->mi_ad_seeAlso,
170 #if defined(SLAPD_LDAP)
171 if ( strcmp( bi->bi_type, "ldap" ) == 0 ) {
172 struct ldapinfo *li = (struct ldapinfo *)be->be_private;
176 bv.bv_len = strlen( bv.bv_val );
177 attr_merge_normalize_one( e, mi->mi_ad_labeledURI,
180 #endif /* defined(SLAPD_LDAP) */
182 for ( j = nBackendInfo; j--; ) {
183 if ( backendInfo[ j ].bi_type == bi->bi_type ) {
186 snprintf( buf, sizeof( buf ),
188 j, monitor_subsys[SLAPD_MONITOR_BACKEND].mss_dn.bv_val );
190 bv.bv_len = strlen( buf );
191 attr_merge_normalize_one( e, mi->mi_ad_seeAlso,
196 /* we must find it! */
199 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
200 e->e_private = ( void * )mp;
202 mp->mp_children = NULL;
203 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_DATABASE];
204 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_DATABASE].mss_flags
207 if ( monitor_cache_add( mi, e ) ) {
209 LDAP_LOG( OPERATION, CRIT,
210 "monitor_subsys_database_init: "
211 "unable to add entry 'cn=Database %d,%s'\n",
212 i, monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val, 0 );
214 Debug( LDAP_DEBUG_ANY,
215 "monitor_subsys_database_init: "
216 "unable to add entry 'cn=Database %d,%s'\n",
218 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val,
224 #if defined(LDAP_SLAPI)
225 monitor_back_add_plugin( be, e );
226 #endif /* defined(LDAP_SLAPI) */
231 mp = ( struct monitorentrypriv * )e_database->e_private;
232 mp->mp_children = e_tmp;
234 monitor_cache_release( mi, e_database );
239 #if defined(LDAP_SLAPI)
241 monitor_back_add_plugin( Backend *be, Entry *e_database )
243 Slapi_PBlock *pCurrentPB;
244 int i, rc = LDAP_SUCCESS;
245 struct monitorinfo *mi = ( struct monitorinfo * )be->be_private;
247 if ( slapi_int_pblock_get_first( be, &pCurrentPB ) != LDAP_SUCCESS ) {
249 * LDAP_OTHER is returned if no plugins are installed
257 Slapi_PluginDesc *srchdesc;
258 char buf[ BACKMONITOR_BUFSIZE ];
261 rc = slapi_pblock_get( pCurrentPB, SLAPI_PLUGIN_DESCRIPTION,
263 if ( rc != LDAP_SUCCESS ) {
267 snprintf( buf, sizeof(buf),
268 "plugin %d name: %s; "
274 srchdesc->spd_vendor,
275 srchdesc->spd_version,
276 srchdesc->spd_description );
279 bv.bv_len = strlen( buf );
280 attr_merge_normalize_one( e_database,
281 mi->mi_ad_monitoredInfo, &bv, NULL );
285 } while ( ( slapi_int_pblock_get_next( &pCurrentPB ) == LDAP_SUCCESS )
286 && ( pCurrentPB != NULL ) );
291 #endif /* defined(LDAP_SLAPI) */