summaryrefslogtreecommitdiff
path: root/Mailman/bin/export.py
diff options
context:
space:
mode:
authorbwarsaw2006-12-30 22:47:12 +0000
committerbwarsaw2006-12-30 22:47:12 +0000
commita951f422ff1adb5533b5ec52495c0c25e060cab9 (patch)
tree173769d9aca45dae6c0824bf61f970908efc9027 /Mailman/bin/export.py
parentf4a456a83b630feb294724ab462c87ca1ce1c3ae (diff)
downloadmailman-a951f422ff1adb5533b5ec52495c0c25e060cab9.tar.gz
mailman-a951f422ff1adb5533b5ec52495c0c25e060cab9.tar.zst
mailman-a951f422ff1adb5533b5ec52495c0c25e060cab9.zip
Diffstat (limited to 'Mailman/bin/export.py')
-rw-r--r--Mailman/bin/export.py73
1 files changed, 59 insertions, 14 deletions
diff --git a/Mailman/bin/export.py b/Mailman/bin/export.py
index 04f18ef16..2bcdbf667 100644
--- a/Mailman/bin/export.py
+++ b/Mailman/bin/export.py
@@ -17,7 +17,10 @@
"""Export an XML representation of a mailing list."""
+import os
import sys
+import sha
+import base64
import datetime
import optparse
@@ -40,6 +43,7 @@ DOLLAR_STRINGS = ('msg_header', 'msg_footer',
'autoresponse_postings_text',
'autoresponse_admin_text',
'autoresponse_request_text')
+SALT_LENGTH = 4 # bytes
TYPES = {
Defaults.Toggle : 'bool',
@@ -177,7 +181,7 @@ class XMLDumper(object):
else:
self._element('option', value, name=varname, type=widget_type)
- def _dump_list(self, mlist, with_passwords):
+ def _dump_list(self, mlist, password_scheme):
# Write list configuration values
self._push_element('list', name=mlist.fqdn_listname)
self._push_element('configuration')
@@ -202,8 +206,8 @@ class XMLDumper(object):
attrs['original'] = cased
self._push_element('member', **attrs)
self._element('realname', mlist.getMemberName(member))
- if with_passwords:
- self._element('password', mlist.getMemberPassword(member))
+ self._element('password',
+ password_scheme(mlist.getMemberPassword(member)))
self._element('language', mlist.getMemberLanguage(member))
# Delivery status, combined with the type of delivery
attrs = {}
@@ -247,7 +251,7 @@ class XMLDumper(object):
self._pop_element('roster')
self._pop_element('list')
- def dump(self, listnames, with_passwords=False):
+ def dump(self, listnames, password_scheme):
print >> self._fp, '<?xml version="1.0" encoding="UTF-8"?>'
self._push_element('mailman', **{
'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
@@ -259,7 +263,7 @@ class XMLDumper(object):
except Errors.MMUnknownListError:
print >> sys.stderr, _('No such list: $listname')
continue
- self._dump_list(mlist, with_passwords)
+ self._dump_list(mlist, password_scheme)
self._pop_element('mailman')
def close(self):
@@ -268,6 +272,41 @@ class XMLDumper(object):
+def no_password(password):
+ return '{NONE}'
+
+
+def plaintext_password(password):
+ return '{PLAIN}' + password
+
+
+def sha_password(password):
+ h = sha.new(password)
+ return '{SHA}' + base64.b64encode(h.digest())
+
+
+def ssha_password(password):
+ salt = os.urandom(SALT_LENGTH)
+ h = sha.new(password)
+ h.update(salt)
+ return '{SSHA}' + base64.b64encode(h.digest() + salt)
+
+
+SCHEMES = {
+ 'none' : no_password,
+ 'plain' : plaintext_password,
+ 'sha' : sha_password,
+ }
+
+try:
+ os.urandom(1)
+except NotImplementedError:
+ pass
+else:
+ SCHEMES['ssha'] = ssha_password
+
+
+
def parseargs():
parser = optparse.OptionParser(version=Version.MAILMAN_VERSION,
usage=_("""\
@@ -279,10 +318,15 @@ Export the configuration and members of a mailing list in XML format."""))
help=_("""\
Output XML to FILENAME. If not given, or if FILENAME is '-', standard out is
used."""))
- parser.add_option('-p', '--with-passwords',
+ parser.add_option('-p', '--password-scheme',
+ default='none', type='string', help=_("""\
+Specify the RFC 2307 style hashing scheme for passwords included in the
+output. Use -P to get a list of supported schemes, which are
+case-insensitive."""))
+ parser.add_option('-P', '--list-hash-schemes',
default=False, action='store_true', help=_("""\
-With this option, user passwords are included in cleartext. For this reason,
-the default is to not include passwords."""))
+List the supported password hashing schemes and exit. The scheme labels are
+case-insensitive."""))
parser.add_option('-l', '--listname',
default=[], action='append', type='string',
metavar='LISTNAME', dest='listnames', help=_("""\
@@ -294,6 +338,12 @@ included in the XML output. Multiple -l flags may be given."""))
if args:
parser.print_help()
parser.error(_('Unexpected arguments'))
+ if opts.list_hash_schemes:
+ for label in SCHEMES:
+ print label.upper()
+ sys.exit(0)
+ if opts.password_scheme.lower() not in SCHEMES:
+ parser.error(_('Invalid password scheme'))
return parser, opts, args
@@ -317,13 +367,8 @@ def main():
listnames.append(listname)
else:
listnames = Utils.list_names()
- dumper.dump(listnames, opts.with_passwords)
+ dumper.dump(listnames, SCHEMES[opts.password_scheme])
dumper.close()
finally:
if fp is not sys.stdout:
fp.close()
-
-
-
-if __name__ == '__main__':
- main()