[BACK]Return to sshtty.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / ssh

Annotation of src/usr.bin/ssh/sshtty.c, Revision 1.14

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