Bug 28789

Summary: [patch] last(1) does not filter for uucp connects
Product: Base System Reporter: wolfgang
Component: binAssignee: freebsd-bugs (Nobody) <bugs>
Status: Closed Overcome By Events    
Severity: Affects Only Me    
Priority: Normal    
Version: 4.3-STABLE   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
file.diff none

Description wolfgang 2001-07-07 11:20:00 UTC
	/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.

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.
Comment 1 ru freebsd_committer freebsd_triage 2001-07-09 15:18:04 UTC
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
Comment 2 wolfgang 2001-07-09 16:43:49 UTC
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
Comment 3 wolfgang 2017-02-21 22:48:10 UTC
After 16 years of being "in progress", I think this bug report is not relevant anymore: freebsd-uucp nowadays writes an empty tty field while ftp doesn't create an utmp-entry at all. I'm closing this PR.