]> git.sur5r.net Git - openldap/blob - servers/slapd/back-monitor/backend.c
#include <ac/string.h>, to get strlen(), strncmp() and strncasecmp().
[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                                 i,
91                                 monitor_subsys[SLAPD_MONITOR_BACKEND].mss_dn.bv_val,
92                                 mi->oc_monitoredObject->soc_cname.bv_val,
93                                 mi->oc_monitoredObject->soc_cname.bv_val,
94                                 i );
95                 
96                 e = str2entry( buf );
97                 if ( e == NULL ) {
98 #ifdef NEW_LOGGING
99                         LDAP_LOG( OPERATION, CRIT,
100                                 "monitor_subsys_backend_init: "
101                                 "unable to create entry 'cn=Backend %d,%s'\n",
102                                 i, monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val, 0 );
103 #else
104                         Debug( LDAP_DEBUG_ANY,
105                                 "monitor_subsys_backend_init: "
106                                 "unable to create entry 'cn=Backend %d,%s'\n%s",
107                                 i, 
108                                 monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val,
109                                 "" );
110 #endif
111                         return( -1 );
112                 }
113                 
114                 bv.bv_val = bi->bi_type;
115                 bv.bv_len = strlen( bv.bv_val );
116
117                 attr_merge_normalize_one( e, mi->ad_monitoredInfo,
118                                 &bv, NULL );
119                 attr_merge_normalize_one( e_backend, mi->ad_monitoredInfo,
120                                 &bv, NULL );
121
122                 if ( bi->bi_controls ) {
123                         int j;
124
125                         for ( j = 0; bi->bi_controls[ j ]; j++ ) {
126                                 bv.bv_val = bi->bi_controls[ j ];
127                                 bv.bv_len = strlen( bv.bv_val );
128                                 attr_merge_one( e, slap_schema.si_ad_supportedControl, &bv, NULL );
129                         }
130                 }
131
132                 for ( j = 0; j < nBackendDB; j++ ) {
133                         BackendDB       *be = &backendDB[j];
134                         char            buf[ SLAP_LDAPDN_MAXLEN ];
135                         struct berval   dn;
136                         
137                         if ( be->bd_info != bi ) {
138                                 continue;
139                         }
140
141                         snprintf( buf, sizeof( buf ), "cn=Database %d,%s",
142                                         j, monitor_subsys[SLAPD_MONITOR_DATABASE].mss_dn.bv_val );
143                         dn.bv_val = buf;
144                         dn.bv_len = strlen( buf );
145
146                         attr_merge_normalize_one( e, mi->ad_seeAlso,
147                                         &dn, NULL );
148                 }
149                 
150                 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
151                 e->e_private = ( void * )mp;
152                 mp->mp_next = e_tmp;
153                 mp->mp_children = NULL;
154                 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_BACKEND];
155                 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_BACKEND].mss_flags
156                         | MONITOR_F_SUB;
157
158                 if ( monitor_cache_add( mi, e ) ) {
159 #ifdef NEW_LOGGING
160                         LDAP_LOG( OPERATION, CRIT,
161                                 "monitor_subsys_backend_init: "
162                                 "unable to add entry 'cn=Backend %d,%s'\n",
163                                 i, monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val, 0 );
164 #else
165                         Debug( LDAP_DEBUG_ANY,
166                                 "monitor_subsys_backend_init: "
167                                 "unable to add entry 'cn=Backend %d,%s'\n%s",
168                                 i,
169                                 monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val,
170                                 "" );
171 #endif
172                         return( -1 );
173                 }
174
175                 e_tmp = e;
176         }
177         
178         mp = ( struct monitorentrypriv * )e_backend->e_private;
179         mp->mp_children = e_tmp;
180
181         monitor_cache_release( mi, e_backend );
182
183         return( 0 );
184 }
185