From dwmalone@hamilton.maths.tcd.ie  Tue Mar 24 13:06:05 1998
Received: from salmon.maths.tcd.ie (mmdf@salmon.maths.tcd.ie [134.226.81.11])
          by hub.freebsd.org (8.8.8/8.8.8) with SMTP id NAA00713
          for <FreeBSD-gnats-submit@freebsd.org>; Tue, 24 Mar 1998 13:06:03 -0800 (PST)
          (envelope-from dwmalone@hamilton.maths.tcd.ie)
Received: from hamilton.maths.tcd.ie by salmon.maths.tcd.ie with SMTP
          id <aa07429@salmon.maths.tcd.ie>; 24 Mar 98 21:05:59 +0000 (GMT)
Received: (from dwmalone@localhost)
	by hamilton.maths.tcd.ie (8.8.8/8.8.5) id VAA07810;
	Tue, 24 Mar 1998 21:05:57 GMT
Message-Id: <199803242105.VAA07810@hamilton.maths.tcd.ie>
Date: Tue, 24 Mar 1998 21:05:57 GMT
From: David Malone <dwmalone@hamilton.maths.tcd.ie>
Reply-To: dwmalone@hamilton.maths.tcd.ie
To: FreeBSD-gnats-submit@freebsd.org
Subject: Getting md5 to reset access times.
X-Send-Pr-Version: 3.2

>Number:         6124
>Category:       bin
>Synopsis:       No problem - addition to make md5 to reset access times.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Tue Mar 24 13:10:01 PST 1998
>Closed-Date:    Sun Apr 19 00:00:53 PDT 1998
>Last-Modified:  Sun Apr 19 00:01:22 PDT 1998
>Originator:     David Malone
>Release:        FreeBSD 3.0-CURRENT i386
>Organization:
School of Mathematics, Trinity College Dublin.
>Environment:

	2.2-STABLE (as of 2.2.6-RELEASE) and 3.0-CURRENT (98.03.02).

>Description:

	If you are using md5 to checksum a load of files you probably
	don't want all the access times changed. This is a small patch
	which adds a "-r" flag which resets the access times to what
	they were before the file was checksumed.

	It doesn't take into account the possibility that the file is
	accessed while being checksumed.

	The diff's included seem to work OK on both stable and current.

>How-To-Repeat:

	

>Fix:
	
*** /usr/src/sbin/md5/md5.c	Mon Dec 29 14:05:49 1997
--- md5.c	Tue Mar 24 20:51:14 1998
***************
*** 22,27 ****
--- 22,28 ----
   */
  
  #include <sys/types.h>
+ #include <sys/stat.h>
  #include <md5.h>
  
  #include <stdio.h>
***************
*** 60,72 ****
  	int     ch;
  	char   *p;
  	char	buf[33];
  
  	if (argc > 1) {
! 		while ((ch = getopt(argc, argv, "ps:tx")) != -1) {
  			switch (ch) {
  			case 'p':
  				MDFilter(1);
  				break;
  			case 's':
  				MDString(optarg);
  				break;
--- 61,80 ----
  	int     ch;
  	char   *p;
  	char	buf[33];
+ 	int	reset_times = 0;
+ 	int	times_ok;
+ 	struct stat sb;
+ 	struct timeval tv[2];
  
  	if (argc > 1) {
! 		while ((ch = getopt(argc, argv, "prs:tx")) != -1) {
  			switch (ch) {
  			case 'p':
  				MDFilter(1);
  				break;
+ 			case 'r':
+ 				reset_times = 1;
+ 				break;
  			case 's':
  				MDString(optarg);
  				break;
***************
*** 81,91 ****
--- 89,106 ----
  			}
  		}
  		while (optind < argc) {
+ 			times_ok = reset_times && stat(argv[optind],&sb) == 0;
  			p = MD5File(argv[optind], buf);
  			if (!p)
  				perror(argv[optind]);
  			else
  				printf("MD5 (%s) = %s\n", argv[optind], p);
+ 			if( times_ok ) {
+ 				TIMESPEC_TO_TIMEVAL(&tv[0], &sb.st_atimespec);
+ 				TIMESPEC_TO_TIMEVAL(&tv[1], &sb.st_mtimespec);
+ 
+ 				utimes(argv[optind],tv);
+ 			}
  			optind++;
  		}
  	} else
***************
*** 194,199 ****
  usage()
  {
  
! 	fprintf(stderr, "usage: md5 [-ptx] [-s string] [files ...]\n");
  	exit(1);
  }
--- 209,214 ----
  usage()
  {
  
! 	fprintf(stderr, "usage: md5 [-rptx] [-s string] [files ...]\n");
  	exit(1);
  }
*** /usr/src/sbin/md5/md5.1	Mon Dec 29 03:40:37 1997
--- md5.1	Tue Mar 24 20:50:58 1998
***************
*** 6,12 ****
  .Nd calculate a message-digest fingerprint (checksum) for a file
  .Sh SYNOPSIS
  .Nm
! .Op Fl ptx
  .Op Fl s Ar string
  .Op Ar file ...
  .Sh DESCRIPTION
--- 6,12 ----
  .Nd calculate a message-digest fingerprint (checksum) for a file
  .Sh SYNOPSIS
  .Nm
! .Op Fl prtx
  .Op Fl s Ar string
  .Op Ar file ...
  .Sh DESCRIPTION
***************
*** 37,42 ****
--- 37,44 ----
  .Ar string .
  .It Fl p
  echos stdin to stdout and appends the MD5 sum to stdout.
+ .It Fl r
+ resets the access time on files after reading.
  .It Fl t
  runs a built-in time trial.
  .It Fl x
>Release-Note:
>Audit-Trail:

From: Stephen McKay <syssgm@dtir.qld.gov.au>
To: freebsd-gnats-submit@freebsd.org
Cc: syssgm@dtir.qld.gov.au
Subject: Re: bin/6124: Getting md5 to reset access times. 
Date: Wed, 25 Mar 1998 21:31:39 +1000

 On Wednesday, 25th March 1998, David Malone wrote:
 
 > If you are using md5 to checksum a load of files you probably
 > don't want all the access times changed. This is a small patch
 > which adds a "-r" flag which resets the access times to what
 > they were before the file was checksumed.
 
 The updated manual page should point out that resetting the access time
 updates the inode change time.  For me the inode change time is much
 more interesting than the access time since dump checks ctime as well as
 mtime to determine if a file has changed, and since hackers leave more
 interesting footprints in ctime stamps than atime stamps.
 
 And that's where the story should stop, except I found interesting stuff
 when verifying my facts for this note.  FreeBSD allows a user to set an
 arbitrary access time on a file without disturbing the mtime or ctime!
 To do this, pass -1 for the mtime in utime().  That translates to
 setting tv_sec = -1 in the appropriate element for utimes().
 
 This works because VNOVAL == -1 and ufs_setattr() in ufs_vnops.c sets
 IN_ACCESS (since atime.tv_sec != VNOVAL) but not IN_CHANGE and IN_UPDATE
 (because mtime.tv_sec == VNOVAL).  Thus, ffs_update() will happily set
 the access time to the specified value and leave the other two time
 stamps alone.
 
 So, is this a bug like I think it is?  It doesn't work like this under
 Solaris or Digital Unix.  Is it a security hole?  I can't think of an
 exploit yet...
 
 Regardless, the utime and utimes manual pages need some updating, which
 I'm happy to do once the proper behaviour is defined.
 
 >+ 		if( times_ok ) {
 >+ 			TIMESPEC_TO_TIMEVAL(&tv[0], &sb.st_atimespec);
 >+ 			TIMESPEC_TO_TIMEVAL(&tv[1], &sb.st_mtimespec);
 >+ 
 >+ 			utimes(argv[optind],tv);
 >+ 		}
 
 This interesting use of TIMESPEC_TO_TIMEVAL may be of value in the future,
 but ffs_update() only uses the tv_sec portion, and throws the rest away.
 
 Stephen.

From: Poul-Henning Kamp <phk@critter.freebsd.dk>
To: dwmalone@hamilton.maths.tcd.ie
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: bin/6124: Getting md5 to reset access times. 
Date: Thu, 26 Mar 1998 10:59:11 +0100

 >	If you are using md5 to checksum a load of files you probably
 >	don't want all the access times changed. This is a small patch
 >	which adds a "-r" flag which resets the access times to what
 >	they were before the file was checksumed.
 
 I disagree with this change, it doesn't belong in the md5 program.
 
 cksum(1) and sum(1) doesn't have it either.
 
 mtree(8) and tripwire may need this kind of stuff, but not md5(1).
 
 --
 Poul-Henning Kamp             FreeBSD coreteam member
 phk@FreeBSD.ORG               "Real hackers run -current on their laptop."
 "Drink MONO-tonic, it goes down but it will NEVER come back up!"

From: David Malone <dwmalone@maths.tcd.ie>
To: Poul-Henning Kamp <phk@critter.freebsd.dk>
Cc: FreeBSD-gnats-submit@freebsd.org
Subject: Re: bin/6124: Getting md5 to reset access times. 
Date: Thu, 26 Mar 1998 11:51:33 +0000

 > >	If you are using md5 to checksum a load of files you probably
 > >	don't want all the access times changed. This is a small patch
 > >	which adds a "-r" flag which resets the access times to what
 > >	they were before the file was checksumed.
 > 
 > I disagree with this change, it doesn't belong in the md5 program.
 
 Fair enough.
 
 > cksum(1) and sum(1) doesn't have it either.
 > 
 > mtree(8) and tripwire may need this kind of stuff, but not md5(1).
 
 Would you be interested in a similar addition to mtree?
 
 	David.
State-Changed-From-To: open->closed 
State-Changed-By: phk 
State-Changed-When: Sun Apr 19 00:00:53 PDT 1998 
State-Changed-Why:  
Nobody expressed a wish for the modification to mtree either. 
>Unformatted:
