]> git.sur5r.net Git - openldap/blob - servers/slapd/back-monitor/backend.c
import fix to back-monitor attribute normalization (ITS#3659)
[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 2001-2005 The OpenLDAP Foundation.
6  * Portions Copyright 2001-2003 Pierangelo Masarati.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted only as authorized by the OpenLDAP
11  * Public License.
12  *
13  * A copy of this license is available in file LICENSE in the
14  * top-level directory of the distribution or, alternatively, at
15  * <http://www.OpenLDAP.org/license.html>.
16  */
17 /* ACKNOWLEDGEMENTS:
18  * This work was initially developed by Pierangelo Masarati for inclusion
19  * in OpenLDAP Software.
20  */
21
22
23 #include "portable.h"
24
25 #include <stdio.h>
26 #include <ac/string.h>
27
28 #include "slap.h"
29 #include "back-monitor.h"
30
31 /*
32  * initializes backend subentries
33  */
34 int
35 monitor_subsys_backend_init(
36         BackendDB       *be
37 )
38 {
39         struct monitorinfo      *mi;
40         Entry                   *e, *e_backend, *e_tmp;
41         int                     i;
42         struct monitorentrypriv *mp;
43
44         mi = ( struct monitorinfo * )be->be_private;
45
46         if ( monitor_cache_get( mi, 
47                                 &monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn, 
48                                 &e_backend ) ) {
49 #ifdef NEW_LOGGING
50                 LDAP_LOG( OPERATION, CRIT,
51                         "monitor_subsys_backend_init: "
52                         "unable to get entry '%s'\n",
53                         monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val, 0, 0 );
54 #else
55                 Debug( LDAP_DEBUG_ANY,
56                         "monitor_subsys_backend_init: "
57                         "unable to get entry '%s'\n%s%s",
58                         monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val, 
59                         "", "" );
60 #endif
61                 return( -1 );
62         }
63
64         e_tmp = NULL;
65         for ( i = nBackendInfo; i--; ) {
66                 char            buf[ BACKMONITOR_BUFSIZE ];
67                 BackendInfo     *bi;
68                 struct berval   bv;
69                 int             j;
70
71                 bi = &backendInfo[i];
72
73                 snprintf( buf, sizeof( buf ),
74                                 "dn: cn=Backend %d,%s\n"
75                                 "objectClass: %s\n"
76                                 "structuralObjectClass: %s\n"
77                                 "cn: Backend %d\n"
78                                 "createTimestamp: %s\n"
79                                 "modifyTimestamp: %s\n",
80                                 i,
81                                 monitor_subsys[SLAPD_MONITOR_BACKEND].mss_dn.bv_val,
82                                 mi->mi_oc_monitoredObject->soc_cname.bv_val,
83                                 mi->mi_oc_monitoredObject->soc_cname.bv_val,
84                                 i,
85                                 mi->mi_startTime.bv_val,
86                                 mi->mi_startTime.bv_val );
87                 
88                 e = str2entry( buf );
89                 if ( e == NULL ) {
90 #ifdef NEW_LOGGING
91                         LDAP_LOG( OPERATION, CRIT,
92                                 "monitor_subsys_backend_init: "
93                                 "unable to create entry 'cn=Backend %d,%s'\n",
94                                 i, monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val, 0 );
95 #else
96                         Debug( LDAP_DEBUG_ANY,
97                                 "monitor_subsys_backend_init: "
98                                 "unable to create entry 'cn=Backend %d,%s'\n%s",
99                                 i, 
100                                 monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val,
101                                 "" );
102 #endif
103                         return( -1 );
104                 }
105                 
106                 bv.bv_val = bi->bi_type;
107                 bv.bv_len = strlen( bv.bv_val );
108
109                 attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo,
110                                 &bv, NULL );
111                 attr_merge_normalize_one( e_backend, mi->mi_ad_monitoredInfo,
112                                 &bv, NULL );
113
114                 if ( bi->bi_controls ) {
115                         int j;
116
117                         for ( j = 0; bi->bi_controls[ j ]; j++ ) {
118                                 bv.bv_val = bi->bi_controls[ j ];
119                                 bv.bv_len = strlen( bv.bv_val );
120                                 attr_merge_one( e, slap_schema.si_ad_supportedControl, &bv, &bv );
121                         }
122                 }
123
124                 for ( j = 0; j < nBackendDB; j++ ) {
125                         BackendDB       *be = &backendDB[j];
126                         char            buf[ SLAP_LDAPDN_MAXLEN ];
127                         struct berval   dn;
128                         
129                         if ( be->bd_info != bi ) {
130                                 continue;
131                         }
132
133                         snprintf( buf, sizeof( buf ), "cn=Database %d,%s",
134                                         j, monitor_subsys[SLAPD_MONITOR_DATABASE].mss_dn.bv_val );
135                         dn.bv_val = buf;
136                         dn.bv_len = strlen( buf );
137
138                         attr_merge_normalize_one( e, mi->mi_ad_seeAlso,
139                                         &dn, NULL );
140                 }
141                 
142                 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
143                 e->e_private = ( void * )mp;
144                 mp->mp_next = e_tmp;
145                 mp->mp_children = NULL;
146                 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_BACKEND];
147                 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_BACKEND].mss_flags
148                         | MONITOR_F_SUB;
149
150                 if ( monitor_cache_add( mi, e ) ) {
151 #ifdef NEW_LOGGING
152                         LDAP_LOG( OPERATION, CRIT,
153                                 "monitor_subsys_backend_init: "
154                                 "unable to add entry 'cn=Backend %d,%s'\n",
155                                 i, monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val, 0 );
156 #else
157                         Debug( LDAP_DEBUG_ANY,
158                                 "monitor_subsys_backend_init: "
159                                 "unable to add entry 'cn=Backend %d,%s'\n%s",
160                                 i,
161                                 monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val,
162                                 "" );
163 #endif
164                         return( -1 );
165                 }
166
167                 e_tmp = e;
168         }
169         
170         mp = ( struct monitorentrypriv * )e_backend->e_private;
171         mp->mp_children = e_tmp;
172
173         monitor_cache_release( mi, e_backend );
174
175         return( 0 );
176 }
177