… | |
… | |
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 |
… | |
… | |
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 | struct passwd *pwent = getpwuid (getuid ()); |
78 | struct passwd *pwent = getpwuid (getuid ()); |
72 | |
79 | |
73 | if (!strncmp (pty, "/dev/", 5)) |
80 | if (!strncmp (pty, "/dev/", 5)) |
74 | pty += 5; /* skip /dev/ prefix */ |
81 | pty += 5; /* skip /dev/ prefix */ |
75 | |
82 | |
|
|
83 | #ifdef HAVE_UTMP_PID |
76 | if (!strncmp (pty, "pty", 3) || !strncmp (pty, "tty", 3)) |
84 | if (!strncmp (pty, "pty", 3) || !strncmp (pty, "tty", 3)) |
77 | strncpy (ut_id, (pty + 3), sizeof (ut_id)); |
85 | strncpy (ut_id, pty + 3, sizeof (ut_id)); |
78 | #ifdef HAVE_UTMP_PID |
|
|
79 | else if (sscanf (pty, "pts/%d", &i) == 1) |
86 | else if (sscanf (pty, "pts/%d", &i) == 1) |
80 | sprintf (ut_id, "vt%02x", (i & 0xff)); /* sysv naming */ |
87 | sprintf (ut_id, "vt%02x", (i & 0xff)); /* sysv naming */ |
81 | #endif |
|
|
82 | else if (strncmp (pty, "pty", 3) && strncmp (pty, "tty", 3)) |
88 | else if (strncmp (pty, "pty", 3) && strncmp (pty, "tty", 3)) |
83 | { |
89 | { |
84 | 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); |
85 | return; |
91 | return; |
86 | } |
92 | } |
|
|
93 | #endif |
87 | |
94 | |
88 | #ifdef HAVE_STRUCT_UTMP |
95 | #ifdef HAVE_STRUCT_UTMP |
89 | memset (ut, 0, sizeof (struct utmp)); |
96 | memset (ut, 0, sizeof (struct utmp)); |
90 | # ifdef HAVE_UTMP_PID |
97 | # ifdef HAVE_UTMP_PID |
91 | setutent (); |
98 | setutent (); |
… | |
… | |
133 | #ifdef HAVE_STRUCT_UTMPX |
140 | #ifdef HAVE_STRUCT_UTMPX |
134 | strncpy (utx->ut_line, pty, sizeof (utx->ut_line)); |
141 | strncpy (utx->ut_line, pty, sizeof (utx->ut_line)); |
135 | strncpy (utx->ut_user, (pwent && pwent->pw_name) ? pwent->pw_name : "?", |
142 | strncpy (utx->ut_user, (pwent && pwent->pw_name) ? pwent->pw_name : "?", |
136 | sizeof (utx->ut_user)); |
143 | sizeof (utx->ut_user)); |
137 | 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 |
138 | utx->ut_session = getsid (0); |
146 | utx->ut_session = getsid (0); |
|
|
147 | # endif |
139 | utx->ut_tv.tv_sec = time (NULL); |
148 | utx->ut_tv.tv_sec = time (NULL); |
140 | utx->ut_tv.tv_usec = 0; |
149 | utx->ut_tv.tv_usec = 0; |
141 | utx->ut_pid = cmd_pid; |
150 | utx->ut_pid = cmd_pid; |
142 | # ifdef HAVE_UTMPX_HOST |
151 | # ifdef HAVE_UTMPX_HOST |
143 | strncpy (utx->ut_host, hostname, sizeof (utx->ut_host)); |
152 | strncpy (utx->ut_host, hostname, sizeof (utx->ut_host)); |
… | |
… | |
167 | # else |
176 | # else |
168 | FILE *fd0; |
177 | FILE *fd0; |
169 | |
178 | |
170 | if ((fd0 = fopen (TTYTAB_FILENAME, "r")) != NULL) |
179 | if ((fd0 = fopen (TTYTAB_FILENAME, "r")) != NULL) |
171 | { |
180 | { |
172 | char buf[256], name[256]; |
181 | char buf[256], name[256]; |
173 | |
182 | |
174 | buf[sizeof (buf) - 1] = '\0'; |
183 | buf[sizeof (buf) - 1] = '\0'; |
175 | for (i = 1; (fgets (buf, sizeof (buf) - 1, fd0) != NULL);) |
184 | for (i = 1; (fgets (buf, sizeof (buf) - 1, fd0) != NULL);) |
176 | { |
185 | { |
177 | if (*buf == '#' || sscanf (buf, "%s", name) != 1) |
186 | if (*buf == '#' || sscanf (buf, "%s", name) != 1) |
… | |
… | |
204 | # else |
213 | # else |
205 | rxvt_update_wtmp (RXVT_WTMP_FILE, ut); |
214 | rxvt_update_wtmp (RXVT_WTMP_FILE, ut); |
206 | # endif |
215 | # endif |
207 | # endif |
216 | # endif |
208 | # ifdef HAVE_STRUCT_UTMPX |
217 | # ifdef HAVE_STRUCT_UTMPX |
|
|
218 | # if HAVE_UPDWTMPX |
209 | updwtmpx (RXVT_WTMPX_FILE, utx); |
219 | updwtmpx (RXVT_WTMPX_FILE, utx); |
|
|
220 | # else |
|
|
221 | pututxline (utx); |
|
|
222 | # endif |
210 | # endif |
223 | # endif |
211 | } |
224 | } |
212 | #endif |
225 | #endif |
213 | #if defined(LASTLOG_SUPPORT) && defined(RXVT_LASTLOG_FILE) |
226 | #if defined(LASTLOG_SUPPORT) && defined(RXVT_LASTLOG_FILE) |
214 | if (options & Opt_loginShell) |
227 | if (options & Opt_loginShell) |
… | |
… | |
258 | strncpy (utx->ut_id, ut_id, sizeof (utx->ut_id)); |
271 | strncpy (utx->ut_id, ut_id, sizeof (utx->ut_id)); |
259 | utx->ut_type = USER_PROCESS; |
272 | utx->ut_type = USER_PROCESS; |
260 | if ((tmputx = getutxid (utx))) /* position to entry in utmp file */ |
273 | if ((tmputx = getutxid (utx))) /* position to entry in utmp file */ |
261 | utx = tmputx; |
274 | utx = tmputx; |
262 | utx->ut_type = DEAD_PROCESS; |
275 | utx->ut_type = DEAD_PROCESS; |
|
|
276 | # if HAVE_UTMPX_SESSION |
263 | utx->ut_session = getsid (0); |
277 | utx->ut_session = getsid (0); |
|
|
278 | # endif |
264 | utx->ut_tv.tv_sec = time (NULL); |
279 | utx->ut_tv.tv_sec = time (NULL); |
265 | utx->ut_tv.tv_usec = 0; |
280 | utx->ut_tv.tv_usec = 0; |
266 | #endif |
281 | #endif |
267 | |
282 | |
268 | /* |
283 | /* |
… | |
… | |
279 | # else |
294 | # else |
280 | rxvt_update_wtmp (RXVT_WTMP_FILE, ut); |
295 | rxvt_update_wtmp (RXVT_WTMP_FILE, ut); |
281 | # endif |
296 | # endif |
282 | # endif |
297 | # endif |
283 | # ifdef HAVE_STRUCT_UTMPX |
298 | # ifdef HAVE_STRUCT_UTMPX |
|
|
299 | # if HAVE_UPDWTMPX |
284 | updwtmpx (RXVT_WTMPX_FILE, utx); |
300 | updwtmpx (RXVT_WTMPX_FILE, utx); |
|
|
301 | # else |
|
|
302 | pututxline (utx); |
|
|
303 | # endif |
285 | # endif |
304 | # endif |
286 | } |
305 | } |
287 | #endif |
306 | #endif |
288 | |
307 | |
289 | /* |
308 | /* |
… | |
… | |
309 | /* ------------------------------------------------------------------------- */ |
328 | /* ------------------------------------------------------------------------- */ |
310 | /* |
329 | /* |
311 | * Write a BSD style utmp entry |
330 | * Write a BSD style utmp entry |
312 | */ |
331 | */ |
313 | #ifdef HAVE_UTMP_H |
332 | #ifdef HAVE_UTMP_H |
314 | /* INTPROTO */ |
|
|
315 | int |
333 | int |
316 | rxvt_write_bsd_utmp (int utmp_pos, struct utmp *wu) |
334 | rxvt_write_bsd_utmp (int utmp_pos, struct utmp *wu) |
317 | { |
335 | { |
318 | int fd; |
336 | int fd; |
319 | |
337 | |
… | |
… | |
329 | |
347 | |
330 | /* ------------------------------------------------------------------------- */ |
348 | /* ------------------------------------------------------------------------- */ |
331 | /* |
349 | /* |
332 | * Update a BSD style wtmp entry |
350 | * Update a BSD style wtmp entry |
333 | */ |
351 | */ |
334 | #if defined(WTMP_SUPPORT) && !defined(HAVE_UPDWTMP) |
352 | #if defined(WTMP_SUPPORT) && !defined(HAVE_UPDWTMP) && defined(HAVE_STRUCT_UTMP) |
335 | /* INTPROTO */ |
|
|
336 | void |
353 | void |
337 | rxvt_update_wtmp (const char *fname, const struct utmp *putmp) |
354 | rxvt_update_wtmp (const char *fname, const struct utmp *putmp) |
338 | { |
355 | { |
339 | int fd, gotlock, retry; |
356 | int fd, gotlock, retry; |
340 | struct flock lck; /* fcntl locking scheme */ |
357 | struct flock lck; /* fcntl locking scheme */ |
… | |
… | |
372 | } |
389 | } |
373 | #endif |
390 | #endif |
374 | |
391 | |
375 | /* ------------------------------------------------------------------------- */ |
392 | /* ------------------------------------------------------------------------- */ |
376 | #ifdef LASTLOG_SUPPORT |
393 | #ifdef LASTLOG_SUPPORT |
377 | /* INTPROTO */ |
|
|
378 | void |
394 | void |
379 | 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) |
380 | { |
396 | { |
381 | # ifdef HAVE_STRUCT_LASTLOGX |
397 | # ifdef HAVE_STRUCT_LASTLOGX |
382 | struct lastlogx llx; |
398 | struct lastlogx llx; |