r22879 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r22878‎ | r22879 | r22880 >
Date:12:42, 10 June 2007
Author:Mark Bergsma
Status:old
Tags:
Comment:
Support password prompting
Modified paths:
  • /trunk/wmfmailadmin/wmfmailadmin.py (modified) (history)

Diff [purge]

Index: trunk/wmfmailadmin/wmfmailadmin.py
@@ -5,7 +5,7 @@
66 Written by Mark Bergsma <mark@wikimedia.org>
77 """
88
9 -import sys
 9+import sys, os
1010
1111 dbname = 'user.db'
1212 conn = None
@@ -22,7 +22,7 @@
2323 fieldmappings = {
2424 # Option: ( fieldname, description, default )
2525 'e': ('email', "E-mail address", None),
26 - 'p': ('password', "Password", None),
 26+ 'p': ('password', "Password", '-'),
2727 'r': ('realname', "Real name", None),
2828 'i': ('id', "Id", None),
2929 'q': ('quota', "Quota", 2**30/1024),
@@ -33,6 +33,8 @@
3434
3535 updateables = ('password', 'quota', 'realname', 'active')
3636
 37+supported_hash_algorithms = ('{SHA1}')
 38+
3739 def list_accounts(fields):
3840 """
3941 List accounts in the database
@@ -74,17 +76,20 @@
7577
7678 global conn, longmappings, updateables
7779
78 - required_fields = ('email', 'password', 'realname')
 80+ required_fields = ('email', 'realname') # password will be prompted for if needed
7981 require_fields( (required_fields, ), fields)
8082
8183 # Set default values for fields not given
82 - value_fields = ['localpart', 'domain', 'password', 'realname']
 84+ value_fields = ['localpart', 'domain', 'realname']
8385 for fieldname in updateables:
8486 default = longmappings[fieldname][2]
8587 if fieldname not in fields and default is not None:
8688 fields[fieldname] = default
8789 value_fields.append(fieldname)
8890
 91+ # Input password if needed
 92+ password_input(fields)
 93+
8994 # Construct list of fields that are either given, or should get default values
9095 values_list = "(" + ", ".join(value_fields) + ") VALUES (:" + ", :".join(value_fields) + ")"
9196
@@ -115,6 +120,9 @@
116121
117122 require_fields( (('id', ), ('email', )), fields)
118123 require_fields( (('password', ), ('realname', ), ('quota', ), ('active', ), ), fields)
 124+
 125+ # Input password if needed
 126+ password_input(fields)
119127
120128 # Build UPDATE clause from update arguments
121129 update_clause = " AND ".join(
@@ -151,6 +159,26 @@
152160 # TODO: syntax checking
153161 return fields
154162
 163+def password_input(fields):
 164+ """
 165+ Checks if the password argument on the commandline was "-",
 166+ and prompts for a password if that is the case
 167+ """
 168+
 169+ global supported_hash_algorithms
 170+
 171+ if fields['password'] != '-': return
 172+
 173+ # Simply outsource to dovecotpw
 174+ pipe = os.popen('dovecotpw -s sha1', 'r')
 175+ password = pipe.readline().rstrip('\n')
 176+ rval = pipe.close()
 177+ if rval is None and password.startswith(supported_hash_algorithms):
 178+ fields['password'] = password
 179+ else:
 180+ raise Exception("Problem invoking dovecotpw")
 181+
 182+
155183 def add_index(dct, fieldindex):
156184 """
157185 Expects: a dict containing tuples

Status & tagging log