Esempio n. 1
0
    def __connect__(self, host, port, identity):
        """
    Attempt to open a connection to the LDBD Server
    using the 'host' and 'port' and expecting the server
    to identify itself with a corresponding host certificate.

    A IOException is raised if the connection cannot be made,
    but this is caught by the __init__ method above and 
    turned into a LDBDClient exception.
        
    @param host: the host on which the LDBD Server runs
    @type host: string

    @param port: port on which the LDBD Server listens
    @type port: integer

    @param identity: string which the LDBD Server identifies itself
    @type identity: string

    @return: None
    """
        # remove the globus tcp port range environment variable if set
        try:
            port_range = os.environ["GLOBUS_TCP_PORT_RANGE"]
            os.environ["GLOBUS_TCP_PORT_RANGE"] = ""
        except:
            pass

        self.host = host
        self.port = port
        self.identity = identity

        # redirect stdout and stderror for now
        try:
            f = open("/dev/null", "w")
            sys.stdout = f
            sys.stderr = f
        except:
            pass

        try:
            # create TCPIOAttr instance
            clientAttr = io.TCPIOAttr()
            authData = io.AuthData()
            soc = io.GSITCPSocket()

            if identity is None:
                # try an unauthenticated connection
                clientAttr.set_authentication_mode(
                    io.ioc.GLOBUS_IO_SECURE_AUTHENTICATION_MODE_NONE)
                clientAttr.set_authorization_mode(
                    io.ioc.GLOBUS_IO_SECURE_AUTHORIZATION_MODE_NONE, authData)
                clientAttr.set_channel_mode(
                    io.ioc.GLOBUS_IO_SECURE_CHANNEL_MODE_CLEAR)
                clientAttr.set_delegation_mode(
                    io.ioc.GLOBUS_IO_SECURE_DELEGATION_MODE_NONE)

            else:
                # set authentication mode to be GSSAPI
                clientAttr.set_authentication_mode(
                    io.ioc.GLOBUS_IO_SECURE_AUTHENTICATION_MODE_GSSAPI)

                # set expected identity
                authData.set_identity(identity)

                # set authorization, channel, and delegation modes
                clientAttr.set_authorization_mode(
                    io.ioc.GLOBUS_IO_SECURE_AUTHORIZATION_MODE_IDENTITY,
                    authData)
                clientAttr.set_channel_mode(
                    io.ioc.GLOBUS_IO_SECURE_CHANNEL_MODE_CLEAR)
                clientAttr.set_delegation_mode(
                    io.ioc.GLOBUS_IO_SECURE_DELEGATION_MODE_LIMITED_PROXY)

            soc.connect(host, port, clientAttr)
            self.socket = soc
            self.sfile = soc.makefile("rw")

        finally:
            sys.stdout = sys.__stdout__
            sys.stderr = sys.__stderr__
            f.close()
        def __connect__(self):
                """
                Attempt to open a connection to the LDRdataFindServer
                using the 'host' and 'port' and expecting the server
                to identify itself with a corresponding host certificate.

                A IOException is raised if the connection cannot be made,
                but this is caught by the __init__ method above and 
                turned into a LDRdataFindClient exception.
        
                @param host: the host on which the LDRdataFindServer runs
                @type host: string

                @param port: port on which the LDRdataFindServer listens
                @type port: integer

                @param noproxy: whether or not to attempt connection with
                                a proxy certificate.
                @type noproxy: boolean

                @return: None
                """

                # remove the globus tcp port range environment variable if set
                try:
                        port_range = os.environ["GLOBUS_TCP_PORT_RANGE"]
                        os.environ["GLOBUS_TCP_PORT_RANGE"] = ""
                except:
                        pass

                

                # redirect stdout and stderror for now
                try:
                        f = open("/dev/null", "w")
                        sys.stdout = f
                        sys.stderr = f
                except:
                        pass

                try:
                        if self.noproxy:
                                # Try connecting without the proxy
                                # create TCPIOAttr instance and set authentication mode to be NONE
                                myAttr = io.TCPIOAttr()
                                myAttr.set_authentication_mode(io.ioc.GLOBUS_IO_SECURE_AUTHENTICATION_MODE_NONE)

                                authData = io.AuthData()
                                # set authorization, channel, and delegation modes
                                myAttr.set_authorization_mode(io.ioc.GLOBUS_IO_SECURE_AUTHORIZATION_MODE_NONE,authData)
                                myAttr.set_channel_mode(io.ioc.GLOBUS_IO_SECURE_CHANNEL_MODE_CLEAR)
                                myAttr.set_delegation_mode(io.ioc.GLOBUS_IO_SECURE_DELEGATION_MODE_NONE)
                        else:
                                # Try normal GSI-authenticated connection
                                # create TCPIOAttr instance and set authentication mode to be NONE
                                myAttr = io.TCPIOAttr()
                                myAttr.set_authentication_mode(io.ioc.GLOBUS_IO_SECURE_AUTHENTICATION_MODE_GSSAPI)

                                authData = io.AuthData()
                                # set authorization, channel, and delegation modes
                                if self.disablehostauth:
                                        # Disable the GSI hostname checking
                                        myAttr.set_authorization_mode(io.ioc.GLOBUS_IO_SECURE_AUTHORIZATION_MODE_NONE,authData)
                                        myAttr.set_channel_mode(io.ioc.GLOBUS_IO_SECURE_CHANNEL_MODE_CLEAR)
                                        myAttr.set_delegation_mode(io.ioc.GLOBUS_IO_SECURE_DELEGATION_MODE_NONE)
                                else:
                                        # Use the normal GSI hostname checking
                                        myAttr.set_authorization_mode(io.ioc.GLOBUS_IO_SECURE_AUTHORIZATION_MODE_HOST,authData)
                                        myAttr.set_channel_mode(io.ioc.GLOBUS_IO_SECURE_CHANNEL_MODE_CLEAR)
                                        myAttr.set_delegation_mode(io.ioc.GLOBUS_IO_SECURE_DELEGATION_MODE_LIMITED_PROXY)

                        # fi

                        # create socket instance and attempt to connect
                        s = io.GSITCPSocket()
                        s.connect(self.host, self.port, myAttr)
                        self.socket = s
                        self.sfile = s.makefile("rw")


                finally:
                        sys.stdout = sys.__stdout__
                        sys.stderr = sys.__stderr__
                        f.close()