[Mailman-Developers] password from a tty

Scott scott@chronis.icgroup.com
Mon, 3 Aug 1998 23:48:30 -0400


here's a patch that will get passwords from a tty with echo off for
mmsitepass and newlist only if it's possible, otherwise it gets the
password the normal, more portable, less secure way.

scott


diff -c Mailman/Utils.py /home/mm/Mailman/Utils.py 
*** Mailman/Utils.py	Mon Jul 27 18:48:31 1998
--- /home/mm/Mailman/Utils.py	Mon Aug  3 23:27:55 1998
***************
*** 429,431 ****
--- 429,476 ----
      if raw:
          return template % dict
      return wrap(template % dict)
+ 
+ 
+ def getapwtty(prmpt="Password: "):
+     wrote_prmpt = 0
+     try:
+         import termios, TERMIOS
+         fd = sys.stdin.fileno()
+         org = termios.tcgetattr(fd)
+         new = termios.tcgetattr(fd)
+         new[3] = new[3] & ~TERMIOS.ECHO
+         termios.tcsetattr(fd, TERMIOS.TCSANOW, new)
+         sys.stdout.write(prmpt)
+         sys.stdout.flush()
+         wrote_prmpt = 1
+         pw = string.strip(raw_input())
+         sys.stdout.write("\n")
+         sys.stdout.flush()
+         termios.tcsetattr(fd, TERMIOS.TCSAFLUSH, org)
+         return pw
+     except:
+         if wrote_prmpt:
+             prmpt = ""
+         pw = string.strip(raw_input(prmtp))
+     return pw
+ 
+ def getpw():
+     while 1:
+         pw1 = getapwtty()
+         pw2 = getapwtty("Verify: ")
+         if pw1 == pw2:
+             break
+         else:
+             print "passwords didn't match, try again"
+     return pw1
+ 
+ 
+     
+         
+ 
+ 
+ 
+ 
+ 
+ 
+ 

diff -c bin/mmsitepass /home/mm/bin/mmsitepass 
*** bin/mmsitepass	Mon Jul 27 18:48:31 1998
--- /home/mm/bin/mmsitepass	Mon Aug  3 23:32:11 1998
***************
*** 22,38 ****
  administrator's password can be used, which in turn can be used in most
  places that a list users password can be used."""
  
- import sys
  import paths
  from Mailman import MailList
  
! def main(argv):
!     if len(sys.argv) != 2:
!         print "Usage: mmsitepass password"
!         raise SystemExit, 1
      l = MailList.MailList()
!     l.SetSiteAdminPassword(sys.argv[1])
!     if l.CheckSiteAdminPassword(sys.argv[1]):
          print "Password changed."
          raise SystemExit, 0
      else:
--- 22,36 ----
  administrator's password can be used, which in turn can be used in most
  places that a list users password can be used."""
  
  import paths
  from Mailman import MailList
+ from Mailman.Utils import getpw
  
! def main():
!     print "enter a site password for mailman"
!     pw = getpw()
      l = MailList.MailList()
!     if l.CheckSiteAdminPassword(pw):
          print "Password changed."
          raise SystemExit, 0
      else:
***************
*** 40,43 ****
          raise SystemExit, 1
  
  if __name__ == "__main__":
!     main(sys.argv)
--- 38,48 ----
          raise SystemExit, 1
  
  if __name__ == "__main__":
!     main()
! 
! 
! 
! 
! 
! 
! 

diff -c bin/newlist /home/mm/bin/newlist
*** bin/newlist	Mon Jul 27 18:48:31 1998
--- /home/mm/bin/newlist	Mon Aug  3 23:33:22 1998
***************
*** 71,77 ****
      if len(argv) > 3:
  	list_pw = argv[3]
      else:
! 	list_pw = raw_input("Enter the initial list password: ")
  
      newlist = MailList.MailList()
      pw = crypt(list_pw , Utils.GetRandomSeed())
--- 71,78 ----
      if len(argv) > 3:
  	list_pw = argv[3]
      else:
! 	print "Please Enter the initial list password."
! 	list_pw = Utils.getpw()
  
      newlist = MailList.MailList()
      pw = crypt(list_pw , Utils.GetRandomSeed())