diff options
author | 2019-03-22 07:03:23 +0000 | |
---|---|---|
committer | 2019-03-22 07:03:23 +0000 | |
commit | f3767adaf341d8acf48dca87c7b34b69e5b0cc3c (patch) | |
tree | af6bab6985456bf2c5b5bb5c525ce8d8ef4bb60a | |
parent | back out 1.28 (diff) | |
download | wireguard-openbsd-f3767adaf341d8acf48dca87c7b34b69e5b0cc3c.tar.xz wireguard-openbsd-f3767adaf341d8acf48dca87c7b34b69e5b0cc3c.zip |
Add -E to change the escape character, from Artturi Alm.
no objections from deraadt, ok millert
-rw-r--r-- | usr.bin/cu/command.c | 30 | ||||
-rw-r--r-- | usr.bin/cu/cu.1 | 7 | ||||
-rw-r--r-- | usr.bin/cu/cu.c | 28 | ||||
-rw-r--r-- | usr.bin/cu/cu.h | 3 |
4 files changed, 44 insertions, 24 deletions
diff --git a/usr.bin/cu/command.c b/usr.bin/cu/command.c index c07fe73aeca..e826c659aad 100644 --- a/usr.bin/cu/command.c +++ b/usr.bin/cu/command.c @@ -1,4 +1,4 @@ -/* $OpenBSD: command.c,v 1.16 2017/12/10 01:03:46 deraadt Exp $ */ +/* $OpenBSD: command.c,v 1.17 2019/03/22 07:03:23 nicm Exp $ */ /* * Copyright (c) 2012 Nicholas Marriott <nicm@openbsd.org> @@ -30,6 +30,7 @@ #include <stdio.h> #include <string.h> #include <unistd.h> +#include <vis.h> #include "cu.h" @@ -223,6 +224,8 @@ start_record(void) void do_command(char c) { + char esc[4 + 1]; + if (restricted && strchr("CRX$>", c) != NULL) { cu_warnx("~%c command is not allowed in restricted mode", c); return; @@ -266,20 +269,23 @@ do_command(char c) sleep(1); ioctl(line_fd, TIOCCBRK, NULL); break; - case '~': - bufferevent_write(line_ev, "~", 1); + default: + if ((u_char)c == escape_char) + bufferevent_write(line_ev, &c, 1); break; case '?': + vis(esc, escape_char, VIS_WHITE | VIS_NOSLASH, 0); printf("\r\n" - "~# send break\r\n" - "~$ pipe local command to remote host\r\n" - "~> send file to remote host\r\n" - "~C connect program to remote host\r\n" - "~D de-assert DTR line briefly\r\n" - "~R start recording to file\r\n" - "~S set speed\r\n" - "~X send file with XMODEM\r\n" - "~? get this summary\r\n" + "%s# send break\r\n" + "%s$ pipe local command to remote host\r\n" + "%s> send file to remote host\r\n" + "%sC connect program to remote host\r\n" + "%sD de-assert DTR line briefly\r\n" + "%sR start recording to file\r\n" + "%sS set speed\r\n" + "%sX send file with XMODEM\r\n" + "%s? get this summary\r\n", + esc, esc, esc, esc, esc, esc, esc, esc, esc ); break; } diff --git a/usr.bin/cu/cu.1 b/usr.bin/cu/cu.1 index 104a6ea7893..5daab4bc074 100644 --- a/usr.bin/cu/cu.1 +++ b/usr.bin/cu/cu.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: cu.1,v 1.18 2018/08/05 06:11:55 jmc Exp $ +.\" $OpenBSD: cu.1,v 1.19 2019/03/22 07:03:23 nicm Exp $ .\" .\" Copyright (c) 1980, 1990, 1993 .\" The Regents of the University of California. All rights reserved. @@ -27,7 +27,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd $Mdocdate: August 5 2018 $ +.Dd $Mdocdate: March 22 2019 $ .Dt CU 1 .Os .Sh NAME @@ -36,6 +36,7 @@ .Sh SYNOPSIS .Nm .Op Fl dr +.Op Fl E Ar escape_char .Op Fl l Ar line .Op Fl s Ar speed | Fl Ar speed .Nm @@ -55,6 +56,8 @@ The options are as follows: Specify that the line is directly connected and .Nm should not allow the driver to block waiting for a carrier to be detected. +.It Fl E Ar escape_char +Specify an escape character to use instead of the default tilde. .It Fl l Ar line Specify the line to use. Either of the forms like diff --git a/usr.bin/cu/cu.c b/usr.bin/cu/cu.c index 03a2df4181f..697f72d3418 100644 --- a/usr.bin/cu/cu.c +++ b/usr.bin/cu/cu.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cu.c,v 1.26 2017/12/10 01:03:46 deraadt Exp $ */ +/* $OpenBSD: cu.c,v 1.27 2019/03/22 07:03:23 nicm Exp $ */ /* * Copyright (c) 2012 Nicholas Marriott <nicm@openbsd.org> @@ -41,6 +41,7 @@ FILE *record_file; struct termios saved_tio; struct bufferevent *input_ev; struct bufferevent *output_ev; +int escape_char = '~'; int is_direct = -1; int restricted = 0; const char *line_path = NULL; @@ -53,7 +54,7 @@ struct event sighup_ev; enum { STATE_NONE, STATE_NEWLINE, - STATE_TILDE + STATE_ESCAPE } last_state = STATE_NEWLINE; __dead void usage(void); @@ -67,8 +68,8 @@ void try_remote(const char *, const char *, const char *); __dead void usage(void) { - fprintf(stderr, "usage: %s [-dr] [-l line] [-s speed | -speed]\n", - __progname); + fprintf(stderr, "usage: %s [-dr] [-E escape_char] [-l line] " + "[-s speed | -speed]\n", __progname); fprintf(stderr, " %s [host]\n", __progname); exit(1); } @@ -94,14 +95,14 @@ main(int argc, char **argv) for (i = 1; i < argc; i++) { if (strcmp("--", argv[i]) == 0) break; - if (argv[i][0] != '-' || !isdigit((unsigned char)argv[i][1])) + if (argv[i][0] != '-' || !isdigit((u_char)argv[i][1])) continue; if (asprintf(&argv[i], "-s%s", &argv[i][1]) == -1) errx(1, "speed asprintf"); } - while ((opt = getopt(argc, argv, "drl:s:")) != -1) { + while ((opt = getopt(argc, argv, "drE:l:s:")) != -1) { switch (opt) { case 'd': is_direct = 1; @@ -111,6 +112,15 @@ main(int argc, char **argv) err(1, "pledge"); restricted = 1; break; + case 'E': + if (optarg[0] == '^' && optarg[2] == '\0' && + (u_char)optarg[1] >= 64 && (u_char)optarg[1] < 128) + escape_char = (u_char)optarg[1] & 31; + else if (strlen(optarg) == 1) + escape_char = (u_char)optarg[0]; + else + errx(1, "invalid escape character: %s", optarg); + break; case 'l': line_path = optarg; break; @@ -308,14 +318,14 @@ stream_read(struct bufferevent *bufev, void *data) last_state = STATE_NEWLINE; break; case STATE_NEWLINE: - if (state_change && *ptr == '~') { - last_state = STATE_TILDE; + if (state_change && (u_char)*ptr == escape_char) { + last_state = STATE_ESCAPE; continue; } if (*ptr != '\r') last_state = STATE_NONE; break; - case STATE_TILDE: + case STATE_ESCAPE: do_command(*ptr); last_state = STATE_NEWLINE; continue; diff --git a/usr.bin/cu/cu.h b/usr.bin/cu/cu.h index 2a7ca45d414..9e3fb776857 100644 --- a/usr.bin/cu/cu.h +++ b/usr.bin/cu/cu.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cu.h,v 1.8 2017/12/10 01:03:46 deraadt Exp $ */ +/* $OpenBSD: cu.h,v 1.9 2019/03/22 07:03:23 nicm Exp $ */ /* * Copyright (c) 2012 Nicholas Marriott <nicm@openbsd.org> @@ -23,6 +23,7 @@ void do_command(char); /* cu.c */ +extern int escape_char; extern int restricted; extern FILE *record_file; extern struct termios saved_tio; |