Add vmail command for changing password when you know the current password
[hcoop/domtool2.git] / scripts / domtool-vmailpasswd
diff --git a/scripts/domtool-vmailpasswd b/scripts/domtool-vmailpasswd
new file mode 100755 (executable)
index 0000000..1ebb365
--- /dev/null
@@ -0,0 +1,27 @@
+#!/usr/bin/python2
+# -*- python -*-
+
+# Helper for domtool to check if a vmail password matches the stored
+# password, before allowing the portal to change the password. This
+# should never be run manually, since it does not suppress echoing of
+# anything entered.
+
+import crypt, getpass, sys
+
+def getpasswords ():
+   crypted = raw_input()
+   clear = raw_input()
+   return (crypted, clear)
+
+def checkpassword (crypted, clear):
+    return crypt.crypt (clear, crypted) == crypted
+
+def main ():
+    (crypted, clear) = getpasswords ()
+    if checkpassword (crypted, clear):
+        sys.exit ()
+    else:
+        sys.exit (1)
+
+if __name__ == "__main__":
+    main ()