diff options
author | Erlang/OTP <[email protected]> | 2016-06-29 17:42:52 +0200 |
---|---|---|
committer | Erlang/OTP <[email protected]> | 2016-06-29 17:42:52 +0200 |
commit | 10991ae10b85d65215aaf570127c29d1e48a2e62 (patch) | |
tree | 54d6c25fd4e1a4b04db5039f43e0bfb473d4af1e /lib/ssh/src/ssh_io.erl | |
parent | 932cda08f6a1e08fd908097276fd10529b7d8e29 (diff) | |
parent | e6e8b9bd005910ba3840b5ff154e37d5e1366a8b (diff) | |
download | otp-10991ae10b85d65215aaf570127c29d1e48a2e62.tar.gz otp-10991ae10b85d65215aaf570127c29d1e48a2e62.tar.bz2 otp-10991ae10b85d65215aaf570127c29d1e48a2e62.zip |
Merge branch 'hans/ssh/retry_passwd_patch/OTP-13674' into maint-19
* hans/ssh/retry_passwd_patch/OTP-13674:
ssh: update vsn.mk
ssh: polishing of password prompt's linefeed
ssh: Fix a hazard bug in ssh_auth
ssh: Some code cuddling in ssh_io
ssh: Fix type error in args of ssh_auth:sort_selected_mthds
ssh: Make client send a faulty pwd only once, ssh_connection_handler part
ssh: Make client send a faulty pwd only once, ssh_auth part
ssh: test cases for no repetition of bad passwords
Diffstat (limited to 'lib/ssh/src/ssh_io.erl')
-rw-r--r-- | lib/ssh/src/ssh_io.erl | 52 |
1 files changed, 24 insertions, 28 deletions
diff --git a/lib/ssh/src/ssh_io.erl b/lib/ssh/src/ssh_io.erl index 026d0f6151..1d8f370884 100644 --- a/lib/ssh/src/ssh_io.erl +++ b/lib/ssh/src/ssh_io.erl @@ -31,56 +31,55 @@ read_line(Prompt, Ssh) -> format("~s", [listify(Prompt)]), proplists:get_value(user_pid, Ssh) ! {self(), question}, receive - Answer -> + Answer when is_list(Answer) -> Answer end. yes_no(Prompt, Ssh) -> - io:format("~s [y/n]?", [Prompt]), + format("~s [y/n]?", [Prompt]), proplists:get_value(user_pid, Ssh#ssh.opts) ! {self(), question}, receive - Answer -> + %% I can't see that the atoms y and n are ever received, but it must + %% be investigated before removing + y -> yes; + n -> no; + + Answer when is_list(Answer) -> case trim(Answer) of "y" -> yes; "n" -> no; "Y" -> yes; "N" -> no; - y -> yes; - n -> no; _ -> - io:format("please answer y or n\n"), + format("please answer y or n\n",[]), yes_no(Prompt, Ssh) end end. -read_password(Prompt, Ssh) -> +read_password(Prompt, #ssh{opts=Opts}) -> read_password(Prompt, Opts); +read_password(Prompt, Opts) when is_list(Opts) -> format("~s", [listify(Prompt)]), - case is_list(Ssh) of - false -> - proplists:get_value(user_pid, Ssh#ssh.opts) ! {self(), user_password}; - _ -> - proplists:get_value(user_pid, Ssh) ! {self(), user_password} - end, + proplists:get_value(user_pid, Opts) ! {self(), user_password}, receive - Answer -> - case Answer of - "" -> - read_password(Prompt, Ssh); - Pass -> Pass - end + Answer when is_list(Answer) -> + case trim(Answer) of + "" -> + read_password(Prompt, Opts); + Pwd -> + Pwd + end end. -listify(A) when is_atom(A) -> - atom_to_list(A); -listify(L) when is_list(L) -> - L; -listify(B) when is_binary(B) -> - binary_to_list(B). format(Fmt, Args) -> io:format(Fmt, Args). +%%%================================================================ +listify(A) when is_atom(A) -> atom_to_list(A); +listify(L) when is_list(L) -> L; +listify(B) when is_binary(B) -> binary_to_list(B). + trim(Line) when is_list(Line) -> lists:reverse(trim1(lists:reverse(trim1(Line)))); @@ -93,6 +92,3 @@ trim1([$\r|Cs]) -> trim(Cs); trim1([$\n|Cs]) -> trim(Cs); trim1([$\t|Cs]) -> trim(Cs); trim1(Cs) -> Cs. - - - |