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