… | |
… | |
104 | break; |
104 | break; |
105 | } |
105 | } |
106 | else if (errno != EAGAIN && errno != EACCES) |
106 | else if (errno != EAGAIN && errno != EACCES) |
107 | break; |
107 | break; |
108 | if (!gotlock) |
108 | if (!gotlock) |
|
|
109 | { |
109 | { /* give it up */ |
110 | /* give it up */ |
110 | close (fd); |
111 | close (fd); |
111 | return; |
112 | return; |
112 | } |
113 | } |
113 | if (fstat (fd, &sbuf) == 0) |
114 | if (fstat (fd, &sbuf) == 0) |
114 | if (write (fd, putmp, sizeof (struct utmp)) != sizeof (struct utmp)) |
115 | if (write (fd, putmp, sizeof (struct utmp)) != sizeof (struct utmp)) |
… | |
… | |
160 | if (stat (fname, &st) != 0) |
161 | if (stat (fname, &st) != 0) |
161 | return; |
162 | return; |
162 | if (S_ISDIR (st.st_mode)) |
163 | if (S_ISDIR (st.st_mode)) |
163 | { |
164 | { |
164 | sprintf (lastlogfile, "%.*s/%.*s", |
165 | sprintf (lastlogfile, "%.*s/%.*s", |
165 | sizeof (lastlogfile) - sizeof (pwent->pw_name) - 2, fname, |
166 | (int)(sizeof (lastlogfile) - sizeof (pwent->pw_name) - 2), fname, |
166 | sizeof (pwent->pw_name), |
167 | (int)sizeof (pwent->pw_name), |
167 | (!pwent->pw_name || pwent->pw_name[0] == '\0') ? "unknown" |
168 | (!pwent->pw_name || pwent->pw_name[0] == '\0') ? "unknown" |
168 | : pwent->pw_name); |
169 | : pwent->pw_name); |
169 | if ((fd = open (lastlogfile, O_WRONLY | O_CREAT, 0644)) >= 0) |
170 | if ((fd = open (lastlogfile, O_WRONLY | O_CREAT, 0644)) >= 0) |
170 | { |
171 | { |
171 | write (fd, &ll, sizeof (ll)); |
172 | write (fd, &ll, sizeof (ll)); |
… | |
… | |
178 | if (lseek (fd, (off_t) ((long)pwent->pw_uid * sizeof (ll)), |
179 | if (lseek (fd, (off_t) ((long)pwent->pw_uid * sizeof (ll)), |
179 | SEEK_SET) != -1) |
180 | SEEK_SET) != -1) |
180 | write (fd, &ll, sizeof (ll)); |
181 | write (fd, &ll, sizeof (ll)); |
181 | close (fd); |
182 | close (fd); |
182 | } |
183 | } |
183 | # endif /* HAVE_STRUCT_LASTLOG */ |
184 | # endif /* HAVE_STRUCT_LASTLOG */ |
184 | } |
185 | } |
185 | #endif /* LASTLOG_SUPPORT */ |
186 | #endif /* LASTLOG_SUPPORT */ |
186 | |
187 | |
187 | /* ------------------------------------------------------------------------- */ |
188 | /* ------------------------------------------------------------------------- */ |
188 | |
189 | |
189 | /* |
190 | /* |
190 | * make and write utmp and wtmp entries |
191 | * make and write utmp and wtmp entries |
… | |
… | |
206 | #ifdef HAVE_STRUCT_UTMPX |
207 | #ifdef HAVE_STRUCT_UTMPX |
207 | struct utmpx *utx = &this->utx; |
208 | struct utmpx *utx = &this->utx; |
208 | #endif |
209 | #endif |
209 | int i; |
210 | int i; |
210 | struct passwd *pwent = getpwuid (getuid ()); |
211 | struct passwd *pwent = getpwuid (getuid ()); |
|
|
212 | const char *name = (pwent && pwent->pw_name) ? pwent->pw_name : "?"; |
211 | |
213 | |
212 | if (!strncmp (pty, "/dev/", 5)) |
214 | if (!strncmp (pty, "/dev/", 5)) |
213 | pty += 5; /* skip /dev/ prefix */ |
215 | pty += 5; /* skip /dev/ prefix */ |
214 | |
216 | |
215 | #if defined(HAVE_UTMP_PID) || defined(HAVE_STRUCT_UTMPX) |
217 | #if defined(HAVE_UTMP_PID) || defined(HAVE_STRUCT_UTMPX) |
216 | if (!strncmp (pty, "pty", 3) || !strncmp (pty, "tty", 3)) |
218 | if (!strncmp (pty, "pty", 3) || !strncmp (pty, "tty", 3)) |
217 | strncpy (ut_id, pty + 3, sizeof (ut_id)); |
219 | strncpy (ut_id, pty + 3, sizeof (ut_id)); |
218 | else if (sscanf (pty, "pts/%d", &i) == 1) |
220 | else if (sscanf (pty, "pts/%d", &i) == 1) |
219 | sprintf (ut_id, "vt%02x", (i & 0xff)); /* sysv naming */ |
221 | sprintf (ut_id, "vt%02x", (i & 0xff)); /* sysv naming */ |
220 | else if (strncmp (pty, "pty", 3) && strncmp (pty, "tty", 3)) |
222 | else |
221 | { |
223 | { |
222 | ptytty_warn ("can't parse tty name \"%s\", not adding utmp entry.\n", pty); |
224 | ptytty_warn ("can't parse tty name \"%s\", not adding utmp entry.\n", pty); |
223 | return; |
225 | return; |
224 | } |
226 | } |
225 | #endif |
227 | #endif |
… | |
… | |
229 | # ifdef HAVE_UTMP_PID |
231 | # ifdef HAVE_UTMP_PID |
230 | setutent (); |
232 | setutent (); |
231 | strncpy (ut->ut_id, ut_id, sizeof (ut->ut_id)); |
233 | strncpy (ut->ut_id, ut_id, sizeof (ut->ut_id)); |
232 | ut->ut_type = DEAD_PROCESS; |
234 | ut->ut_type = DEAD_PROCESS; |
233 | getutid (ut); /* position to entry in utmp file */ |
235 | getutid (ut); /* position to entry in utmp file */ |
234 | strncpy (this->ut_id, ut_id, sizeof (this->ut_id)); |
|
|
235 | # endif |
236 | # endif |
236 | #endif |
237 | #endif |
237 | |
238 | |
238 | #ifdef HAVE_STRUCT_UTMPX |
239 | #ifdef HAVE_STRUCT_UTMPX |
239 | memset (utx, 0, sizeof (struct utmpx)); |
240 | memset (utx, 0, sizeof (struct utmpx)); |
240 | setutxent (); |
241 | setutxent (); |
241 | strncpy (utx->ut_id, ut_id, sizeof (utx->ut_id)); |
242 | strncpy (utx->ut_id, ut_id, sizeof (utx->ut_id)); |
242 | utx->ut_type = DEAD_PROCESS; |
243 | utx->ut_type = DEAD_PROCESS; |
243 | getutxid (utx); /* position to entry in utmp file */ |
244 | getutxid (utx); /* position to entry in utmp file */ |
244 | strncpy (this->ut_id, ut_id, sizeof (this->ut_id)); |
|
|
245 | #endif |
245 | #endif |
246 | |
246 | |
247 | #ifdef HAVE_STRUCT_UTMP |
247 | #ifdef HAVE_STRUCT_UTMP |
248 | strncpy (ut->ut_line, pty, sizeof (ut->ut_line)); |
248 | strncpy (ut->ut_line, pty, sizeof (ut->ut_line)); |
|
|
249 | # ifdef HAVE_UTMP_HOST |
|
|
250 | strncpy (ut->ut_host, hostname, sizeof (ut->ut_host)); |
|
|
251 | # endif |
249 | ut->ut_time = time (NULL); |
252 | ut->ut_time = time (NULL); |
250 | # ifdef HAVE_UTMP_PID |
253 | # ifdef HAVE_UTMP_PID |
251 | strncpy (ut->ut_user, (pwent && pwent->pw_name) ? pwent->pw_name : "?", |
254 | strncpy (ut->ut_user, name, sizeof (ut->ut_user)); |
252 | sizeof (ut->ut_user)); |
|
|
253 | strncpy (ut->ut_id, ut_id, sizeof (ut->ut_id)); |
255 | strncpy (ut->ut_id, ut_id, sizeof (ut->ut_id)); |
254 | ut->ut_time = time (NULL); |
|
|
255 | ut->ut_pid = cmd_pid; |
256 | ut->ut_pid = cmd_pid; |
256 | # ifdef HAVE_UTMP_HOST |
|
|
257 | strncpy (ut->ut_host, hostname, sizeof (ut->ut_host)); |
|
|
258 | # endif |
|
|
259 | ut->ut_type = USER_PROCESS; |
257 | ut->ut_type = USER_PROCESS; |
260 | pututline (ut); |
258 | pututline (ut); |
261 | endutent (); /* close the file */ |
259 | endutent (); /* close the file */ |
262 | utmp_pos = 0; |
260 | utmp_pos = 0; |
263 | # else |
261 | # else |
264 | strncpy (ut->ut_name, (pwent && pwent->pw_name) ? pwent->pw_name : "?", |
|
|
265 | sizeof (ut->ut_name)); |
|
|
266 | # ifdef HAVE_UTMP_HOST |
|
|
267 | strncpy (ut->ut_host, hostname, sizeof (ut->ut_host)); |
262 | strncpy (ut->ut_name, name, sizeof (ut->ut_name)); |
268 | # endif |
|
|
269 | # endif |
263 | # endif |
270 | #endif |
264 | #endif |
271 | |
265 | |
272 | #ifdef HAVE_STRUCT_UTMPX |
266 | #ifdef HAVE_STRUCT_UTMPX |
273 | strncpy (utx->ut_line, pty, sizeof (utx->ut_line)); |
267 | strncpy (utx->ut_line, pty, sizeof (utx->ut_line)); |
274 | strncpy (utx->ut_user, (pwent && pwent->pw_name) ? pwent->pw_name : "?", |
268 | strncpy (utx->ut_user, name, sizeof (utx->ut_user)); |
275 | sizeof (utx->ut_user)); |
|
|
276 | strncpy (utx->ut_id, ut_id, sizeof (utx->ut_id)); |
269 | strncpy (utx->ut_id, ut_id, sizeof (utx->ut_id)); |
277 | # if HAVE_UTMPX_SESSION |
270 | # if HAVE_UTMPX_SESSION |
278 | utx->ut_session = getsid (0); |
271 | utx->ut_session = getsid (0); |
279 | # endif |
272 | # endif |
280 | utx->ut_tv.tv_sec = time (NULL); |
273 | utx->ut_tv.tv_sec = time (NULL); |