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