summaryrefslogtreecommitdiff
path: root/mailman/bin/mmsitepass.py
diff options
context:
space:
mode:
authorBarry Warsaw2008-02-27 01:26:18 -0500
committerBarry Warsaw2008-02-27 01:26:18 -0500
commita1c73f6c305c7f74987d99855ba59d8fa823c253 (patch)
tree65696889450862357c9e05c8e9a589f1bdc074ac /mailman/bin/mmsitepass.py
parent3f31f8cce369529d177cfb5a7c66346ec1e12130 (diff)
downloadmailman-a1c73f6c305c7f74987d99855ba59d8fa823c253.tar.gz
mailman-a1c73f6c305c7f74987d99855ba59d8fa823c253.tar.zst
mailman-a1c73f6c305c7f74987d99855ba59d8fa823c253.zip
Diffstat (limited to 'mailman/bin/mmsitepass.py')
-rw-r--r--mailman/bin/mmsitepass.py113
1 files changed, 113 insertions, 0 deletions
diff --git a/mailman/bin/mmsitepass.py b/mailman/bin/mmsitepass.py
new file mode 100644
index 000000000..c9a5f7ade
--- /dev/null
+++ b/mailman/bin/mmsitepass.py
@@ -0,0 +1,113 @@
+# Copyright (C) 1998-2008 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
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# 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.
+
+import sys
+import getpass
+import optparse
+
+from mailman import Utils
+from mailman import Version
+from mailman import passwords
+from mailman.configuration import config
+from mailman.i18n import _
+from mailman.initialize import initialize
+
+
+
+def parseargs():
+ parser = optparse.OptionParser(version=Version.MAILMAN_VERSION,
+ usage=_("""\
+%prog [options] [password]
+
+Set the site or list creator password.
+
+The site password can be used in most if not all places that the list
+administrator's password can be used, which in turn can be used in most places
+that a list user's password can be used. The list creator password is a
+separate password that can be given to non-site administrators to delegate the
+ability to create new mailing lists.
+
+If password is not given on the command line, it will be prompted for.
+"""))
+ parser.add_option('-c', '--listcreator',
+ default=False, action='store_true',
+ help=_("""\
+Set the list creator password instead of the site password. The list
+creator is authorized to create and remove lists, but does not have
+the total power of the site administrator."""))
+ parser.add_option('-p', '--password-scheme',
+ default='', 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=_("""\
+List the supported password hashing schemes and exit. The scheme labels are
+case-insensitive."""))
+ parser.add_option('-C', '--config',
+ help=_('Alternative configuration file to use'))
+ opts, args = parser.parse_args()
+ if len(args) > 1:
+ parser.error(_('Unexpected arguments'))
+ if opts.list_hash_schemes:
+ for label in passwords.Schemes:
+ print str(label).upper()
+ sys.exit(0)
+ return parser, opts, args
+
+
+def check_password_scheme(parser, password_scheme):
+ # shoule be checked after config is loaded.
+ if password_scheme == '':
+ password_scheme = config.PASSWORD_SCHEME
+ scheme = passwords.lookup_scheme(password_scheme.lower())
+ if not scheme:
+ parser.error(_('Invalid password scheme'))
+ return scheme
+
+
+
+def main():
+ parser, opts, args = parseargs()
+ initialize(opts.config)
+ opts.password_scheme = check_password_scheme(parser, opts.password_scheme)
+ if args:
+ password = args[0]
+ else:
+ # Prompt for the password
+ if opts.listcreator:
+ prompt_1 = _('New list creator password: ')
+ else:
+ prompt_1 = _('New site administrator password: ')
+ pw1 = getpass.getpass(prompt_1)
+ pw2 = getpass.getpass(_('Enter password again to confirm: '))
+ if pw1 <> pw2:
+ print _('Passwords do not match; no changes made.')
+ sys.exit(1)
+ password = pw1
+ Utils.set_global_password(password,
+ not opts.listcreator, opts.password_scheme)
+ if Utils.check_global_password(password, not opts.listcreator):
+ print _('Password changed.')
+ else:
+ print _('Password change failed.')
+
+
+
+if __name__ == '__main__':
+ main()