[1517] in Athena Bugs

home help back first fref pref prev next nref lref last post

No subject found in mail header

daemon@ATHENA.MIT.EDU (Ilhamuddin Ahmed)
Mon Dec 12 00:41:42 1988

To: Ken Raeburn <raeburn@ATHENA.MIT.EDU>
Cc: bugs@ATHENA.MIT.EDU, geer@ATHENA.MIT.EDU, probe@ATHENA.MIT.EDU,
In-Reply-To: Your message of Fri, 09 Dec 88 23:25:10 -0500
Reply-To: ilham@ATHENA.MIT.EDU
Date: Mon, 12 Dec 88 00:41:03 EST
From: Ilhamuddin Ahmed <ilham@ATHENA.MIT.EDU>

-> Date: Fri, 9 Dec 88 23:25:10 EST
-> From: Ken Raeburn <raeburn@ATHENA.MIT.EDU>
-> To: ilham@ATHENA.MIT.EDU
-> Cc: bugs@ATHENA.MIT.EDU, geer@ATHENA.MIT.EDU, probe@ATHENA.MIT.EDU,
->         tjcoppet@ATHENA.MIT.EDU
-> 
-> 
-> I would suggest attempting to provide some compatibility.  In fact,
-> perhaps an enhancement to the functionality described would be to make
-> the name and group ownership fields be optional, and copy the values
-> from the old file if they are not present.
-> 
-> (Then again, maybe it wouldn't be all that useful...)

Okay ... new version. It check for a format like :

logfile_name  owner.group  number  size  interval  flags
                   ^
                   |
               note 'period'

The other format is what is was before (for backward compatibility) when
in does not find a period in the second field.

As for the owner & group, if a name (in characters) is specified, it
looks up /etc/passwd and /etc/group. If a number is given, it sets it to
that uid & gid. If the username is a number (gasp!!) then we lose! If
the owner.group field is not there, the owner and group of the new log
file becomes the same as that of the old log file.

					- Ilhamuddin Ahmed
					  Project Athena `Watchmaker'

===============================================================================

*** /paris/source/4.3/etc.athena/newsyslog.c	Sun Aug 23 00:31:37 1987
--- ./newsyslog.c	Mon Dec 12 00:21:16 1988
***************
*** 2,13 ****
   * 	newsyslog - roll over selected logs at the appropriate time,
   * 		keeping the a specified number of backup files around.
   *
!  * 	$Source: /source/4.3/etc.athena/RCS/newsyslog.c,v $
!  * 	$Author: tytso $
   */
  
  #ifndef lint
! static char *rcsid = "$Header: newsyslog.c,v 1.1 87/08/23 00:31:21 tytso Exp $";
  #endif  lint
  
  #define TRIMLOG "/etc/athena/trimlog" /* File that actually trims the log */
--- 2,13 ----
   * 	newsyslog - roll over selected logs at the appropriate time,
   * 		keeping the a specified number of backup files around.
   *
!  * 	$Source: /mit/ilham/Athena/newsyslog/RCS/newsyslog.c,v $
!  * 	$Author: ilham $
   */
  
  #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>
***************
*** 29,37 ****
--- 31,42 ----
  #define CE_COMPACT 1		/* Compact the achived log files */
  #define CE_BINARY 2		/* Logfile is in binary, don't add */
  				/* status messages */
+ #define NONE -1
  	
  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");
--- 122,128 ----
  					       ent->log,ent->numlogs);
  			}
  			dotrim(ent->log, ent->numlogs, ent->flags,
! 			       ent->permissions, ent->uid, ent->gid);
  		} else {
  			if (verbose)
  				printf("--> skipping\n");
***************
*** 184,192 ****
  {
  	FILE	*f;
  	char	line[BUFSIZ], *parse, *q;
! 	char	*errline;
  	struct conf_entry *first = NULL;
  	struct conf_entry *working;
  
  	if (strcmp(conf,"-"))
  		f = fopen(conf,"r");
--- 189,199 ----
  {
  	FILE	*f;
  	char	line[BUFSIZ], *parse, *q;
! 	char	*errline, *group = NULL;
  	struct conf_entry *first = NULL;
  	struct conf_entry *working;
+ 	struct passwd *pass;
+ 	struct group *grp;
  
  	if (strcmp(conf,"-"))
  		f = fopen(conf,"r");
***************
*** 215,220 ****
--- 222,260 ----
  
  		q = parse = missing_field(sob(++parse),errline);
  		*(parse = son(parse)) = '\0';
+ 		if ((group = index(q, '.')) != NULL) {
+ 		    *group++ = '\0';
+ 		    if (!(isnumber(q))) {
+ 			if ((pass = getpwnam(q)) == NULL) {
+ 			    fprintf(stderr,
+ 				    "Error in config file; unknown user:\n");
+ 			    fputs(errline,stderr);
+ 			    exit(1);
+ 			}
+ 			working->uid = pass->pw_uid;
+ 		    }
+ 		    else
+ 			working->uid = atoi(q);
+ 		    
+ 		    q = group;
+ 		    if (!(isnumber(q))) {
+ 			if ((grp = getgrnam(q)) == NULL) {
+ 			    fprintf(stderr,
+ 				    "Error in config file; unknown group:\n");
+ 			    fputs(errline,stderr);
+ 			    exit(1);
+ 			}
+ 			working->gid = grp->gr_gid;
+ 		    }
+ 		    else
+ 			working->gid = atoi(q);
+ 		    
+ 		    q = parse = missing_field(sob(++parse),errline);
+ 		    *(parse = son(parse)) = '\0';
+ 		}
+ 		else 
+ 		    working->uid = working->gid = NONE;
+ 
  		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;
--- 321,333 ----
  	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;
***************
*** 321,326 ****
--- 363,381 ----
  			perror("can't start new log");
  			exit(1);
  		}
+ 		if (owner_uid == NONE && group_gid == NONE) {
+ 		    static struct stat oldfile_stat;
+ 		    if (stat(file1,&oldfile_stat)) {
+ 			perror("can't stat old log");
+ 			exit(1);
+ 		    }
+ 		    owner_uid = oldfile_stat.st_uid;
+ 		    group_gid = oldfile_stat.st_gid;
+ 		}
+ 		if (fchown(fd, owner_uid, group_gid)) {
+ 			perror("can't chmod new log file");
+ 			exit(1);
+ 		}
  		(void) close(fd);
  		if (!(flags & CE_BINARY))
  			if (log_trim(log)) {	/* Add status message */
***************
*** 440,442 ****
--- 495,508 ----
  }
  
  	
+ /* Check if string is actually a number */
+ 
+ isnumber(string)
+ char *string;
+ {
+ 	while (*string != '\0') {
+ 	    if (*string < '0' || *string > '9') return(0);
+ 	    string++;
+ 	}
+ 	return(1);
+ }

home help back first fref pref prev next nref lref last post