Revamp SSH authentication code so that user interaction is more
[u/mdw/putty] / windows / winsftp.c
index d9ea3ca..47d3c43 100644 (file)
@@ -125,6 +125,17 @@ void gui_enable(char *arg)
     gui_hwnd = (HWND) atoi(arg);
 }
 
+char *get_ttymode(void *frontend, const char *mode) { return NULL; }
+
+int get_userpass_input(prompts_t *p, unsigned char *in, int inlen)
+{
+    int ret;
+    ret = cmdline_get_passwd_input(p, in, inlen);
+    if (ret == -1)
+       ret = console_get_userpass_input(p, in, inlen);
+    return ret;
+}
+
 /* ----------------------------------------------------------------------
  * File access abstraction.
  */
@@ -306,20 +317,26 @@ DirHandle *open_directory(char *name)
 
 char *read_filename(DirHandle *dir)
 {
-    while (!dir->name) {
-       WIN32_FIND_DATA fdat;
-       int ok = FindNextFile(dir->h, &fdat);
+    do {
 
-       if (!ok)
-           return NULL;
+       if (!dir->name) {
+           WIN32_FIND_DATA fdat;
+           int ok = FindNextFile(dir->h, &fdat);
+           if (!ok)
+               return NULL;
+           else
+               dir->name = dupstr(fdat.cFileName);
+       }
 
-       if (fdat.cFileName[0] == '.' &&
-           (fdat.cFileName[1] == '\0' ||
-            (fdat.cFileName[1] == '.' && fdat.cFileName[2] == '\0')))
+       assert(dir->name);
+       if (dir->name[0] == '.' &&
+           (dir->name[1] == '\0' ||
+            (dir->name[1] == '.' && dir->name[2] == '\0'))) {
+           sfree(dir->name);
            dir->name = NULL;
-       else
-           dir->name = dupstr(fdat.cFileName);
-    }
+       }
+
+    } while (!dir->name);
 
     if (dir->name) {
        char *ret = dir->name;
@@ -445,6 +462,17 @@ void finish_wildcard_matching(WildcardMatcher *dir)
     sfree(dir);
 }
 
+int vet_filename(char *name)
+{
+    if (strchr(name, '/') || strchr(name, '\\') || strchr(name, ':'))
+       return FALSE;
+
+    if (!name[strspn(name, ".")])      /* entirely composed of dots */
+       return FALSE;
+
+    return TRUE;
+}
+
 int create_directory(char *name)
 {
     return CreateDirectory(name, NULL) != 0;
@@ -462,7 +490,7 @@ char *dir_file_cat(char *dir, char *file)
 /*
  * Be told what socket we're supposed to be using.
  */
-static SOCKET sftp_ssh_socket;
+static SOCKET sftp_ssh_socket = INVALID_SOCKET;
 static HANDLE netevent = NULL;
 char *do_select(SOCKET skt, int startup)
 {
@@ -676,7 +704,7 @@ static DWORD WINAPI command_read_thread(void *param)
     return 0;
 }
 
-char *ssh_sftp_get_cmdline(char *prompt)
+char *ssh_sftp_get_cmdline(char *prompt, int no_fds_ok)
 {
     int ret;
     struct command_read_ctx actx, *ctx = &actx;
@@ -685,7 +713,8 @@ char *ssh_sftp_get_cmdline(char *prompt)
     fputs(prompt, stdout);
     fflush(stdout);
 
-    if (sftp_ssh_socket == INVALID_SOCKET || p_WSAEventSelect == NULL) {
+    if ((sftp_ssh_socket == INVALID_SOCKET && no_fds_ok) ||
+       p_WSAEventSelect == NULL) {
        return fgetline(stdin);        /* very simple */
     }