]> git.sur5r.net Git - openldap/blob - servers/slapd/back-monitor/backend.c
c0c61b95fef06c76aec7d1004d142f5fdf4e4bdf
[openldap] / servers / slapd / back-monitor / backend.c
1 /* backend.c - deals with backend subsystem */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2001-2004 The OpenLDAP Foundation.
6  * Portions Copyright 2001-2003 Pierangelo Masarati.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted only as authorized by the OpenLDAP
11  * Public License.
12  *
13  * A copy of this license is available in file LICENSE in the
14  * top-level directory of the distribution or, alternatively, at
15  * <http://www.OpenLDAP.org/license.html>.
16  */
17 /* ACKNOWLEDGEMENTS:
18  * This work was initially developed by Pierangelo Masarati for inclusion
19  * in OpenLDAP Software.
20  */
21
22
23 #include "portable.h"
24
25 #include <stdio.h>
26 #include <ac/string.h>
27
28 #include "slap.h"
29 #include "back-monitor.h"
30
31 /*
32  * initializes backend subentries
33  */
34 int
35 monitor_subsys_backend_init(
36         BackendDB       *be
37 )
38 {
39         struct monitorinfo      *mi;
40         Entry                   *e_backend, **ep;
41         int                     i;
42         struct monitorentrypriv *mp;
43
44         mi = ( struct monitorinfo * )be->be_private;
45
46         if ( monitor_cache_get( mi, 
47                                 &monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn, 
48                                 &e_backend ) )
49         {
50                 Debug( LDAP_DEBUG_ANY,
51                         "monitor_subsys_backend_init: "
52                         "unable to get entry \"%s\"\n",
53                         monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val, 0, 0 );
54                 return( -1 );
55         }
56
57         mp = ( struct monitorentrypriv * )e_backend->e_private;
58         mp->mp_children = NULL;
59         ep = &mp->mp_children;
60
61         for ( i = 0; i < nBackendInfo; i++ ) {
62                 char            buf[ BACKMONITOR_BUFSIZE ];
63                 BackendInfo     *bi;
64                 struct berval   bv;
65                 int             j;
66                 Entry           *e;
67
68                 bi = &backendInfo[i];
69
70                 snprintf( buf, sizeof( buf ),
71                                 "dn: cn=Backend %d,%s\n"
72                                 "objectClass: %s\n"
73                                 "structuralObjectClass: %s\n"
74                                 "cn: Backend %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_BACKEND].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                         Debug( LDAP_DEBUG_ANY,
92                                 "monitor_subsys_backend_init: "
93                                 "unable to create entry \"cn=Backend %d,%s\"\n",
94                                 i, monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val, 0 );
95                         return( -1 );
96                 }
97                 
98                 bv.bv_val = bi->bi_type;
99                 bv.bv_len = strlen( bv.bv_val );
100
101                 attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo,
102                                 &bv, NULL );
103                 attr_merge_normalize_one( e_backend, mi->mi_ad_monitoredInfo,
104                                 &bv, NULL );
105
106                 if ( bi->bi_controls ) {
107                         int j;
108
109                         for ( j = 0; bi->bi_controls[ j ]; j++ ) {
110                                 bv.bv_val = bi->bi_controls[ j ];
111                                 bv.bv_len = strlen( bv.bv_val );
112                                 attr_merge_one( e, slap_schema.si_ad_supportedControl, &bv, NULL );
113                         }
114                 }
115
116                 for ( j = 0; j < nBackendDB; j++ ) {
117                         BackendDB       *be = &backendDB[j];
118                         char            buf[ SLAP_LDAPDN_MAXLEN ];
119                         struct berval   dn;
120                         
121                         if ( be->bd_info != bi ) {
122                                 continue;
123                         }
124
125                         snprintf( buf, sizeof( buf ), "cn=Database %d,%s",
126                                         j, monitor_subsys[SLAPD_MONITOR_DATABASE].mss_dn.bv_val );
127                         dn.bv_val = buf;
128                         dn.bv_len = strlen( buf );
129
130                         attr_merge_normalize_one( e, mi->mi_ad_seeAlso,
131                                         &dn, NULL );
132                 }
133                 
134                 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
135                 e->e_private = ( void * )mp;
136                 mp->mp_next = NULL;
137                 mp->mp_children = NULL;
138                 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_BACKEND];
139                 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_BACKEND].mss_flags
140                         | MONITOR_F_SUB;
141
142                 if ( monitor_cache_add( mi, e ) ) {
143                         Debug( LDAP_DEBUG_ANY,
144                                 "monitor_subsys_backend_init: "
145                                 "unable to add entry \"cn=Backend %d,%s\"\n",
146                                 i,
147                                 monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val, 0 );
148                         return( -1 );
149                 }
150
151                 *ep = e;
152                 ep = &mp->mp_next;
153         }
154         
155         monitor_cache_release( mi, e_backend );
156
157         return( 0 );
158 }
159