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