]> git.sur5r.net Git - openldap/blob - servers/slapd/back-monitor/backend.c
+ Fixed slapd connectionless LDAP support
[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-2006 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         monitor_subsys_t        *ms
38 )
39 {
40         monitor_info_t          *mi;
41         Entry                   *e_backend, **ep;
42         int                     i;
43         monitor_entry_t         *mp;
44         monitor_subsys_t        *ms_database;
45         BackendInfo                     *bi;
46
47         mi = ( monitor_info_t * )be->be_private;
48
49         ms_database = monitor_back_get_subsys( SLAPD_MONITOR_DATABASE_NAME );
50         if ( ms_database == NULL ) {
51                 Debug( LDAP_DEBUG_ANY,
52                         "monitor_subsys_backend_init: "
53                         "unable to get "
54                         "\"" SLAPD_MONITOR_DATABASE_NAME "\" "
55                         "subsystem\n",
56                         0, 0, 0 );
57                 return -1;
58         }
59
60         if ( monitor_cache_get( mi, &ms->mss_ndn, &e_backend ) ) {
61                 Debug( LDAP_DEBUG_ANY,
62                         "monitor_subsys_backend_init: "
63                         "unable to get entry \"%s\"\n",
64                         ms->mss_ndn.bv_val, 0, 0 );
65                 return( -1 );
66         }
67
68         mp = ( monitor_entry_t * )e_backend->e_private;
69         mp->mp_children = NULL;
70         ep = &mp->mp_children;
71
72         i = -1;
73         LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next ) {
74                 char            buf[ BACKMONITOR_BUFSIZE ];
75                 BackendDB       *be;
76                 struct berval   bv;
77                 int             j;
78                 Entry           *e;
79
80                 i++;
81
82                 snprintf( buf, sizeof( buf ),
83                                 "dn: cn=Backend %d,%s\n"
84                                 "objectClass: %s\n"
85                                 "structuralObjectClass: %s\n"
86                                 "cn: Backend %d\n"
87                                 "%s: %s\n"
88                                 "%s: %s\n"
89                                 "creatorsName: %s\n"
90                                 "modifiersName: %s\n"
91                                 "createTimestamp: %s\n"
92                                 "modifyTimestamp: %s\n",
93                                 i,
94                                 ms->mss_dn.bv_val,
95                                 mi->mi_oc_monitoredObject->soc_cname.bv_val,
96                                 mi->mi_oc_monitoredObject->soc_cname.bv_val,
97                                 i,
98                                 mi->mi_ad_monitoredInfo->ad_cname.bv_val,
99                                         bi->bi_type,
100                                 mi->mi_ad_monitorRuntimeConfig->ad_cname.bv_val,
101                                         bi->bi_cf_ocs == NULL ? "FALSE" : "TRUE",
102                                 mi->mi_creatorsName.bv_val,
103                                 mi->mi_creatorsName.bv_val,
104                                 mi->mi_startTime.bv_val,
105                                 mi->mi_startTime.bv_val );
106                 
107                 e = str2entry( buf );
108                 if ( e == NULL ) {
109                         Debug( LDAP_DEBUG_ANY,
110                                 "monitor_subsys_backend_init: "
111                                 "unable to create entry \"cn=Backend %d,%s\"\n",
112                                 i, ms->mss_ndn.bv_val, 0 );
113                         return( -1 );
114                 }
115                 
116                 ber_str2bv( bi->bi_type, 0, 0, &bv );
117                 attr_merge_normalize_one( e_backend, mi->mi_ad_monitoredInfo,
118                                 &bv, NULL );
119
120                 if ( bi->bi_controls ) {
121                         int j;
122
123                         for ( j = 0; bi->bi_controls[ j ]; j++ ) {
124                                 ber_str2bv( bi->bi_controls[ j ], 0, 0, &bv );
125                                 attr_merge_one( e, slap_schema.si_ad_supportedControl,
126                                                 &bv, &bv );
127                         }
128                 }
129
130                 j = -1;
131                 LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
132                         char            buf[ SLAP_LDAPDN_MAXLEN ];
133                         struct berval   dn;
134                         
135                         j++;
136
137                         if ( be->bd_info != bi ) {
138                                 continue;
139                         }
140
141                         snprintf( buf, sizeof( buf ), "cn=Database %d,%s",
142                                         j, ms_database->mss_dn.bv_val );
143
144                         ber_str2bv( buf, 0, 0, &dn );
145                         attr_merge_normalize_one( e, slap_schema.si_ad_seeAlso,
146                                         &dn, NULL );
147                 }
148                 
149                 mp = monitor_entrypriv_create();
150                 if ( mp == NULL ) {
151                         return -1;
152                 }
153                 e->e_private = ( void * )mp;
154                 mp->mp_info = ms;
155                 mp->mp_flags = ms->mss_flags | MONITOR_F_SUB;
156
157                 if ( monitor_cache_add( mi, e ) ) {
158                         Debug( LDAP_DEBUG_ANY,
159                                 "monitor_subsys_backend_init: "
160                                 "unable to add entry \"cn=Backend %d,%s\"\n",
161                                 i,
162                                 ms->mss_ndn.bv_val, 0 );
163                         return( -1 );
164                 }
165
166                 *ep = e;
167                 ep = &mp->mp_next;
168         }
169         
170         monitor_cache_release( mi, e_backend );
171
172         return( 0 );
173 }
174