44# --- BEGIN_HEADER ---
55#
66# grid_ftps - secure ftp server wrapping ftp in tls/ssl and mapping user home
7- # Copyright (C) 2014-2022 The MiG Project lead by Brian Vinter
7+ # Copyright (C) 2003-2026 The MiG Project by the Science HPC Center at UCPH
88#
99# This file is part of MiG.
1010#
2020#
2121# You should have received a copy of the GNU General Public License
2222# along with this program; if not, write to the Free Software
23- # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
24+ # USA.
2425#
2526# -- END_HEADER ---
2627#
@@ -121,15 +122,15 @@ class MiGTLSFTPHandler(TLS_FTPHandler):
121122 Makes sure buffer gets reset after AUTH to avoid command injection.
122123 """
123124
125+ # TODO: is this workaround still needed? (the upstream issue remains open)
124126 def ftp_AUTH (self , line ):
125- res = super (MiGTLSFTPHandler , self ).ftp_AUTH (line )
127+ super (MiGTLSFTPHandler , self ).ftp_AUTH (line )
126128 # NOTE: fix for https://github.com/giampaolo/pyftpdlib/issues/315
127129 print ("DEBUG: reset in buffer on switch to secure channel" )
128- print ("I.e. truncate '%s'" % self . ac_in_buffer )
130+ print ("I.e. truncate ac_in_buffer as suggested in pyftpdlib issue 315" )
129131 # IMPORTANT: buffer must be bytes on all python versions
130132 self .ac_in_buffer = b''
131133 self .incoming = []
132- return res
133134
134135
135136class MiGUserAuthorizer (DummyAuthorizer ):
@@ -177,7 +178,8 @@ def _update_logins(self, configuration, user_id):
177178 try :
178179 home_path = os .readlink (home_path )
179180 except Exception as err :
180- logger .error ("could not expand link %s" % home_path )
181+ logger .error ("could not expand %r link: %s" % (home_path ,
182+ err ))
181183 continue
182184 logger .debug ("add user to user_table: %s" % user_obj )
183185 # The add_user format and perm string meaning is explained at:
@@ -333,7 +335,7 @@ class MiGRestrictedFilesystem(AbstractedFS):
333335
334336 def _acceptable_chmod (self , ftps_path , mode ):
335337 """Wrap helper"""
336- #logger.debug("acceptable_chmod: %s" % ftps_path)
338+ # logger.debug("acceptable_chmod: %s" % ftps_path)
337339 reply = acceptable_chmod (ftps_path , mode , self .chmod_exceptions )
338340 if not reply :
339341 logger .warning ("acceptable_chmod failed: %s %s %s" %
@@ -352,7 +354,7 @@ def validpath(self, path):
352354 try :
353355 get_fs_path (configuration , path , self .root ,
354356 daemon_conf ['chroot_exceptions' ])
355- #logger.debug("accepted access to %s" % path)
357+ # logger.debug("accepted access to %s" % path)
356358 return True
357359 except ValueError as err :
358360 logger .warning ("rejected illegal access to %s :: %s" % (path , err ))
@@ -403,7 +405,7 @@ def lexists(self, path):
403405 try :
404406 self .stat (path )
405407 return True
406- except :
408+ except Exception :
407409 return False
408410
409411 def rmdir (self , path ):
@@ -439,7 +441,7 @@ def remove(self, path):
439441 def rename (self , old_path , new_path ):
440442 """Handle operations of same name"""
441443 ftp_old_path = self .fs2ftp (old_path )
442- ftp_new_path = self .fs2ftp (new_path )
444+ _ = self .fs2ftp (new_path )
443445 # Prevent rename of special files
444446 if in_vgrid_share (configuration , old_path ) == ftp_old_path .lstrip (os .sep ):
445447 logger .error ("rename on vgrid share root %s :: %s" %
@@ -458,6 +460,7 @@ def update_users(configuration, login_map, username):
458460 """Update login_map with username/password pairs for username and any
459461 aliases.
460462 """
463+ daemon_conf = configuration .daemon_conf
461464 # Only need to update users and shares here, since jobs only use sftp
462465 changed_users , changed_shares = [], []
463466 if possible_user_id (configuration , username ):
0 commit comments