Commit 11dae336 authored by BaiJiangJie's avatar BaiJiangJie

[Update] 解决sftp登录,绕过校验系统用户手动登录的情况3

parent e1eaaf8c
......@@ -4,6 +4,7 @@
import threading
import time
import copy
from .session import Session
from .models import Server, TelnetServer
......@@ -27,7 +28,7 @@ class ProxyServer:
def __init__(self, client, asset, system_user):
self.client = client
self.asset = asset
self.system_user = system_user
self.system_user = copy.deepcopy(system_user)
self.server = None
self.connecting = True
......
......@@ -120,27 +120,27 @@ class SFTPServer(paramiko.SFTPServerInterface):
raise PermissionError("No asset or system user explicit")
cache_key = '{}@{}'.format(su, host)
if cache_key not in self._sftp:
conn = SSHConnection.new_connection(self.server.connection.user,
asset, system_user)
__sftp = conn.get_sftp()
if __sftp:
sftp = {
'client': __sftp, 'connection': conn,
'home': __sftp.normalize('')
}
self._sftp[cache_key] = sftp
return sftp
elif system_user.login_mode == MANUAL_LOGIN:
raise PermissionError(
"System user is in manual login mode, "
"please use SSH protocol to connect assets first."
)
else:
raise OSError("Can not connect asset sftp server: {}".format(conn.error))
else:
if cache_key in self._sftp:
return self._sftp[cache_key]
conn = SSHConnection.new_connection(self.server.connection.user,
asset, system_user)
__sftp = conn.get_sftp()
if __sftp:
sftp = {
'client': __sftp, 'connection': conn,
'home': __sftp.normalize('')
}
self._sftp[cache_key] = sftp
return sftp
elif system_user.login_mode == MANUAL_LOGIN:
raise PermissionError(
"System user is in manual login mode, "
"please use SSH protocol to connect assets first."
)
else:
raise OSError("Can not connect asset sftp server: {}".format(conn.error))
def host_has_unique_su(self, host):
host_sus = self.get_host_system_users(host, only_name=True)
logger.debug("Host system users: {}".format(host_sus))
......
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