diff options
| author | bwarsaw | 2006-05-01 18:07:32 +0000 |
|---|---|---|
| committer | bwarsaw | 2006-05-01 18:07:32 +0000 |
| commit | b38b93ad819cf988ac2016a9b8fbaef8705b28fd (patch) | |
| tree | 2dc6b8413169043a6b4ac1545b1b538590788976 | |
| parent | 0efe24ecd85a5e1fc6cb562bc9e54fac0890d4c6 (diff) | |
| download | mailman-b38b93ad819cf988ac2016a9b8fbaef8705b28fd.tar.gz mailman-b38b93ad819cf988ac2016a9b8fbaef8705b28fd.tar.zst mailman-b38b93ad819cf988ac2016a9b8fbaef8705b28fd.zip | |
Convert change_pw and show_qfiles to Mailman.bin package. Note that
after this commit, I have to fix the filename of
Mailman/bin/show_qfiles because of silly svn restrictions.
| -rw-r--r-- | Mailman/bin/change_pw.py (renamed from bin/change_pw) | 208 | ||||
| -rw-r--r-- | Mailman/bin/show_qfiles (renamed from bin/show_qfiles) | 62 | ||||
| -rw-r--r-- | bin/Makefile.in | 7 | ||||
| -rwxr-xr-x | configure | 4 | ||||
| -rw-r--r-- | configure.in | 4 |
5 files changed, 110 insertions, 175 deletions
diff --git a/bin/change_pw b/Mailman/bin/change_pw.py index 1305e1a4c..00c555d9b 100644 --- a/bin/change_pw +++ b/Mailman/bin/change_pw.py @@ -1,6 +1,4 @@ -#! @PYTHON@ -# -# Copyright (C) 2001-2004 by the Free Software Foundation, Inc. +# Copyright (C) 2001-2006 by the Free Software Foundation, Inc. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -14,156 +12,128 @@ # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -"""Change a list's password. - -Prior to Mailman 2.1, list passwords were kept in crypt'd format -- usually. -Some Python installations didn't have the crypt module available, so they'd -fall back to md5. Then suddenly the Python installation might grow a crypt -module and all list passwords would be broken. - -In Mailman 2.1, all list and site passwords are stored in SHA1 hexdigest -form. This breaks list passwords for all existing pre-Mailman 2.1 lists, and -since those passwords aren't stored anywhere in plain text, they cannot be -retrieved and updated. - -Thus, this script generates new passwords for a list, and optionally sends it -to all the owners of the list. +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +# USA. -Usage: change_pw [options] - -Options: - - --all / -a - Change the password for all lists. - - --domain=domain - -d domain - Change the password for all lists in the virtual domain `domain'. It - is okay to give multiple -d options. - - --listname=listname - -l listname - Change the password only for the named list. It is okay to give - multiple -l options. - - --password=newpassword - -p newpassword - Use the supplied plain text password `newpassword' as the new password - for any lists that are being changed (as specified by the -a, -d, and - -l options). If not given, lists will be assigned a randomly - generated new password. - - --quiet / -q - Don't notify list owners of the new password. You'll have to have - some other way of letting the list owners know the new password - (presumably out-of-band). - - --help / -h - Print this help message and exit. -""" - -import sys import sha -import getopt +import sys +import optparse -import paths -from Mailman import mm_cfg -from Mailman import Utils -from Mailman import MailList from Mailman import Errors +from Mailman import MailList from Mailman import Message +from Mailman import Utils from Mailman import i18n +from Mailman import mm_cfg _ = i18n._ +__i18n_templates__ = True SPACE = ' ' -def usage(code, msg=''): - if code: - fd = sys.stderr - else: - fd = sys.stdout - print >> fd, _(__doc__) - if msg: - print >> fd, msg - sys.exit(code) +def parseargs(): + parser = optparse.OptionParser(version=mm_cfg.MAILMAN_VERSION, + usage=_("""\ +%%prog [options] + +Change a list's password. + +Prior to Mailman 2.1, list passwords were kept in crypt'd format -- usually. +Some Python installations didn't have the crypt module available, so they'd +fall back to md5. Then suddenly the Python installation might grow a crypt +module and all list passwords would be broken. + +In Mailman 2.1, all list and site passwords are stored in SHA1 hexdigest +form. This breaks list passwords for all existing pre-Mailman 2.1 lists, and +since those passwords aren't stored anywhere in plain text, they cannot be +retrieved and updated. + +Thus, this script generates new passwords for a list, and optionally sends it +to all the owners of the list.""")) + parser.add_option('-a', '--all', + default=False, action='store_true', + help_('Change the password for all lists')) + parser.add_option('-d', '--domain', + default=[], type='string', action='append', + dest='domains', help=_("""\ +Change the password for all lists in the virtual domain DOMAIN. It is okay +to give multiple -d options.""")) + parser.add_option('-l', '--listname', + default=[], type='string', action='append', + dest='listnames', help=_("""\ +Change the password only for the named list. It is okay to give multiple -l +options.""")) + parser.add_option('-p', '--password', + type='string', metavar='NEWPASSWORD', help=_("""\ +Use the supplied plain text password NEWPASSWORD as the new password for any +lists that are being changed (as specified by the -a, -d, and -l options). If +not given, lists will be assigned a randomly generated new password.""")) + parser.add_option('-q', '--quiet', + default=False, action='store_true', help=_("""\ +Don't notify list owners of the new password. You'll have to have some other +way of letting the list owners know the new password (presumably +out-of-band).""")) + opts, args = parser.parse_args() + if args: + parser.print_help() + print >> sys.stderr, _('Unexpected arguments') + sys.exit(1) + if opts.password == '': + parser.print_help() + print >> sys.stderr, _('Empty list passwords are not allowed') + sys.exit(1) + return parser, opts, args _listcache = {} +_missing = object() def openlist(listname): missing = [] - mlist = _listcache.get(listname, missing) - if mlist is missing: + mlist = _listcache.get(listname, _missing) + if mlist is _missing: try: - mlist = MailList.MailList(listname, lock=0) - except Errors.MMListError, e: - usage(1, _('No such list "%(listname)s"\n%(e)s')) + mlist = MailList.MailList(listname, lock=False) + except Errors.MMListError: + print >> sys.stderr, _('No such list: $listname') + return None _listcache[listname] = mlist return mlist def main(): - # Parse options - try: - opts, args = getopt.getopt( - sys.argv[1:], 'ad:l:p:qh', - ['all', 'domain=', 'listname=', 'password=', 'quiet', 'help']) - except getopt.error, msg: - usage(1, msg) - - # defaults - listnames = {} - domains = {} - password = None - quiet = 0 - - for opt, arg in opts: - if opt in ('-h', '--help'): - usage(0) - elif opt in ('-a', '--all'): - for name in Utils.list_names(): - listnames[name] = 1 - elif opt in ('-d', '--domain'): - domains[arg] = 1 - elif opt in ('-l', '--listname'): - listnames[arg] = 1 - elif opt in ('-p', '--password'): - password = arg - elif opt in ('-q', '--quiet'): - quiet = 1 + parser, opts, args = parseargs() - if args: - strargs = SPACE.join(args) - usage(1, _('Bad arguments: %(strargs)s')) - - if password is not None: - if not password: - usage(1, _('Empty list passwords are not allowed')) - shapassword = sha.new(password).hexdigest() + # Cull duplicates + domains = set(opts.domains) + if opts.all: + listnames = set(Utils.list_names()) + else: + listnames = set(opts.listnames) if domains: for name in Utils.list_names(): mlist = openlist(name) - if domains.has_key(mlist.host_name): - listnames[name] = 1 + if mlist.host_name in domains: + listnames.add(name) if not listnames: print >> sys.stderr, _('Nothing to do.') sys.exit(0) # Set the password on the lists - for listname in listnames.keys(): + if opts.password: + shapassword = sha.new(password).hexdigest() + + for listname in listnames: mlist = openlist(listname) mlist.Lock() try: - if password is None: + if opts.password is None: randompw = Utils.MakeRandomPassword( mm_cfg.ADMIN_PASSWORD_LENGTH) shapassword = sha.new(randompw).hexdigest() @@ -177,27 +147,27 @@ def main(): mlist.Unlock() # Notification - print _('New %(listname)s password: %(notifypassword)s') + print _('New $listname password: $notifypassword') if not quiet: otrans = i18n.get_translation() i18n.set_language(mlist.preferred_language) try: hostname = mlist.host_name - adminurl = mlist.GetScriptURL('admin', absolute=1) + adminurl = mlist.GetScriptURL('admin', absolute=True) msg = Message.UserNotification( mlist.owner[:], Utils.get_site_email(), - _('Your new %(listname)s list password'), + _('Your new $listname list password'), _('''\ -The site administrator at %(hostname)s has changed the password for your -mailing list %(listname)s. It is now +The site administrator at $hostname has changed the password for your +mailing list $listname. It is now - %(notifypassword)s + $notifypassword Please be sure to use this for all future list administration. You may want to log in now to your list and change the password to something more to your liking. Visit your list admin page at - %(adminurl)s + $adminurl '''), mlist.preferred_language) finally: diff --git a/bin/show_qfiles b/Mailman/bin/show_qfiles index 0dbe9fe0b..f2ec819c1 100644 --- a/bin/show_qfiles +++ b/Mailman/bin/show_qfiles @@ -1,5 +1,3 @@ -#! @PYTHON@ -# # Copyright (C) 2006 by the Free Software Foundation, Inc. # # This program is free software; you can redistribute it and/or @@ -17,63 +15,33 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, # USA. -"""Show the contents of one or more Mailman queue files. - -Usage: show_qfiles [options] qfile ... - -Options: - - -q / --quiet - Don't print `helpful' message delimiters. - - -h / --help - Print this text and exit. - -Example: show_qfiles qfiles/shunt/*.pck -""" - import sys -import getopt +import optparse from cPickle import load -import paths from Mailman.i18n import _ -try: - True, False -except NameError: - True = 1 - False = 0 +__i18_templates__ = True -def usage(code, msg=''): - if code: - fd = sys.stderr - else: - fd = sys.stdout - print >> fd, _(__doc__) - if msg: - print >> fd, msg - sys.exit(code) +def parseargs(): + parser = optparse.OptionParser(version=mm_cfg.MAILMAN_VERSION, + usage=_("""\ +%%prog [options] qfiles ... + +Show the contents of one or more Mailman queue files.""")) + parser.add_option('-q', '--quiet', + default=False, action='store_true', + help=_("Don't print 'helpful' message delimiters.")) + opts, args = parser.parse_args() + return parser, opts, args + def main(): - try: - opts, args = getopt.getopt(sys.argv[1:], 'hq', ['help', 'quiet']) - except getopt.error, msg: - usage(1, msg) - - quiet = False - for opt, arg in opts: - if opt in ('-h', '--help'): - usage(0) - elif opt in ('-q', '--quiet'): - quiet = True - - if not args: - usage(1, "Not enough arguments") + parser, opts, args = parseargs() for filename in args: if not quiet: diff --git a/bin/Makefile.in b/bin/Makefile.in index 2cc6c41c4..9be471942 100644 --- a/bin/Makefile.in +++ b/bin/Makefile.in @@ -48,12 +48,13 @@ SCRIPTS= mmshell add_members \ remove_members clone_member update \ sync_members check_db withlist check_perms find_member \ version config_list dumpdb cleanarch \ - list_admins genaliases change_pw mailmanctl qrunner inject \ + list_admins genaliases mailmanctl qrunner inject \ fix_url.py convert.py transcheck \ - list_owners msgfmt.py show_qfiles discard rb-archfix \ + list_owners msgfmt.py discard rb-archfix \ reset_pw.py templ2pot.py po2templ.py -LN_SCRIPTS= arch list_lists list_members mmsitepass newlist rmlist unshunt +LN_SCRIPTS= arch change_pw list_lists list_members mmsitepass newlist \ + rmlist show_qfiles unshunt BUILDDIR= ../build/bin @@ -1,5 +1,5 @@ #! /bin/sh -# From configure.in Revision: 7881 . +# From configure.in Revision: 7882 . # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.59. # @@ -4277,7 +4277,6 @@ done SCRIPTS="build/bin/add_members:bin/add_members \ -build/bin/change_pw:bin/change_pw \ build/bin/check_db:bin/check_db \ build/bin/check_perms:bin/check_perms \ build/bin/cleanarch:bin/cleanarch \ @@ -4299,7 +4298,6 @@ build/bin/pygettext.py:bin/pygettext.py \ build/bin/qrunner:bin/qrunner \ build/bin/remove_members:bin/remove_members \ build/bin/reset_pw.py:bin/reset_pw.py \ -build/bin/show_qfiles:bin/show_qfiles \ build/bin/sync_members:bin/sync_members \ build/bin/transcheck:bin/transcheck \ build/bin/update:bin/update \ diff --git a/configure.in b/configure.in index 34aee4ab9..fe8ba0936 100644 --- a/configure.in +++ b/configure.in @@ -15,7 +15,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. dnl Process this file with autoconf to produce a configure script. -AC_REVISION($Revision: 7882 $) +AC_REVISION($Revision: 7886 $) AC_PREREQ(2.0) AC_INIT(src/common.h) @@ -595,7 +595,6 @@ dnl Expand PYTHON path in the scripts, output into build/scriptname AC_DEFUN(MM_SCRIPTS, [dnl bin/add_members \ -bin/change_pw \ bin/check_db \ bin/check_perms \ bin/cleanarch \ @@ -617,7 +616,6 @@ bin/pygettext.py \ bin/qrunner \ bin/remove_members \ bin/reset_pw.py \ -bin/show_qfiles \ bin/sync_members \ bin/transcheck \ bin/update \ |
