]> git.sur5r.net Git - openldap/blob - servers/slapd/back-monitor/listener.c
Added ppolicy_hide_lockout keyword
[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                                 "createTimestamp: %s\n"
88                                 "modifyTimestamp: %s\n",
89                                 i,
90                                 monitor_subsys[SLAPD_MONITOR_LISTENER].mss_dn.bv_val,
91                                 mi->mi_oc_monitoredObject->soc_cname.bv_val,
92                                 mi->mi_oc_monitoredObject->soc_cname.bv_val,
93                                 i,
94                                 mi->mi_ad_monitorConnectionLocalAddress->ad_cname.bv_val,
95                                 l[i]->sl_name.bv_val,
96                                 l[i]->sl_url.bv_val,
97                                 mi->mi_startTime.bv_val,
98                                 mi->mi_startTime.bv_val );
99                 
100                 e = str2entry( buf );
101                 if ( e == NULL ) {
102 #ifdef NEW_LOGGING
103                         LDAP_LOG( OPERATION, CRIT,
104                                 "monitor_subsys_listener_init: "
105                                 "unable to create entry 'cn=Listener, %d,%s'\n",
106                                 i, monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val, 0 );
107 #else
108                         Debug( LDAP_DEBUG_ANY,
109                                 "monitor_subsys_listener_init: "
110                                 "unable to create entry 'cn=Listener %d,%s'\n%s",
111                                 i,
112                                 monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val,
113                                 "" );
114 #endif
115                         return( -1 );
116                 }
117
118 #ifdef HAVE_TLS
119                 if ( l[i]->sl_is_tls ) {
120                         struct berval bv;
121
122                         bv.bv_val = "TLS";
123                         bv.bv_len = sizeof("TLS")-1;
124
125                         attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo,
126                                         &bv, NULL );
127                 }
128 #endif /* HAVE_TLS */
129 #ifdef LDAP_CONNECTIONLESS
130                 if ( l[i]->sl_is_udp ) {
131                         struct berval bv;
132
133                         bv.bv_val = "UDP";
134                         bv.bv_len = sizeof("UDP")-1;
135
136                         attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo,
137                                         &bv, NULL );
138                 }
139 #endif /* HAVE_TLS */
140
141                 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
142                 e->e_private = ( void * )mp;
143                 mp->mp_next = e_tmp;
144                 mp->mp_children = NULL;
145                 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_LISTENER];
146                 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_LISTENER].mss_flags
147                         | MONITOR_F_SUB;
148
149                 if ( monitor_cache_add( mi, e ) ) {
150 #ifdef NEW_LOGGING
151                         LDAP_LOG( OPERATION, CRIT,
152                                 "monitor_subsys_listener_init: "
153                                 "unable to add entry 'cn=Listener %d,%s'\n",
154                                 i, monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val, 0 );
155 #else
156                         Debug( LDAP_DEBUG_ANY,
157                                 "monitor_subsys_listener_init: "
158                                 "unable to add entry 'cn=Listener %d,%s'\n",
159                                 i,
160                                 monitor_subsys[SLAPD_MONITOR_LISTENER].mss_ndn.bv_val,
161                                 0 );
162 #endif
163                         return( -1 );
164                 }
165
166                 e_tmp = e;
167         }
168         
169         mp = ( struct monitorentrypriv * )e_listener->e_private;
170         mp->mp_children = e_tmp;
171
172         monitor_cache_release( mi, e_listener );
173
174         return( 0 );
175 }
176