Skip to content

Commit beef43b

Browse files
authored
Merge pull request #27 from thegushi/fix/py3-portability-fixes
Python 3 portability fixes: convert_to_utf8, is_old_password_format, update notification, interpolation, BSD make, configure, common.c
2 parents 8896a1f + 802728f commit beef43b

11 files changed

Lines changed: 2407 additions & 1958 deletions

File tree

Mailman/MTA/Postfix.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -442,12 +442,12 @@ def checkperms(state):
442442
if stat and (stat[ST_MODE] & targetmode) != targetmode:
443443
state.ERRORS += 1
444444
octmode = oct(stat[ST_MODE])
445-
print(C_('%(file)s permissions must be 0664 (got %(octmode)s)'),)
445+
print(C_('%(file)s permissions must be 0664 (got %(octmode)s)') % locals())
446446
if state.FIX:
447447
print(C_('(fixing)'))
448448
os.chmod(file, stat[ST_MODE] | targetmode)
449449
else:
450-
print
450+
print()
451451
# Make sure the corresponding .db files are owned by the Mailman user.
452452
# We don't need to check the group ownership of the file, since
453453
# check_perms checks this itself.
@@ -481,7 +481,7 @@ def checkperms(state):
481481
if stat and (stat[ST_MODE] & targetmode) != targetmode:
482482
state.ERRORS += 1
483483
octmode = oct(stat[ST_MODE])
484-
print(C_('%(dbfile)s permissions must be 0664 (got %(octmode)s)'),)
484+
print(C_('%(dbfile)s permissions must be 0664 (got %(octmode)s)') % locals())
485485
if state.FIX:
486486
print(C_('(fixing)'))
487487
os.chmod(dbfile, stat[ST_MODE] | targetmode)

Mailman/Utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,11 @@ def hash_password(plaintext):
727727
binascii.hexlify(dk).decode('ascii'))
728728

729729

730+
def is_old_password_format(pw):
731+
"""Return True if pw is a legacy password that needs upgrading to PBKDF2."""
732+
return bool(pw) and not pw.startswith(_PBKDF2_SHA256_PREFIX)
733+
734+
730735
def verify_password(response, stored):
731736
"""Verify password against stored hash.
732737

bin/check_perms

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def checkwalk(arg, dirname, names):
141141
octperms = oct(targetperms)
142142
if S_ISDIR(mode) and (mode & targetperms) != targetperms:
143143
arg.ERRORS += 1
144-
print(C_('directory permissions must be %(octperms)s: %(path)s'),)
144+
print(C_('directory permissions must be %(octperms)s: %(path)s') % locals())
145145
if STATE.FIX:
146146
print(C_('(fixing)'))
147147
os.chmod(path, mode | targetperms)
@@ -150,7 +150,7 @@ def checkwalk(arg, dirname, names):
150150
elif os.path.splitext(path)[1] in ('.py', '.pyc', '.pyo'):
151151
octperms = oct(PYFILEPERMS)
152152
if mode & PYFILEPERMS != PYFILEPERMS:
153-
print(C_('source perms must be %(octperms)s: %(path)s'),)
153+
print(C_('source perms must be %(octperms)s: %(path)s') % locals())
154154
arg.ERRORS += 1
155155
if STATE.FIX:
156156
print(C_('(fixing)'))
@@ -161,7 +161,7 @@ def checkwalk(arg, dirname, names):
161161
# Article files must be group writeable
162162
octperms = oct(ARTICLEFILEPERMS)
163163
if mode & ARTICLEFILEPERMS != ARTICLEFILEPERMS:
164-
print(C_('article db files must be %(octperms)s: %(path)s'),)
164+
print(C_('article db files must be %(octperms)s: %(path)s') % locals())
165165
arg.ERRORS += 1
166166
if STATE.FIX:
167167
print(C_('(fixing)'))
@@ -187,7 +187,7 @@ def checkall():
187187
continue
188188
if (mode & DIRPERMS) != DIRPERMS:
189189
STATE.ERRORS += 1
190-
print(C_('directory must be at least 02775: %(d)s'),)
190+
print(C_('directory must be at least 02775: %(d)s') % locals())
191191
if STATE.FIX:
192192
print(C_('(fixing)'))
193193
os.chmod(d, mode | DIRPERMS)
@@ -204,7 +204,7 @@ def checkarchives():
204204
mode = statmode(private)
205205
if mode & S_IROTH:
206206
STATE.ERRORS += 1
207-
print(C_('%(private)s must not be other-readable'),)
207+
print(C_('%(private)s must not be other-readable') % locals())
208208
if STATE.FIX:
209209
print(C_('(fixing)'))
210210
os.chmod(private, mode & ~S_IROTH)
@@ -253,7 +253,7 @@ def checkarchivedbs():
253253
continue
254254
if mode & S_IRWXO:
255255
STATE.ERRORS += 1
256-
print(C_('%(dbdir)s "other" perms must be 000'),)
256+
print(C_('%(dbdir)s "other" perms must be 000') % locals())
257257
if STATE.FIX:
258258
print(C_('(fixing)'))
259259
os.chmod(dbdir, mode & ~S_IRWXO)
@@ -272,7 +272,7 @@ def checkcgi():
272272
mode = statmode(path)
273273
if mode & S_IXGRP and not mode & S_ISGID:
274274
STATE.ERRORS += 1
275-
print(C_('%(path)s must be set-gid'),)
275+
print(C_('%(path)s must be set-gid') % locals())
276276
if STATE.FIX:
277277
print(C_('(fixing)'))
278278
os.chmod(path, mode | S_ISGID)
@@ -286,7 +286,7 @@ def checkmail():
286286
mode = statmode(wrapper)
287287
if not mode & S_ISGID:
288288
STATE.ERRORS += 1
289-
print(C_('%(wrapper)s must be set-gid'),)
289+
print(C_('%(wrapper)s must be set-gid') % locals())
290290
if STATE.FIX:
291291
print(C_('(fixing)'))
292292
os.chmod(wrapper, mode | S_ISGID)
@@ -346,7 +346,7 @@ def checkdata():
346346
continue
347347
if (mode & targetmode) != targetmode:
348348
STATE.ERRORS += 1
349-
print(C_('file permissions must be at least 660: %(path)s'),)
349+
print(C_('file permissions must be at least 660: %(path)s') % locals())
350350
if STATE.FIX:
351351
print(C_('(fixing)'))
352352
os.chmod(path, mode | targetmode)

bin/newlist

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,7 @@ def main():
241241

242242
# And send the notice to the list owner
243243
if not quiet and not automate:
244-
print('Hit enter to notify %(listname)s owner...'),
245-
sys.stdin.readline()
244+
input('Hit enter to notify %s owner...' % listname)
246245
if not quiet:
247246
siteowner = Utils.get_site_email(mlist.host_name, 'owner')
248247
text = Utils.maketext(

bin/update

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -814,27 +814,27 @@ def send_password_upgrade_notification(mlist):
814814
listaddr = mlist.GetListEmail()
815815
siteowner = Utils.get_site_email(mlist.host_name, 'owner')
816816

817-
text = _("""\
817+
text = C_("""\
818818
This is an automated message from your Mailman installation.
819819

820-
Your mailing list "%(listname)s" (%(listaddr)s) is using an older password
821-
hashing format. For security reasons, we have upgraded Mailman to use a more
820+
Your mailing list "%(listname)s" (%(listaddr)s) is using an older password
821+
hashing format. For security reasons, we have upgraded Mailman to use a more
822822
secure password hashing method (PBKDF2-SHA256 instead of SHA1).
823823

824824
To complete the upgrade, please log in to your list administration page:
825825

826826
%(admin_url)s
827827

828-
Simply logging in with your current list administrator password will
829-
automatically upgrade your password to the new secure format. You don't
830-
need to change your password - just log in once and the upgrade will happen
828+
Simply logging in with your current list administrator password will
829+
automatically upgrade your password to the new secure format. You don't
830+
need to change your password - just log in once and the upgrade will happen
831831
automatically.
832832

833-
This is a one-time upgrade. After you log in, your password will be
834-
automatically converted to the new format and you won't need to do anything
833+
This is a one-time upgrade. After you log in, your password will be
834+
automatically converted to the new format and you won't need to do anything
835835
else.
836836

837-
If you have any questions or concerns, please contact the site administrator
837+
If you have any questions or concerns, please contact the site administrator
838838
at %(siteowner)s.
839839

840840
Thank you for your attention to this important security upgrade.
@@ -844,8 +844,8 @@ Thank you for your attention to this important security upgrade.
844844
'admin_url': admin_url,
845845
'siteowner': siteowner,
846846
}
847-
848-
subject = _('Action Required: Password Upgrade for %(listname)s') % {
847+
848+
subject = C_('Action Required: Password Upgrade for %(listname)s') % {
849849
'listname': listname
850850
}
851851

0 commit comments

Comments
 (0)