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