[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#303362: scp: Restore termios flags on Ctrl-C



Package:	ssh
Version:	3.8.1p1

Hi!

Occassionally, I mistype my username when I try to scp a file from one
machine to another one. Typically, I then press Ctrl-C (while being at
the "Password:" prompt). Unfortunately, the termios settings aren't
restored then, leaving me with a terminal that doesn't echo my input. I
need to reset(1) then...

For inhouse use, I'm using this patch to fix the issue, maybe it's
useful for Debian (or even upstream), too:

diff -Nur openssh-3.8.1p1/scp.c openssh-3.8.1p1-hacked/scp.c
--- openssh-3.8.1p1/scp.c	2003-11-24 03:09:28.000000000 +0100
+++ openssh-3.8.1p1-hacked/scp.c	2005-04-06 12:24:31.000000000 +0200
@@ -109,12 +109,22 @@
 /* This is used to store the pid of ssh_program */
 pid_t do_cmd_pid = -1;
 
+/* Keep old terminal settings to restore them on Ctrl-C etc. */
+int termios_valid = -1;
+struct termios old_termios[3];
+
 static void
 killchild(int signo)
 {
 	if (do_cmd_pid > 1)
 		kill(do_cmd_pid, signo);
 
+	if (termios_valid == 0) {
+		(void) tcsetattr(STDIN_FILENO,  TCSANOW, &old_termios[0]);
+		(void) tcsetattr(STDOUT_FILENO, TCSANOW, &old_termios[1]);
+		(void) tcsetattr(STDERR_FILENO, TCSANOW, &old_termios[2]);
+	}
+
 	_exit(1);
 }
 
@@ -298,6 +308,10 @@
 	argc -= optind;
 	argv += optind;
 
+	termios_valid  = tcgetattr(STDIN_FILENO,  &old_termios[0]);
+	termios_valid |= tcgetattr(STDOUT_FILENO, &old_termios[1]);
+	termios_valid |= tcgetattr(STDERR_FILENO, &old_termios[2]);
+
 	if ((pwd = getpwuid(userid = getuid())) == NULL)
 		fatal("unknown user %u", (u_int) userid);
 

Thanks, JBG

-- 
Jan-Benedict Glaw       jbglaw@lug-owl.de    . +49-172-7608481             _ O _
"Eine Freie Meinung in  einem Freien Kopf    | Gegen Zensur | Gegen Krieg  _ _ O
 fuer einen Freien Staat voll Freier Bürger" | im Internet! |   im Irak!   O O O
ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA));

Attachment: signature.asc
Description: Digital signature


Reply to: