summaryrefslogtreecommitdiff
path: root/bsd-login.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>1999-12-09 10:16:54 +1100
committerDamien Miller <djm@mindrot.org>1999-12-09 10:16:54 +1100
commitbf1c9b2012fadab02392126bece5d21e9ddffda6 (patch)
tree371e5f27669fa28773e2b2bb008a81a03715cf2e /bsd-login.c
parentfce1648681a20b99f569d4bfd9335bc4a956b119 (diff)
- Import of patch from Ben Taylor <bent@clark.net>:
- Improved PAM support - "uninstall" rule for Makefile - utmpx support - Should fix PAM problems on Solaris
Diffstat (limited to 'bsd-login.c')
-rw-r--r--bsd-login.c36
1 files changed, 24 insertions, 12 deletions
diff --git a/bsd-login.c b/bsd-login.c
index dcbabe0bf..9c1206547 100644
--- a/bsd-login.c
+++ b/bsd-login.c
@@ -45,47 +45,59 @@ static char *rcsid = "$OpenBSD: login.c,v 1.5 1998/07/13 02:11:12 millert Exp $"
45#include <fcntl.h> 45#include <fcntl.h>
46#include <unistd.h> 46#include <unistd.h>
47#include <stdlib.h> 47#include <stdlib.h>
48#include <utmp.h> 48#ifdef HAVE_UTMPX_H
49# include <utmpx.h>
50#endif
51#ifdef HAVE_UTMP_H
52# include <utmp.h>
53#endif
49#include <stdio.h> 54#include <stdio.h>
50 55
51void 56void
52login(utp) 57login(utp)
53 struct utmp *utp; 58 struct UTMP_STR *utp;
54{ 59{
55 struct utmp old_ut; 60 struct UTMP_STR old_ut;
56 register int fd; 61 register int fd;
57 int tty; 62 int tty;
58 63
59#ifndef UT_LINESIZE 64#ifndef UT_LINESIZE
60# define UT_LINESIZE (sizeof(old_ut.ut_line)) 65# define UT_LINESIZE (sizeof(old_ut.ut_line))
61# define UT_NAMESIZE (sizeof(old_ut.ut_name)) 66# ifdef HAVE_UTMPX_H
67# define UT_NAMESIZE (sizeof(old_ut.ut_user))
68# else
69# define UT_NAMESIZE (sizeof(old_ut.ut_name))
70# endif
62# ifdef HAVE_HOST_IN_UTMP 71# ifdef HAVE_HOST_IN_UTMP
63# define UT_HOSTSIZE (sizeof(old_ut.ut_host)) 72# define UT_HOSTSIZE (sizeof(old_ut.ut_host))
64# endif 73# endif
74# ifdef HAVE_HOST_IN_UTMPX
75# define UT_HOSTSIZE (sizeof(old_ut.ut_host))
76# endif
65#endif 77#endif
66 78
67 tty = ttyslot(); 79 tty = ttyslot();
68 if (tty > 0 && (fd = open(_PATH_UTMP, O_RDWR|O_CREAT, 0644)) >= 0) { 80 if (tty > 0 && (fd = open(_PATH_UTMP, O_RDWR|O_CREAT, 0644)) >= 0) {
69#ifdef HAVE_HOST_IN_UTMP 81#ifdef HAVE_HOST_IN_UTMP || HAVE_HOST_IN_UTMPX
70 (void)lseek(fd, (off_t)(tty * sizeof(struct utmp)), SEEK_SET); 82 (void)lseek(fd, (off_t)(tty * sizeof(struct UTMP_STR)), SEEK_SET);
71 /* 83 /*
72 * Prevent luser from zero'ing out ut_host. 84 * Prevent luser from zero'ing out ut_host.
73 * If the new ut_line is empty but the old one is not 85 * If the new ut_line is empty but the old one is not
74 * and ut_line and ut_name match, preserve the old ut_line. 86 * and ut_line and ut_name match, preserve the old ut_line.
75 */ 87 */
76 if (read(fd, &old_ut, sizeof(struct utmp)) == 88 if (read(fd, &old_ut, sizeof(struct UTMP_STR)) ==
77 sizeof(struct utmp) && utp->ut_host[0] == '\0' && 89 sizeof(struct UTMP_STR) && utp->ut_host[0] == '\0' &&
78 old_ut.ut_host[0] != '\0' && 90 old_ut.ut_host[0] != '\0' &&
79 strncmp(old_ut.ut_line, utp->ut_line, UT_LINESIZE) == 0 && 91 strncmp(old_ut.ut_line, utp->ut_line, UT_LINESIZE) == 0 &&
80 strncmp(old_ut.ut_name, utp->ut_name, UT_NAMESIZE) == 0) 92 strncmp(old_ut.ut_name, utp->ut_name, UT_NAMESIZE) == 0)
81 (void)memcpy(utp->ut_host, old_ut.ut_host, UT_HOSTSIZE); 93 (void)memcpy(utp->ut_host, old_ut.ut_host, UT_HOSTSIZE);
82#endif /* HAVE_HOST_IN_UTMP */ 94#endif /* HAVE_HOST_IN_UTMP || HAVE_HOST_IN_UTMPX */
83 (void)lseek(fd, (off_t)(tty * sizeof(struct utmp)), SEEK_SET); 95 (void)lseek(fd, (off_t)(tty * sizeof(struct UTMP_STR)), SEEK_SET);
84 (void)write(fd, utp, sizeof(struct utmp)); 96 (void)write(fd, utp, sizeof(struct UTMP_STR));
85 (void)close(fd); 97 (void)close(fd);
86 } 98 }
87 if ((fd = open(_PATH_WTMP, O_WRONLY|O_APPEND, 0)) >= 0) { 99 if ((fd = open(_PATH_WTMP, O_WRONLY|O_APPEND, 0)) >= 0) {
88 (void)write(fd, utp, sizeof(struct utmp)); 100 (void)write(fd, utp, sizeof(struct UTMP_STR));
89 (void)close(fd); 101 (void)close(fd);
90 } 102 }
91} 103}