]> git.sur5r.net Git - openldap/blob - servers/slapd/back-monitor/overlay.c
8081d77b0c6571a2b577e5b2f2b7377ce45f86ed
[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_overlay, **ep;
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         {
50                 Debug( LDAP_DEBUG_ANY,
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                 return( -1 );
55         }
56
57         mp = ( struct monitorentrypriv * )e_overlay->e_private;
58         mp->mp_children = NULL;
59         ep = &mp->mp_children;
60
61         for ( on = overlay_next( NULL ), i = 0; on; on = overlay_next( on ), i++ ) {
62                 char            buf[ BACKMONITOR_BUFSIZE ];
63                 struct berval   bv;
64                 int             j;
65                 Entry           *e;
66
67                 snprintf( buf, sizeof( buf ),
68                                 "dn: cn=Overlay %d,%s\n"
69                                 "objectClass: %s\n"
70                                 "structuralObjectClass: %s\n"
71                                 "cn: Overlay %d\n"
72                                 "creatorsName: %s\n"
73                                 "modifiersName: %s\n"
74                                 "createTimestamp: %s\n"
75                                 "modifyTimestamp: %s\n",
76                                 i,
77                                 monitor_subsys[SLAPD_MONITOR_OVERLAY].mss_dn.bv_val,
78                                 mi->mi_oc_monitoredObject->soc_cname.bv_val,
79                                 mi->mi_oc_monitoredObject->soc_cname.bv_val,
80                                 i,
81                                 mi->mi_creatorsName.bv_val,
82                                 mi->mi_creatorsName.bv_val,
83                                 mi->mi_startTime.bv_val,
84                                 mi->mi_startTime.bv_val );
85                 
86                 e = str2entry( buf );
87                 if ( e == NULL ) {
88                         Debug( LDAP_DEBUG_ANY,
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                         return( -1 );
93                 }
94                 
95                 bv.bv_val = on->on_bi.bi_type;
96                 bv.bv_len = strlen( bv.bv_val );
97
98                 attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo,
99                                 &bv, NULL );
100                 attr_merge_normalize_one( e_overlay, mi->mi_ad_monitoredInfo,
101                                 &bv, NULL );
102
103                 for ( j = 0; j < nBackendDB; j++ ) {
104                         BackendDB       *be = &backendDB[j];
105                         char            buf[ SLAP_LDAPDN_MAXLEN ];
106                         struct berval   dn;
107                         slap_overinst   *on2;
108
109                         if ( strcmp( be->bd_info->bi_type, "over" ) != 0 ) {
110                                 continue;
111                         }
112
113                         on2 = ((slap_overinfo *)be->bd_info->bi_private)->oi_list;
114                         for ( ; on2; on2 = on2->on_next ) {
115                                 if ( on2->on_bi.bi_type == on->on_bi.bi_type ) {
116                                         break;
117                                 }
118                         }
119
120                         if ( on2 == NULL ) {
121                                 continue;
122                         }
123
124                         snprintf( buf, sizeof( buf ), "cn=Database %d,%s",
125                                         j, monitor_subsys[SLAPD_MONITOR_DATABASE].mss_dn.bv_val );
126                         dn.bv_val = buf;
127                         dn.bv_len = strlen( buf );
128
129                         attr_merge_normalize_one( e, mi->mi_ad_seeAlso,
130                                         &dn, NULL );
131                 }
132                 
133                 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
134                 e->e_private = ( void * )mp;
135                 mp->mp_next = NULL;
136                 mp->mp_children = NULL;
137                 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_OVERLAY];
138                 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_OVERLAY].mss_flags
139                         | MONITOR_F_SUB;
140
141                 if ( monitor_cache_add( mi, e ) ) {
142                         Debug( LDAP_DEBUG_ANY,
143                                 "monitor_subsys_overlay_init: "
144                                 "unable to add entry \"cn=Overlay %d,%s\"\n",
145                                 i, monitor_subsys[SLAPD_MONITOR_OVERLAY].mss_ndn.bv_val, 0 );
146                         return( -1 );
147                 }
148
149                 *ep = e;
150                 ep = &mp->mp_next;
151         }
152         
153         monitor_cache_release( mi, e_overlay );
154
155         return( 0 );
156 }
157