Commit 375799e9 authored by Lukas Nemec's avatar Lukas Nemec

Merge branch 'channel_data' into 'master'

Handle KeyError in shs_CHANNEL_DATA

See merge request !10
parents d4a85358 beb4e99c
=== 1.8 (2018-07-16) ===
* Fix of KeyError in ssh_CHANNEL_DATA
=== 1.7 (2018-05-21) ===
* Fix of path to sshpass
......
......@@ -53,14 +53,28 @@ class SSHConnection(SSHConnectionTwisted):
if channel_type != b'direct-tcpip':
return SSHConnectionTwisted.ssh_CHANNEL_OPEN(self, packet)
senderChannel, _ = struct.unpack('>3L', rest[:12])
log.err('channel open failed, direct-tcpip is not allowed')
reason = OPEN_CONNECT_FAILED
self.transport.sendPacket(
MSG_CHANNEL_OPEN_FAILURE,
struct.pack('>2L', senderChannel, reason) +
common.NS(networkString('unknown failure')) + common.NS(b'')
)
try:
senderChannel, _ = struct.unpack('>3L', rest[:12])
except ValueError:
# Some bad packet, ignore it completely without responding.
pass
else:
self.transport.sendPacket(
MSG_CHANNEL_OPEN_FAILURE,
struct.pack('>2L', senderChannel, OPEN_CONNECT_FAILED) +
common.NS(networkString('unknown failure')) + common.NS(b'')
)
# pylint: disable=invalid-name,inconsistent-return-statements
def ssh_CHANNEL_DATA(self, packet):
try:
return SSHConnectionTwisted.ssh_CHANNEL_DATA(self, packet)
except KeyError:
# Some packets send data to the channel even it's not successfully opened.
# Very probably direct-tcpip types which has bad packet resulting in not
# responding in `ssh_CHANNEL_OPEN`. Ignore it as it's unimportant.
pass
# pylint: disable=abstract-method
......@@ -131,7 +145,7 @@ class ProxySSHUser(ConchUser):
self.password = password
self.channelLookup.update({b'session': session.SSHSession})
# # pylint: disable=invalid-name
# pylint: disable=invalid-name
def getUserGroupId(self):
"""
Returns tuple with user and group ID.
......@@ -139,12 +153,14 @@ class ProxySSHUser(ConchUser):
"""
return 0, 0
# pylint: disable=invalid-name
def getHomeDir(self):
"""
Method needed by `SSHSessionForUnixConchUser.openShell`.
"""
return "/root"
# pylint: disable=invalid-name
def getShell(self):
"""
Method needed by `SSHSessionForUnixConchUser.openShell`.
......
......@@ -90,6 +90,7 @@ class Options(usage.Options):
raise usage.UsageError('Device token is not valid')
# pylint: disable=useless-object-inheritance
@implementer(IServiceMaker, IPlugin)
class MyServiceMaker(object):
tapname = 'haas_proxy'
......
......@@ -20,7 +20,7 @@ def force_text(value):
# This function is copy-pasted from shutils. It using for compatibility with python 2.7 and 3.6 because shutils
# hasn't which() function in python 2.7. It will be removed when support python 2.7 ends.
# pylint:disable=invalid-name,too-many-branches
# pylint:disable=invalid-name,too-many-branches,unneeded-not
def which(cmd, mode=os.F_OK | os.X_OK, path=None):
"""Given a command, mode, and a PATH string, return the path which
conforms to the given mode on the PATH, or None if there is no such
......
......@@ -21,7 +21,7 @@ if sys.version_info < (3, 0):
setup(
name='haas-proxy',
version='1.7',
version='1.8',
packages=[
'haas_proxy',
'haas_proxy.twisted.plugins',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment