]> git.sur5r.net Git - openldap/blob - servers/slapd/back-monitor/backend.c
use back-monitor without including core.schema; commit by now; will cleanup later
[openldap] / servers / slapd / back-monitor / backend.c
1 /* backend.c - deals with backend subsystem */
2 /*
3  * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
4  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5  */
6 /*
7  * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
8  * 
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.
12  * 
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:
16  * 
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
19  *    flaws in it.
20  * 
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.
24  * 
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
29  *    alterations.
30  * 
31  * 4. This notice may not be removed or altered.
32  */
33
34
35 #include "portable.h"
36
37 #include <stdio.h>
38 #include <ac/string.h>
39
40 #include "slap.h"
41 #include "back-monitor.h"
42
43 /*
44  * initializes backend subentries
45  */
46 int
47 monitor_subsys_backend_init(
48         BackendDB       *be
49 )
50 {
51         struct monitorinfo      *mi;
52         Entry                   *e, *e_backend, *e_tmp;
53         int                     i;
54         struct monitorentrypriv *mp;
55
56         mi = ( struct monitorinfo * )be->be_private;
57
58         if ( monitor_cache_get( mi, 
59                                 &monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn, 
60                                 &e_backend ) ) {
61 #ifdef NEW_LOGGING
62                 LDAP_LOG( OPERATION, CRIT,
63                         "monitor_subsys_backend_init: "
64                         "unable to get entry '%s'\n",
65                         monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val, 0, 0 );
66 #else
67                 Debug( LDAP_DEBUG_ANY,
68                         "monitor_subsys_backend_init: "
69                         "unable to get entry '%s'\n%s%s",
70                         monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val, 
71                         "", "" );
72 #endif
73                 return( -1 );
74         }
75
76         e_tmp = NULL;
77         for ( i = nBackendInfo; i--; ) {
78                 char            buf[ BACKMONITOR_BUFSIZE ];
79                 BackendInfo     *bi;
80                 struct berval   bv;
81                 int             j;
82
83                 bi = &backendInfo[i];
84
85                 snprintf( buf, sizeof( buf ),
86                                 "dn: cn=Backend %d,%s\n"
87                                 "objectClass: %s\n"
88                                 "structuralObjectClass: %s\n"
89                                 "cn: Backend %d\n"
90                                 "createTimestamp: %s\n"
91                                 "modifyTimestamp: %s\n",
92                                 i,
93                                 monitor_subsys[SLAPD_MONITOR_BACKEND].mss_dn.bv_val,
94                                 mi->mi_oc_monitoredObject->soc_cname.bv_val,
95                                 mi->mi_oc_monitoredObject->soc_cname.bv_val,
96                                 i,
97                                 mi->mi_startTime.bv_val,
98                                 mi->mi_startTime.bv_val );
99                 
100                 e = str2entry( buf );
101                 if ( e == NULL ) {
102 #ifdef NEW_LOGGING
103                         LDAP_LOG( OPERATION, CRIT,
104                                 "monitor_subsys_backend_init: "
105                                 "unable to create entry 'cn=Backend %d,%s'\n",
106                                 i, monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val, 0 );
107 #else
108                         Debug( LDAP_DEBUG_ANY,
109                                 "monitor_subsys_backend_init: "
110                                 "unable to create entry 'cn=Backend %d,%s'\n%s",
111                                 i, 
112                                 monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val,
113                                 "" );
114 #endif
115                         return( -1 );
116                 }
117                 
118                 bv.bv_val = bi->bi_type;
119                 bv.bv_len = strlen( bv.bv_val );
120
121                 attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo,
122                                 &bv, NULL );
123                 attr_merge_normalize_one( e_backend, mi->mi_ad_monitoredInfo,
124                                 &bv, NULL );
125
126                 if ( bi->bi_controls ) {
127                         int j;
128
129                         for ( j = 0; bi->bi_controls[ j ]; j++ ) {
130                                 bv.bv_val = bi->bi_controls[ j ];
131                                 bv.bv_len = strlen( bv.bv_val );
132                                 attr_merge_one( e, slap_schema.si_ad_supportedControl, &bv, NULL );
133                         }
134                 }
135
136                 for ( j = 0; j < nBackendDB; j++ ) {
137                         BackendDB       *be = &backendDB[j];
138                         char            buf[ SLAP_LDAPDN_MAXLEN ];
139                         struct berval   dn;
140                         
141                         if ( be->bd_info != bi ) {
142                                 continue;
143                         }
144
145                         snprintf( buf, sizeof( buf ), "cn=Database %d,%s",
146                                         j, monitor_subsys[SLAPD_MONITOR_DATABASE].mss_dn.bv_val );
147                         dn.bv_val = buf;
148                         dn.bv_len = strlen( buf );
149
150                         attr_merge_normalize_one( e, mi->mi_ad_seeAlso,
151                                         &dn, NULL );
152                 }
153                 
154                 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
155                 e->e_private = ( void * )mp;
156                 mp->mp_next = e_tmp;
157                 mp->mp_children = NULL;
158                 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_BACKEND];
159                 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_BACKEND].mss_flags
160                         | MONITOR_F_SUB;
161
162                 if ( monitor_cache_add( mi, e ) ) {
163 #ifdef NEW_LOGGING
164                         LDAP_LOG( OPERATION, CRIT,
165                                 "monitor_subsys_backend_init: "
166                                 "unable to add entry 'cn=Backend %d,%s'\n",
167                                 i, monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val, 0 );
168 #else
169                         Debug( LDAP_DEBUG_ANY,
170                                 "monitor_subsys_backend_init: "
171                                 "unable to add entry 'cn=Backend %d,%s'\n%s",
172                                 i,
173                                 monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val,
174                                 "" );
175 #endif
176                         return( -1 );
177                 }
178
179                 e_tmp = e;
180         }
181         
182         mp = ( struct monitorentrypriv * )e_backend->e_private;
183         mp->mp_children = e_tmp;
184
185         monitor_cache_release( mi, e_backend );
186
187         return( 0 );
188 }
189