Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1 | /* |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 2 | * |
| 3 | * login.c |
| 4 | * |
| 5 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
| 6 | * |
| 7 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
| 8 | * All rights reserved |
| 9 | * |
| 10 | * Created: Fri Mar 24 14:51:08 1995 ylo |
| 11 | * |
| 12 | * This file performs some of the things login(1) normally does. We cannot |
| 13 | * easily use something like login -p -h host -f user, because there are |
| 14 | * several different logins around, and it is hard to determined what kind of |
| 15 | * login the current system has. Also, we want to be able to execute commands |
| 16 | * on a tty. |
| 17 | * |
| 18 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 19 | |
| 20 | #include "includes.h" |
Damien Miller | 6552758 | 2000-02-02 19:17:40 +1100 | [diff] [blame] | 21 | RCSID("$Id: login.c,v 1.22 2000/02/02 08:17:41 damien Exp $"); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 22 | |
Damien Miller | 368cf64 | 1999-12-21 09:51:36 +1100 | [diff] [blame] | 23 | #if defined(HAVE_UTMPX_H) && defined(USE_UTMPX) |
Damien Miller | bf1c9b2 | 1999-12-09 10:16:54 +1100 | [diff] [blame] | 24 | # include <utmpx.h> |
| 25 | #endif |
| 26 | #ifdef HAVE_UTMP_H |
| 27 | # include <utmp.h> |
| 28 | #endif |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 29 | #include "ssh.h" |
Damien Miller | ab18c41 | 1999-11-11 10:40:23 +1100 | [diff] [blame] | 30 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 31 | #ifdef HAVE_UTIL_H |
| 32 | # include <util.h> |
| 33 | #endif |
Damien Miller | ab18c41 | 1999-11-11 10:40:23 +1100 | [diff] [blame] | 34 | #ifdef HAVE_LASTLOG_H |
| 35 | # include <lastlog.h> |
| 36 | #endif |
Damien Miller | 063fdf8 | 1999-11-25 13:08:31 +1100 | [diff] [blame] | 37 | #ifdef HAVE_LOGIN_H |
| 38 | # include <login.h> |
| 39 | #endif |
Damien Miller | ab18c41 | 1999-11-11 10:40:23 +1100 | [diff] [blame] | 40 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 41 | /* |
| 42 | * Returns the time when the user last logged in. Returns 0 if the |
| 43 | * information is not available. This must be called before record_login. |
| 44 | * The host the user logged in from will be returned in buf. |
| 45 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 46 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 47 | /* |
| 48 | * Returns the time when the user last logged in (or 0 if no previous login |
| 49 | * is found). The name of the host used last time is returned in buf. |
| 50 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 51 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 52 | unsigned long |
| 53 | get_last_login_time(uid_t uid, const char *logname, |
| 54 | char *buf, unsigned int bufsize) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 55 | { |
Damien Miller | 1b0c228 | 1999-12-22 16:09:48 +1100 | [diff] [blame] | 56 | #if defined(_PATH_LASTLOG) && !defined(DISABLE_LASTLOG) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 57 | struct lastlog ll; |
| 58 | char *lastlog; |
| 59 | int fd; |
Damien Miller | 6b85a7f | 2000-01-02 11:45:33 +1100 | [diff] [blame] | 60 | #ifdef LASTLOG_IS_DIR |
Damien Miller | def0dc9 | 2000-01-23 20:18:35 +1100 | [diff] [blame] | 61 | char lbuf[1024]; |
Damien Miller | 6b85a7f | 2000-01-02 11:45:33 +1100 | [diff] [blame] | 62 | #endif /* LASTLOG_IS_DIR */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 63 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 64 | lastlog = _PATH_LASTLOG; |
| 65 | buf[0] = '\0'; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 66 | |
Damien Miller | def0dc9 | 2000-01-23 20:18:35 +1100 | [diff] [blame] | 67 | #ifndef LASTLOG_IS_DIR |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 68 | fd = open(lastlog, O_RDONLY); |
| 69 | if (fd < 0) |
| 70 | return 0; |
| 71 | lseek(fd, (off_t) ((long) uid * sizeof(ll)), SEEK_SET); |
Damien Miller | 6b85a7f | 2000-01-02 11:45:33 +1100 | [diff] [blame] | 72 | #else /* LASTLOG_IS_DIR */ |
Damien Miller | def0dc9 | 2000-01-23 20:18:35 +1100 | [diff] [blame] | 73 | snprintf(lbuf, sizeof(buf), "%s/%s", lastlog, logname); |
| 74 | fd = open(lbuf, O_RDONLY); |
Damien Miller | 6b85a7f | 2000-01-02 11:45:33 +1100 | [diff] [blame] | 75 | if (fd < 0) |
| 76 | return 0; |
| 77 | #endif /* LASTLOG_IS_DIR */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 78 | if (read(fd, &ll, sizeof(ll)) != sizeof(ll)) { |
| 79 | close(fd); |
| 80 | return 0; |
| 81 | } |
| 82 | close(fd); |
| 83 | if (bufsize > sizeof(ll.ll_host) + 1) |
| 84 | bufsize = sizeof(ll.ll_host) + 1; |
| 85 | strncpy(buf, ll.ll_host, bufsize - 1); |
| 86 | buf[bufsize - 1] = 0; |
| 87 | return ll.ll_time; |
Damien Miller | 76112de | 1999-12-21 11:18:08 +1100 | [diff] [blame] | 88 | |
Damien Miller | 1b0c228 | 1999-12-22 16:09:48 +1100 | [diff] [blame] | 89 | #else /* defined(_PATH_LASTLOG) && !defined(DISABLE_LASTLOG) */ |
Damien Miller | 76112de | 1999-12-21 11:18:08 +1100 | [diff] [blame] | 90 | /* Look in wtmp for the last login */ |
| 91 | struct utmp wt; |
| 92 | char *wt_file = _PATH_WTMP; |
| 93 | int fd1; |
| 94 | unsigned long t = 0; |
| 95 | |
| 96 | if ( (fd1 = open(wt_file, O_RDONLY)) < 0 ) { |
| 97 | error("Couldn't open %.100s to find last login time.", wt_file); |
| 98 | return 0; |
| 99 | } |
| 100 | |
| 101 | /* seek to last record of file */ |
| 102 | lseek(fd1, (off_t)(0-sizeof(struct utmp)), SEEK_END); |
| 103 | |
| 104 | /* loop through wtmp for our last user login record */ |
| 105 | do { |
| 106 | if (read(fd1, &wt, sizeof(wt)) != sizeof(wt)) { |
| 107 | close(fd1); |
| 108 | return 0; |
| 109 | } |
| 110 | |
| 111 | if ( wt.ut_type == USER_PROCESS) { |
| 112 | if ( !strncmp(logname, wt.ut_user, 8) ) { |
| 113 | t = (unsigned long) wt.ut_time; |
Damien Miller | 1b0c228 | 1999-12-22 16:09:48 +1100 | [diff] [blame] | 114 | #ifdef HAVE_HOST_IN_UTMP |
Damien Miller | 76112de | 1999-12-21 11:18:08 +1100 | [diff] [blame] | 115 | if (bufsize > sizeof(wt.ut_host) + 1) |
| 116 | bufsize = sizeof(wt.ut_host) + 1; |
| 117 | strncpy(buf, wt.ut_host, bufsize - 1); |
| 118 | buf[bufsize - 1] = 0; |
Damien Miller | 1b0c228 | 1999-12-22 16:09:48 +1100 | [diff] [blame] | 119 | #else /* HAVE_HOST_IN_UTMP */ |
| 120 | buf[0] = 0; |
| 121 | #endif /* HAVE_HOST_IN_UTMP */ |
Damien Miller | 76112de | 1999-12-21 11:18:08 +1100 | [diff] [blame] | 122 | } |
| 123 | } |
| 124 | |
| 125 | if (lseek(fd1, (off_t)(0-2*sizeof(struct utmp)), SEEK_CUR) == -1) |
| 126 | break; |
| 127 | } while (t == 0); |
| 128 | |
| 129 | return t; |
Damien Miller | 1b0c228 | 1999-12-22 16:09:48 +1100 | [diff] [blame] | 130 | #endif /* defined(_PATH_LASTLOG) && !defined(DISABLE_LASTLOG) */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 131 | } |
| 132 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 133 | /* |
| 134 | * Records that the user has logged in. I these parts of operating systems |
| 135 | * were more standardized. |
| 136 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 137 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 138 | void |
| 139 | record_login(int pid, const char *ttyname, const char *user, uid_t uid, |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 140 | const char *host, struct sockaddr * addr) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 141 | { |
Damien Miller | 1b0c228 | 1999-12-22 16:09:48 +1100 | [diff] [blame] | 142 | #if defined(_PATH_LASTLOG) && !defined(DISABLE_LASTLOG) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 143 | struct lastlog ll; |
| 144 | char *lastlog; |
Damien Miller | 6b85a7f | 2000-01-02 11:45:33 +1100 | [diff] [blame] | 145 | #ifdef LASTLOG_IS_DIR |
| 146 | char buf[1024]; |
| 147 | #endif /* LASTLOG_IS_DIR */ |
Damien Miller | 1b0c228 | 1999-12-22 16:09:48 +1100 | [diff] [blame] | 148 | #endif /* defined(_PATH_LASTLOG) && !defined(DISABLE_LASTLOG) */ |
Damien Miller | 2e1b082 | 1999-12-25 10:11:29 +1100 | [diff] [blame] | 149 | struct utmp u; |
| 150 | #if defined(HAVE_UTMPX_H) && defined(USE_UTMPX) |
| 151 | struct utmpx utx; |
| 152 | #endif |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 153 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 154 | /* Construct an utmp/wtmp entry. */ |
| 155 | memset(&u, 0, sizeof(u)); |
| 156 | strncpy(u.ut_line, ttyname + 5, sizeof(u.ut_line)); |
Damien Miller | 9550a76 | 1999-12-29 02:32:22 +1100 | [diff] [blame] | 157 | #if defined(HAVE_ID_IN_UTMP) |
Damien Miller | e127624 | 1999-12-27 11:33:56 +1100 | [diff] [blame] | 158 | strncpy(u.ut_id, ttyname + 8, sizeof(u.ut_id)); |
Damien Miller | 9550a76 | 1999-12-29 02:32:22 +1100 | [diff] [blame] | 159 | #endif /* defined(HAVE_ID_IN_UTMP) */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 160 | strncpy(u.ut_name, user, sizeof(u.ut_name)); |
Damien Miller | 4ff2b9b | 1999-12-28 10:41:12 +1100 | [diff] [blame] | 161 | #if defined(HAVE_TV_IN_UTMP) |
| 162 | (void)gettimeofday(&u.ut_tv, NULL); |
| 163 | #else /* defined(HAVE_TV_IN_UTMP) */ |
| 164 | u.ut_time = time(NULL); |
| 165 | #endif /* defined(HAVE_TV_IN_UTMP) */ |
| 166 | #if defined(HAVE_PID_IN_UTMP) |
| 167 | u.ut_pid = (pid_t)pid; |
| 168 | #endif /* HAVE_PID_IN_UTMP */ |
| 169 | #if defined(HAVE_TYPE_IN_UTMP) |
Damien Miller | 2e1b082 | 1999-12-25 10:11:29 +1100 | [diff] [blame] | 170 | u.ut_type = (uid == -1)?DEAD_PROCESS:USER_PROCESS; |
Damien Miller | 4ff2b9b | 1999-12-28 10:41:12 +1100 | [diff] [blame] | 171 | #endif /* HAVE_TYPE_IN_UTMP */ |
Damien Miller | 2e1b082 | 1999-12-25 10:11:29 +1100 | [diff] [blame] | 172 | #if defined(HAVE_HOST_IN_UTMP) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 173 | strncpy(u.ut_host, host, sizeof(u.ut_host)); |
Damien Miller | ab18c41 | 1999-11-11 10:40:23 +1100 | [diff] [blame] | 174 | #endif |
Damien Miller | 3131d8b | 1999-12-31 09:42:24 +1100 | [diff] [blame] | 175 | #if defined(HAVE_ADDR_IN_UTMP) |
Damien Miller | d89c24b | 2000-01-26 11:04:48 +1100 | [diff] [blame] | 176 | if (addr) { |
| 177 | switch (addr->sa_family) { |
| 178 | case AF_INET: { |
| 179 | struct sockaddr_in *in = (struct sockaddr_in*)addr; |
| 180 | memcpy(&(u.ut_addr), &(in->sin_addr), sizeof(&(in->sin_addr))); |
| 181 | break; |
| 182 | } |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 183 | #if defined(HAVE_ADDR_V6_IN_UTMP) |
Damien Miller | d89c24b | 2000-01-26 11:04:48 +1100 | [diff] [blame] | 184 | case AF_INET6: { |
| 185 | struct sockaddr_in6 *in6 = (struct sockaddr_in6*)addr; |
| 186 | memcpy(u.ut_addr_v6, &(in6->sin6_addr), sizeof(&(in6->sin6_addr))); |
| 187 | break; |
| 188 | } |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 189 | #endif |
Damien Miller | d89c24b | 2000-01-26 11:04:48 +1100 | [diff] [blame] | 190 | default: |
| 191 | break; |
| 192 | } |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 193 | } |
Damien Miller | 3131d8b | 1999-12-31 09:42:24 +1100 | [diff] [blame] | 194 | #endif |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 195 | |
Damien Miller | 2e1b082 | 1999-12-25 10:11:29 +1100 | [diff] [blame] | 196 | #if defined(HAVE_UTMPX_H) && defined(USE_UTMPX) |
| 197 | memset(&utx, 0, sizeof(utx)); |
| 198 | strncpy(utx.ut_user, user, sizeof(utx.ut_name)); |
| 199 | strncpy(utx.ut_line, ttyname + 5, sizeof(utx.ut_line)); |
Damien Miller | e127624 | 1999-12-27 11:33:56 +1100 | [diff] [blame] | 200 | strncpy(utx.ut_id, ttyname + 8, sizeof(utx.ut_id)); |
Damien Miller | 2e1b082 | 1999-12-25 10:11:29 +1100 | [diff] [blame] | 201 | utx.ut_pid = (pid_t)pid; |
Damien Miller | 4ff2b9b | 1999-12-28 10:41:12 +1100 | [diff] [blame] | 202 | (void)gettimeofday(&utx.ut_tv, NULL); |
Damien Miller | 32b3cf2 | 1999-12-26 10:21:48 +1100 | [diff] [blame] | 203 | utx.ut_type = (uid == -1)?DEAD_PROCESS:USER_PROCESS; |
| 204 | # ifdef HAVE_HOST_IN_UTMPX |
| 205 | # ifdef HAVE_SYSLEN_IN_UTMPX |
Damien Miller | 2e1b082 | 1999-12-25 10:11:29 +1100 | [diff] [blame] | 206 | utx.ut_syslen = strlen(host); |
Damien Miller | 32b3cf2 | 1999-12-26 10:21:48 +1100 | [diff] [blame] | 207 | strncpy(utx.ut_host, host, utx.ut_syslen); |
| 208 | # else |
Damien Miller | 2e1b082 | 1999-12-25 10:11:29 +1100 | [diff] [blame] | 209 | strncpy(utx.ut_host, host, sizeof(utx.ut_host)); |
Damien Miller | 32b3cf2 | 1999-12-26 10:21:48 +1100 | [diff] [blame] | 210 | # endif /* HAVE_SYSLEN_IN_UTMPX */ |
| 211 | # endif |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 212 | #if defined(HAVE_ADDR_IN_UTMPX) |
Damien Miller | 6034fdf | 2000-01-29 20:55:09 +1100 | [diff] [blame] | 213 | if (addr) { |
Damien Miller | d89c24b | 2000-01-26 11:04:48 +1100 | [diff] [blame] | 214 | switch (addr->sa_family) { |
| 215 | case AF_INET: { |
| 216 | struct sockaddr_in *in = (struct sockaddr_in*)addr; |
| 217 | memcpy(&(utx.ut_addr), &(in->sin_addr), sizeof(&(in->sin_addr))); |
| 218 | break; |
| 219 | } |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 220 | #if defined(HAVE_ADDR_V6_IN_UTMPX) |
Damien Miller | d89c24b | 2000-01-26 11:04:48 +1100 | [diff] [blame] | 221 | case AF_INET6: { |
| 222 | struct sockaddr_in6 *in6 = (struct sockaddr_in6*)addr; |
| 223 | memcpy(utx.ut_addr_v6, &(in6->sin6_addr), sizeof(&(in6->sin6_addr))); |
| 224 | break; |
| 225 | } |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 226 | #endif |
Damien Miller | d89c24b | 2000-01-26 11:04:48 +1100 | [diff] [blame] | 227 | default: |
| 228 | break; |
| 229 | } |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 230 | } |
| 231 | #endif |
Damien Miller | 2e1b082 | 1999-12-25 10:11:29 +1100 | [diff] [blame] | 232 | #endif /* defined(HAVE_UTMPX_H) && defined(USE_UTMPX) */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 233 | |
Damien Miller | 32b3cf2 | 1999-12-26 10:21:48 +1100 | [diff] [blame] | 234 | /*#if defined(HAVE_UTMPX_H) && defined(USE_UTMPX) && !defined(HAVE_LOGIN)*/ |
| 235 | #if defined(HAVE_UTMPX_H) && defined(USE_UTMPX) |
Damien Miller | 2e1b082 | 1999-12-25 10:11:29 +1100 | [diff] [blame] | 236 | login(&u, &utx); |
| 237 | #else /* defined(HAVE_UTMPX_H) && defined(USE_UTMPX) */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 238 | login(&u); |
Damien Miller | 2e1b082 | 1999-12-25 10:11:29 +1100 | [diff] [blame] | 239 | #endif /* defined(HAVE_UTMPX_H) && defined(USE_UTMPX) */ |
Damien Miller | 76112de | 1999-12-21 11:18:08 +1100 | [diff] [blame] | 240 | |
Damien Miller | 1b0c228 | 1999-12-22 16:09:48 +1100 | [diff] [blame] | 241 | #if defined(_PATH_LASTLOG) && !defined(DISABLE_LASTLOG) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 242 | lastlog = _PATH_LASTLOG; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 243 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 244 | /* Update lastlog unless actually recording a logout. */ |
| 245 | if (strcmp(user, "") != 0) { |
Damien Miller | 76112de | 1999-12-21 11:18:08 +1100 | [diff] [blame] | 246 | int fd; |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 247 | /* |
| 248 | * It is safer to bzero the lastlog structure first because |
| 249 | * some systems might have some extra fields in it (e.g. SGI) |
| 250 | */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 251 | memset(&ll, 0, sizeof(ll)); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 252 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 253 | /* Update lastlog. */ |
| 254 | ll.ll_time = time(NULL); |
| 255 | strncpy(ll.ll_line, ttyname + 5, sizeof(ll.ll_line)); |
| 256 | strncpy(ll.ll_host, host, sizeof(ll.ll_host)); |
Damien Miller | 6b85a7f | 2000-01-02 11:45:33 +1100 | [diff] [blame] | 257 | #ifdef LASTLOG_IS_DIR |
Damien Miller | 6552758 | 2000-02-02 19:17:40 +1100 | [diff] [blame] | 258 | snprintf(buf, sizeof(buf), "%s/%s", lastlog, user); |
Damien Miller | 6b85a7f | 2000-01-02 11:45:33 +1100 | [diff] [blame] | 259 | fd = open(buf, O_RDWR); |
| 260 | if (fd >= 0) { |
| 261 | #else /* LASTLOG_IS_DIR */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 262 | fd = open(lastlog, O_RDWR); |
| 263 | if (fd >= 0) { |
| 264 | lseek(fd, (off_t) ((long) uid * sizeof(ll)), SEEK_SET); |
Damien Miller | 6b85a7f | 2000-01-02 11:45:33 +1100 | [diff] [blame] | 265 | #endif /* LASTLOG_IS_DIR */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 266 | if (write(fd, &ll, sizeof(ll)) != sizeof(ll)) |
| 267 | log("Could not write %.100s: %.100s", lastlog, strerror(errno)); |
| 268 | close(fd); |
| 269 | } |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 270 | } |
Damien Miller | 1b0c228 | 1999-12-22 16:09:48 +1100 | [diff] [blame] | 271 | #endif /* defined(_PATH_LASTLOG) && !defined(DISABLE_LASTLOG) */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 272 | } |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 273 | |
| 274 | /* Records that the user has logged out. */ |
| 275 | |
| 276 | void |
| 277 | record_logout(int pid, const char *ttyname) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 278 | { |
Damien Miller | ab18c41 | 1999-11-11 10:40:23 +1100 | [diff] [blame] | 279 | #ifdef HAVE_LIBUTIL_LOGIN |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 280 | const char *line = ttyname + 5; /* /dev/ttyq8 -> ttyq8 */ |
| 281 | if (logout(line)) |
| 282 | logwtmp(line, "", ""); |
Damien Miller | ab18c41 | 1999-11-11 10:40:23 +1100 | [diff] [blame] | 283 | #else /* HAVE_LIBUTIL_LOGIN */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 284 | record_login(pid, ttyname, "", -1, "", NULL); |
Damien Miller | ab18c41 | 1999-11-11 10:40:23 +1100 | [diff] [blame] | 285 | #endif /* HAVE_LIBUTIL_LOGIN */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 286 | } |