]> git.sur5r.net Git - openldap/blob - servers/slapd/back-monitor/backend.c
015992593fdde2c52543d8b106056d99f038a767
[openldap] / servers / slapd / back-monitor / backend.c
1 /* backend.c - deals with backend subsystem */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 1998-2003 The OpenLDAP Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
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>.
15  */
16 /* ACKNOWLEDGEMENTS:
17  * This work was initially developed by Pierangelo Masarati for inclusion
18  * in OpenLDAP Software.
19  */
20 /* This is an altered version */
21 /*
22  * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
23  * 
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.
27  * 
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:
31  * 
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
34  *    flaws in it.
35  * 
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.
39  * 
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
44  *    alterations.
45  * 
46  * 4. This notice may not be removed or altered.
47  */
48
49 #ifndef _BACK_MONITOR_H_
50 #define _BACK_MONITOR_H_
51
52 #include <ldap_pvt.h>
53 #include <ldap_pvt_thread.h>
54 #include <avl.h>
55 #include <slap.h>
56
57 LDAP_BEGIN_DECL
58
59 /*
60  * The cache maps DNs to Entries.
61 /*
62  * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
63  * 
64  * This work has beed deveolped for the OpenLDAP Foundation 
65  * in the hope that it may be useful to the Open Source community, 
66  * but WITHOUT ANY WARRANTY.
67  * 
68  * Permission is granted to anyone to use this software for any purpose
69  * on any computer system, and to alter it and redistribute it, subject
70  * to the following restrictions:
71  * 
72  * 1. The author and SysNet s.n.c. are not responsible for the consequences
73  *    of use of this software, no matter how awful, even if they arise from
74  *    flaws in it.
75  * 
76  * 2. The origin of this software must not be misrepresented, either by
77  *    explicit claim or by omission.  Since few users ever read sources,
78  *    credits should appear in the documentation.
79  * 
80  * 3. Altered versions must be plainly marked as such, and must not be
81  *    misrepresented as being the original software.  Since few users
82  *    ever read sources, credits should appear in the documentation.
83  *    SysNet s.n.c. cannot be responsible for the consequences of the
84  *    alterations.
85  * 
86  * 4. This notice may not be removed or altered.
87  */
88
89
90 #include "portable.h"
91
92 #include <stdio.h>
93 #include <ac/string.h>
94
95 #include "slap.h"
96 #include "back-monitor.h"
97
98 /*
99  * initializes backend subentries
100  */
101 int
102 monitor_subsys_backend_init(
103         BackendDB       *be
104 )
105 {
106         struct monitorinfo      *mi;
107         Entry                   *e, *e_backend, *e_tmp;
108         int                     i;
109         struct monitorentrypriv *mp;
110
111         mi = ( struct monitorinfo * )be->be_private;
112
113         if ( monitor_cache_get( mi, 
114                                 &monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn, 
115                                 &e_backend ) ) {
116 #ifdef NEW_LOGGING
117                 LDAP_LOG( OPERATION, CRIT,
118                         "monitor_subsys_backend_init: "
119                         "unable to get entry '%s'\n",
120                         monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val, 0, 0 );
121 #else
122                 Debug( LDAP_DEBUG_ANY,
123                         "monitor_subsys_backend_init: "
124                         "unable to get entry '%s'\n%s%s",
125                         monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val, 
126                         "", "" );
127 #endif
128                 return( -1 );
129         }
130
131         e_tmp = NULL;
132         for ( i = nBackendInfo; i--; ) {
133                 char            buf[ BACKMONITOR_BUFSIZE ];
134                 BackendInfo     *bi;
135                 struct berval   bv;
136                 int             j;
137
138                 bi = &backendInfo[i];
139
140                 snprintf( buf, sizeof( buf ),
141                                 "dn: cn=Backend %d,%s\n"
142                                 "objectClass: %s\n"
143                                 "structuralObjectClass: %s\n"
144                                 "cn: Backend %d\n"
145                                 "createTimestamp: %s\n"
146                                 "modifyTimestamp: %s\n",
147                                 i,
148                                 monitor_subsys[SLAPD_MONITOR_BACKEND].mss_dn.bv_val,
149                                 mi->mi_oc_monitoredObject->soc_cname.bv_val,
150                                 mi->mi_oc_monitoredObject->soc_cname.bv_val,
151                                 i,
152                                 mi->mi_startTime.bv_val,
153                                 mi->mi_startTime.bv_val );
154                 
155                 e = str2entry( buf );
156                 if ( e == NULL ) {
157 #ifdef NEW_LOGGING
158                         LDAP_LOG( OPERATION, CRIT,
159                                 "monitor_subsys_backend_init: "
160                                 "unable to create entry 'cn=Backend %d,%s'\n",
161                                 i, monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val, 0 );
162 #else
163                         Debug( LDAP_DEBUG_ANY,
164                                 "monitor_subsys_backend_init: "
165                                 "unable to create entry 'cn=Backend %d,%s'\n%s",
166                                 i, 
167                                 monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val,
168                                 "" );
169 #endif
170                         return( -1 );
171                 }
172                 
173                 bv.bv_val = bi->bi_type;
174                 bv.bv_len = strlen( bv.bv_val );
175
176                 attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo,
177                                 &bv, NULL );
178                 attr_merge_normalize_one( e_backend, mi->mi_ad_monitoredInfo,
179                                 &bv, NULL );
180
181                 if ( bi->bi_controls ) {
182                         int j;
183
184                         for ( j = 0; bi->bi_controls[ j ]; j++ ) {
185                                 bv.bv_val = bi->bi_controls[ j ];
186                                 bv.bv_len = strlen( bv.bv_val );
187                                 attr_merge_one( e, slap_schema.si_ad_supportedControl, &bv, NULL );
188                         }
189                 }
190
191                 for ( j = 0; j < nBackendDB; j++ ) {
192                         BackendDB       *be = &backendDB[j];
193                         char            buf[ SLAP_LDAPDN_MAXLEN ];
194                         struct berval   dn;
195                         
196                         if ( be->bd_info != bi ) {
197                                 continue;
198                         }
199
200                         snprintf( buf, sizeof( buf ), "cn=Database %d,%s",
201                                         j, monitor_subsys[SLAPD_MONITOR_DATABASE].mss_dn.bv_val );
202                         dn.bv_val = buf;
203                         dn.bv_len = strlen( buf );
204
205                         attr_merge_normalize_one( e, mi->mi_ad_seeAlso,
206                                         &dn, NULL );
207                 }
208                 
209                 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
210                 e->e_private = ( void * )mp;
211                 mp->mp_next = e_tmp;
212                 mp->mp_children = NULL;
213                 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_BACKEND];
214                 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_BACKEND].mss_flags
215                         | MONITOR_F_SUB;
216
217                 if ( monitor_cache_add( mi, e ) ) {
218 #ifdef NEW_LOGGING
219                         LDAP_LOG( OPERATION, CRIT,
220                                 "monitor_subsys_backend_init: "
221                                 "unable to add entry 'cn=Backend %d,%s'\n",
222                                 i, monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val, 0 );
223 #else
224                         Debug( LDAP_DEBUG_ANY,
225                                 "monitor_subsys_backend_init: "
226                                 "unable to add entry 'cn=Backend %d,%s'\n%s",
227                                 i,
228                                 monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val,
229                                 "" );
230 #endif
231                         return( -1 );
232                 }
233
234                 e_tmp = e;
235         }
236         
237         mp = ( struct monitorentrypriv * )e_backend->e_private;
238         mp->mp_children = e_tmp;
239
240         monitor_cache_release( mi, e_backend );
241
242         return( 0 );
243 }
244