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