]> git.sur5r.net Git - openldap/blob - servers/slapd/back-monitor/database.c
Changed search attrs from struct berval ** to AttributeName *
[openldap] / servers / slapd / back-monitor / database.c
1 /* database.c - deals with database subsystem */
2 /*
3  * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
4  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5  */
6 /*
7  * Copyright 2001 The OpenLDAP Foundation, All Rights Reserved.
8  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
9  * 
10  * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
11  * 
12  * This work has beed deveolped for the OpenLDAP Foundation 
13  * in the hope that it may be useful to the Open Source community, 
14  * but WITHOUT ANY WARRANTY.
15  * 
16  * Permission is granted to anyone to use this software for any purpose
17  * on any computer system, and to alter it and redistribute it, subject
18  * to the following restrictions:
19  * 
20  * 1. The author and SysNet s.n.c. are not responsible for the consequences
21  *    of use of this software, no matter how awful, even if they arise from
22  *    flaws in it.
23  * 
24  * 2. The origin of this software must not be misrepresented, either by
25  *    explicit claim or by omission.  Since few users ever read sources,
26  *    credits should appear in the documentation.
27  * 
28  * 3. Altered versions must be plainly marked as such, and must not be
29  *    misrepresented as being the original software.  Since few users
30  *    ever read sources, credits should appear in the documentation.
31  *    SysNet s.n.c. cannot be responsible for the consequences of the
32  *    alterations.
33  * 
34  * 4. This notice may not be removed or altered.
35  */
36
37 #include "portable.h"
38
39 #include <stdio.h>
40
41 #include "slap.h"
42 #include "back-monitor.h"
43
44 int
45 monitor_subsys_database_init(
46         BackendDB       *be
47 )
48 {
49         struct monitorinfo      *mi;
50         Entry                   *e, *e_database, *e_tmp;
51         int                     i;
52         struct monitorentrypriv *mp;
53         AttributeDescription    *ad_nc = slap_schema.si_ad_namingContexts;
54         struct berval           val, *bv[2] = { &val, NULL };
55
56         assert( be != NULL );
57         assert( monitor_ad_desc != NULL );
58
59         mi = ( struct monitorinfo * )be->be_private;
60
61         if ( monitor_cache_get( mi, 
62                                 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn, 
63                                 &e_database ) ) {
64 #ifdef NEW_LOGGING
65                 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
66                         "monitor_subsys_database_init: "
67                         "unable to get entry '%s'\n",
68                         monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn->bv_val ));
69 #else
70                 Debug( LDAP_DEBUG_ANY,
71                         "monitor_subsys_database_init: "
72                         "unable to get entry '%s'\n%s%s",
73                         monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn->bv_val, 
74                         "", "" );
75 #endif
76                 return( -1 );
77         }
78
79         e_tmp = NULL;
80         for ( i = nBackendDB; i--; ) {
81                 char buf[1024];
82                 int j;
83
84                 be = &backendDB[i];
85
86                 snprintf( buf, sizeof( buf ),
87                                 "dn: cn=%d,%s\n"
88                                 "objectClass: top\n"
89                                 "objectClass: LDAPsubEntry\n"
90 #ifdef SLAPD_MONITORSUBENTRY
91                                 "objectClass: monitorSubEntry\n"
92 #else /* !SLAPD_MONITORSUBENTRY */
93                                 "objectClass: extensibleObject\n"
94 #endif /* !SLAPD_MONITORSUBENTRY */
95                                 "cn: %d\n",
96                                 i,
97                                 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_dn->bv_val,
98                                 i );
99                 
100                 e = str2entry( buf );
101                 if ( e == NULL ) {
102 #ifdef NEW_LOGGING
103                         LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
104                                 "monitor_subsys_database_init: "
105                                 "unable to create entry 'cn=%d,%s'\n",
106                                 i, 
107                                 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn->bv_val ));
108 #else
109                         Debug( LDAP_DEBUG_ANY,
110                                 "monitor_subsys_database_init: "
111                                 "unable to create entry 'cn=%d,%s'\n%s",
112                                 i, 
113                                 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn->bv_val,
114                                 "" );
115 #endif
116                         return( -1 );
117                 }
118                 
119                 val.bv_val = be->bd_info->bi_type;
120                 val.bv_len = strlen( val.bv_val );
121                 attr_merge( e, monitor_ad_desc, bv );
122                 
123                 for ( j = 0; be->be_suffix[j]; j++ ) {
124                         val = *be->be_suffix[j];
125
126                         attr_merge( e, ad_nc, bv );
127                         attr_merge( e_database, ad_nc, bv );
128                 }
129                                 
130                 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
131                 e->e_private = ( void * )mp;
132                 mp->mp_next = e_tmp;
133                 mp->mp_children = NULL;
134                 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_DATABASE];
135                 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_DATABASE].mss_flags
136                         | MONITOR_F_SUB;
137
138                 if ( monitor_cache_add( mi, e ) ) {
139 #ifdef NEW_LOGGING
140                         LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
141                                 "monitor_subsys_database_init: "
142                                 "unable to add entry 'cn=%d,%s'\n",
143                                 i, 
144                                 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn->bv_val ));
145 #else
146                         Debug( LDAP_DEBUG_ANY,
147                                 "monitor_subsys_database_init: "
148                                 "unable to add entry 'cn=%d,%s'\n",
149                                 i, 
150                                 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn->bv_val,
151                                 0 );
152 #endif
153                         return( -1 );
154                 }
155
156                 e_tmp = e;
157         }
158         
159         mp = ( struct monitorentrypriv * )e_database->e_private;
160         mp->mp_children = e_tmp;
161
162         monitor_cache_release( mi, e_database );
163
164         return( 0 );
165 }
166