]> git.sur5r.net Git - openldap/blob - servers/slapd/back-monitor/listener.c
16d384c17a08913f5cc62d86395ba3167f73e99d
[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 #include "portable.h"
50
51 #include <stdio.h>
52
53 #include "slap.h"
54 #include "back-monitor.h"
55
56 int
57 monitor_subsys_listener_init(
58         BackendDB       *be
59 )
60 {
61         struct monitorinfo      *mi;
62         Entry                   *e, *e_listener, *e_tmp;
63         int                     i;
64         struct monitorentrypriv *mp;
65         Listener                **l;
66
67         assert( be != NULL );
68
69         mi = ( struct monitorinfo * )be->be_private;
70
71         if ( monitor_cache_get( mi, 
72                                 &monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn, 
73                                 &e_listener ) ) {
74 #ifdef NEW_LOGGING
75                 LDAP_LOG( OPERATION, CRIT,
76                         "monitor_subsys_listener_init: "
77                         "unable to get entry '%s'\n",
78                         monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val, 0, 0 );
79 #else
80                 Debug( LDAP_DEBUG_ANY,
81                         "monitor_subsys_listener_init: "
82                         "unable to get entry '%s'\n%s%s",
83                         monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val, 
84                         "", "" );
85 #endif
86                 return( -1 );
87         }
88
89         if ( ( l = slapd_get_listeners() ) == NULL ) {
90 #ifdef NEW_LOGGING
91                 LDAP_LOG( OPERATION, CRIT,
92                         "monitor_subsys_listener_init: "
93                         "unable to get listeners\n", 0, 0, 0 );
94 #else
95                 Debug( LDAP_DEBUG_ANY,
96                         "monitor_subsys_listener_init: "
97                         "unable to get listeners\n", 0, 0, 0 );
98 #endif
99                 return( -1 );
100         }
101
102         e_tmp = NULL;
103         for ( i = 0; l[i]; i++ );
104         for ( ; i--; ) {
105                 char            buf[ BACKMONITOR_BUFSIZE ];
106
107                 snprintf( buf, sizeof( buf ),
108                                 "dn: cn=Listener %d,%s\n"
109                                 "objectClass: %s\n"
110                                 "structuralObjectClass: %s\n"
111                                 "cn: Listener %d\n"
112                                 "%s: %s\n"
113                                 "labeledURI: %s\n"
114                                 "createTimestamp: %s\n"
115                                 "modifyTimestamp: %s\n",
116                                 i,
117                                 monitor_subsys[SLAPD_MONITOR_LISTENER].mss_dn.bv_val,
118                                 mi->mi_oc_monitoredObject->soc_cname.bv_val,
119                                 mi->mi_oc_monitoredObject->soc_cname.bv_val,
120                                 i,
121                                 mi->mi_ad_monitorConnectionLocalAddress->ad_cname.bv_val,
122                                 l[i]->sl_name.bv_val,
123                                 l[i]->sl_url.bv_val,
124                                 mi->mi_startTime.bv_val,
125                                 mi->mi_startTime.bv_val );
126                 
127                 e = str2entry( buf );
128                 if ( e == NULL ) {
129 #ifdef NEW_LOGGING
130                         LDAP_LOG( OPERATION, CRIT,
131                                 "monitor_subsys_listener_init: "
132                                 "unable to create entry 'cn=Listener, %d,%s'\n",
133                                 i, monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val, 0 );
134 #else
135                         Debug( LDAP_DEBUG_ANY,
136                                 "monitor_subsys_listener_init: "
137                                 "unable to create entry 'cn=Listener %d,%s'\n%s",
138                                 i,
139                                 monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val,
140                                 "" );
141 #endif
142                         return( -1 );
143                 }
144
145 #ifdef HAVE_TLS
146                 if ( l[i]->sl_is_tls ) {
147                         struct berval bv;
148
149                         bv.bv_val = "TLS";
150                         bv.bv_len = sizeof("TLS")-1;
151
152                         attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo,
153                                         &bv, NULL );
154                 }
155 #endif /* HAVE_TLS */
156 #ifdef LDAP_CONNECTIONLESS
157                 if ( l[i]->sl_is_udp ) {
158                         struct berval bv;
159
160                         bv.bv_val = "UDP";
161                         bv.bv_len = sizeof("UDP")-1;
162
163                         attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo,
164                                         &bv, NULL );
165                 }
166 #endif /* HAVE_TLS */
167
168                 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
169                 e->e_private = ( void * )mp;
170                 mp->mp_next = e_tmp;
171                 mp->mp_children = NULL;
172                 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_LISTENER];
173                 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_LISTENER].mss_flags
174                         | MONITOR_F_SUB;
175
176                 if ( monitor_cache_add( mi, e ) ) {
177 #ifdef NEW_LOGGING
178                         LDAP_LOG( OPERATION, CRIT,
179                                 "monitor_subsys_listener_init: "
180                                 "unable to add entry 'cn=Listener %d,%s'\n",
181                                 i, monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val, 0 );
182 #else
183                         Debug( LDAP_DEBUG_ANY,
184                                 "monitor_subsys_listener_init: "
185                                 "unable to add entry 'cn=Listener %d,%s'\n",
186                                 i,
187                                 monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val,
188                                 0 );
189 #endif
190                         return( -1 );
191                 }
192
193                 e_tmp = e;
194         }
195         
196         mp = ( struct monitorentrypriv * )e_listener->e_private;
197         mp->mp_children = e_tmp;
198
199         monitor_cache_release( mi, e_listener );
200
201         return( 0 );
202 }
203