From: Clinton Ebadi Date: Mon, 6 Oct 2014 03:14:25 +0000 (-0400) Subject: portal: Use readLine and not getPass when stdin is not a terminal X-Git-Tag: release_20141005^2~3 X-Git-Url: https://git.hcoop.net/hcoop/domtool2.git/commitdiff_plain/f391f15cc33046d202754ea8c104f04729e4a79e?ds=inline 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. --- 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"