bin/67137: newsyslog does not set correct user/group on the compression

James E. Housley jeh at FreeBSD.org
Tue May 25 07:20:17 PDT 2004


The following reply was made to PR bin/67137; it has been noted by GNATS.

From: "James E. Housley" <jeh at FreeBSD.org>
To: freebsd-gnats-submit at FreeBSD.org, jeh at thehousleys.net
Cc:  
Subject: Re: bin/67137: newsyslog does not set correct user/group on the compression
Date: Tue, 25 May 2004 10:09:39 -0400

 This is a multi-part message in MIME format.
 --------------080902010807000702070205
 Content-Type: text/plain; charset=us-ascii; format=flowed
 Content-Transfer-Encoding: 7bit
 
 This patch seems to do it, but I don't like the sleep(10) that I had to 
 add because even though compress_log and bzcompress_log specify wait, 
 they seem to return before compression is done.
 
 How to duplicate the problem (somewhat made up but reflects reality).
 
 modify /etc/newsyslog.conf
 
 /var/log/console.log    root:www       640  5     100  *     Z
 
 % newsyslog -n -v -F -R testing /var/log/console.log
 housley at prcd5001:~ {6} sudo newsyslog -n -v -F -R testing 
 /var/log/console.log
 /var/log/console.log <5Z>: size (Kb): 2 [100] --> trimming log....
          rm -f /var/log/console.log.5
          rm -f /var/log/console.log.5.gz
          rm -f /var/log/console.log.5.bz2
          mv /var/log/console.log.4.gz /var/log/console.log.5.gz
          chmod 640 /var/log/console.log.5.gz
          chown 0:80 /var/log/console.log.5.gz
          mv /var/log/console.log.3.gz /var/log/console.log.4.gz
          chmod 640 /var/log/console.log.4.gz
          chown 0:80 /var/log/console.log.4.gz
          mv /var/log/console.log.2.gz /var/log/console.log.3.gz
          chmod 640 /var/log/console.log.3.gz
          chown 0:80 /var/log/console.log.3.gz
          mv /var/log/console.log.1.gz /var/log/console.log.2.gz
          chmod 640 /var/log/console.log.2.gz
          chown 0:80 /var/log/console.log.2.gz
          mv /var/log/console.log.0.gz /var/log/console.log.1.gz
          chmod 640 /var/log/console.log.1.gz
          chown 0:80 /var/log/console.log.1.gz
          mv /var/log/console.log to /var/log/console.log.0
 Start new log...
          mktemp /var/log/console.log.XXXXXX
          chmod 640 /var/log/console.log.XXXXXX
          mv /var/log/console.log.XXXXXX /var/log/console.log
          kill -1 123
          gzip /var/log/console.log.0
 
 What this produces is /var/log/console.log.0.gz to still be owned by 
 root:wheel
 
 The attached patch changes it to work as:
 
 /var/log/console.log <5Z>: size (Kb): 2 [100] --> trimming log....
          rm -f /var/log/console.log.5
          rm -f /var/log/console.log.5.gz
          rm -f /var/log/console.log.5.bz2
          mv /var/log/console.log.4.gz /var/log/console.log.5.gz
          chmod 640 /var/log/console.log.5.gz
          chown 0:80 /var/log/console.log.5.gz
          mv /var/log/console.log.3.gz /var/log/console.log.4.gz
          chmod 640 /var/log/console.log.4.gz
          chown 0:80 /var/log/console.log.4.gz
          mv /var/log/console.log.2.gz /var/log/console.log.3.gz
          chmod 640 /var/log/console.log.3.gz
          chown 0:80 /var/log/console.log.3.gz
          mv /var/log/console.log.1.gz /var/log/console.log.2.gz
          chmod 640 /var/log/console.log.2.gz
          chown 0:80 /var/log/console.log.2.gz
          mv /var/log/console.log.0.gz /var/log/console.log.1.gz
          chmod 640 /var/log/console.log.1.gz
          chown 0:80 /var/log/console.log.1.gz
          mv /var/log/console.log to /var/log/console.log.0
          chown 0:80 /var/log/console.log.0
 Start new log...
          mktemp /var/log/console.log.XXXXXX
          chmod 640 /var/log/console.log.XXXXXX
          mv /var/log/console.log.XXXXXX /var/log/console.log
          kill -1 123
          gzip /var/log/console.log.0
 
 I believe this will apply cleanly to -CURRENT also.
 
 Jim
 
 -- 
 /"\   ASCII Ribbon Campaign  .
 \ / - NO HTML/RTF in e-mail  .
   X  - NO Word docs in e-mail .
 / \ -----------------------------------------------------------------
 jeh at FreeBSD.org      http://www.FreeBSD.org     The Power to Serve
 jim at TheHousleys.Net  http://www.TheHousleys.net
 ---------------------------------------------------------------------
 Progress (n) : What led from smart users in front of dumb terminals to
 dumb users in front of smart terminals.
 
 --------------080902010807000702070205
 Content-Type: text/plain;
  name="newsyslog.c-patch"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: inline;
  filename="newsyslog.c-patch"
 
 --- newsyslog.c-orig	Tue Nov  4 11:11:17 2003
 +++ newsyslog.c	Tue May 25 10:05:24 2004
 @@ -1288,14 +1288,21 @@
  		else
  			(void) unlink(log);
  	} else {
 -		if (noaction)
 +		if (noaction) {
  			printf("\tmv %s to %s\n", log, file1);
 -		else {
 +			if (ent->uid != (uid_t)-1 || ent->gid != (gid_t)-1)
 +				printf("\tchown %u:%u %s\n",
 +				    ent->uid, ent->gid, file1);
 +		} else {
  			if (archtodir)
  				movefile(log, file1, ent->permissions, ent->uid,
  				    ent->gid);
 -			else
 +			else {
  				(void) rename(log, file1);
 +				if (ent->uid != (uid_t)-1 || ent->gid != (gid_t)-1)
 +					if (chown(file1, ent->uid, ent->gid))
 +						warn("can't chown %s", file1);
 +			}
  		}
  	}
  
 
 --------------080902010807000702070205--


More information about the freebsd-bugs mailing list