]> git.sur5r.net Git - openldap/blob - servers/slapd/back-monitor/backend.c
use a macro for the entry buffer size
[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
39 #include "slap.h"
40 #include "back-monitor.h"
41
42 /*
43  * initializes backend subentries
44  */
45 int
46 monitor_subsys_backend_init(
47         BackendDB       *be
48 )
49 {
50         struct monitorinfo      *mi;
51         Entry                   *e, *e_backend, *e_tmp;
52         int                     i;
53         struct monitorentrypriv *mp;
54
55         mi = ( struct monitorinfo * )be->be_private;
56
57         if ( monitor_cache_get( mi, 
58                                 &monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn, 
59                                 &e_backend ) ) {
60 #ifdef NEW_LOGGING
61                 LDAP_LOG( OPERATION, CRIT,
62                         "monitor_subsys_backend_init: "
63                         "unable to get entry '%s'\n",
64                         monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val, 0, 0 );
65 #else
66                 Debug( LDAP_DEBUG_ANY,
67                         "monitor_subsys_backend_init: "
68                         "unable to get entry '%s'\n%s%s",
69                         monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val, 
70                         "", "" );
71 #endif
72                 return( -1 );
73         }
74
75         e_tmp = NULL;
76         for ( i = nBackendInfo; i--; ) {
77                 char            buf[ BACKMONITOR_BUFSIZE ];
78                 BackendInfo     *bi;
79                 struct berval   bv;
80                 int             j;
81
82                 bi = &backendInfo[i];
83
84                 snprintf( buf, sizeof( buf ),
85                                 "dn: cn=Backend %d,%s\n"
86                                 "objectClass: %s\n"
87                                 "structuralObjectClass: %s\n"
88                                 "cn: Backend %d\n",
89                                 i,
90                                 monitor_subsys[SLAPD_MONITOR_BACKEND].mss_dn.bv_val,
91                                 mi->oc_monitoredObject->soc_cname.bv_val,
92                                 mi->oc_monitoredObject->soc_cname.bv_val,
93                                 i );
94                 
95                 e = str2entry( buf );
96                 if ( e == NULL ) {
97 #ifdef NEW_LOGGING
98                         LDAP_LOG( OPERATION, CRIT,
99                                 "monitor_subsys_backend_init: "
100                                 "unable to create entry 'cn=Backend %d,%s'\n",
101                                 i, monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val, 0 );
102 #else
103                         Debug( LDAP_DEBUG_ANY,
104                                 "monitor_subsys_backend_init: "
105                                 "unable to create entry 'cn=Backend %d,%s'\n%s",
106                                 i, 
107                                 monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val,
108                                 "" );
109 #endif
110                         return( -1 );
111                 }
112                 
113                 bv.bv_val = bi->bi_type;
114                 bv.bv_len = strlen( bv.bv_val );
115
116                 attr_merge_normalize_one( e, mi->ad_monitoredInfo,
117                                 &bv, NULL );
118                 attr_merge_normalize_one( e_backend, mi->ad_monitoredInfo,
119                                 &bv, NULL );
120
121                 if ( bi->bi_controls ) {
122                         int j;
123
124                         for ( j = 0; bi->bi_controls[ j ]; j++ ) {
125                                 bv.bv_val = bi->bi_controls[ j ];
126                                 bv.bv_len = strlen( bv.bv_val );
127                                 attr_merge_one( e, slap_schema.si_ad_supportedControl, &bv, NULL );
128                         }
129                 }
130
131                 for ( j = 0; j < nBackendDB; j++ ) {
132                         BackendDB       *be = &backendDB[j];
133                         char            buf[ SLAP_LDAPDN_MAXLEN ];
134                         struct berval   dn;
135                         
136                         if ( be->bd_info != bi ) {
137                                 continue;
138                         }
139
140                         snprintf( buf, sizeof( buf ), "cn=Database %d,%s",
141                                         j, monitor_subsys[SLAPD_MONITOR_DATABASE].mss_dn.bv_val );
142                         dn.bv_val = buf;
143                         dn.bv_len = strlen( buf );
144
145                         attr_merge_normalize_one( e, mi->ad_seeAlso,
146                                         &dn, NULL );
147                 }
148                 
149                 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
150                 e->e_private = ( void * )mp;
151                 mp->mp_next = e_tmp;
152                 mp->mp_children = NULL;
153                 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_BACKEND];
154                 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_BACKEND].mss_flags
155                         | MONITOR_F_SUB;
156
157                 if ( monitor_cache_add( mi, e ) ) {
158 #ifdef NEW_LOGGING
159                         LDAP_LOG( OPERATION, CRIT,
160                                 "monitor_subsys_backend_init: "
161                                 "unable to add entry 'cn=Backend %d,%s'\n",
162                                 i, monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val, 0 );
163 #else
164                         Debug( LDAP_DEBUG_ANY,
165                                 "monitor_subsys_backend_init: "
166                                 "unable to add entry 'cn=Backend %d,%s'\n%s",
167                                 i,
168                                 monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val,
169                                 "" );
170 #endif
171                         return( -1 );
172                 }
173
174                 e_tmp = e;
175         }
176         
177         mp = ( struct monitorentrypriv * )e_backend->e_private;
178         mp->mp_children = e_tmp;
179
180         monitor_cache_release( mi, e_backend );
181
182         return( 0 );
183 }
184