… | |
… | |
44 | #include "logging.h" |
44 | #include "logging.h" |
45 | |
45 | |
46 | #ifdef UTMP_SUPPORT |
46 | #ifdef UTMP_SUPPORT |
47 | |
47 | |
48 | #if HAVE_STRUCT_UTMP |
48 | #if HAVE_STRUCT_UTMP |
49 | int rxvt_write_bsd_utmp (int utmp_pos, struct utmp *wu); |
49 | static int rxvt_write_bsd_utmp (int utmp_pos, struct utmp *wu); |
50 | void rxvt_update_wtmp (const char *fname, const struct utmp *putmp); |
50 | static void rxvt_update_wtmp (const char *fname, const struct utmp *putmp); |
51 | #endif |
51 | #endif |
52 | |
52 | |
53 | void rxvt_update_lastlog (const char *fname, const char *pty, const char *host); |
53 | static void rxvt_update_lastlog (const char *fname, const char *pty, const char *host); |
54 | |
54 | |
55 | /* |
55 | /* |
56 | * BSD style utmp entry |
56 | * BSD style utmp entry |
57 | * ut_line, ut_name, ut_host, ut_time |
57 | * ut_line, ut_name, ut_host, ut_time |
58 | * SYSV style utmp (and utmpx) entry |
58 | * SYSV style utmp (and utmpx) entry |
… | |
… | |
71 | struct utmp *ut = &this->ut; |
71 | struct utmp *ut = &this->ut; |
72 | #endif |
72 | #endif |
73 | #ifdef HAVE_STRUCT_UTMPX |
73 | #ifdef HAVE_STRUCT_UTMPX |
74 | struct utmpx *utx = &this->utx; |
74 | struct utmpx *utx = &this->utx; |
75 | #endif |
75 | #endif |
76 | #ifdef HAVE_UTMP_PID |
|
|
77 | int i; |
76 | int i; |
78 | #endif |
|
|
79 | struct passwd *pwent = getpwuid (getuid ()); |
77 | struct passwd *pwent = getpwuid (getuid ()); |
80 | |
78 | |
81 | if (!strncmp (pty, "/dev/", 5)) |
79 | if (!strncmp (pty, "/dev/", 5)) |
82 | pty += 5; /* skip /dev/ prefix */ |
80 | pty += 5; /* skip /dev/ prefix */ |
83 | |
81 | |
84 | #ifdef HAVE_UTMP_PID |
82 | #if defined(HAVE_UTMP_PID) || defined(HAVE_STRUCT_UTMPX) |
85 | if (!strncmp (pty, "pty", 3) || !strncmp (pty, "tty", 3)) |
83 | if (!strncmp (pty, "pty", 3) || !strncmp (pty, "tty", 3)) |
86 | strncpy (ut_id, pty + 3, sizeof (ut_id)); |
84 | strncpy (ut_id, pty + 3, sizeof (ut_id)); |
87 | else if (sscanf (pty, "pts/%d", &i) == 1) |
85 | else if (sscanf (pty, "pts/%d", &i) == 1) |
88 | sprintf (ut_id, "vt%02x", (i & 0xff)); /* sysv naming */ |
86 | sprintf (ut_id, "vt%02x", (i & 0xff)); /* sysv naming */ |
89 | else if (strncmp (pty, "pty", 3) && strncmp (pty, "tty", 3)) |
87 | else if (strncmp (pty, "pty", 3) && strncmp (pty, "tty", 3)) |
… | |
… | |
98 | # ifdef HAVE_UTMP_PID |
96 | # ifdef HAVE_UTMP_PID |
99 | setutent (); |
97 | setutent (); |
100 | strncpy (ut->ut_id, ut_id, sizeof (ut->ut_id)); |
98 | strncpy (ut->ut_id, ut_id, sizeof (ut->ut_id)); |
101 | ut->ut_type = DEAD_PROCESS; |
99 | ut->ut_type = DEAD_PROCESS; |
102 | getutid (ut); /* position to entry in utmp file */ |
100 | getutid (ut); /* position to entry in utmp file */ |
103 | strncpy (ut_id, ut_id, sizeof (ut_id)); |
101 | strncpy (this->ut_id, ut_id, sizeof (this->ut_id)); |
104 | # endif |
102 | # endif |
105 | #endif |
103 | #endif |
106 | |
104 | |
107 | #ifdef HAVE_STRUCT_UTMPX |
105 | #ifdef HAVE_STRUCT_UTMPX |
108 | memset (utx, 0, sizeof (struct utmpx)); |
106 | memset (utx, 0, sizeof (struct utmpx)); |
109 | setutxent (); |
107 | setutxent (); |
110 | strncpy (utx->ut_id, ut_id, sizeof (utx->ut_id)); |
108 | strncpy (utx->ut_id, ut_id, sizeof (utx->ut_id)); |
111 | utx->ut_type = DEAD_PROCESS; |
109 | utx->ut_type = DEAD_PROCESS; |
112 | getutxid (utx); /* position to entry in utmp file */ |
110 | getutxid (utx); /* position to entry in utmp file */ |
113 | strncpy (ut_id, ut_id, sizeof (ut_id)); |
111 | strncpy (this->ut_id, ut_id, sizeof (this->ut_id)); |
114 | #endif |
112 | #endif |
115 | |
113 | |
116 | #ifdef HAVE_STRUCT_UTMP |
114 | #ifdef HAVE_STRUCT_UTMP |
117 | strncpy (ut->ut_line, pty, sizeof (ut->ut_line)); |
115 | strncpy (ut->ut_line, pty, sizeof (ut->ut_line)); |
118 | ut->ut_time = time (NULL); |
116 | ut->ut_time = time (NULL); |
… | |
… | |
167 | #endif |
165 | #endif |
168 | |
166 | |
169 | #if defined(HAVE_STRUCT_UTMP) && !defined(HAVE_UTMP_PID) |
167 | #if defined(HAVE_STRUCT_UTMP) && !defined(HAVE_UTMP_PID) |
170 | |
168 | |
171 | { |
169 | { |
172 | int i; |
|
|
173 | # ifdef HAVE_TTYSLOT |
170 | # ifdef HAVE_TTYSLOT |
174 | i = ttyslot (); |
171 | i = ttyslot (); |
175 | if (rxvt_write_bsd_utmp (i, ut)) |
172 | if (rxvt_write_bsd_utmp (i, ut)) |
176 | utmp_pos = i; |
173 | utmp_pos = i; |
177 | # else |
174 | # else |
… | |
… | |
246 | |
243 | |
247 | #ifdef HAVE_STRUCT_UTMP |
244 | #ifdef HAVE_STRUCT_UTMP |
248 | # ifdef HAVE_UTMP_PID |
245 | # ifdef HAVE_UTMP_PID |
249 | memset (ut, 0, sizeof (struct utmp)); |
246 | memset (ut, 0, sizeof (struct utmp)); |
250 | setutent (); |
247 | setutent (); |
251 | strncpy (ut->ut_id, ut_id, sizeof (ut->ut_id)); |
248 | strncpy (ut->ut_id, this->ut_id, sizeof (ut->ut_id)); |
252 | ut->ut_type = USER_PROCESS; |
249 | ut->ut_type = USER_PROCESS; |
253 | { |
250 | { |
254 | struct utmp *tmput = getutid (ut); |
251 | struct utmp *tmput = getutid (ut); |
255 | |
252 | |
256 | if (tmput) /* position to entry in utmp file */ |
253 | if (tmput) /* position to entry in utmp file */ |
… | |
… | |
267 | #endif |
264 | #endif |
268 | |
265 | |
269 | #ifdef HAVE_STRUCT_UTMPX |
266 | #ifdef HAVE_STRUCT_UTMPX |
270 | memset (utx, 0, sizeof (struct utmpx)); |
267 | memset (utx, 0, sizeof (struct utmpx)); |
271 | setutxent (); |
268 | setutxent (); |
272 | strncpy (utx->ut_id, ut_id, sizeof (utx->ut_id)); |
269 | strncpy (utx->ut_id, this->ut_id, sizeof (utx->ut_id)); |
273 | utx->ut_type = USER_PROCESS; |
270 | utx->ut_type = USER_PROCESS; |
274 | if ((tmputx = getutxid (utx))) /* position to entry in utmp file */ |
271 | if ((tmputx = getutxid (utx))) /* position to entry in utmp file */ |
275 | utx = tmputx; |
272 | utx = tmputx; |
276 | utx->ut_type = DEAD_PROCESS; |
273 | utx->ut_type = DEAD_PROCESS; |
277 | # if HAVE_UTMPX_SESSION |
274 | # if HAVE_UTMPX_SESSION |
… | |
… | |
328 | |
325 | |
329 | /* ------------------------------------------------------------------------- */ |
326 | /* ------------------------------------------------------------------------- */ |
330 | /* |
327 | /* |
331 | * Write a BSD style utmp entry |
328 | * Write a BSD style utmp entry |
332 | */ |
329 | */ |
333 | #ifdef HAVE_UTMP_H |
330 | #if defined(HAVE_STRUCT_UTMP) && !defined(HAVE_UTMP_PID) |
334 | int |
331 | static int |
335 | rxvt_write_bsd_utmp (int utmp_pos, struct utmp *wu) |
332 | rxvt_write_bsd_utmp (int utmp_pos, struct utmp *wu) |
336 | { |
333 | { |
337 | int fd; |
334 | int fd; |
338 | |
335 | |
339 | if (utmp_pos <= 0 || (fd = open (RXVT_UTMP_FILE, O_WRONLY)) == -1) |
336 | if (utmp_pos <= 0 || (fd = open (RXVT_UTMP_FILE, O_WRONLY)) == -1) |
… | |
… | |
349 | /* ------------------------------------------------------------------------- */ |
346 | /* ------------------------------------------------------------------------- */ |
350 | /* |
347 | /* |
351 | * Update a BSD style wtmp entry |
348 | * Update a BSD style wtmp entry |
352 | */ |
349 | */ |
353 | #if defined(WTMP_SUPPORT) && !defined(HAVE_UPDWTMP) && defined(HAVE_STRUCT_UTMP) |
350 | #if defined(WTMP_SUPPORT) && !defined(HAVE_UPDWTMP) && defined(HAVE_STRUCT_UTMP) |
354 | void |
351 | static void |
355 | rxvt_update_wtmp (const char *fname, const struct utmp *putmp) |
352 | rxvt_update_wtmp (const char *fname, const struct utmp *putmp) |
356 | { |
353 | { |
357 | int fd, gotlock, retry; |
354 | int fd, gotlock, retry; |
358 | struct flock lck; /* fcntl locking scheme */ |
355 | struct flock lck; /* fcntl locking scheme */ |
359 | struct stat sbuf; |
356 | struct stat sbuf; |
… | |
… | |
390 | } |
387 | } |
391 | #endif |
388 | #endif |
392 | |
389 | |
393 | /* ------------------------------------------------------------------------- */ |
390 | /* ------------------------------------------------------------------------- */ |
394 | #ifdef LASTLOG_SUPPORT |
391 | #ifdef LASTLOG_SUPPORT |
395 | void |
392 | static void |
396 | rxvt_update_lastlog (const char *fname, const char *pty, const char *host) |
393 | rxvt_update_lastlog (const char *fname, const char *pty, const char *host) |
397 | { |
394 | { |
398 | # ifdef HAVE_STRUCT_LASTLOGX |
395 | # ifdef HAVE_STRUCT_LASTLOGX |
399 | struct lastlogx llx; |
396 | struct lastlogx llx; |
400 | # endif |
397 | # endif |