trouble with select and tochild of Popen3 object

Richard Cook rcook at llnl.gov
Fri Feb 21 13:44:48 EST 2003


Hi, the below code is supposed to open an ssh connection to a remote 
machine.  It has been set up so that username and password is not 
necessary for this connection, but often the ssh asks a yes/no 
question to which I always wish to answer yes.  The code below is 
supposed to wait until the tochild is writable and write 'yes' to it. 
what actually happens is written below.  Can anyone help me figure 
this one out?  Thanks.

NORMAL SSH BEHAVIOR:
snow01{rcook}157: ssh snow05 sleep 1
Host key not found from the list of known hosts.
!! If host key is new or changed, ssh1 protocol is vulnerable to an
!! attack known as false-split, which makes it relativily easy to
!! hijack the connection without the attack being detected. It is
!! highly advisable to turn StrictHostKeyChecking to "yes" and
!! manually copy host keys to known_hosts.
Are you sure you want to continue connecting (yes/no)? (<--I WISH TO 
ANSWER 'YES' HERE FROM MY SCRIPT)

MY CODE:
hostname = sys.argv[1]
command = 'ssh '+hostname+' sleep 1'

theProcess = popen2.Popen3(command,capturestderr=1)
while 1:
     returnCode = theProcess.poll()
     fdstderr = theProcess.childerr.fileno()
     fdstdout = theProcess.fromchild.fileno()
     fdstdin = theProcess.tochild.fileno()
     selectables = [fdstdout, fdstderr, fdstdin]
     (input, output, exc) = ([],[],[])
     #note that the output of theProcess is the 'input' of select.select, so
     # the return values look funny, but they're right
     (output, input, exc) = select.select(selectables,selectables, [])
     if input or output:
         print "output or input detected"
     if input:
         print 'input'
         theProcess.tochild.write('yes\n')
         theProcess.tochild.flush()
     if output:
         for theOutput in output:
             if theOutput == fdstdout or theOutput == fdstderr:
                 eoutput = os.read(theOutput, 5000)
                 print eoutput
                 theProcess.tochild.write('yes\n')
                 theProcess.tochild.flush()
     if not output and not input:
         print 'no request for input yet  waiting...'
     time.sleep(1)
     if returnCode != -1:
         break;
print 'done'


ACTUAL BEHAVIOR:
snow01{rcook}158: ~/test.py snow05
output or input detected
input
output or input detected
input
output or input detected
input
Host key not found from the list of known hosts.
!! If host key is new or changed, ssh1 protocol is vulnerable to an
!! attack known as false-split, which makes it relativily easy to
!! hijack the connection without the attack being detected. It is
!! highly advisable to turn StrictHostKeyChecking to "yes" and
!! manually copy host keys to known_hosts.
Are you sure you want to continue connecting (yes/no)?
output or input detected
input
output or input detected
input
output or input detected
input
output or input detected
input
output or input detected
input
output or input detected
input
output or input detected
input
output or input detected
input
output or input detected
input
output or input detected
input
^CTraceback (most recent call last):
   File "/g/g2/rcook/test.py", line 102, in ?
     time.sleep(1)
KeyboardInterrupt

-- 
Richard Cook
Lawrence Livermore National Laboratory
Bldg-451 Rm-2043, Mail Stop L-561
7000 East Avenue,  Livermore, CA, 94550, USA
phone (925) 423-9605 (work)    fax (925) 423-8704
---
Information Management & Graphics Grp., Services & Development Div., 
Integrated Computing & Communications Dept.
(opinions expressed herein are mine and not those of LLNL)





More information about the Python-list mailing list