Example #1
0
 def _getSession(self, client_stream, client_local, client_listen,
                 client_address):
     """
     <method internal="yes">
       <summary>Returns the service associated with the listener</summary>
       <description>
         <para>
           Returns the service to start.
         </para>
       </description>
       <metainfo>
         <arguments>
           <argument maturity="stable">
             <name>client_info</name>
             <type></type>
             <description>client_info reference</description>
           </argument>
         </arguments>
       </metainfo>
     </method>
     """
     return MasterSession(self.service,
                          client_stream,
                          client_local,
                          client_listen,
                          client_address,
                          instance_id=getInstanceId(self.service.name))
Example #2
0
    def _getSession(self, client_stream, client_local, client_listen,
                    client_address):
        """<method internal="yes">
        </method>
        """
        result = getKZorpResult(client_address.family, client_stream.fd)
        if result is None:
            ## LOG ##
            # This message indicates that the KZorp result
            # lookup has failed for this session.
            ##
            log(
                None, CORE_POLICY, 0,
                "Unable to determine service, KZorp service lookup failed; bindto='%s'",
                (self.bindto[0], ))
            return None

        (client_zone_name, server_zone_name, dispatcher_name, service_name,
         rule_id) = result
        service = Globals.services.get(service_name)
        client_zone = Zone.lookupByName(client_zone_name)
        server_zone = Zone.lookupByName(server_zone_name)

        return MasterSession(service,
                             client_stream,
                             client_local,
                             client_listen,
                             client_address,
                             client_zone=client_zone,
                             server_zone=server_zone,
                             rule_id=rule_id,
                             instance_id=getInstanceId(service.name))
Example #3
0
File: APR.py Project: erdoukki/zorp
    def startService(self, service):
        session = MasterSession(service=service,
                                client_stream=self.session.client_stream,
                                client_local=self.session.client_local,
                                client_listen=self.session.client_listen,
                                client_address=self.session.client_address)

        BaseDispatch.startService(service, session)
Example #4
0
    def startService(self, service):
        session = MasterSession(service=service,
                                client_stream=self.session.client_stream,
                                client_local=self.session.client_local,
                                client_listen=self.session.client_listen,
                                client_address=self.session.client_address,
                                instance_id=getInstanceId(service.name))

        BaseDispatch.startService(service, session)
Example #5
0
    def accepted(self, stream, client_address, client_local, client_listen):
        """
        <method internal="yes">
          <summary>Callback to inform the python layer about incoming connections.</summary>
          <description>
            <para>
              This callback is called by the core when a connection is
              accepted. Its primary function is to check access control
              (whether the client is permitted to connect to this port),
              and to spawn a new session to handle the connection.
            </para>
            <para>
              Exceptions raised due to policy violations are handled here.
              Returns TRUE if the connection is accepted
            </para>
          </description>
          <metainfo>
            <arguments>
              <argument maturity="stable">
                <name>stream</name>
                <type></type>
                <description>the stream of the connection to the client</description>
              </argument>
              <argument maturity="stable">
                <name>client_address</name>
                <type></type>
                <description>the address of the client</description>
              </argument>
              <argument maturity="stable">
                <name>client_local</name>
                <type></type>
                <description>client local address (contains the original destination if transparent)</description>
              </argument>
              <argument maturity="stable">
                <name>client_listen</name>
                <type></type>
                <description>the address where the listener was bound to</description>
              </argument>
            </arguments>
          </metainfo>
        </method>
        """
        if stream == None:
            return None
        session = None
        try:
            session = MasterSession()
            session.setProtocol(client_listen.protocol)
            stream.name = session.session_id
            session.client_stream = stream
            session.client_local = client_local
            session.client_listen = client_listen
            session.setClientAddress(client_address)

            service = self.getService(session)
            if not service:
                raise DACException, "No applicable service found"
            session.setService(service)

            service.router.routeConnection(session)

            ## LOG ##
            # This message indicates that a new connection is accepted.
            ##
            log(session.session_id, CORE_DEBUG, 8,
                "Connection accepted; client_address='%s'", (client_address, ))
            sys.exc_clear()
            stream.keepalive = service.keepalive & Z_KEEPALIVE_CLIENT
            if session.service.startInstance(session):
                return TRUE

        except ZoneException, s:
            ## LOG ##
            # This message indicates that no appropriate zone was found for the client address.
            # @see: Zone
            ##
            log(session.session_id, CORE_POLICY, 1,
                "Zone not found; info='%s'", (s, ))
Example #6
0
    def _getSession(self, client_stream, client_local, client_listen,
                    client_address):
        """
        <method internal="yes">
          <summary>Virtual function which returns the service to be ran</summary>
          <description>
            <para>
              This function is called by our base class to find out the
              service to be used. It uses the client zone name to decide
              which service to use.
            </para>
          </description>
          <metainfo>
            <arguments>
              <argument maturity="stable">
                <name>client_info</name>
                <type></type>
                <description>Session information</description>
              </argument>
            </arguments>
          </metainfo>
        </method>
        """

        client_zone = Zone.lookup(client_address)
        cache_ndx = client_zone.getName()

        cached = self.cache.lookup(cache_ndx)
        if cached == 0:
            ## LOG ##
            # This message indicates that no applicable service was found for this client zone in the services cache.
            # It is likely that there is no applicable service configured in this ZoneDispatcher at all.
            # Check your ZoneDispatcher service configuration.
            # @see: Dispatcher.ZoneDispatcher
            ##
            log(
                None, CORE_POLICY, 2,
                "No applicable service found for this client zone (cached); bindto='%s', client_zone='%s'",
                (self.bindto, client_zone))
        elif cached:
            return MasterSession(cached,
                                 client_stream,
                                 client_local,
                                 client_listen,
                                 client_address,
                                 client_zone=client_zone,
                                 instance_id=getInstanceId(cached.name))

        src_hierarchy = {}
        if self.follow_parent:
            z = client_zone
            level = 0
            while z:
                src_hierarchy[z.getName()] = level
                z = z.admin_parent
                level = level + 1
            src_hierarchy['*'] = level
            max_level = level + 1
        else:
            src_hierarchy[client_zone.getName()] = 0
            src_hierarchy['*'] = 1
            max_level = 10

        best = None
        for spec in self.services.keys():
            try:
                src_level = src_hierarchy[spec]
            except KeyError:
                src_level = max_level

            if not best or                                                  \
               (best_src_level > src_level):
                best = self.services[spec]
                best_src_level = src_level

        service = None
        if best is not None and best_src_level < max_level:
            try:
                service = Globals.services[best]
            except KeyError:
                log(None, CORE_POLICY, 2, "No such service; service='%s'",
                    (best))

        else:
            ## LOG ##
            # This message indicates that no applicable service was found for this client zone.
            # Check your ZoneDispatcher service configuration.
            # @see: Dispatcher.ZoneDispatcher
            ##
            log(
                None, CORE_POLICY, 2,
                "No applicable service found for this client zone; bindto='%s', client_zone='%s'",
                (self.bindto, client_zone))

        if service is None:
            return None

        self.cache.store(cache_ndx, service)
        return MasterSession(service,
                             client_stream,
                             client_local,
                             client_listen,
                             client_address,
                             client_zone=client_zone,
                             instance_id=getInstanceId(service.name))
Example #7
0
    def accepted(self, stream, client_address, client_local, client_listen):
        """
        <method internal="yes">
          <summary>Callback to inform the python layer about incoming connections.</summary>
          <description>
            <para>
              This callback is called by the core when a connection is
              accepted. Its primary function is to check access control
              (whether the client is permitted to connect to this port),
              and to spawn a new session to handle the connection.
            </para>
            <para>
              Exceptions raised due to policy violations are handled here.
              Returns TRUE if the connection is accepted
            </para>
          </description>
          <metainfo>
            <arguments>
              <argument maturity="stable">
                <name>stream</name>
                <type></type>
                <description>the stream of the connection to the client</description>
              </argument>
              <argument maturity="stable">
                <name>client_address</name>
                <type></type>
                <description>the address of the client</description>
              </argument>
              <argument maturity="stable">
                <name>client_local</name>
                <type></type>
                <description>client local address (contains the original destination if transparent)</description>
              </argument>
              <argument maturity="stable">
                <name>client_listen</name>
                <type></type>
                <description>the address where the listener was bound to</description>
              </argument>
            </arguments>
          </metainfo>
        </method>
        """
        if stream == None:
            return None
        session = None
        try:
            session = MasterSession()
            session.setProtocol(client_listen.protocol)
            stream.name = session.session_id
            session.client_stream = stream
            session.client_local = client_local
            session.client_listen = client_listen
            session.setClientAddress(client_address)

            service = self.getService(session)
            if not service:
                raise DACException, "No applicable service found"
            session.setService(service)

            service.router.routeConnection(session)

            ## LOG ##
            # This message indicates that a new connection is accepted.
            ##
            log(session.session_id, CORE_DEBUG, 8, "Connection accepted; client_address='%s'", (client_address,))
            sys.exc_clear()
            stream.keepalive = service.keepalive & Z_KEEPALIVE_CLIENT;
            if session.service.startInstance(session):
                return TRUE

        except ZoneException, s:
            ## LOG ##
            # This message indicates that no appropriate zone was found for the client address.
            # @see: Zone
            ##
            log(session.session_id, CORE_POLICY, 1, "Zone not found; info='%s'", (s,))