diff options
Diffstat (limited to 'bsd-login.c')
-rw-r--r-- | bsd-login.c | 46 |
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) | ||
58 | void | ||
59 | login(utp,utx) | ||
60 | struct utmp *utp; | ||
61 | struct utmpx *utx; | ||
62 | #else /* defined(HAVE_UTMPX_H) && defined(USE_UTMPX) */ | ||
57 | void | 63 | void |
58 | login(utp) | 64 | login(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 */ |