]> git.sur5r.net Git - openldap/blob - servers/slapd/back-monitor/overlay.c
53980bfd5770924d29d22597a8d53ae56588625d
[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         monitorsubsys   *ms
37 )
38 {
39         struct monitorinfo      *mi;
40         Entry                   *e_overlay, **ep;
41         int                     i;
42         struct monitorentrypriv *mp;
43         slap_overinst           *on;
44         monitorsubsys           *ms_database;
45
46         mi = ( struct monitorinfo * )be->be_private;
47
48         ms_database = monitor_back_get_subsys( SLAPD_MONITOR_DATABASE_NAME );
49         if ( ms_database == NULL ) {
50                 Debug( LDAP_DEBUG_ANY,
51                         "monitor_subsys_backend_init: "
52                         "unable to get "
53                         "\"" SLAPD_MONITOR_DATABASE_NAME "\" "
54                         "subsystem\n",
55                         0, 0, 0 );
56                 return -1;
57         }
58
59         if ( monitor_cache_get( mi, 
60                                 &ms->mss_ndn, 
61                                 &e_overlay ) )
62         {
63                 Debug( LDAP_DEBUG_ANY,
64                         "monitor_subsys_overlay_init: "
65                         "unable to get entry \"%s\"\n",
66                         ms->mss_ndn.bv_val, 0, 0 );
67                 return( -1 );
68         }
69
70         mp = ( struct monitorentrypriv * )e_overlay->e_private;
71         mp->mp_children = NULL;
72         ep = &mp->mp_children;
73
74         for ( on = overlay_next( NULL ), i = 0; on; on = overlay_next( on ), i++ ) {
75                 char            buf[ BACKMONITOR_BUFSIZE ];
76                 struct berval   bv;
77                 int             j;
78                 Entry           *e;
79
80                 snprintf( buf, sizeof( buf ),
81                                 "dn: cn=Overlay %d,%s\n"
82                                 "objectClass: %s\n"
83                                 "structuralObjectClass: %s\n"
84                                 "cn: Overlay %d\n"
85                                 "creatorsName: %s\n"
86                                 "modifiersName: %s\n"
87                                 "createTimestamp: %s\n"
88                                 "modifyTimestamp: %s\n",
89                                 i,
90                                 ms->mss_dn.bv_val,
91                                 mi->mi_oc_monitoredObject->soc_cname.bv_val,
92                                 mi->mi_oc_monitoredObject->soc_cname.bv_val,
93                                 i,
94                                 mi->mi_creatorsName.bv_val,
95                                 mi->mi_creatorsName.bv_val,
96                                 mi->mi_startTime.bv_val,
97                                 mi->mi_startTime.bv_val );
98                 
99                 e = str2entry( buf );
100                 if ( e == NULL ) {
101                         Debug( LDAP_DEBUG_ANY,
102                                 "monitor_subsys_overlay_init: "
103                                 "unable to create entry \"cn=Overlay %d,%s\"\n",
104                                 i, ms->mss_ndn.bv_val, 0 );
105                         return( -1 );
106                 }
107                 
108                 bv.bv_val = on->on_bi.bi_type;
109                 bv.bv_len = strlen( bv.bv_val );
110
111                 attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo,
112                                 &bv, NULL );
113                 attr_merge_normalize_one( e_overlay, mi->mi_ad_monitoredInfo,
114                                 &bv, NULL );
115
116                 for ( j = 0; j < nBackendDB; j++ ) {
117                         BackendDB       *be = &backendDB[ j ];
118                         char            buf[ SLAP_LDAPDN_MAXLEN ];
119                         struct berval   dn;
120                         slap_overinst   *on2;
121
122                         if ( strcmp( be->bd_info->bi_type, "over" ) != 0 ) {
123                                 continue;
124                         }
125
126                         on2 = ((slap_overinfo *)be->bd_info->bi_private)->oi_list;
127                         for ( ; on2; on2 = on2->on_next ) {
128                                 if ( on2->on_bi.bi_type == on->on_bi.bi_type ) {
129                                         break;
130                                 }
131                         }
132
133                         if ( on2 == NULL ) {
134                                 continue;
135                         }
136
137                         snprintf( buf, sizeof( buf ), "cn=Database %d,%s",
138                                         j, ms_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 = monitor_entrypriv_create();
147                 if ( mp == NULL ) {
148                         return -1;
149                 }
150                 e->e_private = ( void * )mp;
151                 mp->mp_info = ms;
152                 mp->mp_flags = ms->mss_flags
153                         | MONITOR_F_SUB;
154
155                 if ( monitor_cache_add( mi, e ) ) {
156                         Debug( LDAP_DEBUG_ANY,
157                                 "monitor_subsys_overlay_init: "
158                                 "unable to add entry \"cn=Overlay %d,%s\"\n",
159                                 i, ms->mss_ndn.bv_val, 0 );
160                         return( -1 );
161                 }
162
163                 *ep = e;
164                 ep = &mp->mp_next;
165         }
166         
167         monitor_cache_release( mi, e_overlay );
168
169         return( 0 );
170 }
171