1 /* database.c - deals with database subsystem */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2003 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
17 * This work was initially developed by Pierangelo Masarati for inclusion
18 * in OpenLDAP Software.
20 /* This is an altered version */
22 * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
24 * This work has beed deveolped for the OpenLDAP Foundation
25 * in the hope that it may be useful to the Open Source community,
26 * but WITHOUT ANY WARRANTY.
28 * Permission is granted to anyone to use this software for any purpose
29 * on any computer system, and to alter it and redistribute it, subject
30 * to the following restrictions:
32 * 1. The author and SysNet s.n.c. are not responsible for the consequences
33 * of use of this software, no matter how awful, even if they arise from
36 * 2. The origin of this software must not be misrepresented, either by
37 * explicit claim or by omission. Since few users ever read sources,
38 * credits should appear in the documentation.
40 * 3. Altered versions must be plainly marked as such, and must not be
41 * misrepresented as being the original software. Since few users
42 * ever read sources, credits should appear in the documentation.
43 * SysNet s.n.c. cannot be responsible for the consequences of the
46 * 4. This notice may not be removed or altered.
52 #include <ac/string.h>
55 #include "back-monitor.h"
57 #if defined(LDAP_SLAPI)
59 static int monitor_back_add_plugin( Backend *be, Entry *e );
60 #endif /* defined(LDAP_SLAPI) */
63 monitor_subsys_database_init(
67 struct monitorinfo *mi;
68 Entry *e, *e_database, *e_tmp;
70 struct monitorentrypriv *mp;
74 mi = ( struct monitorinfo * )be->be_private;
76 if ( monitor_cache_get( mi,
77 &monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn,
80 LDAP_LOG( OPERATION, CRIT,
81 "monitor_subsys_database_init: "
82 "unable to get entry '%s'\n",
83 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val, 0, 0 );
85 Debug( LDAP_DEBUG_ANY,
86 "monitor_subsys_database_init: "
87 "unable to get entry '%s'\n%s%s",
88 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val,
95 for ( i = nBackendDB; i--; ) {
96 char buf[ BACKMONITOR_BUFSIZE ];
101 /* Subordinates are not exposed as their own naming context */
102 if ( SLAP_GLUE_SUBORDINATE( be ) ) {
106 snprintf( buf, sizeof( buf ),
107 "dn: cn=Database %d,%s\n"
109 "structuralObjectClass: %s\n"
111 "description: This object contains the type of the database.\n"
113 "createTimestamp: %s\n"
114 "modifyTimestamp: %s\n",
116 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_dn.bv_val,
117 mi->mi_oc_monitoredObject->soc_cname.bv_val,
118 mi->mi_oc_monitoredObject->soc_cname.bv_val,
120 mi->mi_ad_monitoredInfo->ad_cname.bv_val,
121 be->bd_info->bi_type,
122 mi->mi_startTime.bv_val,
123 mi->mi_startTime.bv_val );
125 e = str2entry( buf );
128 LDAP_LOG( OPERATION, CRIT,
129 "monitor_subsys_database_init: "
130 "unable to create entry 'cn=Database %d,%s'\n",
131 i, monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val, 0 );
133 Debug( LDAP_DEBUG_ANY,
134 "monitor_subsys_database_init: "
135 "unable to create entry 'cn=Database %d,%s'\n%s",
137 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val,
143 if ( be->be_flags & SLAP_BFLAG_MONITOR ) {
144 attr_merge( e, slap_schema.si_ad_monitorContext,
145 be->be_suffix, be->be_nsuffix );
146 attr_merge( e_database, slap_schema.si_ad_monitorContext,
147 be->be_suffix, be->be_nsuffix );
149 attr_merge( e, slap_schema.si_ad_namingContexts,
150 be->be_suffix, be->be_nsuffix );
151 attr_merge( e_database, slap_schema.si_ad_namingContexts,
152 be->be_suffix, be->be_nsuffix );
155 for ( j = nBackendInfo; j--; ) {
156 if ( backendInfo[ j ].bi_type == be->bd_info->bi_type ) {
159 snprintf( buf, sizeof( buf ),
161 j, monitor_subsys[SLAPD_MONITOR_BACKEND].mss_dn.bv_val );
163 bv.bv_len = strlen( buf );
164 attr_merge_normalize_one( e, mi->mi_ad_seeAlso,
169 /* we must find it! */
172 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
173 e->e_private = ( void * )mp;
175 mp->mp_children = NULL;
176 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_DATABASE];
177 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_DATABASE].mss_flags
180 if ( monitor_cache_add( mi, e ) ) {
182 LDAP_LOG( OPERATION, CRIT,
183 "monitor_subsys_database_init: "
184 "unable to add entry 'cn=Database %d,%s'\n",
185 i, monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val, 0 );
187 Debug( LDAP_DEBUG_ANY,
188 "monitor_subsys_database_init: "
189 "unable to add entry 'cn=Database %d,%s'\n",
191 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val,
197 #if defined(LDAP_SLAPI)
198 monitor_back_add_plugin( be, e );
199 #endif /* defined(LDAP_SLAPI) */
204 mp = ( struct monitorentrypriv * )e_database->e_private;
205 mp->mp_children = e_tmp;
207 monitor_cache_release( mi, e_database );
212 #if defined(LDAP_SLAPI)
214 monitor_back_add_plugin( Backend *be, Entry *e_database )
216 Slapi_PBlock *pCurrentPB;
217 int i, rc = LDAP_SUCCESS;
218 struct monitorinfo *mi = ( struct monitorinfo * )be->be_private;
220 if ( slapi_x_pblock_get_first( be, &pCurrentPB ) != LDAP_SUCCESS ) {
222 * LDAP_OTHER is returned if no plugins are installed
230 Slapi_PluginDesc *srchdesc;
231 char buf[ BACKMONITOR_BUFSIZE ];
234 rc = slapi_pblock_get( pCurrentPB, SLAPI_PLUGIN_DESCRIPTION,
236 if ( rc != LDAP_SUCCESS ) {
240 snprintf( buf, sizeof(buf),
241 "plugin %d name: %s; "
247 srchdesc->spd_vendor,
248 srchdesc->spd_version,
249 srchdesc->spd_description );
252 bv.bv_len = strlen( buf );
253 attr_merge_normalize_one( e_database,
254 mi->mi_ad_monitoredInfo, &bv, NULL );
258 } while ( ( slapi_x_pblock_get_next( &pCurrentPB ) == LDAP_SUCCESS )
259 && ( pCurrentPB != NULL ) );
264 #endif /* defined(LDAP_SLAPI) */