[1150] in Kerberos-V5-bugs
krb5b4pl3: appl/bsd/logutil.c should use end of tty name when filling in ut_id
daemon@ATHENA.MIT.EDU (Jonathan I. Kamens)
Tue Mar 14 10:14:15 1995
From: "Jonathan I. Kamens" <jik@cam.ov.com>
Date: Tue, 14 Mar 1995 10:17:16 -0500
To: krb5-bugs@MIT.EDU
When appl/bsd/logutil.c fills in the ut_id field of the utmp
structure, it should use the last characters in the tty name, not the
first characters, because some platforms have very short ut_id fields,
and copying the first characters of the tty name into them will result
in a non-unique ID field. Note that the last characters of the tty
name are much more likely to be unique than the first characters.
Here's a patch:
--- logutil.c 1995/03/10 20:17:04 1.1
+++ logutil.c 1995/03/10 20:18:09 1.2
@@ -51,12 +51,25 @@
register int fd;
struct utmp utmp;
int tty;
-
+ char *p;
+
#if defined(HAVE_GETUTENT) && !defined(NO_UT_PID)
if (!ut->ut_pid)
ut->ut_pid = getppid();
ut->ut_type = USER_PROCESS;
- (void) strncpy(ut->ut_id, ut->ut_line, sizeof(ut->ut_id));
+ /*
+ Find the last <sizeof(ut->ut_id)> characters in the tty string
+ and use them as the ID, since they're the ones that are most
+ likely to be unique. This is important on systems with very
+ short ut_id fields.
+ */
+ for (p = ut->ut_line;
+ *p && (p - ut->ut_line < sizeof(ut->ut_line));
+ p++) /* empty */;
+ p -= sizeof(ut->ut_id);
+ if (p < ut->ut_line)
+ p = ut->ut_line;
+ (void) strncpy(ut->ut_id, p, sizeof(ut->ut_id));
(void) setutent();
(void) memset((char *)&utmp, 0, sizeof(utmp));