Repository: mina-sshd Updated Branches: refs/heads/master 16fae05ab -> b8bf38740
[SSHD-798] Provide split GIT command arguments to GitLocationResolver Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/b8bf3874 Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/b8bf3874 Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/b8bf3874 Branch: refs/heads/master Commit: b8bf38740c1fdbceb61c6c6b2bf25e39e3ea869a Parents: 16fae05 Author: Goldstein Lyor <[email protected]> Authored: Sun Feb 25 09:56:45 2018 +0200 Committer: Goldstein Lyor <[email protected]> Committed: Sun Feb 25 09:59:22 2018 +0200 ---------------------------------------------------------------------- .../java/org/apache/sshd/git/GitLocationResolver.java | 11 ++++++++--- .../java/org/apache/sshd/git/pack/GitPackCommand.java | 14 ++++++++------ .../java/org/apache/sshd/git/pgm/GitPgmCommand.java | 2 +- 3 files changed, 17 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/b8bf3874/sshd-git/src/main/java/org/apache/sshd/git/GitLocationResolver.java ---------------------------------------------------------------------- diff --git a/sshd-git/src/main/java/org/apache/sshd/git/GitLocationResolver.java b/sshd-git/src/main/java/org/apache/sshd/git/GitLocationResolver.java index 7679c90..323807f 100644 --- a/sshd-git/src/main/java/org/apache/sshd/git/GitLocationResolver.java +++ b/sshd-git/src/main/java/org/apache/sshd/git/GitLocationResolver.java @@ -33,13 +33,18 @@ import org.apache.sshd.server.session.ServerSession; */ public interface GitLocationResolver { /** - * @param command The received command + * @param command The complete received command + * @param args The command split into arguments - {@code args[0]} is the + * "pure" command itself without any other arguments. <B>Note:</B> + * changing the content of the arguments array may affect command execution + * in undetermined ways, due to invocation code changes without prior notice, + * so <U>highly recommended to avoid it</U>. * @param session The {@link ServerSession} through which the command was received * @param fs The {@link FileSystem} associated with the server session * @return The local GIT repository root path * @throws IOException If failed to resolve */ - Path resolveRootDirectory(String command, ServerSession session, FileSystem fs) throws IOException; + Path resolveRootDirectory(String command, String[] args, ServerSession session, FileSystem fs) throws IOException; /** * Creates a resolver that returns the same root directory for any invocation of @@ -50,6 +55,6 @@ public interface GitLocationResolver { */ static GitLocationResolver constantPath(Path rootDir) { Objects.requireNonNull(rootDir, "No root directory provided"); - return (cmd, session, fs) -> rootDir; + return (cmd, args, session, fs) -> rootDir; } } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/b8bf3874/sshd-git/src/main/java/org/apache/sshd/git/pack/GitPackCommand.java ---------------------------------------------------------------------- diff --git a/sshd-git/src/main/java/org/apache/sshd/git/pack/GitPackCommand.java b/sshd-git/src/main/java/org/apache/sshd/git/pack/GitPackCommand.java index bb123da..3b65b2a 100644 --- a/sshd-git/src/main/java/org/apache/sshd/git/pack/GitPackCommand.java +++ b/sshd-git/src/main/java/org/apache/sshd/git/pack/GitPackCommand.java @@ -72,13 +72,13 @@ public class GitPackCommand extends AbstractGitCommand { } if (args.length != 2) { - throw new IllegalArgumentException("Invalid git command line: " + command); + throw new IllegalArgumentException("Invalid git command line (no arguments): " + command); } - String subCommand = args[0]; - Path rootDir = resolveRootDirectory(command, subCommand, args[1]); + Path rootDir = resolveRootDirectory(command, args); RepositoryCache.FileKey key = RepositoryCache.FileKey.lenient(rootDir.toFile(), FS.DETECTED); Repository db = key.open(true /* must exist */); + String subCommand = args[0]; if (RemoteConfig.DEFAULT_UPLOAD_PACK.equals(subCommand)) { new UploadPack(db).upload(getInputStream(), getOutputStream(), getErrorStream()); } else if (RemoteConfig.DEFAULT_RECEIVE_PACK.equals(subCommand)) { @@ -93,10 +93,12 @@ public class GitPackCommand extends AbstractGitCommand { } } - protected Path resolveRootDirectory(String command, String subCommand, String pathArg) throws IOException { + protected Path resolveRootDirectory(String command, String[] args) throws IOException { GitLocationResolver resolver = getGitLocationResolver(); - Path rootDir = resolver.resolveRootDirectory(command, getServerSession(), getFileSystem()); + Path rootDir = resolver.resolveRootDirectory(command, args, getServerSession(), getFileSystem()); ValidateUtils.checkState(rootDir != null, "No root directory provided for %s command", command); + + String pathArg = args[1]; int len = GenericUtils.length(pathArg); // Strip any leading path separator since we use relative to root if ((len > 0) && (pathArg.charAt(0) == '/')) { @@ -104,7 +106,7 @@ public class GitPackCommand extends AbstractGitCommand { len--; } - ValidateUtils.checkNotNullAndNotEmpty(pathArg, "No %s command sub-path specified", subCommand); + ValidateUtils.checkNotNullAndNotEmpty(pathArg, "No %s command sub-path specified", args[0]); return rootDir.resolve(pathArg); } } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/b8bf3874/sshd-git/src/main/java/org/apache/sshd/git/pgm/GitPgmCommand.java ---------------------------------------------------------------------- diff --git a/sshd-git/src/main/java/org/apache/sshd/git/pgm/GitPgmCommand.java b/sshd-git/src/main/java/org/apache/sshd/git/pgm/GitPgmCommand.java index a80012d..5a95449 100644 --- a/sshd-git/src/main/java/org/apache/sshd/git/pgm/GitPgmCommand.java +++ b/sshd-git/src/main/java/org/apache/sshd/git/pgm/GitPgmCommand.java @@ -69,7 +69,7 @@ public class GitPgmCommand extends AbstractGitCommand { } GitLocationResolver resolver = getGitLocationResolver(); - Path rootDir = resolver.resolveRootDirectory(command, getServerSession(), getFileSystem()); + Path rootDir = resolver.resolveRootDirectory(command, args, getServerSession(), getFileSystem()); ValidateUtils.checkState(rootDir != null, "No root directory provided for %s command", command); new EmbeddedCommandRunner(rootDir).execute(args, getInputStream(), getOutputStream(), err);
