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