Commit | Line | Data |
---|---|---|
21d921a5 AC |
1 | (* HCoop Domtool (http://hcoop.sourceforge.net/) |
2 | * Copyright (c) 2006, Adam Chlipala | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or | |
5 | * modify it under the terms of the GNU General Public License | |
6 | * as published by the Free Software Foundation; either version 2 | |
7 | * of the License, or (at your option) any later version. | |
8 | * | |
9 | * This program is distributed in the hope that it will be useful, | |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License | |
15 | * along with this program; if not, write to the Free Software | |
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 | *) | |
18 | ||
19 | (* Code for receiving and executing configuration files *) | |
20 | ||
21 | structure Client :> CLIENT = struct | |
22 | ||
23 | datatype passwd_result = | |
24 | Passwd of string | |
25 | | Aborted | |
26 | | Error | |
27 | ||
28 | fun getpass () = | |
29 | let | |
30 | val tty = Posix.FileSys.stdin | |
931aae14 | 31 | val termios = Posix.TTY.TC.getattr tty |
21d921a5 AC |
32 | val fields = Posix.TTY.fieldsOf termios |
33 | ||
34 | val termios' = Posix.TTY.termios {iflag = #iflag fields, | |
35 | oflag = #oflag fields, | |
36 | cflag = #cflag fields, | |
37 | lflag = Posix.TTY.L.flags [Posix.TTY.L.clear (Posix.TTY.L.echo, #lflag fields), | |
38 | Posix.TTY.L.echonl, | |
39 | Posix.TTY.L.icanon], | |
40 | cc = #cc fields, | |
41 | ispeed = #ispeed fields, | |
42 | ospeed = #ospeed fields} | |
43 | ||
931aae14 | 44 | fun reset () = Posix.TTY.TC.setattr (tty, Posix.TTY.TC.sanow, termios) |
21d921a5 AC |
45 | in |
46 | print " Password: "; | |
47 | TextIO.flushOut TextIO.stdOut; | |
931aae14 | 48 | Posix.TTY.TC.setattr (tty, Posix.TTY.TC.sanow, termios'); |
21d921a5 AC |
49 | case TextIO.inputLine TextIO.stdIn of |
50 | NONE => (reset (); | |
51 | Aborted) | |
52 | | SOME pass => | |
53 | (print "Confirm password: "; | |
54 | TextIO.flushOut TextIO.stdOut; | |
55 | case TextIO.inputLine TextIO.stdIn of | |
56 | NONE => (reset (); | |
57 | Aborted) | |
58 | | SOME pass' => | |
59 | (reset (); | |
60 | if pass = pass' then | |
61 | Passwd (String.substring (pass, 0, size pass - 1)) | |
62 | else | |
63 | (print "Passwords don't match!\n"; | |
64 | Error))) | |
65 | end | |
66 | ||
67 | end |