diff options
author | jkh <jkh@FreeBSD.org> | 1996-12-02 12:32:46 +0000 |
---|---|---|
committer | jkh <jkh@FreeBSD.org> | 1996-12-02 12:32:46 +0000 |
commit | 19c8e3590eb69c931d661625dda16fd1bb866bb4 (patch) | |
tree | 2769f1f2499acbaaaa6160ff2885bc2931baf237 /usr.sbin/watch/watch.c | |
parent | 239b648336e79fe1eb04148a10085de8b7628161 (diff) | |
download | FreeBSD-src-19c8e3590eb69c931d661625dda16fd1bb866bb4.zip FreeBSD-src-19c8e3590eb69c931d661625dda16fd1bb866bb4.tar.gz |
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
Diffstat (limited to 'usr.sbin/watch/watch.c')
-rw-r--r-- | usr.sbin/watch/watch.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/usr.sbin/watch/watch.c b/usr.sbin/watch/watch.c index a145916..8add801 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 |