diff options
Diffstat (limited to 'lib/ssh')
-rw-r--r-- | lib/ssh/src/ssh.appup.src | 26 | ||||
-rw-r--r-- | lib/ssh/src/ssh_connection_manager.erl | 22 | ||||
-rw-r--r-- | lib/ssh/src/ssh_sftpd.erl | 14 | ||||
-rw-r--r-- | lib/ssh/test/ssh_basic_SUITE.erl | 30 | ||||
-rw-r--r-- | lib/ssh/test/ssh_sftp_SUITE.erl | 114 | ||||
-rw-r--r-- | lib/ssh/test/ssh_sftpd_SUITE.erl | 85 | ||||
-rw-r--r-- | lib/ssh/vsn.mk | 2 |
7 files changed, 170 insertions, 123 deletions
diff --git a/lib/ssh/src/ssh.appup.src b/lib/ssh/src/ssh.appup.src index 21a0582c06..0542054596 100644 --- a/lib/ssh/src/ssh.appup.src +++ b/lib/ssh/src/ssh.appup.src @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2011. All Rights Reserved. +%% Copyright Ericsson AB 2004-2012. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -18,26 +18,12 @@ %% {"%VSN%", - [ - {"2.0.8", [{load_module, ssh_sftpd_file_api, soft_purge, soft_purge, []}, - {load_module, ssh_channel, soft_purge, soft_purge, []}]}, - {"2.0.7", [{load_module, ssh_sftp, soft_purge, soft_purge, []}]}, - {"2.0.6", [{load_module, ssh_userreg, soft_purge, soft_purge, []}, - {load_module, ssh_sftp, soft_purge, soft_purge, []}]}, - {"2.0.5", [{load_module, ssh_userreg, soft_purge, soft_purge, []}, - {load_module, ssh_sftp, soft_purge, soft_purge, []}, - {load_module, ssh_connection_handler, soft_purge, soft_purge, [ssh_userreg]}]} + [ + {<<"2\\.*">>, [{restart_application, ssh}]}, + {<<"1\\.*">>, [{restart_application, ssh}]} ], [ - {"2.0.8", [{load_module, ssh_sftpd_file_api, soft_purge, soft_purge, []}, - {load_module, ssh_channel, soft_purge, soft_purge, []}]}, - {"2.0.7", [{load_module, ssh_sftp, soft_purge, soft_purge, []}]}, - {"2.0.6", [{load_module, ssh_userreg, soft_purge, soft_purge, []}, - {load_module, ssh_sftp, soft_purge, soft_purge, []}]}, - {"2.0.5", [{load_module, ssh_userreg, soft_purge, soft_purge, []}, - {load_module, ssh_sftp, soft_purge, soft_purge, []}, - {load_module, ssh_connection_handler, soft_purge, soft_purge, [ssh_userreg]}]} + {<<"2\\.*">>, [{restart_application, ssh}]}, + {<<"1\\.*">>, [{restart_application, ssh}]} ] }. - - diff --git a/lib/ssh/src/ssh_connection_manager.erl b/lib/ssh/src/ssh_connection_manager.erl index 406a042d72..e993f597a5 100644 --- a/lib/ssh/src/ssh_connection_manager.erl +++ b/lib/ssh/src/ssh_connection_manager.erl @@ -144,27 +144,21 @@ adjust_window(ConnectionManager, Channel, Bytes) -> cast(ConnectionManager, {adjust_window, Channel, Bytes}). close(ConnectionManager, ChannelId) -> - try call(ConnectionManager, {close, ChannelId}) of - ok -> + case call(ConnectionManager, {close, ChannelId}) of + ok -> ok; - {error, channel_closed} -> - ok - catch - exit:{noproc, _} -> + {error, channel_closed} -> ok - end. + end. stop(ConnectionManager) -> - try call(ConnectionManager, stop) of + case call(ConnectionManager, stop) of ok -> ok; {error, channel_closed} -> ok - catch - exit:{noproc, _} -> - ok end. - + send(ConnectionManager, ChannelId, Type, Data, Timeout) -> call(ConnectionManager, {data, ChannelId, Type, Data}, Timeout). @@ -591,7 +585,9 @@ call(Pid, Msg, Timeout) -> catch exit:{timeout, _} -> {error, timeout}; - exit:{normal, _} -> + exit:{normal} -> + {error, channel_closed}; + exit:{{shutdown, _}, _} -> {error, channel_closed}; exit:{noproc,_} -> {error, channel_closed} diff --git a/lib/ssh/src/ssh_sftpd.erl b/lib/ssh/src/ssh_sftpd.erl index 8cc414f83a..ec7b76b0b3 100644 --- a/lib/ssh/src/ssh_sftpd.erl +++ b/lib/ssh/src/ssh_sftpd.erl @@ -424,18 +424,18 @@ handle_op(?SSH_FXP_RENAME, ReqId, State0 end; handle_op(?SSH_FXP_SYMLINK, ReqId, - <<?UINT32(PLen), BPath:PLen/binary, ?UINT32(PLen2), - BPath2:PLen2/binary>>, + <<?UINT32(PLen), Link:PLen/binary, ?UINT32(PLen2), + Target:PLen2/binary>>, State0 = #state{file_handler = FileMod, file_state = FS0}) -> - Path = relate_file_name(BPath, State0), - Path2 = relate_file_name(BPath2, State0), - {Status, FS1} = FileMod:make_symlink(Path2, Path, FS0), + LinkPath = relate_file_name(Link, State0), + TargetPath = relate_file_name(Target, State0), + {Status, FS1} = FileMod:make_symlink(TargetPath, LinkPath, FS0), State1 = State0#state{file_state = FS1}, send_status(Status, ReqId, State1). new_handle([], H) -> H; -new_handle([{N, _} | Rest], H) when N > H -> +new_handle([{N, _,_} | Rest], H) when N =< H -> new_handle(Rest, N+1); new_handle([_ | Rest], H) -> new_handle(Rest, H). @@ -444,6 +444,8 @@ add_handle(State, XF, ReqId, Type, DirFileTuple) -> Handles = State#state.handles, Handle = new_handle(Handles, 0), ssh_xfer:xf_send_handle(XF, ReqId, integer_to_list(Handle)), + %% OBS: If you change handles-tuple also change new_handle! + %% Is this this the best way to implement new handle? State#state{handles = [{Handle, Type, DirFileTuple} | Handles]}. get_handle(Handles, BinHandle) -> diff --git a/lib/ssh/test/ssh_basic_SUITE.erl b/lib/ssh/test/ssh_basic_SUITE.erl index 012367a6df..d66214d415 100644 --- a/lib/ssh/test/ssh_basic_SUITE.erl +++ b/lib/ssh/test/ssh_basic_SUITE.erl @@ -110,7 +110,8 @@ all() -> {group, rsa_pass_key}, {group, internal_error}, daemon_already_started, - server_password_option, server_userpassword_option]. + server_password_option, server_userpassword_option, + close]. groups() -> [{dsa_key, [], [exec, exec_compressed, shell, known_hosts]}, @@ -507,7 +508,34 @@ internal_error(Config) when is_list(Config) -> {user_dir, UserDir}, {user_interaction, false}]). +%%-------------------------------------------------------------------- +close(doc) -> + ["Simulate that we try to close an already closed connection"]; + +close(suite) -> + []; + +close(Config) when is_list(Config) -> + SystemDir = ?config(data_dir, Config), + PrivDir = ?config(priv_dir, Config), + UserDir = filename:join(PrivDir, nopubkey), % to make sure we don't use public-key-auth + file:make_dir(UserDir), + + {_Pid, Host, Port} = ssh_test_lib:daemon([{system_dir, SystemDir}, + {user_dir, UserDir}, + {user_passwords, [{"vego", "morot"}]}, + {failfun, fun ssh_test_lib:failfun/2}]), + {ok, CM} = ssh:connect(Host, Port, [{silently_accept_hosts, true}, + {user_dir, UserDir}, + {user, "vego"}, + {password, "morot"}, + {user_interaction, false}]), + exit(CM, {shutdown, normal}), + ok = ssh:close(CM). + + + %%-------------------------------------------------------------------- %% Internal functions %%-------------------------------------------------------------------- diff --git a/lib/ssh/test/ssh_sftp_SUITE.erl b/lib/ssh/test/ssh_sftp_SUITE.erl index 7644db155d..d40b1d544d 100644 --- a/lib/ssh/test/ssh_sftp_SUITE.erl +++ b/lib/ssh/test/ssh_sftp_SUITE.erl @@ -76,42 +76,34 @@ end_per_suite(Config) -> %% variable, but should NOT alter/remove any existing entries. %% Description: Initiation before each test case %%-------------------------------------------------------------------- -init_per_testcase(_Case, Config) -> +init_per_testcase(Case, Config) -> prep(Config), TmpConfig0 = lists:keydelete(watchdog, 1, Config), TmpConfig = lists:keydelete(sftp, 1, TmpConfig0), Dog = test_server:timetrap(?default_timeout), - PrivDir = ?config(priv_dir, Config), - SysDir = ?config(data_dir, Config), - Host = ssh_test_lib:hostname(), - %% Run test against openssh server if available - Sftp = case (catch ssh_sftp:start_channel(Host, - [{user_interaction, false}, - {silently_accept_hosts, true}])) of - {ok, ChannelPid, Connection} -> - test_server:format("Running against openssh"), - {ChannelPid, Connection}; - _Error -> %% Start own sftp - test_server:format("Running against erlang ssh"), - {_Sftpd, Host1, Port} = - ssh_test_lib:daemon([{system_dir, SysDir}, - {user_dir, PrivDir}, - {user_passwords, - [{?USER, ?PASSWD}]}, - {failfun, - fun ssh_test_lib:failfun/2}]), - Result = (catch ssh_sftp:start_channel(Host1, Port, - [{user, ?USER}, - {password, ?PASSWD}, - {user_dir, PrivDir}, - {user_interaction, false}, - {silently_accept_hosts, true}])), - {ok, ChannelPid, Connection} = Result, - {ChannelPid, Connection} - end, - - [{sftp, Sftp}, {watchdog, Dog} | TmpConfig]. + case ?config(group, Config) of + erlang_server -> + {_,Host, Port} = ?config(sftpd, Config), + {ok, ChannelPid, Connection} = + ssh_sftp:start_channel(Host, Port, + [{user, ?USER}, + {password, ?PASSWD}, + {user_interaction, false}, + {silently_accept_hosts, true}]), + Sftp = {ChannelPid, Connection}, + [{sftp, Sftp}, {watchdog, Dog} | TmpConfig]; + openssh_server when Case == links -> + {skip, "known bug in openssh"}; + openssh_server -> + Host = ssh_test_lib:hostname(), + {ok, ChannelPid, Connection} = + ssh_sftp:start_channel(Host, + [{user_interaction, false}, + {silently_accept_hosts, true}]), + Sftp = {ChannelPid, Connection}, + [{sftp, Sftp}, {watchdog, Dog} | TmpConfig] + end. %%-------------------------------------------------------------------- %% Function: end_per_testcase(TestCase, Config) -> _ @@ -121,7 +113,15 @@ init_per_testcase(_Case, Config) -> %% A list of key/value pairs, holding the test case configuration. %% Description: Cleanup after each test case %%-------------------------------------------------------------------- -end_per_testcase(_Case, Config) -> +end_per_testcase(rename_file, Config) -> + PrivDir = ?config(priv_dir, Config), + NewFileName = filename:join(PrivDir, "test.txt"), + file:delete(NewFileName), + end_per_testcase(Config); +end_per_testcase(_, Config) -> + end_per_testcase(Config). + +end_per_testcase(Config) -> {Sftp, Connection} = ?config(sftp, Config), ssh_sftp:stop_channel(Sftp), ssh:close(Connection), @@ -138,19 +138,47 @@ end_per_testcase(_Case, Config) -> %% Description: Returns a list of all test cases in this test suite %%-------------------------------------------------------------------- all() -> - [open_close_file, open_close_dir, read_file, read_dir, - write_file, rename_file, mk_rm_dir, remove_file, links, - retrieve_attributes, set_attributes, async_read, - async_write, position, pos_read, pos_write]. + [{group, erlang_server}, + {group, openssh_server}]. groups() -> - []. - -init_per_group(_GroupName, Config) -> - Config. + [{erlang_server, [], [open_close_file, open_close_dir, read_file, read_dir, + write_file, rename_file, mk_rm_dir, remove_file, links, + retrieve_attributes, set_attributes, async_read, + async_write, position, pos_read, pos_write]}, + {openssh_server, [], [open_close_file, open_close_dir, read_file, read_dir, + write_file, rename_file, mk_rm_dir, remove_file, links, + retrieve_attributes, set_attributes, async_read, + async_write, position, pos_read, pos_write]}]. + +init_per_group(erlang_server, Config) -> + PrivDir = ?config(priv_dir, Config), + SysDir = ?config(data_dir, Config), + Sftpd = + ssh_test_lib:daemon([{system_dir, SysDir}, + {user_dir, PrivDir}, + {user_passwords, + [{?USER, ?PASSWD}]}, + {failfun, + fun ssh_test_lib:failfun/2}]), + [{group, erlang_server}, {sftpd, Sftpd} | Config]; + +init_per_group(openssh_server, Config) -> + Host = ssh_test_lib:hostname(), + case (catch ssh_sftp:start_channel(Host, + [{user_interaction, false}, + {silently_accept_hosts, true}])) of + {ok, _ChannelPid, Connection} -> + ssh:close(Connection), + [{group, openssh_server} | Config]; + _ -> + {skip, "No openssh server"} + end. -end_per_group(_GroupName, Config) -> - Config. +end_per_group(erlang_server, Config) -> + Config; +end_per_group(_, Config) -> + Config. %% Test cases starts here. @@ -332,7 +360,7 @@ links(Config) when is_list(Config) -> FileName = filename:join(PrivDir, "sftp.txt"), LinkFileName = filename:join(PrivDir, "link_test.txt"), - ok = ssh_sftp:make_symlink(Sftp, FileName, LinkFileName), + ok = ssh_sftp:make_symlink(Sftp, LinkFileName, FileName), {ok, FileName} = ssh_sftp:read_link(Sftp, LinkFileName), ok end. diff --git a/lib/ssh/test/ssh_sftpd_SUITE.erl b/lib/ssh/test/ssh_sftpd_SUITE.erl index de946d4c4c..695a7caa7d 100644 --- a/lib/ssh/test/ssh_sftpd_SUITE.erl +++ b/lib/ssh/test/ssh_sftpd_SUITE.erl @@ -545,56 +545,60 @@ set_attributes(doc) -> set_attributes(suite) -> []; set_attributes(Config) when is_list(Config) -> - PrivDir = ?config(priv_dir, Config), - FileName = filename:join(PrivDir, "test.txt"), - ReqId = 0, - {Cm, Channel} = ?config(sftp, Config), + case test_server:os_type() of + {win32, _} -> + {skip, "Known error bug in erts file:read_file_info"}; + _ -> + PrivDir = ?config(priv_dir, Config), + FileName = filename:join(PrivDir, "test.txt"), + ReqId = 0, + {Cm, Channel} = ?config(sftp, Config), - {ok, FileInfo} = file:read_file_info(FileName), + {ok, FileInfo} = file:read_file_info(FileName), - OrigPermissions = FileInfo#file_info.mode, - Permissions = 8#600, %% User read-write-only + OrigPermissions = FileInfo#file_info.mode, + Permissions = not_default_permissions(), - Flags = ?SSH_FILEXFER_ATTR_PERMISSIONS, + Flags = ?SSH_FILEXFER_ATTR_PERMISSIONS, - Atters = [?uint32(Flags), ?byte(?SSH_FILEXFER_TYPE_REGULAR), - ?uint32(Permissions)], + Atters = [?uint32(Flags), ?byte(?SSH_FILEXFER_TYPE_REGULAR), + ?uint32(Permissions)], - {ok, <<?SSH_FXP_STATUS, ?UINT32(ReqId), - ?UINT32(?SSH_FX_OK), _/binary>>, _} = - set_attributes_file(FileName, Atters, Cm, Channel, ReqId), - - {ok, NewFileInfo} = file:read_file_info(FileName), - NewPermissions = NewFileInfo#file_info.mode, - - %% Can not test that NewPermissions = Permissions as - %% on Unix platforms, other bits than those listed in the - %% API may be set. - test_server:format("Org: ~p New: ~p~n", [OrigPermissions, NewPermissions]), - true = OrigPermissions =/= NewPermissions, - - test_server:format("Try to open the file"), - NewReqId = 2, - {ok, <<?SSH_FXP_HANDLE, ?UINT32(NewReqId), Handle/binary>>, _} = - open_file(FileName, Cm, Channel, NewReqId, - ?ACE4_READ_DATA bor ?ACE4_WRITE_ATTRIBUTES, - ?SSH_FXF_OPEN_EXISTING), + {ok, <<?SSH_FXP_STATUS, ?UINT32(ReqId), + ?UINT32(?SSH_FX_OK), _/binary>>, _} = + set_attributes_file(FileName, Atters, Cm, Channel, ReqId), - NewAtters = [?uint32(Flags), ?byte(?SSH_FILEXFER_TYPE_REGULAR), - ?uint32(OrigPermissions)], + {ok, NewFileInfo} = file:read_file_info(FileName), + NewPermissions = NewFileInfo#file_info.mode, - NewReqId1 = 3, + %% Can not test that NewPermissions = Permissions as + %% on Unix platforms, other bits than those listed in the + %% API may be set. + test_server:format("Org: ~p New: ~p~n", [OrigPermissions, NewPermissions]), + true = OrigPermissions =/= NewPermissions, - test_server:format("Set original permissions on the now open file"), + test_server:format("Try to open the file"), + NewReqId = 2, + {ok, <<?SSH_FXP_HANDLE, ?UINT32(NewReqId), Handle/binary>>, _} = + open_file(FileName, Cm, Channel, NewReqId, + ?ACE4_READ_DATA bor ?ACE4_WRITE_ATTRIBUTES, + ?SSH_FXF_OPEN_EXISTING), - {ok, <<?SSH_FXP_STATUS, ?UINT32(NewReqId1), - ?UINT32(?SSH_FX_OK), _/binary>>, _} = - set_attributes_open_file(Handle, NewAtters, Cm, Channel, NewReqId1), + NewAtters = [?uint32(Flags), ?byte(?SSH_FILEXFER_TYPE_REGULAR), + ?uint32(OrigPermissions)], - {ok, NewFileInfo1} = file:read_file_info(FileName), - OrigPermissions = NewFileInfo1#file_info.mode, + NewReqId1 = 3, - ok. + test_server:format("Set original permissions on the now open file"), + + {ok, <<?SSH_FXP_STATUS, ?UINT32(NewReqId1), + ?UINT32(?SSH_FX_OK), _/binary>>, _} = + set_attributes_open_file(Handle, NewAtters, Cm, Channel, NewReqId1), + + {ok, NewFileInfo1} = file:read_file_info(FileName), + OrigPermissions = NewFileInfo1#file_info.mode, + ok + end. %%-------------------------------------------------------------------- ver3_rename_OTP_6352(doc) -> @@ -943,3 +947,6 @@ sshd_read_file(Config) when is_list(Config) -> {ok, Data} = file:read_file(FileName), ok. + +not_default_permissions() -> + 8#600. %% User read-write-only diff --git a/lib/ssh/vsn.mk b/lib/ssh/vsn.mk index 42f860d6ae..bff73a1b40 100644 --- a/lib/ssh/vsn.mk +++ b/lib/ssh/vsn.mk @@ -1,5 +1,5 @@ #-*-makefile-*- ; force emacs to enter makefile-mode -SSH_VSN = 2.0.9 +SSH_VSN = 2.1 APP_VSN = "ssh-$(SSH_VSN)" |