From f391f15cc33046d202754ea8c104f04729e4a79e Mon Sep 17 00:00:00 2001 From: Clinton Ebadi Date: Sun, 5 Oct 2014 23:14:25 -0400 Subject: [PATCH 1/1] portal: Use readLine and not getPass when stdin is not a terminal It is way harder than neccessary to make the portal call domtool-portal when it spews output. Just assume input produced via a pipe is from a program that knows what it is doing. --- src/main-portal.sml | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/src/main-portal.sml b/src/main-portal.sml index 93f7612..068d16c 100644 --- a/src/main-portal.sml +++ b/src/main-portal.sml @@ -29,16 +29,31 @@ fun die reason = (printerr reason; printerr "\n"; OS.Process.exit OS.Process.fai val _ = case CommandLine.arguments () of ["vmailpasswd", domain, user] => - (case Client.getpass () of - Client.Passwd oldpasswd => - (case Client.getpass () of - Client.Passwd newpasswd => - Main.requestPortalPasswdMailbox {domain = domain, - user = user, - oldpasswd = oldpasswd, - newpasswd = newpasswd} - | Client.Aborted => die "Aborted" - | Client.Error => die "New passwords did not match") - | _ => die "Error entering old password") + if (Client.hastty ()) + then + (case Client.getpass () of + Client.Passwd oldpasswd => + (case Client.getpass () of + Client.Passwd newpasswd => + Main.requestPortalPasswdMailbox {domain = domain, + user = user, + oldpasswd = oldpasswd, + newpasswd = newpasswd} + | Client.Aborted => die "Aborted" + | Client.Error => die "New passwords did not match") + | _ => die "Error entering old password") + else + let + val oldpasswd = TextIO.inputLine TextIO.stdIn + val newpasswd = TextIO.inputLine TextIO.stdIn + in + case (oldpasswd, newpasswd) of + (SOME oldpasswd, SOME newpasswd) => + Main.requestPortalPasswdMailbox {domain = domain, + user = user, + oldpasswd = String.substring (oldpasswd, 0, size oldpasswd - 1), + newpasswd = String.substring (newpasswd, 0, size newpasswd - 2)} + | _ => die "Invalid input" + end | _ => die "Invalid command-line arguments" -- 2.20.1