I have added a '-n' flag to the watch(8) command. This option

disables the ability to interactively select a new tty.  I have also
removed a check for uid == 0 because it gets in the way of using suid
mode based access control.  Watch (8)is only runnable by root, so this
does not really change things much.

Closes PR#2131

Submitted-By: adrian@virginia.edu
This commit is contained in:
Jordan K. Hubbard 1996-12-02 12:32:46 +00:00
parent 40b8bc74b7
commit 5009d1be3c
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=20085
2 changed files with 20 additions and 9 deletions

View File

@ -11,7 +11,7 @@
.Nm watch
.Op Fl ciotW
.Ar tty
.\" watch [-ciotW] [<tty name>]
.\" watch [-ciotnW] [<tty name>]
.Sh DESCRIPTION
.Nm Watch
allows the superuser to examine all data coming through a specified tty.
@ -45,6 +45,12 @@ For more info see
.Xr snp 4 .
.It Fl t
Print the date and time when observation of a given tty is started.
.It Fl n
Disable the ability to switch the watched tty interactively. This disables
both change requests made with <control-X> as well as automatic prompting
when the current tty is closed or overflows. In all cases where a prompt
would be displayed, watch will exit. The reconnect flags are unaffected by
this option.
.It Fl W
Allow write access to observed tty.
.It Ar tty

View File

@ -48,6 +48,7 @@ int opt_reconn_oflow = 0;
int opt_interactive = 1;
int opt_timestamp = 0;
int opt_write = 0;
int opt_no_switch = 0;
char dev_name[DEV_NAME_LEN];
int snp_io;
@ -158,7 +159,7 @@ cleanup()
void
show_usage()
{
printf("watch -[ciotW] [tty name]\n");
printf("watch -[ciotnW] [tty name]\n");
exit(1);
}
@ -274,16 +275,13 @@ main(ac, av)
(void) setlocale(LC_TIME, "");
if (getuid() != 0)
fatal(NULL);
if (isatty(std_out))
opt_interactive = 1;
else
opt_interactive = 0;
while ((ch = getopt(ac, av, "Wciot")) != EOF)
while ((ch = getopt(ac, av, "Wciotn")) != EOF)
switch (ch) {
case 'W':
opt_write = 1;
@ -300,6 +298,9 @@ main(ac, av)
case 't':
opt_timestamp = 1;
break;
case 'n':
opt_no_switch = 1;
break;
case '?':
default:
show_usage();
@ -312,7 +313,7 @@ main(ac, av)
snp_io = open_snp();
if (*(av += optind) == NULL) {
if (opt_interactive)
if (opt_interactive && !opt_no_switch)
ask_dev(dev_name, MSG_INIT);
else
fatal("No device name given.");
@ -345,6 +346,8 @@ main(ac, av)
clear();
break;
case CHR_SWITCH:
if (opt_no_switch)
break;
detach_snp();
ask_dev(dev_name, MSG_CHANGE);
set_dev(dev_name);
@ -353,6 +356,8 @@ main(ac, av)
if (opt_write) {
if (write(snp_io,chb,nread) != nread) {
detach_snp();
if (opt_no_switch)
fatal("Write failed.");
ask_dev(dev_name, MSG_NOWRITE);
set_dev(dev_name);
}
@ -370,7 +375,7 @@ main(ac, av)
case SNP_OFLOW:
if (opt_reconn_oflow)
attach_snp();
else if (opt_interactive) {
else if (opt_interactive && !opt_no_switch) {
ask_dev(dev_name, MSG_OFLOW);
set_dev(dev_name);
} else
@ -379,7 +384,7 @@ main(ac, av)
case SNP_TTYCLOSE:
if (opt_reconn_close)
attach_snp();
else if (opt_interactive) {
else if (opt_interactive && !opt_no_switch) {
ask_dev(dev_name, MSG_CLOSED);
set_dev(dev_name);
} else