[379] in SIPB_Linux_Development

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

/etc/athena/login.krb utmp problem fixed

daemon@ATHENA.MIT.EDU (svalente@MIT.EDU)
Thu Feb 3 07:00:20 1994

From: svalente@MIT.EDU
Date: Thu, 3 Feb 94 07:00:07 -0500
To: linux-dev@MIT.EDU
Cc: eichin@MIT.EDU


Well, it appears that the bug was that /etc/athena/login.krb was
always overwriting the same utmp entry.  That is, if 6 people logged
into virtual consoles and 20 people rlogin'd, utmp would only show
whoever was the most recent person to log in as being logged in.

If anyone cares, here's the patch that seems to fix the problem.  This
could probably be done better.

-Sal.

*** logutil.c.orig	Thu Feb  3 05:50:35 1994
--- kerberos/appl/bsd/logutil.c	Thu Feb  3 06:45:27 1994
***************
*** 64,70 ****
--- 64,97 ----
  	register int fd;
  	struct utmp utmp;
  	int tty;
+ 	FILE *fp;
  
+ #ifdef linux
+ 	/*
+ 	 *  the existing code was always overwriting the same utmp entry.
+ 	 *  it's probably possible to get it to work using sysv
+ 	 *  utmp functions, but I don't know enough about how them.
+ 	 *  so i wrote this instead.  --svalente
+ 	 */
+ 	/*
+ 	 *  getty_ps execs login from the process that initialized
+ 	 *  the utmp entry.  therefore, we look for the current
+ 	 *  pid, not the ppid.
+ 	 */
+ 	ut->ut_pid = getpid ();
+ 	ut->ut_type = USER_PROCESS;
+ 
+ 	if ((fp = fopen (UTMPFILE, "r+")) != NULL) {
+ 	  while (fread ((char *) &utmp, sizeof (utmp), 1, fp) == 1)
+ 	    if (utmp.ut_pid == ut->ut_pid) {
+ 	      strncpy (ut->ut_id, utmp.ut_id, sizeof (utmp.ut_id));
+ 	      fseek (fp, (long)-sizeof (utmp), SEEK_CUR);
+ 	      break;
+ 	    }
+ 	  fwrite ((char *) ut, sizeof (utmp), 1, fp);
+ 	  fclose (fp);
+ 	}
+ #else /* ! linux */
  #ifdef HAVE_GETUTENT
  	if (!ut->ut_pid)
  		ut->ut_pid = getppid();
***************
*** 87,92 ****
--- 114,121 ----
  		(void)close(fd);
  	}
  #endif
+ #endif /* linux */
+ 
  	if ((fd = open(WTMPFILE, O_WRONLY|O_APPEND, 0)) >= 0) {
  		(void)write(fd, (char *)ut, sizeof(struct utmp));
  		(void)close(fd);


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