diff options
author | Karolis Petrauskas <[email protected]> | 2017-02-08 15:06:43 +0200 |
---|---|---|
committer | Karolis Petrauskas <[email protected]> | 2017-02-12 12:56:43 +0200 |
commit | 859ac82433da2dcd11685b8c8beb972336cf70cf (patch) | |
tree | 9164c7233c28c06ab73e2f559c9a9235b800bf9f /lib/ssh/src/ssh_sftpd.erl | |
parent | 47b4abf118e2dac88c5c2cbd531372cc217854ec (diff) | |
download | otp-859ac82433da2dcd11685b8c8beb972336cf70cf.tar.gz otp-859ac82433da2dcd11685b8c8beb972336cf70cf.tar.bz2 otp-859ac82433da2dcd11685b8c8beb972336cf70cf.zip |
Consider root_dir and cwd in ssh_sftpd, if both are provided
The SFTPD server should use root_dir and cwd when resolving
file paths, if both are provided. The root directory should
be used for resolving absolute file names, and cwd should
be used for resolving relative paths.
Diffstat (limited to 'lib/ssh/src/ssh_sftpd.erl')
-rw-r--r-- | lib/ssh/src/ssh_sftpd.erl | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/lib/ssh/src/ssh_sftpd.erl b/lib/ssh/src/ssh_sftpd.erl index b739955836..bc30b7fb7d 100644 --- a/lib/ssh/src/ssh_sftpd.erl +++ b/lib/ssh/src/ssh_sftpd.erl @@ -742,6 +742,10 @@ resolve_symlinks_2([], State, _LinkCnt, AccPath) -> {{ok, AccPath}, State}. +%% The File argument is always in a user visible file system, i.e. +%% is under Root and is relative to CWD or Root, if starts with "/". +%% The result of the function is always an absolute path in a +%% "backend" file system. relate_file_name(File, State) -> relate_file_name(File, State, _Canonicalize=true). @@ -749,19 +753,20 @@ relate_file_name(File, State, Canonicalize) when is_binary(File) -> relate_file_name(unicode:characters_to_list(File), State, Canonicalize); relate_file_name(File, #state{cwd = CWD, root = ""}, Canonicalize) -> relate_filename_to_path(File, CWD, Canonicalize); -relate_file_name(File, #state{root = Root}, Canonicalize) -> - case is_within_root(Root, File) of - true -> - File; - false -> - RelFile = make_relative_filename(File), - NewFile = relate_filename_to_path(RelFile, Root, Canonicalize), - case is_within_root(Root, NewFile) of - true -> - NewFile; - false -> - Root - end +relate_file_name(File, #state{cwd = CWD, root = Root}, Canonicalize) -> + CWD1 = case is_within_root(Root, CWD) of + true -> CWD; + false -> Root + end, + AbsFile = case make_relative_filename(File) of + File -> + relate_filename_to_path(File, CWD1, Canonicalize); + RelFile -> + relate_filename_to_path(RelFile, Root, Canonicalize) + end, + case is_within_root(Root, AbsFile) of + true -> AbsFile; + false -> Root end. is_within_root(Root, File) -> |