コード例 #1
0
ファイル: Chainer.py プロジェクト: kkovaacs/zorp
    def chainParent(self, session):
        """
                <method internal="yes">
                  <summary>
                    Overridden function to perform chaining.
                  </summary>
                  <description>
                    <para>
                      This function is called by a Proxy instance to establish its
                      server side connection. Instead of connecting to a server
                      this chainer creates another proxy instance and connects
                      this new proxy with the current one.
                    </para>
                  </description>
                  <metainfo>
                    <arguments>
                      <argument maturity="stable">
                        <name>session</name>
                        <type>SESSION</type>
                        <description>session we belong to</description>
                      </argument>
                    </arguments>
                  </metainfo>
                </method>
		"""
        try:
            streams = streamPair(AF_UNIX, SOCK_STREAM)
        except IOError:
            ## LOG ##
            # This message indicates that side stacking failed, because Zorp was unable to create a socketPair.
            # It is likely that there is now resource available. Try increase fd limits.
            ##
            log(session.session_id, CORE_SESSION, 3,
                "Side stacking failed, socketPair failed;")
            return None

        try:
            # convert our tuple to an array, to make it possible
            # to modify items
            streams = [streams[0], streams[1]]
            ss = None

            session.server_stream = streams[0]
            session.server_stream.name = session.owner.session_id + "/leftside"
            ss = StackedSession(session, self.right_chainer)
            streams[0] = None
            ss.client_stream = streams[1]
            ss.client_stream.name = ss.session_id + "/rightside"
            ss.server_stream = None
            streams[1] = None
            ## LOG ##
            # This message indicates that side stacking was successful.
            ##
            log(
                session.session_id, CORE_SESSION, 4,
                "Side-stacking proxy instance; server_fd='%d', client_fd='%d', proxy_class='%s'",
                (session.server_stream.fd, ss.client_stream.fd,
                 self.right_class.__name__))
            proxy = self.right_class(ss)
            if ProxyGroup(1).start(proxy):
                return ss.client_stream
            else:
                raise RuntimeError, "Error starting proxy in group"
        except:
            ## LOG ##
            # This message indicates that side stacking failed.
            ##
            log(session.session_id, CORE_ERROR, 3,
                "Side-stacking failed; proxy_class='%s'",
                (self.right_class.__name__))
            if ss:
                ss.destroy()
            if (streams[0] != None):
                streams[0].close()
            if (streams[1] != None):
                streams[1].close()
コード例 #2
0
ファイル: Proxy.py プロジェクト: mochrul/zorp
    def stackProxy(self, client_stream, server_stream, proxy_class, stack_info):
        """
        <method internal="yes">
          <summary>
            Function to embed (stack) a proxy into the current proxy instance.
          </summary>
          <description>
            <para>
              This function stacks a new proxy into the current proxy instance. The function receives the
              downstream filedescriptors and the protocol-specific proxy class to embed.
              The way the underlying proxy decides which proxy_class
              to use is proxy specific.
            </para>
          </description>
          <metainfo>
            <arguments>
              <argument maturity="stable">
                <name>client_stream</name>
                <type></type>
                <description>The client-side data stream.</description>
              </argument>
              <argument maturity="stable">
                <name>server_stream</name>
                <type></type>
                <description>The server-side data stream.</description>
              </argument>
              <argument maturity="stable">
                <name>proxy_class</name>
                <type></type>
                <description>The protocol-specific proxy class to embed into the current proxy instance.
                </description>
              </argument>
              <argument maturity="stable">
                <name>stack_info</name>
                <type></type>
                <description>Meta-information provided by the parent proxy.
                </description>
              </argument>
            </arguments>
          </metainfo>
        </method>
        """

        proxyLog(self, CORE_DEBUG, 7, "Stacking child proxy; client_fd='%d', server_fd='%d', class='%s'", (client_stream.fd, server_stream.fd, proxy_class.__name__))

        # generate session ID for streams by replacing proxy name in the current value
        session_id_parts = string.split(self.session.session_id, '/')
        session_id_parts[-1] = proxy_class.name
        session_id = string.join(session_id_parts, '/')

        subsession = StackedSession(self.session)
        subsession.stack_info = stack_info
        subsession.client_stream = client_stream
        subsession.client_stream.name = "%s/client_upstream" % (session_id)
        subsession.server_stream = server_stream
        subsession.server_stream.name = "%s/server_upstream" % (session_id)

        try:
            return self._stackProxyInSession(proxy_class, subsession)
        except:
            subsession.destroy()
            raise
コード例 #3
0
ファイル: Proxy.py プロジェクト: akatrevorjay/zorp
        def stackProxy(self, client_stream, server_stream, proxy_class, stack_info, side_stacking=False):
                """
                <method internal="yes">
                  <summary>
                    Function to embed (stack) a proxy into the current proxy instance.
                  </summary>
                  <description>
                    <para>
                      This function stacks a new proxy into the current proxy instance. The function receives the
                      downstream filedescriptors and the protocol-specific proxy class to embed.
                      The way the underlying proxy decides which proxy_class
                      to use is proxy specific.
                    </para>
                  </description>
                  <metainfo>
                    <arguments>
                      <argument maturity="stable">
                        <name>client_stream</name>
                        <type></type>
                        <description>The client-side data stream.</description>
                      </argument>
                      <argument maturity="stable">
                        <name>server_stream</name>
                        <type></type>
                        <description>The server-side data stream.</description>
                      </argument>
                      <argument maturity="stable">
                        <name>proxy_class</name>
                        <type></type>
                        <description>The protocol-specific proxy class to embed into the current proxy instance.
                        </description>
                      </argument>
                      <argument>
                        <name>side_stacking</name>
                        <type></type>
                        <description>TRUE if a side-stack is requested, FALSE for normal stack.
                        </description>
                      </argument>
                    </arguments>
                  </metainfo>
                </method>
                """


                if side_stacking:
                        ## LOG ##
                        # This message reports that Zorp is about to stack a new proxy under the current proxy, as a child proxy.
                        ##
                        proxyLog(self, CORE_DEBUG, 7, "Stacking child proxy on right side; client_fd='%d', class='%s'", (client_stream.fd, proxy_class.__name__))
                        subsession = StackedSession(self.session, ConnectChainer())
                else:
                        ## LOG ##
                        # This message reports that Zorp is about to stack a new proxy under the current proxy, as a child proxy.
                        ##
                        proxyLog(self, CORE_DEBUG, 7, "Stacking child proxy; client_fd='%d', server_fd='%d', class='%s'", (client_stream.fd, server_stream.fd, proxy_class.__name__))
                        subsession = StackedSession(self.session)
                subsession.stack_info = stack_info
                session_id = string.split(self.session.session_id, '/')
                if len(session_id):
                        session_id[len(session_id)-1] = proxy_class.name
                        session_id = string.join(session_id, '/')
                else:
                        # hmm, funny session_id ...
                        session_id = self.session.session_id
                subsession.client_stream = client_stream
                subsession.client_stream.name = "%s/client_upstream" % (session_id)
                if not side_stacking:
                        subsession.server_stream = server_stream
                        subsession.server_stream.name = "%s/server_upstream" % (session_id)
                try:
                        proxy = proxy_class(subsession)
                        if ProxyGroup(1).start(proxy):
                                return proxy
                        else:
                                raise RuntimeError, "Error starting proxy in group"

                except:
                        ## LOG ##
                        # This message indicates that an error occurred during child proxy stacking.
                        # The stacking failed and the subsession is destroyed.
                        ##
                        proxyLog(self, CORE_ERROR, 2, "Error while stacking child proxy; error='%s', error_desc='%s', " % (sys.exc_info()[0], sys.exc_info()[1]))
                        subsession.destroy()
                        raise

                return None
コード例 #4
0
    def startInstance(self, session):
        """
        <method maturity="stable">
          <summary>
            Start a service instance.
          </summary>
          <description>
            <para>
              Called by the Rule to create an instance of this
              service.
            </para>
          </description>
          <metainfo>
            <arguments>
              <argument maturity="stable">
                <name>session</name>
                <type></type>
                <description>The session object</description>
              </argument>
            </arguments>
          </metainfo>
        </method>
        """
        if self.max_instances != 0 and self.num_instances >= self.max_instances:
            raise LimitException, "Instance limit reached"

        sys.exc_clear()
        session.client_stream.keepalive = self.keepalive & Z_KEEPALIVE_CLIENT

        self.lock.acquire()
        self.num_instances = self.num_instances + 1
        self.lock.release()

        session.started = 1

        ## LOG ##
        # This message reports that a new proxy instance is started.
        ##
        log(
            session.session_id, CORE_SESSION, 3,
            "Starting proxy instance; client_fd='%d', client_address='%s', client_zone='%s', client_local='%s', client_protocol='%s'",
            (session.client_stream.fd, session.client_address,
             session.client_zone, session.client_local, session.protocol_name))
        ss = StackedSession(session, self.chainer)

        # set up proxy stream
        ss.client_stream = session.client_stream
        ss.client_stream.name = session.session_id + '/' + self.proxy_class.name + '/client'

        # route session
        self.router.routeConnection(ss)

        start_time = time.time()
        timestamp = str(start_time)
        self.start_time = int(start_time)

        szigEvent(Z_SZIG_SERVICE_COUNT,
                  (Z_SZIG_TYPE_PROPS, (self.name, {
                      'session_number': session.instance_id + 1,
                      'sessions_running': self.num_instances,
                      'last_started': timestamp,
                  })))

        # start up proxy
        proxy = self.proxy_class(ss)
        ss.registerStart(timestamp)
        if not self.proxy_group.start(proxy):
            self.proxy_group = ProxyGroup(self.max_sessions)
            if not self.proxy_group.start(proxy):
                raise RuntimeError, "Error starting proxy in group"
        return ss
コード例 #5
0
ファイル: Service.py プロジェクト: kkovaacs/zorp
    def startInstance(self, session):
        """
                <method internal="yes">
                  <summary>
                    Start a service instance.
                  </summary>
                  <description>
                    <para>
                      Called by the Listener to create an instance of this
                      service.
                    </para>
                  </description>
                  <metainfo>
                    <arguments>
                      <argument maturity="stable">
                        <name>session</name>
                        <type></type>
                        <description>The session object</description>
                      </argument>
                    </arguments>
                  </metainfo>
                </method>
		"""
        if self.max_instances != 0 and self.num_instances >= self.max_instances:
            raise LimitException

        self.lock.acquire()
        self.num_instances = self.num_instances + 1
        self.lock.release()

        session.started = 1
        session.name = self.name
        instance_id = getInstanceId(self.name)

        # NOTE: the instance id calculation is now based in C to create
        # unique session IDs even after policy reload
        # instance_id = self.instance_id
        # self.instance_id = self.instance_id + 1

        session.setServiceInstance(instance_id)

        timestamp = str(time.time())

        szigEvent(Z_SZIG_SERVICE_COUNT,
                  (Z_SZIG_TYPE_PROPS, (self.name, {
                      'session_number': instance_id + 1,
                      'sessions_running': self.num_instances,
                      'last_started': timestamp,
                  })))

        szigEvent(Z_SZIG_CONNECTION_PROPS,
                  (Z_SZIG_TYPE_CONNECTION_PROPS,
                   (self.name, instance_id, 0, 0, {
                       'started': timestamp,
                       'session_id': session.session_id,
                       'proxy_module': self.proxy_class.name,
                       'proxy_class': self.proxy_class.__name__,
                       'client_address': str(session.client_address),
                       'client_local': str(session.client_local),
                       'client_zone': session.client_zone.getName(),
                   })))

        ## LOG ##
        # This message reports that a new proxy instance is started.
        ##
        log(
            session.session_id, CORE_SESSION, 3,
            "Starting proxy instance; client_fd='%d', client_address='%s', client_zone='%s', client_local='%s', client_protocol='%s'",
            (session.client_stream.fd, session.client_address,
             session.client_zone, session.client_local, session.protocol_name))
        ss = StackedSession(session, self.chainer)
        session.client_stream.name = session.session_id + '/' + self.proxy_class.name + '/client'

        proxy = self.proxy_class(ss)
        if not self.proxy_group.start(proxy):
            self.proxy_group = ProxyGroup(self.max_sessions)
            if not self.proxy_group.start(proxy):
                raise RuntimeError, "Error starting proxy in group"
        return TRUE
コード例 #6
0
ファイル: Chainer.py プロジェクト: kkovaacs/zorp
	def chainParent(self, session):
		"""
                <method internal="yes">
                  <summary>
                    Overridden function to perform chaining.
                  </summary>
                  <description>
                    <para>
                      This function is called by a Proxy instance to establish its
                      server side connection. Instead of connecting to a server
                      this chainer creates another proxy instance and connects
                      this new proxy with the current one.
                    </para>
                  </description>
                  <metainfo>
                    <arguments>
                      <argument maturity="stable">
                        <name>session</name>
                        <type>SESSION</type>
                        <description>session we belong to</description>
                      </argument>
                    </arguments>
                  </metainfo>
                </method>
		"""
		try:
			streams = streamPair(AF_UNIX, SOCK_STREAM)
		except IOError:
			## LOG ##
			# This message indicates that side stacking failed, because Zorp was unable to create a socketPair.
			# It is likely that there is now resource available. Try increase fd limits.
			##
			log(session.session_id, CORE_SESSION, 3, "Side stacking failed, socketPair failed;")
			return None

		try:
			# convert our tuple to an array, to make it possible
			# to modify items
			streams = [streams[0], streams[1]]
			ss = None

			session.server_stream = streams[0]
			session.server_stream.name = session.owner.session_id + "/leftside"
			ss = StackedSession(session, self.right_chainer)
			streams[0] = None
			ss.client_stream = streams[1]
			ss.client_stream.name = ss.session_id + "/rightside"
			ss.server_stream = None
			streams[1] = None
			## LOG ##
			# This message indicates that side stacking was successful.
			##
			log(session.session_id, CORE_SESSION, 4, 
                                "Side-stacking proxy instance; server_fd='%d', client_fd='%d', proxy_class='%s'",
                                (session.server_stream.fd, ss.client_stream.fd, self.right_class.__name__))
			proxy = self.right_class(ss)
			if ProxyGroup(1).start(proxy):
				return ss.client_stream
			else:
				raise RuntimeError, "Error starting proxy in group"
		except:
			## LOG ##
			# This message indicates that side stacking failed. 
			##
			log(session.session_id, CORE_ERROR, 3, "Side-stacking failed; proxy_class='%s'", (self.right_class.__name__))
			if ss:
				ss.destroy()
			if (streams[0] != None):
				streams[0].close()
			if (streams[1] != None):
				streams[1].close()
コード例 #7
0
ファイル: Service.py プロジェクト: Balasys/zorp
    def startInstance(self, session):
        """
        <method maturity="stable">
          <summary>
            Start a service instance.
          </summary>
          <description>
            <para>
              Called by the Rule to create an instance of this
              service.
            </para>
          </description>
          <metainfo>
            <arguments>
              <argument maturity="stable">
                <name>session</name>
                <type></type>
                <description>The session object</description>
              </argument>
            </arguments>
          </metainfo>
        </method>
        """
        if self.max_instances != 0 and self.num_instances >= self.max_instances:
            raise LimitException, "Instance limit reached"

        sys.exc_clear()
        session.client_stream.keepalive = self.keepalive & Z_KEEPALIVE_CLIENT;


        self.lock.acquire()
        self.num_instances = self.num_instances + 1
        self.lock.release()

        session.started = 1


        ## LOG ##
        # This message reports that a new proxy instance is started.
        ##
        log(session.session_id, CORE_SESSION, 3, "Starting proxy instance; client_fd='%d', client_address='%s', client_zone='%s', client_local='%s', client_protocol='%s'", (session.client_stream.fd, session.client_address, session.client_zone, session.client_local, session.protocol_name))
        ss = StackedSession(session, self.chainer)

        # set up proxy stream
        ss.client_stream = session.client_stream
        ss.client_stream.name = session.session_id + '/' + self.proxy_class.name + '/client'

        # route session
        self.router.routeConnection(ss)

        start_time = time.time()
        timestamp = str(start_time)
        self.start_time = int(start_time)

        szigEvent(Z_SZIG_SERVICE_COUNT,
                    (Z_SZIG_TYPE_PROPS,
                       (self.name, {
                         'session_number': session.instance_id + 1,
                         'sessions_running': self.num_instances,
                         'last_started': timestamp,
                         }
                 )))

        # start up proxy
        proxy = self.proxy_class(ss)
        ss.registerStart(timestamp)
        if not self.proxy_group.start(proxy):
            self.proxy_group = ProxyGroup(self.max_sessions)
            if not self.proxy_group.start(proxy):
                raise RuntimeError, "Error starting proxy in group"
        return ss
コード例 #8
0
ファイル: Proxy.py プロジェクト: sn00pydog/zorp
    def stackProxy(self, client_stream, server_stream, proxy_class, stack_info):
        """
        <method internal="yes">
          <summary>
            Function to embed (stack) a proxy into the current proxy instance.
          </summary>
          <description>
            <para>
              This function stacks a new proxy into the current proxy instance. The function receives the
              downstream filedescriptors and the protocol-specific proxy class to embed.
              The way the underlying proxy decides which proxy_class
              to use is proxy specific.
            </para>
          </description>
          <metainfo>
            <arguments>
              <argument maturity="stable">
                <name>client_stream</name>
                <type></type>
                <description>The client-side data stream.</description>
              </argument>
              <argument maturity="stable">
                <name>server_stream</name>
                <type></type>
                <description>The server-side data stream.</description>
              </argument>
              <argument maturity="stable">
                <name>proxy_class</name>
                <type></type>
                <description>The protocol-specific proxy class to embed into the current proxy instance.
                </description>
              </argument>
              <argument maturity="stable">
                <name>stack_info</name>
                <type></type>
                <description>Meta-information provided by the parent proxy.
                </description>
              </argument>
            </arguments>
          </metainfo>
        </method>
        """

        proxyLog(self, CORE_DEBUG, 7, "Stacking child proxy; client_fd='%d', server_fd='%d', class='%s'", (client_stream.fd, server_stream.fd, proxy_class.__name__))

        # generate session ID for streams by replacing proxy name in the current value
        session_id_parts = string.split(self.session.session_id, '/')
        session_id_parts[-1] = proxy_class.name
        session_id = string.join(session_id_parts, '/')

        subsession = StackedSession(self.session)
        subsession.stack_info = stack_info
        subsession.client_stream = client_stream
        subsession.client_stream.name = "%s/client_upstream" % (session_id)
        subsession.server_stream = server_stream
        subsession.server_stream.name = "%s/server_upstream" % (session_id)

        try:
            return self._stackProxyInSession(proxy_class, subsession)
        except:
            subsession.destroy()
            raise