aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ssh/src/ssh_io.erl
diff options
context:
space:
mode:
authorErlang/OTP <[email protected]>2016-06-22 14:15:18 +0200
committerErlang/OTP <[email protected]>2016-06-22 14:15:18 +0200
commitc5e8ddfec9757e44513dceaac5a00e112bb4a4e4 (patch)
tree4d7416f210e1a54e7ef95ee3aa6c3181a333fe96 /lib/ssh/src/ssh_io.erl
parent53e7743216647d810d529e397bd3ea7278c6047c (diff)
parent76c968d9a0f667ea3e112676861f5dc399113dae (diff)
downloadotp-c5e8ddfec9757e44513dceaac5a00e112bb4a4e4.tar.gz
otp-c5e8ddfec9757e44513dceaac5a00e112bb4a4e4.tar.bz2
otp-c5e8ddfec9757e44513dceaac5a00e112bb4a4e4.zip
Merge branch 'hans/ssh/retry_pwd_patch/OTP-13674' into maint-18
* hans/ssh/retry_pwd_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.erl52
1 files changed, 24 insertions, 28 deletions
diff --git a/lib/ssh/src/ssh_io.erl b/lib/ssh/src/ssh_io.erl
index a5e627fdb3..5e335c2063 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.
-
-
-