summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>2002-04-20 12:23:04 +0000
committerdes <des@FreeBSD.org>2002-04-20 12:23:04 +0000
commit23c5e9b8161a4b8361e0c98447c7c59f82b3a018 (patch)
treefcb585adcd88f5b2de91bbcf96953afab9fd2d27 /lib
parentad8a79e6a5c75acf360e9310860387b68066c0b7 (diff)
downloadFreeBSD-src-23c5e9b8161a4b8361e0c98447c7c59f82b3a018.zip
FreeBSD-src-23c5e9b8161a4b8361e0c98447c7c59f82b3a018.tar.gz
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
Diffstat (limited to 'lib')
-rw-r--r--lib/libutil/login.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/libutil/login.c b/lib/libutil/login.c
index cbb6013..f54ce7b 100644
--- a/lib/libutil/login.c
+++ b/lib/libutil/login.c
@@ -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 <libutil.h>
#include <stdlib.h>
+#include <ttyent.h>
+#include <unistd.h>
#include <utmp.h>
-#include <libutil.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));
OpenPOWER on IntegriCloud