diff options
author | Darren Tucker <dtucker@zip.com.au> | 2012-09-07 11:20:20 +1000 |
---|---|---|
committer | Darren Tucker <dtucker@zip.com.au> | 2012-09-07 11:20:20 +1000 |
commit | 92a39cfa09e38152be34437345577105c4110438 (patch) | |
tree | 380e81fd80292f6bf6059ad437ecf16fc6000ed5 /clientloop.c | |
parent | 241995382ee30b562a1f644ab9dd518bbbb8f902 (diff) |
- dtucker@cvs.openbsd.org 2012/09/06 09:50:13
[clientloop.c]
Make the escape command help (~?) context sensitive so that only commands
that will work in the current session are shown. ok markus@
(note: previous commit with this description was a mistake on my part while
pulling changes from OpenBSD)
Diffstat (limited to 'clientloop.c')
-rw-r--r-- | clientloop.c | 103 |
1 files changed, 62 insertions, 41 deletions
diff --git a/clientloop.c b/clientloop.c index 72b1d40f0..07d2c8923 100644 --- a/clientloop.c +++ b/clientloop.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: clientloop.c,v 1.243 2012/09/06 06:25:41 dtucker Exp $ */ | 1 | /* $OpenBSD: clientloop.c,v 1.244 2012/09/06 09:50:13 dtucker Exp $ */ |
2 | /* | 2 | /* |
3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> | 3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland | 4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
@@ -996,6 +996,64 @@ out: | |||
996 | xfree(fwd.connect_host); | 996 | xfree(fwd.connect_host); |
997 | } | 997 | } |
998 | 998 | ||
999 | /* reasons to suppress output of an escape command in help output */ | ||
1000 | #define SUPPRESS_NEVER 0 /* never suppress, always show */ | ||
1001 | #define SUPPRESS_PROTO1 1 /* don't show in protocol 1 sessions */ | ||
1002 | #define SUPPRESS_MUXCLIENT 2 /* don't show in mux client sessions */ | ||
1003 | #define SUPPRESS_MUXMASTER 4 /* don't show in mux master sessions */ | ||
1004 | #define SUPPRESS_SYSLOG 8 /* don't show when logging to syslog */ | ||
1005 | struct escape_help_text { | ||
1006 | const char *cmd; | ||
1007 | const char *text; | ||
1008 | unsigned int flags; | ||
1009 | }; | ||
1010 | static struct escape_help_text esc_txt[] = { | ||
1011 | {".", "terminate session", SUPPRESS_MUXMASTER}, | ||
1012 | {".", "terminate connection (and any multiplexed sessions)", | ||
1013 | SUPPRESS_MUXCLIENT}, | ||
1014 | {"B", "send a BREAK to the remote system", SUPPRESS_PROTO1}, | ||
1015 | {"C", "open a command line", SUPPRESS_MUXCLIENT}, | ||
1016 | {"R", "request rekey", SUPPRESS_PROTO1}, | ||
1017 | {"V", "decrease verbosity (LogLevel)", SUPPRESS_MUXCLIENT}, | ||
1018 | {"v", "increase verbosity (LogLevel)", SUPPRESS_MUXCLIENT}, | ||
1019 | {"^Z", "suspend ssh", SUPPRESS_MUXCLIENT}, | ||
1020 | {"#", "list forwarded connections", SUPPRESS_NEVER}, | ||
1021 | {"&", "background ssh (when waiting for connections to terminate)", | ||
1022 | SUPPRESS_MUXCLIENT}, | ||
1023 | {"?", "this message", SUPPRESS_NEVER}, | ||
1024 | }; | ||
1025 | |||
1026 | static void | ||
1027 | print_escape_help(Buffer *b, int escape_char, int protocol2, int mux_client, | ||
1028 | int using_stderr) | ||
1029 | { | ||
1030 | unsigned int i, suppress_flags; | ||
1031 | char string[1024]; | ||
1032 | |||
1033 | snprintf(string, sizeof string, "%c?\r\n" | ||
1034 | "Supported escape sequences:\r\n", escape_char); | ||
1035 | buffer_append(b, string, strlen(string)); | ||
1036 | |||
1037 | suppress_flags = (protocol2 ? 0 : SUPPRESS_PROTO1) | | ||
1038 | (mux_client ? SUPPRESS_MUXCLIENT : 0) | | ||
1039 | (mux_client ? 0 : SUPPRESS_MUXMASTER) | | ||
1040 | (using_stderr ? 0 : SUPPRESS_SYSLOG); | ||
1041 | |||
1042 | for (i = 0; i < sizeof(esc_txt)/sizeof(esc_txt[0]); i++) { | ||
1043 | if (esc_txt[i].flags & suppress_flags) | ||
1044 | continue; | ||
1045 | snprintf(string, sizeof string, " %c%-2s - %s\r\n", | ||
1046 | escape_char, esc_txt[i].cmd, esc_txt[i].text); | ||
1047 | buffer_append(b, string, strlen(string)); | ||
1048 | } | ||
1049 | |||
1050 | snprintf(string, sizeof string, | ||
1051 | " %c%c - send the escape character by typing it twice\r\n" | ||
1052 | "(Note that escapes are only recognized immediately after " | ||
1053 | "newline.)\r\n", escape_char, escape_char); | ||
1054 | buffer_append(b, string, strlen(string)); | ||
1055 | } | ||
1056 | |||
999 | /* | 1057 | /* |
1000 | * Process the characters one by one, call with c==NULL for proto1 case. | 1058 | * Process the characters one by one, call with c==NULL for proto1 case. |
1001 | */ | 1059 | */ |
@@ -1177,46 +1235,9 @@ process_escapes(Channel *c, Buffer *bin, Buffer *bout, Buffer *berr, | |||
1177 | continue; | 1235 | continue; |
1178 | 1236 | ||
1179 | case '?': | 1237 | case '?': |
1180 | if (c && c->ctl_chan != -1) { | 1238 | print_escape_help(berr, escape_char, compat20, |
1181 | snprintf(string, sizeof string, | 1239 | (c && c->ctl_chan != -1), |
1182 | "%c?\r\n\ | 1240 | log_is_on_stderr()); |
1183 | Supported escape sequences:\r\n\ | ||
1184 | %c. - terminate session\r\n\ | ||
1185 | %cB - send a BREAK to the remote system\r\n\ | ||
1186 | %cR - Request rekey (SSH protocol 2 only)\r\n\ | ||
1187 | %c# - list forwarded connections\r\n\ | ||
1188 | %c? - this message\r\n\ | ||
1189 | %c%c - send the escape character by typing it twice\r\n\ | ||
1190 | (Note that escapes are only recognized immediately after newline.)\r\n", | ||
1191 | escape_char, escape_char, | ||
1192 | escape_char, escape_char, | ||
1193 | escape_char, escape_char, | ||
1194 | escape_char, escape_char); | ||
1195 | } else { | ||
1196 | snprintf(string, sizeof string, | ||
1197 | "%c?\r\n\ | ||
1198 | Supported escape sequences:\r\n\ | ||
1199 | %c. - terminate connection (and any multiplexed sessions)\r\n\ | ||
1200 | %cB - send a BREAK to the remote system\r\n\ | ||
1201 | %cC - open a command line\r\n\ | ||
1202 | %cR - Request rekey (SSH protocol 2 only)\r\n\ | ||
1203 | %cV - Decrease verbosity (LogLevel)\r\n\ | ||
1204 | %cv - Increase verbosity (LogLevel)\r\n\ | ||
1205 | %c^Z - suspend ssh\r\n\ | ||
1206 | %c# - list forwarded connections\r\n\ | ||
1207 | %c& - background ssh (when waiting for connections to terminate)\r\n\ | ||
1208 | %c? - this message\r\n\ | ||
1209 | %c%c - send the escape character by typing it twice\r\n\ | ||
1210 | (Note that escapes are only recognized immediately after newline.)\r\n", | ||
1211 | escape_char, escape_char, | ||
1212 | escape_char, escape_char, | ||
1213 | escape_char, escape_char, | ||
1214 | escape_char, escape_char, | ||
1215 | escape_char, escape_char, | ||
1216 | escape_char, escape_char, | ||
1217 | escape_char); | ||
1218 | } | ||
1219 | buffer_append(berr, string, strlen(string)); | ||
1220 | continue; | 1241 | continue; |
1221 | 1242 | ||
1222 | case '#': | 1243 | case '#': |