Commit b9394717 authored by ibuler's avatar ibuler

[Bugfix] 增加目录check

parent 40d8bab1
...@@ -19,8 +19,9 @@ class SFTPServer(paramiko.SFTPServerInterface): ...@@ -19,8 +19,9 @@ class SFTPServer(paramiko.SFTPServerInterface):
def get_host_sftp(self, host, su): def get_host_sftp(self, host, su):
asset = self.hosts.get(host) asset = self.hosts.get(host)
system_user = None system_user = None
for system_user in self.get_asset_system_users(host): for s in self.get_asset_system_users(host):
if system_user.name == su: if s.name == su:
system_user = s
break break
if not asset or not system_user: if not asset or not system_user:
...@@ -67,6 +68,13 @@ class SFTPServer(paramiko.SFTPServerInterface): ...@@ -67,6 +68,13 @@ class SFTPServer(paramiko.SFTPServerInterface):
return [] return []
return [su for su in asset.system_users_granted if su.protocol == "ssh"] return [su for su in asset.system_users_granted if su.protocol == "ssh"]
def su_in_asset(self, su, host):
system_users = self.get_asset_system_users(host)
if su in [s.name for s in system_users]:
return True
else:
return False
def create_ftp_log(self, path, operate, is_success=True, filename=None): def create_ftp_log(self, path, operate, is_success=True, filename=None):
host, su, rpath = self.parse_path(path) host, su, rpath = self.parse_path(path)
date_start = datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S") + " +0000", date_start = datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S") + " +0000",
...@@ -119,6 +127,13 @@ class SFTPServer(paramiko.SFTPServerInterface): ...@@ -119,6 +127,13 @@ class SFTPServer(paramiko.SFTPServerInterface):
def stat(self, path): def stat(self, path):
host, su, rpath = self.parse_path(path) host, su, rpath = self.parse_path(path)
e = OSError("Not that dir")
if host and host not in self.hosts:
return paramiko.SFTPServer.convert_errno(e.errno)
if su and not self.su_in_asset(su, host):
return paramiko.SFTPServer.convert_errno(e.errno)
if not rpath or rpath == "/": if not rpath or rpath == "/":
attr = self.stat_host_dir() attr = self.stat_host_dir()
attr.filename = su or host attr.filename = su or host
...@@ -229,7 +244,7 @@ class SFTPServer(paramiko.SFTPServerInterface): ...@@ -229,7 +244,7 @@ class SFTPServer(paramiko.SFTPServerInterface):
result = paramiko.SFTP_OK result = paramiko.SFTP_OK
else: else:
result = paramiko.SFTP_FAILURE result = paramiko.SFTP_FAILURE
self.create_ftp_log(path, "MakeDir", success) self.create_ftp_log(path, "Mkdir", success)
return result return result
def rmdir(self, path): def rmdir(self, path):
...@@ -246,7 +261,7 @@ class SFTPServer(paramiko.SFTPServerInterface): ...@@ -246,7 +261,7 @@ class SFTPServer(paramiko.SFTPServerInterface):
result = paramiko.SFTP_OK result = paramiko.SFTP_OK
else: else:
result = paramiko.SFTP_FAILURE result = paramiko.SFTP_FAILURE
self.create_ftp_log(path, "RmDir", success) self.create_ftp_log(path, "Rmdir", success)
return result return result
# def chattr(self, path, attr): # def chattr(self, path, attr):
......
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