Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge branch 'ia/ssh/options-check-OTP-10061' into maint

* ia/ssh/options-check-OTP-10061:
  Corrected ssh option handling
  • Loading branch information...
commit 33fe8806939849c47b8ec5de91b8e8ef94a9f1df 2 parents e3c9c6a + b85e884
Ingela Andin authored April 24, 2012
20  lib/ssh/src/ssh.erl
@@ -346,8 +346,9 @@ handle_option([{role, _} = Opt | Rest], SocketOptions, SshOptions) ->
346 346
     handle_option(Rest, SocketOptions, [handle_ssh_option(Opt) | SshOptions]);
347 347
 handle_option([{compression, _} = Opt | Rest], SocketOptions, SshOptions) ->
348 348
     handle_option(Rest, SocketOptions, [handle_ssh_option(Opt) | SshOptions]);
349  
-handle_option([{allow_user_interaction, _} = Opt | Rest], SocketOptions, SshOptions) ->
350  
-    handle_option(Rest, SocketOptions, [handle_ssh_option(Opt) | SshOptions]);
  349
+%%Backwards compatibility
  350
+handle_option([{allow_user_interaction, Value}  | Rest], SocketOptions, SshOptions) ->
  351
+    handle_option(Rest, SocketOptions, [handle_ssh_option({user_interaction, Value}) | SshOptions]);
351 352
 handle_option([{infofun, _} = Opt | Rest],SocketOptions, SshOptions) ->
352 353
     handle_option(Rest, SocketOptions, [handle_ssh_option(Opt) | SshOptions]);
353 354
 handle_option([{connectfun, _} = Opt | Rest], SocketOptions, SshOptions) ->
@@ -366,6 +367,8 @@ handle_option([{ssh_cli, _} = Opt | Rest], SocketOptions, SshOptions) ->
366 367
     handle_option(Rest, SocketOptions, [handle_ssh_option(Opt) | SshOptions]);
367 368
 handle_option([{shell, _} = Opt | Rest], SocketOptions, SshOptions) ->
368 369
     handle_option(Rest, SocketOptions, [handle_ssh_option(Opt) | SshOptions]);
  370
+handle_option([{exec, _} = Opt | Rest], SocketOptions, SshOptions) ->
  371
+    handle_option(Rest, SocketOptions, [handle_ssh_option(Opt) | SshOptions]);
369 372
 handle_option([Opt | Rest], SocketOptions, SshOptions) ->
370 373
     handle_option(Rest, [handle_inet_option(Opt) | SocketOptions], SshOptions).
371 374
 
@@ -401,8 +404,9 @@ handle_ssh_option({key_cb, Value} = Opt)  when is_atom(Value) ->
401 404
     Opt;
402 405
 handle_ssh_option({compression, Value} = Opt) when is_atom(Value) ->
403 406
     Opt;
404  
-handle_ssh_option({allow_user_interaction, Value} = Opt) when Value == true;
405  
-							      Value == false ->
  407
+handle_ssh_option({exec, {Module, Function, _}} = Opt) when is_atom(Module), 
  408
+							    is_atom(Function) ->
  409
+
406 410
     Opt;
407 411
 handle_ssh_option({infofun, Value} = Opt)  when is_function(Value) ->
408 412
     Opt;
@@ -412,11 +416,12 @@ handle_ssh_option({disconnectfun , Value} = Opt) when is_function(Value) ->
412 416
     Opt;
413 417
 handle_ssh_option({failfun, Value} = Opt) when is_function(Value) ->
414 418
     Opt;
415  
-handle_ssh_option({ip_v6_disabled, Value} = Opt) when is_function(Value) ->
  419
+handle_ssh_option({ip_v6_disabled, Value} = Opt) when Value == true;
  420
+						      Value == false ->
416 421
     Opt;
417 422
 handle_ssh_option({transport, {Protocol, Cb, ClosTag}} = Opt) when is_atom(Protocol),
418  
-							     is_atom(Cb),
419  
-							     is_atom(ClosTag) ->
  423
+								   is_atom(Cb),
  424
+								   is_atom(ClosTag) ->
420 425
     Opt;
421 426
 handle_ssh_option({subsystems, Value} = Opt) when is_list(Value) ->
422 427
     Opt;
@@ -495,4 +500,3 @@ verify_data(Data, Signature, Algorithm) when is_binary(Data), is_binary(Signatur
495 500
 	Error ->
496 501
 	    Error
497 502
     end.
498  
-
16  lib/ssh/src/ssh_auth.erl
@@ -71,7 +71,7 @@ password_msg([#ssh{opts = Opts, io_cb = IoCb,
71 71
     ssh_bits:install_messages(userauth_passwd_messages()),
72 72
     Password = case proplists:get_value(password, Opts) of
73 73
 		   undefined -> 
74  
-		       user_interaction(Opts, IoCb);
  74
+		       user_interaction(IoCb);
75 75
 		   PW -> 
76 76
 		       PW
77 77
 	       end,
@@ -89,13 +89,10 @@ password_msg([#ssh{opts = Opts, io_cb = IoCb,
89 89
 	      Ssh)
90 90
     end.
91 91
 
92  
-user_interaction(Opts, IoCb) ->
93  
-    case proplists:get_value(allow_user_interaction, Opts, true) of
94  
-	true ->
95  
-	    IoCb:read_password("ssh password: ");
96  
-	false ->
97  
-	    not_ok
98  
-    end.
  92
+user_interaction(ssh_no_io) ->
  93
+    not_ok;
  94
+user_interaction(IoCb) ->
  95
+    IoCb:read_password("ssh password: ").
99 96
 
100 97
 
101 98
 %% See RFC 4256 for info on keyboard-interactive
@@ -124,8 +121,7 @@ init_userauth_request_msg(#ssh{opts = Opts} = Ssh) ->
124 121
 	    FirstAlg = algorithm(proplists:get_value(public_key_alg, Opts,
125 122
 					  ?PREFERRED_PK_ALG)),
126 123
 	    SecondAlg = other_alg(FirstAlg),
127  
-	    AllowUserInt =  proplists:get_value(allow_user_interaction, Opts,
128  
-						true),
  124
+	    AllowUserInt =  proplists:get_value(user_interaction, Opts, true),
129 125
 	    Prefs = method_preference(FirstAlg, SecondAlg, AllowUserInt),
130 126
 	    ssh_transport:ssh_packet(Msg, Ssh#ssh{user = User,
131 127
 					    userauth_preference = Prefs,
36  lib/ssh/test/ssh_basic_SUITE.erl
@@ -183,7 +183,29 @@ app_test(doc) ->
183 183
 app_test(Config) when is_list(Config) ->
184 184
     ?t:app_test(ssh),
185 185
     ok.
  186
+%%--------------------------------------------------------------------
  187
+misc_ssh_options(doc) ->
  188
+    ["Test that we can set some misc options not tested elsewhere, "
  189
+     "some options not yet present are not decided if we should support or "
  190
+     "if they need thier own test case."];
  191
+misc_ssh_options(suite) ->
  192
+    [];
  193
+misc_ssh_options(Config) when is_list(Config) ->  
  194
+    SystemDir = filename:join(?config(priv_dir, Config), system),
  195
+    UserDir = ?config(priv_dir, Config),
  196
+    
  197
+    CMiscOpt0 = [{connecect_timeout, 1000}, {ip_v6_disable, false}, {user_dir, UserDir}],
  198
+    CMiscOpt1 = [{connecect_timeout, infinity}, {ip_v6_disable, true}, {user_dir, UserDir}],
  199
+    SMiscOpt0 =  [{ip_v6_disable, false}, {user_dir, UserDir}, {system_dir, SystemDir}],
  200
+    SMiscOpt1 =  [{ip_v6_disable, true}, {user_dir, UserDir}, {system_dir, SystemDir}],
  201
+    
  202
+    ClientOpts = ?config(client_opts, Config),
  203
+    ServerOpts = ?config(server_opts, Config),
  204
+
  205
+    basic_test([{client_opts, CMiscOpt0 ++ ClientOpts}, {server_opts, SMiscOpt0 ++ ServerOpts}]),
  206
+    basic_test([{client_opts, CMiscOpt1 ++ ClientOpts}, {server_opts, SMiscOpt1 ++ ServerOpts}]).
186 207
 
  208
+%%--------------------------------------------------------------------
187 209
 exec(doc) ->
188 210
     ["Test api function ssh_connection:exec"];
189 211
 
@@ -500,13 +522,14 @@ internal_error(Config) when is_list(Config) ->
500 522
     SystemDir = filename:join(?config(priv_dir, Config), system),
501 523
     UserDir = ?config(priv_dir, Config),
502 524
     
503  
-    {_Pid, Host, Port} = ssh_test_lib:daemon([{system_dir, SystemDir},
  525
+    {Pid, Host, Port} = ssh_test_lib:daemon([{system_dir, SystemDir},
504 526
 					     {user_dir, UserDir},
505 527
 					     {failfun, fun ssh_test_lib:failfun/2}]),
506 528
     {error,"Internal error"} =
507 529
 	ssh:connect(Host, Port, [{silently_accept_hosts, true},
508 530
 				 {user_dir, UserDir},
509  
-				 {user_interaction, false}]).
  531
+				 {user_interaction, false}]),
  532
+    ssh:stop_daemon(Pid).
510 533
 
511 534
 %%--------------------------------------------------------------------
512 535
 close(doc) ->
@@ -539,3 +562,12 @@ close(Config) when is_list(Config) ->
539 562
 %%--------------------------------------------------------------------
540 563
 %% Internal functions
541 564
 %%--------------------------------------------------------------------
  565
+  
  566
+basic_test(Config) ->
  567
+    ClientOpts = ?config(client_opts, Config),
  568
+    ServerOpts = ?config(server_opts, Config),
  569
+    
  570
+    {Pid, Host, Port} = ssh_test_lib:daemon(ServerOpts),
  571
+    {ok, CM} = ssh:connect(Host, Port, ClientOpts),
  572
+    ok = ssh:close(CM),
  573
+    ssh:stop_daemon(Pid).

0 notes on commit 33fe880

Please sign in to comment.
Something went wrong with that request. Please try again.