summaryrefslogtreecommitdiff
path: root/bsd-login.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>1999-12-25 10:11:29 +1100
committerDamien Miller <djm@mindrot.org>1999-12-25 10:11:29 +1100
commit2e1b082dfbc5dcdae80957a3d889abe9fa480d77 (patch)
treec2bfe8d4115d22146448ce829fb7b16e9b762b4f /bsd-login.c
parent1b0c228ec48d54705474701b6486f1593539a88a (diff)
- Prepare for 1.2.1pre20
19991225 - More fixes from Andre Lucas <andre.lucas@dial.pipex.com> - Cleanup of auth-passwd.c for shadow and MD5 passwords - Cleanup and bugfix of PAM authentication code 19991223 - Merged later HPUX patch from Andre Lucas <andre.lucas@dial.pipex.com> - Above patch included better utmpx support from Ben Taylor <bent@clark.net>:
Diffstat (limited to 'bsd-login.c')
-rw-r--r--bsd-login.c46
1 files changed, 28 insertions, 18 deletions
diff --git a/bsd-login.c b/bsd-login.c
index c0f4c1ab0..d81e46914 100644
--- a/bsd-login.c
+++ b/bsd-login.c
@@ -54,53 +54,63 @@ static char *rcsid = "$OpenBSD: login.c,v 1.5 1998/07/13 02:11:12 millert Exp $"
54#include <stdio.h> 54#include <stdio.h>
55#include <string.h> 55#include <string.h>
56 56
57#if defined(HAVE_UTMPX_H) && defined(USE_UTMPX)
58void
59login(utp,utx)
60 struct utmp *utp;
61 struct utmpx *utx;
62#else /* defined(HAVE_UTMPX_H) && defined(USE_UTMPX) */
57void 63void
58login(utp) 64login(utp)
59 struct UTMP_STR *utp; 65 struct utmp *utp;
66#endif /* defined(HAVE_UTMPX_H) && defined(USE_UTMPX) */
60{ 67{
61 struct UTMP_STR old_ut; 68 struct utmp old_ut;
69#if defined(HAVE_UTMPX_H) && defined(USE_UTMPX)
70 struct utmpx *old_utx;
71#endif /* defined(HAVE_UTMPX_H) && defined(USE_UTMPX) */
62 register int fd; 72 register int fd;
63 int tty; 73 int tty;
64 74
65#ifndef UT_LINESIZE 75#ifndef UT_LINESIZE
66# define UT_LINESIZE (sizeof(old_ut.ut_line)) 76# define UT_LINESIZE (sizeof(old_ut.ut_line))
67# if defined(HAVE_UTMPX_H) && defined(USE_UTMPX) 77# define UT_NAMESIZE (sizeof(old_ut.ut_name))
68# define UT_NAMESIZE (sizeof(old_ut.ut_user))
69# else
70# define UT_NAMESIZE (sizeof(old_ut.ut_name))
71# endif
72# ifdef HAVE_HOST_IN_UTMP 78# ifdef HAVE_HOST_IN_UTMP
73# define UT_HOSTSIZE (sizeof(old_ut.ut_host)) 79# define UT_HOSTSIZE (sizeof(old_ut.ut_host))
74# endif 80# endif
75# if defined(HAVE_HOST_IN_UTMPX) && defined(USE_UTMPX)
76# define UT_HOSTSIZE (sizeof(old_ut.ut_host))
77# endif
78#endif 81#endif
79 82
80 tty = ttyslot(); 83 tty = ttyslot();
81 if (tty > 0 && (fd = open(_PATH_UTMP, O_RDWR|O_CREAT, 0644)) >= 0) { 84 if (tty > 0 && (fd = open(_PATH_UTMP, O_RDWR|O_CREAT, 0644)) >= 0) {
82#if defined(HAVE_HOST_IN_UTMP) || defined(HAVE_HOST_IN_UTMPX) 85#if defined(HAVE_HOST_IN_UTMP)
83 (void)lseek(fd, (off_t)(tty * sizeof(struct UTMP_STR)), SEEK_SET); 86 (void)lseek(fd, (off_t)(tty * sizeof(struct utmp)), SEEK_SET);
84 /* 87 /*
85 * Prevent luser from zero'ing out ut_host. 88 * Prevent luser from zero'ing out ut_host.
86 * If the new ut_line is empty but the old one is not 89 * If the new ut_line is empty but the old one is not
87 * and ut_line and ut_name match, preserve the old ut_line. 90 * and ut_line and ut_name match, preserve the old ut_line.
88 */ 91 */
89 if (read(fd, &old_ut, sizeof(struct UTMP_STR)) == 92 if (read(fd, &old_ut, sizeof(struct utmp)) ==
90 sizeof(struct UTMP_STR) && utp->ut_host[0] == '\0' && 93 sizeof(struct utmp) && utp->ut_host[0] == '\0' &&
91 old_ut.ut_host[0] != '\0' && 94 old_ut.ut_host[0] != '\0' &&
92 strncmp(old_ut.ut_line, utp->ut_line, UT_LINESIZE) == 0 && 95 strncmp(old_ut.ut_line, utp->ut_line, UT_LINESIZE) == 0 &&
93 strncmp(old_ut.ut_name, utp->ut_name, UT_NAMESIZE) == 0) 96 strncmp(old_ut.ut_name, utp->ut_name, UT_NAMESIZE) == 0)
94 (void)memcpy(utp->ut_host, old_ut.ut_host, UT_HOSTSIZE); 97 (void)memcpy(utp->ut_host, old_ut.ut_host, UT_HOSTSIZE);
95#endif /* defined(HAVE_HOST_IN_UTMP) || defined(HAVE_HOST_IN_UTMPX) */ 98#endif /* defined(HAVE_HOST_IN_UTMP) */
96 (void)lseek(fd, (off_t)(tty * sizeof(struct UTMP_STR)), SEEK_SET); 99 (void)lseek(fd, (off_t)(tty * sizeof(struct utmp)), SEEK_SET);
97 (void)write(fd, utp, sizeof(struct UTMP_STR)); 100 (void)write(fd, utp, sizeof(struct utmp));
98 (void)close(fd); 101 (void)close(fd);
99 } 102 }
100 if ((fd = open(_PATH_WTMP, O_WRONLY|O_APPEND, 0)) >= 0) { 103 if ((fd = open(_PATH_WTMP, O_WRONLY|O_APPEND, 0)) >= 0) {
101 (void)write(fd, utp, sizeof(struct UTMP_STR)); 104 (void)write(fd, utp, sizeof(struct utmp));
102 (void)close(fd); 105 (void)close(fd);
103 } 106 }
107#if defined(HAVE_UTMPX_H) && defined(USE_UTMPX)
108 old_utx = pututxline(utx);
109# ifdef HAVE_UPDWTMPX
110 updwtmpx(_PATH_WTMPX, utx);
111# endif /* HAVE_UPDWTMPX */
112 endutxent();
113#endif /* defined(HAVE_UTMPX_H) && defined(USE_UTMPX) */
104} 114}
105 115
106#endif /* HAVE_LOGIN */ 116#endif /* HAVE_LOGIN */