Fix for the sshd(8) utmp problem. Previously, login(3) would ignore the tty
named by its argument and use ttyslot(3) instead to determine what slot to use. The problem is that sshd(8) calls pam_open_session(3) before forking the child (as it should), at which point it does not have a controlling terminal. Also, ttyslot(3) is very crude as it assumes fd 0, 1 or 2 refers to the controlling terminal, which is usually (but not always) the case. Instead of using ttyslot(3) to determine the slot number, look up the specified tty in /etc/ttys ourselves (this is what ttyslot(3) does anyway). (perforce change 9969) Sponsored by: DARPA, NAI Labs
This commit is contained in:
parent
e8937ba009
commit
324e8fd88f
@ -44,19 +44,25 @@ static char sccsid[] = "@(#)login.c 8.1 (Berkeley) 6/4/93";
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <utmp.h>
|
||||
#include <libutil.h>
|
||||
#include <stdlib.h>
|
||||
#include <ttyent.h>
|
||||
#include <unistd.h>
|
||||
#include <utmp.h>
|
||||
|
||||
void
|
||||
login(ut)
|
||||
struct utmp *ut;
|
||||
{
|
||||
struct ttyent *ty;
|
||||
int fd;
|
||||
int tty;
|
||||
|
||||
tty = ttyslot();
|
||||
setttyent();
|
||||
for (tty = 1; (ty = getttyent()) != NULL; ++tty)
|
||||
if (strcmp(ty->ty_name, ut->ut_line) == 0)
|
||||
break;
|
||||
endttyent();
|
||||
if (tty > 0 && (fd = open(_PATH_UTMP, O_WRONLY|O_CREAT, 0644)) >= 0) {
|
||||
(void)lseek(fd, (off_t)(tty * sizeof(struct utmp)), L_SET);
|
||||
(void)write(fd, ut, sizeof(struct utmp));
|
||||
|
Loading…
x
Reference in New Issue
Block a user