diff options
author | Erlang/OTP <[email protected]> | 2011-01-24 08:42:57 +0100 |
---|---|---|
committer | Erlang/OTP <[email protected]> | 2011-01-24 08:42:57 +0100 |
commit | 7db8499d81b8c05d6019df9cf923351d0e96f7a0 (patch) | |
tree | 17ef47166162af0524a1ee99be95158819940079 | |
parent | a261e2982b7cd5d0101c8c04b76c10c8dad64dd3 (diff) | |
parent | 28ecd6a36a3203d2e99a724039109ee612a26296 (diff) | |
download | otp-7db8499d81b8c05d6019df9cf923351d0e96f7a0.tar.gz otp-7db8499d81b8c05d6019df9cf923351d0e96f7a0.tar.bz2 otp-7db8499d81b8c05d6019df9cf923351d0e96f7a0.zip |
Merge branch 'nick/ensure_ssh_dir_exists/OTP-9010' into maint-r14
* nick/ensure_ssh_dir_exists/OTP-9010:
Updated appup file.
Updated notes file.
Updated year in license.
OTP-9010:
ssh: ensure ~/.ssh exists
-rwxr-xr-x | lib/ssh/src/ssh_file.erl | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/ssh/src/ssh_file.erl b/lib/ssh/src/ssh_file.erl index 13722656db..c78f5dc337 100755 --- a/lib/ssh/src/ssh_file.erl +++ b/lib/ssh/src/ssh_file.erl @@ -27,6 +27,8 @@ -include("PKCS-1.hrl"). -include("DSS.hrl"). +-include_lib("kernel/include/file.hrl"). + -export([public_host_dsa_key/2,private_host_dsa_key/2, public_host_rsa_key/2,private_host_rsa_key/2, public_host_key/2,private_host_key/2, @@ -43,6 +45,9 @@ -define(DBG_PATHS, true). +-define(PERM_700, 8#700). +-define(PERM_644, 8#644). + %% API public_host_dsa_key(Type, Opts) -> File = file_name(Type, "ssh_host_dsa_key.pub", Opts), @@ -113,8 +118,10 @@ do_lookup_host_key(Host, Alg, Opts) -> add_host_key(Host, Key, Opts) -> Host1 = add_ip(replace_localhost(Host)), - case file:open(file_name(user, "known_hosts", Opts),[write,append]) of + KnownHosts = file_name(user, "known_hosts", Opts), + case file:open(KnownHosts, [write,append]) of {ok, Fd} -> + ok = file:change_mode(KnownHosts, ?PERM_644), Res = add_key_fd(Fd, Host1, Key), file:close(Fd), Res; @@ -532,4 +539,7 @@ file_name(Type, Name, Opts) -> default_user_dir()-> {ok,[[Home|_]]} = init:get_argument(home), - filename:join(Home, ".ssh"). + UserDir = filename:join(Home, ".ssh"), + ok = filelib:ensure_dir(filename:join(UserDir, "dummy")), + ok = file:change_mode(UserDir, ?PERM_700), + UserDir. |