[1510] in Athena Bugs
No subject found in mail header
daemon@ATHENA.MIT.EDU (Ilhamuddin Ahmed)
Fri Dec 9 20:59:41 1988
To: bugs@ATHENA.MIT.EDU
Cc: geer@ATHENA.MIT.EDU, probe@ATHENA.MIT.EDU, tjcoppet@ATHENA.MIT.EDU,
Reply-To: ilham@ATHENA.MIT.EDU
Date: Fri, 09 Dec 88 20:55:45 EST
From: Ilhamuddin Ahmed <ilham@ATHENA.MIT.EDU>
-> /***** paris:changes / henry / 4:25 pm Dec 1, 1988*/
-> From henry@GARP.MIT.EDU Thu Dec 1 16:25:50 1988
-> To: changes@ATHENA.MIT.EDU
-> Subject: [Tom Coppeto: newsyslog]
-> Date: Thu, 01 Dec 88 16:25:38 EST
-> From: Henry Mensch <henry@GARP.MIT.EDU>
->
-> this may be listed here already.
->
-> ------- Forwarded Message
->
-> Received: by E40-PO.MIT.EDU (5.45/4.7) id AA28064; Wed, 20 Jul 88 15:01:06 EDT
-> Received: by ATHENA.MIT.EDU (5.45/4.7) id AA12843; Wed, 20 Jul 88 14:59:42 EDT
-> Received: by M11-115-5.MIT.EDU (5.45/4.7) id AA12191; Wed, 20 Jul 88 14:59:15 EDT
-> Message-Id: <8807201859.AA12191@M11-115-5.MIT.EDU>
-> To: bugs@ATHENA.MIT.EDU
-> Subject: newsyslog
-> Date: Wed, 20 Jul 88 14:59:08 EDT
-> From: Tom Coppeto <tjcoppet@ATHENA.MIT.EDU>
->
->
-> newsyslog does not seem to preserve the ownership of files.
-> For example:
->
-> - -rw------- 1 daemon 11844 Jul 20 14:30 log
-> |
-> V
-> - -rw------- 1 root 11 Jul 20 14:35 log
-> - -rw------- 1 daemon 11844 Jul 20 14:35 log.0
->
->
-> This is inconvenient for daemon processes generating log files.
-> Perhaps another field in /etc/newsyslog.conf indicating the owner
-> of the file.
->
-> - Tom
->
-> ------- End of Forwarded Message
->
-> /* ---------- */
The context diff to fix this problem is attached. Two new fields should
be in added in /etc/athena/newsyslog.conf. These are the owner and group
of the new log. The format is as follows :
name_of_log owner group permission number size interval flags(optional)
The owner and group can be in characters (eg root wheel) or in uid & gid
(eg. 1 1). The man page for newsyslog should be updated accordingly.
One point <probe> pointed out was, do we have to keep backward
compatibility (i.e. should the program work with the old
/etc/athena/newsyslog.conf file as well as with the new format?
Personally I think it should not (not worth the effort) but I am open to
comments.
- Ilhamuddin Ahmed
Athena User Consultant
Project Athena `Watchmaker'
===============================================================================
*** /tmp/,RCSt1028937 Fri Dec 9 20:40:16 1988
--- /tmp/,RCSt2028937 Fri Dec 9 20:40:18 1988
***************
*** 7,13 ****
*/
#ifndef lint
! static char *rcsid = "$Header: newsyslog.c,v 1.1 88/12/06 08:33:42 ilham Exp $";
#endif lint
#define TRIMLOG "/etc/athena/trimlog" /* File that actually trims the log */
--- 7,13 ----
*/
#ifndef lint
! static char *rcsid = "$Header: newsyslog.c,v 1.4 88/12/09 20:38:09 ilham Exp $";
#endif lint
#define TRIMLOG "/etc/athena/trimlog" /* File that actually trims the log */
***************
*** 18,23 ****
--- 18,25 ----
#include <strings.h>
#include <ctype.h>
#include <signal.h>
+ #include <pwd.h>
+ #include <grp.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/stat.h>
***************
*** 32,37 ****
--- 34,41 ----
struct conf_entry {
char *log; /* Name of the log */
+ int uid; /* Owner of log */
+ int gid; /* Group of log */
int numlogs; /* Number of logs to keep */
int size; /* Size cutoff to trigger trimming the log */
int hours; /* Hours between log trimming */
***************
*** 117,123 ****
ent->log,ent->numlogs);
}
dotrim(ent->log, ent->numlogs, ent->flags,
! ent->permissions);
} else {
if (verbose)
printf("--> skipping\n");
--- 121,127 ----
ent->log,ent->numlogs);
}
dotrim(ent->log, ent->numlogs, ent->flags,
! ent->permissions, ent->uid, ent->gid);
} else {
if (verbose)
printf("--> skipping\n");
***************
*** 187,192 ****
--- 191,198 ----
char *errline;
struct conf_entry *first = NULL;
struct conf_entry *working;
+ struct passwd *pass;
+ struct group *grp;
if (strcmp(conf,"-"))
f = fopen(conf,"r");
***************
*** 215,220 ****
--- 221,250 ----
q = parse = missing_field(sob(++parse),errline);
*(parse = son(parse)) = '\0';
+ if ((isdigit(*q) ?
+ (pass = getpwuid(atoi(q))) :
+ (pass = getpwnam(q))) == NULL) {
+ fprintf(stderr,
+ "Error in config file; unknown user:\n");
+ fputs(errline,stderr);
+ exit(1);
+ }
+ working->uid = pass->pw_uid;
+
+ q = parse = missing_field(sob(++parse),errline);
+ *(parse = son(parse)) = '\0';
+ if ((isdigit(*q) ?
+ (grp = getgrgid(atoi(q))) :
+ (grp = getgrnam(q))) == NULL) {
+ fprintf(stderr,
+ "Error in config file; unknown group:\n");
+ fputs(errline,stderr);
+ exit(1);
+ }
+ working->gid = grp->gr_gid;
+
+ q = parse = missing_field(sob(++parse),errline);
+ *(parse = son(parse)) = '\0';
if (!sscanf(q,"%o",&working->permissions)) {
fprintf(stderr,
"Error in config file; bad permissions:\n");
***************
*** 281,291 ****
return(p);
}
! dotrim(log,numdays,flags,perm)
char *log;
int numdays;
int flags;
int perm;
{
char file1[128], file2[128];
int fd;
--- 311,323 ----
return(p);
}
! dotrim(log,numdays,flags,perm,owner_uid,group_gid)
char *log;
int numdays;
int flags;
int perm;
+ int owner_uid;
+ int group_gid;
{
char file1[128], file2[128];
int fd;
***************
*** 319,324 ****
--- 351,360 ----
fd = creat(log,perm);
if (fd < 0) {
perror("can't start new log");
+ exit(1);
+ }
+ if (fchown(fd, owner_uid, group_gid)) {
+ perror("can't chmod new log file");
exit(1);
}
(void) close(fd);