… | |
… | |
42 | #include "../config.h" /* NECESSARY */ |
42 | #include "../config.h" /* NECESSARY */ |
43 | #include "rxvt.h" /* NECESSARY */ |
43 | #include "rxvt.h" /* NECESSARY */ |
44 | #include "logging.h" |
44 | #include "logging.h" |
45 | #ifdef UTMP_SUPPORT |
45 | #ifdef UTMP_SUPPORT |
46 | |
46 | |
|
|
47 | #if HAVE_STRUCT_UTMP |
47 | int rxvt_write_bsd_utmp (int utmp_pos, struct utmp *wu); |
48 | int rxvt_write_bsd_utmp (int utmp_pos, struct utmp *wu); |
48 | void rxvt_update_wtmp (const char *fname, const struct utmp *putmp); |
49 | void rxvt_update_wtmp (const char *fname, const struct utmp *putmp); |
|
|
50 | #endif |
|
|
51 | |
49 | void rxvt_update_lastlog (const char *fname, const char *pty, const char *host); |
52 | void rxvt_update_lastlog (const char *fname, const char *pty, const char *host); |
50 | |
53 | |
51 | /* |
54 | /* |
52 | * BSD style utmp entry |
55 | * BSD style utmp entry |
53 | * ut_line, ut_name, ut_host, ut_time |
56 | * ut_line, ut_name, ut_host, ut_time |
… | |
… | |
70 | struct utmpx *utx = &this->utx; |
73 | struct utmpx *utx = &this->utx; |
71 | #endif |
74 | #endif |
72 | #ifdef HAVE_UTMP_PID |
75 | #ifdef HAVE_UTMP_PID |
73 | int i; |
76 | int i; |
74 | #endif |
77 | #endif |
75 | struct passwd *pwent = getpwuid (getuid ()); |
78 | struct passwd *pwent = getpwuid (getuid ()); |
76 | |
79 | |
77 | if (!strncmp (pty, "/dev/", 5)) |
80 | if (!strncmp (pty, "/dev/", 5)) |
78 | pty += 5; /* skip /dev/ prefix */ |
81 | pty += 5; /* skip /dev/ prefix */ |
79 | |
82 | |
80 | #ifdef HAVE_UTMP_PID |
83 | #ifdef HAVE_UTMP_PID |
… | |
… | |
137 | #ifdef HAVE_STRUCT_UTMPX |
140 | #ifdef HAVE_STRUCT_UTMPX |
138 | strncpy (utx->ut_line, pty, sizeof (utx->ut_line)); |
141 | strncpy (utx->ut_line, pty, sizeof (utx->ut_line)); |
139 | strncpy (utx->ut_user, (pwent && pwent->pw_name) ? pwent->pw_name : "?", |
142 | strncpy (utx->ut_user, (pwent && pwent->pw_name) ? pwent->pw_name : "?", |
140 | sizeof (utx->ut_user)); |
143 | sizeof (utx->ut_user)); |
141 | strncpy (utx->ut_id, ut_id, sizeof (utx->ut_id)); |
144 | strncpy (utx->ut_id, ut_id, sizeof (utx->ut_id)); |
|
|
145 | # if HAVE_UTMPX_SESSION |
142 | utx->ut_session = getsid (0); |
146 | utx->ut_session = getsid (0); |
|
|
147 | # endif |
143 | utx->ut_tv.tv_sec = time (NULL); |
148 | utx->ut_tv.tv_sec = time (NULL); |
144 | utx->ut_tv.tv_usec = 0; |
149 | utx->ut_tv.tv_usec = 0; |
145 | utx->ut_pid = cmd_pid; |
150 | utx->ut_pid = cmd_pid; |
146 | # ifdef HAVE_UTMPX_HOST |
151 | # ifdef HAVE_UTMPX_HOST |
147 | strncpy (utx->ut_host, hostname, sizeof (utx->ut_host)); |
152 | strncpy (utx->ut_host, hostname, sizeof (utx->ut_host)); |
… | |
… | |
171 | # else |
176 | # else |
172 | FILE *fd0; |
177 | FILE *fd0; |
173 | |
178 | |
174 | if ((fd0 = fopen (TTYTAB_FILENAME, "r")) != NULL) |
179 | if ((fd0 = fopen (TTYTAB_FILENAME, "r")) != NULL) |
175 | { |
180 | { |
176 | char buf[256], name[256]; |
181 | char buf[256], name[256]; |
177 | |
182 | |
178 | buf[sizeof (buf) - 1] = '\0'; |
183 | buf[sizeof (buf) - 1] = '\0'; |
179 | for (i = 1; (fgets (buf, sizeof (buf) - 1, fd0) != NULL);) |
184 | for (i = 1; (fgets (buf, sizeof (buf) - 1, fd0) != NULL);) |
180 | { |
185 | { |
181 | if (*buf == '#' || sscanf (buf, "%s", name) != 1) |
186 | if (*buf == '#' || sscanf (buf, "%s", name) != 1) |
… | |
… | |
197 | } |
202 | } |
198 | #endif |
203 | #endif |
199 | |
204 | |
200 | #ifdef WTMP_SUPPORT |
205 | #ifdef WTMP_SUPPORT |
201 | # ifdef WTMP_ONLY_ON_LOGIN |
206 | # ifdef WTMP_ONLY_ON_LOGIN |
202 | if (options & Opt_loginShell) |
207 | if (OPTION (Opt_loginShell)) |
203 | # endif |
208 | # endif |
204 | { |
209 | { |
205 | # ifdef HAVE_STRUCT_UTMP |
210 | # ifdef HAVE_STRUCT_UTMP |
206 | # ifdef HAVE_UPDWTMP |
211 | # ifdef HAVE_UPDWTMP |
207 | updwtmp (RXVT_WTMP_FILE, ut); |
212 | updwtmp (RXVT_WTMP_FILE, ut); |
208 | # else |
213 | # else |
209 | rxvt_update_wtmp (RXVT_WTMP_FILE, ut); |
214 | rxvt_update_wtmp (RXVT_WTMP_FILE, ut); |
210 | # endif |
215 | # endif |
211 | # endif |
216 | # endif |
212 | # ifdef HAVE_STRUCT_UTMPX |
217 | # ifdef HAVE_STRUCT_UTMPX |
|
|
218 | # if HAVE_UPDWTMPX |
213 | updwtmpx (RXVT_WTMPX_FILE, utx); |
219 | updwtmpx (RXVT_WTMPX_FILE, utx); |
|
|
220 | # else |
|
|
221 | pututxline (utx); |
|
|
222 | # endif |
214 | # endif |
223 | # endif |
215 | } |
224 | } |
216 | #endif |
225 | #endif |
217 | #if defined(LASTLOG_SUPPORT) && defined(RXVT_LASTLOG_FILE) |
226 | #if defined(LASTLOG_SUPPORT) && defined(RXVT_LASTLOG_FILE) |
218 | if (options & Opt_loginShell) |
227 | if (OPTION (Opt_loginShell)) |
219 | rxvt_update_lastlog (RXVT_LASTLOG_FILE, pty, hostname); |
228 | rxvt_update_lastlog (RXVT_LASTLOG_FILE, pty, hostname); |
220 | #endif |
229 | #endif |
221 | } |
230 | } |
222 | |
231 | |
223 | /* ------------------------------------------------------------------------- */ |
232 | /* ------------------------------------------------------------------------- */ |
… | |
… | |
262 | strncpy (utx->ut_id, ut_id, sizeof (utx->ut_id)); |
271 | strncpy (utx->ut_id, ut_id, sizeof (utx->ut_id)); |
263 | utx->ut_type = USER_PROCESS; |
272 | utx->ut_type = USER_PROCESS; |
264 | if ((tmputx = getutxid (utx))) /* position to entry in utmp file */ |
273 | if ((tmputx = getutxid (utx))) /* position to entry in utmp file */ |
265 | utx = tmputx; |
274 | utx = tmputx; |
266 | utx->ut_type = DEAD_PROCESS; |
275 | utx->ut_type = DEAD_PROCESS; |
|
|
276 | # if HAVE_UTMPX_SESSION |
267 | utx->ut_session = getsid (0); |
277 | utx->ut_session = getsid (0); |
|
|
278 | # endif |
268 | utx->ut_tv.tv_sec = time (NULL); |
279 | utx->ut_tv.tv_sec = time (NULL); |
269 | utx->ut_tv.tv_usec = 0; |
280 | utx->ut_tv.tv_usec = 0; |
270 | #endif |
281 | #endif |
271 | |
282 | |
272 | /* |
283 | /* |
273 | * Write ending wtmp entry |
284 | * Write ending wtmp entry |
274 | */ |
285 | */ |
275 | #ifdef WTMP_SUPPORT |
286 | #ifdef WTMP_SUPPORT |
276 | # ifdef WTMP_ONLY_ON_LOGIN |
287 | # ifdef WTMP_ONLY_ON_LOGIN |
277 | if (options & Opt_loginShell) |
288 | if (OPTION (Opt_loginShell)) |
278 | # endif |
289 | # endif |
279 | { |
290 | { |
280 | # ifdef HAVE_STRUCT_UTMP |
291 | # ifdef HAVE_STRUCT_UTMP |
281 | # ifdef HAVE_UPDWTMP |
292 | # ifdef HAVE_UPDWTMP |
282 | updwtmp (RXVT_WTMP_FILE, ut); |
293 | updwtmp (RXVT_WTMP_FILE, ut); |
283 | # else |
294 | # else |
284 | rxvt_update_wtmp (RXVT_WTMP_FILE, ut); |
295 | rxvt_update_wtmp (RXVT_WTMP_FILE, ut); |
285 | # endif |
296 | # endif |
286 | # endif |
297 | # endif |
287 | # ifdef HAVE_STRUCT_UTMPX |
298 | # ifdef HAVE_STRUCT_UTMPX |
|
|
299 | # if HAVE_UPDWTMPX |
288 | updwtmpx (RXVT_WTMPX_FILE, utx); |
300 | updwtmpx (RXVT_WTMPX_FILE, utx); |
|
|
301 | # else |
|
|
302 | pututxline (utx); |
|
|
303 | # endif |
289 | # endif |
304 | # endif |
290 | } |
305 | } |
291 | #endif |
306 | #endif |
292 | |
307 | |
293 | /* |
308 | /* |
… | |
… | |
313 | /* ------------------------------------------------------------------------- */ |
328 | /* ------------------------------------------------------------------------- */ |
314 | /* |
329 | /* |
315 | * Write a BSD style utmp entry |
330 | * Write a BSD style utmp entry |
316 | */ |
331 | */ |
317 | #ifdef HAVE_UTMP_H |
332 | #ifdef HAVE_UTMP_H |
318 | /* INTPROTO */ |
|
|
319 | int |
333 | int |
320 | rxvt_write_bsd_utmp (int utmp_pos, struct utmp *wu) |
334 | rxvt_write_bsd_utmp (int utmp_pos, struct utmp *wu) |
321 | { |
335 | { |
322 | int fd; |
336 | int fd; |
323 | |
337 | |
… | |
… | |
333 | |
347 | |
334 | /* ------------------------------------------------------------------------- */ |
348 | /* ------------------------------------------------------------------------- */ |
335 | /* |
349 | /* |
336 | * Update a BSD style wtmp entry |
350 | * Update a BSD style wtmp entry |
337 | */ |
351 | */ |
338 | #if defined(WTMP_SUPPORT) && !defined(HAVE_UPDWTMP) |
352 | #if defined(WTMP_SUPPORT) && !defined(HAVE_UPDWTMP) && defined(HAVE_STRUCT_UTMP) |
339 | /* INTPROTO */ |
|
|
340 | void |
353 | void |
341 | rxvt_update_wtmp (const char *fname, const struct utmp *putmp) |
354 | rxvt_update_wtmp (const char *fname, const struct utmp *putmp) |
342 | { |
355 | { |
343 | int fd, gotlock, retry; |
356 | int fd, gotlock, retry; |
344 | struct flock lck; /* fcntl locking scheme */ |
357 | struct flock lck; /* fcntl locking scheme */ |
… | |
… | |
376 | } |
389 | } |
377 | #endif |
390 | #endif |
378 | |
391 | |
379 | /* ------------------------------------------------------------------------- */ |
392 | /* ------------------------------------------------------------------------- */ |
380 | #ifdef LASTLOG_SUPPORT |
393 | #ifdef LASTLOG_SUPPORT |
381 | /* INTPROTO */ |
|
|
382 | void |
394 | void |
383 | rxvt_update_lastlog (const char *fname, const char *pty, const char *host) |
395 | rxvt_update_lastlog (const char *fname, const char *pty, const char *host) |
384 | { |
396 | { |
385 | # ifdef HAVE_STRUCT_LASTLOGX |
397 | # ifdef HAVE_STRUCT_LASTLOGX |
386 | struct lastlogx llx; |
398 | struct lastlogx llx; |