]> git.sur5r.net Git - openldap/blob - servers/slapd/back-monitor/backend.c
0d5ae841d82683309e0a757339b979761519a002
[openldap] / servers / slapd / back-monitor / backend.c
1 /* backend.c - deals with backend 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
38 #include "portable.h"
39
40 #include <stdio.h>
41
42 #include "slap.h"
43 #include "back-monitor.h"
44
45 /*
46  * initializes backend subentries
47  */
48 int
49 monitor_subsys_backend_init(
50         BackendDB       *be
51 )
52 {
53         struct monitorinfo      *mi;
54         Entry                   *e, *e_backend, *e_tmp;
55         int                     i;
56         struct monitorentrypriv *mp;
57         struct berval           bv[2];
58
59         mi = ( struct monitorinfo * )be->be_private;
60
61         if ( monitor_cache_get( mi, 
62                                 &monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn, 
63                                 &e_backend ) ) {
64 #ifdef NEW_LOGGING
65                 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
66                         "monitor_subsys_backend_init: "
67                         "unable to get entry '%s'\n",
68                         monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val ));
69 #else
70                 Debug( LDAP_DEBUG_ANY,
71                         "monitor_subsys_backend_init: "
72                         "unable to get entry '%s'\n%s%s",
73                         monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val, 
74                         "", "" );
75 #endif
76                 return( -1 );
77         }
78
79         bv[1].bv_val = NULL;
80         e_tmp = NULL;
81         for ( i = nBackendInfo; i--; ) {
82                 char buf[1024];
83                 BackendInfo *bi;
84
85                 bi = &backendInfo[i];
86
87                 snprintf( buf, sizeof( buf ),
88                                 "dn: cn=%d,%s\n"
89                                 "objectClass: top\n"
90                                 "objectClass: LDAPsubEntry\n"
91 #ifdef SLAPD_MONITORSUBENTRY
92                                 "objectClass: monitorSubEntry\n"
93 #else /* !SLAPD_MONITORSUBENTRY */
94                                 "objectClass: extensibleObject\n"
95 #endif /* !SLAPD_MONITORSUBENTRY */
96                                 "cn: %d\n",
97                                 i,
98                                 monitor_subsys[SLAPD_MONITOR_BACKEND].mss_dn.bv_val,
99                                 i );
100                 
101                 e = str2entry( buf );
102                 if ( e == NULL ) {
103 #ifdef NEW_LOGGING
104                         LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
105                                 "monitor_subsys_backend_init: "
106                                 "unable to create entry 'cn=%d,%s'\n",
107                                 i, 
108                                 monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val ));
109 #else
110                         Debug( LDAP_DEBUG_ANY,
111                                 "monitor_subsys_backend_init: "
112                                 "unable to create entry 'cn=%d,%s'\n%s",
113                                 i, 
114                                 monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val,
115                                 "" );
116 #endif
117                         return( -1 );
118                 }
119                 
120                 bv[0].bv_val = bi->bi_type;
121                 bv[0].bv_len = strlen( bv[0].bv_val );
122
123                 attr_merge( e, monitor_ad_desc, bv );
124                 attr_merge( e_backend, monitor_ad_desc, bv );
125                 
126                 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
127                 e->e_private = ( void * )mp;
128                 mp->mp_next = e_tmp;
129                 mp->mp_children = NULL;
130                 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_BACKEND];
131                 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_BACKEND].mss_flags
132                         | MONITOR_F_SUB;
133
134                 if ( monitor_cache_add( mi, e ) ) {
135 #ifdef NEW_LOGGING
136                         LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
137                                 "monitor_subsys_backend_init: "
138                                 "unable to add entry 'cn=%d,%s'\n",
139                                 i,
140                                 monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val ));
141 #else
142                         Debug( LDAP_DEBUG_ANY,
143                                 "monitor_subsys_backend_init: "
144                                 "unable to add entry 'cn=%d,%s'\n%s",
145                                 i,
146                                 monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn.bv_val,
147                                 "" );
148 #endif
149                         return( -1 );
150                 }
151
152                 e_tmp = e;
153         }
154         
155         mp = ( struct monitorentrypriv * )e_backend->e_private;
156         mp->mp_children = e_tmp;
157
158         monitor_cache_release( mi, e_backend );
159
160         return( 0 );
161 }
162