[Twisted-Python] changing password remotely with twisted.conch

Paul Swartz z3p at twistedmatrix.com
Tue Oct 12 08:09:02 MDT 2004


On Tue, 2004-10-12 at 13:34 +0200,
jean-marc.pouchoulon at ac-montpellier.fr wrote:
> The program seems to wait for a password's confirmation. 
> 2004/10/12 13:05 CEST [SimpleTransport,client] starting service 
> ssh-connection
> 2004/10/12 13:05 CEST [SimpleTransport,client] opening channel 0 with 
> 65536 32768
> 2004/10/12 13:05 CEST [SimpleTransport,client] sending request for 
> channel 0, request exec
> 2004/10/12 13:05 CEST [SimpleTransport,client] got extended data 1
> 'New 
> UNIX password: '
> 2004/10/12 13:05 CEST [SimpleTransport,client] got extended data 1 
> 'Retype new UNIX password: '
> 
> here it is an extract of my CatChannel(channel.SSHChannel)  class.
> 
>     CMD = 'passwd'
>     def channelOpen(self, ignoredData):
>         self.data = ''
>         d = self.conn.sendRequest(self, 'exec', common.NS(CMD), 
> wantReply = 1)
>         d.addCallback(self._cbRequest)
> 
>     def _cbRequest(self, ignored):
>          self.write('myrootpassword')
>          self.conn.sendEOF(self)
>    
>     def dataReceived(self, data):
>          self.write('myrootpassword')
>          self.conn.sendEOF(self)

There are a couple problems with this code.

1) The messages "New UNIX Password" and "Retype UNIX Password" aren't
going to dataReceived, but to errReceived, which is why they're showing
up in to the log.
2) You're sending EOF after writing the first password.  What EOF means
is "I will send no more data." which clearly isn't what you want.

You can probably get away with:

    def _cbRequest(self, ignored):
        self.write('newpassword\n')
        self.write('newpassword\n')
        self.loseConnection()

But I'd try it first.  Hope this has helped.

-p	
-- 
       Paul Swartz
(o_    http://z3p.livejournal.com/
//\    z3p at twistedmatrix.com
V_/_   AIM: z3penguin  GPG:5CF0B1C9
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: </pipermail/twisted-python/attachments/20041012/46599497/attachment.sig>


More information about the Twisted-Python mailing list