1 /* backend.c - deals with backend 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.
53 #include <ac/string.h>
56 #include "back-monitor.h"
59 * initializes backend subentries
62 monitor_subsys_backend_init(
66 struct monitorinfo *mi;
67 Entry *e, *e_backend, *e_tmp;
69 struct monitorentrypriv *mp;
71 mi = ( struct monitorinfo * )be->be_private;
73 if ( monitor_cache_get( mi,
74 &monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn,
77 LDAP_LOG( OPERATION, CRIT,
78 "monitor_subsys_backend_init: "
79 "unable to get entry '%s'\n",
80 monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val, 0, 0 );
82 Debug( LDAP_DEBUG_ANY,
83 "monitor_subsys_backend_init: "
84 "unable to get entry '%s'\n%s%s",
85 monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val,
92 for ( i = nBackendInfo; i--; ) {
93 char buf[ BACKMONITOR_BUFSIZE ];
100 snprintf( buf, sizeof( buf ),
101 "dn: cn=Backend %d,%s\n"
103 "structuralObjectClass: %s\n"
105 "createTimestamp: %s\n"
106 "modifyTimestamp: %s\n",
108 monitor_subsys[SLAPD_MONITOR_BACKEND].mss_dn.bv_val,
109 mi->mi_oc_monitoredObject->soc_cname.bv_val,
110 mi->mi_oc_monitoredObject->soc_cname.bv_val,
112 mi->mi_startTime.bv_val,
113 mi->mi_startTime.bv_val );
115 e = str2entry( buf );
118 LDAP_LOG( OPERATION, CRIT,
119 "monitor_subsys_backend_init: "
120 "unable to create entry 'cn=Backend %d,%s'\n",
121 i, monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val, 0 );
123 Debug( LDAP_DEBUG_ANY,
124 "monitor_subsys_backend_init: "
125 "unable to create entry 'cn=Backend %d,%s'\n%s",
127 monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val,
133 bv.bv_val = bi->bi_type;
134 bv.bv_len = strlen( bv.bv_val );
136 attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo,
138 attr_merge_normalize_one( e_backend, mi->mi_ad_monitoredInfo,
141 if ( bi->bi_controls ) {
144 for ( j = 0; bi->bi_controls[ j ]; j++ ) {
145 bv.bv_val = bi->bi_controls[ j ];
146 bv.bv_len = strlen( bv.bv_val );
147 attr_merge_one( e, slap_schema.si_ad_supportedControl, &bv, NULL );
151 for ( j = 0; j < nBackendDB; j++ ) {
152 BackendDB *be = &backendDB[j];
153 char buf[ SLAP_LDAPDN_MAXLEN ];
156 if ( be->bd_info != bi ) {
160 snprintf( buf, sizeof( buf ), "cn=Database %d,%s",
161 j, monitor_subsys[SLAPD_MONITOR_DATABASE].mss_dn.bv_val );
163 dn.bv_len = strlen( buf );
165 attr_merge_normalize_one( e, mi->mi_ad_seeAlso,
169 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
170 e->e_private = ( void * )mp;
172 mp->mp_children = NULL;
173 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_BACKEND];
174 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_BACKEND].mss_flags
177 if ( monitor_cache_add( mi, e ) ) {
179 LDAP_LOG( OPERATION, CRIT,
180 "monitor_subsys_backend_init: "
181 "unable to add entry 'cn=Backend %d,%s'\n",
182 i, monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val, 0 );
184 Debug( LDAP_DEBUG_ANY,
185 "monitor_subsys_backend_init: "
186 "unable to add entry 'cn=Backend %d,%s'\n%s",
188 monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val,
197 mp = ( struct monitorentrypriv * )e_backend->e_private;
198 mp->mp_children = e_tmp;
200 monitor_cache_release( mi, e_backend );