[Zope-Checkins] CVS: ZODB3/ZEO - zpasswd.py:1.1.2.2

Jeremy Hylton jeremy@zope.com
Tue, 13 May 2003 17:06:50 -0400


Update of /cvs-repository/ZODB3/ZEO
In directory cvs.zope.org:/tmp/cvs-serv13706

Modified Files:
      Tag: ZODB3-auth-branch
	zpasswd.py 
Log Message:
Update to work with auth_digest.


=== ZODB3/ZEO/zpasswd.py 1.1.2.1 => 1.1.2.2 ===
--- ZODB3/ZEO/zpasswd.py:1.1.2.1	Tue Apr 29 16:02:54 2003
+++ ZODB3/ZEO/zpasswd.py	Tue May 13 17:06:50 2003
@@ -1,3 +1,4 @@
+#!python
 ##############################################################################
 #
 # Copyright (c) 2003 Zope Corporation and Contributors.
@@ -20,17 +21,17 @@
  -c  Create a new file.
  -d  Delete user
  -n  Don't update file; display results on stdout.
- -b  Use the password from the command line rather than prompting for it."""
+ -b  Use the password from the command line rather than prompting for it.
+ 
+ -f/--format format  Specify the database format: srp or digest
+"""
 
 import sys
 import getopt
 import getpass
 
-from ZEO.auth.database import Database
-#from ZEO.auth.srp import SRPDatabase
-   
 try:
-    opts, args = getopt.getopt(sys.argv[1:], 'cdnbs')
+    opts, args = getopt.getopt(sys.argv[1:], "cdnbsf", ["--format"])
 except getopt.GetoptError:
     # print help information and exit:
     print __doc__
@@ -40,7 +41,13 @@
 create = 0
 delete = 0
 prompt = 1
-#srp = 0
+
+class Format:
+    plain = "plain"
+    srp = "srp"
+    digest = "digest"
+
+format = Format.plain
 
 for opt, arg in opts:
     if opt in ("-h", "--help"):
@@ -52,10 +59,18 @@
         create = 1
     if opt == "-d":
         delete = 1
-    if opt == "b":
+    if opt == "-b":
         prompt = 0
-#    if opt == "-s":
-#        srp = 1
+    if opt == "-f":
+        arg = arg.lower()
+        if arg == "srp":
+            format = Format.srp
+        elif arg == "digest":
+            format = Format.digest
+        else:
+            print "Invalid format", arg
+            print __doc__
+            sys.exit(2)
 
 if create and delete:
     print "Can't create and delete at the same time"
@@ -78,9 +93,13 @@
     else:
         password = args[2]
 
-#if srp:
-#    db = SRPDatabase(output)
-#else:
+if format == Format.plain:
+    from ZEO.auth.database import Database
+elif format == Format.srp:
+    from ZEO.auth.auth_srp import SRPDatabase as Database
+elif format == Format.digest:
+    from ZEO.auth.auth_digest import DigestDatabase as Database
+
 db = Database(output)
 
 if create:
@@ -104,4 +123,3 @@
         db.save(fd=sys.stdout)
     else:
         db.save()
-