… | |
… | |
28 | * |
28 | * |
29 | * You should have received a copy of the GNU General Public License |
29 | * You should have received a copy of the GNU General Public License |
30 | * along with this program; if not, write to the Free Software |
30 | * along with this program; if not, write to the Free Software |
31 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
31 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
32 | *----------------------------------------------------------------------*/ |
32 | *----------------------------------------------------------------------*/ |
33 | /*----------------------------------------------------------------------* |
|
|
34 | * Public: |
|
|
35 | * extern void cleanutent (void); |
|
|
36 | * extern void makeutent (const char * pty, const char * hostname); |
|
|
37 | * |
|
|
38 | * Private: |
|
|
39 | * rxvt_update_wtmp (); |
|
|
40 | *----------------------------------------------------------------------*/ |
|
|
41 | |
33 | |
42 | #include "../config.h" |
34 | #include "../config.h" |
43 | #include "rxvt.h" |
35 | #include "rxvt.h" |
44 | #include "logging.h" |
36 | #include "ptytty.h" |
45 | |
37 | |
46 | #ifdef UTMP_SUPPORT |
38 | #if UTMP_SUPPORT |
47 | |
39 | |
48 | #if HAVE_STRUCT_UTMP |
40 | #if HAVE_STRUCT_UTMP |
49 | static int rxvt_write_bsd_utmp (int utmp_pos, struct utmp *wu); |
41 | static int rxvt_write_bsd_utmp (int utmp_pos, struct utmp *wu); |
50 | static void rxvt_update_wtmp (const char *fname, const struct utmp *putmp); |
42 | static void rxvt_update_wtmp (const char *fname, const struct utmp *putmp); |
51 | #endif |
43 | #endif |
… | |
… | |
63 | |
55 | |
64 | /* |
56 | /* |
65 | * make and write utmp and wtmp entries |
57 | * make and write utmp and wtmp entries |
66 | */ |
58 | */ |
67 | void |
59 | void |
68 | rxvt_term::makeutent (const char *pty, const char *hostname) |
60 | rxvt_ptytty_unix::login (int cmd_pid, bool login_shell, const char *hostname) |
69 | { |
61 | { |
|
|
62 | const char *pty = name; |
|
|
63 | |
|
|
64 | if (!pty || !*pty) |
|
|
65 | return; |
|
|
66 | |
|
|
67 | this->cmd_pid = cmd_pid; |
|
|
68 | this->login_shell = login_shell; |
|
|
69 | |
70 | #ifdef HAVE_STRUCT_UTMP |
70 | #ifdef HAVE_STRUCT_UTMP |
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; |
… | |
… | |
199 | } |
199 | } |
200 | #endif |
200 | #endif |
201 | |
201 | |
202 | #ifdef WTMP_SUPPORT |
202 | #ifdef WTMP_SUPPORT |
203 | # ifdef WTMP_ONLY_ON_LOGIN |
203 | # ifdef WTMP_ONLY_ON_LOGIN |
204 | if (OPTION (Opt_loginShell)) |
204 | if (login_shell) |
205 | # endif |
205 | # endif |
206 | { |
206 | { |
207 | # ifdef HAVE_STRUCT_UTMP |
207 | # ifdef HAVE_STRUCT_UTMP |
208 | # ifdef HAVE_UPDWTMP |
208 | # ifdef HAVE_UPDWTMP |
209 | updwtmp (RXVT_WTMP_FILE, ut); |
209 | updwtmp (RXVT_WTMP_FILE, ut); |
… | |
… | |
215 | updwtmpx (RXVT_WTMPX_FILE, utx); |
215 | updwtmpx (RXVT_WTMPX_FILE, utx); |
216 | # endif |
216 | # endif |
217 | } |
217 | } |
218 | #endif |
218 | #endif |
219 | #if defined(LASTLOG_SUPPORT) && defined(RXVT_LASTLOG_FILE) |
219 | #if defined(LASTLOG_SUPPORT) && defined(RXVT_LASTLOG_FILE) |
220 | if (OPTION (Opt_loginShell)) |
220 | if (login_shell) |
221 | rxvt_update_lastlog (RXVT_LASTLOG_FILE, pty, hostname); |
221 | rxvt_update_lastlog (RXVT_LASTLOG_FILE, pty, hostname); |
222 | #endif |
222 | #endif |
223 | } |
223 | } |
224 | |
224 | |
225 | /* ------------------------------------------------------------------------- */ |
225 | /* ------------------------------------------------------------------------- */ |
226 | /* |
226 | /* |
227 | * remove utmp and wtmp entries |
227 | * remove utmp and wtmp entries |
228 | */ |
228 | */ |
229 | void |
229 | void |
230 | rxvt_term::cleanutent () |
230 | rxvt_ptytty_unix::logout () |
231 | { |
231 | { |
|
|
232 | if (!cmd_pid) |
|
|
233 | return; |
|
|
234 | |
232 | #ifdef HAVE_STRUCT_UTMP |
235 | #ifdef HAVE_STRUCT_UTMP |
233 | struct utmp *ut = &this->ut; |
236 | struct utmp *tmput, *ut = &this->ut; |
234 | #endif |
237 | #endif |
235 | #ifdef HAVE_STRUCT_UTMPX |
238 | #ifdef HAVE_STRUCT_UTMPX |
236 | struct utmpx *tmputx, *utx = &this->utx; |
239 | struct utmpx *tmputx, *utx = &this->utx; |
237 | #endif |
240 | #endif |
238 | |
241 | |
… | |
… | |
240 | # ifdef HAVE_UTMP_PID |
243 | # ifdef HAVE_UTMP_PID |
241 | memset (ut, 0, sizeof (struct utmp)); |
244 | memset (ut, 0, sizeof (struct utmp)); |
242 | setutent (); |
245 | setutent (); |
243 | strncpy (ut->ut_id, this->ut_id, sizeof (ut->ut_id)); |
246 | strncpy (ut->ut_id, this->ut_id, sizeof (ut->ut_id)); |
244 | ut->ut_type = USER_PROCESS; |
247 | ut->ut_type = USER_PROCESS; |
245 | { |
|
|
246 | struct utmp *tmput = getutid (ut); |
|
|
247 | |
|
|
248 | if (tmput) /* position to entry in utmp file */ |
248 | if ((tmput = getutid (ut))) /* position to entry in utmp file */ |
249 | ut = tmput; |
249 | ut = tmput; |
250 | } |
|
|
251 | ut->ut_type = DEAD_PROCESS; |
250 | ut->ut_type = DEAD_PROCESS; |
252 | # else |
251 | # else |
253 | memset (ut->ut_name, 0, sizeof (ut->ut_name)); |
252 | memset (ut->ut_name, 0, sizeof (ut->ut_name)); |
254 | # ifdef HAVE_UTMP_HOST |
253 | # ifdef HAVE_UTMP_HOST |
255 | memset (ut->ut_host, 0, sizeof (ut->ut_host)); |
254 | memset (ut->ut_host, 0, sizeof (ut->ut_host)); |
… | |
… | |
276 | /* |
275 | /* |
277 | * Write ending wtmp entry |
276 | * Write ending wtmp entry |
278 | */ |
277 | */ |
279 | #ifdef WTMP_SUPPORT |
278 | #ifdef WTMP_SUPPORT |
280 | # ifdef WTMP_ONLY_ON_LOGIN |
279 | # ifdef WTMP_ONLY_ON_LOGIN |
281 | if (OPTION (Opt_loginShell)) |
280 | if (login_shell) |
282 | # endif |
281 | # endif |
283 | { |
282 | { |
284 | # ifdef HAVE_STRUCT_UTMP |
283 | # ifdef HAVE_STRUCT_UTMP |
285 | # ifdef HAVE_UPDWTMP |
284 | # ifdef HAVE_UPDWTMP |
286 | updwtmp (RXVT_WTMP_FILE, ut); |
285 | updwtmp (RXVT_WTMP_FILE, ut); |
287 | # else |
286 | # else |
288 | rxvt_update_wtmp (RXVT_WTMP_FILE, ut); |
287 | rxvt_update_wtmp (RXVT_WTMP_FILE, ut); |
289 | # endif |
288 | # endif |
290 | # endif |
289 | # endif |
291 | # ifdef HAVE_STRUCT_UTMPX |
290 | # if defined(HAVE_STRUCT_UTMPX) && defined(HAVE_UPDWTMPX) |
292 | # if HAVE_UPDWTMPX |
|
|
293 | updwtmpx (RXVT_WTMPX_FILE, utx); |
291 | updwtmpx (RXVT_WTMPX_FILE, utx); |
294 | # else |
|
|
295 | pututxline (utx); |
|
|
296 | # endif |
|
|
297 | # endif |
292 | # endif |
298 | } |
293 | } |
299 | #endif |
294 | #endif |
300 | |
295 | |
301 | /* |
296 | /* |
… | |
… | |
314 | #ifdef HAVE_STRUCT_UTMPX |
309 | #ifdef HAVE_STRUCT_UTMPX |
315 | if (utx->ut_pid == cmd_pid) |
310 | if (utx->ut_pid == cmd_pid) |
316 | pututxline (utx); |
311 | pututxline (utx); |
317 | endutxent (); |
312 | endutxent (); |
318 | #endif |
313 | #endif |
|
|
314 | |
|
|
315 | cmd_pid = 0; |
319 | } |
316 | } |
320 | |
317 | |
321 | /* ------------------------------------------------------------------------- */ |
318 | /* ------------------------------------------------------------------------- */ |
322 | /* |
319 | /* |
323 | * Write a BSD style utmp entry |
320 | * Write a BSD style utmp entry |