Mercurial > gftp.yaz
diff lib/sshv2.c @ 210:82ebd1b05345
2003-7-6 Brian Masney <masneyb@gftp.org>
* lib/pty.c lib/gftp.h - added gftp_exec_with_new_pty() and
gftp_exec_without_new_pty()
* lib/sshv2.c - use the 2 new functions above
* lib/pty.c lib/gftp.h - split open_ptys() to _gftp_ptym_open()
and _gftp_ptys_open()
* lib/sslcommon.c - don't do thread setup if we are compiling against
glib 1.2. I do not want to link against the pthread library because
that would make the text port dependant on pthreads being installed on
the box
author | masneyb |
---|---|
date | Sun, 06 Jul 2003 13:52:43 +0000 |
parents | 13ca1defdc75 |
children | 3f2203e70218 |
line wrap: on
line diff
--- a/lib/sshv2.c Sat Jul 05 17:30:14 2003 +0000 +++ b/lib/sshv2.c Sun Jul 06 13:52:43 2003 +0000 @@ -813,7 +813,7 @@ static int sshv2_connect (gftp_request * request) { - int version, s[2], ret, ssh_use_askpass, sshv2_use_sftp_subsys; + int version, ret, ssh_use_askpass, sshv2_use_sftp_subsys, fdm; char **args, *tempstr, *p1, p2, *exepath, *ssh2_sftp_path; struct servent serv_struct; sshv2_message message; @@ -867,90 +867,56 @@ args = sshv2_gen_exec_args (request, exepath, sshv2_use_sftp_subsys); if (ssh_use_askpass || sshv2_use_sftp_subsys) - { - if (socketpair (AF_LOCAL, SOCK_STREAM, 0, s) < 0) - { - request->logging_function (gftp_logging_error, request, - _("Cannot create a socket pair: %s\n"), - g_strerror (errno)); - return (GFTP_ERETRYABLE); - } - } + child = gftp_exec_without_new_pty (request, &fdm, args); else - { - if ((ret = open_ptys (request, &s[0], &s[1])) < 0) - return (ret); - } - - if ((child = fork ()) == 0) + child = gftp_exec_with_new_pty (request, &fdm, args); + + if (child == 0) + exit (0); + else if (child < 0) + return (GFTP_ERETRYABLE); + + if (!sshv2_use_sftp_subsys) { - setsid (); - close (s[0]); - - tty_raw (s[1]); - dup2 (s[1], 0); - dup2 (s[1], 1); - dup2 (s[1], 2); - execvp (args[0], args); - - printf (_("Error: Cannot execute ssh: %s\n"), g_strerror (errno)); - exit (1); - } - else if (child > 0) - { - close (s[1]); - tty_raw (s[0]); - - if (!sshv2_use_sftp_subsys) + tempstr = sshv2_start_login_sequence (request, fdm); + if (!tempstr || !(strlen (tempstr) > 4 && strcmp (tempstr + strlen (tempstr) - 5, + "xsftp") == 0)) { - tempstr = sshv2_start_login_sequence (request, s[0]); - if (!tempstr || - !(strlen (tempstr) > 4 && strcmp (tempstr + strlen (tempstr) - 5, - "xsftp") == 0)) - { - sshv2_free_args (args); - g_free (exepath); - return (GFTP_EFATAL); - } - g_free (tempstr); + sshv2_free_args (args); + g_free (exepath); + return (GFTP_EFATAL); } - sshv2_free_args (args); - g_free (exepath); - - request->datafd = s[0]; + g_free (tempstr); + } - version = htonl (SSH_MY_VERSION); - if ((ret = sshv2_send_command (request, SSH_FXP_INIT, (char *) - &version, 4)) < 0) - return (ret); + sshv2_free_args (args); + g_free (exepath); - memset (&message, 0, sizeof (message)); - if ((ret = sshv2_read_response (request, &message, -1)) != SSH_FXP_VERSION) - { - request->logging_function (gftp_logging_error, request, - _("Received wrong response from server, disconnecting\n")); - sshv2_message_free (&message); - gftp_disconnect (request); + request->datafd = fdm; - if (ret < 0) - return (ret); - else - return (GFTP_ERETRYABLE); - } - sshv2_message_free (&message); + version = htonl (SSH_MY_VERSION); + if ((ret = sshv2_send_command (request, SSH_FXP_INIT, (char *) + &version, 4)) < 0) + return (ret); - request->logging_function (gftp_logging_misc, request, - _("Successfully logged into SSH server %s\n"), - request->hostname); - } - else + memset (&message, 0, sizeof (message)); + if ((ret = sshv2_read_response (request, &message, -1)) != SSH_FXP_VERSION) { request->logging_function (gftp_logging_error, request, - _("Cannot fork another process: %s\n"), - g_strerror (errno)); - g_free (args); - return (GFTP_ERETRYABLE); + _("Received wrong response from server, disconnecting\n")); + sshv2_message_free (&message); + gftp_disconnect (request); + + if (ret < 0) + return (ret); + else + return (GFTP_ERETRYABLE); } + sshv2_message_free (&message); + + request->logging_function (gftp_logging_misc, request, + _("Successfully logged into SSH server %s\n"), + request->hostname); if (sshv2_getcwd (request) < 0) {