Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 1 Dec 1996 15:02:49 -0500 (EST)
From:      adrian@virginia.edu
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   bin/2131: New option for watch(8) [patch included]
Message-ID:  <199612012002.PAA01540@briton.neuro.virginia.edu>
Resent-Message-ID: <199612012010.MAA28427@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>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] [<tty name>]
  .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] [<tty name>]
  .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 <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
*** 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:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199612012002.PAA01540>