From wolfgang@lyxys.ka.sub.org  Sat Jul  7 03:10:45 2001
Return-Path: <wolfgang@lyxys.ka.sub.org>
Received: from subnet.sub.net (subnet.sub.net [212.227.14.21])
	by hub.freebsd.org (Postfix) with ESMTP id 31C9E37B405
	for <FreeBSD-gnats-submit@freebsd.org>; Sat,  7 Jul 2001 03:10:44 -0700 (PDT)
	(envelope-from wolfgang@lyxys.ka.sub.org)
Received: from lyxys.ka.sub.org (uucp@localhost)
	by subnet.sub.net (8.8.8/8.8.8/1.2subnet-linux) with bsmtp id MAA17051
	for FreeBSD-gnats-submit@freebsd.org; Sat, 7 Jul 2001 12:10:38 +0200
Received: from localhost (3804 bytes) by lyxys.ka.sub.org
	via sendmail with P:stdio/R:smart_host/T:inet_uusmtp
	(sender: <wolfgang>) (ident <wolfgang> using unix)
	id <m15Ip0Z-003pVhC@lyxys.ka.sub.org>
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 7 Jul 2001 12:08:15 +0200 (CEST)
	(Smail-3.2.0.111 2000-Feb-17 #1 built 2000-Aug-23)
Message-Id: <m15Ip0Z-003pVhC@lyxys.ka.sub.org>
Date: Sat, 7 Jul 2001 12:08:15 +0200 (CEST)
From: wolfgang@lyxys.ka.sub.org
Reply-To: wolfgang@lyxys.ka.sub.org
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: /usr/bin/last does not filter for uucp connects
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         28789
>Category:       bin
>Synopsis:       [patch] last(1) does not filter for uucp connects
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat Jul 07 03:20:00 PDT 2001
>Closed-Date:    
>Last-Modified:  Sat Aug 15 20:57:36 UTC 2009
>Originator:     Wolfgang Zenker
>Release:        FreeBSD 4.3-STABLE i386
>Organization:
>Environment:
System: FreeBSD vectra.lyx 4.3-STABLE FreeBSD 4.3-STABLE #8: Mon Jun 4 21:58:24 CEST 2001 wolfgang@vectra.lyx:/var/obj/usr/src/sys/VECTRA i386


	
>Description:
	/usr/bin/last has an option "-t tty" that allows to filter
	only entries related to the specified tty. However this does
	not work with pseudo tty names like "uucp" or "ftpd", because
	the tty field of the utmp-entry contains a combination of the
	pseudo tty name and the (non-displayed) process-id.
>How-To-Repeat:
	
>Fix:

	Suggested fix is to introduce a new option "-T ttytype" to
	/usr/bin/last. This option would allow to filter for entries
	with tty name fields starting with the specified string.
	
	Suggested implementation is attached as diff to last.c and last.1,
	I hope it is not garbled by send-pr.

*** last.c.org	Mon Mar 12 02:41:21 2001
--- last.c	Sat Jul  7 11:09:54 2001
***************
*** 69,74 ****
--- 69,75 ----
  #define	HOST_TYPE	-2
  #define	TTY_TYPE	-3
  #define	USER_TYPE	-4
+ #define TTYG_TYPE	-5
  	int	type;				/* type of arg */
  	struct arg	*next;			/* linked list pointer */
  } ARG;
***************
*** 99,105 ****
  usage(void)
  {
  	(void)fprintf(stderr,
! 	"usage: last [-#] [-f file] [-h hostname] [-t tty] [-s|w] [user ...]\n");
  	exit(1);
  }
  
--- 100,106 ----
  usage(void)
  {
  	(void)fprintf(stderr,
! 	"usage: last [-#] [-f file] [-h hostname] [-t tty] [-T ttytype] [-s|w] [user ...]\n");
  	exit(1);
  }
  
***************
*** 114,120 ****
  	(void) setlocale(LC_TIME, "");
  
  	maxrec = -1;
! 	while ((ch = getopt(argc, argv, "0123456789f:h:st:w")) != -1)
  		switch (ch) {
  		case '0': case '1': case '2': case '3': case '4':
  		case '5': case '6': case '7': case '8': case '9':
--- 115,121 ----
  	(void) setlocale(LC_TIME, "");
  
  	maxrec = -1;
! 	while ((ch = getopt(argc, argv, "0123456789f:h:st:wT:")) != -1)
  		switch (ch) {
  		case '0': case '1': case '2': case '3': case '4':
  		case '5': case '6': case '7': case '8': case '9':
***************
*** 148,153 ****
--- 149,157 ----
  		case 'w':
  			width = 8;
  			break;
+ 		case 'T':
+ 			addarg(TTYG_TYPE, ttyconv(optarg));
+ 			break;
  		case '?':
  		default:
  			usage();
***************
*** 349,354 ****
--- 353,362 ----
  			break;
  		case USER_TYPE:
  			if (!strncmp(step->name, bp->ut_name, UT_NAMESIZE))
+ 				return (YES);
+ 			break;
+ 		case TTYG_TYPE:
+ 			if (!strncmp(step->name, bp->ut_line, strlen(step->name)))
  				return (YES);
  			break;
  	}
*** last.1.org	Thu Dec 14 10:54:46 2000
--- last.1	Sat Jul  7 11:12:30 2001
***************
*** 45,50 ****
--- 45,51 ----
  .Op Fl h Ar host
  .Op Fl s
  .Op Fl t Ar tty
+ .Op Fl T Ar ttytype
  .Op Fl w
  .Op user ...
  .Sh DESCRIPTION
***************
*** 52,57 ****
--- 53,59 ----
  will list the sessions of specified
  .Ar users ,
  .Ar ttys ,
+ .Ar ttytypes ,
  and
  .Ar hosts ,
  in reverse time order.  Each line of output contains
***************
*** 87,92 ****
--- 89,102 ----
  is
  equivalent to
  .Dq Li "last -t tty03" .
+ .It Fl T Ar ttytype
+ Specify the
+ .Ar tty type .
+ Tty type in this context is the start of the tty name, so you can ask for
+ groups of ttys, e.g.,
+ .Dq Li "last -T cua" .
+ This is especially usefull for pseudo tty names like
+ .Dq "uucp" .
  .It Fl w
  Widen the duration field to show seconds, as well as the
  default days, hours and minutes.

>Release-Note:
>Audit-Trail:

From: Ruslan Ermilov <ru@FreeBSD.org>
To: wolfgang@lyxys.ka.sub.org
Cc: bug-followup@FreeBSD.org
Subject: Re: bin/28789: /usr/bin/last does not filter for uucp connects
Date: Mon, 9 Jul 2001 17:18:04 +0300

 On Sat, Jul 07, 2001 at 12:08:15PM +0200, wolfgang@lyxys.ka.sub.org wrote:
 > 
 > Suggested fix is to introduce a new option "-T ttytype" to
 > /usr/bin/last. This option would allow to filter for entries
 > with tty name fields starting with the specified string.
 > 
 > Suggested implementation is attached as diff to last.c and last.1,
 > I hope it is not garbled by send-pr.
 > 
 An alternate solution would be to add the concept of wildcard tty
 match, e.g., ``last -t ftp*'' (modulo the shell expansion).
 
 Index: last.c
 ===================================================================
 RCS file: /home/ncvs/src/usr.bin/last/last.c,v
 retrieving revision 1.10.6.2
 diff -u -r1.10.6.2 last.c
 --- last.c	2001/03/04 08:39:25	1.10.6.2
 +++ last.c	2001/07/09 14:11:59
 @@ -333,6 +333,7 @@
  	struct utmp *bp;
  {
  	ARG *step;
 +	char *c;
  
  	if (!arglist)
  		return (YES);
 @@ -344,7 +345,9 @@
  				return (YES);
  			break;
  		case TTY_TYPE:
 -			if (!strncmp(step->name, bp->ut_line, UT_LINESIZE))
 +			if (!strncmp(step->name, bp->ut_line,
 +			    (c = strchr(step->name, '*')) != NULL ?
 +			    c - step->name : UT_LINESIZE))
  				return (YES);
  			break;
  		case USER_TYPE:
 
 
 Cheers,
 -- 
 Ruslan Ermilov		Oracle Developer/DBA,
 ru@sunbay.com		Sunbay Software AG,
 ru@FreeBSD.org		FreeBSD committer,
 +380.652.512.251	Simferopol, Ukraine
 
 http://www.FreeBSD.org	The Power To Serve
 http://www.oracle.com	Enabling The Information Age

From: wolfgang@lyxys.ka.sub.org (Wolfgang Zenker)
To: Ruslan Ermilov <ru@FreeBSD.org>
Cc: wolfgang@lyxys.ka.sub.org, bug-followup@FreeBSD.org
Subject: Re: bin/28789: /usr/bin/last does not filter for uucp connects
Date: Mon, 9 Jul 2001 17:43:49 +0200 (CEST)

 Hello,
 
 Ruslan Ermilov wrote:
 > An alternate solution would be to add the concept of wildcard tty
 > match, e.g., ``last -t ftp*'' (modulo the shell expansion).
 > 
 > Index: last.c
 > ===================================================================
 > RCS file: /home/ncvs/src/usr.bin/last/last.c,v
 > retrieving revision 1.10.6.2
 > diff -u -r1.10.6.2 last.c
 > --- last.c	2001/03/04 08:39:25	1.10.6.2
 > +++ last.c	2001/07/09 14:11:59
 > @@ -333,6 +333,7 @@
 >  	struct utmp *bp;
 >  {
 >  	ARG *step;
 > +	char *c;
 >  
 >  	if (!arglist)
 >  		return (YES);
 > @@ -344,7 +345,9 @@
 >  				return (YES);
 >  			break;
 >  		case TTY_TYPE:
 > -			if (!strncmp(step->name, bp->ut_line, UT_LINESIZE))
 > +			if (!strncmp(step->name, bp->ut_line,
 > +			    (c = strchr(step->name, '*')) != NULL ?
 > +			    c - step->name : UT_LINESIZE))
 >  				return (YES);
 >  			break;
 >  		case USER_TYPE:
 
 this would of course work, but i don't think it would be a good idea,
 because
 a) the "wildcard" would only work right at the end of the terminal string,
 b) the user would have to quote the tty-string or shell metacharacter expansion
    might lead to unexpected results,
 c) the -t option is already supposed to have wildcard characteristics, as
    e.g. "-t p0" is supposed to match "ttyp0", so it might be a bit hard to
    see why one of the "wildcard options" requires a "*" and the other doesn't.
 
 BTW, the wildcard characteristic for "-t" doesn't work right either, it fails
 for e.g. "-t a0" to match "cuaa0". I will file a separate PR for this problem.
 
 Wolfgang
>Unformatted:
