git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Mike Hommey <mh@glandium.org>
Date
Apr 21, 2009, 05:43 UTC
Message-ID
<1240292586-28192-1-git-send-email-mh@glandium.org>
In-Reply-To
<20090418063100.GA18568@glandium.org>

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@glandium.org>
---
 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
Previous: Mike HommeyNext: Dmitry Potapov
Message 13 of 18 in “Allow git-shell to be used as a ssh forced-command”
  1. Allow git-shell to be used as a ssh forced-commandMike Hommey, Apr 16, 2009
  2. Dmitry PotapovApr 17, 2009
  3. Mike HommeyApr 17, 2009
  4. Dmitry PotapovApr 17, 2009
  5. Mike HommeyApr 17, 2009
  6. Shawn O. PearceApr 17, 2009
  7. Mike HommeyApr 17, 2009
  8. Matthieu MoyApr 18, 2009
  9. Junio C HamanoApr 17, 2009
  10. Tommi VirtanenApr 17, 2009
  11. Junio C HamanoApr 18, 2009
  12. Mike HommeyApr 18, 2009
  13. Allow git-shell to be used as a ssh forced-commandMike Hommey, Apr 21, 2009
  14. Dmitry PotapovApr 21, 2009
  15. Eygene RyabinkinApr 21, 2009
  16. Junio C HamanoApr 21, 2009
  17. Mike HommeyApr 21, 2009
  18. Dmitry PotapovApr 21, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.