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

Re: [PATCH] Ensure that SSH runs in non-interactive mode

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 20, 2008, 18:23 UTC
Message-ID
<7v63r0bejy.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<alpine.DEB.1.00.0807201214060.3305@eeepc-johanness>
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
Show 39 quoted lines
>> Ah, right. Would it be OK to add the `-x' flag to ssh instead?
>
> I think this would be the correct way, together with "-T".
>
>> I imagine that that might make git less portable to SSH implementations 
>> other than OpenSSH, but I don't know if that is considered a problem.
>
> Well, this was to be expected, after what I wrote in response to 3. in
> http://thread.gmane.org/gmane.comp.version-control.git/76650/focus=2598
>
> Reality always catches up with you, and here again we see that plink and 
> other siblings of OpenSSH should be best handled with scripts, preferably 
> ones that strip out options they do not recognize.
>
> IOW something like
>
> -- snip --
> #!/bin/bash
>
> plinkopt=
> while test $# != 0
> do
> 	case "$1" in
> 	-p)
> 		plinkopt="$plinkopt -P $2"
> 		shift
> 	;;
> 	-*)
> 		# unrecognized; strip out
> 	;;
> 	*)
> 		break
> 	;;
> 	esac
> 	shift
> done
>
> exec plink $plinkopt "$@"
> -- snap --

I think that is a very sensible approach, but just like we have a few "built-in" function-header regexps with customization possibilities for the user, we might want to:

 * Have that "-x", "-T" in the command line we generate for OpenSSH;
 * Allow users to specify OpenSSH substitute via a configuration and/or
   environment variable, and have them use your script; and
 * Have a built-in logic for selected and common "OpenSSH substitute",
   e.g. plink.

There is no reason to make users suffer an extra redirection for common enough alternatives.

Here is to get it started...
 connect.c |   30 +++++++++++++++++++++++++++---
 1 files changed, 27 insertions(+), 3 deletions(-)
diff --git a/connect.c b/connect.c
index 574f42f..c72dd9e 100644
--- a/connect.c
+++ b/connect.c
@@ -599,12 +599,36 @@ struct child_process *git_connect(int fd[2], const char *url_orig,
 	conn->argv = arg = xcalloc(6, sizeof(*arg));
 	if (protocol == PROTO_SSH) {
 		const char *ssh = getenv("GIT_SSH");
+		const char *ssh_basename;
 		if (!ssh) ssh = "ssh";
 
+		ssh_basename = strrchr(ssh, '/');
+		ssh_basename = ssh_basename ? (ssh_basename + 1) : ssh;
+
 		*arg++ = ssh;
-		if (port) {
-			*arg++ = "-p";
-			*arg++ = port;
+		/*
+		 * Make sure to enlarge conn->argv if you add more
+		 * paremeters here.
+		 *
+		 * We know how to invoke a few ssh implementations
+		 * ourselves.
+		 */
+		if (!strcmp(ssh_basename, "plink")) {
+			if (port) {
+				*arg++ = "-P";
+				*arg++ = port;
+			}
+		} else {
+			/*
+			 * This is for stock OpenSSH, but you can have
+			 * your custom wrapper script to parse this
+			 * and invoke other ssh implementations after
+			 * rearranging parameters as well.
+			 */
+			if (port) {
+				*arg++ = "-p";
+				*arg++ = port;
+			}
 		}
 		*arg++ = host;
 	}
Previous: Fredrik TolfNext: Johannes Schindelin
Message 9 of 16 in “Ensure that SSH runs in non-interactive mode”
  1. Ensure that SSH runs in non-interactive modeFredrik Tolf, Jul 19, 2008
  2. Mike HommeyJul 19, 2008
  3. Keith PackardJul 19, 2008
  4. Fredrik TolfJul 19, 2008
  5. Johannes SchindelinJul 20, 2008
  6. Fredrik TolfJul 20, 2008
  7. Johannes SchindelinJul 20, 2008
  8. Fredrik TolfJul 20, 2008
  9. Junio C HamanoJul 20, 2008
  10. Johannes SchindelinJul 20, 2008
  11. Junio C HamanoJul 20, 2008
  12. Johannes SchindelinJul 20, 2008
  13. Steffen ProhaskaJul 21, 2008
  14. Jeff KingJul 21, 2008
  15. Mike HommeyJul 21, 2008
  16. Jeff KingJul 21, 2008

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.