1 /* database.c - deals with database subsystem */
3 * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
7 * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
9 * This work has beed deveolped for the OpenLDAP Foundation
10 * in the hope that it may be useful to the Open Source community,
11 * but WITHOUT ANY WARRANTY.
13 * Permission is granted to anyone to use this software for any purpose
14 * on any computer system, and to alter it and redistribute it, subject
15 * to the following restrictions:
17 * 1. The author and SysNet s.n.c. are not responsible for the consequences
18 * of use of this software, no matter how awful, even if they arise from
21 * 2. The origin of this software must not be misrepresented, either by
22 * explicit claim or by omission. Since few users ever read sources,
23 * credits should appear in the documentation.
25 * 3. Altered versions must be plainly marked as such, and must not be
26 * misrepresented as being the original software. Since few users
27 * ever read sources, credits should appear in the documentation.
28 * SysNet s.n.c. cannot be responsible for the consequences of the
31 * 4. This notice may not be removed or altered.
39 #include "back-monitor.h"
42 monitor_subsys_database_init(
46 struct monitorinfo *mi;
47 Entry *e, *e_database, *e_tmp;
49 struct monitorentrypriv *mp;
50 AttributeDescription *ad_nc = slap_schema.si_ad_namingContexts;
51 AttributeDescription *ad_mc = slap_schema.si_ad_monitorContext;
52 AttributeDescription *ad_seeAlso = NULL;
53 const char *text = NULL;
56 assert( monitor_ad_desc != NULL );
58 mi = ( struct monitorinfo * )be->be_private;
60 if ( monitor_cache_get( mi,
61 &monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn,
64 LDAP_LOG( OPERATION, CRIT,
65 "monitor_subsys_database_init: "
66 "unable to get entry '%s'\n",
67 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val, 0, 0 );
69 Debug( LDAP_DEBUG_ANY,
70 "monitor_subsys_database_init: "
71 "unable to get entry '%s'\n%s%s",
72 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val,
78 if ( slap_str2ad( "seeAlso", &ad_seeAlso, &text ) != LDAP_SUCCESS ) {
83 for ( i = nBackendDB; i--; ) {
89 snprintf( buf, sizeof( buf ),
90 "dn: cn=Database %d,%s\n"
91 SLAPD_MONITOR_OBJECTCLASSES
95 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_dn.bv_val,
97 be->bd_info->bi_type );
102 LDAP_LOG( OPERATION, CRIT,
103 "monitor_subsys_database_init: "
104 "unable to create entry 'cn=Database %d,%s'\n",
105 i, monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val, 0 );
107 Debug( LDAP_DEBUG_ANY,
108 "monitor_subsys_database_init: "
109 "unable to create entry 'cn=Database %d,%s'\n%s",
111 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val,
117 if ( be->be_flags & SLAP_BFLAG_MONITOR ) {
118 attr_merge( e, ad_mc, be->be_suffix );
119 attr_merge( e_database, ad_mc, be->be_suffix );
121 attr_merge( e, ad_nc, be->be_suffix );
122 attr_merge( e_database, ad_nc, be->be_suffix );
125 for ( j = nBackendInfo; j--; ) {
126 if ( &backendInfo[ j ] == be->bd_info ) {
127 struct berval bv[ 2 ];
129 /* we check the pointer; the test on the
130 * string should be more reliable */
131 assert( strcasecmp( backendInfo[ j ].bi_type,
132 be->bd_info->bi_type ) == 0 );
134 snprintf( buf, sizeof( buf ),
136 j, monitor_subsys[SLAPD_MONITOR_BACKEND].mss_dn.bv_val );
137 bv[ 0 ].bv_val = buf;
138 bv[ 0 ].bv_len = strlen( buf );
139 bv[ 1 ].bv_val = NULL;
140 attr_merge( e, ad_seeAlso, bv );
144 /* we must find it! */
147 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
148 e->e_private = ( void * )mp;
150 mp->mp_children = NULL;
151 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_DATABASE];
152 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_DATABASE].mss_flags
155 if ( monitor_cache_add( mi, e ) ) {
157 LDAP_LOG( OPERATION, CRIT,
158 "monitor_subsys_database_init: "
159 "unable to add entry 'cn=Database %d,%s'\n",
160 i, monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val, 0 );
162 Debug( LDAP_DEBUG_ANY,
163 "monitor_subsys_database_init: "
164 "unable to add entry 'cn=Database %d,%s'\n",
166 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val,
175 mp = ( struct monitorentrypriv * )e_database->e_private;
176 mp->mp_children = e_tmp;
178 monitor_cache_release( mi, e_database );