From owner-freebsd-bugs Sun Dec 1 12:10:07 1996 Return-Path: owner-bugs Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id MAA28433 for bugs-outgoing; Sun, 1 Dec 1996 12:10:07 -0800 (PST) Received: (from gnats@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id MAA28427; Sun, 1 Dec 1996 12:10:04 -0800 (PST) Resent-Date: Sun, 1 Dec 1996 12:10:04 -0800 (PST) Resent-Message-Id: <199612012010.MAA28427@freefall.freebsd.org> Resent-From: gnats (GNATS Management) Resent-To: freebsd-bugs Resent-Reply-To: FreeBSD-gnats@freefall.FreeBSD.org, adrian@virginia.edu Received: from briton.neuro.virginia.edu (briton.neuro.Virginia.EDU [128.143.244.32]) by freefall.freebsd.org (8.7.5/8.7.3) with ESMTP id MAA28235 for ; Sun, 1 Dec 1996 12:07:03 -0800 (PST) Received: (from adrian@localhost) by briton.neuro.virginia.edu (8.8.2/8.8.2) id PAA01540; Sun, 1 Dec 1996 15:02:49 -0500 (EST) Message-Id: <199612012002.PAA01540@briton.neuro.virginia.edu> Date: Sun, 1 Dec 1996 15:02:49 -0500 (EST) From: adrian@virginia.edu Reply-To: adrian@virginia.edu To: FreeBSD-gnats-submit@freebsd.org X-Send-Pr-Version: 3.2 Subject: bin/2131: New option for watch(8) [patch included] Sender: owner-bugs@freebsd.org X-Loop: FreeBSD.org Precedence: bulk >Number: 2131 >Category: bin >Synopsis: New option for watch(8) >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Class: change-request >Submitter-Id: current-users >Arrival-Date: Sun Dec 1 12:10:01 PST 1996 >Last-Modified: >Originator: Adrian Filipi-Martin >Organization: UVA >Release: FreeBSD 2.2-ALPHA i386 >Environment: N/A >Description: 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. This change makes is acceptible to use watch(8) from within a suid binary by making it impossible to chage the watched tty. >How-To-Repeat: N/A >Fix: Apply the following patch: *** watch.8.orig Sun Dec 1 13:29:08 1996 --- watch.8 Sun Dec 1 14:46:33 1996 *************** *** 11,17 **** .Nm watch .Op Fl ciotW .Ar tty ! .\" watch [-ciotW] [] .Sh DESCRIPTION .Nm Watch allows the superuser to examine all data coming through a specified tty. --- 11,17 ---- .Nm watch .Op Fl ciotW .Ar tty ! .\" watch [-ciotnW] [] .Sh DESCRIPTION .Nm Watch allows the superuser to examine all data coming through a specified tty. *************** *** 45,50 **** --- 45,56 ---- .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 *** watch.c.orig Sun Dec 1 14:25:15 1996 --- watch.c Sun Dec 1 14:32:18 1996 *************** *** 48,53 **** --- 48,54 ---- 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,164 **** void show_usage() { ! printf("watch -[ciotW] [tty name]\n"); exit(1); } --- 159,165 ---- void show_usage() { ! printf("watch -[ciotnW] [tty name]\n"); exit(1); } *************** *** 274,289 **** (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) switch (ch) { case 'W': opt_write = 1; --- 275,287 ---- (void) setlocale(LC_TIME, ""); if (isatty(std_out)) opt_interactive = 1; else opt_interactive = 0; ! while ((ch = getopt(ac, av, "Wciotn")) != EOF) switch (ch) { case 'W': opt_write = 1; *************** *** 300,305 **** --- 298,306 ---- case 't': opt_timestamp = 1; break; + case 'n': + opt_no_switch = 1; + break; case '?': default: show_usage(); *************** *** 312,318 **** snp_io = open_snp(); if (*(av += optind) == NULL) { ! if (opt_interactive) ask_dev(dev_name, MSG_INIT); else fatal("No device name given."); --- 313,319 ---- snp_io = open_snp(); if (*(av += optind) == NULL) { ! if (opt_interactive && !opt_no_switch) ask_dev(dev_name, MSG_INIT); else fatal("No device name given."); *************** *** 345,350 **** --- 346,353 ---- clear(); break; case CHR_SWITCH: + if (opt_no_switch) + break; detach_snp(); ask_dev(dev_name, MSG_CHANGE); set_dev(dev_name); *************** *** 353,358 **** --- 356,363 ---- 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,376 **** case SNP_OFLOW: if (opt_reconn_oflow) attach_snp(); ! else if (opt_interactive) { ask_dev(dev_name, MSG_OFLOW); set_dev(dev_name); } else --- 375,381 ---- case SNP_OFLOW: if (opt_reconn_oflow) attach_snp(); ! else if (opt_interactive && !opt_no_switch) { ask_dev(dev_name, MSG_OFLOW); set_dev(dev_name); } else *************** *** 379,385 **** case SNP_TTYCLOSE: if (opt_reconn_close) attach_snp(); ! else if (opt_interactive) { ask_dev(dev_name, MSG_CLOSED); set_dev(dev_name); } else --- 384,390 ---- case SNP_TTYCLOSE: if (opt_reconn_close) attach_snp(); ! else if (opt_interactive && !opt_no_switch) { ask_dev(dev_name, MSG_CLOSED); set_dev(dev_name); } else >Audit-Trail: >Unformatted: