diff options
author | Thomas Wolf <thomas.wolf@paranor.ch> | 2017-10-18 22:45:36 +0200 |
---|---|---|
committer | Thomas Wolf <thomas.wolf@paranor.ch> | 2017-10-18 22:45:36 +0200 |
commit | adbf0935e105819f6b8f65325013b6def6205f18 (patch) | |
tree | 52c819fcd0057e89581d48b425fd8150ef08bf6e /org.eclipse.jgit | |
parent | 81801832892a211be534c1c0ccd382df6c77e003 (diff) | |
download | jgit-adbf0935e105819f6b8f65325013b6def6205f18.tar.gz jgit-adbf0935e105819f6b8f65325013b6def6205f18.zip |
Ensure that ~ in ssh config is replaced before Jsch sees it
Do tilde replacement for values from the ssh config file that are
file names in all cases to make sure that they are already replaced
when Jsch tries to get the values.
Previously, OpenSshConfig did tilde replacement only for the
IdentityFile in the JGit-facing "Host" interface and left the
replacement in the Jsch-facing "Config" interface to Jsch.
But on Windows the JGit notion of what should be used to replace the
tilde differs from Jsch's replacement. Jsch always replaces the tilde
by the value of the system property "user.home", whereas JGit also
considers some environment variables like %HOME%. This can lead to
rather surprising failures as in the case of bug 526175 where
%HOME% != user.home.
Prior to commit 9d24470 (i.e.,prior to JGit 4.9.0) this problem never
occurred because Jsch was completely unaware of the ssh config file
and all host and IdentityFile handling happened exclusively in JGit.
Bug: 526175
Change-Id: I1511699664ffea07cb58ed751cfdb79b15e3a99e
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/transport/OpenSshConfig.java | 45 |
1 files changed, 34 insertions, 11 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/OpenSshConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/OpenSshConfig.java index b5b532dffd..67a7db99f4 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/OpenSshConfig.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/OpenSshConfig.java @@ -352,6 +352,17 @@ public class OpenSshConfig implements ConfigRepository { return Boolean.FALSE; } + private static File toFile(String path, File home) { + if (path.startsWith("~/")) { //$NON-NLS-1$ + return new File(home, path.substring(2)); + } + File ret = new File(path); + if (ret.isAbsolute()) { + return ret; + } + return new File(home, path); + } + private static int positive(final String value) { if (value != null) { try { @@ -730,25 +741,48 @@ public class OpenSshConfig implements ConfigRepository { return result; } + private List<String> replaceTilde(List<String> values, File home) { + List<String> result = new ArrayList<>(values.size()); + for (String value : values) { + result.add(toFile(value, home).getPath()); + } + return result; + } + protected void substitute(String originalHostName, File home) { Replacer r = new Replacer(originalHostName, home); if (multiOptions != null) { List<String> values = multiOptions.get("IDENTITYFILE"); //$NON-NLS-1$ if (values != null) { values = substitute(values, "dhlru", r); //$NON-NLS-1$ + values = replaceTilde(values, home); multiOptions.put("IDENTITYFILE", values); //$NON-NLS-1$ } values = multiOptions.get("CERTIFICATEFILE"); //$NON-NLS-1$ if (values != null) { values = substitute(values, "dhlru", r); //$NON-NLS-1$ + values = replaceTilde(values, home); multiOptions.put("CERTIFICATEFILE", values); //$NON-NLS-1$ } } + if (listOptions != null) { + List<String> values = listOptions.get("GLOBALKNOWNHOSTSFILE"); //$NON-NLS-1$ + if (values != null) { + values = replaceTilde(values, home); + listOptions.put("GLOBALKNOWNHOSTSFILE", values); //$NON-NLS-1$ + } + values = listOptions.get("USERKNOWNHOSTSFILE"); //$NON-NLS-1$ + if (values != null) { + values = replaceTilde(values, home); + listOptions.put("USERKNOWNHOSTSFILE", values); //$NON-NLS-1$ + } + } if (options != null) { // HOSTNAME already done in Replacer constructor String value = options.get("IDENTITYAGENT"); //$NON-NLS-1$ if (value != null) { value = r.substitute(value, "dhlru"); //$NON-NLS-1$ + value = toFile(value, home).getPath(); options.put("IDENTITYAGENT", value); //$NON-NLS-1$ } } @@ -909,17 +943,6 @@ public class OpenSshConfig implements ConfigRepository { } } - private File toFile(String path, File home) { - if (path.startsWith("~/")) { //$NON-NLS-1$ - return new File(home, path.substring(2)); - } - File ret = new File(path); - if (ret.isAbsolute()) { - return ret; - } - return new File(home, path); - } - Config getConfig() { return config; } |