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