* NEWS, libmisc/chowntty.c, libmisc/utmp.c: is_my_tty() moved from
utmp.c to chowntty.c. checkutmp() now only uses an existing utmp entry if the pid matches and ut_line matches with the current tty. This fixes a possible DOS when entries can be forged in the utmp file. * libmisc/chowntty.c, src/login.c, lib/prototypes.h: Remove the tty argument from chown_tty. chown_tty always changes stdin and does not need this argument anymore.
This commit is contained in:
@@ -43,32 +43,14 @@
|
||||
#include "defines.h"
|
||||
#include <pwd.h>
|
||||
#include "getdef.h"
|
||||
/*
|
||||
* is_my_tty -- determine if "tty" is the same as TTY stdin is using
|
||||
*/
|
||||
static bool is_my_tty (const char *tty)
|
||||
{
|
||||
struct stat by_name, by_fd;
|
||||
|
||||
if ((stat (tty, &by_name) != 0) || (fstat (0, &by_fd) != 0)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (by_name.st_rdev != by_fd.st_rdev) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* chown_tty() sets the login tty to be owned by the new user ID
|
||||
* with TTYPERM modes
|
||||
*/
|
||||
|
||||
void chown_tty (const char *tty, const struct passwd *info)
|
||||
void chown_tty (const struct passwd *info)
|
||||
{
|
||||
char buf[200], full_tty[200];
|
||||
char *group; /* TTY group name or number */
|
||||
struct group *grent;
|
||||
gid_t gid;
|
||||
@@ -97,18 +79,6 @@ void chown_tty (const char *tty, const struct passwd *info)
|
||||
* the group as determined above.
|
||||
*/
|
||||
|
||||
if ('/' != *tty) {
|
||||
snprintf (full_tty, sizeof full_tty, "/dev/%s", tty);
|
||||
tty = full_tty;
|
||||
}
|
||||
|
||||
if (!is_my_tty (tty)) {
|
||||
SYSLOG ((LOG_WARN,
|
||||
"unable to determine TTY name, got %s\n", tty));
|
||||
closelog ();
|
||||
exit (1);
|
||||
}
|
||||
|
||||
if ( (fchown (STDIN_FILENO, info->pw_uid, gid) != 0)
|
||||
|| (fchmod (STDIN_FILENO, getdef_num ("TTYPERM", 0600)) != 0)) {
|
||||
int err = errno;
|
||||
|
Reference in New Issue
Block a user