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