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

[PATCH v2 2/2] git_connect: when using GIT_SSH_CMD, check for plink in argv[0] only

From
Thomas Quinot <thomas@quinot.org>
Date
Nov 8, 2014, 14:29 UTC
Message-ID
<20141108142940.GB28652@melamine.cuivre.fr.eu.org>
In-Reply-To
<20141108123554.GA90057@melamine.cuivre.fr.eu.org>

git_connect includes circuitry to use specific command line arguments when using PuTTY's plink. This circuitry is enabled based on the presence of the "plink" and "tortoiseplink" substrings in the name of the SSH program to use. When using GIT_SSH_CMD to specify a complete shell command to run for ssh connections, look for these substrings only in the program name (not in subsequent arguments).

Signed-off-by: Thomas Quinot <thomas@quinot.org>
---
 connect.c | 33 +++++++++++++++++++++++++++------
 1 file changed, 27 insertions(+), 6 deletions(-)
diff --git a/connect.c b/connect.c
index ecb1821..fcb928a 100644
--- a/connect.c
+++ b/connect.c
@@ -700,22 +700,42 @@ struct child_process *git_connect(int fd[2], const char *url,
 
 		conn->in = conn->out = -1;
 		if (protocol == PROTO_SSH) {
-			const char *ssh;
-			int putty;
+			const char *ssh_cmd, *ssh;
+			char *ssh_cmd_var = NULL;
+			char *putty;
 			char *ssh_host = hostandport;
 			const char *port = NULL;
 			get_host_and_port(&ssh_host, &port);
 			port = get_port_numeric(port);
 
-			ssh = getenv("GIT_SSH_CMD");
-			if (ssh)
+			ssh_cmd = getenv("GIT_SSH_CMD");
+			if (ssh_cmd) {
+				/*
+				 * Split command line to check for plink in
+				 * ssh_argv[0].
+				 */
+				const char **ssh_argv;
+				ssh_cmd_var = xstrdup(ssh_cmd);
+				int ssh_argc =
+				    split_cmdline(ssh_cmd_var, &ssh_argv);
+				if (ssh_argv < 0) {
+					free(ssh_argv);
+					free(ssh_cmd_var);
+					die("invalid GIT_SSH_CMD '%s': %s",
+					    ssh,
+					    split_cmdline_strerror(ssh_argc));
+				}
+				ssh = ssh_argv[0];
+				free(ssh_argv);
+
 				conn->use_shell = 1;
-			else {
+				argv_array_push(&conn->args, ssh_cmd);
+			} else {
 				ssh = getenv("GIT_SSH");
 				if (!ssh) ssh = "ssh";
+				argv_array_push(&conn->args, ssh);
 			}
 
-			argv_array_push(&conn->args, ssh);
 			putty = strcasestr(ssh, "plink");
 			if (putty && !strcasestr(ssh, "tortoiseplink"))
 				argv_array_push(&conn->args, "-batch");
@@ -725,6 +745,7 @@ struct child_process *git_connect(int fd[2], const char *url,
 				argv_array_push(&conn->args, port);
 			}
 			argv_array_push(&conn->args, ssh_host);
+			if (ssh_cmd_var) free(ssh_cmd_var);
 		} else {
 			/* remove repo-local variables from the environment */
 			conn->env = local_repo_env;
-- 
2.1.2
Previous: Junio C Hamano
Message 15 of 15 in “git_connect: allow passing arguments to ssh in GIT_SSH_ARGS”
  1. git_connect: allow passing arguments to ssh in GIT_SSH_ARGSThomas Quinot, Nov 8, 2014
  2. Jeff KingNov 8, 2014
  3. Thomas QuinotNov 8, 2014
  4. 1/2 git_connect: set ssh shell command in GIT_SSH_CMDThomas Quinot, Nov 8, 2014
  5. Jeff KingNov 9, 2014
  6. Thomas QuinotNov 9, 2014
  7. git_connect: set ssh shell command in GIT_SSH_CMDThomas Quinot, Nov 9, 2014
  8. Junio C HamanoNov 9, 2014
  9. Thomas QuinotNov 9, 2014
  10. Junio C HamanoNov 9, 2014
  11. git_connect: set ssh shell command in GIT_SSH_COMMANDThomas Quinot, Nov 9, 2014
  12. Jeff KingNov 10, 2014
  13. Thomas QuinotNov 10, 2014
  14. Junio C HamanoNov 10, 2014
  15. 2/2 git_connect: when using GIT_SSH_CMD, check for plink in argv[0] onlyThomas Quinot, Nov 8, 2014

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.