summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CREDITS1
-rw-r--r--ChangeLog2
-rw-r--r--bsd-login.c99
-rw-r--r--login.c6
4 files changed, 90 insertions, 18 deletions
diff --git a/CREDITS b/CREDITS
index 470480842..b8f231c62 100644
--- a/CREDITS
+++ b/CREDITS
@@ -22,6 +22,7 @@ David Hesprich <darkgrue@gue-tech.org> - Configure fixes
22David Rankin <drankin@bohemians.lexington.ky.us> - libwrap, AIX, NetBSD fixes 22David Rankin <drankin@bohemians.lexington.ky.us> - libwrap, AIX, NetBSD fixes
23Gary E. Miller <gem@rellim.com> - SCO support 23Gary E. Miller <gem@rellim.com> - SCO support
24Ged Lodder <lodder@yacc.com.au> - HPUX fixes and enhancements 24Ged Lodder <lodder@yacc.com.au> - HPUX fixes and enhancements
25Gert Doering <gd@hilb1.medat.de> - bug and portability fixes
25HARUYAMA Seigo <haruyama@nt.phys.s.u-tokyo.ac.jp> - Translations & doc fixes 26HARUYAMA Seigo <haruyama@nt.phys.s.u-tokyo.ac.jp> - Translations & doc fixes
26Hideaki YOSHIFUJI <yoshfuji@ecei.tohoku.ac.jp> - IPv6 fixes 27Hideaki YOSHIFUJI <yoshfuji@ecei.tohoku.ac.jp> - IPv6 fixes
27Hiroshi Takekawa <takekawa@sr3.t.u-tokyo.ac.jp> - Configure fixes 28Hiroshi Takekawa <takekawa@sr3.t.u-tokyo.ac.jp> - Configure fixes
diff --git a/ChangeLog b/ChangeLog
index f015f5620..d48430a50 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -16,6 +16,8 @@
16 <karn@ka9q.ampr.org> 16 <karn@ka9q.ampr.org>
17 - Fixed __progname symbol collisions reported by Andre Lucas 17 - Fixed __progname symbol collisions reported by Andre Lucas
18 <andre.lucas@dial.pipex.com> 18 <andre.lucas@dial.pipex.com>
19 - Merged bsd-login ttyslot and AIX utmp patch from Gert Doering
20 <gd@hilb1.medat.de>
19 21
2020000430 2220000430
21 - Merge HP-UX fixes and TCB support from Ged Lodder <lodder@yacc.com.au> 23 - Merge HP-UX fixes and TCB support from Ged Lodder <lodder@yacc.com.au>
diff --git a/bsd-login.c b/bsd-login.c
index eccb29ee4..910f9ff9f 100644
--- a/bsd-login.c
+++ b/bsd-login.c
@@ -1,3 +1,7 @@
1/*
2 * This file has been modified from the original OpenBSD version
3 */
4
1/* $OpenBSD: login.c,v 1.5 1998/07/13 02:11:12 millert Exp $ */ 5/* $OpenBSD: login.c,v 1.5 1998/07/13 02:11:12 millert Exp $ */
2/* 6/*
3 * Copyright (c) 1988, 1993 7 * Copyright (c) 1988, 1993
@@ -35,6 +39,8 @@
35#include "config.h" 39#include "config.h"
36#ifndef HAVE_LOGIN 40#ifndef HAVE_LOGIN
37 41
42#include <errno.h>
43
38#if defined(LIBC_SCCS) && !defined(lint) 44#if defined(LIBC_SCCS) && !defined(lint)
39/* from: static char sccsid[] = "@(#)login.c 8.1 (Berkeley) 6/4/93"; */ 45/* from: static char sccsid[] = "@(#)login.c 8.1 (Berkeley) 6/4/93"; */
40static char *rcsid = "$OpenBSD: login.c,v 1.5 1998/07/13 02:11:12 millert Exp $"; 46static char *rcsid = "$OpenBSD: login.c,v 1.5 1998/07/13 02:11:12 millert Exp $";
@@ -54,6 +60,40 @@ static char *rcsid = "$OpenBSD: login.c,v 1.5 1998/07/13 02:11:12 millert Exp $"
54#include <stdio.h> 60#include <stdio.h>
55#include <string.h> 61#include <string.h>
56 62
63/*
64 * find first matching slot in utmp, or "-1" for none
65 *
66 * algorithm: for USER_PROCESS, check tty name
67 * for DEAD_PROCESS, check PID and tty name
68 *
69 */
70int find_tty_slot( utp )
71struct utmp * utp;
72{
73 int t = 0;
74 struct utmp * u;
75
76 setutent();
77
78 while((u = getutent()) != NULL) {
79 if (utp->ut_type == USER_PROCESS &&
80 (strncmp(utp->ut_line, u->ut_line, sizeof(utp->ut_line)) == 0)) {
81 endutent();
82 return(t);
83 }
84
85 if ((utp->ut_type == DEAD_PROCESS) && (utp->ut_pid == u->ut_pid) &&
86 (strncmp(utp->ut_line, u->ut_line, sizeof(utp->ut_line)) == 0 )) {
87 endutent();
88 return(t);
89 }
90 t++;
91 }
92
93 endutent();
94 return(-1);
95}
96
57#if defined(HAVE_UTMPX_H) && defined(USE_UTMPX) 97#if defined(HAVE_UTMPX_H) && defined(USE_UTMPX)
58void 98void
59login(utp,utx) 99login(utp,utx)
@@ -74,32 +114,57 @@ login(utp)
74 register int fd; 114 register int fd;
75 int tty; 115 int tty;
76 116
77 tty = ttyslot(); 117 /* can't use ttyslot here, as that will not work for logout
78 if (tty > 0 && (fd = open(_PATH_UTMP, O_RDWR|O_CREAT, 0644)) >= 0) { 118 * (record_logout() is called from the master sshd, which does
119 * not have the correct tty on stdin/out, so ttyslot will return
120 * "-1" or (worse) a wrong number
121 */
122 tty = find_tty_slot(utp);
79 123
124 fd = open(_PATH_UTMP, O_RDWR|O_CREAT, 0644);
125 if (fd == -1) {
126 log("Couldn't open %s: %s", _PATH_UTMP, strerror(errno));
127 } else {
128 /* If no tty was found... */
129 if (tty == -1) {
130 /* ... append it to utmp on login */
131 if (utp->ut_type == USER_PROCESS) {
132 if ((fd = open(_PATH_UTMP, O_WRONLY|O_APPEND, 0)) >= 0) {
133 (void)write(fd, utp, sizeof(struct utmp));
134 (void)close(fd);
135 }
136 } else {
137 /* Shouldn't get to here unless somthing happened to utmp */
138 /* Between login and logout */
139 log("No tty slot found at logout");
140 }
141 } else {
142 /* Otherwise, tty was found - update at its location */
80#if defined(HAVE_HOST_IN_UTMP) 143#if defined(HAVE_HOST_IN_UTMP)
81# ifndef UT_LINESIZE 144# ifndef UT_LINESIZE
82# define UT_LINESIZE (sizeof(old_ut.ut_line)) 145# define UT_LINESIZE (sizeof(old_ut.ut_line))
83# define UT_NAMESIZE (sizeof(old_ut.ut_name)) 146# define UT_NAMESIZE (sizeof(old_ut.ut_name))
84# define UT_HOSTSIZE (sizeof(old_ut.ut_host)) 147# define UT_HOSTSIZE (sizeof(old_ut.ut_host))
85# endif 148# endif
86 (void)lseek(fd, (off_t)(tty * sizeof(struct utmp)), SEEK_SET); 149 (void)lseek(fd, (off_t)(tty * sizeof(struct utmp)), SEEK_SET);
87 /* 150 /*
88 * Prevent luser from zero'ing out ut_host. 151 * Prevent luser from zero'ing out ut_host.
89 * If the new ut_line is empty but the old one is not 152 * If the new ut_line is empty but the old one is not
90 * and ut_line and ut_name match, preserve the old ut_line. 153 * and ut_line and ut_name match, preserve the old ut_line.
91 */ 154 */
92 if (read(fd, &old_ut, sizeof(struct utmp)) == 155 if (read(fd, &old_ut, sizeof(struct utmp)) ==
93 sizeof(struct utmp) && utp->ut_host[0] == '\0' && 156 sizeof(struct utmp) && utp->ut_host[0] == '\0' &&
94 old_ut.ut_host[0] != '\0' && 157 old_ut.ut_host[0] != '\0' &&
95 strncmp(old_ut.ut_line, utp->ut_line, UT_LINESIZE) == 0 && 158 strncmp(old_ut.ut_line, utp->ut_line, UT_LINESIZE) == 0 &&
96 strncmp(old_ut.ut_name, utp->ut_name, UT_NAMESIZE) == 0) 159 strncmp(old_ut.ut_name, utp->ut_name, UT_NAMESIZE) == 0)
97 (void)memcpy(utp->ut_host, old_ut.ut_host, UT_HOSTSIZE); 160 (void)memcpy(utp->ut_host, old_ut.ut_host, UT_HOSTSIZE);
98#endif /* defined(HAVE_HOST_IN_UTMP) */ 161#endif /* defined(HAVE_HOST_IN_UTMP) */
99 (void)lseek(fd, (off_t)(tty * sizeof(struct utmp)), SEEK_SET); 162 (void)lseek(fd, (off_t)(tty * sizeof(struct utmp)), SEEK_SET);
100 (void)write(fd, utp, sizeof(struct utmp)); 163 (void)write(fd, utp, sizeof(struct utmp));
101 (void)close(fd); 164 (void)close(fd);
165 }
102 } 166 }
167
103 if ((fd = open(_PATH_WTMP, O_WRONLY|O_APPEND, 0)) >= 0) { 168 if ((fd = open(_PATH_WTMP, O_WRONLY|O_APPEND, 0)) >= 0) {
104 (void)write(fd, utp, sizeof(struct utmp)); 169 (void)write(fd, utp, sizeof(struct utmp));
105 (void)close(fd); 170 (void)close(fd);
diff --git a/login.c b/login.c
index de2c89cba..660eb6705 100644
--- a/login.c
+++ b/login.c
@@ -18,7 +18,7 @@
18 */ 18 */
19 19
20#include "includes.h" 20#include "includes.h"
21RCSID("$Id: login.c,v 1.24 2000/04/19 21:42:22 damien Exp $"); 21RCSID("$Id: login.c,v 1.25 2000/05/01 12:53:53 damien Exp $");
22 22
23#if defined(HAVE_UTMPX_H) && defined(USE_UTMPX) 23#if defined(HAVE_UTMPX_H) && defined(USE_UTMPX)
24# include <utmpx.h> 24# include <utmpx.h>
@@ -155,7 +155,11 @@ record_login(pid_t pid, const char *ttyname, const char *user, uid_t uid,
155 memset(&u, 0, sizeof(u)); 155 memset(&u, 0, sizeof(u));
156 strncpy(u.ut_line, ttyname + 5, sizeof(u.ut_line)); 156 strncpy(u.ut_line, ttyname + 5, sizeof(u.ut_line));
157#if defined(HAVE_ID_IN_UTMP) 157#if defined(HAVE_ID_IN_UTMP)
158#ifdef _AIX
159 strncpy(u.ut_id, ttyname + 5, sizeof(u.ut_id));
160#else /* !AIX */
158 strncpy(u.ut_id, ttyname + 8, sizeof(u.ut_id)); 161 strncpy(u.ut_id, ttyname + 8, sizeof(u.ut_id));
162#endif
159#endif /* defined(HAVE_ID_IN_UTMP) */ 163#endif /* defined(HAVE_ID_IN_UTMP) */
160 strncpy(u.ut_name, user, sizeof(u.ut_name)); 164 strncpy(u.ut_name, user, sizeof(u.ut_name));
161#if defined(HAVE_TV_IN_UTMP) 165#if defined(HAVE_TV_IN_UTMP)