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