[PATCH v2] Allow git-shell to be used as a ssh forced-command

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When using a forced-command, OpenSSH sets the SSH_ORIGINAL_COMMAND
variable to what would otherwise be passed to $SHELL -c. When this
variable is set and git-shell was given no argument, we use it.

Signed-off-by: Mike Hommey <mh@xxxxxxxxxxxx>
---
 shell.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/shell.c b/shell.c
index b968be7..86c9273 100644
--- a/shell.c
+++ b/shell.c
@@ -72,11 +72,16 @@ int main(int argc, char **argv)
 	/*
 	 * We do not accept anything but "-c" followed by "cmd arg",
 	 * where "cmd" is a very limited subset of git commands.
+	 * If no argument is given at all, see whether we were run from
+	 * a ssh forced-command and use the original command if so.
 	 */
 	else if (argc != 3 || strcmp(argv[1], "-c"))
-		die("What do you think I am? A shell?");
+		if (argc != 1 || !(prog = getenv("SSH_ORIGINAL_COMMAND")))
+			die("What do you think I am? A shell?");
+
+	if (!prog)
+		prog = argv[2];
 
-	prog = argv[2];
 	if (!strncmp(prog, "git", 3) && isspace(prog[3]))
 		/* Accept "git foo" as if the caller said "git-foo". */
 		prog[3] = '-';
-- 
1.6.3.rc0.54.g1042b

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]