123123_filter_ops = ['chattr' , 'lstat' , 'stat' ]
124124_other_ops = ['close' ]
125125
126+
126127def list_attr_changes (configuration , path , attr ):
127128 """Decipher actual attribute changes requested in attr on path"""
128129 _logger = configuration .logger
129130 _logger .debug ("check %s attr changes: %s" % (path , attr ))
130131 changes = []
131132 for field in ('st_size' , 'st_uid' , 'st_gid' , 'st_mode' , 'st_atime' ,
132133 'st_mtime' ):
133- #_logger.debug("checking path %s attr %s" % (path, field))
134+ # _logger.debug("checking path %s attr %s" % (path, field))
134135 val = getattr (attr , field , None )
135136 if val is not None :
136137 _logger .debug ("found %s attr %s value %s" % (path , field , val ))
137138 changes .append (field )
138139 return changes
139140
141+
140142def filter_data_access (configuration , path , access_mode , operation , args = []):
141143 """Filter access to what operation is allowed to do based on path, args
142144 and access_mode.
@@ -160,7 +162,7 @@ def filter_data_access(configuration, path, access_mode, operation, args=[]):
160162 return True
161163 # NOTE: allow non-changing chattr
162164 # TODO: allow non-changing chown and chmod, too?
163- if operation == 'chattr' and args :
165+ if operation == 'chattr' and args :
164166 if not list_attr_changes (configuration , path , args [0 ]):
165167 return True
166168
@@ -177,6 +179,7 @@ def filter_data_access(configuration, path, access_mode, operation, args=[]):
177179 (operation , path , access_mode ))
178180 return False
179181
182+
180183def check_data_access (configuration , user_id , path , access_mode , operation ,
181184 args = []):
182185 """A simple helper to check if user_id has access to execute operation on path
@@ -908,7 +911,8 @@ def _chattr(self, path, attr, sftphandle=None):
908911 path = force_native_str (path )
909912 self .logger .debug ("_chattr %r %r" % (path , attr ))
910913 try :
911- real_path = self ._get_fs_path (path , operation = 'chattr' , args = [attr ])
914+ real_path = self ._get_fs_path (path , operation = 'chattr' ,
915+ args = [attr ])
912916 except AccessError as aer :
913917 self .logger .warning ('chattr %s: %s' % ([path ], [aer ]))
914918 return paramiko .SFTP_PERMISSION_DENIED
@@ -1048,7 +1052,8 @@ def open(self, path, flags, attr):
10481052 open_flavor = 'open+read'
10491053
10501054 try :
1051- real_path = self ._get_fs_path (path , operation = open_flavor , args = [flags ])
1055+ real_path = self ._get_fs_path (path , operation = open_flavor ,
1056+ args = [flags ])
10521057 except ValueError as err :
10531058 self .logger .warning ('open %s: %s' % ([path ], [err ]))
10541059 return paramiko .SFTP_PERMISSION_DENIED
@@ -1122,7 +1127,8 @@ def list_folder(self, path):
11221127 """Handle operations of same name"""
11231128 # self.logger.debug('list_folder %s' % [path])
11241129 try :
1125- real_path = self ._get_fs_path (path , operation = 'list_folder' , args = [])
1130+ real_path = self ._get_fs_path (path , operation = 'list_folder' ,
1131+ args = [])
11261132 except ValueError as err :
11271133 self .logger .warning ('list_folder %s: %s' % ([path ], [err ]))
11281134 return paramiko .SFTP_PERMISSION_DENIED
@@ -1268,7 +1274,8 @@ def rename(self, oldpath, newpath):
12681274 # newpath = force_utf8(newpath)
12691275 # self.logger.debug("rename %s %s" % (oldpath, newpath))
12701276 try :
1271- real_oldpath = self ._get_fs_path (oldpath , operation = 'rename' , args = [])
1277+ real_oldpath = self ._get_fs_path (oldpath , operation = 'rename' ,
1278+ args = [])
12721279 except ValueError as err :
12731280 self .logger .warning ('rename %s %s: %s' % (oldpath , newpath , err ))
12741281 return paramiko .SFTP_PERMISSION_DENIED
@@ -1684,8 +1691,8 @@ def update_sftp_login_map(daemon_conf, username, password=False, key=False):
16841691 _ , changed_users = refresh_user_creds (configuration ,
16851692 'sftp' , username )
16861693 if possible_sharelink_id (configuration , username ):
1687- allow_modes = [ READ_WRITE_ACCESS , READ_ONLY_ACCESS ,
1688- WRITE_ONLY_ACCESS ]
1694+ allow_modes = ( READ_WRITE_ACCESS , READ_ONLY_ACCESS ,
1695+ WRITE_ONLY_ACCESS )
16891696 _ , changed_shares = refresh_share_creds (configuration ,
16901697 'sftp' , username ,
16911698 share_modes = allow_modes )
0 commit comments