aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTuncer Ayaz <[email protected]>2010-09-02 23:06:08 +0200
committerNiclas Eklund <[email protected]>2010-12-28 16:15:31 +0100
commit25e6de467ebddd6ba006ab95811711008cc4e1ea (patch)
tree6a12b7f2c771a4da2e2f368c43e0aaa3c844ce8a
parent99e34bba1a60b262e24496cc9288b549360c6377 (diff)
downloadotp-25e6de467ebddd6ba006ab95811711008cc4e1ea.tar.gz
otp-25e6de467ebddd6ba006ab95811711008cc4e1ea.tar.bz2
otp-25e6de467ebddd6ba006ab95811711008cc4e1ea.zip
ssh: ensure ~/.ssh exists
Make sure that ~/.ssh exists before trying to open files like ~/.ssh/known_hosts. Reported-By: Daniel Goertzen
-rwxr-xr-xlib/ssh/src/ssh_file.erl14
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.