]> git.sur5r.net Git - openldap/blob - servers/slapd/back-monitor/listener.c
Set peeraddr also for IPv6, fixes ITS#1918
[openldap] / servers / slapd / back-monitor / listener.c
1 /* listener.c - deals with listener 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 #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         assert( monitor_ad_desc != NULL );
54
55         mi = ( struct monitorinfo * )be->be_private;
56
57         if ( monitor_cache_get( mi, 
58                                 &monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn, 
59                                 &e_listener ) ) {
60 #ifdef NEW_LOGGING
61                 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
62                         "monitor_subsys_listener_init: "
63                         "unable to get entry '%s'\n",
64                         monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val ));
65 #else
66                 Debug( LDAP_DEBUG_ANY,
67                         "monitor_subsys_listener_init: "
68                         "unable to get entry '%s'\n%s%s",
69                         monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val, 
70                         "", "" );
71 #endif
72                 return( -1 );
73         }
74
75         if ( ( l = slapd_get_listeners() ) == NULL ) {
76 #ifdef NEW_LOGGING
77                 LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
78                         "monitor_subsys_listener_init: "
79                         "unable to get listeners\n" ));
80 #else
81                 Debug( LDAP_DEBUG_ANY,
82                         "monitor_subsys_listener_init: "
83                         "unable to get listeners\n", 0, 0, 0 );
84 #endif
85                 return( -1 );
86         }
87
88         e_tmp = NULL;
89         for ( i = 0; l[i]; i++ );
90         for ( ; i--; ) {
91                 char            buf[1024];
92
93                 snprintf( buf, sizeof( buf ),
94                                 "dn: cn=Listener %d,%s\n"
95                                 SLAPD_MONITOR_OBJECTCLASSES
96                                 "cn: Listener %d\n"
97                                 "description: %s\n"
98                                 "labeledURI: %s",
99                                 i,
100                                 monitor_subsys[SLAPD_MONITOR_LISTENER].mss_dn.bv_val,
101                                 i,
102                                 l[i]->sl_name,
103
104                                 l[i]->sl_url );
105                 
106                 e = str2entry( buf );
107                 if ( e == NULL ) {
108 #ifdef NEW_LOGGING
109                         LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
110                                 "monitor_subsys_listener_init: "
111                                 "unable to create entry 'cn=Listener, %d,%s'\n",
112                                 i,
113                                 monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val ));
114 #else
115                         Debug( LDAP_DEBUG_ANY,
116                                 "monitor_subsys_listener_init: "
117                                 "unable to create entry 'cn=Listener %d,%s'\n%s",
118                                 i,
119                                 monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val,
120                                 "" );
121 #endif
122                         return( -1 );
123                 }
124
125 #ifdef HAVE_TLS
126                 if ( l[i]->sl_is_tls ) {
127                         struct berval bv[2];
128                         bv[1].bv_val = NULL;
129                         bv[0].bv_val = "TLS";
130                         bv[0].bv_len = sizeof("TLS")-1;
131                         attr_merge( e, monitor_ad_desc, bv );
132                 }
133 #endif /* HAVE_TLS */
134 #ifdef LDAP_CONNECTIONLESS
135                 if ( l[i]->sl_is_udp ) {
136                         struct berval bv[2];
137                         bv[1].bv_val = NULL;
138                         bv[0].bv_val = "UDP";
139                         bv[0].bv_len = sizeof("UDP")-1;
140                         attr_merge( e, monitor_ad_desc, bv );
141                 }
142 #endif /* HAVE_TLS */
143
144                 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
145                 e->e_private = ( void * )mp;
146                 mp->mp_next = e_tmp;
147                 mp->mp_children = NULL;
148                 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_LISTENER];
149                 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_LISTENER].mss_flags
150                         | MONITOR_F_SUB;
151
152                 if ( monitor_cache_add( mi, e ) ) {
153 #ifdef NEW_LOGGING
154                         LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
155                                 "monitor_subsys_listener_init: "
156                                 "unable to add entry 'cn=Listener %d,%s'\n",
157                                 i,
158                                 monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val ));
159 #else
160                         Debug( LDAP_DEBUG_ANY,
161                                 "monitor_subsys_listener_init: "
162                                 "unable to add entry 'cn=Listener %d,%s'\n",
163                                 i,
164                                 monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val,
165                                 0 );
166 #endif
167                         return( -1 );
168                 }
169
170                 e_tmp = e;
171         }
172         
173         mp = ( struct monitorentrypriv * )e_listener->e_private;
174         mp->mp_children = e_tmp;
175
176         monitor_cache_release( mi, e_listener );
177
178         return( 0 );
179 }
180