… | |
… | |
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 | 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_lastlog (const char *fname, const char *pty, const char *host); |
|
|
50 | |
47 | /* |
51 | /* |
48 | * BSD style utmp entry |
52 | * BSD style utmp entry |
49 | * ut_line, ut_name, ut_host, ut_time |
53 | * ut_line, ut_name, ut_host, ut_time |
50 | * SYSV style utmp (and utmpx) entry |
54 | * SYSV style utmp (and utmpx) entry |
51 | * ut_user, ut_id, ut_line, ut_pid, ut_type, ut_exit, ut_time |
55 | * ut_user, ut_id, ut_line, ut_pid, ut_type, ut_exit, ut_time |
… | |
… | |
58 | */ |
62 | */ |
59 | void |
63 | void |
60 | rxvt_term::makeutent (const char *pty, const char *hostname) |
64 | rxvt_term::makeutent (const char *pty, const char *hostname) |
61 | { |
65 | { |
62 | #ifdef HAVE_STRUCT_UTMP |
66 | #ifdef HAVE_STRUCT_UTMP |
63 | struct utmp *ut = & (this->ut); |
67 | struct utmp *ut = &this->ut; |
64 | #endif |
68 | #endif |
65 | #ifdef HAVE_STRUCT_UTMPX |
69 | #ifdef HAVE_STRUCT_UTMPX |
66 | struct utmpx *utx = & (this->utx); |
70 | struct utmpx *utx = &this->utx; |
67 | #endif |
71 | #endif |
68 | #ifdef HAVE_UTMP_PID |
72 | #ifdef HAVE_UTMP_PID |
69 | int i; |
73 | int i; |
70 | #endif |
74 | #endif |
71 | char ut_id[5]; |
|
|
72 | struct passwd *pwent = getpwuid (getuid ()); |
75 | struct passwd *pwent = getpwuid (getuid ()); |
73 | |
76 | |
74 | if (!strncmp (pty, "/dev/", 5)) |
77 | if (!strncmp (pty, "/dev/", 5)) |
75 | pty += 5; /* skip /dev/ prefix */ |
78 | pty += 5; /* skip /dev/ prefix */ |
76 | |
79 | |
|
|
80 | #ifdef HAVE_UTMP_PID |
77 | if (!strncmp (pty, "pty", 3) || !strncmp (pty, "tty", 3)) |
81 | if (!strncmp (pty, "pty", 3) || !strncmp (pty, "tty", 3)) |
78 | { |
|
|
79 | strncpy (ut_id, (pty + 3), sizeof (ut_id)); |
82 | strncpy (ut_id, pty + 3, sizeof (ut_id)); |
80 | } |
|
|
81 | #ifdef HAVE_UTMP_PID |
|
|
82 | else if (sscanf (pty, "pts/%d", &i) == 1) |
83 | else if (sscanf (pty, "pts/%d", &i) == 1) |
83 | sprintf (ut_id, "vt%02x", (i & 0xff)); /* sysv naming */ |
84 | sprintf (ut_id, "vt%02x", (i & 0xff)); /* sysv naming */ |
84 | #endif |
|
|
85 | else if (strncmp (pty, "pty", 3) && strncmp (pty, "tty", 3)) |
85 | else if (strncmp (pty, "pty", 3) && strncmp (pty, "tty", 3)) |
86 | { |
86 | { |
87 | rxvt_warn ("can't parse tty name \"%s\", not adding utmp entry.\n", pty); |
87 | rxvt_warn ("can't parse tty name \"%s\", not adding utmp entry.\n", pty); |
88 | return; |
88 | return; |
89 | } |
89 | } |
|
|
90 | #endif |
90 | |
91 | |
91 | #ifdef HAVE_STRUCT_UTMP |
92 | #ifdef HAVE_STRUCT_UTMP |
92 | memset (ut, 0, sizeof (struct utmp)); |
93 | memset (ut, 0, sizeof (struct utmp)); |
93 | # ifdef HAVE_UTMP_PID |
94 | # ifdef HAVE_UTMP_PID |
94 | setutent (); |
95 | setutent (); |
… | |
… | |
136 | #ifdef HAVE_STRUCT_UTMPX |
137 | #ifdef HAVE_STRUCT_UTMPX |
137 | strncpy (utx->ut_line, pty, sizeof (utx->ut_line)); |
138 | strncpy (utx->ut_line, pty, sizeof (utx->ut_line)); |
138 | strncpy (utx->ut_user, (pwent && pwent->pw_name) ? pwent->pw_name : "?", |
139 | strncpy (utx->ut_user, (pwent && pwent->pw_name) ? pwent->pw_name : "?", |
139 | sizeof (utx->ut_user)); |
140 | sizeof (utx->ut_user)); |
140 | strncpy (utx->ut_id, ut_id, sizeof (utx->ut_id)); |
141 | strncpy (utx->ut_id, ut_id, sizeof (utx->ut_id)); |
|
|
142 | # if HAVE_UTMPX_SESSION |
141 | utx->ut_session = getsid (0); |
143 | utx->ut_session = getsid (0); |
|
|
144 | # endif |
142 | utx->ut_tv.tv_sec = time (NULL); |
145 | utx->ut_tv.tv_sec = time (NULL); |
143 | utx->ut_tv.tv_usec = 0; |
146 | utx->ut_tv.tv_usec = 0; |
144 | utx->ut_pid = cmd_pid; |
147 | utx->ut_pid = cmd_pid; |
145 | # ifdef HAVE_UTMPX_HOST |
148 | # ifdef HAVE_UTMPX_HOST |
146 | strncpy (utx->ut_host, hostname, sizeof (utx->ut_host)); |
149 | strncpy (utx->ut_host, hostname, sizeof (utx->ut_host)); |
… | |
… | |
207 | # else |
210 | # else |
208 | rxvt_update_wtmp (RXVT_WTMP_FILE, ut); |
211 | rxvt_update_wtmp (RXVT_WTMP_FILE, ut); |
209 | # endif |
212 | # endif |
210 | # endif |
213 | # endif |
211 | # ifdef HAVE_STRUCT_UTMPX |
214 | # ifdef HAVE_STRUCT_UTMPX |
|
|
215 | # if HAVE_UPDWTMPX |
212 | updwtmpx (RXVT_WTMPX_FILE, utx); |
216 | updwtmpx (RXVT_WTMPX_FILE, utx); |
|
|
217 | # endif |
213 | # endif |
218 | # endif |
214 | } |
219 | } |
215 | #endif |
220 | #endif |
216 | #if defined(LASTLOG_SUPPORT) && defined(RXVT_LASTLOG_FILE) |
221 | #if defined(LASTLOG_SUPPORT) && defined(RXVT_LASTLOG_FILE) |
217 | if (options & Opt_loginShell) |
222 | if (options & Opt_loginShell) |
… | |
… | |
225 | */ |
230 | */ |
226 | void |
231 | void |
227 | rxvt_term::cleanutent () |
232 | rxvt_term::cleanutent () |
228 | { |
233 | { |
229 | #ifdef HAVE_STRUCT_UTMP |
234 | #ifdef HAVE_STRUCT_UTMP |
230 | struct utmp *ut = & (this->ut); |
235 | struct utmp *ut = &this->ut; |
231 | #endif |
236 | #endif |
232 | #ifdef HAVE_STRUCT_UTMPX |
237 | #ifdef HAVE_STRUCT_UTMPX |
233 | struct utmpx *tmputx, *utx = & (this->utx); |
238 | struct utmpx *tmputx, *utx = &this->utx; |
234 | #endif |
239 | #endif |
235 | |
240 | |
236 | #ifdef HAVE_STRUCT_UTMP |
241 | #ifdef HAVE_STRUCT_UTMP |
237 | # ifdef HAVE_UTMP_PID |
242 | # ifdef HAVE_UTMP_PID |
238 | memset (ut, 0, sizeof (struct utmp)); |
243 | memset (ut, 0, sizeof (struct utmp)); |
… | |
… | |
261 | strncpy (utx->ut_id, ut_id, sizeof (utx->ut_id)); |
266 | strncpy (utx->ut_id, ut_id, sizeof (utx->ut_id)); |
262 | utx->ut_type = USER_PROCESS; |
267 | utx->ut_type = USER_PROCESS; |
263 | if ((tmputx = getutxid (utx))) /* position to entry in utmp file */ |
268 | if ((tmputx = getutxid (utx))) /* position to entry in utmp file */ |
264 | utx = tmputx; |
269 | utx = tmputx; |
265 | utx->ut_type = DEAD_PROCESS; |
270 | utx->ut_type = DEAD_PROCESS; |
|
|
271 | # if HAVE_UTMPX_SESSION |
266 | utx->ut_session = getsid (0); |
272 | utx->ut_session = getsid (0); |
|
|
273 | # endif |
267 | utx->ut_tv.tv_sec = time (NULL); |
274 | utx->ut_tv.tv_sec = time (NULL); |
268 | utx->ut_tv.tv_usec = 0; |
275 | utx->ut_tv.tv_usec = 0; |
269 | #endif |
276 | #endif |
270 | |
277 | |
271 | /* |
278 | /* |
… | |
… | |
282 | # else |
289 | # else |
283 | rxvt_update_wtmp (RXVT_WTMP_FILE, ut); |
290 | rxvt_update_wtmp (RXVT_WTMP_FILE, ut); |
284 | # endif |
291 | # endif |
285 | # endif |
292 | # endif |
286 | # ifdef HAVE_STRUCT_UTMPX |
293 | # ifdef HAVE_STRUCT_UTMPX |
|
|
294 | # if HAVE_UPDWTMPX |
287 | updwtmpx (RXVT_WTMPX_FILE, utx); |
295 | updwtmpx (RXVT_WTMPX_FILE, utx); |
|
|
296 | # endif |
288 | # endif |
297 | # endif |
289 | } |
298 | } |
290 | #endif |
299 | #endif |
291 | |
300 | |
292 | /* |
301 | /* |