From 5009d1be3cbbf60136f516d130387878c7ed7540 Mon Sep 17 00:00:00 2001 From: "Jordan K. Hubbard" Date: Mon, 2 Dec 1996 12:32:46 +0000 Subject: [PATCH] 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 --- usr.sbin/watch/watch.8 | 8 +++++++- usr.sbin/watch/watch.c | 21 +++++++++++++-------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/usr.sbin/watch/watch.8 b/usr.sbin/watch/watch.8 index 50bd5b87414d..f2f9ed8e26ee 100644 --- a/usr.sbin/watch/watch.8 +++ b/usr.sbin/watch/watch.8 @@ -11,7 +11,7 @@ .Nm watch .Op Fl ciotW .Ar tty -.\" watch [-ciotW] [] +.\" watch [-ciotnW] [] .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 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 diff --git a/usr.sbin/watch/watch.c b/usr.sbin/watch/watch.c index a1459164bca9..8add801f5796 100644 --- a/usr.sbin/watch/watch.c +++ b/usr.sbin/watch/watch.c @@ -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