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