hostbyname_cache = dict()
+def gethostbyname(host):
+ hostbyname = hostbyname_cache.get(host)
+ if not hostbyname:
+ hostbyname = socket.gethostbyname(host)
+ hostbyname_cache[host] = hostbyname
+ return hostbyname
+
def openssh_has_persist():
global OPENSSH_HAS_PERSIST
if OPENSSH_HAS_PERSIST is None:
# Create a temporary server key file
tmp_known_hosts = tempfile.NamedTemporaryFile()
- hostbyname = hostbyname_cache.get(host)
- if not hostbyname:
- hostbyname = socket.gethostbyname(host)
- hostbyname_cache[host] = hostbyname
+ hostbyname = gethostbyname(host)
# Add the intended host key
tmp_known_hosts.write('%s,%s %s\n' % (host, hostbyname, server_key))
return tmp_known_hosts
-def make_connkey(user, host, port):
- connkey = repr((user,host,port)).encode("base64").strip().replace('/','.')
- if len(connkey) > 60:
- connkey = hashlib.sha1(connkey).hexdigest()
- return connkey
-
def popen_ssh_command(command, host, port, user, agent,
stdin="",
ident_key = None,
timeout = None,
retry = 0,
err_on_timeout = True,
- connect_timeout = 1200,
+ connect_timeout = 900,
persistent = True,
hostip = None):
"""
print "ssh", host, command
tmp_known_hosts = None
- connkey = make_connkey(user,host,port)
args = ['ssh', '-C',
# Don't bother with localhost. Makes test easier
'-o', 'NoHostAuthenticationForLocalhost=yes',
+ # XXX: Security vulnerability
+ #'-o', 'StrictHostKeyChecking=no',
'-o', 'ConnectTimeout=%d' % (int(connect_timeout),),
'-o', 'ConnectionAttempts=3',
'-o', 'ServerAliveInterval=30',
if persistent and openssh_has_persist():
args.extend([
'-o', 'ControlMaster=auto',
- '-o', 'ControlPath=/tmp/nepi_ssh_pl_%s' % ( connkey, ),
+ '-o', 'ControlPath=/tmp/nepi_ssh-%r@%h:%p',
'-o', 'ControlPersist=60' ])
if agent:
args.append('-A')
# attach tempfile object to the process, to make sure the file stays
# alive until the process is finished with it
proc._known_hosts = tmp_known_hosts
-
+
try:
out, err = _communicate(proc, stdin, timeout, err_on_timeout)
if proc.poll():
user,host = remspec.rsplit('@',1)
tmp_known_hosts = None
- connkey = make_connkey(user,host,port)
args = ['ssh', '-l', user, '-C',
# Don't bother with localhost. Makes test easier
'-o', 'NoHostAuthenticationForLocalhost=yes',
- '-o', 'ConnectTimeout=1200',
+ # XXX: Security vulnerability
+ #'-o', 'StrictHostKeyChecking=no',
+ '-o', 'ConnectTimeout=900',
'-o', 'ConnectionAttempts=3',
'-o', 'ServerAliveInterval=30',
'-o', 'TCPKeepAlive=yes',
if openssh_has_persist():
args.extend([
'-o', 'ControlMaster=auto',
- '-o', 'ControlPath=/tmp/nepi_ssh_pl_%s' % ( connkey, ),
+ '-o', 'ControlPath=/tmp/nepi_ssh-%r@%h:%p',
'-o', 'ControlPersist=60' ])
if port:
args.append('-P%d' % port)
args = ['scp', '-q', '-p', '-C',
# Don't bother with localhost. Makes test easier
'-o', 'NoHostAuthenticationForLocalhost=yes',
- '-o', 'ConnectTimeout=1200',
+ # XXX: Security vulnerability
+ #'-o', 'StrictHostKeyChecking=no',
+ '-o', 'ConnectTimeout=900',
'-o', 'ConnectionAttempts=3',
'-o', 'ServerAliveInterval=30',
'-o', 'TCPKeepAlive=yes' ]
args.extend(source)
else:
if openssh_has_persist():
- connkey = make_connkey(user,host,port)
args.extend([
- '-o', 'ControlMaster=no',
- '-o', 'ControlPath=/tmp/nepi_ssh_pl_%s' % ( connkey, ) ])
+ '-o', 'ControlMaster=auto',
+ '-o', 'ControlPath=/tmp/nepi_ssh-%r@%h:%p'])
args.append(source)
args.append(dest)
args = ['ssh', '-C',
# Don't bother with localhost. Makes test easier
'-o', 'NoHostAuthenticationForLocalhost=yes',
+ # XXX: Security vulnerability
+ #'-o', 'StrictHostKeyChecking=no',
'-o', 'ConnectionAttempts=3',
'-o', 'ServerAliveInterval=30',
'-o', 'TCPKeepAlive=yes',