]> git.sur5r.net Git - openldap/blob - servers/slapd/back-monitor/listener.c
20695a664e8b9a8b814fee590f002ffe5c3720a1
[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 2001-2004 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 #include "portable.h"
23
24 #include <stdio.h>
25
26 #include "slap.h"
27 #include "back-monitor.h"
28
29 int
30 monitor_subsys_listener_init(
31         BackendDB       *be
32 )
33 {
34         struct monitorinfo      *mi;
35         Entry                   *e, *e_listener, *e_tmp;
36         int                     i;
37         struct monitorentrypriv *mp;
38         Listener                **l;
39
40         assert( be != NULL );
41
42         mi = ( struct monitorinfo * )be->be_private;
43
44         if ( monitor_cache_get( mi, 
45                                 &monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn, 
46                                 &e_listener ) ) {
47 #ifdef NEW_LOGGING
48                 LDAP_LOG( OPERATION, CRIT,
49                         "monitor_subsys_listener_init: "
50                         "unable to get entry '%s'\n",
51                         monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val, 0, 0 );
52 #else
53                 Debug( LDAP_DEBUG_ANY,
54                         "monitor_subsys_listener_init: "
55                         "unable to get entry '%s'\n%s%s",
56                         monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val, 
57                         "", "" );
58 #endif
59                 return( -1 );
60         }
61
62         if ( ( l = slapd_get_listeners() ) == NULL ) {
63 #ifdef NEW_LOGGING
64                 LDAP_LOG( OPERATION, CRIT,
65                         "monitor_subsys_listener_init: "
66                         "unable to get listeners\n", 0, 0, 0 );
67 #else
68                 Debug( LDAP_DEBUG_ANY,
69                         "monitor_subsys_listener_init: "
70                         "unable to get listeners\n", 0, 0, 0 );
71 #endif
72                 return( -1 );
73         }
74
75         e_tmp = NULL;
76         for ( i = 0; l[i]; i++ );
77         for ( ; i--; ) {
78                 char            buf[ BACKMONITOR_BUFSIZE ];
79
80                 snprintf( buf, sizeof( buf ),
81                                 "dn: cn=Listener %d,%s\n"
82                                 "objectClass: %s\n"
83                                 "structuralObjectClass: %s\n"
84                                 "cn: Listener %d\n"
85                                 "%s: %s\n"
86                                 "labeledURI: %s\n"
87                                 "creatorsName: %s\n"
88                                 "modifiersName: %s\n"
89                                 "createTimestamp: %s\n"
90                                 "modifyTimestamp: %s\n",
91                                 i,
92                                 monitor_subsys[SLAPD_MONITOR_LISTENER].mss_dn.bv_val,
93                                 mi->mi_oc_monitoredObject->soc_cname.bv_val,
94                                 mi->mi_oc_monitoredObject->soc_cname.bv_val,
95                                 i,
96                                 mi->mi_ad_monitorConnectionLocalAddress->ad_cname.bv_val,
97                                 l[i]->sl_name.bv_val,
98                                 l[i]->sl_url.bv_val,
99                                 mi->mi_creatorsName.bv_val,
100                                 mi->mi_creatorsName.bv_val,
101                                 mi->mi_startTime.bv_val,
102                                 mi->mi_startTime.bv_val );
103                 
104                 e = str2entry( buf );
105                 if ( e == NULL ) {
106 #ifdef NEW_LOGGING
107                         LDAP_LOG( OPERATION, CRIT,
108                                 "monitor_subsys_listener_init: "
109                                 "unable to create entry 'cn=Listener, %d,%s'\n",
110                                 i, monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val, 0 );
111 #else
112                         Debug( LDAP_DEBUG_ANY,
113                                 "monitor_subsys_listener_init: "
114                                 "unable to create entry 'cn=Listener %d,%s'\n%s",
115                                 i,
116                                 monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val,
117                                 "" );
118 #endif
119                         return( -1 );
120                 }
121
122 #ifdef HAVE_TLS
123                 if ( l[i]->sl_is_tls ) {
124                         struct berval bv;
125
126                         bv.bv_val = "TLS";
127                         bv.bv_len = sizeof("TLS")-1;
128
129                         attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo,
130                                         &bv, NULL );
131                 }
132 #endif /* HAVE_TLS */
133 #ifdef LDAP_CONNECTIONLESS
134                 if ( l[i]->sl_is_udp ) {
135                         struct berval bv;
136
137                         bv.bv_val = "UDP";
138                         bv.bv_len = sizeof("UDP")-1;
139
140                         attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo,
141                                         &bv, NULL );
142                 }
143 #endif /* HAVE_TLS */
144
145                 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
146                 e->e_private = ( void * )mp;
147                 mp->mp_next = e_tmp;
148                 mp->mp_children = NULL;
149                 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_LISTENER];
150                 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_LISTENER].mss_flags
151                         | MONITOR_F_SUB;
152
153                 if ( monitor_cache_add( mi, e ) ) {
154 #ifdef NEW_LOGGING
155                         LDAP_LOG( OPERATION, CRIT,
156                                 "monitor_subsys_listener_init: "
157                                 "unable to add entry 'cn=Listener %d,%s'\n",
158                                 i, monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val, 0 );
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