t7800: readlink may not be available
[gitweb.git] / connect.c
index 391d21192f8d9593ce9b194488019eae3ec7d8d3..27a706f76621621a25b7e58188e5d1da9b9a2ccd 100644 (file)
--- a/connect.c
+++ b/connect.c
@@ -9,6 +9,7 @@
 #include "url.h"
 #include "string-list.h"
 #include "sha1-array.h"
+#include "transport.h"
 
 static char *server_capabilities;
 static const char *parse_feature_value(const char *, const char *, int *);
@@ -694,6 +695,8 @@ struct child_process *git_connect(int fd[2], const char *url,
                else
                        target_host = xstrdup(hostandport);
 
+               transport_check_allowed("git");
+
                /* These underlying connection commands die() if they
                 * cannot connect.
                 */
@@ -724,9 +727,10 @@ 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;
+                       int putty, tortoiseplink = 0;
                        char *ssh_host = hostandport;
                        const char *port = NULL;
+                       transport_check_allowed("ssh");
                        get_host_and_port(&ssh_host, &port);
 
                        if (!port)
@@ -743,32 +747,45 @@ struct child_process *git_connect(int fd[2], const char *url,
                                free(path);
                                free(conn);
                                return NULL;
+                       }
+
+                       ssh = getenv("GIT_SSH_COMMAND");
+                       if (ssh) {
+                               conn->use_shell = 1;
+                               putty = 0;
                        } else {
-                               ssh = getenv("GIT_SSH_COMMAND");
-                               if (ssh) {
-                                       conn->use_shell = 1;
-                                       putty = 0;
-                               } else {
-                                       ssh = getenv("GIT_SSH");
-                                       if (!ssh)
-                                               ssh = "ssh";
-                                       putty = !!strcasestr(ssh, "plink");
-                               }
-
-                               argv_array_push(&conn->args, ssh);
-                               if (putty && !strcasestr(ssh, "tortoiseplink"))
-                                       argv_array_push(&conn->args, "-batch");
-                               if (port) {
-                                       /* P is for PuTTY, p is for OpenSSH */
-                                       argv_array_push(&conn->args, putty ? "-P" : "-p");
-                                       argv_array_push(&conn->args, port);
-                               }
-                               argv_array_push(&conn->args, ssh_host);
+                               const char *base;
+                               char *ssh_dup;
+
+                               ssh = getenv("GIT_SSH");
+                               if (!ssh)
+                                       ssh = "ssh";
+
+                               ssh_dup = xstrdup(ssh);
+                               base = basename(ssh_dup);
+
+                               tortoiseplink = !strcasecmp(base, "tortoiseplink") ||
+                                       !strcasecmp(base, "tortoiseplink.exe");
+                               putty = !strcasecmp(base, "plink") ||
+                                       !strcasecmp(base, "plink.exe") || tortoiseplink;
+
+                               free(ssh_dup);
+                       }
+
+                       argv_array_push(&conn->args, ssh);
+                       if (tortoiseplink)
+                               argv_array_push(&conn->args, "-batch");
+                       if (port) {
+                               /* P is for PuTTY, p is for OpenSSH */
+                               argv_array_push(&conn->args, putty ? "-P" : "-p");
+                               argv_array_push(&conn->args, port);
                        }
+                       argv_array_push(&conn->args, ssh_host);
                } else {
                        /* remove repo-local variables from the environment */
                        conn->env = local_repo_env;
                        conn->use_shell = 1;
+                       transport_check_allowed("file");
                }
                argv_array_push(&conn->args, cmd.buf);