Skip to content

Commit 66840a7

Browse files
jared mauchjared mauch
authored andcommitted
Handle permission errors gracefully during password auto-upgrade
- Catch PermissionError/IOError when attempting to write password upgrades - Log uid/euid/gid/egid for debugging permission issues - Continue authentication even if upgrade fails (non-fatal) - Apply to global passwords, list admin, moderator, and poster passwords This prevents authentication failures when the process doesn't have write permissions to update password files, while still logging the issue for administrator review.
1 parent 34c2145 commit 66840a7

2 files changed

Lines changed: 57 additions & 1 deletion

File tree

Mailman/SecurityManager.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,21 @@ def cryptmatchp(response, secret):
208208
self.password = hash_password(response_str)
209209
if save_and_unlock:
210210
self.Save()
211+
except (PermissionError, IOError) as e:
212+
# Log permission error but don't fail authentication
213+
# Get uid/euid/gid/egid for debugging
214+
try:
215+
uid = os.getuid()
216+
euid = os.geteuid()
217+
gid = os.getgid()
218+
egid = os.getegid()
219+
except (AttributeError, OSError):
220+
# Fallback if getuid/geteuid not available
221+
uid = euid = gid = egid = 'unknown'
222+
syslog('error',
223+
'Could not auto-upgrade list admin password for %s: %s (uid=%s euid=%s gid=%s egid=%s)',
224+
self.internal_name(), e, uid, euid, gid, egid)
225+
# Continue - authentication still succeeds even if upgrade fails
211226
finally:
212227
if save_and_unlock:
213228
self.Unlock()
@@ -238,6 +253,18 @@ def cryptmatchp(response, secret):
238253
self.mod_password = hash_password(response_str)
239254
if save_and_unlock:
240255
self.Save()
256+
except (PermissionError, IOError) as e:
257+
# Log permission error but don't fail authentication
258+
try:
259+
uid = os.getuid()
260+
euid = os.geteuid()
261+
gid = os.getgid()
262+
egid = os.getegid()
263+
except (AttributeError, OSError):
264+
uid = euid = gid = egid = 'unknown'
265+
syslog('error',
266+
'Could not auto-upgrade moderator password for %s: %s (uid=%s euid=%s gid=%s egid=%s)',
267+
self.internal_name(), e, uid, euid, gid, egid)
241268
finally:
242269
if save_and_unlock:
243270
self.Unlock()
@@ -267,6 +294,18 @@ def cryptmatchp(response, secret):
267294
self.post_password = hash_password(response_str)
268295
if save_and_unlock:
269296
self.Save()
297+
except (PermissionError, IOError) as e:
298+
# Log permission error but don't fail authentication
299+
try:
300+
uid = os.getuid()
301+
euid = os.geteuid()
302+
gid = os.getgid()
303+
egid = os.getegid()
304+
except (AttributeError, OSError):
305+
uid = euid = gid = egid = 'unknown'
306+
syslog('error',
307+
'Could not auto-upgrade poster password for %s: %s (uid=%s euid=%s gid=%s egid=%s)',
308+
self.internal_name(), e, uid, euid, gid, egid)
270309
finally:
271310
if save_and_unlock:
272311
self.Unlock()

Mailman/Utils.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,24 @@ def check_global_password(response, siteadmin=True, auto_upgrade=False):
843843
is_valid, needs_upgrade = verify_password(response, challenge)
844844
# Auto-upgrade if requested and password is valid but in old format
845845
if is_valid and needs_upgrade and auto_upgrade:
846-
set_global_password(response, siteadmin)
846+
try:
847+
set_global_password(response, siteadmin)
848+
except (PermissionError, IOError) as e:
849+
# Log permission error but don't fail authentication
850+
# Get uid/euid/gid/egid for debugging
851+
try:
852+
uid = os.getuid()
853+
euid = os.geteuid()
854+
gid = os.getgid()
855+
egid = os.getegid()
856+
except (AttributeError, OSError):
857+
# Fallback if getuid/geteuid not available
858+
uid = euid = gid = egid = 'unknown'
859+
pw_type = 'site admin' if siteadmin else 'list creator'
860+
syslog('error',
861+
'Could not auto-upgrade %s password: %s (uid=%s euid=%s gid=%s egid=%s)',
862+
pw_type, e, uid, euid, gid, egid)
863+
# Continue - authentication still succeeds even if upgrade fails
847864
return is_valid
848865

849866

0 commit comments

Comments
 (0)