[Twisted-Python] Re : Re : Telnet server using Twisted and AuthenticatingTelnetProtocol

filoufake-python at yahoo.fr filoufake-python at yahoo.fr
Tue Sep 1 16:49:27 EDT 2009


Thanks to your help, the server now requests a username and password for the authentication.
Once the password has been enterred, nothing happened on the client side. I'm even not able to escape from the client. I have to ctrl-c in the server console.
If I well understood the doc, for each state of the connection a method is called: telnet_User called when state = 'User', telnet_Password called when state = 'Password' and at the end telnet_Command (to be written by me).
I have added my "telnet_Command" method into my ITelnetProtocol implementation return by requestAvatar, but it is never called.
In the telnet_Password method, the deferred calls _cbLogin in case of good authentication or _ebLogin.
I could verify that _cbLogin is well called but it seems the application blocks in.

The method looks like this:
def _cbLogin(self, ial):
        interface, protocol, logout = ial
        assert interface is ITelnetProtocol
        self.protocol = protocol
        self.logout = logout
        self.state = 'Command'
        self.transport.protocol = protocol

I almost sure this has to do with what requestAvatar returns in my Realm class:
class Realm:

    def requestAvatar(self, avatarId, mind, *interfaces):
        if ITelnetProtocol in interfaces:
            av = MyTelnet()
            return ITelnetProtocol, av, lambda:None
        raise NotImplementedError("Only IProtocolUser interface is supported by this realm")

MyTelnet being a derived class of StatefulTelnetProtocol.

Is it what you explained in your previous reply?
>AuthenticatingTelnetProtocol is an ITelnetProtocol implementation.  So, 
>it needs to be hooked up to an ITelnetTransport implementation, as all 
>ITelnetProtocol implementations need to.
>However, since the only thing it knows how to do is handle 
>authentication, it also wants to get /another/ ITelnetProtocol 
>implementation out of the portal you give it.  After authentication 
>succeeds, that new ITelnetProtocol implementation will be given control 
>of the connection and the AuthenticatingTelnetProtocol will get out of 
>the way.
>So you end up with one telnet transport and two telnet protocols.

I think I did all you said but I'm not able to get it work. Do you have another idea?
Thanks in advance.

Here is the log on the server:
2009-09-01 22:37:35+0200 [-] Log opened.
2009-09-01 22:37:35+0200 [-] twisted.internet.protocol.ServerFactory starting on 4738
2009-09-01 22:37:35+0200 [-] Starting factory <twisted.internet.protocol.ServerFactory instance at 0x00D82DA0>
2009-09-01 22:37:57+0200 [twisted.internet.protocol.ServerFactory] state User
2009-09-01 22:38:01+0200 [TelnetTransport,0,] state User
2009-09-01 22:38:02+0200 [TelnetTransport,0,] state Password
2009-09-01 22:38:02+0200 [TelnetTransport,0,] BEGUG in requestAvatar: av = <__main__.MyTelnet instance at 0x00E757D8>
2009-09-01 22:38:02+0200 [TelnetTransport,0,] BEGUG in _cbLogin: ial = (<InterfaceClass twisted.conch.telnet.ITelnetProtocol>, <__main__.MyTelnet instance at 0x00E757D8>, None)
2009-09-01 22:38:02+0200 [TelnetTransport,0,] BEGUG in _cbLogin: state = Command
2009-09-01 22:38:02+0200 [TelnetTransport,0,] BEGUG in telnet_Password: deferred d = <Deferred at 0xe75b48  current result: None>



More information about the Twisted-Python mailing list