Bug 106 - permissions and ownerships of the "original" log file changed
permissions and ownerships of the "original" log file changed
Status: NEW
Product: Newsyslog
Classification: Unclassified
Component: Newsyslog
1.1
Sun Solaris 2.x
: normal normal
Assigned To: Todd C. Miller
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2003-04-16 17:47 MDT by Dirk Herre
Modified: 2003-06-26 19:44 MDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dirk Herre 2003-04-16 17:47:57 MDT
Hi, 
I use your newsyslog on Solaris 8 (SPARC and Intel) to rotate 
several log file. It is a great tool, thanks for this idea to port this. 
It seems that the possibility to chanche the archives permissions 
and ownerships is not working correct. 
I had made some tests an will explain my test environment: 
 
newsyslog.conf 
-------------- 
# logfilename    [owner:group] mode ngen size when [ZB] 
/var/log/authlog  root:users   640  7    2    *     Z 
 
existing authlog file 
--------------------- 
-rw-------   1 root     sys         1316 Apr 17 00:43 authlog 
 
First run of newsyslog 
============ 
newsyslog -n -v 
--------------- 
/var/log/authlog <7Z>: size (KB): 1.33 [1] --> trimming log.... 
        rm -f /var/log/authlog.7 /var/log/authlog.7.gz 
        mktemp /var/log/authlog.XXXXXXXXXX 
        mv /var/log/authlog to /var/log/authlog.0 
        mv /var/log/authlog.XXXXXXXXXX to /var/log/authlog 
kill -1 222 
gzip /var/log/authlog 
 
Result 
------ 
-rw-r-----   1 root     users         60 Apr 17 01:12 authlog 
-rw-------   1 root     sys          446 Apr 17 01:12 authlog.0.gz 
 
Second run 
========== 
newsyslog -n -v 
--------------- 
/var/log/authlog <7Z>: size (KB): 1.39 [1] --> trimming log.... 
        rm -f /var/log/authlog.7 /var/log/authlog.7.gz 
        mv /var/log/authlog.0.gz /var/log/authlog.1.gz 
        chmod 640 /var/log/authlog.1.gz 
        chown 0:100 /var/log/authlog.1.gz 
        mktemp /var/log/authlog.XXXXXXXXXX 
        mv /var/log/authlog to /var/log/authlog.0 
        mv /var/log/authlog.XXXXXXXXXX to /var/log/authlog 
kill -1 222 
gzip /var/log/authlog 
 
Result 
------ 
-rw-r-----   1 root     users         60 Apr 17 01:18 authlog 
-rw-r-----   1 root     users        463 Apr 17 01:18 authlog.0.gz 
-rw-r-----   1 root     users        446 Apr 17 01:12 authlog.1.gz 
 
I think the original ownership and the permissions must not change. 
 
Greetings 
    Dirk
Comment 1 Dirk Herre 2003-06-26 15:44:09 MDT
A possible solution (see diff). Work faultlessly for some weeks. 
 
==========[ diff end ]========== 
--- newsyslog.c.orig    2003-02-12 21:05:32.000000000 +0100 
+++ newsyslog.c 2003-05-18 15:32:44.000000000 +0200 
@@ -1,4 +1,4 @@ 
-/*     $OpenBSD: newsyslog.c,v 1.63 2003/02/12 19:17:36 millert Exp $  */ 
+/*     $OpenBSD: newsyslog.c,v 1.63a 2003/05/18 15:51:27 millert (uk) Exp $    */ 
 
 /* 
  * Copyright (c) 1999, 2002, 2003 Todd C. Miller <Todd.Miller@courtesan.com> 
@@ -86,7 +86,7 @@ 
  */ 
 
 #ifndef lint 
-static const char rcsid[] = "$OpenBSD: newsyslog.c,v 1.63 2003/02/12 19:17:36 millert Exp 
$"; 
+static const char rcsid[] = "$OpenBSD: newsyslog.c,v 1.63a 2003/05/18 15:51:27 millert 
(uk) Exp $"; 
 #endif /* not lint */ 
 
 #include <sys/param.h> 
@@ -111,6 +111,7 @@ 
 /* Older versions of Linux need this. */ 
 #include <linux/types.h> 
 #include <linux/quota.h> 
+#include <time.h> 
 #endif 
 
 #include "config.h" 
@@ -174,7 +175,7 @@ 
 void usage(void); 
 struct conf_entry *parse_file(int *); 
 char *missing_field(char *, char *, int); 
-void dotrim(struct conf_entry *); 
+void dotrim(struct conf_entry *, mode_t, uid_t, gid_t); 
 int log_trim(char *); 
 void compress_log(struct conf_entry *); 
 off_t sizefile(char *); 
@@ -205,7 +206,7 @@ 
        char **av; 
        int status, listlen; 
        extern int optind; 
- 
+ 
 #ifndef        HAVE_PROGNAME 
        if ((__progname = strrchr(argv[0], '/')) != NULL) 
                __progname++; 
@@ -365,7 +366,7 @@ 
                                    (ent->flags & CE_COMPACT) ? "Z" : "", 
                                    (ent->flags & CE_BINARY) ? "B" : "", 
                                    (ent->flags & CE_FOLLOW) ? "F" : ""); 
-                       dotrim(ent); 
+                       dotrim(ent, sb.st_mode, sb.st_uid, sb.st_gid); 
                        ent->flags |= CE_ROTATED; 
                } else 
                        DPRINTF(("--> skipping\n")); 
@@ -762,7 +763,7 @@ 
 } 
 
 void 
-dotrim(struct conf_entry *ent) 
+dotrim(struct conf_entry *ent, mode_t mode, uid_t uid, gid_t gid) 
 { 
        char    file1[MAXPATHLEN], file2[MAXPATHLEN]; 
        char    oldlog[MAXPATHLEN], *suffix; 
@@ -800,7 +801,7 @@ 
 
                if (noaction) { 
                        printf("\tmv %s %s\n", file1, file2); 
-                       printf("\tchmod %o %s\n", ent->permissions, file2); 
+                       printf("\tchmod %04o %s\n", ent->permissions, file2); 
                        if (ent->uid != (uid_t)-1 || ent->gid != (gid_t)-1) 
                                printf("\tchown %u:%u %s\n", 
                                    ent->uid, ent->gid, file2); 
@@ -823,10 +824,9 @@ 
        } else { 
                if ((fd = mkstemp(file2)) < 0) 
                        err(1, "can't start '%s' log", file2); 
-               if (ent->uid != (uid_t)-1 || ent->gid != (gid_t)-1) 
-                       if (fchown(fd, ent->uid, ent->gid)) 
-                               err(1, "can't chown '%s' log file", file2); 
-               if (fchmod(fd, ent->permissions)) 
+               if (fchown(fd, uid, gid)) 
+                       err(1, "can't chown '%s' log file", file2); 
+               if (fchmod(fd, mode)) 
                        err(1, "can't chmod '%s' log file", file2); 
                (void)close(fd); 
                /* Add status message */ 
@@ -841,10 +841,21 @@ 
                        warn("can't rm %s", ent->log); 
        } else { 
                (void)sprintf(file1, "%s.0", oldlog); 
-               if (noaction) 
+               if (noaction) { 
                        printf("\tmv %s to %s\n", ent->log, file1); 
-               else if (rename(ent->log, file1)) 
-                       warn("can't mv %s to %s", ent->log, file1); 
+                       printf("\tchmod %04o %s\n", ent->permissions, file1); 
+                       if (ent->uid != (uid_t)-1 || ent->gid != (gid_t)-1) 
+                               printf("\tchown %u:%u %s\n", 
+                                   ent->uid, ent->gid, file1); 
+               } else { 
+                       if (rename(ent->log, file1)) 
+                               warn("can't mv %s to %s", ent->log, file1); 
+                       if (chmod(file1, ent->permissions)) 
+                               warn("can't chmod %s", 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); 
+               } 
        } 
 
        /* Now move the new log file into place */ 
@@ -875,7 +886,7 @@ 
 { 
        pid_t pid; 
        char *base, tmp[MAXPATHLEN]; 
- 
+ 
        if (ent->backdir != NULL) 
                sprintf(tmp, "%s/%s.0", ent->backdir, ent->logbase); 
        else 
==========[ diff end ]========== 
Greetings 
   Dirk