[Pkg-shadow-commits] r2707 - in upstream/trunk: . libmisc
Nicolas FRANÇOIS
nekral-guest at alioth.debian.org
Fri Apr 17 21:25:30 UTC 2009
Author: nekral-guest
Date: 2009-04-17 21:25:30 +0000 (Fri, 17 Apr 2009)
New Revision: 2707
Modified:
upstream/trunk/ChangeLog
upstream/trunk/libmisc/utmp.c
Log:
* libmisc/utmp.c: Do not trust the current utmp entry's ut_line.
Always set ut_line based on ttyname(0).
Modified: upstream/trunk/ChangeLog
===================================================================
--- upstream/trunk/ChangeLog 2009-04-17 20:40:26 UTC (rev 2706)
+++ upstream/trunk/ChangeLog 2009-04-17 21:25:30 UTC (rev 2707)
@@ -2,6 +2,8 @@
* NEWS, src/login.c: Do not trust the current utmp entry's ut_line
to set PAM_TTY.
+ * libmisc/utmp.c: Do not trust the current utmp entry's ut_line.
+ Always set ut_line based on ttyname(0).
2009-04-15 Nicolas François <nicolas.francois at centraliens.net>
Modified: upstream/trunk/libmisc/utmp.c
===================================================================
--- upstream/trunk/libmisc/utmp.c 2009-04-17 20:40:26 UTC (rev 2706)
+++ upstream/trunk/libmisc/utmp.c 2009-04-17 21:25:30 UTC (rev 2707)
@@ -113,12 +113,22 @@
&& ( (LOGIN_PROCESS == ut->ut_type)
|| (USER_PROCESS == ut->ut_type))
/* A process may have failed to close an entry
- * Check if this entry refers to this tty */
+ * Check if this entry refers to the current tty */
&& is_my_tty (ut->ut_line)) {
break;
}
}
+ /* We cannot trust the ut_line field. Prepare the new value. */
+ line = ttyname (0);
+ if (NULL == line) {
+ (void) puts (NO_TTY);
+ exit (EXIT_FAILURE);
+ }
+ if (strncmp (line, "/dev/", 5) == 0) {
+ line += 5;
+ }
+
/* If there is one, just use it, otherwise create a new one. */
if (NULL != ut) {
utent = *ut;
@@ -127,23 +137,17 @@
(void) puts (NO_UTENT);
exit (EXIT_FAILURE);
}
- line = ttyname (0);
- if (NULL == line) {
- (void) puts (NO_TTY);
- exit (EXIT_FAILURE);
- }
- if (strncmp (line, "/dev/", 5) == 0) {
- line += 5;
- }
memset ((void *) &utent, 0, sizeof utent);
utent.ut_type = LOGIN_PROCESS;
utent.ut_pid = pid;
- strncpy (utent.ut_line, line, sizeof utent.ut_line);
/* XXX - assumes /dev/tty?? or /dev/pts/?? */
- strncpy (utent.ut_id, utent.ut_line + 3, sizeof utent.ut_id);
+ strncpy (utent.ut_id, line + 3, sizeof utent.ut_id);
strcpy (utent.ut_user, "LOGIN");
utent.ut_time = time (NULL);
}
+
+ /* Sanitize / set the ut_line field */
+ strncpy (utent.ut_line, line, sizeof utent.ut_line);
}
#elif defined(LOGIN_PROCESS)
More information about the Pkg-shadow-commits
mailing list