]> git.sur5r.net Git - openldap/blob - servers/slapd/back-monitor/backend.c
notices
[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
50 #include "portable.h"
51
52 #include <stdio.h>
53 #include <ac/string.h>
54
55 #include "slap.h"
56 #include "back-monitor.h"
57
58 /*
59  * initializes backend subentries
60  */
61 int
62 monitor_subsys_backend_init(
63         BackendDB       *be
64 )
65 {
66         struct monitorinfo      *mi;
67         Entry                   *e, *e_backend, *e_tmp;
68         int                     i;
69         struct monitorentrypriv *mp;
70
71         mi = ( struct monitorinfo * )be->be_private;
72
73         if ( monitor_cache_get( mi, 
74                                 &monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn, 
75                                 &e_backend ) ) {
76 #ifdef NEW_LOGGING
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 );
81 #else
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, 
86                         "", "" );
87 #endif
88                 return( -1 );
89         }
90
91         e_tmp = NULL;
92         for ( i = nBackendInfo; i--; ) {
93                 char            buf[ BACKMONITOR_BUFSIZE ];
94                 BackendInfo     *bi;
95                 struct berval   bv;
96                 int             j;
97
98                 bi = &backendInfo[i];
99
100                 snprintf( buf, sizeof( buf ),
101                                 "dn: cn=Backend %d,%s\n"
102                                 "objectClass: %s\n"
103                                 "structuralObjectClass: %s\n"
104                                 "cn: Backend %d\n"
105                                 "createTimestamp: %s\n"
106                                 "modifyTimestamp: %s\n",
107                                 i,
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,
111                                 i,
112                                 mi->mi_startTime.bv_val,
113                                 mi->mi_startTime.bv_val );
114                 
115                 e = str2entry( buf );
116                 if ( e == NULL ) {
117 #ifdef NEW_LOGGING
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 );
122 #else
123                         Debug( LDAP_DEBUG_ANY,
124                                 "monitor_subsys_backend_init: "
125                                 "unable to create entry 'cn=Backend %d,%s'\n%s",
126                                 i, 
127                                 monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val,
128                                 "" );
129 #endif
130                         return( -1 );
131                 }
132                 
133                 bv.bv_val = bi->bi_type;
134                 bv.bv_len = strlen( bv.bv_val );
135
136                 attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo,
137                                 &bv, NULL );
138                 attr_merge_normalize_one( e_backend, mi->mi_ad_monitoredInfo,
139                                 &bv, NULL );
140
141                 if ( bi->bi_controls ) {
142                         int j;
143
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 );
148                         }
149                 }
150
151                 for ( j = 0; j < nBackendDB; j++ ) {
152                         BackendDB       *be = &backendDB[j];
153                         char            buf[ SLAP_LDAPDN_MAXLEN ];
154                         struct berval   dn;
155                         
156                         if ( be->bd_info != bi ) {
157                                 continue;
158                         }
159
160                         snprintf( buf, sizeof( buf ), "cn=Database %d,%s",
161                                         j, monitor_subsys[SLAPD_MONITOR_DATABASE].mss_dn.bv_val );
162                         dn.bv_val = buf;
163                         dn.bv_len = strlen( buf );
164
165                         attr_merge_normalize_one( e, mi->mi_ad_seeAlso,
166                                         &dn, NULL );
167                 }
168                 
169                 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
170                 e->e_private = ( void * )mp;
171                 mp->mp_next = e_tmp;
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
175                         | MONITOR_F_SUB;
176
177                 if ( monitor_cache_add( mi, e ) ) {
178 #ifdef NEW_LOGGING
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 );
183 #else
184                         Debug( LDAP_DEBUG_ANY,
185                                 "monitor_subsys_backend_init: "
186                                 "unable to add entry 'cn=Backend %d,%s'\n%s",
187                                 i,
188                                 monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val,
189                                 "" );
190 #endif
191                         return( -1 );
192                 }
193
194                 e_tmp = e;
195         }
196         
197         mp = ( struct monitorentrypriv * )e_backend->e_private;
198         mp->mp_children = e_tmp;
199
200         monitor_cache_release( mi, e_backend );
201
202         return( 0 );
203 }
204