First crack at `terminal-modes' in SSH. PuTTY now sends ERASE by default,
authorjacob <jacob@cda61777-01e9-0310-a592-d414129be87e>
Thu, 21 Apr 2005 13:57:08 +0000 (13:57 +0000)
committerjacob <jacob@cda61777-01e9-0310-a592-d414129be87e>
Thu, 21 Apr 2005 13:57:08 +0000 (13:57 +0000)
Unix Plink sends everything sensible it can find, and it's fully configurable
from the GUI.

I'm not entirely sure about the precise set of modes that Unix Plink should
look at; informed tweaks are welcome.

Also the Mac bits are guesses (but trivial).

git-svn-id: svn://svn.tartarus.org/sgt/putty@5653 cda61777-01e9-0310-a592-d414129be87e

16 files changed:
config.c
doc/config.but
doc/index.but
mac/macterm.c
macosx/osxwin.m
putty.h
settings.c
ssh.c
terminal.c
unix/gtkwin.c
unix/uxplink.c
unix/uxsftp.c
windows/window.c
windows/winhelp.h
windows/winplink.c
windows/winsftp.c

index 638e3d8..71d3ac0 100644 (file)
--- a/config.c
+++ b/config.c
@@ -602,6 +602,99 @@ static void colour_handler(union control *ctrl, void *dlg,
     }
 }
 
+struct ttymodes_data {
+    union control *modelist, *valradio, *valbox;
+    union control *addbutton, *rembutton, *listbox;
+};
+
+static void ttymodes_handler(union control *ctrl, void *dlg,
+                            void *data, int event)
+{
+    Config *cfg = (Config *)data;
+    struct ttymodes_data *td =
+       (struct ttymodes_data *)ctrl->generic.context.p;
+
+    if (event == EVENT_REFRESH) {
+       if (ctrl == td->listbox) {
+           char *p = cfg->ttymodes;
+           dlg_update_start(ctrl, dlg);
+           dlg_listbox_clear(ctrl, dlg);
+           while (*p) {
+               int tabpos = strchr(p, '\t') - p;
+               char *disp = dupprintf("%.*s\t%s", tabpos, p,
+                                      (p[tabpos+1] == 'A') ? "(auto)" :
+                                      p+tabpos+2);
+               dlg_listbox_add(ctrl, dlg, disp);
+               p += strlen(p) + 1;
+               sfree(disp);
+           }
+           dlg_update_done(ctrl, dlg);
+       } else if (ctrl == td->modelist) {
+           int i;
+           dlg_update_start(ctrl, dlg);
+           dlg_listbox_clear(ctrl, dlg);
+           for (i = 0; ttymodes[i]; i++)
+               dlg_listbox_add(ctrl, dlg, ttymodes[i]);
+           dlg_listbox_select(ctrl, dlg, 0); /* *shrug* */
+           dlg_update_done(ctrl, dlg);
+       } else if (ctrl == td->valradio) {
+           dlg_radiobutton_set(ctrl, dlg, 0);
+       }
+    } else if (event == EVENT_ACTION) {
+       if (ctrl == td->addbutton) {
+           int ind = dlg_listbox_index(td->modelist, dlg);
+           if (ind >= 0) {
+               char type = dlg_radiobutton_get(td->valradio, dlg) ? 'V' : 'A';
+               int slen, left;
+               char *p, str[lenof(cfg->ttymodes)];
+               /* Construct new entry */
+               memset(str, 0, lenof(str));
+               strncpy(str, ttymodes[ind], lenof(str)-3);
+               slen = strlen(str);
+               str[slen] = '\t';
+               str[slen+1] = type;
+               slen += 2;
+               if (type == 'V') {
+                   dlg_editbox_get(td->valbox, dlg, str+slen, lenof(str)-slen);
+               }
+               /* Find end of list, deleting any existing instance */
+               p = cfg->ttymodes;
+               left = lenof(cfg->ttymodes);
+               while (*p) {
+                   int t = strchr(p, '\t') - p;
+                   if (t == strlen(ttymodes[ind]) &&
+                       strncmp(p, ttymodes[ind], t) == 0) {
+                       memmove(p, p+strlen(p)+1, left - (strlen(p)+1));
+                       continue;
+                   }
+                   left -= strlen(p) + 1;
+                   p    += strlen(p) + 1;
+               }
+               /* Append new entry */
+               memset(p, 0, left);
+               strncpy(p, str, left - 2);
+               dlg_refresh(td->listbox, dlg);
+           } else
+               dlg_beep(dlg);
+       } else if (ctrl == td->rembutton) {
+           char *p = cfg->ttymodes;
+           int i = 0, len = lenof(cfg->ttymodes);
+           while (*p) {
+               if (dlg_listbox_issel(td->listbox, dlg, i)) {
+                   memmove(p, p+strlen(p)+1, len - (strlen(p)+1));
+                   i++;
+                   continue;
+               }
+               len -= strlen(p) + 1;
+               p   += strlen(p) + 1;
+               i++;
+           }
+           memset(p, 0, lenof(cfg->ttymodes) - len);
+           dlg_refresh(td->listbox, dlg);
+       }
+    }
+}
+
 struct environ_data {
     union control *varbox, *valbox, *addbutton, *rembutton, *listbox;
 };
@@ -827,6 +920,7 @@ void setup_config_box(struct controlbox *b, int midsession,
     struct sessionsaver_data *ssd;
     struct charclass_data *ccd;
     struct colour_data *cd;
+    struct ttymodes_data *td;
     struct environ_data *ed;
     struct portfwd_data *pfd;
     union control *c;
@@ -1641,10 +1735,6 @@ void setup_config_box(struct controlbox *b, int midsession,
                         I(sizeof(((Config *)0)->remote_cmd)));
 
            s = ctrl_getset(b, "Connection/SSH", "protocol", "Protocol options");
-           ctrl_checkbox(s, "Don't allocate a pseudo-terminal", 'p',
-                         HELPCTX(ssh_nopty),
-                         dlg_stdcheckbox_handler,
-                         I(offsetof(Config,nopty)));
            ctrl_checkbox(s, "Don't start a shell or command at all", 'n',
                          HELPCTX(ssh_noshell),
                          dlg_stdcheckbox_handler,
@@ -1755,6 +1845,72 @@ void setup_config_box(struct controlbox *b, int midsession,
 
        if (!midsession) {
            /*
+            * The Connection/SSH/TTY panel.
+            */
+           ctrl_settitle(b, "Connection/SSH/TTY", "Remote terminal settings");
+
+           s = ctrl_getset(b, "Connection/SSH/TTY", "sshtty", NULL);
+           ctrl_checkbox(s, "Don't allocate a pseudo-terminal", 'p',
+                         HELPCTX(ssh_nopty),
+                         dlg_stdcheckbox_handler,
+                         I(offsetof(Config,nopty)));
+
+           s = ctrl_getset(b, "Connection/SSH/TTY", "ttymodes",
+                           "Terminal modes");
+           td = (struct ttymodes_data *)
+               ctrl_alloc(b, sizeof(struct ttymodes_data));
+           ctrl_columns(s, 2, 75, 25);
+           c = ctrl_text(s, "Terminal modes to send:", HELPCTX(ssh_ttymodes));
+           c->generic.column = 0;
+           td->rembutton = ctrl_pushbutton(s, "Remove", 'r',
+                                           HELPCTX(ssh_ttymodes),
+                                           ttymodes_handler, P(td));
+           td->rembutton->generic.column = 1;
+           td->rembutton->generic.tabdelay = 1;
+           ctrl_columns(s, 1, 100);
+           td->listbox = ctrl_listbox(s, NULL, NO_SHORTCUT,
+                                      HELPCTX(ssh_ttymodes),
+                                      ttymodes_handler, P(td));
+           td->listbox->listbox.multisel = 1;
+           td->listbox->listbox.height = 4;
+           td->listbox->listbox.ncols = 2;
+           td->listbox->listbox.percentages = snewn(2, int);
+           td->listbox->listbox.percentages[0] = 40;
+           td->listbox->listbox.percentages[1] = 60;
+           ctrl_tabdelay(s, td->rembutton);
+           ctrl_columns(s, 2, 75, 25);
+           td->modelist = ctrl_droplist(s, "Mode:", 'm', 67,
+                                        HELPCTX(ssh_ttymodes),
+                                        ttymodes_handler, P(td));
+           td->modelist->generic.column = 0;
+           td->addbutton = ctrl_pushbutton(s, "Add", 'd',
+                                           HELPCTX(ssh_ttymodes),
+                                           ttymodes_handler, P(td));
+           td->addbutton->generic.column = 1;
+           td->addbutton->generic.tabdelay = 1;
+           ctrl_columns(s, 1, 100);        /* column break */
+           /* Bit of a hack to get the value radio buttons and
+            * edit-box on the same row. */
+           ctrl_columns(s, 3, 25, 50, 25);
+           c = ctrl_text(s, "Value:", HELPCTX(ssh_ttymodes));
+           c->generic.column = 0;
+           td->valradio = ctrl_radiobuttons(s, NULL, NO_SHORTCUT, 2,
+                                            HELPCTX(ssh_ttymodes),
+                                            ttymodes_handler, P(td),
+                                            "Auto", NO_SHORTCUT, P(NULL),
+                                            "This:", NO_SHORTCUT, P(NULL),
+                                            NULL);
+           td->valradio->generic.column = 1;
+           td->valbox = ctrl_editbox(s, NULL, NO_SHORTCUT, 100,
+                                     HELPCTX(ssh_ttymodes),
+                                     ttymodes_handler, P(td), P(NULL));
+           td->valbox->generic.column = 2;
+           ctrl_tabdelay(s, td->addbutton);
+
+       }
+
+       if (!midsession) {
+           /*
             * The Connection/SSH/X11 panel.
             */
            ctrl_settitle(b, "Connection/SSH/X11",
index a6219a5..1ac177e 100644 (file)
@@ -515,9 +515,12 @@ known as \i{Control-?}) so that it can be distinguished from Control-H.
 This option allows you to choose which code PuTTY generates when you
 press Backspace.
 
-If you are connecting to a Unix system, you will probably find that
+If you are connecting over SSH, PuTTY by default tells the server
+the value of this option (see \k{config-ttymodes}), so you may find
+that the Backspace key does the right thing either way. Similarly,
+if you are connecting to a \i{Unix} system, you will probably find that
 the Unix \i\c{stty} command lets you configure which the server
-expects to see, so you might not need to change which one PuTTY
+expects to see, so again you might not need to change which one PuTTY
 generates. On other systems, the server's expectation might be fixed
 and you might have no choice but to configure PuTTY.
 
@@ -2049,22 +2052,6 @@ Instead, you can choose to run a single specific command (such as a
 mail user agent, for example). If you want to do this, enter the
 command in the \q{\ii{Remote command}} box.
 
-\S{config-ssh-pty} \I{pseudo-terminal allocation}\q{Don't allocate
-a pseudo-terminal}
-
-\cfg{winhelp-topic}{ssh.nopty}
-
-When connecting to a \i{Unix} system, most \I{interactive
-connections}interactive shell sessions are run in a \e{pseudo-terminal},
-which allows the Unix system to pretend it's talking to a real physical
-terminal device but allows the SSH server to catch all the data coming
-from that fake device and send it back to the client.
-
-Occasionally you might find you have a need to run a session \e{not}
-in a pseudo-terminal. In PuTTY, this is generally only useful for
-very specialist purposes; although in Plink (see \k{plink}) it is
-the usual way of working.
-
 \S{config-ssh-noshell} \q{Don't start a \I{remote shell}shell or
 \I{remote command}command at all}
 
@@ -2372,6 +2359,112 @@ This key must be in PuTTY's native format (\c{*.\i{PPK}}). If you have a
 private key in another format that you want to use with PuTTY, see
 \k{puttygen-conversions}.
 
+\H{config-ssh-tty} The TTY panel
+
+The TTY panel lets you configure the remote pseudo-terminal.
+
+\S{config-ssh-pty} \I{pseudo-terminal allocation}\q{Don't allocate
+a pseudo-terminal}
+
+\cfg{winhelp-topic}{ssh.nopty}
+
+When connecting to a \i{Unix} system, most \I{interactive
+connections}interactive shell sessions are run in a \e{pseudo-terminal},
+which allows the Unix system to pretend it's talking to a real physical
+terminal device but allows the SSH server to catch all the data coming
+from that fake device and send it back to the client.
+
+Occasionally you might find you have a need to run a session \e{not}
+in a pseudo-terminal. In PuTTY, this is generally only useful for
+very specialist purposes; although in Plink (see \k{plink}) it is
+the usual way of working.
+
+\S{config-ttymodes} Sending \i{terminal modes}
+
+\cfg{winhelp-topic}{ssh.ttymodes}
+
+The SSH protocol allows the client to send \q{terminal modes} for
+the remote pseudo-terminal. These usually control the server's
+expectation of the local terminal's behaviour.
+
+If your server does not have sensible defaults for these modes, you
+may find that changing them here helps. If you don't understand any of
+this, it's safe to leave these settings alone.
+
+(None of these settings will have any effect if no pseudo-terminal
+is requested or allocated.)
+
+You can add or modify a mode by selecting it from the drop-down list,
+choosing whether it's set automatically or to a specific value with
+the radio buttons and edit box, and hitting \q{Add}. A mode (or
+several) can be removed from the list by selecting them and hitting
+\q{Remove}. The effect of the mode list is as follows:
+
+\b If a mode is not on the list, it will not be specified to the
+server under any circumstances.
+
+\b If a mode is on the list:
+
+\lcont{
+
+\b If the \q{Auto} option is selected, the PuTTY tools will decide
+whether to specify that mode to the server, and if so, will send
+a sensible value.
+
+\lcont{
+
+PuTTY proper will send modes that it has an opinion on (currently only
+the code for the Backspace key, \cw{ERASE}). Plink on Unix
+will propagate appropriate modes from the local terminal, if any.
+
+}
+
+\b If a value is specified, it will be sent to the server under all
+circumstances. The precise syntax of the value box depends on the
+mode.
+
+}
+
+By default, all of the available modes are listed as \q{Auto},
+which should do the right thing in most circumstances.
+
+The precise effect of each setting, if any, is up to the server. Their
+names come from \i{POSIX} and other Unix systems, and they are most
+likely to have a useful effect on such systems. (These are the same
+settings that can usually be changed using the \i\c{stty} command once
+logged in to such servers.)
+
+Some notable modes are described below; for fuller explanations, see
+your server documentation.
+
+\b \I{ERASE special character}\cw{ERASE} is the character that when typed
+by the user will delete one space to the left. When set to \q{Auto}
+(the default setting), this follows the setting of the local Backspace
+key in PuTTY (see \k{config-backspace}).
+
+\lcont{
+This and other \i{special character}s are specified using \c{^C} notation
+for Ctrl-C, and so on. Use \c{^<27>} or \c{^<0x1B>} to specify a
+character numerically, and \c{^~} to get a literal \c{^}. Other
+non-control characters are denoted by themselves. Leaving the box
+entirely blank indicates that \e{no} character should be assigned to
+the specified function, although this may not be supported by all
+servers.
+}
+
+\b \I{QUIT special character}\cw{QUIT} is a special character that
+usually forcefully ends the current process on the server
+(\cw{SIGQUIT}). On many servers its default setting is Ctrl-backslash
+(\c{^\\}), which is easy to accidentally invoke on many keyboards. If
+this is getting in your way, you may want to change it to another
+character or turn it off entirely.
+
+\b Boolean modes such as \cw{ECHO} and \cw{ICANON} can be specified in
+PuTTY in a variety of ways, such as \cw{true}/\cw{false},
+\cw{yes}/\cw{no}, and \cw{0}/\cw{1}.
+
+\b Terminal speeds are configured elsewhere; see \k{config-termspeed}.
+
 \H{config-ssh-x11} The X11 panel
 
 \cfg{winhelp-topic}{ssh.tunnels.x11}
index 8ff9308..44977a0 100644 (file)
@@ -191,6 +191,11 @@ saved sessions from
 \IM{pseudo-terminal allocation} pty allocation
 \IM{pseudo-terminal allocation} allocation, of pseudo-terminal
 
+\IM{ERASE special character} \cw{ERASE}, special character
+\IM{ERASE special character} \cw{VERASE}, special character
+\IM{QUIT special character} \cw{QUIT}, special character
+\IM{QUIT special character} \cw{VQUIT}, special character
+
 \IM{-telnet} \c{-telnet} command-line option
 \IM{-raw} \c{-raw} command-line option
 \IM{-rlogin} \c{-rlogin} command-line option
index d5a6014..443c0c8 100644 (file)
@@ -1845,6 +1845,12 @@ void ldisc_update(void *frontend, int echo, int edit)
 {
 }
 
+char *get_ttymode(void *frontend, const char *mode)
+{
+    Session *s = frontend;
+    return term_get_ttymode(s->term, mode);
+}
+
 /*
  * Mac PuTTY doesn't support printing yet.
  */
index 59cc4bf..f3cba03 100644 (file)
@@ -913,6 +913,13 @@ void ldisc_update(void *frontend, int echo, int edit)
      */
 }
 
+char *get_ttymode(void *frontend, const char *mode)
+{
+    SessionWindow *win = (SessionWindow *)ctx;
+    Terminal *term = [win term];
+    return term_get_ttymode(term, mode);
+}
+
 void update_specials_menu(void *frontend)
 {
     //SessionWindow *win = (SessionWindow *)frontend;
diff --git a/putty.h b/putty.h
index b08eec8..0dfb42c 100644 (file)
--- a/putty.h
+++ b/putty.h
@@ -324,6 +324,8 @@ enum {
     FUNKY_SCO
 };
 
+extern const char *const ttymodes[];
+
 enum {
     /*
      * Network address types. Used for specifying choice of IPv4/v6
@@ -438,6 +440,7 @@ struct config_tag {
     /* Telnet options */
     char termtype[32];
     char termspeed[32];
+    char ttymodes[768];                       /* MODE\tVvalue\0MODE\tA\0\0 */
     char environmt[1024];             /* VAR\tvalue\0VAR\tvalue\0\0 */
     char username[100];
     char localusername[100];
@@ -647,6 +650,9 @@ void ldisc_update(void *frontend, int echo, int edit);
 void update_specials_menu(void *frontend);
 int from_backend(void *frontend, int is_stderr, const char *data, int len);
 void notify_remote_exit(void *frontend);
+/* Get a sensible value for a tty mode. NULL return = don't set.
+ * Otherwise, returned value should be freed by caller. */
+char *get_ttymode(void *frontend, const char *mode);
 #define OPTIMISE_IS_SCROLL 1
 
 void set_iconic(void *frontend, int iconic);
@@ -741,6 +747,7 @@ void term_provide_resize_fn(Terminal *term,
                            void *resize_ctx);
 void term_provide_logctx(Terminal *term, void *logctx);
 void term_set_focus(Terminal *term, int has_focus);
+char *term_get_ttymode(Terminal *term, const char *mode);
 
 /*
  * Exports from logging.c.
index 9dce4f8..4058b7d 100644 (file)
@@ -29,6 +29,27 @@ static const struct keyval kexnames[] = {
     { "WARN",              KEX_WARN }
 };
 
+/*
+ * All the terminal modes that we know about for the "TerminalModes"
+ * setting. (Also used by config.c for the drop-down list.)
+ * This is currently precisely the same as the set in ssh.c, but could
+ * in principle differ if other backends started to support tty modes
+ * (e.g., the pty backend).
+ */
+const char *const ttymodes[] = {
+    "INTR",    "QUIT",     "ERASE",    "KILL",     "EOF",
+    "EOL",     "EOL2",     "START",    "STOP",     "SUSP",
+    "DSUSP",   "REPRINT",  "WERASE",   "LNEXT",    "FLUSH",
+    "SWTCH",   "STATUS",   "DISCARD",  "IGNPAR",   "PARMRK",
+    "INPCK",   "ISTRIP",   "INLCR",    "IGNCR",    "ICRNL",
+    "IUCLC",   "IXON",     "IXANY",    "IXOFF",    "IMAXBEL",
+    "ISIG",    "ICANON",   "XCASE",    "ECHO",     "ECHOE",
+    "ECHOK",   "ECHONL",   "NOFLSH",   "TOSTOP",   "IEXTEN",
+    "ECHOCTL", "ECHOKE",   "PENDIN",   "OPOST",    "OLCUC",
+    "ONLCR",   "OCRNL",    "ONOCR",    "ONLRET",   "CS7",
+    "CS8",     "PARENB",   "PARODD",   NULL
+};
+
 static void gpps(void *handle, const char *name, const char *def,
                 char *val, int len)
 {
@@ -252,6 +273,7 @@ void save_open_settings(void *sesskey, int do_host, Config *cfg)
     write_setting_i(sesskey, "TCPKeepalives", cfg->tcp_keepalives);
     write_setting_s(sesskey, "TerminalType", cfg->termtype);
     write_setting_s(sesskey, "TerminalSpeed", cfg->termspeed);
+    wmap(sesskey, "TerminalModes", cfg->ttymodes, lenof(cfg->ttymodes));
 
     /* Address family selection */
     write_setting_i(sesskey, "AddressFamily", cfg->addressfamily);
@@ -471,6 +493,21 @@ void load_open_settings(void *sesskey, int do_host, Config *cfg)
         sizeof(cfg->termtype));
     gpps(sesskey, "TerminalSpeed", "38400,38400", cfg->termspeed,
         sizeof(cfg->termspeed));
+    {
+       /* This hardcodes a big set of defaults in any new saved
+        * sessions. Let's hope we don't change our mind. */
+       int i;
+       char *def = dupstr("");
+       /* Default: all set to "auto" */
+       for (i = 0; ttymodes[i]; i++) {
+           char *def2 = dupprintf("%s%s=A,", def, ttymodes[i]);
+           sfree(def);
+           def = def2;
+       }
+       gppmap(sesskey, "TerminalModes", def,
+              cfg->ttymodes, lenof(cfg->ttymodes));
+       sfree(def);
+    }
 
     /* proxy settings */
     gpps(sesskey, "ProxyExcludeList", "", cfg->proxy_exclude_list,
diff --git a/ssh.c b/ssh.c
index a9ecaa3..f26eafd 100644 (file)
--- a/ssh.c
+++ b/ssh.c
@@ -166,6 +166,110 @@ static const char *const ssh2_disconnect_reasons[] = {
 #define BUG_SSH2_REKEY                           64
 #define BUG_SSH2_PK_SESSIONID                   128
 
+/*
+ * Codes for terminal modes.
+ * Most of these are the same in SSH-1 and SSH-2.
+ * This list is derived from draft-ietf-secsh-connect-25 and
+ * SSH-1 RFC-1.2.31.
+ */
+static const struct {
+    const char* const mode;
+    int opcode;
+    enum { TTY_OP_CHAR, TTY_OP_BOOL } type;
+} ssh_ttymodes[] = {
+    /* "V" prefix discarded for special characters relative to SSH specs */
+    { "INTR",        1, TTY_OP_CHAR },
+    { "QUIT",        2, TTY_OP_CHAR },
+    { "ERASE",       3, TTY_OP_CHAR },
+    { "KILL",        4, TTY_OP_CHAR },
+    { "EOF",         5, TTY_OP_CHAR },
+    { "EOL",         6, TTY_OP_CHAR },
+    { "EOL2",        7, TTY_OP_CHAR },
+    { "START",       8, TTY_OP_CHAR },
+    { "STOP",        9, TTY_OP_CHAR },
+    { "SUSP",       10, TTY_OP_CHAR },
+    { "DSUSP",      11, TTY_OP_CHAR },
+    { "REPRINT",     12, TTY_OP_CHAR },
+    { "WERASE",             13, TTY_OP_CHAR },
+    { "LNEXT",      14, TTY_OP_CHAR },
+    { "FLUSH",      15, TTY_OP_CHAR },
+    { "SWTCH",      16, TTY_OP_CHAR },
+    { "STATUS",             17, TTY_OP_CHAR },
+    { "DISCARD",     18, TTY_OP_CHAR },
+    { "IGNPAR",             30, TTY_OP_BOOL },
+    { "PARMRK",             31, TTY_OP_BOOL },
+    { "INPCK",      32, TTY_OP_BOOL },
+    { "ISTRIP",             33, TTY_OP_BOOL },
+    { "INLCR",      34, TTY_OP_BOOL },
+    { "IGNCR",      35, TTY_OP_BOOL },
+    { "ICRNL",      36, TTY_OP_BOOL },
+    { "IUCLC",      37, TTY_OP_BOOL },
+    { "IXON",       38, TTY_OP_BOOL },
+    { "IXANY",      39, TTY_OP_BOOL },
+    { "IXOFF",      40, TTY_OP_BOOL },
+    { "IMAXBEL",     41, TTY_OP_BOOL },
+    { "ISIG",       50, TTY_OP_BOOL },
+    { "ICANON",             51, TTY_OP_BOOL },
+    { "XCASE",      52, TTY_OP_BOOL },
+    { "ECHO",       53, TTY_OP_BOOL },
+    { "ECHOE",      54, TTY_OP_BOOL },
+    { "ECHOK",      55, TTY_OP_BOOL },
+    { "ECHONL",             56, TTY_OP_BOOL },
+    { "NOFLSH",             57, TTY_OP_BOOL },
+    { "TOSTOP",             58, TTY_OP_BOOL },
+    { "IEXTEN",             59, TTY_OP_BOOL },
+    { "ECHOCTL",     60, TTY_OP_BOOL },
+    { "ECHOKE",             61, TTY_OP_BOOL },
+    { "PENDIN",             62, TTY_OP_BOOL }, /* XXX is this a real mode? */
+    { "OPOST",      70, TTY_OP_BOOL },
+    { "OLCUC",      71, TTY_OP_BOOL },
+    { "ONLCR",      72, TTY_OP_BOOL },
+    { "OCRNL",      73, TTY_OP_BOOL },
+    { "ONOCR",      74, TTY_OP_BOOL },
+    { "ONLRET",             75, TTY_OP_BOOL },
+    { "CS7",        90, TTY_OP_BOOL },
+    { "CS8",        91, TTY_OP_BOOL },
+    { "PARENB",             92, TTY_OP_BOOL },
+    { "PARODD",             93, TTY_OP_BOOL }
+};
+
+/* Miscellaneous other tty-related constants. */
+#define SSH_TTY_OP_END           0
+/* The opcodes for ISPEED/OSPEED differ between SSH-1 and SSH-2. */
+#define SSH1_TTY_OP_ISPEED     192
+#define SSH1_TTY_OP_OSPEED     193
+#define SSH2_TTY_OP_ISPEED     128
+#define SSH2_TTY_OP_OSPEED     129
+
+/* Helper functions for parsing tty-related config. */
+static unsigned int ssh_tty_parse_specchar(char *s)
+{
+    unsigned int ret;
+    if (*s) {
+       char *next = NULL;
+       ret = ctrlparse(s, &next);
+       if (!next) ret = s[0];
+    } else {
+       ret = 255; /* special value meaning "don't set" */
+    }
+    return ret;
+}
+static unsigned int ssh_tty_parse_boolean(char *s)
+{
+    if (stricmp(s, "yes") == 0 ||
+       stricmp(s, "on") == 0 ||
+       stricmp(s, "true") == 0 ||
+       stricmp(s, "+") == 0)
+       return 1; /* true */
+    else if (stricmp(s, "no") == 0 ||
+            stricmp(s, "off") == 0 ||
+            stricmp(s, "false") == 0 ||
+            stricmp(s, "-") == 0)
+       return 0; /* false */
+    else
+       return (atoi(s) != 0);
+}
+
 #define translate(x) if (type == x) return #x
 #define translatec(x,ctx) if (type == x && (pkt_ctx & ctx)) return #x
 static char *ssh1_pkt_type(int type)
@@ -785,6 +889,29 @@ static void end_log_omission(Ssh ssh, struct Packet *pkt)
     pkt->logmode = PKTLOG_EMIT;
 }
 
+/* Helper function for common bits of parsing cfg.ttymodes. */
+static void parse_ttymodes(Ssh ssh, char *modes,
+                          void (*do_mode)(void *data, char *mode, char *val),
+                          void *data)
+{
+    while (*modes) {
+       char *t = strchr(modes, '\t');
+       char *m = snewn(t-modes+1, char);
+       char *val;
+       strncpy(m, modes, t-modes);
+       m[t-modes] = '\0';
+       if (*(t+1) == 'A')
+           val = get_ttymode(ssh->frontend, m);
+       else
+           val = dupstr(t+2);
+       if (val)
+           do_mode(data, m, val);
+       sfree(m);
+       sfree(val);
+       modes += strlen(modes) + 1;
+    }
+}
+
 static int ssh_channelcmp(void *av, void *bv)
 {
     struct ssh_channel *a = (struct ssh_channel *) av;
@@ -4411,6 +4538,27 @@ static void ssh1_smsg_exit_status(Ssh ssh, struct Packet *pktin)
     ssh_closing((Plug)ssh, NULL, 0, 0);
 }
 
+/* Helper function to deal with sending tty modes for REQUEST_PTY */
+static void ssh1_send_ttymode(void *data, char *mode, char *val)
+{
+    struct Packet *pktout = (struct Packet *)data;
+    int i = 0;
+    unsigned int arg = 0;
+    while (strcmp(mode, ssh_ttymodes[i].mode) != 0) i++;
+    if (i == lenof(ssh_ttymodes)) return;
+    switch (ssh_ttymodes[i].type) {
+      case TTY_OP_CHAR:
+       arg = ssh_tty_parse_specchar(val);
+       break;
+      case TTY_OP_BOOL:
+       arg = ssh_tty_parse_boolean(val);
+       break;
+    }
+    ssh2_pkt_addbyte(pktout, ssh_ttymodes[i].opcode);
+    ssh2_pkt_addbyte(pktout, arg);
+}
+
+
 static void do_ssh1_connection(Ssh ssh, unsigned char *in, int inlen,
                               struct Packet *pktin)
 {
@@ -4484,19 +4632,26 @@ static void do_ssh1_connection(Ssh ssh, unsigned char *in, int inlen,
     ssh->packet_dispatch[SSH1_MSG_PORT_OPEN] = ssh1_msg_port_open;
 
     if (!ssh->cfg.nopty) {
+       struct Packet *pkt;
        /* Unpick the terminal-speed string. */
        /* XXX perhaps we should allow no speeds to be sent. */
        ssh->ospeed = 38400; ssh->ispeed = 38400; /* last-resort defaults */
        sscanf(ssh->cfg.termspeed, "%d,%d", &ssh->ospeed, &ssh->ispeed);
        /* Send the pty request. */
-       send_packet(ssh, SSH1_CMSG_REQUEST_PTY,
-                   PKT_STR, ssh->cfg.termtype,
-                   PKT_INT, ssh->term_height,
-                   PKT_INT, ssh->term_width,
-                   PKT_INT, 0, PKT_INT, 0, /* width,height in pixels */
-                   PKT_CHAR, 192, PKT_INT, ssh->ispeed, /* TTY_OP_ISPEED */
-                   PKT_CHAR, 193, PKT_INT, ssh->ospeed, /* TTY_OP_OSPEED */
-                   PKT_CHAR, 0, PKT_END);
+       pkt = ssh1_pkt_init(SSH1_CMSG_REQUEST_PTY);
+       ssh_pkt_addstring(pkt, ssh->cfg.termtype);
+       ssh_pkt_adduint32(pkt, ssh->term_height);
+       ssh_pkt_adduint32(pkt, ssh->term_width);
+       ssh_pkt_adduint32(pkt, 0); /* width in pixels */
+       ssh_pkt_adduint32(pkt, 0); /* height in pixels */
+       parse_ttymodes(ssh, ssh->cfg.ttymodes,
+                      ssh1_send_ttymode, (void *)pkt);
+       ssh_pkt_addbyte(pkt, SSH1_TTY_OP_ISPEED);
+       ssh_pkt_adduint32(pkt, ssh->ispeed);
+       ssh_pkt_addbyte(pkt, SSH1_TTY_OP_OSPEED);
+       ssh_pkt_adduint32(pkt, ssh->ospeed);
+       ssh_pkt_addbyte(pkt, SSH_TTY_OP_END);
+       s_wrpkt(ssh, pkt);
        ssh->state = SSH_STATE_INTERMED;
        do {
            crReturnV;
@@ -6194,6 +6349,26 @@ static void ssh2_msg_channel_open(Ssh ssh, struct Packet *pktin)
     }
 }
 
+/* Helper function to deal with sending tty modes for "pty-req" */
+static void ssh2_send_ttymode(void *data, char *mode, char *val)
+{
+    struct Packet *pktout = (struct Packet *)data;
+    int i = 0;
+    unsigned int arg = 0;
+    while (strcmp(mode, ssh_ttymodes[i].mode) != 0) i++;
+    if (i == lenof(ssh_ttymodes)) return;
+    switch (ssh_ttymodes[i].type) {
+      case TTY_OP_CHAR:
+       arg = ssh_tty_parse_specchar(val);
+       break;
+      case TTY_OP_BOOL:
+       arg = ssh_tty_parse_boolean(val);
+       break;
+    }
+    ssh2_pkt_addbyte(pktout, ssh_ttymodes[i].opcode);
+    ssh2_pkt_adduint32(pktout, arg);
+}
+
 /*
  * Handle the SSH-2 userauth and connection layers.
  */
@@ -7179,9 +7354,11 @@ static void do_ssh2_authconn(Ssh ssh, unsigned char *in, int inlen,
        ssh2_pkt_adduint32(s->pktout, 0);              /* pixel width */
        ssh2_pkt_adduint32(s->pktout, 0);              /* pixel height */
        ssh2_pkt_addstring_start(s->pktout);
-       ssh2_pkt_addbyte(s->pktout, 128);              /* TTY_OP_ISPEED */
+       parse_ttymodes(ssh, ssh->cfg.ttymodes,
+                      ssh2_send_ttymode, (void *)s->pktout);
+       ssh2_pkt_addbyte(s->pktout, SSH2_TTY_OP_ISPEED);
        ssh2_pkt_adduint32(s->pktout, ssh->ispeed);
-       ssh2_pkt_addbyte(s->pktout, 129);              /* TTY_OP_OSPEED */
+       ssh2_pkt_addbyte(s->pktout, SSH2_TTY_OP_OSPEED);
        ssh2_pkt_adduint32(s->pktout, ssh->ospeed);
        ssh2_pkt_addstring_data(s->pktout, "\0", 1); /* TTY_OP_END */
        ssh2_pkt_send(ssh, s->pktout);
index dfd9a19..432ed93 100644 (file)
@@ -6265,3 +6265,17 @@ void term_set_focus(Terminal *term, int has_focus)
     term->has_focus = has_focus;
     term_schedule_cblink(term);
 }
+
+/*
+ * Provide "auto" settings for remote tty modes, suitable for an
+ * application with a terminal window.
+ */
+char *term_get_ttymode(Terminal *term, const char *mode)
+{
+    char *val = NULL;
+    if (strcmp(mode, "ERASE") == 0) {
+       val = term->cfg.bksp_is_delete ? "^?" : "^H";
+    }
+    /* FIXME: perhaps we should set ONLCR based on cfg.lfhascr as well? */
+    return dupstr(val);
+}
index 5397236..2f4943d 100644 (file)
@@ -177,6 +177,12 @@ void ldisc_update(void *frontend, int echo, int edit)
      */
 }
 
+char *get_ttymode(void *frontend, const char *mode)
+{
+    struct gui_data *inst = (struct gui_data *)frontend;
+    return term_get_ttymode(inst->term, mode);
+}
+
 int from_backend(void *frontend, int is_stderr, const char *data, int len)
 {
     struct gui_data *inst = (struct gui_data *)frontend;
index c026157..69816dc 100644 (file)
@@ -63,7 +63,8 @@ void cmdline_error(char *p, ...)
     exit(1);
 }
 
-struct termios orig_termios;
+static int local_tty = 0; /* do we have a local tty? */
+static struct termios orig_termios;
 
 static Backend *back;
 static void *backhandle;
@@ -122,6 +123,8 @@ void ldisc_update(void *frontend, int echo, int edit)
     /* Update stdin read mode to reflect changes in line discipline. */
     struct termios mode;
 
+    if (!local_tty) return;
+
     mode = orig_termios;
 
     if (echo)
@@ -135,16 +138,184 @@ void ldisc_update(void *frontend, int echo, int edit)
     } else {
        mode.c_iflag &= ~ICRNL;
        mode.c_lflag &= ~(ISIG | ICANON);
+       /* Solaris sets these to unhelpful values */
        mode.c_cc[VMIN] = 1;
        mode.c_cc[VTIME] = 0;
+       /* FIXME: perhaps what we do with IXON/IXOFF should be an
+        * argument to ldisc_update(), to allow implementation of SSH-2
+        * "xon-xoff" and Rlogin's equivalent? */
+       mode.c_iflag &= ~IXON;
+       mode.c_iflag &= ~IXOFF;
     }
 
     tcsetattr(0, TCSANOW, &mode);
 }
 
+/* Helper function to extract a special character from a termios. */
+static char *get_ttychar(struct termios *t, int index)
+{
+    cc_t c = t->c_cc[index];
+#if defined(_POSIX_VDISABLE)
+    if (c == _POSIX_VDISABLE)
+       return dupprintf("");
+#endif
+    return dupprintf("^<%d>", c);
+}
+
+char *get_ttymode(void *frontend, const char *mode)
+{
+    /*
+     * Propagate appropriate terminal modes from the local terminal,
+     * if any.
+     */
+    if (!local_tty) return NULL;
+
+#define GET_CHAR(ourname, uxname) \
+    do { \
+       if (strcmp(mode, ourname) == 0) \
+           return get_ttychar(&orig_termios, uxname); \
+    } while(0)
+#define GET_BOOL(ourname, uxname, uxmemb, transform) \
+    do { \
+       if (strcmp(mode, ourname) == 0) { \
+           int b = (orig_termios.uxmemb & uxname) != 0; \
+           transform; \
+           return dupprintf("%d", b); \
+       } \
+    } while (0)
+
+    /*
+     * Modes that want to be the same on all terminal devices involved.
+     */
+    /* All the special characters supported by SSH */
+#if defined(VINTR)
+    GET_CHAR("INTR", VINTR);
+#endif
+#if defined(VQUIT)
+    GET_CHAR("QUIT", VQUIT);
+#endif
+#if defined(VERASE)
+    GET_CHAR("ERASE", VERASE);
+#endif
+#if defined(VKILL)
+    GET_CHAR("KILL", VKILL);
+#endif
+#if defined(VEOF)
+    GET_CHAR("EOF", VEOF);
+#endif
+#if defined(VEOL)
+    GET_CHAR("EOL", VEOL);
+#endif
+#if defined(VEOL2)
+    GET_CHAR("EOL2", VEOL2);
+#endif
+#if defined(VSTART)
+    GET_CHAR("START", VSTART);
+#endif
+#if defined(VSTOP)
+    GET_CHAR("STOP", VSTOP);
+#endif
+#if defined(VSUSP)
+    GET_CHAR("SUSP", VSUSP);
+#endif
+#if defined(VDSUSP)
+    GET_CHAR("DSUSP", VDSUSP);
+#endif
+#if defined(VREPRINT)
+    GET_CHAR("REPRINT", VREPRINT);
+#endif
+#if defined(VWERASE)
+    GET_CHAR("WERASE", VWERASE);
+#endif
+#if defined(VLNEXT)
+    GET_CHAR("LNEXT", VLNEXT);
+#endif
+#if defined(VFLUSH)
+    GET_CHAR("FLUSH", VFLUSH);
+#endif
+#if defined(VSWTCH)
+    GET_CHAR("SWTCH", VSWTCH);
+#endif
+#if defined(VSTATUS)
+    GET_CHAR("STATUS", VSTATUS);
+#endif
+#if defined(VDISCARD)
+    GET_CHAR("DISCARD", VDISCARD);
+#endif
+    /* Modes that "configure" other major modes. These should probably be
+     * considered as user preferences. */
+    /* Configuration of ICANON */
+#if defined(ECHOK)
+    GET_BOOL("ECHOK", ECHOK, c_lflag, );
+#endif
+#if defined(ECHOKE)
+    GET_BOOL("ECHOKE", ECHOKE, c_lflag, );
+#endif
+#if defined(ECHOE)
+    GET_BOOL("ECHOE", ECHOE, c_lflag, );
+#endif
+#if defined(ECHONL)
+    GET_BOOL("ECHONL", ECHONL, c_lflag, );
+#endif
+#if defined(XCASE)
+    GET_BOOL("XCASE", XCASE, c_lflag, );
+#endif
+    /* Configuration of ECHO */
+#if defined(ECHOCTL)
+    GET_BOOL("ECHOCTL", ECHOCTL, c_lflag, );
+#endif
+    /* Configuration of IXON/IXOFF */
+#if defined(IXANY)
+    GET_BOOL("IXANY", IXANY, c_iflag, );
+#endif
+
+    /*
+     * Modes that want to be set in only one place, and that we have
+     * squashed locally.
+     */
+#if defined(ISIG)
+    GET_BOOL("ISIG", ISIG, c_lflag, );
+#endif
+#if defined(ICANON)
+    GET_BOOL("ICANON", ICANON, c_lflag, );
+#endif
+#if defined(ECHO)
+    GET_BOOL("ECHO", ECHO, c_lflag, );
+#endif
+#if defined(IXON)
+    GET_BOOL("IXON", IXON, c_iflag, );
+#endif
+#if defined(IXOFF)
+    GET_BOOL("IXOFF", IXOFF, c_iflag, );
+#endif
+
+    /*
+     * We do not propagate the following modes:
+     *  - Parity/serial settings, which are a local affair and don't
+     *    make sense propagated over SSH's 8-bit byte-stream.
+     *      IGNPAR PARMRK INPCK CS7 CS8 PARENB PARODD
+     *  - Things that want to be enabled in one place that we don't
+     *    squash locally.
+     *      IUCLC OLCUC
+     *  - Status bits.
+     *      PENDIN
+     *  - Things I don't know what to do with. (FIXME)
+     *      ISTRIP IMAXBEL NOFLSH TOSTOP IEXTEN OPOST 
+     *      INLCR IGNCR ICRNL ONLCR OCRNL ONOCR ONLRET
+     */
+
+#undef GET_CHAR
+#undef GET_BOOL
+
+    /* Fall through to here for unrecognised names, or ones that are
+     * unsupported on this platform */
+    return NULL;
+}
+
 void cleanup_termios(void)
 {
-    tcsetattr(0, TCSANOW, &orig_termios);
+    if (local_tty)
+       tcsetattr(0, TCSANOW, &orig_termios);
 }
 
 bufchain stdout_data, stderr_data;
@@ -590,7 +761,7 @@ int main(int argc, char **argv)
      * fails, because we know we aren't necessarily running in a
      * console.
      */
-    tcgetattr(0, &orig_termios);
+    local_tty = (tcgetattr(0, &orig_termios) == 0);
     atexit(cleanup_termios);
     ldisc_update(NULL, 1, 1);
     sending = FALSE;
index f5fc12e..60289eb 100644 (file)
@@ -65,6 +65,8 @@ Filename platform_default_filename(const char *name)
     return ret;
 }
 
+char *get_ttymode(void *frontend, const char *mode) { return NULL; }
+
 /*
  * Stubs for the GUI feedback mechanism in Windows PSCP.
  */
index b5ac961..68920d3 100644 (file)
@@ -191,6 +191,11 @@ void ldisc_update(void *frontend, int echo, int edit)
 {
 }
 
+char *get_ttymode(void *frontend, const char *mode)
+{
+    return term_get_ttymode(term, mode);
+}
+
 static void start_backend(void)
 {
     const char *error;
index 92ad7be..2aa5a14 100644 (file)
@@ -87,6 +87,7 @@
 #define WINHELP_CTX_telnet_newline "telnet.newline"
 #define WINHELP_CTX_rlogin_localuser "rlogin.localuser"
 #define WINHELP_CTX_ssh_nopty "ssh.nopty"
+#define WINHELP_CTX_ssh_ttymodes "ssh.ttymodes"
 #define WINHELP_CTX_ssh_noshell "ssh.noshell"
 #define WINHELP_CTX_ssh_ciphers "ssh.ciphers"
 #define WINHELP_CTX_ssh_protocol "ssh.protocol"
index 66af541..fdf0190 100644 (file)
@@ -94,6 +94,8 @@ void ldisc_update(void *frontend, int echo, int edit)
     SetConsoleMode(inhandle, mode);
 }
 
+char *get_ttymode(void *frontend, const char *mode) { return NULL; }
+
 struct input_data {
     DWORD len;
     char buffer[4096];
index ff471dd..6eecb31 100644 (file)
@@ -125,6 +125,8 @@ void gui_enable(char *arg)
     gui_hwnd = (HWND) atoi(arg);
 }
 
+char *get_ttymode(void *frontend, const char *mode) { return NULL; }
+
 /* ----------------------------------------------------------------------
  * File access abstraction.
  */