Ben Lindstrom | e626cf8 | 2001-04-14 23:21:50 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
| 3 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
| 4 | * All rights reserved |
| 5 | * |
| 6 | * As far as I am concerned, the code I have written for this software |
| 7 | * can be used freely for any purpose. Any derived versions of this |
| 8 | * software must be clearly marked as such, and if the derived work is |
| 9 | * incompatible with the protocol description in the RFC file, it must be |
| 10 | * called by a name other than "ssh" or "Secure Shell". |
| 11 | */ |
| 12 | /* |
| 13 | * Copyright (c) 2001 Markus Friedl. All rights reserved. |
| 14 | * Copyright (c) 2001 Kevin Steves. All rights reserved. |
| 15 | * |
| 16 | * Redistribution and use in source and binary forms, with or without |
| 17 | * modification, are permitted provided that the following conditions |
| 18 | * are met: |
| 19 | * 1. Redistributions of source code must retain the above copyright |
| 20 | * notice, this list of conditions and the following disclaimer. |
| 21 | * 2. Redistributions in binary form must reproduce the above copyright |
| 22 | * notice, this list of conditions and the following disclaimer in the |
| 23 | * documentation and/or other materials provided with the distribution. |
| 24 | * |
| 25 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 26 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 27 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 28 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 30 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 31 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 32 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 33 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 34 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 35 | */ |
| 36 | |
| 37 | #include "includes.h" |
Damien Miller | 972c84b | 2006-03-15 11:11:56 +1100 | [diff] [blame] | 38 | RCSID("$OpenBSD: sshtty.c,v 1.8 2006/02/07 01:52:50 stevesk Exp $"); |
Damien Miller | 99bd21e | 2006-03-15 11:11:28 +1100 | [diff] [blame] | 39 | |
| 40 | #include <termios.h> |
Ben Lindstrom | e626cf8 | 2001-04-14 23:21:50 +0000 | [diff] [blame] | 41 | |
Darren Tucker | 06f2bd8 | 2004-05-13 16:06:46 +1000 | [diff] [blame] | 42 | #include "sshpty.h" |
Ben Lindstrom | e626cf8 | 2001-04-14 23:21:50 +0000 | [diff] [blame] | 43 | |
| 44 | static struct termios _saved_tio; |
| 45 | static int _in_raw_mode = 0; |
| 46 | |
Ben Lindstrom | e626cf8 | 2001-04-14 23:21:50 +0000 | [diff] [blame] | 47 | struct termios |
| 48 | get_saved_tio(void) |
| 49 | { |
| 50 | return _saved_tio; |
| 51 | } |
| 52 | |
| 53 | void |
| 54 | leave_raw_mode(void) |
| 55 | { |
| 56 | if (!_in_raw_mode) |
| 57 | return; |
| 58 | if (tcsetattr(fileno(stdin), TCSADRAIN, &_saved_tio) == -1) |
| 59 | perror("tcsetattr"); |
| 60 | else |
| 61 | _in_raw_mode = 0; |
Ben Lindstrom | e626cf8 | 2001-04-14 23:21:50 +0000 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | void |
| 65 | enter_raw_mode(void) |
| 66 | { |
| 67 | struct termios tio; |
| 68 | |
| 69 | if (tcgetattr(fileno(stdin), &tio) == -1) { |
| 70 | perror("tcgetattr"); |
| 71 | return; |
| 72 | } |
| 73 | _saved_tio = tio; |
| 74 | tio.c_iflag |= IGNPAR; |
| 75 | tio.c_iflag &= ~(ISTRIP | INLCR | IGNCR | ICRNL | IXON | IXANY | IXOFF); |
Darren Tucker | 538d180 | 2003-07-19 19:56:18 +1000 | [diff] [blame] | 76 | #ifdef IUCLC |
| 77 | tio.c_iflag &= ~IUCLC; |
| 78 | #endif |
Ben Lindstrom | e626cf8 | 2001-04-14 23:21:50 +0000 | [diff] [blame] | 79 | tio.c_lflag &= ~(ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHONL); |
| 80 | #ifdef IEXTEN |
| 81 | tio.c_lflag &= ~IEXTEN; |
| 82 | #endif |
| 83 | tio.c_oflag &= ~OPOST; |
| 84 | tio.c_cc[VMIN] = 1; |
| 85 | tio.c_cc[VTIME] = 0; |
| 86 | if (tcsetattr(fileno(stdin), TCSADRAIN, &tio) == -1) |
| 87 | perror("tcsetattr"); |
| 88 | else |
| 89 | _in_raw_mode = 1; |
Ben Lindstrom | e626cf8 | 2001-04-14 23:21:50 +0000 | [diff] [blame] | 90 | } |