]> git.sur5r.net Git - openldap/blob - servers/slapd/back-monitor/listener.c
6d8fd280991b48bccabf5ff1d25b824805755717
[openldap] / servers / slapd / back-monitor / listener.c
1 /* listener.c - deals with listener subsystem */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 1998-2003 The OpenLDAP Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
12  * A copy of this license is available in file LICENSE in the
13  * top-level directory of the distribution or, alternatively, at
14  * <http://www.OpenLDAP.org/license.html>.
15  */
16 /* ACKNOWLEDGEMENTS:
17  * This work was initially developed by Pierangelo Masarati for inclusion
18  * in OpenLDAP Software.
19  */
20 /* This is an altered version */
21 /*
22  * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
23  * 
24  * This work has beed deveolped for the OpenLDAP Foundation 
25  * in the hope that it may be useful to the Open Source community, 
26  * but WITHOUT ANY WARRANTY.
27  * 
28  * Permission is granted to anyone to use this software for any purpose
29  * on any computer system, and to alter it and redistribute it, subject
30  * to the following restrictions:
31  * 
32  * 1. The author and SysNet s.n.c. are not responsible for the consequences
33  *    of use of this software, no matter how awful, even if they arise from
34  *    flaws in it.
35  * 
36  * 2. The origin of this software must not be misrepresented, either by
37  *    explicit claim or by omission.  Since few users ever read sources,
38  *    credits should appear in the documentation.
39  * 
40  * 3. Altered versions must be plainly marked as such, and must not be
41  *    misrepresented as being the original software.  Since few users
42  *    ever read sources, credits should appear in the documentation.
43  *    SysNet s.n.c. cannot be responsible for the consequences of the
44  *    alterations.
45  * 
46  * 4. This notice may not be removed or altered.
47  */
48
49 #ifndef _BACK_MONITOR_H_
50 #define _BACK_MONITOR_H_
51
52 #include <ldap_pvt.h>
53 #include <ldap_pvt_thread.h>
54 #include <avl.h>
55 #include <slap.h>
56
57 LDAP_BEGIN_DECL
58
59 /*
60  * The cache maps DNs to Entries.
61 /*
62  * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
63  * 
64  * This work has beed deveolped for the OpenLDAP Foundation 
65  * in the hope that it may be useful to the Open Source community, 
66  * but WITHOUT ANY WARRANTY.
67  * 
68  * Permission is granted to anyone to use this software for any purpose
69  * on any computer system, and to alter it and redistribute it, subject
70  * to the following restrictions:
71  * 
72  * 1. The author and SysNet s.n.c. are not responsible for the consequences
73  *    of use of this software, no matter how awful, even if they arise from
74  *    flaws in it.
75  * 
76  * 2. The origin of this software must not be misrepresented, either by
77  *    explicit claim or by omission.  Since few users ever read sources,
78  *    credits should appear in the documentation.
79  * 
80  * 3. Altered versions must be plainly marked as such, and must not be
81  *    misrepresented as being the original software.  Since few users
82  *    ever read sources, credits should appear in the documentation.
83  *    SysNet s.n.c. cannot be responsible for the consequences of the
84  *    alterations.
85  * 
86  * 4. This notice may not be removed or altered.
87  */
88
89 #include "portable.h"
90
91 #include <stdio.h>
92
93 #include "slap.h"
94 #include "back-monitor.h"
95
96 int
97 monitor_subsys_listener_init(
98         BackendDB       *be
99 )
100 {
101         struct monitorinfo      *mi;
102         Entry                   *e, *e_listener, *e_tmp;
103         int                     i;
104         struct monitorentrypriv *mp;
105         Listener                **l;
106
107         assert( be != NULL );
108
109         mi = ( struct monitorinfo * )be->be_private;
110
111         if ( monitor_cache_get( mi, 
112                                 &monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn, 
113                                 &e_listener ) ) {
114 #ifdef NEW_LOGGING
115                 LDAP_LOG( OPERATION, CRIT,
116                         "monitor_subsys_listener_init: "
117                         "unable to get entry '%s'\n",
118                         monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val, 0, 0 );
119 #else
120                 Debug( LDAP_DEBUG_ANY,
121                         "monitor_subsys_listener_init: "
122                         "unable to get entry '%s'\n%s%s",
123                         monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val, 
124                         "", "" );
125 #endif
126                 return( -1 );
127         }
128
129         if ( ( l = slapd_get_listeners() ) == NULL ) {
130 #ifdef NEW_LOGGING
131                 LDAP_LOG( OPERATION, CRIT,
132                         "monitor_subsys_listener_init: "
133                         "unable to get listeners\n", 0, 0, 0 );
134 #else
135                 Debug( LDAP_DEBUG_ANY,
136                         "monitor_subsys_listener_init: "
137                         "unable to get listeners\n", 0, 0, 0 );
138 #endif
139                 return( -1 );
140         }
141
142         e_tmp = NULL;
143         for ( i = 0; l[i]; i++ );
144         for ( ; i--; ) {
145                 char            buf[ BACKMONITOR_BUFSIZE ];
146
147                 snprintf( buf, sizeof( buf ),
148                                 "dn: cn=Listener %d,%s\n"
149                                 "objectClass: %s\n"
150                                 "structuralObjectClass: %s\n"
151                                 "cn: Listener %d\n"
152                                 "%s: %s\n"
153                                 "labeledURI: %s\n"
154                                 "createTimestamp: %s\n"
155                                 "modifyTimestamp: %s\n",
156                                 i,
157                                 monitor_subsys[SLAPD_MONITOR_LISTENER].mss_dn.bv_val,
158                                 mi->mi_oc_monitoredObject->soc_cname.bv_val,
159                                 mi->mi_oc_monitoredObject->soc_cname.bv_val,
160                                 i,
161                                 mi->mi_ad_monitorConnectionLocalAddress->ad_cname.bv_val,
162                                 l[i]->sl_name.bv_val,
163                                 l[i]->sl_url.bv_val,
164                                 mi->mi_startTime.bv_val,
165                                 mi->mi_startTime.bv_val );
166                 
167                 e = str2entry( buf );
168                 if ( e == NULL ) {
169 #ifdef NEW_LOGGING
170                         LDAP_LOG( OPERATION, CRIT,
171                                 "monitor_subsys_listener_init: "
172                                 "unable to create entry 'cn=Listener, %d,%s'\n",
173                                 i, monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val, 0 );
174 #else
175                         Debug( LDAP_DEBUG_ANY,
176                                 "monitor_subsys_listener_init: "
177                                 "unable to create entry 'cn=Listener %d,%s'\n%s",
178                                 i,
179                                 monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val,
180                                 "" );
181 #endif
182                         return( -1 );
183                 }
184
185 #ifdef HAVE_TLS
186                 if ( l[i]->sl_is_tls ) {
187                         struct berval bv;
188
189                         bv.bv_val = "TLS";
190                         bv.bv_len = sizeof("TLS")-1;
191
192                         attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo,
193                                         &bv, NULL );
194                 }
195 #endif /* HAVE_TLS */
196 #ifdef LDAP_CONNECTIONLESS
197                 if ( l[i]->sl_is_udp ) {
198                         struct berval bv;
199
200                         bv.bv_val = "UDP";
201                         bv.bv_len = sizeof("UDP")-1;
202
203                         attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo,
204                                         &bv, NULL );
205                 }
206 #endif /* HAVE_TLS */
207
208                 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
209                 e->e_private = ( void * )mp;
210                 mp->mp_next = e_tmp;
211                 mp->mp_children = NULL;
212                 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_LISTENER];
213                 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_LISTENER].mss_flags
214                         | MONITOR_F_SUB;
215
216                 if ( monitor_cache_add( mi, e ) ) {
217 #ifdef NEW_LOGGING
218                         LDAP_LOG( OPERATION, CRIT,
219                                 "monitor_subsys_listener_init: "
220                                 "unable to add entry 'cn=Listener %d,%s'\n",
221                                 i, monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val, 0 );
222 #else
223                         Debug( LDAP_DEBUG_ANY,
224                                 "monitor_subsys_listener_init: "
225                                 "unable to add entry 'cn=Listener %d,%s'\n",
226                                 i,
227                                 monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val,
228                                 0 );
229 #endif
230                         return( -1 );
231                 }
232
233                 e_tmp = e;
234         }
235         
236         mp = ( struct monitorentrypriv * )e_listener->e_private;
237         mp->mp_children = e_tmp;
238
239         monitor_cache_release( mi, e_listener );
240
241         return( 0 );
242 }
243