Add the names of major contributors to the copyright statement. I've
[u/mdw/putty] / psftp.c
diff --git a/psftp.c b/psftp.c
index edc4bed..fead5c7 100644 (file)
--- a/psftp.c
+++ b/psftp.c
  */
 
 /* ----------------------------------------------------------------------
- * String handling routines.
- */
-
-char *dupstr(char *s)
-{
-    int len = strlen(s);
-    char *p = smalloc(len + 1);
-    strcpy(p, s);
-    return p;
-}
-
-/* Allocate the concatenation of N strings. Terminate arg list with NULL. */
-char *dupcat(char *s1, ...)
-{
-    int len;
-    char *p, *q, *sn;
-    va_list ap;
-
-    len = strlen(s1);
-    va_start(ap, s1);
-    while (1) {
-       sn = va_arg(ap, char *);
-       if (!sn)
-           break;
-       len += strlen(sn);
-    }
-    va_end(ap);
-
-    p = smalloc(len + 1);
-    strcpy(p, s1);
-    q = p + strlen(p);
-
-    va_start(ap, s1);
-    while (1) {
-       sn = va_arg(ap, char *);
-       if (!sn)
-           break;
-       strcpy(q, sn);
-       q += strlen(q);
-    }
-    va_end(ap);
-
-    return p;
-}
-
-/* ----------------------------------------------------------------------
  * sftp client state.
  */
 
@@ -1455,7 +1409,7 @@ int main(int argc, char *argv[])
     int modeflags = 0;
     char *batchfile = NULL;
 
-    flags = FLAG_STDERR;
+    flags = FLAG_STDERR | FLAG_INTERACTIVE;
     ssh_get_line = &get_line;
     init_winsock();
     sk_init();
@@ -1550,11 +1504,34 @@ int main(int argc, char *argv[])
     /* SFTP uses SSH2 by default always */
     cfg.sshprot = 2;
 
-    /* Set up subsystem name. FIXME: fudge for SSH1. */
+    /* Set up subsystem name. */
     strcpy(cfg.remote_cmd, "sftp");
     cfg.ssh_subsys = TRUE;
     cfg.nopty = TRUE;
 
+    /*
+     * Set up fallback option, for SSH1 servers or servers with the
+     * sftp subsystem not enabled but the server binary installed
+     * in the usual place. We only support fallback on Unix
+     * systems, and we use a kludgy piece of shellery which should
+     * try to find sftp-server in various places (the obvious
+     * systemwide spots /usr/lib and /usr/local/lib, and then the
+     * user's PATH) and finally give up.
+     * 
+     *   test -x /usr/lib/sftp-server && exec /usr/lib/sftp-server
+     *   test -x /usr/local/lib/sftp-server && exec /usr/local/lib/sftp-server
+     *   exec sftp-server
+     * 
+     * the idea being that this will attempt to use either of the
+     * obvious pathnames and then give up, and when it does give up
+     * it will print the preferred pathname in the error messages.
+     */
+    cfg.remote_cmd_ptr2 =
+       "test -x /usr/lib/sftp-server && exec /usr/lib/sftp-server\n"
+       "test -x /usr/local/lib/sftp-server && exec /usr/local/lib/sftp-server\n"
+       "exec sftp-server";
+    cfg.ssh_subsys2 = FALSE;
+
     back = &ssh_backend;
 
     err = back->init(cfg.host, cfg.port, &realhost);