Mercurial > gftp.yaz
diff lib/pty.c @ 458:656a0b3d1403
2004-4-10 Brian Masney <masneyb@gftp.org>
* lib/gftp.h lib/pty.c lib/sshv2.c - added gftp_exec() that will always
open a pseudo terminal and a separate socket pair for the stdin/stdout
file descriptors. The banner and password request will come through the
pseudo terminal while the sftp protocol specific data will always come
through the socket pair. This allows for a much cleaner SSH login
sequence that does not require echo xsftp to capture a login banner.
Removed option ssh_use_askpass since it is no longer needed.
This code is based off of a suggestion from Gertjan Halkes
* src/text/gftp-text.c - removed setting the options ssh_use_askpass
and sshv2_use_sftp_subsys
author | masneyb |
---|---|
date | Sat, 10 Apr 2004 15:14:46 +0000 |
parents | 094e83b55cb1 |
children | cb78cf311d23 |
line wrap: on
line diff
--- a/lib/pty.c Sat Apr 10 00:28:31 2004 +0000 +++ b/lib/pty.c Sat Apr 10 15:14:46 2004 +0000 @@ -259,7 +259,7 @@ static void -_gftp_close_all_fds (void) +_gftp_close_all_fds (int ptysfd) { int i, maxfds; @@ -272,16 +272,32 @@ #endif for (i=3; i<maxfds; i++) - close (i); + { + if (i == ptysfd) + continue; + + close (i); + } } pid_t -gftp_exec_without_new_pty (gftp_request * request, int *fdm, char **args) +gftp_exec (gftp_request * request, int *fdm, int *ptymfd, char **args) { + char pts_name[64]; pid_t child; + int ptysfd; int s[2]; + *pts_name = '\0'; + if ((*ptymfd = _gftp_ptym_open (pts_name, sizeof (pts_name), &ptysfd)) < 0) + { + request->logging_function (gftp_logging_error, request->user_data, + _("Cannot open master pty %s: %s\n"), pts_name, + g_strerror (errno)); + return (-1); + } + if (socketpair (AF_LOCAL, SOCK_STREAM, 0, s) < 0) { request->logging_function (gftp_logging_error, request, @@ -294,24 +310,36 @@ { setsid (); + if ((ptysfd = _gftp_ptys_open (*ptymfd, ptysfd, pts_name)) < 0) + { + printf ("Cannot open slave pts %s: %s\n", pts_name, + g_strerror (errno)); + return (-1); + } + close (s[0]); + close (*ptymfd); _gftp_tty_raw (s[1]); + _gftp_tty_raw (ptysfd); + dup2 (s[1], 0); dup2 (s[1], 1); - dup2 (s[1], 2); - _gftp_close_all_fds (); + _gftp_close_all_fds (ptysfd); execvp (args[0], args); printf (_("Error: Cannot execute ssh: %s\n"), g_strerror (errno)); - exit (1); + _exit (1); } else if (child > 0) { close (s[1]); + + *fdm = s[0]; _gftp_tty_raw (s[0]); - *fdm = s[0]; + _gftp_tty_raw (*ptymfd); + return (child); } else @@ -323,58 +351,3 @@ } } - -pid_t -gftp_exec_with_new_pty (gftp_request * request, int *fdm, char **args) -{ - char pts_name[64]; - pid_t child; - int fds; - - *pts_name = '\0'; - if ((*fdm = _gftp_ptym_open (pts_name, sizeof (pts_name), &fds)) < 0) - { - request->logging_function (gftp_logging_error, request->user_data, - _("Cannot open master pty %s: %s\n"), pts_name, - g_strerror (errno)); - return (-1); - } - - if ((child = fork ()) == 0) - { - setsid (); - - if ((fds = _gftp_ptys_open (*fdm, fds, pts_name)) < 0) - { - printf ("Cannot open slave pts %s: %s\n", pts_name, - g_strerror (errno)); - return (-1); - } - - close (*fdm); - - _gftp_tty_raw (fds); - dup2 (fds, 0); - dup2 (fds, 1); - dup2 (fds, 2); - _gftp_close_all_fds (); - - execvp (args[0], args); - - printf (_("Error: Cannot execute ssh: %s\n"), g_strerror (errno)); - exit (1); - } - else if (child > 0) - { - _gftp_tty_raw (*fdm); - return (child); - } - else - { - request->logging_function (gftp_logging_error, request->user_data, - _("Cannot fork another process: %s\n"), - g_strerror (errno)); - return (-1); - } -} -