… | |
… | |
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 |
|
|
48 | int rxvt_write_bsd_utmp (int utmp_pos, struct utmp *wu); |
|
|
49 | void rxvt_update_wtmp (const char *fname, const struct utmp *putmp); |
|
|
50 | #endif |
|
|
51 | |
|
|
52 | void rxvt_update_lastlog (const char *fname, const char *pty, const char *host); |
|
|
53 | |
47 | /* |
54 | /* |
48 | * BSD style utmp entry |
55 | * BSD style utmp entry |
49 | * ut_line, ut_name, ut_host, ut_time |
56 | * ut_line, ut_name, ut_host, ut_time |
50 | * SYSV style utmp (and utmpx) entry |
57 | * SYSV style utmp (and utmpx) entry |
51 | * ut_user, ut_id, ut_line, ut_pid, ut_type, ut_exit, ut_time |
58 | * ut_user, ut_id, ut_line, ut_pid, ut_type, ut_exit, ut_time |
… | |
… | |
58 | */ |
65 | */ |
59 | void |
66 | void |
60 | rxvt_term::makeutent (const char *pty, const char *hostname) |
67 | rxvt_term::makeutent (const char *pty, const char *hostname) |
61 | { |
68 | { |
62 | #ifdef HAVE_STRUCT_UTMP |
69 | #ifdef HAVE_STRUCT_UTMP |
63 | struct utmp *ut = & (this->ut); |
70 | struct utmp *ut = &this->ut; |
64 | #endif |
71 | #endif |
65 | #ifdef HAVE_STRUCT_UTMPX |
72 | #ifdef HAVE_STRUCT_UTMPX |
66 | struct utmpx *utx = & (this->utx); |
73 | struct utmpx *utx = &this->utx; |
67 | #endif |
74 | #endif |
68 | #ifdef HAVE_UTMP_PID |
75 | #ifdef HAVE_UTMP_PID |
69 | int i; |
76 | int i; |
70 | #endif |
77 | #endif |
71 | char ut_id[5]; |
|
|
72 | struct passwd *pwent = getpwuid (getuid ()); |
78 | struct passwd *pwent = getpwuid (getuid ()); |
73 | |
79 | |
74 | if (!strncmp (pty, "/dev/", 5)) |
80 | if (!strncmp (pty, "/dev/", 5)) |
75 | pty += 5; /* skip /dev/ prefix */ |
81 | pty += 5; /* skip /dev/ prefix */ |
76 | |
82 | |
|
|
83 | #ifdef HAVE_UTMP_PID |
77 | if (!strncmp (pty, "pty", 3) || !strncmp (pty, "tty", 3)) |
84 | if (!strncmp (pty, "pty", 3) || !strncmp (pty, "tty", 3)) |
78 | { |
|
|
79 | strncpy (ut_id, (pty + 3), sizeof (ut_id)); |
85 | strncpy (ut_id, pty + 3, sizeof (ut_id)); |
80 | } |
|
|
81 | #ifdef HAVE_UTMP_PID |
|
|
82 | else if (sscanf (pty, "pts/%d", &i) == 1) |
86 | else if (sscanf (pty, "pts/%d", &i) == 1) |
83 | sprintf (ut_id, "vt%02x", (i & 0xff)); /* sysv naming */ |
87 | sprintf (ut_id, "vt%02x", (i & 0xff)); /* sysv naming */ |
84 | #endif |
|
|
85 | else if (strncmp (pty, "pty", 3) && strncmp (pty, "tty", 3)) |
88 | else if (strncmp (pty, "pty", 3) && strncmp (pty, "tty", 3)) |
86 | { |
89 | { |
87 | rxvt_warn ("can't parse tty name \"%s\", not adding utmp entry.\n", pty); |
90 | rxvt_warn ("can't parse tty name \"%s\", not adding utmp entry.\n", pty); |
88 | return; |
91 | return; |
89 | } |
92 | } |
|
|
93 | #endif |
90 | |
94 | |
91 | #ifdef HAVE_STRUCT_UTMP |
95 | #ifdef HAVE_STRUCT_UTMP |
92 | memset (ut, 0, sizeof (struct utmp)); |
96 | memset (ut, 0, sizeof (struct utmp)); |
93 | # ifdef HAVE_UTMP_PID |
97 | # ifdef HAVE_UTMP_PID |
94 | setutent (); |
98 | setutent (); |
… | |
… | |
136 | #ifdef HAVE_STRUCT_UTMPX |
140 | #ifdef HAVE_STRUCT_UTMPX |
137 | strncpy (utx->ut_line, pty, sizeof (utx->ut_line)); |
141 | strncpy (utx->ut_line, pty, sizeof (utx->ut_line)); |
138 | strncpy (utx->ut_user, (pwent && pwent->pw_name) ? pwent->pw_name : "?", |
142 | strncpy (utx->ut_user, (pwent && pwent->pw_name) ? pwent->pw_name : "?", |
139 | sizeof (utx->ut_user)); |
143 | sizeof (utx->ut_user)); |
140 | 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 |
141 | utx->ut_session = getsid (0); |
146 | utx->ut_session = getsid (0); |
|
|
147 | # endif |
142 | utx->ut_tv.tv_sec = time (NULL); |
148 | utx->ut_tv.tv_sec = time (NULL); |
143 | utx->ut_tv.tv_usec = 0; |
149 | utx->ut_tv.tv_usec = 0; |
144 | utx->ut_pid = cmd_pid; |
150 | utx->ut_pid = cmd_pid; |
145 | # ifdef HAVE_UTMPX_HOST |
151 | # ifdef HAVE_UTMPX_HOST |
146 | strncpy (utx->ut_host, hostname, sizeof (utx->ut_host)); |
152 | strncpy (utx->ut_host, hostname, sizeof (utx->ut_host)); |
… | |
… | |
207 | # else |
213 | # else |
208 | rxvt_update_wtmp (RXVT_WTMP_FILE, ut); |
214 | rxvt_update_wtmp (RXVT_WTMP_FILE, ut); |
209 | # endif |
215 | # endif |
210 | # endif |
216 | # endif |
211 | # ifdef HAVE_STRUCT_UTMPX |
217 | # ifdef HAVE_STRUCT_UTMPX |
|
|
218 | # if HAVE_UPDWTMPX |
212 | updwtmpx (RXVT_WTMPX_FILE, utx); |
219 | updwtmpx (RXVT_WTMPX_FILE, utx); |
|
|
220 | # else |
|
|
221 | pututxline (utx); |
|
|
222 | # endif |
213 | # endif |
223 | # endif |
214 | } |
224 | } |
215 | #endif |
225 | #endif |
216 | #if defined(LASTLOG_SUPPORT) && defined(RXVT_LASTLOG_FILE) |
226 | #if defined(LASTLOG_SUPPORT) && defined(RXVT_LASTLOG_FILE) |
217 | if (options & Opt_loginShell) |
227 | if (options & Opt_loginShell) |
… | |
… | |
225 | */ |
235 | */ |
226 | void |
236 | void |
227 | rxvt_term::cleanutent () |
237 | rxvt_term::cleanutent () |
228 | { |
238 | { |
229 | #ifdef HAVE_STRUCT_UTMP |
239 | #ifdef HAVE_STRUCT_UTMP |
230 | struct utmp *ut = & (this->ut); |
240 | struct utmp *ut = &this->ut; |
231 | #endif |
241 | #endif |
232 | #ifdef HAVE_STRUCT_UTMPX |
242 | #ifdef HAVE_STRUCT_UTMPX |
233 | struct utmpx *tmputx, *utx = & (this->utx); |
243 | struct utmpx *tmputx, *utx = &this->utx; |
234 | #endif |
244 | #endif |
235 | |
245 | |
236 | #ifdef HAVE_STRUCT_UTMP |
246 | #ifdef HAVE_STRUCT_UTMP |
237 | # ifdef HAVE_UTMP_PID |
247 | # ifdef HAVE_UTMP_PID |
238 | memset (ut, 0, sizeof (struct utmp)); |
248 | memset (ut, 0, sizeof (struct utmp)); |
… | |
… | |
261 | strncpy (utx->ut_id, ut_id, sizeof (utx->ut_id)); |
271 | strncpy (utx->ut_id, ut_id, sizeof (utx->ut_id)); |
262 | utx->ut_type = USER_PROCESS; |
272 | utx->ut_type = USER_PROCESS; |
263 | if ((tmputx = getutxid (utx))) /* position to entry in utmp file */ |
273 | if ((tmputx = getutxid (utx))) /* position to entry in utmp file */ |
264 | utx = tmputx; |
274 | utx = tmputx; |
265 | utx->ut_type = DEAD_PROCESS; |
275 | utx->ut_type = DEAD_PROCESS; |
|
|
276 | # if HAVE_UTMPX_SESSION |
266 | utx->ut_session = getsid (0); |
277 | utx->ut_session = getsid (0); |
|
|
278 | # endif |
267 | utx->ut_tv.tv_sec = time (NULL); |
279 | utx->ut_tv.tv_sec = time (NULL); |
268 | utx->ut_tv.tv_usec = 0; |
280 | utx->ut_tv.tv_usec = 0; |
269 | #endif |
281 | #endif |
270 | |
282 | |
271 | /* |
283 | /* |
… | |
… | |
282 | # else |
294 | # else |
283 | rxvt_update_wtmp (RXVT_WTMP_FILE, ut); |
295 | rxvt_update_wtmp (RXVT_WTMP_FILE, ut); |
284 | # endif |
296 | # endif |
285 | # endif |
297 | # endif |
286 | # ifdef HAVE_STRUCT_UTMPX |
298 | # ifdef HAVE_STRUCT_UTMPX |
|
|
299 | # if HAVE_UPDWTMPX |
287 | updwtmpx (RXVT_WTMPX_FILE, utx); |
300 | updwtmpx (RXVT_WTMPX_FILE, utx); |
|
|
301 | # else |
|
|
302 | pututxline (utx); |
|
|
303 | # endif |
288 | # endif |
304 | # endif |
289 | } |
305 | } |
290 | #endif |
306 | #endif |
291 | |
307 | |
292 | /* |
308 | /* |
… | |
… | |
312 | /* ------------------------------------------------------------------------- */ |
328 | /* ------------------------------------------------------------------------- */ |
313 | /* |
329 | /* |
314 | * Write a BSD style utmp entry |
330 | * Write a BSD style utmp entry |
315 | */ |
331 | */ |
316 | #ifdef HAVE_UTMP_H |
332 | #ifdef HAVE_UTMP_H |
317 | /* INTPROTO */ |
|
|
318 | int |
333 | int |
319 | rxvt_write_bsd_utmp (int utmp_pos, struct utmp *wu) |
334 | rxvt_write_bsd_utmp (int utmp_pos, struct utmp *wu) |
320 | { |
335 | { |
321 | int fd; |
336 | int fd; |
322 | |
337 | |
… | |
… | |
332 | |
347 | |
333 | /* ------------------------------------------------------------------------- */ |
348 | /* ------------------------------------------------------------------------- */ |
334 | /* |
349 | /* |
335 | * Update a BSD style wtmp entry |
350 | * Update a BSD style wtmp entry |
336 | */ |
351 | */ |
337 | #if defined(WTMP_SUPPORT) && !defined(HAVE_UPDWTMP) |
352 | #if defined(WTMP_SUPPORT) && !defined(HAVE_UPDWTMP) && defined(HAVE_STRUCT_UTMP) |
338 | /* INTPROTO */ |
|
|
339 | void |
353 | void |
340 | rxvt_update_wtmp (const char *fname, const struct utmp *putmp) |
354 | rxvt_update_wtmp (const char *fname, const struct utmp *putmp) |
341 | { |
355 | { |
342 | int fd, gotlock, retry; |
356 | int fd, gotlock, retry; |
343 | struct flock lck; /* fcntl locking scheme */ |
357 | struct flock lck; /* fcntl locking scheme */ |
… | |
… | |
375 | } |
389 | } |
376 | #endif |
390 | #endif |
377 | |
391 | |
378 | /* ------------------------------------------------------------------------- */ |
392 | /* ------------------------------------------------------------------------- */ |
379 | #ifdef LASTLOG_SUPPORT |
393 | #ifdef LASTLOG_SUPPORT |
380 | /* INTPROTO */ |
|
|
381 | void |
394 | void |
382 | 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) |
383 | { |
396 | { |
384 | # ifdef HAVE_STRUCT_LASTLOGX |
397 | # ifdef HAVE_STRUCT_LASTLOGX |
385 | struct lastlogx llx; |
398 | struct lastlogx llx; |