Download raw body.
cu, remote: fix host usage, add ec and rm capabilities
cu.c r1.25 / r1.26 adding -r / -E look like they simply didn't consider
the second form, perhaps because noone needed those bits from the file:
$ man -h cu
cu [-dr] [-E escape_char] [-l line] [-s speed | -speed]
cu [host]
Switching to mnemonic names in remote(5), I thought restricted mode
would be unusable, but 'cu -r -E# foo' does work, so fix the usage:
$ man -h -l ./cu.1
cu [-dr] [-E escape_char] [-l line] [-s speed | -speed]
cu [-r] [-E escape_char] [host]
Feeback? OK?
Additionally, we could add "rm" and "ec" capabilities for one single
file to control everything and thus simplify usage; I have a few
scripts, doas.conf and tmux.conf bits which would benefit from it.
Restricted mode also becomes enforcible through the file alone,
which is a plus for me.
Diff below fixes usage and adds "rm" and "ec", I tested 'cu foo' with
foo:\
:dv=usb0.2.00001.0:\
:br#115200:\
:ec=#:\
:rm:
where final pledges are "stdio tty" and <Enter># leads to [EOT].
Users can still 'cu -E@ foo' to overrule ec=#, which seems safe
and especially useful if you want to avoid duplicates inside cu
inside ssh inside ...
Thoughts? OK for that as well?
Index: share/man/man5/remote.5
===================================================================
RCS file: /cvs/src/share/man/man5/remote.5,v
diff -u -p -r1.28 remote.5
--- share/man/man5/remote.5 10 Feb 2020 13:18:20 -0000 1.28
+++ share/man/man5/remote.5 8 Nov 2026 00:31:14 -0000
@@ -88,6 +88,13 @@ If this file refers to a terminal line,
.Xr cu 1
attempts to perform an exclusive open on the device to ensure only
one user at a time has access to the port.
+.It Sy \&ec
+(str)
+Escape character to use.
+.It Sy \&rm
+(bool)
+Use restricted mode, preventing all local filesystem operations
+and command executions.
.El
.Sh FILES
.Bl -tag -width /etc/examples/remote -compact
Index: usr.bin/cu/cu.1
===================================================================
RCS file: /cvs/src/usr.bin/cu/cu.1,v
diff -u -p -r1.25 cu.1
--- usr.bin/cu/cu.1 3 Oct 2023 05:20:38 -0000 1.25
+++ usr.bin/cu/cu.1 8 Nov 2026 00:34:42 -0000
@@ -40,6 +40,8 @@
.Op Fl l Ar line
.Op Fl s Ar speed | Fl Ar speed
.Nm
+.Op Fl r
+.Op Fl E Ar escape_char
.Op Ar host
.Sh DESCRIPTION
.Nm
@@ -111,10 +113,12 @@ is given,
uses the
.Xr remote 5
database to retrieve the
+.Sy br Pq baud rate ,
.Sy dc Pq directly connected ,
-.Sy dv Pq device
+.Sy dv Pq device ,
+.Sy ec Pq escape character
and
-.Sy br Pq baud rate
+.Sy rs Pq restricted mode
capabilities for that host.
The
.Nm
Index: usr.bin/cu/cu.c
===================================================================
RCS file: /cvs/src/usr.bin/cu/cu.c,v
diff -u -p -r1.32 cu.c
--- usr.bin/cu/cu.c 24 Oct 2024 22:42:08 -0000 1.32
+++ usr.bin/cu/cu.c 8 Nov 2026 00:47:16 -0000
@@ -75,11 +75,25 @@ usage(void)
{
fprintf(stderr, "usage: %s [-dr] [-E escape_char] [-l line] "
"[-s speed | -speed]\n", __progname);
- fprintf(stderr, " %s [host]\n", __progname);
+ fprintf(stderr, " %s [-r] [-E escape_char] [host]\n", __progname);
exit(1);
}
int
+parse_escape(const char *esc)
+{
+ if (esc[0] == '^' && esc[2] == '\0' &&
+ (u_char)esc[1] >= 64 && (u_char)esc[1] < 128)
+ escape_char = (u_char)esc[1] & 31;
+ else if (strlen(esc) == 1)
+ escape_char = (u_char)esc[0];
+ else
+ return -1;
+
+ return 0;
+}
+
+int
main(int argc, char **argv)
{
const char *errstr;
@@ -120,12 +134,7 @@ main(int argc, char **argv)
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
+ if (parse_escape(optarg) == -1)
errx(1, "invalid escape character: %s", optarg);
break;
case 'l':
@@ -420,6 +429,14 @@ try_remote(const char *host, const char
cu_errx(1, "speed out of range");
line_speed = l;
}
+
+ if (escape_char == '~' && cgetstr(cp, "ec", &s) >= 0) {
+ if (parse_escape(s) == -1)
+ cu_errx(1, "invalid escape character: %s", s);
+ }
+
+ if (cgetcap(cp, "rm", ':') != NULL)
+ restricted = 1;
}
/* Expands tildes in the file name. Based on code from ssh/misc.c. */
cu, remote: fix host usage, add ec and rm capabilities