Back to index

openldap  2.4.31
listener.c
Go to the documentation of this file.
00001 /* listener.c - deals with listener subsystem */
00002 /* $OpenLDAP$ */
00003 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00004  *
00005  * Copyright 2001-2012 The OpenLDAP Foundation.
00006  * Portions Copyright 2001-2003 Pierangelo Masarati.
00007  * All rights reserved.
00008  *
00009  * Redistribution and use in source and binary forms, with or without
00010  * modification, are permitted only as authorized by the OpenLDAP
00011  * Public License.
00012  *
00013  * A copy of this license is available in file LICENSE in the
00014  * top-level directory of the distribution or, alternatively, at
00015  * <http://www.OpenLDAP.org/license.html>.
00016  */
00017 /* ACKNOWLEDGEMENTS:
00018  * This work was initially developed by Pierangelo Masarati for inclusion
00019  * in OpenLDAP Software.
00020  */
00021 
00022 #include "portable.h"
00023 
00024 #include <stdio.h>
00025 #include <ac/string.h>
00026 
00027 #include "slap.h"
00028 #include "back-monitor.h"
00029 
00030 int
00031 monitor_subsys_listener_init(
00032        BackendDB            *be,
00033        monitor_subsys_t     *ms
00034 )
00035 {
00036        monitor_info_t       *mi;
00037        Entry         *e_listener, **ep;
00038        int           i;
00039        monitor_entry_t      *mp;
00040        Listener      **l;
00041 
00042        assert( be != NULL );
00043 
00044        if ( ( l = slapd_get_listeners() ) == NULL ) {
00045               if ( slapMode & SLAP_TOOL_MODE ) {
00046                      return 0;
00047               }
00048 
00049               Debug( LDAP_DEBUG_ANY,
00050                      "monitor_subsys_listener_init: "
00051                      "unable to get listeners\n", 0, 0, 0 );
00052               return( -1 );
00053        }
00054 
00055        mi = ( monitor_info_t * )be->be_private;
00056 
00057        if ( monitor_cache_get( mi, &ms->mss_ndn, &e_listener ) ) {
00058               Debug( LDAP_DEBUG_ANY,
00059                      "monitor_subsys_listener_init: "
00060                      "unable to get entry \"%s\"\n",
00061                      ms->mss_ndn.bv_val, 0, 0 );
00062               return( -1 );
00063        }
00064 
00065        mp = ( monitor_entry_t * )e_listener->e_private;
00066        mp->mp_children = NULL;
00067        ep = &mp->mp_children;
00068 
00069        for ( i = 0; l[ i ]; i++ ) {
00070               char          buf[ BACKMONITOR_BUFSIZE ];
00071               Entry         *e;
00072               struct berval bv;
00073 
00074               bv.bv_len = snprintf( buf, sizeof( buf ),
00075                             "cn=Listener %d", i );
00076               bv.bv_val = buf;
00077               e = monitor_entry_stub( &ms->mss_dn, &ms->mss_ndn, &bv,
00078                      mi->mi_oc_monitoredObject, mi, NULL, NULL );
00079 
00080               if ( e == NULL ) {
00081                      Debug( LDAP_DEBUG_ANY,
00082                             "monitor_subsys_listener_init: "
00083                             "unable to create entry \"cn=Listener %d,%s\"\n",
00084                             i, ms->mss_ndn.bv_val, 0 );
00085                      return( -1 );
00086               }
00087 
00088               attr_merge_normalize_one( e, mi->mi_ad_monitorConnectionLocalAddress,
00089                             &l[ i ]->sl_name, NULL );
00090 
00091               attr_merge_normalize_one( e, slap_schema.si_ad_labeledURI,
00092                             &l[ i ]->sl_url, NULL );
00093 
00094 #ifdef HAVE_TLS
00095               if ( l[ i ]->sl_is_tls ) {
00096                      struct berval bv;
00097 
00098                      BER_BVSTR( &bv, "TLS" );
00099                      attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo,
00100                                    &bv, NULL );
00101               }
00102 #endif /* HAVE_TLS */
00103 #ifdef LDAP_CONNECTIONLESS
00104               if ( l[ i ]->sl_is_udp ) {
00105                      struct berval bv;
00106 
00107                      BER_BVSTR( &bv, "UDP" );
00108                      attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo,
00109                                    &bv, NULL );
00110               }
00111 #endif /* HAVE_TLS */
00112 
00113               mp = monitor_entrypriv_create();
00114               if ( mp == NULL ) {
00115                      return -1;
00116               }
00117               e->e_private = ( void * )mp;
00118               mp->mp_info = ms;
00119               mp->mp_flags = ms->mss_flags
00120                      | MONITOR_F_SUB;
00121 
00122               if ( monitor_cache_add( mi, e ) ) {
00123                      Debug( LDAP_DEBUG_ANY,
00124                             "monitor_subsys_listener_init: "
00125                             "unable to add entry \"cn=Listener %d,%s\"\n",
00126                             i, ms->mss_ndn.bv_val, 0 );
00127                      return( -1 );
00128               }
00129 
00130               *ep = e;
00131               ep = &mp->mp_next;
00132        }
00133        
00134        monitor_cache_release( mi, e_listener );
00135 
00136        return( 0 );
00137 }
00138